akhauriyash/Code-Regression huggingface dataset:
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.06.22 20:57:44
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

vector<P> ret;

int main() {
    int n, k;
    scanf("%d%d", &n, &k);

    int v = (n - 1) * (n - 2) / 2;

    if (v < k) {
        printf("%d\n", -1);
        return 0;
    }

    rep1(i, n - 1) {
        ret.pb(P(n, i));
    }

    bool b = false;
    rep1(i, n - 1) {
        rep1(j, n - 1 - i) {
            if (v <= k) {
                b = true;
                break;
            }
            ret.pb(P(i, i + j));
            v--;
        }
        if (b) {
            break;
        }
    }

    int m = ret.size();
    printf("%d\n", m);
    rep(i, m) {
        printf("%d %d\n", ret[i].fr, ret[i].sc);
    }

    /* --------------------------------- */
    return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int ans=0;
int main()
{
  string s,t;
  cin>>s>>t;
  for(int i=0;i<3;i++)
  {
  	if(s[i]==t[i])
  	  ans++;
  }
  cout<<ans;
  return 0;
}

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

using namespace std;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const int maxn = 110000;
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    int n, m;
    cin >> n >> m;
    vector<int> a(n);
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    int cur = ceil(sum * 1.0 / 4 / m);
    int cnt = 0;
    for (int i = 0; i < n; i++)
    {
        if (a[i] >= cur)
            cnt++;
    }
    if (cnt >= m)
        cout << "Yes\n";
    else
        cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
def main():
    V, E = map(int, input().split())
    INF = float("inf")
    G = [[-1 for _ in range(V)] for _ in range(V)]

    for i in range(E):
        s,t,d = map(int, input().split())
        G[s][t] = d

    # dp[bit][i] bitの１が立っている場所を訪問済みで、現在iにいる
    dp = [[INF for _ in range(V)] for _ in range(1 << V)]
    # 各所一回だけ訪問して一周できるなら、どこから始めても同じなので0のみ初期化
    dp[0][0] = 0



    for bit in range(1 << V):
        for curr in range(V):
            for nxt in range(V):
                # 現在地と次の場所が同じなら飛ばす
                if curr == nxt:
                    continue
                # 次行くところが既に訪問済みなら飛ばす
                if bit & (1 << nxt):
                    continue
                # 現在値から次の目的地にいけなければ飛ばす
                if G[curr][nxt] == -1:
                    continue
                dp[bit | (1 << nxt)][nxt] = min(dp[bit | (1 << nxt)][nxt], dp[bit][curr] + G[curr][nxt])

    ans = dp[-1][0]
    print(ans if ans != INF else -1)
        
if __name__ == "__main__":
    main()


Measured memory_bytes: 20068
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <cstdlib>

using namespace std;
//DP用
template<class T> inline bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

//a^n mod を計算する関数
long long modpow(long long a,long long n,long long mod) {
    long long res = 1;
    while(n > 0) {
        if(n % 2 == 1) {
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

//a^(-1) mod すなわちaの逆元を返す関数
long long modinv(long long a,long long mod) {
    return modpow(a,mod-2,mod);
}

//最大公約数をを返す関数
long long gcd (long long a,long long b) {
    if(a % b == 0) {
        return b;
    }else {
        return (gcd(b,a%b));
    }
}

const long long INF = 1LL << 60;
const long long P = 1000000007;

//nCkを求める関数
long long conbi (long long n,long long k) {
    long long res = 1;
    long long inv;
    for(long long i = n-k+1; i <= n; i++) {
        res *= i;
        res %= P;
    }
    for(long long i = 1; i <= k; i++) {
        inv = modinv(i,P);
        res *= inv;
        res %= P;
    }
    return res;
}

int main() {
    int n,m;
    cin >> n >> m;
    int p[m];
    string s[m];
    int judge[n+1],penalty[n+1];
    int correct = 0,failed = 0;
    for(int i = 0; i < n+1; i++) {
        judge[i] = 0;
        penalty[i] = 0;
    }
    for(int i = 0; i < m; i++) {
        cin >> p[i] >> s[i];
        if(s[i] == "AC") {
            if(judge[p[i]] != 1) {
                correct++;
                failed += penalty[p[i]];
            }
            judge[p[i]] = 1;
        }
        if(s[i] == "WA") {
            if(judge[p[i]] == 0) {
                penalty[p[i]]++;
            }
        }
    }
    cout << correct << " " << failed;
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> L(N);
  for(int i=0; i<N; i++) cin >> L.at(i);
  sort(L.begin(),L.end());
  
  int ans=0;
  for(int a=0; a<N; a++){
    for(int b=a+1; b<N; b++){
      int ab = L.at(a) + L.at(b);
      int r = lower_bound(L.begin(), L.end(), ab) - L.begin();
      int l = b+1;
      ans += max(0,r-l);
    }
  }
  cout << ans << endl;
}

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

#define Fast ios_base::sync_with_stdio(0);cin.tie(0),cout.tie(0)
#define FO freopen("in.txt", "r", stdin)
#define FC freopen("out.txt", "w", stdout)
#define aise cout<<"aise"<<endl
#define pb push_back
#define mp make_pair
#define ll long long
#define mset(v, a) memset(v, a, sizeof(v))
#define pll pair< ll, ll >
#define pdd pair< double, double >
#define ff first
#define ss second
#define pi acos(-1.0)
#define mxN 100010
#define inf 1e9

int main()
{

    string ss;
    cin >> ss;
    bool tf = 1;
    for(ll i = 0; i < ss.size(); i+=2)
    {

        if(ss[i] == 'L') tf=0;
    }
    for(ll i = 1; i < ss.size(); i+=2)
    {

        if(ss[i] == 'R') tf=0;
    }
    if(tf) cout << "Yes";
    else cout << "No";
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
    val (A, B, C, D) = readLine()!!.split(" ").map(String::toInt)
    val CD = C..D
    var sum = 0
    for (ab in A..B) {
        if (CD.contains(ab)) {
            sum++
        }
    }

    println(
        if (sum == 0) {
            0
        } else {
            --sum
        }
    )
}



Measured memory_bytes: 37856
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]) {
  int X;
  cin >> X;

  int ret = 0;
  for (int i = 1; i < 1000; ++i) {
    for (int j = 2; j < 10; ++j) {
      int tmp = pow(i, j);
      if (tmp > X)
        break;
      ret = max(ret, tmp);
    }
  }

  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 384
/*
 * FileName:     D_fix
 * CreatedDate:  2020-04-10 22:00:13 +0900
 * LastModified: 2020-04-10 22:11:55 +0900
 */

#include <stdio.h>
long int max(long int s,long int t){
    if(s<t){return t;}
    return s;
}
int main(void){
    int n;
    long int W;
    scanf("%d %ld",&n,&W);
    int w[n],v[n];
    for(int i=0;i<n;i++){
        scanf("%d %d",&w[i],&v[i]);
    }
    long int dp[n+1][W+1];
    for(int i=0;i<n+1;i++){
        for(long int j=0;j<W+1;j++){
            dp[i][j]=0;
        }
    }
    for(int i=n-1;i>=0;i--){
        for(long int j=0;j<=W;j++){
            if(j<w[i]){
                dp[i][j]=dp[i+1][j];
            }
            else{
                dp[i][j]=max(dp[i+1][j],dp[i+1][j-w[i]]+v[i]);
            }
        }
    }
    printf("%ld\n",dp[0][W]);
    return 0;
}


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

const int N_MAX = 50;

int main() {
	long long N, X;
	std::cin >> N >> X;

	// numPate[i] iレベルが含むパティの数
	std::vector<long long> numPate(N_MAX + 1);
	std::vector<long long> numLayer(N_MAX + 1);
	long long pate = 1;
	long long layer = 1;
	for(int i = 0; i <= N_MAX; i++) {
		numPate[i] = pate;
		numLayer[i] = layer;
		pate = pate * 2 + 1;
		layer = layer * 2 + 3;
	}

	long long result = 0;
	for(int i = N; i >= 0; i--) {
		if(X == 0) {
			break;
		} else if(i == 0) {
			// 0レベルは別
			if(X == 1) {
				result += 1;
				X -= 1;
			}
		} else if(X == numLayer[i]) {
			// 最後のパンズまで
			result += numPate[i];
			X -= numLayer[i];
		} else if(X >= (numLayer[i - 1] + 2)) {
			// 真ん中のパティ以上
			result += numPate[i - 1] + 1;
			X -= numLayer[i - 1] + 2;
		} else {
			X -= 1;
		}
	}

	std::cout << result << std::endl;

	return 0;
}

Measured memory_bytes: 256
N,P = map(int, input().split())
S = input()

if P == 2:
    ans = 0
    for i in range(N):
        if int(S[i])%2 == 0:
            ans += i+1
elif P == 5:
    ans = 0
    for i in range(N):
        if S[i] == "0" or S[i] == "5":
            ans += i+1
else:
    L = [0]*P
    num = 0
    for i in range(N):
        num += int(S[N-i-1])*pow(10, i, P)
        num %= P
        L[num] += 1
    ans = L[0]
    for i in range(P):
        ans += L[i]*(L[i]-1)//2

print(ans)

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

typedef long long ll;

const int MAXN = 1e5 + 10;
const int MOD = 1e9 + 7;

vector<int> grafo[MAXN];
ll dp[MAXN][2];
int N;

ll solve(int v,int c,int p){

	if(dp[v][c] != -1) return dp[v][c];

	ll tot = 1;
	for(int u : grafo[v]){
		if(u == p) continue;
		if(c == 0) tot = (tot * (solve(u,0,v) + solve(u,1,v))) % MOD;
		else tot = (tot * solve(u,0,v)) % MOD;
	}

	return dp[v][c] = tot;

}

int main(){

	memset(dp,-1,sizeof(dp));

	scanf("%d",&N);
	for(int i = 1;i<N;i++){
		int u,v;
		scanf("%d %d",&u,&v);
		grafo[u].push_back(v);
		grafo[v].push_back(u);
	}

	printf("%lld\n", (solve(1,0,-1) + solve(1,1,-1)) % MOD );

	return 0;

}

Measured memory_bytes: 15744
import java.util.*;
public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int k = sc.nextInt();
    int c = sc.nextInt();
    String s = sc.next();
    int front[] = new int[k]; // 前から貪欲
    int back[] = new int[k]; // 後ろから貪欲
    ArrayList<Integer> res = new ArrayList<>();
    int num = 0;
    int i = 0;
    while (num < k) {
      if (s.charAt(i) == 'o') {
        front[num] = i;
        i += c;
        num++;
      }
      i++;
    }
    num = k-1;
    i = n-1;
    while (num >= 0) {
      if (s.charAt(i) == 'o') {
        back[num] = i;
        i -= c;
        num--;
      }
      i--;
    }
    for (int j = 0; j < k; j++) {
      if (front[j] == back[j]) res.add(front[j]+1); // インデックスから日に直すことに注意
    }
    if (!(res.isEmpty())) {
      for (int e: res) {
        System.out.println(e);
      }
    }
    sc.close();
  }
}

Measured memory_bytes: 57380
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
	ll n,k,mx=-1;
	cin>>n>>k;
	ll a[n];
	for(ll i=0;i<n;i++)cin>>a[i];
	ll dp[n];
	memset(dp,0,sizeof(dp));
	dp[0]=0;
	for(ll i=1;i<n;i++){
		dp[i]=dp[i-1]+abs(a[i-1]-a[i]);
		for(ll j=2;j<=k;j++){
			if(i-j<0)break;
			dp[i]=min(dp[i],abs(dp[i-j]+abs(a[i]-a[i-j])));
		}
//	cout<<dp[i]<<endl;
	}
	cout<<dp[n-1];
}

Measured memory_bytes: 1792
#pragma target("avx")
#pragma optimize("O3")
#include<bits/stdc++.h>

bool alp[26];
char c;

int main(){
	while((c=getchar())!='\n') alp[c-'a'] = true;
	for(int i=0; i<26; i++) if(!alp[i]) {
		putchar(i+'a');
		return 0;
	}
	puts("None");
	return 0;
}



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

//define
#define int long long
#define UNIQUE(v) v.erase(unique(all(v)), v.end());
#define ZIP(v) sort(all(v)),UNIQUE(v)
#define ADD(a, b) a = (a + b) % mod
#define SUB(a, b) a = (a+mod-b)%mod
#define MUL(a, b) a = (a * b) % mod
#define repi(i,m,n) for(int i = m;i < n;i++)
#define drep(i,n,m) for(int i = n;i >= m;i--)
#define rep(i,n) repi(i,0,n)
#define rrep(i,n) repi(i,1,n+1)
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(), v.rend()
#define dmp(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define fi first
#define se second

//template
template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p){
  os << p.first << " " << p.second;return os;
}
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &v){
  for (auto it = v.begin();it != v.end();++it){
    if (it != v.begin())os << " ";os << *it;
  }return os;
}
template<typename T, int SIZE>
int array_length(const T (&)[SIZE]){return SIZE;}
template<typename T, int N>
void print(const T (&a)[N], int s = N, int t = -1, bool f = true){
	if(t == -1){rep(i,s){if(i)cout << " ";cout << a[i];}}
	else repi(i,s,t){if(i!=s)cout << " ";cout << a[i];}
	if(f)cout << "\n";
}
template<typename T, int N1, int N2>
void print(const T (&a)[N1][N2], int h = N1, int w = N2){
	rep(i,h){rep(j,w){cout << a[i][j] << " \n"[j==w-1];}}
}

//typedef
typedef pair<int,int> P;
typedef pair<int, P> PP;
typedef pair<P, int> Pi;
typedef vector<int> vi;
typedef deque<int> dq;
const int inf = 1e9+7;
const int INF = 1e18+7;

P gcd(int x, int y){
	if(x < y)swap(x, y);
	int ans = 0;
	while(y != 0){
		x = x%y;swap(x, y);
		ans++;
	}
	return P(x, ans);
}

signed main(){
	while(1){
		int a, b;
		scanf("%lld%lld", &a, &b);
		if(a == 0 and b == 0)break;
		cout << gcd(a, b) << endl;
	}
	return 0;
}







Measured memory_bytes: 3148
// C.cpp
#include <bits/stdc++.h>

using namespace std;

const int MAX_N = 2e5 + 200;

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

int n, ai[MAX_N], bi[MAX_N];
priority_queue<pii> pq;
ll ans;

int main()
{
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
		scanf("%d", &ai[i]);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &bi[i]);
		if (bi[i] != ai[i])
			pq.push(make_pair(bi[i], i));
	}
	while (!pq.empty())
	{
		int u = pq.top().second;
		pq.pop();
		int pre = (u + n - 2) % n + 1, suf = u % n + 1, steps = (bi[u] - ai[u]) / (bi[pre] + bi[suf]);
		if (steps == 0)
			puts("-1"), exit(0);
		ans += steps, bi[u] -= steps * (bi[pre] + bi[suf]);
		if (ai[u] != bi[u])
			pq.push(make_pair(bi[u], u));
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 6620
import math
n=int(input())

l=[4 if i%2==0 else 2 for i in range(max(5,n+1))]
l[1]=1
l[2]=2
l[4]=3
for i in range(3,int(math.sqrt(n))+1):#振るい
  for j in range(i,n//i+1):
   # print(i,i*j)
    if i==j:
      l[i*j]+=1
    else:
      l[i*j]+=2
#print(l)

l2=[i*l[i] for i in range(n+1)]
print(sum(l2))


Measured memory_bytes: 389888
from collections import defaultdict


def main():
    N = int(input())
    a_list = list(map(int, input().split()))
    color_set = set()
    free = 0
    for a in a_list:
        for i, (s, e) in enumerate([(1, 399), (400, 799), (800, 1199), (1200, 1599), (1600, 1999), (2000, 2399), (2400, 2799), (2800, 3199)]):
            if s <= a <= e:
                color_set.add(i)
                break
        else:
            free += 1
    print(max(1, len(color_set)), len(color_set) + free)


if __name__ == '__main__':
    main()


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

using namespace std;

int main() {
    int a,b;
    
    cin>>a>>b;
    
    if(a>9 || b > 9 || a < 1 || b<1)
    {
     cout<<"-1";   
    }
    else{
        cout<<a*b;
    }
}

Measured memory_bytes: 764
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
ostream& operator << (ostream& os, const vector<T>& vs){
  for (const T& v : vs) os << v << " ";
  return os;
}

int main() {
  int N, K; cin >> N >> K;
  string S; cin >> S; S += '!';
  vector<int> a;
  char prev = '?';
  int cnt = 0;
  if (S[0] == '0') a.push_back(0);
  for (char c : S) {
    if (prev == c) ++cnt;
    else if (prev != '?') {
      ++cnt;
      a.push_back(cnt);
      cnt = 0;
    }
    prev = c;
  }
  if (S[N-1] == '0') a.push_back(0);

  int Na = a.size(), Ns = Na + 1;
  vector<int> s(Na + 1);
  s[0] = 0;
  for (int i = 0; i < Na; ++i) {
    s[i + 1] = s[i] + a[i];
  }

  if (2 * K + 1 >= Ns) {
    cout << s[Na] << endl;
    return 0;
  }

  int vmax = 0;
  for (int i = 0; i + 2 * K + 1 < Ns; i += 2) {
    vmax = max(vmax, s[i + 2 * K + 1] - s[i]);
  }
  cout << vmax << endl;
}


Measured memory_bytes: 4196
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;

void solve() {
    string s, t = "AKIHABARA"; cin >> s; // KIHBR
    if(s.size() > t.size()){
        cout << "NO" << endl;
        return;
    }
    int f = 0;
    rep(i, 0, t.size()){
        if(s[f] != t[i]){
            if(t[i] != 'A'){
                cout << "NO" << endl;
                return;
            }
        }else{
            f++;
        }
    }
    cout << "YES" << endl;
}

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

    solve();
    return 0;
}
 


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#include <set>
#include <math.h>
#define pai 3.14159265358979323846264338327950288;
#define keta(n) cout << fixed << setprecision((n));
using ll = long long;
int main()
{
  string s;
  cin>>s;
  string ans ;
  for(int i=0;i<s.size();i += 2){
    ans += s[i];
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 512
#include <stdio.h>

int main(){
    int a, b, c, A, B, C;
    int X_a, X_b,X_c,Y;
    int count = 0;

    scanf ("%d", &A);
    scanf ("%d", &B);    
    scanf ("%d", &C);
    scanf ("%d", &Y);

    for (a = 0; a <= A;a++){
        X_a = Y;
        X_a = X_a - 500 * a;
        if (X_a < 0){
            break;
        }
        if (X_a == 0){
            count++;
            break;
        }
        for (b = 0; b <= B;b++){
            X_b = X_a;
            X_b = X_b - 100 * b;
            if (X_b < 0){
                break;
            }
            if (X_b == 0){
                count++;
                break;
            }
            for (c = 0; c <= C;c++){
                X_c = X_b;
                X_c = X_c - 50 * c;
                if (X_c < 0){
                    break;
                }
                if (X_c == 0){
                    count++;
                    break;
                }
            }
        }
    }
    printf("%d", count);
    return 0;
}

Measured memory_bytes: 128
#include<stdio.h>



int main()
{
	int ans ;
	int kale ;

	while( 1 )
	{
		scanf( "%d" ,&ans ) ;

		if( ans == 0 )
		{
			return 0 ;
		}

		int i ;
		for( i = 0 ; i < 9 ; ++i )
		{
			scanf( "%d" ,&kale ) ;

			ans -= kale ;
		}


		printf( "%d\n" ,ans ) ;
	}
}

Measured memory_bytes: 1808
#include<bits/stdc++.h>
using namespace std;
struct DisjointSet{
  vector<int>data;
  DisjointSet(int size){data.assign(size, -1);}
  bool unite(int x,int y){
    x=find(x),y=find(y);
    if(x==y)return false;
    if(data[x]>data[y])swap(x, y);
    data[x]+=data[y];
    data[y]=x;
    return true;
  }
  int find(int k){
    if(data[k]<0)return k;
    return data[k]=find(data[k]);
  }
  int size(int k){
    return -data[find(k)];
  }
};
long N,M,A[1<<17],B[1<<17],i,c;
vector<long>r;
int main(){
  cin>>N>>M;
  DisjointSet ds(N);
  for(i=0;i<M;i++)cin>>A[i]>>B[i],A[i]--,B[i]--;
  r.resize(M);
  for(i=M-1;i>=0;i--){
    r[i]=N*(N-1)/2-c;
    if(ds.find(A[i])!=ds.find(B[i])){
      c+=ds.size(A[i])*ds.size(B[i]);
      ds.unite(A[i],B[i]);
    }
  }
  for(auto e:r)cout<<e<<endl;
}


Measured memory_bytes: 4096
#include<stdio.h>
int cost[100000];
int min(int a,int b){
        if(a>b) return b;
        return a;
}
int aabs(int n){
        if(n>0) return n;
        return -n;
}
int main(void){
        int n,k;
        int i,j;
        int h[100000];
        scanf("%d%d",&n,&k);
        for(i=0;i<n;i++){
                scanf("%d",&h[i]);
        }
        for(i=1;i<n;i++){
                cost[i]=-1;
        }
        for(i=1;i<n;i++){
                for(j=1;j<=k;j++){
                        if(i>=j){
                                if(cost[i]==-1){
                                        cost[i]=cost[i-j]+aabs(h[i]-h[i-j]);
                                }else{
                                        cost[i]=min(cost[i],cost[i-j]+aabs(h[i]-h[i-j]));
                                }
                        }
                }
        }
        printf("%d\n",cost[n-1]);
        return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define FORI(i,v) for (auto i = v.begin(); i != v.end(); i++)
#define ALL(v) v.begin(), v.end()
#define CHMIN(x,y) x = min(x, y)
#define CHMAX(x,y) x = max(x, y)
#define YES(b) cout << ((b) ? "YES" : "NO") << endl
#define Yes(b) cout << ((b) ? "Yes" : "No") << endl

int main() {
    cout << fixed << setprecision(15);
    int a, b;
    cin >> a >> b;
    cout << a*b << endl;
}

Measured memory_bytes: 3608
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

int main() {
	int n, m,count=0;
	cin >> n >> m;
	vector<int> a(m);
	vector<int> b(m);
	for (int i = 0; i < m; i++) cin >> a[i] >> b[i];

	vector<int> c(n+1);
	for (int i = 1; i <= n; i++) {
		for (int j = 0; j < m; j++) {
			if (a[j] == i || b[j]==i) {
				c[i]++;
			}
		}
	}
	
	for (int i = 1; i <= n; i++) {
		cout << c[i] << "\n";
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  vector<vector<vector<int>>> data(4, vector<vector<int>>(3, vector<int>(10,0)));
  int n, b, f, r, v;
  cin >> n;
  
  for(int i = 0; i < n; i++){
    cin >> b >> f >> r >> v;
    data.at(b-1).at(f-1).at(r-1) += v;
  }
  
  for(int a = 0; a < 4; a++){
    for(int c = 0; c < 3; c++){
      for(int d = 0; d < 10; d++){
        cout<< " " << data.at(a).at(c).at(d) ;
      }
      cout << endl;
    }
    if(a == 3){
      break;
    }
    cout << "####################" << endl;
  }
  
  
  
}


Measured memory_bytes: 3160
#include <stdio.h>


int main(){
	int n, page[1000], start[1000], end[1000], i, j;
	
	while(1){
		scanf("%d", &n);
		if(n == 0) break;
		for(i = 0;i < 50;i++){
			page[i] = 0;
			start[i] = 0;
			end[i] = 0;
		}
		for(i = 0;i < n;i++) scanf("%d", &page[i]);
		j = 0;
		start[j] = end[j] = page[0];
		for(i = 1;i < n;i++){
			if(page[i] - page[i - 1] == 1) end[j] = page[i];
			else{
				j++;
				start[j] = end[j] = page[i];
			}
		}
		for(j = 0;start[j] != 0;j++){
			if(j != 0) printf(" ");
			if(start[j] == end[j]) printf("%d", start[j]);
			else printf("%d-%d", start[j], end[j]);
		}
		printf("\n");
	}
	
	return 0;
}

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

int n;
vector<int> all;

void get_n(string s){
    if (s.size() == n){
        int z = 0;
        for (int i = 0; i < s.size(); i++) z += (int)pow(10, i) * (s[i] - '0');
        all.push_back(z);
        return;
    }
    vector<bool> used(n, 0);
    for (int i = 0; i < s.size(); i++) used[(s[i] - '1')] = true;
    for (int i = 0; i < n; i++){
        if (used[i]) continue;
        get_n(s + (char)(i + '1'));
    }
}

int main(){
    cin >> n;
    get_n("");
    sort(all.begin(), all.end());
    map<int, int> mp;
    for (int i = 0; i < all.size(); i++) mp[all[i]] = i;
    int p = 0;
    int q = 0;
    int x;
    for (int i = 0; i < n; i++) cin >> x, p += x * (int)pow(10, n - i - 1);
    for (int i = 0; i < n; i++) cin >> x, q += x * (int)pow(10, n - i - 1);
    cout << abs(mp[p] - mp[q]) << endl;
}

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

int main() {
  long long A,B,C;
  cin >> A >> B;
  
  for(int i=1; i<=B; i++){
    C=A*i;
    if(C%B==0){
      cout << C;
      break;
    }
  }
}
    

Measured memory_bytes: 256
import java.util.*;

public class Main
{
    public static long y(long m, long n)
    {
        long tmp;
        while(m%n != 0)
        {
            tmp = n;
            n = m%n;
            m = tmp;
        }
        return n;
    }
    public static void main(String[] args)
    {
        Scanner sc = new Scanner(System.in);
        long a, b, c, d;
        a = sc.nextLong();
        b = sc.nextLong();
        c = sc.nextLong();
        d = sc.nextLong();
        long count = b - a + (long)1;

        long gcd = y(c,d);
        long lcd = c*d/gcd;
        

        // if(a%c==0 && a%d==0)
        // {
        //     count++;
        // }
        // if(b%c==0 && b%d==0){
        //     count++;
        // }
        long tmp;
        tmp = b/c + b/d - b/lcd - (a-1)/c - (a-1)/d + (a-1)/lcd;
        
            
        count = count - tmp;

        System.out.println(count);
        
        
    }
}



Measured memory_bytes: 21844
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;

public class Main {
	static List<Integer> path;

	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] sa = br.readLine().split(" ");
		long h = Long.parseLong(sa[0]);
		long w = Long.parseLong(sa[1]);
		int n = Integer.parseInt(sa[2]);

		int[] a = new int[n];
		int[] b = new int[n];
		Map<Integer, Set<Integer>> map = new HashMap<Integer, Set<Integer>>();
		for (int i = 0; i < n; i++) {
			sa = br.readLine().split(" ");
			a[i] = Integer.parseInt(sa[0]) - 1;
			b[i] = Integer.parseInt(sa[1]) - 1;
			Set<Integer> set = map.get(a[i]);
			if (set == null) {
				set = new HashSet<Integer>();
				map.put(a[i], set);
			}
			set.add(b[i]);
		}
		br.close();

		long[] ans = new long[10];
		for (int i = 0; i < n; i++) {
			for (int jx = -2; jx <= 0; jx++) {
				for (int jy = -2; jy <= 0; jy++) {
					int x = a[i] + jx;
					if (x < 0 || h - 3 < x) {
						continue;
					}
					int y = b[i] + jy;
					if (y < 0 || w - 3 < y) {
						continue;
					}

					int cnt = 0;
					for (int kx = 0; kx <= 2; kx++) {
						Set<Integer> set = map.get(x + kx);
						if (set != null) {
							for (int ky = 0; ky <= 2; ky++) {
								if (set.contains(y + ky)) {
									cnt++;
								}
							}
						}
					}
					ans[cnt]++;
				}
			}
		}

		for (int i = 2; i < 10; i++) {
			ans[i] /= i;
		}

		ans[0] = (h - 2) * (w - 2);
		for (int i = 1; i < 10; i++) {
			ans[0] -= ans[i];
		}

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


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

/*
 *変数
 */
int n,a,b;

/*
 *解 
 */
void solve(){
    printf("%d",a+b);
}

/*
 *入力 
 */
int main(){
       std::cin.tie(0);
       std::ios::sync_with_stdio(false);
       std::cin>>n;
       if(n==2)std::cin>>a>>b;
       else {
           printf("Hello World");
           return 0;
       }
       solve();
       return 0;
}

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

int main () {
	int sharps = 0;
	int H, W;
	char a;
	cin >> H >> W;
	for(int i = 0; i < H; i++)
	{
		for(int j = 0; j < W; j++)
		{
			cin >> a;
			if(a == '#') sharps++;
		}
	}
	if(sharps == H + W - 1) {
		cout << "Possible" << endl;
	}else {
		cout << "Impossible" << endl;
	}
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
public static class P
{
    public static void Main()
    {
        Console.WriteLine(Console.ReadLine().Sum(x => x - '0') % 9 == 0 ? "Yes" : "No");
    }
}

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

int main() {
    int n;cin>>n;
    map<int,int> pf;
    for (int i=2;i<=n;i++) {
        int t=i;
        for (int j=2;j<=t;j++)
            while (t%j==0) {
                pf[j]++;
                t/=j;
            }
    }
    ll ans=1;
    for (auto p:pf)
        ans=ans*(p.second+1)%1000000007;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;

using System.Collections;

class Program
{
    static void Main()
    {
        int K = int.Parse(Console.ReadLine());

        int a = K / 2;
        int b = K - a;

        Console.WriteLine(a * b);

    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
using lint = long long;

int main()
{
  lint a,b;
  cin >> a >> b;
  lint gcd = __gcd(a,b);
  int ans=1;
  for(lint i=2; i*i<=gcd; i++){
    if(gcd%i==0){
      ans++;
      while(gcd%i==0) gcd /= i;
    }
  }
  ans = gcd == 1 ? ans : ans + 1;
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
//using namespace __gnu_pbds;
#define rep(i,a,b) for(i=(a);i<=(b);i++)
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int,int>
#define pb push_back
#define F first
#define S second
#define mod 1000000007
#define maxn 100005
#define inf 1e18
#define boost ios::sync_with_stdio(false);cin.tie(0)
#define fr freopen("source.txt","r",stdin),freopen("output.txt","w",stdout)
#define SET(a,b) memset(a,b,sizeof(a))
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define all(x) x.begin(), x.end()
//template<typename T>
//using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
template<class A, class B> ostream& operator << (ostream& out, const pair<A, B> &a) {
	return out <<  "(" << a.F << ", " << a.S << ")";
}
 
template<class A> ostream& operator << (ostream& out, const vector<A> &a) {
	out << "[";
	for (auto it = a.begin(); it != a.end(); ++it) {
		if (it != a.begin())
			out << ", ";
		out << *it;
	}
	return out << "]";
}
ll powermod(ll x,ll y){
	ll res=1;
	while(y>0){
		if(y&1)
		res=(res*x)%mod;

		y/=2;
		x=(x*x)%mod;
	}
	return res;
}
int main()
{
    boost;
    ll n,i,j,x,t,y,p;
	string s;
	cin>>s;
	n=s.size();
	p=2019;
	vector<ll>v(p+5,0);
	ll cur=1,sum=0;
	for(i=n-1;i>=0;i--){
		x=s[i]-'0';
		x%=p;
		x=(x*cur)%p;
		x=(x+sum)%p;
		v[x]++;
		sum=x%p;
		cur=(cur*10)%p;
	}
	ll ans=v[0];
	cur=1;
	sum=0;
	for(i=n-1;i>=0;i--){
		x=s[i]-'0';
		x%=p;
		x=(x*cur)%p;
		x=(x+sum)%p;
		v[x]--;	
		v[x]=max(v[x],0LL);
		ans+=v[x];
		sum=x%p;
		cur=(cur*10)%p;
	}
	ans=min(ans,n*(n+1)/2);
	cout<<ans<<"\n";
}


Measured memory_bytes: 3696
#include <stdio.h>
#define N 100
 
int main(){
  int i, j, n, temp, arr[N], flag = 1, cnt = 0;
 
  scanf("%d", &n);
 
  for(i = 0; i < n; i++){
    scanf("%d", &arr[i]);
  }
 
  while(flag){
    flag = 0;
    for(i = n - 1; i > 0; i--){
      if(arr[i] < arr[i - 1]){
    temp = arr[i];
    arr[i] = arr[i - 1];
    arr[i - 1] = temp;
    flag = 1;
    cnt++;
      }
    }
  }
 
  for(i = 0; i < n - 1; i++){
    printf("%d ", arr[i]);
  }
  printf("%d\n%d\n", arr[i], cnt);
 
  return 0;
}  

Measured memory_bytes: 600
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdint>
#include <cstdio>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <tuple>
#include <utility>
#include <vector>
using namespace std;

using int64 = int64_t;

constexpr int64 MOD = 1000000007;

int main() {
    int N, M; cin >> N >> M;
    int ans[50];
    fill(ans, ans+50, 0);
    for (int j = 0; j < M; ++j) {
        int a, b; cin >> a >> b;
        --a; --b;
        ans[a]++; ans[b]++;
    }
    for (int j = 0; j < N; ++j) {
        cout << ans[j] << endl;
    }
    return 0;
}


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

using namespace std;

int main(void){
	ios::sync_with_stdio(false);
	
	 #ifdef DEBUG
 
 	 freopen("input.txt", "r", stdin);
   		#endif
   	 int a,b;
   	 cin >> a >> b;               
   	 int sum = 0;
   	 int small, big;
   	 if (a<b)
   	 {
   		small = a;
   		big = b;
   	 }
   	  else
   	  {
   	  	small = b;
   	  	big = a;
   	  }
          
          int left = (16 - 2 * small)/2;
          int right = (big-small);

          if (left >= right)
          {
          	cout << "Yay!" << "\n";
   	  
          }
          else 
          {
         	 cout << ":(" << "\n";

 
          }
   	  return 0;
 
            }


Measured memory_bytes: 256
import std.stdio;

void main() {
//	writeln(__VERSION__);
	if (__VERSION__ <= 2065) {
		return;
	}
	foreach (i; 1..10) {
		foreach (j; 1..10) {
			writef("%dx%d=%d\n", i, j, i*j);
		}
	}
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a,n) for(int i=(a); i<(int)(n); i++)
#define rep(i,n) REP(i,0,n)
#define FOR(it,c) for(__typeof((c).begin()) it=(c).begin(); it!=(c).end(); ++it)
#define ALLOF(c) (c).begin(), (c).end()
typedef long long ll;
typedef unsigned long long ull;

int ret;

bool issame(char a, char b){
  if(a == '?' || b == '?') return true;
  return a == b;
}

void check(const string& a, const string& b, const string& c){
  int M = b.size() + c.size();
  string xa = string(M, '?') + a + string(M, '?');
  int N = xa.size();
  vector<bool> checkB(N,false);
  vector<bool> checkC(N,false);
  
  rep(i,N-b.size()+1){
    bool flg = true;
    rep(j,b.size()){
      if(!issame(xa[i+j],b[j])){
        flg = false;
        break;
      }
    }
    checkB[i] = flg;
  }
  rep(i,N-c.size()+1){
    bool flg = true;
    rep(j,c.size()){
      if(!issame(xa[i+j],c[j])){
        flg = false;
        break;
      }
    }
    checkC[i] = flg;
  }
  unordered_map<int,bool> checkBC;
  string xb = string(N, '?') + b + string(N, '?');
  rep(i,xb.size()-c.size()+1){
    bool flg = true;
    rep(j,c.size()){
      if(!issame(xb[i+j],c[j])){
        flg = false;
        break;
      }
    }
    checkBC[i-N] = flg;
  }

  /*
  cout << xa << endl;
  rep(i,checkB.size()) cout << (checkB[i]?1:0);cout << endl;
  rep(i,checkC.size()) cout << (checkC[i]?1:0);cout << endl;
  cout << xb << endl;
  REP(i,-N,N+1) cout << (checkBC[i]?1:0); cout << endl;
   */
  
  rep(i,N){
    rep(j,N){
      if(checkB[i] && checkC[j] && checkBC[j-i]){
        int lhs = min({i,j,M});
        int rhs = max({i+b.size(),j+c.size(),M+a.size()});
        
        ret = min(ret, rhs-lhs);
      }
    }
  }

  
}

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

  ret = 10000000;

  check(a,b,c);
  
  cout << ret << endl;
  
  return 0;
}



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

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

using namespace std;
using lint=long long;

template<class T>
class network{
	struct edge{
		int to,rev;
		T capa,flow;
		edge(int to,int rev,const T& capa,const T& flow):to(to),rev(rev),capa(capa),flow(flow){}
	};

	int s,t;
	vector<vector<edge>> G;

	vector<int> layer,now;

	bool make_layer(){
		int n=G.size();
		rep(u,n) layer[u]=(u==s?0:-1);

		queue<int> Q; Q.emplace(s);
		while(!Q.empty()){
			int u=Q.front(); Q.pop();
			for(const edge& e:G[u]) if(layer[e.to]==-1 && e.capa-e.flow>0) {
				layer[e.to]=layer[u]+1;
				if(e.to==t) return true;
				Q.emplace(e.to);
			}
		}
		return false;
	}

	T augment(int u,const T& water){
		if(u==t) return water;

		for(int& i=now[u];i<G[u].size();i++){
			edge& e=G[u][i];
			if(layer[e.to]>layer[u] && e.capa-e.flow>0){
				T w=augment(e.to,min(water,e.capa-e.flow));
				if(w>0){
					e.flow+=w;
					G[e.to][e.rev].flow-=w;
					return w;
				}
			}
		}
		return 0;
	}

public:
	network(int n,int s,int t):s(s),t(t),G(n){}

	void add_directed_edge(int u,int v,const T& capa){
		G[u].emplace_back(v,G[v].size()  ,capa,0);
		G[v].emplace_back(u,G[u].size()-1,   0,0);
	}

	void add_undirected_edge(int u,int v,const T& capa){
		G[u].emplace_back(v,G[v].size()  ,capa,0);
		G[v].emplace_back(u,G[u].size()-1,capa,0);
	}

	T maximum_flow(){
		int n=G.size();
		layer.resize(n);

		T res=0;
		while(make_layer()){
			now.assign(n,0);
			for(T water=1;water>0;res+=water) water=augment(s,numeric_limits<T>::max());
		}
		return res;
	}
};

const long long INF=1LL<<61;

int main(){
	int n; scanf("%d",&n);
	vector<lint> a(n);
	rep(i,n) scanf("%lld",&a[i]);

	lint res=0;
	int s=0,t=n+1; // s 側 : 壊す, t 側 : 残す
	network<lint> G(n+2,s,t);
	rep(i,n){
		int x=i+1;
		if(a[i]>=0){
			res+=a[i];
			G.add_directed_edge(x,t,a[i]);
		}
		else{
			G.add_directed_edge(s,x,-a[i]);
		}
		for(int y=2*x;y<=n;y+=x){
			G.add_directed_edge(x,y,INF);
		}
	}

	printf("%lld\n",res-G.maximum_flow());

	return 0;
}


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

using namespace std;

int zeller(int M,int D,int Y = 2004){
  if(M < 3){
    Y--;
    M += 12;
  }
  return (Y+Y/4-Y/100+Y/400+(13*M+8)/5+D)%7;
}

int main(){
  int M,D;
  string A[7] = {"Sunday",
                 "Monday",
                 "Tuesday",
                 "Wednesday",
                 "Thursday",
                 "Friday",
                 "Saturday"};

  while(cin >> M >> D,M){
    cout << A[zeller(M,D)] << endl;
  }
}

Measured memory_bytes: 1192
import java.util.Scanner;

public class Main {
	
	static long[] maxPas = new long[5];
	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		int A = sc.nextInt();
		int B = sc.nextInt();
		int T = sc.nextInt();
		
		if(T/A > 0) {
			System.out.println(T/A*B);
		} else {
			System.out.println(0);
		}
		
	}

}

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

int main(){
    int H1, M1, H2, M2, K;
    std::cin >> H1 >> M1 >> H2 >> M2 >> K;
    
    int wake = (H2 - H1) * 60 + M2 - M1 - K;
    
    std::cout << wake << std::endl;
    
    return 0;
}


Measured memory_bytes: 3592
#include "bits/stdc++.h"
 
using namespace std;
 
typedef long long ll;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;

typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<vi> vvi;
    
 #define sz(x) (int)(x).size()
 #define mp make_pair
 #define pb push_back
 #define all(x) x.begin(), x.end()
 
 #define PI 3.14159265358979323846264338327950L
const int MOD = 1000000007;
 
int main() 
{
    ios_base::sync_with_stdio(0); cin.tie(0);
    
    int n;cin>>n;

    map<int,int> v;
    vi vec(n);
    for(int i=0;i<n;++i)
    {
        cin>>vec[i];
        v[vec[i]]=0;
    }
    
    ll count=0;
    
    vi temp(vec);
    sort(all(temp));
    
    if(!is_sorted(vec.begin(),vec.end()))
    {
    int j=n-1;
    for(int i=n-1;i>=0;--i)
    {
        if(v[temp[i]]==0)
        {
            while(vec[j]!=temp[i])
            {
                count+=(temp[i] - vec[j]);
                v[vec[j]]=1;
                vec[j]=temp[i];
                --j;
            }
            --j;
            
        }
    }
    }
    cout<<count;
}


Measured memory_bytes: 14276
import sys

def conv(c):
    if c == 'A':
        return 'X'
    elif c == 'B':
        return 'Y'
    elif c == 'C':
        return 'Z'
    elif c == 'D':
        return 'A'
    elif c == 'E':
        return 'B'
    elif c == 'F':
        return 'C'
    elif c == 'G':
        return 'D'
    elif c == 'H':
        return 'E'
    elif c == 'I':
        return 'F'
    elif c == 'J':
        return 'G'
    elif c == 'K':
        return 'H'
    elif c == 'L':
        return 'I'
    elif c == 'M':
        return 'J'
    elif c == 'N':
        return 'K'
    elif c == 'O':
        return 'L'
    elif c == 'P':
        return 'M'
    elif c == 'Q':
        return 'N'
    elif c == 'R':
        return 'O'
    elif c == 'S':
        return 'P'
    elif c == 'T':
        return 'Q'
    elif c == 'U':
        return 'R'
    elif c == 'V':
        return 'S'
    elif c == 'W':
        return 'T'
    elif c == 'X':
        return 'U'
    elif c == 'Y':
        return 'V'
    elif c == 'Z':
        return 'W'
    return '_err_'
def decode(str):
    strli = list(str)
    ret = []
    for i in strli[:-1]:
        ret.append(conv(i))
    return "".join(ret)

# fp = open("input.txt", "r")
fp = sys.stdin

str = fp.readline()
str = decode(str)
print str

Measured memory_bytes: 4276
n = int(input())
l = [int(i) for i in input().split()]
cnt = 0
cnt_max = 0
pre = l[0]
for i in range(1,n):
    if pre >= l[i]:
        cnt += 1
    else:
        if cnt_max < cnt:
            cnt_max = cnt
        cnt = 0
    pre = l[i]
else:
    if cnt_max < cnt:
        cnt_max = cnt
print(cnt_max)

Measured memory_bytes: 63984
#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>;

signed main() {
  int n;
  cin >> n;
  vector<int> c(n - 1);
  vector<int> s(n - 1);
  vector<int> f(n - 1);
  for (int i = 0; i < n - 1; ++i) cin >> c[i] >> s[i] >> f[i];

  vector<int> t(n, 0);

  for (int i = 0; i < n - 1; ++i) {
    for (int j = 0; j <= i; ++j) {
      int _t = t[j] - s[i];
      int _s;
      if (_t <= 0)
        _s = s[i];
      else if (_t % f[i] == 0)
        _s = s[i] + _t;
      else
        _s = s[i] + _t + f[i] - (_t % f[i]);

      t[j] = _s + c[i];
    }
  }
  for (int i = 0; i < n; ++i) cout << t[i] << endl;
}


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

int main(){
  int N,K;
  cin>>N>>K;
  set<int> A;
  for(int i=0;i<K;i++){
    int d;
    cin>>d;
    for(int j=0;j<d;j++){
      int a;
      cin>>a;
      A.insert(a);
    }
  }
  cout<<N-A.size()<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
const int mod = 1000000007;

int main(){
	long long n,sum=0,ans=0;
	cin >> n;
	long long a[n+1];
	for(int i = 1 ; i <= n ; i += 1){
		cin >> a[i];
		sum += a[i];
	}
	for(int i = 1 ; i <= n ; i += 1){
		sum -= a[i];
		sum %= mod;
		ans += a[i]*sum;
		ans %= mod;
	}
	if(ans < 0){
		ans += mod;
	}
	cout << ans << endl;
}

Measured memory_bytes: 5160
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        long[] d = new long[n];
        Map<Long, Integer> map = new HashMap<>();
        for (int i = 0; i < n; i++) {
            d[i] = sc.nextLong();
            map.put(d[i], map.getOrDefault(d[i], 0) + 1);
        }
        int m = sc.nextInt();
        long[] t = new long[m];
        for (int i = 0; i < m; i++) {
            t[i] = sc.nextLong();
            if (!map.containsKey(t[i]) || map.get(t[i]) <= 0) {
                System.out.println("NO");
                return;
            }
            map.put(t[i], map.get(t[i]) - 1);
        }
        System.out.println("YES");
    }

}


Measured memory_bytes: 144116
#include <iostream>
#include <algorithm>
#include <cstring>
#include<cstdio>
#include <cmath>
#include<string>
#include<cmath>
using namespace std;

int main()
{
	int x, a, b;

	cin >> x >> a >> b;

	x -= a;
	x -= b* (x/b);

	cout << x << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int gcd(int n, int m){
	return (m==0) ? n:gcd(m,n%m);
}

int main(void) {
	int a,b,g,l;
	while (scanf("%d %d",&a,&b)!=EOF){
		g=gcd(a,b);
		printf("%d %d\n",g,a/g*b);
	}
	return 0;
}

Measured memory_bytes: 596
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <map>
#include <set>
#include <vector>
#include <iostream>
#include <algorithm>
#include <string>
#include <iomanip>
#include <assert.h>
#include <math.h>
#include <stack>
#include <queue>
#include <list>
using namespace std;

// #define __DEBUG__

#ifdef __DEBUG__
bool debug_disabled = false;
#else
bool debug_disabled = true;
#endif

#define dbg if (debug_disabled) {} else cerr

const int MAX = 200000;

int mods[MAX + 10];

void solve() {
    string S;
    cin >> S;
    int cur_pow = 1;
    for (int i = 0; i < S.size(); ++i) {
        int cur_dig = S[S.size() - i - 1] - '0';
        mods[i + 1] = (cur_dig * cur_pow + mods[i]) % 2019;
        cur_pow = (cur_pow * 10) % 2019;
    }

    long long res = 0;
    map<int, long long> counts;
    for (int i = 0; i <= S.size(); ++i) {
        res += counts[mods[i]];
        ++counts[mods[i]];
    }
    cout << res << endl;
}

int main() {
    cout.setf(ios::fixed, ios::floatfield);
    cout.setf(ios::showpoint);
    cout.precision(12);
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    int T = 1;
    // cin >> T;
    for (int i = 1; i <= T; ++i) {
        solve();
    }

    return 0;
}


Measured memory_bytes: 4556
import scala.io.{StdIn => in}

object Main extends App {
  val Array(x, y, z, k) = in.readLine.split(" ").map(_.toInt)
  val a = in.readLine.split(" ").map(_.toLong).sorted(Ordering[Long].reverse)
  val b = in.readLine.split(" ").map(_.toLong).sorted(Ordering[Long].reverse)
  val c = in.readLine.split(" ").map(_.toLong).sorted(Ordering[Long].reverse)

  val ab = {
    for {
      i <- 0 until x
      j <- 0 until y
      if i * j <= k
    } yield {
      a(i) + b(j)
    }
  }.toArray.sorted(Ordering[Long].reverse).take(k)

  val ans = {
    for {
      j <- 0 until z
      i <- 0 until ab.size
      if i * j <= k
    } yield {
      ab(i) + c(j)
    }
  }.toArray.sorted(Ordering[Long].reverse).take(k)

  val out = new java.io.PrintWriter(System.out)
  out.println(ans.mkString("\n"))
  out.flush
}

Measured memory_bytes: 52880
#include<bits/stdc++.h>
#define pb  push_back
using namespace std;
typedef long long ll;
int main(){
	int a[3];
	for(int i=0;i<3;i++) cin >>a[i];
	sort(a,a+3);
	cout << a[0]+a[1];
	return 0;
}

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

using namespace std;

inline int read()
{
    char ch=getchar(); int f=1,x=0;
    while (ch<'0' || ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
    while (ch>='0' && ch<='9') { x=x*10+ch-'0'; ch=getchar(); }
    return f*x;
}

int a,b;

signed main()
{
    a=read(); b=read();
    printf("%d\n",max(0,a-2*b));
    return 0;
}

Measured memory_bytes: 256