akhauriyash/Code-Regression huggingface dataset:
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt(input.readLine());
        int k = Integer.parseInt(input.readLine());
        System.out.println(calc(n, 1, k, 1));
    }

    public static int  calc (int k, int count, int incrementValue  ,int sum){
        if (count > k){
            return sum;
        }

        return Math.min(calc(k, count + 1, incrementValue,sum * 2), calc(k, count + 1, incrementValue , sum + incrementValue));
    }
}


Measured memory_bytes: 21204
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, x, ans = 1;
	vector<int> d;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> x;
		d.push_back(x);
	}
	sort(d.begin(), d.end());
	for (int i = 0; i < n - 1; i++) {
		if (d[i] != d[i + 1]) {
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int n;
    cin >> n;
    
    vector<int> v(n), c(n);
    
    for (int i = 0; i < n; i++) {
        cin >> v[i];
    }
    
    for (int i = 0; i < n; i++) {
        cin >> c[i];
    }
    
    int ans = 0;
    
    for (int i = 0; i < n; i++) {
        ans += max(0, v[i] - c[i]);
    }
    
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#define IO(i, o) freopen(i, "r", stdin), freopen(o, "w", stdout)

using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;
mt19937 rng((uint32_t)chrono::steady_clock::now().time_since_epoch().count());

int x, y;

int main(){
	//IO("input.txt", "output.txt");
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> x >> y;
	if(x == 4 || x == 6 || x == 9 || x == 11) x = 1;
	else if(x == 2) x = 2;
	else x = 0;
	if(y == 4 || y == 6 || y == 9 || y == 11) y = 1;
	else if(y == 2) y = 2;
	else y = 0;
	cout << ((y == x) ? "Yes\n" : "No\n");
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
#define ll long long
#define ld long double
#define rep(i,n) for(int i = 0; i < (int)(n); i++)
#define repo(i,n) for(int i = 1; i < (int)(n); i++)
#define pb push_back
#define mp make_pair
#define np next_permutation
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define uniq(v) v.erase(unique(v.begin(),v.end()),v.end())
#define lb(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define ub(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
using Pair = pair<ll,pair<int,int>>;
#define pq priority_queue<Pair, vector<Pair>, greater<Pair>> 
const ll mod=1000000007;
//const ll mod=998244353;
const ld pi=acos(-1.0);
const ll INF = 1LL<<61;
template<class T>bool chmax(T &a, const T &b) { 
  if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) {
  if (b<a) { a=b; return 1; } return 0; }
ll gcd(ll x, ll y) { return y ? gcd(y, x % y) : x; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }
//intの最大値2147483647 ≒ 2×10^9
//long longの最大値9223372036854775807 ≒ 9×10^18
//'大文字'+=32;    で小文字に
//  cout << fixed << setprecision (20);   小数点以下2０桁まで
//実行時間制約2秒では２×10^8回くらいまで計算できる



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

  int n;
  cin>>n;

  vector<ll> p(n);
  rep(i,n){
    cin>>p[i];
  }

  reverse(all(p));

  if(p[0]!=2) {
    cout << -1 << endl;
    return 0;
  }

  ll s=2,d=3;
  repo(i,n){
    ll ss=p[i]*((s+p[i]-1)/p[i]);
    ll dd=p[i]*(d/p[i]);
    if(ss>dd) {
      cout << -1 << endl;
      return 0;
    }
    s=ss,d=dd+p[i]-1;
  }

  cout << s << " " << d << endl;

}

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


int main() {
	string s, t;
	cin >> s >> t;
	vector<int> start(26, -1);
	vector<int> goal(26, -1);
	for (int i = 0; i < s.size(); i++)
	{
		int a = s[i] - 'a';
		int b = t[i] - 'a';

		if (start[a] != -1 || goal[b] != -1) {
			if (start[a] != b || goal[b] != a) {
				cout << "No" << endl;
				return 0;
			}
		}
		else {
			start[a] = b;
			goal[b] = a;
		}
	}

	cout << "Yes" << endl;
}


Measured memory_bytes: 776
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
using ll = long long;
int main(){
    int n;
    vector<int> c(4);
    cin >>n;
    rep(i,n){
        string s;
        cin >>s;
        if(s=="AC"){
            c[0]++;
        }
        if(s=="WA"){
            c[1]++;
        }
        if(s=="TLE"){
            c[2]++;
        }
        if(s=="RE"){
            c[3]++;
        }
    }
    cout << "AC x "<< c[0] << endl <<"WA x "<< c[1] << endl <<"TLE x " << c[2] << endl <<"RE x " <<c[3]<< endl;
}

Measured memory_bytes: 3632
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7
#s=input().rstrip()

n,k=MI()
ans=k*((k-1)**(n-1))
print(ans)


Measured memory_bytes: 38256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		int A = sc.nextInt();
		int B = sc.nextInt();
		int res = 0;
		for (int i = 1; i <= N; i++) {
			int sum = 0;
			int value = i;
			while (value > 0) {
				sum += value % 10;
				value /= 10;
			}
			if (A <= sum && sum <= B) {
				res += i;
			}
		}
		System.out.print(res);
	}
}


Measured memory_bytes: 23892
#include <cstdio>
#include <iomanip>
#include <iterator>
#include <iostream>
#include <sstream>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <climits>
#include <string>
#include <set>
#include <numeric>
#include <bitset>
#include <cmath>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <stack>
#include <numeric>
#include <vector>
#include <cassert>
#include <ctime>

using namespace std;
 
#define dump(...) do{print_vars(cout<<"# "<<#__VA_ARGS__<<'=',__VA_ARGS__);cout<<endl;}while(0)
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define all(c) begin(c),end(c)
#define mp make_pair
#define mt make_tuple
 
using uint=unsigned;
using ll=long long;
using ull=unsigned long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using vd=vector<double>;
using vvd=vector<vd>;
using vs=vector<string>;
using pii=pair<int, int>;
template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename Ch,typename Tr,typename C>
basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>& os,const C& c){
	os<<'[';
	for(auto& p: c) os << p << " ";
	return os<<']';
}
 
void print_vars(ostream&){}
template<typename Car,typename... Cdr>
void print_vars(ostream& os,const Car& car,const Cdr&... cdr){
	print_vars(os<<car<<(sizeof...(cdr)?",":""),cdr...);
}
 
 
template<int I,typename Tuple>
void print_tuple(ostream&,const Tuple&){}
template<int I,typename Car,typename... Cdr,typename Tuple>
void print_tuple(ostream& os,const Tuple& t){
	os<<get<I>(t)<<(sizeof...(Cdr)?",":"");
	print_tuple<I+1,Cdr...>(os,t);
}
template<typename... Args>
ostream& operator<<(ostream& os,const tuple<Args...>& t){
	print_tuple<0,Args...>(os<<'(',t);
	return os<<')';
}
 
 
constexpr int INF=1e9;
constexpr int MOD=1e9+7;
constexpr double EPS=1e-9;
constexpr int maxn=1001;
constexpr int pro=2000;


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

	int x0, y0, x2, y2;
	int N;
	while(cin>> x0>>y0>>x2>>y2) {
		cin>>N;
		vector<pii> points(N);
		rep(i, N) cin>> points[i].first >> points[i].second;
		if(x0 > x2) {
			swap(x0, x2);
			swap(y0, y2);
		}
		if(y0 > y2) {
			y0 = -y0;
			y2 = -y2;
			rep(i, N) points[i].second *= -1;
		}
		points.erase(remove_if(all(points), [&](pii p) {
				return p.first < x0 || p.first > x2 || p.second < y0 || p.second > y2;
				}), points.end());
		sort(all(points));
		vi c;
		rep(i, points.size()) if(c.empty() || c.back() < points[i].second) c.push_back(points[i].second);
		else *upper_bound(all(c), points[i].second) = points[i].second;
		double ans = 0;

		if(c.size() == min(y2-y0, x2-x0) + 1) {
			ans = 10*M_PI-20;
			c.pop_back();
		}
		ans += (y2 - y0 + x2-x0) * 100.0 - c.size() * 20.0 + c.size() * 5 * M_PI;
		cout << setiosflags(ios::fixed) << setprecision(11) << ans << endl;
	}
	return 0;
}
		



Measured memory_bytes: 2936
#include <stdio.h>
int a,b;//a=a盒顆數  b=b盒顆數
int main(void) {
scanf("%d%d",&a,&b);
if(a%3==0&b%3==0)
printf("Possible");
else if(a%3==0&b%3!=0)
printf("Possible");
else if(a%3!=0&b%3==0)
printf("Possible");
else if(a%3!=0&b%3!=0&(a+b)%3==0)
printf("Possible");
else
printf("Impossible");



return 0;
}

Measured memory_bytes: 1700
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define F first
#define S second
#define pb push_back
mt19937 rnd;

const int N = 2e5 + 10;
map<string, int> mp;
set<string> ans;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
#ifdef LOCAL
    freopen("input.txt", "r", stdin);
#endif

    int n;
    cin >> n;
    for (int i=1; i<=n; i++) {
        string s;
        cin >> s;
        mp[s]++;
    }
    int mx = 0;
    for (pair<string, int> cur : mp) {
        mx = max(mx, cur.S);
    }
    for (pair<string, int> cur : mp) {
        if (mx == cur.S) {
            ans.insert(cur.F);
        }
    }
    for (string s : ans) {
        cout << s << "\n";
    }

#ifdef LOCAL
    cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
   return 0;
}


Measured memory_bytes: 33280
#include<stdio.h>
#include<iostream>
#include<vector>
#include <bits/stdc++.h>
#include <queue>
#include <algorithm>
#include <string>
#include <iomanip>
#include <cmath>

using namespace std;
typedef long long ll;

#define rep(i,n) for(ll i=0; i<(ll)(n); i++)
#define Q 1000000007

// ll white, black;
// vector<vector<char>> c(h, vector<char>(w));
// ll ans = 0;
// vector<ll> a(N);
// const int M = 2;
// void dfs(vector<int> &A) {
//     // 終端条件 --- 10 重ループまで回したら処理して打ち切り
    

//     if(A.size() == h+w){
//       // rep(i, A.size()) cout << A[i];
//       // cout << " ";
//       vector<vector<char>> tmp(h, vector<char>(w));
//       rep(i, h){
//         rep(j, w) tmp[i][j] = c[i][j];
//       }
//       ll cnt = black;
//       for(ll i = 0; i < h; i++){
//         if(A[i] == 1){
//           // cout << i << " ";
//           rep(j, w){
//             if(tmp[i][j] == '#'){
//               tmp[i][j] = 'r';
//               cnt--;
//             }
//           }
//         }
//       }
//       for(ll i = h; i < h+w; i++){
//         if(A[i] == 1){
//           // cout << i << " ";
//           rep(j, h){
//             if(tmp[j][i-h] == '#'){
//               tmp[j][i-h] = 'r';
//               cnt--;
//             }
//           }
//         }
//       }

//       // cout << cnt << endl;
//       if(cnt == k) ans++;
      
//       return;
//     }

//     for (int v = 0; v < M; ++v) {
//         A.push_back(v);
//         dfs(A);
//         A.pop_back(); // これが結構ポイント
//     }
// }

ll max(vector<ll> a) {
  return *max_element(a.begin(), a.end());
}

ll max_index(vector<ll> a) {
  vector<ll>::iterator max_it = max_element(a.begin(), a.end());
  return distance(a.begin(), max_it);
}

int main(){
  
  double d,t,s;
  cin >> d >> t >> s;

  if(d/s <= t) cout << "Yes" << endl;
  else cout << "No" << endl;
  

  return 0;
}

Measured memory_bytes: 3680
from collections import deque

n=int(input())
s=deque(input())


left=0
right=0
for i in range(n):
  if s[i]=="(":
    left+=1
  else:
    if left>0:
      left-=1
    else:
      right+=1
    
      

for _ in range(left):
    s.append(")")
    

for _ in range(right):
    s.appendleft("(")

print("".join(s))

Measured memory_bytes: 9304
n=int(input())
a=list(map(int,input().split()))
t=0
for i in a:
  if i % 2==0:
    if i%3==0:
      continue
    elif i%5==0:
      continue
    else:
      t=1
      print("DENIED")
      break

if t==0:
  print("APPROVED")
  

Measured memory_bytes: 2940
#include <iostream>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <algorithm>
#include <bitset>
#include <cstdlib>
#include <cmath>
#define INF 100000000000
#define MOD 1000000007
#define ll long long int
//#define int long long int
using namespace std;

signed main(){
   ll N,X;cin>>N>>X;
   ll d = 0;
   vector <ll> D; D.resize(N+1,0);
   ll ans = 0;
   ll now = 0;
   vector <ll> L; L.resize(N);
   for(int i=0;i<N;i++) cin>>L[i];
   for(int i=1;i<=N;i++){
       D[i] = D[i-1] + L[i-1];
   }

   for(int i=0;i<=N;i++){
       if(D[i] <= X) ans++;
      // cout<<D[i]<<endl;
   }

   cout<<ans<<endl;

}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <functional>

using namespace std;

int main()
{
  int n;
  cin >> n;

  int b[100000];
  for (int i = 0; i < n - 1; ++i) cin >> b[i];

  int a[100000];
  a[0] = b[0];
  for (int i = 1; i < n - 1; ++i) a[i] = min(b[i], b[i - 1]);
  a[n - 1] = b[n - 2];

  int count = 0;
  for (int i = 0; i < n; ++i) count += a[i];

  cout << count << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#include <math.h>
#include <iomanip>
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 int mod=1e9+7;
const int INF=1001001001;

int main() {
  string s;
  cin>>s;
  int N=s.size();
  vector<vector<int64_t>>dp(100005,vector<int64_t>(13));
  dp[0][0]=1;
  for(int i=0;i<N;i++){
    for(int j=0;j<13;j++){
      if(s[i]=='?'){
        for(int k=0;k<10;k++){
          dp[i+1][(10*j+k)%13]+=dp[i][j];
          dp[i+1][(10*j+k)%13]%=mod;
        }
      }
      else{
        dp[i+1][(10*j+s[i]-'0')%13]+=dp[i][j];
        dp[i+1][(10*j+s[i]-'0')%13]%=mod;

      }
    }
  }
  cout<<dp[N][5]<<endl;
  return 0;  
}

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

int main() {
  int n;
  cin >> n;
  vector<int> ip(n);
  rep(i, n) cin >> ip[i];
  sort(ip.begin(), ip.end());
  vector<ll int> len;
  int last = 0;
  map<int, ll int> mp;
  for(int x : ip) {
    ++mp[x];
    if(last != x) len.push_back(x);
    last = x;
  }
  
  int m = len.size();
  // rep(i, m) cout << len[i] << " ";
  
  int ans = 0;
  for(int i = 0; i < m-2; ++i) {
    for(int j = i+1; j < m-1; ++j) {
      for(int k = j+1; k < m; ++k) {
        if(len[i] + len[j] > len[k]) {
          ans += mp[len[i]]*mp[len[j]]*mp[len[k]];
        }
      }
    }
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 3636
#define _CRT_SECURE_NO_WARNINGS
#include <cstdio>
using namespace std;

int main()
{
    int N;

    if (scanf("%d", &N) < 1) return 0;

    char s[101];
    char t[101];

    if (scanf("%s", s) < 1) return 0;
    if (scanf("%s", t) < 1) return 0;

    int match = 0;
    int tmp = 0;
    for (int i = 0; i < N; i++)
    {
        if (tmp == N) break;
        tmp = i;
        for (int j = 0; j < N; j++)
        {
            if (j == 0) match = 0;
            if (s[tmp] != t[j]) break;
            else
            {
                tmp++;
                match++;
                continue;
            }
        }
    }

    printf("%d\n", 2 * N - match);
    return 0;
}


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


using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(ll i=st; i<ed; i++)
#define repn(i, st, ed) for(ll i=st; i<=ed; i++)
#define repb(i, ed, st) for(ll i=ed; i>=st; i--)
#define all(v) v.begin(),v.end()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 1e5 + 10;
const ll INF = 1LL << 60;

template<class T> void chmax(T &a,T b) { if (a<b) a=b;}
template<class T> void chmin(T &a,T b) { if (a>b) a=b;}



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


Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
    int max, min, i, n, a[10000];
    long sum;
    scanf("%d", &n);
    for (i = 0; i<n; i++) {
        scanf("%d", &a[i]);
    }
    max = min = sum = a[0];
    for (i = 1; i<n; i++) {
        if (a[i]>max)  
             max = a[i]; 
        if (a[i]<min)  min = a[i]; 
             sum += a[i];
    }
    printf("%d %d %ld\n", min, max, sum);
    return 0;
}


Measured memory_bytes: 2096
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
#define SZ(x) ((int)((x).size()))

template <typename T1, typename T2>
string print_iterable(T1 begin_iter, T2 end_iter, int counter) {
    bool done_something = false;
    stringstream res;
    res << "[";
    for (; begin_iter != end_iter and counter; ++begin_iter) {
        done_something = true;
        counter--;
        res << *begin_iter << ", ";
    }
    string str = res.str();
    if (done_something) {
        str.pop_back();
        str.pop_back();
    }
    str += "]";
    return str;
}

vector<int> SortIndex(int size, std::function<bool(int, int)> compare) {
    vector<int> ord(size);
    for (int i = 0; i < size; i++) ord[i] = i;
    sort(ord.begin(), ord.end(), compare);
    return ord;
}

template <typename T>
bool MinPlace(T& a, const T& b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool MaxPlace(T& a, const T& b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

template <typename S, typename T>
ostream& operator <<(ostream& out, const pair<S, T>& p) {
    out << "{" << p.first << ", " << p.second << "}";
    return out;
}

template <typename T>
ostream& operator <<(ostream& out, const vector<T>& v) {
    out << "[";
    for (int i = 0; i < (int)v.size(); i++) {
        out << v[i];
        if (i != (int)v.size()-1) out << ", ";
    }
    out << "]";
    return out;
}

template<class TH>
void _dbg(const char* name, TH val){
    clog << name << ": " << val << endl;
}
template<class TH, class... TA>
void _dbg(const char* names, TH curr_val, TA... vals) {
    while(*names != ',') clog << *names++;
    clog << ": " << curr_val << ", ";
    _dbg(names+1, vals...);
}

#if DEBUG && !ONLINE_JUDGE
    ifstream input_from_file("input.txt");
    #define cin input_from_file

    #define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
    #define dbg_arr(x, len) clog << #x << ": " << print_iterable(x, x+len, -1) << endl;
#else
    #define dbg(...)
    #define dbg_arr(x, len)
#endif

///////////////////////////////////////////////////////////////////////////
//////////////////// DO NOT TOUCH BEFORE THIS LINE ////////////////////////
///////////////////////////////////////////////////////////////////////////


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); // Remove in problems with online queries!

    LL S;
    cin >> S;
    LL x1 = 1e9;
    LL y2 = (S+x1-1)/x1;
    LL x2 = 1;
    LL y1 = x1*y2-S;
    cout << 0 << " " << 0 << " ";
    cout << x1 << " " << y1 << " ";
    cout << x2 << " " << y2 << "\n";
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC121
{
    class A
    {
        static void Main(string[] args)
        {
            int[] a = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int[] b = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            int H = a[0], W = a[1];
            int h = b[0], w = b[1];

            Console.WriteLine((H - h) * (W - w));
        }
    }
}


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

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

template<class T>
void debug(T itr1, T itr2) { auto now = itr1; while(now<itr2) { cout << *now << " "; now++; } cout << endl; }
#define repr(i,from,to) for (int i=(int)from; i<(int)to; i++)
#define all(vec) vec.begin(), vec.end()
#define rep(i,N) repr(i,0,N)
#define per(i,N) for (int i=(int)N-1; i>=0; i--)

const ll MOD = pow(10,9)+7;
const ll LLINF = pow(2,61)-1;
const int INF = pow(2,30)-1;

vector<ll> fac;
void c_fac(int x=pow(10,6)+10) { fac.resize(x,true); rep(i,x) fac[i] = i ? (fac[i-1]*i)%MOD : 1; }
ll inv(ll a, ll m=MOD) { ll b = m, x = 1, y = 0; while (b!=0) { int d = a/b; a -= b*d; swap(a,b); x -= y*d; swap(x,y); } return (x+m)%m; }
ll nck(ll n, ll k) { return fac[n]*inv(fac[k]*fac[n-k]%MOD)%MOD; }
ll gcd(ll a, ll b) { if (a<b) swap(a,b); return b==0 ? a : gcd(b, a%b); }
ll lcm(ll a, ll b) { return a/gcd(a,b)*b; }


int main() {
  string N; cin >> N;
  string result = "No";
  rep(i,3) if (N[i]=='7') result = "Yes";
  cout << result << endl;
  return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <iomanip>
#include <string>
#include <algorithm>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;
const int MAXN = 510;

int N;
char grid[MAXN][MAXN];
bool rgood[MAXN];
int cscore[MAXN];

int main()
{
    cin >> N;
    for (int i = 0; i < N; i++)
    {
        for (int j = 0; j < N; j++)
        {
            cin >> grid[i][j];
        }
    }

    int ctot = 0;
    for (int i = 0; i < N; i++)
    {
        bool good = true;
        for (int j = 0; j < N; j++)
            if (grid[j][i] == '.')
                good = false;
        if (good)
            ctot++;
    }

    for (int i = 0; i < N; i++)
    {
        cscore[i] = 0;
        rgood[i] = false;
    }

    for (int i = 0; i < N; i++)
        for (int j = 0; j < N; j++)
        {
            if (grid[i][j] == '#')
            {
                rgood[j] = true;
                cscore[i]++;
            }
        }

    int ms = -1;
    for (int i = 0; i < N; i++)
    {
        if (rgood[i])
        {
            ms = max (ms, cscore[i]);
        }
        else
            ms = max (ms, cscore[i] - 1);
    }

    if (ms == -1)
        cout << "-1\n";
    else
        cout << 2 * N - ms - ctot << "\n";
}

Measured memory_bytes: 512
d = int(input())

lists = [1, 2, 3, 4, 5, 6, 7, 8, 9]

if d < 10:
    print(d)
    exit()

times = 9

while True:
    tmps = []
    for i in lists:  
        if i % 10 == 0:
            times += 2
            tmps.append(i * 10)
            tmps.append(i * 10 + 1)
        elif i % 10 == 9:
            times += 2
            tmps.append(i * 10 + 8)
            tmps.append(i * 10 + 9)
        else:
            times += 3
            tmps.append(i * 10 + (i % 10 - 1))
            tmps.append(i * 10 + (i % 10))
            tmps.append(i * 10 + (i % 10 + 1))
        
        if times >= d:
            print(tmps[len(tmps) - abs(times - d) - 1])
            exit()
            
    lists = tmps

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

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)

using namespace std;

int main(){
  char ch[10][6] = { {""},
		     {".,!? "},
		     {"abc"},
		     {"def"},
		     {"ghi"},
		     {"jkl"},
		     {"mno"},
		     {"pqrs"},
		     {"tuv"},
		     {"wxyz"}};

  int n;
  scanf("%d", &n);
  while(n--){
    string s;
    cin >> s;
    int f = 0, c = 0, k = 0;
    rep(i, s.size()){
      if(s[i] == '0'){
	//	printf("%d %d\n", k, c-1);
	if(f) printf("%c", ch[k][(c-1)%strlen(ch[k])]);
	f = 0;
	c = 0;
	k = 0;
      }else{
	f = 1;
	c++;
	k = s[i]-'0';
	//	printf("%d %d %d\n", f, c, k);
      }
    }
    puts("");
  }
  return 0;
}

Measured memory_bytes: 1212
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return sys.stdin.read()
def II(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()

from collections import deque

def main():
	n,m=MI()

	G=[[] for _ in range(n+1)]

	for _ in range(m):
		a,b=MI()
		G[a].append(b)
		G[b].append(a)
	#print(G)

	D=[-1]*(n+1)


	Q=deque()
	Q.append([1,0])

	#print(Q)

	f=0

	while Q:
		#print(Q)
		now,d=Q.pop()
		D[now]=d
		for nx in G[now]:
			if D[nx]==-1:
				Q.append([nx,1-d])
			elif D[nx]!=d:
				continue
			else:
				f=1
				break


	if f==1:
		ans=(n*(n-1))//2
	else:
		ans=D.count(0)*D.count(1)


	ans-=m

	print(ans)

















if __name__ == "__main__":
	main()


Measured memory_bytes: 87544
package main

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

var sc = bufio.NewScanner(os.Stdin)

func readInt() int {
	sc.Scan()
	iv, _ := strconv.Atoi(sc.Text())
	return iv
}

func max(x, y float64) float64 {
	if x > y {
		return x
	}
	return y
}

func init() {
	sc.Split(bufio.ScanWords)
}

func main() {
	n, k := readInt(), readInt()
	e := make([]float64, n+1)
	for i := 1; i <= n; i++ {
		p := float64(readInt())
		e[i] = (p+1)/2 + e[i-1]
	}

	ans := 0.0
	for i := 0; i <= n-k; i++ {
		ans = max(e[i+k]-e[i], ans)
	}
	fmt.Println(ans)
}


Measured memory_bytes: 3072
#include<string>
#include<list>
#include<iostream>
using namespace std;
int main(){
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  string str;
  list<int> data;
  list<int>::iterator it,l;
  int n,x;
  cin >> n;
  while(n--){
    cin >> str;
    if(str == "insert"){
      cin >> x;
      data.push_front(x);
    }else if(str == "delete"){
      cin >> x;
      for(it=data.begin(),l=data.end();it!=l;++it){
	if(*it == x){
	  data.erase(it);
	  break;
	}
      }
    }else if(str == "deleteFirst") data.pop_front();
    else data.pop_back();
  }
  for(it=data.begin(),l=data.end();it!=l;++it){
    cout << (it==data.begin() ? "" : " ") << *it;
  }
  cout << endl;
}

Measured memory_bytes: 32476
N = int(input())

Alist = list(map(int, input().split()))
Blist = list(map(int, input().split()))
Clist = list(map(int, input().split()))

ans = 0
pre = 100
for i in Alist:
    ans += Blist[i-1]

    if i - pre == 1:
        ans += Clist[pre-1]

    pre = i

print(ans)

Measured memory_bytes: 3064
N = int(input())
s = [input() for i in range(N)]
pre = ''
shirori = {}
for i in range(N):
    S = s[i]
    if i == 0:
        pre = S[len(S) - 1]
        shirori[S] = 1
        continue
    else:
        if shirori.get(S) is None:
            now = S[0]
            if now == pre:
                pre = S[len(S) - 1]
                shirori[S] = 1
            else:
                print('No')
                exit(0)
        else:
            print('No')
            exit(0)
print('Yes')


Measured memory_bytes: 8900
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define pb push_back
#define forr(i,x,y) for(int i=x;i< y;i++)
#define sci(x) int x; cin>>x;
#define scii(x,y) int x,y; cin>>x>>y;
#define sciii(x,y,z) int x,y,z; cin>>x>>y>>z;
#define tc(x) sci(x); while(x--)
int main(){
    int n;
    cin>>n;
    int x =n%10;
    if(x==2||x==4||x==5||x==7||x==9)cout<<"hon"<<endl;
    else if(x==0||x==1||x==6||x==8)cout<<"pon"<<endl;
    else cout<<"bon"<<endl;
    return 0;
}

Measured memory_bytes: 3628
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ULL;
typedef long long LL;
#define FOR(i, a, b) for(LL i=(LL)(a);i<(LL)(b);i++)
#define REP(i,x) for(LL i=0;i<(LL)(x);i++)
#define MOD_PRIME = 1e9 + 7;

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

    LL a, b, c;
    cin >> a >> b >> c;
    cout << c << " " << a << " " << b << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define maxn 200015
#define maxm 200015
#define maxb
#define maxr 200000
#define maxs
#define M 
#define pii pair<int, int>
#define pdd pair<double, double>
#define uint unsigned int
#define ull unsigned long long int
#define ll long long int 
#define lowbit(x) x & -x
#define fi first
#define se second
#define pb push_back
#define next NEXT
#define hash HASH
#define ls ch[x][0]
#define rs ch[x][1]
#define pi 3.141592653589793
#define ei 2.718281828459045
#define rep(i, l, r) for (register int i = l; i <= r; i++)
#define per(i, r, l) for (register int i = r; i >= l; i--)
#define srep(i, l, r) for (register int i = l; i < r; i++)
#define sper(i, r, l) for (register int i = r; i > l; i--)
#define erep(i, x) for (register int i = h[x]; i; i = e[i].next)
#define gc() ((p1 == p2 && (p2 = (p1 = buffer) + fread(buffer, 1, maxr, stdin), p1 == p2)) ? EOF : *p1++)
#define END return 0
//#define ONLINE_JUDGE
//#define DEBUG
using namespace std;

char *p1, *p2, buffer[maxr];
template <class T> void read(T& x){
    char ch = gc(); x = 0; bool f = 1;
    while (!('0' <= ch && ch <= '9') && ch != '-') ch = gc();
    if (ch == '-') f = 0, ch = gc();
    while ('0' <= ch && ch <= '9') x = (x << 3) + (x << 1) + ch - '0', ch = gc();
    x = f ? x : -x;
}

int n,m;
struct edge{
    int next, to;
    edge(int next, int to) : next(next), to(to){}
    edge(){}
}e[maxm << 1];
int cnt = 1, h[maxn], ans[maxn];
void Add_Edge(int x, int y){
    e[++cnt] = edge(h[x], y);
    h[x] = cnt;
    e[++cnt] = edge(h[y], x);
    h[y] = cnt;
}
bool vis[maxm << 1];
pii e2[maxm];
pii out[maxm << 1];
int ct = 0;

int ufs[maxn];
int get(int x){
    return ufs[x] = (ufs[x] == x) ? x : get(ufs[x]);
}

int num[maxn];
void dfs(int x, int fa){
    if (ans[x]) num[x] = 1;
    erep(i, x){
        int op = e[i].to;
        if (op == fa) continue;
        dfs(op, x);
        if (num[op] ^ vis[i]) out[++ct] = pii(x, op);
        else out[++ct] = pii(op, x);
        num[x] ^= num[op];
    }
}
int main(){
    int x, y;
    read(n), read(m);
    if (m & 1) {printf("-1"); END;}
    rep(i, 1, n) ufs[i] = i;
    rep(i, 1, m) {
        read(x), read(y);
        ans[x] ^= 1;
        int _x = get(x), _y = get(y);
        if (_x == _y) out[++ct] = pii(x, y);
        else Add_Edge(x, y), ufs[_x] = _y, vis[cnt ^ 1] = 1;
    }
    dfs(1, 1);
    rep(i, 1, ct) printf("%d %d\n", out[i].fi, out[i].se);
    return 0;
}

Measured memory_bytes: 12928
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<stack>
#include<queue>
#include<deque>
#include<map>
#include<set>
using namespace std;
typedef long long ll;
typedef vector<int> VI;
#define FOR(i,n) for(int (i)=0;(i)<(n);(i)++)
#define FOR1(i,n) for(int (i)=1;(i)<(n);(i)++)
#define eFOR(i,n) for(int (i)=0;(i)<=(n);(i)++)
#define eFOR1(i,n) for(int (i)=1;(i)<=(n);(i)++)
#define SORT(i) sort((i).begin(),(i).end())
#define rSORT(i) sort((i).begin(),(i).end(), greater<int>());
#define YES(i) cout << ((i) ? "Yes" : "No") << endl;
#define F first
#define S second
constexpr auto INF = 1000000000;
constexpr auto LLINF = 9223372036854775807;
constexpr auto mod = 1000000007;


int main() {

	ll a;
	cin >> a;
	ll ans = 0;
	for (ll i = 1; i * i <= a; i++) {
		if (a % i == 0) {
			ll r = a / i - 1;
			if (r > 0 && a % r == a / r)ans += r;
		}
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 256
import sys 
sys.setrecursionlimit(10**6)

n = int(input())

memo= [0]*n

def f(i):
	global count

	if i ==1:
		return (1)
	elif memo[i]:
		return (0)
	else:
		count+=1
		memo[i]=1
		return f(a[i]-1)
	
 

a = [int(input()) for i in range(n)]
count=0
if f(0):
	print(count)
else:
	print(-1)



Measured memory_bytes: 88232
#include <cstdio>
#include <string.h>
#include <algorithm>
#define N 510

using namespace std;
int cnt[N][N], dp[N][N];

int main() {
	int n, m, q, l, r;
	scanf("%d%d%d", &n, &m, &q);
	for (int i = 1; i <= m; ++i) {
		scanf("%d%d", &l, &r);
		cnt[l][r]++;
	}
	for (int i = n; i >= 1; --i) {
        for (int j = 1; j <= n; ++j) {
            dp[i][j] = cnt[i][j] + dp[i + 1][j] + dp[i][j - 1] - dp[i + 1][j - 1];
        }
    }
	for (int i = 1; i <= q; ++i) {
		scanf("%d%d", &l, &r);
		printf("%d\n", dp[l][r]); 
	}
	return 0;
}

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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;

int main() {
    int n; cin >> n;
    V<ll> a(n);
    ll m = 0;
    for(int i = 0; i < n; i++){
        cin >> a[i];
        m += a[i] - 1;
    }
    cout << m << endl;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(void){
    int n, x;
    int i, j, k;
    int c;

    while(1){
        scanf("%d %d", &n, &x);
        if(n == 0 && x == 0)
            break;
        c = 0;
        for(i = 1; i <= n; i++){
            for(j = 1; j < i; j++){
                for(k = 1; k < j; k++){
                    if(i + j + k == x)
                        c++;
                }
            }
        }
        printf("%d\n", c);
    }
    return 0;
}

Measured memory_bytes: 1772
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = Integer.parseInt(sc.next());
        int ans = 1;
        String[] dic = new String[ n ];

        for( int i=0; i<n; i++ ){
           dic[i] = sc.next();
        }
        sc.close();
        Arrays.sort(dic);

        for( int j=0; j<n-1; j++ ){
            if( dic[ j ].equals( dic[ j+1 ] ) ){
            }else{
                ans++;
            }
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 61896
#include <stdio.h>

int main(){
  int n,q,i,k,l,r,m;
  int S[100000],c = 0;

  scanf("%d" ,&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d" , S + i);
  }

  scanf("%d" ,&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d" ,&k);
    l = 0; r = n;
    while(r >= l){
      m = (l + r) / 2;

      if(S[m] == k){
	c++;
	break;
      }

      if(S[m] < k){
	l = m+1;
      }else{
	r = m-1;
      }
    }
  }
  printf("%d\n" ,c);

  return 0;
}



Measured memory_bytes: 2156
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
using namespace std;
using ll=long long;
#define mod  1000000007

int main(int argc, char const *argv[]) {
  ll x;
  std::cin >> x;
  int sum=0,i=0;
  while(x>sum){
    i++;
    sum+=i;
  }

  std::cout << i << '\n';
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <algorithm>
#include <string> //文字列
#include <iomanip> //doubleの桁数指定
#include <list> //前後に数値を入れれる配列
#include <map> //map
#include <vector> //vecror



#define REP(i,m,n) for(ll i = (ll) (m);i < (ll) (n);i++) //forの短縮
#define rep(i,n) REP(i,0,n) //REPが0の時
#define ll long long int

using namespace std;

double PI = 3.141592653589793; //円周率

//常設関数↓

//最大公約数
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}

//degree → radian
ll chg_DegRad(int deg) {
	return deg * PI / 180.0;
}

//radian → degree
ll chg_RadDeg(int rad) {
	return rad * 180.0 / PI;
}

//距離
double dis(double xa, double ya, double xb, double yb) {
	return pow(pow(xa - xb, 2.0) + pow(ya - yb, 2.0), 0.5);
}



//提出コード↓
string s;
bool J = true;




int main() {
	cin >> s;
	rep(i, 3) {
		if (s[i] == s[i + 1]) J = false;
	}
	if (J) cout << "Good" << endl;
	else cout << "Bad" << endl;

	return 0;
}



Measured memory_bytes: 256
while gets do
  @n, @s = $_.split(' ').map(&:to_i)
  break if @n == 0 and @s == 0
  @a = []
  @c = 0

  def dfs(j)
    if @a.size >= @n
      @c += 1 if @a.inject(:+) == @s
      return
    end

    j.upto(9) do |i|
      @a.push(i)
      dfs(i+1)
      @a.pop
    end
  end

  dfs(0)
  puts @c
end

Measured memory_bytes: 6112
#include <cstdio>

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

int main(){
	int a , b ;
	scanf("%d%d" ,&a ,&b) ;
	printf("%d\n" ,gcd(a,b)) ;
	return 0 ;
}



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

int main() {
	int A, B, K;
	cin >> A >> B >> K;
	vector<int> vec;
	vec.push_back(1);
	for (int i = 2; i < 101; i++) {
		if (A % i == 0 && B % i == 0) {
			vec.push_back(i);
		}
	}
	reverse(vec.begin(), vec.end());
	cout << vec.at(K - 1) << endl;
}


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

const int MOD = 1000000007;
#define p(var) std::cout<<#var" = "<<var<<std::endl
#define PI (acos(-1))
#define rep(i, n)   for (int i = 0; i <  (n); i++)
#define repeq(i, n) for (int i = 1; i <= (n); i++)
#define all(a) (a).begin(), (a).end()
#define pb push_back
using ll = long long;
template<typename T> inline T gcd(T a, T b) { return b ? gcd(b,a%b) : a;}
template<typename T> inline T lcm(T a, T b) { return a / gcd(a,  b) * b;}

int main(){
    vector<int> a(5,0);
    vector<int> b(5,0);
    vector<int> v(5,-1);
    rep(i,5){
        cin >> a[i];
    }
    int min=99999999;

    int t;
    rep(i,5){
        b[0]=a[i];
        rep(j,5){
            if(i==j)continue;
            b[1]=a[j];
            rep(k,5){
                if(k==i)continue;
                if(k==j)continue;
                b[2]=a[k];
                rep(l,5){
                    if(l==i)continue;
                    if(l==j)continue;
                    if(l==k)continue;
                    b[3]=a[l];
                    rep(m,5){
                        if(m==i)continue;
                        if(m==j)continue;
                        if(m==k)continue;
                        if(m==l)continue;
                        b[4]=a[m];

                        int tmp=0;
                        rep(m,5){
                            tmp+=b[m];
                            if(m!=4 && tmp%10>0)tmp+=10-(tmp%10);
                        }
                        if(tmp<min)min=tmp;    

                        
                    }
                   
                }
                
            }
            
        }
        
    }

    cout << min << endl;
    

    return 0;
    
}






Measured memory_bytes: 256
import sys
from itertools import permutations

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    M, K = map(int, readline().split())

    if M == 0:
        if K == 0:
            print(0, 0)
            return
        else:
            print(-1)
            return
    elif M == 1:
        if K == 0:
            print(0, 0, 1, 1)
            return
        else:
            print(-1)
            return
    elif K >= pow(2, M):
        print(-1)
        return

    vec = [i for i in range(pow(2, M)) if i != K]
    ans = vec + [K] + vec[::-1] + [K]

    print(' '.join(map(str, ans)))
    return


if __name__ == '__main__':
    main()


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

int main(){
    string s;
    cin >> s;
    if(s[0]==s[1]){
        cout << "1 2" << endl;
        exit(0);
    }
    for(int i = 0; i < (int)s.size() - 2; i++){
        if(s[i] == s[i + 1] || s[i + 1] == s[i + 2] || s[i] == s[i + 2]){
            cout << i + 1 << ' ' << i + 3 << endl;
            exit(0);
        }
    }
    cout << "-1 -1" << endl;
}

Measured memory_bytes: 3816
#include<cstdio>
#include<algorithm>
#include<cstring>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
ll read()
{
   ll x=0;bool f=1;char ch=getchar();
   while (ch<'0'||ch>'9') {if (ch=='-') f=-1;ch=getchar();}
   while (ch>='0'&&ch<='9') x=(x<<1)+(x<<3)+ch-'0',ch=getchar();
   return x*f;
}
struct node{ll s,t,cha[202];}num[60*202];
int n,tot,top;
pair<ll,ll> q[60*202];
ll K,ans,a[202],mo[202],d[202];
bool cmp(const node &A,const node &B)
{for (int i=1;i<n;i++) if (A.cha[i]<B.cha[i]) return 1;else if (A.cha[i]>B.cha[i]) return 0;return 0;}
bool check(int x,int y)
{
	for (int i=1;i<n;i++) 
	  if (num[x].cha[i]!=num[y].cha[i]) return 0;
	return 1;
}
ll minpop(ll x,ll y)
{ 
   ll res=0;
	for (int i=60;i>=0;i--)
	  if (((x>>i)&1)==((y>>i)&1)) res+=((x>>i)&1);
	  else {res++;break;}
	return res;
}
void work()
{
	sort(q+1,q+top+1);
	ll l=q[1].first,r=q[1].second; 
	for (int i=2;i<=top;i++)
	{
		if (r<q[i].first) ans=((ll)ans+r-l+1)%mod,l=q[i].first;
		r=max(r,q[i].second);
	}
	ans=((ll)ans+r-l+1)%mod;
}
int main()
{
	n=read();K=read();
	for (int i=1;i<=n;i++) a[i]=read();
	sort(a+1,a+n+1);
	for (int i=0;i<=60;i++)//枚举除以2的次数
	{
		for (int j=1;j<=n;j++)
		  mo[j]=(a[j]&((1ll<<i)-1));//将a[i]都%2^k
		sort(mo+1,mo+n+1);
		int sc=unique(mo+1,mo+n+1)-mo-1;
		for (int j=1;j<=sc;j++)
		if (mo[j]<=a[1])//a[1]（最小的一个）要能够减得下mo[j] 
		{
			int P=(j==1)?0:minpop(mo[j],mo[j-1]);
			for (int k=1;k<=n;k++)
			  d[k]=((a[k]-mo[j])>>i);//算出除去后面i位后剩下的东西
			if (i+P<=K)
			{
			  num[++tot].s=d[1];num[tot].t=i+P;//保存首项和最少操作次数 
			  for (int k=1;k<n;k++)
			    num[tot].cha[k]=d[k+1]-d[k];//保存差分数组，用来判断是否本质不同 
		   }
		} 
	}
	sort(num+1,num+tot+1,cmp);
	for (int i=1;i<=tot;i++)
	{
		if (i!=1&&!check(i,i-1)) work(),top=0;
		q[++top]=make_pair(max(num[i].s-K+num[i].t,0ll),num[i].s);
	} 
	work(); 
	printf("%lld\n",ans);
   return 0;
}

Measured memory_bytes: 16512
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;

int n, m, s, t;

struct edge
{
    int to, cost;
};
#define V 100010
vector<edge> G1[V], G2[V];
int d1[V], d2[V];

void dijkstra1(int s)
{
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d1, d1 + V, INF);
    d1[s] = 0;
    que.push(P(0, s));

    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d1[v] < p.first)
            continue;
        for (int i = 0; i < G1[v].size(); i++)
        {
            edge e = G1[v][i];
            if (d1[e.to] > d1[v] + e.cost)
            {
                d1[e.to] = d1[v] + e.cost;
                que.push(P(d1[e.to], e.to));
            }
        }
    }
}
void dijkstra2(int s)
{
    priority_queue<P, vector<P>, greater<P>> que;
    fill(d2, d2 + V, INF);
    d2[s] = 0;
    que.push(P(0, s));

    while (!que.empty())
    {
        P p = que.top();
        que.pop();
        int v = p.second;
        if (d2[v] < p.first)
            continue;
        for (int i = 0; i < G2[v].size(); i++)
        {
            edge e = G2[v][i];
            if (d2[e.to] > d2[v] + e.cost)
            {
                d2[e.to] = d2[v] + e.cost;
                que.push(P(d2[e.to], e.to));
            }
        }
    }
}

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

    cin >> n >> m >> s >> t;
    s--, t--;
    rep(i, m)
    {
        int u, v, a, b;
        cin >> u >> v >> a >> b;
        u--, v--;
        G1[u].push_back({v, a});
        G1[v].push_back({u, a});
        G2[u].push_back({v, b});
        G2[v].push_back({u, b});
    }
    dijkstra1(s);
    dijkstra2(t);
    priority_queue<P, vector<P>, greater<P>> que;
    rep(i, n) que.push(P(d1[i] + d2[i], i));
    P p = que.top();
    int x = p.first, y = p.second;
    rep(i, n)
    {
        while (y < i)
        {
            que.pop();
            P p = que.top();
            x = p.first, y = p.second;
        }
        cout << 1000000000000000 - x << endl;
    }
}

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

using namespace std;

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

const char sp[] = {'7', '5', '3'};
set<int> all;

bool check(string& s) {
  int i,j;
  bool b[3];
  REP(i,3) b[i] = false;
  REP(i,s.length()) REP(j,3) if (s[i] == sp[j]) b[j] = true;
  return b[0] && b[1] && b[2];
}

void make(string& base) {
  if (base.length() >= 10) return;
  if (check(base)) {
    all.insert(stoi(base));
  }
  int i;
  REP(i,3) {
    string a = sp[i] + base;
    make(a);
  }
}

int main() {
  int N;

  string init = "";
  make(init);

  cin >> N;
  int res = 0;
  // for (const int& x : all) cout << x << endl;
  for (const int& x : all) if (x <= N) res++;
  cout << res << endl;

  return 0;
}



Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a[3];
    cin >> a[0] >> a[1] >> a[2];
    sort(a,a+3);
    if((2*a[2]-a[0]-a[1])%2==0)cout << (2*a[2]-a[0]-a[1])/2 << endl;
    else cout << 2+(2*a[2]-a[0]-a[1])/2 << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <functional>
#include <iostream>
#include <vector>

using namespace std;

template <typename T>
class BIT {
  vector<T> tree_;

 public:
  BIT(int n) : tree_(n, 0) {}
  void Add(int i, T x) {
    for (i++; i <= tree_.size(); i += i & -i) {
      tree_[i - 1] += x;
    }
  }

  T Sum(int s) {
    T ans = 0;
    for (s++; s > 0; s -= s & -s) {
      ans += tree_[s - 1];
    }

    return ans;
  }

  T Sum(int l, int r) { return Sum(r - 1) - Sum(l - 1); }
};

int main(int argc, const char *argv[]) {
  using ll = long long;
  int n;
  cin >> n;
  vector<vector<int>> vs(n);
  for (int i = 0; i < n; i++) {
    int c;
    cin >> c;
    vs[c - 1].push_back(i);
  }

  vector<vector<int>> tree(n);
  for (int i = 0; i < n - 1; i++) {
    int a, b;
    cin >> a >> b;
    a--;
    b--;
    tree[a].push_back(b);
    tree[b].push_back(a);
  }

  int k = 0;
  vector<int> in(n), out(n);
  function<void(int, int)> dfs;
  dfs = [&](int v, int p) {
    in[v] = k++;
    for (int u : tree[v]) {
      if (u != p) {
        dfs(u, v);
      }
    }

    out[v] = k;
  };

  dfs(0, -1);

  auto c2 = [](ll n) -> ll { return n * (n + 1) / 2; };
  ll tot = c2(n);
  BIT<ll> d(n);
  for (int i = 0; i < n; i++) {
    d.Add(i, 1);
  }

  for (int i = 0; i < n; i++) {
    ll ans = tot;
    vector<int> &nvs = vs[i];
    sort(nvs.begin(), nvs.end(), [&](int a, int b) { return in[a] > in[b]; });
    vector<pair<int, int>> history;
    for (int v : nvs) {
      int cnt = 1;
      for (int u : tree[v]) {
        if (in[u] < in[v]) {
          continue;
        }

        int num = d.Sum(in[u], out[u]);
        ans -= c2(num);
        cnt += num;
      }

      d.Add(in[v], -cnt);
      history.emplace_back(in[v], cnt);
    }

    ans -= c2(d.Sum(0, n));
    for (auto p : history) {
      d.Add(p.first, p.second);
    }

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

  return 0;
}

Measured memory_bytes: 41052
#include <bits/stdc++.h>
#define rep(i,N) for (int i = 0; i < (N); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
const int inf{int(1e9)};
int main(void){
  ll L, R;
  cin >> L >> R;
  /*
  ll sa = R - L;
  L %= 2019;
  R %= 2019;
  if (L == 0 || L == 2018) cout << 0 << endl;
  else if (sa < 2019 - L) cout << (L * (L + 1)) % 2019 << endl;
  else cout << 0 << endl;
  */
  int ans = 2018;
  R = min(R, L + 4038);
  for (ll i = L; i <= R; i++){
    for (ll j = i + 1; j <= R; j++){
      int x = i*j%2019;
      ans = min(ans, x);
    }
  }
  cout << ans << endl;
  return 0;
}


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

using namespace std;

int main() {

    int x;
    int q1;
    int q2;
    int r1;

    cin >> x;

    q1 = x/500;
    r1 = x - 500*q1;

    q2 = r1/5;

    cout << (1000*q1 + 5*q2) << endl;

    return 0;
}


Measured memory_bytes: 256