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

int n,m;
ll x[123456],y[123456];

int main(){

cin>>n>>m;

for(int i=0; i<n; i++) scanf("%lld", &x[i]);
for(int i=0; i<m; i++) scanf("%lld", &y[i]);

ll X=0,Y=0,p=0,q=0;

for(int i=0; i<(n-1)/2; i++){
	p=(p+x[n-1-i]-x[i])%MOD;
	X=(X+p)%MOD; 
}
X=(X+X)%MOD; 
if((n-1)%2!=0){
	p=(p+x[n-1-(n-1)/2]-x[(n-1)/2])%MOD;
	X=(X+p)%MOD;
}

for(int i=0; i<(m-1)/2; i++){
	q=(q+y[m-1-i]-y[i])%MOD;
	Y=(Y+q)%MOD; 
}
Y=(Y+Y)%MOD; 
if((m-1)%2!=0){
	q=(q+y[m-1-(m-1)/2]-y[(m-1)/2])%MOD;
	Y=(Y+q)%MOD;
}

cout<<X*Y%MOD<<endl;

return 0;
 
}

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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define mp(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s, t;
    cin >> s >> t;
    int n = sz(s);
    int ans = 0;
    for (int i = 0; i < n; i++) {
        ans += s[i] != t[i];
    }
    cout << ans << '\n';
    return 0;
}

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

long long n;
vector<long long> a, b, c, d;

long long solve();

int main() {
  cin >> n;
  a.resize(n + 1);
  b.resize(n);
  for(int i = 0; i < n + 1; ++i) cin >> a[i];
  for(int i = 0; i < n; ++i) cin >> b[i];

  cout << solve() << endl;
  return 0;
}

long long solve() {
  long long ans = 0, now = 0;
  c = a;
  d = b;
  for(int i = 0; i < n; ++i) {
    long long x = min(c[i], d[i]);
    ans += x;
    c[i] -= x;
    d[i] -= x;
    if(d[i] > 0) {
      x = min(c[i + 1], d[i]);
      ans += x;
      c[i + 1] -= x;
      d[i] -= x;
    }
  }
  c = a;
  d = b;
  reverse(d.begin(), d.end());
  reverse(c.begin(), c.end());
  for(int i = 0; i < n; ++i) {
    long long x = min(c[i], d[i]);
    now += x;
    c[i] -= x;
    d[i] -= x;
    if(d[i] > 0) {
      x = min(c[i + 1], d[i]);
      now += x;
      c[i + 1] -= x;
      d[i] -= x;
    }
  }

  return max(now, ans);
}

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

#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 ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18
typedef long long ll;


int main() {
    int N; cin >> N;
    cout << N*N*N << endl;
    return 0;
}

Measured memory_bytes: 3616
/*input
1
z
*/
/**
    Author: Kristopher Paul
    Date Created: 16-11-2019
    Contest Name:
                _/    _/   _/_/_/_/   _/   _/_/_/_/
               _/  _/     _/    _/   _/   _/
              _/_/       _/_/_/_/   _/   _/_/_/_/
             _/  _/     _/  _/     _/         _/
            _/    _/   _/    _/   _/   _/_/_/_/
**/
#include<bits/stdc++.h>
#include<stdio.h>
//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
#define ll long long
#define int ll
#define pb push_back
#define INF 1e18
#define MOD 1000000007
//#define MOD 998244353
#define mp make_pair
const double PI=3.141592653589793238462643383279502884197169399375105820974944;
#define REP(i,n) for (int i = 0; i < n; i++)
#define FOR(i,a,b) for (int i = a; i < b; i++)
#define REPD(i,n) for (int i = n-1; i >= 0; i--)
#define FORD(i,a,b) for (int i = a; i >= b; i--)
#define remax(a,b) a = max(a,b)
#define remin(a,b) a = min(a,b)
#define umap unordered_map
#define pii pair<int,int>
#define F first
#define S second
#define mii map<int,int>
#define vi vector<int>
#define vvi vector<vi>
#define itr :: iterator it
#define all(v) v.begin(),v.end()
#define WL(t) while(t--)
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/gcd((a),(b))
#define out(x) cout << #x << " is " << x << endl
#define FastIO ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
using namespace std;
//using namespace __gnu_pbds;

//typedef tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // set
//typedef tree<int,null_type,less_equal<int>,rb_tree_tag,tree_order_statistics_node_update> pbds; // multiset

int ModExp(int x,int y,int m){
    int res = 1;
    x = x % m;
    while (y > 0)
    {
        if (y & 1)
            res = (res*x) % m;

        y = y>>1;
        x = (x*x) % m;
    }
    return res;
}

void solve(){
    int n;
    cin >> n;
    string s;
    cin >> s;
    if(n % 2 == 1){
        cout << "No" << endl;
    }else{
        string a = s.substr(0,n/2);
        string b = s.substr(n/2,n/2);
        if(a == b){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

signed main(){
    FastIO;
    int t = 1;
//    cin >> t;
    WL(t){
        solve();
    }
}


Measured memory_bytes: 256
#include <cmath>
#include <cstdio>
#include <algorithm>
#pragma warning(disable : 4996)
using namespace std;
int n, m, c[155], p[155][15], v[155][15], dp[155][15][79];
int main() {
	while (scanf("%d%d", &n, &m), n) {
		for (int i = 0; i < n; i++) {
			scanf("%d", &c[i]);
			for (int j = 0; j < c[i]; j++) scanf("%d%d", &p[i][j], &v[i][j]);
		}
		for (int i = 1; i < n; i++) {
			for (int j = 0; j < c[i]; j++) {
				for (int k = 0; k <= m; k++) {
					dp[i][j][k] = 999999999;
					for (int l = 0; l < c[i - 1]; l++) {
						dp[i][j][k] = min(dp[i][j][k], dp[i - 1][l][k] + abs(p[i][j] - p[i - 1][l]) * (v[i][j] + v[i - 1][l]));
					}
					if (k == 0) continue;
					if (i == 1) {
						dp[i][j][k] = 0;
						continue;
					}
					for (int l = 0; l < c[i - 2]; l++) {
						dp[i][j][k] = min(dp[i][j][k], dp[i - 2][l][k - 1] + abs(p[i][j] - p[i - 2][l]) * (v[i][j] + v[i - 2][l]));
					}
				}
			}
		}
		int ret = 999999999;
		for (int i = 0; i < c[n - 1]; i++) ret = min(ret, dp[n - 1][i][m]);
		if (m >= 1) for (int i = 0; i < c[n - 2]; i++) ret = min(ret, dp[n - 2][i][m - 1]);
		printf("%d\n", ret);
	}
	return 0;
}

Measured memory_bytes: 3260
S=input()
ls=len(S)
T=input()
lt=len(T)
ans="z"*51
for i in range(ls-lt+1):
  s=S[i:i+lt]
  hamaru=True
  now="z"*51
  for j in range(lt):
    if s[j]!="?" and s[j]!=T[j]:
      hamaru=False
  #print(hamaru)
  if hamaru:
    now=""
    for k in range(ls):
      if k in list(range(i,i+lt)):
        now+=T[k-i]
      elif S[k]=="?":
        now+="a"
      else:
        now+=S[k]
  ans=min(ans,now)
if ans=="z"*51:
  ans="UNRESTORABLE"
print(ans)

Measured memory_bytes: 3064
h,n = gets.split.map(&:to_i)  # スペースで区切られた複数の整数
ary = gets.split.map(&:to_i)  # スペースで区切られた複数の整数

newary = ary.sort {|a, b| (-1) * (a <=> b) }  # 配列降順ソート

i = 0
ans = h
while i < n do
  ans = ans - newary[i]
  i = i + 1
end

if ans <= 0 then
  puts "Yes"
else
  puts "No"
end

Measured memory_bytes: 9720
#include<iomanip>
#include<iostream>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define maxn 1000100
using namespace std;
struct node{
	int to,wi;
	node*next;
}*con[maxn];
void addedge(int x,int y,int w)
{
node*p=new node;
p->to=y;
p->wi=w;
p->next=con[x];
con[x]=p;
}
	int dist[maxn],dl[maxn<<2],head,tail;
	bool insta[maxn];
int spfa(int s)
{
	memset(insta,0,sizeof(insta));
	memset(dist,0x3f,sizeof(dist));
	head=1;tail=0;
	dist[s]=0;insta[s]=true;
	dl[++tail]=s;
	while(head<=tail)
	{
		int v=dl[head];
		for(node*p=con[v];p;p=p->next)
		if(dist[p->to]>dist[v]+p->wi) 
		{
			dist[p->to]=dist[v]+p->wi;
			if(!insta[p->to]) dl[++tail]=p->to,insta[p->to]=true;
		}
		insta[dl[head++]]=false;
	}
	return dist[0];
}
int main()
{
	int k;
	scanf("%d",&k);
	for(int i=1;i<k;++i)
	addedge(i,i*10%k,0),addedge(i,(i+1)%k,1);
	int ans=0x3f3f3f3f;
	cout<<spfa(1)+1<<endl;
	return 0;
}



Measured memory_bytes: 16768
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n, cnt = 0; long x;
	cin >> n;
	long sum = 0, mi = 0x3f3f3f3f;
	for (int i = 0; i < n; i++){
		cin >> x;
		if (mi > abs(x) ) mi = abs(x);
		if (x < 0) cnt++;
		sum += abs(x);
	}
	if (cnt % 2 == 1) sum -= 2*mi;
	cout << sum << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
const int INF = 1 << 29;

int a[110];

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

    int n;
    cin >> n;

    int max0 = -100;
    int min0 = 100;
    for(int i = 0; i < n; ++i){
        cin >> a[i];
        max0 = max(a[i], max0);
        min0 = min(a[i], min0);
    }

    int ans = INF;
    for(int i = min0; i <= max0; ++i){
        int sum = 0;
        for(int j = 0; j < n; ++j){
            sum += (i - a[j]) * (i - a[j]);
        }
        ans = min(ans, sum);
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
    ll n,i;
    cin >> n;

    vector<ll> A(n);
    vector<ll> B(n);
  
    ios::sync_with_stdio(false);
  
    for(i=1; i<n; i++){
        cin >> A.at(i);
        B.at(A.at(i)-1)++;
    }

    for(i=0; i<n; i++){
        cout << B.at(i) << endl;
    }
  
    return 0;
}


Measured memory_bytes: 6420
#include<stdio.h>

int Min(int a,int b){
	if (a>b) return b;
	else return a;}
int main(){
	int x,n;
	while(1){
	scanf("%d%d",&x,&n);
	int i=0,j=0,k=0,sum=0;
	if(x==0&&n==0) break;
	for(i=Min(x,(n-3));i>n/3;--i)
		for(j=i-1;j>(n-i)/2;--j)
			for(k=j-1;k>0;--k)
				if(i+j+k==n) ++sum;
	printf("%d\n",sum);}
	return 0;
}


Measured memory_bytes: 2104
X,Y,A,B,C=map(int,input().split())
a_list=list(map(int,input().split()))
b_list=list(map(int,input().split()))
c_list=list(map(int,input().split()))
A_list=sorted(a_list,reverse=True)
B_list=sorted(b_list,reverse=True)
apples=[]
for i in range(X):
    apples.append(A_list[i])
for i in range(Y):
    apples.append(B_list[i])
D_list= apples + c_list
ans=0
E_list=sorted(D_list,reverse=True)
for i in range(X+Y):
   ans+=E_list[i]
print(ans)

Measured memory_bytes: 24752
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

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

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        n: usize,
        s: chars
    }
    let mut ans = n;
    for i in 1..n {
        if s[i - 1] == s[i] {
            ans -= 1;
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
import java.io.ByteArrayInputStream;

import java.nio.charset.StandardCharsets;
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Collectors;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = getScanner();
    String a = scanner.nextLine().trim().toLowerCase();
    int count = 0;
    while (scanner.hasNext()) {
     String line = scanner.nextLine().trim().toLowerCase();
     if(!"END_OF_TEXT".equals(line)) {
       count += Arrays.stream(line.split(" ")).filter(s -> a.equals(s)).collect(Collectors.toList()).size();
     }
    }
    System.out.println(count);
  }

static Scanner getScanner() {    return new Scanner(System.in);  }
}


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

using namespace std;

int main(void)
{
    int N;
    int A;

    cin >> N;

    vector<int> ord(N);
    for (int i = 0; i < N; i++) {
        cin >> A;        
        ord[A - 1] = i + 1;
    }
    
    for (int i = 0; i < N; i++) {
        if (i == N - 1) cout << ord[i] << endl;
        else            cout << ord[i] << " ";
    }

    return 0;
}


Measured memory_bytes: 1152
fun main(args : Array<String>) {
    // a の約数.filter prime count
    // bの約数
    // A とBの公約数列挙　素数の数
    val (A, B) = readLine()!!.split(" ").map { it.toLong() }

    val a = divisors(A).toHashSet()
    val b = divisors(B)

    var answer = 1L
    b.forEach {
        if (a.contains(it) && isPrime(it)) {
            answer++
        }
    }

    println(
            answer
    )
}

// O(√n)
fun isPrime(n: Long) : Boolean {
    for (i in 2..(Math.sqrt(n.toDouble())).toLong()) {
        // iで割れるなら素数でない
        if (n % i == 0L) {
            return false
        }
    }

    return n != 1L
}

// O(√n)
fun divisors(n: Long) : List<Long> {
    val list = mutableListOf<Long>()
    for (i in 1L..(Math.sqrt(n.toDouble())).toLong()) {
        // iで割れるならカウント
        if (n % i == 0L) {
            list.add(i)
            // iの対となるもうひとつの約数も入れる.
            if (i != n / i) {
                list.add(n / i)
            }
        }
    }

    return list
}
// O(√n)
fun primeFactor(n: Long) : Map<Long, Long> {
    val map = mutableMapOf<Long, Long>()
    var num = n;
    for (i in 2..(Math.sqrt(n.toDouble())).toLong()) {
        // iで割れるところまで割り続ける
        while (num % i == 0L) {
            if (map[i] == null) {
                map[i] = 1L
            } else {
                map[i] = 1L + map[i]!!
            }
            num /= i;
        }
    }
    // 残りが1Lじゃなかったらそれもカウントする
    if (num != 1L) map[num] = 1L

    return map
}


Measured memory_bytes: 40312
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> P;
 
const int INF = 1e9;
const int mod = 1e9+7;
const double EPS = 1e-10;
const double PI = acos(-1.0);

int main()
{
    string s;
    cin >> s;
    if((s[5]-'0')*10+(s[6]-'0') <= 4){
        if((s[8]-'0')*10+(s[9]-'0') <= 30){
            cout << "Heisei" << endl;
        }else cout << "TBD" << endl;
    }else cout << "TBD" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt(), m = sc.nextInt(), c = sc.nextInt();
        int[] b = new int[m];
        for (int i = 0; i < m; i++) b[i] = sc.nextInt();
        int ans = 0;
        for (int i = 0; i < n; i++) {
            int a = 0;
            for (int j = 0; j < m; j++) {
                a += sc.nextInt() * b[j];
            } if (a + c > 0) ans += 1;
        }

        System.out.println(ans);

    }
}


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

typedef struct{
  int p;
  int y;
  int i;
  int n;
} city_t;

int sort1(const void *a, const void *b){
  if(((city_t*)a)->p!=((city_t*)b)->p){
    return ((city_t*)a)->p - ((city_t*)b)->p;
  }else{
    return ((city_t*)a)->y - ((city_t*)b)->y;
  }
}

int sort2(const void *a, const void *b){
  return ((city_t*)a)->i - ((city_t*)b)->i;
}

int main(void){
  int n,m;
  
  scanf("%d%d",&n,&m);
  city_t city[m];
  for(int i=0;i<m;i++){
    scanf("%d %d",&city[i].p,&city[i].y);
    city[i].i=i;
  }
  
  qsort(city,m,sizeof(city_t),sort1);
  
  city[0].n=1;
  for(int i=1;i<m;i++){
    if(city[i].p==city[i-1].p) city[i].n=city[i-1].n+1;
    else city[i].n=1;
  }
  
  qsort(city,m,sizeof(city_t),sort2);
  
    for (int i=0; i<m; i++){
        if (city[i].p==100000){
            printf("100000");
        } else if (city[i].p>=10000){
            printf("0%d",city[i].p);
        } else if (city[i].p>=1000){
            printf("00%d",city[i].p);
        } else if (city[i].p>=100){
            printf("000%d",city[i].p);
        } else if (city[i].p>=10){
            printf("0000%d",city[i].p);
        } else {
            printf("00000%d",city[i].p);
        }
        if (city[i].n==100000){
            printf("100000\n");
        } else if (city[i].n>=10000){
            printf("0%d\n",city[i].n);
        } else if (city[i].n>=1000){
            printf("00%d\n",city[i].n);
        } else if (city[i].n>=100){
            printf("000%d\n",city[i].n);
        } else if (city[i].n>=10){
            printf("0000%d\n",city[i].n);
        } else {
            printf("00000%d\n",city[i].n);
        }
    }
  return 0;
}

Measured memory_bytes: 4580
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#define rep(i,a,b) for(register int i(a);i <= b;i++)
#define ll long long
using namespace std;
const ll mod = 1000000007;
int main()
{
	int n,x,k(0);ll ans(1);
	scanf("%d",&n);
	rep(i,1,n)
	{
		scanf("%d",&x);++k;
		if(x < (k << 1) - 1) ans *= k,ans %= mod,--k;
	}
	while(k != 1) ans *= k,ans %= mod,--k;
	printf("%lld",ans);
	return 0;
}

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


int main() {
int  S;
  cin >>S;
  if(S/100 >=1 &&S/100 <=12 && S%100 >=1 &&S%100 <=12 ) puts ("AMBIGUOUS");
  else if (S/100 >=1 &&S/100 <=12 ) puts ("MMYY");
  else if( S%100 >=1 &&S%100 <=12 ) puts ("YYMM");
  else puts ("NA");
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
const int N = 2e6 + 10;
int a[N];
using namespace std;

signed main() {
	int ans = 0;
	int n;
	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
	}
	sort(a + 1, a + 1 + n);
	for (int i = 1; i <= n; i++) {
		if (a[i] == a[i + 1])ans = 1;
	}
	if (ans) cout << "NO" << endl;
	else cout << "YES" << endl;
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define f first
#define s second
typedef long long ll;
typedef vector<int> lnum;
const int base = 1000*1000*1000;
#define pb push_back
#define mp make_pair


const int mod = 1000 * 1000 * 1000 + 7;
const int INF = 1000 * 1000 * 1000;
const ll LINF = (ll)INF * INF;
ll a , b , c , k;
int main()
{
	//memset(dpT , -1 , sizeof dpT);
	ios_base::sync_with_stdio(0);
	//freopen("input.txt" , "r"  , stdin);
	cin >> a >> b >> c >> k;
	if((k % 2))
	{
		cout << b - a;
	}
	else
		cout << a - b;


}




Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int n = scan.nextInt();
		int sum = 0;
		for(int i=0; i<n; ++i) {
			sum += scan.nextInt();
		}

		if(sum >= h) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

Measured memory_bytes: 48204
import Control.Monad
import qualified Data.Map as M

main = do
    [h, w] <- map read . words <$> getLine
    maze <- toMap h w <$> replicateM h getLine
    print $ maximum [pathLength maze i j| i <- [1..h], j <- [1..w]]

toMap h w xss = toMap' h w 1 1 xss
  where
    toMap' h w _ _ [] = M.fromList [((i,j),'#')|i<-[0..h+1],j<-[0..w+1],i==0||i==h+1||j==0||j==w+1]
    toMap' h w i j ([]:xss) = toMap' h w (i+1) 1 xss
    toMap' h w i j ((x:xs):xss) = M.insert (i,j) x (toMap' h w i (j+1) (xs:xss))

pathLength maze i j = bfs 0 [((i,j), 0)] maze
    where bfs l [] maze = l
          bfs l (((i,j),d) : q) maze
              | maze M.! (i,j) == '#' = bfs l q maze
              | otherwise = bfs d (q ++ r) $ M.insert (i,j) '#' maze
                  where r = [((x,y),d+1)|(x,y)<-[(i-1,j),(i+1,j),(i,j-1),(i,j+1)], maze M.! (x,y) == '.']

Measured memory_bytes: 2428
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;

pub fn readln() -> String {
    let mut line = String::new();
    ::std::io::stdin()
        .read_line(&mut line)
        .unwrap_or_else(|e| panic!("{}", e));
    line
}

macro_rules! read {
	($($t:tt),*; $n:expr) => {{
		let stdin = ::std::io::stdin();
		let ret = ::std::io::BufRead::lines(stdin.lock()).take($n).map(|line| {
			let line = line.unwrap();
			let mut it = line.split_whitespace();
			_read!(it; $($t),*)
		}).collect::<Vec<_>>();
		ret
	}};
	($($t:tt),*) => {{
		let line = readln();
		let mut it = line.split_whitespace();
		_read!(it; $($t),*)
	}};
}

macro_rules! _read {
	($it:ident; [char]) => {
		_read!($it; String).chars().collect::<Vec<_>>()
	};
	($it:ident; [u8]) => {
		Vec::from(_read!($it; String).into_bytes())
	};
	($it:ident; [$t:ty]) => {
		$it.map(|s| s.parse::<$t>().unwrap_or_else(|e| panic!("{}", e))).collect::<Vec<_>>()
	};
	($it:ident; $t:ty) => {
		$it.next().unwrap_or_else(|| panic!("input mismatch")).parse::<$t>().unwrap_or_else(|e| panic!("{}", e))
	};
	($it:ident; $($t:ty),+) => {
		($(_read!($it; $t)),*)
	};
}

fn main() {
    let (n, m) = read!(usize, usize);

    let mut keys = vec![];
    for i in 0..m {
        let (a, b) = read!(u64, usize);
        let mut mask = 0;
        let c = read!([usize]);
        for &c_ in &c {
            mask |= 1<<(c_-1);
        }
        keys.push((a, mask));
    }

    let mut dp = vec![std::u64::MAX / 2; 1 << n];
    dp[0] = 0;

    for &(p, mask) in &keys {
        for mask_ in 0..(1 << n) {
            let acc = mask_ | mask;
            dp[acc] = min(dp[acc], dp[mask_] + p);
        }
    }
    let ans = dp[(1 << n) - 1];
    if ans == std::u64::MAX / 2 {
        println!("-1");
    } else {
        println!("{}", ans);
    }
}


Measured memory_bytes: 4352
#include <stdio.h>
#include <stdlib.h>
#define N 100
#define FAC 1000
int main()
{
  int i,j,k,v,card[N],n;
  scanf("%d",&n);
  if( n > N )
    exit(1);
  for( i = 0; i < n; i++ )
    {
      scanf("%d",&card[i]);
      if( card [i] > FAC || card[i] < 0 )
	exit(1);
    }
  for( i = 1; i <= n; i++ )
    {
      for( k = 0; k < n; k++ )
	{
	  if( k == n-1 )printf("%d",card[k]);
	  else printf("%d ",card[k]);
	}
      printf("\n");
      v = card[i];
      j = i-1;
      while ( j >= 0 && card[j] > v )
	{
	  card[j+1] = card[j];
	  j--;
	  card[j+1] = v;
	}
    }
  return 0;
}



Measured memory_bytes: 2084
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int cntOdd = 0;
		
		for (int i = 0; i < n; i++) {
			int a = sc.nextInt();
			if (a % 2 == 1)
				cntOdd++;
		}
		
		String ans = cntOdd % 2 == 0 ? "YES" : "NO";
		
		System.out.println(ans);
	}

}


Measured memory_bytes: 49432
N, M = map(int, input().split())
# N:スイッチの数、M：電球の数
s = [[] for _ in range(M)]
for i in range(M):
    temp = list(map(int, input().split()))
    s[i] = temp[1:]
p = list(map(int, input().split()))
ans = 0

# bit全探索
for i in range(2 ** N):
    on = [0 for _ in range(M)]
    for j in range(N): 
        if (i >> j) & 1:
            for k in range(M):
                if j+1 in s[k]:
                    on[k] += 1
    tf = []
    for on_n, p_n in zip(on, p):
        if on_n % 2 == p_n:
            tf.append(True)
        else:
            tf.append(False)
    if all(flg for flg in tf):
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int comp_char(const void*a,const void*b){
     char *aa=(char*)a;
     char *bb=(char*)b;
     return strcmp(aa,bb);
} 
int main(void){
 int n,ans=1;
 static char s[200000][11];
 scanf("%d",&n);
 for(int i=0;i<n;i++){
    scanf("%s",s[i]);
 }
 qsort(s,n,sizeof(s[0]),comp_char);
 for(int i=1;i<n;i++){
    if(strcmp(s[i],s[i-1])==0){
       continue;
    }else{
       ans++;
    }
   }
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 5688
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

unsigned euclidean_gcd(unsigned a, unsigned b) {
  if(a < b) return euclidean_gcd(b, a);
  unsigned r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main()
{
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    long long count1 = 0;
    count1 += b / c;
    count1 -= a / c;
    if (a % c == 0)
    {
        count1++;
    }

    long long count2 = 0;
    count2 += b / d;
    count2 -= a / d;
    if (a % d == 0)
    {
        count2++;
    }

    //ll xxx=gcd(c,d);

    ll xxx=euclidean_gcd(c,d);


    xxx = c * d / xxx;

    long long count3 = 0;
    count3 += b / xxx;
    count3 -= a / xxx;
    if (a % xxx == 0)
    {
        count3++;
    }

    ll lll = count1 + count2 - count3;
    cout << (long long)(b - a + 1 - lll) << endl;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {

	public static void main(String[] args) {
	Scanner cin = new Scanner(System.in);
	while(true){
		int n,c=0;
		n=cin.nextInt();
		if(n==0){
			break;
		}
		for(int i=1;i<n+1;i++){
			int q=i;
			while(true){
				if(q%5==0){
					c=c+1;
					q=q/5;
				}
				if(q%5!=0){
					break;
				}
		    }
			}
		System.out.println(c);
	}
	}
}

Measured memory_bytes: 18044
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int n, b, f, r, v;
    int i, j, k;
    int x[4][3][10]={0};
    
    scanf("%d", &n);
    
    for (i=0; i<n; i++) {
        scanf("%d %d %d %d", &b, &f, &r, &v);
        x[b-1][f-1][r-1]+=v;
    }
    
    for (i=0; i<4; i++) {
        for (j=0; j<3; j++) {
            for (k=0; k<10; k++) {
                printf(" %d", x[i][j][k]);
            }
            printf("\n");
        }
        if (i != 3) {
            printf("####################\n");
        }
    }
    return 0;
}

Measured memory_bytes: 612
let readInt _ = stdin.ReadLine() |> int
let choice ok ng bool = if bool then ok else ng

()
|> readInt
|> fun x ->
    x
    |> string
    |> fun x -> x.ToCharArray()
    |> Array.map string
    |> Array.map int
    |> Array.sum
    |> (%) x
    |> (=) 0
    |> choice "Yes" "No"
    |> printfn "%s"


Measured memory_bytes: 29608
#include<bits/stdc++.h>
#define mod 1000003
#define fr first
#define se second
#define ll long long
#define PI 3.1415926535 
#define pb push_back
#define mpr make_pair
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define senky_bansal ios_base::sync_with_stdio(false);
#define IIIT_ALLAHABAD    cin.tie(NULL);cout.tie(NULL);
using namespace std;
ll fac[1000003];
ll ifac[1000003];
ll power(ll a,ll b)
{
    ll res=1;
    while(b)
    {
        a%=mod;
        if(b&1) res=(res*a)%mod;
        a=(a*a)%mod;
        b=b/2;
    }
    return res%mod;
}
signed main()
{   
      senky_bansal
      IIIT_ALLAHABAD
      
      fac[0]=1;
      fac[1]=1;
      for(int i=2;i<1000003;i++)
        fac[i]=(i*fac[i-1])%mod;
      ifac[1000002] = power(fac[1000002],mod-2);
      for(int i=1000001;i>=0;i--)
      {
          ifac[i]=((i+1)*ifac[i+1])%mod;
      }
      ll q;
      cin>>q;
      while(q--)
      {
        ll x,d,n;
        cin>>x>>d>>n;
        if(d==0)
        {
            cout<<power(x,n)<<endl;
        }
        else
        {
        //   cout<<ifac[d]<<endl;
          // cout<<power(d,mod-2)<<endl; 
           ll p = (x*power(d,mod-2))%mod;
           ll r = power(d,n);
           if(p+n-1>=mod)
           {
            cout<<"0"<<endl;
           }
           else
           {
              cout<<((fac[p+n-1]*power(fac[p-1],mod-2))%mod*r)%mod<<endl;
           }
        }
      }

    

}

Measured memory_bytes: 16512
#include <iostream>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <string>
#include <vector>
#include <queue>
#include <map>
#include <set>
#include <tuple>
#include <algorithm>
#include <functional>
#include <cstring>
#include <limits.h>
#include <bitset>
#include <complex>
#include <cassert>
#define FOR(i,k,n)  for (int i=(k); i<(int)(n); ++i)
#define REP(i,n)    FOR(i,0,n)
#define FORIT(i,c)	for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define SZ(i) ((int)i.size())
#define GI(i) (scanf("%d",&i))
#define GLL(i) (scanf("%lld",&i))
#define GD(i)  (scanf("%lf",&i))
#define PB          push_back
#define MP          make_pair
#define MT          make_tuple
#define GET0(x)     (get<0>(x))
#define GET1(x)     (get<1>(x))
#define GET2(x)     (get<2>(x))
#define ALL(X)      (X).begin(),(X).end()
#define LLMAX       (1LL<<60)
#define LLMIN       -(1LL<<60)
#define IMAX        (1<<30)
#define IMIN        -(1<<30)
typedef long long LL;
using namespace std;

int main(void){
    LL N,K;
    GLL(N);GLL(K);
    if(K==0){
        printf("%lld\n",N*N);
        return 0;
    }
    LL ans = 0;
    for(LL b = K+1;b<=N;b++){
        // printf("b=%lld\n",b);
        for(LL a = 0;a<=N;a+=b){
            // printf("a=%lld\n",a);
            // printf("min(N,a+b-1) - a+(K-1) = %lld\n",min(N,a+b-1) - (a+(K-1)));
            ans += max((LL)0,min(N,a+b-1) - (a+(K-1)));
        }
    }
    printf("%lld\n",ans);
    return 0;
}


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

int main(){
	int N;
	cin >> N;
	vector<ll> A(N+1);
	for(int i(0);i<N+1;++i) cin >> A[i];
	ll B,prev_B,ans(0);
	for(int i(0);i<N;++i){
		cin >> B;
		if(A[i] >= B){
			ans += B;
		}else{
			ans += A[i];
			B -= A[i];
			if(B >= A[i+1]){
				ans += A[i+1];
				A[i+1] = 0;
			}else{
				ans += B;
				A[i+1] -= B;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
#define For(i,x,y) for (register int i=(x);i<=(y);i++)
#define FOR(i,x,y) for (register int i=(x);i<(y);i++)
#define Dow(i,x,y) for (register int i=(x);i>=(y);i--)
#define Debug(v) for (auto i:v) printf("%lld ",i);puts("")
#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define ep emplace_back
#define siz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define fil(a,b) memset((a),(b),sizeof(a))
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pa;
typedef pair<ll,ll> PA;
typedef vector<int> poly;
inline ll read(){
    ll x=0,f=1;char c=getchar();
    while ((c<'0'||c>'9')&&(c!='-')) c=getchar();
    if (c=='-') f=-1,c=getchar();
    while (c>='0'&&c<='9') x=x*10+c-'0',c=getchar();
    return x*f;
}

const int N = 3010, mod = 998244353;
int a,b,c,d,dp[N][N];

int main(){
	a=read(),b=read(),c=read(),d=read();
	dp[a][b]=1;
	For(i,a,c)
		For(j,b,d) if (i!=a||j!=b){
			dp[i][j]=(1ll*dp[i-1][j]*j+1ll*dp[i][j-1]*i)%mod;
			dp[i][j]=(dp[i][j]+1ll*(mod-dp[i-1][j-1])*(i-1)%mod*(j-1))%mod;
		}
	printf("%d\n",dp[c][d]);
}

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

int int_cmp(const int *a, const int *b)
{
	if (*a > *b)
		return 1;
	else if (*a < *b)
		return -1;
	else
		return 0;
}


int main(void)
{
	int n, q, c;
	int S[100000], T[50000];
	int i, j;


	scanf("%d", &n);
	for (i = 0; i < n; i++)
		scanf("%d", &S[i]);
	
	scanf("%d", &q);
	for (i = 0; i < q; i++)
		scanf("%d", &T[i]);

	qsort(T, q, sizeof(int), (int (*)(const void *, const void *))int_cmp);

	c = 0;
	j = 0;
	for (i = 0; i < q; i++){
		while (T[i] > S[j] && j < n-1)
			j++;
		if (T[i] == S[j])
			c++;
	}
	printf("%d\n", c);

	return 0;
}

Measured memory_bytes: 1228
from itertools import combinations

n, x, y = map(int, input().split())
x -= 1
y -= 1
dist = [0] * n

for i, j in combinations(list(range(n)), 2):
    num = min((abs(x - i) + 1 + abs(y - j)), (abs(y - i) + 1 + abs(x - j)), abs(i - j))
    dist[num] += 1

for i in range(1, n):
    print(dist[i])


Measured memory_bytes: 3444
N = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

sum = 0
prev = -1
for num in A:
    sum += B[num-1]
    if num - prev == 1:
        sum += C[prev-1]
    prev = num
print(sum)


Measured memory_bytes: 3060
MOD=2019
S=input()
N=len(S)
nums=[0]*N
nums[-1]=int(S[-1])%MOD
for i in range(-2, -N-1, -1):
  nums[i]=(int(S[i])*pow(10, -(i+1), MOD)+nums[i+1])%MOD

a=[0]*2019
for i in range(N):
  a[nums[i]]+=1
  
print(a[0]+sum([(a[i]*(a[i]-1))//2 for i in range(2019)]))

Measured memory_bytes: 16364
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a[214514];
int main(){
	ll n,k;
	cin>>n>>k;
	ll ma=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		ma=max(ma,a[i]);
	}
	ll ok=ma,ng=0;
	while(ok-ng>1){
		ll mid=(ok+ng)/2;
		ll cnt=0;
		for(int i=0;i<n;i++)cnt+=(a[i]+mid-1)/mid-1;
		if(cnt<=k)ok=mid;
		else ng=mid;
	}
	cout<<ok;
	return 0;
}


Measured memory_bytes: 5148
while 1:
    try:
        s=list(input())
        ans=""
        while len(s)>0:
            i=s.pop(0)
            if i=="@":
                c=s.pop(0)
                l=s.pop(0)
                ans+=l*int(c)
            else:ans+=i
        print(ans)
    except:break


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

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

    string ans;
    if (s.compare("2019/04/30") <= 0) {
        ans = "Heisei";
    } else {
        ans = "TBD";
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#pragma GCC optimize("unroll-loops")
#pragma warning(disable : 4996)
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<math.h>
#include<iomanip>
#include<set>
#include<numeric>
#include<cstring>
#include<cstdio>
#include<functional>
#include<bitset>
#include<limits.h>
#include<cassert>
#include<iterator>
#include<complex>
#include<stack>
#include<unordered_map>
#include<unordered_set>
#include<time.h>
#include<random>
#include<array>


using namespace std;

#define REP(i, n) for(int i = 0;i < n;++i)
#define REPR(i, n) for(int i = n-1;i >= 0;--i)
#define FOR(i, m, n) for(int i = m;i < n;++i)
#define FORR(i, m, n) for(int i = m-1;i >= n;--i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define REVERSE(v,n) reverse(v,v+n);
#define VREVERSE(v) reverse(v.begin(), v.end())
#define ll long long
#define print(x) cout<<(x)<<'\n'
#define pe(x) cout<<(x)<<" "
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define lb(v,n) lower_bound(v.begin(), v.end(), (n))
#define ub(v,n) upper_bound(v.begin(), v.end(), (n))
#define int long long
//#define double long double
#define all(x) (x).begin(), (x).end()
#define print_space(v) REP(i,v.size())cout << v[i] << ((i == v.size() - 1) ? "\n" : " ")
template<typename T1, typename T2> inline void chmin(T1 & a, T2 b) { if (a > b) a = b; }
template<typename T1, typename T2> inline void chmax(T1& a, T2 b) { if (a < b) a = b; }
typedef pair<int, int>pii;
typedef array<int, 3> arr3;
std::random_device rd;
std::mt19937 mt(rd());
constexpr ll MOD = 1e9 + 7; constexpr int MAX = 2000020;
const double pi = acos(-1); constexpr double EPS = 1e-8;
constexpr ll INF = 1e18;
void y(bool c) {
	if (c)print("Yes");
	else print("No");
}
long long gcd(long long x, long long y) {
	long long m = max(x, y), n = min(x, y);
	if (m%n == 0)return n;
	else return gcd(m%n, n);
}
void solve() {
	int N; cin >> N;
	vector<int>D(N);
	int sum = 0;
	REP(i, N) {
		cin >> D[i];
		if (i & 1)sum -= D[i];
		else sum += D[i];
	}
	vector<int>ans(N);
	ans[0] = sum;
	REP(i, N - 1) {
		ans[i + 1] = (D[i] - ans[i]/2) * 2;
	}
	print_space(ans);
}

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	//int q; cin >> q;
	//while (q--)
	solve();
}




Measured memory_bytes: 2944
using System;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Globalization;
using System.Diagnostics;
using static System.Console;
using Pair = System.Collections.Generic.KeyValuePair<int, int>;
//using System.Numerics;
using static System.Math;

class Program
{
    static void Main()
    {
        //SetOut(new StreamWriter(OpenStandardOutput()) { AutoFlush = false });
        new Program().solve();
        Out.Flush();
    }
    Scanner cin = new Scanner();
    Random rnd = new Random();
    Stopwatch sw = new Stopwatch();
    readonly int[] dd = { 0, 1, 0, -1, 0 };
    readonly int mod = 1000000007;
    readonly string alfa = "abcdefghijklmnopqrstuvwxyz";
    readonly string ALFA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

    int N;
    void solve()
    {
        WriteLine(Math.Max(0, cin.nextint - cin.nextint));
    }

}

class Scanner
{
    string[] s; int i;
    char[] cs = new char[] { ' ' };
    public Scanner() { s = new string[0]; i = 0; }
    public string[] scan { get { return ReadLine().Split(); } }
    public int[] scanint { get { return Array.ConvertAll(scan, int.Parse); } }
    public long[] scanlong { get { return Array.ConvertAll(scan, long.Parse); } }
    public double[] scandouble { get { return Array.ConvertAll(scan, double.Parse); } }
    public string next
    {
        get
        {
            if (i < s.Length) return s[i++];
            string st = ReadLine();
            while (st == "") st = ReadLine();
            s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
            i = 0;
            return next;
        }
    }
    public int nextint { get { return int.Parse(next); } }
    public long nextlong { get { return long.Parse(next); } }
    public double nextdouble { get { return double.Parse(next); } }
}

Measured memory_bytes: 13264
import std.algorithm;
import std.array;
import std.conv;
import std.math;
import std.range;
import std.stdio;
import std.string;
import std.typecons;

T read(T)() { return readln.chomp.to!T; }
T[] reads(T)() { return readln.split.to!(T[]); }
alias readint = read!int;
alias readints = reads!int;

int calc(int[] a) {
    int ans = 1;
    int h = a[0];
    for (int i = 1; i < a.length; i++) {
        if (h <= a[i]) ans++;
        h = max(h, a[i]);
    }
    return ans;
}

void main() {
    readint;
    auto a = readints;
    writeln(calc(a));
}



Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N, M = map(int, input().split())

S = []
C = []

for i in range(M):
    s, c = map(int, input().split())
    S.append(s)
    C.append(c)


X = [None for i in range(N)]

for j in range(M):
    value = C[j]
    i = S[j] - 1

    if X[i] is None:
        X[i] = value
    elif X[i] != value:
        print(-1)
        exit(0)

if X[0] == 0 and N >= 2:
    print(-1)
else:
    if X[0] is None and N >= 2:
        X[0] = 1
    print(''.join(['{}'.format(x or 0) for x in X]))

Measured memory_bytes: 3064
package main

import (
	"fmt"
	"math"
)

func calcArea(round float64) float64 {
	return math.Pow(round, 2) * math.Pi
}
func calcLength(round float64) float64 {
	return 2 * math.Pi * round
}
func formatF(val float64) string {
	return fmt.Sprintf("%.6f", val)
}

func main() {
	var round float64

	fmt.Scan(&round)
	fmt.Println(formatF(calcArea(round)),
		formatF(calcLength(round)))
}



Measured memory_bytes: 1204
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
from typing import Iterable
import sys
def main():
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    uf = UnionFindTree(N)
    ans = []
    for _ in range(Q):
        t, u, v = map(int, input().split())
        if t:
            ans.append('1' if uf.same(u, v) else '0')
        else:
            uf.union(u, v)
    print('\n'.join(ans))

class UnionFindTree:
    __slots__ = ('parent')

    def __init__(self, n: int) -> None:
        self.parent = [-1] * n

    def find(self, x: int) -> int:
        p = self.parent
        while p[x] >= 0: x, p[x] = p[x], p[p[x]]
        return x

    def union(self, x: int, y: int) -> bool:
        x, y, p = self.find(x), self.find(y), self.parent
        if x == y: return False
        if p[x] > p[y]: x, y = y, x
        p[x], p[y] = p[x] + p[y], x
        return True

    def same(self, x: int, y: int) -> bool:
        return self.find(x) == self.find(y)

    def size(self, x: int) -> int:
        return -self.parent[self.find(x)]

    def same_all(self, indices: Iterable[int]) -> bool:
        f, v = self.find, self.find(indices[0])
        return all(f(i) == v for i in indices)

if __name__ == '__main__':
    main()


Measured memory_bytes: 78788
#include <algorithm>
#include <iostream>
#include <cstdio>
#include <vector>
#include <cmath>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long lli;
typedef pair<int, int> pii;
const int INF = 1e9;
int n, k, s;
vector<int> a;

void ReadInput()
{
    cin >> n >> k >> s;
    a.resize(n);
}

void Solve()
{
    for(int i = 0; i < k; ++i)
        a[i] = s;
    for(int i = k; i < n; ++i)
        a[i] = (s == INF) ? INF - 1 : INF;
    for(auto to: a)
        cout << to << ' ';
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    ReadInput();
    Solve();
}


Measured memory_bytes: 1792
import std.algorithm, std.array, std.container, std.range, std.bitmanip;
import std.numeric, std.math, std.bigint, std.random, core.bitop;
import std.string, std.regex, std.conv, std.stdio, std.typecons;

void main()
{
  auto rd = readln.split.map!(to!size_t);
  auto n = rd[0], m = rd[1];
  auto aij = iota(n).map!(_ => readln.split.map!(to!int)).array;
  auto bi = iota(m).map!(_ => readln.chomp.to!int).array;

  auto ci = new int[](n);
  foreach (i; 0..n)
    ci[i] = iota(m).map!(j => aij[i][j] * bi[j]).sum;

  ci.each!(writeln);
}

Measured memory_bytes: 2636
class BIT():
    """数列aに対して以下の操作がO(log n) でできる
    - add(i,x): a[i] += x
    - sum_1_to_i(i): 区間[1, i]のaの総和
    
    sum_i_to_j(i,j): 区間[i,j]のaの総和
    数列aは0に初期化されているとする"""
    def __init__(self, n:int):
        self.n = n
        self.bit = [0]*(n+1)
        
    def add(self, i:int, x:int):
        """i番目(1-idexed)にxを加算"""
        while i<=self.n:
            self.bit[i] += x
            i += i&-i
            
    def sum_1_to_i(self, i:int)->int: 
        """1番目からi番目(含む)までの総和"""
        s=0
        while i>0:
            s += self.bit[i]
            i -= i&-i
        return s
    
    def sum_i_to_j(self, i:int, j:int):
        """i番目からj番目(含む)までの総和"""
        return self.sum_1_to_i(j) - self.sum_1_to_i(i-1)
    
#####
n,q = map(int, input().split())
bit = BIT(n)
for _ in range(q):
    com,x,y = map(int, input().split())
    if com==0:
        bit.add(x,y)
    else:
        print(bit.sum_i_to_j(x,y))


Measured memory_bytes: 7944
#include <iostream>
#include <string>
using namespace std;
int main()
{
	string str;
	cin >> str;
	int num_0=0;
	for (int i = 0; i < str.length(); ++i) {
		if (str[i] == '0') {
			num_0++;
		}
	}
	int num_1 = str.length() - num_0;
	if (num_0 < num_1) {
		cout << num_0*2 << endl;
	}
	else {
		cout << num_1 * 2 << endl;
	}
	return 0;
}


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

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

    vector<int> x(N), y(N), h(N);
    int se = 0;
    rep(i, N) {
        cin >> x[i] >> y[i] >> h[i];
        if (h[i] != 0)
            se = i;
    }

    rep(i, 101) {
        rep(j, 101) {
            bool flag = true;
            int top = abs(x[se] - i) + abs(y[se] - j) + h[se];
            rep(k, N) {
                if (h[k] == 0) {
                    if (top - abs(x[k] - i) - abs(y[k] - j) > 0) {
                        flag = false;
                        break;
                    }
                } else if (top != abs(x[k] - i) + abs(y[k] - j) + h[k]) {
                    flag = false;
                    break;
                }
            }

            if (flag) {
                cout << i << " " << j << " " << top << endl;
                return 0;
            }
        }
    }

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define int long long
using namespace std;
#define deb(x) cout<<#x<<" = "<<x<<"\n";
#define F first
#define S second
 
signed main()
{
	//#ifndef ONLINE_JUDGE
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);
	//#endif
	/************************************/
	
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a, a+3);
	cout<<a[1]+a[0];
	
	
	
	
	
	
	
}

Measured memory_bytes: 256
#include <stdio.h>

int search(int A[],int n, int key)
{
	int i = 0;
	A[n] = key;
	while(A[i] != key) i++;
	return i != n;
}

int main()
{
	int i,n,A[10000+1],q,key,sum = 0;
	
	scanf("%d",&n);
	for(i = 0; i < n; i++) scanf("%d",A + i);
	
	scanf("%d",&q);
	for(i = 0; i < q; i++)
	{
		scanf("%d",&key);
		if(search(A,n,key)) sum++;
	}
	
	printf("%d\n",sum);
	
	return 0;
}

Measured memory_bytes: 636
#include<bits/stdc++.h>
using namespace std;
const int N=105;
int ans,b[N];
int main()
{
    int n;
    scanf("%d",&n);
    for(int i=1;i<n;i++)
        scanf("%d",&b[i]);
    b[n]=0x3f3f3f3f;
    for(int i=n-1;i>0;i--)
        ans+=min(b[i],b[i+1]);
    ans+=b[1];
    cout<<ans<<endl; 
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using vs = vector<string>;
using msi = map<string, int>;
using mii = map<int, int>;
using psi = pair<string, int>;
using pii = pair<int, int>;
using tii = tuple<int, int>;
using vlai = valarray<int>;
#define rep(i,n) for(int i=0;i<n;i++)
#define range(i,s,n) for(int i=s;i<n;i++)
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define fs first
#define sc second
#define INF 1E9
#define LINF 1E18*5
#define EPS 1E-9
#define MOD 1000000007
#define PI 3.1415926535897932384

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

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

class compare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return (get<1>(a) < get<1>(b));
	}
};

class pcompare {
public:
	bool operator()(tuple<int, int> a, tuple<int, int> b) {
		return !(get<1>(a) < get<1>(b));
	}
};

int main() {
	ll n;
	int ans = 0;
	cin >> n;
	vl x(n), y(n);
	vector<tii> xv, yv;
	vector<vector<tii>> xe(n), ye(n);
	vb used(n, false);
	rep(i, n) {
		cin >> x[i] >> y[i];
		xv.push_back(tii(i, x[i]));
		yv.push_back(tii(i, y[i]));
	}
	sort(all(xv),compare()); sort(all(yv),compare());
	range(i, 1, n) {
		xe[get<0>(xv[i])].push_back(tii(get<0>(xv[i - 1]), abs(get<1>(xv[i]) - get<1>(xv[i - 1]))));
		xe[get<0>(xv[i - 1])].push_back(tii(get<0>(xv[i]), abs(get<1>(xv[i]) - get<1>(xv[i - 1]))));
		ye[get<0>(yv[i])].push_back(tii(get<0>(yv[i - 1]), abs(get<1>(yv[i]) - get<1>(yv[i - 1]))));
		ye[get<0>(yv[i - 1])].push_back(tii(get<0>(yv[i]), abs(get<1>(yv[i]) - get<1>(yv[i - 1]))));
	}
	used[0] = true;
	priority_queue<tii, vector<tii>, pcompare> q;
	rep(i, xe[0].size()) {
		q.push(xe[0][i]);
	}
	rep(i, ye[0].size()) {
		q.push(ye[0][i]);
	}
	rep(i, n - 1) {
		while (used[get<0>(q.top())]) {
			q.pop();
		}
		int to = get<0>(q.top());
		used[to] = true;
		ans += get<1>(q.top()); q.pop();
		rep(j, xe[to].size()) {
			if (!used[get<0>(xe[to][j])]) q.push(tii(xe[to][j]));
		}
		rep(j, ye[to].size()) {
			if (!used[get<0>(ye[to][j])])q.push(tii(ye[to][j]));
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 15852
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int i,j,count=0;
    string S,T;
    cin>>S>>T;
    for(i=0;i<S.size();i++)
    {
        if(S[i]!=T[i])
        {
            count++;
        }
    }
    cout<<count<<endl;

    return 0;
}



Measured memory_bytes: 3840