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

int main(){
    int n, k;
    cin >> n >> k;
    int d[10];
    for(int i=0; i<k; i++){
        cin >> d[i];
    }

    for(int i=n; ; i++){
        bool isok = true;
        string s = to_string(i);
        for(int j=0; j<s.size(); j++){
            for(int a=0; a<k; a++){
                if(s[j] - '0' == d[a]){
                    isok = false;
                    goto loopend;
                }
            }
        }
        loopend:
        if(isok){
            cout << i << endl;
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
// https://atcoder.jp/contests/soundhound2018-summer-qual/tasks/soundhound2018_summer_qual_d

#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <numeric>
#include <array>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pow(x) x*x
#define ll long long
static const int MAX = 100010;
static const ll INFTY = 1e18;

struct edge {
    ll to;
    ll cost;
    ll cost_s;
};
using Graph = vector<vector<edge>>;

// <最短距離, 頂点の番号>
using P = pair<ll, ll>;

ll d[MAX];
ll d_s[MAX];
ll _min[MAX];

void dijkstra(const Graph &G, ll N, ll s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d, d+N, INFTY);
    d[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if (d[v] < p.first) continue;

        for (ll i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d[e.to] > d[v] + e.cost) {
                d[e.to] = d[v] + e.cost;
                que.push(P(d[e.to], e.to));
            }
        }
    }
}

void dijkstra_s(const Graph &G, ll N, ll s) {
    priority_queue<P, vector<P>, greater<P> > que;
    fill(d_s, d_s+N, INFTY);
    d_s[s] = 0;
    que.push(P(0, s));

    while (!que.empty()) {
        P p = que.top();
        que.pop();
        ll v = p.second;
        if (d_s[v] < p.first) continue;

        for (ll i=0; i<G[v].size(); ++i) {
            edge e = G[v][i];
            if (d_s[e.to] > d_s[v] + e.cost_s) {
                d_s[e.to] = d_s[v] + e.cost_s;
                que.push(P(d_s[e.to], e.to));
            }
        }
    }
}




int main() {

    ll n, m, s, t; cin >> n >> m >> s >> t;
    s--; t--;
    Graph G(n);

    REP(i, m){
        ll u, v, a, b;
        cin >> u >> v>> a>> b;
        u--; v--;
        edge e;
        e = {v, a, b};
        G[u].push_back(e);
        e = {u, a, b};
        G[v].push_back(e);
    }

    dijkstra(G, n, s);
    dijkstra_s(G, n, t);

    ll t_min = INFTY;
    for(int i = n-1; i >=0; i--){
        ll ryogae = d[i] + d_s[i];
        if( t_min > ryogae){
            t_min = ryogae;
        }
        _min[i] = t_min;
    }

    REP(i, n){
        cout << 1000000000000000 - _min[i] << endl;
    }
 
    
}
/*
                   _ooOoo_
                  o8888888o
                  88" . "88
                  (| -_- |)
                  O\  =  /O
               ____/`---'\____
             .'  \\|     |//  `.
            /  \\|||  :  |||//  \
           /  _||||| -:- |||||-  \
           |   | \\\  -  /// |   |
           | \_|  ''\---/''  |   |
           \  .-\__  `-`  ___/-. /
         ___`. .'  /--.--\  `. . __
      ."" '<  `.___\_<|>_/___.'  >'"".
     | | :  `- \`.;`\ _ /`;.`/ - ` : | |
     \  \ `-.   \_ __\ /__ _/   .-` /  /
======`-.____`-.___\_____/___.-`____.-'======
                   `=---='
^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
         pass System Test!
*/

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

using namespace std;
using ll = long long int;
using lc = complex<double>;

int main(void) {
    constexpr ll MOD = 998244353;
    constexpr double PI = acos(-1);
    cout << fixed << setprecision(32);
    cin.tie(0); ios::sync_with_stdio(false);

    ll n, k;
    cin >> n >> k;
    vector<pair<ll,ll>> lr(k);
    for(auto &e: lr) cin >> e.first >> e.second;

    vector<ll> dp(n+1);
    dp[0] = 1, dp[1] = -1;
    for(ll i=0; i<n; i++) {
        for(auto &[l, r]: lr) {
            if(i+l<=n) dp[i+l] = (dp[i+l] + dp[i]) % MOD;
            if(i+r+1<=n) dp[i+r+1] = (MOD-dp[i] + dp[i+r+1]) % MOD;
        }
        (dp[i+1]+=dp[i]) %= MOD;
    }
    cout << dp[n-1] << endl;
}

Measured memory_bytes: 4752
#include <bits/stdc++.h>
using namespace std;
#define mod (int)1000000007
#define MOD (int)10000000007
#define X 1001100011100001111ll
#define M 26388279066623ll
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for0e(i, n) for (int i = 0; i <= n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
#define ll long long
#define pb emplace_back
#define fio ios_base::sync_with_stdio(false), cin.tie(NULL), cout.tie(NULL)
#define in(x) scanf("%d", &x)
#define rr return 0
#define prec(n) fixed<<setprecision(n)
#define maxpq priority_queue<int>
#define minpq priority_queue<int, vector<int>, greater<int> >
#define inf (int)(1e18)
#define ini(a, i) memset(a, i, sizeof(a))
#define vi vector<int> 
#define F first
#define S second
#define pi pair<int, int>
#define ppi pair<pair<int,int> , int >
#define vii vector<pi>
const int MAXN = (int)((1e5) + 100);
int max(int a,int b){if(a>b) return a; else return b;}
int min(int a,int b){if(a<b) return a; else return b;} 
int gcd(int a,int b) { if (a == 0) return b; return gcd(b%a, a);}
int cbrt(int x){ int lo=1,hi=min(2000000ll,x);while(hi-lo>1){int mid=(lo+hi)/2;if(mid*mid*mid<x){lo=mid;}else hi=mid;}if(hi*hi*hi<=x) return hi;else return lo;} 
const int dx[4] = {-1, 1, 0, 0};
const int dy[4] = {0, 0, -1, 1};
const int N =  (int)(1e6+5); 
// ========================================================
signed main(){
  #ifndef ONLINE_JUDGE
  //freopen("input.txt", "r", stdin);
  //freopen("output.txt", "w", stdout);
  #endif
  fio;
    int n;
    cin>>n;
    vector<int> h(n);
    for(auto &x : h) cin>>x;
    vector<int> dp(n);//  dp[i] = min cost to reach ith stone
    dp[0] = 0;
    dp[1] = abs(h[0] - h[1]);
    for(int i=2;i<n;i++){
        dp[i] = min(dp[i-1]+abs(h[i] - h[i-1]),dp[i-2]+abs(h[i] - h[i-2]));
    }
    cout<<dp[n-1];
  rr;
}



Measured memory_bytes: 3996
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string a,b,c;
    while(cin >> a >> b >> c)
    {
        string s;
        s+=a[0]-32;
        s+=b[0]-32;
        s+=c[0]-32;
       cout<<s<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>

using namespace std;

vector<char> tag[2];
vector< vector<int> > e[2];

struct Node {
	unsigned char a, b, score;
};
bool operator <(const Node& node1, const Node& node2) {
	return node1.score < node2.score;
}

int v[100][100];

void PushQ(priority_queue<Node>& Q, int a, int b, int score) {
	if (tag[0][a] == tag[1][b]) ++score;
	if (score <= v[a][b]) return;
	v[a][b] = score;

	Q.push({(unsigned char)a, (unsigned char)b, (unsigned char)score});
}
int main() {
	fill(&v[0][0], &v[0][0]+100*100, -1);

	for (int t = 0; t < 2; ++t) {
		int N, M; cin >> N >> M;
		tag[t].resize(N);
		for (int i = 0; i < N; ++i) {
			cin >> tag[t][i];
		}
		e[t].resize(N);
		for (int i = 0; i < M; ++i) {
			int a, b; cin >> a >> b; --a, --b;
			e[t][a].push_back(b);
		}
	}

	priority_queue<Node> Q;
	for (int a = 0; a < tag[0].size(); ++a) for (int b = 0; b < tag[1].size(); ++b) {
		PushQ(Q, a, b, 0);
	}

	while ( !Q.empty() ) {
		Node node = Q.top(); Q.pop();
		int a = (int)node.a, b = (int)node.b;
		int score = (int)node.score;

		if (score < v[a][b]) continue;
		if (score > 100) {
			cout << -1 << endl;
			return 0;
		}

		if (tag[0][a] != tag[1][b]) {
			for (int i = 0; i < e[0][a].size(); ++i) {
				PushQ(Q, e[0][a][i], b, score);
			}
			for (int i = 0; i < e[1][b].size(); ++i) {
				PushQ(Q, a, e[1][b][i], score);
			}
		}
		for (int i = 0; i < e[0][a].size(); ++i) {
			for (int j = 0; j < e[1][b].size(); ++j) {
				PushQ(Q, e[0][a][i], e[1][b][j], score);
			}
		}
	}
	int ans = 0;
	for (int a = 0; a < tag[0].size(); ++a) for (int b = 0; b < tag[1].size(); ++b) {
		ans = max(ans, v[a][b]);
	}
	cout << ans << endl;
}

Measured memory_bytes: 2844
n, k = map(int, input().split())
p = list(map(int, input().split()))
nxt = 0
mx = []
for i in range(n):
    pex = (1+p[i])/2
    mx.append(pex+nxt)
    nxt = pex + nxt
if n == k:
    print(mx[-1])
else:
    ans = []
    for i in range(n-k):
        ans.append(mx[i+k] - mx[i])
    print(max(ans))

Measured memory_bytes: 25060
#include<bits/stdc++.h>
using namespace std;
 
#define rep(i, a, n) for(int i=a; i<n; i++)
#define ll long long
#define all(x) begin(x), end(x)
#define toInt(x) (x - '0')
#define pll pair<ll, ll>
#define pli pair<ll, int>
// #define int long long

#define INF 1e+9
#define MAX_V 100008

vector<pair<ll, int>> factrized(ll num){
  vector<pair<ll, int>>  res;
 
  for(ll i = 2; i * i <= num; i++){
    if(num % i)continue;
    res.emplace_back(i, 0);
    while(num % i == 0){
      num /= i;
      res.back().second++;
    }
  }
  if(num != 1) res.emplace_back(num, 1);
  return res;
}

int main(){
    int a, b;
    cin >> a >> b;
    cout << a * b << endl;
}


Measured memory_bytes: 3632
{-# LANGUAGE FlexibleContexts #-}
 
module Main where
 
import Debug.Trace
import Data.List
import qualified Data.Set as Set
import qualified Data.Sequence as Seq
import qualified Data.ByteString.Char8 as B
import Data.Int
import Data.Word
import Data.Char
import Data.Bits
import Data.Array
-- import Data.Array.Unboxed
-- import Data.Array.IO
import Data.Maybe
-- import qualified Data.Map as M
import qualified Data.IntMap as M
-- import Control.Monad.ST
-- import Data.STRef
import Data.Ord
import Data.Functor
import Control.Applicative
import Control.Monad
import Text.Printf
 
size = 3 
sqSize = size*size
maxAdr = sqSize -1
mask = 0xF
shiftSize = 4
shiftTimes= 16
 
solver :: [[Int]] -> Int
solver lst
    | start == goal = 0
    | otherwise = iter (initialQueue, initialVisited) where
        iter (que, visited) = case Seq.viewr que of
            Seq.EmptyR -> error "No path found."
            que Seq.:> path@(board, distance, forward) -> case next path visited of
                (_, Just d)  -> distance + d +1
                (nextPaths, Nothing) -> iter (insertPaths que visited nextPaths) where
                    insertPaths q v [] = (q, v)
                    insertPaths q v (p@(x, d, f):ps) = insertPaths insertQue insertVisited ps where
                        insertQue = p Seq.<| q
                        insertVisited = M.insert x (d, f) v
        next path@(board, distance, forward) visited = iter [] Nothing nextBoards where
            iter ac af [] = (ac, af)
            iter ac af (x:xs) = case M.lookup x visited of
                Nothing -> iter ((x, distance+1, forward):ac) af xs
                Just (d', f') -> if forward == f' then iter ac af xs else (ac, Just d')
            nextBoards = [swapWith (valueAt p board) board | p <- dest!(searchZero board)]
 
        initialQueue = (goal, 0, False) Seq.<| (Seq.singleton (start, 0, True))
        initialVisited = M.insert goal (0, False) $ M.singleton start (0, True)
        goal    = toBits [1,2,3,4,5,6,7,8,0]
        start   = toBits $ concat lst
        dest    = listArray (0, maxAdr) [[1,3],[0,2,4],[1,5],[0,4,6],[1,3,5,7],[2,4,8],[3,7],[4,6,8],[5,7]]
        toBits = foldl' (\b a-> shiftL b shiftSize .|. a) 0
        valueAt i w = mask .&. shiftR w (shiftSize*i)
 
searchZero :: Int -> Int
searchZero = iter 0 where
    iter c w = case mask .&. w of 
        hb  | hb == 0 -> c
            | otherwise -> iter (c+1) (rotateR w shiftSize)
 
swapWith :: Int -> Int -> Int
swapWith v = iter sqSize where
    iter 0 w = rotateR w (shiftSize*(shiftTimes-sqSize))
    iter c w = iter (c-1) $ rotateR (case mask .&. w of
        hb  | hb == 0 -> w .|. v
            | hb == v -> w `xor` v
            | otherwise -> w) shiftSize
 
readIntLn:: IO Int
readIntLn = (fst . fromJust . B.readInt) <$> B.getLine
 
readIntList:: IO [Int]
readIntList = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
 
main :: IO() 
main = do
    l <- replicateM size readIntList
    print $ solver l


Measured memory_bytes: 7848
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i < (n); i++)
template<class T> istream& operator >> (istream& s, vector<T>& v)
{ for (T& x: v) { s >> x; } return s;}

int main()
{
    string S, T;
    cin >> S >> T;

    bool yes = (S == T.substr(0, T.size()-1));

    cout << ( yes ? "Yes" : "No" )<< endl;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <complex>
#include <iostream>
#include <string>
//#include <math>
using namespace std;

long Max = 1000000000;

long sum_distance(long n, long m){
   if(n*m>=0) return max(abs(n),abs(m));

   n = abs(n);
   m = abs(m);
   return min(2*n+m, 2*m+n);
}
int main(){
  long N, K;
  cin >> N >> K;
  long x[N];

  for(int i=0;i<N;i++) cin >> x[i];

  long ans = Max;
  for(int i=0;i<N-K+1;i++){
    ans = min(ans, sum_distance(x[i],x[i+K-1]));
  }

  cout << ans <<endl;



  return 0;
}

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

bool prime[200001];
int n,p;
int primebox[100000];

int main(void){
	memset(prime,true,sizeof(prime));
	prime[0]=prime[1]=false;
	for(int i=2;i<=200000;i++){
		if(prime[i]){
			for(int j=i*2;j<=200000;j+=i){
				prime[j]=false;
			}
		}
	}
	int cnt=0;
	for(int i=2;i<=200000;i++){
		if(prime[i])primebox[cnt++]=i;
	}
	while(1){
		scanf("%d %d",&n,&p);
		if(n+p==-2)break;
		int l=0;
		while(primebox[l]<=n)l++;
		vector<int> v;
		for(int i=l;i<=min(l+100,cnt-1);i++){
			for(int j=i;j<=min(cnt-1,l+100);j++){
				v.push_back(primebox[i]+primebox[j]);
			}
		}
		sort(v.begin(),v.end());
		printf("%d\n",v[p-1]);
	}
	return 0;
}

Measured memory_bytes: 1380
#include<cstdio>
#include<algorithm>

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

using namespace std;

int main(){
	int h,n,atari,m,k;
	scanf("%d%d%d%d%d",&h,&n,&atari,&m,&k); atari--;
	int bh[100],bx[100];
	rep(i,m) scanf("%d%d",bh+i,bx+i), bh[i]--, bx[i]--;

	int i_bar=m-1;
	static double dp[501][101][100];
	dp[h][0][atari]=1;
	for(int y=h-1;y>=0;y--){
		if(i_bar>=0 && bh[i_bar]==y){
			rep(i,k+1){
				rep(x,n) dp[y][i][x]=dp[y+1][i][x];
				swap(dp[y][i][bx[i_bar]],dp[y][i][bx[i_bar]+1]);
			}
			i_bar--;
		}
		else{
			rep(i,k+1){
				double p=(double)(k-i)/(y-i_bar);
				if(k-i>y-i_bar) continue;

				rep(x,n) dp[y][i][x]+=dp[y+1][i][x]*(1-p);

				rep(x,n){
					if(0<x){
						dp[y][i+1][x-1]+=dp[y+1][i][x]*p/(n-1);
					}
					if(x<n-1){
						dp[y][i+1][x+1]+=dp[y+1][i][x]*p/(n-1);
					}
					if(x==0 || x==n-1){
						dp[y][i+1][x]+=dp[y+1][i][x]*p*(n-2)/(n-1);
					}
					else{
						dp[y][i+1][x]+=dp[y+1][i][x]*p*(n-3)/(n-1);
					}
				}
			}
		}
	}

	printf("%.9f\n",*max_element(dp[0][k],dp[0][k]+n));

	return 0;
}

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

int main() {
    // 制約見て！！！デカかったらlong longにすること！
    int n, m;
    cin >> n >> m;
    vector<int> cnt(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        cnt[a]++;
        cnt[b]++;
    }
    rep(i,n){
        cout<<cnt[i]<<endl;
    }
}

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

typedef long long  ll;

ll MOD = 1000000007;
ll INF = 10000000000000000;
double PI = 3.1415926535;

ll ceiling(ll a,ll b){
  if(a % b == 0){
    return a / b;
  }else{
    return (a / b) + 1;
  }
}

template<typename T>
void remove(std::vector<T>& vector, unsigned int index)
{
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

ll GCD(ll a,ll b){
  if(a < b)return GCD(b,a);
  ll r = INF;
  while(r){
    r = a % b;
    a = b;
    b = r;
  }
  return a;
}

int main(){
  ll N,K;cin >> N >> K;
  vector<ll> A(N);
  ll M = 0;
  for(int i = 0;i < N;i++){
    cin >> A[i];
    M = max(M,A[i]);
  }
  ll G = A[0];
  for(int i = 0;i < N;i++){
    G = GCD(G,A[i]);
  }
  if(K % G == 0 && K <= M){
    cout << "POSSIBLE" << endl;
  }else{
    cout << "IMPOSSIBLE" << endl;
  }
}

Measured memory_bytes: 1024
#include <iostream>
#include <utility>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <unordered_map>
#include <unordered_set>
#include <iterator>
#include <cmath>
#include <string>

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<pii> vpii;

#define pb push_back
#define fi first
#define se second
#define mp make_pair
#define ins insert
#define iter ::iterator
#define upb upper_bound
#define lwb lower_bound

#define sz(v) v.size()
#define aloc(i, a, n) i *a = new i[n]

#define for0(i,a) for(ll i = 0; i < a; i++)
#define fori(i,a,b) for(ll i = a; i < b; ++i)
#define rfor0(i,a) for(ll i = a; i >= 0; --i)
#define rfor(i,a,b) for(ll i = a; i >= b; --i)

int main(){

  ll a,b;
  cin >> a >> b;
  ll damage = 0;
  for0(i, b){
    int temp;
    cin >> temp;
    damage += temp;
  }
  if(damage >= a) cout << "Yes" << endl;
  else cout << "No" << endl;

}


Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("unroll-loops")

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

using namespace std;
using namespace __gnu_pbds; 

#define pb push_back
#define eb emplace_back
#define mp make_pair
#define all(v) (v).begin(),(v).end()
#define f first
#define s second
#define sz(x) ll(x.size())
#define endl '\n'
#define forn(i,n) for(int i=0;i<n;++i)
#define fore(i,l,r) for(int i=int(l);i<=int(r);++i)
#define rep(i,begin,end) for(__typeof(end) i=(begin);i!=(end);i++)
#define fill(a,value) memset(a,value,sizeof(a));
#define gcd(a,b) __gcd((a),(b))
#define watch1(x) cout << (x) << endl
#define watch2(x,y) cout << (x) << " " << (y) << endl
#define watch3(x,y,z) cout << (x) << " " << (y) << " " << (z) << endl
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);
 
typedef long long ll;
typedef long double ld; 
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pii> vpii;
typedef tree<pii, null_type, less<pii>, rb_tree_tag, tree_order_statistics_node_update> oset;
 
const ll mod = 1e9 + 9;
const int inf = 1e9 + 5;
const int N = 1e5 + 5;

signed main(){
    fastio;
    int l;
    cin>>l;
    ld ans=(l*l*l)/27.0;
    cout<<fixed<<setprecision(12)<<ans;
    return 0;
}

Measured memory_bytes: 256
#167C bit探索
def main():
    import sys, numpy as np
    
    N,M,X =map(int, sys.stdin.readline().split())
    CAB = [tuple(map(int, sys.stdin.readline().split())) for _ in range(N)]
    
    #bit探索
    ans = -1
    for i in range(2**N):
        result = np.array([0 for _ in range(M+1)])
        for j in range(N): #桁(右始まり)
            if ((i>>j) &1) ==1:
                result +=np.array(CAB[N-j-1])
        if np.all(result[1:]>=X):
            if ans==-1 or ans > result[0]:
                ans = result[0]
    print(ans)
   

if __name__=='__main__':
    main()


Measured memory_bytes: 27280
n = int(input())
p = list(map(int, input().split()))
k = 0
flag = False
for i in range(n):
  if p[i] == i+1:
    k += 1
    if flag:
      k -= 1
      flag = False
    else:
      flag = True
  else:
    flag = False

print(k)


Measured memory_bytes: 14008
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  long N, L, T;
  cin >> N >> L >> T;
  vector<long> xs(N, 0), ws(N, 0);
  for (long i = 0; i < N; ++i) {
    cin >> xs[i] >> ws[i];
  }

  vector<long> last_poses(N, 0);
  long counter = 0;
  for (long i = 0; i < N; ++i) {
    if (ws[i] == 1) {
      last_poses[i] = (xs[i] + T) % L;
      counter += (xs[i] + T) / L;
    } else {
      if (xs[i] - T >= 0) {
        last_poses[i] = xs[i] - T;
        // counterは変化なし
      } else {
        last_poses[i] = (((xs[i] - T) % L) + L) % L;
        counter -= (T - (xs[i] + 1) + L) / L;
      }
    }
  }

  sort(last_poses.begin(), last_poses.end());
  counter = (counter % N + N) % N;

  vector<long> res(N, 0);
  for (long i = 0; i < N; ++i) {
    res[i] = last_poses[(i + counter) % N];
  }

  for (auto &e : res) {
    cout << e << endl;
  }
  return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define int long long
#define ld long double
#define endl '\n'
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define vpii vector<pii>
#define gr vector<vpii>
#define str string
#define mask vector<bool>
#define vs vector<str>
#define pq priority_queue
#define si set<int>
#define ordered_set_of(T) tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>
#define fi first
#define se second
#define sz(x) (int)((x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define nub(x) x.resize(unique(all(x)) - x.begin())
#define TWO class T1, class T2
#define YES cout << "YES" << endl
#define NO cout << "NO" << endl
#define GAME_OVER return 0
using namespace std;
using namespace __gnu_pbds;
char _$ = ' ';
struct sep {sep(char c) {_$ = c;}};
ostream& operator<<(ostream& o, sep s) {return o;}
template<TWO> ostream& operator<<(ostream& o, pair<T1, T2> x) {return o << x.fi << ' ' << x.se;}
template<TWO> istream& operator>>(istream& i, pair<T1, T2>& x) {return i >> x.fi >> x.se;}
template<class T> ostream& operator<<(ostream& o, vector<T> x) {for (auto it : x) o << it << _$; return o;}
template<class T> istream& operator>>(istream& i, vector<T>& x) {for (auto& it : x) i >> it; return i;}
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    str s, t;
    cin >> s >> t;
    int res = 0;
    for (int i = 0; i < sz(s); i++)
        if (s[i] != t[i])
            res++;
    cout << res << endl;
    GAME_OVER;
}

Measured memory_bytes: 3788
#include <iostream>
#include <cmath>

using namespace std;

int main(int argc, char const *argv[])
{
    int D, T, S;
    cin >> D >> T >> S;
    int t = static_cast<int>(ceil(D * 1.0 / S));
    cout << (T >= t ? "Yes": "No") << '\n';
    return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

const ll mod = 1000000007;

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

    int r_to_w = 0;
    int w_to_r = 0;

    rep(i, N) if (c[i] == 'R') r_to_w++;
    int ans = r_to_w;

    rep(i, N) {
        if (c[i] == 'R') {
            r_to_w--;
        } else {
            w_to_r++;
        }
        chmin(ans, chmax(r_to_w, w_to_r));
    }

    cout << ans << endl;
}


Measured memory_bytes: 3688
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = Number(input[0][0]);
  const A = Number(input[1][0]);

  return N * N - A;
};

console.log(main(read()));


Measured memory_bytes: 29668
#include <iostream>
#include <string>
#include <unordered_map>
#include <stdio.h>
#include <list>
#include <vector>
#include <algorithm>
#include <stack>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; ++i)
#define ALL(v) v.begin(), v.end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100000000;

int main()
{
   double n,k;
   cin >> n >> k;
   double ans = 0;
   for(int i=1;i<=n;i++)
   {
      double p=1;
      double now = i;
      while(now<k)
      {
         p/=2;
         now*=2;
      }
      ans +=p/n;

   }
   printf("%.15lf\n",ans);
   return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int k = Integer.parseInt(sc.next());
		sc.close();
		sc = null;
		System.out.println(n-k+1);
	}
}


Measured memory_bytes: 22228
s = list(input())

t1 = ["0" if i % 2 == 0 else "1" for i in range(len(s))]
t2 = ["1" if i % 2 == 0 else "0" for i in range(len(s))]

c1 = 0
c2 = 0

for i in range(len(s)):
    if s[i] != t1[i]:
        c1 += 1

for i in range(len(s)):
    if s[i] != t2[i]:
        c2 += 1

print(min(c1,c2))


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

int main() {
  int N, K, L;
  cin >> N >> K;
  L = 0;
  
  for (int i = 0; i < N; i++){
    int x;
    cin >> x;
    
    if (x < K - x){
      L += 2 * x;
    }
    else {
      L += 2 * (K - x);
    }
  }
  
  cout << L << endl;
  
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

typedef int Weight;
struct Edge {
  int src, dst;
  Weight weight;
  Edge(int src, int dst, Weight weight) :
    src(src), dst(dst), weight(weight) { }
};

bool operator < (const Edge &e, const Edge &f) {
  return e.weight != f.weight ? e.weight > f.weight : // !!INVERSE!!
    e.src != f.src ? e.src < f.src : e.dst < f.dst;
}

typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

pair<Weight, Edges> prim(const Graph &g, int r = 0) {
  int n = g.size();
  Edges T;
  Weight total = 0;

  vector<bool> visited(n);
  priority_queue<Edge> Q;
  Q.push( Edge(-1, r, 0) );
  while (!Q.empty()) {
    Edge e = Q.top(); Q.pop();
    if (visited[e.dst]) continue;
    T.push_back(e);
    total += e.weight;
    visited[e.dst] = true;
    FOR(f, g[e.dst]) if (!visited[f->dst]) Q.push(*f);
  }
  return pair<Weight, Edges>(total, T);
}

int main() {
  int n, m;
  while(cin>>n>>m, n||m) {
    Graph g(n);
    while(m--) {
      int a, b, cost;
      cin >> a>> b >> cost;
      g[a].push_back(Edge(a,b,cost));
      g[b].push_back(Edge(b,a,cost));
    }
    cout << prim(g).first << endl;
  }
}

Measured memory_bytes: 0
#include <cstdio>
#include <cstdint>
#include <cassert>
#include <algorithm>
#include <set>
#include <functional>

template <typename Tp, typename Comparator = std::less<Tp>>
class median {
public:
  using value_type = Tp;
  using key_compare = Comparator;

private:
  using container = std::multiset<value_type, key_compare>;
  using iterator = typename container::iterator;
  container M_c;
  iterator M_it;
  key_compare M_comp = Comparator();
  size_t M_size = 0;
  value_type M_lower_sum = Tp();
  value_type M_upper_sum = Tp();

public:
  median() = default;

  bool empty() const { return M_c.empty(); }
  value_type get() const { return *M_it; }
  value_type lower_sum() const { return M_lower_sum; }
  value_type upper_sum() const { return M_upper_sum; }
  void insert(value_type const& x) {
    ++M_size;
    if (empty()) {
      M_it = M_c.insert(x);
      M_lower_sum += x;
      return;
    }
    M_c.insert(x);
    if (M_comp(x, *M_it)) {
      if (M_size % 2 == 0) {
        // x ? ! ?
        M_lower_sum -= *M_it;
        M_upper_sum += *M_it;
        --M_it;
        M_lower_sum += x;
      } else {
        // x ? ! ? ?
        M_lower_sum += x;
      }
    } else {
      if (M_size % 2 == 0) {
        // ? ! ? x
        M_upper_sum += x;
      } else {
        // ? ! ? ? x
        ++M_it;
        M_lower_sum += *M_it;
        M_upper_sum -= *M_it;
        M_upper_sum += x;
      }
    }
  }
  void erase(value_type const& x);
};

int main() {
  size_t Q;
  scanf("%zu", &Q);

  intmax_t bs = 0;
  intmax_t n = 0;
  median<intmax_t> md;
  for (size_t i = 0; i < Q; ++i) {
    int t;
    scanf("%d", &t);

    if (t == 1) {
      intmax_t a, b;
      scanf("%jd %jd", &a, &b);
      md.insert(a);
      bs += b;
      ++n;
    } else if (t == 2) {
      intmax_t x = md.get();
      intmax_t y = bs;
      y -= md.lower_sum();
      y += md.upper_sum();
      if (n % 2 == 1) y += x;
      printf("%jd %jd\n", x, y);
    } else {
      assert(false);
    }
  }
}


Measured memory_bytes: 9600
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<vector>
#define ll long long
#define pb push_back
using namespace std;
const int N=110000;
int P[N];
int n;
ll Ans;
int main()
{
	cin>>n;
	for(int i=1;i<=n;i++) cin>>P[i];
	sort(P+1,P+n+1);
	int l=2,r=n,nl=P[1],nr=P[1];
	for(int i=1;i<=n-1;i++)
	{
		int b1=abs(nl-P[l]);
		int b2=abs(nl-P[r]);
		int b3=abs(nr-P[l]);
		int b4=abs(nr-P[r]);
		int mx=max(max(b1,b2),max(b3,b4));
		if(mx==b1) nl=P[l],l++;
		else if(mx==b2) nl=P[r],r--;
		else if(mx==b3) nr=P[l],l++;
		else if(mx==b4) nr=P[r],r--;
		Ans+=1ll*mx;
	}
	cout<<Ans<<endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    bool fail=0;
    for(int i=0;i<s.size();++i)
    {
        if(i&1)
        {
            if(s[i]=='R'){fail=1;break;}
        }
        else
        {
            if(s[i]=='L'){fail=1;break;}
        }
    }
    if(fail)cout<<"No\n";
    else cout<<"Yes\n";
    return 0;
}


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

int main() {
  int n, m, trueCount;
  cin >> n >> m;
  char a[50][50], b[50][50];

  rep(i, n) rep(j, n) cin >> a[i][j];
  rep(i, m) rep(j, m) cin >> b[i][j];

  rep(i, n) {
    rep(j, n) {
      rep(mi, m) {
        rep(mj, m) {
          if (a[i + mi][j + mj] == b[mi][mj]) trueCount++;
        }
      }
      if (trueCount == m*m) {
        cout << "Yes" << endl;
        return 0;
      } else trueCount = 0;
    }
  }

  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <stack>
#include <algorithm>
#include <cmath>

int main()
{
	long long h, w, k, sx, sy;
 
	std::cin >> h >> w >> k;
 
	std::vector<std::string> v(h);
 
	for (long long i = 0; i < h; i++) {
		std::cin >> v[i];
		auto pos = std::find(v[i].begin(), v[i].end(), 'S');
		if (pos != v[i].end()) {
			sx = i;
			sy = pos - v[i].begin();
		}
	}
 
	std::stack<std::pair<long long, long long> > s, p;
	s.push({ sx, sy });
	p.push({ sx, sy });
 
	int xx[] = { 1,0,-1,0 }, yy[] = { 0,1,0,-1 };
	while (!s.empty()) {
		int x = s.top().first, y = s.top().second;
		s.pop();
		for (int i = 0; i < 4; i++) {
			if (x + xx[i] < 0 || x + xx[i] >= h || y + yy[i] < 0 || y + yy[i] >= w) {
				continue;
			}
			if (std::abs(x + xx[i] - sx) + std::abs(y + yy[i] - sy) > k) {
				continue;
			}
			if (v[x + xx[i]][y + yy[i]] == '.') {
				s.push({ x + xx[i], y + yy[i] });
				p.push({ x + xx[i], y + yy[i] });
				v[x + xx[i]][y + yy[i]] = '#'; // 一度行った場所に行かないようにする
			}
		}
	}

	long long ans = 1000000000000;
	while(!p.empty()){
		long long x = p.top().first, y = p.top().second;
		p.pop();
		ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * x / k)));
		ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (h - x - 1) / k)));
		ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * y / k)));
		ans = std::min(ans, static_cast<long long>(std::ceil(1.0 * (w - y - 1) / k)));
	}
 
	std::cout << ans + 1 << std::endl;
 
	return 0;
}

Measured memory_bytes: 16272
// by Isaunoya
#include<bits/stdc++.h>
#define int long long
using namespace std;
struct io {
	char buf[1 << 25 | 3], *s;
	int f;
	io() { f = 0, buf[fread(s = buf, 1, 1 << 25, stdin)] = '\n'; }
	io& operator >> (int&x) {
		for(x = f = 0; !isdigit(*s); ++s) f |= *s  == '-';
		while(isdigit(*s)) x = x * 10 + (*s++ ^ 48);
		return x = f ? -x : x, *this;
	}
};

signed main() {
#ifdef LOCAL
	freopen("testdata.in", "r", stdin);
#endif
	int n;
	cin >> n;
	set <string> s;
	for(int i = 0 ; i < n ; i ++) {
		string str;
		cin >> str;
		s.insert(str);
	}
	cout << s.size() << '\n';
	return 0;
}


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

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
using namespace std;

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

	if( s[2] == s[3] && s[4] == s[5] )	cout << "Yes" << endl;
	else	cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3604
#include<cstdio>
#include<algorithm>
using namespace std;
const int MAX=1e6;
int d[MAX];
bool cmp(int a,int b)
{
	return a>b;
}
int main()
{  int a,b,c,i;
long long int s=0;
  scanf("%d%d",&a,&b);
  for(i=0;i<a;i++)
  {
  	scanf("%d",&d[i]);
  }
  sort(d,d+a);
  for(i=0;i<a-b;i++)
  {
  	s+=d[i];
  }
  printf("%lld\n",s);
  
    
 
	
}






















Measured memory_bytes: 896
<?php
$str = trim(fgets(STDIN));

$ans = [];
for ($i = 0; $i < 4; ++$i) {
    if (!array_key_exists($str[$i], $ans)) {
        $ans[$str[$i]] = 0;
    }
    $ans[$str[$i]]++;
}

foreach ($ans as $key=>$value) {
    if ($value === 1 || $value === 3 || $value === 4) {
        echo "No\n";
        return;
    }
}
echo "Yes\n";

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
#define pb push_back
typedef long long ll;
typedef unsigned long long ull;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef pair<ll, ll> pll;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<ll> vll;
const int MN = 2e5+5, MOD=1e9+7, LOG=33;
ll lcm (ll a, ll b) {return a*b/__gcd(a,b);}
ll multiplyMod(ll a, ll b) { return (a % MOD * b % MOD) % MOD; }
ll addMod(ll a, ll b) { return (a % MOD + b % MOD) % MOD; }
ll subMod(ll a, ll b) { return (a % MOD - b % MOD) % MOD; }
ll fpow(ll b, ll exp, ll mod){if(exp == 0) return 1;ll t = fpow(b,exp/2,mod);if(exp&1) return t*t%mod*b%mod;return t*t%mod;}
ll divmod(ll i, ll j, ll mod){i%=mod,j%=mod;return i*fpow(j,mod-2,mod)%mod;}
int n, k;
vi H;
int main() {
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> k;
    for (int i =0,z;i<n;i++) {
        cin >> z;
        H.pb(z);
    }
    sort(H.begin(), H.end(), greater<int>());
    ll res = 0;
    for (int i = k;i<n;i++) {
        res += H[i];
    }
    cout << res << '\n';


    return 0;

}

Measured memory_bytes: 1400
#include <iostream>
#include <iosfwd>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <ctime>
#include <cmath>
#include <cassert>
#include <cctype>
#include <climits>
#include <vector>
#include <bitset>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <deque>
#include <string>
#include <list>
#include <iterator>
#include <sstream>
#include <complex>
#include <fstream>
#include <functional>
#include <numeric>
#include <utility>
#include <algorithm>
#include <assert.h>
#include <unordered_map>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef double ld;
typedef vector < long long > vll;
typedef pair <long long, long long> pll;
typedef pair <int, int> pii;
typedef vector < int > vii;
typedef complex < double > Point;

#define csl ios_base::sync_with_stdio(false); cin.tie(NULL)
#define mp make_pair
#define fst first
#define snd second

ll t, n, m, u, v, q, r, ql, qr, k, l, s, w, z, x, y, d, p, c, L, b;
const int N = 100;
const int LN = 21;
const long long mod = 1e9 + 7;
const long long INF = 1LL << 52LL;
string str;
int main() {
    csl;
    cin >> str;
    for (int i = 0; i < 4; ++i) cout << str[i];
    cout << " ";
    for (int i = 4; i < str.size(); ++i) cout << str[i];
    cout <<'\n';
    return 0;
}










Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
int main()
{
  long long res = 0;
  int N;
  cin >> N;
  vector<long long> a(N);
  vector<long long> b(N);
  for (int i = 0; i < N; i++) cin >> a[N-i-1] >> b[N-i-1];
  long long sum = 0;
  for (int i = 0; i < N; i++) {
    a[i] += sum;
    long long t = b[i] - a[i] % b[i];
    if (a[i] % b[i] != 0) {
      a[i] += t;
      sum += t;
    }
  }
  cout << sum << endl;
}

Measured memory_bytes: 1792
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <math.h>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <cassert>
#include <random>
#include <deque>
#include <bitset>
#include <string>
#include <queue>
#include <complex>

//#define int long long

#define mp(a, b) make_pair(a, b)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()

#define endl '\n'

using namespace std;
typedef long long ll;
typedef long double ld;

mt19937 mrand(random_device{}());

double PI = acos((double)-1);
const ld eps = 1e-7;
const ll inf0 = 1023 * 1024 * 1024;
const ll inf = inf0 * inf0;
//const ll mod = 1e9 + 9;
const ll mod = 998244353;

void solve();
void scan();

signed main() {
#ifdef _DEBUG
	freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
#endif
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(false);
	cout << fixed; cout.precision(15);
	solve();
	return 0;
}

void solve() {
	ll x; cin >> x;
	ll ans = (x / 500) * 1000;
	x = x % 500;
	ans += (x / 5) * 5;
	cout << ans << endl;
	return;
}

Measured memory_bytes: 256
n,m=map(int,input().split())
ab=[list(map(int,input().split())) for _ in range(m)]
b=min(ab[i][1] for i in range(m))
a=max(ab[i][0] for i in range(m))
if b-a+1<0:print(0)
else:print(b-a+1)

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

using namespace std;

int main(){
  long  n;

  cin>>n;
  
  priority_queue< long, std::vector<long>, std::greater<long> > m;
  
  for(int i = 1 ; i <= sqrt( n ) ; i++){
	if(n % i == 0){
    m.push((long)i + n / i);
    }
  }
  
  cout<<m.top()-2<<endl;
  
}



Measured memory_bytes: 256
n,x,*a=map(int,open(0).read().split())
c=max(0,a[0]-x)
a[0]=min(a[0],x)
for i in range(n-1):
	if a[i]+a[i+1]>x:
		c+=a[i]+a[i+1]-x
		a[i+1]=x-a[i]
print(c)

Measured memory_bytes: 14092
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define inf 10e17
#define rep(i,n) for(long long i=0; i<n; i++)
#define repr(i,n,m) for(long long i=m; i<n; i++)
#define mod 1000000007
#define sorti(x) sort(x.begin(), x.end())
#define sortd(x) sort(x.begin(), x.end(), std::greater<long long>())
#define debug(x) std::cerr << (x) << std::endl;
#define roll(x) for (auto&& itr : x) { cerr << (itr) << " "; }

template <class T> inline void chmax(T &ans, T t) { if (t > ans) ans = t;}
template <class T> inline void chmin(T &ans, T t) { if (t < ans) ans = t;}

int main() {
  int n;
  cin >> n;
  vector<int> a(n-1);
  vector<int> p(n+1);
  repr(i, n-1, 0) {
    cin >> a[i];
    p[a[i]] += 1;
  }

  for (int i = 1; i<=n; ++i) {
    cout << p[i] << endl;
  }
}

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

string s;
long long m = 0, u = 0, d = 0, pu = 0;

int main()
{	
	cin >> s;

	if (s[0] == '>')
		d++;
	else
		u++;

	for (int i = 1; i < s.size(); i++) {
		if (s[i - 1] == '<') {
			if (s[i] == '>') {
				m += u * (u + 1) / 2;
				pu = u;

				u = 0;
				d = 1;
			}
			else {
				u++;
			}
		}
		else {
			if (s[i] == '<') {
				if (d < pu)
					m += d * (d - 1) / 2;
				else
					m += d * (d + 1) / 2 - pu;

				d = 0;
				u = 1;
			}
			else {
				d++;
			}
		}
	}

	if (d == 0)
		m += u * (u + 1) / 2;
	else if (u == 0) {
		if (d < pu)
			m += d * (d - 1) / 2;
		else
			m += d * (d + 1) / 2 - pu;
	}

	cout << m << endl;

	return 0;
}

Measured memory_bytes: 900
#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <iomanip>
#include <numeric>
 
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
string S;
ll N,X,K,D;
ll L[100];
ll ans;
ll p[5000];
ll C[5000];
ll M = 1000000000;
ll A[5000];
ll B[10005];
 
 
int main() {
    cin >> N>>K;
    for(ll i=0;i<N;i++){
        cin >> p[i];
    }
    for(ll i=0;i<N;i++){
        cin >> C[i];
    }
    for(ll i=0;i<N;i++){
        ll a = i;
        ll cnt = 1;
        ll j = p[i]-1;
        B[0] = 0;
        while(a!=j){
            A[i] += C[j];
            B[cnt] = B[cnt-1] + C[j];
            j =p[j]-1;
            cnt++;
        }
        A[i] += C[j];
        B[cnt] = B[cnt-1] + C[j];
        for(ll k=0;k<cnt;k++){
            B[k]=B[k+1];
        }
        if(A[i]>0 && K>cnt){
            A[i] *= K/cnt - 1;
        }else{
            A[i] = 0;
        }
        for(ll k=0;k<cnt;k++){
            B[k+cnt] = B[k] + B[cnt-1];
        }
        if(K>=cnt){
            sort(B,B+(cnt+K%cnt));
            A[i] += B[cnt+K%cnt-1];
        }else{
            sort(B,B+K);
            A[i] += B[K-1];
        }
    }
    ans = -100000000000;
    for(ll i=0;i<N;i++){
        if(ans < A[i]){
            ans = A[i];
        }
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 3812
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
ll S[101010];

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) cin>>S[i];
	ll ret=0;
	for(int D=1;D<=N-1;D++) {
		
		ll sum=0;
		int L=0,R=N-1;
		if((N-1)%D==0) {
			while(L<R) {
				sum+=S[L]+S[R];
				ret=max(ret,sum);
				L+=D;
				R-=D;
			}
		}
		else {
			while(L+D<N-1) {
				sum+=S[L]+S[R];
				ret=max(ret,sum);
				L+=D;
				R-=D;
			}
			
		}
		
	}
	
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {
	static Scanner s = new Scanner(System.in);

	public static void main(String[] args) {
		String X = s.next();
		String Y = s.next();


		String ans=(int)X.charAt(0)<(int)Y.charAt(0)?"<"
				:(int)X.charAt(0)==(int)Y.charAt(0)?"=":">";

		System.out.println(ans);
	}
}


Measured memory_bytes: 22612
/* When Talent doesn't work, Hard work beats Talent*/

#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

#include"bits/stdc++.h"

using namespace std;

#define Fast_D cout<<fixed<<setprecision(13);
#define FastIO ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define nl "\n"
#define int long long
#define double long double
#define all(v) v.begin(),v.end()
#define scanstr(s) cin>>ws; getline(cin,s);

const double PI = 3.141592653589793;

void solve()
{
	int n;
	cin >> n;
	vector <string> s(n);
	for(int i=0;i<n;i++)
	{
		string x;
		cin >> x;
		sort(all(x));
		s[i] = x;
	}
	sort (all(s));
	int i=0,j=0;
	int ans = 0;
	for(i=0;i<n;)
	{
		string cur = s[i];
		for(j=i+1;j<n;j++)
		{
			if(s[j]!=cur) break;
		}
		int f = (j-i);
		ans += f*(f-1);
		i = j;
	}
	cout << ans/2 ;
}

int32_t main()
{
	FastIO;
	Fast_D;
	int T;
	T=1;
	while(T--) solve();
	return 0;
}



Measured memory_bytes: 6400
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using lpair = pair<ll, ll>;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    ll h[100010];
    rep(i,0,N) cin >> h[i];
    ll dp[100010] = {};
    fill(dp, dp+N+1, INF);
    dp[0] = 0;
    rep(i,0,N){
        rep(j,1,K+1){
            if(i+j <= N-1){
                dp[i+j] = min(dp[i+j], dp[i] + abs(h[i+j] - h[i]));
            }
        }
    }
    print(dp[N-1]);


}

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

int main() {
  int N;
  cin >> N;
  
  vector <int> D (N);
  for(int i=0;i<N;i++) cin >> D.at(i);
  
  sort (D.begin(),D.end());
  int c=0;
  for(int i=1;i<N;i++){
    if (D.at(i) == D.at(i-1)) c++;
  }
  
  cout << N-c << endl;
  
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline

#n = int(input())
#l = list(map(int, input().split()))

'''
a=[]
b=[]
for i in range():
    A, B = map(int, input().split())
    a.append(A)   
    b.append(B)'''

k=int(input())
if k%2==0:
    print("-1")
    sys.exit()

flg=False
cnt=0
a=7
for i in range(k):
    cnt+=1
    a%=k
    if a%k==0:
        print(cnt)
        sys.exit()
    a*=10
    a+=7

if not flg:
    print(-1)

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

int main(){
	int n,tmp ,count = 0;
  	cin >> n;
  	vector<int> a(2*n);
  	for(int i = 0; i< 2*n;i++) {
    	cin >> a[i];
    }
  	sort(a.begin(),a.end());
  	for(int i = 0; i< 2*n;i+=2) {
  		count += a[i];
    }
  	cout << count << endl;
}


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

const long long M = (long long)(1e9) + 7;

int N, K;
long long prefixSum[100001];

long long x[100002];
long long mulMax[100002];
long long mulMin[100002];


long long fact[100002];

void _build_fact() {
    fact[0] = 1;
    for(int i = 1; i <= 100000; i++) fact[i] = fact[i-1] * i % M;
}

long long inv(long long x, long long y = M, long long p = 1, long long q = 0, long long r = 0, long long s = 1) {
    if(y == 0) return (p % M + M) % M;
    return inv(y, x%y, r, s, p-r*(x/y), q-s*(x/y));
}

long long C(long long n, long long k) {
    // n! / (k! * (n-k)!);
    if(k < 0) return 0;
    if(n < 0) return 0;
    if(k > n) return 0;
    if(k == n) return 1;
    return fact[n] * inv(fact[k]) % M * inv(fact[n-k]) % M;
}

int main() {
    _build_fact();
    //
    cin >> N >> K;
    for(int i = 1; i <= N; i++) {
        cin >> x[i];
        prefixSum[i] = prefixSum[i-1] + x[i];
    }
    //
    sort(x + 1, x + N + 1);
    // --------------------------------------
    for(int i = 1; i <= N; i++) {
        mulMax[i] = C(i-1, K - 1);
        mulMin[i] = C(N-i, K - 1);
    }
    // // --------------------------------------
    // for(int i = 1; i <= N; i++) {
    //     cout << mulMin[i] << " ";
    // }
    // cout << endl;
    // for(int i = 1; i <= N; i++) {
    //     cout << mulMax[i] << " ";
    // }
    // cout << endl;
    //
    long long Add = 0, Minus = 0;
    for(int i = K; i <= N; i++) {
        Add = (Add + (mulMax[i] % M) * (x[i] % M)) % M;
    }
    for(int i = N-K+1; i >= 1; i--) {
        Minus = (Minus + ((mulMin[i] % M) * (x[i] % M))) % M;
    }
    cout << (Add - Minus + M) % M;
}

Measured memory_bytes: 4096
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>

#define F first
#define S second
#define int long long
#define ll long long
//#define int  unsigned long long
#define pb push_back
//#define double long double

using namespace std;
using namespace __gnu_pbds;
typedef  tree< int , null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
const int mod = 1e9 + 7;
const int N = (1 << 20);
const int K = 300000;
map < pair < int, int >, int > m;
int a[N];
main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt", "r", stdin);
    int h, w, n;
    cin >> h >> w >> n;
    swap(h, w);
    a[w + 1] = 1;
    for (int i = 1; i <= w; i++) a[i] = 1e9;
    for (int i = 1; i <= n; i++){
        int x, y;
        cin >> x >> y;
        swap(x, y);
        m[{y, x}] = 1;
        a[y] = min(a[y], x);
    }
    int l = 1;
    for (int i = 1; i <= w; i++){
        if (a[i + 1] <= l){
            cout << i;
            return 0;
        }
        if (m.find({i + 1, l + 1}) == m.end()) l++;
    }
}


Measured memory_bytes: 14336