akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <vector>
using namespace std;

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> hv(n);
	for (auto& i : hv) {
		cin >> i;
	}
	vector<bool> ret(n, true);
	for (int i = 0; i < m; ++i)
	{
		int a, b;
		cin >> a >> b;
		--a;
		--b;
		if (hv[a] < hv[b]) {
			ret[a] = false;
		}
		else if (hv[b] < hv[a]) {
			ret[b] = false;
		}
		else {
			ret[a] = false;
			ret[b] = false;
		}
	}

	int sum = 0;
	for(int i = 0; i < n; ++i){
		if (ret[i]) {
			++sum;
		}
	}
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 3788
#include<stdio.h>
#include<math.h>
#define pi acos(-1.0)
int main()
{
    int a,b,h,m;
    double k,l;
    scanf("%d%d%d%d",&a,&b,&h,&m);
    k =((30.0*h)+(m/12.0)*6.0-m*6.0)*pi/180;
    l=sqrt(a*a+b*b-2*a*b*cos(k));
    printf("%0.20lf",l);

    return 0;
}


Measured memory_bytes: 2600
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

// sñÌÏ
vector<vector<bool> > matrixProduct(const vector<vector<bool> >& x, const vector<vector<bool> >& y)
{
    int a = x.size();
    int b = x[0].size();
    int c = y[0].size();
    vector<vector<bool> > z(a, vector<bool>(c, false));
    for(int i=0; i<a; ++i){
        for(int j=0; j<c; ++j){
            for(int k=0; k<b; ++k){
                z[i][j] = z[i][j] || (x[i][k] && y[k][j]);
            }
        }
    }
    return z;
}

// sñÌÝæ
vector<vector<bool> > matrixPower(const vector<vector<bool> >& x, int k)
{
    int n = x.size();
    vector<vector<bool> > y(n, vector<bool>(n, false));
    for(int i=0; i<n; ++i)
        y[i][i] = true;

    vector<vector<bool> > z = x;
    while(k > 0){
        if(k & 1)
            y = matrixProduct(y, z);
        z = matrixProduct(z, z);
        k >>= 1;
    }
    return y;
}


int main()
{
    for(;;){
        int n, m, z;
        cin >> n >> m >> z;
        if(n == 0)
            return 0;

        vector<vector<bool> > graph(n, vector<bool>(n, false));
        int size = 2*m+1;
        vector<int> curr(size);
        vector<int> prev(size);
        for(int i=0; i<m; ++i){
            int s, d;
            cin >> s >> d;
            graph[s-1][d-1] = graph[d-1][s-1] = true;
            curr[2*i+1] = s-1;
            prev[2*i+1] = d-1;
            curr[2*i+2] = d-1;
            prev[2*i+2] = s-1;
        }
        curr[0] = 0;
        prev[0] = -1;

        vector<vector<bool> > x(size, vector<bool>(size, false));
        for(int i=0; i<size; ++i){
            for(int j=0; j<size; ++j){
                if(graph[curr[i]][curr[j]] && curr[i] == prev[j] && prev[i] != curr[j])
                    x[i][j] = true;
            }
        }

        x = matrixPower(x, z);

        bool ok = false;
        for(int i=0; i<size; ++i){
            if(x[0][i] && curr[i] == n-1)
                ok = true;
        }

        if(ok)
            cout << "yes" << endl;
        else
             cout << "no" << endl;
    }
}

Measured memory_bytes: 920
#include <bits/stdc++.h>
typedef long long ll;
const int maxn = 1e6 + 5;

inline ll read()
{
    ll w = 0;
    ll t = 1;
    char ch = getchar();
    while (ch > '9' || ch < '0') {if (ch == '-') t = -1; ch = getchar();}
    while (ch >= '0' && ch <= '9') { w = (w << 3) + (w << 1) + (ch ^ '0'); ch = getchar();}
    return w * t;
}
int n, m;
ll k;
ll a[maxn];
int vis[maxn], to[maxn], c[maxn];
ll ans[maxn];
int main()
{
    n = read();
    ll lst = 0;
    for (int i = 1; i <= n; i++)
    {
        a[i] = read() - lst;
        lst += a[i];
        to[i] = i;
    }
    m = read(), k = read();
    int input;
    for (int i = 1; i <= m; i++)
        input = read(), std::swap(to[input], to[input + 1]);
    for (int i = 1; i <= n; i++)
        if (!vis[i])
        {
            int cnt = 0, j;
            for (j = i; !vis[j]; j = to[j])
                vis[j] = 1, c[++cnt] = j;
            for (j = 1; j <= cnt; j++)
                ans[c[j]] = a[c[(j + k - 1) % cnt + 1]];
        }
    for (int i = 1; i <= n; i++)
    {
        printf("%lld.0\n", ans[i] += ans[i - 1]);
    }
    return 0;
}

Measured memory_bytes: 6444
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>

#include <limits.h>

using namespace std;

typedef long long ll;

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

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

vector<int> as;

int main(void) {
    int N, D, X;
    cin >> N >> D >> X;

    as.resize(N);
    for (int i = 0; i < N; i++) {
        cin >> as[i];
    }

    int ans = X;
    for (int i = 0; i < N; i++) {
        ans += 1 + (D - 1) / as[i];
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3604
// --https://kenkoooo.com/atcoder/#/table/soma62jp

#include <stdio.h>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iostream>
#include <iterator>
#include <algorithm>
#include <functional>

typedef long long LL;
typedef unsigned int UI;
typedef long double LD;

#define rSort(a) 		sort(a.rbegin(),a.rend())
#define Sort(a) 		sort(a.begin(),a.end())
#define Reverse(a) 		reverse(a.begin(),a.end())
#define Sum(a)  		accumulate(a.begin(), a.end(), 0)
#define REP(i, n) 		for(UI i = 0;i < n;i++)
#define REPR(i, n) 		for(UI i = n;i >= 0;i--)
#define FOR(i, m, n) 	for(UI i = m;i < n;i++)
#define pb(i) 			push_back(i)
#define SWAP(x,y) 		((x!=y)&&(x^=y,y^=x,x^=y))

#define MOD  			(LL)1000000007;
#define INF  			(LL)1 << 62;

using namespace std;

struct Node {
	int i, j;
};

queue<Node>que;

char a[1010][1010];
int vis[1010][1010];
int visc[1010];
int h, w;

int bfs() {

	int step = 0;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (a[i][j] == '#') {
				Node node;
				node.i = i;
				node.j = j;
				que.push(node);
			}
		}
	}

	while (!que.empty()) {
		Node node = que.front();
		int c = node.i;
		int l = node.j;
		if (vis[c][l] == step)
			step++;
		if (vis[c][l] == step - 1) {
			if (c - 1 >= 0 && a[c - 1][l] == '.') {
				a[c - 1][l] = '#';
				vis[c - 1][l] = step;
				Node temp;
				temp.i = c - 1;
				temp.j = l;
				que.push(temp);
			}
			if (c + 1 < h && a[c + 1][l] == '.') {
				a[c + 1][l] = '#';
				vis[c + 1][l] = step;
				Node temp;
				temp.i = c + 1;
				temp.j = l;
				que.push(temp);
			}
			if (l - 1 >= 0 && a[c][l - 1] == '.') {
				a[c][l - 1] = '#';
				vis[c][l - 1] = step;
				Node temp;
				temp.i = c;
				temp.j = l - 1;
				que.push(temp);
			}
			if (l + 1 < w && a[c][l + 1] == '.') {
				a[c][l + 1] = '#';
				vis[c][l + 1] = step;
				Node temp;
				temp.i = c;
				temp.j = l + 1;
				que.push(temp);
			}
		}
		que.pop();
	}

	return step - 1;
}

int main(int argc, char* argv[]) {

	cin.tie(0);
	ios::sync_with_stdio(false);

	cin >> h >> w;

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
		}
	}

	memset(vis, 0, sizeof(vis));
	memset(visc, -1, sizeof(visc));

	cout << bfs() << endl;

	return 0;
}



Measured memory_bytes: 13456
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

int N;
int P[128],Q[128],R[128],B[128];

int rec(int v){
  int p = P[v], q = Q[v], r = R[v], b = B[v];
  int rw=1, bw=1;
  if(r) rw = rec(r);
  if(b) bw = rec(b);
  int rx = p*rw, bx = q*bw;
  int lcm = rx/__gcd(rx,bx)*bx;
  return lcm/rx*rw+lcm/bx*bw;
}

int main(){
  while(scanf("%d", &N) && N){
    int par[128]={};
    for(int i=1;i<=N;i++){
      scanf("%d%d%d%d",&P[i], &Q[i], &R[i], &B[i]);
      par[R[i]] = 1;
      par[B[i]] = 1;
    }
    int s;
    for(int i=1;i<=N;i++) if(!par[i]) s = i;
    printf("%d\n", rec(s));
  }
  return 0;
}

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

#define INF 1LL << 60
#define MOD 1000000007;
#define pb push_back

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REPR(i, b, e) for (int i = (b); i <= (e); i++)
#define DEBUG(x) cout << #x << ": " << (x) << endl
#define DEBUGA(a) cout << #a << ": " << endl; for (const auto& v: (a)) cout << v << endl

int R, G, B;
int N;

int main() {
    cin.tie(0);
    cin >> R >> G >> B >> N;

    int cnt = 0;
    int tmp = 0;
    REPR(r, 0, N / R + 1) {
        REPR(g, 0, N / G + 1) {
            tmp = N - r * R - g * G;
            if (tmp >= 0 && tmp % B == 0) {
                cnt++;
            } 
        }
    }
    cout << cnt << endl;

    return 0;
}


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

int main()
{
  int n;
  cin>>n;
  set<int> s;
  while(n--)
  {
    int t;
    cin>>t;
    if(s.find(t)==s.end())
      s.insert(t);
    else
      s.erase(t);
  }
  cout<<s.size();
  
  return 0;
}

Measured memory_bytes: 4864
#include "bits/stdc++.h"
#include<unordered_map>
#pragma warning(disable:4996)
using namespace std;

const int My_Inf=2147483647;
const long long int My_LInf=9223372036854775807;
//左辺に底　右辺に真数
long double mlog(const long double base, const long double anti) {
	return log(anti) / log(base);
}
int main() {
	int N; cin >> N;
	int a = mlog(3, N) - 1e-16;
	cout << a + 1 << endl;
	return 0;
}

Measured memory_bytes: 3272
#include<iostream>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<string.h>
using namespace std;
#define N 1000
#define M 100000
#define S second
#define F first
#define MP(i, j) make_pair((i), (j))
#define INF 1e9
typedef pair<int, int> P;

vector<int> vec[N + 1][2], vec2, vec3;
P yoko[M];
int s[N + 1];
int main() {
	int n, m, h, k;
	while (cin >> n >> m >> h >> k && n && m && h && k) {
		int ans = INF, sum = 0;
		memset(s, 0, sizeof s);
		memset(yoko, 0, sizeof yoko);
		vec2.clear(); vec3.clear();
		for (int i = 0; i < n; i++) {
			scanf("%d", s + i);
			vec[i][0].clear();
			vec[i][1].clear();
		}
		for (int i = 0; i < m; i++) {
			int a, b;
			scanf("%d%d", &a, &b);
			yoko[i] = MP(b, a);
		}
		sort(yoko, yoko + m);
		for (int i = 0; i < n; i++) {
			vec[i][0].push_back(i);
		}
		for (int i = 0; i < m; i++) {
			int a = yoko[i].S;
			a--;
			int sz = vec[a][1].size();
			for (int j = 0; j < vec[a + 1][1].size(); j++) {
				vec[a][1].push_back(vec[a + 1][1][j]);
			};
			vec[a + 1][1].clear();

			for (int j = 0; j < sz; j++) {
				vec[a + 1][1].push_back(vec[a][1][j]);
			}
			vec[a][1].erase(vec[a][1].begin(), vec[a][1].begin() + sz);
			for (int j = 0; j < vec[a + 1][0].size(); j++) {
				vec[a][0].push_back(vec[a + 1][0][j]);
				vec[a + 1][1].push_back(vec[a + 1][0][j]);
			}
			vec[a + 1][0].erase(vec[a + 1][0].begin(), vec[a + 1][0].end());
			for (int j = 0; j < 1; j++) {
				vec[a + 1][0].push_back(vec[a][0][j]);
				vec[a][1].push_back(vec[a][0][j]);
			}
			if (vec[a][0].size())
				vec[a][0].erase(vec[a][0].begin(), vec[a][0].begin() + 1);
		}
		for (int i = 0; i < n; i++) {
			if (k >= vec[i][0][0] + 1) {
				sum += s[i];
				vec2.push_back(i);
			}
			else {
				vec3.push_back(i);
			}
			sort(vec[i][1].begin(), vec[i][1].end());
		}
		for (int i = 0; i < vec2.size(); i++) {
			for (int j = 0; j < vec3.size(); j++) {
				if (s[vec2[i]] > s[vec3[j]]) {
					if (binary_search(vec[vec3[j]][1].begin(), vec[vec3[j]][1].end(), vec[vec2[i]][0][0])) {
						ans = min(ans, sum - s[vec2[i]] + s[vec3[j]]);
					}
				}
			}
		}
		ans = min(ans, sum);
		cout << ans << endl;
	}
}

Measured memory_bytes: 4408
#include "stdio.h"
#include "iostream"
#include "string"

using namespace std;

int main(){
  string c, d;
  cin >> c >> d;
  
  bool ok = true;
  if(c[0] != d[2]) ok = false;
  if(c[2] != d[0]) ok = false;
  if(c[1] != d[1]) ok = false;
  
  if(ok){
    	cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	static int mod(String num, int a) 
    { 
          
        // Initialize result 
        int res = 0; 
  
        // One by one process all digits of 'num' 
        for (int i = 0; i < num.length(); i++) 
            res = (res * 10 + (int)num.charAt(i) 
                                     - '0') % a; 
  
        return res; 
    } 
	public static void main(String args[])
	{
		Scanner scan=new Scanner(System.in);
		String cur=scan.next();
//		int dp[]=new int[13];
		int n=cur.length();
		long sum=0;
//		String zero=cur.replace('?','0');
//		int modx=mod(zero,13);
		int dp[][]=new int[n+1][13];
		dp[0][0]=1;
		for(int i=0;i<n;i++)
		{
			int c;
			if(cur.charAt(i)=='?') {c=-1;}
			else {
				c=cur.charAt(i)-'0';
			}
			for(int num=0;num<=9;num++)
			{
				if(c!=-1 && c!=num)continue;
				for(int mod_prev=0;mod_prev<13;mod_prev++)
				{
					int mod_pos=(mod_prev*10+num)%13;
					dp[i+1][mod_pos]+=dp[i][mod_prev];
					dp[i+1][mod_pos]%=1000000007;
					
				}
			}
		}
		System.out.println(dp[n][5]);
		
		
	}
}


Measured memory_bytes: 32464
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n;
  cin >> n;
 
  int i=1;
  while(i<50001){
    if(n <= i*1.08 && i*1.08 < n+1){
      cout << i << endl;
      break;
    }
    i++;
  }
  
if(i==50001){
  cout << ":(" << endl;
}

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
#define REP(i,n) for (lint i = 0; i < (n); i++)
#define REP1(i,n) for (lint i = 1; i < (n); i++)

int main(void){
    lint r;
    cin >> r;
    cout << 3 * r * r << endl;
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10 ** 8)
ini = lambda: int(sys.stdin.readline())
inm = lambda: map(int, sys.stdin.readline().split())
inl = lambda: list(inm())
ins = lambda: sys.stdin.readline().rstrip()
debug = lambda *a, **kw: print("\033[33m", *a, "\033[0m", **dict(file=sys.stderr, **kw))

N = ins()
K = ini()


def solve():
    M = len(N)
    dp_eq = [[0 for _ in range(K + 1)] for _ in range(M)]
    dp_less = [[0 for _ in range(K + 1)] for _ in range(M)]

    dp_eq[0][K - 1] = 1
    dp_less[0][K] = 1
    dp_less[0][K - 1] = ord(N[0]) - ord("0") - 1
    for i in range(1, M):
        is_zero = N[i] == "0"
        for k in range(K + 1):
            if is_zero:
                dp_eq[i][k] = dp_eq[i - 1][k]
            elif k < K:
                dp_eq[i][k] = dp_eq[i - 1][k + 1]

            dp_less[i][k] = dp_less[i - 1][k]
            if k < K:
                dp_less[i][k] += dp_less[i - 1][k + 1] * 9
            if not is_zero:
                dp_less[i][k] += dp_eq[i - 1][k]
                if k < K:
                    dp_less[i][k] += dp_eq[i - 1][k + 1] * (ord(N[i]) - ord("0") - 1)
    return dp_eq[M - 1][0] + dp_less[M - 1][0]


print(solve())


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

using namespace std;

#define INF ((int)2e18)
#define eb emplace_back
#define ii pair<int, int>
#define OK (cerr << "OK" << endl)
#define debug(x) cerr << #x " = " << (x) << endl
#define ff first
#define ss second
#define int long long
#define tt tuple<int, int, int>
#define all(x) x.begin(), x.end()
#define Matrix vector<vector<int>>
#define Mat(n, m, v) vector<vector<int>>(n, vector<int>(m, v))
#define endl '\n'
const int MOD = 1e9 + 7;

signed main() {

  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  vector<int> v = {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};

  int k;
  cin >> k;
  cout << v[k - 1] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define F first
#define S second
#define _READ freopen("input.txt", "r", stdin);
#define _FAST                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(0);                       \
    cout.tie(0);
const int mod = 1e9 + 7;
void max_self(int &a,int b)
{
    a=max(a,b);
}
int32_t main()
{
    int n,m;
    cin>>n;
    m=n;
    n=(n+1000-1)/1000;
    n*=1000;
    cout<<n-m;
    return 0;
}

Measured memory_bytes: 3632
import java.io.InputStream;
import java.io.OutputStream;
import java.util.Scanner;
import java.io.PrintWriter;
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task task = new Task();
        while (in.hasNext()) {
            task.solve(in, out);
            out.flush();
        }
        out.close();
    }
    static class Task {
        public void solve(Scanner in, PrintWriter out) {
            int a = in.nextInt(), b = in.nextInt();
            out.println((a * b) % 2 == 0 ? "Even" : "Odd");
        }
    }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for(int i = a; i <= b; i++)
#define per(i, a, b) for(int i = a; i >= b; i--)
typedef long long LL;
const int maxn = 2e5 + 5;
const LL mod = 1e9 + 7;

int n, x, y, first[maxn], dep[maxn], s[maxn][2], f[maxn][27], g[maxn], dis[maxn], cnt;
bool vis[maxn];
struct Edge {
	int to, next, ser;
} e[maxn<<2];

void Dfs(int u, int fa) {
	dep[u] = dep[fa] + 1;
	f[u][0] = fa;
	g[u] = dep[u];
	for(int i = first[u]; i; i = e[i].next) {
		int v = e[i].to;
		if(v == fa || e[i].ser) continue;
		Dfs(v, u);
		g[u] = max(g[v], g[u]);
	}
}

void add(int u, int v, int ser) {
	e[++cnt] = (Edge) {v, first[u], ser};
	first[u] = cnt;
}

int Lca(int u, int v) {
	if(dep[u] < dep[v]) swap(u, v);
	int dif = dep[u] - dep[v];
	per(i, 25, 0)
	    if(dif >= (1<<i)) {
	    	dif -= 1<<i;
	    	u = f[u][i];
	    }
	if(u == v) return u;
	per(i, 25, 0)
	    if(f[u][i] != f[v][i]) {
	    	u = f[u][i];
	    	v = f[v][i];
	    }
	return f[u][0];
}


bool Bfs(int s) {
	memset(dis, 0x7f, sizeof(dis));
	queue <int> q;
	dis[s] = 0;
	q.push(s);
	while(!q.empty()) {
		int u = q.front();
		q.pop();
		for(int i = first[u]; i; i = e[i].next) {
			int v = e[i].to;
			if(!e[i].ser || dis[u] + 1 >= dep[v] || dis[v] != 0x7f7f7f7f) continue;
			dis[v] = dis[u] + 1;
			q.push(v);
		}
	}
	rep(i, 1, n)
	    if(dis[i] < dep[i] && vis[i])
	    	return 1;
	return 0;
}

int main() {
	cin>>n>>x>>y;
	int u, v;
	rep(i, 1, n - 1) {
		scanf("%d%d", &u, &v);
		s[i][0] = u, s[i][1] = v;
	}
	rep(i, 1, n - 1) {
		scanf("%d%d", &u, &v);
		add(u, v, 0);
		add(v, u, 0);
	}
	dep[0] = -1;
	Dfs(y, 0);
	rep(k, 1, 25)
	    rep(i, 1, n) 
	        f[i][k] = f[f[i][k - 1]][k - 1];
	rep(i, 1, n - 1) {
		int d = Lca(s[i][0], s[i][1]);
		if(dep[s[i][0]] + dep[s[i][1]] - 2*dep[d] > 2) vis[s[i][0]] = vis[s[i][1]] = 1;
		else {
			add(s[i][0], s[i][1], 1);
			add(s[i][1], s[i][0], 1);
		}
	} 
	if(Bfs(x)) {
		cout<<-1<<endl;
		return 0;
	}
	else {
		int ans = 0;
		rep(i, 1, n)
		    if(dis[i] < dep[i]) ans = max(ans, dep[i]);
		cout<<ans*2<<endl;
	}
}

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

int main() {
  int n, k, d, a;
  int ans = 0;
  cin >> n >> k;
  vector<bool> oka(n);
  rep(i, k) {
    cin >> d;
    rep(j, d){
      cin >> a;
      oka.at(a - 1) = 1;
    }
  }
  rep(i, n){
    if(!oka.at(i)) ans++;
  }
  cout << ans << endl;
    
}
  
  

Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
//#define int long long

template <class T>
bool INRANGE(T x, T a, T b) { return a <= x && x <= b; }
template <class T>
bool chmax(T &a, const T &b) {if (a < b){ a = b; return 1;} return 0;}
template <class T>
bool chmin(T &a, const T &b) {if (a > b){ a = b; return 1;}return 0;}
template <class T>
void printv(vector<T> v) {for (T t : v) {cout << t << " ";}cout << '\n';}

#define REP(i, n) for (int i = 0; i < (n); ++i)
#define RREP(i, n) for (int i = (n); i >= 0; --i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define RFOR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(v) (v).begin(), (v).end()
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" <<endl;

typedef vector<int> vi;
typedef vector<string> vs;
typedef vector<vi> vvi;
typedef pair<int, int> pii;

int main()
{

    int n;
    cin >> n;

    int half = (n+1)/2;
    cout << (double) half/n << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, i; cin >> N;
  int cAC = 0, cWA = 0, cTLE = 0, cRE = 0;
  string Si;
  string AC = "AC", WA = "WA", TLE = "TLE", RE = "RE";
  
  for(i=0; i<N; i++){
    cin >> Si;
    if(Si == AC){cAC++;
    }else if(Si == WA){cWA++;
    }else if(Si == TLE){cTLE++;
    }else if(Si == RE){cRE++;
    }
  }
  cout << "AC x " << cAC << endl;
  cout << "WA x " << cWA << endl;
  cout << "TLE x " << cTLE << endl;
  cout << "RE x " << cRE << endl;
}

Measured memory_bytes: 3624
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    A, B, C = map(int, input().split())

    ans1 = abs(A // 2 * B * C - (A - A // 2) * B * C)
    ans2 = abs(B // 2 * A * C - (B - B // 2) * A * C)
    ans3 = abs(C // 2 * B * A - (C - C // 2) * B * A)
    print(min(ans1, ans2, ans3))


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
n=int(input())
ans=0
flag=0

for i in range(n):
  a,b=map(int,input().split())
  if a==b:
    ans+=1
  else:
    ans=0
  if ans == 3:
    flag=1
if flag == 1:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 62432
#include <bits/stdc++.h>
#define ll long long
#define vl vector<ll>
using namespace std;
int main() {
    ll N, W;
    cin >> N >> W;
    vl val(N + 1), wei(N + 1);
    for(int i = 1; i <= N; ++i) cin >> wei[i] >> val[i];
    vector<vector<ll>> arr(N + 1, vector<ll>(W + 1));
    for(int i = 1; i <= N; ++i){
        for(int j = 1; j <= W; ++j) {
            if(wei[i] > j)
                arr[i][j] = arr[i - 1][j];
            else
                arr[i][j] = max(arr[i - 1][j], arr[i - 1][j - wei[i]] + val[i]);
        }
    }
    cout << arr[N][W] << endl;
}


Measured memory_bytes: 81520
import numpy as np
words = lambda t : list(map(t, input().split()))

n,k = words(int)
vs = words(int)
#print(vs)
ans = 0
if True: # k < n:
    for i in range(k+1):
        #print("--------------")
        r = k-i
        #print(i,r)
        if i > n:
            continue
        for j in range(-1,i):
            temp = []
            for l in range(i):
                #print(j-l)
                temp.append(vs[j-l])
            temp.sort()
            #print(temp)
            for _ in range(r):
                if len(temp) == 0:
                    break
                if temp[0] < 0:
                    temp.pop(0)
                else:
                    break
            ss = sum(temp)
            ans = max(ans, ss)


print(ans)


Measured memory_bytes: 14408
#include<stdio.h>
#include<math.h>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	scanf("%d",&n);
	int a[10000]={0};
	for(int i=0;i<n;i++)
	scanf("%d",&a[i]);
	sort(a,a+n);
	long long num=0;
	for(int i=0;i<n-2;i++)
	{
		for(int j=i+1;j<n-1;j++)
		{
			for(int k=j+1;k<n;k++)
			{
				if(a[k]<(a[i]+a[j]))
				num++;
			
			}
		}
	}
	printf("%d\n",num);
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void) {
    int num,len,i,j,count,flag;
    char p[1000000];
    while (1) {
        scanf("%d\n",&num);
        if (num==0) break;
        count=0,flag=0;
        scanf("%d\n%s",&len,p);
        for (i=0; i<=len-(num*2+1); i++) {
            if (p[i]=='I') {
                if (flag==0) {
                    for (j=1; j<num*2+1; j++) {
                        if ((j%2==0&&p[i+j]!='I')||(j%2==1&&p[i+j]!='O')) {
                        	i+=j-1;
                            flag=0;
                            break;
                        }
                        if (j==num*2) {
                            count++;
                            i++;
                            flag=1;
                        }
                    }
                } else {
                    if (p[i+num*2-1]=='O'&&p[i+num*2]=='I') {
                        count++;
                        i++;
                    } else {
                        i+=num*2-2;
                        flag=0;
                    }
                }
            }
        }
        printf("%d\n",count);
    }
    return 0;
}

Measured memory_bytes: 1584
import java.util.HashSet;
import java.util.Scanner;
import java.util.Set;

public class Main {
    static Scanner in;

    void solve() {
        int n = in.nextInt();
        Set<Integer> s = new HashSet<>();
        for(int i = 0; i < n; i++) {
            s.add(in.nextInt());
        }
        int q = in.nextInt();
        Set<Integer> t = new HashSet<>();
        for(int i = 0; i < q; i++) {
            t.add(in.nextInt());
        }
        int sum = 0;
        for(int i : s) {
            for(int j : t) {
                sum += i == j ? 1 : 0;
            }
        }

        System.out.println(sum);
    }

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

Measured memory_bytes: 40872
/*input
2
ip cc
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define eb emplace_back
#define pb push_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define EL cout<<'\n'
#define BS(a,x) binary_search(ALL(a),x)
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}
template<typename T>
ostream& operator<<(ostream& out,vector<T> V){
	REP(i,SZ(V)) out<<V[i]<<((i!=SZ(V)-1)?" ":"");
	return out;
}
//}}}
const ll maxn=300005;
const ll maxlg=20;
const ll INF64=1e18;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const ld PI=acos(-1);
const ld eps=1e-9;
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}


int main(){
	IOS;
	int n;
	string s;
	cin>>n>>s;
	if(string(s,0,n/2)==string(s,n/2,n-n/2)) cout<<"Yes\n";
	else cout<<"No\n";
	return 0;
}


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

using namespace std;

#define PI 3.1415926535
 
int main()
{
    double a, b, c, d;
    int n;
     
    while (1) {
        cin >> a >> b >> c;
        if (a == 0 && b == 0 && c == 0) break;

        double e = min(min(sqrt(pow(a, 2) + pow(b, 2)),
			   sqrt(pow(a, 2) + pow(c, 2))),
                           sqrt(pow(b, 2) + pow(c, 2)));
         
        cin >> n;
        for (int i = 0; i < n; i++) {
            cin >> d;
            cout << (d * 2 <= e ? "NA" : "OK") << endl;
        }
    }     
    return 0;
}

Measured memory_bytes: 3216
/* https://tenka1-2019-beginner.contest.atcoder.jp/tasks/tenka1_2019_c */

#include <iostream>
#include <vector>
#include <string>
#include <stack>

using namespace std;

/* {{{ Variables */
int N;
string S;
vector<int> T;
/* }}} */

int main(int argc, char *argv[])
{
  /* {{{ Input */
  cin >> N >> S;

  T = vector<int>(N);
  /* }}} */

  /* {{{ Output */
  stack<char> stk;
  int cnt = 0;

  for (int i = 0; i < N; ++i) {
    char s = S.at(i);

    if (s == '#') {
      stk.push(s);
      continue;
    }

    if (stk.empty()) {
      continue;
    }

    stk.pop();
    cnt++;
  }


  cout << cnt << endl;
  /* }}} */

  return 0;
}


Measured memory_bytes: 1412
import java.util.Scanner;
public class Main{
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();
        int b = a / 100;
        String c = Integer.toString(b);
        String d = c + c + c;
        if (a - Integer.parseInt(d) > 0) {
            System.out.println(Integer.parseInt(d) + 111);
        } else {
            System.out.println(d);
        }
    }
}


Measured memory_bytes: 22992
#include <iostream>
#include <fstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <string>
#include <cstdio>
#include <stack>

using namespace std;

int main()
{
	int X;
	cin >> X;
	long long int ans = 0;

	for (int i = 1; i < X; ++i) {
		for (int j = 2; j < X; ++j) {
			if ((long long)pow(i, j) > 0 && (long long)pow(i, j) <= X) {
				ans = max(ans, (long long)pow(i, j));
			}
		}
	}

	if (X == 1) {
		ans = 1;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 512
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		long N=sc.nextLong();
		long sq=root(N)+1L;
		for(; sq>=1L; sq--) {
			if(N%sq==0) {
				if((N/sq) * sq == N ) {
					p(sq + N/sq - 2);
					System.exit(0);
				}
			}
		}
	}
	public static void p(Object o) {
		System.out.println(o);
	}
	static long root(long a) {

		int ketasu=0;
		long tmp=a;
		while(tmp>0) {
			ketasu++;
			tmp/=10L;
		}
		int constant=(ketasu+1)/2;	//よく使うので定数化
		if(ketasu>=1) {
			long[] suuji=new long[constant];
			tmp=a;
			for(int i=0; i<constant; i++) {
				suuji[constant-1-i]=a%100L;
				a/=100L;
			}
			long ans=0;
			long kai=0;
			long mae=0;
			if(constant<=1) {
				for(long i=10L; i>=0L; i--) {
					if(suuji[0]>=i*i) {
						return i;
					}
				}
			}
			else {
				for(long i=0L; i<constant; i++) {
					mae+=kai*2L;
					for(long j=9L; j>=0L; j--) {
						if((mae*10+j)*j<=suuji[(int)i]) {
							ans=ans*10+j;
							mae*=10;
							kai=j;
							if(i+1<constant) {
								suuji[(int)i+1]+=(suuji[(int)i]-(mae+j)*j)*100;
							}
							break;
						}
					}
				}
			}
			return ans;
		}
		else {
			return 0L;
		}
	}
}

Measured memory_bytes: 23892
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define rfor(i,a,b)     for(ll i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll lul2 = 998244353;
const ll lul = 1000000007;

void mod(ll &x)
{
    if(x>=lul) x-=lul;
    if(x<0) x+=lul;
}

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

ll expo(ll n, ll p)
{
    if(p == 0) return 1;
    ll x = expo((n*n)%lul, p/2)%lul;
    if(p&1) return (x*n)%lul;
    return x;
}
//---------------------------------------------------------------------

void solve()
{
    string s; cin>>s;
    int n = s.length();
    int ans = 0;
    rep(i,0,n)
    {
        if(s[i] == '?') s[i] = 'D';
    }
    cout<<s;
    
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3728
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  if(a + b > c + d) cout << "Left" << "\n";
  else if(a + b == c + d) cout << "Balanced" << "\n";
  else cout << "Right" << "\n";

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
	int a,s,d,f,i;
	scanf("%d",&f);
	for(i=1;i<=f;i++){
	scanf("%d %d",&a,&s);
	d=a%s;
		if(d==0){
		printf("%d\n",s);
		}
		else {
	printf("%d\n",d);
	}

	}
 return 0;
}

Measured memory_bytes: 1028
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int a = s.nextInt();
		int b = s.nextInt();
		int ans = Math.max(Math.max(a+b, a-b),a*b);
		System.out.println(ans);

	}

}


Measured memory_bytes: 21844
#include<iostream>
#include<sstream>
#include<vector>
#include<iterator>
#include<algorithm>
#include<numeric>
using namespace std;

int main(void)
{
	vector<int> abc(3);
	for(int i=0; i<3; i++)
		cin >> abc[i];

	int K;
	cin >> K;

	sort(abc.begin(), abc.end());
	for(int i=0; i<K; i++)
		abc[2] *= 2;

	cout << accumulate(abc.begin(), abc.end(), 0) << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){

    int N,a[100001],i,ans=0;

    scanf("%d",&N);
    for(i = 1;i <= N;i++){
        scanf("%d",&a[i]);
    }

    for(i = 1;i <= N;i++){
        if(a[a[i]] == i){
            ans++;
        }
    }

    printf("%d\n",ans/2);
    return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<cstdio>
#include<string>
#include<algorithm>
using namespace std;

int main() {
  long long a, b, x;
  cin >> a >> b >> x;
  long long ans = (b/x) -(((a+x-1)/x)-1);
  
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
    int i,j,l,m,n;
    char a[500],b[500],c[500];
    scanf("%s %s %s",a,b,c);
    l=strlen(a);
    m=strlen(b);
    n=strlen(c);
    if(a[l-1]==b[0] && b[m-1]==c[0])
    {
        printf("YES\n");
    }
    else
    {
        printf("NO\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

int main() {
  int n, m; cin >> n >> m;
  vector<int> num(n, 1);
  vector<bool> red(n, false);
  red[0] = true;

  for (int i = 0; i < m; i ++) {
    int x, y;
    cin >> x >> y;
    x --, y --;
    if (red[x]) red[y] = true;
    num[x] --, num[y] ++;
    if (num[x] == 0) red[x] = false;
  }

  int ans = 0;
  rep(i, n) {
    if (red[i]) ans ++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <stdio.h>

int fanc(int x, int y, int z)
{
	int r;
	if(x*x + y*y == z*z || x*x + z*z == y*y || z*z + y*y == x*x){
		r = 1;
	}
	else{ r = 0; }

	return r;
}


int main(void)
{
	int n;
	int i;
	int x, y, z;
	
	while(scanf("%d", &n) != EOF){
		for(i = 0; i < n; i++){
			scanf("%d %d %d", &x, &y, &z);
			if(fanc(x, y, z)){ puts("YES"); }
			else{ puts("NO");}
		}
	}
	return 0;
}

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

int main() {
  int m,n;
  int value=0;
  map<string,int> mp;
  
  cin >>m;
  for(int i=0;i<m;i++){
    string s;
    cin >>s;
    mp[s]++;
  }
  
  cin >>n;
  for(int i=0; i<n;i++){
    string s; cin >>s;
    mp[s]--;
  }
  
  for(auto it :mp){
    value=max(value,it.second);
  }
 cout << value << endl; 
}


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

template<typename T>
istream& operator >> (istream& istr, vector<T>& v){
    for(T& x: v) istr >> x;
    return istr;
}

template<typename T, typename U>
istream& operator >> (istream& istr, pair<T,U>& p){
    istr >> p.first >> p.second;
    return istr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<T>& v){
    if(!v.empty()){
        ostr << v.front();
        for(auto itr = ++v.begin(); itr != v.end(); itr++)
            // ostr << *itr;
            ostr << " " << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, pair<T,U>& p){
    // ostr << p.first << p.second;
    // ostr << p.first << ", " << p.second;
    ostr << "(" << p.first << ", " << p.second << ")";
    return ostr;
}

template<typename T>
ostream& operator << (ostream& ostr, vector<vector<T>>& vv){
    if(!vv.empty()){
        ostr << vv.front();
        for(auto itr = ++vv.begin(); itr != vv.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

template<typename T, typename U>
ostream& operator << (ostream& ostr, vector<pair<T,U>>& vp){
    if(!vp.empty()){
        ostr << vp.front();
        for(auto itr = ++vp.begin(); itr != vp.end(); itr++)
            ostr << endl << *itr;
    }
    return ostr;
}

typedef long long ll;
typedef vector<ll> vll;
typedef vector<char> vc;
typedef vector<double> vd;
// vll v(n); v[i]=x;
typedef vector<vll> vvll;
typedef vector<vc> vvc;
typedef vector<vd> vvd;
// vvll v(m,vll(n)); v[i][j]=x;
typedef pair<ll,ll> pll;
typedef pair<double,double> pd;
typedef vector<pll> vpll;
typedef vector<pd> vpd;
// vpll v(n); v[i]=make_pair(x,y); v[i].first/second;
// v.front() : v[0]
// v.back()  : v[v.size()-1]

#define PI 3.1415926535897932
#define EPS 1e-12
#define INF ((ll)1e+12)
#define REP(i,n) for(ll i=0; i<(n); i++)
#define RREP(i,n) for(ll i=(n)-1; i>=0; i--)
#define FOR(i,a,b) for(ll i=(a); i<=(b); i++)
#define FORR(i,a,b) for(ll i=(b); i>=(a); i--)
#define fix(x) cout << fixed << setprecision(x)
#define dump(x) cout << #x << " = " << (x) << endl
#define all(x) (x).begin(),(x).end()

template<typename T> T sum(vector<T>& v){return accumulate(all(v), (T)0);}
template<typename T> inline void sort(vector<T>& v){sort(all(v));}
template<typename T> inline void rsort(vector<T>& v){sort(all(v), greater<T>());}
template<typename T> inline void chmin(T& a, T b){if(a>b) a=b;}
template<typename T> inline void chmax(T& a, T b){if(a<b) a=b;}

int main(){
    ll a, b, c, d = 0;
    cin >> a >> b >> c >> d;
    while(1){
        c -= b;
        if(c<=0){cout << "Yes" << endl; return 0;}
        a -= d;
        if(a<=0){cout << "No" << endl; return 0;}
    }
    return 0;
}


Measured memory_bytes: 3636
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define rep(i,a,b) for(int i=a;i<=b;i++)
#define per(i,a,b) for(int i=a;i>=b;i--)
#define mset(s,_) memset(s,_,sizeof s)
#define fi first
#define se second
#define pb push_back

template<typename T>
void chmax(T &a,T b){
  if(a<b)a=b;
}

map<int,ll>dp[200010];
ll a[200010],n;

ll dfs(int num,int k){
	if(k<=0) return 0;
  if(num==n&&k==1) return a[num];
  if(k>(n-num)/2+1) return -1e18;
	if(dp[num].count(k)) return dp[num][k];
	if((n-num+1)&1){
		 return dp[num][k]=max(dfs(num+2,k-1)+a[num],max(dfs(num+3,k-1)+a[num+1],dfs(num+4,k-1)+a[num+2]));
	}
	else {
		return dp[num][k]=max(dfs(num+2,k-1)+a[num],dfs(num+3,k-1)+a[num+1]);
	}
}

int main(){
	cin>>n;
	rep(i,1,n) cin>>a[i];
	a[1+n]=-1e18;
	a[2+n]=-1e18;
	a[3+n]=-1e18;
	cout<<dfs(1,n/2)<<'\n';
}

	
	
	

Measured memory_bytes: 45796
N, M, X = map(int, input().split())
A = [0] * N
for i in [int(a) for a in input().split()]:
    A[i] += 1
B = [0] * (N+1)
C = [0] * (N+1)
for i in range(N):
    B[i+1] = B[i] + A[i]
for i in range(N)[::-1]:
    C[i] = C[i+1] + A[i]

print(M - max(B[X+1], C[X]))

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

typedef long long lint;
typedef pair<int, int> P;
#define REP(i, x, n) for(int i = x ; i < n ; ++i)
#define rep(i, n) for(int i = 0 ; i < n ; ++i)
#define repr(i, n) for(int i = n - 1 ; i >= 0 ; --i)
#define ALL(x) (x).begin(), (x).end()
#define SORT(x) sort((x).begin(), (x).end())

const int IINF = 1e9 + 10;
const long long LLINF = (long long)1e18 + 10;
const long long MOD = (long long)1e9 + 7;
const int dx4[] = {1, 0, -1, 0}, dy4[] = {0, 1, 0, -1};
const int dx8[] = {1, 1, 0, -1, -1, -1, 0, 1}, dy8[] = {0, -1, -1, -1, 0, 1, 1, 1};
const double EPS = 1e-8;

int main(){
    int n, k;
    cin >> n >> k;
    vector<lint> a(n);
    rep(i, n){
        cin >> a[i];
    }
    vector<lint> sum1(n + 1), sum2(n + 1);
    sum1[0] = 0;
    sum2[0] = 0;
    REP(i, 1, n + 1){
        sum1[i] = sum1[i - 1] + a[i - 1];
        sum2[i] = sum2[i - 1] + max(a[i - 1], 0LL);
    }
    lint ans = -LLINF;
    rep(i, n - k + 1){
        ans = max(ans, max(sum1[i + k] - sum1[i], 0LL) + sum2[n] - (sum2[i + k] - sum2[i]));
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
import sys

input = sys.stdin.buffer.readline
n, m = map(int, input().split())


# union-find
# xの根を求める


def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]


# xとyの属する集合の併合
def unite(x, y):
    x = find(x)
    y = find(y)
    if x == y:
        return False
    else:
        # sizeの大きい方をxとする
        if par[x] > par[y]:
            x, y = y, x
        par[x] += par[y]
        par[y] = x
        return True


# xとyが同じ集合か判定
def is_same(x, y):
    return find(x) == find(y)


def size(x):
    return -par[find(x)]


# 初期化
# 根なら-size、子なら親の頂点
par = [-1] * (n + 1)

for _ in range(m):
    x, y, z = map(int, input().split())
    unite(x, y)
ans = 0
for i in range(1, n + 1):
    if i == find(i):
        ans += 1
print(ans)


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

def insertionSort():
  for i in range(1, n):
    v = a[i]
    j = i-1
    while j>=0 and a[j]>v:
      a[j+1] = a[j]
      j -= 1
    a[j+1] = v
    print(" ".join(map(str, a)))

print(" ".join(map(str, a)))
insertionSort()


Measured memory_bytes: 5604
#include <bits/stdc++.h>
#include <unordered_set>
using namespace std;
#define ll long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define repeat(i,s,n) for(int (i)=s; (i)<(n); (i)++)
#define revrep(i,n) for(int (i)=(n)-1;i>=0; i--)

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<setprecision(std::numeric_limits<float>::max_digits10);
  int n,a,b;
  cin>>n>>a>>b;
  int c1=0;
  int c2=0;
  int c3=0;
  rep(i,n) {
    int x;
    cin>>x;
    if(x<=a)c1++;
    else if(x<=b)c2++;
    else c3++;
  }
  cout << min(c1,min(c2,c3)) << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <unordered_map>
#include <vector>
#include <utility>
#include <cassert>
#include <algorithm>
#include <cstring>

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using pii64 = pair<int64_t, int64_t>;

int main(int argc, char *argv[]) {
  int X, A;
  cin >> X >> A;
  cout << (X < A ? 0 : 10) << endl;
  return 0;
}


Measured memory_bytes: 256
s=str(input())
t=str(input())
for i in range(len(s)-len(t)+1):
    l=s[len(s)-len(t)-i:len(s)-i]
    if all([l[i]==t[i] or l[i]=="?" for i in range(len(t))]):
        s=s[:len(s)-len(t)-i]+t+s[len(s)-i:]
        break
s=s.replace("?","a")
if t in s:print(s)
else:print("UNRESTORABLE")

Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cstring>
#include <map>
#include <algorithm>
using namespace std;
typedef long long LL;
#define PI 3.1415926536

int main(){
    string a, b;
    while(cin >> a >> b) {
        int flag = 0;
        if(a.size() > b.size()) flag = 1;
        else if(a.size() == b.size()) {
            for (int i = 0; i < a.size(); i++) {
                if(a[i] > b[i]){
                    flag = 1;
                    break;
                }
                else if(a[i] < b[i]) break;
                else flag = 2;
            }
        }
        if(flag == 1) cout << "GREATER" << endl;
        else if(flag == 2) cout << "EQUAL" << endl;
        else cout << "LESS" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
// ALDS1_01 Insertion Sort
import java.io.*;

class Main {
   public static void main(String[] args) {
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));

      try { 
         int N = Integer.parseInt(br.readLine());
         int[] A = new int[N];
         String[] input = br.readLine().split(" ");
         for (int i = 0; i < N; i++) {
            A[i] = Integer.parseInt(input[i]);
         }
         trace(A, N);
         insertionSort(A, N);
      }
      catch (Exception e) {
         e.printStackTrace();
      }
   }
   static void insertionSort(int[] A, int N) {
      for (int i = 1; i < A.length; i++) {
         int key = A[i];
         int j = i - 1;
         while (j >= 0 && A[j] > key) {
            A[j + 1] = A[j];
            j--;
         }
         A[j + 1] = key;
         trace(A, N);
      }
   }
   static void trace(int[] A, int N) {
      for (int i = 0; i < A.length; i++) {
         if (i < N - 1) {
            System.out.print(A[i] + " ");
         } else { 
            System.out.println(A[i]);
         }
      }
   }
}

Measured memory_bytes: 23800
#include <iostream>
using namespace std;
int main(){
 int N, D, X;
 cin >> N >> D >> X;
 int A[N];
 for(int i=0;i<N;i++) cin >> A[i];

 int S = X;
 for(int i=0;i<N;i++) S += 1 + (D-1)/A[i];
 cout << S << endl;
 return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
using Pld = pair<ld, ld>;
using Vec = vector<ll>;
using VecP = vector<P>;
using VecB = vector<bool>;
using VecC = vector<char>;
using VecD = vector<ld>;
using VecS = vector<string>;
template <class T>
using Vec2 = vector<vector<T>>;
#define REP(i, m, n) for(ll i = (m); i < (n); ++i)
#define REPN(i, m, n) for(ll i = (m); i <= (n); ++i)
#define REPR(i, m, n) for(ll i = (m)-1; i >= (n); --i)
#define REPNR(i, m, n) for(ll i = (m); i >= (n); --i)
#define rep(i, n) REP(i, 0, n)
#define repn(i, n) REPN(i, 1, n)
#define repr(i, n) REPR(i, n, 0)
#define repnr(i, n) REPNR(i, n, 1)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <class T1, class T2>
bool chmax(T1 &a, const T2 b){if(a < b){a = b; return true;} return false;}
template <class T1, class T2>
bool chmin(T1 &a, const T2 b){if(a > b){a = b; return true;} return false;}
ll pow2(const int n){return (1LL << n);}
void co() { cout << endl; }
template <class Head, class... Tail>
void co(Head&& head, Tail&&... tail) {
    cout << head << ' ';
    co(forward<Tail>(tail)...);
}
void ce() { cerr << endl; }
template <class Head, class... Tail>
void ce(Head&& head, Tail&&... tail) {
    cerr << head << ' ';
    ce(forward<Tail>(tail)...);
}
void sonic(){ios::sync_with_stdio(false); cin.tie(0);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18L+1;
constexpr ll MOD = 1e9L+7;
constexpr ll MOD_N = 998244353;
constexpr ld EPS = 1e-11;
const double PI = acos(-1);

int main(void){
    ll d, t, s;
    cin >> d >> t >> s;
    if (d <= t * s) puts("Yes");
    else
        puts("No");

    return 0;
}


Measured memory_bytes: 3632
import heapq
from collections import deque


def max_value(V, N, K, A, B):
    V = deque(V.copy())
    value = 0
    neg_que = list()
    for _ in range(A):
        if len(V) == 0:
            break
        v = V.popleft()
        value += v
        if v < 0:
            heapq.heappush(neg_que, v)
    for _ in range(B):
        if len(V) == 0:
            break
        v = V.pop()
        value += v
        if v < 0:
            heapq.heappush(neg_que, v)
    max_throw_num = max([K - min([N, A + B]), 0])
    for _ in range(max_throw_num):
        if len(neg_que) == 0:
            break
        v = heapq.heappop(neg_que)
        value -= v
    return value


def main():
    N, K = list(map(int, input().split(' ')))
    V = list(map(int, input().split(' ')))
    max_v = 0
    for a in range(K + 1):
        for b in range(K + 1):
            if a + b > K:
                continue
            v = max_value(V, N, K, a, b)
            max_v = max([v, max_v])
    print(max_v)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316