akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import static java.lang.Math.*;
import java.math.BigInteger;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		int m = sc.nextInt();
		String s = sc.next();

		// 計算
		ArrayList<Integer> result = new ArrayList<Integer>();
		int now = s.length() - 1;
		boolean can = true;
		while(now > 0 && can){
		    can = false;
		    for(int i = 0; i < m; i++){
		        int index = max(0, now - (m - i));
		        if(s.charAt(index) == '0'){
		            result.add(now - index);
		            now = index;
		            can = true;
		            break;
		        }
		    }
		}
		if(now != 0){
		    System.out.println(-1);
		    return;
		}
		
		// 出力
		for(int i = result.size() - 1; i >= 0; i--){
		    System.out.print(result.get(i) + " ");
		}
	}
}


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

const int mod = 1000000007;
struct mint {
  ll x;
  mint(ll x=0):x((x%mod+mod)%mod){}
  mint operator-() const { return mint(-x);}
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod-a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) { (x *= a.x) %= mod; return *this;}
  mint operator+(const mint a) const { return mint(*this) += a;}
  mint operator-(const mint a) const { return mint(*this) -= a;}
  mint operator*(const mint a) const { return mint(*this) *= a;}
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t>>1);
    a *= a;
    if (t&1) a *= *this;
    return a;
  }
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, const mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}

int main() {
    int n;
    cin >> n;
    int zero = 0;
    map<pair<ll,ll>,P> mp;
    rep(i,n) {
        ll x, y;
        cin >> x >> y;
        if (x == 0 && y == 0) {
            zero++;
            continue;
        }
        ll g = gcd(x, y);
        x /= g;
        y /= g;
        if(y < 0) x = -x, y = -y;
        if(y == 0 && x < 0) x = -x, y = -y;
        bool rot = (x <= 0);
        if(rot) {
            ll tmp = x;
            x = y, y = -tmp;
        }
        if(rot) mp[{x,y}].first++;
        else mp[{x,y}].second++;
    }

    mint ans = 1;
    for(auto p : mp){
        int s = p.second.first;
        int t = p.second.second;
        mint now = 1;
        now += mint(2).pow(s) - 1;
        now += mint(2).pow(t) - 1;
        ans *= now;
    }

    ans -= 1;

    ans += zero;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 15980
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n;i++)
using namespace std;
int main(){
    int n, k;
    cin >> n >> k;
    string s;
    cin >> s;
    int cnt = 0,ans=0;
    rep(i,n-1){
        if(s[i]==s[i+1]){
            ans++;
        }
    }
    cout << min(2*k+ans,n-1) << endl;
}

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

int main()
{
	int N, L;
	bool flag = false;
	cin >> N >> L;
	int a, b, res;
	cin >> b;
	for (int i = 1; i < N; i++) {
		cin >> a;
		if (b + a >= L) {
			flag = true;
			res = i;
		}
		b = a;
	}
	if (flag) {
		cout << "Possible" << endl;
		for (int i = 1; i < res; i++)
			cout << i << endl;
		for (int i = N - 1; i > res; i--)
			cout << i << endl;
		cout << res << endl;
	}
	else
		cout << "Impossible" << endl;
	return 0;
}


Measured memory_bytes: 768
#include <stdio.h>
#define N 2000
#define Q 2000

int n,q,i,j;
int a[N],m[Q],array[N];
void solve(int,int);

main(){
  
  scanf("%d",&n);
  
  for(i=0;i < n;i++)  scanf("%d",&a[i]);
  
  scanf("%d",&q);
  
  for(i=0;i < q;i++)  scanf("%d",&m[i]);
  
  for(i=0;i < q;i++){
    array[i]=0;
    solve(0,m[i]);
    if(array[i]==1)  printf("yes\n");
    else printf("no\n");
  }
  return 0;
}

void solve(int l,int m){
  if (m == 0) array[i]=1;
  if(m>0 && l<n){
    solve(l+1,m-a[l]);
    solve(l+1,m);
  }
}

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

int main() {
    #ifdef DEBUG
        freopen("in.txt", "r", stdin);
    #endif
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);

    int a, b, c; cin >> a >> b >> c;
    int a_orig = a;
    while (a <= 1000000) {
        if (a % b == c) {
            cout << "YES\n";
            return 0;
        }
        a += a_orig;
    }

    cout << "NO\n";

    return 0;
}


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

int main(){
    int N;
    cin >> N;
    int T, A;
    cin >> T >> A;
    int H[N],D;
    int res = 0;
    int min = 1000000;
    for (int i = 1; i < N+1; ++i){
        cin >> H[i];
        D = 1000*T - 6*H[i] - 1000*A;
        if (D < 0){
            D = -D;
        }
        if (D < min){
            min = D;
            res = i;
        }
    }

    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

#define N 101
#define WHITE  0
#define GRAY   1
#define BRACK  2

void DFS();
void visit(int);

int n,time=0,color[N],d[N],f[N],k[N],G[N][N];

int main(){

  int i,j,u,v;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      G[i][j]=0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&u,&k[i]);
    for(j=0;j<k[i];j++){
      scanf("%d",&v);
      G[u-1][j]=v-1;
    }
  }

  DFS();

  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }

  return 0;
}

void DFS(){
  int i;

  for(i=0;i<n;i++){
    color[i]=WHITE;
  }
  for(i=0;i<n;i++){
    if(color[i]==WHITE) visit(i);
  }
}


void visit(int u){
  int v;

  color[u]=GRAY;
  time++;
  d[u]=time;
  
  for(v=0;v<k[u];v++){
    if(G[u][v] && color[G[u][v]]==WHITE)
      visit(G[u][v]);
  }
  
  color[u]=BRACK;
  f[u]=++time;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long n,i;
    double w;
    cin>>n;
    if(n%2==0) i=n/2;
    else i=(n+1)/2;
     w=(double)(i)/(double)(n);
    cout<<fixed<<setprecision(10)<<w<<endl;

return 0;
}


Measured memory_bytes: 3764
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#define rep(i, n) for(i = 0; i < n; i++)
#define int long long
using namespace std;

int powmod(int a, int n, int mod) {
	if (n == 0) return 1;
	if (n % 2 == 0) return powmod((a * a) % mod, n / 2, mod);
	return (a * powmod(a, n - 1, mod)) % mod;
}

int mod = 900000011;
int mod2 = 1000000009;
int base = 500000003;
int n;
string s;

bool check(int len) {
	int i;
	int memo[5000];
	int memo2[5000];
	
	int B = powmod(base, len, mod);
	int B2 = powmod(base, len, mod2);
	
	int hashNum = 0;
	for (i = n - 1; i >= 0; i--) {
		hashNum += s[i];
		hashNum %= mod;
		if (n - i >= len) {
			memo[i] = hashNum;
		}
		else {
			memo[i] = -1;
		}
		hashNum *= base;
		hashNum %= mod;
		if (n - i >= len) {
			hashNum = (hashNum - s[i + len - 1] * B % mod + mod) % mod;
		}
	}
	
	hashNum = 0;
	for (i = n - 1; i >= 0; i--) {
		hashNum += s[i];
		hashNum %= mod2;
		if (n - i >= len) {
			memo2[i] = hashNum;
		}
		else {
			memo2[i] = -1;
		}
		hashNum *= base;
		hashNum %= mod2;
		if (n - i >= len) {
			hashNum = (hashNum - s[i + len - 1] * B2 % mod2 + mod2) % mod2;
		}
	}
	
	set<int> dict;
	set<int> dict2;
	for (i = n - len; i >= 0; i--) {
		if (i + len <= n - len) {
			dict.insert(memo[i + len]);
			dict2.insert(memo2[i + len]);
		}
		if (dict.find(memo[i]) != dict.end() && dict2.find(memo2[i]) != dict2.end()) return true;
	}
	return false;
}

signed main() {
	int i;
	
	cin >> n >> s;
	
	int st = 0, ed = n + 1, mid;	//oooxxx
	while (ed - st >= 2) {
		mid = (st + ed) / 2;
		if (check(mid)) st = mid;
		else ed = mid;
	}
	cout << st << endl;
	return 0;
}

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

long long N,K;
int main(){
    cin >> N >> K;
    long long ans = (N / K) * (N / K) * (N / K);
    if(K % 2 == 0) ans += ((N + K/2) / K) * ((N + K/2) / K) * ((N + K/2) / K);
    cout << ans << endl;
    return 0;
}

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

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

    if(a+b > c+d) cout << "Left" << endl;
    else if(a+b == c+d) cout << "Balanced" << endl;
    else cout << "Right" << endl;
}

Measured memory_bytes: 384
s=input()
n=len(s)
s+="ZZZ"
si=0
ra=0
rbc=0
ans=0
while si<n:
    if(s[si]=="A"):
        ra+=1
        si+=1
    else:
        if(s[si:si+2]=="BC"):
            ans+=ra
            si+=2
        else:
            ra=0
            si+=1
print(ans)

Measured memory_bytes: 3500
#include<stdio.h>
int main(){
  int n, a; scanf("%d %d", &n, &a);
  int v[n]; for(int i = 0; i < n; ++i) scanf("%d", &v[i]);
  long dp[n+1][n+1][50*n+1];
  for(int i = 0; i <= n; ++i) for(int j = 0; j <= n; ++j) for(int k = 0; k <= 50*n; ++k) dp[i][j][k] = 0;
  dp[0][0][0] = 1;
  for(int i = 0; i < n; ++i){
    for(int j = 0; j <= i; ++j){
      for(int k = 0; k <= 50*i; ++k){
        dp[i+1][j][k] += dp[i][j][k]; dp[i+1][j+1][k+v[i]] += dp[i][j][k];
      }
    }
  }
  long ans = 0;
  for(int i = 1; i <= n; ++i) ans += dp[n][i][a*i];
  printf("%ld\n", ans);
  return 0;
}

Measured memory_bytes: 52548
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll>pl;
const ll asize=1e5+5,inf=1e15;

int main(){
	ios_base::sync_with_stdio(0),cin.tie(NULL);
	ll a,b;
	cin>>a>>b;
	cout<<a*b;

	return 0;
}

Measured memory_bytes: 3600
import java.util.*;

public class Main {


    public static void main(String[] args){

        Scanner sc = new Scanner(System.in);

        int n = sc.nextInt();
        int m = sc.nextInt();

        List[] e = new List[n];
        for(int i=0; i<n; i++) {
            e[i] =  new ArrayList<Integer>();
        }
        for(int i=0; i<m; i++) {
            int u = sc.nextInt() -1;
            int v = sc.nextInt() -1;
            e[u].add(v);
        }
        int s = sc.nextInt() -1;
        int t = sc.nextInt() -1;

        boolean[] v = new boolean[n * 3];
        int[] d = new int[n * 3];
        Arrays.fill(d, Integer.MAX_VALUE);

        Queue<Integer> q = new LinkedList<>();
        q.add(s * 3);
        d[s * 3] = 0;
        v[s*3] = true;
        while(!q.isEmpty()) {
            int a = q.poll();
            int node = a / 3;
            int rem = a % 3;
            int nr = (rem + 1) % 3;
            for(int next : (List<Integer>)e[node]) {
                int na = next * 3 + nr;
                if(v[na]) continue;
                v[na] = true;
                d[na] = Math.min(d[na], d[a] + 1);
                q.add(na);
                if(na == t * 3) {
                    System.out.println(d[na] / 3);
                    return;
                }
            }
        }
        System.out.println(-1);
    }

}


Measured memory_bytes: 103292
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    long a = sc.nextLong();
    long b = sc.nextLong();
    long ans = func(b);
    if(a > 0) ans = func(b) ^ func(a - 1);
    System.out.println(ans);
  }

  public static long func(long x) {
    if(x == 0) return 0;
    if(x == 1) return 1;
    long t = x;
    long p = 0;
    for(int i = 0; i < 100; i++) {
      t /= 2;
      if(t == 0) {
        p = i;
        break;
      }
    }
    long x1 = x - (long)Math.pow(2, p);
    long x2 = func(x1);
    if((x1 % 2) == 0) x2 += (long)Math.pow(2, p);
    if(p == 1) x2 = (x2 ^ 1);
    return x2;
  }
}

Measured memory_bytes: 25172
#include <iostream>
#include <algorithm>

using namespace std;

//??´?§?????§???¢????????¢??°Right_Triangle
bool Right_Triangle(int data[]){
    //????????§?????????????????????
    sort(data, data+3, greater<int>());
    if(data[0]*data[0] == data[1]*data[1] + data[2]*data[2]){
        return true;
    }
    else return false;
}

int main (){
    int i = 0;
    //????????????????????°n
    int n = 0;
    //????????????????????? data
    int data[3];

    cin >> n;

    //??´?§?????§???¢?????????????´??????? ans
    bool ans[n];

    //??\?????????Right_Triangle??????????????????????????£??¨???
    for(i = 0; i < n; i++){
        cin >> data[0] >> data[1] >> data[2];
        if(Right_Triangle(data)) ans[i] = true;
        else ans[i] = false;

    }
    for(i = 0; i < n; i++){
        if(ans[i] == true) cout << "YES\n";
        else cout << "NO\n";
    }
    return 0;
}

Measured memory_bytes: 3004
package main
import (
  "bufio"
  "os"
  "strconv"
  "strings"
  "fmt"
)

func Factorial(N int) (F, Finv, Inv []int) {
  F = make([]int, N + 1)
  Finv = make([]int, N + 1)
  Inv = make([]int, N + 1)
  F[0] = 1
  F[1] = 1
  Finv[0] = 1
  Finv[1] = 1
  Inv[0] = 1
  Inv[1] = 1
  for i := 2; i < N + 1; i++ {
    F[i] = F[i - 1] * i % p
    Inv[i] = p - Inv[p % i] * (p / i) % p
    Finv[i] = Finv[i - 1] * Inv[i] % p
  }
  return
}

func Comb(F, Finv *[]int, A ...int) int {
  S := SumInt(A...)
  C := (*F)[S]
  for _, a := range A {
    C *= (*Finv)[a]
    C %= p
  }
  return C
}

const p = 1000000007

func Solve() {
  var N, M int
  NextInt(&N, &M)
  F, Finv, Inv := Factorial(M)
  P := make([]int, M + 1)
  P[0]++
  for i := range P[1:] {
    P[i + 1] = P[i] * (M - i) % p
  }
  Q := make([]int, M + 1)
  Q[0] = P[N]
  for i := 0; i < N; i++ {
    Q[i + 1] = Q[i] * Inv[M - i] %p
  }
  ans := 0
  for k := 0; k <= N; k++ {
    C := Comb(&F, &Finv, N - k, k)
    ans = ans + (1 - 2 * (k % 2)) * ((C * P[k] % p) * (Q[k] * Q[k] % p) % p) + p
    ans %= p
  }
  Write(ans)
}

func main() {
  Solve()
  Output()
}

var reader = bufio.NewReaderSize(os.Stdin, 1000000)
var writer = bufio.NewWriter(os.Stdout)
func NextLine() string {
  buffer := make([]byte, 0)
  for true {
    line, isPrefix, err := reader.ReadLine()
    if err != nil { panic(err) }
    buffer = append(buffer, line...)
    if !isPrefix { break }
  }
  return string(buffer)
}
func NextInt(A ...*int) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.Atoi(L[i])
  }
}
func NextIntSlice(A *[]int) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]int, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.Atoi(l)
  }
}
func NextFloat(A ...*float64) {
  L := strings.Split(NextLine(), " ")
  for i, a := range A {
    *a, _ = strconv.ParseFloat(L[i], 64)
  }
}
func NextFloatSlice(A *[]float64) {
  L := strings.Split(NextLine(), " ")
  (*A) = make([]float64, len(L))
  for i, l := range L {
    (*A)[i], _ = strconv.ParseFloat(l, 64)
  }
}
func Write(S ...interface{}) {
  fmt.Fprintln(writer, S...)
}
func WriteIntSlice(A []int) {
  B := make([]interface{}, len(A))
  for i, a := range A { B[i] = a }
  Write(B...)
}
func Output() {
  _ = writer.Flush()
}
func MaxInt(A ...int) int {
  max := A[0]
  for _, a := range A {
    if max < a { max = a }
  }
  return max
}
func MinInt(A ...int) int {
  min := A[0]
  for _, a := range A {
    if a < min { min = a }
  }
  return min
}
func SumInt(A ...int) int {
  sum := 0
  for _, a := range A {
    sum += a
  }
  return sum
}
func AbsInt(x int) int {
  if x < 0 { x = -x }
  return x
}

Measured memory_bytes: 22144
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <cctype>
#include <cstring>
#define fi first
#define se second
#define N 100005
 
using namespace std;
typedef long long ll;
 
template <class T> inline void read(T &x) {
	char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	if (flag) x = -x;
}
 
inline int input() {
	int x; char ch; bool flag = false;
	while (!isdigit(ch = getchar())) flag |= ch == '-';
	for (x = ch ^ 48; isdigit(ch = getchar()); x = x * 10 + (ch ^ 48));
	return flag ? -x : x;
}
 
const int mod = 1e9 + 7;
inline int add(int x, int y) { x += y; return x >= mod ? x - mod : x; }
inline void inc(int &x, int y) { x += y; x -= x >= mod ? mod : 0; }
 
inline int Power(int x, int y) {
	int res = 1;
	while (y) {
		if (y & 1) res = (ll) res * x % mod;
		x = (ll) x * x % mod, y >>= 1;
	} return res;
}
 
template <class T> void chkmax(T &x, T y) { x = x > y ? x : y; }
template <class T> void chkmin(T &x, T y) { x = x < y ? x : y; }
template <class T> T gcd(T x, T y) { return !y ? x : gcd(y, x % y); }
 
int q, A, B, C, D;
 
int main() {
	q = input();
	while (q--) {
		A = input(), B = input(), C = input(), D = input();
		int n = A + B, len = (max(A, B) - 1) / (min(A, B) + 1) + 1;
		int l = 0, r = n + 1, mid, ans = n + 1;
		while (l <= r) {
			mid = (l + r) >> 1;
			int a = A - mid + mid / (len + 1) ;
			int b = B - mid / (len + 1);
			if (b <= (ll) a * len) l = mid + 1;
			else r = mid - 1, ans = mid;
		}
		int a = A - ans / (len + 1) * len - ans % (len + 1);
		int b = B - ans / (len + 1), P = ans + b - a * len + 1;
		for (int i = C; i <= min(D, ans); ++i) putchar(i % (len + 1) ? 'A' : 'B');
		for (int i = max(C, ans + 1); i <= D; ++i) putchar(abs(P - i) % (len + 1) ? 'B' : 'A');
		putchar('\n');
	}
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
      	int n = sc.nextInt();
      	int[] a = new int[n];
      	for(int i=0;i<n;i++){
          a[i] = sc.nextInt();
        }
      	int ans = 0;
      	Arrays.sort(a);
        for(int i=0;i<a.length;i++){
          for(int j=i+1;j<a.length;j++){
            for(int k=j+1;k<a.length;k++){
              if( (a[i]!=a[j])&&(a[j]!=a[k])&&(a[i]!=a[k])&&(a[i]+a[j]>a[k])&&(a[i]+a[k]>a[j])&&(a[j]+a[k]>a[i])){
                ans++;
                //System.out.println(i+":"+j+":"+k);
              }
            }
          }
        }
      /*
      	int count = 1;
      	for(int i=1;i<n;i++){
          if(a[i]!=a[i-1]){
            count++;
          }
        }
      	int[] num = new int[count];
      	num[0] = a[0];
      	count = 1;
      	for(int i=1;i<n;i++){
          if(a[i]!=a[i-1]){
            num[count] = a[i];
            //System.out.println(num[count-1]);
            count++;
            
          }
        }
      	for(int i=0;i<num.length;i++){
          for(int j=i+1;j<num.length;j++){
            for(int k=j+1;k<num.length;k++){
              if( (i!=j)&&(j!=k)&&(i!=k)&&(num[i]+num[j]>num[k])&&(num[i]+num[k]>num[j])&&(num[j]+num[k]>num[i])){
                ans++;
              }
            }
          }
        }
        */
      System.out.println(ans);
	}
}

Measured memory_bytes: 27812
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val a = sc.next()
    val b = sc.next()
    val c = sc.next()
    println(problem060a(a, b, c))
}

fun problem060a(a: String, b: String, c: String): String {
    return if (a.takeLast(1) == b.take(1) &&
        b.takeLast(1) == c.take(1)
    ) "YES" else "NO"
}

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

int main(){
	int n, k, ans = 0,count = 0;
	string s;
	cin >> n >> k;//nはsの大きさ
	cin >> s;
	for (int i = 0; i < n - 1; i++){
		if(s[i] == s[i + 1]) ans++;
		else count++;
	}
	if(count % 2 == 0) ans += min(count / 2, k) * 2;
	else {
		if(count / 2 + 1 <= k) ans += (count / 2) * 2 + 1;
		else ans += k * 2;
	}
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
 
#define ff              first
#define ss              second
#define ll              long long
#define dd              double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define vll             vector<long long>
#define vdd             vector<double>
#define vpii            vector<pair<int,int>>
#define vpll            vector<pair<long long,long long>>
#define vvi             vector<vector<int>>
#define vvl             vector<vector<long long>>
#define mii             map<int,int>
#define mll             map<long long,long long>
#define umii            unordered_map<int,int>
#define umll            unordered_map<long long,long long>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define rep(i,n)        for(int i=0;i<n;i++)
#define rep2(i,a,b)     for(int i=a;i<b;i++)
#define rev(i,n)        for(int i=n;i>=0;i--)
#define rev2(i,a,b)     for(int i=a;i>=b;i--)
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define inf             9e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define fio             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl            '\n'
#define all(x)          x.begin(),x.end()
#define d0(x)           cout <<x<<" "
#define d1(x)           cout <<x<<endl
#define d2(x,y)         cout <<x<<" "<<y<<endl
#define d3(x,y,z)       cout <<x<<" "<<y<<" "<<z<<endl
#define d4(x,y,z,w)     cout <<x<<" "<<y<<" "<<z<<" "<<w<<endl
#define read2(x,y)      cin>>x>>y
#define read3(x,y,z)    cin>>x>>y>>z
#define read4(x,y,z,w)  cin>>x>>y>>z>>w
#define read5(x,y,z,w,a)cin>>x>>y>>z>>w>>a
#define sz(a)           (int)a.size()
const ll mod=1e9+7;
const double PI = 3.14159265359;
const ll MOD=998244353;
void i_o()
{
   #ifndef ONLINE_JUDGE
   freopen("input.txt", "r", stdin);
   freopen("output.txt", "w", stdout);
   #endif
}
int n,m;
vvi adj;
vi dp;
vector<bool> vis;
void dfs(int v){
   vis[v]=true;
   for(int i:adj[v]){
      if(!vis[i]) dfs(i);
      dp[v]=max(dp[v],dp[i]+1);
   }
}
int main() {
   fio
  // i_o();
   cin>>n>>m;
   adj=vvi(n);
   rep(i,m){
      int x,y;
      cin>>x>>y;
      --x,--y;
      adj[x].pb(y);
   }
   dp=vi(n,0);
   vis=vector<bool>(n,false);
   rep(i,n) if(!vis[i]) dfs(i);
   d1(*max_element(all(dp)));
   return 0;
}



Measured memory_bytes: 8320
#include <stdio.h>
#include <iostream>

using namespace std;

int main() {
	int n;
	int pm,pe,pj;
	double ave,meave;
	while (1) {
		cin >> n;
		if (n == 0) {
			break;
		} else {
			for (int i = 0; i < n; i++) {
				cin >> pm >> pe >> pj;
				ave = ((double)pm + (double)pe + (double)pj) / 3.0;
				meave = ((double)pm + (double)pe) / 2.0;
				if (pm == 100 || pe == 100 || pj == 100) {
					cout << "A" << endl;
				} else if (meave >= 90.0) {
					cout << "A" << endl;
				} else if (ave >= 80.0) {
					cout << "A" << endl;
				} else if (ave >= 70.0) {
					cout << "B" << endl;
				} else if (ave >= 50.0 && (pm >= 80.0 || pe >= 80.0)) {
					cout << "B" << endl;
				} else {
					cout << "C" << endl;
				}
			}
		}
	}
	return 0;
}

Measured memory_bytes: 1156
#include<bits/stdc++.h>
using namespace std;
#define forr(i,a,n)	for(long long int i=a; i<n; i++)
#define loop(i,a,n)	for(long long int i=a; i>=n; i--)

int main() 
{
	ios_base :: sync_with_stdio(false),cin.tie(NULL),cout.tie(0);
	
	long long int a,ct=0;
	cin>>a;
	while(1)
	{
		ct+=1000;
		if(ct>=a)
			break;
	}
	cout<<ct-a;
	
	return 0; 	
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
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 INF = 1LL << 60;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  int n;
  cin>>n;
  set<int> s;
  map<int,int> m;
  vector<int> l;
  rep(i,n){
    int j;
    cin>>j;
    l.pb(j);
    s.insert(j);
    m[j]++;
  }
  auto itr=s.begin();
  int co=0;
  for(int i=0;i<m.size();i++){
    int num=*itr;
    if(num>m[num]){
      co+=m[num];
    }
    else if(num<m[num]){
      co+=abs(num-m[num]);
    }
    itr++;
  }
  cout<<co;
}

Measured memory_bytes: 9592
#include<bits/stdc++.h>
using namespace std;
vector<int>adj[100005];
int main(){
 
  int n,m;
  cin>>n>>m;
  for(int i=0;i<m;i++)
  {
	  int a,b;
	  cin>>a>>b;
	  adj[a].push_back(b);
	  adj[b].push_back(a);
  }
 int visited[n+1];
 memset(visited,-1,sizeof(visited));
 visited[1]=0;
 queue<int>q;
 q.push(1);
 while(!q.empty())
 {
	 int p = q.front();
	 q.pop();
	 for(int i=0;i<adj[p].size();i++)
	 {    
		 int ind = adj[p][i];
		 if(visited[ind]==-1)
		 {
			 visited[ind]=p;
			 q.push(ind);
		 }
	 }
 }
 int flg =0;
 for(int i=2;i<=n;i++)
 {
	 if(visited[i]==-1)
	 {
		 flg=1;
		 break;
	 }
 }
if(flg==1)
{
	cout<<"No";
} 
else
{
	cout<<"Yes"<<endl;
	for(int i=2;i<=n;i++)
	cout<<visited[i]<<endl;
}

}


Measured memory_bytes: 10332
import java.io.PrintStream;
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = null;
		PrintStream out = null;
		try {
			sc = new Scanner(System.in);
			out = System.out;
			exec(sc, out);
		} catch (Exception e) {
			e.printStackTrace();
			System.exit(1);
		} finally {
			if(out != null) {
				out.close();
			}
			if(sc != null) {
				sc.close();
			}
		}
		System.exit(0);
	}
	public static void exec(final Scanner sc, final PrintStream out) throws Exception{
		final int N = sc.nextInt();
		final int v[] = new int[N];
		for(int i=0;i<N;i++) {
			v[i] = sc.nextInt();
		}
		Arrays.sort(v);
		double sum = v[0];
		for(int i=1;i<N;i++) {
			sum = (sum + v[i])/2;
		}
		out.println(sum);
	}
}


Measured memory_bytes: 25300
import sys
read = sys.stdin.read
readlines = sys.stdin.readlines
#import numpy as np
from math import sqrt, floor
def main():
    def factorization(n):
        l = []
        t = n
        for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
            if t % i == 0:
                cnt = 0
                while t % i == 0:
                    cnt += 1
                    t = t // i
                l.append([i, cnt])
        if t != 1:
            l.append([t, 1])
        if not l:
            l.append([n, 1])
        return l
    n = int(input())
    if n == 1:
        print(0)
        sys.exit()
    p = factorization(n)
    r = 0
    for pe in p:
        pe1 = pe[1]
        cnt = 1
        while pe1 >= cnt:
            pe1 -= cnt
            cnt = cnt + 1
            r += 1
    print(r)

if __name__ == '__main__':
    main()


Measured memory_bytes: 9476
#include <iostream>
#define REP(i, a, n) for(int i = (a); i < (n); i++)
using namespace std;
typedef long long ll;

int N, K;

bool ok(ll n) {
  for(int i = 0; i < N; i++) {
    if(n >= 0 && i == N -1) return true;
    n -= n / K + 1;
  }
  return false;
}

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

  ll low = -1, high = 1ll << 60;
  while(high - low > 1) {
    ll mid = (low + high) / 2;
    if(ok(mid)) high = mid;
    else low = mid;
  }

  cout << high << endl;

  return 0;
}

Measured memory_bytes: 3072
#include <cmath>
#include <vector>
#include <list>
#include <map>
#include <set>
#include <functional>
#include <queue>
#include <iostream>
#include <string.h>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <cstdint>
#include <climits>
#include <unordered_set>
#include <sstream>
#include <stack>

using namespace std;

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

using namespace std;

int n,k;
vector<ll> xs;
vector<ll> ys;
vector<pii> xy;

int main() {
    cin >> n >> k;
    xs.resize(n);
    ys.resize(n);
    xy.resize(n);
    for(int i = 0;i < n;i++)
    {
        cin >> xy[i].first >> xy[i].second;
        xs[i] = xy[i].first;
        ys[i] = xy[i].second;
    }
    sort(xs.begin(), xs.end());
    sort(ys.begin(), ys.end());
    
    ll mm = 1LL << 62;
    
    for(int x1 = 0;x1 < n;x1++)
    {
        for(int x2 = x1 + 1;x2 < n;x2++)
        {
            for(int y1 = 0;y1 < n;y1++)
            {
                for(int y2 = y1 + 1;y2 < n;y2++)
                {
                    int c = 0;
                    for(int i = 0;i < n;i++)
                    {
                        auto x = xy[i].first;
                        auto y = xy[i].second;
                        if(x >= xs[x1] && x <= xs[x2] && y >= ys[y1] && y <= ys[y2])
                        {
                            c++;
                        }
                    }
                    if(c >= k)
                    {
                        mm = min(mm, (ll)(ys[y2]-ys[y1]) * (xs[x2]-xs[x1]));
                    }
                }
            }
        }
    }
    cout << mm << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include <iomanip>
#include <ios>
#include <vector>
#include <string>
#include <algorithm>
#include <string>
#include<limits>
#include<cstdlib>
#include<functional>
#include<cassert>
#include <cstdio>
#include <stack>
#include <queue>
#include <map>
#define fi(p) for(int i=0;i<(p);i++)
#define ce(d) cout<<d<<endl;
#define ll long long
#define sorts(c) sort((c).begin(),(c).end());

using namespace std;

void solve() {
	int n;
	string a, b;
	cin >> n ;
	cin >> a >> b;

	string res;

	fi(n) 
	{
		res += a[i];
		res += b[i];
	}


	ce(res)
}

int main()
{
	solve();

	int a;//止める用
	cin >> a;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);++i)
#define rrep(i,n) for(int i=1;i<(n);++i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define maxs(a, b) a = max(a, b)
#define mins(a, b) a = min(a, b)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const ll linf = (1ll << 61);
const int inf = 1001001001;
const int mod = 1000000007;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	ll n, a, b;
	cin >> n >> a >> b;
	ll res1 = b * (n - 1) + a;
	ll res2 = a * (n - 1) + b;
	cout << max(0LL, res1 - res2 + 1) << endl;
	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<unordered_set>
#include<unordered_map>
#include <algorithm> 
#include <iostream>
#include <string>
#include <cmath>
using namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define all(v)(v).begin(),(v).end()
#define rall(v)(v).rbegin(),(v).rend()
#define F first
#define S second
#define pb push_back
#define pu push
#define COUT(x) cout<<(x)<<endl
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,vector<ll>,greater<ll>>
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define mp make_pair
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define sz(x) (ll)(x).size()
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1000000007LL;
const ll INF = 1LL << 60;
using vll = vector<ll>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pll = pair<ll, ll>;
using vc = vector<char>;
using vvc = vector<vc>;
ll dx[4]={0,1,0,-1};
ll dy[4]={1,0,-1,0};
int main(){
  ll n,m;
  cin>>n>>m;
  vll t(n);
  rep(i,m){
    ll a,b;
    cin>>a>>b;
    a--;
    b--;
    t[a]++;
    t[b]++;
  }
  rep(i,n){
    if(t[i]%2==1){
      COUT("NO");
      return 0;
    }
  }
  COUT("YES");
}


Measured memory_bytes: 1024
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
long long int a[200500]={0};
long long int l[200500]={0};
long long int r[200500]={0};
int main()
{
    register int n;
    scanf("%d",&n);
    for(register int i=1;i<=n;i++)
        scanf("%d",&a[i]);
    for(register int i=1;i<=n;i++)
    {
        for(l[i]=i;l[i]>1;)
        {
            if(a[l[i]-1]>a[i])
                l[i]=l[l[i]-1];
            else
                break;
        }
    }
    for(int i=n;i>=1;i--)
    {
        for(r[i]=i;r[i]<=n;)
        {
            if(a[r[i]+1]>a[i])
            {
                r[i]=r[r[i]+1];
            }
            else
                break;
        }
    }
    register long long int sum=0;
    for(register int i=1;i<=n;i++)
    {
        sum+=a[i]*(i-l[i]+1)*(r[i]-i+1);
    }
    printf("%lld",sum);
    return 0;
}


Measured memory_bytes: 4992
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 h = sc.nextInt();
		
		System.out.println((a + b )* h / 2);
	}

}


Measured memory_bytes: 22736
minus :: [Int] -> [Int] -> [Int]
minus (x : xs) (y : ys) = case (compare x y) of
  LT -> x : minus xs (y : ys)
  EQ -> minus xs ys
  GT -> minus (x : xs) ys
minus xs _ = xs

primesToQ :: Int -> [Int]
primesToQ m = eratos [2 .. m]
 where
  eratos []       = []
  eratos (p : xs) = p : eratos (xs `minus` [p * p, p * p + p .. m])

lowerBound'' :: (Ord a) => a -> Int -> Int -> [a] -> Int
lowerBound'' num left right array
  | right == left + 1 = right
  | midValue < num    = lowerBound'' num mid right array
  | otherwise         = lowerBound'' num left mid array
 where
  mid      = (left + right) `div` 2
  midValue = array !! mid

lowerBound :: (Ord a) => a -> [a] -> Int
lowerBound num array | num <= head array = 0
                     | last array < num = length array
                     | otherwise = lowerBound'' num 0 (length array - 1) array

lowerBoundValue :: (Ord a) => a -> [a] -> Maybe a
lowerBoundValue num array | i == length array = Nothing
                          | otherwise         = Just (array !! i)
  where i = lowerBound num array

main :: IO ()
main = do
  [x] <- map read . words <$> getLine
  let Just ans = lowerBoundValue x (primesToQ $ 2 * x)
  putStrLn $ show ans

Measured memory_bytes: 2684
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define all(x) (x).begin(),(x).end()
#define INF 10000000
using ll = long long ;

using namespace std;

int main(){
    ll a,b,x;
    cin >> a >> b >> x;
    if (a==0) cout << b/x+1 << endl;
    else cout << b/x-(a-1)/x << endl;
}

Measured memory_bytes: 256
# editrialを参考にした
N, K = map(int, input().split())
ans = 0
for b in range(1, N + 1):
    div, mod = divmod(N, b)
    ans += div * max(0, b - K)
    ans += max(mod - K + 1, 0)
if K == 0:
    ans -= N
print(ans)


Measured memory_bytes: 2940
import java.io.BufferedReader
import java.io.InputStreamReader
import java.io.PrintWriter

val br = BufferedReader(InputStreamReader(System.`in`))
val out = PrintWriter(System.out)

fun main() {
    br.use { out.use {
        solve()
        out.flush()
    } }
}

fun solve() {
    /** O(n) */
    fun <T>elementCountMap(list: List<T>): Map<T, Long> {
        val countMap = mutableMapOf<T, Long>()
        for (e in list) {
            countMap[e] = (countMap[e] ?: 0) + 1
        }
        return countMap
    }

    val n = readInteger()
    val ss = List(n) { br.readLine()!!.toCharArray().sorted().toString() }
    val countMap = elementCountMap(ss)
    var ans = countMap.values.fold(0L) { acc, v -> acc + (v * (v - 1) / 2) }
    out.println(ans)
}

fun readInteger() = Integer.parseInt(br.readLine())
fun readLong() = java.lang.Long.parseLong(br.readLine())
fun readStringList() = br.readLine()!!.split(' ')
fun readIntegerList() = readStringList().map(Integer::parseInt)
fun readLongList() = readStringList().map(java.lang.Long::parseLong)
fun readDoubleList() = readStringList().map(java.lang.Double::parseDouble)


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

using namespace std;

typedef long long ll;



ifstream fin ("calafat.in");
ofstream fout ("calafat.out");

int n, x, v[102];

int main()
{
  cin >> n;
  for (int i = 1; i <= n; i++)
    cin >> v[i];
  int ans = 1e9;
  for (int i = 1; i <= 100; i++) {
    int sum = 0;
    for (int j = 1; j <= n; j++)
      sum += (v[j] - i) * (v[j] - i);
    ans = min(sum , ans);
  }
  cout << ans;
  return 0;
}


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

int main()
{
  int X;scanf("%d",&X);vector<int> prime(0);
  bool pri[X+1];fill(pri,pri+X+1,false);pri[1]=true;
  for(int i=2;i<X+1;i++)
  {
    int x=i;
    if(pri[i])continue;
    bool check=false;
    while(x*i<=X){pri[x*i]=true;x*=i;check=true;}
    if(!check)pri[i]=false;
  }
  for(int i=X;i>0;i--)if(pri[i]){printf("%d",i);return 0;}
}

Measured memory_bytes: 3752
/*input
10 10 10 10

*/ 
#include <iostream>
#include <bits/stdc++.h>
#include <math.h> 
    
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define gc getchar_unlocked
#define fo(i,n) for(ll i=0;i<n;i++)
#define Fo(i,k,n) for(ll i=k;k<n?i<n:i>n;k<n?i+=1:i-=1)
#define int long long
#define si(x)   scanf("%d",&x)
#define sl(x)   scanf("%lld",&x)
#define ss(s)   scanf("%s",s)
#define pi(x)   printf("%d\n",x)
#define pl(x)   printf("%lld\n",x)
#define ps(s)   printf("%s\n",s)
#define deb(x) cout << #x << "=" << x << endl
#define deb2(x, y) cout << #x << "=" << x << "," << #y << "=" << y << endl
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define clr(x) memset(x, 0, sizeof(x))
#define sortall(x) sort(all(x))
#define tr(it, a) for(auto it = a.begin(); it != a.end(); it++)
#define PI 3.1415926535897932384626
#define ms(a,x) memset(a, x, sizeof(a));
#define endl "\n"
typedef pair<int, int>  pii;
typedef vector<int>     vi;
typedef vector<pii>     vpii;
typedef vector<vi>      vvi;
int mpow(int base, int exp); 
void ipgraph(int m);
void dfs(int u, int par);
const int mod = 1000000007;
const int N = 1000000001;
const int MAX = 1e5+1;
    



int32_t main() {
    IOS;
	int a,b,c,d;
	cin>>a>>b>>c>>d;
	int first = c/b;
	int r1 = c%b;
	int second  = a/d;
	int r2 = a%d;
	if(r1!=0){
		first++;
	}
	if(r2!=0){
		second++;
	}
	if(first<=second)
	cout<<"Yes"<<endl;
	else
	cout<<"No"<<endl;

    return 0;
}       



Measured memory_bytes: 3640
#include <iostream>
#include<string>
#include<cctype>
#include<algorithm>
using namespace std;

int main() {
 
	int num=1, n, k;
	cin >> n >> k;
	for (int x = 0; x < n; x++) {
		if (num < k)num = num * 2;
		else num = num + k;
	}
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#define REP(i, m, n) for(int i=int(m);i<int(n);i++)
#define EACH(i, c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

//#define LOCAL 1
#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR
#endif


//改造
typedef long long int ll;
using namespace std;


//ここから編集する

bool jud(vector<int> v,int num){
    while(num > 0){
        for(int i = 0; i < v.size(); i++){
            if(num % 10 == v[i]){
                return false;
            }
        }
        num /= 10;
    }
    return true;
}

int main() {
    vector<int> v;
    int n;
    int k;
    cin >> n >> k;

    for(int i = 0; i < k; i++){
        int tmp;
        cin >> tmp;
        v.push_back(tmp);
    }

    int num = n;
    while(!jud(v,num)){
        num++;
    }


    cout << num << endl;



    return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split(' '))


def main(n, m):
    cnt = 0

    if m <= 1:
        cnt += n * (n - 1) / 2
    else:
        cnt += n * (n - 1) / 2
        cnt += m * (m - 1) / 2

    return int(cnt)


print(main(N, M))


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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

template<class T1, class T2> void chmin(T1 &a, T2 b){if(a>b)a=b;}
template<class T1, class T2> void chmax(T1 &a, T2 b){if(a<b)a=b;}

using Pi = pair<int, int>;
using Tapris = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
//const int mod = 1e9 + 7;

struct Combinatorics {
  using int64 = long long;
  int64 mod;
  int64 fact[202020];
  int64 invfact[202020];
  Combinatorics(int64 mod):mod(mod) {
    fact[0] = invfact[0] = 1;
    for(int i = 1; i < 202020; ++i) {
      fact[i] = fact[i-1]*i%mod;
      invfact[i] = minv(fact[i]);
    }
  }
  int64 mpow(int64 x, int64 n) const {
    int64 res = 1;
    while(n > 0) {
      if(n&1) res = res*x%mod;
      x = x*x%mod;
      n >>= 1;
    }
    return res;
  }
  int64 minv(int64 x) const {
    return mpow(x, mod-2);
  }
  int64 mfact(int64 x) const {
    return fact[x];
  }
  int64 C(int64 n, int64 r) const {
    if(r < 0 || n < r) return 0;
    return fact[n]*invfact[r]%mod*invfact[n-r]%mod;
  }
  int64 P(int64 n, int64 r) const {
    if(r < 0 || n < r) return 0;
    return fact[n]*invfact[n-r]%mod;
  }
};

int N, M;

int dp[3003][3003];
int dfs(int x, int y) {
  if(x < 0 || y < 0) return 0;
  int& res = dp[x][y];
  if(~res) return res;
  if(x == 0 && y == 0) return res = 1;
  if(x < y) return res = 0;
  return res = (dfs(x-1, y-1)+(y+1)*dfs(x-1, y)%M) % M;
}

int way[3003];

int C[3003][3003];

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  cin >> N >> M;

  rep(i, 3003) {
    C[i][0] = C[i][i] = 1;
    reps(j, 1, i) C[i][j] = (C[i-1][j-1]+C[i-1][j]) % M;
  }

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

  Combinatorics c1(M);
  Combinatorics c2(M-1);
  memset(way, -1, sizeof(way));
  rep(x, N+1) {
    way[x] = 0;
    int b = c1.mpow(2, N-x);
    int p = 1;
    rep(y, N+1) {
      way[x] += dfs(x, y)*p % M;
      way[x] %= M;
      p = p*b % M;
    }
    way[x] *= c1.mpow(2, c2.mpow(2, N-x));
    way[x] %= M;
  }
  int ans = 0;
  rep(i, N+1) {
    if(i&1) ans += M-C[N][i]*way[i]%M;
    else ans += C[N][i]*way[i]%M;
    ans %= M;
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 145920
#include <bits/stdc++.h>
#define ll long long 

using namespace std;

int main()
{
    int n,k;
    cin >> n >> k;
    int a[n];
    for(int i=0;i<n;i++)
    {
        cin >> a[i];
    }
    sort(a,a+n);
    int sum =0;
    for(int i=0;i<k;i++)
    {
        sum += a[i];
    }
    cout << sum ;
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
#define int long long 
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define all(a) a.begin(),a.end()
#define ld long double
#define ub upper_bound
#define lb lower_bound
#define pii pair<int,int>
using namespace std;
signed main()
{
    fast;
    int n;
    cin>>n;
    int a[n+1];
    int mn = 1e18;
    for(int i=1;i<=n;i++)
        cin>>a[i];
    int ans = 0;
    for(int i=1;i<=n;i++)
    {
        mn = min(mn,a[i]);
        if(a[i] == mn)
            ans++;
    }
    cout<<ans;
}   

Measured memory_bytes: 1792
import java.util.Scanner

class UnionFind(n: Int) {
  private val pare = Array.ofDim[Int](n)
  private val rk = Array.ofDim[Int](n)

  (0 until n).foreach(i => {
    pare(i) = i
    rk(i) = i
  })

  def find(x: Int): Int = {
    if (x == pare(x)) x
    else {
      pare(x) = find(pare(x))
      pare(x)
    }
  }

  def unite(x: Int, y: Int): Unit = {
    val xx: Int = find(x)
    val yy: Int = find(y)
    if (xx != yy) {
      if (rk(xx) < rk(yy)) pare(xx) = yy
      else pare(yy) = xx
      if (rk(xx) == rk(yy)) rk(xx) += 1
    }
  }

  def same(x: Int, y: Int): Boolean = {
    find(x) == find(y)
  }
}

object Main {
  def main(args: Array[String]): Unit = {
    val sc = new Scanner(System.in)

    val N, M = sc.nextInt
    val p = Array.ofDim[Int](N+1)
    (1 to N).foreach(i => {
      p(i) = sc.nextInt
    })

    val uf = new UnionFind(N+1)
    (1 to M).foreach(_ => {
      val x, y = sc.nextInt
      uf.unite(x, y)
    })

    var ans = 0
    (1 to N).foreach(i => {
      if (uf.same(p(i), i)) ans += 1
    })

    println(ans)
  }
}

Measured memory_bytes: 109544
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! debug {($($a:expr),*) => {println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);}}
#[allow(unused_macros)]
macro_rules! input {(source=$s:expr,$($r:tt)*) => {let mut iter=$s.split_whitespace(); let mut next=||{iter.next().unwrap()}; input_inner! {next,$($r)*}};($($r:tt)*) => {let stdin=std::io::stdin();let mut bytes=std::io::Read::bytes(std::io::BufReader::new(stdin.lock())); let mut next=move||->String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()}; input_inner! {next,$($r)*}};}
#[allow(unused_macros)]
macro_rules! input_inner {($next:expr) => {}; ($next:expr,) => {}; ($next:expr,$var:ident:$t:tt$($r:tt)*) => {let $var=read_value!($next,$t); input_inner! {$next$($r)*}};}
#[allow(unused_macros)]
macro_rules! read_value {($next:expr,($($t:tt),*)) => {($(read_value! ($next,$t)),*)}; ($next:expr, [$t:tt; $len:expr]) => {(0..$len).map(|_|read_value! ($next,$t)).collect::<Vec<_>>()}; ($next:expr,chars) => {read_value! ($next,String).chars().collect::<Vec<char>>()}; ($next:expr,usize1) => {read_value! ($next,usize)-1}; ($next:expr,$t:ty) => {$next().parse::<$t>().expect("Parse error")};}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);
impl<T: PartialEq> Eq for Total<T> {}
impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

#[allow(dead_code)]
const MAX: usize = 100006;
#[allow(dead_code)]
const INF_U32: u32 = 1 << 31;
#[allow(dead_code)]
const INF_I32: i32 = 1 << 30;
#[allow(dead_code)]
const INF_U64: u64 = 1 << 63;
#[allow(dead_code)]
const INF_I64: i64 = 1 << 62;
#[allow(dead_code)]
const MOD: i64 = 1e9 as i64 + 7;

#[allow(dead_code)]
fn read<T: FromStr>() -> 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().expect("failed to parse token")
}

#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}

#[allow(unused_imports)]
use std::f64;


fn main() {
    input!{s:chars};
    let mut v = vec![0i64,0i64,0i64];
    for ch in s {
        match ch {
            'a' => v[0]+=1,
            'b' => v[1]+=1,
            'c' => v[2]+=1,
            _ => v[0]+=1,
        };
    }

    println!("{}", if (v[0]-v[1]).abs() < 2 && (v[0]-v[2]).abs() < 2 && (v[1]-v[2]).abs() < 2 {"YES"} else {"NO"});

}


Measured memory_bytes: 4352
/*  -*- coding: utf-8 -*-
 *
 * a.cc: A - ∴ (Therefore)
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>
 
using namespace std;

/* constant */

/* typedef */

/* global variables */

/* subroutines */

/* main */

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

  int d = n % 10;
  if (d == 3) puts("bon");
  else if (d == 0 || d == 1 || d == 6 || d == 8) puts("pon");
  else puts("hon");
  
  return 0;
}


Measured memory_bytes: 3168