akhauriyash/Code-Regression huggingface dataset:
while (n,m=gets.split.map(&:to_i))!=[0,0]
  r=gets.to_i

  time=(1..r).map{gets.split.map(&:to_i)}.sort

  gets.to_i.times{
    ts,te,tm=gets.split.map(&:to_i)
    tmptime = (time.dup + [[ts,nil,tm,2],[te,nil,tm,3]]).sort_by{|a,|a}
    use = 0 # 利用PC数
    sum = 0
    pre_t = 0
    measure = false
    tmptime.each{|t,n,m,s|
      if m == tm
        case s
        when 0 # ログアウト
          use -= 1
          if measure && use==0
            sum += t - pre_t
          end
        when 1 # ログイン
          if use == 0
            pre_t = t
          end
          use += 1
        when 2 # 計測開始
          pre_t = t
          measure = true
        when 3 # 計測終了
          if use > 0
            sum += t - pre_t
          end
          measure = false
        end
      end
    }
    p sum
  }
end


Measured memory_bytes: 8344
require 'matrix'
require 'bigdecimal'
require 'bigdecimal/util'
require 'bigdecimal/ludcmp'
include LUSolve

def len3d(x, y)
  l2=0.0
  0.upto(3-1){|i|
    l2 += (x[i] - y[i])**2
  }
  return Math.sqrt(l2)
end

def heron(a,b,c)
  s = (a + b + c) / 2.0
  return  Math.sqrt(s*(s-a).abs*(s-b).abs*(s-c).abs)
end

Eps=1e-9
def solve(a,b,c,d,e)   # returns true if beam hits barrier.
  # a, b, c: ????????¢???????§???¢??????????????????????????????
  # d:???????????????????????????
  # e:???????????????????????????
  # a + s*u + t*v = d + x*w ????§£??????(0<x<1) ???P(d+xw)???????§???¢ABC????????¨???????????°??????????????????????????????
  # ??????????????????true?????§???????????°false????????????
  u = c - a
  v = b - a
  w = e - d
  m = Matrix.columns([u, v, -w])

#  abort("Impssible case") if m.determinant.abs <=Eps
  return false if m.determinant.abs <Eps
  parms = m.inv * (d - a)
  #parms = m.lup.solve(d - a)

  s = parms[0]
  t = parms[1]
  x = parms[2]
# ???P???????§???¢ABC??????????????¢??¨??´???DE??¨?????????
  return false if x < 0 or x > 1.0
#return true if x.abs<Eps
  p = d + x*w
# ????§???¢ PAC, PAB, PBC?????¢???????????¨????§???¢ABC?????¢????????????????????°???P???ABC???????????????
  pa = len3d(a, p)
  pb = len3d(b, p)
  pc = len3d(c, p)

  ab = len3d(b, a)
  ac = len3d(c, a)
  bc = len3d(c, b)

  s0=heron(ab,ac,bc)
  s1=heron(pa,pc,ac)
  s2=heron(pa,pb,ab)
  s3=heron(pb,pc,bc)

  return  (s1+s2+s3-s0).abs <Eps
end

def main
  if true then
#  if false then
    fh=STDIN
  else
    #fh=open("in1_0115a.txt")
    #fh=open("in1_0115b.txt")
    fh=open("in1_0115c.txt")
  end
  d1,d2,d3=fh.gets.chomp.split.map{|x| x.to_i}
  e1,e2,e3=fh.gets.chomp.split.map{|x| x.to_i}

  a1,a2,a3=fh.gets.chomp.split.map{|x| x.to_i}
  b1,b2,b3=fh.gets.chomp.split.map{|x| x.to_i}
  c1,c2,c3=fh.gets.chomp.split.map{|x| x.to_i}

  d=Vector[d1,d2,d3]
  e=Vector[e1,e2,e3]
  a=Vector[a1,a2,a3]
  b=Vector[b1,b2,b3]
  c=Vector[c1,c2,c3]

  if solve(a,b,c,d,e) then
    puts "MISS"
  else
    puts "HIT"
  end

end

if $0 == __FILE__ then
  main
end

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

int main() {
    long long X;
    cin >> X;
    long long upper = 50000;
    long long lower = 0;
    while (lower + 1 < upper){
        long long mid = (upper + lower) / 2;
        if (mid * (mid + 1) / 2 >= X){
            upper = mid;
        }else{
            lower = mid;
        }
    }
    cout << upper;
    return 0;
}

Measured memory_bytes: 256
try:
    from fractions import gcd
except:
    from math import gcd
from itertools import accumulate
N=int(input())
A=[int(i) for i in input().split()]
l=[0]+list(accumulate(A,gcd))
g=list(reversed(list(accumulate(reversed(A),gcd))))+[0]

print(max([gcd(l[i-1],g[i]) for i in range(1,N+1)]))

Measured memory_bytes: 16152
use proconio::{fastout, input};
// use proconio::marker::*;

#[fastout]
fn main() {
   input! {
      k: usize,
      s: String,
   }

   if k >= s.len() {
      println!("{}", s);
   } else {
      for (i, c) in s.chars().enumerate() {
         if i == k {
            break;
         }
         print!("{}", c);
      }
      println!("...");
   }
}


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

#define int long long

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

int N;

signed main() {
    cin >> N;
    if (N == 3) {
        cout << "2 5 63" << endl;
        return 0;
    }
    if (N == 4) {
        cout << "2 3 4 9" << endl;
        return 0;
    }
    if (N == 5) {
        cout << "2 3 4 9 12" << endl;
        return 0;
    }
    int sum = 0;
    vector<int> ans;
    for (int i = 1; ans.size() < N; i++) {
        if ((i % 2 == 0 || i % 3 == 0)) {
            ans.push_back(i);
            sum += i;
        }
    }
    if (N == 19997) {
        ans[19996] = 29997;
    } else {
        switch (sum % 6) {
            case 1:
                replace(ans.begin(), ans.end(), 9, 30000);
                replace(ans.begin(), ans.end(), 10, 29994);
                break;
            case 2:
                replace(ans.begin(), ans.end(), 8, 30000);
                break;
            case 3:
                replace(ans.begin(), ans.end(), 9, 30000);
                break;
            case 4:
                replace(ans.begin(), ans.end(), 10, 30000);
                break;
            case 5:
                replace(ans.begin(), ans.end(), 8, 30000);
                replace(ans.begin(), ans.end(), 9, 29994);
                break;
        }
    }
    for (int i = 0; i < N; i++) {
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

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

typedef pair <int, int> PII;
typedef map <int, PII>  MIP;
int inf = 1<<24;

int main( void )
{
    int n, ni, di;
    while ( cin >> n && n )
    {
        MIP M;
        M[0] = PII( 0, 0 );
        for ( int i = 0; i < n - 1; i++ )
        {
            cin >> ni >> di;
            PII p = M[ni];
            if ( di == 0 ) p.first--;
            if ( di == 1 ) p.second++;
            if ( di == 2 ) p.first++;
            if ( di == 3 ) p.second--;
            M[i+1] = p;
        }

        int minw = inf, maxw = -inf, minh = inf, maxh = -inf;
        for ( int i = 0; i <= n; i++ )
        {
            minw = min( minw, M[i].first );
            maxw = max( maxw, M[i].first );
            minh = min( minh, M[i].second );
            maxh = max( maxh, M[i].second );
        }

        int w = maxw - minw + 1, h = maxh - minh + 1;
        cout << w << " " << h << endl;
    }

    return 0;
}

Measured memory_bytes: 0
import { stringLiteral } from "@babel/types"

// general helpers
const debug = (message?: any, ...optionalParams: any[]) => {
  if (process.env.LOCAL_DEBUG === '1') console.log(message, ...optionalParams)
}

// helpers
const parseLines = (
  lines: string[]
): { S: string } => {
  const S = lines[0]
  const obj = { S }
  debug(obj)
  return obj
}
// solver
export const solve = (lines: string[]): string => {
  const { S } = parseLines(lines)
  const str = S.split('')
  let current = str[0]
  for (let i = 1; i < S.length; i++) {
    if (current === str[i]) {
      return 'Bad'
    }
    current = str[i]
  }
  return 'Good'
}

// main
const main = (lines: string[]) => {
  console.log(solve(lines))
}

// exec main function for submit
if (process.env.LOCAL_DEBUG !== '1') {
  const { stdin: input, stdout: output } = process
  input.resume()
  input.setEncoding('utf8')
  const lines: string[] = []
  require('readline')
    .createInterface({ input, output })
    .on('line', (line: string) => lines.push(line))
    .on('close', () => main(lines))
}


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

typedef long long ll;
typedef pair<int, int> pii;
typedef unsigned long long ull;
typedef long double ld;

bool ok(int n, vector<string> g, vector<string> cls) {
	vector<bitset<14>> inDeg(n), outDeg(n);

	for (int i = 1; i < n; i++) {
		if (cls[i].size() != i) {
			return false;
		}
		for (int j = 0; j < i; j++) {
			if (g[i][j] == '1') {
				outDeg[i][cls[i][j] - 'a'] = true;
				inDeg[j][cls[i][j] - 'a'] = true;
			} else {
				outDeg[j][cls[i][j] - 'a'] = true;
				inDeg[i][cls[i][j] - 'a'] = true;
			}
		}
	}

	bool ok = true;

	for (int i = 0; i < n && ok; i++) {
		for (int j = 0; j < 14; j++) {
			if (outDeg[i][j] && inDeg[i][j]) {
				ok = false;
				break;
			}
		}
	}

	return ok;
}

bool solvable(int n, const vector<string> &g) {
	mt19937 gen(chrono::high_resolution_clock::now().time_since_epoch().count());
	int iter = 50000;

	while (iter--) {
		vector<string> cls(n);
		uniform_int_distribution<char> uid('a', 'n');
		vector<bitset<14>> inDeg(n), outDeg(n);

		for (int i = 1; i < n; i++) {
			for (int j = 0; j < i; j++) {
				cls[i] += uid(gen);

				if (g[i][j] == '1') {
					outDeg[i][cls[i][j] - 'a'] = true;
					inDeg[j][cls[i][j] - 'a'] = true;
				} else {
					outDeg[j][cls[i][j] - 'a'] = true;
					inDeg[i][cls[i][j] - 'a'] = true;
				}
			}
		}

		bool ok = true;

		for (int i = 0; i < n && ok; i++) {
			for (int j = 0; j < 14; j++) {
				if (outDeg[i][j] && inDeg[i][j]) {
					ok = false;
					break;
				}
			}
		}

		if (ok) {
			return true;
		}
	}

	return false;
}

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

#ifdef LOCAL
	freopen("in.txt", "r", stdin);
	freopen("out.txt", "w", stdout);
	auto START = chrono::steady_clock::now();
#endif

	int a, b, c, d;
	cin >> a >> b >> c >> d;

	while (a > 0 && c > 0) {
		c = max(0, c - b);

		if (c > 0) {
			a = max(0, a - d);
		}
	}

	if (a > 0) {
		cout << "Yes";
	} else {
		cout << "No";
	}

#ifdef LOCAL
	cerr << "Working time: " << chrono::duration_cast<chrono::milliseconds>(chrono::steady_clock::now() - START).count()
			 << " ms.";
#endif

	return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(s,i, n) for (int i = (int)s; i < (int)(n); i++)
#define pb push_back
typedef long long ll;
  
int main(){
    int x,a;
    cin>>x>>a;
    int ans=(x<a)?0:10;
    cout<<ans<<endl;
    return 0;
}

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

int main(int argc, char const *argv[])
{
	int n, m; cin >> n >> m;
	vector<int> a(n), b(n);
	rep(i, n) cin >> a[i] >> b[i];

	vector<pair<int, int>> v(n); // day, money
	rep(i, n) {
		v[i] = make_pair(a[i], b[i]);
	}
	sort(v.begin(), v.end());

	int idx = 0, ans = 0;
	priority_queue<pair<int, int>> que; // money, day
	rep(i, m) {
		while (v[idx].first <= i + 1) {
			que.push(make_pair(v[idx].second, v[idx].first));
			idx++;
		}
		if (not que.empty()) {
			ans += que.top().first;
			que.pop();
		}
	}
	cout << ans << endl;
	return 0;
}


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

const string YES = "YES";
const string NO = "NO";

void solve(long long r, long long g, long long b){
    if ((r * 100 + g * 10 + b) % 4) cout << NO << '\n';
    else cout << YES << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    long long r;
    scanf("%lld",&r);
    long long g;
    scanf("%lld",&g);
    long long b;
    scanf("%lld",&b);
    solve(r, g, b);
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main()
{
int a[30];
for(int i=0;i<30;i++)a[i]=0;
int n;
for(int i=0;i<28;i++){
cin >> n;
a[n-1]++;
}
for(int i=0;i<30;i++){
if(a[i]==0){
cout << i+1 << "\n";
}
}
return 0;
}

Measured memory_bytes: 1160
#include <vector>
#include <iostream>
#include <algorithm>
using namespace std;
int n, m;
int main() {
	ios::sync_with_stdio(false);
	cin >> n >> m;
	vector<int> a(n), l(n - 1), r(n - 1);
	for (int i = 0; i < n; i++) cin >> a[i], a[i]--;
	for (int i = 0; i < n - 1; i++) {
		l[i] = a[i] + 2; r[i] = a[i + 1] + 1;
		if (l[i] >= m) l[i] -= m, r[i] -= m;
		if (l[i] > r[i]) r[i] += m;
	}
	vector<long long> imos(2 * m + 1), imos2(2 * m + 1);
	for (int i = 0; i < n - 1; i++) {
		imos[l[i]]++; imos[r[i]]--; imos2[r[i]] -= r[i] - l[i];
	}
	imos2[0] = imos[0];
	for (int i = 1; i <= 2 * m; i++) imos[i] += imos[i - 1];
	for (int i = 1; i <= 2 * m; i++) imos2[i] += imos2[i - 1] + imos[i];
	for (int i = m; i <= 2 * m; i++) imos2[i % m] += imos2[i];
	long long ret = -(*max_element(imos2.begin(), imos2.begin() + m));
	for (int i = 1; i < n; i++) {
		ret += a[i] - a[i - 1];
		if (a[i] < a[i - 1]) ret += m;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 4608
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<iostream>
#include<cstring>

using namespace std;

int main(void){
	int x,y,s;
	while(1){
		int res=0;
		scanf("%d %d %d",&x,&y,&s);
		if(x+y+s==0)break;
		for(int i=1;i<s;i++){
			for(int j=1;j<s;j++){
				if(i*(100+x)/100+j*(100+x)/100!=s)continue;
				res=max(res,i*(100+y)/100+j*(100+y)/100);
			}
		}
		printf("%d\n",res);
	}
	return 0;
}

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

int main()
{
    long long int n,m,i;
    cin>>n>>m;
    vector<pair<long long int,long long int> > v;
    for(i=0;i<n;i++)
    {
        long long int a,b;
        cin>>a>>b;
        v.push_back({b,a});
    }

    sort(v.rbegin(),v.rend());
    long long int ans=0;
    set<long long int> s;
    for(i=1;i<=m;i++)
    {
        s.insert(i);
    }
    set<long long int>::iterator it;
    for(i=0;i<n;i++)
    {
        it=s.lower_bound(v[i].second);
        if(it!=s.end())
        {
            ans+=v[i].first;
            s.erase(it);
        }
    }

    cout<<ans;

}


Measured memory_bytes: 6512
from decimal import Decimal, ROUND_HALF_UP

n = int(input())
habit = list(map(int, input().split(" ")))

x = Decimal(str(sum(habit)/n)).quantize(Decimal('0'), rounding=ROUND_HALF_UP)

total = 0
for i in habit:
    total += (i - x) ** 2
print(total)

Measured memory_bytes: 5204
#include<stdio.h>
int main(){
int a,b;
scanf("%d %d",&a,&b);
if(a < b){
printf("a < b\n",a,b);
}
else if(a > b){
printf("a > b\n",a,b);
}
else{
printf("a == b\n");
}
return 0;
}

Measured memory_bytes: 2684
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <cmath>
#include <ctime>
#include <vector>
#include <cstdio>
#include <string>
#include <iomanip>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <deque>
using namespace std;
long long  a[200005];
bool cmp(int a, int b)
{
    return a > b;
}
int main(void)
{
    int n;
    cin >> n;
    long long sum = 0;
    for (int i = 0; i < n; ++i)
    {
        scanf("%lld", &a[i]);
    }
    sort(a, a + n, cmp);
    sum = a[0];
    for (int i = 1; i < n / 2; ++i)
    {
        sum += 2 * a[i];
    }
    if (n & 1)
        sum += a[n / 2];
    printf("%lld\n", sum);
}

Measured memory_bytes: 5332
#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " << 
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;
  
  
signed main(){
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout.precision(20);
  
  int a,b;
  cin >> a >> b;
  int t = 1;
  int n = 0;
  while(t < b){
    t += a;
    t--;
    n++;
  }
  
  cout << n << endl;
  
  return 0;
}

Measured memory_bytes: 256
def serch(x,y,p):
    if x<0 or W<=y or y<0 or H<=x or meiro[x][y] =="#":
        return
    if memo[x][y]:
        p = [x,y]
        return
    memo[x][y] = 1
    kyo[x][y] = kyo[p[0]][p[1]] + 1
    p = [x,y]
    serch(x+1,y,p)
    serch(x-1,y,p)
    serch(x,y+1,p)
    serch(x,y-1,p)
H,W = list(map(int,input().split()))
sx,sy = 0,0
gx,gy = H-1,W-1
meiro = [list(input()) for l in range(H)]
counter = 0
for a in range(H):
    for b in range(W):
        n = 1 if meiro[a][b] =="." else 0
        counter += n
dx = [1,0,-1,0]
dy = [0,1,0,-1]
stk = [(sx,sy)]

memo =[[0 for i in range(W)] for l in range(H)]
memo[sx][sy]=1
dis =[[0 for i in range(W)] for l in range(H)]
while stk:
    x,y = stk.pop(0)
    for i in range(4):
        xx,yy = x+dx[i],y+dy[i]
        if xx<0 or W<=yy or yy<0 or H<=xx or meiro[xx][yy] =="#" or memo[xx][yy]==True:
            continue
        dis[xx][yy] = dis[x][y]+1
        stk.append((xx,yy))
        memo[xx][yy] = 1
if dis[gx][gy]==0:
    print(-1)
else:
    print(counter-dis[gx][gy]-1)

Measured memory_bytes: 3192
package main

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

func NewLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	line := NewLine(sc)

	words := strings.Fields(line)
	num1, _ := strconv.Atoi(words[0])
	num2, _ := strconv.Atoi(words[1])
	fmt.Printf("%d\n", num1+num2/2)
}


Measured memory_bytes: 640
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>

    #define INF 1e7
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))

    using namespace std;

    int main(){
      int n;
      cin>>n;
      int sum = 0;
      rep(i,n){
        int a;
        cin>>a;
        a--;
        sum +=a;
      }
      cout<<sum;
    }


Measured memory_bytes: 256
#include<iostream>
#include<math.h>
using namespace std;
int main(){
   	int n;
    long double d;
    cin>>n>>d;
    int cnt=0;
    for(int i=0;i<n;i++){
      	long double x,y;
        cin>>x>>y;
        long double chk=sqrt(x*x+y*y);
        if(chk<=d)cnt++;
    }
    cout<<cnt<<endl;
}

Measured memory_bytes: 3804
#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 itrfor(itr,A) for(auto itr = A.begin(); itr !=A.end();itr++)
typedef long long llong;
char moji[26]={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
char moji2[26]={'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
char moji3[10]={'0','1','2','3','4','5','6','7','8','9'};
#define Sort(a) sort(a.begin(),a.end());
#define Reverse(a) reverse(a.begin(),a.end());
#define print(a) cout << a << endl;



int n,k;
set<int> D;

bool judge(int x){
    while(x>0){
        if(D.find(x%10) !=D.end()){
            return false;
        }
        x/=10;
    }
    return true;
}




int main(){
    cin >> n >> k;
    int tmp;
    REP(i,k){
        cin >> tmp;
        D.insert(tmp);
    };
    int ans = n;
    while(1){
        if( judge(ans)){
            cout << ans << endl;
            return 0;
        }
        ans+=1;
    }
}

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

int selectionSort(int A[], const int N)
{
    int cnt = 0;

    for( int i = 0; i < N; ++i ){
        int min = i;

	//iより後でA[i]より最も小さい値の添字を求める
        for( int j = i; j < N; ++j )
            if( A[j] < A[min] )
                min = j;

	//iとminが異なれば交換
        if( i != min ){
	   swap(A[i], A[min]);
	   ++cnt;
	}
    }

    return cnt;
}

int main()
{
    int N;
    scanf("%d", &N);
    int A[N];
    for( int i = 0; i < N; ++i )
        scanf("%d", &A[i]);

    int cnt = selectionSort(A, N);

    for( int i = 0; i < N; ++i ){
        if( i ) printf(" ");
        printf("%d", A[i]);
    }
    printf("\n%d\n", cnt);

    return 0;
}

Measured memory_bytes: 1192
n = int(input())
AL = list(map(int, input().split()))
BL = list(map(int, input().split()))
ans = 0
for i in range(n):
    if BL[i] <= AL[i]:
        ans += BL[i]
    elif BL[i] > AL[i] and BL[i] <= AL[i]+AL[i+1]:
        ans += BL[i]
        AL[i+1] = AL[i+1] - BL[i] + AL[i]
    else:
        ans += AL[i]+AL[i+1]
        AL[i+1] = 0
print(ans)

Measured memory_bytes: 19156
#include <vector>
#include <sstream>
#include <algorithm>
#include <fstream>
#include <list>
#include <map>
#include <istream>
#include <bitset>
#include <sstream>
#include <unordered_map>
#include <stack>
#include <set>
#include <cmath>
#include <random>
#include <iostream>
#include <bitset>
#include <iomanip>
#include <queue>
#include <string>

#define int long long
#define endl "\n"
#define all(x) x.begin(),x.end()
#define rr return 0
#define xx first
#define yy second
#define pii pair<int,int>

using namespace std;

typedef long long ll;
typedef long double ld;

signed main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int k, x;
    cin >> k >> x;
    for(int i = x - k + 1;i < x + k;i++){
        cout << i << " ";
    }
    rr;
}


Measured memory_bytes: 256
#include <stdio.h>

void right_triangle(int a, int b, int c);

int main(void)
{
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        int a, b, c;
        scanf("%d %d %d", &a, &b, &c);
        right_triangle(a, b, c);
    }
    return 0;
}

void right_triangle(int a, int b, int c)
{
    int x, y, z;
    if (a <= b) {
        if (b <= c) {
            x = a;
            y = b;
            z = c;
        } else {
            x = a;
            y = c;
            z = b;
        }
    } else {
        if (a <= c) {
            x = a;
            y = b;
            z = c;
        } else {
            x = b;
            y = c;
            z = a;
        }
    }
    //ここまででzに最大値を持ってきた
    if (x * x + y * y == z * z) {
    printf("YES\n");
    } else {
    printf("NO\n");
    }
}

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

const int INF = 1001001001;
const int di[4] = {-1, 0, 1, 0};
const int dj[4] = {0, -1, 0, 1};

int main()
{
    int h, w;
    cin >> h >> w;
    vector<string> s(h);
    rep(i, h) cin >> s[i];
    int ans = 0;
    rep(si,h)rep(sj,w){
        if(s[si][sj] == '#') continue;
        vector<vector<int>> dist(h, vector<int>(w, INF));
        queue<P> q;
        auto update = [&](int i, int j, int x){
            if(dist[i][j] != INF) return;
            dist[i][j] = x;
            q.push(P(i,j));
        };
        update(si, sj, 0);
        while(!q.empty()){
            int i = q.front().first;
            int j = q.front().second;
            q.pop();
            rep(dir, 4){
                int ni = i + di[dir], nj = j + dj[dir];
                if(ni<0||ni>=h||nj<0||nj>=w||s[ni][nj]=='#') continue;
                update(ni, nj, dist[i][j] + 1);
            }
        }
        rep(i,h)rep(j,w){
            if(dist[i][j] == INF) continue;
            ans = max(ans, dist[i][j]);
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2")
#include<stdio.h>
#include<algorithm>
#include<math.h>
#include<vector>
#include<set>
#include<unordered_map>
#include<assert.h>
#include<time.h>
#include<stdlib.h>
#include<random>
#include<queue>
using namespace std;
using lld = long long int;
using pll = pair<lld, lld>;
using lf = double;
using pff = pair<lf, lf>;
using pif = pair<int, lf>;
using pii = pair<int, int>;
using pli = pair<lld, int>;
using pil = pair<int, lld>;
using piii = pair<int, pii>;
#define M 1000000007
int n;
int a[200009];
int s[200009];
int b[200009];
pii c[200009];
int r[200009];
#define I 262144
struct A {
	int m1;
	int m2;
	int i1;
	int i2;
	int type;
	A() {
		m2 = m1 = i2 = i1 = I;
		type = 0;
	}
	A operator +(const A& p) {
		A res;
		res.m1 = m1;
		res.m2 = m2;
		res.i1 = i1;
		res.i2 = i2;
		if (res.m2 > p.m1) {
			res.m2 = p.m1;
			res.i2 = p.i1;
			if (res.m1 > res.m2) {
				swap(res.m1, res.m2);
				swap(res.i1, res.i2);
			}
		}
		if (res.m2 > p.m2) {
			res.m2 = p.m2;
			res.i2 = p.i2;
		}
		return res;
	}
};
A ma[2 * I];
A mb[2 * I];
void updatema(int i) {
	i += I;
	if (a[i - I] > 0) {
		ma[i].m1 = n - a[i - I] - b[i - I];
		ma[i].i1 = i - I;
	}
	else {
		ma[i] = A();
	}
	if (b[i - I] > 0) {
		mb[i].m1 = n - a[i - I] - b[i - I];
		mb[i].i1 = i - I;
	}
	else {
		mb[i] = A();
	}
	i >>= 1;
	while (i > 0) {
		ma[i] = ma[i * 2] + ma[i * 2 + 1];
		mb[i] = mb[i * 2] + mb[i * 2 + 1];
		i >>= 1;
	}
}
int main() {
	int i, j, k, l;
	int t = 1, tv = 0;
	//scanf("%d", &t);
	while (t--) {
		scanf("%d", &n);
		for (i = 0; i < n; i++) {
			scanf("%d", &j);
			a[j - 1]++;
		}
		for (i = 0; i < n; i++) {
			s[i + 1] = s[i] + a[i];
		}
		for (i = 0; i < n; i++) {
			scanf("%d", &j);
			b[j - 1]++;
		}
		bool valid = true;
		for (i = 0; i < n; i++) {
			if (a[i] > n - b[i])
			{
				valid = false;
				break;
			}
		}
		if (!valid) {
			printf("No\n");
		}
		else {
			printf("Yes\n");
			for (i = 0; i < n; i++) {
				if (a[i] > 0) {
					ma[i + I].m1 = n - a[i] - b[i];
					ma[i + I].i1 = i;
				}
				else {
					ma[i + I] = A();
				}
				if (b[i] > 0) {
					mb[i + I].m1 = n - a[i] - b[i];
					mb[i + I].i1 = i;
				}
				else {
					mb[i + I] = A();
				}
			}
			for (; i < I; i++) {
				ma[i + I] = A();
				mb[i + I] = A();
			}
			for (i = I - 1; i > 0; i--) {
				ma[i] = ma[i * 2] + ma[i * 2 + 1];
				mb[i] = mb[i * 2] + mb[i * 2 + 1];
			}
			int ccnt = n;
			queue<int> que;
			while (ccnt--) {
				int mi = ma[1].i1;
				int ei = mb[1].i1;
				if (mi == ei) {
					ei = mb[1].i2;
				}
				//printf("%d %d  %d %d  %d %d\n", mi, ei, a[mi], b[mi], a[ei], b[ei]);
				r[s[mi]++] = ei;
				a[mi]--;
				b[ei]--;
				updatema(mi);
				updatema(ei);
			}
			for (i = 0; i < n; i++) {
				printf("%d ", r[i] + 1);
			}
			printf("\n");
		}
	}
	return 0;
}

Measured memory_bytes: 26772
#include <bits/stdc++.h>
using namespace std;
long long int a,b,c;
vector<long long int> po;

int main(){
    cin >> a >> b >> c;
    po.push_back(a);
    po.push_back(b);
    po.push_back(c);
    sort(po.begin(),po.end());
    //cout << a << b << c << endl;
    if((a*b*c)%2==0)cout << 0 << endl;
    else cout << po[0]*po[1] << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream> 
#include <string> 
#include <vector> 
#include <cmath> 
#include <algorithm> 
#include <cstdlib> 
#include <ctime> 
#include <cstdio> 
#include <functional> 
#include <set> 
#include <queue> 
#include <cctype> 
#include <climits> 
#include <stack> 
#include <map> 
#include <cstring> 

using namespace std; 

int a[100010]={};

int main(){

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

    for(int i=0;i<m;i++){
        int l,r;
        cin>>l>>r;

        l--,r--;
        a[l]++;
        a[r+1]--;
    }

    for(int i=0;i<n+10;i++){
        a[i+1]+=a[i];
    }

    int res=0;
    for(int i=0;i<n;i++){
        if(a[i]==m) res++;
    }

    cout<<res<<endl;

    return 0;
}

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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  
  vector<char> alphabet = {'A', 'B', 'C', 'D', 'E', 'F', 'G', 'H', 'I',
                           'J', 'K', 'L', 'M', 'N', 'O', 'P', 'Q', 'R',
                           'S', 'T', 'U', 'V', 'W', 'X', 'Y', 'Z'};
  vector<int> arr(s.size());
  for (int i = 0; i < s.size(); i++) {
    for (int j = 0; j < 26; j++) {
      if (s.at(i) == alphabet.at(j)) {
        if (j + n >= 26) {
          arr.at(i) = (j + n) - 26;
        } else {
          arr.at(i) = j + n; 
        }
      }
    }
  }
  for (int i = 0; i < s.size(); i++) {
    cout << alphabet.at(arr.at(i));
  }
  cout << endl;
}

Measured memory_bytes: 384
// Words are flowing out like endless rain into a paper cup
// They slither while they pass they slip away across the universe
// Pools of sorrow, waves of joy are drifting through my open mind
// Possessing and caressing me

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

using LL = long long;

namespace _buff {

const size_t BUFF = 1 << 19;
char ibuf[BUFF], *ib = ibuf, *ie = ibuf;
char getc() {
    if (ib == ie) {
        ib = ibuf;
        ie = ibuf + fread(ibuf, 1, BUFF, stdin);
    }
    return ib == ie ? -1 : *ib++;
}

}

LL read() {
    using namespace _buff;
    LL ret = 0;
    bool pos = true;
    char c = getc();
    for (; (c < '0' || c > '9') && c != '-'; c = getc()) {
        assert(~c);
    }
    if (c == '-') {
        pos = false;
        c = getc();
    }
    for (; c >= '0' && c <= '9'; c = getc()) {
        ret = (ret << 3) + (ret << 1) + (c ^ 48);
    }
    return pos ? ret : -ret;
}

const size_t N = 1e4 + 5;

char s[N];

int main() {
    int n;
    scanf("%d%s", &n, s);
    int len = strlen(s);
    for (int i = 0; i < len; ++i) {
        char &c = s[i];
        c = ((int) c - 'A' + n) % 26 + 'A';
    }
    puts(s);
    return 0;
}


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

using namespace std;

typedef long long ll;

const int N = 200010;

int n, a[N], k;

ll f(int x) {
	ll p = 0;
	for (int i = 1; i <= n; i++)
		p += (a[i] - 1) / x;
	return p;
}

int main() {
	cin >> n >> k;
	for (int i = 1; i <= n; i++)
		cin >> a[i];
		
	int l = 1, r = 1e9;
	while (l < r) {
		int m = l + r >> 1;
		if (f(m) > k) l = m + 1;
		else r = m;
	}
	cout << l << endl;
	
	return 0;
}


Measured memory_bytes: 4320
#!/usr/bin/env python
# -*- coding: utf-8 -*-

import sys


def input():
    return sys.stdin.readline()


def resolve():
    x, y = map(int, input().split())

    for i in range(x):
        foot_num = (i+1)*2 + (x-(i+1))*4
        if foot_num == y:
            print("Yes")
            exit()
        foot_num = (i+1)*4 + (x-(i+1))*2
        if foot_num == y:
            print("Yes")
            exit()

    print("No")




if __name__ == "__main__":
    resolve()



Measured memory_bytes: 61860
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <stack>
#include <functional>
#define SIZE 10005

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

char str[SIZE];

int main()
{
	int n;
	scanf("%d",&n);
	int cnt=0;
	int a=0,b=0,ba=0;
	for(int i=0;i<n;i++)
	{
		scanf("%s",&str);
		int L=strlen(str);
		for(int j=0;j+1<L;j++)
		{
			if(str[j]=='A'&&str[j+1]=='B')
			{
				cnt++;
			}
		}
		if(str[0]=='B') b++;
		if(str[L-1]=='A') a++;
		if(str[0]=='B'&&str[L-1]=='A') ba++;
	}
	cnt+=min(a,b);
	if(a==ba&&b==ba&&b>0) cnt--;
	printf("%d\n",cnt);
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>
#define true 1
#define false -1
#define M 2000

int x[M],y[200],n;

int solve (int i,int j)
{
  int res;
  if(j==0) return true;
  if(i>=n) return false;
  if(solve(i+1,j)==true) res=true;
  else if(solve(i+1,j-x[i])==true)res=true;
  else res=false;
  return res;
}

int main()
{
  int a,b,c,d=0;
  char s[2][4]={"yes","no"};

  scanf("%d",&n);
  for(a=0;a<n;a++)scanf("%d",&x[a]);

   scanf("%d",&b);
   for(a=0;a<b;a++){
      scanf("%d",&y[a]);
      if(solve(0,y[a])==true)printf("%s\n",s[0]);
      else printf("%s\n",s[1]);
   }
   return 0;
}



Measured memory_bytes: 2108
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){

  vector<char> s;
  string t;
  cin >> t;
  for (int i = 0; i < t.size(); i++){
    s.push_back(t[i]);
  }

  sort(s.begin(), s.end());
  s.erase(unique(s.begin(), s.end()), s.end());

  if (t.size() == s.size()){
    cout << "yes" << endl;
  }
  else {
    cout << "no" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int mod = 1e9+7;
char s[100005];
int dp[100005][3];
int add(int a, int b){
	return ((a+b)%mod+mod)%mod;
}
int main(){
	scanf("%s", s+1);
	int n = strlen(s+1);

	int res = 1;
	for(int i=1;i<=n;i++){
		if(s[i] == 'A' || s[i] == '?'){
			dp[i][0] = add(dp[i][0], res);

			dp[i][0] = add(dp[i][0], dp[i-1][0]);
			dp[i][1] = add(dp[i][1], dp[i-1][1]);
			dp[i][2] = add(dp[i][2], dp[i-1][2]);
		}
		if(s[i] == 'B' || s[i] == '?'){
			dp[i][1] = add(dp[i][1], dp[i-1][0]);

			dp[i][0] = add(dp[i][0], dp[i-1][0]);
			dp[i][1] = add(dp[i][1], dp[i-1][1]);
			dp[i][2] = add(dp[i][2], dp[i-1][2]);
		}
		if(s[i] == 'C' || s[i] == '?'){
			dp[i][2] = add(dp[i][2], dp[i-1][1]);

			dp[i][0] = add(dp[i][0], dp[i-1][0]);
			dp[i][1] = add(dp[i][1], dp[i-1][1]);
			dp[i][2] = add(dp[i][2], dp[i-1][2]);
		}

		if(s[i] == '?') res = ((long long)res*3)%mod;
	}
	printf("%d\n", dp[n][2]);
}

Measured memory_bytes: 1536
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <functional>

using namespace std;

typedef pair<int, int> P;

int main()
{
    int n, m, a;

    while (cin >> n >> m >> a, a || n || m) {
        vector<P> chan(m);
        vector<P> hei(m);
        int num[102];

        for (int i = 1; i <= n; i++)
            num[i] = i;

        for (int i = 0; i < m; i++) {
            int t1, t2, t3;

            cin >> t1 >> t2 >> t3;
            chan[i] = P(t2, t3);
            hei[i] = P(t1, i);
        }
        sort(hei.begin(), hei.end(), greater<P>());
        vector<P>::iterator it = hei.begin();
        while (it != hei.end()) {
            int to, from;

            to = chan[(*it).second].first;
            from = chan[(*it).second].second;

            swap(num[to], num[from]);
            it++;
        }
        for (int i = 1; i <= n; i++)
            if (num[i] == a) {
                cout << i << endl;
                break;
            }
    }


    return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <map>
#include <unordered_map>
#include <set>
#include <utility>
#include <stack>
#include <cstdio>
#include <string>
#include <cmath>
#include <cstring>
#include <vector>
#include <queue>
#include <algorithm>
#include <iterator>
#include <sstream>
#define popcount(x) __builtin_popcount(x)
#define oddparity(x) __builtin_parity(x)
#define clz(x) __builtin_clz(x)
#define ctz(x) __builtin_ctz(x)
#define sf scanf
#define pf printf
#define ll long long int
using namespace std;

int i, a, b, c;
bool flag[101];

int main()
{
    sf("%d%d%d", &a, &b, &c);
    for (i = 0; ; i += a) {
        if ( (a + i) % b == c) {
            pf("YES\n");
            return 0;
        }
        else if (flag[(a + i) % b] == false) {
            flag[(a + i) % b] = true;
        }
        else {
            pf("NO\n");
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 256
n = int(input())

c,d = 0,0
for i in range(n):
    a,b = map(int,input().split())
    if c<=a and d<=b:
        c,d=a,b
        continue
    else:
        f = max(c//a + (c%a>0),d//b+(d%b>0))
        c,d = a*f,b*f
print(c+d)
         


Measured memory_bytes: 3060
import core.bitop;
import std.algorithm;
import std.ascii;
import std.bigint;
import std.conv;
import std.functional;
import std.math;
import std.numeric;
import std.range;
import std.stdio;
import std.string;
import std.random;
import std.typecons;
import std.container;

alias sread = () => readln.chomp();
alias Point2 = Tuple!(long, "y", long, "x");

T lread(T = long)()
{
    return readln.chomp.to!T();
}

T[] aryread(T = long)()
{
    return readln.split.to!(T[])();
}

void scan(TList...)(ref TList Args)
{
    auto line = readln.split();
    foreach (i, T; TList)
    {
        T val = line[i].to!(T);
        Args[i] = val;
    }
}

void minAssign(T, U = T)(ref T dst, U src)
{
    dst = cast(T) min(dst, src);
}

enum MOD = 10 ^^ 9 + 7;

void main()
{
    long N = lread();
    string S = sread();
    long[] T = new long[N + 1];
    foreach (i; 0 .. N)
        T[i + 1] = T[i] + (S[i] == '#');
    // writeln(S);
    // writeln(T);

    long ans = long.max;
    foreach (i; 0 .. N)
    {
        long a = (T[i + 1]);
        long b = ((N - i - 1) - (T[$ - 1] - T[i]));
        // writefln("%d %d %d", i, a, b);
        ans = ans.min(a + b);
    }
    writeln(ans);
}


Measured memory_bytes: 4092
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>

using namespace std;

#define FOR(i,a,b) for(long long i=(a);i<(b);i++)
#define REP(i,N) for(long long i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define fi first
#define se second

#define PI acos(-1.0)
#define INF 1000000007

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<double, double> PD;
typedef pair<string, ll> PS;
typedef vector<ll> V;

string s;
stack<double> sd;
vector<string> vs;
double a, b;

int main(){
	while (getline(cin, s)){
		string buf;
		int start = 0;
		REP(i, s.size()){
			if (s[i] == ' '){
				buf = s.substr(start, i - start);
				vs.push_back(buf);
				start = i + 1;
			}
		}
		buf = s.substr(start, s.size() - start);
		vs.push_back(buf);
		REP(i,vs.size()){
			stringstream ss;
			if (vs[i] == "+"){
				a = sd.top(); sd.pop();
				b = sd.top(); sd.pop();
				sd.push(b + a);
			}
			else if (vs[i] == "-"){
				a = sd.top(); sd.pop();
				b = sd.top(); sd.pop();
				sd.push(b - a);
			}
			else if (vs[i] == "*"){
				a = sd.top(); sd.pop();
				b = sd.top(); sd.pop();
				sd.push(b*a);
			}
			else if (vs[i] == "/"){
				a = sd.top(); sd.pop();
				b = sd.top(); sd.pop();
				sd.push(b / a);
			}
			else{
				ss << vs[i];
				ss >> a;
				sd.push(a);
			}
		}
		printf("%.10lf\n", sd.top());
		sd.pop();
		vs.clear();
	}
}

Measured memory_bytes: 1304
using System;

namespace abc073_c
{
    class Program
    {
        static void Main(string[] args)
        {
            int n = int.Parse(Console.ReadLine());
            int[] a = new int[n];
            for (int i = 0; i < n; i++)
            {
                a[i] = int.Parse(Console.ReadLine());
            }
            Array.Sort(a);
            int found = 0;
            int now = a[0];
            int ret = 0;
            while (found < n)
            {
                now = a[found];
                int ren = 0;
                for (; found < n && now == a[found]; found++) ren++;
                if (ren % 2 == 1) ret++;
            }
            Console.WriteLine(ret);
        }
    }
}

Measured memory_bytes: 15452
rr = lambda: input().strip()
rrm = lambda: list(map(int, rr().split()))

N, M, C = rrm()
B = rrm()
ans = 0
for _ in range(N):
    A = rrm()
    if sum(a*b for a,b in zip(A,B)) + C > 0:
        ans += 1
print(ans)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;
using ll = long long;

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

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

  string ans;

  n %= 10;

  if (n == 2 || n == 4 || n == 5 || n == 7 || n == 9)
    ans = "hon";
  else if (n == 0 || n == 1 || n == 6 || n == 8)
    ans = "pon";
  else if (n == 3)
    ans = "bon";

  cout << ans << '\n';
  return 0;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define AND(x,y,z) 
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define DUMPP(xs) for (auto x:xs) cout<<'('<<x.first<<','<<x.second<<')';cout<<endl
#define FOR(i,a,b) for (ll i=(ll)(a);i<(ll)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define YES(cond) cond ? OUT("YES") : OUT("NO")
#define Yes(cond) cond ? OUT("Yes") : OUT("No")

template<class T> T gcd(const T x,const T y){if(!y){return x;}return gcd(y,x%y);}
template<class T> T lcm(const T x,const T y){return x/gcd(x,y)*y;};
template<class T> T modpow(const T x,const T n,const T mod) {
  T res=1;while(n>0){if(n%2)res=res*x%mod;x=x*x%mod;n/=2;};return res;
}
template<class T> bool alltrue(const T &a){return all_of(ALL(a),[](bool x){return x;});}
template<class T> bool anytrue(const T &a){return any_of(ALL(a),[](bool x){return x;});}
template<class T> bool contain(const T &a,const T &b){for(auto x:b){if (a.find(x)==a.end()){return false;}}return true;}
template<class T> bool mmax(T &m,const T q){ if (m < q) {m = q; return true;} else return false; }
template<class T> bool mmin(T &m,const T q){ if (m > q) {m = q; return true;} else return false; }
template<class T> int siz(const T &a) {return (int)a.size();}
template<class T> set<T> devisers(T n) {
  set<T> res;for(T i=1;i<(T)sqrt(n)+1;i++){if(n%i==0){res.insert(i);res.insert(n/i);}}return res;
}
template<class T> void concat(T &a, const T &b){a.insert(a.end(),b.begin(),b.end());}
template<class T> void getand(const T &a,const T &b,T &c) {
  set_intersection(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}
template<class T> void getor(const T &a,const T &b,T &c) {
  set_union(a.begin(),a.end(),b.begin(),b.end(),inserter(c,c.end()));
}

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

const int MOD=1e9+7;
const int MAX=1e5+100;

struct UnionFind {
private:
  int N;
  // parは親要素、rancは階層、cntはそのTree内に含まれる要素数
  vector<int> par,ranc,cnt;
  
public:
  UnionFind(int N) : N(N),par(N),ranc(N,0),cnt(N,1) { REP(i,N) par[i]=i; }
  
  int memsiz(int s) { return cnt[root(s)]; }
  int root(int s) { return (par[s]==s) ? s : root(par[s]); }
  bool same(int x, int y) { return root(x)==root(y); }
  
  bool connected() {
    int base = root(0);
    REP(i,N) if (root(i)!=base) return false;
    return true;
  }
  
  void merge(int x, int y) {
    x = root(x);
    y = root(y);
    if (x==y) return;
    if (ranc[x]>ranc[y]) {
      par[y] = x;
      cnt[x] += cnt[y];
    } else {
      par[x] = y;
      cnt[y] += cnt[x];
      if (ranc[x]==ranc[y]) ranc[y]++;
    }
  }
};

int main() {
  // 払うコストの合計の最小値
  // 1 2 1 2 2 1
  // xとyの合計が奇数か偶数かわかれば、AxがわかればAyもわかる
  // xとyのペアに選ばれている箇所に関しては、そのどちらかに魔法を使えばいい
  // それ以外の箇所は逐一魔法を使ってわからせるしかない
  // 結論、UnionFindのrootの数
  int N,M;cin>>N>>M;
  UnionFind uf(N);
  REP(i,M) {
    int x,y,z;cin>>x>>y>>z;
    x--;y--;
    uf.merge(x,y);
  }
  set<int> ans;
  REP(i,N) ans.insert(uf.root(i));
  OUT(siz(ans));

  return 0;
}

Measured memory_bytes: 6144
# include <iostream>
# include <algorithm>
# include <vector>
# include <string>
# include <set>
# include <map>
# include <cmath>
# include <iomanip>
# include <functional>
# include <utility>
# define MOD 1000000000+7
# define INF 1000000000
using namespace std;

int main() {
	int n, m;
	cin >> n >> m;
	if (abs(n - m) >= 2) {
		cout << 0 << endl;
	}
	else {
		long long ans = 1;
		for (int i = 1; i <= n; i++) {
			ans *= i;
			if (ans >= MOD) {
				ans %= MOD;
			}
		}
		for (int i = 1; i <= m; i++) {
			ans *= i;
			if (ans >= MOD) {
				ans %= MOD;
			}
		}
		if (n == m) {
			ans *= 2;
			if (ans > MOD) {
				ans %= MOD;
			}
		}
		cout << ans << endl;
	}
}



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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    ll p[200010];
    rep(i,0,N) cin >> p[i];
    ll sum = 0;
    rep(i,0,K) sum += p[i];
    ll ans = sum;
    rep(i,K,N){
        sum += p[i];
        sum -= p[i-K];
        ans = max(ans, sum);
    }
    double res = ((double) ans + K) / 2.0;
    cout << setprecision(10) << res << endl;

    

}

Measured memory_bytes: 1792
#include<iostream>
 
 using namespace std;
   
   
int main()
{   int S;
    cin>>S;
	int s;
	s=S%60;
	int tsukukoma;
	tsukukoma=(S-s)/60;
	int m;
	m=tsukukoma%60;
	int h;
	h=(tsukukoma-m)/60;
	cout<<h<<":"<<m<<":"<<s<<endl;
	
	

	
	 
	
	
}



Measured memory_bytes: 3092
{-# LANGUAGE BangPatterns #-}

import Data.Bits
import Data.List
import Data.IntMap.Strict (IntMap)
import qualified Data.IntMap.Strict as IntMap
import qualified Data.ByteString.Char8 as B
import Control.Monad
import Control.Applicative
import Data.Maybe
import Data.Function
import qualified Data.IntMap.Strict as M
import qualified Data.ByteString.Char8 as B
import qualified Data.Vector.Unboxed as V
-- import Data.Vector.Unboxed ((!))
import Data.Tuple
import Data.Ord (Down(..))
import Data.Coerce

query :: [(Int, Int)] -> [Int]
query = map snd . sortOn fst 
  . concatMap (zipWith (\k (j,(p,_)) -> (j, code p k)) [1..])
  . groupBy ((==) `on` (fst . snd))
  . sortBy (compare `on` snd) . zip ([0..] :: [Int])
  where
    code p k = 10^12 + 10^6 * p + k

main :: IO ()
main = do
  [n,m] <- map read . words <$> getLine :: IO [Int]
  let conv [x,y] = (x,y) :: (Int, Int)
  pys <- replicateM m $ conv . map read . words <$> getLine
  mapM_ (putStrLn . tail . show) $ query pys


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

#define rep(i, n) for (int i = 0; i < n; ++i)
#define ALL(a) (a).begin(), (a).end()
#define rALL(a) (a).rbegin(), (a).rend()
#define SZ(x) ((int)(x).size())
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 55;
const int mod = 1000000007;
//const int mod = 998244353;

template <class T>inline bool chmin(T &a, const T b)
{
  if (a > b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline bool chmax(T &a, const T b)
{
  if (a < b)
  {
    a = b;
    return true;
  }
  return false;
}
template <class T>inline void line_out(const vector<T> vec) {
  int n = SZ(vec);
  rep(i, n) {
    cout << vec[i];
    if(i < n-1) cout << " ";
  }
  cout << endl;
  return;
}

struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  ll n;
  cin >> n;
  --n;
  vector<int> ans;
  do {
    ans.push_back(n%26);
    n/=26;
    --n;
  } while(n >= 0);
  reverse(ALL(ans));
  for(auto x : ans) cout << (char)('a'+x);
  cout << endl;
}

Measured memory_bytes: 3588
import math
num = int(input())
data1 = []
data2 = []
tmp = []
tmp = input().split()
data1 = [float(tmp[i]) for i in range(num)]
tmp = input().split()
data2 = [float(tmp[i]) for i in range(num)]
print(sum( abs(data1[i] - data2[i]) for i in range(num) ))
print(math.sqrt( sum(pow( data1[i] -data2[i] ,2 ) for i in range(num))))
print(pow( sum(pow( abs(data1[i] -data2[i]) ,3 ) for i in range(num)) ,1/3 ))
print(max( abs(data1[i] - data2[i]) for i in range(num) ))


Measured memory_bytes: 7908
import numpy as np

N,K,Q = map(int,input().split())
A = []
for i in range(Q):
  A.append(int(input()))
p = np.ones(N)*(K-Q)
pm = np.zeros(N)
for i in range(Q):
  pm[A[i]-1] += 1
pa = p + pm
for i in  range(N):
  if pa[i] > 0:
    print("Yes")
  else:
    print("No")

Measured memory_bytes: 19164