akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

int main(){
    long long n,temp;
    cin >> n;
    vector<long long> a;
    for(long long i = 0; i < 3*n; i++){
        cin >> temp;
        a.push_back(temp);
    }
    sort(a.begin(),a.end());
    long long ans = 0;
    for(long long i = n; i <= 3*n; i = i+2){
        ans += a[i];
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 6256
// D - I hate Factorization
#include <bits/stdc++.h>
using namespace std;
using ll = long long;

int main(){
	ll X; cin>>X;
	for(ll a=-119; a<=119; ++a)
		for(ll b=-119; b<=119; ++b)
			if(a*a*a*a*a - b*b*b*b*b == X){ cout<<a<<" "<<b<<endl; return 0; }
}

Measured memory_bytes: 3652
#include <iostream>
#include <queue>
using namespace std;
struct masu { int y, x; };

int h, w, check[50][50];
int X[] = { -1, 0, 1, 0 };
int Y[] = { 0, -1, 0, 1 };
char s[50][50];

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

	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			check[i][j] = INT32_MAX;
		}
	}
	check[0][0] = 0;

	deque<masu>que;
	que.push_back(masu{ 0, 0 });
	while (!que.empty()) {
		masu m = que.front();
		que.pop_front();
		for (int i = 0; i < 4; i++) {
			int y = m.y + Y[i];
			int x = m.x + X[i];
			if (0 <= y && y < h && 0 <= x && x < w && check[y][x] == INT32_MAX && s[y][x] == '.') {
				check[y][x] = check[m.y][m.x] + 1;
				que.push_back(masu{ y, x });
			}
		}
	}

	int y = h - 1, x = w - 1;
	while (check[y][x] != INT32_MAX) {
		s[y][x] = '#';
		if (y == 0 && x == 0)break;

		for (int i = 0; i < 4; i++) {
			int y2 = y + Y[i];
			int x2 = x + X[i];
			if (0 <= y2 && y2 < h && 0 <= x2 && x2 < w && check[y2][x2] == check[y][x] - 1) {
				y = y2;
				x = x2;
				break;
			}
		}
	}

	int ans = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if (s[i][j] == '.')ans++;
		}
	}

	cout << (s[0][0] == '.' ? -1 : ans) << endl;
}

Measured memory_bytes: 256
/**************************************************************
	File name: C.cpp
	Author: huhao
	Email: 826538400@qq.com
	Create time: 2019/8/17 下午8:51:35
**************************************************************/
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;
#define fr(i,a,b) for(int i=(a),end_##i=(b);i<=end_##i;i++)
#define fd(i,a,b) for(int i=(a),end_##i=(b);i>=end_##i;i--)
int read()
{
	int r=0,t=1,c=getchar();
	while(c<'0'||c>'9')
	{
		t=c=='-'?-1:1;
		c=getchar();
	}
	while(c>='0'&&c<='9')
	{
		r=(r<<3)+(r<<1)+(c^48);
		c=getchar();
	}
	return r*t;
}
const int N=200010;
int a[N],b[N];
#include<queue>
priority_queue<pair<int,int>>q;
int n;
long long ans;
int main()
{
	n=read();
	fr(i,1,n)
		a[i]=read();
	fr(i,1,n)
	{
		b[i]=read();
		if(b[i]>a[i])
			q.push(make_pair(b[i],i));
		if(b[i]<a[i])
		{
			printf("-1\n");
			return 0;
		}
	}
	b[0]=b[n];
	b[n+1]=b[1];
	while(!q.empty())
	{
		int p=q.top().second;
		q.pop();
		int k=max(b[p]-max(a[p],max(b[p-1],b[p+1]))-1,0)/(b[p-1]+b[p+1])+1;
		ans+=k;
		b[p]-=k*(b[p-1]+b[p+1]);
		b[0]=b[n];
		b[n+1]=b[1];
		if(b[p]<a[p])
		{
			printf("-1\n");
			return 0;
		}
		if(b[p]!=a[p])
			q.push(make_pair(b[p],p));
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 3700
n = int(input())
ls = []
for i in range(n-1):
    c, s, f = map(int, input().split())
    ls.append((c, s, f))

for i in range(n-1):
    x = 0
    for j in range(i, n-1):
        if x < ls[j][1]:
            x = ls[j][1] + ls[j][0]
        else:
            mod = x % ls[j][2]
            if mod == 0:
                time = 0
            else:
                time = ls[j][2] - mod
            x += time + ls[j][0]
    print(x)

print(0)


Measured memory_bytes: 3188
N = int(input())
A = [int(i) for i in input().split()]
Sa = sum(A)
h = Sa/2
S = 0

for a in A:
    if S+a > h:
        if abs(h-S) > abs(h-S-a):
            S += a
        break
    S += a

print(abs((Sa-S)-S))


Measured memory_bytes: 26396
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define pb push_back
 
const int maxn = 2e5 + 20;

int a[maxn] , n , m;

bool check(int x)
{
	x *= 2;
	bool f = 1;
	for(int i = 2 * n - x; i < 2 * n; i++)
		f &= (a[i] + a[4 * n - i - 1 - x] >= m);

	return f;
}

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

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

	sort(a , a + 2 * n);

	int l = 0 , r = n + 1;
	while(r - l > 1)
	{
		int x = (l + r) / 2;

		if(check(x))
			l = x;
		else
			r = x;
	}

	int res = 0 , x = l * 2;
	for(int i = 0; i < 2 * n - x; i++)
		res = max(res , (a[i] + a[2 * n - x - i - 1]) % m);

	for(int i = 2 * n - x; i < 2 * n; i++)
		res = max(res , (a[i] + a[4 * n - i - 1 - x]) % m);

	cout << res << endl;
}


















Measured memory_bytes: 1024
from heapq import heappop, heappush

N=int(input())
*a,=map(int,input().split())

r=[None]*(3*N)
s=[None]*(3*N)
p=[]
q=[]
ans=-float("inf")

for i in range(N):
    heappush(p,a[i])
v=sum(p)
r[N-1]=v
for i in range(N,2*N):
    heappush(p,a[i])
    b=heappop(p)
    v=v+a[i]-b
    r[i]=v

for i in range(2*N,3*N)[::-1]:
    heappush(q,-a[i])
v=sum(q)
s[2*N]=-v
for i in range(N,2*N)[::-1]:
    heappush(q,-a[i])
    b=heappop(q)
    v=v-a[i]-b
    s[i]=-v

for i in range(N-1,2*N):
    ans=max(ans,r[i]-s[i+1])

print(ans)

Measured memory_bytes: 37212
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
#define rep(i, n) for(int i=0; i<n; ++i)
#define all(obj) (obj).begin(), (obj).end()
using P = pair<int, int>;
const int inf = 1e9;
const ll INF = 1e18;
const ll MOD = 1e9+7;
const ll MAX = 1e9+7;
template<typename T> T factorial(T n){
    if(n==1) return 1;
    else return n*factorial(n-1)%MOD;
}
template<typename T> T Pow(T x, T n, T m){
    if(n == 0) return 1;
    if(n % 2 == 0) return Pow(x * x % m, n / 2, m);
    else return x * Pow(x, n - 1, m) % m;
}
template<typename T> T combination(T n, T k, T m){
    return factorial<T>(n) * Pow<T>(factorial(k), m-2, m) % m * Pow<T>(factorial(n-k), m-2, m) % m;
}
struct edge{
    int to; // 辺の行き先
    int weight; // 辺の重み
    edge(int t, int w) : to(t), weight(w) { }
};
using graph = vector<vector<edge>>;
using Graph = vector<vector<int>>;

int main(){
    int n; cin >> n;
    ll ans = 0;
    for(int i=1; i<=n; i++){
        if((i % 3 != 0) && (i % 5 != 0)) ans += (ll)i;
    }
    cout << ans << endl;
    return 0;
}

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

int main()
{
	string s;
	int count, x = 0, result = 0;
	cin >> count >> s;

	for (int i = 0; i < count; i++)
	{
		if (s[i] == 'I')
		{
			x++;
			if (result < x)	
				result = x;
		}
		else if (s[i] == 'D')
		{
			x--;
		}
	}

	cout << result << endl;
	return 0;
}

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

int main()
{
    int n, m;
    cin >> n >> m;
    // scanf("%d", &x);
    int mi = 1;
    int ma = n;

    rep(i, m)
    {
        printf("%d %d\n", mi, ma);
        if (n % 2 == 0 && mi == n / 4)
        {
            mi++;
        }
        mi++;
        ma--;
    }
}

Measured memory_bytes: 3760
W, H, c = input().split()
W, H = int(W), int(H)
for i in range(H):
    if i == 0 or i == H - 1:
        print("+" + "-" * (W-2) + "+")
    elif i == H//2:
        line = list(("|" + "." * (W-2) + "|"))
        line[W//2] = c
        print("".join(line))
    else:
        print("|" + "." * (W-2) + "|")



Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<n; ++i) // マクロ
using namespace std; // stdの省略
using pii = pair<int, int>; // pairの略記
using ll = long long; // long longの略記


int main(void) {
   
   int x;
   cin >> x;
   
   int ans = 0;
   if (x==ans) ans = 1;

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

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define n_max 55




 
llong nCk (int n, int k) {
    llong ans=1;
    if( n-k < k) k= n-k;
    FOR(i,1,k+1){
        ans *= (n+1-i);
        ans /= i;
    }
    return ans;
}


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

    llong A[n_max];
    REP(i,n) cin >> A[i];
    sort(A,A+n,greater<llong>() );


    llong cnt=0;
    llong ans=0;
    if( A[0] == A[a-1]){
        REP(i,n) if( A[0] == A[i]) cnt +=1;
        FOR(i,a,1+min(cnt,llong(b))) ans += nCk(cnt,i);

    }
    else{
        int i=0;
        int kosuu=0;
        REP(i,a) if( A[i] == A[a-1] ) kosuu +=1;
        while(1){
            if( A[a-1] == A[i]) cnt +=1;
            i+=1;
            if(i>=n) break;
        }
        ans = nCk(cnt,kosuu);

    }

    double sum=0;
    double ave;
    REP(i,a){
        sum += A[i];
    }


    cout << fixed << setprecision(8) << (double)sum/a << endl;
    cout << ans << endl;
}

Measured memory_bytes: 256
# ABC119b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

n = int(input())
x = [list(input().split()) for _ in range(n)]
ans = 0

for i in x:
    if (i[1] == 'BTC'):
        ans += float(i[0]) * 380000
    else:
        ans += int(i[0])
print(ans)

Measured memory_bytes: 3060
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# include <stack>
# include <queue>
# include <list>
using namespace std;
using LL = long long;
constexpr int MOD = 1000000000 + 7;
constexpr int INF = 2000000000;

int C[1000];

int main() {
	LL q, h, s, d, n;
	cin >> q >> h >> s >> d >> n;
	LL min1 = min({ q * 4,h * 2,q * 2 + h,s });
	LL min2 = min(min1*2, d);
	cout << (n / 2)*min2 + (n % 2 == 0 ? 0: min1) << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <array>
#include <algorithm>

using namespace std;

const int32_t N = 25;
array<int32_t, N> parent, left, right, sibling, degree, depth, height;

int32_t calc_depth_height(int32_t id, int32_t d) {
    depth[id] = d;

    int32_t height_l = 0, height_r = 0;
    if (left[id] != -1) height_l = calc_depth_height(left[id], d+1);
    if (right[id] != -1) height_r = calc_depth_height(right[id], d+1);

    height[id] = max(height_l, height_r);

    return height[id] + 1;
}

int main() {
    parent.fill(-1);
    left.fill(-1);
    right.fill(-1);
    sibling.fill(-1);
    degree.fill(0);
    int32_t n;

    scanf("%d", &n);
    for (int32_t i = 0; i < n; i++) {
        int32_t id, l, r;
        scanf("%d %d %d", &id, &l, &r);

        if (l != -1) {
            left[id] = l;
            degree[id]++;
            parent[l] = id;
            sibling[l] = r;
        }

        if (r != -1) {
            right[id] = r;
            degree[id]++;
            parent[r] = id;
            sibling[r] = l;
        }
    }

    int32_t id = 0;
    while (parent[id] != -1) id++;
    calc_depth_height(id, 0);

    for (int32_t id = 0; id < n; id++) {
        printf("node %d: parent = %d, sibling = %d, degree = %d, depth = %d, height = %d, ", id, parent[id], sibling[id], degree[id], depth[id], height[id]);

        if (parent[id] == -1) {
            printf("root");
        } else if (left[id] == -1 && right[id] == -1) {
            printf("leaf");
        } else {
            printf("internal node");
        }

        printf("\n");
    }

    return 0;
}

Measured memory_bytes: 2760
def print_list(array, N):
    for i, e in enumerate(array):
        if i == N - 1:
            print(e)
        else:
            print(e, end=" ")

N = int(input())
a = [int(e) for e in input().split()]
print_list(a, N)
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_list(a, N)



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

long n, p, w, b, sum, x[100010];

int main() {
    ios::sync_with_stdio(false); cin.tie(0);
    cin >> n >> p;
    for(int i = 0; i < n; ++i) {
      cin >> w >> b;
      x[i] = (100 - p) * w + p * b;
      sum -= p * b;
    }
    sort(x, x + n, greater<long>());

    long ans = 0;
    for(int i = 0; i < n; ++i) {
      ++ans;
      sum += x[i];
      if(sum >= 0) break;
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 1024
using System;

namespace ITP1_10_A
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            double x = double.Parse(str[2]) - double.Parse(str[0]);
            double y = double.Parse(str[3]) - double.Parse(str[1]);

            double r = Math.Sqrt(Math.Pow(x, 2) + Math.Pow(y, 2));
            Console.WriteLine(r);
        }
    }
}

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

using namespace std;

typedef long long ll;
const ll INF = 1LL<<60;

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

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

ll modpow(ll a, ll n, ll mod) {
    ll res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

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

    int N, K;
    cin >> N >> K;
    if(K > ((N-1)*(N-2)/2)){
        cout << -1 << endl;
    }else{
        int N_add = (N-1)*(N-2)/2 - K;

        int M = (N-1) + N_add;
        cout << M << endl;
        for(int i = 2; i <= N; i++){
            cout << 1 << " " << i << endl;
        }

        int tmp_N_add = 0;
        for(int i = 2; i < N; i++){
            for(int j = i+1; j <= N; j++){
                if(tmp_N_add == N_add) break;
                cout << i << " " << j << endl;
                tmp_N_add++;
            }
        }
    }

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define N 2000010
#define INF 0x3f3f3f3f

using namespace std;

int n_road,n_rail;
int city;
int road_cont[2][N];
int road[2][N];
bool visit[N];
int cont[N];
int path[N];

set <int> way_cont[2][N],temp_cont;
set <int>::iterator it;

int Find(bool way,int x)
{
    if(x==road_cont[way][x])return x;
    else return road_cont[way][x]=Find(way,road_cont[way][x]);
}

void join(bool way,int a,int b)
{
    if(road[way][a]<road[way][b]) road_cont[way][a]=b;
    else
    {
        road_cont[way][b]=a;
        if(road[way][a]==road[way][b]) ++road[way][a];
    }
}

void Create()
{
    int i;
    int x,y;
    for(i=1; i<=city; ++i)
    {
        road_cont[0][i]=road_cont[1][i]=i;
    }
    for(i=1; i<=n_road; ++i)
    {
        scanf("%d%d",&x,&y);

        int f1=Find(0,x);
        int f2=Find(0,y);
        if(f1!=f2) join(0,f1,f2);
    }
    for(i=1; i<=n_rail; ++i)
    {
        scanf("%d%d",&x,&y);

        int f1=Find(1,x);
        int f2=Find(1,y);
        if(f1!=f2) join(1,f1,f2);
    }
    //Create_tree
    for(int j=1; j<=city; ++j)
    {
        way_cont[0][Find(0,j)].insert(j);
    }
    //公路
    for(int j=1; j<=city; ++j)
    {
        way_cont[1][Find(1,j)].insert(j);
    }
    //火车
    memset(visit,0,sizeof(visit));
}

void Travel_Tree()
{
    for(int i=1; i<=city; i++)
    {
        if(visit[i])continue;
        int top=0;
        int Root1,Root2;
        Root1=Find(0,i);
        Root2=Find(1,i);
        bool road;
        if(way_cont[0][Root1].size() > way_cont[1][Root2].size())
        {
            temp_cont=way_cont[1][Root2];
            road=true;
        }
        else
        {
            temp_cont=way_cont[0][Root1];
            road=false;
            int t=Root1;
            Root1=Root2;
            Root2=t;
        }

        for(it=temp_cont.begin(); it!=temp_cont.end(); it++)
        {
            int p=*it;
            if(way_cont[!road][Root1].find(p)!=way_cont[!road][Root1].end())
            {
                path[++top]=(p);
                visit[p]=1;

                way_cont[road][Root2].erase(p);
                way_cont[!road][Root1].erase(p);
            }
        }
        for(int j=1; j<=top; j++)
        {
            cont[path[j]]=top;
        }
    }
}

int main()
{
    scanf("%d%d%d",&city,&n_road,&n_rail);
    Create();
    Travel_Tree();
    for(int i=1; i<=city; ++i)
    {
        if(i!=1)printf(" ");
        printf("%d",cont[i]);
    }
    printf("\n");
    return 0;
}


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

typedef long long LL;
typedef pair<int,int> pii;

#define pb push_back
#define mp make_pair

const int N = 1e5 + 10;
int n, x[N], y[N], fa[N], sz[N];
unordered_map<int, int> X, Y, cx[N], cy[N];
int ST[N], top;

int find_fa(int x){
    top = 0;
    while(x != fa[x]){
        ST[top++] = x;
        x = fa[x];
    }
    while(top--){
        fa[ST[top]] = x;
    }
    return x;
}

int main(){
    scanf("%d", &n);
    int fx, fy;
    for(int i=1; i<=n; i++){
        fa[i] = i;
        sz[i] = 1;
        scanf("%d %d", x+i, y+i);

        if(!X.count(x[i])){
            X[x[i]] = i;
        }
        fx = find_fa(X[x[i]]);
        if(!Y.count(y[i])){
            Y[y[i]] = i;
        }
        fy = find_fa(Y[y[i]]);

        if(fx != fy){
            if(sz[fx] < sz[fy]){
                swap(fx, fy);
            }
            fa[fy] = fx;
            sz[fx] += sz[fy];
            X[x[i]] = fx;
            Y[y[i]] = fx;
        }
    }

    LL ans = 0;
    for(int i=1; i<=n; i++){
        fx = find_fa(X[x[i]]);

        cx[fx][x[i]]++;
        cy[fx][y[i]]++;
    }

    for(int i=1; i<=n; i++){
        if(fa[i] == i){
            ans = ans + 1LL * cx[i].size() * cy[i].size() - sz[i];
        }
    }

    printf("%lld\n", ans);

    return 0;
}


Measured memory_bytes: 21272
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
using namespace std;
typedef long long ll;
int main() {
    int n,m;
    cin >> n >> m;
    int a[n + 1];
    int sum = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        sum += a[i];
    }
    int count = 0;
    for (int i = 1; i <= n; i++) {
        if (a[i] * 4 * m >= sum) {
            count ++;
        }
    }
    if (count >= m) {
        cout << "Yes";
    }
    else {
        cout << "No";
    }
    return 0;
    }

Measured memory_bytes: 256
def input():
    import sys
    return sys.stdin.readline().rstrip()


def main():
    import math
    import collections
    import itertools

    n = int(input())
    as_ = list(map(int, input().split()))
    
    sunuke = as_[0]
    araiguma = sum(as_[1:])
    diff = abs(sunuke - araiguma)
    for i in range(1, n - 1):
        sunuke += as_[i]
        araiguma -= as_[i]
        diff = min(diff, abs(sunuke - araiguma))

    print(diff)
    
if __name__ == '__main__':
    main()

Measured memory_bytes: 25316
def prime_factorize(n):
    res = []
    p = 2
    while p*p <= n:
        if n % p != 0:
            p += 1
            continue
        num = 0
        while n % p == 0:
            num += 1
            n //= p
        res.append( [p, num] )
        p += 1

    if n != 1: res.append( [n, 1] )

    return res


# n! の約数の数を mod で割った余りを返す
def mod_div_fact(n, mod):
    d = {}
    for i in range(2, n+1):
        L = prime_factorize(i)
        for (p, e) in L:
            d[p] = d.get(p, 0) + e
    res = 1
    for v in d.values():
        res *= (v+1)
        res %= mod
    return res;

n = int(input())
mod = int(1e9)+7

print(mod_div_fact(n, mod))

Measured memory_bytes: 3064
#include <stdio.h>

int main(void)
{
	int d, l, r, i;

	scanf("%d %d %d", &l, &r, &d);

	int ans = 0;
	for (i = l; i <= r; i++)
		if (i % d == 0)
			ans++;

	printf("%d", ans);
	return 0;
}

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

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

	vector<bool> a(n, false);

	for (int i = 0; i < k; i++) {

		int tmp_d; cin >> tmp_d;

		for (int j = 0; j < tmp_d; j++) {
			int tmp_a; cin >> tmp_a;
			a[tmp_a - 1] = true;
		}

	}

	int  ans = 0;
	for (int i = 0; i < n; i++) {
		if (!a[i]) ans++;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
using namespace std;


int main(int argc, const char * argv[]) {
    int H, W;
    cin >> H >> W;
    vector<vector<char>> c(H, vector<char> (W));
    for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
            cin >> c.at(i).at(j);
        }
    }

    for(int i = 0; i < H*2; i++){
        for(int j = 0; j < W; j++){
            cout << c.at(i/2).at(j);
        }
        cout << endl;
    }
    return 0;    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
#define INF 1e9+7
#define rep(i,n) for(ll i=0;i<n;i++)
const int maxn = 200000;
ll mod = INF;

int n;
int a[maxn];
bool key=false;
int ans;

int main(){
    
    cin >> n;
    rep(i,n){
        cin >> a[i];
    }
    ans=n;
    int now=0;
    rep(i,n){
        if(a[i]==now+1){
            now=a[i];
            ans--;
        }
    }

    if(ans==n){
        cout << -1<<endl;
    }else{
        cout << ans<<endl;
    }

    return 0;
}

Measured memory_bytes: 4380
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>
using namespace std;
const long long md=1000000007;
string s1,s2;
long long n,p,ans;
bool ok;
int main()
{
	cin>>n>>s1>>s2;
	if(s1[0]==s2[0])
	{
		ans=3;
		p++;
		ok=true;
	}
	else
	{
		ans=6;
		p+=2;
		ok=false;
	}
	while(p<n)
	{
		if(s1[p]==s2[p])
		{
			if(ok)
			{
				ans*=2;
			}
			p++;
			ok=true;
		}
		else
		{
			if(ok)
			{
				ans*=2;
			}
			else
			{
				ans*=3;
			}
			p+=2;
			ok=false;
		}
		ans%=md;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define PII pair<int,int>
const int INF = (1<<30);


void solve(){

}

int main(){

//    ios_base::sync_with_stdio(false);
//    cin.tie(nullptr);

//    int test;
//    cin>>test;
//
//    while(test--)
//        solve();
    
    
    char ch;
    cin>>ch;
    ch++;
    cout<<ch;
    
    return 0;
}





Measured memory_bytes: 256
def main():
    N = int(input())
    S = [s for s in input()]
    ans = 10**9
    w = 0
    r = S.count("R")
    for i in range(N+1):
        ans = min(ans, max(w, r))
        if i == N:
            break
        if S[i] == "W":
            w += 1
        else:
            r -= 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 92884
#include <string>
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <cmath>
#define rep(i,n) for(int i = 0; i < (n); i++)
using namespace std;

int main()
{
    int n, m;
    cin >> n >> m;
    if(n == m) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 888
N = int(input())
p = list(map(int, input().split()))

ans = 0
for i in range(N-1):
    if p[i] != i+1:
        continue
    tmp = p[i]
    p[i] = p[i+1]
    p[i+1] = tmp
    ans += 1
if p[N-1] == N:
    ans += 1
print(ans)


Measured memory_bytes: 14008
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n, m, k;
  cin >> n >> m >> k;
  UnionFind uf(n);
  vi cnt(n);
  rep(i,m){
    int a, b;
    cin >> a >> b;
    a--; b--;
    cnt[a] ++;
    cnt[b] ++;
    uf.unite(a, b);
  }
  rep(i,k){
    int c, d;
    cin >> c >> d;
    c--; d--;
    if(uf.same(c, d)){
      cnt[c]++;
      cnt[d]++;
    }
  }
  rep(i,n) cout << uf.size(i)-cnt[i]-1 << " ";
}

Measured memory_bytes: 3964
#include<bits/stdc++.h>
using namespace std;
int main(){
  int K,S;cin >> K >> S;
  int x,y,z;
  int ans = 0;
  for(x = 0; x <= K; x++){
    for(y = 0; y <= K; y++){
      z = S - x - y;
      if(z <= K and z >= 0) ans++;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3584
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());
    let n: usize = sc.read();
    let k: usize = sc.read();
    let mut a: Vec<usize> = sc.vec::<usize>(n).into_iter().filter(|&a| a < k).collect();
    a.sort();
    if a.is_empty() || is_needed(0, &a, k) {
        sc.write("0\n".to_string());
        return;
    }
    let n = a.len();
    let mut no_need = 0;
    let mut needed = n;
    while needed - no_need > 1 {
        let m = (needed + no_need) / 2;
        if is_needed(m, &a, k) {
            needed = m;
        } else {
            no_need = m;
        }
    }
    sc.write(format!("{}\n", no_need + 1));
}

fn is_needed(i: usize, a: &Vec<usize>, k: usize) -> bool {
    let mut dp = vec![false; k];
    dp[0] = true;
    for (j, &a) in a.iter().enumerate() {
        if j == i {
            continue;
        }
        for l in (0..k).rev() {
            if l + a < k {
                dp[l + a] |= dp[l];
            }
        }
    }
    for t in 0..k {
        if dp[t] && t + a[i] >= k {
            return true;
        }
    }
    false
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write(&mut self, s: String) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll INF = 1e18;
const ll mod = 1000000007;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return 1;
  }
  return 0;
}
int ctoi(char c) {
  if (c >= '0' && c <= '9') {
    return c - '0';
  }
  return 0;
}
ll factorial(ll n) {
  if (n == 1) {
    return 1;
  }
  ll ans = factorial(n-1);
  return ans*n;
}
ll gcd(ll a, ll b) {
  if (a < b) {
    ll tmp = a;
    a = b;
    b = tmp;
  }
  ll r = a%b;
  while(r != 0) {
    a = b;
    b = r;
    r = a%b;
  }
  return b;
}
ll lcm(ll a, ll b) {
  return (a/gcd(a, b))*b;
}
bool prime(ll n) {
  if (n == 1) {
    return false;
  } else {
    for (ll i = 2; i <= (ll)pow(n, 0.5); i++) {
      if (n%i == 0) return false;
    }
  }
  return true;
}

int main() {
  ll n;
  cin >> n;
  vector <tuple <ll, ll, string, ll, string>> v(n, tuple <ll, ll, string, ll, string> ());
  ll a, b, d;
  string c, e;  
  rep(i, n) {
    cin >> a >> b >> c >> d >> e;
    v.at(i) = make_tuple(a, b, c, d, e);
  }
  sort(v.begin(), v.end());
  rep(i, n) {
    tie(a, b, c, d, e) = v.at(i);
    cout << a << ' ' << b << ' ' << c << ' ' << d << ' ' << e << endl;
  }
}


Measured memory_bytes: 17744
constexpr bool isDebugMode = false;
int testcase = 1;
#include <bits/stdc++.h>
#if __has_include(<atcoder/all>)
    #include <atcoder/all>
    using namespace atcoder;
#endif
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
struct edge{long long to,cost;};
const int inf = 1 << 27;
const long long INF = 1LL << 60;
const int COMBMAX = 1001001;
const long long MOD = 1000000007; //998244353;
const long long dy[] = {-1, 0, 0, 1};
const long long dx[] = {0, -1, 1, 0};
const string abc = "abcdefghijklmnopqrstuvwxyz";
#define rep(i, n) for(int i = 0; i < (n); ++i)
#define eachdo(v, e) for (const auto &e : (v))
#define all(v) (v).begin(), (v).end()
#define lower_index(v, e) (long long)distance((v).begin(), lower_bound((v).begin(), (v).end(), e))
#define upper_index(v, e) (long long)distance((v).begin(), upper_bound((v).begin(), (v).end(), e))
long long mpow(long long a, long long n, long long mod = MOD){long long res = 1; while(n > 0){if(n & 1)res = res * a % mod; a = a * a % mod; n >>= 1;} return res;}
void pt(){cout << endl; return;}
template<class Head> void pt(Head&& head){cout << head; pt(); return;}
template<class Head, class... Tail> void pt(Head&& head, Tail&&... tail){cout << head << " "; pt(forward<Tail>(tail)...);}
void dpt(){if(!isDebugMode) return; cout << endl; return;}
template<class Head> void dpt(Head&& head){if(!isDebugMode) return; cout << head; pt(); return;}
template<class Head, class... Tail> void dpt(Head&& head, Tail&&... tail){if(!isDebugMode) return; cout << head << " "; pt(forward<Tail>(tail)...);}
template<class T> void enu(T v){rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void enu2(T v){rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T> void debug(T v){if(!isDebugMode) return; rep(i, v.size()) cout << v[i] << " " ; cout << endl;}
template<class T> void debug2(T v){if(!isDebugMode) return; rep(i, v.size()){rep(j, v[i].size()) cout << v[i][j] << " " ; cout << endl;}}
template<class T1, class T2> inline bool chmin(T1 &a, T2 b){if(a > b){a = b; return true;} return false;}
template<class T1, class T2> inline bool chmax(T1 &a, T2 b){if(a < b){a = b; return true;} return false;}
template<class T1, class T2> long long recgcd(T1 a, T2 b){return a % b ? recgcd(b, a % b) : b;}
bool valid(long long H, long long W, long long h, long long w) { return 0 <= h && h < H && 0 <= w && w < W; }

void solve();

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    // cin >> testcase;
    while(testcase--) solve();
    return 0;
}

void solve(){
    ll N; cin >> N;
    vector<ll> a(N);
    vector<ll> ind(N);
    rep(i, N) cin >> a[i];
    rep(i, N) ind[a[i] - 1] = i;
    set<ll> st;
    ll ans = 0;
    st.insert(-1);
    st.insert(N);
    rep(i, N){
        ll left = *(--st.lower_bound(ind[i]));
        ll right = *st.upper_bound(ind[i]);
        ans += a[ind[i]] * (ind[i] - left) * (right - ind[i]);
        st.insert(ind[i]);
    }
    pt(ans);

}

Measured memory_bytes: 15820
#include<iostream>
#include<cstdio>
#include<algorithm>//sort头文件
using namespace std;
int a[10001],ans=0,bns=0,n;//乱入了1个打酱油的变量。
int main()
{
    scanf("%d",&n);//读入数据
    for(int i=1;i<=2*n;i++)//题目说的是2n，别一顺手就打错了。
    {
        scanf("%d",&a[i]);//循环读入
    }
    sort(a+1,a+1+2*n);    //所有数据排序
    for(int i=1;i<=2*n;i+=2)
    {
        bns+=a[i];//根据题意分析，我们只需要逐个跳着加和即为所求。
    } 
    printf("%d\n",bns);//AT通性，换行
    return 0;//结束
}


Measured memory_bytes: 256
### constant

MAX_INT = 1 << 30

COINS = [1, 5, 10, 50, 100, 500]
RCOINS = COINS.reverse

### subroutines

def num_coins(pn, nis)
  num = 0

  5.downto(0) do |i|
    ci = COINS[i]
    k = [pn / ci, nis[i]].min
    next if k == 0

    num += k
    pn -= ci * k
    break if pn == 0
  end

  num
end

def changes(pn)
  count = 0

  for cn in RCOINS
    k = pn / cn
    count += k
    pn -= k * cn
    break if pn == 0
  end

  count
end

### main

loop do
  pn, *nis = gets.strip.split(' ').map(&:to_i)
  break if pn == 0

  min_num = MAX_INT

  for plus in (0..499)
    n0 = num_coins(pn + plus, nis)
    n1 = changes(plus)
    num = n0 + n1

    min_num = num if min_num > num
  end

  puts min_num
end

Measured memory_bytes: 6112
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
 
int main(){
    string w , t;
    int count=0;
    cin>>w;
    transform(w.begin() , w.end() , w.begin() , ::toupper);
    while(1){   
        cin>>t;
        if (t.find("END_OF_TEXT")!=string::npos) break;
        transform(t.begin() , t.end() , t.begin() , ::toupper);
        if (t==w) count++;
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 1184
#include<bits/stdc++.h>
using namespace std;
#define int long long 
#define mp make_pair
#define pb push_back
#define pii pair<int,int>
#define F first
#define S second
int const M=2e5+10;
int a[M];
main()
{
	int ans=0;
	int n;
	cin>>n;
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=n;i>=1;i--)
	{
		if((n-i)%2==0)ans+=a[i];
		else ans-=a[i];
	}
	cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cctype>
#include <cstdio>
using namespace std;
typedef long long ll;
typedef string::const_iterator State;
#define rep(i,n) for(int i=0;i<(n);i++)

class Parser{
public:
    int expression(State &begin){
        int ret = term(begin);
        for(;;){
            if(*begin == '+'){
                begin++;
                ret += term(begin);
            }else if(*begin == '-'){
                begin++;
                ret -= term(begin);
            }else{
                break;
            }
        }
        return ret;
    }
    int term(State &begin){
        int ret = factor(begin);
        for(;;){
            if(*begin == '*'){
                begin++;
                ret *= factor(begin);
            }else if(*begin == '/'){
                begin++;
                ret /= factor(begin);
            }else{
                break;
            }
        }
        return ret;
    }
    int factor(State &begin){
        int ret;
        if(*begin == '('){
            begin++;//'('?????????
            ret = expression(begin);
            begin++;//')'?????????
        }else{
            ret = number(begin);
        }
        return ret;
    }
    int number(State &begin){
        int ret = 0;
        while(isdigit(*begin)){
            ret *= 10;
            ret += *begin - '0';
            begin++;
        }
        return ret;
    }
};

int main(void){
    int n; cin >> n;
    rep(i, n){
        Parser ps;
        string s; cin >> s;
        string tmp = s.substr(0, s.size() - 1);
   //     cout << tmp << endl;
        State begin = s.begin();
        int ret = ps.expression(begin);
        printf("%d\n", ret);
    }
    return 0;
}

Measured memory_bytes: 3156
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In,' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var min = 30;

            var N = cin.ReadInt;
            for(int i=0;i<N;++i)
            {
                var A = cin.ReadInt;
                var c = 0;
                //シフト関数を使って、1bit左にシフトさせる
                while(A%2==0 && A!=0){A >>= 1; ++c;}

                //最小値の取得
                min = Min(min,c);
            }
            WriteLine(min);
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream,char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }

        public string Read
        {
            get
            {
                if(inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for(int i = 0;i < tmp.Length;i++)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }

        
        public string ReadLine { get { return _stream.ReadLine(); }}
        public int ReadInt { get { return int.Parse(Read); }}
        public long ReadLong { get { return long.Parse(Read); }}
        public double ReadDouble { get { return double.Parse(Read); }}
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret;}
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret;}
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret;}
    }

}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =1001001001;

//最大公約数
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*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




/*10億7。　　　100000007
2*2行列 H*W
vector<vector<int>> vec(H,vector<int>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>vec[i][j];
  }
}

文字列→数列
string S;int A=atoi(S.c_str());
数列→文字列
int A;string S=to_string(A);
数字判定　isdigit(a)
pair宣言　pair<int,int> p(5,7);
ソート　sort(vec.begin(),vec.end());
キュー　queue<int> q;
   q.push(7);　//７が入る
   cout << q.front() << endl;  // 先頭の値を出力
   q.pop();  // 先頭の値を削除
   q.empty();
*/
//座標　corrdinateト深さヲ保持スルタメノ構造体
struct Coor{
  ll y;
  ll x;
  ll depth;
};
 ll N,M;  
 ll sy,sx,gy,gx;
 ll y,x,depth;//キューから取り出した座標
vector<string> vec;
queue<Coor> q;
vector<ll> y_vec={0,0,-1,+1};//technique
vector<ll> x_vec={-1,+1,0,0};

int BFS(){
  while(!q.empty()){
    Coor now=q.front();q.pop();//キューの先頭を取り出す
    y=now.y,x=now.x,depth=now.depth;
    
    //停止条件
    if(y==gy&&x==gx){return depth;}
    
    //上下左右４方向を探索、進むことができればキューに格納
    for(int i=0;i<4;i++){
      Coor next={y+y_vec[i],x+x_vec[i],depth+1};
      if(0<=next.y&&next.y<=N-1&&0<=next.x&&next.x<=M-1&&vec[next.y][next.x]=='.'){
        vec[next.y][next.x]='x';//同じ場所を探索しないようにする
        q.push(next);
      }
    }
  }
  return 0;
}
                   
  


int main(void){
cout<<fixed<<setprecision(14);
//cin.tie(0); ios::sync_with_stdio(false);


  string S;cin>>S;
  vsort(S);
  
  int counter=1;
  for(int i=0;i<S.size();i++){
    if(S[i]==S[i+1]){
      counter++;
    }
    if(S[i]!=S[i+1]){
      if(counter%2==1){
        cout<<"No"<<endl;
        return 0;
      }else{
        counter=1;
      }
    }
  }
    cout<<"Yes"<<endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
const ll INF = 1e17;
const int MOD = 1000000007;

 
int main() {
  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i,n) cin >> a.at(i);
  rep(i,n-1) a.at(i+1) += a.at(i);
  
  ll ans = INF;
  rep(i,n-1){
    ans = min(ans,abs(a.at(n-1) - 2*a.at(i)));
  }
  
  cout << ans << endl;            
  return 0;
}






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

#define ll long long
using namespace std;

int main() {
ll n;
cin>>n;
ll x=1;
ll ans=0;
for(ll i=0;i<n;i++)
{
    ll temp;
    cin>>temp;
    if(temp==x)
    {
        x++;
    }
    else{
        ans++;
    }
}
if(ans==n)
{
    ans=-1;
}
cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし

N,M,K = map(int,S().split())
A = LI()
A.reverse()
B = LI()
C = A+B

a = 0
b = N-1
r = sum(A)
ans = 0
while a <= N:
    if r > K:
        a += 1
        r -= C[a-1]
    else:
        ans = max(ans,b-a+1)
        b += 1
        if b < len(C):
            r += C[b]
        else:
            break

print(ans)

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

int main() {
  char a, b;
  cin >> a >> b;

  if ((a == 'H' && b == 'H') || (a == 'D' && b == 'D'))
    cout << 'H' << endl;
  else
    cout << 'D' << endl;
  return 0;
}

Measured memory_bytes: 3380
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus < 201703L
#        pragma GCC target("avx")
#    else
#        pragma GCC target("avx2")
#    endif

#endif

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;
typedef long double Ld;

using namespace std;
using Graph = vector<vector<Int>>;

const Ld pi = M_PI;
const Int MOD = 1000000007;
const Int INF = 1LL << 61;

Int Floor(Int a, Int b) {
    return (a - (a % b)) / b;
}

Int Ceil(Int a, Int b) {
    if (a % b == 0) {
        return a / b;
    } else {
        return Floor(a, b) + 1;
    }
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);

    const int alp = (int)('z' - 'a' + 1);
    int n;
    cin >> n;
    vector<vector<int>> s(n, vector<int>(alp));
    for (int i = 0; i < n; i++) {
        string k;
        cin >> k;

        int ro = k.size();
        for (int j = 0; j < ro; j++) {
            s[i][k[j] - 'a']++;
        }
    }

    vector<int> anschars(alp, 1 << 30);
    for (int i = 0; i < alp; i++) {
        for (int j = 0; j < n; j++) {
            anschars[i] = min(anschars[i], s[j][i]);
        }
    }

    string ans;
    for (int i = 0; i < alp; i++) {
        int ro = anschars[i];
        for (int j = 0; j < ro; j++) {
            ans += (char)(i + 'a');
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3648
#include <stdio.h>
int main(void)
{
    int a, b;
    scanf("%d %d", &a, &b);
    if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 ==0)
        puts("Possible");
    else
        puts("Impossible");
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define INF 1e16
ll n0;
ll dp[105][100005];
ll sol[105][100005]={0};
ll val[105];
ll wei[105];

ll solv(ll i,ll v)
{
    if(v<=0) return 0;                  //base condition    
    if(i>=n0) return INF;             //base condition
    if(sol[i][v]==1) return dp[i][v];
    
    ll a=solv(i+1,v-val[i])+wei[i];
    ll b=solv(i+1,v);
    
    sol[i][v]=1;
    
    dp[i][v]=min(a,b);              //saving memory
    return dp[i][v];                    //returning ans
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll a,b,c,d,e,f,n,m,k,t,q;
    t=1;
    //cin>>t;
    string s1;
    while(t--)
    {
        cin>>n>>m;
        vector<pair<ll,ll> > v1;
        c=0;
        for(int i=0;i<n;i++)
        {
            cin>>wei[i]>>val[i];
            c+=val[i];
        }
        n0=n;
        
        for(ll v=c;v>=0;v--)
        {
            if(solv(0,v)<=m)
            {
                a=v;
                break;
            }
        }
        cout<<a;
        
    }
    return 0;
}

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

using namespace std;
typedef long long ll;

int main() {
  ll n, k;
  cin >> n >> k;
  if (n % k == 0) {
    puts("0");
  } else {
    ll one = n / k;
    ll two = one + 1;
    ll ans = min(abs(k * one - n), abs(k * two - n));
    cout << ans << '\n';
  }
  return 0;
}



Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,k,c; cin >> n >> k >> c;
	string s; cin >> s;
	int mx=0;
	string t=s;
	for(int i=0;i<s.size();i++){
		if(s[i]=='o'){
			t[i]='#';
			mx++;
			i+=c;
		}
	}
	if(mx>k){
		return 0;
	}
	bool canskip=0;
	vector<int> res;
	int last=1e9;
	for(int i=n-1;i>=0;i--){
		if(t[i]=='o'){
			if(last-i>=c+1&&!canskip){
				canskip=1;
				last=i;
			}
		}
		else if(t[i]=='#'){
			if(canskip)canskip=0;
			else{
				res.push_back(i+1);
				last=i;
			}
		}
	}
	sort(res.begin(),res.end());
	for(int i:res){
		printf("%d\n",i );
	}
}

Measured memory_bytes: 2828
#include <iostream>
#include <algorithm>
#include <string>
#include <cstring>
#include <vector>
using namespace std;
 
vector<int> bt[101];
bool no[101][101];
bool bad[101];
void solve(){
	int N,K;
	cin>>N>>K;
	for(int i=0;i<K;i++){
		int m;
		cin>>m;
		for(int j=0;j<m;j++){
			int a;
			cin>>a;
			bt[i].push_back(a);
		}
	}
	int R;
	cin>>R;
	for(int i=0;i<R;i++){
		int p,q;
		cin>>p>>q;
		no[p][q]=no[q][p]=true;
	}
	for(int i=0;i<K;i++){
		for(int j=0;j<bt[i].size();j++){
			for(int k=j+1;k<bt[i].size();k++){
				if(no[bt[i][j]][bt[i][k]]){
					bad[bt[i][j]]=true;
					bad[bt[i][k]]=true;
				}
			}
		}
	}
	int cnt=0;
	for(int i=0;i<=N;i++){
		if(bad[i])cnt++;
	}
	cout<<cnt<<endl;
}
int main(){
	solve();
	return 0;
}

Measured memory_bytes: 0
import numpy as np

N, K = map(int, input().split())
p = np.array(list(map(int, input().split())))

begin = 0
till = K

max = np.sum(p[0:K])
partial = max
for i in range(N-K):
    partial = partial - p[begin] + p[till]
    if(max < partial):
        max = partial

    begin += 1
    till += 1

print((max + K) / 2)

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

int main() {
	int price = 0;
	cin >> price;

	int bill = 0, change = 0;
	bill = price / 1000;
	if (price % 1000) bill++;
	
	change = 1000 * bill - price;
	cout << change << endl;
	return 0;
}

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

int main()
{
	int n;
	cin >> n;
	int x[1007], y[1007];
	cin >> x[0] >> y[0];
	int eo = ((x[0] + y[0]) % 2 + 2) % 2;
	for (int i = 1; i < n; i++) {
		cin >> x[i] >> y[i];
		if (((x[i] + y[i]) % 2 + 2) % 2 != eo) {
			cout << -1 << endl;
			return 0;
		}
	}
	int m = 31;
	int d[40];
	int pow2 = 1;
	for (int i = 0; i < m; i++) {
		d[30 - i] = pow2;
		pow2 *= 2;
	}
	if (eo == 0) {
		d[31] = 1;
		m++;
	}
    cout << m << endl;
    for (int i = 0; i < m; i++) {
        cout << d[i] << " ";
    }
    cout << endl;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			if (abs(x[i]) > abs(y[i])) {
				if (x[i] >= 0) {
					x[i] -= d[j];
					cout << "R";
				}
				else {
					x[i] += d[j];
					cout << "L";
				}
			}
			else {
				if (y[i] >= 0) {
					y[i] -= d[j];
					cout << "U";
				}
				else {
					y[i] += d[j];
					cout << "D";
				}
			}
		}
		cout << endl;
	}
}

Measured memory_bytes: 256