akhauriyash/Code-Regression huggingface dataset:
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
 
public class Main {
	private static FastScanner sc = new FastScanner();
	
	public static void main(String[] args) {
		int H = sc.nextInt();
		int W = sc.nextInt();
		int N = sc.nextInt();
		
		int[] a = new int[N];
		for(int i=0; i<N; i++) {
			a[i] = sc.nextInt();
		}
		
		int[][] grid = new int[H][W];
		int i = 0;
		int j = 0;
		for(int k=0; k<N; k++) {
			for(int l=0; l<a[k]; l++) {
				grid[i][j] = k;
				if(i%2 == 0) {
					if(j == W-1) {
						i++;
					} else {
						j++;
					}
				} else {
					if(j == 0) {
						i++;
					} else {
						j--;
					}
				}
			}
 		}
		
		StringBuilder ans = new StringBuilder();
		for(i=0; i<H; i++) {
			for(j=0; j<W; j++) {
				ans.append(grid[i][j] + 1);
				if(j != W-1) ans.append(" ");
			}
			ans.append("\n");
		}
		System.out.print(ans);
	}
	
	static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}


Measured memory_bytes: 23124
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
/* clang-format on */

const ll INF = 1ll << 60;

int main() {
  int N;
  while (cin >> N) {
    vector<ll> h(N);
    for (int i = 0; i < N; i++) cin >> h[i];
    vector<ll> dp(N, INF);
    dp[0] = 0;
    for (int i = 0; i < N; i++) {
      if (i + 1 < N) {
        dp[i + 1] = min(dp[i + 1], dp[i] + abs(h[i + 1] - h[i]));
      }
      if (i + 2 < N) {
        dp[i + 2] = min(dp[i + 2], dp[i] + abs(h[i + 2] - h[i]));
      }
    }
    cout << dp[N - 1] << endl;
  }
  return 0;
}


Measured memory_bytes: 1792
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>

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

using namespace std;

struct UnionFind{
  vector<int> par,num;

  UnionFind(int N) : par(N),num(N){
    for(int i=0;i<N;i++){
      par[i] = i;
      num[i] = 1;
    }
  }

  int root(int x){
    if(par[x] == x) return x;
    return par[x] = root(par[x]);
  }

  void unite(int x, int y){
    int rx = root(x);
    int ry = root(y);
    if(rx == ry) return;
    par[rx] = ry;
    num[ry] = num[ry]+num[rx]; 
  }

  int get_num(int x){
    int rx = root(x);
    return num[rx];
  }

  bool same(int x, int y){
    int rx = root(x);
    int ry = root(y);
    return rx == ry;
  }
};


int main(void){
  int n,m;
  cin >> n >> m;
  ll sum = 0;
  rep(i,m){
    ll work;
    cin >> work;
    sum += work;
  }

  if(n-sum > -1)cout << n-sum << endl;
  else cout << -1 << endl;
  return 0;
}


Measured memory_bytes: 3636
#include <stdio.h>
#define MAX 100005
#define nil -1

struct Node{
	int p,l,r;
	};
	
struct Node T[MAX];
int n;
int D[MAX];

void print(int u){
	int i,c;
	printf("node %d: ",u);
	printf("parent = %d, ",T[u].p);
	printf("depth = %d, ",D[u]);
	
	if(T[u].p==nil){
		printf("root, ");
	}
	else if(T[u].l==nil){
		printf("leaf, ");
	}
	else {
		printf("internal node, ");
	}
	
	printf("[");
	
	for(i=0,c=T[u].l;c!=nil;i++,c=T[c].r){
		if(i>0){
		printf(", ");
		}
		printf("%d",c);
	}
	
	printf("]");
	printf("\n");
}
void rec(int u,int p){
	D[u]=p;
	if(T[u].r!=nil){
		rec(T[u].r,p);
	}
	if(T[u].l!=nil){
		rec(T[u].l,p+1);
	}
}



int main(void){
	int i,j,d,v,c,l,r;
	scanf("%d",&n);
	for(i=0;i<n;i++){
		T[i].p=T[i].l=T[i].r=nil;
	}
	
	for(i=0;i<n;i++){
		scanf("%d %d",&v,&d);
		for(j=0;j<d;j++){
			scanf("%d",&c);
		
			if(j==0){
				T[v].l=c;
			}
			else{
				T[l].r=c;
			}
			l=c;
			T[c].p=v;
		}
	}

	for(i=0;i<n;i++){
		if(T[i].p==nil){
			r=i;
		}
	}
	rec(r,0);
	
	for(i=0;i<n;i++){
		print(i);
	}
	return 0;
}


Measured memory_bytes: 6448
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i=0; i<n; ++i)
#define all(obj) (obj).begin(),(obj).end()
using namespace std;
typedef long long ll;
 
int main(){
    int S, W;
    cin >> S >> W;
    if(S<=W) cout << "unsafe" << endl;
    else cout << "safe" << endl;
    return 0;
 
 }

Measured memory_bytes: 3636
import java.util.*;

public class Main{

	public static void main(String[] args){

		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        String S = sc.next();
        String T = sc.next();
       
        char[] s = S.toCharArray();
        char[] t = T.toCharArray();
      
        ArrayList<Character> ans = new ArrayList<>();
      
        for(int i = 0; i < N; i++){
          ans.add(s[i]);
          ans.add(t[i]);
        }
        
        
       for(int i = 0; i < N*2; i++){
          char next = ans.get(i);
          System.out.print(next);
        }
        System.out.println();
        
      
	}

}





Measured memory_bytes: 35944
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <cmath>
#include <limits>
#include <climits>
#include <utility>
#include <algorithm>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

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

    if (a + b == 15) {
        cout << "+" << endl;
    } else if (a * b == 15) {
        cout << "*" << endl;
    } else {
        cout << "x" << endl;
    }

    return 0;
}


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

int main(){
  int n;
  cin >> n;
  vector<int> v(n, 0);
  for(int i = 0; i < n; i++){
    cin >> v[i];
  }
  sort(v.begin(), v.end());

  if(v[n/2] == v[n/2 - 1]){cout << 0 << endl;}
  else{
    cout << v[n/2]-v[n/2 - 1] << endl;
  }
}     

Measured memory_bytes: 640
#include <iostream>
#include <vector>
#include <map>
#include <cstdio>
#include <string>
#include <algorithm>
using namespace std;

int main(void){
	int N;
	cin >> N;

	vector<int> A = vector<int>(N, 0);
	long long minLP = 1e10;
	int minIndex = -1;
	int monsterNum = 0;

	for (int cnt = 0; cnt < N; ++cnt){
		cin >> A[cnt];
		if (minLP > A[cnt]){
			minLP = A[cnt];
			minIndex = cnt;
		}
		++monsterNum;
	}

	while(monsterNum > 1){
		int count = 0;
		long long nextMinLP = 1e10;
		int nextMinIndex = -1;
		for(int cnt = 0; cnt < N; ++cnt){
			if(cnt == minIndex){
				continue;
			}
			A[cnt] %= A[minIndex];
			if(A[cnt] == 0){
				++count;
			}else if(nextMinLP > A[cnt]){
				nextMinLP = A[cnt];
				nextMinIndex = cnt;
			}
		}
		if(count == N - 1){
			break;
		}
		minLP = nextMinLP;
		minIndex = nextMinIndex;
	}
	cout << minLP << endl;
    return 0;
}


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

 #最小公倍数


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


S = input().split()
A = int(S[0])
B = int(S[1])
C = int(S[2])
D = int(S[3])

E = lcm(C, D)

X = int(B//C)-int((A-1)//C)
Y = int(B//D)-int((A-1)//D)
Z = int(B//E)-int((A-1)//E)

print(B-A+1-X-Y+Z)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

using namespace __gnu_pbds;
using namespace std;

typedef long long int ll;
typedef unsigned long long int ull;
typedef long double ld;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> indexed_set;

#define mp make_pair
#define pb push_back
#define pf push_front
#define ss second
#define ff first
#define sz(x) (int)x.size()
#define newl "\n"
#define vi vector<int>
#define pii pair<int, int>
#define vii vector<pii>
#define vl vector<ll>
#define pll pair<ll, ll>
#define vll vector<pll>
#define coutp cout << fixed << setprecision(12)
#define mem(x, val) memset(x, val, sizeof(x))
#define fastio                        \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define all(v) (v).begin(), (v).end()

const ld pi = 3.14159265359;
ll INF = 1e18 + 10;
ll MOD = 998244353;
ll mod = 1e9 + 7;

inline ll add(ll a, ll b, ll m)
{
    if ((a + b) >= m)
        return (a + b) % m;
    return a + b;
}

inline ll mul(ll a, ll b, ll m)
{
    if ((a * b) < m)
        return a * b;
    return (a * b) % m;
}

ll power(ll x, ll y, ll m)
{
    ll res = 1;
    x = x % m;
    if (x == 0)
        return 0;
    while (y > 0)
    {
        if (y & 1)
            res = (res * x) % m;
        y = y >> 1;
        x = (x * x) % m;
    }
    return res;
}

void solve()
{
    string s,t;
    cin>>s>>t;
    int cnt=0;
    for(int i=0;i<sz(s);i++) {
        if(s[i]!=t[i]) {
            cnt++;
        }
    }
    cout<<cnt;


}

int main()
{
    fastio;
    int t;

    t = 1;
    //cin >> t;
    //int test=t;
    while (t-- > 0)
    {
        //cout<<"Case #"<<(test-t)<<": ";
        solve();
        cout << newl;
    }

    return 0;
}

Measured memory_bytes: 3740
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<string> vs;
typedef pair<ll,ll> P;
typedef vector<P> vp;
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,m,n) for(int i=m;i<n;i++)
#define REPR(i,n) for(int i=n-1;i>=0;i--)
#define FORR(i,n,m) for(int i=n-1;i>=m;i--)
#define all(in) in.begin(),in.end()
#define ALL(in,K) in,in+K
#define INF 1e18
#define MOD 100000007
#define SIZE 10005
#define PI 	3.14159265358979323846

template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x,y;
    cin >> x >> y;
    cout << ((x%2==1&&y%2==1)?"Yes":"No") << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	cin>>n;
	int a=0;
	for(int i=0;i<n;i++){
		int b;
		cin>>b;
		a=__gcd(a,b);
	}
	cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 384
#include <cstdio>

typedef long long int ll;
const ll INF = 10000000000;

int main(){
    ll a, min = INF, max = -INF;
    for (int i = 0; i < 3; i++){
        scanf("%lld", &a);
        if (a < min){
            min = a;
        }
        if (max < a){
            max = a;
        }
    }
    printf("%lld %lld\n", min, max);
    return 0;
}



Measured memory_bytes: 2720
#include<bits/stdc++.h>
//#define MOD 1000000007
using namespace std;
using ll=long long;

vector<ll> dp(1<<20,-1e18),pre(1<<20);

void rec(int st,vector<int> &left,int mask,int group)
{
	if(st==left.size())
	{
		dp[mask]=max(dp[mask],dp[mask^group]+pre[group]);
		return;
	}
	
	rec(st+1,left,mask|(1<<left[st]),group|(1<<left[st]));
	rec(st+1,left,mask,group);
}

main()
{
	int n;
	cin>>n;
	
	vector<vector<ll>> v(n,vector<ll> (n));
	
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<n;j++)
		cin>>v[i][j];
	}
	
	for(int i=0;i<(1<<n);i++)
	{
		for(int j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				for(int k=j+1;k<n;k++)
				{
					if(i&(1<<k))
					pre[i]+=v[j][k];
				}
			}
		}
	}
	
	dp[0]=0;
	for(int i=0;i<(1<<n);i++)
	{
		vector<int> left;
		for(int j=0;j<n;j++)
		{
			if(((1<<j)&i)==0)
			{
				left.push_back(j);
			}
		}
		
		rec(0,left,i,0);
	}
	
	//for(int i=0;i<(1<<n);i++)
	//cout<<i<<" "<<dp[i]<<" "<<pre[i]<<endl;
	
	cout<<dp[(1<<n)-1];
}

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

static vector<int> adj[2005];
static long long sz[2005]; ///number of stones in the subtree
static long long maxDis[2005]; ///maximum total distance of all stones in the subtree rooted at u, achieved by moving no stones
static long long minDis[2005]; ///minimum total distance of all stones in the subtree rooted at u, move as many stones up towards u
string s;

long long ans = 1e16;

void dp(int u, int p){
	maxDis[u] = 0;
	sz[u] = 0;
	long long totalMax = 0;
	long long maxmax = 0;
	long long maxindex = 0;
	for(int v : adj[u]){
		if(v == p) continue;
		dp(v, u);
		sz[u] += sz[v];
		maxDis[u] += maxDis[v];
		if(maxDis[v] + sz[v] > maxmax){
			maxmax = maxDis[v] + sz[v];
			maxindex = v;
		}
		totalMax += maxDis[v] + sz[v];
	}
	maxDis[u] += sz[u];
	
	long long rem = totalMax - maxmax;
	if(maxmax <= rem) minDis[u] = totalMax % 2;
	else{
		if(rem >= minDis[maxindex] + sz[maxindex]) minDis[u] = totalMax % 2;
		else{
			minDis[u] = minDis[maxindex] + sz[maxindex] - rem;
		}
	}
	
	sz[u] += (s[u] == '1');
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	int n; cin >> n;
	cin >> s;
	for(int i = 1;i < n;i++){
		int a, b; cin >> a >> b; a--; b--;
		adj[a].push_back(b);
		adj[b].push_back(a);
	} 
	
	
	for(int i = 0;i < n;i++){
		dp(i, -1);
		if(minDis[i] == 0 && maxDis[i] % 2 == 0){ ///minDis = 0 implies all stones can be moved to i
			ans = min(ans, maxDis[i] / 2); ///total number of moves depends on the distance of all stones to the center
		}
	}
	
	if(ans >= 1e16) ans = -1;
	cout << ans;
}



Measured memory_bytes: 512
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<queue>
#include<stack>
#include<iomanip>
#include<sstream>

#define fast_io ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);

using namespace std;

#define deb(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) { cout << '\n';}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
    cout << '[' << *it << " = " << a << "]  ";
    err(++it, args...);
}

#define fcout cout<<fixed<<setprecision(15)
#define repp(i,j,k) for(int i=j; i<k; ++i)
#define rep(i,j) repp(i,0,j)
#define rrep(i,j,k) for(int i=j; i>=k; --i)
#define all(x) (x).begin(), (x).end()
#define sort(x) sort(x.begin(), x.end())
#define lb(x,val) lower_bound(x.begin(), x.end(), val)
#define ub(x,val) upper_bound(x.begin(), x.end(), val)
#define pb(x) emplace_back(x);

typedef long long int lli;
typedef pair<int,int> pii;
typedef pair<lli,lli> pll;
typedef vector<int> vi;
typedef vector<lli> vl;
typedef tuple<lli, lli> tii;
typedef tuple<lli, lli, lli> tiii;

//const lli M=998244353ll;
const lli M=1000000007ll;
const double D=1.0;


void solve(){
	int n,m; cin>>n>>m;
	int s=0,h;
	rep(i,m){
		cin>>h;
		s+=h;
	}
	if(s>n)cout<<"-1";
	else cout<<(n-s);
	
	

}

int main(){
	fast_io
	int tc=1;
	//cin>>tc;
	while(tc--){solve();}
	return 0;
}

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

int main()
{
  int n;
  vector<int> prime;
  {
    bool data[300000];
    memset(data,true,sizeof(data));
    for(int i=2;i<300000;i++)
      {
	if(data[i])
	  {
	    prime.push_back(i);
	    for(int j=i+i;j<300000;j+=i)
	      data[j]=false;
	  }
      }
  }
  for(;cin>>n,n;)
    {
      int ans=0;
      for(int i=0;;i++)
	{
	  if(prime[i]>2*n)
	    break;
	  if(prime[i]>n)
	    {
	      //      cout<<"add:"<<prime[i]<<endl;
	      ans++;	  
	    }
	}
      cout<<ans<<endl;
    }
}

Measured memory_bytes: 1640
#include <stdio.h>
#include <string.h>
typedef long long ll;

int main(){
  ll n, cnt=0, w=0, p=0;
  char c[200001]={0};
  scanf("%s",c);
  n=strlen(c);
    
  for(int i=0; i<n; i++){
      if( c[i]=='W' ){
        cnt += i-p;
        p++;
      }
  }
  printf("%lld\n",cnt);
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  ll a[n];
  rep(i, n) {
    cin >> a[i];
    a[i] -= i+1;
  }
  sort(a, a+n);
  ll ans = 0;
  rep(i, n) ans += abs(a[i]-a[n/2]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include "bits/stdc++.h"
using namespace std;
#define print(x) cout<<x<<endl;
#define rep(i,a,b) for(int i=a;i<b;i++)
#define REP(i,a) for(int i=0;i<a;i++)
#define debug int debug = 0;
#define RREP(i,a) for(int i=a-1;i>=0;i--)
#define rrep(i,a,b) for(int i=a-1;i>=b;i--)
#define printall(n,array) {for(int i=0;i<n;i++){cout<<array[i]<<" ";}cout<<endl;}
#define U() cout<<endl;
typedef long long ll;
typedef pair<int, int> Pi;
typedef pair<int, Pi> V;
typedef vector<ll> VE;
const ll mod = 1e9 + 7; //10^9+7

int main(){
    ll n;
    ll c[502] = {}, s[502] = {}, f[502] = {};
    cin >> n;
    REP(i, n - 1){
        cin >> c[i] >> s[i] >> f[i];
    }
    ll now = 0;
    REP(i, n - 1){
        now = 0;
        rep(j, i, n - 1){
            if(now < s[j])now = s[j];
            if(now % f[j]){now += f[j] - now % f[j];}
            now += c[j];
        }
        print(now);
    }
    print(0);
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);
#define ll long long
#define MOD 1000000007

int main(){
	fast;
	int n;
	cin>>n;
	int i=1000;
	while(1){
		if(n<=i){
			cout<<i-n;
			break;
		}
		i+=1000;
	}
	return 0;
}


Measured memory_bytes: 3648
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace ConsoleApplication1
{
    class Program
    {
        static readonly double EPS = 1E-10;

        static void Main(string[] args)
        {
            double[] input;

            input = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
            Point3D p = new Point3D(input[0], input[1], input[2]);

            input = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
            Point3D e = new Point3D(input[0], input[1], input[2]);

            Point3D[] b = new Point3D[3];

            for (int i = 0; i < 3; i++)
            {
                input = Array.ConvertAll(Console.ReadLine().Split(' '), double.Parse);
                b[i] = new Point3D(input[0], input[1], input[2]);
            }

            Point3D vb = (b[1] - b[0]).Cross(b[2] - b[0]);

            Point3D ub = p - b[0];
            Point3D eb = e - b[0];

            if (vb.Dot(ub) * vb.Dot(eb) > 0)
            {
                Console.WriteLine("HIT");
            }
            else
            {
                Point3D vr = p + (e - p) * Math.Abs(vb.Dot(ub)) / (Math.Abs(vb.Dot(ub)) + Math.Abs(vb.Dot(eb)));

                if ((b[1] - b[0]).Cross(vr - b[1]).Dot((b[2] - b[1]).Cross(vr - b[2])) > -EPS &&
                    (b[1] - b[0]).Cross(vr - b[1]).Dot((b[0] - b[2]).Cross(vr - b[0])) > -EPS)
                {
                    Console.WriteLine("MISS");
                }
                else
                {
                    Console.WriteLine("HIT");
                }
            }
        }
    }

    struct Point3D
    {
        internal double x, y, z;

        public Point3D(double x, double y, double z)
        {
            this.x = x;
            this.y = y;
            this.z = z;
        }

        public Point3D Cross(Point3D other)
        {
            Point3D ret;
            ret.x = y * other.z - z * other.y;
            ret.y = z * other.x - x * other.z;
            ret.z = x * other.y - y * other.x;
            return ret;
        }

        public double Dot(Point3D other)
        {
            return x * other.x + y * other.y + z * other.z;
        }

        public static Point3D operator +(Point3D a, Point3D b)
        {
            return new Point3D(a.x + b.x, a.y + b.y, a.z + b.z);
        }

        public static Point3D operator -(Point3D a, Point3D b)
        {
            return new Point3D(a.x - b.x, a.y - b.y, a.z - b.z);
        }

        public static Point3D operator *(Point3D p, double m)
        {
            return new Point3D(p.x * m, p.y * m, p.z * m);
        }

        public static Point3D operator /(Point3D p, double m)
        {
            return new Point3D(p.x / m, p.y / m, p.z / m);
        }
    }
}

Measured memory_bytes: 9344
from math import sqrt
def gcd(a,b):
	if a==0:
		return(b)
	return(gcd(b%a,a))
a,b=map(int,input().split())
g=gcd(a,b)
ans=1
if g%2==0:
	ans+=1
	while(g%2==0):
		g//=2
for divide in range(3,int(sqrt(g))+1,2):
	if g%divide==0:
		ans+=1
		while(g%divide==0):
			g//=divide
if g>2:
	ans+=1
print(ans)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
    a[i] -= i + 1;
  }
  sort(begin(a), end(a));
  int b = a[n / 2];
  long long s = 0;
  for (auto e : a) {
    s += abs(e - b);
  }
  cout << s << endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<vector>
using namespace std;

#define lld long long

int main() {
    lld N,K;
    cin >> N >> K;
    lld sum = 0;
    lld first = 0;
    lld end = 0;
    lld end_plus = N;
    for(int i=0;i<K-1;i++){
        first += i;
        end += end_plus;
        end_plus--;
    }
    for(int i=K;i<=N+1;i++){
        first += i-1;
        end += end_plus;
        end_plus--;
        sum += end-first+1;
    }
    cout << sum%(1000000007) << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <vector>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <cstring>
#include <deque>
#include <cstdio>
#include <cmath>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;

int main()
{
	int n;
	scanf("%d", &n);
	
	int hist[6] = {0};
	rep(i, n){
		double h;
		scanf("%lf", &h);
		
		const double harr[] = {165.0, 170.0, 175.0, 180.0, 185.0};
		int term = 0;
		rep(i, 5)
			term += harr[i] <= h;
		hist[term]++;
	}
	
	rep(i, 6){
		printf("%d:", i+1);
		rep(j, hist[i])
			putchar('*');
		puts("");
	}
	
	return 0;
}

Measured memory_bytes: 0
#include<stdio.h>
int a[50],b[50],c[50],d[50];
int max=0;
int n,m,q;
int h[10];
int check(int h[]){
  int sum=0;
for(int k=0;k<q;k++){
if(h[b[k]]-h[a[k]]==c[k])sum+=d[k];
}
 // printf("%d\n",sum);
             return sum;
            }
void gen(int s,int t){
if(s==n+1){///printf(" scoreは");
  int score=check(h);
           
  if(score>max)max=score;
           return ;
          }           
  
  for(int i=t;i<=m;i++){
	h[s]=i;
    //printf("%d番目 %d ",s,h[s]);
    gen(s+1,i);
  }
}
int main(void){
  scanf("%d%d%d",&n,&m,&q);
  
  for(int i=0;i<q;i++){
	scanf("%d%d%d%d",&a[i],&b[i],&c[i],&d[i]);
  }
  
  gen(1,1);
  printf("%d",max);
  return 0;
}

Measured memory_bytes: 1736
#include<bits/stdc++.h>
#define ALL(c) (c).begin(),(c).end()
#define EACH(i,c) for(auto i=(c).begin();i!=(c).end();++i)
using namespace std;
#define int long long

const long long MOD = 1000000007;

void test(int L, int R) {
    int a = 0, b = 0, c = 0;
    for(int x = L; x <= R; ++x) {
        for(int y = x; y <= R; ++y) {
            bool f = false, g = false;
            if ((x ^ y) == y % x) {
                ++a;
                f = true;
            }
            if (2 * x > y && (x & ~y) == 0) {
                ++b;
                g = true;
                cerr << x << "," << y << endl;
            }
            if (f != g) {
                ++c;
            }
        }
    }
    cerr << a << "," << b << "," << c << endl;
}

int dp[100][2][2][2];

void solve(long long L, long long R){
    int res = 0;

    int t = 62;
    dp[t][1][1][1] = 1;

    for(int i = t; i > 0; --i) {
        int ls = (L >> (i - 1)) & 1, rs = (R >> (i - 1)) & 1;

        // 0, 0, 0
        dp[i - 1][0][0][0] += dp[i][0][0][0] * 3 % MOD;
        dp[i - 1][0][0][0] %= MOD;

        // 0, 0, 1
        // This case doesn't exist

        // 1, 0, 0
        dp[i - 1][1][0][0] += dp[i][1][0][0] * 1 % MOD;
        dp[i - 1][1][0][0] %= MOD;

        // 1, 0, 1
        // This case doesn't exist
        if (rs) {
            // 1, 0, 0
            dp[i - 1][1][0][0] += dp[i][1][0][0] * 1 % MOD;
            dp[i - 1][1][0][0] %= MOD;

            dp[i - 1][0][0][0] += dp[i][1][0][0] * 1 % MOD;
            dp[i - 1][0][0][0] %= MOD;
        }

        // 0, 1, 0
        dp[i - 1][0][1][0] = ((2 - ls) * dp[i][0][1][0] % MOD + ls * dp[i][0][1][1]) % MOD + rs * (1 - ls) * dp[i][1][1][0];
        dp[i - 1][0][1][0] %= MOD;
        if (ls) {
            // 0, 1, 1
        } else {
            // 0, 1, 0

            dp[i - 1][0][0][0] += dp[i][0][1][0] * 1 % MOD;
            dp[i - 1][0][0][0] %= MOD;

            // 0, 1, 1

            dp[i - 1][0][0][0] += dp[i][0][1][1] * 1 % MOD;
            dp[i - 1][0][0][0] %= MOD;
        }


        dp[i - 1][0][1][1] = (1 - ls) * (dp[i][0][1][1] + dp[i][1][1][1] * rs) % MOD;

        if (rs || !ls) {
            // 1, 1, 0
            dp[i - 1][1][1][0] = (dp[i][1][1][0] + dp[i][1][1][1] * rs * ls) % MOD;
        }

        if (rs && !ls) {
            // 1, 1, 1
            dp[i - 1][1][0][0] += dp[i][1][1][1] * 1 % MOD;
            dp[i - 1][1][0][0] %= MOD;

            // 1, 1, 0
            dp[i - 1][1][0][0] += dp[i][1][1][0] * 1 % MOD;
            dp[i - 1][1][0][0] %= MOD;

        } else if (!rs && !ls) {
            // 1, 1, 1
            dp[i - 1][1][1][1] += dp[i][1][1][1] * 1 % MOD;
            dp[i - 1][1][1][1] %= MOD;

            // 1, 1, 0
        }
    }

    for(int i = 0; i < 2; ++i) for(int j = 0; j < 2; ++j)  {
                res = (res + dp[0][i][j][0]) % MOD;
            }

    cout << res << endl;
}

signed main(){
    long long L;
    scanf("%lld",&L);
    long long R;
    scanf("%lld",&R);
    solve(L, R);
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define pb push_back
#define REP(i, n) for (signed long long i = 0; i < (n); i++)
#define MOD 998244353
#define INF 98765431219876543
#define bitcnt(a) (ll) __builtin_popcount((a))
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<string, string> PS;

int main() {
  ll n, k, ret = 0;
  cin >> n >> k;
  if (k % 2 == 0) {
    ret += pow((n / (k / 2)) - n / k, 3);
  }
  ret += pow(n / k, 3);
  cout << ret << endl;
}

Measured memory_bytes: 640
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>


using namespace std;
#define rep(i,n) for (int i = 0; i < (int)(n); ++i)
#define reps(i,n) for (int i = 1; i <= (int)(n); ++i)
#define repd(i,n) for (int i = (int)(n - 1); i >= 0; --i)
#define repds(i,n) for (int i = (int)(n); i > 0; --i)
#define loop(i,x,n) for (int i = (int)(x); i < (n); ++i)
#define loops(i,x,n) for (int i = (int)(x); i <= (n); ++i)
#define loopd(i,x,n) for (int i = (int)(x); i > (n); --i)
#define loopds(i,x,n) for (int i = (int)(x); i >= (n); --i)
#define itrep(i,s) for (auto i = begin(s); i != end(s); ++i)
#define itrepd(i,s) for (auto i = --end(s); i != begin(s); --i)
#define all(f,x,...) [&](decltype(x)& whole) { return (f)(begin(whole), end(whole), ##__VA_ARGS__); }(x)
#define rall(f,x,...) [&](decltype(x)& whole) { return (f)(rbegin(whole), rend(whole), ##__VA_ARGS__); }(x)
using ll = long long;
using ld = long double;
constexpr ll inf = static_cast<ll>(1e17);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e17;
constexpr ll mod = static_cast<ll>(1e9 + 7);
std::ostream& endn(std::ostream& os) { return os.put(os.widen('\n')); }
template<class T> constexpr int sz(const T& a) { return (int)a.size(); }
template<class T, class ... Args> constexpr T mins(T& a, Args... args) { return a = min<T>({ a, args... }); }
template<class T, class... Args> constexpr T maxs(T& a, Args... args) { return a = max<T>({ a,args... }); }


double a, b, x;
void solve() {
    cin >> a >> b >> x;

    if (x <= a * a * b / 2) {
        auto ah = x * 2 / (a * b);
        cout << 90 - atan2(ah, b) * 180 / M_PI << endn;
    }
    else {
        auto nx = x - a * a * b / 2;
        auto bw = nx * 2 / (a * a);
        cout << 90 - atan2(a, b - bw) * 180 / M_PI << endn;
    }
}

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


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

void read() { cin >> N; }

int main() {
  read();

  vector<int> availables;
  availables.push_back(1);
  int n = 6;
  while (n <= N) {
    availables.push_back(n);
    n *= 6;
  }
  n = 9;
  while (n <= N) {
    availables.push_back(n);
    n *= 9;
  }

  vector<int> DP;
  DP.push_back(0);
  DP.push_back(1);

  for (int i = 2; i <= N; i++) {
    int cost = INT_MAX;
    for (int a : availables) {
      if (i - a >= 0) {
        cost = min(cost, DP.at(i - a) + 1);
      }
    }
    DP.push_back(cost);
  }

  cout << DP.back() << endl;
}


Measured memory_bytes: 892
#include <map>
#include <set>
#include <list>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <string>
#include <vector>
#include <complex>
#include <cstdlib>
#include <cstring>
#include <numeric>
#include <sstream>
#include <iostream>
#include <algorithm>
#include <functional>
  
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
  
using namespace std;
  
typedef    long long          ll;
typedef    unsigned long long ull;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      pii;
  
const int INF=1<<29;
const double EPS=1e-9;
  
const int dx[]={1,0,-1,0,1,1,-1,-1},dy[]={0,-1,0,1,1,-1,-1,1};


int main() {
  int K, T;
  cin >> K >> T;
  vector<int> A(T);
  for (int i = 0; i < T; i++) {
    cin >> A[i];
  }
  vector<int> dp(K + 1);
  dp[0] = 1;
  for (int i = 0; i < T; i++) {
    for(int j = K; j >= 0; j--) {
      if (j + A[i] <= K) dp[j + A[i]] |= dp[j];
    }
  }
  int mind = INF, x, y;
  for (int i = 0; i <= K; i++) {
    if (dp[i] && dp[K - i] && mind > (abs(K - i - i))) {
      mind = abs(K - i - i);
      x = i;
      y = K - i;
    }
  }

  if (abs(x - y) <= 1) {
    cout << 0 << endl;
  } else if (x < y) {
    cout << y - 1 - x << endl;
  } else {
    cout << x - 1 - y << endl;
  }
  return 0;
}

Measured memory_bytes: 256
main :: IO ()
main = do
  [n, yen] <- (map read . words) <$> getLine :: IO [Int]
  let candidates = [(x, y, n - x - y) | x <- [0..n], y <- [0..n - x],
                                        10000 * x + 5000 * y + 1000 * (n - x - y) == yen]
  if null candidates
    then putStrLn "-1 -1 -1"
    else do
      let (a, b, c) = head candidates
      putStrLn $ show a ++ " " ++ show b ++ " " ++ show c


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

int main(){
 double a,t; cin>>a>>t;
 double r; cin>>r;
 cout << setprecision(10)<<fixed;
 cout<<(r*t/a)<<endl;
 return 0;
}



Measured memory_bytes: 3272
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp>/
// #include <ext/pb_ds/tree_policy.hpp>

#define pb push_back
#define mp make_pair

#define mod 1000000007LL
#define IN freopen("input.txt","r",stdin)
#define OUT freopen("output.txt","w",stdout)
#define FOR(i,a,b) for(i=a ; i<=b ; i++)
#define DBG printf("Hi\n")
#define INF 2000000000000000000LL
#define i64 long long int
#define eps (1e-8)
#define xx first
#define yy second
#define ln 17
#define off 2
#define SZ(z) ((int)z.size())
#define sq(x) ((x)*(x))

#define FastIO ios_base::sync_with_stdio(false); cin.tie(NULL)

#define EPS 1e-7

// using namespace __gnu_pbds;
using namespace std ;

// typedef tree< i64, null_type, less<i64>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;

#define maxn 200005

set <int> st ;
int a[maxn] , sum[maxn] ;

int main()
{
    int n , k ;
    scanf("%d %d",&n,&k) ;

    for(int i=1 ; i<=n ; i++) scanf("%d",&a[i]) ;

    int ans = 1 ;

    for(int i=1 ; i<=k ; i++)
    {
        st.insert(a[i]) ;
    }

    for(int i=2 ; i<=n; i++)
    {
        if( a[i] > a[i-1] ) sum[i] = 1 ;
        sum[i] += sum[i-1] ;
    }

    int fl = 0 ;

    fl = ((sum[k]-sum[1])==(k-1)) ;

    for(int i=k+1 ; i<=n ; i++)
    {
        ans++ ;
        int fl1 = 0 , fl2 = 0 ;

        int First = *st.begin() ;
        fl1 = (First==a[i-k]) ;

        st.erase(a[i-k]) ;

        st.insert(a[i]) ;
        auto it = st.end() ;
        it-- ;
        fl2 = ((*it)==a[i]) ;

        ans -= ( (fl1&fl2)||( (sum[i]-sum[i-k+1] == (k-1))&&fl==1 ) ) ;

        fl |= ( (sum[i]-sum[i-k+1]) == (k-1) ) ;
    }

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

    return 0 ;
}


Measured memory_bytes: 11136
A,B,K = map(int,input().split())
if A == B:
    print(A)
else:
    if K > B - A:
        K = B - A
    tmp1 = list(range(A,A+K))
    tmp2 = list(range(B-K+1,B+1))
    ans = sorted(list(set(tmp1 + tmp2)))
    for i in ans:
        print(i)

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

const int NM=405;
const ll oo=1e18;

ll dp[NM][NM],s[NM];

int main()
{   int n;
    cin>>n;
    for(int i=1; i<=n; i++)
        for(int j=i; j<=n; j++)
            dp[i][j]=oo;
    for(int i=1; i<=n; i++)
    {   ll x;
        cin>>x;
        s[i]=s[i-1]+x;
    }
    for(int i=1; i<=n; i++)
    {   dp[i][i]=0;
        dp[i][i+1]=s[i+1]-s[i-1];
    }
    /// dp[i][j]=costul minim pentru [i,j]
    for(int k=2; k<n; k++)
        for(int i=1,j; i+k<=n; i++)
        {   j=i+k;
            for(int l=i; l<j; l++)
                dp[i][j]=min(dp[i][j],dp[i][l]+dp[l+1][j]);
            dp[i][j]+=s[j]-s[i-1];
        }
    cout<<dp[1][n];
    return 0;
}

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

using namespace std;

int main(void){
    int N;
    cin >> N;
    vector<long long> D(N);
    map<long long, long long> m;
    for(int i = 0; i < N; i++){
        cin >> D[i];
        m[D[i]]++;
    }
    if(D[0] > 0){
        cout << 0 << endl;
        return 0;
    }
    int n = 1;
    int d = 1;
    long long ans = 1;
    while(n < N){
        if(m[d] == 0){
            cout << 0 << endl;
            return 0;
        }
        for(int e = 0; e < m[d]; e++){
            ans *= m[d - 1];
            ans %= 998244353;
        }
        n += m[d];
        d++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 7296
import java.util.Scanner;

public class Main {
  public static int Q;
  public static int[] a;
  public static int[] b;
  public static int[] c;
  public static int[] d;
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in);
    int N = scan.nextInt();
    int M = scan.nextInt();
    Q = scan.nextInt();
    a = new int[Q];
    b = new int[Q];
    c = new int[Q];
    d = new int[Q];
    for(int i=0; i<Q; i++) {
      a[i] = scan.nextInt();
      b[i] = scan.nextInt();
      c[i] = scan.nextInt();
      d[i] = scan.nextInt();
    }
    scan.close();

    System.out.println(rec(0, N, M, new int[N]));
  }

  public static int rec(int now, int size, int M, int[] array) {
    if(now == size) {
      int sum = 0;
      for(int i=0; i<Q; i++) {
        if(array[b[i]-1] - array[a[i]-1] == c[i]) {
          sum += d[i];
        }
      }
      return sum;
    }

    int start;
    if(now == 0) {
      start = 1;
    }
    else {
      start = array[now-1];
    }
    int max = 0;
    for(int i=start; i<=M; i++) {
      array[now] = i;
      int sum = rec(now+1, size, M, array);
      if(max < sum) {
        max = sum;
      }
    }

    return max;
  }
}

Measured memory_bytes: 27692
#include "iostream"
#include <stdio.h>
#include <algorithm>
#include <stdlib.h>
#include <cstring>
#include <math.h>
#include <cctype>
#include <stack>
#include <vector>
#include <list>
#include <queue>
#include <set>
#include <map>
#include <bitset>
#include <iomanip>
using namespace std;
using ll=long long;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
#define MOD  1000000007


int main(int argc, char const *argv[]) {
  int a[10]={0,0,0,0,0};
  for(int i=0; i<3; i++){
    int b,c;
    std::cin >> b >> c;
    a[b]++; a[c]++;
  }
  sort(a,a+5);
  //std::cout << a[1] << a[2] << a[3] << a[4] << '\n';
  if(a[1]==1 && a[2]==1 && a[3]==2 && a[4]==2)std::cout << "YES" << '\n';
  else std::cout << "NO" << '\n';
  return 0;
}


Measured memory_bytes: 256
import math
import string
import collections
from collections import Counter
from collections import deque


def readints():
    return list(map(int, input().split()))


def nCr(n, r):
    return math.factorial(n)//(math.factorial(n-r)*math.factorial(r))


def has_duplicates2(seq):
    seen = []
    for item in seq:
        if not(item in seen):
            seen.append(item)
    return len(seq) != len(seen)


def divisor(n):
    divisor = []
    for i in range(1, n+1):
        if n % i == 0:
            divisor.append(i)
    return divisor


# coordinates
dx = [-1, -1, -1, 0, 0, 1, 1, 1]
dy = [-1, 0, 1, -1, 1, -1, 0, 1]
h1, m1, h2, m2, k = map(int, input().split())
h = (h2-h1)*60
m = (m2-m1)
sum = h+m
print(sum-k)


Measured memory_bytes: 68624
#include <numeric>
#include<iostream>
#include<set>
#include<queue>
#include<vector>
#include<map>
#include<stack>
#include <cstdio>
#include<algorithm>
#include <sstream>
#include<string>
#include<string.h>
#include <cmath>
#include <iomanip>
#include <string>
#include<list>
using namespace std;
#define int long long
#define inf 1000000007
#define rep(i,j,n) for(int i=j;i<n;i++)
typedef pair<int,int>  P;
double pi = 3.141592653589793;
//使うやつはここから下に置こうな
struct edge{int to,cost;};
vector<int> es[114];
signed main(){
    int n,a,b;
    cin>>n>>a>>b;
    if(a>b||(n==1&&a!=b)){
        cout<<0<<endl;
    }
    else{
        int min=a*(n-1)+b;
        int max=b*(n-1)+a;
        cout<<max-min+1<<endl;
    }
    return 0;
}

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

int n,w;
long long wei[110], v[110], memo[110][100010];

long long go(int ind,int val)
{
    if(val <= 0) return 0;
   if(memo[ind][val]!=-1) return memo[ind][val];
   if(ind == n) return 1e18+10;
   return memo[ind][val] = min(go(ind+1,val),wei[ind]+go(ind+1,val-v[ind]));
}

int main()
{
    cin>>n>>w;
    for(int i = 0;i<n;i++){
        cin>>wei[i]>>v[i];
    }

    int ans;
    memset(memo,-1,sizeof memo);

    for(int i = 1;i<= 1e5;i++){
        long long l = go(0,i);
        if(l<=w) ans = i;
    }

    cout<<ans<<endl;
}

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

int main(){
    int n , d;
    cin >> n >> d;
    if((d*2+1)*(n/(d*2+1))<n){
        cout << n/(d*2+1)+1 << endl;
    }else {
        cout << n/(d*2+1) << endl;
    }
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var kx = ReadInts();

            var list = new List<int>();
            var min = kx[1] - kx[0] + 1;
            var max = kx[1] + kx[0] - 1;

                Write(min);
            for (int i = min+1; i <= max; i++)
            {
                Write(" "+i);
            }
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        //最大公約数

        public static int Gcd(int a, int b)
        {
            if (a < b)
            {
                return Gcd(b, a);
            }
            while (b != 0)
            {
                var reminder = a % b;
                a = b;
                b = reminder;
            }
            return a;
        }

        //最小公倍数
        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

        //文字数を数える
        public static int CountChar(string s, char c)
        {
            return s.Length - s.Replace(c.ToString(), "").Length;
        }
    }
}


Measured memory_bytes: 11220
#include <iostream>
#include <string>
using namespace std;

int main(){

  char str[26]={}, ans;
  string S;
  getline(cin, S);

  for(int i=0; i<S.size(); i++){
    str[S[i]-'a']++;
  }

  for(int i=0; i<26; i++){
    if(!str[i]){
      ans = 'a'+i;
      cout << ans << endl;
      return 0;
    }
  }

  cout << "None" << endl;

  return 0;
}


Measured memory_bytes: 512
//use itertools::Itertools;
use std::cmp;
use std::collections::BTreeMap;
use std::collections::BTreeSet;
use std::collections::BinaryHeap;
use std::collections::HashMap;
use std::collections::HashSet;
use std::collections::VecDeque;
use std::io::Read;
use std::usize::MAX;

macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, [ $t:tt ]) => {{let len = read_value!($next, usize);(0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()}};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

fn solve() {
    input! {
        s: chars
    }

    let mut max = 0;
    let mut ans = 0;

    for i in 0..s.len() {
        if s[i] == 'R' {
            ans += 1;
        } else {
            ans = 0;
        }

        max = cmp::max(ans, max);
    }

    println!("{}", max);
}

fn main() {
    let thd = std::thread::Builder::new().stack_size(104_857_600);
    thd.spawn(|| solve()).unwrap().join().unwrap();

    /*
    // 入力を一括で読み込む場合
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut input = buf.split_whitespace();

    // inputに対しnext()で読み込んでいく
    let q: usize = input.next().unwrap().parse().unwrap();
    */
}

const LARGE_PRIME: u64 = 1_000_000_007;

// @〜でsnippet


Measured memory_bytes: 2172
#include<algorithm>
#include<cstdio>
#include<functional>
#include<iostream>
#include<cfloat>
#include<climits>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<map>
#include<queue>
#include<set>
#include<sstream>
#include<stack>
#include<string>
#include<time.h>
#include<vector>
using namespace std;
int main()
{
	int x,y,i,j,n;
	cin >> x >> y;
	for (i=0;i<=y/10000;i++)
	{
		for (j=0;j<=y/5000;j++)
		{
			n=x-i-j;
			if (n>=0 and (10000*i+5000*j+1000*n)==y)
			{
				cout << i << " " << j << " " << n << "\n";
				system ("pause");
				return 0;
			}
		}
	}
	cout << "-1 -1 -1" << endl;
	system("pause");
	return 0;
}


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

int a,b,c,d,e;

int main()
{
    ref(i,5) {
        cin>>a;
        if(a==0) cout<<i+1;
    }

    return 0;
}


Measured memory_bytes: 3628
a, b = map(lambda x: int(x), input().split())

x = a if a > b else b
y = a if a < b else b

def gcd(x,y):
    if x == y :
        return x
    if y == 0:
        return x
    elif x < y:
        return gcd(x,y%x)
    else:
        return gcd(y,x%y)

print(gcd(x,y))


Measured memory_bytes: 5600
#template
def inputlist(): return [int(k) for k in input().split()]
#template
N = int(input())
s = [0]*N
for i in range(N):
    s[i] = input()
from collections import Counter
c = Counter(s)
li = []
m = max(list(c.values()))
for i in list(c.keys()):
    if c[i] == m:
        li.append(i)
li.sort()
for i in range(len(li)):
    print(li[i])

Measured memory_bytes: 35560
#include <stdio.h>

int main(){
	char a[11],b[11],c[11];
	int al=-1,bl=-1,cl=-1;
	scanf("%s %s %s",&a,&b,&c);
	for(int i=0;i<11;i++){
		if(a[i]=='\0'&&al==-1){
			al=i-1;
		}
		if(b[i]=='\0'&&bl==-1){
			bl=i-1;
		}
		/*if(c[i]=='\0'&&cl==-1){
			cl=i-1;
		}*/
	}
	if(a[al]==b[0]&&b[bl]==c[0]){
		printf("YES");
	}
	else{
		printf("NO");
	}
	return 0;

}

Measured memory_bytes: 128