akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cassert>
#include <vector>
#include <iostream>
#include <cstring>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
using namespace std;

typedef long long LL;
#define X first
#define Y second
typedef pair<LL, LL> pii;
const int N = 1e6 + 100;

int dp[N][2];
char s[N];
int main() {
	int ans = 0;
	scanf("%s", s + 1);
	int len = strlen(s + 1);
	s[0] = '0';
	bool flag = false;
	dp[len + 1][1] = 0x3f3f3f3f;
	for(int i = len; i >= 0; i --) {
		dp[i][0] = min(s[i] - '0' + dp[i + 1][0], s[i] + 1 - '0' + dp[i + 1][1]);
		dp[i][1] = min(10 - s[i] + '0' + dp[i + 1][0], 10 + '0' - s[i] - 1 + dp[i + 1][1]);
	}
	printf("%d\n", min(dp[0][0], dp[0][1]));

}


Measured memory_bytes: 9088
import Debug.Trace


count :: Int -> Int
count x = length (filter (\a -> mod x a == 0) [1..x])

check :: Int -> Bool
check x
    | even x = False
    | otherwise = 
        let val = count x == 8 in
        val

solve :: Int -> Int
solve a = length (filter id (map check [1..a]))

main :: IO ()
main = do
    a <- read <$> getLine
    print (solve a)



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

using namespace std;

typedef pair<int, int> II;
typedef vector<II> VII;
typedef vector<int> VI;
typedef vector<VI> VVI;

typedef long long int LL;

#define PB push_back
#define MP make_pair
#define F first
#define S second
#define SZ(a) (int)(a.size())
#define ALL(a) a.begin(), a.end()
#define SET(a, b) memset(a, b, sizeof(a))
#define si(n) scanf("%d", &n)
#define dout(n) printf("%d\n", n)
#define sll(n) scanf("%lld", &n)
#define lldout(n) printf("%lld\n", n)

#define TRACE

#ifdef TRACE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char *name, Arg1 &&arg1) {
  cerr << name << " : " << arg1 << std::endl;
}
template <typename Arg1, typename... Args>
void __f(const char *names, Arg1 &&arg1, Args &&... args) {
  const char *comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << " : " << arg1 << " | ";
  __f(comma + 1, args...);
}
#else
#define trace(...)
#endif

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

#define endl '\n'
bool x[26];
int main() {
  fast_io;
  string s;
  cin >> s;
  for (auto c : s) x[c - 'a'] = true;
  int i = 0;
  for (i = 0; i < 26; i++)
    if (!x[i]) break;
  if (i == 26) return 0 * puts("None");
  cout << (char)(i + 'a') << endl;
  return 0;
}


Measured memory_bytes: 512
import itertools
import math

N = int(input())
X = []
Y = []
for _ in range(N):
    x,y = map(int,input().split())
    X.append(x); Y.append(y)

num = [i for i in range(N)]
distance_list = []
for perm in itertools.permutations(num):
    prev = None
    distance = 0
    for v in perm:
        if prev is None:
            prev = v
        else:
            distance += math.sqrt((X[prev] - X[v]) ** 2 + (Y[prev] - Y[v]) ** 2)
    distance_list.append(distance)

print(sum(distance_list) / len(distance_list))


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

typedef long long ll;
typedef  unsigned long long ull;
const ll mod = 1e9 + 7;
const int N=1000000000;
const int M=2000;

void Run()
{
     ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
}

int main()
{
    Run();
    int n;
    cin>>n;
    cout<<(n+pow(n,2)+pow(n,3));
}


Measured memory_bytes: 4164
#include<stdio.h>

#define MAX 1001
#define INF 1000000
#define white 0
#define gra 1
#define black 2

int n,u,M[MAX][MAX];

void kei(void);

int main(){
  int i,j,k,v,c;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      M[i][j] = INF;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d %d",&u,&k);
    for(j=0;j<k;j++){
      scanf("%d %d",&v,&c);
      M[u][v] = c;
    }
  }

  kei();

  return 0;
}

void kei(){
  int i,min,d[MAX],color[MAX] = {white};

  for(i=0;i<n;i++)d[i] = INF;

  d[0] = 0;
  color[0] = gra;

  while(1){
    min = INF;
    u = -1;
    for(i=0;i<n;i++){
      if(min > d[i] && color[i] != black){
		u = i;
		min = d[i];
      }
    }
	if(u == -1)break;
    color[u] = black;
    for(i=0;i<n;i++){
      if(color[i] != black && M[u][i] != INF){
		if(d[i] > d[u] + M[u][i]){
	  	d[i] = d[u] + M[u][i];
	  	color[i] = gra;
		}
      }
  	}
  }
  for(i=0;i<n;i++){
   	if(d[i] == INF)printf("%d -1\n",i);
   	else printf("%d %d\n",i,d[i]);
  }
}


Measured memory_bytes: 2196
#include <stdio.h>
#include <string.h>

int main(void)
{
  int N,i;
  double sum=0;
  double BTC = 380000.0;
  double x[11];
  char u[11];
  
  
  scanf("%d",&N);
  
  for(i=0;i<=N;i++)
  {
   scanf("%lf", &x[i]); 
   scanf("%s", &u[i]);
  }
  
  for(i=0;i<N;i++)
  {
    if(u[i]=='J')
      sum += x[i];
    
    if(u[i]=='B')
      sum += x[i] * BTC;
    
  }
  
  printf("%lf", sum);
   
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <map>
using namespace std;
using ll = long long;

int main()
{
  int N, P;
  cin >> N >> P;
  string S;
  cin >> S;
  
  ll ans = 0;
  if (P == 2 || P == 5)
  {
    for (int i = 0; i < N; ++i)
    {
      int c = S[i] - '0';
      if (c % P == 0) ans += i + 1;
    }
  }
  else
  {
    int a = 0;
    map<int,int> buk;
    int t10 = 1;
    for (int i = N - 1; i >= 0; --i)
    {
      int c = S[i] - '0';
      t10 = (t10 * 10) % P;
      a = (a + c * t10) % P;
      ++buk[a];
    }
    for (auto [a, i] : buk)
    {
      ans += (ll)i * (i-1) / 2;
      if (a == 0)
        ans += i;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 3904
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<double>;
using vvd = vector<vd>;
using vl = vector<ll>;
using vvl = vector<vl>;
using pii = pair<int, int>;
using vs = vector<string>;
#define rep(i,n) range(i,0,n)
#define range(i,a,n) for(int i=a;i<n;i++)
#define all(a) a.begin(),a.end()
#define LINF    	((ll)1ll<60)
#define INF     	((int)1<<30)
#define EPS     	(1e-9)
#define MOD     	(1000000007)
#define fcout(a)	cout<<setprecision(a)<<fixed
#define fs 			first
#define sc			second
#define PI 3.1415926535897932384

template<class S, class T>ostream& operator<<(ostream&os, pair<S, T>p) { os << "[" << p.first << ", " << p.second << "]"; return os; };
template<class S>auto&operator<<(ostream&os, vector<S>t) { bool a = 1; for (auto s : t) { os << (a ? "" : " ") << s; a = 0; } return os; }


//int dx[]={1,1,1,0,-1,-1,-1,0},dy[8]={1,0,-1,-1,-1,0,1,1,1};
//
//constexpr ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
//

ll nCr[51][51];

void comb(int n) {
	rep(i, n+1) {
		rep(j, i + 1) {
			if (j == 0 || j == i) {
				nCr[i][j] = 1ll;
			}
			else {
				nCr[i][j] = nCr[i - 1][j - 1] + nCr[i - 1][j];
			}
		}
	}
}

int main() {
	//cin.tie(0); ios::sync_with_stdio(false);
	int n, a, b;
	cin >> n >> a >> b;
	comb(n);
	ll ans = 0;
	vector<double> v(n);
	vector<double> dp(n + 1, -1);
	dp[0] = 0;
	rep(i, n) {
		cin >> v[i];
	}
	sort(all(v),greater<ll>());
	ll sum = 0;
	rep(i, a) {
		sum += v[i];
	}
	fcout(10) << (sum / (double)a) << endl;
	if (v[0] == v[a - 1]) {
		int cntn = 0;
		rep(i, v.size()) {
			if (v[i] == v[a - 1]) cntn++;
		}
		range(i, a, b + 1) {
			ans += nCr[cntn][i];
		}
		cout << ans << endl;
	}
	else {
		ll ans = 0;
		int pos = 0;
		int cntn = 0, cntr = 0;
		rep(i, v.size()) {
			if (v[i] == v[a - 1]) {
				cntn++;
				if (i < a)pos++;
			}
		}
		cout << nCr[cntn][pos] << endl;
	}
}

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

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

  if(n == 1){
    cout << "Hello World" << endl;
  }
  if(n == 2){
    cin >> a >> b;
    cout << a + b << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <iomanip>
using namespace std;

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

  int n;
  cin >> n;
  vector<int> a(n);

  for(int i = 0; i < n; i++){
    cin >> a[i];
  }
  for(int i = n-1; i >= 0; i-=2){
    if(i != n - 1) cout << " ";
    cout << a[i];
  }
  for(int i = n % 2; i < n; i+=2){
    cout << " " << a[i];
  }
  cout << endl;
}

Measured memory_bytes: 2944
#include <bits/stdc++.h>
#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,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 998244353;
const ll LINF = 1e18;
const double PI=3.14159265358979323846;
using namespace std;
vector<int> dx={1,0,-1,0};
vector<int> dy={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

ll ext_gxd(ll a,ll b,ll &x,ll &y) {
    if(b==0) {
        x=1;
        y=0;
        return a;
    }
    ll q = a/b;
    ll g = ext_gxd(b,a-q*b,x,y);
    ll z = x-q*y;
    x=y;
    y=z;
    return g;
}

ll modinv(ll a, ll m) {
    ll x,y;
    ext_gxd(a,m,x,y);
    x%=m;
    if(x<0) x+=m;
    return x;
}

vector<ll> kaijou() {
    vector<ll> vec(1001001,1);
    rep(i,1001000) vec[i+1]=(vec[i]*(i+1))%MOD;
    return vec;
}

vector<ll> kai;
ll comb(int x,int y) {
    if(x<y || y<0)  return 0;
    return kai[x]*modinv(kai[x-y]*kai[y],MOD)%MOD;
}

int main() {
    kai=kaijou();
    ll n,a,b,k;
    cin>>n>>a>>b>>k;
    ll ans=0;
    for(ll p=0; p<=n; p++) {
        if((k-a*p)%b!=0) continue;
        ll q=(k-a*p)/b;
        if(q<0 || q>n) continue;
        ans+=(comb(n,p)*comb(n,q))%MOD;
        ans%=MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define divceil(A, B) ((A + (B - 1)) / B)
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr

typedef long long ll;

using namespace std;

int main(){

    int n;
    cin >> n;

    vector<int> w;
    int sum = 0;

    rep(i,n){
        int tmp;
        cin >> tmp;

        w.pback(tmp);
        sum += tmp;
    }

    int ans = sum;

    int tmpsum = 0;

    rep(i,n){

        tmpsum += w[i];

        ans = min(ans, abs(tmpsum - (sum - tmpsum)));

    }


    cout << ans << endl;


    return 0;
}


Measured memory_bytes: 256
//#pragma GCC optimize("Ofast")
//#pragma GCC optimize ("unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
//Tariquzzaman Faisal
//_Faisal101_
//IUT_CSE'19
//190041101
 
#include<iostream>
#include<stdio.h>
#include<vector>
#include<deque>
#include<map>
#include<stack>
#include<queue>
#include<algorithm>
#include<cstring>
#include<climits>
#include<cmath>
#include<iterator>
#include<set>
#define fileOut freopen("out.txt","w",stdout)
#define fileIn freopen("in.txt","r",stdout)
#define testcases ll TC,T; cin >> TC; for(T=1; T<=TC; T++)
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define INFLL 9223372036854775807
#define INF 2147483647
#define pi acos(-1.0)
#define ll long long
#define endll printf("\n")
#define CASE printf("Case %lld: ",T)
#define ff first
#define ss second
#define mem(ara,n) memset(ara,n,sizeof ara)
#define ull unsigned long long
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define mid3(a,b,c) min(max(a,b),max(b,c),max(a,b))
#define max4(a,b,c,d) max(max(a,b),max(c,d))
#define min4(a,b,c,d) min(min(a,b),min(c,d))
#define endl '\n'
#define ld long double
 
 
using namespace std;


int main(){
  ll n, a, b;
  cin >> n >> a >> b;
  if(a > b) cout<<0<<endl;
  else if(n==1){
    if(a < b) {cout<<0<<endl;}
    else cout << 1 <<endl;
  }
  else{
    cout << (n-2)*(b-a) + 1 <<endl;
  }
  return 0;
}

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


void solve(long long N, std::vector<long long> a, std::vector<long long> b){

  vector<long long> moda(N), modb(N);
  vector<long long> ans(30);

  for(auto i=1;i<30;++i){
    long long T = pow(2.0, i-1);
    for(auto j=0;j<N;++j){
      moda[j] = a[j]%(2*T);
      modb[j] = b[j]%(2*T);
    }
    sort(modb.begin(), modb.end());
    long long counter=0;
    for(auto j=0;j<N;++j){
      counter += (long long)(lower_bound(modb.begin(), modb.end(), 2*T-moda[j])
                             - lower_bound(modb.begin(), modb.end(), T-moda[j]));
      counter += (long long)(lower_bound(modb.begin(), modb.end(), 4*T-moda[j])
                             - lower_bound(modb.begin(), modb.end(),3*T-moda[j]));
    }
    ans[i]=(long long)(counter%2==1);
  }
  long long A=0;
  for(auto i=1;i<30;++i){
    A <<= 1;
    A += ans[30-i];
  }
  cout << A << endl;

}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
  long long N;
    scanf("%lld",&N);
    std::vector<long long> a(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&a[i]);
    }
    std::vector<long long> b(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&b[i]);
    }
  solve(N, std::move(a), std::move(b));
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> pii;


#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1e9+1)


int main(){
    int n;
    cin>>n;
    vector<int> v;
    rep(i,n){
        string s;
        cin>>s;
        int c;
        rep(i,s.size()){
            if(s[i]=='.'){
                c=i;
                break;
            }
        }
        s.erase(s.begin()+c);
        v.pb(stoi(s));
    }
    
    vector<int> a=v;
    sort(all(a));
    
    
    rep(i,n){
        int win, lose, drow;
        win = lower_bound(all(a),v[i]) - a.begin();
        drow= upper_bound(all(a),v[i]) - lower_bound(all(a),v[i])-1;
        lose= n - (upper_bound(all(a),v[i]) - a.begin());
        int ans = 3*win + 1*drow;
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3664
from collections import Counter
MOD = 1000000007
N = int(input())
A = map(int, input().split())
c = Counter(A)
if N % 2 == 0:
    for i in range(1, N, 2):
        if c[i] != 2:
            print(0)
            exit()
    ans = 2 ** (N // 2) % MOD
else:
    if c[0] != 1:
        print(0)
        exit()
    for i in range(2, N, 2):
        if c[i] != 2:
            print(0)
            exit()
    ans = 2 ** (N // 2) % MOD
print(ans)


Measured memory_bytes: 16624
#include<iostream>
#include<iomanip>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
#include<string>
#include<utility>
#include<numeric>
#include<algorithm>
#include<cmath>
#include<climits>

//エイリアス
using namespace std;
using ll = long long;
using pll = pair<ll, ll>;

class Stream{
public:
    Stream(){

    }
    //配列以外の入力を受け取る
    void read(){

    }
    template<typename First, typename... Rest>
    void read(First& first, Rest&... rest){
        cin >> first;
        read(rest...);
    }
    template<typename T>
    vector<T> read_vec(size_t n){
        vector<T> tmp(n);
        for(size_t i = 0; i < n; i++){
            cin >> tmp[i];
        }
        return tmp;
    }
    //配列を区切って出力する
    template<typename T>
    void write_vec(vector<T>& v, char divider){
        for(size_t i = 0; i < v.size(); i++){
            cout << v[i] << divider;
        }
    }
};

int main(){
    Stream io;
    
    int a;
    io.read(a);
    cout << a + a * a + a * a * a; 
    
    return 0;
}


Measured memory_bytes: 3592
#define Z(V) for(v=360,m=g();--m;V+=sin(x*z))v-=x=g();V+=sin(v*z)
a;g(){scanf("%d",&a);a?a:exit(0);}main(m,v,x){for(;;){double s=0,t=0,z=.018,e=.000001;Z(s);Z(t);puts(s>t+e?"1":s+e<t?"2":"0");}}

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

int main() {
    int A, B, ans;
    cin >> A >> B;
    ans = 0;

    int n, a, b, d, e;
    for (int i = A; i <= B; i++) {
        n = i;
        a = n % 10;
        n /= 10;
        b = n % 10;
        n /= 100;
        d = n % 10;
        n /= 10;
        e = n % 10;
        if ((a == e) && (b == d)){
            ans++;
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define ll long long
using namespace std;
//typedef vector<unsigned int>vec;
//typedef vector<ll>vec;
//typedef vector<vec> mat;
typedef pair<int, int> P;
typedef pair<ll,ll> LP;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const int INF = 1000000000;
const ll LINF = 1000000000000000000;//1e18
const ll  MOD = 1000000007;
const double PI = acos(-1.0);
const double EPS = 1e-10;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
//template<class T> inline void add(T &a, T b){a = ((a+b) % MOD + MOD) % MOD;};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    set<int> st;
    REP(i,3){
        int a;
        cin >> a;
        st.insert(a);
    }
    if(st.size() == 2) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		long A = sc.nextLong();
		long B = sc.nextLong();
		long N = sc.nextLong();

		long max = 0;
		//		long startp = Math.min(B, N);
		//		HashSet<Long> nSet = new HashSet<Long>();
		//		for (long i = startp; i <= N; i++) {
		//			nSet.add(i);
		//		}

		//		for (long i : nSet) {
		//			long tmp = floor(A * i, B) - A * floor(i, B);
		//			max = Math.max(max, tmp);
		//		}
		long i = 0;
		if (B <= N) {
			i = B - 1;
		} else {
			i = N;
		}
		long tmp = floor(A * i, B) - A * floor(i, B);

		System.out.println(tmp);
	}

	private static long floor(long a, long b) {
		return a / b;

	}
}


Measured memory_bytes: 35744
a,b,c,d = map(int,input().split())
dis_ab = abs(a-b)
dis_bc = abs(b-c)
dis_ac = abs(a-c)

if dis_ab <= d and dis_bc <= d:
  print('Yes')
elif dis_ac <= d:
  print('Yes')
else:
  print('No')

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

#if DEBUG && !ONLINE_JUDGE
    #include "/home/tushar_garg/Desktop/cpp/debug.h"
#else
    #define dbg(x...)
#endif

typedef     long long                            ll; 
typedef     pair<ll, ll>                         pl; 
typedef     vector<ll>                           vl;
typedef     vector<char>                         vc;
typedef     vector<bool>                         vb; 
typedef     vector<vl>                           vvl; 
typedef     vector<pl>                           vll; 
typedef     map<ll, ll>                          dict; 
typedef     map<ll, ll, greater <ll> >           sdict; 
typedef     map<char, ll>                        mcl;
typedef     priority_queue<ll>                   pqi;
typedef     priority_queue<pl>                   pqii;
typedef     priority_queue<ll, vl, greater<ll>>  pqmini;

#define rep(i, a, n) for (auto i=(a)-((a)>(n)); i!=(n)-((a)>(n)); i+=1-2*((a)>(n)))
#define trav(i, a) for(auto &i:a)
#define fi first 
#define se second 
#define mp make_pair 
#define pb push_back
#define eb emplace_back
#define flash ios_base::sync_with_stdio(false),cin.tie(nullptr),cout.tie(nullptr)
#define QuickSilver cin.exceptions(cin.failbit),setprecision(12),cout.precision(12);
#define fill(a, b) memset(a, b, sizeof(a)
#define get(a) rep(i,0,sz(a))cin>>a[i];
#define sz(a) (ll)(a.size())
#define all(a) a.begin(), a.end()
#define mod 1000000007

int main(){
	flash; QuickSilver;
	ll n,k; cin>>n>>k;
	vl a(n); get(a);
	vl dp(k+1, 0); dp[0]=1;
	// dp[i] rep. no. of ways of distributing i candies
	rep(i,0,n){
		vl pre(k+2); pre[0]=0;
		rep(j,0,k+1) pre[j+1]=pre[j]+dp[j];
		rep(j,1,k+1) dp[j]=(pre[j+1]-pre[max(0LL,j-a[i])])%mod;
	}
	cout<<dp[k]<<"\n";
	return 0;
}

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

template <class T> inline bool chmax(T& a, T b) {
  if(a < b) {
    a = b;
    return true;
  }
  return false;
}

int main() {
  int N;
  cin >> N;
  string s;
  map<string, int> ss;
  int mxv = 0;
  for(int i = 0; i < N; ++i) {
    cin >> s;
    ss[s]++;
    chmax(mxv, ss[s]);
  }
  for(auto s : ss) {
    if(s.second == mxv) {
      cout << s.first << endl;
    }
  }

  return 0;
}

Measured memory_bytes: 25216
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define rep(i, n) ;for (int i = 0;i < (int)(n);i++)
#define rep2(i, s, n) ;for (int i = s; i < (int)(n);i++)
#define ALL(vec)  (vec).begin(),(vec).end()
#define pi 3.1415926535897932384626433832795
#define MAX_INF 9223372036854775807
#define MIN_INF (922337203685477587+1)
#define sosuu 1000000007

int main() {
  int N;
  cin >> N;
  vector<int> L(2*N);
  rep(i, 2*N)
    cin >> L[i];
  sort(ALL(L));
  int ans=0;
  rep(i, N){
  ans+=L[2*i];
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <fstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;
typedef long long LL;
typedef pair<int, int> P;
static const double EPS = 1e-5;

#define FOR(i,k,n) for (int i=(k); i<(int)(n); ++i)
#define REP(i,n) FOR(i,0,n)
int m[3] = {1,2,3};
int c(int n){
  return (7-n);
}
int main(void){
  int N;
  while(cin>>N){
    REP(i,3) m[i]=i+1;
    int count=0;
    if(N==0) break;
    string str;
    REP(i,N){
      int nm[3];
      REP(i,3)nm[i]=m[i];
      cin>>str;
        if(str== "North"){
          nm[0]=m[1];
          nm[1]=c(m[0]);
          }
        if(str== "East"){
          nm[0]=c(m[2]);
          nm[2]=m[0];
          }
        if(str== "West"){
          nm[0]=m[2];
          nm[2]=c(m[0]);
          }
        if(str== "South"){
          nm[0]=c(m[1]);
          nm[1]=m[0];
          }
        if(str== "Right"){
          nm[1]=m[2];
          nm[2]=c(m[1]);
          }
        if(str== "Left"){
          nm[1]=c(m[2]);
          nm[2]=m[1];
          }
      REP(i,3)m[i]=nm[i];
      count+=m[0];
    }
    cout<<count+1<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
	ll n;
	cin >> n;
	ll po[5] = {};
	string s = "MARCH";
	map<char, ll> m;
	for(ll i = 0; i < 5; i++) m[s[i]] = i;
	for(ll i = 0; i < n; i++){
		string yo;
		cin >> yo;
		if(m.find(yo[0]) == m.end()) continue;
		po[m[yo[0]]]++;
	}
	ll ans = 0;
	for(ll i = 0; i < 5; i++)for(ll j = i + 1; j < 5; j++)for(ll k = j + 1; k < 5; k++) ans += po[i] * po[j] * po[k];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
// Happy Birthday!

#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int main(){
	int A, B;
	cin >> A >> B;
	if (A <= 8 && B <= 8)
		cout << "Yay!" << endl;
	else
		cout << ":(" << endl;

	return 0;
}

Measured memory_bytes: 256
input1 = input().split()
N = int(input1[0])
M = int(input1[1])

list = ['a' for i in range(N)]
ans = 0

for i in range(M):
  input2 = input().split()
  s = int(input2[0])
  c = int(input2[1])
  if s == 1 and c == 0:
    if N > 1:
      ans = -1
  if list[s-1] == "a" or list[s-1] == c:
    list[s-1] = c
  else:
    ans = -1

if list[0] == "a":
  if N > 1:
    list[0] = 1

if N == 1 and list[0] == "a":
  list[0]=0

for i in range(N):
  if list[i] == "a":
    list[i] = 0
  
ans2 = ""

for i in list:
  ans2 = ans2 + str(i)
  
if ans == 0:
  print(int(ans2))
else:
  print(ans)
  

Measured memory_bytes: 3064
import java.util.*;
class Main{
  public static void main(String[]$){
    Scanner c=new Scanner(System.in);
    char[] x=c.next().toCharArray();
    int s=0;
    for(char t:x)s+=t=='S'?2:s>0?-2:0;
    System.out.print(s);
  }
}

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

H = list(map(int, input().split()))

dp = {}

dp[1] = 0
dp[2] = abs(H[1]-H[0])

for i in range(3, N+1):
    dp[i] = min(dp[i-1]+abs(H[i-1]-H[i-2]), dp[i-2]+abs(H[i-1]-H[i-3]))

print(dp[N])

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

int main()
{
	vector<int> HeightOfMountain(10);
	for(int i = 0; i < 10; i++){
		cin >> HeightOfMountain[i];
	}
	sort(HeightOfMountain.begin(), HeightOfMountain.end());
	cout << HeightOfMountain[9] << endl;
	cout << HeightOfMountain[8] << endl;
	cout << HeightOfMountain[7] << endl;
	return 0;
}

Measured memory_bytes: 3164
#include <bits/stdc++.h>
#define ll long long
using namespace std;
ll n ;
double ans , di=2 , x , a[51] , cur , sec ,pu;
priority_queue<double > p ;
int main()
{

        cin >> n ;
          //cin >>ans;
        for ( int i = 0 ; i < n ;i++)cin >> a[i] , p.emplace(-1 * a[i]);
        while(p.size() > 1)
        {
            cur = -1 * p.top();
            p.pop();
            sec = -1 * p.top();
            p.pop();
            pu= (cur + sec) / di;
            p.emplace(-1 * pu);
        }
        cout << -1 * p.top();

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <cstring>
#include <utility>
#include <set>
#include <stack>
#include <climits>
#include <cmath>

#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 reps(i,s,n) for(int i=s, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
#define MEMSET(v, h) memset((v), h, sizeof(v))
typedef long long ll;
const char sp = ' ';


using namespace std;

int main(void){
    ll X;
    cin>>X;
    ll count=0;
    count+=(X/500)*1000;
    X=X%500;
    count+=(X/5)*5;
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
//arc060_c.cpp
//Sat Jun 23 13:19:44 2018

#include <iostream>
#include <string>
#include <queue>
#include <unordered_map>
#include <vector>
#include <algorithm>
using namespace std;
using ll=long long;

int n,a,X;
int x[50];
ll dptable[51][51][2502];

int main(){
	cin >> n >> a;
	X = a;
	for (int i=0;i<n;i++){
		cin >> x[i+1];
		X = max(X,x[i+1]);
	}

	for (int j=0;j<=n;j++){
		for (int k=0;k<=n;k++){
			for (int s=0;s<=2500;s++){
				if (j==0 && k==0 && s==0){
					dptable[j][k][s] = 1;
				}else if (j>=1 && s<x[j]){
					dptable[j][k][s] = dptable[j-1][k][s];
				}else if (j>=1 && k>=1 && s>=x[j]){
					dptable[j][k][s] = dptable[j-1][k][s] + dptable[j-1][k-1][s-x[j]];
				}else {
					dptable[j][k][s] = 0;
				}
			}
		}
	}

	ll ans = 0;

	for (int k=1;k<=n;k++){
		ans += dptable[n][k][k*a];
	}

	cout << ans << endl;
}

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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    rep(i, n) {
        cin >> a[i];
        a[i] -= (i+1);
    }
    sort(a.begin(), a.end());
    ll ans1 = 0, ans2 = 0;
    rep(i, n) {
        ans1 += abs(a[i]-a[n/2]);
        ans2 += abs(a[i]-a[n/2+1]);
    }
    cout << min(ans1, ans2) << endl;
    return 0;
}


Measured memory_bytes: 1024
S=input()
N=len(S)

bit=0

ans=0

for i in range(2**(N-1)):
    bit=bin(i)
    
    Z=[]
    sf=0
    for k in range(len(bit)-2):
        
        if bit[len(bit)-1-k] =="1":
            
            Z.append(S[sf:k+1])
            sf=k+1
    Z.append(S[sf:])
    
    for k in range(len(Z)):
        ans+=int(Z[k])
print(ans)
            

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

int main(){
    int N;
    cin >> N;
    vector<int> A(N);
    for(int i=0; i<N; i++){
        cin >> A.at(i);
    }
  	bool a=true;
    for(int i=0; i<N; i++){
        if(A.at(i)%2==0 && (A.at(i)%3!=0 && A.at(i)%5!=0)) {
            a=false;
        }
    }
  	if(a) cout << "APPROVED" << endl;
 	else cout << "DENIED" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
#define MOD 1000000007
using namespace std;

// int prime[1000001];
// vector<ll> primes;

// void soe() {
//     int i,j;
//     for(i=2;i<1000001;i++) prime[i] = 1;
//     for(i=2;i<=sqrt(1000001);i++) {
//         if(prime[i] == 1) {
//             for(j=i*i;j<1000001;j+=i) {
//                 prime[j] = 0;
//             }
//         }
//     }
//     for(i=2;i<1000001;i++) {
//         if(prime[i]) primes.pb(i);
//     }
// }


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

    int n,l,i;
    cin >> n >> l;
    vector<string> v(n);
    for(i=0;i<n;i++) cin >> v[i];
    sort(v.begin(),v.end());
    for(i=0;i<n;i++) cout << v[i];
    cout << "\n";
    return 0;
}




Measured memory_bytes: 256
//g++ -std=c++11 -Wall -O2 -o main.exe main.cpp
 
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <functional>
#include <algorithm>
#include <complex>
#include <numeric>
//最大公約数: gcd()
//最小公倍数: lcm()
 
using namespace std;
 
template <typename T>
void sortasc(vector<T> &v){ //vectorを昇順にソート
    sort(v.begin(), v.end(), std::greater<int>());
    return;
}
 
template <typename T>
void sortdesc(vector<T> &v){ //vectorを降順にソート
    sort(v.begin(), v.end(), std::less<int>());
    return;
}
 
int main(){
    int n, t, min = 1000;
    cin >> n >> t;
    vector<int> cn(n), tn(n);
    bool flag = false;

    for(int i = 0; i < n; i++){
        cin >> cn[i] >> tn[i];

        if(tn[i] <= t && cn[i] <= min){
            min = cn[i];
            flag = true;
        }
    }

    if(flag) cout << min << endl;
    else cout << "TLE" << endl;
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		sc.close();

		long MOD = 1000000007L;

		boolean[] chk = new boolean[1010];
		Arrays.fill(chk, true);
		int[] prime = new int[1000];
		int cnt = 0;
		for (int i = 2; i <= 1000; i++) {
			if (chk[i]) {
				prime[cnt++] = i;
				int x = 2 * i;
				while (x <= 1000) {
					chk[x] = false;
					x += i;
				}
			}
		}

		long ans = 1L;
		for (int i = 0; i < cnt; i++) {
			int factor = 0;

			for (int j = 2; j <= N; j++) {
				int cur = j;
				while (cur >= prime[i]) {
					if (cur % prime[i] == 0) {
						factor++;
						cur = cur / prime[i];
					} else {
						break;
					}
				}
			}
			ans = (ans * (factor + 1)) % MOD;
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 10188
#include<iostream>
int main(){
	int Digit, a, b, sum;

	while (std::cin >> a >> b){
		Digit = 0;
		sum = a + b;
		while (sum > 0){
			Digit++;
			sum /= 10;
		}
		std::cout<<Digit<<std::endl;
	}
return 0;
}

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

int segTree[1000000];
int segSize;

void init(int n){
  segSize = 1;
  while(segSize < n) segSize *= 2;

  for(int i = 0;i < segSize;i++){
    segTree[segSize-1+i] = INT_MAX;
  }

  for(int i = segSize-2;i >= 0;i--){
    segTree[i] = min(segTree[i*2+1],segTree[i*2+2]);
  }
  return;
}

void update(int i, int val){
  i = segSize-1+i;
  segTree[i] = val;

  while(i > 0){
    i = (i - 1) / 2;
    segTree[i] = min(segTree[i*2+1], segTree[i*2+2]);
  }

  return;
}

int getmin(int a, int b, int k = 0, int l = 0, int r = segSize){

  if(r <= a || b <= l) return INT_MAX;
  if(a <= l && r <= b) return segTree[k];

  int vl = getmin(a,b,2*k+1,l,(l+r)/2);
  int vr = getmin(a,b,2*k+2,(l+r)/2,r);
  return min(vl, vr);
}

int main(){
    long long n;
    cin >> n;
    init(n+1);

    int a[200010];
    long long mas[200010];
    for(int i = 0;i < n;i++){
        cin >> a[i];
        mas[a[i]] = i;
    }

    long long ans[200010] = {};

    long long mimi[200010];

    for(int i = 1;i <= n;i++){
        int mi;
        if((mi = getmin(mas[i], n+1)) == INT_MAX){
            mimi[i] = -1;
        }else{
            mimi[i] = mi;
        }
        update(mas[i], mas[i]);
    }

    long long all = 0;
    for(int i = n-1;i >= 0;i--){
        if(mimi[a[i]] == -1){
            ans[i] = (n-i)*a[i];
        }else{
            ans[i] = (mimi[a[i]]-i)*a[i] + ans[mimi[a[i]]];
        }
        all += ans[i];
    }

    cout << all << endl;

    return 0;
}




Measured memory_bytes: 7808
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Runtime.InteropServices;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;

public static class P
{
    public static void Main()
    {
        int carriedMin = int.MaxValue / 2;
        int uncarriedMin = 0;
        //繰越の次に繰り越す場合
        foreach (var item in Console.ReadLine().Reverse().Select(x => x - '0'))
        {
            var nextCarried = 0;
            var nextUncarried = 0;
            nextCarried = Min(carriedMin + 10 - (item + 1), uncarriedMin + 10 - item);
            nextUncarried = Min(carriedMin + (item + 1), uncarriedMin + item);
            carriedMin = nextCarried;
            uncarriedMin = nextUncarried;
        }
        carriedMin++;
        Console.WriteLine(Min(carriedMin, uncarriedMin));
    }
}

Measured memory_bytes: 19168
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <cstring>
#include <cstdlib>
using namespace std;

int main(){
    int n;
    bool m[51][51];

    vector<int> v;
    set<int> s;
    set<int> schedules[101];
    while(cin>>n&&n!=0){
        for(int i = 0; i < n; i++){
            schedules[i].clear();
            int t;
            cin>>t;
            for(int j = 0; j < t; j++){
                int p;
                cin>>p;
                schedules[i].insert(p);
            }
        }
        // ツつサツづェツつシツづェツつェツつ「ツづ慊づづ個地ツ図ツづーツ篠敖づづつ「ツづゥツつゥ
        memset(m,0,sizeof(m));
        for(int i = 0; i < n; i++)
            m[i][i]=true;
        int idx=31;
        for(int i = 1; i <= 30; i++){
            v.clear();
            s.clear();

            for(int j = 0; j < n; j++){
                if(schedules[j].find(i)!=schedules[j].end()){
                    v.push_back(j);
                    for(int k = 0; k < n; k++){
                        if(m[j][k])
                            s.insert(k);
                    }
                }
            }
            if(s.size()==n){
                idx=i;
                break;
            }
            for(set<int>::iterator it = s.begin(); it!=s.end(); it++)
                for(int j = 0; j < v.size(); j++)
                    m[v[j]][*it]=true;

        }
        if(idx==31)
            cout<<-1<<endl;
        else
            cout<<idx<<endl;
    }

    return 0;
}

Measured memory_bytes: 956
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N;
    cin>>N;
    int j=0;
    for(int i=0;i<3;i++)
    {
        if(N%10==7)
        {
            j=1;
            cout<<"Yes"<<endl;
            break;
        }
        N=N/10;
    }
    if(j==0)
    {
        cout<<"No"<<endl;
    }
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define int long long
#define double long double
#define mod 1000000007
#define F first
#define S second
#define P pair<long long,long long>
#define all(a) a.begin(),a.end()
#define INF 1000000000000000000
#define endl '\n'
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;

signed main(void){
    string s; cin>>s;
    vector<int> alp(26,0);
    rep(i,s.size())alp.at(s.at(i)-'a')++;
    int ans=INF;
    rep(i,26){
        if(alp.at(i)==0)continue;
        char c=i+'a';
        string t=s;
        int cnt=0;
        while(t.size()){
            bool b=true;
            rep(i,t.size()-1)if(t.at(i)!=t.at(i+1)){b=false; break;}
            if(b)break;
            string u="";
            rep(i,t.size()-1){
                if(t.at(i)==c or t.at(i+1)==c)u+=c;
                else u+=t.at(i);
            }
            t=u;
            cnt++;
        }
        chmin(ans, cnt);
    }
    cout<<ans<<endl;
}

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

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}

int main() {
  int n;
  ll MOD = 998244353;
  cin >> n;
  vector<int>d(n);
  rep(i,0,n) cin >> d[i];
  if(d[0] != 0){
    cout << 0 << endl;
    return 0;
  }
  sort(d.begin(),d.end());
  vector<int>c(d[n-1]+1);
  rep(i,0,n) c[d[i]]++;
  if(c[0] != 1){
    cout << 0 << endl;
    return 0;
  }
  rep(i,1,c.size()){
    if(c[i] == 0){
      cout << 0 << endl;
      return 0;
    }
  }
  ll ans = 1;
  rep(i,2,c.size()){
    ans *= modpow(c[i-1],c[i],MOD);
    ans %= MOD;
  }
  cout << ans << endl;
}

Measured memory_bytes: 1024
while n = STDIN.gets.to_i do
  break if n == 0
  twodarr = []
  n.times{ |i|
    arr = STDIN.gets.split.map(&:to_i)
    twodarr[i] = arr
  }
  n.times{ |i|
    twodarr[i][twodarr.size] = twodarr[i].inject(:+)
    (twodarr.size+1).times{ |j|
      print twodarr[i][j].to_s.rjust(5)
    }
    puts
  }
  rowsum = []
  rowsum = twodarr.transpose.map{|ary| ary.inject(&:+)}
  (twodarr.size+1).times{ |i|
    print rowsum[i].to_s.rjust(5)
  }
  puts
end

Measured memory_bytes: 8808
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.Random;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner fs=new FastScanner();
		int d = fs.nextInt();
		int t = fs.nextInt();
		int s = fs.nextInt();
		
		if((float)d/s<=t) {
			System.out.println("Yes");
		}
		else {
			System.out.println("No");
		}
		
	}
	
	

	static final Random random=new Random();
	
	static void ruffleSort(int[] a) {
		int n=a.length;//shuffle, then sort 
		for (int i=0; i<n; i++) {
			int oi=random.nextInt(n), temp=a[oi];
			a[oi]=a[i]; a[i]=temp;
		}
		Arrays.sort(a);
	}
	
	static class FastScanner {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		StringTokenizer st=new StringTokenizer("");
		String next() {
			while (!st.hasMoreTokens())
				try {
					st=new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			return st.nextToken();
		}
		
		int nextInt() {
			return Integer.parseInt(next());
		}
		int[] readArray(int n) {
			int[] a=new int[n];
			for (int i=0; i<n; i++) a[i]=nextInt();
			return a;
		}
		long nextLong() {
			return Long.parseLong(next());
		}
	}

	
}


class node{
	int data;
	node next;

	node(int data){
		this.data=data;
	}
}

class Methods{
	node head;
	int size =0 ;
	void insert(int data) {
		node n = new node(data);
		size++;
		if(head==null) {
			head= n;
		}
		else {
			node k = head;
			while(k.next!=null) {
				k=k.next;
			}
			
			k.next=n;
		}
		
	}

	void print() {
		node n = head;
		while(n.next!=null) {
			System.out.print(n.data+" ");
			n=n.next;
		}
		System.out.println(n.data);
		
	}
	
	void isLoop(int x) {
		
		System.out.println(size - x +1);
		
		node n = head;
		
		while(n.next!=null && x-->2 ) {
			n=n.next;
		}
		
		n.next=n.next.next;
		
	}
	
	
}




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

int main() {
	// your code goes here
	
	int n;
	cin>>n;
	
	if(n%1000==0)
	cout<<0;
	else
	cout<<((n/1000)+1)*1000-n;
	
	return 0;
}


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

typedef long long ll;

ll N, A, B;
bool First = true;
ll Top;

void go(ll k) {
  for (ll i = 0; i < k; ++i) {
    cout << (First ? "" : " ") << Top - (k - 1) + i;
    First = false;
  }
  Top -= k;
}
void solve() {
  if (N < A + B - 1 || A * B < N) {
    cout << -1 << endl;
    return;
  }
  Top = N;
  for (ll i = 0; i < B; ++i) {
    if (A == 1) {
      assert(N == B);
      go(1);
    } else {
      ll n_fulls = (N - B) / (A - 1);
      go(i < n_fulls ? A : i == n_fulls ? (N - B) % (A - 1) + 1 : 1);
    }
  }
  cout << endl;
}
int main() {
  cin >> N >> A >> B;
  solve();
  return 0;
}


Measured memory_bytes: 2176
import bisect

N = int(input())
L  =list(map(int, input().split()))

count  =0
L.sort()
for i in range(0, N - 1):
  for j in range(i + 1, N):
    index = bisect.bisect_left(L, L[i] + L[j]) 
    count += max(0, index - j - 1)
print(count)


Measured memory_bytes: 3188
#define _USE_MATH_DEFIMES
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <clocale>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

const int MOD = 1'000'000'007;
const int INF = 1'000'000'000; //1e9
const int NIL = -1;
const long long LINF = 1'000'000'000'000'000'000; // 1e18
const long double EPS = 1E-10;

template<class T, class S> inline bool chmax(T &a, const S &b){
    if(a < b){
        a = b; return true;
    }
    return false;
}
template<class T, class S> inline bool chmin(T &a, const S &b){
    if(b < a){
        a = b; return true;
    }
    return false;
}




std::map<long long, int> primeFactorisation_Map(long long n){
    std::map<long long, int> mp;
    for(long long i(2); i * i <= n; ++i)
        while(!(n % i)){
            ++mp[i]; n /= i;
        }
    if(n > 1) ++mp[n];
    return mp;
}


int main(){
    long long N; std::cin >> N;
    std::map<long long, int> mp(primeFactorisation_Map(N));
    int cnt(0);
    for(auto e: mp){
        for(int i(1);; ++i){
            if(e.second >= i){
                ++cnt; e.second -= i;
            }else break;
        }
    }
    std::cout << cnt << std::endl;
    return 0;
}


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

int main(){
	int n;
	int dt[300000];
	for(int i=0;i<300000;i++){
		dt[i]=1;
	}
	dt[0]=dt[1]=0;
	for(int i=2;i<sqrt(300000);i++){
		for(int j=(i*2);j<300000;j+=i){
			dt[j]=0;
		}
	}
	while(1){
		cin>>n;
		if(n==0)break;
		int cnt=0;
		for(int i=n+1;i<=2*n;i++){
			if(dt[i]==1){
				cnt++;
			}
		}
		cout<<cnt<<endl;
	}
	return 0;
}

Measured memory_bytes: 2328
#include<iostream>
#include<queue>
#include<map>
#include<string>
using namespace std;

map<string, int> mp;
string s;
queue<pair<string, int> > Q;
const int dx[4] = {-1, 1, -4, 4};

void bfs(){
	mp["01234567"] = 0;
	Q.push(make_pair("01234567",0));
	while(!Q.empty()){
		for(int i=0;i<4;i++){
			string next = Q.front().first;
			int pos = Q.front().second;
			int npos = pos + dx[i];
			if(npos<0||npos>7||(pos==3&&npos==4)||(pos==4&&npos==3))
				continue;
			swap(next[pos],next[npos]);
			if(mp.find(next)==mp.end()){
				mp[next] = mp[Q.front().first] + 1;
				Q.push(make_pair(next,npos));
			}
		}
		Q.pop();
	}
}

int main(){
	s.resize(8);
	bfs();
	while(cin>>s[0]>>s[1]>>s[2]>>s[3]>>s[4]>>s[5]>>s[6]>>s[7]){
		cout << mp[s] << endl;
	}
}


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

#pragma GCC optimize("02")
#pragma GCC target("tune=native")

using namespace std;

#define ll long long int
#define lu unsigned long long int
#define fi first
#define se second
#define edge pair<long long int,long long int>
#define weighted_edge pair<long long int,pair<long long int,long long int>>

int main() {

	ios_base::sync_with_stdio(0);
	cin.tie(0);

	int arr[3];

	for(int i = 0; i < 3; i++) cin >> arr[i];

	sort(arr, arr + 3);

	if(arr[0] + arr[1] == arr[2])cout << "Yes\n";
	else cout << "No\n";

	return 0;
}

Measured memory_bytes: 256
from itertools import accumulate

n, m = map(int, input().split())
a = list(map(int, input().split()))
MAX = 10 ** 5

scores = [0] * (2 * MAX + 1)
for e in a:
    scores[e] += 1

acc = list(accumulate(scores))


def f(x):
    cnt = 0
    for e in a:
        cnt += n - acc[max(0, x - e - 1)]

    return cnt


l = 0
r = 2 * MAX + 1
while r - l > 1:
    mid = (l + r) // 2
    if f(mid) >= m:
        l = mid
    else:
        r = mid

scores_sum = [i * e for i, e in enumerate(scores)]
acc_sum = list(accumulate(scores_sum))
sm = sum(a)
ans = 0
cnt_sum = 0
for e in a:
    i = max(0, l - e - 1)
    cnt = n - acc[i]
    ans += e * cnt + sm - acc_sum[i]
    cnt_sum += cnt

ans -= (cnt_sum - m) * l

print(ans)


Measured memory_bytes: 31908
#include <iostream>

using namespace std;

int main(){
    int W,H,x,y,r;
    cin >> W >> H >> x >> y >> r;
    if(x >= r && y >= r && W >= x + r && H >= y + r){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 3088
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "YES" << endl
#define pyes cout << "Yes" << endl
#define POK cout << "OK" << endl
#define PNO cout << "NO" << endl
#define pno cout << "No" << endl
#define PNG cout << "NG" << endl
#define ret return 0

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

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

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  string s,t;
  cin >> s;
  cin >> t;
  int res =0;
  rep(i,SIZE(s)){
    res += s[i]!=t[i];
  }
  cout << res << endl;
  ret;
}


Measured memory_bytes: 3788
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int sx,sy,tx,ty;
int main(){
    cin>>sx>>sy>>tx>>ty;
    for(int i=0;i<ty-sy;++i)    printf("U");
    for(int i=0;i<tx-sx;++i)    printf("R");
    for(int i=0;i<ty-sy;++i)    printf("D");
    for(int i=0;i<tx-sx;++i)    printf("L");
    printf("L");
    for(int i=0;i<ty-sy+1;++i)  printf("U");
    for(int i=0;i<tx-sx+1;++i)    printf("R");
    printf("D");
    printf("R");
    for(int i=0;i<ty-sy+1;++i)    printf("D");
    for(int i=0;i<tx-sx+1;++i)    printf("L");
    printf("U");
   // getchar();
   // getchar();
    return 0;
}

Measured memory_bytes: 256