akhauriyash/Code-Regression huggingface dataset:
// We only fail when we stop trying
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define endl '\n'
#define D(x) cerr << #x << " = " << (x) << '\n'
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
typedef long long ll;

const int N = 21;
const int Mod = 1e9 + 7;

int n;
int a[N][N];
int dp[1 << N], lg[1 << N];
int dp2[N][1 << N];

int solve(int i, int msk) {
  if(i >= n) return 1;
  int& r = dp2[i][msk];
  if(r != -1) return r;
  r = 0;
  for(int cur = msk; cur > 0; cur -= cur & -cur) {
    int j = lg[cur & -cur];
    if(a[i][j]) {
      r += solve(i + 1, msk ^ (1 << j));
      if(r >= Mod) r %= Mod;
    }
  }
  return r;
}

int main()
{
  cin >> n;
  lg[1] = 0;
  for(int i = 2 ; i < (1 << n) ; i++)
    lg[i] = 1 + lg[i >> 1];

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

  dp[0] = 1;
  for(int i = 0; i < n; i++) {
    for(int msk = (1 << n) - 1; msk >= 0; msk--) {
      dp[msk] = 0;
      if(__builtin_popcount(msk) != i + 1) continue;
      for(int cur = msk; cur > 0; cur -= cur & -cur) {
        int j = lg[cur & -cur];
        if(a[i][j]) {
          dp[msk] += dp[msk ^ (1 << j)];
          if(dp[msk] > Mod) dp[msk] -= Mod;
        }
      }
    }
  }
  // memset(dp2, -1, sizeof dp2);
  // cout << solve(0, (1 << n) - 1) << endl;
  cout << dp[(1 << n) - 1] << endl;
  return 0;
}


Measured memory_bytes: 16768
A,B,C = map(int,input().split())
K = int(input())
cnt=0
while A>=B:
    if cnt<K:
        B *=2
        cnt += 1
    if cnt>=K:
        break
if A>=B:
    print("No")
else:
    while B>=C:
        if cnt<K:
            C *= 2
            cnt += 1
        if cnt>=K:
            break
    if B>=C:
        print("No")
    else:
        print("Yes")

Measured memory_bytes: 61860
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,int> pdi;
typedef pair<double,double> pdd;
typedef pair<double,ll> pdl;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<pdd> vdd;
typedef vector<pdi> vdi;
typedef vector<pdl> vdl;
#define fi first
#define se second
const ll INFLL=LLONG_MAX;
const int INF=INT_MAX;
const ll MAXLL=0x3f3f3f3f3f3f3f3f;
const int MAX=0x3f3f3f3f;
#define eb emplace_back
#define emp emplace
#define mp(a,b) make_pair(a,b)
template<class T> using min_heap=priority_queue<T,vector<T>,greater<T> >;
template<class T>
void sort(vector<T>& v){
	sort(v.begin(),v.end());
}
template <class T, class U>
void sort(vector<T>& v,U func){
	sort(v.begin(),v.end(),func);
}
template<class T>
void rsort(vector<T>& v){
	sort(v.rbegin(),v.rend());
}
template <class T>
int lb_index(vector<T>& v,T k){
	return lower_bound(v.begin(),v.end(),k)-v.begin();
}
template <class T>
int ub_index(vector<T>& v,T k){
	return upper_bound(v.begin(),v.end(),k)-v.begin();
}
template<class T>
bool is_sorted(vector<T>& v){
	return is_sorted(v.begin(),v.end());
}
template<class T>
bool sorted(vector<T>& v){
	return is_sorted(v);
}
void precompute(){
 
	return;
}
void solve(){
	int n;
	cin>>n;
	ll ans=-n;
	for(int i=0;i<n;i++){
		ll k;
		cin>>k;
		ans+=k;
	}
	cout<<ans;
}
 
int main(){
	ios::sync_with_stdio(0);
	int numberofsubtestcases=1;
//	cin>>numberofsubtestcases;
	precompute();
	for(int looping=1;looping<=numberofsubtestcases;looping++){
//		cout<<"Case #"<<looping<<": ";
		solve();
	}
	return 0;
}

Measured memory_bytes: 3692
#include <bits/stdc++.h>
using namespace std;
const long long INF = 123456789987654321;
const int MAX = 123456;
struct edge {
	long long cost;
	int from, to;
};
int v, e, r;
edge ed[MAX];
long long dist[MAX];
void bellmanford(int s) {
	fill(dist, dist + MAX, INF);
	dist[s] = 0;
	int cnt = 0;
	while(true) {
		bool up = false;
		cnt++;
		for(int i = 0; i < e; i++) {
			edge tmp = ed[i];
			if(dist[tmp.from] != INF && dist[tmp.to] > dist[tmp.from] + tmp.cost) {
				dist[tmp.to] = dist[tmp.from] + tmp.cost;
				up = true;
			}
		}
		if(!up) {
			break;
		}
		if(cnt == v) {
			cout << "NEGATIVE CYCLE" << endl;
			exit(0);
		}
	}
}
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);  
	cin >> v >> e >> r;
	for(int i = 0; i < e; i++) {
		int s, t, d;
		cin >> s >> t >> d;
		ed[i] = edge{d, s, t};
	}
	bellmanford(r);
	for(int i = 0; i < v; i++) {
		if(dist[i] == INF) {
			cout << "INF" << endl;
		}
		else {
			cout << dist[i] << endl;
		}
	}
	return 0;	
}



Measured memory_bytes: 4196
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main() {
	string s, t;
	cin >> s >> t;
	sort(s.begin(), s.end());
	sort(t.begin(), t.end(), greater<>());
	if(s < t) cout << "Yes" << endl;
	else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(){
  int S, h, m, s, a = 0, b = 0, c= 0;

  scanf("%d", &S);

  h = S % 3600;
  m = h % 60;
  s = m;

  a = S / 3600;

  b = h / 60;

  c = s;


  printf("%d:%d:%d\n", a, b, c);

  return 0;

}


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

using namespace std;

int main() {
    int N; cin>>N;
    int T,A; cin>>T>>A;
    vector<int> Hn(N+1);

    for (int i=1;i<=N;i++) cin>>Hn[i];

    int minIdx=0;
    double minTempSub=DBL_MAX;

    for (int i=1;i<=N;i++) {
        double t = T - Hn[i] * 0.006;
        if (minTempSub > abs(A - t)) {
            minTempSub = abs(A - t);
            minIdx = i;
        }
    }

    cout << minIdx << endl;

    return 0;
}

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

#define int long long int

signed main(){

ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int t=1;
//cin>>t;
while(t--){
int s,w;
cin>>s>>w;
if(w>=s)
    cout<<"unsafe"<<endl;
else cout<<"safe"<<endl;


}


}



Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i,n) for(i=0;i<n;i++)
using namespace std;

int main(){
    long long N, A, B, i, temp = 0;
    long long red = 0, blue = 0, nokori = 0;
    cin >> N >> A >> B;
    temp = N/(A+B);
    blue += temp * A;
    nokori = N - temp * (A + B);
    if(nokori <= A)
    {    
        blue += nokori;
    }
    else
    {
        blue += A;
    }
    
    cout << blue << endl;
}

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

int main(void){
  int N,M,i,j,target;
  int a[51],b[51],c[51],d[51];
  int dist[51][51];
  scanf("%d %d",&N,&M);
  for(i=0;i<N;i++){
    scanf("%d %d",&a[i],&b[i]);
  }
  for(i=0;i<M;i++){
    scanf("%d %d",&c[i],&d[i]);
  }
  for(i=0;i<N;i++){
    for(j=0;j<M;j++){
      dist[i][j]=abs(a[i]-c[j])+abs(b[i]-d[j]);
    }
    target=0;
    for(j=1;j<M;j++){
      if(dist[i][j]<dist[i][target]) target=j;
    }
    printf("%d\n",target+1);
  }
  return 0;
}


Measured memory_bytes: 128
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = String.valueOf(n);
        boolean bl = false;
        if ("7".equals(s.substring(0,1))||"7".equals(s.substring(1,2))||"7".equals(s.substring(2,3))) {
            bl = true;
        }
        System.out.println(bl?"Yes":"No");
    }
}


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

struct RMQ {
  static const int MAXN=1<<17;
  int n;
  int dat[2*MAXN-1];
  RMQ(int n_){init(n_);}
  void init(int n_){
    n=1;
    while(n<n_) n*=2;
    for(int i=0;i<2*n-1;i++) dat[i]=INT_MAX;
  }
  void update(int k,int a){
    k+=n-1;
    dat[k]=a;
    while(k>0){
      k=(k-1)/2;
      dat[k]=min(dat[k*2+1],dat[k*2+2]);
    }
  }
  int query(int a,int b,int k,int l,int r){
    if(r<=a||b<=l) return INT_MAX;
    if(a<=l&&r<=b) return dat[k];
    else{
      int vl=query(a,b,k*2+1,l,(l+r)/2);
      int vr=query(a,b,k*2+2,(l+r)/2,r);
      return min(vl,vr);
    }
  }
  int query(int a,int b){
    return query(a,b,0,0,n);
  }
};
int main(){
  int n,q;
  cin>>n>>q;
  RMQ rmq(n);
  for(int i=0;i<q;i++){
    int c,x,y;
    cin>>c>>x>>y;
    if(c) cout<<rmq.query(x,y+1)<<endl;
    else rmq.update(x,y);
  }
  return 0;
}

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

using namespace std;

vector <int> g[100001];

int color[100001], clr = 1;

bool used[100001];

int block[100001];

int sizes[100001];

void dfs(int v)
{
    used[v] = true;
    color[v] = clr;
    sizes[clr]++;
    for(auto u : g[v])
    {
        if(!used[u])
        {
            dfs(u);
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cout.tie(nullptr);
    cin.tie(nullptr);
    int n, m, k;
    cin >> n >> m >> k;
    for(int i = 0; i < m; i++)
    {
        int a, b;
        cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    fill(sizes, sizes + n + 1, 0);
    for(int i = 1; i <= n; i++)
    {
        if(!used[i])
        {
            dfs(i);
            clr++;
        }
    }
    fill(block, block + n + 1, 0);
    for(int i = 0; i < k; i++)
    {
        int c, d;
        cin >> c >> d;
        if(color[c] == color[d])
        {
            block[c]++;
            block[d]++;
        }
    }
    for(int i = 1; i <= n; i++)
    {
        cout << sizes[color[i]] - (int)g[i].size() - 1 - block[i] << " ";
    }
    return 0;
}


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

int main()
{
    int f, m, r;

    while (1) {
        cin >> f >> m >> r;
        if (f == -1 && m == -1 && r == -1) break;

        if (f == -1 || m == -1) cout << "F";
        else if (f + m >= 80) cout << "A";
        else if (f + m >= 65) cout << "B";
        else if (f + m >= 50) cout << "C";
        else if (f + m >= 30) {
            if (r >= 50) cout << "C";
            else cout << "D";
        } else cout << "F";
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3024
#include <stdio.h>


int main(void){
  int n,q;
  int a,v;
  int i,j;
  int p[1000001];
  int max=-1,mn=-1;
  scanf("%d %d",&n,&q);
  for(i=0;i<=1000000;i++) p[i]=0;
  for(i=0;i<q;i++){
    scanf("%d %d",&a,&v);
    p[a]+=v;
    if(v>0){
      if(max<p[a]){
	max=p[a]; mn=a;
      }else if(max==p[a]){
	if(mn>a) mn=a;
      }
    }else{
      if(mn==a){
	max=-1; mn=-1;
	for(j=1;j<=n;j++){
	  if(max<p[j]){
	    max=p[j]; mn=j;
	  }else if(max==p[j]){
	    if(mn>j) mn=j;
	  }
	}
      }
    }
    printf("%d %d\n",mn,max);
  }
  return 0;
}

Measured memory_bytes: 4504
#include <bits/stdc++.h>
 
#define int long long
#define MOD 1000000007
 
using namespace std;
 
template <class T> ostream &operator<<(ostream &os, vector<T> V) {
    os << "[ ";
    for (auto v : V)
        os << v << " ";
    os << "]";
    return os;
}
template <class T> ostream &operator<<(ostream &os, set<T> S) {
    os << "{ ";
    for (auto s : S)
        os << s << " ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, map<L, R> M) {
    os << "{ ";
    for (auto m : M)
        os << "(" << m.first << ":" << m.second << ") ";
    return os << "}";
}
template <class L, class R> ostream &operator<<(ostream &os, pair<L, R> P) {
    return os << "(" << P.first << "," << P.second << ")";
}
 

 
void solve() {
    int X, Y;
    cin >> X >> Y;
    if(Y >= 2 * X && Y <= 4 * X && Y % 2 == 0) {
        cout << "Yes" << endl;
    }
    else cout << "No" << endl;
}
 
int32_t main() {
    int t;
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
    // cin >> t;
    // while(t--) {
    //     solve();
    // }
    return 0;
}

Measured memory_bytes: 3600
import math
a, b, x = [int(w) for w in input().split()]

if x > a * a * b / 2:
    rad = math.atan(2*(a ** 2 * b - x) / a ** 3)
else:
    rad = math.atan((a * b ** 2) / (2 * x))

print(math.degrees(rad))


Measured memory_bytes: 9256
#include<stdio.h>
int main(void)
{
	int d,l,i;
	scanf("%d %d",&d,&l);
	while(d!=0){
		if(d>=l)	d=d-l;
		else	d=d-1;
		i++;
	}
	printf("%d\n",i);
	return 0;
}

Measured memory_bytes: 2756
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
  int N,g=0;
  cin>>N;
  vector<int> A(N),B(N),C(N);
  for(int &i:A)
    cin>>i;
  for(int &i:B)
    cin>>i;
  for(int i=0;i<N;i++)
    C[i]=B[i]-A[i];
  sort(C.begin(),C.end());
  if(C[N-1]<=0){
    cout<<0<<endl;
    return 0;
  }
  int i=N-1;
  for(;i>=0;i--){
    if(C[i]<=0)
      break;
    g+=C[i];
  }
  for(int j=0;j<=i;j++){
    g+=C[j];
    if(g<=0){
      cout<<N-(i-j)<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
}

Measured memory_bytes: 5612
#include<iostream>
#include<algorithm>
#pragma warning(disable:4996)
using namespace std;
long long seg[1 << 19], seg2[1 << 19], n, v, a, b, c, d, INF = (1LL << 31) - 1, size_ = 1;

void push(int u) {
	if (seg[u] == INF)return;
	seg[u * 2] = seg[u]; seg[u * 2 + 1] = seg[u];
	seg2[u * 2] = seg2[u]; seg2[u * 2 + 1] = seg2[u];
	seg[u] = INF;
}
void update(int p, int q, int r, int s, int t, int u) {
	if (s <= p || q <= r)return;
	if (p <= r && s <= q) { seg[u] = t; seg2[u] = t; return; }
	push(u);
	update(p, q, r, (r + s) / 2, t, u * 2);
	update(p, q, (r + s) / 2, s, t, u * 2 + 1);
	seg2[u] = min(seg2[u * 2], seg2[u * 2 + 1]);
}
long long query(long long p, long long q, long long r, long long s, long long u) {
	if (s <= p || q <= r)return INF;
	if (p <= r && s <= q)return seg2[u];
	push(u);
	return min(query(p, q, r, (r + s) / 2, u * 2), query(p, q, (r + s) / 2, s, u * 2 + 1));
}
int main() {
	cin >> n >> v; while (size_ < n)size_ *= 2;
	for (int i = 1; i <= size_ * 2; i++) { seg[i] = INF; seg2[i] = INF; }
	for (int i = 1; i <= v; i++) {
		scanf("%d", &a);
		if (a == 0) { scanf("%lld%lld%lld", &b, &c, &d); c++; update(b, c, 0, size_, d, 1); }
		if (a == 1) { scanf("%lld%lld", &b, &c); c++; printf("%lld\n", query(b, c, 0, size_, 1)); }
	}
	return 0;
}

Measured memory_bytes: 7292
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()


const ll mod=1000000007;

int main(){
    ll n,k;
    cin>>n>>k;
    vector<ll> m(n+5);
    ll s=0,e=0,a=0, b=n;
    rep(i,n+2){
        s+=a; a++;
        e+=b; b--;
        m[i+1]=e-s+1;
    }
    ll ans=0;
    for(int i=k; i<n+2; ++i){
        ans+=m[i];
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 4832
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  string str1,str2,str3;
  cin >> str1 >> str2 >> str3;
  int l1=0,l2=0,l3=0;
  int k=0;
  int p=0;
  int ans=0;
  while(p==0)
  {
    if(l1==str1.length() && k==0)
    {
      p=1;
      ans=1;
      break;
    }
    else if(l2==str2.length() && k==1)
    {
      p=1;
      ans=2;
      break;
    }
    else if(l3==str3.length() && k==2)
    {
      p=1;
      ans=3;
      break;
    }

    if(k==0)
    {
      if(str1[l1]=='a')
      {
        l1++;
      }
      else if(str1[l1]=='b')
      {
        l1++;
        k=1;
      }
      else if(str1[l1]=='c')
      {
        l1++;
        k=2;
      }
    }
    else if(k==1)
    {
      if(str2[l2]=='a')
      {
        l2++;
        k=0;
      }
      else if(str2[l2]=='b')
      {
        l2++;
      }
      else if(str2[l2]=='c')
      {
        l2++;
        k=2;
      }
    }
    else if(k==2)
    {
      if(str3[l3]=='a')
      {
        l3++;
        k=0;
      }
      else if(str3[l3]=='b')
      {
        l3++;
        k=1;
      }
      else if(str3[l3]=='c')
      {
        l3++;
      }
    }
    // cout << k << ' ' << l1 << ' ' << l2 << ' ' << l3 << endl;
  }
  if(ans==1)
  {
    cout << "A" << endl;
  }
  else if(ans==2)
  {
    cout << "B" << endl;
  }
  else if(ans==3)
  {
    cout << "C" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;

void main() {
    int[] tmp = readln.split.to!(int[]);
    int n = tmp[0], m = tmp[1];
    int[][] s = new int[][](m);
    foreach (i; 0 .. m) {
        int[] ss = readln.split.to!(int[]);
        ss = ss[1..$];
        foreach (x; ss) {
            s[i] ~= x - 1;
        }
    }
    int[] p = readln.split.to!(int[]);
    int ans;
    for (int i = 0; i < (1 << n); ++i) {
        bool ok;
        foreach (j; 0 .. m) {
            int cnt;
            foreach (x; s[j]) {
                if ((i >> x) & 1) ++cnt;
            }
            cnt %= 2;
            if (cnt != p[j]) ok = true;
        }
        if (!ok) ++ans;
    }
    ans.writeln;
}

Measured memory_bytes: 256
N, S = map(int,input().split())
A = list(map(int,input().split()))
mod = 998244353
dp = [[0 for j in range(S + 1)] for i in range(N + 1)]
dp[0][0] = 1
for i in range(N) : 
    for j in range(S + 1) : 
        dp[i + 1][j] += 2 * dp[i][j]
        dp[i + 1][j] %= mod 
        if j + A[i] <= S : 
            dp[i + 1][j + A[i]] += dp[i][j]
            dp[i + 1][j + A[i]] %= mod
print(dp[N][S])

Measured memory_bytes: 147660
w, h, n = map(int, input().split())

xmin, xmax, ymin, ymax = 0,w,0,h

for i in range(n):
    xi,yi,ai = map(int, input().split())
    if ai == 1:
        if xmin < xi:
            xmin = xi
    if ai == 2:
        if xmax > xi:
            xmax = xi
    if ai == 3:
        if ymin < yi:
            ymin = yi
    if ai == 4:
        if ymax > yi:
            ymax = yi

if xmax < xmin or ymax < ymin:
    menseki = 0
else:
    menseki = (xmax-xmin) * (ymax-ymin)
print(menseki)

Measured memory_bytes: 3064
#include<stdio.h>
int main(){
  int n,i,j,a[50001]={0};
  char p[50001]={1,1};
  for(i=2;i*i<50001;i++){
    if(p[i])continue;
    for(j=i*i;j<50001;j+=i)p[j]=1;
  }
  for(i=0;i<50001;i++){
    for(j=1;j*2<=i;j++){
      if(p[j]+p[i-j]==0)a[i]++;
    }
  }
  while(scanf("%d",&n),n)printf("%d\n",a[n]);
  return 0;
}
		     

Measured memory_bytes: 852
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<sstream>
#include<iterator>
#include<list>

using namespace std;

typedef  long long int lint;

#define rep(i, n) for (lint i = 0; i < n; i++)
#define sort(v) sort((v).begin(), (v).end())
#define reverse(v) reverse((v).begin(), (v).end())
#define upper(v,hoge) upper_bound(v.begin(),v.end(),hoge)
#define lower(v,hoge) lower_bound(v.begin(),v.end(),hoge)
#define mp make_pair
#define IP pair<int,int>
#define enld endl

int main() {
	lint A, B, C, K;
	cin >> A >> B >> C >> K;
	lint ans = 0;
	if (K <= A) {
		ans = K;
	}
	else if (A < K && K <= B) {
		ans = A;
	}
	else {
		ans = 2 * A + B - K;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3636
"use strict";
function main(arg) {
    //    console.log(arg.trim().split("\n"));
    let ary = arg.trim().split("\n");
    let N = ary.shift();
//    let S = ary.filter((x, i, self) => self.indexOf(x) == i);
    let S = Array.from(new Set(ary));

    console.log(S.length);

}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

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

int main(){
  unsigned long long N, M;
  cin >> N >> M;
  vector<unsigned long long> H(N, 0);
  for (unsigned long long i = 0; i < N; i++){
    cin >> H.at(i);
  }
  vector<unsigned long long> A(N,1);
  for (unsigned long long i = 0; i < M; i++){
    unsigned long long a, b;
    cin >> a >> b;
    if ( H.at(a-1) >= H.at(b-1) ) A.at(b-1) = 0;
    if ( H.at(a-1) <= H.at(b-1) ) A.at(a-1) = 0;
  }
  unsigned long long ans = 0;
  for (unsigned long long i = 0; i < N; i++){
    if ( A.at(i) == 1 ) ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 4840
def cnct(lint,lim):
    global list753
    global list357
    global list333
    lint1=str(lint)+"3"
    lint1int=int(lint1)
    if lint1int<=lim and not lint1int in list357:
        list357.add(lint1int)
        cnct(lint1int,lim)
    lint2=str(lint)+"5"
    lint2int=int(lint2)
    if lint2int<=lim and not lint2int in list357:
        list357.add(lint2int)
        cnct(lint2int,lim)
    lint3=str(lint)+"7"
    lint3int=int(lint3)
    if lint3int<=lim and not lint3int in list357:
        list357.add(lint3int)
        cnct(lint3int,lim) 
    lint4="3"+str(lint)
    lint4int=int(lint4)
    if lint4int<=lim and not lint4int in list357:
        list357.add(lint4int)
        cnct(lint4int,lim)
    lint5="5"+str(lint)
    lint5int=int(lint5)
    if lint5int<=lim and not lint5int in list357:
        list357.add(lint5int)
        cnct(lint5int,lim)
    lint6="7"+str(lint)
    lint6int=int(lint6)
    if lint6int<=lim and not lint6int in list357:
        list357.add(lint6int)
        cnct(lint6int,lim)
def D(lint):
    lista=list(str(lint))
    if lista.count("3") and lista.count("5") and lista.count("7"):
        return True
    else:
        return False

list753=[3,5,7]
list357=set()
k=int(input())
count=0
for b in list753:
    cnct(b,k)
list333=list(list357)
list333.sort()
for c in [x for x in list333]:
    if not D(c):
        list333.remove(c)
print(len(list333))


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

int main() {
  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};
  int num;
  cin >> num;
  cout << vec[num-1] << endl;
  return 0;
}

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

int main()
{
    int d;
    cin >> d;
    string ans = "NO";
    if (d == 3 || d == 5 || d == 7)
        ans = "YES";
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<string>
#include<string.h>
#include<math.h>
#include<stdlib.h>
#include<vector>
#include<queue>
#include<map>
#include<iomanip>
#include<set>
#include "bits/stdc++.h"
#define rep(index,num) for(int index=0;index<num;index++)
#define rep1(index,num) for(int index=1;index<=num;index++)
#define scan(argument) cin>>argument
#define prin(argument) cout<<argument<<endl
#define kaigyo cout<<endl
#define eps 1e-7
#define mp(a1,a2) make_pair(a1,a2)
typedef long long ll;
typedef long double ld;
using namespace std;
typedef pair<ll,ll> pll;
typedef pair<int,int> pint;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<pint> vpint;
typedef vector<pll> vpll;
ll INFl=1e+18+1;
int INF=1e+9+1;
int main(){
	int N,K;
	string S;
	scan(N>>K>>S);
	S[K-1]-=('A'-'a');
	prin(S);
	return 0;
}


Measured memory_bytes: 764
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define puts(i) cout<<i<<endl
#define pi 3.14159265358979323846264338
#define pb push_back
#define mp make_pair
using ll = long long;
using P = pair<int,int>;

ll divisor=998244353;
int main(){
	int n,m;

	cin>>n>>m;
	vector<int> g[n];
	
	rep(i,m){
		int a,b;
		cin>>a>>b;
		a--;b--;
		g[a].pb(b);
		g[b].pb(a);
	}
	int ans[n]={};
	bool used[n]={};
	deque<P> d;
	d.pb(mp(0,-1));
	used[0]=true;
	while(!d.empty()){
      	//rep(i,d.size())cout<<d[i].first<<d[i].second<<endl;
      	//cout<<endl;
		P a = d.front();
		d.pop_front();
      	//if(used[a.first])continue;
		used[a.first]=true;
		rep(i,(int)g[a.first].size()){
			if(used[g[a.first][i]])continue;
          	used[g[a.first][i]]=true;
			ans[g[a.first][i]]=a.first;
			d.pb(mp(g[a.first][i],a.first));
		}
	}
	puts("Yes");
	rep(i,n){
		if(i==0)continue;
		puts(ans[i]+1);
	}
	
	
}


Measured memory_bytes: 10772
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
#define FAST  ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define ll long long
#define ar array 
 
 
int main() {
	FAST;
 
	//int t;
	//cin >> t;
	//while(t--) 
	{
		int n;
		cin>>n;
		map<string,int> m;
		for(int i=0;i<n;i++)
		{
			string s;
			cin>>s;
			m[s]++;
		}
		cout<<"AC"<<" x "<<m["AC"]<<'\n';
		cout<<"WA"<<" x "<<m["WA"]<<'\n';
		cout<<"TLE"<<" x "<<m["TLE"]<<'\n';
		cout<<"RE"<<" x "<<m["RE"]<<'\n';
	}
}


Measured memory_bytes: 3664
N, M, K = map(int, input().split())
mod = 10**9+7

def cmb(n, r, mod=mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

NN = 10**6 # 使うデータによって変える
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, NN + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

ans = 0
for n in range(1, N+1):
    le = n*(n-1)//2 + (N-n)*(N-n+1)//2
    le *= M**2
    ans += le

for m in range(1, M+1):
    le = m*(m-1)//2 + (M-m)*(M-m+1)//2
    le *= N**2
    ans += le

ans //= 2
ans %= mod
ans =  ans * cmb(N*M-2, K-2) % mod
print(ans)

Measured memory_bytes: 121840
#include<iostream>
#include<list>
using namespace std;

int main() {
  int N; cin >> N;
  bool A[N]; for (int i = 0; i < N; i++) cin >> A[i];
  bool P[N+1];
  list<int> E[N+1];
  for (int i = 1; i <= N; i++) {
    for (int j = i+i; j <= N; j+=i) {
      E[i].push_back(j);
    }
  }
  for (int i = N; i >= 1; i--) {
    bool put_ball = A[i-1];
    for (auto it = E[i].begin(); it != E[i].end(); it++) {
      put_ball ^= P[*it];
    }
    P[i] = put_ball;
  }
  int M = 0, B[N];
  for (int i = 1; i <= N; i++) {
    if (P[i]) B[M++] = i;
  }
  cout << M << endl;
  for (int i = 0; i < M; i++) cout << B[i] << endl;
}

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

using namespace std;

const int inf = 1000000000;

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

	int n;
	cin >> n;

	vector<int> x(n);
	vector<int> y(n);
	vector<char> u(n);

	map<int, int> mp;
	map<char, int> dir;
	dir['U'] = 0;
	dir['R'] = 1;
	dir['D'] = 2;
	dir['L'] = 3;

	int m = 400001;
	int cnt = 0;
	vector<vector<pair<int, char> > > minus(n * 2);
	vector<vector<pair<int, char> > > pos(n * 2);
	vector<vector<pair<int, int> > > X(m);
	vector<vector<pair<int, int> > > Y(m);
	int ans = inf;

	for(int i = 0; i < n; ++i) {
		cin >> x[i] >> y[i] >> u[i];
		if(!mp.count(y[i] - x[i])) {
			mp[y[i] - x[i]] = cnt++;
		}
		minus[mp[y[i] - x[i]]].emplace_back(y[i], u[i]);
		if(!mp.count(y[i] + x[i])) {
			mp[y[i] + x[i]] = cnt++;
		}
		pos[mp[y[i] + x[i]]].emplace_back(y[i], u[i]);
		if(u[i] == 'U') {
			X[x[i]].emplace_back(y[i], 1);
		}
		if(u[i] == 'D') {
			X[x[i]].emplace_back(y[i], -1);
		}
		if(u[i] == 'L') {
			Y[y[i]].emplace_back(x[i], 1);
		}
		if(u[i] == 'R') {
			Y[y[i]].emplace_back(x[i], -1);
		}
	}

	for(int j = 0; j < m; ++j) {
		sort(X[j].begin(), X[j].end());
		sort(Y[j].begin(), Y[j].end());
		for(int i = 0; i + 1 < X[j].size(); ++i) {
			if(X[j][i].second == 1 && X[j][i + 1].second == -1) {
				ans = min(ans, (X[j][i + 1].first - X[j][i].first) * 5);
			}
		}

		for(int i = 0; i + 1 < Y[j].size(); ++i) {
			if(Y[j][i].second == -1 && Y[j][i + 1].second == 1) {
				ans = min(ans, (Y[j][i + 1].first - Y[j][i].first) * 5);
			}
		}
	}

	cerr << "ans = " << ans << '\n';

	for(int i = 0; i < cnt; ++i) {
		vector<multiset<int> > s(4); 
		for(auto o : minus[i]) {
			s[dir[o.second]].emplace(o.first);	
		}	
		for(auto o : minus[i]) {
			int x = dir[o.second];
			int y = o.first;
			if(x == 2) {
				auto it = s[1].upper_bound(y);
				if(it != s[1].begin()) {
					--it;
					ans = min(ans, (y - *it) * 10);
				}
			}
			if(x == 3) {
				auto it = s[0].upper_bound(y);
				if(it != s[0].begin()) {
					--it;
					ans = min(ans, (y - *it) * 10);
				}
			}
		}
	}

	for(int i = 0; i < cnt; ++i) {
		vector<multiset<int> > s(4);
		for(auto o : pos[i]) {
			s[dir[o.second]].emplace(o.first);
		}
		for(auto o : pos[i]) {
			int x = dir[o.second];
			int y = o.first;
			if(x == 0) {
				auto it = s[1].lower_bound(y);
				if(it != s[1].end()) {
					ans = min(ans, (*it - y) * 10);
				}
			}
			if(x == 3) {
				auto it = s[2].lower_bound(y);
				if(it != s[2].end()) {
					ans = min(ans, (*it - y) * 10);
				}
			}
		}
	}

	if(ans != inf) {
		cout << ans << '\n';
	} else {
		cout << "SAFE" << '\n';
	}

	return 0;
}


Measured memory_bytes: 79288
#include <iostream>
#include <utility>
#include <map>
#include <vector>
#include <algorithm>
#include <queue>
#include <math.h>
#include <stack>
#include <set>
#include <deque>
#include <cmath>

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

int main(){
    ll n;
    cin >> n;
    ll ans = 1e16;
    for ( ll i = 1; i * i <= n; ++i ) {
        if ( n % i == 0 ) {
            ans = min(ans, n / i + i - 2);
        }
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
import Control.Monad
import Data.List

main = do
  n <- readLn
  a <- map (map read . words) <$> replicateM (n - 1) getLine
  forM_ [0..n-1] $ \i ->
    print $ solve (drop i a)

solve :: [[Int]] -> Int
solve = foldl' f 0
  where
    f :: Int -> [Int] -> Int
    f curr [c, s, f] = max s ((curr + f - 1) `div` f * f) + c
  


Measured memory_bytes: 1404
// Created by Manuver
#include <bits/stdc++.h>
using namespace std;
#define deb(x) cout << #x << " : " << x << endl;


int main() {
    long long n;
    cin >> n;
    long long ans = 1000*(n/500);
    ans += ((n%500)/5)*5;
    cout << ans << endl;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

void solve() {
    ll N, K;
    cin >> N >> K;
    vector<ll> P(N);
    rep(i, N) cin >> P[i];
    vector<double> S(N + 1, 0);
    rep(i, N) {
        S[i + 1] += S[i] + (1 + P[i]) / 2.0;
    }
    double ans = 0;
    rep(i, N - K + 1) {
        ans = max(ans, S[K + i] - S[i]);
    }
    cout << ans << '\n';
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
    return 0;
}


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

using namespace std;

typedef long long ll;

int C[10][10];

int main() {
    int n, m; cin >> n >> m;
    for(int i = 0; i < 10; ++i)
        for(int j = 0; j < 10; ++j)
            cin >> C[i][j];
    
    for(int k = 0; k < 10; ++k)
        for(int i = 0; i < 10; ++i)
            for(int j = 0; j < 10; ++j)
                C[i][j] = min(C[i][j], C[i][k] + C[k][j]);
    int u, v;
    ll mx = 0;
    for(int i = 0; i < n; ++i)
        for(int j = 0; j < m; ++j) {
            cin >> u;
            if(u > -1) mx += C[u][1];
        }
    cout << mx;
    return 0;
}

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

using namespace std;

#define ll long long
#define PI 3.14159265358979323846264338327950L

struct obs {
    int v;
    int good = 0;
    set<obs*> reachable;
};

int n,m,aa,bb;

obs a[100000];

void solve(){

    cin >> n >> m;

    for (int i = 0; i < n; i++)
    {
        cin >> aa;
        a[i].v = aa;
    }
    
    for (int i = 0; i < m; i++)
    {
        cin >> aa >> bb;
        aa--;
        bb--;
        a[aa].reachable.insert(&a[bb]);
        a[bb].reachable.insert(&a[aa]);
    }
    
    for (int i = 0; i < n; i++)
    {
        if(a[i].good != 0) continue;

        bool flag = true;
        for (auto o : a[i].reachable )
        {
            if(o->v >a[i].v){
                a[i].good = 1;
                o->reachable.erase(&a[i]);
                flag = false;
            }
            else if(o->v  == a[i].v){
                o->good = 1;
                a[i].good = 1;
                flag = false;
            }
            else{
                o->good = 1;
            }
        }
        if(flag) a[i].good = 2;
    }
    
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        if(a[i].good ==2){
            ans++;
        }
    }
    

    cout << ans << endl;
}





int main(){

    ios::sync_with_stdio(false);
    cin.tie(0);

    solve();

}

Measured memory_bytes: 18388
N, M = map(int, input().split())
A = []
B = []
for n in range(N):
    a = list(map(int, input().split()))
    A.append(a)

for m in range(M):
    b = int(input())
    B.append(b)

for a in A:
    c = [unit * b for unit, b in zip(a, B)]
    print(sum(c))


Measured memory_bytes: 6028
#include <vector>
#include <string>
#include <iostream>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>

using namespace std;

int main(int argc, char* argv[]){
    long long N;
    cin >> N;

    string S;
    cin >> S;

    vector<int> rgb_sum[3];

    rgb_sum[0].resize(N + 1, 0);
    rgb_sum[1].resize(N + 1, 0);
    rgb_sum[2].resize(N + 1, 0);

    for(int i = 1; i <= N; ++i){
        rgb_sum[0][i] = rgb_sum[0][i-1];
        rgb_sum[1][i] = rgb_sum[1][i-1];
        rgb_sum[2][i] = rgb_sum[2][i-1];

        if(S[i-1] == 'R'){
            rgb_sum[0][i] += 1;
        }
        else if(S[i-1] == 'G'){
            rgb_sum[1][i] += 1;
        }
        else{
            rgb_sum[2][i] += 1;
        }
    }

    long long sum = 0;

    for(int i = 0; i < N; ++i){
        char start = S[i];

        for(int j = i + 1; j < N; ++j){
            if(S[j] == start)continue;

            int diff = j - i;

            int second = j + 1;
            int anchor = second + diff;

            int target_index ;
            if(start == 'R'){
                if(S[j] == 'G'){
                    target_index = 2;
                }
                else{
                    target_index = 1;
                }
            }
            else if(start == 'G'){
                if(S[j] == 'R'){
                    target_index = 2;
                }
                else{
                    target_index = 0;
                }
            }
            else{
                if(S[j] == 'R'){
                    target_index = 1;
                }
                else{
                    target_index = 0;
                }
            }

            if(anchor > N + 1){
                sum += rgb_sum[target_index][N] - rgb_sum[target_index][second];
            }
            else{
                sum += (rgb_sum[target_index][anchor - 1] - rgb_sum[target_index][second]);
            }

            if(anchor <= N){
                sum += (rgb_sum[target_index][N] - rgb_sum[target_index][anchor]);
            }
        }
    }

    cout << sum;

}


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

using namespace std;

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

#define pb push_back
#define odd(x) ((x)&1)
#define even(x) (!odd(x))
#define all(v) (v).begin(),(v).end()
#define rep(i,n) for(auto i=0;i<n;++i)
#define FASTIO ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define TEST_CASE int tc;cin>>tc;while(tc--)

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

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

#ifdef LOCAL
#define cerr cout
#else
#endif

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
    cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
    const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<" | ";__f(comma+1, args...);
}
#else
#define trace(...)
#endif


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


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



int main(int argv, char* argc[])
{
    FASTIO

    #ifndef JD
        freopen("in.txt","r",stdin);
        //freopen("out.txt","w",stdout);
    #endif

    int n;
    cin>>n;
    string s[n];
    map<string,int> mp;
    rep(i,n) {cin>>s[i];++mp[s[i]];}


    vector<string> v{"AC","WA","TLE","RE"};
    for(auto i:v)
    cout<<i<<" x "<<mp[i]<<"\n";






    return 0;
}


Measured memory_bytes: 6796
NUM = 1000000000 + 7
N = int(input())
total = 0
A = list(map(int, input().split()))
S = [0] * N
S[0] = A[0]
for i in range(1, len(A)):
  S[i] = S[i-1] + A[i]; 
for i in range(N):
  total += A[i] * (S[N-1] - S[i]);
print(total%NUM)

Measured memory_bytes: 93824
fun main() {
    var n = readLine()!!.toInt()
    var d = mutableMapOf("AC" to 0, "WA" to 0, "TLE" to 0, "RE" to 0)
    for(i in 0 until n) {
        var s = readLine()!!
        d[s] = d[s]!! + 1
    }
    d.forEach{(k, v) ->
        println("$k x $v")
    }
}

Measured memory_bytes: 57844
from heapq import heapify, heappush, heappop
def main():
    N, M = map(int, input().split())
    lst = list(map(int, input().split()))
    lst = [(-l, 1) for l in lst]
    heapify(lst)
    
    for _ in range(M):
        b, c = map(int, input().split())
        heappush(lst, (-c, b))
    
    ans = 0
    cnt = 0
    while True:
        tmp = heappop(lst)
        flag = False
        for _ in range(tmp[1]):
            ans -= tmp[0]
            cnt += 1
            if cnt==N:
                flag = True
                break
        
        if flag:
            break
    
    print(ans)
main()

Measured memory_bytes: 28440
//include <bits/stdc++.h>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <iostream>
#include <sstream>
#include <cmath>
#include <stack>
#include <queue>
#include <deque>
#include <vector>
#include <utility>
#include <string>
#include <set>
#include <map>
#include <cassert>
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define pf push_front
#define pof push_front
#define pb push_back
#define pob pob_back
#define FOR(i, n) for (int i = 0; i < n; i++)
#define FOR_(i, n) for (int i = n; i >= 0; i--)
#define FOR1(i, n) for(int i = 1; i <= n; i++)
#define FOR2(i, a, b) for (int i = a; a <= b; i++)
#define FOR2_(i, b, a) for (int i = b; i >= a; i--)
#define IOS ios::sync_with_stdio(0); cin.tie(0);
#ifdef momo
#define  debug(...) do{\
fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
_do(__VA_ARGS__);\
}while(0)
template<typename t> void _do(t &&_x){cerr<<_x<<endl;}
template<typename t,typename ...T> void _do(t &&_x,T &&...tail){cerr<<_x<<", ";_do(tail...);}
#else
#define debug(...)
#endif

const int MXN = 40 + 5;
const int MXS = 40*10 + 5;
const int INF = 99999999;

int N, Ma, Mb;
int a[MXN], b[MXN], c[MXN];
int dp[MXS][MXS];
int Sa, Sb;

void DP()
{
    FOR_(j, Sa) FOR_(k, Sb) dp[j][k] = INF;
    dp[0][0] = 0;
    FOR1(i, N)
        FOR_(j, Sa)
            FOR_(k, Sb)
                if (j-a[i] >= 0 && k-b[i] >= 0) dp[j][k] = min(dp[j][k], dp[j-a[i]][k-b[i]] + c[i]);
    
}
int main(void)
{
    IOS;
    
    cin >> N >> Ma >> Mb;
    FOR1(i, N) cin >> a[i] >> b[i] >> c[i], Sa += a[i], Sb += b[i];
    
    DP();
    int ans = INF;
    FOR1(i, MXS) {
        if (i*Ma > Sa || i*Mb > Sb) break;
        ans = min(ans, dp[i*Ma][i*Mb]);
    }
    if (ans < INF) cout << ans << '\n';
    else cout << -1 << '\n';
    return 0;
}

Measured memory_bytes: 640
# -*- coding: utf-8 -*-
#値の取得
t_1 = int(input())
t_2 = int(input())
if (t_1 < t_2):
  sum_1 = t_1
else:
  sum_1 = t_2
  
b_1 = int(input())
b_2 = int(input())
if (b_1 < b_2):
  sum_2 = b_1
else:
  sum_2 = b_2
  
print(sum_1 + sum_2)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define IOS ios_base::sync_with_stdio(false); cin.tie(0);
#define pb push_back
#define PI acos(-1)
#define EPS 1e-5
#define sz(v) ((int)(v).size())
#define all(v) v.begin(),v.end()
#define forn(i, n) for(ll i=0;i<(ll)n;i++)
#define fi first
#define se second
 

int main() {
	string s;
	cin >> s;
	if(s == "AAA" || s == "BBB")
		cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}



Measured memory_bytes: 3528
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];
		for(int i=0; i<N; i++)
			a[i] = sc.nextInt();
		Arrays.sort(a);
		
		System.out.println(isPossible(a) ? "Yes" : "No");
		
		sc.close();
	}
	
	static boolean isPossible(int[] a) {
		int N = a.length;
		if(a[0]+1 < a[N-1]) {
			return false;
			
		} else if(a[0]==a[N-1]) {
			return a[0]*2 <= N || a[0] == N-1;
			
		} else {
			int uniq = 0;
			for(int i=0; i<N; i++)
				if(a[i]==a[0])
					uniq++;
			
			return uniq < a[N-1] && uniq + (a[N-1]-uniq)*2 <= N;
		}
	}
}


Measured memory_bytes: 50224
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
using node = pair<string,ll>;
const ll inf = numeric_limits<ll>::max()/3;
const ll mod = 1e9+7;

ll a[200200];
ll to_right[200200][16];
ll to_left[200200][16];

ll get_x(ll head, ll next){
  if(head <= next)
    return 0;
  ll div = (head / next) + (head % next > 0);
  return (ll)ceil(log(div) / log(4));
}


int main(void) {
  ll n;
  cin >> n;
  for(int i = 1;i <= n;++i){
    cin >> a[i];
  }

  for(int j = 1;j < 16;++j){
    to_left[0][j] = 0;
    to_left[1][j] = 0;
  }
  for(int i = 2;i <= n;++i){
    for(int j = 0;j < 16;++j){
      ll head = a[i] * (ll)pow(4,j);
      ll x = get_x(head, a[i-1]);
      if(x < 16) {
        to_left[i][j] = x + to_left[i-1][x];
      } else {
        to_left[i][j] = x + to_left[i-1][15] + (x - 15) * (i-2);
      }
    }
  }

  for(int j = 0;j < 16;++j){
    to_right[n+1][j] = 0;
    to_right[n][j] = 0;
  }
  for(int i = n-1;i >= 1;--i){
    for(int j = 0;j < 16;++j){
      ll head = a[i] * (ll)pow(4,j);
      ll x = get_x(head, a[i+1]);
      if(x < 16) {
        to_right[i][j] = x + to_right[i+1][x];
      } else {
        to_right[i][j] = x + to_right[i+1][15] + (x - 15) * (n-i-1);
      }
    }
  }

  ll res = inf;
  for(int i = 1;i <= n+1;++i){
    //printf("[%d : ", i);
    //cout << (i-1) + to_left[i-1][0]*2 + to_right[i][0]*2 << endl;
    res = min(res, (i-1) + to_left[i-1][0]*2 + to_right[i][0]*2);
  }
  cout << res << endl;
  return 0;
}


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

double a, b, h, m;
double ans;
int main()
{
    // scanf("%d", &x);
    cin >> a >> b >> h >> m;

    m = m / 60 * 2 * M_PI;
    h = h / 12 * 2 * M_PI + m / 12;
    double x = a * cos(h) - b * cos(m);
    double y = a * sin(h) - b * sin(m);
    ans = sqrt(x * x + y * y);
    printf("%15.13e\n", ans);
}

Measured memory_bytes: 4072
#include<bits/stdc++.h>
using namespace std;
int a[100001],dp[100001];
int n;
int main(){
	cin>>n;
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	memset(dp,63,sizeof(dp));
	dp[1]=0;
	for(int i=1;i<=n;i++)
		if(dp[i]<=1.5e9){
			dp[i+1]=min(dp[i]+abs(a[i+1]-a[i]),dp[i+1]);
			dp[i+2]=min(dp[i]+abs(a[i+2]-a[i]),dp[i+2]);
		}
	cout<<dp[n]<<endl;
	return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>

int Odd_Even_judgment2(int a, int b){
    int x = a*b;
    if(x%2 == 0){
        printf("Even");
    }else{
        printf("Odd");
    }    
}

int main(void){
    int a;
    int b;
    scanf("%d",&a);
    scanf("%d",&b);
    Odd_Even_judgment2(a,b);
    return 0;
}

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

int main(){
    string S;
    cin >>S;
 if(S=="RSR"||S=="RSS"||S=="SRS"||S=="SSR"){
   cout<<1;
 }
  else if(S=="RRR"){
    cout<<3;
  }
  else if(S=="SSS"){
    cout<<0;
  }
  else{
    cout<<2;
  }
}
    

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int ans;
  string str;
  cin>>str;
  ans=700;
  for(int i=0; i<3; i++){
    if(str.at(i)=='o'){
      ans=ans+100;
    }
  }
  cout<<ans;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
	int n , a , b ;
	cin>>n>>a>>b;
	int arr[n];
	for(int i = 0 ; i < n ; ++i)cin>>arr[i];
	ll res = 0;
	for(int i = 0 ; i < n-1 ; ++i){
		ll dis = abs(arr[i] - arr[i+1]);
		res += min(dis*a , ll(b));
	}
	cout<<res;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<stdlib.h>
#define N 500000
#define S 1000000000
#define SENTINEL 100000000000
void Merge(int *,int,int,int);
void MergeSort(int *,int,int);
int A[N],count;
int main(){
  int n,i,left,right;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&A[i]);
    //printf("%d",A[i]);
  }
  right = n;
  left=0;
  MergeSort(A,left,right);

  for(i=0;i<n-1;i++){
    printf("%d ",A[i]);
  }
  printf("%d\n%d\n",A[n-1],count);
  return 0;
}

void MergeSort(int *A,int left, int right){
  int mid;
  if(left+1<right){
    mid =(left + right) / 2;
    MergeSort(A, left, mid);
    MergeSort(A, mid, right);
    Merge(A,left,mid,right);
      }
}

void Merge(int *A, int left, int mid, int right){
  int n1= mid -left;
  int n2 = right - mid;
  int i,j,k;//,*L,*R;
    int L[n1+1],R[n2+1];
  //L=(int *)malloc(sizeof(int)*n1);
  //R=(int *)malloc(sizeof(int)*n2);
  for(i=0;i<n1;i++){
    L[i]=A[left+i];
  }
  for(i=0;i<n2;i++){
    R[i]=A[mid+i];
  }
  L[n1]=SENTINEL;
  R[n2]=SENTINEL;
  i=0;
  j=0;
  for(k=left;k<right;k++){
    if(L[i]<=R[j]){
      A[k]=L[i];
      i++;
    }
    else{
      A[k]=R[j];
      j++;
    }
    count++;
  }
}

Measured memory_bytes: 4500
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int A,B,C;
    cin >> A >> B >> C;
    if(A>B+C)cout<< 0;else cout << B+C-A;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define vtpl(x,y,z) vector<tuple<x,y,z>>
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[8]={1,0,-1,0,1,1,-1,-1};
const ll dx[8]={0,-1,0,1,1,-1,1,-1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
int main(){
    ll n;cin >>n;
    ll ans=0;
    rep(i,n){
        rep(j,n){
            rep(k,n){
                ll tmp=__gcd(i+1,j+1);
                tmp=__gcd(tmp,k+1);
                ans+=tmp;
            }
        }
    }
    cout <<ans <<endl;
}

Measured memory_bytes: 3632