akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<iomanip>
#include<iostream>
using namespace std;
int main(){
  int a,b,d,r;
  double f,a2,b2;
  cin>>a>>b;
  d=a/b;
  r=a%b;
  a2=a*1.0;
  b2=b*1.0;
  f=a2/b2;
  cout<<d<<" "<<r<<" ";
  printf("%5f\n",f);
  return 0;
}

Measured memory_bytes: 1240
#include <bits/stdc++.h>
#define ll long long int
#define N 1000
#define f(i, a, b) for (ll i = (ll)a; i <= (ll)b; i++)
#define rf(i, a, b) for (ll i = (ll)a; i >= (ll)b; i--)
#define po pop_back
#define pb push_back
#define lb lower_bound
#define fi first
#define se second
#define debug(x) cout << #x << " = " << x << endl
#define ub upper_bound
#define ibs ios_base::sync_with_stdio(false)
#define cti cin.tie(0)
#define all(x) x.begin(), x.end()
#define PI 3.14159265
#define cot cout.tie(0)
using namespace std;
/**
        * @author :: Sawlani
        *
        */
int main()
{
     ll n,k;
     cin >>  n >>  k;


     if(n>=k)
     {
         cout <<  min({n%k,k-n%k}) << endl;
     }
     else
     {
          cout <<  min(n,k-n) << endl;
     }
     
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll                      long long int
#define fi                      first
#define se                      second
#define pb                      push_back
#define pbb                     pop_back
#define mp                      make_pair
#define pii     	            pair<int,int>
#define all(x)                  x.begin(), x.end()
#define mem(array, value)       memset(array, value, sizeof(array))
#define fastRead 	            ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#ifdef Lollipop
    #define line                    cout << "\n===================\n"
    #define trace(...)              __f( #__VA_ARGS__ , __VA_ARGS__ )
    template <typename Arg1>
    void __f(const char* name, Arg1&& arg1){
        cerr << name << " = " << arg1 << "\n";
    }
    template <typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names + 1, ',');
        cerr.write(names, comma - names) << " = " << arg1 << " , ";
    __f(comma + 1, args...);
    }
#else
    #define line
    #define trace(...)
#endif

//int dx[] = {-1, 0, 1, 0},                  dy[] = {0, 1, 0, -1};                  // 4 Direction
//int dx[] = {-1, 0, 1, 0, -1, 1, 1, -1},    dy[] = {0, 1, 0, -1, -1, 1, -1, 1};    // 8 Direction

inline ll power(ll a, ll p){
    ll res = 1, x = a;
    while (p){
        if (p & 1) res = (res * x);
        x = (x * x), p >>= 1;
    }
    return res;
}
inline ll big_mod(ll a, ll p, ll m){
    ll res = 1 % m, x = a % m;
    while (p){
        if (p & 1) res = (res * x) % m;
        x = (x * x) % m, p >>= 1;
    }
    return res;
}

const ll INF = 1e15;

int main ()
{
    #ifdef Lollipop
        //freopen ("input.txt", "r", stdin);
        //freopen ("output.txt", "w", stdout);
    #endif
    //fastRead;
    int n;
    cin >> n;
    string s, t;
    cin >> s >> t;
    string res;
    for (int i = 0; i < n; i++){
        res.pb(s[i]);
        res.pb(t[i]);
    }
    cout << res << endl;
    return 0;
}



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

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

bool IsPrime(long long int num)
{
    if (num < 2) return false;
    else if (num == 2) return true;
    else if (num % 2 == 0) return false;

    double sqrtNum = sqrt(num);
    for (int i = 3; i <= sqrtNum; i += 2){
        if (num % i == 0){
            return false;
        }
    }
    return true;
}


int main(){
  long long int a, b; cin >> a >> b;
  long long int x = gcd(a, b);

  int times = sqrt(x);
  vector<long long int> cd = {};
  for(int i=1; i <= times; i++){
    if(x%i == 0) {
      cd.push_back(i); cd.push_back(x/i);
    } 
  }

  long long int ans = 1;
  for(int i=0; i<cd.size(); i++){
    if(IsPrime(cd[i])) ans++;
  }
  cout << ans << endl;
  return 0;
}

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


int main()
{
	//freopen("input16.txt","r",stdin);freopen("output16.txt","w",stdout);
	ios_base::sync_with_stdio(false); cin.tie(0);
	int a[3];
	cin>>a[0]>>a[1]>>a[2];
	sort(a,a+3);
	if (a[2]==a[1]+a[0]){
		cout<<"Yes";
	}
	else {
		cout<<"No";
	}
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int n;
    int d, min, max;
    long long sum;
 
    scanf("%d%d", &n, &d);
    sum = min = max = d;
    while (--n > 0) {
        scanf("%d", &d);
        if (d < min) min = d;
        if (d > max) max = d;
        sum += d;
    }
    printf("%d %d %lld\n", min, max, sum);
    return 0;
}



Measured memory_bytes: 2112
#include <iostream>
using namespace std;
int n, m;
string a[55], b[55];
int main() {
	int i, j, k;
	cin>>n>>m;
	for(i=0; i<n; i++) cin>>a[i];
	for(i=0; i<m; i++) cin>>b[i];
	for(i=0; i<=n-m; i++) for(j=0; j<=n-m; j++) {
		for(k=0; k<m; k++) if(a[i+k].substr(j,m) != b[k]) break;
		if(k==m) {cout<<"Yes"; return 0;}
	}
	cout<<"No";
	return 0;
}

Measured memory_bytes: 256
import numpy as np
n, m = map(int, input().split())
a = list(map(int, input().split()))
a.sort(reverse=True)
a = np.array(a)

diff = a[:-1] - a[1:]
diff.sort()

if n == 1:
    print(sum(diff))
else:
    print(sum(diff[:-n + 1]))


Measured memory_bytes: 23064
#include <bits/stdc++.h>
#define x first
#define y second

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MOD = 1e9+7;
const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

int n, m;
vector<int> lis[100100];
int deg[100100];
int chk[100100];

int dfs(int here, int wo) {
    chk[here] = 1;
    int ans = 1;
    for (int &v : lis[here]) {
        if (!chk[v]&&v!=wo) ans += dfs(v,wo);
    }
    return ans;
}

void pung() {
    puts("No");
    exit(0);
}

int main() {
    int i, j;

    scanf("%d%d",&n,&m);
    for (i=0;i<m;i++) {
        int a, b;
        scanf("%d%d",&a,&b); --a; --b;
        lis[a].push_back(b);
        lis[b].push_back(a);
        deg[a]++; deg[b]++;
    }
    int f = 1, c = 0;
    vector<int> vec;
    for (i=0;i<n;i++) {
        if (deg[i]%2) f = 0;
        c+=(deg[i]-2)/2;
        if (deg[i]>2) vec.push_back(i);
    }
    if (!f) pung();
    if (c<=1) pung();
    if (c==2) {
        if (vec.size()>1) {
            if (dfs(0,vec[0]?vec[0]:vec[1])==n-1) pung();
        }
    }
    puts("Yes");

    return 0;
}


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

H, W = map(int, input().split())
state = [list(input().rstrip()) for _ in range(H)]

def next(h, w):
    ret = []
    if h != H-1:
        ret.append((h+1, w))
    if w != W-1:
        ret.append((h, w+1))

dp = [[0]*(W) for _ in range(H)]

for w in range(W-1):
    t = dp[0][w]
    if state[0][w] != state[0][w+1]:
        t += 1
    dp[0][w+1] = t

for h in range(1, H):
    tmp = dp[h-1][0]
    if state[h-1][0] != state[h][0]:
        tmp += 1
    dp[h][0] = tmp
    for w in range(1, W):
        t1 = dp[h][w-1]
        t2 = dp[h-1][w]
        if state[h][w-1] != state[h][w]:
            t1 += 1
        if state[h-1][w] != state[h][w]:
            t2 += 1
        dp[h][w] = min(t1, t2)

p = dp[H-1][W-1]
if p%2 == 0:
    if state[0][0] == ".":
        ans = p//2
    else:
        ans = p//2+1
else:
    ans = (p+1)//2
print(ans)

Measured memory_bytes: 41712
n,m=map(int,input().split())
ab=[[int(j) for j in input().split()] for i in range(n)]
cd=[[int(j) for j in input().split()] for i in range(m)]
for a,b in ab:
    l=[abs(a-c)+abs(b-d) for c,d in cd]
    print(l.index(min(l))+1)

Measured memory_bytes: 39152
#include<cstdio>
#include<iostream>
#include<map>
#include<set>
#include<vector>
#include<cstring>
#include<cassert>
#include<sstream>
#include<cmath>
#include<algorithm>
#include<queue>
#include<limits>
#include<ctime>
#include<stack>
#include<bits/stdc++.h>
#include<string>
#include<stdlib.h>
#include<stdio.h>
typedef long long ll;

using namespace std;

int main(){
	ll n;
	cin>>n;
	ll a[n];
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	sort(a,a+n);
	cout<<a[(n/2)]-a[(n/2)-1];
}



Measured memory_bytes: 4388
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <fstream>
#include <iostream>
#include <map>
#include <queue>
#include <string>
#include <stack>
#include <vector>
#include <set>
#include <tuple>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> T3;

int main(){
	int n,m;
	cin >> n >> m;
	int p = 1 << m;
	cout << p * (1900 * m + 100 * (n-m)) << endl;
}


Measured memory_bytes: 256
a = [list(map(str,input().split())) for i in range(3)]
a_conv = []
for i in range(3):
    for j in range(2):
        a_conv.append(a[i][j])

judge = 0
for i in range(1,5):
    temp = a_conv.count(str(i))
    if temp == (0 or 3):
        print('NO')
        exit()
    elif temp == 2:
        judge += 1

if judge == 2:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 3064
K = int(input())
N = len(input()) + K
P = 10**9+7

nn = 2002002
fa = [1] * (nn+1)
fainv = [1] * (nn+1)
for i in range(nn):
    fa[i+1] = fa[i] * (i+1) % P
fainv[-1] = pow(fa[-1], P-2, P)
for i in range(nn)[::-1]:
    fainv[i] = fainv[i+1] * (i+1) % P

C = lambda a, b: fa[a] * fainv[b] % P * fainv[a-b] % P if 0 <= b <= a else 0

s = 0
po = 1
for i in range(K + 1):
    s = (s + C(N, i) * po) % P
    po = po * 25 % P
print(s)

Measured memory_bytes: 167392
#include<iostream>
#include<cstring>
#include<string>
#include<algorithm>
#include<vector>
#include<map>
#include<queue>
#include<cstdio>
#include<cmath>
using namespace std;
int n;
int main(){
//	freopen("1.txt","r",stdin);
	cin>>n;
	long long sum=0;
	//A*B+C=N
	for(int i=1;i<=n;i++){
		if(n%i==0){
			sum+=n/i-1;
		}else{
			sum+=n/i;
		}
	}
	cout<<sum<<endl;
	return 0;
}




Measured memory_bytes: 3632
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f;
	double x,y;
	while(scanf("%d %d %d %d %d %d",&a,&b,&c,&d,&e,&f)!=EOF){
		x=(double)(c*e-b*f)/(a*e-b*d);
		y=(double)(c*d-a*f)/(b*d-a*e);
		if(x==0){
			x=0;
			printf("%0.3f %0.3f\n",x,y);	
		}
		else{
			printf("%0.3f %0.3f\n",x,y);
		}
	}
	return 0;
}

Measured memory_bytes: 1064
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);  
int d = sc.nextInt();
int n = sc.nextInt();
if(n == 100) {
	System.out.println((long)Math.pow(100,d)*(n+1));	
}
else {
System.out.println((long)Math.pow(100,d)*n);
}
}}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#include <cstdlib>  
#include <cmath>
#define rep(i,n) for (int i=0;i<(n);++i)
using namespace std;
using ll = long long;
using P= pair<ll,ll>;
 
int main() {
    int N;
    ll L[100];
    cin>>N;
    rep(i,N){
      cin>>L[i];
    }
    int count=0;
    for(int i=0;i<N;i++){
      for(int j=i+1;j<N;j++){
        for(int k=j+1;k<N;k++){
          if((L[i]!=L[j])&&(L[j]!=L[k])&&(L[i]!=L[k])){
         	if(((L[i]+L[j])>L[k])&&((L[j]+L[k])>L[i])&&((L[i]+L[k])>L[j]))count++;
          }
      	}
      }
    }
    cout<<count<<endl;
    return 0;
}

Measured memory_bytes: 3636
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto xy = readln.split.to!(long[]);
    auto X = xy[0];
    auto Y = xy[1];
    auto a = X;
    long r;
    while (a <= Y && a ) {
        ++r;
        a *= 2;
    }
    writeln(r);
}

Measured memory_bytes: 256
n = gets.chomp.to_i 

n.times{
    
    s = gets.chomp.split(" ").map(&:to_i)
    
    days_each_year =[0] 
    
    (1..999).to_a.each{|item|
        
        item%3 == 0 ? days_each_year << 200 : days_each_year << 195
        
    }
    
    #p days_each_year
    
    i = 0 
    (s[0]+1..999).to_a.each{|item|
    
        i += days_each_year[item]
        
    }
    
    
    (s[1]+1..10).to_a.each{|item|
        
        if (s[0]%3 != 0) and (item%2 == 0)
            i += 19 
        else 
            i += 20
        end 
        
    }
    
    
    if (s[0]%3 != 0) and (s[1]%2 == 0)
        i += 20-s[2]
    else 
        i += 21-s[2]
    end 
    
    puts i 
    
}

Measured memory_bytes: 11572
import std.stdio, std.conv, std.string, std.array, std.range, std.algorithm, std.container;
import std.math, std.random, std.bigint, std.datetime, std.format;
void main(string[] args){ if(args.length > 1) if(args[1] == "-debug") DEBUG = 1; solve(); }
void log()(){ writeln(""); } void log(T, A ...)(T t, lazy A a){ if(DEBUG) write(t, " "), log(a); } bool DEBUG = 0; 
string read(){ static string[] ss; while(!ss.length) ss = readln.chomp.split; string res = ss[0]; ss.popFront; return res; }
T read(T)(){ return read.to!T; }
T[] read(T)(long n){ return n.iota.map!(_ => read!T).array; }
T[][] read(T)(long m, long n){ return m.iota.map!(_ => read!T(n)).array; }
// ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- ----- //

void solve(){
	
	int n = read!int;
	string s = readln.chomp;
	
	int sum = 0;
	int[] sums = [0]; // sum[i] = sum(0 .. i)
	foreach(i; 0 .. n){
		if(s[i] == '#') sum += 1;
		sums ~= sum;
	}
	
	int ans = n + 10;
	foreach(i; 0 .. n + 1){
		int tmp = sums[i] + ((n - i) - (sums[n] - sums[i]));
		if(tmp < ans) ans = tmp;
	}
	
	ans.writeln;
	
}



Measured memory_bytes: 3452
#include <cstdio>
#include <iostream>
#include <cstring>
#include <algorithm>

inline int read() {
	int x = 0, f = 1; char ch = getchar();
	while(ch > '9' || ch < '0') { if(ch == '-') f = -1; ch = getchar(); }
	do x = x * 10 + ch - 48, ch = getchar(); while(ch >= '0' && ch <= '9');
	return x * f;
}

typedef long long ll;
const int MAXN = 500001;
const int p = 998244353;

int n,k;
ll fac[MAXN],ifac[MAXN];

ll C(int n,int m) {
	if(n < m) return 0;
	if(m < 0 || n < 0) return 0;
	return fac[n] * ifac[m] % p * ifac[n - m] % p;
}

int main() {
	n = read(), k = read();
	if(k < n) return std::puts("0"), 0;
	fac[0] = 1;
	for(int i = 1;i <= k;i++) fac[i] = fac[i - 1] * i % p;
	ifac[0] = ifac[1] = 1;
	for(int i = 2;i <= k;i++) ifac[i] = (p - p / i) * ifac[p % i] % p;
	for(int i = 1;i <= k;i++) ifac[i] = ifac[i - 1] * ifac[i] % p; 
	ll ans = 0;
	for(int r = (k - 1) / 2 + 1;r <= k;r++) {
		int b = k - r;
		if(r == b) b--;
		ans = ((ans + C(r + b,b)) % p + p - C(r + b,2 * r - n + 1)) % p;
	}
	std::printf("%lld\n",ans);
	return 0;
}


Measured memory_bytes: 8192
use std::io;
use parse::ParseNext;

fn main() {
    let stdin = io::stdin();
    let mut r = read::Reader::new(io::BufReader::new(stdin));
    let mut i = r.read_line().unwrap().split_whitespace();
    let (a, b): (i32, i32) = (i.parse_next().unwrap(), i.parse_next().unwrap());
    let max = *[a + b, a - b, a * b].iter().max().unwrap();
    println!("{}", max);
}

/// 文字列のパースの補助モジュール.
pub mod parse {
    use std::error;
    use std::fmt;
    use std::str::FromStr;

    #[derive(Eq, PartialEq, Copy, Clone, Hash, Debug)]
    pub enum Error<E> {
        GetNextError,
        ParseErr(E),
    }

    impl<E: fmt::Display> fmt::Display for Error<E> {
        #[inline]
        fn fmt(&self, f: &mut fmt::Formatter) -> Result<(), fmt::Error> {
            match self {
                &Error::GetNextError => f.write_str("Iterator has no next element"),
                &Error::ParseErr(ref e) => write!(f, "{}", e)
            }
        }
    }

    impl<E: error::Error> error::Error for Error<E> {
        #[inline]
        fn description(&self) -> &str {
            match self {
                &Error::GetNextError => "Iterator error",
                &Error::ParseErr(ref e) => e.description()
            }
        }
    }

    pub trait ParseNext: Iterator {
        fn parse_next<F: FromStr>(&mut self) -> Result<F, Error<F::Err>>;
    }

    impl<'a, S: AsRef<str>, I: Iterator<Item=S>> ParseNext for I {
        fn parse_next<F: FromStr>(&mut self) -> Result<F, Error<F::Err>> {
            if let Some(s) = self.next() {
                match s.as_ref().parse() {
                    Ok(x) => Ok(x),
                    Err(e) => Err(Error::ParseErr(e))
                }
            } else {
                Err(Error::GetNextError)
            }
        }
    }
}

/// 標準入力読み取りモジュール.
pub mod read {
    use std::io::{BufRead, Result};

    pub struct Reader<R> {
        buf: String,
        inner: R,
    }

    impl<R> Reader<R> {
        #[inline]
        pub fn new(inner: R) -> Self {
            Reader { buf: String::new(), inner: inner }
        }
    }

    impl<R: BufRead> Reader<R> {
        #[inline]
        pub fn read_line(&mut self) -> Result<&str> {
            self.buf.clear();
            self.inner.read_line(&mut self.buf)?;
            Ok(&self.buf)
        }
    }
}


Measured memory_bytes: 4352
/*
  AtCoder Beginner Contest 103
  D - Islands War
*/

#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int N, M, a, b;
vector<pair<int,int>> requests;

int main() {
  scanf("%d%d", &N, &M);
  for (int i = 0; i < M; ++i) {
    scanf("%d%d", &a, &b);
    requests.push_back(make_pair(a,b));
  }

  sort(requests.begin(), requests.end(), [](pair<int,int>& x, pair<int,int>& y) {return (x.second < y.second);});

  int count = 0;
  int buffer = -1;
  for (int i = 0; i < requests.size(); ++i) {
    if (requests[i].first <= buffer && buffer < requests[i].second) continue;

    count += 1;
    buffer = requests[i].second - 1;
  }

  printf("%d\n", count);
  return 0;
}

Measured memory_bytes: 1400
import java.util.*;
import java.lang.*;
 
public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true){
            StandardDeviation standard = new StandardDeviation();
            int n = sc.nextInt();
            int numbers[] = new int[n];
            if(n == 0){
                break;
            }else{
                for(int i = 0; i < n; i++){
                    numbers[i] = sc.nextInt();
                }
            }
            double average = standard.average(n, numbers);
            double dispersion = standard.dispersion(n,average,numbers);
            System.out.println(String.format("%f", dispersion));

        }
            
    }
}

class StandardDeviation{
    public double average(int n,int numbers[]){
        double sum = 0;
        for(int i = 0; i < n; i++){
            sum += numbers[i];
        }
    return sum / n;
    }
    
    public double dispersion(int n, double average,int numbers[]){
        double sum = 0;
        for(int i = 0; i < n; i++){
            sum += Math.pow(numbers[i] - average,2);
        }
    return Math.sqrt(sum / n);
    }
}


Measured memory_bytes: 31564
#include <stdio.h>
#include <string>
#include <stdlib.h>
#include <iostream>
#include <vector>
#include <string.h>
#include <algorithm>
#include <map>
using namespace std;
const int maxn = 5e5+10;
int n = 0, q = 0;

struct Query{
	int id, l, r;
	bool operator< (Query a) const{
		return r < a.r;
	}
}query[maxn];



int v[maxn], sum[maxn], ans[maxn];

int lowbit(int x){
	return x & (-x);
}

void change(int i, int a){
	while(i <= n){
		sum[i] += a;
		i += lowbit(i);
	}
}

int getsum(int i){
	int sum_t = 0;
	while(i > 0){
		sum_t += sum[i];
		i -= lowbit(i);
	}
	return sum_t;
}

int main() {

        scanf("%d", &n);
		memset(v, 0, sizeof(v));
		memset(sum, 0, sizeof(sum));
		memset(ans, 0, sizeof(ans));
        scanf("%d", &q);
        int t = 0;
		for(int i = 1; i <= n; i++){
			scanf("%d", &v[i]);
		}

			for(int i = 1; i <= q; i++){
			scanf("%d%d", &query[i].l, &query[i].r);
			query[i].id = i;
		}

		sort(query + 1, query + q + 1);

		int pre = 1;
		map<int, int> mymap;
		for(int i = 1; i <= q; i++){
			for(int j = pre; j <= query[i].r; j++){
				//已存在
				if(mymap[v[j]]){
					change(mymap[v[j]], -1);
				}
				mymap[v[j]] = j;
				change(j, 1);
			}
			pre = query[i].r + 1;
			ans[query[i].id] = getsum(query[i].r) - getsum(query[i].l - 1);
		}

		for(int i = 1; i <= q; i++){
			cout << ans[i] << endl;
		}
	return 0;
}



Measured memory_bytes: 38960
import java.util.*;

public class Main {
	static Scanner sc = new Scanner(System.in);
	public static void main(String args[]) {
		while(sc.hasNext()) {
			String line = sc.nextLine();
			int ans = 0;
			int prev = 0;
			for(int i = 0; i < line.length(); i++) {
				char c = line.charAt(i);
				int p = 0;
				if(c == 'I') p = 1;
				else if(c == 'V') p = 5;
				else if(c == 'X') p = 10;
				else if(c == 'L') p = 50;
				else if(c == 'C') p = 100;
				else if(c == 'D') p = 500;
				else if(c == 'M') p = 1000;
				else {
					System.out.println("error");
				}
				if(prev < p) ans += p - prev * 2;
				else ans += p;
				prev = p;
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a,b,c,d;
  cin >> a >> b >> c >> d;
 
  if (a+b > c+d) {
    cout << "Left" << endl;
  }
  else if (a+b < c+d) {
    cout << "Right" <<endl;
  }
  else {
    cout << "Balanced" <<endl;
  }
}

Measured memory_bytes: 256
#include <stdio.h>
int sub(int n){
  if(n < 10){
    return n;
  }
  int a = n / 10;
  return n % 10 + sub(a);
}

int main(){
  int in;
  scanf("%d",&in);
  if(in % sub(in) == 0){
    printf("Yes");
  }else{
    printf("No");
  }
}

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

using namespace std;

double dis(double x,double y)
{
  return sqrt(x*x+y*y);
}

double ang(double x1,double y1,double x2,double y2)
{
  double a=dis(x1,y1),b=dis(x2,y2),c=dis(x1-x2,y2-y1);
  return acos((-c*c+a*a+b*b)/(2*a*b));
}

double calc(double x1,double y1,double x2,double y2)
{
  double L=0,R=10000;
  double D=dis(x1,y1);
  double th1=ang(x1,y1,x2,y2)/2.,th2=ang(-x1,-y1,x2-x1,y2-y1)/2.;
  return D/(1./tan(th1)+1./tan(th2)+2);
}

int main()
{
  double x1,y1,x2,y2,x3,y3;
  scanf("%lf%lf%lf%lf%lf%lf",&x1,&y1,&x2,&y2,&x3,&y3);
  printf("%.10lf\n",max(calc(x2-x1,y2-y1,x3-x1,y3-y1),
			max(calc(x3-x2,y3-y2,x1-x2,y1-y2),
			    calc(x1-x3,y1-y3,x2-x3,y2-y3))));
  return 0;
}


Measured memory_bytes: 384
""" AtCoder """

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

x = list(map(int, input().split()))
ans = 1000000000

for i in range(N - K + 1):
    if x[i] < 0 and x[i + K - 1] > 0:
        ans = min(ans, abs(x[i])*2 + x[i + K - 1], abs(x[i]) + x[i + K - 1] * 2)
    elif x[i] >= 0 and x[i + K - 1] >= 0:
        ans = min(ans, x[i + K - 1])
    else:
        ans = min(ans, abs(x[i]))

print(ans)



Measured memory_bytes: 14224
#include <bits/stdc++.h>
#define IOS {ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);}
#define ll long long int
#define endl "\n"
#define f(i, a, b) for(ll i=a; i<b; i++)
#define fb(i, a, b) for(ll i=a; i>=b; i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define vi vector <ll>
#define vl vector <long long>
#define pi pair <int, int>
#define sz(x) (int) x.size()
#define LB lower_bound
#define UB upper_bound
#define M 200005
#define mod 1000000007
using namespace std;

void solve()
{
	ll n, k, loop, x = 0, cnt = 0;
	cin>>n>>k;
	map <ll, ll> m;
	ll a[n];
	vi v, v2;
	f(i, 0, n)
	{
		cin>>a[i];
		a[i]--;
	}
	while(m[x] != 1)
	{
		v.pb(x);
		m[x]++;
		x = a[x];
	}
	// cout<<x<<endl;
	f(i, 0, v.size())
	{
		if(v[i] == x)
		{
			loop = v.size()-i;
			f(j, i, v.size()) v2.pb(v[j]);
		}
	}
	// f(i, 0, v2.size()) cout<<v2[i]+1<<' '; cout<<endl;
	int y = 0;
	f(i, 0, v.size())
	{
		if(v[i] == x)
		{
			k %= loop;
			break;
		}
		else if(k == 0)
		{
			cout<<v[i]+1;
			return;
		}
		k--;
	}
	f(i, 0, v2.size())
	{
		if(k == 0)
		{
			cout<<v2[i]+1;
			break;
		}
		k--;
	}
}

int main()
{
    IOS
    int t = 1;
    //cin>>t;
    f(tno, 1, t+1)
    {
        solve();
    }
    return 0;
}

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

using namespace std;

typedef long long LL;

#define ALL(a) (a).begin(), (a).end()
#define PB push_back
#define MP make_pair
#define LEN(a) int((a).size())
#define SORT(a) sort((a).begin(), (a).end())
#define CLR(a) memset((a), 0, sizeof(a))

const double EPS = 1e-10;

int main() {
    int n;
    cin >> n;
    vector<LL> x(n), y(n);
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i];

    if (n == 1) {
        cout << 1 << endl;
        return 0;
    }

    int mn = 1e9 + 7;
    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i == j) continue;
            vector<bool> a(n, false);
            int cnt = 0;
            LL p = x[i] - x[j], q = y[i] - y[j];
            // cout << p << " " << q << endl;
            for (int k = 0; k < n; k++) {
                for (int l = 0; l < n; l++) {
                    if (l == k) continue;
                    if (x[k] - x[l] == p && y[k] - y[l] == q) {
                        if (!a[k] && !a[l]) cnt++;
                        else if (a[k] && a[l]) cnt--;
                        a[k] = a[l] = true;
                        // cout << k << " " << l << endl;
                    }
                }
            }
            for (int k = 0; k < n; k++) {
                if (!a[k]) cnt++;
            }
            // cout << cnt << endl;
            // cout << endl;
            mn = min(mn, cnt);
        }
    }
    cout << mn << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#define maxn 5010
#define maxint 0x7fffffff/2
using namespace std;
int n,m;
int main() {
	cin>>n>>m;
	for(int i=1; i<=m; i++) {
		int x;
		cin>>x;
		n-=x;
	}
	if(n<0) n=-1;
	cout<<n;
	return 0;
}


Measured memory_bytes: 3624
def tow_pointers(Q=1):

    # Q回分のクエリを処理
    for i in range(Q):

        # 合計値
        res = 0

        # 区間の左端で場合分け
        right = 0
        cnt = 0

        for left in range(n):
            while right < len(a) and a[left] + 2 >= a[right]:
                cnt += 1
                right += 1

            res = max(res, cnt)

            # leftをインクリメントする準備
            if right == left: right += 1
            else: cnt -= 1

        print(res)


n = int(input())
a = list(map(int, input().split()))
a.sort()
tow_pointers()


Measured memory_bytes: 20904
/*----------------
     Smit Patel
     DA-IICT
----------------*/
#include<iostream>
#include<bits/stdc++.h>
using namespace std;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define ins insert
#define fori(i,a,n) for(int i=a; i<n; i++)
#define ford(i,a,n) for(int i=a; i>n; i--)
#define clr(a,b) memset(a,b,sizeof(a))
#define deb(x) cout<<#x<<" : "<<x<<endl;
#define debug(x,y) cout<<#x<<" : "<<x<<"\t"<<#y<<" : "<<y<<endl;
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define bp __builtin_popcount
#define mod 1000000007
#define eps 1e-6
#define infi 1000000002
#define infll 1e18+5
#define N 200005
#define LN 20

typedef long double ld;
typedef long long ll;
typedef map<ll,ll> mll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef set<ll> sll;

ll choose(ll n,ll k);
bool isprime(ll n);
ll power(ll x,ll y,ll p);
ll power(ll x,ll y);
ll gcd(ll a,ll b);

int main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.tie(0);
  ll n,k;
  cin>>n>>k;
  ll a[n];
  fori(i,0,n)
  {
    cin>>a[i];
  }
  ll dp[n+1]={};
  fori(i,1,n)
  {
    dp[i]=infi;
    fori(j,1,k+1)
    {
      if(i-j>=0) dp[i]=min(dp[i],dp[i-j]+abs(a[i]-a[i-j]));
    }
  }
  cout<<dp[n-1]<<endl;
  return 0;
}

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

ll choose(ll n,ll k)
{
  if(k==0)
    return 1;
  return (n* choose(n-1,k-1))/k;
}

bool isprime(ll n)
{
  for(ll i=2;i*i<=n;i++)
  {
    if(n%i==0)
      return false;
  }
  return true;
}

ll power(ll x,ll y,ll p)
{
  ll res=1;
  x=x%p;
  while(y>0)
  {
    if(y&1)
      res=(res*x)%p;
    y=y>>1;
    x=(x*x)%p;
  }
  return res;
}

ll power(ll x,ll y)
{
  ll res=1;
  while(y>0)
  {
    if(y&1)
      res=res*x;
    y=y>>1;
    x=x*x;
  }
  return res;
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, a, b;
	cin >> n >> a >> b;
	ll mi = a*(n-1)+b, ma = b*(n-1)+a;
	ll ans = ma - mi + 1LL;
	chmax(ans, 0LL);
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <string>
#include <queue>
#include <map>
#include <utility>
#include <iomanip>  // std::setprecision()
#include <set>

using namespace std;
using ll = long long;
#define rep(i,a,b) for(ll i=(a); i<(b); i++)
#define YES cout << "YES" << endl;
#define NO cout << "NO" << endl;
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define pai 3.14159265358979323846
ll gcd(ll a, ll b){if (a%b == 0)  return(b);else  return(gcd(b, a%b));}
ll lcm(ll a, ll b){return a * b / gcd(a, b);}

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

  // for prime mod
  mint inv() const { return pow(mod-2);}
  mint& operator/=(const mint a) { return *this *= a.inv();}
  mint operator/(const mint a) const { return mint(*this) /= a;}
};
istream& operator>>(istream& is, mint& a) { return is >> a.x;}
ostream& operator<<(ostream& os, const mint& a) { return os << a.x;}
/* map<string,int> */
/* 大文字を小文字に変換 tolower*/
/* 小文字を大文字に変換 toupper*/
/* 辞書順 next_permutation(a.begin(),a.end()) */
void printVec(std::vector<char> &vec) {
  std::cout << "";
  for (auto it = vec.begin(); it != vec.end(); ++it) {
    std::cout << *it << " ";
  }
  std::cout << std::endl;
}


int main() {
    string s;
    cin >>s;
    ll k;
    cin >>k;
    if (s[0] != '1') {
        cout << s[0] << endl;
    } else {
        ll i =0;
        while (s[i] == '1') {
            if (i == k-1) break;
            ++i;
        }
        cout << s[i] << endl;
    }
}

Measured memory_bytes: 3092
n = gets.to_i
p = gets.split.map(&:to_i)

count = 0

a = p[-1]

p.each_with_index do |elem, i|
  next if (i == 0) || (elem == a)
  temp_array = [p[i-1], p[i], p[i+1]]
  count += 1 if (temp_array.sort[1] == elem)
end

p count


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

using namespace std;

int main() {
	double A, B;
	cin >> A >> B;
	double init_price = ceil(A / 0.08);
	while(floor(init_price * 0.08) == A) {
		if(floor(init_price * 0.1) == B) {
			cout << init_price << "\n";
			return 0;
		}
		init_price++;
	}
	cout << "-1\n";
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
const int MAXN = 1000000;
const int mod = 1e9 + 7;
typedef pair<int, int> pi;

int dis[MAXN];
priority_queue<pi, vector<pi>, greater<pi> > pq;

int main(){
	int n;
	cin >> n;
	memset(dis, 0x3f, sizeof(dis));
	for(int i=1; i<=9; i++){
		if(dis[i % n] > i){
			dis[i % n] = i;
			pq.push(pi(i, i % n));
		}
	}
	while(!pq.empty()){
		auto x = pq.top();
		pq.pop();
		if(dis[x.second] != x.first) continue;
		for(int i=0; i<10; i++){
			int nxt = 10 * x.second + i;
			nxt %= n;
			if(dis[nxt] > dis[x.second] + i){
				dis[nxt] = dis[x.second] + i;
				pq.push(pi(dis[nxt], nxt));
			}
		}
	}
	cout << dis[0] << endl;
}


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

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

  ll ans = 0;
  ll temp = 0;
  if (N % 2 == 0) {
    temp = N / 2;
    while (temp > 0) {
      temp /= 5;
      ans += temp;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
typedef long long ll;
int main() {
  int n;
  cin >> n;
  ll ans=0;
  for (int i = 1; i <= n; ++i) {
    if (!(i % 3 == 0 || i % 5 == 0)) {
      ans += i;
    }
  }
  cout << ans;
}

Measured memory_bytes: 3640
import sys
from itertools import combinations

sys.setrecursionlimit(10 ** 6)
int1 = lambda x: int(x) - 1
p2D = lambda x: print(*x, sep="\n")
def II(): return int(sys.stdin.readline())
def MI(): return map(int, sys.stdin.readline().split())
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

class BitSum:
    def __init__(self, n):
        self.n = n + 3
        self.table = [0] * (self.n + 1)

    def add(self, i, x):
        i += 1
        while i <= self.n:
            self.table[i] += x
            i += i & -i

    def sum(self, i):
        i += 1
        res = 0
        while i > 0:
            res += self.table[i]
            i -= i & -i
        return res

def main():
    def ng():
        px=-1
        for i in range(n):
            if i % 2:
                x = xx1[i // 2][1]
            else:
                x = xx0[i // 2][0]
            if x<px:return True
            px=x
        return False

    def change(ans):
        res=0
        bit=BitSum(n)
        for i,k in enumerate(kk):
            res+=i-bit.sum(k)
            if res>ans:return ans
            bit.add(k,1)
        return res

    n = II()
    aa = LI()
    bb = LI()
    ab = []
    for i, (a, b) in enumerate(zip(aa, bb)):
        if i % 2:
            ab.append([b, a, i])
        else:
            ab.append([a, b, i])
    ans=1000
    for odd in combinations(range(n), n // 2):
        isodd = [False] * n
        xx0 = []
        xx1 = []
        for i in odd:
            xx1.append(ab[i])
            isodd[i] = True
        for i in range(n):
            if isodd[i]: continue
            xx0.append(ab[i])
        xx0.sort(key=lambda x: (x[0],x[2]))
        xx1.sort(key=lambda x: (x[1],x[2]))
        #print(xx0)
        #print(xx1)
        if ng():continue
        kk=[]
        for [_,_,i0],[_,_,i1] in zip(xx0,xx1):
            kk+=[i0,i1]
        if n%2:kk+=[xx0[-1][2]]
        #print(kk)
        ans=change(ans)
        #print(ans,xx0,xx1)
    if ans==1000:print(-1)
    else:print(ans)

main()


Measured memory_bytes: 3192
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main{

	public static void main(String[] args) throws IOException {
		// TODO 自動生成されたメソッド・スタブ
		BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
		int inputInt;

		inputInt = Integer.parseInt(input.readLine());

		int x1, x2, x3;

		for (int i = 1; i <= inputInt; i++) {
			x1 = i / 10; // 10の位が3になる数値を判定
			x2 = i / 100; // 100の位が3になる数値を判定
			x3 = i / 1000; // 1000の位が3になる数値を判定

			if (i % 3 == 0 || i % 10 == 3 || x1 % 10 == 3 || x2 % 10 == 3 || x3 % 10 == 3) {

				System.out.print(" " + i);

			}
		}
		System.out.println();

	}

}



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

	public static void main(String[]agrs){
		Scanner sc = new Scanner(System.in);
		IX:while(true) {
			int n = sc.nextInt();
			if(n == 0) break;
			boolean[][] a = new boolean[n][n];
			for(int i = 0; i < n; i++) {
				a[i][i] = true;
			}
			int[][] b = new int[n][];
			for(int i = 0; i < n; i++) {
				int l = sc.nextInt();
				b[i] = new int[l];
				for(int j = 0; j < l ; j++) {
					b[i][j] = sc.nextInt();
				}
			}
			
			for(int i = 1; i <= 30; i++) {
				for(int j = 0; j < n; j++) {
					for(int k = 0; k < b[j].length; k++) {
						if(b[j][k] == i) {
							for(int l = 0; l < n; l++) {
								for(int m = 0; m < b[l].length; m++) {
									if(b[l][m] == i) {
										for(int N = 0; N < n; N++) {
											if(a[j][N]) {
												a[l][N] = true;
											}
											if(a[l][N]) {
												a[j][N] = true;
											}
										}
									}
								}
							}
						}
					}
					
				}
				
				IN:for(int j = 0; j < n; j++) {
					for(int k = 0; k < n; k++) {
						if(!a[j][k])continue IN;
					}
					System.out.println(i);
					continue IX;
				}
			}
			System.out.println(-1);
		}
	}
}

Measured memory_bytes: 65692
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = Integer.parseInt(sc.next());
        int count = 0;
        for(int i=0; i<3; i++) {
            if ((a % 10) == 1) {
                count++;
            }
            a /= 10;
        }
        System.out.println(count);
    }
}


Measured memory_bytes: 23252
#include<iostream>
#include<vector>
#include<cmath>
#include<algorithm>
using namespace std;
int main()
{
	int a[4];
	cin>>a[0]>>a[1]>>a[2]>>a[3];
	if((a[1]<=a[2])||(a[3]<=a[0]))
        cout<<'0';
    else
    {
    	sort(a,a+4);
    	cout<<a[2]-a[1];
	}
}

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

using namespace std;

const int MOD = 1000000007;

int main(){
    const int maxSize = 100001;
    vector<long long> inv(maxSize);
    vector<long long> fact(maxSize);
    vector<long long> factInv(maxSize);
    for(int i=0;i<2;i++) inv[i] = fact[i] = factInv[i] = 1;
    for(int i=2;i<maxSize;i++){
        inv[i] = inv[MOD % i] * (MOD - MOD / i) % MOD;
        fact[i] = fact[i-1] * i % MOD;
        factInv[i] = factInv[i-1] * inv[i] % MOD;
    }
    int N, X; cin >> N >> X;
    vector<int> S(N);
    for(auto& t : S) cin >> t;
    sort(S.begin(), S.end());
    vector<int> sum(100001, 0);
    for(auto& t : S) sum[t] = 1;
    for(int i=1;i<=100001;i++) sum[i] += sum[i-1];
    vector dp(X+1, vector(N+1, 0LL));
    dp[X][N-sum[X]] = 1;
    for(int i=X;i>=S[0];i--){
        for(int j=N;j>=0;j--){
            if(!dp[i][j]) continue;
            if(j > 0){
                dp[i][j-1] += dp[i][j] * j;
                dp[i][j-1] %= MOD;
            }
            for(int k=0;k<sum[i];k++){
                int dst = i%S[k];
                int add = sum[i] - sum[dst] - 1;
                dp[dst][j+add] += dp[i][j];
                dp[dst][j+add] %= MOD;
            }
        }
    }
    long long res = 0;
    for(int i=1;i<S[0];i++){
        for(int j=0;j<=N;j++){
            res += dp[i][j] * fact[j] % MOD * i % MOD;
            res %= MOD;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 166124
//#include <bits/stdc++.h>
//#include <stdio.h>
#include<iostream>
#include<cstdio>
#include<bitset>
#include<algorithm>
#include<vector>
#include<list>
#include<queue>
#include<stack>
#include<string>
#include<string.h>
#include<cmath>
#include<utility>
#include<functional>
#include<map>
#include<set>
#include<cctype>
#include<fstream>
#include <numeric>
#include <iomanip>
 
#define FOR(i, a, b) for( int i=(a);i<=(b);i++)
#define RFOR(i, a, b) for( int i=(a);i>=(b);i--)
#define LFOR(i, a, b) for( long long int i=(a);i<=(b);i++)
#define LRFOR(i, a, b) for(long long int i=(a);i>=(b);i--)
#define MOD 1000000007
using namespace std;
using ll=long long;
constexpr ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
constexpr ll lcm(ll a,ll b){return a*b/gcd(a,b);}
constexpr ll abs(ll a,ll b){
if(a>=b)return a-b;
if(a<b)return b-a;
}

int main() {
ll N;
ll ans=0;
cin >> N;

ll A[N],B[N];

FOR(i,0,N-1){
cin >> A[N-1-i]>>B[N-1-i];
}

FOR(i,0,N-1){
  if((A[i]+ans)%B[i]!=0){
    ll sabun;
    sabun = B[i]-(A[i]+ans)%B[i];
    ans=ans+sabun;

  }
}

cout <<ans << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <algorithm>
#define maxn 200010
#define LL long long
using namespace std;
int a[maxn];
LL dp[maxn],sum[maxn];
int main(){
	int n,i;
	scanf("%d",&n);
	for(i=1;i<=n;i++)scanf("%d",&a[i]);
	for(i=1;i<=n;i++)
		if(i%2)sum[i]=sum[i-1]+a[i];
		else sum[i]=sum[i-1];
	for(i=2;i<=n;i++)
		if(i&1)dp[i]=max(dp[i-2]+a[i],dp[i-1]);//i是奇数,i/2==(i-1)/2
		else dp[i]=max(dp[i-2]+a[i],sum[i-1]);//i是偶数
	printf("%lld\n",dp[n]);
	return 0;
}

Measured memory_bytes: 5628
#include<bits/stdc++.h>
#include<map>
#define ll long long int
#define ld long double
#define pb push_back
#define forn(i, n) for (int i = 0; i < int(n); i++)
#define mod 1000000007
#define MAX 200010
//#define endl '\n'
#define mp make_pair
#define INF 10000000
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
#define ff first
#define ss second
#define ps(x,y) fixed<<setprecision(y)<<x
#define pii pair<long long int,long int>
#define mii map<long long int,long long int>
#define w(t) 	int t; cin>>t; while(t--)
#define coutyes cout<<"Yes"
#define coutno cout<<"No"
#define pi 3.141592653589793238
using namespace std;

int main() {
	int n;
	cin>>n;
	int x=n%10;
	if(x==3)	cout<<"bon";
	else if(x==0||x==1||x==6||x==8)	cout<<"pon";
	else	cout<<"hon";
}
 

Measured memory_bytes: 3648
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define INF (1<<30)
#define INFLL (1ll<<60)
typedef pair<double, int> P;
typedef pair<int, P> E;
#define MOD (1000000007ll)
#define l_ength size
#define EPS (1e-10)

void add_mod(ll &a, ll b){
	a += b;
	a %= MOD;
}

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

int main(void){
	int a,b;
	cin >> a >> b;
	if(a+b == 15){
		cout << "+" << endl;
	}else if(a*b==15){
		cout << "*" << endl;
	}else{
		cout << "x" << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int isSquare(int D,int X[],int Y[]);

int main(){
  int N,D;
  int X[10][10];
  int cnt=0;

  scanf("%d %d",&N,&D);
  for(int n=0;n<N;n++)
    for(int d=0;d<D;d++)
      scanf("%d",&X[n][d]);

  for(int n=0;n<N;n++)
    for(int m=0;m<N;m++)
      if(n!=m && isSquare(D,X[n],X[m]))
	cnt++;

  printf("%d\n",cnt/2);
  
  return 0;
}

int isSquare(int D,int X[],int Y[]){
  int s=0,flag=0;
  for(int d=0;d<D;d++)
    s+=(X[d]-Y[d])*(X[d]-Y[d]);

  
  for(int r=0;r<130;r++)
    if(s==r*r)
      flag++;

  return flag;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<iostream>
#include<string>
#include<algorithm>
#include<vector> 
#include<limits>
#include<numeric>
#include<type_traits>
#include<math.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define in(x) cin >> x
#define out(str) cout << str << endl

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



int main(){
    int A[3];
    rep(i,3)cin>>A[i];
    sort(A,A+3);
out(A[2]*10+A[1]+A[0]);

}


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

#define EPS (1e-10)
#define rep(i, a, b) for (int i = a; i < (int)(b); ++i)
#define rrep(i, a, b) for (int i = b - 1; i >= (int)(a); --i)
#define all(a) a.begin(), a.end()

using namespace std;
using ll = long long;
using vi = vector<int>;
using vb = vector<bool>;
using vll = vector<ll>;
using vd = vector<double>;
using vvi = vector<vi>;
using vvb = vector<vb>;

constexpr int MOD = 1000000007;

struct V {
    ll val;
    int l, m, n;

    V(ll val = 0, int l = 0, int m = 0, int n = 0) : val(val), l(l), m(m), n(n) {}
    bool const operator<(const V& v) const { return val < v.val; }
};

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

    int x, y, z, k;
    cin >> x >> y >> z >> k;

    vll a(x), b(y), c(z);
    rep(i, 0, x) { cin >> a[i]; }
    rep(i, 0, y) { cin >> b[i]; }
    rep(i, 0, z) { cin >> c[i]; }

    sort(all(a), greater<ll>());
    sort(all(b), greater<ll>());
    sort(all(c), greater<ll>());

    vector<vvb> seen(x, vvb(y, vb(z, false)));
    seen[0][0][0] = true;

    priority_queue<V> pq;
    pq.emplace(a[0] + b[0] + c[0], 0, 0, 0);

    rep(_, 0, k) {
        V p = pq.top();
        pq.pop();
        cout << p.val << endl;

        if (p.l + 1 < x && !seen[p.l + 1][p.m][p.n]) {
            pq.emplace(a[p.l + 1] + b[p.m] + c[p.n], p.l + 1, p.m, p.n);
            seen[p.l + 1][p.m][p.n] = true;
        }

        if (p.m + 1 < y && !seen[p.l][p.m + 1][p.n]) {
            pq.emplace(a[p.l] + b[p.m + 1] + c[p.n], p.l, p.m + 1, p.n);
            seen[p.l][p.m + 1][p.n] = true;
        }

        if (p.n + 1 < z && !seen[p.l][p.m][p.n + 1]) {
            pq.emplace(a[p.l] + b[p.m] + c[p.n + 1], p.l, p.m, p.n + 1);
            seen[p.l][p.m][p.n + 1] = true;
        }
    }

    return 0;
}

Measured memory_bytes: 180352
def sumArray(n):
    sum = 0
    for i in range(len(n)):
        sum += n[i]
    return sum

n = int(input())
t = list(map(int, input().rstrip().split()))
m = int(input())
sum = sumArray(t)
temp = sum
for i in range(m):
    data = list(map(int, input().split()))
    sum = sum - t[data[0] - 1] + data[1]
    print(sum)
    sum = temp

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
using ll = int64_t;

void main_()
{
    ll N, Q;
    cin >> N >> Q;
    string S;
    cin >> S;

    ll ac_sum = 0;
    vector<ll> ac_sums;
    ac_sums.reserve(N);
    ac_sums.push_back(0);
    for (ll i = 1; i < N; ++i) {
        if (S[i - 1] == 'A' && S[i] == 'C') {
            ac_sum++;
        }
        ac_sums.push_back(ac_sum);
    }

    while (Q--) {
        ll l, r;
        cin >> l >> r;
        l--;
        r--;

        ll ans = ac_sums[r] - ac_sums[l];
        cout << ans << "\n";
    }
}
int main()
{
    cin.tie(nullptr);
    cout.tie(nullptr);
    ios_base::sync_with_stdio(false);
    main_();
    return 0;
}


Measured memory_bytes: 1872
/*
 * ALDS1_11_B.cpp
 *
 *  Created on: May 5, 2018
 *      Author: 13743
 */

#include<iostream>
#include<vector>
#include<stack>

using namespace std;

int d[101];
int f[101];
int nowTime;

stack<int> st;

void dfsRec(vector<int>* a, int v) {
	if(d[v] > 0) return;
	nowTime++;
	d[v] = nowTime;
	for(int &x:a[v]) {
		dfsRec(a, x);
	}
	nowTime++;
	f[v] = nowTime;
}

void dfsStack(vector<int>* a, int rt) {
	st.push(rt);
	while(!st.empty()) {
		int v = st.top();
		if(d[v] == 0) d[v] = ++nowTime;
		bool found = false;
		for(int &x:a[v]) {
			if(d[x] == 0) {
				st.push(x); found = true; break;
			}
		}
		if(!found) {
			st.pop();
			f[v] = ++nowTime;
		}
	}
}

int main() {
	int n;
	vector<int> adj[101];

	cin >> n;
	for(int i=0; i<n; i++) {
		int v;
		int k;
		cin >> v >> k;
		for(int j=0; j<k; j++) {
			int u;
			cin >> u;
			adj[v].push_back(u);
		}
	}

	for(int i=1; i<=n; i++) {
		if(d[i] ==0) dfsStack(adj, i);
	}

//	for(int i=1; i<=n; i++) {
//		if(d[i] ==0) dfsRec(adj, i);
//	}

	for(int i=1; i<=n; i++) {
		cout << i << " " << d[i] << " " << f[i] << endl;
	}
}





Measured memory_bytes: 3128
#include <iostream>
#include <cstring>

using namespace std;

const int MAX_M = 7;
const int MAX_G = 10;
const int MAX_K = 1000;
int m;  // カードの種類 1<= m <= 7
int a[MAX_M], b[MAX_M]; // a: カードに書かれた数字 b: 枚数
int g; // ゲームの回数
int n[MAX_G];
int K;
int dp[MAX_M + 1][MAX_K + 1];

void solve()
{
    memset(dp, 0, sizeof(dp));
    dp[0][0] = 1;

    for (int i = 0; i < m; i++)
        for (int j = 0; j <= K; j++)
            for (int k = 0; k <= b[i] && k * a[i] <= j; k++)
                dp[i + 1][j] += dp[i][j - k * a[i]];
}

int main()
{
    while (cin >> m, m) {
        for (int i = 0; i < m; i++)
            cin >> a[i] >> b[i];
      
        K = 0;
        cin >> g;
        for (int i = 0; i < g; i++) {
            cin >> n[i];
            K = max(K, n[i]);
        }
        solve();

        for (int i = 0; i < g; i++)
            cout << dp[m][n[i]] << endl;
    }


    return 0;
}

Measured memory_bytes: 1200
import sys

N,M=map(int,input().split())
X=list(map(int,input().split()))
X.sort()

if N>=M:
    print(0)
    sys.exit()


SA=[]
for i in range(1,M):
    SA.append(X[i]-X[i-1])

SA.sort()
print(sum(SA[:M-N]))

Measured memory_bytes: 13968