akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
struct meow {int a, b, c, d;}; 

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readc(n, m, q);
	vector<multiset <int>> s[11];
	
	FOR (j, 1, m) s[1].pb({j});
	FOR (i, 2, n)
	{
	        {
	            for (auto p: s[i - 1])
	            {
	                int x = *(--p.end());
	                FOR (k, x, m){
	                s[i].pb(p);
	                (s[i].back()).insert(k);}
	            }
	        }
	}

	meow que[q + 1];
	FOR (i, 1, q)
	{
	    int a, b, c, d;
	    cin >> a>> b >> c >> d;
	    que[i] = {a, b, c,d};
	}
	
	int ans = 0;
	for (auto x: s[n])
	{
	    int arr[n + 1];
	    int p = 0;
	    for (int i: x) arr[++p] = i;
	    //FOR (i, 1, n) cout << arr[i]; cout << endl;
	    
	    int sum = 0;
	    FOR (i, 1, q)
	    {
	        int a = que[i].a, b = que[i].b, c = que[i].c, d = que[i].d;
	        //cout << a << b <<c<<d <<endl;
	        //cout << arr[b] - arr[a] << " " << c << " " << d <<endl;
	        if (arr[b] - arr[a] == c) sum += d;
	    }
	    ans = max(ans, sum);
	}
    
    cout << ans;	
}










Measured memory_bytes: 90700
# coding: utf-8
# Your code here!
import sys
winner='A'

a_card=input()
a_len=len(a_card)
b_card=input()
b_len=len(b_card)
c_card=input()
c_len=len(c_card)
input_a_len=0
input_b_len=0
input_c_len=0

max_len=a_len+b_len+c_len
next_abc=""

if a_card[0]=='a':
    next_abc='a'
elif a_card[0]=='b':    
    next_abc='b'
else:
    next_abc='c'
a_len = a_len-1
input_a_len=input_a_len+1

if a_len==0:
    print("A")
    sys.exit()

for i in range(max_len-1):
    if next_abc=='a':
        if a_len==0:
            print('A')
            break
        else:
            next_abc=a_card[input_a_len]
            input_a_len=input_a_len+1
            a_len = a_len-1
    elif next_abc=='b':
        if b_len==0:
            print('B')
            break
        else:
            next_abc=b_card[input_b_len]
            input_b_len=input_b_len+1
            b_len = b_len-1
    else:
        if c_len==0:
            print('C')
            break
        else:
            next_abc=c_card[input_c_len]
            input_c_len=input_c_len+1
            c_len = c_len-1
#            print(str(c_len))
        





        

Measured memory_bytes: 3064
#include <stdio.h>

void input_data(int a[][3][10]);
void display(int a[][3][10]);

int main(void){
  int A[4][3][10]={0};

  input_data(A);
  display(A);

  return 0;
}

void input_data(int a[][3][10]){
  int n,i,j,k,b,f,r,v;

  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d %d %d %d",&b,&f,&r,&v);
    a[b-1][f-1][r-1]+=v;
  }

  return ;
}

void display(int a[][3][10]){
  int i,j,k;

  for(i=0;i<4;i++){
    for(j=0;j<3;j++){
      for(k=0;k<10;k++){
	printf(" %d",a[i][j][k]);
      }
      printf("\n");
    }
    if(i!=3) printf("####################\n");
  }

  return ;
}

Measured memory_bytes: 612
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <memory.h>
using namespace std;

int arr[51];

int main()
{
	ios::sync_with_stdio(0);
	int m, n, a, b;
	cin >> n >> m;
	for (int i = 0; i < m; ++i)
	{
		cin >> a >> b;
		arr[a]++;
		arr[b]++;
	}
	for (int i = 1; i <= n; ++i)
		cout << arr[i] << '\n';
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a,b,c;
	scanf("%d %d %d",&a,&b,&c);
	if(a<=b&&a<=c){
		if(b>=c){
			printf("%d\n",((b*10)+c)+a);
		}
		else{
			printf("%d\n",((c*10)+b)+a);
		}
	}
	if(b<a&&b<c){
		if(a>c){
			printf("%d\n",((a*10)+c)+b);
		}
		else{
			printf("%d\n",((c*10)+a)+b);
		}
	}
	if(c<a&&c<b){
		if(a>b){
			printf("%d\n",((a*10)+b)+c);
		}
		else{
			printf("%d\n",((b*10)+a)+c);
		}
	}
	return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define itn int
#define REP(i, n) for (int i = 0; i < (n); i++)
#define IREP(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, k, n) for (int i = (k); i < (n); i++)
#define REPEACH(itr, k) for (auto &&itr : k)
#define all(v) v.begin(),v.end()
using namespace std;
typedef long long ll;


const ll INF = 1ll << 60;
const ll MOD = 1000000007;
vector<int> v;

int main()
{
    string s,t;
    cin >> s >> t;
    cout << t << s << endl;
}

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

#define ll long long

int dp[100001];
int n, arr[100001];
int pound(int pos)
{
    if (dp[pos] != -1)
        return dp[pos];
    
    return dp[pos] = min(abs(arr[pos] - arr[pos - 1]) + pound(pos - 1), abs(arr[pos] - arr[pos - 2]) + pound(pos - 2));
    
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    cin >> n;

    memset(dp, -1, sizeof(dp));
    for (int i = 0; i < n; ++i)
        cin >> arr[i];

    dp[0] = 0;
    dp[1] = abs(arr[0] - arr[1]);
    
    cout << pound(n - 1);

    return 0;
}


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

int main() {
  int ballCount, numberCount;
  cin >> ballCount >> numberCount;
  int inputList[200001] = {0};
  int a;

  // 入力値取得
  for (int i = 0; i < ballCount; i++) {
      cin >> a;
      inputList[a]++;
  }
  
  sort(inputList, inputList + ballCount, greater<int>());
  
  int cnt = 0;
  for (int k = 0; k < numberCount; k++) {
      cnt += inputList[k];
  }

  cout << ballCount - cnt << endl;
}

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

using namespace std;

int main(){
	double a,b,c,degree,S;
	scanf("%lf %lf %lf",&a,&b,&degree);
	S = (0.5)*a*b*sin(M_PI*degree/180);
	c = sqrt(a*a+b*b-2*a*b*cos(M_PI*degree/180));
	printf("%.8lf\n",S);
	printf("%.8lf\n",a+b+c);
	printf("%.8lf\n",2*S/a);
}



Measured memory_bytes: 2960
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,k;
    char s[50];
    cin>>n>>k>>s;
    for(int i=0;i<n;i++){
        if(i+1==k){
            printf("%c",s[i]+'a'-'A');
        }
        else{
            cout<<s[i];
        }
    }
}

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

std::vector<int> edges[2010];
int dist[2010][2010];

void dfs(int now, int fa, int depth,int root) {
    dist[root][now] = depth;
    for(int next: edges[now]) {
        if(next == fa) {
            continue;
        }
        dfs(next, now, depth + 1, root);
    }
}

void MAIN() {
    int n, k;
    scanf("%d%d", &n, &k);
    std::vector<std::pair<int, int> > edgePairs;
    for(int i = 1; i < n; ++ i) {
        int u, v;
        scanf("%d%d", &u, &v);
        -- u, -- v;
        edges[u].push_back(v);
        edges[v].push_back(u);
        edgePairs.push_back(std::make_pair(u, v));
    }
    for(int i = 0; i < n; ++ i) {
        dfs(i, i, 0, i);
    }
    int ans = 0;
    if(k & 1) {
        k >>= 1;
        for(auto edge: edgePairs) {
            int cnt = 0;
            for(int i = 0; i < n; ++ i) {
                cnt += std::min(dist[edge.first][i], dist[edge.second][i]) <= k;
            }
            ans = std::max(ans, cnt);
        }
    } else {
        k >>= 1;
        for(int root = 0; root < n; ++ root) {
            int cnt = 0;
            for(int i = 0; i < n; ++ i) {
                cnt += dist[root][i] <= k;
            }
            ans = std::max(ans, cnt);
        }
    }
    printf("%d\n", n - ans);
}

int main() {
    MAIN();
    return 0;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int n, ans = 0;
  cin >> n;
  vector<string> vs(n);
  int a_cnt, b_cnt, ba_cnt;
  a_cnt = b_cnt = ba_cnt = 0;
  for (int i = 0; i < n; i++) {
    cin >> vs[i];
    string &s = vs[i];
    for (int i = 0; i < s.size() - 1; i++) {
      if (s[i] == 'A' && s[i + 1] == 'B') {
        ans++;
      }
    }

    if (s.front() == 'B' && s.back() == 'A') {
      ba_cnt++;
    } else if (s.back() == 'A') {
      a_cnt++;
    } else if (s.front() == 'B') {
      b_cnt++;
    }
  }

  if (ba_cnt > 0) {
    ans += ba_cnt - 1;

    if (b_cnt > 0) {
      ans++;
      b_cnt--;
    }

    if (a_cnt > 0) {
      ans++;
      a_cnt--;
    }
  }

  ans += min(a_cnt, b_cnt) * 2 / 2;
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 768
#include <algorithm>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>

using namespace std;

int solve(int a, int b, int c)
{
  int maximum = max(a, max(b, c));
  if((maximum * 3 - a - b - c) % 2 == 0) {
    return (maximum * 3 - a - b - c) / 2;
  } else {
    return ((maximum+1) * 3 - a - b - c) / 2;
  }
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  int M;
  cin >> N >> M;
  vector<int> answer(N);
  
  // データを受け取る
  for (int i = 0; i < M; i++) {
   int a;
   int b;
   cin >> a >>b;
    answer.at(a-1)++;
    answer.at(b-1)++;
    }
 
  for(int j = 0; j < N; j++){
 cout << answer.at(j) << endl;
  }
}

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

const ll MOD = 1e9+7;
const int INF = (int)1e9+7;

// vector<tuple<long,long>> items; // (value, weight)
// auto item = items[i];
// long v = get<0>(item);
// long w = get<1>(item);
// long v, w;
//   for( int i = 0; i < N; i++ ){
//     cin >> v >> w;
//     items.push_back( make_tuple(v, w) ); // item : (value, weight)
//   }

int main(){
    ll N,M;
    cin >> N >> M;
    ll L, R;
    ll Lmax=0, Rmin=INF;
    for(int i=1; i<M+1; i++){
        cin >> L >> R;
        if(L > Lmax) Lmax = L;
        if(R < Rmin) Rmin = R;
    }
    ll ans = Rmin - Lmax + 1;
    if(ans<0) cout << 0 << endl;
    else if(ans==0) cout << 0 << endl;
    else cout << ans << endl;
    return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);++i)
#define reps(i,n) for(int i=1;i<=(n);++i)
#define repr(i,n) for(int i=(n);i>=0;--i)
#define int long long
#define itn int
#define pb push_back
#define m_p make_pair
#define m_t make_tuple
#define p_p(a,b) pb(m_p(a,b))
#define all(a) a.begin(),a.end()
#define SORT(a) sort(all(a))
#define RSORT(a) sort(all(a),greater<>)
#define UNIQUE(a) a.erase(unique(all(a)),a.end())
#define SZ(a) a.size()
#define ENDL cout<<endl
#define debg(a) cout<<#a<<" "<<a<<endl
#define debgp(a) cout<<#a<<" "<<a.fi<<" "<<a,se<<endl
#define call(a) for(auto i:a)cout<<i<<" ";cout<<endl
#define show(a) for(const auto&y:a){for(const auto&x:y)cout<<x<<" ";cout<<endl;}
#define out(a) cout<<(a)<<endl
#define fi first
#define se second
#define V vector
#define P pair
#define PQ priority_queue
typedef long long ll;
typedef string str;
typedef vector<ll> VL;
typedef pair<ll,ll> PL;
typedef vector<PL> VP;
const long long INF = 1LL<<60;
const long long MOD = 1e9+7;
void Yes(){cout<<"Yes"<<endl;}
void No(){cout<<"No"<<endl;}
void YN(bool b){cout<<(b?"Yes":"No")<<endl;}
template<class T>bool chmax(T &a,const T &b){if(a<b){a=b;return true;}return false;}
template<class T>bool chmin(T &a,const T &b){if(a>b){a=b;return true;}return false;}
template<class T>T gcd(T a,T b){return (b==0?a:gcd(b,a%b));}
template<class T>T lcm(T a,T b){return a/gcd(a,b)*a;}

signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int a,b,c;
  cin>>a>>b>>c;
  if(a==b && b==c && a%2==0){
    out(-1);
    return 0;
  }
  int ans=0;
  for(;;ans++){
    if(a&1 || b&1 || c&1)break;
    int na,nb,nc;
    na=b/2+c/2;
    nb=a/2+c/2;
    nc=a/2+b/2;
    a=na;
    b=nb;
    c=nc;
    //cout<<a<<" "<<b<<" "<<c<<endl;
  }
  out(ans);
    
  
  
  
  return 0;
}


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


struct node { int size, id; };


int main()
{
	while(true) {

		map<int, node> frags;
		int n;
		const int init_size = 2000000000;

		frags.insert({0, {init_size, -1}});
		scanf("%d", &n);

		if(n == 0)
			break;

		for(int command_index = 0; command_index < n; ++command_index) {

			char cmd;
			scanf(" %c", &cmd);

			if(cmd == 'W') {

				int id, size;
				scanf("%d%d", &id, &size);

				auto it = frags.begin();

				while(true) {
					auto &v = it->second;
					if(v.id != -1) {
						++it;
						continue;
					}
					if(v.size > size)
						break;
					v.id = id;
					size -= v.size;
					++it;
				}

				if(size > 0) {
					const int pos = it->first;
					auto &v = it->second;
					const int space = v.size - size;
					v.id = id;
					v.size = size;
					frags.insert({pos + size, {space, -1}});
				}

			} else if(cmd == 'R') {

				int seg;
				scanf("%d", &seg);

				auto it = frags.begin();

				while(true) {
					const int pos = it->first;
					const int size = it->second.size;
					if(pos <= seg && seg < pos + size)
						break;
					++it;
				}

				int ans = it->second.id;

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

			} else {

				int target;
				scanf("%d", &target);

				for(auto it = frags.begin(); it != frags.end(); ++it) {
					if(it->second.id == target)
						it->second.id = -1;
				}
			}

			/*for(auto it = frags.begin(); it != frags.end(); ++it) {
				const int pos = it->first;
				const int size = it->second.size;
				const int id = it->second.id;
				printf("frag: %d %d - %d\n", pos, size, id);
			}
			printf("\n");*/
		}

		printf("\n");
	}

	return 0;
}

Measured memory_bytes: 1276
var GET=(function(){function f(s){return new g(s);}function g(s){this._s=s.trim().split("\n");this._y=0;}g.prototype.a=function(f){var s=this._s, y=this._y, r;if(typeof s[y]==="string")s[y]=s[y].split(" ").reverse();r=s[y].pop();if(!s[y].length)this._y++;return f?r:+r;};g.prototype.l=function(f){var s=this._s[this._y++].split(" ");return f?s:s.map(a=>+a);};g.prototype.m=function(n,f){var r=this._s.slice(this._y,this._y+=n).map(a=>a.split(" "));return f?r:r.map(a=>a.map(a=>+a));};g.prototype.r=function(n,f){var r=this._s.slice(this._y,this._y+=n);return f?r:r.map(a=>+a);};return f;})();
var o=GET(require("fs").readFileSync("/dev/stdin","utf8"));

console.log(main());
function main(){
  var h = o.a();
  var w = o.a();
  var s = o.r(h,1);
  var b = Array(h).fill(0).map(a=>Array(w).fill(0));
  var k = 0;
  for(var y = 0; y < h; y++){
    for(var x = 0; x < w; x++){
      if(b[y][x] !== 0)continue;
      b[y][x] = ++k;
      var l = [[y,x]];
      while(l.length){
        var i = l.pop(), j = i[1]; i = i[0];
        if(i > 0 && b[i-1][j] === 0 && s[i][j] !== s[i-1][j]){b[i-1][j] = k; l.push([i-1,j]);}
        if(i < h-1 && b[i+1][j] === 0 && s[i][j] !== s[i+1][j]){b[i+1][j] = k; l.push([i+1,j]);}
        if(j > 0 && b[i][j-1] === 0 && s[i][j] !== s[i][j-1]){b[i][j-1] = k; l.push([i,j-1]);}
        if(j < w-1 && b[i][j+1] === 0 && s[i][j] !== s[i][j+1]){b[i][j+1] = k; l.push([i,j+1]);}
      }
    }
  }
  var c = Array(k+1).fill(0).map(a=>[0,0]);
  var ans = 0;
  for(i = 0; i < h; i++){
    for(j = 0; j < w; j++){
      if(s[i][j] === ".")c[b[i][j]][0]++;
      else c[b[i][j]][1]++;
    }
  }
  for(i = 0; i <= k; i++)ans += c[i][0] * c[i][1];
  return ans;
}

Measured memory_bytes: 32812
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int k, n, x;
	vector<int> ho, dis;
	cin >> k >> n;
	for (int i = 0; i < n; ++i) {
		cin >> x;
		ho.push_back(x);
	}
	for (int i = 1; i < n; ++i) {
		int l = ho[i] - ho[i - 1];
		dis.push_back(l);
	}
	int l = k - ho[n-1] + ho[0];
	dis.push_back(l);
	sort(dis.begin(), dis.end());
	int ans = k - dis[n - 1];
	cout << ans;

	return 0;
}


Measured memory_bytes: 2548
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <algorithm>
#include <cstring>
using namespace std;

int main() {
  int a,b,c,d;
  int L,R;
  cin >> a >> b >> c >> d;
  L = a + b;
  R = c + d;
  if(L > R)
    cout << "Left" <<'\n';
  if(L < R)
    cout << "Right" <<'\n';
  if(L == R)
    cout << "Balanced" <<'\n';

  return 0;
}

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


int main() {
    int n;
    cin >> n;
    vector<int> v(n);
    for (int i=0; i<n; i++) {
        cin >> v[i];
    }
    
    vector<int> count_odd(100000+1,0), count_even(100000+1,0);
    
    //それぞれの配列のi番目に値iが出た回数を入れておく
    for (int i=0; i<n; i+=2) {
        count_odd[v[i]]++;
    }
    for (int i=1; i<n; i+=2) {
        count_even[v[i]]++;
    }
    
    int max_odd = 0, rec_odd = 0, max_even = 0, rec_even = 0;
    
    for (int i=0; i<n; i+=2) {
        if (count_odd[v[i]] > max_odd) {
            max_odd = count_odd[v[i]];
            rec_odd = v[i];
        }
    }
    
    for (int i=1; i<n; i+=2) {
        if (count_even[v[i]] > max_even) {
            max_even = count_even[v[i]];
            rec_even = v[i];
        }
    }
    
    if (rec_odd != rec_even)
        cout << n - max_odd - max_even << endl;
    else {
        count_odd[rec_odd] = 0;
        int max_odd_2 = 0;
        for (int i=0; i<n; i+=2) {
            if (count_odd[v[i]] > max_odd_2) {
                max_odd_2 = count_odd[v[i]];
            }
        }
        count_even[rec_even] = 0;
        int max_even_2 = 0;
        for (int i=1; i<n; i+=2) {
            if (count_even[v[i]] > max_even_2) {
                max_even_2 = count_even[v[i]];
            }
        }
        
        if (max_odd_2 > max_even_2)
            cout << n - max_odd_2 - max_even << endl;
        else
            cout << n - max_odd - max_even_2 << endl;
        
        
        
    }

    
    
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.math.BigInteger;
import java.util.Comparator;
import java.util.StringTokenizer;

/**
 *
 * @author dkcs
 */
class Main
{
    static class FastReader {
        
        BufferedReader br;
        StringTokenizer st;
        
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
        
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    
    static class Node {
        
        long pp;
        long a, b;
        
        Node(long x, long y) {
            a = x;
            b = y;
            pp = a * b;
        }
    }
    
    static class Comp implements Comparator<Node> {
        
        public int compare(Node o1, Node o2) {
            if (o1.pp > o2.pp) {
                return 1;
            } else {
                return -1;
            }
        }
    }

    public static void main(String[] args) 
    {
        FastReader sc = new FastReader();
        String s[]=sc.nextLine().split(" ");
        BigInteger a=new BigInteger(s[0]);
        BigInteger b=new BigInteger(s[1]);
        BigInteger c=new BigInteger(s[2]);
        BigInteger d=new BigInteger(s[3]);
        BigInteger g=c.gcd(d);
        BigInteger lcm=(c.multiply(d)).divide(g);
        
        BigInteger ca=(a.subtract(BigInteger.ONE)).divide(c);
        BigInteger cb=b.divide(c);
        
        BigInteger da=(a.subtract(BigInteger.ONE)).divide(d);
        BigInteger db=b.divide(d);
        
        BigInteger la=(a.subtract(BigInteger.ONE)).divide(lcm);
        BigInteger lb=b.divide(lcm);
        
        BigInteger ans1=(cb.subtract(ca));
        BigInteger ans2=(db.subtract(da));
        BigInteger ans3=(lb.subtract(la));
        
        BigInteger ans=ans1.add(ans2);
        ans=ans.subtract(ans3);
        
        BigInteger t=b.subtract(a.subtract(BigInteger.ONE));
        ans=t.subtract(ans);
        System.out.println(ans);


        
        
        
        
        
    }
    
    
}


Measured memory_bytes: 23252
/*
    Author:zeke
    
    pass System Test!
    GET AC!!
*/
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <string>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
#include <iomanip>
#include <utility>
#include <stack>
using ll = long long;
using ld = long double;
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define rep3(var, min, max) for (ll(var) = (min); (var) < (max); ++(var))
#define repi3(var, min, max) for (ll(var) = (max)-1; (var) + 1 > (min); --(var))
#define Mp(a, b) make_pair((a), (b))
#define F first
#define S second
#define Icin(s) \
    ll(s);      \
    cin >> (s);
#define Scin(s) \
    ll(s);      \
    cin >> (s);
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;
}
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef vector<V> VV;
typedef vector<P> VP;
ll MOD = 1e9 + 7;
ll INF = 1e18;
ll dfs(){

}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin>>n>>m;
    cout<<n*m<<endl;
}



Measured memory_bytes: 3180
#include<iostream>
#include<cstdio>
#define MAX 105
using namespace std;
int w[MAX];
int v[MAX];
long long dp[MAX][100005]={0};
int main(){
	int n,maxW;
	scanf("%d %d",&n,&maxW);
	for(int i=0;i<n;i++){
		scanf("%d %d",&w[i],&v[i]);
	}
	for(int i=0;i<=100005;i++){
		dp[0][i]=0;
	}
	for(int i=1;i<=n;i++){
		for(int j=1;j<=maxW;j++){
			dp[i][j]=dp[i-1][j];
			if(j>=w[i-1]) dp[i][j]= max(dp[i-1][j-w[i-1]]+v[i-1],dp[i][j]);
		}
	}
	long long res=0;
	for(int j=1;j<=maxW;j++){
		res=max(res,dp[n][j]);
	}
	printf("%lld",res); 
	return 0;
}

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

#define REP(i,num) for(int i=0;i<(num);++i)
#define LOOP(i) while(i--)
#define ALL(c) c.begin(),c.end()
#define PRINTALL(c) for(auto pitr=c.begin();pitr!=c.end();++pitr){cout<<*pitr;if(next(pitr,1)!=c.end())cout<<' ';}cout<<endl;
#define PAIRCOMP(c,comp) [](const pair<ll,ll>& lhs,const pair<ll,ll>& rhs){return lhs.c comp rhs.c;}

using namespace std;
using ll = long long;

constexpr ll atcoder_mod = 1e9+7;

template<typename T=int>
T in(){T x; cin >> x; return (x);}
template<typename T=int,typename C=vector<T>>
C vecin(int N){C x(N);REP(i,N){x[i]=in<T>();}return move(x);}

void vout(){cout << endl;}
template<typename Head,typename... Tail>
void vout(Head&& h,Tail&&... t){cout << ' ' << h;vout(forward<Tail>(t)...);}
void out(){cout << endl;}
template<typename Head,typename... Tail>
void out(Head&& h,Tail&&... t){cout << h;vout(forward<Tail>(t)...);}

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

	int H=in(),W=in(),K=in();
	vector<vector<int>> M(H,vector<int>(W,0)),C(H,vector<int>(W,0));

	int total=1;
	REP(i,H){
		string S=in<string>();
		REP(j,W){
			if(S[j]=='#'){
				M[i][j]=1;
				C[i][j]=total++;
			}
		}
	}

	REP(i,H){
		int start=0;
		bool exist=false;
		int lastC;
		REP(j,W){
			if(M[i][j]==1){
				for(int k=start;k<j;k++) C[i][k]=C[i][j];
				start = j+1;
				lastC=C[i][j];
				exist = true;
			}
		}
		if(exist){
			for(int k=start;k<W;k++) C[i][k]=lastC;
		}
	}
	REP(j,W){
		int start=-1;
		bool exist=false;
		int lastC;
		REP(i,H){
			if(C[i][j]==0 && start<0){
				start = i;
			}
			else if(C[i][j]){
				lastC=C[i][j];
				if(start>=0){
					for(int k=start;k<i;k++) C[k][j]=C[i][j];
					exist = true;
					start = -1;
				}
			}
		}
		if(start>=0){
			for(int k=start;k<H;k++) C[k][j]=lastC;
		}
	}

	for(auto& x:C){
		PRINTALL(x);
	}
	return 0;
}


Measured memory_bytes: 1536
/*
      author  : nishi5451
      created : 14.08.2020 18:23:27
*/

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


int main(){
    int x;
    cin >> x;
    int ans = 1;
    for(int i=2; i*i<=x; i++){
        int now = i;
        while(now*i <= x){
            now*=i;
        }
        if(now != i){
            ans = max(ans,now);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define ld long double 
int32_t main(){
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	#ifndef ONLINE_JUDGE
		freopen("input.txt","r",stdin);
		freopen("output.txt","w",stdout);
	#endif
	int arr[201][201];
	for(int i=1;i<=200;++i)
		for(int j=1;j<=200;++j)
			arr[i][j]=__gcd(i,j);
	int k,s=0; cin>>k;
	for(int i=1;i<=k;++i){
		for(int j=1;j<=k;++j){
			for(int l=1;l<=k;++l){
			//	cout<<arr[i][arr[j][l]]<<"\n";
				s+=arr[i][arr[j][l]];
			}
		}
	}
	cout<<s;
	return 0;
}

Measured memory_bytes: 3968
#include<bits/stdc++.h>
using namespace std;
#define max(a,b) (a<b?b:a)
#define abs(x) (x<0?(-x):x)
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define RF(i,L,R) for (int i = L; i > R; i--)
#define RFE(i,L,R) for (int i = L; i >= R; i--)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define ll long long
#define INF 1000000000000000005
#define nINF -2000000000
#define MOD 1e9+7
#define PI 3.1415926535897932384626
int main(){
	int a,b,c;
	while(~getIII(a,b,c)) printf("%d\n",a*b/2);
}


Measured memory_bytes: 256
def MaxHeapify(a,i):
    l = i*2
    r = i*2+1
    j = i
    if l<len(a) and a[l]>a[j]:j = l
    if r<len(a) and a[r]>a[j]:j = r
    if j!=i:
        a[i],a[j] = a[j],a[i]
        MaxHeapify(a,j)


def init(a):
    for i in reversed(range(1,len(a)//2+1)):
        MaxHeapify(a,i)

def main():
    n = int(input())+1
    a = [-1]+list(map(int,input().split()))
    init(a)
    for i in range(1,n):print (' %d'%a[i],end='')
    print ()


if __name__ == '__main__':
    main()




Measured memory_bytes: 63696
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

const max: usize = 998244353;

fn main() {
    let n: usize = read();
    let s: usize = read();
    let a: Vec<usize> = (0..n).map(|_| read()).collect();
    let mut dp: Vec<Vec<usize>> = vec![vec![0; s + 1]; n + 1];
    dp[0][0] = 1;
    for i in 0..n {
        for j in 0..s + 1 {
            dp[i + 1][j] += 2 * dp[i][j];
            dp[i + 1][j] %= max;
            if j + a[i] <= s {
                dp[i + 1][j + a[i]] += dp[i][j];
                dp[i + 1][j] %= max;
            }
        }
    }

    print!("{}", dp[n][s]);
}


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

using namespace std;

typedef long long ll;
typedef long double ld;

int main() {
    ios_base::sync_with_stdio(false); cin.tie(0); cout.setf(ios::fixed); cout.precision(20);
    #ifdef LOCAL
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    int n, m;
    cin >> n >> m;
    vector <vector <int>> a(n, vector <int> (m));
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            cin >> a[i][j];
            --a[i][j];
        }
    }
    int ans = n;
    vector <int> cnt(m);
    vector <int> hv(m, 1);
    auto relax = [&] () {
        for (int i = 0; i < m; ++i) cnt[i] = 0;
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < m; ++j) {
                if (hv[a[i][j]]) {
                    ++cnt[a[i][j]];
                    break;
                }
            }
        }
    };
    for (int i = 0; i < m; ++i) {
        relax();
        ans = min(ans, *max_element(cnt.begin(), cnt.end()));
        int id = max_element(cnt.begin(), cnt.end()) - cnt.begin();
        hv[id] = 0;
    }
    cout << ans << '\n';
}

Measured memory_bytes: 640
#include<stdio.h>
#define N 100000

int main(void){

  int n, q, C=0, i, j;
  int S[N], T[N];
  int left=0, right, mid, key;

  scanf("%d",&n);

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

  scanf("%d",&q);

  for(j=0;j<q;j++){
    scanf("%d",&T[j]);
  }


  for(j=0;j<q;j++){

    key = T[j];
    right = n;
    left = 0;

    while(left<right){
      mid = (left+right)/2;

      if(S[mid] == key){ C++; break;}
      if(S[mid] != key && S[mid] < key){ left = mid+1;}
      if(S[mid] != key && S[mid] > key){ right = mid;}

    }
  }

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

  return 0;
}



Measured memory_bytes: 2324
// --------------
// Tejas Pandey  |
// 22 - 08 - 20  |
// Atcoder BC 176|
// --------------

#include <bits/stdc++.h>
using namespace std;
     
#define mod 1000000007
#define vi vector<int>
typedef long long int ll;

  int h,w;
  
bool check(int x,int y){
	return (x > -1 && x < h && y > -1 && y < w);
}
       
int main (void){
  //freopen("in.txt","r",stdin);
  //freopen("out.txt","w",stdout);
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  cin >> h >> w;
  char a[h][w];
  bool vis[h][w];
  
  int ch,cw,dh,dw;
  cin >> ch >> cw >> dh >> dw;
  for(int i = 0;i < h;i++)
	for(int j = 0;j < w;j++)
		cin >> a[i][j],vis[i][j] = 0;
  ch--;
  cw--;
  dh--;
  dw--;
  int flag = -1;
  deque<pair<pair<int,int>,int>> dq;
  dq.push_back({{ch,cw},0});
  int dx[] = {0,0,1,-1};
  int dy[] = {1,-1,0,0};
  int dx2[] = {0,0,2,-2,1,-1,1,-1,1,1,-1,-1,2,-2,2,-2,2,-2,2,-2};
  int dy2[] = {2,-2,0,0,-1,1,1,-1,2,-2,2,-2,1,1,-1,-1,2,-2,-2,2}; 
  while(!dq.empty()){
	int x = dq.front().first.first,y = dq.front().first.second;
	int dis = dq.front().second;
	dq.pop_front();
	if(vis[x][y]) continue;
	if(x == dh && y == dw){
		flag = 0;
		cout << dis << "\n";
		break;
	}
	vis[x][y] = 1;
	for(int i = 0;i < 4;i++)
		if(check(x + dx[i],y + dy[i]) && !vis[x + dx[i]][y + dy[i]] && a[x + dx[i]][y + dy[i]] == '.')
			dq.push_front({{x + dx[i],y + dy[i]},dis});
	for(int i = 0;i < 20;i++)
		if(check(x + dx2[i],y + dy2[i]) && !vis[x + dx2[i]][y + dy2[i]] && a[x + dx2[i]][y + dy2[i]] == '.')
			dq.push_back({{x + dx2[i],y + dy2[i]},dis + 1});
	
  }
  if(flag) cout << flag << "\n";
  return 0;
}


Measured memory_bytes: 6148
#include <iostream>
#include <cstring>
#include <cstdio>
#include<cstdint>
#include<utility>
#include<algorithm>
#include<queue>
#include<set>
using namespace std;
typedef long long ll;
typedef pair<int,int>P;
typedef pair<double,double>P_D;
#define rep(i, n) for (int i = 0; i < n; i++)
#define reprev(i, n) for (int i = n - 1; i >= 0; i--)
#define MAX 100100
#define MAX_N 200100
#define SENTINEL 2000000000
const int MOD = 1e9+7;
#define NIL -1
const int INF = 1 << 29;
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}return 0;}
int GCD(int a,int b){return b?GCD(b,a%b):a;}

int main(){
    int n;cin>>n;
    vector<int>a(n);
    rep(i,n)cin>>a[i];
    vector<int>left(n+1,0),right(n+1,0);
    rep(i,n)left[i+1]=GCD(left[i],a[i]);
    reprev(i,n)right[i]=GCD(right[i+1],a[i]);

    int res=0;
    rep(i,n){
        int l=left[i];
        int r=right[i+1];
        chmax(res,GCD(l,r));

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



Measured memory_bytes: 1408
package main

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

var scanner = bufio.NewScanner(os.Stdin)

func nextInt() int {
	scanner.Scan()
	i, err := strconv.Atoi(scanner.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func nextString() string {
	scanner.Scan()
	return scanner.Text()
}

type Item struct {
	v int
	w int
	t string
	d int
	s string
}

type Items []Item

func (p Items) Len() int {
	return len(p)
}

func (p Items) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Items) Less(i, j int) bool {
	if p[i].v == p[j].v {
		if p[i].w == p[j].w {
			if p[i].t == p[j].t {
				if p[i].d == p[j].d {
					return p[i].s < p[j].s
				} else {
					return p[i].d < p[j].d
				}
			} else {
				return p[i].t < p[j].t
			}
		} else {
			return p[i].w < p[j].w
		}
	}
	return p[i].v < p[j].v
}

func main() {
	scanner.Split(bufio.ScanWords)
	var points Items = []Item{}
	n := nextInt()
	for i := 0; i < n; i++ {
		v := nextInt()
		w := nextInt()
		t := nextString()
		d := nextInt()
		s := nextString()
		points = append(points, Item{v,w,t,d,s})
	}
	sort.Sort(points)
	for i := range points {
		fmt.Printf("%d %d %s %d %s\n", points[i].v, points[i].w, points[i].t, points[i].d, points[i].s)
	}
}


Measured memory_bytes: 34884
#include <cstdio>
#include <vector>
#include <numeric>
using namespace std;

int main()
{
  int K;
  while (~scanf("%d", &K)) {
    if (K == 0)
      break;

    vector<int> c(K*(K-1)/2);
    for (int i = 0; i < K*(K-1)/2; ++i)
      scanf("%d", &c[i]);

    printf("%d\n", accumulate(c.begin(), c.end(), 0) / (K-1));
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#include<string.h>
#include <algorithm>
#include<math.h>
#include<vector>
#include <queue>
#include <deque> 
#define ll long long
#define M 1000000007 
#define MM 998244353
using namespace std;
 
int main()
{
	long long int n, temp;

	cin >> n;

	long long int a[n], left[n], right[n];
	
	for (int i = 0; i < n; i++)
	{
		cin >> a[i];
	}

	left[0] = a[0];
	right[n - 1] = a[n - 1];

	for (int i = 1; i < n; i++)
	{
		left[i] = __gcd(left[i - 1], a[i]);
	}

	for (int i = n - 2; i >= 0; i--)
	{
		right[i] = __gcd(right[i + 1], a[i]);
	}

	long long int ans = max(left[n - 2], right[1]);

	for (int i = 1; i < n - 1; i++)
	{
		temp = __gcd(left[i - 1], right[i + 1]);
		ans = max(ans, temp);
	}

	cout << ans;

    return 0;
}

Measured memory_bytes: 5904
#include<bits/stdc++.h>
using namespace std;
long long read()
{
	char ch=getchar();long long x=0,ff=1;
	while(ch<'0'||ch>'9') {if(ch=='-') ff=-ff;ch=getchar();}
	while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
	return x*ff;
}
void write(long long aa)
{
	if(aa<0) putchar('-'),aa=-aa;
	if(aa>9) write(aa/10);
	putchar(aa%10+'0');
	return;
}
const long long mod=998244353;
long long n,m,ans;
long long fac[1000005],ny[1000005];
long long ksm(long long aa,long long bb)
{
	long long now=1;
	while(bb)
	{
		if(bb&1) now=now*aa%mod;
		aa=aa*aa%mod;bb>>=1;
	}
	return now;
}
long long C(long long aa,long long bb)
{
	if(aa>bb) return 0;
	return fac[bb]*ny[aa]%mod*ny[bb-aa]%mod;
}
int main()
{
	n=read(),m=read();fac[0]=1;ans=max(n,m);
	for(int i=1;i<=1000000;++i) fac[i]=fac[i-1]*i%mod;
	ny[1000000]=ksm(fac[1000000],mod-2);
	for(int i=1000000;i;--i) ny[i-1]=ny[i]*i%mod;
	long long NY=ksm(2*C(n,n+m)%mod,mod-2);
	for(int i=1;i<=min(n,m);++i) (ans+=C(i,2*i)*C(n-i,n+m-2*i)%mod*NY%mod)%=mod;
	write(ans);
	return 0;
}

Measured memory_bytes: 15872
#include <bits/stdc++.h>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define PB push_back
#define MK make_pair
#define MOD 1000000007LL
#define endl "\n"
const ll UNDEF = -1;
const ll INF=1e18;
template<typename T> inline bool chkmax(T &aa, T bb) { return aa < bb ? aa = bb, true : false; }
template<typename T> inline bool chkmin(T &aa, T bb) { return aa > bb ? aa = bb, true : false; }
const ll mn=2e3+4;
ll a[mn];
inline ll MK(ll x, ll y) {
	return (x<<32)|y;
}
int main() {
	ios_base::sync_with_stdio(false);
	ll n,rot; cin>>n>>rot;
	for (ll i=0;i<n;i++) cin>>a[i];
	ll final=INF;
	for (ll k=0;k<n;k++) {
		set<ll> s;
		for (ll x=0;x>=-k;x--) {
			ll y=(n+x)%n;
			s.insert(MK(a[y],y));
			//printf("Ins (%lld,%lld)\n",a[y],y);
		}
		ll ans=0;
		for (ll x=0;x<n;x++) {
			ll cand=(*(s.begin()))>>32;
			//printf("x:%lld cand:%lld\n",x,cand);
			ans+=cand;
			ll y=(x-k+n)%n;
			s.erase(MK(a[y],y));
			//printf("Er (%lld,%lld)\n",a[y],y);
			s.insert(MK(a[x+1],x+1));
			//printf("Ins (%lld,%lld)\n",a[x+1],x+1);
		}
		ans+=k*rot;
		//printf("ANS:%lld\n",ans);
		chkmin(final,ans);
	}
	cout<<final<<endl;
}


Measured memory_bytes: 384
import math,string,itertools,fractions,heapq,collections,re,array,bisect,sys,random,time,copy,functools

sys.setrecursionlimit(10**7)
inf = 10**20
eps = 1.0 / 10**15
mod = 10**9+7

def LI(): return [int(x) for x in sys.stdin.readline().split()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()
def pf(s): return print(s, flush=True)


def main():
    n = I()
    s = str(n)
    a = [int(c) for c in s]
    r = sum(a)
    for i in range(len(a)):
        t = sum(a[:i+1]) - 1
        t += (len(a) - i - 1) * 9
        if r < t:
            r = t


    return r


print(main())




Measured memory_bytes: 67536
import java.io.*;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) throws IOException {
        PrintWriter out = new PrintWriter(new OutputStreamWriter(System.out));
        InputReader in=new InputReader(System.in);
        int a=in.nextInt();
        int b=in.nextInt();
        int c=in.nextInt();
        int k=in.nextInt();
        if(a>k)
            out.println(k);
        else{
            int res=0;
            res+=a;
            k-=a;
            if(b>k) {
                res += k;
                k=0;
            }
            else
                k-=b;
            res+=-k;
            out.println(res);
        }
        out.flush();
    }
    static class InputReader{
        private BufferedReader in;
        private StringTokenizer tokenizer;
        public InputReader(InputStream stream){
            in = new BufferedReader(new InputStreamReader(stream),32768);
            tokenizer = null;
        }
        public String next() throws IOException{
            while(tokenizer==null || !tokenizer.hasMoreTokens()){
                tokenizer = new StringTokenizer(in.readLine());
            }
            return tokenizer.nextToken();
        }
        public Long nextLong() throws IOException {
            String next = next();
            return Long.valueOf(next);
        }
        public int nextInt() throws IOException{
            return Integer.valueOf(next());
        }
    }
}

Measured memory_bytes: 32820
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 1e9;
const int MOD = 1000000007;
const double PI = acos(-1);
int dx[4] = {0,1,0,-1};
int dy[4] = {1,0,-1,0};

void solve() {
	int h, w;
	cin >> h >> w;
	vector<string> v(h);
	rep(i,h) cin >> v[i];
	vector<vector<int>> d(h, vector<int>(w, INF));
	queue<pii> q;
	auto update = [&](int y, int x, int nd) {
		if (d[y][x] != INF) return;
		d[y][x] = nd;
		q.push(pii(y, x));
	};

	update(0, 0, 1);
	while (!q.empty()) {
		auto p = q.front(); q.pop();
		rep(i,4) {
			int ny = p.first + dy[i];
			int nx = p.second + dx[i];
			if (nx < 0 || nx >= w || ny < 0 || ny >= h) continue;
			if (v[ny][nx] == '#') continue;
			update(ny, nx, d[p.first][p.second] + 1);
		}
	}
	if (d[h-1][w-1] == INF) {
		cout << -1 << endl;
	} else {
		int cs = 0;
		rep(i,h) rep(j,w) if (v[i][j] == '#') cs++;
		// cout << h * w << " " << cs << " " << d[h-1][w-1] << endl;
		cout << h * w - (cs + d[h-1][w-1]) << endl;
	}
}

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

Measured memory_bytes: 3648
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		Scanner io = new Scanner(System.in);
		int r = io.nextInt();
		int g = io.nextInt();
		int b = io.nextInt();
		
		System.out.println(((10*g+b)%4==0)?"YES":"NO");
	}
}

Measured memory_bytes: 21844
#include <iostream>
#include <vector>
#include <map>

using namespace std;
typedef long long ll;

int main() {
    ll h, w, n;
    cin >> h >> w >> n;
    map<vector<int>, int> ma;
    for (int i = 0; i < n; i++) {
        int x, y;
        cin >> x >> y;
        for (int j = -1; j <= 1; j++) {
            for (int k = -1; k <= 1; k++) {
                int nx = x + j, ny = y + k;
                if (1 < nx && nx < h && 1 < ny && ny < w) ma[{nx, ny}]++;
            }
        }
    }

    vector<ll> ret(10);
    ret[0] = (h - 2) * (w - 2);
    for (auto x:ma) {
        ret[0]--;
        ret[x.second]++;
    }

    for (auto x:ret)cout << x << endl;
    return 0;
}

Measured memory_bytes: 98688
X, N = [int(_) for _ in input().split()]
pn = [int(_) for _ in input().split()]
pn.sort()

pn_bar = [int(_) for _ in range(-100*2-1,100*2+1) if (_ not in pn)]

#print(pn_bar)


now_min = 10000
ans = 10000
for i in pn_bar:
    delta = abs(i - X)
    if(delta < now_min):
        ans = i
        now_min = delta
        
print(ans)

Measured memory_bytes: 62068
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i = 0; i < (n); ++i)
int main() {
    int h, w;
    cin >> h >> w;
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) cin >> a[i];
    vector<vector<int>> cnum(h, vector<int>(w));
    int nowy = 0;
    int nowx = 0;
    rep(i, n) {
        rep(j, a[i]) {
            cnum[nowy][nowx] = i + 1;
            if ( nowy % 2 == 0 ) {
                if ( nowx == w - 1 ) {
                    if ( nowy == h - 1 ) break;
                    ++nowy;
                }
                else {
                    ++nowx;
                }
            }
            else {
                if ( nowx == 0 ) {
                    if ( nowy == h - 1 ) break;
                    ++nowy;
                }
                else {
                    --nowx;
                }
            }
        }
    }
    rep(i, h) {
        rep(j, w) printf("%d ", cnum[i][j]);
        printf("\n");
    }
    return 0;
}


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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  int ans = 1;
  while (ans * 2 <= N) { ans *= 2; }
  printf("%d\n", ans);
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	string s,t="";
	cin>>s;
	if(s.size()<4){
		cout<<"No"<<endl;
		return 0;
	}
	for(int i=0;i<4;i++){
		t+=s[i];
	}
	if(t=="YAKI"){
		cout<<"Yes"<<endl;
	}
	else{
		cout<<"No"<<endl;
	}
	return 0;
}

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

signed main(){
	int y, m, d;
	scanf("%4d/%2d/%2d", &y, &m, &d);
	if(m < 4 || (m == 4 && d <= 30)){
		printf("Heisei\n");
	}
	else{
		printf("TBD\n");
	}
	return 0;
}

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

	#define ll long long
	#define ld long double
	#define F first
	#define S second

	//#define ONLINE_JUDGE 1

	using namespace std;

	const int mod = 1e9+7;

	void solve(){
		int n;
		cin >> n;
		int x,y;
		cin >> x >> y;
		vector<int> cnt(n);
		for(int i = 1; i <= n; i++){
			for(int j = i+1; j <= n; j++){
				int d = min(j-i,abs(x - i) + abs(j - y) +1);
			//	cout << i << " " << j << " " << d << "\n";
				cnt[d]++;
			}
		}
		for(int i = 1; i < n; i++)
			cout << cnt[i] << " ";
	}

	int main(){
		//#ifndef ONLINE_JUDGE	
		//	freopen("in.txt","r",stdin);
		//	freopen("out.txt","w",stdout);
		//#endif
		ios_base::sync_with_stdio(false);
		cin.tie(NULL),cout.tie(NULL);		
		int t = 1;
		//cin >> t;
		while(t--)
			solve();
		return 0;
	}

Measured memory_bytes: 256
#include <stdio.h>

char judge(int pm, int pe, int pj)
{
    int average = (pm + pe + pj) / 3;
    if (pm == 100 || pe == 100 || pj == 100) {
        return 'A';
    } else if ((pm + pe) / 2 >= 90) {
        return 'A';
    } else if (average >= 80) {
        return 'A';
    } else if (average >= 70) {
        return 'B';
    } else if (average >= 50 && (pm >= 80 || pe >= 80)) {
        return 'B';
    } else {
        return 'C';
    }
}

int main(void)
{
    int n; //, pm, pe, pj;
    while (1) {
        scanf("%d", &n);
        if (n == 0) {
            break;
        }
        int pm[n], pe[n], pj[n];
        for (int i = 0; i < n; i++) {
            scanf("%d %d %d",&pm[i], &pe[i], &pj[i]);
        }
        for (int i = 0; i < n; i++) {
          printf("%c\n", judge(pm[i], pe[i], pj[i]));
        }
    }
    return 0;
}

Measured memory_bytes: 1028
#include <bits/stdc++.h>
using namespace std;
int N,K,counter;
int main(){
	cin >> N >> K;
  	bool visited[N];
  	for(int i = 0 ; i < N; i++){
		visited[i] = true;
    }
  	for(int i = 0 ; i < K; i++){
		cin >> counter;
      	for(int j = 0; j < counter; j++){
          	int v;
          	cin >> v;
			visited[v-1] = false;
        }
    }
  	counter = 0;
  	for(int i = 0 ; i < N; i++){
		if(visited[i]){
         	counter++; 
        }
    }
  	cout << counter;
}

Measured memory_bytes: 3604
#include <iostream>
#include <bits/stdc++.h>
#include <math.h>

using namespace std;

int main()
{
    long long available;
    long long assignments;

    cin >> available >> assignments;

    vector<long> times;

    long input;
    for (long long i = 0; i < assignments; i++)
    {
        cin >> input;

        times.push_back(input);
    }

    sort(times.begin(), times.end());

    for (long long i = 0; i < times.size(); i++)
    {
        available -= times[i];
        if (available < 0)
        {
            break;
        }
    }

    if (available < 0)
    {
        cout << -1 << '\n';
    }
    else
    {
        cout << available << '\n';
    }
}


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

int main(){
  int n;
  cin >> n;
  int *x = new int[n];
  for(int i=0; i<n; i++){
    cin >> x[i]; //座標
  }

  int max=x[0];
  int min=x[0];
  for(int i=0; i<n; i++){
    if(max<x[i]){
      max = x[i];
    }else if(min>x[i]){
      min = x[i];
    }
  }

  int ans;
  int *tairyoku = new int[n];
  for(int p=min; p<max; p++){
  	for(int i=0; i<n; i++){
  		tairyoku[p] += pow(x[i]-(p+1), 2);
  	}
    //cout << tairyoku[p] << " ";
  }
  
  int mintai=tairyoku[min];
  for(int p=min; p<max; p++){
    if(mintai > tairyoku[p]){
      mintai = tairyoku[p];
    }
  }
  cout << mintai;
}

Measured memory_bytes: 256
n = int(input())
a = 1
ans = 0
 
# while a < n/2:
#     b = 2
#     while a * b < n:
#         ans += 1
#         b += 1
#     a += 1
 
# print(ans+2*(n-2)+1)
for i in range(1,n):
    ans += (n-1)//i

print(ans)

Measured memory_bytes: 9168