akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
public class Main {
    static Scanner sc = new Scanner(System.in);
    static int d, n, m;
    static int[] shop, dist;
    public static void main(String[] args) {
        while(read()){
            solve();
        }
    }

    static boolean read(){
        d = sc.nextInt();
        if(d == 0) return false;
        n = sc.nextInt();
        m = sc.nextInt();

        shop = new int[n+1];
        dist = new int[m+1];
        //System.out.println("shop.length = " + shop.length);
        for(int i = 1; i < shop.length-1; i++){
            shop[i] = sc.nextInt();
            //System.out.println("shop["+i+"] = " + shop[i]);
        }
        shop[0] = 0;
        shop[shop.length-1] = d;
        for(int j = 1; j < dist.length; j++){
            dist[j] = sc.nextInt();
            //System.out.println("dist[" + j + "] = " + dist[j]);
        }

        return true;
    }

    static void solve(){
        int res = 0;
        Arrays.sort(shop);
        Arrays.sort(dist);
        for(int i = 1; i < dist.length; i++){
            int index = -1;
            int point = Arrays.binarySearch(shop, dist[i]);
            if(point < 0){
                point = Math.abs(point)-1;
                res += Math.min(Math.abs(shop[point] - dist[i]), Math.abs(shop[point-1] - dist[i]));
            }
            //System.out.println("point = " + point);
        }
        System.out.println(res);
    }
    /*
    static void solve(){
        int res = 0;

        for(int i = 1; i <= m; i++){
            int cost = Integer.MAX_VALUE;
            for(int j = 0; j < n; j++){
                int to = Math.abs(dist[i] - shop[j]);
                cost = Math.min(cost, Math.min(to, d - to));
            }
            res += cost;
        }
        System.out.println(res);
    }
    */
}

Measured memory_bytes: 13000
/*
Author: Arham_doshi
@quote "Code like there's no tommorow!"
 ***************************************   UNAUTHORISED COPYING OF CODE PROHIBITED   **********************************
*/
#include <bits/stdc++.h>

#define int         long long
#define double      long double
#define pb          push_back
#define pf          push_front
#define pii         pair<int,int>
#define vi          vector<int>
#define vii         vector<pii>
#define mi          map<int,int>
#define mii         map<pii,int>
#define piii           pair<int,pair<int,int> >
#define all(a)      (a).begin(),(a).end()
#define rall(a)     (a).rbegin(),(a).rend()
#define x           first
#define y           second
#define sz(x)       (int)x.size()
#define endl        '\n'
#define hell        998244353 
#define PI          3.141592653589
#define bs(v,n)     binary_search(all((v)),(n))
#define lb(v,n)     lower_bound(all((v)),(n))
#define ub(v,n)     upper_bound(all((v)),(n))
#define fo(i,l,u)   for(i=l;i<u;i++)
#define rfo(i,l,u)  for(i=l;i>=u;i--)
#define allfo(s)    for(auto it=(s).begin();it!=(s).end();it++)
#define _init(b)     memset(b,-1,sizeof(b))
#define _init0(b)     memset(b,0,sizeof(b))
#define MOD         1000000007
#define ef else if



using namespace std;

int gcd(int a, int b) {  if (a == 0)  return b; return gcd(b % a, a); }  
bool mod(double a,double b) {return a/b - floor(a/b);}

int occurs(vi v,int n){
auto it=lb(v,n);auto it1=ub(v,n);int x=it1-it;return x;}

int logb(int base, int x) {
    return (log(x) / log(base));
}

int pow2(int x){return x*x;}
double dis(pii p1,pii p2){
    return sqrt((pow2(p1.x-p2.x)+pow2(p1.y-p2.y)));
}

signed main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int i,j,x,n;
cin>>n;
    double t=0;
    vii v;
    fo(i,0,n){
        int a,b;
        cin>>a>>b;
        v.pb({a,b});
    }
    
    fo(i,0,n){
        fo(j,0,n){
            t+=dis(v[i],v[j]);
        }
    }
    cout<<setprecision(10)<<t/n;
    
    
    return 0;
}

Measured memory_bytes: 256
n,m = map(int,input().split())
h = list(map(int,input().split()))
warui = []
for i in range(m):
    a,b = map(int,input().split())
    if h[a-1] > h[b-1]:
        warui.append(b)
    elif h[a-1] < h[b-1]:
        warui.append(a)
    else:
        warui.append(a)
        warui.append(b)
warui = set(warui)
print(n - len(warui))

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

#define pb(n) push_back(n)
#define fi first
#define se second
#define all(r) begin(r),end(r)
#define vmax(ary) *max_element(all(ary))
#define vmin(ary) *min_element(all(ary))
#define debug(x) cout<<#x<<": "<<x<<endl
#define fcout(n) cout<<fixed<<setprecision((n))
#define scout(n) cout<<setw(n)
#define vary(type,name,size,init) vector< type> name(size,init)
#define vvl(v,w,h,init) vector<vector<ll>> v(w,vector<ll>(h,init))
#define mp(a,b) make_pair(a,b)

#define rep(i,n) for(int i = 0; i < (int)(n);++i)
#define REP(i,a,b) for(int i = (a);i < (int)(b);++i)
#define repi(it,array) for(auto it = array.begin(),end = array.end(); it != end;++it)
#define repa(n,array) for(auto &n :(array))

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

template<typename T>
void O(T t){
  cout << t << endl;
}

  const double EPS = 1e-10;
  const double INF = 1e12;
  typedef complex<double> P;//????´???°????????¢?????????????????¨?§£???
  namespace std {
    bool operator < (const P& a, const P& b) {//x????????????
      return real(a) != real(b) ? real(a) < real(b) : imag(a) < imag(b);
    }
    bool sorty(const P& a, const P& b) {//y????????????
      return imag(a) != imag(b) ? imag(a) < imag(b) : real(a) < real(b);
    }
  }
  double cross(const P& a, const P& b) {//??????
    return imag(conj(a)*b);
  }
  double dot(const P& a, const P& b) {//??????
    return real(conj(a)*b);
  }
  struct L : public vector<P> {//??´???
    L(){};
    L(const P &a, const P &b) {
      push_back(a); push_back(b);
    }
  };

  typedef vector<P> G;

  struct C {//???
    P p; double r;
    C(){};
    C(const P &p, double r) : p(p), r(r) { }
  };
  P crosspoint(const L &l, const L &m) {
    double A = cross(l[1] - l[0], m[1] - m[0]);
    double B = cross(l[1] - l[0], l[1] - m[0]);
    if (abs(A) < EPS && abs(B) < EPS) return m[0]; // same line
    if (abs(A) < EPS) assert(false); // !!!PRECONDITION NOT SATISFIED!!!
    return m[0] + B / A * (m[1] - m[0]);
  }

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  ll q;
  cin >> q;
  double x,y;
  rep(i,q){
    cin >> x >> y;
    P a(x,y);
    cin >> x >> y;
    P b(x,y);
    cin >> x >> y;
    P c(x,y);
    cin >> x >> y;
    P d(x,y);
    L ab(a,b),cd(c,d);
    P p = crosspoint(ab,cd);
    fcout(10) << real(p) << ' ' << imag(p) << endl;
  }
  return 0;
}

Measured memory_bytes: 3248
N = int(input())
S = list(input())
r = 0
g = 0
b = 0

for i in range(N):
    if S[i] == 'R':
        r += 1
    elif S[i] == 'G':
        g += 1
    else:
        b += 1

allcnt = r * g * b

sub = 0
for i in range(N):
    for j in range(i+1,N):
        if S[i] == S[j]:
            None
        else:
            k = 2*j-i
            if k >= N or S[i] == S[k] or S[j] == S[k]:
                None
            else:
                sub += 1

print(allcnt - sub)

Measured memory_bytes: 9136
import java.util.*;
import java.text.*;


public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int counter = 0;
		// # of friends
		int a = sc.nextInt();
		// min height
		int b = sc.nextInt();


		for(int i = 1; i <= a ; i++)
		{
			// height in cm.
			int c = sc.nextInt();
				if(c >= b)
				{
					counter++;

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

Measured memory_bytes: 46440
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <cassert>
#include <memory>
#include <stack>
#include <set>
#include <map>

#define MAX_SIZE 100000000
typedef long long ll;
typedef unsigned long long ull;
using namespace std;

int main() {
  int n; cin>>n;
  vector<ll> vec;
  ll ans = 1;
  for(ll i = 0; i < 10000000001; i++) {
    ll sq = i * i;
    vec.push_back(sq);
    if(sq > n) {
      ans = vec[i - 1];
      break;
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 640
#include "bits/stdc++.h"
using namespace std;

int main(){
	int n,d,x;
	cin>>n>>d>>x;
	int ans=x+n;
	d--;
	for(int i=0;i<n;i++){
		int a;
		cin>>a;
		ans+=d/a;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

const ll INF = 1000000000000001;

int main() {
    ll n;
    cin >> n;
    n--;
    ll keta = 1;
    ll mul26[13];
    mul26[0] = 1;
    srep(i,1,13)mul26[i] = mul26[i-1] * 26;
    while(true){
        if(n >= mul26[keta]){
            n -= mul26[keta];
            keta++;
        }else{
            break;
        }
    }

    char c[keta];
    rep(i,keta){
        c[i] = 'a';
        while(n >= mul26[keta-1-i]){
            c[i]++;
            n -= mul26[keta-1-i];
        }
    }

    rep(i,keta)cout << c[i];
    cout << endl;
    return 0;
}




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

int main()
{
  int n = 0;
  string s;
  vector<char> a(10);

  cin >> s;
  for (int i = 0; i < s.size(); i++)
  {
    if (s[i] == 'B')
    {
      if (n != 0)
        n--;
    }
    else
    {
      a[n] = s[i];
      n++;
    }
  }
  for (int i = 0; i < n; i++)
    cout << a[i];
  cout << endl;
}

Measured memory_bytes: 256
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math

H,W = map(int,input().split())

# a = [[0 for i in range(W)] for j in range(H)]
a = []
for i in range(H):
    a.append([int(j) for j in input().split()])


ans = []
# print(a)
for hi in range(H):
    for wi in range(W):
        if a[hi][wi] % 2 == 1 and wi < W-1:
            #move
            ans.append([hi,wi,hi,wi+1])
            a[hi][wi] -= 1
            a[hi][wi+1] += 1

for hi in range(H):
    if a[hi][-1]%2 == 1 and hi < H-1:
        ans.append([hi,W-1,hi+1,W-1])
        a[hi][-1] -= 1
        a[hi+1][-1] += 1

print(len(ans))
for i in range(len(ans)):
    x,y,dx,dy = ans[i]
    print(x+1,y+1,dx+1,dy+1)

# print(a)


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

namespace AtCoder.Abc
{
    class A_164_SheepandWolves
    {
        public static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
            Console.SetOut(sw);

            // 整数配列の入力
            var inputLongArray = Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
            string result = "";
            if (inputLongArray[0] <= inputLongArray[1])
            {
                result = "unsafe";
            }
            else
            {
                result = "safe";
            }

            Console.WriteLine(result);

            Console.Out.Flush();
        }
    }
}


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

#define YES(condition) if(condition) cout << "YES" << endl; else cout << "NO" << endl
#define Yes(condition) if(condition) cout << "Yes" << endl; else cout << "No" << endl
#define POSS(condition) if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl
#define Poss(condition) if(condition)cout << "Possible" << endl; else cout << "Impossible" << endl
#define First(condition) if(condition)cout << "First" << endl; else cout << "Second" << endl
#define negative(condition, num) if(condition)cout << -1 << endl; else cout << num << endl
long power(long base, long exponent, long mod){ if(exponent % 2){ return power(base, exponent - 1, mod) * base % mod; }else if(exponent){ long root_ans = power(base, exponent / 2, mod); return root_ans * root_ans % mod; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}};
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
long gcd(long a, long b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }}
#define division long(1e9 + 7)

int main(){
    int N;
    cin >> N;
    vector<bool> is_in_this(8, false);
    int free_color = 0;
    for(int i = 0; i < N; i++){
        int rate;
        cin >> rate;
        bool is_free_color = true;
        for(int j = 0; j < 8; j++){
            if(rate <= j * 400 + 399){
                is_in_this[j] = true;
                is_free_color = false;
                break;
            }
        }
        free_color += is_free_color;
    }
    int is_in_this_sum = 0;
    for(int i = 0; i < 8; i++){
        is_in_this_sum += is_in_this[i];
    }
    cout << max(1, is_in_this_sum) << " " << is_in_this_sum + free_color << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main()
{
	int a,b,g;
	char g2[100];
	while(scanf("%d %d",&a,&b)!=EOF){
	sprintf(g2,"%d",a+b);
	printf("%d\n",strlen(g2));
}
	return 0;
}

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

int main() {
  int a,b,c,d;
  
  cin >> a >> b >> c >> d;
  
  if((a+b) < (c+d)){
    cout << "Right" << endl;
  }
  else if((a+b) == (c+d)){
    cout << "Balanced" << endl;
  }
  else{
    cout << "Left" << endl;
  }
}



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

int main() {
    // A: 1; B: 0; C:-1; K: num to pick
    int a, b, c, k;
    cin >> a >> b >> c >> k;

    int total{0};
    // when a <= k
    if (a <= k) {
        total += 1 * a;
        k -= a;
        // have to pick c
        if (b < k) {
            total += -1 * (k - b);
        }
    } else {
        total = 1 * k;
    }

    cout << total << endl;

    return 0;
}

Measured memory_bytes: 3640
#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(){
  string st;
  ll k;
  cin >> st;
  ll suu = 0;
  for(int i=0; i<st.size(); i++){
    if(st.at(i) != '1') break;
    suu++;
  }
  cin >> k;
  if(k <= suu){
    cout << 1 << endl;
  }else{
    cout << st.at(suu) << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int a[200005];
int main()
{
    int n;
    cin>>n;
    for(int i=0;i<n;i++)
    {
        cin>>a[i];
    }
    int maxv=-2134131000;
    int minv=a[0];
    for(int i=1;i<n;i++)
    {
        maxv=max(maxv,a[i]-minv);
        minv=min(minv,a[i]);
    }
    cout<<maxv<<endl;
    return 0;
}


Measured memory_bytes: 3856
#include<iostream>
#include<vector>
#include<cstring>
 
using namespace std;
 
long long memo[60][1000];
 
vector<int> X;
 
long long solve(int i, long long j) {
	if (memo[i][j] != -1) return memo[i][j]; 
	if (i == X.size()) return (j == 0);
	return memo[i][j] = (solve(i+1, j)+solve(i + 1, j + X[i]));
}
 
int main() {
	int n, a;
	cin >> n >> a;
	X.resize(n);
	for (int i = 0; i < n; i++)cin >> X[i];
	for (auto &v : X)v -= a;
	memset(*memo, -1, sizeof(memo));
	cout << solve(0,0)-1 << endl;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define forn(i,n) for(int i=0;i<int(n);i++)
#define rforn(i,n) for(int i = int(n) - 1; i >= 0; --i)

using namespace std;
typedef long long ll;

int N;
int even_counts[100100];
int odd_counts[100100];


int populate_sorted(vector<pair<int, int>> &v, int *counts) {
    for (int i = 1; i <= 100000; ++i) {
        if (counts[i]) {
            v.push_back(make_pair(counts[i], i));
        }
    }
    sort(v.begin(), v.end());
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    cin >> N;
    forn(i, N) {
        int temp; cin >> temp;
        if (i & 1) {
            odd_counts[temp]++;
        }
        else {
            even_counts[temp]++;
        }
    }
    vector<pair<int, int>> odd_count;
    vector<pair<int, int>> even_count;
    populate_sorted(odd_count, odd_counts);
    populate_sorted(even_count, even_counts);
    auto oidx = odd_count.size() - 1;
    auto eidx = even_count.size() - 1;
    auto target = N >> 1;
    auto ans = 0;

    if (even_count[eidx].second != odd_count[oidx].second) {
        ans = (target - even_count[eidx].first) + (target - odd_count[oidx].first);
    }
    else {
        auto e1 = even_count[eidx].first;
        auto e2 = eidx > 0 ? even_count[eidx - 1].first : 0;

        auto o1 = odd_count[oidx].first;
        auto o2 = oidx > 0 ? odd_count[oidx - 1].first : 0;

        ans = min((target - e1) + (target - o2), (target - e2) + (target - o1));
    }

    cout << ans << '\n';
}

Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
int f[100000],dp[100000],n,k;
int main(){
    cin>>n>>k;
    memset(dp,0x3f,sizeof(dp));
    for(int i=0;i<n;i++)
        scanf("%d",&f[i]);
    dp[0]=0;
    for(int i=1;i<k;i++){
        for(int j=i;j>=0;j--){
            dp[i]=min(dp[i],dp[i-j]+abs(f[i]-f[i-j]));
        }
    }
    for(int i=k;i<n;i++){
        for(int j=1;j<=k;j++){
            dp[i]=min(dp[i],dp[i-j]+abs(f[i]-f[i-j]));
        }
    }
    cout<<dp[n-1]<<endl;
    return 0;
}

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

int main(){
    ll n,a,b,c;
    string in;
    cin >> n >> a >> b >> c;
    vector<string> res;
    vector<int> var = {a,b,c};
    vector<pair<string,int>> choices;
    bool solvable = true;
    for(int i=0;i<n;i++) {
        cin >> in;
        if(!choices.empty() && in == choices.back().first) {
            choices.back().second += 1;
        } else {
            choices.push_back(make_pair(in, 1));
        }
    }
    for(int j=0;j<choices.size();j++) {
        auto p = choices[j];
        string choice = p.first;
        int times = p.second;
        int first = choice[0] - 'A';
        int second = choice[1] - 'A';
        for(int i=0;i<times;i++) {
            bool takefirst = true;
            if(var[first] > var[second]) {
                var[second]++;
                if(--var[first] < 0) solvable = false;
                takefirst = false;
            } else if(var[second] > var[first]){
                var[first]++;
                if(--var[second] < 0) solvable = false;
            } else {
                // same, look at next choice
                if(j == choices.size()-1) {
                    var[second]++;
                    if(--var[first] < 0) solvable = false;
                    takefirst = false;
                } else {
                    auto p2 = choices[j+1].first;
                    int f1 = p2[0] -'A';
                    int f2 = p2[1] - 'A';
                    if(first == f1 || first == f2) {
                        var[first]++;
                        if(--var[second] < 0) solvable = false;
                    } else {
                        var[second]++;
                        if(--var[first] < 0) solvable = false;
                        takefirst = false;
                    }
                }

            }
            res.push_back(string(1,(takefirst ? choice[0] : choice[1])));
        }
    }
    if(solvable) {cout << "Yes" << endl;
    for(auto& s : res) cout << s << endl;
    }
    else cout << "No" << endl;
}


Measured memory_bytes: 13232
sx, sy, tx, ty = map(int, input().split())
x = tx-sx
y = ty-sy
first = "U"*y+"R"*x+"D"*y+"L"*x
second = "L"+"U"*(y+1)+"R"*(x+1)+"D"+"R"+"D"*(y+1)+"L"*(x+1)+"U"
print(first+second)

Measured memory_bytes: 3060
import sys
import math
import itertools
import collections
import heapq
import re
import numpy as np

rr = lambda: sys.stdin.readline().rstrip()
rs = lambda: sys.stdin.readline().split()
ri = lambda: int(sys.stdin.readline())
rm = lambda: map(int, sys.stdin.readline().split())
rl = lambda: list(map(int, sys.stdin.readline().split()))
inf = float('inf')
mod = 10**9 + 7

n, m = rm()
li = [0]*m
for _ in range(n):
  for i in rl()[1:]:
    li[i-1]+=1
print(sum([i==n for i in li]))

Measured memory_bytes: 26888
a = ['+', '-']
b = [lambda x,y: x+y, lambda x,y: x-y]

A, B, C, D = map(int, input())

end = False
for q, w in zip(a, b):
    for t, y in zip(a, b):
        for o, p in zip(a, b):
            if p(y(w(A,B), C), D) == 7:
                print('{0}{1}{2}{3}{4}{5}{6}=7'.format(A,q,B,t,C,o,D))
                exit()


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}

int main()
{
    int N, K;
    cin >> N >> K;
    vint A(N), S(N + 1);
    map<int,int> cnt; 
    for (int i = 0; i < N; i++)
    {
        cin >> A[i];
        S[i + 1] = (S[i] + A[i]) % K;
    }
    ll ans = 0;
    for (int i = 0; i < N+1; i++)
    {
        if(i>=K)
        {
            cnt[((S[i-K]-(i-K))%K+K)%K]--;
        }
        ans += cnt[((S[i]-i)%K+K)%K];
        cnt[((S[i]-i)%K+K)%K]++;
    }
    
    cout<<ans;
    return 0;
}

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

using namespace std;

using ll = long long;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n = 5;
    vector<int> v(n);
    for (int i = 0; i < n; i++) cin >> v[i];
    sort(v.begin(), v.end());

    int ans = 1e9;
    do {
        int t = 0;
        for (int i = 0; i < n; i++) {
            t += v[i];
            if (i + 1 < n) t = (t + 9) / 10 * 10;
        }
        ans = min(ans, t);
    } while (next_permutation(v.begin(), v.end()));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
using namespace std;
int main(void){
    double n,m,num=0;
    cin>>n>>m;
    vector<int>a(n);
    double sum=0;
    for(int i=0; i<n; i++){
        cin >> a.at(i);
        sum += a.at(i);
    }
    sum = sum*(1.0/(4.0*m));
    for(int i=0; i<n; i++)if(a.at(i)>=sum)num++;
    if(num>=m)cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 3744
#include <iostream>
#include <vector>

int main(){
	int n;
	std::cin >> n;
	int h[n];
	for(int i=0;i<n; i++){
		std::cin >> h[i];
	}
	int sum = 0;
	for(int i=1;i<n; i++){
		if(h[i-1] - h[i] > 0){
			sum += h[i-1] - h[i];
		}
	}
	sum += h[n-1];
	std::cout << sum << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Int = unsigned long long;
typedef pair<int,int> P;
typedef priority_queue<int> Pr;
typedef vector<int> Vi;
typedef vector<P> Vp;
int const MOD = 1000000007;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
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 main(){
    cin.tie(nullptr); ios::sync_with_stdio(false);

    int n,k,ans=0; cin>>n>>k; string s; cin>>s; Vi c;
    int key=1,l=1;
    for (int i = 1; i < n; i++){
        if(s[i]!=s[i-1])l++;
        if(s[i]==s[i-1])key++;
        else {
            c.push_back(key); ans+=max(0,key-1); key=1;
        }
        if(i==n-1&&s[i]==s[i-1]){c.push_back(key); ans+=max(0,key-1);}
    }
    //cout<<l<<'\n';
    if(l==1){cout<<n-1<<'\n'; return 0;}
    while(k&&l>=2){
        if(l>=3){ans+=2; l-=2;}
        else {ans+=1; l--;}
        k--;
    }
    cout<<ans<<'\n';
}

Measured memory_bytes: 972
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<int,int>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
#define minn(x,y) x=min(x,y)
#define maxx(x,y) x=max(x,y)
using namespace std;
int a[210][210];
int gcd(int i,int j)
{
	if(j==0)return i;
	return gcd(j,i%j);
}
int main()
{
	int i,j,k,n,m,x,y,z,t;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			a[i][j]=gcd(i,j);
		}
	}
	int ans=0;
	for(i=1;i<=n;i++)
	{
		for(j=1;j<=n;j++)
		{
			for(k=1;k<=n;k++)
			{
				ans+=a[i][a[j][k]];
			}
		}
	}
	printf("%d",ans);
}


Measured memory_bytes: 3972
#include <iostream>
#include <vector>
#include <numeric>
#include <algorithm>

int main() {
	int m, n;
	std::cin >> n >> m;

	std::vector<int> C(m);
	for (auto&& e : C)
		std::cin >> e;

	std::vector<int> dp(n + 1, std::numeric_limits<int>::max() - 1);
	dp[0] = 0;

	for (int i = 0; i < n; ++i) {
		for (auto&& e : C) {
			if (i + e > n)
				continue;

			dp[i + e] = std::min(dp[i] + 1, dp[i + e]);
		}
	}

	std::cout << dp[n] << std::endl;
}


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

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define pb push_back

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

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};

int wa[100010];
bool ac[100010];

int main(){
	int n,m;
	cin>>n>>m;
	
	int p;
	string s;
	ll a=0,b=0;
	for (int i = 0; i < m; i++){
		cin>>p>>s;
		if(s=="AC"&&ac[p]==false){
			ac[p]=true;
			a++;
			b+=wa[p];
		}
		if(s=="WA")wa[p]++;

	}

	cout<<a<<' '<<b<<endl;

	return 0;
}


Measured memory_bytes: 768
while true
  n,m = gets.split(" ").map{|str| str.to_i}
  break if [n,m] == [0,0]
  pd = Array.new(n){gets.split(" ").map{|str| str.to_i}.reverse}.sort #??±????????§????????????????????£????????§reverse?????????

  attack = pd.inject(0){|sum,arr| sum += arr.inject(:*)}

  while m>0
    attack -= pd[-1][0]
    break if attack == 0
    m -= 1 ; pd[-1][1] -= 1
    pd.pop if pd[-1][1] == 0
  end

  puts attack
end

Measured memory_bytes: 9028
#include<bits/stdc++.h>
#define fast ios::sync_with_stdio(false), cin.tie(0);
#define ll long long
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define endl '\n'

using namespace std;

main()
{
    fast;
    int n,a;
    cin>>n>>a;
    cout<<n*n-a<<endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <stdint.h> // int64_t

#define max(a,b) ((a) > (b) ? (a) : (b))
#define min(a,b) ((a) > (b) ? (b) : (a))

int get_int(void) {
  int num;
  scanf("%d", &num);
  return num;
}

int get_int2(int *a1, int *a2) {
  scanf("%d %d", a1, a2);
  return 0;
}

struct work {
    int cost;
    int deadline;
};


int asc_by_deadline(const void *a1, const void *a2) {
    struct work *w1 = (struct work*)a1;
    struct work *w2 = (struct work*)a2;
    if(w1->deadline == w2->deadline) {
        return w2->cost - w1->cost;
    } 
    return w1->deadline - w2->deadline;
    
}

#define NUM_MAX 200000

int main(void) {
    int num = get_int();

    int i;
    static struct work works[NUM_MAX];
    for(i = 0; i < num; i++) {
        get_int2(&works[i].cost, &works[i].deadline);
    }

    qsort(works, num, sizeof(struct work), asc_by_deadline);

    int64_t time = 0;
    int flag = 1;
    for(i = 0; i < num; i++) {
        struct work cur = works[i];
        time += cur.cost;
#ifdef DEBUG
        printf("cur time: %lld\n", time);
#endif
        if(time > cur.deadline) {
            flag = 0;
            break;
        }
    }
    printf("%s\n", flag ? "Yes" : "No");
    return 0;
}

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

#define dictsize int(pow(5.0, 12.0))
int dict[dictsize] = {};

map<char, int> dict_to_key = {
    {'A', 1},
    {'C', 2},
    {'G', 3},
    {'T', 4},
};

int name_to_key(string &str) {
  auto res = 0;
  for(auto &item : str) {
    res = res * 4 + dict_to_key[item];
  }
  return res;
}

int main() {
  int N;
  cin >> N;
  string operate;
  string name;
  rep (i, N) {
    cin >> operate >> name;
    if (operate == "insert"){
      dict [name_to_key(name)] = 1;
    } else {
      if (dict [name_to_key(name)])
        cout << "yes" << endl;
      else
        cout << "no" << endl;
    }
  }
}




Measured memory_bytes: 8516
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cctype>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <map>
#include <set>
#include <vector>
#include <queue>


using namespace std;
#define INF 0x3f3f3f3f3f
#define ll long long
#define pr(x) (cerr << #x << ' ' << x << ' ')
#define prln(x) (cerr << #x << ' ' << x << endl)


int main()
{
	#ifdef LOCAL
		freopen("in.txt", "r", stdin);
	#endif // LOCAL

	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	int t = max(a, max(b, c));
	int x;
	if (t * 3 % 2 == (a + b + c) % 2) {
		x = t;
	}else {
		x = t + 1;
	}
	printf("%d\n", (3 * x - (a + b + c)) / 2);
	return 0;
}

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

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

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

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

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

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

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

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

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

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

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

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

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

void debug_out() { cerr << endl; }

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

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif
// tourist set end

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,b) FOR(i, 0, b)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("YES")
#define p_no() p("NO")
#define pb(s) push_back(s)
#define SZ(x) ((int)(x).size())

const ll mod = 1e9 + 7;
const ll inf = 1e18;

void vprint(vector<ll> A){
    ll L = A.size();
    FOR(i, 0, L){
        if(i) cout << ' ';
        cout << A[i];
    }
    cout << endl;
}

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

    // input
    ll K,X;cin>>K>>X;
    VI ans;
    FOR(i, X-K+1, X+K){
      ans.pb(i);
    }
    vprint(ans);
    
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
using namespace std;
void die(int x){
	cout<<x;
	exit(0);
}
int main()
{
    ios::sync_with_stdio(0);
	ll o=1,maxi=1e18,sum=1;
	ll n;
	cin>>n;
	vector<ll>x(n+1);
	for(int i=0;i<n;i++){
		cin>>x[i];
		if(x[i]==0)
		die(0);
	}
	for(int i=0;i<n;i++){
		if(x[i]>maxi) die(-1);
		sum*=x[i];
		maxi/=x[i];
	}
	cout<<sum;
    return 0;
}


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

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    int q;
    cin >> q;
    vector<int> tp(q), p1(q), p2(q);
    vector<char> p3(q);
    rep(i,q){
        cin >> tp.at(i) >> p1.at(i);
        if(tp.at(i) == 2) cin >> p2.at(i);
        else cin >> p3.at(i);
    }
    vector<set<int>> vs(26);
    rep(i,s.size()){
        vs.at(s.at(i) - 'a').insert(i+1);
    }
    
    rep(i,q){
        if(tp.at(i) == 1){
            rep(j,26){
                vs.at(j).erase(p1.at(i));
            }
            vs.at(p3.at(i) - 'a').insert(p1.at(i));
        }
        else {
            int cnt = 0;
            rep(j,26){
                auto lt = vs.at(j).lower_bound(p1.at(i));
                if(lt != vs.at(j).end() && *lt <= p2.at(i)){
                    cnt++;
                }
            }
            cout << cnt << endl;
        }
    }

    // rep(i,26){
    //     if(vs.at(i).size() == 0) continue;
    //     char c = 'a' + i;
    //     cout << c << ":";
    //     for(auto x:vs.at(i)){
    //         cout << x << " ";
    //     }
    //     cout << endl;
    // }
    return 0;
}

Measured memory_bytes: 24452
// Tarun IIITA
//Тарун Асудани 
//Не читайте этот код
 
#include<bits/stdc++.h>
using namespace std;
#define ll   long long
#define pb push_back
#define pf push_front
#define MP make_pair
#define all(v) v.begin(),v.end()
#define F first
#define lb lower_bound
#define ub upper_bound
#define bs binary_search
#define S second
#define P pair<ll,ll>
#define vect vector<ll>
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL)
#define mod  1000000007
#define int  long long


void solve(){
   int n;
   cin>>n;
   if(n<2000 && n>=1800){
      cout<<"1";
   }
   if(n<1800 && n>=1600){
      cout<<"2";
   }
   if(n<1600 && n>=1400){
      cout<<"3";
   }
   if(n<1400 && n>=1200){
      cout<<"4";
   }
   if(n<1200 && n>=1000){
      cout<<"5";
   }
   if( n<1000 && n>=800){
      cout<<"6";
   }
   if(n<800 && n>=600){
      cout<<"7";
   }
   if(n<600 && n>=400){
      cout<<"8";
   }
}



signed main(){
   boost;
   int t=1;
   //cin>>t;
   while(t--){
      solve();
   }
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long
#define vec_rep(itr,v) for(auto itr = v.begin(); itr != v.end(); ++itr)

int main(void){
    int N;
    cin >> N;
    ll ans = 0; 
    ll count = 0;
    while(1){
        count += N;
        ans++;
        if(count %360 == 0)break;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3564
//start of jonathanirvings' template v3.0.3 (BETA)

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

typedef long long LL;
typedef pair<int,int> pii;
typedef pair<LL,LL> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vii;
typedef vector<LL> vl;
typedef vector<vl> vvl;

double EPS = 1e-9;
int INF = 1000000005;
long long INFF = 1000000000000000005LL;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};

#ifdef TESTING
  #define DEBUG fprintf(stderr,"====TESTING====\n")
  #define VALUE(x) cerr << "The value of " << #x << " is " << x << endl
  #define debug(...) fprintf(stderr, __VA_ARGS__)
#else
  #define DEBUG 
  #define VALUE(x)
  #define debug(...)
#endif

#define FOR(a,b,c) for (int (a)=(b);(a)<(c);++(a))
#define FORN(a,b,c) for (int (a)=(b);(a)<=(c);++(a))
#define FORD(a,b,c) for (int (a)=(b);(a)>=(c);--(a))
#define FORSQ(a,b,c) for (int (a)=(b);(a)*(a)<=(c);++(a))
#define FORC(a,b,c) for (char (a)=(b);(a)<=(c);++(a))
#define FOREACH(a,b) for (auto &(a) : (b))
#define REP(i,n) FOR(i,0,n)
#define REPN(i,n) FORN(i,1,n)
#define MAX(a,b) a = max(a,b)
#define MIN(a,b) a = min(a,b)
#define SQR(x) ((LL)(x) * (x))
#define RESET(a,b) memset(a,b,sizeof(a))
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ALL(v) v.begin(),v.end()
#define ALLA(arr,sz) arr,arr+sz
#define SIZE(v) (int)v.size()
#define SORT(v) sort(ALL(v))
#define REVERSE(v) reverse(ALL(v))
#define SORTA(arr,sz) sort(ALLA(arr,sz))
#define REVERSEA(arr,sz) reverse(ALLA(arr,sz))
#define PERMUTE next_permutation
#define TC(t) while(t--)

inline string IntToString(LL a){
  char x[100];
  sprintf(x,"%lld",a); string s = x;
  return s;
}

inline LL StringToInt(string a){
  char x[100]; LL res;
  strcpy(x,a.c_str()); sscanf(x,"%lld",&res);
  return res;
}

inline string GetString(void){
  char x[1000005];
  scanf("%s",x); string s = x;
  return s;
}

inline string uppercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'a' && s[i] <= 'z') s[i] = s[i] - 'a' + 'A';
  return s;
}

inline string lowercase(string s){
  int n = SIZE(s); 
  REP(i,n) if (s[i] >= 'A' && s[i] <= 'Z') s[i] = s[i] - 'A' + 'a';
  return s;
}

inline void OPEN (string s) {
  #ifndef TESTING
  freopen ((s + ".in").c_str (), "r", stdin);
  freopen ((s + ".out").c_str (), "w", stdout);
  #endif
}

//end of jonathanirvings' template v3.0.3 (BETA)

int n;
int a[100005],b[100005],c[100005];

int main()
{
  scanf("%d",&n);
  REP(i,n) scanf("%d",&a[i]);
  REP(i,n) scanf("%d",&b[i]);
  REP(i,n) scanf("%d",&c[i]);
  SORTA(a,n);
  SORTA(b,n);
  SORTA(c,n);
  int L = 0;
  int R = 0;
  LL risan = 0;
  REP(i,n)
  {
    while (L < n && a[L] < b[i]) ++L;
    while (R < n && b[i] >= c[R]) ++R;
    // debug("%d %d\n",L,R);
    risan += (LL)(L) * (n - R);
  }
  printf("%lld\n",risan);
  return 0;
}










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

typedef long long ll;

int main() {
    string S;
    cin >> S;
    ll ans = 0;
    int n = S.size();
    rep(i, n) {
        ll c = 0;
        while (i < n && S[i] == '<') {
            c++;
            i++;
        }
        ans += c * (c - 1) / 2;
        //cout << c << " " << ans << "\n";
        ll d = 0;
        while (i < n && S[i] == '>') {
            d++;
            i++;
        }
        ans += max(c, d) + d * (d - 1) / 2;
        //cout << d << " " << ans << "\n";
        i--;
    }
    cout << ans << "\n";
}

Measured memory_bytes: 900
#include <bits/stdc++.h>
#define rg register
#define mk(x,y) make_pair(x,y)
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=100010;
template <typename Tp> inline int getmin(Tp &x,Tp y){return y<x?x=y,1:0;}
template <typename Tp> inline int getmax(Tp &x,Tp y){return y>x?x=y,1:0;}
template <typename Tp> inline void read(Tp &x)
{
    x=0;int f=0;char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') f=1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    if(f) x=-x;
}
int n,x,y,v,lim,f[maxn];
map<ll,int> ma;
queue<pii> q;
set<int> s[maxn];
set<int>::iterator itr;
inline int find(int x){return f[x]==x?x:f[x]=find(f[x]);}
inline ll getid(int x,int y){return x<y?(ll)x*n+y:(ll)y*n+x;}
int link(int x,int y)
{
	s[x].insert(y);s[y].insert(x);
	ll tmp=getid(x,y);
	int t=(++ma[tmp]);
	if(t==2) q.push(mk(x,y));
	if(t==3){puts("NO");exit(0);}
}
int main()
{
	read(n);lim=n-1<<1;
	for(rg int i=1;i<=n;i++) f[i]=i;
	for(rg int i=1;i<=lim;i++)
	{
		read(x);read(y);
		link(x,y);
	}
	for(rg int i=1;i<n;i++)
	{
		while(1)
		{
			if(q.empty()){puts("NO");return 0;}
			x=q.front().first;y=q.front().second;q.pop();
			x=find(x);y=find(y);
			if(x^y) break;
		}
		if(s[x].size()>s[y].size()) swap(x,y);
		f[x]=y;s[y].erase(x);ma.erase(getid(x,y));
		for(itr=s[x].begin();itr!=s[x].end();++itr)
		{
			v=find(*itr);
			if(v==y) continue;
			ma.erase(getid(v,x));
			s[v].erase(x);
			link(y,v);
		}
		s[x].clear();
	}
	puts("YES");
	return 0;
}

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

/*
#include <algorithm>
#include <cstring>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <vector>
#include <set>
*/

using namespace std;

typedef long long LL;
typedef double DB;
typedef unsigned int UI;
typedef pair<int, int> PII;

const int inf = 0x7f7f7f7f;

#define rdi() read<int>()
#define rdl() read<LL>()
#define rds(a) scanf("%s", a)
#define mk(i, j) make_pair(i, j)
#define pb push_back
#define fi first
#define se second
#define For(i, j, k) for (int i = j; i <= k; i ++)
#define Rep(i, j, k) for (int i = j; i >= k; i --)
#define Edge(i, u) for (int i = head[u]; i; i = e[i].nxt)

template<typename t> t read() {
	t x = 0; int f = 1; char c = getchar();
	while (c > '9' || c < '0') f = c == '-' ? -1 : 1 , c = getchar();
	while (c >= '0' && c <= '9') x = x * 10 + c - 48 , c = getchar();
	return x * f;
}

template<typename t> void write(t x) {
	if (x < 0){
		putchar('-'), write(-x);
		return;
	}
	if (x >= 10) write(x / 10);
	putchar(x % 10 + 48);
}

const int N = 2e5 + 10;
int r, c, n;
int x[N][2], y[N][2];
bool exist[N];
stack <int> stk;
 
int getpos(int x, int y) {
	if (!y) return x;
	if (x == r) return r + y;
	if (y == c) return r + c + r - x;
	return r + c + r + (c - y);	
}

int main() {
//	freopen(".in", "r", stdin);
//	freopen(".out", "w", stdout);
	r = rdi(), c = rdi(), n = rdi();
	for (int i = 0; i < n; i ++) x[i][0] = rdi(), y[i][0] = rdi(), x[i][1] = rdi(), y[i][1] = rdi();
	vector <PII> nums;
	for (int j, i = 0; i < n; i ++) {
		for (j = 0; j < 2; j ++) {
			if (!(x[i][j] == 0 || x[i][j] == r || y[i][j] == 0 || y[i][j] == c)) break;
		}
		if (j == 2) {
			int p = getpos(x[i][0], y[i][0]);
			int q = getpos(x[i][1], y[i][1]);
			nums.push_back(mk(p, i));
			nums.push_back(mk(q, i));
		}
	}
	sort(nums.begin(), nums.end());
	for (int i = 0; i < nums.size(); i ++) {
		int v = nums[i].second;
		if (!exist[v]) {
			stk.push(v);
			exist[v] = true;
		}
		else {
			if (stk.top() != v) return puts("NO"), 0;
			stk.pop();
			exist[v] = false;
		}			
	}
	return puts("YES"), 0;
}


Measured memory_bytes: 3956
#include<bits/stdc++.h>
using namespace std;
int main(){
  map<int, int> D, T;
  int N;
  cin >> N;
  for (int i=0;i<N;i++){
    int d;
    cin >> d;
    if (D.count(d)){
      D.at(d) += 1;
    }
    else{
      D[d] = 1;
    }
  }
  int M;
  cin >> M;
  for (int i=0;i<M;i++){
    int t;
    cin >> t;
    if (T.count(t)){
      T.at(t) += 1;
    }
    else{
      T[t] = 1;
    }
  }
  int flg = 1;
  for (pair<int, int> p : T){
    if (!D.count(p.first) || D[p.first] < p.second){
      flg = 0;
    }
  }
  if (flg == 1){
    cout << "YES" << endl;
  }
  else{
    cout << "NO" << endl;
  }
}

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

#define int long long

using namespace std;



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

    int N, Q;
    cin >> N >> Q;

    vector<pair<int,pair<int,int>>> v1, v2;

    v1.push_back({1,{0,N-2}});
    v2.push_back({1,{0,N-2}});

    int res = (N-2)*(N-2);

    for(int i = 0 ; i < Q ; i++)
    {
    	int qu, x;
    	cin >> qu >> x;

    	x = N-x+1;

    	if(qu == 1)
    	{
    		pair<int,pair<int,int>> pp = {x,{0,0}};
    		auto it = lower_bound(v1.begin(), v1.end(), pp);

    		if(it == v1.end())
    		{
    			v1.push_back({x, {v2.back().second.second, N - x - 1}});

    			res -= v2.back().second.second;
    		}
    		else
    		{
    			res -= (*it).second.first;
    		}
    	}
    	else
    	{
    		pair<int,pair<int,int>> pp = {x,{0,0}};
    		auto it = lower_bound(v2.begin(), v2.end(), pp);

    		if(it == v2.end())
    		{
    			v2.push_back({x, {v1.back().second.second, N - x - 1}});

    			res -= v1.back().second.second;
    		}
    		else
    		{
    			res -= (*it).second.first;
    		}
    	}
    }

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 9360
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=998244353;
constexpr int N=200000;
mt19937 mt;

int D,c[26],s[200000][26],t[200000],T[200000],v,V,l[26];

int main(){
	scanf("%d",&D);
	for(int i=0;i<26;i++){
		scanf("%d",&c[i]);
	}
	for(int i=0;i<D;i++){
		for(int j=0;j<26;j++){
			scanf("%d",&s[i][j]);
		}
	}
	for(int i=0;i<D;i++){
		t[i]=uniform_int_distribution<int>(0,25)(mt);
	}
	for(int i=0;i<26;i++){
		l[i]=-1;
	}
	for(int i=0;i<D;i++){
		l[t[i]]=i;
		v+=s[i][t[i]];
		for(int j=0;j<26;j++){
			v-=c[j]*(i-l[j]);
		}
	}
	for(int i=0;i<N;i++){
		for(int j=0;j<D;j++){
			if(uniform_int_distribution<int>(0,N*10)(mt)<=N-i){
				T[j]=uniform_int_distribution<int>(0,25)(mt);
			}
			else{
				T[j]=t[j];
			}
		}
		for(int j=0;j<26;j++){
			l[j]=-1;
		}
		V=0;
		for(int j=0;j<D;j++){
			V-=c[T[j]]*(j-l[T[j]]-1)*(j-l[T[j]])/2;
			l[T[j]]=j;
			V+=s[j][T[j]];
		}
		for(int j=0;j<26;j++){
			V-=c[j]*(D-l[j]-1)*(D-l[j])/2;
		}
		if(V>v){
			v=V;
			for(int j=0;j<D;j++){
				t[j]=T[j];
			}
		}
	}
	for(int i=0;i<D;i++){
		printf("%d\n",t[i]+1);
	}
}


Measured memory_bytes: 3868
module Main (main) where

import qualified Data.ByteString.Char8     as C8
import           Data.Maybe

main :: IO ()
main = do
  [n] <- readInts
  print . showAnswer $ solve n

type Input  = (Int)
type Output = Bool

solve :: Input -> Output
solve = any (=='9') . show

showAnswer :: Output -> Answer
showAnswer = YesNo

-- utils
readInts :: IO [Int]
readInts = map (fst . fromJust . C8.readInt) . C8.words <$> C8.getLine

data Answer
  = YesNo Bool
  | AB Bool
  | Number Int

instance Show Answer where
  show (YesNo b)  = if b then "Yes" else "No"
  show (AB b)     = if b then "A"   else "B"
  show (Number i) = show i

Measured memory_bytes: 380
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>

using namespace std;

#define Whats(x) cout<<#x<<" is "<<(x)<<endl
#define Divhim() cout<<">>>>>>>>>"<<endl
#define Divher() cout<<"<<<<<<<<<"<<endl
#define Oops() cout<<"!!!!!!!!!!"<<endl

template<typename T> bool Getmax(T &a,T b)
{
	return (a<b)?(a=b,true):false;
}

template<typename T> bool Getmin(T &a,T b)
{
	return (a>b)?(a=b,true):false;
}

#define LL long long
const int MOD=998244353;
const int N=1e6+10;

int n,m,jc[N],njc[N];

int C(int n,int m){return (LL)jc[n]*njc[m]%MOD*njc[n-m]%MOD;}

int Qpow(int x,int y=MOD-2)
{
	int res=1;
	for(;y;y>>=1,x=(LL)x*x%MOD)if(y&1)
		res=(LL)res*x%MOD;
	return res;
}

void Prework()
{
	jc[0]=1;
	for(int i=1;i<N;++i)
		jc[i]=(LL)jc[i-1]*i%MOD;
	njc[N-1]=Qpow(jc[N-1]);
	for(int i=N-2;i>=0;--i)
		njc[i]=(LL)njc[i+1]*(i+1)%MOD;
}

int main()
{
	Prework();
	scanf("%d%d",&n,&m);
	if(n>m)swap(n,m);
	LL ans=(LL)n*C(n+m,n)%MOD;
	for(int i=1;i<=n;++i)
		ans-=(LL)C(i+i-1,i)*C(n+m-2*i,n-i)%MOD;
	ans=ans%MOD*Qpow(C(n+m,n))%MOD;
	ans=n+m-ans;
	ans=(ans%MOD+MOD)%MOD;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 8064
#include <iostream>

using namespace std;
int main(){
	static bool cmp[1000000] = {true};
	static int ans[1000000];
	for(int i=2; i<1000000;i++){
		if(!cmp[i]){
			for(int j=2;j*i<1000000;j++){
				cmp[i*j] = true;
			}
		}
		ans[i] = ans[i-1]+!cmp[i];
	}
	for(int n; cin>>n; n++){
		cout<<ans[n]<<endl;
	}
	return 0;
}

Measured memory_bytes: 6044