akhauriyash/Code-Regression huggingface dataset:
import collections

n = int(input())
a = list(map(int, input().split()))
a = sorted(a)
c = collections.Counter(a)
data = sorted(list(set(a)))
max_ = max(a)+1
prime_bool = [True]*max_
prime_bool[0] = False

for i in range(len(data)):
  p = data[i]
  if prime_bool[p]:
    #print(p)
    k = 2
    while k*p < max_:
      prime_bool[k*p] = False
      k += 1

count = 0
for i in range(len(prime_bool)):
  if prime_bool[i]:
    if c[i] == 1:
      count += 1
print(count)
#print(prime_bool)


Measured memory_bytes: 44544
A, B, C, D = list(input())

oplist = ['+', '-']

for op1 in oplist:
    for op2 in oplist:
        for op3 in oplist:
            f = A + op1 + B + op2 + C + op3 + D
            ans = eval(f)
            if ans == 7:
                print(f + "=7")
                quit()

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

int main(){
  int H,N;
  cin >> H >> N;
  int Attack=0;
  int A;
  for(int i=0;i<N;i++){
    cin >> A;
    Attack += A;
  }
  if(Attack>=H){
    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;

int main(){

    ll A;
    cin >> A;
    vector<pair<ll,ll>> a(A);
    for(ll i=0;i<A;i++)
    {
        std::cin >> a[i].first;
        a[i].second = 0;
    }

    ll nextIndex = a[0].first;
    a[0].second = 1;
    if(nextIndex-1 == 1)
    {
        std::cout << 1;
        return 0;
    }

    bool canTrain = false;
    ll cnt =1;
    while(true)
    {
        if(a[nextIndex-1].second == 1) break;
        a[nextIndex-1].second = 1;
        nextIndex = a[nextIndex - 1].first;

        cnt++;
        if(nextIndex-1 == 1)
        {
            canTrain = true;
            break;
        }
    }

    if(canTrain)
    {
        std::cout << cnt;
    }else
    {
        std::cout << -1;
    }
    

    return 0;
}




Measured memory_bytes: 1792
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	long long int a, b;
	cin >> a >> b;
	long long int num = __gcd(a,b);
	long long int ans = a*b/num;
	cout << ans << endl;
	return 0;
}

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

int main(){
  int N;
  cin >> N;
  for(int i=0;i<N*0.001+1;i++){
    if(i*1000-N>-1 && i*1000-N<1000){
      cout << i*1000-N << endl;
    }
  }
}

Measured memory_bytes: 3588
/*
　　　∫ ∫ ∫
　　　ノヽ
　　（＿　 ）
　（＿　　　 ）
（＿＿＿＿＿＿ ）
　ヽ(´･ω･)ﾉ　
　　 |　 /
　　 UU
*/
#pragma region macro
#include <bits/stdc++.h>
typedef long long int64;
using namespace std;
using P = pair<int64, int64>;
typedef vector<int> vi;
const int MOD = (int)1e9 + 7;
const int64 INF = 1LL << 62;
const int inf = 1<<30;
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 REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i,s,n) for (int i = s; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end() //コンテナじゃないと使えない!!
#define debug(x) cerr << #x << ": " << x << "\n";
#define mp make_pair
#define bn '\n'
template <typename T>
ostream& operator<<(ostream& os, const vector<T> &V){
    int N = V.size();
    REP(i,N){
        os << V[i];
        if (i!=N-1) os << " ";
    }
    os << "\n";
    return os;
}
template <typename T,typename S>
ostream& operator<<(ostream& os, pair<T,S> const&P){
    os << "(";
    os << P.first;
    os << " , ";
    os << P.second;
    os << ")";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, set<T> &S){
    auto it=S.begin();
    while(it!=S.end()){
        os << *it;
        os << " ";
        it++;
    }
    os << "\n";
    return os;
}
template <typename T>
ostream& operator<<(ostream& os, deque<T> &q){
    for(auto it=q.begin();it<q.end();it++){
        os<<*it;
        os<<" ";
    }
     os<<endl;
    return os;
}
vector<pair<int,int>> dxdy = {mp(0,1),mp(1,0),mp(-1,0),mp(0,-1)};
#pragma endregion
//fixed<<setprecision(10)<<ans<<endl;

// ax + by = gcd(a, b) となるような (x, y) を求める
// 多くの場合 a と b は互いに素として ax + by = 1 となる (x, y) を求める
long long extGCD(long long a, long long b, long long &x, long long &y) {
    if (b == 0) {
        x = 1;
        y = 0;
        return a;
    }
    long long d = extGCD(b, a%b, y, x); // 再帰的に解く
    y -= a / b * x;
    return d;
}

// 負の数にも対応した mod (a = -11 とかでも OK) 
inline long long mod(long long a, long long m) {
    return (a % m + m) % m;
}

// 逆元計算 (ここでは a と m が互いに素であることが必要)
long long modinv(long long a, long long m) {
    long long x, y;
    extGCD(a, m, x, y);
    return mod(x, m); // 気持ち的には x % m だが、x が負かもしれないので
}

int64 pow(int a,int b,int mod){
    if(b==0)return 1;
    vector<bool> bit;
    for(b=b;b>0;b>>=1){
        bit.push_back(b&1);
    }
    vector<int64> fac(bit.size()); fac[0] = a;
    int64 res = 1;
    for(int i=1;i<bit.size();i++){
        fac[i] = (fac[i-1] * fac[i-1])%mod;
    }
    for(int i=0;i<bit.size();i++){
        if(bit[i]) res*=fac[i];
        res%=mod;
    }
    return res;
}


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int P = 2019;
    string S;
    cin >> S;
    int N; N = S.size();

    map<int64,int64> M;
    int zero_cnt = 1;
    int64 before = 0;
    int64 ans = 0;
    M[0]++;

    REP(i,N){
        int idx = N-i-1;
        int x = S[idx] - '0';

        before += pow(10,i,P)*x;
        before %= P;
        ans += M[before];
        M[before]++;
    }


    cout << ans << endl;
}

Measured memory_bytes: 3728
#include<iostream>
using namespace std;
int main() {
    int check[999] = {0};
    check[0] = 1;
    for (int i = 1; i < 999; i++) {
        check[i] += check[i - 1] + (i + 1);
    }/*
    for (int i = 0; i < 999; i++) {
        cout << check[i] << " ";
    }
    cout << endl;*/
    int a, b;
    cin >> a >> b;
    int ans = 0;
    for (int i = 0; i < 999; i++) {
        if (check[i] - a == check[i + 1] - b) {
            ans = check[i] - a;
            break;
        }
    }
    cout << ans << endl;
}



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

typedef long long int ll;
typedef pair<int,int> pi;
priority_queue<pi, vector<pi>, greater<pi> > pq; //min heap

ll mini(ll a,ll b){	return a<b?a:b;}
ll maxi(ll a,ll b){	return a>b?a:b;}
ll gcd(ll a,ll b){	if(b == 0)	return a;return gcd(b,a%b);}
ll binpow(ll n,ll x){	ll ans = 1;while(x){if(x & 1)	ans *= n;n *= n;x >>= 1;}return ans;}

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

    int n;
    cin>>n;
    int k;
    cin>>k;
    vector<int> sto(n+1,0);
    for(int i=1;i<=n;++i)   cin>>sto[i];

    vector<int> dp(k+1,0);

    for(int i=0;i<=k;++i){
        for(int j=1;j<=n;++j){
            if(i >= sto[j] && !dp[i-sto[j]])  dp[i] = 1;
        }
    }

    if(dp[k])  cout<<"First\n";
    else        cout<<"Second\n";

    return 0;
}

Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
struct edge {
	int v, cap, rev;
	edge(int a, int b, int c) : v(a), cap(b), rev(c) {}
};
vector<edge> adj[200005];
int lst[200005], dep[200005];
void add(int x, int y, int c)
{
	adj[x].emplace_back(y, c, (int)adj[y].size());
	adj[y].emplace_back(x, 0, (int)adj[x].size() - 1);
}
bool bfs(int s, int t)
{
	memset(dep, -1, sizeof(dep));
	dep[s] = 0;
	queue<int> que;
	que.push(s);
	while (!que.empty()) {
		int u = que.front();
		que.pop();
		for (edge &e : adj[u]) {
			if (e.cap && dep[e.v] == -1) {
				dep[e.v] = dep[u] + 1;
				que.push(e.v);
			}
		}
	}
	return ~dep[t];
}
int dfs(int u, int t, int c)
{
	if (u == t) {
		return c;
	}
	int res = 0;
	for (int &i = lst[u]; i >= 0; i--) {
		auto &e = adj[u][i];
		if (e.cap && dep[e.v] == dep[u] + 1) {
			int x = dfs(e.v, t, min(c - res, e.cap));
			e.cap -= x;
			adj[e.v][e.rev].cap += x;
			res += x;
			if (res == c) {
				return res;
			}
		}
	}
	if (!res) {
		dep[u] = 0;
	}
	return res;
}
int dinic(int s, int t)
{
	int ans = 0;
	while (bfs(s, t)) {
		for (int i = 0; i <= t; i++) {
			lst[i] = (int)adj[i].size() - 1;
		}
		ans += dfs(s, t, 1e9);
	}
	return ans;
}
vector<int> have[200005];
int ans[200005], node[200005];
bool in[200005];
int dfs(int u)
{
	int res = 1;
	in[u] = true;
	for (int x : have[u]) {
		if (!in[node[x]]) {
			ans[x] = u;
			res += dfs(node[x]);
		}
	}
	return res;
}
int main()
{
	cin.sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	int n;
	cin >> n;
	for (int i = 0; i < n - 1; i++) {
		int k;
		cin >> k;
		for (int j = 0; j < k; j++) {
			int x;
			cin >> x;
			have[--x].push_back(i);
			if (x) {
				add(i + 1, x + n - 1, 1);
			}
		}
		add(0, i + 1, 1);
		add(i + n, n * 2, 1);
	}
	if (dinic(0, n * 2) != n - 1) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 1; i < n; i++) {
		for (edge &e : adj[i]) {
			if (e.v != 0 && !e.cap) {
				node[i - 1] = e.v - n + 1;
			}
		}
	}
	if (dfs(0) != n) {
		cout << -1 << endl;
		return 0;
	}
	for (int i = 0; i < n - 1; i++) {
		cout << ans[i] + 1 << " " << node[i] + 1 << endl;
	}
	return 0;
}


Measured memory_bytes: 34536
import java.io.*;
import java.io.IOException;
import java.util.*;

@SuppressWarnings({"rawtypes", "unchecked"})
class Main {
    final static int INF = 1 << 28;
    final static long LNF = 1L << 60;
    final static double EPS = 1e-9;
    final static double GOLDEN_RATIO = (1.0 + Math.sqrt(5)) / 2.0;

    static final long MOD = 1_000_000_007;

    public static void main(String[] args) throws Exception {
        final MyScanner sc = new MyScanner();
        long N;
        N = sc.nextLong();
        long[] a = new long[(int)(N)];
        for(int i = 0 ; i < N ; i++){
                a[i] = sc.nextLong();
        }
        solve(N, a);
    }

    static void solve(long N, long[] a){
        long cur = 1;
        long ans = 0;
        for (long l : a) {
            if(l == cur) {
                cur++;
            } else {
                ans++;
            }
        }
        if(ans == a.length) ans = -1;
        System.out.println(ans);
    }


    static class MyScanner {
 
        BufferedReader br;
        StringTokenizer st;
 
        MyScanner(FileReader fileReader) {
            br = new BufferedReader(fileReader);
        }
 
        MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String nn() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        String next() {
            String ans = "";
            try {
                ans = br.readLine();
            } catch (IOException ex) {
                ex.printStackTrace();
            }
            return ans;
        }
 
        char nextChar() {
            return nn().charAt(0);
        }
 
        int nextInt() {
            return Integer.parseInt(nn());
        }
 
        long nextLong() {
            return Long.parseLong(nn());
        }
 
        double nextDouble() {
            return Double.parseDouble(nn());
        }
 
        Integer[] niArr0(int n) {
            Integer[] ar = new Integer[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Integer[] niArr1(int n) {
            Integer[] ar = new Integer[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextInt();
            }
            return ar;
        }
 
        Long[] nlArr0(int n) {
            Long[] ar = new Long[n];
            for (int i = 0; i < n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
 
        Long[] nlArr1(int n) {
            Long[] ar = new Long[n + 1];
            for (int i = 1; i <= n; i++) {
                ar[i] = nextLong();
            }
            return ar;
        }
    }

}


Measured memory_bytes: 47316
/* 学籍番号 17D8101029G 石塚 博之 ID: mcatpolo 言語:C */
#include <stdio.h>
#include <math.h>
#define N 200000

long a[N];

long merge(int left, int mid, int right){
    long c = 0;
    long L[N/2+2], R[N/2+2];
    int n1, n2, i, j, k;

    n1 = mid - left;
    n2 = right - mid;

   for(i=0; i<n1; i++){
       L[i] = a[left+i];
   }

   for(i=0; i<n2; i++){
       R[i] = a[mid + i];
   }

   L[n1] = (long)INFINITY;
   R[n2] = (long)INFINITY;

   i=0;
   j=0;

   for(k=left; k<right; k++){
       if(L[i] <= R[j]) {
           a[k] = L[i];
           i++;
       }
       else {
           a[k] = R[j];
           j++;
           c += n1 - i;
       }
   }

   return c;
}

long mergeSort(int left, int right){
    int mid;
    long v1, v2, v3;
    if (left + 1 < right)
    {
        mid = (left+right)/2;
        v1 = mergeSort(left, mid);
        v2 = mergeSort(mid, right);
        v3 = merge(left, mid, right);

        return v1 + v2 + v3;
    }

    return 0;
}

int main(void){
    long i;
    long n;

    scanf("%ld", &n);

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

   

   printf("%ld\n", mergeSort(0, n));

   return 0;
}


Measured memory_bytes: 4852
import sys
sys.setrecursionlimit(100000)

def ins(): return input().split()
def ii(): return int(input())
def iil(): return list(map(int,ins()))
def lin(): return list(input())
def iin(): return map(int,ins())

n = ii()
a = iil()
b = [0 for i in range(n)]
for i,j in enumerate(a):
    b[j-1] = str(i+1)
print(" ".join(b))

Measured memory_bytes: 15588
#include <iostream>
using namespace std;
const int mod = 1e9 + 7;

int main()
{
  int n;
  cin >> n;
  int arr[n];
  for (int i = 0; i < n; ++i)
  {
    cin >> arr[i];
  }
  int dp[n];
  dp[n-1] = 0;
  dp[n-2] = abs(arr[n-2] - arr[n-1]);

  for (int i = n-3; i >= 0; --i)
  {
     dp[i] = min(dp[i + 1] + abs(arr[i] - arr[i + 1]), dp[i + 2] + abs(arr[i] - arr[i + 2]));
  }
  cout << dp[0];
}

Measured memory_bytes: 1024
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

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

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, begin, end) for(ll i = (begin); i < (end); i++)
#define rep(i, n) FOR(i, 0, n)
using ll = long long;
using ull = unsigned long long;
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using pii = pair<int, int>; using pll = pair<ll, ll>; using vi = vector<int>; using vl = vector<ll>;
template<typename T, typename U> static void chmin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void chmax(T &x, U y) { if (x < y) x = y; }

signed main() {
    int a,b,h,m;
    cin>>a>>b>>h>>m;
    double at = 2 * M_PI * (h / 12.0 + m / (60.0 * 12.0));
    double bt = 2 * M_PI * m / 60.0;
    double c = std::cos(bt - at);
    double ans = std::sqrt(a * a + b*b - 2*a*b*c);
    printf("%.14lf", ans);
    return 0;
}

Measured memory_bytes: 4188
fn main() {
    proconio::input! {
        n: usize,
        d: i64,
        xys: [(i64, i64); n],
    }
    fn distance2(x: i64, y: i64) -> i64 {
        x * x + y * y
    }
    let ans = xys
        .iter()
        .filter(|(x, y)| distance2(*x, *y) <= d * d)
        .count();
    println!("{}", ans);
}


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

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

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> void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U> void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

template<typename T>auto&operator<<(ostream&s,const vector<T>&v){s<<"[";bool a=1;for(auto e:v){s<<(a?"":" ")<<e;a=0;}s<<"]";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const pair<T,U>&p){s<<"("<<p.first<<","<<p.second<<")";return s;}
template<typename T>auto&operator<<(ostream&s,const set<T>&st){s<<"{";bool a=1;for(auto e:st){s<<(a?"":" ")<<e;a=0;}s<<"}";return s;}
template<typename T,typename U>auto&operator<<(ostream&s,const map<T,U>&m){s<<"{";bool a=1;for(auto e:m){s<<(a?"":" ")<<e.first<<":"<<e.second;a=0;}s<<"}";return s;}
#define DUMP(x) cout<<#x<<" = "<<(x)<<endl

struct edge { int to, cost; };

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

int main()
{
   int a, b; cin >> a >> b;
   cout << max({ a + a-1, a + b, b + b-1 }) << endl;

   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int c[20][20], a[300][300], mp[20];

int main(){
    int h, w;
    cin >> h >> w;
    for (int i = 0; i <= 9; i++){
        for (int j = 0; j <= 9; j++){
            cin >> c[i][j];
        }
        mp[i] = c[i][1];
    }
    for (int i = 0; i <= 9; i++){
        for (int j = 0; j <= 9; j++){
            if (j == 1)
                continue;
            for (int k = 0; k <= 9; k++){
                if (k == 1 || k == j)
                    continue;
                mp[k] = min(mp[k], mp[j] + c[k][j]);
            }
        }
    }
    int k = 0;
    for (int i = 1; i <= h; i++){
        for (int j = 1; j <= w; j++){
            cin >> a[i][j];
            if (abs(a[i][j]) != 1)
                k += mp[a[i][j]];
        }
    }
    cout << k << endl;
}


Measured memory_bytes: 512
import java.io.IOException;
import java.util.Scanner;
public class Main {
	public static void main(String[] args) throws IOException{
		Scanner sc = new Scanner(System.in);

		int[] array = new int[3];
		String judge;

		for(int i=0;i<3;i++) {
			array[i] = sc.nextInt();
		}

		if(array[0] < array[1] && array[1] < array[2]) {
			judge = "Yes";
		}else {
			judge = "No";
		}

		System.out.println(judge);

		sc.close();
	}
}


Measured memory_bytes: 26272
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <iomanip>
#include <numeric>
#include <queue>
#include <cmath>
using namespace std;


int main() {
    string s;
    cin >> s;
    if (s[0] == 'R' && s[1] == 'R' && s[2] == 'R') {
        cout << 3 << endl;
        return 0;
    }
    if ((s[1] == 'R' && s[0] == 'R') || (s[1] == 'R' && s[2] == 'R')) {
        cout << 2 << endl;
        return 0;
    }
    if (s[0] == 'R' || s[1] == 'R' || s[2] == 'R') {
        cout << 1 << endl;
        return 0;
    }
    
    cout << 0 << endl;
}


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

using namespace std;

int main() {
    int n;
    cin >> n;
    vector<int> d(n);
    for (int i=0; i<n; i++) cin >> d[i];
    sort(d.begin(), d.end());
    d.erase(unique(d.begin(), d.end()), d.end());

    cout << d.size() << endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
    static int[]dp = new int[100000];
    static int[]stones = new int[100000];
    static int N;
    public static void main(String[]args){
        Scanner in = new Scanner(System.in);
        N = in.nextInt();
        for(int i = 0 ; i < N ; ++i)
            stones[i] = in.nextInt();
        solve();
        System.out.println(dp[N-1]);
    }
    public static void solve(){
        dp[0] = 0;
        dp[1] = Math.abs(stones[1]-stones[0]);
        for(int i = 2 ; i < N ; ++i){
            dp[i] = Math.min(dp[i-1] + Math.abs(stones[i]-stones[i-1]),
            dp[i-2]+Math.abs(stones[i]-stones[i-2]));
        }
    }
}

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

int main(){
  string s;
  cin >> s;
  int count = 0;
  if(s.at(0) == 'o') count++;
  if(s.at(1) == 'o') count++;
  if(s.at(2) == 'o') count++;
  cout << 700 + 100*count << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <chrono>
#include <climits>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;

template <class T1, class T2>
ostream& operator << (ostream& out, const pair <T1, T2> p)
{
    out << '(' << p.first << ',' << p.second << ')';
    return out;
}

template <class T1, class T2>
istream& operator >> (istream& in, pair<T1, T2> &p)
{
    in >> p.first >> p.second;
    return in;
}

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

template <class T>
ostream& operator << (ostream& out, const vector<vector<T>> &v)
{
    for (const vector<T> &x : v)
        out << x << '\n';
    return out;
}

template <class T>
ostream& operator << (ostream& out, const vector<T> &v)
{
    for (const T &x : v)
        out << x << ' ';
    return out;
}

long long gcd (long long a, long long b)
{
    if (b > a)
        swap(a, b);
    return (b ? gcd(b, a % b) : a);
}

using ll   = long long;
using pii  = pair<int, int>;
using pll  = pair<long long, long long>;
using tiii = pair<pair<int, int>, int>;
using vi   = vector<int>;
using vl   = vector<long long>;
using vvi  = vector<vector<int>>;
using vvl  = vector<vector<long long>>;

#define F          first
#define S          second
#define First      first.first
#define Second     first.second
#define Third      second
#define mp         make_pair
#define rep(i,a,b) for (int i = (a); i < (b); i++)
#define per(i,b,a) for (int i = (b); i > (a); i--)
#define all(x)     x.begin(), x.end()
#define ret(x)     return cout << x, 0;
#define throwex    throw runtime_error ("Found the error.");

const int h = 1000000007;

signed main()
{
    ios::sync_with_stdio(false);
    #ifdef ONLINE_JUDGE
    cin.tie(nullptr);
    cout.tie(nullptr);
    cerr.setstate(ios::failbit);
    #endif

    string t;
    cin >> t;
    string s;
    ll ans = 0;
    int len = t.size();
    for(char c : t)
    {
        if(c == '1' and !s.empty() and s.back() == '1')
        {
            s.pop_back();
            ans += len;
            len -= 2;
        }
        else
            s.push_back(c);
    }

    int z = 0, one_cnt = 0;
    rep(i,0,s.size())
    {
        if(s[i] == '0')
            z++;
        if(s[i] == '1')
        {
            if(one_cnt)
                z--;
            ans += len - 2 * one_cnt - (z + 1) / 2;
            one_cnt++;
        }
    }
    cout << ans;
}


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

using namespace std;

using int64 = long long;

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

  int n;
  cin >> n;
  vector<int64> xs(n);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }

  int64 ans = 0;
  for (int i = 0; i < n; i++) {
    if (xs[i] % 2 == 1) {
      for (int j = i + 1; j < n; j++) {
        if (xs[j] == 0) {
          i = j;
          break;
        } else if (xs[j] % 2 == 1) {
          for (int k = i; k + 1 <= j; k++) {
            xs[k]--;
            xs[k + 1]--;
            ans++;
          }
          break;
        }
      }
    }
  }

  for (int64 x : xs) ans += x / 2;
  cout << ans << endl;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

struct Edge {
    long long to;
    long long cost;
};
using Graph = vector<vector<Edge>>;
using P = pair<long, int>;
vll dist;
vector<int> pre;

/* dijkstra(G,s,dis,prev)
    入力：グラフ G, 開始点 s, 距離を格納する dis, 最短経路の前の点を記録するprev
    計算量：O(|E|log|V|)
    副作用：dis, prevが書き換えられる
*/
void dijkstra(const Graph &G, int s, vector<long long> &dis, vector<int> &prev) {
    int N = G.size();
    dis.resize(N, INF);
    prev.resize(N, -1); // 初期化
    priority_queue<P, vector<P>, greater<P>> pq;
    dis[s] = 0;
    pq.emplace(dis[s], s);
    while (!pq.empty()) {
        P p = pq.top();
        pq.pop();
        int v = p.second;
        if (dis[v] < p.first) {
            continue;
        }
        for (auto &e : G[v]) {
            if (dis[e.to] > dis[v] + e.cost) {
                dis[e.to] = dis[v] + e.cost;
                prev[e.to] = v; // 頂点 v を通って e.to にたどり着いた
                pq.emplace(dis[e.to], e.to);
            }
        }
    }
}


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

    int N, M;
    cin >> N >> M;
    Graph g(N);
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        Edge e1, e2;
        e1.to = b, e1.cost = 1;
        e2.to = a, e2.cost = 1;
        g[a].push_back(e1);
        g[b].push_back(e2);
    }

    dijkstra(g, 0, dist, pre);

    rep(i, N) if(dist[i] >= INF) {
        cout << "No" << endl;
        return 0;
    }

    cout << "Yes" << endl;
    for(ll i = 1; i < N; i++) cout << pre[i] + 1 << endl;

}


Measured memory_bytes: 19140
<?php

$sc = new Scanner();

$N = $sc->next();
$h = [];
for($i = 0; $i < $N; $i++) {
    $h[] = $sc->nextInt();
}

$dp[pow(10,5) - 1][2];
for($i = 0; $i < pow(10,5) - 1; $i++) {
    $dp[$i][0] = -1;
    $dp[$i][1] = -1;
}

$a = dfs(0);

echo $a . PHP_EOL;

function dfs($i) {
    global $N, $h, $dp;
    if ($i >= $N - 1) {
        return 0;
    } 
    if ($i == $N - 2) {
        if ($dp[$i][0] >= 0) {
            return $dp[$i][0];
        }
        $d = abs($h[$i] - $h[$i+1]);
        $dp[$i][0] = $d;
        return $d;
    }
    if ($i < $N - 2) {
        $d1 = abs($h[$i] - $h[$i+1]);
        $d2 = abs($h[$i] - $h[$i+2]);
        if ($dp[$i][0] < 0) {
            $dp[$i][0] = $d1 + dfs($i + 1);
            $dp[$i][1] = $d2 + dfs($i + 2);
        }
        return min($dp[$i][0], $dp[$i][1]);
    }
    return 0;
}

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}


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

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

    vector<ll> a(N);

    ll sum = 0;
    ll tmp = 0;
    rep(i, N) {
        cin >> a[i];
        sum += a[i];
        if (i % 2 == 1) {
            tmp += a[i];
        }
    }

    vector<ll> x(N);
    x[0] = sum - 2 * tmp;

    for (int i = 1; i < N; i++) {
        x[i] = 2 * a[i-1] - x[i-1];
    }

    rep(i, N) {
        cout << x[i] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 2944
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <set>

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,j) FOR(i,0,j)

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

typedef unsigned long long ull;

int N, M;
int cost[110][110];

int prim(){
    int mincost[110], used[110];
    REP(i, 110){
        mincost[i] = INF;
        used[i] = 0;
    }

    mincost[0] = 0;
    
    int res = 0;
    while(1){
        int u = -1;
        
        REP(i, N){
            if(!used[i] && (u == -1 || mincost[u] > mincost[i])){u = i;}
        }

        if(u == -1){break;}

        used[u] = 1;
        res += mincost[u];

        REP(i, N){
            mincost[i] = std::min(mincost[i], cost[i][u]);
        }
    }

    return res;
}

int main(){
    while(std::cin >> N >> M, N){
        REP(i, 110){
            REP(j, 110){
                cost[i][j] = INF;
            }
        }

        REP(i, M){
            int to, from, co;
            std::cin >> to >> from >> co;

            cost[to][from] = co;
            cost[from][to] = co;
        }

        std::cout << prim() << std::endl;
    }
}

Measured memory_bytes: 1208
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
const int N=2e5+4;
int n;
ll a[N],b[N],m;
inline bool cmp(ll x,ll y) {
	return x>y;
}
inline bool ok(ll x) {
	ll temp=0;
	for (register int i=1;i<=n;++i) {
		ll cur=x/b[i];
		if (cur<a[i]) temp+=a[i]-cur;
		if (temp>m) return false;
	}
	return temp<=m;
}
inline ll find(ll l,ll r) {
	while (l<r) {
		ll mid=l+r>>1;
		if (ok(mid)) r=mid;
		else l=mid+1;
	}
	return r;
}
int main() {
	scanf("%d%lld",&n,&m);
	for (register int i=1;i<=n;++i) scanf("%d",&a[i]);
	for (register int i=1;i<=n;++i) scanf("%d",&b[i]);
	sort(a+1,a+n+1,cmp);
	sort(b+1,b+n+1);
	ll x=0,y=0;
	for (register int i=1;i<=n;++i) y=max(y,a[i]*b[i]);
	printf("%lld\n",find(x,y));
	return 0;
}

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

#define ios  ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
ll n;

int main() {
    ios;

    ll n;
    cin>>n;
    ll arr[n+2];
    for(ll i=1;i<=n;i++)
    {
        cin>>arr[i];
    }
    ll dp[n+2]={0};
    dp[n]=0;
    dp[n-1]=abs(arr[n-1]-arr[n]);
     for(ll i=n-2;i>=1;i--)
     {
         dp[i]=min((dp[i+1]+abs(arr[i]-arr[i+1])),(dp[i+2]+abs(arr[i+2]-arr[i])));
     }
     cout<<dp[1];
     return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,u,k,t;
	cin>>n;
	int a[n+1][n+1];
	memset(a,0,sizeof(a));
	for(int i=0;i<n;i++)
	{
		cin>>u>>k;
		for(int j=0;j<k;j++)
		{
			cin>>t;
			a[u][t]=1;
		}
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(j>1) cout<<" ";
			cout<<a[i][j];
		}
		cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3144
e,y = map(int,input().split())

if e == 0:
    if 1868 <= y <= 1911:
        x = y - 1867
        print("M"+str(x))
    elif  1912 <= y <= 1925:
        x = y - 1911
        print("T"+str(x))
    elif  1926 <= y <= 1988:
        x = y - 1925
        print("S"+str(x))
    else:
        x = y-1988
        print("H"+str(x))

if e == 1:
    print(1867 + y)

if e == 2:
    print(1911 + y)

if e == 3:
    print(1925 + y)

if e == 4:
    print(1988 + y)



Measured memory_bytes: 5596
#include<bits/stdc++.h>
#define For(i,l,r) for(int i = (l),i##end = (r);i <= i##end;i++)
#define Fordown(i,r,l) for(int i = (r),i##end = (l);i >= i##end;i--)
#define debug(x) cout << #x << " = " << x << endl

using namespace std;

typedef long long ll;

template <typename T> inline bool chkmin(T &x,T y) { return y < x ? x = y,1 : 0; }
template <typename T> inline bool chkmax(T &x,T y) { return x < y ? x = y,1 : 0; }

const int INF = 0x3f3f3f3f;
const int N = 1e5 + 10,mod = 1e9 + 7;

char str[N];
int cnt[N];

inline int read() {
	int x = 0,flag = 1;
	char ch = getchar();
	while(!isdigit(ch) && ch != '-')ch = getchar();
	if(ch == '-')flag = -1,ch = getchar();
	while(isdigit(ch))x = (x << 3) + (x << 1) + (ch - '0'),ch = getchar();
	return x * flag;
}

int main() {

	int n = read();
	scanf("%s",str + 1);
	For(i,1,n) cnt[str[i] - 'a']++;
	int ans = 1;
	For(i,0,25) ans = 1ll * ans * (cnt[i] + 1) % mod;
	printf("%d\n",(ans + mod - 1) % mod);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
    string S;
    cin >> S;
    for(int i = 0; i < S.size(); i++){
        S[i] = 'x';
    }
    cout << S;
    return 0;
}


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

#define REP(type, i, a, b) for( type i = a; i < b; i++ )
typedef long long ll;

using namespace std;

int main (void) {
    ll N, K;
    ll ans=0;
    ll h;
    scanf("%lld %lld", &N, &K);
    REP(ll,i,0,N){ 
        scanf("%lld", &h);
        if ( h >= K ) ans++;
    }
    printf("%lld\n", ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define ll long long
#define pb push_back
#define fi first
#define se second 
#define mp make_pair
#define int long long
signed main()
{
    IOS
    int n; cin>>n;
    int res = ((n)*(n-1))/2;
    cout<<res;  
    return 0;
}

Measured memory_bytes: 256
n = input()
t, a = map(int, input().split())

i = 0
d_min = 1000

for j, h in enumerate(map(int, input().split())):
  d = abs(t - h * 0.006 - a)
  if d < d_min:
    d_min = d
    i = j

else:
  print(i+1)

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

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

	vector<int> X1(N);
	vector<int> Y1(N);
	vector<int> D1(N);
	vector<int> X2(N);
	vector<int> Y2(N);
	vector<int> D2(N);

	for (int i = 0; i < N; i++){
		cin >> X1[i] >> Y1[i]>> D1[i]>> X2[i]>> Y2[i]>> D2[i];
	}
	
	//ソート用vector
	vector<int> X(2*N);
	vector<int> Y(2*N);
	vector<int> D(2*N);
	for (int i = 0; i < N; i++){
		X[2 * i]     = X1[i];
		X[2 * i + 1] = X2[i];
		Y[2 * i]     = Y1[i];
		Y[2 * i + 1] = Y2[i];
		D[2 * i]     = D1[i];
		D[2 * i + 1] = D2[i];
	}
	sort(X.begin(), X.end());
	sort(Y.begin(), Y.end());
	sort(D.begin(), D.end());

	long long int ans = 0;
	int kasanari;
	for (int i = 0; i < 2*N-1; i++){ //X
		for (int j = 0; j < 2*N-1; j++){ //Y
			for (int k = 0; k < 2*N-1; k++){ //D
				kasanari = 0;
				for (int l = 0; l < N; l++){ //実際の直方体
					if ((X1[l]<=X[i] && X[i+1] <= X2[l]) &&
						(Y1[l]<=Y[j] && Y[j+1] <= Y2[l]) &&
						(D1[l]<=D[k] && D[k+1] <= D2[l]))
						kasanari++;
				}
				if (kasanari >= K){
					ans += (long long int)(X[i + 1] - X[i]) * (Y[j + 1] - Y[j]) * (D[k + 1] - D[k]);
				}
			}
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1216
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <map>

typedef long long LL;
std::map<LL, int> S;

int main() {
  int n;
  scanf("%d", &n);
  LL ans = 0, s = 0;
  for (int i = 0, x; i < n; ++i) {
    ++S[s];
    scanf("%d", &x);
    ans += S[s += x];
  }
  printf("%lld\n", ans);
  return 0;
}


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

void solve() {
  ll n;
  cin >> n;
  vector<ll> v(n);
  rep(i,n) cin >> v[i];
  ll count = 0;
  ll m = abs(v[0]);
  rep(i,n) {
    m = min(m, abs(v[i]));
    if (v[i] == 0) {
      count = 0;
      break;
    } else if (v[i] < 0) count++;
  }
  count %= 2;
  ll ans = 0;
  rep(i,n) ans += abs(v[i]);
  if (count) ans -= (2 * m);
  cout << ans << endl;
}

int main() {
  solve();
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define ff first
#define ss second
using namespace std;
 
const int N = 1e6;
typedef pair <ll, ll> pii;
ll a[N];
 
int main() {
	ll n;
	cin >> n;
	ll ga, sa, ba, gb, sb, bb;
	cin >> ga >> sa >> ba >> gb >> sb >> bb;
	if(ga <= gb && sa <= sb && ba <= bb) {
		ll ans = n;
		for(ll i = 0; i <= (n / ga); i++) {
			for(ll j = 0; j <= (n / sa); j++) {
				ll t = ga * i + sa * j;
				if(t > n)
					break;
				t = n - t;
				t /= ba;
				ll k = n + (gb - ga) * i + (sb - sa) * j + (bb - ba) * t;
				ans = max(ans, k);
			}
		}
		cout << ans << endl;
		return 0;
	}
	if(ga >= gb && sa >= sb && ba >= bb) {
		swap(ga, gb);
		swap(sa, sb);
		swap(ba, bb);
		ll ans = n;
		for(ll i = 0; i <= (n / ga); i++) {
			for(ll j = 0; j <= (n / sa); j++) {
				ll t = ga * i + sa * j;
				if(t > n)
					break;
				t = n - t;
				t /= ba;
				ll k = n + (gb - ga) * i + (sb - sa) * j + (bb - ba) * t;
				ans = max(ans, k);
			}
		}
		cout << ans << endl;
		return 0;		
	}
	vector <pii> va, vb; 
	if(ga < gb)
		va.pb({ga, gb});
	else if(gb < ga)
		vb.pb({gb, ga});
	if(sa < sb)
		va.pb({sa, sb});
	else if(sb < sa)
		vb.pb({sb, sa});
	if(ba < bb)
		va.pb({ba, bb});
	else if(bb < ba)
		vb.pb({bb, ba});
	ll m = n;
	if(va.size() == 1) {
		ll t = n / va[0].ff;
		m += t * (va[0].ss - va[0].ff);
	}
	else if(va.size() == 2) {
		for(int i = 0; i <= n; i++) {
			ll t = i * va[0].ff;
			if(t > n)
				break;
			t = n - t;
			t /= va[1].ff;
			t = n + t * (va[1].ss - va[1].ff) + i * (va[0].ss - va[0].ff);
			m = max(m, t);
		}
	}
	n = m;
	swap(va, vb);

	if(va.size() == 1) {
		ll t = n / va[0].ff;
		m += t * (va[0].ss - va[0].ff);
	}
	else if(va.size() == 2) {
		for(int i = 0; i <= n; i++) {
			ll t = i * va[0].ff;
			if(t > n)
				break;
			t = n - t;
			t /= va[1].ff;
			t = n + t * (va[1].ss - va[1].ff) + i * (va[0].ss - va[0].ff);
			m = max(m, t);
		}
	}
	cout << m << endl;	
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
#define rep(i, begin, n) for (int i = begin; i < n; i++)
#define repe(i, begin, n) for (int i = begin; i <= n; i++)
#define repr(i, begin, n) for (int i = begin; i > begin - n; i--)
#define repre(i, begin, end) for (int i = begin; i >= end; i--)

const int inf = 1000000007;
const int MOD = 1000000007;
const long long INF = 1000000000000000007;

int N, M;
int p[101010];
string S[101010];
bool AC[101010];
int WA[101010];
int acnum;
int wanum;

int main()
{
    cin >> N >> M;
    rep(i, 0, M)
    {
        cin >> p[i] >> S[i];
        if (S[i] == "AC")
        {
            AC[p[i]] = true;
        }
        else
        {
            if (!AC[p[i]])
            {
                WA[p[i]]++;
            }
        }
    }

    repe(i, 1, N)
    {
        if (AC[i])
        {
            acnum++;
            wanum += WA[i];
        }
    }
    cout << acnum << " " << wanum << endl;
}


Measured memory_bytes: 6528
N,M=map(int,input().split())
a_list=[]
b_list=[]
for i in range(N):
    a,b=map(int,input().split())
    a_list.append(a)
    b_list.append(b)
    
c_list=[]
d_list=[]
for i in range(M):
    c,d=map(int,input().split())
    c_list.append(c)
    d_list.append(d)

for i in range(N):
    sum=1000000000
    for j in range(M):
        key=abs(a_list[i]-c_list[j])+abs(b_list[i]-d_list[j])
        if sum>key:
            ans=j+1
            sum=key
    print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <cmath>
#include <iomanip>
#include <bitset>
#include <string>
#include <stdlib.h>
using namespace std;
//cout <<  << endl;
typedef long long int ll;
typedef long double ld;

int main() {
    ll ans=1,n;
    cin >> n;
    for (ll i=1;i<=n;++i){
        ans*=i;
        ans%=1000000007;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
a = int(input()) # 500
b = int(input()) # 100
c = int(input()) # 50
x = int(input())

count = 0

for an in range(a+1):
    if 500 * an == x:
        count += 1
        break
    else:
        for bn in range(b+1):
            if 500 * an + 100 * bn == x:
                count += 1
                break
            else:
                for cn in range(c+1):
                    if 500 * an + 100 * bn + 50 * cn == x:
                        count += 1
                        break

print(count)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned int uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=998244353;
const int dx[4]={-1,0,1,0},dy[4]={0,-1,0,1};

int n,m;

int main(){
	cin>>n>>m;
	vi a(n,1);
	for(int i=0;i<m;i++){
		int k;
		cin>>k;
		for(int j=0;j<k;j++){
			int t;
			cin>>t;
			a[t-1]=0;
		}
	}
	int res=0;
	for(auto i:a) res+=i;
	cout<<res<<endl;
}

Measured memory_bytes: 3600
a,b,c=map(int,input().split())
i=0
l=[]
while True:
  i+=1
  m=(a*i-c)%b
  if m==0:
    print('YES')
    exit()
  if l.count(m):
    print('NO')
    exit()
  else:
    l.append(m)

Measured memory_bytes: 3060
#include<stdio.h>
#include<stdlib.h>
#define NIL -1

typedef struct node{

  int key;  
  struct node *p;
  struct node *r;
  struct node *l;
}Node; 

void insert(int);
void nodegene(Node *, int);
void print();
void in_p(Node *);
void pre_p(Node *);
 
Node *root = NULL;

int main(){

  char str[10];
  int i,n,m,l;
  Node *node;

  scanf("%d", &n);

  //scanf("%d", &l);
  //nodegene( root,l);

  for( i = 0; i < n; i++){

    scanf("%s", str);

    switch(str[0]){
    case 'i':
      scanf("%d",&m);
      insert(m);
      break;

    case 'p':
      print();
      break;
    }
  }
return 0;
}

void nodegene(Node *n,int num){
  n -> key = num;
  n -> p = NULL;
  n -> r = NULL;  
  n -> l = NULL;
}


void insert(int n){
 
  Node *p = malloc(sizeof(Node));
  Node *search;

  nodegene( p, n);

  if(root == NULL){
    root = p;
    return;
  }

  search = root;

  while (1) {
    if (p -> key < search -> key) {
      if (search -> l == NULL) {
	search -> l = p;
	break;
      } 
      else {
	search = search -> l;
      }
    } 
    else {
      if (search -> r == NULL) {
	search -> r = p;
	break;
      } 
      else {
	search = search -> r;
      }
    }
  }
  search = p;
 
}


void in_p(Node *n){
  
  if(n != NULL){
    in_p(n -> l);
    printf(" %d", n -> key);
    in_p(n -> r);
  }
}

void pre_p(Node *n){
  
  if(n != NULL){  
    printf(" %d", n -> key);
    pre_p(n -> l);
    pre_p(n -> r);
  }
}

void print(){

  in_p( root);
  printf("\n");  
  pre_p( root);
  printf("\n");
}

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

int dx[]={2,1,-1,-2,-2,-1,1,2};int dy[]={1,2,2,1,-1,-2,-2,-1};//Knight Direction

int main(){

    int n,ss,k=0,m=0;
    string s;

    cin>>n;

    getchar();

    cin>>s;
    ss = s.size();
    for(int i=0 ; i<ss; i++){
        if(s[i]=='I') k++;
        else k--;
        m = max(m,k);
    }

    cout<<m<<"\n";

}



Measured memory_bytes: 256
s = input()

i_flips = []
i = 0
for j in range(1, len(s)):
    if s[j] != s[i]:
        i_flips.append(j)
        i = j
# print(i_flips)

if len(i_flips) == 0:
    print(len(s))
else:
    ans = len(s)
    for i in i_flips:
        ans = min(ans, max(i, len(s)-i))
    print(ans)


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

int main() {
	int n;
	int ans = 0;
	cin >> n;
	vector<int> vec(n);
	for (int i = 0; i < n; i++) {
		cin >> vec.at(i);
	}
	bool flag = true;
	while (flag) {
		flag = false;
		for (int i = n - 1; i > 0; i--) {
			if (vec.at(i) < vec.at(i - 1)) {
				int t = vec.at(i);
				vec.at(i) = vec.at(i - 1);
				vec.at(i - 1) = t;
				ans++;
				flag = true;
			}
		}
	}
	for (int i = 0; i < n; i++) {
		cout << vec.at(i);
		if (i != n - 1) cout << ' ';
	}
	cout << endl;
	cout << ans << endl;
}


Measured memory_bytes: 3116
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, s, n) for (int i = (s); i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
int main() {
  int n, k, r, s, p;
  cin >> n >> k >> r >> s >> p;
  string t;
  cin >> t;
  for (int i = 0; i < n; i++) {
    if (i + k < n && t[i] == t[i + k]) {
      t[i + k] = '0';
    }
  }
  ll ans = 0;
  for (char c : t) {
    if (c == 'r')
      ans += p;
    else if (c == 's')
      ans += r;
    else if (c == 'p')
      ans += s;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3712
#include <iostream>
#include <fstream>
#include <algorithm>
#include <chrono>
#include <random>
#include <vector>
#include <string>
#include <cmath>
#include <bitset>
#include <list>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cassert>

#define sq(x) ((x) * (x))
#define err(x) cerr << "["#x"]  " << (x) << "\n";
#define errp(x) cerr << "["#x"]  {" << ((x).first) << ", " << ((x).second) << "}\n";
#define errv(x) {cerr << "["#x"]  [";for(const auto& ___ : (x)) cerr << ___ << ", "; cerr << "]\n";}
#define errvn(x, n) {cerr << "["#x"]  [";for(auto ___ = 0; ___ < (n); ++___) cerr << (x)[___] << ", "; cerr << "]\n";}
#define errf() cerr << "\n\n";

//#pragma GCC optimize("O3")
//#pragma GCC optimize("Ofast, unroll-loops", "omit-frame-pointer","inline")
//#pragma GCC option("arch=native","tune=native","no-zero-upper")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native,avx2")

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int getrnd(int l, int r) {
    return uniform_int_distribution<int>(l, r)(rng);
}

ll getrndll(ll l, ll r) {
    return uniform_int_distribution<ll>(l, r)(rng);
}

template <typename T1, typename T2>
inline bool relax(T1& a, const T2& b) {
    if (a > b) {
        a = b;
        return 1;
    }
    return 0;
}

template <typename T1, typename T2>
inline bool strain(T1& a, const T2& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}

// :::::::::::::::::::::::::::::::

void solve() {
    int n, a, b, c;
    cin >> n >> a >> b >> c;
    
    vector<string> s(n);
    for (int i = 0; i < n; ++i)
        cin >> s[i], s[i][0] -= 'A', s[i][1] -= 'A';
    
    vector<int> cnt = {a, b, c}, picks(n);
    for (int i = 0; i < n; ++i) {
//        errv(cnt);
        int f = s[i][0], t = s[i][1];
        if (cnt[f] == 0 && cnt[t] == 0) {
            cout << "No\n";
            return;
        }
        else if (cnt[f] == 0)
            ++cnt[f], --cnt[t], picks[i] = f;
        else if (cnt[t] == 0)
            ++cnt[t], --cnt[f], picks[i] = t;
        else if (cnt[t] == 1 && cnt[f] == 1) {
            if (i + 1 < n) {
                if (s[i + 1][0] == t || s[i + 1][1] == t)
                    ++cnt[t], --cnt[f], picks[i] = t;
                else
                    ++cnt[f], --cnt[t], picks[i] = f;
            }
            else
                ++cnt[t], --cnt[f], picks[i] = t;
        }
        else {
            if (cnt[t] > cnt[f])
                swap(t, f);
            ++cnt[t], --cnt[f], picks[i] = t;
        }
    }
    
    cout << "Yes\n";
    for (int i = 0; i < n; ++i)
        cout << char(picks[i] + 'A') << '\n';
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr); cout.tie(nullptr);
    srand(time(0));
    
    int t = 1;
//    cin >> t;
    while (t--)
        solve();
    
    return 0;
}



Measured memory_bytes: 6940
from heapq import heappop, heappush

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)

h = []
heappush(h, (-A[0]-B[0]-C[0], 0, 0, 0))
used = set()
result = []

for _ in range(K):
    sum, i, j, k = heappop(h)
    result.append(-sum)
    if i < X-1 and (i+1, j, k) not in used:
        heappush(h, (-A[i+1]-B[j]-C[k], i+1, j, k))
        used.add((i+1, j, k))
    if j < Y-1 and (i, j+1, k) not in used:
        heappush(h, (-A[i]-B[j+1]-C[k], i, j+1, k))
        used.add((i, j+1, k))
    if k < Z-1 and (i, j, k+1) not in used:
        heappush(h, (-A[i]-B[j]-C[k+1], i, j, k+1))
        used.add((i, j, k+1))

for v in result:
    print(v)


Measured memory_bytes: 5104