akhauriyash/Code-Regression huggingface dataset:
from itertools import permutations
import sys
input = sys.stdin.readline
N, M, R = map(int, input().split())
r = [int(i)-1 for i in input().split()]
D = [[float("inf")] * N for _ in range(N)]
for a, b, c in [[int(i) for i in input().split()] for _ in range(M)]:
    a -= 1
    b -= 1
    D[a][b] = c
    D[b][a] = c
for i in range(N):
    D[i][i] = 0

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])

ans = float("inf")
for l in permutations(range(R)):
    l = list(l)
    c = 0
    for i in range(R - 1):
        c += D[r[l[i]]][r[l[i + 1]]]
    ans = min(ans, c)
print(ans)

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

#define i64 long long int

i64 dfs(i64 x) {
	if(x==0) return 0LL;
	return 1LL + 2*dfs(x/2);
}

int main() {
	i64 x;
	cin>>x;
	
	cout<<dfs(x)<<endl;
	
	return 0;
}

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

bool is_exchange(long int A, long int B, long int K){
    if ((B - A > 2)){
        return true;
    }
    else{
        return false;
    }
}

int main(){
    long int K, A, B, now;
    cin >> K >> A >> B;
    now = 1;
    bool is_true = is_exchange(A, B, K);
    while(K > 0){
        if (now < A){
            now += 1;
            K -= 1;
        }
        else if (is_true && K >= 2){
            now += B - A;
            K -= 2;
        }
        else{
            now += 1;
            K -= 1;
        }
    }
    cout << now << endl;

    return 0;
}

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

import sys
sys.setrecursionlimit(300000)

MOD = 998244353  # type: int

def solve(N: int, S: int, A: "List[int]"):
    dp = [[0] * 2 for _ in range(S + 1)]
    for i, v in enumerate(A):
        if v > S:
            continue
        for s in range(S + 1)[::-1]:
            if dp[s][0] > 0 and s + v <= S:
                dp[s + v][0] += dp[s][0]
                dp[s + v][1] += dp[s][0] * (N - i)
                dp[s + v][0] %= MOD
                dp[s + v][1] %= MOD
        dp[v][0] += i + 1
        dp[v][1] += (i + 1) * (N - i)
    print(dp[S][1] % MOD)
    return

def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    S = int(next(tokens))  # type: int
    A = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, S, A)

if __name__ == '__main__':
    main()


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

using ll = long long;
const int INF = 1001001001;
const ll LLINF = 1001001001001001001;
const int MOD = 1000000007;

#define rep(i,n) for (int i = 0; i < (n); ++i)

int main()
{
  int n;
  cin >> n;
  int zorome = 0;
  bool flag = false;
  rep(i, n) {
    int d1, d2;
    cin >> d1 >> d2;
    if (d1 == d2) {
      zorome++;
    } else {
      zorome = 0;
    }

    if (zorome == 3) {
      flag = true;
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}




Measured memory_bytes: 3628
S=gets.chomp

arr = Array.new(S.length,0)

i = 0
loop do
  idx = S.index('L',i)
  count = idx - i
  arr[idx] += count/2
  arr[idx-1] += count/2+(count%2)
  i = S.index('R',idx) || S.length
  count = i-idx
  arr[idx-1] += count/2
  arr[idx] += count/2+(count%2)
  break if i == S.length
end

puts arr.join(' ')



Measured memory_bytes: 3196
#include <string>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cfloat>
#include <algorithm>
#include <vector>
#include <iostream>
#define PI 3.141592
using namespace std;
 
int main (){
    int x,y;
    char num[11] = "0123456789";
    char hypn[2] = "-";
    cin >> x >> y;
 
    char s[x+y+2];
 
    for (int i=0;i<x+y+1;i++){
        cin >> s[i];
    }
 
    // for (int i=0;i<x+y+1;i++){
    //     cout <<  s[i];
    // }cout << "\n";
int w,z=0;
w = 0;
    for(int i = 0;i<x+y+1;i++){
        if(i == x){
            if(s[i] == hypn[0]){
                z++;
            }
        }
        for(int j=0;j<10;j++){
 
            if(s[i] == num[j]){
                w++;
            }
        }
    }
    //cout << w <<" "<< z << "\n";
    if(w == x+y && z == 1){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int x = Integer.parseInt(sc.next());
        int t = Integer.parseInt(sc.next());
        int answer = 0;
        int takoyaki = 0;
        while (takoyaki < n) {
            takoyaki += x;
            answer += t;
        }
        System.out.println(answer);
        sc.close();
    }
}

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

using namespace std;


int main() {
  int a, b, c;
  long long k;
  scanf("%d %d %d %lld", &a, &b, &c, &k);
  if (k % 2 == 0) {
    printf("%d\n", a - b);
  } else {
    printf("%d\n", b - a);
  }
  return 0;
}

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

struct Benri { Benri() { std::cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(12);}} benri;

using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int, int>;
using vll = vector<long long>;
using vvll = vector<vll>;
using pll = pair<ll, ll>;
using ull = unsigned long long;

template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define mp make_pair
#define F first
#define S second

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

constexpr long long MOD = 1000000007;
//constexpr long long MOD = 998244353;
//constexpr int INF = 1001001001;
constexpr ll INF = 1001001001001001001LL;
//constexpr double INF = 1e10;
constexpr double EPS = 1e-10;
using number = long long;


using Matrix = vector<vector<number>>;

void warshall_floyd(int V, Matrix &g) {
    rep(k, V) {
        rep(i, V) {
            rep(j, V) {
                if (g[i][k] == INF || g[k][j] == INF) continue;
                g[i][j] = min(g[i][j], g[i][k] + g[k][j]);
            }
        }
    }
}


int main() {
    ll n, m, l; cin >> n >> m >> l;
    Matrix g(n, vll(n, INF));
    rep(i, n) g[i][i] = 0;
    ll a, b, c;
    rep(i, m) {
        cin >> a >> b >> c;
        a--; b--;
        if (c > l) continue;
        g[a][b] = c;
        g[b][a] = c;
    }

    warshall_floyd(n, g);
    rep(i, n) rep(j, n) g[i][j] = (g[i][j] <= l ? 1 : INF);
    rep(i, n) g[i][i] = 0;
    warshall_floyd(n, g);


    int q; cin >> q;
    int s, t;
    rep(i, q) {
        cin >> s >> t;
        s--; t--;
        cout << (g[s][t] == INF ? (ll) - 1 : g[s][t] -1) << endl;
    }
}


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

int main() {
	int a, b, c, d;
	cin >> a 
		>> b 
		>> c 
		>> d;
	int s = min(a, b);
	int t = min(c, d);
	int result = s + t;
	cout << result << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int MAXn = 1e5 + 10, INF = 1e9;

long long last[2 * MAXn], cnt[2 * MAXn], n, ar[MAXn], psum[MAXn];
long long hp2;
bool check(int a) {
	fill_n(last, 2 * MAXn, -1);
	fill_n(cnt, 2 * MAXn, 0);
	fill_n(psum, MAXn, 0);
	long long psum1 = 0, ans = 0;
	for (int i = 0; i < n; i++) {
		if (ar[i] > a)
			psum1--;
		else
			psum1++;
		int hp = last[psum1 + MAXn] + 1;
		
		if (psum[hp] < psum1) {
			cnt[psum1 + MAXn] += (i - hp);
		}
		ans += cnt[psum1 + MAXn] + (psum1 > 0);
		last[psum1 + MAXn] = i;
		psum[i] = psum1;
	}
//	cout << ans << endl;
	
	return hp2 < ans;
}
int main() {
	ios::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	cin >> n;
	hp2 = (n * (n + 1)) / 2;
	hp2 /= 2;
	for (int i = 0; i < n; i++)
		cin >> ar[i];
	if (n == 1)
		return cout << ar[0],0;
	
	int st = 0, en = INF;
	while(st + 1 < en) {
		int med = (st + en) / 2;
		if (check(med))
			en = med;
		else
			st = med;
	}
	cout << en;
}

Measured memory_bytes: 4992
#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>;

int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    // cout << a << endl;
    ll ans = a * c;
    ll tmp = a * d;
    if(tmp > ans) ans = tmp;
    tmp = b * c;
    if(tmp > ans) ans = tmp;
    tmp = b * d;
    if(tmp > ans) ans = tmp;
    cout << ans << endl;   
    return 0;
}

Measured memory_bytes: 3612
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<iostream>
#include<string>
#include<stack>
#include<queue>
#include<vector>
#include<map>
#include<set>
#include<algorithm>
#include<numeric>

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<=n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define MOD 1000000007
#define MAX 1001
#define INF 1410065408
#define EPS 1e-9
#define DEBUG 0
#define ll long long
#define Pll pair<ll, ll>
#define Pii pair<int, int>
 
using namespace std;
struct edge{int from, to; ll cost;};

signed main(){
    int h,w;
    cin >> h >> w;
    int one = (h*w) % 2;
    int four = (h/2) * (w/2);
    int two = (h*w - one - 4*four)/2;
    /*
    printf("%d %d %d\n", one, two, four);
    return 0;
    */

    map<char, int> mp;
    rep(h){
        string s;
        cin >> s;
        repp(j, w) mp[s[j]]++;
    }

    for(auto itr=mp.begin();itr!=mp.end();itr++){
        int n = itr->second;
        if(n % 2 == 1){
            if(one > 0){
                n--;
                one--;
            }else{
                cout << "No\n";
                return 0;
            }
        }
        while(four > 0 && n >= 4){
            n -= 4;
            four--;
        }
        while(two > 0 && n >= 2){
            n -= 2;
            two--;
        }
        if(n > 0){
            cout << "No\n";
            return 0;
        }
    }
    if(one + two + four == 0){
        cout << "Yes\n";
    }else{
        cout << "No\n";
    }
    return 0;
}

Measured memory_bytes: 256
package main

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

//Util
func nextStr() string {
	sc.Scan()
	return sc.Text()
}

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

func maxInt(a, b int) int {
	if a > b {
		return a
	} else {
		return b
	}
}

func minInt(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}

func absInt(a int) int {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func absFloat64(a float64) float64 {
	if a >= 0 {
		return a
	} else {
		return -a
	}
}

func maxFloat64(a, b float64) float64 {
	if a > b {
		return a
	} else {
		return b
	}
}

func minFloat64(a, b float64) float64 {
	if a > b {
		return b
	} else {
		return a
	}
}

func str2Int(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}

func reverse(s string) string {
	runes := []rune(s)
	for i, j := 0, len(runes)-1; i < j; i, j = i+1, j-1 {
		runes[i], runes[j] = runes[j], runes[i]
	}
	return string(runes)
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func isPrime(x int) bool {
	if x == 1 {
		return false
	}
	if x == 2 {
		return true
	}
	if x%2 == 0 {
		return false
	}

	b := true
	rootx := int(math.Sqrt(float64(x)))
	i := 3
	for i <= rootx {
		if x%i == 0 {
			b = false
			break
		}
		i += 2
	}
	return b
}

func PrimeFactors(n int) (pfs []int) {
	// Get the number of 2s that divide n
	for n%2 == 0 {
		pfs = append(pfs, 2)
		n = n / 2
	}

	// n must be odd at this point. so we can skip one element
	// (note i = i + 2)
	for i := 3; i*i <= n; i = i + 2 {
		// while i divides n, append i and divide n
		for n%i == 0 {
			pfs = append(pfs, i)
			n = n / i
		}
	}

	// This condition is to handle the case when n is a prime number
	// greater than 2
	if n > 2 {
		pfs = append(pfs, n)
	}

	return
}

//Main
const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		return sc
	}()
)

var A, B string

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

	A, B = nextStr(), nextStr()
	if len(A) > len(B) {
		fmt.Println("GREATER")
		return
	} else if len(A) < len(B) {
		fmt.Println("LESS")
		return
	}

	ans := "EQUAL"
	for i := 0; i < len(A); i++ {
		if string(A[i]) == string(B[i]) {
			continue
		} else if string(A[i]) > string(B[i]) {
			ans = "GREATER"
			break
		} else {
			ans = "LESS"
			break
		}
	}

	fmt.Println(ans)
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> vec(N);
  for (int i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    vec.at(a-1)++;
    vec.at(b-1)++;
  }
  
  for (int i = 0; i < N; i++) {
    cout << vec.at(i) << endl;
  }
}

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

// template {{{  0 
// using {{{ 1
using ll = long long int;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vii = vector<pii>;
using vll = vector<pll>;
// }}} 1
// definition {{{ 1
// scaning {{{ 2
#define Scd(x) scanf("%d", &x)
#define Scd2(x,y) scanf("%d%d", &x, &y)
#define Scd3(x,y,z) scanf("%d%d%d", &x, &y, &z)
#define Scll(x) scanf("%lld", &x)
#define Scll2(x,y) scanf("%lld%lld", &x, &y)
#define Scll3(x,y,z) scanf("%lld%lld%lld", &x, &y, &z)
#define Scc(c) scanf("%c", &c);
#define Scs(s) scanf("%s", s);
#define Scstr(s) scanf("%s", &s);
// }}} 2
// constants {{{ 2
#define EPS (1e-7)
#define INF (2e9)
#define PI (acos(-1))
// }}} 2
// systems {{{ 2
#define Repe(x,y,z) for(ll x = z; x < y; x++)
#define Rep(x,y) Repe(x,y,0)
#define RRepe(x,y,z) for(ll x = y-z-1; x >= 0; x--)
#define RRep(x,y) RRepe(x,y,0)
// }}} 2
// output {{{ 2
#define YesNo(a) (a)?printf("Yes\n"):printf("No\n")
#define YESNO(a) (a)?printf("YES\n"):printf("NO\n")
// }}} 2
// }}} 1
// input {{{ 1
// }}} 1
// }}} 0

int main() {

    ll N;
    Scll(N);

    ll h,n,w=0;
    ll t = 0;
    ll b = 0;
    Repe(i,3501,1){ Repe(j,3501,1){
            t = 4*i*j-N*j-N*i;
            if( t <= 0 ) continue;
            b = N*i*j;
            if( b%t == 0 ){
                h = i;
                n = j;
                w = b/t;
                break;
            }
        }
        if( w ) break;
    }

    printf ("%lld %lld %lld\n", h,n,w );

    return 0;
}



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

int main() {
    int N;
    cin >> N; 
    vector<ll> A(N);
    ll sum = 0;
    for(int i = 0; i < N; i++) {
        cin >> A[i];
        sum = (sum + A[i]) % 1000000007;
        
    }
    ll ans = 0;
    for(int i = 0; i < N - 1; i++) {
        
        if(sum - A[i] < 0){ 
            ans = (ans + (A[i] % 1000000007) * ((sum + 1000000007 - A[i]) % 1000000007) % 1000000007) % 1000000007;
            sum = (sum + 1000000007 - A[i]) % 1000000007; }
        else {ans = (ans + (A[i] % 1000000007) * ((sum - A[i]) % 1000000007) % 1000000007) % 1000000007;
              sum = (sum - A[i]) % 1000000007;
        }
    }

    cout << ans % 1000000007;
    return 0;
}

Measured memory_bytes: 4820
#include<bits/stdc++.h>
#define MOD 1000000007
#define MOD2 1000000006
#define TEMPMOD1 998244353
#define TEMPMOD2 998244352
#define INF 1000000000000000007
#define NEGINF -1000000000000000007
#define vll vector<ll> 
#define vvll vector<vector<ll>>
#define pll pair<ll,ll>
#define pii pair<int,int>
#define plll pair<ll,pll>
#define vpll vector<pll>
using namespace std;
typedef long long int ll;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    
    ll n;
    cin>>n;
    ll arr1[n];
    ll temp[n];
    for(ll i=0;i<n;i++)
    {
        cin>>arr1[i];
        temp[i]=arr1[i];
    }
    sort(arr1,arr1+n);
    ll max1=arr1[n-1];
    ll max2=arr1[n-2];
    for(ll i=0;i<n;i++)
    {
        if(temp[i]!=max1)
        {
            cout<<max1<<endl;
        }
        else
        {
            cout<<max2<<endl;
        }
    }
    return 0;
}

Measured memory_bytes: 4736
/*
	  Author : @evenbao
	  Created : 2020 / 07 / 17 
*/

#ifdef _MSC_VER
#define _CRT_SECURE_NO_WARNINGS
#endif

#include<bits/stdc++.h>

using namespace std;

typedef long long LL;

#define pii pair<int , int>
#define mp make_pair
#define fi first
#define se second

const int N = 20;
const LL inf = 1e18;

int n;
LL a[N];

template <typename T> inline void chkmax(T &x , T y) { x = max(x , y); }
template <typename T> inline void chkmin(T &x , T y) { x = min(x , y); }
template <typename T> inline void read(T &x) {
    T f = 1; x = 0;
    char c = getchar();
    for (; !isdigit(c); c = getchar()) if (c == '-') f = -f;
    for (; isdigit(c); c = getchar()) x = (x << 3) + (x << 1) + c - '0';
    x *= f;
}

inline LL solve(int l , int r , int cl , int cr) {
		if (r - l <= 1) return 0LL; 
		LL ret = inf;
		for (int mid = l + 1; mid < r; ++mid)
				chkmin(ret , (LL) solve(l , mid , cl , cl + cr) + solve(mid , r , cl + cr , cr) + (LL) a[mid] * (cl + cr));
		return ret;
}

int main() {
		
		read(n);
		for (int i = 1; i <= n; ++i) read(a[i]);
		printf("%lld\n" , solve(1 , n , 1 , 1) + a[1] + a[n]);
	  return 0;
}



Measured memory_bytes: 3760
#include <iostream>
#include <algorithm>
#include <limits>
#include <vector>
#include <map>
#include <cmath>
#include <limits>
#include <iomanip>
#define ll long long int
#define rep(i,n) for(int i = 0;i < n;i++)
#define pb push_back
#define mp make_pair

using namespace std;

ll n,m;

vector<int> parent;
//ノードXの根を返す
int root(int X)
{
    if (parent[X] < 0)
        return X;
    return parent[X] = root(parent[X]);
}
//ノードXが属するグループのサイズ(属するノード数)を返す
int size(int X)
{
    return -parent[root(X)];
}
//Xの属するグループとYの属するグループを繋ぐ
//それぞれの根どうしを繋ぐ
bool connect(int X, int Y)
{
    //根同士をつなぐため指すノードを根にする
    X = root(X);
    Y = root(Y);
    //すでに繋がっているときは繋がずにfalseを返す
    if (X == Y)
    {
        return false;
    }
    //大きいほうに小さいほうを繋ぎたいので逆ならスワップ
    if (size(X) < size(Y))
        swap(X, Y);
    //繋がれる方のサイズを更新
    parent[X] += parent[Y];
    //繋ぐ方の親を設定
    parent[Y] = X;
    return true;
}

int main(){
    cin >> n >>m;
    vector<pair<ll,ll> > e(m);
    vector<ll> ans(m + 1);
    parent.resize(n);
    rep(i,n) parent[i] = -1;
    ll x,y;
    rep(i,m){
        cin >> x >> y;
        x--;
        y--;
        e[i] = mp(x,y);
    }

    ans[0] = n * (n - 1) / 2;

    for(int i = 0;i < m;i++){
        if(root(e[m - 1 - i].first) == root(e[m-1-i].second)){
            ans[i + 1] = ans[i];
        }
        else{
            ans[i + 1] = ans[i] - size(e[m-1-i].first) * size(e[m-1-i].second);
            connect(e[m - 1 - i].first,e[m - 1 - i].second);
        }
    }

    for(int i = m - 1;i >= 0;i--){
        cout << ans[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph= vector<vector<int>>; 
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
 
int main(){
  ll n;
  cin>>n;
  vector<ll> A(n+1) ;rep(i,n+1) cin>>A[i] ;
  
  if(n==0){
  if(A[0]==1) cout<<1<<endl;
  else cout<<-1<<endl ;
  }
    
    else{
      ll ans=0 ;
      int seigo=0;
      vector<ll> r(n) ;//深さiでの個数
      ll res=1;
      rep(i,n+1){
        r[0]=1 ;
      if(i==n){
        if(res*2<A[i]){
          seigo=-1 ;
          break ;
        }

      }
       
       else if(i==0) {
          if(A[i]!=0){
            seigo=-1 ;
            break ;
          }
        }
        else {
          
          res=res*2-A[i] ;
          r[i]=res ;
          if(res<=0){
            seigo=-1 ;
            break ;
          }
          else if(res>1e14) res=1e14 ;
        }
      
      
         if(res>1e14) res=1e14 ;
      
      
      
      }
    ll hon=0 ;
    for(ll i=n;i>=1;i--){
      if(i==n){ ans+=A[n] ;
      hon=A[n] ;
     }else{
       hon=A[i]+min(r[i],hon) ;
      ans+=hon;
     }
    }
    ans++ ;
    
    
    
    if(seigo==-1) cout<<-1<<endl ;
    if(seigo==0) cout<<ans<<endl ;

    
    }
    
    
    return 0;
  }

Measured memory_bytes: 4844
#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;


typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;

typedef pair<ll, ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<vll> vvll;
typedef vector<ld> vld;

#define fi first
#define se second

typedef tree<pll, null_type, less<pll>, rb_tree_tag, tree_order_statistics_node_update> pbds;

const ll mod = 1e9 + 7;
const ll inf = ll(1e18);

ll n,k;
ll arr[101];
ll dp[100001],dp1[100001],dpsum[100001];

int main() {

	ios_base::sync_with_stdio(false);
    	cin.tie(NULL);
	#ifdef DEBUG_
		freopen("input.txt","r",stdin);
	#endif
	
	cout.setf(ios::fixed), cout.precision(20);
	cin >> n >> k;
	for(int i=0;i<n;i++){
		cin >> arr[i];
	}

	for(int j=0;j<=k;j++){
		if(j>arr[n-1]) 
			dp[j]=0;
		else
			dp[j]=1;
	}
	dpsum[0]=dp[0];
	for(int j1=1;j1<=k;j1++)
		dpsum[j1]=dpsum[j1-1]+dp[j1];
	for(ll i=n-2;i>=0;i--){
		for(ll j=0;j<=k;j++){
			ll xx = min(j,arr[i]);
			ll temp;
			if(j-xx==0)
				temp=(dpsum[j])%mod;
			else
				temp=(dpsum[j]-dpsum[j-xx-1])%mod;
			dp1[j]=temp%mod;
		}
		for(int j=0;j<=k;j++) 
			dp[j]=dp1[j];
		dpsum[0]=dp[0];
		for(int j=1;j<=k;j++){
			dpsum[j]=dpsum[j-1]+dp[j];
		}
	}
	cout<<dp[k]<<"\n";
	return 0;
}



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

int main(){
	int f = 0, a, b;
	string s;
	cin >> s;
	a = (s[0] - '0') * 10 + (s[1] - '0');
	b = (s[2] - '0') * 10 + (s[3] - '0');
	if (b <= 12 && b) f++;
	if (a <= 12 && a) f += 2;
	switch (f){
	case 0: cout << "NA" << endl; break;
	case 1: cout << "YYMM" << endl; break;
	case 2: cout << "MMYY" << endl; break;
	case 3: cout << "AMBIGUOUS" << endl; break;
	}
	return 0;
}

Measured memory_bytes: 256
#D
N, K = map(int, input().split())
R, S, P = map(int, input().split())
T = list(input())
ans = 0

for i in range(N-K):
    if T[i] == "s":
        if T[i+K] == "s":
            T[i+K] = "x"
            ans += R
        else:
            ans += R
    elif T[i] == "p":
        if T[i+K] == "p":
            T[i+K] = "x"
            ans += S
        else:
            ans += S
    elif T[i] == "r":
        if T[i+K] == "r":
            T[i+K] = "x"
            ans += P
        else:
            ans += P
    else:
        pass

for i in range(N-K, N):
    if T[i] == "s":
        ans += R
    elif T[i] == "p":
        ans += S
    elif T[i] == "r":
        ans += P
    else:
        pass
print(ans)

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

#define rep(i,n) for(int i=0;i<(n);i++)

using namespace std;

class mint{
	static const int MOD=1e9+7;
	int x;
public:
	mint():x(0){}
	mint(long long y){ x=y%MOD; if(x<0) x+=MOD; }

	mint& operator+=(const mint& m){ x+=m.x; if(x>=MOD) x-=MOD; return *this; }
	mint& operator-=(const mint& m){ x-=m.x; if(x<   0) x+=MOD; return *this; }
	mint& operator*=(const mint& m){ x=1LL*x*m.x%MOD; return *this; }
	mint& operator/=(const mint& m){ return *this*=inverse(m); }
	mint operator+(const mint& m)const{ return mint(*this)+=m; }
	mint operator-(const mint& m)const{ return mint(*this)-=m; }
	mint operator*(const mint& m)const{ return mint(*this)*=m; }
	mint operator/(const mint& m)const{ return mint(*this)/=m; }
	mint operator-()const{ return mint(-x); }

	friend mint inverse(const mint& m){
		int a=m.x,b=MOD,u=1,v=0;
		while(b>0){ int t=a/b; a-=t*b; swap(a,b); u-=t*v; swap(u,v); }
		return u;
	}

	friend istream& operator>>(istream& is,mint& m){ long long t; is>>t; m=mint(t); return is; }
	friend ostream& operator<<(ostream& os,const mint& m){ return os<<m.x; }
	int to_int()const{ return x; }
};

mint operator+(long long x,const mint& m){ return mint(x)+m; }
mint operator-(long long x,const mint& m){ return mint(x)-m; }
mint operator*(long long x,const mint& m){ return mint(x)*m; }
mint operator/(long long x,const mint& m){ return mint(x)/m; }

mint pow(mint m,long long k){
	mint res=1;
	for(;k>0;k>>=1,m*=m) if(k&1) res*=m;
	return res;
}

mint fact(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		for(;k<=n;k++) memo[k]=memo[k-1]*k;
	}
	return memo[n];
}

mint fact_inverse(int n){
	static vector<mint> memo={1};
	if(memo.size()<=n){
		int k=memo.size();
		memo.resize(n+1);
		memo[n]=inverse(fact(n));
		for(int i=n;i>k;i--) memo[i-1]=memo[i]*i;
	}
	return memo[n];
}

mint choose(int n,int k,int type=0){
	if(k==0) return 1;
	if(n< k) return 0;
	if(type==0){
		return fact(n)*fact_inverse(k)*fact_inverse(n-k);
	}
	else{
		if(k>n-k) k=n-k;
		mint res=fact_inverse(k);
		rep(i,k) res*=n-i;
		return res;
	}
}

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

	mint p=mint(a)/(100-c);
	mint q=mint(b)/(100-c);

	mint ans=0;
	for(int k=n;k<2*n;k++){
		ans+=k*choose(k-1,k-n)*(pow(p,n)*pow(q,k-n)+pow(p,k-n)*pow(q,n));
	}
	ans*=mint(100)/(100-c);
	cout<<ans<<'\n';

	return 0;
}


Measured memory_bytes: 1416
var input = require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");
var obj = {
  "list" : input, "index" : 0, "max" : input.length,
  "hasNext" : function(){return (this.index < this.max);},
  "next" : function(){
    if(!this.hasNext()){return "";}
    var returnObj = this.list[this.index];
    this.index++;
    return returnObj;
  }
}
Main();
function next(){return obj.next();}
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function hasNext(){return obj.hasNext();}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
  var list = new Array(Math.pow(2,N));
  for(var i = 0; i < list.length; i++){
    list[i] = nextInt();
  }
  var ato;
  for(var i = 0; i < N; i++){
    ato = new Array(Math.pow(2,N - i - 1));
    for(var j = 0; j < list.length; j = j + 2){
      if(list[j] > list[j + 1]){
        ato[j / 2] = list[j] - list[j + 1];
      }else if(list[j] < list[j + 1]){
         ato[j / 2] = list[j + 1] - list[j];
      }else{
         ato[j / 2] = list[j];
      }
    }
    list = ato;
    //myerr(list);
  }
  myout(list[0]);
}


Measured memory_bytes: 36952
# F - Bracket Sequencing
import sys
readline = sys.stdin.readline

N = int(input())
L = []
R = []
for _ in range(N):
    S = readline().strip()
    sums = 0
    mins = 0
    for s in S:
        if s == '(':
            sums += 1
        else:
            sums -= 1
            mins = min(mins, sums)
    if sums >= 0:
        L.append((sums, mins))
    else:
        R.append((-sums, mins-sums))

L.sort(key=lambda x: x[1], reverse=True)
R.sort(key=lambda x: x[1], reverse=True)

ans = 'Yes'
l_now = 0
for d, min_d in L:
    if l_now + min_d < 0:
        ans = 'No'
        break
    else:
        l_now += d

r_now = 0
for d, min_d in R:
    if r_now + min_d < 0:
        ans = 'No'
        break
    else:
        r_now += d

if l_now != r_now:
    ans = 'No'

print(ans)

Measured memory_bytes: 84176
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        s: chars,
        t: chars
    }
    let n = s.len();
    let mut tab = vec![vec![n; 26]; n];
    tab[n - 1][alp(s[n - 1])] = n - 1;
    for i in (0..n - 1).rev() {
        for j in 0..26 {
            tab[i][j] = tab[i + 1][j];
        }
        tab[i][alp(s[i])] = i;
    }
    for &c in &t {
        if tab[0][alp(c)] == n {
            println!("-1");
            return;
        }
    }
    let mut ans: usize = 0;
    let mut idx = 0;
    for &c in &t {
        let next = tab[idx][alp(c)] + 1;
        if next <= n {
            ans += next - idx;
            idx = next % n;
        } else {
            let next2 = tab[0][alp(c)] + 1;
            ans += n - idx + next2;
            idx = next2;
        }
    }
    println!("{}", ans);
}

fn alp(c: char) -> usize {
    c as usize - 'a' as usize
}


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

//#define int long long
struct Fast {Fast(){std::cin.tie(0);ios::sync_with_stdio(false);}} fast;

/* cpp template {{{ */

/* short */
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define Fi first
#define Se second
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define X real()
#define Y imag()

/* REPmacro */
#define REPS(i, a, n) for (ll i = (a); i < (ll)(n); ++i)
#define rep(i, n) REPS(i, 0, n)
#define REP0(i,n) for (ll i = 0; i <= (ll)(n); ++i)
#define REP1(i,n) for (ll i = 1; i <= (ll)(n); ++i)
#define RREP(i, n) REPS(i, 1, n + 1)
#define DEPS(i, a, n) for (ll i = (a); i >= (ll)(n); --i)
#define DEP(i, n) DEPS(i, n, 0)
#define EACH(i, n) for (auto&& i : n)

/* debug */
#define debug(x) cerr << x << " " << "(L:" << __LINE__ << ")" << '\n';

/* alias */
using ll = long long;
using ull = unsigned long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using pii = pair<int, int>;
using D = double;
using P = complex<D>;
using vs = vector<string>;
template <typename T> using PQ = priority_queue<T>;
template <typename T> using minPQ = priority_queue<T, vector<T>, greater<T>>;

/* const */
const int INF = 1001001001;
const ll LINF = 1001001001001001001ll;
const int MOD = 1e9 + 7;
const D EPS = 1e-9;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};

/* func */
inline bool inside(int y, int x, int H, int W) {return y >= 0 && x >= 0 && y < H && x < W;}
inline int in() {int x; cin >> x; return x;}
inline ll IN() {ll x; cin >> x; return x;}
inline vs split(const string& t, char c) {vs v; stringstream s(t); string b; while(getline(s, b, c)) v.eb(b); return v;}
template <typename T> inline bool chmin(T& a, const T& b) {if (a > b) a = b; return a > b;}
template <typename T> inline bool chmax(T& a, const T& b) {if (a < b) a = b; return a < b;}
template <typename T, typename S> inline void print(const pair<T, S>& p) {cout << p.first << " " << p.second << endl;}
template <typename T> inline void print(const T& x) {cout << x << '\n';}
template <typename T, typename S> inline void print(const vector<pair<T, S>>& v) {for (auto&& p : v) print(p);}
template <typename T> inline void print(const vector<T>& v, string s = " ") {rep(i, v.size()) cout << v[i] << (i != (ll)v.size() - 1 ? s : "\n");}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) is >> x;
  //for(int i=0; i<vec.size(); i++) is >> x[i]; とかでもいいです。
  return is;
}
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
  for(int i=0; i<vec.size(); i++){
    os << vec[i] << ( i+1 == vec.size() ? "" : " " );
  }
  return os;
}
/* }}} */

signed main() 
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int ans1,ans2;
  a>b?ans1=b:ans1=a;
  c>d?ans2=d:ans2=c;
  print(ans1+ans2);

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
	string str;
	cin >> str;
	int A = str.length(), n = 0;
	for(int i = 0; i < A; i++){
		if(str[i] != str[A - i - 1]){
			n++;
        }
    }
	n = (n - n % 2) / 2;
	cout << n;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 5010;
int f[N], a[N], n, va, vb, mn[N][N];
signed main() {
    scanf("%lld%lld%lld", &n, &va, &vb);
    for (int i = 1; i <= n; ++i) scanf("%lld", a + i);
    if (va > vb) {
        swap(va, vb);
        reverse(a + 1, a + n + 1);
        for (int i = 1; i <= n; ++i) a[i] = n - a[i] + 1;
    }
    ++n; a[n] = n;
    for (int i = 1; i <= n; ++i)
        for (int j = i + 1; j <= n; ++j)
            mn[i][j] = mn[i][j - 1] + bool(a[j] < a[i]);
    for (int i = 1; i <= n; ++i) {
        f[i] = 1e15;
        for (int j = i - 1; ~j; --j) if (a[j] < a[i])
            f[i] = min(f[i], f[j] + mn[j][i] * vb + (i - j - 1 - mn[j][i]) * va);
    }
    printf("%lld\n", f[n]);
    return 0;
}

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

int main()
{
	int h1,m1,h2,m2,k;
	cin>>h1>>m1>>h2>>m2>>k;
	int sum=(h2-h1)*60+(m2-m1);
	cout<<sum-k<<endl;
	return 0;
}

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

#define MAX_N (100000)
#define MAX_H (1000000000)

using namespace std;

int main(int argc, char *argv[]) {
  // read inputs
  int N, A, B, hs[MAX_N];
  scanf("%d %d %d", &N, &A, &B);
  for (int i = 0; i < N; i++) {
    scanf("%d", &hs[i]);
  }

  // keep attacking the one with the most health
  int b = 0, e = MAX_H + 1;
  while (e - b > 1) {
    const long m = (b + e - 1) / 2, damage_all = m * B;
    long cnt = 0;
    for (int i = 0; i < N; i++) {
      const int h = hs[i];
      if (h > damage_all) {
        cnt += (h - damage_all + (A - B - 1)) / (A - B);
      }
    }
    if (cnt <= m) {
      e = m + 1;
    } else {
      b = m + 1;
    }
  }
  printf("%d\n", b);

  return 0;
}


Measured memory_bytes: 512
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))

ans = min(a) + min(b)

for i in range(M):
    x, y, c = map(int, input().split())
    ans = min(ans, a[x-1] + b[y-1] - c)
print(ans)

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

int A[30];
int main() {
  A[0] = 1;
  A[1] = 1;
  A[2] = 2;

  for(int i = 3; i <= 30; i++) {
    A[i] = A[i-1] + A[i-2]+ A[i-3];
  }
  int N;
  while(cin >> N && N)
    cout << A[N]/3650 + 1 << endl;
}

Measured memory_bytes: 3040
# https://atcoder.jp/contests/abc085/tasks/abc085_c
def solve(N, Y):
    for m in range(int(Y/10000) + 1):
        for g in range(int(Y/5000) + 1):
            s = N - m - g
            if 0 <= s == (Y - m * 10000 - g * 5000) / 1000.0:
                return '{} {} {}'.format(m, g, s)
    return '-1 -1 -1'


if __name__ == '__main__':
    N, Y = map(int, input().split())
    print(solve(N, Y))


Measured memory_bytes: 3060
// clang-format off
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <numeric>
#include <array>
#include <cmath>
#include <memory>
using namespace std;
#define DEB(variable) cout << #variable << '=' << variable << endl

#define FOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin); (LoopVariable) < (numberOFend); (LoopVariable)++)
#define DEFOR(LoopVariable,numberOFbegin,numberOFend) for (long long int LoopVariable = (numberOFbegin)-1; (LoopVariable) >= (numberOFend); (LoopVariable)--)
#define REP(LoopVariable,numberOFend) for(long long int LoopVariable = 0;(LoopVariable)<(numberOFend);LoopVariable++)

using llint = long long int;

constexpr long long int linf = numeric_limits<long long int>::max()-5;
constexpr long long int inf= numeric_limits<int>::max()-5;
constexpr long long int mod = 1000000007;

// clang-format on
int main(){

    llint n;
    cin>>n;
    string s;
    cin>>s;
    vector R(n+1,0ll),G(n+1,0ll),B(n+1,0ll);
    REP(i,n){
        R[i + 1] = R[i] + (s[i] == 'R' ? 1 : 0);
        G[i + 1] = G[i] + (s[i] == 'G' ? 1 : 0);
        B[i + 1] = B[i] + (s[i] == 'B' ? 1 : 0);
    }
    llint result = 0;
    REP(i,n-2){
        FOR(j,i,n-1){
            if(s[i]==s[j]||(i==n-3&&j==n-2)){
                continue;
            }else if((s[i]=='R'&&s[j]=='G')||
            (s[j]=='R'&&s[i]=='G')){
                result += B[n] - B[j + 1] - ((s[j + (j - i)] == 'B')&&j+j-i<n ? 1 : 0);
            }else if((s[i]=='B'&&s[j]=='G')||
            (s[j]=='B'&&s[i]=='G')){
                result += R[n] - R[j + 1] - ((s[j + (j - i)] == 'R')&&j+j-i<n ? 1 : 0);
            }else if((s[i]=='R'&&s[j]=='B')||
            (s[j]=='R'&&s[i]=='B')){
                result += G[n] - G[j + 1] - ((s[j + (j - i)] == 'G')&&j+j-i<n ? 1 : 0);
            }
        }
    }
    cout << result << endl; 
    return 0;
}


Measured memory_bytes: 3236
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
namespace AtCoder {
    class MainClass {
        public static void Main(string[] args) { new MainClass().solve(); }
        Scanner cin = new Scanner();

        char a, b;
        void solve() {
            a = cin.nextChar();
            b = cin.nextChar();

            bool atHonest = a == 'H';
            bool toHonest = atHonest == (b == 'H');

            Console.WriteLine(toHonest ? "H" : "D");
       
        }
        class Scanner {
            string[] nextBuffer; int BufferCnt; char[] cs = new char[] { ' ' };
            public Scanner() { nextBuffer = new string[0]; BufferCnt = 0; }
            public string next() {
                if (BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
                string st = Console.ReadLine();
                while (st == "") st = Console.ReadLine();
                nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
                BufferCnt = 0;
                return nextBuffer[BufferCnt++];
            }
            public char nextChar() { return char.Parse(next()); }
            public int nextInt() { return int.Parse(next()); }
            public long nextLong() { return long.Parse(next()); }
            public double nextDouble() { return double.Parse(next()); }
            public string[] array() { return Console.ReadLine().Split(' '); }
            public char[] arrayChar() { return Array.ConvertAll(array(), char.Parse); }
            public int[] arrayInt() { return Array.ConvertAll(array(), int.Parse); }
            public long[] arrayLong() { return Array.ConvertAll(array(), long.Parse); }
            public double[] arrayDouble() { return Array.ConvertAll(array(), double.Parse); }
        }

        class Mathf {
            public int mod = 1000000007;//10^9+7
            public long Pow(long a, long b) {
                if (b == 0) return 1;
                if (b % 2 == 1) return (a % mod * Pow(a % mod, b - 1) % mod) % mod;
                else return Pow(a * a % mod, b / 2) % mod;
            }
            public long Fact(long n) { return n != 0 ? (n % mod * (Fact(n - 1) % mod) % mod) : 1; }
            public long C(long n, long r) {
                if (r == 0 || n == r) return 1;
                else return (Fact(n) % mod * Pow((Fact(n - r) % mod * Fact(r) % mod) % mod, mod - 2) % mod) % mod;
            }
            public int GCD(int a, int b) { if (a < b) Swap(ref a, ref b); return b == 0 ? a : GCD(b, a % b); }
            public int GCD(int[] array) { return array.Aggregate((v, next) => GCD(v, next)); }
            public void Swap<T>(ref T a, ref T b) { T tmp = a; a = b; b = tmp; }
        }
    }
}

Measured memory_bytes: 11092
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<set>
using namespace std;

int main()
{
	int n;
	while(scanf("%d",&n)!=EOF)
	{
	set<int>s;
	for(int i=0;i<n;i++)
	
	{
		int x;
		scanf("%d",&x);
		if(s.count(x))
		{
			s.erase(x);
		}
		else
		s.insert(x);
	}
		printf("%d\n",s.size());
    	s.clear();

}
}

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

int main(){
  int n, k; 
  vector<int> v; 
  scanf("%d %d", &n, &k); 
  v.resize(n); 
  map<int, int> m; 
  int size = 0; 
  for(int i = 0; i<n; ++i){
    scanf("%d", &v[i]); 
    m[v[i]]++; 
  }
  vector<int> sizes; 
  map<int, int>::iterator it;
  for(it = m.begin(); it != m.end(); it++){
    sizes.push_back((*it).second); 
  }
  sort(sizes.begin(), sizes.end()); 
  long res = 0; 
  for(int i = 0; i<(int)sizes.size()-k; ++i){
    res += sizes[i]; 
  }
  printf("%ld\n", res); 
}

Measured memory_bytes: 11516
import sys

INPUT = lambda: sys.stdin.readline().rstrip()
INT = lambda: int(INPUT())
LIST = lambda: list(map(int, INPUT().split()))

sys.setrecursionlimit(10 ** 9)


def main():
    N = INT()
    A = LIST()

    check = False
    cnt = 1
    for i, a in enumerate(A):
        if a == cnt:
            check = True
            cnt += 1

    print(N - cnt + 1 if check else -1)


if __name__ == '__main__':
    main()

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

#define SIS std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define lowbit(x) (x & -x)
#define PI 3.14159265358979323846264338327950L
typedef long long ll;
using namespace std;
const int MAX = 0x7ffffff;
const int N = 55;
int t;
char a[N][N];
int b[N][N];
int ne[8][2] = {{1,0},{-1,0},{0,1},{0,-1},
{1,1},{1,-1},{-1,1},{-1,-1}};
int check(int x,int y)
{
	int ans = 0;
	for(int i = 0;i < 8;i ++)
	{
		int nx = x + ne[i][0];
		int ny = y + ne[i][1];
		if(a[nx][ny] == '#')ans++;
	}
	return ans;
}
void slove()
{
	int h , w;
	cin >> h >> w;
	for(int i = 1;i <= h ;i ++)
	{
		for(int j = 1;j <= w;j ++)
			cin >> a[i][j];
	}
	for(int i = 1;i <= h;i ++)
	{
		for(int j = 1;j <= w;j ++)
		{
			if(a[i][j] != '#')
				cout << check(i,j);
			else cout << '#';
		}
		cout << endl;
	}
}
int main()
{
	SIS;
	slove();
}

Measured memory_bytes: 3632
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#define INF 1000000;

using namespace std;

int main() {
   long long int  n;
   long long int k;
   cin >> n >> k;
   n = abs(n%k);
   if(n==0) cout << 0 << endl;
   else {
   long long loop=n;
   n = abs(n-k);
   if (n<=loop) cout << n << endl;
   else cout << loop << endl;
   }
}

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

int main(){
    int one = 0;
    int two = 0;
    int three = 0;
    int a, b;
    cin>>a>>b;
    if(a == 1) one++;
    if(a == 2) two++;
    if(a == 3) three++;
    if(b == 1) one++;
    if(b == 2) two++;
    if(b == 3) three++;
    if(one == 0){
        cout<<1<<endl;
    } else if(two == 0){
        cout<<2<<endl;
    } else {
        cout<<3<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define ITR(v,c) for(auto v=begin(c);v!=end(c);v++)
#define FOR(v,a,n) for(int v=a;v<(int)(n);v++)
#define FORE(x,arr) for(auto &x:arr)
#define REP(v,n) FOR(v,0,n)
#define ALL(c) begin(c),end(c)
const int DX[4]={0,1,0,-1}, DY[4]={-1,0,1,0};
const int INF = 1e9;
const ll INFLL = 1e18;
template<class T,class U>ostream&operator<<(ostream &os,const pair<T,U> &p){
    os<<"("<<p.first<<","<<p.second<<")";return os;}
template<class T>ostream&operator<<(ostream &os,const vector<T> &v){
    ITR(i,v)os<<*i<<(i==end(v)-1?"":" ");return os;}
//------------------------------------------------------------------------------

ll dp[52][5001];
int main(int argc, char const *argv[]) {
    int N,A;
    cin>>N>>A;
    vector<int> x(N),y(N);
    REP(i,N) {
        cin>>x[i];
        y[i]=x[i]-A;
    }
    FOR(i,0,N) {
        dp[i][2501+y[i]]++;
        REP(j,5002) {
            dp[i+1][j]+=dp[i][j];
            if(0<=j+y[i+1] && j+y[i+1]<5002) dp[i+1][j+y[i+1]]+=dp[i][j];
        }
    }
    cout<<dp[N-1][2501]<<endl;
    return 0;
}


Measured memory_bytes: 2176
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        q: usize,
        s: chars,
        v: [(usize1, usize1); q]
    }
    let mut acc: Vec<usize> = vec![0; n + 1];
    for i in 1..n {
        acc[i + 1] = acc[i];
        if s[i - 1] == 'A' && s[i] == 'C' {
            acc[i + 1] += 1;
        }
    }
    for &(l, r) in v.iter() {
        let mut ans = acc[r + 1] - acc[l];
        if l > 0 && s[l - 1] == 'A' && s[l] == 'C' {
            ans -= 1;
        }
        println!("{}", ans);
    }
}


Measured memory_bytes: 6908