akhauriyash/Code-Regression huggingface dataset:
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np
from numpy.fft import rfft, irfft
MOD = 10 ** 9 + 7
K = [int(x) for x in input().rstrip()]
L = len(K)
D = int(input())

def convolve_ones(x,arr):
    # 0,1,...,x-1
    after = np.zeros(D+x,dtype=np.int64)
    for i in range(x):
        after[i:i+D] += arr
    for i in range(D,D+x):
        after[i%D]+= after[i]
    return after[:D] % MOD

# d桁以下、自由に使った場合の余りごとの個数。0を含めて数えておく
full = [np.zeros(D, dtype=np.int64)]
full[0][0] = 1
for d in range(1,L):
    full.append(convolve_ones(10,full[-1]))

dist = np.zeros(D+D, dtype=np.int64)

cumsum = 0
for i,x in enumerate(K):
    arr = convolve_ones(x, full[L-i-1])
    dist[cumsum:cumsum+D] += arr
    cumsum += x
    cumsum %= D
dist[cumsum] += 1 # 全部そのまま使う

answer = dist[::D].sum() - 1 # 0除外
answer %= MOD
print(answer)

Measured memory_bytes: 22916
#include <iostream>
#include<stdio.h>
using namespace std;
#define pqMAX 2000000
#define INFTY 1<<30
class priority_queue
{
public:
	priority_queue() :H(0) {};
	void insert(int key) {
		++H;
		data[H] = -INFTY;
		heapIncreaseKey(H, key);
	}
	int extractMax() 
	{
		int max = data[1];
		data[1] = data[H];
		--H;
		maxHeapify(1);
		return max;
	}
private:
	int H;
	int data[pqMAX];
	inline int parent(int i) {
		return i / 2;
	}

	inline int leftson(int i) {
		return 2 * i;
	}

	inline int rightson(int i) {
		return 2 * i + 1;
	}
	inline void exchange(int &a, int &b)
	{
		int c = a;
		a = b;
		b = c;
	}
	void maxHeapify(int i) {
		int l = leftson(i);
		int r = rightson(i);
		int max = l;
		if (r <= H){
			if (data[l] < data[r])max = r;
		}
		else if (l > H) return;
		if (data[i]>data[max])return;
		exchange(data[i], data[max]);
		maxHeapify(max);
	}
	void buidup() {
		for (int i = H / 2; i>0; --i) {
			maxHeapify(i);
		}
	}
	void heapIncreaseKey(int i,int key) 
	{
		if (key < data[i]){
			printf("Error,the value of key is too low.\n");
			return;
		}
		else data[i] = key;
		//maybe become the minheap by changing the i/2 to i in "while loop" below.
		while (i/2 > 0 && data[i] > data[i / 2]) 
		{
			exchange(data[i], data[i / 2]);
			i /= 2;
		}
	}
};

int main()
{
	priority_queue mark;
	char tmp[20];
	int G;
	while (cin >> tmp)
	{
		if ('i'==tmp[0] ){
			cin >>G;
			mark.insert(G);
		}
		else if ( 'x' ==tmp[1]) {
			cout << mark.extractMax() << endl;;
		}
		else return 0;
	}
	return 0;
}




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

int main()
{
	int64_t n, k;
	cin >> n >> k;

	int64_t ans = 0, mod = 1000000007;
	for (int64_t i = k; i <= n + 1; i++)
	{
		(ans += (i * (n - i + 1) % mod + 1) % mod) %= mod;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3632
//package ABC173;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc =new Scanner(System.in);
		int n=sc.nextInt();
		if(n%1000==0)
		{
			System.out.println(0);
		}
		else
		{
			System.out.println(1000-n%1000);
		}
		
		

	}

}


Measured memory_bytes: 35652
#include <bits/stdc++.h>
#define REP(i, n) for(ll i = 0; i < (ll)n; i++)
#define FOR(i, a, b) for(ll i = (a); i < (ll)b; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1000000000000000
using namespace std;
typedef long long ll;
typedef double db;
typedef string str;
typedef pair<ll, ll> p;
constexpr int MOD = 1000000007;
using ll = long long;
template <class T> inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T> inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

void print(const std::vector<int> &v) {
    std::for_each(v.begin(), v.end(), [](int x) { std::cout << x << " "; });
    std::cout << std::endl;
}

int main() {
    int N;
    cin >> N;
    vector<long long> A(N + 1), B(N);
    REP(i, N + 1) { cin >> A[i]; }
    long long f = accumulate(A.begin(), A.end(), 0LL);
    REP(i, N) { cin >> B[i]; }
    REP(i, N) {
        // cout << B[i] << A[i] << endl;
        if(A[i] >= B[i]) {
            A[i] -= B[i];
            B[i] = 0;
        } else {
            B[i] -= A[i];
            A[i] -= A[i];
            if(B[i] >= 0) {
                if(A[i + 1] >= B[i]) {
                    A[i + 1] -= B[i];
                    B[i] = 0;
                } else {
                    // cout << A[i + 1] << B[i] << endl;
                    B[i] -= A[i + 1];
                    A[i + 1] -= A[i + 1];
                }
            }
        }
    }
    // REP(i, N + 1) { cout << A[i]; }
    // cout << endl;
    cout << f - accumulate(A.begin(), A.end(), 0LL) << endl;
    return 0;
}

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

map<char,int> ma;
char c;
int main(){
	for(int i = 0; i < 4; i++){
	cin >> c;
	ma[c]++;
	}
	for(auto u : ma){
		if(u.second != 2){cout << "No\n"; return 0;}
	}
	cout << "Yes\n";
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cmath>
#include<vector>
#include<queue>
#include<map>
#include<algorithm>
#include<set>
#include<complex>
#include<string>
#include<cstring>
using namespace std;
#define rep2(x,from,to) for(long long x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
#define INF 100000000
#define debug(x) cout<<#x<<": "<<x<<endl
#define MOD 1000000007
#define all(x) x.begin(),x.end()
typedef pair<long long,long long> P;
typedef pair<long long,P> PP;
long long ans;

long long L;
string s,t;
long long dp[53][4][4];
int main()
{
	cin>>L;
	cin>>s;
	cin>>t;
	dp[0][0][0]=1;
	rep2(i,1,L+1)
	{
		if(s[i-1]==t[i-1])
		{
			rep2(j,1,4)//next
			{
				rep(k,4)rep(l,4)
				{
					if(j!=k&&j!=l)
					{
						dp[i][j][j]+=dp[i-1][k][l];
						dp[i][j][j]%=MOD;
					}
				}
			}
		}
		else
		{
			i++;
			rep2(j,1,4)rep2(k,1,4)
			{
				if(j==k)continue;
				rep(l,4)rep(m,4)
				{
					if(j!=l&&k!=m)
					{
						dp[i][j][k]+=dp[i-2][l][m];
						dp[i][j][k]%=MOD;
					}
				}
			}
		}
	}
	rep(i,4)rep(j,4)
	{
		ans+=dp[L][i][j];
		ans%=MOD;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <map>
#include <vector>
#include <stack>
#include <queue>
#define MAX 1000000
typedef long long int ll;

using namespace std;

bool isprime[MAX];
int prime[MAX];

void sieve()
{
    isprime[1]=1;
    for(int i=2;i<=sqrt(MAX);i++){
        if(!isprime[i]){
            for(int j=i*i;j<=MAX;j+=i){
                isprime[j]=true;
            }
        }
    }
    int count=0;
    for(int k=1;k<=MAX;k++){
        if(!isprime[k])prime[k]=++count;
        else prime[k]=count;
    }
}

int main()
{
    sieve();
    int n;
    while(scanf("%d",&n)==1){
        printf("%d\n",prime[n]);
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

map<ll, ll> mmap;
int N, M;
ll A, B, C;

int main() 
{
	cin>>N>>M;
	for (int i = 0; i < N; i++) {
		cin>>A;
		mmap[-A]++;
	}
	for (int i = 0; i < M; i++) {
		cin>>B>>C;
		mmap[-C] += B;
	}
	ll sol = 0;
	ll cnt = N;
	for (auto it = mmap.begin(); it != mmap.end(); it++) {
		ll cost = min(cnt, it->second);
		if (cost == 0) 
		    break;
		sol -= it->first*cost;
		cnt -= cost;
	}
	cout<<sol<<endl;
}

Measured memory_bytes: 12800
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<cassert>
#include<iostream>
#include<sstream>
#include<string>
#include<vector>
#include<queue>
#include<set>
#include<map>
#include<utility>
#include<numeric>
#include<algorithm>
#include<bitset>
#include<complex>

using namespace std;

typedef long long Int;
typedef vector<int> vint;
typedef pair<int,int> pint;
#define mp make_pair

template<class T> void pv(T a, T b) { for (T i = a; i != b; ++i) cout << *i << " "; cout << endl; }
template<class T> void chmin(T &t, T f) { if (t > f) t = f; }
template<class T> void chmax(T &t, T f) { if (t < f) t = f; }
int in() { int x; scanf("%d", &x); return x; }

vector<string> res;

int main() {
	int n=in();
	while(n--){
		res.clear();
		string str;
		cin>>str;
		int i;
		for(i=1;i<str.size();i++){
			string buf,buf1,buf2;
			buf1=str.substr(0,i);
			buf2=str.substr(i);
			buf=buf1+buf2;
			if(find(res.begin(),res.end(),buf)==res.end())res.push_back(buf);
			buf=buf2+buf1;
			if(find(res.begin(),res.end(),buf)==res.end())res.push_back(buf);
			reverse(buf2.begin(),buf2.end());
			buf=buf1+buf2;
			if(find(res.begin(),res.end(),buf)==res.end())res.push_back(buf);
			buf=buf2+buf1;
			if(find(res.begin(),res.end(),buf)==res.end())res.push_back(buf);
			reverse(buf1.begin(),buf1.end());
			reverse(buf2.begin(),buf2.end());
			buf=buf1+buf2;
			if(find(res.begin(),res.end(),buf)==res.end())res.push_back(buf);
			buf=buf2+buf1;
			if(find(res.begin(),res.end(),buf)==res.end())res.push_back(buf);
			reverse(buf2.begin(),buf2.end());
			buf=buf1+buf2;
			if(find(res.begin(),res.end(),buf)==res.end())res.push_back(buf);
			buf=buf2+buf1;
			if(find(res.begin(),res.end(),buf)==res.end())res.push_back(buf);
		}
		cout<<res.size()<<endl;
	}
	return 0;
}

Measured memory_bytes: 1012
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

constexpr int INF = 1 << 30;

void solve() {
    int min, sum = 0;

    min = INF;
    for (int i = 0; i < 3; ++i) {
        int x;
        std::cin >> x;
        min = std::min(min, x);
    }
    sum += min;

    min = INF;
    for (int i = 0; i < 2; ++i) {
        int x;
        std::cin >> x;
        min = std::min(min, x);
    }
    sum += min;

    std::cout << sum - 50 << std::endl;
}

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

    solve();

    return 0;
}



Measured memory_bytes: 3216
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <string>
#include <map>
#include <unordered_map> //C++11
#include <queue>
#include <functional>
using namespace std;

typedef long long ll;

int n, p;
int a[102];
ll e[102], o[102];

int main() {
	cin >> n >> p;
	e[0] = 1;
	o[0] = 0;
	for (int i = 1; i <= n; i++) {
		cin >> a[i];
		if (a[i] % 2 == 1) {
			e[i] = o[i - 1] + e[i - 1];
			o[i] = e[i - 1] + o[i - 1];
		}
		else {
			e[i] = 2 * e[i - 1];
			o[i] = 2*o[i - 1];
		}
	}
	if (p % 2 == 0) cout << e[n] << endl;
	else cout << o[n] << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
def linput():
    return list(map(int, input().split()))

def main():
    # N = int(input())
    N,M = linput()
    # vA = linput()
    # S = input()
    # mX = [linput() for _ in [0,]*N]

    # res = 0
    if N%2 and M%2:
        res = -(-N*M//2)
    else:
        res = N*M//2

    if N==1 or M==1:
        res = 1

    print(res)

main()


Measured memory_bytes: 2940
x, y, a, b, c = map(int,input().split())
p = list(map(int,input().split()))
q = list(map(int,input().split()))
r = list(map(int,input().split()))

p.sort(reverse=True)
q.sort(reverse=True)

r = p[:x] + q[:y] + r
r.sort(reverse=True)
r = r[:x+y]

print(sum(r))

Measured memory_bytes: 23328
#include<bits/stdc++.h>
using namespace std;
int n=0;
int id(int a ,int b,int c){
    return a*(n+1)*(n+1)+b*(n+1)+c;
}
double pr(double a[],int p ,int q, int r){
    double n1 =n;
    double p1 =p;
    double q1 =q;
    double r1 =r;
    if(a[id(p,q,r)]!=-1)return a[id(p,q,r)];
    if((p==0)&&(q==0)&&(r==1)) return n1;
    double y =p1+q1+r1;
    double x = 0;
    if(p>0) x+=(p1/y)*(pr(a,p-1,q+1,r));
    if(q>0) x+=(q1/y)*(pr(a,p,q-1,r+1));
    if(r>0) x+=(r1/y)*(pr(a,p,q,r-1));
    //cout<<n<<" "<<y<<" "<<p<<" "<<q<<" "<<r<<" "<<x<<endl;
    x=x+n1/y;
    a[id(p,q,r)] = x;
    return x;
}
int main()
{
    scanf("%d",&n);
    int c1=0,c2=0,c3=0;
    for(int i=0;i<n;i++){
        int x;
        scanf("%d",&x);
        if(x==3)c1++;
        if(x==2)c2++;
        if(x==1)c3++;
    }
    double a[(n+1)*(n+1)*(n+1)];
    for(int i=0;i<=n;i++){
        for(int j=0;j<n+1;j++){
            for(int k=0;k<=n;k++)
                a[id(i,j,k)]=-1;
        }
    }
    printf("%.10f\n",pr(a,c1,c2,c3));
    return 0;
}


Measured memory_bytes: 213376
k = int(input())
s = input()
MOD = 10**9+7

FAC = [1]
INV = [1]
for i in range(1,len(s)+k+1):
  FAC.append((FAC[i-1]*i) % MOD)
  INV.append(pow(FAC[-1],MOD-2,MOD))

def nCr(n,r):
  return FAC[n]*INV[n-r]*INV[r]

p25 = [1]
for i in range(len(s)+k):
  p25.append((p25[-1]*25)%MOD)
p26 = [1]
for i in range(len(s)+k):
  p26.append((p26[-1]*26)%MOD)

ans = 0
for i in range(len(s),len(s)+k+1):
  tmp = nCr(i-1,len(s)-1)*p25[i-len(s)]
  tmp %= MOD
  tmp *= p26[len(s)+k-i]
  tmp %= MOD
  ans +=tmp
  ans %= MOD
print(ans)

Measured memory_bytes: 233592
#![allow(unused_mut)]

use std::io::{self, BufWriter, Write};
use std::error::Error;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

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

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

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

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

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

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

fn main() -> Result<(), Box<dyn Error>> {
    let sout = io::stdout();
    let mut o = BufWriter::new(sout.lock());
  
    input! {
        // input
        x : i32,
    }

    // operate
    let q = if x < 600 {
        8
    } else if x < 800 {
        7
    } else if x < 1000 {
        6
    } else if x < 1200 {
        5
    } else if x < 1400 {
        4
    } else if x < 1600 {
        3
    } else if x < 1800 {
        2
    } else {
        1
    };

    let line = format!("{}\n", q);
    o.write(line.as_bytes())?;
    Ok(())
  }


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

// MACROS SAMPAH
#define Jehian using
#define Norman namespace
#define Saviero std

Jehian Norman Saviero;

// MACROS TYPE
typedef long l;
typedef long long ll;
typedef unsigned long ul;
typedef unsigned long long ull;
typedef double ld;
typedef pair<int,int> pi;
typedef pair<l,l> pl;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<l> vl;
typedef vector<ll> vll;

// MACROS FOR ATTRIBUTE
#define fi first
#define se second

// MACROS FOR FUNCTION AND METHOD
#define mp make_pair
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define RESET(x) memset((x), 0, sizeof(x))
#define SET(x,y) for (int _qwe = sizeof(x)/sizeof(x[0]); _qwe; ) x[--_qwe] = (y)
#define ALL(x) (x).begin(), (x).end()
#define ALLSIZE(x,n) (x), (x)+(n)
#define SQR(x) ((x)*(x))
#define CUBE(x) (SQR(x)*(x))

// MACROS READ INPUT
#define sci(x) scanf("%d", &x)
#define scl(x) scanf("%ld", &x)
#define scll(x) scanf("%lld", &x)
#define scul(x) scl(x)
#define scull(x) scll(x)

const ll sz = 1e5+5;
bool visited[sz];
int main(){
	RESET(visited);
	ll X;
	scll(X);
	set<ll> accepted;
	ll curr = 6;
	accepted.insert(1);
	for (; curr < sz; ){
		accepted.insert(curr);
		curr *= 6;
	}
	curr = 9;
	for (; curr < sz; ){
		accepted.insert(curr);
		curr *= 9;
	}
	queue<pll> q;
	q.push({X, 0});
	visited[X] = 1;
	while (q.front().fi != 0){
		pll tmp = q.front();
		q.pop();
		for (auto& x : accepted){
			if (tmp.fi - x >= 0 && !visited[tmp.fi - x]){
				visited[tmp.fi - x] = 1;
				q.push({tmp.fi - x, tmp.se + 1});
			} else if (tmp.fi < 0){
				break;
			}
		}
	}
	cout << q.front().se << endl;
	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
#include<string.h>

typedef struct {
	int Up;
	int Sorth;
	int East;
	int West;
	int North;
	int Down;
}DICE;
DICE assignment( DICE *t);
DICE North( DICE *t);
DICE Sorth( DICE *t);
DICE East( DICE *t);
DICE West( DICE *t);
DICE temp;
char temp_sentence[100];
int main()
{
	int i;
	char word[100];
	DICE Dice1 =assignment(&temp);
	scanf("%s",word);
	for (i = 0; i < strlen(word); i++){
		switch (word[i]){
		case 'N':Dice1 = North(&Dice1);
			break;
		case 'S':Dice1 = Sorth(&Dice1);
			break;
		case 'E':Dice1 = East(&Dice1);
			break;
		case 'W':Dice1 = West(&Dice1);
			break;
		}
	}
	printf("%d\n",Dice1.Up);
	return 0;
}
DICE assignment(DICE *t){
	int i,as,a[6];
	for (i = 0; i < 6; i++){
		scanf("%d", &as);
		a[i] = as;
	}
	temp = { t->Up = a[0], t->Sorth = a[1], t->East = a[2], t->West = a[3], t->North = a[4],t->Down=a[5] };
	return temp;
}
DICE North( DICE *t){
	temp = { t->Sorth, t->Down, t->East, t->West, t->Up, t->North };
	return temp;
}
DICE Sorth( DICE *t){
	temp = { t->North, t->Up, t->East, t->West, t->Down, t->Sorth};
	return temp;
}
DICE East( DICE *t){
	temp = { t->West, t->Sorth, t->Up, t->Down, t->North, t->East };
	return temp;
}
DICE West( DICE *t){
	temp = { t->East, t->Sorth, t->Down, t->Up, t->North, t->West };
	return temp;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()
int N;

int M;
i64 K;
vector<i64> x;
vector<i64> a;
vector<i64> d;
int main(){
  cin >> N;
  x.resize(N);
  rep(i,0,N - 1) cin >> x[i];
  cin >> M >> K;
  a.resize(M);
  rep(i,0,M - 1) cin >> a[i];
  rep(i,0,M - 1) a[i]--;
  d.resize(N - 1);
  rep(i,0,N - 2){
    d[i] = x[i + 1] - x[i];
  }
  vector<int> sw(N - 1);
  rep(i,0,N - 2) sw[i] = i;
  rep(i,0,M - 1){
    swap(sw[a[i] - 1],sw[a[i]]);
  }

  vector<int> ret(N - 1);
  rep(i,0,N - 2) ret[i] = i;

  while(K){
    if(K & 1){
      vector<int> temp(N - 1);
      rep(i,0,N - 2) temp[i] = ret[sw[i]];
      ret = temp;
    }
    {
      vector<int> temp(N - 1);
      rep(i,0,N - 2) temp[i] = sw[sw[i]];
      sw = temp;
    }
    K >>= 1;
  }

  vector<i64> ans(N);
  ans[0] = x[0];
  rep(i,1,N - 1){
    ans[i] = d[ret[i - 1]] + ans[i - 1];
  }

  rep(i,0,N - 1){
    cout << ans[i] <<endl;
  }
}


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

using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;
typedef pair<int, int> Pi;
typedef vector<ll> Vec;
typedef vector<int> Vi;
typedef vector<string> Vs;
typedef vector<vector<ll>> VV;

#define REP(i, a, b) for(ll i=(a); i<(b); i++)
#define PER(i, a, b) for(ll i=(a); i>=(b); i--)
#define rep(i, n) REP(i, 0, n)
#define per(i, n) PER(i, n, 0)
const ll INF=1e16+18;
const ll MAX=100005;
const ll MOD=1000000007;
#define Yes(n) cout << ((n) ? "Yes" : "No") << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl;
#define ALL(v) v.begin(), v.end()
#define pb(x) push_back(x)
#define mp(a, b) make_pair(a,b)
#define Each(a,b) for(auto &a :b)
#define REPM(i, mp) for (auto i = mp.begin(); i != mp.end(); ++i)
#define dbg(x_) cerr << #x_ << ":" << x_ << endl;
#define dbgmap(mp) cerr << #mp << ":"<<endl; for (auto i = mp.begin(); i != mp.end(); ++i) { cerr << i->first <<":"<<i->second << endl;}
#define dbgarr(n,m,arr) rep(i,n){rep(j,m){cerr<<arr[i][j]<<" ";}cerr<<endl;}
#define dbgdp(n,arr) rep(i,n){cerr<<arr[i]<<" ";}cerr<<endl;
#define sum(v) accumulate(ALL(v),0)
#define fi first
#define se second

template<typename T1, typename T2>
ostream &operator<<(ostream &s, const pair<T1, T2> &p) { return s<<"("<<p.first<<", "<<p.second<<")"; }

// vector
template<typename T>
ostream &operator<<(ostream &s, const vector<T> &v) {
    int len=v.size();
    for(int i=0; i<len; ++i) {
        s<<v[i];
        if(i<len-1) s<<"	";
    }
    return s;
}

// 2 dimentional vector
template<typename T>
ostream &operator<<(ostream &s, const vector<vector<T> > &vv) {
    int len=vv.size();
    for(int i=0; i<len; ++i) {
        s<<vv[i]<<endl;
    }
    return s;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<std::setprecision(10);

    ll n;
    cin>>n;
    Vec a(n);
    rep(i,n)cin>>a[i];

    Vec p;
    Vec m;
    rep(i,n){
        if(a[i]>=0){
            p.pb(a[i]);
        }else{
            m.pb(a[i]);
        }
    }
    ll q = n-1;

    if(m.size()==0){
        sort(ALL(p));
        m.pb(p[0]);
        p.erase(p.begin());
    }

    if(p.size()==0){
        sort(ALL(m));
        reverse(ALL(m));
        p.pb(m[0]);
        m.erase(m.begin());
    }

    ll mi = m.size()-1;
    ll pi = p.size()-1;

    vector<P> pr;
    bool change = false;
    ll tmp = p[pi];
    pi--;

    while(q--){
        if(mi==0&&pi>-1){
            pr.emplace_back(m[0],tmp);
            tmp = m[mi]-tmp;
            mi--;
            change = true;
            continue;
        }
        if(!change){
            pr.emplace_back(tmp,m[mi]);
            tmp = tmp-m[mi];
            mi--;
        }else{
            if(pi==0){
                pr.emplace_back(p[0],tmp);
                tmp = p[0]-tmp;
                break;
            } else{
                pr.emplace_back(tmp,p[pi]);
                tmp = tmp-p[pi];
                pi--;
            }
        }
    }
    cout << tmp << endl;
    rep(i,n-1){
        cout<<pr[i].fi<<" "<<pr[i].se<<endl;
    }

    return  0;
}


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

#define int long long

int N, M;
vector<int> G[100000];
bool flag = true;
int used[100000] = {};

void dfs(int u, int c) {
  if ( used[u] && used[u] != c ) {
    flag = false;
    return;    
  }
  if ( used[u] ) return;
  used[u] = c;  
  for ( int v : G[u] ) {
    dfs(v, 3-c);    
  }
}

signed main() {
  cin >> N >> M;
  for ( int i = 0; i < M; i++ ) {
    int u, v;
    cin >> u >> v;
    u--; v--;
    G[u].emplace_back(v);
    G[v].emplace_back(u);
  }

  dfs(0, 1);
  for ( int i = 0; i < N; i++ ) {
    if ( !used[i] ) {
      flag = true;
      break;
    }
  }
  if ( flag ) {
    cout << -1 << endl;
    return 0;
  }

  const int INF = 1e15;
  typedef pair<int, int> P;  
  int dp[N][2];
  fill_n(*dp, N*2, INF);  
  queue<P> q;
  q.push(P(0, 0));  
  while ( !q.empty() ) {
    P p = q.front(); q.pop();
    int u = p.first, c = p.second;

    // cout << u << " " << c << endl;
    
    if ( dp[u][c%2] != INF ) continue;
    dp[u][c%2] = c;    

    for ( int v : G[u] ) {
      q.push(P(v, c+1));      
    }
  }  

  int a = 0, b = 0;
  for ( int i = 0; i < N; i++ ) {
    a = max(a, dp[i][0]);
    b = max(b, dp[i][1]);    
  }

  cout << min(a, b) << endl;
  
  return 0;
}



Measured memory_bytes: 12524
#include <iostream>

using namespace std;

long long int f(long long int n, long long int x) {
  long long int number;
  if (n == -1) {
    return 0;
  } else {
    return n / x + 1;
  }
}

int main(int argc, char const *argv[]) {
  long long int a, b, x;
  cin >> a >> b >> x;

  cout << f(b, x) - f(a - 1, x) << endl;
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
  int x,y;
  scanf("%d %d", &x,&y);
  int che=2*x;
  if(che>100){
    printf("No");
  }else{
  for(int i=0;i<x+1;i++){
    if(y==che){
      printf("Yes");
      break;
    }
    if(i==x){
      printf("No");
      break;
    }
    che +=2;
  }
}
  return 0;
}

Measured memory_bytes: 1732
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a, b, c, d, e;
  cin >> a;
  b = a / 100;
  e = a - 100 * b;
  c = e / 10;
  d = e - 10 * c;
  cout << b + c + d << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <utility>
#include <set>
#include <vector>
#include <map>
#include <queue>
#include <list>
#include <stack>
#include <string>
#include <cmath>

using namespace std;

typedef pair<int, int> pi;
typedef vector<int> vi;
typedef vector<pi> vpi;
typedef long long ll;
typedef vector<ll> vl;
typedef pair<ll, ll> pl;
typedef double db;

#define in(x) cin >> x
#define ini(x) int x; cin >> x
#define inl(x) ll x; cin >> x
#define ins(x) string s; cin >> x

#define out(x) cout << x
#define outb(x) cout << x << ' '
#define outn(x) cout << x << '\n'

#define mp make_pair
#define fi first
#define se second
#define pb push_back
#define sz size()
#define len length()
#define all(x) x.begin(), x.end()
#define alln(a, n) a, a+n 

#define forn(i, s, e) for (int i = s; i < e; i++)
#define forr(i, s, e) for (int i = s; i >= e; i--)
#define ford(i, s, e, d) for (int i = s; i < e; i += d)
#define fors(i, n) for (int i = 1; i*i <= n; i++)

string b[109];
int f[109][109];

int main() {
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	
	ini(h); ini(w);
	string bh, bw;
	forn(i, 0, h) bh += '.';
	forn(i, 0, w) bw += '.';
	forn(i, 0, h) in(b[i]);
	forn(i, 0, w) {
		string wh;
		forn(j, 0, h) wh += b[j][i];
		if (wh == bh) forn(j, 0, h) f[j][i] = 1;
	}
	forn(i, 0, h) {
		if (b[i] == bw) continue;
		forn(j, 0, w) if (!f[i][j]) out(b[i][j]);
		outn("");
	}
	
		
	return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;

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

int A, B, C;

int main(void)
{
	cin >> A >> B >> C;
	
	if(C % gcd(A, B)) cout << "NO" << endl;
	else cout << "YES" << endl;
	
	return 0;
}

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

int main() {
    int n;
    std::cin >> n;
    int prev, cnt = 1, ret = 0;
    std::cin >> prev;
    for (int i = 1; i < n; i++) {
        int curr;
        std::cin >> curr;
        if (curr == prev) cnt++;
        else {
            ret += cnt / 2;
            cnt = 1;
            prev = curr;
        }
    }
    ret += cnt / 2;
    std::cout << ret << std::endl;
    return 0;
}

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

#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* na , Arg1&& arg1 , Args&&... args ) {
        const char* c = strchr( na + 1 , ',' );
        cerr.write( na , c - na ) << " : " << arg1 << " , ";
        __f( c + 1 , args... );
}
#define endl "\n"
#define all(V) V.begin(),V.end()
#define Unique(V) sort(all(V)),V.erase(unique(all(V)),V.end())
#define IO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long int LL;
typedef pair <int,int> pii;
const int MOD = 1e9 + 7;
const int inf = 1e9;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const long long INF = 1e18;
const int N = 1e5 + 5;

int main( ) {
        IO;
        #ifdef LOCAL
            //freopen( "input.txt" , "r" , stdin );
        #endif // LOCAL
        int len;
        string s;
        cin >> len >> s;
        int ans = 0;
        for( int i = 0; i < s.size(); ) {
            int j = i;
            while( j < s.size() && s[j] == s[i] ) j++;
            i = j;
            ans++;
        }
        cout << ans << endl;
        return 0;
}










Measured memory_bytes: 512
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from bisect import bisect_right, bisect_left
import random
from itertools import permutations, accumulate, combinations, product
from re import split
import sys
import string
from bisect import bisect_left, bisect_right
from math import factorial, ceil, floor, gamma, log
from operator import mul
from functools import reduce
from copy import deepcopy
import re

sys.setrecursionlimit(2147483647)
INF = 10 ** 20
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
mod = 10 ** 9 + 7

h, w, k = LI()
s = []
for _ in range(h):
    s += [[int(i) for i in list(S())]]
ans = INF
for j in range(2 ** (h - 1)):
    L = []
    last = 0
    for m in range(h - 1):
        if j >> m & 1:
            L += [(last, m + 1)]
            last = m + 1
    L += [(last, h)]
    now = [0] * len(L)
    last_x = 0
    cnt = len(L) - 1
    flag2 = 0
    flag = 0
    x = 0
    while x < w:
        flag3 = 0
        K = [s[y][x] for y in range(h)]
        for i in range(len(L)):
            l, r = L[i]
            k_sum = sum(K[l:r])
            if now[i] + k_sum > k:
                cnt += 1
                if flag == 0:
                    flag2 = 1
                    break
                else:
                    flag = 0
                    now = [0] * len(L)
                    flag3 = 1
                    break
            else:
                now[i] += k_sum
        else:
            flag = 1
        if flag3:
            continue
        if flag2:
            break
        x += 1
    else:
        ans = min(ans, cnt)


print(ans)


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

#define INF 1000000001

long s[500000];
int cnt = 0;


void Merge(int left, int mid , int right){

  int n1 = mid-left;
  int n2 = right - mid;

  long L[250001],R[250001];

  for(int i=0; i<n1; i++)L[i] = s[left+i];

  for(int i=0; i<n2; i++)R[i] = s[mid+i];

  L[n1] = R[n2] = INF;
  
  int r,l=r=0;
  for(int i=left; i<right; i++){
    if(L[l] <= R[r]) s[i] = L[l++];
    else             s[i] = R[r++];
    cnt++;
  }

}

void MergeSort(int left, int right){
  if(left+1 < right){
    int mid = (left+right)/2;
    MergeSort(left , mid);
    MergeSort(mid , right);
    Merge(left , mid , right);
  }
}


int main(){
 
  int n;

  cin >> n;

  for(int i=0; i<n; i++)cin>>s[i];

  MergeSort(0 , n);

  cout << s[0];
  for(int i=1; i<n; i++)cout << ' ' <<s[i];
  cout << endl << cnt << endl;

  return 0;
}

Measured memory_bytes: 8968
#include<iostream>
using namespace std;
int main(){
  long long n,i,c[222222],dp[222222],p[222222],mod=1000000007;
  cin>>n;
  for(i=1;i<=n;i++)
    cin>>c[i];
  for(i=0;i<222222;i++)
    p[i]=-1;
  dp[0]=1;
  for(i=1;i<=n;i++){
    dp[i]=dp[i-1];
    if(p[c[i]]!=-1)
      if(p[c[i]]!=i-1)
        dp[i]=(dp[i]+dp[p[c[i]]])%mod;
    p[c[i]]=i;
  }
  cout<<dp[n]<<endl;
}


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

int main() {
  char tmp;
  int i = 0;
  while(tmp != '\n') {
    cin >> noskipws >> tmp;
    if ('a' <= tmp && tmp <= 'z') {
      tmp = tmp - 'a' + 'A';
    } else if ('A' <= tmp && tmp <= 'Z') {
      tmp = tmp - 'A' + 'a';
    }
    cout << tmp;
  }

  return 0;
}



Measured memory_bytes: 3088
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<cmath>
#include<stack>
#include<algorithm>
#define rg register
#define ll long long
#define LDB long double
#define ull unsigned long long
#define view(i,x) for(rg int i=hd[x];i!=-1;i=e[i].nt)
#define go(i,x,a) for(rg int i=a;i<x;i++)
#define inf 0x3f3f3f3f
#define INF 0x7fffffff
using namespace std;

const int maxn=2005;
int n,X,a[maxn],p[maxn][maxn];
ll ans=1e15;

inline int rd(){
	int ret=0,af=1; char gc=getchar();
	while(gc < '0' || gc > '9'){ if(gc=='-') af=-af; gc=getchar(); }
	while(gc >= '0' && gc <= '9') ret=ret*10+gc-'0',gc=getchar();
	return ret*af;
}

void pre(){
	go(i,n+1,1){
		p[i][0]=a[i];
		go(j,n+1,1){
			int id=i-j;	if(id < 1) id+=n;
			p[i][j]=min(p[i][j-1],a[id]);
		}
	}
}

int main(){
	n=rd(); X=rd();
	go(i,n+1,1) a[i]=rd(); pre();
	go(i,n+1,0){
		if((ll)X*i >= ans) break;
		ll ss=(ll)X*i;
		go(j,n+1,1) ss+=p[j][i];
		ans=min(ans,ss);
	}
	printf("%lld",ans);
	return 0;
}//Faze


Measured memory_bytes: 15872
using System;

class AtCoder
{    
    static void Main(string[] args)
     {
        var input = Console.ReadLine().ToUpper();
        var atcg = new char[] { 'A', 'T','C', 'G'};

        int count = 0;
        int max = 0;
        foreach(var chr in input)
        {
            switch (chr)
            {
                case 'A':
                case 'T':
                case 'C':
                case 'G':
                    count++;
                    max = count >= max ? count : max;
                    break;
                default:
                    count = 0;
                    break;
            }
        }

        Console.WriteLine(max.ToString());
     }
 }

Measured memory_bytes: 13140
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <fstream>
#include <iostream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <ext/random>
#include <ext/rope>
#include <functional>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = long long;
using ull = unsigned long long;
using vi = std::vector<int>;
using vl = std::vector<int64>;
using pii = std::pair<int, int>;
using pii = std::pair<int, int>;
using pll = std::pair<int64, int64>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(_) (_).begin(), (_).end()
#define rall(_) (_).rbegin(), (_).rend()
#define print(_) std::cout << (_) << '\n'
#define debug(_) std::cerr << #_ << ": " << (_) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
template<typename T> std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  os << '{';
  for (size_t i = 0; i < vec.size(); ++i) {
    os << vec[i];
    if (i != vec.size() - 1) os << ',';
  }
  os << '}';
  return os;
}
template<typename T, typename U> std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '{' << p.first << " " << p.second << '}';
}
// constant
const int INF = (1<<30) - 1;  // 1.073741823e9
const int64 INF64 = (1LL<<62) - 1;  // 4.611686018427387903e18
const int MOD = 1000000007;

int main(){
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(nullptr);

  int n; cin >> n;
  if (n & 1) {
    cout << setprecision(10) << static_cast<double>(n / 2 + 1) / static_cast<double>(n) << '\n';
  } else {
    cout << setprecision(10) << 0.500000 << '\n';
  }

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <stack>
#include <queue>
#include <functional>
#include <limits.h>
#include <set>
#include <map>
#include <tuple>
using namespace std;

#define ll long long
#define ull unsigned long long
#define rep(i,N) for (ll i=0;i<N;i++)
#define loop(i,N,M) for(ll i=N;i<M;i++)
#define MAX(v) *max_element(v.begin(),v.end())
#define MIN(v) *min_element(v.begin(),v.end())
#define SORTL2S(type,v) sort(v.begin(),v.end(),greater<type>())
#define SORTS2L(type,v) sort(v.begin(),v.end())
#define SORTMF(v,func) sort(v.begin(),v.end(),func)
#define MP(a,b) make_pair(a,b)

#if __has_include("debug.hpp")
#include "debug.hpp"
#else
template<typename T>
void debug(T& obj) {}
#endif

template<typename T>
T in(){
	T val;
	cin >> val;
	return val;
}

template<typename T>
vector<T> inv(ll num) {
	vector<T> val(num);
	rep(i,num) cin >> val[i];
	return val;
}

//最大公約数
ll GCD(ll x, ll y) {
	ll tmp;
	if (y > x) {
		tmp	= x;
		x = y;
		y = tmp;
	}
	while (x%y != 0) {
		tmp = y;
		y = x%y;
		x = tmp;
	}
	return y;
}

//最小公倍数
ll LCM(ll x, ll y) {
	return x*y / GCD(x, y);
}

//----------------------------------------------------------------------
void solve() {

	ll a,b;
	cin >> a>>b;
	cout << LCM(a,b);

}
//----------------------------------------------------------------------

int main(int argc, char* argv[]) {
	solve();
	return 0;
}


Measured memory_bytes: 3616
#import itertools
#K = int(input())
#N,K = map(int,input().split())
X = int(input())
n=[i**5 for i in range(121)]
m=[i**5 for i in range(121)]
#A = list(map(int,input().split()))
for i in n:
    for j in m:
        if i-j==X:
            print(n.index(i),m.index(j))
            exit()
        elif i+j==X:
            print(n.index(i),-m.index(j))
            exit()


Measured memory_bytes: 9188
#include<stdio.h>
#define N 101
#define inf 1000000000
#define NIL -1

int A[N][N],d[N],v[N],color[N],pi[N];

int main(){
  int n,i,j,mincost,v,r=0,cost=0,u;
  scanf("%d",&n);

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

  for(u=0;u<n;u++){
    d[u] = inf;
    pi[u] = NIL;
    color[u] = 0;
  }
  d[r] = 0;
  
  while(1){
    mincost = inf;
    for(i=0;i<n;i++){
      if(color[i] != 1 && d[i] < mincost){
	mincost = d[i];
	u = i;
      }
    }
    if(mincost == inf){
      break;
    }
    color[u] = 1;
    for(v=0;v<n;v++){
      if(color[v] != 1 && A[u][v] < d[v] && A[u][v] != -1){
	pi[v] = u;
	d[v] = A[u][v];
      }
    }
  }

  for(i=0;i<n;i++){
    if(pi[i] != -1){
      cost = cost + A[i][pi[i]];
    }
  }


  printf("%d\n",cost);

  return 0;
  
}



Measured memory_bytes: 2052
while True:
 N = int(input())
 if N==0: break
 ans = float('inf')
 for c200 in range(N//200+1):
  for c300 in range(N//300+1):
   for c500 in range(N//500+1):
    if 200 * c200 + c300 * 300 + c500 * 500 == N:
     ans = min(ans, 1520*(c200//5)+380*(c200%5)+1870*(c300//4)+550*(c300%4)+2244*(c500//3)+850*(c500%3))
 print(ans)


Measured memory_bytes: 5596
#include <bits/stdc++.h>
using namespace std;
#define ll      long long 
#define ld      long double
#define pii     pair<int ,int>
#define pld     pair<ld ,ld>
#define all(v)  v.begin(),v.end()
#define F       first
#define S       second
#define mod     1000000007
#define pb      push_back
#define MP      make_pair
#define mset(x) memset(x, 0, sizeof(x));
#define ios     ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define inf     10000000000000007
const int N=300004;
ll a[N],b[N],c[N];
void run(){
    ll n,k,ans,cnt,l,r,mid,i;
    cin>>n>>k;
    for(i=1;i<=n;i++)
        cin>>a[i];
    for(i=1;i<=n;i++)
        cin>>b[i];
    sort(a+1,a+n+1);
    sort(b+1,b+n+1);
    reverse(a+1,a+n+1);
    for(i=1;i<=n;i++)
        c[i]=a[i]*b[i];
    
    ans=1000000000000;
    l=0;
    r=ans;
    while(l<=r)
    {
        mid=(l+r)/2;
        cnt=0;
        for(i=1;i<=n;i++)
        {
            if(c[i]<=mid) continue;
            ll x=(c[i]-mid+b[i]-1)/b[i];
            if(x>a[i]) {
                l=mid+1;
                break;
            }
            else cnt+=x;
        }
        if(cnt<=k) ans=mid,r=mid-1;
        else l=mid+1;

    }
    cout<<ans;
}
 
 
void setup(){
    ios;
    //cout << setprecision(20);
    // #ifndef ONLINE_JUDGE
    // freopen("input", "r", stdin);
    // freopen("output", "w", stdout);
    // #endif
}
 
signed main(){
    setup();
    int tests = 1;
    //cin >> tests;
    for(int i = 1; i <= tests; i++) run();
    return 0;
}

Measured memory_bytes: 6016
#include<cstdio>
#include<algorithm>
using namespace std;
int main(){
	long long int n, a, b;
	scanf("%lld%lld%lld",&n,&a,&b);
	if(a%2==b%2){
		printf("%lld\n",(b-a)/2);
	}else{
		long long int s=(a+b-1)/2;
		long long int t=(2*n-a-b+1)/2;
		if(s<t)printf("%lld\n",s);
		else printf("%lld\n",t);
	}
	return 0;
}

Measured memory_bytes: 128
#include<iostream>
using namespace std;
int main()
{
	int n;
	int count=0;
	cin>>n;
	int a[n] = {0};
	for(int i = 0; i < n; i++)cin >> a[i];
	
	int flag = 1;
	
	while(flag)
	{
		flag = 0;
		
		for(int i = n-1; i>0; i--)
		{
			if(a[i] < a[i-1])
			{
				int temp = a[i];
				a[i] = a[i-1];
				a[i-1] = temp; 
				
				flag = 1; 
				
				count++;
			}
		}
	}
	
	for(int i = 0; i < n; i++)
	{
		if(i > 0)cout << " ";
		cout << a[i];
	}
	cout << endl;
	
	cout << count << endl;
	
	return 0;
	
 } 


Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
using P = pair<int, int>;

long long gcd(long long a, long long b) {
    while (b > 0) {
        long long t = a % b;
        a = b;
        b = t;
    }
    return a;
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b;
}

long long powmod(long long a, long long b, long long mod) {
    if (b == 0) return 1;
    long long p = powmod(a, b / 2, mod);
    p = p * p % mod;
    if (b & 1) p = p * a % mod;
    return p;
}

int main() {
    int n;
    cin >> n;
    int m = n;
    vector<int> v;
    for (int i = 2; i * i <= n; ++i) {
        if (n % i == 0) {
            if (n % (i * i) == 0) {
                cout << "-1\n";
                return 0;
            }
            v.push_back(i);
            n /= i;
        }
    }
    if (n > 1) v.push_back(n);
    long long l = 1;
    for (auto& a : v) l = lcm(l, a - 1);
    if (gcd(m, l) > 1) {
        cout << "-1\n";
        return 0;
    }
    long long p = l;
    long long cnt = l;
    for (int i = 2; i * i <= l; ++i) {
        if (l % i == 0) {
            cnt = cnt / i * (i - 1);
            while (l % i == 0)
                l /= i;
        }
    }
    if (l > 1) cnt = cnt / l * (l - 1);

    long long ans = cnt;
    for (long long i = 1; i * i <= cnt; ++i) {
        if (cnt % i == 0) {
            if (powmod(m, i, p) == 1)
                ans = min(ans, i);
            if (powmod(m, cnt / i, p) == 1)
                ans = min(ans, cnt / i);
        }
    }
    cout << ans << "\n";
    return 0;
}



Measured memory_bytes: 3156
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>

using namespace std;

int main() {
	int n;
	while (cin >> n, n) {
		vector<int> imos(90000);
		while (n--) {
			int h, m, s;
			scanf("%d:%d:%d", &h, &m, &s);
			imos[3600 * h + 60 * m + s]++;
			scanf("%d:%d:%d", &h, &m, &s);
			imos[3600 * h + 60 * m + s]--;
		}
		int ans = imos[0];
		for (int i = 1; i < 90000; ++i) {
			imos[i] += imos[i - 1];
			ans = max(ans, imos[i]);
		}
		cout << ans << endl;
	}

	return 0;
}


Measured memory_bytes: 3484
#!/usr/bin/python3
# ABC058_A
"""
ι⊥l（柱）
"""

def beautiful():
    """
    本体
    """
    a, b, c = map(int, input().split())
    if b-a == c-b:
        print('YES')
    else:
        print('NO')


def main():
    beautiful()


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <cstdio>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <vector>
#include <queue>
using namespace std;
typedef long long LL;

LL n,m,ans = 0;
LL a[500005];

int main(){
	ios::sync_with_stdio(false);
	cin >> n >> m;
	for(LL i = 1;i <= n;i ++) cin >> a[i];
	sort(a + 1,a + 1 + n);
	for(LL i = 1;i <= n - m;i ++) ans += a[i];
	cout << ans << endl;
	return 0;
}

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

int main() {
    int N,M;
    cin >> N >> M;
    vector<int>A(N);
    int i;
    int cnt = 0;
    int flg = 1;


    for(i = 0; i < N; i++){
        cin >>  A.at(i);
        cnt += A.at(i);
    }
    sort(A.begin(), A.end());
    reverse(A.begin(), A.end());

    for(i = 0; i < M; i++){
        if(A.at(i) < cnt*1.0/4.0/M){
            flg *= 0;
        }else{
            flg *= 1;
        }
    }

    if(flg == 0){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
using namespace std;
int n,t,d[1<<17];
main()
{
	cin>>n>>t;
	for(int i=0;i<n;i++)cin>>d[i];
	long dp=1,M=1e9+7;
	sort(d,d+n);
	for(int i=1;i<n;i++)
	{
		int cnt=i+1;
		int l=lower_bound(d,d+i,d[i]-t)-d-1;
		cnt-=l>=0?l+1:0;
		dp=dp*cnt%M;
	}
	cout<<dp<<endl;
}



Measured memory_bytes: 3520
k , n= map(int, input().split())
a_list = list(map(int, input().split()))
diff_list = []
for i in range(n-1):
    diff_list.append(a_list[i+1]- a_list[i])
diff_list.append(k-a_list[n-1] + a_list[0])
print(sum(diff_list)-max(diff_list))

Measured memory_bytes: 32104
from numpy import*;B=searchsorted;a,b=loadtxt(open(0),'i',skiprows=1);c=0;l=2**29
while l:y=sort(hstack((b%l-l,b%l)));A=l-a%l;l//=2;c+=sum(B(y,A)-B(y,A-l))%2*l
print(c)

Measured memory_bytes: 64172
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<functional>
#include<vector>
#include<queue>
#include<stack>
#include<set>
using namespace std;
#define MOD 1000000007
#define f(i,n) for(int i=0;i<int(n);i++)
#define N 200000


int main(){
	char a[N + 1];
	f(i, N + 1)a[i] = 0;
	int n, k;
	scanf("%d %d", &n, &k);
	scanf("%s", a);
	n = strlen(a);
	f(i, n){
		if (i % 2 == 0 && a[i] == 'A'){
			k--;
		}
		else if (i % 2 == 1 && a[i] == 'B'){
			k--;
		}
		if (k <= 0){
			printf("B");
			if (i % 2 == 0){
				for (int j = i + 1; j < n; j++){
					if (a[j] == 'A')printf("A");
					else printf("B");
				}
				f(j, i){
					if (j % 2 == 0)printf("B");
					else printf("A");
				}
			}
			else{
				for (int j = i + 1; j < n; j++){
					if (a[j] == 'A')printf("B");
					else printf("A");
				}
				f(j, i){
					if (j % 2 == 0)printf("A");
					else printf("B");
				}
			}
			printf("\n");
			return 0;
		}
		k--;
		if (k <= 0){
			if (i % 2 == 0){
				for (int j = i + 1; j < n; j++){
					if (a[j] == 'A')printf("B");
					else printf("A");
				}
				f(j, i+1){
					if (j % 2 == 0)printf("A");
					else printf("B");
				}
			}
			else{
				for (int j = i + 1; j < n; j++){
					if (a[j] == 'A')printf("A");
					else printf("B");
				}
				f(j, i + 1){
					if (j % 2 == 0)printf("B");
					else printf("A");
				}
			}
			printf("\n");
			return 0;
		}
	}

	if (n % 2 == 0){
		f(i, n){
			if (i % 2 == 0)printf("B");
			else printf("A");
		}
		printf("\n");
		return 0;
	}
	else{
		if (k % 2 == 0)printf("A");
		else printf("B");
		f(i, n-1){
			if (i % 2 == 0)printf("B");
			else printf("A");
		}
		printf("\n");
		return 0;
	}


	return 0;
}

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

int main() {
	int N;
	
	while (cin >> N, N) {	
		int sum = 1;
		
		for (int x = 2; x * x <= N; ++x) {
			if (N % x == 0) {
				sum += x;
				if (x != N / x) sum += N / x;
			}
		}
		
		if (N == 1 || sum < N) cout << "deficient number" << endl;
		else cout << (sum == N ? "perfect number" : "abundant number") << endl;
	}
}

Measured memory_bytes: 1152
def main():
    g = []
    n = int(input())
    v = list(map(int,input().split()))
    c = list(map(int,input().split()))
    for i in range(n):
        gain = v[i] -c[i]
        if gain > 0 :
            g.append(gain)
    print(sum(g))


if __name__ == '__main__':
    main()

Measured memory_bytes: 9144
#include<stdio.h>
#define max 250

int main(){
  int n,i;
  int a[max];
  
  scanf("%d",&n);
  for(i=1;i<=n;i++) scanf("%d",&a[i]);

  for(i=1;i<=n;i++){
    printf("node %d: key = %d, ",i,a[i]);
    if(i/2>=1) printf("parent key = %d, ",a[i/2]);
    if(i*2<=n) printf("left key = %d, ",a[i*2]);
    if(i*2+1<=n) printf("right key = %d, ",a[i*2+1]);
    printf("\n");
  }
  
  return 0;
}



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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<int> X(M);
    for(int i=0; i<M; i++){
        cin >> X.at(i);
    }
    sort(X.begin(), X.end());
    vector<int> Y(M-1);
    for(int i=0; i<M-1; i++){
        Y.at(i) = X.at(i+1) - X.at(i);
    }
    sort(Y.begin(), Y.end());
    int ans = X.at(M-1)-X.at(0);
    bool flag = true;
    for(int i=0; i<N-1; i++){
        if(i==M-1){
            cout << 0 << endl;
            flag = false;
            break;
        }
        ans -= Y.at(M-2-i);
    }
    if(flag){
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 1024