akhauriyash/Code-Regression huggingface dataset:
#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<int(b);i++)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define rrep(i,n) for (int i=(n-1);i >= 0;i--)
#define all(v) v.begin(),v.end()
#define sz(v) (int)((v).size())
#define MAX(v) *max_element(all(v))
#define MIN(v) *min_element(all(v))
using namespace std; using ll = long long; using P = pair<int,int>;
using vl = vector<ll>; using vvl = vector<vl>;
inline void IN(void){return;}
template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){cin >> first;IN(rest...);return;}
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;}
const ll INF = 1LL << 60;
const int dx[8] = {1,0,-1,0,1,1,-1,-1}; const int dy[8] = {0,1,0,-1,1,1,-1,-1};

int main(){
    cin.tie(0); ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    vl a(n,0);
    bool s = true;
    rep(i,n){
        cin >> a[i];
        if(a[i]%2==1) s = false;
    }
    if(s) cout << "second" << endl;
    else cout << "first" << endl;
}

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

using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define ll long long int
#define INF 1000000007
// cin.eof() 入力個数の問題
int main(){
int n,m;
cin>>n>>m;
vector<vector<int>> gr(n+1);
rep(i,m){
  int a,b;
  cin>>a>>b;
  gr[a].push_back(b);
  gr[b].push_back(a);
}

bool visit[n+1];
for(int i=0;i<=n;i++){
  visit[i]=true;
}
queue<int> que;
int ans[n+1]={0};
visit[1]=false;
que.push(1);
while(!que.empty()){

int v=que.front();
//cout<<"v=="<<v<<endl;
que.pop();
for(auto i:gr[v]){
 // cout<<"visit=="<<visit[i]<<endl;
if(!visit[i]) continue;
  que.push(i);
  visit[i]=false;
ans[i]=+v;
}
}cout<<"Yes"<<endl;
for(int i=2;i<=n;i++){
  cout<<ans[i]<<endl;
}
  return 0;
}


Measured memory_bytes: 10492
N = int(input())

list=[0]*N
for x in range(1,N+1):
    if x * x+2*x+3 > N:
        break
    for y in range(1,N+1):
        if x * x + y * y + x * y+x+y+1 > N:
            break
        for z in range(1, N + 1):
            val=x * x + y * y + z * z + x * y + y * z + z * x
            if val > N:
                break
            list[val - 1] += 1
for i in range(N):
    print("{}".format(list[i]))
 




Measured memory_bytes: 9104
#include <bits/stdc++.h>
#define D(x) cout << #x << "=" << x << endl
#define De(...)
using namespace std; 

int _; 
 
int n,a[200020],b[200020];
vector<pair<int,int> > v;
long long cnt=0; 
 
int main()
{
	//for(scanf("%d",&_);_;_--)
	scanf("%d",&n);
	for(int i=0;i<n;i++)
	{	
		scanf("%d%d",a+i,b+i);
		v.push_back(pair<int,int> (b[i],a[i]));
	}
	sort(v.begin(),v.end());
	for(int i=0;i<n;i++)
	{
		cnt += v[i].second;
		if(cnt>v[i].first)
			return puts("No"),0;	
	} 
	return puts("Yes"),0;
}


Measured memory_bytes: 6620
#include <iostream>
#include <vector>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)

int main() {
	int n, k, q;
	cin >> n >> k >> q;
	vector<int> a(n,0);
	rep(i, q) {
		int p;
		cin >> p;
		a[p - 1]++;
	}
	rep(i, n) {
		if (a[i] >= q - k + 1) {
			cout << "Yes" << endl;
		}
		else cout << "No" << endl;
	}
	return 0;
}


Measured memory_bytes: 1024
#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 n;
    cin >> n;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    int mem = 0;
    int cnt=0;
    rep(i,n-1){
        if(h[i+1] <= h[i]){
            cnt++;
        }else{
            mem = max(mem,cnt);
            cnt = 0;
        }
    }
    mem = max(mem,cnt);
    cout << mem << endl;

    
    return 0;
}

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

int main(){
	// sengen
	int n;
	// nyuryoku
	cin >> n;
	// keisan
	int m = n%10;
	if(m == 3){
		cout << "bon";
	}else if(m==0 || m==1 || m==6 || m==8){
		cout << "pon";
	}else{
		cout << "hon";
	}
	// syutsuryoku
}

Measured memory_bytes: 3580
using System;
using System.Collections.Generic;
using System.Linq;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            //[summary]
            var numbers = new[] { 1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };

            int K = int.Parse(Console.ReadLine());

            Console.WriteLine(numbers[K - 1]);
        }
    }
}

Measured memory_bytes: 13140
#include <iostream>
using namespace std;
int main() {
    int n, k, c; cin >> n >> k >> c;
    string s; cin >> s;
    int A[k], B[k];
    for (int i = 0, j = 0; j < k; ) {
        if (s[i] == 'o') { A[j] = i; j++; i += c+1; }
        else i++;
    }
    for (int i = n-1, j = k-1; j >= 0; ) {
        if (s[i] == 'o') { B[j] = i; j--; i -= c+1; }
        else i--;
    }
    for (int j = 0; j < k; j++)
        if (A[j] == B[j]) cout << A[j]+1 << endl;
}


Measured memory_bytes: 3332
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#define watch(x) cout << (#x) << " is " << (x) << endl
#define debug cout << "hi" << endl

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

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


const ll mod = 1e9 + 7;
const int INF32 = 1<<30;
const ll INF64 = 1LL<<60;
const ld pi = 3.141592653589793;

vector<vector<pii>>adj;
vector<int>ans;

void dfs(int v,int prev,int skip){
     int color = 1;
     for(int j = 0;j<adj[v].size();j++){
        int nex = adj[v][j].first;
        if(nex == prev) continue;
        if(color == skip) color++;
        ans[adj[v][j].second] = color;
        dfs(adj[v][j].first,v,color);
        color++;
     }
}

void solve(){
     int n;cin >> n;
     adj.resize(n+1);
     ans.resize(n+1);
     int maxi = 0;
     for(int i = 0;i<n-1;i++){
        int v,u;cin >> v >> u;
        adj[v].push_back({u,i});
        adj[u].push_back({v,i});
        int j = adj[v].size();int k = adj[u].size();
        maxi = max(max(j,k),maxi);
     }
     dfs(1,-1,-1);
     cout << maxi <<endl;
     for(int i = 0;i<n-1;i++) cout << ans[i]<<endl;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    return 0;
}

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

ll dblng[(ll)1e5 + 10][30];

int main(){
    ll N;
    cin >> N;
    vector<ll> X(N);
    for(ll &x : X) cin >> x;
    ll L;
    cin >> L;
    for(ll i = 0; i < N; i++){
        auto ite = upper_bound(X.begin(), X.end(), X[i] + L);
        ite--;
        dblng[i][0] = (ite - X.begin());
    }
    for(ll dig = 1; dig < 30; dig++){
        for(ll i = 0; i < N; i++){
            ll fst = dblng[i][dig - 1];
            dblng[i][dig] = dblng[fst][dig - 1];
        }
    }
    ll Q;
    cin >> Q;
    for(ll QQ = 0; QQ < Q; QQ++){
        ll a, b;
        cin >> a >> b;
        a--;
        b--;
        if(a > b) swap(a, b);
        ll ok = 1e9, ng = 0;
        while(ok - ng > 1){
            ll mid = (ok + ng) / 2;
            ll now = a;
            for(ll i = 0; i < 30; i++){
                if(!(mid & (1 << i))) continue;
                now = dblng[now][i];
            }
            if(now >= b) ok = mid;
            else ng = mid;
        }
        cout << ok << '\n';
    }
    return 0;
}


Measured memory_bytes: 25088
import java.util.*;
public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);
		int n,i,cnt,j;
		n = sc.nextInt();
		int [][] graph = new int[n][n+1];
		for(i=0;i<n;i++){
			for(j=0;j<=n;j++){
				graph[i][j] =0;
			}
		}
		for(i=0;i<n;i++){
			graph[i][0] = sc.nextInt();
			cnt = sc.nextInt();
			for(j=0;j<cnt;j++){
				graph[i][sc.nextInt()]++;
			}
		}
		for(i=0;i<n;i++){
			for(j=1;j<n;j++){
				System.out.print(graph[i][j]+" ");
			}
				System.out.print(graph[i][n]);
			System.out.println("");
		}
	}

}



Measured memory_bytes: 31588
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int MAX = 10005;
const int MOD = 1e9+7;
const int INF = 0x3f3f3f3f;

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    cout << a + b + c - max(a, max(b, c));
    return 0;
}


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

using ll = long long int;
using P = pair<int, int>;
using P3 = pair<int,P>;
using PP = pair<P, P>;
constexpr int INF = 1<<30;
constexpr ll MOD = ll(1e9)+7;
constexpr int di[] = {0,1,0,-1};
constexpr int dj[] = {1,0,-1,0};

void chmin(int &a, int b){
    a = min(a, b);
}

void chmax(int &a, int b){
    a = max(a, b);
}

int n, smax = -INF, smin = INF, tmax = -INF, tmin = INF;
vector<int> s, t;

// 距離x以下で分割できるか
bool check(int x){
    vector<int> gs(n,2), gt(n,2);
    // 45度回転した平面で9つの領域に分類
    for(int i=0;i<n;i++){
        if(min(abs(s[i]-smin),abs(s[i]-smax)) > x) return false;
        else if(abs(s[i]-smax) > x) gs[i] = 0;
        else if(abs(s[i]-smin) > x) gs[i] = 1;
    }
    for(int i=0;i<n;i++){
        if(min(abs(t[i]-tmin),abs(t[i]-tmax)) > x) return false;
        else if(abs(t[i]-tmax) > x) gt[i] = 0;
        else if(abs(t[i]-tmin) > x) gt[i] = 1;
    }
    int cnt[4]{};
    for(int i=0;i<n;i++){
        if(gs[i]==0 && gt[i]==0) cnt[0]++;
        if(gs[i]==0 && gt[i]==1) cnt[1]++;
        if(gs[i]==1 && gt[i]==0) cnt[2]++;
        if(gs[i]==1 && gt[i]==1) cnt[3]++;
    }
    return (cnt[0]+cnt[3]==0 || cnt[1]+cnt[2]==0);
}

int main(){
    cin >> n;
    s.resize(n);
    t.resize(n);
    for(int i=0;i<n;i++){
        int x, y;
        cin >> x >> y;
        s[i] = x+y;
        t[i] = x-y;
        chmax(smax, s[i]); chmin(smin, s[i]);
        chmax(tmax, t[i]); chmin(tmin, t[i]);
    }
    int ok = 1e6, ng = 0;
    while(abs(ok-ng)>1){
        int mid = (ok+ng)/2;
        if(check(mid)){
            ok = mid;
        }else{
            ng = mid;
        }
    }
    cout << ok << endl;
    return 0;
}



Measured memory_bytes: 4384
#include <bits/stdc++.h>
using namespace std;
#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#define all(x) (x).begin(), (x).end()
#define Sort(x) sort((x).begin(), (x).end())
#define Reverse(x) reverse((x).begin(), (x).end())
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define REP(i, m, n) for (int i = m; i < n; i++)
#define INF INT_MAX
#define fcout cout << fixed << setprecision(15) // 15桁まで表示
#define en '\n'
using str = string;
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using puu = pair<ui, ui>;
using P = pair<int, int>;
using vi = vector<int>;
int gcd(int a, int b) {
  return b ? gcd(b, a % b) : a;
};
int lcm(int a, int b) {
  return a / gcd(a, b) * b;
};
int floor(int a, int b) {
  return (a + b - 1) / b;
};
int month[12] = {31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31};
template <class T> inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
};
template <class T> inline bool chmin(T &a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
};
const ll mod = 1000000007;
const double PI = acos(-1.0);
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(20) << setiosflags(ios::fixed);
  int n,y;
  cin >> n>>y;
  rep(i,n+1)rep(j,n-i+1){
    int x = 10000 * i + 5000 * j;
    if (y-x>=0 and (y-x)%1000==0 and i+j+(y-x)/1000==n){
      printf("%d %d %d", i, j, (y - x) / 1000);
      return 0;
    }
  }
  printf("-1 -1 -1");
}

Measured memory_bytes: 3756
#include <cstdio>
int n, Log[1005];
int main(){
	scanf("%d", &n);
	Log[1] = 0;
	for (register int i = 2; i <= n * 2; ++i) Log[i] = Log[i >> 1] + 1;
	for (register int i = 0; i < n; ++i)
		for (register int j = i + 1; j < n; ++j)
			printf("%d", Log[i ^ j] + 1), putchar(" \n"[j == n - 1]);
}


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

void merge(int *, int, int, int);
void mergeSort(int *, int, int);

int total;

void merge(int *getA, int left, int mid, int right)
{
    int n1 = mid - left;
    int n2 = right - mid;
    int L[n1], R[n2];
    int i;
    for (i = 0; i < n1; i++)
    {
        L[i] = getA[left + i];
    }
    for (i = 0; i < n2; i++)
    {
        R[i] = getA[mid + i];
    }
    L[n1] = INT_MAX;
    R[n2] = INT_MAX;
    int j = 0, k, l;
    i = 0;
    for (k = left; k < right; k++)
    {
        total++;
        if (L[i] <= R[j])
        {
            getA[k] = L[i];
            i = i + 1;
        }
        else
        {
            getA[k] = R[j];
            j = j + 1;
        }
    }
}

void mergeSort(int *getA, int left, int right)
{
    if (left + 1 < right)
    {
        int mid = (left + right) / 2;
        mergeSort(getA, left, mid);
        mergeSort(getA, mid, right);
        merge(getA, left, mid, right);
    }
}

int main()
{
    total = 0;
    int n;
    scanf("%d", &n);
    int *A;
    A = malloc((sizeof(int) * n));
    int pre;
    for (pre = 0; pre < n; pre++)
    {
        scanf(" %d", &A[pre]);
    }
    mergeSort(A, 0, n);
    for (pre = 0; pre < n; pre++)
    {
        printf("%d", A[pre]);
        if (pre < n - 1)
        {
            printf(" ");
        }
    }
    printf("\n%d\n", total);
    return 0;
}

// merge(A, left, mid, right)
//   n1 = mid - left;
//   n2 = right - mid;
//   L[0...n1], R[0...n2] を生成
//   for i = 0 to n1-1
//     L[i] = A[left + i]
//   for i = 0 to n2-1
//     R[i] = A[mid + i]
//   L[n1] = INFTY
//   R[n2] = INFTY
//   i = 0
//   j = 0
//   for k = left to right-1
//     if L[i] <= R[j]
//       A[k] = L[i]
//       i = i + 1
//     else
//       A[k] = R[j]
//       j = j + 1

// mergeSort(A, left, right)
//   if left+1 < right
//     mid = (left + right)/2;
//     mergeSort(A, left, mid)
//     mergeSort(A, mid, right)
//     merge(A, left, mid, right)


Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int m = sc.nextInt();
		sc.close();

		int result = n * (n - 1) / 2  + m * (m - 1) / 2;

		System.out.print(result);
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
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;
}
typedef long long int ll;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define endl "\n"
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

ll GCD(ll a, ll b)
{
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}

ll LCM(ll a, ll b)
{
    return a * b / GCD(a, b);
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll x, y;
    cin >> x >> y;
    ll k = GCD(x, y);
    cout << x + y + 2 - (k + 1) << endl;
}


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

using ll = long long;
using ull = unsigned long long;
using st = string;
using ch = char;
using db = double;
using bl = bool;
using vll = vector<long long>;
using vdb = vector<db>;
using vvll = vector<vll>;
using vst = vector<st>;
using vch = vector<char>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;
using vvpll = vector<vpll>;
#define rep(i, m, n) for (ll i = (ll)(m); i < (ll)(n); i++)
#define vrep(i, vec) for(auto& i : vec)
#define vin(vec) for(auto& i : vec) cin >> i
#define all(v) v.begin(), v.end()
template<class T> inline bool chmin(T& a, T b){if(a > b){a = b;return true;} return false;}
template<class T> inline bool chmax(T& a, T b){if(a < b){a = b;return true;} return false;}
const ll mod = 1000000007;
const ll inf = 1LL << 60;

int main(){
  ll n;
  cin >> n;
  vll p(n), q(n);
  vin(p); vin(q);
  st pst = "", qst = "";
  rep(i, 0, n){
    pst += p.at(i);
    qst += q.at(i);
  }
  ll ans = 0;
  
  if(pst < qst){
    do{
      bl check = true;
      rep(i, 0, n) if(p.at(i) != q.at(i))check = false;
      if(check) break;
      ans++;
    }while(next_permutation(all(p)));
  }
  else{
    do{
      bl check = true;
      rep(i, 0, n) if(p.at(i) != q.at(i))check = false;
      if(check) break;
      ans++;
    }while(next_permutation(all(q)));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 998244353;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
signed main() {
    int N,A,B;
    cin >> N >> A >> B;
    if(abs(A-B)%2 == 0) {
        cout << abs(A-B)/2 << endl;
    }
    else {
        cout << min(A-1,N-B)+1+(B-A-1)/2 << endl;
    }
}

Measured memory_bytes: 3636
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<set>
#include<sstream>
#include<vector>
using namespace std;
using uint = unsigned int;
using ll = long long;
const int M = 1e9 + 7;
const ll MLL = 1e18L + 9;
#pragma unused(M)
#pragma unused(MLL)
#ifdef LOCAL
#include"basic.hpp"
#else
template <class... T> void printl(T&&...){ }
template <class... T> void printc(T&&...){ }
template <class... T> void prints(T&&...){ }
#endif

int main(){
    int n; cin >> n;
    vector<ll> as(n), bs(n);
    for(int i=0;i<n;i++){
        cin >> as[i] >> bs[i];
    }
    ll ans = 0;
    for(int i=n-1;i>=0;i--){
        ll a = as[i] + ans;
        if(!a){
        }else if(a < bs[i]){
            ans += bs[i] - a;
        }else if(a > bs[i]){
            ll num = a / bs[i];
            while(a > bs[i] * num){ num++; }
            ans += num * bs[i] - a;
        }
    }
    cout << ans << '\n';
    return 0;
}


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

int main() {
  int N, n1, n2, n3, n4;
  cin >> N;
  
  n1 = N/1000;
  n2 = N/100%10;
  n3 = N/10%10;
  n4 = N%10;
  
  if (n2 == n3 && (n1 == n2 || n3 == n4)) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <unordered_set>

using namespace std;

int main() {
	unordered_set<string> S;
  	int n;
  	string s;
  	cin >> n;
  	for (int i = 0; i < n; i++) {
      cin >> s;
      S.emplace(s);
    }
  	cout << S.size() << endl;
}

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

int main(){
    int n;
    cin >> n;
    vector<string> s(n);
    for(int i=0;i<n;i++){
        cin >> s[i];
    }
    int a=0,b=0,ab=0;
    bool ba=true;
    for(int i=0;i<n;i++){
        if(s[i][0]=='B')b++;
        if(s[i][s[i].size()-1]=='A')a++;
        if(s[i][0]=='B' && s[i][s[i].size()-1]!='A')ba=false;
        if(s[i][0]!='B' && s[i][s[i].size()-1]=='A')ba=false;
        for(int j=0;j<s[i].size()-1;j++){
            if(s[i][j]=='A' && s[i][j+1]=='B')ab++;
        }
    }

    int x=0;
    if(ba && min(a,b))x++;
    cout << ab+min(a,b)-x << endl;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
#include <iostream>
#include <string.h>
#include <vector>
#include <algorithm>
using namespace std;

int main(){
  int n,m,s=0;
  cin >>n >>m;
  int c[m],d[m][n],t,p[m];
  for(int i=0;i<m;i++){
    for(int j=0;j<n;j++)
      d[i][j]==0;
  }
  for(int i=0;i<m;i++){
    cin >>c[i];
    for(int j=0;j<c[i];j++){
      cin >>t;
      d[i][t-1]=1;
    }
  }
  for(int i=0;i<m;i++)cin >>p[i];
  
  for (int bit = 0; bit < (1<<n); ++bit){
     
     int sum=0;
     for(int j=0;j<m;j++){
         int ans=0;
         for (int i = 0; i < n; ++i) {
             if (bit & (1<<i)) { 
                 if(d[j][i]==1)ans++;
             }
         }
         if(ans%2==p[j])sum++;
      }
    if (sum==m)s++;
   }
  
   cout << s << endl;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String str = "";
        int countAB = 0;
        int FinishedA = 0;
        int startB = 0;
        int startBFinishA = 0;

        for (int i = 0; i < N; i++) {
            str = sc.next();

            countAB += count(str);

            if (str.charAt(0) == 'B' && str.charAt(str.length() - 1) == 'A') {
                startBFinishA++;
            } else if (str.charAt(0) == 'B') {
                startB++;
            } else if (str.charAt(str.length() - 1) == 'A') {
                FinishedA++;
            }
        }

        if (startB > 0 && FinishedA > 0) {
            countAB += (startB >= FinishedA ? FinishedA : startB);
            countAB += startBFinishA;
        } else if (startB == 0 && FinishedA == 0) {
            countAB += (startBFinishA > 0 ? startBFinishA - 1 : startBFinishA);
        } else {
            countAB += (startBFinishA > 0 ? startBFinishA : 0);
        }
        System.out.println(countAB);
    }

    public static int count(String str) {
        int count = 0;
        for (int index = 0; (index = str.indexOf("AB", index)) != -1; index++) {
            count++;
        }
        return count;
    }
}


Measured memory_bytes: 29864
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	int n,x;
	cin >> n>>x;
	vector<int> a(n);
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}

	sort(all(a));
	int ans = 0;
	for(int i = 0; i < n; i++){
		x -= a[i];
		if(x >= 0) ans++;
		if(x < 0){
			break;
		}

		if(i == n-1 && x>0) ans--;
	}

	cout << ans << endl;

	return 0;
}

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

using namespace std;

int main(void) {
	int h, w, i, j, k, ans = 0;
	cin >> h >> w;
	vector<vector<int>> c(10, vector<int>(10)), d(h, vector<int>(w));
	for (i = 0; i < 10; i++) {
		for (j = 0; j < 10; j++) {
			scanf("%d", &c[i][j]);
		}
	}
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			scanf("%d", &d[i][j]);
		}
	}
	for (i = 0; i < 10; i++) {
		for (j = 0; j < 10; j++) {
			for (k = 0; k < 10; k++) {
				c[j][k] = min(c[j][k], c[j][i] + c[i][k]);
			}
		}
	}
	for (i = 0; i < h; i++) {
		for (j = 0; j < w; j++) {
			if (d[i][j] >= 0) {
				ans += c[d[i][j]][1];
			}
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 384
from collections import deque
# (sx, sy) から (gx, gy) への最短距離を求める
# 辿り着けないと INF
def bfs():
    # すべての点を INF で初期化
    d = [[float("inf")] * m for i in range(n)]
    # 移動4方向のベクトル
    dx = [1, 0, -1, 0]
    dy = [0, 1, 0, -1]
    sx = c[0]
    sy = c[1]
    gx = g[0]
    gy = g[1]

    # 周辺25マス移動
    dd = []
    for i in range(-2,3):
        for j in range(-2,3):
            dd.append([i,j])

    # スタート地点をキューに入れ、その点の距離を0にする
    que = deque([])
    que.append((sx, sy))
    d[sx][sy] = 0
    # キューが空になるまでループ
    while que:
        # キューの先頭を取り出す
        p = que.popleft()
        # 取り出してきた状態がゴールなら探索をやめる
        if p[0] == gx and p[1] == gy:
            break
        # 移動4方向をループ
        for i in range(4):
            # 移動した後の点を (nx, ny) とする
            nx = p[0] + dx[i]
            ny = p[1] + dy[i]
            # 移動が可能かの判定とすでに訪れたことがあるかの判定
            # d[nx][ny] != INF なら訪れたことがある
            if 0 <= nx < n and 0 <= ny < m and maze[nx][ny] == "." and d[nx][ny] > d[p[0]][p[1]]:
                # 移動できるならキューに入れ、その点の距離を p からの距離 +1 で確定する
                que.appendleft((nx, ny))
                d[nx][ny] = d[p[0]][p[1]]
        for i in range(25):
            # 移動した後の点を (nx, ny) とする
            nx = p[0] + dd[i][0]
            ny = p[1] + dd[i][1]
            # 移動が可能かの判定とすでに訪れたことがあるかの判定
            # d[nx][ny] != INF なら訪れたことがある
            if 0 <= nx < n and 0 <= ny < m and maze[nx][ny] == "." and d[nx][ny] == float("inf"):
                que.append((nx, ny))
                d[nx][ny] = d[p[0]][p[1]]+1

    return d[gx][gy]

n, m = map(int, input().split())
c = list(map(lambda x:int(x)-1,input().split()))
g = list(map(lambda x:int(x)-1,input().split()))
maze = [list(input()) for i in range(n)]

ans = bfs()
if ans == float("inf"):
    print(-1)
else:
    print(ans)

Measured memory_bytes: 142552
#include<iostream>
#include<string>

using namespace std;

int main(){
    string s;
    cin >> s;
    int head, last;
    for(int i=0;i<s.length();i++){
        if(s[i]=='A'){
            head=i;
            break;
        }
    }
    for(int i=s.length()-1;i>=0;i--){
        if(s[i]=='Z'){
            last=i;
            break;
        }
    }
    cout << last-head+1 << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <queue>
#include <utility>
#include <map>
#include <bitset>
#include <numeric>
#define ll long long
using namespace std;
using p = pair<ll, ll>;
ll dx[8]={ 0, 1, 0,-1, 1, 1,-1,-1}; // x軸方向への変位
ll dy[8]={ 1, 0,-1, 0, 1,-1, 1,-1}; // y軸方向への変位

int main(void) {
    ll n;
    cin >> n;
    ll a[n];
    for(ll i = 0; i < n; i++)
        cin >> a[i];
    ll ans = 1;
    ll INF = 1e+9+7;
    vector<ll> c(n+1, 0);
    for(ll i = 0; i < n; i++){
        ll b = a[i];
        if(b==0) ans*=(3-c[b]);
        else ans*=(c[b-1]-c[b]);
        ans%=INF;
        c[b]++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
use proconio::input;
use proconio::marker::Chars;

fn main() {
    input! {
        mut s: Chars,
    }
    s.reverse();

    let m = 2019;
    let n = s.len();

    let mut v = vec![0usize; n + 1];
    let mut base = 1;
    for i in 0..n {
        v[i + 1] = (v[i] + base * s[i].to_digit(10).unwrap() as usize) % m;
        base = (base * 10) % m;
    }
    // dbg!(&v);

    let mut counts = vec![0; 2019];
    for i in 0..(n + 1) {
        counts[v[i]] += 1;
    }

    let mut ans = 0i64;
    for i in 0..2019 {
        ans += counts[i] * (counts[i] - 1) / 2;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4556
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int A, B;
		A = sc.nextInt();
		B = sc.nextInt();
		if (B % A == 0) {
			System.out.println(A + B);
		} else {
			System.out.println(B - A);
		}

		sc.close();

	}

}

Measured memory_bytes: 21844
#include <iostream>
#define llint long long

using namespace std;

llint N, K;
llint w[100005], d[100005];


llint count(llint pos)
{
	llint ret = 0;
	for(int i = 0; i < N; i++){
		if(pos < w[i]) continue;
		ret += (pos - w[i]) / d[i] + 1;
	}
	return ret;
}


int main(void)
{
	cin >> N >> K;
	for(int i = 0; i < N; i++){
		cin >> w[i] >> d[i];
	}
	
	llint ub = 2e18+5, lb = 0, mid;
	while(ub - lb > 1){
		mid = (ub + lb) / 2;
		if(count(mid) >= K) ub = mid;
		else lb = mid;
	}
	
	cout << ub << endl;
	return 0;
}

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

const int N = 500009;
const int mod = 1000000007;

#define IOS                               \
	ios_base::sync_with_stdio(false); \
	cin.tie(0);                       \
	cout.tie(0);
#define int long long int
#define endl "\n"
#define sz(a) (int)((a).size())
#define all(a) a.begin(), a.end()

int n;

void pre()
{
}

int32_t main()
{
	IOS;
	pre();
	string s,t;
	cin>>n>>s>>t;
	string ans = "";
	for(int i=0;i<(2*n);i++)
	{
		if(i%2)
		{
			ans+=t[i/2];
		}
		else
		{
			ans+=s[i/2];
			
		}
		
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
// In the name of god
#include <iostream>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <iomanip>
#include <assert.h>
#include <ctime>
#include <queue>
#include <set>
#include <map>
#include <vector>
#include <list>
#include <bitset>
#define sqr(a) ((a)*(a))
#define all(a) (a).begin(), (a).end()
using namespace std;
 
template <typename T>
T next_int() {
    T x = 0, p = 1;
    char ch;
    do { ch = getchar(); } while(ch <= ' ');
    if(ch == '-') {
        p = -1;
        ch = getchar();
    }
    while(ch >= '0' && ch <= '9') {
        x = x * 10 + (ch - '0');
        ch = getchar();
    }
    return p * x;
}
 
string next_token() {
    char ch;
    string ans = "";
    do { ch = getchar(); } while(ch <= ' ');
    while(ch > ' ') {
        ans += ch;
        ch = getchar();
    }
    return ans;
}
 
const long long INF = (long long)1e18;
const int INFINT = (int)1e9 + 227 + 1;
const int MAXN = (int)1e6 + 227 + 1;    
const int MOD = (int)1e9 + 7;
const long double EPS = 1e-9;
 
long long bin_pow(long long a, long long b) {
    if(!b) return 1;
    long long ans = bin_pow(a, b / 2);
    ans = ans * ans % MOD;
    if(b % 2) ans = ans * a % MOD;
    return ans;
}

int a[501][501];

int main() {
    // freopen(".in", "r", stdin);

    int n, m, N, M; cin >> n >> m >> N >> M;

    int x = (int)1e9 / (N * M);

    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            a[i][j] = (((i + 1) % N == 0 && (j + 1) % M == 0) ? -(x * (N * M - 1) + 1) : x);

    long long sum = 0;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < m; j++)
            sum += a[i][j];

    if(sum <= 0) {
        puts("No");
        return 0;
    }

    puts("Yes");
    for(int i = 0; i < n; i++) {
        for(int j = 0; j < m; j++)
            cout << a[i][j] << " ";
        puts("");
    }
}


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

int main() {
  long N;
  cin >> N;
  
  vector<long> A(N+1);
  vector<long> D(N+1);
  for(long i=1; i<N+1; i++){
    long t;
    cin >> t;
    A.at(i) = t;
    D.at(t)++;
  }
  
  long pat=0;
  for(long i=1; i<N+1; i++){
    long temp;
    if(D.at(i)!=0){
      temp = (D.at(i)*(D.at(i)-1))/2;
      pat += temp;    
    }
  }
  //cout << pat << "pat" << endl;
  
  for(long i=1; i<N+1; i++){
    cout << pat-D.at(A.at(i))+1 << endl;
  }
   
  return 0;
}



Measured memory_bytes: 5760
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define exp pow(10,-9)
#define F first
#define S second
#define PB push_back 
#define MP make_pair
#define daman ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lowercase(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define uppercase(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
main(){
	int n;
	cin>>n;
	int numb,count = 0;
	
	for(int i=1;i<=n;i++)
	{
		cin>>numb;
		if(i%2==1 && numb%2 == 1)
			count++;
	}
	cout<<count<<"\n";
}

Measured memory_bytes: 3596
import random
from collections import deque
import sys
sys.setrecursionlimit(10**7)

def input():
    return sys.stdin.readline().strip()

# スペース区切りの入力を読み込んで数値リストにして返します。
def get_nums_l():
    return [ int(s) for s in input().split(" ")]

def log(*args):
    print("DEBUG:", *args, file=sys.stderr)

n,a,b,c = get_nums_l()
d = {
    "A": a,
    "B": b,
    "C": c
}
S = []
for _ in range(n):
    S.append(input())

def dfs(i, x, history):

    if d[S[i][1-x]] == 0:
        return False

    d[S[i][x]] += 1
    d[S[i][1-x]] -= 1

    history.append(S[i][x])

    if i == n-1:
        return True

    nex = random.randint(0, 1)

    ok = dfs(i+1, nex, history)
    if ok:
        return ok

    ok = dfs(i+1, 1-nex, history)

    if ok:
        return ok

    # バックトラック
    history.pop()
    d[S[i][x]] -= 1
    d[S[i][1-x]] += 1

    return False

history = deque()
ok = dfs(0, 0, history) or dfs(0, 1, history)

print("Yes" if ok else "No")
if ok:
    for s in history:
        print(s)


Measured memory_bytes: 182932
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.Comparator;
import java.util.PriorityQueue;
import java.util.Scanner;

public class Main {
	static int N;
	static int M;
	static int[][] h;
	static int[] h2;
	static ArrayList<Edge>[] g;

	@SuppressWarnings("unchecked")
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while (true) {
			N = sc.nextInt();
			M = sc.nextInt();
			if (N == 0 && M == 0)
				break;
			h = new int[N][2];
			h2 = new int[N];
			for (int i = 0; i < N; ++i) {
				h[i] = new int[] { i, sc.nextInt() };
				h2[i] = h[i][1];
			}
			Arrays.sort(h, new Comparator<int[]>() {
				@Override
				public int compare(int[] o1, int[] o2) {
					return -Integer.compare(o1[1], o2[1]);
				}
			});
			ArrayList<Edge> elis = new ArrayList<>();
			g = new ArrayList[N];
			for (int i = 0; i < N; ++i)
				g[i] = new ArrayList<>();
			for (int i = 0; i < M; ++i) {
				int a = sc.nextInt() - 1;
				int b = sc.nextInt() - 1;
				int c = sc.nextInt();
				g[a].add(new Edge(a, b, c));
				g[b].add(new Edge(b, a, c));
				elis.add(new Edge(a, b, c));
				elis.add(new Edge(b, a, c));
			}

			Collections.sort(elis);
			DJSet ds = new DJSet(N);
			long ans = 0;
			for (int i = 0; i < N; ++i) {
				while (i + 1 < N && h[i][1] == h[i + 1][1])
					++i;
				int t = h[i][1];
				int v = h[i][0];
				for (Edge e : elis) {
					if (h2[e.src] >= t && h2[e.dst] >= t && !ds.equiv(e.src, e.dst)) {
						ds.setUnion(e.src, e.dst);
						ans += e.cost;
					}
				}
				if (ds.size(v) != i + 1) {
					ds.clear();
					ans = 0;
				}
			}

			System.out.println(ans);
		}
	}

	static class Edge implements Comparable<Edge> {
		int src;
		int dst;
		int cost;

		public Edge(int src, int dst, int cost) {
			this.src = src;
			this.dst = dst;
			this.cost = cost;
		}

		@Override
		public int compareTo(Edge o) {
			return Integer.compare(cost, o.cost);
		}
	}

	static class DJSet {
		int n;
		int[] upper;

		public DJSet(int n) {
			this.n = n;
			upper = new int[n];
			Arrays.fill(upper, -1);
		}

		int root(int x) {
			return upper[x] < 0 ? x : (upper[x] = root(upper[x]));
		}

		boolean equiv(int x, int y) {
			return root(x) == root(y);
		}

		boolean setUnion(int x, int y) {
			x = root(x);
			y = root(y);

			if (x != y) {
				if (upper[x] < upper[y]) {
					int d = x;
					x = y;
					y = d;
				}
				upper[y] += upper[x];
				upper[x] = y;
			}
			return x != y;
		}

		void clear() {
			Arrays.fill(upper, -1);
		}

		int size(int x) {
			return -upper[root(x)];
		}

	}
}

Measured memory_bytes: 177012
a = 0
b = 0
inp = []

i = 0
j = 0

while True:
    inp.append(list(map(int, input().split())))
    if inp[i][0] == 0 and inp[i][1] == 0:
        break

    i += 1

for j in range(i):
    if inp[j][0] <= inp[j][1]:
        print("%s %s" % (inp[j][0], inp[j][1]))
    else:
        print("%s %s" % (inp[j][1], inp[j][0]))


Measured memory_bytes: 5980
import java.util.HashSet;
import java.util.Scanner;

public class Main{
	public static int[] color;
	public static int[] state;
	public static int[] cnum;
	public static int n;
	public static void main(String[] args){
		Scanner in = new Scanner(System.in);
		while(true){
			n = in.nextInt();
			if(n == 0) return;
			Circle[] cir = new Circle[n];
			color = new int[4];
			state = new int[n];
			cnum = new int[4];
			for(int i=0; i<n; i++){
				cir[i] = new Circle(in.nextInt()
						, in.nextInt()
						, in.nextInt()
						, in.nextInt()-1);
				color[cir[i].color] |= 1<<i;
				cnum[cir[i].color]++;
				for(int j=0; j<i; j++){
					if(cir[i].cross(cir[j])) state[i] |= 1<<j;
				}
			}
			res = n;
			set = new HashSet<Integer>();
			dfs((1<<n)-1);
			System.out.println(n-res);
		}
	}
	
	public static HashSet<Integer> set;
	public static int res;
	public static void dfs(int all){
		if(set.contains(all)) return;
		set.add(all);
		res = Math.min(res, Integer.bitCount(all));
		for(int i=0; i<4; i++){
			int col = color[i] & all;
			if(Integer.bitCount(col) < 2) continue;
			for(int j=1, i1=0; i1<n; i1++,j<<=1){
				if((col&j) == 0 || (state[i1]&all) > 0) continue;
				for(int k=j<<1, i2=i1+1; i2<n; i2++,k<<=1){
					if((col&k) == 0 || (state[i2]&all) > 0) continue;
					dfs(all&~j&~k);
				}
			}
		}
	}
}

class Circle{
	int x, y, r;
	int color;
	public Circle(int x, int y, int r, int color){
		this.x = x;
		this.y = y;
		this.r = r;
		this.color = color;
	}
	
	public boolean cross(Circle c){
		return sq(x-c.x)+sq(y-c.y) < sq(r+c.r);
	}
	
	public int sq(int a){
		return a*a;
	}
}

Measured memory_bytes: 196424
N,M,K=map(int,input().split())
A =list(map(int,input().split()))
B =list(map(int,input().split()))
Sum = 0
Al = [0]
Bl = [0]
for i in range(N):
    Sum += A[i]
    Al.append(Sum)
Sum = 0
for j in range(M):
    Sum += B[j]
    Bl.append(Sum)
ans, j = 0, M
for i in range(N+1):
    if Al[i] > K:
        break
    while Bl[j] > K - Al[i]:
        j -= 1
    ans = max(ans,i+j)
print(ans)
        

Measured memory_bytes: 47452
#include<bits/stdc++.h>
using namespace std;
int n,a,b,A,B,aa,bb,aaa,bbb;
string s;
bool judge(int a,int b,int A,int B)
{
    A-=b;
    B-=a;
    return A>=0&&B>=0&&A==B;
}
vector<pair<int,int>>v;
bool cmp(pair<int,int>x,pair<int,int>y)
{
    return min(x.first,y.second)>min(x.second,y.first);
}
int main()
{
    srand(time(0));
    cin>>n;
    while(n--)
    {
        cin>>s;
        int l=0,r=0;
        for(int i=0;i<s.size();i++)
            if(s[i]=='(') r++;
        else
        {
            if(r) r--;
            else l++;
        }
        if(l&&r) v.push_back({l,r});
        else if(l) A+=l;
        else if(r) B+=r;
    }
    sort(v.begin(),v.end(),cmp);
    for(pair<int,int>x:v)
    {
        int l=x.first,r=x.second;
        int k=max(min(a,r),min(b,l));
        a=a+l-k;
        b=b+r-k;
    }
    if(judge(a,b,A,B))
        printf("Yes\n");
    else
    {
        printf("No\n");
    }
}


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

using namespace std;

#define ll long long
#define ld long double

#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

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

ll INF = (ll) 1e20;
int iINF = (int) 1e20;
ll mod = (ll) 1e9 + 7;

signed main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    ll n;
    cin >> n;
    ll ans = 0;
    vector <ll> d(n);
    for(int i = 0; i < n; ++i) {
        cin >> d[i];
    }
    for(int i = 0; i < n; ++i) {
        for(int j = i + 1; j < n; ++j) {
            ans += d[i] * d[j];
        }
    }
    cout << ans;
}

Measured memory_bytes: 256
from math import sqrt
n = int(input())
p = 0

for i in range(n):
    x = int(input())
    if x == 2:
        p += 1
    elif x%2 == 1:
        j=3
        f = 0
        while j < (int(sqrt(x))+1):
            if x%j == 0:
                f = 1
                break
            else:
                j += 2
        if f == 0:
            p += 1
print(p)


Measured memory_bytes: 5676
#include<bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=(a);i<=(b);i++)
#define re(i,a,b) for(int i=(a);i<(b);i++)
#define repd(i,a,b) for(int i=(a);i>=(b);i--)
#define per(i,a,b) for(int i=(a);i>=(b);i--)
#define Rep(i,a,b) for(int i=(a);i<(b);i++)
#define fi first
#define se second
#define clr(a) memset(a,0,sizeof(a));
#define il inline
#define sz(a) ((int)o.size())
#define run(x) for(int k=head[x];k;k=e[k].ne)
#define v e[k].t
#define all(a) o.begin(),o.end()
#define pb push_back 
#define w1 first
#define w2 second
#define adm(a,b,c) {a=a+b;if(a>=c)a-=c;else if(a<0)a+=c;}
typedef double db;
typedef long long ll;typedef long double ld;typedef unsigned long long ull;
typedef pair<int,int> pa;
const int N=100+5,INF=1e9,mod=1e9+7;
const ll linf=1e18;const double eps=1e-8,pi=acos(-1);
il int gmin(int &a,int b){if(a>b)a=b;}il ll gmin(ll &a,ll b){if(a>b)a=b;}il int gmax(int &a,int b){if(a<b)a=b;}il ll gmax(ll &a,ll b){if(a<b)a=b;}
il void read(ll&x){ll f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il ll read(ll&x,ll&y){read(x);read(y);}
il void read(int&x){int f=1,t=0;char ch=getchar();while(ch<'0'||ch>'9'){if(ch=='-')f=-1;ch=getchar();}while(ch>='0'&&ch<='9'){t=t*10+ch-'0';ch=getchar();}x=t*f;}il int read(int&x,int&y){read(x);read(y);}
il void read(int&a,int&b,int&c){read(a);read(b);read(c);}il void read(ll&a,ll&b,ll&c){read(a);read(b);read(c);}
il int read(){int x;read(x);return x;}
il void judge(){
	freopen("dato.in","r",stdin);
	freopen("dato.out","w",stdout);
}
int n,a[N],f[N][N][N];
void ad(int&x,int y){x+=y;x%=mod;}
int main(){
	read(n);rep(i,1,n+n-1)read(a[i]);
	sort(a+1,a+1+2*n-1);
	f[n][1][1]=1;
	repd(i,n,2)
	rep(j,1,2*(n-i)+1)rep(k,1,2*(n-i)+1)if(f[i][j][k]){
		int nj=j+(a[i]!=a[i-1])+(a[2*n-i]!=a[2*n-i+1]),nk=k+(a[i]!=a[i-1]);
		ad(f[i-1][nj][nk],f[i][j][k]);
		rep(o,1,nk-1)
			ad(f[i-1][nj-(nk-o-1)][o],f[i][j][k]);
		rep(o,nk+1,nj)
			ad(f[i-1][nj-(o-nk-1)][nk+1],f[i][j][k]);
	}int res=0;
	rep(i,1,2*n-1)rep(j,1,2*n-1)ad(res,f[1][i][j]);
	cout<<res<<endl;
}

Measured memory_bytes: 3456
#!/usr/bin/env python3
import sys


def solve(X: int, A: int, B: int):
    expire = B - A

    if expire <= 0:
        print('delicious')
        return
    elif X - expire >= 0:
        print('safe')
        return
    else:
        print('dangerous')
        return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    X = int(next(tokens))  # type: int
    A = int(next(tokens))  # type: int
    B = int(next(tokens))  # type: int
    solve(X, A, B)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>

using namespace std;

int main()
{
    int n, m, ite;
    cin >> n >> m;
    while(m){
        cin >> ite;
        n -=  ite;
        if(n < 0){
            n = -1;
            break;
        }
        m--;
    }

    cout << n << endl;

    return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
using lint = long long int;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, begin, end) for(int i=(begin),i##_end_=(end);i<i##_end_;i++)
#define REP(i, n) FOR(i,0,n)
template<typename T> bool mmax(T &m, const T q) { if (m < q) {m = q; return true;} else return false; }
template<typename T> bool mmin(T &m, const T q) { if (m > q) {m = q; return true;} else return false; }

lint tos(lint n, lint X, lint D)
{
    return X * n + D * n * (n - 1) / 2;
}

int main()
{
    lint N, X, D;
    cin >> N >> X >> D;
    if (!D)
    {
        cout << (X != 0) * N + 1 << endl;
        return 0;
    }
    if (D < 0) {
        X += D * (N - 1);
        D *= -1;
    }

    int g = (X != 0 ? __gcd(abs(X), D) : D);
    X /= g, D /= g;

    map<int, vector<plint>> Q;
    REP(i, N + 1) {
        lint lo = 9e18, hi = -9e18;
        Q[i % D].emplace_back(tos(i, X, D), tos(i, X + D * (N - 1), -D));
    }
    lint ret = 0;
    for (auto &vec : Q) {
        sort(ALL(vec.second));
        lint h = vec.second[0].first - D;
        for (auto x : vec.second) {
            mmax(h, x.first - D);
            ret += max((x.second - h) / D, 0LL);
            mmax(h, x.second);
        }
    }
    cout << ret << endl;
}


Measured memory_bytes: 22144
import java.util.Scanner;

public class Main {

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

        final int n = sc.nextInt();
        final int k = sc.nextInt();

        final int[] p = new int[n];
        for (int i = 0; i < n; i++) {
            p[i] = sc.nextInt();
        }

        final double[] evs = new double[1001];
        for (int i = 1; i <= 1000; i++) {
            evs[i] = getExpectedValue(i);
        }

        double ans = Double.MIN_VALUE;
        final double[] sum = new double[n];
        sum[0] = evs[p[0]];
        for (int i = 1; i < n; i++) {
            sum[i] = evs[p[i]] + sum[i-1];
            if (i >= k) {
//                System.out.println(i + "," + (i - k));
                ans = Math.max(ans, sum[i] - sum[i - k]);
            }
        }

//        for (double s : sum) System.out.println(s);

        if (n == k) {
            ans = Math.max(ans, sum[n-1]);
        }

        System.out.println(ans);
    }

    private static double getExpectedValue(final int max) {
        double result = 0;
        for (double j = 1; j <= max; j++) {
            result += j;
        }
        return result / max;
    }
}


Measured memory_bytes: 64708
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <string>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
using namespace std;
#define rep(i,n) for (int i=0;i<n;i++)
vector <long long> A;
vector <long long> B;
int N;
int M = 30;
int main(void) {
	long long ans = 0;
	long long T = 1;
	cin >> N;
	rep(i, N) { 
		long long p;
        scanf("%d ",&p);
		A.push_back(p);
	}
	rep(i, N) { 
		long long p;
        scanf("%d ",&p);
		B.push_back(p);
	}
	rep(k, M) {
		vector <long long> C;
		vector <long long> D;
		rep(i, N) { 
			C.push_back(B[i] % (2 * T));
			D.push_back(A[i] % (2 * T));
		}
		sort(C.begin(),C.end());
		long long tmp = 0;
		rep(i, N) {
			tmp += lower_bound(C.begin(), C.end(), 2 * T - D[i]) - C.begin();
			tmp -= lower_bound(C.begin(), C.end(), 1 * T - D[i]) - C.begin();
			tmp += lower_bound(C.begin(), C.end(), 4 * T - D[i]) - C.begin();
			tmp -= lower_bound(C.begin(), C.end(), 3 * T - D[i]) - C.begin();
		}
		ans += T * (tmp % 2);
		T = T * 2;
	}
	cout << ans << endl;
	return 0;
}


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

using namespace std;

int main(void){
    
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    
    while (true){
        
        c -= b;
        if (c <= 0){
            cout << "Yes" << endl;
            return 0;
        }
        
        a -= d;
        if (a <= 0){
            cout << "No" << endl;
            return 0;
        }
    }
    
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define ll long long int

using namespace std;

int main ()
{
	
	int n;
	cin >> n;
	int a[n];
	for (int i=0; i<n; i++){
		cin >> a[i];
	}
	int sum = 0;
	for (int i=0; i<n-1; i++){
		for (int j=i+1; j<n; j++){
			sum += a[i] * a[j];
		}
	}
	cout << sum << endl;
}

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

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int testcase=1;
    
    for(int p=0;p<testcase;p++){
    ll n=0,x=0;
    cin>>n>>x;
    ll array[n]={0};
	ll totalsum=0;
    for(int i=0;i<n;i++){
    cin>>array[i];
    totalsum+=array[i];
    }
    if(totalsum<x){
        cout<<n-1;
    }
else if(totalsum==x)
cout<<n;
    else
    {
        sort(array,array+n);
        ll counter=0;
        ll sum=x;
        ll i=0;
        while(sum>=0){
       // cout<<array[i];
        sum-=array[i];
    	if(sum<0)
    	break;        
	    i++;
        counter++;
        }
        cout<<counter;
    }
     
    
    
    
        
    }

    return 0;
}


Measured memory_bytes: 3676