akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }
    input! {
        n: usize,
        k: usize,
        h: [i64; n],
    }
    let mut dp = vec![1i64 << 40; n];
    dp[0] = 0;
    for i in 1 .. n {
        for j in 1 .. min(i, k) + 1 {
            dp[i] = min(dp[i], dp[i - j] + (h[i] - h[i - j]).abs());
        }
    }
    puts!("{}\n", dp[n - 1]);
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 10620
K = int(input())
A = tuple(map(int, input().split()))

l, r = 1, 10 ** 18
while r - l > 1:
    m = (l + r) // 2
    M = m
    for a in A:
        M = (M // a) * a

    if M <= 2:
        l = m
    else:
        r = m
ans_max = l

l, r = 1, 10 ** 18
while r - l > 1:
    m = (l + r) // 2
    M = m
    for a in A:
        M = (M // a) * a

    if M >= 2:
        r = m
    else:
        l = m
ans_min = r

if ans_min > ans_max:
    print(-1)
else:
    print(ans_min, ans_max)


Measured memory_bytes: 63984
N = int(input())
t, x, y = [0]*3
for _ in range(N):
  t_, x_, y_ = map(int, input().split())
  dis = abs(x_ - x) + abs(y_ - y)
  dt = t_ - t
  if dis > dt:
    print("No")
    exit()
  if dis%2 == dt%2:
    t, x, y = t_, x_, y_
  else:
    print("No")
    exit()
print("Yes")

Measured memory_bytes: 9088
import java.util.*;

public class Main {
	static public void main(String args[]){
		Scanner sc=new Scanner(System.in);
		 
		 String str=sc.next();
		 int len=str.length();
		 int i=0,j=len-1;
		 boolean ju=true;
		 
		 while(i<j){
		 	if(str.charAt(i++)!=str.charAt(j--)){
				ju=false;
				System.out.println("No");
				System.exit(0);
		 	}
		 }
		 
		 i=0;
		 j=(len-1)/2;
		 j-=1;
		 while(i<j){
		 	if(str.charAt(i++)!=str.charAt(j--)){
				ju=false;
				System.out.println("No");
				System.exit(0);
		 	}
		 }
		 
		 i=(len+3)/2;
		 i-=1;
		 j=len-1;
		  while(i<j){
		 	if(str.charAt(i++)!=str.charAt(j--)){
				ju=false;
				System.out.println("No");
				System.exit(0);
		 	}
		 }
		 
		 if(ju)System.out.println("Yes");
	}
}

Measured memory_bytes: 35588
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<limits.h>
#include<stdbool.h>
#define lpton(i,n) for(int i=0;i<(int)n;i++)
#define lpto0(i,n) for(int i=n;i>-1;i--)
#define lpmn(i,m,n) for(int i=m;i<n;i++)
#define ms(l,n,s) memset(l,n,s)
#define m(l,n) (l*)malloc(n*sizeof(l))
#define max 250
//void print(int*,int);
void print(int[],int);
int main(){
  int n,v;
  //int *heap;
  int heap[max];
  scanf("%d",&n);
  //heap=m(int,n+1);
  lpmn(i,1,n+1){
    scanf("%d",&v);
    //*(heap+i)=v;
    heap[i]=v;
  }
  print(heap,n);
  //free(heap);
  return 0;
}
/*void print(int *heap,int n){
  lpmn(i,1,n+1){
    printf("node %d: key = %d, ",i,*(heap+i));
    if(i/2>0)printf("parent key = %d, ",*(heap+(i/2)));
    if(i*2<n+1)printf("left key = %d, ",*(heap+(i*2)));
    if(i*2+1<n+1)printf("right key = %d, ",*(heap+(i*2+1)));
    printf("\n");
  }
}*/
void print(int heap[],int n){
  lpmn(i,1,n+1){
    printf("node %d: key = %d, ",i,heap[i]);
    if(i/2>0)printf("parent key = %d, ",heap[i/2]);
    if(i*2<n+1)printf("left key = %d, ",heap[i*2]);
    if(i*2+1<n+1)printf("right key = %d, ",heap[i*2+1]);
    printf("\n");
  }
}



Measured memory_bytes: 2104
import sys
sys.setrecursionlimit(10000000)
MOD = 10 ** 9 + 7
INF = 10 ** 15

class UnionFind():
    def __init__(self,n):
        self.n = n
        self.parents = [-1]*n

    def find(self,x): #根を見つける、繋ぎ直す
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    
    def unite(self,x,y):
        y = self.find(y)
        x = self.find(x)
        self.parents[y] += self.parents[x]
        self.parents[x] = y
    
    def same(self,x,y):#xとyが同じグループにいるか判定
        return self.find(x) == self.find(y)


def solve(N,Q):
    parents = [-1] * N
    for i in range(1,N):
        p = int(input()) - 1
        parents[i] = p
    
    query = []
    mark = [0] * N
    mark[0] = 1
    for _ in range(Q):
        q = input().split()
        v = int(q[1]) - 1
        if q[0] == 'M':
            mark[v] += 1
            query.append((0,v))
        else:
            query.append((1,v))
    
    uf = UnionFind(N)
    for i in range(N):
        if mark[i] == 0:
            uf.unite(i,parents[i])
    
    ans = 0
    for ty,v in query[::-1]:
        if ty == 0:
            mark[v] -= 1
            if mark[v] == 0:
                uf.unite(v,parents[v])
        else:
            ans += uf.find(v) + 1
    print(ans)

def main():
    while True:
        N,M = map(int,input().split())
        if N == 0:
            return
        solve(N,M)
if __name__ == '__main__':
    main()


Measured memory_bytes: 22340
#include <bits/stdc++.h>
#define ll long long int
#define mod 1000000007
#define intpair pair<int,int>
using namespace std;
inline int add(int a,int b){a+=b;if(a>=mod)a-=mod;return a;}
inline int mul(int a,int b){return (a*1ll*b)%mod;}
inline int pow(int a,int b){int rt=1;while(b>0){if(b&1)rt=mul(rt,a);a=mul(a,a);b>>=1;}return rt;}
inline bool sortinrev(const pair<int,int> &a,const pair<int,int> &b){return (a.first > b.first);} //sort pair in descending order
int main(){
		ios_base::sync_with_stdio(false);
    cin.tie(NULL);
		ll w,s;
		cin>>s>>w;
		if(w>=s)cout<<"unsafe\n";
		else cout<<"safe\n";
}



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

int main() {
	int a,b,c,k;
	pair<int,int>ma;
	ma.second=-1;
	cin>>a>>b>>c>>k;
	if(a>=b && a>=c){
		ma.first=a;
		ma.second=a;
	}else if(b>=a&&b>=c){
		ma.first=b;
		ma.second=b;
	}else if(c>=a&&c>=b){
		ma.first=c;
		ma.second=c;
	}
	for(int i=0;i<k;i++){
		ma.first*=2;
	}
	cout<<ma.first+a+b+c-ma.second<<endl;
	return 0;

}



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

int p,n,a[100];
int odd=0,even=0;
long long C[60][60];
long long jiec[60];

void init();

int main()
{
    init();
    scanf("%d %d",&n,&p);
    for(int i=0;i<n;++i)
    {
        scanf("%d",&a[i]);
        if(a[i]%2==0)
            ++even;
        else
            ++odd;
    }

    long long a=0,b=0;
    if(p==0)
    {
        for(int i=0;i<=even;++i)
            a+=C[even][i];
        for(int j=0;j<=odd;j+=2)
            b+=C[odd][j];
    }
    else
    {
        for(int i=0;i<=even;++i)
            a+=C[even][i];
        for(int j=1;j<=odd;j+=2)
            b+=C[odd][j];
    }

    long long ans=a*b;
    printf("%lld",ans);
}

void init()
{
    jiec[0]=jiec[1]=1;
    for(int i=2;i<=51;++i)
    {
        jiec[i]=i*jiec[i-1];
    }

    int i,j;
    for(i=0; i<=MAXN; ++i)
    {
        C[0][i] = 0;
        C[i][0] = 1;
    }
    for(i=1; i<=MAXN; ++i)
    {
        for(j=1; j<=MAXN; ++j)
            C[i][j] = (C[i-1][j] + C[i-1][j-1]);
    }
}

int cbin(int n, int m)
{

}


Measured memory_bytes: 256
//#include<bits/stdc++.h>
#include<iostream>
#include<iomanip>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<string>
#include<numeric>
#include<vector>
#include<set>
#include<map>
#include<unordered_map>
#include<stack>
#include<queue>
#include<list>
using namespace std;

typedef long long ll;

#define MOD 1000000007

class Comb{
private:
  ll *fac,*finv,*inv;
public:
  Comb(){
    fac = new ll[1000000];
    finv = new ll[1000000];
    inv = new ll[1000000];
    fac[0] = 1;
    for(int i=1;i<1000000;i++){
      fac[i] = i*fac[i-1];
      fac[i] %= MOD;
    }
    inv[1] = 1;
    for(int i=2;i<1000000;i++){
      inv[i] = MOD-inv[MOD%i]*(MOD/i)%MOD;
    }
    finv[0] = 1;
    for(int i=1;i<1000000;i++){
      finv[i] = inv[i]*finv[i-1];
      finv[i] %= MOD;
    }
  }
  ll calc(ll n,ll k){
    ll c = fac[n];
    c *= finv[k];c %= MOD;
    c *= finv[n-k];c %= MOD;
    return c;
  }
};

int debug(vector<int>& nums, int target) {
        if(target == 0) return 0;
        int dp[target+1];
        for(int i=0;i<target+1;i++){
            dp[i] = 0;
        }
        
        dp[0] = 1;
        for(int i=1;i<target+1;i++){
            for(int j=0;j<nums.size();j++){
                if(i - nums[j] >= 0){
                    //cout << i - nums[j] << endl;
                    dp[i] += dp[i-nums[j]];
                }
            }
        }
        return dp[target];
    }

int main(){
  int m,d;
  cin >> m >> d;
  int ans = 0;
  for(int i=1;i<m+1;i++){
    for(int j=1;j<d+1;j++){
      if((j/10) < 2 || (j%10) < 2) continue;
      if(i == (j/10)*(j%10)) ans += 1;
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>


int main(void){
	int w,n,a,b;
	int i,temp;
	int data[40];

	for(i=0;i<30;i++){
		data[i]=i+1;
	}

	scanf("%d %d",&w,&n);
	for(i=0;i<n;i++){
		scanf("%d,%d",&a,&b);
		temp = data[a-1];
		data[a-1] = data[b-1];
		data[b-1] = temp;
	}

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

Measured memory_bytes: 596
// MPC-B.cpp :
//#include "pch.h"
#include <iostream>
using namespace std;

int main()
{
	int N;
	cin >> N;
	int X;
	X = N / 1.08;
	if ((int)(X*1.08)==N)
	{
		cout << X << endl;
	}
	else {
		if ((int)((X+1)*1.08)==N)
		{
			cout << X+1 << endl;
		}
		else
		{
			//cout << "(X+1)*1.08=" << (X + 1)*1.08 << endl;
			cout << ":(" << endl;
		}
	}
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
class Program
    {
        static void Main(string[] args)
        {
            String S = Console.ReadLine();
            String[] resultset = { "Yes", "No" };

            bool[] charchecker = new bool[3];
            bool clearflag = true;
            
            // 3個の文字が出てくればいい
            for (int i = 0; i < S.Length; i++)
            {
                if(S[i] == 'a' && !charchecker[0])
                {
                    charchecker[0] = true;
                }
                else if(S[i] == 'b' && !charchecker[1])
                {
                    charchecker[1] = true;
                }
                else if (S[i] == 'c' && !charchecker[2])
                {
                    charchecker[2] = true;
                }
                else
                {
                    clearflag = false;
                    break;
                }
            }
            String result = clearflag ? resultset[0] : resultset[1];
            Console.WriteLine(result);
            //Console.ReadLine();
        }
    }

Measured memory_bytes: 11092
## abc070d: Transit Tree Path

n = int(input())

T = [None]*(n+1)
for _ in range(n-1):
    v1,v2,d = map(int, input().split())
    if(T[v1] is None): T[v1] = [[v1,v2,d]]
    else: T[v1].append([v1,v2,d])
    if(T[v2] is None): T[v2] = [[v2,v1,d]]
    else: T[v2].append([v2,v1,d])

depth = [0]*(n+1)

q,k = map(int, input().split())

is_visit = [False]*(n+1)
p,c,d = 0,k,0
depth[c] = d
is_visit[c] = True
stack = T[c]
while stack:
    p,c,d = stack.pop()
    if is_visit[c]: continue
    is_visit[c] = True
    depth[c] = depth[p] + d
    for pp,cc,dd in T[c]:
        if not is_visit[cc]: stack.append([pp,cc,dd])

for _ in range(q):
    v1,v2 = map(int, input().split())
    print(depth[v1]+depth[v2])

Measured memory_bytes: 51872
#include <stdio.h>
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cstdlib>
#include <list>
#include <numeric>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

int a, b = 0, n, k;
string s, t;
//cout<<<<endl;


int main()
{
	cin >> n;
	rep(i, 9)
	{
		rep(j, 9)
			if (n == (i + 1) * (j + 1))
			{
				s = "Yes"; break;
			}
		if (s == "Yes")
			break;

	}
	if (s == "Yes")
		cout << s << endl;
	else
		cout << "No" << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <cstdio>
#include <cmath>
#include <tuple>
#include <iomanip>
#include <numeric>
#include <unordered_map>
#include <sstream>   
#include<limits.h>
#include<float.h>
#include<list>
#include <array>
#include <complex>
#include<stdio.h>
#include<string.h>

using namespace std;
#define int  long long
 
#define I32_MAX 2147483647
#define I64_MAX 9223372036854775807LL
#define I64_MAX2 1223372036854775807LL
#define INF I64_MAX2
#define MOD 1000000007
#define MEM_SIZE 10000
#define DEBUG_OUT true
#define ALL(x) (x).begin(),(x).end()
// int DP[MEM_SIZE][MEM_SIZE] = {0};
// int GMEM[MEM_SIZE][MEM_SIZE] = {0};
template<typename T> void DEBUG(T e){if(DEBUG_OUT == false)return;std::cout << e << std::endl;}
template<typename T> void DEBUG(const std::vector<T>& v){if(DEBUG_OUT == false)return;for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void DEBUG(const std::vector<std::vector<T> >& vv){if(DEBUG_OUT == false)return;for(const auto& v : vv){ DEBUG(v); } }
template<class T,class X> void DEBUG(X d, T e){if(DEBUG_OUT == false)return;std::cout <<d<<" ";DEBUG(e);};
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template< typename T1, typename T2 > inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 > inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }
template< typename T > using matrix = vector< vector< T > >;

//FUNCTION  


void solve(void)
{
  int K,N;
  cin>>K>>N;
  vector<int> vec(N);
  for (int i = 0; i < N; i++)
  {
    cin>>vec[i];
  }
  
  sort(ALL(vec));
  vec.push_back(K+vec[0]);
  int MAX = 0;
  for (int i = 0; i < N; i++)
  {
    chmax(MAX,vec[i+1] - vec[i]);
  }
  cout<< K - MAX<<endl;
  
  
  return;
}

int32_t main(int32_t argc, const char *argv[])
{
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);

  std::cout << std::fixed;
  std::cout << std::setprecision(9);
  solve();

  return 0;
}


Measured memory_bytes: 4864
#include <iostream>
#include <algorithm>

using namespace std;

int main (void)
{
    string s, ans = "";

    cin >> s;
    for (int i = 0; i < s.size(); i++) {
        if (i % 2 == 1) continue;
        ans += s[i];
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 512
#include <iostream>
using namespace std;
typedef long long ll;
int main (void) {
    ll x;

    cin >> x;

    ll ans = 0;
    ans = x / 11 * 2;
    x = x % 11;
    if (x == 0) ;
    else if (x <= 6) ans++;
    else ans += 2;

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <algorithm>
#include <cstdio>
#include <functional>
#include <iostream>
#include <cfloat>
#include <climits>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <time.h>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<ll, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<ll, ll> ll_ll;
typedef pair<double, double> d_d;
struct edge { int u, v; ll w; };

ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
	int N, T; cin >> N >> T;
	vector<int> D(N);
	for (int i = 0; i < N; i++)
		cin >> D[i];
	sort(D.begin(), D.end());
	ll ans = 1;
	for (int i = 0; i < N; i++) {
		int _i = upper_bound(D.begin(), D.end(), D[i] + T) - D.begin();
		ans = (ans * (_i - i)) % MOD;
	}
	cout << ans << endl;
}

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

using namespace std;

const int N=1e5+10;
int dp[N];
int a[N];

int main()
{

    int n;
    scanf("%d",&n);

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

        dp[0]=0;
        dp[1]=abs(a[0]-a[1]);

        for(int i=2;i<n;i++)
            dp[i]=min(abs(a[i]-a[i-1])+dp[i-1],abs(a[i]-a[i-2])+dp[i-2]);

        printf("%d",dp[n-1]);
}


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

typedef long long ll;
const ll MAX = 1e18;

ll x; int n;
int main()
{
  	ll now = 1;
  	int flag = 0;
	scanf("%d", &n);
  	for(int i = 1; i <= n; i++) {
    	scanf("%lld", &x);
		if(now == 0 || x == 0) {now = 0; continue;}
      	if(MAX / now >= x) now = now * x;
        else flag = 1;
    }
  	if(flag && now != 0) puts("-1");
  	else printf("%lld\n", now);
  
  	return 0;
}


Measured memory_bytes: 3792
<?php
fscanf(STDIN, "%d", $n);
$x = strlen($n) * 9;
for ($a = 1; $a < $n; $a *= 10) {
	$b = $n - $a;
	$s = array_sum(str_split($a . $b));
	if ($s < $x) $x = $s;
}
echo $x;

Measured memory_bytes: 4732
// Problem : C - Skill Up
// Contest : AtCoder - AtCoder Beginner Contest 167
// URL : https://atcoder.jp/contests/abc167/tasks/abc167_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define db long double
#define pb push_back
#define pii pair<int,int>
#define vi vector<int>
#define vl vector<ll>
#define vii vector<pii>
#define mi map<int,int>
#define ml map<ll,ll>
#define mii map<pii,int>
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define sz(x) (int)x.size()
#define mod 1000000007
#define MAX 4294967295
#define EPS 1e-9
#define io ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define MAXN 15000005
#define inf 1e10
#define PI acos(-1.0)
#define int long long

int c[13],a[13][13],n,m,x;

signed main(){
    io;
    //freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
    cin>>n>>m>>x;
    int cost = inf;
    for(int i=0;i<n;i++){
        cin>>c[i];
        for(int j=0;j<m;j++) cin>>a[i][j];
    }
    for(int mask=0;mask<(1<<12);mask++){
        int cur_cost = 0, skill[13]={};
        for(int i=0;i<n;i++){
            if(mask&(1<<i)){
                cur_cost += c[i];
                for(int j=0;j<m;j++) skill[j] += a[i][j];
            }
        }
        bool ok = true;
        for(int i=0;i<m;i++) if(skill[i]<x) ok = false;
        if(ok) cost = min(cost,cur_cost);
    }
    if(cost == inf) cout<<-1<<endl;
    else cout<<cost<<endl;
    return 0;
}


Measured memory_bytes: 3612
def get_i() #空白区切の入力を数値(整数)の配列で返す
  return gets.chomp.split(" ").map(&:to_i)
end
def get_f() #空白区切の入力を数値(実数)の配列で返す
  return gets.chomp.split(" ").map(&:to_f)
end
def get() #空白区切の入力を文字列の配列で返す
  return gets.chomp.split(" ")
end
def get_nsp() #入力されたものを一文字ずつに区切った文字列の配列で返す
  return gets.chomp.split("")
end
def yn_judge(bool,y="Yes",n="No") #boolに真偽を投げることで、trueならy、falseならnの値を出力する
  return bool ? y : n 
end
def array(size,n=1,init=nil) #nに配列の次元数、sizeに配列の大きさ、initに初期値を投げることでその配列を返す
  if n==1
    return Array.new(size){init}
  else
    return Array.new(n).map{Array.new(size){init}}
  end
end

class Edge
  attr_accessor:to,:from,:c
  def initialize(from,to,c)
    @to=to
    @from=from
    @c=c
  end
end

n,m=get_i
edges=array(m,1)
m.times do|i|
  a,b,c=get_i
  a-=1
  b-=1
  c*=-1
  edges[i]=Edge.new(a,b,c)
end

INF=Float::INFINITY
d=array(n,1,INF)
d[0]=0
flag=array(n,1,false)
n.times do|i|
  m.times do|j|
    e=edges[j]
    if d[e.to]>d[e.from]+e.c
      d[e.to]=d[e.from]+e.c
    end
  end
end
n.times do|i|
  m.times do|j|
    e=edges[j]
    if d[e.to]>d[e.from]+e.c
      d[e.to]=d[e.from]+e.c
      flag[e.from]=true
    end
    flag[e.to]=true if flag[e.from]
  end
end
if flag[n-1]
  puts "inf"
else
  puts d[n-1]*-1
end

Measured memory_bytes: 3836
#include<iostream>
using namespace std;
int main(){
    int ans;
    int A, B;
    cin >> A >> B;
    if(A > B) ans = 2 * A - 1;
    if(A == B) ans = A + B;
    if(A < B) ans = 2 * B - 1;
    cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(k,i,n) for(ll i=k;i<n;++i)
int main(void){
    double a,b,h,m;
    cin>>a>>b>>h>>m;
    double the=abs(2.*M_PI*(h+m/60.)/12-2.*M_PI*(m)/60.);
    cout<<fixed<<setprecision(10)<<sqrt(a*a+b*b-2*a*b*cos(the));
    
}


Measured memory_bytes: 4152
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using namespace std::string_literals;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

constexpr ll MOD = 1000000007;

ll fact[200001];
ll factinv[200001];

// a^-1 mod p
ll inv(ll a,ll p){
  return ( a == 1 ? 1 : (1 - p*inv(p%a,a)) / a + p );
}

ll comb(ll n, ll k) {
  return fact[n] * factinv[k] % MOD * factinv[n-k] % MOD;
}

int main() {
  fact[0] = 1;
  for(auto&& i:irange(0,200000)) {
    fact[i+1] = fact[i] * (i+1) % MOD;
  }
  factinv[200000] = inv(fact[200000], MOD);
  for(auto&& i:irange(0,200000)) {
    int j = 199999-i;
    factinv[j] = factinv[j+1] * (j+1) % MOD;
  }
  ll h,w,a,b;
  cin>>h>>w>>a>>b;
  ll sum = 0;
  ll acc = 0;
  for(auto&& i:irange(0l,h)) {
    if (i + a < h) {
      ll x = b-1;
      ll y = i;
      acc += comb(x+y, x);
      acc %= MOD;
    }
    ll x = w-b-2;
    if (x >= 0) {
      ll y = h-i-1;
      sum += acc * comb(x+y, x) % MOD;
      sum %= MOD;
    } else if (i == h-1) {
      sum += acc;
    }
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 3328
N,M=map(int,input().split())
XYZ=[]
for i in range(M):
    X,Y,Z=map(int,input().split())
    XYZ.append([X,Y])

def find_root(root,x):
    y = root[x]
    if x == y:
        return x
    z = find_root(root,y)
    root[x] = z
    return z
 
def merge(root,size,x,y):
    x = find_root(root,x)
    y = find_root(root,y)
    if x == y:
        return
    sx,sy = size[x],size[y]
    if sx < sy:
        sx,sy = sy,sx
        x,y = y,x
    root[y] = x
    size[x] += sy
    
def UF_make(graph,n):
    Root=list(range(n+1))
    Size=[1] * (n+1)
    for i in range(len(graph)):
        merge(Root,Size,graph[i][0],graph[i][1])
    for i in range(n+1):
        Root[i] = find_root(Root,i)
    Root.pop(0)
    return Root

L=UF_make(XYZ,N)
print(len(set(L)))

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

int main(void) {
	int i, n;
	double val[1000];
	double m;
	double aa;
	while(scanf("%d\n", &n)==1) {
		if(n == 0)
			break;
		
		for(i=0,m=0;i<n;i++) {
			scanf("%lf", &val[i]);
			m += val[i];
		}
		scanf("\n");
		
		m /= n;	/* 平均 */
		for(i=0,aa=0;i<n;i++) {
			aa += ((val[i]-m)*(val[i]-m));
		}
		aa /= n;	/* 分散 */
		printf("%.8lf\n", sqrt(aa));
	}
	
	return 0;
}

Measured memory_bytes: 668
#include <algorithm>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <iomanip>
#include <iostream>
#include <string>
#include <vector>

typedef long long ll;
using namespace std;

int main() {
    int n = 0, k = 0;
    cin >> n >> k;
    int now = 1;
    for (int i=0; i<n; i++) {
        if (now*2 < now+k) {
            now *= 2;
        }
        else {
            now += k;
        }
    }
    cout << now << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Arrays;
import java.util.LinkedList;
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    
    int h = sc.nextInt();
    int w = sc.nextInt();
    int k = sc.nextInt();

    String[] c = new String[h];

    for(int i=0; i<h; i++){
      c[i] = sc.next();
    }
    
    int selection_row = 1 << h;
    int selection_col = 1 << w;
    int count = 0;

    for(int row=0; row<selection_row; row++){
      for(int col=0; col<selection_col; col++){

        int black = 0;

        for(int i=0; i<h; i++){
          for(int j=0; j<w; j++){
            int r = (1 << i) & row;
            int co = (1 << j) & col;
            if( r > 0 && co > 0 ){
              if(c[i].charAt(j) == '#')  black++;
            }

          }
        }

        if(black == k) count++;
      }
    }

    System.out.println(count);
  }
}

Measured memory_bytes: 36296
from collections import defaultdict
from collections import OrderedDict
N = int(input())
ans = dict()
for _ in range(N):
    k = str(input())
    if k in ans:
        ans[k]+=1
    else:
        ans.update({k:1})
groupedByValue = defaultdict(list)
for key, value in sorted(ans.items()):
    groupedByValue[value].append(key)
j = groupedByValue[max(groupedByValue)]
for i in j:
    print(i)

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

using namespace std;

int main(){
	int k,a,b;
	cin>>k>>a>>b;
	for(int i=a;i<=b;i++){
		if(i%k==0){
			cout<<"OK";	
			return 0;
		}
	}
	cout<<"NG";
	return 0;
}

Measured memory_bytes: 3636
#include "bits/stdc++.h"
using namespace std;

int keta(long long n){
  int c = 0;
  while(n){
    n /= 10;
    c++;
  }
  return c;
}

int main(){
  long long N;
  cin >> N;
  int min = 100;
  for(long long a = 1; a * a <=  N; a++){
    if((N % a) != 0) continue;
    long long b = N / a;
    /*
    int ka = keta(a);
    int kb = keta(b);
    if(ka > kb){
      if(ka < min){
        min = ka;
      }
    }else{
      if(kb < min){
        min = kb;
      }
    }
    */
    int c = max(keta(a), keta(b));
    if(c < min){
      min = c;
    }
  }
  cout << min << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <math.h>
typedef long long ll;
#define rep(i,n) for(ll i=0;i<n;++i)
#define REP(i,k,n) for(ll i=k;i<=n;++i)
const ll MOD=1e9+7;

int main(){
    ll x;
    std::cin >> x;
    REP(a,-120,120){
        REP(b,-120,120){
            if(pow(a,5)-pow(b,5)==x){
                std::cout << a << " " << b << std::endl;
                return 0;
            }
        }
    }
    return 0;
}


Measured memory_bytes: 4052
#include <iostream>
#include <vector>
#include <math.h>
#include <algorithm>
using namespace std;
int main() {
  int n; cin >> n;
  vector<int> a(n, 0);
  for (int i=0; i<n; i++) cin >> a.at(i);
  sort(a.begin(), a.end());
  int r=1;
  for (int i=a.at(1); i>0; i--) {
    int s = 0;
    for (int j=0; j<n; j++) {
      if (a.at(j) % i != 0) {
        s++;
        if (s==2) break;
      }
    }
    if (s<=1) {r=i; break;}
  }
  cout << r << endl;
}

Measured memory_bytes: 640
def main():
    n, x, y = map(int, input().split())
    x -= 1
    y -= 1
    ans = [0]*(n-1)
    for i in range(n):
        for j in range(i+1, n):
            if i < x and y < j:
                dist = j-i-(y-x)+1
            elif j < x or y < i:
                dist = j-i
            elif i <= x and j <= y:
                dist = min(j-i, x-i+1+y-j)
            elif x <= i and y <= j:
                dist = min(j-i, j-y+1+i-x)
            else:
                dist = min(j-i, y-x-(j-i)+1)
            ans[dist-1] += 1
    for i in ans:
        print(i)


main()


Measured memory_bytes: 3444
#include <bits/stdc++.h>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define NMAX 52
using namespace std;
int N, x, y, i, j, guess, sol = -1, K;
vector <pair <int, int> > Guesses[16];
int main() {
    cin >> N;
    for (int i = 0; i < N; ++i) {
        cin >> K;
        for (int j = 0; j < K; ++j) {
            cin >> x >> y;
            Guesses[i].pb({x - 1, y});
        }
    }
    for (guess = 0; guess < (1 << N); ++guess) {
        bool OK = 1;
        int cnt = 0;
        for (int i = 0; i < N && OK; ++i) {
            int ok = 0;
            if ((1 << i) & guess) {
                ++ cnt;
                for (auto pe : Guesses[i] ) {
                    if ( ((1 << pe.first) * pe.second) ^ (guess  & (1 << pe.first)  )) ok = 1;
                }
                if (ok == 1) OK = 0;
            }
            else {
                for (auto pe : Guesses[i]) {
                    if ( ((1 << pe.first) * pe.second) ^ (guess  & (1 << pe.first)  )) ok = 1;
                }
                if (ok == 0) OK = 0;
            }
        }
        if (OK) {
            sol = max(sol, cnt);
        }
    }
    cout << sol;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; ++i)

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

int ave=0;
if((a+b)%2==0) cout<<(a+b)/2<<endl;
else cout<<((a+b)/2)+1<<endl;
return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int n,a[10000],m,M,i=0;
	long s=0;

	scanf("%d",&n);
	while(i<n){
		scanf("%d",&a[i]);
		i++;
	}
	i=0;	
	m=a[0];
	M=a[0];
	while(i<n){
		if(m>a[i]) m=a[i];
		if(M<a[i]) M=a[i];
		s=s+a[i];
		i++;
	}
	printf("%d %d %ld\n",m,M,s);
	return 0;
}

Measured memory_bytes: 636
import collections
n = int(input())
s=input()
l=list(collections.Counter(s).values())
if len(l) == 3:
    ans=l[0]*l[1]*l[2]
    for i in range(n):
        for j in range(i+1,n):
            k = 2*j-i
            if n <= k:
                break
            if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
                ans-=1
    print(ans)
else:
    print(0)


Measured memory_bytes: 9468
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
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 print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,K;
    cin >> N >> K;
    if(K > (N-1) * (N-2) / 2){
        print(-1);
        return 0;
    }
    vector<lpair> ans;
    rep(i,0,N-1){
        ans.push_back(make_pair(1, i+2));
    }
    ll v = (N-1) * (N-2) / 2 - K;
    ll cnt = 0;
    bool flg = true;
    rep(stride, 1, N-1){
        rep(num,0,N-2-stride + 1){
            if(cnt >= v){
                flg = false;
                break;
            }
            ans.push_back(make_pair(num+2, num+2+stride));
            cnt++;
        }
        if(not flg) break;
    }
    print(ans.size());
    rep(i,0,ans.size()){
        cout << ans[i].first << " " << ans[i].second << endl;
    }


}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <unordered_map>
using namespace std;

class Problem
{
private:
	// Variables
	int n, k;
	vector<int> x, y;
	vector<char> c;
	int ans;
public:
	// Methods
	void input ()
	{
		cin >> n >> k;

		x.resize(n);
		y.resize(n);
		c.resize(n);
		int k2 = k * 2;
		for (int i=0; i<n; ++i) {
			cin >> x[i] >> y[i] >> c[i];
			x[i] %= k2;
			y[i] %= k2;
		}
	}
	
	void add(vector<vector<int>>&counts, int x, int y) {
		++counts[2*k+x][2*k+y];
		--counts[3*k+x][2*k+y];
		--counts[2*k+x][3*k+y];
		++counts[3*k+x][3*k+y];
	}
	void process ()
	{
		// ...###  |       |        |+-
		// ...###  |       |        |     
		// ...###  |-   *  |- +  -  |     
		// ###...  |       |        |-*
		// ###...  |       |        |  #  
		// ###...  |+   -  |+#-  +  |+-   

		int k2 = k * 2;
		int k3 = k * 3;
		int k4 = k2 * 2;
		int k7 = k * 7;
		vector<vector<int>> counts(k7);
		for (int i=0; i<k7; ++i) {
			counts[i].resize(k7, 0);
		}
		for (int i=0; i<n; ++i) {
			if ('B' == c[i]) {
				add(counts, -x[i], -y[i]);
				add(counts, k2-x[i], -y[i]);
				add(counts, -x[i], k2-y[i]);
				add(counts, k-x[i], k-y[i]);
                add(counts, k3-x[i], k-y[i]);
				add(counts, k2-x[i], k2-y[i]);
                add(counts, k-x[i], k3-y[i]);
                add(counts, k3-x[i], k3-y[i]);
			} else {
				add(counts, k-x[i], -y[i]);
                add(counts, k3-x[i], -y[i]);
				add(counts, -x[i], k-y[i]);
				add(counts, k2-x[i], k-y[i]);
				add(counts, k-x[i], k2-y[i]);
                add(counts, k3-x[i], k2-y[i]);
                add(counts, -x[i], k3-y[i]);
                add(counts, k2-x[i], k3-y[i]);
			}
		}


		for (int i=0; i<k7; ++i) {
			for (int j=1; j<k7; ++j) {
				counts[i][j] += counts[i][j-1];
			}
		}
		for (int j=0; j<k7; ++j) {
			for (int i=1; i<k7; ++i) {
				counts[i][j] += counts[i-1][j];
			}
		}

		ans = 0;
		for (int i=k2; i<k4; ++i) {
			for (int j=k2; j<k4; ++j) {
				ans = max(ans, counts[i][j]);
			}
		}
		

		// for (int dy=0; dy<k2; ++dy)
		// for (int dx=0; dx<k2; ++dx) {
		// 	int count = 0;
		// 	for (int i=0; i<n; ++i) {
		// 		int a = ((x[i] + dx) % k2) / k;
		// 		int b = ((y[i] + dy) % k2) / k;
		// 		if ((0 == a && 0 == b) || (1 == a && 1 == b)) {
		// 			if ('B' == c[i]) {
		// 				++count;
		// 			}
		// 		} else {
		// 			if ('W' == c[i]) {
		// 				++count;
		// 			}
		// 		}
		// 	}
		// 	ans = max(ans, count);
		// }
	}
	
	void output ()
	{
		cout << ans << endl;
	}
};

int main ()
{
	Problem problem;
	problem.input();
	problem.process();
	problem.output();
	return 0;
}


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

string S; long long dp[100009][2], mod = 1000000007;

int main() {
	cin >> S;
	dp[0][1] = 1;
	for (int i = 0; i < S.size(); i++) {
		if (S[i] == '0') {
			dp[i + 1][0] += dp[i][0];
			dp[i + 1][0] += dp[i][0] * 2LL;
			dp[i + 1][1] += dp[i][1];
			dp[i + 1][0] %= mod;
			dp[i + 1][1] %= mod;
		}
		if (S[i] == '1') {
			dp[i + 1][0] += dp[i][0];
			dp[i + 1][0] += dp[i][0] * 2LL;
			dp[i + 1][0] += dp[i][1];
			dp[i + 1][1] += dp[i][1] * 2LL;
			dp[i + 1][0] %= mod;
			dp[i + 1][1] %= mod;
		}
	}
	cout << (dp[S.size()][0] + dp[S.size()][1]) % mod << endl;
	return 0;
}

Measured memory_bytes: 2176
#lower
#横に積み木のsブロックがいくつか並んで積み上げられている。その中の任意の一つに降りてもし右が同じか低ければ移動できる。
#与えられた条件の中で最大に移動できるマスは何マスでしょうか
num = int(input())
#積み木の横列
line = input().split(" ")
step = 0
ans = 0
for n,i in enumerate(line):
    #積み木の列について、とりあえずひとつづつ確かめて、ぶつかったら（移動できないなら）次のマスからまた移動しなおす！！！！！！
    stand_area = n
    next_area = n + 1
    if n == (len(line) -1):
        break
    stand_height = int(i)
    next_height = int(line[next_area])
    if stand_height >= next_height:
        step += 1
    else:
        step = 0
    if step >= ans:
        ans = step     
print(ans)

Measured memory_bytes: 11132
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
int f[101010],g[101001];
int main()
{
	int ans,n,i,x,mx1,mx2,pl1,pll1,mxx1,mxx2;
	scanf("%d",&n);
	for(i=1;i<=n;i++)
	{
		scanf("%d",&x);
		if(i&1)
			f[x]++;
		else
			g[x]++;
	}
	mx1=mx2=mxx1=mxx2=0,pl1=pll1=0;
	for(i=1;i<=100000;i++)
	{
		if(f[i]>mx1)
		{
			mx2=mx1;
			mx1=f[i];
			pl1=i;
		}
		else if(f[i]>mx2)
			mx2=f[i];
		if(g[i]>mxx1)
		{
			mxx2=mxx1;
			mxx1=g[i];
			pll1=i;
		}
		else if(g[i]>mxx2)
			mxx2=g[i];
	}
//	printf("%d %d\n",pl1,pll1);
	if(pl1==pll1)
		ans=min(n-mx1-mxx2,n-mx2-mxx1);
	else
		ans=n-mx1-mxx1;
	printf("%d\n",ans);
	//freopen(".in","r",stdin);
	//freopen(".out","w",stdout);
 	return 0;
}


Measured memory_bytes: 1024
from collections import Counter 

n,k,q = map(int,input().split())
a_inputs = [int(input())-1 for i in range(q)]

a_dic = Counter(a_inputs)

score_li = [k]*n
for key,value in a_dic.items():
    score_li[key]+=value
score_li = list(map(lambda x:x-q,score_li))

for member in score_li:
    if member<=0:
        print('No')
    else:
        print('Yes')



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

using ll = long long;
using P = pair<ll, ll>;

const ll MOD = 1e9+7;
// const ll MOD = 998244353;
const ll INF = 1ll<<60;

#define FOR(i,a,b) for (ll i=(a);i<(ll)(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define DEBUG(x) std::cerr << #x << " : " << (x) << std::endl;
//#define DEBUG(x) ;

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

int main(int argc, char **argv)
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll N; cin >> N;
	vector<ll> d(N); REP(i, N) cin >> d[i];

	ll res{0}	;
	REP(i, N-1)
	{
		for (ll j = i + 1; j < N; ++j)
		{
			res += d[i] * d[j];
		}
	}

	std::cout << res << std::endl;
	
	return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define LL long long
#define MOD 1000000007
#define fastio                    \
    ios_base::sync_with_stdio(0); \
    cin.tie(0);                   \
    cout.tie(0)

using namespace std;

int main()
{
    fastio;
    // ifstream f("f.txt");
    // ofstream g("out.txt");
    int n, x, t, sum = 0, ans = 0;
    cin >> n >> x >> t;
    while (sum < n)
    {

        sum += x;
        ans += t;
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>
#define MAX 2000000

int H,A[MAX+1];

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

  if(l<=H && A[l]>A[i]) largest=l;
  else largest=i;
  if(r<=H && A[r]>A[largest]) largest=r;

  if(largest!=i)
    {
      t=A[i];
      A[i]=A[largest];
      A[largest]=t;
      maxHeapify(largest);
    }
}

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

  for(i=H/2;i>=1;i--)
    {
      maxHeapify(i);
    }

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

  return 0;
}
      



Measured memory_bytes: 3692
def main():
    [N, K] = [int(num) for num in input().split()]
    h_list = [int(h) for h in input().split()]
    cost = [0] * N
    cost[1] = abs(h_list[1] - h_list[0])

    for i in range(2, N):
        min_cost = 10**10
        for j in range(1, min(K, i)+1):
            min_cost = min(min_cost, cost[i-j] + abs(h_list[i] - h_list[i-j]))

        cost[i] = min_cost


    print(cost[N-1])


if __name__ == '__main__':
    main()


Measured memory_bytes: 52448
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <algorithm>
#include <stdio.h>
#include <cstring>
#include <iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <numeric>

//#include <map>

using namespace std;

int main()
{
	int r, c;
	cin >> r >> c;

	vector<vector<int>> vsh;
	for (int i = 0; i < r; i++)
	{
		vector<int> vt;
		for (int j = 0; j < c; j++)
		{
			int t;
			cin >> t;
			vt.push_back(t);
		}
		vsh.push_back(vt);
	}

	for (int i = 0; i < r; i++)
	{
		int sumr = 0;
		for (int j = 0; j < c; j++)
		{
			cout << vsh.at(i).at(j) << " ";
			sumr += vsh.at(i).at(j);
		}
		vsh.at(i).push_back(sumr);
		cout << sumr << endl;
	}

	for (int i = 0; i < c + 1; i++)
	{	
		int sumc = 0;
		for (int j = 0; j < r; j++)
		{
			sumc += vsh.at(j).at(i);
		}
		cout << sumc;
		if (i < c)
		{
			cout << " ";
		}
	}
	cout << endl;

	return 0;
}

Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
#define max1 1000000007

int main()
{  int n;
cin>>n;
double p[n];
for(int i=0;i<n;i++)
{
    cin>>p[i];
}
	double arre[n+1];
	for(int i=0;i<=n;i++)
	{
	    if(i==0)
	    {
	        arre[0]=1;
	       
	    }
	    if(i!=0)
	    {
	      arre[i]=arre[i-1]*(1.0-p[i-1]);
	    }
	}
	double arro[n+1];
	double ans=0.0;
	for(int i=1;i<=n;i++)
	{  if(i%2==1)
	   { arro[i]=p[i-1]*arre[i-1];
	    for(int j=i+1;j<=n;j++)
	    {
	       arro[j]=(arro[j-1]*(1.0-p[j-1])+arre[j-1]*p[j-1]);
	    }
	    if(i>n/2)
	    {
	        ans+=arro[n];
	    }
	   }
	   else
	   {
	       arre[i]=arro[i-1]*p[i-1];
	       for(int j=i+1;j<=n;j++)
	       {
	           arre[j]=(arre[j-1]*(1.0-p[j-1])+arro[j-1]*p[j-1]);
	       }
	       if(i>n/2)
	       {
	           ans+=arre[n];
	       }
	       
	   }
	}

	
    cout<<setprecision(10)<<ans<<"\n";
}


Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <cmath>
#include <utility>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <cstring>
#include <climits>
#include <iomanip>

#define EPS 1e-7
#define LLMAX 9223372036854775807
#define INTMAX 2147483647
#define ULLMAX 18446744073709551615
#define precision(n) cout << setprecision(n) << fixed
#define forn(i, n) for (int i = 0; i<(int)n; ++i)
#define forr(i, t, n) for (int i = t; i<n; ++i)
#define rforr(i, t, n) (int i = n-1; i>=t; --i)
#define rfor(i, n) for (int i = n-1; i>=0; --i)
#define rmod(x, y) (((x%y)+y)%y)
#define pb push_back
#define emp emplace_back
using namespace std;
typedef vector<int>::iterator vit;
typedef unsigned int uint;
typedef unsigned short ushort;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
const int MAXN = 1024;

//STRUCTS


//OPERATORS


//GLOBALS


//FUNCTIONS


//PROBLEM: 
//LINK: 
int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);

		int a, b;
		cin >> a >> b;
		if (b*2 >= a) cout << 0;
		else
		{
			cout << a-(2*b);
		}
	
	return 0;
}

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

struct node{
  struct node *right;
  struct node *left;
  struct node *p;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){


}

Node treeMaximum(Node x){


}

Node treeSearch(Node u, int k){


}

Node treeSuccessor(Node x){


}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y



}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x!=NIL){
    y=x;
    if(z->key < x->key)x=x->left;
    else x=x->right;
  }
  z->p=y;

  if(y==NIL)root=z;
  else if(z->key < y->key)y->left=z;
  else y->right=z;

}

void inorder(Node u){
  if (u==NIL)return;

  inorder(u->left);
  printf(" %d",u->key);
  inorder(u->right);

}
void preorder(Node u){
if (u==NIL)return;

 printf(" %d",u->key);
 preorder(u->left);
 preorder(u->right);

}


int main(){
  int n, i, x;
  char com[20];
  Node t;
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
       t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 24040
import numpy as np
N = int(input())
a = np.array(list(map(int,input().split())))
b = a[a<0]
if len(b)%2==0:
    print(int(sum(np.abs(a))))
else:
    print(int(sum(np.abs(a))-2*min(np.abs(a))))


Measured memory_bytes: 23308
#include<stdio.h>
int main(){
int a,b,i;char c[12],d[12],e[12];
scanf("%s%s%d%d%s",c,d,&a,&b,&e);
for(i=0;i<12;i++){if(d[i]!=e[i]){printf("%d %d",a-1,b);break;}
if(c[i]!=e[i]){printf("%d %d",a,b-1);break;}} 
}


Measured memory_bytes: 1736
#include <iostream>

using namespace std;

#define MAX 100005
#define NIL -1

struct Node{
    int p, l, r;
};

Node T[MAX];
int n, D[MAX];

void print(int u){
    cout << "node " << u << ": ";
    cout << "parent = " << T[u].p << ", ";
    cout << "depth = " << D[u] << ", ";
    
    if( T[u].p == NIL){
        cout << "root, "; 
    }
    else if(T[u].l == NIL){
        cout << "leaf, ";
    }
    else cout << "internal node, ";   
    
    cout << "[";
    
    for(int i = 0, c = T[u].l; c != NIL; i++, c = T[c].r){
        if(i) cout << ", ";
        cout << c;
    }
    cout << "]" << endl;
}

void rec(int u, int p){
    D[u] = p;
    if(T[u].r != NIL)rec(T[u].r, p);
    if(T[u].l != NIL)rec(T[u].l, p + 1);
}

int main(void){
    // Your code here!
    int i, j, d, v, c, l, r;
    cin >> n;
    for(i = 0; i < n; i++)T[i].p = T[i].l = T[i].r = NIL;
    
    for(i = 0; i < n; i++){
        cin >> v >> d;
        for( j = 0; j < d; j++){
            cin >> c;
            if(j == 0)T[v].l = c;
            else T[l].r = c;
            l = c;
            T[c].p = v;
        }
    }
    for(i = 0; i < n; i++){
        if(T[i].p == NIL){
            r = i;
        }
    }
    rec(r, 0);
    
    for(i = 0; i < n; i++){
        print(i);
    }
    
    return 0;
}


Measured memory_bytes: 7712
function Main(input) {
  input = input.split("\n");
  var N = parseInt(input[0]);
  var h = input[1].split(" ").map(i => parseInt(i));
  var a = input[2].split(" ").map(i => parseInt(i));
  for(var i=0;N/Math.pow(2,i)>0.5;i++){
    var x = i;
  }
  var n = Math.pow(2,x);
  var dp = new Array(Math.pow(2,x)*2-1).fill(0);
  function query(a,b,k,l,r){
    if(r<=a||b<=l){
      return 0;
    }else if(a<=l&&r<=b){
      return dp[k];
    }else{
      var vl=query(a,b,k*2+1,l,(l+r)/2);
      var vr=query(a,b,k*2+2,(l+r)/2,r);
      return Math.max(vl,vr);
    }
  }
  function update(i,x){
    i+=n-1;
    dp[i]=x;
    while(i>0){
      i=Math.floor((i-1)/2);
      dp[i]=Math.max(dp[i*2+1],dp[i*2+2]);
    }
  }
  //dp[h[0]]=a[0];
  var ans=0;
  for(var i=0;i<N;i++){
    var max=0;
    max=query(0,h[i]-1,0,0,n);
    update(h[i]-1,max+a[i]);
    ans=Math.max(ans,max+a[i]);
  }
  console.log('%s', ans);
  return ans;
}
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 73764
import sys
import itertools
import numpy
input = sys.stdin.readline
N,K = [int(i) for i in input().split()]
li = [int(i) for i in input().split()]
mina = 10000000001
for i in range(N-K+1) :
    ll = abs(li[i])
    lr = abs(li[i+K-1])
    if li[i] * li[i+K-1] > 0 :
        l = max(ll,lr)
    else :
        if ll >= lr :
            l = lr * 2 + ll
        else :
            l = ll * 2 + lr
    mina = min(mina,l)
print(mina)

Measured memory_bytes: 23056
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    ll ts = 1, as = 1;
    for (int i = 0; i < n; i++) {
        ll t, a; cin >> t >> a;
        if (ts % t != 0) ts = ((ts + t) / t) * t;
        if (as % a != 0) as = ((as + a) / a) * a;
        if (ts / t > as / a) as = ts / t * a;
        else if (ts / t < as / a) ts = as / a * t;
    }
    cout << ts + as << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5 + 10;
int n;
ll k;
int a[maxn], vis[maxn];
int main()
{
	scanf("%d%lld", &n, &k);
	for(int i = 1; i <= n; ++i) scanf("%d", &a[i]);
	int i, j;
	memset(vis, -1, sizeof vis);
	for(i = 1, j = 0; vis[i] == -1; i = a[i], ++j)
	{
		vis[i] = j;
		if(j == k)
		{
			cout << i << endl;
			return 0;
		}
	}
	int c = j - vis[i];
	k = (k - vis[i]) % c;
	while(k)
	{
		--k;
		i = a[i];
	}
	cout << i << endl;
	return 0;
}
	
		

Measured memory_bytes: 5260