akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define ll long long
#define pll pair<ll, ll>
#define pii pair<int, int>
#define f first
#define se second
#define pb push_back
 
 
using namespace std;
 
 
const int N = 4e3 + 219;
const ll M = 3e5 + 19;
const ll inf = 1e15 + 10;
const ll mod = 1e9 + 7;
 
 
ll n, k, a[N], r[N], p[N], s[N], ans = 0; 
vector <ll> d; 
 
 
int main() {
    cin >> n >> k;
    ll S = 0;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        S += a[i];
    }
    ll t = sqrt(S + 0.5);
    for (ll i = 1; i <= t; i++) {
        if (S % i == 0) {
            d.pb(i);
            if (S / i != i)
                d.pb(S / i);
        }
    }
    for (int i = 0; i < d.size(); i++) {
        for (int j = 1; j <= n; j++)
            r[j] = a[j] % d[i];
        sort(r + 1, r + n + 1);
        p[0] = s[n + 1] = 0;
        for (int j = 1; j <= n; j++)
            p[j] = p[j - 1] + r[j];
        for (int j = n; j >= 1; j--) {
            if (r[j] == 0)
                s[j] = s[j + 1];
            else
                s[j] = s[j + 1] + d[i] - r[j];
        }
        bool is = 0;
        for (int j = 1; j < n; j++) {
            if ((p[j] - s[j + 1]) % d[i] == 0) {
                if (p[j] >= s[j + 1] && p[j] <= k) {
                    is = 1;
                    break;
                }
                if (p[j] < s[j + 1] && s[j + 1] <= k) {
                    is = 1;
                    break;
                }
            }
        }
        if (is)
            ans = max(ans, d[i]);
    }
    cout << ans;
}

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

int main() 
{
	int n;
	scanf("%d", &n);
	int a[n];
	long long dp[n+1][n+1];
	memset(dp, 0, sizeof(dp));
	for(int i = 0; i < n; i++) {
		scanf("%d", &a[i]);
		dp[i][i] = a[i];
	}
	for(int i = 1; i < n; i++) {
		for(int j = 0; j < n; j++) {
			if(i + j >= n) continue;
			dp[j][j+i] = max(a[j] - dp[j+1][j+i], a[j+i] - dp[j][j+i-1]);
		}
	}
	printf("%lld\n", dp[0][n-1]);
}

Measured memory_bytes: 74132
N, M = map(int, input().split())
a = []
for i in range(M):
  a.append(int(input()))
dp = []
dp.append(1)
if a:
  cantuse = a.pop(0)
  if cantuse == 1:
    dp.append(0)
    if a:
      cantuse = a.pop(0)
  else:
    dp.append(1)
else:
  cantuse = -1
  dp.append(1)

for i in range(N-1):
  if (i+2) == cantuse:
    dp.append(0)
    if a:
      cantuse = a.pop(0)
  else:
    dp.append(dp[-1]+dp[-2])
print(dp[-1]%1000000007)

Measured memory_bytes: 460020
a = []
b = []
res = [0]*4
two = 0

for i in range(3):
    a1,b1 = map(int,input().split())
    a.append(a1)
    b.append(b1)

for i in range(3):
    for j in range(1,4):
        if a[i]==j:
            res[j] += 1
        if b[i]==j:
            res[j] += 1

for i in range(4):
    if res[i] == 2:
        two += 1
else:
    if two==2:
        print("YES")
    else:
        print("NO")




Measured memory_bytes: 3064
#include<iostream>

using namespace std;

int main(){
  int H,W,N,num,iti=0,lop3=0,ws=0,hs=0;

  cin>>H;
  cin>>W;
  cin>>N;
  int a[H*W],b[H*W];

  for(int lop=0;lop<N;lop++){
    cin>>num;
    for(int lop2=iti;lop2<num+iti;lop2++){
      a[lop2]=lop+1;
    }
    iti+=num;
  }


  /*while(lop3<W*H){
    //右
    for(int lop=0+W*ws;lop<W-ws;lop++){
      b[lop]=a[lop3];
      lop3++;
    }
    ws++;
    if(lop3==W*H){
      break;
    }
    //下
    for(int lop=0+H*hs;lop<W-ws;lop++){
      b[lop]=a[lop3];
      lop3++;
    }
    hs++;
    if(lop3==W*H){
      break;
    }
    //左
    for(int lop=0*W+ws;lop<W-ws;lop++){
      b[lop]=a[lop3];
      lop3++;
    }
    if(lop3==W*H){
      break;
    }
    //上
    for(int lop=0+H*hs;lop<W-ws;lop++){
      b[lop]=a[lop3];
      lop3++;
    }
    if(lop3==W*H){
      break;
    }
  }*/

  //yagiプロの参考プログラム
  while(lop3<H*W){
    for(int lop=0;lop<W;lop++){
      cout<<a[lop3];
      if(lop!=W-1){
        cout<<' ';
      }
      lop3++;
    }
    cout<<endl;
    if(lop3>=W*H)break;
    lop3+=W;
    for(int lop=0;lop<W;lop++){
      lop3--;
      cout<<a[lop3];
      if(lop!=W-1){
        cout<<' ';
      }
    }
    cout<<endl;
    lop3+=W;
    if(lop3>=W*H){
      break;
    }
  }
  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
using namespace std;

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

const int N = 2010;

int ans[N] = {0};

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(nullptr);
	int x, y, a, b, c;
	cin >> x >> y >> a >> b >> c;
	vi p(a), q(b), r(c);
	vector<pii> z;
	for(int i = 0 ; i < a ; i++) {
		cin >> p[i];
		z.push_back({p[i], 0});
	}
	for(int i = 0 ; i < b ; i++) {
		cin >> q[i];
		z.push_back({q[i], 1});
	}
	for(int i = 0 ; i < c ; i++) {
		cin >> r[i];
		z.push_back({r[i], 2});
	}
	sort(z.rbegin(), z.rend());
	int tmp = x + y;
	ll ans = 0;
	int cnt[3] = {0, 0, 0};
	for(int i = 0 ; i < z.size() ; i++) {
		int val = z[i].first;
		int curt = z[i].second;
		if (cnt[0] == x and curt == 0) continue;
		if (cnt[1] == y and curt == 1) continue;
		if (cnt[0] + cnt[1] + cnt[2] == tmp) break;
		cnt[curt]++;
		ans += val;
	}
	cout << ans;
}


Measured memory_bytes: 7664
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cctype>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cstring>
#include <string>
#include <sstream>
#include <algorithm>
#include <iomanip>
using namespace std;

typedef vector<int> VI;
typedef vector<VI> VII;
typedef pair<int, int> PII;
typedef long long ll;

#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back;
#define MP make_pair

const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = INT_MAX / 3;

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

#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<double, int> P;

vector<P> a;

int main(void){
  for(int i = 0; i < 3; i++){
    vector<P> p(8, P(0.0, 0));
    for(int j = 0; j < 8; j++) cin >> p[j].second >> p[j].first;
    sort(ALL(p));
    cout << p[0].second << " " << p[0].first << endl;
    cout << p[1].second << " " << p[1].first << endl;
    p.erase(p.begin()); p.erase(p.begin());
    a.insert(a.begin(), p.begin(), p.end());
  }
  sort(ALL(a));
  cout << a[0].second << " " << a[0].first << endl;
  cout << a[1].second << " " << a[1].first << endl;
  return 0;
}

Measured memory_bytes: 1304
#include <iostream>
#include <vector>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
using namespace std;
using VI = vector<int>;

int main() {
  int a, b, c, d; cin >> a >> b >> c >> d;
  VI sw(101, 0);
  sw[a]++;
  sw[b]--;
  sw[c]++;
  sw[d]--;
  int ans = 0;
  FOR(i, 0, 100) {
    sw[i + 1] += sw[i];
    if (sw[i] == 2) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <string>
#include <iostream>
#include <math.h>

using namespace std;



int main(void){

    

    long x;
    cin >>x;
    string ans;

    long i,j;
    for(long a = -200; a < 200; a++) {
        for(long b = a+1; b<200; b++) {
            if(b*b*b*b*b-a*a*a*a*a==x) {
                i = b;
                j = a;
            }
        }
    }




    cout<< i<<" "<<j;


    return 0;
}

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

using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
#define inf 1ll<<60
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
#define int llong
#define be(x) x.begin(), x.end()
typedef pair<int, int> P;


signed main(){
	int n, k;
	cin >> n >> k;

cerr << n/2 + n%2 << endl;
	if(n/2 + n%2 >= k)
		cout << "YES" << endl;
	else
		cout << "NO" << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <climits>
#include <vector>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <stack>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>

#define int long long
#define MOD7 1000000007
#define MOD9 1000000009

#define rep(i, n) for (int i = 0; i < (n); i++)
#define itrep(i, a) for (auto i = (a).begin(); i != (a).end(); i++)
#define REP(i, a, n) for (int i = (a); i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define mp(a, b) make_pair((a), (b))

using namespace std;

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

template<class T> void inputVector(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < v.size(); i++) cin >> v[i];
}

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

    vector<string> strs(N);
    rep(i, N) cin >> strs[i];

    int cnt[4] = {0, 0, 0, 0};

    int ret = 0;
    for (auto &S : strs) {
        if (S[0] != 'B') {
            if (S.back() != 'A') cnt[0]++;
            else cnt[1]++;
        } else {
            if (S.back() != 'A') cnt[2]++;
            else cnt[3]++;
        }
        rep(i, S.size() - 1) {
            if (S[i] == 'A' && S[i + 1] == 'B') ret++;
        }
    }

    rep(i, 4) cerr << cnt[i] << " ";
    cerr << endl;

    if (cnt[3] > 1) {
        ret += cnt[3] - 1;
        cnt[3] = 1;
    }

    if (cnt[3] == 1) {
        if (cnt[1] > 0) {
            cnt[1]--;
            ret++;
        }
        if (cnt[2] > 0) {
            cnt[2]--;
            ret++;
        }
    }

    int tmp = min(cnt[1], cnt[2]);
    ret += tmp;
    cnt[1] -= tmp;
    cnt[2] -= tmp;

    cout << ret << endl;

    return 0;
}


Measured memory_bytes: 1144
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#define INF 0x3f3f3f3f
#define MOD 1000000007
#define PI 4*atan(1.0)
typedef long long ll;
typedef long double ld;
using namespace std;
int dx[4]={0,0,-1,1};
int dy[4]={-1,1,0,0};

int main(){
	int X;
	cin>>X;
	int now=0;
	int i=0;
	for(i=0;1;i++){
		if(now==X){
			break;
		}
		else if(now<X){
			now+=i+1;
		}
		else if(now>X){
			break;
		}
	}
	cout<<i<<endl;
}

Measured memory_bytes: 256
#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 (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ll long long
#define lld long double
#define ALL(x) x.begin(), x.end()
using namespace std;

int main(int argc, char const *argv[])
{
    int n, k;
    cin >> n >> k;
    vector<int> v(n);
    rep(i, n) cin >> v[i];
    int vmin = (1 << 30);
    int bestpro = 0;
    int numpro = 0;
    rep(i, n)
    {
        int curpro = max(0, v[i] - vmin);
        cerr << curpro << endl;
        if (curpro == bestpro)
        {
            numpro++;
        }
        else if (curpro > bestpro)
        {
            bestpro = curpro;
            numpro = 1;
        }
        vmin = min(vmin, v[i]);
    }
    cout << numpro << endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
int n;
int ten[10]={1,10,100,1000,10000,100000,1000000,10000000,100000000};
int aaa[4]={3,5,7};
int result=0;


int main(){
	int b,as,bs;
	int result=9999;
	scanf("%d",&n);
	
	for(int a=1;a<n;a++)
	{
		b=n-a;
		as=a%10+(a/10)%10+(a/100)%10+(a/1000)%10+(a/10000)%10+(a/100000)%10;
		bs=b%10+(b/10)%10+(b/100)%10+(b/1000)%10+(b/10000)%10+(b/100000)%10;
		if(as+bs<result)
		{
			result=as+bs;
		}
	}
	printf("%d",result);
	}

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

#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;

int main()
{
    int a[13] = {0, 1, 2, 1, 4, 1, 4, 1, 1, 4, 1, 4, 1};
    int x, y;
    cin >> x >> y;
    a[x] == a[y] ? OP("Yes") : OP("No");

    return 0;
}

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

    using namespace std;
    typedef long long ll;
    # define M_PI  3.14159265358979323846
    const int MOD=1e9+7;

    vector<ll>a(100005);
    void solve(){
        int n;
        cin>>n;
        ll sum=0;
        for(int i=0;i<n;i++){
            int k;
            cin>>k;
            sum+=(ll)k;
            a[k]++;
        }
        int q;
        cin>>q;
        while(q--){
            ll b,c;
            cin>>b>>c;
            sum-=(a[b]*b);
            sum+=(a[b]*c);
            a[c]+=a[b];
            a[b]=0;
            cout<<sum<<"\n";
        }
    }
    int main(){
        ios::sync_with_stdio(0);
        cin.tie(0);
        cout.tie(0);
        cout<<fixed;
        cout<<setprecision(10);
        int t=1;
//        cin>>t;
        for(int i=1;i<=t;i++){
            solve();
        }
        return 0;
    }


Measured memory_bytes: 3880
#include<iostream>
using namespace std;
#include<map>
#include<vector>
#include<cmath>
#define int long long int
int power(int a,int b)
{
	int x=pow(a,b);
	return x;
}
int solve(int val)
{
	int j;
	if(val>0)
	{
		int sum=0;
		for(j=0;;j+=2)
		{
			sum+=power(2,j);
			if(sum>=val)
			{
				return j;
			}
		}
	}
	else
	{
		int sum=0;
		val*=-1;
		for(j=1;;j+=2)
		{
			sum+=power(2,j);
			if(sum>=val)
			{
				return j;
			}
		}
	}
}
int32_t main()
{
     int n;
     cin>>n;
     bool result=false;
     int j;
     for(j=0;j<=100;j++)
     {
		 for(int i=0;i<=100;i++)
		 {
			 if(4*j+7*i==n)
			 {
				 result=true;
			 }
		 }
	 }
	 if(result)
	    cout<<"Yes"<<endl;
	 else
	    cout<<"No"<<endl;
}


Measured memory_bytes: 3528
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string>
#include <bitset>
#include <map>
#include <vector>
#include <cstdlib>
#include <stack>
#include <queue>
#include <list>
#include <set>
using namespace std;
#define llong long long int

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int a[3] = {0}, ans = 100000;
    cin >> a[0] >> a[1] >> a[2];
    for (int i = 0; i < 3; ++i) {
        int sum = 0;
        for (int j = 0; j < 3; ++j) {
            sum += abs(a[i] - a[j]);
        }
        ans = min(ans, sum);
        sum = 0;
    }

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

Measured memory_bytes: 256
process.stdin.setEncoding('utf-8');
process.stdin.on('data', input => {
  var [num1, num2, num3] = input.split(' ');
  const a = parseInt(num1);
  const b = parseInt(num2);
  const c = parseInt(num3);

  if ( a < b && b < c ) {
    console.log('Yes');
  } else {
    console.log('No');
  }
})


Measured memory_bytes: 15256
#include <bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int main(){
	int a[4];
	r(i,4)cin>>a[i];
	sort(a,a+4);
	int s=0;
	r(i,4)if(i>0)s+=a[i];
	int q,w;
	cin>>q>>w;
	if(q<w)s+=w;
	else s+=q;
	cout<<s<<endl;
}

Measured memory_bytes: 3132
// AtCoder Beginner Contest 065
// D - Built?
// https://atcoder.jp/contests/abc065/tasks/arc076_b
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

#define MOD 1000000007

int main()
{
    int N; cin >> N;
    vector<int> X(N), Y(N);
    for (int i = 0; i < N; i++) {
        cin >> X[i] >> Y[i];
    }

    vector<int> ix(N), iy(N);
    iota(ix.begin(), ix.end(), 0);
    iota(iy.begin(), iy.end(), 0);

    sort(ix.begin(), ix.end(), [&](int a, int b) {
        return X[a] < X[b];
    });
    sort(iy.begin(), iy.end(), [&](int a, int b) {
        return Y[a] < Y[b];
    });

    vector<vector<pair<int, int>>> G(N);
    //               weight vertexの順
    int a, b, w;
    for (int i = 0; i < N-1; i++) {
        a = ix[i];
        b = ix[i+1];
        w = X[b] - X[a];
        G[a].push_back(make_pair(w, b));
        G[b].push_back(make_pair(w, a));
        a = iy[i];
        b = iy[i+1];
        w = Y[b] - Y[a];
        G[a].push_back(make_pair(w, b));
        G[b].push_back(make_pair(w, a));
    }

    // prim コストのみ求めるタイプ
    vector<bool> done(N, false);
    ll total_weight = 0;

    priority_queue<
        pair<int, int>,
        vector<pair<int, int>>,
        greater<pair<int, int>> // 直感と逆
    > q;
    q.push(make_pair(0, 0));
    while (!q.empty()) {
        pair<int, int> e = q.top(); q.pop();
        int& w = e.first, v = e.second;
        if (done[v]) continue;
        total_weight += w;
        done[v] = true;
        for (const auto& f : G[v]) {
            if (!done[f.second]) q.push(f);
        }
    }

    cout << total_weight << endl;
}


Measured memory_bytes: 10616
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()

const int MOD = 1000000007;
int N;

int main() {
  cin >> N;
  vector<int> x(N), r(N + 1, 0);
  rep(i, N) x[i] = i + 1;
  rep(i, N) {
    if (x[i] == 1) continue;
    rep(j, N) {
      if (i == j) continue;
      if (x[j] % x[i] == 0) {
        x[j] /= x[i];
        r[x[i]] += 1;
      }
    }
    r[x[i]] += 1;
    x[i] = 1;
  }

  ll ans = 1;
  rep(i, N) ans = (ans * (r[i + 1] + 1)) % MOD;

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


Measured memory_bytes: 256
while s = gets
  b = Array.new(13, 0)
  s.split(',').map(&:to_i).each { |c| b[c - 1] += 1 } 
  s = b.join

  d = b.clone.sort
  d.delete_if { |c| c == 0 }
  h = 'null'

  if s =~ /1{5}/ || s =~ /10{8}1{4}/
    h = 'straight'
  elsif d == [1, 4] then 
    h = 'four card'
  elsif d == [2, 3]
    h = 'full house'
  elsif d == [1, 1, 3]
    h = 'three card'
  elsif d == [1, 2, 2]
    h = 'two pair'
  elsif d == [1, 1, 1, 2]
    h = 'one pair'
  end 

  puts h
end

Measured memory_bytes: 2432
N = STDIN.gets.to_i
A = STDIN.gets.split(' ').map(&:to_i).map.with_index(2) {|a, i| [i, a] }.to_h

nums = Hash.new { 0 }

A.each do |_, boss|
  nums[boss] += 1
end

1.upto(N) do |i|
  puts nums[i]
end


Measured memory_bytes: 60364
#include<bits/stdc++.h>
#define cases long long t;cin>>t;while(t--)
#define f_io ios::sync_with_stdio(false); cin.tie(0)
#define foi(a,n) for(long long i=a;i<n;i++)
#define foj(a,n) for(long long j=a;j<n;j++)
#define fok(a,n) for(long long k=a;k<n;k++)
#define ll long long
#define MOD 1000000007
#define INF 1000000000
using namespace std;

int main()
{
    f_io;
    ll n;
    cin >> n;
    vector<ll> arr(n),pre(n);
    foi(0,n)
        cin >> arr[i];
    pre[n-1]= arr[n-1];
    for(ll i = n-2;i>=0;i--)
        pre[i]=(pre[i+1]+arr[i])%MOD;
    ll ans = 0;
    foi(0,n-1)
        ans = (ans + (arr[i]*pre[i+1])%MOD)%MOD;
    cout << ans;
    return 0;
}


Measured memory_bytes: 6360
n,a,b,c,d = gets.chomp.split(" ").map(&:to_i)
n -= 1
rem = (a-b).abs
min,max = 0,n
while min <= max
  mid = min+(max-min)/2
  if d*mid-c*(n-mid) >= rem && c*mid-d*(n-mid) <= rem
    puts "YES"
    exit
  elsif d*mid-c*(n-mid) < rem
    min = mid+1
  else
    max = mid-1
  end
end
puts "NO"

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

bool isAinB(vector<int>& a, vector<int>&b){
  if(a.empty()) return true;
  if(b.empty()) return false;
  unsigned int p=0;
  for(unsigned int i=0; i<a.size(); i++){
    while(p<b.size()){
      if(b[p]!=a[i]) p++;
      else break;
    }
  }
  if(p==b.size()) return false;
  else return true;
}
  

int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0) break;

    vector<vector<int> > info(n+1);
    for(int i=0; i<n+1; i++){
      int m;
      cin >> m;
      for(int j=0; j<m; j++){
        int tmp;
        cin >> tmp;
        info[i].push_back(tmp);
        sort(info[i].begin(), info[i].end());
      }
    }

    int susp=-1;
    for(int i=0; i<n; i++){
      if(isAinB(info[n],info[i])){
        if(susp==-1){
          susp=i;
        }else{
          susp=-2;
        }
      }
    }

    if(susp==-1 || susp==-2){
      cout << -1 << endl;
    }else{
      cout << susp+1 << endl;
    }
    
  }
  return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector<int> t(n), x(n), y(n), d(n);
	for (int i = 0; i < n; i++)
		cin >> t[i] >> x[i] >> y[i];
	d[0] = abs(x[0]) + abs(y[0]);
	for (int i = 1; i < n; i++)
		d[i] = t[i - 1] + abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
	for (int i = 0; i < n; i++) {
		if (t[i] < d[i]) {
			cout << "No" << endl;
			return 0;
		}
	}
	for (int i = 0; i < n; i++) {
		if (t[i] % 2 != d[i] % 2) {
			cout << "No" << endl;
			return 0;
		}
	}
	cout << "Yes" << endl;
	return 0;
}

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

const int maxn = 1e5+5;
int n, m, a[maxn];
vector<int> at[maxn];

int dist(int a, int b) {
    if (b-a >= 0) return b-a;
    return m - (a-b);
}

int main()
{
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    cin >> n >> m;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
        a[i]--;
        at[a[i]].push_back(i);
    }
    int active = 0;
    int x = 0;
    ll currAns = 0;
    for (int i = 1; i < n; i++) {
        if (1 + dist(x,a[i+1]) <= dist(a[i],a[i+1])) {
            currAns += 1 + dist(x,a[i+1]);
            active++;
        }
        else {
            currAns += dist(a[i],a[i+1]);
        }
    }
    ll bestAns = currAns;
    for (int x = 1; x < m; x++) {
        for (int i: at[x-1]) {
            if (i-1 > 0) {
                currAns--;
                currAns += dist(a[i-1],a[i]);
                active--;
            }
        }
        currAns -= active;
        for (int i: at[x-1]) {
            if (i+1 <= n) {
                active++;
            }
        }
        //cout << x << ": " << currAns << '\n';
        //cout << "active = " << active << '\n';
        bestAns = min(bestAns,currAns);
    }
    cout << bestAns << '\n';
}



Measured memory_bytes: 5376
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define sz(x) (int)x.size()
#define all(x) begin(x), end(x)
#define debug(x) cerr << #x << " " << x << '\n'
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using pli = pair<ll,int>;
const int INF = 0x3f3f3f3f, N = 2e5 + 5;
const ll LINF = 1e18 + 5;
constexpr int mod = 2019;
int l, r;
int main()
{
 	ios::sync_with_stdio(false);
 	cin.tie(0);
 	pii ans = mp(0, 0);
 	cin >> l >> r;
 	int minn = INF;
 	for(int i=l;i<=min(r, l+2019);i++)
 		for(int j=i+1;j<=min(r, l+2019);j++)
 			if((i%2019)*(j%2019)%mod<minn) minn = (i%2019)*(j%2019)%mod, ans = mp(i, j);
 	cout << minn;
	return 0;
}


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

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

int main(){
    ll n,x;
    cin>>n>>x;
    vector<ll> dat(n);
    rep(i,n){
        ll a;
        cin>>a;
        if(a>=x) dat[i]=a-x;
        else dat[i]=x-a;
    }
    ll gc=dat[0];
    for(int i=1;i<n;i++){
        gc=gcd(gc,dat[i]);
    }
    cout<<gc<<endl;
    return 0;
}

Measured memory_bytes: 3992
#include <iostream>
#include <stdio.h>
#include <string>

#define rep(i,n) for(int i = 0; i < n; i++)

typedef long long ll;

using namespace std;

const int INF = 1e9;
const int MOD = 1e9+7;
const double PI=3.14159265358979323846;

int main(){
  int a,b,c,flag;
  cin >> a >> b >> c;
  flag = int(a==b) + int(a==c) + int(b==c);
  if(flag==1) cout << "Yes" << endl;
  else cout << "No" << endl;
}


Measured memory_bytes: 256
n, m = map(int, input().split())
lst = [True] * (n + 1)
for _ in range(m):
    a = int(input())
    lst[a] = False
dp = [0] * (n + 1)
dp[0] = 1
div = 10 ** 9 + 7
for i in range(1, n + 1):
    if  lst[i]:
        dp[i] += dp[i - 1]
        dp[i] = dp[i] % div
        if i > 1:
            dp[i] += dp[i - 2]
            dp[i] = dp[i] % div

print(dp[n])

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

int main()
{
	int n,sum,max,tmp;
	cin >> n;
	sum = 0;
	max = 0;
	for (int i = 0; i < n; i++)
	{
		cin >> tmp;
		if (tmp >= max)
		{
			sum++;
			max = tmp;
		}
	}
	cout << sum << endl;
	return 0;
}

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

int main(void)
{
  std::vector<int> a;
  int b[3] = {5, 7, 5};
  int i=0;
  int temp;
  for(int ii=0;ii<3;ii++){
    std::cin >> temp;
    a.push_back(temp);
  }

  for(int ii=0;ii<a.size();ii++){
    if(a[ii]==b[i]){
      i++;
      a.erase(a.begin()+ii);
      ii=-1;
    }
  }

  if(a.size()==0){
    std::cout << "YES" << std::endl;
  }else{
    std::cout << "NO" << std::endl;
  }

  return 0;
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

ll N,A,B,C,D;

int main()
{
	scanf("%lld%lld%lld%lld%lld",&N,&A,&B,&C,&D);

	bool ans = false;
	FOR(i,0,N){
		ans |= (-D * (N - i - 1) + C * i <= B - A && B - A <= -C * (N - i - 1) + D * i);
	}
	puts(ans ? "YES" : "NO");

	return 0;
}


Measured memory_bytes: 256
#include <array>
#include <iostream>
#include <tuple>
#include <vector>
#define repeat(i, n) for (int i = 0; (i) < int(n); ++(i))
#define repeat_reverse(i, n) for (int i = (n)-1; (i) >= 0; --(i))
#define whole(x) begin(x), end(x)
using namespace std;

constexpr int inf = 1e9+7;
int main() {
    string s; cin >> s;
    int n = s.length();
    vector<int> dp(n + 2, inf);
    dp[n + 1] = 0;
    dp[n] = 1;
    vector<pair<char, int> > g(n + 1);
    g[n] = { 'a', n + 1 };
    array<int, 26> f;
    fill(whole(f), n + 1);
    repeat_reverse (i, n) {
        f[s[i] - 'a'] = i + 1;
        repeat (j, 26) {
            if (1 + dp[f[j]] < dp[i]) {
                dp[i] =  1 + dp[f[j]];
                g[i] = { 'a' + j, f[j] };
            }
        }
    }
    string t;
    for (int i = 0; i < n + 1; ) {
        char c; tie(c, i) = g[i];
        t += c;
    }
    cout << t << endl;
    return 0;
}


Measured memory_bytes: 2948
N = int(input())
dic, rst = {}, []
for i in range(N):
    s = input()
    if not s in dic:
        dic[s] = 1
    else:
        dic[s] += 1
max_val = max(dic.values())
rst = [ key for key, val in dic.items() if val == max_val ]
[ print(i) for i in sorted(rst) ]

Measured memory_bytes: 36548
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
#define INF 1000000000
#define LLINF 10000000000000000ll
#define MOD 1000000007

bool dbgflag = false;

struct prime_n {
  int p = -1;
  bool isPrime = true;
};

int struct_prime(vector<prime_n>&primes) {
  primes[0].isPrime = false;
  primes[1].isPrime = false;
  int cnt = 0;
  for (int i = 0; i < primes.size(); i++) {
    if (!primes[i].isPrime) continue;
    primes[i].p = i;
    cnt++;
    for (int k = 2 * i; k < primes.size(); k += i) {
      primes[k].isPrime = false;
    }
  }
  return cnt;
}

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

  const int MAX_N = 10e5;
  vector<prime_n> primes(MAX_N+1);
  struct_prime(primes);

  vector<int> sim2017(MAX_N+1); //i以下の2017に似た数の個数

  int c = 0;
  for (int i = 0; i <= MAX_N; i++) {
    if (primes[i].isPrime && primes[(i+1)/2].isPrime) c++;
    sim2017[i] = c;
  }

  int q;
  cin >> q;
  for (int i = 0; i < q; i++) {
    int l, r;
    cin >> l >> r;
    /*while (l <= r) {
      if (primes[l].isPrime && primes[(l+1)/2].isPrime) cnt++;
      l += 2;
    }*/
    cout << sim2017[r] - sim2017[l-1] << endl;
  }
}


Measured memory_bytes: 12416
def main():
    from sys import stdin, setrecursionlimit
    setrecursionlimit(10**6)
    r = stdin.readline()[:-1]
    #n = int(stdin.readline()[:-1])   
    #r = [stdin.readline() for i in range(n)]
    #t = [int(stdin.readline()) for i in range(n)]

    a, b = map(int, r.split())
    print((a-1)*(b-1))

if __name__ == '__main__':
    main()



Measured memory_bytes: 38384
#include<stdio.h>
#include<bitset>
int main()
{
	std::bitset<246913> p;
	int i,j,s=p.size();
	p.set();
	p[0]=p[1]=0;
	for(i=2;i*i<s;++i)if(p[i])for(j=i*i;j<s;j+=i)p[j]=0;
	while(s=!scanf("%d",&j),j)
	{
		for(i=j+1;i<=j*2;++i)if(p[i])++s;
		printf("%d\n",s);
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>
  int main (void){
    int n,k,j,a,ans = 0;
    scanf("%d",&n);
    k = 800 * n;
    j = n / 15;
    a = j * 200;
    ans = k - a;
    printf("%d\n",ans);
    return 0;
  }


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

using namespace std;

int main(){
	string s;
	cin>>s;
	int cont=0;
	for(int i=0;i<s.size()/2;i++){
		if(s[i]!=s[s.size()-i-1]) cont++;
	}
	cout<<cont;
	return 0;
}

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

#define ll long long 
#define fi first
#define se second
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define all(x) (x).begin(), (x).end()
#define allr(x) (x).rbegin(), (x).rend()

void initforfac() {
/* 
	set const int N = ...; ll fac[N], inv[N];

	fac[0] = fac[1] = inv[0] = inv[1] = 1;
	for(int i = 2; i < N; ++i) inv[i] = 1ll * inv[MOD % i] * (MOD - MOD / i) % MOD;
	for(int i = 1; i < N; ++i) inv[i] = 1ll * inv[i - 1] * inv[i] % MOD;
	for(int i = 2; i < N; ++i) fac[i] = 1ll * fac[i - 1] * i % MOD;
*/
}

ll gcd(ll a, ll b) {
	return (a % b) ? gcd(b, a % b) : b;
}
ll lcm(ll a, ll b) {
	return (a * b) / gcd(a, b);
}
ll add(ll a, ll b) {
	ll x = (a + b) % MOD;
	if(x < 0) return x + MOD;
	return x;
}
ll sub(ll a, ll b) {
	ll x = (a - b) % MOD;
	if(x < 0) return x + MOD;
	return x;
}
ll mul(ll a, ll b) {
	ll x = (a * b) % MOD;
	if(x < 0) return x + MOD;
	return x;
}
ll power(ll a, ll b) {
	if(b == 0) return 1;
	if(b & 1) return mul(a, power(a, b - 1));
	return power(mul(a, a), b / 2);
}
ll inv(ll x) {
	return power(x, MOD - 2);
}
/*
ll C(ll n, ll r) {
	return 1ll * fac[n] * inv[r] % MOD * inv[n - r] % MOD;
}
*/

void init() {
	
}

void solve() {
	int l, r, d;
	cin >> l >> r >> d;
	cout << (r / d) - ((l - 1) / d) << "\n";
}

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

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

int main() {
	int A, B, C;
	std::cin >> A >> B >> C;
	if((A < C and C < B) or (A > C and C > B)) {
		std::cout << "Yes" << std::endl;
		return 0;
	} else {
		std::cout << "No" << std::endl;
		return 0;
	}
}


Measured memory_bytes: 256
import sys
import math
from collections import Counter
import itertools
import fractions
#from functools import reduce

# 入力を整数に変換して受け取る
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def MI1(): return map(int1, sys.stdin.readline().split())
# 入力全てを整数に変換したものの配列を受け取る
def LI(): return list(map(int, sys.stdin.readline().split()))
# 入力全てを整数に変換して1引いたものの配列を受け取る
def LLI(rows_number): return [LI() for _ in range(rows_number)]
def SR(): return sys.stdin.readline().rstrip()

ascii_lowercase = 'abcdefghijklmnopqrstuvwxyz'
ascii_uppercase = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ'
ascii_uppercase2 = 'ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXYZ'

# リストを改行区切りで出力する
p2D = lambda x: print(*x, sep="\n")
p2E = lambda x: print(''.join(x))
p2S = lambda x: print(*x, sep=" ")

# ###########################################
 
N,M=MI()
H=LI()
A=LLI(M)

ansList=[0]*N
for i in range(N):
    ansList[i] = True

for a in A:
    if H[a[0]-1] > H[a[1]-1]:
        ansList[a[1]-1] = False
    elif H[a[0]-1] == H[a[1]-1]:
        ansList[a[1]-1] = False
        ansList[a[0]-1] = False
    else:
        ansList[a[0]-1] = False

print(ansList.count(True))



Measured memory_bytes: 33780
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <array>
#include <tuple>
#include <string>
#include <algorithm>
#include <functional> // greater など
#include <cmath>      // abs など
#include <numeric>    // accumulate, gcd など
#include <cassert>    // assert
#include <stdexcept>
#include <bitset>
using namespace std;

// #include <boost/multiprecision/cpp_int.hpp>
// using namespace boost::multiprecision;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
// typedef int128_t ll;
// typedef cpp_int ll;

// GCC, 配列のアクセスなど
#define _GLIBCXX_DEBUG
// Clang, 配列のアクセスなど
#define _LIBCPP_DEBUG 0

// #define NDEBUG 1
// debug用出力 https://trap.jp/post/998/
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T)
{
    cerr << H << " ";
    debug_out(T...);
}
#ifdef NDEBUG
#define debug(...)
#else
#define debug(...) debug_out(__VA_ARGS__)
#endif

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

// constexpr inline ll mod = 1'000'000'007;

int n, m, res;
vector<int> k(20);
vector<vector<int>> s(20, vector<int>(20));
vector<int> p(20);

int main()
{
    // 入出力
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);

    // 3:42
    cin>>n>>m;
    rep(i,m){
        cin>>k[i];
        rep(j,k[i]){
            cin>>s[i][j];
            s[i][j]--;
        }
    }
    rep(i,m){
        cin>>p[i];
    }

    rep(subset, 1<<n){
        bool all = true;
        rep(i,m){
            int q = 0;
            rep(j, k[i])
            {
                q ^= (subset >> s[i][j]) & 1;
            }
            all &= (q == p[i]);
        }
        res += all;
    }
    cout<<res<<endl;

    return 0;
}


Measured memory_bytes: 3596
#include <iostream>
#include <vector>
#include <set>
#include <algorithm>
#include <string>
#include <sstream>
 
#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

void dfs(int w, int h, int x, int y, std::vector<std::string> &image){
	image[y][x] = '0';

	if(x >= 1 && image[y][x - 1] == '1'){
		dfs(w, h, x - 1, y, image);
	}
	if(x < w - 1 && image[y][x + 1] == '1'){
		dfs(w, h, x + 1, y, image);
	}
	if(y < h - 1 && image[y + 1][x] == '1'){
		dfs(w, h, x, y + 1, image);
	}

	return;
}

int main(int argc, char **argv){
	std::string buf;
	std::vector<std::string> image;
	int w = 12;
	int h = 12;
	int counter = 0;

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

	for(;;){
		image.clear();
		counter = 0;
		for(int i = 0; i < h; i++){
#if INPUT_FROM_FILE
			std::getline(ifs, buf);
#else
			std::getline(std::cin, buf);
#endif
			image.push_back(buf);
		}

		for(int y = 0; y < h; y++){
			for(int x = 0; x < w; x++){
				if(image[y][x] == '1'){
					counter++;
					dfs(w, h, x, y, image);
				}
			}
		}
		std::cout << counter << std::endl;

#if INPUT_FROM_FILE
		if(!std::getline(ifs, buf)){ break; }
#else
		if(!std::getline(std::cin, buf)){ break; }
#endif
	}

 
#if INPUT_FROM_FILE
	//fclose(fp);
#endif
    return 0;
}


Measured memory_bytes: 3168
N, M = map(int, input().split())
lstMain = list()
for i in range(M):
    lstSub = list(map(int, input().split()))
    lstMain.append(lstSub[1:])
lstP = list(map(int, input().split()))

endStr = ("0000000000" + "1"*N)[-10:]
count = 0
#スイッチの付け方
for i in range(0, 2 ** 10):
    binStr = ("0000000000" + format(i, 'b'))[-10:]
    errFlg = 0
    #各電球が点灯するか判定
    for j in range(M):
        s = 0
        for k in range(len(lstMain[j])):
            s += int(binStr[(-1) * lstMain[j][k]])
        if s % 2 != lstP[j]:
            errFlg = 1
        if errFlg == 1:
            break
    if errFlg == 0:
        count += 1
    if binStr == endStr:
        break
    
print(count)



Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;

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

    char s[16];
    int p[256] = {};
    for (int i = 0; i < n; i++) {
        cin >> s;
        p[s[0]]++;
    }

    int64_t r = 0;
    int q[5] = { 0, 0, 1, 1, 1 };
    do {
        char *c = "MARCH";
        int64_t t = 1;
        for (int i = 0; i < 5; i++) {
            if (q[i]) {
                t *= p[c[i]];
            }
        }
        r += t;
    } while (next_permutation(q, q + 5));

    cout << r << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<map>
#define mod 1000000007
#define rep(i,N) for(int i=0;i<N;i++)
using namespace std;

int main(){
    vector<int> x;
    vector<int> diff;
    int n,m,a;
    long long ans=0;
    cin>>n>>m;
    rep(i,m){
        cin>>a;
        x.push_back(a);
    }
    sort(x.begin(),x.end());
    rep(i,m-1)diff.push_back(x[i+1]-x[i]);
    sort(diff.begin(),diff.end(),greater<int>());
    if(n-1>=diff.size())ans=0;
    // 0 1 2 3 4 5
    // 9 8 4 3 2 1
    else{
        for(int i=n-1;i<diff.size();i++){
            ans+=diff.at(i);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1400
// --------------------<optimizations>--------------------
#pragma GCC optimize("O3")

//(UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)\
#pragma comment(linker, "/stack:200000000")
//(UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\
#pragma GCC optimize("unroll-loops")

// -------------------</optimizations>--------------------
#include<bits/stdc++.h>
using namespace std;
#define int long long
//#define d long double
#define pii pair<int,int>
#define pb push_back
#define cases int tc;cin>>tc;while(tc--)
#define N 100003
#define M 52
#define inf 1e18
#define Arena ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
//int mod=1e9+7;
//int mod=998244353;
map<pii,vector<int>> mp;
int x[M],y[M],n,p,q;

signed main()
{
    Arena
        
    cin>>n;
    int i,j;
    for(i=1;i<=n;++i)
        cin>>x[i]>>y[i];
    
    set<pii> s;
    for(i=1;i<=n;++i)
    {
        s.clear();
        for(j=1;j<=n;++j)
        {
            if(i!=j)
                s.insert({x[j]-x[i],y[j]-y[i]});
        }
        for(auto it:s)
            mp[it].pb(i);
    }   
    
    int ma=0;
    vector<int> v;
    for(auto it:mp)
    {
        if(it.second.size()>ma)
            ma=it.second.size(),p=it.first.first,q=it.first.second,v=it.second;
    }   
    
    cout<<n-ma;
    
    
    return 0;
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
  
int main()
{
  int n;
  cin>>n;
  int *p=new int[n];
  for(int i=0;i<n;i++)
    cin>>p[i];
  
  int dp[n];
  dp[n-1]=0;
  dp[n-2]=abs(p[n-2]-p[n-1]);
   for(int i=n-3;i>=0;i--)
   {
     dp[i]=min(abs(p[i]-p[i+1])+dp[i+1],abs(p[i]-p[i+2])+dp[i+2]);
   }
  cout<<dp[0];
  return 0;
}


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

constexpr int MOD = 1'000'000'007;
constexpr int MAX = 200'200;

template<int mod> struct ModInt {
    int x;
    ModInt() : x(0) {}
    ModInt(long long y) : x(y >= 0 ? y % mod : (mod - (-y) % mod) % mod) {}
    ModInt &operator+=(const ModInt &p) { if((x += p.x) >= mod) x -= mod; return *this; }
    ModInt &operator-=(const ModInt &p) { if((x += mod-p.x) >= mod) x -= mod; return *this; }
    ModInt &operator*=(const ModInt &p) { x = (int)(1LL*x*p.x%mod); return *this; }
    ModInt &operator/=(const ModInt &p) { *this *= p.inverse(); return *this; }
    ModInt operator-() const { return ModInt(-x); }
    ModInt operator+(const ModInt &p) const { return ModInt(*this) += p; }
    ModInt operator-(const ModInt &p) const { return ModInt(*this) -= p; }
    ModInt operator*(const ModInt &p) const { return ModInt(*this) *= p; }
    ModInt operator/(const ModInt &p) const { return ModInt(*this) /= p; }
    bool operator==(const ModInt &p) const { return x == p.x; }
    bool operator!=(const ModInt &p) const { return x != p.x; }
    ModInt inverse() const {
        int a = x, b = mod, u = 1, v = 0, t;
        while(b > 0) { t = a / b; a -= t * b; swap(a, b); u -= t * v; swap(u, v); }
        return ModInt(u);
    }
    ModInt pow(int e){
        long long a = 1, p = x;
        while(e > 0) {
            if(e%2 == 0) {p = (p*p) % mod; e /= 2;}
            else {a = (a*p) % mod; e--;}
        }
        return ModInt(a);
    }
    friend ostream &operator<<(ostream &os, const ModInt<mod> &p) {
        return os << p.x;
    }
    friend istream &operator>>(istream &is, ModInt<mod> &a) {
        long long x;
        is >> x;
        a = ModInt<mod>(x);
        return (is);
    }
};

template<int mod> struct Combination {
    vector<ModInt<mod>> fact, ifact;
    Combination(int n) : fact(n+1), ifact(n+1) {
        fact[0] = 1;
        for (int i = 1; i <= n; i++) fact[i] = (fact[i-1] * i);
        ifact[n] = fact[n].inverse();
        for (int i = n; i > 0; i--) ifact[i-1] = ifact[i] * i;
    }
    ModInt<mod> operator() (int n, int r) {
        if (r < 0 or r > n) return 0;
        return fact[n] * ifact[n-r] * ifact[r];
    }
    const ModInt<mod> &operator[] (int i) const {
        return fact[i];
    }
};

int main() {
    using mint = ModInt<MOD>;
    Combination<MOD> com(MAX);
    
    long long n, m, k;
    cin >> n >> m >> k;
    
    mint ans = 0;
    for (int i = 0; i < 2; i++) {
        for (int d = 1; d < n; d++) {
            mint res = (n - d) * m * m;
            res *= com(n * m - 2, k - 2);
            res *= d;
            ans += res;
        }
        swap(n, m);
    }
    
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1920
import sys

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7
EPS = 10 ** -10

class ModTools:
    """ 階乗・逆元用のテーブルを構築する """

    def __init__(self, MAX, MOD):
        
        MAX += 1
        self.MAX = MAX
        self.MOD = MOD
        factorial = [1] * MAX
        factorial[0] = factorial[1] = 1
        for i in range(2, MAX):
            factorial[i] = factorial[i-1] * i % MOD
        inverse = [1] * MAX
        inverse[MAX-1] = pow(factorial[MAX-1], MOD-2, MOD)
        for i in range(MAX-2, -1, -1):
            inverse[i] = inverse[i+1] * (i+1) % MOD
        self.fact = factorial
        self.inv = inverse
    
    def nCr(self, n, r):
        """ 組み合わせ """

        if n < r: return 0
        r = min(r, n-r)
        numerator = self.fact[n]
        denominator = self.inv[r] * self.inv[n-r] % self.MOD
        return numerator * denominator % self.MOD

    def nHr(self, n, r):
        """ 重複組み合わせ """

        return self.nCr(r+n-1, r)

    def nPr(self, n, r):
        """ 順列 """

        if n < r: return 0
        return self.fact[n] * self.inv[n-r] % self.MOD

    def div(self, x, y):
        """ MOD除算 """

        return x * pow(y, self.MOD-2, self.MOD) % self.MOD

N, K = MAP()

mt = ModTools(N+K+1, MOD)
ans = mt.nHr(K, N)
print(ans)



Measured memory_bytes: 5820
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_macros)]
#![allow(unused_imports)]

use std::str::FromStr;
use std::io::*;
use std::collections::*;
use std::cmp::*;

struct Scanner<I: Iterator<Item = char>> {
    iter: std::iter::Peekable<I>,
}

macro_rules! exit {
    () => {{
        exit!(0)
    }};
    ($code:expr) => {{
        if cfg!(local) {
            writeln!(std::io::stderr(), "===== Terminated =====")
                .expect("failed printing to stderr");
        }
        std::process::exit($code);
    }}
}

impl<I: Iterator<Item = char>> Scanner<I> {
    pub fn new(iter: I) -> Scanner<I> {
        Scanner {
            iter: iter.peekable(),
        }
    }

    pub fn safe_get_token(&mut self) -> Option<String> {
        let token = self.iter
            .by_ref()
            .skip_while(|c| c.is_whitespace())
            .take_while(|c| !c.is_whitespace())
            .collect::<String>();
        if token.is_empty() {
            None
        } else {
            Some(token)
        }
    }

    pub fn token(&mut self) -> String {
        self.safe_get_token().unwrap_or_else(|| exit!())
    }

    pub fn get<T: FromStr>(&mut self) -> T {
        self.token().parse::<T>().unwrap_or_else(|_| exit!())
    }

    pub fn vec<T: FromStr>(&mut self, len: usize) -> Vec<T> {
        (0..len).map(|_| self.get()).collect()
    }

    pub fn mat<T: FromStr>(&mut self, row: usize, col: usize) -> Vec<Vec<T>> {
        (0..row).map(|_| self.vec(col)).collect()
    }

    pub fn char(&mut self) -> char {
        self.iter.next().unwrap_or_else(|| exit!())
    }

    pub fn chars(&mut self) -> Vec<char> {
        self.get::<String>().chars().collect()
    }

    pub fn mat_chars(&mut self, row: usize) -> Vec<Vec<char>> {
        (0..row).map(|_| self.chars()).collect()
    }

    pub fn line(&mut self) -> String {
        if self.peek().is_some() {
            self.iter
                .by_ref()
                .take_while(|&c| !(c == '\n' || c == '\r'))
                .collect::<String>()
        } else {
            exit!();
        }
    }

    pub fn peek(&mut self) -> Option<&char> {
        self.iter.peek()
    }
}

fn main() {
    let cin = stdin();
    let cin = cin.lock();
    let mut sc = Scanner::new(cin.bytes().map(|c| c.unwrap() as char));
    let N: usize = sc.get();
    let A: Vec<usize> = sc.vec(N);
    let mut cum = vec![0; N+1];
    for i in 0..N {
        cum[i+1] = max(cum[i], A[i]);
    }
    let mut rev_cum = vec![0; N+1];
    for i in (0..N).rev() {
        rev_cum[i] = max(rev_cum[i+1], A[i]);
    }
    for i in 0..N {
        let ans = max(cum[i], rev_cum[i+1]);
        println!("{}", ans);
    }
}


Measured memory_bytes: 11772
# 完全二分木  Complete binary tree

H = int(input())
T = [-1] + [int(i) for i in input().split()]

for i in range(1, H+1):
    print("node ", i, ": ", sep="", end="")
    print("key = ", T[i], ", ", sep="", end="")
    if i != 1:
        print("parent key = ", T[i // 2], ", ", sep="", end="")
    if 2 * i <= H:
        print("left key = ", T[2 * i], ", ", sep="", end="")
    if 2 * i + 1 <= H:
        print("right key = ", T[2 * i + 1], ", ", sep="", end="")
    print()




Measured memory_bytes: 5800
#include <iostream>

int main()
{
    // 問題定義取得
    int N, M;
    std::cin >> N >> M;

    // 配列定義
    int* data = new int[N];

    // 問題取得
    int sum = 0;
    for (size_t i = 0; i < N; i++)
    {
        std::cin >> data[i];
        sum += data[i];
    }

    double t = sum*(double)(1.0 / 4.0 / M);
    int cnt = 0;
    for (size_t i = 0; i < N; i++)
        if (t <= (double)data[i])
            cnt++;

    if (cnt >= M)
        std::cout << "Yes" << std::endl;
    else
        std::cout << "No" << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<climits>
#include<cstdio>
#include<cmath>
using namespace std;
const int M=1e5+5;
const long long MN=LONG_MAX;
long long pos[M];
int main()
{
     int n,k;
     long long ans;
     cin>>n>>k;
         pos[0]=0;
         int s=0,bound=0,flag=0;
         for(int i=1;i<=n;++i)
         {
             scanf("%lld",&pos[i]);
             if(pos[i-1]<0&&pos[i]>=0)s=i-1;
             if(s!=0)bound++;
         }
        // cout<<s<<endl;
         if(s==0)
         {
             if(pos[1]>=0)cout<<pos[k]<<endl;
             else if(pos[1]<=0)cout<<-pos[n-k+1]<<endl;
         }
         else
         {
           //  cout<<s<<" "<<bound<<endl;
             if(bound>k)bound=k;
             bound+=s;
             ans=MN;
            // cout<<s<<" "<<bound<<endl;
             for(int i=bound;i-k+1>=1&&i>=s;--i)
             {
                 int t=i-k+1;
               // cout<<t<<" "<<i<<endl;
                 if(t>s)ans=min(ans,pos[i]);
                 else if(i==s)ans=min(ans,-pos[t]);
                 else ans=min(ans,min(pos[i]+pos[i]-pos[t],-pos[t]+pos[i]-pos[t]));
               // cout<<ans<<endl;
             }
             cout<<ans<<endl;
         }
}


Measured memory_bytes: 1024