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

using namespace std;

using ll = long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vi = vector<int>;
using vl = vector<ll>;

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

#define CHMIN(a,b) (a)=min((a),(b))
#define CHMAX(a,b) (a)=max((a),(b))
#define ALL(v) (v).begin(),(v).end()

#define DEBUG(x) cerr<<#x<<": "<<(x)<<endl
#define DEBUG_VEC(v) cerr<<#v<<": ";REP(__i,(v).size())cerr<<((v)[__i])<<", ";cerr<<endl

const ll MOD = 1000000007ll;

const int NIL = 1<<30;

int q;
int t[252521];
int a[252521], b[252521];

const int N = 1<<18;
pll dat[2*N];
pll f(pll a, pll b){
    return pll(a.first+b.first, a.second+b.second);
}
void update(int x, pll v){
    x += N-1;
    dat[x] = v;
    while(x){
        x = (x-1)/2;
        dat[x] = f(dat[2*x+1],dat[2*x+2]);
    }
}
pll query(int l, int r, int a, int b, int k){
    if(r<=a || b<=l)return pll(0,0);
    if(l<=a && b<=r)return dat[k];
    int m = (a+b)/2;
    return f(query(l,r,a,m,2*k+1), query(l,r,m,b,2*k+2));
}

pii vs[252521];
int pos[252521];
int main(){
    scanf("%d",&q);
    REP(i,q){
        scanf("%d",t+i);
        if(t[i]==1)scanf("%d%d",a+i,b+i);
        else a[i]=b[i]=NIL;
    }
    int n = 0;
    REP(i,q)if(t[i]==1){
        vs[n++] = pii(a[i],i);
    }
    sort(vs,vs+n);
    REP(i,n)pos[vs[i].second] = i;
    
    int cnt = 0;
    ll bsum = 0;
    REP(i,q){
        if(t[i]==1){
            cnt++;
            bsum += b[i];
            int p = pos[i];
            update(p,pll(1,a[i]));
        }else{
            int w = (cnt-1)/2+1;
            int ok = n, ng = -1;
            while(abs(ok-ng)>1){
                int x = (ok+ng)/2;
                (query(0,x+1,0,N,0).first>=w ? ok : ng) = x;
            }
            int p = ok;
            ll aa = vs[p].first;
            ll ans = bsum;
            pll v = query(0,p,0,N,0);
            ans += aa*v.first - v.second;
            v = query(p,N,0,N,0);
            ans += v.second - aa*v.first;
            printf("%lld %lld\n",aa,ans);
        }
    }
    return 0;
}


Measured memory_bytes: 16128
#include <bits/stdc++.h>
#define ll long long int
#define pb push_back
#define mp make_pair
#define mod 1000000007
#define pi 3.141592653589793
using namespace std;


int main() {
//    cout << setprecision(10);
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);


    ll a, b;
    cin >> a >> b;
    if (abs(a - b) % 2 == 0) cout << abs(a - b) / 2 + min(a, b);
    else cout << "IMPOSSIBLE";



}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
int main() {
  string s; cin>>s;
  ll cnt=0;
  ll n=s.size();
  if(s.size()%2==0) {
    for(int i=0; i<n/2; i++) {
      if(s.at(n/2-1-i)!=s.at(n/2+i)) cnt++;
    }
  }
  else {
    for(int i=0; i<n/2; i++) {
      if(s.at(n/2-1-i)!=s.at(n/2+1+i)) cnt++;
    }
  }
  cout << cnt;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>
#include <numeric>
using namespace std;
typedef long long int ll;

#define EPS (1e-7)
#define INF 1e18
#define max(p,q)((p)>(q)?(p):(q))
#define min(p,q)((p)<(q)?(p):(q))
#define PI (acos(-1))

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

int main() {
    int N, M;
    cin >> N >> M;
    int ans = N * (N - 1) / 2 + M * (M - 1) / 2;
    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <ctime>
using namespace std;
double fen,jiao,v,wei,ma,x,y,pai,ca,cb,l[110],r[110],b[110],t[110];
int n,i,j;
double qiu(double a)
{
 return(a*a*ca+cb*a);
}
bool can(int a)
{
  double bt,x1,x2,y1,y2;
  y1=qiu(l[a]);
  if (l[a]<=x && (t[a]-y1)*(b[a]-y1)<=0) return(false);
  y2=qiu(r[a]);
  if (r[a]<=x && (t[a]-y2)*(b[a]-y2)<=0) return(false); 
  bt=cb*cb+4*ca*t[a];
  if (bt>0)
  {
    x1=(-cb+sqrt(bt))/2/ca;
	x2=(-cb-sqrt(bt))/2/ca;
	if (x1<=x && l[a]<=x1 && r[a]>=x1) return(false);
	if (x2<=x && l[a]<=x2 && r[a]>=x2) return(false); 
  }
  if (bt==0)
  {
    if (wei<=x && l[a]<=wei && r[a]>=wei) return(false);  
  }
  bt=cb*cb+4*ca*b[a];
  if (bt>0)
  {
    x1=(-cb+sqrt(bt))/2/ca;
	x2=(-cb-sqrt(bt))/2/ca;
	if (x1<=x && l[a]<=x1 && r[a]>=x1) return(false);
	if (x2<=x && l[a]<=x2 && r[a]>=x2) return(false); 
  }
  if (bt==0)
  {
    if (wei<=x && l[a]<=wei && r[a]>=wei) return(false);  
  }
  if (x>=l[a] && x<=r[a] && ma>t[a] && y<t[a]) return(false);
  if (x>=l[a] && x<=r[a] && ma>b[a] && y<b[a]) return(false);
  return(true);
}
int main()
{
  scanf("%d%lf%lf%lf",&n,&v,&x,&y);
  for (i=1;i<=n;i++) scanf("%lf%lf%lf%lf",&l[i],&b[i],&r[i],&t[i]);
  pai=3.1415926535898/2;
  fen=pai/50000;
  for (i=1;i<50000;i++)
  {
    jiao=i*fen;
    ca=-9.8/(2*cos(jiao)*cos(jiao)*v*v);
    cb=sin(jiao)/cos(jiao);
	if (qiu(x)<=y) continue;
	wei=-cb/ca/2;
	ma=qiu(x);
    for (j=1;j<=n;j++) if (!can(j)) break;
    if (j>n) break;
  }
  if (i<50000) printf("Yes\n"); else printf("No\n");
}

Measured memory_bytes: 1212
n=int(input())
lis=list(map(int,input().split()))
humi=0
c=0
for i in range(1,n):
    if lis[i]-lis[i-1]>=0:
        humi=0
    else:
        humi=(lis[i-1]-lis[i])
        lis[i]=lis[i]+humi
        c+=humi
        humi=0
print(c)

Measured memory_bytes: 32160
#include<cstdio>
#include<cstdlib>
using namespace std;

int top,S[1000];

void push(int x)
{
	S[++top]=x;
}

int pop()
{
	top--;
	return S[top+1];
}

int main()
{
	char s;int a,b;
	while(scanf("%s",&s)!=EOF)
	{
		if(s=='+')
		{
			a=pop(),b=pop();
			push(b+a);
		}
		else if(s=='-')
		{
			a=pop(),b=pop();
			push(b-a);
		}
		else if(s=='*')
		{
			a=pop(),b=pop();
			push(b*a);
		}
		else
		{
			push(atoi(&s));
		}
	}
	printf("%d\n",pop());
	return 0;
}

Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <vector>
using namespace std;
int main(void){
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    while(a >= b){
        b *= 2;
        k--;
    }
    while(b >= c){
        c *= 2;
        k--;
    }
    if(k >= 0) puts("Yes");
    else puts("No");
}


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

int main()
{
	int x;
	cin>>x;
	int p=x;
	while(1){
		bool flag = true;
		for(int i=2;i*i<=p;i++){
			if(p%i==0){
				flag = false;
				break;
			}
		}
		if(flag) break;
		p++;
	}
	cout<<p<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int N;cin>>N;
    vector<tuple<int,int,int>> V(N+1);
    V.at(0)=make_tuple(0,0,0);
    rep(n,0,N){int t,x,y; cin>>t>>x>>y; V.at(n+1)=make_tuple(t,x,y);}

    string ans="Yes";
    rep(n,1,N+1){
        int dst=abs(get<1>(V.at(n))-get<1>(V.at(n-1)))+abs(get<2>(V.at(n))-get<2>(V.at(n-1)));
        int dT=get<0>(V.at(n))-get<0>(V.at(n-1));
        if(dT<dst || dT%2!=dst%2){ans="No"; break;}
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 1408
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <cwchar>
#include <cwctype>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <codecvt>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, n) for(int i = 1; i <= (int)(n); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll INF=(1LL<<62);
const double inf=pow(10,10);
const ld pi=acosl(1);
const ll mod = 1000000007;
const int dx[4]={0,1,0,-1};
const int dy[4]={1,0,-1,0};
const int ddx[8]={1,0,-1,-1,-1,0,1,1};
const int ddy[8]={1,1,1,0,-1,-1,-1,0};

int main(){
	ll count=0;
	ll n;cin>>n;
	rep(i,n){
		ll a;cin>>a;
		if(a%2==1)count++;
	}
	if(count%2==1)cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <math.h>
#include <iomanip>
#include <bitset>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <utility>
#include <set>
#include <queue>
using namespace std;
typedef long long int ll;
typedef long double ld;
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; }
const long long INF = 1LL << 60;
typedef pair<ll,ll> pairs;
vector<pairs> p;
bool pairCompare(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.first < secondElof.first;
}
bool pairCompareSecond(const pair<double,ll>& firstElof, const pair<double,ll>& secondElof){
    return firstElof.second < secondElof.second;
}
#define MAX_N 100100
#define MOD 1000000007
bool x[MAX_N];
ll num[MAX_N];
ll fibl[MAX_N]={0};
// 四方向への移動ベクトル
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll fib(ll a){
    if (fibl[a]!=0)return fibl[a];
    if (a==0){
        return 0;
    }else if (a==1){
        return 1;
    }
    return fibl[a]=fib(a-1)+fib(a-2);
}
 
ll eratosthenes(ll n) {
    int p = 0;
    for (ll i=0; i<=n; ++i) x[i] = true;
    x[0] = x[1] = false;
    for(int i=2; i<=n; ++i) {
        if(x[i]) {
            p++;
            for(int j=2*i; j<=n; j+=i) x[j] = false;
        }
        
        num[i] = p;
    }
    return p;
}
 
ll gcd(ll a,ll b){
    if (a%b==0)return(b);
    else return(gcd(b,a%b));
}
 
ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

void  base_num(ll data,ll base){
    if(data==0) return;
    ll next=abs(data)%abs(base);
    if(data<0) next=(abs(base)-next)%abs(base);
    base_num((data-next)/base,base);
    cout << next;
}



int main(){
    string s;
    cin >> s;
    bool f=true;
    for (ll i=0;i<s.size();i++){
        if (s.size()-i>=5){
            if (s.substr(s.size()-i-5,5)=="dream" or s.substr(s.size()-i-5,5)=="erase"){
                i+=4;
                continue;
            }
        }
        if (s.size()-i>=6){
            if(s.substr(s.size()-i-6,6)=="eraser"){
                i+=5;
                continue;
            }
        }
        if (s.size()-i>=7){
            if (s.substr(s.size()-i-7,7)=="dreamer"){
                i+=6;
                continue;
            }
        }
        f=false;
    }
    if (f){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
    return 0;
}


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

using namespace std;

using int64 = long long;

template<class T> inline bool UpdateMin(T& a, T b) {
  if (a > b) { a = b; return 1; } return 0;
}
template<class T> inline bool UpdateMax(T& a, T b) {
  if (a < b) { a = b; return 1; } return 0;
}

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

  cout << setprecision(12);

  int n;
  cin >> n;
  vector<double> xs(n);
  vector<double> ys(n);
  vector<double> rs;
  rs.push_back(0.0);
  rs.push_back(2 * M_PI);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
    cin >> ys[i];
    double r = fmod((atan2(ys[i], xs[i]) + 2.0 * M_PI), 2.0 * M_PI);
    // cout << r << endl;
    rs.push_back(fmod(r + 0.5 * M_PI, 2.0 * M_PI));
    rs.push_back(fmod(r + 1.5 * M_PI, 2.0 * M_PI));
  }
  sort(rs.begin(), rs.end());

  double ans = 0.0;
  for (int i = 0; i + 1 < rs.size(); i++) {
    double r = (rs[i] + rs[i + 1]) / 2.0;
    // cout << r << endl;
    double sx = 0.0;
    double sy = 0.0;
    for (int j = 0; j < n; j++) {
      if (cos(r) * xs[j] + sin(r) * ys[j] > 0) {
        sx += xs[j];
        sy += ys[j];
      }
    }
    UpdateMax(ans, sx * sx + sy * sy);
  }
  cout << sqrt(ans) << endl;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>
#include <set>

using namespace std;
using ll = long long;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

const ll MOD = 1e9 + 7;
const ll INF = 1 << 30;
const ll INF2 = 9e18;
const double INF3 = 9e14;
const int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
const int tx[8] = { -1,0,1,-1,1,-1,0,1 }, ty[8] = { -1,-1,-1,0,0,1,1,1 };
#define ALL(x) (x).begin(),(x).end()
#define pb push_back
#define fr first
#define sc second




int main() {
	ll ans[26], a = INF;
	string s;
	cin >> s;
	for (int j = 0;j < 26;j++) {
		string t = s;
		int sum = 0;
		bool flag = 0;
		for (int i = 0;i < t.size();i++) {
			if (t[i] != char('a' + j))flag = true;
		}
		if (!flag) {
			ans[j] = INF;
			continue;
		}

		while (true) {
			bool fl = true;
			for (int i = 0;i < t.size() - 1;i++) {
				if (t[i] != t[i + 1])fl = false;
			}
			if (fl) {
				ans[j] = sum;
				break;
			}
			else {
				fl = true;
				sum++;
				for (int i = 0;i < t.size();i++) {
					if (t[i] == (char)('a' + j)) {
						t[i - 1] = (char)('a' + j);
					}
				}
				for (int i = 0;i < t.size();i++) {
					if (t[i] != (char)('a' + j)) {
						t = t.substr(0, i) + t.substr(i, t.size() - i - 1);
						fl = false;
						break;
					}
				}
				if (fl) {
					ans[j] = sum;
					break;
				}
			}
		}
	}
	for (int i = 0;i < 26;i++) {
		a = min(a, ans[i]);
	}
	cout << a << endl;
}

Measured memory_bytes: 256
void main()
{
    string n = readln.chomp;

    int total;
    foreach (d; n)
    {
        total += d - '0';
    }
    if (total == 1) total *= 10;

    total.writeln;
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

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

#define ALL(v) v.begin(), v.end()
#define V vector
#define P pair
#define ld long double
#define ll long long
#define mod 1000000007
#define IINF INT_MAX
#define INF 1LL << 30


int main() {
    int n, k; cin >> n >> k;
    V<int> h(n);
    for(int i = 0; i < n; i++) cin >> h[i];

    ll ans = 0;
    sort(ALL(h), greater<int>());
    for(int i = 0; i < n; i++){
        if(0 < k){
            k--;
            continue;
        }else{
            ans += h[i];
        }
    }
    cout << ans << endl;



    return 0;
}


Measured memory_bytes: 4004
a = list(map(int, input().split()))
for i in range(a[2]):
    if a[i%2]%2 == 1:
        a[i%2] -= 1
    a[1-i%2] += a[i%2]//2
    a[i%2] //= 2
print(a[0],a[1])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
//typedef long long int ll;
using namespace std;
int main()
{
    int k;
    cin >> k;
    int a,b;
    cin >> a >> b;
    int flag=0;
    for(int i=a;i<=b;++i)
    {
        if(i%k==0)
        flag=1;
}
if(flag==1)
cout << "OK" << endl;
else
{
    cout << "NG" << endl;
}

}

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

using namespace std;
#define rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define pb push_back

using namespace std;

int main(){

    int n,k;
    
    vector<int> v;
    cin>>n>>k;


    for(int i=0;i<n;i++){
        int tmp;
        cin>>tmp;
        v.push_back(tmp);
    }

    sort(v.rbegin(),v.rend());

    int ans=0;

    // for(int i=0;i<n;i++){
    //     cout<<v[i]<<" ";
    // }

    for(int i=0;i<k;i++){
        ans+=v[i];
    }

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

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

cnt=[0]*(n+1)
for a in A:
    cnt[a]+=1

total=0
for c in cnt:
    total+=c*(c-1)
total//=2

for k in range(n):
    print(total-cnt[A[k]]+1)

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




int main() {
    int n;
    string s;
    cin>>n>>s;
    int l=0;
    string str=s;
    for(int i=0;i<s.length();i++){
        if(s[i]=='('){
            l++;
        }
        else {
            l--;
            if(l<0){
                str='('+str;
                l++;
            }
        }
    }
    while(l--)str=str+')';
    cout<<str<<endl;
   
}


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

using namespace std;

int main()
{
    char s[4];
    cin >> s;
    int cnt = 0;
    for (int i = 0; i < strlen(s); i++)
        if (s[i] == 'o')
            cnt++;
    printf("%d\n", 700 + 100 * cnt);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <array>
#include <algorithm>
#include <vector>
#include <bitset>
#include <set>
#include <unordered_set>
#include <cmath>
#include <complex>
#include <deque>
#include <iterator>
#include <numeric>
#include <map>
#include <unordered_map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
#include <functional>
#include <cassert>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
#define ALL(v) v.begin(),v.end()
template < class T > inline bool chmax(T& a, T b) {if (a < b) { a=b; return true; } return false; }
template < class T > inline bool chmin(T& a, T b) {if (a > b) { a=b; return true; } return false; }
#define DEBUG_VLL(vec) REP(sz, vec.size()) std::cerr<<vec[sz]<<(sz==vec.size()-1?'\n':' ');

const long long MOD = 1000000007;
const long long HIGHINF = (long long)1e18;
const int INF = (int)1e9;

vll a;
vvll dp;

ll dfs(int left, int right) {
    if (dp[left][right] > -HIGHINF) return dp[left][right];
    if (left == right) return dp[left][right] = a[left];
    return dp[left][right] = max(a[left] - dfs(left + 1, right), a[right] - dfs(left, right - 1));
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    a.resize(n);
    for (int i = 0; i < n; i++) cin >> a[i];
    dp.resize(n, vll(n, -HIGHINF));
    cout << dfs(0, n - 1) << '\n';
    return 0;
}


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

typedef long long ll;

#define F first 
#define S second 
#define PB push_back
#define MP make_pair 
#define rep(i,a,b) for (ll i=a;i<b;i++)

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


int main()
{

    int h,a;
    cin>>h>>a;

    int res = h/a;
    int rem = h%a;
    if(rem!=0) res++;
    
    cout<<res<<endl;
    return 0; 
}



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

using ll = long long;
using Vi = vector<int>;
using Vl = vector<ll>;
using Pii = pair<int, int>;
using Pll = pair<ll, ll>;

constexpr int I_INF = numeric_limits<int>::max();
constexpr ll L_INF = numeric_limits<ll>::max();

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

void solve() {
    ll A, B;
    cin >> A;
    string S;
    cin >> S;
    B = 0;
    B += (S[0] - '0') * 100;
    B += (S[2] - '0') * 10;
    B += (S[3] - '0');

    ll ans = A * B;
    cout << ans / 100 << "\n";
}

//%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%

int main() {
#ifdef FASTIO
    cin.tie(0), cout.tie(0);
    ios::sync_with_stdio(false);
#endif
#ifdef FILEINPUT
    ifstream ifs("./in_out/input.txt");
    cin.rdbuf(ifs.rdbuf());
#endif
#ifdef FILEOUTPUT
    ofstream ofs("./in_out/output.txt");
    cout.rdbuf(ofs.rdbuf());
#endif
    solve();
    cout << flush;
    return 0;
}


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

// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }


int main(){
  int n;
  cin >> n;
  bool ramp[n];
  rep(i,n)ramp[i] = false;
  int a[n];
  rep(i,n){
    cin >> a[i];
    a[i] --;
  }
  int now = 0;
  int ans = 0;
  while(true){
    if(now == 1)break;
    if(ramp[now] == true){
      ans = -1;
      break;
    }
    ramp[now] = true;
    now = a[now];
    ans++;
  }
  cout << ans << endl;
}

Measured memory_bytes: 768
#include<iostream>
#include<queue>
#include<vector>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<functional>
#include<set>

using namespace std;

int road[20][100][100];
int cost[20][20001];
int mincost[100][100];
int movecost[100];
bool movee[100];
int INF = 1 << 28;

#define lengthof(x) (sizeof(x) / sizeof(*(x)))

struct Edge{
public:
	int from;
	int to;
	int cost;
	Edge(){
		from=0;to=0;cost=0;
	}
	Edge(int f,int t,int c){
		from=f;to=t;cost=c;
	}
	bool operator< (const Edge &e) const{
		return cost > e.cost;
	}
};

int usecost(int c,int s,int e){
	int roadsize = road[c][s][e];
	if(roadsize == INF){
		return INF;
	}
	return cost[c][roadsize-1];
}

int main(){
	while(true){
		int n,m,c,s,g;
		
		//初期化
		fill((int*)road,(int*)(road+lengthof(road)),INF);
		fill((int*)cost,(int*)(cost+lengthof(cost)),INF);
		fill((int*)mincost,(int*)(mincost+lengthof(mincost)),INF);
		fill(movecost,movecost+100,INF);
		memset(movee,false,sizeof(movee));

		cin >> n >> m >> c >> s >> g;
		if(n==0){
			break;
		}

		//線路
		for(int i=0;i<m;i++){
			int x,y,d,cc;
			cin >> x >> y >> d >> cc;
			road[cc-1][y-1][x-1] = road[cc-1][x-1][y-1] = min(road[cc-1][y-1][x-1],d);
		}
		for(int i=0;i<n;i++){
			for(int j=0;j<c;j++){
				road[j][i][i] = 0;
			}
		}

		for(int i=0;i<c;i++){
			for(int k=0;k<n;k++){
				for(int ii=0;ii<n;ii++){
					for(int jj=0;jj<n;jj++){
						road[i][ii][jj] = min(road[i][ii][jj],road[i][ii][k]+road[i][k][jj]);
					}
				}
			}
		}

		//運賃計算
		int p[20];
		for(int i=0;i<c;i++){
			cin >> p[i];
		}
		for(int i=0;i<c;i++){
			int index = 0;
			vector<int> next;
			vector<int> add;
			for(int j=0;j<p[i]-1;j++){
				int buf;
				cin >> buf;
				next.push_back(buf);
			}
			next.push_back(-1);
			for(int j=0;j<p[i];j++){
				int buf;
				cin >> buf;
				add.push_back(buf);
			}
			cost[i][0] = add[0];
			for(int j=1;j<20000;j++){
				if(j==next[index]){
					index++;
				}
				cost[i][j] = cost[i][j-1] + add[index];
			}
		}
		
		//各路線の駅同士を結ぶ
		for(int i=0;i<c;i++){
			set<int> slist;
			for(int j=0;j<n;j++){

			}
		}

		//各路線のA→B駅までの運賃計算
		for(int i=0;i<n;i++){
			for(int j=0;j<n;j++){
				for(int k=0;k<20;k++){
					mincost[i][j] = min(mincost[i][j],usecost(k,i,j));
				}
			}
		}

		priority_queue<Edge> que;
		//vector<Edge> que;
		Edge ed;
		ed.from = s-1;
		ed.to = s-1;
		ed.cost = 0;
		que.push(ed);
		movecost[s-1] = 0;
		movee[s-1] = true;

		while(!que.empty()){
			Edge edg = que.top();
			que.pop();
			movee[edg.from] = true;
			if(movee[g-1]){
				break;
			}
			for(int i=0;i<n;i++){
				if(mincost[edg.to][i] != INF && !movee[i]){
					if(movecost[i] > edg.cost+mincost[edg.to][i]){
						Edge bufed;
						bufed.from = edg.to;
						bufed.to = i;
						bufed.cost = edg.cost+mincost[edg.to][i];
						que.push(bufed);
						movecost[i] = edg.cost+mincost[edg.to][i];
					}
				}
			}
		}
		if(movecost[g-1] == INF){
			cout << -1 << endl;
		}else{
			cout << movecost[g-1] << endl;
		}
	}
}

Measured memory_bytes: 3732
#include <cstdio>           // printf(), scanf()
#include <cmath>            // sqrt()
#include <algorithm>        // min()

using namespace std;
static const int MAX_N = 100;
static const double EPS = 1e-10;

class Point
{
public:
	double x, y;

	Point(double x = 0, double y = 0): x(x), y(y) {}
	Point operator - (Point p) { return Point(x - p.x, y - p.y); }
};

typedef Point Vector;

Point g[MAX_N];
Point p;
int n;

double
norm(Vector a)
{
	return a.x * a.x + a.y * a.y;
}

double
abs(Vector a)
{
	return sqrt(norm(a));
}

double
dot(Vector a, Vector b)
{
	return a.x * b.x + a.y * b.y;
}


double
cross(Vector a, Vector b)
{
	return a.x * b.y - a.y * b.x;
}

int
solve()
{
	bool f = false;
	for (int i = 0; i < n; ++i)
	{
		Point a = g[i] - p;
		Point b = g[(i + 1) % n] - p;
		if (abs(cross(a, b)) < EPS && dot(a, b) < EPS)
			return 1;

		if (a.y > b.y)
			swap(a, b);

		if (a.y < EPS && EPS < b.y && cross(a, b) > EPS)
			f = !f;
	}

	return f ? 2 : 0;
}

int
main(int argc, char** argv)
{
	int x, y;
	int q;

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

	scanf("%d", &q);
	while (q--)
	{
		scanf("%d %d", &x, &y);
		p.x = x, p.y = y;
		printf("%d\n", solve());
	}

	return 0;
}

Measured memory_bytes: 2748
n,a,b = map(int, input().split())
hl = []
for _ in range(n):
    h = int(input())
    hl.append(h)


ok, ng = 10**10, 0
while abs(ok-ng) > 1:
    mid = (ok+ng)//2
    ok_flag = True
    cnt = 0
    for h in hl:
        rem = h - mid*b
        if rem > 0:
            need = (rem-1)//(a-b) + 1
        else:
            need = 0
        cnt += need
    # ...
    if cnt <= mid:
        ok = mid
    else:
    	ng = mid
print(ok)

Measured memory_bytes: 80976
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
const int MOD = 1000000007;

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

  int n;
  cin >> n;
  vector<ll> a(n);
  rep(i, 0, n) cin >> a[i];

  ll ans = 0;
  rep(i, 0, 60) {
    ll x = 0;
    rep(j, 0, n) if (a[j] >> i & 1) x++;
    ll now = x * (n - x) % MOD;
    rep(j, 0, i) now = now * 2 % MOD;
    ans += now;
    ans %= MOD;
  }
  cout << ans << endl;
}


Measured memory_bytes: 2560
#include <iostream>
#include <queue>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <iomanip>
#include <cmath>
#include <cstdlib>
#include <math.h>
#include <stdlib.h>
#include <numeric>
#include <functional>
int main(){
	int a, b, ans;
	std::cin >> a >> b;
	ans = (b - 1) / (a - 1);
	if((b - 1) % (a - 1) != 0){
		ans++;
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;

#define ran 555

int n, lim;
int a[ran];
long long pre[ran], suf[ran];
int rem[ran], nr;

bool chk(int mo) {
	/*int reqd = 0;
	vector<int> v;
	for(int i = 0; i < n; i++)
	{
		int cur = a[i] % x;
		v.push_back(cur);
	}
	sort(v.begin(), v.end());
	int l = 0, r = v.size() - 1;
	int rem = 0;
	while(l <= r)
	{
		if(rem <= 0)
		{
			rem += v[l];
			reqd += v[l];
			l++;
		}
		else
		{
			rem -= (x - v[r]);
			reqd += (x - v[r]);
			r--;
		}
	}
	if(reqd > 2 * lim)
		return 0;
	if(rem != 0)
		return 0;
	return 1;*/
	
	nr = 0;
	for(int i=0;i<n;i++) {
		if (a[i] % mo) rem[nr++] = a[i]%mo;
	}
	if (!nr) return true;
	sort(rem, rem+nr);
	
	int mi = 2e9;
	for(int i=0;i<nr;i++) {
		pre[i] = rem[i];
		if(i>0) pre[i] += pre[i-1];
	}
	for(int i=nr-1;i>=0;i--) {
		suf[i] = mo - rem[i];
		if(i<nr-1) suf[i] += suf[i+1];
	}
	/*if (mo==3) {
		printf("%d\n", nr);
		for(int i=0;i<nr;i++) printf("%d%c", pre[i], i<nr-1 ? ' ' : '\n');	
		for(int i=0;i<nr;i++) printf("%d%c", suf[i], i<nr-1 ? ' ' : '\n');
	}*/
	for(int i=1;i<nr;i++)
		mi = min((long long)mi, max(pre[i-1], suf[i]));
	//if (mi<=lim) printf("%d %d\n", mo, mi);
	return (mi <= lim);
}

int main() {
	scanf("%d%d", &n, &lim);
	int s = 0;
	for(int i=0;i<n;i++) {
		scanf("%d", &a[i]);
		s += a[i];
	}
	
	int ans = 1;
	for(int i=1;i*i<=s;i++) {
		if (s%i) continue;
		if(chk(i)) ans = max(ans, i);
		if(chk(s/i)) ans = max(ans, s/i);
	}
	printf("%d\n", ans);
	
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>
#include<math.h>

int main(void)
{
	int n,i;
	double x[100], y[100], d1=0,tmp,d2=0,d3=0,d4=0;

	scanf("%d", &n);

	for (i = 0; i < n;i++) {
		scanf("%lf", &x[i]);
	}

	for (i = 0; i < n; i++) {
		scanf("%lf", &y[i]);
	}

	for (i = 0; i < n; i++) {//p=1のとき
		tmp = 0;

		d1 += fabs(x[i] - y[i]);

	}

	printf("%f\n", d1);//p=1のときおわり

	for (i = 0; i < n; i++) {//p=2のとき

		d2 += pow((x[i] - y[i]), 2);
	}

	printf("%f\n", pow(d2,1.0/2.0));//p=2のときおわり


	for (i = 0; i < n; i++) {//p=3のとき

		d3 += fabs(pow((x[i] - y[i]), 3));
	}

	printf("%f\n", pow(d3, 1.0 / 3.0));//p=3のときおわり

	for (i = 0; i < n; i++) {
	
		if (d4 < fabs(x[i] - y[i])) {

			d4 = fabs(x[i] - y[i]);
		}
	}
	printf("%f\n", d4);
			
			return 0;
}


Measured memory_bytes: 2104
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
int map[100005];
int main()
{
	int n,maxn=0,mine=666666,sum=0;
	memset(map,0,sizeof(map));
	cin>>n;
	while(n--)
	{
		int a,b;
		cin>>a>>b;
		maxn=max(a,maxn);
		maxn=max(b,maxn);
		mine=min(a,mine);
		mine=min(a,mine);
		for(int i=a; i<=b; i++)
		{
			if(map[i])
				continue;
			else
				map[i]=1;
		}
	}
	for(int i=mine; i<=maxn; i++)
		if(map[i])
			sum++;
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 640
//
// Created by 佐竹俊哉 on 2019/11/12.
//

#include <bits/stdc++.h>
using namespace std;

typedef pair<int, int> pii;
typedef long long ll;
template<class T> using V = vector<T>;
template<class T> using VV = V<V<T>>;

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define fi first
#define se second
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define ALL(c) (c).begin(),(c).end()
#define dump(x) cout << #x << " = " << (x) << endl
constexpr ll TEN(int n) { return (n == 0) ? 1 : 10 * TEN(n-1); }

template<class T, class U> void chmin(T& t, const U& u) { if (t > u) t = u; }
template<class T, class U> void chmax(T& t, const U& u) { if (t < u) t = u; }

template<class T, class U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os<<"("<<p.first<<","<<p.second<<")";
    return os;
}

template<class T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os<<"{";
    rep(i, v.size()) {
        if (i) os<<",";
        os<<v[i];
    }
    os<<"}";
    return os;
}

int main() {
    int N; cin >> N;
    int odd = (N + 1) / 2;
    double ans = (double)odd / N;
    printf("%.8f\n", ans);
    return 0;
}

Measured memory_bytes: 256
import Control.Monad

inGrid :: (Int,Int)->Bool
inGrid (x,y)
    | (0<=y&&y<9)&&(even y)&&(0<=x&&x<4) = True
    | (0<=y&&y<9)&&(odd y) &&(0<=x&&x<5) = True
    | otherwise                          = False

isWall grid (x,y)
    | (inGrid (x,y))&&(((grid!!y)!!x)=='1') = True
    | otherwise                             = False

solve :: [[Char]]->(Int,Int)->[Char]->[Char]
solve grid (i,j) (x:xs)
    | ((i,j)==(0,0)&&(x=='L'))||
       (i,j)==(0,1)&&(x=='U')            = (x:xs)
    --
    | (x=='R')&&(isWall grid (i+1,j-1))  = solve grid (i+1,j-1) ('U':x:xs)
    | (x=='R')&&(isWall grid (i+1,j))    = solve grid (i+1,j)   ('R':x:xs)
    | (x=='R')&&(isWall grid (i+1,j+1))  = solve grid (i+1,j+1) ('D':x:xs)
    | (x=='R')                           = solve grid (i,j)     ('L':x:xs)
    --
    | (x=='L')&&(isWall grid (i,j+1))    = solve grid (i,j+1)   ('D':x:xs)
    | (x=='L')&&(isWall grid (i-1,j))    = solve grid (i-1,j)   ('L':x:xs)
    | (x=='L')&&(isWall grid (i,j-1))    = solve grid (i,j-1)   ('U':x:xs)
    | (x=='L')                           = solve grid (i,j)     ('R':x:xs)
    --
    | (x=='D')&&(isWall grid (i,j+1))    = solve grid (i,j+1)   ('R':x:xs)
    | (x=='D')&&(isWall grid (i,j+2))    = solve grid (i,j+2)   ('D':x:xs)
    | (x=='D')&&(isWall grid (i-1,j+1))  = solve grid (i-1,j+1) ('L':x:xs)
    | (x=='D')                           = solve grid (i,j)     ('U':x:xs)
    --
    | (x=='U')&&(isWall grid (i-1,j-1))  = solve grid (i-1,j-1)  ('L':x:xs)
    | (x=='U')&&(isWall grid (i,j-2))    = solve grid (i,j-2)   ('U':x:xs)
    | (x=='U')&&(isWall grid (i,j-1))    = solve grid (i,j-1)   ('R':x:xs)
    | (x=='U')                           = solve grid (i,j)     ('D':x:xs)


main = do
    grid <- replicateM 9 getLine
    putStrLn $ reverse $ solve grid (0,0) ['R']

Measured memory_bytes: 3536
#include <iostream>
#include <string>
#include <fstream>

using namespace std;

int main()
{
	int x, y;
	char a[200000], b[200000];
	std::string s, t;
	cin >> s >> t;
	size_t r = s.length();
	y = r;
	s.copy(a, y);
	t.copy(b, y);
	x = 0;
	for (int i = 0; i < y; i++) {
		if (a[i] != b[i]) x = x + 1;
	}
	cout << x;

	return 0;
}

Measured memory_bytes: 4144
#include <bits/stdc++.h>
#define long long long int
using namespace std;

// @author: pashka

int main() {
    ios::sync_with_stdio(false);

    long a, b, n;
    cin >> a >> b >> n;
    cout << a * min(n, b - 1) / b;

    return 0;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
using namespace std;
int n,m,a[100005],b[100005],x,y;
int main()
{
	scanf("%d%d%d%d",&n,&m,&x,&y);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=m;i++)
		scanf("%d",&b[i]);
	sort(a+1,a+n+1);
	sort(b+1,b+m+1);
	a[n]++;
	if(x<a[n]&&a[n]<=y&&a[n]<=b[1])
		printf("No War");
	else
		printf("War");
}

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

#define LL long long
#define REP(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define ALL(x) (x).begin(),(x).end()
const int IINF = 1e9;
const LL LINF = 1e18;
const LL mod = 1e9+7;

struct sushi {
    LL x;
    LL v;
};

int main() {
    LL N, C;
    cin >> N >> C;
    vector<sushi> sushies;
    sushies.resize(N);
    REP(i, N) {
        cin >> sushies[i].x >> sushies[i].v;
    }

    vector<LL> sum;
    sum.resize(N + 1);
    sum[0] = 0;
    FOR(i, 1, N + 1) {
        sum[i] = sum[i - 1] + sushies[i - 1].v;
    }

    vector<sushi> forward;
    vector<sushi> back;
    vector<sushi> forward2;
    vector<sushi> back2;

    forward.resize(N + 1);
    back.resize(N + 1);
    forward2.resize(N + 1);
    back2.resize(N + 1);

    forward[0] = {0, 0};
    back[0] = {0, 0};
    forward2[0] = {0, 0};
    back2[0] = {0, 0};

    FOR(i, 1,N + 1) {
        if(forward[i - 1].v - forward[i - 1].x < sum[i] - sushies[i - 1].x) {
            forward[i] = {sushies[i - 1].x, sum[i]};
        }else{
            forward[i] = forward[i - 1];
        }
        if(back[i - 1].v - back[i - 1].x < sum[N] - sum[N - i] - C + sushies[N - i].x) {
            back[i] = {C - sushies[N - i].x, sum[N] - sum[N - i]};
        }else{
            back[i] = back[i - 1];
        }

        if(forward2[i - 1].v - forward2[i - 1].x*2 < sum[i] - sushies[i - 1].x*2) {
            forward2[i] = {sushies[i - 1].x, sum[i]};
        }else{
            forward2[i] = forward2[i - 1];
        }
        if(back2[i - 1].v - back2[i - 1].x*2 < sum[N] - sum[N - i] - (C - sushies[N - i].x)*2) {
            back2[i] = {C - sushies[N - i].x, sum[N] - sum[N - i]};
        }else{
            back2[i] = back2[i - 1];
        }
    }
    LL res = 0;
    REP(i, N + 1) {
        res = max<LL>(res, forward[i].v + back2[N - i].v - forward[i].x - back2[N - i].x*2);
        res = max<LL>(res, forward2[i].v + back[N - i].v - forward2[i].x*2 - back[N - i].x);
    }
    cout << res << endl;
    return 0;
}



Measured memory_bytes: 8832
#include "bits/stdc++.h"

//#include <atcoder/all>

using namespace std;
//using namespace atcoder;

//#define int long long
#define ll long long

ll INF = (1LL << 60);
int mod = 998244353;
using P = pair<ll, ll>;

signed main() {
	int a, b, c; cin >> a >> b >> c;
	if (a + b + c >= 22)cout << "bust" << endl;
	else cout << "win" << endl;
	return 0;
}



Measured memory_bytes: 3584
import sys
sys.setrecursionlimit(500000)

N, K = map(int,input().split())

T = [[] for i in range(N)]
for i in range(N-1):
    a, b = map(int,input().split())
    T[a-1].append(b-1)
    T[b-1].append(a-1)

ans = 1
def dfs(i, bb, b, p):
    global ans
    ans = (ans*(K-bb-b))%(10**9+7)
    cnt = 0
    for j in T[i]:
        if j == p:
            continue
        dfs(j, b + cnt, 1, i)
        cnt += 1

dfs(0, 0, 0, -1)
print(ans)

Measured memory_bytes: 87340
#include <iostream>
#include <fstream>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <algorithm>
#include <functional>
#include <stack>
#include <queue>
#include <string>
#include <map>
#include <unordered_map>
#include <bitset>
#include <numeric>
#include <vector>
#include <unordered_set>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <numeric>
#include <cstdlib>
#include <bits/stdc++.h>


using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;

const ll mod=1000000007ll;
const ll inf=1000000000000000ll;

const ll nmax=50;

bool visited[nmax+1][nmax+1];
ll field[nmax+1][nmax+1];

ll h,w;

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

ll dfs(ll n){
    bool fl,fl3,fl5,fl7;
    stack<string> stk;
    stk.push("3");
    stk.push("5");
    stk.push("7");
    ll ct=0;
    while(!(stk.empty())){
        string t=stk.top();stk.pop();
        if(stoll("3"+t)<=n) stk.push("3"+t);
        if(stoll("5"+t)<=n) stk.push("5"+t);
        if(stoll("7"+t)<=n) stk.push("7"+t);
        //各桁チェック
        fl3=fl5=fl7=false;
        fl=true;
        for(ll j=0;j<t.length();j++){
            if((t[j]=='3')||(t[j]=='5')||(t[j]=='7')){
                if(t[j]=='3')fl3=true;
                if(t[j]=='5')fl5=true;
                if(t[j]=='7')fl7=true;
            }
            else{
                fl=false;
                break;
            }
        }
        if(fl&&fl3&&fl5&&fl7)ct++;
    }
    return ct;
}

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

    ans=dfs(n);

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


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

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var strs = Console.ReadLine().Split();
            var N = int.Parse(strs[0]);
            var i = int.Parse(strs[1]);

            Console.WriteLine(N - i + 1);
        }
    }
}


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

using namespace std;
typedef long long ll;
map<ll, ll> mapa;
int n;
ll m;
int arr[100005];
int main()
{
    ios_base::sync_with_stdio(false);
    cin >> n >> m;
    for(int i = 0; i < n; i ++){
        cin >> arr[i];
    }
    ll sum = 0;
    ll ret = 0;
    mapa[0] = 1;
    for(int i = 0; i < n; i ++){
        sum += arr[i];
        ret += mapa[sum % m];
        mapa[sum % m] ++;
    }
    cout << ret << endl;
    return 0;
}


Measured memory_bytes: 4608
def main():
    N = int(input())

    if N == 3:
        ans = [2, 5, 63]
    else:
        ans = []
        apnd = ans.append
        n = -(-N // 8)
        if N % 2:
            num = (6, 2, 10, 3, 9, 4, 8, 12)
        else:
            num = (2, 10, 3, 9, 4, 8, 6, 12)
        for i in range(n):
            for j in num:
                apnd(j + 12 * i)
                N -= 1
                if not N:
                    break

    print(*ans, sep=' ')

main()


Measured memory_bytes: 4572
n, k = gets.split.map(&:to_i)
strs = gets.chomp.split("")
previous = strs.first
ans = n - 1
changed_count = 0
strs.each do |str|
  changed_count += 1 if str != previous
  previous = str
end
ans -= changed_count
ans += (k * 2)
puts [ans, n - 1].min


Measured memory_bytes: 6908
#include<stdio.h>
int a[1000005];
int main(){
	int n;
	scanf("%d",&n);
	int b;
	for(int i=1;i<=n-1;i++){
		scanf("%d",&b);
		a[b]++;
	}
	for(int i=1;i<=n;i++) printf("%d\n",a[i]);
	return 0;
} 

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

#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rep2(i, m, n) for(int i = (int)m; i < (int)n; i++)
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii; //2次元配列
typedef vector<ll> vll;
typedef vector<string> vs;


/*FUNCs=================================================*/


/*MAIN==================================================*/
int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化

    ll n; cin >> n;
    cout << (n * (n - 1)) / 2 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

int main(void)
{
  int n;
  int ans=0;
  cin>>n;
  for(int i=1;i<=n;i+=2){
    int yaku=0;
    for(int j=1;j<=n;j+=2){
      if(i%j==0){
	yaku++;
      }
    }
    if(yaku==8){
      ans++;
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

signed main() {
  int A, B;
  cin >> A >> B;
  if( A * B == 15 ) cout << "*" << endl;
  else if( A + B == 15 ) cout << "+" << endl;
  else cout << "x" << endl;
}


Measured memory_bytes: 256
#3.4

N = int(input())
a = list(map(int, input().split()))

swapCount = 0
for i in range(0, N):
    minIndex = i
    for j in range(i, N):
        if a[j] < a[minIndex]:
            minIndex = j
    
    if i != minIndex:
        tmp = a[i]
        a[i] = a[minIndex]
        a[minIndex] = tmp
        swapCount += 1

print(' '.join(map(str, a)))
print(swapCount)

        

Measured memory_bytes: 7636
fun main(args: Array<String>) {
    val n = readLine()!!.toInt()
    val l = readLine()!!.split(" ").map { it.toInt() }
    var ll = mutableListOf<Int>()
    l.forEach{
        ll.add(it - 1)
        ll.add(it)
        ll.add(it + 1)
    }
    println(ll.groupBy { it }.mapValues { it.value.count() }.values.max())
}

Measured memory_bytes: 82124
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
#define vi vector<int>
#define vl vector<ll>
#define vii vector< vector<int> >
#define vll vector< vector<ll> >
#define vs vector<string>
#define pii pair<int,int>
#define pis pair<int,string>
#define psi pair<string,int>
#define pll pair<ll,ll>
#define tll tuple<ll, ll, ll>
#define all(c) c.begin(),c.end()

#define DEBUG(x) cerr<<#x<<": "<<x<<endl;
#define DEBUG_VEC(v) cerr<<#v<<":";for(int i=0;i<v.size();i++) cerr<<" "<<v[i]; cerr<<endl
 
const ll inf = 1000000001;
const ll INF = 1e18;
const ll MOD = 1000000007;

char albt[26] = {'a','b','c','d','e','f','g','h','i','j','k','l',
                 'm','n','o','p','q','r','s','t','u','v','w','x',
                 'y','z'};

//vector<ll> g[202020];
//fill(score, score+202020, 0);
//vector<ll> v;

int main(){
  ll n, k;
  cin >> n >> k;
  if (k > (n-1)*(n-2)/2){
    cout << -1 << endl;
    exit(0);
  }
  
  queue<pll> que;
  for (int i=2;i<=n;i++) que.push(pll(1,i));
  
  ll num = (n-1)*(n-2)/2 - k;
  //DEBUG(num);
  for (int i=2;i<=n;i++){
    for (int j=i+1;j<=n;j++){
      if (num == 0) break;
      //cout << i << " " << j << endl;
      que.push(pll(i,j));
      num -= 1;
    }
    if (num == 0) break;
  }
  //cout << que.size() << endl;
  ll cnt = que.size();
  
  cout << cnt << endl;
  for (int i=0;i<cnt;i++){
    cout << que.front().first << " " << que.front().second << endl;
    que.pop();
  }

  //cout << sum << endl;
}

Measured memory_bytes: 384
use std::io;
use std::str::*;

fn main() {
    let mut line = String::new();
    io::stdin().read_line(&mut line).unwrap();
    let mut line = line.split_whitespace().map(i32::from_str);
    let (a, b) = (line.next().unwrap().unwrap(), line.next().unwrap().unwrap());
    println!("{}", ((a + b) as f64 / 2.0 + 0.1).round());
}


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



int main() {
    string s;
    cin >> s;
    
    vector<int> ans(s.size());
    int n = (int)s.size();
    char c = 'R';
    int cnt = 1;
    for(int i = 1; i < n; i++) {
        if(s[i] != c) {
            if(s[i] == 'L') {
                ans[i-1] += (cnt+1) / 2;
                ans[i] += cnt / 2;
                
                c = 'L';
                cnt = 1;
            }
            else {
                ans[i-cnt] += (cnt+1) / 2;
                ans[i-cnt-1] += cnt / 2;
                
                c = 'R';
                cnt = 1;
            }
        }
        else
            cnt++;
    }
    ans[n-cnt] += (cnt+1) / 2;
    ans[n-1-cnt] += cnt / 2;
    
    
    rep(i,n-1) {
        cout << ans[i] << " ";
    }
    cout << ans[n-1] << endl;
    
    
    
    return 0;
}


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

int max(int a,int b){
  if(a > b){
    return a;
  }
  return b;
}

int compare_int(const void *a,const void *b){
  if(*(int*)a > *(int*)b) return 1;
  return -1;
}

int main(void){
  int N,K;
  scanf("%d%d",&N,&K);

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

  int ans = 0;
  for (int i = 0; i <= K; i++) {    //hidari
    for (int j = 0; j <= K; j++) {  //migi
      if(i+j > N || i+j > K) continue;
      int cur = 0,cnt = 0;
      int sum[i+j];
      for (int A = 0; A < i; A++) { //hidari
        cur += V[A];
        sum[cnt++] = V[A];
      }
      for (int B = 0; B < j; B++) { //migi
        cur += V[N-1-B];
        sum[cnt++] = V[N-1-B];
      }
      int ok = K-i-j;               //torinozokukaisuu
      qsort(sum,cnt,sizeof(int),compare_int);
      for (int x = 0; x < ok && x < cnt; x++) {
        if(sum[x] < 0) cur -= sum[x];
        else break;
      }
      ans = max(ans,cur);
    }
  }

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

  return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include<cstring>
using namespace std;
typedef long long ll;
int main()
{
  ll n,k;
  cin>>n>>k;
  ll i,ans=0;
  if(k==0)
    ans=n*n;
  else{
    for(i=k+1;i<=n;i++){
        ans+=(i-k)*(n/i);
        ll b=(n/i)*i+k;
        if(n>=b)
            ans+=n-b+1;
    }
  }
cout<<ans<<endl;
    return 0;

}


Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
f=1
for i in range(n):
    if a[i]%2==0 and a[i]%3!=0 and a[i]%5!=0:
        f=0
        break
if f==1:
    print("APPROVED")
else:
    print("DENIED")

Measured memory_bytes: 3060
package main
import "fmt"
// import "math"

func main(){
	var a, b, c int64

	fmt.Scan(&a, &b, &c)

	if c>a+b && 4*a*b<(c-a-b)*(c-a-b) {
		fmt.Println("Yes")
	}else {
		fmt.Println("No")
	}

	// if c > a+b && 4*a*b < (c-a-b)*(c-a-b) {
	// 	fmt.Println("Yes")
	// } else {
	// 	fmt.Println("No")
	// }
}

Measured memory_bytes: 512
import sys
input = sys.stdin.readline
def ii(): return int(input())
def mi(): return map(int, input().rstrip().split())
def lmi(): return list(map(int, input().rstrip().split()))
def li(): return list(input().rstrip())
def debug(*args, sep=" ", end="\n"): print("debug:", *args, file=sys.stderr, sep=sep, end=end) if not __debug__ else None
def exit(*arg): print(*arg); sys.exit()
# template

def main():
    a, b = mi()
    print(a * b)
    return

if __name__ == "__main__":
    main()


Measured memory_bytes: 9220