akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i, n) for (int i = 0; i < n; i++)
#define INF 10000000;
int main()
{
    int n, m, x;
    cin >> n >> m >> x;
    vector<ll> c(n);
    vector<vector<ll>> a(n, vector<ll>(m));
    rep(i, n)
    {
        cin >> c[i];
        rep(j, m)
        {
            cin >> a[i][j];
        }
    }
    //vector<ll> A(m);
    ll min1 = 10000000;

    for (int tmp = 0; tmp < (1 << n); tmp++)
    {
        int flag = 0;
        ll count = 0;
        vector<ll> A(m);
        bitset<14> s(tmp); //s[0]は1の位であり、数字型
        // ビット列を出力
        for (int i = 0; i < n; i++)
        {
            if (s[i] == 1)
            {
                count += c[i];
                rep(j, m)
                {
                    A[j] += a[i][j];
                }
            }
        }
        rep(i, m)
        {
            if (A[i] < x)
            {
                flag = 1;
            }
        }
        if (flag == 0) //満たしている。
        {
            min1 = min(min1, count);
        }
    }
    if (min1 == 10000000)
    {
        cout << -1 << endl;
    }
    else
    {
        cout << min1 << endl;
    }
}

Measured memory_bytes: 3648
def gs() STDIN.gets.chomp end
def gi() gets.to_i end
def gsmi() gets.chomp.split.map(&:to_i) end
 
def desc(ar) ar.sort!{|x,y|y<=>x} end
def min(a,b) a<=b ? a : b end
def max(a,b) a>=b ? a : b end
def sum(ar) ar.inject(:+) end


h,w,ki = gsmi #h<100, w<8, k<8
answer = Array.new(h+1){ Array.new(w){0} }
answer[0][0] = 1
mod = 1000000007

h.times do |i|
	(2**(w-1)).times do |j|
		next if (w-1).times.map{|k| ((j>>k)%4)==3}.any?{|v| v==true}
		
		perm = Array.new(w){|k| k }
		(w-1).times {|k| (perm[k],perm[k+1] = perm[k+1], perm[k]) if (j>>k)&1==1}
		w.times do |k|
			answer[i+1][perm[k]] += answer[i][k]
			answer[i+1][perm[k]] = answer[i+1][perm[k]] % mod
		end
	end
end

puts answer[h][ki-1]

Measured memory_bytes: 2428
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        int[] A = Console.ReadLine().Split().Select(int.Parse).ToArray();
        string s = Console.ReadLine();
        int all = 0;
        int bcount = 0;

        bool b = true;
        for (int i = 0; i < s.Length; i++)
        {
            if (b)
            {
                switch (s[i])
                {
                    case 'a':
                    Console.WriteLine("Yes");
                    all++;
                    break;
                    case 'b':
                    if (bcount < A[2])
                    {
                        Console.WriteLine("Yes");
                        all++;
                        bcount++;
                    }
                    else Console.WriteLine("No");
                    break;
                    default:
                    Console.WriteLine("No");
                    break;
                }
            }
            else
            {
                Console.WriteLine("No");
            }
            if (all >= A[1] + A[2]) b = false;
        }
    }
}

Measured memory_bytes: 15840
def main():
    N = int(input())
    A = list(map(int, input().split()))
    nums = [0] * (N+1)
    for i in A:
        nums[i] += 1
    #nums = [A.count(i) for i in range(N+1)]
    comb = sum((i*(i-1)//2 for i in nums))
    for k in range(N):
        print(comb-(nums[A[k]]-1))

if __name__ == '__main__':
    main()

Measured memory_bytes: 24748
// B - Mix Juice
import { readFileSync } from 'fs';
const input = readFileSync('/dev/stdin', 'utf8');

const [NK, P] = input.split('\n');
const [N, K] = NK.split(' ').map((s) => parseInt(s));
const p = P.split(' ').map((s) => parseInt(s));

const sortedP = p.sort((a, b) => a - b);

let anser = 0;

for (let index = 0; index < K; index++) {
  anser += sortedP[index];
}

console.log(anser);


Measured memory_bytes: 29728
//https://blog.csdn.net/hesorchen
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <list>
#include <set>
#include <queue>
#include <string>
#include <cstring>
using namespace std;
#define ll long long
#define lowbit(a) (a & (-a))
#define endl "\n"
#define PI acos(-1.0)
#define mod 1000000009
#define INF 0x3f3f3f3f
#define MAX 200010

int main()
{
    ll a, b;
    cin >> a >> b;
    if (a % b == 0)
        return !printf("0\n");
    if (a < b)
        return !printf("%lld\n", min((ll)fabs(a - b), a));
    else
    {
        ll temp = a % b;
        return !printf("%lld\n", min(temp, min((ll)fabs(temp - b), b)));
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
// *テンプレート*
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<int, int>
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MOD = 1000000007;
const long long INF = (1LL << 29);
using namespace std;
typedef long long ll;
map<int, int> mp;
using Graph = vector<vector<int>>; 
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

// *テンプレートここまで*

// pair -> vector<pair<int,int>> 
//		   AandB.push_back(make_pair(a[i],b[i]))


signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n, y; cin >> n >> y;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= n; j++) {
			int a = n - i - j;
			if (i >= 0 && j >= 0 && a >= 0 && 10000 * i + 5000 * j + 1000 * a == y) {
				cout << i << " " << j << " " << a << endl;
				return 0;
			}
		}
	}
	cout << -1 << " " << -1 << " " << -1 << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n,m) for(int i = (n); i <(m); i++)
#define rrep(i,n,m) for(int i = (n) - 1; i >=(m); i--)
using namespace std;
using ll = long long;

int main()
{
    ll n, m;
    cin >> n >> m;

    priority_queue<ll> que;
    rep(i, 0, n)
    {
        ll a;
        cin >> a;
        que.push(a);
    }

    while(m > 0)
    {
        ll now = que.top();
        que.pop();
        que.push(now/2);
        --m;
    }

    ll ans = 0;
    while (que.size() > 0)
    {
        ans += que.top();
        que.pop();
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1400
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  vector<long long>a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  sort(a.begin(),a.end());
  
  if(n==2)
  {
    cout<<abs(a[0]-a[1])<<endl;
    return 0;
  }
  vector<int>coef1(n);
  vector<int>coef2(n);
  coef1[0]=1;
  coef1[n-1]=(n%2)? 1:-1;
  coef2[0]=-1;
  coef2[n-1]=(n%2)? -1:1;
  for(int i=1;i<(n-1);i++)
  {
    coef1[i]=(i%2==1)? (-2) : 2;
    coef2[i]=(i%2==1)? 2 : (-2);
  }
  
  sort(coef1.begin(),coef1.end());
  sort(coef2.begin(),coef2.end());
  long long ans1=0;
  long long ans2=0;
  for(int i=0;i<n;i++)
  {
    ans1+=(coef1[i]*a[i]);
    ans2+=(coef2[i]*a[i]);
  }
  cout<<max(ans1,ans2)<<endl;
  return 0;
}

Measured memory_bytes: 4824
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
int main(){
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i,n)cin >> a[i];
    vector<int> v;
    rep(i,n){
        int t = a[i];
        for(int j = 2; j*j <= t; j++)if(t%j == 0){
            v.push_back(j);
            while(t%j == 0)t /= j;
        }
        if(t > 1)v.push_back(t);
    }
    sort(v.begin(),v.end());
    //rep(i,v.size())cout << " " << v[i];cout << endl;
    long long ans = 0;
    rep(i,v.size()){
        long long sum = 0;
        rep(j,n)if(a[j] % v[i] == 0)sum += a[j];
        ans = max(ans, sum);
    }
    cout << ans << endl;
}



Measured memory_bytes: 3184
#include<iostream>
using namespace std;
static const int MAX_M=20;
int B[MAX_M];
int main(void){
	int N,M,C;
		cin >> N >> M >> C;
	for(int i=0;i<M;i++){
		cin >> B[i];
	}
	int res=0;
	for(int i=0;i<N;i++){
		int ans=C;
		for(int j=0;j<M;j++){
			int a;
				cin >> a;
			ans+=a*B[j];
		}
		if(ans>0)
			res++;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextInt()
    val a = IntArray(n) { sc.nextInt() }

    fun gcd(a: Int, b: Int): Int {
        val c = a % b
        return if (c == 0) b else gcd(b, c)
    }

    val ret = a.reduce { acc, i -> gcd(acc, i) }
    println(ret)
}

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

using namespace std;
typedef long long ll;

int n;
ll a[2010];
ll memo[2010][2010];

ll rec(int l, int r) {
  if (memo[l][r]) return memo[l][r];
  if (r - l == 0) return memo[l][r] = a[l];
  if ((r - l + n) % n == 1) return memo[l][r] = max(a[l], a[r]);
  ll res = 0;
  if (a[(l + 1) % n] >= a[r]) res = max(res, rec((l + 2) % n, r) + a[l]);
  if (a[(l + 1) % n] <= a[r]) res = max(res, rec((l + 1) % n, (r - 1 + n) % n) + a[l]);
  if (a[l] > a[(r - 1 + n) % n]) res = max(res, rec((l + 1) % n, (r - 1 + n) % n) + a[r]);
  if (a[l] < a[(r - 1 + n) % n]) res = max(res, rec(l, (r - 2 + n) % n) + a[r]);
  return memo[l][r] = res;
}

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

  ll ans = 0;
  for (int i = 0; i < n; i++) {
    ans = max(ans, rec(i, (i - 1 + n) % n));
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 34592
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using V = vector<ll>;
#define _GLIBCXX_DEBUG
#define rep(i, a) for(int i = 0; i < a; i++)
#define ALL(v) v.begin(), v.end()

int main(){
    string s; cin>>s;
    int ans=700;
    rep(i,3) if(s[i]=='o') ans+=100;
    cout<<ans<<endl;
}

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

template <class T> using V = vector<T>;

using ll = long long;
using db = double;
using st = string;
using ch = char;
using vll = V<ll>;
using vpll =V<pair<ll,ll>>;
using vst = V<st>;
using vdb = V<db>;
using vch = V<ch>;


#define FOR(i,a,b) for(ll i=(a);i<(ll)(b);i++)
#define rFOR(i,a,b) for(ll i=(b);i>(ll)(a);i--)
#define oFOR(i,a,b) for(ll i=(a);i<(ll)(b);i+=2)
#define bgn begin()
#define en end()
#define SORT(a) sort((a).bgn,(a).en)
#define REV(a) reverse((a).bgn,(a).en)
#define M(a,b) max(a,b)
#define rM(a,b) min(a,b)
#define fi first
#define se second
#define sz size()
#define gcd(a,b) __gcd(a,b)
#define co(a) cout<<a<<endl;
#define ci(a) cin>>a;


ll sum(ll n) {
  ll m=0;
  FOR(i,0,12){
    m+=n%10;
    n/=10;
  }
  return m;
}


ll combi(ll n,ll m) {
  ll ans=1;
  rFOR(i,n,n-m){
    ans*=i;
  }
  FOR(i,1,m+1){
    ans/=i;
  }
  return ans;
}


ll lcm(ll a,ll b){
  ll n;
  n=a*b/gcd(a,b);
  return n;
}


/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/


signed main() {
  ll a;
  	ci(a);
  co(lcm(a,2))
     }

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

int main()
{
  int n,a=0,b=0;
  cin>>n;
  vector<int> v(n);
  for(int &i:v) cin>>i;
  for(int i:v)
  {
    if(i%4==0)
      a++;
    else if(i%2==0)
      b++;
  }
  if(n/2<=a+(b/2))
    cout<<"Yes";
  else
    cout<<"No";
  return 0;
}

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

int main(){
	int a,b;
	string s,t,u;
	cin>>s>>t>>a>>b>>u;
	
	if(s==u)
		a-=1;
	else
		b-=1;
		
	cout<<a<<" "<<b<<endl;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#include <algorithm>
using namespace std;

#define ll long long

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}

int main() {

	ll l = 0, r, ans = 0;
	string S;

	cin >> S;
	r = S.size() - 1;

	while (1) {

		if (l >= r) {

			cout << ans << endl;
			break;

		}
		if (S[l] == S[r]) {

			l++;
			r--;
			continue;

		}
		if (S[l] == 'x') {

			l++;
			ans++;

		}
		else if (S[r] == 'x') {

			r--;
			ans++;

		}
		else {

			cout << -1 << endl;
			break;

		}

	}

	return 0;
}

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

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

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n,k,s;
    cin >> n >> k >> s;
    if (s < (int)1e9) {
        for (int i = 0;i < k;++i) cout << s << " \n"[i == n-1];
        for (int i = k;i < n;++i) cout << 1000000000 << " \n"[i == n-1];
    } else {
        for (int i = 0;i < k;++i) cout << s << " \n"[i == n-1];
        for (int i = k;i < n;++i) cout << 1 << " \n"[i == n-1];
    }
    return 0;
}

Measured memory_bytes: 1280
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        t: usize
    }
    for _ in 0..t {
        input!(n: usize, abcd: (usize, usize, usize, usize));

        let mut memo = HashMap::new();
        println!("{}", rec(n, abcd, &mut memo));
    }
}

fn rec(n: usize, abcd: (usize, usize, usize, usize), memo: &mut HashMap<usize, usize>) -> usize {
    let (a, b, c, d) = abcd;
    if n == 0 {
        return 0;
    } else if n == 1 {
        return d;
    }
    if let Some(&res) = memo.get(&n) {
        return res;
    }

    let mut res = Vec::new();
    res.push(rec(n/2, abcd, memo) + d*(n - n/2*2) + a);
    res.push(rec((n+1)/2, abcd, memo) + d*((n+1)/2*2 - n) + a);
    res.push(rec(n/3, abcd, memo) + d*(n - n/3*3) + b);
    res.push(rec((n+2)/3, abcd, memo) + d*((n+2)/3*3 - n) + b);
    res.push(rec(n/5, abcd, memo) + d*(n - n/5*5) + c);
    res.push(rec((n+4)/5, abcd, memo) + d*((n+4)/5*5 - n) + c);
    res.push(n.saturating_mul(d));
    let res = res.into_iter().min().unwrap();
    memo.insert(n, res);
    res
}

Measured memory_bytes: 2732
n,m=map(int,input().split())
PY=[list(map(int,input().split())) for _ in range(m)]

order=[list() for _ in range(n)]
ans=['']*m
for i,py in enumerate(PY):
  p,y=py[0],py[1]
  order[p-1].append((i,y))
  ans[i]+=str(p).zfill(6)
for o in order:
  o.sort(key=lambda x:x[1])
  for i in range(len(o)):
    ans[o[i][0]]+=str(i+1).zfill(6)
for a in ans:
  print(a)

Measured memory_bytes: 58532
N = int(input())
A = list(map(int, input().split()))
A = [0] + A + [0]
total = sum([ abs(A[x]-A[x+1]) for x in range(N+1) ])
for i in range(N):
    minus = abs(A[i] - A[i+1]) + abs(A[i+1] - A[i+2])
    plus = abs(A[i] - A[i+2])
    print(total-minus+plus)

Measured memory_bytes: 14044
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define llp 1000000007
#define mod 1000000007

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;
bool comp(pair<int, int> a, pair<int,int> b){
    return a.S>b.S;
}

int32_t main(){
	ios::sync_with_stdio(false);
    int n, m;
    cin>>n>>m;
    vi a(n);
    REP(i,0,n)cin>>a[i];
    vi b(m),c(m);
    vector<pair<int, int> >bc;
    REP(i,0,m){
        cin>>b[i]>>c[i];
        bc.PB({b[i],c[i]});
    }
    sort(bc.begin(),bc.end(),comp);
    int I=0;
    sort(a.begin(),a.end());
    // deb(bc);
    // deb(a);
    REP(i,0,m){
        // deb(i);
        // deb(I);
        // deb(bc[i].F);
        // deb(min(I+bc[i].F,n));
        int J=I;
        for(int j=I;j<min(I+bc[i].F,n);j++){
            // deb(j);
            if(a[j]>bc[i].S){
                break;
            }
            else{
                a[j]=bc[i].S;
                J++;
            }
        }
        I=J;
        // deb(i);
        // deb(a);
    }
    int sum=0;
    // deb(a);
    REP(i,0,n){
        sum+=a[i];
    }
    cout<<sum<<"\n";

    return 0;
}

Measured memory_bytes: 4852
# -*- coding: utf-8 -*-
import math
import sys
import itertools
import numpy as np
import functools
mo = 1000000007
r = range

n = int(input())

primes = set()
for i in r(2, 1000):
    for p in primes:
        if i % p == 0:
            break
    else:
        primes.add(i)

d = {}
for i in r(2, n+1):
    x = i
    while x != 1:
        for p in primes:
            if x % p != 0:
                continue;
            x //= p
            if p not in d:
                d[p] = 0
            d[p] += 1
            break

ret = 1
for i in d.values():
    ret *= (i+1)
    ret %= mo

print(ret)


Measured memory_bytes: 12416
#n=int(input())
n,m=map(int,input().split())
#l=list(map(int,input().split()))
#l=[list(map(int,input().split())) for i in range(n)]

adjl=[[0 for i in range(n)] for j in range(n)]

for i in range(m):
    a,b=map(int,input().split())
    adjl[a-1][b-1]=1
    adjl[b-1][a-1]=1

import itertools
l=[i for i in range(1,n+1)]
ans=0
#p = itertools.permutations(l)
for v in itertools.permutations(l):
    #tupleで返ってくる
    #print(v[0])
    flag=True
    if v[0]!=1 :
        continue
    for i in range(n-1):
        if adjl[v[i]-1][v[i+1]-1]==0:
            flag=False
            break
    if flag:
        ans+=1
print(ans)


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

int main()
{
  int N, A, B;
  cin >> N >> A >> B;
  int total = 0;
  for (int i = 0; i < 5; ++i)
  {
    int begin = 1;
    int end = 10;
    for (int j = 0; j < i; ++j)
    {
      begin *= 10;
      end *= 10;
    }
    int j = begin;
    for (; j < end; ++j)
    {
      if (N < j)
        break;
      auto m = j;
      int sum = m%10;
      for (int k = 0; k < i; ++k)
      {
        m /= 10;
        sum += m%10;
      }
      if ((A <= sum) && (sum <= B))
        total += j;
    }
    if (j < end)
      break;
  }
  cout << total;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> P;
map <int,int> mp;
vector<int> V;
list<int> L;
stack<int> S;
queue<int> Q;
deque<int> dq;
#define INF (1<<30)
#define INFLL (1ll<<60)
#define EPS (1e-10)
static const int MAX=100000;
static const int MOD=1e9+7;
static const int NMAX=50;
static const int MMAX=50;
int N;
ll T[2],A[2],k1,k2;
ll sum;
int main(){
    cin.tie(0);  ios::sync_with_stdio(false);
    
    cin>>N;
    cin>>T[0]>>A[0];
    N--;
    while(N--){
        cin>>T[1]>>A[1];
        
        k1=(T[0]%T[1]?T[0]/T[1]+1:T[0]/T[1]);
        k2=(A[0]%A[1]?A[0]/A[1]+1:A[0]/A[1]);
        
        
        T[1]*=max(k1,k2);
        A[1]*=max(k1,k2);
        
        swap(T[0],T[1]); swap(A[0],A[1]);
    }
    
    cout<<T[0]+A[0]<<"\n";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Problems problems = new Problems();
        problems.problemB_Flog2();
    }
}

class Problems {
    public static void problemA_Flog1() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] h = new int[N];
        for (int i=0; i<N; i++) {
            h[i] = sc.nextInt();
        }
        int[] C = new int[N];
        C[0] = 0; C[1] = Math.abs(h[0]-h[1]);
        if (N == 2) {
            System.out.println(C[1]);
            return;
        }
        for (int i=2; i<N; i++) {
            C[i] = Math.min(C[i-2]+Math.abs(h[i]-h[i-2]),
                    C[i-1]+Math.abs(h[i]-h[i-1]));
        }
        System.out.println(C[N-1]);
    }

    public static void problemB_Flog2() {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int K = sc.nextInt();
        int[] h = new int[N];
        for (int i=0; i<N; i++) {
            h[i] = sc.nextInt();
        }
        int[] C = new int[N];
        C[0] = 0; C[1] = Math.abs(h[0]-h[1]);
        if (N == 2) {
            System.out.println(C[1]);
            return;
        }
        for (int i=2; i<N; i++) {
            int len = Math.min(K,i);
            int[] Carray = new int[len];
            for (int k = 0; k < len; k++) {
                Carray[k] = C[i-len+k]+Math.abs(h[i]-h[i-len+k]);
            }
            C[i] = Arrays.stream(Carray).min().getAsInt();
        }
        System.out.println(C[N-1]);
    }
}

Measured memory_bytes: 66188
#include <iostream>
#include <string.h>
using namespace std;

int main(){
	char s[10001];
	cin.getline(s,10000);
	int c = strlen(s);
	while(c--)
		if('a' <= s[c] && s[c] <= 'z')
			s[c] += 'A' - 'a';
	cout << s << "\n";
	return 0;
}

Measured memory_bytes: 1132
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "Yes" << endl;
#define POK cout << "OK" << endl;
#define PNO cout << "No" << endl;
#define PNG cout << "NG" << endl;

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  int x,a; cin >> x >>a;
  if(x<a) cout << 0 << endl;
  else cout << 10 << endl;
  return 0;
}


Measured memory_bytes: 256
//20190615
#include <iostream>
#include <vector>
using namespace std;
int func(int a_i);

int main() {
    vector<int> a;
    int s;
    cin >> s;

    a.push_back(s);
    a.push_back(func(a[0]));


    if(a[1] == a[0]){
        cout << 2;
    }
    else{
        int i,j;
        while(true){
            for(i=a.size()-1;i>=0;i--){
                for(j=i-1;j>=0;j--){
                    if(a[i]==a[j]){
                        cout << i+1;
                        return 0;
                    }
                }
            }
        a.push_back(func(a[a.size()-1]));
        }
    }
}

int func(int a_i){
    if(a_i%2==0) return a_i/2;
    else return a_i * 3 + 1;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
template <class T> using reversed_priority_queue = priority_queue<T, vector<T>, greater<T> >;
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;


int main(){
    int n,h,w;
    cin >> n >> h >> w;
    int ans = 0;
    REP(i,n){
        int x,y;
        cin >> x >> y;
        if( x >= h and y >= w) ans++;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.io.*;
import java.util.*;

public class Main {

    private static FastReader in = new FastReader(System.in);
    private static PrintWriter out = new PrintWriter(System.out);

    private static final long MOD = (long) 1e9 + 7;

    public static void main(String[] args) {
        solve();
        out.flush();
    }

    private static void solve() {
        int n = in.nextInt();
        int[] p = in.nextIntArray(n);
        int ans = 0;
        int min = p[0];
        for (int i = 0; i < n; i++) {
            min = Math.min(min, p[i]);
            if (p[i] <= min) {
                ans++;
            }
        }
        out.println(ans);
    }

    // https://www.geeksforgeeks.org/fast-io-in-java-in-competitive-programming/
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;

        FastReader(InputStream inputStream) {
            br = new BufferedReader(new
                    InputStreamReader(inputStream));
        }

        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;
        }

        // https://qiita.com/masakinpo/items/5f77f2a879578a85a0bb
        public int[] nextIntArray(int n) {
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
                a[i] = nextInt();
            return a;
        }

        public long[] nextLongArray(int n) {
            long[] a = new long[n];
            for (int i = 0; i < n; i++)
                a[i] = nextLong();
            return a;
        }
    }
}


Measured memory_bytes: 49232
N=gets.to_i
ACGT=['A','C','G','T']
MOD=10**9+7
dp = {}
ACGT.each do |c1|
  ACGT.each do |c2|
    ACGT.each do |c3|
      c = c1+c2+c3
      dp[c] = [0]*102
      if c == 'AGC' || c == 'ACG' || c == 'GAC'
      else
        dp[c][3] = 1
      end
    end
  end
end
4.upto(N) do |i|
  ACGT.each do |c1|
    ACGT.each do |c2|
      ACGT.each do |c3|
        ACGT.each do |c4|
          c = c1+c2+c3+c4
          if c.match(/AGC/) || c.match(/GAC/) || c.match(/ACG/) || c.match(/A.GC/) || c.match(/AG.C/)
          else
            dp[c2+c3+c4][i] += dp[c1+c2+c3][i-1]         
            dp[c2+c3+c4][i] %= MOD
          end
        end
      end
    end  
  end
end
ans = 0
dp.each_key do |k|
  ans += dp[k][N]
end
puts ans%MOD



Measured memory_bytes: 3836
#include<stdio.h>
#include<math.h>
#include<string.h>
#include<string>
#include<stack>
#include<map>
#include<set>
#include<queue>
#include<iostream>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#define PI acos(-1)
#define pb push_back
#define all(x) x.begin(),x.end()
#define INF 0x3f3f3f3f
#define dd(x) cout<<#x<<" = "<<x<<","
#define de(x) cout<<#x<<" = "<<x<<"\n"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int N=1e6+5;
ll a[N],b[N];
int main()
{
	int n,m,k;
	scanf("%d%d%d",&n,&m,&k);
	for(int i=1;i<=n;i++){
		scanf("%lld",&a[i]);
		a[i]+=a[i-1];
	}
	for(int i=1;i<=m;i++){
		scanf("%lld",&b[i]);
		b[i]+=b[i-1];
	} 
	int ans=0;
	int j=0;
	for(int i=n;i>=0;i--){
		while(a[i]>k){
			i--;
		}
		while(j+1<=m&&a[i]+b[j+1]<=k){
			j++;
		}
		
		ans=max(ans,i+j);
	}
	printf("%d",ans);
}
/*
3 4 102
100 1 1
50 50 50 50
*/

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

int main(){
  int s, t, u;
  cin >> s;

  t = s / 100;
  u = s % 100;

  if((t > 12 || t == 0) && 0 < u && u < 13){
    cout << "YYMM" << endl;
  }
  else if(0 < t && t < 13 && (u > 12 || u == 0)){
    cout << "MMYY" << endl;
  }
  else if(0 < t && t < 13 && 0 < u && u < 13){
    cout << "AMBIGUOUS" << endl;
  }
  else{
    cout << "NA" << endl;
  }

  
}

Measured memory_bytes: 256
n, s = list(map(int, input().split()))
nums = list(map(int, input().split()))

dp = [[0 for i in range(s+1)] for j in range(n+1)]
mod = 998244353

dp[0][0] = 1
for i in range(n):
    for summ in range(s+1):
        if summ - nums[i] >= 0:
            dp[i+1][summ] = (2 * dp[i][summ] + dp[i][summ - nums[i]]) % mod
        else:
            dp[i+1][summ] = (2 * dp[i][summ]) % mod


# print(dp)
print(dp[n][s] % mod)

Measured memory_bytes: 147028
"use strict";

const main = (input) =>{
  
  let arr = input.trim().split(" ");
  
  if(arr[0] =="0") console.log("1");
  if(arr[1] =="0") console.log("2");
  if(arr[2] =="0") console.log("3");
  if(arr[3] =="0") console.log("4");
  if(arr[4] =="0") console.log("5");
 
};

main(require("fs").readFileSync("/dev/stdin","utf8"));

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

namespace AtCoder.Abc
{
    class Abc_049_C
    {
        // https://atcoder.jp/contests/abc049/tasks/arc065_a
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            string[] divide = new string[4]{ "dream", "dreamer", "erase", "eraser" };

            for (int k = 0; k < 4; ++k) divide[k] = new string(divide[k].Reverse().ToArray());
            // 文字列の入力
            string s = Console.ReadLine();
            s = new string(s.Reverse().ToArray());
            bool can = true;
            while (can)
	{
bool can2 = false;
                for (int j = 0; j < 4; j++)
                {
                    string d = divide[j];
                    if (s.Length >= d.Length && s.Substring(0, d.Length) == d)
                    {
                        s = s.Remove(0, d.Length);
                        can2 = true;
                        if (string.IsNullOrEmpty(s)){
                            Console.WriteLine("YES");
                            Console.Out.Flush();
                            return;
                        }
                    }
                }
                if (!can2)
                {
                    can = false;
                    break;
                }
	}

            Console.WriteLine("NO");

            Console.Out.Flush();
        }
    }
}


Measured memory_bytes: 32012
#include<bits/stdc++.h>
#include<cmath>
#include<queue>
#include<algorithm>

using namespace std;
using ll=long long;
using db=double;

typedef vector<int> vii;
typedef vector<ll> vll;
typedef vector<string> vstr;
typedef vector<bool> vbl;

int inf=(1LL<<31)-1;
int MOD=1000000007;

#define fi(a,b) for(int i=a;i<b;i++)
#define fj(a,b) for(int j=a;j<b;j++)
#define f_i(a,b) for(int i=a;i<=b;i++)
#define f_j(a,b) for(int j=a;j<=b;j++)
#define vvii(c,a,b) vector<vector<ii>> c(a,vector<ii>(b,0))
#define vvll(c,a,b) vector<vector<ll>> c(a,vector<ll>(b,0))
#define vvstr(c,a,b) vector<vectorM<string> c(a,vector<string>(b,0))

signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    
    while(true)
    {
        int m,f,r;
        cin >> m >> f >> r;
        if(m==-1&&f==-1&&r==-1)
        {
            return(0);
        }
        else if(m==-1||f==-1)
        {
            cout <<"F" << endl;
        }
        else if(m+f>=80)
        {
            cout << "A" << endl;
        }
        else if(m+f>=65&&m+f<80)
        {
            cout <<"B"<<endl;
        }
        else if(m+f>=50&&m+f<65)
        {
            cout << "C" << endl;
        }
        else if(m+f>=30&&m+f<50&&r>=50)
        {
            cout << "C" << endl;
        }
        else if(m+f>=30&&m+f<50&&r<50)
        {
            cout << "D" << endl;
        }
        else if(m+f<30)
        {
            cout << "F" << endl;
        }
    }
}


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

typedef long long ll;
#define maxn 100005
ll x[maxn];
ll v[maxn], v1[maxn], v2[maxn];
ll mv1[maxn], mv2[maxn];

int main()
{
	ll n, c, ans=0;
	scanf ("%lld%lld", &n, &c);
	
	for (int i=1; i<=n; i++){
		scanf ("%lld%lld", x+i, v+i);
		v1[i] = v1[i-1] + v[i] - x[i] + x[i-1];
		mv1[i] = max (mv1[i-1], v1[i]);
	}
	
	x[n+1] = c;
	for (int i=n; i; i--){
		v2[i] = v2[i+1] + v[i] + x[i] - x[i+1];
		mv2[i] = max (mv2[i+1], v2[i]);
	}
	
	for (int i=0; i<=n; i++)
		ans = max (ans, mv1[i]+mv2[i+1]-min (x[i], c-x[i+1]));
	
	printf("%lld\n",ans);
    return 0;
}

Measured memory_bytes: 4992
setting = input().rstrip().split(" ")
N = int(setting[0])
Y = int(setting[1])
A = -1
B = -1
C = -1

for x in range(N+1):
    for y in range(N+1):
        if N-x-y >= 0:
            if 10000*x + 5000*y + 1000*(N-x-y) == Y :
                A , B , C = x ,y,N-x-y
                break
    else:
            continue
    break
print(A," ",B," ",C)


Measured memory_bytes: 3188
from collections import Counter
n=int(input())
a=[int(i) for i in input().split()]

dic = Counter(a)
for i,j in list(dic.items()):
    if i-1 in dic:
        dic[i-1]+=j
    elif i-1 not in dic:
        dic[i-1]=j
    if i+1 in dic:
        dic[i+1]+=j
    elif i+1 not in dic:
        dic[i+1]=j

print(max(dic.values()))

Measured memory_bytes: 22944
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i=0;i < (int)(n);i++)

int main(){
   string s;
   cin >> s;
   rep(i,s.size()){
      if(s[i] == ',' ) s[i] = ' ';
   }
   cout << s << endl;
   return 0;
   
}



Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<=n;++i)
using namespace std;
int main()
{
  string s;cin >> s;
  bool f = true;
  rep(i,3) {
    if(s[i] == '7') f = false;
  }

  if(f) cout << "No" << "\n";
  else cout << "Yes" << "\n";
  return 0;
}


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

using namespace std;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vb = vector<bool>;
using vd = vector<double>;
using vs = vector<string>;

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

    int N;
    ll M;
    cin >> N >> M;

    vvi adj(N);
    for(int i=0;i<N-1;i++) {
        int x, y;
        cin >> x >> y;
        x--; y--;
        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    queue<int> bfs;
    vi parent(N, -1);
    vvi children(N);
    vi cindex(N, -1);
    vi order;

    bfs.push(0);
    parent[0] = 0;

    while (!bfs.empty()) {
        int cur = bfs.front();
        bfs.pop();

        order.push_back(cur);

        for(int nbr : adj[cur]) {
            if (parent[nbr] == -1) {
                parent[nbr] = cur;
                cindex[nbr] = children[cur].size();
                children[cur].push_back(nbr);
                bfs.push(nbr);
            }
        }

    }

    reverse(order.begin(), order.end());

    vll dp(N, 0);

    vvll prefs(N);
    vvll suffs(N);
    for (int v : order) {
        int S = children[v].size();

        ll cur = 1;
        prefs[v].push_back(cur);
        for (int i=0;i<S;i++) {
            int w = children[v][i];
            cur *= dp[w];
            cur %= M;
            prefs[v].push_back(cur);
        }

        cur = 1;
        suffs[v].push_back(cur);
        for(int i=0;i<S;i++) {
            int w = children[v][S-1-i];
            cur *= dp[w];
            cur %= M;
            suffs[v].push_back(cur);
        }
        
        dp[v] = 1 + prefs[v][S];
        dp[v] %= M;
    }

    vvll dpe(N);
    reverse(order.begin(), order.end());
    for (int v : order) {
        ll base = 1;
        if (v != 0) {
            // contribution from parent
            int par = parent[v];
            base = dpe[par][cindex[v]];
        }

        int S = children[v].size();
        for(int i=0;i<S;i++) {

            ll cur = (base * prefs[v][i]) % M;
            cur = (cur * suffs[v][S-i-1]) % M;
            cur++;
            dpe[v].push_back(cur);
        }
    }

    vll dpf(N);
    for (int v : order) {
        dpf[v] = 1;
        if (v != 0) {
            int par = parent[v];
            dpf[v] = dpe[par][cindex[v]];
        }
        dpf[v] = (dpf[v]*(dp[v]+M-1)) % M;
    }

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


    return 0;
}

Measured memory_bytes: 31352
import numpy as np
import copy
N = int(input())
A = []
for i in range(N):
    A.append(int(input()))

tmp = copy.deepcopy(A)
tmp = list(sorted(A, reverse=True))

Amax = tmp[0]
Asecond = tmp[1]

for i in range(N):
    if A[i] != Amax:
        print(Amax)
    else:
        print(Asecond)


Measured memory_bytes: 24888
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define ss st.st
#define sn st.nd 
/****************************/
int a[3][100010];
int n;
ll dp[3][100010];
int main()
{
	ios::sync_with_stdio(0);
	cin>>n;
	rep(i,n)
	{
		rep(j,3)
		{
			cin>>a[j][i];
		}
	}
	memset(dp,0,sizeof(dp));
	dp[0][0]=a[0][0];
	dp[1][0]=a[1][0];
	dp[2][0]=a[2][0];
	rep3(i,1,n)
	{
		rep(j,3)
		{
			rep(k,3)
			{
				if(j!=k)
				{
					dp[j][i]=max(dp[j][i],dp[k][i-1]+a[j][i]);
				}
			}
		}
	}
	ll ans=0;
	rep(i,3)
	{
		ans=max(ans,dp[i][n-1]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3840
#include <iostream>
using namespace std;
int main(void){
 int A, B, C;
 cin >> A >> B >> C;
if ( A != B && B != C && C != A ){
    cout << "No" << endl;
}
else if ( A == B & B == C ){
    cout << "No" << endl;
}
else { cout << "Yes" << endl; }
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define loop2(i, s, n, a) for (int i = int(s); i < int(n); i += a)
#define loop(i, s, n) loop2(i, s, n, 1)
#define rep(i, n) loop(i, 0, n)

#define pb push_back
#define all(in) in.begin(),in.end()

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

int main(){
    ll n; cin >> n;
    ll ans;
    for(ll i = 1; i*i <= n; i++) if(n%i == 0) ans = i + n/i -2;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
typedef long long ll;
vector<ll> ans;
ll par[100010], n, m, a[100010], b[100010], res, gro[100010];

int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
	if (par[x] == x) return x;
	return par[x] = root(par[x]);
}

void unite(int x, int y) { // xとyの木を併合
	int rx = root(x); //xの根をrx
	int ry = root(y); //yの根をry
	if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
	par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
}

bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
	int rx = root(x);
	int ry = root(y);
	return rx == ry;
}


int main()
{
	cin >> n >> m;
	for (ll i = 1; i <= n; i++) par[i] = i;
	for (ll i = 0; i <= n; i++) gro[i] = 1;
	res = (n - 1) * n / 2;
	for (ll i = m; i >= 1; i--) cin >> a[i] >> b[i];
	for (ll i = 1; i <= m; i++)
	{
		ans.push_back(res);
		if (!same(a[i], b[i]))
		{
			res += gro[root(a[i])] * (gro[root(a[i])] - 1) / 2 + gro[root(b[i])] * (gro[root(b[i])] - 1) / 2;
			ll tt = gro[root(a[i])] + gro[root(b[i])];
			unite(a[i], b[i]);
			gro[root(a[i])] = tt;
			res -= tt * (tt - 1) / 2;
		}
	}
	for (ll i = ans.size() - 1; i >= 0; i--) cout << ans[i] << endl;
}

Measured memory_bytes: 5364
import sys, math, itertools, bisect, copy, re
from collections import Counter, deque, defaultdict

# from itertools import accumulate, permutations, combinations, takewhile, compress, cycle
# from functools import reduce
# from math import ceil, floor, log10, log2, factorial
# from pprint import pprint

INF = float('inf')
MOD = 10 ** 9 + 7
EPS = 10 ** -7
sys.setrecursionlimit(1000000)

# N = int(input())
# N,M = [int(x) for x in input().split()]
# V = [[0] * 100 for _ in range(100)]
# A = [int(input()) for _ in range(N)]
# DP = [[0] * 100 for _ in range(100)]
# DP = defaultdict(lambda: float('inf'))


N = int(input())
s = {int(input()) for _ in range(N)}
print(len(s))

Measured memory_bytes: 4208
import java.util.*;
import java.math.BigDecimal;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        double n = sc.nextInt();
        double m = sc.nextInt();
        double d = sc.nextInt();
        double ans = 0;
        if (d == 0) {
            ans = ((m - 1) / n);
        } else {
            ans = (2 * (n - d) * (m - 1)) / (n * n);
        }
        System.out.println(BigDecimal.valueOf(ans).toPlainString());
    }    
}


Measured memory_bytes: 21972
import math

def main():
    n = int(input())
    v = [int(t)for t in input().split()]
    c = [int(t)for t in input().split()]

    e = [v[i]-c[i]for i in range(n)]
    e = [t for t in e if t>0]

    print(sum(e))
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
/***
**   AUTHOR::ASHUTOSH MOUDGIL
***/


#include<bits/stdc++.h>
using namespace std;

#define pb push_back
#define mp make_pair
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F first
#define S second
#define int long long
//#define ll long long
#define all(x) x.begin(),x.end()
#define rsort(x) sort(all(x)); reverse(all(x));
#define endl '\n'
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define vi vector<int>
#define vlli vector<long long>
#define pii pair<int,int>
#define mod 1000000007
#define LMAX 1e18
#define deb(x) cout<<#x<<" : "<<x<<endl;

const int M = 1000005;
int seive[M];
void pre(){
    for(int i=1;i<M;i++)
        seive[i]=i;
    for(int i=2;i*i<M;i++){
        if(seive[i]==i){
            for(int j=i*i;j<M;j+=i)
                if(seive[j]==j)
                    seive[j]=i;
        }
    }
}

void mymain(){
    pre();
    int a,b;
    cin >> a >> b;
    int g = gcd(a,b);
    set<int> s;
    int x = g;
    map<int,int> res;
    for(int i=2;i*i<=g;i++){
        while(g%i==0){
           res[i]++;
           g/=i;
        }
    }
    if(g!=1){
        res[g]++;
    }
    cout << res.size() +1<< endl;
}

signed main(){
IOS;
///freopen("input.txt", "r", stdin);
///freopen("output.txt", "w", stdout);
int t=1;
///cin>>t;

for(int tt=0;tt<t;tt++){
   ///cout << "Case #" << tt+1 <<": ";
   mymain();
   }
return 0;
}


Measured memory_bytes: 8064
#include<iostream>
#define rep(i,n) for(int i=0;i < (n);i++)

using namespace std;
int main()
{
    int k,x;
    int m,p;
    int ans[105];

    cin>>k>>x;
    m = x-k+1;
    rep(i,k*2-1)
    {
        ans[i] = m+i;
        cout<<ans[i]<<" ";
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 256
module AOJ_Volume0101;

import std.stdio,std.string,std.conv,std.array;

int main()
{
	int n = readln.chomp.to!int;
	while(n--)
	{
		string s = readln.chomp;
		replace(s,"Hoshino","Hoshina").writeln;
	}
	return 0;
}

Measured memory_bytes: 1068
#include <bits/stdc++.h>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <iostream>
#include <numeric>
#define rep(i,n) for (int i = 0;i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define chmax(x,y) x = max(x,y)
int INF = 1e9;

ll calc(ll n,ll b){
	if(b>n) return n;
	ll ret = n%b;
	return ret + calc(n/b,b);
}

int main(){
	ll n,s;cin >> n >> s;
	if(s == n) {
		cout << n+1 << endl;
		return 0;
	}else if(s > n){
		cout << -1 << endl;
		return 0;
	}
	for(int i = 2;i <= sqrt(n);i++){
		if(calc(n,ll(i))==s) {
			cout << i << endl;
			return 0;
		}
	}
	for(int p = sqrt(n);p >= 1;p--){
		ll b = (n-s)/ll(p) + 1;
		if(b < 2) continue;
		//cout << b << endl;
		//if((n-s)%ll(p)!=0) continue;
		if(calc(n,b)==s) {
			cout << b << endl;
			return 0;
		}
	}
	cout << -1 << endl;
	

} 
//99999999999 100000000000 100000000000 99999999999

Measured memory_bytes: 3680
import java.util.Scanner;

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

		if(b%a==0){
			c=a+b;
		} else {
			c=b-a;
		}

		System.out.println(c);
		return;

	}
}


Measured memory_bytes: 21844