akhauriyash/Code-Regression huggingface dataset:
import java.util.*;

class Main {
    static final long I=1L<<40;
    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int n=Integer.parseInt(scan.next());
        int q=Integer.parseInt(scan.next());
        long[]a=new long[2*n],b=new long[2*n];
        for(int i=0;i<2*n;++i)a[i]=Integer.parseInt(scan.next());
        for(int i=0;i<2*n;++i)b[i]=Integer.parseInt(scan.next());
        long t=0;
        MaxSegmentTree sd=new MaxSegmentTree();
        MaxSegmentTree sdp=new MaxSegmentTree();
        long tpos=0;
        int cpos=0;
        for(int i=0;i<2*n;++i)t+=a[i];
        for(int i=1;i<2*n-1;++i){
            long c=b[i]-a[i];
            tpos+=Math.max(c,0);
            if(c>=0)cpos++;
            sd.update(i,c>=0?-I:c);
            sdp.update(i,c<0?-I:-c);
        }
        for(int i=0;i<q;++i){
            int p=Integer.parseInt(scan.next())-1;
            long x=Integer.parseInt(scan.next());
            long y=Integer.parseInt(scan.next());
            long c=b[p]-a[p];
            t-=a[p];
            if(1<=p&&p<=2*n-2&&c>=0){
                tpos-=c;
                cpos--;
            }
            a[p]=x;
            b[p]=y;
            c=b[p]-a[p];
            t+=a[p];
            if(1<=p&&p<=2*n-2&&c>=0){
                tpos+=c;
                cpos++;
            }
            if(1<=p&&p<=2*n-2) {
                sd.update(p,c>=0?-I:c);
                sdp.update(p,c<0?-I:-c);
            }
            long ans;
            if(cpos%2==0)
                ans=tpos;
            else{
                ans=Math.max(tpos+sd.query(1,2*n-1),tpos+sdp.query(1,2*n-1));
            }
            System.out.println(ans+t);
        }
    }
}
class MaxSegmentTree {
    static final int SIZE = 1 << 18;
    static final long INFINITY = (1L << 62) - 1;
    long[] seg;
    MaxSegmentTree() {
	this.seg = new long[2 * SIZE];
    }
    void update(int x, long value) {
	x += SIZE - 1;
	this.seg[x] = value;
	while (x > 0) {
	    x = (x - 1) / 2;
	    this.seg[x] = Math.max(this.seg[2 * x + 1], this.seg[2 * x + 2]);
	}
    }
    long query(int l, int r) {
	l += SIZE - 1;
	r += SIZE - 1;
        long y = -INFINITY;
	while (l < r) {
	    if ((l & 1) == 0) {
		y = Math.max(y, this.seg[l]);
	    }
	    if ((r & 1) == 0) {
		y = Math.max(y, this.seg[r - 1]);
	    }
	    l /= 2;
	    r = (r - 1) / 2;
	}
	return y;
    }
}


Measured memory_bytes: 111712
#include <algorithm>
#include <iostream>
#include <memory.h>
#include <math.h>
#include <time.h>
#include <string>
#include <vector>
#include <queue>
#include<stack>
#include <map>
#include <set>
#include <list>
using namespace std;
typedef long long ll;
int main() {
	int n, k;
	scanf("%d %d", &n, &k);
	if (n%k == 0)
		printf("0\n");
	else
		printf("1\n");
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int N,i,ans=0;
  scanf("%d",&N);
  int V[N],C[N];
  for(i=0;i<N;i++){
    scanf("%d",&V[i]);
  }
  for(i=0;i<N;i++){
    scanf("%d",&C[i]);
  }
  for(i=0;i<N;i++)
    if(V[i]-C[i]>0)ans+=V[i]-C[i];
    printf("%d",ans);
    return 0;
}


Measured memory_bytes: 128
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp5
{

    class Program
    {
        static void Main(string[] args)
        {

            int N = int.Parse(Console.ReadLine());
            int[] A = new int[N];
            int[] B = new int[N];

            for(int i=0; i<N; i++)
            {
                A[i] = int.Parse(Console.ReadLine());
                B[i] = i;
            }

            Array.Sort(A, B);

            for(int i=0; i<N; i++)
            {
                if(i == B[N - 1])
                {
                    Console.WriteLine(A[N - 2]);
                }
                else
                {
                    Console.WriteLine(A[N - 1]);
                }
            }
        }
    }
}

Measured memory_bytes: 18004
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<map>
#include<bitset>
#include<queue>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
typedef long long ll;
int main(){
	ll n,a,b;
	cin >> n>>a>>b;

	if(n==1){
		if (a!=b) cout << "0" << endl;
		else cout << "1" << endl;
	}
	else {
		if (a>b) cout << "0" << endl;
		else {
			ll ans = (n-2)*(b-a) + 1;
			cout << ans << endl;
		}
	}

	return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    while (in.hasNext()) {
      int n = in.nextInt();
      int[] p = new int[n];

      for (int i = 0; i < p.length; ++i) {
        p[i] = in.nextInt();
      }

      int count = 0;
      for (int i = 1; i < p.length - 1; ++i) {
        int max = Math.max(p[i - 1], Math.max(p[i], p[i + 1]));
        int min = Math.min(p[i - 1], Math.min(p[i], p[i + 1]));

        if (p[i] < max && p[i] > min) {
          ++count;
        }
      }

      System.out.println(count);
    }
  }
}

Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <cstdio>
#include <string>
#include <cmath>
using namespace std;

long long N, A, B;
int main() {
  while (cin >> N >> A >> B) {
	if (N == 1) {
	  if (A != B) cout << 0 << endl;
	  else cout << 1 << endl;
	}
	else {
	  long long Min = A*(N-1)+B;
	  long long Max = B*(N-1)+A;
	  cout << max(0LL, Max - Min + 1) << endl;
	}
  }
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  int state = 0, num;
  int train[100];
  while(scanf("%d", &num) != EOF){
    if(num != 0){
      train[state] = num;
      state += 1;
    }else{
      state -= 1;
      printf("%d\n", train[state]);
    }
  }
  return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;
const ll inf = (1 << 30) - 1;
const ll infll = (1LL << 61) - 1;

int n, ans, cnt;
string s;

int main()
{
    cin >> n >> s;
    for (int i = 0; i < n; i++)
    {
        if (s[i] == '#')
            ++cnt;
        else
        {
            if (cnt > 0)
                ++ans;
            cnt = max(0, cnt - 1);
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 640
#include<iostream>

using namespace std;

int main()
{
    int D, N;
    cin >> D >> N;
    int x = 0, ans = 0;
    if (D == 0)
    {
        x = 1;
        if (N == 100)
        {
            ans = 101;
            cout << ans << endl;
            return 0;
        }
    }
    else if (D == 1)
    {
        x = 100;
        if (N == 100)
        {
            ans = 10100;
            cout << ans << endl;
            return 0;
        }
    }
    else if (D == 2)
    {
        x = 10000;
        if (N == 100)
        {
            ans = 1010000;
            cout << ans << endl;
            return 0;
        }
    }
    ans = x * N;
    cout << ans << endl;
    return 0;
}

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

#define FOR(i, a, b) for (int i = a; i < b; i++)
#define FORN(i, a, b) for (int i = a; i <= b; i++)
#define P(s) cout << s << endl
#define PC(condition, _true, _false) if (condition) _true; else _false;
#define toInt(_char) _char - '0'

using namespace std;
//
// Created by karayuu on 2018-12-18.
//

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

    P((f - 30) / 2);
}


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

int main() {
  int K, S;
  cin >> K >> S;
  
  int count = 0;
  for (int x = 0; x < K+1; x++) {
    for (int y = 0; y < K+1; y++) {
      int z = S-x-y;
      if (z >= 0 && z <= K)
        count += 1;
    }
  }
  
  cout << count << endl;
}
    

Measured memory_bytes: 256
#include <stdio.h>
#include <queue>
using namespace std;

#define MAX_N (105)
#define MAX_D (100010)
#define INF (MAX_N * MAX_D)

int n;

int G[MAX_N][MAX_N];
int dist[MAX_N];
bool arrived[MAX_N];

void dijkstra(int s)
{
    for ( int i = 0; i < n; i++ ) dist[i] = INF;

    dist[s] = 0;

    while ( true ) {
	int min_dist = INF;
	int index = -1;
	for ( int i = 0; i < n; i++ ) {
	    if ( !arrived[i] && dist[i] < min_dist ) {
		min_dist = dist[i];
		index = i;
	    }
	}
	
	if ( index == -1 ) break;
	arrived[index] = true;

	for ( int i = 0; i < n; i++ ) {
	    if ( !arrived[i] && G[index][i] != INF ) {
		if ( dist[i] > (dist[index] + G[index][i]) ) {
		    dist[i] = dist[index] + G[index][i];
		}
	    }
	}
    }
}


int main()
{
    scanf("%d", &n);

    for ( int i = 0; i < n; i++ ) {
	for ( int j = 0; j < n; j++ ) {
	    G[i][j] = INF;
	}
    }

    for ( int i = 0; i < n; i++ ) {
	int u, k;
	scanf("%d %d", &u, &k);

	for ( int j = 0; j < k; j++ ) {
	    int v, c;
	    scanf("%d %d", &v, &c);
	    G[u][v] = c;
	}
    }

    dijkstra(0);

    for ( int i = 0; i < n; i++ ) {
	printf("%d %d\n", i, dist[i]);
    }

    return 0;
}

Measured memory_bytes: 1072
#include <bits/stdc++.h>
#define rep(i, N) for (int i = 0; i < N; i++)
using namespace std;
int main()
{
    string S;
    int Q, N;
    cin >> N >> Q >> S;
    vector<int> count(N), l(Q), r(Q);
    count[0] = 0;
    rep(i, N - 1)
    {
        if (S[i] == 'A' && S[i + 1] == 'C')
        {
            count[i + 1] = count[i] + 1;
        }
        else
        {
            count[i + 1] = count[i];
        }
    }
    rep(i, Q)
    {
        cin >> l[i] >> r[i];
        cout << count[r[i] - 1] - count[l[i] - 1] << endl;
    }
}


Measured memory_bytes: 2304
import itertools
n = int(input())
#証言　testimony
tes = [[] for _ in range(n)]
for i in range(n):
    a = int(input())
    for _ in range(a):
        x, y = map(int, input().split())
        tes[i].append([x-1, y])
            
# 全員正直者と仮定, n-1人正直者と仮定, n-2人正直者...と数を減らしながら全探索
for i in range(n):
    for C in itertools.combinations(range(n), n-i):
        for c in C:
            for x, y in tes[c]:
                if (y == 0 and x in C) or (y == 1 and x not in C):
                    break
            else:
                continue
            break
        else:
            print(n-i)
            exit()
print(0)

Measured memory_bytes: 3064
a,b,k = gets.chomp.split.map(&:to_i)

if b - a + 1 <= 2 * k
  for i in a..b
    puts i
  end
else
  for i in 0...k
    puts a + i
  end
  for i in 0...k
    puts b - k + 1 + i
  end
end

Measured memory_bytes: 1788
#include <stdio.h>

int main(void)
{
	int a,b;
	
	scanf("%d %d",&a,&b);
	
	if(a>=13)printf("%d\n",b);
	else if(a<=5)printf("0\n");
	else printf("%d\n",b/2);
	
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std; 
const int maxn = 200500;

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    long long a, b;
    cin >> a >> b;
    cout << (a * b) / (long long)__gcd(a, b);
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

// 配列の要素を順番に出力
  void trace(int A[],int N){
    int i;
    for(i=0;i<N;i++){
      if(i>0) printf(" ");//隣接する要素の間に１つの空白を出力
      printf("%d",A[i]);
    }
    printf("\n");
  }
  // 挿入ソート（0オリジン配列）
  void insertionSort(int A[],int  N){
    int j,i,v;
    for (i = 1; i < N; i++) {
      v=A[i];
      j=i-1;
      while(j>=0&&A[j]>v){
        A[j+1]=A[j];
        j--;
      }
      A[j+1]=v;
      trace(A,N);

    }
  }

  int main(){
    int N,i;
    int A[100];

    scanf("%d",&N );
    for (i = 0; i < N; i++) scanf("%d",&A[i] );

    trace(A,N);
    insertionSort(A,N);


  return 0;
}



Measured memory_bytes: 2148
#include <iostream>
#include <string>
#include <cmath>
#include <vector>

using namespace std;

int main(int argc, const char *argv[])
{
  int n;
  cin >> n;

  vector<vector<int>> memo(10, vector<int>(10, 0));
  for (int i = 1; i <= n; i++) {
    string s = to_string(i);
    memo[s.front() - '0'][s.back() - '0']++;
  }

  int ans = 0;
  for (int i = 1; i <= 9; i++) {
    for (int j = 1; j <= 9; j++) {
      ans += memo[i][j] * memo[j][i];
    }
  }

  cout << ans << "\n";
  return 0;
}

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

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<ll> xs;
vector<ll> S;

int main(void) {
    int N, M;
    cin >> N >> M;

    if (N >= M) {
        cout << 0 << endl;
        return 0;
    }

    xs.resize(M);
    for (int i = 0; i < M; i++) {
        cin >> xs[i];
    }
    sort(xs.begin(), xs.end());

    S.resize(M - 1);
    for (int i = 0; i < (int) S.size(); i++) {
        S[i] = xs[i + 1] - xs[i];
    }
    sort(S.begin(), S.end());

    ll acc = 0;
    for (int i = 0; i < M - N; i++) {
        acc += S[i];
    }

    cout << acc << endl;
    return 0;
}


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

int main(){
  int Ans, AnsR, Ans1, r;
  
  cin >> r;
  
  AnsR = r * r * 3;
  Ans1 = 1 * 1 * 3;
  
  Ans = AnsR / Ans1;
  
  cout << Ans << endl;
  
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
      Scanner scan = new Scanner(System.in);
      String num = scan.nextLine();
      String[] strs = num.split("");
      int[] nums = new int[strs.length];
      int sum = 0;
      
      for (int i = 0; i < strs.length; i++) {
        nums[i] = Integer.parseInt(strs[i]);
        sum += nums[i];
      }
      
      if (sum % 9 == 0) {
        System.out.println("Yes");
      } else {
        System.out.println("No");
      }

      
      scan.close();
    }
}

Measured memory_bytes: 65560
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <list>
#include <bitset>
#include <numeric>
#include <utility>
#define INF 1e9
#define MOD 1000000007
#define ll long long
#define int long long
using namespace std;
typedef unsigned long long ull;
typedef pair<int, int> p;
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    string s;
    int c[5];
    fill(c,c+5,0);
    for(int i=0;i<n;i++){
        cin>>s;
        if(s[0]=='M'){
            c[0]++;
        }
        else if(s[0]=='A'){
            c[1]++;
        }
        else if(s[0]=='R'){
            c[2]++;
        }
        else if(s[0]=='C'){
            c[3]++;
        }
        else if(s[0]=='H'){
            c[4]++;
        }
    }
    //    cout<<c[0]<<" "<<c[1]<<" "<<c[2]<<" "<<c[3]<<" "<<c[4]<<endl;
    int ans=0;
    for(int i=0;i<3;i++){
        for(int j=i+1;j<4;j++){
            for(int k=j+1;k<5;k++){
                //            cout<<i<<" "<<j<<" "<<k<<" "<<c[i]*c[j]*c[k]<<endl;
                ans+=c[i]*c[j]*c[k];
            }
        }
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<pair<long,long>> data(N);
  long X, L;
  for(int i = 0; i < N; i++){
    cin >> X >> L;
    data.at(i).first = X + L;
    data.at(i).second = X - L;
  }
  sort(data.begin(), data.end());
  long pl = -1000000001, ans = 0;
  for(int i = 0; i < N; i++){
    if(data.at(i).second >= pl){
      ans++;
      pl = data.at(i).first;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
using namespace std;
int main() {
    int n;
    cin >> n;
    long long sum = 0;
    for (int i = 1; i <= n; i++)
        sum += 1LL * (i + (n / i) * i) * (n / i) / 2;
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 3632
def solve():
    S = input()
    S = S+'*' # 終端文字
    max_sub = 0
    sub_length = 0
    for s in S:
        if s in 'ACGT':
            sub_length += 1
        else: 
            max_sub = max(max_sub, sub_length)
            sub_length = 0
        
    print(max_sub)
    
solve()

Measured memory_bytes: 2940
#include <iostream>
#include <string>
#include <sstream>
 
int main()
{
	std::string text;
	std::string key;
	std::getline(std::cin, text, '\n');
	std::getline(std::cin, key, '\n');

	text += text;

	std::string res;
	if (text.find(key) == std::string::npos)
		res = "No";
	else
		res = "Yes";

	std::cout << res << std::endl;

	return 0;
}


Measured memory_bytes: 3216
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
typedef  long long LL;
using namespace std;
int main()
{
    LL a;
    cin>>a;
    LL b=sqrt(a);
    if(b*b==a)
        cout<<b*b<<endl;
    else
        cout<<b*b<<endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<31でオーバーフロー

int main(int argc,char* argv[]){
    int n,m;
    cin >> n >> m;

    // const int maxvar=100000000;

    int a[m],b[m],c[m],dist[100][100];
    for(int i=0;i<m;i++){
        cin >> a[i] >> b[i] >> c[i];
        a[i]--;
        b[i]--;
    }

    for(int i=0;i<n;i++){
        for(int j=0;j<n;j++){
            if(i==j)dist[i][j]=0;
            else dist[i][j]=inf;
        }
    }

    for(int i=0;i<m;i++){
        int ai=a[i], bi=b[i], ci=c[i];
        dist[ai][bi]=min(dist[ai][bi],ci);
        dist[bi][ai]=min(dist[bi][ai],ci);
    }

    for(int k=0;k<n;k++){
        for(int i=0;i<n;i++){
            for(int j=0;j<n;j++){
                dist[i][j]=min(dist[i][j],dist[i][k]+dist[k][j]);
            }
        }
    }

    int ans=m;
    for(int i=0;i<m;i++){
        bool shortest=false;
        int ai=a[i],bi=b[i],ci=c[i];
        for(int j=0;j<n;j++)
            if(dist[j][ai]+ci==dist[j][bi]) shortest=true;
        if(shortest) ans=ans-1;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3656
string = input()
q = int(input())
for i in range(q):
    command = list(input().split())
    a = int(command[1])
    b = int(command[2])
    if command[0] == "print":
        print(string[a:b + 1])
    elif command[0] == "reverse":
        tmp_str = string[a: b + 1]
        string = string[:a] + tmp_str[::-1] + string[b + 1:]
    elif command[0] == "replace":
        string = string[:a] + command[3] + string[b + 1:]



Measured memory_bytes: 5608
#include<iostream>
#include<string>
using namespace std;
int main()
{
	int N;
	cin >> N;
	if (N == 1)cout << 1 << endl;
	else if (N >= 2 && N < 4) cout<< 2 <<endl;
	else if (N >= 4 && N < 8) cout<< 4 <<endl;
	else if (N >= 8 && N < 16) cout<< 8 <<endl;
	else if (N >= 16 && N < 32) cout<< 16 <<endl;
	else if (N >= 32 && N < 64) cout<< 32 <<endl;
	else cout << 64 << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using VI = vector<int>;
using VL = vector<ll>;
template<class T> using PQ = priority_queue<T, vector<T>, greater<T>>;
#define FOR(i,a,n) for(int (i)=(a);(i)<(n);++(i))
#define eFOR(i,a,n) for(int (i)=(a);(i)<=(n);++(i))
#define rFOR(i,a,n) for(int (i)=(n)-1;(i)>=(a);--(i))
#define erFOR(i,a,n) for(int (i)=(n);(i)>=(a);--(i))
#define each(i, a) for(auto &i : a)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i,a) sort((i).begin(),(i).end(),(a))
#define all(i) (i).begin(),(i).end()
#define out(y,x) ((y) < 0 || h <= (y) || (x) < 0 || w <= (x))
#define line cout << "------------------------\n" 
#define ENDL(i,n) ((i) == (n) - 1 ? "\n" : " ")
#define stop system("pause") //comment out this on AOJ.
constexpr ll INF = 1000000000;
constexpr ll LLINF = 1LL << 60;
constexpr ll mod = 1000000007;
constexpr ll MOD = 998244353;
constexpr ld eps = 1e-10; //1e-9?
constexpr ld pi = 3.1415926535897932;
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; }
inline void init() { cin.tie(nullptr); cout.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(15); }
template<class T>inline istream& operator>>(istream& is, vector<T>& v) { for (auto& elemnt : v)is >> elemnt; return is; }
template<class T, class U>inline istream& operator>>(istream& is, pair<T, U>& p) { is >> p.first >> p.second; return is; }
template<class T>inline vector<T> vec(size_t a) { return vector<T>(a); }
template<class T>inline vector<T> defvec(T def, size_t a) { return vector<T>(a, def); }
template<class T, class... Ts>inline auto vec(size_t a, Ts... ts) { return vector<decltype(vec<T>(ts...))>(a, vec<T>(ts...)); }
template<class T, class... Ts>inline auto defvec(T def, size_t a, Ts... ts) { return vector<decltype(defvec<T>(def, ts...))>(a, defvec<T>(def, ts...)); }

int main() {
    init();

    int n, m; cin >> n >> m;
    string s; cin >> s;
    reverse(all(s));

    int now = 0;
    VI ans;
    while (now < n) {
        erFOR(to, now, min(now + m, n)) {
            if (to == now) {
                cout << "-1\n";
                return 0;
            }
            if (s[to] == '0') {
                ans.push_back(to - now);
                now = to;
                break;
            }
        }
    }
    reverse(all(ans));

    FOR(i, 0, ans.size())cout << ans[i] << ENDL(i, ans.size());
}

Measured memory_bytes: 1096
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

using namespace std;

typedef pair<long long int, long long int> P;
typedef tuple<int, int, int> T;

long long int INF = 1e18;
long long int MOD = 1e9 + 7;

long long int A[210000], B[210000];

int main(){
    int N;
    cin >> N;
    for(int i = 0; i < N; i++){
        cin >> A[i];
    }
    for(int i = 0; i < N; i++){
        cin >> B[i];
        if(B[i] < A[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    long long int ans = 0;
    queue<int> que;
    for(int i = 0; i < N; i++){
        if(B[(i - 1 + N) % N] < B[i] && B[i] > B[(i + 1) % N]){
            que.push(i);
        }
    }
    while(!que.empty()){
        int pos = que.front();
        que.pop();
        long long int S = B[(pos - 1 + N) % N] + B[(pos + 1) % N];
        ans += (B[pos] - A[pos]) / S;
        B[pos] -= (B[pos] - A[pos]) / S * S;
        if(B[(pos - 2 + N * 2) % N] < B[(pos - 1 + N) % N] && B[(pos - 1 + N) % N] > B[pos]){
            que.push((pos - 1 + N) % N);
        }
        if(B[pos] < B[(pos + 1) % N] && B[(pos + 1) % N] > B[(pos + 2) % N]){
            que.push((pos + 1) % N);
        }
    }
    for(int i = 0; i < N; i++){
        if(A[i] != B[i]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3840
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "cassert"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;
//const long long int MOD = 998244353;

//int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;


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

	cin >> N;
	long long int ll, ul, rl, dl;
	long long int lu, uu, ru, du;
	long long int lr, ur, rr, dr;
	long long int ld, ud, rd, dd;
	ll = ul = rl = dl = ld = ud = rd = dd = MOD;
	lr = ur = rr = dr = lu = uu = ru = du = -MOD;
	for (int i = 0; i < N; i++) {
		long long int a, b;
		cin >> a >> b;
		a *= 4;
		b *= 4;
		char c;
		cin >> c;
		if (c == 'L') {
			ll = min(ll, a);
			lr = max(lr, a);
			ld = min(ld, b);
			lu = max(lu, b);
		}
		if (c == 'R') {
			rl = min(rl, a);
			rr = max(rr, a);
			rd = min(rd, b);
			ru = max(ru, b);
		}
		if (c == 'D') {
			dl = min(dl, a);
			dr = max(dr, a);
			dd = min(dd, b);
			du = max(du, b);
		}
		if (c == 'U') {
			ul = min(ul, a);
			ur = max(ur, a);
			ud = min(ud, b);
			uu = max(uu, b);
		}
	}
	lu = max(lu, ru);
	ld = min(ld, rd);
	dl = min(dl, ul);
	dr = max(dr, ur);
	long long int ans = MOD * MOD;
	for (long long int i = 0; i <= 800000000; i ++) {
		long long int l, r, u, d;
		l = min({ ll - i,rl + i,dl });
		r = max({ lr - i,rr + i,dr });
		u = max({ lu,uu + i,du - i });
		d = min({ ld,ud + i,dd - i });
		ans = min(ans, (r - l)*(u - d));
	}
	long double ret = ans;
	ret /= 16;
	cout << setprecision(20) << ret << endl;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.IOException;

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

        try {
            data = br.readLine().split(" ");
            for (int i = 0; i < 4; i++)
                points[i] = Double.parseDouble(data[i]);
            double dis = Math.sqrt(Math.pow(points[3] - points[1], 2) + Math.pow(points[2] - points[0], 2));
            System.out.printf("%.4f", dis);
        } catch (IOException e) {
            e.printStackTrace();
        }
    }
}


Measured memory_bytes: 24740
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int H, W, N;
    cin >> H >> W >> N;

    int cnt[10];
    fill(cnt, cnt + 10, 0);
    cnt[0] = (H - 2) * (W - 2);

    map<P, bool> m;

    for (int i = 0; i < N; i++) {
        int a, b;
        cin >> a >> b;
        a--; b--;

        for (int i = -1; i <= 1; i++) {
            for (int j = -1; j <= 1; j++) {
                int center_i = a + i;
                int center_j = b + j;
                if (center_i <= 0 || center_i >= H - 1 || center_j <= 0 || center_j >= W - 1) continue;

                int black_cnt = 0;
                for (int p = -1; p <= 1; p++) {
                    for (int q = -1; q <= 1; q++) {
                        if (m.find(make_pair(center_i + p, center_j + q)) != m.end()) black_cnt++;
                    }
                }

                cnt[black_cnt]--;
                cnt[black_cnt+1]++;
            }
        }

        m[make_pair(a, b)] = true;
    }

    for (int i = 0; i < 10; i++) cout << cnt[i] << endl;

    return 0;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

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

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

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

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

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

const int N = 5000+5;
const ll inf = 1e14;

int n;
int h[N];
int p[N];
ll memo[N][N];

int main(){
	ri(n);
	for(int i = 1; i <= n; i++) ri2(h[i], p[i]);
	vector<int> a(n);
	iota(all(a), 1);
	sort(all(a), [&] (int i, int j){
		return h[i] + p[i] < h[j] + p[j];
	});
	memo[0][0] = 0;
	for(int i = 1; i <= n; i++) memo[0][i] = inf;
	for(int i = 1; i <= n; i++){
		int pos = a[i - 1];
		for(int j = 1; j <= n; j++){
			memo[i][j] = memo[i - 1][j];
			if(memo[i - 1][j - 1] <= h[pos]){
				memo[i][j] = min(memo[i][j], memo[i - 1][j - 1] + p[pos]);
			}
		}
	}
	int ans = 0;
	for(int i = 0; i <= n; i++){
		if(memo[n][i] < inf){
			ans = i;
		}
	}
	printf("%d\n", ans);
	return 0;
}


Measured memory_bytes: 199356
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <ctime>
#include <cstring>
#define ll long long
#define INF 1000000000
#define For(i,a,b) for(int i=a;i<=b;++i)
#define Rev(i,a,b) for(int i=a;i>=b;--i)
#define pb push_back
#define pq priority_queue
#define PI acos(-1)

namespace IO
{
#define p(x) ('0'<=x&&x<='9')
	char cc; int C;
	template <class T>
	void read( T &x )
	{
		x=0; cc=getchar(); C=1;
		while(!p(cc)) { if(cc=='-') C=-1; cc=getchar(); }
		while(p(cc)) { x=x*10+cc-48; cc=getchar(); }
		x*=C;
	}
#undef p
}

using namespace IO;
using namespace std;

#define N 100005

#define lb(x) (x&-x)
int a[N],b[N],c[N],n;
ll Arr[N<<1],Arr_minor[N<<1],tot,tot_minor,tot_zero;

ll sigema(int pos)
{
	ll ret=0;
	while(pos)
	{
		ret+=Arr[pos];
		pos-=lb(pos);
	}
	return ret;
}

void add(int pos)
{
	++tot;
	while(pos<=N) ++Arr[pos],pos+=lb(pos);
}

ll sigema_minor(int pos)
{
	ll ret=0;
	while(pos)
	{
		ret+=Arr_minor[pos];
		pos-=lb(pos);
	}
	return ret;
}

void add_minor(int pos)
{
	++tot_minor;
	while(pos<=N) ++Arr_minor[pos],pos+=lb(pos);
}

#undef lb

void init()
{
	read(n);
	For(i,1,n) read(a[i]),b[i]=a[i];
	sort(b+1,b+1+n);
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	srand(time(0));
#ifdef LOCAL
	freopen("./tmp/input.txt", "r", stdin);
#endif
	init();
	int L=1,R=n,mid,pre,ans;
	ll sum;
	const ll total=1LL*n*(n+1)/2;
	const ll target=(total/2)+1;
	while(L<R)
	{
		mid=(L+R)>>1;

		memset(Arr,0,sizeof(Arr)); tot=0;
		memset(Arr_minor,0,sizeof(Arr)); tot_minor=0;
		tot_zero=0;

		For(i,1,n) c[i]=(a[i]<=b[mid]?1:-1);
		sum=pre=0;
		++tot_zero;
		For(i,1,n)
		{
			pre+=c[i];
			if(pre<0)
			{
				sum+=tot_minor;
				sum-=sigema_minor(-pre);
				add_minor(-pre);
				continue;
			}
			if(pre==0)
			{
				sum+=tot_minor;
				++tot_zero;
				continue;
			}
			if(pre>0)
			{
				sum+=tot_minor+tot_zero;
				sum+=sigema(pre-1);
				add(pre);
				continue;
			}
		}
		if(sum>=target) R=mid;
		else L=mid+1;
	}

	printf("%d\n",b[L]);

	return 0;
}
//resubmition


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

import sys


def main():
    WINNING_HANDS = [
                '111', '222', '333', '444', '555', '666', '777', '888', '999',
                '123', '234', '345', '456', '567', '678', '789'
            ]

    num_of_datasets = int(sys.stdin.readline().strip('\n'))
    datasets = [{'R': [], 'G': [], 'B': []} for _ in range(num_of_datasets)]
    results = list()

    for dataset in range(num_of_datasets):
        n_set = [num for num in sys.stdin.readline().strip('\n').split()]
        c_set = [colour for colour in sys.stdin.readline().strip('\n').split()]
        for idx, colour in enumerate(c_set):
            if colour == 'R':
                datasets[dataset]['R'].append(n_set[idx])
            elif colour == 'G':
                datasets[dataset]['G'].append(n_set[idx])
            elif colour == 'B':
                datasets[dataset]['B'].append(n_set[idx])

        match_count = int()

        for rgb_key in datasets[dataset]:
            if len(datasets[dataset][rgb_key]) > 1:
                nums = sorted(datasets[dataset][rgb_key])
            else:
                continue

            for hand in WINNING_HANDS:
                while hand[0] in nums and hand[1] in nums and hand[2] in nums:
                    tmp = nums.copy()
                    if hand[0] in tmp:
                        tmp.pop(tmp.index(hand[0]))
                        if hand[1] in tmp:
                            tmp.pop(tmp.index(hand[1]))
                            if hand[2] in tmp:
                                tmp.pop(tmp.index(hand[2]))
                                match_count += 1
                                nums = tmp
                            else:
                                break
                        else:
                            break
                    else:
                        break

                    if match_count == 3:
                        results.append(1)
                        break

        if dataset < num_of_datasets and match_count != 3:
            results.append(0)

    for result in results:
        print(result)


if __name__ == '__main__':
    main()

Measured memory_bytes: 7688
#include <vector>
#include <list>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <utility>
#include <functional>
#include <sstream>
#include <iostream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <climits>
#include <cassert>
using namespace std;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define EXIST(s, e) ((s).find(e)!=(s).end())
#define FOR(i,a,b) for(int i=(a); i<(b); ++i)
#define REP(i,n) FOR(i, 0, n)

const int INF = INT_MAX/10;

struct state {
    int p, t;
	state(int p, int t) : p(p), t(t) {};
    bool operator< (const state &o)const {
        return t>o.t;
	}
};

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

    vi field(N);
    REP(i, N) {
        cin >> field[i];
	}

    vi turn(N, INF);
    priority_queue<state> Q;

    FOR(i, 1, min(N, 6)+1) {
        Q.push(state(i, 1));
        turn[i] = 1;
	}
    Q.push(state(0, 0));
    turn[0] = 0;

	while(!Q.empty()) {
		state st = Q.top();
		Q.pop();

        if(st.p == N-1) {
            cout << st.t << endl;
            return 0;
		}

        if(field[st.p] != 0) {
            int np = st.p + field[st.p];
            if(np >= N) {
                np = N-1;
			}
            if(turn[np] > st.t) {
                turn[np] = st.t;
                Q.push(state(np, st.t));
			}
		} else {
            FOR(d, 1, 6+1) {
                int np = st.p + d;
                if(np >= N) {
                    np = N-1;
				}
                if(turn[np] > st.t+1) {
                    turn[np] = st.t+1;
                    Q.push(state(np, st.t+1));
				}
			}
		}
	}
}

Measured memory_bytes: 1796
#include<iostream>
using namespace std;
int main() {
	int N;
	cin >> N;
	int sum = 0;
	int M = N;
	while (N > 0) {
		sum += N % 10;
		N /= 10;
	}
	if (M%sum == 0) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
	return 0;
}

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

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

  int n;
  cin >> n;
  int a0 = 0;
  int a1 = 0;
  int a2 = 0;
  int a3 = 0;
  int b;
  rep(i, n) {
    cin >> b;
    if (b%4 == 0) a0++;
    if (b%4 == 1) a1++;
    if (b%4 == 2) a2++;
    if (b%4 == 3) a3++;
  }

  if (a2 >= 2) {
    if (n-a2 <= a0*2) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  } else {
    if (n <= a0*2+1) {
      cout << "Yes" << endl;
    } else {
      cout << "No" << endl;
    }
  }
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
using namespace std;
ll n , m , cnt;
string s;
int main(){
    cin >> n >> m >> cnt;
    if( n % m == 0 )
        cout << n / m * cnt << endl;
    else
        cout << (n / m + 1) *cnt << endl;
}


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

int main() {
  int N, M;
  cin >> N >> M;
  vector<int> A(N);
  for (int i = 0; i < N; i++) cin >> A.at(i);
  vector<pair<int, int>> P(M);
  for (int i = 0; i < M; i++) {
    int B, C;
    cin >> B >> C;
    P.at(i) = make_pair(C, B);
  }
  
  sort(A.begin(), A.end());
  sort(P.begin(), P.end());
  reverse(P.begin(), P.end());
  
  int k = 0;
  for (int i = 0; i < N; i++) {
    if (A.at(i) < P.at(k).first) {
      A.at(i) = P.at(k).first;
      P.at(k).second--;
      if (P.at(k).second == 0) {
        k++;
        if (k >= M) break;
      }
    }
  }
  
  long long int ans = 0;
  for (int i = 0; i < N; i++) ans += A.at(i);
  cout << ans << endl;
}

Measured memory_bytes: 1536
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <cmath>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <iostream>
#include <random>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include <fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;

using ll = long long;
using vll = vector<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using vb = vector<bool>;
using mll = map<ll, ll>;
using sll = stack<ll>;
#define REP(i,n) for(ll i(0);(i)<(n);(i)++)
#define rep(i,n) for(ll i(0);(i)<(n);(i)++)
#define ALL(a) a.begin(), a.end()
#define elnd endl //* missspell check
const ll INF = 1LL << 60;


int main(){
    ll N, A, B; cin >>N>> A>> B;
    ll k = N / (A+B), r = N % (A+B);
    ll ans = k*A + min(r, A);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;
int INF = 1000000009;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << max(c - (a - b), 0) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          163577857
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -1e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

 typedef tree<pii, null_type, less<pii>, rb_tree_tag,  
            tree_order_statistics_node_update>  odst; 


void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
   
    #endif
}



void solve()
{
 // int n;
 // cin >> n ;
 // int a[n+1];

 // forf(i,1,n+1) cin >> a[i];

 // map<int,int>mp;
 
 // int an =0;
 // for(int i=1;i<=n;i++)
 // {
 //   an += mp[i-a[i]];
 //   mp[a[i]+i]++;
 // }

 // cout<<an<<endl;
 
int n,k;
cin>> n >> k;

int vis[n+1];
for(int i=1;i<=n;i++)
vis[i]=0;

for(int j=0;j<k;j++)
{
  int ss;
  cin >> ss;

  forf(k,0,ss)
  {
    int el;
    cin >> el;
    vis[el]=1;
  }
}

int an=0;

for(int i=1;i<=n;i++)
if(vis[i]==0) an++;
cout<<an<<endl;



}

int32_t main()
{
  pr_init();
  fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
  
    // cout << "Time taken by function: "
    //      << duration.count() << " microseconds" << endl; 

 }

Measured memory_bytes: 3548
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define stop exit(0)
#define dd double
#define po pop_back
#define pb push_back
#define ub upper_bound
#define lb lower_bound
int main(){
    vector <long long> v;
    ll a,b,c,d=0,e=0,f=0,g=0,i,j,k=1,l=1,r=1,n,m[300001],z[400001],h[600001],p[600001];
    string s,t,x[1001],y[1001];
    dd q,u,w;
    cin>>a;
    for(i=1;i<=a;i++){
        if(i%5>0&&i%3>0){
            d+=i;
        }
    }
    cout<<d;
}

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

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

int main(){
    int  N;
    cin>>N;
    if(N%2==0) cout<<N/2<<endl;
    else cout<<N/2 +1<<endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep(i,n) for(ll i=0;i<(n);i++)
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))

using namespace std;

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;}

const ll INF=1e18;

int main(){
    ll h,w;
    cin >> h >> w;
    ll dx[4]={-1,1,0,0};
    ll dy[4]={0,0,-1,1};
    vector<vector<char>> s(h,vector<char>(w));
    rep(i,h){
        rep(j,w){
            cin >> s[i][j];
        }
    }
    bool ans=true;
    rep(i,h){
        rep(j,w){
            if(s[i][j]=='#'){
                bool ok=false;
                rep(k,4){
                    ll nx=i+dx[k];
                    ll ny=j+dy[k];
                    if(0<=nx && nx<=h-1 && 0<=ny && ny<=w-1 && s[nx][ny]=='#'){
                        ok=true;
                        break;
                    }
                }
                if(!ok){
                    ans=false;
                }
            }
        }
    }
    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
} 

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

int main() {
  int n, d;
  cin >> n >> d;
  int a = 2 * d + 1;
  int ans = (n + a - 1) / a;
  cout << ans << endl;
  return 0;
}

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

const int INF = 1e+9+7;

struct UnionFind
{
  // par[i]：データiが属する木の親の番号。i == par[i]のとき、データiは木の根ノードである
  vector<int> par;
  // sizes[i]：根ノードiの木に含まれるデータの数。iが根ノードでない場合は無意味な値となる
  vector<int> sizes;

  UnionFind(int n) : par(n), sizes(n, 1) {
    // 最初は全てのデータiがグループiに存在するものとして初期化
    rep(i,n) par[i] = i;
  }

  // データxが属する木の根を得る
  int find(int x) {
    if (x == par[x]) return x;
    return par[x] = find(par[x]);  // 根を張り替えながら再帰的に根ノードを探す
  }

  // 2つのデータx, yが属する木をマージする
  void unite(int x, int y) {
    // データの根ノードを得る
    x = find(x);
    y = find(y);

    // 既に同じ木に属しているならマージしない
    if (x == y) return;

    // xの木がyの木より大きくなるようにする
    if (sizes[x] < sizes[y]) swap(x, y);

    // xがyの親になるように連結する
    par[y] = x;
    sizes[x] += sizes[y];
    // sizes[y] = 0;  // sizes[y]は無意味な値となるので0を入れておいてもよい
  }

  // 2つのデータx, yが属する木が同じならtrueを返す
  bool same(int x, int y) {
    return find(x) == find(y);
  }

  // データxが含まれる木の大きさを返す
  int size(int x) {
    return sizes[find(x)];
  }
};

int main(){
    int N;
    cin >> N;
    vector<pair<int,int>> X(N);
    vector<pair<int,int>> Y(N);

    int x,y;
    rep(i,N){
        cin >> x >> y;
        X[i] = {x,i};
        Y[i] = {y,i};
    }

    sort(X.begin(),X.end());
    sort(Y.begin(),Y.end());

    vector<tuple<int,int,int>> d(2*(N-1));

    rep(i,N-1){
        // d[i]={X[i+1].first-X[i].first,X[i].second,X[i+1].second};
        // d[i+N-1]={Y[i+1].first-Y[i].first,Y[i].second,Y[i+1].second};
        get<0>(d[i])=X[i+1].first-X[i].first;
        get<1>(d[i])=X[i].second;
        get<2>(d[i])=X[i+1].second;
        get<0>(d[i+N-1])=Y[i+1].first-Y[i].first;
        get<1>(d[i+N-1])=Y[i].second;
        get<2>(d[i+N-1])=Y[i+1].second;
        
    }

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

    vector<bool> v(N,false);
    int dist,a,b;
    ll ans=0;

    UnionFind uf(N);

    rep(i,2*(N-1)){
        dist=get<0>(d[i]);
        a=get<1>(d[i]);
        b=get<2>(d[i]);
        if(!uf.same(a,b)){
            uf.unite(a,b);
            ans+=dist;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<cstring>
#include<set>
#include<map>
using namespace std;

int main(){
    int n,ans=0,sum=0,d;
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%d",&d);
        ans+=sum*d;
        sum+=d;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 888
L = []
import math
while True:
    n = int(input())
    if n == 0:
        break
    l = list(map(int,input().split()))
    m = sum(l)/n
    var = 0
    for i in l:
        var += (i-m)*(i-m)
    L.append(math.sqrt(var/n))
for j in L:
    print('{:.5f}'.format(j))


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

using namespace std;
#define DBG(x)                         \
    (void)(cout << "L" << __LINE__     \
                << ": " << #x << " = " \
                << (x) << '\n')
#define Lower_bound(v, x) distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) distance(v.begin(), upper_bound(v.begin(), v.end(), x))
typedef long long ll;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const long double PI = (acos(-1));
const long double EPS = 0.0000000001;
const int INF = 0x3f3f3f3f;
const int maxn = 1100000;

void run_case()
{
    int n;
    cin >> n;
    int cnt = 0;
    bool ok = 0;
    for (int i = 1; i <= n; i++)
    {
        int x, y;
        cin >> x >> y;
        if (x == y)
        {
            cnt++;
        }
        else
        {
            cnt = 0;
        }
        if (cnt >= 3)
        {
            ok = 1;
        }
    }
    if (ok)
    {
        cout << "Yes\n";
    }
    else
        cout << "No\n";
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setiosflags(ios::fixed) << setprecision(12);
    run_case();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3644