akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

const int INF = 1000000000;


#define NDEBUG


#ifndef NDEBUG
void print_grid(int h, int w, int grid[h][w])
{
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (grid[y][x] == 0) {
        fprintf(stderr, "   %c", '#');
      } else if (grid[y][x] == INF) {
        fprintf(stderr, "   %c", '.');
      } else {
        fprintf(stderr, "%4d", grid[y][x]);
      }
    }
    fprintf(stderr, "\n");
  }
  fprintf(stderr, "\n");
}
#endif

int main(void)
{
  int h, w;
  scanf("%d%d", &h, &w);
  int grid[h][w];

  for (int y = 0; y < h; y++) {
    char s[w + 1];
    scanf("%s", s);
    for (int x = 0; x < w; x++) {
      grid[y][x] = s[x] == '#' ? 0 : INF;
    }
  }

#ifndef NDEBUG
  print_grid(h, w, grid);
#endif

  for (int y = 0; y < h; y++) {
    for (int x = 1; x < w; x++) {
      if (grid[y][x] > grid[y][x - 1] + 1) {
        grid[y][x] = grid[y][x - 1] + 1;
      }
      int xx = w - 1 - x;
      if (grid[y][xx] > grid[y][xx + 1] + 1) {
        grid[y][xx] = grid[y][xx + 1] + 1;
      }
    }
  }

#ifndef NDEBUG
  print_grid(h, w, grid);
#endif

  for (int x = 0; x < w; x++) {
    for (int y = 1; y < h; y++) {
      if (grid[y][x] > grid[y - 1][x] + 1) {
        grid[y][x] = grid[y - 1][x] + 1;
      }
      int yy = h - 1 - y;
      if (grid[yy][x] > grid[yy + 1][x] + 1) {
        grid[yy][x] = grid[yy + 1][x] + 1;
      }
    }
  }

#ifndef NDEBUG
  print_grid(h, w, grid);
#endif

  int ans = 0;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      if (ans < grid[y][x]) {
        ans = grid[y][x];
      }
    }
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 4096
def check(xa, ya, ra, xb, yb, rb)
  d = ((xa - xb) ** 2 + (ya - yb) ** 2) ** 0.5
  if (ra - rb) * (ra <=> rb) > d
    return 2 * (ra <=> rb)
  elsif ra + rb < d
    return 0
  else
    return 1
  end
end
def main(input = $stdin)
  n = input.gets.to_i
  n.times do
    puts check(*input.gets.split(" ").map(&:to_f))
  end
end
main

Measured memory_bytes: 6168
#define _CRT_SECURE_NO_WARNINGS

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

typedef unsigned int uint;
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<ii> vii;
typedef vector<vi> vvi;
typedef map<int, int> mii;
typedef map<string, int> msi;
typedef map<int, string> mis;
typedef pair<int, ii> edge;


#define sc(x)  scanf("%d",&x)
#define scl(x) scanf("%lld",&x)
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define mem(arr,val) memset(arr,val,sizeof arr)
#define sz(v) (int)v.size()
#define rsz(v) v.resize
#define clr(v) v.clear()
#define rev(v) reverse(all(v))
#define lop(i,end) for(int i=0; i<end; i++)
#define rlop(i,start) for(int i=start-1; i>=0; i--)
#define loop(i,start,end) for(int i=start; i<end; i++)
#define rloop(i,start,end) for(int i=start-1; i>=end; i--)
#define PB push_back
#define pb pop_back
#define mP make_pair
#define f first
#define s second

const ll OO = (4e18) + 9;
const int MOD = (1e9) + 7;
const int oo = 2147483647;
const double EPS = 1e-8;
const double PI = acos(-1.0);

//enum dir { r, d, l, u };
int dx[] = { 0, 1, 0,-1 };
int dy[] = { 1, 0,-1, 0 };

//enum diR { d, r, u, l , dr, ur, dl, ul };
int dX[] = { 1, 0, -1, 0, 1, -1, 1, -1 };
int dY[] = { 0, 1, 0, -1, 1, 1, -1, -1 };

string abc = "abcdefghijklmnopqrstuvwxyz";
string vowels = "aeiou"; //and sometimes "aeiouy"

int dcmp(ld d1, ld d2) { return fabs(d1 - d2) <= EPS ? 0 : d1 > d2 ? 1 : -1; } //Compare Double Numbers
ll gcd(ll x, ll y) { return !y ? x : gcd(y, x%y); }
ll lcm(ll a, ll b) { return a * (b / gcd(a, b)); }
//convert index from 2D matrix to 1D array. (Zero-indexed)
int ord(int r, int c, int nCol) { return (nCol*r) + c + 1; }
//convert index from 1D array to 2D matrix . (One-indexed)
ii rord(int n, int nCol) {
	int r = n%nCol, c = n / nCol;
	if (n%nCol == 0) c--, r = nCol;
	return ii(r, c);
}

ll poww(ll num, ll p, ll md = MOD) {
	num %= md;
	ll ret = 1;
	while (p > 0) {
		if (p & 1) ret = (ret * num) % md;
		num = (num * num) % md;
		p >>= 1;
	}
	return ret;
}

ll nCr(ll n, ll r) {
	if (n < r)
		return 0;
	if (r == 0)
		return 1;
	return n * nCr(n - 1, r - 1) / r;
}

const int N = 3100;
int dp[N][N];
string s, t;
int solve(int idx1, int idx2) {
	if (idx1 >= sz(s) || idx2 >= sz(t)) return 0;
	int& ret = dp[idx1][idx2];
	if (~ret) return ret;
	if (s[idx1] == t[idx2]) return ret = 1 + solve(idx1 + 1, idx2 + 1);
	return ret = max(solve(idx1 + 1, idx2), solve(idx1, idx2 + 1));
}

void printS(int idx1, int idx2) {
	if (idx1 >= sz(s) || idx2 >= sz(t)) return;
	if (s[idx1] == t[idx2]) {
		cout << s[idx1];
		printS(idx1 + 1, idx2 + 1);
	}
	else {
		if (dp[idx1][idx2] == solve(idx1 + 1, idx2)) printS(idx1 + 1, idx2);
		else printS(idx1, idx2 + 1);
	}
}


int main()
{
#ifndef ONLINE_JUDGE

#else
	//freopen("pyramid.in", "r", stdin);
#endif
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cin >> s >> t;
	mem(dp, -1);
	solve(0, 0);
	printS(0, 0);



	return 0;
}


Measured memory_bytes: 38144
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
int main(){ 
    string s;
    cin >>s;
    for(char i='a';i<='z';i++){
        for(int j=0;j<s.size();j++){
            if(s[j]==i){
                break;
            }
            if(j==s.size()-1){
                cout<<i;
                return 0;
            }
        }
    }
    cout<<"None";
    return 0;
}


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

using namespace std;

struct SegmentTree
{
  vector< int > seg, lazy;
  int sz;

  SegmentTree(int n)
  {
    sz = 1;
    while(sz < n) sz <<= 1;
    seg.assign(2 * sz - 1, 2147483647);
    lazy.assign(2 * sz - 1, -1);
  }

  void push(int k)
  {
    if(~lazy[k]) {
      seg[k] = lazy[k];
      if(k < sz - 1) lazy[2 * k + 1] = lazy[2 * k + 2] = lazy[k];
      lazy[k] = -1;
    }
  }

  void update(int a, int b, int x, int k, int l, int r)
  {
    push(k);
    if(a >= r || b <= l) return;
    if(a <= l && r <= b) {
      lazy[k] = x;
      push(k);
      return;
    }
    update(a, b, x, 2 * k + 1, l, (l + r) >> 1);
    update(a, b, x, 2 * k + 2, (l + r) >> 1, r);
    seg[k] = min(seg[2 * k + 1], seg[2 * k + 2]);
  }

  void update(int a, int b, int x)
  {
    update(a, b, x, 0, 0, sz);
  }

  int query(int a, int b, int k, int l, int r)
  {
    push(k);
    if(a >= r || b <= l) return (2147483647);
    if(a <= l && r <= b) return (seg[k]);
    return (min(query(a, b, 2 * k + 1, l, (l + r) >> 1),
                query(a, b, 2 * k + 2, (l + r) >> 1, r)));
  }

  int query(int a, int b)
  {
    return (query(a, b, 0, 0, sz));
  }
};

int main()
{
  int N, Q;
  scanf("%d %d", &N, &Q);
  SegmentTree tree(N);
  while(Q--) {
    int t;
    scanf("%d", &t);
    if(t == 0) {
      int s, t, x;
      scanf("%d %d %d", &s, &t, &x);
      tree.update(s, ++t, x);
    } else {
      int s, t;
      scanf("%d %d", &s, &t);
      printf("%d\n", tree.query(s, ++t));
    }
  }
}

Measured memory_bytes: 4920
package main

import (
	"bufio"
	"fmt"
	"io"
	"os"
	"strconv"
)

const (
	initialBufSize = 100000
	maxBufSize     = 1000000
)

var sc *bufio.Scanner

func initScanner(r io.Reader) *bufio.Scanner {
	buf := make([]byte, initialBufSize)

	sc := bufio.NewScanner(r)
	sc.Buffer(buf, maxBufSize)
	sc.Split(bufio.ScanWords) // bufio.ScanLines
	return sc
}

func main() {
	sc = initScanner(os.Stdin)
	fmt.Println(resolve(parseProblem()))
}

func parseProblem() int {
	return scanInt(sc)
}

func resolve(n int) int {
	if n < 600 {
		return 8
	} else if n < 800 {
		return 7
	} else if n < 1000 {
		return 6
	} else if n < 1200 {
		return 5
	} else if n < 1400 {
		return 4
	} else if n < 1600 {
		return 3
	} else if n < 1800 {
		return 2
	} else if n < 2000 {
		return 1
	}
	panic(-1)
}

// snip-scan-funcs
func scanInt(sc *bufio.Scanner) int {
	sc.Scan()
	i, _ := strconv.Atoi(sc.Text())
	return int(i)
}
func scanString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}


Measured memory_bytes: 1784
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <cctype>
#define rep(i, m, n) for(int i = m;i < n;i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define ll long long
#define ull unsigned long long
#define push(a) push_back(a)
#define pop(a) pop_back(a)
#define debug(x) cout<<#x<<": "<<x<<endl
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

int main(){
  int n;
  cin >> n;
  cout << n*800-(n/15*200) << endl;
}


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

int main() {
	int a, b, k; cin >> a >> b >> k;

	int minv = min(a, b);
	while (k > 0) {
		if (a % minv == 0 && b % minv == 0) {
			k--;
		}
		minv--;
	}

	cout << minv+1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cctype>
#include<utility>
#include<string>
#include<cstring>
#include<cmath>
#include <numeric>
#include<queue>
#include<climits>
#include<cstdio>


#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
//#define INF ((LLONG_MAX) / (2))
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
typedef long long int ll;
typedef pair<ll,int> LL_IP;
#define INF 1e9+7




int main(){

    int n;
    cin >> n;
    vector<int> arr(n);
    REP(i,n){
        cin >> arr[i];
    }
    int odd_count = 0;
    REP(i,n){
        if(arr[i] % 2 == 1){
            odd_count++;
        }
    }
    if(odd_count % 2 == 0){
        cout << "YES" << endl;
    }else{
        cout << "NO" << endl;
    }
  
    return 0;
}

Measured memory_bytes: 640
package main

import (
	"bufio"
	"fmt"
	"os"
	"sort"
	"strconv"
)

type rec struct {
	num, idx int
}

type recs []rec

func (r recs) Len() int {
	return len(r)
}
func (r recs) Swap(i, j int) {
	r[i], r[j] = r[j], r[i]
}
func (r recs) Less(i, j int) bool {
	return r[i].num < r[j].num
}

func nextInt(sc *bufio.Scanner) int {
	sc.Scan()
	t, _ := strconv.Atoi(sc.Text())
	return t
}
func main() {
	var N int
	fmt.Scan(&N)
	rs := make([]rec, N)
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := 0; i < N; i++ {
		rs[i].num = nextInt(sc)
		rs[i].idx = i + 1
	}
	sort.Sort(recs(rs))
	for i := 0; i < N; i++ {
		fmt.Print(rs[i].idx, " ")
	}
	fmt.Println()
}


Measured memory_bytes: 5632
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int a[100001],n,tot=1,ans=0;
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(int i=2;i<=n;i++)
	{
		if(a[i]==a[i-1]) tot++;
			else if(tot%2==1) ans++,tot=1;
				else tot=1;
	}
	if(tot%2==1) ans++;
	cout<<ans;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>
#include <memory.h>

#define arr_print_d0dn(a, n) for(int i=0;i<(n)-1;++i)printf("%d ",(a)[i]);printf("%d\n",(a)[(n)-1])
#define arr_rprint_d0dn(a, n) for(int i=(n)-1;i>0;--i)printf("%d ",(a)[i]);printf("%d\n",(a)[0])
#define arr_print_dndn(a, n) for(int i=0;i<(n);++i)printf("%d\n",(a)[i])
#define arr_rprint_dndn(a, n) for(int i=(n)-1;i>=0;--i)printf("%d\n",(a)[i])

int get_uint() {
    int n = 0;
    int c = getchar_unlocked();
    if(c < 48 || 57 < c) return c;
    while(47 < c && c < 58) {
        n = 10 * n + (c & 0xf);
        c = getchar_unlocked();
    }
    return n;
}
int cnt;
void merge(int *first, int *mid, int *last) {
    const int N1 = (int)(mid - first);
    const int N2 = (int)(last - mid);
    int *left = malloc(sizeof(int) * (N1 + 1));
    int *right = malloc(sizeof(int) * (N2 + 1));
    memcpy(left, first, sizeof(int) * (N1 + 1));
    memcpy(right, mid, sizeof(int) * (N2 + 1));
    left[N1] = right[N2] = 1000000000;
    for(int *it = first, i = 0, j = 0; it != last; ++it) {
        *it = left[i] <= right[j] ? left[i++] : right[j++];
    }
    free(left);
    free(right);
}
void merge_sort(int *first, int *last) {
    const int N = (int)(last - first);
    if(N < 2) return;
    int *mid = first + N / 2;
    merge_sort(first, mid);
    merge_sort(mid, last);
    merge(first, mid, last);
    cnt += N;
}
int main(int argc, char **argv) {
    int n = get_uint();
    int s[500001];
    for(int i = 0; i < n; ++i) s[i] = get_uint();
    merge_sort(s, s + n);
    arr_print_d0dn(s, n);
    printf("%d\n", cnt);
    return 0;
}



Measured memory_bytes: 5436
import java.util.Arrays;
import java.util.Scanner;
public class Main{
    public static Scanner scan  = new Scanner(System.in);
    public static void main(String[]args){
        long n;
        n = nextLong();
        Long sum = 0L;
        for(long i = 1;i<=n;i++){
            if(i%3!=0&&i%5!=0&&i%15!=0){
                sum+=i;
            }
        }
        print(sum);
    }



    public static int nextInt(){
        return Integer.parseInt(scan.next());
    }
    public static long nextLong(){
        return Long.parseLong(scan.next());
    }
    public static String next(){
        return scan.next();
    }
    public static double nextDouble(){
        return Double.parseDouble(scan.next());
    }
    public static float nextFloat(){
        return Float.parseFloat(scan.next());
    }

    //Yes or No
    public static void yesNo(boolean flag){
        if(flag) System.out.println("Yes");
        else System.out.println("No");
    }
    public static void print(Object a){
        System.out.println(a);
    }
}

Measured memory_bytes: 48140
import sys

def solve():
    H, W = map(int, sys.stdin.readline().split())
    S = ['.' + sys.stdin.readline().rstrip() + '.' for _ in range(H)]
    S.insert(0,'.'*(W+2))
    S.append('.'*(W+2))
    for h in range(1,H+1):
        for w in range(1,W+1):
            if S[h][w] == '#':
                if '.' == S[h-1][w] == S[h][w-1] == S[h][w+1] == S[h+1][w]:
                    print('No')
                    exit()
    print('Yes')
    
if __name__ == '__main__':
    solve()

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

using namespace std;

int main() {
	int n;

	cin >> n;

	vector <int> a(n);

	int ans = 0;
	
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		if ((i+1) % 2) {
			if (a[i] % 2) {
				ans++;
			}
		}
	}

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 3620
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp> 
#include <functional> // for less 
#define MAX 5002
#define pb push_back
#define For(i,s,e) for (ll i=(s); i<(e); i++)
#define Debug_array(a,n) for (ll i=(0); i<(n); i++) cout<<a[i]<<" "
#define Foe(i,s,e) for (ll i=(s); i<=(e); i++)
#define Fod(i,s,e) for (ll i=(s)-1; i>=(e); i--)
#define Mod 1000000007
#define pii pair<ll,ll>
#define fi first
#define se second
#define endl "\n"
#define mp make_pair
#define big_prime 15486277
#define bigger_prime 179424697
#define biggest_prime 32416188691
//#define random_shuffle(indices.begin(), indices.end());
//std::random_device rd;
//std::mt19937 g(rd());
//std::shuffle(v.begin(), v.end(), g);
using namespace __gnu_pbds; 
using namespace std;

typedef long long ll;
typedef tree<ll, null_type, less<ll>, rb_tree_tag,tree_order_statistics_node_update> ordered_set; 


int main(){
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	
	ll n,k;cin>>n>>k;
	ll a[n];
	For(i,0,n){
		cin>>a[i];
	}

	ll ans=1e18;
	For(i,0,n){
		if(i+k-1>=n) break;
		ll x = a[i] , y = a[i+k-1];
		ll temp=0;
		if(x>=0 && y>=0) temp = y;
		else if(x<=0 && y<=0) temp = abs(x);
		else{
			temp = min(2*y+abs(x),2*abs(x)+y);
		}
		ans = min(ans,temp);
	}
	cout<<ans<<endl;











	
}

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

#define mod 1000000007

// Fermat の小定理を用いた F_mod 上での逆元計算x^(mod-2), 蟻本p115
ll Inverse(ll x){
    ll res = 1;
    int n = mod - 2;
    while(n > 0){
        if(n & 1){
            res = res * x % mod;
        }
        x = x * x % mod;
        n >>= 1;
    }
    return res;
}

// iの階乗 = fact[i], main内の階乗計算をする必要がある
#define MAX_FACT 200100
ll fact[MAX_FACT];

ll nCk(int n, int k){
    //　n_C_kの計算, Inverseの中身にもmodを入れないとオーバーフローするので注意, 蟻本p.263
    ll ans = fact[n] * Inverse(fact[k] * fact[n-k] % mod);
    ans %= mod;
    return ans;
}


int main() {
    int N, M, K;
    cin >> N >> M >> K;
    // N <= M にする
    if(N > M){
        int t = N;
        N = M;
        M = t;
    }
    // コストは駒が配置されている任意の2点間のマンハッタン距離の総和

    // 階乗計算
    fact[0]=1;
    for(int i = 1; i < MAX_FACT; ++i) {
        fact[i] = fact[i-1] * i % mod;
    }

    // ある点とある点の距離は (N*M-2)_C_(K-2) 回数えられるので,
    // マス目の任意の2点間のマンハッタン距離の総和に (N*M-2)_C_(K-2) をかけたものが求める総和
    ll ans = 0;
    ll temp;
    // 1*M
    for (int i = 1; i < M; ++i) {
        temp = M - i;
        temp = temp * i % mod;
        ans = ans + temp;
        ans %= mod;
    }

    ll base = ans;
    // N*M
    for (int i = 1; i < N; ++i) {
        temp = i + 1;
        temp = temp * i % mod;
        temp = temp * Inverse(2) % mod;
        temp = temp * M % mod;
        temp = temp * M % mod;
        ans += temp;
        ans %= mod;
        temp = base * 2 % mod;
        temp = temp * i % mod;
        ans += temp;
        ans %= mod;
        ans += base;
        ans %= mod;
    }

    ans *= nCk(N*M-2, K-2);
    ans %= mod;
    
    cout << ans;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <queue>
#include <vector>
#include <functional>
#include <tuple>
#include <algorithm>
using namespace std;

const long long INF = 10000000000000000;

int n, m, s, t, u[100009], v[100009], a[100009], b[100009];
long long si[100009], it[100009], sit[100009], ans[100009];
vector<tuple<int, int, int>> G[100009];
priority_queue<pair<long long, int>, vector<pair<long long, int>>, greater<pair<long long, int>>> Q;

int main()
{
    cin >> n >> m >> s >> t;
    for (int i = 0; i < m; i++) {
        cin >> u[i] >> v[i] >> a[i] >> b[i];
        G[u[i]].push_back(make_tuple(v[i], a[i], b[i]));
        G[v[i]].push_back(make_tuple(u[i], a[i], b[i]));
    }

    for (int i = 1; i <= n; i++) {
        si[i] = INF;
        it[i] = INF;
    }

    Q.push(make_pair(0, s));
    si[s] = 0;
    while (Q.size()) {
        int pos = Q.top().second; Q.pop();
        for (int i = 0; i < G[pos].size(); i++) {
            int to = get<0>(G[pos][i]), cost = get<1>(G[pos][i]);
            if (si[to] > si[pos] + cost) {
                si[to] = si[pos] + cost;
                Q.push(make_pair(si[to], to));
            }
        }
    }

    Q.push(make_pair(0, t));
    it[t] = 0;
    while (Q.size()) {
        int pos = Q.top().second; Q.pop();
        for (int i = 0; i < G[pos].size(); i++) {
            int to = get<0>(G[pos][i]), cost = get<2>(G[pos][i]);
            if (it[to] > it[pos] + cost) {
                it[to] = it[pos] + cost;
                Q.push(make_pair(it[to], to));
            }
        }
    }

    for (int i = 1; i <= n; i++) sit[i] = si[i] + it[i];

    ans[n-1] = 1000000000000000 - sit[n];
    for (int i = n-2; i >= 0; i--) ans[i] = max(ans[i+1], 1000000000000000 - sit[i+1]);

    for (int i = 0; i < n; i++) cout << ans[i] << endl;
    return 0;
}

Measured memory_bytes: 13684
n = int(input())
a = [int(input()) for i in range(n)]
if a[0] != 0:
  print(-1)
  exit()
  
ans = 0
for i in range(1,n):
  if a[i] > a[i-1] + 1:
    ans = -1
    break
  if a[i] == a[i-1] + 1:
    ans += 1
  else:
    ans += a[i]
    
print(ans)

Measured memory_bytes: 11052
#include<bits/stdc++.h>
using namespace std;
typedef  long long ll;
using vll=vector<ll>;
using vvll=vector<vll>;
using vi=vector<int>;
using vvi=vector<vector<int>>;
using vb=vector<bool>;
using pii=pair<int,int>;
using vpii=vector<pair<int,int>>;

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

//pow(llpow,modpow)
template<class T> ll llpow(ll x,T n){ll ans=1;if(x==0)ans=0;while(n){if(n&1)ans*=x;x*=x;n>>=1;}return ans;}
long long modpow(long long a, long long n, long long mod) {long long res = 1;while (n > 0) {if (n & 1) res = res * a % mod;a = a * a % mod;n >>= 1;}return res;}
//最大公約数
template<class T> inline T gcd(T x,T y){if(y==0)return x; else {return gcd(y,x%y);}}
//最小公倍数
template<class T> inline T lcm(T x,T y){return x/gcd(x,y)*y;}
//逆元
long long modinv(long long a, long long m) {long long b = m, u = 1, v = 0;while (b) {long long t = a / b;a -= t * b; swap(a, b);u -= t * v; swap(u, v);}u %= m;if (u < 0) u += m;return u;}

#define rep(i, begin_i, end_i) for (ll i = (ll)begin_i; i < (ll)end_i; i++)
//試験導入
#define irep(i, end_i, begin_i) for (ll i = (ll)begin_i-1; i >= (ll)end_i; i--)

long long INF = 1LL<<60;
int main( ){
    ll n,m;
    cin>>n>>m;
    ll p=1900*m+100*(n-m);
    cout<<llpow(2,m)*p<<endl;
    return 0;
}




Measured memory_bytes: 256
#include <iostream>
#include <array>

int main() {
    int n;
    std::cin >> n;

    std::array<std::array<std::array<int, 11>, 4>, 5> residents = {{{}}};

    int b, f, r, v;
    for (int i = 0; i < n; i++) {
        std::cin >> b >> f >> r >> v;
        residents[b][f][r] += v;
    }

    for (b = 1; b <= 4; b++) {
        for (f = 1; f <= 3; f++) {
            for (r = 1; r <= 10; r++) {
                std::cout << " " << residents[b][f][r];
            }
            std::cout << std::endl;
        }
        if (b < 4) {
            std::cout << "####################" << std::endl;
        }
    }
}



Measured memory_bytes: 3088
import java.util.Scanner;

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

        try{
            //入力
            int N = scan.nextInt();
            int[] A_ = new int[N];
            for(int i = 0; i < N; i++){
                A_[i] = scan.nextInt();
            }

            int g = A_[0];
            for(int i = 1; i < N; i++){
                g = gcd(g,A_[i]);
            }
            System.out.println(g);

        }finally{
            scan.close();
        }
    }

    //最大公約数を求める
    static int gcd(int a, int b){
        if(a < b){
            int tmp = b;
            b = a;
            a = tmp;
        }
        while(a % b != 0){
            int tmp = a % b;
            a = b;
            b = tmp;
        }
        return b;
    }
}


Measured memory_bytes: 51060
import java.util.Scanner;
public class Main {
    public static void main(String[] args){
        Scanner scan = new java.util.Scanner(System.in);
        for(;;){
            int n = scan.nextInt();
            double sum = 0;
            double m = 0;
            if(n == 0)break;
            double[] s = new double[n];
            for(int i = 0; i < n; i++){
                s[i] = scan.nextDouble();
                sum += s[i];
            }
            m = (double)sum / n;
            double a = 0;
            for(int i = 0; i < n; i++){
                a += (s[i] - m) * (s[i] - m);
            }
            double ans = Math.sqrt(a / n);
            if(ans >= 0){
                System.out.println(ans);
            }
        }

    }
}

Measured memory_bytes: 40808
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int n,a,x[60];
ll ans,d[2505][52][52];
int main() {
	scanf("%d %d",&n,&a);
	for (int i=1;i<=n;i++)
		scanf("%d",&x[i]);
	d[0][0][0]=1;
	for (int i=0;i<=2500;i++) {
		for (int j=1;j<=n;j++) {
			for (int k=0;k<=j;k++) {
				d[i][j][k]=d[i][j-1][k];
				if (i>=x[j])
					d[i][j][k]+=d[i-x[j]][j-1][k-1];
			}
		}
	}
	for (int i=1;i<=n;i++)
		ans+=d[i*a][n][i];
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 53120
#include <bits/stdc++.h>
#include <boost/algorithm/string/join.hpp>
#include <boost/range/irange.hpp>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
using boost::irange;
using boost::algorithm::join;

typedef long long ll;
typedef unsigned long long ull;
//typedef long double ld;

typedef map<int, int> mii;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef set<int> si;
typedef set<ll> sll;
typedef vector<int> vi;
typedef vector<pair<int, int > > vii;
typedef vector<ll> vll;
typedef vector<double> vd;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
typedef vector<vll> vvll;

constexpr ll MOD = 1e9+7;
template<typename T>constexpr auto inf=numeric_limits<T>::max()/4;
constexpr int INF=inf<int>;
constexpr ll LINF=inf<ll>;

#define Sort(x) sort(begin(x),end(x))
#define Reverse(x) reverse(begin(x),end(x))
#define ABS(a,b) ((a)<(b)?(b)-(a):(a)-(b))
#define nbit(n) (1ull<<(n))
#define _ol3(_1,_2,_3,name,...)name
#define _rep(i,n)_repi(i,0,n)
#define _repi(i,a,b)for(int i=a,i##_l=(b);i<i##_l;++i)
#define REP(...) _ol3(__VA_ARGS__,_repi,_rep,)(__VA_ARGS__)
#define REPR(i,n) for(int i=n-1;i>=0;--i)
#define REPA(i,v) REP(i,(v).size())

// sort(begin(x), end(x), greater<ll>());
// lower_bound(a.begin(), a.end(), val): a[i] ≥ valである最左の位置
// upper_bound(a.begin(), a.end(), val): a[i] > valである最左の位置

// Returns minimum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmin(T& a, T b) {
  if (a > b) {
    a = b;
  }
  return a;
}

// Returns maximum of a and b.
// If a is less b, a is set to b.
template<typename T>
T chmax(T& a, T b) {
  if (a < b) {
    a = b;
  }
  return a;
}

template <typename T>
void dumpContents(const T& v, const string& msg)
{
  cerr << "### " << msg << " ###\n";
  for (const auto& x : v) {
    cerr << x << " ";
  }
  cerr << endl;
}

struct before_main_function {
  before_main_function() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<setprecision(20)<<fixed;
    #define endl "\n"
  }
} before_main_function;

// ========== end of template ==========

int main(int argc, char** argv) {
  int N;
  cin >> N;
  string S;
  cin >> S;

  int ret = 1;
  for (int i=1; i<N; i++) {
    if (S[i-1] == S[i]) continue;
    ret++;
  }

  cout << ret << endl;

  return 0;
}


Measured memory_bytes: 512
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
#include <deque>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef pair<ll, ll> PL;
typedef vector<P> vp;
typedef vector<PL> vpl;
typedef vector<vector<P>> vvp;
typedef vector<vector<PL>> vvpl;
const int INF = 1001001001;
const ll LINF = 1e18;
const double pi = 3.1415926535897932;
const string endstr = "\n";
#define FOR(i, a, b) for(ll i = (a); i < b; i++)
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, n) for(ll i = n; i >= 0; i--)
#define FORMAP(it, m) for(auto it = m.begin(); it != m.end(); it++)
#define ff first
#define ss second
#define pb push_back

template <typename T>
T gcd(T a, T b) {
    return (a == 0) ? b : gcd(b%a, a);
}
template <typename T>
T lcm(T a, T b) {
    return a / gcd(a, b) * b;
}

bool p_comp_fs(const PL p1, const PL p2){ return p1.first < p2.first;};
bool p_comp_fg(const PL p1, const PL p2){ return p1.first > p2.first;};
bool p_comp_ss(const PL p1, const PL p2){ return p1.second < p2.second;};
bool p_comp_sg(const PL p1, const PL p2){ return p1.second > p2.second;};
template <typename T>
vector<T> uniquen(vector<T> vec){
    vec.erase(unique(vec.begin(), vec.end()), vec.end());
    return vec;
}
const ll size = 100100;
vl G[size];
ll N, M;
ll dp[size];

ll dfs(ll now, ll par){
    ll res = 1;
    for(ll c : G[now]) if(c != par){
        res = res * (dfs(c, now) + 1) % M;
    }
    return dp[now] = res;
}

ll ans[size];

void dfs2(ll par, ll parpar, ll par_cnt){
    vl gl(G[par].size(), 1), gr(G[par].size(), 1);
    ll la = 1, ra = 1;
    rep(i, G[par].size()){
        if(G[par][i] == parpar) la = la * (par_cnt+1)%M;
        else la = la * (dp[G[par][i]]+1)%M;
        gl[i] = la;
    }
    for(ll i = G[par].size()-1; i >= 0; i--){
        if(G[par][i] == parpar) ra = ra * (par_cnt+1)%M;
        else ra = ra * (dp[G[par][i]]+1)%M;
        gr[i] = ra;
    }
    rep(i, G[par].size()){
        if(G[par][i] == parpar) continue;
        ll p_cnt = ((i==0 ? 1 : gl[i-1]) * (i == G[par].size()-1 ? 1 : gr[i+1])%M);
        dfs2(G[par][i], par, p_cnt);
        ans[G[par][i]] = (p_cnt+1) * dp[G[par][i]] % M;
    }
}

int main(){
    cin >> N >> M;
    rep(_, N-1){
        ll x, y; cin >> x >> y; x--; y--;
        G[x].pb(y); G[y].pb(x);
    }
    dfs(0, -1);
    dfs2(0, -1, 0);
    ans[0] = dp[0];
    rep(i, N) cout << ans[i] << endstr;
    
    return 0;
}


Measured memory_bytes: 19712
#include<bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define all(x) (x).begin(),(x).end()
#define INF (1<<30)-1
using ll = long long;
using namespace std;
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; }

int main(){
  int n; cin >> n;
  vector<ll> a(n); rep(i,n) cin >> a[i];
  vector<bool> up(n+1,false);
  rep(i,n-1) if(a[i] < a[i+1]) up[i+1] = true;
  ll ans = 1000;
  rep(i,n){
    if(up[i]){
      int now = i-1;
      bool ok = false;
      while(i <= n){
        if(up[i]) i++;
        else{
          ok = true;
          break;
        }
      }
      if(ok){
        ll cnt = ans/a[now];
        ans -= cnt*a[now];
        ans += cnt*a[i-1];
      }
    }
  }
  cout << ans;
  return 0;
}


Measured memory_bytes: 3636
#include<iostream>
#include<string>
#include<vector>
#include<unordered_map>
#include<algorithm>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<cstdlib>
#include<queue>
#include<utility> //pair
using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)

typedef long long ll;
typedef vector<vector<int>> Graph;

int main() {
	//入力;
	int N, K;
	cin >> N >> K;
	vector<ll> H(N);
	REP(i, N) {
		cin >> H[i];
	}

	sort(H.begin(), H.end());

	//小数点以下の桁数表示;
	//cout << fixed << setprecision(15);

	ll ans = 0;
	REP(i, N - K) {
		ans += H[i];
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    for(int q=0;q<n;q++){
        int m,x,y,dp[20][20]={0};
        cin >> x >> y >> m;
        array<tuple<int,int,int,int>, 100> mat;
        for (int j=0;j<m;j++){
            int x1,y1,x2,y2;
            cin >> x1 >> y1 >> x2 >> y2;
            if (x1 == x2) {
                if (y2 < y1)swap(y1,y2);
            } else {
                if (x2 < x1)swap(x1,x2);
            }
            mat[j] = make_tuple(x1,y1,x2,y2);
        }
        for (int i=0; i<x+1; i++){
            for(int j=0; j<y+1; j++){
                if (i == 0 && j == 0){
                    dp[i][j] = 1;
                } else {
                    bool _x=1,_y=1;
                    for(int k=0;k<m;k++){
                        if (get<2>(mat[k]) == i && get<3>(mat[k]) == j){
                            if (get<0>(mat[k]) == i-1 && get<1>(mat[k]) == j ) _x=0;
                            if (get<0>(mat[k]) == i && get<1>(mat[k]) == j-1 ) _y=0;
                        }
                    }
                    dp[i][j] += (_x && i ? dp[i-1][j] : 0) + (_y && j != 0 ? dp[i][j-1] : 0 );
                }
            }
        }
        if (dp[x][y] == 0) cout << "Miserable Hokusai!" << endl;
        else cout << dp[x][y] << endl;
    }
}


Measured memory_bytes: 3060
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
const int N=1e5+10;
struct path{int y,nxt;}g[N<<1];int h[N];
int d[N],n,m,x,y,cnt,a,b;
bool vis[N];
int q[N],ql,qr;
bool bfs(int x){
	memset(vis,0,sizeof(vis));
	vis[x]=vis[a]=1;q[ql=qr=1]=x;
	while(ql<=qr){
		x=q[ql++];
		for(int i=h[x];i;i=g[i].nxt)if(!vis[g[i].y]) vis[g[i].y]=1,q[++qr]=g[i].y;
	}return vis[b];
}
int main(){
//	freopen("a.in","r",stdin);
	scanf("%d%d",&n,&m);
	for(int i=1;i<=m;i++){
		scanf("%d%d",&x,&y);g[i*2]=path{y,h[x]};h[x]=i*2;
		g[i*2+1]=path{x,h[y]};h[y]=i*2+1;d[x]++;d[y]++;
	}
	for(int i=1;i<=n;i++)if(d[i]&1){puts("No");return 0;}
	for(int i=1;i<=n;i++) if(d[i]>=6){puts("Yes");return 0;}
	for(int i=1;i<=n;i++)if(d[i]==4)cnt++;
	if(cnt>=3) {puts("Yes");return 0;}
	if(cnt<2){puts("No");return 0;}
	for(int i=1;i<=n;i++)if(d[i]==4) a?b=i:a=i;
	cnt=0;
	for(int i=h[a];i;i=g[i].nxt) 
		if(bfs(g[i].y)) cnt++;
	if(cnt==2)puts("Yes");else puts("No");
}

Measured memory_bytes: 3072
def main():

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

    mx = 0
    cnt = 0
    for i in range(1,n):
        tmp = a[i] - a[i - 1]
        if tmp > mx:
            mx = tmp
        cnt += tmp
    tmp = k - a[-1] + a[0]
    if tmp > mx :
        mx = tmp
    cnt = cnt + tmp - mx
    print(cnt)



if __name__ =='__main__':
    main()


Measured memory_bytes: 26444
n = list(map(int,input().split()))
cnt = 0

while n.count(n[0]) != len(n):
    n.sort()
    if n[0] == n[1]:
        n[0] += 1
        n[1] += 1
    else:
        n[0] += 2
    cnt += 1
print(cnt)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
//const long double EPS = 1e-14;
const int INF = (1<<30)-1;
const ll LINF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
inline ll lin() { ll x; scanf("%lld",&x); return x;}
inline char chin() { char x; scanf("%c",&x); return x;}
inline string stin() { string x; cin >> x; return x;}
inline double din() { double x; scanf("%lf",&x); return x;}
//template<class T = int> inline T in() { T x; cin >> x; return (x);}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
char itoa(int n) { return n + '0';}
ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}
ll lcm(ll a, ll b) { return a/gcd(a,b)*b;}

int main () {
  while (true) {
    int n, x;
    cin >> n >> x;
    if (n == 0 && x == 0) break;
    int ans = 0;
    srep(i,1,n+1)srep(j,i+1,n+1)srep(k,j+1,n+1) {
      if (i+j+k == x) ans++;
    }
    cout << ans << endl;
  }
  return 0;
}


Measured memory_bytes: 3040
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
ll gcd(ll a , ll b) { return b==0?a: gcd( b, a%b); }
ll lcm(ll a , ll b) { return a/gcd(a,b) * b ; }
int main()
{
  ios::sync_with_stdio(false);cin.tie(0);
  //freopen("input.txt" , "r" , stdin );
  ll n;
  cin>>n;
  ll q = n%10;
  if(q==2 || q==4 || q==5 || q==7 || q==9 )
    cout<<"hon";
  else if(q==0 || q==1 || q==6 || q==8)
    cout<<"pon";
  else
    cout<<"bon";
  return 0;
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define DUMP(v) REP(aa, (v).size()) { cout << v[aa]; if (aa != v.size() - 1)cout << " "; else cout << endl; }
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

const int dx[8] = { 1,1,0,-1,-1,-1,0,1 };
const int dy[8] = { 0,1,1,1,0,-1,-1,-1 };


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll max(ll a, int b) { return max(a, ll(b)); }
ll max(int a, ll b) { return max(ll(a), b); }
ll min(ll a, int b) { return min(a, ll(b)); }
ll min(int a, ll b) { return min(ll(a), b); }


int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s;
	cin >> s;
	vi cnt(26, 0);
	REP(i, s.size()) {
		cnt[s[i] - 'a']++;
	}
	REP(i, 26) {
		if (cnt[i] == 0) {
			cout << char(i + 'a') << endl;
			return 0;
		}
	}
	cout << "None" << endl;
}


Measured memory_bytes: 512
#include<stdio.h>

int main(void)
{
  int x1,x2,y1,y2;
  scanf("%d %d %d %d",&x1,&y1,&x2,&y2);
  int dist_x=x2-x1;
  int dist_y=y2-y1;
  printf("%d %d %d %d\n",x2-dist_y,y2+dist_x,x1-dist_y,y1+dist_x);
  return 0;
}


Measured memory_bytes: 128
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
 
#include <bits/stdc++.h> 
#include <iostream>
#include <iomanip>
#include <sstream>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <set>
#include <map>
#include <boost/math/common_factor.hpp>
#include <algorithm>
#include <valarray>
#include <iterator>
#include <functional>
#include <limits>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <cassert>
#include <unordered_map>
#include <unordered_set>
#include <stack>
#include<chrono>
 
using namespace std;
//using namespace std::chrono;
 
#define ios ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int
#define vl int64_t

int main()
{
     ll n;
     cin>>n;
     vector<ll>v;
     map<ll,ll>minpos;
     map<ll,ll>maxpos;
     for(ll i=1;i<=n;i++)
     minpos[i]=INT_MAX;
     
     for(ll i=1;i<=n;i++)
     maxpos[i]=INT_MIN;
     
     map<ll,ll>pos;
     
     
     for(ll i=0;i<n;i++)
     {
          ll temp;
          cin>>temp;
          v.push_back(temp);
          pos[temp]=i+1;
          minpos[temp]=min(minpos[temp],i);
          maxpos[temp]=max(maxpos[temp],i);
     }
     
     if(pos[1]==0)
     {
          cout<<-1;
          return 0;
     }
     ll curr=1;
     ll ctr=1;
     
     for(ll i=minpos[1];i<n;i++)
     {
          if(v[i]==curr+1)
          {
               curr++;
               ctr++;
          }
     }
     
     cout<<n-ctr;
      
    
     
     
}

Measured memory_bytes: 39280
import sys
def rs(): return sys.stdin.readline().rstrip()
def ri(): return int(rs())
def rs_(): return [_ for _ in rs().split()]
def ri_(): return [int(_) for _ in rs().split()]

import decimal
import math
N = ri()
for i in range(N + 1):
    if math.floor(i * decimal.Decimal(1.08)) == N:
        print(i)
        exit()
print(':(')

Measured memory_bytes: 5072
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff first
#define ss second
#define u128 __int128
#define pb push_back

#define N 100010
#define MOD 1000000007

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

	int a, b;
	cin >> a >> b;
	cout << max({a+b, a - b, a * b});
	return 0;
}



Measured memory_bytes: 256
s = input()
cnt = 0
while len(s) > 0:
#  print(s)
  if s[0] == s[-1]:
    s = s[1:-1]
  elif s[0] == "x":
    cnt += 1
    s = s[1:]
  elif s[-1] == "x":
    cnt += 1
    s = s[:-1]
  else:
    print(-1)
    exit()
print(cnt)


Measured memory_bytes: 3316
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <limits.h>


int main(void)
{
	int a,b,c,x;
	int i,j,k,t=0;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	
	for(i=0;i<=a;i++)for(j=0;j<=b;j++){
		if((0<=x/50-10*i-2*j)&&(x/50-10*i-2*j<=c)){t++;}
	}
	printf("%d\n",t);
	
	return 0;
}




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

int main(){
    string S;  cin >> S;
    replace(S.begin(), S.end(), '1', '#');
    replace(S.begin(), S.end(), '9', '1');
    replace(S.begin(), S.end(), '#', '9');
    cout << S << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>	
 
#define f first
#define s second
#define pb push_back
 
#define ll long long
 
#define int ll
 
#define mp make_pair
  
using namespace std;
                       
 
const int inf = 1e9 + 7;
 
const ll ll_inf = 1e18 + 7;
const int K = 2e5;
const int N = 4e5 + 300;
                                         
ll binpow (ll a, ll n)
{
    ll res = 1;
    while (n) {
        if (n & 1)
        {
            res *= a;
            res %= inf;
        }      	
        a *= a;
        n >>= 1;
        a %= inf;
    }                          
    return res;
}   
          
  
 
void boost()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
}  

int ans,n,k;

main() 
{
  cin >> n >> k;
  for(int i = k;i <= n + 1;++i){
    ans += i * (n + n - i + 1) / 2 - i * (i - 1) / 2 + 1;
    ans %= inf;
  }
  cout << ans << endl;
}

Measured memory_bytes: 3616
n = int(input())
t = [0]
x = [0]
y = [0]
for i in range(n):
  t_, x_, y_ = map(int, input().split())
  t.append(t_)
  x.append(x_)
  y.append(y_)

for j in range(n):
  dt = t[j+1] - t[j]
  dx = abs(x[j+1] - x[j])
  dy = abs(y[j+1] - y[j])
  if dx+dy>dt or dt%2!=(dx+dy)%2:
    print('No')
    exit()
    
print('Yes')

Measured memory_bytes: 17720
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)
#define rep2(i, x, n) for(int i = x; i <= n; i++)
#define rep3(i, x, n) for(int i = x; i >= n; i--)
#define elif else if
#define sp setprecision
#define pb(x) push_back(x)
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, ll> pil;
typedef pair<ll, int> pli;
typedef pair<ld, ld> pdd;
const ll MOD = 1e9+7;
//const ll MOD = 998244353;
const int inf = 1e8;
const ll INF = 1e16;
const string alpha = "abcdefghijklmnopqrstuvwxyz";

int main(){
    int N;
    ll L;
    cin >> N >> L;
    ll a[N];
    rep(i, N) cin >> a[i];
    int c = 0;
    rep(i, N-1){
        if(a[i]+a[i+1] >= L) c = i+1;
    }
    if(c == 0) cout << "Impossible" << endl;
    else{
        cout << "Possible" << endl;
        rep2(i, 1, c-1) cout << i << endl;
        rep3(i, N-1, c+1) cout << i << endl;
        cout << c << endl;
    }
}

Measured memory_bytes: 1536
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

# リーダよりW (左)→ E(右)
# リーダよりE (右)→ W (左)
# W, Eの数を累積和として持っておく

N =  int(sys.stdin.readline())
S =  list(sys.stdin.readline().rstrip())

Wn = [0] * (N + 1)
En = [0] * (N + 1)

Wc = 0
Ec = 0
for i, s in enumerate(S):
    if s == "W":
        Wc += 1
    else:
        Ec += 1
    Wn[i + 1] = Wc
    En[i + 1] = Ec

ans = 10 ** 10
for i, (w, e) in enumerate(zip(Wn[1::], En[1::])):
    ans = min(Wn[i] + En[N] - En[i + 1], ans)

print(ans)

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

const int MX = 100001;

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

  sort(a.begin(),a.end(),greater<int>());

  int A = 0;
  int B = 0;
  rep(i,n){
    if(i%2==0) A += a[i];
    else B += a[i];
  }

  cout << A - B << endl;
  
  return 0;
}

Measured memory_bytes: 3628
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>



void swap (int *x, int *y) {
  int temp;

  temp = *x;
  *x = *y;
  *y = temp;

  return;
}


int gcd(int a, int b){
  int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

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

long int modinv(long int a,long int mod){
  return modpow(a,mod-2,mod);
}

int max(int a,int b){
  if(a<b){
    return b;
  }
  else{
    return a;
  }
}

int min(int a,int b){
  if(a<b){
    return a;
  }
  else{
    return b;
  }
}

void chmax(int *a,int b){
  if(*a < b){
    *a = b;
  }

  return;
}

void chmin(int *a,int b){
  if(*a > b){
    *a =b;
  }

  return;
}

int main(void){
  int x,y,z;
  scanf("%d%d%d",&x,&y,&z);
  int ans=0;
  for(int i=0;i<x;i++){
    if((y+2*z+i*(y+z))<=x){
      ans++;
    }else{
      break;
    }
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 1712
#include <iostream>
#include <algorithm>
#include <vector>
#include<string>
#include <set>
#include <map>
#include <queue>
#include <limits.h>
#include <bitset>
#include <cmath>

using namespace std;

#define rip(i, n, s) for (int i = (s);i < ( int )( n ); i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;

struct P
{
	int first;
	int second;
};

P make_P(int &a,int &b){
	P ret;
	ret.first=a;
	ret.second=b;
	return ret;
}

bool operator<(const P &a, const P &b){
	if(a.first == b.first){
		return a.second < b.second;
	}
	else{
		return a.first > b.first;
	}
}

bool operator>(const P &a, const P &b){
	return b<a;
}

int main(){
	int n;
	cin >> n;
	set<P> li;
	vector<int> da(n);
	rip(i,n,0){
		cin >> da[i];
		li.insert(make_P(da[i],i));
	}
	vector<ll> ans(n);
	auto itr=li.begin();
	P now=*itr,next,maxi=now;
	int cou=1;
	ll su=0;
	rip(i,n-1,0){
		++itr;
		next=*itr;
		su+=(ll) cou*(now.first-next.first);
		if(maxi.second>next.second){
			ans[maxi.second]=su;
			su=0;
			maxi=next;
		}
		cou++;
		now=next;
	}
	ans[maxi.second]=(ll) cou*now.first + su;
	auto iit=li.begin();
	rip(i,n,0){
		printf("%lld\n",ans[i]);
		++iit;
	}
}

Measured memory_bytes: 6912