akhauriyash/Code-Regression huggingface dataset:
/*
ID: wangjun30
LANG: C++11
TASK:
*/
#include<iostream>
#include<algorithm>
#include<array>
#include<unordered_map>
#include<map>
#include<set>
#include<list>
#include<stack>
#include<unordered_set>
#include<vector>
#include<bitset>
#include<queue>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<climits>
//#include<fstream>
#define int long long
using namespace std;
//ifstream cin(".in");
//ofstream cout(".out");
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	string a,b;
	cin>>a>>b;
	if(a!=b.substr(0,a.size()))
		cout<<"No";
	else
		cout<<"Yes";
	return 0;
}

Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c,dif;
    scanf("%d %d %d",&a,&b,&c);
    if(a == b) dif = c;
    else if(a == c) dif = b;
    else if(b == c) dif = a;
    printf("%d\n",dif);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  string S; cin >> S;
  bool flag = false;
  
  char A = S.at(0);
  char B = S.at(1);
  char C = S.at(2);
  char D = S.at(3);
  if(A == B && C == D && A != C) flag = true;
  if(A == C && B == D && A != B) flag = true;
  if(A == D && B == C && A != B) flag = true;
  
  if(flag) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <map>
#include <queue>

static const int MOD = 1000000007;
using ll = long long;
using u32 = unsigned;
using namespace std;

template<class T>
constexpr T INF = ::numeric_limits<T>::max() / 32 * 15 + 208;

template <class T, class U>
vector<T> make_v(U size, const T& init){ return vector<T>(static_cast<size_t>(size), init); }

template<class... Ts, class U>
auto make_v(U size, Ts... rest) { return vector<decltype(make_v(rest...))>(static_cast<size_t>(size), make_v(rest...)); }


int main() {
    int n;
    cin >> n;
    vector<long double> v(n);
    for (auto &&i : v) scanf("%Lf", &i);
    auto dp = make_v(n+1, n+1, 0.0L);
    dp[0][0] = 1.0L;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) {
            dp[i+1][j] += dp[i][j]*(1.0-v[i]);
            dp[i+1][j+1] += dp[i][j]*v[i];
        }
    }
    long double ans = 0.0L;
    for (int i = 0; i <= n; ++i) {
        if(2*i >= n) ans += dp[n][i];
    }
    cout << setprecision(15) << ans << "\n";
    return 0;
}


Measured memory_bytes: 141056
#include <cstdio>
#include <algorithm>
using namespace std;
#define x 10001
int dp[x][2],num[x];
int main()
{
  int n;
  scanf("%d",&n);
  for(int i=1;i<n;i++)
  {
    scanf("%d",&num[i]);
  }
  for(int i=0;i<x;i++)
  {
    dp[i][0]=x*x;
    dp[i][1]=x*x;
  }
  dp[1][0]=0;
  for(int i=1;i<n;i++)
  {
    for(int j=n/2;j>=1;j--)
    {
      dp[j][1]=min(dp[j][1],dp[j][0]+num[i]);
      dp[j][0]=min(dp[j-1][0],dp[j-1][1]+num[i]);
    }
  }
  printf("%d\n",min(dp[n/2][0],dp[n/2][1]));
  return 0;
}

Measured memory_bytes: 1140
#include <iostream>
#include <vector>
#include <algorithm>
#define int long long
using namespace std;
signed main(){

  int k;
  vector<int> a;
  cin>>k;
  for(int i=0,b;i<k&&cin>>b;i++) a.push_back(b);
  reverse(a.begin(),a.end());
  int n=2,m=2;
  for(int i=0;i<k;i++){
    int t=((n-1)/a[i]+1)*a[i],t2=m/a[i]*a[i]+a[i]-1;
    if(t<n||m<t){
      cout<<-1<<endl;
      return 0;
    }
    n=t;
    m=t2;
    //    cout<<n<<" "<<m<<endl;                                                                                               
  }
  cout<<n<<" "<<m<<endl;
  return 0;

}

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

int main() {
  long a, v, b, w, t;

  cin >> a >> v >> b >> w >> t;

  if (a < b) {
    if (a + (v * t) >= b + (w * t)) {
      cout << "YES";
    } else {
      cout << "NO";
    }
  } else {
    if (a - (v * t) <= b - (w * t)) {
      cout << "YES";
    } else {
      cout << "NO";
    }
  }
  return 0;
}

Measured memory_bytes: 3636
#include<iostream>
#include<cstdio>
#include<cstring>
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include <math.h>
#include<vector>
#include<stack>
#include<malloc.h>
#define INF 0x3f3f3f3f
#define maxn 1000006
using namespace std;
int a[102];
int main()
{     int maxs=0;
      cin>>a[0]>>a[1]>>a[2];
      sort(a,a+3);
      maxs=a[2]*10+a[1]+a[0];

    cout<<maxs<<endl;

 return 0;
}


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

typedef std::pair<int, int> P;

const int MAX_W = 10000;
const int MAX_H = 10000;
const int MAX_N = 1000;
int h, w, n;
P t[MAX_N];

unsigned int long long sum;

int main() {
	int x,y;
	std::cin >> w >> h >> n;
	for (int i = 0; i < n; ++i) {
		std::cin >> x >> y;
		t[i].first = x - 1;
		t[i].second = y - 1;
	}
	for (int i = 0; i < n - 1; ++i) {
		int ax = t[i + 1].first - t[i].first;
		int ay = t[i + 1].second - t[i].second;
		if ((ax >= 0 && ay >= 0) || (ax < 0 && ay < 0))
			sum += std::max(std::abs(ax), std::abs(ay));
		else
			sum += std::abs(ax) + std::abs(ay);
	}
	std::cout << sum << std::endl;
	return 0;
}

Measured memory_bytes: 1168
#include <iostream>
#include <vector>
#include <utility>
#include <string>
#include <map>
#include <algorithm>
#include <queue>
#include <cstdio>

using namespace std;

int main(){
    int n;
    cin >> n;
    n %= 10;
    if(n == 3){
      cout << "bon" << endl;
    }else if(n==0 || n==1 || n==6 || n==8){
       cout << "pon" << endl;
    }else{
        cout << "hon" << endl;
    }

    return 0;
}


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

using namespace std;

void fastio() {
	cin.tie(nullptr);
	cin.sync_with_stdio(false);
}

using LL = long long;
using LD = long double;

const LL MOD = 1e9+7;
const LL INF = LLONG_MAX;
const LL N = 1e6+1;

int main() {
	fastio();
	
	LL x, k, d;
	cin >> x >> k >> d;

	if (x < 0) x = -x;

	if (d == 0) {
		cout << x << "\n";
		return 0;
	}

	LL req = (x/d);
	
	if (k > req) {
		x -= req*d;
		k -= req;

		LL ans;
		if (k % 2 == 1) {
			ans = abs(x-d);
		}
		else {
			ans = x;
		}
		cout << ans << "\n";
	}
	else {
		x -= k*d;
		cout << x << "\n";
		return 0;
	}



}

Measured memory_bytes: 3684
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;

vector< vector<int> > M;
int h,w;

bool dfs(int y, int x){
    if(y>=h||y<0||x>=w||x<0)return false;
    if(M[y][x]==0)return false;
    M[y][x]=0;
    for(int i=-1;i<=1;i++){
        for(int j=-1;j<=1;j++){
            dfs(y+i,x+j);
        }
    }
    return true;
}

int ans(){
    int res=0;
    REP(i,h)REP(j,w){
        if(dfs(i,j))res++;
    }
    
    return res;
}

int main(){
    
    while(true){
        cin>>w>>h;
        if(h==0&&w==0)break;
        
        M.clear();
        M.resize(h);
        REP(i,h){
            REP(j,w){
                int t; cin>>t;
                M[i].push_back(t);
            }
        }
        
        cout<<ans()<<endl;
        
    }
    
    return 0;
}

Measured memory_bytes: 3300
import numpy as np
from itertools import product

def main():
    n, m = [int(i) for i in input().split()]
    sw = np.zeros((m, n), int)
    for i in range(m):
        for s in input().split()[1:]:
            sw[i][int(s)-1] = 1

    p = np.array([int(i) for i in input().split()])
    res = 0
    for t in product((0, 1), repeat=n):
        stat = np.array(t)
        if np.array_equal(p, np.dot(sw, stat) % 2):
            res += 1
    print(res)


if __name__ == '__main__':
    main()



Measured memory_bytes: 12400
import java.util.Scanner;
public class Main {
public static void main(String[] args) {
  Scanner sc = new Scanner(System.in);
  int n  = sc.nextInt();
  int[] a = new int[n + 1];
  for (int i = 0; i < n; i++)
    a[i] = sc.nextInt();
  int b = a[0];
  int ans = 1;
  while (b != 2) {
    b = a[b-1];
    ans++;
    if (ans > n) {
      ans = -1;
      break;
    }
  }
  System.out.println(ans);
}}

Measured memory_bytes: 51716
#include<bits/stdc++.h>
#include<bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 2e5 + 7;
const int maxm = 1e6 + 7;
const int ALP = 26;
const long long mod = 1e9 + 7;
const double pi = acos(-1.0);
const double eps = 1e-8;

long long a,b,k;

int main()
{
	cin>>a>>b>>k;
	long long tmp=min(a,k);
	a-=tmp;
	k-=tmp;
	tmp=min(b,k);
	b-=tmp;
	cout<<a<<" "<<b<<endl;
	return 0;
}


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

using namespace std;
static const int MAX = 200000;

int main(){
  int R[MAX],n;

  cin >> n;

  for (int i = 0;  i < n; i++)
  cin >> R[i];

  int maxv =-2000000000;
  int minv = R[0];

  for (int i = 1;i<n;i++){
    maxv = max(maxv,R[i]-minv);
    minv = min(minv,R[i]);
  }

  cout << maxv << endl;

  return 0;
}

Measured memory_bytes: 3820
#include <stdio.h>

#define MAX(x,y)	((x)>(y)?(x):(y))
typedef long long ll;

int main(){
    ll ans,a,b,c,d;
    scanf("%lld%lld%lld%lld",&a,&b,&c,&d);
    printf("%lld\n", (ll)MAX( (ll)MAX(a*c,a*d), (ll)MAX(b*c,b*d) ));  
    return 0;
}

Measured memory_bytes: 1736
// B - Papers, Please
#include <bits/stdc++.h>
using namespace std;
int main(){
	int N; cin>>N;
	while(N--){
		int a;cin>>a;
		if(a%2==0 && a%3 && a%5){ puts("DENIED"); return 0; }
	}
	puts("APPROVED");
}

Measured memory_bytes: 256
h, w = map(int, input().split())
n = int(input())
a = list( map(int, input().split()))

ans = [[-1 for i in range(w)] for j in range(h)]

num_list = []
for i in range(len(a)):
    num_list.extend([i+1]*a[i])

k = 0
for i in range(h):
    if i %2 == 0:
        for j in range(w):
            ans[i][j] = num_list[k]
            k+=1
    else:
        for j in reversed(range(w)):
            ans[i][j] = num_list[k]
            k+=1


for i in range(h):
    print(*ans[i], sep = ' ')

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

int main(){
  // std::ifstream in("input.txt");
  // std::cin.rdbuf(in.rdbuf());
  
  int K, X;
  cin >> K >> X;
  if(500 * K >= X){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-
import sys
sys.setrecursionlimit(10 ** 5)
input = sys.stdin.readline
mod = 1000000007
inf = float("INF")
def I(): return int(input().rstrip())
def IR(n): return [I() for _ in range(n)]
def LI(): return list(map(int, input().rstrip().split()))
def LIR(n): return [LI() for _ in range(n)]
def LI_(): return list(map(lambda x: int(x) - 1, input().rstrip().split()))
def LIR_(n): return [LI_() for _ in range(n)]
def F(): return float(input().rstrip())
def FR(n): return [F() for _ in range(n)]
def LF(): return list(map(float, input().rstrip().split()))
def LFR(n): return [LI() for _ in range(n)]
def S(): return input().rstrip()
def SR(n): return [S() for _ in range(n)]
def LS(): return list(sys.stdin.readline().rstrip().split())
def LSR(n): return [LS() for _ in range(n)]
# ↑template↑
# ↓solution↑
a, b = LI()
s = S()
if s.count('-') == 1 and a == s.find('-') and b == len(s) - s.find('-') - 1:
    print('Yes')
else:
    print('No')


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

const ll INF = 1LL << 60;
ll N, A[5000];
vector<ll> E[5000];

vector<ll> merge1(vector<ll> &dp, vector<ll> &ch1, vector<ll> &ch2) {
  vector<ll> next(dp.size() + ch1.size(), INF);
  REP(i, 0, dp.size()) if (dp[i] < INF) {
    REP(j, 0, ch1.size()) {
      if (ch1[j] < INF) next[i + j] = min(next[i + j], dp[i] + ch1[j]);
      if (ch1[j] < INF) next[i + j + 1] = min(next[i + j + 1], dp[i]);
      if (ch2[j] < 0) next[i + j + 1] = min(next[i + j + 1], dp[i]);
    }
  }
  return next;
}

vector<ll> merge2(vector<ll> &dp, vector<ll> &ch1, vector<ll> &ch2) {
  vector<ll> next(dp.size() + ch1.size(), INF);
  REP(i, 0, dp.size()) if (dp[i] < INF) {
    REP(j, 0, ch1.size()) {
      if (ch1[j] < INF) next[i + j] = min(next[i + j], dp[i] + ch1[j]);
      if (ch2[j] < INF) next[i + j] = min(next[i + j], dp[i] + ch2[j]);
      if (ch1[j] < INF) next[i + j + 1] = min(next[i + j + 1], dp[i]);
      if (ch2[j] < 0) next[i + j + 1] = min(next[i + j + 1], dp[i]);
    }
  }
  return next;
}

pair<vector<ll>, vector<ll>> dfs(ll v, ll p) {
  vector<ll> dp1(1, A[v] > 0 ? A[v] : INF), dp2(1, A[v]);
  for (ll u : E[v]) if (u != p) {
    pair<vector<ll>, vector<ll>> ch = dfs(u, v);
    vector<ll> ch1 = ch.first, ch2 = ch.second;
    dp1 = merge1(dp1, ch1, ch2);
    dp2 = merge2(dp2, ch1, ch2);
  }
  return make_pair(dp1, dp2);
}

ll solve() {
}

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> A[i];
  REP(i, 0, N - 1) {
    ll u, v;
    cin >> u >> v, u--, v--;
    E[u].push_back(v);
    E[v].push_back(u);
  }

  pair<vector<ll>, vector<ll>> dp = dfs(0, -1);
  vector<ll> dp1 = dp.first, dp2 = dp.second;

  ll ans = INF;
  REP(i, 0, dp1.size()) if (dp1[i] < INF || dp2[i] < 0) ans = min(ans, i);
  cout << ans << endl;
}

Measured memory_bytes: 2304
#include<iostream>
#include<string>
#include<queue>
#include<vector>
using namespace std;
struct Point{int x,y,c;};
struct xy{int x,y;};
int main(){
  int t;
  cin >> t;
  int i,j,k,a;
  for(i=0;i<t;i++){
    string str;
    int b;
    int o=0;
    int st[6][12]={{}};
    for(j=0;j<12;j++){
      cin >> str;
      for(k=0;k<6;k++){
	if(str[k]=='R') b=2;
	if(str[k]=='G') b=3;
	if(str[k]=='B') b=4;
	if(str[k]=='Y') b=5;
	if(str[k]=='P') b=6;
	if(str[k]=='O') b=1;
	if(str[k]=='.') b=0;
	st[k][j]=b;
      }
    }
    queue<Point> q;
    Point p,bu;

    int ax[]={1,-1,0,0},ay[]={0,0,1,-1};
    int f=0;
    int s;
    while(f==0){
      o++;
      f=1;
      int v[6][12]={{}};
      for(j=0;j<12;j++){
	for(k=0;k<6;k++){
	  if(st[k][j]==0||st[k][j]==1||v[k][j]==1) continue;
	  p.x=k;p.y=j;p.c=st[k][j];
	  q.push(p);
	  vector <xy> vxy;
	  xy bxy;
	  bxy.x=k;bxy.y=j;
	  vxy.push_back(bxy);
	  v[k][j]=1;
	  s=1;
	  while(!q.empty()){
	    p=q.front();
	    q.pop();
	    for(a=0;a<4;a++){
	      bu.x=p.x+ax[a];
	      bu.y=p.y+ay[a];
	      if(bu.x<0||bu.x>=6||bu.y<0||bu.y>=12) continue;
	      bu.c=st[bu.x][bu.y];
	      if(bu.c==1) {
		bxy.x=bu.x;bxy.y=bu.y;
		vxy.push_back(bxy);
		continue;
	      }
	      
	      if(bu.c==p.c&&v[bu.x][bu.y]==0){
		s++;
		bxy.x=bu.x;bxy.y=bu.y;
		vxy.push_back(bxy);
		q.push(bu);
		v[bu.x][bu.y]=1;
	      }
	    }
	  }
	  //cout << k << " " << j << endl;
	  
	  if(s>=4){
	    for(a=0;a<vxy.size();a++){
	      st[vxy[a].x][vxy[a].y]=0;
	      //cout << vxy[a].x << " " << vxy[a].y << endl;
	      f=0;
	      
	    }
	    
	  }
	  //cout << endl;
	}
      }
      /*

      for(j=0;j<12;j++){
	for(k=0;k<6;k++){
	  cout << v[k][j];
	}
	cout << endl;
      }

      */
      
      for(k=0;k<6;k++){
	vector<int> data;
	for(j=0;j<12;j++){
	  if(st[k][j]!=0) data.push_back(st[k][j]);
	}
	for(j=0;j<12-data.size();j++) st[k][j]=0;
	for(j=12-data.size();j<12;j++) st[k][j]=data[j+data.size()-12];
	
      }
      /*
      for(j=0;j<12;j++){
	for(k=0;k<6;k++){
	  cout << st[k][j];
	}
	cout << endl;
      }
      cout <<o<< endl;
      */
    }
    
    /*
      cout << endl;
    
    for(j=0;j<12;j++){
      for(k=0;k<6;k++){
	cout << st[k][j];
      }
      cout << endl;
    }
    */
    cout << o-1 << endl;
  }
}

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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define all(x) (x).begin(),(x).end()

using ll = long long;
using P = pair<int,int>;

const int MOD = 1e9 + 7;
const int INF = 1001001001;


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

    int x, n;
    cin >> x >> n;

    vector<int> p(n);
    for (int i = 0; i < n; ++i) {
        cin >> p[i];
    }
    sort(all(p));

    int tmp = INF, ans;
    for (int i = 101; i >= 0; --i) {
        if(!binary_search(all(p), i)){
            if(tmp >= abs(x-i)){
                ans = i;
                tmp = abs(x-i);
            }
        }
    }

    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 3648
//
/*==========================================================*/
/*    Template ver 2017-0720    |    Created by JollyBee    */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<pii> vii;
const double EPS=(double)1e-9;
const double PI=(double)acos(-1.0);
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define FOR(i,n) for(int i=0;i<n;i++)
#define REPP(i,l,r,c) for(int i=l;i<=r;i+=c)
#define REP(i,l,r) REPP(i,l,r,1)
#define FORD(i,n) for(int i=n-1;i>=0;i--)
#define REVV(i,l,r,c) for(int i=l;i>=r;i-=c)
#define REV(i,l,r) REVV(i,l,r,1)
//random
int irand(int lo, int hi){
    return (((double)rand())/(RAND_MAX+1.0)) * (hi-lo+1) + lo;
}
//ll to string
string toString(ll x) {
    stringstream ss;
    ss << x;
    return ss.str();
}
//string to ll
ll toNumber(string S) {
    ll ret;
    sscanf(S.c_str(),"%lld",&ret);
    return ret;
}
// std::fill(start, end, value);
// for(auto it: DS){}

const int INF=(int)2e9;
const ll MOD=(ll)1e9+7;
/*==========================================================*/
/*                     END OF TEMPLATE                      */
/* DOMINUS pascit me, et nihil mihi deerit (Psalmorum 23:1) */
/*==========================================================*/

int order[25];
int value[25];
int adds[25];

int main(){
    int n; scanf("%d", &n);
    REP(i,1,n) scanf("%d", order+i);
    REP(i,1,n) scanf("%d", value+i);
    REP(i,1,n-1) scanf("%d", adds+i);
    // do
    order[0] = -1;
    int res = 0;
    REP(i,1,n){
        res += value[order[i]];
        if(order[i-1]+1 == order[i]){
            res += adds[order[i-1]];
        }
    }
    // print
    printf("%d\n", res);
    return 0;
}


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

int main()
{
    int X, Y, Z;
    long long int K;

    cin >> X >> Y >> Z >> K;
    vector<long long int> A(X), B(Y), C(Z);
    vector<long long int> M, R;

    for (int i = 0; i < X; i++) {
        cin >> A.at(i);
    }
    for (int i = 0; i < Y; i++) {
        cin >> B.at(i);
    }
    for (int i = 0; i < Z; i++) {
        cin >> C.at(i);
    }

    for (int i = 0; i < X; i++) {
        for (int j = 0; j < Y; j++) {
            M.push_back(A.at(i) + B.at(j));
        }
    }

    sort(M.begin(), M.end());
    reverse(M.begin(), M.end());

    for (int i = 0; i < min((int)M.size(), (int)K); i++) {
        for (int j = 0; j < Z; j++) {
            R.push_back(M.at(i) + C.at(j));
        }
    }

    sort(R.begin(), R.end());
    reverse(R.begin(), R.end());

    for (int i = 0; i < K; i++) {
        cout << R.at(i) << endl;
    }

    return 0;
}

Measured memory_bytes: 43240
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????

		//Scanner????????????????????????
		Scanner scan = new Scanner(System.in);
		//A????????????(n,m)
		int n = scan.nextInt();
		int m = scan.nextInt();

		//a?????????
		int[][] aAry = new int[n][m];
		for(int i = 0; i < n; i++){

			for(int j = 0; j < m; j++){
				aAry[i][j] = scan.nextInt();
			}
		}

		//b?????????
		int[] bAry = new int[m];
		//?????????????´?
		for(int i = 0; i < m; i++ ){

			bAry[i] = scan.nextInt();
		}

		scan.close();

		//?????????????????\???????????°
		int intAnswer = 0;

		for(int i =0; i < n; i++){
			//?????????????????\???????????°
			int intResult = 0;
			for(int j = 0; j < m; j++){
				//???????????????????????£??\
				intAnswer = bAry[j] * aAry[i][j];
				intResult = intResult + intAnswer;
			}
			System.out.println(intResult);
			//intResult????????????
			//intResult = 0;
		}


	}
}

Measured memory_bytes: 32064
n = int(input())
a = list(map(int, input().split()))
cnt2 = 0
cnt4 = 0
for i in range(n):
    if(a[i] % 4 == 0):
        cnt4 += 1
    elif(a[i] % 2 == 0):
        cnt2 += 1

if((cnt4 * 2 + 1) >= n or cnt2 >= (n - (cnt4 * 2 + 1) + 1)):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 62576
# pragma GCC optimize("O3")
# include <bits/stdc++.h>
# define maxn 100005
# define ll long long
# define clock (clock() * 1000.0 / CLOCKS_PER_SEC)
# define rc(s) return cout << s,0
# define _ ios_base::sync_with_stdio(false);cin.tie(0);cerr.tie(0);cout.tie(0);
# define db(x) cerr << #x << " = " << x << '\n'
# define pb push_back
# define mp make_pair
# define sz(x) (int)((x).size())
//# define int ll
using namespace std;
#define pii pair<int,int>
const int mod = 1e9 + 7;

const int inf = INT_MAX;
vector<pair<int,int>>v,vv;
set<pair<int,int>>s;

bool viz[maxn];
vector< pii > ans;
vector< pii > vec[maxn];
int sum,n,x,y,z,m,vizited;
priority_queue< pair< int,pii >, vector< pair< int,pii > >, greater < pair< int,pii > > > Q;

void prim()
{
    viz[1] = 1;
    for(int i = 0;i<vec[1].size();i++)
        Q.push(mp(vec[1][i].first,mp(1,vec[1][i].second)));
    while(vizited>0 && !Q.empty())
    {
        while(viz[Q.top().second.first] && viz[Q.top().second.second] && !Q.empty())
            Q.pop();
        if(Q.empty()) break;
        int n1 = Q.top().second.first;
        int n2 = Q.top().second.second;
        ans.push_back(mp(n1,n2));
        sum+=Q.top().first;
        if(!viz[n1]) vizited--;
        if(!viz[n2]) vizited--;
        Q.pop();
        if(!viz[n1])
            for(int i = 0;i<vec[n1].size();i++)
                if(!viz[vec[n1][i].second]) Q.push(mp(vec[n1][i].first,mp(vec[n1][i].second,n1)));
        if(!viz[n2])
            for(int i = 0;i<vec[n2].size();i++)
                if(!viz[vec[n2][i].second]) Q.push(mp(vec[n2][i].first,mp(vec[n2][i].second,n2)));
        viz[n1] = 1;
        viz[n2] = 1;
    }
}

int32_t main(){_
    //freopen("input","r",stdin);
    cin >> n;
    for(int i = 1;i <= n;i++)
    {
		cin >> x >> y;
		s.insert(mp(x,y));
    }
    int i = 1;
    for(auto it : s)
    {
		v.pb(mp(it.first,i));
		vv.pb(mp(it.second,i));
		i++;
	}
	sort(v.begin(),v.end());
	sort(vv.begin(),vv.end());
	n = sz(s);
	vizited = n;
	for(int i = 0;i < sz(v) - 1;i++)
	{
        vec[v[i].second].pb(mp(abs(v[i + 1].first - v[i].first),v[i + 1].second));
        vec[v[i + 1].second].pb(mp(abs(v[i + 1].first - v[i].first),v[i].second));
        m += 2;
	}
	swap(v,vv);
	for(int i = 0;i < sz(v) - 1;i++)
	{
        vec[v[i].second].pb(mp(abs(v[i + 1].first - v[i].first),v[i + 1].second));
        vec[v[i + 1].second].pb(mp(abs(v[i + 1].first - v[i].first),v[i].second));
        m += 2;
	}
	prim();
	rc(sum);
}


Measured memory_bytes: 17384
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);
        int n = scanner.nextInt();
        Node[] nodes = new Node[n];
        for (int i = 0; i < n; i++) {
            nodes[i] = new Node(i);
        }
        for (int i = 0; i < n; i++) {
            Node node = nodes[scanner.nextInt()];
            int left = scanner.nextInt();
            int right = scanner.nextInt();
            if (left != -1) {
                node.left = nodes[left];
                nodes[left].parent = node;
            }
            if (right != -1) {
                node.right = nodes[right];
                nodes[right].parent = node;
            }
        }
        Node root = null;
        for (int i = 0; i < n; i++) {
            if (nodes[i].parent == null) {
                root = nodes[i];
                break;
            }
        }

        StringBuilder sb = new StringBuilder();
        sb.append("Preorder\n");
        root.preOrder(sb);
        sb.append("\n");
        sb.append("Inorder\n");
        root.inOrder(sb);
        sb.append("\n");
        sb.append("Postorder\n");
        root.postOrder(sb);
        System.out.println(sb.toString());
    }

    private static class Node {
        int id;
        Node parent;
        Node left;
        Node right;

        public Node(int id) {
            this.id = id;
        }

        private void preOrder(StringBuilder sb) {
            sb.append(" " + String.valueOf(id));
            if (left != null) {
                left.preOrder(sb);
            }
            if (right != null) {
                right.preOrder(sb);
            }
        }

        private void inOrder(StringBuilder sb) {
            if (left != null) {
                left.inOrder(sb);
            }
            sb.append(" " + String.valueOf(id));
            if (right != null) {
                right.inOrder(sb);
            }
        }

        private void postOrder(StringBuilder sb) {
            if (left != null) {
                left.postOrder(sb);
            }
            if (right != null) {
                right.postOrder(sb);
            }
            sb.append(" " + String.valueOf(id));
        }
    }
}

Measured memory_bytes: 26456
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;

ll mod_pow(ll a, ll n, ll p) {
	if (n == 0) return 1;
	if (n % 2 == 0) {
		ll tmp = mod_pow(a, n / 2, p);
		return (tmp * tmp) % p;
	}
	return (a * mod_pow(a, n - 1, p)) % p;
}

// 多項式P(x)を受け取って(x-s)P(x)+tという多項式を返す
// 係数はmod p
vector<ll> mul(const vector<ll> &P, int s, int t, ll p) {
	vector<ll> Q(P.size() + 1);
	for (int i = 0; i < P.size(); i++) {
		(Q[i + 1] += P[i]) %= p;
		(Q[i] += P[i] * (p - s) % p) %= p;
	}
	(Q[0] += t) %= p;
	return Q;
}

ll inv[2999];
ll a[2999];
int main() {
	int p;
	cin >> p;
	for (int i = 1; i < p; i++) {
		inv[i] = mod_pow(i, p - 2, p);
	}
	for (int i = 0; i < p; i++) cin >> a[i];
	vector<ll> s, t;
	for (int i = 0; i < p; i++) {
		s.push_back(i);
		t.push_back(a[i]);
		for (int j = i + 1; j < p; j++) {
			(a[j] += p - a[i]) %= p;
			(a[j] *= inv[j - i]) %= p;
		}
	}
	vector<ll> P = { 1 };
	for (int i = p - 1; i >= 0; i--) {
		P = mul(P, s[i], t[i], p);
	}
	(P[1] += P[p]) %= p;
	for (int i = 0; i < p; i++) cout << P[i] << " ";
	cout << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

vi v,ans;
int a,b,n;
int x[200010];
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n;
    for(int i=1;i<=n;i++){cin>>x[i];v.pb(x[i]);}
    sort(v.begin(),v.end());
    b = v[n/2 - 1];
    a = v[n/2];
    for(int i=1;i<=n;i++){
        if(x[i]<a){ans.pb(a);}
        else ans.pb(b);
    }
    for(int i=0;i<ans.size();i++)cout<<ans[i]<<newl;
}


Measured memory_bytes: 4724
N,W=map(int,input().split())
li=[list(map(int,input().split())) for i in range(N)]
max_n=0
for a in range(N):
    max_n+=li[a][1]
dp=[[float('INF')]*(max_n+1) for i in range(N+1)]
dp[0][0]=0
for i in range(N):
    for sum_v in range(max_n+1):
        if sum_v >= li[i][1]:
            dp[i+1][sum_v]=min(dp[i][sum_v],dp[i][sum_v-li[i][1]]+li[i][0])
        else:
            dp[i+1][sum_v]=dp[i][sum_v]
ans=0
for i in range(max_n+1):
    if dp[N][i] <= W:
        ans = i
print(ans)


Measured memory_bytes: 307656
import numpy as np
N = int(input())
#print("N",N)
a_arr = input().split()
tmp = []
for ele in a_arr:
    tmp.append(int(ele))
arr = np.array(tmp)
avg = np.mean(arr)
evaluate_arr = np.abs(arr - avg)
evaluate_pos = np.argmin(evaluate_arr)
print(evaluate_pos)

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

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define IOS             ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define read            freopen("in.txt","r",stdin)
#define write           freopen("out.txt","w",stdout)
#define ms(a,x)         memset(a,x,sizeof a)
#define ll              long long int
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define rall(a)         a.rbegin(),a.rend()
#define pb              push_back
#define nl              cout<<"\n"
#define gcd(a,b)        __gcd((a),(b))
#define lcm(a,b)        ((a)*(b))/(gcd(a,b))
#define sq(a)           (a)*(a)
#define loop(i,a,b)     for (ll i = a; i <= b; i++)
#define rloop(i,a,b)    for (ll i = a; i >= b; i--)
#define sz(a)           a.size()
#define mod             1000000007
#define PI              2*acos(0.0)

int main()
{
    IOS
    int T=1;
    //cin>>T;
    while(T--)
    {
        ll n,x,t;
        cin>>n>>x>>t;
        if(n%x)
        {
            cout<<(n/x)*t+t;
        }
        else cout<<(n/x)*t;
    }
    return 0;
}


Measured memory_bytes: 3600
import java.io.InputStream;
import java.util.Scanner;

public class Main {
	static Scanner sc;

	public static void main(String[] args) throws Exception {
		//InputStream in = new FileInputStream("src/input.txt");
		InputStream in = System.in;

		sc = new Scanner(in);
		
		int n = sc.nextInt();
		
		int[] a = new int[n];
		
		for(int i = 0; i < n; i++){
			a[i] = sc.nextInt() - 1;
		}
		
		int answer = 0;
		int nowPoint = 0;
		
		while(nowPoint + 1 != 2){
			int prePoint = nowPoint;
			nowPoint = a[nowPoint] ;
			a[prePoint] = -1;
			answer++;
			//System.out.println("ans " + answer);
			if(nowPoint == -1){
				answer = -1;
				break;
				//System.out.println("out");
			}
		}
		
		System.out.println(answer);

	}
}

Measured memory_bytes: 51112
#include <iostream>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<tuple>
#include<sstream>
#include<functional>
#include<list>
#include<queue>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).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; }
typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> p;
typedef pair<int, pair<int, pair<int, int>>> PP;
typedef vector<int> vec;
using Graph = vector<vector<int>>;
using graph = vector<vector<ll>>;

const long long INF = 1LL << 60;
const int inf = 1e9;
const long long MOD = 1e9+7;



int main() {
	int n;
	cin >> n;
	int cnt = 0;
	rep(i, n) {
		int a, b;
		cin >> a >> b;
		if (a == b)cnt++;
		else cnt = 0;
		if (cnt == 3)break;
	}
	if (cnt == 3)cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 3632
#include <iostream>

using namespace std;
bool all(int *a,int n)
{
for(int i=0;i<n;i++)
if(a[i]%2!=0)
return 0;
return 1;
}
void half(int *a,int n)
{for(int i=0;i<n;i++)
a[i]/=2;}

int main() {int x;
cin >>x;
int a[x];
for(int i=0;i<x;i++)
cin >>a[i];
int count=0;
while(all(a,x))
{count++;
half(a,x);}
cout << count;
return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;

bool solve(int X, int M, vector<int>ss) {
	if (1 + X <= ss[0]) {
		return true;
	}
	 {

		int now_enemy=0;
		int now_level=1;

		for (int i = 0; i < M-1; ++i) {
			if(now_level+X>ss.back())return false;
			while (true) {
				if (now_level + X > ss[now_enemy + 1]) {
					int now_exp=max(1,X-abs(now_level-ss[now_enemy]));
					int next_exp=max(1,X-abs(now_level-ss[now_enemy+1]));

					if (now_exp <= next_exp) {
						now_enemy++;
					}
					else {
						break;
					}
				}
				else {
					break;
				}
			}

			now_level+=max(1,X-abs(now_level-ss[now_enemy]));
		}
		return true;
	}
}

int main()
{
	while (true) {
		int N,M;cin>>N>>M;
		if(!N)break;
		vector<int>ss(N);
		for(int i=0;i<N;++i)cin>>ss[i];

		int amin=-1;
		int amax=1e9;

		while (amin + 1 != amax) {
			int amid=(amin+amax+1)/2;

			if (solve(amid, M, ss)) {
				amin=amid;
			}
			else {
				amax=amid;
			}
		}
		if (amin == 0) {
			cout<<-1<<endl;
		}
		else if (amin + 1 <= ss[0]) {
			cout<<-1<<endl;
		}
		else {
			cout << amin << endl;

		}
	}
	return 0;
}



Measured memory_bytes: 3588
#[allow(unused_imports)]
use std::cmp::{max, min};
#[allow(unused_imports)]
use std::collections::{HashMap, HashSet};

mod util {
    use std::io::stdin;
    use std::str::FromStr;
    use std::fmt::Debug;

    #[allow(dead_code)]
    pub fn line() -> String {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().to_string()
    }

    #[allow(dead_code)]
    pub fn get<T: FromStr>() -> T
        where <T as FromStr>::Err: Debug
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.trim().parse().unwrap()
    }

    #[allow(dead_code)]
    pub fn gets<T: FromStr>() -> Vec<T>
        where <T as FromStr>::Err: Debug
    {
        let mut line: String = String::new();
        stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|t| t.parse().unwrap())
            .collect()
    }
}

fn main() {
    let mut s: Vec<_> = util::line().chars().collect();
    s.sort();
    if s.windows(2).any(|v| v[0] == v[1]) {
        println!("no");
    } else {
        println!("yes");
    }
}


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

using namespace std;

#define ll long long

int main()
{
	ll N, K;
	cin >> N >> K;
	vector < ll > H(N);
	for (int i = 0; i < N; i++) {
		cin >> H[i];
	}
	sort(H.begin(), H.end());
	ll ans = 0;
	for (int i = 0; i < N - K; i++) {
		ans += H[i];
	}

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


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

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

using ll = long long int;
const ll MOD = 1e9 + 7;

int main() {
  int X, Y, A, B, C;
  std::cin >> X >> Y >> A >> B >> C;

  std::vector<ll> p(A), q(B), r(C);
  rep(i, A) std::cin >> p[i];
  rep(i, B) std::cin >> q[i];
  rep(i, C) std::cin >> r[i];

  std::sort(p.rbegin(), p.rend());
  std::sort(q.rbegin(), q.rend());

  std::priority_queue<ll> que;
  rep(i, std::min(X, A)) {
    que.push(p[i]);
  }
  rep(i, std::min(Y, B)) {
    que.push(q[i]);
  }
  rep(i, C) {
    que.push(r[i]);
  }

  ll ans = 0;
  rep(i, X + Y) {
    ans += que.top(); que.pop();
  }

  std::cout << ans << '\n';
}


Measured memory_bytes: 8688
#include<bits/stdc++.h>
using namespace std;
int w[100001];
int n,k,v;
int cont(long long p){
    int t=k,i=0;
    long long tt=0;
    while (t--){
    	while (tt<=p){
    		  tt+=w[i++];
    		  if (i-1==n && tt<=p){
    		  	// if (t==0){
    		  	    return n;	
			//	 }
				// else return n+1;
			  }
			  if (tt>p) i--;
		}
		tt=0;
	}
	return i;
}
int main(){
	cin>>n>>k;
	long long l=20000,r=1,mid;
	for (int i=0; i<n; i++){
		cin>>w[i];
		r+=w[i];
		if (w[i]<l) l=w[i];
	}
	while (l<r){
		  mid=(l+r)/2;
		  v=cont(mid);
		  //if (cont(mid)==n){
		//  	  while (cont(mid)==n) mid--;
		 // 	  cout<<mid+1<<endl;
		//  	  break;
		//  }
		  if (v<n)
		     l=mid+1;
		  else
		     r=mid;
	}
	cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 3492
from collections import Counter


def LI():
    return list(map(int, input().split()))


N, K = LI()
A = LI()
A = Counter(A)
A = sorted(A.items(), key=lambda x: x[1])
ans = 0

if len(A) > K:
    L = len(A)-K
    for i in range(L):
        ans += A[i][1]

print(ans)


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

long long gcd(long long x, long long y) {
	return y ? gcd(y, x % y) : x;
}

int main() {
	long long N;
	cin >> N;
	vector<long long> A(N), gcd_l(N+1, 0), gcd_r(N+1, 0), gcds(N);
	for (long long i = 0; i < N; i++)
	{
		cin >> A[i];
	}

	for (long long i = 0; i < N; i++)
	{
		gcd_l[i + 1] = gcd(gcd_l[i], A[i]);
		gcd_r[i + 1] = gcd(gcd_r[i], A[N - i - 1]);
	}

	long long ans = 0;
	for (long long i = 0; i < N; i++)
	{
		gcds[i] = gcd(gcd_l[i], gcd_r[N - i - 1]);
		ans = max(gcds[i], ans);
	}

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


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

#define endl '\n'
#define endt '\t'
#define ends ' '
#define die(x) return cout << x << endl, 0;
#define all(v) v.begin(), v.end()
#define sz(x) (int)(x.size())
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) { cerr << ends << H; debug_out(T...); }
#define debug(...) cerr << '[' << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const ll MOD = 924844033; 

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

const int MAXN = 2e3 + 5;

int F[MAXN], M[MAXN];
int DP[MAXN][MAXN];

void Mul(int &x, int y) { x = 1LL * x * y % MOD; }
int SMul(int x, int y) { return 1LL * x * y % MOD; }
int SAdd(int x, int y) { int z = x + y; if (z >= MOD) z -= MOD; return z; }
void Add(int &x, int y) { x += y; if (x >= MOD) x -= MOD; }

int main() {

	ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);

	#ifdef LOCAL
	ifstream cin("sample.in");
	#endif

	F[0] = 1;
	for (int i = 1; i < MAXN; i++) F[i] = SMul(i, F[i - 1]);
	DP[0][0] = 1;
	for (int i = 1; i < MAXN; i++) {
		DP[i][0] = 1;
		for (int j = 1; 2 * j <= i; j++) DP[i][j] = SAdd(DP[i - 1][j], DP[i - 2][j - 1]);
	}

	int n, k; cin >> n >> k;
	
	M[0] = 1;
	for (int i = 0; i < min(n, k << 1); i++) {
		int l = (n - i - 1) / k + 1 + (i >= k);
		for (int j = MAXN - 1; j >= 0; j--) for (int m = 1; m <= j && 2 * m <= l; m++) Add(M[j], SMul(M[j - m], DP[l][m]));
	}
	int ans = 0;
	for (int i = 0; i <= n; i++) {
		if (i & 1) Add(ans, MOD - SMul(M[i], F[n - i]));
		else Add(ans, SMul(M[i], F[n - i]));
	}
	cout << ans << endl;


	return 0;
}

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

int main() {
  int N;
  cin >> N;
  
  int64_t b = 1;
  for (int i=0; i<N; i++){
    int64_t a;
    cin >> a;
    if (b != -1){
      int64_t c=1000000000000000000/b;
      if (a>c)
        b = -1;
      else
        b *= a;
    }
    else if (a == 0){
      b = 0;
      break;
    }
  }
  
  cout << b << endl;

}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(ll i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const int MOD = 1000000007;
#define MAX_N 200010

ll N;
vector<ll> P;

bool isUsed[MAX_N] = {};
ll pToInd[MAX_N] = {};

signed main()
{
    cin >> N;
    REP(i, N) {
        ll tmp;
        cin >> tmp;
        P.push_back(tmp);
        pToInd[tmp] = i;
    }

    ll ans = N - 1;
    for(ll i = 1; i < N; ++i) {
        if(isUsed[i]) { continue; }
        ll cur = i;
        ll cand = 1;
        while(1) {
            isUsed[cur] = true;
            ll next = cur + 1;
            if(next > N) { break; }
            if(pToInd[cur] < pToInd[next]) {
                cur = next;
                cand++;
            } else {
                break;
            }
        }
        ans = min(ans, N - cand);
    }
    printf("%lld\n", ans);

    return 0;
}


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

using namespace std;

#define sz(x) (int)((x).size())
#define forn(i,n) for (int i=0; i < n; i++)
#define forse(i,s,e) for (int i=s; i < e; i++)
#define pb push_back
#define fi first
#define se second
#define all(vec) vec.begin(), vec.end()
#define time() ((double)clock() / CLOCKS_PER_SEC)

typedef unsigned long long ull;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

//Debug
string to_string(const string& s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
string to_string(bool b) { return (b ? "true" : "false");}
template <typename A, typename B>
string to_string(pair<A, B> p) {return "("+to_string(p.fi)+", "+to_string(p.se)+")";}
template <typename A>
string to_string(A v) {
	if(v.begin()==v.end()) return "";
	return accumulate(++v.begin(), v.end(), "{"+to_string(*v.begin()),
			[](const string& a, auto b){ return a + ", " + to_string(b);})+"}";
}
void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {cerr << " " << to_string(H); debug_out(T...);}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) false
#endif


double PI=3.141592653589793;

const int mx=1e6+1;
int ise[mx]={};

void solve(){
	int n,ans=0;
	cin >> n;
	vector<int> in;
	forn(i,n){
		int k;cin >> k;
		ise[k]++;
		in.pb(k);
	}
	forn(i,n){
		int k=in[i];
		ise[k]--;
		bool chk=1;
		for(int p=1;p*p<=k;p++){
			if(k%p) continue;
			if(ise[p]) chk=0;
			if(ise[k/p]) chk=0;
		}
		if(chk) ans++;
		ise[k]++;
	}
	cout << ans;
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0); 
	int T=1;
//	cin >> T;
	forse(c,1,T+1){
		//	cout << "Case #" << cid << ": ";
		solve();
	}
}


Measured memory_bytes: 8160
#include <stdio.h>

int main(){
  int n,q,i,j,C=0;

  scanf("%d",&n);

  int S[n];

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

  scanf("%d",&q);

  int T[q];
  
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  for(i=0;i<q;i++){
    for(j=0;j<n;j++){
      if(S[j]==T[i]){
	C++;
	j=n;
      }
    }
  }

  printf("%d\n",C);

  return 0;
}
  



Measured memory_bytes: 2104
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools
sys.setrecursionlimit(10**8)
mod = 10**9+7
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
a = inpl()
a.sort()
print(a[-1]-a[0])

Measured memory_bytes: 38256
#include "bits/stdc++.h"
using namespace std;
#define FOR(i,j,k) for(int (i)=(j);(i)<(int)(k);++(i))
#define rep(i,j) FOR(i,0,j)
#define each(x,y) for(auto &(x):(y))
#define mp make_pair
#define MT make_tuple
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<(x)<<endl
#define smax(x,y) (x)=max((x),(y))
#define smin(x,y) (x)=min((x),(y))
#define MEM(x,y) memset((x),(y),sizeof (x))
#define sz(x) (int)(x).size()
#define rt return
using dbl = double;
using ll = long long;
using pii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;

vi G[100001];

int f(int u, int p) {
    if (u != 0 && sz(G[u]) == 1) { // leaf
        return 0;
    }
    int sm = 0;
    each(v, G[u])if (v != p) {
        sm ^= f(v, u) + 1;
    }
    return sm;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N; // 2<=N<=10^5
    cin >> N;

    rep(i, N - 1) {
        int x, y; // 1<=x,y<=N
        cin >> x >> y;
        --x; --y;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    int gr = f(0, -1);
    cout << (gr ? "Alice" : "Bob") << endl;
}


Measured memory_bytes: 10368