akhauriyash/Code-Regression huggingface dataset:
import itertools

def solve(n, a):
    if n < 0:
        return False
    elif n == 0:
        return True
    elif len(a) == 0:
        return False
    elif len(a) == 1:
        return n % a[0] == 0
    elif n % a[0] == 0:
        return True
    else:
        for i in itertools.count(0):
            r = n - i * a[0]
            if r < 0:
                break
            if solve(r, a[1:]):
                return True
    return False

def main():
    n = int(input())

    if solve(n, (4, 7)):
        print('Yes')
    else:
        print('No')

main()


Measured memory_bytes: 3060
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<ll, int> P;
#define MOD (1000000007ll)
#define l_ength size

ll sq(ll x){
	return x*x;
}

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

bool isvowel(char c){
	int i;
	string v="aeiou";
	for(i = (v.size()-1); i>=0; --i){
		if(c == v[i]){
			return true;
		}
	}
	return false;
}

int main(void){
	int n,i;
	ll x[123456],a,b,ans=0ll;
	cin >> n >> a >> b;
	for(i=0; i<n; ++i){
		cin >> x[i];
	}
	for(i=1; i<n; i++){
		ans += min(a*(x[i]-x[i-1]),b);
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    vector<long long> H(N);
    for (int i = 0; i < N; i++) {
        cin >> H.at(i);
    }

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

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

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <sstream> 
#include <cstdio>
#include <cstdlib>
#include <string>
#include <set>
#include <map>
#include <list>
#include <queue>
#include <stack>
#include <cmath>
#include <ctype.h>
#include <ctime>
#include <cstdio>
#include <vector>
#include <string>
#include <bitset>
#include <cctype>
#include <cstdlib>
#include <cstring>
#include <utility>
#include <numeric>
#include <complex>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <cassert>
#include <iterator>
#include <algorithm>

using namespace std;

#define SIZE 200

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

class Stack
{
	int stck[SIZE];
	int tos;
public:
	Stack() { tos = 0; }
	void push(int d);
	int pop();
};

void Stack::push(int d)
{
	if (tos == SIZE) return;		
	stck[tos] = d;
	tos++;
}

int Stack::pop()
{
	if (tos == 0) return 0;
	tos--;
	return stck[tos];
	
}

int main()
{
	Stack st;
	int a, b;
	/*string s;
	getline(cin, s);*/

	//char *g;
	char g1[1000];

	while (scanf("%s", g1) != EOF) {
		switch (g1[0])
		{
		case '+':
			st.push(st.pop() + st.pop());
			break;
		case '-':
			a = st.pop();
			b = st.pop();
			st.push(b - a);
			break;
		case '*':
			st.push(st.pop() * st.pop());
			break;
		default:
			st.push(atoi(g1));
			break;
		}

	}
	
	/*cin >> g1;
	g = strtok(g1, " ");
	cout << g << endl;
	g = strtok(NULL, " ");
	cout << g << endl*/;

	/*vector<string> ss = split(s, ' ');
	std::stoi(ss[0]);*/

	/*for (int i = 0; i < (int)ss.size(); i += 2) {
		switch ()
		{
		case '+':
			st.push(st.pop() + st.pop());
			break;
		case '-':
			a = st.pop();
			b = st.pop();
			st.push(b - a);
			break;
		case '*':
			st.push(st.pop() * st.pop());
			break;
		default:
			st.push(s[i] - 48);
			break;
		}
	}*/
	cout << st.pop() << endl;
	return 0;
}

Measured memory_bytes: 1168
#include<bits/stdc++.h>
#define rep(i,n)for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
  int n,q;cin>>n>>q;
  
  string s;cin>>s;
  
  vector<int> l(q);
  vector<int> r(q);
  
  rep(i,q) cin>>l[i]>>r[i];
  
  vector<int> vec(n);
  int count=0;
  for (int i=0;i<n-1;i++) {
    if (s[i]=='A' && s[i+1]=='C') {
      count++;
      vec[i]=count;
    }
    else {
      vec[i]=count;
    }
  }
  
  vec[n-1]=count;
  rep(i,q) {
    cout<<vec[r[i]-2]-vec[l[i]-2]<<endl;
  }
  
  
  
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
#define rep(i, start, end) for (long long i = start; i < end; ++i)
#define repreverse(i, start, end) for (long long i = start; i >= end; --i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define len(x) ((long long)(x).size())
#define lcm(a, b) ((a) / __gcd((a), (b)) * (b))
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vllvll = vector<vll>;
using vc = vector<char>;
using pll = pair<ll, ll>;
template<class T> void print1d(T x,ll n=-1){if(n==-1)n=x.size();rep(i,0,n){cout<<x[i]<<' ';}cout<<'\n';}
template<class T> void print2d(T x,ll r=-1,ll c=-1){if(r==-1)r=x.size();if(c==-1)c=x[0].size();rep(i,0,r)print1d(x[i],c);}
template<class T, class U> bool haskey(T mp, U key) { return mp.find(key) != mp.end(); }
template<class T, class U> bool isin(T el, U container) { return find(all(container), el) != container.end(); }
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; }
template<class T> bool even(T n) { return ! (n & 1); }
template<class T> bool odd(T n) { return n & 1; }
template<class T> ll rup(T a, T b) { return a % b ? a / b + 1 : a / b; }
template<class T> ld deg2rad(T deg) { return M_PI * deg / 180.0; }
template<class T> ld rad2deg(T rad) { return 180.0 * rad / M_PI; }
const long double pi = M_PI;
const long long big = 1LL << 50;
const long long inf = 1LL << 60;
const long long mod = 1e9 + 7;
ll intpow(ll a, ll n, ll _mod=numeric_limits<ll>::max()) { ll p=1; while (n) { if (n&1) p=p*a%_mod; a=a*a%_mod; n>>=1; } return p; } 
ll modc(ll a, char op, ll b, ll _mod=mod)
{
        a %= _mod; b %= _mod; ll res = 1;
        switch (op) {
        case '+': res = (a + b) % _mod; break;
        case '-': res = (a - b) % _mod; break;
        case '*': res = a * b % _mod; break;
        case '/': res = modc(a, '*', modc(b, '^', _mod-2, _mod), _mod); break;
        case '^': res = intpow(a, b, _mod); break;
        case 'P': rep(i, a-b+1, a+1) res = modc(res, '*', i, _mod); break;
        case 'C': res = modc(modc(a, 'P', b, _mod), '/', modc(b, 'P', b, _mod)); break;
        } 
        if (res < 0) { res += _mod; } return res;
}



int main()
{
        ll N, H, W;
        cin >> N >> H >> W;
        ll ans = 0;
        rep(i, 0, N) {
                ll a, b;
                cin >> a >> b;
                if (a >= H and b >= W) ++ans;
        }

        cout << ans << endl;
}


Measured memory_bytes: 3544
#include <iostream>

using namespace std;

const int MOD = 1000000007;

// mのn乗を求める
long power(int m, int n){
    long ret = 1;
    long t = 0; 
    long p = m;
    while(n != 0){
        if((n >> t)&1 == 1){
            ret = ret * p % MOD;
            n ^= 1<<t;
        }
        t++;
        p = p * p % MOD;
    }
    return ret;
}

int main(){
    int m, n;

    cin >> m >> n;

    cout << power(m, n) << endl;

    return 0;
}


Measured memory_bytes: 3092
#include<bits/stdc++.h>
using namespace std;
const int maxn=1e6+9;
const double ep=1e-7;
const int mod=1e9+7;
const int INF=0x3f3f3f3f;
const double pi=acos(-1);
#define debug1 puts("?");
#define debug(x) cout<<"##"<<(x)<<endl;
#define mk make_pair
#define PII pair<int,int>
#define PIII pair<PII,int>
#define PIL pair<int,ll>
#define PLL pair<ll,ll>
#define eb emplace_back
#define fi first
#define se second
#define rep(i,a,b) for(register int i=(a);i<=(b);++i)
#define sd(x) scanf("%d",&(x))
#define slld(x) scanf("%lld",&(x))
#define sdd(x,y) scanf("%d%d",&(x),&(y))
#define sc(s) scanf("%s",(s))
#define pd(x) printf("%d\n",(x))
#define plld(x) printf("%lld\n",(x))
#define pdk(x) printf("%d ",(x))
typedef long long ll;
int pri[maxn],cnt,a[maxn],n;
bool vis[maxn],vis1[maxn];
void init()
{
	rep(i,2,maxn-2)
	{
		if(!vis[i])pri[++cnt]=i;
		for(int j=1;j<=cnt&&i*pri[j]<maxn;j++)
		{
			vis[i*pri[j]]=1;
			if(i%pri[j]==0)break;
		}
	}
}
void solve()
{
	init();
	sd(n);
	int GCD=0;
	bool ju=0;
	rep(i,1,n)sd(a[i]),GCD=__gcd(GCD,a[i]);
	rep(i,1,n)
	{
		for(int j=1;j<=cnt&&pri[j]*pri[j]<=a[i];j++)
		{
			if(a[i]%pri[j]==0)
			{
				if(vis1[pri[j]])
				{
					ju=1;break;
				}
				vis1[pri[j]]=1;
				while(a[i]%pri[j]==0)a[i]/=pri[j];
			}
		}
		if(a[i]>1)
		{
			if(vis1[a[i]])
			{
				ju=1;break;
			}
			vis1[a[i]]=1;
		}
		if(ju)break;
	}
	if(!ju)puts("pairwise coprime");
	else if(GCD==1)puts("setwise coprime");
	else puts("not coprime");
}
int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int T=1;
//	sd(T);
	while(T--)solve();
} 

Measured memory_bytes: 8820
n,t = gets.split.map!(&:to_i)
a = gets.split.map(&:to_i)

max = a.shift
min = max
gain = [0,0]

a.each do |e|
    if e >= max then
        max = e

    elsif e < min then
        m = max - min

        if gain[0] < m then
            gain[0] = m
            gain[1] = 1
        elsif gain[0] == m
            gain[1] += 1
        end

        max = e
        min = e
    end
end

m = max - min

if gain[0] < m then
    gain[0] = m
    gain[1] = 1
elsif gain[0] == m
    gain[1] += 1
end

puts gain[1]

Measured memory_bytes: 8452
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR (i, 0, n)
#define _ << " _ " <<
#define TRACE(x) cerr << #x << " = " << x << endl
#define debug(...) fprintf(stderr, __VA_ARGS__)
//#define debug
//#define TRACE(x)

using namespace std;

typedef long long llint;

const int MAXN = 100010;

int n, m, r[MAXN], cnt[MAXN];

int main(void) {
  scanf("%d %d",&n,&m);
  REP(i, n) cnt[i] = 1;
  r[0] = 1;
  REP(i, m) {
    int x, y;
    scanf("%d %d",&x,&y);
    --x;
    --y;
    r[y] |= r[x];
    --cnt[x];
    ++cnt[y];
    if (cnt[x] == 0) r[x] = 0;
  }

  int sol = 0;
  REP(i, n) {
    //TRACE(i _ r[i]);
    sol += r[i];
  }

  printf("%d\n",sol);
  
  return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define REP(i,a,b) for(int i=(a),_ed=(b);i<=_ed;++i)
#define DREP(i,a,b) for(int i=(a),_ed=(b);i>=_ed;--i)
typedef long long ll;
inline int read(){
    register int x=0,f=1;register char ch=getchar();
    while(!isdigit(ch)){if(ch=='-')f=0;ch=getchar();}
    while(isdigit(ch)){x=x*10+(ch^'0');ch=getchar();}
    return f?x:-x;
}

#define fail return puts("-1"),0;
const int N=1e5+5,inf=1e9;
const char ch[]="BW";
int n,m,d[N],num=1,head[N],w[N<<1],col[N],fa[N];
struct edge{int to,next,vis;} e[N<<2];
inline void add(int u,int v){
    e[++num]=(edge){v,head[u]},head[u]=num;
    e[++num]=(edge){u,head[v]},head[v]=num;
}

inline void dfs(int u){
    for(int i=head[u];i;i=e[i].next){
	int v=e[i].to;if(!e[i].vis||~col[v])continue;
	col[v]=1-col[u];dfs(v);
    }
}

int main(){
    //freopen("in.in","r",stdin);
//hao我瞎了
    n=read(),m=read();
    REP(i,1,n)d[i]=read();
    REP(i,1,m)add(read(),read()),w[i]=inf;
    REP(u,1,n){
	if(!head[u])fail;
	int p=head[u];
	for(int i=e[p].next;i;i=e[i].next){
	    if(d[e[i].to]<d[e[p].to])p=i;
	    else if(d[e[i].to]==d[e[p].to]&&e[i].to<e[p].to)p=i;
	}
	if(d[e[p].to]>d[u])fail;
	e[p^1].vis=1;w[p>>1]=d[u];fa[u]=e[p].to;
    }
    memset(col,-1,sizeof col);
    REP(i,1,n)if(fa[fa[i]]==i&&!~col[i])col[i]=0,dfs(i);
    REP(i,1,n)putchar(ch[col[i]]);
    puts("");
    REP(i,1,m)printf("%d\n",w[i]);
    return 0;
}


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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(long long &a, long long b) { if (a > b) a = b; }

int main(){
  ll i, j;
  ll n, k;
  cin >> n >> k;;
  vector<ll> a(n);
  ll result;
  for(i = 0; i < n; i++)
    cin >> a[i];
  sort(ALL(a));
  vector<ll> buf(n - k + 1);
  
  for(i = 0; i < n - k + 1; i++)
    buf[i] = a[i + k - 1] - a[i];
  sort(ALL(buf));
  cout << buf[0] << endl;

  return 0;
}

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

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


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

ll lcm(ll a, ll b){
    return a / gcd(a, b) * b;
}

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n){
    ll res = 1;
    while(n){
        if(n & 1){
            res = res * a % MOD;
        }
        a = a * a % MOD;
        n = n >> 1;
    }
    return res;
}

// コンビネーション
ll MAXN = 2e5+10;
vector<ll> inv(MAXN);
ll nCk(ll n, ll k) {
	ll res = 1;
	for(ll i = 1; i <= k; i++) {
		res = res*(n-i+1) % MOD;
	}
 
	for(ll i = 1; i <= k; i++) {
		res = res*inv[i] % MOD;
	}
	return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    ll x, k, d;
    cin>>x>>k>>d;
    ll ans;

    ll a = abs(x) / d;
    if(a >= k){
        if(x < 0){
            ans = x + k * d;
        }else{
            ans = x - k * d;
        }
        cout<<abs(ans)<<endl;
        return 0;
    }

    if(x > 0){
        x -= a * d;
        k -= a;
        // cout<<k<<endl;
        ans = x;
        if(k % 2){
            ans = abs(x - d);
        }
    }else{
        x += a * d;
        k -= a;
        ans = x;
        if(k % 2){
            ans = abs(x + d);
        }
    }
    cout<<abs(ans)<<endl;

    return 0;
}

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

int main() {
    string s;
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < (int)s.size() - 1; i++) {
        if (s.at(i) != s.at(i + 1)) cnt++;
    }
    cout << cnt << endl;
}   

Measured memory_bytes: 512
import java.lang.reflect.Array;
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int ret = 0, n = sc.nextInt();
        for(int i=0;i<n;i++){
            int l = sc.nextInt(), r = sc.nextInt();
            ret += (r - l + 1);
        }
        System.out.println(ret);
    }
}



Measured memory_bytes: 24164
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <algorithm>
#include <queue>
#include <iterator>
#include <functional>
#include <numeric>
#include <cmath>
#include <stack>
#include <limits>
#include <ctime>

using namespace std;

#define ll long long
#define sc(n) static_cast<ll>(n)
#define IO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

int main() {
	IO;
#ifdef _DEBUG
	ifstream cin("In.txt");
#endif	
	ll t;
	ll a, b, c;
	cin >> a >> b >> c;
	if (a == b && a != c) {
		cout << "Yes" << endl;
		return 0;
	}
	if (a == c && a != b) {
		cout << "Yes" << endl;
		return 0;
	}
	if (c == b && a != c) {
		cout << "Yes" << endl;
		return 0;
	}
	cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int H, W;
int d[21][21];
string S[21];
int vx[] = { 1,0,-1,0 };
int vy[] = { 0,1,0,-1 };
struct point {
	int X, Y;
};
void bfs(int x, int y) {
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '.') d[i][j] = mod;
		}
	}
	d[y][x] = 0;
	queue<point> que;
	que.push({ x,y });
	while (!que.empty()) {
		point now = que.front();
		que.pop();
		for (int i = 0; i < 4; i++) {
			int nx = now.X + vx[i];
			int  ny = now.Y + vy[i];
			if (nx < 0 || nx >= W || ny < 0 || ny >= H || S[ny][nx] == '#' || d[ny][nx] != mod) continue;
			d[ny][nx] = d[now.Y][now.X] + 1;
			que.push({ nx,ny });
		}
	}
}
int main()
{
	cin >> H >> W;
	for (int i = 0; i < H; i++) cin >> S[i];
	int ans = 0;
	for (int i = 0; i < H; i++) {
		for (int j = 0; j < W; j++) {
			if (S[i][j] == '.') {
				bfs(j, i);
				for (int k = 0; k < H; k++) {
					for (int l = 0; l < W; l++) {
						ans = max(ans, d[k][l]);
					}
				}
			}
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 3600
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define MAXN 100100
const ll inf = (ll)1e10;
const ll mod = (ll)1e9+7;
ll dp[22][1 << 22];
bool chk ( int pos, int mask ) {
	return mask & (1 << pos);
}
int on ( int pos, int mask ) {
	return mask | (1<<pos);
}
int n;
int mat[22][22];
ll solve ( int pos, int mask ) {
	if ( pos == n ) {
		int taken = __builtin_popcount(mask);
		if ( taken == n ) return 1;
		return 0;
	}
	if ( dp[pos][mask] != -1 ) return dp[pos][mask];
	ll ret = 0;
	for ( int i = 0; i < n; i++ ) {
		if ( mat[pos][i] == 1 ) {
			if ( !chk(i,mask) ) ret = (ret+solve(pos+1,on(i,mask)))%mod;
		}
	}
	return dp[pos][mask] = ret%mod;
}
int main()
{
	#ifdef __APPLE__
	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
	#endif
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	cin >> n;
	for ( int i = 0; i < n; i++ ) {
		for ( int j = 0; j < n; j++ ) {
			cin >> mat[i][j];
		}
	}
	memset(dp,-1,sizeof(dp));
	cout << solve(0,0) << endl;
	return 0;
}
 


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

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

int main() {
	int N, K, temp, sum=0;
	cin >> N >> K;
	rep(i, N) {
		cin >> temp;
		p.push_back(temp);
	}
	sort(p.begin(),p.end());
	rep(i, K) {
		sum += p[i];
	}
	cout << sum;
}

Measured memory_bytes: 3632
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int[] a = new int[N];
      
        int count1 = 0;
        for(int i = 0 ; i < N; i++){
          a[i] = sc.nextInt();
          if(a[i] == 1){
            count1++;
          }
        }
      
       if(count1 == 0){
         System.out.println(-1);
         return;
       }
      
       int ans = 0;
       int num = 1;
       for(int i = 0 ; i < N; i++){
         if(a[i] == num){
           num++;
         }else{
           ans++;
         }
       }
        
        
          System.out.println(ans);
        
	}
}

Measured memory_bytes: 60012
#include<iostream>
#include<cmath>
#define boost ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
const int N = 200010;
const int M = 200010;
int q[N];
int a,b;
#include <unordered_set>
#include <vector>
using namespace std;

int find(int x)
{
    if(q[x]!=x)q[x] = find(q[x]);

    return q[x];
}
int main()
{
    boost;
    int n,m;
    cin>>n>>m;
    for(int i=1;i<=n;i++)q[i] = i;

    vector<int>v1;
    vector<int>v2;
    unordered_set<int>res;
    bool tf =false;
    while(m--)
    {
        cin>>a>>b;
        if(a==1)
        {
            if(b==n)
            {
                tf =true;
            }
           res.insert(b);
        }

        if(b==n)
        {
            v2.push_back(a);
        }
    }

    if(tf){
        cout<<"POSSIBLE"<<endl;
    }
    else
    {

        for(auto &x :v2)
        {
            if(res.count(x)){
                tf = true;
                break;
            }
        }

        if(tf)
        {
            cout<<"POSSIBLE"<<endl;
        }
        else
        {
            cout<<"IMPOSSIBLE"<<endl;
        }
    }
	return 0;
}


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

struct node{
  int key;
  int cst;
  struct node *next;
};

typedef struct node *gg;

gg G[10001];
gg mNode(int,int,gg);
void insert(int,int,int);

int main(){
  int i,j,n,cnt=0,v,c,c1,v1;
  int clr[10001],d[10001],pi[10001],mincst,ii;
  gg GGG;
  
  scanf("%d",&n);
  for(i=0;i<n;i++)G[i]=mNode(0,0,NULL);
  
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&c);
    
    for(j=0;j<c;j++){
      scanf("%d%d",&v1,&c1);
      insert(i,v1,c1);
    }
  }
  
  for(i=0;i<n;i++){
    clr[i]=0;
    pi[i]=-1;
    d[i]=10000001;
  }
  
  d[0]=0;
  
  while(1){
    mincst=10000001;
    
    for(i=0;i<n;i++){
      if(clr[i]!=2 && d[i]<mincst){
	mincst=d[i];
	ii=i;
      }
    }
    
    if(mincst==10000001)break;
    clr[ii]=2;
    
    for(GGG=G[ii];GGG!=NULL;GGG=GGG->next){
      if(clr[GGG->key]!=2 && (GGG->cst+d[ii])<d[GGG->key]){
	pi[GGG->key]=ii;
	d[GGG->key]=GGG->cst+d[ii];
	clr[GGG->key]=1;
      }
    }
  }
  
  for(i=0;i<n;i++)printf("%d %d\n",i,d[i]);
  
  return 0;
}

gg mNode(int key,int cst,gg node){
  gg n;
  n=(gg)malloc(sizeof(struct node));
  n->key=key;
  n->cst=cst;
  n->next=node;
  return n;
}

void insert(int s,int t,int u){
  gg GGG;
  GGG=mNode(t,u,G[s]->next);
  G[s]->next=GGG;
}



Measured memory_bytes: 17364
#include<bits/stdc++.h>
using namespace std;
int main(void){
  int n=0;
  cin>>n;
  int data[500][3];
  for(int i=0;i<(n-1);i++){
  	cin>>data[i][0]>>data[i][1]>>data[i][2];
  }
  for(int i=0;i<(n-1);i++){
    int time=data[i][0]+data[i][1];
  	for(int j=i+1;j<(n-1);j++){
  	    if(time<data[j][1]){
  	    	time=data[j][1];
  	    }
  		if(time%data[j][2]!=0){
  			time+=data[j][2]-(time%data[j][2]);
  		}
  		time+=data[j][0];
  	}
  	cout<<time<<endl;
  }
  cout<<0<<endl;
  return 0;
}

Measured memory_bytes: 256
n,m,v,p = map(int,input().split())
a = list(map(int,input().split()))
a.sort(reverse = True)
ans = p
border = a[p-1]
to_border = 0
for i in range(p,n):
    new_border = a[i] + m
    if new_border < border:
        print(ans)
        exit()
    possible_votes = 0
    possible_votes += (n+p-i-1)*m
    possible_votes += to_border
    possible_votes += (new_border-border)*(i-p+1)
    if possible_votes >= m*v:
        ans += 1
        to_border += border-a[i]
    else:
        print(ans)
        exit()
print(ans)
exit()


Measured memory_bytes: 85312
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define MOD 1000000007
#define INF 1000000011
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep1(i, n) for(int i = 1; i <= (int)(n); i++)
using namespace std;
typedef long long ll;
 
int main(){
 int n;
  cin>>n;
  int mod[n+1];
    int cnt[n+1];
  
  cnt[0]=0;
  rep(i, n){
    cin>>mod[i+1];
    cnt[i+1]=0;
  }
  

  for(int j=n;j>=1;j--){
  int p=j;

    if(mod[p]==0){
      cnt[p]=0;
        continue;}

    else{
      cnt[p]=1;
    for(int i=1;i*i<=p;i++){
      if(p%i==0){
       mod[i]=abs(mod[i]-1);
        int r=i;
        int q=p/r;
        if(r!=q){
        mod[q]=abs(mod[q]-1);}
 
    }
    }
    
  }
   
  }
  
  int cnts=0;
  rep(i, n){
  cnts+=cnt[i+1];}
  
  if(cnts==0){
    cout<<0<<endl;
    return 0;}
  else{
    cout<<cnts<<endl;}
    
  
  rep(i, n){
    
    if(cnt[i+1]==1&&cnts==1){
      cout<<i+1<<endl;}
    if(cnt[i+1]==1&&cnts>=2){
    cout<<i+1<<" ";
      cnts--;}
    
   
  }

  
  
  
  
 
}

Measured memory_bytes: 2432
// This amazing code is by Eric Sunli Chen.
#include<bits/stdc++.h>
using namespace std;
template<typename T> bool get_int(T &x)
{
	char t=getchar();
	bool neg=false;
	x=0;
	for(; (t>'9'||t<'0')&&t!='-'&&t!=EOF; t=getchar());
	if(t=='-')neg=true,t=getchar();if(t==EOF)return false;
	for(; t<='9'&&t>='0'; t=getchar())x=x*10+t-'0';
	if(neg)x=-x;return true;
}
template<typename T> void print_int(T x)
{
	if(x<0)putchar('-'),x=-x;
	short a[20]= {},sz=0;
	while(x>0)a[sz++]=x%10,x/=10;
	if(sz==0)putchar('0');
	for(int i=sz-1; i>=0; i--)putchar('0'+a[i]);
}
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define get1(a) get_int(a)
#define get2(a,b) (get1(a)&&get1(b))
#define get3(a,b,c) (get1(a)&&get2(b,c))
#define printendl(a) print_int(a),puts("")
typedef long long LL;
typedef unsigned long long uLL;
typedef pair<int,int> pii;
typedef vector<int> vi;
const int inf=0x3f3f3f3f;
const LL Linf=1ll<<61;
const double pi=acos(-1.0);
const int maxn=200111;
int n,pa[maxn],w[maxn],f[maxn];
int gf(int x){return x==f[x]?x:f[x]=gf(f[x]);}
vector<int> g[maxn];

struct state
{
	int id,sum,need;LL cost;
	state(){id=sum=cost=need=0;}
	state(int k1,int k2,int k3,LL k4){id=k1;sum=k2;need=k3;cost=k4;}
};
bool operator <(const state&a,const state&b)
{
	return (LL)a.sum*b.need>(LL)b.sum*a.need;
}
bool operator !=(const state&a,const state&b){return (a.id!=b.id)||(a.sum!=b.sum)||(a.cost!=b.cost)||(a.need!=b.need);}
state cur[maxn];
state merge(const state&a,const state&b)
{
	return state(a.id,a.sum+b.sum,a.need+b.need,a.cost+b.cost+(LL)a.sum*b.need);
}

int main()
{
	get1(n);
	for(int i=2;i<=n;i++)
	{
		get1(pa[i]);
		g[pa[i]].pb(i);
	}
	priority_queue<state>pq;
	for(int i=1;i<=n;i++)
	{
		f[i]=i;
		get1(w[i]);
		cur[i]=state(i,w[i],w[i]^1,0);
		pq.push(cur[i]);
	}
	while(!pq.empty())
	{
		state cv=pq.top();pq.pop();int x=cv.id;
		if(cur[x]!=cv)continue;
		f[x]=gf(pa[x]);
		cur[f[x]]=merge(cur[f[x]],cur[x]);
		if(f[x])pq.push(cur[f[x]]);
	}
	LL sum=cur[0].cost;
	printendl(sum);
	return 0;
}

Measured memory_bytes: 26224
/**
 * @brief  : c++ code for AtCoder
 * @author : rk222
 * @created: 2019.05.19 20:58:34
 */

#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
typedef pair<int, P> P1;

#define fr first
#define sc second
#define mp make_pair
#define pb push_back
#define rep(i, x) for (int i = 0; i < x; i++)
#define rep1(i, x) for (int i = 1; i <= x; i++)
#define rrep(i, x) for (int i = x - 1; i >= 0; i--)
#define rrep1(i, x) for (int i = x; i > 0; i--)
#define sor(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define lb(vec, a) lower_bound(vec.begin(), vec.end(), a)
#define ub(vec, a) upper_bound(vec.begin(), vec.end(), a)
#define uniq(vec) vec.erase(unique(vec.begin(), vec.end()), vec.end())
#define mp1(a, b, c) P1(a, P(b, c))

#define disp(x) cout << #x << ": " << x << endl
#define disp_vec(v)                                                                           \
    cout << #v << ":";                                                                        \
    rep(i, v.size()) cout << " " << v[i];                                                     \
    cout << endl

const int INF = 100000000;
const int M = 100000000;
const int dir_4[4][2] = {{1, 0}, {0, 1}, {-1, 0}, {0, -1}};
const int dir_8[8][2] = {{1, 0}, {1, 1}, {0, 1}, {-1, 1}, {-1, 0}, {-1, -1}, {0, -1}, {1, -1}};

/* ------------------------------------- */

int main() {
    string s;
    cin >> s;

    int c1, c2, c3, c4;
    c1 = s[0] - '0';
    c2 = s[1] - '0';
    c3 = s[2] - '0';
    c4 = s[3] - '0';

    int n1 = c1 * 10 + c2;
    int n2 = c3 * 10 + c4;

    bool m1 = (n1 >= 1 && n1 <= 12);
    bool y1 = true;
    bool m2 = (n2 >= 1 && n2 <= 12);
    bool y2 = true;

    if (m1 && m2) {
        cout << "AMBIGUOUS";
    } else if (m1 && !m2) {
        cout << "MMYY";
    } else if (!m1 && m2) {
        cout << "YYMM";
    } else if (!m1 && !m2) {
        cout << "NA";
    }

    cout << '\n';

    /* --------------------------------- */
    return 0;
}

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

#define STR_MAX	100001

char s[STR_MAX];
int Csum[STR_MAX];
int n;

void ruisekiwa()	// 文字列sに対して文字列"AC"が出現する累積和を求める。
{
	for( int i = 0; i < n; ++i )
		Csum[i + 1] = Csum[i] + ( s[i] == 'A' && s[i + 1] == 'C' );
}

int main()
{
	int q, r, l;
	cin >> n >> q >> s;
	
	ruisekiwa();

	for( int i = 0; i < q; ++i )
	{
		cin >> l >> r;
		cout << Csum[r-1] - Csum[l-1] << endl;		// 0オリジン
	}

	return 0;
}

Measured memory_bytes: 1280
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

#[allow(unused_imports)]
use std::{i32, i64, u32, u64, f64};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
#[allow(unused_imports)]
use std::collections::{VecDeque, HashMap, BTreeMap, HashSet, BTreeSet};
#[allow(unused_imports)]
use std::io::{stdout, Write, BufWriter};
#[allow(unused_imports)]
use std::mem::{swap};
//#[allow(unused_imports)]
//use proconio::marker::{Isize1, Usize1, Bytes, Chars};

//#[proconio::fastout]
fn main() {
    input!{
        n: u64,
    }
    println!("{}", (1..(n + 1)).fold(1, |p, k| { (p * k) % (10u64.pow(9) + 7) }));
}



Measured memory_bytes: 4352
using System;
using System.Linq;

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(l => int.Parse(l)).ToArray();
            var a = input[0];
            var b = input[1];
            var x = ((a + b) + 2 - 1) / 2;

            Console.WriteLine(x);
        }
    }
}


Measured memory_bytes: 13396
s = input()
a = s[0:2]
b = s[2:]

def to_int(i):
    if i[0] == 0:
        return int(i[1])
    else:
        return int(i)

a = to_int(a)
b = to_int(b)

if (a > 12 or a == 0) and 1 <= b <= 12:
    print("YYMM")
elif 1 <= a <= 12 and (b > 12 or b == 0):
    print("MMYY")
elif 1 <= a <= 12 and 1 <= b <= 12:
    print("AMBIGUOUS")
else:
    print("NA")



Measured memory_bytes: 3064
import java.util.*;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int a = parseInt(sc.next());
		int b = parseInt(sc.next());
		sc.close();
		out.println(a%3==0||b%3==0||(a+b)%3==0?"Possible":"Impossible");
	}
}


Measured memory_bytes: 21716
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main(){
    int n;
    scanf("%d",&n);
    int x[n][2];
    for(int i=0;i<n;i++)scanf("%d%d",&x[i][0],&x[i][1]);
    double sum = 0;
    for(int i=1;i<n;i++){
        for(int j=0;j<i;j++){
            sum += hypot(x[i][0]-x[j][0],x[i][1]-x[j][1]);
        }
    }
    printf("%.9f",2*sum / n);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define EM 1000000
using namespace std;
using LL = long long;
using P = pair<LL, LL>;
LL LINF = 1e18;
int INF = 1e9;
LL mod = 1e9+7;
using vint = vector<int>;
using vLL = vector<LL>;
using vvint = vector<vector<int>>;
using vvLL = vector<vector<LL>>;
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; }


vector<LL>  d(2510, INF);
LL N, M;
vector<vector<pair<int, int >>> G1(2510);
vector<vector<pair<int, int >>> G2(2510);
vector<int> used1(2510, 0);
vector<int> used2(2510, 0);

void dfs1(int s){
    used1[s] = 1;
    for(auto g : G1[s]){
        if(used1[g.first] == 0)    dfs1(g.first);
    }
    return;
}
void dfs2(int s){
    used2[s] = 1;
    for(auto g : G2[s]){
        if(used2[g.first] == 0)    dfs2(g.first);
    }
    return;
}
bool path(int s){
    d[s] = 0;
    bool f = false;
    for(int i = 0;i < 2*N;i++){
        bool up = false;
        for(int j = 0;j < N;j++){
            if(used1[j] == 0 || used2[j] == 0)  continue;
            for(auto g : G1[j]){
                int to = g.first;
                int cost = g.second;
                int from = j;
                if(used1[to] == 0 || used2[to] == 0)  continue;
                if(d[from] != INF && d[to] > d[from]+cost){
                    up = true;
                    d[to] = d[from]+cost;
                    if(i > N)   f = true;
                }
            }
        }
        if(!up) break;
    }
    return f;
}

int main(){
    int P;
    cin >> N >> M >> P;
    for(int i = 0;i < M;i++){
        int a, b, c;
        cin >> a >> b >> c;
        G1[a-1].push_back(make_pair(b-1, P-c));
        G2[b-1].push_back(make_pair(a-1, P-c));
    }
    dfs1(0);
    dfs2(N-1);
    bool inf = path(0);

    if(inf) cout << -1 << endl;
    else    cout << max(-d[N-1], 0LL) << endl;
}

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


int main(void){
    // Your code here!
   int n,a,b;
   int souwa=0;
   
   cin >> n >>a >>b;
   
   //ｎ回ループ
   for(int i=1;i<=n;i++){
       
       int n = i;
       int sum = 0;
       
       //各桁の和を算出
       while(n>0){
           sum += n % 10;
           n /= 10;
       }
       
       //和がa以上b以下ならsouwa++していく
       if(a<=sum && sum <= b) {
                    souwa += i;
       }
       
   }
   
    
  cout << souwa << endl;
   
   
   
   
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  vector<int> count(N, 0);
  for (int i = 0; i < N - 1; i++){
    int A;
    cin >> A;
    A--;
    count[A]++;
  }
  for (int i = 0; i < N; i++){
    cout << count[i] << endl;
  }
}

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

typedef list<int> li;

int main(void){
	int n,m;
	cin>>n;
	std::vector<int> v;
	for(int i=1;i<=2*n;i++)v.push_back(i);
	cin>>m;
	while(m--){
		int k;
		cin>>k;
		if(k==0){
			// ref
			std::vector<int> v1(n);
			std::vector<int> v2(n);
			copy(v.begin(),v.begin()+n,v1.begin());
			copy(v.begin()+n,v.end(),v2.begin());
			for(int i=0;i<2*n;i++){
				if(i%2==0)v[i]=v1[i/2];
				else v[i]=v2[i/2];
			}
		}else{
			// cut
			std::vector<int> v1(k);
			std::vector<int> v2(2*n-k);
			copy(v.begin(),v.begin()+k,v1.begin());
			copy(v.begin()+k,v.end(),v2.begin());
			for(int i=0;i<v2.size();i++){
				v[i]=v2[i];
			}
			for(int i=0;i<v1.size();i++){
				v[i+v2.size()]=v1[i];
			}
		}
	}
	for(int i=0;i<v.size();i++){
		cout<<v[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 3128
#include <stdio.h>

int main()
{
  int n,k;
  int s=0;
  scanf("%d %d",&n,&k);

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

  for(int j=0;j<n;j++){
    if(h[j]>=k)s=s+1;
  }
  printf("%d",s);

  return 0;
  
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
long long gcd(long a,long b){    if (b==0)         return a;    return gcd(b, a%b);}
long long ngcd(vector<long long> & a, int n)
{
    if(n==1)
    {
        return a[0];
    }
    else
    {
        return gcd(a[n-1], ngcd(a, n-1));
    }
}    

long long lcm(long long a, long long b)

{

        return a/gcd(a, b)*b;
}

long long nlcm(vector<long long> & a, int n)

{

      if (n == 1)

            return a[0];

      else

            return lcm(a[n-1], nlcm(a, n-1));

}

int main()
{
    std::ios::sync_with_stdio(false);	
    int n;
    cin>>n;
    vector<long long> circle_one_time(n);
    for(int i = 0 ; i < n ; i++)
    {
        cin>>circle_one_time[i];
    }
    
    
    cout<<nlcm(circle_one_time, n);
    
   
    
    return 0;
}

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

#define ll long long int
#define pb emplace_back

int main() {
    ios_base::sync_with_stdio(false);
    
    ll n, x, y;
    cin>>n>>x>>y;
    
    vector<ll> count(n, 0);
    for(ll i=1; i<=n; i++){
        for(ll j=i+1; j<=n; j++){
            count[min(j-i, abs(x-i)+abs(y-j)+1)]++;
        }
    }
    for(ll k=1; k<n; k++){
        cout<<count[k]<<"\n";
    }
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define MAX 101
#define INT_MAX 100000000
#define min(a,b) (a>b?b:a)
int N;
int M[2][MAX][MAX];

void dijkstra( int s, int q,int flag){
    char visited[MAX]; // S É®·ém[hÍ true
	int d[MAX];
	int i;
    for (i = 1; i <= N; i++ ){
        d[i] = INT_MAX;
        visited[i] = 0;
    }
    
    d[s] = 0; // ÅÉ s ª u ÆµÄIÎêé
    
    while( 1 ){
        int u; // ÅKÈm[h u ðIÔ
        int mincost = INT_MAX;
        for ( i = 1; i <= N; i++ ){
            if ( !visited[i] && d[i] < mincost ){
                mincost = d[i]; u = i;
            }
        }
        
        // u ª¶ÝµÈ©Á½Æ«AÂÜè S ª±êÈã¦È¢Æ«AI¹
        if ( mincost == INT_MAX ) break;
        
        visited[u] = 1; // u ð S ÉÇÁ
        int v;
        for (  v = 1; v <= N; v++ ){
            // v ª S ÉÜÜêéê@Ü½Í@GbW(u, v)ªÈ¢êÍ@³
            if ( visited[v] || M[flag][u][v] == INT_MAX ) continue;
            d[v] = ( d[v]> d[u] + M[flag][u][v]?d[u]+M[flag][u][v]:d[v] );
        }
    }
	printf("%d\n",d[q]);
}

int main(){
	int m,i,j,a,b,c,t,k,p,q,r;
	
	while(~scanf("%d%d",&m,&N)){
		if(N==0 && m==0)break;
		
		for(i=1;i<=N;i++){
			for(j=1;j<=N;j++){
				M[0][i][j]=INT_MAX;
				M[1][i][j]=INT_MAX;
			}
		}
		
		for(i=0;i<m;i++){
			scanf("%d%d%d%d",&a,&b,&c,&t);
			M[0][a][b]=c;
			M[0][b][a]=c;
			M[1][a][b]=t;
			M[1][b][a]=t;
		}
		scanf("%d",&k);
		for(i=0;i<k;i++){
			scanf("%d%d%d",&p,&q,&r);
			dijkstra(p,q,r);
		}
	}
	return 0;
}

Measured memory_bytes: 844
fun main(args: Array<String>) {
    val N = readInputLine().toInt()
    val dishes = mutableListOf<Pair<Long, Long>>()

    for (i in 0 until N) {
        val (A, B) = readInputLine().split(" ").map { it.toLong() }
        dishes.add(Pair(A, B))
    }
    
    dishes.sortByDescending { it.first + it.second }

    var ans = 0L
    for ((i, e) in dishes.withIndex()) {
        ans += if (i % 2 == 0) e.first else -e.second
    }
    
    println(ans)
}

fun readInputLine(): String {
    return readLine()!!
}


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

int main()
{
	int n;
	scanf("%d", &n);
	printf("%d:", n);
	for (int i = 2; i * i <= n && n != 1; i++)
	{
		while (!(n % i))
		{
			printf(" %d", i);
			n /= i;
		}
	}
	if (n != 1) printf(" %d", n);
	printf("\n");
	return 0;
}


Measured memory_bytes: 3216
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import accumulate, permutations, combinations, product
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

M, D = MAP()
ans = 0
for m in range(1, M+1):
	for d in range(1, D+1):
		if len(str(d)) == 2:
			d1 = int(str(d)[1])
			d10 = int(str(d)[0])
			if d1 >= 2 and d10 >= 2 and d1*d10 == m:
				ans += 1
print(ans)


Measured memory_bytes: 5148
N = int(input())
D = [int(d) for d in input().split()]
D.sort()
D_small = D[0:N//2]
D_big = D[N//2:N]
if D_small[-1]==D_big[0]:
  ans = 0
else:
  ans = D_big[0] - D_small[-1]
print(ans)

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

ll N, A[100005], AI;

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

	cin >> N;
	for (ll i = 0; i < N; i++) {
		cin >> AI;
		for (ll j = max(AI-1, 0LL); j <= AI+1; j++) {
			A[j]++;
		}
	}

	cout << *max_element(A, A+100005) << "\n";
}

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#define int long long
#define rep(i, n) for (int i = 0; i < (n); i++)
#define P pair<long long,long long>
#define INF 1000000000000000000
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long MOD = 1000000007;
using namespace std;
typedef long long ll;
map<int, int> mp;
//最大公約数
ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
//最小公倍数
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

int N, A, B, C;
vector<int> L;
int dfs(int cur, int a, int b, int c) {
	if (cur == N) return (min({ a,b,c }) > 0 ? abs(A - a) + abs(B - b) + abs(C - c) - 30 : INF);
	int res0, res1, res2, res3;
	res0 = dfs(cur + 1, a, b, c);
	res1 = dfs(cur + 1, a + L.at(cur), b, c) + 10;
	res2 = dfs(cur + 1, a, b + L.at(cur), c) + 10;
	res3 = dfs(cur + 1, a, b, c + L.at(cur)) + 10;
	return min({ res0,res1,res2,res3 });
}
signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cin >> N >> A >> B >> C;
	rep(i, N) {
		int n; cin >> n;
		L.push_back(n);
	}
	cout << dfs(0, 0, 0, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            int N;
            var a1 = Console.ReadLine().Split(' ');
            var a = Console.ReadLine().Split(' ');
            Int32.TryParse(a1[0], out N);
            var P = new int[N];
            int id = 0;
            foreach (var x in a)
            {
                Int32.TryParse(x, out P[id]);
                //Console.WriteLine(P[id]);
                id++;
            }
            long curPoint = 1000000000000;
            int L = P[0];
            int R = P[0];
            for (var i = 1; i < N; i++)
            {
                L = Math.Min(P[i], L);
                R = Math.Max(P[i], R);
            }
            for (var i = L; i<=R; i++)
            {
                long s = 0;
                foreach (var j in P)
                {
                    s += (j - i) * (j - i);
                }
                curPoint = Math.Min(curPoint, s);
            }
            Console.WriteLine(curPoint);
        }
    }
}


Measured memory_bytes: 11092
N, M = map(int, input().split())
A = list(map(int, input().split()))
A = sorted(A,reverse=True)

suma = sum(A)
sup = (1 / (4*M)) * suma

count = 0
flag = 0
for a in A:
    if a < sup:
        break
    else:
        count += 1

if count >= M:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include<cstdio>
#include<cstring>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#define MN 1005
#define INF 1000000007
using namespace std;
int n;
int a[3][MN];
int sum[3][MN];
int main() {
	int i,j;
	scanf("%d", &n);
	for (i = 1; i <= 2; i++) {
		for (j = 1; j <= n; j++) {
			scanf("%d", &a[i][j]);
		}
	}
	for (i = 1; i <= n; i++) {
		sum[1][i] = sum[1][i - 1] + a[1][i];
		sum[2][n - i + 1] = sum[2][n - i + 2] + a[2][n-i+1];
	}
	int ans = 0;
	for (i = 1; i <= n; i++) ans = max(ans, sum[1][i]+ sum[2][i]);
	printf("%d", ans);
	return 0;
}

Measured memory_bytes: 128
/*
dp[i][j] = length of the longest common subsequence in s[i, i+1, .... s.size()-1] and t[j, j+1, ..... t.size()-1]
*/

#include <bits/stdc++.h>

using namespace std;

int main(){
	string s, t;
	int n, m;
	vector<vector<int> > dp;
	cin>>s;
	cin>>t;
	n = s.size();
	m = t.size();
	dp.assign(n+1, vector<int>(m+1, 0));

	for(int i=n-1;i>=0;i--){
		for(int j=m-1;j>=0;j--){
			if(s[i] == t[j])
				dp[i][j] = dp[i+1][j+1]+1;
			else
				dp[i][j] = max(dp[i][j+1], dp[i+1][j]);
		}
	}
	
	//cout<<dp[0][0]<<"\n";
	
	int curr_i = 0, curr_j = 0;
	while(curr_i < n && curr_j < m){
		if(s[curr_i] == t[curr_j]){
			cout<<s[curr_i];
			curr_i++; curr_j++;
		}
		else if(dp[curr_i][curr_j] == dp[curr_i+1][curr_j])
			curr_i++;
		else
			curr_j++;
		/*else if(dp[curr_i+1][curr_j] > dp[curr_i][curr_j+1])
			curr_i++;
		else
			curr_j++;*/
	}
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 35584
#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()
struct Data {
    int count, penalty, id;
    Data(int id_) : count(0), penalty(0), id(id_) {}
};

bool comp(const Data &d1, const Data &d2) {
    if (d1.count != d2.count)
        return d1.count > d2.count;
    else if (d1.penalty != d2.penalty)
        return d1.penalty < d2.penalty;
    else
        return d1.id > d2.id;
}

int pena[101][1010];
bool solved[101][1010];
void solve() {
    int M, T, P, R;
    cin >> M >> T >> P >> R;
    if (M == 0) exit(0);
    REP(i, T + 1) REP(j, P + 1) {
        solved[i][j] = false;
        pena[i][j] = 0;
    }
    vector<Data> v;
    REP(i, T) {
        Data d(i);
        v.push_back(d);
    }
    REP(_, R) {
        int m, t, p, j;
        cin >> m >> t >> p >> j;
        p--, t--;
        if (j != 0) {
            pena[t][p]++;
        } else {
            if (!solved[t][p]) {
                solved[t][p] = true;
                v[t].count++;
                v[t].penalty += 20 * pena[t][p];
                v[t].penalty += m;
            }
        }
    }
    sort(v.begin(), v.end(), comp);
    Data d(T);
    v.push_back(d);
    REP(i, T) {
        cout << v[i].id + 1;
        if (i != T - 1) {
            if (v[i].count == v[i + 1].count && v[i].penalty == v[i + 1].penalty)
                cout << '=';
            else
                cout << ',';
        }
    }

    cout << endl;
    // REP(i, T) { cout << v[i].id + 1 << " " << v[i].count << " " << v[i].penalty << endl; }
}

signed main() {
    while (true) solve();
}


Measured memory_bytes: 3364
#include <bits/stdc++.h>
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
using namespace std;
using ll = long long;
using ld = long double;

int main(){
  ios_base::sync_with_stdio(false);cin.tie(0);
  int N;
  cin >> N;
  vector<int> h(N);
  for(int i=0;i<N;i++)  cin >> h.at(i);
  h.pb(1e9);
  h.pb(1e9);

  vector<int> dp(N+2,1e9);
  dp.at(0)=0;
  for(int i=0;i<N;i++){
    dp.at(i+1)=min(dp.at(i+1),dp.at(i)+abs(h.at(i)-h.at(i+1)));
    dp.at(i+2)=min(dp.at(i+2),dp.at(i)+abs(h.at(i)-h.at(i+2)));
  }
  cout << dp.at(N-1) << endl;

  return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = std::vector<T>;
using vvi = std::vector<vt<int>>;

int main(){
  std::string s;
  std::cin >> s;

  //condition1
  if(s[0] != 'A') {
    std::cout << "WA" << '\n';
    return 0;
  }

  //condition2
  int c_cnt = 0;
  for(int i = 2; i < s.size()-1; i++) {
    if(s[i] == 'C')
      ++c_cnt;
  }

  if(c_cnt != 1) {
    std::cout << "WA" << '\n';
    return 0;
  }

  //condition3
  for(int i = 1; i < s.size(); i++) {
    if(s[i] == 'C' && 1 < i && i < s.size()-1)
      continue;
    if(s[i] >= 'a' && s[i] <= 'z')
      continue;
    else {
      std::cout << "WA" << '\n';
      return 0;
    }
  }

  std::cout << "AC" << '\n';
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<vector>
#include<string>
#include<cstdlib>
using namespace std;


int main()
{
	int a, b, t;
	cin >> a >> b >> t;
	cout << b * (t / a) << endl;
}


Measured memory_bytes: 256