akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cctype>
#include <cstdio>
#include <cstdlib>
 
using namespace std;


int main(){
	int n,m;
	cin>>n>>m;
	long long int a=1,b=1;
	int x;
	x=abs(n-m);
	if (x>1){
		cout<<0<<endl;
	}
	if (x==1){
		
		for (int i = 1; i <= n; ++i)
		{
			a=(a*i)%1000000007;
		}
		for (int i = 1; i <= m; ++i)
		{
			b=(b*i)%1000000007;
		}
		
		cout<<a*b%1000000007<<endl;
	}
	if (x==0){
		for (int i = 1; i <= n; ++i)
		{
			a=(a*i)%1000000007;
		}
		cout<<2*a*a%1000000007<<endl;
	}

return 0;
}


Measured memory_bytes: 888
#include<iostream>
#include <cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
typedef pair<int,int> pint;
typedef pair<ll,int> pli;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

const int MAX = 1000000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(){
  string N; cin >> N; int K; cin >> K;
  ll dp[110][110][2] = {};
  int P = N.size();
  dp[0][0][0]=1; int cnt = 0;
  rep(i, P){
    rep(j, 5){
      if(N[i]=='0'){
       dp[i+1][j][0]+=dp[i][j][0];
       dp[i+1][j+1][1]+=9*dp[i][j][1];
       dp[i+1][j][1]+=dp[i][j][1];
     }
     else{
       dp[i+1][j+1][0]+=dp[i][j][0];
       dp[i+1][j+1][1]+=((int)N[i] - '1')*dp[i][j][0];
       dp[i+1][j][1]+=dp[i][j][0];
       dp[i+1][j+1][1]+=9*dp[i][j][1];
       dp[i+1][j][1]+=dp[i][j][1];
       cnt++;
     }
    }
  }
  if(cnt==5*K) cout << dp[P][K][1]+1 << endl;
  else cout << dp[P][K][1] << endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define all(vec) vec.begin(), vec.end()
#define tmax(x,y,z) max((x),max((y),(z)))
#define tmin(x,y,z) min((x),min((y),(z)))
typedef long long ll; ll MM = 1000000000;ll mod = MM + 7; ll MMM=9223372036854775807;//2^63 -1
ll GCD(ll x, ll y) {if (y == 0) return x;else return GCD(y, x % y);}
ll LCM(ll x, ll y) { return x / GCD(x, y) * y;}
//cout << fixed << setprecision(10);

int main(){
    ll n,m; cin>>n>>m;
    double t=1.0/4.0/(double)m;
    ll cnt=0,x,sum=0;
    vector<ll> v(n);
    rep(i,n) cin>>v[i], sum+=v[i];
    rep(i,n){
        if(v[i]>=t*sum) cnt++;
    }
    if(cnt>=m) cout<<"Yes"<<endl;
    else cout<<"No"<<endl;
}

Measured memory_bytes: 256
from math import factorial
import sys
sys.setrecursionlimit(2000000)
# import math
# import itertools
# import statistics
# import numpy as np
# import collections
#n = int(input())
n, m = list(map(int, input().split()))
if abs(n-m) >= 2:
    print(0)
else:
    if n == m:
        a = factorial(n) * factorial(m) * 2
    else:
        a = factorial(n) * factorial(m)
    print(a % (pow(10, 9)+7))


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

int main()
{
    map<string, int> dict = {
        {"SUN", 7},
        {"MON", 6},
        {"TUE", 5},
        {"WED", 4},
        {"THU", 3},
        {"FRI", 2},
        {"SAT", 1},
    };
    string s;
    cin >> s;
    cout << dict[s] << endl;
    return 0;
}

Measured memory_bytes: 764
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
using namespace std;
#define rep(i,n)	for(int i=0;i<n;i++)
int main(){
	int n,m;
	cin>>n>>m;
	int x[100010],y[100010];
	bool b[100010];
	rep(i,n){
		b[i]=false;
	}
	b[1]=true;	
	int c[100010];
	rep(i,n){
		c[i+1]=1;
	}	
	rep(i,m){
		cin>>x[i]>>y[i];
		if(b[x[i]]){
			b[y[i]]=true;
		}
		int s=x[i];
		int t=y[i];
		c[s]--;
		c[t]++;	
		if(!c[x[i]])b[x[i]]=false;
	}
	int ans=0;
	rep(i,n){
		if(b[i+1]==true)ans++;
	}
	cout<<ans<<endl;
	
}

Measured memory_bytes: 1536
import java.io.BufferedReader
import java.io.InputStream
import java.io.InputStreamReader
import java.util.*

fun main(args: Array<String>) {
    val sc = FastScanner(System.`in`)
    val h = sc.nextLong()
    val w = sc.nextLong()
    if (h == 1L || w == 1L) {
        println(1)
        return
    }
    println((h * w + 1) / 2)

}

class FastScanner(s: InputStream) {
    private var st = StringTokenizer("")
    private val br = BufferedReader(InputStreamReader(s))

    fun next(): String {
        while (!st.hasMoreTokens()) st = StringTokenizer(br.readLine())

        return st.nextToken()
    }

    fun nextInt() = next().toInt()
    fun nextLong() = next().toLong()
    fun nextLine() = br.readLine()
    fun nextDouble() = next().toDouble()
    fun ready() = br.ready()
}

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

using namespace std;
#define ll  long long
#define ld  long double
#define endl '\n'
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
const ll MOD = 1e9 + 7;
const double PI = 3.141592653589793238463;
const int MAXN = 1e5 + 5;

void debug_out() {
    cerr << endl;
}

template<typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << H;
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
set<ll>v[MAXN];
int main() {
    FAST
    ll x;
    cin>>x;
    for(int i=-1000;i<=1000;i++)
    {
        for(int j=-1000;j<=1000;j++)
        {
            ll s1=(ll)i*i*i*i*i;
            ll s2=(ll)j*j*j*j*j;
            if(s1-s2==x)
            {
                return cout<<i<<" "<<j<<endl,0;
            }
        }
    }

    return 0;
}


Measured memory_bytes: 8300
import itertools,sys
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,W = LI()
wv = [LI() for _ in range(N)]
dp = [[0]*(W+1) for _ in range(N+1)] #1_indexed
for i,j in itertools.product(range(N),range(W+1)):
    w,v = wv[i]
    if j-w>=0:
        dp[i+1][j] = max(dp[i+1][j],dp[i][j-w]+v)
    dp[i+1][j] = max(dp[i+1][j],dp[i][j])
print(dp[-1][-1])


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

using namespace std;
typedef long long ll;

int main(){

  
  ios_base::sync_with_stdio(0);

  int n;
  cin >> n;

  vector < pair < ll, ll > > a(n);
  vector < int > b(n);

  ll ma = 0;

  for (int i = 0; i < n; ++i) {
    cin >> a[i].first;
    a[i].second = i;
    b[i] = ma;
    ma = max(ma, a[i].first);
  }

  vector < ll > ans(n);

  sort(a.begin(), a.end(), [](pair <ll, ll> x, pair <ll, ll> y) {
    return x.first > y.first || (x.first == y.first && x.second < y.second);
  });

  ll cnt = 0;

  for (int i = 0; i < n;) {
    int j = i;
    ll ret = 0;
    ll tem = cnt;

    while (j < n && a[j].first >= b[a[i].second] && a[j].second >= a[i].second) {
      cnt++;
      ret += a[j].first - b[a[i].second];
      j++;
    }


    ans[a[i].second] = ret + tem * (a[i].first - b[a[i].second]);
    i = j;
  }

  for (auto i : ans)
    cout << i << '\n';

  return 0;

}


Measured memory_bytes: 3840
#include <bits/stdc++.h>
#define gc getchar_unlocked()
#define pc(x) putchar_unlocked(x)
template<typename T> void scan(T &x){x = 0;bool _=0;T c=gc;_=c==45;c=_?gc:c;while(c<48||c>57)c=gc;for(;c<48||c>57;c=gc);for(;c>47&&c<58;c=gc)x=(x<<3)+(x<<1)+(c&15);x=_?-x:x;}
template<typename T> void printn(T n){bool _=0;_=n<0;n=_?-n:n;char snum[65];int i=0;do{snum[i++]=n%10+48;n/= 10;}while(n);--i;if (_)pc(45);while(i>=0)pc(snum[i--]);}
template<typename First, typename ... Ints> void scan(First &arg, Ints&... rest){scan(arg);scan(rest...);}
template<typename T> void print(T n){printn(n);pc(10);}
template<typename First, typename ... Ints> void print(First arg, Ints... rest){printn(arg);pc(32);print(rest...);}

using namespace std;


int main(){
    
    char c;
    cin >> c;
    c++;
    cout << c;
    
    return 0;
}

Measured memory_bytes: 256
l, r = [int(x) for x in input().split()]

if r - l >= 2019:
    skip_flag = [False] * 2019
else:
    a = l % 2019
    temp = r % 2019
    b = temp if temp > a else temp + 2019
    skip_flag = [True] * 2019
    for i in range(a, b + 1):
        skip_flag[i % 2019] = False

if not skip_flag[0]:
    print(0)
    exit()

ans = 2019
for i in range(1, 2019):
    if skip_flag[i]:
        continue
    for j in range(i + 1, 2019):
        if skip_flag[j]:
            continue
        
        temp = (i * j) % 2019
        if temp < ans:
            ans = temp
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
const ll MOD = 1e9 + 7;

ll add (ll a, ll b) { return (a + b) % MOD; }
ll sub (ll a, ll b) { return (a + MOD - b) % MOD; }

int main (void) {
  ios::sync_with_stdio(false);cin.tie(0);
  cout << fixed << setprecision(15);
  ll n, k;
  cin >> n >> k;
  ll min_sum = 0, max_sum = 0;
  ll mn = 0, mx = n;
  ll ans = 0;
  for (ll i = 1; i <= n+1; i++) {
    min_sum = add(min_sum, mn);
    max_sum = add(max_sum, mx);
    if (i >= k) ans = add(ans, sub(max_sum + 1, min_sum));
    mn++;
    mx--;
  }
  cout << ans << '\n';
  return 0;
}



Measured memory_bytes: 3672
#include<bits/stdc++.h>
using namespace std;
typedef struct x
{
    long long a[3];
}x;
long long n;
void solve()
{
    vector < x > a(n);
    long long i,ans=0;
    for (i=0;i<n;i++)
        cin>>a[i].a[0]>>a[i].a[1]>>a[i].a[2];
    for (i=1;i<n;i++)
    {
        a[i].a[0]+=max(a[i-1].a[1],a[i-1].a[2]);
        a[i].a[1]+=max(a[i-1].a[0],a[i-1].a[2]);
        a[i].a[2]+=max(a[i-1].a[0],a[i-1].a[1]);
    }
    for (i=0;i<3;i++)
        ans=max(ans,a[n-1].a[i]);
    cout<<ans<<endl;
}
int main()
{
    while(cin>>n)
        solve();
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++){
		if(s[i]==','){
			s[i]=' ';
		}
	}
	cout<<s<<endl;
	return 0;
}

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

long fib(long x){
    if (x == 1 || x == 0) {
        return 1;
    }
    if (x == 2) {
        return 2;
    }
    else {
        long a;
        long b = 1;
        long ans = 2;
        for (long i = 0; i < x-2; i++) {
            a = b % 1000000007;
            b = ans % 1000000007;
            ans = (a + b) % 1000000007;
        }
        return ans;
    }
}

int main() {
    long n, m;
    cin >> n >> m;
    vector<long> a(m+2);
    a[0]=-1;
    a[m+1] = n+1;
    for (long i = 1; i < m+1; i++) {
        cin >> a[i];
    }
    long an = 1;
    for (long i = 1; i < m+2; i++) {
        if (a[i] - a[i-1] == 1 && i != 1) {
            an = 0;
            break;
        }
        if (a[i] == 1) {
            continue;
        }
        long d = a[i] - a[i-1];
        long f = fib(d-2);
        an = (an * f) % 1000000007;
    }
    cout << an << endl;
}


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

int main(void){
   int N;
   cin>>N;
   vector<int> a(N);
   for(int i=0;i<N;i++){
      cin>>a[i];
   }
   int result[8]={0};
   int count=0;
   for(int i=0;i<N;i++){
      if(1<=a[i]&&a[i]<=399) result[0]++;
      if(400<=a[i]&&a[i]<=799) result[1]++;
      if(800<=a[i]&&a[i]<=1199) result[2]++;
      if(1200<=a[i]&&a[i]<=1599) result[3]++;
      if(1600<=a[i]&&a[i]<=1999) result[4]++;
      if(2000<=a[i]&&a[i]<=2399) result[5]++;
      if(2400<=a[i]&&a[i]<=2799) result[6]++;
      if(2800<=a[i]&&a[i]<=3199) result[7]++;
      if(3200<=a[i]) count++;
   }
   int ans=0;
   for(int i=0;i<8;i++){
      if(result[i]>=1) ans++;
   }
   if(ans==0){
      cout<<1<<" "<<count<<endl;
   }else{
      cout<<ans<<" "<<ans+count<<endl;
   }
   return 0;
}



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

int expression(int &idx, int level, vector<vector<int>> &a) {
    int ret;
    int mode;
    if (a[idx][1] == -1) mode = 1;
    else if ( a[idx][1] == -2) mode = 2;
    else return ret = a[idx][1];
    
    if (mode == 1) ret = 0;
    else if (mode == 2) ret = 1;
    
    while (1) {
        idx++;
        if (mode == 1) {
            ret += expression(idx, level+1, a);
        } else {
            ret *= expression(idx, level+1, a);
        }
        if (level > a[idx+1][0]) return ret;
    }
}


int solve(int N) {
    vector<vector<int>> a(N+1, vector<int>(2));
    for (int i = 0; i < N; i++) {
        string s; cin >> s;
        int level = 0;
        for (int j = 0; j < s.length(); j++) {
            if (s[j] == '.') level++;
            if (s[j] == '+') a[i][1] = -1;
            else if (s[j] == '*') a[i][1] = -2;
            else a[i][1] = s[j] - '0';
            a[i][0] = level;
        }
    }
    a[N][0] = -1;
    
    int idx = 0;
    int ret = expression(idx, 1, a);
    return ret;
}

int main(void){
    // Your code here!
    int N;
    vector<int> ans;
    while (1) {
        cin >> N;
        if (!N) break;
        ans.push_back(solve(N));
    }
    for (auto &i : ans) {
        cout << i << endl;
    }
}



Measured memory_bytes: 3056
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define pp pair<int,int>
#define ll long long
#define ld long double
int inf=100000000;
ll INF=5000000000000000000;
ll MOD=1000000007;


int main() {
   
    int n;
    cin >> n;
     while (true){
         int m=0;
         string s,t;
         vector<string> a(0);
         while (true){
         
         cin >> s;
         if (s=="0" || s=="1" || s=="2" || s=="3" || s=="4" || s=="5" || s=="6" || s=="7" || s=="8" || s=="9" || s=="10") break;
         if (m==1) a.push_back(t);
         m=1;
         t=s;
         }
         char f=t.at(0);
         sort (a.begin(),a.end());
         vector<pair<int,string>> v(0);
         pair<int,string> o;
         for (int i=0;i<a.size();i++){
             if (i!=0) {
             if (a.at(i).at(0)==f && a.at(i)!=a.at(i-1)) {o.first=1;o.second=a.at(i);v.push_back(o);}
             if (a.at(i).at(0)==f && a.at(i)==a.at(i-1)) v.at(v.size()-1).first--;}
             if (i==0 && a.at(i).at(0)==f) {o.first=1;o.second=a.at(i);v.push_back(o);}
         }
         sort(v.begin(),v.end());
         rep(i,5){
             if (i==v.size()) break;
             if (i==v.size()-1 || i==4) cout << v.at(i).second << endl;
             else cout << v.at(i).second << " ";
         }
         if (v.size()==0) cout << "NA" << endl;
         if (s=="0") return 0;
    }
}



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

// conpact ver.
int main() {
  int n;
  cin >> n;
  vector<int>a(n);
  rep(i,n) cin >> a[i];
  sort(a.begin(), a.end());
  cout << a[n - 1] - a[0] << endl;
}

Measured memory_bytes: 256
#include<stdio.h>

#define MAX 100005
#define NIL -1

struct Node_struct{
  int p, l, r;
}; /*p: 親(parent), l: 一番左の子(left child), r:右の兄弟(right sibling)*/

typedef struct Node_struct Node;
Node T[MAX];
int D[MAX];

void print(int u){
  int i, c;
  printf("node %d: parent = %d, depth = %d, ", u, T[u].p, D[u]);

  if(T[u].p==NIL) printf("root, ");
  else if(T[u].l==NIL) printf("leaf, ");
  else printf("internal node, ");
  
  printf("[");
  for (i=0, c = T[u].l; c != NIL; i++, c = T[c].r){
    if(i) printf(", ");
    printf("%d", c);
  }
  printf("]\n");
  
}

void calcDepth(int u, int p){
  D[u] = p;
  if(T[u].r!=NIL) calcDepth(T[u].r,p);
  if(T[u].l!=NIL) calcDepth(T[u].l,p+1);
}

int main(){
  int i, j, k;
  int n;
  int id, sib, child;
  int root = NIL;
  scanf("%d", &n);
  for(i=0; i<n; i++) T[i].p = T[i].l = T[i].r = NIL;
  
  for(i=0; i<n; i++){
    scanf("%d %d", &id, &k);
    for(j = 0, sib = NIL; j<k; j++){ //子を入力する (input children)
      scanf("%d", &child);
      T[child].p = id;
      if(j == 0) T[id].l = child; //idの一番左の子 (the most left child of id)
      else T[sib].r = child; //左の兄弟に繋げる (connect to left sibling)
      sib = child;//次の子供の左の兄弟 (the left sibling of the next child)
    }
  }

  //根を求める (find the root)
  for(i=0; i<n; i++){
    if(T[i].p == -1) root = i;
  }
  
  //それぞれのノードの深さを求める (find depth of each node)
  calcDepth(root, 0);

  //出力 (output)
  for(i=0; i<n; i++) print(i);
  
  return 0;
}



Measured memory_bytes: 6540
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>

using namespace std;

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

    int ans = 0;

    for (int i = 0; i < a.length(); i++) {
        if (a[i] != b[i])ans++;
    }

    cout << ans;


    return 0;
}

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

int main(){
	int N,K;
	cin >> N >> K;
	string S;
	cin >> S;
	vector<int> memo;
	if(S[0] == '0') memo.push_back(0);
	int cnt(1);
	for(int i(0);i<N-1;++i){
		if(S[i] == S[i+1]){
			cnt++;
		}else{
			memo.push_back(cnt);
			cnt = 1;
		}
	}
	if(S[N-1] == S[N-2]){
		memo.push_back(cnt);
	}else{
		memo.push_back(1);
	}
	if(S[N-1] == '0') memo.push_back(0);
	int s_len = 2 * K + 1;
	if(memo.size() < 2*K+1) s_len = memo.size();
	ll sum(0),ans(0);
	for(int i(0);i<memo.size();++i){
		sum += memo[i];
		if(i >= s_len){
			sum -= memo[i-s_len];
		}
		if(i >= s_len - 1 && i % 2 == 0 && ans < sum) ans = sum;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1020
import math
import collections
import fractions
import itertools
import functools
import operator
import bisect

S = int(input())

def ncr(n, r):
    if n < r: return 0
    r = min(r, n-r)
    if r == 0: return 1
    numer = functools.reduce(operator.mul, range(n, n-r, -1), 1)
    denom = functools.reduce(operator.mul, range(1, r+1), 1)
    return numer // denom

def solve():
    mod = 10**9+7
    ans = 0
    for i in range(1, S):
        if 3 * i > S:
            break
        ans += ncr(S-3*i+i-1, i-1)
    ans %= mod
    print(ans)
    return 0

if __name__ == "__main__":
    solve()


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

int main()
{
    int a, b, c, x, y;
    scanf("%d%d%d", &a, &b, &c);
    x=a-b;
    if(c>x){
		y=c-x;
		printf("%d", y);
		return 0;
    }
    else printf("0");

    return 0;
}


Measured memory_bytes: 128
/*input
10
3 3 3 3 4 4 4 5 5 5
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie() , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define INF 0x3f3f3f3f

int n;
vector<int> v , p;
int32_t main(){
	IOS;
	cin >> n;
	REP(i , 1 , n + 1){
		int in;cin >> in;
		v.pb(in);
	}
	sort(ALL(v));
	while(v.size() >= 2){
		if(v[v.size() - 1] == v[v.size() - 2]) p.pb(v.back()) , v.pop_back() , v.pop_back();
		else v.pop_back();
	}
	if(p.size() >= 2) cout << p[0] * p[1] << endl;
	else cout << 0 << endl;
    return 0;
}

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

using namespace std;

int n,i,j,l,a[100005],p[18][100005];

int get(int id){
	int lb = 0;
	int ub = n;
	
	while(ub - lb > 1){
		int mid = (lb + ub) / 2;
		if(a[mid] - a[id] <= l)
		lb = mid;
		else
		ub = mid;
	}

	return lb;
}

int solve(int l, int r){
	if(l == r) return 0;
	
	int now = l;
	int cnt = 0;
	for(int ii = 17; ii >= 0; ii--){
		if(p[ii][now] < r){
			cnt += (1 << ii);
			now = p[ii][now];
		}
	}
	
	return cnt + 1;
}

int main(){
	scanf("%d", &n);
	for(i = 0; i < n; i++)
	scanf("%d", &a[i]);
	scanf("%d", &l);
	
	for(i = 0; i <= 17; i++){
		for(j = 0; j < n; j++){
			if(i == 0)
			p[i][j] = get(j);
			else
			p[i][j] = p[i - 1][p[i - 1][j]];
		}
	}
	
	int q;
	scanf("%d", &q);
	
	for(i = 0; i < q; i++){
		int l,r;
		scanf("%d%d", &l, &r);
		l--;
		r--;
		if(l > r)
		swap(l, r);
		printf("%d\n", solve(l, r));
	}
}


Measured memory_bytes: 8192
#include<bits/stdc++.h>
using namespace std;
int main(){
	int q;
	vector<int> a;
	cin>>q;
	for(int i=0;i<q;i++){
		int b,c;
		cin>>b;
		if(b==0){
			cin>>c;
			a.push_back(c);
		}
		else if(b==1){
			cin>>c;
			cout<<a[c]<<endl;
		}
		else a.pop_back();
	}
	return 0;
}



Measured memory_bytes: 3872
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>

using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define pb(a) push_back
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), n)
#define ub(v,n) upper_bound(v.begin(), v.end(), n)
#define int long long
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>P;
const int MOD = 1e9 + 7; const int MAX = 200020;
const double pi = acos(-1); const double EPS = 1e-12;
const ll INF = 1e18;
const int INT_INF = 1e9;
long long gcd(long long x, long long y) {
	long long m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}


char A[100][100], B[100][100];
int N, M;
bool check(int x, int y) {
	REP(i, M) {
		REP(j, M) {
			if (A[i + x][j + y] != B[i][j])return false;
		}
	}
	return true;
}
void solve() {
	int K, S; cin >> K >> S;
	int ans = 0;
	REP(X, K + 1)REP(Y, K + 1) {
		int rem = S - X - Y;
		if (0 <= rem && rem <= K)ans++;
	}
	print(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q;cin>>q;
	//while(q--)
	solve();
}




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

int a, b, c;

int main() {
	scanf("%d %d %d", &a, &b, &c);
	printf("%d", min(min(
	min(abs(abs(a - b) + abs(b - c)), abs(abs(a - c) + abs(c - b))),
	min(abs(abs(b - a) + abs(a - c)), abs(abs(b - c) + abs(c - a)))),
	min(abs(abs(c - a) + abs(a - b)), abs(abs(c - b) + abs(b - a)))));
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<map>
#include<stack>
#include<set>
#include<iomanip>
#include<string.h>
#include<iterator>
#include<queue>
//#include<bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
#define ll long long
#define inf 244000000000000000
#define mod 1000000007
#define endl '\n'
ll q[maxn];
int n;
int main()
{
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    ll ans = -(ll)1e18;
    ans = max(a * c, ans);
    ans = max(a * d, ans);
    ans = max(b * c, ans);
    ans = max(b * d, ans);
    cout << ans << endl;
}

Measured memory_bytes: 3656
ns = input()
N=int(ns)

C = [[ 0 for _ in range(10)] for _ in range(10)]
for i in range(N+1):
  si = str(i)
  s = int(si[0])
  e = int(si[-1])
  C[s][e] += 1
ans = 0
for i in range(1,10):
  for j in range(1,10):
#    print(i,j,C[i][j])
    ans += (C[i][j] * C[j][i])
print(ans)


Measured memory_bytes: 3064
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    String S = sc.next();
    
    int ecount = 0;
    for (int i = 0; i < N; i++) {
      if (S.charAt(i) == 'E') {
        ecount++;
      }
    }
    
    int wcount = 0;
    int ans = Integer.MAX_VALUE;
    for (int i = 0; i < N; i++) {
      int count = 0;
      if (S.charAt(i) == 'W') {
        wcount++;
        count--;
      } else {
        ecount--;
      }
      count += wcount + ecount;
      ans = Math.min(count, ans);
    }
    
    System.out.println(ans);
  }
}


Measured memory_bytes: 28988
package main

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

var (
	readString func() string
	readBytes  func() []byte
)

func init() {
	readString, readBytes = newReadString(os.Stdin)
}

func newReadString(ior io.Reader) (func() string, func() []byte) {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	f1 := func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
	f2 := func() []byte {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Bytes()
	}
	return f1, f2
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 10, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readFloat64() float64 {
	f, err := strconv.ParseFloat(readString(), 64)
	if err != nil {
		panic(err.Error())
	}
	return f
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

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

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func maxInt64(a, b int64) int64 {
	if a > b {
		return a
	}
	return b
}

func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

func sum(a []int) int {
	var ret int
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumInt64(a []int64) int64 {
	var ret int64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func sumFloat64(a []float64) float64 {
	var ret float64
	for i := range a {
		ret += a[i]
	}
	return ret
}

func gcdInt64(m, n int64) int64 {
	for m%n != 0 {
		m, n = n, m%n
	}
	return n
}

func lcmInt64(m, n int64) int64 {
	return m / gcdInt64(m, n) * n
}

// sort ------------------------------------------------------------

type int64Array []int64

func (s int64Array) Len() int           { return len(s) }
func (s int64Array) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s int64Array) Less(i, j int) bool { return s[i] < s[j] }

type xxx struct {
	x int
}

type sortArray []xxx

func (s sortArray) Len() int           { return len(s) }
func (s sortArray) Swap(i, j int)      { s[i], s[j] = s[j], s[i] }
func (s sortArray) Less(i, j int) bool { return s[i].x < s[j].x }

// -----------------------------------------------------------------

func main() {
	a := readInt()
	b := readInt()

	if a%2 == b%2 {
		fmt.Println((a + b) / 2)
	} else {
		fmt.Println("IMPOSSIBLE")
	}
}


Measured memory_bytes: 640
#include<stdio.h>
int main(){
	int a;
	scanf("%d",&a);
	for(;a--;){
		int b[10];
		for(int i=0;i<10;i++)scanf("%d",b+i);
		bool ans=false;
		for(int i=0;i<1024;i++){
			int maxa=0;
			int maxb=0;
			bool val=true;
			for(int j=0;j<10;j++){
				if(i&1<<j){
					if(maxa<b[j])maxa=b[j];
					else val=false;
				}else{
					if(maxb<b[j])maxb=b[j];
					else val=false;
				}
			}
			if(val)ans=true;
		}
		printf(ans?"YES\n":"NO\n");
	}
}

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

int main() {
  int n;
  scanf("%d", &n);
  vector<pair<int, int>> v;
  for (int i = 0, a, b; i < n; ++i) {
    scanf("%d%d", &a, &b);
    v.emplace_back(b, a);
  }
  int s = 0;
  sort(v.begin(), v.end());
  for (auto &it : v) {
    if ((s += it.second) > it.first) {
      puts("No");
      return 0;
    }
  }
  puts("Yes");
  return 0;
}


Measured memory_bytes: 2420
#include <iostream>
#include <cmath>
#include <string>
#include <algorithm>
#include <utility>
#include <vector>
#include <stack>
#include <queue>
using namespace std;

int main()
{

    int n=0;
    cin >> n;
    // string s = to_string(n);
    string ans = "";
    for(int i = 0 ; i <=2; i++)
    {
        int keta = n % 10;
        if(keta == 1)
        {
            ans = "9" + ans;
        }
        else if (keta == 9)
        {
            ans = "1" + ans;
        }
        else{
            ans = to_string(keta) + ans;
        }
        n = n / 10;
    }


    // for(int i = 0; i < s.length(); i++)
    // {
    //     cout << s[i] << endl;
    //     if(s[i] == '1')
    //     {
    //         cout << "1dayo" << endl;
    //         s[i] = '5';
    //     }
    //     if (s[i] == '9')
    //     {
    //         // cout << "9dayo" << endl;
    //         s[i] = '1';
    //     }
    // }

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

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

deque<int>f,r;
int p=2;
void rec(ll n){
	if(n==2){
		f={1};r={1};
		return;
	}
	if(n&1){
		rec(n-1);
		f.push_back(p);
		r.push_front(p);
		p++;
	}
	else{
		rec(n/2);
		f.push_back(p);
		r.push_back(p);
		p++;
	}
}

int main(){
	ll n;cin>>n;n++;
	rec(n);
	for(int i:r)f.push_back(i);
	cout<<f.size()<<endl;
	rep(i,f.size()){
		if(i)printf(" ");
		cout<<f[i];
	}
	cout<<endl;
}

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


int main() {
  string ans = "No";
  int n; cin>>n;
  while(n != 0){
    if ((n-7)%10 == 0) {
      ans = "Yes";
      break;
    }
    n = n/10;
  }
  cout<<ans<<"\n";
  return 0;
}


Measured memory_bytes: 3560
#include<cstdio>
#include<string>
#include<cstring>
#include<utility>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<algorithm>
#include<vector>
#include<iostream>
#define ll long long
#define pii pair<ll,ll>
#define mp make_pair
#define fi first
#define se second
#define inf 0x7fffffff
using namespace std;
ll q[200010],mu[200010];
pii a[200010];
int main()
{
	int i,j,k,n,m,h,t;ll x,y,z;
	scanf("%d%lld%lld",&n,&x,&y);
	for(i=0;i<n;i++)
	{
		scanf("%lld%lld",&a[i].fi,&a[i].se);
	}
	sort(a,a+n);
	t=0;
	z=0;
	h=0;
	ll ans=0;
	for(i=0;i<n;i++)
	{
		while(t-h>0&&q[h]<a[i].fi)
		{
			z-=mu[h];
			h++;
		}
		a[i].se-=z;
		if(a[i].se<=0)
		{
			continue;
		}
		q[t]=a[i].fi+x+x;
		mu[t]=(((a[i].se+y-1)/y)*y);
		z+=(((a[i].se+y-1)/y)*y);
		t++;
		ans+=((a[i].se+y-1)/y);
	}
	cout<<ans;
}


Measured memory_bytes: 6528
#include<iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define rep(i,m,n) for(int (i)=(int)(m);(i)<(int)(n);(i)++)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;(i)>=(int)(m);(i)--)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
typedef pair<ll, ll> P;
constexpr long long INF = 1 << 60;
constexpr int INF_INT = 1 << 25;

typedef vector<ll> Array;
typedef vector<Array> Matrix;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

constexpr long long MOD = 998244353;

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

struct Edge {
	int to, cap, rev;
	Edge(int _to, int _cap, int _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, int from, int to, int cap, bool revFlag, int revCap) {
	G[from].push_back(Edge(to, cap, G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, G[from].size() - 1));
}


void solve() {
	ll n, s;
	cin >> n >> s;
	Array a(n);
	REP(i, n)cin >> a[i];

	Matrix dp(n + 1, Array(s + 1, 0));
	dp[0][0] = 1;
	ll ans = 0;

	REP(i, n) {

		REP(j, s + 1) {
			if (dp[i][j] == 0) continue;

			(dp[i + 1][j] += dp[i][j]) %= MOD;
			
			if (j == 0) {
				//0から遷移するときはi+1区間分、sへ遷移するときはn-i区間分カウントされる
				if (a[i] <= s) (dp[i + 1][j+a[i]] += dp[i][j] * (i + 1) % MOD) %= MOD;
				if (a[i] == s) (ans += dp[i][j] * (i + 1) * (n - i) % MOD) %= MOD;
				continue;
			}

			if (j + a[i] <= s) (dp[i + 1][j + a[i]] += dp[i][j]) %= MOD;
			if (j + a[i] == s) (ans += dp[i][j] * (n - i) % MOD) %= MOD;

		}

	}

	cout << ans << en;
}

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

	solve();
	//int t; cin >> t; REP(i, t) solve();

	return 0;
}


Measured memory_bytes: 70784
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <ctime>
#include <vector>
#include <stack>

using namespace std;
////////////////*My library*////////////////////////
#define rep_to(a,i,n) for(int i=a;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_r(i,n) for(int i=n-1;i>=0;i--)
#define debug(x) cout<<x<<endl
#define s_1(x) cin>>x
#define s_2(x,y) cin>>x>>y
////////////////////////////////////////////////////

////////////////////////
/*prime()*/
/*primecount()*/
/*sort()*/
/*imos???*/
/*????????¢?´¢*/
/*??±???????????¢?´¢*/
/*???????¨???????*/
///////////////////////

int main()
{
	int N;
	int flag[40]={};

	rep(i,30)flag[i]=0;
	rep(i,28)
	{
		s_1(N);
		flag[N]=1;
	}
	rep_to(1,i,31)if(flag[i]==0)cout<<i<<endl;
	return 0;
}

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

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

int main(){
  int X, Y;
  cin >> X >> Y;
  for (int i = 0; i < X; i++) cin >> board[i];
  
  for (int i = 0; i < X; i++) {
    for (int j = 0; j < Y; j++) {
      if (board[i][j] == '.') {
        int cnt = 0;
        for (int k = 0; k < 8; k++) {
          int x = i + dx[k];
          int y = j + dy[k];
          if (x >= 0 && x < X && y >= 0 && y < Y && board[x][y] == '#') 
            cnt++;
        }
        board[i][j] = '0' + cnt;
      }
    }
  }
  for (int i = 0; i < X; i++) cout << board[i] << endl;
  return 0;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	ll n;
	int k;
	cin >> n >> k;
	ll ans=0;
	for(int j=2; j<=6; j++){
		int r=(1+7*k+3*j)%11;
		if(n-r-1<0) continue;
		else if(r>=2) ans+=(n-r-1)/11+1;
		else ans+=(n-r-1)/11;
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
//Night's template
//orzakyrt
#include <bits/stdc++.h>
#define R register
#define LL long long
#ifdef __DEBUG__
	#define Debug (fprintf(stderr,"orzyrt\n"),fflush(stderr))
	#define debug(__a...) (fprintf(stderr,__a),fflush(stderr))
	#define setfile(__a) ('orzyrt')
	#define Compile(__a) system("g++ "__a".cpp -lm -o "__a)
#else
	#define Debug ('orzyrt')
	#define debug(__a...) ('orzyrt')
	#define setfile(__a) freopen(__a".in","r",stdin);freopen(__a".out","w",stdout)
	#define Compile(__a) ('orzyrt')
#endif
template<class TT>inline TT Max(R TT a,R TT b){return a<b?b:a;}
template<class TT>inline TT Min(R TT a,R TT b){return a<b?a:b;}
template<class TT>inline TT Abs(R TT a){return a<0?-a:a;}
template<class TT>inline TT cmin(R TT &a,R TT b){(b<a)&&(a=b);}
template<class TT>inline TT cmax(R TT &a,R TT b){(a<b)&&(a=b);}
using namespace std;
template<class TT>inline void read(R TT &x){
	x=0;R bool f=false;R char c=getchar();
	for(;c<48||c>57;c=getchar())f|=(c=='-');
	for(;c>47&&c<58;c=getchar())x=(x<<1)+(x<<3)+(c^48);
	(f)&&(x=-x);
}
//end template

namespace Night{
	map<string,int>mp;
	string now,lst;
	int n;
	int ans;
	int main(){
		read(n);
		cin>>lst;
		mp[lst]=1;
		for(R int i=2;i<=n;++i){
			cin>>now;
			if(ans)continue;
			if(mp[now]==1){
				ans=1;
			}else{
				R char l=lst[lst.size()-1],t=now[0];
				if(l!=t){
					ans=1;
				}
				mp[now]=1;
				lst=now;
			}
		}
		if(ans)puts("No");
		else puts("Yes");
		return 0;
	}
}
int main(){
	return Night::main();
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int i,dice[7];
    char order[101];
    
    for(i=1;i<7;i++)
        scanf("%d", &dice[i]);
    
    scanf("%s", order);
    
    for(i=0;order[i]!='\0';i++){
        
        dice[0] = dice[1];
        
        switch(order[i]){
                
            case 'E':
                dice[1] = dice[4];
                dice[4] = dice[6];
                dice[6] = dice[3];
                dice[3] = dice[0]; 
                break;
            
            case 'N':
                dice[1] = dice[2];
                dice[2] = dice[6];
                dice[6] = dice[5];
                dice[5] = dice[0]; 
                break;
            
            case 'S':
                dice[1] = dice[5];
                dice[5] = dice[6];
                dice[6] = dice[2];
                dice[2] = dice[0]; 
                break;
                
            case 'W':
                dice[1] = dice[3];
                dice[3] = dice[6];
                dice[6] = dice[4];
                dice[4] = dice[0]; 
                break;

        }
    }
    
    printf("%d\n", dice[1]);
    
    return 0;
}


Measured memory_bytes: 2140
#include <stdio.h>
#define INF 100000001

void matrixChainOrder(int);
int min(int, int);

int n,k,i,j,q,l;
int p[100],m[100][100];

int main(){

  scanf("%d",&n);

  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }

  matrixChainOrder(n);

  printf("%d\n",m[1][n]);

  return 0;
}

void matrixChainOrder(int n){


  for(i=1; i<=n; i++){
    m[i][i] = 0;
  }

  for(l=2; l<=n; l++){
    for(i=1; i<=n-l+1; i++){
      j=i+l-1;
      m[i][j] = INF;
      for(k=i;k<=j-1;k++){
	q= m[i][k] + m[k+1][j] + p[i-1] * p[k] * p[j];
	m[i][j] = min(m[i][j], q);
      }
    }
  }
}

int min(int x, int y){
  if(x < y) return x;
  else if(x > y) return y;
  else if(x == y) return x;
}   

Measured memory_bytes: 636
import java.util.*

fun main(args: Array<String>) {
    val scan = Scanner(System.`in`)
    var kotlin=scan.nextLine().toInt()
    if(kotlin>=400 && kotlin<=599)
        println("8")
    if(kotlin>=600 && kotlin<=799)
        println("7")
    if(kotlin>=800 && kotlin<=999)
        println("6")
    if(kotlin>=1000 && kotlin<=1199)
        println("5")
    if(kotlin>=1200 && kotlin<=1399)
        println("4")
    if(kotlin>=1400 && kotlin<=1599)
        println("3")
    if(kotlin>=1600 && kotlin<=1799)
        println("2")
    if(kotlin>=1800 && kotlin<=1999)
        println("1")
}


Measured memory_bytes: 36368
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cctype>
#include<math.h>
#include<string>
#include<string.h>
#include<stack>
#include<queue>
#include<vector>
#include<utility>
#include<set>
#include<map>
#include<stdlib.h>
#include<iomanip>
#include<complex>

using namespace std;

#define ll long long
#define ld long double
#define INF 1e9
#define LINF (ll)INF*INF
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<(n);i++)
#define loop(i,a,n) for(int i=a;i<(n);i++)
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)


const double PI=acos(-1);
const double EPS=1e-9; //うまくいかなかったらゆるめる

typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int,int> pii;
typedef pair<pii,int> ppi;
typedef pair<int,pii> pip;
typedef vector<pii> vp;
typedef vector<vi> vvi;

int gcd(int a, int b){if(b==0) return a;return gcd(b,a%b);}
int lcm(int a, int b){return a/gcd(a,b)*b;}


signed main(void) {
    string s;
    cin >> s;
    int n = s.size();
    vvi v(2,vi(2019,0));
    int ans = 0;
    rep(i,n){
        ans += v[i%2][0];
        v[i%2][0]++;
        int t = s[i]-'0';
        rep(j,2019)if(v[i%2][j]){
            v[(i+1)%2][(j*10+t)%2019] += v[i%2][j];
            v[i%2][j] = 0;
        }
    }
    ans += v[n%2][0];
    cout << ans << endl;
}


Measured memory_bytes: 3376
'use strict';
function main(input) {
  const args = input.split('\n'),
        N = args[0],
        string = args[1];
  let counter = 0;
  let check = '';
  for (let i = 0; i < N; ++i) {
    if (check !== string[i]) {
      ++counter;
      check = string[i];
    }
  }
  console.log(counter);
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7628
X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))
AB = []
for i in A:
    for j in B:
        AB.append(i + j)
AB = sorted(AB, reverse=True)[:K]
ABC = []
for i in AB:
    for j in C:
        ABC.append(i + j)

ABC = sorted(ABC, reverse=True)[:K]
for a in ABC:
    print(a)

Measured memory_bytes: 155740
#include <iostream>
using namespace std;
 
int main() {
  int N, A, B;
  int max, min;
  cin >> N >> A >> B;
  
  if (N == A && N == B) {
  	max = N;
  	min = N;
  }
  else if (N == A) {
  	max = B;
  	min = B;
  }
  
  else if (N == B) {
  	max = A;
  	min = A;
  }
  
  else{
  	int sum;
    sum = A+B;
  
    if (sum > N) {
  	  if (A > B) {max = B;}
  	  else if (B > A) {max = A;}
  	  else {max = A;}
  	
  	  min = sum - N;
  	
    }
  
    else if(N > sum) {
  	  if (A > B) {max = B;}
  	  else if (B > A) {max = A;}
  	  else { max = A;}
  	  min = 0;
    }
  }
  
  cout << max << " " << min;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
 
int main() {
    int N;
    cin >> N;
    map <string , long int> Ain;
    rep(i,N){
        string tmp;
        cin >> tmp;
        Ain[tmp]++;
    }

    string out = "YES";

    for (auto itr = Ain.begin(); itr != Ain.end(); ++itr) {
        if(itr->second > 1){
            out = "NO";
            break;
        }
    }

    cout << out << endl;
}

Measured memory_bytes: 24832
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

const LL inf = 1123456789012;
LL N, S;

LL f(LL b, LL n)
{
	LL res = 0;
	while (n > 0)
	{
		res += n % b;
		n /= b;
	}
	return res;
}

int main()
{
	in >> N >> S;
	if (N == S) out << N + 1 << std::endl;
	else
	{
		for (LL b = 2; b <= sqrt(N); ++b)
		{
			if (f(b, N) == S)
			{
				out << b << std::endl;
				return 0;
			}
		}
		LL ans = inf;
		for (LL alp = 1; alp <= sqrt(N); ++alp)
		{
			LL b = (N - S) / alp + 1;
			if (b < 2) continue;
			if (f(b, N) == S) ans = std::min(ans, b);
		}
		out << (ans == inf ? -1 : ans) << std::endl;
	}
	return 0;
}


Measured memory_bytes: 3604
# -*- coding: utf-8 -*-

import sys
from collections import Counter

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
MOD = 10 ** 9 + 7

N=INT()
S=input()

C=Counter(S)
ans=1
for v in C.values():
    # 各文字は1回しか使えないので、文字毎の場合の数は出現回数+1(使わない分)
    ans*=v+1
    ans%=MOD
# 最後に空文字列の分を引く
ans-=1
print(ans)


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

int main()
{
  int N;
  cin >> N;
  int count_4n = 0;
  int count_2n = 0;
  rep(i, N)
  {
    int a;
    cin >> a;
    if (a % 2 == 0)
      count_2n++;
    if (a % 4 == 0)
      count_4n++;
  }
  count_2n -= count_4n;
  N /= 2;
  string ans = "No";
  N -= count_4n + count_2n / 2;

  if (N <= 0)
  {
    ans = "Yes";
  }

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

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

int main(){

    char c[4];
    bool check=false;

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

    if(c[0]==c[1]){
        if(c[2]==c[3]){
            check=true;
        }
    }
    if(c[0]==c[2]){
        if(c[1]==c[3]){
            check=true;
        }
    }
    if(c[0]==c[3]){
        if(c[1]==c[2]){
            check=true;
        }
    }

    if(c[0]==c[1] && c[0]==c[2] && c[0]==c[3]){
        check=false;
    }

    if(check){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }

    return 0;

}

Measured memory_bytes: 256
use proconio::input;

// use std::cmp::*;
// use std::collections::*;
use proconio::marker::Chars;

fn main() {
    input! {
        s: Chars
        // n: isize
    }
    let mut l:usize = s.len();
    let mut r:usize = 0;
    for (i, c) in s.iter().enumerate() {
        if *c == 'A' && l == s.len() {
            l = i;
        }
        if *c == 'Z' {
            r = i;
        }
    }
    println!("{}", r-l+1);
}


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


map<long long,int> pFactorize(long long n){
	map<long long,int> memo;
	
	for(long long i = 2 ; i <= 1000 ; i++){
		while(n%i==0){
			memo[i]++;
			n/=i;
		}
	}
	if(n>1){
		long long x = sqrt(n) + 0.5;
		if( x * x == n ){
			memo[x] += 2;
		}else{
			memo[n] = 1;
		}
	}
	map<long long,int> res;
	for( auto i : memo ) if( i.second % 3 ) res[i.first] = i.second % 3;
	return res;
}
map<long long,int> inv(map<long long,int> x){
	map<long long,int> res;
	for( auto i : x ) res[i.first] = 3 - i.second;
	return res;
}
void output(map<long long,int> t){
	cout << "{";
	for( auto e : t ) cout << e.first << ":" << e.second << ",";
	cout << "}" << endl;
}
void solve(long long N, vector<long long> s){
	map<map<long long,int>,int> ps;
	
	for(int i = 0 ; i < s.size() ; i++){
		auto t = pFactorize(s[i]);
		
		ps[t]++;
	}
	long long ans = 0;
	while(ps.size()){
		auto it = ps.begin();
		auto r = inv(it->first);
		assert(it->second);
		// cout << "--" << endl;
		// output(it->first);
		// output(r);
		
		if( r == it->first ){
			ans++;
			ps.erase(it);
		}else{
			if( ps.count(r) ){
				ans += max(it->second,ps[r]);
				ps.erase(it);
				ps.erase(r);
			}else{
				ans += it->second;
				ps.erase(it);
			}
		}
	}
	cout << ans << endl;
	
}



int main(){	
	ios::sync_with_stdio(false);
	long long N;
	cin >> N;
	vector<long long> s(N-1+1);
	for(int i = 0 ; i <= N-1 ; i++){
		cin >> s[i];
	}
	// N = 100000;
	// s = vector<long long> (N,1000000007ll);
	
	solve(N, s);
	return 0;
}


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

int main(){
  
      string a;
      cin >> a;
       int n = a.length();
       int  dp[2][n+1];
       memset(dp,INT_MAX,sizeof(dp));
       dp[0][0] = a[0] -'0';
       dp[1][0] = 10 - (a[0] - '0') + 1;

       for(int i =1;i<n;i++){
           for(int j =0;j<2;j++){
               if( j == 0){
                   dp[0][i] = min(dp[0][i-1] + (a[i]-'0'),dp[1][i-1] + (a[i]-'0'));
               }
               else{
                   dp[1][i] = min(dp[0][i-1] + 11 -(a[i] -'0'),dp[1][i-1] + (10- (a[i]-'0') -1));
               }

           }
       }
   cout << min(dp[0][n-1],dp[1][n-1]) << endl;
  return 0;
}

Measured memory_bytes: 9220
def dfs(s, n):
    if int(s) > n:
        return 0
    cnt = 0
    if "7" in s and "5" in s and "3" in s:#もし753数だったら
        cnt += 1
    return cnt + dfs(s + "7", n) + dfs(s + "5", n) + dfs(s + "3", n)#sに７か５か３を加えた数について、再帰的に探索

n = int(input())
print((dfs("0", n)))#int("07") = 7なので、0つけてOK

Measured memory_bytes: 45160