akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long LL;
typedef pair<LL,LL> P;
const LL LINF=1LL<<62;
#define max 302

LL dp[max][max];
LL c[max][max];
LL d[max];

int main(){
    int N,K,mod;
    cin >> N >> K >> mod;
    for(int i=0;i<max;i++) {
        for(int j=0;j<max;j++) {
            if(j==0) c[i][j]=1;
            else if(i==0) c[i][j]=0;
            else c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
        }
    }
    for(int i=0;i<=K;i++){
        dp[1][i]=1;
    }
    for(int n=2;n<=N+1;n++){
        memset(d,0,sizeof(d));
        for(int k=K-1;k>=0;k--){
            for(int i=0;i<n;i++){
                d[i]=(d[i]+dp[i][k+1])%mod;
            }
            for(int i=1;i<n;i++){
                dp[n][k]=(dp[n][k]+dp[n-i][k]*c[n-2][i-1]%mod*d[i]%mod)%mod;
            }
        }
    }
    cout << dp[N+1][0] << endl;
    return 0;
}

Measured memory_bytes: 1664
#C - Count Order
#DFS
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))

a = 0
b = 0
cnt = 0
def dfs(A):
    global cnt
    global a
    global b
    if len(A) == N:
        cnt += 1
        if A == P:
            a = cnt
        if A == Q:
            b = cnt
        return   
    for v in range(1,N+1):
        if v in A:
            continue
        A.append(v)
        dfs(A)
        A.pop()
dfs([])
print(abs(a-b))

Measured memory_bytes: 9216
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
#include <bitset>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll mod = 1e9 + 7;
ll MOD = 1e9 + 7;
ll INF = 1e18;
long long modinv(long long a, long long m)
{
    long long b = m, u = 1, v = 0;
    while (b)
    {
        long long t = a / b;
        a -= t * b;
        swap(a, b);
        u -= t * v;
        swap(u, v);
    }
    u %= m;
    if (u < 0)
        u += m;
    return u;
}
ll combi(ll a, ll b)
{
    if (a < b)
        return 0;
    ll res = 1;
    for (ll i = a; i >= a - b + 1; i--)
    {
        res *= i;
        res %= MOD;
    }
    rep3(i, 1, b + 1)
    {
        res *= modinv(i, MOD);
        res %= MOD;
    }
    return res;
}
//a,m=MOD MOD逆元
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin >> n;
    string s;
    cin>>s;
    sort(all(s));
    map<int, ll> mp;
    rep(i,n){
        mp[s[i] - 'a']++;
    }
    ll res = 1;
    rep(i,26){
        res *= (mp[i] + 1);
        res %= MOD;
    }
    cout << res-1 << endl;
}


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

//+=を=+と打って動作してた

const int INF = 1001000000;

int main(){
  int n,m,a[1000000]={0},res=0;
  long int total=0;
  cin >> n;
  m=3*n;
  for(int i=0;i<m;i++){
    cin >> a[i];
  }
  sort(a,a+3*n,greater<int>());
  //上から二つ飛びでとってく
  /*for(int i = 0;i<3*n;++i){
    cout << a[i] << flush;
  }*/
  //cout << endl;
  for(int i=0;i<n;i++){
    total+=a[2*i+1];
  //  cout << a[2*i+1] << endl;
  }
  cout << total << endl;
}


Measured memory_bytes: 4096
count = 0;
maxnum=0;
s = input();

for i in range(len(s)):
    if(s[i]=='A' or s[i]=='T' or s[i]=='G' or s[i]=='C'):
        count  = count +1;
    else:
        maxnum = max(count,maxnum);
        count = 0;

maxnum = max(count,maxnum);
print(maxnum);

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

int main(){
  int64_t N, K;
  cin >> N >> K;
  vector <int64_t> H(N);
  for (int64_t i = 0; i < N; i++){
    cin >> H.at(i);
  }
  sort(H.begin(), H.end());
  int64_t sum = 0;
  int64_t normal = H.size() - K;
  if (normal > 0){
    for (int64_t i = 0; i < normal; i++){
      sum += H.at(i);
    }

    cout << sum << endl;
  }
  else cout << 0 << endl;
  }

Measured memory_bytes: 1792
#include<stdio.h>
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <iostream>
#include <iterator>
#include <list>
#include <map>     
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <iomanip>
#include <stack>
#include <string>
#include <vector>
using namespace std;
#define ll long long
#define ld long double
#define loop(a,t) for(int a=0;a<t;a++) 
#define forever while(true)
#define Sort(a) sort(a.begin(),a.end())
#define Reverse(a) reverse(a.begin(),a.end())
int ans[300];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	while (true) {
		int a, b, c, n;
		cin >> a >> b >> c;
		if (a == 0 && b == 0 && c == 0) { break; }
		cin >> n;
		int ak[1000], bk[1000], ck[1000];
		loop(i, 1000) {
			ak[i] = bk[i] = ck[i] = -1;
			if (i < 300) {
				ans[i] = 2;
			}
		}
		loop(i, n) {
			int an, bn, cn, or1;
			cin >> an >> bn >> cn >> or1;
			if (or1 == 1) {
				ans[an - 1] = 1;
				ans[bn - 1] = 1;
				ans[cn - 1] = 1;
			}
			else {
				ak[i] = an - 1;
				bk[i] = bn - 1;
				ck[i] = cn - 1;
			}
		}
		loop(i, n) {
			if (ak[i] != -1) {
				if (ans[ak[i]] == 2 && ans[bk[i]] == 1 && ans[ck[i]] == 1) {
					ans[ak[i]] = 0;
				}
				if (ans[ak[i]] == 1 && ans[bk[i]] == 2 && ans[ck[i]] == 1) {
					ans[bk[i]] = 0;
				}
				if (ans[ak[i]] == 1 && ans[bk[i]] == 1 && ans[ck[i]] == 2) {
					ans[ck[i]] = 0;
				}

			}
		}
		loop(i, a + b + c) {
			cout << ans[i] << endl;
		}

	}
	return 0;

}


Measured memory_bytes: 3148
N,A,B=map(int,input().split())
H=[int(input()) for _ in range(N)]
H=sorted(H,reverse=True)

ok=max(H)//B+1
ng=0
mid=(ok+ng)//2
while ok-ng>1:
  cntlive=0
  for h in H:
    h-=B*mid
    if h>0:
      cntlive+=(h+A-B-1)//(A-B)
  if cntlive<=mid:
    ok=mid
  else:
    ng=mid
  mid=(ok+ng)//2
print(ok)


Measured memory_bytes: 8280
use std::io::*;
use std::str::FromStr;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n = read::<usize>();
    let mut aseq = vec![0; n];
    let mut sum = 0;
    for i in 0..n {
        aseq[i] = read::<i64>();
        sum += aseq[i];
    }
    let mut ans = 1i64 << 60;
    let mut v = 0;
    for i in 0..n - 1 {
        v += aseq[i];
        ans = std::cmp::min(ans, (v - (sum - v)).abs());
    }
    println!("{}", ans);
}


Measured memory_bytes: 6396
#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()

int x;
int main() {
  cin >> x;
  cout << (x < 1200 ? "ABC" : "ARC") << endl;
  return 0;
}


Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        k: usize,
        mut p: [i32; n]
    }

    solve(k, &mut p);
}

fn solve(k: usize, p: &mut [i32]) {
    p.sort();

    let s = p.iter().take(k).sum::<i32>();
    println!("{}", s);
}


Measured memory_bytes: 2172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
const int INF = 1000000000; // 10^9
int main() {
    // ifstream in("data1.txt");
    // cin.rdbuf(in.rdbuf());
    double N, M;
    cin >> N >> M;
    vector<double> v(N);
    rep(i, N) cin >> v[i];
    double total = 0;
    int cnt = 0;
    rep(i, N) { total += v[i]; };

    rep(i, N){
        if(v[i] >= total / (4 * M)) {
            cnt++;
        }
    };
    if(cnt >= M){
        cout << "Yes" << endl;
        return 0;
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  double a,b,h,m;
  cin >> a >> b >> h >> m;
  double s,t;
  s = 2*acos(-1)*m/60;
  t = 2*acos(-1)*(60*h+m)/(12*60);
  double th;
  if(abs(s-t) > acos(-1)){
    th = 2*acos(-1) - abs(s-t);
  }else{
    th = abs(s-t);
  }
  double x;
  x = sqrt(a*a+b*b-2*a*b*cos(th));
  printf("%.10f\n", x);
  return 0;
}


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

ans = 0
for i in range(1, N):
    if A[i] + A[i-1] > x:
        diff1 = min((A[i] + A[i-1]) - x, A[i])
        ans += diff1
        A[i] -= diff1
    if A[i] + A[i-1] > x:
        diff0 = A[i-1] - x
        ans += diff0

print(ans)


Measured memory_bytes: 14052
#include<bits/stdc++.h>
using namespace std;
int f1=0,top,i,l,f=0;
char c[256];
int main()
{
	gets(c);
	l=strlen(c);
	for(i=0;i<l&&!f;i++)
		if(c[i]=='C') f=1;
	for(;i<l&&!f1;i++)
		if(c[i]=='F') f1=1;
	if(f&&f1) cout<<"Yes";
	else cout<<"No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, a, b) for (int i = a; i < b; i++)
//'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122

int main() {
    int n, k;
    cin >> n >> k;
    map<int, int> mp;
    rep(i, 0, n) {
        int a;
        cin >> a;
        mp[a]++;
    }

    vector<int> cnt;
    for (auto x:mp) {
        cnt.push_back(x.second);
    }

    sort(cnt.begin(), cnt.end());

    int ans = 0;
    int dif = cnt.size() - k;
    for (int i = 0; i <= dif - 1; i++) {
        ans += cnt[i];
    }

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


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
typedef vector<int> vi;
typedef vector<ll> vl;

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

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

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

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

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

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

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

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


int main(){
    
    ll r,g,b, n;
    cin >> r >> g >> b >> n;
    
    ll ans = 0;
    
    ll rn = 0,gn = 0;
    while(rn <= n){
	gn = 0;
	while(gn <= n){
	    if((n - rn -gn)%b == 0 && (n - rn -gn) >= 0){
		//	PS(rn);PS(gn);P(n - rn -gn);
		ans++;
	    }
	    gn += g;
	}
	rn += r;
    }
    
    P(ans);
    
    return  0;
}


Measured memory_bytes: 256
N,K=map(int,input().split())
A=input().split()
balls=[int(a) for a in A]
answers=[0]*200000
for a in balls:
    answers[a-1]+=1
list=[a for a in answers if a!=0]
newlist=sorted(list)
n=len(newlist)-K
answer=0
for a in range(n):
    answer+=newlist[a]
print(answer)


Measured memory_bytes: 29064
#include<iostream>
#include<iomanip>
//#include<cstdio>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cassert>
using namespace std;
typedef long long ll;
const int Hmax=300;
int H, W, D, A[Hmax][Hmax], Q;

int main(){
	cin >> H >> W >> D;
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++) cin >> A[i][j];
	}

	vector<pair<int, int>> pos(H*W+1);
	for(int i=0; i<H; i++){
		for(int j=0; j<W; j++) pos[A[i][j]] = {i, j};
	}

	vector<int> cost(H*W+1);
	for(int i=D+1; i<=H*W; i++){
		cost[i] = cost[i-D]
				+ abs(pos[i].first-pos[i-D].first)
				+ abs(pos[i].second-pos[i-D].second);
	}

	cin >> Q;

	for(int i=0; i<Q; i++){
		int L, R;
		cin >> L >> R;
		cout << cost[R]-cost[L] << endl;
	}

	return 0;
}


Measured memory_bytes: 2560
/* ITP1_9_C */
import java.io.*;

class Main
{
  public static void main(String[] args)
  {
    try{
      BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
      StringBuilder sb = new StringBuilder();

      int n = Integer.parseInt(br.readLine());
      int taro = 0;
      int hanaco = 0;

      for(int i = 0; i < n; i++){
        String[] str = br.readLine().split(" ");
        String taro_card = str[0];
        String hanaco_card = str[1];
        int comp = taro_card.compareTo(hanaco_card);

        if(comp > 0) taro += 3;
        else if(comp < 0 ) hanaco += 3;
        else if(comp == 0){
          taro++;
          hanaco++;
        }
      }
      sb.append(taro).append(" ").append(hanaco);
      System.out.println(sb);
    }catch(Exception e){
      System.out.println(e);
    }
  }
}

Measured memory_bytes: 25192
#include <iostream>
#include <climits>
using namespace std;
int s[2];
int main(){
  int n, a;
  while(cin >> n, n){
    int ans = -(INT_MAX-1);
    for(int i = 0 ; i < n ; i++){
      cin >> a;
      if(i == 0)s[0] = a;
      else{
	s[1] = max(a, a + s[0]);
	s[0] = s[1];
      }
      ans = max(ans, s[0]);
    }
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#include <cstdlib>
#include <cmath>
#include <algorithm>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
using Graph= vector<vector<ll>>;
struct edge{ll to ; ll cost ;} ;
using graph =vector<vector<edge>> ;
#define rep(i,n) for (ll i=0; i < (n); ++i)
#define rep2(i,n,m) for(ll i=n;i<=m;i++)
#define rep3(i,n,m) for(ll i=n;i>=m;i--)
#define pb push_back
#define eb emplace_back
#define ppb pop_back
#define mpa make_pair
#define fi first
#define se second 
#define set20 cout<<fixed<<setprecision(20) ;
const ll INF=1e18 ;
inline void chmax(ll& a,ll b){a=max(a,b);}
inline void chmin(ll& a,ll b){a=min(a,b);}
double pi=acos(-1) ;
ll gcd(ll a, ll b) { return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

ll dp[105][4] ;
ll ep[105][4] ;
int main(){
  string s ; cin>>s ;
  ll k ; cin>>k ;
  ll x= s.size() ;
  rep(i,105){
      rep(j,4){
          dp[i][j]=0 ;
          ep[i][j]=0 ;
      }
  }
  ep[0][0]= 1 ; 
  rep2(i,1,x){
     ll now = s[i-1]-'0' ; 
      rep(j,4){
          dp[i][j] += dp[i-1][j] ;
          if(j>0) dp[i][j]+= dp[i-1][j-1]*9 ;
          dp[i][j] += ep[i-1][j]*min(1ll,now) ;
          if(j>0) dp[i][j]+=ep[i-1][j-1]*max(0ll,now-1) ;
          if(now!=0&&j>0) ep[i][j]=ep[i-1][j-1] ;
          if(now==0) ep[i][j]=ep[i-1][j] ;
      }
  }
  ll ans = dp[x][k] + ep[x][k] ;
  cout<<ans<<endl ;
   return 0 ; 
}



Measured memory_bytes: 3588
#include <stdio.h>
#include <math.h>
int main(void){
	int n;
	int p = 0;
	int i,j;
	int primes[1000000];
	for(i = 2;i < 1000000;i++){
		primes[i] = 0;
		for(j = 3;j <= sqrt(i);j += 2){
			if(i % j == 0){
				primes[i] = 1;
				break;
			}
		}
	}
	
	while(scanf("%d",&n) != EOF){
		p = 0;
		if(n >= 2)p++;
		for(i = 3;i <= n;i += 2){
			if(primes[i] == 0)p++;
		}
		printf("%d\n",p);
	}
	return 0;
}

Measured memory_bytes: 4500
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair <int, int> P;

void printVec(std::vector<int> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}

int main() {
  int x, y, z;
  cin >> x >> y >> z;
  int tmp;

  tmp = x;
  x = y;
  y = tmp;

  tmp = x;
  x = z;
  z = tmp;

  cout << x << " " << y << " " << z << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
	#include <ext/pb_ds/assoc_container.hpp>
	#include <ext/pb_ds/tree_policy.hpp>
	#define PI 				acos(-1)
	#define mp				make_pair
	#define pb				push_back
	#define all(a)			(a).begin(), (a).end()
	#define sz(a)			a.size()
	#define srt(a)			sort(all(a))
	#define mem(a, h)		memset(a, (h), sizeof(a))
	#define f 				first
	#define s 				second
	#define MOD1			998244353
	#define fore(i, b, e)	for(int i = b; i < e; i++)
	#define forg(i, b, e, m)	for(int i = b; i < e; i+=m)
	int in(){int r=0,c;for(c=getchar();c<=32;c=getchar());if(c=='-') return -in();for(;c>32;r=(r<<1)+(r<<3)+c-'0',c=getchar());return r;}

	using namespace std;
	using namespace __gnu_pbds;

	typedef long long 		ll;
	typedef unsigned long long 		ull;
	typedef pair<int, int>  ii;
	typedef vector<int>     vi;
	typedef vector<ii>      vii;
	typedef vector<ll>      vll;
	typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ordered_set;
	const int tam = 100010;
	const int MOD = 1e9+7;
	const double EPS = 1e-9;
	vector<int> g[100010], gp[100010];
	int posis[100010];
	bool dfs(int node)
	{
		bool res = true;
		fore(i, 0, g[node].size())
		{
			if(posis[g[node][i]] == -MOD)
			{
				posis[g[node][i]] = posis[node] + gp[node][i];
				res = res && dfs(g[node][i]);
			}
			else
				res = res && (posis[g[node][i]] == posis[node] + gp[node][i]);
		}
		return res;
	}
	int main()
	{
		ios::sync_with_stdio(0); cin.tie(0);
		//freopen("qwe.txt", "r", stdin);
		
		//freopen("asd.txt", "w", stdout);
		int n, m;
		cin>>n>>m;
		fore(i, 0, n) posis[i] = -MOD;
		int a, b, c;
		fore(i, 0, m)
		{
			cin>>a>>b>>c;
			a--, b--;
			g[a].pb(b);
			g[b].pb(a);
			gp[a].pb(c);
			gp[b].pb(-c);
		}
		bool res = true;
		fore(i, 0, n)
		{
			if(posis[i] == -MOD)
			{
				posis[i] = 0;
				res = res && dfs(i);
			}
		}
		cout<<(res?"Yes\n":"No\n");
		return 0;
	}

	// read the question correctly (is y a vowel? what are the exact constraints?)
	// look out for SPECIAL CASES (n=1?) and overflow (ll vs int?) ARRAY OUT OF BOUNDSS2

Measured memory_bytes: 16384
#include <bits/stdc++.h>
#define f first
#define s second
#define mp make_pair
#define pb push_back
#define lp(i,a,n) for(int i=a;i<=n;++i)
#define lpd(i,a,n) for(int i=a;i>=n;--i)
#define mem(a,b) memset(a,b,sizeof a)
#define all(v) v.begin(),v.end()
#define println(a) cout <<(a) <<endl
#define sz(x) ((int)(x).size())
#define readi(x) scanf("%d",&x)
#define read2i(x,y) scanf("%d%d",&x,&y)
#define read3i(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define mod 1000000007
#define eps 1e-8
#define infi 1000000000
#define infll 1000000000000000000ll
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vll;
typedef set<int> si;
typedef map<int,int> mii;

const int N = 100002;
int n;

int main(){
    int a,b;
    cin >>a >>b;
    if(a+b == 15) cout <<'+';
    else if(a*b == 15) cout <<'*';
    else cout <<'x';
}

/*
freopen("input.txt","r",stdin);
freopen("output.txt","w",stdout);
*/


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define endl '\n'
#define INF (1 << 21)
const int MOD = 1000000007;
using namespace std;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  int k[10005];
  int cnt;

  cin >> n;
  while(n != 0){
    cnt = 0;
    for(int i = 0;i < n;i++){
      cin >> k[i];
      if(k[i] > 0) cnt ++;
    }
    
    sort(k, k + n);
    if(k[n - 1] < 2){
      cout << "NA" << endl;
    }else{
      cout << cnt + 1 << endl;
    }
    cin >> n;
  }
  return 0;
}




Measured memory_bytes: 3176
import java.io.*;
import java.util.*;

public class Main {
	FastScanner in;
	PrintWriter out;

	void solve() {
		final int mod = (int) 1e9 + 7;
		int n = in.nextInt();
		int[] a = new int[n];
		for (int i = 0; i < n; i++) {
			a[i] = in.nextInt();
		}
		long res = 1;
		int cnt = 0;
		for (int i = 0; i < n; i++) {
			int pos = a[i];
			cnt++;
			int can = (pos + 1) / 2;
			while (cnt > can) {
				res = res * cnt % mod;
				cnt--;
			}
		}
		while (cnt > 1) {
			res = res * cnt % mod;
			cnt--;
		}
		out.println(res);
	}

	void run() {
		try {
			in = new FastScanner(new File("object.in"));
			out = new PrintWriter(new File("object.out"));

			solve();

			out.close();
		} catch (FileNotFoundException e) {
			e.printStackTrace();
		}
	}

	void runIO() {

		in = new FastScanner(System.in);
		out = new PrintWriter(System.out);

		solve();

		out.close();
	}

	class FastScanner {
		BufferedReader br;
		StringTokenizer st;

		public FastScanner(File f) {
			try {
				br = new BufferedReader(new FileReader(f));
			} catch (FileNotFoundException e) {
				e.printStackTrace();
			}
		}

		public FastScanner(InputStream f) {
			br = new BufferedReader(new InputStreamReader(f));
		}

		String next() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return null;
				st = new StringTokenizer(s);
			}
			return st.nextToken();
		}

		boolean hasMoreTokens() {
			while (st == null || !st.hasMoreTokens()) {
				String s = null;
				try {
					s = br.readLine();
				} catch (IOException e) {
					e.printStackTrace();
				}
				if (s == null)
					return false;
				st = new StringTokenizer(s);
			}
			return true;
		}

		int nextInt() {
			return Integer.parseInt(next());
		}

		long nextLong() {
			return Long.parseLong(next());
		}

		double nextDouble() {
			return Double.parseDouble(next());
		}
	}

	public static void main(String[] args) {
		new Main().runIO();
	}
}

Measured memory_bytes: 35860
use std::io;
use std::cmp;

macro_rules! read {
    () => {
        {
            let mut line = String::new();
            io::stdin().read_line(&mut line).unwrap();
            line
        }
    };
}

fn split(s: &String) -> std::str::SplitWhitespace {
    s.trim().split_whitespace()
}

fn main() {
    let mut line = read!();
    let mut line = split(&mut line);
    let a: i64 = line.next().unwrap().parse().unwrap();
    let b: i64 = line.next().unwrap().parse().unwrap();
    let f = |x : i64| if x%2 == 0 { (((x + 1)/2)&1)^x } else { ((x + 1)/2)&1 };
    println!("{}", f(a - 1)^f(b));
}


Measured memory_bytes: 4352
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

bool isACGT(char c) { return c == 'A' || c == 'C' || c == 'G' || c == 'T'; }

int main() {
  string S;
  cin >> S;
  int ans = 0;
  int tot = 0;
  rep(i, 0, S.size()) {
    if (isACGT(S[i]))
      tot++;
    else
      tot = 0;
    ans = max(ans, tot);
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 3608
from scipy import ndimage
import numpy as np
import sys
input = sys.stdin.readline
 
H, W = map(int, input().split())
 
A_array = np.array(
    [[0 if s == "#" else 1 for s in input().strip("\n")] for i in range(H)])
# print(A_array)
 
# print(A_array)
b = ndimage.morphology.distance_transform_cdt(
    A_array, metric="taxicab")
print(np.max(b))

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

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

#define REP(i, n) for (ll i = 0; i < n; i++)

using namespace std;

int main()
{
  int n, v;
  cin >> n;
  vector<int> o(10e5, 0), e(10e5, 0);

  REP(i, n)
  {
    cin >> v;
    if (i % 2 == 0)
    {
      e[v]++;
    }
    else
    {
      o[v]++;
    }
  }

  int o1 = 0, o2 = 0, e1 = 0, e2 = 0;
  REP(i, 10e5)
  {
    if (o[o1] < o[i])
    {
      o1 = i;
    }
    if (e[e1] < e[i])
    {
      e1 = i;
    }
  }

  if (o1 == e1)
  {
    REP(i, 10e5)
    {
      if (o[o2] < o[i] && i != o1)
      {
        o2 = i;
      }
      if (e[e2] < e[i] && i != e1)
      {
        e2 = i;
      }
    }
    cout << min(n - o[o1] - e[e2], n - o[o2] - e[e1]) << endl;
  }
  else
  {
    cout << n - o[o1] - e[e1] << endl;
  }
  return 0;
}

Measured memory_bytes: 8064
#include <iostream>
#include <string>
#include <map>
#include <queue>
#include <algorithm>


//aoj 0121  广度优先搜索
//将一组数字看作一个状态，遍历所有的状态空间，放在res中
using namespace std;
int d[4] = {1, -1, 4, -4};

map<string, int> res;


//用于存储所有状态空间

void slove() {

    queue<string> que;
    que.push("01234567");

    while (!que.empty()) {
        string s = que.front();
        que.pop();

        //pos用于记录其中0的位置
        int pos;
        for (int i = 0; i < 8; i++) {
            if (s[i] == '0')
                pos = i;
        }
        for(int i=0;i<4;i++){
            if(pos+d[i]>=0&&pos+d[i]<8&&!(pos==3&&i==0)&&!(pos==4&&i==1)){
                string u=s;
                swap(u[pos],u[pos+d[i]]);

                if(res[u]==0){
                    que.push(u);
                    res[u]=res[s]+1;
                }

            }
        }

    }

}

int main() {
    int in;
    res["01234567"] = 1;

    slove();

    while (true) {
        string s;
        for (int i = 0; i < 8; i++) {
            if (!(cin >> in)) return 0;

            s += in + '0';
        }

        cout << res[s] - 1 << endl;
    }

    return 0;

}


Measured memory_bytes: 5416
#! python3
# weighted_union_find_tree.py

class WeightedUnionFindTree():
    def __init__(self, n):
        self.par = [i for i in range(n+1)]
        self.rank = [0] * (n+1)
        self.weight = [0] * (n+1)

    def find(self, x):
        if self.par[x] == x:
            return x
        else:
            y = self.find(self.par[x])
            self.weight[x] += self.weight[self.par[x]]
            self.par[x] = y
            return y

    def unite(self, x, y, w):
        rx = self.find(x)
        ry = self.find(y)
        if self.rank[rx] < self.rank[ry]:
            self.par[rx] = ry
            self.weight[rx] = w - self.weight[x] + self.weight[y]
        else:
            self.par[ry] = rx
            self.weight[ry] = -w - self.weight[y] + self.weight[x]
            if self.rank[rx] == self.rank[ry]:
                self.rank[rx] += 1

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def diff(self, x, y):
        return self.weight[x] - self.weight[y]

n, q = [int(x) for x in input().split(' ')]
wuft = WeightedUnionFindTree(n-1)
for i in range(q):
    query = [int(x) for x in input().split(' ')]
    if query[0] == 0:
        x, y, z = query[1:]
        wuft.unite(x, y, z)
    elif query[0] == 1:
        x, y = query[1:]
        if wuft.same(x, y):
            print(wuft.diff(x,y))
        else:
            print('?')


Measured memory_bytes: 12092
#include<stdio.h>
int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);
    int max = a;
    if (max < b)
        max = b;
    if (max < c)
        max = c;
    printf("%d\n", a + b + c - max);
    return 0;
}

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

using namespace std;

void solve(void)
{
	int n, cnt = 0;
	cin >> n;
	vector<int> as(n), ans(n);
	for (int i = 0; i < n; i++) cin >> as[i];
	for (int f = n; f >= 1; f--)
	{
		int res = 0;
		for (int j = f*2; j <= n; j += f)
		{
			res ^= ans[j-1];
		}
		if (res ^ as[f-1])
		{
			ans[f-1] = 1;
			cnt++;
		}
	}
	cout << cnt << '\n';
	for (int i = 0; i < n; i++)
	{
		if (ans[i])
		{
			cout << i+1 << ' ';
		}
	}
	cout << '\n';
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}



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

using namespace std;

string s1,s2;
int ans=1e9;

int main()
{
	cin>>s1>>s2;
	for(int i=0;i+s2.length()-1<s1.length();i++)
	{
		int cnt=0;
		for(int j=0;j<s2.length();j++)
			if(s1[i+j]!=s2[j])
				cnt++;
		ans=min(ans,cnt);
	}
	printf("%d",ans);
	return 0;
}


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

const int N = 100005;

vector<int> G[N];

int dp[N];

int rec(int pos) {
  if (dp[pos] != -1) return dp[pos];
  int res = 0;
  rep(i, G[pos].size()) {
    int to = G[pos][i];
    res = max(res, rec(to) + 1);
  }
  return dp[pos] = res;
}

int main() {
  int n, m;
  cin >> n >> m;
  rep(i, m) {
    int x, y;
    cin >> x >> y;
    --x; --y;
    G[x].push_back(y);
  }
  rep(i, n) dp[i] = -1;
  int ans = 0;
  rep(i, n) ans = max(ans, rec(i));
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 11240
#include<bits/stdc++.h>
#include<string>
#define int long long
#define mod 1000000007
#define all(x) x.begin(),x.end()
using namespace std;
void solve() {
    int n,k;
    cin>>n>>k;
    if(n<k)
    {
        cout<<min(n,abs(n-k));
    } else
    {
        if(n%k==0) cout<<0;
        else
        cout<<(((n/k)+1)*k)-n;
    }
}


int32_t main()
{
    ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int t=1;
    //cin>>t;
    while(t--) solve();

}


Measured memory_bytes: 3616
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cctype>
#include <ctime>
#include <climits>
#include <cfloat>
#include <cstdint>
#include <cstddef>
#include <cinttypes>
#include <memory>
#include <iostream>
#include <sstream>
#include <iomanip>
#include <vector>
#include <array>
#include <valarray>
#include <string>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <stack>
#include <bitset>
#include <queue>
#include <complex>
#include <tuple>
#include <utility>
#include <functional>
#include <algorithm>
#include <numeric>

#include <atcoder/dsu>

using namespace std;
using namespace atcoder;

const double EPS = 1e-10;
const int64_t INF = 1e9;
typedef long long ll;

typedef pair<int,int> P;
typedef pair<pair<int,int>,int> PP;

vector<PP> yx;

int main()
{
	int n;
	scanf("%d", &n);
	yx.resize(n);

	for (int i = 0; i < n; ++i) {
		int x, y;
		scanf("%d%d", &x, &y);
		yx[i] = make_pair(P(y,x),i);
	}
	sort(yx.begin(), yx.end(), greater<PP>());

	/*
	for (int i = 0; i < n; ++i) {
		printf("%d %d %d\n", yx[i].first.first, yx[i].first.second, yx[i].second);
	}
	fflush(stdout);
	*/

	dsu d(n);
	set<P> cand; // x,i
	cand.insert(P(yx[0].first.second, yx[0].second));
	
	for (int  i = 1; i < n; ++i) {
		auto ite = cand.lower_bound(P(yx[i].first.second, 0));
		if (ite == cand.end()) {
			cand.insert(P(yx[i].first.second, yx[i].second));
	//		printf("insert: %d %d\n", yx[i].first.second, i);
		} else {
			auto iteprev = ite;
			for (auto ite2 = ite; ite2 != cand.end(); ++ite2) {
				d.merge(yx[i].second, ite2->second);
				iteprev = ite2;
			}
			if (ite != iteprev) {
				cand.erase(ite, iteprev);
			}
		}
	}


	vector<int> ans(n);
	for (int i = 0; i < n; ++i) {
		ans[yx[i].second] = d.size(yx[i].second);
	}

	for (int i = 0; i < n; ++i) {
		printf("%d\n", ans[i]);
	}
	return 0;
}


Measured memory_bytes: 7108
n = int(input())
l = sorted(list(map(int, input().split())))
ans = 0
for i in range(n):
    for j in range(i + 1, n):
        for k in range(j + 1, n):
            if l[i] < l[j] < l[k] and l[k] < l[i] + l[j]:
                ans += 1
print(ans)

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

ll a[MAX];
int main(){
	int n, k;
	while(cin >> n >> k, n){
		ll ans = 0;
		a[0] = 0;
		for(int i = 1;i <= n;i++)cin >> a[i];
		for(int i = 2;i <= n;i++)a[i] += a[i-1];
		for(int i = k;i <= n;i++){
			ans = max(ans, a[i]-a[i-k]);
		}
		//for(int i = 1;i <= n;i++)cout << a[i] << " ";
		//cout << endl;
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3776
/*
ITP1_7_D
行列の積

1≤n,m,l≤100
0≤aij,bij≤10000
*/

#include <iostream>
using namespace std;

int main()
{
	int n, m, l;
	long a[100][100], b[100][100], c[100][100];
	cin >> n >> m >> l;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < m; j++) {
			cin >> a[i][j];
		}
	}
	for (int i = 0; i < m; i++) {
		for (int j = 0; j < l; j++) {
			cin >> b[i][j];
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			c[i][j] = 0;
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			for (int k = 0; k < m; k++){
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < l; j++) {
			cout << c[i][j];
			if (j < l - 1) {
				cout << " ";
			}
		}
		cout << endl;
	}
}


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

int solution() {
    int n, k;
    cin >> n >> k;
    int d, x, ans = 0;
    vector <int> a(n, -1);
    for (int i = 0; i<k; ++i) {
        cin >> d;
        for (int j = 0; j<d; ++j) {
            cin >> x;
            a[x-1] = i+1;
        }
    } for (int j = 0; j<n; ++j) {
        if (a[j] == -1) {
            ++ans;
        }
    } cout << ans;
    return 0;
}
 
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    //cin >> TN;
    for (ll i = 0; i<TN; ++i) solution();
    return 0;
}

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

typedef long long ll;

#define REP(i, N) for (int i = 0; i < (int)(N); i++)

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

int N,Q;
vector<int> par, rnk;

// 初期化
void init () {
    REP(i,N) {
        par[i] = i;
        rnk[i] = 0;
    }
}

// 木の根を求める
int find ( int x ){
    if ( par[x] == x ) return x;
    else return par[x] = find(par[x]);
}

// xとyの属する集合を併合
void unite( int x, int y){
    x = find(x);
    y = find(y);
    if ( x == y ) return;
    
    if ( rnk[x] < rnk[y] ){
        par[x] = y;
    } else {
        par[y] = x;
        if ( rnk[x] == rnk[y] ) rnk[x]++;
    }
}

// xとyが同じ集合に属するか否か
bool same( int x, int y ){
    return find(x) == find(y);
}

int main() {
    cin >> N >> Q;
    par.resize(N); rnk.resize(N);
    
    init();
    
    REP(i,Q){
        int x,y;
        cin >> x >> y; --x; --y;
        unite(x,y);
    }
    
    set<int> st;
    REP(i,N){
        int r = find(i);
        st.insert(r);
    }
    
    int num = st.size();
    
    cout << num - 1 << endl;
    
    
    
    
    return 0;
}



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

int main(){
    int N,X;
    cin >> N >> X;
    int L[N];
    int D;
    for(int i=0; i<N; i++){
        cin >> L[i];
    }
    D=0;
    for(int i=0; i<N; i++){
        D=D+L[i];
        if( D > X ){
            cout << i+1 << endl;
            return 0;
        }
    }

    cout << N+1 << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std; 
typedef long long ll;
#define fi first
#define se second 
#define pb push_back
int main(){
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	int n,d,a;
	cin>>n>>d>>a; 
	vector<pair<ll,ll> >v;
	for(int i=0;i<n;i++){
		ll x,h;
		cin>>x>>h;
		v.pb({x,(h+a-1)/a});
	}
	sort(v.begin(),v.end());
	queue<pair<ll,ll> > q;
	ll ans = 0;
	ll cur = 0;
	for(int i=0;i<n;i++){
		while(!q.empty()){
			if(q.front().fi>v[i].fi)break;
			cur-=q.front().se;
			q.pop();
		}
		
		ll trt = max(0ll,v[i].se-cur);
		cur+=trt;
		if(trt)q.push({v[i].fi+d+d+1,trt});
		ans += trt;
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 7876
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    int k;
    cin >> k;
    vector<int > vec{1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51 };
    cout << vec[k-1] << endl;
    return 0;
}

Measured memory_bytes: 256
/** @Date    : 2017-07-23 19:58:55
  * @FileName: A.cpp
  * @Platform: Windows
  * @Author  : Lweleth (SoungEarlf@gmail.com)
  * @Link    : https://github.com/
  * @Version : $Id$
  */
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <algorithm>
#include <utility>
#include <vector>
#include <map>
#include <set>
#include <string>
#include <stack>
#include <queue>
#include <math.h>
//#include <bits/stdc++.h>
#define LL long long
#define PII pair<int ,int>
#define MP(x, y) make_pair((x),(y))
#define fi first
#define se second
#define PB(x) push_back((x))
#define MMG(x) memset((x), -1,sizeof(x))
#define MMF(x) memset((x),0,sizeof(x))
#define MMI(x) memset((x), INF, sizeof(x))
using namespace std;

const int INF = 0x3f3f3f3f;
const int N = 1e5+20;
const double eps = 1e-8;

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


int main()
{
	int n, k;
	while(cin >> n >> k)
	{
		int x;
		int ma = 0;
		int g = 0;
		for(int i = 0; i < n; i++)
		{
			scanf("%d", &x);
			g = gcd(x, g);
			ma = max(ma, x);
		}
		if(ma >= k && k % g == 0)
			printf("POSSIBLE\n");
		else printf("IMPOSSIBLE\n");
	}
    return 0;
}
//是我太垃圾 没看出来是GCD

Measured memory_bytes: 256
n=int(input())
a=list(map(int, input().split()))
a_list=[0]*(n+1)
for i in a:
  a_list[i]+=1
ans1=[0]*(n+1)
ans2=[0]*(n+1)
for i,m in enumerate(a_list):
  if m>=2:
    ans1[i]=m*(m-1)//2
    ans2[i]=(m-2)*(m-1)//2
all=sum(ans1)
for i in a:
  print(all-ans1[i]+ans2[i])
    

Measured memory_bytes: 24748
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>

long long int INF = 1e18;
using namespace std;

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

int main(){
	
	int n, q;
	cin >> n;
	
	bool flag[5000] = {};
	flag[0] = true;
	
	for(int i = 0; i < n; i++){
		int num;
		cin >> num;
		for(int j = 2100; j >= num; j--){
			flag[j] = (flag[j] | flag[j - num]);
		}
	}
	
	cin >> q;
	
	for(int i = 0; i < q; i++){
		int num;
		cin >> num;
		if(flag[num]){
			cout << "yes" << endl;
		}else{
			cout << "no" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 3116
// SeeAlso: 

#include <bits/stdc++.h>

using namespace std;

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

#define MAX 100000

typedef int _loop_int;
#define REP(i,n) for(int i = 0; i < n; i++)
#define FOR(i,a,b) for(_loop_int i=(_loop_int)(a);i<(_loop_int)(b);++i)
#define FORR(i,a,b) for(_loop_int i=(_loop_int)(b)-1;i>=(_loop_int)(a);--i)

#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()

#define CHMIN(a,b) a=min((a),(b))
#define CHMAX(a,b) a=max((a),(b))

// 最大公約数
inline constexpr ll gcd(ll a,ll b){if(!a||!b)return 0;while(b){ll c=b;b=a%b;a=c;}return a;}
// 最小公倍数
inline constexpr ll lcm(ll a,ll b){if(!a||!b)return 0;return a*b/gcd(a,b);}

#define print2D(h, w, arr) REP(i, h) { REP(j, w) cout << arr[i][j] << " "; cout << endl; }
template<class T> void print(const T& x){cout << setprecision(12) << x << endl;}
template<class T, class... A> void print(const T& first, const A&... rest) { cout << first << " "; print(rest...); }

string S;
string T;

int main() {
    cin >> S >> T;

    int ans = 0;
    REP(i, 3) {
        if (S[i]==T[i]) {
            ans++;
        }
    }    
    print(ans);
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y){
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] >= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) right = mid;
		else left = mid;
	}
	/* left は条件を満たさない最大の値、right は条件を満たす最小の値になっている */
	return right;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	int n, a, b;
	cin >> n >> a >> b;
	int ans = 0;
	for (int i = 1; i <= n; i++) {
		int number = i;
		int sum = 0;
		while (number) {
			sum = sum + number % 10;
			number = number / 10;
		}
		if (a <= sum && sum <= b) {
			ans = ans + i;
		}
	}
	cout << ans;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll n, m;
  cin >> n >> m;
  vector<int> p(m), y(m);
  vector<vector<int>> yd(1e5 + 1);

  rep(i, m) cin >> p[i] >> y[i], yd[p[i]].push_back(y[i]);
  for (int i = 1; i <= n; ++i) sort(yd[i].begin(), yd[i].end());
  rep(i, m) printf("%06d", p[i]),
      printf("%06d\n", lower_bound(yd[p[i]].begin(), yd[p[i]].end(), y[i]) -
                           yd[p[i]].begin() + 1);
}


Measured memory_bytes: 7808
#include<bits/stdc++.h>
#define endl '\n'
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for(int i=a; i<b; i++)

using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;

int main(){
    int x,ans=0,temp;
    cin>>x;
    if(x>=500){
        ans=x/500;
        x%=500;
        ans*=1000;
    }
    if(x){
        temp=x/5;
        temp*=5;
        ans+=temp;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
# _*_ coding:utf-8 _*_
#  Atcoder_Beginner_Contest120-A
# 　https://atcoder.jp/contests/abc120/tasks/abc120_a

def FavoriteSound(oneTimePay,haveMoney,satisfiedCount):
	if oneTimePay*satisfiedCount <= haveMoney:
		return satisfiedCount
	else:
		possibleCount = haveMoney // oneTimePay
		return possibleCount


if __name__ == '__main__':
	A,B,C = map(int,input().strip().split(' '))
	solution = FavoriteSound(A,B,C)
	print("{}".format(solution))


Measured memory_bytes: 2940
import java.util.Scanner;

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

		long dMax = -1000000001;
		long min = sc.nextLong();
		for (int i = 1; i < n; i++) {
			long r = sc.nextLong();
			dMax = Math.max((r - min), dMax);
			min = Math.min(r, min);
		}
		
		System.out.println(dMax);
		sc.close();
	}
}



Measured memory_bytes: 99008
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const ll INF = 1000000000;
int main(){
  ll N,A,B; cin >> N >> A >> B;
  vector<ll> h(N);
  for(ll i = 0; i < N; i++){ cin >> h[i];}
  
  ll l = 0; ll r = INF;
  
  while( r-l>1 ){
    ll mid = l+(r-l)/2;
    vector<ll> H(N); ll cnt = 0;
    for(ll i = 0; i < N; i++){H[i] = h[i] - mid*B;}
    //各hからmid回基礎攻撃Bを加える
    for(ll i = 0; i < N; i++){ 
      if( H[i] <= 0){ continue;}
      cnt += (H[i] + A - B - 1) / ( A - B);}
    //H[i] / ( A - B ) の切り上げ
    if( cnt <= mid){ r = mid;} else{ l = mid;}
  }
  
  cout << r << endl; return 0;}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef pair<int,int> P;

#define INF 1<<30
#define LINF 1ll<<60ll
#define MOD 1000000007
#define pb(a) push_back(a)

#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) _repi(i,0,n)
#define _repi(i,a,b) for(int i=a, i##_len=(b); i<i##_len; ++i)
#define REP(...) _overload3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)

#define REPR(i, n) for(int i = n;i >= 0;--i)
#define REPARR(i, v) for(int i = 0;i < sz(v);++i)

#define all(vec) (vec.begin()),(vec.end())
#define sz(x) ((int)(x).size())
#define bit(n) (1ll<<(n))

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

#define YES(n) cout<<((n)?"YES":"NO")<<endl
#define Yes(n) cout<<((n)?"Yes":"No")<<endl
#define yes(n) cout<<((n)?"yes":"no")<<endl
#define poss(n) cout<<((n)?"possible":"impossible")<<endl
#define Poss(n) cout<<((n)?"Possible":"Impossible")<<endl

const int AMAX = 100000;
ll cnt[AMAX + 1];

int main(void) {
int N;
ll K;
cin >> N >> K;

for (int i = 0; i < N; ++i) {
int A, B;
cin >> A >> B;
cnt[A] += B;
}

for (int ans = 1; ans <= AMAX; ++ans){
if (K <= cnt[ans]) {
cout << ans << endl;
break;
}
K -= cnt[ans];
}

return 0;
}

Measured memory_bytes: 1024