akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

long long int dp[1002][1001];

int road[1000];
int day[1000];

const long long int INF = 1000000000000000;

int main() {

    int n,m;

    cin >> n >> m;

    for(int i=0;i<n;i++){
        cin >> road[i];
    }

    for(int i=0;i<m;i++){
        cin >> day[i];
    }

    for(int i=1;i<=n;i++){
        dp[i][0] = INF;
    }

    for(int j=1;j<=m;j++){
        dp[0][j] = 0;
    }

    dp[0][0] = 0;

    for(int j=1;j<=m;j++){
        for(int i=1;i<=n;i++){
            dp[i][j] = min(dp[i][j-1],dp[i-1][j-1] + day[j-1]*road[i-1]);
        }
    }

    cout << dp[n][m] << endl;



    return 0;
}

Measured memory_bytes: 9444
#include<stdio.h>

int main(void)
{
	int d,kai[100]={0},i,j=0,k;

	while(scanf("%d",&d) != EOF)
	{
		for(i=0;i<600;i+=d)
		{
		  kai[j]+=i*i*d;
		}
	j+=1;
	}
    for(i=0;i<j;i++)
	{
		printf("%d\n",kai[i]);
	}
  return 0;
}

Measured memory_bytes: 1024
N = int(input())
A = [list(map(int, input().split())) for _ in range(2)]
ans = 0
s = 0
for i in range(N):
    tmp = 0
    for j in range(i+1):
        tmp += A[0][j]
    for j in range(i, N):
        tmp += A[1][j]
    ans = max(ans, tmp)
print(ans)


Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <cmath>
#include <limits>
#include <vector>
#include <cstdio>
#include <bits/stdc++.h>
#include <set>
#include <map>
#include <stdio.h>
#include <stack>
#include <queue>
#include <deque>
#include <numeric>
#include<bits/stdc++.h>
#include <utility>

#define ALL(obj) (obj).begin(), (obj).end()
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define RFOR(i,a,b) for(int i = (a); (b) <= i; i--)
#define REP(i,n) for(int i = 0; i < (n); i++)
#define RREP(i,n) for(int i = n; n <= i; i--)
#define ABS(a) ((a < 0) ? ((-1)*(a)) : (a))
#define elif else if
#define MOD 1000000007
#define INF (1<<29)

using namespace std;
using ll = long long;
map <int ,int> mpa,mpb;
typedef pair<ll, ll> P;
priority_queue<P, vector<P>, greater<P>> pque;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(NULL);
  ll N,T;
  cin >> N >> T;
  ll A[100010];
  for(int i=1;i<=N;i++){
    cin >> A[i];
  }
  ll ans=0;
  ll min_v=A[1];
  ll cost=0;
  for(int i=2;i<=N;i++){
    if(cost<A[i]-min_v){
      cost=A[i]-min_v;
      ans=1;
    }else if(cost==A[i]-min_v){
      ans++;
    }
    min_v=min(min_v,A[i]);
  }
  cout << ans << endl;
  return 0;
}

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

typedef long long ll;
#define INF 0x3f3f3f3f3f3f3f3f
#define MOD 1000000007
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define foreach(i, v) for (__typeof((v).begin()) i = (v).begin(); i != (v).end(); ++ i)
const double pi = acos(-1.0);

int n;

char s[110];

int main(){
  cin>>n;
  scanf("%s",s);
  if(n%2){
    printf("No\n");
    return 0;
  }
  rep(i,0,n/2){
    if(s[i] != s[n/2+i]){
      printf("No\n");
      return 0;
    }
  }
  printf("Yes\n");
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
	
	public static void main(String[] args) {
		Scanner scanner = new Scanner(System.in);
		
		
		while(true){ 
		int H = scanner.nextInt();
		int W = scanner.nextInt();
		
		if ( H == 0 && W == 0 ){
			break;
			}
			else{
				int smallh;
				int smallw;
				
				for( smallh = 0; smallh < H; smallh++  ) {
					
					
					for( smallw = 0; smallw < W; smallw++ ) {
					System.out.print("#");
					}
					System.out.println();
				}
			}
		System.out.println();
		}
	}
}

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

int n, a[200000];
pair<int, int> p[200000];

int main() {
	cin >> n;
	for(int i = 0; i < n; i++){
		int x;
		cin >> x;
		p[i] = make_pair(x, i);
	}
	
	sort(p, p+n);
	
	for(int i = 0; i < n; i++){
		a[p[i].second] = i;
	}
	
	for(int i = 0; i < n; i++){
		if(a[i] < n/2){
			cout << p[n/2].first << endl;
		}else{
			cout << p[n/2-1].first << endl;
		}
	}
	
	return 0;
}

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

int main()
{
  long long n, k ,mo=0;
  cin>>n>>k;
  int arr[n]= { };
  for(long long i=0 ; i<n ;i++ )
  {
      cin>>arr[i];
  }

  sort(arr , arr+n);
for(long long i=n-1 ; k>0 ;k-- ,i-- )
  {
      arr[i]=0;
  }
  for(long long i=0 ; i<n ;i++ )
  {
      mo+=arr[i];

  }
  cout<<mo;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i > 0; i++)
const int MOD =1e9+7;
using ll=long long;

int main(){
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i];
  for(int i = n-1; i>=0; i-=2){
    cout << a[i] << " ";
    a[i] = -1;
  }
  rep(i,n) if(a[i] != -1) cout << a[i] << " "; 
}

Measured memory_bytes: 2944
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <map>
#include <functional>
#include <cmath>
#include <cstdint>
#include <mutex>
#include <thread>
#include <bitset>


using namespace std;

int main(void)
{
	int n;
	vector<string> s;

	string s_;

	cin >> n;
	for (int i = 0; i < n; i++)
	{
		cin >> s_;
		s.push_back(s_);
	}
	std::sort(s.begin(), s.end());
	s.erase(std::unique(s.begin(), s.end()), s.end());

	cout << s.size();

	return 0;
}

Measured memory_bytes: 11664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e6+100;

ll qpow(ll x,ll n,int mod){
    ll sum=1;
    while(n){
        if(n&1) sum=sum*x%mod;
        x=x*x%mod;
        n>>=1;
    }
    return sum;
}

int popcount(int u){
    u=(u&0x55555555)+((u>>1)&0x55555555);
    u=(u&0x33333333)+((u>>2)&0x33333333);
    u=(u&0x0F0F0F0F)+((u>>4)&0x0F0F0F0F);
    u=(u&0x00FF00FF)+((u>>8)&0x00FF00FF);
    u=(u&0x0000FFFF)+((u>>16)&0x0000FFFF);
    return u;
}

int ans(int x){
    if(x==0) return 0;
    int kk=popcount(x);
    return 1+ans(x%kk);
}

int main(){
    ios::sync_with_stdio(0);cin.tie(0);
    int n;
    cin>>n;
    string s;
    cin>>s;
    int one=0;

    for(int i=0;i<n;i++){
        if(s[i]=='1') 
            one++;
    }

    int p1=0,p2=0;

    for(int i=0;i<n;i++){
        if(one!=1){
            p1=(p1*2+s[i]-'0')%(one-1);
        }
        p2=(p2*2+s[i]-'0')%(one+1);
    }

    for(int i=0;i<n;i++){
        if((s[i]=='1' && one==1)){
            cout<<0<<endl;
        }
        else if(s[i]=='1'){
            cout<<1+ans((p1-qpow(2,n-i-1,one-1)+(one-1))%(one-1))<<endl;
        }
        else if(s[i]=='0'){
            cout<<1+ans((p2+qpow(2,n-i-1,one+1)+(one+1))%(one+1))<<endl;
        }
    }

    return 0;
}

Measured memory_bytes: 3772
#include<iostream>
#include<cstdio>
#include<map>
#include<vector>
#include<algorithm>
using namespace std;
typedef pair<int,int>PAIR;
 
bool cmp(const PAIR&left,const PAIR&right){     //Õâ¶ùÓÐ¸Ä¶¯ 
	
		return left.second == right.second ? left.first < right.first : left.second > right.second;
	
};
  
int main()
{
	map<int,int>m;
	int a,max;
	while(~scanf("%d",&a))
		m[a]++;
	vector<PAIR>v(m.begin(),m.end());
	sort(v.begin(),v.end(),cmp);
	max=v[0].second;
	for(int i=0;i!=(int)v.size();++i)
		if(v[i].second==max)
			cout<<v[i].first<<endl;
		else 
			break;
	return 0;
}



Measured memory_bytes: 3148
from collections import defaultdict


def mapt(fn, *args):
    return tuple(map(fn, *args))


def Input():
    return mapt(int, input().split(" "))


def main():
    n, x = Input()
    l = Input()
    d = defaultdict(int)
    d[0] = 0
    ans = 0

    for i in range(1, n+1):
        d[i] = d[i-1] + l[i-1]

    for i in d.values():
        if i <= x: ans += 1

    print(ans)

main()

Measured memory_bytes: 9320
A=[[int(_) for _ in input().split()] for i in range(3)]
flag=[[0]*3 for i in range(3)]
n=int(input())
for k in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if A[i][j]==b:
                flag[i][j]=1
import numpy as np
if (3 in np.sum(flag,axis=0)) or (3 in np.sum(flag,axis=1)) or (((flag[0][0]==flag[1][1] and flag[1][1]==flag[2][2]) or (flag[0][2]==flag[1][1] and flag[1][1]==flag[2][0])) and flag[1][1]==1):
    print("Yes")
else:
    print("No")

Measured memory_bytes: 12192
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memst(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))

#define MOD ((lli)(1000000007))
lli mop(lli p,lli q){
	lli res=1,bp=p,b=1;
	while(q){
		if(q&b){
			res=(res*bp)%MOD;
			q-=b;
		}
		bp=(bp*bp)%MOD;
		b*=2;
	}
	return res;
}

lli inv(lli p){
	return mop(p,MOD-2);
}

lli fact(int p){
	lli res=1;
	reg(i,1,p)res=(res*i)%MOD;
	return res;
}

/*
lli comb(lli p,lli q){
	lli res=(((fact(p)*inv(fact(q)))%MOD)*inv(fact(p-q)))%MOD;
	return res;
}
*/

lli fdat[500005];

lli ifdat[500005];

void init(){
	{
		fdat[0]=fdat[1]=1;
		lli r=1;
		reg(i,1,500004){
			r=(r*i)%MOD;
			fdat[i] = r;
		}
	}

	{
		ifdat[0]=ifdat[1]=1;
		lli r=1;
		reg(i,1,500004){
			r=(r*inv(i))%MOD;
			ifdat[i] = r;
		}
	}
}

lli comb(lli p,int q){
	p%=MOD;
	lli res=1;
	rep(i,q)res=(res*(p-i))%MOD;
	res=(res*ifdat[q])%MOD;
	return res;
}


int n,x;
lli d;
lli dp[2005][4005];

int main(void){
	init();
	for(;;){
		scanf("%d%lld%d",&n,&d,&x);
		if(n==0)break;
		//printf("%d %lld %d\n",n,d,x);
		memset(dp,0,sizeof(dp));
		dp[0][n]=1;
		reg(i,1,n){
			lli ns=0;
			reg(j,1,x-1)ns=(ns+dp[i-1][j])%MOD;
			rep(j,n){
				dp[i][j]=ns;
				ns=(ns+dp[i-1][j+x])%MOD;
				ns=(ns-dp[i-1][j+1]+MOD)%MOD;
			}
		}
		lli ans=0;
		reg(i,1,n){
			if(i>d)break;
			lli na=(comb(d,i)*dp[i][0])%MOD;
			ans=(ans+na)%MOD;
		}
		printf("%lld\n",ans);
	}
	
	return 0;
}

Measured memory_bytes: 71740
#include<stdio.h>

int serch(int a[],int b,int key){
  int c=0;
  a[b]=key;
  while(a[c]!=key) c++;
  if(c==b) return 0;
  else return 1;
}
  

int main(){
  int i,b,d,a[10001],sum=0,key;
    scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&a[i]);
  }

  scanf("%d",&d);
  for(i=0;i<d;i++){
    scanf("%d",&key);
    if(serch(a,b,key)) sum++;
  }

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

    return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int,int>;
const long long inf = 1000000001; // const 書き換え禁止
const double PI = 3.14159265358979323846; //M_PI はライブラリ

int main(void){
    string s;
    cin >> s;
    int a = (s[0]-'0')*10 + (s[1]-'0');
    int b = (s[2]-'0')*10 + (s[3]-'0');
    if(1<= b && b <= 12 && 1<= a && a <= 12){
        cout << "AMBIGUOUS" << endl;
    }else if(1<= b && b <= 12){
        cout << "YYMM" << endl;
    }else if(1<= a && a <= 12){
        cout << "MMYY" << endl;
    }else{
        cout << "NA" << endl;
    }
}

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

int main()
{
  int N ;
  string S ;
  cin>>N>>S ;
  
  int SIZE=S.size() ;
  for(int i=0;i<SIZE;i++){
    S.at(i)+=N ;
    if(S.at(i)>'Z') S.at(i)='A'+S.at(i)-'Z'-1 ;
  }
  for(int i=0;i<SIZE;i++) cout<<S.at(i) ;
  
  return 0 ;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
long n,k;
while(cin>>n){
if(n==0)break;
for(k=0;;k++){
if(n==1)break;
if(n/2*2==n)n/=2;else n=3*n+1;
}
cout<<k<<endl;
}
return 0;
}

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

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    long sum = 0;
    if (2*C <= A + B) {
        sum += min(X, Y) * 2 * C;
        sum += (X - min(X, Y)) * min(A, 2*C) + (Y - min(X, Y)) * min(B, 2*C);
        cout << sum << endl;
    } else {
        sum += A * X + B * Y;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n, a, b;
	cin >> n >> a >> b;
	cout << min(a, b) << " " << max(a+b-n, 0) << endl;
	return 0;
}


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

// g++ -std=c++17 -O2 -Wall template.cpp -o template
int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x;
    cin >> x;
    while (true) {
        auto r = x - 1;
        while (x % r) {
            r--;
        }
        if (r == 1) {
            cout << x << endl;
            return 0;
        } else {
            x++;
        }
    }
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    // Solution
}


Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <cstdint>
#include <iostream>
#include <iterator>
#include <utility>
#include <vector>

// lib/util.hpp
#ifndef UTIL_HPP
#define UTIL_HPP


typedef std::int_fast64_t i64;
typedef std::uint_fast64_t u64;
typedef std::int_fast32_t i32;
typedef std::uint_fast32_t u32;

namespace tools {
  template <typename T>
  void read(std::vector<T>& vector, const typename std::vector<T>::size_type size) {
    vector.reserve(size);
    std::copy_n(std::istream_iterator<T>(std::cin), size, std::back_inserter(vector));
  }

  template <typename T, std::size_t N>
  void read(std::array<T, N>& array) {
    std::copy_n(std::istream_iterator<T>(std::cin), N, array.begin());
  }
}

#endif

// lib/union_find.hpp
#ifndef UNION_FIND_HPP
#define UNION_FIND_HPP


/*
usage:

tools::union_find<std::int_fast64_t> uf(10);
uf.unite(1, 3);
uf.is_same(1, 3);
*/

namespace tools {
  template <typename T>
  class union_find {
  private:
    std::vector<T> parents;
    std::vector<T> sizes;

  public:
    union_find(const T n) :
      parents(n),
      sizes(n, 1) {
      for (T i = 0; i < n; ++i) {
        parents[i] = i;
      }
    }

    T root(const T x) {
      return this->parents[x] == x ? x : (this->parents[x] = this->root(this->parents[x]));
    }

    bool is_same(const T x, const T y) {
      return this->root(x) == this->root(y);
    }

    void unite(T x, T y) {
      x = this->root(x);
      y = this->root(y);
      if (x == y) return;

      if (this->sizes[x] < this->sizes[y]) std::swap(x, y);
      this->parents[y] = x;
      this->sizes[x] += this->sizes[y];
    }

    T size(const T x) {
      return this->sizes[this->root(x)];
    }
  };
}

#endif

// main.cpp

int main() {
  i32 N, K, L;
  std::cin >> N >> K >> L;

  tools::union_find<i32> road(N);
  for (i32 i = 0; i < K; ++i) {
    i32 p_i, q_i;
    std::cin >> p_i >> q_i;
    --p_i;
    --q_i;
    road.unite(p_i, q_i);
  }

  tools::union_find<i32> train(N);
  for (i32 i = 0; i < L; ++i) {
    i32 r_i, s_i;
    std::cin >> r_i >> s_i;
    --r_i;
    --s_i;
    train.unite(r_i, s_i);
  }

  const auto key = [&road, &train](const i32 i) {
    return (static_cast<i64>(road.root(i)) << 32) | static_cast<i64>(train.root(i));
  };

  std::unordered_map<i64, i64> map;
  for (i32 i = 0; i < N; ++i) {
    ++map[key(i)];
  }

  std::string delimiter = "";
  for (i64 i = 0; i < N; ++i) {
    std::cout << delimiter << map[key(i)];
    delimiter = " ";
  }
  std::cout << std::endl;
  return 0;
}

Measured memory_bytes: 14408
#include <bits/stdc++.h>
#define ll long long
#define double long double
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
#define mod (ll)(1e9+7)
#define inf (ll)(3e18+7)
#define P pair<int,int>
#define PiP pair<int,pair<int,int>>
#define all(x) x.begin(),x.end()
using namespace std;

int main() {
  int n, ans=0;
  cin >> n;
  REP(i, n) if(i % 2 == 1) ans++;
  cout << fixed << setprecision(10) << (double)ans / n;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <vector>
#include <utility>
#include <string>
#include <algorithm>
#include <cmath>
#include <queue>
 
typedef long long ll;

#define rep(i,n) for(ll i = 0; i < n; i++)
 
using namespace std;
 
const ll INF = ll(1e18)+1;
const double PI=3.14159265358979323846;

int main(){
  int N;
  cin >> N;
  vector<int> vi, P(N), Q(N);
  rep(i,N) vi.push_back(i+1);
  rep(i,N) cin >> P[i];
  rep(i,N) cin >> Q[i];
  int a, b, now=1;
  do{
    if(vi == P) a = now;
    if(vi == Q) b = now;
    now++;
  }while(next_permutation(vi.begin(),vi.end()));
  cout << abs(a-b) << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
const int inf=1e9,mod=1e9+7;
typedef long long ll;
int read() {
	int x=0,f=1;
	char c=getchar();
	while(c<'0'||c>'9') f=(c=='-')?-1:1,c=getchar();
	while(c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
	return x*f;
}
int a[100001],b[100001];
main() {
	int n=read(),ans=0,x;
	for(int i=1; i<=n+1; i++)
		a[i]=read();
	for(int i=1; i<=n; i++)
		b[i]=read();
	for(int i=n+1; i>=1; i--) {
		if(b[i]!=0)
			x=min(b[i],a[i]),ans+=min(b[i],a[i]),a[i]-=x,b[i]-=x;
		if(b[i]==0) {
			ans+=min(b[i-1],a[i]);
			b[i-1]-=min(b[i-1],a[i]);
		}
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <utility>
#include <typeinfo>
#include <cmath>
#include <algorithm>
#include <iostream>
#include <string>
typedef long long int ll;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
using namespace std;

int main()
{
  int sx,sy,tx,ty;
  cin >> sx >> sy >> tx >>ty;

  REP(i,tx-sx){cout <<'R';}
  REP(i,ty-sy){cout <<'U';}

  REP(i,tx-sx){cout <<'L';}
  REP(i,ty-sy+1){cout <<'D';}

  REP(i,tx-sx+1){cout <<'R';}
  REP(i,ty-sy+1){cout <<'U';}

  cout << 'L';
  cout << 'U';

  REP(i,tx-sx+1){cout <<'L';}
  REP(i,ty-sy+1){cout <<'D';}

  cout << 'R';

  cout << endl;

  return 0;
}




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

int main(void){
    int n,k,q;
    cin >> n >> k >> q;
    vector<int> vec(n,0);
    vector<int> result(n,k-q);

    for(int i=0;i<q;i++){
        int m;
        cin >> m; m--;
        vec[m]++;
    }
    for(int i=0;i<n;i++) result[i] += vec[i];
    for(int i=0;i<n;i++){
        if(result[i]>0) cout << "Yes" << endl;
        else cout << "No" << endl;
    }
}

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

using namespace std;

const int n = 100005;

int main(){
  int N, M;
  int H[n];
  
  cin >> N >> M;
  vector<int> ma(N,0);

  for(int i=0; i<N; i++) cin >> H[i];
  for(int i=0; i<M; i++){
    int a, b;
    cin >> a >> b;
    ma[a-1] = max(ma[a-1], H[b-1]);
    ma[b-1] = max(ma[b-1], H[a-1]);
  }
  
  int count = 0;
  for(int i=0; i<N; i++){
    if(ma[i] < H[i]) ++count;
  }
  
  cout << count << endl;
  return 0;
}

Measured memory_bytes: 4052
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
using namespace std;


int main(void){
    long long int n,m;
    long long int inf = 1000000007;
    cin >> n >> m;
    int a[m];
    int check[n+1];
    long long int ans = 1, count = 1;
    for(int i = 0; i < n+1; i++)
        check[i] = 0;
    for(int i = 0; i < m; i++){
        cin >> a[i];
        check[a[i]]++;

    }
    long long fibo[100002];
    fibo[1] = 1; fibo[2] = 1;
    for(int i = 3; i < 100002; i++)
        fibo[i] = (fibo[i-1]+fibo[i-2]) % inf;
        //cout << fibo[i] << endl;
    for(int i = 1; i <= n; i++){
        if(check[i] == 0)
            count++;
        else{
            ans *= fibo[count];
            ans %= inf;
           // cout << count << endl;
            count = 0;
        }
        if(check[i] == 1 && check[i-1] == 1){
            ans = 0;
            break;
        }
       // cout << ans << endl;
    }
    if(count != 0){
        ans *= fibo[count];
        ans %= inf;        
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, n) for(int i = 1; i <= (int)(n); i++)
const long long INF = 1LL << 60;
const double PI=3.14159265358979323846;
int main() 
{
    int k,n;
    cin >> k >> n;

    int a[n+10];
    rep(i,n){
        cin >> a[i];
    }

    int ans=10000000;
    for(int i=0;i<n-1;i++){
        ans=min(ans,k-(a[i+1]-a[i]));
    }
  ans=min(ans,k-(k+a[0]-a[n-1]));
    cout << ans << endl;
}

Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
#include <string>
#include <ctype.h>
#include <iomanip>
#include <utility>
#include <bitset>
#include <set>
#include <map>
#include <ios>
#include <cstdlib>
using namespace std;
int main() {
    int N; cin >> N;
    vector<string> S(N);
    vector<int> P(N);
    for(int i = 0; i < N; i++) {
        cin >> S[i] >> P[i];
    }
    vector<int> A(N);
    for(int i = 0; i < N; i++) {
        A[i]= 1;
        for(int j = 0; j < N; j++) {
            if (i==j) continue;
            if (S[i]==S[j]&&P[i]<P[j]) A[i]++;
            else if (S[i]>S[j]) A[i]++;
        }
    }
    for(int i = 0; i < N; i++) {
        for (int j=0;j<N;j++){
            if (i+1==A[j]) {
                cout << j+1 << endl;
                continue;
            }
        }
    }
    return 0;
}

Measured memory_bytes: 256
f, s, t = 3,2,1
for i in range(10):
    z = int(input())
    if z >= f:
        f,s,t = z, f, s;
    elif z>=s:
        s,t = z,s;
    elif z>=t:
        t = z
print(f);print(s);print(t)

Measured memory_bytes: 7560
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#define ll long long
#define rep(i,l,r)for(ll i=(l);i<(r);i++)
#define repp(i,l,r,k)for(ll i=(l);i<(r);i+=(k))
#define INF ((1LL<<62)-(1LL<<31))
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define bit(n,m)(((n)>>(m))&1)
int upll(const void*a, const void*b){return*(ll*)a<*(ll*)b?-1:*(ll*)a>*(ll*)b?1:0;}
int downll(const void*a, const void*b){return*(ll*)a<*(ll*)b?1:*(ll*)a>*(ll*)b?-1:0;}
void sortup(ll*a,int n){qsort(a,n,sizeof(ll),upll);}
void sortdown(ll*a,int n){qsort(a,n,sizeof(ll),downll);}
ll pom(ll a,ll n,int m){ll x=1;for(a%=m;n;n/=2)n&1?x=x*a%m:0,a=a*a%m;return x;}
//#define MOD 998244353
#define MOD 1000000007
#define invp(a,p)pom(a,p-2,p)

int main(){
    int a,b,c;
    scanf("%d %d %d",&a,&b,&c);
  
  if((a!=b && a!=c && b!= c)||(a==b && a==c)){
    printf("No");
  }
  else
    printf("Yes");
  return 0;
}

Measured memory_bytes: 128
from fractions import gcd
N,M = map(int,input().split())
a = list(map(int,input().split()))

def count_2(x):
    count = 0
    while x%2 == 0:
        count += 1
        x /= 2
    return count

flag = True

for i in range(N-1):
    if count_2(a[i]) != count_2(a[i+1]):
        flag = False
        break
    
if not flag:
    print(0)
    exit()

lcm=1
for i in range(N):
    lcm = lcm*a[i]//gcd(a[i],lcm)

ans=0
if lcm//2<=M:
    ans=(M-lcm//2)//lcm+1

print(ans)

Measured memory_bytes: 89580
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	m, d := iScan(), iScan()
	ans := 0
	for i := 22; i <= d; i++ {
		if (i%10)*(i/10) <= m && (i%10) > 1 {
			ans++
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1772
#include <stdio.h>
#include <iostream>
using namespace std;

int main(){
    int input_sec;
    int hour;
    int min;
    int sec;
    
    cin >> input_sec;
    
    hour = input_sec / 3600;
    min = (input_sec % 3600) / 60;
    sec = input_sec % 60;
    
    printf("%d:%d:%d\n", hour, min, sec);
    
    return 0;
}


Measured memory_bytes: 3212
#define _CRT_SECURE_NO_WARNINGS
#include <bits/stdc++.h>

using namespace std;

typedef long long ll;

void solve() {
	int n;
	cin >> n;
	vector<int> s(n + 1);
	for (int i = 2; i <= n; i++)
		if (s[i] == 0)
			for (int j = i; j <= n; j += i)
				s[j] = i;
	ll otv = 1;
	for (int i = 2; i <= n; i++) {
		map<int, int> div;
		int t = i;
		while (t != 1) {
			div[s[t]]++;
			t /= s[t];
		}
		ll cnt = 1;
		for (auto x : div)
			cnt *= (x.second + 1);
		otv += i * cnt;
	}
	cout << otv;
}

int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#if defined(_DEBUG)
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
	int q = 1;
	//cin >> q;
	for (; q > 0; q--) {
		solve();
		cout << '\n';
	}
}

Measured memory_bytes: 42276
//#include <bits/stdc++.h>
#include <iostream>
#include <fstream>
#include <vector>
#include <string>
#include <cmath>
#include <algorithm>
#include <map>
#include <iomanip>
#include <stdlib.h>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <time.h>

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

const ll nmax = 1e9 + 7;
const ll Mod = 998244353;
const double PI = 2 * asin(1);

int main(){
  ll N, A, B; cin >> N >> A >> B;

  ll ans = N / (A + B) * A;
  ans += min(N % (A + B), A);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
open Batteries
open Printf
open Scanf

let ($) g f x = g (f x)
let nil = ()

module MyList = struct
  include List
  let foldl = fold_left
  let foldr = fold_right
  
  let flatmap f ls = concat @@ map f ls

  let zipf = map2
  let zipfi = map2i
end

module L = MyList

let atoi = int_of_string
let itoa = string_of_int
let atof = float_of_string
let ftoa = string_of_float
let ctoi = int_of_char
let itoc = char_of_int

let stocl = String.to_list
let cltos = String.of_list
let spsp s = String.split_on_char ' ' s

module MyString = struct
  include String

  let map' f s = L.map f (stocl s)
  let mapi' f s = L.map f (stocl s)

  let zipf f a b = L.zipf f (stocl a) (stocl b)
  let zipfi f a b = L.zipfi f (stocl a) (stocl b)

  let mkstr f sep ls =
    L.foldl (fun acc x -> acc ^ sep ^ (f x)) (f @@ L.hd ls) (List.tl ls)
end

module S = MyString

let tup2 a b = (a, b)
let tup3 a b c = (a, b, c)
let tup4 a b c d = (a, b, c, d)

let rds () = read_line ()
let rds2 () = scanf "%s %s\n" tup2

let rdi () = atoi @@ rds ()
let rdi2 () = scanf "%d %d\n" tup2
let rdi3 () = scanf "%d %d %d\n" tup3
let rdi4 () = scanf "%d %d %d %d\n" tup4

let rdhs () = spsp @@ rds ()
let rdhi () = rdhs () |> L.map atoi

let rdvs n rdf = L.init n (fun _ -> rdf ())

let rdvi n = rdvs n rdi
let rdvi2 n = rdvs n rdi2
let rdvi3 n = rdvs n rdi3
let rdvi4 n = rdvs n rdi4

let puts s = print_endline s
let putyn b = puts (if b then "Yes" else "No")
let puti i = puts @@ itoa i

let _ =
  let (a,b,c,k) = rdi4 () in
  let r =
    if k <= a + b then (min a k)
    else a - (k - (a + b))
  in puti r;;

Measured memory_bytes: 5532
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import static java.lang.Math.sin;
import static java.lang.Math.cos;
import static java.lang.Math.toRadians;

public class Main {

  private static StringBuilder buf = new StringBuilder();

  public static void main(String[] args) throws IOException {
    
    try(BufferedReader br = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt( br.readLine() );
      Point2D p1 = new Point2D(0,0);
      Point2D p2 = new Point2D(100, 0);

      calcKochCurve(n, p1, p2);
      System.out.print(buf);
      
    }
  }

  private static void calcKochCurve(int d, Point2D p1, Point2D p2) {
    double rad = toRadians(60);

    buf.append(p1);
    kochCurve( d, p1, p2, rad );
    buf.append(p2);
  } 

  private static void kochCurve(int d, Point2D p1, Point2D p2, double rad) {
    if( d != 0) {
      Point2D s = new Point2D();
      Point2D t = new Point2D();

      s.x = (2*p1.x + p2.x) / 3;
      s.y = (2*p1.y + p2.y) / 3;
      t.x = (p1.x + 2*p2.x) / 3;
      t.y = (p1.y + 2*p2.y) / 3;

      Point2D u = new Point2D();

      u.x = (t.x - s.x)*cos(rad) - (t.y - s.y)*sin(rad) + s.x;
      u.y = (t.x - s.x)*sin(rad) + (t.y - s.y)*cos(rad) + s.y;

      kochCurve(d-1, p1, s, rad);
      buf.append(s);
      kochCurve(d-1, s, u, rad);
      buf.append(u);
      kochCurve(d-1, u, t, rad);
      buf.append(t);
      kochCurve(d-1, t, p2, rad);
    }
  }
}

class Point2D {
  double x;
  double y;

  public Point2D() { }
  public Point2D(double x,double y) {
    this.x = x;
    this.y = y;
  }

  @Override
  public String toString() {
    return String.format("%.8f %.8f\n", x, y);
  }
  public double distance(Point2D p) {
    return Math.sqrt(Math.pow((p.x - this.x),2) + Math.pow((p.y - this.y), 2));
  }
}


Measured memory_bytes: 41140
#include <iostream>
using namespace std;
int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while (a >= b) {
        b *= 2;
        k--;
    }
    while (b >= c) {
        c *= 2;
        k--;
    }
    cout << ((k >= 0) ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3672
#include <iostream>

int counts[1001];

int main(int argc, char *argv[]){
	int n;
	std::cin >> n;

	for(int i = 2;i <= n; i++){
		int x = i;
		for(int j = 2; x > 1;){
			if(x % j == 0){
				counts[j]++;
				x /= j;
			}else{
				j++;
			}
		}
	}
	unsigned long long result = 1;
	for(int i = 2; i <= 1000; i++){
		if(i > 0)
			result = (result * (counts[i] + 1)) % 1000000007;
	}
	std::cout << result << std::endl;
	return 0;
}


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

namespace AtCoderBegin
{
    class Program
    {
        static void Main(string[] args)
        {
            int red = 0, white = 0;
            int N = int.Parse(Console.ReadLine());
            var stones = new List<string>();
            {
                for (int i = 0; i < N; i++)
                {
                    string a = Char.ConvertFromUtf32(Console.Read());
                    stones.Add(a);
                }
                for (int i = 0; i < N; i++)
                {
                    if (stones[i] == "R")
                    {
                        red++;
                    }
                }
                for (int i = 0; i < red; i++)
                {
                    if (stones[i] == "W")
                    {
                        white++;
                    }
                }
            }
            Console.WriteLine(white);
		}
    }
}   


Measured memory_bytes: 36044
# from sys import stdin

# # 解説のコード
# def get_result(data):
#     N, X, Y = data
#     dist_cnt = [0 for i in range(N)]
#     for i in range(1, N+1):
#         for j in range(i+1, N+1):
#             min_dist = min([j-i, abs(X-i) + 1 + abs(Y-j), abs(Y-i) + 1 + abs(X-j)])
#             dist_cnt[min_dist] += 1
#     for i in range(1, N):
#         print(dist_cnt[i])


# if __name__ == '__main__':
#     data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
#     get_result(data)

from sys import stdin
from collections import deque


class BreadthFirstSearch:
    def __init__(self, num_nodes):
        self.n = num_nodes
        self.graph = [[] for _ in range(self.n)]

    # Edge数分回すことを想定
    def add_edge(self, start, end, undirected=True):
        self.graph[start].append(end)
        if undirected:
            self.graph[end].append(start)

    # depth = distance
    def search(self, start_node):
        order = [-1] * self.n # a bfs ordering of each vertex
        parent = [-1] * self.n # parent of each vertex in the bfs search tree
        depth = [-1] * self.n # the depth of each vertex
        q = deque([(start_node, -1, 0)]) # (vertex, parent, depth)
        num = 0 # current ordering
        while len(q) > 0:
            v, p, d = q.popleft()
            if order[v] < 0: # visited v for the first time
                order[v] = num; parent[v] = p; depth[v] = d
                num += 1
                for u in self.graph[v]:
                    if order[u] >= 0: continue
                    q.append((u, v, d+1))
        return order, parent, depth


# BFS pypyでAC
def get_result(data):
    N, X, Y = data
    _data = [[i, i+1] for i in range(1, N)]
    _data += [[X, Y]]
    bfs = BreadthFirstSearch(N)
    for val in _data:
        bfs.add_edge(val[0]-1, val[1]-1)
    dist_cnt = [0 for i in range(N)]
    for i in range(N):
        _, _, depth = bfs.search(i)
        for j in range(i, N):
            dist_cnt[depth[j]] += 1
    for i in range(1, N):
        print(dist_cnt[i])


if __name__ == '__main__':
    data = list(map(int, stdin.readline().rstrip('\n').split(' ')))
    get_result(data)


Measured memory_bytes: 53596
#include<stdio.h>
int min(int a,int b)
{
	if (a < b)
		return a;
	else
		return b;
}
int main()
{
	int N, A, B;
	int P;

	int least = 0, middle = 0, best = 0;
	scanf("%d", &N);
	scanf("%d %d", &A, &B);
	int i;
	for ( i = 0; i < N; i++)
	{
		scanf("%d", &P);
		if (P <= A)
			least++;
		else if (P <= B)
			middle++;
		else
			best++;
	}
	printf("%d", min(min(middle, best), least));
	return 0;
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;

#define SZ(x) ((int)x.size())

const int N = (int)1e5+5;
const ll oo = (ll)1e18+7;
int n, op[N];
ll a[N], f[N][3];

void readData() {
	scanf("%d", &n);
	op[0] = 1;
	for (int i = 1; i <= n; ++i) {
		scanf("%lld", &a[i]);
		if (i == n) break;
		char s[2]; scanf("%s", s);
		if (s[0] == '-') op[i] = -1;
		else op[i] = 1;
	}
}

namespace my_old_sol {
	ll dp[N], sum[N];
	priority_queue<ll> pq;
	vector<int> q;

	void solve() {
		readData();
		for (int i = 1; i <= n; ++i) sum[i] = sum[i - 1] + a[i];
		int idx = 1;
		for (; idx <= n; ++idx) {
			dp[idx] = sum[idx];
			if (op[idx] == -1) break;
		}
		for (int i = idx + 1; i <= n; ++i) {
			dp[i] = dp[i - 1] + (ll)op[i - 1] * a[i];
			if (op[i - 1] == -1) {
				if (SZ(q)) {
					ll val = sum[i - 1] - sum[q.back() - 1];
					pq.push(dp[q.back() - 1] - val - sum[i - 1]);
				}
				q.push_back(i);
			}
			if (SZ(pq) > 0) dp[i] = max(dp[i], pq.top() + sum[i]);
		}
		printf("%lld", dp[n]);
	}
}

int main() {
	readData();
	for (int i = 0; i <= n; ++i) f[i][0] = f[i][1] = f[i][2] = -oo;
	f[0][0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int j = 0; j < 3; ++j) if (f[i][j] != -oo) {
			int oper = (j % 2 == 0 ? op[i] : -op[i]);
			f[i + 1][j] = max(f[i + 1][j], f[i][j] + (ll)oper * a[i + 1]);
			if (op[i] == -1 && j < 2) f[i + 1][j + 1] = max(f[i + 1][j + 1], f[i][j] + (ll)oper * a[i + 1]);
			if (j > 0) f[i + 1][j - 1] = max(f[i + 1][j - 1], f[i][j] + (ll)oper * a[i + 1]);
		}
	}
	printf("%lld", max(f[n][0], max(f[n][1], f[n][2])));
	return 0;
}


Measured memory_bytes: 3712
#include <vector>
#include <string>
#include <iostream>
#include <iomanip>
#include <queue>
#include <algorithm>
#include <functional>
#include <map>
#include <array>
#include <cmath>
#include <set>
#include <numeric>

using namespace std;

template <typename T>
using TABLE = vector<vector<T>>;

using LONG = long long;
using LVEC = vector<long long>;

#define FOR(_i, s, e) for(_i = s; _i < e; ++_i)
#define FOR_INV(_i, s, e) for(_i = e - 1; _i >= s; --_i)

long long PRIME = 1e9 + 7;
long long PRIME2 = 998244353;


using pos = std::pair<LONG, LONG>;


int main(){
    LONG i, j, k;

    LONG N;
    cin >> N;

    string S;

    map<string, int> counter;
    counter["AC"] = 0;
    counter["WA"] = 0;
    counter["TLE"] = 0;
    counter["RE"] = 0;

    FOR(i, 0, N){
        cin >> S;
        counter[S] += 1;
    }

    cout << "AC x " << counter["AC"] << "\n";
    cout << "WA x " << counter["WA"] << "\n";
    cout << "TLE x " << counter["TLE"] << "\n";
    cout << "RE x " << counter["RE"] << "\n";
}


Measured memory_bytes: 3628
/* BISMILLAHIR RAHMANIR RAHIM */
#include<bits/stdc++.h>
using namespace std;
#define ll        long long
#define ull       unsigned long long
#define si(x)     scanf("%d", &x)
#define sll(x)    scanf("%lld", &x)
#define ssll(x,y)    scanf("%lld %lld", &x ,&y)
#define sd(x)     scanf("%lf", &x)
#define l0(i,n)   for(ll i=0; i<n; i++)
#define MAX       100005
#define maxn 	  200002
#define pb 		  push_back
#define mk 		  make_pair
#define endl	  "\n"
#define INF 	  1000000000
#define MOD		  1000000007
#define imie(...) "[" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

int main ()
{
		ios::sync_with_stdio(0);
		cin.tie(0);
		//CODE TONOY
		int a,b;
		cin >> a >> b;
		if (a+b == 15) 
		{
			cout << "+" << endl; 
			return 0;
		}
		if (a*b == 15) 
		{
			cout << "*" << endl;
			return 0;
		}
		else cout << "x" << endl;
		return 0;  
}  

/*
               
 

*/


Measured memory_bytes: 3628
import java.util.*;
public class Main {
    public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
        int nA = sc.nextInt();
        int nB = sc.nextInt();
//        double rP = (double) 0.0;
		int  nX = 0;
		

//		rP =  (double) ((double)(nA + nB)/2.0);
		
//		nX = (int) Math.floor(rP);
		if((nA + nB)%2 != 0){
          nX = (nA + nB)/2 +1;
		} else {
          nX = (nA + nB)/2;
		}
		// 出力
		System.out.println(nX);
	}
}

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

using namespace std;

using int64 = long long;

constexpr int MAX_BIT = 17;

vector<int> Path(int s, int t, int mask, int base) {
  if (__builtin_popcount(mask) == 1) {
    return vector<int>({s, t});
  }

  for (int i = 0; i < MAX_BIT; i++) {
    if ((mask & (1 << i)) == 0) continue;
    if ((s & (1 << i)) != (t & (1 << i))) {
      // cout << "i: " << i << endl;;
      for (int j = 0; j < MAX_BIT; j++) {
        if ((mask & (1 << j)) == 0) continue;
        if (j == i) continue;
        // cout << "j: " << j << endl;
        int m_t = s ^ (1 << j);
        int m_s = m_t ^ (1 << i);
        auto p1 = Path(s, m_t, mask ^ (1 << i), base | (s & (1 << i)));
        auto p2 = Path(m_s, t, mask ^ (1 << i), base | (t & (1 << i)));
        p1.insert(p1.end(), p2.begin(), p2.end());
        return p1;
      }
      cerr << "Unexpected!" << endl;
    }
  }
  cerr << "Unexpected!" << endl;
  exit(1);
}

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

  int n, a, b;
  cin >> n >> a >> b;
  if (__builtin_popcount(a) % 2 == __builtin_popcount(b) % 2) {
    cout << "NO" << endl;
    return 0;
  }
  cout << "YES" << endl;
  int mask = (1 << n) - 1;
  auto path = Path(a, b, mask, 0);
  for (int x : path) {
    cout << x << " ";
  }
  cout << endl;
}

Measured memory_bytes: 1776
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

struct state{
	int pos, cost;
	bool operator<(const state &r) const{
		return cost > r.cost;
	}
};

const int INF = 1 << 30;
int C[5010];
int R[5010];
vector<int> G[5010];
vector<int> G2[5010];
int n, k;

void BFS(int v){
	queue<pair<int, int>> q;
	vector<int> dist(n, -1);
	q.push({ v, 0 });
	while (!q.empty()){
		pair<int, int> p = q.front();
		q.pop();

		for (auto &v : G[p.first]){
			if (dist[v] >= 0) continue;
			dist[v] = p.second + 1;
			q.push({ v, dist[v] });
		}
	}

	for (int i = 0; i < n; ++i){
		if (i == v) continue;
		if (dist[i] <= R[v]) G2[v].push_back(i);
	}
}

int main(){
	cin >> n >> k;
	for (int i = 0; i < n; ++i) cin >> C[i] >> R[i];
	while (k--){
		int a, b;
		cin >> a >> b;
		--a, --b;
		G[a].push_back(b);
		G[b].push_back(a);
	}

	for (int i = 0; i < n; ++i) BFS(i);

	int ans = INF;
	{
		priority_queue<state> q;
		q.push({ 0, 0 });

		vector<int> dist(n, INF);
		dist[0] = 0;
		while (!q.empty()){
			state s = q.top();
			q.pop();

			if (dist[s.pos] < s.cost) continue;
			if (s.pos == n-1){
				ans = s.cost;
				break;
			}

			for (auto &v : G2[s.pos]){
				state nxt = {v, s.cost+C[s.pos]};
				if (dist[v] <= nxt.cost) continue;
				dist[v] = nxt.cost;
				q.push(nxt);
			}
		}
	}
	cout << ans << endl;
	
	return 0;
}

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

#define int long long
#define double long double

#define REP(i, b) for(int i = 0; i < (b); i++)
#define REPS(i, b) for(int i = 1; i <= (b); i++)
#define ALL(v) (v).begin(), (v).end()

#define fi first
#define se second
#define pb push_back
#define mp make_pair

using namespace std;

using pi = pair<int, int>;
using vi = vector<int>;
using vd = vector<double>;
using vs = vector<string>;
using vb = vector<bool>;
using vpi = vector<pi>;
using vvi = vector<vi>;
using vvb = vector<vb>;

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

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; }


signed main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(10);

    int N, W; cin >> N >> W;
    vi v(N), w(N); REP(i, N) cin >> v[i] >> w[i];
    vvi dp(N+1, vi(W+1, 0)); dp[0][0] = 0;
    REP(i, N)
    {
        REPS(j, W)
        {
            chmax(dp[i+1][j], dp[i][j]);
            if(j >= w[i]) chmax(dp[i+1][j], dp[i+1][j-w[i]]+v[i]);
        }
    }
    cout << dp[N][W] << endl;
}


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

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int n;
vector<int> pathes[100050];
int dist[3][100050];
int point[3];
vector<int> ans[3];
void solve(int index, int from, int num) {
    for(int i = 1; i + 2 <= pathes[from].size(); i++) {
        ans[index].push_back(num + i);
    }
    ans[index].push_back(num);
    int NEXT = num + 1;
    if(pathes[from].size() >= 3) NEXT += pathes[from].size() - 2;
    for(int i = 0; i < pathes[from].size(); i++) {
        int to = pathes[from][i];
        if(dist[3 - index][to] < dist[3-index][from]) solve(index, to, NEXT);
    }
}

void bfs(int from, int cost, int index) {
    if(dist[index][from] < cost) return;
    dist[index][from] = cost;
    for(int i = 0; i < pathes[from].size(); i++) {
        int to = pathes[from][i];
        bfs(to, cost + 1, index);
    }
}

bool comp(int index) {
    if(index == n) return true;
    if(ans[1][index] != ans[2][index]) return ans[1][index] > ans[2][index];
    return comp(index + 1);
}

int main() {
    //cout.precision(10);
    cin >> n;
    for(int i = 1; i < n; i++) {
        int u, v;
        cin >> u >> v;
        pathes[u].push_back(v);
        pathes[v].push_back(u);
    }
    for(int i = 0; i < 3; i++) {
        for(int j = 1; j <= n; j++) dist[i][j] = INF;
    }
    bfs(1, 0, 0);
    point[1] = 1;
    for(int i = 1; i <= n; i++) {
        if(dist[0][i] > dist[0][point[1]]) point[1] = i;
        //cerr << i << " " << dist[0][i] << endl;
    }
    bfs(point[1], 0, 1);
    point[2] = 1;
    for(int i = 1; i <= n; i++) {
        if(dist[1][i] > dist[1][point[2]]) point[2] = i;
    }
    bfs(point[2], 0, 2);
    int diameter = dist[2][point[1]];
    for(int i = 1; i <= n; i++) {
        if(dist[1][i] + dist[2][i] == diameter) continue;
        if(pathes[i].size() != 1) {
            cout << -1 << endl;
            return 0;
        }
    }
    //cout << point[1] << " " << point[2] << endl;
    solve(1, point[1], 1);
    solve(2, point[2], 1);
    /*
    for(int i = 0; i < ans[1].size(); i++) cout << ans[1][i] << " ";
    cout << endl;
    for(int i = 0; i < ans[2].size(); i++) cout << ans[2][i] << " ";
    */
    if(comp(0)) swap(ans[1], ans[2]);
    for(int i = 0; i < ans[1].size(); i++) {
        cout << ans[1][i] << " ";
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 17784
N,M = map(int,input().split())
AB = [list(map(int,input().split())) for i in range(N)]
AB.sort()
m=0
c=0
for i,x in enumerate(AB):
    m += x[1]
    c += x[0]*x[1]
    if m >= M:
        c -= (m-M)*x[0]
        print(c)
        exit()

Measured memory_bytes: 27880
#include <stdio.h>
#include <stdio.h>

int main(void)
{
	double v,t,y,n1;
	int n;
	while(scanf(" %lf",&v)!=EOF){
		t=v/9.8;
		y=4.9*t*t;
		n=0;
		n1=(5+y)/5;
		while(n<n1){
			n=n+1;
		}
	printf("%d\n",n);
	}
	return 0;
}

Measured memory_bytes: 628
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
#define big 1000000007
int main(){
    int N;
    cin >> N;
    int time = 0;
    vector <pair <int ,int >> p(N);
    for(int i = 0;i<N;i++){
        int a,b;
        cin >> a>>b;
        p.at(i)=make_pair(b,a);
    }
    sort(p.begin(),p.end()); //(締め切りが近い順に並べる)
    bool ans = true;
    for(int i=0;i<N;i++){
        time += p.at(i).second;
        if(time > p.at(i).first){//締め切りオーバー
            ans = false;
        }
    }
    if(ans){
        cout << "Yes" <<endl;
    }
    else{
        cout <<"No"<<endl;
    }
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<queue>
#include<vector>

#define MAX 100000

std::vector<int> G[MAX+1];
int group[MAX];
int n, m;

bool bfs(int src, int id) {

    std::queue<int> Q;
    Q.push(src);
    while(!Q.empty()) {
        int cur = Q.front();Q.pop();
        for (int i = 0; i < G[cur].size(); ++i) {
            int t = G[cur][i];
            if (group[t] != -1) continue;
            group[t] = id;
            Q.push(t);
        }
    }

    return false;
}

void assignGroup() {
    int id = 1;

    for (int i = 0; i < n; ++i) group[i] = -1;
    for (int i = 0; i < n; ++i) {
        if (group[i] != -1) continue;
        bfs(i, id++);
    }

}

int main() {
    scanf("%d %d", &n, &m);

    for (int i = 0; i < m; ++i) {
        int u,k;
        scanf("%d %d", &u, &k);
        G[u].push_back(k);
        G[k].push_back(u);
    }

    assignGroup();

    int q;
    scanf("%d", &q);
    for (int i = 1; i <= q; ++i) {
        int s,d;
        scanf("%d %d", &s, &d);
        group[s] != -1 && group[s] == group[d] ? printf("yes\n") : printf("no\n");
    }

    return 0;
}

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

void rec(int n, int k, string s = "") {
	if (n == 0) {
		cout << s << endl;
		return;
	}
	for (int i = 0; i < k; ++i) {
		rec(n - 1, k, s + (char)('a' + i));
	}
	rec(n - 1, k + 1, s + (char)('a' + k));
}

int main() {
	int n;
	cin >> n;
	rec(n, 0);
}

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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
using P = pair<ll, ll>;
using V = vector<ll>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep1(i, n) for(ll i=1;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--)
#define ALL(obj) (obj).begin(), (obj).end()
#define MOD 1000000007
#define INF 1000000000

ll dp[10001];

void solve_abc153() {
	ll h, n;

	cin >> h >> n;

	V a(n), b(n);

	rep(i, n) {
		cin >> a[i] >> b[i];
	}

	rep(i, 10001) {
		dp[i] = INF;
	}

	dp[h] = 0;
	rrep(i, h, 0) {
		rep(j, n) {
			if (i - a[j] >= 0) {
				dp[i - a[j]] = min(dp[i - a[j]], dp[i] + b[j]);
			}
			else {
				dp[0] = min(dp[0], dp[i] + b[j]);
			}
		}
	}

	cout << dp[0] << "\n";
}

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

	solve_abc153();

	return 0;
}

Measured memory_bytes: 384