akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <climits>
#include <cmath>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;

typedef long long ll;
typedef long double ld;

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

  int n, m;
  cin >> n >> m;
  int cnt = 0;
  for (int i = 0; i < n + m; ++i) {
    for (int j = 0; j < n + m; ++j) {
      if (i == j) continue;
      if ((i < n && j < n) || (i >= n && j >= n)) {
        ++cnt;
      }
    }
  }
  cout << cnt / 2;
}

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

int n;
int i,counter,t;
int main(){
    cin>>n;
    counter=0;
    for(i=1;i<n+1;i++){
        cin>>t;
        if(t!=i){
            counter++;
        }
    }
    if(counter>2){
        cout<<"NO"<<endl;
    }else{
        cout<<"YES"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N;
 
  vector<int> k(N);
  for (int i = 0; i < N; i++) {
  cin >> k.at(i);
}
  sort(k.begin(), k.end());
  int a = 0;
  for (int i = 0; i < N-2; i++){
   for (int j = 1; j < N-1; j++){
     for (int l = 2; l < N; l++){
       if(k.at(i) < k.at(j) && k.at(j) < k.at(l)  &&
          k.at(i) + k.at(j) > k.at(l) )
       {a++;}
     }}}
  
  cout << a << endl;
}
       

Measured memory_bytes: 3624
function main(input) {
	var splitted = input.split("\n")
	var num = Number(splitted[0])
	var list = splitted
		.slice(1)
		.map(s => Array.from(s).sort().join(''))
		.sort()
	var count = 0
	var pasts = [
		[list[0]]
	]
	var pastsIndex = 0
	for (var i = 1; i < list.length; i++) {
		if (list[i] === pasts[pastsIndex][0]) {
			count += pasts[pastsIndex].length
			pasts[pastsIndex].push(list[i])
			continue;
		}
		pastsIndex++
		pasts.push([list[i]])
	}
	console.log(count)
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 55560
#include <iostream>
#include <iomanip>
#include <cmath>
#include <vector>
#include <queue>
#include <limits>
#include <algorithm>
#include <string>
using namespace std;

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

	int32_t A, B, C, D;
	A = str[0] - '0';
	B = str[1] - '0';
	C = str[2] - '0';
	D = str[3] - '0';

	for (int32_t i = 0; i < 0x8; i++) {
		bool is_plus0 = (i & 0x01) == 0;
		bool is_plus1 = (i & 0x02) == 0;
		bool is_plus2 = (i & 0x04) == 0;

		int32_t sum = A;
		sum += is_plus0 ? B : -B;
		sum += is_plus1 ? C : -C;
		sum += is_plus2 ? D : -D;
		if (sum == 7) {
			cout << A << (is_plus0 ? '+' : '-') << B << (is_plus1 ? '+' : '-') << C << (is_plus2 ? '+' : '-') << D << "=7" << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

// 最大公約数
int gcd(int m, int n) {
  if (n==0) return abs(m);
  else return gcd(n, m%n);
}

int main() {
  int N;
  cin >> N;
  vector<int> A(N);
  for (int i=0; i<N; i++) cin >> A[i];
  int ans = gcd(A[0], A[1]);
  for (int i=2; i<N; i++) ans = gcd(ans, A[i]);
  cout << ans << endl;
}

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

using namespace std;

#define REP(i,a,b) for(int i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

typedef complex<double> P;

#define EPS (1e-7)

double dot(P const& a, P const& b) {
  return real(conj(a)*b);
}

double cross(P const& a, P const& b) {
  return imag(conj(a)*b);
}

P projection_point(P const& a, P const& b, P const& c) {
  double k = dot(b-a, c-a) / norm(b-a);
  return a+k*(b-a);
}

P reflection_point(P const& a, P const& b, P const& c) {
  return c + 2.*(projection_point(a, b, c) - c);
}

int main () {
  
  P a, b;
  cin >> a.real() >> a.imag() >> b.real() >> b.imag();
  int q; cin >> q;
  for(;q--;) {
    P c; cin >> c.real() >> c.imag();
    P ans(reflection_point(a, b, c));
    printf("%.10f %.10f\n", ans.real(), ans.imag());
  }
  return 0;
}

Measured memory_bytes: 1268
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<algorithm>
#include<map>
#include<stack>
#include<queue>  
#include<vector>
#define ll long long
using namespace std;

int main(){
	int n;
	cin>>n;
	int a[20][500];
	for (int i=1;i<=2;i++){
		for (int j=1;j<=n;j++) cin>>a[i][j];
	}
	int dp[20][500];
	memset(dp,0,sizeof(dp));
	dp[1][1]=a[1][1];
	for (int i=2;i<=n;i++) dp[1][i]=dp[1][i-1]+a[1][i];
	dp[2][1]=a[1][1]+a[2][1];
	
	for (int i=2;i<=n;i++){
		dp[2][i]=max(dp[1][i],dp[2][i-1])+a[2][i];
	}
//	for (int i=1;i<=2;i++){
//		for (int j=1;j<=n;j++){
//			printf("%d\t",dp[i][j]);
//		}printf("\n");
//	}
	
	cout<<dp[2][n];
	
}

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

#define MOD 1000000007

long long int N;
long long int dp[70][3], bit, ans;

int main()
{
	scanf("%lld", &N);

	dp[0][0] = 1;
	for (long long int i = N; i > 0; i /= 2)
	{
		++bit;
	}
	for (int i = 0; i <= bit; ++i)
	{
		for (int j = 0; j < 3; ++j)
		{
			if (N >> (bit - i) & 1)
			{
				dp[i + 1][std::min(j * 2 + 1, 2)] += dp[i][j];
				dp[i + 1][std::min(j * 2, 2)] += dp[i][j];
				dp[i + 1][std::min(j * 2 + 1, 2)] %= MOD;
				dp[i + 1][std::min(j * 2, 2)] %= MOD;
				if ((j * 2 - 1) >= 0)
				{
					dp[i + 1][std::min(j * 2 - 1, 2)] += dp[i][j];
					dp[i + 1][std::min(j * 2 - 1, 2)] %= MOD;
				}
			}
			else
			{
				dp[i + 1][std::min(j * 2, 2)] += dp[i][j];
				dp[i + 1][std::min(j * 2, 2)] %= MOD;
				if ((j * 2 - 1) >= 0)
				{
					dp[i + 1][std::min(j * 2 - 1, 2)] += dp[i][j];
					dp[i + 1][std::min(j * 2 - 1, 2)] %= MOD;
				}
				if ((j * 2 - 2) >= 0)
				{
					dp[i + 1][std::min(j * 2 - 2, 2)] += dp[i][j];
					dp[i + 1][std::min(j * 2 - 2, 2)] %= MOD;
				}
			}
		}
	}
	ans = dp[bit + 1][0] + dp[bit + 1][1] + dp[bit + 1][2];
	ans %= MOD;

	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 128
#include<cstdio>

int main(){
	long long a,b,g,l,t;
	while(scanf("%d %d", &a, &b) + 1){
		if(a > b){
			t = a;
			a = b;
			b = t;
		}
		if(b % a){
			t = a / 2;
			for(int i = t; i > 0; i--){
				if(!(a % i)){
					if(!(b % i)){
						g = i;
						i -= t;
						printf("%lld %lld\n", g, a * b / g);
					}
				}
			}
		}else{
			printf("%lld %lld\n", a, b);
		}
	}
	return 0;
}

Measured memory_bytes: 1024
#!/usr/bin/env python3
import sys
try:
    from typing import List
except ImportError:
    pass


def solve(N: int, a: "List[int]"):
    print(sum(a) - N)


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    a = [int(next(tokens)) for _ in range(N)]  # type: "List[int]"
    solve(N, a)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
import java.math.BigInteger;
import java.util.Scanner;

public class Main {
    BigInteger ZERO = new BigInteger("0");

    public Main() {
        Scanner scanner = new Scanner(System.in);
        int N = scanner.nextInt();
        long[] A = new long[N];

        BigInteger LCM = new BigInteger("1");
        for (int i = 0; i < N; i++) {
            String in = scanner.next();
            BigInteger temp = new BigInteger(in);
            LCM = LCM.multiply(temp).divide(GCD(LCM, temp));
            A[i] = Long.parseLong(in);
        }

        long modLCM = LCM.mod(new BigInteger("1000000007")).longValue();

        long Ans = 0;
        for (int i = 0; i < N; i++) {
            Ans = ( Ans + modLCM * modInv(A[i]) % 1000000007L ) % 1000000007L;
        }

        System.out.println(Ans);
    }

    long modInv(long a){
        long b = 1000000007L, u = 1, v = 0;
        while(b > 0){
            long t = a / b;
            a -= t * b;
            u -= t * v;

            a = a ^ b;
            b = a ^ b;
            a = a ^ b;
            u = u ^ v;
            v = u ^ v;
            u = u ^ v;
        }
        u %= 1000000007L;
        if (u < 0) u += 1000000007L;

        return u;
    }

    BigInteger GCD(BigInteger a, BigInteger b){
        if (b.equals(ZERO))
            return a;
        else
            return GCD(b, a.mod(b));
    }

    public static void main(String[] args){
        new Main();
    }
}


Measured memory_bytes: 61728
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cmath>
#include <set>
#include <map>

#define N 0
#define INF 0x3f3f3f3f
#define LL long long
#define mz(x) ms(x,0)
#define ms(x,y) memset(x,y,sizeof(x))
#define mc(x,y) memcopy(x,y,sizeof(y))
#define MOD 1000000007

using namespace std ;

LL idx[100010] ;
vector<LL> cycle ;

LL mod_mul (LL x, LL y, LL p) {
		LL s = 0 ;
		while (y > 0) {
				if (y & 1) {
						s += x ;
						s %= p ;
				}
				x <<= 1 ;
				x %= p ;
				y >>= 1 ;
		} return s ;
}

int main()
{
	LL n, x, m ;
	scanf ("%lld%lld%lld", &n, &x, &m) ;
	
	LL s = x ;
	idx[x] = 1 ;
	cycle.push_back(0) ;
	cycle.push_back(x) ;
	LL i, j = -1 ;
	for (i=2; i<=n; i++)
	{
		x = mod_mul (x, x, m) ;
		if (idx[x] > 0)
		{
			j = idx[x] ;
			break ;
		}
		idx[x] = i ;
		cycle.push_back(x) ;
		s += x ;
	}
	
	if (j == -1)
		cout << s << endl ;
	else
	{
		LL cn = i - j ;
		LL res = n - i + 1 ;
		LL cs = 0 ;
		for (LL k=j; k<i; k++)
			cs += cycle[k] ;
			
		s += res / cn * cs ;
		if (res % cn)
			for (LL k=j; k<j+(res%cn); k++)
				s += cycle[k] ;
		
		cout << s << endl ;
	}

	return 0 ;
}

Measured memory_bytes: 4272
#include<cstdio>
typedef unsigned long long ull;
struct Edge{int to;Edge*next;}E[1010],*fir[1010];
int n,a[1010],b[1010];
ull f[80];
bool dfs(int i){
	int lim=a[i],sum=0,m=0;
	for(Edge*e=fir[i];e;e=e->next){
		if(!dfs(e->to))return 0;
		lim-=a[e->to];
		sum+=b[e->to];
	}
	if(lim<0)return 0;
	for(;m<<6<=lim;m++)f[m]=!m;
	for(Edge*e=fir[i];e;e=e->next){
		int u=b[e->to]-a[e->to],v=u&63;
		u>>=6;
		for(int j=m;j-->u;){
			f[j]|=f[j-u]<<v;
			if(j>u&&v)f[j]|=f[j-u-1]>>64-v;
		}
	}
	for(int j=m;j--;){
		int v=lim+1-(j<<6);
		if(v<64)f[j]&=(1ull<<v)-1;
		if(f[j]){
			v=j<<6|63-__builtin_clzll(f[j]);
			v=sum-v;
			if(v<a[i])b[i]=a[i],a[i]=v;
			else b[i]=v;
			return 1;
		}
	}
}
int main(){
	scanf("%d",&n);
	for(int i=2,p;i<=n;i++)scanf("%d",&p),E[i]=(Edge){i,fir[p]},fir[p]=E+i;
	for(int i=1;i<=n;i++)scanf("%d",a+i);
	puts(dfs(1)?"POSSIBLE":"IMPOSSIBLE");
}

Measured memory_bytes: 256
#include <stdio.h>
#include <iostream>
#include <string.h>
#include <limits.h>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>

typedef unsigned long long ULLONG;
typedef long long LLONG;
static const LLONG MOD_NUM = 1000000007LL;

template <class _T> static _T tp_abs(const _T& a) {
	return ((a < 0) ? (a * -1) : a);
}
template <class _T> static _T tp_min(_T a, _T b) {
	return a < b ? a : b;
}
template <class _T> static _T tp_max(_T a, _T b) {
	return a > b ? a : b;
}
template<class _T> static void get1int(_T& a) {
	const char* fmt = " %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld";
	}

	if (scanf(fmt, &a) < 0) {
		printf("g1int Error\n");
	}
}
template<class _T> static void get2int(_T& a, _T& b) {
	const char* fmt = " %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld";
	}

	if (scanf(fmt, &a, &b) < 0) {
		printf("g2int Error\n");
	}
}
template<class _T> static void get3int(_T& a, _T& b, _T& c) {
	const char* fmt = " %d %d %d";
	if (sizeof(_T) == sizeof(long long)) {
		fmt = " %lld %lld %lld";
	}

	if (scanf(fmt, &a, &b, &c) < 0) {
		printf("g3int Error\n");
	}
}
static void getstring(char* buff) {
	if (scanf(" %s", buff) < 0) {
		printf("getstr error!\n");
	}
}

static void D_task();

int main()
{
	D_task();
	fflush(stdout);
	return 0;
}


static void D_task()
{
	int N, M;
	get2int(N, M);

	std::priority_queue<LLONG> dat;
	for (int i = 0; i < N; i++) {
		LLONG tmp;
		get1int<LLONG>(tmp);
		dat.push(tmp);
	}
	
	int ticket = M;
	while (ticket > 0) {
		LLONG value = dat.top(); dat.pop();
		value /= 2LL;
		dat.push(value);
		ticket--;
	}

	LLONG ans = 0;
	while(dat.size()) {
		ans += dat.top(); dat.pop();
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 1400
import java.util.*;
import java.io.*;
class Main{
  public static void main(String []args) {
      Scanner sc=new Scanner(System.in);
      int i=1;
      while (true) {
          int x=sc.nextInt();
          if(x==0){
            break;
          }
          System.out.println("Case "+i+": "+x);
          i++;
      }
  }
}


Measured memory_bytes: 41416
/*
We will not return to the countless mistakes of the past
I will not relive the failures of the man I once was

Only through dedication will I destroy all preconception

No longer will I let myself be truly satisfied with the standard
We will not return to the countless mistakes of the past

Only through dedication will I destroy all preconception

Let this be
Be the day
Day of my
My declaration
Let this be the day of my declaration

Join me,
Walk with me

Shatter the bonds that tie us
To what we strive to never be

Join me,
Walk with me
*/
#include<bits/stdc++.h>

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

using namespace std;

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn=1000001;

int gcd(int a,int b){

if(a<b) swap(a,b);
if(a%b==0) return b;
return gcd(b,a%b);

}

int main(){

int n;
cin>>n;
cout<<2*n/gcd(2,n)<<endl;
return 0;

}


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

typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PLL;
typedef pair<P,P> PP;
typedef vector<ll> VECLL;
typedef vector<P> VECP;
typedef priority_queue<P,VECP,greater<P> > PQP;
typedef priority_queue<ll, VECLL, greater<ll> > PQll;

#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define index_check(i,n) if(i > n-1 || i < 0) continue;
#define LINF (ll)1e18
#define INF (int)1e9
#define fs first
#define sc second

template<typename T>
ll sz(vector<T> vec){ return (ll)vec.size(); }
ll sz(string s){ return (ll)s.size(); }

ll gcd(ll a,ll b){ return ((!b) ?a :gcd(b, a%b)); }

int main(){

    ll n,c;
    cin >> n >> c;
    
    ll d[c][c] = {};
    rep(i,0,c) rep(j,0,c) cin >> d[i][j];
    
    ll grid[n][n];
    rep(i,0,n) rep(j,0,n) cin >> grid[i][j];

    ll sum[3][c];
    rep(i,0,3) rep(j,0,c) sum[i][j] = 0; 

    rep(i,0,n){
        rep(j,0,n){
            ll temp = (i+1+j+1)%3;
            rep(k,0,c){
                sum[temp][k] += d[grid[i][j]-1][k];
            }
        }
    }

    ll ans = LINF;
    rep(i,0,c){
        rep(j,0,c){
            if(i == j) continue;
            rep(k,0,c){
                if(i == k || j == k) continue;
                ll temp = sum[0][i] + sum[1][j] + sum[2][k];
                ans = min(temp,ans);
            }
        }
    }
    cout << ans << endl;

    return 0;
}




Measured memory_bytes: 5536
#include<bits/stdc++.h>
#define cs ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

using namespace std;
bool f(string s){
    int l=0,r=s.size()-1,k=s.size();
    while(l!=r){
        if(s[l]!=s[r]) return 0;
        l++;r--;
        if(l-r==1&&k%2==0) break;
    }
    return 1;
}
int main(){
    cs;
    string s;int k;
    cin>>s;
    k=s.size();
    if(f(s)&&f(s.substr(0,(k-1)/2))&&f(s.substr((k+1)/2,(k-1)/2))) cout<<"Yes";
    else cout<<"No";
}

Measured memory_bytes: 256
from sys import stdin

N = int(stdin.readline().rstrip())
S = stdin.readline().rstrip()
dp = [[0] * (N + 1) for _ in range(N + 1)]
res = 0

for i in range(N - 1, -1, -1):
    for j in range(N - 1, i, -1):
        if S[i] == S[j]:
            dp[i][j] = dp[i + 1][j + 1] + 1
        res = max(res, min(j - i, dp[i][j]))

print(res)


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

void solve(std::istream &in, std::ostream &out);

int main() {
#ifdef LOCAL
  freopen("../IO/a.in", "r", stdin);
//  freopen("../IO/a.in", "w", stdout);
#else
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);
  std::cout.tie(nullptr);
#endif
  solve(std::cin, std::cout);
  return 0;
}



void solve(std::istream &in, std::ostream &out) {
  int n;
  in >> n;
  vector<int> dp(n + 1);
  vector<int> h(n);
  for (int &i : h) {
    in >> i;
  }
  dp[0] = 0;
  dp[1] = abs(h[1] - h[0]);
  for (int i = 2; i < n; ++i) {
    dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
  }
  out << dp[n - 1] << '\n';
}


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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
int main(){
    long long n,x;
    cin>>n>>x;
    if(n>x){
        n%=x;
        cout<<min(x-n,n)<<endl;
    }
    else{
        cout<<min(x-n,n)<<endl;
    }
    return 0;

}
/*


*/


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

long long inv;
int *B;

long long countup(int *A, int p, int r);

int main(int argc, char *argv[])
{
  int n, i, j;
  int *A;

  inv = 0;

  scanf("%d", &n);
  A = (int *)malloc(sizeof(int) * n);
  B = (int *)malloc(sizeof(int) * n);
  for (i = 0; i < n; i++) scanf("%d", &A[i]);

  inv = countup(A, 0, n - 1);

  printf("%lld\n", inv);

  return 0;
}

long long countup(int *A, int p, int r)
{
  int q = p + (r-p)/2;
  int i, j, k, tmp;
  long long ct = 0;

  if (r - p < 3) {
    for (i = p; i < r; i++) {
      for (j = r; j > i; j--) {
	if (A[j] < A[j-1]) {
	  tmp = A[j-1];
	  A[j-1] = A[j];
	  A[j] = tmp;
	  ct++;
	}
      }
    }
    return ct;
  }
  ct += countup(A, p, q);
  ct += countup(A, q+1, r);

  i = p;
  j = q + 1;
  for (k = p; k <= r; k++) {
    if (i >= q + 1 || j >= r + 1) {
      if (i >= q + 1) B[k] = A[j++];
      else B[k] = A[i++];
    } else {
      if (A[i] > A[j]) {
	B[k] = A[j];
	ct += q - i + 1;
	j++;
      } else {
	B[k] = A[i];
	i++;
      }
    }
  }
  for (k = p; k <= r; k++) A[k] = B[k];
  return ct;
}

Measured memory_bytes: 2164
// #include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <set>
#include <queue>
#include <cstdio>
#include <stack>
#include <list>
using namespace std;
#define rep(i, n) for(int i=0;i<n;i++)
#define irep(i, n) for(int i=n-1;i>=0;i--)
#define lrep(i, n) for(long long i=0;i<n;i++)
typedef long long ll;
typedef vector<long long> llv;
typedef vector<vector<long long> > llvv;
template <class T> T gcd(T n, T m){return m ? gcd(m, n%m):n;}

const int N = 2010;
const int MOD = 1e9+7;
int L[N][N];
int R[N][N];
int U[N][N];
int D[N][N];

int main(){
    int n,m;
    cin>>n>>m;
    vector<ll> a(n);
    rep(i,n)cin>>a[i];
    ll ans=0;
    rep(i,n){
        ans+=a[i];
    }
    sort(a.begin(),a.end());
    vector<pair<ll,ll> > bc(m);
    rep(i,m){
        cin>>bc[i].second>>bc[i].first;
    }
    sort(bc.begin(), bc.end());
    reverse(bc.begin(), bc.end());
    int idx=0;
    rep(i,m){
        rep(j,bc[i].second){
            if(bc[i].first>a[idx] && idx<n){
                ans-=a[idx++];
                // a.push_back(bc[i].first);
                ans+=bc[i].first;
            }else break;
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 2560
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    a,b=input().split()
    if a=='H':
        print(b)
    else:
        if b=='H':
            print('D')
        else:
            print('H')

if __name__ == '__main__':
    main()


Measured memory_bytes: 38256
#include <stdio.h>
#define N 5

int a[N] = {105, 135, 165, 189, 195}, c = 0;

int main()
{		
	int n, i;
	
	scanf("%d", &n);
	for(i = 0; i < N; i++){
		if(a[i] <= n) c++;
	}
	printf("%d\n", c);
			
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>



#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))

using namespace std;
int a,b,c;

int main(){
  cin >> a >> b;
  cout << a*a-b <<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define MSET(x,y) memset(x,y,sizeof(x))
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SZ size()
#define M 100005
#define ll long long
#define ld long double
#define INF 1e18
#define endl "\n"
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
using namespace std;
ll MOD = 1000000007;
string yes = "YES\n";
string no = "NO\n";
#define PI 3.1415926535 ]


bool isOverflow(long long a, long long b) 
{ 
    // Check if either of them is zero 
    if (a == 0 || b == 0)  
        return false; 
      
    long long result = a * b; 
    if (a == result / b) 
        return false; 
    else
        return true; 
} 


int32_t main() {
  fastio;
  ld a,b;
  cin>>a>>b;
  ll ans = a*b;
  cout<<ans<<endl;
}


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

using namespace std;
#define f first
#define s second
//#define int long long
#define st string
#define int long long
#define dear_crush int32_t main()
#define bari_ja return 0
#define forn(i, n) for (int i = 0; i < n; i++)
#define INF 1e9+5

dear_crush
{

int n;

std::cin >> n;

std::cout << ceil(n/2.00) << '\n';


bari_ja;
}


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

class Procon
{
    public Procon() { }
    static void Main(string[] agrs)
    {
        new Procon().Do();
    }

    Scanner cin;

    public void Do()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int[] p = cin.arrayInt();

        int count = 0;
        for (int i = 0; i < N; i++)
        {
            if (p[i] != i + 1)
            {
                count++;
            }
        }

        if (count > 2)
        {
            Console.WriteLine("NO");
            return;
        }

        Console.WriteLine("YES");
    }
}

class Scanner
{
    string[] s;
    int i;
    int max_i;

    public Scanner()
    {
        s = new string[0];
        max_i = 0;
        i = 0;
    }

    public string nextString()
    {
        if (i >= s.Length)
        {
            s = Console.ReadLine().Split(' ');
            max_i = s.Length;
            i = 0;
            if (max_i == 0)
            {
                return "";
            }
            return s[i++];
        }
        else
        {
            return s[i++];
        }
    }

    public int nextInt()
    {
        return int.Parse(nextString());
    }


    public long nextLong()
    {
        return long.Parse(nextString());
    }

    public double nextDouble()
    {
        return double.Parse(nextString());
    }

    public string[] arrayString()
    {
        return Console.ReadLine().Split(' ');
    }

    public int[] arrayInt()
    {
        string[] str = Console.ReadLine().Split(' ');
        int[] array = new int[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = int.Parse(str[i]);
        }
        return array;
    }

    public long[] arrayLong()
    {
        string[] str = Console.ReadLine().Split(' ');
        long[] array = new long[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = long.Parse(str[i]);
        }
        return array;
    }

    public double[] arrayDouble()
    {
        string[] str = Console.ReadLine().Split(' ');
        double[] array = new double[str.Length];
        for (int i = 0; i < str.Length; i++)
        {
            array[i] = double.Parse(str[i]);
        }
        return array;
    }
}



Measured memory_bytes: 11092
using System;
using System.Linq;
using System.Collections.Generic;

namespace AtCoder.Regular080
{
    public class ARC080D_GridColoring
    {
        public static void Main(string[] args)
        {
            
            int[] nums = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
            int h = nums[0];
            int w = nums[1];
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

            int[][] ans = new int[h][];
            for(int i=0;i<h;i++)
            {
                ans[i] = new int[w];
            }

            int cnt = 0;
            for(int i = 0; i < n; i++)
            {
                for(int j=0;j<a[i];j++)
                {
                    ans[cnt / w][cnt % w] = i + 1;
                    cnt++;
                }
            }
            
            for(int i = 0; i < h; i++)
            {
                if(i % 2 == 0)
                {
                    Console.Write(string.Join(" ",ans[i]));
                }
                else
                {
                    Console.Write(string.Join(" ", ans[i].Reverse()));
                }
                if( i != h - 1 )
                {
                    Console.WriteLine();
                }
            }

#if DEBUG
            Console.WriteLine("press Enter.");
            Console.ReadLine();
#endif

        }
    }
}

Measured memory_bytes: 13524
import java.io.IOException;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws IOException {
		//キーボード入力メソッド
		Scanner sc = new Scanner(System.in);

		//入力
		int a = sc.nextInt();
		int b = sc.nextInt();

		//処理
		int menseki = 0;
		int syuu = 0;

		menseki = a * b;
		syuu = (a + b) * 2;

		//出力
		System.out.println(menseki +" "+ syuu);

	}

}



Measured memory_bytes: 26288
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        int[] A = new int[N].Select(x => int.Parse(Console.ReadLine())).ToArray();

        Dictionary<int, int> paper = new Dictionary<int, int>();
        foreach (int num in A)
        {
            if (!paper.ContainsKey(num))
            {
                paper.Add(num, 0);
            }
            paper[num]++;
        }
        Console.WriteLine(paper.Values.Count(x => x % 2 == 1));
    }
}

Measured memory_bytes: 23132
Scanf.scanf " %s" @@ fun s ->
  let n = String.length s in
  for i=0 to n-1 do
    for j=i to n-1 do
      if String.(sub s 0 i ^ sub s j (n-j)) = "keyence" then (
        print_endline "YES"; exit 0)
    done
  done;
  print_endline "NO"

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int judge(char x){
  if(x=='r') return 2;
  else if(x=='s') return 0;
  else return 1;
}

int main(){
  int n,k;
  cin>>n>>k;
  int gomi=n/k+1;
  int dp[k][gomi][3];
  rep(i,k) rep(j,gomi) rep(l,3) dp[i][j][l] = 0;
  vi h(3);
  cin>>h[0]>>h[1]>>h[2];
  vector<char> t(n);
  rep(i,n) cin>>t[i];
  ll ans=0;
  rep(i,n){
    int x=judge(t[i]);
    if(i<k) ans+=h[x];
    else{
      if(t[i-k]==t[i]){
        t[i]=' ';
        continue;
      }else {
        ans+=h[x];
      }
    }
  }
  cout << ans;
}


Measured memory_bytes: 5676
#include <iostream>

using namespace std;

int S[5000];

int main(){
	int n;
	while(cin >> n,n){
		S[0] = 0;
		int tmp,sum = 0;
		for(int i = 1; i <= n; i++){
			cin >> tmp;
			sum += tmp;
			S[i] = sum;
		}
		tmp = S[1] - S[0];
		for(int i = 0; i <= n; i++){
			for(int j = i + 1; j <= n; j++){
				if(tmp < S[j] - S[i]) tmp = S[j] - S[i];
			}
		}
		cout << tmp << endl;
	}
	return 0;
}

Measured memory_bytes: 1172
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))

x = max(b)
y = min(c)

p = max(a[2],x)
q = min(a[3],y)

if q-p > 0:
    print("No War")
else:
    print("War")

Measured memory_bytes: 3064
def main():
    S = input()
    X = int(S)
    fx = sum(map(int, S))
    print('Yes' if X % fx == 0 else 'No')


if __name__ == '__main__':
    main()

# import sys
# input = sys.stdin.readline
# 
# sys.setrecursionlimit(10 ** 7)
# 
# (int(x)-1 for x in input().split())
# rstrip()
#
# def binary_search(*, ok, ng, func):
#     while abs(ok - ng) > 1:
#         mid = (ok + ng) // 2
#         if func(mid):
#             ok = mid
#         else:
#             ng = mid
#     return ok


Measured memory_bytes: 2940
#include <string>
#include <iostream>
#include <algorithm>
#include <array>
#include <math.h>
#include <vector>
using namespace std;

int main(){
    int n, height, count = 0;
    cin >> n >> height;
    for(int i = 0, k; i<n; i++){
        cin >> k;
        if (k >= height)
            count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, o, n) for (auto i = (o); (i) < (n); ++(i))
#define FOR1(i, n) FOR(i, 1, n+1)
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (auto i = (n)-1; (i) >= 0; --i)
#define REPI(itr, v) for (auto itr = v.begin(); itr != v.end(); ++itr)
#define REPIR(itr, v) for (auto itr = v.rbegin(); itr != v.rend(); ++itr)
#define fi first
#define se second
#define ll long long
#define int long long
#define V2(name, h, w) vector<vector<int> > name((h), vector<int>(w));

#define dl(line) cerr << "RUN: until " << (line) << "th line." << endl
#define dv(name, value) cerr << (name) << " is " << (value) << endl
#define da(v)  cerr << "["; REPI(itr, v){cerr << *itr << (itr != --v.end() ? ", " : "");} cerr << "]" << endl


void solve(std::vector<long long> A){
  int sum = 0;
  REP(i, (ll)A.size()) sum += A.at(i);
  if (sum >= 22) {
    cout << "bust" << endl;
  } else {
    cout << "win" << endl;
  }
}

signed main(){
  std::vector<long long> A(3);
  for(int i = 0 ; i < 3 ; i++){
    scanf("%lld",&A[i]);
  }
  solve(std::move(A));
}


Measured memory_bytes: 256
fun main(args:Array<String>?): Unit {
    val hex = Array(121){BooleanArray(121){false}}
    while(true){
        val (t, n) = readLine()!!.trim().split(' ').map(String::toInt)
        if (t == 0 && n == 0) return
        hex.forEach { it.fill(false) }
        repeat(n){
            val (x, y) = readLine()!!.trim().split(' ').map(String::toInt)
            hex[y + 60][x + 60] = true
        }
        val (sx, sy) = readLine()!!.trim().split(' ').map{it.toInt() + 60}
        hex[sy][sx] = true
        var current = listOf(HexPoint(sx, sy))
        repeat(t){
            current = current.flatMap {it.neighbors().filterNot{p -> hex[p.y][p.x]}}.distinct()
            current.forEach{hex[it.y][it.x] = true}
        }
        println(hex.sumBy{line -> line.count{it}} - n)
    }
}
data class HexPoint(val x: Int, val y: Int){
    fun neighbors(): Iterable<HexPoint> = listOf(HexPoint(0, 1), HexPoint(1, 1), HexPoint(1, 0), HexPoint(0, -1), HexPoint(-1, -1), HexPoint(-1, 0)).map{it + this}
    private operator fun plus(that: HexPoint): HexPoint = HexPoint(x + that.x, y + that.y)
}


Measured memory_bytes: 81952
//ABC102A
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
using namespace std;

int main(){
	int n;
	cin >> n;
	if(n%2 == 0){
		cout << n << endl;
	}else{
		cout << n*2 << endl;
	}
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int n, x[200010], a[200010];
int main() {
	scanf("%d", &n);
	for(int i=1; i<=n; i++) {
		scanf("%d", x+i);
		a[i] = x[i];
	}
	sort(a+1, a+n+1);
	for(int i=1; i<=n; i++) {
		int idx = lower_bound(a+1, a+n+1, x[i]) - a;
		if(idx <= n / 2) printf("%d\n", a[n/2+1]);
		else printf("%d\n", a[n/2]);
	}
	return 0;
}

Measured memory_bytes: 3712
def GCD(a, b):
    while a:
        a, b = b % a, a
    return b


if __name__ == "__main__":
    N, *A = map(int, open(0).read().split())
    g = 0
    for i in range(N):
        g = GCD(g, A[i])
    print(g)

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

#define int long long

signed main() {
    int x;
    cin >> x;

    for(int i = 0; i <= x; i++) {
        if(i * 100 <= x && x <= i * 105) {
            cout << 1 << endl;
            return 0;
        }
    }

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

Measured memory_bytes: 3624
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)
fun <T> Array<Array<T>>.print() {
    this.forEach {
        println(it.joinToString(" "))
    }
}

fun main() {
    val n = readInt()
    val set = mutableSetOf<String>()
    for (i in 0 until n) {
        val s = readString()
        set.add(s)
    }
    println(set.size)
}


Measured memory_bytes: 78460
#include<bits/stdc++.h>
using namespace std;
using Int = long long;
//BEGIN CUT HERE
template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  int n,height;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(int n_,F f,G g,H h,T ti,E ei):
    f(f),g(g),h(h),ti(ti),ei(ei){init(n_);}
  void init(int n_){
    n=1;height=0;
    while(n<n_) n<<=1,height++;
    dat.assign(2*n,ti);
    laz.assign(2*n,ei);
  }
  void build(int n_, vector<T> v){
    for(int i=0;i<n_;i++) dat[n+i]=v[i];
    for(int i=n-1;i;i--)
      dat[i]=f(dat[(i<<1)|0],dat[(i<<1)|1]);
  }
  T reflect(int k){
    return g(dat[k],laz[k]);
  }
  inline void eval(int k){
    if(laz[k]==ei) return;
    laz[(k<<1)|0]=h(laz[(k<<1)|0],laz[k]);
    laz[(k<<1)|1]=h(laz[(k<<1)|1],laz[k]);
    dat[k]=reflect(k);
    laz[k]=ei;
  }
  void update(int a,int b,E x){
    a+=n;b+=n;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval((b-1)>>i);
    for(int l=a,r=b;l<r;l>>=1,r>>=1){
      if(l&1) laz[l]=h(laz[l],x),l++;
      if(r&1) --r,laz[r]=h(laz[r],x);
    }
    while(a>>=1)
      dat[a]=f(reflect((a<<1)|0),reflect((a<<1)|1));
    b--;
    while(b>>=1)
      dat[b]=f(reflect((b<<1)|0),reflect((b<<1)|1));
  }
  T query(int a,int b){
    a+=n;b+=n;
    for(int i=height;i;i--) eval(a>>i);
    for(int i=height;i;i--) eval((b-1)>>i);
    T vl=ti,vr=ti;
    for(int l=a,r=b;l<r;l>>=1,r>>=1) {
      if(l&1) vl=f(vl,reflect(l++));
      if(r&1) vr=f(reflect(--r),vr);
    }
    return f(vl,vr);
  }
};
//END CUT HERE
signed DSL_2_G(){
  int n,q;
  scanf("%d %d",&n,&q);
  using P = pair<Int, Int>;
  auto f=[](P a,P b){return P(a.first+b.first,a.second+b.second);};
  auto g=[](P a,Int b){return P(a.first+b*a.second,a.second);};
  auto h=[](Int a,Int b){return a+b;};
  
  SegmentTree<P,Int> ch(n,f,g,h,P(0,0),0);  
  ch.build(n,vector<P>(n,P(0,1)));
  for(int i=0;i<q;i++){
    int c,s,t,x;
    scanf("%d",&c);
    if(c){
      scanf("%d %d",&s,&t);
      printf("%lld\n",ch.query(s-1,t).first);
    }else{
      scanf("%d %d %d",&s,&t,&x);
      ch.update(s-1,t,x);
    }
  }
  return 0;
}

/*
  verified on 2018/08/21
  http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=DSL_2_G&lang=jp
*/

signed main(){
  DSL_2_G();
  return 0;
}



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

int main()
{
    int num =1, n,k;
    cin >> n >> k;
    for(int i=0; i<n; i++)
    {
        if(num * 2 < num + k) num *= 2;
        else num += k;
    }
    cout << num << endl;
}

Measured memory_bytes: 3612
import scala.math._

object Main extends App {

  val YES = "YES"
  val Yes = "Yes"
  val NO = "NO"
  val No = "No"
  ///////////////////////////////////////////

  val sc = new java.util.Scanner(System.in)
  val n = sc.nextInt
  val k = sc.nextInt
  val x = sc.nextInt
  val y = sc.nextInt
//  val list = List.fill(3)(sc.nextInt)

  val ans = if (n <= k) n * x else x * k + y * (n - k)

  println(ans)


  ///////////////////////////////////////////

  def bigIterator(start: BigInt, end: BigInt, step: BigInt = 1) =
    Iterator.iterate(start)(_ + step).takeWhile(_ <= end)

  def lcm(a :Int, b :Int): Int =
    a / gcd(a, b) * b

  def lcm(a :Long, b :Long): Long =
    a / gcd(a, b) * b

  def gcd(a: Int, b: Int): Int =
    if (b == 0) a else gcd(b, a % b)

  def gcd(a: Long, b: Long): Long =
    if (b == 0) a else gcd(b, a % b)

  def setOrUpdated[A, B](a: Map[A, B], key: A, value: B, f: (B, B) => B) =
    a.get(key) match {
      case Some(v) => a.updated(key, f(value, v))
      case _ => a + (key -> value)
    }
}

Measured memory_bytes: 25548
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <numeric>
#include <stdio.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <cmath>
#include <iterator>
#include <map>
#include <fstream>
#include <cctype>

using namespace std;

#define Int int64_t

void printVec(std::vector<int>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}
void printVec1(std::vector<string>& vec) {
	std::cout << "";
	for (auto it = vec.begin(); it != vec.end(); ++it) {
		std::cout << *it << " ";
	}
	std::cout << std::endl;
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
	vector.erase(vector.begin() + index);
}

int vector_finder(std::vector<string> vec, string number) {
	auto itr = std::find(vec.begin(), vec.end(), number);
	size_t index = std::distance(vec.begin(), itr);
	if (index != vec.size()) { // 発見できたとき
		return 1;
	}
	else { // 発見できなかったとき
		return 0;
	}
}

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



int main() {
	Int a, b; cin >> a >> b;

	if ((a + b) % 2 == 0) cout << (a + b) / 2;
	else cout << "IMPOSSIBLE";

	cout << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};

vector<int> v;

void rec(ll num){
    if(1e9 <= num) return ;

    v.emplace_back(num);

    rec(num * 10 + 3);
    rec(num * 10 + 5);
    rec(num * 10 + 7);
}

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

    int n; cin>>n;

    rec(0);

    set<int> num357;
    for(auto i:v){
        bool is3 = false;
        bool is5 = false;
        bool is7 = false;

        int num = i;
        while(0 < num){
            if(num % 10 == 3) is3 = true;
            if(num % 10 == 5) is5 = true;
            if(num % 10 == 7) is7 = true;
            num /= 10;
        }

        if(is3 && is5 && is7) num357.emplace(i);
    }

    int ans = 0;
    for(auto i:num357){
        if(n < i) break;
        ans++;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1664
import java.util.*;
import java.io.*;
import java.awt.geom.*;
import java.math.*;

public class Main {

	static final Scanner in = new Scanner(System.in);
	static final PrintWriter out = new PrintWriter(System.out,false);
	static boolean debug = false;

	static int p, q, r;
	static String s;

	static int and(int x, int y) {
		return x < y ? x : y;
	}

	static int or(int x, int y) {
		return x > y ? x : y;
	}

	static int not(int x) {
		return x == 1 ? 1 : (x == 0 ? 2 : 0);
	}

	static int factor(int l) {
		if ('0' <= s.charAt(l) && s.charAt(l) <= '2') {
			return s.charAt(l) - '0';
		}
		if (s.charAt(l) == 'P') {
			return p;
		} else if (s.charAt(l) == 'Q') {
			return q;
		} else {
			return r;
		}
	}

	static int formula(int l, int r) {
		if (l == r) return factor(l);
		if (s.charAt(l) == '-') {
			return not(formula(l+1, r));
		}
		int lv = 0;
		for (int i=l; i<=r; i++) {
			if (s.charAt(i) == '(') {
				lv++;
			} else if (s.charAt(i) == ')') {
				lv--;
			}

			if (lv == 1 && s.charAt(i) == '*') {
				return and(formula(l+1, i-1), formula(i+1, r-1));
			} else if (lv == 1 && s.charAt(i) == '+') {
				return or(formula(l+1, i-1), formula(i+1, r-1));
			}
		}

		return -1;
	}

	static boolean solve() {
		s = in.next();
		if (s.equals(".")) return false;

		int ans = 0;

		for (p=0; p<=2; p++) {
			for (q=0; q<=2; q++) {
				for (r=0; r<=2; r++) {
					if (formula(0, s.length()-1) == 2) {
						ans++;
					}
				}
			}
		}

		out.println(ans);

		return true;
	}

	public static void main(String[] args) {
		debug = args.length > 0;
		long start = System.currentTimeMillis();

		while (solve());
		out.flush();

		long end = System.currentTimeMillis();
		dump((end-start) + "ms");
		in.close();
		out.close();
	}

	static void dump(Object... o) { if (debug) System.err.println(Arrays.deepToString(o)); }
}

Measured memory_bytes: 29492
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, std.random, core.bitop;

enum inf = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Pair = Tuple!(int, "a", int, "b");

void main() {
    auto a = readln.split.to!(int[]).sort!"a > b"();
    auto ans = a[0] * 10 + a[1] + a[2];
    writeln(ans);
}




void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


Measured memory_bytes: 256
import java.util.*;

import static java.lang.System.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();

        Set<Integer> cnt = new HashSet<>();
        for (int i = 0; i < N; i++) {
            int a = sc.nextInt();

            if(cnt.contains(a)){
                cnt.remove(a);
            } else {
                cnt.add(a);
            }
        }

        out.println(cnt.size());
    }
}

Measured memory_bytes: 62192
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N = 2e5 + 10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
int n,a[N];
vector<int>v[N];
int sz[N],s[N];
LL get(int x){
	return 1ll*x*(x-1)/2;
}
LL ans[N];
void dfs(int x,int y){
	sz[x]=1;int pre=s[a[x]];
	for(auto k:v[x])if(k!=y){
		int g=s[a[x]];
		dfs(k,x);
		ans[a[x]]-=get(sz[k]-s[a[x]]+g);  
		sz[x]+=sz[k];
	}
	s[a[x]]=pre+sz[x];
	return ;
}

int main() {
  ios::sync_with_stdio(false);
  cin>>n;
  for(int i=1;i<=n;i++)cin>>a[i],ans[a[i]]++;
  for(int i=1;i<n;i++){
  	int s,t;
  	cin>>s>>t;
  	v[s].pb(t);
  	v[t].pb(s);
  }
  for(int i=1;i<=n;i++){
  	ans[i]+=1ll*n*(n-1)/2;
  }
  dfs(1,0);
  for(int i=1;i<=n;i++){
  	ans[i]-=get(n-s[i]);
  	cout<<ans[i]<<'\n';
  }
 	return 0;
}

Measured memory_bytes: 37076
#include <bits/stdc++.h>
typedef long long int ll;
using namespace std;
int main() {
    int n, m;
    cin >> n >> m;
    priority_queue<ll> q;
    for (int i = 0; i < n; i++) {
        int k;
        cin >> k;
        q.push(k);
    }
    while(m) {
        ll a1 = q.top();
        q.pop();
        q.push(a1/ 2);
        m--;
    }
    ll ret = 0;
    for (int i = 0; i < n; i++) {
        ret += q.top();
        q.pop();
    }
    cout << ret << endl;
    return 0;
}

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

using namespace std;

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

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const ll MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

template<typename T1, typename T2>
ostream& operator<<(ostream &os, const pair<T1, T2> p) {
  os << p.first << ":" << p.second;
  return os;
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);

  ll h, n; cin >> h >> n;
  vll a(n), b(n);
  for(int i=0;i<n;++i) {
    cin >> a[i] >> b[i];
  }

  ll res = 0;
  vvll dp(n+1, vll(h+1, LINF));
  dp[0][0] = 0;
  for(int i=0;i<n;++i) {
    for(int j=0;j<=h;++j) {
      if(dp[i][j] == LINF) continue;
      if(j + a[i] > h) {
        dp[i][h] = min(dp[i][h], dp[i][j] + b[i]);
      } else {
        dp[i][j+a[i]] = min(dp[i][j+a[i]], dp[i][j] + b[i]);
      }
      dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    }
    //printv(dp[i]);
  }
  //printv(dp[n]);
  
  cout << dp[n][h] << endl;
}


Measured memory_bytes: 78592