akhauriyash/Code-Regression huggingface dataset:
/*

#      #      #####   ##   ##  #####      ##     #  #      #   #  #####
#      #      #   #  #  ###  # #          # ##   #  #      #   #  #   #
#      #      #   #  #   #   # #          #  ##  #  #      #   #  #   #
#      #      #   #   #     #  #####      #   #  #  #       ###   #####
#      #      #   #    #   #   #          #  ##  #  #        #    #   #
#      #      #   #     ###    #          # ##   #  #        #    #   #
#      #####  #####      #     #####      ##     #  #####    #    #   #

*/

#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define pb push_back
#define np next_permutation
#define bs binary_search
#define mp make_pair
#define all(x) x.begin(), x.end()
#define bp __builtin_popcountll
#define sqr(x) ((llong)sqrt (x))
#define b_ctz __builtin_ctzll
#define b_clz __builtin_clzll

#define y1 road_to_respa_top_6
#define prev road_to_respa_top_6
#define Abdrakhman abcdefghijklmnopqrstuvwxyzRakhman
#define left kotoriy_levee_chem_right
#define right kotoriy_pravee_chem_left

#define android ios_base::sync_with_stdio(0), cin.tie (0), cout.tie (0)
#define fn ""

typedef long long llong;
typedef long double ldouble;
typedef unsigned long long ullong;

typedef vector <llong> vl;
typedef vector <string> vs;
typedef vector <vector <llong>> matrix;

typedef pair <llong, llong> pll;

typedef map <llong, llong> mll;

typedef set <llong> sl;

const llong MXN = 1e6 + 1;
const llong MNN = 1e3 + 1;
const llong MOD = 1e9 + 7;
const llong INF = 1e18;
const llong MAGIC = 1000;
const ldouble EPS = 1e-9;
const ldouble PI = 3.1415926536;
const string TIME = "rovno_ushten_push_ketti";

inline llong log2 (llong x) {return 64 - b_clz (x) - 1;};
inline llong __lcm (llong a, llong b) {return a / __gcd (a, b) * b;};

int a, b, c;

int main () {
    android;
    random_device rand;
    #ifdef I_LOVE_DILYA
        freopen ("input.txt", "r", stdin);
    #endif
    cin >> a >> b;
    c = log (b) / log (10);
    ++ c;
    while (c --) {
        a *= 10;
    }
    a += b;
    if (sqr (a) * sqr (a) == a) cout << "Yes";
    else cout << "No";
    return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <cmath>
#include <cstdio>
using namespace std;

int main(){
    int A[5], k;

    for (int i=0;i<5;++i) cin>>A[i];
    cin>>k;

    bool isContinue = true;
    for (int i=0;i<5 && isContinue;++i) {
        for (int j=i+1;j<5 &&isContinue;j++){
            if (abs(A[i]-A[j])>k) isContinue = false;
        }
    }

    if (isContinue) printf ("Yay!\n");
    else printf (":(\n");

    return 0;
}

Measured memory_bytes: 256
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val temp=readLine()!!.split(" ")
    val a=IntArray(n,{i: Int -> temp[i].toInt()})
    val b=IntArray(n-1,{i: Int -> abs(a[i]-a[i+1])})
    val len=abs(a[0])+b.sum()+abs(a[n-1])
    println(len-abs(a[0])-b[0]+abs(a[1]))
    for (i in 1 until n-1){
        println(len-b[i-1]-b[i]+abs(a[i+1]-a[i-1]))
    }
    println(len-abs(a[n-1])-b[n-2]+abs(a[n-2]))
}
fun  abs(i:Int):Int{
    if (i<0)return -i
    return i
}

Measured memory_bytes: 54848
def slove():
    import sys
    input = sys.stdin.readline
    n = int(input().rstrip('\n'))
    p = list(map(int, input().rstrip('\n').split()))
    cnt = 0
    for i in range(1, n-1):
        if p[i-1] < p[i] < p[i+1]:
            cnt += 1
        elif p[i-1] > p[i] > p[i+1]:
            cnt += 1
    print(cnt)


if __name__ == '__main__':
    slove()


Measured memory_bytes: 39876
import scala.io.{StdIn => in}

object Main extends App {
  val Array(n, k) = in.readLine.split(" ").map(_.toInt)

  def f(cnt:Int, num:Int):Int = {
    if(num >= k) cnt
    else f(cnt+1, num*2)
  }

  val dn = n.toDouble
  val ans = if (k == 1) 1
    else (1 to n)./:(0d)((acc, i) => {
        val cnt = f(0, i)
        acc + 1 / dn * math.pow(0.5,cnt)
      })

  println(ans)
}

Measured memory_bytes: 29752
K = gets.chomp.to_i

list = [
  1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
 ]

print list[K-1]

Measured memory_bytes: 1788
import java.util.*;
import static java.util.Map.Entry.comparingByValue;
import static java.util.stream.Collectors.toMap;

public class Main {

    int V;
    String S;

    Main(String S, int V) {
        this.S = S;
        this.V = V;
    }

    public String toString() {
        return S + " " + V;
    }

    public static void main(String[] args) {

        Scanner Input = new Scanner(System.in);

        String A = Input.next();
        String B = Input.next();

        int C = Integer.parseInt(A + B);

        int N = 1;
        boolean F = false;
        while (N <= C) {
            if (N * N == C) {
                F = true;
                break;
            }
            N++;
        }
        if (F) {
            System.out.println("Yes");
        }else{System.out.println("No");}
    }
}


Measured memory_bytes: 23892
#include <stdio.h>
int main(){
	int A,B;
	int K=0;
	int sum=0;
	scanf("%d %d",&A,&B);
	sum=A+B;
 	if(sum%2==0){
		K=sum/2;
      	printf("%d",K);
	}else{
		printf("IMPOSSIBLE");
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#include<boost/dynamic_bitset.hpp>
using namespace std;
using u64 = uint64_t;
using s64 = int64_t;

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

    vector<u64> L(N);
    for(u64 i=0; i<N; i++) {
        cin >> L[i];
    }

    u64 ans = 0;
    for(u64 i=0; i<N; i++) {
        for(u64 j=i+1; j<N; j++) {
            for(u64 k=j+1; k<N; k++) {
                if(L[i]+L[j]>L[k] && L[j]+L[k]>L[i] && L[i]+L[k]>L[j]) {
                    if(L[i]!=L[j] && L[j]!=L[k] && L[k]!=L[i]) {
                        ans++;
                    }
                }
            }
        }
    }

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

Measured memory_bytes: 3640
package main

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

func main() {
	h, w, hh, ww := readInt(), readInt(), readInt(), readInt()

	fmt.Println(h*w - (h*ww + hh*w - hh*ww))
}

// sort ------------------------------------------------------------

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

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

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcd(m, n int) int {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcm(m, n int) int {
	return m / gcd(m, n) * n
}


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

using namespace std;

#define REP(i,n)   for(int i=0; i<(int)(n); i++)
#define FOR(i,b,e) for(int i=(b); i<=(int)(e); i++)
#define TRAV(a, x) for(const auto& a : x)
#define ALL(x) x.begin(), x.end()
#define NEXT_PERM(x) while(next_permutation(ALL(x))) // 순열 알고리즘(오름)
#define PREV_PERM(x) while(prev_permutation(ALL(x))) // 순열 알고리즘(내림)
#define PRINT(x) cout << x
#define PRINT_LN(x) cout << x << endl;
#define DUMP(a, n) REP(_i, n) printf("%d%c", a[_i], _i + 1 == n ? '\n' : ' ')
#define DUMP2D(a, n, m) REP(_i, n) REP(_j, m) printf("%d%c", a[_i][_j], _j + 1 == m ? '\n' : ' '); puts("")

typedef long long int ll;
typedef vector<int> vi;
typedef vector<string> vs;

int gcd(int a, int b);
int lcm(int a, int b);



void solve() {
  int n;
  cin >> n;
  ll result = 0;
  FOR(i,1,n) {
    if (i%3 ==0 && i%5 ==0) continue;
    else if (i%3 ==0) continue;
    else if (i%5 ==0) continue;
    result += i;
  }
  PRINT_LN(result);
}

int main() {
  solve();
  return 0;
}

int gcd(int a, int b){
	while(b!=0){
		int r = a%b;
		a= b;
		b= r;
	}
	return a;
}

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


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
int main() {
    i64 N, A, B, C, D;
    cin >> N >> A >> B >> C >> D;
    B = abs(B - A), A = 0;
    N--;
    for(int i = 0; i <= N; i++) {
        i64 X, Y;
        X = B + i * C, Y = B + i * D;
        if(Y - (N - i) * C >= 0 && X - (N - i) * D <= 0) {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x, a, b; cin >> x >> a >> b;
  if(b <= a) cout << "delicious" << endl;
  else if(b <= a + x) cout << "safe" << endl;
  else cout << "dangerous" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;
const int INF = (1 << 30) - 1;
// const ll LL_INF = (1LL << 62) - 1;
// const ll MOD = 1e9 + 7;

const int MAX_V = 101;

int d[MAX_V][MAX_V];
int V, E;
map<pair<int, int>, bool> mp;
vector<int> a, b;

void warshall_floyd() {
  for (int k = 0; k < V; k++) {
    for (int i = 0; i < V; i++) {
      for (int j = 0; j < V; j++) {
        if (d[i][k] == INF || d[k][j] == INF) {
          continue;
        }
        if (d[i][j] > d[i][k] + d[k][j]) {
          d[i][j] = d[i][k] + d[k][j];
          mp[make_pair(i, j)] = false;
          // mp[make_pair(i, k)] = true;
          // mp[make_pair(k, j)] = true;
        }
      }
    }
  }
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cin >> V >> E;
  a.resize(E);
  b.resize(E);
  for (int i = 0; i < V; i++) {
    for (int j = 0; j < V; j++) {
      if (i == j) {
        d[i][j] = 0;
      } else {
        d[i][j] = INF;
      }
    }
  }
  for (int i = 0; i < E; i++) {
    int ai, bi, ci;
    cin >> ai >> bi >> ci;
    ai--;
    bi--;
    d[ai][bi] = ci;
    d[bi][ai] = ci;
    a[i] = ai;
    b[i] = bi;
    mp[make_pair(ai, bi)] = true;
    mp[make_pair(bi, ai)] = true;
  }

  warshall_floyd();
  int ans = 0;
  for (int i = 0; i < E; i++) {
    if (!mp[make_pair(a[i], b[i])] && !mp[make_pair(b[i], a[i])]) {
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

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

int N, M;
vector<int> s;

bool enough(int X) {
    int L = 1;
    for (int i = 0; i < M - 1; ++i) {
        if (s.back() < L + X) return false;
        auto itr = lower_bound(begin(s), end(s), L);
        int diff = 1e9;
        if (itr != begin(s) && *prev(itr) < L + X) {
            diff = min(diff, abs(L - *prev(itr)));
        }
        if (*itr < L + X) {
            diff = min(diff, abs(L - *itr));
        }
        if (diff == 1e9) return false;
        L += max(1, X - diff);
    }
    return true;
}

int main() {
    while (cin >> N >> M, N) {
        s = vector<int>(N);
        for (int i = 0; i < N; ++i) cin >> s[i];
        int ok = s.front(), ng = s.back();
        while (ng - ok > 1) {
            int mid = (ok + ng) / 2;
            ( (enough(mid)) ? ok : ng ) = mid;
        }
        cout << ( (enough(ok)) ? ok : -1 ) << endl;
    }
    return 0;
}



Measured memory_bytes: 3660
#include<bits/stdc++.h>
using namespace std;
 
 
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    long long int a,b;
    char op;
    cin>>a;cin>>op;cin>>b;
    
    if(op=='+'){
        cout<<a+b;
    }
    
    if(op=='-'){
        cout<<a-b;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string.h>
#include <iostream>
#include <queue>
#include <stack>
#include <vector>
#include <functional>
#include <math.h>
#include <map>
#include <set>
#include <string>
using namespace std;
#define fio ios::sync_with_stdio(false); cin.tie(NULL);
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll,ll> pll;
typedef pair<int, int> pii;
 
const int INT_INF = 1e9;
const ll LL_INF = 1e18;
const int MAXN = 500003;
 
typedef struct GE{
    int to;
    ll w;
    GE(){};
}GE;
 
int n, m;
int cnt[300];
int main() {
    char s[10];
    scanf("%s", s);
    int ans=0;
    int mxcnt=0;
    for(int i=0;i<4;i++){
    	if(cnt[s[i]]==0){
    		ans++;
    	}
    	cnt[s[i]]++;
    	mxcnt = max(mxcnt, cnt[s[i]]);
    }
 
    if(ans==2) {
    	puts("Yes");
    }
    else
    	puts("No");
    
    
    return 0;
}

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

int main()
{
	int n;
	long long k;
	cin >> n >> k;
	vector<pair<int, int>> v(n);
	for (auto& i : v) {
		cin >> i.first >> i.second;
	}

	sort(v.begin(), v.end(), [](const pair<int, int>& a, const pair<int, int>& b) 
	{
		return a.first < b.first;
	});

	int ret = 0;
	long long c = 0;
	for (auto& i : v) {
		c += i.second;
		if (k <= c) {
			ret = i.first;
			break;
		}
	}

	cout << ret << endl;

	return 0;
}

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

using LL = long long;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);

  int A, B;
  cin >> A >> B;

  vector<int> vec;
  vec.push_back(A + B);
  vec.push_back(A - B);
  vec.push_back(A * B);

  int ans = *max_element(vec.begin(), vec.end());

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<queue>
#include<algorithm>

using namespace std;

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

int main() {
  int n;
  cin >> n;
  pair<int, int> a[n];
  rep (i, n) cin >> a[i].second >> a[i].first;
  sort(a, a + n, greater<pair<int, int> >());
  int l = 0, u = n + 1;
  while (l + 1 < u) {
    int m = (l + u) / 2;
    priority_queue<int> que;
    long long sum = 0;
    bool ok = false;
    rep (i, n) {
      que.push(a[i].second);
      sum += a[i].second;
      if (i >= m) {
	sum -= que.top();
	que.pop();
      }
      if (i >= m - 1 && sum <= (long long)a[i].first * m) {
	ok = true;
	break;
      }
    }
    if (ok) l = m;
    else u = m;
  }
  cout << l << endl;
}

Measured memory_bytes: 6528
def solve():
    # Q回の正解者が出たってことは全員-Qして、正解者が+1すると考える
    N,K,Q = map(int, input().split())
    points = [K-Q]*N
    for _ in range(Q):
        correct_idx = int(input())
        points[correct_idx-1] += 1
        
    print('\n'.join(['Yes' if p>0 else 'No' for p in points]))
    
solve()

Measured memory_bytes: 7092
#include <stdio.h>

int main(){
  int n, a, b, i, j;
  scanf("%d%d%d", &n, &a, &b);

  if((n == 1 && a != b) || a > b) puts("0");
  else printf("%lld\n", (long long) b * (n-1) + a - ((long long) a * (n-1) + b) + 1);
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <deque>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
#define REP(i,n) for(int i = 1; i<=n; ++i)
#define all(x) begin(x),end(x)
typedef long long ll;
typedef pair<int,int> ip;
typedef pair<ll,ll> lp;
const int inf = 1001001000;
const ll INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

int main(){
	int n;
	cin>>n;
	vector<int> ans(110,-1);
	vector<vector<int>> input (110);
	REP(i,n){
		int el_siz;
		cin>>el_siz>>el_siz;
		vector<int> el(el_siz);
		rep(j,el_siz)cin>>el[j];
		input[i] = el;
	}
	queue<int> Q;
	int cnt = 0;
	ans[1] = 0;
	Q.push(1);
	while(!Q.empty()){
		int node = Q.front();
		Q.pop();
		rep(i,input[node].size()){
			if(ans[input[node][i]] == -1){
				ans[input[node][i]] = ans[node]+1;
				Q.push(input[node][i]);
			}
		}
	}
	REP(i,n)cout<<i<<' '<<ans[i]<<endl;
	return 0;
}



Measured memory_bytes: 3144
s = input()
t = input()
s_num = len(s)
t_num = len(t)
dp = [[0] * (t_num + 1) for _ in range(s_num + 1)]

for i in range(s_num):
    for j in range(t_num):
        if s[i] == t[j]:
            dp[i + 1][j + 1] = max(dp[i][j] + 1, dp[i + 1][j], dp[i][j + 1])
        else:
            dp[i + 1][j + 1] = max(dp[i + 1][j], dp[i][j + 1])
ans = ""
i = s_num
j = t_num
while i > 0 and j > 0:
    if dp[i][j] == dp[i - 1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j - 1]:
        j -= 1
    elif dp[i][j] == dp[i - 1][j - 1] + 1:
        ans = s[i - 1] + ans
        i -= 1
        j -= 1
print(ans)

Measured memory_bytes: 112476
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define reps(i, f, n) for (int i = (f); i < (n); i++)
#define repv(v) for (auto it = (v).begin(); it != (v).end(); it++)
ll const INF = 1LL << 60;

int main() {
    ll N;
    cin >> N;

    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    ll minsum = INF;

    ll left = -1e9, right = 1e9;
    ll b = INF;

    ll cnt = 0;
    for (int k = 0; k < 100; k++) {
        ll lmid = (left * 2 + right) / 3;
        ll rmid = (right * 2 + left) / 3;

        ll lsum = 0;
        ll rsum = 0;

        rep(i, N) {
            lsum += abs(A[i] - (lmid + (i + 1)));
            rsum += abs(A[i] - (rmid + (i + 1)));
        }

        // cout << "cnt:" << cnt << ", l:" << lsum << ", r:" << rsum << "... ("
        //      << lmid << ", " << rmid << ")" << endl;

        if (lsum > rsum) {
            left = lmid;
        } else {
            right = rmid;
        }
        cnt++;
    }

    for (ll k = left; k <= right; k++) {
        ll sum = 0;
        rep(i, N) { sum += abs(A[i] - (k + (i + 1))); }
        // cout << k << "," << sum << endl;
        minsum = min(minsum, sum);
    }

    cout << minsum << endl;

    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string s[102];
int main(void){
    int n; cin>>n;
    string a,b;
    cin>>a;
    s[0]=a;
    for(int i=1;i<n;i++){
        b=a; cin>>a;
        s[i]=a;
        if(b[b.size()-1]!=a[0]){
            cout<<"No"<<endl; return 0;
        }
        for(int j=0;j<i;j++){
            if(s[i]==s[j]){
                cout<<"No"<<endl; return 0;
            }
        }
    }
    cout<<"Yes"<<endl;
    
}


Measured memory_bytes: 256
#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());
   d.erase(unique(d.begin(), d.end()), d.end());
   cout << d.size() << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    private static final int INF = (int) 1e8;
    private static int N;
    private static int A;
    private static int B;
    private static int C;
    private static int[] L;

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        A = sc.nextInt();
        B = sc.nextInt();
        C = sc.nextInt();
        L = new int[N];
        for (int n = 0; n < N; n += 1) {
            L[n] = sc.nextInt();
        }

        System.out.println(dfs(0, 0, 0, 0));
    }

    private static int dfs(int n, int a, int b, int c) {
        if (n == N) {
            if (a == 0 || b == 0 || c == 0) {
                return INF;
            } else {
                return Math.abs(a - A) + Math.abs(b - B) + Math.abs(c - C) - 30;
            }
        }

        int dfsNull = dfs(n + 1, a, b, c);
        int dfsA = dfs(n + 1, a + L[n], b, c) + 10;
        int dfsB = dfs(n + 1, a, b + L[n], c) + 10;
        int dfsC = dfs(n + 1, a, b, c + L[n]) + 10;

        int[] maxArray = new int[]{dfsNull, dfsA, dfsB, dfsC};
        return Arrays.stream(maxArray).min().getAsInt();
    }

}


Measured memory_bytes: 32280
//package cf;
import java.awt.event.MouseAdapter;
import java.io.*;
import java.util.*;
public class Main {
    static int p=1000000007;
    public static void main(String[] args) throws Exception{
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        FastReader sc=new FastReader();
        // long k = sc.nextLong();
            int n = sc.nextInt();
            int a=sc.nextInt();
            int ar[]=new int[n];

            String inp[]=sc.nextLine().split(" ");
        for(int i=0;i<n;i++)
            {
                ar[i]=Integer.parseInt(inp[i]);
            }
       int max_sum=n*a+1;
        long dp[][][]=new long[n+1][n+1][max_sum];
        for(int i=0;i<=n;i++) {
                dp[i][0][0]=1;
        }
            
            List<Integer> l1=new ArrayList<>();
            for(int i=1;i<=n;i++)
            {
                for(int k=1;k<=n;k++)
                {
                for(int j=1;j<=max_sum-1;j++)
                {
                    if(j-ar[i-1]>=0&&dp[i-1][k-1][j-ar[i-1]]>0)
                   {
                       if(j==ar[i-1])
                       {
                   
                           dp[i][k][j]=dp[i-1][k][j]+dp[i-1][k-1][j-ar[i-1]];
                       }
                        else
                       {
                   
                           dp[i][k][j]=dp[i-1][k][j]+dp[i-1][k-1][j-ar[i-1]];
                       }

                    }
                    dp[i][k][j]=Math.max(dp[i][k][j],dp[i-1][k][j]);
                }
                }
            }
        for(int i=1;i<=n;i++)
        {
                c+=dp[n][i][i*a];
        }
            System.out.println(c);
        //  out.write(sb.toString());
        out.flush();
    }
    static  long c=0;
 





    ///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

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

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }


}


Measured memory_bytes: 101960
N, K, C = map(int, input().split())
S = input()

L = []
R = []

count_L = C
count_R = C

for i in range(N):
    if S[i] == "o" and count_L >= C:
        count_L = 0
        L.append(i)
    else:
        count_L += 1
        
    if S[N-i-1] == "o" and count_R >= C:
        count_R = 0
        R.append(N-i-1)
    else:
        count_R += 1
        
    if len(L) >= K and len(R) >= K:
        break
    
for l, r in zip(L, R[::-1]):
    if l == r:
        print(l+1)

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

using namespace std;

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

//class Timer {
//    clock_t start;
//    string name;
//public:
//    Timer() {name = "";start = clock();}
//    Timer(string s){name = s;start = clock();}
//    ~Timer() {fprintf(stderr, "%s: %.3gs\n", name.c_str(), 1.0*(clock() - start) / CLOCKS_PER_SEC);}
//};

//#define isValid(a, b) ((a) >= 0 && (a) < (b))
//int dr[]  =  {0, -1, -1, -1,  0,  1, 1, 1};
//int dc[]  =  {1,  1,  0, -1, -1, -1, 0, 1};

#define all(x) (x).begin(), (x).end()
#define pb push_back
#define eb emplace_back
#define um unordered_map
#define us unordered_set
#define endl '\n'
#define what_is(x) cerr << fixed << setprecision(2) << boolalpha << #x << " = " << x << endl

const double EPS = 1e-9;
const double PI = acos(-1.0);

template<typename T> inline T sq(T a){return a*a;}
template<typename T1, typename T2> inline pair<T1, T2> mp(T1 a, T2 b){return make_pair(a, b);}
template<typename T1, typename T2> inline T1 safeMod(T1 a, T2 m){return (a%m + m)%m;}/*handling negative sign of remainder*/
template<typename T1, typename T2> inline bool isEq(T1 a, T2 b){return abs(a - b) < EPS;}
template<typename T1, typename T2, typename T3> inline bool isEq(T1 a, T2 b, T3 eps){return abs(a - b) < eps;}
template<typename T> inline bool isKthBitOn(T n, int k){assert(n <= numeric_limits<T>::max());assert(k<=numeric_limits<T>::digits);T ONE = 1;return bool((n & (ONE<<k)));}
template<typename T> inline void setKthBit(T& n, int k){assert(n <= numeric_limits<T>::max());assert(k<=numeric_limits<T>::digits);T ONE = 1;n = (n|(ONE<<k));}
//mt19937 rng((int)chrono::steady_clock::now().time_since_epoch().count());
//template<typename T> inline T nextRand(T lo, T hi){return uniform_int_distribution<T>(lo, hi)(rng);}

#define toRad(deg) ((deg)*PI/180.0)
#define toDeg(rad) ((rad)*180.0/PI)

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;

const int oo = 0x3f3f3f3f;
const int MAX = 200010;
const int MOD = 1000000007;
const int precision = 10;

int relations[MAX];
int findrep(int n){
    if(n == relations[n])return n;
    return relations[n] = findrep(relations[n]);
}

void solve(int kas){
    int n, m;
    cin >> n >> m;
    for(int i = 1; i <= n; i++)relations[i] = i;
    for(int i = 0; i < m; i++){
        int a, b;
        cin >> a >> b;
        int x = findrep(a);
        int y = findrep(b);
        if(x != y)
        relations[x] = y;
    }
    int cmp = 0;
    for(int i = 1; i <= n; i++){
        if(findrep(i) == i)cmp++;
    }
    cout << cmp-1 << endl;
}

int main()
{
    //assert(freopen("in.txt", "r", stdin));
    //assert(freopen("out.txt", "w", stdout));
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(false); cin.tie(NULL);
#endif
    //cout << fixed << setprecision(precision);
    int tc = 1;
    //cin >> tc;
    for(int _ = 1; _ <= tc; _++){
        solve(_);
    }
    return 0;
}


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

int main(){
  long long int k, n, ans = 0;
  cin >> k >> n;

  vector<int> a(n);

  for (int i = 0; i < n; i++) {
    cin >> a[i];
    if (i != 0 && a[i] - a[i-1] > ans) ans = a[i] - a[i-1];
  }
  if (a[0] + k - a[n-1] > ans) ans = a[0] + k - a[n-1];

  cout << k - ans << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define MOD 1000000007
#define pb push_back 
#define ins insert
#define fast(); ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
int m(int a) {
    return ((a%MOD)+MOD)%MOD;
}
int p(int a, int b) {
    if (b==0) return (int)1;
    int x = p(a, b>>1);
    if (b & 1) return m(x*m(a*x));
    return m(x*x);
}
signed main(){
    fast();
    int n, m;
    cin >> n >> m;
    vector<vector<string>> a(n+1);
    int loss = 0, win = 0; 
    for(int i=0; i<m; i++){
        int f; string s;
        cin >> f >> s;
        a[f].pb(s);
    }
    for(auto i: a){
        int pen = 0;
        for(auto j: i){
            if(j == "WA")   pen++;
            else{
                win++;
                loss += pen;
                break;
            }
        }
    }
    cout << win << " " << loss << endl;
} 

Measured memory_bytes: 10368
N = int(input())
A = list(map(int,input().split()))
Q = int(input())
B = [0]*Q
C = [0]*Q
for i in range(Q):
    B[i],C[i] = map(int, input().split())

S = sum(A)
num_dict = {i:0 for i in range(1,100001)}
for i in range(N):
    num_dict[A[i]] += 1

S_dif = 0
for i in range(Q):
    S_dif = (C[i] - B[i])*num_dict[B[i]]
    num_dict[C[i]] += num_dict[B[i]]
    num_dict[B[i]] = 0
    S += S_dif
    print(S)

Measured memory_bytes: 32180
/* #region template */
#![allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, stdout, Bytes, Read, Stdin, StdinLock, Stdout, StdoutLock, Write};
use std::iter::{repeat, repeat_with};
use std::mem::swap;
use std::str::FromStr;
#[allow(dead_code)]
struct Io<'a> {
    reader: Bytes<StdinLock<'a>>,
    writer: StdoutLock<'a>,
    in_buf: [u8; BUF_SIZE],
}
#[allow(dead_code)]
impl<'a> Io<'a> {
    fn new(stdin: &'a Stdin, stdout: &'a Stdout) -> Io<'a> {
        Io {
            reader: stdin.lock().bytes(),
            writer: stdout.lock(),
            in_buf: [0; BUF_SIZE],
        }
    }
    fn r<T: FromStr>(&mut self) -> T {
        let mut count = 0;
        loop {
            match self.reader.next() {
                Some(Ok(b' ')) | Some(Ok(b'\n')) => break,
                Some(Ok(c)) => self.in_buf[count] = c,
                _ => panic!(),
            }
            count += 1;
        }

        let s = unsafe { std::str::from_utf8_unchecked(&self.in_buf[0..count]) };
        s.parse().unwrap_or_else(|_| panic!())
    }
    fn ru(&mut self) -> usize {
        self.r()
    }
    fn iter<'b, T>(&'b mut self) -> IoIter<'a, 'b, T> {
        IoIter::new(self)
    }
    fn c<T: FromStr>(&mut self, n: usize) -> Vec<T> {
        self.iter().take(n).collect()
    }
    fn cu(&mut self, n: usize) -> Vec<usize> {
        self.c(n)
    }
    fn w<T: std::fmt::Display>(&mut self, v: T) {
        writeln!(self.writer, "{}", v).unwrap();
    }
    fn wn<T: std::fmt::Display>(&mut self, v: T) {
        write!(self.writer, "{}", v).unwrap();
    }
}
#[allow(dead_code)]
struct IoIter<'a: 'b, 'b, T> {
    io: &'b mut Io<'a>,
    m: std::marker::PhantomData<T>,
}
#[allow(dead_code)]
impl<'a: 'b, 'b, T> IoIter<'a, 'b, T> {
    fn new(io: &'b mut Io<'a>) -> IoIter<'a, 'b, T> {
        IoIter {
            io,
            m: std::marker::PhantomData,
        }
    }
}
impl<'a, 'b, T: FromStr> Iterator for IoIter<'a, 'b, T> {
    type Item = T;
    fn next(&mut self) -> Option<Self::Item> {
        Some(self.io.r())
    }
}
fn main() {
    let stdin = stdin();
    let stdout = stdout();
    let mut io = Io::new(&stdin, &stdout);
    unsafe {
        solve(&mut io);
    }
}
/* #endregion */

const BUF_SIZE: usize = 1024;

unsafe fn solve(io: &mut Io) {
    match &*io.r::<String>() {
        "ABC" => io.w("ARC"),
        "ARC" => io.w("ABC"),
        _ => {}
    }
}


Measured memory_bytes: 2116
using System;
using System.Collections.Generic;
using System.Linq;

class Program
{
    static void Main(string[] args)
    {
        var nk = Console.ReadLine().Split(' ');
        var n = long.Parse(nk[0]);
        var k = long.Parse(nk[1]);
        var hs = new HashSet<int>();
        for (var i = 0; i < k; i++)
        {
            Console.ReadLine();
            foreach (var a in Console.ReadLine().Split(' '))
            {
                hs.Add(int.Parse(a));
            }
        }

        Console.WriteLine(n - hs.Count);
    }
}


Measured memory_bytes: 20376
w, h, n=map(int, input().split())
xa=0
xb=w
ya=0
yb=h
for _ in range(n):
  x, y, a=map(int, input().split())
  if a==1:
    xa=max(x, xa)
  if a==2:
    xb=min(x, xb)
  if a==3:
    ya=max(y, ya)
  if a==4:
    yb=min(y, yb)
    
print(max(max(xb-xa, 0)*max(yb-ya, 0), 0))

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

#define SORT(c) sort((c).begin(),(c).end())
#define REVERSE(v) reverse((v).begin(),(v).end())
#define ANS(ans) cout<<(ans)<<endl;
#define UNIQUE(v) (v).erase(unique((v).begin(), (v).end()), (v).end());
typedef vector<int> VI;
typedef pair<int, int> P;
 
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<=(b);++i)
#define REP(i,n)  for (int i = 0; i < (n); ++i)

int main() {
    int h,n;
    cin >> h >> n;

    VI v(n);
    REP(i,n){
        cin >> v[i];
    }
    long long sum = 0;
    REP(i,n){
        sum += v[i];
    }

    if(sum>=h){
        ANS("Yes");
    }
    else{
        ANS("No");
    }

    return 0;
}


Measured memory_bytes: 768
import java.util.Scanner;
//B - 文字列大好きいろはちゃんイージー / Iroha Loves Strings (ABC Edition)

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

		String str = sc.next(); //文字列ｓを標準入力する
		
		int cnt = 0;

		for (char c = 'a' ; c <= 'z'; c++) {
			for (int i = 0; i < str.length(); i++) {
				if (str.charAt(i) == c) {
	                cnt ++;
				}
			}
			if (cnt % 2 != 0) {
				System.out.println("No");
				return;
			}
		}
		System.out.println("Yes");
	}
}


Measured memory_bytes: 22608
n=int(input())
dp={}
def f(i,last4):
    if i==n:
        return 1
    else:
        if (i,last4) in dp:
            return dp[(i,last4)]
        else:
            addA=f(i+1,last4[1:4]+'A')
            addT=f(i+1,last4[1:4]+'T')
            if not last4[2:4]=='AC':
                addG=f(i+1,last4[1:4]+'G')
            else:
                addG=0
            if not (last4[2:4]=='AG' or last4[2:4]=='GA' or last4[1:4]=='ATG' or last4[1:4]=='AGG' or last4[1:4]=='AGT'):
                addC=f(i+1,last4[1:4]+'C')
            else:
                addC=0
            answer=addA+addT+addG+addC
            dp[(i,last4)]=answer
            return answer
print(f(0,'SSSS')%(10**9+7))
        
        
        


Measured memory_bytes: 51032
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n) - 1; i >= 0; i--)
#define range(a) a.begin(), a.end()

constexpr int MOD = 998244353;

class mint {
  int n;
public:
  mint(int n_ = 0) : n(n_) {}
  explicit operator int() { return n; }
  friend mint operator-(mint a) { return -a.n + MOD * (a.n != 0); }
  friend mint operator+(mint a, mint b) { int x = a.n + b.n; return x - (x >= MOD) * MOD; }
  friend mint operator-(mint a, mint b) { int x = a.n - b.n; return x + (x < 0) * MOD; }
  friend mint operator*(mint a, mint b) { return (long long)a.n * b.n % MOD; }
  friend mint &operator+=(mint &a, mint b) { return a = a + b; }
  friend mint &operator-=(mint &a, mint b) { return a = a - b; }
  friend mint &operator*=(mint &a, mint b) { return a = a * b; }
  friend bool operator==(mint a, mint b) { return a.n == b.n; }
  friend bool operator!=(mint a, mint b) { return a.n != b.n; }
  friend istream &operator>>(istream &i, mint &a) { return i >> a.n; }
  friend ostream &operator<<(ostream &o, mint a) { return o << a.n; }
};

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(15);
  int H, W, K; cin >> H >> W >> K;
  vector<string> S(H); rep(i, H) cin >> S[i];
  int ans = INT_MAX;
  rep(s, 1 << (H - 1)) {
    int cand = 0;
    vector<int> pos;
    pos.push_back(0);
    rep(i, H - 1) if (s >> i & 1) pos.push_back(i + 1);
    pos.push_back(H);
    const int m = pos.size() - 1;
    vector<int> now(m);
    cand += m - 1;
    bool imp = false;
    rep(j, W) {
      bool over = false;
      rep(k, m) {
        for (int i = pos[k]; i < pos[k + 1]; i++) {
          now[k] += S[i][j] - '0';
        }
        if (now[k] > K) {
          over = true;
        }
      }
      if (over) {
        cand++;
        over = false;
        rep(k, m) now[k] = 0;
        rep(k, m) {
          for (int i = pos[k]; i < pos[k + 1]; i++) {
            now[k] += S[i][j] - '0';
          }
          if (now[k] > K) {
            over = true;
          }
        }
        if (over) {
          imp = true;
        }
      }
    }
    if (!imp) {
      ans = min(ans, cand);
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <string>
#include <iomanip>
# define M_PIl        3.141592653589793238462643383279502884
using namespace std;

typedef long long ll;
typedef long double ld;

int main(){
  string s,t;
  cin >> s >> t;
  ll ans=0;
  for(ll i=0;i<s.size();i++){
    if(s[i]!=t[i]){
      ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3468
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(std::string s, std::string t)
{
    ll ans = 0;
    vector<vector<int>> index(28);
    for (int i = 0; i < s.size(); i++)
    {
        index[(int)s[i] - 'a'].push_back(i);
    }

    int now = -1;
    ll loop = 1;
    for (int i = 0; i < t.size(); i++)
    {
        char c = t[i];
        if (index[(int)c - 'a'].size() == 0)
        {
            cout << -1 << endl;
            return;
        }
        auto iter = upper_bound(index[(int)c - 'a'].begin(), index[(int)c - 'a'].end(), now);

        if (index[(int)c - 'a'].end() - iter == 0)
        {
            loop++;
            now = index[(int)c - 'a'][0];
        }
        else
        {
            now = *iter;
        }
    }

    cout << (loop-1) * s.size() + now + 1 << endl;
}

int main()
{
    std::string s;
    std::cin >> s;
    std::string t;
    std::cin >> t;
    solve(s, t);
    return 0;
}


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

int n, a[200000];

int main() {
    cin >> n;
    for (int i = 0; i < n; i++) scanf("%d", &a[i]);
    for (int i = n - 1; i >= 0; i -= 2) {
        if (i != n - 1) cout << " ";
        cout << a[i];
    }
    for (int i = n % 2; i < n; i += 2) cout << " " << a[i];
    cout << endl;
    return 0;
}

Measured memory_bytes: 2944
object Main extends App {
  val Array(a, b, c, x) = Iterator.continually(io.StdIn.readLine.toInt)
    .take(4).toArray

  val ans = {
    var cnt = 0
      for {
        i <- 0 to a
        if 500*i <= x
        j <- 0 to b
        if 500*i + 100*j <= x
        k <- 0 to c
        if 500*i + 100*j + 50*k == x
      } {cnt += 1}
    cnt
  }

  println(ans)
}

Measured memory_bytes: 27460
#include <bits/stdc++.h>
using namespace std;
const int inf=1e2+9,MX=1e5+9;
bool dp[MX];
int a[inf];
int main(){
    int n,k;
    cin>>n>>k;
    for(int i=1;i<=n;i++)
        cin>>a[i];

    for(int i=1;i<=k;i++)
        for(int j=1;j<=n;j++)
            if(i>=a[j])
                dp[i]|=!dp[i-a[j]];

    cout<<(dp[k]?"First":"Second")<<endl;

}


Measured memory_bytes: 384
import java.util.*

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)
    val n = sc.nextLong()
    println(problem114c(n))
}

fun problem114c(n: Long): Long {
    var count = 0L
    fun counter(current: Long, use: Long, used: HashSet<Long>) {
        if (current > n) return
        used.add(use)
        if (used.contains(3) && used.contains(5) && used.contains(7)) {
            count++
        }

        counter(current * 10 + 7, 7, HashSet(used))
        counter(current * 10 + 5, 5, HashSet(used))
        counter(current * 10 + 3, 3, HashSet(used))
    }

    counter(0L, 0, HashSet())
    return count
}

Measured memory_bytes: 47844
#include <iostream>
#include <algorithm>
#include <map>
#include <regex>
#include <string>
#include <cstdlib>
#include <math.h>
#include <vector>
using namespace std;
int main() {
  char C;
  cin >> C;
  C++;
  cout << C << endl;
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize(3)
#include<bits/stdc++.h>
#define MAXN 5005
#define INF 1000000000000000000LL
#define MOD 1000000007
#define F first
#define S second
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
ll n,a[MAXN],sz[MAXN],dp[MAXN][MAXN][2];
ll cur[MAXN][2],upd[MAXN][2];
vector<int> G[MAXN];
void dfs(ll v,ll p)
{
    sz[v]=1;
    for(auto to:G[v])
    {
        if(to==p) continue;
        dfs(to,v);
    }
    if(a[v]>0)
    {
        cur[0][0]=a[v];
        cur[0][1]=a[v];
    }
    else
    {
        cur[0][0]=INF;
        cur[0][1]=a[v];
    }
    for(auto to:G[v])
    {
        if(to==p) continue;
        for(ll i=0;i<n;i++) upd[i][0]=upd[i][1]=INF;
        for(ll j=0;j<sz[to];j++)
        {
            if(dp[to][j][0]!=INF)
            {
                for(ll i=0;i<sz[v];i++) if(cur[i][0]!=INF) upd[i+j][0]=min(upd[i+j][0],cur[i][0]+dp[to][j][0]);
                for(ll i=0;i<sz[v];i++) upd[i+j][1]=min(upd[i+j][1],cur[i][1]+dp[to][j][0]);
                for(ll i=0;i<sz[v];i++) if(cur[i][0]!=INF) upd[i+j+1][0]=min(upd[i+j+1][0],cur[i][0]);
                for(ll i=0;i<sz[v];i++) if(cur[i][1]!=INF) upd[i+j+1][1]=min(upd[i+j+1][1],cur[i][1]);
            }
            if(dp[to][j][1]!=INF)
            {
                for(ll i=0;i<sz[v];i++) if(cur[i][0]!=INF) upd[i+j][1]=min(upd[i+j][1],cur[i][0]+dp[to][j][1]);
                for(ll i=0;i<sz[v];i++) upd[i+j][1]=min(upd[i+j][1],cur[i][1]+dp[to][j][1]);
            }
            if(dp[to][j][1]<0)
            {
                for(ll i=0;i<sz[v];i++) if(cur[i][0]!=INF) upd[i+j+1][0]=min(upd[i+j+1][0],cur[i][0]);
                for(ll i=0;i<sz[v];i++) if(cur[i][1]!=INF) upd[i+j+1][1]=min(upd[i+j+1][1],cur[i][1]);
            }
        }
        sz[v]+=sz[to];
        for(ll i=0;i<sz[v];i++) cur[i][0]=upd[i][0],cur[i][1]=upd[i][1];
    }
    for(ll i=0;i<sz[v];i++) dp[v][i][0]=cur[i][0],dp[v][i][1]=cur[i][1];
}
int main()
{
    scanf("%lld",&n);
    for(ll i=1;i<=n;i++) scanf("%lld",&a[i]);
    for(ll i=0;i<n-1;i++)
    {
        ll u,v;
        scanf("%lld%lld",&u,&v);
        G[u].push_back(v);G[v].push_back(u);
    }
    dfs(1,0);
    ll ans=INF;
    for(ll i=0;i<=n-1;i++)
    {
        //printf("%lld %lld\n",dp[1][i][0],dp[1][i][1]);
        if(dp[1][i][0]!=INF) ans=min(ans,i);
        if(dp[1][i][1]<0) ans=min(ans,i);
    }
    printf("%lld\n",ans);
    return 0;
}



Measured memory_bytes: 391424
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60


class UnionFind:
    # Reference: https://note.nkmk.me/python-union-find/
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

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

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

        if x == y:
            return

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

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

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


N, M, *AB = map(int, read().split())
uf = UnionFind(N)
ans = [N * (N - 1) // 2]

for a, b in zip(AB[-2:0:-2], AB[-1:1:-2]):
    a -= 1
    b -= 1
    if uf.same(a, b):
        ans.append(ans[-1])
    else:
        ans.append(ans[-1] - uf.parents[uf.find(a)] * uf.parents[uf.find(b)])
        uf.union(a, b)

print(*reversed(ans), sep='\n')


Measured memory_bytes: 115060
#include <bits/stdc++.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string.h>
#include <tuple>

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

void solve(){
  int a, b;
  cin >> a >> b;
  if(6 <= a && a <= 12) b /= 2;
  if(a <= 5) b = 0;
  cout << b << endl;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define NINZU 50

int main(void)
{
   int m[NINZU], f[NINZU], 
       r[NINZU], gou[NINZU],q;
   int i = 0;
   
   while(!(m[i-1]==-1 && f[i-1]==-1 && r[i-1]==-1)){
      scanf("%d", &m[i]);
      scanf("%d", &f[i]);
      scanf("%d", &r[i]);
      
      gou[i] = m[i] + f[i];
      
      i++;}
      
   for(q=0; q<i-1; q++){
      if(m[q]==-1 || f[q]==-1){
         printf("F\n");}
      else if(gou[q]>=80){
         printf("A\n");}
      else if(gou[q]>=65 && gou[q]<80){
         printf("B\n");}
      else if(gou[q]>=50 && gou[q]<65){
         printf("C\n");}
      else if(gou[q]>=30 && gou[q]<50){
         if(r[q]>=50){
            printf("C\n");}
         else{
            printf("D\n");}}
      else{
         printf("F\n");}}
   
   return 0;
}


Measured memory_bytes: 2040
#include <bits/stdc++.h>
#define int long long
using namespace std;
using PII = pair<int, int>;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;

const int MAX = 1000000;

int fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

int COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

signed main() {
    double x, y;
    cin >> x >> y;
    double n = (-1.0 * x + 2.0 * y) / 3.0;
    double m = (2.0 * x - 1.0 * y) / 3.0;
    if (n - floor(n) != 0 || m - floor(m) != 0) {
        cout << 0 << "\n";
        return 0;
    }
    COMinit();
    int ni = (int)floor(n);
    int mi = (int)floor(m);
    cout << COM(ni + mi, ni) << "\n";
}

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

using namespace std;

int n, a[100000], ans = 0;
char dp[100000];
long long b[100000];

bool can(int now){
  if(now == n) return true;
  if(~dp[now]) return dp[now];
  if(b[now] * 2 >= (b[now + 1] - b[now])) return dp[now] = can(now + 1);
  return dp[now] = false;
}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(0);
  cin >> n;
  memset(dp, -1, sizeof(dp));
  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  sort(a, a + n);
  b[0] = a[0];
  for(int i = 1; i < n; i++){
    b[i] = b[i - 1] + a[i];
  }
  for(int i = 0; i < n; i++){
    ans += can(i);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 3072