akhauriyash/Code-Regression huggingface dataset:
n = int(input())
P = list(map(float, input().split()))
dp = [[0]*(n+1) for _ in range(n+1)]
dp[0][0] = 1
for i in range(n):
  for j in range(n+1):
    if j==0:
      dp[i+1][j] = dp[i][j]*(1-P[i])
    else:
      dp[i+1][j] = dp[i][j-1]*P[i] + dp[i][j]*(1-P[i])
print(sum(dp[n][1+n//2:]))

Measured memory_bytes: 259720
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine().replace("\n", "");
        sc.close();
        if (s.length() == 2) {
            System.out.println(s);
        } else {
            for (int i = 2; i >= 0; i--) {
                System.out.print(s.charAt(i));
            }
            System.out.println();
        }
    }
}


Measured memory_bytes: 21972
#include<bits/stdc++.h>
#define f(i,n) for(int i=0;i<n;i++)
#define F first
#define S second
#define mod 1000000007
#define P pair<int,int>
#define int long long
using namespace std;
long long x[100000],y[100000],z[100000],vx[2],vy[2];
signed main(){
	long long a,b,c;
	cin>>a>>b>>c;
	f(i,a) cin>>x[i];
	f(i,b) cin>>y[i];
	f(i,c){
		cin>>z[i];
		long long ans=LLONG_MAX/3;
		f(j,2){
			vx[j]=x[max((int)(0),min((long long)(lower_bound(x,x+a,z[i])-x-j),a-1))];
			f(k,2){
				vy[k]=y[max((int)(0),min((long long)(lower_bound(y,y+b,z[i])-y-k),b-1))];
				ans=min(ans,min(abs(z[i]-vx[j]),abs(z[i]-vy[k]))+abs(vx[j]-vy[k]));
			}
		}
		cout<<ans<<endl;
	}
	return 0;
}


Measured memory_bytes: 3712
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ctime>
#include<deque>
using namespace std;

#define fr                first
#define se                second
#define int               long long
#define pb                push_back
#define mp                make_pair
#define pii               pair<int,int>
#define vi                vector<int>
#define mi                map<int,int>
#define pq                priority_queue<int>
#define set_bits(x)       __builtin_popcountll(x)
#define mod               1000000007
#define inf               1e18                        //Defining infinity the overflow of int
#define ps(x,y)           fixed<<setprecision(y)<<x   //for defining the precision of the decimal upto y places.
#define zrosetbits(x)     __builtin_ctzll(x)         //it will give no of 0's before the first 1 from the right.
#define mk(a,n,type)      type *a=new type[n];
#define test(t)           int t; cin>>t; while(t--)
#define no                cout<<"No\n";
#define yes               cout<<"Yes\n";
#define NO                cout<<"NO\n";
#define YES               cout<<"YES\n";
// #define for(i,n)          for(int i=0;i<n;i++)
// #define for(j,n)          for(int j=0;j<n;j++)
// #define forn(i,n)               for(int i=0;i<n;i--)



//**********************************************************************************************************
struct custom_hash {
  static uint64_t splitmix64(uint64_t x) {
    // http://xorshift.di.unimi.it/splitmix64.c
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
  }

  size_t operator()(uint64_t x) const {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
  }
};

#define safemap               unordered_map<int,int,custom_hash>

//*********************************************************************************************************

void io()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cin.tie(0);

}


int helper(int si, int a[], int n, int k, vi &dp)
{
//BASE CASE
  if (si == n - 1)
    return 0;

  if (dp[si] != -1)
    return dp[si];

//RECURSIVE CASE
  int res = INT_MAX;

  for (int i = 1; i <= k; i++)
  {
    if (si + i < n)
      res = min(abs(a[si + i] - a[si]) + helper(si + i, a, n, k, dp), res);
  }

  dp[si] = res;

  return res;


}


int32_t main()
{

  io();


  int n, k;
  cin >> n >> k;

  int a[n] = {0};

  for (int i = 0; i < n; i++)
    cin >> a[i];

  vi dp(n + 1, -1);

  int ans = helper(0, a, n, k, dp);

  cout << dp[0] << "\n";
  
  return 0;
}








Measured memory_bytes: 14264
import heapq


n = int(input())
a = list(map(int, input().split()))

first = a[0: n]
latter = list(map(lambda x: x*-1, a[2*n: 3*n]))
heapq.heapify(first)
heapq.heapify(latter)

sum_first = []
sum_latter = []
sum_first.append(sum(first))
sum_latter.append(-sum(latter))

for i in range(0, n):
    new = a[n+i]
    heapq.heappush(first, new)
    old = heapq.heappop(first)
    sum_first.append(sum_first[i] + new - old)

for j in range(n):
    new = a[2*n-1-j]
    heapq.heappush(latter, -new)
    old = -heapq.heappop(latter)
    sum_latter.append(sum_latter[j] + new - old)

ans = sum_first[0] - sum_latter[n]
for k in range(n+1):
    x = sum_first[k] - sum_latter[n-k]
    if x > ans:
        ans = x

print(ans)


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


#define lld long long 

lld max(lld x,lld y)
{
	if(x>y)
		return x;
	return y;
}		
lld min(lld x,lld y)
{

	if(x<y)
		return x;
	return y;
}

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


void solve ()
{
	lld n,W;
	cin>>n>>W;
	lld v[n],w[n];
	for(lld i=0;i<n;i++)
	{
		cin>>w[i];
		cin>>v[i];
	}
	lld a[n+1][W+1];
	for(lld i=0;i<=n;i++)
	{
		for(lld j=0;j<=W;j++)
		{
			if(i==0 || j==0)
			{
				a[i][j]=0;
			}
			else if( j-w[i-1]>=0)
			{
				a[i][j]=max(v[i-1]+a[i-1][j-w[i-1]],a[i-1][j]);
			}
			else
			{
				a[i][j]=a[i-1][j];


			}
		}
	}
	cout<<a[n][W]<<"\n";
}



int main()
{
	solve();
}

Measured memory_bytes: 79104
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
    sizeは(int)とキャストしよう
    ごちゃごちゃ場合分けを考える前に全探索は考えましたか？
*/

const ll mod = 1e9+7;

void chmod(ll &M){
    if(M >= mod) M %= mod;
    else if(M < 0){
        M += (abs(M)/mod + 1)*mod;
        M %= mod;
    }
}

ll modpow(ll x, ll n){
    if(n == 0) return 1;

    ll res = modpow(x, n/2);
    if(n%2 == 0) return res*res%mod;
    else return res*res%mod*x%mod;
}

ll power(ll x, ll n){
    if(n == 0) return 1;

    ll res = power(x, n/2);
    if(n%2 == 0) return res*res;
    else return res*res*x;
}

int getl(int i, int N) { return i==0? N-1:i-1; };
int getr(int i, int N) { return i==N-1? 0:i+1; };

/* <--------------------------------------------> */

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

    const int inf = 1<<30;
    int n,k; cin >> n >> k;
    vector<ll> h(n+5);
    for(int i=1; i<=n; ++i) cin >> h[i];

    vector<ll> dp(100005, inf);
    dp[1] = 0;
    for(int i=1; i<n; ++i){
        for(int j=1; j<=k; ++j){
            if(i+j > n) continue;
            chmin(dp[i+j], dp[i] + abs(h[i]-h[i+j]));
        }
    }


    cout << dp[n] << endl;

	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <unordered_set>
#include <random>
#include <cassert>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD=998244353;
int main()
{
	string s;
	cin>>s;
	int n=s.size();
	ll dp[4001][4001]={};
	dp[0][0]=1;
	int ct[3]={};
	for(int i=0; i<2*n; i++){
		if(i<n) ct[s[i]-'0']++;
		for(int j=0; j<=i+1; j++){
			if(j<=2*ct[0]+ct[1] && i+1-j<=2*ct[2]+ct[1]){
				if(j) dp[i+1][j]+=dp[i][j-1];
				dp[i+1][j]+=dp[i][j];
				dp[i+1][j]%=MOD;
			}
		}
	}
	ll ans=0;
	for(int i=0; i<=2*n; i++) ans=(ans+dp[2*n][i])%MOD;
	cout<<ans<<endl;
	return 0;
}

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

int main() {
  int D, G;
  cin >> D >> G;
  vector<int> p(D);
  vector<int> c(D);
  for (int i = 0; i < D; i++) cin >> p.at(i) >> c.at(i);
  
  int ans = 1e9;
  for (int mask = 0; mask < (1 << D); mask++) {
    int s = 0, num = 0, rest_max = -1;
    for (int i = 0; i < D; i++) {
      if (mask >> i & 1) {
        s += 100 * (i + 1) * p.at(i) + c.at(i);
        num += p.at(i);
      }
      else {
        rest_max = i;
      }
    }
    if (s < G) {
      int s1 = 100 * (rest_max + 1);
      int need = (G - s + s1 - 1) / s1;
      if (need >= p.at(rest_max)) {
        continue;
      }
      num += need;
    }
    ans = min(ans, num);
  }
  cout << ans << endl;
}

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

int main()
{
    int n,m,k;
    scanf("%d%d%d",&n,&m,&k);
    int cnt=0;
    while(cnt<1e6){
        if(n%2||m%2||k%2)break;
        cnt++;
        int a=(m+k)/2;
        int b=(n+k)/2;
        int c=(m+n)/2;
        n=a,m=b,k=c;
    }
    if(cnt>=1e6){
        puts("-1");
    }else{
        cout<<cnt<<endl;
    }

    return 0;
}


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

inline int read()
{
	int x = 0, f = 1; char ch = getchar();
	for (; ch < '0' || ch > '9'; ch = getchar()) if (ch == '-') f = -1;
	for (; ch >= '0' && ch <= '9'; ch = getchar()) x = (x << 1) + (x << 3) + ch - '0';
	return x * f;
}

const int N = 305;
int l[N], p[N], f[N][N][N];

int main()
{
	int n = read(), c = read();
	for (int i = 1; i <= n; ++i) l[i] = read();
	sort(l + 1, l + n + 1);
	for (int i = 1; i < n; ++i) p[i] = i;
	
	double ans = 0.0;
	while (1)
	{
		memset(f, 0, sizeof(f));
		f[0][l[n] * n][0] = 1;
		
		for (int i = 1; i < n * c; ++i)
			for (int j = i; j <= n * c; ++j)
				for (int S = 0; S < (1 << (n - 1)); ++S)
				{
					f[i][j][S] += f[i - 1][j][S];
					
					int x = i % n;
					if (!x || ((1 << (x - 1)) & S)) continue;
					
					int nj = min(n * c, max(j, i + l[p[x]] * n));
					int nS = (S | (1 << (x - 1)));
					f[i][nj][nS] += f[i - 1][j][S];
				}
		
		ans += f[n * c - 1][n * c][(1 << (n - 1)) - 1];
		if (!next_permutation(p + 1, p + n)) break;
	}
	
	for (int i = 1; i < n; ++i) ans /= (i * c);
	
	printf("%.12f\n", ans);
	return 0;
}


Measured memory_bytes: 114564
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
struct S{
  int mx, my, cx, cy;
};

int main(){
  int w, h;
  while(cin>>w>>h && w){
    int d[8][8];
    int mx, my, cx, cy;
    REP(y, h)REP(x, w){
      cin>>d[y][x];
      if(d[y][x] == 2) cx = x, cy = y;
      if(d[y][x] == 4) mx = x, my = y;
    }
    int dist[8][8][8][8] = {};
    memset(dist, -1, sizeof(dist));
    dist[mx][my][cx][cy] = 0;
    queue<S> que;
    que.push((S){mx,my,cx,cy});
    int dx[4] = {1,0,-1,0};
    int dy[4] = {0,1,0,-1};
    int ans = INF;
    while(!que.empty()){
      const S s = que.front(); que.pop();
      int now = dist[s.mx][s.my][s.cx][s.cy];
      if(d[s.cy][s.cx] == 3){
        ans = min(ans, now);
      }
      REP(r, 4){
        int nx = s.mx + dx[r];
        int ny = s.my + dy[r];
        if(nx >= 0 && ny >= 0 && nx < w && ny < h && d[ny][nx] != 1){
          if(nx == s.cx && ny == s.cy){
            int ncx = s.cx + dx[r];
            int ncy = s.cy + dy[r];
            if(ncx >= 0 && ncy >= 0 && ncx < w && ncy < h && d[ncy][ncx] != 1){
              int& next = dist[nx][ny][ncx][ncy];
              if(next == -1 || next > now + 1){
                next = now + 1;
                que.push((S){nx, ny, ncx, ncy});
              }
            }
          }else{
            int& next = dist[nx][ny][s.cx][s.cy];
            if(next == -1 || next > now){
              next = now;
              que.push((S){nx, ny, s.cx, s.cy});
            }
          }
        }
      }
    }
    if(ans >= INF) ans = -1;
OUTPUT: cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
//________
#define pb push_back
#define fi first
#define se second
#define ALL(x) x.begin(),x.end()
#define rep(i,n) for(int i=0; i<(n); ++i)
#define reps(i,f,n) for(int i=(f); i<=(n); ++i)
#define err(...) fprintf(stderr, __VA_ARGS__ )
#define show(x) cerr << #x << ':' << (x) << endl
#define outl(x) cout << (x) << '\n'
#define FAST() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef pair<int,int> pii;
template<class A, class B>inline bool chmax(A &a, B b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, B b){return b<a ? a=b,1 : 0;}
inline bool inside(int y, int x, int H, int W){return(y>=0 && x>=0 && y<H && x<W);}
const int dx[] = {1, 0, -1, 0,  1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1,  -1, 1, 1, -1};
#define INF  0x3f3f3f3f
#define LINF 0x3f3f3f3f3f3f3f3f
#define NIL -1
//________

int N;
pii p[100005];
int t[100005];

signed main()
{
   FAST();
   cin >> N;
   rep(i, N){
      cin >> t[i] >> p[i].fi >> p[i].se;
   }

   int x = 0, y = 0;
   bool f = true;

   int far = abs(p[0].fi - x) + abs(p[0].se - y);
   int sum = t[0];

   // err( "[%d] sum:%d far:%d\n", 0, sum, far);
   f = ( sum >= far && (sum % 2 ) == (far % 2) );

   for(int i=1; i<N; ++i){
      far = abs(p[i].fi - p[i-1].fi) + abs(p[i].se - p[i-1].se);
      sum = t[i] - t[i-1];
      // err( "[%d] sum:%d far:%d\n", i, sum, far);
      if( sum >= far && (sum % 2) == (far % 2) ){
         // x = p[i].fi;
         // y = p[i].se;
         continue;
      }
      else {
         f = false;
         break;
      }
   }

   outl( f ? "Yes" : "No" );
}



Measured memory_bytes: 1408
#include<bits/stdc++.h>
#define ll long long
#define ld long double
#define db double
#define pint pair<int,int>
#define mk(x,y) make_pair(x,y)
#define pb(x) push_back(x)
#define eb(x,y) emplace_back(x,y)
#define fi first
#define se second
#define Rep(x,y,z) for(int x=y;x<=z;x++)
#define Red(x,y,z) for(int x=y;x>=z;x--)
using namespace std;
const int MAXN=1e7+5,Mod=1e9+7;
char buf[1<<12],*pp1=buf,*pp2=buf,nc;int ny;
inline char gc() {return pp1==pp2&&(pp2=(pp1=buf)+fread(buf,1,1<<12,stdin),pp1==pp2)?EOF:*pp1++;}
//inline char gc(){return getchar();}
inline int read(){
	int x=0;for(ny=1;nc=gc(),(nc<48||nc>57)&&nc!=EOF;)if(nc==45)ny=-1;if(nc<0)return nc;
	for(x=nc-48;nc=gc(),47<nc&&nc<58&&nc!=EOF;x=(x<<3)+(x<<1)+(nc^48));return x*ny;
}
int n,A,ans,Fac[MAXN],iFac[MAXN],inv[MAXN];
inline int Fp(int x,int k){int ans=1;for(;k;k>>=1,x=1ll*x*x%Mod)if(k&1)ans=1ll*ans*x%Mod;return ans;}
inline int C(int n,int m){return n<0||m<0||n<m?0:1ll*Fac[n]*iFac[n-m]%Mod*iFac[m]%Mod;}
inline int Solve(int a,int b,int c){return 1ll*Fac[a+b+c]*inv[a+b]%Mod*a%Mod;}
inline void Init(){
	inv[1]=1;Rep(i,2,n)inv[i]=1ll*inv[Mod%i]*(Mod-Mod/i)%Mod;
	Fac[0]=1;Rep(i,1,n)Fac[i]=1ll*Fac[i-1]*i%Mod;
	iFac[n]=Fp(Fac[n],Mod-2);Red(i,n,1)iFac[i-1]=1ll*iFac[i]*i%Mod;
}
int main(){
//	freopen("std.in","r",stdin);
//	freopen("std.out","w",stdout);
	n=read(),A=read(),Init();
	Rep(i,1,A)Rep(j,1,i)ans=(ans+1ll*(((i-j)&1)?Mod-C(i,j):C(i,j))*Solve(j,n-A,max(0,A-i-1)))%Mod;
	cout<<ans<<'\n';
	return 0;
}




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

using namespace std;

const int N = 4e5 + 10;

int n, a[N], b[N];

bool check(int val) {
  for (int i = 1; i <= n * 2 - 1; i++) {
    b[i] = (a[i] >= val);
  }
  for (int i = 0; i < n; i++) {
    if (b[n + i] == b[n + i + 1]) return b[n + i];
    if (b[n - i] == b[n - i - 1]) return b[n - i];
  }
  return b[1];
}

int main() {
  scanf("%d", &n);
  for (int i = 1; i <= n * 2 - 1; i++) {
    scanf("%d", &a[i]);
  }
  int l = 1, r = n * 2 - 1, res = 1;
  while (l <= r) {
    int mid = (l + r) >> 1;
    if (check(mid)) {
      l = mid + 1;
      res = mid;
    } else {
      r = mid - 1;
    }
  }
  printf("%d\n", res);
  return 0;
}

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


int main(){
  char x;
  int a=0, b=0, c=0;
  for(int i = 0; i < 3;i++){
    cin >> x;
    if(x == 'a'){
      a++;
    }else if(x == 'b'){
      b++;
    }else if(x == 'c'){
      c++;
    }
  }

  if(a == 1 && b == 1 && c == 1){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
def Write_and_Erase():

    numbers = []
    try:
        LOCAL_FLAG
        N = 3
        numbers = [6, 2, 6]
        # N = 4
        # numbers = [2, 5, 5, 2]
        N = 6
        numbers = [12, 22, 16, 22, 18, 12]

    except NameError:
        N = int(input())
        for i in range(N):
            numbers.append(int(input()))

    onPaper = set([numbers[0]])
    for i in range(1, N):
        if numbers[i] in onPaper:
            onPaper.remove(numbers[i])
        else:
            onPaper.add(numbers[i])

    # print(onPaper)
    print(len(onPaper))


Write_and_Erase()

Measured memory_bytes: 13204
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int a,b,c,d,e,k;
  cin>>a>>b>>c>>d>>e>>k;
  cout<<(e-a>k?":(":"Yay!");
}

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

#define debug(...)   printf( __VA_ARGS__ )
//#define debug(...)   /****nothing****/

#define ll long long
#define ull unsigned long long
#define pb push_back
#define mem(arr,val)    memset(arr,val,sizeof(arr))
#define mp make_pair
#define pii pair<int,int>
#define F first
#define S second
#define sz(x) (int)(x).size()
#define nopos string::npos
#define fr(i,a,b) for(i=a;i<=b;i++)
#define frn(i,a,b) for(i=a;i>=b;i--)

char a,b;
int main()
{
    //freopen("d://i.txt","r",stdin);
    //freopen("d://o.txt","w",stdout);
    cin>>a>>b;
    if(a=='D')
        printf("%c\n",(b=='H')?'D':'H');
    else
        cout<<b<<'\n';



    return 0;
}





Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  long N;cin>>N;
  vector<pair<long,long>>XL(N);
  for(long i=0;i<N;i++)cin>>XL[i].first>>XL[i].second;
  vector<pair<long,long>>RL(N);
  for(long i=0;i<N;i++){
    RL[i].first=XL[i].first+XL[i].second;
    RL[i].second=XL[i].first-XL[i].second;
  }
  sort(RL.begin(),RL.end());//右でソート
  long C=1;long L=RL[0].first;
  for(long i=1;i<N;i++){
    if(RL[i].second<L){//ぶつかるなら使わない
      
    }
    else {//ぶつからないなら使う
      C++;
      L=RL[i].first;
    }
  }
  cout<<C; 
}

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


int main(void) {
  ll n;
  cin >> n;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
  }

  // 0スタートで
  // 偶数番目が正
  ll ans1 = 0;
  ll sum = 0;
  rep(i, n) {
    sum += a[i];
    if (i % 2 == 0) {
      if (sum <= 0) {
        ans1 += 1 - sum;
        sum = 1;
      }
    } else {
      if (sum >= 0) {
        ans1 += 1 + sum;
        sum = -1; 
      }
    }
  }

  // 奇数番目が正
  ll ans2 = 0;
  sum = 0;
  rep(i, n) {
    sum += a[i];
    if (i % 2 != 0) {
      if (sum <= 0) {
        ans2 += 1 - sum;
        sum = 1;
      }
    } else {
      if (sum >= 0) {
        ans2 += 1 + sum;
        sum = -1; 
      }
    }
  }

  cout << min(ans1, ans2) << endl;
  
  return 0;
}

Measured memory_bytes: 4052
from collections import Counter

N = int(input())
A = [int(_) for _ in input().split()]

counter = Counter(A)

ans = 0
dic = {}
for k, v in counter.items():
    ans += v * (v - 1) // 2
    dic[k] = v * (v - 1) // 2
# print(dic)
# print(ans)
for i, a in enumerate(A):
    tmp = counter[a]
    tmp_2 = dic[a]
    print(ans - tmp_2 + (tmp - 1) * (tmp - 2) // 2)


Measured memory_bytes: 32284
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		int A, B, C, K;
		cin >> A >> B >> C >> K;

		if( A >= K ) {
			cout << K << endl;
		}
		else if( A+B >= K ) {
			cout << A << endl;
		}
		else {
			cout << A - (K - A - B) << endl;
		}
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3616
#include <climits>
#include <cmath>
#include <cstdlib>
#include <iostream>
#include <vector>
using namespace std;

constexpr int MAX_N = 10;

int dist, n, max_bound;
double p[MAX_N], h[MAX_N];

constexpr double EPS = 1e-8;

vector<double> solve_quadratic_equation(double a, double b, double c) {
	if(abs(a) <= EPS) {
		if(abs(b) <= EPS) {
			if(abs(c) <= EPS) return {0};
			return {};
		}
		return {-c / b};
	}

	const double d = b * b - 4 * a * c;
	if(d < 0) return {};

	return {(-b - sqrt(d)) / (2 * a), (-b + sqrt(d)) / (2 * a)};
}

double calc_y(double vx, double vy, double x) {
	return - (1.0 / (2.0 * vx * vx)) * (x * x) + (vy / vx) * x;
}

double calc_vx(double x, double y, double theta) {
	const double a = (x * sin(theta) / cos(theta) - y);
	const double b = 0.0;
	const double c = - x * x / 2.0;

	double res = 0.0;
	for(const auto &e : solve_quadratic_equation(a, b, c)) {
		if(e > 0.0) {
			res = e;
			break;
		}
	}

	return res;
}

double calc_vy(double vx, double theta) {
	return vx * sin(theta) / cos(theta);
}

bool check(int bound, double theta) {
	const double jump_dist = dist / (bound + 1.0);
	const double vx = calc_vx(jump_dist, 0, theta);
	const double vy = calc_vy(vx, theta);

	for(int i = 0; i < n; ++i) {
		double s = 0.0;
		while(s + jump_dist + EPS < p[i]) {
			s += jump_dist;
		}

		if(calc_y(vx, vy, p[i] - s) + EPS < h[i]) return false;
	}
	
	return true;
}

int main() {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	cout.setf(ios::fixed);
	cout.precision(10);

	cin >> dist >> n >> max_bound;

	for(int i = 0; i < n; ++i) {
		cin >> p[i] >> h[i];
	}

	double ans = INT_MAX;
	for(int bound = 0; bound <= max_bound; ++bound) {
		double L = M_PI / 4.0, R = M_PI / 2.0;

		for(int i = 0; i < 100; ++i) {
			const double M = (L + R) / 2;

			if(check(bound, M)) {
				R = M;
			}
			else {
				L = M;
			}
		}

		const double vx = calc_vx(dist / (bound + 1.0), 0, L);
		const double vy = calc_vy(vx, L);
		ans = min(ans, vx * vx + vy * vy);
	}

	cout << sqrt(ans) << endl;

	return EXIT_SUCCESS;
}

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

int main(){
  int K;
  cin >> K;
  
  const int nums[] = {
    1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14,
    1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51
  };
  cout << nums[K-1];
  return 0;
}

Measured memory_bytes: 3576
#include <stdio.h>
#include <stdlib.h>

int main(void)
{
    int *a;
    int n, min, max;
    long long int sum = 0;
    int i;
    
    scanf("%d", &n);
    
    a = (int *) malloc(sizeof(int)*n);
    
    for(i=0; i<n; i++){
        scanf("%d", &a[i]);
    }
    
    min = a[0];
    max = a[0];
    sum = a[0];
    
    for(i=1; i<n; i++){
        if(min>a[i]){
            min = a[i];
        }
        if(max<a[i]){
            max = a[i];
        }
        sum += a[i];
    }
    
    printf("%d %d %lld\n", min, max, sum);

    free(a);
    
    return 0;
}

Measured memory_bytes: 636
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#ifndef ONLINE_JUDGE
#define show(a) cout<<""#a""<<" is "<<a<<endl;
#define shw(a,b)cout<<"-->"<<a<<" "<<b<<endl;
#define print(arr,xx)for(int i=0;i<xx;i++)cout<<arr[i]<<" \n"[i==xx-1];
#define here cout<<"here\n";
#define fastio ;
#else
#define show(a)  ;
#define shw(a,b) ;
#define print(arr,xx) ;
#define here
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#endif
int caseno = 0;
#define print_case cout<<"Case "<<++caseno<<": ";
#define fout freopen("output.txt","w",stdout);
#define fin freopen("input.txt","r",stdin);
#define pb push_back
#define pi acos(-1.0)
typedef long long ll;
typedef pair<ll, ll> pll;
typedef vector<vector<int> > vii;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
void yesno(bool okk) {cout << (okk ? "YES" : "NO") << endl;}
const int primemod = 1000000007;
#define max(a, b) ((a) > (b) ? (a) : (b))
#define min(a, b) ((a) < (b) ? (a) : (b))
const ll maxsize = 1 * 1000000 + 9;
#define fi first
#define se second
#define inf 1<<25
const double eps = 1e-10;
const int N = 210;
ll n, k, b, m, y;
#define ass(XX) (if(!XX){cout<<-1<<endl;return;})

void solve() {
	cin >> n;
	std::vector<int> v(n);
	int xr = 0;
	for (int i = 0; i < n; i++) {
		cin >> v[i];
		xr = xr ^ v[i];
	}
	rep(i, 0, n) {
		cout << (xr ^ v[i]) << " ";
	}
	cout<<endl;
}

int main() {
#ifndef ONLINE_JUDGE
	fin
	fout
#endif
	///-----
	fastio
	int T;
	T = 1;
	// cin >> T;
	while (T--) {
		// yesno(solve());
		solve();
	}
	///-----
	return 0 ;
}


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

int main(){
    ll n, k; cin >> n >> k;
    ll waru = n/k;
    ll ans = n - waru*k;

    ans = min(ans, abs(ans-k));

    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Welcome_to_AtCoder
{
    class Program
    {
        static void Main()
        {
            string[] input = Console.ReadLine().Split(' ');
            int n = int.Parse(input[0]);
            int k = int.Parse(input[1]);
            string[] bc = Console.ReadLine().Split(' ');
            Array.Sort(bc,Comp);
            int maxlen = 0;
            for(int i=n; i>n-k;i--)
            {
                maxlen += int.Parse(bc[i-1]);
            }

            Console.WriteLine(maxlen);
        }

        public static int Comp(string x, string y)
        {
            return int.Parse(x)-int.Parse(y);
        }
    }
}

Measured memory_bytes: 11092
class UnionFind():
    def __init__(self,n):
        self.n=n
        self.root=[-1]*n
        self.rank=[-1]*n

    def Find_Root(self,x):
        if self.root[x]<0:return x
        else:
            self.root[x]=self.Find_Root(self.root[x])
            return self.root[x]

    def Unite(self,x,y):
        x=self.Find_Root(x)
        y=self.Find_Root(y)

        if x==y:return
        elif self.rank[x]>self.rank[y]:
            self.root[x] +=self.root[y]
            self.root[y]=x
        else:
            self.root[y] +=self.root[x]
            self.root[x]=y
            if self.rank[x]==self.rank[y]:
                self.rank[y] +=1

    def isSameGroup(self,x,y):
        return self.Find_Root(x)==self.Find_Root(y)

    def size(self,x):
        return -self.root[self.Find_Root(x)]

    def members(self,x):
        root=self.Find_Root(x)
        return [i for i in range(self.n) if self.Find_Root(i)==root]

    def roots(self):
        return[i for i,j in enumerate(self.root) if j<0]

    def group_members(self):
        return {i:self.members(i) for i in self.roots()}

    def group_count(self):
        return len(self.roots())


n,m=map(int,input().split())
AB=[list(map(int,input().split())) for _ in range(m)]

ans=[n*(n-1)//2]
UnionFind=UnionFind(n+1)
for a,b in AB[::-1]:
    if UnionFind.isSameGroup(a,b):ans.append(ans[-1])
    else:ans.append(ans[-1]-UnionFind.size(a)*UnionFind.size(b))
    UnionFind.Unite(a,b)

for i in ans[::-1][1:]:
    print(i)

Measured memory_bytes: 116952
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

use std::cmp;

fn main() {
    input! {
        n: i32,
        s: String,
    }
    let mut count = 0;
    let ans = s.chars().fold(0, |m, c| {
            if c == 'D' { count -= 1 } 
            if c == 'I' { count += 1 }
            cmp::max(count, m)
            
    });

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


Measured memory_bytes: 4352
import Control.Monad

main :: IO ()
main = do
  s1 <- getLine
  if s1 == "0"
    then return ()
    else do
      s23 <- replicateM 2 getLine
      let ls = s1:s23
          ans = solve ls
      putStrLn ans
      main

solve :: [String] -> String
solve ls
  |solve' ls == 1 = "b"
  |solve' ls == 2 = "w"
  |otherwise = "NA"
  where
    solve' :: [String] -> Int
    solve' ls = max (max (rowC ls) (colC ls)) (slaC ls)
      where
        rowC :: [String] -> Int
        rowC ls = maximum (map check ls)
          where
            check :: String -> Int
            check s
              | s == "bbb" = 1
              | s == "www" = 2
              | otherwise = 0
        colC :: [String] -> Int
        colC ls = rowC (spin ls)
          where
            spin :: [String] -> [String]
            spin [[],[],[]] = []
            spin [(x:xs),(y:ys),(z:zs)] = [x,y,z]:(spin [xs,ys,zs])
        slaC :: [String] -> Int
        slaC ls = rowC (sla ls)
          where
            sla :: [String] -> [String]
            sla [s1,s2,s3] = [(head s1):(head (tail s2)):[last s3], (head s3):(head (tail s2)):[last s1]]

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

using namespace std;

#define MOD 1000000007
#define PI 3.1415926535897932384626433832795
#define INF (int)1e9
typedef long long int int64;

void print() {
    cout << endl;
}

void print(const char* s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(string s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(int64 s, bool endline = true) {
    cout << s;
    if (endline) print();
}

void print(int s, bool endline = true) {
    cout << s;
    if (endline) print();
}

template <typename T, typename T2>
void print(pair<T, T2>& p, bool endline = true) {
    cout << "(";
    print(p.first, false);
    cout << ", ";
    print(p.second, false);
    cout << ")";

    if (endline) print();
}

template <typename T>
void print(T& t, bool endline = true) {
    cout << "[";
    for (auto it = t.begin(); it != t.end(); ++it) {
        if (it != t.begin()) cout << ", ";
        print(*it, false);
    }
    cout << "]";

    if(endline) print();
}

template <typename T>
vector<T> operator+(const vector<T> &a, const vector<T> &b)
{
    vector<T> ret;
    ret.reserve( a.size() + b.size() );                // preallocate memory
    ret.insert( ret.end(), a.begin(), a.end() );        // add A;
    ret.insert( ret.end(), b.begin(), b.end() );        // add B;

    return ret;
}

template <typename T>
vector<T> &operator+=(vector<T> &a, const vector<T> &b)
{
    a.reserve( a.size() + b.size() );                // preallocate memory without erase original data
    a.insert( a.end(), b.begin(), b.end() );         // add B;
    return a;
}

bool c(const pair<int,int> &a, const pair<int,int> &b) 
{ 
    return (a.first + a.second > b.first + b.second); 
} 

int main() {
    // g++ -Wall -Wextra -O2 -std=c++17 helloworld.cpp
    int64 n, k;
    cin >> n >> k;

    if(k == 0) {
        print(n * n);
        return 0;
    }

    int64 ret = 0LL;

    for(int64 i = 0LL; i <= n; ++i) {
        if(i >= k) {
            int64 p = n / i;
            int64 r = n % i;

            ret += max(0LL, p * (i - k));
            ret += max(0LL, (r - k + 1));
        }
    }

    print(ret);

    return 0;
}

Measured memory_bytes: 256
from sys import stdin, setrecursionlimit
from collections import defaultdict
from math import gcd

setrecursionlimit(10 ** 9)
INF = 1 << 60


def input():
    return stdin.readline().strip()


MOD = 1000000007
N = int(input())
d = defaultdict(int)
zeros = 0
for i in range(N):
    a, b = map(int, input().split())
    if a == 0 and b == 0:
        zeros += 1
    else:
        g = gcd(a, b)
        a //= g
        b //= g
        if a < 0:
            a *= -1
            b *= -1
        if a == 0 and b == -1:
            b = 1
        d[(a, b)] += 1

ans = 1
free = 0
keys = sorted(d.keys())
for a, b in keys:
    n = d[(a, b)]
    if b > 0:
        if (b, -a) in d:
            m = d[(b, -a)]
            ans = ans * (pow(2, n, MOD) + pow(2, m, MOD) - 1) % MOD
        else:
            free += n
    else:
        if (-b, a) not in d:
            free += n

ans = (ans * pow(2, free, MOD) + zeros - 1) % MOD
print(ans)


Measured memory_bytes: 50176
// Author : MohamedSameh
#include <bits/stdc++.h>
typedef long long ll ;
#define pb push_back
#define f first
#define s second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define SZ(a) (int)a.size()
#define IN(n) scanf("%d" , &n )
void fo (){fflush(stdout);}
using namespace std;
ll fact (int x ){return (x <= 1 ? 1 : 1LL * x * fact (x-1));}
int n , ans [100000] , ps[][2] = {{1,1} , {1,0} , {0,1} , {0,0}};
string x ;
bool check ()
{
  for (int i =0 ; i < n ;i++)
  {
    int prv = (i - 1 + n )%n ;
    int nex = (i + 1 )%n ;

    if (ans[i] == 1 )
    {
      if (x[i] == 'o')
      {
        if (ans[prv] != ans[nex])return false ;
      }else
      {
        if (ans[prv] == ans[nex])return false ;
      }
    }else
    {
      if (x[i] == 'o')
      {
        if (ans[prv] == ans[nex])return false ;
      }else
      {
        if (ans[prv] != ans[nex])return false ;
      }

    }
  }
  return true ;
}
int main ()
{
cin >> n >> x ;
for (int p =0 ; p < 4 ; p++)
{
  ans[0] = ps[p][0];
  ans[1] = ps[p][1];
  for (int i = 1 ; i < n ;i++)
  {
    // 1 S
    // 0 W
    int prv = (i -1 + n )% n ;
    int nex = (i + 1 )%n ;
    if (ans[i] == 1 )
    {
      if (x[i] == 'o')
      {
      ans[nex] = ans[prv] ;
      }else
      {
      ans[nex] = abs (ans[prv] - 1);
      }

    }else
    {
      if (x[i] == 'o')
      {
        ans[nex] = abs (ans[prv] - 1);
      }else
      {
        ans[nex] = ans[prv] ;
      }
    }
  }
  if (check())
  {
    for (int i =0 ; i < n ;i++)
    if (ans[i])printf ("S");
    else
    printf("W");
    printf("\n");
    return 0 ;
  }
}
printf("-1\n");
  cerr << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
  return 0;
}


Measured memory_bytes: 896
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author alireza_kaviani
 */

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>

using namespace std;
using namespace __gnu_pbds;

template<class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

#define all(x)                      (x).begin(),(x).end()
#define Sort(x)                     sort(all((x)))
#define X                           first
#define Y                           second
#define Mp                          make_pair
#define sep                         ' '
#define endl                        '\n'
#define debug(x)                    cerr << #x << " = " << x << endl
#define SZ(x)                       ll(x.size())
#define fast_io                     ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define set_random                  mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

ll poww(ll a, ll b, ll md) {
    return (!b ? 1 : (b & 1 ? a * poww(a * a % md, b / 2, md) % md : poww(a * a % md, b / 2, md) % md));
}

const ll MAXN = 1e6 + 10;
const ll LOG = 22;
const ll INF = 8e18;
const ll MOD = 1e9 + 7; // 998244353; // 1e9 + 9;

ll l, t;
vector<pair<pll, ll>> E;

int main() {
    fast_io;

    cin >> l;
    cout << 20 << sep;

    for (ll i = 2; i < 20; i++) E.push_back({{i, i + 1}, 0}), E.push_back({{i, i + 1}, (1LL << (19 - i))});

    for (ll i = 0; i < 19; i++) {
        if (l & (1LL << i)) E.push_back({{1, 20 - i}, t}), t += (1LL << i);
    }
    if (l & (1LL << 19)) E.push_back({{1, 2}, t}), E.push_back({{1, 2}, t + (1LL << 18)});

    cout << E.size() << endl;
    for (pair<pll, ll> i : E) cout << i.X.X << sep << i.X.Y << sep << i.Y << endl;

    return 0;
}
/*

*/


Measured memory_bytes: 256
from collections import Counter
N = int(input())
anslist = set([])
A = list(map(int, input().split()))
Amax = max(A)
for i in A:
    j = i*2
    while j <= Amax:
        anslist.add(j)
        j += i

anslist = list(anslist)
anslist.extend(A)
anslist = Counter(anslist)

A = Counter(A)
cnt=0
for  k,v in A.items():
    if v!=1:
        del anslist[k]
    else:
        cnt+=1

ans = Counter(anslist.values())
print(cnt-ans[2])

Measured memory_bytes: 138804
#include <stdio.h>
int main(){
  int N,M;
  scanf("%d %d",&N,&M);
  int i,j;
  int K=0;
  int wa[30]={};
  for(i=0; i<N; i++){
    scanf("%d",&K);
    for(j=0; j<K; j++){
      int num=0;
      scanf("%d",&num);
      wa[num-1]++;
    }
  }
  int count=0;
  for(i=0; i<M; i++){
    if(wa[i]==N)
      count++;
  }
  printf("%d\n",count);

  return 0;
}


Measured memory_bytes: 128
#include <stdio.h>  
#include <algorithm>  
#include <assert.h>
#include <bitset>
#include <cmath>  
#include <complex>  
#include <deque>  
#include <functional>  
#include <iostream>  
#include <limits.h>  
#include <map>  
#include <math.h>  
#include <queue>  
#include <set>  
#include <stdlib.h>  
#include <string.h>  
#include <string>  
#include <time.h>  
#include <unordered_map>  
#include <unordered_set>  
#include <vector>

#pragma warning(disable:4996)  
#pragma comment(linker, "/STACK:336777216")  
using namespace std;

#define mp make_pair  
#define Fi first  
#define Se second  
#define pb(x) push_back(x)  
#define szz(x) ((int)(x).size())  
#define rep(i, n) for(int i=0;i<n;i++)  
#define all(x) (x).begin(), (x).end()  
#define ldb ldouble  

typedef tuple<int, int, int> t3;
typedef long long ll;
typedef unsigned long long ull;
typedef double db;
typedef long double ldb;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef pair <ll, int> pli;
typedef pair <db, db> pdd;

int IT_MAX = 1 << 17;
const ll MOD = 1000000007;
const int INF = 0x3f3f3f3f;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
const db PI = acos(-1);
const db ERR = 1e-10;

map <int, int> Mx;
int main() {
	int N, i;
	scanf("%d", &N);
	for (i = 1; i <= N; i++) {
		int t;
		scanf("%d", &t);
		Mx[t]++;
		Mx[t - 1]++;
		Mx[t + 1]++;
	}
	int ans = 0;
	for (auto it : Mx) ans = max(ans, it.second);
	return !printf("%d\n", ans);
}

Measured memory_bytes: 4736
#include <stdio.h>

int main(void)
{
	int a, b, c;
	scanf("%d %d %d", &a, &b, &c);
	if(a<=b&&b<=c)
	{
		printf("%d %d %d\n", a, b, c);
	}
	else if(a<=b&&b<=c)
	{
		printf("%d %d %d\n", a, c, b);
	}
	else if(b<=a&&a<=c)
	{
		printf("%d %d %d\n", b, a, c);
	}
	else if(b<=c&&c<=a)
	{
		printf("%d %d %d\n", b, c, a);
	}
	else if(c<=a&&a<=b)
	{
		printf("%d %d %d\n", c, a, b);
	}
	else if(c<=b&&b<=a)
	{
		printf("%d %d %d\n", c, b, a);
	}
	return 0;
}


Measured memory_bytes: 2724
import java.io.*;
import java.util.*;

public class Main {

	final static long MOD = 1000000007;
	public static String[] Ws = null;
	public static int wsIndx = 0;
	public static BufferedReader in = null;
	public static void main(String[] args) throws Exception {
		solution(args);
		if(in!=null){
			in.close();
		}
	}

	public static void solution(String[] args) throws Exception{

		int N = nextInt();
		int A = nextInt();
		long ans;
		N=N%500;


		System.out.println(N<=A?"Yes":"No");

	}
	public static String[] toStringArray(String s) {
		String[] tmp = new String[s.length()];
		char[] c = s.toCharArray();
		for (int i = 0; i < tmp.length; i++) {
			tmp[i] = String.valueOf(c[i]);
		}
		return tmp;
	}

	public static void check() throws Exception{
		if(in == null){
			in = new BufferedReader(new InputStreamReader(System.in));
		}
		if(Ws==null || Ws.length<=wsIndx){
			Ws = in.readLine().split(" ");
			wsIndx=0;
		}
	}
	public static int nextInt()throws Exception{
		check();
		return Integer.parseInt(Ws[wsIndx++]);
	}

	public static long nextLong()throws Exception{
		check();
		return Long.parseLong(Ws[wsIndx++]);
	}

	public static String nextString()throws Exception{
		check();
		return Ws[wsIndx++];
	}

	public static int[] nextInts()throws Exception{
		check();
		int[] tmp = new int[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Integer.parseInt(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static long[] nextLongs()throws Exception{
		check();
		long[] tmp = new long[Ws.length];
		for(int i=0;i<tmp.length;i++){
			tmp[i]=Long.parseLong(Ws[i]);
		}
		wsIndx=Ws.length;
		return tmp;
	}

	public static String[] nextStrings()throws Exception{
		check();
		wsIndx=Ws.length;
		return Ws;
	}


}


Measured memory_bytes: 21204
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;
import java.io.IOException;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.io.InputStream;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        TaskC solver = new TaskC();
        solver.solve(1, in, out);
        out.close();
    }

    static class TaskC {
        public void solve(int testNumber, InputReader in, PrintWriter out) {
            int n = in.nextInt();
            int t = in.nextInt();
            int[] times = new int[n];
            int ans = t;

            if (n == 1) {
                out.println(t);
                return;
            }
            for (int i = 0; i < n; i++) {
                times[i] = in.nextInt();
            }
            for (int i = 1; i < n; i++) {
                int diff = times[i] - times[i - 1];
                if (diff >= t) {
                    ans += t;
                } else {
                    ans += diff;
                }
            }
            out.println(ans);
        }

    }

    static class InputReader {
        public BufferedReader reader;
        public StringTokenizer tokenizer;

        public InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream), 32768);
            tokenizer = null;
        }

        public String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        public int nextInt() {
            return Integer.parseInt(next());
        }

    }
}



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

int H, W, HS, WS;
#define BIG 4000

int main() {
  cin >> H >> W >> HS >> WS;
  if(H % HS == 0 && W % WS == 0) cout << "No" << endl;
  else {
    cout << "Yes" << endl;
    for(int i = 0; i < H; ++i) {
      for(int j = 0; j < W; ++j) {
        cout << (j == 0 ? "" : " ")
          << (i % HS == HS - 1 && j % WS == WS - 1 ? BIG - 1 - BIG * HS * WS : BIG);
      }
      cout << endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1536
#include<bits/stdc++.h>
using namespace std;
int main(){
  long long int n;
  long long int ans=1;
  cin >>n;
for(long long int i=2;i<=n;i++){
  bool ok=true;
  for(long long int j=2;j<=pow(i,0.5);j++){
    if(i%j==0)ok=false;
  }
  if(ok){
    long long int count=0;
    for(long long int j=2;j<=n;j++){
      long long int s=j;
      while(s%i==0){
        s/=i;
      count++;
      }
    }
    ans=ans*(count+1)%((long long int)1E9+7);
  }
  cerr<<ans<<endl;
}
  cout <<ans <<endl;
}

Measured memory_bytes: 256
n=int(input())
a=[0]*n
sa=0
for i in range(1,n+1):
    if i%15==0:
        a[i-1]="FizzBuzz"
    elif i%3==0:
        a[i-1]="Fizz"
    elif i%5==0:
        a[i-1]="Buzz"
    else:
        a[i-1]=str(i)
        sa+=i
print(sa)

Measured memory_bytes: 140424
#include <algorithm>
#include <string>
#include <iostream>

using namespace std;

int main() {
    string s, t;
    cin >> s >> t;

    sort(s.begin(), s.end());
    sort(t.begin(), t.end(), greater<char>());

    for (int i = 0; i < min(s.length(), t.length()); i++) {
        if (s[i] < t[i]) {
            cout << "Yes" << endl;
            return 0;
        } else if (s[i] > t[i]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << (s.length() < t.length() ? "Yes" : "No") << endl;

    return 0;
};


Measured memory_bytes: 256
#include <stdio.h>


 
int main(){
  int n,i,j,count=0,max=0;
  scanf("%d",&n);
  char s[n];
  scanf("%s",s);
  
  int left[26]={0},right[26]={0},sum[26]={0};//26はアルファベット数
  
  for(i=1;i<n;i++){
    for(j=0;j<i;j++) 
      left[s[j]-'a']=1;//一文字一要素
    for(j=i;j<n;j++) 
      right[s[j]-'a']=1;
    for(j=0;j<26;j++) 
      count += left[j]*right[j];//一致の確認
    if(max<count){
      max=count;
    }
    count=0;
    for(j=0;j<26;j++){
      left[j]=0;
      right[j]=0;//次の分割へ準備
    }
  }
  
  printf("%d",max);
  return 0;
}
/*一文字一要素として配列を作り、
前半後半の２配列の積をとることで
文字の一致を確認した。
　この問題の難所は、重複の解決法である。*/
    
  



Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5 + 1;
int n , a[N] , dp[N];
int calc(int indx){
    if(indx == n - 1)
        return 0;
    if(indx >= n)
        return 1e9 + 10;
    if(dp[indx] != -1)
    	return dp[indx];
    // try to go to i + 1
	int val1 = calc(indx + 1) + abs(a[indx] - a[indx + 1]);
	// try to go to i + 2
	int val2 =  calc(indx + 2) + abs(a[indx] - a[indx + 2]);
    return dp[indx] = min( val1 , val2 ); 
}
int main(){
    cin >> n;
    for(int i = 0 ; i < n ; i++){
        cin >> a[i];
    }
    memset(dp , -1 , sizeof dp);
    cout<<calc(0);
    return 0;
}

Measured memory_bytes: 4096