akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
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; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    int n, m;
    cin >> n >> m;
    vector<int> s(m), c(m);
    REP(i, m) {
        cin >> s[i] >> c[i];
        s[i]--;
    }

    for(int i = 0; i < 1000; i++) {
        
        string t = to_string(i);
        if (t.length() < n) continue;
        
        bool ok = true;
        for(int j = 0; j < m; j++) {
            // cout << t[s[j]] << " " << c[j] << endl;
            if ((t[s[j]]-'0')!= c[j]) ok = false;
        }

        if (ok) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}

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

using namespace std;
typedef long long int ll;

#define SP(x) setprecision((int)x)
#define ALL(v) v.begin(),v.end()

// 約数の列挙O(sqrt(n))
vector<ll> divisor (ll n) {
    vector<ll> res;
    for (ll i = 1; i * i <= n; i++)
    {
        if (n % i == 0) {
            res.push_back(i);
            if (i * i != n) res.push_back(n / i);
        }
    }
    return res;
}

bool is_prime (ll n) {
    for (ll i = 2; i * i <= n; i++)
    {
        if (n % i == 0) return false;
    }
    return n != 1;
}

int main(int argc, char const *argv[])
{
    ll a, b;
    cin>>a>>b;
    
    vector<ll> v_a = divisor(a), v_b=divisor(b);

    // sort(ALL(v_a));
    // sort(ALL(v_b));
    
    set<ll> s;

    for (ll i = 0; i < v_a.size(); i++)
    {
        // cout << v_a[i] << endl;
        if (b % v_a[i] == 0)
        {
            s.insert(v_a[i]);
        }
    }
    // cout << endl;
    for (ll i = 0; i < v_b.size(); i++)
    {
        // cout << v_b[i] << endl;
        if (a % v_b[i] == 0)
        {
            s.insert(v_b[i]);
        }
    }

    ll ans = 0;

    for (auto p : s)
    {
        if(p==1 || is_prime(p)){
            ans++;
        }
    }

    cout << ans << endl;
}

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

using namespace std;

#define rep(i, n) for (int i = 0; i < (int)n; ++i)
#define REP(i, a, b) for (int i = (int)a; i < (int)b; ++i)
#define each(i,c) for(__typeof((c).begin()) i = (c).begin(); i != (c).end(); ++i)
#define all(v) v.begin(), v.end()
#define mset(a, n) memset(a, n, sizeof(a))

typedef long long ll;

const int INF = 1000000000;
const int MOD = 1000000007;

int main () {
    string N; cin >> N;
    if (N[0] == '9' || N[1] == '9')
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

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

using namespace std;

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

const ll INF=1e15;

ll n;
string s;
vector<ll> ans;

void dfs(ll num,ll cnt,ll sum){
    if(cnt==n){
        ans.push_back(sum+num);
        //cout << sum+num << endl;
        return ;
    }
    dfs(num*10+(ll)(s[cnt]-'0'),cnt+1,sum);//+を入れないとき
    dfs((ll)(s[cnt]-'0'),cnt+1,sum+num);
}

int main(){
    cin>> s;
    n=s.length();
    //cout << n << endl;
    dfs(0LL,0LL,0LL);
    ll ans_sum=0;
    for(auto x:ans){
        //cout << x << endl;
        ans_sum+=x;
    }
    cout << ans_sum/2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

void scanfone(char *c)
{
	while(scanf("%c",c))
	{
		if(*c!=' '&&*c!='\n'){break;}
		
	}
}

int main()
{
	int i,j;
	
	int n;
	char data[2][100];
	
	
	int m;
	char c;
	
	while(scanf("%d",&n)&&n!=0)
	{
		/*data read*/
		for(i=0;i<n;++i)
		{
			for(j=0;j<2;j++)
			{
				scanfone(&data[j][i]);
			}
		}
		/*change ward*/
		scanf("%d",&m);
		
		for(i=0;i<m;++i)
		{
			scanfone(&c);
			for(j=0;j<n;++j)
			{
				if(c==data[0][j])
				{
					c=data[1][j];
					break;
				}
			}
			printf("%c",c);
		}
		printf("\n");
	}	
	return 0;
}

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

struct line { double p, d; ll n; };

ll N, A[100000], B[100000], C[100000];

template<typename T> class BinaryIndexedTree {
  vector<T> vec;
  const ll n;

public:
  BinaryIndexedTree(T _n) : vec(_n + 1), n(_n) {}

  T query(ll x) {
    T ret = 0;
    for(ll i = x; i > 0; i -= i & (-i)) ret += vec[i];
    return ret;
  }

  void update(ll x, T k) {
    for(ll i = x; i <= n; i += i & (-i)) vec[i] += k;
  }
};

bool ok(double x, ll k) {
  line l[100000];
  REP(i, 0, N) l[i] = (line) { (double) (C[i] - A[i] * x) / B[i], (double) -A[i] / B[i], 0 };

  sort(l, l + N, [](const line &a, const line &b) { return a.d < b.d; });
  REP(i, 0, N) l[i].n = i + 1;
  sort(l, l + N, [](const line &a, const line &b) { return a.p < b.p; });

  BinaryIndexedTree<ll> bit(100000);
  ll cnt = 0;
  REP(i, 0, N) {
    cnt += i - bit.query(l[i].n);
    bit.update(l[i].n, 1);
  }

  return N * (N - 1) / 2 - cnt < k;
}

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> A[i] >> B[i] >> C[i];

  ll n = N * (N - 1) / 2;
  ll k = n / 2 + (n % 2 ? 1 : 0);

  double lx = -1e10, hx = 1e10;
  REP(i, 0, 200) {
    double mx = (lx + hx) / 2;
    if(ok(mx, k)) lx = mx;
    else hx = mx;
  }

  REP(i, 0, N) swap(A[i], B[i]);

  double ly = -1e10, hy = 1e10;
  REP(i, 0, 200) {
    double my = (ly + hy) / 2;
    if(ok(my, k)) ly = my;
    else hy = my;
  }

  printf("%.15lf %.15lf\n", hx, hy);
}


Measured memory_bytes: 4352
// Author: Shusuke Ueda
// AOJ NTL_1_C (Least Common Multiple)

#include <iostream>

namespace nt {
    template <typename T>
    T gcd(T m, T n) {
        return n == 0? m: gcd(n, m % n);
    }

    template <typename T>
    T lcm(T m, T n) {
        return m / gcd(m, n) * n;
    }
}

int main() {
    int n;
    std::cin >> n;
    int ans = 1;
    for (int i = 0; i < n; i++) {
        int a;
        std::cin >> a;
        ans = nt::lcm(ans, a);
    }

    std::cout << ans << std::endl;

    return 0;
}


Measured memory_bytes: 3112
#[allow(unused_macros)]
macro_rules! input {
  ($($r:tt)*) => {
    let stdin = std::io::stdin();
    let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
    let mut next = move || -> String{
      bytes
        .by_ref()
        .map(|r|r.unwrap() as char)
        .skip_while(|c|c.is_whitespace())
        .take_while(|c|!c.is_whitespace())
        .collect()
    };
    input_inner!{next, $($r)*}
  };
}

#[allow(unused_macros)]
macro_rules! input_inner {
  ($next:expr) => {};
  ($next:expr, ) => {};

  ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
    #[allow(unused_mut)]
    let mut $var = read_value!($next, $t);
    input_inner!{$next $($r)*}
  };
}

#[allow(unused_macros)]
macro_rules! read_value {
  ($next:expr, ( $($t:tt),* )) => {
    ( $(read_value!($next, $t)),* )
  };

  ($next:expr, [ $t:tt ; $len:expr ]) => {
    (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
  };

  ($next:expr, chars) => {
    read_value!($next, String).chars().collect::<Vec<char>>()
  };

  ($next:expr, usize1) => {
    read_value!($next, usize) - 1
  };

  ($next:expr, [ $t:tt ]) => {{
    let len = read_value!($next, usize);
    (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
  }};

  ($next:expr, $t:ty) => {
    $next().parse::<$t>().expect("Parse error")
  };
}

fn main() {
  let stack_size = 104_857_600;
  let thd = std::thread::Builder::new().stack_size(stack_size);
  thd.spawn(|| work()).unwrap().join().unwrap();
}

fn work() {
  input! {
    n: usize,
    a: [u32; n],
  };
  let s: u32 = a.iter().sum();
  let mut ans: u32 = 0;
  for x in a.iter() {
    ans += x * (s - x);
  }
  println!("{}", ans / 2);
}


Measured memory_bytes: 8572
from heapq import*
(N, M), *t = [map(int, s.split()) for s in open(0)]
q, z = [], 0
v = [[] for _ in [None] * 10**5]
for a, b in t:
    v[a - 1] += b,
for i in v[:M]:
    for j in i:
        heappush(q, -j)
    if q:
        z += -heappop(q)
print(z)

Measured memory_bytes: 62472
#include<bits/stdc++.h>
using namespace std;
int main(){

 int N;
  cin>>N;
  vector <int>W(N);
  for(int i=0;i<N;i++)
    cin>>W.at(i);
  int sum=0;
  for(int i=0;i<N;i++)
    sum+=W.at(i);
 int j=-1;
  for(int i=0;0<sum;i++){
    sum-=W.at(i)*2;j++;
  }
  int sum1=sum+2*W.at(j);
  if(-sum<=sum1)
    cout<<-sum<<endl;
  else
    cout<<sum1<<endl;
  
  return 0;
  
}

Measured memory_bytes: 256
stack = []

gets.chomp.split.each do |i|
	if i == "+"
		stack.push(stack.pop + stack.pop)
	elsif i == "-"
		stack.push(0 - stack.pop + stack.pop)	
	elsif i == "*"
		stack.push(stack.pop * stack.pop)
	else
		stack.push(i.to_i)
	end
end

p stack.pop


Measured memory_bytes: 6872
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const LL mod=1000000007;
const LL LINF=1LL<<60;
const int INF=1<<30;
int dx[]={1,0,1,-1,1,-1,-1,0};
int dy[]={0,1,1,-1,-1,1,0,-1};



int main(){
    int n;cin >> n;
    vector<int> a(n);
    set<int> st;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        st.insert(a[i]);
    }
    if(st.size() == n) puts("YES");
    else puts("NO");
    return 0;
}


Measured memory_bytes: 10368
import java.util.*;
import static java.lang.System.*;

public class Main {

	Scanner sc = new Scanner(in);
	
	void run() {
		Set<Character> right = new HashSet<Character>();
		right.add('y'); right.add('u'); right.add('i'); right.add('o'); right.add('p'); right.add('h'); right.add('j'); right.add('k'); right.add('l'); right.add('n'); right.add('m');
		String s;
		while (true) {
			s = sc.nextLine();
			if (s.equals("#")) break;
			char[] letters = s.toCharArray();
			boolean flag = right.contains(letters[0]);
			boolean fb;
			int count = 0;
			for (int i = 1; i < letters.length; i++) {
				fb = right.contains(letters[i]);
				if (flag != fb)
					count++;
				flag = fb;
			}
			out.println(count);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}

}

Measured memory_bytes: 17728
from collections import Counter

N = int(input())
A = list(map(int, input().split()))

C = Counter(A)

tmp = 0
for v in C.values():
    tmp += v * (v - 1) // 2

for i in range(N):
    d = C[A[i]]
    res = tmp - d * (d - 1) // 2 + (d - 1) * (d - 2) // 2
    print(res)

Measured memory_bytes: 87884
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
struct ToDist{
    int to;
    int distance;
};
const int MINIMUM = -2001;
int N, M;
vector<vector<ToDist>> G;
vector<int> Nums;
bool flag = true;

void dfs(int now){
    if(Nums[now] == MINIMUM) Nums[now] = 0;
    for(auto e:G[now]){
        int to = e.to;
        int distance = e.distance;

        if(Nums[to] == MINIMUM){
            Nums[to] = Nums[now] + distance;
            dfs(to);
        } else if(Nums[to] != Nums[now] + distance){
            flag = false;
        }
    }
}

int main() {

    cin >> N >> M;
    G.resize(N);
    Nums.assign(N,MINIMUM);

    rep(i,M){
        int from,to,distance;
        cin >> from >> to >> distance;
        from--;to--;
        G[from].push_back({to,distance});
        G[to].push_back({from,distance*-1});
    }

    for(int i=0;i<N;i++){
        if(flag == false) break;
        else if(Nums[i] == MINIMUM) dfs(i);
    }

    cout <<  (flag ? "Yes" : "No") << endl;

}

Measured memory_bytes: 11008
N=int(input())
A=[]
for i in range(N):
    D=list(map(int,input().split()))
    A.append(D)
    
for i in range(N-2):
    if A[i][0]==A[i][1] and A[i+1][0]==A[i+1][1] and A[i+2][0]==A[i+2][1]:
        print('Yes')
        break
else:
    print('No')

Measured memory_bytes: 9048
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

int main()
{
	LL H, W;
	in >> H >> W;
	std::vector<std::string>S(H);
	rep(i, H) in >> S[i];

	LL ans = 0;
	rep(i, H)
	{
		rep(j, W)
		{
			if (S[i][j] == '#') continue;

			std::queue<std::pair<LL,LL>>que;
			que.push(std::pair<LL, LL>(i, j));
			std::vector<std::vector<LL>>dist(H, std::vector<LL>(W, -1));
			LL dx[] = { -1,0,0,1 }, dy[] = { 0,-1,1,0 };
			dist[i][j] = 0;
			while (!que.empty())
			{
				auto p = que.front(); que.pop();
				LL x = p.first, y = p.second;
				rep(k, 4)
				{
					LL rx = x + dx[k], ry = y + dy[k];
					if (rx < 0 || H <= rx || ry < 0 || W <= ry) continue;
					if (S[rx][ry] == '#') continue;
					if (dist[rx][ry] == -1)
					{
						dist[rx][ry] = dist[x][y] + 1;
						que.push(std::pair<LL, LL>(rx, ry));
					}
				}
			}
			LL res = 0;
			rep(x, H) rep(y, W) res = std::max(res, dist[x][y]);
			ans = std::max(ans, res);
		}
	}

	out << ans << std::endl;
}


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

ll N;

int main() {
    cin >> N;

    for (ll k = 1; k <= N; k++) {
        if ((k-1)*k/2 < N && N <= k*(k+1)/2) {
            int i = k;
            while (N > 0) {
                if (N-i >= 0) {
                    cout << i << endl;
                    N -= i;
                }
                i--;
            }

            //cout << k << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
    int a, b;
    std::cin >> a >> b;
    if (a == 1 ^ b == 1){
        if (a == 1)
            std::cout << "Alice";
        else if (b == 1)
            std::cout << "Bob";
    }
    else if (a > b)
        std::cout << "Alice";
    else if (a < b)
        std::cout << "Bob";
    else
        std::cout << "Draw";
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
// types
typedef long long ll; 
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int, int> pii;
// IO
#define fo(i, n) for (int i = 0; i < n; i++)
#define fo1(i, n) for (int i = 1; i <= n; i++)
#define sc(n) scanf("%d", &n) 
#define sca(a, n) fo(i, n) sc(a[i])
#define pd(a) printf("%d ", a)
#define pld(a) printf("%d\n", a)
#define pda(a, n) fo(i, n) pd(a[i])
#define pl printf("\n")
#define pb(a) push_back(a)
#define mp(a, b) make_pair(a, b) 
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
// math
const ll mod = 1e9+7;
template<typename T> T gcf(T a, T b) {return (b == 0) ? a : gcf(b, a%b);} 
template<typename T> T lcm(T a, T b) {return (a*b)/gcf(a, b);}
template<typename T> T sumTo(T x) {return x * (x+1) / 2;}
template<typename T> T sumSquaresTo(T x) {return x * (x+1) * (2*x+1) / 6;}
template<typename T> T ceilDiv(T n, T d) {return (n+d-1)/d;}

void solve() {
    int xorall = 0;
    int n; sc(n);
    int a[n]; sca(a, n);
    fo(i, n){
        xorall ^= a[i];
    }
    fo(i, n) {
        pd(xorall ^ a[i]);
    }
}

int main() {
    int t = 1;
    //scanf("%d", &t);
    while (t--) {
        solve();
    }
    return 0;
}

Measured memory_bytes: 4552
#include<bits/stdc++.h>
//#include<ext/pb_ds/assoc_container.hpp>
//#include<ext/pb_ds/tree_policy.hpp>
 
    #pragma GCC optimize("unroll-loops")
    #pragma GCC optimize("Ofast")
    #pragma GCC optimize("-O3")
    #pragma GCC optimize("no-stack-protector")
    #pragma GCC optimize("fast-math")
 
#define fi first
#define f first
#define se second
#define s second
#define vi_a vector<int>a;
#define p_b push_back
#define ll int
#define ld  double
#define pll pair<ll,ll>
#define pii pair<int,int>
#define m_p make_pair
#define fast_io cin.tie(0);cout.tie(0);ios_base::sync_with_stdio(0);
#define all(x) x.begin(),x.end()
#define getfiles    ifstream cin("input.txt");ofstream cout("output.txt");
#define pw(x) (1ll << x)
#define sz(x) (ll)x.size()
#define endl "\n"
#define rall(x) x.rbegin(),x.rend()
#define len(a) (ll)a.size()
#define rep(x,l,r) for(ll x=l;x<r;x++)
//#define for(int i=0;i<n;i++) for(ll i=0;i<n;i++)
using namespace std;
//using namespace __gnu_pbds;
ld eps = (ld)1 / 1e6;
ll inf = INT_MAX, mod2 = 998244353, mod1 = 1e9 + 7;
ll sqr(ll a) { return a * a; }
ll qb(ll a) { return a * a * a; }
ll gcd(ll a, ll b) { return !a ? b : gcd(b % a, a); }
ll binpow(ll a, ll b, ll mod) { return b ? (b % 2 ? (a * (sqr(binpow(a, b / 2, mod)) % mod)) % mod : sqr(binpow(a, b / 2, mod)) % mod) : 1; }
ll binmult(ll a, ll b, ll mod) { return b ? (b % 2 ? (2 * binmult(a, b / 2, mod) + a) % mod : (2 * binmult(a, b / 2, mod)) % mod) : 0; }
/////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////////
//const ll to[5]={0,4,6,7,9};
//const ll N=2*1e5+1;
const ll R=1e4;
const ll to[7]={1,2,3,1,3,2,1};
const ll tx[4]={0,0,-1,1};
const ll ty[4]={-1,1,0,0};
const char rev_to[4]={'E','W','N','S'};
const ll N=1e5;
signed main(){
    fast_io;
    string a;
    cin>>a;
    if(a.find('7')==string::npos){
        cout<<"No";
    }
    else{
        cout<<"Yes";
    }
    return 0;
}
 
/*
 
 
 
    /////
 
*/

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

vector <int> v;

bool ok(int x)
{
	int flag[10] = {false};
	while (x)
	{
		flag[x % 10] = 1;
		x /= 10;
	}
	if (flag[3] == 0 || flag[5] == 0 || flag[7] == 0) return false;
	return true;
}

void DFS(int cur, int num)
{
	if (cur == 10) 
	{
		if (ok(num)) v.push_back(num);
		return;
	}
	DFS(cur + 1, num);
	DFS(cur + 1, num * 10 + 3);
	DFS(cur + 1, num * 10 + 5);
	DFS(cur + 1, num * 10 + 7);
}

int main()
{
	DFS(0, 0);
	sort(v.begin(), v.end());
	v.erase(unique(v.begin(), v.end()), v.end());
	int n;
	while (scanf("%d", &n) != EOF) printf("%d\n", (int)(upper_bound(v.begin(), v.end(), n) - v.begin()));
	return 0;
}


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

const int mod = 924844033;

int dp[2010][2010][4];
long long f[2010];
long long fac[2010];
int n, k;

void add(int &a, int b) {
	a = (a + b) % mod;
}

void add(long long &a, long long b) {
	a = (a + b) % mod;
}

void solve() {
	dp[0][0][1] = 1;
	for (int i = 0; i <= n; i++) {
		for (int j = 0; j <= i; j++) {
			for (int mask = 0; mask < 4; mask++) {
				if (!dp[i][j][mask]) continue;
//				cout << "    dp:" << i << " " << j << " " << mask << " " << dp[i][j][mask] << endl;
				int val = dp[i][j][mask];
				add(dp[i + 1][j][mask >> 1], val);
//				cout << "      -> dp:" << i + 1 << " " << j << " " << (mask >> 1) << endl;
				if (!(mask & 1)) add(dp[i + 1][j + 1][mask >> 1], val);
				add(dp[i + 1][j + 1][(mask >> 1) | 2], val);
//				cout << "      -> dp:" << i + 1 << " " << j + 1 << " " << ((mask >> 1) | 2) << endl;
			}
		}
	}
	f[0] = 1;
	for (int i = 0; i < k; i++) {
		for (int j = n; j >= 0; j--) {
			for (int t = 1; t <= min((n / k + (i < n % k)), j); t++) {
				add(f[j], f[j - t] * (dp[n / k + (i < n % k)][t][0] + dp[n / k + (i < n % k)][t][1]));
			}
		}
	}
}

int main () {
	scanf("%d%d", &n, &k);
	fac[0] = 1;
	for (int i = 1; i <= n; i++) {
		fac[i] = fac[i - 1] * i % mod;
	}
	long long ans = 0;
	solve();
	for (int i = 0; i <= n; i++) {
//		cout << "    f:" << i << " " << f[i] << endl;
		ans = (ans + (i & 1 ? -1 : 1) * f[i] * fac[n - i] % mod + mod) % mod;
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main(){
  int A,B,C;
  cin >> A >> B >> C;
  if(A==B){
    cout << C << endl;
  }else if(B==C){
    cout << A << endl;
  }else{
    cout << B << endl;
  }
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
using namespace std;
const int INF = 1e9;
const string emp = "Vacant";
const string M = "Male";
const string F = "Female";
 
void out(int N, string &S) {
    cout << N << endl;
    fflush(stdout);
    cin >> S;
    return;
}
 
int main() {
    int N;
    cin >> N;
    int L = 0, R = N;
    string Sl, Sr;
    out(0, Sl);
    if (Sl == emp) return 0;
    
    while (abs(L-R) > 1) {
        int mid = (L + R) / 2;
        string Sm;
        out(mid, Sm);
        if (Sm == emp) return 0;
        if ((abs(mid-L) % 2 == 0 && Sl != Sm) || (abs(mid-L) % 2 == 1 && Sl == Sm)) {
            R = mid; Sr = Sm;
        } else {
            L = mid; Sl = Sm;
        }
    }
    
    return 0;
}


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

#define rep(i, n) for (ll i = 0; i < (int)(n); i++)
#define repk(i,s, n) for (ll i = s; i < (int)(n); i++)
#define ll long long
using namespace std;


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

	vector<ll> a(n+1); // 1からスタート
	vector<ll> b(m+1);
	a.at(0) = b.at(0) = 0;
	ll bsum = 0;
	repk(i,1, n+1) {
		cin >> a.at(i);
	}
	repk(i,1, m+1) {
		cin >> b.at(i);
		bsum += b.at(i);
	}


	ll asum = 0;
	ll best0 = m;
	vector<ll> c(n+1);
	rep(i, n+1) {
		asum += a.at(i);
		if (asum > k) break;

		ll j = best0;
		rep(r, best0 + 1) {
			if (bsum <= k - asum) {
				best0 = j - r; // bestを更新
				c.at(i) = i + best0;
				// cout << i << " : " << best0 << endl;
				break;
			}
			bsum -= b.at(j - r);
		}
	}

	sort(c.begin(), c.end());
	reverse(c.begin(), c.end());
	cout << c.at(0) << endl;

}

Measured memory_bytes: 7964
import sys
n,m=map(int,input().split())
if n==3:
  ans=["1","0","0"]
elif n==2:
  ans=["1","0"]
else:
  ans=["0"]
cnt=[0,0,0]
for i in range(m):
  s,c=map(int,input().split())
  if s==1 and c==0 and n!=1:
    print(-1)
    sys.exit()
  elif ans[s-1]!=str(c):
    if cnt[s-1]==0:
      ans[s-1]=str(c)
      cnt[s-1]=1
    else:
      print(-1)
      sys.exit()
print("".join(ans))




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

int main()
{
    int N, M, ac = 0, pen = 0;
    cin >> N >> M;

    vector<int> P(M);
    vector<string> S(M);

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

        cin >> P.at(i) >> S.at(i);
    }

    bitset<int(1e5)> flag_ac(0);

    for (int i = 0; i < M; i++)
    {
        if (S.at(i) == "AC")
        {
            flag_ac.set(P.at(i) - 1, 1);
        }

        if (S.at(i) == "WA")
        {
            if (flag_ac.test(P.at(i) - 1))
            {
                S.at(i) = "br";
            }
        }
    }
    for (int i = 0; i < M; i++)
    {
        if (S.at(i) == "WA")
        {
            if (flag_ac.test(P.at(i) - 1))
            {
                pen++;
            }
        }
    }

    ac = flag_ac.count();

    std::cout << ac << " " << pen << endl;
}


Measured memory_bytes: 6144
#include <iostream>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <functional>
#include <bitset>

using namespace std;
using lint = long long int;
long long int INF = 1001001001001001LL;
int inf = 1000000007;
long long int MOD = 1000000007LL;
double PI = 3.1415926535897932;
long long int di[] = {-1, 0, 1, 0, -1, 1, 1, -1};
long long int dj[] = {0, 1, 0, -1, 1, 1, -1, -1};

template<typename T1,typename T2>inline void chmin(T1 &a,const T2 &b){if(a>b) a=b;}
template<typename T1,typename T2>inline void chmax(T1 &a,const T2 &b){if(a<b) a=b;}

#define ALL(a) a.begin(),a.end()
#define RALL(a) a.rbegin(),a.rend()

/* do your best */

int main() {
  
  int k, x; cin >> k >> x;
  if(k * 500 >= x) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
def same(s,t):
    for a,b in zip(s,t):
        if not (a==b or a=='?'):
            return False
    return True

s=input()
t=input()
if len(s)<len(t):
    print('UNRESTORABLE')
    exit()
elif len(s)==len(t):
    if same(s,t):
        print(t)
        exit()
for i in range(len(t),len(s)):
    i=len(s)-i
    if same(s[i:i+len(t)],t):
        s=s[:i]+t+s[i+len(t):]
        break
else:
    print('UNRESTORABLE')
    exit()
for c in s:
    print(c if c!='?'else 'a',end='')
print()

Measured memory_bytes: 3064
#include <iostream>
#include<vector>
#include <algorithm>
using namespace std;
typedef struct city{
  int num;
  int pref;
  string id;
  int year;
}city;

string makeid(int pref, int order){
  pref++; order++;
  string id = "";
  for(int i=0; i<6-to_string(pref).size(); i++){
    id += "0";
  }
  id += to_string(pref);
  for(int i=0; i<6-to_string(order).size(); i++){
    id += "0";
  }
  id += to_string(order);
  return id;
}

int main(){
  int N, M; cin >> N >> M;
  vector<vector<city>> pref(N);
  for(int i=0; i<M; i++){
    int P, Y; cin >> P >> Y;
    city c; c.num = i; c.pref = P-1; c.year = Y; 
    pref[P-1].push_back(c);
  }
  vector<city> all;
  for(int i=0; i<N; i++){
    sort(pref[i].begin(),
         pref[i].end(),
         [](const city& a, const city& b){return a.year < b.year;});
    for(int j=0; j<pref[i].size(); j++){
      pref[i][j].id = makeid(i, j);
      all.push_back(pref[i][j]);
    }
  }
  sort(all.begin(),
       all.end(),
       [](const city&a, const city&b){return a.num < b.num;});
  for(int i=0; i<M; i++){
    cout << all[i].id << endl;
  }
}

Measured memory_bytes: 14640
#include<bits/stdc++.h>
 
#define lol long long
#define gcd(x,y) __gcd(x,y)
#define mt make_tuple
#define mp make_pair
#define fi first
#define se second
#define fixed(x) fixed<<setprecision(x)
using namespace std;
template <class A, class B> inline bool chmax(A &a, const B &b) { return b > a && (a = b, true); }
template <class A, class B> inline bool chmin(A &a, const B &b) { return b < a && (a = b, true); }
template <class A> inline lol abs(A &a) { return (a < 0 ? -a : a); }
bool inLine(int x,int y,int mx,int my){return (x>=0&&y>=0&&x<mx&&y<my);}
const lol inf=(1LL<<62);
const lol MOD=(1e9)+7;
const lol mod=998244353;
const int dx[]={1,0,-1,0,1,1,-1,-1};
const int dy[]={0,1,0,-1,1,-1,1,-1};
lol n,m,k;
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >>n>>k;
  vector<int> a(n);
  vector<int> ans(n);
  for(auto&&o:a) cin >>o;
  lol sum=0;
  lol so=0;
  set<int> se;
  se.insert(0);
  ans[0]=0;
  while(1){
    if(k<=0) break;
    sum=a[sum]-1;
    so++;
    k--;
    if(se.find(sum)!=se.end()){
      k%=so-ans[sum];
      break;
    }
    ans[sum]=so;
    se.insert(sum);
  }
  for(int i=0;i<k;i++){
    sum=a[sum]-1;
  }
  cout <<sum+1<<'\n';
  return (0);
}

Measured memory_bytes: 12380
using System;
using System.Collections.Generic;
using System.Linq;
using System.Diagnostics;

class Program
{
    static void Main(string[] args)
    {
        var sc = new Scanner();
        int n = sc.nextInt();
        int m = sc.nextInt();
        var l = new int[n + 1];
        var r = new int[n + 1];

        for (int i = 0; i < m; i++)
        {
            l[sc.nextInt()]++;
            r[sc.nextInt()]++;
        }

        int tmp = 0;
        int ans = 0;
        for (int i = 1; i <= n; i++)
        {
            tmp += l[i];
            if (tmp == m) ans++;
            tmp -= r[i];
        }

        Console.WriteLine(ans);
    }
}

// chokudai's Scanner
class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }

    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }

    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 15832
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long
#define mk make_pair
#define hs ios_base::sync_with_stdio(false);cin.tie(NULL );
#define N (ll)(1e5+2)


int main()
{
  ll t;
  cin>>t;
  ll c[t];
  for(ll i=0;i<t;i++)
  cin>>c[i];
  sort(c,c+t);
  ll ans=0;
  for(ll i=0;i<t;i++)
  {
    for(ll j=i+1;j<t;j++)
    {
      if(c[i]!=c[j])
      {
        for(ll k=j+1;k<t;k++)
        {
            if(c[j]!=c[k]&&(c[i]+c[j])>c[k])
            {
              ans++;
            }
        }
      }
    }
  }
  cout<<ans<<endl;
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const int INF = (1<<30) - 1;
const ll LINF = (1LL<<60) - 1;

int main(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    for (int i = 0; i < s.size(); ++i) {
        cout <<((s[i] + n > 'Z') ? (char)(s[i] + n - ('Z' - 'A' + 1)) : (char)(s[i] + n));
    }
    cout << endl;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>

#include <bitset>
#include <cassert>
#include <queue>
#include <random>
#include <stack>
#include <iomanip>

using namespace std;

#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)

#define repv(x, arr) for (auto &x : arr)
#define all(v) (v).begin(), (v).end()
#define vec(name, num) vector<ll> name((num), 0);
#define mp(a, b) make_pair(a, b)
#define op(i) cout << (i) << endl;
#define F first
#define S second

typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;

const ll mod = 1e9 + 7;
const ll infl = 1e17;

int main()
{
    ll n;
    cin >> n;
    vll a(n);
    ll s = 0;
    rep(i, n) {cin >> a[i];
        s += a[i];
    }
    s /= 2;
    vll x(n, 0);
    rep(k,(n-1)/2){
        s -= a[2 * k];
    }
    x[n - 1] = s;
    repf(i,1,n){
        x[n - 1 - i] = a[n-1 - i] - x[n - i];
    }
    rep(i, n) cout << x[i] * 2 << " ";
    cout << endl;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<ld,ld> pdd;
typedef vector<ll> vll;
typedef vector<ld> vld;
typedef vector<pll> vpl;
typedef vector<vll> vvll;

#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define FI first
#define SE second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define REP1(i,n) for(int i=1;i<((int)n);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define PB push_back
#define EB emplace_back
#define MP(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define no cout<<"No"<<endl
#define NO cout<<"NO"<<endl
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL

const int inf = 1e9;
const ll linf = 1LL << 50;
const double eps = 1e-10;
const int MOD = 1e9 + 7;
const int dx[4] = {-1, 0, 1, 0};
const int dy[4] = {0, -1, 0, 1};

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

  char c;
  cin>>c;
  ll i=c-'A';
  if(i<0 || 'z'-'a'<i)
    cout<<'a'<<endl;
  else
    cout<<'A'<<endl;

}



Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
long f[10000000],a[10000000],n,k;
int main()
{
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    cin>>n>>k;
    for (long i=1;i<=n;i++)
    {
        cin>>a[i];
    }
    f[1]=0;
    f[2]=abs(a[2]-a[1]);
    for (long i=3;i<=n;i++)
    {
        f[i]=LONG_MAX;
        for (long j=i-1;j>=i-k && j>0;j--)
        {
            f[i]=min(f[j]+abs(a[j]-a[i]),f[i]);
        }
    }
    cout<<f[n];
}


Measured memory_bytes: 3072
N, K = map(int, input().split())
h = list(map(int, input().split()))
dp = [float('inf')] * N
dp[0] = 0
dp[1] = abs(h[1] - h[0])
for i in range(2, N):
    for j in range(1, K+1):
        if j <= i:
            dp[i] = min(dp[i], dp[i-j] + abs(h[i] - h[i-j]))
        else:
            break
print(dp[-1])

Measured memory_bytes: 85488
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll n,l=0,r=INT_MAX,a,b,m;
     cin>>n>>m;
     for(int i=0;i<m;i++)
     {
         cin>>a>>b;
         if(a>l)
            l=a;
         if(b<r)
            r=b;
     }
     if(l>r)
        cout<<"0"<<endl;
     else
        cout<<r-l+1<<endl;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(1){
    if(x->left == NIL)break;
    x = x->left;
  }
  return x;
}

Node treeMaximum(Node x){
  while(1){
    if(x->right == NIL)break;
    x = x->right;
  }
  return x;


}

Node treeSearch(Node u, int k){
  while(1){
    if(u == NIL || k == NIL)break;
    if(k < u->key){
      u = u->left;
    } else {
      u = u->right;
    }
  }
  return u;
}

Node treeSuccessor(Node x){
  Node y;
  if(x->right != NIL){
    return treeMinimum(x->right);
  }
  y = x->parent;
  while(1){
    if(y == NIL || x != y->right)break;
    x=y;
    y=y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL){
    y = z;
  } else {
    y = treeSuccessor(z);
  }

  if(y->left != NIL){
    x = y->left;
  } else {
    x = y->right;
  }

  if(x != NIL){
    x->parent = y->parent;
  }

  if(y->parent == NIL){
    root = x;
  } else {
    if(y == y->parent->left){
      y->parent->left = x;
    } else {
      y->parent->right = x;
    }
  }

  if(y != z){
    z->key = y->key;
  }
  free(y);
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(1){
    if(x == NIL)break;
    y=x;
    if(z->key < x->key){
      x = x->left;
    } else {
      x = x->right;
    }
  }
  z->parent = y;
  if(y == NIL){
    root = z;
  } else {
    if(z->key < y->key){
      y->left = z;
    } else {
      y->right = z;
    }
  }
}

void inorder(Node u){
  if(u==NIL)return;
  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);
}
void preorder(Node u){
  if(u==NIL)return;
  printf(" %d",u->key);
  preorder(u->left);
  preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}



Measured memory_bytes: 25140
import java.util.Arrays;
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner s = new Scanner(System.in);
		int n = s.nextInt();
		int l = s.nextInt();
		int i = 0;
		String a = "";

		String[] ary = new String[n];

		for(i=0;i<n;i++) {
			ary[i]=s.next();
		}

		Arrays.sort(ary);

		i=0;
		for(i=0;i<n;i++) {
			a=a+ary[i];
		}
		System.out.println(a);

	}

}

Measured memory_bytes: 25556
import java.util.Scanner;

class Main{



    public static void main(String[] a){


        Scanner sc = new Scanner(System.in);

        while(sc.hasNext()) {


	        	int z = sc.nextInt();
	        	int y = sc.nextInt();

	        	int ans = z + y;
	        	String ansSt = String.valueOf(ans);
	        	int ansK = ansSt.length();
	        	System.out.println(ansK);

        }

        sc.close();


     }




}

Measured memory_bytes: 26636
#include<bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
using namespace std;

//ループマクロ
#define FOR(i , a , b)  for(int i = (a) ; i < (b) ; i++)
#define REP(i , n)      for(int i = 0 ; i < n ; i++)
#define REPR(i , n)     for(int i = n ; 0 <= i ; i--)
#define ROP(i, n)       for(int i = 1 ; i <= n ; i++)

//入出力
#define SCOUT(x) cout << (x) << " "
#define VECCIN(x) for(auto& ele : (x) ) cin >> ele
#define VECOUT(x) for(auto& ele : (x) ) cout << ele << " "; cout << endl;

//その他
#define ALL(obj) (obj).begin() , (obj).end() 
#define SORT(obj) sort(ALL(obj))
#define GSORT(obj) sort(ALL(obj) , greater<int>())
#define P pair<int , int>
#define V vector<int>
#define VLL vector<long long>
#define M map<int, int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int , V , greater<int>>

int main(void) {

	ios::sync_with_stdio(false);	cin.tie(0);
    int N;  cin >> N;
    for(int i = 0 ; i < N ; i++){
      int num;  cin >> num;
      if(num % 2 == 0){
        if(num % 3 != 0 && num % 5 != 0){
          cout << "DENIED" << endl;
          return 0;
        }
      }
    }
    cout << "APPROVED" << endl;
    
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define For(i, l, r) for(int i = (l), _end_ = (int)(r); i <= _end_; ++i)
#define Fordown(i, r, l) for(int i = (r), _end_ = (int)(l); i >= _end_; --i)
#define Set(a, v) memset(a, v, sizeof(a))
using namespace std;

bool chkmin(int &a, int b) {return b < a ? a = b, 1 : 0;}
bool chkmax(int &a, int b) {return b > a ? a = b, 1 : 0;}

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

map<int, int> M;
int main () {
	int n = read();
	For (i, 1, n) {
		int val = read();
		++M[val];
	}
	int m = read();
	bool flag = true;
	For (i, 1, m) {
		int val = read();
		if (M[val]) 
			--M[val];
		else {
			flag = false;
			break ;
		}
	}
	puts(flag ? "YES" : "NO");
    return 0;
}


Measured memory_bytes: 9600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double dl;
#define pb push_back
#define F first
#define S second
#define inf 1e18
#define mod 1000000007
#define PI 3.1415926536
#define vll vector <ll>
#define pll pair <ll,ll>
#define dbg(n) cout<<n<<' '
#define cu continue
#define br break
#define N 1000005
#define min_pq priority_queue <pll> ,vector <pll>, greater <pll> > > 

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


    ll n,a,b;
    cin>>n>>a>>b;
    ll c=a+b;
    ll x=n/c,y=n%c;
    ll ans=min(y,a);
    ans+=(x*a);
    cout<<ans<<'\n';
}

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

int main() {
    long long N;
    cin >> N;
    string s = "";
    int i = 1;
    do{
        int tmp = N % (long long)pow(2,i);
        if(tmp) {
            s.insert(0, "1");
            N -= (long long)pow(-2, i-1);
        } else{
            s.insert(0, "0");
        }
        ++i;
   } while(N != 0);
   cout << s << endl;
}

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

int main() {
  int N;
  cin >> N;
  vector <double> vec(N);
  
  for (int i=0;i<N;i++){
    cin >> vec[i] ;
  }
  double sum = 0;
  for (int j=0;j<N;j++){
    sum += 1/vec[j];
  }
  cout << 1/sum << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i)
using namespace std;
const int INF = 100000000;
const int MAX_N = 100;
typedef pair<int , int> P;
typedef long long ll;
 
int main () {
  ll N, D, ans;
  ans = 0;
  cin >> N >> D;
  for (int i = 0; i < N; ++i) {
    ll X, Y;
    cin >> X >> Y;
    if (X*X + Y*Y <= D*D) {
      ++ans;
    }
  }
  printf("%lld\n", ans);
  return 0;
}

Measured memory_bytes: 3760
from itertools import*
from math import*
from collections import*
from heapq import*
from bisect import bisect_left,bisect_right
from copy import deepcopy
inf = float("inf")
mod = 10**9+7
from functools import reduce
import sys
sys.setrecursionlimit(10**7)

S = input()
C  =Counter(S)
a = 0
for k,v in C.items():
    if v!=2:
        print("No")
        exit()
print("Yes")

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

int main(){
  string w;
  cin >>w;
  int l=w.size();
  vector<int> d(26);
  for(int i=0;i<l;i++){
    int x=w[i]-97;
    d.at(x)++;
  }
  for(int i=0;i<26;i++){
    if(d.at(i)%2 == 1){
      cout << "No" << endl;
      return 0;
    }
  }
  cout <<"Yes" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,w,n) for(int i=(int) w;i<(int) n;i++)
#define qi queue<int>
#define vi vector<int>
#define ll long long
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define pii pair<int,int>
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define fi first
#define se second
#define prq priority_queue
#define foreach(it,c) for(__typeof((c).begin()) it=c.begin();it!=c.end();it++)
using namespace std;
inline ll read(){
	ll x=0;
	int f=1;
	char c=getchar();
	for(;!isdigit(c);c=getchar()) if(c=='-')f=-f;
	for(;isdigit(c);c=getchar())x=x*10+(c-'0');
	return x*f;
}
int main(){
	//freopen("a.in","r",stdin);
	//freopen("a.out","w",stdout);
	int r;
	cin>>r;
	cout<<3*r*r<<endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <cstdlib>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <string>
#include <cmath>
using namespace std;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
using vi = vector<int>; // intの1次元の型に vi という別名をつける
using vvi = vector<vi>; // intの2次元の型に vvi という別名をつける
using vl = vector<ll>;  // long longの1次元の型に vl という別名をつける
using vvl = vector<vl>; // long longの2次元の型に vvl という別名をつける
int MOD = 1000000007; //10^9 + 7

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

// 無限大の値
const ll  lINF = 1LL << 60;
const int iINF = 1 << 29;

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

  int l,r,ans=0;
  rep(i,n){
    cin >> l >> r;
    ans += r-l+1;
  }

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

Measured memory_bytes: 3612
import copy

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

all_list = []
for h in range(H):
    h_list = []
    tmp = input()
    for i in range(len(tmp)):
        if(tmp[i] == ('.')):
            h_list.append(0)
        else:
            h_list.append(1)
    all_list.append(h_list)

cnt = 0
for i_b in range(2 ** H):
    for j_b in range(2 ** W):
        cnt_tmp = 0
        all_list_tmp = copy.deepcopy(all_list)
        for i in range(H):
            if((i_b >> i) & 1):
                for j_tmp in range(W):
                    all_list_tmp[i][j_tmp] = 3
        for j in range(W):
            if((j_b >> j) & 1):
                for i_tmp in range(H):
                    all_list_tmp[i_tmp][j] = 3
        
        for i in range(H):
            cnt_tmp += all_list_tmp[i].count(1)
        if(cnt_tmp == K):
            cnt += 1

print(cnt)

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

int main() {
	int N,M,A,B,r=0;
	cin >> N >> M;
	vector<int> H(N);
	vector<set<int>> p(N);

	rep(i,N)
		cin >> H.at(i);
	rep(i,M) {
		cin >> A >> B;
		--A, --B;
		p.at(A).insert(B);
		p.at(B).insert(A);
	}

	rep(i,N) {
		bool ok = 1;
		for(int x : p.at(i))
			if(H.at(i) <= H.at(x)) {
				ok = 0;
				break;
			}

		if(ok)
			++r;
	}

	cout << r << endl;
}

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

const int INF = 2e9;

int main(){
    int n;
    cin >> n;
    vector<map<char,int>> d(n);
    rep(i,n){
        string s;
        cin >> s;
        rep(j,s.size()){
            d[i][s[j]]++;
        }
    }
    map<char,int> m = d[0];
    for(auto x:m){
        char k = x.first;
        rep(i,n) m[k] = min(m[k],d[i][k]);
    }
    for(auto x:m){
        rep(i,x.second) cout << x.first;
    }
    cout << endl;
}

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

typedef long long ll;
typedef pair<int,int> P;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    int n;
    ll k;
    cin >> n >> k;
    vector<ll> a(n),f(n);
    for (int i = 0;i < n;++i) cin >> a[i];
    for (int i = 0;i < n;++i) cin >> f[i];
    sort(a.begin(),a.end());
    sort(f.begin(),f.end());
    reverse(f.begin(),f.end());
    ll ng = -1,ok = 1e12;
    while (ok-ng > 1) {
        ll mid = (ok+ng)/2;
        ll sum = 0;
        for (int i = 0;i < n;++i) sum += max(0LL,a[i]-mid/f[i]);
        (sum <= k ? ok : ng) = mid;
    }
    cout << ok << endl;
    return 0;
}

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

int main()
{
    int N,K;
    cin >> N >> K;
    int x;
    int ans=0;
    for(int i=0;i<N;i++){
        cin >> x;
        ans+=min(x,K-x);
    }
    cout << 2*ans << endl;
    return 0;
}

Measured memory_bytes: 256
import itertools

N=int(input())
P=list(map(int,input().split()))
Q=list(map(int,input().split()))
a=0
b=0

for i,v in enumerate(itertools.permutations(range(1,N+1),N)):
  if tuple(P)==v:
    a=i
  if tuple(Q)==v:
    b=i
print(abs(a-b))

Measured memory_bytes: 9136
#ABC086C
N=int(input())
txy=[[0,0,0]]
for n in range(N):
	txy.append(list(map(int,input().split())))
for n in range(N):
	tt=txy[n+1][0]-txy[n][0]
	xy=abs(txy[n+1][1]-txy[n][1])+abs(txy[n+1][2]-txy[n][2])
	if tt>=xy:
		if (xy-tt)%2==0:
			continue
	print('No')
	exit()
print('Yes')

Measured memory_bytes: 27300
#include <bits/stdc++.h>
using namespace std;
int main(){
  
  string s,a;
  cin >> s;
  a="abcdefghijklmnopqrstuvwxyz";
  vector<int> b(26,0);
  
  for(int i=0; i<s.size(); i++){
  	for(int j=0; j<26; j++){
      if(s[i]==a[j]) b[j]++;
    }
  }
  char ans;
  bool exist=0;
  for(int i=0; i<26; i++){
    if(b[i]==0){
      ans = a[i];
      exist = 1;
      break;
    }
  }
  
  if(exist) cout << ans << endl;
  else cout << "None"<< endl;
  
}

Measured memory_bytes: 512