akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define all(v) v.begin(),v.end()
using namespace std;
using ll=long long;
#ifdef ONLINE_JUDGE
#define D(...)
#else
#define D(...)cerr<<__LINE__<<":"<<"["<<#__VA_ARGS__<<"]->",P(__VA_ARGS__)
#endif
void P(){cerr<<endl;} 
template<typename H,typename...T>void P(H h,T...t){cerr<<h<<" ";P(t...);}
int main()
{
    ios::sync_with_stdio(false);cin.tie(0);
    int x1,y1,x2,y2,x3,y3,x4,y4;
    cin>>x1>>y1>>x2>>y2;
    x2-=x1;y2-=y1;
    x4=-y2;y4=x2;
    x3=(x2+x4);
    y3=(y2+y4);
    cout<<x3+x1<<" "<<y3+y1<<" "<<x4+x1<<" "<<y4+y1;
    
}

Measured memory_bytes: 3636
splitline()=split(readline())
parseInt(x)=parse(Int,x)

function main()
    n = parseInt(readline())
    a = map(parseInt, split(readline()))

    ans = 0
    for i in 1:n
        while a[i]%2 == 0
            a[i] /= 2
            ans += 1
        end
    end

    println(ans)
end

main()


Measured memory_bytes: 133124
#include <bits/stdc++.h>
#include <iostream>
#include <algorithm>
#include <ctype.h>
#include <math.h>
#include <stack>
#include <string>
#include <string.h>
using namespace std;
double PI = 3.1415926535897932;
long mod = 1000000007;

const long INF = 1e9 + 1;

int main() {
  string s;
  cin >> s;
  for(int i = 0; i < s.size(); i++) {
    if(i % 2 == 0) {
      if(!(s[i] == 'R' | s[i] == 'U' | s[i] == 'D')) {
        cout << "No" << endl;
        return 0;
      }
    }
    else {
      if(!(s[i] == 'L' | s[i] == 'U' | s[i] == 'D')) {
        cout << "No" << endl;
        return 0;
      }
    }
  }
  
  cout << "Yes" << endl;  
}

Measured memory_bytes: 3624
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
//#include <stdio.h>
#include <cstdio>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { std::cerr << std::endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	std::cerr << " " << h;
	if (sizeof...(t) > 0)std::cerr << " :";
	debug_out(t...);
}
int ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = INF;
vl flag, color, D; vll path;
//***********//
int main() {
	ll A, B;
	cin >> A >> B;
	debug(A,B);
	cout << (A - 1) * (B - 1);
}

Measured memory_bytes: 256
#!/usr/bin/python3
# -*- coding: utf-8 -*-

import sys
from math import sqrt

def rl(proc=None):
    if proc is not None:
        return proc(sys.stdin.readline())
    else:
        return sys.stdin.readline().rstrip()

def srl(proc=None):
    if proc is not None:
        return list(map(proc, rl().split()))
    else:
        return rl().split()

def dist(a, b):
    r = 0
    for i in range(len(a)):
        d = a[i] - b[i]
        r += d * d
    return r

def issq(d):
    c = int(sqrt(d))
    return c * c == d or (c+1) * (c+1) == d

def main():
    N, D = srl(int)
    A = []
    for _ in range(N):
        A.append(srl(int))
    c = 0
    for i in range(N):
        for j in range(i+1, N):
            if issq(dist(A[i], A[j])):
                c += 1
    print(c)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
#include <string>

std::string S;

int main(int argc, char const* argv[])
{
    std::cin >> S;
    std::sort(S.begin(), S.end());
    if (S[0] == S[1] && S[2] == S[3] && S[0] != S[2]) {
        std::cout << "Yes" << std::endl;
    }
    else {
        std::cout << "No" << std::endl;
    }
    return 0;
}


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

int main() {
    int N;
    int top[100], bottom[100];
    cin >> N;
    for (int i = 0; i < N; i++) {
        int t;
        cin >> t;
        if (i == 0) {
            top[i] = t;
        } else {
            top[i] = t + top[i-1];
        }
    }
    for (int i = 0; i < N; i++) {
        int t;
        cin >> t;
        if (i == 0) {
            bottom[i] = t;
        } else {
            bottom[i] = t + bottom[i-1];
        }
    }
    int max = 0;
    for (int i = 0; i < N; i++) {
        int t;
        if (i == 0) {
            t = top[i] + bottom[N-1];
        } else {
            t = top[i] + (bottom[N-1]-bottom[i-1]);
        }
        max = (max < t) ? t : max;
    }
    cout << max << endl;
    return 0;
}
        
        
    


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

using namespace std;

int main()
{
  int N; cin >> N;
  vector<int> team(N, 0);
  for(int i = 0; i < N*(N-1)/2; i++){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    --a, --b;
    if(c > d) team[a] += 3;
    else if(c < d) team[b] += 3;
    else team[a]++, team[b]++;
  }
  vector<int> score;
  for(int i = 0; i < N; i++) score.push_back(-team[i]);
  sort(score.begin(), score.end());
  for(int i = 0; i < N; i++){
    cout << lower_bound(score.begin(), score.end(), -team[i]) - score.begin() + 1 << endl;
  }
  return 0;
}

Measured memory_bytes: 1220
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]

k, x = ril()
if k * 500 >= x:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 3064
N = int(input())
s = input()
def stoi(s):
    return ord(s)-97
X = [1] * 26
for ss in s:
    X[stoi(ss)] += 1

ans = 1
P = 10**9+7
for x in X:
    ans *= x
    ans %= P
print((ans - 1) % P)


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

def make_divisors(n):
    lower_divisors , upper_divisors = [], []
    i = 1
    while i*i <= n:
        if n % i == 0:
            lower_divisors.append(i)
            if i != n // i:
                upper_divisors.append(n//i)
        i += 1
    return lower_divisors + upper_divisors[::-1]

ans=0

for i in range(1,n+1):
  if i % 2 == 1:
    l=make_divisors(i)
    if len(l)==8:
      ans+=1

print(ans)

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int main(){
    int n,m;
    while(scanf(" %d %d", &n, &m),n){
        vector<int> mx(n),mn(n);
        rep(i,m){
            int s,k;
            scanf(" %d %d", &s, &k);

            rep(j,k){
                int c;
                scanf(" %d", &c);
                --c;

                mx[c] += s;
                if(k==1) mn[c] +=s;
            }
        }

        multiset<int> s;
        rep(i,n) s.insert(mn[i]);

        int ans = 0;
        rep(i,n){
            s.erase(s.find(mn[i]));
            int MN = *s.begin();
            ans = max(ans, mx[i]-MN);
            s.insert(mn[i]);
        }
        cout << ans+1 << endl;
    }
    return 0;
}



Measured memory_bytes: 3492
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        int s = sc.nextInt();
        int w = sc.nextInt();

        String result = "unsafe";
        if (s > w) {
            result = "safe";
        }

        System.out.println(result);
    }
}

Measured memory_bytes: 27088
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
template<class T, class U> void init_n(vector<T>& v, size_t n, U x) 
{ v = vector<T>(n, x); }
template<class T> void init_n(vector<T>& v, size_t n) { init_n(v, n, T()); }
template<class T> void read_n(vector<T>& v, size_t n, size_t o = 0) 
{ v = vector<T>(n+o); for (lli i=o; i<n+o; ++i) cin >> v[i]; }
template<class T> T gabs(const T& x) { return max(x, -x); }
#define abs gabs

lli n, m;
vector<vector<lli>> v;

vector<lli> ts, ti, p;

void tsort_dfs(lli i, vector<bool>& vi) {
  if (vi[i]) return;
  vi[i] = true;
  for (lli to : v[i]) {
    tsort_dfs(to, vi);
  }
  ts.push_back(i);
}

void tsort() {
  vector<bool> vi(n+1, false);
  for (lli i=1; i<=n; ++i) {
    tsort_dfs(i, vi);
  }
  reverse(begin(ts), end(ts));
}

int main() {
  cin >> n >> m;
  init_n(v, n+1);
  for (lli i=1; i<=n-1+m; ++i) {
    lli f, t; cin >> f >> t;
    v[f].emplace_back(t);
  }
  tsort();
  init_n(ti, n+1);
  ti[0] = -1;
  for (lli i=0; i<n; ++i) ti[ts[i]] = i;
  init_n(p, n+1, 0);
  for (lli i=1; i<=n; ++i) {
    for (lli to : v[i]) {
      if (ti[p[to]] <= ti[i]) p[to] = i;
    }
  }
  for (lli i=1; i<=n; ++i) cout << p[i] << endl;
  return 0;
}



Measured memory_bytes: 12020
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <string>
using namespace std;

int main()
{   
    int count =0;
    unordered_map<string,int> u;
    int n;
    cin>>n;
    vector<string> vec(n+1);
    for(int i = 0;i<n;i++){
        cin>>vec[i];
    }
    for(int i=0;i<n;i++){
        u[vec[i]]++;
    }
    for(auto x:u){
        if (x.second !=0)
            count++;
    }
    cout<<count;
}


Measured memory_bytes: 23984
from math import factorial

def comb(n, r):
  return factorial(n) / factorial(r) / factorial(n - r)


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

answer = 0

if N >= 2:
  answer += comb(N, 2)
else:
  answer += 0

if M >= 2:
  answer += comb(M, 2)
else:
  answer += 0

print(int(answer))

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

int main()
{
	int a,b,c,d,n=0;
	
	while(cin>>n)
	{
		a=n/1000;
		b=(n/100)%10;
		c=(n/10)%10;
		d=n%10;

		if(a+b+c+d==7)
		{
			cout<<a<<"+"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;


		}
		else if(a+b+c-d==7)
		{

				cout<<a<<"+"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;

				
		}
		else if(a+b-c+d==7)
		{

				cout<<a<<"+"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;

				
		}
		else if(a+b-c-d==7)
		{

				cout<<a<<"+"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;
	
		}
		else if(a-b+c+d==7)
		{

				cout<<a<<"-"<<b<<"+"<<c<<"+"<<d<<"=7"<<endl;

		}
		else if(a-b+c-d==7)
		{

				cout<<a<<"-"<<b<<"+"<<c<<"-"<<d<<"=7"<<endl;
	
		}
		else if(a-b-c+d==7)
		{

				cout<<a<<"-"<<b<<"-"<<c<<"+"<<d<<"=7"<<endl;

		}
		else if(a-b-c-d==7)
		{

				cout<<a<<"-"<<b<<"-"<<c<<"-"<<d<<"=7"<<endl;

		}


	}


	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int i,j,n[5],t;
  while(scanf("%d%d%d%d%d",&n[0],&n[1],&n[2],&n[3],&n[4])!=EOF){
    for(i=0;i<4;i++){
      for(j=0;j<4;j++){
        if(n[j]<n[j+1]){
          t=n[j];
          n[j]=n[j+1];
          n[j+1]=t;
        }
      }
    }
    printf("%d %d %d %d %d\n",n[0],n[1],n[2],n[3],n[4]);
  }
  return 0;
}

Measured memory_bytes: 596
a,b,c,d = gets.split.map(&:to_i)
if b <= c || d <= a then
    puts 0
elsif a <= c && d <= b then
    puts d-c
elsif c <= a && b <= d then
    puts b-a
elsif a <= c && b <= d then
    puts b-c
elsif c <= a && d <= b then
    puts d-a
end

Measured memory_bytes: 1788
N = int(input())

def cnt_keta(n):
  keta = 0
  while n > 0:
    n //= 10
    keta += 1
  return keta

ans = 0
for i in range(1, N+1):
  if cnt_keta(i) % 2 == 1:
    ans += 1
print(ans)

Measured memory_bytes: 9100
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順

int main() {
    int N,M;
    cin >> N >> M;
    map<int, int> MAP;
    rep(i, N) {
        int K;
        cin >> K;
        rep(j,K) {
            int A;
            cin >> A;
            MAP[--A]++;
        }
    }
    int res = 0;
    rep(i,M) {
        int A = MAP[i];
        if (A == N) res++;
    }
    cout << res << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
    #include <ext/pb_ds/assoc_container.hpp>
    #include <ext/pb_ds/tree_policy.hpp>
    #include <ext/pb_ds/detail/standard_policies.hpp>
 
    using namespace std;
    using namespace __gnu_pbds;
 
    #define endl "\n"
    #define fi first
    #define se second
    #define pb push_back
    #define int long long
    #define ll long long
    #define ld long double
    #define pii pair<ll,ll>
 
    #define read(t) ll t;cin>>t;
    #define all(x) x.begin(),x.end()
    #define f(a,b,c) for(ll a=b;a<c;a++)
    #define For(i,n) for(ll i=0;i<n;i++)
 
    #define what(x) cerr << #x << " is " << x << endl;
    #define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL) ;
 
    typedef tree<pair<ll,ll>, null_type,less<pair<ll,ll>>, rb_tree_tag,tree_order_statistics_node_update> omultiset;
    typedef tree<long long,null_type,less<long long>,rb_tree_tag,tree_order_statistics_node_update> oset;
    typedef tree<long long,null_type,greater<long long>,rb_tree_tag,tree_order_statistics_node_update> oset1;
 
/*.....................................................................................................................*/
 
    const ll mod=(ll)1e9+ 7;
 
    ll add(ll x,ll y) {return (x+y)%mod;}
    ll mult(ll x, ll y){return ((x%mod )* (y%mod)) % mod;}
 
    long long binpow(long long x, long long p) 
    {
        if (p == 0) {return 1;} 
    	if (p == 2 || (p & 1)) {return mult(x, binpow(x, p - 1));}
    	return binpow(binpow(x, p / 2), 2);
    }
    ll modinv(ll a) {return binpow(a,mod-2);}
 
    //A.erase(unique(A.begin(),A.end()),A.end());
    double pi=3.141592653589793238462641;
    ll dx[4]={1,-1,0,0},dy[4]={0,0,1,-1};
    const ll  man  =   (int)200005 ,  inf   =   1e18;
 
 
/*......................................................................................................................*/



signed main()
{
    fast;
    int n;
    cin>>n;
    map<string,int>mp;
    for(int i=0;i<n;i++)
    {
        string s;
        cin>>s;
        mp[s]++;
    }
    cout<<"AC x "<<mp["AC"]<<endl;
    cout<<"WA x "<<mp["WA"]<<endl;
    cout<<"TLE x "<<mp["TLE"]<<endl;
    cout<<"RE x "<<mp["RE"]<<endl;
}   

Measured memory_bytes: 3656
#include <iostream>
#include <map>

using namespace std;

int main(void){

  int n;
  while( cin >> n , n ){

    map<int,long long> m;
    bool isNA = false;

    while( n-- ){

      int id,price,num;
      cin >> id >> price >> num;

      if( m[id] < 1000000 && 1000000 <= m[id] + (long long)price*num ){
	cout << id << endl;
	isNA = true;
      }
      m[id] += (long long)price*num;
    }

    if(!isNA) cout << "NA" << endl;
  }
  return 0;
}

Measured memory_bytes: 1256
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
using namespace std;

int my_abs(int num){
   if (num > 0)
      return num;
   else
      return -num;
}

int main(){
    int W,A,B;
    cin >> W >> A >> B;
    int kyori;
    
    kyori = my_abs(B-A);

    if(kyori <= W){
        cout <<"0" << endl;
    }
    else{
        cout << kyori - W << endl;
    }
}

Measured memory_bytes: 256
#![allow(non_snake_case)]

#[allow(unused_macros)]
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, bytes) => { read_value!($next, String).into_bytes() }; ($next:expr, usize1) => { read_value!($next, usize) - 1 }; ($next:expr, $t:ty) => { $next().parse::<$t>().expect("Parse error") }; }

fn main() {
    input!{
        N: u32,
        Y: u32,
    }
    for i in 0..N + 1 {
        for j in 0..N + 1 - i {
            let k = N - i - j;
            if 10000 * i + 5000 * j + 1000 * k == Y {
                println!("{} {} {}", i, j, k);
                return;
            }
        }
    }

    println!("{}", "-1 -1 -1");
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
#include <vector>
#include <stdio.h>
#include <string>
int main(void){
    // Your code here!
    int N;
    cin >> N;
    string S;
    cin >> S;
    
    int ans = N;
    for(int i = 0; i < N - 1; i++){
        if (S.substr(i, 1) == S.substr(i + 1, 1)) ans -= 1;
    }
    cout << ans << endl;
    
}


Measured memory_bytes: 512
use std::vec::Vec;
use std::cmp::*;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
  let s: String = read();
  let r: String = s.chars().rev().collect();
  if s == r {
    println!("Yes");
  } else {
    println!("No")
  }
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<math.h>
using namespace std;
int main(){
	double xa,ya,ra,xb,yb,rb;
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>xa>>ya>>ra>>xb>>yb>>rb;
		double s=(xa-xb)*(xa-xb)+(ya-yb)*(ya-yb);
		s=(double)sqrt((double)s);
		int t=1;
		if(ra+s<rb)
			t=-2;
		if(rb+s<ra)
			t=2;
		if(s>ra+rb)
			t=0;
		cout<<t<<endl;
	}
	return 0;
}

Measured memory_bytes: 1232
#include<bits/stdc++.h>
using namespace std;
int main()
{
    map < string , int > mp;
    int n;
    scanf("%d",&n);
    int mx=0;
    while(n--)
    {
        string s;
        cin>>s;
        mp[s]++;
        mx=max(mx,mp[s]);
    }
    for(auto i : mp)
    {
        if(i.second==mx)
        {
            cout<<i.first<<endl;
        }
    }
    cout<<endl;
}


Measured memory_bytes: 25216
#include<bits/stdc++.h>
using namespace std ;
#define ll long long int 
#define pb push_back 
#define mp make_pair 
#define pii pair <int , int > 
#define pll pair < ll , ll >
vector <int > adj[200005] ;
int main(){
	ios_base::sync_with_stdio(false) ;
	cin.tie(NULL) ;
	int n , m ;
	cin >> n >> m ;
	
	for(int i = 0 ; i < n ; i++){
		int a , b ;
		cin >> a >> b ;
		if(a <= m)
			adj[a].pb(b) ;
	}
	ll ans = 0 ;
	priority_queue < int > pq ;
	for(int i = 1 ; i <= m ; i++){
		for(auto it : adj[i])pq.push(it) ;
		if(!pq.empty()){
			ans += pq.top() ;
			pq.pop() ;
		}
	}
	cout << ans ;
}

Measured memory_bytes: 8064
import sys
import math
input = sys.stdin.readline
N = int(input())
A,B = map(int,input().split())
P = list(map(int,input().split()))
p1 = []
p2 = []
p3 = []

for i in range(N):
    if P[i] <= A:
        p1.append(P[i])
    elif A < P[i] <= B:
        p2.append(P[i])
    else:
        p3.append(P[i])

p = min(len(p1),len(p2),len(p3))
print(p)


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

using namespace std;

int main(int argc, char *argv[]) {
	int A, B, C, D;
	cin >> A >> B >> C >> D;

	int l = A + B;
	int r = C + D;

	string answer;
	if (l == r) {
		answer = "Balanced";
	} else if (l > r) {
		answer = "Left";
	} else {
		answer = "Right";
	}

	cout << answer << endl;
	return 0;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define ALL(a)     (a).begin(),(a).end()
#define MOD 1000000007

typedef long long int ll;

const ll INF=(ll)1e18;
//const int INF=(1<<30);


int main(){
  string s;
  cin >> s;
  cout << s[0] << s.size()-2 << s[s.size()-1] << endl;
}



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

int main() {
    int x, ans;
    cin >> x;

    if ((x >= 400) && (x <= 599)) {
        ans = 8;
    } else if ((x >= 600) && (x <= 799)) {
        ans = 7;
    } else if ((x >= 800) && (x <= 999)) {
        ans = 6;
    } else if ((x >= 1000) && (x <= 1199)) {
        ans = 5;
    } else if ((x >= 1200) && (x <= 1399)) {
        ans = 4;
    } else if ((x >= 1400) && (x <= 1599)) {
        ans = 3;
    } else if ((x >= 1600) && (x <= 1799)) {
        ans = 2;
    } else if ((x >= 1800) && (x <= 1999)) {
        ans = 1;
    } 

    cout << ans << endl;
    return 0;
}

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

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

int main(void){
  long long A, B, C;
  scanf("%lld%lld%lld", &A, &B, &C);

  long long ans = 1e18;
  chmin(&ans, llabs((A/2)*B*C-(A-A/2)*B*C));
  chmin(&ans, llabs((B/2)*C*A-(B-B/2)*C*A));
  chmin(&ans, llabs((C/2)*A*B-(C-C/2)*A*B));

  printf("%lld\n", ans);

  return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    i64 r;
    cin >> r;

    cout << r * r << endl;

    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
using namespace std;
 


const long long mod = 1000000007;
long long dp[100005];

long long power(long long a, long long b)
{
    if (b == 0)
    {
        return 1LL;
    }
    if (b == 1)
    {
        return 1LL*a%mod;
    }
    if (b%2 == 0)
    {
        long long  x = power (a, b/2);
        x = (x*x)%mod;
        return x;
    }
    else if (b != 1 && b!= 0 && b%2 != 0)
    {
        long long  x = power(a, (b-1)/2);
        x = (x*x)%mod;
        return (x*a)%mod;
    }
}

int main()
{ 
    long long  n, k;
    cin >> n >> k;
    
    for (int i = k; i >= 1; i--)
    {
        dp[i] = power(k/i, n);
        for (int j = 2*i; j <= k; j+=i)
        {
            dp[i] = dp[i] - dp[j];
        }
    }

    long long ans = 0;
    for (int i = 1; i <= k; i++)
    {
        ans = (ans + (dp[i]*i)%mod)%mod;
    }

    cout << ans%mod;
    return 0;
    
}

Measured memory_bytes: 4408
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd(b,a%b);
  }
}
 
long long lcm(long long x, long long y){
  return (x/gcd(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};

int main(){
  int n;
  long long k;
  cin>>n>>k;
  long long a[n];
  long long g;
  long long m;
  REP(i,n){
    cin>>a[i];
    if(i==0){
      g = a[i];
      m = a[i];
    }else{
      g = gcd(g,a[i]);
      m = max(m,a[i]);
    }
  }
  if(k%g==0 && k<=m){
    cout<<"POSSIBLE"<<endl;
  }else{
    cout<<"IMPOSSIBLE"<<endl;
  }
  return 0;
}


Measured memory_bytes: 1024
n, A, B, k = list(map(int, input().split()))

MOD = 998244353
MAX = 3*10**5+2

fac = [0 for i in range(MAX)]
inv = [0 for i in range(MAX)]
ifac = [0 for i in range(MAX)]
fac[0] = 1; fac[1] = 1
inv[1] = 1
ifac[0] = 1; ifac[1] = 1

for i in range(2, MAX):
  fac[i] = fac[i-1]*i%MOD
  inv[i] = inv[MOD%i]*(MOD-MOD//i)%MOD
  ifac[i] = ifac[i-1]*inv[i]%MOD

def nCk(n, k):
  if n<k or n<0 or k<0: return 0
  return (((fac[n]*ifac[k])%MOD)*ifac[n-k])%MOD

ans = 0
for i in range(n+1):
  if (k-A*i)%B == 0:
    b = (k-A*i)//B
    if 0<=b<=n:
      ans = (ans+nCk(n, i)*nCk(n, b))%MOD

if ans==0:
  print(1)
else:
  print(ans)

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

#define int long long

using namespace std;
#define rep(i,s,n) for(int i = s;i<n;i++)
#define repe(i,s,n) for(int i = s;i<=n;i++)
#define pb push_back
#define fi first
#define se second
typedef long long ll;
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
static const ll maxLL = (ll)1 << 62;
const ll MOD=1000000007,INF=1e18;
int dy[]={-1,0,1,0};
int dx[]={0,1,0,-1};

int n,m,X,Y;
int x[100010],y[100010];

signed main(){
    cin>>n>>m>>X>>Y;
    rep(i,0,n){
        cin>>x[i];
    }
    sort(x,x+n);
    rep(i,0,m){
        cin>>y[i];
    }
    sort(y,y+m);
    if(min(Y,y[0])-max(X,x[n-1])>=1)cout<<"No War"<<endl;
    else cout<<"War"<<endl;
    //cout<<min(Y,y[m-1])-max(X,x[n-1])<<endl;
//cout<<min(Y,y[0])<<" "<<max(X,x[n-1])<<endl;
    
    
    
    
    
    
    
    
    
    
    
    
    
    return 0;
}

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

int n,arr[101],array[101],sum,p,x,m,bil;

int main(){
	cin>>n;
	for(int i = 1;i <= n;i++){
		cin>>bil;
		sum = sum + bil;
		arr[i] = bil;
	}
	cin>>m;
	for(int i = 1;i <= m;i++){
		cin>>p>>x;
		sum = sum + x - arr[p];
		array[i] = sum;
		sum = sum - x + arr[p];
	}
	for(int i = 1;i <= m;i++){
		cout<<array[i]<<endl;
	}
}


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

using namespace std;

const int N = 1e5 + 5;

int a[N];

int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; ++i)
    scanf("%d", a+i);
  sort(a, a+n);
  if (n % 3) {
    if (a[0] != a[n-1] || a[n-1] != 0) {
      puts("No");
      return 0;
    }
    puts("Yes");
  }
  else {
    int k = n / 3;
    if (a[0] != a[k-1] || a[k] != a[2 * k-1] || a[2*k] != a[n-1] || (a[0] ^ a[k] ^a[2*k]) != 0) {
      puts("No");
      return 0;
    }
    puts("Yes");
  }
  return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define lper(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[4]={1,0,-1,0};
const ll dx[4]={0,-1,0,1};
int main(){
    ll a[32]={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    ll K;cin>>K;
    cout<<a[K-1]<<endl;
    return 0;
}

Measured memory_bytes: 256
n,h= map(int, input().split())
a = 0
num = 0
b = []
for i in range(n):
  c,d = map(int, input().split())
  if c > a:
    a = c
    num = i
  b.append(d)
cnt = 0
b2 = b[num]
b = sorted(b)
if a >= max(b):
  if h%a == 0:
    print(h//a)
  else:
    print(h//a + 1)
  exit(0)
  
for i,j in enumerate(b):
  if j > a:
    b = sorted(b[i:], reverse=True)
    break
for i in b:
  h -= i
  cnt += 1
  if h <= 0:
    print(cnt)
    exit(0)
if h%a == 0:
  print(cnt + h//a)
else:
  print(cnt + h//a + 1)

Measured memory_bytes: 8764
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <map>
#include <queue>
#include <string>

#define reps(i,s,n) for(int (i) = (s); (i) < (n); (i)++)
#define rep(i,n) reps(i,0,n)
using namespace std;
using ll = long long;
using pii = pair<int,int>;
using vi = vector<int> ;
using vl = vector<ll>;

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

    ll len = s.length();
    vi vec;
    ll cnt = 1;
    rep(i,len-1){
        if(s[i] == s[i+1]){
            cnt++;
        }else{
            vec.push_back(cnt);
            cnt = 1;
        }
    }

    if(cnt != 0){
        vec.push_back(cnt);
    }


    // cout << "vec" << endl;
    // for(auto e: vec){
    //     cout << e << endl;
    // }

    if(vec.size() > 0){
        if(vec[0] == len){
            cout << (len * k) / 2 << endl;
        }else{
            ll ans = 0;
            for(auto e: vec){
                ans += e/2;
            }
            ans = ans * k;
            
            if(s[0] == s[len-1]){
                ll a = vec[0];
                ll b = vec[vec.size()-1];

                ll sub = a/2 + b/2 - (a+b)/2;
                sub = sub * (k-1);
                ans -= sub;
            }
            cout << ans << endl;
        }
    }else{
        cout << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 3588
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
const int oo = 1e9;
const int MOD = 1000000007;
const int BASE = 26;
const int N = 200001;
#define pb push_back
#define mp make_pair
#define x first
#define y second

int n,a , k;

int f(ll n,ll k){
	if(n%k==0)return n/k;
	ll rem = n/k + 1;
	ll nxt = n/k * k;
	ll need = (n-nxt)/rem + ((n-nxt)%rem != 0);
	ll kk = n - need*rem;
	return f(kk,k);
}

int sum = 0;
int main() {
	scanf("%d",&n);
	for (int i = 0; i < n; ++i){
		scanf("%d%d",&a,&k);
		sum ^= f(a,k);
	}
 
	if(sum==0){
		puts("Aoki");
	}else{
		puts("Takahashi");
	}
	return 0;
}

Measured memory_bytes: 256
x,y=map(int,input().split())

y_li = []
x_li = []
for _ in range(x):
    li = list(map(int,input().split()))
    li_sum = sum(li)
    li.append(li_sum)
    y_li.append(li)

for i in range(y+1):
    x_li.append((sum(e[i] for e in y_li)))
y_li.append(x_li)

for ans in y_li:
    print(' '.join(map(str,ans)))


Measured memory_bytes: 5708
package main

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

func main() {
	scanInit()
	n := scanInt()
	lottery := map[string]bool{}
	count := 0
	for i:= 0; i<n; i++ {
		s := scan()
		// fmt.Println(s)
		if _,ok := lottery[s]; !ok {
			lottery[s] = true
			count ++
		}
	}
	fmt.Println(count)
}
var sc = bufio.NewScanner(os.Stdin)
func scanInit () {
	sc.Split(bufio.ScanWords)
}
func scanInt () int{
sc.Scan()
	i,_ := strconv.Atoi(sc.Text())
	return i
}
func scan () string{
	sc.Scan()
	return sc.Text()
}

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

int main() {
  int N,M,X,Y;
  cin>>N>>M>>X>>Y;
  vector<int> V(N),W(M);
  
  for (int i=0;i<N;i++) {
    cin>>V[i];
  }
  sort(V.begin(),V.end());
  reverse(V.begin(),V.end());
  
  for (int i=0;i<M;i++) {
    cin>>W[i];
  }
  sort(W.begin(),W.end());
  
  if (X>Y) cout<<"War"<<endl;
  
  else {
    if (V[0]<W[0] && V[0]<Y && X<W[0]) cout<<"No War"<<endl;
    else cout<<"War"<<endl;
  }
}

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

int main(){
    unsigned int a,b;
    double fa,fb;

    std::cin >> a >> b;
    
    fa = a;
    fb = b;

    std::cout << a/b << " " << a%b << " ";
    std::cout << std::fixed;
    std::cout << std::setprecision(5) << fa/fb << std::endl;
    

}


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

typedef long long ll;
typedef long double ld;
// use unique(x) - removec consecutive items, returns vec.begin() + number of items
// for vector: sort(all(vec)); vec.erase(unique(all(vec)), vec.end());
// use iota(all(vec), 0) for filling a vector with 0,1,2...
// use fill(all(vec), 1) for filling a vector with 1,1,1...
// use rotate(vec.begin(), vec.begin() + 1, vec.end()) to rotate a vector | middle arg becomes first
// use merge(all(vec1), all(vec2), vec3.begin()) to merge 2 vectors, use vec3.resize(vec1.size() + vec2.size()) first
// ll pos = partition_point(all(vec), pred) - vec.begin(); bool pred(ll a){return a<3};
// print number in binary -> cout << bitset<20>(n);

const int N=200100;
int a[N],n;;
int main(){
	cin>>n;
	for(int i=0;i<n;++i)cin>>a[i];
	sort(a,a+n);
	reverse(a,a+n);
	ll res=a[0];
	int cnt=1;
	for(int i=1;i<n;++i){
		if(cnt<n-1)res+=a[i];
		++cnt;
		if(cnt<n-1)res+=a[i];
		++cnt;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 4416
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

ll lcm(ll a, ll b) {
	return a * b / gcd(a, b);
}





///////////////////////////


int main() {
	ll N, M;
	cin >> N >> M;

	if (N == 1 && M == 1) { cout << 1; }
	else if (N == 1) { cout << M - 2; }
	else if (M == 1) { cout << N - 2; }
	else { cout << (N - 2)*(M - 2); }

	system("PAUSE");

}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;

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

int main() {
    int r;
    cin >> r;
    if      ( r < 1200 ) cout << "ABC" << endl;
    else if ( r < 2800 ) cout << "ARC" << endl;
    else                 cout << "AGC" << endl;
    return 0;
}

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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int key){
  NodePointer cur = nil->next;
  while(cur != nil && cur->key != key){
    cur = cur->next;
  }
  return cur;
}

void init(){
  nil = malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if(cur == nil) break;
    if(isf == 0){
      printf(" ");
    }
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  if(t == nil) return;
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(){
  NodePointer t = nil->next;
  if(t == nil) return;
  deleteNode(t);
}

void deleteLast(){
  deleteNode(nil->prev);
}

void delete(int key){
  NodePointer t = listSearch(key);
  deleteNode(t);
}

void insert(int key){
  NodePointer x;
  x = malloc(sizeof(struct node));
  x->key = key;
  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;
}

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;

  scanf("%d", &n);

  init();

  for(i = 0; i < n; i++){
    scanf("%s%d", com, &key);
    if(com[0] == 'i'){insert(key); np++; size++;}
    else if(com[0] == 'd'){
      if(strlen(com) > 6){
	if(com[6] == 'F') deleteFirst();
	else if(com[6] == 'L') deleteLast();
      }else {
	delete(key); nd++;
      }
      size--;
    }
  }

  printList();

  return 0;
}



Measured memory_bytes: 33040
using System;
class p
{
  static void Main()
  {
    int N = int.Parse(Console.ReadLine());
    string[] input = Console.ReadLine().Split(' ');
    int[] arr = new int[N];
    for (int i = 0; i < N; i++) {
      arr[i] = int.Parse(input[i]);
    }
    
    int sum = 0;
    for (int i = 0; i < N; i++) {
      for (int j = 0; j < N; j++) {
        if (i != j) {
          sum += (arr[i] * arr[j]);
        }
      }
    }
    Console.WriteLine(sum/2);
  }
}

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

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define Task ""

using namespace std;
typedef long long ll;

const int maxn = 1 << 18;

signed main(void)
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    if (fopen("A.INP", "r")){
        freopen("A.INP", "r", stdin);
        freopen("A.OUT", "w", stdout);
    }
    if (fopen(Task".INP", "r")){
        freopen(Task".INP", "r", stdin);
        freopen(Task".OUT", "w", stdout);
    }
    int n, k; cin >> n >> k;
    vector<int> a(n+1);
    bool ok = 1;
    for (int i=0; i<n; ++i){
        cin >> a[i];
        if (a[i] == 0) ok = 0;
    }
    if (ok) a[n] = 0;
    sort(a.begin(), a.end());
    int pos;
    for (int i=0; i<=n; ++i){
        if (a[i] == 0) pos = i;
    }
    if (!ok) --k;
    int res = 1e9;
    for (int l=0; l<=k; ++l){
        int r = k - l;
        if (pos + r <= n && pos-l >= 0)
            res = min(res, min(2 * abs(a[pos-l]) + a[pos+r], abs(a[pos-l]) + 2  * a[pos+r]));
    }
    cout << res << '\n';
}


Measured memory_bytes: 640
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:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        k: usize,
        h: [i32; n],
    }

    let mut memo = vec![-1; 100005]; // -1が10個
    memo[0] = 0;
    memo[1] = (h[1] - h[0]).abs();
    let r = dp(n-1, k+1, &mut memo, &h);
    println!("{}", r);
}

fn dp(i: usize, k: usize, memo: &mut Vec<i32>, h: &Vec<i32>) -> i32 {
    if memo[i] != -1 {
        // println!("memo {}: {}", i, memo[i]);
        return memo[i];
    }

    let mut v: i32 = 999999999;

    for x in 1..k {
        if i < x {
            break;
        }
        let y = dp(i-x, k, memo, h) + (h[i] - h[i-x]).abs();
        if y < v {
            v = y;
        }
    }

    // println!("{}: {}", i, v);
    memo[i] = v;
    return v
}


Measured memory_bytes: 10492
import { readFileSync } from "fs";

const read = () =>
  readFileSync(0, "utf8")
    .split("\n")
    .map((line) => line.split(" "));

const main = (input: string[][]) => {
  const N = Number(input[0][0]);

  let exponent = 0;

  for (let i = 2; i <= N; i *= 2) {
    exponent += 1;
  }

  return 2 ** exponent;
};

console.log(main(read()));


Measured memory_bytes: 29600
fun Triple<Int, Int, Int>.sum() = first * 10000 + second * 5000 + third * 1000

fun solve(N: Int, Y: Int): Triple<Int, Int, Int> {
    (0..N).forEach { x ->
        (0..N - x).forEach { y ->
            val z = N - x - y
            Triple(x, y, z).let {
                if (it.sum() == Y) return it
            }
        }
    }
    return Triple(-1, -1, -1)
}

fun main(args: Array<String>) {
    val (N, Y) = readLine()!!.split(" ").map{ it.toInt() }
    print(solve(N, Y).toList().joinToString(" "))
}

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

int gcd(int a,int b){
  if(a%b==0)
    return(b);
  else
    return(gcd(b,a%b));
}

int main(){
  int a,b,k;
  cin >> a >> b >> k;
  
  int x=gcd(a,b);
  
  int answer;
  
  int j=0;
  for(int i=x;i>0;i--){
    if(x%i==0){
      answer=i;
      j++;
    }
    if(j==k)
      break;
  }
  cout << answer << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int int64_t
main(){
  int N,A,B;
  cin>>N>>A>>B;
  vector<int>X(N);
  for(auto&x:X)cin>>x;
  int sum=0;
  for(int i=1;i<N;++i){
    int distance=X[i]-X[i-1];
    int cost_walk=distance*A;
    int cost_teleportation=B;
    sum+=min(cost_walk,cost_teleportation);
  }
  cout<<sum<<endl;
}


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

using namespace std;

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

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

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

struct Face
{
	int f;
	int a[4];
};
struct Dice
{
	Face f[6];
};

Dice createDice(int k[])
{
	Face d[6];
	d[0].f = k[0];
	d[0].a[0] = k[4];
	d[0].a[1] = k[2];
	d[0].a[2] = k[1];
	d[0].a[3] = k[3];

	d[1].f = k[1];
	d[1].a[0] = k[0];
	d[1].a[1] = k[2];
	d[1].a[2] = k[5];
	d[1].a[3] = k[3];

	d[2].f = k[2];
	d[2].a[0] = k[0];
	d[2].a[1] = k[4];
	d[2].a[2] = k[5];
	d[2].a[3] = k[1];

	d[3].f = k[3];
	d[3].a[0] = k[0];
	d[3].a[1] = k[1];
	d[3].a[2] = k[5];
	d[3].a[3] = k[4];

	d[4].f = k[4];
	d[4].a[0] = k[0];
	d[4].a[1] = k[3];
	d[4].a[2] = k[5];
	d[4].a[3] = k[2];

	d[5].f = k[5];
	d[5].a[0] = k[1];
	d[5].a[1] = k[2];
	d[5].a[2] = k[4];
	d[5].a[3] = k[3];
	Dice dice;
	REP(i, 6)
	{
		dice.f[i] = d[i];
	}
	return dice;
}

int main()
{
	Dice d[2];

	int n = 2;
	int sum = 0;
	REP(i, n)
	{
		int k[6];
		
		REP(j, 6)
		{
			cin >> k[j];
			sum += k[j];
		}

		
		d[i] = createDice(k);
	}
	if (sum == 22)
	{
		cout << "Yes" << endl;
		return 0;
	}
	string S = "Yes";

	REP(i, n)
	{
		FOR(j, n, i + 1)
		{
			bool same = true;
			REP(k, 6)
			{
				Face f1 = d[i].f[k];
				REP(l, 6)
				{
					Face f2 = d[j].f[l];
					if (f1.f == f2.f)
					{
						int s = -1;
						REP(m, 4)
						{
							if (f1.a[0] == f2.a[m])
							{
								s = m;
								break;
							}
						}
						if (s == -1)
						{
							same = false;
							break;
						}
						REP(m, 4)
						{
							if (f1.a[m] != f2.a[(m + s) % 4])
							{
								same = false;
								break;
							}
						}
						break;
					}
					if (l == 5)
					{
						same = false;
					}
				}
			}
			if (same)
			{
				cout << "Yes" << endl;
			}
			else
			{
				cout << "No" << endl;
			}
		}
	}

	//cout << S << endl;
	return 0;
}


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

int main(){
  float n,m,c;
  cin >> n >> m >> c;
  vector<int> vec(m);
  
  for(int i = 0;i < m;i ++){
    cin >> vec.at(i);
  }
  
  int count = 0;
  
  for(int i = 0;i < n;i ++){
    float a = 0;
      for(int j = 0;j < m;j ++){
        float b;
        cin >> b;
        a += b * vec.at(j);
      }
    if(a + c > 0)count ++;
  }
  
  cout << count << endl;
}

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

int main() {
	int a, b, c, d, e, k;
	cin >> a;
	cin >> b;
	cin >> c;
	cin >> d;
	cin >> e;
	cin >> k;
	if (e - a <= k)cout << "Yay!" << endl;
	else cout << ":(" << endl;
	return 0;
}

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

int main(){

  int N, s[27], t[27];
  char ans;
  cin >> N;
  string S, T;
  for(int i=0; i<N; i++){
    for(int j=0; j<27; j++) s[j] = 0;
    cin >> S;
    for(int j=0; j<S.size(); j++) s[S[j]-'a']++;
    if(i==0) for(int j=0; j<27; j++) t[j] = s[j];
    for(int j=0; j<27; j++) t[j] = min(t[j], s[j]);
  }

  for(int i=0; i<27; i++){
    ans = i + 'a';
    for(int j=0; j<t[i]; j++) cout << ans << flush;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <math.h>
#include <sstream>

using namespace std;

int main()
{
  int N, K;
  string S;
  cin >> N >> S >> K;
  char ch = S[K - 1];
  string T;
  for (int i = 0; i < N; ++i) {
    if (S[i] == ch) T += ch;
    else T += '*';
  }
  cout << T << endl;
  return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int A[100000];

int partition(int p, int r){
    int i = p - 1;
    int x = A[r];
    for(int j = p; j < r; j++){
        if(A[j] <= x){
            i += 1;
            int tmp = A[j];
            A[j] = A[i];
            A[i] = tmp;
        }
    }

    int tmp = A[i + 1];
    A[i + 1] = A[r];
    A[r] = tmp;

    return i + 1;
}

int main(){

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

    int base = partition(0, n-1);
    for(int i= 0; i< n; i++){
        if(i < n-1){
            if(i != base){
                printf("%d ",A[i]);
            } else{
                printf("[");
                printf("%d",A[i]);
                printf("] ");
            }
        } else{
            printf("%d", A[i]);
        }
    }

    printf("\n");
    return 0;
}


Measured memory_bytes: 2120