akhauriyash/Code-Regression huggingface dataset:
use proconio::{input, fastout};
use proconio::marker::{Chars};
use proconio::marker::Usize1;
use std::cmp::*;

macro_rules! debug { 
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

#[fastout]
fn main() {
    input!{
        n: usize,
        mut d: [usize;n],
        m: usize,
        mut t: [usize;m],
    }

    d.sort();
    t.sort();

    let mut point = 0;
    let mut ok: bool = true;
    if n<m {
        println!("NO");
        return;
    } else {
        for i in 0..m {
            while t[i]!=d[point] {
                if point==n-1 {
                    ok = false;
                    break;
                }
                point += 1;
            }
            if t[i]==d[point] {
                point += 1;
            }
            if ok==false {
                println!("NO");
                return;
            }
            // debug!(t[i]);
            // debug!(point);
        }
    }

    println!("YES");

    // let inf = 10_0000_0000 + 5;
    // let mut dist: Vec<usize> = vec![0;inf];

    // for i in 0..n {
    //     dist[d[i]] += 1;
    // }

    // for i in 0..m {
    //     if dist[t[i]] != 0 {
    //         dist[t[i]] -= 1;
    //     } else {
    //         println!("NO");
    //         return;
    //     }
    // }
    // println!("YES");
}


Measured memory_bytes: 9692
#include<iostream>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<limits>
#include<sstream>      

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;

const int inf = numeric_limits<int>::max() /4;
const ll linf = numeric_limits<ll>::max() /4;
const ull ulinf = numeric_limits<ull>::max()/4;
const double pi = acos(-1);
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
const int dx8[8]={-1,0,1,-1,1,-1,0,1};
const int dy8[8]={-1,-1,-1,0,0,1,1,1};

#define p_queue(i) priority_queue<i> 
#define rp_queue(i) priority_queue<i, vector<i>, greater<i>> 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define mod(i) ((i)%(ll)(1e9 + 7))
#define divm(a,b) (mod(a * modpow((ll)b,(ll)(1e9+5))))
#define rsort(a,b,c) sort(a, b, greater<c>())
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.end(), v.begin());
#define ft first
#define sd second
#define pb push_back
#define it insert
#define sz(x) ((int)(x).size())
#define lb(a,n,k) (lower_bound(a,a+n,k) - a) 
#define vlb(a,k)  (lower_bound(a.begin(),a.end(),k) - a.begin())
#define ub(a,n,k) (upper_bound(a,a+n,k) - a) 
#define vub(a,k)  (upper_bound(a.begin(),a.end(),k) - a.begin())
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return

ll modpow(ll i,ll j){ ll tmp=1; while(j){ if(j%2)tmp=mod(tmp*i);i=mod(i*i);j/=2;}return tmp;}
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }

vector<string> split(const string &str, char sep){
    vector<string> v;
    stringstream ss(str);
    string buffer;
    while( getline(ss, buffer, sep) ) {
        v.push_back(buffer);
    }
    return v;
}

//ll ncr[100][100];
//ll nCr(int n, int r){if(n==r) ret ncr[n][r] = 1; if(r==0) ret ncr[n][r] = 1; if(r==1) ret ncr[n][r] = n;if(ncr[n][r]) ret ncr[n][r]; ret ncr[n][r] = nCr(n-1,r) + nCr(n-1,r-1);}

//ll npr[100][100]={};
//ll nPr(int n,int r){if(npr[n][r])ret npr[n][r];if(r==0)ret npr[n][r] = 1;if(r==1)ret npr[n][r] = n;ret npr[n][r] = n * nPr(n-1,r-1);}

//ll nHr(int n,int r){ret nCr(n+r-1,r);}

///////////////////////////////////////////////////////////////////////////



int main(){
    int n;
    cin >> n;
    int a[100005] = {};
    rep(i,0,n)cin >> a[i];

    int cnt = 1;

    int f = 0;
    rep(i,1,n){
        if(f == 0){
            if(a[i-1] < a[i])f = 1;
            else if(a[i-1] > a[i])f = -1;
            
        }else if(f == 1){
            if(a[i-1] > a[i]){
                f = 0;
                cnt++;
            }
        }else{
            if(a[i-1] < a[i]){
                f = 0;
                cnt++;
            }
        }
        
    }

    P(cnt);
	return  0;
}

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

t = sum(a)//2

b = [0]*n

b[0]=sum(a[1::2])
b[1]=sum(a[2::2])

for i in range(2,n):
    b[i] =b[i-2]-a[i-1]+a[i-2]

for i in range(n):
    print((t-b[i])*2, end=' ')


Measured memory_bytes: 64100
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007
sys.setrecursionlimit(1000000)

#A
def A():
    s = S()
    a = s.count("a")
    b = s.count("b")
    c = 3-a-b
    if a&b&c:
        print("Yes")
    else:
        print("No")
#B
def B():
    a,b,k = LI()
    ans = []
    for i in range(a,min(a+k,b+1)):
        ans.append(i)
    for i in range(max(a,b-k+1),b+1):
        ans.append(i)
    ans = list(set(ans))
    ans.sort()
    for i in ans:
        print(i)

#C
def C():
    a,b,c = LI()
    ans = 0
    if a%2:
        if b%2:
            if not c%2:
                ans += 1
                a += 1
                b += 1
        else:
            ans += 1
            if not c%2:
                b += 1
                c += 1
            else:
                a += 1
                c += 1
    else:
        if b%2:
            ans += 1
            if not c%2:
                a += 1
                c += 1
            else:
                b += 1
                c += 1
        else:
            if c%2:
                ans += 1
                a += 1
                b += 1
    ans += (3*max(a,b,c)-a-b-c)//2
    print(ans)
#D
def D():
    q = I()
    for i in range(q):
        a,b = LI()
        x = int((a*b)**0.5)
        y = math.ceil((a*b)/x)-1
        ans = x+y-2
        if a==b:
            ans += 1
        print(ans)

#E
def E():
    s = S()
    f = {"N":0,"W":0,"S":0,"E":0}
    for i in s:
        f[i] = 1
    if f["N"]^f["S"]:
        print("No")
    elif f["W"]^f["E"]:
        print("No")
    else:
        print("Yes")
#F
def F():
    return

#G
def G():
    return

#H
def H():
    return

#Solve
if __name__ == "__main__":
    B()


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

int main() {
  long long N, A, B, C, D, E;
  cin >> N >> A >> B >> C >> D >> E;

  long long Neck = min({A, B, C, D, E});
  long long ans = 4;

  cout << ans + ((N + Neck - 1) / Neck) << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
using namespace std;

int main(){
    string a, b;
    cin >> a >> b;
    int n = stoi(a+b), flag = 0;

    for(int i=1;i<=1000;i++){
        if(i*i == n){
            cout << "Yes" << '\n';
            flag = 1;
        }
    }

    if(flag == 0)
        cout << "No" << '\n';
    return 0;
}

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

int main(){
    int n, m;
    cin >> n >> m;
    
    vector<vector<int>> graph(n);
    for(int i=0; i<m; i++){
        int s, t;
        cin >> s >> t;
        s -= 1;
        t -= 1;
        graph[s].push_back(t);
    }

    vector<double> dp(n);
    for(int i=n-2; i>=0; i--){
        double sum = 0;
        for(int v : graph[i]) sum += dp[v];
        sum /= (double)graph[i].size();
        dp[i] = sum + 1;
    }

    double ans = dp[0];
    for(int i=n-2; i>=0; i--){
        if(graph[i].size() == 1) continue;

        int block = graph[i][0];
        for(int v : graph[i]){
            if(dp[v] > dp[block]) block = v;
        }
        
        vector<double> dp(n);
        for(int j=n-2; j>=0; j--){
            double sum = 0;
            for(int v : graph[j]){
                if(j == i && v == block) continue;
                sum += dp[v];
            }
            if(j == i) sum /= (double)(graph[j].size() - 1);
            if(j != i) sum /= (double)graph[j].size();
            dp[j] = sum + 1;
        }
        ans = min(ans, dp[0]);
    }
    cout << fixed << setprecision(10) << ans << endl;
    return 0;
}

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

const int MAX_K = 1e5;
lint A[MAX_K+5];

int main(){
    int k; cin >> k;
    for(int i=0;i<k;i++) cin >> A[i];

    lint mn = 2, mx = 2;
    bool ok = true;
    for(int i=k-1;0<=i;i--){
        lint a = A[i];
        mn = (mn+a-1) / a * a;
        if(mx < a || mx < mn) ok = false;
        mx = mx / a * a + a - 1;
    }

    if(ok) cout << mn << ' ' << mx << endl;
    else cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 1024
n = int(input())
l = list(map(int, input().split()))
ret = 0

for i in range(n-2):
  for j in range(i+1, n-1):
    for k in range(j+1, n):
      if l[i] + l[j] > l[k] and l[j] + l[k] > l[i] and l[k] + l[i] > l[j]:
        if l[i] != l[j] and l[j] != l[k] and l[k] != l[i]:
          ret += 1

print(ret)

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

int main(){
    int n,k;
    vector<long long> a;
    cin >> n >> k;
    for(int i = 0;i < n;i++){
        int x;
        cin >> x;
        a.push_back(x);
    }

    /**/

    for(int i = k;i < n;i++){
        long long x = a[i - k] - a[i];
        if(x < 0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 4892
#include <iostream>
#include <queue>

using namespace std;

int main() {
	int n, r;
	while (cin >> n >> r) {
		queue<int> c;
		for (int i = 0; i < n; i++) {
			c.push(i);
		}
		for (int i = 0; i < r; i++) {
			queue<int> a;
			queue<int> b;
			for (int j = 0; j < (n/2); j++) {
				b.push(c.front());
				c.pop();
			}
			while (!c.empty()) {
				a.push(c.front());
				c.pop();
			}
			int d;
			cin >> d;
			while (!(a.empty() && b.empty())) {
				for (int i = 0; i < d; i++) {
					if (!a.empty()) {
						c.push(a.front());
						a.pop();
					} else {
						break;
					}
				}
				for (int i = 0; i < d; i++) {
					if (!b.empty()) {
						c.push(b.front());
						b.pop();
					} else {
						break;
					}
				}
			}
		}
		int k = c.front();
		c.pop();
		while (!c.empty()) {
			k = c.front();
			c.pop();
		}
		cout << k << endl;
	}
	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
#define SZ(x) ((int)(x).size())
typedef long long ll;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0); cout.setf(ios::fixed); cout.precision(20);
    int n, k; cin >> n >> k;
    vector<int> a(n);
    for (int &x : a) {
        cin >> x;
    }
    int res = 0;
    for (int left = 0; left <= min(n, k); left++) {
        for (int right = 0; right <= min(n - left, k); right++) {
            for (int removingNeg = 0; removingNeg <= min(n, k - left - right); removingNeg++) {
                vector<int> neg;
                int sum = 0;
                for (int i = 0; i < left; i++) {
                    sum += a[i];
                    if (a[i] < 0) {
                        neg.push_back(a[i]);
                    }
                }
                for (int j = n - 1; j > n - 1 - right && j > left; j--) {
                    sum += a[j];
                    if (a[j] < 0) {
                        neg.push_back(a[j]);
                    }
                }
                sort(neg.begin(), neg.end());
                for (int i = 0; i < min(SZ(neg), removingNeg); i++) {
                    sum -= neg[i];
                }
                res = max(res, sum);
            }
        }
    }
    cout << res << "\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct Fast {
    Fast() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(20);
    }
} fast;

long long mod = 1000000007;

long long div(long long a, long long b, long long c) { return b / c - (a - 1) / c; }

void print_binary(long long a) {
    for (int i = 31; i >= 0; i--) {
        cout << (a >> i & 1);
    }
    cout << endl;
}
long long modpow(long long m, long long n) {
    if (n == 0) return 1;
    if (n % 2 == 0) {
        long long t = modpow(m, n / 2);
        return t * t;
    } else {
        return modpow(m, n - 1) * m;
    }
}
void yes() {
    cout << "Yes" << endl;
    exit(0);
}
void no() {
    cout << "No" << endl;
    exit(0);
}

int main() {
    long long n, wrong = 0;
    cin >> n;
    vector<int> ps(n);
    vector<int> sorted(n);
    for (int i = 0; i < n; i++) {
        cin >> ps[i];
        sorted[i] = i + 1;
        if (ps[i] != sorted[i]) {
            wrong++;
        }
    }
    if (wrong > 2) {
        cout << "NO" << endl;
    } else {
        cout << "YES" << endl;
    }
}

Measured memory_bytes: 256
n = gets.to_i
as = (gets.chomp.split(" ").map(&:to_i)).sort.reverse

#偶数インデックスの合計
aliceTotal = as.each_with_index.inject(0) do |alice, (a, i)|
    if i.even?
        alice + a
    else
        alice
    end
end

#奇数インデックスの合計
bobTotal = as.each_with_index.inject(0) do |bob, (a, i)|
    if i.odd?
        bob + a
    else
        bob
    end
end

puts aliceTotal - bobTotal

Measured memory_bytes: 14328
#include "bits/stdc++.h"
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a),i##_len=(b);i<i##_len;++i)
#define MSVC_UNKO(x) x
#define rep(...) MSVC_UNKO(_overload3(__VA_ARGS__,repi,_rep,_rep)(__VA_ARGS__))
#define all(c) c.begin(),c.end()
#define mp make_pair
#define write(x) cout<<(x)<<"\n"
using namespace std; typedef long long ll;
typedef vector<int> vi; typedef vector<ll> vll; template<class T>using vv = vector<vector<T>>;
template<class T>vv<T> vvec(size_t n, size_t m, T v) { return vv<T>(n, vector<T>(m, v)); }
template<class T>bool chmax(T& a, const T& b) { return a < b ? a = b, 1 : 0; }
template<class T>bool chmin(T& a, const T& b) { return b < a ? a = b, 1 : 0; }
constexpr int INF = 1 << 28, MOD = 1e9 + 7; constexpr ll LINF = 1ll << 60;
struct aaa { aaa() { cin.tie(0); ios::sync_with_stdio(0); }; }aaaa;

ll mpow(ll x, int n) { ll y = 1; for (; n > 0; n /= 2) { y = n % 2 ? y * x % MOD : y; x = x * x % MOD; } return y; }
struct Combination {
    vector<ll> fact, ifact;
    Combination(int n) : fact(n + 1), ifact(n + 1) {
        fact[0] = 1;
        for (int i = 0; i < n; ++i) fact[i + 1] = fact[i] * (i + 1) % MOD;
        ifact[n] = mpow(fact[n], MOD - 2);
        for (int i = n; i > 0; --i) ifact[i - 1] = ifact[i] * i % MOD;
    }
    ll operator()(int n, int k) { return fact[n] * ifact[n - k] % MOD * ifact[k] % MOD; }
} C(2e5 + 5);

int N, M, K;

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

    ll ans = 0;
    rep(d, 1, N) {
        ans = (ans + (ll)d * (N - d) % MOD * M % MOD * M % MOD * C(N * M - 2, K - 2) % MOD) % MOD;
    }
    rep(d, 1, M) {
        ans = (ans + (ll)d * (M - d) % MOD * N % MOD * N % MOD * C(N * M - 2, K - 2) % MOD) % MOD;
    }
    write(ans);
}

Measured memory_bytes: 3328
#include <stdio.h>
#include <vector>
#include <algorithm>
#include <string>
#include <iostream>
#include <math.h>
#define rep(i,n) for(int i = 0; i <(n); i++)
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;

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

ll N, i, j, k, h, w, t;

int main(void) {
	bool flag = false;

	vector<string>s;
	string tmp;
	ll t, cnt = 0, sum = 0;

	scanf("%lld", &N);

	for (i = 0; i < N; i++) {
		cin >> tmp;
		sort(tmp.begin(),tmp.end());
		s.push_back(tmp);
	}

	sort(s.begin(), s.end());
	tmp = s.at(0);
	k = 1;

	for (i = 1; i < N; i++) {
		if (tmp == s.at(i)) {//解答候補と一致
			cnt += k;//１加算
			k++;
		}
		else {
			tmp = s.at(i);//変更
			k = 1;
		}
	}
	printf("%lld", cnt);

	return 0;
}

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

int N, A, B;
void solve() {
  int train = N * A;
  int taxi = B;

  if (train > taxi) {
    cout << taxi << endl;
  } else {
    cout << train << endl;
  }
}

int main() {
  cin >> N >> A >> B;
  solve();
}

Measured memory_bytes: 256
import java.util.*;
 
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
 
        long N = sc.nextLong();
        long M = sc.nextLong();

        if(N>=M / 2){
            System.out.println(M / 2);
        }
        else{
            long x = (M - 2 * N) / 4;
            System.out.println(x + N);
        }
    }
}

Measured memory_bytes: 21076
#include <iostream>
#include <vector>
#include <array>
#include <set>
#include <cmath>
#include <string>
#include <queue>
#include <list>
#include <stack>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cassert>
#include <cctype>  // std::islower(), std::isupper(), std::tolower, std::toupper
#include <iomanip> // std::std::setprecision(X)
#include <limits>  //std::numeric_limits<int>::max(), min()

typedef long long ll;

int main (void) {

  std::string S; std::cin >> S;
  std::string ans = "2018" + S.substr(4);
  std::cout << ans << std::endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
typedef long long ll;
ll N,cnt,ans;
string s;
vector <ll> V1;
vector <ll> V2;
int main() {
    cin >> N >> s;
    for(int x=0; x<N; x++) {
        if(s[x] == 'R') V1.push_back(x);
        if(s[x] == 'G') V2.push_back(x);
        if(s[x] == 'B') cnt++;
    }
    for(auto i : V1) {
        for(auto j : V2) {
            ll mi = 0;
            ll diff = (j-i) > 0 ? (j-i) : (i-j);
            if(i < j) {
                if(j+diff < N && s[j+diff] == 'B') mi++;
                if(i-diff >=0 && s[i-diff] == 'B') mi++;
                if(diff % 2 == 0) {
                    if(s[i + diff/2] == 'B') mi++;
                }
            }
            else {
                if(i+diff < N && s[i+diff] == 'B') mi++;
                if(j-diff >=0 && s[j-diff] == 'B') mi++;
                if(diff % 2 == 0) {
                    if(s[j + diff/2] == 'B') mi++;
                }
            }
            ans += cnt - mi;
        }
    }
    cout<<ans;
}

Measured memory_bytes: 3692
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#define REP(i,n) for(int i = 0;i < (n);i++)
#define pb push_back
using namespace std;
const int INF = 1e9;
typedef long long ll;
 
int main(){
  long long a,b,c,d,e,f;
  cin >> a >> b>> c >> d >> e >> f;
  
  long long sum = 0;
  vector <long long> A;
  for(int i = 0;i < f/a+1;i++){
    
    for(int j = 0;j < f/b+1;j++){
      
      sum = a*100*i+ b*100*j;
      if(sum <= f){
	A.push_back(sum);
      }
      else
	break;
    }
 
  }
  vector <long long> B;
  for(int i = 0;i < f/c+1;i++){
    
    for(int j = 0;j < f/d+1;j++){
    
      sum = c*i+ d*j;
      if(sum <= f){
	B.push_back(sum);
      }
      else
	break;
    }
 
  }
  //cout << "sfgsf" << endl; 
  /*REP(i,A.size()){
    cout << A[i] << "  ";
  }
  cout << endl;
  sort(B.begin(),B.end());
  REP(i,B.size()){
    cout << B[i] << "  ";
  }
  cout << endl;*/
  double res,E,bres = 0;
  ll sum1=0,sum2=0;
  
  REP(i,A.size()){
    REP(j,B.size()){
      
      if(A[i] != 0){
	res = (double)B[j]/(A[i]+B[j])*100;
	E = (double)e/(100+e)*100;
	//cout << res  << "  " << E << endl;
	if(A[i]+B[j] <= f && res <= E){
	  if(res >= bres){
	    sum1 = A[i]+B[j];
	    sum2 = B[j];
	    bres = res;
	  }
	}
      }
    }
  }
  if(sum1 == 0)
    sum1 = A[2];
  cout << sum1 << " " << sum2 << endl;
  return 0;
}


Measured memory_bytes: 2420
#include<stdio.h>

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

  if(a>b)
    printf("a > b\n");
  else if(a < b)
    printf("a < b\n");
  else
    printf("a == b\n");
  
  return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <vector>
#include <set>
#include <string>
#include <algorithm>
#include <math.h>
typedef long long ll;
using namespace std;

int main()
{
	string s, t;
	int cnt=0;
	cin >> s >> t;
	for (int i = 0; i < 3; i++)
	{
		if (s[i] == t[i]) cnt++;
	}
	cout << cnt;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    int N; cin >> N;
    vector<int> A(N), B(N), C(N);
    REP(i, 0, N) cin >> A[i];
    REP(i, 0, N) cin >> B[i];
    REP(i, 0, N) cin >> C[i];
    sort(A.begin(), A.end());
    sort(B.begin(), B.end());
    sort(C.begin(), C.end());

    ll ans = 0;
    REP(i, 0, N) {
        int a = distance(A.begin(), lower_bound(A.begin(), A.end(), B[i]) - 1) + 1;
        int c = C.size() - distance(C.begin(), upper_bound(C.begin(), C.end(), B[i]));
        ans += (ll)a * c;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408
n , k = map(int, input().split())
d = []
a = []

for i in range(k):
    d.append(int(input()))
    a.append(list(map(int, input().split())))

l = [0]*n

for i in a:
    for j in i:
        l[j-1] += 1

ans = 0
for i in l:
    if i == 0:
        ans += 1
print(ans)


Measured memory_bytes: 9184
#include<iostream>
#include<algorithm>

using namespace std;

int main  () {

    int i, j, k, l, n, p[101], m[101][101];

    cin >> n;

    for (i = 1; i <= n; i++) {
        cin >> p[i - 1] >> p[i];
    }

    for (i = 1; i<= n; i++) {
        m[i][i] = 0;
    }

    for (l = 2; l <= n; l++) {
        for (i = 1; i <= n - l+ 1; i++) {
            j = i + l - 1;
            m[i][j] = (1 << 21);

            for (k = i; k <=j - 1; k++) {
                m[i][j] = min (m[i][j], m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j]);
            }
        }
    }

    cout << m[1][n] << endl;

    return 0;

}

Measured memory_bytes: 3128
N = int(input())
A = list(map(int, input().split()))

# 体力最小のモンスターが他全員に攻撃することを繰り返す。ただし体力0にはしない
# 全員同じ体力になったら終了

while len(set(A)) >= 2:
    A = list(set(A))
    min_A = min(A)
    A = [x%min_A if x%min_A != 0 else min_A for x in A]
    
print(A[0])

Measured memory_bytes: 16992
#include <iostream>
using namespace std;
int main() {
cin.tie(0);
ios::sync_with_stdio(false);
int a, b;
cin >> a >> b;
if (a < b)
cout << "a < b\n";
else if (a > b)
cout << "a > b\n";
else
cout << "a == b\n";
}

Measured memory_bytes: 3164
dy = [-1, 0, 1, 0]
dx = [0, 1, 0, -1]
t = [[1, 2, 3], [4, 5, 6], [7, 8, 0]]


def get_heuri():
    res = 0
    for i in range(3):
        for j in range(3):
            if t[i][j] == 0:
                continue
            a = t[i][j] - 1
            res += abs(a // 3 - i) + abs(a % 3 - j)
    return res


def check(depth, prev, py, px, limit):
    heuri = get_heuri()
    if heuri + depth > limit:
        return False
    if heuri == 0:
        return True
    for i in range(4):
        if abs(i - prev) == 2:
            continue
        ny = py + dy[i]
        nx = px + dx[i]
        if ny < 0 or nx < 0 or ny >= 3 or nx >= 3:
            continue
        t[ny][nx], t[py][px] = t[py][px], t[ny][nx]
        if check(depth + 1, i, ny, nx, limit):
            return True
        t[ny][nx], t[py][px] = t[py][px], t[ny][nx]
    return False

for i in range(3):
    s = list(map(int, input().split()))
    for j in range(3):
        if s[j] == 0:
            py = i
            px = j
        t[i][j] = s[j]
limit = 0
while True:
    if check(0, 99, py, px, limit):
        print(limit)
        break
    limit += 1


Measured memory_bytes: 5612
#include<bits/stdc++.h>
///OK @rid
using namespace std;

/*****************MACRO*****/

#define ll long long
typedef pair<ll, ll> pll;
typedef pair<int, int> pii;

/*******CONSTANT***********/
#define INF (1<<30) //infinity value
#define EPS 1e-9
#define MOD 10000007
#define SIZ 1005
#define PI (acos(-1))

/// returns count of non-overlapping occurrences of 'sub' in 'str'
int countSubstring(const std::string& str, const std::string& sub)
{
    if (sub.length() == 0) return 0;
    int cnt = 0;
    for (size_t offset = str.find(sub); offset != std::string::npos;
	 offset = str.find(sub, offset + sub.length()))
    {
        ++cnt;
    }
    return cnt;
}


int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);
    cout.tie(0);
    int n;
    cin>>n;
    vector<string> s(n);
    int c1=0, c2=0, c3=0;
    int cnt=0;
    for(int i=0; i<n; i++){
        cin>>s[i];
        cnt+= countSubstring(s[i], "AB");
        ///cout<<"s[i]="<<s[i]<<"\t cnt="<<cnt<<"\n";
        if(s[i][0]=='B' && s[i][s[i].length()-1]=='A') c1++;
        else if(s[i][0]=='B') c2++;
        else if(s[i][s[i].length()-1]=='A') c3++;

    }
    //cout<<"c1="<<c1<<"\t c2="<<c2<<"\tc3="<<c3<<"\n";
    /******
    why is this wrong?
    suppose c1=c2=c3=0; cnt=0
    then cnt=-1 hoye jay (mane ek kome jay) :3
    but not possible
    (AB -1 bar pawa ki possible?? :3)

    if(c2==0 && c3==0) cnt+= (c1-1);
    else cnt+= (c1+min(c2,c3));

    */

    if(c1==0) cnt+= min(c2,c3);
    else if(c2==0 && c3==0) cnt+= (c1-1);
    else cnt+= (c1+min(c2,c3));
    cout<<cnt<<"\n";






    return 0;
}








/**********************************************************************************







*************************************************************************************/


Measured memory_bytes: 768
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class AtCoderA
{
    static void Main()
    {
        var sc = new Scanner();

        long n = sc.NextLong();

        int answer = int.MaxValue;

        long sqrt = (long)Math.Sqrt(n);

        for (long i = sqrt; i >= 1; i--)
        {
            long a = i;

            if (n % a != 0)
            {
                continue;
            }

            long b = n / a;

            int digitA = a.ToString().Length;

            int digitB = b.ToString().Length;

            answer = Math.Min(answer, Math.Max(digitA, digitB));
            break;
        }

        Console.WriteLine(answer);
    }

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            while (_index >= _line.Length)
            {
                _line = Console.ReadLine().Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            _line = Console.ReadLine().Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}

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

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

    vector<tuple<int, int>> a;
    for (int i = 0; i < n; i++)
    {
        int num;
        cin >> num;
        a.emplace_back(num, i);
    }

    sort(begin(a), end(a));
    for (int j = 0; j < n; j++)
    {
        cout << get<1>(a[j]) + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 1780
#include<iostream>

using namespace std;

int A, B, C;
int X;


int main(){
    cin >> A >> B >> C;
    cin >> X;

    int res=0;

    for(int i=0; i<A+1; ++i){
        for(int j=0; j<B+1; ++j){
            for(int k=0; k<C+1; ++k){
                if(500*i+100*j+50*k==X) ++res;
            }
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 256
n=int(input())
mod=10**9+7
ans=1
for i in range(n):
    ans*=10
    ans%=mod
tmp=1
for i in range(n):
    tmp*=9
    tmp%=mod
ans-=2*tmp
ans%=mod
tmp=1
for i in range(n):
    tmp*=8
    tmp%=mod
ans+=tmp
ans%=mod
print(ans)

Measured memory_bytes: 64240
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#include <cmath>
#include <map>
#include <set>
#define rep(i, m, n) for (int i = m; i < n; i++)
#define repr(i, n) for (int i = n; i >= 0; i--)
#define srep(i) for (int i = 0; i < s.size(); i++)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout << #x << ": " << x << endl
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
#define PI 3.14159265358979
    using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

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

int n, w;
int weight[105] = {}, value[105] = {};

int dp[105][10005] = {};

int main()
{
    int n,d;
    set<int> s;
    cin >> n;
    rep(i,0,n){
        cin>>d;
        s.insert(d);
    }
    cout<<s.size()<<endl;
}

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

int main(){
  int m;
  std::cin >> m;
  for (int l = 0; l < m; l++) {
    int n, k;
    std::cin >> n >> k;
    vector<int> x(n), ans;
    for (int i = 0; i < n; i++) std::cin >> x[i];
    for (int i = 0; i < n - 1; i++) {
      ans.push_back(x[i + 1] - x[i]);
    }
    // std::cout << "l:" << l << std::endl;
    sort(ans.begin(), ans.end());
    reverse(ans.begin(), ans.end());
    // if(not ans.empty())std::cout << ans[0] << std::endl;
    int sum = 0;
    for (int i = k - 1; i < ans.size(); i++) {
      sum += ans[i];
    }
    std::cout << sum << std::endl;
  }  
  return 0;
}



Measured memory_bytes: 4160
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <string>
#include <cmath>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <list>
#include <iostream>
#include <sstream>
#include <climits>
#include <cfloat>
#include <complex>

using namespace std;

int main()
{
	while (true)
	{
		int am[5], pm[5];
		for (int i = 0; i < 5; ++i)
			scanf("%d %d", am+i, pm+i);
		if (!(*am | *pm))
			break;

		int shop, m = 0;
		for (int i = 0; i < 5; ++i)
		{
			if (am[i] + pm[i] > m)
			{
				m = am[i] + pm[i];
				shop = i;
			}
		}
		printf("%c %d\n", 'A' + shop, m);
	}

	return 0;
}

Measured memory_bytes: 0
//coded by dsingh_24
#include<bits/stdc++.h>
#define ll          long long
#define pb          push_back
#define mp          make_pair
#define pll         pair<long long,long long>
#define vll          vector<long long>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (long long)x.size()
#define hell        1000000007
#define lbnd        lower_bound
#define ubnd        upper_bound
#define bs          binary_search
#define ios         ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
int main()
{
	ios
    string s;
    cin>>s;
    ll t=s.size();
    cout<<s[0]<<t-2<<s[t-1];
	return 0;
}


Measured memory_bytes: 256
def func(k, a, b):
    if b > a + 2 and k >= a - 1:
            print(a + (b - a) * ((k - a + 1) // 2)
                  + (k - a + 1) % 2)
    else:
        print(1 + k)
#func(4, 2, 6)
#func(7, 3, 4)
#func(314159265, 35897932, 384626433)
k, a, b = [int(i) for i in input().split()]
func(k, a, b)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
#define sz(x) ((int)(x).size())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
#define MEMSET(v, h) memset((v), h, sizeof(v))
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 pb push_back
#define mp make_pair
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll INF = 1LL<<60;
 
int main() {
	ll n,k;
  	cin >> n >> k;
  	vector<ll> h(n);
  	rep(i,n){
      cin >> h[i];
    }
  	ll ans = INF;
  	sort(all(h));
  	rep(i, n - k + 1){
      chmin(ans, h[i + k - 1] - h[i]);
    }
    
  	cout << ans << endl;
}

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

int main() 
{
    long N;
    cin>>N;
    vector<long>A(N);
 
    for (int i = 0; i < N; i++)
    {
       cin>>A[i];
    }   
    
    vector<long>Kane(N);
    Kane[0]=1000;
    for (int i = 1; i < N; i++)
    {
        Kane[i]=Kane[i-1];
        for (int j = 0; j < i; j++)
        {
            long s=Kane[j]/A[j];
            long mouke=Kane[j]+(A[i]-A[i-1])*s;
            Kane[i]=max(Kane[i],mouke);
        }
        
        
    }
    
    cout<<Kane.back()<<endl;
    
    return 0;
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
string t;
int main() {
  cin >> t;
  if(t.size() == 1){
    t.at(0) = 'D';
    cout << t << endl;
    return 0;
  }
  if(t.at(0) == '?' && (t.at(1) == '?' || t.at(1) == 'D')){
    t.at(0) = 'P';
  }
  else if(t.at(0) == '?' && t.at(1) == 'P'){
    t.at(0) = 'D';
  }
  for(int i = 1;i<t.size()-1;i++){
    if(t.at(i-1) == 'P' && t.at(i) == '?'){
      t.at(i) = 'D';
    }
    else if(t.at(i-1) == 'D' && t.at(i) == '?' && t.at(i+1) != 'P'){
      t.at(i) = 'P';
    }
    else if(t.at(i-1) == 'D' && t.at(i) == '?' && t.at(i+1) == 'P'){
      t.at(i) = 'D';
    }
  }
  if(t.at(t.size()-1) == '?'){
    t.at(t.size()-1) = 'D';
  }
  cout << t << endl;
  return 0;
}

Measured memory_bytes: 3744
#include<bits/stdc++.h>
using namespace std;
map<string,int> d; 
string a[1000010];
set<string> q;
int n,j,maxn;
int main() {
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		string x;
		cin>>x;
		if(q.count(x)==0) a[++j]=x;
		q.insert(a[j]);
		d[x]++;
		maxn=max(d[x],maxn);
	}
	sort(a+1,a+j+1);
	for(int i=1;i<=j;i++){
		if(d[a[i]]==maxn){
			cout<<a[i]<<endl;
		}
	}
	return 0;
}

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

using namespace std;
int main() {
    int x, y;
    cin >> x >> y;

    if(x < y) {
        int tmp = x;
        x = y;
        y = tmp;
    }
    int m = 0;    
    while(y > 0) {
        m = x % y;
        x = y;
        y = m;
    }
    
    cout << x << endl;
}
    



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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define all(x) begin(x), end(x)
#define sz(x) (int)(x).size()
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;

template<typename H> bool chmin(H& v1, const H v2) { if (v1 > v2) { v1 = v2; return true; } return false; }
template<typename H> bool chmax(H& v1, const H v2) { if (v1 < v2) { v1 = v2; return true; } return false; }
template<typename H> void read(H& head) { cin >> head; }
template<typename H, typename ...T> void read(H& head, T& ...tail) { cin >> head; read(tail...); }
template<typename H> void write(H head) { cout << head << '\n'; }
template<typename H, typename ...T> void write(H head, T ...tail) { cout << head << " "; write(tail...); }
template<typename ...T> void die(T ...tok) { write(tok...); exit(0); }

int main() {
	cin.tie(0)->sync_with_stdio(0);
	cin.exceptions(cin.failbit);

	int n, k; read(n, k);
	vector<int> v(n);

	rep(i, 0, n) read(v[i]);

	ll ans = 0;
	rep(i, 0, min(n, k) + 1) {
		int p = k - i; // put back
		rep(j, 0, i + 1) {
			int left = j, right = i - j;
			multiset<int> m;
			rep(k, 0, left) m.insert(v[k]);
			rep(k, 0, right) m.insert(v[n - 1 - k]);
			rep(k, 0, p) if (m.size() && *m.begin() < 0) m.erase(m.begin());
			ll lans = 0;
			for (int h : m) lans += h;
			chmax(ans, lans);
		}
	}
	die(ans);
}


Measured memory_bytes: 256
let (a, b) = Scanf.scanf "%d %d\n" @@ fun a b -> (a, b)

let rec gcd = function
  | (x, 0) -> x
  | (x, y) -> gcd (y, x mod y)

let lcm (x, y) = x * (y / gcd (x, y))

let () = print_int (lcm (a, b))

Measured memory_bytes: 384
#include<stdio.h>

int main(){
  int k;
  for(;scanf("%d",&k)&&k;){
    int t=0;
    for(int i=0;i<k*(k-1)/2;++i){
      int v;scanf("%d",&v);t+=v;
    }
    printf("%d\n",t/(k-1));
  }
}



Measured memory_bytes: 2572
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii =  pair<int, int>;
using pll =  pair<long long, long long>;
constexpr char ln =  '\n';
constexpr long long MOD = 1000000007LL;
constexpr long long INF = 1000000009LL;
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
#define fo(i,j,n) for (int i=(j); i < (n); i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }


int main() {
    string s; cin >> s;
    int dp[13][100001];

    rep(i, 13){
        rep(j, 100001){
            dp[i][j] = 0;
        }
    }
    dp[0][0] = 1;

    rep(i, s.size()){
        rep(j, 13){
            if(s[i] != '?'){
                int n = s[i] - '0';
                int mod = (j*10 + n) % 13;
                dp[mod][i+1] = (dp[mod][i+1] + dp[j][i]) % MOD;
            }else{
                rep(k, 10){
                    int mod = (j*10 + k) % 13;
                    dp[mod][i+1] = (dp[mod][i+1] + dp[j][i]) % MOD;
                }
            }
        }
    }
    cout << dp[5][s.size()] << ln;
}

Measured memory_bytes: 5504
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Linq.Expressions;
using System.Security.Principal;
using System.Text;
class Simple {
    private int N, Y;
    void Solve() {
        //input
        N = io.Int;
        Y = io.Int;
        //cal
        Func <int, int, int, int> otoshidama = (int x, int y, int z) =>
            10000 * x + 5000 * y + 1000 * z;
        for(int i = 0; i <= N; ++i) {
            for(int j = 0; i + j <= N; ++j) {
                int k = N - i - j;
                if(otoshidama(i, j, k) == Y) {
                    Console.WriteLine(i + " " + j + " " + k); 
                    return;
                }
            }
        }
        Console.WriteLine(-1 + " " + -1 + " " + -1); 
    }
    SimpleIO io = new SimpleIO();
    public static void Main(string[] args) { new Simple().Stream(); }
    void Stream() {
        Solve();
        io.writeFlush();
    }
}
class SimpleIO {
    string[] nextBuffer;
    int BufferCnt;
    char[] cs = new char[] {' '};
    StreamWriter sw = new StreamWriter(Console.OpenStandardOutput()) {AutoFlush = false};
    public SimpleIO() {
        nextBuffer = new string[0];
        BufferCnt = 0;
        Console.SetOut(sw);
    }
    public string Next() {
        if(BufferCnt < nextBuffer.Length) return nextBuffer[BufferCnt++];
        string st = Console.ReadLine();
        while(st == "") st = Console.ReadLine();
        nextBuffer = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        BufferCnt = 0;
        return nextBuffer[BufferCnt++];
    }
    public string String => Next();
    public char Char => char.Parse(String);
    public int Int => int.Parse(String);
    public long Long => long.Parse(String);
    public double Double => double.Parse(String);
    public void writeFlush() { Console.Out.Flush(); }
}

Measured memory_bytes: 13140
use std::io;
use std::cmp;
use std::collections::BinaryHeap;
use std::collections::HashMap;

fn read_line() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn get_min(q: u64, s: u64, t:u64) -> u64 {
    if s <= q && t <= q {
        q - cmp::min(s, t)
    } else if s > q && t <= q {
        let sq = s - q;
        let tq = q - t;
        cmp::min(sq + 2 * tq, 2 * sq + tq)
    } else if s <= q && t > q {
        let sq = q - s;
        let tq = t - q;
        cmp::min(sq + 2 * tq, 2 * sq + tq)
    } else {
        cmp::max(s, t) - q
    }
}

fn main() {
    let line: Vec<usize> = read_line().split_whitespace().map(|s| s.parse().unwrap()).collect();
    
    let a = line[0];
    let b = line[1];
    let q = line[2];

    let mut s = Vec::with_capacity(a);
    for i in 0..a {
        let val: u64 = read_line().trim().parse().unwrap();
        s.push(val);
    }
    let mut t = Vec::with_capacity(b);
    for i in 0..b {
        let val: u64 = read_line().trim().parse().unwrap();
        t.push(val);
    }

    for i in 0..q {
        let query:u64 = read_line().trim().parse().unwrap();
        let mut low = 0;
        let mut high = a;
        while high - low > 1 {
            let mid = (high + low) / 2;
            if s[mid] <= query {
                low = mid;
            } else {
                high = mid;
            }
        }
        let si = low;
        let mut low = 0;
        let mut high = b;
        while high - low > 1 {
            let mid = (high + low) / 2;
            if t[mid] <= query {
                low = mid;
            } else {
                high = mid;
            }
        }
        let ti = low;
        let mut ans = query + s[si] + t[ti];
        for sj in si..cmp::min(si+3, a) {
            for tj in ti..cmp::min(ti+3, b) {
                ans = cmp::min(ans, get_min(query, s[sj], t[tj]));
            }
        }

        println!("{}", ans);
    }
}


Measured memory_bytes: 7420
#include<stdio.h>
#include<algorithm>
using namespace std;
int w[110], S, n;
int main(){
    int i;
    scanf("%d%d",&S,&n);
    for(i=1;i<=n;i++)scanf("%d",&w[i]);
    sort(w+1,w+n+1);
    printf("%d\n",max(0,w[n]*2-S-1));
}

Measured memory_bytes: 128
n=int(input())
l=list(map(int,input().split()))
nOdd=len(l)%2==1
if nOdd:
    num=[x for x in range(len(l)) if n%2==0]
else:
    num=[x for x in range(len(l)) if n%2!=0]
dic={}
for i in num:
    dic[i]=0
for i in l:
    dic.setdefault(i,0)
    dic[i]+=1
for i,c in dic.items():
    if i==0 and nOdd:
        if c!=1:
            print(0)
            exit()
    elif i==0 and not(nOdd):
        print(0)
        exit()
    elif c!=2:
        print(0)
        exit()
    

        
       

print(pow(2, len(l)//2) % 1000000007)

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

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

    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k <= a + b)
        cout << (min(k, a)) << endl;
    else
        cout << (a - min(c, k - a - b)) << endl;

    return 0;
}

Measured memory_bytes: 3640
#include <cstdio>
#include <iostream>
#include <algorithm>
#define N 80005
using namespace std;
int n,r,m;int d[402][402],a[N],b[N];
int main ()
{
	scanf ("%d%d%d",&n,&m,&r);
	for (int i=1;i<=n;++i)
		for (int j=1;j<=n;++j) i^j?d[i][j]=1e9:0;
	for (int i=1;i<=r;++i) scanf ("%d",&a[i]),b[i]=r-i+1;
	for (int i=1,x,y,w;i<=m;++i)
		scanf ("%d%d%d",&x,&y,&w),d[x][y]=d[y][x]=w;
	for (int k=1;k<=n;k++)
		for (int i=1;i<=n;i++) if (i^k)
			for (int j=1;j<=n;j++) if (i^j && k^j) d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
	int g=1,ans=1e9;
	for (int i=1;i<=r;i++) g=g*i;
	for (int i=1;i<=g;i++)
	{
		int u=0;
		next_permutation (b+1,b+r+1);
		for (int j=2;j<=r;j++) u+=d[a[b[j-1]]][a[b[j]]];
		ans=min(ans,u);
	}
	cout<<ans<<endl;
	return 0; 
}

Measured memory_bytes: 512
n = int(input())
a = list(map(int, input().split()))
a_min = 0
minus_count = 0
for i in a:
    if i < 0:
        minus_count += 1
a = [abs(e) for e in a]
if minus_count % 2 != 0:
    a_min = a.pop(a.index(min(a)))
ans = sum(a) - a_min
print(ans)

Measured memory_bytes: 14332
s = input()
head = 0
dreameraser = ["dream","dreamer","erase","eraser"]
for i in range(len(s)):
    for word in dreameraser:
        head = len(s) - len(word)
        cut = s[head:head+len(word)]
#        print(cut)
        if cut in dreameraser:
            s = s[0:head]
if s == "":
    print("YES")
else:
    print("NO")



Measured memory_bytes: 3188
N, M = map(int, input().split())
Light = []
for _ in range(M):
    Tmp = list(map(int, input().split()))
    Tmp.pop(0)
    Light.append(set(Tmp))
P = list(map(int, input().split()))

import itertools
bit = list(itertools.product(['On', 'Off'], repeat=N))
ans = [0 for _ in range(2**N)]

for idx in range(M):
    light = Light[idx]
    p = P[idx]
    for j, switchs in enumerate(bit):
        cnt = 0
        for l in light:
            if switchs[l-1] == 'On':
                cnt += 1
        if cnt % 2 == p:
            ans[j] += 1
print(ans.count(M))

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
int main(){
  int flag=0;
  vector<int> c(9);
  for(int i=0;i<9;i++)cin>>c.at(i);
  if(c[0]-c[1]==c[3]-c[4] && c[3]-c[4]==c[6]-c[7] && c[1]-c[2]==c[4]-c[5] && c[4]-c[5]==c[7]-c[8] &&
     c[0]-c[3]==c[1]-c[4] && c[1]-c[4]==c[2]-c[5] && c[3]-c[6]==c[4]-c[7] && c[4]-c[7]==c[5]-c[8])flag++;
  if(flag==1)cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MAX_INT 2100000000
#define rep(i,n) for (i=1;i<=(n);++i)
using namespace std;
typedef long long int ll;
#ifdef COMPILE_IN_VCPP
#include <windows.h>
HWND GetConsoleHwnd(void)
{
#define MY_BUFSIZE 1024 // Buffer size for console window titles.
	HWND hwndFound;         // This is what is returned to the caller.
	char pszNewWindowTitle[MY_BUFSIZE]; // Contains fabricated// WindowTitle.
	char pszOldWindowTitle[MY_BUFSIZE]; // Contains original// WindowTitle.
	ULARGE_INTEGER nt;
	nt.QuadPart = GetTickCount64();
	GetConsoleTitle(pszOldWindowTitle, MY_BUFSIZE);
	wsprintf(pszNewWindowTitle, "%d%d/%d", nt.HighPart, nt.LowPart, GetCurrentProcessId());
	SetConsoleTitle(pszNewWindowTitle);
	Sleep(40);
	hwndFound = FindWindow(NULL, pszNewWindowTitle);
	SetConsoleTitle(pszOldWindowTitle);
	return(hwndFound);
}
#endif
int mod = 1e9 + 7;
int main()
{
	int a, b;
	cin >> a >> b;
	if ((a+ b) % 2) cout << "IMPOSSIBLE" << endl;
	else cout << (a + b) / 2 << endl;
}


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

using namespace std;
using ll = long long int;

template<typename T>
constexpr T Inf = numeric_limits<T>::max() / 1024;

ll Solve(const vector<ll> &a, int index, int skip, vector<vector<ll>> &memo)
{
	if (index + (1 + a.size() % 2 - skip) >= a.size())
	{
		return 0;
	}

	if (memo[index][skip] != -Inf<ll>)
	{
		return memo[index][skip];
	}

	ll ans = Solve(a, index + 2, skip, memo) + a[index];
	if (skip < 1 + a.size() % 2)
	{
		ans = max(ans, Solve(a, index + 1, skip + 1, memo));
	}

	return memo[index][skip] = ans;
}

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

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

	vector<vector<ll>> memo(n + 5, vector<ll>(5, -Inf<ll>));
	ll ans = Solve(A, 0, 0, memo);

	cout << ans << endl;
}

Measured memory_bytes: 26756
#include<bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> piii;
int r,c,dr[]={0,0,-1,1},dc[]={-1,1,0,0};
vector<pii> black;
const int MAXN=1005;
bool visited[MAXN][MAXN];
char a[MAXN][MAXN];

bool border(int x,int y){
	return x>=1 && x<=r && y>=1 && y<=c;
}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	cin >> r >> c;
	for(int i=1;i<=r;i++){
		for(int j=1;j<=c;j++){
			cin >> a[i][j];
			if(a[i][j]=='#')black.push_back({i,j});
		}
	}
	queue<piii> Q;
	memset(visited,0,sizeof(visited));
	for(auto isi : black){
		Q.push({0,{isi.first,isi.second}});
		visited[isi.first][isi.second]=true;
	}
	int ans=-1;
	while(!Q.empty()){
		piii now=Q.front();
		ans=max(ans,now.first);
		Q.pop();
		for(int i=0;i<4;i++){
			int xnow=now.second.first+dr[i],ynow=now.second.second+dc[i];
			if(!visited[xnow][ynow] && border(xnow,ynow) && a[xnow][ynow]=='.'){
				visited[xnow][ynow]=true;
				Q.push({now.first+1,{xnow,ynow}});
			}
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 22248