akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
 
using namespace std;
 
int main() {
    int l;
    cin >> l;
 
    int tl = l;
    int dl = 0;
    bool te[20];
    int ce = 0;
    memset(te, 0, sizeof(te));
    while (l) {
        if (l & 1) {
            te[dl] = true;
            ce++;
        }
        l >>= 1;
        dl++;
    }
 
    cout << dl << " " << (dl-1)*2+ce-1 << endl;
    l = tl;
    int t = 1;
    for (int i = 1; i < dl; i++) {
        cout << i << " " << i+1 << " " << 0 << endl;
        cout << i << " " << i+1 << " " << t << endl;
        if (te[i-1]) {
            cout << i << " " << dl << " " << l - t << endl;
            l -= t;
        }
        t <<= 1;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main()
{
    int N, a[100], b[100], c[100], i, sum, temp;
    scanf("%d", &N);
    for (i = 1; i <= N; i++)
    {
        scanf("%d", &a[i]);
    }
    for (i = 1; i <= N; i++)
    {
        scanf("%d", &b[i]);
    }
    for (i = 1; i < N; i++)
    {
        scanf("%d", &c[i]);
    }
    sum = 0;
    temp = 10000;
    for (i = 1; i <= N; i++)
    {
        sum = sum + b[a[i]];
        if (a[i] - 1 == temp)
        {
            sum = sum + c[a[i - 1]];
        }
        temp = a[i];
    }
    printf("%d", sum);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include <algorithm>
#include<cstdio>
#include<string>
#include<math.h>
#include<vector>
#include <queue>
#include <bits/stdc++.h>
#include <map>
#include <cmath>
#include <cctype>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define srep(i,s,t) for (int i = s; i < t; i++)
#define drep(i,n) for(int i = (n)-1; i >= 0; i--)
using namespace std;
typedef vector<vector<char>> field_t;

typedef pair<int, int> point_t;
vector<vector<pair<int,int>>> z(100010);

char tolower(char c) {
  return (c + 0x20);
}
int main()
{
    
    
    int N,K,i,y;
    string S;
    cin >>N >>K;
    K--;
    cin >> S;
    S.at(K)=tolower(S.at(K)); 
    cout << S <<endl;
    return 0;
}

Measured memory_bytes: 2560
S=input()
left=S[0:2]
right=S[2:4]
MM=["01","02","03","04","05","06","07","08","09","10","11","12"]

if (left in MM)==False:
   if right in MM:
      print("YYMM")
   else:
      print("NA")

elif left in MM:
   if right in MM:
      print("AMBIGUOUS")
   else:
      print("MMYY")

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	ll n;
	cin>>n;
	ll a[n];
	for(ll i=0;i<n;i++)
	{
		cin>>a[i];
	}
	ll pre[n],suf[n];
	pre[0]=a[0];
	for(ll i=1;i<n;i++)
	{
		pre[i]=max(pre[i-1],a[i]);
	}
	suf[n-1]=a[n-1];
	for(ll i=n-2;i>=0;i--)
	{
		suf[i]=max(suf[i+1],a[i]);
	}
	for(ll i=0;i<n;i++)
	{
		ll ans=0;
		if (i>0)
			ans=max(ans,pre[i-1]);
		if (i<n-1)
			ans=max(ans,suf[i+1]);
		cout<<ans<<"\n";
	}

}

Measured memory_bytes: 6272
n=int(input())
s=input()
r=g=b=0
for i in s:
  if i=="R":r+=1
  elif i=="G":g+=1
  else:b+=1
ans=r*g*b
for i in range(n-2):
  for j in range(i+1,n-1):
    k=j+(j-i)
    if k>=n:break
    if not(s[i]==s[j] or s[j]==s[k] or s[i]==s[k]):ans-=1
print(ans)

Measured memory_bytes: 9156
#pragma GCC optimize ("Ofast")
#include "bits/stdc++.h"
	
#define PI 3.141592653589793
#define FAST ios::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
// Use for file I/O;
#define FIN string _fname = "paintbarn"; \
			string _is = _fname + ".in", _os = _fname + ".out"; \
			freopen(_is.c_str(), "r", stdin); \
			freopen(_os.c_str(), "w", stdout);

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

using namespace std;

const ll INF = 1e9 + 10;
const ll INF2 = 3e18 + 10;
const int MOD = 1e9 + 7;
const ld EPS = 1e-4;

const int LOGN = 19;
const int MAXN = 305;


inline void add_self(int &a, int b) {
	a = (a + b) % MOD;
}

ll dp[1 << 16];
ll t[1 << 16];
ll p[16][16];
int a[16];

int main() {
	FAST;

	int n;
	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> p[i][j];
		}
	}
	for (int i = 0; i < (1 << n); i++) dp[i] = -INF2;

	for (int mask = 0; mask < (1 << n); mask++) {
		for (int i = 0; i < n; i++) {
			if ((mask >> i) & 1) {
				for (int j = i + 1; j < n; j++) {
					if ((mask >> j) & 1) {
						t[mask] += p[i][j];
					}
				}
			}
		}
	}

	dp[0] = 0;
	int pn = (1 << n) - 1;
	for (int mask = 0; mask < (1 << n); mask++) {
		int m = mask ^ pn;
		for (int s = m; s; s=(s - 1) & m) {
			dp[s|mask] = max(dp[s|mask], dp[mask] + t[s]);
		} 
	}
	cout << dp[(1 << n) - 1];

}

Measured memory_bytes: 4680
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int x[110];
int y[110];
int v[110];
int main(){
	int a;
	while(scanf("%d",&a),a){
		for(int i=0;i<a;i++){
			scanf("%d%d%d",x+i,y+i,v+i);
		}
		double ret=999999999;
	//for(int T=0;T<100;T++){
		double tx=rand()%101;
		double ty=rand()%101;
		double mv=10;
		for(int i=0;i<10000;i++){
			double val=0;
			int at=0;
			for(int j=0;j<a;j++){
				double dis=sqrt((tx-x[j])*(tx-x[j])+(ty-y[j])*(ty-y[j]))/v[j];
				if(val<dis){
					val=dis;
					at=j;
				}
			}
			ret=min(ret,val);
			double dx=((double)x[at]-tx)*mv/val;
			double dy=((double)y[at]-ty)*mv/val;
			tx+=dx;ty+=dy;
			if(i%200==0)mv/=2;
		}
	//}
		printf("%.12f\n",ret);
	}
}

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

int main(){
    int N, X, T;
    cin >> N >> X >> T;
    int cnt = N/X;
    int add = N % X;
    if(add != 0){
        cnt++;
    }

    int ans = cnt * T;

    cout << ans << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,a,b;
	cin>>n>>a>>b;
	int ans=0;
	for(int i=0;i<=n;i++)
	{
		int u1=0,u2=i;
		while(u2>0)
		{
			u1+=u2%10;
			u2/=10;
		}
		if(u1>=a&&u1<=b)
		ans+=i;
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 256
// #include "pch.h"
#include <iostream>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <climits>
#include <string>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <ctime>
#include <cassert>
#include <fstream>
#include<unordered_map>

typedef long long ll;
typedef std::pair<int, int> Pii;
typedef std::pair<long long, long long> Pll;
typedef std::pair<double, double> Pdd;

#define rip(i, n, s) for (int i = (s);i < (int)( n ); i++)
#define mapa make_pair
#define all(a) a.begin(), a.end()
#define MM << " " <<

template<typename T>
using MaxHeap = std::priority_queue<T>;
template<typename T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

template<typename T>
void vdeb(std::vector<T> &da) {
	for (int i = 0;i < da.size();i++) {
		if (i == da.size() - 1) std::cout << da[i];
		else std::cout << da[i] << ' ';
	}
	std::cout << std::endl;
}
template<typename T>
void vdeb(std::vector<std::vector<T>> &da) {
	for (int i = 0;i < da.size();i++) vdeb(da[i]);
	std::cout << std::endl;
}

using namespace std;

long long gcd(ll x, ll y){
	if(x < y) swap(x,y);
	while(x%y){
		long long tmp = y;
		y = x%y; x = tmp;
	}
	return y;
}

int main(){
	int k; cin >> k;
	ll ans = 0;
	rip(i,k,0){
		rip(j,k,0){
			rip(l,k,0){
				// cout << i MM j MM l << endl;
				ans += gcd(gcd(i+1,j+1),l+1);
			}
		}
	}
	cout << ans << endl;
}


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

int main()
{
  string n;
  cin>>n;
  int max=0;
  for (int i=0;i<=n.size();i++)
  {
    int s=0,k=i;
    while (n[k]=='A' || n[k]=='C' || n[k]=='G' || n[k]=='T' )
    {
      s++;
      k++;
    }
    if (s>max) max=s;
  }
  cout<<max;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define endl "\n"
#define sz(x) (int)(x).size()
using namespace std;
typedef long long int lli;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

int main() {
    int k, x;
    cin >> k >> x;
    rep(i, (x-k+1), x+k) cout << i << " ";
    return 0;
}

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

int main() {
    int N,X,Y;
    cin >> N >> X >> Y;
    X--; Y--;
    double M=(Y-X)/2.0;
    vector<vector<int>> dist(N,vector<int>(N));
    vector<int> cnt(N,0);
    for(int i=0;i<N;i++){
        for(int j=i;j<N;j++){
            if(i<=X){
               if(j<=X+M){
                   dist.at(i).at(j)=j-i;
               }
               else if(j<=Y){
                   dist.at(i).at(j)=(X-i)+1+(Y-j);
               }
               else{
                   dist.at(i).at(j)=(X-i)+1+(j-Y);
               }
            }
            else if(i<=X+M){
                if(j<=X+M){
                   dist.at(i).at(j)=j-i;
               }
               else if(j<=Y){
                   dist.at(i).at(j)=min((i-X)+1+(Y-j),j-i);
               }
               else{
                   dist.at(i).at(j)=min((i-X)+1+(j-Y),j-i);
               }
            }
            else{
                dist.at(i).at(j)=j-i;
            }
            cnt.at(dist.at(i).at(j))++;
        }
    }
    for(int i=1;i<N;i++){
        cout << cnt.at(i) << endl;
    }
}


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

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  for(int i=0;i<n;i++) cin >> a[i];
  sort(a.begin(),a.end());
  
  long long ans=0;
  for(int i=1;i<n;i++){
    ans+=a[n-i/2-1];
  }
  
  cout << ans << endl;
}

Measured memory_bytes: 4008
import scala.io.StdIn._

object Helpers {
  def readIntLine = readLine.split(" ").map(_.toInt)
  def readInts(n: Int) = Array.fill(n)(readInt)

  def splitDigits(i: Int): Seq[Int] = i.toString.map(_.asDigit)

  def log[A](x: A): A = {println(x); x}

  implicit class IntImplicits(val i: Int) {
    def isEven = i % 2 == 0
    def isOdd = !isEven
  }
}

object Main extends App {
  import Helpers._

  val Array(n, m) = readIntLine
  val hs: Array[Int] = readIntLine

  var roads = Map[Int, Set[Int]]()
  for (_ <- Range(0, m)) {
    val Array(a, b) = readIntLine
    roads = if (roads.contains(a)) roads + (a -> (roads(a) + b)) else roads + (a -> Set(b))
    roads = if (roads.contains(b)) roads + (b -> (roads(b) + a)) else roads + (b -> Set(a))
  }

  def isGood(x: Int, roads: Map[Int, Set[Int]]): Boolean = {
    if (roads.contains(x + 1)) {
      val h = hs(x)
      !roads(x + 1).exists((a: Int) => (hs(a - 1) >= h))
    } else {
      true
    }
  }

  println(Range(0, n).count(isGood(_, roads)))
}



Measured memory_bytes: 90848
import math

n = 0
res = 0


def append(ds, r):
    global n, res
    if r == 0:
        if "3" in ds and "5" in ds and "7" in ds and int("".join(ds)) <= n:
            res += 1
        return
    for d in "357":
        append(ds + [d], r - 1)


def main():
    global n, res
    n = int(input())
    if n < 357:
        print(0)
        return
    r_max = int(math.log10(n)) + 1
    for r in range(3, r_max + 1):
        append([], r)
    print(res)


if __name__ == "__main__":
    main()


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

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl

int main(){
  const int N = 26;
  int D;
  cin >> D;
  vector<int> C(N);
  rep(i,N) cin >> C[i];
  vector<vector<int>> S(D, vector<int>(N));
  rep(i,D)rep(j,N) cin >> S[i][j];

  vector<int> current_penalty(N, 0);
  int score=0;
  rep(i,D){
    rep(j,N){
      current_penalty[j]+=C[j];
    }

    int mx=0;
    rep(j,N){
      if(S[i][mx]+current_penalty[mx]<S[i][j]+current_penalty[j])mx=j;
    }

    cout<<mx+1<<endl;

    score+=S[i][mx];
    current_penalty[mx]=0;
    rep(j,N){
      score-=current_penalty[j];
    }
  }
  //dbg(score);

  return 0;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
#define rep(i,m,n) for(int i=m;i<n;i++)
#define c(n) cin>>n
#define co(n) cout<<n<<endl
using namespace std;

int main(){
  long a,b,c=0,d=10000000,e,f,g,h,n,m,mx=0,x,y,ans=0;
  cin>>a>>b>>c>>x;
  rep(i,0,a+1){
    rep(j,0,b+1){
      rep(k,0,c+1){
        n=500*i+100*j+50*k;
        if(n==x) ans++;
      }
    }
  }
  co(ans);
    
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
	ll h,n;
	cin>>h>>n;
	ll a[n+1];
	for(ll i=0;i<n;i++)
	cin>>a[i];
	
	ll sum=0;
	for(ll i=0;i<n;i++)
	sum=sum+a[i];
	if(sum>=h)
	cout<<"Yes";
	else
	cout<<"No";
	
}


Measured memory_bytes: 1024
q,sub=map(int,input().split())
ac=[0 for i in range(q)]
sum_wa=[0 for i in range(q)]
waans=0
for i in range(sub):
    m,n=input().split()
    m=int(m)
    if n=='WA':
        if ac[m-1]==0:
            sum_wa[m-1]+=1
    elif n=='AC' and ac[m-1]==0:
        ac[m-1]+=1
        waans+=sum_wa[m-1]
print(sum(ac) ,waans)

Measured memory_bytes: 4656
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
using namespace std;
int main() {
	int A, B ,ans = 0;
	cin >> A >> B;
	if (A <= 5) {
		ans = 0;
	}
	else if (A <= 12) {
		ans = B / 2;
	}
	else {
		ans = B;
	}
	cout << ans << endl;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define mod 1000000007
ll fact[50];
#define eps 1e-9
#define INF 1e18
ll power(ll a,ll b,ll c){
  ll ans=1;
  while(b){
    if(b&1){
      ans=ans*a%c;
    }
    a=a*a%c;
    b=b/2;
  }
  return ans;
}
ll ncr(ll n,ll r){
    if(r>n)return 0;
    if(r==n)return 1;
    ll z=fact[n];
    z=z*power(fact[r],mod-2,mod)%mod;
    z=z*power(fact[n-r],mod-2,mod)%mod;
    return z;
}
ll min(ll a,ll b){return a<b?a:b;}
ll max(ll a,ll b){return a>b?a:b;}
ll gcd(ll a,ll b){
    if(b==0)return a;
    return gcd(b,a%b);
}

int main() {
   ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
   int n; cin>>n;
   ll sum=0;
   for(int i=1;i<=n;++i){
    for(int j=1;j<=n;++j){
        for(int k=1;k<=n;k++){
            sum+=gcd(i,gcd(j,k));
        }
    }
   }
   cout<<sum;
}


Measured memory_bytes: 3652
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>

#define INT_MAX 2147483647

int main(void){
    int N;
    scanf("%d", &N);
    
    int i = N;
    while(1) {
         if((int)(i/100) == (int)(i/10)%10 && (int)(i/100) == (int)(i%10)) {
             printf("%d\n", i);
             return 0;
         }
         else{
            i++;
         }
    }

    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>

using namespace std;

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

    int ans =0;
    for(int i=0; i<N; i++) {
        int x;
        cin >> x;
        ans += 2 * min(x, abs(x-K));
    }

    cout << ans << endl;
    return 0;
}


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

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) a / __gcd(a, b) * b /* 最小公倍数 */

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}

void Main() {
    u32 N;
    u64 K;
    cin >> N >> K;
    Vec<u32> A(N + 1);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }
    Vec<bool> B(N + 1, false);
    u32 index = 1;
    stack<u32> trace;
    int i = 0;
    if (K <= 2e5) {
        for (int i = 0; i < K; i++) {
            index = A[index];
        }
        cout << index << endl;
        return;
    }
    for (i = 0; i < N; i++) {
        if (B[index]) {
            break;
        }
        B[index] = true;
        trace.push(index);
        index = A[index];
    }
    u32 one_loop = 1;
    while(1) {
        if (trace.top() == index) break;
        trace.pop();
        one_loop++;
        i--;
    }
    K = K - i;
    u64 loop = K % one_loop;
    for (int i = 0; i < loop; i++) {
        index = A[index];
    }
    cout << A[index] << endl;
}


Measured memory_bytes: 4840
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define ar array
#define pb push_back
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	string s,t;
	cin>>s>>t;
	if(t.substr(0,s.length())==s)
		cout<<"Yes";
	else
		cout<<"No"<<endl;
	return 0;
}

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

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << setprecision(20);

  int H, W, h, w;
  cin >> H >> W >> h >> w;
  cout << H * W - H * w - W * h + h * w << endl;
  return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x, y) CPP_CAT_I(x, y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x, y) x##y

#define ASSERT(expr...) assert((expr))

using i8 = int8_t;
using u8 = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;
// }}}

constexpr i64 INF = 1'010'000'000'000'000'017LL;

constexpr i64 MOD = 1'000'000'007LL;

constexpr f64 EPS = 1e-12;

constexpr f64 PI = 3.14159265358979323846;

#define M5 100007
#define M9 1000000000

// util {{{
#define FOR(i, start, end) for (i64 i = (start), CPP_CAT(i, xxxx_end) = (end); i < CPP_CAT(i, xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)

#define ALL(f, c, ...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ##__VA_ARGS__); })(c))
#define ll long long int
#define VI vector<int>
template <typename C>
i64 SIZE(const C &c)
{
    return static_cast<i64>(c.size());
}

template <typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }

template <typename T, typename U, typename Comp = less<>>
bool chmax(T &xmax, const U &x, Comp comp = {})
{
    if (comp(xmax, x))
    {
        xmax = x;
        return true;
    }
    return false;
}

template <typename T, typename U, typename Comp = less<>>
bool chmin(T &xmin, const U &x, Comp comp = {})
{
    if (comp(x, xmin))
    {
        xmin = x;
        return true;
    }
    return false;
}
// }}}

// init {{{
struct ProconInit
{
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit()
    {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if (AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;
// }}}

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

bool isOK(int mid, double key)
{
}

int binary_search(double key)
{
    int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
    int right = 2000000000;
    /* どんな二分探索でもここの書き方を変えずにできる！ */
    while (right - left > 1)
    {
        int mid = left + (right - left) / 2;

        if (isOK(mid, key))
            right = mid;
        else
            left = mid;
    }

    /* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
    return right;
}

bool isKaibun(string st)
{
    bool ans = true;
    int n = st.length();
    REP(i, n / 2)
    {
        if (st[i] != st[n - i - 1])
        {
            return false;
        }
    }
    return true;
}

int toInt(char a)
{
    return a - '0';
}

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

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

void solve()
{
    ll A, B, N;
    cin >> A >> B >> N;

    ll m = min(N, B - 1);
    cout << setprecision(0) << fixed << floor((double)m * A / B) - A * floor((double)m / B);
}
signed main()
{

    solve();

    return 0;
}


Measured memory_bytes: 3800
Q = int(input())
qs = [input().split() for i in range(Q)]

import heapq
class Heapq:
    def __init__(self, arr, desc=False):
        if desc:
            arr = [-a for a in arr]
        self.sign = -1 if desc else 1
        self.hq = arr
        heapq.heapify(self.hq)

    def pop(self):
        return heapq.heappop(self.hq) * self.sign

    def push(self, a):
        heapq.heappush(self.hq, a * self.sign)

    def top(self):
        return self.hq[0] * self.sign

    def size(self):
        return len(self.hq)

lq = Heapq([], True)
rq = Heapq([], False)

ofs = 0
for q in qs:
    if q[0] == '2':
        print(lq.top(), ofs)
        continue
    _,a,b, = q
    a,b = int(a),int(b)
    ofs += b
    lq.push(a)
    rq.push(a)
    if lq.top() > rq.top():
        l,r = lq.pop(), rq.pop()
        ofs += abs(l-r)
        lq.push(r)
        rq.push(l)

Measured memory_bytes: 80632
#include<iostream>
using namespace std;
int main() {
	int x[3] = {}, f[3] = {};
	for (int i = 0; i < 3; i++) {
		cin >> x[i];
		if (x[i] == 7) {
			f[0] = true;
		}
		else if (f[1]&&x[i] == 5) {
			f[2] = true;
		}
		else if (x[i] == 5) {
			f[1] = true;
		}
		//cout << f[0] << f[1] << f[2] << endl;
	}
	if (f[0] && f[1] && f[2])puts("YES");
	else puts("NO");
	return 0;

}

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

#define SIZE 10000

int main(void)
{
    int n, q;
    int com, x, y;
    int rootX, rootY;
    int parent[SIZE + 1];
    
    cin >> n >> q;
    
    for(int i = 0; i <= n; ++i)
    {
        parent[i] = i;
    }
    
    for(int i = 0; i < q; ++i)
    {
        cin >> com >> x >> y;
        
        if(com == 0)
        {
            rootX = x;
            while(parent[rootX] != rootX)
                rootX = parent[rootX];
            rootY = y;
            while(parent[rootY] != rootY)
                rootY = parent[rootY];
            if(rootX < rootY)
                parent[rootY] = rootX;
            else
                parent[rootX] = rootY;
        }
        else if(com == 1)
        {
            rootX = x;
            while(parent[rootX] != rootX)
                rootX = parent[rootX];
            rootY = y;
            while(parent[rootY] != rootY)
                rootY = parent[rootY];
            if(rootX == rootY)
                cout << 1 << endl;
            else
                cout << 0 << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3128
#include <cstdio>
#include <cstring>
#include <iostream>
#include <vector>
#define debug(...) fprintf(stderr,__VA_ARGS__)
using namespace std;
template<class T> void read(T &x) {
	x=0; int f=1,ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10-'0'+ch;ch=getchar();}
	x*=f;
}
template<class T> inline bool Cmin(T &x,T y) {return x>y?x=y,1:0;}
const int inf=1e9;
const int maxn=1e5+50;
int N;
int an,mn;
int head[maxn],deg[maxn];
int siz[maxn];
int dp[maxn][2];
char c[maxn];
struct edge {
	int to,nex;
	edge(int to=0,int nex=0):to(to),nex(nex){}
};
vector<edge> G;
inline void addedge(int u,int v) {
	G.push_back(edge(v,head[u])),head[u]=G.size()-1;
	G.push_back(edge(u,head[v])),head[v]=G.size()-1;
	++deg[u],++deg[v];
}
void dfs0(int u,int fa) {
//	debug("%d %d\n",u,fa);
	siz[u]=c[u]=='W';
	for(int i=head[u];~i;i=G[i].nex) {
		int v=G[i].to; if(v==fa) continue;
		dfs0(v,u);
		siz[u]+=siz[v];
	}
	if(siz[u]==0) --deg[fa];
}
void dfs1(int u,int fa) {
//	debug("%d %d\n",u,fa);
	int w=deg[u]==1?0:((c[u]=='B')^deg[u])&1;
	if(deg[u]>1&&((c[u]=='W')^deg[u])&1) ++an,--w;
	for(int i=head[u];~i;i=G[i].nex) {
		int v=G[i].to; if(v==fa||!siz[v]) continue;
		an+=2;
		dfs1(v,u);
		int t=dp[v][0]-1;
		if(t<dp[u][0]) dp[u][1]=dp[u][0],dp[u][0]=t;
		else if(t<dp[u][1]) dp[u][1]=t;
	}
	dp[u][0]+=w;
	Cmin(mn,dp[u][0]+dp[u][1]);
}
int main() {
	read(N);
	memset(head,-1,sizeof(head));
	for(int i=1;i<N;++i) {
		int u,v; read(u),read(v);
		addedge(u,v);
	}
	scanf("%s",c+1);
	int rt=-1;
	for(int i=1;i<=N;++i) if(c[i]=='W') {rt=i;break;}
	if(rt==-1) {puts("0"); return 0;}
	dfs0(rt,0);
	if(deg[rt]==0) {puts("1"); return 0;}
	an=1,mn=inf,dfs1(rt,0);
//	debug("%d %d\n",an,mn);
	an+=mn;
	printf("%d\n",an);
	return 0;
}


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

int main()
{
    long n;
    cin >> n;
    static vector<int>a(100005),b(100005);
    for (int x,i = 0; i < n>>1; i++)
    {
        cin >> x;
        a[x]++;
        cin >> x;
        b[x]++;
    }
    long maxA = *max_element(a.begin(),a.end()), 
         maxB = *max_element(b.begin(),b.end());
    if (max_element(a.begin(),a.end())-a.begin() != max_element(b.begin(),b.end())-b.begin())
        cout << n-(maxA + maxB);
    else
    {
        a[max_element(a.begin(),a.end())-a.begin()] = 0;
        b[max_element(b.begin(),b.end())-b.begin()] = 0;
        long MaxA = *max_element(a.begin(),a.end()), 
             MaxB = *max_element(b.begin(),b.end());
        cout << min(n-MaxA-maxB, n-maxA-MaxB);
    }
    return 0;
}

Measured memory_bytes: 1024
/*Coded by::
    **Avinash Tiwary**
    **BE/10298/2015**
    **Production Engineer**
    **Producing <code>**
*/
#include<bits/stdc++.h>
#define buf ios_base::sync_with_stdio (0), cin.tie (0)
typedef long long ll;
typedef double dob;
#define MAX 50010
#define M5 200009
#define M6 2000009
#define M 1000000007
#define INF 1e18
using namespace std;
typedef vector<ll> V;
typedef queue<ll > Q;
typedef stack<ll> S;
typedef pair<ll,ll> P;
#define mp make_pair
#define mt make_tuple
#define pb push_back
ll fac[M6],not_prime[M6],n,ar[M5],dp[M6],sum[M6];
string s[1009];
ll power(ll x,ll n)
{   if(n==0||x==0) return 1;
    else if(n%2 == 0) return power((x*x),n/2);
    else return (x*power((x*x),(n-1)/2));
}
void fact(){
    fac[0]=1;
    for(ll i=1;i<M6;i++) fac[i]=(i*fac[i-1])%M;
}
void sieve(){
    not_prime[1]=1; not_prime[0]=1;
    for(ll p=2;p*p<M6;p++){
        if(!not_prime[p]){
            for(ll i=p*2;i<=MAX;i+=p) not_prime[i]=1;
        }
    }
}
ll modi(ll a, ll m){
    ll m0 = m, t, q; ll x0 = 0, x1 = 1;
    if (m == 1) return 0;
    while (a > 1){  q = a / m; t = m; m = a % m, a = t;t = x0;x0 = x1 - q * x0; x1 = t;}
    if (x1 < 0) x1 += m0;return x1;
}
vector<list<ll> >g(M5);
int main(){
    buf; 
    //sieve(); 
    //fact();
    ll l,r,i,j,test,ans,m,q; string s;
    test=1;
    while(test--){
        cin>>n;
        set<ll> ss;
        q=0; ans=0;
        for(i=1;i<=n;i++) {
            cin>>ar[i];
        }
        for(i=1;i<=n;i++){
            if(ar[i]==i){
                j=i;
                while(ar[j+1]==j) {j++;}
                while(j>=i){swap(ar[j],ar[j+1]),j--; ans++; j--;}
            }
        }
        cout<<ans;
    }
    return 0;
}

Measured memory_bytes: 7552
import sys
from heapq import heappop, heappush


adjacent = (
    (1, 3),        # 位置 0 に 0が存在したときに入れ替え可能な位置
    (0, 2, 4),     # 位置 1 に 0が存在したときに入れ替え可能な位置
    (1, 5),        # 位置 2 に 0が存在したときに入れ替え可能な位置
    (0, 4, 6),     # 位置 3 に 0が存在したときに入れ替え可能な位置
    (1, 3, 5, 7),  # 位置 4 に 0が存在したときに入れ替え可能な位置
    (2, 4, 8),     # 位置 5 に 0が存在したときに入れ替え可能な位置
    (3, 7),        # 位置 6 に 0が存在したときに入れ替え可能な位置
    (4, 6, 8),     # 位置 7 に 0が存在したときに入れ替え可能な位置
    (5, 7)         # 位置 8 に 0が存在したときに入れ替え可能な位置
)


def move(board, space, prev_space):
    for next_space in adjacent[space]:
        if next_space == prev_space:
            continue
        next_board = board[:]
        next_board[space], next_board[next_space] = next_board[next_space], 0
        yield next_board, next_space


end = [1, 2, 3, 4, 5, 6, 7, 8, 0]
discovered_state = set()  # すでに知っている状態を記録する


def search(start):
    discovered_state.add(tuple(start))
    heap = [(0, start, start.index(0), None)]  # 今の状態へ到達する手順回数

    while heap:
        i, board, space, prev = heappop(heap)

        if board == end:
            return i

        i += 1
        for next_board, next_space in move(board, space, prev):
            if tuple(next_board) in discovered_state:
                continue
            discovered_state.add(tuple(next_board))
            heappush(heap, (i, next_board, next_space, space))


def main():
    start = []
    for _ in range(3):
        start.extend(list(map(int, sys.stdin.readline().strip().split())))
    ans = search(start)
    print(ans)


if __name__ == '__main__':
    main()





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

#define int long long

vector<int> tree[200010];
int imos[200010];
int cnt[200010];

void solve(int idx, int par, int c){
    c += imos[idx];
    cnt[idx] = c;

    for(auto e : tree[idx]){
        if(e != par) solve(e, idx, c);
    }
    return;

}

signed main(){
    int n, q;
    cin >> n >> q;

    for(int i = 0;i < n-1;i++){
        int a, b;
        cin >> a >> b;
        a--; b--;
        tree[a].push_back(b);
        tree[b].push_back(a);
    }

    for(int i = 0;i < q;i++){
        int p, x;
        cin >> p >> x;
        imos[--p] += x;
    }

    solve(0, -1, 0);

    for(int i = 0;i < n;i++){
        cout << cnt[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 25856
#include <iostream>

using namespace std;

int main(void){

	int score, member, memo, found = 0;;
	cin >> member;
	int card[3][member];

	for(int i = 0; i < member; i++){
		for(int j = 0; j < 3; j++){
			cin >> card[j][i];
		}
	}
	for(int i = 0; i < 3; i++){
		for(int j = 0; j < member; j++){
			memo = card[i][j];
			for(int k = 0; k < member; k++){
				if(memo == card[i][k] && k != j){
					found++;
					card[i][k] = 0;
					card[i][j] = 0;
				}
			}
			if(found == 1){
				found = 0;
				card[i][j] = 0;
			}
		}
	}
	for(int i = 0; i < member; i++){
		score = 0;
		for(int j = 0; j < 3; j++){
			score += card[j][i];
		}
		cout << score << endl;
	}
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back 
#define eb emplace_back
#define fn for(int i =0 ;i <n;i++)
#define fn1 for( int i =1;i<=n;i++)
#define fm for(int j =0 ;j <m;j++)
#define fm1 for(int j =1;j<=m;j++)
#define fi first
#define se second
#define endl '\n'
# define PI  3.14159265358979323846
#define MOD 1000000007
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
const int N = 2e6+5;
const int INF = 1e18L;
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
int ar[N];
int dp[N];
signed main(){
	// #ifndef ONLINE_JUDGE
	// freopen("input.txt","r",stdin);
	// freopen("output.txt","w",stdout);
	// #endif
	IOS;
	int T=1;
	// cin >> T;
	while(T--){
		int n , m;
		cin >> n >>m;
		int tit =0;
		fm{
			cin >> ar[j];
			tit+=ar[j];
		}
		if(tit > n)cout <<"-1";else
		cout <<n-tit;
	
	
	}
	cerr << "Time Taken : " << 1.0 * clock() / CLOCKS_PER_SEC << " sec \n";
	return 0;
}

Measured memory_bytes: 3804
x, y = map(int, input().split())

flg = False
for i in range(101):
    for j in range(101):
        if (i * 2) + (j * 4) == y and (i + j) == x:
            print("Yes")
            flg = True
            break
    if flg == True:
        break
else:
    print("No")

Measured memory_bytes: 9184
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdio>

using namespace std;

int main(){
  int N, M, P[100010], Y[100010];
  vector< vector<int> > p(100010);
  
  cin >> N >> M;
  for(int i = 0;i < M;i++){
    cin >> P[i] >> Y[i];
    p[P[i]].push_back(Y[i]);
  }
  
  for(int i = 1;i <= N;i++) sort(p[i].begin(), p[i].end());
  
  for(int i = 0;i < M;i++) printf("%06d%06d\n", P[i], int(lower_bound(p[P[i]].begin(), p[P[i]].end(), Y[i]) - p[P[i]].begin()) + 1);
  
  return 0;
}

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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcountll

#define INF 1e16
#define mod 1000000007

ll N;

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

  cin>>N;
  set<P> st;
  repl(i,1,N){
    if(i==N-i)continue;
    st.insert(P(min(i,N-i),max(i,N-i)));
  }
  cout<<st.size()<<endl;

  return 0;
}


Measured memory_bytes: 31488
#include<stdio.h>

int main(void)
{
	int m[] = {0,3,3,6,1,4,6,2,5,0,3,5};
	char *d[] = {"Sunday","Monday","Tuesday","Wednesday","Thursday","Friday","Saturday"};
	int month, day, w;
	
	do {
		scanf("%d%d", &month,&day);
		if (month == 0)break;

		w = (104 + 26 + m[month - 1] + day)%7;
		if ((month == 1) || (month == 2)) {
			w = w - 1;
		}
		printf("%s\n",d[w]);
	} while (month != 0);


	return 0;
}

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

int main() {
    ll N, K;
    cin >> N >> K;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    ll one = 0;
    rep(i,N-1)for(int j=i+1;j<N;j++){
        if(A[i]>A[j]) one += 1;
    }

    ll two = 0;
    rep(i,N)rep(j,N){
        if(A[i]>A[j]) two += 1;
    }

    ll between = two % mod;
    ll nC2 = (K * (K - 1))/2 % mod;
    ll ans = ((one * K) % mod + (between * nC2) % mod) % mod;
    cout << ans << endl;
}


Measured memory_bytes: 256
num = int(input())
output = []
data = []

for x in range(num):
    data = input().split()
    for y in range(len(data)):
        data[y] = int(data[y])
    data.sort()
    if data[2]**2 == data[1]**2 + data[0]**2:
        output.append("YES")
    else:
        output.append("NO")

for x in range(num):
    print(output[x])


Measured memory_bytes: 7576
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String N = scan.next();
		if(N.substring(0, 1).equals("9") || N.substring(1, 2).equals("9")) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
		scan.close();
	}

}


Measured memory_bytes: 23892
n,k = map(int,input().split())
r = list(map(int,input().split()))

firstValue =  (r[0] / 2) + 0.5

#最初の1セットを計算して、maxSumと前回結果に設定
firstSet = r[0:k]
tempMax = 0
for p in firstSet:
    tempMax += (p / 2) + 0.5

maxSum = tempMax
beforeSum = tempMax

for i in range(k,n):
    lastValue = (r[i] /2)+0.5
    nowValue = beforeSum - firstValue + lastValue
    if nowValue > maxSum:
        maxSum = nowValue

    beforeSum = nowValue
    firstValue = (r[i-k+1]/2)+0.5

print(maxSum)

Measured memory_bytes: 71792
#include<iostream>
using namespace std;
long N,K,mi;
long f(long x){
    return abs(x-K);
}
int main(){
    cin>>N>>K;
    N=N%K;
    mi=N;
    for(int i=0;i<100000000;i++){
        N=f(N);
        mi=min(mi,N);
    }
    cout<<mi<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;

namespace Rectangle
{
	class MainClass
	{
		public static void Main (string[] args)
		{
			//???a cm??¨?¨?b cm?????\??????
			string[] ab = Console.ReadLine().Split(' ');

			//???
			int a = int.Parse (ab[0]);
			//?¨?
			int b = int.Parse (ab[1]);

			//????????¢?????¢???????±???????
			var area = a*b;
			//??¨?????????????±???????
			var periphery =(a+b)*2;
			Console.WriteLine (area+" "+periphery);

		}
	}
}

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

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;
const ull mod = 1e9 + 7;
#define REP(i,n) for(int i=0;i<(int)n;++i)
const ll INF = LLONG_MAX/3;

int main(){
    int n;
    cin >> n;
    ll a[n];
    REP(i, n) cin >> a[i];
    ll b[n];
    REP(i, n) b[i] = INF;
    REP(i, n){
        *lower_bound(b, b+n, a[i]) = a[i];
    }
    cout << lower_bound(b, b+n, INF)-b << endl;
    return 0;
}

Measured memory_bytes: 4640
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define All(V) V.begin(), V.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main()
{
	int n; cin >> n;
    vector<ll> v(n);
    ll ans = 1;
    rep(i, n){
        cin >> v[i];
        if(v[i] == 0){
            cout << 0 << endl;
            return 0;
        }
    }
    rep(i, n) ans *= v[i];
    if(ans <= (ll)1e18 && ans > 0)cout << ans << endl;
    else cout <<-1 << endl;
    system("pause");
}


Measured memory_bytes: 3992
H,W,K = map(int,input().split())
A = [[] for i in range(H)]
c = 0
f = 0
for i in range(H):
    S = input()
    if '#' in  S:
        t = 0
        c += 1
        for j in range(W):
            if S[j] == '.':
                A[i].append(c)
            else:
                if t > 0:
                    c += 1
                else:
                    t += 1
                A[i].append(c)
            if f > 0:
                for k in range(f):
                    A[k] = A[i]
                f = 0
    else:
        if i == 0:
            f = 1
        else:
            if f > 0:
                f += 1
            elif f == 0:
                for k in range(W):
                    A[i].append(A[i-1][k])
for i in range(H):
    L = [str(a) for a in A[i]]
    L = " ".join(L)
    print(L)

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

using namespace std;

using ll = long long;
using ull = unsigned long long;

int main(int argc, char const *argv[]) {
	int a,b,c;
	std::cin >> a >> b >> c;
	std::vector<bool> v(b,true);
	int i = 1;
	while (v[(i * a)%b]) {
		if ((i*a)%b == c) {
			std::cout << "YES" << '\n';
			return 0;
		}
		v[(i*a)%b] = false;
		i++;
	}
	std::cout << "NO" << '\n';
	return 0;
}


Measured memory_bytes: 256
import sys
from functools import reduce
import copy
import math
from pprint import pprint
import collections


sys.setrecursionlimit(4100000)


def inputs(num_of_input):
    ins = [input() for i in range(num_of_input)]
    return ins


def int_inputs(num_of_input):
    ins = [int(input()) for i in range(num_of_input)]
    return ins


def solve(inputs):
    A = string_to_int(inputs[0])
    counter = collections.Counter()
    del_num = 0
    LIMIT = 10 ** 5 + 1
    for a in A:
        if a >= LIMIT:
            del_num += 1
        else:
            counter[a] += 1
    for k in counter.keys():
        c = counter[k]
        if k > c:
            del_num += c
        else:
            del_num += c - k
    return del_num


def string_to_int(string):
    return list(map(int, string.split()))


if __name__ == "__main__":
    input()
    ret = solve(inputs(1))
    print(ret)


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

int main() {
  const int N_MAX = 200001;
  int n, k, a[N_MAX];
  cin >> n >> k;
  for (int i = 0; i < n; i++) cin >> a[i];
  int boll[N_MAX] = {0};
  for (int i = 0; i < n; i++) {
    boll[a[i] - 1]++;
  }
  sort(boll, boll + N_MAX);
  int notZero = 0;
  while (boll[notZero] == 0) notZero++;
  int kind = N_MAX - notZero;
  int res = 0;
  for (int i = 0; kind - i > k; i++) {
    res += boll[notZero + i];
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <cmath>
#include <deque>
#include <iostream>
#include <numeric>
#include <queue>
#include <sstream>
#include <string>
#include <string.h>
#include <tuple>
#include <vector>

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)
#define REPC(i,x) for(int i{ 0 }; i <= (int)(x); i++)
#define RREP(i,x) for(int i{ (int)(x) - 1 }; i >= 0 ;i--)
#define RREPC(i,x) for(int i{ (int)(x)}; i >= 0; i--)
#define REP1O(i,x) for(int i{ 1 }; i < (int)(x); i++)
#define REP1C(i,x) for(int i{ 1 }; i <= (int)(x); i++)

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef int64_t ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef pair<int, int> pii;
typedef tuple<int, int, int> tupiii;
typedef tuple<ll, ll, ll> tuplll;

const int INTMAX = 2147483647;
const ll LLMAX = 9223372036854775807;
const int MOD = 1000000007;

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; }
void swap(ll& a, ll& b) { a ^= b; b ^= a; a ^= b; }
void swap(int& a, int& b) { a ^= b; b ^= a; a ^= b; }


int n, m;
vvi g;
vi depth;

void init()
{
	cin >> n >> m;
	g.resize(n); 
	depth.resize(n, -1);

	REP(i, m)
	{
		int a, b; cin >> a >> b; --a; --b;
		g[a].PB(b);
	}
}

int dfs(int v)
{
	if (depth[v] != -1)
		return depth[v];

	int d = 1;
	for (int adj : g[v])
		chmax(d, 1 + dfs(adj));

	depth[v] = d;
	return d;
}

int main()
{
	init();

	int ans = 0;
	REP(i, n)
		chmax(ans, dfs(i));
	cout << ans - 1 << endl;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#define MAX ((int)(1e9))
#define pi (1.0*acos(-1))
#define M ((int)(258280327))
#define NN ((ll)(305))
#define N ((ll)(1e3+7))
#define eps 0
#define log 20


using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef unsigned long long ull;


typedef tree < ll,  null_type,  less < ll >,  rb_tree_tag,  tree_order_statistics_node_update > o_set;
queue < pair < int,int > > q;
int x[] = {-1,1,0,0};
int y[] = {0,0,-1,1};
int dis[N][N];
char s[N];
int main()
{
    int n, m;
    scanf("%d %d",&n,&m);
    memset(dis,-1,sizeof dis);
    for(int i = 0; i<=n+1; i++) dis[i][0] = dis[i][m+1] = 0;
    for(int j = 0; j<=m+1; j++) dis[0][j] = dis[n+1][j] = 0;
    for(int i = 0; i<n; i++){
        scanf("%s",s);
        for(int j = 0; j<m; j++){
            if(s[j]=='#'){
                q.push(make_pair(i+1,1+j));
                dis[i+1][1+j] = 0;
                //cout<<i<<" "<<j<<endl;
            }
        }
    }

    while(!q.empty()){
        pair < int,int > p = q.front();
        q.pop();
        int a = p.first, b = p.second;
        //cout<<a<<" "<<b<<endl;
        for(int i = 0; i<4; i++){
            int aa = a+x[i], bb = b+y[i];

            if(dis[aa][bb]==-1){
                dis[aa][bb] = dis[a][b]+1;
                q.push(make_pair(aa,bb));
            }
            //cout<<aa<<" "<<bb<<" "<<dis[aa][bb]<<endl;
        }
    }
    int ans = 0;
    for(int i = 1; i<=n; i++){
        for(int j = 1; j<=m; j++) ans = max(ans,dis[i][j]);
    }
    printf("%d\n",ans);
    return 0;
}


Measured memory_bytes: 12432
package main

import (
	"fmt"
	"sort"
)

func main() {
	var s string
	var k int
	fmt.Scan(&s, &k)

	b := make([]string, 0, len(s)*k)
	m := make(map[string]bool)
	for i := 0; i < len(s); i++ {
		for j := 0; j <= k && i+j < len(s); j++ {
			if _, ok := m[s[i:i+j+1]]; !ok {
				m[s[i:i+j+1]] = true
				b = append(b, s[i:i+j+1])
			}
		}
	}
	sort.Strings(b)

	fmt.Println(b[k-1])
}


Measured memory_bytes: 2432
#include <algorithm>
#include <iostream>
#include <cstring>
#include <vector>
#include <cstdio>
#define INF 999999999
#define bit_set(integer,offset)   ((integer)|=1<<(offset))
#define bit_clear(integer,offset) ((integer)&=~(1<<(offset)))
#define bit_check(integer,offset) ((integer)&(1<<(offset)))
using namespace std;
int n,m,dp[16][33000],f[20][20];
char s[20][30],str[20][30];
int cal(char *a,char *b)
{
    int la=strlen(a),lb=strlen(b);
    for(int i=min(la-1,lb-1);i>=0;i--)
    {
        bool ok=true;
        for(int j=la-1,k=i;j>=0&&k>=0;j--,k--) if(b[k]!=a[j]) {ok=false;break;}
        if(ok) return i+1;
    }
    return 0;
}
int main()
{
    //freopen("in.txt","r",stdin);
    while(scanf("%d",&n)==1)
    {
        if(n==0) break;
        for(int i=0;i<n;i++) scanf("%s",s[i]);
        m=0;
        bool vis[20];
        memset(vis,0,sizeof(vis));
        for(int i=0;i<n;i++)
        {
            if(vis[i]) continue;
            for(int j=0;j<n;j++)
            {
                if(vis[j]||i==j) continue;
                if(strstr(s[i],s[j])) vis[j]=true;
            }
        }
        int le[20];
        for(int i=0;i<n;i++)
        {
            if(vis[i]) continue;
            int l=strlen(s[i]);
            strcpy(str[m],s[i]);
            le[m]=strlen(s[i]);
            m++;
        }
        for(int i=0;i<m;i++)
            for(int j=0;j<m;j++) f[i][j]=cal(str[i],str[j]);
        int M=1<<m;
        for(int i=0;i<m;i++)
        {
            for(int j=0;j<M;j++) dp[i][j]=INF;
            dp[i][1<<i]=le[i];
        }
        for(int j=1;j<M;j++)
        {
            for(int i=0;i<m;i++)
            {
                if(bit_check(j,i)==0) continue;
                for(int k=0;k<m;k++)
                {
                    if(bit_check(j,k)!=0) continue;
                    dp[k][j|(1<<k)]=min(dp[k][j|(1<<k)],dp[i][j]+le[k]-f[i][k]);
                }
            }
        }
        int ans=INF;
        for(int i=0;i<m;i++) ans=min(ans,dp[i][M-1]);
        printf("%d\n",ans);
    }
}

Measured memory_bytes: 2164
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(a); (i)<(b); ++(i))
#define rFor(i, a, b) for(int (i)=(a)-1; (i)>=(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef pair<int, int> pii;

int main(){
    double n, m, d;
    scanf("%lf%lf%lf", &n, &m, &d);
    printf("%.10lf\n", (2-(d==0))*(n-d)*(m-1) / (n*n));
}

Measured memory_bytes: 256
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <climits>
#include <fstream>
#include <iomanip>
using namespace std;
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toStr(T x) { ostringstream sout; sout << x; return sout.str(); }
typedef vector<int> vi;
typedef vector<vi>  vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(),(a).rend()
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n) FOR(i,0,(n)-1)
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 2;
const int MOD = 1000000007;
typedef vector<ll> vl;
typedef vector<vl> vvl;

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

	int L = S.length();
	int ans0 = 0, ans1 = 0;
	REP(i, L) {
		char c = '0' + (i % 2);
		if (S[i] != c) {
			ans0++;
		}
	}

	REP(i, L) {
		char c = '1' - (i % 2);
		if (S[i] != c) {
			ans1++;
		}
	}
	cout << min(ans0, ans1) << endl;
	return 0;
}

Measured memory_bytes: 512
#include <stdio.h>
#include <math.h>
#include <string.h>
#define pai 3.1415926535

int main(void) {
	
	int N;
	scanf("%d", &N);
	int a[100];
	for (int i = 0; i < N; i++) {
		scanf("%d", &a[i]);
	}
	int b = 0;
	int sum = 0;

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N - 1 - i; j++) {
			if (a[j] > a[j + 1]) {
				b = a[j];
				a[j] = a[j + 1];
				a[j + 1] = b;
			}
		}
	}

	for (int i = 0; i < N-1; i++) {
		sum += a[i + 1] - a[i];

	}

	printf("%d", sum);
	
	return 0;

}

Measured memory_bytes: 128
n=int(input())
da=list(map(int,input().split()))
chco=0
flag=1
while flag:
    flag=0
    for i in range(n-1,0,-1):
        if da[i]<da[i-1]:
            da[i],da[i-1]=da[i-1],da[i]
            flag=1
            chco+=1
for i in range(n):
    if i==n-1:
        print(da[i])
    else:
        print(da[i],end=' ')
print(chco)


Measured memory_bytes: 5612