akhauriyash/Code-Regression huggingface dataset:
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int x1, y1, x2, y2;
    scan(x1, y1, x2, y2);
    int dx = x2 - x1, dy = y2 - y1;
    int x3 = x2 - dy, y3 = y2 + dx;
    int x4 = x3 - dx, y4 = y3 - dy;
    writefln("%s %s %s %s", x3, y3, x4, y4);
}





void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
typedef double DOUBLE;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const ll LL_INF = 1e17 + 10;
const int INF = 1e9 + 10;
const ll MOD = 1e9 + 7;

const int MAXN = 300 + 5;

char g[MAXN][MAXN];

int ans[MAXN][MAXN];

void solve(){
	int n, m, k;
	scanf("%d%d%d", &n, &m, &k);
	REPN(i, 1, n) {
		scanf("%s", &g[i][1]);
	}
	int last = 0, cnt = 1;
	REPN(i, 1, n) {
		int lastj = 0;
		REPN(j, 1, m) {
			if (g[i][j] == '#') {
				lastj = j;
			}
		}
		if (lastj) {
			REPN(j, 1, lastj) {
				ans[i][j] = cnt;
				if (g[i][j] == '#') {
					cnt++;
				}
			}
			REPN(j, lastj + 1, m) {
				ans[i][j] = ans[i][lastj];
			}
		}
	}
	REPN(i, 1, n) {
		if (ans[i][1] == 0) {
			int ii = 0;
			REPN(j, i + 1, n) {
				if (ans[j][1]) {
					ii = j;
					break;
				}
			}
			if (!ii) {
				for(int j = i - 1; j >= 1; j--) {
					if (ans[j][1]) {
						ii = j;
						break;
					}
				}
			}
			REPN(j, 1, m) {
				ans[i][j] = ans[ii][j];
			}
		}
	}
	REPN(i, 1, n) {
		REPN(j, 1, m) {
			printf("%d ", ans[i][j]);
		}
		putchar('\n');
	}
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 1280
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <sstream>
#include <string>
#include <cstring>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdlib>
#include <ctime>
#include <numeric>
#include <functional>
#include <cctype>
#include <list>
#include <limits>
#include <cassert>
#include <random>
#include <time.h>
//#include <boost/multiprecision/cpp_int.hpp>



using namespace std;
using Int = long long;
//using namespace boost::multiprecision;

const double EPS = 1e-10;
long long const MOD = 1000000007;

long long mod_pow(long long x, long long n) {
    long long res = 1;
    for (int i = 0;i < 60; i++) {
        if (n >> i & 1) res = res * x % MOD;
        x = x * x % MOD;
    }
    return res;
}

template<typename T>
T gcd(T a, T b) {
    return b != 0 ? gcd(b, a % b) : a;
}

template<typename T>
T lcm(T a, T b) {
    return a * b / gcd(a, b);
}

void fastInput() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

vector<Int> left_sum;
vector<Int> right_sum;

int main(void) {
    int N; cin >> N;
    vector<Int> A(N+5);
    for (int i = 1; i <= N; i++) {
        cin >> A[i];
    }

    left_sum = vector<Int> (N+1);
    right_sum = vector<Int> (N+1);
    for (int i = 1; i <= N; i++) {
        left_sum[i] = A[i];
        left_sum[i] += left_sum[i-1];
    }
    for (int i = 1; i <= N; i++) {
        right_sum[i] = A[N+1-i];
        right_sum[i] += right_sum[i-1];
    }

    Int INF = 1e16;
    Int ans = INF;
    for (int i = 2; i <= N-2; i++) {
        int P = (int)(lower_bound(left_sum.begin(), left_sum.end(), left_sum[i]/2) - left_sum.begin());
        int S = (int)(lower_bound(right_sum.begin(), right_sum.end(), right_sum[N-i]/2) - right_sum.begin());

        for (int j = P-1; j <= P+1; j++) {
            for (int k = S-1; k <= S+1; k++) {
                if (j <= 0 || i - j <= 0 || k <= 0 || N-i - k <= 0) continue;
                Int tmp = max({left_sum[j], left_sum[i] - left_sum[j], right_sum[k], right_sum[N-i] - right_sum[k]}) - min({left_sum[j], left_sum[i] - left_sum[j], right_sum[k], right_sum[N-i] - right_sum[k]});
                ans = min(tmp, ans);
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <functional>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (size_t i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> void read_n(T a[], size_t n, size_t o = 0)
{ for (size_t i=o; i<n+o; ++i) cin >> a[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

i64 x;
int main() {
  cin >> x;
  i64 d = x / 100, r = x % 100;
  bool f = r <= 5 * d;
  cout << f << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int r = sc.nextInt();
		int d = sc.nextInt();
		long x = sc.nextLong();
		for(int i = 0; i < 10; i++) {
			x = r * x - d;
			System.out.println(x);
		}
	}

}


Measured memory_bytes: 21844
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();
    
    if(a<=8&&b<=8){
      System.out.println("Yay!");
    }else{
      System.out.println(":(");
    }
  }
}

Measured memory_bytes: 35688
from collections import defaultdict
from sys import stdin, stdout

int_in = lambda: int(stdin.readline())
arr_in = lambda: [int(x) for x in stdin.readline().split()]
mat_in = lambda rows: [arr_in() for _ in range(rows)]
str_in = lambda: stdin.readline().strip()
out = lambda o: stdout.write("{}\n".format(o))
arr_out = lambda o: out(" ".join(map(str, o)))
bool_out = lambda o: out("YES" if o else "NO")
tests = lambda: range(1, int_in() + 1)
case_out = lambda i, o: out("Case #{}: {}".format(i, o))


# https://atcoder.jp/contests/abc171/tasks/abc171_d
def solve(n, a, q, bc):
    buckets = defaultdict(int)
    for item in a:
        buckets[item] += 1
    curr_sum = sum(a)
    result = []
    for b, c in bc:
        curr_sum -= b * buckets[b]
        curr_sum += c * buckets[b]
        buckets[c] += buckets[b]
        buckets[b] = 0
        result.append(curr_sum)
    return result


if __name__ == "__main__":
    n = int_in()
    a = arr_in()
    q = int_in()
    bc = mat_in(q)
    for row in solve(n, a, q, bc):
        out(row)

Measured memory_bytes: 108456
def warshall_floyd(d):
    # d[i][j]: The shortest distance from i to j
    n = len(d)
    for k in range(n):
        for i in range(n):
            for j in range(n):
                d[i][j] = min(d[i][j], d[i][k] + d[k][j])
    return d


h, w = map(int, input().split())

c = [[] for _ in range(10)]
a = [[] for _ in range(h)]

for i in range(10):
    c[i] = list(map(int, input().split()))

for i in range(h):
    a[i] = list(map(int, input().split()))

warshall_floyd(c)

ans = 0
for i in range(h):
    for j in range(w):
        if a[i][j] != -1 and a[i][j] != 1:
            ans += c[a[i][j]][1]

print(ans)



Measured memory_bytes: 74080
N = int(input())
ss = []
for i in range(N):
	ss.append("".join(sorted(list(input()))))
	
dicS = {}
for s in ss:
	if s not in dicS:
		dicS[s] = 1
	else:
		dicS[s] += 1
		
#print(dicS)
		
ans = 0
for v in dicS.values():
	if v != 1:
		ans += int((v*(v-1))/2)
	
print(ans)

Measured memory_bytes: 19504
def tsumo?(a)
    g = Hash[*a.group_by(&:itself).map {|k, s| [k, s.size]}.flatten]
    return false if g.values.max > 4
    return g.keys.any? {|i| f1(g, i)}
end

def f1(g, i)
    return false if g[i] == 1
    h = g.dup
    h[i] -= 2
    h.delete(i) if h[i] == 0
    return f2(h)
end

def f2(g)
    return true if g.empty?
    i = g.keys.min
    if g[i] >= 3
        h = g.dup
        h[i] -= 3
        h.delete(i) if h[i] == 0
        return true if f2(h)
    end
    if g[i] && g[i+1] && g[i+2]
        h = g.dup
        h[i] -= 1
        h[i+1] -= 1
        h[i+2] -= 1
        h.delete(i) if h[i] == 0
        h.delete(i+1) if h[i+1] == 0
        h.delete(i+2) if h[i+2] == 0
        return true if f2(h)
    end
    return false
end

while l = gets
    a = l.chomp.split("").map(&:to_i)
    ans = (1..9).select {|i| tsumo?(a + [i])}
    puts ans.empty? ? '0' : ans * ' '
end



Measured memory_bytes: 7348
import java.util.Scanner;

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

        int a = sc.nextInt();
        int b = sc.nextInt();
        int c = sc.nextInt();
        int d = sc.nextInt();
        int e = sc.nextInt();
        int k = sc.nextInt();

        if(
                e-a <= k
        ) {
            System.out.println("Yay!");
        } else {
            System.out.println(":(");
        }
    }
}

Measured memory_bytes: 22740
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// Edge :
type Edge struct {
	from, to, cost int
}

// Route :
type Route struct {
	path []int
}

// ベルマンフォード法
func bellmanFord2(N, S int, edges []Edge) ([]int, []Route, bool) {
	d := make([]int, N+1)
	for i := 0; i <= N; i++ {
		d[i] = -math.MaxInt64
	}
	d[S] = 0
	r := make([]Route, N+1)
	r[S].path = []int{S}

	negativeLoop := false
	for i := 0; i <= N; i++ {
		for _, e := range edges {
			if d[e.to] < d[e.from]+e.cost {
				d[e.to] = d[e.from] + e.cost
				r[e.to].path = append(r[e.from].path, e.to)
				if i == N {
					negativeLoop = true
				}
			}
		}
	}

	return d, r, negativeLoop
}

const inf = math.MaxInt64 >> 10

// ベルマンフォード法
func bellmanFord(N, S int, edges []Edge) ([]int, bool) {
	d := make([]int, N+1)
	for i := 0; i <= N; i++ {
		d[i] = inf
	}
	d[S] = 0

	for i := 0; i <= N; i++ {
		for _, e := range edges {
			if d[e.from] == inf {
				continue
			}
			if d[e.to] > d[e.from]+e.cost {
				d[e.to] = d[e.from] + e.cost
			}
		}
	}

	negativeLoop := false
	for i := 0; i <= N; i++ {
		for _, e := range edges {
			if d[e.from] == inf {
				continue
			}
			if d[e.to] > d[e.from]+e.cost {
				d[e.to] = d[e.from] + e.cost
				if e.to == N || e.from == N {
					negativeLoop = true
				}
			}
		}
	}

	return d, negativeLoop
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M := getInt(), getInt()
	edges := make([]Edge, M)
	for i := 0; i < M; i++ {
		f, t, c := getInt(), getInt(), getInt()
		edges[i] = Edge{f, t, -c}
	}
	S, D := 1, N

	// ここから
	d, negativeLoop := bellmanFord(N, S, edges)

	if negativeLoop == true {
		out("inf")
	} else {
		out(-d[D])
	}

}


Measured memory_bytes: 768
n=int(input())
l=[]
for i in range(n):
  s,p=[x for x in input().rstrip().split()]
  l.append([s,int(p),i+1])
l.sort(key=lambda x:x[1],reverse=True)
l.sort(key=lambda x:x[0])

for s,p,i in l:
  print(i) 


Measured memory_bytes: 3060
N=int(input())
S=[input() for i in range(N)]
m=len([s for s in S if s[0]=='M'])
a=len([s for s in S if s[0]=='A'])
r=len([s for s in S if s[0]=='R'])
c=len([s for s in S if s[0]=='C'])
h=len([s for s in S if s[0]=='H'])
count=0
march=[m,a,r,c,h]
for x in range(0,3):
    for y in range(x+1,4):
          for z in range(y+1,5):
                count+=march[x]*march[y]*march[z]
print(count)

Measured memory_bytes: 10540
#include <bits/stdc++.h>
using namespace std;
long long c[200001];
int h[200001];
long long max_v;
int n;
int lowbit(int x)
{
	return x&-x;
}
void updatemax(int index,long long value)
{
	while(index<=n)
	{
		c[index]=max(c[index],value);
		index+=lowbit(index);
	}
}
long long maxrange(int index)
{
	long long ret=0;
	while(index)
	{
		ret=max(ret,c[index]);
		index-=lowbit(index);
	}
	return ret;
}
int main()
{
	int i;
	long long a,t;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
		scanf("%d",&h[i]);
	for(i=1;i<=n;i++)
	{
		scanf("%lld",&a);
		t=maxrange(h[i]-1)+a;
		updatemax(h[i],t);
		max_v=max(max_v,t);
	}
	printf("%lld",max_v);
	return 0;
}

Measured memory_bytes: 2688
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N; cin >> N;
    vector<int> d(N);
    for(int i = 0; i<N; i++){
        cin>>d[i];
    }
    sort(d.begin(),d.end());
    cout  <<  d[N/2] -d[N/2-1] << endl;
}


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

int main(){
    int N;
    cin >> N;
    int A[2][N];
    for(int i=0;i<2;++i){
        for(int j=0;j<N;++j){
            cin >> A[i][j];
        }
    }
    int res[N]={0};
    int res_end=0;
    int tmp=0;
    int res_pas=A[0][0]+A[1][N-1];
    int res_ini=A[0][0]+A[1][N-1];
        for(int j=1;j<N;++j){
            res_ini+=A[0][j];
        }
        int dif_res[N]={0};
        for(int j=0;j<N-1;++j){
            if(A[1][j]>A[0][j+1]){
                dif_res[j]=j;
            }
        }
        int cor_dif_res[N]={0};
        int num_cor=0;
        sort(dif_res,dif_res+N,greater<int>());
        for(int j=0;j<N-1;++j){
            if(dif_res>0){
                ++num_cor;
            }
            else{
                break;
            }
        }
        for(int j=0;j<num_cor;++j){
            cor_dif_res[j]=dif_res[j];
        }
        
        for(int i=0;i<num_cor;++i){
            for(int j=0;j<N-1;++j){
            if(j<cor_dif_res[i]){
                res[i]+=A[0][j+1];
            }
            else{
                res[i]+=A[1][j];
            }
        }
        }
        sort(res,res+N,greater<int>());
        res[0]+=A[0][0]+A[1][N-1];
        if(res[0]>=res_ini){
            res_end=res[0];
        }
        else{
            res_end=res_ini;
        }
        cout << res_end<<endl;
}

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

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

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

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

signed main() {
	set<P> ch;
  ll n, a, b;
  rep(j, 2) {
    cin >> n;
    rep(i, n) {
      cin >> a >> b;
      ch.insert(make_pair(a, b));
    }
  }
  ll i = 0;
  for(auto x = ch.begin(); x != ch.end(); x++) {
    if(i) cout << " " ;
    i++;
    cout << x->first << ':';
    if(x->second < 10) cout << 0;
    cout << x->second;
  }
  cout << endl;
	return 0;
}


Measured memory_bytes: 3176
n = int(input())
a = list(map(int, input().split()))

aMax = max(a)

answer = 0
countOld = 0

for i,v in enumerate(a):
    if i != 0:
        count = 0
        count = a[i-1] + countOld - v
        if count < 0:
            count = 0
        answer += count
        countOld = count

print(answer)


Measured memory_bytes: 32236
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define M_PIl   3.141592653589793238462643383279502884L

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    ll n;
    cin>>n;
    ll a[n];
    
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    
    ll _max=0,_min=1000000001;
    
    for(int i=0;i<n;i++){
        
        _max = max(_max,a[i]);
        _min = min(_min,a[i]);
    }
    
    cout<<abs(_max-_min)<<"\n";
    
    return 0;
}

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

using namespace std;

typedef long long ll;

const int maxN = 1e4 + 1;
int main(){
	int a[maxN] = {0};
	bool para = false;
	for(int x = 1; x < 100; x++){
		for(int y = 1; y < 100; y++){
			for(int z = 1; z < 100; z++){
				int cur = x * x + y * y + z * z + x * y + y * z + z * x;
				if(cur < maxN) a[cur]++;
			}
		}
	}
	int n; 
	cin >> n;
	for(int i = 1; i <= n; i++){
		cout << a[i] << '\n';
	}
}


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

int main() {
  int64_t A, B, K;
  cin >> A >> B >> K;
  
  if(K <= A){
    cout << (A - K) << ' ' << B << endl;
  }else if (K <= A + B){
    cout << 0 << ' ' << (A + B - K) << endl;
  }else{
    cout << 0 << ' ' << 0 << endl;
  }
}


Measured memory_bytes: 3624
def new_pow(x, n):
    C = 10**9+7
    
    if n == 0:
        return 1
    
    if n:
        return new_pow(x*x%C, n//2) * (x if n % 2 else 1) % C
    
m, n = map(int,input().split())
print(new_pow(m,n))

Measured memory_bytes: 7668
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define trep(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
int main(){
    int a, b;
    cin >> a >> b;
    if((a*b)%2==0){
        cout << "Even" << endl;
    }else{
        cout << "Odd" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <complex>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#include <functional>
#include <cstring>
#include <regex>
#include <random>
#include <cassert>
#include <stack>
#include <climits>
#include <chrono>
using namespace std;

#pragma region

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, s, n) for (int i = (s); i < (int)(n); i++)
#define revrep(i, n) for (int i = (n) - 1; i >= 0; i--)
#define revrepr(i, s, n) for (int i = (n) - 1; i >= s; i--)
#define debug(x) cerr << #x << ": " << x << "\n"
#define popcnt(x) __builtin_popcount(x)

const double PI = acos(-1.0);

using ll = long long;
using P = pair<int, int>;

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

template<class T>
istream& operator >>(istream &is, vector<T> &v) {
    for (int i = 0; i < (int)v.size(); i++) cin >> v.at(i);
    return is;
}

template<class T, class U>
ostream& operator <<(ostream &os, pair<T, U> p) {
    cout << '(' << p.first << ", " << p.second << ')';
    return os;
}

template<class T>
void print(const vector<T> &v, const string &delimiter = " ") { rep(i, v.size()) cout << (0 < i ? delimiter : "") << v.at(i); cout << endl; }

template<class T>
void print(const vector<vector<T>> &vv, const string &delimiter) { for (const auto &v: vv) print(v, delimiter); }

#pragma endregion

template<class T>
struct BIT {
    int n;
    vector<T> dat;

    //[1, n]
    BIT(int n): n(n), dat(n + 1) {}

    void init(int _n) {
        n = _n;
        dat.assign(_n);
    }

    //[1, i]
    T sum(int i) const {
        T s = 0;
        while (i > 0) {
            s += dat[i];
            i -= i & -i;
        }
        return s;
    }

    //[l, r]
    T sum(int l, int r) const {
        return sum(r) - sum(l - 1);
    }

    //1-indexed
    void add(int i, T x) {
        while (i <= n) {
            dat[i] += x;
            i += i & -i;
        }
    }
};

struct Query {
    int l, r, idx;
    bool operator <(const Query &q) { return r < q.r; }
};

int main() {
    int n, q;
    cin >> n >> q;
    vector<int> c(n);
    cin >> c;

    vector<Query> querys(q);
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        querys[i] = Query{l, r, i};
    }

    sort(querys.begin(), querys.end());
    
    BIT<int> bit(n);
    vector<int> last(n + 1, -1);
    vector<int> ans(q);

    int p = 0;
    rep(i, q) {
        auto [l, r, idx] = querys[i];
        while (p < n && p < r) {
            bit.add(p + 1, 1);
            if (last[c[p]] != -1) bit.add(last[c[p]] + 1, -1);
            last[c[p]] = p;
            p++;
        }

        ans[idx] = bit.sum(l, r);
    }

    print(ans, "\n");
}

Measured memory_bytes: 17372
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll maxx = 1e5+1;
const ll mod = 1e9 + 7;
int dp[maxx][101][2];
string s;
int d;
int Size;
int rec(int pos,int remainder,int exceeds,int number){
		if(pos==Size){
			if(remainder==0){
			 //cout << number << "\n";
			 return 1;
		  }
		  return 0;
		}
		if(dp[pos][remainder][exceeds]!=-1)	return dp[pos][remainder][exceeds];
		int ans = 0;
		if(pos==0){
			for(int i = 0;i <=(int)(s[pos]-48);i ++){ // is pos is 0 then iterate upto s[pos] only .
				ans = ans + rec(pos+1,(remainder+i)%d,((int)(s[pos]-48))==i,number*10+i);
				if(ans>=mod)
					ans-=mod;
			}
		}else{
			for(int i = 0 ;i <=9 ; i ++){
				if(exceeds){ // if prev limit is reached then iterate upto current's limit .
				if(i<=((int)(s[pos] - 48))){
				    ans = ans + rec(pos+1,(remainder + i)%d,((int)(s[pos]-48)==i),number*10+i);
				    if(ans>=mod)
					 ans-=mod;
					}
				}
				else{ // else iterate all digits from 0 to 9.
					 ans = ans + rec(pos+1,(remainder + i)%d,0,number*10+i);
				   if(ans>=mod)
					ans-=mod;
				}
			}
		}
		return  dp[pos][remainder][exceeds]=ans; // memoization
}



int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> s;
	cin >> d;
	Size = s.size();
	memset(dp,-1,sizeof dp);
	cout << (rec(0,0,0,0) - 1 + mod)%mod  << "\n";
}


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

int main(){

  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;

  int max_len;
  max_len = e - a;
  
  if (max_len <= k) cout << "Yay!" << endl;
  else cout << ":(" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

int main(void)
{
    int A, B;
    string S;
    bool flag = true;
    cin >> A >> B;
    cin >> S;
    for (int i = 0; i <= A + B; i++)
    {
        if ((i == A && S[i] != '-') || (i != A && S[i] == '-'))
        {
            flag = false;
            break;
        }
    }
    cout << ( (flag) ? "Yes" : "No") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using pp=pair<int,int>;

int main() {
  int N, doubt=0, M=0;
  cin >> N;
  vector<vector<pp>> V(N, vector<pp>(0));
  
  int A, p, q;
  
  for (int i=0; i<N; i++) {
    cin >> A;
    for (int j=0; j<A; j++) {
      cin >> p >> q;
      V[i].push_back(pp(p,q));
    }
  }
  
  for (int b=0; b<(1<<N); b++) {
    bitset<15> s(b);
    vector<int> W(N);
    doubt=0;
    
    for (int i=0; i<N; i++) {
      W[i]=s.test(i);
      //cout << W[i] << endl;
    }
    
    for (int i=0; i<N; i++) {
      if (s.test(i)) {
        for (int j=0; j<(int)V[i].size(); j++) {
          int x=V[i][j].first, y=V[i][j].second;
          if (W[x-1]!=y) {
            doubt=1;
            break;
          }
        }
        if (doubt==1) {break;}
      }
    }
    if (doubt==0) {
      int rr=0;
      for (int i=0; i<N; i++) {
        rr+=s.test(i);
      }
      M=max(M, rr);
      //cout << M << endl;
    }
  }
  cout << M << endl;
}

Measured memory_bytes: 3608
# Integer Square Root
# Param::  positive integer n
# Return:: integer part of the square root of n
#  i.e. the number m s.t. m ** 2 <= n < (m + 1) ** 2
def isqrt(n)
	x = 1 << (((n.to_s(2).size - 1) >> 1) + 1)

	loop do
		# Newtonian step
		next_x = (x + n / x) >> 1
		return x if x <= next_x

		x = next_x
	end
end

def eratosthenes_sieve(n)
	return to_enum(:eratosthenes_sieve, n) unless block_given?

	return if n < 2

	yield 2
	return if 2 == n

	yield 3

	# make list for sieve
	sieve_len_max = (n + 1) >> 1
	sieve = [true, false, true]
	sieve_len = 3
	k = 5
	i = 2
	while sieve_len < sieve_len_max
		if sieve[i]
			yield k
			sieve_len *= k
			if sieve_len_max < sieve_len
				sieve_len /= k
				# adjust sieve list length
				sieve *= sieve_len_max / sieve_len
				sieve += sieve[0...(sieve_len_max - sieve.size)]
				sieve_len = sieve_len_max
			else
				sieve *= k
			end

			i.step(sieve_len - 1, k) do |j|
				sieve[j] = false
			end
		end

		k += 2
		i += 1
	end

	# sieve
	limit = (isqrt(n) - 1) >> 1
	while i <= limit
		if sieve[i]
			yield k = (i << 1) + 1
			j = (k ** 2) >> 1
			while j < sieve_len_max
				sieve[j] = false
				j += k
			end
		end

		i += 1
	end

	# output result
	limit = (n - 1) >> 1
	while i <= limit
		yield((i << 1) + 1) if sieve[i]
		i += 1
	end
end

def bisect_right(list, item, lo = 0, hi = list.size)
	while lo < hi
		i = (lo + hi - 1) >> 1

		if 0 < (list[i] <=> item)
			hi = i
		else
			lo = i + 1
		end
	end

	return lo
end

nums = $<.each_line.map(&:to_i)

primes = eratosthenes_sieve(nums.max).to_a
nums.each do |n|
	p bisect_right(primes, n)
end

Measured memory_bytes: 14868
#include <iostream>
#include <vector>
#include <sstream>
#include <string>
#include <algorithm>
#include <set>
#include <limits>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cstdlib>

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define all(x) (x).begin(),(x).end()
#define SORT(v) sort((v).begin(), (v).end())
#define REVERSE(v) reverse((v).begin(), (v).end())


using namespace std;

int main(){
	int n,nt,nx,ny;
	bool h=false;
	int t[100000],x[100000],y[100000];
	cin>>n;
	REP(i,n){
		cin>>t[i]>>x[i]>>y[i];
	}

	REP(i,n){
		if(i!=0){
			nt=t[i]-t[i-1];
			nx=x[i]-x[i-1];
			nx=abs(nx);
			ny=y[i]-y[i-1];
			ny=abs(ny);
		}else{
			nt=t[i];
			nx=x[i];
			nx=abs(nx);
			ny=y[i];
			ny=abs(ny);
		}
		if(nt<nx+ny){
			break;
		}
		if(nt>nx+ny){
			nt=nt-(nx+ny);
			if(nt%2!=0){
				break;
			}
		}
		if(i==n-1){
			h=true;
		}
	}

	if(h==true){
		cout<<"Yes"<<endl;
	}else{
		cout<<"No"<<endl;
	}

	return 0;
}

Measured memory_bytes: 1408
fn main() {
    let n: i32 = read();
    let m: i32 = read();

    let ans = (n-1) * (m-1);
    println!("{}", ans);
}



use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed toparse token")
}

Measured memory_bytes: 4352
#include <stdio.h>

int main(void){
		int a[10]={0},i,o,temp;
		for(i=0;i<10;i++){
			scanf("%d",&a[0]);
			o=0;
			while(a[o] > a[o+1]){
				temp=a[o];
				a[o]=a[o+1];
				a[o+1]=temp;
				o++;
				if(o==9)
					break;
			}
		}o=9;
		printf("%d\n%d\n%d\n",a[9],a[8],a[7]);
		return 0;
}

Measured memory_bytes: 600
import Data.List

f :: String->Bool
f x=(head x) `elem` "MARCH"

f2 :: [Integer]->[Integer]->Integer
f2 (a:b:c:[]) _ =a*b*c
f2 _ []=0
f2 xs (y:ys)=(f2 (y:xs) ys) + (f2 xs ys)

main =do
      x<-getLine
      y<-getContents
      let ys=map head $ filter f $ lines y
          zs=map fromIntegral $ map length $ group $ sort ys
      print $ f2 [] zs

Measured memory_bytes: 12668
S = list(input())
S = list(set(S))

n,w,s,e = 0,0,0,0
for i in range(len(S)):
  if(S[i] == 'N'): n = 1
  elif(S[i] == 'W'): w = 1 
  elif(S[i] == 'S'): s = 1 
  elif(S[i] == 'E'): e = 1
    
judge = [n,w,s,e]
if((judge == [1,0,1,0])or(judge == [0,1,0,1])or(judge == [1,1,1,1])):
  print('Yes')
else:
  print('No')
  

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;

namespace abc170
{
    class Program
    {
        static int[] ReadNumList()
        {
            var line = Console.ReadLine().Split(' ');
            if (line.Length == 1 && string.IsNullOrEmpty(line[0]))
            {
                return new int[0];
            }
            var numList = new int[line.Length];
            for (var i = 0; i < line.Length; ++i)
            {
                numList[i] = int.Parse(line[i]);
            }
            return numList;
        }
        static void Main()
        {
            var xn = Console.ReadLine().Split(' ');
            var x = int.Parse(xn[0]);
            var n = int.Parse(xn[1]);
            var pList = new List<int>(ReadNumList());

            Console.WriteLine(Near(x, pList));
        }
        static int Near(int x, List<int> pList)
        {
            if (!pList.Contains(x))
            {
                return x;
            }
            var diff = 1;
            while (true)
            {
                if (!pList.Contains(x - diff))
                {
                    return x - diff;
                }
                if (!pList.Contains(x + diff))
                {
                    return x + diff;
                }
                ++diff;
            }
        }
    }
}


Measured memory_bytes: 27832
from collections import defaultdict


def combination(a, b):
    if b > a - b:
        return combination(a, a - b)
    return fact[a] * ifact[b] * ifact[a-b]


N, K = map(int, input().split())
A = sorted(map(int, input().split()))
MOD = 10 ** 9 + 7
# 階乗を前処理
fact = defaultdict(int)
fact[0] = 1
for i in range(1, N+1):
    fact[i] = fact[i-1] * i
    fact[i] %= MOD
# 階乗の逆元を前処理
ifact = defaultdict(int)
ifact[N] = pow(fact[N], MOD-2, MOD)
for i in reversed(range(1, N + 1)):
    ifact[i-1] = ifact[i] * i
    ifact[i-1] %= MOD

mx = 0
mn = 0
for i in range(N):
    mx += A[i] * combination(i, K - 1)
    mn += A[i] * combination(N - i - 1, K - 1)
    mx %= MOD
    mn %= MOD
print((mx - mn) % MOD)

Measured memory_bytes: 40076
using System;
using System.Linq;
public class Program{
    public static void Main(){
        string[] input = Console.ReadLine().Split(' ');
        int x1 = int.Parse(input[0]);
        int y1 = int.Parse(input[1]);
        int x2 = int.Parse(input[2]);
        int y2 = int.Parse(input[3]);
//        int x = int.Parse(Console.ReadLine());
        int x = x2 - x1;
        int y = y2 - y1;
        Console.WriteLine("{0} {1} {2} {3}",x2-y,y2+x,x1-y,y1+x);
    }
}

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

const int mod=1000000007;
int main(){
  int N; cin >> N;
  vector<long long> A(N);
  for(int i=0;i<N;i++){
    cin >> A[i];
  }
  long long ans=0;
  for(int i=0;i<60;i++){
    long long x=0;
    for(int j=0;j<N;j++){
      if(A[j]>>i&1) x++;
    }
    long long now=x*(N-x)%mod;
    if(i!=0){
      for(int j=0;j<i;j++){
        now=now*2%mod;
      }
    }
    ans+=now;
    ans%=mod;
  }
  cout << ans << endl;
}
  

Measured memory_bytes: 2560
#include <iostream>
#include <vector>
#include <functional>
#include <algorithm>
#include <numeric>
using namespace std;


int main()
{
        int K, N, Index, NumKind=0;
        cin >> N >> K;
        vector<int> A(N);
        for(int i=0; i<N; i++){
                cin >> Index;
                A[Index-1] += 1;
                if(A[Index-1] == 1) NumKind ++;
        }

        if(NumKind <= K) cout << 0;
        else{
                vector<int> B;
                for(int i=0; i<N;i++){
                        if(A[i] != 0) B.push_back(A[i]);
                }
                sort(B.begin(), B.end());

                cout << accumulate(B.begin(), B.begin()+NumKind-K, 0);

        }

}

Measured memory_bytes: 2168
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
using namespace std;
typedef long long ll;
const ll mod = 1000000007;
const ll INF = mod * mod;
typedef pair<ll, ll> LP;

#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define stop char nyaa;cin>>nyaa;

struct edge {
	int to; ll cost;
};
vector<edge> G[1 << 17];
ll d[1 << 17];
int n, m;
void solve() {
	cin >> n >> m;
	int s, t; cin >> s >> t; s--; t--;
	rep(i, m) {
		int a, b, c, d; cin >> a >> b >> c >> d; a--; b--; c--;
		G[a].push_back({ b,d });
		G[a].push_back({ c,d });
		G[b].push_back({ a,d });
		G[b].push_back({ c,d });
		G[c].push_back({ a,d });
		G[c].push_back({ b,d });
	}
	fill(d, d + n, INF);
	priority_queue<LP, vector<LP>, greater<LP>> q;
	d[s] = 0;
	q.push({ 0,s });
	while (!q.empty()) {
		LP p = q.top(); q.pop();
		int id = p.second;
		rep(j, G[id].size()) {
			int to = G[id][j].to;
			ll nd = d[id] + G[id][j].cost;
			if (nd < d[to]) {
				d[to] = nd; q.push({ d[to],to });
			}
		}
	}
	cout << d[t] << endl;
}

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


Measured memory_bytes: 24464
#include<bits/stdc++.h>
#define pi acos(-1)
#define ll long long
#define pii pair<ll,ll>
#define debug(a) cout<<a<<'\n'
#define maxn 100009 /// Still trying to be normal
#define MOD 1000000007
#define F first
#define S second
#define rep(i, a, b) for(ll i = a; i < (b); ++i)
#define per(i, b, a) for(ll i = b-1; i>=a ; i--)
#define trav(a, x) for(auto& a : x)
#define allin(a , x) for(auto a : x)
#define all(x) begin(x), end(x)
#define sz(x) (ll)(x).size()
using namespace std;
const ll INF = 1e17 + 9;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,m;
    cin>>n>>m;
    if(n&1){
        rep(i,1,m+1){
            cout<<i<<" "<<n-i<<'\n';
        }
    }
    else{
        ll fim=n;
        rep(i,1,m+1){
            ll clock = fim-i;
            ll antic = n-fim+i;
            // cout<<clock<<" "<<antic<<endl;
            if(clock>antic){
                cout<<i<<" "<<fim<<'\n',fim--;
                // fim--;
            }
            else{
                cout<<i<<" "<<fim-1<<'\n',fim--;
            }
        }
    }
    return 0;   
}

Measured memory_bytes: 3696
#include<iostream>
#include<vector>
#include<map>
#include<cmath>
#include<algorithm>
#include<string>
#include<set>
#include<deque>
#include<bits/stdc++.h>

using namespace std;

#define pb push_back
#define ld long double
#define int long long

mt19937 rnd(51);

const int MOD = 1e9 + 7;

int32_t main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    if (n == 1){
        cout << 0 << endl;
    }
    else if (n == 2){
        cout << 2 << endl;
    }
    else{
        vector<int> po(n);
        int ans = 1, ans1 = 1, ans2 = 1;
        for (int i = 0; i < n; i++){
            ans *= 10, ans1 *= 9, ans2 *= 8;
            ans %= MOD, ans1 %= MOD, ans2 %= MOD;
        }
        cout << (((ans - ans1 - ans1 + ans2) + MOD * MOD) % MOD);
    }
    return 0;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++) {
    cin >> vec.at(i);
  }
  
  sort(vec.begin(), vec.end());
  reverse(vec.begin(), vec.end());
  
  //Aliceの点数
  int Asum = 0;
  for (int i = 0; i < N; i += 2) {
    Asum += vec.at(i);
  }
  
  //Bobの点数
  int Bsum = 0;
  for (int i = 1; i < N; i += 2) {
    Bsum += vec.at(i);
  }
  
  cout << Asum - Bsum << endl;
  
}

Measured memory_bytes: 256
fn main() {
	proconio::input!{
		n: usize,
		s: String,
	}

	let cs: Vec<char> = s.chars().collect();

	let mut stack = 0;
	let mut err = 0;
	for i in 0..n {
		if cs[i] == '(' {
			stack += 1;
		}
		else {
			if stack > 0 {
				stack -= 1;
			}
			else {
				err += 1;
			}
		}
	}
	for _i in 0..err {
		print!("(");
	}
	print!("{}", s);
	for _i in 0..stack {
		print!(")");
	}
	println!("");
}



Measured memory_bytes: 2088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pl = pair<ll, ll>;
using Tl = tuple<ll, ll, ll>;

const ll INF = 1e15;
const ld eps = 1e-6;

int main(){
  ll N;
  cin >> N;
  vector<ll> a(N);
  for(int i=0;i<N;i++)
    cin >> a[i];
  ll ans = 0;
  ll now = 0;
  bool can = true;
  for(int i=N-1;i>=0;i--){
    if(now > a[i])
      can = false;
    if(now < a[i]){
      ans += a[i];
      now = a[i];
    }
    now--;
  }
  if(now >= 0)
    can = false;
  if(!can)
    cout << -1 << endl;
  else
    cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N, x; cin >> N >> x;
    vector<int> A(N);
    REP(i, 0, N) cin >> A[i];
    
    vector<int> B = A;
    ll ans = 1LL << 60;
    REP(i, 0, N) {
        REP(j, 0, N) B[j] = min(B[j], A[(N - i + j) % N]);
        ans = min(ans, accumulate(ALL(B), 0LL) + (ll)i * x);
    }
    
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
/*#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>*/
 
#define pb push_back
#define mp make_pair
#define sz(s) ((int)(s.size()))
#define all(s) s.begin(), s.end()
#define rep(i, a, n) for (int i = a; i <= n; ++i)
#define per(i, n, a) for (int i = n; i >= a; --i)
#define onlycin ios_base::sync_with_stdio(false); cin.tie(0) 
using namespace std;
// using namespace __gnu_pbds;
typedef long long ll;
typedef unsigned long long ull;
/*typedef tree<
pair < int, int >,
null_type,
less< pair < int, int > >,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;*/
// find_by_order() order_of_key()
const int MAXN = (int)5e5+228;
const char nxtl = '\n';
const int mod = (int)1e9+7;
const double eps = (double)1e-7;
template<typename T> inline bool updmin(T &a, const T &b) {return a > b ? a = b, 1 : 0;}
template<typename T> inline bool updmax(T &a, const T &b) {return a < b ? a = b, 1 : 0;}

// int D[] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
char have[] = {'a', 'e', 'i', 'o', 'u'};
string s;

int main() {
	#ifdef accepted
		freopen(".in", "r", stdin);
		freopen(".out", "w", stdout);
	#endif
	onlycin;
	int m; cin >> m;
	cout << 48-m;
	
	return 0;
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 29;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  double lim = pow(10, 18);
  sort(ALL(a));
  if(a[0] == 0) {
    cout << 0 << endl;
    return 0;
  }
  rep(i, n) lim /= a[i];
  if(lim < 1.0) {
    cout << -1 << endl;
    return 0;
  }
  ll ans = 1;
  rep(i, n) ans *= a[i];
  if(ans <= (ll)pow(10, 18)) cout << ans << endl;
  else cout << -1 << endl;
  
}

Measured memory_bytes: 4008
#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 Int;
typedef pair<Int,Int> P;
#define print(x) cout<<(x)<<endl

#define INF10 10000000000
#define INF5 100000
#define EPS 1e-10
#define MOD 1000000007



int main() {
	int a, b;
	cin >> a >> b;
	int c = a + b;
	if (c % 2 == 1)c++;
	c /= 2;
	print(c);





	return 0;
}

Measured memory_bytes: 256
def inN():
    return int(input())
def inL():
    return list(map(int,input().split()))
def inNL(n):
    return [list(map(int,input().split())) for i in range(n)]

a,b,c,k = inL()
cnt = 0
if k >= a:
    cnt += a
    k -= a
else:
    cnt += k
    print(cnt)
    exit()

k -= b

if k>0:
    cnt -= k

print(cnt)

Measured memory_bytes: 61936
#include <memory.h>

#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <utility>
#include <vector>

using namespace std;

#define MOD 1000000007
#define INIT -1

int main() {
	int n;
	cin >> n;
	long long int a[300000];
	for (int i = 0; i < 3 * n; i++) {
		cin >> a[i];
	}
	// suml[i] = a_0 ~ a_(i - 1) から大きい値をn個選んだときの総和
	long long int suml[300010] = {};
	priority_queue<long long int> qu;
	for (int i = 1; i <= 3 * n; i++) {
		if (qu.size() == n) {
			long long int tmp = suml[i - 1] + qu.top() + a[i - 1];
			if (tmp > suml[i - 1]) {
				qu.pop();
				qu.push(-a[i - 1]);
				suml[i] = tmp;
			} else {
				suml[i] = suml[i - 1];
			}
		} else {
			qu.push(-a[i - 1]);
			suml[i] = suml[i - 1] + a[i - 1];
		}
		// cout << i << " " << suml[i] << endl;
	}

	qu = priority_queue<long long int>();
	// suml[i] = a_i ~ a_(3 * n - 1) から小さい値をn個選んだときの総和
	long long int sumr[300010] = {};
	for (int i = 3 * n - 1; i >= 0; i--) {
		if (qu.size() == n) {
			long long int tmp = sumr[i + 1] - qu.top() + a[i];
			if (tmp < sumr[i + 1]) {
				qu.pop();
				qu.push(a[i]);
				sumr[i] = tmp;
			} else {
				sumr[i] = sumr[i + 1];
			}
		} else {
			qu.push(a[i]);
			sumr[i] = sumr[i + 1] + a[i];
		}
		// cout << i << " " << sumr[i] << endl;
	}
	long long int ans = (long long int)-MOD * MOD;
	for (int i = n; i + n <= 3 * n; i++) {
		ans = max(ans, suml[i] - sumr[i]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 9076
#include<stdio.h>
#include<math.h>
int main()
{
   int k,m,i,c=0,d=0;
   scanf("%d",&k);

       for(i=1;i<=k;i++)
       {
           if(i%2==0)
            c++;
           else
            d++;
       }
       printf("%d\n",(c*d));

    return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<algorithm>
using namespace std;
int*t,n,m,d,i,s[99999];
main(){
	for(;cin>>d>>n>>m;cout<<i<<'\n'){
		for(s[i=n]=d;--i;)
			cin>>s[i];
		for(sort(s,s+n);m--;t=upper_bound(s,s+n,d),i+=min(d-*--t,*t-d))
			cin>>d;
	}
}

Measured memory_bytes: 1248
import sys
from collections import Counter


def main():
    s = input()
    t = input()
    s_count = [0]*26
    t_count = [0]*26
    for i in range(ord("a"), ord("z")+1):
        s_count[i-97] = s.count(chr(i))
        t_count[i-97] = t.count(chr(i))
    s_count.sort()
    t_count.sort()
    if s_count == t_count:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


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

using namespace std;

#define rep(i,x) for(int i=0;i<x;++i)
#define all(a) begin(a),end(a)

int d[100010];
int sum[100010];

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

    rep(i, n - 1) cin >> d[i];

    for (int i = 0; i < n - 1; ++i) {
        sum[i + 1] += d[i] + sum[i];
    } 

    int cur = 0;

    int ans = 0;

    rep(i, m) {
        int a;
        cin >> a;

        if (a > 0) {
            ans += sum[cur + a] - sum[cur];
        } else {
            ans += sum[cur] - sum[cur + a];
        }

        cur += a;

        ans %= 100000;
    }

    cout << ans << endl;
}

Measured memory_bytes: 3832
#include<iostream>
using namespace std;
int N;
int A[210];

int main()
{
  cin >> N;
  for(int i = 0; i < N;++i)cin >> A[i];
  int res = 0;

  while(true){
    bool exist_odd = false;
    for (int i = 0; i <N; ++i){
      if(A[i] % 2 != 0) exist_odd = true;
    }

    if(exist_odd) break;

    for(int i = 0; i < N; ++i){
      A[i] /= 2;
    }
    ++res;
  }
  cout << res << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    /* チェックリスト
     * 結果はintの範囲を超えていませんか？(必要な時以外はlongを使いましょう)
     * TLEしそうな処理はありませんか？
     */
    public static void main(String[] args) {
        Scanner s = new Scanner(System.in);
        String[] in = s.nextLine().split(" ");
        int a = Integer.parseInt(in[0]);
        int b = Integer.parseInt(in[1]);
        String out = "";
        for(int i = b-(a-1);i <= a+b-1;i++){
            out += " "+i;
        }
        System.out.println(out.replaceFirst(" ",""));
    }
}

Measured memory_bytes: 23892
import java.util.Scanner;

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

        if (b - a == c - b) {
            System.out.println("YES");
        } else {
            System.out.println("NO");
        }
    }
}

Measured memory_bytes: 23892