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

template<typename T,T MOD = 1000000007>
struct Mint{
  static constexpr T mod = MOD;
  T v;
  Mint():v(0){}
  Mint(signed v):v(v){}
  Mint(long long t){v=t%MOD;if(v<0) v+=MOD;}

  Mint pow(long long k){
    Mint res(1),tmp(v);
    while(k){
      if(k&1) res*=tmp;
      tmp*=tmp;
      k>>=1;
    }
    return res;
  }

  static Mint add_identity(){return Mint(0);}
  static Mint mul_identity(){return Mint(1);}

  Mint inv(){return pow(MOD-2);}

  Mint& operator+=(Mint a){v+=a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator-=(Mint a){v+=MOD-a.v;if(v>=MOD)v-=MOD;return *this;}
  Mint& operator*=(Mint a){v=1LL*v*a.v%MOD;return *this;}
  Mint& operator/=(Mint a){return (*this)*=a.inv();}

  Mint operator+(Mint a) const{return Mint(v)+=a;}
  Mint operator-(Mint a) const{return Mint(v)-=a;}
  Mint operator*(Mint a) const{return Mint(v)*=a;}
  Mint operator/(Mint a) const{return Mint(v)/=a;}

  Mint operator-() const{return v?Mint(MOD-v):Mint(v);}

  bool operator==(const Mint a)const{return v==a.v;}
  bool operator!=(const Mint a)const{return v!=a.v;}
  bool operator <(const Mint a)const{return v <a.v;}

  static Mint comb(long long n,int k){
    Mint num(1),dom(1);
    for(int i=0;i<k;i++){
      num*=Mint(n-i);
      dom*=Mint(i+1);
    }
    return num/dom;
  }
};
template<typename T,T MOD> constexpr T Mint<T, MOD>::mod;
template<typename T,T MOD>
ostream& operator<<(ostream &os,Mint<T, MOD> m){os<<m.v;return os;}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int k;  
  string s;
  cin >> k >> s;
  int l = k+ s.size();
  vector<Mint<int>> fac(l+1);
  vector<Mint<int>> inv(l+1);
  fac[0] = inv[0] = 1;
  rep(i,l){
    Mint<int> ii =i;
    fac[i+1] = fac[i] * (ii+1);
    inv[i+1] = (Mint<int> (1))/fac[i+1];
    // cout << fac[i+1] << endl;
  }
  Mint<int> ans = (Mint<int> (26)).pow(l);
  Mint<int> coef = (Mint<int> (25)).pow(l);
  // cout << ans << endl;
  rep(i,s.size()){
    // cout << fac[l] <<" " << inv[i] <<" " << inv[l-i] << " " << fac[l]*inv[i]*inv[l-i] << " " << coef << endl;
    ans -= fac[l]*inv[i]*inv[l-i]*coef;
    coef /=25;
    // cout << ans << endl;
  }
  cout << ans << endl;
  
  return 0;
    

}


Measured memory_bytes: 20092
#include<bits/stdc++.h>
#define F first
#define S second
#define pb push_back
#define mp make_pair
#define full(a) a.begin(),a.end()
#define rfull(a) a.rbegin(),a.rend()

using namespace std;
const double pi=acos(-1.0);
const double pii=2*pi;
const double eps=1e-6;
const long long MOD=1e9+7;

int rec(int n,int m, int len, int curr,vector<int> seq, vector<vector<int>>& q){
    if(len==n){
        int ret=0;
        for(int i=0;i<q.size();i++){
            if(q[i][2]==seq[q[i][1]-1]-seq[q[i][0]-1]) ret+=q[i][3];
        }
        return ret;
    }
    if(len<n && curr>m) return 0;
    vector<int> a=seq;
    a.pb(curr);
    return max(rec(n,m,a.size(),curr,a,q),rec(n,m,seq.size(),curr+1,seq,q));
}

void solve(){
    int n,m,q;
    cin>>n>>m>>q;
    vector<vector<int>> qu(q,vector<int>(4,0));
    for(int i=0;i<qu.size();i++){
        for(int j=0;j<4;j++) cin>>qu[i][j];
    }
    int ans=rec(n,m,0,1,vector<int>{},qu);
    cout<<ans<<"\n";
}

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

    solve();
    return 0;
}

Measured memory_bytes: 3668
import java.util.*;

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

    int a = A+B;
    int b = A-B;
    int c = A*B;
    

    System.out.println(Math.max(c,Math.max(a,b)));
}
    }

Measured memory_bytes: 35968
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> a(N);
  for (int i = 0; i < N; i++){
    cin >> a[i];
    a[i]--;
  }
  int ans = 0;
  for (int i = 0; i < N; i++){
    if (a[a[i]] == i) ans++;
  }
  cout << ans / 2;
}

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

ll n, m, k, ans, M=998244353;
ll fac[N]={1,1}, inv[N]={1,1}, fiv[N]={1,1};
ll C(ll p, ll q) {return fac[p] * fiv[q] % M * fiv[p-q] % M;}
ll pow(ll p, ll q) {return q ? pow(p*p%M, q/2) * (q&1 ? p : 1) % M : 1;}

int main() {
	ll i, t;
	cin >> n >> m >> k;
	for(i=2; i<=n; i++) fac[i] = fac[i-1] * i % M;
	for(i=2; i<=n; i++) inv[i] = inv[M%i] * (M-M/i) % M;
	for(i=2; i<=n; i++) fiv[i] = fiv[i-1] * inv[i] % M;
	for(i=0; i<=k; i++) {
		t = m * C(n-1, i) % M * pow(m-1, n-1-i) % M;
		(ans += t) %= M;
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 8328
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

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

#define NINJA ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define fo(i,n) for(int i=0;i<n;i++)
#define Fo(i,k,n) for(int i=k;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
#define dloop(i,n) for(int i=n-1;i>=0;i--)
#define iii tuple<int,int,int>
#define vi vector<int>
#define ii pair<int,int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int,int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

const int mxn = 1e5+10;
int a[mxn];

int32_t main(){
	NINJA;

	int n; cin >> n;
	int cnt = 1;
	int have = 0;
	int temp = 1000;
	while(have < n){
		have = temp*cnt++;
	}
	cout << have - n << endl;
	
	return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(void){
	int n,d[100],i,y=0;
	scanf("%d",&n);
	for(i=0;i<n;i++)scanf("%d",&d[i]);
	int min=d[0];
	for(i=0;i<n;i++)if(min>d[i])min=d[i];
	for(;min<=100;min++)
		for(i=0;i<n;i++)
			if(min==d[i]){y++;break;}
	printf("%d\n",y);
}

Measured memory_bytes: 128
import java.util.Scanner;
import java.util.Arrays;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        sc.close();

        for(char c='a'; c<='z'; c++) {
            if(!s.contains(Character.toString(c))) {
                System.out.println(c);
                System.exit(0);
            }
        }
        System.out.println("None");
    }
}


Measured memory_bytes: 26184
import java.util.Arrays;
import java.util.Collections;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();
		int m = sc.nextInt();
		Integer a[] = new Integer[n];

		int total = 0;
		for (int i=0; i< n; i++){
			a[i] = sc.nextInt();
			total += a[i];
		}
		double minVote = (double)total / (4 * m);
		Arrays.sort(a, Collections.reverseOrder());
		boolean result = true;
		for (int i=0; i<m; i++){
			if (a[i] < minVote){
				result = false;
				break;
			}
		}
		if (result) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 23764
#include <stdio.h>
 
int main(void)
{
  int N;
  scanf("%d", &N);
  switch (N%10) {
	case 2:
    case 4:
    case 5:
    case 7:
    case 9:
		printf("hon");
		break;
	case 0:
    case 1:
    case 6:
    case 8:
		printf("pon");
		break;
	default:
		printf("bon");
		break;
}
  
return 0;
}

Measured memory_bytes: 1732
import sys
from collections import defaultdict
from heapq import *
sys.setrecursionlimit(200000)
input = sys.stdin.readline

# N, M, = map(int, input().split())
# L = [int(v) for v in input().split()]
# L = [int(input()) for _ in range(Q)]
S = input().strip()

print(len([v for v in S if v == "o"]) * 100 + 700)

Measured memory_bytes: 3316
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.math.BigInteger;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 *
 * @author MaxHeap
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        FastReader in = new FastReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        MultipleClocks solver = new MultipleClocks();
        solver.solve(1, in, out);
        out.close();
    }

    static class MultipleClocks {
        public BigInteger lcm(BigInteger a, BigInteger b) {
            return a.multiply(b).divide(a.gcd(b));
        }

        public void solve(int testNumber, FastReader in, PrintWriter out) {
            int n = in.nextInt();
            BigInteger[] arr = new BigInteger[n];
            for (int i = 0; i < n; i++) {
                arr[i] = new BigInteger(in.next());
            }
            BigInteger lcm = arr[0];
            for (int i = 1; i < n; i++) {
                lcm = lcm(lcm, arr[i]);
            }
            out.println(lcm);
        }

    }

    static class FastReader {
        BufferedReader reader;
        StringTokenizer st;

        public FastReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            st = null;
        }

        public String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    String line = reader.readLine();
                    if (line == null) {
                        return null;
                    }
                    st = new StringTokenizer(line);
                } catch (Exception e) {
                    throw new RuntimeException();
                }
            }
            return st.nextToken();
        }

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

    }
}



Measured memory_bytes: 24660
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::usize;

#[allow(unused_macros)]
macro_rules! read_cols {
    ($($t:ty),+) => {{
        let mut line = String::new();
        stdin().read_line(&mut line).unwrap();

        let mut it = line.trim()
            .split_whitespace();

        ($(
            it.next().unwrap().parse::<$t>().ok().unwrap()
        ),+)
    }}
}

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_vec<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn nth_bit(k: u64, n: u64) -> u64 {
    (k >> n) & 1
}

fn next(k: u64, n: u64) -> u64 {
    (k & !((1u64 << n) - 1)) + (1u64 << n)
}

fn main() {
    let (a, b) = read_cols!(u64, u64);

    let ans = (0..40).map(|n| {
        let (s, k) = if nth_bit(a, n) == 1 {
            (next(next(a, n), n), min(next(a, n), b + 1) - a)
        } else {
            (next(a, n), 0)
        };
        if s > b {
            return k;
        }
        
        let rr = (b - s) / (1 << n);
        let r = (rr + 1) / 2 * (1 << n);
        
        let t = if nth_bit(b, n) == 1 {
            b + 1 - (s + rr * (1 << n))
        } else {
            0
        };

        k + r + t
    }).enumerate().map(|(i, k)| (k % 2) << i).sum::<u64>();
    
    println!("{}", ans);
}


Measured memory_bytes: 4352
// #define DEBUGGING
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define ALL(V) (V).begin(), (V).end()
#define ALLR(V) (V).rbegin(), (V).rend()

template <typename T> using V = vector<T>;
template <typename T> using VV = V<V<T>>;
using ll = int64_t;
using ull = uint64_t;
using PLL = pair<ll, ll>;

template <typename T> const T& var_min(const T &t) { return t; }
template <typename T> const T& var_max(const T &t) { return t; }
template <typename T, typename... Tail> const T& var_min(const T &t, const Tail&... tail) { return min(t, var_min(tail...)); }
template <typename T, typename... Tail> const T& var_max(const T &t, const Tail&... tail) { return max(t, var_max(tail...)); }
template <typename T, typename... Tail> void chmin(T &t, const Tail&... tail) { t = var_min(t, tail...); }
template <typename T, typename... Tail> void chmax(T &t, const Tail&... tail) { t = var_max(t, tail...); }
template <typename T> const T& clamp(const T &t, const T &low, const T &high) { return max(low, min(high, t)); }
template <typename T> void chclamp(T &t, const T &low, const T &high) { t = clamp(t, low, high); }

namespace init__ {

struct InitIO {
    InitIO() {
        cin.tie(nullptr);
        ios_base::sync_with_stdio(false);
        cout << fixed << setprecision(30);
    }
} init_io;

}

#ifdef DEBUGGING
// #include "../debug/debug.cpp"
#include "../../debug/debug.cpp"
#else
#define DEBUG(...) 0
#define DEBUG_SEPARATOR_LINE 0
#endif

template <typename T>
T make_v(T init) { return init; }

template <typename T, typename... Tail>
auto make_v(T init, size_t s, Tail... tail) {
#define rec make_v(init, tail...)
    return V<decltype(rec)>(s, rec);
#undef rec
}

ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

int main() {
    ll A, B;
    cin >> A >> B;
    ll G = gcd(A, B);
    ll GG = G;
    ll ans = 1;

    auto update_ans = [&](ll n) {
        ll cnt = 0;
        while(GG % n == 0) {
            cnt++;
            GG /= n;
        }
        if(cnt) ans++;
    };

    for(ll i = 2; i * i <= G; i++) {
        if(GG % i) continue;
        update_ans(i);
    }
    if(GG > 1) update_ans(GG);

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

func main() {
	var n, x, y int

	fmt.Scan(&n)
	fmt.Scan(&x)
	fmt.Scan(&y)

	a := make([]int, n, n)

	for i := 1; i <= n; i++ {
		for j := i + 1; j <= n; j++ {
			k := min(j-i, abs(x-i)+abs(y-j)+1)
			a[k]++
		}
	}

	for i := 1; i <= n-1; i++ {
		fmt.Println(a[i])
	}
}

func min(n1, n2 int) int {
	if n1 <= n2 {
		return n1
	}
	return n2
}

func abs(n1 int) int {
	if n1 < 0 {
		return -n1
	}
	return n1
}


Measured memory_bytes: 512
from sys import setrecursionlimit
setrecursionlimit(100000)

global visited,num,graph

def dfs(subtree):
    global visited,num,graph
    if visited[subtree] != 0:
        return

    visited[subtree] = num
    for node in graph[subtree]:
        if visited[node] != 0:
            continue
        dfs(node)

N,M = map(int,input().split())

starting = list(map(int,input().split()))
graph = [[] for x in range(N+1)]
for i in range(M):
    a,b = map(int,input().split())
    graph[a].append(b)
    graph[b].append(a)

visited = [0 for x in range(N+1)]
num = 1
for i in range(1,N+1):
    if visited[i] == 0:
        dfs(i)
        num += 1

ans = 0
for i in range(1,N+1):
    if visited[i] == visited[starting[i-1]]:
        ans += 1

print(ans)


Measured memory_bytes: 79460
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<list>
#include<string>
#include<algorithm>
 
using namespace std;
 
int main(){
  float n,m;
  cin >> n >> m;
  float sum=0;
  vector<int> vc(n);
  for(int i=0;i<n;i++){
    cin >> vc.at(i);
    sum += vc.at(i);
  }
  sort(vc.begin(),vc.end(),greater<int>());
 
  string ans;
  float num = sum / (4*m);
  if(vc[m-1] >= num){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  } 
}

Measured memory_bytes: 384
# 変換テーブルをbefore,afterと2つ使うのがポイント

s = input()
t = input()
 
before = [-1] * 26
after = [-1] * 26
 
for i, j in zip(s, t):
    si = ord(i) - ord('a')
    ti = ord(j) - ord('a')
 
    if before[si] != -1 or after[ti] != -1:
        if before[si] != ti or after[ti] != si:
            print("No")
            exit()
 
    before[si] = ti
    after[ti] = si
print("Yes")

Measured memory_bytes: 3632
// Aizu 1356: Decimal Sequences
// 2017.9.19 bal4u@uu

#include <stdio.h>
#include <string.h>

char f[1003];

int main()
{
	int n, i, d, a;

	scanf("%d", &n);
	memset(f, 0, sizeof(f)), a = 0, f[1000] = 1;
	while (n-- > 0) {
		scanf("%d", &d);
		f[d] = 1;
		a = 10*a + d; f[a%100] = 1, a %= 1000, f[a] = 1;
	}
	for (i = 0; f[i]; i++);
	printf("%d\n", i);
	return 0;
}

Measured memory_bytes: 1832
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

		String s = scanner.nextLine();
		String[] split = s.split("");
		Boolean isOK = false;
		String tmp = split[0];
		for(String ss: split){
			if(isOK) break;
			if(!tmp.equals(ss)){
				isOK = true;
			}
		}
		String result = isOK ? "Yes" : "No";
		System.out.println(result);
	}

}


Measured memory_bytes: 23764
ni = lambda: int(input())
nm = lambda: map(int, input().split())
nl = lambda: list(map(int, input().split()))

import math

d=ni()

x=0
y=1
cnt=0
dd=0
while True:
  cnt+=1
  dd=(dd+d)%360
  r = math.radians(dd)
  x += math.sin(r)
  y += math.cos(r)

  # print("{}, {}".format(x,y))

  if abs(x)<10**(-10) and abs(y)<10**(-10):
    break
print(cnt+1)





Measured memory_bytes: 9576
def hash_sort_desc(hash)
  hash.sort {|a,b| a[1]<=>b[1]}.reverse
end

def search_mode(hash)
  hash = hash_sort_desc(hash)
  [hash[0][0], hash[1][0]]
end

def count_replace(hash, other_replace_key)
  res = 0
  hash.each do |k, v|
    res += v if k != other_replace_key
  end
  res
end

def select_replace_key(hash, other_key)
  d_hash = hash_sort_desc(hash)
  res = nil
  d_hash.each do |k, v|
    if k != other_key
      res = k
      break
    end
  end
  res
end

_ = gets.to_i
a = []
b = []
x = Hash.new(0)
y = Hash.new(0)
gets.chomp.split.each_with_index do |s, i|
  s = s.to_i
  if i.even?
    a << s
    x[s] += 1
  else
    b << s
    y[s] += 1
  end
end

ua = a.uniq
ub = b.uniq
if ua.size == 1 && ub.size == 1
  if ua == ub
    puts b.size
  else
    puts '0'
  end
elsif ua.size == 1
  other_replace_key = select_replace_key(y, ua.first)
  puts count_replace(y, other_replace_key)
elsif ub.size == 1
  other_replace_key = select_replace_key(x, ub.first)
  puts count_replace(x, other_replace_key)
else
  a_key1, a_key2 = search_mode(x)
  b_key1, b_key2 = search_mode(y)
  if a_key1 == b_key1
    ans1 = count_replace(x, a_key1) + count_replace(y, b_key2)
    ans2 = count_replace(x, a_key2) + count_replace(y, b_key1)
    puts [ans1, ans2].min
  else
    puts count_replace(x, a_key1) + count_replace(y, b_key1)
  end
end


Measured memory_bytes: 30812
#include <bits/stdc++.h>
using namespace std;
double solve(vector<vector<vector<double>>> &dp,int a, int b, int c, int n) {
  if (dp[a][b][c]) return dp[a][b][c];
  if (!a&&!b&&!c) return 0;
  dp[a][b][c] = 1.0*n/(a+b+c);
  if (a) dp[a][b][c] += solve(dp,a-1,b,c,n)*a/(a+b+c);
  if (b) dp[a][b][c] += solve(dp,a+1,b-1,c,n)*b/(a+b+c);
  if (c) dp[a][b][c] += solve(dp,a,b+1,c-1,n)*c/(a+b+c);
  return dp[a][b][c];
}
int main() {
  int N;
  cin >> N;
  int ones = 0, twos = 0, threes = 0, a;
  vector<vector<vector<double>>> dp(N+1,vector<vector<double>>(N+1,vector<double>(N+1)));
  for (int i = 0; i < N; i++) {
    cin >> a;
    ones += a == 1;
    twos += a == 2;
    threes += a == 3;
  }
  cout.precision(20);
  cout << solve(dp,ones,twos,threes,N);
}

Measured memory_bytes: 219984
from collections import *
from itertools import *
from bisect import *
from heapq import *
import copy
#import math

#N=int(input())
#X,Y=map(int,input().split())
#S=list(map(int,input().split()))
#S=[list(map(int,input().split())) for i in range(N)]
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]

    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x


    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())




N,M,K=map(int,input().split())
AB=[list(map(int,input().split())) for i in range(M)]
for i in range(M):
    AB[i][0]-=1
    AB[i][1]-=1
CD=[list(map(int,input().split())) for i in range(K)]
for i in range(K):
    CD[i][0]-=1
    CD[i][1]-=1


uf=UnionFind(N)
fblst=[set() for i in range(N)]
blocklst=[0 for i in range(N)]
for a,b in AB:
    uf.union(a,b)
    fblst[a].add(b)
    fblst[b].add(a)


for c,d in CD:
    if uf.same(c,d):
        blocklst[c]+=1
        blocklst[d]+=1

lst=[]
for i in range(N):
    lst.append(uf.size(i)-len(fblst[i])-blocklst[i]-1)


print(" ".join(list(map(str,lst))))


Measured memory_bytes: 135256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define pp pair<int,int>
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ld long double
#define al(a) (a).begin(),(a).end()
#define mk make_pair
#define check cout<<"?"<<endl;

ll MOD=1000000007;
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;

int main() {
    ll n,l,r,e,ind,ans=0; cin>>n;
    vector<pair<ll,ll>> a(n);
    rep(i,n){
        ll q; cin>>q;
        a[i]=mk(q,i);
    }
    sort(al(a)); reverse(al(a));
    vector<vector<ll>> dp(n+1,vector<ll>(n+1,-INF));
    dp[0][0]=0;
    rep(i,n){
        tie(e,ind)=a[i];
        rep(j,i+1){
            l=dp[i][j]+e*(ind-j);
            r=dp[i][j]+e*(n-1-i+j-ind);
            if(l>dp[i+1][j+1]) dp[i+1][j+1]=l;
            if(r>dp[i+1][j]) dp[i+1][j]=r;
        }
    }
    rep(i,n+1) ans=max(ans,dp[n][i]);
    cout<<ans<<endl;
}

Measured memory_bytes: 34676
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {

        Scanner scn = new Scanner(System.in);
        int count = scn.nextInt();

        int[][][] array;
        array = new int[4][3][10];

        for(int i = 0; i < count; i++){
            int b = scn.nextInt();
            int f = scn.nextInt();
            int r = scn.nextInt();
            int v = scn.nextInt();
            array[b - 1][f -1][r -1] += v;
        }


        for(int i = 0; i < 4; i++){
            for(int j = 0; j < 3; j++){
                for(int k = 0; k < 10; k++){
                    System.out.printf(" %d",array[i][j][k]);
                }
                System.out.printf("\n");
            }
            if(i != 3) System.out.printf("####################\n");
        }

    }
}


Measured memory_bytes: 30308
#include <algorithm>
#include <bitset>
//#include <boost/multiprecision/cpp_int.hpp>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
//namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
// using ll = boost::multiprecision::cpp_int;
using ll = long long;
#define FORi(N) for(ll i = 0; i < N; ++i)
#define FORj(N) for(ll j = 0; j < N; ++j)
#define FORk(N) for(ll k = 0; k < N; ++k)

#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}

int main() {
    ll N;
    cin >> N;
    vector<ll> A;
    FORi(N) {
        ll tmp;
        cin >> tmp;
        A.push_back(tmp);
    }
    vector<ll> aa;
    FORi(N){
        ll f = false;
        auto it = lower_bound(ALL(aa),A[i]);
        if(it==aa.begin()){
            //新しく加える
            aa.insert(it,A[i]);
        }else{
            auto it2 = lower_bound(ALL(aa), A[i]);
            it2--;
            *it2 = A[i];
        }
        /*if(!f){
            aa.push_back(A[i]);
        }*/
    }
    //FORi(aa.size()) { cout << aa[i] << endl; }
    cout << aa.size() << endl;
    return 0;
}

Measured memory_bytes: 2548
/**
 *    author:  tourist
 *    created: 06.01.2020 22:59:57       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  int ans = 0;
  int beg = 0;
  while (beg < n) {
    ++ans;
    int end = beg;
    bool up = false;
    bool down = false;
    while (end + 1 < n) {
      if (a[end + 1] > a[end]) {
        if (down) {
          break;
        }
        up = true;
      }
      if (a[end + 1] < a[end]) {
        if (up) {
          break;
        }
        down = true;
      }
      ++end;
    }
    beg = end + 1;
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;
const int INF = 1001001001;

int main() {
  int n;
  cin >> n;
  vector<int> p(n), q(n);
  rep(i,n) cin >> p[i];
  rep(i,n) cin >> q[i];
  vector<int> one_case(n);
  rep(i,n) one_case[i] = i+1;

  map<vector<int>, int> mp;

  do{
      mp[one_case] = mp.size();
  }while (next_permutation(one_case.begin(),one_case.end()));

  int ans = abs(mp[p]-mp[q]);
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 5248
#include<stdio.h>
int vis[103];
int main(){
	int n,k;
	scanf("%d%d",&n,&k);
	for(int i=1;i<=k;i++){
		int tmp;scanf("%d",&tmp);
		for(int j=1;j<=tmp;j++){
			int a;scanf("%d",&a);
			vis[a]=1;
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++){
		if(vis[i]==0)ans++;
	}
	printf("%d\n",ans);
}

Measured memory_bytes: 1724
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<cmath>
#include<string>
#include<bitset>
#include <sstream>
#include<queue>
#include<set>
#define rep(i,n) for(ll i=0;i<(n);++i)
using namespace std;
typedef long long ll;
typedef pair<int,ll>P;

const int MAX=1e5+1;
const ll INF=1e9;

int main()
{
    string s;
    cin>>s;
    if(s=="A")cout<<"T";
    if(s=="T")cout<<"A";
    if(s=="C")cout<<"G";
    if(s=="G")cout<<"C";

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define GET_MACRO(_1, _2, _3, NAME, ...) NAME
#define _repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define _rep(i,n) _repl(i,0,n)
#define rep(...) GET_MACRO(__VA_ARGS__, _repl, _rep)(__VA_ARGS__)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream &o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream &o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

#define INF 1120000000
#define long long long // for codeforces

int main(){
  int n;
  cin>>n;
  vector<int> a(n),b(n),c(n);
  rep(i,n) cin>>a[i];
  rep(i,n) cin>>b[i];
  rep(i,n) cin>>c[i];
  sort(all(a));
  sort(all(b));
  sort(all(c));

  long ans = 0;
  rep(i,n){
    // use b[i]
    long tmp = lower_bound(all(a), b[i]) - a.begin();
    tmp *= c.end() - upper_bound(all(c), b[i]);
    ans += tmp;
  }

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1408
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repm(i, m, n) for (int i = (m); i < (int)(n); i++)
#define repr(i, n) for (int i = (n); i > 0; i--)
#define all(vec) vec.begin(), vec.end()
using namespace std;

int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  
  int ans = 0;
  //string ans;
  rep(i, a + 1){
    rep(j, b + 1){
      rep(k, c + 1){
        if (500 * i + 100 * j + 50 * k == d) ans++;
      }
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
typedef unsigned long long ull;
#define reps(i,s,n) for(ll (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define reptr(i,n) for(ll (i)=(n);(i)>=0;--(i))
#define All(x) (x).begin(),(x).end()
#define Rall(a) (a).rbegin(), (a).rend()
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>
#define mp make_pair
#define pb push_back
const ll MOD=1e9+7;
const ll INF=1e10+1;
using namespace std;
#define NOT_EXIST -1

int dy[]={1,-1,0,0,1,1,-1,-1,0};
int dx[]={0,0,1,-1,1,-1,1,-1,0};

int main(){
	string s;
	cin >> s;
	ll ans = 0;
	for(int i=0;i < (1 << (s.size()-1));i++){
		ll num = 0, st = 0, key = 1;
		for(ll j=0;j<s.size()-1;j++){
			if(i & (1<<j)){
				//cout << st << " " << key << endl;
				num += stoll(s.substr(st, key));
				st = st+key;
				key = 1;
			}else{
				key++;
			}
		}
		//cout << st << " " << key << endl;
		//cout << endl;
		num += stoll(s.substr(st, key));
		ans += num;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>
#include <stack>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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

#define rep(i, n) for(ll i = 0; i < n; ++i)
#define all(s) s.begin(), s.end()
#define sz(x) (ll)(x).size()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;
typedef vector<ll> vl;
typedef vector<P> vp;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0) : n(n), d(n+1) {}
  void add(int i, T x=1) {
    i++; // 0-indexed to 1-indexed
    for (; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
  // The sum of [0, i]
  T sum(int i) {
    i++; // 0-indexed to 1-indexed
    T x = 0;
    for (; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
  // The sum of [l, r)
  T sum(int l, int r) {
    return sum(r-1) - sum(l-1);
  }
};

// int main(int argc, char** argv) {
//   int N;
//   cin >> N;
//   vector<int> v(N);
//   rep(i, N) {
//     cin >> v[i];
//   }
//
//   BIT<int> bit(N);
//   rep(i, N) {
//     bit.add(i, v[i]);
//   }
//
//   cout << bit.sum(4) << endl; // sum of [0,4]. 24
//   cout << bit.sum(9) << endl; // sum of [0,9]. 55
// }

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;
  vector<P> a(n); // pair of <value, idx>
  rep(i,n) {
    cin >> a[i].first;
    a[i].second = i;
  }
  sort(all(a)); // increasing order of value

  BIT<int> bit(200005);
  ll ans = 0;
  for (auto& p : a) {
    ans += bit.sum(p.second+1, 200005); // larger value than p.second
    bit.add(p.second,1);
  }
  cout << ans << endl;
}



Measured memory_bytes: 6764
#include <stdio.h>

int main(void)
{
  int N;
  int a,b,c;

  scanf("%d", &N);
  a = N/100;
  b = (N-100*a)/10;
  c = N-100*a-10*b;
  if (a == 7){
    printf("Yes\n");
  } else {
    if (b == 7){
      printf("Yes\n");
    } else {
      if (c == 7){
	printf("Yes\n");
      } else {
	printf("No\n");
      }
    }
  }

  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
int k;
int mo=7,used[2000005],ans;
int main(){
    scanf("%d",&k);
    if(k%2==0) puts("-1");
    else {
        mo=7%k;
        used[mo]=1;bool flg=0;
        while(mo!=0) {
            ++ans;
            mo*=10;mo+=7;
            mo%=k;
            if(used[mo]) {flg=1;printf("-1\n");break;}
            used[mo]=1;
        }
        if(!flg)printf("%d\n",ans+1);
    }
    return 0;
}

Measured memory_bytes: 7664
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repI(i, d, n) for (int i = (d); i < (n); ++i)
#define reps1(i, n) for (int i = 1; i < (n); ++i)
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; }

using ll = long long;
using P = pair<int, int>;
using Pl = pair<ll, ll>;
using M = map<int, int>;
using Ml = map<ll, ll>;
ll const INF = 1ll<<61;
double pi = 3.141592653589793238;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<ll> G[n];
  rep(i, m) {
    ll a, b;
    cin >> a >> b;
    a--;  b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  queue<ll> q;
  q.push(0);
  vector<ll> prev(n, INF);
  prev[0] = 0;

  while(!q.empty()) {
    ll pos = q.front();
    q.pop();
    rep(i, ll(G[pos].size())) {
      if (prev[G[pos][i]] != INF) continue;
      prev[G[pos][i]] = pos+1;
      q.push(G[pos][i]);
    }
  }

  cout << "Yes" << endl;
  reps1(i, n) {
    cout << prev[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 12908
#include <iostream>
#include <cassert>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <sstream>
#include <limits>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <ctime>
#include <list>
#include <map>
#include <set>
#define PI (acos(-1.0))
#define Abs(a) (((a)<0) ? (-(a)) :(a) )
#define rep(i,n) for((i)=0;(i)<(n);(i)++)
#define Rep(i,n) for(int i=0;i<(n);i++)
#define Rrep(i,n) for(int i=((n)-1);i>=0;i--)
#define rrep(i,n) for((i)=(n)-1;(i)>=0;(i)--)
#define Pii pair<int,int>
#define PB push_back
#define Size(x) ((int)(x.size()))
using namespace std;
typedef long long mint;
typedef unsigned long long umint;
int main()
{
    //freopen("in.txt","r",stdin);
    int n;
    cin >> n;
    int prev;
    cin >> prev;
    int cnt = 1 , val;
    bool dir;
    bool same = true;
    Rep(i,n - 1)
    {
        scanf("%d" , &val);
        if(same && val != prev)
        {
            dir = (val > prev);
            same = false;
        }
        else
        {
            if(val == prev)
            {
                continue;
            }
            bool cDir = (val  > prev);
            if(cDir != dir)
            {
                same = true;
                cnt++;
            }
        }
        prev = val;
    }
    cout << cnt << endl;
    return 0;
}




Measured memory_bytes: 256
import itertools

N = int(input())
XY = [tuple(map(int,input().split())) for _ in range(N)]

def get_circle_center_and_radius(x1, y1, x2, y2, x3, y3):
  d = 2 * ((y1 - y3) * (x1 - x2) - (y1 - y2) * (x1 - x3))
  x = ((y1 - y3) * (y1 ** 2 - y2 ** 2 + x1 ** 2 - x2 ** 2) - (y1 - y2) * (y1 ** 2 - y3 ** 2 + x1 ** 2 - x3 ** 2)) / d
  y = ((x1 - x3) * (x1 ** 2 - x2 ** 2 + y1 ** 2 - y2 ** 2) - (x1 - x2) * (x1 ** 2 - x3 ** 2 + y1 ** 2 - y3 ** 2)) / -d
  r = ((x - x1) ** 2 + (y - y1) ** 2) ** 0.5
  return x, y, r

def check_line(x1,y1,x2,y2,x3,y3):
  if x1 == x2 == x3:
    return True
  elif y1 == y2 == y3:
    return True
  elif (y2-y1)*(x3-x1) == (y3-y1)*(x2-x1):
    return True
  else:
    return False

def check_r(x,y,r):
  res = True
  for i in range(N):
    x1,y1 = XY[i]
    if ((x-x1)**2+(y-y1)**2)**0.5 > r:
      res = False
      break
  return res

mnr = float('inf')
for i in range(N-1):
  for j in range(i+1,N):
    x1,y1 = XY[i]
    x2,y2 = XY[j]
    x = (x1+x2)/2
    y = (y1+y2)/2
    r = (((x2-x1)**2+(y2-y1)**2)**0.5)/2
    if check_r(x,y,r) and mnr > r:
      mnr = r    

for i,j,k in list(itertools.combinations(range(N),3)):
  x1,y1 = XY[i]
  x2,y2 = XY[j]
  x3,y3 = XY[k]
  if check_line(x1,y1,x2,y2,x3,y3):
    continue
  x,y,r = get_circle_center_and_radius(x1,y1,x2,y2,x3,y3)
  if check_r(x,y,r) and mnr > r:
    mnr = r

print(mnr)


Measured memory_bytes: 49900
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }


/*
<url:>
問題文============================================================

=================================================================

解説=============================================================

================================================================
*/

ll dist[105][505*505];
int main(void) {
	cin.tie(0); ios::sync_with_stdio(false);
    ll W,H,N; cin >> W >> H >> N;
    vector<ll> x(N+1),y(N+1);
    x[0] = y[0] = 1;
    for(int i = 1; i <= N;i++) cin >> x[i] >> y[i];
    vector<vector<ll>> G(N+1);
    
    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= N;j++){
            if(i == j) continue;
            //if(x[i] <= x[j]){// && y[i] <= y[j]){
                G[i].push_back(j);
            //}
        }
    }

    for(int i = 0; i < 105;i++)for(int j = 0; j < 505*505; j++) dist[i][j] = LINF;
    
    typedef pair<ll,pll> plpll;
 //   dist[0][0] = 0;
    priority_queue<plpll,vector<plpll>,greater<plpll>> pq;
    for(int i = 1; i <= N;i++){
        ll cost = abs(x[i]-x[0])+abs(y[i]-y[0]);
        pq.push({cost,{i,cost}});
        dist[i][cost] = cost;
    }
//    pq.push({0,{0,0}});
    while(pq.size()){
        auto p = pq.top(); pq.pop();
        ll d = p.first, n = p.second.first, r = p.second.second;
        if(dist[n][r] < d) continue;
        for(ll next : G[n]){
            ll mdis = abs(x[n]-x[next]) + abs(y[n]-y[next]);
            if(r >= mdis-1){
                if(dist[next][0] > dist[n][r]){
                    dist[next][0] = dist[n][r];
                    pq.push({dist[next][0],{next,0}});
                }
            }else{
                ll cost = mdis-r-1;
                if(dist[next][cost] > dist[n][r] + cost){
                    dist[next][cost] = dist[n][r] + cost;
                    pq.push({dist[next][cost],{next,cost}});
                }
            }
        }
    }
    ll ans = LINF;
    for(int i = 1; i <= N;i++){
        for(int j = 0; j < 505*505;j++){
            if(dist[i][j]==LINF)continue;
            ll mdis = abs(W-x[i])+abs(H-y[i]);
            ans = min(ans,dist[i][j]+max(mdis-j,0LL));
        }
    }
    cout << ans << endl;
	return 0;
}



Measured memory_bytes: 213924
#include<iostream>
#include<limits.h>
#define SENTINEL INT_MAX
using namespace std;
typedef long long ll;
ll counter=0;
void Merge(long long S[],int left,int mid,int right){
  int n1 = mid-left;
  int n2 = right-mid;
  ll L[n1+1];
  ll R[n2+1];

  for(int i=0;i<n1;i++){
    L[i] = S[left+i];
  }
  for(int i=0;i<n2;i++){
    R[i]=S[mid+i];
  }
  L[n1]=R[n2]=SENTINEL;
  int i=0;
  int j=0;
  for(int k=left;k<right;k++){
    if(L[i]<=R[j]){
      S[k]=L[i];
      i=i+1;
      counter++;
    }
    else{
      S[k]=R[j];
      j=j+1;
      counter++;
    }
  }
}

void Merge_Sort(long long S[],int left,int right){
 
  if(left+1<right){
    int mid = (left+right)/2;
    Merge_Sort(S,left,mid);
    Merge_Sort(S,mid,right);
    Merge(S,left,mid,right);
  }
}



int main(){
  int n;
  ll S[600000];

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

    Merge_Sort(S,0,n);

    for(int i=0;i<n;i++){
      cout << S[i];
      if(i != n-1)cout << " ";
    }
    cout << endl;
    cout << counter << endl;

  return 0;
}

Measured memory_bytes: 8676
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#define RNG(i,from,to) for(int i=(from); i<(int)(to); i++)
#define gcd(i,j) __gcd((i), (j))
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<ll> vecll;
template<typename S, typename T> string to_string(pair<S, T> p) { return "("+to_string(p.first)+","+to_string(p.second)+")"; }
template<typename T> string to_string(T p[2]) { return "["+to_string(p[0])+","+to_string(p[1])+"]"; }
template<typename T> void println(T e){ cout << to_string(e) << endl; }
template<typename T> void println(const vector<T>& v){ cout << "[";for(const auto& e : v){ cout << to_string(e) << ","; }cout << "]";cout << endl; }
template<typename T> void println(const vector<vector<T>>& vv){ for(const auto& v : vv){ println(v); } }
template<typename Iter> void println(Iter first, Iter last){ for(auto it=first; it != last; it++){ cout << *it << " "; }; cout << endl; }
template<typename T> T mod_pow(T x, T n, const T &p) { T ret = 1; while(n > 0) { if(n & 1) (ret *= x) %= p; (x *= x) %= p; n >>= 1; } return ret; }
template<typename T> T mod_inv(T x, const T &p) { return mod_pow(x, p-2, p); }
const ll DVSR = 1e9+7;


int main(int argc, char const *argv[])
{
  string a,b,c; cin >> a >> b >> c;
  cout << a[0] << b[1] << c[2] << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<string>
#include<math.h>
#include<vector>
#include<iomanip>
using namespace std;

int main(void)
{
    string mass[50];
    int h,w;
    int x[8] = {-1,-1,-1,0,0,1,1,1};
    int y[8] = {-1,0,1,-1,1,-1,0,1};
    cin >> h >> w;
    for(int i = 0;i < h;i++)
    {
        cin >> mass[i];
    }

    for(int i = 0;i < h;i++)
    {
        for(int j = 0;j < w;j++)
        {
            if(mass[i][j] == '#'){continue;}
            
            int num = 0;
            for(int d = 0;d < 8;d++)
            {
                int ni = i + x[d];
                int nj = j + y[d];
                if(ni < 0 || h <= ni){continue;}
                if(nj < 0 || w <= nj){continue;}
                if(mass[ni][nj] == '#'){num++;}
            }
            mass[i][j] = char(num + '0');
        }
    }
    for(int i = 0;i < h;i++){cout << mass[i] << endl;}
    return 0;
}

Measured memory_bytes: 256
N=int(input())
A=list(map(int,input().split()))
ans=0
A=A+[0]
_A=[0]*N
_=0
for i in range(N):
  ans+=abs(_-A[i])
  _A[i]=abs(A[i+1]-_)-abs(_-A[i])-abs(A[i]-A[i+1])
  _=A[i]
ans+=abs(_-A[-1])
for i in range(N):
  print(ans+_A[i])

Measured memory_bytes: 14048
#include<bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using P = pair<int,int>;
using ll = long long;
using namespace std;
int main() {
    int x, n;
    cin >> x >> n;
    int p[n];
    //vector<int> c(n);
    rep(i, n){cin >> p[i];}
    sort(p, p+n, std::greater<int>());
    int sum = 0;
    int mini = 10000;
    int a = 0;
    int hot = 0;
    for(int i = 101; i >= 0; --i){
        rep(j, n){
            if(i == p[j]){hot = 1; break;}
        }
        
        if(hot == 1){hot = 0; continue;}
        
        sum = i - x;
        if(abs(sum) <= mini){
            a = i;
        }
        mini = abs(sum);
        //cout << i << endl;
    }
    cout << a << endl;
    
}

Measured memory_bytes: 3548
#define _CRT_SECURE_NO_WARNINGS
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define E "\n"

using namespace std;
const long long MOD = (long long)1e9 + 7;

int a, b;

int main()
{
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> a >> b;
    int c = a * b;
    cout << c << E;
    //system("pause");
    return 0;
}

Measured memory_bytes: 3596
#include <iostream>
using namespace std;
typedef long long ll;

int main()
{
        ll N;
        cin >> N;
        ll ans = 0;
        for(int i = 0; i < N; i++)
        {
                ll a;
                cin >> a;
                ans += a-1;
        }

        cout << ans << endl;

        return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main()
{
    int a,b;
    while(scanf("%d%d",&a,&b)!=EOF)
    {
        int sum=a+b;
        int cnt=0;
        for(int i=0;;i++)
        {
            cnt++;
            sum=sum/10;
            if(sum==0)break;
        }
        printf("%d\n",cnt);
    }
return 0;
}



Measured memory_bytes: 2692
var lines = [];

var readline = require('readline');
var rl = readline.createInterface({
    input: process.stdin,
    output: process.stdout,
});

rl.on('line', function (x) {
    lines.push(x);
});

rl.on('close', function () {
    var tmp_1 = lines.shift().split(" ");
    var N = Number(tmp_1[0]);
    var K = Number(tmp_1[1]);

    var v = lines[0].split("");

    var Nums = [];
    var now = 1;
    var cnt = 0;

    // 1-0-1-0-1
    for (var i = 0; i < N; i++) {
        if (v[i] === now.toString()) { cnt++; }
        else {
            Nums.push(cnt);
            now = 1 - now; // 0-1反転
            cnt = 1;
        }
    }

    // cntが0でなければ，配列に加える
    if (cnt != 0) { Nums.push(cnt); }

    // 1-0-1-0-...-1のような配列を用意する
    if (Nums.length % 2 === 0) { Nums.push(0); }



    var sum = Array(Nums.length + 1).fill(0);
    for (var i = 0; i <= Nums.length; i++) {
        if (i === 0) { sum[i] = 0; }
        else {
            sum[i] += sum[i - 1] + Nums[i - 1];
        }
    }
    
    var cnt = 0; var max = 1;

    if (sum.length - 2 * K > 0) {
        for (var i = 0; i < sum.length - 2 * K; i = i + 2) {
            cnt = sum[i + 2 * K + 1] - sum[i];

            if (max < cnt + 1) { max = cnt; }
        }
    }
    else {
        max = sum[sum.length - 1];
    }
    console.log(max);
});

Measured memory_bytes: 15296