akhauriyash/Code-Regression huggingface dataset:
package main

import (
	"bufio"
	_ "container/heap"
	"fmt"
	"os"
	_ "sort"
	"strconv"
)

// I/O
type Scanner struct {
	sc *bufio.Scanner
}

func NewScanner() *Scanner {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &Scanner{sc}
}

func (s *Scanner) nextStr() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *Scanner) nextInt() int {
	i, e := strconv.Atoi(s.nextStr())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *Scanner) nextFloat() float64 {
	f, e := strconv.ParseFloat(s.nextStr(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *Scanner) nextRuneSlice() []rune {
	return []rune(s.nextStr())
}

func (s *Scanner) nextIntSlice(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextInt()
	}
	return res
}

func (s *Scanner) nextFloatSlice(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.nextFloat()
	}
	return res
}

// Arithmetic
func max(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m < i {
			m = i
		}
	}
	return m
}

func min(nums ...int) int {
	m := nums[0]
	for _, i := range nums {
		if m > i {
			m = i
		}
	}
	return m
}

func abs(x int) int {
	if x > 0 {
		return x
	}
	return -x
}

func pow(x, y int) int {
	res := 1
	for i := 0; i < y; i++ {
		res *= x
	}
	return res
}

func ceil(a, b int) int {
	if a%b == 0 {
		return a / b
	} else {
		return a/b + 1
	}
}

func gcd(a, b int) int {
	if b == 0 {
		return a
	}
	return gcd(b, a%b)
}

func lcm(a, b int) int {
	return a / gcd(a, b) * b
}

// Sort
type RuneSlice []rune

func (a RuneSlice) Len() int           { return len(a) }
func (a RuneSlice) Less(i, j int) bool { return a[i] < a[j] }
func (a RuneSlice) Swap(i, j int)      { a[i], a[j] = a[j], a[i] }

// Main
const MOD = int(1e+9) + 7
const INF = 1 << 60

func main() {
	sc := NewScanner()
	wtr := bufio.NewWriter(os.Stdout)
	defer wtr.Flush()
	N, M := sc.nextInt(), sc.nextInt()
	A := sc.nextIntSlice(N)
	S := make([]int, N+1)
	for i := 0; i < N; i++ {
		S[i+1] = (S[i] + A[i]) % M
	}
	set := make(map[int]int)
	for i := 1; i < N+1; i++ {
		set[S[i]]++
	}
	ans := 0
	num := 0
	for i := 1; i < N+1; i++ {
		ans += set[num]
		set[S[i]]--
		num = S[i]
	}

	fmt.Fprintln(wtr, ans)
}


Measured memory_bytes: 8576
X = int(input())

for a in range(100):
    for b in range(-100, 0):
        if X == a**5 - b**5:
            print(str(a) + " " + str(b))
            exit()

for t in range(200):
    for b in range(200):
        ans = t * (b**4*5 + b**3*t*10 + b**2*t**2*10 + b*t**3*5 + t**4)
        if X == ans:
            a = b + t
            print(str(a) + " " + str(b))
            exit()

Measured memory_bytes: 9200
N = input()
taro = 0
hanako = 0
for n in range(N):
    cards = raw_input().split()
    if cards[0] > cards[1]:
        taro += 3
    elif cards[0] < cards[1]:
        hanako += 3
    else:
        taro += 1
        hanako += 1
print "%d %d" % (taro, hanako)

Measured memory_bytes: 6400
#include<bits/stdc++.h>
using namespace std;
const int N =1e4+100;
int main()
{
    int h,n,x;
    while(~scanf("%d%d",&h,&n))
    {
        bool vis[N] = {0}; 
        int sum =0;
        for(int i=0; i<n; i++)
        {
            scanf("%d",&x);
           // if(!vis[x])
                sum+=x;
            vis[x] =1;
        }
        if(sum>=h)
            printf("Yes\n");
        else
            printf("No\n");
    }
    return 0;
}


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

#define rep(i,x,y) for(ll i=(x);i<(y);i++)
#define rrep(i,x,y) for(ll i=(ll)(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
//#define int long long

typedef long long ll;
const ll MOD = 1e9 + 7;

class BIT
{
public:
    vector<int> bit;
    int M;

    BIT(int M):
            bit(vector<int>(M+1, 0)), M(M) {}

    int sum(int i) {
        if (!i) return 0;
        return bit[i] + sum(i-(i&-i));
    }

    void add(int i, int x) {
        if (i > M) return;
        bit[i] += x;
        add(i+(i&-i), x);
    }
};

signed main(){
    ll N, Q;
    string S;
    cin >> N >> S >> Q;

    vector<BIT> bits(26, BIT(N));

    rep(i,0,N) {
        bits[S[i] - 'a'].add(i+1, 1);
    }
    rep(_,0,Q) {
        int type;
        cin >> type;
        if (type == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            if (S[i] == c) continue;
            bits[S[i] - 'a'].add(i+1, -1);
            bits[c - 'a'].add(i+1, 1);
            S[i] = c;
        } else if (type == 2) {
            int l, r;
            cin >> l >> r;
            l--; r--;
            int cnt = 0;
            rep(i,0,bits.size()) {
                if (bits[i].sum(r+1) - bits[i].sum(l) > 0) cnt++;
            }
            cout << cnt << endl;
        }
    }
    return 0;
}


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

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    
    
    if ( x - r < 0  || x + r > W || y - r < 0  || y + r > H )  cout << "No" << endl;
    else cout << "Yes" << endl;


    
    return 0;
    
    
}

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

#define rep(i,a,b) for (int64_t i = (a); i < (b); i++)
#define REP(i,n) rep(i,0,n)

void solve() 
{
    int n,r;cin>>n>>r;
    cout<<r+(10-n>0?100*(10-n):0)<<endl;
}

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

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

int main(){
    int N;
    cin >> N;
    for(int i=1;i<10;i++){
        if((N%i==0)&&((N/i)<10)){
            cout <<"Yes";
            return 0;
        }
    }
    cout <<"No";
    return 0;
}

Measured memory_bytes: 256
n = int(input())
H = [int(i) for i in input().split()]
for ni in range(1,n+1):
    print("node "+str(ni)+": ", end = "")
    print("key = "+str(H[ni-1])+", ", end = "")
    if ni != 1:
        print("parent key = "+str(H[ni//2-1])+", ", end = "")
    if 2*ni <= n:
        print("left key = "+str(H[2*ni-1])+", ", end = "")
    if 2*ni+1 <= n:
        print("right key = "+str(H[2*ni])+", ", end = "")
    print()


Measured memory_bytes: 5720
SS = input()
T = input()
N = len(SS) - len(T)
key = []
key_t = []
for i in range(N,-1,-1):
  tmp = i
  cnt = 0
  cnt_t = 0
  for j in range(len(T)):
    if SS[tmp] != T[j] and SS[tmp] != "?":
      pass
    else:
      if SS[tmp] == T[j]:
        cnt += 1
        cnt_t += 1
      else:
        cnt += 1
    tmp += 1
  if cnt == len(T):
    key.append(i)
  if cnt_t == len(T):
    key_t.append(i)
SS = list(SS)
if len(key_t) >= 1:
  for i in SS:
    if i == "?":
      print("a",end="")
    else:
      print(i,end="")
elif len(key) >= 1:
    g = key[0]
    for i in range(len(T)):
      SS[g] = T[i]
      g += 1
    for s in SS:
      if s == "?":
        print("a",end="")
      else:
        print(s,end="")
else:
  print("UNRESTORABLE")

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int array[] = new int[N];
		int count = 0;
		for(int i = 0; i < N; i++){
			array[i] = sc.nextInt();
		}

		for(int i = 0; i < N; i++){
			for(int j = N-1; j >=1; j--){
				if(array[j]< array[j-1]){
					int tmp = array[j];
					array[j] = array[j-1];
					array[j-1] = tmp;
					count++;
				}
			}
		}
		for(int i = 0; i < N; i++){
			if(i == N-1){
				System.out.println(array[i]);
			}else{
				System.out.print(array[i] + " ");
			}
		}
		System.out.println(count);
		sc.close();

	}
}



Measured memory_bytes: 26168
#!/usr/bin/env python3

import sys


class Node(object):
    def __init__(self, parent_id=-1, depth=0, children=[]):
        self.parent_id = parent_id
        self.depth = depth
        self.children = children

if __name__ == "__main__":
    lines = sys.stdin.readlines()
    node_list = [None] * int(lines[0])  # Create empty list
    child_parent_map = [None] * int(lines[0])

    # Create the list of Node
    for line in lines[1:]:
        node_id, _, *children = [int(x) for x in line.strip().split(" ")]
        node_list[node_id] = Node(children=children)
        for child in children:
            child_parent_map[child] = node_id

    # Set the parent_id of each node
    for node_id, node in enumerate(node_list):
        if child_parent_map[node_id] is not None:
            node.parent_id = child_parent_map[node_id]

    # Set the depth of each node
    for node_id, node in enumerate(node_list):
        current_id = node_id
        current_depth = 0
        while True:
            # if current_id == 0:
            if node_list[current_id].parent_id == -1:
                node.depth = current_depth
                break
            else:
                current_id = node_list[current_id].parent_id
                current_depth += 1

    # Output
    for node_id, node in enumerate(node_list):
        if node.parent_id == -1:
            node_type = "root"
        elif len(node.children) == 0:
            node_type = "leaf"
        else:
            node_type = "internal node"

        print("node %d: parent = %d, depth = %d, %s, %s" % (node_id, node.parent_id, node.depth, node_type, node.children))

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

void solve(int N, vector<int> A, vector<int> B)
{
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    int mn, mx;
    if (N % 2 == 0)
    {
        mn = A.at(N / 2 - 1) + A.at(N / 2);
        mx = B.at(N / 2 - 1) + B.at(N / 2);
    }
    else
    {
        mn = A.at(N / 2);
        mx = B.at(N / 2);
    }
    cout << mx - mn + 1 << endl;
}

int main()
{
    int N;
    cin >> N;
    vector<int> A(N);
    vector<int> B(N);
    for (int i = 0; i < N; i++)
    {
        cin >> A.at(i);
        cin >> B.at(i);
    }
    solve(N, move(A), move(B));
    return 0;
}


Measured memory_bytes: 4848
import heapq
def main():

    H, W = map(int, input().split())
    A = []
    white = 0
    visited = set()
    visited.add((0, 0))
    for i in range(H):
        A.append(input())
        for j in range(W):
            if A[-1][j] == '.': white += 1
            else: visited.add((i, j))

    h = [[1, 0, 0]]
    goal = [H-1, W-1]
    mv = [[1,0],[-1,0],[0,1],[0,-1]]

    while h:
        n, i, j = heapq.heappop(h)
        if [i, j] == goal:
            return white - n
        for di, dj in mv:
            i1, j1 = i+di, j+dj
            if 0<=i1<H and 0<=j1<W and (i1, j1) not in visited:
                heapq.heappush(h, [n+1, i1, j1])
                visited.add((i1, j1))

    return -1

if __name__ == '__main__':
    print(main())


Measured memory_bytes: 44632
import java.util.*;


public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long count = 0;
        long current = 100l;
        while(true){
            if(current >= x){
                break;
            }
            long r = (long) (Double.valueOf(current) * 0.01d);
            current += r;
            count++;
        }
        System.out.println(count);

    }
}

Measured memory_bytes: 35888
S=input()
ans="Yes"
if "N" in S and not "S" in S:
  ans="No"
if "S" in S and not "N" in S:
  ans="No"
if "E" in S and not "W" in S:
  ans="No"
if "W" in S and not "E" in S:
  ans="No"
print(ans)


Measured memory_bytes: 8972
#include <iostream>
#include <algorithm>
#include <utility>
#include <vector>
#include <numeric>

template <class T, class U>
inline bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

template <class T, class U>
inline bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) {
    lhs = rhs;
    return true;
  }
  return false;
}

// [l, r) from l to r
struct range {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { ++i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr range(int l_, int r_): l(l_), r(std::max(l_, r_)) { }
  constexpr itr begin() const { return l; }
  constexpr itr end() const { return r; }
};

// [l, r) from r to l
struct revrange {
  struct itr {
    int i;
    constexpr itr(int i_): i(i_) { }
    constexpr void operator ++ () { --i; }
    constexpr int operator * () const { return i; }
    constexpr bool operator != (itr x) const { return i != x.i; }
  };
  const itr l, r;
  constexpr revrange(int l_, int r_): l(l_ - 1), r(std::max(l_, r_) - 1) { }
  constexpr itr begin() const { return r; }
  constexpr itr end() const { return l; }
};

int next_bit(long long x) {
  int res = 0;
  while ((1ll << res) <= x) {
    ++res;
  }
  return res;
}

long long solve(long long A, long long B) {
  if (A <= 1) {
    return (1ll << next_bit(B)) - A;
  }
  int tA = next_bit(A) - 1, tB = next_bit(B) - 1;
  if (tA == tB) {
    long long tmp = (1ll << tA) - 1;
    return solve(A & tmp, B & tmp);
  }
  long long res = ((1ll << tB) - (1ll << (tA + 1))) * 2 + (1ll << (tA + 1)) - A;
  if (B >= (1ll << tB) + (1ll << tA)) {
    return res + (1ll << (tA + 1));
  }
  else {
    long long tmp = (1ll << tA) - 1;
    return res + (1ll << (tA + 1)) - A + solve(0, B & tmp);
  }
}

int main() {
  long long A, B;
  std::cin >> A >> B;
  std::cout << solve(A, B) << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int main(){
	int a=1,n,k;
	cin>>n>>k;
	for(int i=0;i<n;i++){
		a=min(a+k,a*2);
		
	}
	
	cout<<a<<endl;
	
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
using namespace std;
using Int = long long;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<55)+1e9; // ~ 3.6 * 1e16
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
using T = tuple<Int,Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
ostream& operator<<(ostream& o,P p){return o<<"("<<p.first<<","<<p.second<<")";}
ostream& operator<<(ostream& o,T t){return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
istream& operator>>(istream& i,P &p){return i>>p.first>>p.second;}
ostream& operator<<(ostream& o,vector<auto> &a){Int i=0;for(auto t:a)o<<(i++?" ":"")<<t;return o;}
istream& operator>>(istream& i,vector<auto> &a){for(auto &t:a)i>>t;return i;}
void prArr(auto a,string s=" "){Int i=0;for(auto t:a)cout<<(i++?s:"")<<t;cout<<endl;}


signed main(){
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);
  
  Int d,n;
  cin>>d>>n;

  auto calc=[&](Int num){
    Int cnt = 0;
    while(num % 100 == 0) num /= 100, cnt++;
    return cnt;
  };

  Int ans = 0;
  Int cnt = 0;
  while(cnt < n){
    ans++;
    if(calc(ans) == d) cnt++;
  }

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


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

n,m = input().split()

N = int(n)
M = int(m)

if 2 < N and 2 < M:
    print(str((N-2)*(M-2)))
elif N == 1 and 2 < M :
    print(str(M-2))
elif 2 < N and M == 1:
    print(str(N-2))
elif N == 1 and M == 1:
    print(1)
else:
    print(0)

Measured memory_bytes: 3060
N = int(input())

def hash(S) :
    ret = 0
    for s in S :
        ret *= 26
        ret += ord(s)-97
    return ret
        
s = [hash(sorted(input())) for _ in range(N)]

s.sort()
s.append(-1)

count = 1
ret = 0
for i in range(1, N+1) :
    if s[i] == s[i-1] :
        count += 1
    else :
        if count >= 2 :
            ret += count * (count-1) // 2
        count = 1
        
print(ret)

Measured memory_bytes: 54232
#include<bits/stdc++.h>
#define MAX 100005
using namespace std;
 
int main(){
  int n, t, a, l, h, bnf = 0, cnt;
  scanf("%d%d", &n, &t);
  for(int i = 0; i < n; i++){
    scanf("%d", &a);
    if(!(i) || a < l) l = a;
    else if(a - l == bnf) cnt++;
    else if(a - l > bnf){
      bnf = a - l;
      cnt = 1;
    }
  }
  printf("%d\n", cnt);
}

Measured memory_bytes: 256
#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 ll INF = 1e9 + 7;

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	ll ans = 0;
	ll wa = 0;
	rep(i,n){
		wa += a[i]%INF;
		ans += wa%INF*a[i+1]%INF;
	}
	cout << ans%INF << endl;
}

Measured memory_bytes: 4020
#include<stdio.h>

int main(void)

{

int W,H,x,y,r;

scanf("%d %d %d %d %d",&W,&H,&x,&y,&r);

if(0+r<=x&&x<=W-r)

{

if(0+r<=y&&y<=H-r)

{

printf("Yes\n");

}

else

{

printf("No\n");

}

}

else

{

printf("No\n");

}

return 0;

}

Measured memory_bytes: 584
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>

using namespace std;

int c[] = {4, 1, 4, 1, 2, 1, 2, 1, 4, 1, 4, 1, 2, 1, 2, 1};
int s[] = {41412121,
		   14121214,
		   41212141,
		   12121414,
		   21214141,
		   12141412,
		   21414121,
		   14141212 };

void printv(int v[], int len) {
	int ifs = 1;
	for (int i = 0; i < len; i++) {
		if (ifs == 0)
			cout << " ";
		cout << v[i];
		ifs = 0;
	}
	cout << endl;
}

void solve(int p[8]) {
	int ans = 0;
	int minl = 50000000;
	for (int i = 0; i < 8; i++) {
		int l = 0;
		for (int j = 0; j < 8; j++) {
			l += ((p[j] - c[i + j]) > 0 ? p[j] - c[i + j] : 0);
		}
		if (minl > l) {
			ans = i;
			minl = l;
		}
		else if (minl == l) {
			if (s[ans] > s[i]) {
				ans = i;
				minl = l;
			}
		}
	}
	printv(&c[ans], 8);
}

int main() {
	int p[8];
	while (cin >> p[0]) {
		for (int i = 1; i < 8; i++)
			cin >> p[i];
		solve(p);
	}
	return 0;
}

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

using ll = long long;
using Pi = pair<int, int>;
using Pl = pair<ll, ll>;
using vint = vector<int>;
using vvint = vector<vint>;
using vvvint = vector<vvint>;
using vdouble = vector<double>;
using vvdouble = vector<vdouble>;
using vvvdouble = vector<vvdouble>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vvvll = vector<vvll>;
using uint = unsigned int;
using ull = unsigned long long;

template<typename T> using uset = unordered_set<T>;
template<typename T1, typename T2> using umap = unordered_map<T1, T2>;

constexpr int INF = (1 << 30) - 1;
constexpr ll LLINF = 1LL << 60;
constexpr int dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int dx[] = {0, 1, 0, -1, 1, 1, -1, -1};
constexpr char el = '\n';
constexpr int mod = 1000000007;
constexpr int mod2 = 998244353;
template<typename T> T gcd(T a, T b) { return (b ? gcd(b, a % b) : a); }
template<typename T> T lcm(T a, T b) { return (a / gcd(a, b) * b); }
template<typename T1, typename T2>
inline bool chmin(T1 &a, T2 b) { return (a > b && (a = b, true)); }
template<typename T1, typename T2>
inline bool chmax(T1 &a, T2 b) { return (a < b && (a = b, true)); }

template<typename T>
vector<T> makeVector(size_t a, T b) { return (vector<T>(a, b)); }
template<typename... Ts>
auto makeVector(size_t a, Ts... ts) { 
	return (vector<decltype(makeVector(ts...))>(a, makeVector(ts...)));
}

template<typename T>
bool isin(T y, T x, T h, T w) { return (0 <= y && 0 <= x && y < h && x < w); }
template<typename T>
bool isin1(T y, T x, T h, T w) { return (0 < y && 0 < x && y <= h && x <= w); }

template<typename T>
ostream& operator <<(ostream &os, vector<T> &v) {
	if (v.size()) {
		os << v[0];
		for (int i = 1; i < v.size(); i++) os << " " << v[i];
	}
	return (os);
}

template<typename T>
istream& operator >>(istream &is, vector<T> &v) {
	for (auto &u : v) is >> u;
	return (is);
}

template<typename T1, typename T2>
istream& operator >>(istream &is, pair<T1, T2> &p) {
	return (is >> p.first >> p.second);
}


void Main() {
	int N; cin >> N;
	vint A(N); cin >> A;
	sort(rbegin(A), rend(A));
	ll sum = 0; sum += A[0];
	ll cnt = N-2;
	for (int i = 1; i < N; i++) {
		if (cnt > 1) sum += A[i], cnt--;
		if (cnt > 0) sum += A[i], cnt--;
	}
	cout << sum << endl;
}

int main() {
	cin.tie(0);
	ios::sync_with_stdio(0);
	cout << fixed << setprecision(20);
	Main();
	return (0);
}


Measured memory_bytes: 3984
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <vector>
#include <queue>
#include <stack>
#include <cmath>
#include <map>
#include <iomanip>
#include <set>
#include <ctime>
#include <tuple>
#include <bitset>
#include <assert.h>
#include <deque>
using namespace std;

/*
using PAIR = pair<string, int>;
sort(sp.begin(), sp.end(), [](PAIR l, PAIR r){
        return l.first<r.first || (l.first==r.first && l.second > r.second);
        });
*/

typedef long long ll;

#define fi first
#define se second
#define rep(i, n) for (ll i = 0; i < n; i++)
#define debugA() cerr << "AAAAA" << endl
#define debug_() cerr << "-------------" << endl
#define debug(x) cerr << #x << ": " << x << endl
#define debug_vec(v)                   \
    cout << #v << endl;                \
    for (int i = 0; i < v.size(); i++) \
    {                                  \
        cout << v[i] << " ";           \
    }                                  \
    cout << endl;
#define debug_vec2(v)                         \
    cout << #v << endl;                       \
    for (int i = 0; i < v.size(); i++)        \
    {                                         \
        for (int j = 0; j < v[i].size(); j++) \
        {                                     \
            cout << v[i][j] << " ";           \
        }                                     \
        cout << endl;                         \
    }

using Graph = vector<vector<int>>;
using P = pair<int, int>;
using P1 = pair<int, pair<int, int>>; // クラスカル法とかで、{cost, {from, to}}的に使う。
const ll INF = 1001001001001001;
const double pi = acos(-1);

void warshall_floyd(vector<vector<ll>> &dp, ll V)
{
    for (int k = 0; k < V; k++)
    {
        for (int i = 0; i < V; i++)
        {
            for (int j = 0; j < V; j++)
                dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
        }
    }
    return;
}

int main()
{
    ll n, m, l;
    cin >> n >> m >> l;
    vector<vector<ll>> dist(n, vector<ll>(n, INF));
    for (int i = 0; i < n; i++)
    {
        dist[i][i] = 0;
    }
    for (int i = 0; i < m; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        dist[a][b] = dist[b][a] = c;
    }
    warshall_floyd(dist, n);
    vector<vector<ll>> dist2(n, vector<ll>(n, INF));
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            if (dist[i][j] <= l)
            {
                dist2[i][j] = 1;
            }
        }
    }
    warshall_floyd(dist2, n);
    int q;
    cin >> q;
    for (int i = 0; i < q; i++)
    {
        int s, t;
        cin >> s >> t;
        s--;
        t--;
        if (dist2[s][t] == INF)
        {
            cout << -1 << endl;
        }
        else
        {
            cout << dist2[s][t] - 1 << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 1920
#include <iostream>
#include <string>
#include <cstring>
using namespace std;

int main() {
    long long ans[4][4001];
    memset(ans, 0, sizeof ans);
    for (int i=0; i<=1000; ++i) {
        ans[0][i] = 1;
    }
    for (int k=0; k<3; ++k) {
        for (int i=4000; i>=0; --i) {
            if (ans[k][i] <= 0) continue;
            for (int j=0; j<=1000 && i+j<=4000; ++j) {
                ans[k+1][i+j] += ans[k][i];
            }
        }
    }
    int n;
    while (cin >> n) {
        cout << ans[3][n] << endl;
    }
    return 0;
}

Measured memory_bytes: 1288
#include <bits/stdc++.h>
using ll = long long;
constexpr int MOD = 1000000007;
constexpr int M= 61;
constexpr int DEBUG = 0;
using namespace std;
long long int powmod(long long int a, long long int n, long long int m) {
  long long int ret = 1;
  for (; n > 0; n >>= 1, a = a * a % m) {
    if (n % 2 == 1) {
      ret = ret * a % m;
    }
  }
  return ret;
}

int main() {
  int n;
  cin >> n;
  
  vector<ll> a(n), d(M, 0);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    for (int j = 0; j < M; j++) {
      if ((a[i] & (1ull << j)) != 0)
        d[j]++;
    }
  }
  
  if (DEBUG >= 2) {
    ll total = 0;
    for (int i = 0; i < n - 1; i++) {
      for (int j = i + 1; j < n; j++) {
        total += a[i] ^ a[j];
        total %= MOD;
      }
    }
    cout << "total:" << total << endl;
  }

  vector<ll> c(M*2, 0);
  for (int i = 0; i < M; i++) {
    c[i] = d[i] * (n - d[i]);
  }
  for (int i = 0; i < M; i++) {
    if (c[i] > 1) {
      c[i + 1] += c[i] / 2;
      c[i] %= 2;
    }
  }
  
  if (DEBUG) {
    for (int i = c.size() - 1; i >= 0; i--) {
      cout << c[i];
    }
    cout << endl;
  }
  
  ll ans = 0;
  for (int i = 0; i < c.size(); i++) {
    ans += c[i] * powmod(2, i, MOD);
    ans %= MOD;
  }
  
  cout << ans << endl;
  
  return 0;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long 
#define fast ios_base::sync_with_stdio(false); cin.tie(0);cout.tie(0);
const ll mod=998244353;
typedef tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update> data_struct;

bool check(ll a)
{
	ll factor=2;
	while (factor <= sqrt(a)) {
        ll number = a;
        while (number % factor == 0) {
            number /= factor;
        }
        // cout<<factor;
        if (number == 1) {
            return true;
        } 
        else {
            factor++;
        }
        cout<<factor<<"\n";
    }
    cout<<factor;
    return false;
}

int main()
{
	ll x;
	cin>>x;
	ll i,j;
	for(i=-200;i<=200;i++)
	{
		for(j=-200;j<=200;j++)
		{
			ll p=i*i*i*i*i;
			ll q=j*j*j*j*j;
			ll dif=p-q;
			if(dif==x)
			{
				cout<<i<<" "<<j;
				return 0;
			}
		}
	}
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;using ll=int_fast64_t;using ld=long double;using pll=pair<ll,ll>;using pld=pair<ld,ld>;
const ll INF=1LL<<60;void solve();int main(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(10);solve();}
#define foreach(i,a) for(auto &i:a)
#define SELECTOR(_1,_2,_3,_4,SELECT,...) SELECT
#define rep(...) SELECTOR(__VA_ARGS__,_rep2,_rep1,_rep0)(__VA_ARGS__)
#define _rep0(i,n) for(ll i=0;i<n;++i)
#define _rep1(i,k,n) for(ll i=k;i<n;++i)
#define _rep2(i,k,n,d) for(ll i=k;d!=0&&d>0?i<n:i>n;i+=d)
template<class T> vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<class... Ts> auto make_v(size_t a,Ts... ts){return vector<decltype(make_v(ts...))>(a,make_v(ts...));}
template<class T> inline bool chmax(T &a,const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> inline bool chmin(T &a,const T &b){if(a>b){a=b; return 1;} return 0;}

void solve(){
  ll n; cin>>n;
  vector<pll> XI(n);
  rep(i,n){
    ll x; cin>>x;
    XI[i]=make_pair(x,i);
  }


  sort(XI.begin(),XI.end());
  // xの値が小さいほうのindexから入れていく
  ll ans=0;
  set<ll> S{-1,n};
  foreach(p,XI){
    ll x,i; tie(x,i)=p;
    auto it1=S.insert(i).first;
    auto it2=it1;
    it1--; it2++;
    ll prev=*it1, next=*it2;
    ans+=x*(i-prev)*(next-i);
  }

  cout<<ans<<"\n";
}

Measured memory_bytes: 12800
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric, std.container, std.range;

void main()
{
    auto N = readln.chomp.to!int;
    auto rs = new int[][N];
    int[] as = [0];
    foreach (i; 1..N) {
        auto a = readln.chomp.to!int-1;
        as ~= a;
        rs[a] ~= i;
    }
    int solve(int i) {
        if (rs[i].empty) return 1;
        int[] cs;
        foreach (j; rs[i]) cs ~= solve(j);
        sort!"a > b"(cs);
        int r;
        foreach (k, c; cs) r = max(r, k.to!int + c + 1);
        return r;
    }
    writeln(solve(0)-1);
}

Measured memory_bytes: 20040
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack> // s.top()
#include <bitset>
#include <queue> // s.front()
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define print(x) cout<<(x)<<endl
#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main(){

	int N;
	cin >> N;
	vector<int> v(N);
	int sum = 0;
	for (int i = 0; i < N; i++) {
		int ipt;
		cin >> ipt;
		v[i] = ipt;
		sum += ipt;
	}
	int right = sum - v[0];
	int left = v[0];
	int out = abs(right - left);
	for (int i = 1; i < N; i++) {
		left += v[i];
		right -= v[i];
		out = min(out, abs(right - left));
	}

	print(out);







	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
#include <set>
#include <vector>
#include <map>
#include <cmath>
#include <algorithm>
#include <memory.h>
#include <string>
#include <sstream>
#include <cstdlib>
#include <ctime>
#include <cassert>

using namespace std;

typedef long long LL;
typedef pair<int,int> PII;

#define MP make_pair
#define PB push_back
#define FF first
#define SS second

#define FORN(i, n) for (int i = 0; i <  (int)(n); i++)
#define FOR1(i, n) for (int i = 1; i <= (int)(n); i++)
#define FORD(i, n) for (int i = (int)(n) - 1; i >= 0; i--)

#define DEBUG(X) { cout << #X << " = " << (X) << endl; }
#define PR0(A,n) { cout << #A << " = "; FORN(_,n) cout << A[_] << ' '; cout << endl; }

#define MOD 1000000007
#define INF 2000000000

int GLL(LL& x) {
    return scanf("%lld", &x);
}

int GI(int& x) {
    return scanf("%d", &x);
}

int k;

vector<LL> a;

LL lo, hi;

LL next_multiple(LL x, LL m)
{
    if (x % m == 0)
    {
        return x;
    }
    else
    {
        return m * (x / m + 1);
    }
}

LL prev_multiple(LL x, LL m)
{
    if (x % m == 0)
    {
        return x;
    }
    else
    {
        return m * (x / m);
    }
}

int main() {
    GI(k);
    a.resize(k);

    FORN(i, k)
    {
        GLL(a[i]);
    }

    lo = hi = 2;

    FORD(i, k)
    {
        lo = next_multiple(lo, a[i]);
        hi = prev_multiple(hi, a[i]) + a[i] - 1;

//        DEBUG(lo);
//        DEBUG(hi);
        if (lo > hi)
        {
            printf("-1\n");
            return 0;
        }
    }

    printf("%lld %lld\n", lo, hi);
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

#define N 8

typedef struct _chess{
  int row[N];
  int col[N];
  int dpos[2*N-1];
  int dneg[2*N-1];
}Chess;

void initialize(Chess);
void putQueen(int);
void print(void);

Chess chess;
int X[N][N];

int main(){
  int i,j;
  int k;
  int r,c;

  initialize(chess);
  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      X[i][j]=0; /* false */
    }
  }

  scanf("%d",&k);
  for(i=0;i<k;i++){
    scanf("%d%d",&r,&c);
    X[r][c]=1; /* true */
  }

  putQueen(0);

  return 0;
}

void initialize(Chess c){
  int i;
  for(i=0;i<N;i++){
    c.row[i]=-1;
    c.col[i]=-1;
  }
  for(i=0;i<2*N-1;i++){
    c.dpos[i]=-1;
    c.dneg[i]=-1;
  }
}

void putQueen(int i) {
  if(i==N){
    /* print */
    print();
    return;
  }

  for(int j=0;j<N;j++){
    if(chess.col[j]==1 ||chess.dpos[i+j]==1 ||chess.dneg[i-j+N-1]==1) continue;
    chess.row[i]=j;
    chess.col[j]=chess.dpos[i+j]=chess.dneg[i-j+N-1]=1;
    putQueen(i+1);
    chess.row[i]=chess.col[j]=chess.dpos[i+j]=chess.dneg[i-j+N-1]=-1;
  }
}

void print(){
  int i,j;

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      if(X[i][j]==1){
        if(chess.row[i]!=j) return;
      }
    }
  }

  for(i=0;i<N;i++){
    for(j=0;j<N;j++){
      printf("%c",(chess.row[i]==j)?'Q':'.');
    }
    printf("\n");
  }
}




Measured memory_bytes: 2148
#include<stdio.h>

#define Q -1
#define WHITE 0
#define N 8

int k;
int board[N][N];
int temp[N];

void search(int, int);

int findr(int);
int find(int, int);
void output();

int main()
{
  int r, c;
  int i, j;

  for(i = 0; i < N; i++)
    {
      temp[i] = 0;
     for(j = 0; j < N; j++)
       {
	 board[i][j] = WHITE;
       }
    }
  
  scanf("%d", &k);
  
  for(i = 0; i < k; i++)
    {
      scanf("%d %d", &r, &c);
      board[r][c] = Q;
      temp[r] = 1;
    }
  
  search(0, 0);

  return 0;
}

int findr(int r)
{
      if(temp[r])
	{
	  return 1;
	}
  return 0;
}

  
int find(int r, int c)
{
  int i, j;

  //縦
  for(i = 0; i < N; i++)
    {
      if(board[i][c] == Q)return 1;
    }
  
  //右上
  for(i = r+1, j = c-1; i >= 0 && j < N; i--, j++)
    {
      if(board[i][j] == Q)return 1;
    }
  //左下
   for(i = r-1, j = c+1; i < N && j >= 0; i++, j--)
    {
      if(board[i][j] == Q)return 1;
    }

   //右下
   for(i = r+1, j = c+1; i < N && j < N; i++, j++)
     {
       if(board[i][j] == Q)return 1;
     }
   //左上
   for(i = r-1, j = c-1; i >= 0 && j >= 0; i--, j--)
     {
       if(board[i][j] == Q)return 1;
     }
  
   return 0;
}

void search(int r, int c)
{
  int j, flag = 1;
  
  if(r == N)
    {
      output();
      return;
    }
  
  if(findr(r))
    {
	  search(r+1, 0);
    }
  else
    {
      for(j = c; j < N; j++)
	{
	  if(find(r, j))continue;
	  
	  board[r][j] = Q;
	  
	  search(r+1, 0);
	  
	  board[r][j] = WHITE;
	}
    }
}

void output()
{
  int i, j;

 for(i = 0; i < N; i++)
    {
     for(j = 0; j < N; j++)
       {
	 //printf("%2d ", board[i][j]);
	 if(board[i][j] == Q)printf("Q");
	 else printf(".");
       }
     printf("\n");
    }
 
 return;
}



Measured memory_bytes: 2112
#include<stdio.h>
#include<string.h>
int main()
{
	int r[17][17]={0},f[17][17]={0},a,b,i,j,k,n;
	for(;scanf("%d%d%d",&a,&b,&n)==3;memset(r,0,1156),memset(f,0,1156))
	{
		for(i=0;i<n;i++)
		{
			scanf("%d%d",&j,&k);
			f[k][j]=1;
		}
		r[1][1]=1;
		for(i=1;i<=b;i++)
			for(j=1;j<=a;j++)
				r[i][j]+=f[i][j]?0:r[i-1][j]+r[i][j-1];
		printf("%d\n",r[b][a]);
	}
	return 0;
}

Measured memory_bytes: 600
#pragma comment(linker, "/stack:20000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx")

#include <stdio.h>
#include <bits/stdc++.h>

using namespace std;

#include <x86intrin.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
template <typename T> using ordered_set = tree<T, null_type, std::less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define all(x) x.begin(), x.end()

#define mp make_pair
#define in insert
#define er erase
#define con continue
#define pb push_back
#define sc scanf
#define pr printf
#define ub upper_bound
#define lb lower_bound
#define s second
#define f first
#define int long long

const long long infl = 1e18; 
const int N = 3e5 + 300, N2 = 2e3, inf = 1e9 + 200;

set <int> S;
vector <int> g;
int n, m, k;
int a[N], x, y;
string ss;

main (){
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	cin >> n >> x >> y;
	for (int i = 1; i <= n; i++){
		cin >> a[i];
	}
	if (n == 1){
		cout << abs(y - a[n]);
	}
	else cout << max(abs(y - a[n]), abs(a[n - 1] - a[n]));
	return 0;
}












Measured memory_bytes: 256
s = str(input())

num = [int(s[-1])]
for i in range(1, len(s)):
    tmp = num[-1] + pow(10, i, 2019) * int(s[-i - 1])
    num.append(tmp % 2019)

mod = [1] + [0] * 2018
ans = 0
for i in num:
    ans += mod[i]
    mod[i] += 1
print(ans)


Measured memory_bytes: 78844
#include <iostream>
#include <algorithm>
#include <vector>
#include <unordered_map>
#include <unordered_set>
#include <cmath>
#include <cstdio>
#include <map>
#include <set>
#include <utility>
#include <string>
#include <functional>
#include <queue>
#include <stack>

using namespace std;

typedef long long ll;
typedef long double ld;


int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin >> n;
    const ll inf = 2e9;
    vector<vector<ll>> dis(n, vector<ll> (n));
    int i, j, k;
    ll ans = 0;
    for(i = 0; i < n; i++) {
        for(j = 0; j < n; j++) {
            cin >> dis[i][j];
            ans += dis[i][j];
        }
    }
    for(i = 0; i < n; i++) {
        for(j = 0; j < n; j++) {
            if(dis[i][j] != dis[j][i]) {
                cout << -1;
                return 0;
            }
        }
    }
    ans /= 2;
    for(i = 0; i < n; i++) {
        for(j = i + 1; j < n; j++) {
            bool f = false;
            for(k = 0; k < n; k++) {
                if(k != i && k != j) {
                    if(dis[i][k] + dis[k][j] < dis[i][j]) {
                        cout << -1;
                        return 0;
                    }
                    else if(dis[i][k] + dis[k][j] == dis[i][j]) {
                        f = true;
                        break;
                    }
                }
            }
            if(f) {
                ans -= dis[i][j];
            }
        }
    }
    cout << ans;

    return 0;
}



Measured memory_bytes: 1024
#include <stdio.h>
#include <stdlib.h>

int main()
{int i;
char S[7];
gets(S);

{

if(S[0]=='S')
 {

  printf("Cloudy\n");}
 else if(S[0]=='R')
 {

  printf("Sunny\n");}
else
{

  printf("Rainy\n");}}
    return 0;
}

Measured memory_bytes: 128
using System;

namespace A___Painting
{
    class Program
    {
        static void Main (string[] args)
        {
            var h = int.Parse (Console.ReadLine ());
            var w = int.Parse (Console.ReadLine ());
            var n = int.Parse (Console.ReadLine ());
            var min = Math.Min (h, w);
            var max = Math.Max (h, w);
            var ans = 0;
            for (var i = 1; i <= min; i++)
            {
                ans++;
                if (i * max >= n)
                {
                    Console.WriteLine (ans);
                    break;
                }
            }
        }
    }
}

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


using namespace std;
typedef long long ll;

#define REP(i,n) for(ll i=0; i<ll(n); i++)
#define FOR(i,m,n) for(int i=int(m); i<int(n); i++)
#define ALL(obj) (obj).begin(),(obj).end()
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

const int  INF = 1 << 29;
const ll INFL = 1LL << 60;
const ll mod = 1000000007;



int main() {

	int h, n;
	cin >> h >> n;

	vector<int> a(n);
	REP(i, n)cin >> a[i];

	sort(ALL(a));
	reverse(ALL(a));

	REP(i, n) {
		h -= a[i];
		if (h <= 0) {
			cout << "Yes" << endl;
			return 0;
		}
	}
	cout << "No" << endl;

}

Measured memory_bytes: 640
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
	public static void main(String[] args) {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line;
		String in[] = new String[2];
		int a= 0, b = 0;
		try {
			line = br.readLine();
			in = line.split(" ");
			a = Integer.parseInt(in[0]);
			b = Integer.parseInt(in[1]);
		} catch (IOException e) {
			e.getStackTrace();
		}
		
		double ans = (a + b) /2.0;
		double x = Math.ceil(ans);
		if(ans == x) {
			System.out.println((int)x);
		} else {
			System.out.println("IMPOSSIBLE");
		}
	}
}

Measured memory_bytes: 21332
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int H = NextInt();
        int W = NextInt();
        int case1 = INF;
        {
            int x1 = (W / 3);
            int x2 = x1 + 1;
            if (H % 2 == 0)
            {
                case1 = Math.Abs((H / 2) * (W - x1) - H * x1);
                case1 = Math.Min(case1, Math.Abs((H / 2) * (W - x2) - H * x2));
            }
            else
            {
                int sc1 = (H / 2) * (W - x1);
                int sc2 = ((H / 2) + 1) * (W - x1);
                case1 = Math.Max((H * x1), Math.Max(sc1, sc2)) - Math.Min((H * x1), Math.Min(sc1, sc2));
                sc1 = (H / 2) * (W - x2);
                sc2 = ((H / 2) + 1) * (W - x2);
                case1 = Math.Min(case1, Math.Max((H * x2), Math.Max(sc1, sc2)) - Math.Min((H * x2), Math.Min(sc1, sc2)));

            }
        }
        int case2 = INF;
        {
            int x1 = (H / 3);
            int x2 = x1 + 1;
            if (W % 2 == 0)
            {
                case2 = Math.Abs((W / 2) * (H - x1) - W * x1);
                case2 = Math.Min(case2, Math.Abs((W / 2) * (H - x2) - W * x2));
            }
            else
            {
                int sc1 = (W / 2) * (H - x1);
                int sc2 = ((W / 2) + 1) * (H - x1);
                case2 = Math.Max((W * x1), Math.Max(sc1, sc2)) - Math.Min((W * x1), Math.Min(sc1, sc2));
                sc1 = (W / 2) * (H - x2);
                sc2 = ((W / 2) + 1) * (H - x2);
                case2 = Math.Min(case2, Math.Max((W * x2), Math.Max(sc1, sc2)) - Math.Min((W * x2), Math.Min(sc1, sc2)));

            }
        }
        int case3 = INF;
        {
            if (H % 3 == 0) case3 = 0;
            else case3 = W;
        }
        int case4 = INF;
        {
            if (W % 3 == 0) case4 = 0;
            else case4 = H;
        }
        Console.WriteLine(Math.Min(Math.Min(case4, case3), Math.Min(case2, case1)));
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    private static void Confirm() { if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(queue.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(queue.Dequeue()); }
    public static string NextString() { Confirm(); return queue.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(queue.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
}


Measured memory_bytes: 11348
n=int(input())
if n==1:
  print(0)
  exit()
def pf(n):
    a = []
    N = n
    for i in range(2, int(pow(N,0.5)//1+2)):
        if n%i==0:
            count=0
            while n%i==0:
                count+=1
                n //= i
            a.append([i,count])
    if n!=1:
        a.append([n,1])
    if a==[]:
        a.append([n,1])
    return a
l=pf(n)
ans=0
ll=len(l)
for i in range(ll):
  x,y=l[i][0],l[i][1]
  ans+=int((-1+pow(1+8*y,0.5))/2)
print(ans)

Measured memory_bytes: 9504
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <algorithm>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
 
 
int main() {
    int N, n;
    cin >> N;
    n = N;
    int s = 0;
    while (n > 0) {
        s += (n % 10);
        n = n / 10;
    }
    if (N % s == 0) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0; i<(int)(n); i++)
#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[])
{
  ll N, M; cin >> N >> M;
  vecll Hs(N+1), Hr(N+1);
  RNG(i, 1, N+1) {
    Hr[i] = 1;
    cin >> Hs[i];
  }
  ll A, B;
  REP(i, M) {
    cin >> A >> B;
    if (Hs[A] > Hs[B]) {
      Hr[B] = 0;
    } else if (Hs[A] < Hs[B]) {
      Hr[A] = 0;
    } else {
      Hr[A] = 0;
      Hr[B] = 0;
    }
  }
  ll res = 0;
  RNG(i, 1, N+1) {
    if (Hr[i] == 1) res++;
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 4848
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <cmath>
using namespace std;

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

struct BIT {
  int n;
  vector<int> xs;
  BIT (int n) : n(n) {
    xs.resize(n+1);
  }
  void add(int i, int v) {
    for (int x=i+1; x<=n; x+=x&-x) xs[x] += v;
  }
  int sum(int i) {
    int s = 0;
    for (int x=i+1; x>0; x-=x&-x) s += xs[x];
    return s;
  }
  int sum(int a, int b) {
    return sum(b) - sum(a-1);
  }
};

int N, M;
vector<P> X[100001];

signed main() {
  ios::sync_with_stdio(false); cin.tie(0);
  cin >> N >> M;
  rep(i, N) {
    int l, r;
    cin >> l >> r;
    X[r-l].pb(P(l, r));
  }
  int x = N;
  BIT bit(M+1);
  for (int d=1; d<=M; d++) {
    int s = x;
    for (int i=0; i<=M; i+=d) s += bit.sum(i);
    cout << s << "\n";
    for (P &p : X[d-1]) {
      bit.add(p._1, 1);
      bit.add(p._2+1, -1);
      x--;
    }
  }
  return 0;
}


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

int main() {
  int H, W;
  cin >> H >> W;
  vector<vector<int>> c(10,vector<int>(10));
  rep(i, 0, 10) rep(j, 0, 10) cin >> c[i][j];
  rep(k, 0, 10) rep(i, 0, 10) rep(j, 0, 10)
    c[i][j] = min(c[i][j], c[i][k] + c[k][j]);
  int ans = 0;
  rep(i, 0, H) rep(j, 0, W) {
    int a; cin >> a;
    if(a == -1) continue;
    ans += c[a][1];
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
 
int main(void){
	int n1, n2, n3, m, i;
	scanf("%d\n",&m);
	for(i = 0;i < m;i++) {
		scanf("%d %d %d",&n1,&n2,&n3);
		if(n1 * n1 + n2 * n2 == n3 * n3 || n1 * n1 + n3 * n3 == n2 * n2 || n2 * n2 + n3 * n3 == n1 * n1)
			printf("YES\n");
		else
			printf("NO\n");
		}
	return 0;
}

Measured memory_bytes: 580
#include <bits/stdc++.h>
using namespace std;
int main() {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> table(H, vector<char>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            cin >> table.at(i).at(j);
        }
    }
    
    vector<vector<int>> memo(H, vector<int>(W));
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (table.at(i).at(j) == '#') memo.at(i).at(j) = -1;
        }
    }
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (memo.at(i).at(j) == -1) {
                for (int tate = -1; tate <= 1; tate++) {
                    if ((tate==-1 && i==0) || (tate==1 && i==H-1)) continue;
                    for (int yoko = -1; yoko <= 1; yoko++) {
                        if ((yoko==-1 && j==0) || (yoko==1 && j==W-1)) continue;
                        if (tate==0 && yoko==0) continue;
                        if (memo.at(i+tate).at(j+yoko) != -1) memo.at(i+tate).at(j+yoko)++;
                    }
                }
            }
        }
    }
    
    for (int i = 0; i < H; i++) {
        for (int j = 0; j < W; j++) {
            if (memo.at(i).at(j) == -1) cout << '#';
            else cout << memo.at(i).at(j);
            if (j == W-1) cout << endl;
        }
    }

}

Measured memory_bytes: 256