akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <vector>
#include <string>
#include <cstring>
#include <math.h>
#include <cmath>
#include <limits.h>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <functional>
#include <stdio.h>
using namespace std;

long long MOD = 1000000007;

int K;
int dist[100000];

void bfs() {
    
    fill( dist, dist+100000, INT_MAX );
    dist[1] = 1;
    
    deque<int> dq;
    
    long long c;
    dq.push_front(1);
    
    while ( !dq.empty() ) {
        
        c = dq.front();
        dq.pop_front();
        
        if ( dist[(10*c)%K] > dist[c] ) {
            dist[(10*c)%K] = dist[c];
            dq.push_front( (10*c)%K );
        }
        if ( dist[(c+1)%K] > dist[c]+1 ) {
            dist[(c+1)%K] = dist[c]+1;
            dq.push_back( (c+1)%K );
        }
        
    }
    
}


int main() {
        
    cin >> K;
    bfs();
    
    cout << dist[0] << endl;
    
    return 0;
}

Measured memory_bytes: 820
n = gets.to_i
a = gets.split.map(&:to_i).sort.reverse

if a.length.odd?
    a << 0
    n += 1
end

ans1 = 0
ans2 = 0
(0..n/2-1).each{|i|
    ans1 += a[i*2]
    ans2 += a[i*2+1]
}

puts ans1 - ans2


Measured memory_bytes: 1788
n = int(input())
A = list(map(int, input().split()))

cum = [0]
for a in A:
    cum.append(cum[-1]+a)

ans = float('inf')
for i in range(n-1):
    s = cum[i+1]
    t = cum[-1] - s
    ans = min(ans, abs(s-t))

print(ans)

Measured memory_bytes: 100172
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      
      int X  =sc.nextInt();
       int Y  =sc.nextInt();
        int Z  =sc.nextInt();
        
        System.out.println(Z+" "+X+" "+Y);
    }
}

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

int main(){
  int x_1,y_1,x_2,y_2;
  cin >> x_1 >> y_1 >> x_2 >> y_2;

  cout << x_2 - y_2 + y_1 << " " << y_2 + x_2 - x_1 << " " << x_1 - y_2 +y_1 << " " << y_1 + x_2 - x_1 << endl;
}

Measured memory_bytes: 256
A,B,C,D,E,F = map(int,input().split())
mx =- 1
S = set()
W = set()

for a in range(0,F+1,100*A):
  for b in range(0,F+1-a,100*B):
    W.add(a+b)

for c in range(0,F+1,C):
  for d in range(0,F+1-c,D):
    S.add(c+d)

for w in W:
  for s in S:
    if 0<w+s<=F and s<=w*E//100:
      if mx<s/(w+s):
        ans=w+s,s
        mx=s/(w+s)

print(ans[0],ans[1])

Measured memory_bytes: 3188
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define pb push_back
#define COUT(x) cout << (x) << endl
#define COUTF(x) cout << setprecision(15) << (x) << endl
#define ENDL cout << endl
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#ifdef _DEBUG
#define debug(x) cout << "[debug] " << #x << ": " << x << endl
#else
#define debug(x)
#endif
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using P = pair<ll, ll>;
constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr double PI = 3.141592653589793238462643383279;
ll getDigit(ll x) {
  return x == 0 ? 1 : log10(x) + 1;
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

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

template <typename T>
void debugV(const vector<T> v) {
#ifdef _DEBUG
  rep(i, v.size()) {
    cout << i << ":" << v[i] << " ";
  }
  cout << endl;
#else
  (void)v;
#endif
}

signed main() {
  ll A, B, C, D, E;
  cin >> A >> B >> C >> D >> E;

  if (A == 0) {
    COUT(1);
  }
  if (B == 0) {
    COUT(2);
  }
  if (C == 0) {
    COUT(3);
  }
  if (D == 0) {
    COUT(4);
  }
  if (E == 0) {
    COUT(5);
  }
  return 0;
}

Measured memory_bytes: 3716
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
#define deb(x) cout<<#x<<" "<<x<<endl;
#define print(arr,n) for(int i=0;i<n;++i) { cout<<arr[i]<<" "; } cout<<endl;
#define ub(x,el) upper_bound(x.begin(),x.end(),el) - x.begin()
#define lb(x,el) lower_bound(x.begin(),x.end(),el) - x.begin();
#define bs(x,el) binary_search(x.begin(),x.end(),el)
#define MOD 1000000007
#define finish return 0
using namespace std;
using namespace __gnu_pbds; 
typedef long long int ll;
typedef tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set;
template<int D, typename T> struct Vec : public vector<Vec<D - 1, T>> { static_assert(D >= 1, "Vector dimension must be greater than zero!"); template<typename... Args> Vec(int n = 0, Args... args) : vector<Vec<D - 1, T>>(n, Vec<D - 1, T>(args...)) { }}; template<typename T> struct Vec<1, T> : public vector<T> { Vec(int n = 0, T val = T()) : vector<T>(n, val) { } };
inline ll mod(ll x) { return (x%MOD + MOD)%MOD; }
ll gcd(ll a, ll b, ll &x, ll &y){if(a == 0){x = 0, y = 1; return b;} ll x1, y1;  ll d = gcd(b%a, a, x1, y1); x = y1 - (b/a) * x1; y = x1; return d;}
ll power(ll x,ll y, ll p) { ll res = 1; x = x % p; while (y > 0) { if (y & 1) res = (res*x) % p; y = y>>1; x = (x*x) % p;   } return res; } 
ll power(ll x,ll y) { ll res = 1; while (y > 0) { if (y & 1) res = (res*x); y = y>>1; x = (x*x);   } return res; } 
ll mod(ll num, ll den){ return mod(mod(num) * power(den,MOD-2,MOD)); }
int main()
{
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	ll n;
    cin>>n;
    vector<ll> arr(n+1);
    for(ll i=1;i<=n;++i) cin>>arr[i];
    map<ll,ll> mp1,mp2,mp3,mp4;
    for(ll i=1;i<=n;++i)
    {
        mp1[arr[i]-i]++;
        mp2[arr[i]+i]++;
    }
    ll ans = 0;
    for(auto pr:mp1)
    {
        if(mp2.find(-pr.first) != mp2.end())
        {
            ans += (pr.second) * (mp2[-pr.first]);
        }
        
    }
    cout<<ans<<endl;
}

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

int a[3], b[3];
bool used[5];
bool flag = false;

void search(int t, int now) {
    if (t == 4) {
        flag = true;
        used[now] = false;
        return;
    }
    used[now] = true;
    for (int i = 1; i < 5; i++) {
        if (!used[i]) {
            for (int j = 0; j < 3; j++) {
                if (a[j] == now && b[j] == i) {
                    search(t + 1, i);
                }
                if (b[j] == now && a[j] == i) {
                    search(t + 1, i);
                }
            }
        }
    }
    used[now] = false;
}

int main() {
    for (int i = 0; i < 3; i++) {
        cin >> a[i] >> b[i];
    }
    search(1, 1);
    search(1, 2);
    search(1, 3);
    search(1, 4);
    if (flag) cout << "YES" << endl;
    else cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
s = input()
t = input()
S = (len(s)+1)
T = (len(t)+1)

dp = [[0]*T for i in range(S)]

for i in range(1, S):
   for j in range(1, T):
       dp[i][j] = max(dp[i-1][j], dp[i][j-1])
       if s[i-1] == t[j-1]:
           dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1)

# print(dp[len(s)][len(t)])

ans = ""
i = len(s)
j = len(t)
while i > 0 and j > 0:
    if dp[i][j] == dp[i-1][j]:
        i -= 1
    elif dp[i][j] == dp[i][j-1]:
        j -= 1
    else:
        ans += s[i-1]
        i -= 1
        j -= 1
    
print(ans[::-1])


Measured memory_bytes: 144536
#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;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define rREP(i,m,n) for(ll i = (m); i >= (n); i--)
#define ALL(c) (c).begin(), (c).end()
#define print(x) cout << (x) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll x;
    cin >> x;
    ll cnt = 0;
    double n = 100;
    while(n<x)
    {
        cnt++;
        n*=1.01;
        n = floor(n);
    }
    cout << cnt << endl;
    
}




Measured memory_bytes: 3648
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<vector>
#define MaxN 100000+100
using namespace std;
int point[MaxN][2];
vector<int>Ve[MaxN];
void DFS(int Point,int jo)
{
    if(point[Point][jo]==1)
        return ;
    point[Point][jo]=1;
    for(int i=0;i<Ve[Point].size();i++)
        DFS(Ve[Point][i],1-jo);
}
int main()
{
    int N,M;
    scanf("%d %d",&N,&M);
    for(int i=0;i<M;i++)
    {
        int a,b;
        scanf("%d %d",&a,&b);
        Ve[a].push_back(b);
        Ve[b].push_back(a);
    }
    DFS(1,1);
    long long a,b,c;
    a=b=c=0;
    for(int i=1;i<=N;i++)
    {
        if(point[i][0] && point[i][1])
            c++;
        else
            if(point[i][0])
                a++;
            else
                b++;
    }
    printf("%lld\n",c*a+c*b+c*(c-1)/2+a*b-M);
    return 0;
}


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

int main() {

    int n, t, a, h, ans = 0;
    double dif = 1000;

    cin >> n >> t >> a;
    t -= a;

    for (int i = 0; i < n; i++) {
        cin >> h;
        if (abs(t - h*0.006) < dif) {
            dif = abs(t - h*0.006);
            ans = i;
        }
    }

    cout << ans + 1 << "\n";


    return 0;
}

Measured memory_bytes: 256
import sys

fin = sys.stdin.readline

n, d = map(int, fin().split())
x = [tuple(map(int, fin().split())) for i in range(n)]

count = 0
for i in range(n - 1):
    for j in range(i + 1, n):
        d = (sum([(y - z) ** 2 for y, z in zip(x[i], x[j])]) ** 0.5)

        if abs(d - round(d)) < 1e-9:
            count += 1

print(count)


Measured memory_bytes: 38384
/*#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s,t;
    cin>>s>>t;
    int cnt=0;
    for(int i=0;i<s.size();i++)
    {
        if(s[i]!=t[i])
        {
            cnt=1;
            break;
        }
    }
    if(cnt==0)
    {
        cout<<"Yes"<<endl;
    }
    else
        cout<<"NO"<<endl;
}
*/
#include<bits/stdc++.h>
using namespace std;
int main()
{
    char s[15],t[15];
    cin>>s>>t;
    int l=strlen(s);
    int p=strlen(t),cnt=0;
    for(int i=0;i<l;i++)
    {
        if(s[i]==t[i])
        {
            cnt++;
        }
    }
    if(cnt==l)
    {
        if(l==p-1){
            cout<<"Yes"<<endl;
        }
    }
    else
        cout<<"No"<<endl;
}


Measured memory_bytes: 3624
import math
A,B,C,D = input().split()
A = int(A)
B = int(B)
C = int(C)
D = int(D)
a = C
b = D
while a % b != 0:
    a, b = b, a % b
g = C*D//b
a1 = A-1
a2 = B
ans1= (a1//C+a1//D-a1//g)
ans2= (a2//C+a2//D-a2//g)
print(B-A+1-ans2+ans1)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>
using namespace std;
typedef long long ll;
#define rep(n) for(ll i=0; i<n; i++)

struct sushi
{
  ll type;
  ll val;

  sushi(ll t, ll d)
  {
    type = t;
    val = d;
  }
};

void print_vec(vector<sushi> v)
{
  for(auto itr = v.begin(); itr!=v.end(); itr++)
  {
    cout <<(*itr).type << " " << (*itr).val << endl;
  }
}

void print_que(priority_queue<ll,vector<ll>,greater<ll> > que)
{
  cout << "queue:";
  priority_queue<ll,vector<ll>,greater<ll> > p = que;
  while(!p.empty())
  {
    cout << p.top() << " ";
    p.pop();
  }
  cout << endl;
}


int main()
{
  ll n,k;
  cin >> n >> k;

  vector<sushi> v;
  rep(n)
  {
    ll t,d;
    cin >> t >> d;
    v.emplace_back(sushi(t,d));
  }

  auto cmp = [](sushi left, sushi right) {return left.val > right.val;};
  sort(v.begin(),v.end(),cmp);

  priority_queue<ll,vector<ll>,greater<ll> > que;
  vector<bool> flag(n+1,0);
  
  ll cur = 0, tmp_del = 0;
  for (cur = 0; cur < k; cur++)
  {
    sushi s = v[cur];
    if(flag[s.type])
    {
      que.push(s.val);
    } else {
      flag[s.type] = 1;
    }
    tmp_del += s.val;
  }
  
  ll var = 0;
  for (ll i = 1; i < n+1; i++)
  {
    var += (ll)flag[i];
  }
  ll tmp = tmp_del + var*var;

  sushi s = v[cur];
  while( var <= n )
  {
    var++;
    if(que.empty()) break;
    while(flag[s.type]){
      cur++;
      if(cur==n) break;
      s = v[cur];
    }
    if(cur==n) break;

    flag[s.type] = 1;
    tmp_del = tmp_del + s.val - que.top();
    que.pop();
    tmp = max(tmp, tmp_del + var*var);
  }

  cout << tmp << endl;
  

  return 0;
}

Measured memory_bytes: 2672
//#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"

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

using namespace std;

ll n, m;
vector<vector<ll>> g(9, vector<ll>(0));

ll dfs(vector<ll> visits, ll v) {
	for (auto a : visits) {
		if (v == a) return 0;
	}
	visits.emplace_back(v);
	if (visits.size() == n) return 1;
	ll res = 0;
	for (auto a : g[v]) {
		res += dfs(visits, a);
	}
	return res;
}


signed main() {
	cin >> n >> m;
	rep(i, m) {
		ll a, b; cin >> a >> b;
		g[a].emplace_back(b);
		g[b].emplace_back(a);
	}
	vector<ll> visits(0);
	ll ans = dfs(visits, 1);
	cout << ans << endl;
}

Measured memory_bytes: 256
n,l = (int(i) for i in input().split())
a = [int(i) for i in input().split()]
s,x,y,ans,num,z = sum(a),0,n-1,[],0,0
for i in range(n-1):
	num2 = a[i]+a[i+1]
	if num<num2: num,z = num2,i+1
if num>=l:
	print("Possible")
	for i in range(1,z): print(i)
	for i in range(n-1,z-1,-1): print(i)
else: print("Impossible")

Measured memory_bytes: 14596
import java.util.*;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner s = new Scanner(System.in);
		int N = s.nextInt(), Q = s.nextInt();
		int[] a = new int [N];
		a[0] = 0;
		String S = s.next();
		for (int i = 1; i < N; i++){
			String SS = S.substring(i - 1, i + 1);
			//System.out.println(SS);
			a[i] = plus(a[i - 1], SS);
			//System.out.println(a[i]);
		}
		for (int i = 0; i < Q; i++){
			System.out.println(- a[s.nextInt() - 1] + a[s.nextInt() - 1]);
		}
	}
	public static int plus(int a, String s){
		int Flag = 0;
		if (s.equals("AC")){
			Flag = 1;
		}
		return a + Flag;
	}
}


Measured memory_bytes: 79628
#include<iostream>
#include<cstdio>
using namespace std;
const int N=100005;
const int MOD=1000000007;
int n;
int x[N];
long long inv[N];
void init(int n=100000)
{
	inv[1]=1;
	for(int i=2;i<=n;i++)
		inv[i]=(MOD-MOD/i)*inv[MOD%i]%MOD;
	return;
}
long long f[N];
int main()
{
	init();
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&x[i]);
	for(int i=1;i<=n;i++)
		f[i]=f[i-1]+inv[i];
	long long ans=0;
	for(int i=1;i<n;i++)
		ans=(ans+(x[i+1]-x[i])*f[i]%MOD)%MOD;
	for(int i=1;i<n;i++)
		ans=ans*i%MOD;
	printf("%lld",ans);
	return 0;
}

Measured memory_bytes: 5592
#include <iostream>
#include <vector>
#include <deque>
#include <cmath>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include "iomanip"
#include <cstdio>
#include <cstring>

using namespace std;


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

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

int main() {

    long long a, b, c, d;
    cin >> a >> b >> c >> d;
    long long c1 = b / c - (a - 1) / c;
    long long d1 = b / d - (a - 1) / d;
    long long LCM = lcm(c, d);
    long long cd1 = (b / LCM) - ((a - 1) / LCM);
    cout << (b - a + 1 + cd1 - c1 - d1);
    return 0;

}

Measured memory_bytes: 256
func readInts() -> [Int] {
    return readLine()!.split(separator: " ").map { Int($0)! }
}

func main() {
    let ab = readInts()
    let isEven = ab[0] * ab[1] % 2 == 0
    print(isEven ? "Even" : "Odd")
}

main()

Measured memory_bytes: 8256
#include<bits/stdc++.h>
#define int long long
#define F first
#define S second
#define P pair
#define FOR(i,a,b) for(int i=a;i<=b;i++)
#define V vector
#define RE return
#define ALL(a) a.begin(),a.end()
#define MP make_pair
#define PB push_back
#define PF push_front
#define FILL(a,b) memset(a,b,sizeof(a))
using namespace std;
int a[2005],b[2005],la,lb,mod=1e9+7;
int dp[2005][2005];
signed main(){
	ios::sync_with_stdio(0);
    cin.tie(0);
	cin>>la>>lb;
	dp[0][0]=1;
	FOR(i,1,la)cin>>a[i],dp[i][0]=1;
	FOR(i,1,lb)cin>>b[i],dp[0][i]=1;
	FOR(i,1,la){
		FOR(j,1,lb){
			dp[i][j]=(dp[i-1][j]+dp[i][j-1]-dp[i-1][j-1]+mod)%mod;
			if(a[i]==b[j])dp[i][j]=(dp[i][j]+dp[i-1][j-1])%mod;
		}
	}
	cout<<dp[la][lb];
	RE 0;
}




Measured memory_bytes: 31616
#include"bits/stdc++.h"
using namespace std;
typedef long long int ll;
typedef long double lld;
ll MOD = (1e9)+7;
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
inline void fastIO(){
  ios_base::sync_with_stdio(0);cin.tie(0);
}
int main() {
  fastIO();
  int n,val;
  cin>>n;
  vector<int>odd(101010);
  vector<int>even(101010);
  int gE=0,vE=0,gO=0,vO=0;
  for(int i=0;i<n;i++){
    cin>>val;
    if(i%2==0){
      even[val]++;
      if(even[val]>gE){
        gE=even[val],vE=val;
      }
    }else{
      odd[val]++;
      if(odd[val]>gO){
        gO=odd[val],vO=val;
      }
    }
  }
  sort(odd.begin(),odd.end());
  sort(even.begin(),even.end());
  if(vE==vO){
    cout<<min((((n/2)-odd[odd.size()-2])+((n/2)-even[even.size()-1])),(((n/2)-odd[odd.size()-1])+((n/2)-even[even.size()-2])))<<endl;
  }else{
    cout<<(((n/2)-odd[odd.size()-1])+((n/2)-even[even.size()-1]))<<endl;
  }
}
// - VERIFICAR LONG VS INT -

Measured memory_bytes: 1024
N=int(input())
maxd=0
ans=1
for i in range(1,N+1):
    c=0
    for j in range(1,7):
        if i % (2**j)==0:
            c=j
    if maxd < c:
        maxd=max(maxd,c)
        ans=i
    
print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
typedef pair<ll, ll> Pll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repn(i, n) for (int i = 0; i <= (int)(n); i++)
#define srep(i, l, n) for (int i = l; i < (int)(n); i++)
#define srepn(i, l, n) for (int i = l; i <= (int)(n); i++)
#define pb push_back 
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; }

const int MOD = 1000000007;
const int INF = 1e9;
#define PI 3.14159265369;
int dx[4] = {1,-1,0,0};
int dy[4] = {0,0,1,-1};
int ddx[8] = {1,1,1,-1,-1,-1,0,0};
int ddy[8] = {0,1,-1,0,1,-1,1,-1};


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

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

typedef int64_t Int;
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
 
const double EPS = 1e-10;
const Int INF = 1e18;
const int inf = 1e9;
const Int mod = 1e9+7;

bool print_space_enable = false;
void print() { 
    cout << endl; 
    print_space_enable = false;
}

template <class Head, class... Tail>
void print(Head&& head, Tail&&... tail) {
    if (print_space_enable) cout << " ";
    cout << fixed << setprecision(15) << head;
    print_space_enable = true;
    print(std::forward<Tail>(tail)...);
}

template<typename T>
void print(vector<T> v) {
    for (size_t i = 0; i < v.size(); i++) {
        if (i > 0) std::cout << " ";
        std::cout << v[i];
    }
    std::cout << std::endl;
}

int main() {
    Int n;
    cin >> n;
    Int res = 0;
    for (Int i = 1; i <= (Int)n; i++) {
        for (Int j = 1; j <= (Int)n; j++) {
            for (Int k = 1; k <= (Int)n; k++) {
                res += gcd(i, gcd(j, k));
            }
        }
    }
    print(res);
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <array>
#include <algorithm>
#include <map>
#include <vector>
#include <list>
#include <cmath>
#include <stack>
#include <queue>
#include <climits>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
using namespace std;

const int mod = 1000000007;
struct mint {
	ll x; // typedef long long ll;
	mint(ll x = 0) :x((x% mod + mod) % mod) {}
	mint operator-() const { return mint(-x); }
	mint& operator+=(const mint a) {
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator-=(const mint a) {
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator*=(const mint a) {
		(x *= a.x) %= mod;
		return *this;
	}
	mint operator+(const mint a) const {
		mint res(*this);
		return res += a;
	}
	mint operator-(const mint a) const {
		mint res(*this);
		return res -= a;
	}
	mint operator*(const mint a) const {
		mint res(*this);
		return res *= a;
	}
	mint pow(ll t) const {
		if (!t) return 1;
		mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	mint inv() const {
		return pow(mod - 2);
	}
	mint& operator/=(const mint a) {
		return (*this) *= a.inv();
	}
	mint operator/(const mint a) const {
		mint res(*this);
		return res /= a;
	}
};

struct combination {
	vector<mint> fact, ifact;
	combination(int n) :fact(n + 1), ifact(n + 1) {
		fact[0] = 1;
		for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
		ifact[n] = fact[n].inv();
		for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
	}
	mint operator()(int n, int k) {
		if (k < 0 || k > n) return 0;
		return fact[n] * ifact[k] * ifact[n - k];
	}
} comb(2000005);

mint g(int r, int c) {
	return comb(r + c + 2, r + 1) - 1;
}

bool comp(int i, int j) {
	return i > j;
}

int main()
{
	int n;
	cin >> n;
	if (n / 100 == 7 || (n / 10) % 10 == 7 || n % 10 == 7)
	{
		cout << "Yes";
	}
	else
	{
		cout << "No";
	}
}


Measured memory_bytes: 34220
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll A[100];

int main()
{
  std::cin >> N;

  rep( i, N )
    std::cin >> A[i];

  bool mi = true;
  ll prv = -1;
  ll rest = 1000, cnt = 0;
  ll x = -1;

  rep( i, N ) {
    if( mi && A[i] < A[i+1] ) {
      x = A[i];
      mi ^= true;
    }
    
    if( !mi && A[i] > A[i+1] ) {
      cnt += rest/x;
      rest %= x;
      rest += cnt*A[i];
      cnt = 0;

      mi ^= true;
      x = -1;
    }
  }

  std::cout << rest << std::endl;
  
  return 0;
}

Measured memory_bytes: 3524
//Code is like humor. When you have to explain it, it’s bad.
#define fastio ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL)
#include <bits/stdc++.h>
#define MOD 1000000007
#define int long long
using namespace std;
#define ss second
#define ff first
int32_t main()
{
    fastio;
    int T,n,m,i,j,k,a,b,c;
    T=1;
    string str;
    while(T --> 0)
    {
        cin>>n>>str;
        vector<int> R,G;
        unordered_map<int,bool> B;
        for(i=0;i<n;i++)
        if( str[i] == 'R')
            R.emplace_back(i);
        else if( str[i] == 'G')
            G.emplace_back(i);
        else
            B[i]=true;

        m=B.size();
        int ans=R.size()*G.size()*m;
        for(auto a:R)
        for(auto b:G)
        {
            if( (a+b)%2==0 and B[(a+b)/2] )
                ans--;
            if( B[2*a-b])
                ans--;
            if( B[2*b-a])
                ans--;
        }
        cout<<ans;
    }
    return 0;
}


Measured memory_bytes: 4036
#include <bits/stdc++.h>
#define rep(i, n) for(int i= 0; i < (n); i++)
using ll= long long int;
using namespace std;
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; }
ll mod= 1e9 + 7;


int main(){
  int n;
  cin >>n;
  ll ans=1;
  ll a[n];
  rep(i,n)cin >> a[i];
  rep(i,n){
    ans=ans / __gcd(ans,a[i]) * a[i];
  }
  cout << ans << endl;
}

Measured memory_bytes: 3552
#include <iostream>
#include <sstream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <memory>
#include <complex>
#include <numeric>
#include <cstdio>
#include <iomanip>

#define REP(i,m,n) for(int i=int(m);i<int(n);i++)
#define RREP(i,m,n) for(int i=int(n)-1;i>=int(m);--i)
#define EACH(i,c) for (auto &(i): c)
#define all(c) begin(c),end(c)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort(begin(c),end(c))
#define pb emplace_back
#define MP make_pair
#define SZ(a) int((a).size())

#ifdef LOCAL
#define DEBUG(s) cout << (s) << endl
#define dump(x)  cerr << #x << " = " << (x) << endl
#define BR cout << endl;
#else
#define DEBUG(s) do{}while(0)
#define dump(x) do{}while(0)
#define BR 
#endif
using namespace std;

using UI = unsigned int;
using UL = unsigned long;
using LL = long long int;
using ULL = unsigned long long;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using PII = pair<int,int>;
using VP = vector<PII>;

//struct edge {int from, to, cost;};

constexpr double EPS = 1e-10;
constexpr double PI  = acos(-1.0);
//constexpr int INF = INT_MAX;

template<class T> inline T sqr(T x) {return x*x;}

void solve() {
    string s;
    cin >> s;
    REP(i,0,s.size()-1) if (s[i] == s[i+1]) {
        cout << i+1 << " " << i+2 << endl;
        return;
    }
    REP(i,0,s.size()-2) if (s[i] == s[i+2]) {
        cout << i+1 << " " << i+3 << endl;
        return;
    }

    cout << "-1 -1" << endl;
}

int main() {
    solve();
    
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cstring>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <bitset>
#include <numeric>
#include <utility>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <unordered_map>
using namespace std;

#define REP(i, s) for (int i = 0; i < s; ++i)
#define ALL(v) (v.begin(), v.end())
#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
#define EACH(i, s) for (__typeof__((s).begin()) i = (s).begin(); i != (s).end(); ++i)

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; }
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ EACH(it, P) { s << "<" << *it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ EACH(it, P) { s << "<" << it->first << "->" << it->second << "> "; } return s << endl; }

typedef long long  ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
   int w,a,b;
   cin>>w>>a>>b;
   if(a+w<b || b+w<a)
   cout<<min(min(abs(b-(a+w)),abs(a-(b+w))),min((abs(a-b)),abs(b+w-a)))<<endl;
   else cout<<0<<endl;
    return 0;
}

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

using namespace std;

long long DP[100010];

int main()
{
   int n;
   int x,y,k;
   cin >> n >> k;
   for (int a=1;a<=n;a++)
   {
       cin >> x >> y;
       for (int i=100000;i>=y;i--)
       {
           if(DP[i-y]!=0||i-y==0)
           {

              if (DP[i]==0)
                  DP[i]=DP[i-y]+x;
              else DP[i]=min(DP[i-y]+x,DP[i]);


           }
       }
   }

   for (int i=100000;i>=1;i--)
   {
       if (DP[i]!=0&&DP[i]<=k)
       {
           cout << i;
           return 0;
       }
   }
   cout << 0;

}


Measured memory_bytes: 1024
#include<algorithm>
#include<iostream>
#include<string>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
  int i,j;
  int a[100001],d,m,n,p;
  int sm;
  while(cin>>d&&d){
    cin>>m>>n;
    a[0]=0;
    for(i=1;i<m;i++)
      cin>>a[i];
    a[i]=d;
    sort(a,a+m+1);
    sm=0;
    for(i=0;i<n;i++){
      cin>>p;
      for(j=0;a[j]>p||p>=a[j+1];j++);
      sm+=min(p-a[j],a[j+1]-p);
    }
    cout<<sm<<endl;
  }
  return 0;
}

Measured memory_bytes: 1256
import sys
import math
import itertools
from copy import copy
from collections import deque,Counter
from decimal import Decimal
def s(): return input()
def i(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7

X = i()
if X == 7 or X == 5 or X == 3:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 5044
#include<cstdio>
#include<cstring>
using namespace std;
int main(void){
	char s[200000];
	int i;
	int n;
	int x,y;
	scanf("%s",s);
	n=strlen(s);
	for(i=0;i<n;i++){
		if(s[i]=='A'){
			x=i;
			break;
		}
	}
	for(i=n-1;i>=0;i--){
		if(s[i]=='Z'){
			y=i;
			break;
		}
	}
	y=n-y;
	x=x-1;
	printf("%d\n",n-(x+y));
	return 0;
}
	

Measured memory_bytes: 384
/*input
11 14
3 1 4 1 5 9 2 6 5 3 5
8 9 7 9 3 2 3 8 4 6 2
*/
/**
    Author: Kristopher Paul
    Date Created: 27-10-2019
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
//#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int n,k;
    cin >> n >> k;
    int a[n];
    int f[n];
    FOR(i,0,n){
        cin >> a[i];
    }
    FOR(i,0,n){
        cin >> f[i];
    }
    sort(a,a+n);
    sort(f,f+n);
    vector<pii> vec;
    int r = 0;
    FOR(i,0,n){
        vec.pb({a[i],f[n-i-1]});
        remax(r,a[i]*f[n-i-1]);
    }
    int l = 0;
    int ans = r;
    while(l <= r){
        int m = (l+r)/2;
        int step = 0;
        FOR(i,0,vec.size()){
            if((vec[i].first*vec[i].second) <= m){
                continue;
            }
            int aa = vec[i].first;
            int bb = vec[i].second;
            int x = aa-floor(double(m)/double(bb));
            step += x;
        }
        if(step <= k){
            r = m-1;
            remin(ans,m);
        }else{
            l = m+1;
        }
    }
    cout << ans << endl;
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}


Measured memory_bytes: 9072
import java.util.*;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		sc = new Scanner(System.in);
		new Main();
		sc.close();
	}
	
	Main()
	{
		
		int[] arr = new int[5];
		for(int i = 0; i < 5; ++i) arr[i] = sc.nextInt();
		
		Arrays.sort(arr);
		for(int i = 5; i > 0; --i)
			System.out.printf("%d%c", arr[i-1], i == 1 ? '\n' : ' ');
	}
	
	
	boolean isPrime(int n){
		if(n == 2) return true;
		if(n % 2 == 0) return false;
		
		for(int i = 3; i * i <= n; i += 2)
			if(n % i == 0) return false;
		
		return true;
	}

	static Scanner sc;
}

Measured memory_bytes: 17348
#include<stdio.h>
int main(){
  int a,i,A[10000],b,B[10000],j,count=0;
  scanf("%d", &a);
  for(i=0;i<a;i++){
    scanf("%d",&A[i]);
  }
  scanf("%d",&b);
  for(i=0;i<b;i++){
    scanf("%d",&B[i]);
    j=0;
    A[a]=B[i];
    while(A[j]!=B[i]){
      j++;
      if(j==a)break;
  }
    if(j!=a)count++;
  }
  printf("%d\n",count);
}



Measured memory_bytes: 2728
#include <bits/stdc++.h>
using namespace std;
#define lint long long
#define P pair<int, int>

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

    int len = S.length();
    int num = len;
    for(int i = 0; i < len - 1; ++i){
        if(S[i] != S[i + 1]){
            num = min(num, max(i + 1, len - i - 1));
        }
    }
    
    cout << num << endl;
}


Measured memory_bytes: 512
#include <iostream>
#include <cstdio>
#include <vector>
#include <iomanip>
#include <unordered_map>
#include <unordered_set>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
using namespace std;

int main() {
    long long N;
    long long ans = 0;
    cin >> N;

    for (int i = 0; i < N; ++i) {
        ans += (i+1) * (N-i);
    }

    for (int i = 1; i < N; ++i) {
        int f;
        int t;
        cin >> f >> t;
        if (t < f) {
            swap(t, f);
        }
        // cout << "DEBUG " << ans << endl;
        ans -= f * (N-t+1);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3628
#include<bits/stdc++.h>
using namespace std;
int const MAXN=110000;
int parent[MAXN], ran[MAXN];
int _find(int i){
	if(parent[i]==i) return i;
	return parent[i]=_find(parent[i]);
}
void _union(int a, int b){
	int pa=_find(a), pb=_find(b);
	if(pa!=pb){
		if(ran[pa]<ran[pb]) parent[pa]=pb;
		else if(ran[pa]>ran[pb]) parent[pb]=pa;
		else{
			ran[pa]++;
			parent[pb]=pa;
		}
	}
}
int main(){
	int n, m;
	cin>>n>>m;
	for(int i=1;i<=n;i++)
		parent[i]=i;
	vector<int> v(n);
	for(int i=0;i<n;i++)
		cin>>v[i];
	for(int i=0;i<m;i++){
		int a, b;
		cin>>a>>b;
		_union(a,b);
	}
	
	int res=0;
	for(int i=0;i<n;i++)
		if(_find(v[i])==_find(i+1))
			res++;
	cout<<res;
}

Measured memory_bytes: 1408
#include <iostream>
#include<vector>
#include<algorithm>
#include<cstring>
#include<string>
#include <set>
#include <cassert>
#include"math.h"
using namespace std;
#define MOD 1000000007
class UnionFind {
	vector<int> data;
public:
	UnionFind(int size) : data(size, -1) { }
	bool unionSet(int x, int y) {
		x = root(x); y = root(y);
		if (x != y) {
			if (data[y] < data[x]) swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
		return x != y;
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

int find(vector<long long> &arr, long long obj) {
	if (arr[arr.size() - 1] < obj)return arr.size()-1;
	if (arr[0] > obj)return -1;

	int min = 0; int max = arr.size() - 1;
	for (int i = 0; i < arr.size(); i++) {
		if (arr[min+(max-min) / 2] > obj) {
			max = min + (max - min) / 2;
		}
		else {
			min = min + (max - min) / 2;
		}
		if (max - min == 1) {
			return min;
		}
	}


}

int main() {
	int n, m;
	cin >> n >> m;
	if (n >= m) {
		cout << 0;
		return 0;
	}
	int *x = new int[m];
	
	for (int i = 0; i < m; i++) {

		cin >> x[i];
	}
	sort(x,x+m);
	vector<int> dif;
	for (int i = 0; i < m - 1; i++) {
		dif.push_back( x[i + 1] - x[i]);
	}
	sort(dif.begin(), dif.end());
	int sum = 0;
	for (int i = 0; i < m - n; i++) {
		sum += dif[i];
	}
	cout << sum;

	return 0;
}


Measured memory_bytes: 1276
#include<iostream>
#include <math.h>
#include<algorithm>
#include <bits/stdc++.h>

using namespace std;

#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)

main(){
   double K;
   double N, P = 0;
   double Pi;
   int score;
   cin >> N >> K;
    if(K <= N){
        FOR(i, 0, K - 1){
            Pi = 1.0 ;
            score = i + 1;
            while(1 <= score && score <= K - 1){
                score *= 2;
                Pi /= 2.0; 
            
            }
            P += Pi;
        }
        P += N - K + 1.0;
    }
    else{
        FOR(i, 0, N ){
            Pi = 1.0 ;
            score = i + 1;
            while(1 <= score && score <= K - 1){
                score *= 2;
                Pi /= 2.0; 
            }
            P += Pi;
        }
    }
    printf("%.15f",P / N);
}


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

using namespace std;

const int N = 400 + 77 , L = 22 , Mod = 1000000007;
int n , dp[L][1 << L];
bool M[N][N];
int main(){
   ios::sync_with_stdio(0);cin.tie(0);
   cin >> n;
   for(int i = 0;i < n;++ i)
      for(int j = 0;j < n;++ j)
         cin >> M[i][j];
   for(int i = 0;i < (1 << n);++ i)
      for(int j = 0;j < n;++ j)
         if((i & (1 << j)) != 0 && M[0][j] == 1)
            ++ dp[0][i];
   for(int i = 1;i < n;++ i){
      for(int msk = 1;msk < (1 << n);++ msk){
         if(__builtin_popcount(msk) != i + 1)
            continue ;
         for(int j = 0;j < n;++ j){
            if(((1 << j) & msk) != 0 && M[i][j] == 1){
               dp[i][msk] = (dp[i][msk] + dp[i - 1][msk ^ (1 << j)]);
               if(dp[i][msk] >= Mod)
                  dp[i][msk] -= Mod;
            }
         }
      }
   }
   cout << dp[n - 1][(1 << n) - 1];
   return 0;
}


Measured memory_bytes: 192512
N=int(input())
ga,sa,ba=map(int,input().split())
gb,sb,bb=map(int,input().split())

check=(gb>ga)+(sb>sa)+(bb>ba)
if check==3:
    donguri=N

    inc=0
    for i in range(0,donguri//ga+1):
        x=(ga<gb)*i
        for j in range(0,donguri//sa+1):
            y=(sa<sb)*j
            if donguri>=x*ga+y*sa:
                z=((donguri-x*ga-y*sa)//ba)*(bb>ba)
                inc=max(inc,x*(gb-ga)+y*(sb-sa)+z*(bb-ba))

    donguri+=inc
    print(donguri)
elif check==0:
    donguri=N
    inc=0
    for i in range(0,donguri//gb+1):
        x=(ga>gb)*i
        for j in range(0,donguri//sb+1):
            y=(sa>sb)*j
            if donguri>=x*gb+y*sb:
                z=((donguri-x*gb-y*sb)//bb)*(ba>bb)
                inc=max(inc,-x*(gb-ga)-y*(sb-sa)-z*(bb-ba))

    donguri+=inc
    print(donguri)

elif check==2:
    donguri=N
    inc=0
    for i in range(0,donguri//ga+1):
        x=(ga<gb)*i
        for j in range(0,donguri//sa+1):
            y=(sa<sb)*j
            if donguri>=x*ga+y*sa:
                z=((donguri-x*ga-y*sa)//ba)*(bb>ba)
                inc=max(inc,x*(gb-ga)+y*(sb-sa)+z*(bb-ba))

    donguri+=inc
    if ga>gb:
        plus=(donguri//gb)*(ga-gb)
        print(donguri+plus)
    elif sa>sb:
        plus=(donguri//sb)*(sa-sb)
        print(donguri+plus)
    elif ba>bb:
        plus=(donguri//bb)*(ba-bb)
        print(donguri+plus)
    else:
        print(donguri)

else:
    donguri=N
    inc=0
    if ga<gb:
        plus=(donguri//ga)*(gb-ga)
        donguri+=plus
        if sa>sb:
            for i in range(0,donguri//sb+1):
                j=(donguri-i*sb)//bb
                inc=max(inc,i*(sa-sb)+j*(ba-bb))
            print(donguri+inc)
        else:
            inc=(donguri//bb)*(ba-bb)
            print(donguri+inc)

    elif sa<sb:
        plus=(donguri//sa)*(sb-sa)
        donguri+=plus
        if ga>gb:
            for i in range(0,donguri//gb+1):
                j=(donguri-i*gb)//bb
                inc=max(inc,i*(ga-gb)+j*(ba-bb))
            print(donguri+inc)
        else:
            inc=(donguri//bb)*(ba-bb)
            print(donguri+inc)
    else:
        plus=(donguri//ba)*(bb-ba)
        donguri+=plus
        if ga>gb:
            for i in range(0,donguri//gb+1):
                j=(donguri-i*gb)//sb
                inc=max(inc,i*(ga-gb)+j*(sa-sb))
            print(donguri+inc)
        else:
            inc=(donguri//sb)*(sa-sb)
            print(donguri+inc)
                


Measured memory_bytes: 40940
#include <iostream>
#include <cmath>
#include <numeric>
#include <string>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <queue>
#include <algorithm>
using namespace std;

using ll = long long;

#define MOD 1000000007

#define FOR(i, m, n) for (ll i = m; i <= n; i++)
#define FORR(i, m, n) for (ll i = m; i >= n; i--)

ll gcd(ll a, ll b) { if (a < b) { a ^= b; b ^= a; a ^= b; } return b ? gcd(b, a % b) : a; }
ll lcm(ll a, ll b) { return a * b / gcd(a, b); }

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

    bool C[10001];

    FOR(i, 1, 10000) {
        C[i] = i * 8 / 100 == A;
    }

    FOR(i, 1, 10000) {
        if (C[i] && i * 10 / 100 == B) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}


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

int main() {
	string s, t;
	cin >> s;
	cin >> t;
	int len = s.length();
	bool flag=false;
	if (s == t)
		flag = true;
	else {
		char c;
		for (int i = 0;i < len - 1;i++) {
			c = s[len - 1];
			s.erase(s.end() - 1);
			s.insert(s.begin(), c);
			if (s == t) {
				flag = true;
				break;
			}
		}
	}
	if (flag == true) printf("Yes");
	else printf("No");
	return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;


public class Main {


    public static void main(String[] args) {
        int a, b, c, count=0;
        Scanner sc = new Scanner(System.in);
        a = sc.nextInt();
        b = sc.nextInt();
        c = sc.nextInt();
        for(int i = a; i<=b; i++){
        if(c%i ==0){
        count++;
        }
        }
    System.out.println(count);
    }
}



Measured memory_bytes: 26348
// Author : Rifayat Samee (Sanzee)
// Problem :
// Algorithm:

/*

*/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll max(ll a,ll b){
    if(a < b) return b;
    return a;
}
int main(){

	//freopen("in.txt","r",stdin);
	//freopen("out.txt","w",stdout);
    ll n,W;
    scanf("%lld %lld",&n,&W);
    vector<pair<ll,ll>>A(n+1);
    for(ll i=0;i<n;i++){
        ll w,p;
        scanf("%lld %lld",&w,&p);
        A[i].first = w;
        A[i].second = p;
    }
    vector<vector<ll>>dp(n+1,vector<ll>(W+5,0));
    dp[0][A[0].first] = A[0].second;
    dp[0][0] = 0;

    for(ll i=1;i<n;i++){
        for(ll w = 0;w<=W;w++){
           if(w - A[i].first>=0)
                dp[i][w] = max(dp[i-1][w],dp[i-1][w - A[i].first] + A[i].second);
            else
                dp[i][w] = dp[i-1][w];
        }

    }
    ll res = 0;
    for(ll w = 0;w<=W;w++){
        res = max(res,dp[n-1][w]);
    }
    //printf("\n");
    printf("%lld\n",res);
	return 0;
}


Measured memory_bytes: 80256
#include <bits/stdc++.h>
#define sanyes ios_base::sync_with_stdio(0), cout.tie(0); cin.tie(0);
#define llong long long int
#define pb push_back
#define bpc __builtin_popcount
#define f first
#define s second

const llong mxn = 1e5 + 7;
const llong mod = 1e9 + 7;
const llong inf = 1e18 + 9;

using namespace std;

llong n, c, k, a[mxn], cnt = 1, ans;

int main(){
    cin >> n >> c >> k;
    for (int i = 1; i <= n; i ++){
        cin >> a[i];
    }sort(a + 1, a + n + 1);
    llong kek = a[1] + k;
    for (int i = 2; i <= n; i ++){
        if(a[i] > kek || cnt >= c){
            kek = a[i] + k;
            ans ++;
            cnt = 0;
        }cnt ++;
        //cout << kek << ' ';
    }cout << ans + 1;
    return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>
int main(void){
    int a,b,count=0;
    scanf("%d %d",&a,&b);
  
    for(int i = a;i <= b;++i){
        if( (i/10000 == i%10) && ((i/1000)%10 == (i/10)%10) ){
            ++count;
        }
    }
  
    printf("%d",count);
    return 0;
}

Measured memory_bytes: 128
def fct(x):
	t = 1L
	for i in range(1, x+1):
		t = (t * long(i)) % 1000000007L
	return t

inpt = map(int, raw_input().split())
n = inpt[0]
m = inpt[1]

ans = 0L

if abs(n-m) < 2:
	ans = (fct(n)*fct(m)) % 1000000007L
	if n == m:
		ans = (2L * ans) % 1000000007L

print ans

Measured memory_bytes: 5764
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
 
static const double EPS = 1e-8;
static const double PI = 4.0 * atan(1.0);
static const ll INF = 1023456789;
 
#define REP(i,n)	for(int i=0;i<n;++i)
#define REPR(i,n)	for(int i=n-1;i>=0;--i)
#define FOR(i,s,n)	for(int i=s;i<n;++i)
#define FORR(i,s,n)	for(int i=n-1;i>=s;--i)
#define ALL(c)		(c).begin(),(c).end()
#define CLEAR(v)	memset(v,0,sizeof(v))
#define MP(a,b)		make_pair((a),(b))
#define ABS(a)		((a)>0?(a):-(a))
#define F			first
#define S			second
 
int main(int argc, char **argv) {
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	cout << (min(a, b) + min(c, d)) << endl;
	return 0;
}
 

Measured memory_bytes: 256
#include<iostream>
#include<sstream>
#include<fstream>
#include<string>
#include<vector>
#include<deque>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<algorithm>
#include<functional>
#include<utility>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<ctime>
#include<cstdio>

using namespace std;

#define REP(i,n) for(int i=0;i<int(n);i++)
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)
typedef long long ll;
typedef pair<int,int> P;

int main(void){
	          int i;

	          int N,M;
	          cin >> N >> M;

	          vector<int> v;
	          for(i=0;i<M;i++){
	        	  int A,B;
	        	  cin >> A >> B;
	        	  v.push_back(A);
	          }

	          sort(v.begin(),v.end());
	          reverse(v.begin(),v.end());

	          int ans=0,k=0;
	          for(i=0;i<M;i++){
	        	  if(v[i]>=N) k++;
	        	  else{
	        		  ans+=N-v[i];
	        		  k++;
	        	  }
	        	  if(k==M-1) break;
	          }

	          cout << ans << endl;


	          return 0;
}

Measured memory_bytes: 3140
A, B, C = map(int, input().split())
K = int(input())

while A >= B and K > 0:
    K -= 1
    B *= 2
while B >= C and K > 0:
    K -= 1
    C *= 2


if (A < B) and (B < C):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 61640