akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1e9+7;
const int INF=1e9;
const ll LINF=(ll)1e18;

struct UnionFind{
private:
    vector<int> par;
    vector<int> rank;
public:
    UnionFind(int n){
        par.resize(n);
        rank.resize(n);
        for (int i=0;i<n;i++){
            par[i]=i;
            rank[i]=0;
        }
    }
    int root(int x){
        if(par[x]==x)return x;
        else return par[x]=root(par[x]);
    }
    bool issame(int x,int y){
        return root(x)==root(y);
    }
    bool merge(int x,int y){
        x=root(x);
        y=root(y);
        if(x==y)return false;
        if(rank[x]<rank[y])swap(x,y);
        if(rank[x]==rank[y])++rank[x];
        par[y]=x;
        return true;
    }
};

int main(){
    int h,w;
    cin>>h>>w;
    string s[h];
    for(int i=0;i<h;i++){
        cin>>s[i];
    }
    UnionFind uf(h*w);
    const int dx[]={-1,0,0,1};
    const int dy[]={0,-1,1,-0};
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            for(int k=0;k<4;k++){
                int nx=i+dx[k];
                int ny=j+dy[k];
                if(nx<0||h<=nx||ny<0||w<=ny)continue;
                if(s[i][j]!=s[nx][ny]){
                    uf.merge(i*w+j,nx*w+ny);
                }
            }
        }
    }
    int bcnt[h*w]={};
    int ccnt[h*w]={};
    ll ans=0;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            int r=uf.root(i*w+j);
            if(s[i][j]=='#')bcnt[r]++;
            else ccnt[r]++;
        }
    }
    for(int i=0;i<h*w;i++){
        ans+=(ll)bcnt[i]*ccnt[i];
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 2944
#!/usr/bin/env python3
#
# Author: Tetsuya Ishikawa <tiskw111@gmail.com>
# Date  : June 30, 2020
##################################################### SOURCE START #####################################################

ss = input().strip()
xs = [1 for s in ss if s == '1']
print(sum(xs))

##################################################### SOURCE FINISH ####################################################
# vim: expandtab tabstop=4 shiftwidth=4 fdm=marker


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

// nCr mod を計算する O(n)
const int MAX_N = 1000010;
ll fac[MAX_N], finv[MAX_N], inv[MAX_N];
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX_N; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

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

    ll ans=0;
    COMinit();
    for(int i=1;i<s/3+1;i++){
        int k=s-3*i;
        ans=(ans+COM(k+i-1,i-1))%MOD;
    }

    cout<<ans<<endl;
} 


Measured memory_bytes: 27076
/*                         _
                        _ooOoo_
                       o8888888o
                       88" . "88
                       (| -_- |)
                  .'  \\|     |//  `.
                 /  \\|||  :  |||//  \
                /  _||||| -:- |||||_  \
                |   | \\\  -  /'| |   |
                | \_|  `\`---'//  |_/ |
                \  .-\__ `-. -'__/-.  /
              ___`. .'  /--.--\  `. .'___
           ."" '<  `.___\_<|>_/___.' _> \"".
          | | :  `- \`. ;`. _/; .'/ /  .' ; |
          \  \ `-.   \_\_`. _.'_/_/  -' _.' /
===========`-.`___`-.__\ \___  /__.-'_.'_.-'================

                  Please give me AC.
*/
#include<bits/stdc++.h>
#define mem(a) memset(a,0,sizeof(a))
#define INF 0x3f3f3f3f
#define Min 1e-6
#define lowbit(x) ((x)&(-x))
#define ls rt<<1
#define rs rt<<1|1
#define ll int

using namespace std;

const int N = 2e5 + 7;
const int M = 1e9 + 7;
const ll Mod = 1e9 + 7;

int i,j,n,m,t,T,p,l,r,q,len,len1,v,u,k,w,st,res,cnt,ans,tmp,nex,a[N];
double b;
string s;

int main()
{
    ios::sync_with_stdio(false);
    mem(a);
    scanf("%lf",&b);
    printf("%.12f",pow(b/3,3));
    return 0;
}



Measured memory_bytes: 1280
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (int)(n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()
using namespace std;
using ll = long long;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  if (k == 1) {
    cout << 0 << endl;
  } else {
    cout << (n - k) << endl;
  }
}


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

typedef struct {
	int value;
	char symbol;
}Card;

void selectionSort(Card A[], int N) {
	for (int i = 0;i < N;i++) {
		int minj = i;
		for (int j = i + 1;j < N;j++) {
			if (A[j].value < A[minj].value)
				minj = j;
		}
		if (i != minj) {
			swap(A[i], A[minj]);      //??\??? : ??¢??°swap???????????¶??????????????§????????¨???
		}
	}
}

void bubbleSort(Card A[], int N) {
	for (int i = 0;i<N;i++) {
		for (int j = N - 1;j >= i + 1;j--) {
			if (A[j].value<A[j - 1].value)
				swap(A[j], A[j - 1]);
		}
	}
}

int main() {
	Card A[36], B[36];
	int N;
	cin >> N;

	for (int i = 0;i<N;i++) {
		cin >> A[i].symbol >> A[i].value;
		B[i].value = A[i].value;
		B[i].symbol = A[i].symbol;
	}

	bubbleSort(A, N);
	selectionSort(B, N);

	bool flagS = 1;

	for (int i = 0;i<N;i++) {
		if (i) cout << " ";
		cout << A[i].symbol << A[i].value;
	}

	cout << endl << "Stable" << endl;

	for (int i = 0;i<N;i++) {
		if (i) cout << " ";
		cout << B[i].symbol << B[i].value;
		if (B[i].symbol != A[i].symbol) flagS = 0;
	}

	cout << endl << (flagS ? "Stable" : "Not stable") << endl;

	return 0;
}

Measured memory_bytes: 3108
N = int(input())
A = list(map(int, input().split()))
from_left = [A[0]]
from_right = [A[-1]]

for i in range(1, N):
    from_left.append(from_left[-1]+A[i])
    from_right.append(from_right[-1]+A[N-i-1])
from_right.reverse()
ans = float('inf')
for i in range(N-1):
    ans = min(ans, abs(from_left[i]-from_right[i+1]))
print(ans)


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

int main()
{
    int h, w, n, p;

    scanf("%d %d %d", &h, &w, &n);

    p = max(h, w);

    if(n % p == 0)
    printf("%d\n", n/p);
    else
    printf("%d\n", (n/p)+1);

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    int k;
    cin >> k;
    if (k % 2 == 0){
        cout << (k / 2) * (k / 2) << endl;
    }else{
        cout << (k / 2 + 1) * (k / 2) << endl;
    }
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;

const int MAXN=1e5+5;

int n,m,cnta,cntb;
int sum_a[MAXN],sum_b[MAXN];

int main(){
    scanf("%d%d",&n,&m);
    for(int i=1;i<=n;i++){
        int x;
        scanf("%d",&x);
        if(x<=0) sum_a[++cnta]=abs(x);
        else sum_b[++cntb]=x;
    }
    reverse(sum_a+1,sum_a+cnta+1);
    int ans=0x3f3f3f3f;
    for(int p=0;p<=m;p++){
        int x=p,y=m-p;
        if(x>cnta||y>cntb) continue;
        ans=min(ans,min(sum_a[x]*2+sum_b[y],sum_a[x]+sum_b[y]*2));
    }
    printf("%d",ans);
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I = (A); I < (B); ++I)
const ll INF=1e9+7;
const ll N = 100002;
ll iro[8],ziyu=0,n,saisyo=0;

int main(){
	cin>>n;
	FOR(i,0,8)iro[i]=0;
	FOR(i,0,n){
		ll a;
		cin>>a;
		if(a<3200)iro[a/400]=1;
		else ziyu++;
	}
	FOR(i,0,8){
		if(iro[i]==1){
			saisyo++;
		}
	}
	if(saisyo==0&&ziyu>0){
		saisyo=1;
		ziyu--;
	}
	cout<<saisyo<<" "<<saisyo+ziyu<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <stack>
using namespace std;
int n, d;
int x, y;
vector<string> v1, v2;
int main() {
    cin >> n;
    for(int i=0; i<n; ++i){
        string str; cin >> str;
        v1.push_back(str);
        v2.push_back(str);
    }
    for(int i=0; i<n; ++i){
        for(int j=n-1; j>i; j--){
            if(v1[j][1]<v1[j-1][1]) swap(v1[j],v1[j-1]);
        }
    }
    int minj=0;
    for(int i=0; i<n; ++i){
        minj = i;
        for(int j=i; j<n; ++j){
            if(v2[minj][1]>v2[j][1]){
                minj = j;
            }
        }
        swap(v2[minj], v2[i]);
    }
    for(int i=0; i<n; ++i){
        if(i==n-1){
            cout << v1[i] << endl;;
            break;
        }
        cout << v1[i] << " ";
    }
    cout << "Stable" << endl;
    for(int i=0; i<n; ++i){
        if(i==n-1){
            cout << v2[i] << endl;;
            break;
        }
        cout << v2[i] << " ";
    }
    for(int i=0; i<n; ++i){
        if(v1[i]!=v2[i]){
            cout << "Not stable" << endl;
            break;
        }
        if(i==n-1) cout << "Stable" << endl;
    }
    return 0;
}


Measured memory_bytes: 3176
#ifndef HOME
#pragma GCC optimize "-O3"
#endif

#include <bits/stdc++.h>

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

int main() {
    ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
    string s;
    cin >> s;
    int n = s.size();
    s += '#';
    vector<string> go;
    string cur;
    for (int i = 0; i < n; i++) {
        if (s[i] == 'A') {
            cur += 'A';
        } else {
            if (s[i] == 'B' && s[i + 1] == 'C') {
                cur += 'B';
                i++;
            } else {
                if (!cur.empty()) {
                    go.push_back(cur);
                }
                cur.clear();
            }
        }
    }
    if (!cur.empty()) {
        go.push_back(cur);
    }
    ll ans = 0;
    for (auto s : go) {
        int k = s.size();
        int cb = 0;
        for (int i = k - 1; i >= 0; i--) {
            if (s[i] == 'A') {
                ans += cb;
            } else {
                cb++;
            }
        }
    }

    cout << ans << "\n";

    return 0;
}



Measured memory_bytes: 3216
/*
 *created by Kraken on 19-04-2020 at 17:29
 */
//package com.kraken.atcoder.abc163;

import java.util.*;
import java.io.*;

public class Main {

  public static void main(String[] args) {
    FastReader sc = new FastReader();
    double r = sc.nextInt();
    double pi = 3.141592653;
    System.out.println(2 * pi * r);
  }

  static class FastReader {

    BufferedReader br;

    StringTokenizer st;

    public FastReader() {
      br = new BufferedReader(new InputStreamReader(System.in));
    }

    String next() {
      while (st == null || !st.hasMoreElements()) {
        try {
          st = new StringTokenizer(br.readLine());
        }
        catch (IOException e) {
          e.printStackTrace();
        }
      }
      return st.nextToken();
    }

    int nextInt() {
      return Integer.parseInt(next());
    }

    long nextLong() {
      return Long.parseLong(next());
    }

    double nextDouble() {
      return Double.parseDouble(next());
    }

    String nextLine() {
      String str = "";
      try {
        str = br.readLine();
      }
      catch (IOException e) {
        e.printStackTrace();
      }
      return str;
    }
  }
}


Measured memory_bytes: 33288
#pragma GCC optimize("O3")

#define _GLIBCXX_DEBUG
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <list>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
using namespace std;

/*----------macros----------*/

//output================
#define endl '\n'
#define fcout cout << fixed << setprecision(15)

//typedef===============
typedef long long       ll;
typedef long double     ld;
typedef pair<int, int>  Pii;
typedef pair<ll, ll>    Pll;

//const number==========
constexpr ll INF9   = (ll)1e9 + 1;
constexpr ll INF18  = (ll)1e18 + 1;
constexpr ll MOD    = 1000000007;
constexpr ld PI     = 3.141592653589793L;

//member================
#define pb push_back
#define eb emplace_back
#define pf push_front
#define mp make_pair
#define fi first
#define se second

//others================
#define all(x)          (x).begin(), (x).end()
#define rall(x)         (x).rbegin(), (x).rend()
#define rep(i, n)       for(int i = 0; (i) < (n); ++(i))
#define reps(i, n)       for(int i = 1; (i) <= (n); ++(i))
#define rrep(i, n)      for(int i = n - 1; (i) >= 0 ; --(i))
#define CtoI(c)         int((c)) - int('0')
#define ItoC(c)         char((c) + '0')

//functions=============
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }

template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

//vector<int> dx = {1, 0, -1, 0}, dy = {0, 1, 0, -1};
//vector<int> dx2 = { 1,1,0,-1,-1,-1,0,1 }, dy2 = { 0,1,1,1,0,-1,-1,-1 };

/*--------additional--------*/



/*----------main------------*/

int main() {
/*----------fastio----------*/
    std::cin.tie(nullptr);
    std::cout.tie(nullptr);
    std::ios::sync_with_stdio(false);
/*----------solve-----------*/

    int n; cin >> n;
    vector<string> s(n);
    vector<int> t(n);
    
    int sumt = 0;
    rep(i, n){
        cin >> s[i] >> t[i];
        sumt += t[i];
    }
    string x; cin >> x;

    int stop = 0;
    rep(i, n){
        if(x == s[i]){
            stop = i;
        }
    }

    rep(j, stop+1) sumt -= t[j];

    cout << sumt << endl;

return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>

int main(){
  int N,i,j,count=0,A[100],minj,k,l=1,m;
  scanf("%d",&N);
  for(i=0;i<N;i++){
    scanf("%d",&A[i]);
  }
  /*for(i=0;i<N;i++){
    printf("%d ",A[i]);
    }*/
  for(i=0;i<N;i++){
    minj=i;
    for(j=i;j<N-1;j++){
      if(A[minj]>A[j+1]){
	minj=j+1;
	
      }
    }
    if(minj!=i){
      k=A[minj];
      A[minj]=A[i];
      A[i]=k;
      count++;
    }
  }
  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i<N-1)printf(" ");
    else if(i==N-1)printf("\n");
    }
  printf("%d\n",count);
  return 0;
}
      
  



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

typedef long long ll;
const ll INF = 1e18;
const int BIG = 1e9 + 555;

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

	int n;	cin >> n;
	int oddCnt = 0, evenCnt = 0, div4Cnt = 0;
	for(int i = 1; i <= n; i++){
		int x;	cin >> x;
		if(x % 4 == 0){
			div4Cnt++;
			continue;
		}
		if(x % 2 == 0){
			evenCnt++;
		}
		if(x % 2 != 0){
			oddCnt++;
		}
	}
	
	if(evenCnt == 0){
		if(div4Cnt >= max(oddCnt - 1, 1)){
			cout << "Yes\n";
		} else {
			cout << "No\n";
		}
		return 0;
	}

	if(oddCnt == 0){
		cout << "Yes\n";
		return 0;
	}
	
	oddCnt++;
	if(div4Cnt >= max(oddCnt - 1, 1)){
		cout << "Yes\n";
		return 0;
	}

	cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"

using namespace std;

using ll = long long;

template<typename T> using V = std::vector<T>;
using Vi = V<int>;
using VVi = V<V<int>>;
using Vl = V<ll>;
using VVl = V<V<ll>>;
using Vs = V<string>;

template<typename T1, typename T2> using P = std::pair<T1, T2>;
using Pii = P<int, int>;
using Pll = P<ll, ll>;
using Pdd = P<double, double>;

template<typename T1, typename T2> using M = std::map<T1, T2>;
using Mii = M<int, int>;
using Msi = M<string, int>;

#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REP2(i,s,e) for(int i=(int)(s);i<(int)(e);++i)
#define RREP(i,s,e) for(int i=(int)(s);i>=(int)(e);--i)
#define ALL(c) (c).begin(), (c).end()

const double PI = acos(-1);
const ll MOD = 1e9+7;

int n;
// string s;

int main() {
    cin >> n;

    V<Pll> v(n);
    REP(i, n) {
        ll d, c; cin >> d >> c;
        v[i] = {d, c};
    }

    ll digit = 0, sum = 0;
    for (auto x: v) {
        digit += x.second;
        sum += x.first * x.second;
    }

    std::cout << digit - 1 + (sum - 1) / 9 << '\n';

    return 0;
}


Measured memory_bytes: 3328
n = int(input())
h = [int(i) for i in input().split()]
dp = [1000000000 for i in range(n)]
dp[0] = 0
dp[1] = abs(h[1]-h[0])
for i in range(2,n):
    dp[i] = min(dp[i-2]+abs(h[i-2]-h[i]),dp[i-1]+abs(h[i-1]-h[i]))
print(dp[n-1])


Measured memory_bytes: 13924
fun main() = Thread(null, ::abc172c, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun abc172c() {
    val (n, m, k) = readLine()!!.split(' ').map { it.toInt() }
    val aList = readLine()!!.split(' ').map { it.toLong() }
    val bList = readLine()!!.split(' ').map { it.toLong() }

    var takeB = m
    var timeSumA = 0L
    var timeSumB = bList.sum()
    var answer = 0

    for (takeA in 0..n) {
        while (timeSumA + timeSumB > k && takeB > 0) {
            timeSumB -= bList[takeB - 1]
            takeB--
        }

        if (timeSumA + takeB > k) break
        
        answer = Math.max(answer, takeA + takeB)

        if (takeA in aList.indices) timeSumA += aList[takeA]
    }

    println(answer)
}


Measured memory_bytes: 82124
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
	long long int N;
	cin>>N;
	vector<long long int> W;
	for(int i=0;i<5;i++){
		long long int a;
		cin>>a;
		W.push_back(a);
	}
	sort(W.begin(), W.end());
	long long int min = *W.begin();
	long long int kaisu; // 4 + N/min;
	if(N%min==0)
		kaisu = 4 + N/min;
	else
		kaisu = 5 + N/min;
	cout<<kaisu;
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int a,b;
  scanf("%d%d",&a,&b);
  if(a<=9 && a>=1 && b<=9 && b>=1){
    printf("%d\n",a*b);
  }
  else{
    printf("-1\n");
  }
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <iomanip>
#include <cmath>
#include <map>
using namespace std;
using ll = long long;
constexpr ll MOD = 1e9 + 7;
constexpr int INF = 1 << 30;

int main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int N, M;
  string S;
  cin >> N >> M >> S;
  // 後ろからの最短手数
  // 最短手数を満たす動かし方の中で辞書順最小を求める。
  // なるべく後ろから動きたいのでqueueを使う。
  vector<int> dist(N + 1, INF);
  queue<int> q;
  dist[N] = 0;
  q.push(N);
  for (int i = N - 1; i >= 0; --i)
  {
    if (S[i] == '1')
      continue;
    while (q.front() - i > M || dist[q.front()] == INF)
    {
      if (q.empty())
      {
        cout << -1;
        return 0;
      }
      q.pop();
    }
    dist[i] = dist[q.front()] + 1;
    q.push(i);
  }

  vector<int> ans;
  int pos = 0;
  int rest = dist[0];
  while (pos != N)
  {
    --rest;
    int move = 1;
    while (dist[pos + move] != rest)
      ++move;
    pos += move;
    ans.push_back(move);
  }

  for (int i = 0; i < ans.size(); ++i)
    cout << ans[i] << " \n"[i == ans.size() - 1];
  return 0;
}

Measured memory_bytes: 1484
#include <bits/stdc++.h>
using namespace std;
 
int main() {

  int keijiban = 1;
  int N, K;
  cin >> N;
  cin >> K;
  for(int i = 0; i < N; i++) {
  	if(keijiban * 2 < keijiban + K)
    	keijiban *= 2;
  	else
  		keijiban += K;
  }
  cout << keijiban << endl;
}

Measured memory_bytes: 256
inf = 10**15
mod = 10**9+7
s = input()
t = input()
lenn = len(s)
lent = len(t)
ans = []
for i in range(lenn-lent+1):
    flag = True
    tmp = ['' for i in range(lenn)]
    for j,k in enumerate(range(i,i+lent)):
        if (s[k] != t[j]) and (s[k] != '?'):
            flag = False
            break
        else:
            tmp[k]=t[j]
    if flag:
        for l in range(lenn):
            if tmp[l] == '':
                if s[l] == '?':
                    tmp[l] = 'a'
                else:
                    tmp[l] = s[l]
        ans.append(''.join(tmp))
ans.sort()
if ans:
    print(ans[0])
else:
    print('UNRESTORABLE')

Measured memory_bytes: 39856
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);++i)
#define ALL(v)   (v).begin(),(v).end()
#define debug(x) cerr<<#x<<": "<<(x)<<endl
#define INF      (int)1e9
#define EPS      (double)1e-9
#define MOD      ((int)1e9+7)
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
template<class Type> void line(const Type &a){int cnt=0;for(const auto &elem:a){if(cnt++)cout<<' ';cout<<elem;}cout<<endl;}

int main(){
	int n;
	cin>>n;
	
	vi a(n);
	vi cnt(n+1,0);
	REP(i,n){
		cin>>a[i];
		cnt[a[i]]++;
	}
	
	llong sum=0;
	REP(i,n+1) sum+=(llong)cnt[i]*(cnt[i]-1)/2;
	
	vector<llong> ans(n);
	REP(i,n){
		llong tmp=sum-(llong)cnt[a[i]]*(cnt[a[i]]-1)/2;
		tmp+=(llong)(cnt[a[i]]-1)*(cnt[a[i]]-2)/2;
		ans[i]=tmp;
	}
	
	line(ans);
}

Measured memory_bytes: 5760
#include<stdio.h>
#include<math.h>
int main(void){
  int a,b,c,d;
  scanf("%d %d %d",&a,&b,&c);
  while((b/a)>=1){
    if(b<a)break;
    if(d>=c)break;
	d++;
	b=b-a;
}
  printf("%d",d);
  return 0;
}


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

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

using namespace std;

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

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

typedef long long ll;

void solve() {

}

int n;
#define MAX 200010
vector<int> G[MAX];

int main() {
  cin >> n;
  int v;
  REP(i,1,n) {
    cin >> v;
    --v;
    G[v].pb(i);
  }
  rep(i,n) {
    cout << G[i].size() << endl;
  }

  return 0;
}


Measured memory_bytes: 14540
#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 f(int n) {
  if (n % 2 == 0) {
    return n / 2;
  } else {
    return 3 * n + 1;
  }
}

int main() {
  int s;
  cin >> s;
  vector<int> aa;
  for (int i = 1; i <= 1000000; i++) {
    if (i == 1) {
      aa.push_back(s);
      continue;
    }
    int cur = f(aa.back());
    if (find(aa.begin(), aa.end(), cur) != aa.end()) {
      cout << i << endl;
      break;
    }
    aa.push_back(cur);
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];

        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }

        int c = 0;
        for (int i = 0; i < n; i++) {
            while (a[i] % 2 == 0) {
                a[i] = a[i] / 2;
                c++;
            }
        }

        System.out.println(c);
    }
}


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

int main() {
  int N ;
  string P, W, G, Y, color;
  cin >> N;
    
  for(int i = 0; i < N; i++){
  cin >> color;
    if ( color == "Y"){
    cout << "Four" << endl;
    break;
    }
  }
  if( color =="P" || color == "W" || color == "G" )
  {cout << "Three" << endl;}
}
 

Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
#include <time.h>
#include <sys/timeb.h>
#include <cstdio>
#include <sys/time.h>

using namespace std;
#define ll long long
#define uint unsigned int
#define ulong unsigned long long int

template<typename T> bool InRange(T t, T l, T r){ return l <= t && t < r; }

int main(){
	
	double T, X;
	cin >> T >> X;
	cout << (T / X) << endl;
	
	
	
	
	
	
    return 0;
}

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

int main(){
    int m, nmin, nmax;
    while(cin >> m >> nmin >> nmax, m != 0){
        vector<int> v;
        for(int i=0;i<m;++i){
            int p;
            cin >> p;
            v.push_back(p);
        }
        sort(v.rbegin(), v.rend());
        int maxi = 0, n = 0;
        for(int i=nmin-1;i<nmax;++i){
            if(v[i] - v[i+1] >= maxi){
                maxi = v[i] - v[i+1];
                n = i + 1;
            }
        }
        cout << n << endl;
    }

    return 0;
}


Measured memory_bytes: 3160
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
typedef long long ll;
const int MOD = 1000000007;
using namespace std;
int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string s;
  
  cin >> s;
  
  for(int i = 0;i < s.size();i++){
    if(s[i] == '1'){
      s[i] = '9';
    }else{
      s[i] = '1';
    }
  }
  
  cout << s << endl;
  return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
	ll h,w;
	cin>>h>>w;
	if(h==1 || w==1){
	 cout<<"1";
    }
	else if(h%2==0){
		ll ans=(h/2)*w;
		cout<<ans;
	}
	else{
		if(w%2==0){
			ll ans=(h)*(w/2);
			cout<<ans;
		}
		else{
			ll ans=(h)*(w/2)+(h+1)/2;
			cout<<ans;
		}
	}
return 0;

	
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
using namespace std;
#define ll long long int
#define pb push_back
#define mp make_pair
#define deb(x) cout<< #x << " " << x << "\n";
#define MAX 9223372036854775807
#define MIN -9223372036854775807
#define PI 3.141592653589
#define setbits(n) __builtin_popcountll(n)
const ll mod=1e9+7;

const int N=1e5+1;
vector<ll> a[N],dp(N,-1);

ll dfs(ll v){
    if(dp[v]!=-1)
        return dp[v];
    ll mx=0;
    for(ll u: a[v])
        mx=max(mx,1+dfs(u));
    return dp[v]=mx;
}

int main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    ll T=clock();
    
    ll n,m;
    cin>>n>>m;
    vector<ll> in(n);
    for(ll i=0;i<m;i++){
        ll u,v;
        cin>>u>>v; u--,v--;
        a[u].pb(v);
        in[v]++;
    }
    ll ans=0;
    for(ll i=0;i<n;i++)
        if(in[i]==0)
            ans=max(ans,dfs(i));
    cout<<ans;
    

    

    cerr<<"\n\nTIME: "<<(double)(clock()-T)/CLOCKS_PER_SEC<<" sec\n";
    T = clock();
    return 0;
}

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

int H, W, P, Q;

int main() {
	cin >> H >> W >> P >> Q;
	if(!(H%P) && !(W%Q)) {
		puts("No");
		return 0;
	}
	puts("Yes");
	if(H%P) {
		for(int i = 1; i <= H; i++) {
			for(int j = 1; j <= W; j++)
				printf("%d ", i%P ? H+1 : -(P-1)*(H+1)-1);
			puts("");
		}
	} else if(W%Q) {
		for(int i = 1; i <= H; i++) {
			for(int j = 1; j <= W; j++)
				printf("%d ", j%Q ? W+1 : -(Q-1)*(W+1)-1);
			puts("");
		}
	}
	return 0;
}

Measured memory_bytes: 1280
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>
#include <array>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>
#include <stack>
#include <utility>
#include <algorithm>
#include <numeric>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <climits>
#include <bitset>
#include <random>
#include <functional>
#include <sstream>
#include <iomanip>

using namespace std;

#define _CRT_SECURE_NO_WARNINGS
#define rep(i, n) for(int i=0; i<(n); i++)
#define FOR(i, m, n) for(int i=(m);i<(n);i++)
#define SZ(x) ((int)(x).size())
#define ALL(x) (x).begin(),(x).end()
#define SORT(x) sort((x).begin(),(x).end())
#define REVE(x) reverse((x).begin(),(x).end())
#define MP make_pair
#define PB push_back

typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef pair<int, int> PII;
typedef long long LL;

int main() {
	int n, cnt = 0;
	cin >> n;
	VI a(n);
	rep(i, n)cin >> a[i];

	//sort
	int flag = 1;
	while (flag) {
		flag = 0;
		for (int j = n - 1; j >= 1; j--) {
			if (a[j] < a[j - 1]) {
				swap(a[j], a[j - 1]);
				cnt++;
				flag = 1;
			}
		}
	}

	//prin
	rep(i, n) {
		cout << a[i];
		printf(i == n - 1 ? "\n" : " ");
	}
	cout << cnt << endl;
}


Measured memory_bytes: 3232
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
ll mod=1000000007;
int main()
{
	ll i,j,k,m,n,t;
	cin>>n>>k;
	ll l,r;
	ll x=0,y=0,ans=0;
	l=k;
	r=n;
	x=k*(k-1)/2;
	ll ctr=0;
	while(ctr<k)
	{
		ctr++;
		y+=r;
		r--;
	}
//	cout<<y<<' '<<x<<endl;
	ans=y-x+1;
	ans%=mod;
//	cout<<' '<<ans<<endl;
	while(l<=n)
	{
		x+=l++;
		y+=r--;
//		cout<<x<<' '<<y<<endl;
		ans+=y-x+1;
		ans%=mod;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3636
#include <iostream>

using namespace std;

int main()
{
	int a,b,c;
	int buf[3];

	cin >> a >> b >> c;

	if (a < b)
	{
		if (b < c)
		{
			buf[0] = a;
			buf[1] = b;
			buf[2] = c;
		}
		else
		{
			buf[2] = b;
			if (a < c)
			{
				buf[0] = a;
				buf[1] = c;
			}
			else
			{
				buf[0] = c;
				buf[1] = a;
			}
		}
	}
	else
	{
		if (a < c)
		{
			buf[0] = b;
			buf[1] = a;
			buf[2] = c;
		}
		else
		{
			buf[2] = a;
			if (b < c)
			{
				buf[0] = b;
				buf[1] = c;
			}
			else
			{
				buf[0] = c;
				buf[1] = b;
			}
		}
	}

	cout << buf[0] << " " << buf[1] << " " << buf[2] << endl;

	return 0;
}

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

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

    int counter = 0;
    for (int i = 0; i < S.size(); i++)
    {
        if (S[i] == 'o')
            counter++;
    }
    cout << 700 + (100 * counter) << endl;

    return (0);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
#define PI 3.141592653589
typedef pair<int,int> PP;
typedef long long ll;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "No" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl

signed main(void){
    int K;
    cin >> K;
    int N=50;
    int A[57];
    REP(i,N){
        A[i]=N-1;
    }
    REP(i,N){
        A[i]+=K/N;
    }
    REP(i,K%N){
        A[i]+=N+1;
        REP(j,N){
            A[j]--;
        }
    }
    cout << N << endl;
    REP(i,N){
        cout << A[i] << " ";
    }
    cout << endl;
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1234567;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
#define iyasi 1;
signed main() {
    int N;
    cin >> N;
    int X = -1;
    for(int i = 1; i*(i-1)/2 <= N; i++) {
        if(i*(i-1)/2 == N) {
            X = i;
            break;
        }
    }
    if(X == -1) {
        cout << "No" << endl;
    }
    else {
        cout << "Yes" << endl;
        cout << X << endl;
        vector<vector<int>>ans(X);
        int poyo = 1;
        for(int i = 0; i < X; i++) {
            for(int j = i+1; j < X; j++) {
                ans[i].push_back(poyo);
                ans[j].push_back(poyo);
                poyo += iyasi;
            }
        }
        for(int i = 0; i < X; i++) {
            cout << X-1 << " ";
            for(int j = 0; j < X-1; j++) {
                if(j) {
                    cout << " ";
                }
                cout << ans[i][j];
            }
            cout << endl;
        }
    }
}


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

int a[26];

int main(){
  string s; cin>>s;
  rep(i,3) a[s[i]-'a']++;
  if(a[0]==1&&a[1]==1&&a[2]==1){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  return 0;
}


Measured memory_bytes: 764
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
typedef long long ll;
#define all(x) (x).begin(), (x).end()  // sortなどの引数を省略
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define max3(x, y, z) max(x, max(y, z))

#ifdef _MSC_FULL_VER  //デバッグ出力
#define dout cout
#define debug() if (true)
#define check(x) std::cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) std::cout << "☆" << x << endl
#else
#define dout \
  if (false) cout
#define debug() if (false)
#define check(x) \
  if (false) cout << "★" << #x << "の値:" << (x) << endl
#define pass(x) \
  if (false) cout << "☆" << x << endl
#endif
using namespace std;
int main() {
  ll a, b, c;
  cin >> a >> b >> c;
  if (a*b < c){
    cout << a*b;
  } else {
    cout << c;
  }
  return 0;
}
/*
//よく使うやつ
int N;
cin >> N;
vector<int> list(N);
for (int i = 0; i < N; i++) {
  cin >> list[i];
}
// for文
for (int i = 0; i < N; i++) {
}
//配列
vector<int> vec;
vec.at(i)
vector<vector<int>> vec(10, vector<int>(10));
sort(all(vec));
sort(all(vec), greater<int>());
    //配列の内容表示
dout << "====vecの内容====\n";
for (int i = 0; i < N; i++) dout << vec[i] << endl;
dout << "====ここまで====\n";
*/


Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <cmath>
#include <list>
#include <ctime>
#include <sstream>
#include <queue>
#include <stack>
#include <bitset>
#include <numeric>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef long long ll;
#define FOR(x, b, e) for(int x=(b); x<=(e); ++x)
#define FORD(x, b, e) for(int x=((int)(b))-1; x>=(e); --x)
#define REP(x, n) for(int x=0; x<(n); ++x)
#define ALL(c) c.begin(),c.end()
#define sz(x) ((int)((x).size()))
#define pb push_back
#define st first
#define nd second
#define mp(x,y) make_pair(x,y)
typedef short int sint;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it) {
	*this << ((it != d.b) ? ", " : "") << *it;
  }
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main() {
	ios_base::sync_with_stdio(false);


	int n;
	cin >> n;
	int najmn = n + 1;
	int res = 0;
	REP(i, n) {
		int x;
		cin >> x;
		if (x < najmn) {
			++res;
		}
		najmn = min(x, najmn);
	}
	cout << res << endl;
}

Measured memory_bytes: 3640
//#pragma GCC target("avx2")
#pragma GCC optimize("O3")
//#pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>
#include <atcoder/all>

using namespace std;
using namespace atcoder;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

template <typename T>
void print(T x) {
    cout << x << "\n";
}

#define ALL(x) (x).begin(), (x).end()
#define FOR(i, m, n) for (ll i = (m); i < (n); ++i)
#define REVFOR(i, m, n) for (ll i = (n - 1); i >= (m); --i)
#define REP(i, n) FOR(i, 0, n)
#define REVREP(i, n) REVFOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    int n, q;
    cin >> n >> q;

    dsu d(n);

    REP(i, q) {
        int t, a, b;
        cin >> t >> a >> b;
        if (t == 0) {
            d.merge(a, b);
        } else {
            if (d.same(a, b)) print("1");
            else print("0");
        }
    }
}


Measured memory_bytes: 3992
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<list>

using namespace std;

int main(void){

  int n;
  cin>>n;
  vector<int> a(n);

  for(int i=0;i<n;i++){
    cin>>a[i];
    //cout << a[i] << endl;
  }

  for(int i=0;i<n;i++){
    if(a[i]%2==1){
      cout << "first" << endl;
      return 0;
    }
  }
  cout << "second" << endl;

  return 0;
}


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

int main()
{

	int takaHP, takaATK, aoHP, aoATK;

	cin >> takaHP >> takaATK >> aoHP >> aoATK;

	int takaHP0turn = takaHP / aoATK + ((takaHP % aoATK == 0)? 0 : 1);
	int aoHP0turn = aoHP / takaATK + ((aoHP % takaATK == 0)? 0 :1);

	const string outStr = (aoHP0turn <= takaHP0turn) ? "Yes" : "No";

	cout << outStr << endl;
	return 0;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#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 per(i, n) for(ll i=((ll)(n))-1; i>=0; i--)
#define perf(i, n) for(ll i=((ll)(n)); i>0; 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();
    string s; cin >> s;
    ll a = s[0] - '0';
    ll b = s[1] - '0';
    ll c = s[2] - '0';
    ll d = s[3] - '0';

    for(ll bit=0; bit<(1LL<<3); bit++){
        vi op(3, 0); // 0:+, 1:-
        if(bit&(1LL<<0)) op[0] = 1;
        if(bit&(1LL<<1)) op[1] = 1;
        if(bit&(1LL<<2)) op[2] = 1;

        ll sum = a;
        (op[0] == 1) ? sum -=b : sum += b;
        (op[1] == 1) ? sum -=c : sum += c;
        (op[2] == 1) ? sum -=d : sum += d;
        if(sum == 7){
            cout << a << ((op[0] == 1) ? "-" : "+");
            cout << b << ((op[1] == 1) ? "-" : "+");
            cout << c << ((op[2] == 1) ? "-" : "+") << d << "=7" << endl;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define ll long long
#define rep2(i,a,b) for(int i=(a);i<=(b);++i)
#define rep(i,n) rep2(i,0,n-1)
#define pii pair<int,int>
#define ti3 tuple<int,int,int>
int MOD=1000000000+7;
int INF=1e6;

using namespace std;
string alphabet("abcdefghijklmnopqrstuvwxyz");

main(){
    int n;
    cin>>n;
    char s[500000];
    rep(i,n){
        cin>>s[i];
    }
    int e=0,w=0;
    rep(i,n){
        if(s[i]=='W') w++;
        else e++;
    }
    int ans=10000000;
    int enow=0,wnow=0;
    rep(i,n){
        int temp=wnow;
        if(s[i]=='W') wnow++;
        else enow++;
        temp+=e-enow;
        ans=min(temp,ans);
    }
    cout<<ans;
}

Measured memory_bytes: 512
H, K, S = input().split()
H = int(H)
K = int(K)
S = int(S)

ans_list = [str(S)] * K

num = 10 ** 9
if S == 10 **9:
  num = 10 ** 9 -1

dummy_list = [str(num)] * (H-K)

ans_list.extend(dummy_list)
print(" ".join(ans_list))

Measured memory_bytes: 48624
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()

typedef long long ll;

using namespace std;

class ModInt{
public:
    long long n;
    int p;

    ModInt(){
    }

    ModInt(long long _n, int _p){
        p = _p;
        n = _n % _p;

        if(n < 0){
            n += p;
        }
    }

    ModInt operator+(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n += a.n;

        if(tmp.n > tmp.p){
            tmp.n -= tmp.p;
        }
        
        return tmp;
    }

    ModInt operator-(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n -= a.n;

        if(tmp.n < 0){
            tmp.n += tmp.p;
        }

        return tmp;
    }

    ModInt operator*(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n = (tmp.n * a.n) % tmp.p;

        return tmp;
    }

    int modpow(int b, int k){
        if(k == 0){
            return 1;
        }else if(k % 2 == 1){
            long long tmp = b;
            tmp = tmp * modpow(b, k - 1) % p;
            
            return tmp;
        }else{
            long long tmp = modpow(b, k / 2);
            return tmp * tmp % p;
        }
    }

    int modinv(int b){
        return modpow(b, p - 2);
    }

    ModInt operator/(ModInt a){

        ModInt tmp = ModInt(*this);

        tmp.n = tmp.n * modinv(a.n) % tmp.p;
        return tmp;
    }
};

int main(){

    int n,k;
    cin >> n >> k;

    if(k == 1){
        cout << 0 << endl;
        return 0;
    }

    vector<ll> a;

    rep(i,n){
        ll tmp;
        cin >> tmp;

        a.pback(tmp);
    }

    sort(ALL(a));

    int rest = n - k;
 
    vector<ModInt> combi(n, ModInt(1, MODN));
 
    rep(i,n){
        if(i > k - 1){
            combi[i] = combi[i - 1] * ModInt(i, MODN) / ModInt(i - (k - 1), MODN);
        }
    }
 
    ModInt maxsum = ModInt(0,MODN);
    ModInt minsum = ModInt(0,MODN);
 
    rep(i,n - k + 1){
        maxsum = maxsum + ModInt(a[n - 1 - i], MODN) * combi[n - 1 - i];
    }
 
    rep(i,n - k + 1){
        minsum = minsum + ModInt(a[i], MODN) * combi[n - 1 - i];
    }
 
    if(k != 1){
        cout << (maxsum - minsum).n << endl;
    }else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 2676
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
    public static String process(TestCase testCase) {
        final int A = testCase.A;
        final int B = testCase.B;
        final int C = testCase.C;

        PriorityQueue<Integer> pq = new PriorityQueue<>((a, b) -> Integer.compare(b, a));
        pq.add(A);
        pq.add(B);
        pq.add(C);

        int max = noInspectionGet(pq);
        final int smaller = noInspectionGet(pq);
        final int smallest = noInspectionGet(pq);

        return String.valueOf(max * 10 + smaller + smallest);
    }

    private static int noInspectionGet(PriorityQueue<Integer> pq) {
        // impossible, input are never null
        //noinspection ConstantConditions
        return pq.poll();
    }

    // Util func

    public static void main(String[] args) {
        TestCase testCase = readFromInput();

        final String result = process(testCase);

        output(result);
    }

    private static TestCase readFromInput() {
        Scanner sc = new Scanner(System.in);

        int A = sc.nextInt();
        int B = sc.nextInt();
        int C = sc.nextInt();

        return new TestCase(A, B, C);
    }

    private static void output(String result) {
        System.out.println(result);
    }

    public static class TestCase {
        final int A;
        final int B;
        final int C;

        public TestCase(int A, int B, int C) {
            this.A = A;
            this.B = B;
            this.C = C;
        }
    }
}


Measured memory_bytes: 28884
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n,s = LI()
    a = [LI() for _ in range(n)]
    x = [_[0] for _ in a]
    p = [_[1] for _ in a]
    if x[0] > s:
        return x[-1] - s
    if x[-1] < s:
        return s - x[0]
    r = 0
    i = 0
    j = n - 1
    d = p[:]
    e = collections.defaultdict(list)
    sk = set()
    while i < j:
        if x[i] > s:
            break
        if x[j] < s:
            break
        if d[i] >= d[j]:
            d[i] += d[j]
            j -= 1
        else:
            d[j] += d[i]
            i += 1
    t = s
    k = sorted(list(zip(d,range(n))), reverse=True)
    lx = rx = s
    for _,i in k:
        if lx <= x[i] <= rx:
            continue
        if lx > x[i]:
            lx = x[i]
        else:
            rx = x[i]
        r += abs(t-x[i])
        t = x[i]


    return r



print(main())



Measured memory_bytes: 37704
n = gets.chomp.to_i
a = gets.chomp.split(' ').map(&:to_i)

counter = {1 => 0, 2 => 0, 4 => 0}

a.map{|v| if v % 2 == 0 then (v % 4 == 0 ? 4 : 2) else 1 end}.each{|v| counter[v] += 1}

flag = false
if counter[2] > 0 then
  flag = counter[1] <= counter[4]
else
  flag = counter[1] <= (counter[4] + 1)
end
puts (flag ? 'Yes' : 'No')

Measured memory_bytes: 12292
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using P = pair<int,int>;

//----***Like a Pythonista***----
#define REP(ii,jj,nn) for (ll ii=jj;ii<(nn);ii++)
#define RREP(ii,nn,jj) for (ll ii = nn; jj<ii;ii--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(ALL(__VA_ARGS__),0LL)
#define dsum(...) accumulate(ALL(__VA_ARGS__),0.0)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(ALL(a)); }
template<class T> inline auto min(const T& a){ return *min_element(ALL(a)); }
inline ll gcd(ll a,ll b){if(b == 0) return a;return  gcd(b,a%b);}
inline ll lcm(ll a,ll b){ll g = gcd(a,b);return a / g * b;}

//----***定数***----
#define MOD 1000000007
#define INF 100000000000000000
#define EPS 1e-9
const vector<vector<int>> DXY={{-1,0},{1,0},{0,-1},{0,1}};

//----***パーツ***----
#define fi first
#define se second
#define pb push_back
#define re return
#define br break

//----***入出力***---
void print() { std::cout << "\n"; }
template <class T>void print(const T &x) {std::cout << x<<"\n";}
template <class T, class... Args>void print(const T &x, const Args &... args) {std::cout << x << " ";print(args...);}
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0);
#define dbg cerr<<"🥺🥺🥺🥺🥺🥺"<<endl;
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);};}initial_;


signed main(){
  int X;cin>>X;
  int left=X/100,right=X%100;
  if(right<=5*left){
    print(1);
  }
  else{
    print(0);
  }


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define repr(i, n) for (int i = (int)n - 1; i >= 0; --i)
#define ALL(a) (a).begin(), (a).end()
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<ll, ll>;
const int dx[] = {0, 1, -1, 0};
const int dy[] = {1, 0, 0, -1};
const ll mod = 1e9 + 7;
const ll INF = 1e9;
const ll LINF = 1LL << 60;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //////////////////////////////////////
  int n, q;
  cin >> n >> q;
  string t;
  cin >> t;
  vector<int> a(n, 0), s(n + 1, 0);
  repi(i, 1, t.length()) {
    if (t[i - 1] == 'A' && t[i] == 'C') a[i] = 1;
  }
  rep(i, n) s[i + 1] = s[i] + a[i];
  rep(i, q) {
    int l, r;
    cin >> l >> r;
    cout << s[r] - s[l] << endl;
  }
  return 0;
}



Measured memory_bytes: 4216
class GetSecond
  def self.hour_second(total_second, hour)
    second = total_second-hour*3600
  end
end

total_second = gets.to_i


hour = total_second/3600.floor
minute = GetSecond.hour_second(total_second, hour).to_i/60.floor
second = GetSecond.hour_second(total_second, hour).to_i%60

puts "#{hour}:#{minute}:#{second}"

Measured memory_bytes: 8668