akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
using namespace std;
typedef long long ll;

ll gcd(ll x,ll y){
    if(y==0)return x;
    x=x%y;
    gcd(y,x);
}
int main()
{
    ll n,a,b,c,d,e;
    cin>>n>>a>>b>>c>>d>>e;
    ll f;
    f=min(a,min(b,min(c,min(d,e))));
    if(n%f==0){
        cout<<(n/f)+4<<endl;
    }else{
        cout<<(n/f)+5<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**7)
t=int(input())
for _ in range(t):
    memo=dict()
    n,a,b,c,d=map(int,input().split())
    def dfs(x):
        if x==0:
            return 0
        if x==1:
            return d
        if x in memo:
            return memo[x]
        l2=2*(x//2)
        r2=2*(-(-x//2))
        l3=3*(x//3)
        r3=3*(-(-x//3))
        l5=5*(x//5)
        r5=5*(-(-x//5))
        mini=d*x
        mini=min(mini,abs(l2-x)*d+a+dfs(l2//2))
        mini=min(mini,abs(r2-x)*d+a+dfs(r2//2))
        mini=min(mini,abs(l3-x)*d+b+dfs(l3//3))
        mini=min(mini,abs(r3-x)*d+b+dfs(r3//3))
        mini=min(mini,abs(l5-x)*d+c+dfs(l5//5))
        mini=min(mini,abs(r5-x)*d+c+dfs(r5//5))
        memo[x]=mini
        return mini
    print(dfs(n))

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

vector<int> calc(string s) {
	vector<int> res(0x100);
	for(int i = 0; i < s.size(); ++i) {
		res[s[i]]++;
	}
	return res;
}

void solve(long long n, vector<string> S){
	vector<int> res = calc(S[0]);
	for(auto t: S) {
		vector<int> a = calc(t);
		for(int i = 0; i < 0x100; ++i) {
			res[i] = min(res[i], a[i]);
		}
	}
	for(char c = 'a'; c <= 'z'; ++c) {
		for(int i = 0; i < res[c]; ++i) {
			cout << c;
		}
	}
	cout << endl;
}

int main(){	
	long long n;
	scanf("%lld",&n);
	vector<string> S(n-1+1);
	for(int i = 0 ; i <= n-1 ; i++){
		cin >> S[i];
	}
	solve(n, S);
	return 0;
}



Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        int mod = 998244353;
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[][]data = new int[k][2];
        for(int i = 0;i < k;i++){
            data[i][0] = sc.nextInt();
            data[i][1] = sc.nextInt() + 1;
        }
        long[]dp = new long[n];
        dp[0] = 1; dp[1] = -1;
        for(int i = 0;i < n;i++){
            if(i != 0)
            dp[i] = (dp[i] +  dp[i - 1] + mod) % mod;
            for(int j = 0;j < k;j++){
                int l = data[j][0] + i;
                int r = data[j][1] + i;
                if(l < n)
                    dp[l] = (dp[l] + dp[i] + mod) % mod;
                if(r < n)
                    dp[r] = (dp[r] - dp[i] + mod) % mod;
            }
        }
        System.out.println(dp[n - 1]);
    }
}


Measured memory_bytes: 38684
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
using namespace std;
int main(){
  long long n;
  cin>>n;
  string res;
  while(n){
   --n;
   res+=(char)('a'+(n%26));
   n/=26;
  }
reverse(res.begin(),res.end());
cout<<res<<endl;
return 0;
}


Measured memory_bytes: 3624
/************************************
/ AUTHOR : YATHARTH GOSWAMI         /  
/ ALIAS : hacker_yg                 /
/ INSTITUTE : IIT Kanpur            /
************************************/
//          TEMPLATE                //

#include <bits/stdc++.h>

#define ll long long
#define MOD 1000000007
#define pb push_back
#define mp make_pair
#define F first
#define S second

using namespace std;

int main(){
    string a, b;
    int n, m;
    cin >> a >> b;
    cin >> n >> m;
    string rem;
    cin >> rem;
    if (rem == a) cout << n-1 << ' ' << m << endl;
    else cout << n << ' ' << m-1 << endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <queue>
#define N 200005
using namespace std;
typedef long long ll;

ll n, ans, a[N], b[N];
priority_queue<pair<ll, ll>> pq;
int main() {
	int i, x, y, z;
	cin >> n;
	for(i=0; i<n; i++) scanf("%lld", &a[i]);
	for(i=0; i<n; i++) {
		scanf("%lld", &b[i]);
		pq.push({b[i], i});
	}
	while(!pq.empty()) {
		i = pq.top().second;
		pq.pop();
		if(b[i] == a[i]) continue;
		if(b[i] < a[i]) return puts("-1")*0;
		y = b[(i-1+n)%n] + b[(i+1)%n];
		z = (b[i] - a[i]) / y;
		if(z==0) return puts("-1")*0;
		ans += z;
		b[i] -= z * y;
		pq.push({b[i], i});
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 9072
if __name__ == '__main__':
    n, k = map(int, input().split())
    point_r, point_s, point_p = map(int, input().split())
    t = list(input())

    point = {
        'r': point_p,
        's': point_r,
        'p': point_s
    }

    score = 0
    for i in range(n):
        if i < k:
            score += point[t[i]]
        else:
            if t[i] != t[i - k]:
                score += point[t[i]]
            else:
                t[i] = 'x'

    print(score)

Measured memory_bytes: 4084
n = int(input())
edge = [list(map(int, input().split())) for i in range(n-1)]
q, k = map(int, input().split())
query = [list(map(int, input().split())) for i in range(q)]

d = [0 for i in range(n+1)]
visited = [False for i in range(n+1)]
adj = [[] for i in range(n+1)]

for e in edge:
    adj[e[0]].append([e[1], e[2]])
    adj[e[1]].append([e[0], e[2]])
    
st = [k]
visited[k] = True
while st:
    u = st.pop()
    for p in adj[u]:
        v, w = map(int, p)
        if not visited[v]:
            visited[v] = True
            d[v] = d[u]+w
            st.append(v)

for p in query:
    print(d[p[0]]+d[p[1]])

Measured memory_bytes: 83764
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            SolveA();
            //SolveB();
            //SolveC();
            //SolveD();
        }
        private const long MOD = 1000000007;

        static void SolveA()
        {
            int n = ReadAndParseInt();
            var s = new int[n];
            for(int i=0;i<n;++i)
            {
                s[i] = ReadAndParseInt();
            }
            var list = new List<int>(s);
            list.Sort();
            int score = list.Sum();
            if( score % 10 == 0)
            {
                int found = 0;
                foreach(var tmp in list)
                {
                    if(tmp % 10 != 0)
                    {
                        found = tmp;
                        break;
                    }
                }
                if( found >= 1)
                {
                    score -= found;
                }
                else
                {
                    score = 0;
                }
            }
            Console.WriteLine(score);
        }

        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 13268
#include <iostream>

int main(){
  int A,B,K;
  int cp;

  std::cin >> A >> B >> K;

  for(int i=A;i<=B && i<A+K;i++){
    std::cout << i << std::endl;
    cp = i;
  }
  for(int i=cp+1;i<=B;i++){
    if(i > B-K){
      std::cout << i << std::endl;
    }
  }

  return 0;
}


Measured memory_bytes: 256
[<AutoOpen>]
module Program

open System

let read f = stdin.ReadLine() |> f
let reada f = stdin.ReadLine().Split() |> Array.map f
let reads f = stdin.ReadLine().Split() |> Array.toList |> List.map f

[<EntryPoint>]
let main _ =
    let [A;B] = reads int
    if A >= 10 || B >= 10 then
        printfn "-1"
    else
        printfn "%i" (A * B)
    0

Measured memory_bytes: 14160
n,m = map(int, input().split())
h = list(map(int,input().split()))
hbox = []
for i in h:
    a = [i]
    hbox.append(a)
for j in range(m):
    a,b = map(int, input().split())
    hbox[a-1].append(h[b-1])
    hbox[b-1].append(h[a-1])
ans = 0
for l in range(n):
    hbox[l] = sorted(hbox[l])
for k in range(n):
    if h[k] == hbox[k][-1] and not(hbox[k][-1] in set(hbox[k][:-1])):
        ans += 1
print(ans)

Measured memory_bytes: 26688
import java.util.Scanner;

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

        if (a == b && a != c || a == c && a != b || b == c && a != c) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 35808
#include<bits/stdc++.h>
#define pb          push_back
#define endl        '\n'
#define pll         pair<int,int>
#define vll          vector<int>
#define all(a)      (a).begin(),(a).end()
#define x           first
#define y           second
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define int	    int64_t
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count()); 
int n,i,j,k,l,sum=0,flag=0,t,ans=0;
vll v[100005];
int dp[100005][2];
void dfs(int node , int p){
	dp[node][0] = dp[node][1] = 1;
	for(auto j:v[node]){
		if(j!=p){
			dfs(j,node);
			dp[node][0]=(dp[j][1]*dp[node][0])%hell;
			dp[node][1]=(((dp[j][0]+dp[j][1])%hell)*dp[node][1])%hell; 
		}
	}
}
void solve(){
    cin>>n;
    for(int i=0;i<n-1;i++){
    	cin>>j>>k;
    	v[j].pb(k);
    	v[k].pb(j);
    }
    dfs(1,0);
    cout<<(dp[1][0]+dp[1][1])%hell<<endl;
}
signed main()
{
    ios
    int test = 1;
    //cin>>test;
    while(test--){
    	solve();
    }
    return 0;
}

Measured memory_bytes: 14208
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		int h = scanner.nextInt(),w = scanner.nextInt();
		char[][] cstr = new char[h][w];
		for(int i=0;i<h;i++){
			String s = scanner.next();
			cstr[i] = s.toCharArray();
		}
		char[][] board = new char[h][w];
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(cstr[i][j] == '#'){
					board[i][j] = '#';
					continue;
				}
				int count = 0;
				for(int k=-1;k<=1;k++){
					if(i+k < 0 || h - 1 < i+k){
						continue;
					}
					for(int l=-1;l<=1;l++){
						if(j+l < 0 || w - 1 < j+l){
							continue;
						}
						if(cstr[i+k][j+l] == '#'){
							count++;
						}
					}
				}
				board[i][j] = (char)('0' + count);
			}
		}
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				System.out.print(board[i][j]);
			}
			System.out.println();
		}
	}

}


Measured memory_bytes: 22228
#include<iostream>
using namespace std;
int main() {
  int K,N;
  cin >> K >> N;
  int maxd = 0;
  int A[2];
  cin >> A[0];
  int A0 = A[0];
  int i;
  for(i=1;i<N;i++) {
    cin >> A[i%2];
    maxd = max(maxd,A[i%2]-A[(i+1)%2]);
  }
  maxd = max(maxd,A0+K-A[(N+1)%2]);
  cout << K-maxd << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int D;
    cin >> D;
    vector<int>c(26);
    for(int i = 0; i < 26; i++) {
        cin >> c[i];
    }
    vector<vector<int>>s(D,vector<int>(26));
    for(int i = 0; i < D; i++) {
        for(int j = 0; j < 26; j++) {
            cin >> s[i][j];
        }
    }
    vector<int>t(D);
    for(int i = 0; i < D; i++) {
        cin >> t[i];
    }
    int ans = 0;
    vector<int>Last(26);
    for(int i = 0; i < D; i++) {
        ans+=s[i][t[i]-1];
        Last[t[i]-1] = i+1;
        for(int j = 0; j < 26; j++) {
            ans-=c[j]*(i+1-Last[j]);
        }
    }
    int M;
    cin >> M;
    for(int i = 0; i < M; i++) {
        int d,q;
        cin >> d >> q;
        int X = 0;
        int Y = 0;
        int A = 0;
        int B = 0;
        ans+=s[d-1][q-1]-s[d-1][t[d-1]-1];
        for(int j = 0; j < D; j++) {
            if(t[j] == t[d-1]) {
                if(j == d-1) {
                    Y = j+1;
                }
                else {
                    X = j+1;
                }
                A = j+1;
            }
            if(t[j] == q) {
                Y = j+1;
                B = j+1;
            }
            ans-=c[t[d-1]-1]*(j+1-X)-c[t[d-1]-1]*(j+1-A);
            ans+=c[q-1]*(j+1-B)-c[q-1]*(j+1-Y);
        }
        t[d-1] = q;
        cout << ans << endl;
    }
}


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

typedef long long ll;

// chmax, chmin
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 ll INF = 1e+15;
vector<ll> pow6(10),pow9(10);
ll ans;

// 現在X円, これまでに引き落とした回数Y
void dfs( ll X, ll Y ){
    if ( X < 0 ) {
        return;
    } else if ( X == 0 ) {
        chmin(ans,Y);
    } else if ( X < 6 ) {
        chmin(ans,Y+X);
    } else {
        bool flg9 = true, flg6 = true;
        for ( ll i = 9; i >= 0; --i){
            if ( X - pow9[i] >= 0 and flg9 ) {
                dfs( X - pow9[i], Y + 1 );
                flg9 = false;
            } else if ( X - pow6[i] >= 0 and flg6 ) {
                dfs( X - pow6[i], Y + 1 );
                flg6 = false;
            }
        }
    }
    return;
}

int main() {
    ll N;
    cin >> N;
    
    ll six = 1, nine = 1;
    for ( ll i = 0; i < 10; ++i){
        six *= 6; nine *= 9;
        pow6[i] = six;
        pow9[i] = nine;
    }
    ans = INF;
    
    dfs(N,0);
    
    cout << ans << endl;
    
    
    
    return 0;
}


Measured memory_bytes: 3608
#![allow(non_snake_case)]

use std::io::{stdin, Read};
use std::str::FromStr;
fn read_option<T: FromStr>() -> Option<T> {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok()
}
fn read<T: FromStr>() -> T {
    let opt = read_option();
    opt.expect("failed to parse token")
}

fn main() {
    let k: usize = read();
    for _ in 0..k {
        print!("ACL");
    }
    println!("");
}


Measured memory_bytes: 2112
n=int(input())
a=[]
l=[]
for i in range(n):
    p=int(input())
    a.append(p)
    l.append(p)
a.sort()
a=a[::-1]
if a[0]==a[1]:
    for i in range(n):
        print(a[0])
else:
    for i in range(n):
        if l[i]==a[0]:
            print(a[1])
        else:
            print(a[0])





Measured memory_bytes: 14212
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<map>
#include<stack>
#include<queue>
using namespace std;

typedef long long i64;
#define put(n) cout<<(n)<<"\n"
#define FOR(i,num,N) for(int(i)=(num);(i)<(N);(i)++)
#define RFOR(i,num,N) for(int (i)=(num);(i)>(N);(i)--)
#define all(v) (v).begin() , (v).end()
#define rall(v) (v).rbegin() , (v).rend()

int selectionSort(vector<int> &A,int N){
    int count = 0;

    FOR(i,0,N){
        int min_index = i;
        FOR(j,i,N){
            if(A[j] < A[min_index]) min_index = j;
        }

        if(A[i] != A[min_index]) count++;

        swap(A[i],A[min_index]);

    }

    return count;

} 

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

    vector<int> A(N);
    FOR(i,0,N) cin>>A[i];

    int ans = selectionSort(A,N);

    cout<<A[0];
    FOR(i,1,N) cout<<" "<<A[i];

    cout<<"\n";
    put(ans);

}



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

#define FASTIO  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long int
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vl(p) vector<p>
#define w while
#define For(i,s,x) for(i=s;i<x;i++)
#define Fore(i,s,x) for(i=s;i<=x;i++)
#define FOR(i,x) for(i=0;i<x;i++)
#define Rof(i,s,x) for(i=s;i>=x;i--)
#define all(v) v.begin(),v.end()
#define it(r,v) for(auto r=v.begin();r!=v.end();r++)
#define pb push_back
#define in insert
#define sz size()
#define F first
#define S second
#define nl cout<<"\n"
#define pr(a) cout<<a<<" "
#define pr2(a,b) cout<<a<<" "<<b<<"\n"
#define pr3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n"
#define mod 1000000007

int main()
{
	FASTIO;
	int k,i;
	string s;
	cin>>k;
	cin>>s;
	if(k>=s.length())
        cout<<s;
    else
    {
        for(i=0;i<k;i++)
            cout<<s[i];
            cout<<"..."<<"\n";
    }

}


Measured memory_bytes: 3652
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

"""
・次数3以上の点 → d-2個以上の成分に対して1つ以上置かれていないといけない
・それを満たす or 線分 のときに十分：縮約して帰納法
・各部分木に対して、親側にあるとした場合の最小個数を求める
・根として次数3以上の点をとっておけばよい
"""

N = int(readline())
m = map(int,read().split())
AB = zip(m,m)

graph = [[] for _ in range(N+1)]
for a,b in AB:
    graph[a+1].append(b+1)
    graph[b+1].append(a+1)

deg = [len(x) for x in graph]
root = deg.index(max(deg))

if deg[root] <= 2:
    # 区間
    print(1)
    exit()

"""
・dp遷移：max(dp[child],1) の和。ただし0を1つまで許容できる。
・0を既に受け入れたかどうかを補助的にもう1つ持つ。
"""

parent = [0] * (N+1)
ts = []
stack = [root]
while stack:
    x = stack.pop()
    ts.append(x)
    for y in graph[x]:
        if y == parent[x]:
            continue
        parent[y] = x
        stack.append(y)

dp = [0] * (N+1)
use_0 = [False] * (N+1)

for x in ts[::-1]:
    p = parent[x]; d = dp[x]
    if d > 0:
        dp[p] += d
    else:
        if not use_0[p]:
            use_0[p] = True
        else:
            dp[p] += 1

answer = dp[root]
print(answer)

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

using namespace std;


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

    int vDays,assign;
    cin >> vDays >> assign;
    int cap[assign];
    int sum=0;
    for(int i=0;i<assign;i++){
		cin >> cap[i];
		sum+=cap[i];
	}
	int ans = (vDays - sum) >=0 ?(vDays -sum):-1;
	printf("%d",ans); 
	
}



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

int main()
{
    int n,i,co=0;
    std::cin>>n;
    std::vector<int>vec;
    while(n--){
        int x;
        std::cin>>x;
        vec.push_back(x);
    }
    for(i=0;i<vec.size();i++){
        if(vec[i]!=i+1)co++;
    }
    (co>2)?
        std::cout<<"NO"<<std::endl:
        std::cout<<"YES"<<std::endl;
}


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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	int a,b,c;
	cin >> a >> b >> c;
	LL ans = 0;
	if (b >= c) {
		cout << b + c << endl;
		return 0;
	}
	ans += 2*b;
	c -= b;
	ans += min(c,a+1);
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

int main() {
    long long n, k;
    cin >> n >> k;

    long long ret = 0;

    ret = (n / k) * (n / k) * (n / k);
    if (k % 2 == 0) {
        long long t = n / (k / 2) - n / k;
        ret += t * t * t;
    }

    cout << ret << endl;
    return 0;
}


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

int main() {
	string s;
	cin >> s;
	int ret = 0;
	for(int i = 0; i < 4; i++) {
		if(s[i] == '+') ret++;
		if(s[i] == '-') ret--;
	}
	cout << ret << endl;
	return 0;
}


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

int main() {
    vector<int> vec(3);
    cin >> vec[0];
    cin >> vec[1];
    cin >> vec[2];

    sort(vec.begin(),vec.end());

    cout << 10*vec[2]+vec[1]+vec[0] << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define DL double
#define MLL map<LL,LL>::iterator
#define MSL map<string,L>::iterator
#define MLS map<LL,string>::iterator
#define MSS map<string,string>::iterator
#define MCL map<char,LL>::iterator
#define SL set<LL>::iterator
#define SS set<string>::iterator
#define VL V<LL>::iterator
#define G getline
#define SZ size()
#define IN insert
#define C clear()
#define B begin()
#define F front()
#define T top()
#define E end()
#define EM empty()
#define V vector
#define Q queue
#define DQ deque
#define PQ priority_queue
#define ST stack
#define FI first
#define MAX 1e18
#define MIN -1e18
#define SE second
#define PI acos(-1)
#define PS push
#define PP pop()
#define PSF push_front
#define PSB push_back
#define PPF pop_front()
#define PPB pop_back()
#define endl "\n"
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
V<LL>v;
map<LL,LL>u;
int main()
{
    LL n,m,i,j,k,p,q,o,l,s,t,z=0,r;
  cin>>n>>m;
  k=m;
  for(i=1;i<n;i++)
  {
      k*=(m-1);
  }
     cout<<k<<endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String args[]){
        Scanner stdIn = new Scanner(System.in);
 
        int n = stdIn.nextInt();
        long sum = 0;
        //int min = 10000000;
        //int count = 0;
        //int c = stdIn.nextInt();
        //int x = stdIn.nextInt();
        int num[][] = new int[10][10];
        
        for(int i = 0; i < 10; i++){
            for(int j = 0; j < 10; j++){
                num[i][j] = 0;
            }
        }
        //String s = stdIn.next();
        //String t = stdIn.next();
        //char c[] = s.toCharArray();
        
        //c[0] += 1;
        //int sum = 0;
        //boolean flag = true;
        for(int i = 1; i <= n; i++){
            int kazu = i;
            int ue = 0;
            int shita = 0;
            
            while(true){
                if(kazu < 10){
                    ue = kazu;
                    break;
                }else{
                    kazu /= 10;
                }
            }
            
            kazu = i;
            
            shita = kazu % 10;
            
            //System.out.println(ue + " " +shita);
            
            num[ue][shita]++;
        }
        
        for(int i = 1; i < 10; i++){
            for(int j = i; j < 10; j++){
                if(num[i][j] >= 1 && num[j][i] >= 1){
                    if(i == j){
                        sum += num[i][j] * num[j][i];
                    }else{
                        sum += num[i][j] * num[j][i] * 2;
                    }
                }
                
                // if(i == j){
                //     sum += num[i][j];
                // }
                
                //System.out.println(i + " " + j + " " + sum);
            }
        }
        
        
        System.out.println(sum);
        //System.out.println();
        //System.out.print();
        
        //System.out.println(2425 % 10);
 
        stdIn.close();
    }
}

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

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

#define pb push_back
#define in ,
#define rep(i, a, n) for(int i = (a); i < (n); i++)
#define dep(i, a, n) for(int i = (a); i >= (n); i--)
#define mod 1e9+7

__attribute__((constructor))
void initial() {
  cin.tie(0);
  ios::sync_with_stdio(false);
}

int main() {
  int n;
  while(cin >> n) {
    if(!n) return 0;
    int p, a, b;
    int maxs = 0, ans;
    rep(i, 0, n) {
      cin >> p >> a >> b;
      if(maxs < a + b) maxs = a + b, ans = p;
    }
    cout << ans << " " << maxs << endl;
  }
}

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

#define NEW(p,n){p=malloc((n)*sizeof(p[0]));if(p==NULL){printf("not enough memory\n");exit(1);};}
//pの型の変数n個の要素分のメモリを確保し、そのアドレスをpに代入するマクロ

#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define SWAP(type, x, y) do { type tmp = x; x = y; y = tmp; } while (0)

#define MOD 1000000007 

int main(void){
    int H,W;
    scanf("%d%d",&H,&W);

    int c[10][10];
    for(int i=0;i<10;i++){
        for(int j=0;j<10;j++) scanf("%d",&c[i][j]);
    }

    int A[H][W];
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++) scanf("%d",&A[i][j]);
    }

    //C[i][n]...n回の操作でi→1にするときの魔力
    int C[10][1001];
    for(int i=0;i<10;i++) C[i][1]=c[i][1];
    //DPで埋める
    for(int j=2;j<=1000;j++){
        for(int i=0;i<10;i++){
            C[i][j]=99999999;
            for(int k=0;k<10;k++) C[i][j]=MIN(C[i][j],C[k][j-1]+c[i][k]);
        }
    }

    int magic[10];
    for(int i=0;i<10;i++){
        magic[i]=C[i][1];
        for(int j=2;j<=1000;j++) magic[i]=MIN(magic[i],C[i][j]);
    }

    int ans=0;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(A[i][j]!=-1) ans+=magic[A[i][j]];
        }
    }
    printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 384
# x, nを整数で受け取る
x, n= gets.chomp.split(' ').map(&:to_i)


if n == 0
  puts x
else
  # pを配列で受け取る
  array = gets.chomp.split(' ').map(&:to_i)

  
  master = [*0..101]

  array = master - array

  b_array = []
  i_array = []

  array.each_with_index do |a, index|
    b = (a - x).abs
    b_array = b_array.push(b)
  end

  ans = b_array.min
  ans_index = b_array.index(ans)

  p array[ans_index]
end





Measured memory_bytes: 14380
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

S = input()

for i in range(len(S)-1):
	if S[i] == "A" and S[i+1] == "C":
		print("Yes")
		break
else:
	print("No")

Measured memory_bytes: 5396
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readline

n,m = map(int, input().split())
li = [list(map(int, input().split())) for _ in range(n)]

s = 0
for i in sorted(li):
    if i[1] <= m:
        m -= i[1]
        s += i[0] * i[1]
    else:
        s += i[0] * m
        break
print(s)


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

class Program
{
    void Run()
    {
        var sc = new Scanner();
        long l = sc.NextLong();
        long r = sc.NextLong();
        long res = 1 << 60;
        for (long i = 0; i < Math.Min(r - l + 1, 3000); i++)
            for (long j = i + 1; j < Math.Min(r - l + 1, 3000); j++)
            {
                if (l + j > r) break;
                long mm = (((l + i) % 2019) * ((l + j) % 2019)) % 2019;
                if (mm < res) res = mm;
            }
        Console.WriteLine(res);
    }

    static void Main(string[] args)
    {
        new Program().Run();
    }

    static long Gcd(long a, long b)

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

    static long Lcm(long a, long b)
    {
        long d = Gcd(a, b);
        return a / d * b;
    }
}

class Scanner
{
    int index = -1;
    string[] buf;

    public Scanner()
    {
    }

    public int NextInt()
    {
        CheckNext();
        return int.Parse(buf[index++]);
    }

    public long NextLong()
    {
        CheckNext();
        return long.Parse(buf[index++]);
    }

    public double NextDouble()
    {
        CheckNext();
        return double.Parse(buf[index++]);
    }

    public string NextString()
    {
        CheckNext();
        return buf[index++];
    }

    private void CheckNext()
    {
        if (index >= 0 && index < buf.Length) return;

        buf = Console.ReadLine().Split(' ');
        index = 0;
    }
}


Measured memory_bytes: 13140
// 連結成分
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<stack>
#include<algorithm>
#include<iostream>
#include<cmath>
#include<vector>

#include<queue>
#include<stack>

using namespace std;

#define MAX_N 100000

// 値の定義
const int INV = -1;

// 友達関係を保持するための構造体
typedef struct
{
    // 友達関係の個数
    int relation_num;
    // 関係を格納するための vector 配列
    vector<int> v_relation;
}st_Relation;

// 友達関係を保持する配列
st_Relation ary_Link[MAX_N + 1];

// 連結情報を保持する配列
int ary_connection[MAX_N + 1];

void search_relation(int u_ID, int id, int user_num);

int main(void)
{
    int n, m, q, s, t;

    for(int i = 0; i < MAX_N + 1; i++)
    {
        // 配列の初期化
        ary_Link[i].relation_num = 0;
        ary_connection[i] = INV;
    }

    cin >> n >> m;

    for(int i = 0; i < m; i++)
    {
        cin >> s >> t;

        // 友達関係を双方向に設定する
        ary_Link[s].relation_num++;
        ary_Link[s].v_relation.push_back(t);

        ary_Link[t].relation_num++;
        ary_Link[t].v_relation.push_back(s);
    }

    int id = 1;

    for(int u = 0; u < n; u++)
    {
        if( ary_connection[u] == INV )
        {
            // 友達関係の検索を実施
            search_relation(u, id++, n);
        }
    }

    cin >> q;

    for(int i = 0; i < q; i++)
    {
        cin >> s >> t;

        // 質問の結果を表示する
        if( ary_connection[s] == ary_connection[t] )
        {
            // 友達関係が存在する
            printf("yes\n");
        }
        else
        {
            printf("no\n");
        }
    }

    return 0;
}

// 友達関係を検索するための関数
// u_ID : 友達関係を検索する最初のユーザーID
// id   : ary_connection[]に設定するID値
// user_num : 全ユーザー数
void search_relation(int u_ID, int id, int user_num)
{

    int user_id;

    queue<int> Q;

    // 開始点をキューにプッシュする
    Q.push(u_ID);
    // 友達関係を保存する
    ary_connection[u_ID] = id;

    while( !Q.empty() )
    {
        // キューの先頭要素を取得して, 削除する
        // ( 一人のユーザーの巡回は1回だけ )
        int u = Q.front();
        Q.pop();

        for(int v = 0; v < ary_Link[u].relation_num; v++)
        {
            // 友達関係にあるユーザーの検索
            user_id = ary_Link[u].v_relation[v];

            if( ary_connection[user_id] == INV )
            {
                // ----- 未訪問の頂点が見つかった -----

                // 友達関係を保存する
                ary_connection[user_id] = id;

                // キューにプッシュして, 検索を継続する
                Q.push(user_id);
            }
        }
    }

    return;
}



Measured memory_bytes: 9784
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

//        long start1 = System.currentTimeMillis();
//        long end1 = System.currentTimeMillis();
//        System.out.println("time1: " + (end1 - start1));

        Scanner scanner = new Scanner(System.in);
        double l = Integer.parseInt(scanner.nextLine());

//        double v = Math.pow((l / 3), 3);
        double v = (l / 3) * (l / 3) * (l / 3);

        System.out.println(BigDecimal.valueOf(v).toPlainString());
    }
}

Measured memory_bytes: 23508
#include <iostream>
using namespace std;
class Dice {
 public:
  int dice[6];
  int label[6];
  int tmp;
  void init() {
	for(int i = 0; i < 6; ++i) {
	  dice[i] = label[i];
	}
  }
  void moveN() {
	tmp = dice[0];
	dice[0] = dice[1];
	dice[1] = dice[5];
	dice[5] = dice[4];
	dice[4] = tmp;
  }
  void moveS() {
	tmp = dice[0];
	dice[0] = dice[4];
	dice[4] = dice[5];
	dice[5] = dice[1];
	dice[1] = tmp;
  }
  void moveE() {
	tmp = dice[0];
	dice[0] = dice[3];
	dice[3] = dice[5];
	dice[5] = dice[2];
	dice[2] = tmp;
  }
  void moveW() {
	tmp = dice[0];
	dice[0] = dice[2];
	dice[2] = dice[5];
	dice[5] = dice[3];
	dice[3] = tmp;
  }
};
/*
void print(Dice d1) {
    for(int i = 0; i < 6; ++i) {
	  cout << "i:" << i << endl;
	  cout << "\tdice:" << d1.dice[i] << endl;
	}
}
*/
int main() {
  Dice d1;
  char ch;
  
  for(int i = 0; i < 6; ++i) {
	cin >> d1.label[i];
  }
  d1.init();

  while(cin >> ch) {
	if(ch == 'N') {
	  d1.moveN();
	}
	else if(ch == 'E') {
	  d1.moveE();
	}
	else if(ch == 'S') {
	  d1.moveS();
	}
	else {
	  d1.moveW();
	}
	//	print(d1);
  }
  cout << d1.dice[0] << endl;

  return 0;
}

Measured memory_bytes: 3080
#include <iostream>
#include <cstdio>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;


int main(){
    int n, m;

    cin >> n >> m;

    vector<long long> A;

    int count = 0;

    double  sum = 0;

    //int mm = 0;
    int x;

    for(int i = 0; i < n; i++){
        scanf("%d", &x);
        sum = sum + x;
        A.push_back(x);
    }

    sort(A.begin(), A.end());

    //printf("%f\n", sum / (4*m));

    for(int i = 0; i < n; i++){
        if(A[i] >= (sum / (4*m))){
            count++;
            if(count == m){
                break;
            }
        }
    }

    if(count == m){
        printf("Yes\n");
    }
    else{
        printf("No\n");
    }
    

    return 0;
}

Measured memory_bytes: 256
from bisect import bisect_left,bisect_right
import sys
input = sys.stdin.readline


n = int(input())
a = list(map(int, input().replace("\n","").split()))
b = list(map(int, input().replace("\n","").split()))
c = list(map(int, input().replace("\n","").split()))

sa = sorted(a)
sb = sorted(b)
sc = sorted(c)

ans = 0
for i in range(n):
    ab = bisect_left(sa,sb[i])
    bc = n - bisect_right(sc,sb[i])

    if ab == 0:
        continue
    ans += ab * bc

print(ans)

Measured memory_bytes: 96868
#include <bits/stdc++.h>
#define DUMP(x)  cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define IFOR(i, m, n) for(int i = n - 1; i >= m; i-- )
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
const ll INF = 1e18;
/* テンプレートここまで */

int main() {
  string s; cin >> s;
  sort(ALL(s));
  if(s == "abc") cout << "Yes" << endl;
  else cout << "No" << endl;
  
}

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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int inf=1e9;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
int d[10][10];
int main(){
	int n;
	cin>>n;

	
	//memset(d,0,sizeof(d));

	for (int i = 1; i <= n ; i++){
		if(i%10==0)continue;
		string s=to_string(i);
		d[s[0]-'0'][i%10]++;
	}

	int ans=0;
	for (int i = 1; i < 10; i++){
		for (int j = 1; j < 10; j++){
			ans+= d[i][j]*d[j][i];
		}
	}

	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define MAXN 200100
#define inf 1000000000
#define ff first
#define ss second
#define M 1000000007
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
	typedef pair<int,int> pii;
int A[MAXN];

pii BIT[MAXN];


void add1(int x){
	while(x<MAXN){
		BIT[x].ss++;
		x+=(x&-x);
		
	}
}
//valor sem ser comprimido abaixo
void add2(int x,int valor){
	while(x<MAXN){
		BIT[x].ff+=valor;
		x+=(x&-x);
		
	}
}

int soma1(int x){
	
	int r =0;
	while(x>0){
		r+=BIT[x].ss;
		x-=(x&-x);
	}
	return r;
}

int soma2(int x){
	int r =0;
	while(x>0){
		r+=BIT[x].ff;
		x-=(x&-x);
	}
	return r;
}




int soma=0;
vector<int> comprime;

int f(int x){
	int res = soma;
	int posl = lower_bound(comprime.begin(),comprime.end(),x)-comprime.begin()+1;
	int posr = upper_bound(comprime.begin(),comprime.end(),x)-comprime.begin()+1;
	posl--;
	res+=soma1(posl)*x - soma2(posl);
	res+=(soma2(comprime.size())-soma2(posr-1)) - x*(soma1(comprime.size())-soma1(posr-1));
	
	return res;
}

	
int32_t main(){
	fastio
	for(int i=0;i<MAXN;i++){
	BIT[i].ff=BIT[i].ss=0;
	}
	int Q;
	cin>>Q;
	vector<pii> q(Q);
	for(int i=0;i<Q;i++){
		int OP;
		cin>>OP;
		if(OP==1){	
			cin>>q[i].ff>>q[i].ss;
			comprime.push_back(q[i].ff);
		}else {
			q[i].ff=M;
		}
	}
	
	sort(comprime.begin(),comprime.end());

	for(int i=0;i<Q;i++){
		if(q[i].ff!=M){
			soma+=q[i].ss;
			int valor = q[i].ff;
			int pos = lower_bound(comprime.begin(),comprime.end(),valor)-comprime.begin()+1;
			add1(pos);
			add2(pos,valor);
		
		}else{
			int l=-inf-1 , r=inf;
		//	int l = 0,r = 10;
			while(r-l>1){
				int mid = (l+r)/2;
				if(f(mid) > f(mid+1)){
					l = mid;
				
				}else{
					r = mid;
				}
				
			}
			
			cout<<l+1<<" "<<f(l+1)<<endl;
		}
	}

}


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

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

    int k;
    string s;
    cin>>k>>s;
    
    if(s.length()<=k){
        cout<<s<<"\n";
    } else {
        cout<<s.substr(0,k)<<"..."<<"\n";
    }

    return 0;
}

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

int n;
int r[200000];

int main() {
	cin >> n;
	for (int i = 0; i < n; i++) cin >> r[i];
	
	int ans = -2000000001;
	int mini = r[0];
	for (int i = 1; i < n; i++) {
		ans = max(ans, r[i] - mini);
		mini = min(mini, r[i]);
	}
	cout << ans << endl;
	
	return 0;
}

Measured memory_bytes: 3844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
////////////////////////////////////////////////
int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    rep(i, n) cin >> h[i];
    int ans = 0;

    rep(i, n)
    {
        if (h[i] >= k)
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 3688
#include <bits/stdc++.h>
using namespace std;
#define INF 2147483647
#define INFF 9223372036854775807
#define ll long long
#define REP(i,n) for(long long i=0;i<n;i++)
#define REPP(i,m,n) for(long long i=m;i<n;i++)
#define ALL(N) (N.begin(),N.end())
#define de cout << "line : " << __LINE__ << " debug" << endl;
#define pb push_back
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; }

int main() {
    cin.tie(0);    
	ios::sync_with_stdio(false);
    int N;
    cin >> N;
    int H[N];
  	int cnt = 0;
    REP(i,N){
        cin >> H[i];
        if(i >= 1 && H[i-1] - H[i] == 1){
            cnt++;
            if(cnt >= 2){
                cout << "No" << endl;
                return 0;
            }
        }
        else if(i >= 1 && H[i-1] - H[i] >= 2){
            cout << "No" << endl;
            return 0;
        }
        else if(i >= 1 && H[i-1] - H[i] < 0){
            cnt = 0;
        }
    }
    cout << "Yes" << endl;
}

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

using namespace std;
#define ll long long
#define ull unsigned ll
#define all(x) x.begin(), x.end()
const ll MOD = 1e9 + 7;
const int MAX = 5000010;
int lastInc[MAX] = {};

int main()
{
    int a, b;
    cin >> a >> b;
    if (a < b)
        swap(a, b);

    cout << max(a + a - 1, a + b) << endl;
}

Measured memory_bytes: 256
import 'dart:io';

main(List<String> args){
  String s=stdin.readLineSync();
  String t=stdin.readLineSync();
  bool c=true;
  for(int i=0;i<s.length;i++){
    if(s[i]!=t[i]){
      c=false;
      break;
    }
  }
  print(c?"Yes":"No");
}

Measured memory_bytes: 13072
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
#include <iomanip>
#include <cassert>
#include <bitset>
using namespace std;

typedef pair<int, int> P;
#define rep(i, n) for (int i=0; i<(n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define index(xs, x) (int)(lower_bound(all(xs), x) - xs.begin())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007

int N, M;
int X[100000];

int U[100000], R[100000];
long long T[100000];
int S[100000], num_e[100000];
int MX[100000];

int find(int x) {
  if (U[x] == x) return x;
  return U[x] = find(U[x]);
}

void unite(int x, int y) {
  x = find(x), y = find(y);
  if (x == y) return;
  if (R[x] < R[y]) swap(x, y);
  U[y] = x;
  R[x] += R[y]; R[y] = 0;
  T[x] += T[y]; T[y] = 0;
  num_e[x] += num_e[y];
  MX[x] = max(MX[x], MX[y]);
}
bool f(int x) {
  x = find(x);
  return T[x] >= MX[x];
}

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  rep(i, N) cin >> X[i];
  vector<pair<int, P > > edges;
  rep(i, M) {
    int a, b,y;
    cin >> a >> b>>y;a--,b--;
    edges.pb(make_pair(y,P(a,b)));
  }
  sort(all(edges));
  int m = 0;
  rep(i, N) U[i] = i, R[i] = 1, T[i] = X[i], S[i] = 0, num_e[i] = 0;

  int sum = 0;
  rep(i, M) {
    int a = edges[i]._2._1, b = edges[i]._2._2, y = edges[i]._1;
    if (find(a)!=find(b)) {
      sum -= S[find(a)];
      sum -= S[find(b)];
      int s = S[find(a)] + S[find(b)];
      unite(a, b);
      num_e[find(a)]++;
      MX[find(a)] = max(MX[find(a)], y);
      if (f(a)) s = num_e[find(a)];
      S[find(a)] = s;
    }
    else {
      sum -= S[find(a)];
      MX[find(a)] = max(MX[find(a)], y);
      num_e[find(a)]++;
      if (f(a)) S[find(a)] = num_e[find(a)];
    }
    sum += S[find(a)];
    m = max(m, sum);
    //cout<<a<<"<->"<<b<<", y="<<y<<": sum="<<sum<<"\n";
  }

  cout << M-m << "\n";
  return 0;
}


Measured memory_bytes: 4724
using System;

namespace id_0073cs
{
    class Program
    {
        static void Main(string[] args)
        {
            while (true)
            {
                var x = int.Parse(Console.ReadLine());
                var h = int.Parse(Console.ReadLine());
                if (x == 0 && h == 0)
                {
                    break;
                }
                double answer = 2.0 * x * Math.Sqrt(Math.Pow((double)(x) / 2.0, 2.0) + Math.Pow((double)h, 2.0)) + Math.Pow((double)x, 2.0);
                Console.WriteLine("{0:.000000}",answer);
            }
        }
    }
}



Measured memory_bytes: 9232
#![allow(unused_imports)]
#![allow(non_snake_case)]
use proconio::{input, fastout};
use proconio::marker::{Chars, Bytes, Usize1};

use std::cmp::Ordering;
use std::collections::BinaryHeap;

#[derive(Copy, Clone, Eq)]
struct State {
    cost: usize,
    y: usize,
    x: usize
}

impl Ord for State {
    fn cmp(&self, other: &State) -> Ordering {
        other.cost.cmp(&self.cost)
    }
}

impl PartialOrd for State {
    fn partial_cmp(&self, other: &State) -> Option<Ordering> {
        Some(self.cmp(other))
    }
}

impl PartialEq for State {
    fn eq(&self, other: &State) -> bool {
        self.cost == other.cost
    }
}

#[fastout]
fn main() {
    input!{
        H:usize, W:usize,
        ch:Usize1, cw:Usize1,
        dh:Usize1, dw:Usize1,
        g: [String; H]
    }
    let mut G: Vec<Vec<char>> = Vec::new();
    for x in g {
        G.push(x.chars().collect());
    }
    let arr: Vec<(i32, i32)> = vec![(0, 1), (1, 0), (0, -1), (-1, 0)];
    let mut dist = vec![vec![H*W; W]; H];
    dist[ch][cw] = 0;
    let mut q = BinaryHeap::new();
    q.push(State{cost:0, y:ch, x:cw});
    while let Some(State{cost, y, x}) = q.pop() {
        if cost > dist[y][x] { continue; };
        for &(du, dv) in &arr {
            let nu = y.wrapping_add(du as usize);
            let nv = x.wrapping_add(dv as usize);
            if nu < H && nv < W && G[nu][nv] == '.' && dist[nu][nv] > cost {
                dist[nu][nv] = cost;
                q.push(State{cost, y:nu, x:nv});
            }
        }
        for du in -2i32..3 {
            for dv in -2i32..3 {
                let nu = y.wrapping_add(du as usize);
                let nv = x.wrapping_add(dv as usize);
                if nu < H && nv < W && G[nu][nv] == '.' && dist[nu][nv] > cost + 1 {
                    dist[nu][nv] = cost + 1;
                    q.push(State{cost:cost + 1, y:nu, x:nv});
                }
            }
        }
    }
    let ans = dist[dh][dw];
    println!("{}", if ans == H * W {-1} else {ans as i32});
}


Measured memory_bytes: 15196
#include <iostream>
#include <cmath>
#include <algorithm>
#include <map>
#include <vector>

using namespace std;
typedef long long ll;

ll f(ll x, ll m)
{
    return x % m;
}

int main()
{
    ll N, X, M;
    map<ll, ll> entry;
    vector<ll> partial_sum;
    partial_sum.push_back(0);
    cin >> N >> X >> M;
    ll A = X;
    ll sum, period, sum_period;
    int i_0, i_1;
    sum = 0;
    for (int i = 1; i <= N; ++i)
    {
        sum += A;
        partial_sum.push_back(sum);
        if (entry[A] != 0)
        {
            i_0 = entry[A];
            i_1 = i;
            period = i_1 - i_0;
            sum_period = partial_sum[i_1] - partial_sum[i_0];
            ll containing_period = (N - (i_0 - 1)) / period;
            ll remain = N - (i_0 - 1) - containing_period * period;
            sum = partial_sum[i_0 - 1] + sum_period * containing_period + (partial_sum[i_0 + remain - 1] - partial_sum[i_0 - 1]);
            cout << sum;
            return 0;
        }
        entry[A] = i;
        A = f(A * A, M);
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 6740