akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<cmath>
#include<algorithm>
#include<vector>

using namespace std;

int main(){

    int n;

    cin >> n;

    int a[n];
    for(int i=0;i<n;i++)cin >> a[i];

    int q;
    cin >> q;

    int m[q];
    for(int i=0;i<q;i++)cin >> m[i];

    bool e[q];
    for(int i=0;i<q;i++) e[i] = false;

    for(int b=0;b<(1<<n);b++){
        int s=0;
        for(int i=0;i<n;i++){
            if( b & (1<<i)) s += a[i];
        }
        for(int i=0;i<q;i++){
            if(s==m[i])e[i]=true;
        }
    }

    for(int i=0;i<q;i++){
        string s;
        if(e[i]) s="yes";
        else s="no";
        cout << s << endl;
    }

}


Measured memory_bytes: 3192
#include <stdio.h>
#include <ctype.h>

unsigned long long tomorinao(void) {
	unsigned long long utidamaaya = 0;
	int kokoa;
	for(;;) {
		kokoa = getchar();
		if (kokoa == EOF || !isdigit(kokoa)) break;
		utidamaaya = utidamaaya * 10 + (kokoa - '0');
	}
	return utidamaaya;
}

int main(void) {
	unsigned long long ayaneru = tomorinao();
	int riesyonn = 0;
	while (ayaneru > 0) {
		ayaneru >>= 1;
		riesyonn++;
	}
	printf("%d\n", riesyonn);
	return 0;
}

Measured memory_bytes: 524
#define LOCAL

#undef _GLIBCXX_DEBUG

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

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define LLINF 100000000000000005LL
#define INF (int)1e9+1

// Copied from Gennady-Korotkevich's template

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
	return '"' + s + '"';
}

string to_string(const char* s) {
	return to_string((string)s);
}

string to_string(bool b) {
	return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
	bool first = true;
	string res = "{";
	for (int i = 0; i < static_cast<int>(v.size()); i++) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(v[i]);
	}
	res += "}\n";
	return res;
}

template <size_t N>
string to_string(bitset<N> v) {
	string res = "";
	for (size_t i = 0; i < N; i++) {
		res += static_cast<char>('0' + v[i]);
	}
	return res;
}

template <typename A>
string to_string(A v) {
	bool first = true;
	string res = "{";
	for (const auto& x : v) {
		if (!first) {
			res += ", ";
		}
		first = false;
		res += to_string(x);
	}
	res += "}\n";
	return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
	return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

template <typename A, typename B, typename C, typename D, typename E>
string to_string(tuple<A, B, C, D, E> p) {
	return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + "," + to_string(get<4>(p)) + ")";
}

void debug_out() {
	cerr << endl;
}

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
	cerr << " " << to_string(H);
	debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "\n[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

// End of Gennady-Korotkevich's template 

using llong = long long;
using PII = pair<int, int>;

int main() {
	IOS;
	int m1, d1, m2, d2;
	cin >> m1 >> d1 >> m2 >> d2;
	if (m1 != m2) cout << 1;
	else cout << 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdio>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <map>
#include <string.h>
#include <cstring>
 
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    
    long long h[n];
    for(int i=0; i<n; i++) cin >> h[i];
    
    bool flag[n];
    fill(flag, flag+n, true);
    
    for(int i=0; i<m; i++){
        long long a, b;
        cin >> a >> b;
        if(h[a-1]>h[b-1]) flag[b-1]=false;
        else if(h[a-1]<h[b-1]) flag[a-1]=false;
        else if(h[a-1]==h[b-1]){
            flag[a-1]=false;
            flag[b-1]=false;
        }
    }
    
    long long ans=0;
    for(int i=0; i<n; i++){
        if(flag[i]) ans++;
    }
    cout << ans << endl;
    return 0;
 }


Measured memory_bytes: 4484
#include<iostream>


using namespace std;


int main(){
	double left,right;
	int Lnin[4]={}, Rnin[4]={};
	int i;

	while(cin >> left >> right){
		if(left>=1.1){
			Lnin[0]++;
		}else if(left>=0.6){
			Lnin[1]++;
		}else if(left>=0.2){
			Lnin[2]++;
		}else{
			Lnin[3]++;
		}

		if(right>=1.1){
			Rnin[0]++;
		}else if(right>=0.6){
			Rnin[1]++;
		}else if(right>=0.2){
			Rnin[2]++;
		}else{
			Rnin[3]++;
		}
	}

	for(i=0;i<=3;i++){
		cout << Lnin[i] << " " << Rnin[i] << endl;
	}
	



}

Measured memory_bytes: 1224
#include<bits/stdc++.h>
using namespace std;
const int maxN=1e5+100;
const long long int inf=1e12;
long long int n,ans,temp;
long long int arr[maxN];
int main()
{
    string s;
    cin>>s;
    n=s.length();
    if(n<=3)    return cout<<"No"<<endl,0;
    if(s[0]=='Y' && s[1]=='A' && s[2]=='K' && s[3]=='I')   cout<<"Yes"<<endl;
    else        cout<<"No"<<endl;
return 0;
}

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

int main()
{
    ll X; cin >> X;
    ll money=100;
    int i=1;
    while (money<X)
    {
        money=money*1.01;
        i++;
    }
    cout << i-1 << endl;
    return 0;
}

Measured memory_bytes: 3600
import java.util.*;

public class Main {

    public static void main(String args[]) {

        // 入力
        Scanner sc = new Scanner(System.in);
        int x = Integer.parseInt(sc.next());

        // 主処理
        int uresi1 = x / 500;
        x = x % 500;
        int uresi2 = x / 5;
        int result = 1000 * uresi1 + 5 * uresi2;

        // 出力
        System.out.println(result);
        sc.close();
    }
}


Measured memory_bytes: 22228
#![allow(unused, non_snake_case, dead_code, non_upper_case_globals)]
use {
    proconio::{marker::*, *},
    std::{cmp::*, collections::*, mem::*},
};

#[fastout]
fn main() {
    input! {
        n:usize,
        xy:[(Usize1,Usize1);n-1],
    }
    let mut v = vec![vec![]; n];
    for &(x, y) in xy.iter() {
        v[x].push(y);
        v[y].push(x);
    }
    // // root = 0
    // //
    // let mut dp = vec![vec![0; 2]; n + 1];//dp[i][j] := i
    // let mut q = VecDeque::new();
    let mut g = G::new(&v);
    g.dfs(0, !0);
    println!("{}", (g.dp[0][0] + g.dp[0][1]) % MOD);
}
struct G {
    n: usize,
    v: Vec<Vec<usize>>,
    dp: Vec<Vec<i64>>,
}
impl G {
    fn new(v: &Vec<Vec<usize>>) -> G {
        G {
            n: v.len(),
            v: v.clone(),
            dp: vec![vec![0i64; 2]; v.len()],
        }
    }
    fn dfs(&mut self, now: usize, prev: usize) {
        self.dp[now][0] = 1;
        self.dp[now][1] = 1;

        for &nx in self.v[now].clone().iter() {
            if nx != prev {
                self.dfs(nx, now);
                self.dp[now][0] = self.dp[now][0] * (self.dp[nx][0] + self.dp[nx][1]) % MOD;
                self.dp[now][1] = self.dp[now][1] * self.dp[nx][0] % MOD;
            }
        }
    }
}
const MOD: i64 = 1000000007;


Measured memory_bytes: 32072
package main

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

var (
	edges  map[int]map[int]int
	colors []int
)

func dfs(v, d int) {
	if colors[v-1] > 0 {
		return
	}
	colors[v-1] = d + 2
	for u, w := range edges[v] {
		if w > 0 {
			dfs(u, (d+w)%2)
		}
	}
}

func main() {
	var n int
	fmt.Scan(&n)
	edges = make(map[int]map[int]int, n)
	for i := 1; i <= n; i++ {
		edges[i] = make(map[int]int)
	}
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < n-1; i++ {
		sc.Scan()
		u, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		v, _ := strconv.Atoi(sc.Text())
		sc.Scan()
		w, _ := strconv.Atoi(sc.Text())
		edges[u][v] = w
		edges[v][u] = w
	}

	colors = make([]int, n)
	dfs(1, 0)

	wr := bufio.NewWriter(os.Stdout)
	for _, v := range colors {
		wr.WriteString(strconv.Itoa(v-2) + "\n")
	}
	wr.Flush()
}


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

typedef struct dice_struct{
    int num[6], temp;
}dice_struct;

void throw_dice(dice_struct *dice, char order) {
    switch (order) {
        case 'R':
            dice->temp = dice->num[1];
            dice->num[1] = dice->num[3];
            dice->num[3] = dice->num[4];
            dice->num[4] = dice->num[2];
            dice->num[2] = dice->temp;
            break;
        case 'E':
            dice->temp = dice->num[0];
            dice->num[0] = dice->num[3];
            dice->num[3] = dice->num[5];
            dice->num[5] = dice->num[2];
            dice->num[2] = dice->temp;
            break;
        case 'S':
            dice->temp = dice->num[0];
            dice->num[0] = dice->num[4];
            dice->num[4] = dice->num[5];
            dice->num[5] = dice->num[1];
            dice->num[1] = dice->temp;
            break;
        case 'W':
            dice->temp = dice->num[0];
            dice->num[0] = dice->num[2];
            dice->num[2] = dice->num[5];
            dice->num[5] = dice->num[3];
            dice->num[3] = dice->temp;
            break;
        case 'N':
            dice->temp = dice->num[0];
            dice->num[0] = dice->num[1];
            dice->num[1] = dice->num[5];
            dice->num[5] = dice->num[4];
            dice->num[4] = dice->temp;
            break;            
    }
        
}

int isSame(dice_struct dice1, dice_struct dice2) {
    static const char order[] = "NNNESSSWNNNESSSWNNNESSSW";
    int i, j;
    for (i = 0; i < 24; i++) {
        j = 0;
        while(j < 6 && dice1.num[j] == dice2.num[j]) {
            j++;
        }
        if (j == 6) {
            return 1;
        }
        throw_dice(&dice2, order[i]);
    }
    return 0;
}

int main(int argc, char const *argv[]) {
    int i, j, n;
    dice_struct d[100];
    scanf("%d", &n);

    for (i = 0; i < n; i++) {
        for (j = 0; j < 6; j++) {
            scanf("%d", &d[i].num[j]);
        }
        for (int j = 0; j < i; j++) {
            if (isSame(d[i], d[j])) {
                printf("No\n");
                return 0;
            }
        }
    }
    printf("Yes\n");
    return 0;
}


Measured memory_bytes: 2100
// AOJ GRL_5_C Lowest Common Ancestor
// 2018.5.5 bal4u

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

#if 1
#define gc() getchar_unlocked()
#define pc(c) putchar_unlocked(c)
#else
#define gc() getchar()
#define pc(c) putchar(c)
#endif

int in()
{
	int n = 0, c = gc();
	do n = 10*n + (c & 0xf), c = gc(); while (c >= '0');
	return n;
}

void out(int n)
{
	int i;
	char ob[20];

	if (!n) pc('0');
	else {
//		if (n < 0) pc('-'), n = -n;
		i = 0; while (n) ob[i++] = n%10 + '0', n/=10;
		while (i--) pc(ob[i]);
	}
	pc('\n');
}


#define INF 0x30303030

// セグメント木の初期化
int seg[1<<19][2]; int sz;

void segtree(int n, int init_val)
{
	int i;

	sz = 2; while (sz < n) sz <<= 1;
	n = sz << 1;
//	memset(seg, init_val, n << 2);
	for (i = 0; i < n; i++) seg[i][0] = init_val;
}

// RMQのインデックス部分を一括して更新
void update()
{
	int i, k, n, p;

	n = sz;	while (n > 0) {
		for (p = n-1, i = 0; i < n; i+=2, p+=2) {
			k = p >> 1;
			if (seg[p][0] <= seg[p+1][0]) {
				seg[k][0] = seg[p  ][0], seg[k][1] = seg[p  ][1];
			} else {
				seg[k][0] = seg[p+1][0], seg[k][1] = seg[p+1][1];
			}
		}
		n >>= 1;
	}
}


int query2(int a, int b, int k, int l, int r, int *id) 
{
	int m, lmin, rmin;
	int lid, rid;

	if (r <= a || b <= l) { *id = 0; return INF; }
	if (a <= l && r <= b) { *id = seg[k][1]; return seg[k][0]; }
	k <<= 1, m = (l+r) >> 1;
    lmin = query2(a, b, k+1, l, m, &lid);
    rmin = query2(a, b, k+2, m, r, &rid);
	if (lmin > rmin) lmin = rmin, lid = rid;
	*id = lid;
    return lmin; 
}

// 空間 [a, b] 内の最小値
int range_min_query(int a, int b)
{
	int id;
	query2(a, b+1, 0, 0, sz, &id);
	return id;
}


// LCA
#define MAX_V  100005
int hi[MAX_V], *to[MAX_V];
int root;
int vs[MAX_V << 1];
int depth[MAX_V << 1];
int id[MAX_V];

void dfs(int v, int p, int d, int *k)
{
	int i;

	id[v] = *k;
	vs[*k] = v;
	depth[(*k)++] = d;
	for (i = 0; i < hi[v]; i++) {
		if (to[v][i] != p) {
			dfs(to[v][i], v, d+1, k);
			vs[*k] = v;
			depth[(*k)++] = d;
		}
	}
}

int lca(int u, int v)
{
	int min, max;
	if (id[u] < id[v]) min = id[u], max = id[v];
	else               min = id[v], max = id[u];
	return vs[range_min_query(min, max)];
}

int main()
{
	int n, q, i, j, k, u, v;
	int *memo;

	n = in();
	memo = malloc(n<<3);
	i = 0; for (u = 0; u < n; u++) {
		k = in();
		for (j = 0; j < k; j++) {
			memo[i++] = u, memo[i++] = v = in();
			hi[u]++, hi[v]++;
		}
	}

	for (u = 0; u < n; u++) if (hi[u]) to[u] = malloc(hi[u]<<2);
	memset(hi, 0, n<<2);
	j = 0; while (j < i) {
		u = memo[j++], v = memo[j++];
		to[u][hi[u]++] = v, to[v][hi[v]++] = u;
	}

	root = 0, k = 0;
	dfs(root, -1, 0, &k);

	n = (n<<1)-1;
	segtree(n, INF);

	j = sz-1;
	for (u = 0; u < n; u++) seg[j][0] = depth[u], seg[j++][1] = u;
	update();

	q = in();
	while (q--) {
		u = in(), v = in();
		out(lca(u, v));
	}
	return 0;
}


Measured memory_bytes: 20568
#include <bits/stdc++.h>
using namespace std;
using lint = long long;


int main() {
  ios::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);

  int N, K;
  cin >> N >> K;
  vector<int> deg(N);
  for (int i = 0; i < K; i++) {
    int k;
    cin >> k;
    while (k--) {
      int a;
      cin >> a;
      deg[--a]++;
    }
  }

  int ans = 0;
  for (int i = 0; i < N; i++) if (deg[i] == 0) ans++;
  cout << ans << "\n";

}


Measured memory_bytes: 3652
//  ROAD TO GREEN
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>

using namespace std;
typedef long long ll;
const ll MAXN = 1e5+2;
vector<bool> used(MAXN,false);
int a[MAXN];
int dp[3][MAXN];

int main(){
    int n,m;
    cin >> n >> m;
    priority_queue<int> q;
    for(int i = 1; i <= n; i++){
        int x; cin >> x;
        q.push(x);
    }
    for(int i = 1; i <= m; i++){
        int a = q.top();
        q.pop();
        q.push(a/2);
    }
    ll sum = 0;
    for(int i = 1; i <= n; i++){
        sum += q.top();
        q.pop();
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
const int N = 1e6+100;
const int mod = 1e9+7;
typedef long long ll;
const int INF = 0x3f3f3f3f;
const ll llINF = 0x3f3f3f3f3f3f3f3f;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define fep(i,a,b) for(int i=(a);i>=(b);i--)
inline bool read(ll &num) {
    char in;bool IsN=false;
    in=getchar();
    if(in==EOF) return false;
    while(in!='-'&&(in<'0'||in>'9')) in=getchar();
    if(in=='-'){ IsN=true;num=0;}
    else num=in-'0';
    while(in=getchar(),in>='0'&&in<='9'){
            num*=10,num+=in-'0';
    } 
    if(IsN) num=-num;
    return true;
}
int main(){
    //freopen("1.in", "r", stdin);
    double a,b;
    cin>>a>>b;
    cout<<ceil((b-1)/(a-1))<<endl;
    // for(int i=1;;i++){
    //     if(a*i-(i-1)>=b){
    //         cout<<i<<endl;
    //         return 0;
    //     }
    // }
    return 0;
}

Measured memory_bytes: 256
let rec upper_bound l r p =
  if r <= 1 + l
  then l
  else let m = (l + r) / 2 in
       if p m 
       then upper_bound m r p
       else upper_bound l m p

let () = Scanf.scanf "%d %d\n" @@ fun n k ->
  let as_ = Array.init (n + 1) @@ function
    | 0 -> 0
    | _ -> Scanf.scanf "%d " @@ fun a -> a in
  Array.sort compare as_;
  let bs = Array.make k false in
  bs.(0) <- true;
  Printf.printf "%d\n" @@ upper_bound 0 (n + 1) @@ fun i ->
    if k <= as_.(i) then false
    else begin
      Array.fill bs 1 (k - 1) false;
      Array.iteri (fun j a ->
        if i <> j then
          for a' = k - 1 downto a do
            bs.(a') <- bs.(a') || bs.(a' - a)
          done) as_;
      try
        for a = k - as_.(i) to k - 1 do
          if bs.(a) then raise Not_found
        done; true
      with Not_found -> false
    end


Measured memory_bytes: 4480
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>


using namespace std;


int main() {
    int n, t, a, ans;
    cin >> n >> t >> a;
    int h[n];
    double temperature[n];
    for (int i = 0; i < n; ++i) {
        cin >> h[i];
        temperature[i] = t - h[i] * 0.006;
    }
    double dt[n], tmp = 1000;
    for (int j = 0; j < n; ++j) {
        dt[j] = abs(a - temperature[j]);
    }

    for (int k = 0; k < n; ++k) {
        if (dt[k] < tmp) {
            tmp = dt[k];
            ans = k + 1;
        }
    }


    cout << ans;
    return 0;
}

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

using namespace std;

long a[3333], d[3333][3333];
int main() {
	int n;
	cin >> n;
	for (int i = 0; i < n; i++)
		cin >> a[i];
	for (int i = 1; i < n + 1; i++)
		for (int j = 0; j < n - i + 1; j++)
			d[j][i] = max(a[j] - d[j + 1][i - 1], a[j + i - 1] - d[j][i - 1]);
	cout << d[0][n] << endl;
	return 0;
}


Measured memory_bytes: 80128
//created by pyoxiao on 2020/05/03
#include<bits/stdc++.h>
#define LL long long
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define CL(a, b) memset(a, b, sizeof(a))
using namespace std;
const int mod = 1e9 + 7;
LL fpow(LL a, LL b, LL p = mod){LL ans = 1; a %= p; while(b) {if(b & 1) ans = ans * a % p; b >>= 1; a = a * a % p;} return ans;}
LL gcd(LL a, LL b){return b == 0 ? a : gcd(b, a % b);}
const int N = 2e5 + 7;
int n, a[N];
map<int, int> st;
void solve() {
    scanf("%d", &n);
    for(int i = 1; i <= n; i ++) {
        scanf("%d", a + i);
    }
    LL ans = 0;
    for(int i = 1; i <= n; i ++) {
        if(st[i - a[i]])
            ans += st[i - a[i]];
        st[a[i] + i] ++;
    }
    printf("%lld\n", ans);
}
int main() {
    int T = 1;
    // scanf("%d", &T);
    while(T --) 
        solve();
    return 0;
}

Measured memory_bytes: 21672
#include <bits/stdc++.h>
#define FOR(i, k, n) for(int i = (k); i < (n); i++)
#define FORe(i, k, n) for(int i = (k); i <= (n); i++)
#define FORr(i, k, n) for(int i = (k)-1; i > (n); i--)
#define FORre(i, k, n) for(int i = (k)-1; i >= (n); i--)
#define REP(i, n) FOR(i, 0, n)
#define REPr(i, n) FORre(i, n, 0)
#define ALL(x) (x).begin(), (x).end()
#define ALLr(x) (x).rbegin(), (x).rend()
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
using namespace std;
using ll = long long;

const int INF = 1001001001;

int main(void){
  int n;
  cin >> n;
  vector<int> l(n);
  REP(i, n) cin >> l[i];
  sort(ALL(l));
  int sum = 0;
  REP(i, n-1) sum += l[i];
  if(l[n-1] < sum) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int n, m;
int s[250][250], f[250][250][250], g[250][250][250];
char a[250][250];
bool check(int x1, int y1, int x2, int y2) {
    int tmp = s[x2][y2] - s[x1 - 1][y2] - s[x2][y1 - 1] + s[x1 - 1][y1 - 1];
    return tmp == 0 || tmp == (x2 - x1 + 1) * (y2 - y1 + 1);
}
int main() {
    scanf("%d%d", &n, &m);
    for (int i = 1; i <= n; ++i) scanf("%s", a[i] + 1);
    for (int i = 1; i <= n; ++i)
        for (int j = 1; j <= m; ++j)
            s[i][j] =
                s[i - 1][j] + s[i][j - 1] - s[i - 1][j - 1] + (a[i][j] == '.');
    for (int i = 1; i <= n; ++i)
        for (int j = i; j <= n; ++j)
            for (int k = m; k; --k)
                if (k < m && f[i][j][k + 1] && check(i, k, j, f[i][j][k + 1]))
                    f[i][j][k] = f[i][j][k + 1];
                else if (check(i, k, j, k))
                    f[i][j][k] = k;

    for (int i = 1; i <= m; ++i)
        for (int j = i; j <= m; ++j)
            for (int k = n; k; --k)
                if (k < n && g[i][j][k + 1] && check(k, i, g[i][j][k + 1], j))
                    g[i][j][k] = g[i][j][k + 1];
                else if (check(k, i, k, j))
                    g[i][j][k] = k;
    if (f[1][n][1] == m) return puts("0"), 0;

    for (int ans = 1;; ++ans) {
        for (int i = 1; i <= n; ++i)
            for (int j = i; j <= n; ++j)
                for (int k = 1; k <= m; ++k)
                    if (f[i][j][f[i][j][k] + 1] > 0)
                        f[i][j][k] = f[i][j][f[i][j][k] + 1];
        for (int i = 1; i <= m; ++i)
            for (int j = i; j <= m; ++j)
                for (int k = 1; k <= n; ++k)
                    if (g[i][j][g[i][j][k] + 1])
                        g[i][j][k] = g[i][j][g[i][j][k] + 1];
        for (int x = 1; x <= n; ++x)
            for (int y = 1; y <= m; ++y) {
                int tmp = m;
                for (int i = x; i <= n; i++) {
                    while (tmp && g[y][tmp][x] < i) --tmp;
                    f[x][i][y] = max(f[x][i][y], tmp);
                }
                tmp = n;
                for (int i = y; i <= m; i++) {
                    while (tmp && f[x][tmp][y] < i) --tmp;
                    g[y][i][x] = max(g[y][i][x], tmp);
                }
            }
        if (f[1][n][1] == m) return printf("%d\n", ans), 0;
    }
    return 0;
}

Measured memory_bytes: 93952
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

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

#define MOD 1000000007
#define REP(i, N) for (int i = 0; i < N; ++i)
#define REP1(i, N) for (int i = 1; i <= N; ++i)
#define RREP(i, N) for (int i = N - 1; i >= 0; --i)
#define ALL(a) a.begin(), a.end()

int main()
{
  string S;
  cin >> S;
  int N = S.size();
  ll dp[100010][4] = {};
  dp[0][0] = 1;
  REP(i, N)
  {
    REP(j, 4)
    dp[i + 1][j] = ((S[i] == '?' ? 3 : 1) * dp[i][j]) % MOD;
    if (S[i] == 'A' || S[i] == '?')
      dp[i + 1][1] = (dp[i + 1][1] + dp[i][0]) % MOD;
    if (S[i] == 'B' || S[i] == '?')
      dp[i + 1][2] = (dp[i + 1][2] + dp[i][1]) % MOD;
    if (S[i] == 'C' || S[i] == '?')
      dp[i + 1][3] = (dp[i + 1][3] + dp[i][2]) % MOD;
  }
  cout << dp[N][3] << endl;
  return 0;
}

Measured memory_bytes: 3584
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<string,ll> P;
map<P,ll> M;
map<string,ll> upper;
string s;
int p,flg;
ll program();

string getName(){
  string res;
  while(s[p]!='[')res+=s[p++];
  return res;
}

ll getNum(){
  ll res=0;
  while(isdigit(s[p]))res=res*10+s[p++]-'0';  
  return res;
}

ll getIdx(){
  ll res=0;
  if(isdigit(s[p])) res=getNum(),p++;
  else res=program(),p++;
  return res;  
}

ll program(){
  if(isdigit(s[p]))return getNum();
  string name=getName();p++;
  int idx=getIdx();
  if(!M.count(P(name,idx))) flg=0;
  return M[P(name,idx)];
}

void start(){
  flg=1;
  p=0;
  string name=getName();p++;
  ll idx=getIdx();
  ll cnt = upper.count(name);
  if((cnt&&idx>upper[name])||(!cnt&&p!=s.size()))flg=0;
  if(!cnt)upper[name] = idx-1;
  if(p==s.size()) return;
  p++;
  int res=program();
  M[P(name,idx)]=res;
}

int main(){
  while(1){
    int ans=0;
    M.clear();
    upper.clear();
    for(int i=1;;i++){
      cin>>s;
      if(i==1&&s==".")return 0;
      if(s==".")break;
      if(ans)continue;
      start();
      if(!ans&&!flg)ans=i;
    }
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 3148
#include <bits/stdc++.h> 
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
//typedef pair<int, pair<int, int>> P;
//typedef tuple<int,int,int> T;
ll INFL = 1000000000000000010;//10^18 = 2^60
int INF = 1e9 + 10;//10^9
ll MOD  = 1000000007;
int dy[] = {0,0,1,-1};
int dx[] = {1,-1,0,0};

int main(void){
    int A,B,X;
    cin >> A >> B >> X;
    if(X < A || A + B < X){
        cout << "NO" << endl;
    }else{
        cout << "YES" << endl;
    }
}


Measured memory_bytes: 256
s = input()
flg = True
for i in range(len(s)):
    if i%2==0:
        if s[i] == 'L':
            flg = False
            break
    else:
        if s[i] == 'R':
            flg = False
            break
if flg:
    print('Yes')
else:
    print('No')

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

#define rep(i,n) for(i = 0;i < n;++i)
#define all(v) v.begin(), v.end()
using ll = long long;

int main()
{
    ll i,j;
    ll n;
    cin >> n;
    ll ans = 0;
    ll sn = sqrt(n);
    for(i = 2;i <= sn;++i){
        if(n%i != 0)continue;
        ll tmp = n;
        j = i;
        while(true){
            tmp /= j;
            if(tmp%j != 0 || tmp == 1) break;
        }
        if(tmp == 1){
            ++ ans;
        }else{
            if((tmp-1)%j == 0) ++ans;
        }
    }
    ll k = n-1;
    ll sk = sqrt(k);
    for(i = 1;i <= sk;++i){
        if(k%i == 0){
            if(i*i == k){
                ++ans;
            }else{
                ans += 2;
            }
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
#%% for atcoder uniittest use
import sys
input= lambda: sys.stdin.readline().rstrip()
def pin(type=int):return map(type,input().split())
def tupin(t=int):return tuple(pin(t))
def lispin(t=int):return list(pin(t))
#%%code
def solve(LIST):
    ans=0
    last=[0]*26
    for i in range(len(LIST)):
        a=i+1 #day a0
        x=LIST[i]-1
        #increase        
        ans+=S[i][x]
        #decrease
        last[x]=a#update
        temp=0
        for j in range(26):
            temp+=C[j]*(a-last[j])
        #print(ans,temp,"deb")
        ans-=temp
        print(ans)
    
    return  
def resolve():
    global D,C,S
    #input of prob.A
    D,=pin()
    C=[*pin()]#0-indexed
    S=[[*pin()]for i in range(D)]

    #output of prob.A
    T=[int(input()) for i in range(D)]#0indexed
    solve(T)

    
#%%submit!
resolve()

Measured memory_bytes: 68720
#include <iostream>
#include <string.h>
#include <algorithm>
#include <array>
#include <vector>
#include <cmath>

using namespace std;

int main( void ) {

    int N, X, m, count;
    cin >> N >> X;

    vector<int> gram;

    for ( int i = 0; i < N; i++ ) {
        cin >> m;
        gram.push_back(m);
        X -= m;
    }

    sort(gram.begin(), gram.end());

    count = N;
    while ( X >= gram.at(0) ) {
        X -= gram.at(0);
        count++;
    }

    cout << count << endl;
    

    return 0;
}

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

ll gcd(ll a, ll b) {
        if (a % b == 0) return b;
        else {
                return gcd(b, a % b);
        }
}
ll lcm(ll a, ll b) {
        return a / gcd(a, b) * b;
}


int main()
{
        ll N; cin >> N;
        vector<ll> T(N, 0);
        for (int i = 0; i < N; ++i) {
                cin >> T[i];
        }
        if (N == 1) {
                cout << T[0] << endl;
                exit(0);
        }
        ll g = lcm(T[0], T[1]);
        for (int i = 2; i < N; ++i) {
                g = lcm(g, T[i]);
        }
        cout << g << endl;


}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int SolvedPuzzle[100];

int main()
{
    cin >> SolvedPuzzle[0] >> SolvedPuzzle[1] >> SolvedPuzzle[2] >> SolvedPuzzle[3] >> SolvedPuzzle[4];

    for(int x=0; x<4; x++)
    {
        for(int y=0; y<4; y++)
        {
            if(SolvedPuzzle[y]<SolvedPuzzle[y+1])
            {
                int temp;
                temp = SolvedPuzzle[y+1];
                SolvedPuzzle[y+1] = SolvedPuzzle[y];
                SolvedPuzzle[y] = temp;

            }
        }
    }
    cout << SolvedPuzzle[0] << " " << SolvedPuzzle[1] << " " << SolvedPuzzle[2] << " " << SolvedPuzzle[3] << " " << SolvedPuzzle[4] << endl;

}

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

int main() {
  string S;
  cin >> S;
  reverse(S.begin(), S.end());
  int dig = 1, sum = 0;
  map<int, int> MA;
  MA[0]++;
  for (int i = 0; i < S.size(); i++) {
    (sum += (S.at(i) - '0') * dig) %= 2019;
    (dig *= 10) %= 2019;
    MA[sum]++;
  }
  long ans = 0;
  for (auto ma : MA) ans += ma.second * (ma.second - 1) / 2;
  cout << ans << "\n";
}

Measured memory_bytes: 3688
#include <algorithm>
#include <iomanip>
#include <istream>
#include <map>
#include <numeric>
#include <ostream>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>
using namespace std;
// Powered by caide (code generator, tester, and library code inliner)


class Solution {
public:

    long long choose(int n)
    {
        if (n == 0)
        {
            return 0;
        }
        else if (n == 1)
        {
            return 0;
        }
        else if (n == 2)
        {
            return 1;
        }
        else
        {
            long long l = 1;
            return (l * n * (n - 1)) / 2;
        }
    }

    void count(int* a, int n, map<int, int>& m)
    {
        for (int i = 0; i < n; i++)
        {
            if (m.find(a[i]) == m.end())
            {
                m[a[i]] = 0;
            }

            m[a[i]] += 1;
        }
    }

    void solve(std::istream& in, std::ostream& out) {
        int n;
        in >> n;

        int* a = new int[n];

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

        map<int, int> m;
        count(a, n, m);

        long long total = 0;
        map<int, int>::iterator it = m.begin();
        while (it != m.end())
        {
            int f = it->first;
            long long s = choose(it->second);

            total += s;

            it++;
        }

        for (int i = 0; i < n; i++)
        {
            long long c = total - choose(m[a[i]]) + choose(m[a[i]] - 1);

            out << c << endl;
        }

        delete[] a;

    }
};

void solve(std::istream& in, std::ostream& out)
{
    out << std::setprecision(12);
    Solution solution;
    solution.solve(in, out);
}


#include <fstream>
#include <iostream>


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


    istream& in = cin;


    ostream& out = cout;

    solve(in, out);
    return 0;
}




Measured memory_bytes: 8960
#include "iostream"
#include "vector"
#include "string"
#include "algorithm"
#include "math.h"
#include "cstring"
#include "stack"
#include "queue"
#include "cmath"
#include "set"

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<vector<ll> > mat;

int main()
{
  ll n, p;
  cin >> n >> p;
  string s;
  cin >> s;
  if (p != 2 && p != 5)
  {
    ll a[n + 1];
    a[0] = 0;
    ll ind = 1;
    for (ll i = 1; i <= n; i++)
    {
      ll b = s[n - i] - '0';
      a[i] = (((a[i - 1] + (b * ind)) % p) + p) % p;
      ind *= 10;
      ind %= p;
    }
    sort(a, a + n + 1);

    ll ans = 0LL;
    ll check = 1LL;
    for (ll i = 1; i <= n; i++)
    {
      if ((a[i] - a[i - 1]) % p == 0)
      {
        check++;
      }
      else
      {
        ans += check * (check - 1) / 2;
        check = 1LL;
      }
    }
    ans += check * (check - 1) / 2;
    cout << ans << "\n";
  }
  else
  {
    ll ans = 0;
    for (ll i = 0; i < n; i++)
    {
      ll b = s[i] - '0';
      if (b % p == 0)
      {
        ans += i + 1;
      }
    }
    cout << ans << "\n";
  }
}

Measured memory_bytes: 2180
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	int r;
	cin >> r;
	if (r < 1200) cout << "ABC";
	else if (r < 2800) cout << "ARC";
	else cout << "AGC";
}

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

#define dbg(a)  cerr << __LINE__ << ": " << #a << " = " << a << '\n'

typedef long long ll;

int main(){
  double r; cin >> r;
  cout << fixed << setprecision(10) << acos(-1.0)*2*r << endl;
  return 0;
}

Measured memory_bytes: 3784
# 126 B

s = input()

fir = int(s[:2])
sec = int(s[2:])

if fir > 0 or sec > 0:
    if 1 <= fir <= 12 and 1 <= sec <= 12 :
        print("AMBIGUOUS")
    elif 1 <= fir <= 12: 
        print("MMYY")
    elif 1 <= sec <= 12:
        print("YYMM") 
    else:
        print("NA")
else:
    print("NA")


Measured memory_bytes: 9040
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;

#define FOR(i, N) for (int i = 0; i < (int)N; i++)
#define FORIN(i, a, b) for (int i = a; i < (int)b; i++)
#define ALL(x) (x).begin(), (x).end()
#define MOD 1000000007
#define MAX (1 << 29)
#define DEBUG(...) debug(__LINE__, ":" __VA_ARGS__)

using Pi = pair<int, int>;
using ll = long long;
const int INF = 1 << 28;

string to_string(string s) { return s; }

template <class S, class T>
string to_string(pair<S, T> p) {
  return "{" + to_string(p.first) + "," + to_string(p.second) + "}";
}

template <class S>
string to_string(unordered_set<S> s) {
  string ret = "{";
  for (S x : s) ret += to_string(x);
  return ret + "}";
}

template <class S, class T>
string to_string(map<S, T> m) {
  string ret = "{";
  for (pair<S, T> x : m) ret += to_string(x);
  return ret + "}";
}

template <class T>
string to_string(vector<T> v) {
  string ret = "{";
  for (int i = 0; i < v.size() - 1; ++i) {
    ret += to_string(v[i]) + ",";
  }
  if (v.size() > 0) {
    ret += to_string(v.back());
  }
  ret += "}";
  return ret;
}

void debug() { cerr << endl; }

template <class Head, class... Tail>
void debug(Head head, Tail... tail) {
  cerr << to_string(head) << " ";
  debug(tail...);
}

void print() { cout << endl; }

template <class Head, class... Tail>
void print(Head head, Tail... tail) {
  cout << to_string(head);
  print(tail...);
}

void get() {}

template <class Head, class... Tail>
void get(Head& head, Tail&... tail) {
  cin >> head;
  get(tail...);
}

template <class T>
void getv(vector<T>& vec) {
  for (int i = 0; i < vec.size(); ++i) cin >> vec[i];
}

int main() {
  string S;
  int K;
  cin >> S >> K;
  vector<vector<ll>> dp(S.size(), vector<ll>(2));
  dp[0][0] = 0;
  dp[0][1] = 1;
  FORIN(i, 1, S.size()) {
    dp[i][1] = min(dp[i - 1][0], dp[i - 1][1]) + 1;
    dp[i][0] = dp[i - 1][1];
    if (S[i] != S[i - 1]) {
      dp[i][0] = min(dp[i][0], dp[i - 1][0]);
    }
  }
  int l = 0, r = S.size() - 1;
  while (l < S.size() && S[l] == S[l + 1]) l++;
  l++;
  while (r >= 0 && S[r] == S[r - 1]) r--;
  r = S.size() - r;
  unordered_set<char> chars;
  FOR(i, S.size()) chars.insert(S[i]);
  if (S[0] != S.back()) {
    cout << min(dp[S.size() - 1][0], dp[S.size() - 1][1]) * K << endl;
  } else {
    if (chars.size() == 1) {
      cout << S.size() * K / 2 << endl;
    } else {
      ll ans = min(dp[S.size() - 1][0], dp[S.size() - 1][1]) * K;
      ll diff = (l + r) / 2 - l / 2 - r / 2;
      cout << ans + diff * (K - 1) << endl;
    }
  }
  return 0;
}

Measured memory_bytes: 256
N = int(input())
K = int(input())



dp = [[[0 for _ in range(2)] for _ in range(K+1)] for _ in range(len(str(N))+1)]
# 頭から0桁目まで決めて、0以外の数が0個既に使われている時、i桁目までの部分がNより小さいのは0の一通り
dp[0][0][0] = 1


"""
N = 987654として、

（１）3桁目までみたときに、987より小さくなるdp[3][j][1]への派生は
・87から870を作るような、dp[2][j][1]から
・98から980みたいなのがあるから、dp[2][j][0]から。ただし、Nの３桁目が0だと、今作ってる３桁目までの数字98＊が980未満になれないので、その場合はスキップ
↑↑↑ここまではi桁目に0を使うパターン↑↑↑
↓↓↓i桁目に0以外を使うパターン↓↓↓
まだ使える0以外の個数がのこっているとき、
・87から871~879の９パターンに派生する形なので、dp[i][j-1][1] から派生するのが9通りなので * 9 して足す（0以外の値を一つ消化する）
・98から981~986への派生なので、dp[i][j-1][0] * (digit[i] - 1) (例でいうところの７未満の値を使える)　（0以外の値を一つ消化する）

（２）3桁目までみたときに、987と一致するようなdp[3][j][0]への派生は
・もし３桁目が０なら、98から980への派生があるので、dp[i][j][0]から派生できる
・もし３桁目が０ではないのなら、98から987へ派生し、一つ0以外の数字を消化するので、dp[i][j-1][0]から派生


みたいに考えていく。
"""

for i in range(len(str(N))):
    digit = int(str(N)[i])
    for j in range(K+1):
        # i桁目までがNのそこまでより小さい場合、i-1桁目までもNのi-1桁目までより小さいことが確定するから、
        # i-1 -> iへの派生を入れる（from 厳密に小さい to 厳密に小さい）
        dp[i+1][j][1] += dp[i][j][1]

        # i-1桁目までがNのi-1桁目までより小さくなく（一致し）、Nのi桁目が０であれば、作っている数字のi桁目が０になる
        if digit == 0:
            # 厳密に小さくなれないので（from 厳密に小さくない to 厳密に小さくない）
            dp[i+1][j][0] += dp[i][j][0]
        else:
            """
            314159で、31OXXXかつNの3桁目までより小さいパターンは、31XXXXから派生
            """
            # （from 厳密に小さくない（一致する） to 厳密に小さい）
            dp[i+1][j][1] += dp[i][j][0]
        
        # 先頭になんか0以外の数字を入れて、残りがまだ0以外の数字を入れる必要があるとき
        if j-1 >= 0:
            # 0以外のなんかの値を使ったので j-1 -> j かつ  * 9（０以外をいれる）
            dp[i+1][j][1] += dp[i][j-1][1] * 9
            if digit != 0:
                # i桁目が一致する（Nのiまでより小さくならない）パターンについて、直前の場合の数を足す
                dp[i+1][j][0] += dp[i][j-1][0]
                # i桁目までが、Nのそれまでより小さくなるパターンについて、i桁目ではdより小さい値をとれる
                dp[i+1][j][1] += dp[i][j-1][0] * (digit-1)

print(sum(dp[-1][-1]))

Measured memory_bytes: 3064
r, c = (int(x) for x in input().split())

table = []

for i in range(r):
    table.append([int(x) for x in input().split()])

for row in table:
    row.append(sum(row))

nextlist = []
sum = 0
for i in range(c+1):
    for j in range(r):
        sum += table[j][i]
    nextlist.append(sum)
    sum = 0
table.append(nextlist)

for row in table:
    ans_row = " ".join(list(map(str,row)))
    print(ans_row)


Measured memory_bytes: 5680
#include <iostream>

int main(void)
{
    int h, w;
    std::cin >> h >> w;
    for (int i = 0; i < h; ++i)
    {
        std::string s;
        std::cin >> s;
        std::cout << s << std::endl;
        std::cout << s << std::endl;
    }
    return 0;
}


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

#define INF 1e9
#define PI 3.141592653589793238
typedef long long ll;

int main() {
    ll n,k;cin>>n>>k;
    vector<ll> v(n);
    ll ans=0;
    for(int i=0; i<n; i++){
        cin>>v[i];
    }
    sort(v.begin(), v.end());
    for(int i=0; i<n-k; i++) ans+=v[i];

    if(n<=k) cout<<0<<endl;
    else cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 4836
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

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

		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		PriorityQueue<Long> p_que = new PriorityQueue<Long>(Comparator.reverseOrder()); //最大のものを取り出し
		for(int i = 0 ; i < n ; i++) {
			p_que.add(sc.nextLong());
		}
		for(int i = 0 ; i < m ; i++) {
			p_que.add(p_que.poll() / 2);
		}
		long sum = 0;
		while(!p_que.isEmpty()) {
			sum += p_que.poll();
		}
		System.out.println(sum);

	}
}



Measured memory_bytes: 61520
def readinput():
    n,k=list(map(int,input().split()))
    p=list(map(int,input().split()))
    return n,k,p

def main(n,k,p):
    ps=sorted(p)
    sum=0
    for i in range(k):
        sum+=ps[i]
    
    return sum

if __name__=='__main__':
    n,k,p=readinput()
    ans=main(n,k,p)
    print(ans)


Measured memory_bytes: 9264
#include<iostream>
#include<algorithm>
#include<string>
#include<cstdlib>
#include<map>
#include<iomanip>
#include<sstream>
#include<vector>
#include<stack>
#include<math.h>
#include<queue>
#include<complex>
#include<random>
#include<ctime>
#include<set>
using namespace std;


const long long int mod=1000000007;
const long long int INF=99999999999999999;

long long int N,P[10],Q[10],tmp[10]={1,1},a=0,b=0,res=0;
int main() {
	cout << fixed << setprecision(18);
	cin>>N;
	for(int i=0;i<N;i++){
		cin>>P[i];
	}
	for(int i=0;i<N;i++){
		cin>>Q[i];
	}
	for(int i=2;i<N;i++){
		tmp[i]=i*tmp[i-1];
	}
	bool used1[10]={},used2[10]={};

	long long int memo=0;
	for(int i=0;i<N;i++){
		memo=0;
		for(int j=1;j<P[i];j++){
			if(!used1[j]){memo++;}
		}
		used1[P[i]]=true;
		res+=tmp[N-i-1]*memo;

		memo=0;
		for(int j=1;j<Q[i];j++){
			if(!used2[j]){memo++;}
		}
		used2[Q[i]]=true;
		res-=tmp[N-i-1]*memo;
	}
	cout<<abs(res);
} 

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

long long dp[60][60][3000];

int main() {
  int N, A;
  cin >> N >> A;
  int x[N];
  for (int i = 0 ; i < N ; i++) cin >> x[i];
  dp[0][0][0] = 1;
  for (int i = 0 ; i < N ; i++) {
    for (int j = 0 ; j < N ; j++) {
      for (int k = 0 ; k <= 2500 ; k++) {
        dp[i+1][j+1][k+x[i]] += dp[i][j][k];
        dp[i+1][j][k] += dp[i][j][k];
      }
    }
  }
  long long ans = 0;
  for (int j=1 ; j<=N ; j++) {
    for (int k=0 ; k<=A*N ; k++) {
      if (A * j == k) ans += dp[N][j][k];
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 70528
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;
import java.util.Set;
import java.util.HashSet;

public class Main {
  public static void main(String[] args) throws IOException {
    BufferedReader in = new BufferedReader(new InputStreamReader(System.in));
    String[] str = in.readLine().split(" ");
    int x = Integer.parseInt(str[0]);
    int n = Integer.parseInt(str[1]);
    str = in.readLine().split(" ");
    Set<Integer> set = new HashSet<>();
    for(int i=0; i<n; i++) {
      set.add(Integer.parseInt(str[i]));
    }
    for(int i=0; i<=200; i++) {
      if(!set.contains(x-i)) {
        System.out.println(x-i);
        return;
      }
      if(!set.contains(x+i)) {
        System.out.println(x+i);
        return;
      }
    }
  }
}

Measured memory_bytes: 32616
#
# 　　  ⋀_⋀　 
#　　  (･ω･)  
# .／ Ｕ ∽ Ｕ＼
#  │＊　合　＊│
#  │＊　格　＊│ 
#  │＊　祈　＊│ 
#  │＊　願　＊│ 
#  │＊　　　＊│ 
#      ￣
#
import sys
sys.setrecursionlimit(10**6)
input=sys.stdin.readline
from math import floor,sqrt,factorial,hypot,log #log2ないｙｐ
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from fractions import gcd
from random import randint
def ceil(a,b): return (a+b-1)//b
inf=float('inf')
mod = 10**9+7
def pprint(*A): 
    for a in A:     print(*a,sep='\n')
def INT_(n): return int(n)-1
def MI(): return map(int,input().split())
def MF(): return map(float, input().split())
def MI_(): return map(INT_,input().split())
def LI(): return list(MI())
def LI_(): return [int(x) - 1 for x in input().split()]
def LF(): return list(MF())
def LIN(n:int): return [I() for _ in range(n)]
def LLIN(n: int): return [LI() for _ in range(n)]
def LLIN_(n: int): return [LI_() for _ in range(n)]
def LLI(): return [list(map(int, l.split() )) for l in input()]
def I(): return int(input())
def F(): return float(input())
def ST(): return input().replace('\n', '')
def main():
    N=I()
    if(N==3):
        print(2,5,63)
    elif(N==4):
        print(2,5,20,63)
    elif(N==5):
        print(2,3,4,5,16)
    else:
        MAX = 30000
        ans = []
        for i in range(2,MAX+1):
            if(i%3==0 or i%2==0):
                ans.append(i)
                if(len(ans) == N):
                    break
        if(sum(ans)%6 == 0):
            pass
        else:
            if(6+(sum(ans)%6) in ans): # 2,3
                ans.remove(6 + (sum(ans)%6))
                v = ans[-1] + 1
                while True:
                    if(v%6==0):
                        ans.append(v)
                        break
                    v+=1
            else: # 5
                ans.remove(8)
                v = ans[-1]+1
                while True:
                    if((v+3)%6==0):
                        ans.append(v)
                        break
                    v+=1
        print(*ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 67948
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,k;
	cin>>n>>k;
	double b[n+1];
	double a[n+1];
	double c[n+1];
	c[0]=0;
	for(int i=1;i<=n;i++)
	{
		cin>>b[i];
		a[i]=b[i]*(b[i]+1)/2;
		a[i]=a[i]/b[i]; 
		c[i]=c[i-1]+a[i];
	}
	double s=0;
	for(int i=k;i<=n;i++)
	{
		if((c[i]-c[i-k])>s)
		s=c[i]-c[i-k];
	}
	cout<<fixed<<setprecision(12)<<s;
	return 0;
 } 

Measured memory_bytes: 4992
#include <bits/stdc++.h>
 
#define M 1000000007
 
int main(void)
{
  int n;
  std::cin >> n;
 
  std::vector<int> a(n);
  // std::vector<uint64_t> sum(n+1, 0);
  long long sum = 0;
  for (int i = 0; i < n; i++) {
    std::cin >> a[i];
    sum += a[i];
    sum %= M;
  }
 
  long ans = 0;
  for (int i = 0; i < n-1; i++) {
    sum -= a[i];
    if (sum < 0) {
      sum += M;
    }

    ans += (sum * a[i]);
    ans %= M;
  }
 
  std::cout << ans << std::endl;
 
  return 0;
}

Measured memory_bytes: 4000
import bisect

A, B, Q = map(int, input().split())
s = [None] * A
t = [None] * B
x = [None] * Q

for i in range(A):
    s[i] = int(input())
for i in range(B):
    t[i] = int(input())
for i in range(Q):
    x[i] = int(input())

s.sort()
t.sort()

def calc(s, t, x):
    len_s = len(s)
    len_t = len(t)

    def f_nishi_pos(l, x):
        p1 = bisect.bisect_left(l, x)
        #p2 = bisect.bisect_right(l, x)
        #if p2 == len(l):
        #    return p1-1
        #if l[p1] == l[p2]:
        #    return max(p2-1, 0)
        #else:
        #    return p1
        if p1 == len(l):
            return p1 - 1
        else:
            if l[p1] == x:
                return p1
            else:
                return p1 - 1

    def f_higashi_pos(l, x):
        #p1 = bisect.bisect_left(l, x)
        p2 = bisect.bisect_right(l, x)
        #if p1 == len(l):
        #    return p1-1
        #if l[p1] == l[p2]:
        #    return min(p1, len(l)-1)
        #else:
        #    return p1
        if p2 == len(l):
            return p2 - 1
        else:
            return p2

    # 神社 -> 寺
    ## 西の神社
    j_nishi_pos = f_nishi_pos(s, x)
    j_nishi = s[j_nishi_pos]
    ## 東の神社
    j_higashi_pos = f_higashi_pos(s, x)
    j_higashi = s[j_higashi_pos]

    ## 西の神社の西の寺
    j_nishi_t_nishi_pos = f_nishi_pos(t, j_nishi)
    j_nishi_t_nishi = t[j_nishi_t_nishi_pos]
    ## 西の神社の東の寺
    j_nishi_t_higashi_pos = f_higashi_pos(t, j_nishi)
    j_nishi_t_higashi = t[j_nishi_t_higashi_pos]
    ## 東の神社の西の寺
    j_higashi_t_nishi = t[f_nishi_pos(t, j_higashi)]
    ## 東の神社の東の寺
    j_higashi_t_higashi = t[f_higashi_pos(t, j_higashi)]


    # 寺 -> 神社
    t_nishi = t[f_nishi_pos(t, x)]
    t_higashi = t[f_higashi_pos(t, x)]
    
    ## 西の寺の西の神社
    t_nishi_j_nishi = s[f_nishi_pos(s, t_nishi)]
    ## 西の寺の東の神社
    t_nishi_j_higashi = s[f_higashi_pos(s, t_nishi)]
    ## 東の寺の東の神社
    t_higashi_j_nishi = s[f_nishi_pos(s, t_higashi)]
    ## 東の寺の東の神社
    t_higashi_j_higashi = s[f_higashi_pos(s, t_higashi)]


    return min(
        abs(x - j_nishi) + abs(j_nishi - j_nishi_t_nishi),
        abs(x - j_nishi) + abs(j_nishi - j_nishi_t_higashi),
        abs(x - j_higashi) + abs(j_higashi - j_higashi_t_nishi),
        abs(x - j_higashi) + abs(j_higashi - j_higashi_t_higashi),
        abs(x - t_nishi) + abs(t_nishi - t_nishi_j_nishi),
        abs(x - t_nishi) + abs(t_nishi - t_nishi_j_higashi),
        abs(x - t_higashi) + abs(t_higashi - t_higashi_j_nishi),
        abs(x - t_higashi) + abs(t_higashi - t_higashi_j_higashi)
    )

for xx in x:
    print(calc(s, t, xx))

Measured memory_bytes: 17368
import java.util.*;
public class Main{
    static Scanner sc = new Scanner(System.in);
    static int a, b;
    public static void main(String[] args) {
        while(read()){
            slove();
        }
    }

    static boolean read(){
        if(!sc.hasNext())return false;
        a = sc.nextInt();
        b = sc.nextInt();
        return true;
    }

    static void slove(){
        int ans = Integer.toString(a+b).length();
        System.out.println(ans);
    }

}

Measured memory_bytes: 20432
/* ex3_2
   kohei_suzuki */

#include <stdio.h>
int main(void){
    int num, rem; //本数numとnumの一の位rem

    scanf("%d",&num);
    rem = num % 10; //nの一の位を取り出す

    if(rem==0 || rem==1 || rem==6 || rem==8){ //remが0,1,6,8の場合
        printf("pon\n");
    }else if(rem == 3){ //remが3の場合
        printf("bon\n");
    }else{ //remが2,4,5,7,9の場合
        printf("hon\n");
    }

    return 0;
}

Measured memory_bytes: 1612