akhauriyash/Code-Regression huggingface dataset:
#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++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define Would
#define you
#define please

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

	int N;
	int a[200000], b[200000];
	cin >> N;
	rep(i, N) cin >> a[i];
	rep(i, N) cin >> b[i];

	int bmod[30][200000];
	rep1(i, 29) {
		rep(ii, N) {
			bmod[i][ii] = b[ii] % (1 << i);
		}
		sort(bmod[i], bmod[i] + N);
	}

	ll kotae[30] = {};
	rep(i, N) {
		rep1(ii, 29) {
			int amod = a[i] % (1 << ii);

			int l = 0;
			int r = N;
			int hikaku = (1 << ii) - amod;
			while (l != r) {
				int chk = (l + r) / 2;
				if (bmod[ii][chk] < hikaku) l = chk + 1;
				else r = chk;
			}
			int k1 = l;
			l = k1;
			r = N;
			hikaku = (1 << ii) + (1 << (ii - 1)) - amod;
			while (l != r) {
				int chk = (l + r) / 2;
				if (bmod[ii][chk] < hikaku) l = chk + 1;
				else r = chk;
			}
			int k2 = l;
			l = 0;
			r = k1;
			hikaku = (1 << (ii - 1)) - amod;
			while (l != r) {
				int chk = (l + r) / 2;
				if (bmod[ii][chk] < hikaku) l = chk + 1;
				else r = chk;
			}
			kotae[ii] += k1 - l + N - k2;
		}
	}
	int hontou = 0;
	rep1(i, 29) {
		kotae[i] %= 2;
		hontou += kotae[i] * (1 << (i - 1));
	}
	co(hontou);
	Would you please return 0;
}

Measured memory_bytes: 25216
import java.io.IOException;
import java.util.NoSuchElementException;

import java.io.BufferedReader;
import java.io.InputStream;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws IOException {
        try (
            BufferedReader reader = new BufferedReader(
                new InputStreamReader(System.in))) {
            FastScanner fs = new FastScanner();

            final int N = fs.nextInt();
            final double D = fs.nextDouble();
            final int X = fs.nextInt();

            int sm = 0;

            for (int i = 0; i < N; i++) {
                Double A = fs.nextDouble();
                sm += (int)Math.ceil(D / A);
            }

            System.out.println(sm + X);
        }
    }
}

class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() {
        if (hasNextByte()) return buffer[ptr++];
        else return -1;
    }
    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }
    public boolean hasNext() {
        while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;
        return hasNextByte();
    }
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if(b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
            throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() {
        return Double.parseDouble(next());
    }
}


Measured memory_bytes: 21332
#include <iostream>

using namespace std;

int main(){
  int N, K, ans=0;
  cin >> N >> K;
  int h[N];
  for(int i=0; i<N; i++) cin >> h[i];
  for(int i=0; i<N; i++){
    if(h[i] >= K) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 640
#include<atcoder/all>
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define rrep(i, n) for (int i = (int)n-1; i >= 0; --i)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
using namespace atcoder;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
const int mod = 1e9+7;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;

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

__attribute__ ((constructor))
void init() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr);
  cout << fixed << setprecision(10);
}

signed main(){
  int n,q;
  cin >> n >> q;
  dsu uf(n);
  vector<int> ans;
  rep(i,q){
    int t,u,v;
    cin >> t >> u >> v;
    if(t == 0) uf.merge(u,v);
    if(t == 1){
      if(uf.same(u,v)) ans.push_back(1);
      else ans.push_back(0);
    }
  }
  for(auto u : ans) cout << u << endl;
  return 0;
}

Measured memory_bytes: 4436
#include <iostream>

using namespace std;

int main(){
  int D,N;
  cin >> D >> N;
  long long int ans=1;
  for(int i=0;i<D;i++){
    ans*=100;
  }
  if(N!=100){
    cout << ans*N << endl;
  }else{
    cout << ans*N+ans << endl;
  }
}


Measured memory_bytes: 256
w,h,n = gets.split.map(&:to_i)

b = c = 0
n.times do
  x,y,a = gets.split.map(&:to_i)
  case a
  when 1
    b = [b,x].max
  when 2
    w = [w,x].min
  when 3
    c = [c,y].max
  when 4
    h = [h,y].min
  end
end

puts [(w-b),0].max*[(h-c),0].max

Measured memory_bytes: 1788
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <math.h>
#include <string>
#include <numeric>
#include <queue>
#include <cstdio>
#include <cstring>
#define ll long long
#define rep(i,n) for(ll i=0;i<n;++i)
#define rep1(i,n) for(ll i=1;i<n;++i)
#define mrep(i,n) for(ll i=n;i>=0;--i)
#define all(a) (a).begin(),(a).end()
#define vl vector<ll>
#define vvl vector<vector<ll> >
#define vb vector<bool>
#define vvb vector<vector<bool> >
#define pl pair<ll,ll>
#define inf 1001001001001001000
//#define mod 1000000007
#define mod 998244353
#define pi 3.1415926535
using namespace std;
struct __INIT {
	__INIT() {
		cin.tie(0);
		ios::sync_with_stdio(false);
		cout << fixed << setprecision(15);
	}
}__init;


int main(void) {
	ll n, m;
	cin >> n >> m;
	if (n == m) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0;
}


Measured memory_bytes: 3648
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second
 
using namespace std;
 
 
#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif
 
template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }
 
typedef long long int lint;
typedef pair<int,int> pi;
 
namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}
 
//const int INF=5e8;
 
 
static const int MAXN=100005;
struct BIT{
  int val[MAXN*2+2];
  int n;
  void init(int n_){
    n=1;
    while(n<n_) n<<=1;
    REP(i,n+1) val[i]=0;
  }
  void add(int k,int a){
    ++k;
    while(k<=n){
      val[k]+=a;
      k+=k&-k;
    }
  }
  int query(int k){ //[0,k)
    int res=0;
    while(k>0){
      res+=val[k];
      k-=k&-k;
    }
    return res;
  }
};
 
 
int n;
int buf[3][100005];
 
int ar[100005],sign[100005];
void ng(){
  puts("No");
  exit(0);
}
 
BIT bit;
 
int main(){
  cin>>n;
  REP(i,3) REP(j,n) scanf("%d",&buf[i][j]),--buf[i][j];
 
  REP(i,n){
    int base=buf[0][i]/3;
    REP(j,3) if(buf[j][i]/3!=base) ng();
    if(buf[1][i]%3!=1) ng();

    ar[i]=base;
    sign[base]=(buf[0][i]%3==2);
    if((ar[i]&1)!=(i&1)) ng();
  }
 
  bit.init(n);
  debug(ar,ar+n);
  debug(sign,sign+n);
  for(int i=0;i<n;i+=2){
    int dif=(i/2-bit.query(ar[i]));
    sign[1]^=(dif&1);
    bit.add(ar[i],1);
  }
  for(int i=0;i<n;i+=2) sign[ar[i]]^=(abs(ar[i]-i)/2)&1;
  debug(sign,sign+n);
  bit.init(n);
  for(int i=1;i<n;i+=2){
    int dif=(i/2-bit.query(ar[i]));
    sign[0]^=(dif&1);
    bit.add(ar[i],1);
  }
  for(int i=1;i<n;i+=2) sign[ar[i]]^=(abs(ar[i]-i)/2)&1;
 
  debug(sign,sign+n);
 
  int cnt[2]={0};
  REP(i,n) if(sign[i]) cnt[i&1]++;
  if(cnt[0]%2==0 && cnt[1]%2==0) puts("Yes");
  else puts("No");
  return 0;
}
 


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

#define rep(i,m,n) for(int (i)=(int)(m);i<(int)(n);++i)
#define rep2(i,m,n) for(int (i)=(int)(n)-1;i>=(int)(m);--i)
#define REP(i,n) rep(i,0,n)
#define REP2(i,n) rep2(i,0,n)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define all(hoge) (hoge).begin(),(hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll) 1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld=long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

struct Edge {
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
	to = _to; cap = _cap; rev = _rev;
	}
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

void solve(){
    ll h,w;
    cin>>h>>w;
    vec<string> a(h);
    REP(i,h) cin>>a[i];
    Matrix dp(h,Array(w,0));
    dp[0][0]=1;
    REP(i,h){
        REP(j,w){
            if(a[i][j]=='.')continue;
            if(dp[i][j]!=1){
                cout<<"Impossible"<<en;
                return;
            }

            if(i==h-1 && j==w-1) break;
            ll con=0;
            if(i+1 < h && a[i+1][j] == '#'){
                dp[i+1][j]=1;
                con++;
            }
            if(j+1 < w && a[i][j+1] == '#'){
                dp[i][j+1]=1;
                con++;
            }

            if( con==2 || con==0){
                cout<<"Impossible"<<en;
                return;
            }
        }
    }
    cout<<"Possible"<<en;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
	
	solve();
	//ll t;cin>>t;REP(i,t) solve();

    return 0;
}

Measured memory_bytes: 256
floor = [
        [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],

        [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],

        [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]],

        [[0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0],
         [0, 0, 0, 0, 0, 0, 0, 0, 0, 0]]
        ]
s = '####################'

n = int(input())
for c in range(n):
    (b,f,r,v) = [int(x) for x in input().split()]
    if 1 > b > 5 and 1 > f > 4 and 1 > r > 10:
        break
    floor[b-1][f-1][r-1] += v

for z in range(4):
    for i in range(len(floor[z])):
        for v in floor[z][i]:
            print(end=' ')
            print(v, end='')
        print()
    if not z == 3:
        print(s)

Measured memory_bytes: 6796
use proconio::input;
use std::collections::HashSet;

#[proconio::fastout]
pub fn main() {
    input! {
    mut a:[isize],
    }
    a.sort();
    let mut ng: HashSet<isize> = HashSet::new();
    let mut ps: Vec<isize> = Vec::new();
    let mut ans = 0;
    for (i, &v) in a.iter().enumerate() {
        if ps.iter().all(|&p| v % p != 0) && !ng.contains(&v) {
            if v > 1000 {
                for k in 1..1000000 {
                    if k * v > 1000000 { break; }
                    ng.insert(k * v);
                }
            } else {
                ps.push(v);
            }
            if &v != a.get(i + 1).unwrap_or(&0) {
                ans += 1;
            }
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 19624
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <random>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>
#include <new>
#include <typeinfo>

typedef  long long ll;
#define mop 1000000007
#define mop2 998244353

using namespace std;

int main() {
	string s;
	cin >> s;
	for (auto i : s) {
		if (i == '?') {
			cout << 'D';
		}
		else {
			cout << i;
		}
	}
	cout << endl;
}

Measured memory_bytes: 3752
# 入力
n = gets.to_i
a = gets.chomp.split.map(&:to_i)
# 配列から偶数をだす
even = a.select{|x|x%2==0}

# 3と５で割れるかの判定
flag = true
even.each do|i|
 if i%3==0 || i%5==0
    next
  else
    flag = false
    break
 end
end

if flag
   puts "APPROVED"
else
   puts "DENIED"
end

Measured memory_bytes: 1788
#include <iostream>
using namespace std;
    
int main() {
  int a, b;
  cin >> a >> b;
  while (!(a == 0 && b == 0)) {
    if (a > b) {cout << b << " " << a << endl;}
    else {cout << a << " " << b << endl;}

    cin >> a >> b;
  }
  return 0;
}


Measured memory_bytes: 2980
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <limits>
#include <iomanip>
#include <bitset>
#include <queue>

using namespace std;
typedef long long ll;

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
#define REP(i, n) for(int i = 0;i < n;i++)
const long long INF = 1LL << 60;

int MOD = 1000000007;



int main(){
    std::ios_base::sync_with_stdio(false);

    int n,m; cin >> n >> m;

    std::vector<bool> v(m, true);

    REP(i, n){
        int k; cin >> k;
        std::vector<int> love;
        REP(j, k){
            int a; cin >> a;
            love.push_back(a-1);
        }

        REP(j, m){
            if(find(love.begin(), love.end(), j) ==  love.end()){
                v[j] = v[j] & false;
            }
        }
    }

    int ans = 0;
    REP(i, m) if(v[i]) ans++;

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>

int main(){
  int n, i=1;
  std::cin >> n;

  while(++i<=n){
    int x=i;
    if( x%3 == 0 ){
      std::cout << " " << i;
      continue;
    }
    while(x){
      if( x%10 == 3 ){
        std::cout << " " << i;
        break;
      }
      x/=10;
    }
  }
  std::cout << std::endl;
  return 0;
}



Measured memory_bytes: 3088
class AC:
    @staticmethod
    def inputStr(char):
        return input().split(char)
    
    @staticmethod
    def inputInt(char):
        a = input().split(char)
        for i in range(len(a)):
            a[i] = int(a[i])
        return a

A = AC.inputInt(" ")

if (A[0]+A[1]+A[2] < 22):
    print("win")
else:
    print("bust")

Measured memory_bytes: 3060
#include<iostream>
#include<algorithm>
#include<cassert>
#include<cmath>
#include<vector>
#include<iomanip>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
#define inf (1<<29)

using namespace std;

int K;
double L,R,P,E,T;

double dfs(int depth,double l,double r)
{
  double t = (l+r)/2.0;
  if(depth >= K)
    {
      if(fabs(T-t)<E)return 1;
      return 0;
    }  

  if(l < T-E || T+E < r)return 0;

  if(T <= t)
    {
      return (1-P)*dfs(depth+1,t,r) + P*dfs(depth+1,l,t);
    }
  else 
    {
      return (1-P)*dfs(depth+1,l,t) + P*dfs(depth+1,t,r);
    }

}

int main()
{
  cin >> K >> R >> L >> P >> E >> T;
  cout << setiosflags(ios::fixed) << setprecision(5) << dfs(0,L,R) << endl;
  return 0;
}

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

int main()
{
    long N;
    cin >> N;
    long ans = 0;
    long waru = 5;
    if(N%2 != 0)
        cout << 0 << endl;
    else{
        N /= 2;
        REP(i, 40){
            ans += (N/waru);
            N /= waru;
            if(N == 0)
                break;
        }
        cout << ans << endl;
    }
    
    return 0;
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
using i64 = int_fast64_t;
#define rep(i, N) for(int (i) = 0; (i) < (N); (i)++)
#define all(v) (v).begin(), (v).end()
#define eb emplace_back
#define Cout(s) cout << s << endl
string Yes(bool b) {if(b){return "Yes";} else {return "No";}}
string YES(bool b) {if(b){return "YES";} else {return "NO";}}

int main(){
	int N;
	cin >> N;
	set<int> st;
	rep(i, N) {
		int A; cin >> A;
		st.insert(A);
	}

	cout << st.size() - (st.size() + 1) % 2 << endl;
}



Measured memory_bytes: 4992
#include<bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
const long long mod = 1e9+7;
//////////////////////////////////

int main(){
  int x; cin >> x;
  for(int i=0; i<=1000; i++) {
    if (100 * i <= x && x <= 105 * i) {
      cout << 1 << endl;
      return 0;
    }
  }
  cout << 0 << endl;

}

// EOF

Measured memory_bytes: 256
M=10**6+1
f=lambda p: exit(print(['pairwise','setwise','not'][p]+' coprime'))
n=int(input())
l=[*map(int,input().split())]
g=0
from math import *
for x in l:
  g=gcd(g,x)
if g>1: f(2)
def sieve(x):
  p=[]
  s=[0]*x
  for i in range(2,x):
    if s[i]<1:
      p+=[i]
      for j in range(i,x,i): s[j]=i
  return s
s=sieve(M)
C=[0]*M
for x in l:
  t=set()
  while x>1:
    t.add(s[x])
    x//=s[x]
  for y in t:
    if C[y]: f(1)
    C[y]=1
f(0)

Measured memory_bytes: 127160
import itertools
import math
def getdis(a,b):
  return math.sqrt((b[0] - a[0])**2+(b[1]-a[1])**2)

N = int(input())

city = []
l = [i for i in range(N)]
for i in range(1,N+1):
  x,y = map(int,input().split())
  city.append([x,y])
  
l = list(itertools.permutations(l))
sum_dis = [0]*len(l)
for i in range(len(l)):
  for j in range(N-1):
    sum_dis[i]+=getdis(city[l[i][j]],city[l[i][j+1]])
print(sum(sum_dis)/len(l))   

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

string s[105];
int main() {
    // freopen("lucky.in", "r", stdin);
    // freopen("lucky.out", "w", stdout);
    int n, m;
    cin >> n >> m;
    for (int i = 0; i <= m + 1; i++) cout << "#";
    cout << endl;
    for (int i = 1; i <= n; i++)
    {
        cin >> s[i];
        cout << "#" + s[i] + "#" << endl;
    }    
    for (int i = 0; i <= m + 1; i++) cout << "#";
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		try (Scanner in = new Scanner(System.in)) {
			int n = in.nextInt();
			int a = in.nextInt();

			System.out.printf("%d\n", n*n-a);
		} catch (Exception ex) {
			throw new RuntimeException(ex);
		}
	}
}	


Measured memory_bytes: 23124
#include<bits/stdc++.h>
     
    using namespace std;
     
    int main(){
      int a,b,c;
      cin >> a >> b >> c;
      
      if(c - (a - b) < 0){
        cout << 0;
      }
      else{
        cout << c - (a-b);
      }
      return 0;
    }

Measured memory_bytes: 256
import numpy as np
 
N,M=[int(i) for i in input().split()]
x=input().split()
y=[int(i) for i in x]
y.sort()
if(N==1):
    print(max(y)-min(y))
#    print(y[M-1]-y[0])
    exit()
if(M==1):
    print("0")
    exit()
if(N>=M):
    print("0")
    exit()
diff=[]
for i in range(M-1):
    diff.append(y[i+1]-y[i])
sub=[]
array=np.array(diff)
index=np.argsort(array)
c=index[-1::-1]
for i in range(N-1):
    sub.append(c[i])
ans=0
for i in range(N):
    if(i==0):
        ans+=y[sub[i]]-y[0]
    elif(i==N-1):
        ans+=y[M-1]-y[sub[i-1]+1]
    else:
        ans+=y[sub[i]]-y[sub[i-1]+1]
print(ans)


Measured memory_bytes: 28068
//#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <string>
#include <vector>
#include <map>
#include <queue>

using namespace std;

typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<n;++i)
#define mod (ll)(1e9+7)
#define FIX(a) ((a)%mod+mod)%mod
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define fi first
#define se second
#define pb push_back
int dy[]={0, 0, 1, -1};
int dx[]={1, -1, 0, 0};
ll gcd(ll a, ll b ){
    ll r, tmp;
    if(a<b){
        tmp = a;
        a = b;
        b = tmp;
    }
    r = a % b;
    while(r!=0){
        a = b;
        b = r;
        r = a % b;
    }
    return b;
}
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,k;
    cin >> n >> k;
    vll a(n);
    bool f = false;
    REP(i,n) {
        cin >> a[i];
        if(a[i]>=k) f=true;
    }
    if(f==false){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    ll x = a[n-1];
    REP(i,n-1){
        x = gcd(x,a[i]);
    }
    if(k%x==0){
        cout << "POSSIBLE" << endl;
    }else{
        cout << "IMPOSSIBLE" << endl;
    }

    return 0;
}

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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define ALL(V) (V).begin(),(V).end()
#define CERR if(false) cerr
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;

typedef long long ll;

int main(){

    vector<vector<int>> a(3, vector<int>(3));

    rep(i, 3){
        rep(j,3){
            cin >> a[i][j];
        }
    }

    int n;
    cin >> n;

    vector<vector<bool>> bingo(3, vector<bool>(3, false));

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

        rep(j, 3){
            rep(k, 3){
                if(a[j][k] == tmp){
                    bingo[j][k] = true;
                }
            }
        }
    }

    bool ans = false;

    rep(i, 3){
        if(bingo[i][0] && bingo[i][1] && bingo[i][2]) ans = true;
    }

    rep(i, 3){
        if(bingo[0][i] && bingo[1][i] && bingo[2][i]) ans = true;
    }

    if(bingo[0][0] && bingo[1][1] && bingo[2][2]) ans = true;
    if(bingo[0][2] && bingo[1][1] && bingo[2][0]) ans = true;

    if(ans){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IL inline
IL int read() {
	char ch = getchar(); int u = 0, f = 1;
	while (!isdigit(ch)) { if (ch == '-') f = -1; ch = getchar(); }
	while (isdigit(ch)) { u = (u << 1) + (u << 3) + ch - 48; ch = getchar(); }
	return u * f;
}

int main() {
	int a = read(), b = read(), k = read();
	int ct = 0;
	while (k--) {
		ct++;
		if (ct % 2 == 1) {
			if (a % 2 == 1) a--;
			a /= 2;
			b += a;
		}
		else {
			if (b % 2 == 1) b--;
			b /= 2;
			a += b;
		}
	}
	cout << a << " " << b << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

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

    std::string ans = "x";
    if(15 == a + b){
        ans = "+";
    }else if(15 == a * b){
        ans = "*";
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 888
#include <cstdio>
#include <algorithm>
#include <vector>
#include <functional>
using namespace std;

int main(void)
{
	int n, m;
	
	while (scanf("%d %d", &n, &m)){
		if (n == 0 && m == 0) break;
		
		vector <int> v;
		int tmp;
		for (int i = 0; i < n; i++){
			scanf("%d", &tmp);
			v.push_back(tmp);
		}
		sort(v.begin(), v.end(), greater<int>());
		
		int res = 0;
		int sum = 0;
		for (int i = 0; i < n; i++){
			if ((i + 1) % m == 0) {
				sum += v[i];
			}
			res += v[i];
		}
		
		printf("%d\n", res - sum);
	}
	
	return (0);
}

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

const int MOD = 998244353;
const int MAX_N = 3005;
int N, S;
int A[MAX_N];

ll dp[MAX_N][MAX_N]; // len, sum

ll powmod(ll x, int y)
{
	ll res = 1;
	while(y){
		if(y&1) (res*=x)%=MOD;
		(x*=x)%=MOD;
		y>>=1;
	}
	return res;
}

void solve()
{
	dp[0][0]=powmod(2,N);
	for(int i=0;i<N;++i)for(int j=0;j<=S;++j){
		(dp[i+1][j]+=dp[i][j])%=MOD;
		if(j+A[i]<=S) (dp[i+1][j+A[i]]+=dp[i][j]*powmod(2,MOD-2)%MOD)%=MOD;
	}
	cout<<dp[N][S];
}

int main()
{
	cin >> N >> S;
	for(int i=0;i<N;++i) cin >> A[i];
	solve();
	return 0;
}

Measured memory_bytes: 74056
n, m = list(map(int, input().split()))
li = []
yli = []
for _ in range(m):
    p, y = list(map(int, input().split()))
    li.append((y, p))
    yli.append(y)

import numpy as np
idx = np.argsort(yli).argsort()
srt = sorted(li)
ans = []
from collections import Counter
pcnt = Counter()
for y, p in srt:
    pcnt[p] += 1
    ans.append('{:06}{:06}'.format(p, pcnt[p]))

for i in idx:
    print(ans[i])


Measured memory_bytes: 46316
import cmath
from math import pi

N=int(input())
p=[]
for i in range(N):
    x,y=map(int,input().split())
    if (x,y)!=(0,0):
        z=complex(x,y)
        arg=cmath.phase(z)
        p.append((arg,z))

EPS=10**-6
N=len(p)
q=[(p[i][0],i) for i in range(N)]
q.sort()
p=[p[q[i][1]] for i in range(N)]
ans=0
for i in range(N):
    z=0
    for j in range(N):
        if EPS>=abs(cmath.phase(p[j][1]/p[i][1])-pi/2)-pi/2 and (abs(cmath.phase(p[j][1]/p[i][1]))-pi)<EPS and not (abs(cmath.phase(p[j][1]/p[i][1])))<EPS:
            z+=p[j][1]
    ans=max(ans,abs(z))

for i in range(N):
    z=0
    for j in range(N):
        if EPS>=abs(cmath.phase(p[j][1]/p[i][1])-pi/2)-pi/2 and (abs(cmath.phase(p[j][1]/p[i][1]))-pi)<EPS:
            z+=p[j][1]
    ans=max(ans,abs(z))

for i in range(N):
    z=0
    for j in range(N):
        if EPS>=abs(cmath.phase(p[j][1]/p[i][1])+pi/2)-pi/2 and (abs(cmath.phase(p[j][1]/p[i][1]))-pi)<EPS and not (abs(cmath.phase(p[j][1]/p[i][1])))<EPS:
            z+=p[j][1]
    ans=max(ans,abs(z))

for i in range(N):
    z=0
    for j in range(N):
        if EPS>=abs(cmath.phase(p[j][1]/p[i][1])+pi/2)-pi/2 and (abs(cmath.phase(p[j][1]/p[i][1]))-pi)<EPS :
            z+=p[j][1]
    ans=max(ans,abs(z))

print(ans)

Measured memory_bytes: 61936
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
using namespace std;

#define rep(i,a,n) for(int (i)=(a); (i)<(n); (i)++)
#define repq(i,a,n) for(int (i)=(a); (i)<=(n); (i)++)
#define repr(i,a,n) for(int (i)=(a); (i)>=(n); (i)--)
#define all(v) begin(v), end(v)
#define pb(a) push_back(a)
#define fr first
#define sc second
#define INF 2000000000
#define int long long int

#define X real()
#define Y imag()
#define EPS (1e-10)
#define EQ(a,b) (abs((a) - (b)) < EPS)
#define EQV(a,b) ( EQ((a).X, (b).X) && EQ((a).Y, (b).Y) )
#define LE(n, m) ((n) < (m) + EPS)
#define LEQ(n, m) ((n) <= (m) + EPS)
#define GE(n, m) ((n) + EPS > (m))
#define GEQ(n, m) ((n) + EPS >= (m))

typedef vector<int> VI;
typedef vector<VI> MAT;
typedef pair<int, int> pii;
typedef long long ll;

typedef complex<double> P;
typedef pair<P, P> L;
typedef pair<P, double> C;

int dx[]={1, -1, 0, 0};
int dy[]={0, 0, 1, -1};
int const MOD = 1000000007;
ll mod_pow(ll x, ll n) {return (!n)?1:(mod_pow((x*x)%MOD,n/2)*((n&1)?x:1))%MOD;}
int madd(int a, int b) {return (a + b) % MOD;}
int msub(int a, int b) {return (a - b + MOD) % MOD;}
int mmul(int a, int b) {return (a * b) % MOD;}
int minv(int a) {return mod_pow(a, MOD-2);}
int mdiv(int a, int b) {return mmul(a, minv(b));}

namespace std {
    bool operator<(const P& a, const P& b) {
        return a.X != b.X ? a.X < b.X : a.Y < b.Y;
    }
}

signed main() {
    int n; cin >> n;
    vector<string> vs(n);
    rep(i,0,n) {
        cin >> vs[i];
    }
    string t; cin >> t;

    int prev = 0, aft = 0;
    rep(i,0,n) {
        int flag = 0;
        rep(j,0,min(t.length(), vs[i].length())) {
            if(vs[i][j] == '?') {
                if(t[j] != 'z') {
                    flag = INF;
                    break;
                }
            }
            if(vs[i][j] < t[j]) {
                flag = 1;
                break;
            }
            if(vs[i][j] > t[j]) {
                flag = 2;
                break;
            }
        }
        // printf("flag = %lld\n", flag);
        if(flag == 0) {
            if(t.length() > vs[i].length()) prev++;
            else if(t.length() < vs[i].length()) aft++;
        }
        if(flag == 1) prev++;
        if(flag == 2) aft++;
    }

    //printf("prev = %lld, aft = %lld\n", prev, aft);
    int st = prev + 1, en = n - aft + 1;
    //printf("st = %lld, en = %lld\n", st, en);
    repq(i,st,en) {
        if(i == st) printf("%lld", i);
        else printf(" %lld", i);
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 896
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <queue>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <tuple>
#include <deque>
#include <numeric>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <chrono>
#include <random>
#include <limits>
#include <iterator>
#include <functional>
#include <sstream>
#include <complex>
using namespace std;

typedef long long ll;
typedef uint64_t ull;
typedef pair<int, int> P;
typedef pair<int, double> Pid;
typedef pair<double, int> Pdi;
typedef pair<ll, int> Pl;
typedef pair<ll, ll> Pll;
typedef pair<int, pair<int, int>> PP;
typedef pair<P, int> PPi;
constexpr double PI = 3.1415926535897932;   // acos(-1)
constexpr double EPS = 1e-9;
constexpr int INF = 1001001001;
constexpr int mod = 1000000007;
// constexpr int mod = 998244353;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define chadd(x, y) x = (x + y) % mod

bool red[100005];

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

    int n, m;
    cin >> n >> m;
    red[0] = true;
    vector<int> cnt(n, 1);
    for(int i = 0; i < m; ++i){
        int x, y;
        cin >> x >> y;
        --x, --y;
        if(red[x]){
            if(cnt[x] == 1) red[x] = false;
            red[y] = true;
        }
        --cnt[x], ++cnt[y];
    }
    int ans = 0;
    for(int i = 0; i < n; ++i){
        if(red[i])  ++ans;
    }
    cout << ans << endl;
}

Measured memory_bytes: 768
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

class UnionFind():
    def __init__(self, n):
        self.n = n
        # parents[i]: 要素iの親要素の番号
        # 要素iが根の場合、parents[i] = -(そのグループの要素数)
        self.parents = [-1] * n
    def find(self, x):
        if 0 > self.parents[x]:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x
    # 要素xが属するグループの要素数を返す
    def size(self, x):
        return -self.parents[self.find(x)]
    def same(self, x, y):
        return self.find(x) == self.find(y)
    # 要素xが属するグループに属する要素をリストで返す
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]
    # 全ての根の要素をリストで返す
    def roots(self):
        return [i for i, x in enumerate(self.parents) if 0 > x]
    # グループの数を返す
    def group_count(self):
        return len(self.roots())
    # 辞書{根の要素: [そのグループに含まれる要素のリスト], ...}を返す
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}
    # print()での表示用
    # all_group_members()をprintする
    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())
	
N, M = MAP()

tree = UnionFind(N)

for _ in range(M):
	X, Y, Z = MAP()
	tree.union(X-1, Y-1)

print(tree.group_count())


Measured memory_bytes: 9928
n = int(input())
a=list(map(int, input().split()))
a.sort()
A = []
B = []
for i in range(1,n+1):
    if i % 2 != 0:
        A.append(a[-i])
    else:
        B.append(a[-i])
print(sum(A) - sum(B))

Measured memory_bytes: 9048
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define FOR(i,start,end) for(int i=start;i<=end;i++)
const int INF = 1001001001;
using namespace std;
typedef long long ll;

int main()
{
  int N, M;
  int L[110000];
  int R[110000];
  int res=0;
  cin >> N >> M;

  rep(i,M){
    cin >> L[i] >> R[i];
  }

  int l=1;
  int r=N;
  rep(i,M){
    l = max(l, L[i]);
    r = min(r, R[i]);
  }

  res = max(0, r-l+1);

  cout << res << endl;
}

Measured memory_bytes: 1024
using System;
using System.Linq;
using System.Collections.Generic;
class Program
{

    static void Main(string[] args)
    {
        
        long n = long.Parse(Console.ReadLine());
        long[] inp = null;
        inp = Console.ReadLine().Split(' ').Select(z => long.Parse(z)).ToArray();

        List<long> heap = new List<long>();

        heap.Add(0);


        for (int i = 0; i < inp.Length; i++)
        {
            heap.Add(inp[i]);
        }

        for (int i = 1; i < heap.Count; i++)
        {
            int pix = i > 1 ? i / 2 : -1;
            int lix = i * 2 < heap.Count ? i * 2 : -1;
            int rix = i * 2 + 1 < heap.Count ? i * 2 + 1 : -1;

            string s = "node " + i.ToString() + ": key = " + heap[i].ToString() + ", ";
            s += pix > -1 ? "parent key = " + heap[pix].ToString() + ", " : "";
            s += lix > -1 ? "left key = " + heap[lix].ToString() + ", " : "";
            s += rix > -1 ? "right key = " + heap[rix].ToString() + ", " : "";

            Console.WriteLine(s);
        }

    }
}



Measured memory_bytes: 18368
#include <bits/stdc++.h>
#define pb push_back
#define ff first
#define ss second
using namespace std;
using ll = long long;
using vi = vector<int>;
using pii = pair<ll, ll>;
ll a[200005], b[200005];
int n;
int main() {
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> a[i] >> b[i];
  }
  sort(a + 1, a + n + 1);
  sort(b + 1, b + n + 1);
  if (n & 1) {
    cout << (b[int(ceil(n / 2.0))] - a[int(ceil(n / 2.0))] + 1) << endl;
  } else {
    ll lo = (a[n / 2 + 1] + a[n / 2]);
    ll hi = (b[n / 2 + 1] + b[n / 2]);
    // cout << hi << ' ' << lo << endl;
    cout << hi - lo + 1 << endl;
  }
}

Measured memory_bytes: 6736
#define MOD_TYPE 1

#pragma region Macros
#include <bits/stdc++.h>
using namespace std;

#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
using multiInt = boost::multiprecision::cpp_int;
using lld = boost::multiprecision::cpp_dec_float_100;

#pragma GCC target("avx2")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

using ll = long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
template <typename Q_type>
using smaller_queue = priority_queue<Q_type, vector<Q_type>, greater<Q_type>>;

constexpr ll MOD = (MOD_TYPE == 1 ? (ll)(1e9 + 7) : 998244353);
//constexpr ll MOD = 1;
constexpr int INF = (int)1e9;
constexpr ll LINF = (ll)4e18;
constexpr double PI = acos(-1.0);
constexpr double EPS = 1e-10;
constexpr int Dx[] = {0, 0, -1, 1, -1, 1, -1, 1, 0};
constexpr int Dy[] = {1, -1, 0, 0, -1, -1, 1, 1, 0};

#define REP(i, m, n) for (ll i = m; i < (ll)(n); ++i)
#define rep(i, n) REP(i, 0, n)
#define REPI(i, m, n) for (int i = m; i < (int)(n); ++i)
#define repi(i, n) REPI(i, 0, n)
#define MP make_pair
#define MT make_tuple
#define YES(n) cout << ((n) ? "YES" : "NO") << "\n"
#define Yes(n) cout << ((n) ? "Yes" : "No") << "\n"
#define possible(n) cout << ((n) ? "possible" : "impossible") << "\n"
#define Possible(n) cout << ((n) ? "Possible" : "Impossible") << "\n"
#define Yay(n) cout << ((n) ? "Yay!" : ":(") << "\n"
#define all(v) v.begin(), v.end()
#define NP(v) next_permutation(all(v))
#define dbg(x) cerr << #x << ":" << x << "\n";

inline void init_main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout << setprecision(30) << setiosflags(ios::fixed);
}
template <typename T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <typename T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
inline ll CEIL(ll a, ll b)
{
  return (a + b - 1) / b;
}
template <typename A, size_t N, typename T>
inline void Fill(A (&array)[N], const T &val)
{
  fill((T *)array, (T *)(array + N), val);
}
template <typename T, typename U>
constexpr ostream &operator<<(ostream &os, pair<T, U> &p) noexcept
{
  os << p.first << " " << p.second;
  return os;
}
#pragma endregion

void solve()
{
  int n;
  cin >> n;
  vector<multiInt> v(n);
  rep(i, n)
  {
    cin >> v[i];
    if (v[i] == 0)
    {
      cout << 0 << "\n";
      return;
    }
  }
  multiInt p = 1;
  rep(i, n)
  {
    p *= v[i];
    if (p > (multiInt)(1000000000000000000))
    {
      cout << -1 << "\n";
      return;
    }
  }

  cout << p << "\n";
}

int main()
{
  init_main();

  solve();

  return 0;
}

Measured memory_bytes: 6440
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
using namespace std;
const int maxn=1e5+10;
typedef long long LL;
int id[maxn],s1[maxn],t1[maxn],t2[maxn];
LL d[maxn],d2[maxn];
int read()
{
    char ch=getchar();
    int x=0,f=1;
    while(!isdigit(ch))
    {
        f=(ch=='-')?-f:f;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        x=x*10+ch-'0';
        ch=getchar();
    }
    return f<0?-x:x;
}
int main()
{
    int n=read();
    for(int i=1;i<=n;i++) d[i]=read();
    LL left=d[1];
    for(int i=1;i<n;i++) d[i]=d[i+1]-d[i];
    LL k;int m=read();
    scanf("%lld",&k);
    for(int i=1;i<n;i++) id[i]=i;
    for(int i=1;i<=m;i++)
    {
        int t=read();
        swap(id[t-1],id[t]);
    }
    for(int i=1;i<n;i++) s1[id[i]]=i;
    int *cur=t1,*nxt=t2;
    for(int i=1;i<n;i++) cur[i]=s1[i];
    int w=0;
    while((k>>w)>1)w++;
    while(w>0)
    {
        --w;
        for(int i=1;i<n;i++) nxt[i]=cur[cur[i]];
        swap(nxt,cur);
        if((k>>w)&1)
        {
            for(int i=1;i<n;i++) nxt[i]=s1[cur[i]];
            swap(nxt,cur);
        }
    }
    for(int i=1;i<n;i++) d2[cur[i]]=d[i];
    printf("%lld\n",left);
    for(int i=1;i<n;i++) printf("%lld\n",left+=d2[i]);
    return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define all(n) begin(n), end(n)
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
int main()
{
    int R,C,K;
    cin>>R>>C>>K;
    auto goods = make_v<ll>(R+1,C+1);
    auto dp = make_v<ll>(R+1,C+1,4);
    for (size_t i = 0; i < K; i++)
    {
        int r,c,v;
        cin>>r>>c>>v;
        goods[r-1][c-1]=v;
    }
    if(goods[0][0]>0)
    {
        dp[0][0][1]=goods[0][0];
    }
        ll ans=0;
    for (ll i = 0; i < R; i++)
    {
        for (ll j = 0; j < C; j++)
        {
            for (int k = 0; k < 4; k++)
            {
                chmax(dp[i][j+1][k],dp[i][j][k]);
                if(k>0 and goods[i][j+1]>0)
                {
                    chmax(dp[i][j+1][k],dp[i][j][k-1]+goods[i][j+1]);
                }
                chmax(dp[i+1][j][0],dp[i][j][k]);
                if(goods[i+1][j]>0)
                {
                    chmax(dp[i+1][j][1],dp[i+1][j][0]+goods[i+1][j]);
                }
                chmax(ans,dp[i][j+1][k]);
                chmax(ans,dp[i+1][j][k]);
                chmax(ans,dp[i][j][k]);
            }
            
        }
        
    }

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

Measured memory_bytes: 707192
import sys;input=lambda:sys.stdin.readline().rstrip();aint=lambda:int(input());ints=lambda:list(map(int,input().split()))
import math;floor,ceil=math.floor,math.ceil
from collections import deque
Yes=lambda b:print('Yes')if b else print('No');YES=lambda b:print('YES')if b else print('NO')
is_even=lambda x:True if x%2==0 else False

def main():
    k,n=ints();a=ints()
    a.append(a[0]+k);diff=[a[i+1]-a[i]for i in range(n)]
    print(k-max(diff))

if __name__ == '__main__':
    main()

Measured memory_bytes: 26800
// https://atcoder.jp/contests/abc128/tasks/abc128_b
#include <bits/stdc++.h>
using namespace std;

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

int main() {
  int N;
  cin >> N;
  vector<tuple<string, int, int>> p1(N);
  rep(i, N) {
    int n;
    cin >> get<0>(p1.at(i)) >> n;
    get<1>(p1.at(i)) = -n;
    get<2>(p1.at(i)) = i + 1;
  }
  sort(p1.begin(), p1.end());

  rep(i, N) cout << get<2>(p1.at(i)) << endl;
  return 0;
}


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

using namespace std;
typedef long long ll;

int main() {
  ll h, w;
  cin >> h >> w;
  if (h == 1 || w == 1) {
    cout << 1 << '\n';
    return 0;
  }
  ll ans1 = ((w + 1) / 2) *  ((h + 1) / 2);
  ll ans2 = (w / 2) * (h / 2);
  cout << ans1 + ans2 << '\n';
  return 0;
}



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

 int main()
 {
  int n;
    cin>>n;
    
    if(n<2)
        {
        cout<<1<<endl;
        }
        else if(n<4)
            {
                cout<<2<<endl;
            }
        else if(n<8)
        {
            cout<<4<<endl;
        }
        else if(n<16)
        {
            cout<<8<<endl;
        }
        else if(n<32)
        {
            cout<<16<<endl;
        }
        else if(n<64)
        {
            cout<<32<<endl;
        }
        else
        {
            cout<<64<<endl;
        }

return 0;
 }


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

int main(int argc, const char * argv[]) {
    int N = 0, K = 0;
    scanf("%d%d", &N, &K);
    
    int x[102000];
    
    for(int i = 0; i < N; i++){
        scanf("%d", &x[i]);
    }
    
    long long int sum_total[120000];
    for(int i = 0; i <= N - K; i++){
        long long int sum = 0;
        if((x[i] < 0 && x[i+K-1] > 0) ||(x[i] > 0 && x[i+K-1] < 0) ){
            if(abs(x[i]) >= abs(x[i+K-1])){
                sum = abs(x[i]) + abs(x[i+K-1]) * 2;
            }else{
                sum = abs(x[i]) * 2 + abs(x[i+K-1]);
            }
        }else{
            if(x[i] < 0){
                sum = abs(x[i]);
            }else{
                sum = abs(x[i+K-1]);
            }
        }
        sum_total[i] = sum;
    }
    
    long long int min = 100000000000;
    
    for(int i = 0; i <= N - K; i++){
        if(min > sum_total[i])
            min = sum_total[i];
    }
    printf("%lld\n", min);
    return 0;
}

Measured memory_bytes: 896
#include<iostream>
#define ll long long
using namespace std;
int main(){
	ll N,M;
	cin>>N>>M;
	ll t,sum=0;
	for(int i=0;i<M;i++){
		cin>>t;
		sum=sum+t;
	}
	if(N-sum<0){
		cout<<-1;
	}else{
		cout<<N-sum;
	}
	return 0;
}

Measured memory_bytes: 3192
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
	long long n,i,k,j,sum=0,count=0,ans=0,m,w,mx=0,l,r;
	cin>>k>>n;
    long long a[n],b[n];
    for(i=0;i<n;i++)
    cin>>a[i];
	b[0]=a[0]+k-a[n-1];
	for(i=1;i<n;i++)
	b[i]=a[i]-a[i-1];
	sort(b,b+n);
	cout<<k-b[n-1];
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
//#include <atcoder/all>
using namespace std;
using ll = long long;
//const int mod = 1000000007;
const int mod = 998244353;
const double PI = acos(-1);

class Mint
{
private:
	ll x;
public:
	Mint(ll x = 0) :x((x% mod + mod) % mod) {}
	ll Get() const { return x; }
	Mint operator-() const { return Mint(-x); }
	Mint& operator+=(const Mint a)
	{
		if ((x += a.x) >= mod) x -= mod;
		return *this;
	}
	Mint& operator-=(const Mint a)
	{
		if ((x += mod - a.x) >= mod) x -= mod;
		return *this;
	}
	Mint& operator*=(const Mint a) { (x *= a.x) %= mod; return *this; }
	Mint operator+(const Mint a) const { return Mint(*this) += a; }
	Mint operator-(const Mint a) const { return Mint(*this) -= a; }
	Mint operator*(const Mint a) const { return Mint(*this) *= a; }
	Mint pow(ll t) const
	{
		if (!t) return 1;
		Mint a = pow(t >> 1);
		a *= a;
		if (t & 1) a *= *this;
		return a;
	}

	// for prime mod
	Mint inv() const { return pow(mod - 2); }
	Mint& operator/=(const Mint a) { return *this *= a.inv(); }
	Mint operator/(const Mint a) const { return Mint(*this) /= a; }
};
inline ostream& operator<<(ostream& os, const Mint& a) { return os << a.Get(); }

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

	vector<Mint> dp(n + 1);
	dp[1] = 1;
	vector<Mint> dpSum(n + 1);
	dpSum[1] = 1;
	for (int i = 2; i <= n; i++) {
		for (int j = 0; j < k; j++) {
			int li = i - r[j];
			int ri = i - l[j];
			if (ri < 1) continue;
			li = max(li, 1);
			dp[i] += dpSum[ri] - dpSum[li - 1];
		}
		dpSum[i] = dpSum[i - 1] + dp[i];
	}
	cout << dp[n] << endl;
}


Measured memory_bytes: 7932
def selectionSort(A, N):
    count = 0
    for i in range(N):
        minj = i
        for j in range(i,N):
            if A[j] < A[minj]:
                minj = j
        if i != minj:        
            ho = A[i]
            A[i] = A[minj]
            A[minj] = ho
            count += 1
    return A, count

n = int(input())
a = [ int(i) for i in input().split()]
b , count = selectionSort(a,n)
for i in range(len(b)):
    if i == len(b)-1:
        print(b[i])
    else:
        print(b[i],end=' ')            
print(count)


Measured memory_bytes: 5608