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

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

#define int ll


main(){
	int n,k;
	int a[2001];

	ll mod = 1e9+7;

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


	int cnt = 0ll;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(a[i]>a[j]) cnt++;
		}
	}
	int cnt2 = 0ll;
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++){
			if(a[i]<a[j]) cnt2++;
		}
	}
	int ans;
	if(k%2==0) ans = (k+1)*(k/2) % mod;
	else ans = ((k+1)/2)*k % mod;
	ans = ans * cnt % mod;

	int ans2;
	if(k%2==0) ans2 = (k-1)*(k/2) % mod;
	else ans2 = ((k-1)/2)*k % mod;
	ans2 = ans2 * cnt2 % mod;

	cout << (ans+ans2)%mod << endl;

	return 0;
}


Measured memory_bytes: 3620
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size1,init=nil,size2=-1) #size2に二次元配列時の最初の要素数、size1に次の配列の大きさ、initに初期値を投げることでその配列を返す
  if size2==-1
    return Array.new(size1){init}
  else
    return Array.new(size2){Array.new(size1){init}}
  end
end

A,B=get_i
def prime_div(n)
    primes=[]
    2.upto((n**0.5).to_i) do|i|
        while (n%i).zero?
            n/=i
            primes.push(i)
        end
    end
    primes.push(n) if n!=1
    return primes.uniq
end

gcd=A.gcd(B)
puts prime_div(gcd).size+1

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

#define db(x) cout<<x<<'\n'
#define db1(x) cout<<#x<<"="<<x<<'\n'
#define db2(x,y) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define db3(x,y,z) cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define repi(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 ll long long int
#define endl '\n'
#define lld long long double
#define vi vector<int> 
#define vl vector<ll> 
#define vb vector<bool> 
#define vvi vector<vector<int>  >
#define err(t) cout<<"Error : "<<t<<endl;
#define all(v) v.begin(),v.end()
#define mp make_pair
#define M 100000
#define MD 1000000007
#define pb push_back
#define rep(i,a,b) for(ll i = a; i <= (b); i++)
#define pii pair<int,int>
#define pll pair<ll,ll> 
#define vec(a) vector<a >
#define se second
#define fi first
#define inf 0xfffffff
#define inchar getchar_unlocked
#define outchar(x) putchar_unlocked(x)

int32_t main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);cout.tie(NULL);
	// int n;cin>>n;
	// string s;cin>>s;
	
	//ll n;cin>>n; vl a(n); repi(i,n) cin>>a[i];
	int n,m,x;cin>>n>>m>>x;
	vector<int> c(n,0);
	int a[n][m];
	repi(i,n){
		cin>>c[i];
		repi(j,m) cin>>a[i][j];
	}bool ch=false;ll p=inf,q;bool tr=true;
	//vector<bool> vis(n,false);int item=0;
	for(int i=0;i<(1<<n);++i){
		q=0;
		ch=true;
	vector<int> val(m,0);
		for(int j=0;j<n;j++){
			if((1<<j)&i) {
		//	db2(i,j);
			q+=c[j];
			repi(z,m) val[z]+=a[j][z];
			}
		}
		//	repi(z,m) cout<<val[z]<<" ";cout<<'\n';
			repi(z,m) {if(val[z]<x) ch=false;}
		if(ch&&(q<p)) {tr=false;p=q;} 
	}
	if(tr) cout<<-1<<endl; else cout<<p<<endl;
	/*
	int test1;cin>>test1;while(test1--){ 
		
	 }
	 //*/
return 0;
}



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

int main(void){
    int a,b,c;
    cin >> a >> b >> c;
    if(a!=b && a!=c && b!=c)
        cout << 3 << endl;
    else if(a == b && b==c)
        cout << 1 << endl;
    else
        cout << 2 << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(var,cnt) for(int (var)=0; (var)<(int)(cnt); ++(var))
#define REP(var,init,cnt) for(int (var)=(init); (var)<(cnt); ++(var))
#define ran(var,vec) for(auto &(var):(vec))
#define all(v) (v).begin(),(v).end()
#define TF(flag) (flag)?1:0
#define fi first
#define se second
#define debug if(DEBUG)
using namespace std;
 
using ll = long long;
using ull = unsigned long long;
using pi = pair<ll,ll>;
 
template<typename T>
using vec = vector<T>;
template<typename T>
using mat = vector<vec<T>>;
template<typename T>
using pq = priority_queue<T>;
template<typename T>
using rpq = priority_queue<T,vec<T>,greater<T>>;
 
template<typename T1,typename T2>
ostream &operator<<(ostream &os, const pair<T1,T2> &p){
  os<<"P("<<p.first<<", "<<p.second<<") ";
  return os;
}
 
template<typename T1,typename T2>
istream &operator>>(istream &is, pair<T1,T2> &p){
  is>>p.first>>p.second;
  return is;
}
 
template<typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for(int i=0; i<(int)v.size(); ++i){
    os<<v[i]<<(i+1!=v.size()?" ":"");
  }
  return os;
}
 
template<typename T>
istream &operator>>(istream &is, vector<T> &v){
  for(T &in:v) is>>in;
  return is;
}
 
bool DEBUG=true;

// Code from here ! ==================================================================

int main(void){
  int N,A,B; cin>>N>>A>>B;
  vec<ll> X(N); cin>>X;
  
  ll ans=0;
  REP(i,1,N){
    if(A*(X[i]-X[i-1])<B){
      ans+=A*(X[i]-X[i-1]);
    }
    else{
      ans+=B;
    }
  }
  cout<<ans<<endl;
}
















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

int main()
{
	int l, r, d;
	cin >> l >> r >> d;
	int sum = r - l + 1;
	int ans = 0;
	for (int i = l;i<=r; i++)
	{
		sum--;
		if (i % d == 0)
		{
			ans++;
			break;
		}
	}
	ans += sum / d;
	cout << ans;
	return 0;
}

Measured memory_bytes: 3576
#include <iostream>
int main()
{
    int k, s;
    std::cin >> k;
    std::cin >> s;

    int cnt = 0;
    // off-diagonal
    for (int ix = 0; ix < k+1; ++ix)
    {
        for (int iy = ix + 1; iy < k+1; ++iy)
        {
            const int z = s - ix - iy;
            if (z < 0) break;
            if (z <= k) ++cnt;
        }
    }
    cnt *= 2;

    // diagonal
    for (int ix = 0; ix < k+1; ++ix)
    {
        const int z = s - 2*ix;
        if (z < 0) break;
        if (z <= k) ++cnt;
    }

    std::cout << cnt << "\n";

    return 0;
}

Measured memory_bytes: 256
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <bitset>    // bitset
#include <deque>     // deque
#include <iomanip>   //setprecsion
#include <iostream>  // cout, endl, cin
#include <map>       // map
#include <queue>     // queue, priority_queue
#include <set>       // set
#include <stack>     // stack
#include <string>    // string, to_string, stoi
#include <tuple>     // tuple, make_tuple
#include <utility>   // pair, make_pair
#include <vector>    // vector

#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <cmath>  //sin, cos, tan

using namespace std;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = (n - 1); i >= 0; --i)
#define blank(ans) cout << (ans) << " ";
#define mp(p, q) make_pair(p, q)
#define mt(p, q, r) make_tuple(p, q, r)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()

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

typedef vector<ll> vll;
typedef vector<ld> vd;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<str> vs;
typedef vector<vector<ll>> vvll;
typedef vector<vector<ld>> vvd;
typedef vector<vector<bool>> vvb;
typedef vector<vector<char>> vvc;
typedef vector<vector<str>> vvs;
typedef vector<pair<ll, ll>> vpll;
typedef vector<tuple<ll, ll, ll>> vtlll;

const ld PI = acos(-1.0);
const ll MAX = 9000000000000000000;
const ll MIN = -9000000000000000000;
const ld DMAX = 4500;
const ld DMIN = -4500;
const ll MOD = 1000000007;

template <typename T>
void fin(T a)
{
  cout << a << endl;
  exit(0);
}

void Main()
{
  ll n; cin >> n;
  vll a(n); rep(i, n) cin >> a[i];
  ll ans = 0;
  rep(i, n - 1)
  {
    if(a[i] > a[i + 1])
    {
      ans += abs(a[i + 1] - a[i]);
      a[i + 1] += abs(a[i + 1] - a[i]);
    }
  }
  fin(ans);
}

//前処理
int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << fixed << setprecision(4); //高精度少数表示
  Main();
  return 0;
}


Measured memory_bytes: 5132
def isIncremental(a, b, c):
    """
    a: int
    b: int
    c: int

    returns "Yes" if a < b < c, otherwise "No"

    >>> isIncremental(1, 3, 8)
    'Yes'
    >>> isIncremental(3, 8, 1)
    'No'
    >>> isIncremental(1, 1, 1)
    'No'
    """
    if a >= b:
        return "No"
    elif b >= c:
        return "No"
    else:
        return "Yes"

if __name__ == '__main__':
#   import doctest
#   doctest.testmod()

    ival = input().split(' ')
    print(isIncremental(int(ival[0]), int(ival[1]), int(ival[2])))

Measured memory_bytes: 7732
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int,int> pint;

int main(){
    int n;
    ll ti,ans=1;
    cin>>n;
    rep(i,n){
        cin>>ti;
        ans=ti/__gcd(ans,ti)*ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    map<char, vector<ll>> pos;
    string s, t; cin >> s >> t;
    rep(i, s.size()){
        pos[s[i]].push_back(i+1);
    }

    ll ans = 0, cur = 0;
    rep(i, t.size()){
        // sに含まれない文字がtに含まれている場合は何個連結しても無理
        if(!pos[t[i]].size()){
            cout << -1 << endl;
            return 0;
        }

        // 前回参照した位置より右にあるかどうか
        auto it = upper_bound(all(pos[t[i]]), cur);
        if(it != pos[t[i]].end()){
            ans += (*it - cur);
            cur = *it;
        }
        else{
            ans += s.size()-cur+pos[t[i]][0];
            cur = pos[t[i]][0];
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4564
#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0;i < (n);i++)
#define all(v) v.begin(),v.end()
#define dec(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using vl = vector<ll>;
using vvl = vector<vl>;


bool bingo(ll a, ll b, ll c, vl bi){
  bool at,bt,ct; at = false; bt = false; ct = false;
  for(ll i=0; i < bi.size(); i++){
    if(a == bi[i]) at = true;
    else if(b == bi[i]) bt = true;
    else if(c == bi[i]) ct = true;
  }
  
  if(at&&bt&&ct) return true; 
  else return false;
}


int main(){
  vl ai(9); rep(i,9){ ll x; cin >> x; ai[i] = x; }
  ll n; cin >> n;
  vl bi(n); rep(i,n){ ll x; cin >> x; bi[i] = x; }
  
  if(bingo(ai[0],ai[1],ai[2],bi)||bingo(ai[3],ai[4],ai[5],bi)||
     bingo(ai[6],ai[7],ai[8],bi)||bingo(ai[0],ai[3],ai[6],bi)||
     bingo(ai[1],ai[4],ai[7],bi)||bingo(ai[2],ai[5],ai[8],bi)||
     bingo(ai[0],ai[4],ai[8],bi)||bingo(ai[2],ai[4],ai[6],bi))
    cout << "Yes" << endl;
  else cout << "No" << endl;
}
     
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define Rep(i, n) for (int i = 0; i < (int)(n); i++)
#define BitRep(i, n) for (int i = 0; i < (int)(1 << n); i++)
#define Sum(vec) accumulate(vec.begin(), vec.end(), 0)
#define Sort(vec) sort(vec.begin(), vec.end())
#define Reverse(vec) reverse(vec.begin(), vec.end())
#define Next_permutation(vec) next_permutation(vec.begin(), vec.end())
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX / 2 + 2], R[MAX / 2 + 2];
int cnt;

void merge(int *A, int n, int left, int mid, int right) {
    int n1 = mid - left;
    int n2 = right - mid;
    for (int i = 0; i < n1; i++) {
        L[i] = A[left + i];
    }
    for (int i = 0; i < n2; i++) {
        R[i] = A[mid + i];
    }
    L[n1] = R[n2] = SENTINEL;
    int i = 0, j = 0;
    for (int k = left; k < right; k++) {
        cnt++;
        if (L[i] <= R[j]) {
            A[k] = L[i++];
        }
        else {
            A[k] = R[j++];
        }
    }
}

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

int main() {
    int A[MAX], n, i;
    cnt = 0;
    cin >> n;
    for (i = 0; i < n; i++) {
        cin >> A[i];
    }
    mergeSort(A, n, 0, n);
    for (i = 0; i < n; i++) {
        if (i) {
            cout << " ";
        }
        cout << A[i];
    }
    cout << endl;
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 7012
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<double, bool> Pd;
int n; ll W;
ll v[101], w[101];
int ind[101];
ll ans;

Pd rsolve(int i, double ws, double vs){
	bool ok=1;
	for(int k=i; k<n; k++){
		double x=min((double)W-ws, (double)w[ind[k]]);
		if(x>0 && x<(double)w[ind[k]]){
			ok=0;
		}
		ws+=x;
		vs+=x/(double)w[ind[k]]*(double)v[ind[k]];
	}
	return Pd(vs, ok);
}

ll solve(int i, ll ws, ll vs){
	if(i==n){
		ans=max(vs, ans);
		return vs;
	}
	Pd p=rsolve(i, (double)ws, (double)vs);
	if(p.second){
	    ans=max(ans, (ll)p.first);
	    return (ll)p.first;
	}
	if(p.first<(double)ans) return 0;
	ll ret=0;
	if(ws+w[ind[i]]<=W) ret=max(ret, solve(i+1, ws+w[ind[i]], vs+v[ind[i]]));
	ret=max(ret, solve(i+1, ws, vs));
	ans=max(ret, ans);
	return ret;
}

int main()
{
	cin>>n>>W;
	for(int i=0; i<n; i++){
		ind[i]=i;
		cin>>w[i]>>v[i];
	}
	sort(ind, ind+n, [&](int i, int j){ return (double)v[i]/(double)w[i]>(double)v[j]/(double)w[j];});
	solve(0, 0, 0);
	cout<<ans<<endl;
	return 0;
}

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

int main(void)
{
  unsigned int N;
  unsigned int A;
  unsigned int B;
  
  cin >> N >> A >> B;
  
  A *= N;
  
  if(A<B)
    cout << A;
  else
    cout << B;
  
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<algorithm>
#include <cassert>
#include<string>
#include<vector>
#include <utility>
#include <math.h>
using namespace std;
int main(){
	int a = 0, b = 0, c = 0, d = 0, e = 0, money = 0;
	cin >> a >> b >> c >> d >> e;
	if (a + b >= c * 2) {
		money += c * 2 * min(d, e);
		if (d > e) {
			d -= e;
			e = 0;
		}
		else if (d < e) {
			e -= d;
			d = 0;
		}
		else if (d = e) {
			cout << money << endl;
			return 0;
		}
	}
	
	while (d != 0) {
		if (c * 2 > a) {
			money += a;
			d--;
		}
		else {
			money += c * 2;
			d--;
		}
	}
	while (e != 0) {
		if (c * 2 > b) {
			money += b;
			e--;
		}
		else {
			money += c * 2;
			e--;
		}
	}
	cout << money << endl;
	return 0;
}

Measured memory_bytes: 384
import sys

stdin = sys.stdin

ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
ns = lambda: stdin.readline().rstrip()

N, W = na()
dp = [[0] * (W+1) for i in range(N+1)]  # dp[j][w] w以下でj番目までの品物で最大の価値
for i in range(1, N+1):
    wi, vi = na()
    for w in range(1, W+1):
        if w - wi >= 0:
            dp[i][w] = max(dp[i - 1][w], dp[i - 1][w - wi] + vi)
        else:
            dp[i][w] = dp[i - 1][w]
print(dp[N][w])

Measured memory_bytes: 119916
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int A,B,C,K;
    cin >> A >> B >> C >> K;
    if(K%2 == 0) {
        cout << A-B << endl;
    }
    else {
        cout << B-A << endl;
    }
}


Measured memory_bytes: 3644
//ALDS1_1_B: Greatest Common Divisor
#include <stdio.h>
int gcd(int a,int b){//要求a>=b 
    if(a%b==0)
        return b;
    return gcd(b,a%b);//此?写成  gcd(b,a%b); 有失水准 
}
int main(){
    int x,y,z;
    scanf("%d%d",&x,&y);
    if(x>y)z=gcd(x,y);
    else z=gcd(y,x);
    printf("%d\n",z);
    return 0;
}

Measured memory_bytes: 1804
#include <iostream>

using namespace std;


bool judge(int i, int a, int b) {
    int c=0;
    for(;i>0;i/=10) c += i%10;
    return a<=c && c<=b;
}

int main(int argc, char const *argv[])
{
    int n, a, b, v=0;
    cin >> n >> a >> b;
    for(int i=1;i<=n;++i) {
        v += judge(i, a, b)? i: 0;
    }
    cout << v << endl;
    return 0;
}


Measured memory_bytes: 256
//
//  main.cpp
//  ABC124
//
//  Created by hiroaki on 2019/05/07.
//  Copyright © 2019年 hiroaki. All rights reserved.
//

#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath> 
#include <tuple>
#include <bitset>
//pair sort firstに揃う

#define int long long
#define double long double
#define Rap(n,i) for(int (i)=0;(i)<(n);(i)++)
#define Pr(n) cout<<n<<endl;
#define PairV vector<pair<int , int> >
#define F first
#define S second
#define Vector1  vector<int>
#define vector2 vector<vector<int> >
#define index(v,x) find((v).begin(), (v).end(), (x))-(v).begin()
#define ctoi(c) (int)(c-'0')
#define incin(n) int (n); cin>>(n);
#define incin2(n,m) int (n),(m); cin >> (n)>>(m);
#define stcin(s) string (s); cin>>(s);
#define all(v) (v).begin() , (v).end()
namespace Mathf
{
    const int INF = 1000000000000;
    const double PI = 3.14159274;
    const double Rad2Deg = 57.29578;
    const double log2(double a,double b);
    const double log2(double a,double b){
        return log(b)/log(a);
    }
} // namespace Mathf

using namespace std;

int MD(pair<int,int> a,pair<int,int> b){//ManhattanDisRance
    return abs(a.first-b.first) + abs(a.second-b.second);
}
int MOD(int a,int b){
    return abs(a%b);
}
template <typename T1,typename T2> bool Comp (pair<T1,T2> a,pair<T1,T2> b){
    if(a.first!=b.first){
        return a.first<b.first;//first昇順
    }
    if(a.second!=b.second){
        return a.second > b.second;//second降順
    }else{
        return  true;
    }
}
signed  main(){
    cin.tie(0);
    ios::sync_with_stdio(false);

    stcin(s);
    int x=0b00,y=0b00;
    for(int i=0;i<s.size();i++){
        switch (s[i])
        {
        case 'N':
            y=y|0b01;
            break;
        case 'S':
            y=y|0b10;
            break;
        case 'E':
            x=x|0b01;
            break;
        case 'W':
            x=x|0b10;
            break;
        default:
            break;
        }
    }
    ((x==0 || x==3) && (y==0 || y==3))? cout<<"Yes"<<endl:cout<<"No"<<endl;
    return 0;
}
 

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define INF (1LL<<50)
#define MOD 1000000007

int main(){
    string S;
    ll K;
    cin >> S >> K;
    ll cnt=0;
    char bf=S[0];
    ll ac=0;
    for(int i=0;i<S.size();i++){
        if(i==S.size()-1){
            if(S[i-1]==S[i]){
                cnt++;
            }
            ac+=cnt/2;
            break;
        }
        if(S[i]!=bf){
            ac+=cnt/2;
            cnt=1;
            bf=S[i];
        }else{
            cnt++;
        }
    }
    if(S[0]==S[S.size()-1]){
        ll cnt_h=0;
        for(int i=0;i<S.size();i++){
            if(S[i]!=S[0]){
                break;
            }else{
                cnt_h++;
            }
        }
        if(cnt_h==S.size()){
            cout << S.size()*K/2 << endl;
            return 0;
        }
        ll cnt_t=0;
        for(int i=S.size()-1;i>=0;i--){
            if(S[i]!=S[S.size()-1]){
                break;
            }else{
                cnt_t++;
            }
        }
        //cout << ac << " " << cnt_h << " " <<  cnt_t << endl;
        cout << K*ac - (cnt_h/2 + cnt_t/2 - (cnt_h+cnt_t)/2)*(K-1) << endl;
    }else{
        cout << K*(ac) << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int X;
	cin >> X;
	while(X >= 400 && X <= 1999){
		if(X >= 400 && X <= 599){
			cout << "8" << endl;
		}	
		else if(X >= 600 && X <= 799){
			cout << "7" << endl;
		}
		else if(X >= 800 && X <= 999){
			cout << "6" << endl;
		}
		else if(X >= 1000 && X <= 1199){
			cout << "5" << endl;
		}
		else if(X >= 1200 && X <= 1399){
			cout << "4" << endl;
		}
		else if(X >= 1400 && X <= 1599){
			cout << "3" << endl;
		}
		else if(X >= 1600 && X <= 1799){
			cout << "2" << endl;
		}
		else{
			cout << "1" << endl;
		}	
		break;
	}
	return 0;
} 

Measured memory_bytes: 3640
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
template<class S, class T> inline S max_L(S a,T b){
  return a>=b?a:b;
}
inline void rd(char &c){
  int i;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c = i;
}
inline int rd(char c[]){
  int i, sz=0;
  for(;;){
    i = getchar_unlocked();
    if(i!=' '&&i!='\n'&&i!='\r'&&i!='\t'&&i!=EOF){
      break;
    }
  }
  c[sz++] = i;
  for(;;){
    i = getchar_unlocked();
    if(i==' '||i=='\n'||i=='\r'||i=='\t'||i==EOF){
      break;
    }
    c[sz++] = i;
  }
  c[sz]='\0';
  return sz;
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  char f[10];
  int m=0, s=0;
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int N;
char S[100002];
int main(){
  int a, b, res;
  N = rd(S);
  a = b = N/2;
  while(a-1 >= 0 && S[a]==S[a-1]){
    a--;
  }
  while(b+1 <  N && S[b]==S[b+1]){
    b++;
  }
  res = N -max_L(a, N-1-b);
  wt_L(res);
  wt_L('\n');
  return 0;
}
// cLay varsion 20190827-1

// --- original code ---
// int N; char S[100002];
// {
//   int a, b, res;
//   rd(S@N);
//   a = b = N/2;
//   while(a-1 >= 0 && S[a]==S[a-1]) a--;
//   while(b+1 <  N && S[b]==S[b+1]) b++;
//   res = N - max(a, N-1-b);
//   wt(res);
// }


Measured memory_bytes: 384
//
//  ROIGold.cpp
//  Main calisma
//
//  Created by Rakhman on 05/02/2019.
//  Copyright © 2019 Rakhman. All rights reserved.
//

#include <cstring>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <cassert>
#include <iterator>

#define ios ios_base::sync_with_stdio(0), cout.tie(0), cin.tie(0);
#define S second
#define F first
#define pb push_back
#define nl '\n'
#define NL cout << '\n';
#define EX exit(0)
#define all(s) s.begin(), s.end()
#define FOR(i, start, finish, k) for(int i = start; i <= finish; i += k)

const int MXN = 2e5 + 1;
const long long MNN = 5e3 + 100;
const long long MOD = 1e9 + 7;
const long long INF = 1e18;
const int OO = 1e9 + 500;

typedef long long llong;
typedef unsigned long long ullong;

using namespace std;

int n;
int t, q;
llong ans = 0;
pair<int, int> p[MXN];
vector<pair<int, int> > lss, eql, grt;

bool cmp(pair<int, int> a, pair<int, int> b){
    return a.F - a.S < b.F - b.S;
}

int main () {
    cin >> q;
    for(int i = 1; i <= q; i++){
        cin >> p[i].F >> p[i].S;
        ans += p[i].F;
        if(p[i].F == p[i].S){
            eql.pb({p[i].F, p[i].S});
        }
        else if(p[i].F > p[i].S){
            grt.pb({p[i].S, p[i].F});
        }
    }
    if(eql.size() == q) return cout << 0, 0;
    sort(grt.begin(), grt.end());
    cout << ans - grt[0].F;
    return 0;
}


Measured memory_bytes: 768
N, K = map(int, input().split())

a = 0
b = 0

for i in range(1, N+1):
    if i % K == 0:
        a += 1
    
    elif K % 2 == 0 and i % (K/2) == 0:
        b += 1

print(a**3+b**3)

Measured memory_bytes: 3188
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

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

func solve(s string, mx byte, N int) {
	if len(s) == N {
		out(s)
		return
	}
	for c := byte('a'); c <= mx; c++ {
		next := mx
		if c == mx {
			next++
		}
		solve(s+string(c), next, N)
	}
}

func main() {
	sc.Split(bufio.ScanWords)

	N := getInt()
	solve("", 'a', N)
}


Measured memory_bytes: 6016
#include <bits/stdc++.h>
using namespace std;
#define ALL(a) (a).begin(),(a).end()
#define rALL(a) (a).rbegin(),(a).rend()
typedef pair<int, int> P;
typedef pair<int64_t, int64_t> Pll;
  
int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    for (int i = 0; i < N; i++) {
        cin >> A.at(i);
    }
    sort(ALL(A));
    cout << A.at(N - 1) - A.at(0) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stdlib.h>
#include <map>
#include <cmath>
#define MOD_P 1000000007
#define ll long long
using namespace std;



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

	printf("%d", a < 10 && b < 10 ? a * b : -1);

	return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String arg[]){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		int c=sc.nextInt();
		if(a==b&&b!=c&&a!=c)
			System.out.println("Yes");
		else if(a!=b&&b==c&&a!=c)
			System.out.println("Yes");
		else if(a!=b&&b!=c&&a==c)
			System.out.println("Yes");
		else 
			System.out.println("No");
	}
}

Measured memory_bytes: 22096
import os
import sys

import numpy as np


def solve(n, precalc_x, precalc_y):
    ans = np.full(n + 1, 10 ** 18, dtype=np.int64)

    def get_cost(v, bit):
        cost = 0
        pcx = precalc_x[v]
        pcy = precalc_y[v ^ bit]
        for i in range(n):
            if v & (1 << i):
                continue
            cost += min(pcx[i], pcy[i])
        return cost

    for bit in range(1 << n):
        k = (bit & 0x5555) + (bit >> 1 & 0x5555)
        k = (k & 0x3333) + (k >> 2 & 0x3333)
        k = (k & 0x0f0f) + (k >> 4 & 0x0f0f)
        k = (k & 0x00ff) + (k >> 8 & 0x00ff)
        v = bit
        while v:
            ans[k] = min(ans[k], get_cost(v, bit))
            v = (v - 1) & bit
        ans[k] = min(ans[k], get_cost(0, bit))

    return ans


if sys.argv[-1] == 'ONLINE_JUDGE':
    from numba.pycc import CC

    cc = CC('my_module')
    cc.export('solve', '(i8, i8[:,:], i8[:,:])')(solve)
    cc.compile()
    exit()

if os.name == 'posix':
    # noinspection PyUnresolvedReferences
    from my_module import solve
else:
    from numba import njit

    solve = njit('(i8, i8[:,:], i8[:,:])', cache=True)(solve)
    print('compiled', file=sys.stderr)

inp = np.fromstring(sys.stdin.read(), dtype=np.int64, sep=' ')
n = inp[0]
xxx = inp[1::3]
yyy = inp[2::3]
ppp = inp[3::3]

bit_d = (((np.arange(1 << n)[:, None] & (1 << np.arange(n)))) > 0).astype(np.int64)
precalc_x = abs((xxx[None, :] * bit_d)[..., None] - xxx[None, None, :]).min(axis=1) * ppp[None, :]
precalc_y = abs((yyy[None, :] * bit_d)[..., None] - yyy[None, None, :]).min(axis=1) * ppp[None, :]

ans = solve(n, precalc_x, precalc_y)
print('\n'.join(map(str, ans)))


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

int main() {
  int x, y, a, b, c;
  cin >> x >> y >> a >> b >> c;
  vector<int> p(a), q(b), r(c);
  rep(i, a) cin >> p.at(i);
  rep(i, b) cin >> q.at(i);
  rep(i, c) cin >> r.at(i);
  sort(p.rbegin(), p.rend());
  sort(q.rbegin(), q.rend());

  vector<int> s;
  rep(i, x) s.push_back(p.at(i));
  rep(i, y) s.push_back(q.at(i));
  rep(i, c) s.push_back(r.at(i));
  sort(s.rbegin(), s.rend());

  ll ans = 0;
  rep(i, x + y) ans += s.at(i);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 6452
#include<bits/stdc++.h>
using namespace std;
int main(){
int n;
  cin>>n;
  map<string,int>mp;
  for(int i=0;i<n;i++)
  {
    string s;
    cin>>s;
    mp[s]++;
  }
  int max=0;
  for(auto i:mp){
  int tmp=i.second;
    if(tmp>max)
      max=tmp;
  }
  for(auto it=mp.begin();it != mp.end();it++){
  if(it->second == max)
    cout<<it->first<<"\n";
  }
}


Measured memory_bytes: 25216
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int[] a= new int[3];
		for(int i=0;i<3;i++) {
			a[i]=scan.nextInt();
		}
		int max=Integer.MIN_VALUE;
		for(int i=0;i<3;i++) {
			for(int j=i+1;j<3;j++) {
				max=Math.max(max, Math.abs(a[j]-a[i]));
			}
		}
		System.out.println(max);
	}

}


Measured memory_bytes: 26948
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rep1(i,n) for(int i = 1; i <= (n); ++i)
#define COUT(x) cout << (x) << endl
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
const ll LINF = 1e17;
const int INF = 1001001001;
const int MOD = 1000000007;

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


int main() {
    ll n, k;
    cin >> n >> k;
    vector<ll> H(n);
    rep(i, n) cin >> H[i];
    sort(H.begin(), H.end(), greater<ll>());
    ll sum = 0;
    for(int i = k; i < n; i++) {
        sum += H[i];
    }
    COUT(sum);

    return 0;
}

Measured memory_bytes: 1792
n = gets.chomp.to_i
l_arr=[]
min = 10**15+1

5.times do|i|
  l_arr << gets.chomp.to_i
  if l_arr[i]<min then
    min = l_arr[i]
  end
end

if (n%min)==0 then
    m = (n/min)
else
    m = (n/min)+1
end
puts 4+m

Measured memory_bytes: 1788
#pragma GCC optimize("Ofast")
#include<stdio.h>
#include<string>
#include<algorithm>
using namespace std;
char str[100005][5];
int cnt[5]={0};
string ans="";
int main(){
	int i,n,a,b,c;
	scanf("%d%d%d%d",&n,&a,&b,&c);
	for(i=0;i<n;i++){
		scanf(" %s",str[i]);
		cnt[str[i][0]-'A']++;
		cnt[str[i][1]-'A']++;
	}
	bool right=1;
	for(i=0;i<n;i++){
		cnt[str[i][0]-'A']--;
		cnt[str[i][1]-'A']--;
		if(i<n-1&&(!a&&b==1&&c==1)&&str[i][0]=='B'&&str[i][1]=='C'){
			if(str[i+1][0]=='A'&&str[i+1][1]=='B'){
				c--;
				b++;
				ans+='B';
				continue;
			}
			else if(str[i+1][0]=='A'&&str[i+1][1]=='C'){
				c++;
				b--;
				ans+='C';
				continue;
			}
		}
		if(i<n-1&&(!b&&a==1&&c==1)&&str[i][0]=='A'&&str[i][1]=='C'){
			if(str[i+1][0]=='A'&&str[i+1][1]=='B'){
				c--;
				a++;
				ans+='A';
				continue;
			}
			else if(str[i+1][0]=='B'&&str[i+1][1]=='C'){
				c++;
				a--;
				ans+='C';
				continue;
			}
		}
		if(i<n-1&&(!c&&b==1&&a==1)&&str[i][0]=='A'&&str[i][1]=='B'){
			if(str[i+1][0]=='A'&&str[i+1][1]=='C'){
				a++;
				b--;
				ans+='A';
				continue;
			}
			if(str[i+1][0]=='B'&&str[i+1][1]=='C'){
				a--;
				b++;
				ans+='B';
				continue;
			}
		}
		if(str[i][0]=='A'&&str[i][1]=='B'){
			if(!cnt[0]&&a>0){
				a--;
				b++;
				ans+='B';
			}
			else if(!cnt[1]&&b>0){
				b--;
				a++;
				ans+='A';
			}
			else if(a>=b){
				a--;
				b++;
				ans+='B';
			}
			else{
				a++;
				b--;
				ans+='A';
			}
			if(a<0||b<0){
				right=0;
				break;
			}
		}
		else if(str[i][0]=='B'){
			if(!cnt[1]&&b>0){
				b--;
				c++;
				ans+='C';
			}
			else if(!cnt[2]&&c>0){
				c--;
				b++;
				ans+='B';
			}
			else if(b>=c){
				b--;
				c++;
				ans+='C';
			}
			else{
				c--;
				b++;
				ans+='B';
			}
			if(b<0||c<0){
				right=0;
				break;
			}
		}
		else{
			if(!cnt[0]&&a>0){
				a--;
				c++;
				ans+='C';
			}
			else if(!cnt[2]&&c>0){
				a++;
				c--;
				ans+='A';
			}
			else if(a>=c){
				a--;
				c++;
				ans+='C';
			}
			else{
				a++;
				c--;
				ans+='A';
			}
			if(a<0||c<0){
				right=0;
				break;
			}
		}
	}
	if(!right)
		puts("No");
	else{
		puts("Yes");
		for(i=0;i<ans.size();i++){
			printf("%c\n",ans[i]);
		}
	}
}


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

const int N = 3000;
const long long MOD = 1e9 + 7;
long long dp[N][N], sum[N][N];

void add(long long &a, long long b) {
    a += b;
    if (a > MOD)
        a -= MOD;
    if (a < 0)
        a += MOD;
}

void solveTrivial() {
    int n;
    string s;
    cin >> n >> s;
    // dp[i][j] = number of ways to make a permutation of length i + 1 that respects the first i signs and the last element is j (j ≤ i + 1).
    dp[0][1] = 1; // permutation with one element 1
    for (int i = 1; i <= n - 1; i++) {
        for (int j = 1; j <= i + 1; j++) {
            if (s[i - 1] == '<') {
                for (int k = 1; k < j; k++) {
                    add(dp[i][j], dp[i - 1][k]);
                }
            } else if (s[i - 1] == '>') {
                for (int k = j + 1; k <= i + 1; k++) {
                    add(dp[i][j], dp[i - 1][k]);
                }
                add(dp[i][j], dp[i - 1][j]); // insert element j by increasing all the values greater or equal to j by 1
            }
        }
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        add(ans, dp[n - 1][i]);
    }
    cout << ans;
}

void solveSmart() {
    int n;
    string s;
    cin >> n >> s;
    // dp[i][j] = number of ways to make a permutation of length i + 1 that respects the first i signs and the last element is j (j ≤ i + 1).
    dp[0][1] = 1; // permutation with one element 1
    sum[0][1] = 1;
    for (int i = 1; i <= n - 1; i++) {
        for (int j = 1; j <= i + 1; j++) {
            if (s[i - 1] == '<') {
                add(dp[i][j], sum[i - 1][j - 1]);
            } else if (s[i - 1] == '>') {
                add(dp[i][j], sum[i - 1][i] - sum[i - 1][j - 1]);
            }
        }
        sum[i][1] = dp[i][1];
        for (int j = 2; j <= i + 1; j++) {
            add(sum[i][j], sum[i][j - 1] + dp[i][j]);
        }
    }
    long long ans = 0;
    for (int i = 1; i <= n; i++) {
        add(ans, dp[n - 1][i]);
    }
    cout << ans;
}

int main() {
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(20);
    solveSmart();
    return 0;
}


Measured memory_bytes: 139264
import java.util.*;

public class Main {
    static final long DIV = 998244353L;
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] a = new int[m][2];
        for(int i=0; i<m; i++){
            a[i][0] = sc.nextInt() - 1;
            a[i][1] = sc.nextInt() - 1;
        }
        sc.close();

        if(m == 1){
            System.out.println(1);
            return;
        }

        long[] ans = new long[m];

        UnionFindTree ufs = new UnionFindTree(n);
        ans[m-1] = (long)n * (long)(n-1) / 2;
        ans[0] = 0;

        for(int i=m-2; i>=0; i--){
            int t1 = a[i+1][0];
            int t2 = a[i+1][1];
            if(!ufs.same(t1, t2)){
                ans[i] = ans[i+1] - (long)(ufs.num(t1)) * (long)(ufs.num(t2));
                ufs.unite(t1, t2);
            }else{
                ans[i] = ans[i+1];
            }
        }

        for(int i=0; i<m; i++){
            System.out.println(ans[i]);
        }
    }
}

//蟻本p84

class UnionFindTree{
    int[] par;
    int[] rank;
    int[] num;

    public UnionFindTree(int size){
        par = new int[size];
        rank = new int[size];
        num = new int[size];
        for(int i=0; i<size; i++){
            par[i] = i;
            rank[i] = 0;
            num[i] = 1;
        }
    }

    public int find(int x){
        if(par[x] == x){
            return x;
        }else {
            return par[x] = find(par[x]);
        }
    }

    public int num(int x){
        if(par[x] == x){
            return num[x];
        }else{
            return num(par[x]);
        }
        
    }

    public void unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return;

        if(rank[x] < rank[y]){
            par[x] = y;
            num[y] = num[y] + num[x];
        }else{
            par[y] = x;
            num[x] = num[x] + num[y];
            if(rank[x] == rank[y]) rank[x]++;
        }
    }

    public boolean same(int x, int y){
        return find(x) == find(y);
    }
}

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

int main() {
    const int INF = 2e9;
	const int MAX_N = 1e5 + 10;
    int N, A[MAX_N];
    cin >> N;
    for (int i = 0; i < N; ++i){
        A[i] = INF;
    }

    for (int i = 0; i < N; ++i){
        int a;
        cin >> a;
        *lower_bound(A, A+N, a) = a;
    }

    cout << lower_bound(A, A+N, INF) - A <<endl;
    
}


Measured memory_bytes: 3504
import java.util.Scanner;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int i = 1;
		int n = sc.nextInt();
		
		while(i <= n){
			int x = i;
			
			if(x % 3 == 0){
				System.out.print(" " + i);
			}else{
				while(x >= 1){
					if(x % 10 == 3){
						System.out.print(" " + i);
				break;
			}
			x /= 10;
		}
			}
	i++;
	}
	System.out.println("");
	sc.close();
}
}


Measured memory_bytes: 28920
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n;
  cin>>n;
  vector<int> ans(10001,0);
  for(int x=1;x<=100;x++){
    for(int y=1;y<=100;y++){
      for(int z=1;z<=100;z++){
        if(x*x+y*y+z*z+x*y+y*z+z*x>10000) continue;
        ans[x*x+y*y+z*z+x*y+y*z+z*x]++;
      }
    }
  }for(int i=1;i<=n;i++){
    cout<<ans[i]<<endl;
  }
}

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

struct UnionFind {
    vector<int> data;
    UnionFind(int sz) : data(sz, -1) { }
    bool unionSet(int x, int y) {
        if ((x = root(x)) == (y = root(y))) return false;
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y]; data[y] = x;
        return true;
    }
    bool findSet(int x, int y) { return root(x) == root(y); }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
    int size(int x) { return -data[root(x)]; }
};

int main(){
    int N, Q;
    cin >> N >> Q;
    UnionFind uf(N);
    for(int i = 0; i < Q; i++){
        int C, x, y;
        cin >> C  >> x >> y;
        if(C == 0){
            uf.unionSet(x, y);
        }
        if(C == 1){
            cout << uf.findSet(x, y) << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 3164
import sys
input = sys.stdin.readline
from collections import *

N, M = map(int, input().split())
s = input()[:-1]
G = [[] for _ in range(N)]
A = [0]*N
B = [0]*N

for _ in range(M):
    a, b = map(int, input().split())
    G[a-1].append(b-1)
    G[b-1].append(a-1)

q = deque([])
removed = [False]*N

for v in range(N):
    for nv in G[v]:
        if s[nv]=='A':
            A[v] += 1
        else:
            B[v] += 1
    
    if A[v]==0 or B[v]==0:
        q.append(v)
        removed[v] = True

while q:
    v = q.popleft()
    
    for nv in G[v]:
        if removed[nv]:
            continue
        
        if s[v]=='A':
            A[nv] -= 1
        else:
            B[nv] -= 1
        
        if A[nv]==0 or B[nv]==0:
            q.append(nv)
            removed[nv] = True

if False in removed:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 77724
from collections import Counter
n,k = map(int,input().split())
a = list(map(int,input().split()))
ans = 0
x = len(set(a))
if x <= k:
    print(ans)
else:
    b = Counter(a).most_common(x)
    for i in range(x-1,k-1,-1):
        ans += b[i][1]
    print(ans)

Measured memory_bytes: 48432
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;
using static ConsoleApplication.Utils;

namespace ConsoleApplication
{
    public class Program
    {
        public static void Main(string[] args)
        {
            var sorted = ReadInts().OrderBy(i => i).ToArray();
            var res = sorted[0] == 5 && sorted[1] == 5 && sorted[2] == 7 ? "YES" : "NO";
            WriteLine(res);
        }
    }

    public static class Utils
    {
        #region Extensions for IO

        public static int ReadInt()
            => ReadInts().First();

        public static IEnumerable<int> ReadInts()
            => ReadStrings().Select(int.Parse);

        public static IEnumerable<String> ReadStrings()
            => ReadLine().Split(' ');

        #endregion

        #region Extensions of int

        public static bool IsOdd(this int n)
            => !n.IsEven();

        public static bool IsEven(this int n)
            => n % 2 == 0;

        public static bool CanDivideWith(this int n, int divisor)
            => n % divisor == 0;

        #endregion

        #region Extensions of string

        public static int ToInt(this string str)
            => int.Parse(str);

        public static long ToLong(this string str)
            => long.Parse(str);

        public static bool IsNullOrEmpty(this string str)
            => string.IsNullOrEmpty(str);

        #endregion

        public static void ForEach<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (var item in source)
            {
                action(item);
            }
        }

        public static IEnumerable<T> Peek<T>(this IEnumerable<T> source, Action<T> action)
        {
            foreach (var item in source)
            {
                action(item);
            }
            return source;
        }
    }
}


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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  int n, m, a, b;
  cin >> n >> m;
  vector< pair<ll, ll> > d(n);
  for(int i = 0; i < n; ++i)
  {
    cin >> a >> b;
    d[i] = make_pair(a, b);
  }
  sort(d.begin(), d.end());

  ll ans = 0;
  ll cnt = 0;
  for(int i = 0; i < n; ++i)
  {
    if (cnt + d[i].second < m)
    {
      ans += d[i].first * d[i].second;
      cnt += d[i].second;
    }
    else
    {
      ans += d[i].first * (m - cnt);
      break;
    }
  }
  cout << ans;
}

int main()
{
  fastio;
  solve();

  return 0;
}

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

using namespace std;

int main(){
	int N, RES = 1e9, total_sum = 0, left_sum = 0;
	vector < int > W(101);
	cin >> N;
	for (int& w: W) {
		cin >> w;
		total_sum += w;
	}
	RES = min(RES, abs(total_sum - left_sum));
	for (int i = 0; i < N - 1; ++i) {
		left_sum += W[i];
		RES = min(RES, abs(2 * left_sum - total_sum));
	}
	cout << RES;
  	return 0;
}

Measured memory_bytes: 256
/* Dynamic Programming implementation of LCS problem */
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( string X, string Y, int m, int n ) 
{ 
int L[m+1][n+1]; 

/* Following steps build L[m+1][n+1] in bottom up fashion. Note 
	that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
for (int i=0; i<=m; i++) 
{ 
	for (int j=0; j<=n; j++) 
	{ 
	if (i == 0 || j == 0) 
		L[i][j] = 0; 
	else if (X[i-1] == Y[j-1]) 
		L[i][j] = L[i-1][j-1] + 1; 
	else
		L[i][j] = max(L[i-1][j], L[i][j-1]); 
	} 
} 

// Following code is used to print LCS 
int index = L[m][n]; 

// Create a character array to store the lcs string 
char lcs[index+1]; 
lcs[index] = '\0'; // Set the terminating character 

// Start from the right-most-bottom-most corner and 
// one by one store characters in lcs[] 
int i = m, j = n; 
while (i > 0 && j > 0) 
{ 
	// If current character in X[] and Y are same, then 
	// current character is part of LCS 
	if (X[i-1] == Y[j-1]) 
	{ 
		lcs[index-1] = X[i-1]; // Put current character in result 
		i--; j--; index--;	 // reduce values of i, j and index 
	} 

	// If not same, then find the larger of two and 
	// go in the direction of larger value 
	else if (L[i-1][j] > L[i][j-1]) 
		i--; 
	else
		j--; 
} 

// Print the lcs 
cout << lcs; 
} 

/* Driver program to test above function */
int main() 
{ 
string X,Y;
cin >> X >> Y;
int m = X.size(); 
int n = Y.size(); 
lcs(X, Y, m, n); 
return 0; 
} 


Measured memory_bytes: 35456
#include<bits/stdc++.h>
#ifdef LOCAL
#include "lib/debug.hpp"
#else
#define debug(...) 1
#endif
#define ALL(a) (a).begin(), (a).end()
#define rep(i, n) REP(i, 0, (n))
#define repc(i, n) REPC(i, 0, (n))
#define REP(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define REPC(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define REPCM(i, n, m) for (int i = (int)(n); i >= (int)(m); i--)
using namespace std;
using ll = int_fast64_t;
using pr = pair<ll, ll>;
using vll = vector<ll>;
using vpr = vector<pr>;
template<class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } else return false; }
template<class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } else return false; }

void answer() {
  ll a, b; cin >> a >> b;
  if(a>b) rep(i, a) cout << b;
  else rep(i, b) cout << a;
  cout << "\n";
}
int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  answer();
  return 0;
}

Measured memory_bytes: 256
n = int(input())
s=[]
for i in range(n):
    s.append(int(input()))

s.sort(key=lambda x:x%10)

if sum(s) % 10 != 0:
    print(sum(s))
elif s[-1] % 10>0:
    print(sum(s)-min(filter(lambda x:x%10>0,s)))
else:
    print(0)



Measured memory_bytes: 3060
#include<iostream>
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[100001]={0};
    for(int i=1;i<=n;i++) cin>>a[i];
    int x=1;
    int j=0;
    for(int i=1;i<=n;i++){
        j++;
        x=a[x];
        if(x==2){
            break;
        }
    }
    if(x==2) cout<<j;
    else cout<<-1;
}

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

int main() {
	int right_parenthises = 0, left_parenthises = 0;

	int length;
	std::string parenthises;

	std::cin >> length >> parenthises;

	for (int i = 0; i < length; i++) {
		if (parenthises[i] == '(') {
			left_parenthises++;
		} else {
			if (left_parenthises > 0) {
				left_parenthises--;
			} else {
				right_parenthises++;
			}
		}
	}

	for (int i = 0; i < right_parenthises; i++) {
		std::cout << '(';
	}

	std::cout << parenthises;

	for (int i = 0; i < left_parenthises; i++) {
		std::cout << ')';
	}
	std::cout << std::endl;
	return 0;
}

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

int main(){
  int n;
  cin>>n;
  
  int na=1;
  int ac=n+1;
  long long int mid=(ac+na)/2;
  while(na+1<ac){
    if(mid*(mid+1)/2>=n){
      ac=mid;
    }else{
      na=mid;
    }
    mid=(ac+na)/2;
  }
  
  int point=n;
  for(int i=ac;i>0;i--){
    if(i<=point){
      cout<<i<<endl;
      point-=i;
    }
  }
  return(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef vector<int> vi;
typedef vector<pair<int, int> > vpii;
typedef pair<int, int> pii;
typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
typedef vector<ll> vll;
typedef long double ld;
#define INF 0x3f3f3f3f
#define MOD 998244353LL
#define EPSILON 0.00001
#define f first
#define s second
#define pb push_back
#define mp make_pair
 
#define FOR(i, a, b) for (ll i=(a); i<=(signed)(b); i++)
#define F0R(i, a) for (ll i=0; i<(signed)(a); i++)
#define RFOR(i, a, b) for (int i=(a); i >= b; i--)

#define MN 200005
int n;
int a[MN];
int cnt[MN];
ll sm;

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

    cin >> n;
    FOR(i, 1, n){
        cin >> a[i];
        sm += cnt[a[i]];
        ++cnt[a[i]];
    }

    FOR(i, 1, n){
        cout << sm-cnt[a[i]]+1 << "\n";
    }

    return 0;
}


Measured memory_bytes: 3712
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	
	int t;
	cin >> t;
	cout << 3 * t * t << endl;


}

Measured memory_bytes: 256