akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
#define endl "\n"
#define pb push_back
#define f(i,n) for(i=0;i<n;i++)
#define F(i,a,b) for(i=a;a<=b;i++)
#define arr(a,n) for( i=0;i<n;i++)cin>>a[i];
#define fi first
#define se second
#define mp make_pair
#define mod 1000000007
#define YES cout<<"YES"<<endl;
#define Yes cout<<"Yes"<<endl;
#define NO cout<<"NO"<<endl;
#define No cout<<"No"<<endl;
#define yes cout<<"yes"<<endl;
#define no cout<<"no"<<endl;
#define vi vector<ll>
#define ed end()
#define bg begin()
#define sz size()
#define ln length()
#define s() sort(a,a+n);
#define sr() sort(a,a+n,greater<ll>());
#define v()  sort(v.begin(),v.end());
#define vr() sort(v.begin(),v.end(),greater<ll>());
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
ll gcd(ll a, ll b){if(!b)return a;return gcd(b, a % b);}
ll power(ll x,ll y,ll p){ll res=1;x%=p;while(y>0){if(y&1)res=(res*x)%p;y=y>>1;x=(x*x)%p;}return res;}
int main() {
    /*#ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif*/
        /* 
        Ofcourse it's Hard.
        It's supposed to be Hard.
        If it's easy everyone would do it.
        HARD IS WHAT MAKES IT GREAT

        YESTERDAY U SAID TOMORROW

        SLOWLY BECOMING THE PERSON I 
        SHOULD HAVE BEEN A LONG TIME AGO

        SAME TASK CAN'T BE FOUND DIFFICULT TWICE

        BTBHWSITW

        SPRH TU KAB P

        CP IS ALL ABOUT THINKING 
        YOU HAVE MUCH MORE POTENTIAL THAN U THINK


        */

fast();
//ll t;cin>>t;while(t--)
{
   string s;
   cin>>s;
   ll n=s.length();
   string a=s.substr(0,n/2);
   string b=s.substr(n/2+1,n/2);
   cerr<<a<<" "<<b<<endl;
   if(a==b)
   {
    Yes
   } 
   else
   {
    No
   }
}
return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <string>
#include <vector>
#include <bitset>
#define ls id<<1
#define rs id<<1|1
using namespace std;
typedef long long ll;
ll L,R;
int ans=9999;

int main(){
	cin>>L>>R;
	ll l1=L/2019;
	ll l2=L%2019;
	ll r1=R/2019;
	ll r2=R%2019;
	if(l2==0||r2==0||(r1-l1>=1)){
		cout<<0;
		return 0;
	}
	for(int i=l2;i<=r2;++i){
		for(int j=i+1;j<=r2;++j){
			ans=min(ans,(i*j)%2019);
		}
	}
	cout<<ans;
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < n; ++i)
using ll = long long;
const ll MOD = 1000000007;//998244353;
int main() {
   ios::sync_with_stdio(false);
   cin.tie(0);
   int n; cin >> n;
   vector<int> a(n);
   rep(i,n)cin>>a[i];
   sort(a.begin(),a.end());
   reverse(a.begin(),a.end());
   queue<int> que;
   que.push(a[0]);
   ll ans = 0;
   rep(i,n-1){
      ans += que.front();
      que.pop();
      que.push(a[i+1]);
      que.push(a[i+1]);
   }
   cout << ans << endl;
}

Measured memory_bytes: 4748
"use strict";
function main(input) {
    let line = input.split(/\r?\n/g);
    const A = line[1].split(" ").map(Number);
    let flg = true;
    for (let i in A)
        if (!(A[i] % 2) && A[i] % 3 && A[i] % 5) {
            flg = false;
            break;
        }
    console.log(flg ? "APPROVED" : "DENIED");
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));

Measured memory_bytes: 7372
l, r = map(int, input().split())

min = 2019

for i in range(l, r+1):
    for j in range(i+1, r+1):
        p = (i % 2019)*(j % 2019) % 2019
        if p < min:
            min = p

        if min == 0:
            print("0")
            exit()

print(min)

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

int a, b, x, y;
 
int32_t main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	cin >> a >> b >> x >> y;
	cout << (a - x) * (b - y) << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define lli long long int
#define mod 1000000007
#define exp pow(10,-9)
#define F first
#define S second
#define PB push_back 
#define MP make_pair
#define daman ios_base :: sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define lowercase(str) transform(str.begin(), str.end(), str.begin(), ::tolower);
#define uppercase(str) transform(str.begin(), str.end(), str.begin(), ::toupper);
main()
{
	int n;
	cin>>n;
	string str;
	cin>>str;
	
	int l=0,r=n-1;
	int count = 0;
	while(l <= r)
	{
		if(str[l] == 'W' && str[r] == 'R')
		{
			count++;
			swap(str[l],str[r]);
			l++;
			r--;
		}
		else if(str[l] == 'R' && str[r] == 'R')
			l++;
		else if(str[l] == 'W' && str[r] == 'W')
			r--;
		else
		{
			l++;
			r--;
		}
	}
	cout<<count<<"\n";
}

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

#define INPUT_FROM_FILE (0) 
#if INPUT_FROM_FILE
#include <fstream>
#endif

int main(int argc, char **argv){
	int m, d;
	std::vector<int> num_date_month;

	num_date_month.push_back(0);
	num_date_month.push_back(31); //31
	num_date_month.push_back(60); //29
	num_date_month.push_back(91); //31
	num_date_month.push_back(121); //30
	num_date_month.push_back(152); //31
	num_date_month.push_back(182); //30
	num_date_month.push_back(213); //31
	num_date_month.push_back(244); //31
	num_date_month.push_back(274); //30
	num_date_month.push_back(305); //31
	num_date_month.push_back(335); //30

#if INPUT_FROM_FILE
	std::ifstream ifs("test.txt");
	//FILE *fp = fopen("test.txt", "r");
#endif

#if INPUT_FROM_FILE
	while(ifs >> m >> d){
#else
	while(std::cin >> m >> d){
#endif
		if(m == 0 && d == 0){
			break;
		}
		int num_date = num_date_month[m - 1] + d - 1;
		int day = num_date % 7;

		switch(day){
		case 0:
			std::cout << "Thursday" << std::endl;
			break;
		case 1:
			std::cout << "Friday" << std::endl;
			break;
		case 2:
			std::cout << "Saturday" << std::endl;
			break;
		case 3:
			std::cout << "Sunday" << std::endl;
			break;
		case 4:
			std::cout << "Monday" << std::endl;
			break;
		case 5:
			std::cout << "Tuesday" << std::endl;
			break;
		case 6:
			std::cout << "Wednesday" << std::endl;
			break;
		default:
			break;
		}

	}

	
	return 0;
}


Measured memory_bytes: 3148
#include<bits/stdc++.h>
using namespace std;
#define int long long int
int32_t main(){
    int k,i,ans=-1,tmp=0;
    cin>>k;
    for(i=1;i<=k+100;i++){
        tmp=tmp*10+7;
        tmp%=k;
        if(!tmp){ans=i;break;}
    }cout<<ans;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define pb push_back
#define ll int 
#define mp make_pair
#define int long long 
#define ff first 
#define ss second
const int p=1e9 + 7;
const int mod=1e9 + 7;
const int Mod=1e9 + 7;
const int INF=1e9 + 7;
const int Maxn=1000000;
using namespace std;
 
void solve()
{
 string s;
 cin >> s;
 int j=0;vector<int > vv;
 for(int i=0;i<s.length();i=j)
 {
     int count=0;int flag=0;
     //cout << "yes" << endl;
     while(s[i]=='R' && i<s.length())
     {
         count++;
         flag=1;
         i++;
     }
     if(flag)
     {
         j=i;
         vv.pb(count);
     }
     else
     {
         j=i+1;
     }
 }
 sort(vv.begin(),vv.end());
 if(vv.size()>0)
 cout << vv[vv.size()-1] << endl;
 else
 cout << "0" << endl;
 
}
 
signed main() {
    
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
   int t;
   t=1;
   while(t--)
    solve();
  
 
}

Measured memory_bytes: 3640
n, x = map(int, input().split())
a = [int(i) for i in input().split()]

count = 0
for i in range(n):
    #print(a)
    s = sum(a[i:i+2])
    if s > x:
        if (s - x > a[i+1]):
            a[i+1] = 0
            a[i] -= (s - x - a[i+1])
        else:
            a[i+1] -= sum(a[i:i+2]) - x
        count += s - x

print(count)


Measured memory_bytes: 14592
#include <stdlib.h>
#include <iostream>
#include <algorithm>

using namespace std;

int main(void){
    int N;
    int D, X;

    cin >> N;
    cin >> D >> X;

    int A[100];
    int sums=X;
    int tmp;


    for(int i=0;i<N;i++){
        cin >> A[i];
    }
    for(int i=0;i<N;i++){
        sums = sums + ((D - 1) / A[i] + 1);
    }
    cout << sums;
    
    return 0;
}

Measured memory_bytes: 256
def main():
    k, n = map(int, input().split())
    a = list(map(int, input().split()))
    cost = a[n-1]-a[0]
    for i in range(n-1):
        cost = min(cost, k-(a[i+1]-a[i]))
    print(cost)

if __name__ == "__main__":
    main()

Measured memory_bytes: 25836
#include <cstdlib>
#include <iterator>
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cctype>
#include <functional>
using namespace std;

int main() {
    int d;
    cin >> d;
    if(d == 25) cout << "Christmas" << endl;
    else if(d == 24) cout << "Christmas Eve" << endl;
    else if(d == 23) cout << "Christmas Eve Eve" << endl;
    else if(d == 22) cout << "Christmas Eve Eve Eve" << endl;
}


Measured memory_bytes: 256
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-9
#define INF 2000000000
#define sz(x) ((int)(x).size())
#define fi first
#define sec second
#define SORT(x) sort((x).begin(),(x).end())
#define all(x) (x).begin(),(x).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
int dx[6]={-1,-1,0,1,1,0};
int dy[2][6]={{-1,0,1,0,-1,-1},{0,1,1,1,0,-1}};
int W,H;
int m[105][105];
int f[105][105];
void bfs()
{
	memset(f,0,sizeof(f));
	queue<P> q;
	f[0][0]=1;
	q.push(P(0,0));
	while(!q.empty())
	{
		P a=q.front();
		q.pop();
		for(int i=0;i<6;i++)
		{
			int nx=a.fi+dx[i],ny=a.sec+dy[a.fi%2][i];
			if(nx<0||nx>H+2||ny<0||ny>W+2)continue;
			if(f[nx][ny]||m[nx][ny])continue;
			q.push(P(nx,ny));
			f[nx][ny]=1;
		}
	}
	return;
}
int count(int x,int y)
{
	int res=0;
	for(int i=0;i<6;i++)
	{
		int nx=x+dx[i],ny=y+dy[x%2][i];
		if(nx<0||nx>H+2||ny<0||ny>W+2)continue;
		if(f[nx][ny]!=f[x][y])res++;
	}
	return res;
}
int main()
{
	cin >> W >> H;
	for(int i=1;i<=H;i++)
	{
		for(int j=1;j<=W;j++)
		{
			cin >> m[i][j];
		}
	}
	bfs();
	int ans=0;
	for(int i=0;i<=H+2;i++)
	{
		for(int j=0;j<=W+2;j++)
		{
			ans+=count(i,j);
		}
	}
	ans/=2;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1308
//   _/                _/                 _/_/_/   _/
//_/_/_/_/   _/_/   _/_/_/_/   _/_/    _/       _/_/
// _/     _/    _/   _/     _/    _/  _/_/_/     _/
//_/     _/    _/   _/     _/    _/  _/    _/   _/
// _/_/   _/_/       _/_/   _/_/      _/_/     _/
#include<iostream>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<set>
#include<map>
#include<queue>
#include<vector>
using namespace std;
typedef long long ll;
const int MOD=1e9+7;
const double pi=3.14159265358979323846;
const int inf=1e9;
const ll INF=5e18;
typedef pair<int,int> P;
int main() {
  cin.tie(0),cout.tie(0);
  ios::sync_with_stdio(false);
  ll n,a[100005]={},m,cnt1=0,cnt2=0;
  cin >> n;
  for(int i=0; i<n; i++) {
    cin >> a[i];
    cnt1+=a[i];
    if(i%2) {
      cnt2+=a[i];
    }
  }
  m=cnt1-2*cnt2;
  cout << m << " ";
  for(int i=1; i<n; i++) {
    m=2*a[i-1]-m;
    cout << m << " ";
  }
  cout << endl;
}

Measured memory_bytes: 2176
#include<bits/stdc++.h>
using namespace std;
int main()
{
    long long int a,b,c,d,count,count1;
    cin >> a >> b >> c >> d;
    count=0;
    while(1)
    {
        if(a>0)
        {
            a=a-d;
            count++;
        }
        else
        break;
    }
    count1=0;
    while(1)
    {
        if(c>0)
        {
            c=c-b;
            count1++;
        }
        else
        break;
    }
    //cout << count << " " << count1;
    
    if(count>=count1)
    cout << "Yes";
    else 
    cout << "No";
    return 0;
    
}

Measured memory_bytes: 3624
#include <iostream> // cout, endl, cin
#include <cmath> //sqrt pow
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
 
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int a,b,c;
  cin >> a >> b >> c;
  b /= a;
  int ans = min(b, c);
  cout << ans << endl;
}

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

#define rep(i,x,y) for(int i=(x);i<(y);++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define dump(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define dump(x)
#endif

typedef long long int ll;
typedef pair<int,int> pii;
//template<typename T> using vec=std::vector<T>;

const int inf=1<<30;
const long long int infll=1LL<<58;
const double eps=1e-9;
const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){
    os << "[";
    for (const auto &v : vec) {
    	os << v << ",";
    }
    os << "]";
    return os;
}

void solve(){
    while(true){
        int w,h;
        cin >> w >> h;
        if(w==0 and h==0) break;
        vector<vector<char>> c(h,vector<char>(w));
        int start,cnt=0;
        map<int,int> m;
        rep(i,0,h) rep(j,0,w){
            cin >> c[i][j];
            if(c[i][j]=='o'){
                start=cnt;
                m[i*w+j]=cnt;
                ++cnt;
            }
            if(c[i][j]=='*'){
                m[i*w+j]=cnt;
                ++cnt;
            }
        }

        vector<vector<pii>> graph(cnt);
        rep(i,0,h) rep(j,0,w){
            if(c[i][j]!='o' and c[i][j]!='*') continue;
            vector<vector<bool>> done(h,vector<bool>(w,false));
            queue<pii> que;
            done[i][j]=true;
            que.push(make_pair(0,w*i+j));
            while(!que.empty()){
                const auto p=que.front();
                que.pop();
                const int y=p.second/w,x=p.second%w;
                if(c[y][x]=='o' or c[y][x]=='*') graph[m[w*i+j]].emplace_back(make_pair(p.first,m[w*y+x]));
                rep(k,0,4){
                    const int ny=y+dy[k],nx=x+dx[k];
                    if(ny<0 or h<=ny or nx<0 or w<=nx or c[ny][nx]=='x' or done[ny][nx]) continue;
                    que.push(make_pair(p.first+1,w*ny+nx));
                    done[ny][nx]=true;
                }
            }
        }

        typedef tuple<int,int,int> triple;
        vector<vector<int>> dist(cnt,vector<int>(1<<cnt,inf));
        priority_queue<triple,vector<triple>,greater<triple>> que;
        dist[start][1<<start]=0;
        que.push(make_tuple(0,start,1<<start));
        while(!que.empty()){
            const auto tri=que.top();
            que.pop();
            const int d=get<0>(tri),v=get<1>(tri),s=get<2>(tri);
            if(d>dist[v][s]) continue;
            for(const auto& e:graph[v]){
                if((s>>e.second)&1) continue;
                const int tmp_d=d+e.first;
                if(tmp_d>dist[e.second][s|(1<<e.second)]) continue;
                dist[e.second][s|(1<<e.second)]=tmp_d;
                que.push(make_tuple(tmp_d,e.second,s|(1<<e.second)));
            }
        }
        int ans=inf;
        rep(i,0,cnt) ans=min(ans,dist[i][(1<<cnt)-1]);
        if(ans==inf) cout << -1 << endl;
        else cout << ans << endl;
    }
}

int main(){
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    cout << fixed << setprecision(8);
    solve();
    return 0;
}

Measured memory_bytes: 3308
// https://atcoder.jp/contests/abc167/tasks/abc167_d
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, K;
    cin >> N >> K;
    vector<int> A(N + 1);
    FOR(i, 1, N + 1) { cin >> A[i]; }
    // 開始時点に戻る数
    int idx = 1, cnt = 0;
    map<int, int> mp;
    while (mp.count(idx) == 0) {
        mp[idx] = cnt++;
        idx = A[idx];
    }

    if (K > cnt) {
        K -= cnt;
        K %= cnt - mp[idx];
        idx = 1;
        REP(i, mp.size() + K) { idx = A[idx]; }
    } else {
        idx = 1;
        REP(i, K) { idx = A[idx]; }
    }
    cout << idx << endl;

    return 0;
}


Measured memory_bytes: 17160
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
#define mod %1000000007
using namespace std;

typedef long long ll;


int main() {
	/*vector<int>v(3);
	cin >> v[0] >> v[1] >> v[2];
	sort(all(v));
	cout << v[0] + v[1] << endl;*/

	/*int N;
	cin >> N;
	vector<int>w(N);
	int s1 = 0, s = 0;
	rep(i, N) {
		cin >> w[i];
		s += w[i];
	}
	int mi = 0, ma = 0;
	rep(i, N) {
		if (s1 + w[i] < s / 2) {
			s1 += w[i];
		}
		else {
			mi = min(s1, s - w[i] - s1) + w[i];
			ma = max(s1, s - w[i] - s1);
			break;
		}
	}
	cout << abs(mi - ma);*/


	int N, M;
	cin >> N >> M;
	vector<int>b(N + 1);
	vector<ll>v(N + 1);
	ll ans = 0;
	int a;
	rep(i, M) {
		cin >> a;
		b[a] = 1;
	}
	int i;
	v[0] = 1;
	v[1] = 1;
	if (b[1]) {
		v[1] = 0;
	}
	for (i = 2; i <= N; i++) {
		if (b[i]) {
			v[i] = 0;
			continue;
		}
		v[i] = (v[i - 1] + v[i - 2])mod;
	}
	cout << v[N];
	

	return 0;
}

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

using namespace std;

#define int long long
#define all(v) (v).begin(), (v).end()
#define resz(v, ...) (v).clear(), (v).resize(__VA_ARGS__)
#define reps(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep(i, n) reps(i, 0, n)

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

using Pi = pair<int, int>;
using Ti = tuple<int, int, int>;
using vint = vector<int>;

const int inf = 1LL << 55;
const int mod = 1e9 + 7;

signed main()
{
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int x, y;
  cin >> x >> y;
  int n = x;
  int cnt = 0;
  while(y >= n) {
    n <<= 1;
    cnt++;
  }
  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 256
import scala.io.Source

object Main extends App {
  val in = Source.stdin.getLines
  for (n <- in if n != "0") {
    val lines = in.take(n.toInt)
    println(lines.foldLeft(1, 2, 3, 1)(roll)._4)
  }

  def roll(value: (Int, Int, Int, Int), op: String): (Int, Int, Int, Int) = {
    val top = value._1
    val front = value._2
    val side = value._3
    val sum = value._4
    op match {
      case "North" => (front, 7 - top, side, sum + front)
      case "East" => (7 - side, front, top, sum + 7 - side)
      case "West" => (side, front, 7 - top, sum + side)
      case "South" => (7 - front, top, side, sum + 7 - front)
      case "Right" => (top, side, 7 - front, sum + top)
      case "Left" => (top, 7 - side, front, sum + top)
    }
  }
}



Measured memory_bytes: 44944
import java.util.*;

// https://atcoder.jp/contests/dp/tasks/dp_a
public class Main {
    public static void main(String args[]) {
        runCode();
    }

    private static void runCode() {
        try (Scanner scan = new Scanner(System.in)) {
            int n = scan.nextInt(), k = scan.nextInt();
            int[] h = new int[n];
            for (int i = 0; i < n; i++) {
                h[i] = scan.nextInt();
            }
            System.out.println(new UsingDP().minCost(h, k));
        }
    }

    public interface Solution {
        int minCost(int[] heights, int k);
    }

    public static class UsingDP implements Solution {
        public int minCost(int[] heights, int k) {
            if (heights.length < 2) return 0;
            int[] costs = new int[heights.length];
            Arrays.fill(costs, 1, costs.length, Integer.MAX_VALUE);
            for (int i = 1; i < heights.length; i++) {
                for (int j = Math.max(0, i - k); j < i; j++) {
                    costs[i] = Math.min(costs[i], costs[j] + Math.abs(heights[j] - heights[i]));
                }
            }
            return costs[costs.length - 1];
        }
    }
}


Measured memory_bytes: 51592
#include<iostream>
#include<cstring>
using namespace std;
struct dice{
	int court[6];
	dice(int c[6]){court[0]=c[0];court[1]=c[1];court[2]=c[2];court[3]=c[3];court[4]=c[4];court[5]=c[5];}
	dice(){}
	void roll(char *ch);
	int top(){return court[0];}
};

void dice::roll(char *ch){
	int tmp;
	if(!strcmp("North", ch)){
		tmp = court[0];
		court[0] = court[1];
		court[1] = court[5];
		court[5] = court[4];
		court[4] = tmp;
	}
	if(!strcmp("East", ch)){
		tmp = court[0];
		court[0] = court[3];
		court[3] = court[5];
		court[5] = court[2];
		court[2] = tmp;
	}
	if(!strcmp("West", ch)){
		tmp = court[0];
		court[0] = court[2];
		court[2] = court[5];
		court[5] = court[3];
		court[3] = tmp;
	}
	if(!strcmp("South", ch)){
		tmp = court[0];
		court[0] = court[4];
		court[4] = court[5];
		court[5] = court[1];
		court[1] = tmp;
	}
	if(!strcmp("Right", ch)){
		tmp = court[1];
		court[1] = court[2];
		court[2] = court[4];
		court[4] = court[3];
		court[3] = tmp;
	}
	if(!strcmp("Left", ch)){
		tmp = court[1];
		court[1] = court[3];
		court[3] = court[4];
		court[4] = court[2];
		court[2] = tmp;
		}
	return;
}

int main(){
	int n, sum;
	int a[6] = {1,2,3,4,5,6};
	char ch[10];
	while(true){
		cin >> n;
		dice d(a);
		sum=d.top();
		if(n==0)break;
		for(int i=0;i<n;i++){
			cin>>ch;
			d.roll(ch);
			sum += d.top();
		}
		cout << sum << endl;
	}
	return 0;
}

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

// main.cpp

class vector2 {
public:
  std::int_fast64_t x;
  std::int_fast64_t y;
  vector2(const std::int_fast64_t x, const std::int_fast64_t y) :
    x(x),
    y(y) {
  }
};

int main() {
  std::string s;
  std::int_fast64_t x, y;
  std::cin >> s >> x >> y;

  vector2 p(0, 0);
  std::vector<std::int_fast64_t> horizontal_moves;
  std::vector<std::int_fast64_t> vertical_moves;
  {
    bool is_first_fs = true;
    std::int_fast64_t current_streak = 0;
    bool is_horizontal = true;
    s += 'T';
    for (const char& c : s) {
      switch (c) {
      case 'F':
        ++current_streak;
        break;
      case 'T':
        if (is_first_fs) {
          p.x += current_streak;
          is_first_fs = false;
        } else {
          if (current_streak > 0) {
            if (is_horizontal) {
              horizontal_moves.push_back(current_streak);
            } else {
              vertical_moves.push_back(current_streak);
            }
          }
        }
        current_streak = 0;
        is_horizontal = !is_horizontal;
        break;
      }
    }
  }

  std::sort(horizontal_moves.begin(), horizontal_moves.end(), std::greater<std::int_fast64_t>());
  std::sort(vertical_moves.begin(), vertical_moves.end(), std::greater<std::int_fast64_t>());

  for (const std::int_fast64_t& move : horizontal_moves) {
    if (p.x < x) p.x += move;
    else p.x -= move;
  }
  for (const std::int_fast64_t& move : vertical_moves) {
    if (p.y < y) p.y += move;
    else p.y -= move;
  }

  std::cout << (p.x == x && p.y == y ? "Yes" : "No") << std::endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner scan = new Scanner(System.in);

    String str = scan.next();
    int q = scan.nextInt();

    for (int i = 0; i < q; i++) {

      String order = scan.next();

      if (order.equals("print")) {
        int a = scan.nextInt();
        int b = scan.nextInt();
        System.out.println(str.substring(a, b + 1));
      } else if (order.equals("reverse")) {
        int a = scan.nextInt();
        int b = scan.nextInt();
        String tmp = str.substring(0, a);
        for (int j = b; j >= a; j--) {
          tmp = String.join("", tmp, Character.toString(str.charAt(j)));
        }
        str = String.join("", tmp, str.substring(b + 1, str.length()));
      } else {
        int a = scan.nextInt();
        int b = scan.nextInt();
        String p = scan.next();
        str = String.join("", str.substring(0, a), p, str.substring(b + 1, str.length()));
      }

    }

  }

}



Measured memory_bytes: 62648
def permutationIndex(A):
  if A is None or len(A) ==0:
    return 0
  index = 1
  factor = 1
  for i in range(len(A)-1,-1,-1):
    rank = 0
    for j in range(i+1,len(A)):
      if A[i] > A[j]:
        rank+=1
    index += rank*factor
    factor *= (len(A)-i)
  return index
n = int(input())
p = [int(x) for x in input().split()]
q = [int(x) for x in input().split()]
print(abs(permutationIndex(p)-permutationIndex(q)))

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

int main(){
    ll x;
    cin >> x;
    ll m = 100;
    ll cnt = 0;
    while(m < x){
        m *= 1.01;
        cnt++;
    }
    cout << cnt << endl;

}


Measured memory_bytes: 3636
import Data.List

main = interact $ show . sol . read

sol n | n<=9 = 1
sol n = succ . floor $ log (fromIntegral (m+1)) / log 10
  where
  q = ceiling . sqrt $ fromIntegral n
  ps = fmap ((,) <$> head <*> length) . group $ primeFactors n
  ds = foldr1 ((<*>) . ((*) <$>)) $ fmap (\x -> (fst x^) <$> [0..snd x]) ps
  m = minimum [d | d <- ds, d>=q]

-- | Prime numbers
primes :: Integral a => [a]
primes = 2 : filter ((==1) . length . primeFactors) [3,5..]

primeFactors :: Integral a => a -> [a]
primeFactors 1 = []
primeFactors n = factor n primes

factor :: Integral a => a -> [a] -> [a]
factor n (p:ps) 
  | p*p > n        = [n]
  | n `mod` p == 0 = p : factor (n `div` p) (p:ps)
  | otherwise      = factor n ps

Measured memory_bytes: 1404
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
#define all(x) x.begin(),x.end()
#define ln '\n'
const long long MOD = 1000000007LL;
//const long long MOD = 998244353LL;
typedef long long ll;
typedef unsigned long long ull; 
typedef pair<int, int> pii;
typedef pair<long long, long long> pll;
template<class T> inline bool chmax(T &a, T b) { if (a < b) { a = b; return true;} return false; }
template<class T> inline bool chmin(T &a, T b) { if (a > b) { a = b; return true;} return false; }
///////////////////////////////////////////////////////////////////////////////////////////////////

vector<vector<int>> G;
int dp[101010][11];
void dfs(int v, int d, int c) {
    if (d < 0) return;
    if (dp[v][d]) return;
    dp[v][d] = c;
    for (auto nv: G[v]) {
        dfs(nv,d-1,c);
    }
    dfs(v,d-1,c);
}

int main() {
    ios::sync_with_stdio(false); cin.tie(nullptr);
    int N,M; cin >> N >> M;
    G.resize(N);
    rep(i,M) {
        int a,b; cin >> a >> b;
        --a; --b;
        G[a].emplace_back(b);
        G[b].emplace_back(a);
    }
    int Q; cin >> Q;
    vector<tuple<int, int, int>> A(Q);
    rep(i,Q) {
        int v,d,c; cin >> v >> d >> c;
        --v;
        A[i] = make_tuple(v,d,c);
    }

    reverse(all(A));
    rep(i,Q) {
        int v,d,c;
        tie(v,d,c) = A[i];
        dfs(v,d,c);
    }
    rep(i,N) {
        cout << dp[i][0] << ln;
    }
}


Measured memory_bytes: 12024
using System;
using System.Linq;
public class Program {
  public static void Main() {
    int[] AB = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
    int A = AB[0] + AB[1], B = AB[0] - AB[1], C = AB[0] * AB[1];
    Console.WriteLine(Math.Max(C, Math.Max(A,B)));
  }
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
ios::sync_with_stdio(false);
std::cin.tie(nullptr);
ll n;
cin >> n;
vector<ll> p(n),q(n);
for(ll i =0; i < n; i++){
    cin >> p[i];
}
for(ll j = 0; j < n; j++){
    cin >> q[j];
}
vector<ll> list(n);
ll cnt = 0;
for(ll i = 0; i < n; i++){
    list[i] = i + 1;
}
ll cntp = 0,cntq = 0;
do{
    cnt += 1;
    for(ll i = 0; i < n; i++){
        if(list[i] != p[i])
        break;
        if(i == n - 1){
            cntp = cnt;
        }
    }
    for(ll i = 0; i < n; i++){
        if(list[i] != q[i])
        break;
        if(i == n - 1){
            cntq = cnt;
        }
    }
}while(next_permutation(list.begin(),list.end()));
cout << abs(cntp - cntq) << endl;
}

Measured memory_bytes: 256
H, W = map(int, input().split())
N = int(input())
A = list(map(int, input().split()))

stage = [[0 for _ in range(W)] for _ in range(H)]
ds = ((0, 1), (1, 0), (0, -1), (-1, 0))

def set_val(p, v):
	global stage
	stage[p[0]][p[1]] = v

def get_val(p):
	return stage[p[0]][p[1]]

current_p = [0, 0]
set_val(current_p, 1)
A[0] -= 1

for i, a in enumerate(A):
	n = a
	while 0 < n:
		for d in ds:
			next_p = (current_p[0] + d[0], current_p[1] + d[1])
			if 0 <= next_p[0] < H and 0 <= next_p[1] < W:
				v = get_val(next_p)
				if v == 0:
					set_val(next_p, i + 1)
					current_p = next_p
					break
		n -= 1

for line in stage:
	print(*line)


Measured memory_bytes: 3948
import sys

import numpy as np
import math, string, itertools, fractions, heapq, collections, re, array, bisect, copy, functools, random
from collections import deque, defaultdict, Counter
from heapq import heappush, heappop
from itertools import permutations, combinations, product, accumulate, groupby
from bisect import bisect_left, bisect_right, insort_left, insort_right
from operator import itemgetter as ig
sys.setrecursionlimit(10 ** 7)
inf = 10 ** 20
INF = float("INF")
mod = 10 ** 9 + 7
"""dd = [(-1, 0), (0, 1), (1, 0), (0, -1)];
ddn = dd + [(-1, 1), (1, 1), (1, -1), (-1, -1)];
ddn9 = ddn + [(0, 0)]
for dx, dy in dd:
        nx = j + dx; ny = i + dy
            if 0 <= nx < w and 0 <= ny < h:"""

def wi(): return list(map(int, sys.stdin.readline().split()))
def wip(): return [int(x) - 1 for x in sys.stdin.readline().split()]  # WideIntPoint
def ws(): return sys.stdin.readline().split()
def si(): return int(sys.stdin.readline())  # SingleInt
def ss(): return input()
def hi(n): return [si() for _ in range(n)]
def hs(n): return [ss() for _ in range(n)]  # HeightString
def s_list(): return list(input())
def mi(n): return [wi() for _ in range(n)]  # MatrixInt
def mip(n): return [wip() for _ in range(n)]
def ms(n): return [ws() for _ in range(n)]
def num_grid(n): return [[int(i) for i in sys.stdin.readline().split()[0]] for _ in range(n)]  # NumberGrid
def grid(n): return [s_list() for _ in range(n)]


def main():

    n = int(input())

    def dfs(s):
        if int(s) > n:
            return 0
        if all(s.count(c) > 0 for c in '753'):
            res = 1
        else:
            res = 0

        for c in '753':
            res += dfs(s + c)
        return res

    print(dfs('0'))

if __name__ == '__main__':
    main()


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

template <typename T> void chmax(T &x,const T &y)
{
	if(x<y)x=y;
}

#define rep(i,l,r) for(int i=l;i<=r;++i)
#define per(i,r,l) for(int i=r;i>=l;--i)

const int N=2000;
bitset<N>s[N],cant[N];
int n,m;

int lk[N],mx;
void merge(int k)
{
	int l=lk[k-1],r=lk[k];
	chmax(mx,r-l+1);
	lk[l]=r;lk[r]=l;
}

int main()
{
	int n,m;
	cin>>n>>m;
	rep(i,0,n-1)
	{
		string str;
		cin>>str;
		rep(j,0,m-1)s[i][j]=str[j]=='#';
	}
	int ans=0;
	rep(i,0,n-1)
	{
		cant[i].reset();
		rep(j,i+1,n-1)
		{
			bitset<N>now=s[i]^s[j];
			cant[j]=cant[j-1]|(now^(now<<1));
		}
		rep(k,0,m-1)lk[k]=k;
		mx=1;
		rep(k,1,m-1)
		if(!cant[n-1][k])
			merge(k);
		chmax(ans,(n-i)*mx);
		per(j,n-2,i)
		{
			bitset<N>now=cant[j]^cant[j+1];
			for(int k=now._Find_next(0);k<N;k=now._Find_next(k))merge(k);
			chmax(ans,(j-i+1)*mx);
		}
	}
	cout<<ans<<endl;
}

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

int main() {
  int N, A, x;
  cin >> N >> A;
  x = N % 500;
  
  if (x == 0) {
  cout << "Yes" << endl;
  }
  else if (x < A) {
  cout << "Yes" << endl;
  }
  else {
  cout << "No" << endl;
  }
}

Measured memory_bytes: 256
# 組み合わせの全探索

import itertools

n, m, x = map(int, input().split())

prices = []
abilities = []

# 値段と1冊で向上させらる能力のリストを格納
for i in range(n):
    s = list(map(int, input().split()))
    abilities.append(s)

combinations = []

# 全組み合わせの計算
for i in range(1, len(abilities)+1):
    s = list(itertools.combinations(abilities, i))
    combinations.append(s)

# print(combinations)

# それぞれの組み合わせを取り出して、条件を満たすかどうか判定
# combinatinons C 1 ~ m までの組み合わせをバラして出す
for combs in combinations:
    # それぞれの組み合わせにバラす
    for i in range(len(combs)):
        counts = [0] * m
        price = 0

        comb = combs[i]
        # print(comb)
        
        # 組みわせの中から1個ずつ取り出す
        for j in range(len(comb)):
            # 値段を取り出して、計算
            a = comb[j]
            price += a[0]

            # 能力値だけのリスト
            b = a[1:]

            # 組み合わせ内の能力を全て足していく
            for k in range(m):
                counts[k] += b[k]
            
            # 参考書の能力が全てxを超えていれば、m個のokをもつリストを作成
            # 条件を満たす組み合わせ
            ans = ['ok' for num in counts if num >= x]
            if len(ans) == m:
                # その時の値段を記録
                prices.append(price)

# 最後に確認して、出力
if len(prices) >= 1:
    print(min(prices))
else:
    print(-1)

Measured memory_bytes: 10260
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <cmath>
#include <bits/stdc++.h>
using namespace std;

int n, k;

int main() {
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) cin >> h[i];
  vector<int> dp(n, 2147483647);
  dp[0] = 0;
  for (int i = 1; i < n; i++) {
    for (int j = max(0, i-k); j < i; j++) {
      dp[i] = min(dp[i], dp[j] + abs(h[i] - h[j]));
    }
  }
  cout << dp[n-1] << "\n";
}


Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        
        Scanner scan = new Scanner(System.in);
        
        String word = scan.nextLine();
        
        int all = word.length();
        
        String Abb = word.substring(0 , 1) + (all - 2) + word.substring(all-1);
        
        System.out.println(Abb);
    }
    
}

Measured memory_bytes: 39344
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int n, m, q, a[55], b[55], c[55], d[55], A[15], ans,sum;

int main()
{
  cin>>n>>m>>q; 
  for(int i=1;i<=q;i++)
      cin>>a[i]>>b[i]>>c[i]>>d[i];
  for(int i=1;i<=n;i++) A[i]=1;
  while(!A[0]){
  	int res=0;
  	for(int i=1;i<=q;i++)
     {
     	 if(A[b[i]]-A[a[i]]==c[i]) res+=d[i];
     }
    ans=max(ans,res);
    for(int i=n;i>=0;i--)
    {
    	if(A[i]<m)
    	{
    		A[i]++;
    		for(int j=i+1;j<=n;j++) A[j]=A[i];
		    break;
		}
	}	
  }
cout<<ans;

return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <cmath>

using namespace std;

int main(){
    long long a,b,x,count=0;
    cin>>a>>b>>x;
    long long div=a/x;
    if(a%x!=0){
        div++;
    }
    long long div1=b/x;
    count=div1-div+1;
    if(count<0)count=0;
    cout<<count<<endl;
    return 0;
}

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

static const int kMaxNumber = 10000;
static int counter[kMaxNumber] = {};

void do_counting_sort(std::vector<int>& data, std::vector<int>& result)
{
    for(int i = 0; i < data.size(); i++) {
        counter[data[i]]++;
    }

    for(int i = 1; i < kMaxNumber; i++) {
        counter[i] = counter[i] + counter[i-1];
    }

    for(int i = 0; i < data.size(); i++) {
        result[counter[data[i]] - 1] = data[i];
        counter[data[i]]--;
    }
}

int main()
{
    int input_size;
    std::cin >> input_size;
    std::vector<int> data(input_size);
    std::vector<int> result(input_size);
    for(int i = 0; i < data.size(); i++) {
        std::cin >> data[i];
    }

    do_counting_sort(data, result);

    printf("%d", result[0]);
    for(int i = 1; i < result.size(); i++) {
        printf(" %d", result[i]);
    }
    putchar('\n');

    return 0;
}

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

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

using namespace std;

int main() {
  int n,l,r;
  while( cin >> n >> l >> r , n | l | r) {
    vector<int> A(n);
    rep(i,n) cin >> A[i];
    int cnt = 0;
    REP(x,l,r+1) {
      rep(i,n) {
	if( x % A[i] == 0 ) {
	  if( ( i + 1 ) & 1 ) {
	    ++cnt;
	  }
	  goto Skip;
	}
      }
      if( !( n & 1 ) ) ++cnt;
    Skip:;
    }
    cout << cnt << endl;
  }
  return 0;
}



Measured memory_bytes: 3124
#include <stdlib.h>
#include <iostream>

using namespace std;

int main(void){
    long long N;
    long long A,B;
    long long ans;

    cin >> N >> A >> B;

    if(A > B){
        ans = 0;
    }
    else if(N==1 and B - A >0){

    }
    else{
        ans = B*(N-2) - A * (N-2) + 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;
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;}

int main() {
  ll r,d,x;
  cin >> r >> d >> x;
  rep(i,10) {
    x = r * x - d;
    cout << x << endl;
  }
}


Measured memory_bytes: 3536
#include <cstdio>
#include <cstring>
#include <cmath>
#include <iostream>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <functional>
#include <vector>
#include <queue>
#include <string>
#include <complex>
#include <stack>
#include <set>
#include <map>

#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i,n) for (int i = (n)-1; i >= 0; i--)
#define FOR(i,s,n) for (int i = (s); i < (n); i++)
#define ALLOF(c) c.begin(), c.end()
#define RANGEOF(c,i,n) c.begin() + (i), c.begin() + (i) + (n)
#define EPS 1e-9
#define INF 1000000000
using namespace std;

typedef complex<int> POINT;
template <class T>
class vevector : public vector<vector<T>>
{
public:
	using vector<vector<T>>::operator []; 
	T& operator [](const POINT &index) { return (*this)[index.real()][index.imag()]; }
};

template <class T> T read() { T t; cin >> t; return t; }
template <> POINT read<POINT>() { int x, y; cin >> x >> y; return POINT(x, y); }
template <class T> vector<T> read(int n) { vector<T> v; REP(i,n) { v.push_back(read<T>()); } return v; }
template <class T> vevector<T> read(int n, int m) { vevector<T> v; REP(i,n) v.push_back(read<T>(m)); return v; }
template <class T> void write(const T &t) { cout << t << endl; }
template <class T> void write(const T &t, const T &t2) { cout << t << ' ' << t2 << endl; }

template <class T> void write(const vector<T> &v)
{
	ostringstream ss; 
	for (auto x : v) ss << x << ' ';
	auto s = ss.str();
	cout << s.substr(0, s.length() - 1) << endl;
}

struct _Reader { template <class T> _Reader operator ,(T &rhs) { cin >> rhs; return *this; } };
#define READ(t,...) t __VA_ARGS__; _Reader(), __VA_ARGS__

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

vector<unsigned char> isPrime;
vector<int> primes;
void initPrimes(int n)
{
	isPrime = vector<unsigned char>(n + 1, true);
	isPrime[0] = isPrime[1] = false;
	FOR(i, 2, n)
	{
		if (!isPrime[i]) continue;
		primes.push_back(i);
		for (int j = i * 2; j <= n; j += i)
			isPrime[j] = false;
	}
}
/// template end ///

void solve()
{
	while (true)
	{
		const int maxHeight = 1000 + 1;
		READ(int, n, m, a);
		if (!(n|m|a)) { break; }

		vector<vector<int>> amida(maxHeight, vector<int>(n + 1));
		REP(i, m) { READ(int, h, p, q); amida[h][p] = q; amida[h][q] = p; }

		int cur = a;
		RREP(i, maxHeight) { if (amida[i][cur]) { cur = amida[i][cur]; } }
		write(cur);
	}
}

Measured memory_bytes: 1600
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a


def lcm(a, b):
    return a * b // gcd(a, b)


def two(val):
    ret = 0
    tmp = val
    while True:
        if tmp != 0 and tmp % 2 == 0:
            ret += 1
            tmp = tmp // 2
        else:
            break
    return ret


n, m = map(int, input().split())
a_list = list(map(int, input().split()))
b_list = []

for item in a_list:
    b_list.append(item // 2)

cnt = -1

for item in b_list:
    ret = two(item)
    if cnt == -1:
        cnt = ret
    elif cnt != ret:
        print(0)
        exit()

val = b_list[0]

for item in b_list:
    val = lcm(item, val)

ret = m // val

tmp1 = ret // 2
tmp2 = ret % 2

print(tmp1 + tmp2)


Measured memory_bytes: 64228
#include <stdio.h>
#define MAX(A,B) ((A)>(B))?(A):(B)
int main()
{
  int a,b,c,x,y;
  scanf("%d%d%d%d%d%*c",&a,&b,&c,&x,&y);
  if(c*2 < a && c*2 < b)
    {
      printf("%d\n", MAX(x,y) * 2 * c);
    }
  else if (c*2 > a + b)
    {
      printf("%d\n", x * a + y * b);
    }
  else
    {
      if(x<y)
	{
	  int yz = y - x;
	  printf("%d\n", c*2 * x + ((c*2 < b)?(c*2):(b)) * yz);
	}
      else
	{
	  int xz = x - y;
	  printf("%d\n", c*2 * y + ((c*2 < a)?(c*2):(a)) * xz);
	}
    }
  return 0;
}


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

int main() {
  int N, D;
  cin >> N >> D;
  vector<int> X(N), Y(N);
  for (int i = 0; i < N; ++i) cin >> X[i] >> Y[i];
  int r = 0;
  auto sqr = [](int u) { return (int64_t) u * u; };
  for (int i = 0; i < N; ++i) r += sqr(X[i]) + sqr(Y[i]) <= (int64_t) D * D;
  cout << r << endl;
  return 0;
}


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


int main(void) {

    int n;
    cin >> n;

    int ans = 0;

    int g[n][n];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            g[i][j] = -1;
        }
    }

    for(int i = 0; i < n; i++){
        int a;
        cin >> a;
        for(int j = 0; j < a; j++){
            int x, y;
            cin >> x >> y;
            x--;
            g[i][x] = y;
        }
    }

    for(int i = 0; i < 1<< n; i++){
        vector<int> d(n);
        for(int j = 0; j < n; j++){
            if(i>>j&1){
                d[j] = 1;
            }
        }
        bool flag = true;
        for(int j = 0; j < n; j++){
            if(d[j]){
                for(int k = 0; k < n; k++){
                    if(g[j][k] == -1) continue;
                    if(g[j][k] != d[k]) flag = false;
                }
            }
        }
        if (flag) ans = max(ans, __builtin_popcount(i));
    
        
    }

    cout << ans << endl;

    
   
    return 0;
    
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(void)
{
   long long int t,n,x,y,a[100001];
   vector<long long int> v,v1,v2;
   vector< pair <long long int,long long int> >p,p1,p2;
   set<long long int> st;
   priority_queue<long long int> pq;
   string s;
   cin>>n;
   if(n>=500)
   {
      x=(n/500);
      cout<<(x*1000)+((n%500)/5)*5<<endl;
   }
   else
      cout<<(n/5)*5<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define int long long
//#define PI 3.14159265358979

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

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

typedef pair< int, int > pii;
typedef long long ll;

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(11);
	}
};
initializer _____;

int N, M, K, T, Q;
signed main() {
	cin >> N;
	vector< int > A(N);
	map< int, int > M;
	rep(i, N) {
		cin >> A[i];
		M[A[i]]++;
	}
	sort(A.begin(), A.end());
	reverse(A.begin(), A.end());
	int ans = 0;
	rep(i, N) {
		if (M[A[i]] == 0)
			continue;
		int c = 0;
		int a = A[i];
		while (a) {
			a >>= 1;
			c++;
		}
		int pow2 = 1 << c;
		int b = pow2 - A[i];
		if (M[b] > 0 && A[i] != b) {
			ans++;
			M[b]--;
		} else if (M[b] > 1 && A[i] == b) {
			ans++;
			M[b]--;
		}
		M[A[i]]--;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 26752
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
	#define eprintf(...) 42
#endif

#define rep(i, n) for(int i = 0, i##_len = (n); i < i##_len; ++i)
#define repp(i, m, n) for(int i = m, i##_len = (n); i < i##_len; ++i)
#define reprev(i, n) for(ll i = (n-1LL); i >= 0; --i)
#define all(x) (x).begin(), (x).end()
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; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <ll,ll> P;
typedef long double ld;
const int MAX = 55555;
int main(void)
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	bool prime[MAX + 1];
	for (int i = 2; i * i < MAX; i++) {
		if (prime[i]) continue;
		for (int j = 2; j * i <= MAX; j++) {
			prime[i * j] = true;
		}
	}
	vector<int> primes;
	for (int i = 2; i <= MAX; i++) {
		if (!prime[i]) primes.push_back(i);
	}
	int n;
	cin >> n;
	for (int i : primes) {
		// eprintf("%d ", i);
		if (i % 5 == 1 && n > 0) {
			n--;
			cout << i << " ";
		}
		if (n == 0) break;
	}
	cout << "\n";
	return 0;
}

Measured memory_bytes: 384