akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"

#define MOD 1000000007
#define rep(i, n) for(ll i=0; i < (n); i++)
#define rrep(i, n) for(ll i=(n)-1; i >=0; i--)
#define ALL(v) v.begin(),v.end()
#define rALL(v) v.rbegin(),v.rend()
#define FOR(i, j, k) for(ll i=j;i<k;i++)
#define debug_print(var) cerr << #var << "=" << var <<endl;
#define DUMP(i, v)for(ll i=0;i<v.size();i++)cerr<<v[i]<<" "
#define fi first
#define se second

using namespace std;
typedef long long int ll;
typedef vector<ll> llvec;
typedef vector<double> dvec;
typedef pair<ll, ll> P;
typedef long double ld;
struct edge{ll x, c;};

ll mod(ll a, ll mod){
  ll res = a%mod;
  if(res<0)res=res + mod;
  return res;
}

ll modpow(ll a, ll n, ll mod){
  ll res=1;
  while(n>0){
    if(n&1) res=res*a%mod;
    a=a*a%mod;
    n>>=1;
  }
  return res;
}

ll modinv(ll a, ll mod){
  ll b=mod, u=1, v=0;
  while(b){
    ll t=a/b;
    a-=t*b; swap(a, b);
    u-=t*v; swap(u, v);
  }
  u%=mod;
  if(u<0)u+=mod;
  return u;
}

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

bool is_prime(ll n){
  ll i = 2;
  if(n==1)return false;
  if(n==2)return true;
  bool res = true;
  while(i*i <n){
    if(n%i==0){
      res = false;
    }
    i = i+1;
  }

  //if(i==1)res = false;
  if(n%i==0)res=false;
  return res;
}
/**************************************
** A main function starts from here  **
***************************************/
int main(){
  ll N;
  cin >> N;
  llvec S(N-1), C(N-1), F(N-1);
  rep(i, N-1)cin >> C[i] >> S[i] >> F[i];
  rep(from, N-1){
    ll ans = 0;
    for(ll i=from;i<N-1;i++){
      ans = max(ans, S[i]);
      ll tmp = (ans+F[i]-1)/F[i];
      ans = max(ans, tmp*F[i]);
      ans += C[i];
    }
    cout << ans << endl;
  }
  cout << 0 << endl;
  return 0;
}


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

int main(){
    string s;
    cin >> s;
    bool a = false;
    bool b = false;
    for(string::iterator itr = s.begin(); itr != s.end(); itr++){
        if(*itr == 'A') a = true;
        if(*itr == 'B') b = true;
    }
    if(a && b){
        cout << "Yes" << endl;
    } else {
        cout << "No" << 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;

struct dice{
    int l1, l2, l3, l4, l5, l6;
    void north(){
        int tmp = l1;
        l1 = l2;
        l2 = l6;
        l6 = l5;
        l5 = tmp;}
    void south(){
        int tmp = l1;
        l1 = l5;
        l5 = l6;
        l6 = l2;
        l2 = tmp;}
    void east(){
        int tmp = l1;
        l1 = l4;
        l4 = l6;
        l6 = l3;
        l3 = tmp;}
    void west(){
        int tmp = l1;
        l1 = l3;
        l3 = l6;
        l6 = l4;
        l4 = tmp;}
    void roll(char a){
        if (a == 'N') north();
        if (a == 'S') south();
        if (a == 'E') east();
        if (a == 'W') west();}
};

int main(){
    dice d;
    cin >> d.l1 >> d.l2 >> d.l3 >> d.l4 >> d.l5 >> d.l6;
    string s;
    cin >> s;
    REP(i,s.size()) d.roll((char)s[i]);
    cout << d.l1 << endl;
}

Measured memory_bytes: 3116
#include <bits/stdc++.h>
using namespace std;
const int N=200005;

int main(){
	int n,m,nn[N],mm[N];
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>nn[i];
	}
	cin>>m;
	for(int i=0;i<m;i++){
		cin>>mm[i];
	}
	sort(nn,nn+n);
	sort(mm,mm+m);
	int i,j,k;
	for(i=j=k=0;i<m;){
		while(mm[i]!=nn[j]&&j<n)j++;
		if(j>=n)break;
		i++; j++;
	}
	cout<<((i==m)?"YES\n":"NO\n");
}

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

bool nadjiBingo(bool mat[3][3])
{
    // column
    for (int i=0; i<3; i++)
    {
        if (mat[i][0] && mat[i][1] && mat[i][2])
        {
            return true;
        }
    }
    //row
    for (int j=0; j<3; j++)
    {
        if (mat[0][j] && mat[1][j] && mat[2][j])
        {
            return true;
        }
    }

    //left diagonal
    if (mat[0][0] && mat[1][1] && mat[2][2])
    {
        return true;
    }

    //right diagonal
    if (mat[2][0] && mat[1][1] && mat[0][2])
    {
        return true;
    }
    return false;
}

int main()
{
    int papir[3][3];
    bool oznaceniPapir[3][3];
    for (int i=0; i<3; i++)
    {
        for (int j=0; j<3; j++)
        {
            cin >> papir[i][j];
            oznaceniPapir[i][j] = false;
        }
    }
    int n;
    cin >> n;
    for (int k=0; k<n; k++)
    {
        int temp;
        cin >> temp;
        for (int i = 0; i<3; i++)
        {
            for (int j = 0; j<3; j++)
            {
                if(papir[i][j] == temp)
                {
                    oznaceniPapir[i][j] = true;
                }
            }
        }
    }
    if (nadjiBingo(oznaceniPapir))
    {
        cout << "Yes" << "\n";
    }
    else
    {
        cout << "No" << "\n";
    }
    return 0;
}


Measured memory_bytes: 256
def read_int():
    return int(input().strip())


def read_ints():
    return list(map(int, input().strip().split(' ')))


def solve():
    '''
    dreamer
      dream
     eraser
      erase
    '''
    strings = ['dreamer', 'dream', 'eraser', 'erase']
    for i in range(len(strings)):
        strings[i] = ''.join(reversed(strings[i]))
    S = input().strip()
    S = ''.join(reversed(S))
    i = 0
    while i < len(S):
        found_string = None
        for string in strings:
            if S[i:].startswith(string):
                found_string = string
                break
        if found_string is None:
            return 'NO'
        i += len(found_string)
    return 'YES'


if __name__ == '__main__':
    print(solve())


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

const int MAXN = 5e5+20; 

struct Qry 
{ 
	int l, r, idx; 
}; 

bool comp(Qry x, Qry y) 
{ 
	return x.r < y.r; 
} 

void change(int idx, int val, int bit[], int n) 
{ 
	for (; idx <= n; idx += idx&-idx) 
		bit[idx] += val; 
} 

int read(int idx, int bit[], int n) 
{ 
	int sum = 0; 
	for (; idx>0; idx-=idx&-idx) 
		sum += bit[idx]; 
	return sum; 
} 

void process(int arr[], int n, Qry queries[], int q) 
{ 
	int lastv[MAXN]; 
	memset(lastv, -1, sizeof(lastv)); 

	int bit[n+1]; 
	memset(bit, 0, sizeof(bit)); 

	int ans[q]; 
	int qc = 0; 
	for (int i=0; i<n; i++) 
	{ 
		if (lastv[arr[i]] !=-1) 
			change (lastv[arr[i]] + 1, -1, bit, n); 
		lastv[arr[i]] = i; 
		change(i + 1, 1, bit, n); 
		while (qc < q && queries[qc].r == i) 
		{ 
			ans[queries[qc].idx] = read(queries[qc].r + 1, bit, n)- read(queries[qc].l, bit, n); 
			qc++; 
		} 
	} 
	for (int i=0; i<q; i++) 
		cout << ans[i] << endl; 
} 

int main() 
{ 
	int n,q;
	cin>>n>>q;
	int arr[n];
	for(int i=0;i<n;i++){
		cin>>arr[i];
	}
	Qry queries[q];
	int l,r,ind;
	for(int i=0;i<q;i++){
		cin>>l>>r;
		l--;r--;
		queries[i]={l,r,i};
	}
	sort(queries, queries+q, comp); 
	process(arr, n, queries, q); 
	return 0; 
} 


Measured memory_bytes: 17424
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
ll f(int x, vector<ll> a) {
    ll sum = 0, cost = 0;
    for (int i = 0; i < a.size(); i++) {
        sum += a[i];
        if (i % 2 == x) {
            if (sum <= 0) {
                cost += 1 - sum;
                sum = 1;
            }
        }
        else {
            if (sum >= 0) {
                cost += 1 + sum;
                sum = -1;
            }
        }
    }
    return cost;
}
/* main */
int main(){
    int N;
    cin >> N;
    vector<ll> a(N);
    for (int i = 0; i < N; i++) cin >> a[i];


    cout << min(f(0, a), f(1, a)) << '\n';
}


Measured memory_bytes: 2560
import java.util.Scanner;

public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    final int A = sc.nextInt();
    final int B = sc.nextInt();
    final int H = sc.nextInt();
    final int M = sc.nextInt();
    sc.close();
    double rad = Math.toRadians((60*H + M)* 0.5 - M*6);
    double ans = Math.sqrt(Math.pow(A, 2.0) + Math.pow(B, 2.0) - 2*A*B*Math.cos(rad));
    System.out.println(ans);
  }
}

Measured memory_bytes: 36108
# coding: utf-8
# Your code here!

n = int(input())
p = list(map(int,input().split()))

c = 0

for i in range(n-2):
    c += min(p[i:i+3]) != p[i+1] and max(p[i:i+3]) != p[i+1]
    
print(c)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_(i, n, m) for (int i = n; i < (int)(m); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define stoi stoll
//#define _GLIBCXX_DEBUG

signed main() {
  int D; cin >> D;
  vector<int> c(26);
  rep(i, 26) cin >> c[i];
  vector<vector<int>> s(D, vector<int>(26));
  rep(i, D) rep(j, 26) cin >> s[i][j];
  vector<int> t(D);
  rep(i, D) {
    cin >> t[i];
    t[i]--;
  }
  
  int score = 0;
  vector<int> lt(26, -1);
  rep(i, D) {
    score += s[i][t[i]];
    lt[t[i]] = i;
    rep(j, 26) score -= c[j]*(i-lt[j]);
    cout << score << endl;
  }
    

}

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

int main() {
	int n;
	cin >> n;
	bool r = false;

	for(int i=0; i<3; i++) {
		if(n % 10 == 7) {
			r = true;
			break;
		}
		n /= 10;
	}

	if(r) {
		cout << "Yes" << '\n';
	} else {
		cout << "No" << '\n';
	}

    return 0;
}


Measured memory_bytes: 3624
#include<queue>
#include<stack>
#include<math.h>
#include<cmath>
#include<bitset>
#include<stdio.h>
#include<string>
#include<map>
#include<algorithm>
#include<vector>
#include<iostream>
#include<utility>
#include<functional>
#include<deque>
#include<list>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  int n,p[30],i;
  cin >> n;
  for(i=0;i<n;i++){
    cin >> p[i];
  }
  int ans=0;
  for(i=1;i<n-1;i++){
    vector<int> x;
    x.push_back(p[i]);
    x.push_back(p[i+1]);
    x.push_back(p[i-1]);
    sort(x.begin(),x.end());
    if(x[1]==p[i]){
      ans++;
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3592
#include<stdio.h>
 
void visit(int);
int dequeue(void);
void enqueue(int);
 
int map[101][101];
int Q[101],n,head=0,tail=0,color[101],d[101];
int main()
{
  int i,j,v,vv,m,u,k;
 
  scanf("%d",&n);
  for(i=0;i<n;i++){
    color[i]=0;
    for(j=0;j<n;j++){
      map[i][j]=0;
    }
  }
  for(i=0;i<n;i++){
    scanf("%d%d",&v,&m);
    for(j=0;j<m;j++){
      scanf("%d",&vv);
      map[v-1][vv-1]=1;
    }
  }
 
  for(j=0;j<n;j++){
    if(map[0][j]==1){
      color[j]=0;
    }
  }
  color[0]=1;
  d[0]=0;
  enqueue(0);
  while(head!=tail){
    u=dequeue();
    for(k=0;k<n;k++){
      if(map[u][k]==1 && color[k]==0){
    color[k]=1;
    d[k]=d[u]+1;
    enqueue(k);
      }
      color[u]=2;
    }
  }
   
 
   
  for(i=0;i<n;i++){
    if(color[i]==2)printf("%d %d\n",i+1,d[i]);
    else printf("%d -1\n",i+1);
  }
  return 0;
}
 
int dequeue()
{
  int x;
  x=Q[head];
  if(head+1==100)head=0;
  else head=head+1;
  return x;
}
 
void enqueue(int x)
{
  Q[tail]=x;
  if(tail+1==100)tail=0;
  else tail=tail+1;
}



Measured memory_bytes: 2060
import java.util.*;

public class Main {
    public static void main(String[] args) {
        //コード
        Scanner scanner = new Scanner(System.in);
        Integer N = Integer.parseInt(scanner.next());
        List<String> S = new ArrayList<>();
        Map<String, Integer> R = new HashMap<String, Integer>();


        for (int i = 0; i < N; i++) {
            S.add(scanner.next());
        }

        for (String temp : S) {
            Integer count = R.get(temp);
            R.put(temp, (count == null) ? 1 : count + 1);
        }

        System.out.println(R.size());
    }
}


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



int main() {
  const int MOD = 1e9 + 7;
  int n; cin >> n;
  vector<int> A(n);
  for (int i = 0; i < n; ++i) cin >> A[i];
  A.resize(unique(A.begin(), A.end()) - A.begin());
  n = A.size();
  vector<long long> dp(n + 1), color(2.1e5);
  dp[0] = 1;
  for (int i = 1; i <= n; ++i) {
    dp[i] = (dp[i - 1] + color[A[i - 1]]) % MOD;
    (color[A[i - 1]] += dp[i - 1]) %= MOD;
  }
  cout << dp[n] << '\n';
}


Measured memory_bytes: 4224
import java.util.*;
public class Main{
    public static void main(String[] args){
	Scanner scan = new Scanner(System.in);
	int n,m;

	String str;

	List<Integer> list = new LinkedList<Integer>();

	while(scan.hasNext()){
	    n = scan.nextInt();
	    m = scan.nextInt();
	    str = String.valueOf(n+m);
 	    list.add(str.length());
 	}

	for(Iterator<Integer> it = list.iterator(); it.hasNext();){
	    System.out.println(it.next());
	}
     }
 }

Measured memory_bytes: 26444
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;
 
 
template<typename T>
struct SegmentTree{
private:
    int n;
    T E;
    vector<T> node;
    inline void updatef(T& x,T& y){
        x = y;
        //x += y;
        //x = max(x,y);
        //x = min(x,y);
    }
    inline T queryf(T& x,T& y){
        //return x*y;
        //return x+y;
        //return max(x,y);
        return min(x,y);
    }
 
public:
    SegmentTree(int sz,T E_):E(E_){
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
    }
 
    SegmentTree(vector<T>& A,T E_):E(E_){
        int sz=A.size();
        n=1;
        while(n<sz)n<<=1;
        node.resize(2*n-1,E);
        rep(i,sz)node[i+n-1]=A[i];
        for(int i=n-2;i>=0;--i){
            node[i]=queryf(node[2*i+1], node[2*i+2]);
        }
    }
    void update(int k,T x){
        k+=n-1;
        updatef(node[k],x);
        while(k>0){
            k=(k-1)/2;
            node[k]=queryf(node[2*k+1], node[2*k+2]);
        }
    }
       //[a,b)での和を返す
    T get(int a,int b,int k=0,int l=0,int r=-1){
        if(r<0)r=n;
        if(r<=a||b<=l)return E;
        if(a<=l&&r<=b)return node[k];
        T xl=get(a,b,2*k+1,l,(l+r)/2);
        T xr=get(a,b,2*k+2,(l+r)/2,r);
        return queryf(xl, xr);
    }
};
 
 
struct UnionFind{
   vector<int> par;
   UnionFind(int n):par(n,-1){}
   int find(int x){
       if(par[x]<0)return x;
       return par[x]=find(par[x]);
   }
   bool unite(int x,int y){
       x=find(x);
       y=find(y);
       if(x==y)return false;
        par[x]+=par[y];
        par[y]=x;
       return true;
   }
 
   bool same(int x,int y){
       return find(x)==find(y);
   }
   int size(int x){
       return -par[find(x)];
   }
};
int main(){
    int n,k;
    cin>>n>>k;
    SegmentTree<int> sg(2*n, inf),sg2(2*n,inf);
    int a[n];
    rep(i,n){
        cin>>a[i];
        sg.update(i,a[i]);
        sg2.update(i,-a[i]);
    }
    UnionFind uf(n+1);
    REP(i,1,n-k+1){
        if(sg.get(i-1,i+k-1)==a[i-1]&&sg2.get(i,i+k)==-a[k+i-1]){
            uf.unite(i-1,i);
        }
    }
    vector<int> sum(n);
    rep(i,n-1){
        sum[i+1]=(a[i]>a[i+1]);
    }
    rep(i,n)sum[i+1]+=sum[i];
    rep(i,n-k+1){
        if(sum[i]==sum[i+k-1])uf.unite(i,n);
    }
    int ans = 0;
    rep(i,n-k+1){
        if(uf.find(i)==i)++ans;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 10880
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>

using namespace std;

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

ll mod = 1e9 + 7;


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

	for(int i=0;i<s.length();i+=2){
		if(s[i]!='R'&&s[i]!='U'&&s[i]!='D'){
			cout << "No" << endl;
			return 0;
		}
	}

	for(int i=1;i<s.length();i+=2){
		if(s[i]!='L'&&s[i]!='U'&&s[i]!='D'){
			cout << "No" << endl;
			return 0;
		}
	}

	cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 256
#include<iostream>

using namespace std;

int main(){
	int n, m, l, in;
	int a[100][100]={0}, b[100][100]={0};
	long c[100][100]={0};
	
	cin >> n >> m >> l;
	
	/*??????A??\???*/
	for (int i = 0; i < n; i++){
		for (int j = 0; j < m; j++){
			cin >> in;
			a[i][j] = in; 
		}
	}
	/*??????B??\???*/
	for (int i = 0; i < m; i++){
		for (int j = 0; j < l; j++){
			cin >> in;
			b[i][j] = in;
		}
	}
	
	/*??????C?¨????*/
	for (int i = 0; i < n; i++){
		for (int j = 0; j < l; j++){
			for (int k = 0; k < m; k++){
				c[i][j] += a[i][k] * b[k][j];
			}
		}
	}
	
	/*??????C??????*/
	for (int i = 0; i < n; i++){
		for (int j = 0; j < l-1; j++){
			cout << c[i][j] << " ";
		}
		cout << c[i][l-1] << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1324
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
	static void Main()
	{
		string[] input = Console.ReadLine().Split(' ');
		long n = long.Parse(input[0]);
		long q = long.Parse(input[1]);
    long[] nums = new long[400*400];
    long[] numSetsMin = new long[400];//400*400に分割
    long minMemo = long.MaxValue;

    for(long i = 0; i < 400*400; i++)
    {
      nums[i] = 2147483647;//初期化
    }
    for(long i = 0; i < 400; i++)
    {
      numSetsMin[i] = 2147483647;//初期化
    } 

    for(long question = 0; question < q; question++)
    {
      string[] inputq = Console.ReadLine().Split(' ');
      long howNum = long.Parse(inputq[0]);
      long leftNum = long.Parse(inputq[1]);
      long rightNum = long.Parse(inputq[2]);
      if(howNum == 0)//書き換え
      {
        nums[leftNum] = rightNum;
        long numPosition = WherePosition(leftNum);//どの分類に属するか
        numSetsMin[numPosition] = long.MaxValue;//書き換えで最小値が増加することもあるので再確認
        for(long i = 400*numPosition; i < 400*(numPosition+1); i++)
        {
          numSetsMin[numPosition] = Math.Min(numSetsMin[numPosition], nums[i]);
        }
      }
      if(howNum == 1)//最小値を求める
      {
        minMemo = long.MaxValue;
        long leftPosition = WherePosition(leftNum);
        long rightPosition = WherePosition(rightNum);

        if(leftPosition == rightPosition)
        {
          for(long i = leftNum; i <= rightNum; i++)//左右が同じ分類のとき
          {
            minMemo = Math.Min(minMemo, nums[i]);
          }
        }else
        {
          for(long i = leftNum; i < 400*(leftPosition+1); i++)//左区間内（左端より右だけ見る）
          {
            minMemo = Math.Min(minMemo, nums[i]);
          }
          for(long i = 400*rightPosition; i <= rightNum; i++)//右区間内
          {
            minMemo = Math.Min(minMemo, nums[i]);
          }
          for(long i = leftPosition+1; i < rightPosition; i++)//見ていない区間内
          {
            minMemo = Math.Min(minMemo, numSetsMin[i]);
          }
        }
        Console.WriteLine(minMemo);
      }
    }
	}

  static long WherePosition(long num)//左から何番目の分類に属するか
  {
    return num / 400;
  }
  
}


Measured memory_bytes: 22000
#include <iostream>

using namespace std;

int main() {
    int n, m;

    cin >> n >> m;

    if (n-m > 1 || m-n > 1) {
        cout << 0 << endl;
        return 0;
    }

    long long ans = 1;
    if(n == m)  ans = 2;

    for (int i=2; i<=n; i++) {
        ans *= (long long)i;
        if (ans > (long long)1000000007)   ans %= (unsigned long long)1000000007;
    }
    for (int i=1; i<=m; i++) {
        ans *= (long long)i;
        if (ans > (long long)1000000007)   ans %= (unsigned long long)1000000007;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define sz(v)   ((int)(v).size())
#define  all(v)    ((v).begin()),((v).end())
#define  allr(v)    ((v).rbegin()),((v).rend())
#define   pb         push_back
#define   mp         make_pair
#define    clr(v,d)      memset( v, d ,sizeof(v))
typedef  long long     ll ;
using namespace std;
void GO(){ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);}
const int N=1009;
ll a[N];
int main(){
    GO();
    int n;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    double dw=0;
    for(int i=0;i<n;i++){
        dw+= 1.0/a[i];
    }
    cout<<fixed<<setprecision(5)<<1.0/dw<<endl;
}


Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>

using namespace std;
using ll = long long;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  Vi N(4);
  VIN(N)
  SORT(N);
  YES(N[0]==1 && N[1]==4 && N[2]==7 && N[3]==9);
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <cstring>
#include <algorithm> // sort
#include <math.h> // sort

#define REP(i, n) for (long long i = 0; i < (n); i++) 
typedef long long ll;
static const ll MOD = 1000000007;
static const ll INF = 1000000000000000000LL;
using namespace std;

int main(){
    //std::ifstream in("input.txt");
    //std::cin.rdbuf(in.rdbuf());
    string s;
    cin >> s;
    ll res = 0;
 
    REP(i,3)
    {
        if(s[i] == '1')++res;
    }

    cout <<res << endl;


    return 0;    

}



Measured memory_bytes: 256
#include<iostream>
using namespace std;
#define int long long
int gcd(int n,int m){return m?gcd(m,n%m):n;}
int lcm(int n,int m){return n*(m/gcd(n,m));}
signed main(){
    int N,ans,T;cin>>N>>ans;
    for(int i=1;i<N;++i)cin>>T,ans=lcm(ans,T);
    cout<<ans<<endl;
}

Measured memory_bytes: 256
import string

alph_list=list(string.ascii_lowercase)
mydict=dict(zip(alph_list,list(range(26))))
N, L=map(int,input().split())

def compare_str(s,t):
    for i in range(L):
        if mydict[s[i]]<mydict[t[i]]:
            return '<'
        elif mydict[s[i]]>mydict[t[i]]:
            return '>'
    return '='

def newlist(w,lst):
    l=len(lst)
    pos=0
    if l==0:
        return [w]
    while l>0:
        ineq=compare_str(lst[pos+l//2],w)
        if ineq=='<' or ineq=='=':
            pos=pos+l//2+1
            l=(l-1)//2
        else:
            l=l//2
    return lst[:pos] + [w] + lst[pos:]

mylist=[]
for _ in range(N):
    mylist=newlist(input(),mylist)

print(''.join(mylist))


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

// why am I so weak

int n, c, k;
int t[100055];

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

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

	sort(t, t + n);

	int res = 0, away = -1, have = 0;

	for (int i = 0; i < n; i++) {
		if (have == c || away < t[i]) {
			res++, away = t[i] + k;
			have = 1;
		} else {
			have++;
		}
	}

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

	return 0;
}


Measured memory_bytes: 640
#if 1
#include <iostream>
#include <fstream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <queue>
#include <stack>
#include <array>
#include <deque>
#include <algorithm>
#include <utility>
#include <cstdint>
#include <functional>
#include <iomanip>
#include <numeric>

#define in std::cin
#define out std::cout

int32_t N,L;
int32_t a_[1000100];
int32_t* a = (a_+10);

int main()
{
	using std::endl;
	in.sync_with_stdio(false);
	out.sync_with_stdio(false);

	in >> N>> L;
	for (int32_t i = 0; i < N; ++i)
	{
		in >> a[i];
	}
	a[-2] = 0;
	a[-1] = 0;
	a[N] = 0;
	a[N+1] = 0;
	std::priority_queue<std::pair<int64_t, int32_t>,std::vector<std::pair<int64_t, int32_t>>,std::greater<std::pair<int64_t, int32_t>>> queue;
	for (int32_t i = 0; i < N; ++i)
	{
		if (a[i - 1] < a[i] && a[i + 1] < a[i]) {
			queue.emplace(L - a[i], i);
		}
	}
	int64_t time_now = 0;
	while (!queue.empty())
	{
		auto v = queue.top(); queue.pop();
		time_now = v.first;
		a[v.second] = 0;
		auto i = v.second - 1;
		if (a[i - 1] < a[i] && a[i + 1] < a[i]) {
			queue.emplace(time_now + (L - a[i]), i);
		}
		i = v.second + 1;
		if (a[i - 1] < a[i] && a[i + 1] < a[i]) {
			queue.emplace(time_now + (L - a[i]), i);
		}
	}
	std::cout << time_now << std::endl;
	return 0;
}
#endif

Measured memory_bytes: 4232
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rrep(i,a,b) for(int i=(int)(a);i>=(int)(b);--i)
#define fore(i,a) for(auto &i:a)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define isin(i,a,b) ((a) <= (i) && (i) < (b))
#define uni(a) (a).erase(unique(all(a)),(a).end())
#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll  = long long;
using unit= unsigned;
using ull = unsigned long long;
using P   = pair<int,int>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vvi = vector<vi>;
using vp  = vector<P>;
void _main(); int main(){ cin.tie(0); ios::sync_with_stdio(false); _main(); }
template<class T>void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T>void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T>void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T>void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T>bool chmax(T &a, const T &b){ if (a<b){ a = b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if (b<a){ a = b; return 1; } return 0; }
template<class T>T gcd(T a, T b){ if (b==0){ return a; }else{ return gcd(b, a%b); }}
template<class T>T lcm(T a, T b){ return a / gcd(a, b) * b; }
constexpr double eps = 1e-10;
constexpr int inf = INT_MAX / 2;
constexpr ll infl = 1LL << 60;

void _main() {
  int H, W;
  cin >> H >> W;
  v(string) s(H);
  rep(i, 0, H) cin >> s[i];
  vvi cnt(H, vi(W));

  rep(i, 0, H) {
    vi done(W);
    rep(j, 0, W) {
      if (s[i][j] == '#') continue;
      if (done[j]) continue;
      int l = 0;
      while (j+l < W) {
        if (s[i][j+l] == '#') break;
        ++l;
      }
      rep(k, 0, l) {
        cnt[i][j+k] += l;
        done[j+k] = 1;
      }
    }
  }

  rep(j, 0, W) {
    vi done(H);
    rep(i, 0, H) {
      if (s[i][j] == '#') continue;
      if (done[i]) continue;
      int l = 0;
      while (i+l < H) {
        if (s[i+l][j] == '#') break;
        ++l;
      }
      rep(k, 0, l) {
        cnt[i+k][j] += l;
        done[i+k] = 1;
      }
    }
  }

  int ans = 0;
  rep(i, 0, H) rep(j, 0, W) chmax(ans, cnt[i][j]-1);
  cout << ans << endl;
}

Measured memory_bytes: 20224
#include <bits/stdc++.h>
#define IO_OP std::ios::sync_with_stdio(0); std::cin.tie(0);
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define EB emplace_back

using namespace std;

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

const int INF = 1e9 + 7;

int ok[1000004], a[15][15];

int main()
{
	IO_OP;
	
	for(int i=0;i<1000;i++)
		ok[i*i] = 1;
	int n, d;
	cin >> n >> d;
	for(int i=0;i<n;i++)
		for(int j=0;j<d;j++)
			cin >> a[i][j];
	int ans = 0;
	for(int i=0;i<n;i++) {
		for(int j=0;j<i;j++) {
			int s = 0;
			for(int k=0;k<d;k++)
				s += (a[i][k] - a[j][k]) * (a[i][k] - a[j][k]);
			if(ok[s])
				ans++;
		}
	}
	cout << ans << endl;
}



Measured memory_bytes: 3200
#include<stdio.h>
#include<math.h>
int main(void)
{
    int i, j, k, n, x[100], y[100], z[100];
    double L1=0.0, L2=0.0, L3=0.0, Li=0.0;
     
    scanf("%d", &n);
     
    for(i=0; i<n; i++)
	{
        scanf("%d", &x[i]);
    }
    
	for(i=0; i<n; i++)
	{
        scanf("%d", &y[i]);
    }
     
    for(i=0; i<n; i++)
	{
        L1 += abs(x[i]-y[i]);
        L2 += (x[i]-y[i])*(x[i]-y[i]);
        L3 += abs((x[i]-y[i])*(x[i]-y[i])*(x[i]-y[i]));
        z[i] = abs(x[i]-y[i]);
    }
     
    for(i=0; i<n; i++)
	{
        if(z[i] >= Li) Li = z[i]*1.0;
    }
     
    L2 = sqrt(L2);
    L3 = pow(L3, 1.0 / 3.0);
     
    printf("%f\n%f\n%f\n%f\n", L1, L2, L3, Li);
     
	return 0;

}

Measured memory_bytes: 676
#include<bits/stdc++.h>
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
using namespace std;
#define rep(i,x) for(ll i = 0; i < (ll)(x); i++)
#define rrep(i,x) for(ll i = (ll)(x)-1;i <= 0; i--)
#define reps(i,x) for(ll i = 1; i < (ll)(x); i++)
#define rreps(i,x) for(ll i = (ll)(x)-1; i <= 1; i--)
#define debug(x) cerr << #x << ": " << (x) << "\n";
#define all(x) (x).begin(), (x).end()
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<ll>>> vvvl;
const ll INF = numeric_limits<ll>::max()/4;
const int n_max = 1010;

void print() {
    cout << endl;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    cout << head;
    if (sizeof...(tail) != 0) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
void print(vector<T> &vec) {
    for (auto& a : vec) {
        cout << a;
        if (&a != &vec.back()) cout << ' ';
    }
    cout << endl;
}

template <class T>
void print(vector<vector<T>> &df) {
    for (auto& vec : df) {
        print(vec);
    }
}

template<class T, class U>
void print(pair<T,U> &p){
    print(p.first, p.second);
}

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


int main(){
    ll n,m; cin >> n >> m;
    vector<vector<ll>> graph(n), rev(n);
    vector<Pll> edge(m);
    rep(i,m){
        ll a,b; cin >> a >> b;
        a--;b--;
        graph[a].emplace_back(b);
        rev[b].emplace_back(a);
        edge[i] = {a, b};
    }
    vector<ll> path, clear;
    auto check = [&](ll s, ll g) -> bool{
        bool ret = false;
        vector<ll> moved(n,0);
        queue<ll> que;
        que.push(s);
        moved[s] = 1;
        while(!que.empty()) {
            ll t = que.front();que.pop();
            if(t == g){
                ret = true;
                break;
            }
            for(auto to : graph[t]){
                if(moved[to] == 0){
                    moved[to] = moved[t] + 1;
                    que.push(to);
                }
            }
        }
        // debug(s);debug(g);
        // print(moved);
        if(!ret)return ret;
        ll pos = g;
        path.emplace_back(g);
        while(pos != s) {
            for(auto to : rev[pos]){
                if(moved[to] == moved[pos] - 1){
                    path.emplace_back(to);
                    pos = to;
                    break;
                }
            }
        }
        return ret;
    };

    using Pv = pair<ll, vector<ll>>;
    Pv res = make_pair(INF, path);

    rep(i,m){
        ll s = edge[i].first, t = edge[i].second;
        path = clear;
        if(check(t,s)){
            Pv p = {path.size(), path};
            chmin(res, p);
        }
    }



    if(res.first == INF)cout << -1 << endl;
    else{
        cout << res.first << "\n";
        for(auto i : res.second)cout << i+1 << "\n";
    }
    return 0;
}

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

int main(void) {
	int H1, M1, H2, M2, K;
	cin >> H1 >> M1 >> H2 >> M2 >> K;

	int ans = (H2 * 60 + M2) - (H1 * 60 + M1) - K;

	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 3620
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] input = new int[n];
        for (int i = 0; i < n; i++) {
            input[i] = sc.nextInt();
        }

        System.out.print(input[n - 1]);
        for (int i = n - 2; i >= 0; i--) {
            System.out.print(" " + input[i]);
        }
        System.out.println();
    }
}



Measured memory_bytes: 26172
n = input()
n = int(n)
l = []

for i in range(1, n+1):
    if i % 3 == 0:
        l.append(i)
    else:
        j = i
        while j > 0:
            if j % 10 == 3:
                l.append(i)
                break
            else:
                j //= 10

for p in l:
    print(" " + str(p), end="")
print()
     


Measured memory_bytes: 6104
#include <iostream>
#include <string>
#include <vector>
#include <cmath>
#include <deque>
#include <queue>//for queue and priority_queue
#include <fstream>
#include <iomanip>
#include <stack>
#include <algorithm>
#include <set>
#include <map>
#include <list>
#define endl "\n"
typedef long long ll;
using namespace std;
void Lancer() { ios::sync_with_stdio(0); cin.tie(0); cout.tie(0); }
bool isPrime(ll n){
	if (n == 2 || n == 3 || n == 5)
		return true;
	else if (n % 2 == 0 || n % 3 == 0 || n % 5 == 0 || n == 1)
		return false;
	else {
		for (int i = 5; i <= sqrt(n); i += 2){
			if (n%i == 0)
				return false;
		}
		return true;
	}
}

int frq[123],ind[113];
int main(){
	Lancer();
	ll n, k, sum = 0, b,crd;
	cin >> n >> k;
	while (n--)
	{
		cin >> crd;
		b = k - crd;
		sum += (min(crd, b)*2);
	}
	cout << sum;
	cout << endl;
	return 0;
}


Measured memory_bytes: 3588
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
    cin.tie(0); ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int H, W, K; 
  cin >> H >> W >> K;

  vector<string> s(H);
  REP(i, H) cin >> s[i];

  vector<vector<int>> ans(H+1, vector<int>(W+1, 0));

  int p = 1;
  int end = 0;
  vector<bool> empty(H, false);
  REP(i, H){
    int cnt = 0;
    bool flag = false;
    REP(j, W){
      if(s[i][j] == '#'){
        cnt++;
        flag = true;
      }
    }
    if(!flag){
      empty[i] = true;
      continue;
    }
    end = i;

    REP(j, W){
      ans[i][j] = p;
      if(s[i][j] == '#'){
        if(--cnt != 0) p++;
      }
    }
    p++;
  }

  REP(k, H){
    RREP(i, end){
      if(!empty[i]) continue;
      REP(j, W) ans[i][j] = ans[i+1][j];
    }
    FOR(i, end, H){
      if(!empty[i]) continue;
      REP(j, W) ans[i][j] = ans[i-1][j];
    }
  }

  REP(i, H){
    REP(j, W){
      cout << ans[i][j]; SPBR(j, W);
    }
  }

  return 0;
}

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

int main() {
  int N, T, c, t, ans = 1e9;
  cin >> N >> T;

  for (int i = 0; i < N; i++) {
    cin >> c >> t;
    if (t <= T) ans = min(ans, c);
  }

  if (ans == 1e9) cout << "TLE" << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define WHOLE(v) (v).begin(), (v).end()
#define REV_WHOLE(v) (v).rbegin(), (v).rend()
using i64 = int64_t;
using namespace std;
template <size_t I, class H, class... T> struct TupleReaderWriter{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple_cat(tuple<H>(v),TupleReaderWriter<sizeof...(T)-1,T...>::r(i));}static void w(ostream&o,tuple<H,T...>&t,string d){TupleReaderWriter<I-1,H,T...>::w(o,t,d);o<<d<<get<I>(t);}};
template <class H, class... T> struct TupleReaderWriter<0,H,T...>{static tuple<H,T...> r(istream&i){H v;i>>v;return tuple<H>(v);}static void w(ostream&o,tuple<H,T...>&t,string d){o<<get<0>(t);}};
template<class T>istream&operator>>(istream&i,vector<T>&v){for(auto&x:v)i>>x;return i;}
template<class T>ostream&operator<<(ostream&o,vector<T>&v){string delim="";for(auto&x:v)o<<delim<<x,delim=" ";return o;}
template <class... T> istream& operator>>(istream&i,tuple<T...>& t) { t = TupleReaderWriter<sizeof...(T), T...>::r(i); return i; }
template <class... T> ostream& operator<<(ostream& o, tuple<T...>& t) { string delim = " "; TupleReaderWriter<sizeof...(T) - 1, T...>::w(o, t, delim); return o; }
template<typename T> using rev_priority_queue = priority_queue<T, vector<T>, greater<T>>;
template<typename T> using vector2d = vector<vector<T>>;
void R_YESNO(bool p) { cout << (p ? "YES" : "NO") << endl; }
void R_YesNo(bool p) { cout << (p ? "Yes" : "No") << endl; }
int main() {
    const i64 INF = 1e16;
    i64 N, S;
    cin >> N >> S;
    i64 sq = ceil(sqrt(N)) + 10;
    auto f = [](i64 b, i64 n) -> i64 {
        i64 ret = 0;
        while(n) {
            ret += n % b;
            n /= b;
        }
        return ret;
    };
    i64 ans = INF;
    if(N == S) ans = min(ans, N + 1);
    for(i64 b = 2; b <= sq; b++) {
        if(f(b, N) == S) ans = min(ans, b);
    }
    for(i64 p = 1; p <= sq; p++) {
        if((N - S) % p != 0) continue;
        i64 b = (N - S) / p + 1;
        if(b >= 2 && f(b, N) == S) ans = min(ans, b);
    }
    if(ans == INF) ans = -1;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 505


int N;
int price[4],num[4];
int dp[NUM];

int main(){

	scanf("%d",&N);

	for(int i = 0; i < 4; i++){

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

		scanf("%d",&num[i]);
	}

	dp[0] = 0;
	for(int i = 1; i < NUM; i++){

		dp[i] = BIG_NUM;
	}

	for(int i = 0; i < 4; i++){
		for(int k = num[i]; k < NUM; k++){
			if(dp[k-num[i]] == BIG_NUM)continue;

			dp[k] = min(dp[k],dp[k-num[i]]+price[i]);
		}
	}

	for(int i = NUM-2; i >= 0; i--){

		dp[i] = min(dp[i],dp[i+1]);
	}

	printf("%d\n",dp[N]);

	return 0;
}



Measured memory_bytes: 3232
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
#include<math.h>
#include<limits.h>
#include<iostream>
#include<string>
#include<vector>
#include<stdio.h>
#include<sstream>
#include<list>
#include<queue>
#include<algorithm>
#include<functional>
#include<map>
#include<set>
#include<utility>
#include<initializer_list>
#include<tuple>
#include<regex>
using namespace std;
#define ull unsigned long long
#define ll long long
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(t) t.begin(), t.end()
#define mat(type, row, col, init) vector<vector<type>>(row, vector<type>(col, init));
int md(int a, int b, int c, int d) {
	return abs(a - c) + abs(b - d);
}
int main() {
	int w, a, b;
	cin >> w >> a >> b;
	if (abs(b - a) <= w) {
		cout << 0;
		return 0;
	}
	int ans = min(abs(b - (a + w)), abs(a - (b + w)));
	cout << ans;
	return 0;
}




Measured memory_bytes: 256
/* ****mittal21**** */
#include<bits/stdc++.h>
#define ll          long long int 
#define ld          long double
#define pb          push_back
#define endl        '\n'
#define pii         pair<long long int,long long int>
#define vi          vector<ll>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (ll )x.size()
#define hell        1000000007
#define jell        998244353
#define rep(i,a,b)    for(ll int i=a;i<b;i++)
#define repr(i,a,b)   for(ll int i=a;i>=b;i--)
#define lbnd    lower_bound
#define ubnd        upper_bound
#define mp          make_pair
#define DEC(N)  cout << std::fixed; cout << setprecision(N);
using namespace std;
#define N  100005
ll dp[105][N];
void solve()
{
   ll n,k;
   cin>>n>>k;
   ll a[n+3];
   for(int i=1;i<=n;i++)
   {
    cin>>a[i];
   }
   dp[0][0]=1;
   for(int i=1;i<=a[1];i++)
      dp[1][i]=1;
    dp[1][0]=1;
   for(int i=2;i<=n;i++)
   {   
       for(int j=1;j<=k;j++)
       {
          dp[i-1][j]=(dp[i-1][j]+dp[i-1][j-1])%hell;
       }
       for(int j=0;j<=k;j++)
       {
           if(j-a[i]-1<0)
              dp[i][j]=(dp[i-1][j])%hell;
           else
              dp[i][j]=(dp[i-1][j]-dp[i-1][j-a[i]-1]+hell)%hell;
       }
   }
  // cout<<dp[1][8]-dp[1][3];
   cout<<dp[n][k]<<endl;
   return;
}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    ll testcase=1;
    //cin>>testcase;
    while(testcase--)
    {
        solve();
    }
    return 0;
}

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

int main()
{
  int n,a,b;
  cin>>n>>a>>b;
  
  string s;
  cin>>s;
  
  int confirmed=0;
  int overseas=1;
  for(int i=0;i<n;i++){
    if(s.at(i)=='c')
      cout<<"No"<<endl;
    else if(s.at(i)=='a'){
      if(confirmed<a+b){
        cout<<"Yes"<<endl;
        confirmed++;
      }
      else
        cout<<"No"<<endl;
    }else{// 'b'
      if(confirmed<a+b && overseas<=b){
        cout<<"Yes"<<endl;
        confirmed++;
        overseas++;
      }else
        cout<<"No"<<endl;  
  }
  }
    return 0;
  }

Measured memory_bytes: 896
import java.util.*;public class Main{public static void main(String[] args){Scanner s=new Scanner(System.in);String a,d=new String(),b=new String();int x=0,y=0,i=0;Hashtable<String,Integer> h=new Hashtable<String,Integer>();while(s.hasNext()){a=s.next();if(h.containsKey(a)){h.put(a,h.get(a)+1);}else{h.put(a,1);}}for(int o:h.values()){y++;if(x<o){x=o;i=y;}}for(String o:h.keySet()){i--;if(b.length()<o.length())b=o;if(i==0)d=o;}System.out.println(d+" "+b);}}

Measured memory_bytes: 12000
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll N, M;
ll cn = 0;

int main(){
  cin >> N >> M;

  if(N * 2 > M) cn += M / 2;  //Sを使い切れない
  else{
    cn += N;  //Sを使い切れる
    M -= N * 2;
    cn += M / 4;
  }

  cout << cn << endl;
  return 0;
}
    

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

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

#define sz(v) ((int) v.size())
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())

using namespace std;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    int n; cin >> n;
    vector<vector<double>> dp(n + 1, vector<double>(n + 1, 0));
    dp[0][0] = 1;
    FOR(i, 1, n) {
        double p; cin >> p;
        REP(j, i) {
            dp[i][j + 1] += dp[i - 1][j] * p;
            dp[i][j] += dp[i - 1][j] * (1 - p);
        }
    }
    double res = 0;
    FOR(i, n / 2 + 1, n) res += dp[n][i];
    cout << fixed << setprecision(15) << res << "\n";
    return 0;
}


Measured memory_bytes: 70656
import itertools
import functools

s = input()
nums = list(s)

add_table = list(itertools.product((1, 0), repeat=len(nums)-1))

sum = 0

for row in add_table:
    case = []
    for i, v in enumerate(nums):
        if i == 0 or row[i - 1] == 1:
            case.append(v)
        else:
            case[-1] += v

    sum += int(functools.reduce(lambda x, y: int(x) + int(y), case))

print(sum)


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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


int main()
{
    int A,B,C,D;
    cin >> A >> B >> C >> D;

    cout << max(A*B, C*D) << endl;
}


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

int main(){
    int n;
    cin >> n;
    int c0 = 0, c1 = 0, c2 = 0, c3 = 0;
    for(int i = 0; i < n; i++){
        string s;
        cin >> s;
        if (s == "AC")c0++;
        else if (s == "WA")c1++;
        else if (s == "TLE")c2++;
        else c3++;
    }
    cout << "AC x " << c0 << endl;
    cout << "WA x " << c1 << endl;
    cout << "TLE x " << c2 << endl;
    cout << "RE x " << c3 << endl;
    return 0;
}

Measured memory_bytes: 3624