akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;

int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    int h,w,k;
    cin >> h >> w >> k;
    int x1,y1,x2,y2;
    cin >> x1 >> y1 >> x2 >> y2;
    x1--; y1--; x2--; y2--;
    vector<string> v(h);
    for(int o=0;o<h;o++) cin >> v[o];
    vector<set<array<int,2>>> r(h);
    vector<set<array<int,2>>> c(w);
    for(int o=0;o<h;o++)
    {
        for(int i=0;i<w;i++)
        {
            r[o].insert({i,(v[o][i]=='@')});
            c[i].insert({o,(v[o][i]=='@')});
        }
    }
    auto rm=[&](int a,int b)
    {
        r[a].erase({b,(v[a][b]=='@')});
        c[b].erase({a,(v[a][b]=='@')});
    };
    queue<array<int,2>> q;
    q.push({x1,y1});
    rm(x1,y1);
    vector<vector<int>> d(h,vector<int>(w,-1));
    d[x1][y1]=0;
    while(!q.empty())
    {
        auto [a,b]=q.front();
        q.pop();
        vector<array<int,2>> z;
        auto mv_left=[&]()
        {
            auto it=r[a].lower_bound({b,0});
            if(it==r[a].begin()) return;
            it--;
            while(b-(*it)[0]<=k&&(*it)[1]==0)
            {
                int x=(*it)[0];
                d[a][x]=d[a][b]+1;
                q.push({a,x});
                z.push_back({a,x});
                if(it==r[a].begin()) break;
                it--;
            }
        };
        auto mv_right=[&]()
        {
            auto it=r[a].lower_bound({b,0});
            if(it==r[a].end()) return;
            while((*it)[0]-b<=k&&(*it)[1]==0)
            {
                int x=(*it)[0];
                d[a][x]=d[a][b]+1;
                q.push({a,x});
                z.push_back({a,x});
                it++;
                if(it==r[a].end()) break;
            }
        };
        auto mv_up=[&]()
        {
            auto it=c[b].lower_bound({a,0});
            if(it==c[b].begin()) return;
            it--;
            while(a-(*it)[0]<=k&&(*it)[1]==0)
            {
                int x=(*it)[0];
                d[x][b]=d[a][b]+1;
                q.push({x,b});
                z.push_back({x,b});
                if(it==c[b].begin()) break;
                it--;
            }
        };
        auto mv_down=[&]()
        {
            auto it=c[b].lower_bound({a,0});
            if(it==c[b].end()) return;
            while((*it)[0]-a<=k&&(*it)[1]==0)
            {
                int x=(*it)[0];
                d[x][b]=d[a][b]+1;
                q.push({x,b});
                z.push_back({x,b});
                it++;
                if(it==c[b].end()) break;
            }
        };
        mv_left();
        mv_right();
        mv_up();
        mv_down();
        for(auto [x,y]:z) rm(x,y);
    }
    cout << d[x2][y2] << "\n";
    return 0;
}


Measured memory_bytes: 152560
#include <iostream>
#include <vector>

using namespace std;
typedef long long ll;

int main() {
    int k, n;
    cin >> k >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++)cin >> a[i];

    int ma = k + a[0] - a[n - 1];
    for (int i = 0; i < n - 1; i++) ma = max(ma, a[i + 1] - a[i]);
    cout << k - ma << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int l = sc.nextInt();
        
        int[][] A = new int[n][m];
        int[][] B = new int[m][l];
        long[][] C = new long[n][l];
        
        	for(int i=0;i<n;i++){
                for(int j=0;j<m;j++){
                    A[i][j] = sc.nextInt();
                }
            }
        	for(int i=0;i<m;i++){
                for(int j=0;j<l;j++){
                    B[i][j] = sc.nextInt();
                }
            }
        for(int i=0;i<n;i++){
            for(int j=0;j<l;j++){
                for(int k=0;k<m;k++){
                    C[i][j] += A[i][k] * B[k][j];
                }
            }
        }
        for(int i=0;i<n;i++){
            for(int j=0;j<l;j++){
                System.out.print(C[i][j]);
                if(j<l-1)
                    System.out.print(" ");
            }
            System.out.println();
        }
        sc.close();
    }
}


Measured memory_bytes: 53520
//@author yash2040
#include<bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define ll long long
//#define int long long
#define pb push_back
#define mod 1000000007
#define fast() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
int main()
{
	fast();
	int n;
	cin>>n;
	int arr[n-1];
	map<int,int> mp;
	for(int i=0;i<n-1;i++)
	{
		cin>>arr[i];
		mp[arr[i]]++;
	}
	for(int i=1;i<=n;i++)
	cout<<mp[i]<<endl;	
}




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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

#define INF (1e9)
#define PI (acos(-1))
#define EPS (1e-7)

ull gcd(ull a, ull b) { return b ? gcd(b, a % b) : a; }
ull lcm(ull a, ull b) { return a / gcd(a, b) * b; }

int main(){
    int h, n;
    cin >> h >> n;
    vi a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    vi dp(h+1, INF);
    dp[0] = 0;
    rep(i, n) rep(j, h+1) {
        if (dp[j] == INF) continue;
        dp[min(h,j+a[i])] = min(dp[min(h,j+a[i])], dp[j]+b[i]);
    }
    cout << dp[h] << endl;
    return 0;
}


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

#define REP(i, x) REPI(i, 0, x)
#define REPI(i, a, b) for (int i = int(a); i < int(b); ++i)
#define ALL(x) (x).begin(), (x).end()

typedef long long ll;
using namespace std;

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

  int N, M;
  cin >> N >> M;
  vector<vector<int>> G(N);

  int a, b;
  REP(i, M) {
    cin >> a >> b;
    --a;
    --b;
    G.at(a).push_back(b);
    G.at(b).push_back(a);
  }

  vector<int> d(N, 0);
  vector<bool> visit(N, false);
  queue<int> q;
  q.push(0);
  visit.at(0) = true;
  while (!q.empty()) {
    int v = q.front();
    q.pop();
    for (int const &nv : G.at(v)) {
      if (!visit.at(nv)) {
        q.push(nv);
        visit.at(nv) = true;
        d.at(nv) = d.at(v) + 1;
      }
    }
  }

  if (visit.at(N - 1) && d.at(N - 1) == 2) {
    cout << "POSSIBLE" << endl;
  } else {
    cout << "IMPOSSIBLE" << endl;
  }

  return 0;
}


Measured memory_bytes: 13168
using System;
using System.Collections.Generic;
class Program
{
	static void Main(string[] args)
	{
		int N = int.Parse(Console.ReadLine());
		string str = Console.ReadLine();
		string str2 = Console.ReadLine();
		string str3 = Console.ReadLine();
		long ans = 0;
		for(var i=0;i<N;i++){
			string s1 = str.Substring(i,1);
			string s2 = str2.Substring(i,1);
			string s3 = str3.Substring(i,1);
			if(s1 != s2 && s1 != s3 && s2 != s3){
				ans += 2;
			} else if(s1 == s2 && s1 == s3){
				ans += 0;
			} else {
				ans += 1;
			}
		}
		Console.WriteLine(ans);
	}
}

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

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

	long a[200000];
	long c[200001] = {};
	long v[200001] = {};
	
	for(int i = 0; i < N; i++){
		cin >> a[i];
		c[a[i]]++;
	}
	
	long s = 0;
	for(int i = 0; i <= N; i++){
		s += c[i] * (c[i] - 1) / 2;
	}
	
	for(int i = 0; i < N; i++){
		long x = c[a[i]];
		cout << s - x * (x - 1) / 2 + (x - 1) * (x - 2) / 2 << endl;
	}

	return 0;
}


Measured memory_bytes: 5760
# frozen_string_literal: true

n, m = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

# heap
class Heap
  def initialize(n, &func)
    @heap = Array.new(n) { 0 }
    @sz = 0
    @func = func
  end

  def size
    @sz
  end

  def empty?
    @sz.zero?
  end

  def push(x)
    i = @sz
    @sz += 1
    while i > 0
      p = (i - 1) / 2
      break if @func.call(@heap[p], x)

      @heap[i] = @heap[p]
      i = p
    end
    @heap[i] = x
  end

  def pop
    ret = @heap[0]
    @sz -= 1
    x = @heap[@sz]
    i = 0
    while i * 2 + 1 < @sz
      a = i * 2 + 1
      b = i * 2 + 2
      a = b if b < @sz && @func.call(@heap[b], @heap[a])

      break if !@func.call(@heap[a], x)

      @heap[i] = @heap[a]
      i = a
    end
    @heap[i] = x
    ret
  end

  def top
    @heap[0]
  end
end

heap = Heap.new(n){|x, y| x > y}

a.each do |e|
  heap.push e
end

m.times do
  heap.push(heap.pop / 2)
end
sum = 0
until heap.empty?
  sum += heap.pop
end
puts sum


Measured memory_bytes: 9356
solve :: [Int] -> Int
solve [x,k,d]
 | even exceededNumberOfWalking = abs (absX - numberOfWalking * d)
 | otherwise                    = abs (absX - (numberOfWalking + 1) * d)
  where absX = abs x
        numberOfWalking = min k (absX `div` d)
        exceededNumberOfWalking = k - numberOfWalking
main = print =<< solve . map read . words <$> getLine

Measured memory_bytes: 3948
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr long long INFL = numeric_limits<long long>::max() / 2;
constexpr int MOD = 1000000007;
using Graph = vector<vector<int>>;



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

    int N,X;
    cin >> N >> X;
    int L[N];
    rep(i,N) cin >> L[i];
    int ans=1;
    int D=0;
    rep(i,N){
        D+=L[i];
        if(D>X) break;
        else ans++;
    }
    cout << ans << endl;



}


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

int main() {
  int M; cin >>M;
  cout <<(24-M)+24 <<endl;
  return 0;
}


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

#define rep(i,n) for(int i=0;i<(n);i++)
#define all(c) (c).begin(),(c).end()

using namespace std;

const int INF=1e9;
typedef pair<int,int> P;
int n,x;
int d[20],c[20];
int f[200010];
const int offset=100005;

int bfs() {
  f[offset]=0;
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(0,offset));

  while(que.size()) {
    P p=que.top(); que.pop();
    int pos=p.second;
    int cost=p.first;
    if(cost>f[pos]) continue;
     // printf("%d %d\n",pos,cost);
    rep(i,n) {
      int t=pos+d[i];
      if(0<=t&&t<200010&&f[t]>cost+c[i]) {
        f[t]=cost+c[i];
        que.push(P(cost+c[i],t));
      }
      t-=d[i]*2;
      if(0<=t&&t<200010&&f[t]>cost+c[i]) {
        f[t]=cost+c[i];
        que.push(P(cost+c[i],t));
      }
    }
  }
  return -1;
}

int main()
{
  rep(i,200010) f[i]=INF;
  cin>>n>>x;
  rep(i,n) cin>>d[i]>>c[i];
  bfs();
  if(f[offset+x]==INF) f[offset+x]=-1;
  cout<<f[offset+x]<<endl;
}


Measured memory_bytes: 3876
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b,k,c=0;
	cin>>a>>b>>k;
	for(int i=a;i>=0;i--){
		if(a%i==0 && b%i==0){
			c++;
			if(c==k){
				cout<<i<<endl;
				return(0);
			}
		}
	}
  return(0);
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>
#define rep(i, n) for (i = 0; i < n; i++)
using namespace std;

int a[3];
int k;

signed main() {
	cin >> a[0] >> a[1] >> a[2] >> k;
	sort(a, a + 3);
	
	cout << a[2] * (1 << k) + a[0] + a[1] << endl;
	return 0;
}

Measured memory_bytes: 256
//#include "stdafx.h"
#include <iostream>
#include <set>
#include <queue>
#include <vector>
#include <algorithm>
#include <math.h>
#include <cmath>
#include <string>
#include <cstring>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
#include <tuple>
#include <numeric>
#include <assert.h>
#include <functional>
#include <unordered_map>

using namespace std;

/*-----------------------------------------------------------------------------
　定義
 -------------------------------------------------------------------------------*/
#define REP(i, n)				for (int (i) = 0 ; (i) < (int)(n) ; ++(i))
#define REPN(i, m, n)			for (int (i) = m ; (i) < (int)(n) ; ++(i))
#define INF						2e9
#define MOD						(1000 * 1000 * 1000 + 7)
#define Ceil(x, n)				(((((x))+((n)-1))/n))		/* Nの倍数に切り上げ割り算 */
#define CeilN(x, n)				(((((x))+((n)-1))/n)*n)		/* Nの倍数に切り上げ */
#define FloorN(x, n)			((x)-(x)%(n))				/* Nの倍数に切り下げ */
#define IsOdd(x)				(((x)&0x01UL) == 0x01UL)			
#define IsEven(x)				(!IsOdd((x)))						
#define	BitSetV(Val,Bit)		((Val) |= (Bit))			
#define	BitTstV(Val,Bit)		((Val) & (Bit))				
#define ArrayLength(x)			(sizeof( x ) / sizeof( x[ 0 ]))
#define	MAX_QWORD				((QWORD)0xFFFFFFFFFFFFFFFF)
#define M_PI					3.14159265358979323846
typedef long long				ll;
typedef unsigned long long int	QWORD;
typedef pair<ll, ll>			P;

/*-----------------------------------------------------------------------------
　処理
 -------------------------------------------------------------------------------*/
int main()
{
	int N;
	cin >> N;
	vector<int> a;
	REP(i, N) {
		int b;
		cin >> b;
		b--;
		a.emplace_back(b);
	}
	
	int next = 0;
	int ans = -1;
	REP(i, N) {
		if (1 == a[next]) {
			ans = i + 1;
			break;
		}
		next = a[next];
	}

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



Measured memory_bytes: 892
#include <bits/stdc++.h>
                using namespace std;
                typedef long long ll;
                #define INPUT()              freopen("input.txt", "r", stdin)
                #define OUTPUT()             freopen("output.txt", "w", stdout)
                #define F                    first
                #define S                    second
            //Templatefunctions
                template<typename T>T gcd(T x, T y) { if (y == 0)return x; else return gcd(y, x%y);}
                template <class T> T euclideanDistance(T x1 , T x2 , T y1 , T y2){return sqrt(( x1 - x2 ) * ( x1 - x2 ) + ( y1 - y2 ) * ( y1 - y2 ));}
                template <class T> T digitSum(T n){T sum = 0;while(n > 0)sum += n % 10,n /= 10;return sum;}
            //datatypes
                typedef long long int ll;
                typedef unsigned long long int ull;
                typedef long double ld;
            //constants
                const double INF = 1e+9;
                const double INFLL = 1e+18;
                const double EPS = 1e-9;
                const double PI = acos(-1);
                const int knightDir[8][2] = {{-2,-1},{-2,1},{-1,2},{1,2},{2,-1},{2,1},{-1,-2},{1,-2}};
                       //const int dx[]={0,0,0,1,1,1,-1,-1,-1};
                       //const int dy[]={-1,0,1,-1,0,1,-1,0,1};
                const int dx[] = {0 , 1 , 0 , -1};
                const int dy[] = {1 , 0 , -1 , 0};
            //helpers
                //#define MOD         1000000007LL
                #define MAX         1000005
                const ll MOD = 998244353;
                int arr[MAX];
            //Global Variables



                int main()
                {
                        int w , h , n;
                        scanf("%d%d%d",&w,&h,&n);
                        int x0 = 0,xn = w , y0 = 0, yn = h;
                        for(int i = 0 ; i < n ;i++)
                        {
                            int x , y , a;
                            scanf("%d%d%d",&x, &y ,&a);

                            if(a == 1)
                            {
                                if(x0 < x)x0 = x;
                            }else if(a == 2)
                            {
                                if(xn > x)xn = x;
                            }else if(a == 3)
                            {
                                if(y0 < y)y0 = y;
                            }else
                            {
                                if(yn > y)yn = y;
                            }
                        }
                        int a , b;
                        if(y0 > yn)b = 0;
                        else if(x0 > xn)a = 0;
                        else
                        {
                            a = (xn - x0);
                            b = (yn - y0);
                        }
                        printf("%d\n",a*b);
                }


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

typedef tuple<int, int, int> T;

const int MAX_N = 1010;

int n, m;

int par[MAX_N];
int ranks[MAX_N];
int ufSize;

void init(int n){
    ufSize = n;
    for(int i=0; i<n; i++){
        par[i] = i;
        ranks[i] = 0;
    }
}

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

bool same(int x, int y){
    return find(x) == find(y);
}

void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y) return;
    ufSize--;

    if(ranks[x] < ranks[y]){
        par[x] = y;
    }
    else{
        par[y] = x;
    }
    
    if(ranks[x] == ranks[y]){
        ranks[x]++;
    }
}

int kruskal(vector<T> &edge){
    sort(edge.begin(), edge.end());
    init(n);
    int cnt = 0;
    for(int i=0; i<edge.size(); i++){
        int cost, cv, nv;
        tie(cost, cv, nv) = edge[i];

        if(!same(cv, nv)){
            cnt++;

            if(cnt == n / 2){
                return cost;
            }

            unite(cv, nv);
        }
    }
}

int main(){
    while(1){
        cin>>n>>m;
        if(n == 0) return 0;

        vector<T> edge;
        for(int i=0; i<m; i++){
            int s, t, c; cin>>s>>t>>c;
            s--, t--;
            edge.emplace_back(c, s, t);
        }

        cout << kruskal(edge) << endl;
    }
}


Measured memory_bytes: 3152
N = int(input())
#S = [input() for i in range(N)]
S=[]
ans_dic={}
temp_ans = 1
ans = 0

for i in range(N):
    temp = sorted(list(input()))
    temp = ''.join(temp)
    #S.append(''.join(temp))
    #alpha_dic[temp[0]].append(i) 
    if temp in ans_dic:
        ans_dic[temp] += 1
    else:
        ans_dic[temp] = 1
    
for key,value in ans_dic.items():
    ans += value*(value-1)/2

print(round(ans))

Measured memory_bytes: 17804
n, a, b = map(int, input().split())
mod = 10**9 + 7

modinv_table_a = [-1] * (a+1)
modinv_table_a[1] = 1
for i in range(2, a+1):
    modinv_table_a[i] = (-modinv_table_a[mod % i] * (mod // i)) % mod

modinv_table_b = [-1] * (b+1)
modinv_table_b[1] = 1
for i in range(2, b+1):
    modinv_table_b[i] = (-modinv_table_b[mod % i] * (mod // i)) % mod

def binomial_coefficients_a(n, k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table_a[i + 1]
        ans %= mod
    return ans

def binomial_coefficients_b(n, k):
    ans = 1
    for i in range(k):
        ans *= n-i
        ans *= modinv_table_b[i + 1]
        ans %= mod
    return ans

res = (pow(2,n,mod)-binomial_coefficients_a(n,a)-binomial_coefficients_b(n,b)-1)%mod
print(res if res >= 0 else res+mod)

Measured memory_bytes: 76376
s=gets.chomp
l=s.length
flag=true

if s[0..(l-1)/2-1]!=s[(l+3)/2-1..l]
  flag = false
else
  t = s[0..(l-1)/2-1]
  tl=t.length
  tl.times do |i|
    flag = false if t[i]!=t[tl-i-1]
  end
end

puts flag ? "Yes":"No"


Measured memory_bytes: 1788
#include<iostream>
#include<vector>
#include<math.h>
#include<algorithm>
using namespace std;
int combi(int n, int k) {
	if(n<k)
	{
		return 0;
	}
  if (n == k || k == 0)
    return 1;
  else {
    return combi(n - 1, k - 1) + combi(n - 1, k);
  }
}
int main()
{
	int n=0;
	int m=0;
	int l=2;
	int ans=0;
	cin>>n>>m;
	ans+=combi(n,l);
	ans+=combi(m,l);
	cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;
const int N = 1e5 + 100;

int n, ans, a, b, c;
string s;

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n;
	while(n--) {
		cin >> s;
		for (int i = 0; i + 1 < s.length(); i++)
			if(s[i] == 'A' && s[i + 1] == 'B')
				ans++;
		
		if(s[0] == 'B' && s.back() == 'A')
			a++;
		else if(s[0] == 'B')
			b++;
		else if(s.back() == 'A')
			c++;
	}
	while(a && min(b, c) >= 2) {
		a--;
		b--;
		c--;
		ans += 2;
	}
	
	if(a == 0)
		ans += min(b, c);
	else {
		ans += a - 1 + (b > 0) + (c > 0);
	}
	cout << ans;
	return 0;
}

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

vector<intl> dp(1e5+3,-1);

intl fun(intl i,intl n,vector<intl>&ar){
    if(dp[i]!=-1){
        return dp[i];
    }
    if(i==n-1){
        dp[i]=0;
    }
    else if(i==n-2){
        dp[i+1]=fun(i+1,n,ar);
        dp[i]=abs(ar[i]-ar[i+1]);
        dp[i]+=dp[i+1];
    }
    else{
        dp[i+1]=fun(i+1,n,ar);
        dp[i+2]=fun(i+2,n,ar);
        intl x=dp[i+1]+abs(ar[i]-ar[i+1]);
        intl y=dp[i+2]+abs(ar[i]-ar[i+2]);
        dp[i]=min(x,y);
        // return min(dp[i+1],dp[i+2]);
    }
    return dp[i];
}
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    intl i,j,n;
    cin>>n;
    vector<intl> ar(n);
    for(i=0;i<n;i++){
        cin>>ar[i];
    }
    cout<<fun(0,n,ar)<<"\n";
}

Measured memory_bytes: 11096
def solve():
	posA, speedA = map(int, input().split())
	posB, speedB = map(int, input().split())
	T = int(input())
	if posA < posB:
		if posA + speedA * T >= posB + speedB * T:
			return "YES"
	else:
		if posA - speedA * T <= posB - speedB * T:
			return "YES"
	return "NO"

def main():
	print(solve())


if __name__ == '__main__':
	main()

Measured memory_bytes: 9184
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i<(n);i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
const ll INF = 1LL << 60;

int main() {
    
    ll N,D;
    cin >> N >> D;
    ll X[N];
    ll Y[N];
    rep(i,N){
        cin >> X[i] >> Y[i];
    }

    int count = 0;
    ll distance_2 = D*D;

    rep(i,N){
        ll distance_1 = X[i]*X[i]+Y[i]*Y[i];
        if(distance_1 <= distance_2){
            count++;
        } 
    }

    cout << count << endl;
    
    return 0;
}

Measured memory_bytes: 6756
#include <stdio.h>
#include <string.h>
 
int xmove[8001];
int ymove[8001];
int xmove_len=0, ymove_len=0;
 
char S[8001];
int goalx,goaly;
 
char dp[4001][16001];
 
//#define DEBUG
int abs(int a){ return (a < 0)? -a : a;}
char possible(int goal, int * move, int move_len){
#ifdef DEBUG
    puts("move:");
    for(int i = 0; i < move_len; i++) printf("%d,", move[i]);
    puts(""); printf("movelen=%d\n",move_len);
#endif
    if(move_len == 0){
        if(goal == 0) return 1;
        else          return 0;
    }
    
    int sum = 0;
    for(int i = 0; i < move_len ; i++) sum += move[i];
      
    if((sum+goal) % 2 == 1) return 0;

    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;
    dp[0][move[0]]=1;
    for(int i = 1; i < move_len; i++){
        for(int j = 0; j <= (sum+goal)/2 ; j++){
            dp[i][j] |= dp[i-1][j];
            if(j-move[i] >= 0) dp[i][j] |= dp[i-1][j-move[i]];    
        }
    }
#ifdef DEBUG
    for(int i = 0; i < move_len; i++){
        for(int j = 0; j <= (sum+goal)/2 && j <= 8000; j++){
           printf("%d,",dp[i][j]);
        }
       puts("");
    }
#endif
    return dp[move_len-1][(sum+goal)/2];
}
 
int main(void){
    scanf("%s",S);
    scanf("%d %d",&goalx,&goaly);
    /*
    goalx=-8000; goaly=0;
    for(int i = 0; i < 8000 ; i++){
        S[i]='F';
    }S[8000]=0;*/
 
    int xmove_ind = 0, ymove_ind = 0;
    char dir_x = 1;
    int count = 0;
    for(int i = 0; i <= strlen(S); i++){
        if(i == strlen(S) || S[i] == 'T' ){
            if(dir_x) xmove[xmove_ind++] = count;
            else      ymove[ymove_ind++] = count;
            
            dir_x = !dir_x;
            count = 0;
        }else{
            count++;
        }
    }
    xmove_len = xmove_ind;
    ymove_len = ymove_ind;
#ifdef DEBUG
    puts("xmove:");
    for(int i = 0; i < xmove_len; i++){
        printf("%d,",xmove[i]);
    }printf("xmovelen=%d\n",xmove_len);
    
    puts("ymove:");
    for(int i = 0; i < ymove_len; i++){
        printf("%d,",ymove[i]);
    }printf("ymovelen=%d\n",ymove_len);
#endif
    if(possible(abs(goaly),ymove,ymove_len)){
        if(xmove_len==1){
            if(goalx == xmove[0]) puts("Yes");
            else                  puts("No");
        }else{
            if(possible(abs(goalx-xmove[0]), &(xmove[1]), xmove_len-1)) puts("Yes");
            else                                                        puts("No");
        }
    }else{
        puts("No");
    }
    
    return 0;
}

Measured memory_bytes: 62720
using System;
//using System.Collections.Generic;
//using System.Linq;
//using Vector = CGL.Point;
//using Line = CGL.Segment;
//using Polygon = System.Collections.Generic.List<CGL.Point>;


namespace CGL
{
    class Program
    {
        static void Main(string[] args)
        {
            var q = scan[0];
            for (int i = 0; i < q; i++)
            {
                var t = scan;
                var p = new Point[4];
                for (int j = 0; j < 4; j++)
                {
                    p[j] = new Point(t[j * 2], t[j * 2 + 1]);
                }

                if ((p[1] - p[0]).Cross(p[3] - p[2]) == 0) Console.WriteLine(2);
                else if ((p[1] - p[0]).Dot(p[3] - p[2]) == 0) Console.WriteLine(1);
                else Console.WriteLine(0);
            }
        }

        static int[] scan { get { return Array.ConvertAll(Console.ReadLine().Split(), int.Parse); } }
    }
    
    struct Point
    {
        static readonly double EPS = 1E-10;
        double x, y;
        public Point(double x, double y)
        {
            this.x = x;
            this.y = y;
        }

        public static Point operator +(Point a, Point b) { return new Point(a.x + b.x, a.y + b.y); }
        public static Point operator -(Point a, Point b) { return new Point(a.x - b.x, a.y - b.y); }
        public static Point operator *(double k, Point a) { return new Point(k * a.x, k * a.y); }
        public static Point operator /(double k, Point a) { return new Point(a.x / k, a.y / k); }
        
        public double Abs { get { return Math.Sqrt(Norm); } }  
        public double Norm { get { return x * x + y * y; } }

        public static bool operator <(Point a, Point b) { return Math.Abs(a.x - b.x) > EPS ? a.x < b.x : a.y < b.y; }
        public static bool operator >(Point a, Point b) { return Math.Abs(a.x - b.x) > EPS ? a.x > b.x : a.y > b.y; }
        public static bool operator ==(Point a, Point b) { return Math.Abs(a.x - b.x) < EPS && Math.Abs(a.y - b.y) < EPS; }
        public static bool operator !=(Point a, Point b) { return Math.Abs(a.x - b.x) >= EPS || Math.Abs(a.y - b.y) >= EPS; }

        public override bool Equals(object p){  return Math.Abs(x - ((Point)p).x) < EPS && Math.Abs(y - ((Point)p).y) < EPS; }
        public override int GetHashCode(){ return x.GetHashCode() ^ y.GetHashCode(); }

        public double Dot(Point p) { return x * p.x + y * p.y; }
        public double Cross(Point p) { return x * p.y - y * p.x; }

    }
    /*struct Segment
    {
        Point p1, p2;
        public Segment(Point p1, Point p2)
        {
            this.p1 = p1;
            this.p2 = p2;
        }
    }
    struct Circle
    {
        Point c; double r;
        public Circle(Point c, double r)
        {
            this.c = c;
            this.r = r;
        }

    }*/
}

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

int main() {
    int n, h;

    cin >> n;

    int ans = 0;
    int max = 0;
    for (int i = 0; i < n; i++) {
        cin >> h;
        if (h >= max) {
            ans++;
            max = h;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
def p_j_dp():
    n = int(input())
    *a, = map(int, input().split())
    c1 = a.count(1)
    c2 = a.count(2)
    c3 = a.count(3)
    dp = [[[0] * (n + 1) for _ in range(n + 1)] for _ in range(n + 1)]
    for k in range(c3 + 1):
        for j in range(c3 + c2 + 1 - k):
            for i in range(n + 1 - k - j):
                if i + j + k == 0:
                    continue
                res = n
                if i > 0:
                    res += i * dp[i - 1][j][k]
                if j > 0:
                    res += j * dp[i + 1][j - 1][k]
                if k > 0:
                    res += k * dp[i][j + 1][k - 1]
                res /= i + j + k
                dp[i][j][k] = res
    print(dp[c1][c2][c3])
    
p_j_dp()

Measured memory_bytes: 604552
N = int(input())
A = list(map(int, input().split()))
def gcd(a, b):
  if a < b:
    c = a
    a = b
    b = c
  while a % b != 0:
    c = a % b
    a = b
    b = c
  return b
for i in range(N-1):
  A[i+1] = gcd(A[i] , A[i+1])
print(A[N-1])


Measured memory_bytes: 14252
#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, m;
	cin >> n >> m;
	int ans = n * (n - 1) / 2 + m * (m - 1) / 2;
	cout << ans << endl;
	return 0;
}

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

using namespace std;
const int N = 5555;

long long AB[N], BA[N * N], n;
long long Ga, Gb, Sa, Sb, Ba, Bb;

int main() {
	cin >> n;
	cin >> Ga >> Sa >> Ba;
	cin >> Gb >> Sb >> Bb;

	for (int i = 1; i <= n; i++) {
		AB[i] = i;
		if (i >= Ga)
			AB[i] = max(AB[i], AB[i - Ga] + Gb);
		if (i >= Sa)
			AB[i] = max(AB[i], AB[i - Sa] + Sb);
		if (i >= Ba)
			AB[i] = max(AB[i], AB[i - Ba] + Bb);
	}

	int profit = AB[n];
	for (int i = 1; i <= profit; i++) {
		BA[i] = i;
		if (i >= Gb)
			BA[i] = max(BA[i], BA[i - Gb] + Ga);
		if (i >= Sb)
			BA[i] = max(BA[i], BA[i - Sb] + Sa);
		if (i >= Bb)
			BA[i] = max(BA[i], BA[i - Bb] + Ba);
	}

	cout << BA[profit] << endl;	
}

// SamMHD :: July3-2019 :: Another Day in home...

Measured memory_bytes: 195584
t,_,s=open(0).read().partition('\n')
h,w=map(int,t.split())
a=h//2*(w//2)
c=h%2and w%2
b=(h*w-a*4-c)//2
for i in set(s)-{'\n'}:
  i=s.count(i)
  while i>3and a:
    i-=4
    a-=1
  while i>1and b:
    i-=2
    b-=1
  if i and c:
    i-=1
    c-=1
print('YNeos'[any(t for t in(a,b,c))::2])

Measured memory_bytes: 3064
<?php
$table = null;
$num = null;
$i = null;
$j = null;
$size = null;

function main() {
	global $num;
	while($n = trim(fgets(STDIN))) {
		init($n);
		while ($num <= $n * $n) {
			trynext();
		}
		printTable();
	}
}

function init($n) {
	global $table, $num, $i, $j, $size;
	initTable($table, $n);
	$size = $n;
	$num = 1;
	$i = (int)($n/2) + 1;
	$j = (int)($n/2);
}

function initTable(&$table, $n) {
	$row = array_fill(0, $n, 0);
	for ($i = 0; $i < $n; $i++) {
		$table[$i] = $row;
	}
}

function trynext() {
	global $table, $num, $i, $j, $size;

	// はみ出る場合
	if ($j >= $size) {
		$j = 0;
	}
	if ($j < 0) {
		$j = $size - 1;
	}
	if ($i >= $size) {
		$i = 0;
	}

	if ($table[$i][$j] > 0) {
		$i++;
		$j--;
		trynext();
	} else {
		// 格納成功
		$table[$i][$j] = $num;
		// 次の基本位置
		$i++;
		$j++;
		$num++;
		return;
	}
}

function printTable() {
	global $table, $size;
	for ($i = 0; $i < $size; $i++) {
		$row = "";
		for ($j = 0; $j < $size; $j++) {
			$row .= sprintf("%4d", $table[$i][$j]);
		}
		echo rtrim($row) . "\n";
	}
}

main();

Measured memory_bytes: 6696
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
#define pb(x)           push_back(x)
#define mkp(x,y)        make_pair(x,y)
#define L               length()
#define int             long long
#define bs              binary_search
#define mod             1e9+7
#define IOS             ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define all(v)          v.begin(),v.end()
#define mem0(a)         memset(a,0,sizeof(a))
#define mem1(a)         memset(a,-1,sizeof(a))
#define F               first
#define S               second
#define pii             pair<int,int>
#define vi              vector<int>
#define vs              size()
#define gcd(a,b)        __ gcd(a,b)
#define endl            '\n'
#define atoi            stoi
#define elasped_time    1.0 * clock() / CLOCKS_PER_SEC
#define si              set <int>
#define vpii            vector < pair <int,int> >
#define memf(a)         memset(a,false,sizeof(a))
#define memt(a)         memset(a,true,sizeof(a))
#define xxx             998244353
#define pi              3.141592653589
#define ninf            INT_MIN
#define inf             INT_MAX
int max(int a,int b){if(a>b){return a;}else{return b;}}
int min(int a,int b){if(a<b){return a;}else{return b;}}
int sz(vi v){if(v.empty()){return 0;}else{return v.vs;}}
int sz(si v){if(v.empty()){return 0;}else{return v.vs;}}
int sz(vpii v){if(v.empty()){return 0;}else{return v.vs;}}
int power(int b,int e)
{
    if(e==0)
    return 1;
    if(e%2)
    return ((b*power((b)*(b),(e-1)/2)));
    else
    return power((b)*(b),e/2);
}
int modpower(int b,int e,int q)
{
    int MOD=q;
    if(e==0)
    return 1;
    if(e%2)
    return ((b%MOD)*modpower((b%MOD)*(b%MOD),(e-1)/2,q))%MOD;
    else
    return modpower((b%MOD)*(b%MOD),e/2,q)%MOD;
}
void dpv(vi v)
{
    for(int i=0;i<v.vs;i++)
    {
        cout<<v[i]<<" ";
    }
    cout<<endl;
}
void dpv(vpii v)
{
    for(int i=0;i<v.vs;i++)
    {
        cout<<v[i].F<<" "<<v[i].S<<endl;
    }
}
void dpv(set <int> v)
{
    for(auto i:v)
    {
        cout<<i<<" ";
    }
    cout<<endl;
}
//////////////////////**TREE MOVES STARTS**//////////////////////////////
///// **TREE MOVES ENDS**////////////////////////////

////*SOLUTION TO THE QUESTION STARTS HERE*///////
void oblivious()
{
    int n;
    cin>>n;
    int a[n+1],b[n+1],c[n+1];
    for(int i=1;i<=n;i++)
    {
        cin>>a[i]>>b[i]>>c[i];
    }
    int dp[n+1][3]; //maximum amount of points gained
    mem0(dp);
    dp[1][0]=a[1];
    dp[1][1]=b[1];
    dp[1][2]=c[1];
    for(int i=2;i<=n;i++)
    {
        dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
        dp[i][1]=b[i]+max(dp[i-1][2],dp[i-1][0]);
        dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]))<<endl;
}
signed main()
{
    IOS;
    /*#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif*/
    int t=1;
    //cin>>t;
    while(t--)
    {
        oblivious();
    }
    return 0;
}
//Md Zuhair

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

#define trav(a, A) for (auto & a : A)
#define f first
#define s second

typedef long long ll;

const ll MOD = 1e+9+7;
const ll INFLL = 0x3f3f3f3f3f3f3f3f;
const int INF = 0x3f3f3f3f;
const ll MAXN = 1e+5+7;

int main ()
{
	ios_base::sync_with_stdio (0);
	cin.tie (0);
	ll i, j, n, d, ans = 0;
	cin >> n >> d;
	for (i = 0; i < n; ++i)
	{
		ll x, y;
		cin >> x >> y;
		if (hypot (x, y) <= d) ++ans;
	}
	cout << ans << '\n';

	return 0;
}



Measured memory_bytes: 3664
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
template <class T> void chmin(T &a, const T &b) noexcept { if (b < a) a = b; }
template <class T> void chmax(T &a, const T &b) noexcept { if (a < b) a = b; }
void debug_out() { cout << "\n"; }
template <class T, class... Args>
void debug_out(const T &x, const Args &... args) { cout << x << " "; debug_out(args...);}
#ifdef _DEBUG
  #define debug(...) debug_out(__VA_ARGS__)
#else
  #define debug(...) 
#endif

const ll mod = 1000000007;

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  int d;
  string str;
  cin >> str >> d;
  int n = str.size();
  vector<vector< vector<ll> > > dp(n+5, vector<vector<ll> >(2, vector<ll>(d+5, 0)));
  dp[0][0][0] = 1;
  rep(i,n) {
    rep(j,d) {
      rep(k,10) { //i桁目がN未満 -> i+1がN未満
        dp[i+1][1][(j+k) % d] += dp[i][1][j];
        dp[i+1][1][(j+k) % d] %= mod;
      }
      int x = str[i]-'0';
      rep(k,x) { //i桁目がNと同じ -> i+1がN未満
        dp[i+1][1][(j+k) % d] += dp[i][0][j];
        dp[i+1][1][(j+k) % d] %= mod;
      }
      //i桁目がNと同じ -> i+1がNと同じ
      dp[i+1][0][(j+x) % d] += dp[i][0][j];
      dp[i+1][0][(j+x) % d] %= mod;
    }
  }
  cout << (dp[n][1][0] + dp[n][0][0] - 1 + mod) % mod << endl;
  return 0;
}

Measured memory_bytes: 17664
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define repp(i, m, n) for(int i = m; i < n; i++)
#define reps(i, n) for(int i = 1; i <= n; i++)
const int    INF = 100000000;
const double EPS = 1e-10;
const int    MOD = 1000000007;
using namespace std;
typedef long long ll;
typedef pair<int, int> pai;
typedef pair<ll,ll> pal;

ll kaijo[230000];

ll power(ll x, ll y)
{
	if(y==0) return 1;
	else if(y==1) return x%MOD;
	else if(y%2==0) return (power(x, y/2)*power(x, y/2))%MOD;
	else return (x*((power(x, y/2)*power(x, y/2))%MOD))%MOD;
}

ll waru(ll x, ll y)
{
	return (x*power(y, MOD-2))%MOD;
}

ll comb(ll x, ll y)
{
	return waru(waru(kaijo[(int)x], kaijo[(int)y]), kaijo[(int)(x-y)]);
}

int main()
{
	int n, m, k;
	cin >> n >> m >> k;
	ll migi[10010], ue[10010];
	kaijo[0]=1;
	reps(i, n+m+2*k) kaijo[i]=(kaijo[i-1]*i)%MOD;
	migi[0]=1;
	ue[0]=1;
	reps(i, k)
	{
		migi[i]=(comb((ll)(n+2*i), (ll)i)+MOD-comb((ll)(n+2*i), (ll)(i-1)))%MOD;
		ue[i]=(comb((ll)(m+2*i), (ll)i)+MOD-comb((ll)(m+2*i), (ll)(i-1)))%MOD;
	}
	ll ans=0;
	rep(i, k+1)
	{
		ans=(ans+(((migi[i]*ue[k-i])%MOD)*comb((ll)(n+m+2*k), (ll)(n+2*i)))%MOD)%MOD;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 4840
#include <stdio.h>
int main (void)
{
    int i,j,n,ans;
    scanf("%d",&n);
    int h[n];
    for (i = 0; i < n; i++) {
        scanf("%d",&h[i]);
    }
    //入力完了//
    for (i = 0; i < n; i++) {
        for (j = 0; j < i; j ++)    {
            if(h[j] > h[i]) break;
        }
        if(j == i)  ans ++;
    }
    printf("%d\n",ans);
}

Measured memory_bytes: 128
s = input();
first = s[0:2]
second = s[2:4]

first = int(first)
second = int(second)

if 0 < first and first < 13:
    if 0 < second and second < 13:
        print("AMBIGUOUS")
    elif (13 <= second):
        print("MMYY")
    else:
        print("MMYY")

elif 13 <= first:
    if 0 < second and second < 13:
        print("YYMM")
    elif (13 <= second):
        print("NA")
    else:
        print("NA")

else:
    if 0 < second and second < 13:
        print("YYMM")
    elif 13 <= second:
        print("NA")
    else:
        print("NA")

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

int main() {
    int N; cin >> N;
    int light = 1;
    int arr[N];
    int ans = 0;
    for (int i = 0; i < N; i++) {
        cin >> arr[i];
    }
    for (int i = 0; i < N; i++) {
        if (light == 2) {
            cout << ans << endl;
            return 0;
        }
        light = arr[light - 1];
        ans++;
    }
    cout << -1 << endl;
    return 0;
}


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


int main(void){
    // Here your code !
    
    long a=0;
    long b=0;
    long ans = 0;
    string op;
    
    cin>>a;
    cin>>op;
    cin>>b;
    //scanf("%ld%c%ld",&a,&op,&b);
    if("+" == op){
        ans = a + b;
    }else{
        ans = a - b;
    }
    printf("%ld",ans);
    
    
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
#define debug(a) cout<<a<<endl
#define clr(a) memset(a,0,sizeof(a))
#define clrne(a) memset(a,-1,sizeof(a))
#define clrinf(a) memset(a,0x3f,sizeof(a))
#define clrneinf(a) memset(a,0xc0,sizeof(a))
#define pb(a) push_back(a)
#define maxn 10001
#define mod 1000000007
#define eps 1e-9
#define inf 0x7fffffff
int a[100010];
int n;
bool check(int mid)
{
    ll now = 0;
    for (int i =n-1 ;i>=mid;i--)
        now+=a[i];
    for (int i = mid-1;i>=0;i--)
    {
        if (now*2<a[i]) return 0;
        now+=a[i];
    }
    return 1;
}
int main()
{
//  freopen("in.txt","r",stdin);
//  freopen("out.txt","w",stdout);
    scanf("%d",&n);
    for (int i  =0;i<n;i++)
    {
        scanf("%d",&a[i]);
    }
    sort(a,a+n);
    reverse(a,a+n);
    int l = 0;
    int  r = n;
    while (r-l>1)
    {
        int mid = (l+r)>>1;
        if (check(mid)) l = mid;
        else r = mid;
    }
    printf("%d\n",l+1);
    return 0;
}


Measured memory_bytes: 640
// author-Shivam gupta

#include <bits/stdc++.h>


using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))

#define FOREACH(it, l) for (auto it = l.begin(); it != l.end(); it++)

#define IN(A, B, C) assert( B <= A && A <= C)

#define MP make_pair
#define FOR(i,a) for(int i=0;i<a;i++)

#define FOR1(i,j,a) for(int i=j;i<a;i++)

#define EB emplace_back

#define INF (int)1e9

#define EPS 1e-9

#define PI 3.1415926535897932384626433832795

#define MOD 1000000007

#define read(type) readInt<type>()
#define max1 100001
#define out(x) cout<<x<<'\n'
#define out1(x) cout<<x<<" "
#define END cout<<'\n'
#define int long long
void fast(){
ios::sync_with_stdio(0);
cin.tie(0);
cout.tie(0);
}
signed main(){

	  int n;
	  cin>>n;
	  cout<<(1000-n%1000)%1000;
}


Measured memory_bytes: 3672
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
using namespace std;
typedef long long int llint;
typedef vector<int> vint;
typedef vector<llint> vllint;
typedef vector<pair<int, int>> vpint;
typedef vector<pair<llint, llint>> vpllint;
#define rep(i,n) for(int i=0;i<n;i++)
#define yes(ans) if(ans)cout<<"yes"<<endl;else cout<<"no"<<endl;
#define Yes(ans) if(ans)cout<<"Yes"<<endl;else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl;else cout<<"NO"<<endl;
#define POSSIBLE(ans) if(ans)cout<<"POSSIBLE"<<endl;else cout<<"IMPOSSIBLE"<<endl;

class UnionFind {
public:
	//親の番号を格納する。親だった場合は-(その集合のサイズ)
	vector<int> Parent;

	//作るときはParentの値を全て-1にする
	//こうすると全てバラバラになる
	UnionFind(int N) {
		Parent = vector<int>(N, -1);
	}

	//Aがどのグループに属しているか調べる
	int root(int A) {
		if (Parent[A] < 0) return A;
		return Parent[A] = root(Parent[A]);
	}

	//自分のいるグループの頂点数を調べる
	int size(int A) {
		return -Parent[root(A)];//親をとってきたい
	}

	//AとBをくっ付ける
	bool connect(int A, int B) {
		//AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
		A = root(A);
		B = root(B);
		if (A == B) {
			//すでにくっついてるからくっ付けない
			return false;
		}

		//大きい方(A)に小さいほう(B)をくっ付けたい
		//大小が逆だったらひっくり返しちゃう。
		if (size(A) < size(B)) swap(A, B);

		//Aのサイズを更新する
		Parent[A] += Parent[B];
		//Bの親をAに変更する
		Parent[B] = A;

		return true;
	}
};

//aとbの最大公約数を求めるよ
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

// 返り値: a と b の最大公約数
// ax + by = gcd(a, b) を満たす (x, y) が格納される
long long extGCD(long long a, long long b, long long &x, long long &y) {
	if (b == 0) {
		x = 1;
		y = 0;
		return a;
	}
	long long d = extGCD(b, a%b, y, x);
	y -= a / b * x;
	return d;
}

bool check(int a, int b) {
	return a > b;
}

int main() {
	int n;
	cin >> n;
	if (n % 2 == 0) {
		cout << n * n / 4 << endl;
	}
	else {
		cout<< n/2*(n/2 + 1) << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using str = string;
using ll = long long;
#define REP(i,n) for(int i=0; i<int(n); i++)
#define RREP(i,n) for(int i=int(n)-1; i>=0; i--)
#define FOR(i,f,t) for(int i=int(f); i<=int(t); i++)
#define RFOR(i,f,t) for(int i=int(f); i>=int(t); i--)
#define ALL(vec) (vec).begin(),(vec).end()
#define ASORT(vec) sort(ALL(vec))
#define DSORT(vec) sort(ALL(vec), greater<int>());
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define YES(ans) if(ans) cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define Yes(ans) if(ans) cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define yes(ans) if(ans) cout<<"yes"<<endl; else cout<<"no"<<endl;
#define INF 1000000000000
#define NOD 1000000007
#define PI 3.141592653589793238462643

int main() {
    char a, b, c;
    cin >> a >> b >> c;
    Yes(a!=b || b!=c);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  	string S;
  	cin >> S;
  	list<char> lis;
  	for(int i=0;i<S.size();i++){
      lis.push_back(S[i]);
    }
    int q,t,u;
  	char a;
  	cin >> q;
  	char Ward = 'f';
  	for(int i=0;i<q;i++){
    	cin >> t;
      	if(t==1){
          if(Ward == 'f'){
            Ward = 'b';
          }
          else if(Ward=='b'){
            Ward = 'f';
          }
        }
      	else{
        	cin >> u >>a;
          	if((Ward=='f' &&u==1) || (Ward=='b'&&u==2)){
              	lis.push_front(a);
            }
          	else{
            	lis.push_back(a);
            }
        }
    }
    if(Ward == 'f'){
    	while(!lis.empty()){
       		cout<<lis.front();
          	lis.pop_front();
        }
    }
  	else{
      	while(!lis.empty()){
          	cout << lis.back();
          	lis.pop_back();
        }
    }
  	
  	cout<<endl;
  	
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

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

int main()
{
    cout << fixed << setprecision(15);
    ll X, Y, Z, K;
    cin >> X >> Y >> Z >> K;

    vector<ll> A(X);
    vector<ll> B(Y);
    vector<ll> C(Z);
    
    REP(i, X){
        cin >> A[i];
    }
    REP(i, Y){
        cin >> B[i];
    }
    REP(i, Z){
        cin >> C[i];
    }

    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end(), greater<ll>());
    sort(C.begin(), C.end(), greater<ll>());
    vector<ll> ans;
    REP(i, X){
        REP(j, Y){
            REP(k, Z){
                if(i*j*k > K) continue;
                else{
                    ans.push_back(A[i]+B[j]+C[k]);
                }
            }
        }
    } 
    sort(ans.begin(),ans.end(), greater<ll>());

    ll count = 0;
    for(auto v: ans){
        if(count == K) break;
        cout << v << endl;
        count++;
    }
    return 0;
}

Measured memory_bytes: 35176
# 2020/05/06
# AtCoder Grand Contest 009 - A

# Input
n = int(input())

cnt = 0
ablist = list()
for i in range(n):
    ab = list(map(int,input().split()))
    ablist.append(ab)

# Calc from Last element
for i in range(n-1, -1, -1):
    rem = (ablist[i][0] + cnt) % ablist[i][1]
    if rem > 0:
        addval = ablist[i][1] - rem
        cnt = cnt + addval

# Output
print(cnt)


Measured memory_bytes: 27380
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-9;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i > 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()

int main() {
    int x, a;
    cin >> x >> a;
    if(x < a){
        cout << 0 << endl;
    }
    else{
        cout << 10 << endl;
    }
    
    return 0;
}


Measured memory_bytes: 256