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

using namespace std;

#define INF 1000000007
#define LINF (1LL << 60)
#define PI 3.14159265358979

typedef long long i64;
typedef pair<i64,i64> P;

inline i64 mod(i64 a, i64 m) { return (a % m + m) % m; }

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; }



i64 n,m,A,B,C, a[101010], b[101010], c[101010];
void solve(){
	cin >> n >> m >> A >> B >> C;
	for(int i = 0; i < A; i++){
		cin >> a[i];
	}
	sort(a,a+A,greater<i64>());
	for(int i = 0; i < B; i++){
		cin >> b[i];
	}
	sort(b,b+B,greater<i64>());
	for(int i = 0; i < C; i++){
		cin >> c[i];
	}
	sort(c,c+C,greater<i64>());
	
	i64 ans = 0;
	for(int i = 0; i < n; i++){
		ans += a[i];
	}
	for(int i = 0; i < m; i++){
		ans += b[i];
	}
	n--; m--;
	for(int i = 0; i < C; i++){
		if(m >= 0 && n >= 0 && a[n] > b[m] && b[m] < c[i]){
			ans += c[i]-b[m];
			m--;
		}
		else if(n >= 0 && a[n] < c[i]){
			ans += c[i]-a[n];
			n--;
		}
		else break;
	}
	
	cout << ans << endl;
}

int main(){
	std::cin.tie(0);
	std::ios::sync_with_stdio(false);
	int t = 1;
	//cin >> t;
	while(t--){
		solve();
	}
	
	return 0;
}


Measured memory_bytes: 2560
#include<stdio.h>
#define MAX 1000000
int A[MAX+1],n;
void maximumHeap(int);


void maximumHeap(int i){
  int l,r,largest;
  l=2*i;
  r=2*i+1;

  if(l<=n && A[l]>A[i]){
    largest=l;
 
  }
  else{
    largest=i;
  
  }
  if(r<=n && A[r]>A[largest]){
    largest=r;
  
  }
  
  if(largest != i){
 
  int k;
  k=A[i];
  A[i]=A[largest];
  A[largest]=k;
  maximumHeap(largest);
  }
}


int main(){
  
  int i;
  
  scanf("%d",&n);
  
  for(i=1;i<=n;i++){
    scanf("%d",&A[i]);
  }
  
  for(i=n/2;i>=1;i--){
    maximumHeap(i);
  }

  for(i=1;i<=n;i++){
    printf(" %d",A[i]);
  }
  printf("\n");
  return 0;
}

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

int main(){
  while(1){
    int H, W;
    cin>>H>>W;
    if(H == 0 && W == 0)break;

    for(int i=0;i<H;i++){
      for(int j=0;j<W;j++){
	if(i == 0 || i == H - 1 || j == 0 || j ==  W - 1) cout<<"#";
	else cout<<".";
      }
      cout<<endl;
    }

    cout<<endl;
  }

  return 0;
}
  
					


Measured memory_bytes: 3080
#include <iostream>
#include <map>
#include <utility>

using namespace std;

int magic(pair<int,int> p, pair<int,int> q){
  return abs(p.first - q.first) + abs(p.second - q.second);
}

int main(){
  int H, W, D, A, Q, L, R = 0;
  map<int, pair<int,int>> mapping;
  int graph[100000];                //graph[x]はxからx+Dのマスへの移動コストを表す
  cin >> H >> W >> D;
  for(int i = 0; i < H; ++i){
    for(int j = 0; j < W; ++j){
      cin >> A;
      mapping[A] = {i,j};             //マスの値をキーとしてそのマスの座標を保存
    }
  }

  for(int i = 1; i <= D; ++i){
    graph[i] = 0;
    for(int j = i; j <= H * W - D; j += D){
      //x=Dのマスを始点としてx=jまでの移動コストを計算し結果を配列に保存
      graph[j + D] = magic(mapping[j], mapping[j + D]) + graph[j];
    }
  }

  cin >> Q;
  for(int i = 0; i < Q; ++i){
    cin >> L >> R;
    //求める値は x=Dからx=Rまでのコスト - x=Dからx=Lまでのコスト
    cout << graph[R] - graph[L] << endl;
  }

  return 0;
}


Measured memory_bytes: 7168
package main

import (
	"fmt"
	"sort"
)

const MOD = 1000000007

func ModAdd(a, b int64) int64 {
	return (a + b) % MOD
}

func ModMul(a, b int64) int64 {
	return a * b % MOD
}

func ModSub(a, b int64) int64 {
	r := (a%MOD - b%MOD) % MOD
	if r < 0 {
		r += MOD
	}
	return r
}

func ModDiv(a, b int64) int64 {
	return a % MOD * ModInv(b) % MOD
}

func ModPow(a, n int64) int64 {
	var r int64 = 1
	for n > 0 {
		if n&1 == 1 {
			r = r * a % MOD
		}
		a = a * a % MOD
		n >>= 1
	}
	return r
}

func ModInv(a int64) int64 {
	var b, u, v int64 = MOD, 1, 0
	for b > 0 {
		t := a / b
		a -= t * b
		a, b = b, a
		u -= t * v
		u, v = v, u
	}
	u %= MOD
	if u < 0 {
		u += MOD
	}
	return u
}

func main() {
	var N int
	fmt.Scanf("%d\n", &N)

	A := make([]int, N)
	m := map[int]int{}
	for i := 0; i < N; i++ {
		var a int
		fmt.Scan(&a)
		A[i] = a
		m[a] = i + 1
	}
	sort.Ints(A)
	for _, a := range A {
		fmt.Print(m[a], " ")
	}
	fmt.Println()

}


Measured memory_bytes: 9472
import java.io.*
import java.util.*

fun solve(N: Int){
    if (N == 1){ println(2) }
    else if(N % 2 != 0) println(N * 2)
    else println(N)
    return
}


fun main(args: Array<String>) {
    fun StringArray(size: Int, init: (Int) -> String = { "\u0000" }): Array<String> {
        return Array<String>(size, init)
    }
    class Scanner(stream: InputStream) {
        private val reader = BufferedInputStream(stream).bufferedReader()
        private var st: StringTokenizer? = null
        fun next(): String {
            while (!(st?.hasMoreTokens() ?: false)) st = StringTokenizer(reader.readLine())
            return st!!.nextToken()
        }
    }
    val sc = Scanner(System.`in`)
    val N = sc.next().toInt()
    solve(N)
}



Measured memory_bytes: 29600
#include <iostream>
#include <fstream>
#include <algorithm>
#include <vector>
#include <cstring>
//#define LOCAL
using namespace std;
typedef long long ll;
const int mx=1e5+10;
ll a[mx];

void display(ll n, ll num[mx]){
    for(ll i=1;i<=n;i++){
        if(1==i)printf("%lld", num[i]);
        else printf(" %lld", num[i]);
    }
    puts("");
}


int main() {
#ifdef LOCAL
ifstream fin("1.txt");
streambuf*p;
p=cin.rdbuf(fin.rdbuf());
#endif // LOCAL
ll n;
cin>>n;
for(ll i=0;i<n;i++) cin>>a[i];
ll qn;
cin>>qn;
for(ll i=1;i<=qn;i++){
    ll k;
    cin>>k;
    (binary_search(a, a+n, k))?puts("1"):puts("0");
}

#ifdef LOCAL
fin.close();
#endif // LOCAL
}




Measured memory_bytes: 3864
#include <iostream>
#include <vector>
#include <algorithm>
#include <string.h>
#include <iomanip>
#include <math.h>
#include <string>
#include <queue>
#include <map>
#include <set>
#include <functional>

using namespace std;

typedef long long int ll;
typedef std::pair<int, int> pii;
typedef std::pair<ll, int> pli;
typedef std::pair<ll, ll> pll;

#define FOR(i,n,m) for(ll i=(ll)(m);i<(ll)(n);++i)
#define REP(i,n) FOR(i,n,0)
#define IREP(i,n) for(ll i=(ll)(n);i>=0;--i)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

int main()
{
	ll X, Y;
	cin >> X >> Y;
	int ans = 0;
	while (X <= Y)
	{
		ans++;
		X *= 2;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
N = int(input())
S = {}
for n in range(N):
  s = [ss for ss in input()]
  s.sort()
  s_join = "".join(s)
  if s_join not in S.keys():
    S[s_join] = 1
  else: #s_join in S.keys():
    S[s_join] += 1

ans = 0
for k in S.values():
  if k == 1:
    continue
  else:
    ans += sum(range(1, k))

print(ans)

Measured memory_bytes: 17852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define endl "\n"

void solve() {
  int n; cin >> n;
  unordered_map<string, int> mp;
  mp.insert(pair<string, int>("AC", 0));
  mp.insert(pair<string, int>("WA", 0));
  mp.insert(pair<string, int>("TLE", 0));
  mp.insert(pair<string, int>("RE", 0));

  while(n--){
    string str; cin >> str;
    mp[str]++;
  }

  string arr[4] = {"AC", "WA", "TLE", "RE"};
  for(string s: arr){
    cout << s << " x " << mp[s] << endl;
  }
}
int main(){
// #ifndef ONLINE_JUDGE
//    freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
// #endif
  ios::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  int t = 1;
  // cin >> t;
  while (t--) {
    solve();
  }
  return 0;
}

Measured memory_bytes: 3620
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

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;
}

int main(void) {
    string S;
    cin >> S;

    int zero_count = 0;
    int one_count = 0;
    for (int i = 0; i < (int) S.size(); i++) {
        if (S[i] == '0') {
            zero_count++;
        } else {
            one_count++;
        }
    }

    cout << 2 * min(zero_count, one_count) << endl;

    return 0;
}


Measured memory_bytes: 512
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<string>
#include<vector>
using namespace std;
int main()
{
	string s,t;
	cin >> s >> t;
	int sizes=s.size(),sizet=t.size(),count=0,m=0;

	for (int i = 0; i < sizes - sizet + 1; i++)
	{
		for (int j = 0; j < sizet; j++)
		{
			if (t[j] == s[i+j])
			{
				count++;
			}
			if (m < count)
			{
				m = count;
			}
		}
		count = 0;
	}
	cout << sizet - m << endl;
}

Measured memory_bytes: 3632
#include<iostream>
#include<algorithm>
#include<vector>
#include<cmath>
#include<string>
using namespace std;

int main(){

    long unsigned int k;
    cin >> k;

    string s;
    cin >> s;

    if(s.size()>k){
        s.erase(s.begin()+k,s.end());
        cout << s << "..." <<endl;

    }else{
        
        cout << s <<endl; 
        //::system("pause");
    }
    
    // ::system("pause");
    return 0;
}

Measured memory_bytes: 3628
S = input()
N = len(S)
ans = int(S)
for i in range (0,N-2):
  x = 100 * int(S[i]) + 10 * int(S[i+1]) + int(S[i+2])
  d = abs(753 - x)
  ans = min(ans,d)
print(ans)

Measured memory_bytes: 3060
int main() {
  int N, M;
  scanf("%d %d",&N, &M);
  
  if (M % N == 0) {
    printf("%d", M / N);
    return 0;
  }
  
  for (int i = M / N - 1; i > 0; i--) {
    if (M % i != 0) continue;
    printf("%d", i);
    return 0;
  }
  printf("%d", 1);
  return 0;
}

Measured memory_bytes: 128
s = int(input())
a = {s}
idx = 1
while True:
    idx = idx + 1
    if s % 2 == 0:
        s = s / 2
    else:
        s = 3 * s + 1
    if s in a:
        print(idx)
        exit(0)
    else:
        a.add(s)


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

N = int(input())
A = list(map(int, input().split()))
cnt = 0
m = 10**18

for Ai in A:
    if Ai<0:
        cnt += 1
    
    m = min(m, abs(Ai))

if cnt%2==0:
    print(sum(abs(Ai) for Ai in A))
else:
    print(sum(abs(Ai) for Ai in A)-2*m)

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

int main(){
    ll h,w;
    cin>>h>>w;
    ll c[10][10];
    vector<vector<ll>> a(h,vector<ll>(w));
    rep(i,10)rep(j,10) cin>>c[i][j];
    rep(i,h)rep(j,w) cin>>a[i][j];
    rep(k,10){
        rep(i,10){
            rep(j,10){
                c[i][j]=min(c[i][j],c[i][k]+c[k][j]);
            }
        }
    }
    ll ans=0;
    rep(i,h){
        rep(j,w){
            if(a[i][j]!=-1) ans+=c[a[i][j]][1];
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
# -*- encoding: utf-8 -*-
n = int(input().rstrip())
p = list(map(int, input().rstrip().split(' ')))

i, ans = 1, 0
while i <= n:
    if p[i - 1] == i:
        ans += 1
        i += 2
    else:
        i += 1

print(ans)

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

using namespace std;

int main(int argc, const char *argv[]) {
  using ll = long long;
  int n;
  cin >> n;

  vector<ll> va(n);
  for (int i = 0; i < n; ++i) {
    cin >> va[i];
  }

  unordered_map<ll, vector<int>> l_dict, r_dict;
  for (int i = 0; i < va.size(); ++i) {
    int l = i - va[i], r = va[i] + i;
    l_dict[l].push_back(i);
    r_dict[r].push_back(i);
  }

  ll ans = 0;
  for (auto [l, indices] : l_dict) {
    ans += indices.size() * r_dict[l].size();
  }

  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 48108
#!/usr/bin/env python3
n = int(input())
ps = list(map(int,input().split()))
imos = [None] * n
for i, p in enumerate(ps):
    imos[p-1] = i
a = [ 0 ]
b = [ 0 ]
for i in range(n):
    a += [ a[-1] + 1 + imos[i]     ]
    b += [ b[-1] + 1 + imos[n-i-1] ]
print(*a[1:])
print(*reversed(b[1:]))


Measured memory_bytes: 7296
#!/usr/bin/env ruby

require 'set'

class Hash
  def push(key, value)
    self[key] = [] if self[key] == nil
    self[key].push(value)
  end
end

class Array
  def lower_bound(value)
    left = -1;
    right = self.length;
    while left + 1 < right
      mid = left + (right - left) / 2;
      if self[mid] >= value
        right = mid
      else
        left = mid
      end
    end
    right
  end

  def unique
    res = [self.first]
    each_cons(2) do |a, b|
      if a != b
        res.push(b)
      end
    end
    res
  end
end

def get_ints
  gets.chomp.split.map(&:to_i)
end

def get_ints_minus_one
  get_ints.map { |x| x - 1 }
end

def get_int
  gets.chomp.to_i
end

N, K = get_ints
A = get_ints

keta = K.to_s(2).length

ax = A.dup
xx = Array.new(keta) { [] }

i = 0
while i < keta
  ax = ax.map do |a|
    xx[i].push a % 2
    a / 2
  end
  i += 1
end

stock = xx.map { |arr| arr.sum }

value = 0
stock.reverse.each.with_index do |s, i|
  if s <= N/2
    t = value + 2 ** (keta - 1 - i)
    value = t if t <= K
  end
end

ans = 0
A.each do |a|
  ans += a ^ value
end

puts ans


Measured memory_bytes: 74064
#include <stdio.h>

int main(){
  int n,y;
  scanf("%d %d",&n,&y);
  int a = -1;
  int b = -1;
  int c = -1;
  int i,j;
  int x_man,y_thou,z_thou;

  for(i=0;i<=n;i++){
    x_man = i * 10000;
    for(j=0;j<=n;j++){
      y_thou = j * 5000;
      z_thou = (int)(y - x_man - y_thou)/1000;
      if(z_thou >= 0){
        if(i+j+z_thou == n){
          a = i;
          b = j;
          c = z_thou;
          break;
        }
      }
    }
  }
  printf("%d %d %d\n",a,b,c);
  return 0;
}


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

int main() {
	int k,x;
	scanf("%d %d", &k, &x);
	int j = x-k+1;
	if (( j < 1000001) && (j > -1000001)) printf("%d", j);
	for (int i = x-k+2; i < x+k; i++) {
		if ((i < 1000001) && (i > -1000001)) {
			printf(" %d", i);
		}
	}
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
long long n,a[100005],sum=0;
int main()
{
	scanf("%lld",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%lld",&a[i]);
	}
	a[0]=0;
	a[n+1]=0;
	for(int i=1;i<=n+1;i++)
	{
		sum+=(abs(a[i]-a[i-1]));
	}
	for(int i=1;i<=n;i++)
	{
		printf("%lld\n",sum-abs(a[i]-a[i-1])-abs(a[i]-a[i+1])+abs(a[i-1]-a[i+1]));
	}
}

Measured memory_bytes: 4532
import * as fs from "fs";

let input = (fs.readFileSync("/dev/stdin", "utf8") as string).split("\n");
const s = input[0];

const result = (() => {
	let k = Math.floor(s.length / 2);

	let l = k;
	let r = k;

	let tmp = "";
	if (s.length % 2 === 0) {
		l -= 1;
		if (s[l] === s[r]) {
			tmp = s[l];
			k += 1;
		}
		else {
			return k;
		}
	}
	else {
		tmp = s[l];
		k += 1;
	}

	while (l >= 0 && r < s.length) {
		l -= 1;
		r += 1;
		if (tmp !== s[l] || tmp !== s[r]) return k;
		k += 1;
	}
	return k;
})();

console.log(result);


Measured memory_bytes: 7500
#include <iostream>
#include <cstring>
#include <string>    
#include <vector>
#include <queue>
#include <map>
#include <algorithm>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;

const int MAX_V = 100008;
int n, m;

struct dijkstra{//1-origin
	vector<ll> min_dst;
	vector<vector<P>> G;
	dijkstra(int n){
		min_dst.resize(n+1);
		G.resize(n+1);
	}

	void append(int u, int v, ll cost){G[u].push_back(P(v, cost));}
	
	void run(int s){
		priority_queue<P, vector<P>, greater<P>> que;
		fill(min_dst.begin(), min_dst.end(), -1);
		min_dst[s] = 0;
		que.push(P(0, s));
		
		while(!que.empty()){
			P p = que.top(); que.pop();
			int at = p.second;
			if(min_dst[at] < p.first){continue;}
			for(int i = 0; i < G[at].size(); i++){
				int to = G[at][i].first;
				ll cost = G[at][i].second;
				if(min_dst[to] == -1 || min_dst[at]+cost < min_dst[to]){
					min_dst[to] = min_dst[at]+cost;
					que.push(P(min_dst[to], to));
				}
			}
		}	
	}
	
	ll get(int at){return min_dst[at];}
};

int main(){
	int s, t;
	cin >> n >> m >> s >> t;
	
	dijkstra da(n), db(n);
	
	ll u, v, a, b;
	for(ll i = 1; i <= m; i++){
		cin >> u >> v >> a >> b;
		da.append(u, v, a);
		da.append(v, u, a);
		db.append(u, v, b);
		db.append(v, u, b);
	}
	
	da.run(s);
	db.run(t);
	
	ll ans[n];
	ans[n-1] = da.get(n)+db.get(n);
	for(ll i = n-2; i >= 0; i--){
		ans[i] = min(da.get(i+1)+db.get(i+1), ans[i+1]);
	}
	for(ll i = 0; i <= n-1; i++){
		cout << 1000000000000000-ans[i] << endl;
	}
	return 0;
}


Measured memory_bytes: 19068
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <stdio.h>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <tuple>
#include <math.h>
#include <set>
#include <map>
using namespace std ;
using ll = long long ;
using ld = long double ;
using vll = vector<ll> ;
using vvll = vector<vll> ;
using vc = vector<char> ;
using vvc = vector<vc> ;
using vb = vector<bool> ;
using vvb = vector<vb> ;
using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end() 
const ll INF = 1e18 ;
const ll mod = 1e9+7 ;
const double pie = acos(-1); 
vll dx4 = {-1,0,1,0} ;
vll dy4 = {0,-1,0,1} ;
vll dx8 = {-1,0,1,1,1,0,-1,-1} ;
vll dy8 = {-1,-1,-1,0,1,1,1,0} ; 

void fix_cout(){cout << fixed << setprecision(20) ; }
ll gcd(ll a,ll b){if(b==0) return a ; return gcd(b,a%b) ; }
ll lcm(ll a,ll b){return a/gcd(a,b)*b ; }
void chmax(ll &a,ll b){if(a<b) a = b ; }
void chmin(ll &a,ll b){if(a>b) a = b ; }


int main(){
	ll n ; cin >> n ;
	map<ll,ll> m ;
	ll ans = 0 ;
	for(int i=0;i<n;i++){
		ll a ; cin >> a ;
		m[a]++ ;
		ans += a ;
	}
	ll q ; cin >> q ;
	while(q--){
		ll b,c ;
		cin >> b >> c ;
		ans += (c-b)*m[b] ;
		cout << ans << endl ;
		m[c] += m[b] ;
		m[b] = 0 ;
	}
}




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

int main(){
    int a[5], k;
    for(int i = 0; i < 5; i++)
    {
        cin >> a[i];
    }
    cin >> k;
    string ans = "Yay!";
    if(a[4]-a[0]>k) ans=":(";
    cout << ans << endl;

}

Measured memory_bytes: 256
use std::collections::*;
use std::io::*;

fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let mut s = sc.chars();
    s.reverse();
    let mut sub: Vec<i64> = vec![0; s.len() + 1];
    let m: i64 = 2019;
    let mut pow: i64 = 1;
    for i in 0..s.len() {
        sub[i + 1] = (s[i].to_digit(10).unwrap() as i64 * pow + sub[i]) % 2019;
        pow = (pow * 10) % m;
    }
    let mut count: BTreeMap<i64, i64> = BTreeMap::new();
    for e in sub.iter() {
        *count.entry(*e).or_insert(0) += 1;
    }
    let mut ans: i64 = 0;
    for p in count.iter() {
        let num = *p.1;
        ans += num * (num - 1) / 2;
    }
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

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

int main() {
	int A, B, C, D, ans=0;
	cin >> A >> B >> C >> D;
	
	for (int i = A; i <= B; i++) {
		for (int j = C; j <= D; j++) {
			if (i == j) {
				ans++;
			}
		}
	}
	if (ans > 0) {
		ans--;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int main() {
	int h, w, k;
	cin >> h >> w >> k;
	vector<string> s(h);
	inc(i, h) { cin >> s[i]; }
	
	int n = 1, c = 0;
	vector<vector<int>> ans;
	inc(i, h) {
		int f = 0;
		vector<int> v;
		inc(j, w) {
			if(s[i][j] == '#') { f++; if(f >= 2) { n++; } }
			v.PB(n);
		}
		c++;
		if(f > 0) {
			inc(j, c) { ans.PB(v); }
			n++;
			c = 0;
		}
	}
	
	while(SI(ans) < h) { ans.PB(ans.back()); }
	
	inc(i, h) {
	inc(j, w) {
		cout << ans[i][j] << (j == w - 1 ? "\n" : " ");
	}
	}
	
	return 0;
}


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

using ll = long long;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int d;
  cin >> d;
  
  vector<int> c(26);
  for (int i = 0; i < 26; i++) cin >> c.at(i);
  
  vector<vector<ll>> s(d, vector<ll>(26));
  for (int i = 0; i < d; i++) {
    for (int j = 0; j < 26; j++) {
      cin >> s.at(i).at(j);
    }
  }
  
  vector<int> t(d);
  for (int i = 0; i < d; i++) {
    cin >> t.at(i);
    t.at(i)--;
  }
  
  vector<vector<int>> dim(d, vector<int>(26, 1));
  ll suff = 0;
  for (int i = 0; i < d; i++) {
    suff += s.at(i).at(t.at(i));
    if (i > 0) {
      for (int j = 0; j < 26; j++) dim.at(i).at(j) = dim.at(i - 1).at(j) + 1;
    }
    dim.at(i).at(t.at(i)) = 0;
    for (int j = 0; j < 26; j++) {
      suff -= c.at(j) * dim.at(i).at(j);
    }
  }
  
  int m;
  cin >> m;
  
  for (int i = 0; i < m; i++) {
    int dd, q;
    cin >> dd >> q;
    dd--;
    q--;
    ll delta = s.at(dd).at(q) - s.at(dd).at(t.at(dd));
    for (int j = dd; j < d; j++) {
      delta += c.at(q) * dim.at(j).at(q);
      delta += c.at(t.at(dd)) * dim.at(j).at(t.at(dd));
    }
    dim.at(dd).at(t.at(dd)) = 1; // 仮
    dim.at(dd).at(q) = 0;
    for (int j = dd; j < d; j++) {
      if (dim.at(j).at(t.at(dd)) > 0 && j > 0) dim.at(j).at(t.at(dd)) = dim.at(j - 1).at(t.at(dd)) + 1;
      if (dim.at(j).at(q) > 0 && j > 0) dim.at(j).at(q) = dim.at(j - 1).at(q) + 1;
      delta -= c.at(q) * dim.at(j).at(q);
      delta -= c.at(t.at(dd)) * dim.at(j).at(t.at(dd));
    }
    t.at(dd) = q;
    suff += delta;
    cout << suff << '\n';
  }
}

Measured memory_bytes: 3768
#include <iostream>
#include <cstdlib>
using namespace std;
int main(){
    int w,a,b;cin>>w>>a>>b;
    bool c=(a<=b&b<=a+w)||(a<=b+w&b+w<=a+w);
    if(c){
        cout<<0;
        return 0;
    }
    int l1=abs(a+w-b),l2=abs(b+w-a);
    cout<<min(l1,l2);
}

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
from math import floor,ceil,sqrt,factorial,log
from heapq import heappop, heappush, heappushpop
from collections import Counter,defaultdict,deque
from itertools import accumulate,permutations,combinations,product,combinations_with_replacement
from bisect import bisect_left,bisect_right
from copy import deepcopy
from operator import itemgetter
from fractions import gcd
mod = 10 ** 9 + 7
 
#整数input
def ii(): return int(sys.stdin.readline().rstrip()) #int(input())
def mii(): return map(int,sys.stdin.readline().rstrip().split())
def limii(): return list(mii()) #list(map(int,input().split()))
def lin(n:int): return [ii() for _ in range(n)]
def llint(n: int): return [limii() for _ in range(n)]
#文字列input
def ss(): return sys.stdin.readline().rstrip() #input()
def mss(): return sys.stdin.readline().rstrip().split()
def limss(): return list(mss()) #list(input().split())
def lst(n:int): return [ss() for _ in range(n)]
def llstr(n: int): return [limss() for _ in range(n)]

#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
#本当に貪欲法か？ DP法では？？
q,h,c,d=mii()
n=ii()


ll05 = min(2*q,h)
ll1 = min(ll05*2,c)
ll2 = min(ll1*2,d)
ans=10**100
if n%2==1:
    ans = (n//2)*ll2 + ll1
else:
    ans = (n//2)*ll2

print(ans)


Measured memory_bytes: 63468
#include<algorithm>
#include<bitset>
#include<cmath>
#include<cstdlib>
#include<iomanip>
#include<iostream>
#include<queue>
#include<set>
#include<string>
#include<utility>
#include<vector>

using namespace std;
 
typedef long long ll;

#define MP make_pair
#define F first
#define S second

vector<ll> divisor(ll n) { //約数列挙
    vector<ll> ret,ter;
    for (ll i = 1; i * i <= n; i++) {
        if (n % i == 0) {
            ret.push_back(i);
            if (i*i != n && n != 1) ter.push_back(n / i);
        }
    }
    reverse(ter.begin(), ter.end());
    copy(ter.begin(),ter.end(),back_inserter(ret));
    return ret;
}

int main(){
	ll n;
    cin >> n;
    vector<ll> ans;
    for(ll i=1;i<=n;i++){
          if(i%2==0) continue;
    	  vector<ll> tmp = divisor(i);
          if(tmp.size()==8){
          		ans.push_back(i);
          }  
    }
	cout << ans.size() << endl;
}

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

int main(){
	int n = 0;
	int a[n][3];
	int m = a[n][0];
	int f = a[n][1];
	int r = a[n][2];
	while(1){
		cin >> m >> f >> r;
		if(m == -1 && f == -1 && r == -1) break;
		else if (m == -1 || f == -1){
			cout << "F" << endl;
		}else if(m + f >= 80){
			cout << "A" <<endl;
		}else if(m + f < 80 && m + f >= 65){
			cout << "B" << endl;
		}else if(m + f < 65 && m + f >= 50){
			cout << "C" << endl;
		}else if(m + f < 50 && m + f >= 30){
			if(r >= 50){
				cout << "C" << endl;
			}else{
				cout << "D" << endl;
			}
		}else if(m + f < 30){
			cout << "F" << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1152
#include <stdio.h>
#include <stdlib.h>
#define MAX_SIZE 101

int main(void) {

	int array[MAX_SIZE];
	int i = 1;
	int n = 0;
	scanf("%d", &n);

	while (i <= n) {
		int a = 0;
		scanf("%d", &a);
		array[i] = a; 
		i++;
	}
	int j = 1; 
	int total = 0;
	while (j <= n) {
		if (j % 2 != 0) {
			int x = array[j];
			if (x % 2 != 0) {
				total++;
			}
		}
		j++;
	}

	printf("%d", total);
	return 0;
	
}

Measured memory_bytes: 1728
#include <bits/stdc++.h>
using namespace std;
#define fol(i,n) for(int i=0;i<n;i++)
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;
typedef vector<P> vip;

void solve(){
    string n;cin>>n;
    int a[4];
    fol(i,4){
        a[i]=(int)((char)n[i]-'0');
    }
    int buf[3];
    char eq[3]={};
    fol(i,2){
        fol(j,2){
            fol(k,2){
                buf[0]=a[1]*(i%2?1:-1);
                buf[1]=a[2]*(j%2?1:-1);
                buf[2]=a[3]*(k%2?1:-1);
                if (a[0]+buf[0]+buf[1]+buf[2]==7){
                    fol(i,3){
                        eq[i]=buf[i]>0?'+':'-';
                    }
                }
            }
        }
    }
    fol(i,3){
        cout << n[i];
        cout << eq[i];
    }
    cout << n[3]<<"=7"<<endl;

}

int main(){
    solve();
    return 0;
}


Measured memory_bytes: 256
using System;
using System.Linq;

namespace ConsoleApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = int.Parse(Console.ReadLine());
            var A = Console.ReadLine().Split().Select(int.Parse).ToArray();

            var L = new int[N];//i番目まで
            var R = new int[N];//i番目以降

            L[0] = A[0];
            for (int i = 1; i <= N - 2; i++) L[i] = Gcd(L[i - 1], A[i]);

            R[N - 1] = A[N - 1];
            for (int i = N - 2; i >= 1; i--) R[i] = Gcd(R[i + 1], A[i]);

            var ans = new int[N];
            ans[0] = R[1];
            ans[N - 1] = L[N - 2];
            for (int i = 1; i <= N - 2; i++) ans[i] = Gcd(L[i - 1], R[i + 1]);

            Console.WriteLine(ans.Max());
        }

        static int Gcd(int a, int b)
        {
            if (b == 0) return a;
            return Gcd(b, a % b);
        }
    }
}


Measured memory_bytes: 27356
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define inf 1e18
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define pb push_back
#define ff first
#define ss second
#define vll vector<ll>
#define pii pair<ll,ll>
#define sz(v) (v).size()
#define srt(v) sort(v.begin(),v.end())
#define ull unsigned long long
#define tell(a) cout<<a<<" "
#define el cout<<endl;
#define rev(v) reverse(v.begin(),v.end())
#define rep(i,a,n) for(int i=a;i<n;i++)
#define M 1000000007
ll power(ll x, ll y, ll p){ll res = 1;x = x % p;while (y > 0){   if (y & 1)res = (res*x) % p;y = y>>1;
x = (x*x) % p;}return res;}



int main()
{
	IOS;
	int n,m;
	cin>>n>>m;
	ll x=(n+m);
	if(x%2)
	cout<<"IMPOSSIBLE";
	else
	cout<<x/2;
}



Measured memory_bytes: 256
/*
author : seryu
title : CODE FESTIVAL 2017 qual C B_"Similar Arrays"
*/
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(all(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
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; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	int n;
	cin >> n;
	int tot = 1, odd = 1;
	rep(i, n)
	{
		int a;cin >> a;
		tot *= 3;
		if(a % 2 == 0)odd *= 2;
	}
	int ans = tot - odd;
	cout << ans << endl;	
	return;	
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

int main ()
{
	int n,k;
	long double ans=1;
	scanf("%d %d \n",&n,&k);
	ans *= k;
	ans *= powl((long double)(k-1),(long double)(n-1));
	printf("%ld\n",(long int)ans);
	return 0;
}

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String line;
        while( (line = br.readLine()) != null ) {
            String[] tokens = line.split(" ");
            Integer result = Integer.parseInt(tokens[0]) + Integer.parseInt(tokens[1]);
            System.out.println(result.toString().length());
        }
    }
}



Measured memory_bytes: 24156
N, x = map(int, input().split())
A = [int(x) for x in input().split()]
ans = 0
for i in range(N-1):
    if A[i] + A[i + 1] > x:
        diff = A[i] + A[i + 1]-x
        ans += diff
        if A[i + 1] >= diff:
            A[i + 1] -= diff

        else:
            A[i+1] = 0

print(ans)


Measured memory_bytes: 14252
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
int main()
{
    char s1[55][55];
    char s2[55][55];
    int n,m,b,judge,i,j,x,y,judgesum,a;
    while(scanf("%d%d",&n,&m)!=EOF)
    {
        judge=0;
        for(a=0;a<n;a++)
            scanf("%s",s1[a]);
        for(a=0;a<m;a++)
            scanf("%s",s2[a]);
        char p=s2[0][0];
        judgesum=1;
        for(a=0;a<=n-m;a++)
        {
            for(b=0;b<=n-m;b++)
            {
                if(s1[a][b]==p)
                {
                    judge=0;
                    x=0;y=0;
                    for(i=a;i<a+m;i++)
                    {
                        for(j=b;j<b+m;j++)
                         {
                             if(s1[i][j]!=s2[x][y])
                             {
                                 judge=1;
                                 break;
                             }
                             y++;
                         }
                         x++;
                         y=0;
                         if(judge==1)break;
                    }
                    if(judge==0)
                    {
                        judgesum=0;
                    }
                }
                if(judgesum==0)break;
            }
            if(judgesum==0)break;
        }
        if(judgesum==0)printf("Yes\n");
        else printf("No\n");
    }
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using ld = long double;
long double const pi = std::acos(-1.0L);
typedef pair<int,int> P;

int main() {
  string n; cin >> n;
  int num = 0;
  rep(i,n.size()){
    num += (int)(n[i]-'0');
  }
  num %= 9;
  if(num==0)cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3712
#!/usr/bin/env perl

@c1 = split(/\s+/ , <STDIN>);
@c2 = split(/\s+/ , <STDIN>);
@c3 = split(/\s+/ , <STDIN>);

if($c1[0] - $c2[0] == $c1[1] - $c2[1] and 
   $c1[0] - $c2[0] == $c1[2] - $c2[2] and 
   $c2[0] - $c3[0] == $c2[1] - $c3[1] and
   $c2[0] - $c3[0] == $c2[2] - $c3[2] and
   $c1[0] - $c3[0] == $c1[1] - $c3[1] and
   $c1[0] - $c3[0] == $c1[2] - $c3[2]){
    
    print "Yes\n";
}else{
    print "No\n";
}



Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
int main(){
  int n,m;
  cin>>n>>m;
  vector<pair<int,char>> vec;
  for(int i=0;i<m;i++){
    int s;
    char c;
    cin>>s>>c;
    vec.push_back(make_pair(s,c));
  }
  for(int i=0;i<1000;i++){
    string s=to_string(i);
    if(s.size()!=n)continue;
    bool ok=true;
    for(auto x:vec){
      int p=x.first;
      char moji=x.second;
      p--;
      if(s[p]!=moji)ok=false;
      if(n>1 && p==0 && moji=='0'){
        cout<<-1<<endl;
        return 0;
      }
    }
    if(ok){
      cout<<s<<endl;
      return 0;
    }
  }
  cout<<-1<<endl;
  return 0;
}

Measured memory_bytes: 3660
#include <stdio.h>
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#include <atcoder/all>

// g++-10 d.cpp -std=c++17 -I .

using ll = long long int;
const int INF = (1<<30);
const ll INFLL = (1ll<<60);
const ll MOD = (ll)(1e9+7);

#define l_ength size

void mul_mod(ll& a, ll b){
	a *= b;
	a %= MOD;
}

void add_mod(ll& a, ll b){
	a = (a<MOD)?a:(a-MOD);
	b = (b<MOD)?b:(b-MOD);
	a += b;
	a = (a<MOD)?a:(a-MOD);
}

int op(int a, int b){
	return std::max(a,b);
}

int e(void){
	return 0;
}

int main(void){
	int n,k,a,i,ans=0,dp;
	std::cin >> n >> k;
	atcoder::segtree<int, op, e> seg(334334);
	for(i=0; i<n; ++i){
		std::cin >> a;
		dp = seg.prod(std::max(a-k,0),std::min(a+k+1,334334))+1;
		ans = std::max(ans,dp);
		seg.set(a,std::max(seg.get(a),dp));
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 8836
program kadai
	implicit none

	integer  ::  a(2)
    character(len=50)  ::  c
    read(*,*) a
    read(*,*) c

	c(a(2):a(2))=char(ichar(c(a(2):a(2)))+32)

	write(*,'(a)') trim(c)
    stop
    
end program kadai

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define INF 1<<30
#define endl '\n'
#define maxn 100005
#define tc printf("Case %d: ", cs)
#define tcn printf("Case %d:\n", cs);
#define FASTIO ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);
typedef long long ll;
const double PI = acos(-1.0);

#define dbg1(x) cerr << #x << " = " << x << endl;
#define dbg2(x, y) cerr << #x << " = " << x << ", " << #y << " = " << y << endl;
#define dbg3(x, y, z) cerr << #x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;
#define dbg4(w,x, y, z) cerr << #w << " = " << w << ", " <<#x << " = " << x << ", " << #y << " = " << y << ", " << #z << " = " << z << endl;

template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
	return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
	os << "{";
	for (auto it = v.begin(); it != v.end(); ++it) {
		if ( it != v.begin() ) os << ", ";
		os << *it;
	}
	return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
	os << "[";
	for (auto it = v.begin(); it != v.end(); ++it) {
		if ( it != v.begin()) os << ", ";
		os << *it;
	}
	return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
	os << "[";
	for (auto it = v.begin(); it != v.end(); ++it) {
		if ( it != v.begin() ) os << ", ";
		os << it -> first << " = " << it -> second ;
	}
	return os << "]";
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)

clock_t tStart = clock();
#define timeStamp dbg("Execution Time: ", (double)(clock() - tStart)/CLOCKS_PER_SEC)

void faltu () { cerr << endl; }

template <typename T>
void faltu( T a[], int n ) {
	for (int i = 0; i < n; ++i) cerr << a[i] << ' ';
	cerr << endl;
}

template <typename T, typename ... hello>
void faltu( T arg, const hello &... rest) { cerr << arg << ' '; faltu(rest...); }
// Program showing a policy-based data structure.
#include <ext/pb_ds/assoc_container.hpp> // Common file 
#include <ext/pb_ds/tree_policy.hpp>
#include <functional> // for less 
#include <iostream>
using namespace __gnu_pbds;
using namespace std;
// GNU link : https://goo.gl/WVDL6g
typedef tree<int, null_type, less_equal<int>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;

/**___________________________________________________**/
const int nx = 2e5 + 5;
vector<int> graph[nx];
int dist[nx];

void dfs(int u, int p)
{
	for (auto v : graph[u]) {
		if (v == p) continue;
		dist[v] += dist[u];
		dfs(v, u);
	}
}

int main()
{
	FASTIO
	///*
// #ifndef ONLINE_JUDGE
// 	freopen("in.txt", "r", stdin);
// 	freopen("out.txt", "w", stdout);
// 	freopen("error.txt", "w", stderr);
// #endif
//*/
	int n, q;
	cin >> n >> q;
	for (int i = 1; i < n; i++) {
		int u, v;
		cin >> u >> v;
		graph[u].push_back(v);
		graph[v].push_back(u);
	}
	while (q--) {
		int u, x;
		cin >> u >> x;
		dist[u] += x;
	}
	dfs(1, 0);
	for (int i = 1; i <= n; i++)
		cout << dist[i] << ' ';
}

Measured memory_bytes: 23552
#include <bits/stdc++.h>
 
#define pii pair<int, int>
#define endl "\n"
#define int long long
#define F first
#define S second
#define B begin
#define E end
#define RB rbegin
#define RE rend
 
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
 
const int INF = 1e9 + 1;
const double EPS = 1e-10;
const ll P = 1e9 + 7;
const int Q = 47;
 
using namespace std;
 
void hello()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
}
 
void show(vector<int>& arr)
{
    for (auto i : arr)
        cout << i << " ";
    cout << endl;
}
void show(vector<vector<int>>& arr)
{
    for (auto i : arr)
        show(i);
    cout << endl;
}


signed main()
{
    hello();
    
    int a, b, c;
    cin >> a >> b >> c;
    if (a == b && b == c || a != b && b != c && a != c)
        cout << "No" << endl;
    else
        cout << "Yes" << endl;
}

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

int main() {
  int N, X, T;
  cin >> N >> X >> T;

  int count;

  if (N == X) {
    cout << T << endl;
  }

  else if (N % X == 0) {
    cout << (N / X) * T << endl;
  }

  else if (X != 1) {

  count = N / X;

  cout << (count + 1) * T << endl;

  }

  else {
    cout << N * T << endl;
  }
}

Measured memory_bytes: 3556
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<cmath>
#include<cstdlib>
#include<ctime>
using namespace std;
typedef long long ll;
int main() {
	int h, w;
	cin >> h >> w;
	char a[10][10];
	int cnt = 0;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			cin >> a[i][j];
			if (a[i][j] == '#')cnt++;
		}
	}
	if (cnt == h + w - 1)cout << "Possible" << endl;
	else cout << "Impossible" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <limits.h>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
using namespace std;
typedef long long ll;

ll gcd(ll a, ll b) {
    if (a < b) {
        ll tmp = a;
        a = b;  b = tmp;
    }
    ll r = a % b;
    while (r != 0) {
        a = b;  b = r;
        r = a % b;
    }
    return b;
}

int main(void){
    int n, k, a[100010], b[100010];
    cin >> n >> k;
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        if (i != 0) b[i - 1] = a[i] - a[i - 1];
    }
    
    bool zeroes = true;
    for (int i = 0; i < n - 1; i++) {
        if (b[i] != 0) zeroes = false;
    }
    
    if (zeroes) {
        if (a[0] == k) cout << "POSSIBLE" << endl;
        else cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    
    
    if (n == 1) {
        if (a[0] == k) cout << "POSSIBLE" << endl;
        else cout << "IMPOSSIBLE" << endl;
        return 0;
    }
    
    int gd;
    if (n == 2) gd = b[0];
    else gd = gcd(b[0], b[1]);
    
    for (int i = 2; i < n - 1; i++) {
        gd = gcd(gd, b[i]);
    }
    
    for (int i = 0; i < n; i++) {
        if (a[i] - k >= 0 && (a[i] - k) % gd == 0) {
            cout << "POSSIBLE" << endl;
            return 0;
        }
    }
    cout << "IMPOSSIBLE" << endl;
}


Measured memory_bytes: 1024
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
#define max3(a,b,c) max(a,max(b,c))
#define min3(a,b,c) min(a,min(b,c))
#define MOD 1000000007
#define INF (1<<30)
#define LINF (1LL<<60)
#define endl "\n"
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define reprev(i,n) for(int (i)=(n-1);(i)>=0;(i)--)
#define Flag(x) (1<<(x))
#define Flagcount(x) __builtin_popcount(x)
#define pint pair<int,int>
#define pdouble pair<double,double>
#define plint pair<lint,lint>
typedef unsigned long long int ull;
typedef long long lint;

int main(void){
    int A,B;
    cin >> A >> B;
    int dis=B-A;
    int ans=0;
    rep(i,dis) ans+=i+1;
    cout << ans-B << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <unordered_map>
#include <utility>
#include <vector>
using namespace std;
#define ALL(x) (x).begin(), (x).end()
#define OUT(x) cout << (x) << endl
typedef long long ll;

const int MAX = 1e7;
const int MOD = 1e9 + 7;

ll fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(int n, int k) {
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main() {
    ll x, y;
    cin >> x >> y;
    if ((x + y) % 3 != 0) {
        OUT(0);
        return 0;
    }
    ll n = (2 * y - x) / 3, m = (2 * x - y) / 3;
    COMinit();
    OUT(COM(n + m, n));
}


Measured memory_bytes: 234624
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define int long long
#define P pair<long,long>
#define all(a) a.begin(),a.end()
using namespace std;
signed main(){
    string s; cin>>s;
    int cnt1=0,cnt2=0,cnt3=0;
    rep(i,s.size()){
        if(s.at(i)=='B'){
            cnt1+=i;
            cnt2++;
        }
    }
    rep(i,cnt2){
        cnt3+=s.size()-i-1;
    }
    cout<<cnt3-cnt1<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define INF 1000000000000000LL
using namespace std;
typedef long long ll;
ll adj[305][305], dp[305][305], dp2[305][305];
int n;
int main(){
	scanf("%d", &n);
	for(int i=0; i<n; i++){
		for(int j=0; j<n; j++){
			scanf("%lld", &adj[i][j]);
			dp[i][j]=adj[i][j];
			dp2[i][j]=INF;
		}
	}
	ll len;
	for(int k=0; k<n; k++){
		for(int i=0; i<n; i++){
			for(int j=0; j<n; j++){
				len=dp[i][k]+dp[k][j];
				if(k!=i && k!=j){
					if(len<dp[i][j]){
						dp2[i][j]=dp[i][j];
						dp[i][j]=len;
					}
					else if(len<dp2[i][j]){
						dp2[i][j]=len;
					}
				}
			}
		}
	}
	bool fg=true;
	ll res=0;
	for(int i=0; i<n; i++){
		for(int j=i+1; j<n; j++){
			if(dp[i][j]<adj[i][j]) fg=false;
			if(dp2[i][j]>dp[i][j]) res+=dp[i][j];
		}
	}
	if(!fg) printf("-1\n");
	else printf("%lld\n", res);
	return 0;
}


Measured memory_bytes: 2432
L = 10
table = [[[0, 0], [0, 1], [-1, 1], [1, 1], [0, 2], [-1, 2], [-2, 2], [1, 2],
  [2, 2], [0, 3], [-1, 3], [1, 3], [0, 4]],
  [[0, 0], [1, 0], [2, 0], [0, 1], [1, 1], [2, 1], [0, 2], [1, 2], [2, 2]],
  [[0, 0], [0, 1], [-1, 1], [1, 1], [0, 2]]]

n = $<.gets.to_i
cloth = $<.readlines.map {|l| l.split.map(&:to_i)}

copy = ->(ary) { ary.map {|l| l.dup} }
form = ->(x, y, i) {
  case (j = 3 - i)
  when 1 then "#{x} #{y + 1} #{j}"
  when 2 then "#{x + 1} #{y + 1} #{j}"
  when 3 then "#{x} #{y + 2} #{j}"
  else nil
  end
}

try = ->(place, field, co, order = []) {
  x = y = nil
  loop do
    return false if place >= L * L
    x, y = place % L, place / L
    break if field[y][x].nonzero?
    place += 1
  end
  
  result = false
  table.each_with_index do |pat, i|
    tmp = copy.(field)
    catch(:jump) do
      pat.each do |po|
        x1, y1 = x + po[0], y + po[1]
        throw(:jump) if x1 < 0 or x1 >= L or y1 >= L or tmp[y1][x1].zero?
        tmp[y1][x1] -= 1
      end
      co -= 1
      prc = form.(x, y, i)
      if co.zero?
        if tmp.flatten.map(&:zero?).all?
          return order + [prc]
        else
          co += 1
          throw(:jump)
        end
      end
      result = try.(place, tmp, co, order + [prc])
      return result if result
      co += 1
    end
  end
  result
}
puts try.(0, cloth, n)


Measured memory_bytes: 8976
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <utility>
#include <tuple>
#include <cctype>
using namespace std;
#define INF 0x3f3f3f3f
#define INFLL 0x3f3f3f3f3f3f3f3fLL
#define MOD 1000000007
#define mp make_pair
#define mt make_tuple
#define pb push_back
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pint;
typedef pair<ll,ll> pll;
typedef tuple<int,int,int> tint;
typedef vector<int> vint;
typedef vector<ll> vll;
int dx[8]={0,0,-1,1,1,1,-1,-1};
int dy[8]={-1,1,0,0,1,-1,1,-1};
const int SIZE=100050;
//ここまでテンプレ
int main(){
	int N;
	cin>>N;
	ll ans=0;
	ll sum=0;
	for(int i=0;i<N;i++){
		int A;
		cin>>A;
		sum+=A;
		if(A==0){
			ans+=sum/2;
			sum=0;
		}
	}
	ans+=sum/2;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256