akhauriyash/Code-Regression huggingface dataset:
x,k,d=map(int,input().split())
x=abs(x)
v=x//d
if v>=k:
    print(x-k*d)
else:
    f=x-d*v
    s=x-d*(v+1)
    f=abs(f)
    s=abs(s)
    if f<s:
        if (k-v)%2==0:
            print(f)
        else:print(s)
    else:
        if (k-(v+1))%2==0:
            print(s)
        else:
            print(f)

Measured memory_bytes: 61876
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,n) for (int i = 0; i < (n); i++)
#define repe(i,n) for (int i = 0; i <= (n); ++i)
#define repe1(i,n) for (int i = 0; i <= (n); ++i)
#define all(x) (x).begin(),(x).end()
#define pb(x) push_back(x)
#define eb(k,v) emplace_back(k,v)
#define ct(res) cout << res << "\n";
#define vi vector<int>
#define vl vector<ll>
using namespace std;
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; }
const int INF = 1e9;
const ll MOD = 1000000007;
using Graph = vector<vector<int>>;
ll gcd(ll a, ll b) {return (a%b) ? gcd(b, a%b) : b;}
ll modPow(ll x, ll n) {
    if(n==0) return 1;
    ll res = modPow(x*x%MOD, n/2);
    if(n&1) res=res*x%MOD;
    return res;
}
ll mul(ll l, ll r) {
    ll ret =1;
    for(int i=0; i<l-r+1; ++i) {
        ret*=i+r;
        ret%=MOD;
    }
    return ret;
}
ll com(ll n, ll k) {
    ll ret1 = mul(n,n-k+1);
    ll ret2 = mul(k,1);
    ll ret3 = modPow(ret2, MOD-2);
    return ret1*ret3%MOD;
}


int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int a,b,c; cin >> a >> b>> c;
    for(int i=a; i<=99999; i+=a) {
        if (i%b==c) {
            ct("YES");
            return 0;
        }
    }
    ct("NO");
}



Measured memory_bytes: 256
#include<iostream>
#include<vector>
#define SIZE 1000000
using namespace std;

struct Stack{
  int line[SIZE];
  int top;
  void init(){
    top = 0;
  }
  bool empty(){
    return top==0;
  }
  void push(int x){
    line[top]=x;
    top ++;
  }
  int pop(){
    if(empty()) return -1;
    top--;
    return line[top];
  }
};
struct Node
{
  vector<int> toList;
  int dt;
  int ft;
};

Stack stack; 
int t; //time

void init(vector<Node>& nodes)
{
  t=0;
  stack.init();
  stack.push(0);
  for(int i=0;i<nodes.size();i++){
    nodes[i].ft=-1;
    nodes[i].dt=-1;
  }
}
void print(vector<Node> nodes)
{
  int n=nodes.size();
  for(int i=0;i<n;i++){
    cout<<i+1<<" "<<nodes[i].ft<<" "<<nodes[i].dt<<endl;
  }
}
void dfs(vector<Node>& nodes)
{ 
  int idx=stack.pop();
  if(idx<0){
    for(int i=0;i<nodes.size();i++){
      if(nodes[i].ft<0){
	idx=i;
	break;
      }
    }
  }
  //cout<<idx+1<<":";
  if(idx>=0){
    if(nodes[idx].ft<0){
      //cout<<" find";
      t++;
      nodes[idx].ft=t;
    }
    if(nodes[idx].toList.size()<=0){
      //cout<<" toList.size==0"<<endl;
      t++;
      nodes[idx].dt=t;
      dfs(nodes);
    }
    int count=0;
    for(int i=0;i<nodes[idx].toList.size();i++){
      if(nodes[nodes[idx].toList[i]].ft<0){
	//cout<<" jumpto "<<i+1<<endl;
	count++;
	stack.push(idx);
	stack.push(nodes[idx].toList[i]);
	dfs(nodes);
      }
    }
    if(count==0 && nodes[idx].dt<0){
      //cout<<" finish"<<endl;
      t++;
      nodes[idx].dt=t;
      dfs(nodes);
    }
  }else{
    //cout<<"finish dfs"<<endl;
  }
}

int main()
{
  int n,u,k;
  cin>>n;
  vector<Node> nodes(n);
  for(int i=0;i<n;i++){
    cin>>u>>k;
    nodes[i].toList.resize(0);
    for(int j=0;j<k;j++){
      int tmp;
      cin>>tmp;
      nodes[i].toList.push_back(tmp-1);
    }
  }
  init(nodes);
  //print(nodes);

  dfs(nodes);
  print(nodes);
  return 0;
}



Measured memory_bytes: 3184
def main():
    n = int(input())
    word = list(input())
    l, r = 0, n - 1
    cnt = 0
    while l < r:
        while l < r and word[l] == 'R':
            l += 1
        while l < r and word[r] == 'W':
            r -= 1
        if l < r:
            word[l], word[r] = word[r], word[l]
            cnt += 1
            l += 1
            r -= 1
    print(cnt)
  
if __name__ == '__main__':
    main()

Measured memory_bytes: 10700
import bisect
def factorization(n):
    arr = []
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            cnt=0
            while temp%i==0:
                cnt+=1
                temp //= i
            arr.append([i, cnt])

    if temp!=1:
        arr.append([temp, 1])

    if arr==[]:
        arr.append([n, 1])

    return arr


def main():
    n = int(input())
    if n == 1:
        print(0)
        return
    ans = 0
    p = factorization(n)

    for i, pp in enumerate(p):
        tmp = pp[1]
        ary = [0] * (tmp+1)
        cnt = 1
        while tmp > 0:
            ans += 1
            tmp -= cnt
            if tmp <= cnt:
                cnt += 1
                break
            if tmp < 0:
                tmp += cnt

            cnt += 1
    print(ans)


if __name__=='__main__':
    main()


Measured memory_bytes: 9532
#include<iostream>
#include<map>
using namespace std;
map<int,int>mp;
int main()
{
	int n,t,ans=0;
	cin >> n;
	for(int i=0;i<n;i++)
	{
		cin >> t;
		if(mp[t]==0)
		{
			mp[t]=1;
			ans++;
		}
		else
		{
			mp[t]=0;
			ans--;
		}
	}
	cout << ans;
}

Measured memory_bytes: 4992
# coding: utf-8
import sys
sys.setrecursionlimit(10 ** 7)

sr = lambda: sys.stdin.readline().rstrip()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

N, M, Q = lr()
ABCD = [lr() for _ in range(Q)]
answer = 0

def dfs(A):
    global answer
    if len(A) == 11:
        temp = 0
        for a, b, c, d in ABCD:
            if A[b] - A[a] == c:
                temp += d
        if temp > answer:
            answer = temp
        return  
    back = A[-1]
    while back <= M:
        dfs(A + [back])
        back += 1

dfs([1])
print(answer)            


Measured memory_bytes: 9064
#include<iostream>
using namespace std;
int main()
{
    int a,b;
    cin>>a>>b;
    int c,y,t;
    c=a*b;
    y=a-b;
    t=a+b;
    if(c>=t&&c>=y)
    {
        cout<<c;
    }
    else if(y>=c&&y>=t)
    {
        cout<<y;
    }
    else if(t>=c&&t>=y)
    {
        cout<<t;
    }
    return 0;
}


Measured memory_bytes: 256
s = input()
l = len(s)

f = 'Yes'
for i in range(int((l-1)/2)):
    if s[i] != s[l-i-1]:
        f = 'No'
for i in range(int(((l-1)/2)//2)):
    if s[i] != s[l-i-int((l-1)/2+1)-1]:
        f = 'No'




print(f)

Measured memory_bytes: 3060
fn main() {
    read::<String>();

    let a: Vec<i64> = read_vec();
    println!("{}", solve(&a));
}

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

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

fn solve(a: &[i64]) -> i64 {
    a.iter().fold(1, |acc, &n| {
        if n == 0 {
            return 0;
        }

        if acc <= 0 {
            return acc;
        }

        let ans = (acc as i128) * (n as i128);
        if ans > 1_000_000_000_000_000_000 {
            return -1;
        }

        ans as i64
    })
}

#[cfg(test)]
mod tests {
    use super::*;

    #[test]
    fn test_solve_1() {
        let input = &[1_000_000_000, 1_000_000_000];
        assert_eq!(1_000_000_000_000_000_000, solve(input));
    }

    #[test]
    fn test_solve_2() {
        let input = &[101, 9901, 999_999_000_001];
        assert_eq!(-1, solve(input));
    }

    #[test]
    fn test_solve_3() {
        let input = &[
            4, 1, 5, 9, 2, 6, 5, 3, 5, 8, 9, 7, 9, 3, 2, 3, 8, 4, 6, 2, 6, 4, 3, 3, 8, 3, 2, 7, 9,
            5, 0,
        ];
        assert_eq!(0, solve(input));
    }
}


Measured memory_bytes: 5836
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cstring>
#include <queue>
#include <vector>
#include <functional>
#include <map>
#include <set>
#include <cmath>
#include <string>
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007

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

int N;

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

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


int main()
{
	scanf("%d",&N);
	ll T;
	ll res = 1;
	for(int i=0;i<N;i++){
		scanf("%lld",&T);
		res = lcm(res,T);
	}
	printf("%lld\n",res);

	return 0;
}


Measured memory_bytes: 128
#include<iostream>
using namespace std;
string n;
int m,d;
int main()
{
	cin>>n;
	m=(n[5]-48)*10+n[6]-48;
	d=(n[8]-48)*10+n[9]-48;
	if(m<4)
	{
		cout<<"Heisei";
	}
	else if(m==4&&d<=30) cout<<"Heisei";
		
	else
	{
		cout<<"TBD";
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<iomanip>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
using namespace std;
#define ll long long
int main(){
    int n;
    string s1,s2,s3;
    cin >> n>> s1 >> s2 >> s3;
    int i,tmp;
    int ans=0;
    for(i=0;i<n;i++){
      tmp=2;
      if(s1[i]==s2[i])tmp--;
      if(s2[i]==s3[i])tmp--;
      if(s3[i]==s1[i])tmp--;
      if(tmp<0)tmp=0;
      ans+=tmp;
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
import scala.io.StdIn._
 
object Main extends App{
  val sc = new java.util.Scanner(System.in)
  val x = sc.next
  val y = sc.next
  if(x>y){
    println(">")
  }
  else if(x<y){
    println("<")
  }
  else{
    println("=")
  }
}

Measured memory_bytes: 27432
#include <cstdio>
#include <iostream>
#include <vector>
#include <map>
#include <algorithm>
#include <unordered_map>

using namespace std;

typedef long long ll;

#define SIZE 200000
#define INF 1000000000


struct UnionFind {
  vector<int> data, data2;
  map<int,int> dic;
  UnionFind()  {}

  int toId(int x) {
    auto it = dic.find(x);
    if (it == dic.end()) {
      int tmp = dic.size();
      dic[x] = tmp;
      data.push_back(-1);
      data2.push_back(0);
      return tmp;
    } else {
      return it->second;
    }
  }

  int root(int x) {
    x = toId(x);
    return _root(x);
  }

  int _root(int x) {
    if(data[x] < 0) return x;
    return data[x] = _root(data[x]);
  }

  bool set(int x, int y) {
    x = toId(x);
    y = toId(y);
    return _set(x, y);
  }

  bool _set(int x, int y) {
    x = _root(x); y = _root(y);
    data2[x] += 1;
    if(x == y) return false;

    data[x] += data[y];
    data2[x] += data2[y];
    data[y] = x;
    return true;
  }

  bool check(int x, int y) {
    x = toId(x);
    y = toId(y);
    return _root(y) == _root(x);
  }
};

vector<int> G[SIZE];
int c[SIZE][2];
int ans[SIZE];

UnionFind *uf[SIZE];
vector<int> *vec[SIZE];

int addedge(UnionFind *uf, int p) {
  int res = 0;

  int a = c[p][0], b = c[p][1];

  int ra = uf->root(a);
  int rb = uf->root(b);

  if (ra == rb){
    if(-uf->data[ra] == uf->data2[ra]+1) {
      res = 1;
    }
  } else  if (-uf->data[ra] == uf->data2[ra]+1 || -uf->data[rb] == uf->data2[rb]+1) {
    res = 1;
  }

  uf->_set(ra, rb);

  return res;
}

int dfs(int now, int back = -1) {
  int size = 1;
  int max_id = -1, max_tmp = 0;

  for(int to : G[now]) {
    if (to == back) continue;

    int tmp = dfs(to, now);
    size += tmp;

    if (max_tmp < tmp) {
      max_id = to;
      max_tmp = tmp;
    }
  }

  if (max_id == -1) {
    uf[now] = new UnionFind();
    vec[now] = new vector<int>();
    ans[now] = 0;
  } else {
    uf[now] = uf[max_id];
    ans[now] = ans[max_id];
    vec[now] = vec[max_id];
  }

  for(int to : G[now]) {
    if (to == back || to == max_id) continue;

    for(int p : *vec[to]) {
      ans[now] += addedge(uf[now], p);
      vec[now]->push_back(p);
    }
  }

  ans[now] += addedge(uf[now], now);
  vec[now]->push_back(now);

  return size;
}


int main() {
  int N, K;

  scanf("%d%d", &N, &K);

  for(int i=0; i<N-1; i++) {
    int u, v;
    scanf("%d%d", &u, &v);
    u--; v--;

    G[u].push_back(v);
    G[v].push_back(u);
  }

  for(int i=0; i<N; i++) {
    scanf("%d%d", c[i]+0, c[i]+1);
    c[i][0]--; c[i][1]--;
  }

  dfs(0);

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

  return 0;
}



Measured memory_bytes: 106412
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0;i<n;i++)
#define rep2(i,a,n) for(int i=a;i<n;i++)
#define been(ix) (ix).begin(),(ix).end()
using namespace std;
typedef long long ll; 
typedef vector<int> vi;
typedef vector<long long> vl;
const ll INFL = 1e18;
const int INF = 1001001001; 
typedef pair<int,int> P;
#define foreach(ix,i) for(auto& (ix) : (i))
typedef long double ld;
const int mod =1000000007;
const double PI = acos(-1);
template<typename TypeInt>
std::string Itoa(const TypeInt v, int base)
{
    static const char table[] = "zabcdefghijklmnopqrstuvwxyz";
    string ret;
    static numeric_limits<TypeInt> t;
    TypeInt n = v;
    if (t.is_signed) {
        if (v < 0) n *= -1;
    }

    while (n >= base) {
        ret += table[n%base];
        n /= base;
    }
    ret += table[n];
    if (t.is_signed) {
        if (v < 0 && base == 10) ret += '-';
    }
    // 文字列の順番を逆にする
    std::reverse(ret.begin(), ret.end());

    return ret;
}
int main(){
	int n;cin>>n;
    map<ll,ll>m;
    rep(i,n){
        ll a;cin>>a;
        m[a]++;
    }

    ll sum =0;
    for(auto x:m){
        sum +=x.first*x.second;
    }
    int q;cin>>q;
    rep(_,q){
        ll b,c;cin>>b>>c;
        ll cnt =m[b];
        m[b]=0;
        sum-=b*cnt;
        sum+=c*cnt;
        m[c]+=cnt;
        cout<<sum<<endl;
    }

}

Measured memory_bytes: 9468
import java.io.BufferedReader;
import java.io.InputStreamReader;
 
public class Main {
 
    public static void main(String[] args) throws Exception{
 
        double r, area, circumference;
 
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        r = Double.parseDouble(br.readLine());
 
        area = r * r *  Math.PI;
        circumference = 2 * r *  Math.PI;
        System.out.println(String.format("%.6f", area) + " " + String.format("%.6f", circumference));
 
    }
 
}

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

using namespace std;

int main() {
	int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int n;
	cin >> n;
	cout << a[n - 1];
	
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define rer(i,l,u) for(int (i)=(int)(l);(i)<=(int)(u);++(i))
#define reu(i,l,u) for(int (i)=(int)(l);(i)<(int)(u);++(i))
static const int INF = 0x3f3f3f3f; static const long long INFL = 0x3f3f3f3f3f3f3f3fLL;
typedef vector<int> vi; typedef pair<int, int> pii; typedef vector<pair<int, int> > vpii; typedef long long ll;
template<typename T, typename U> static void amin(T &x, U y) { if (y < x) x = y; }
template<typename T, typename U> static void amax(T &x, U y) { if (x < y) x = y; }

template<int MOD>
struct ModInt {
	static const int Mod = MOD;
	unsigned x;
	ModInt() : x(0) { }
	ModInt(signed sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	ModInt(signed long long sig) { int sigt = sig % MOD; if (sigt < 0) sigt += MOD; x = sigt; }
	int get() const { return (int)x; }

	ModInt &operator+=(ModInt that) { if ((x += that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator-=(ModInt that) { if ((x += MOD - that.x) >= MOD) x -= MOD; return *this; }
	ModInt &operator*=(ModInt that) { x = (unsigned long long)x * that.x % MOD; return *this; }

	ModInt operator+(ModInt that) const { return ModInt(*this) += that; }
	ModInt operator-(ModInt that) const { return ModInt(*this) -= that; }
	ModInt operator*(ModInt that) const { return ModInt(*this) *= that; }
};
typedef ModInt<1000000007> mint;

int main() {
	char S[200001];
	while (~scanf("%s", S)) {
		const int A = 26;
		int N = (int)strlen(S);
		vector<array<int, A>> next(N + 1);
		rep(a, A) next[N][a] = N;
		for (int i = N - 1; i >= 0; -- i) rep(a, A)
			next[i][a] = S[i] == 'a' + a ? i : next[i + 1][a];
		vector<int> dp(N + 2);
		dp[N + 1] = 0;
		for (int i = N; i >= 0; -- i) {
			int x = INF;
			rep(a, A)
				amin(x, 1 + dp[next[i][a] + 1]);
			dp[i] = x;
		}
		int len = dp[0];
		string ans;
		int i = 0;
		rep(k, len) {
			rep(a, A) {
				if (dp[next[i][a] + 1] == len - k - 1) {
					i = next[i][a] + 1;
					ans += 'a' + a;
					break;
				}
			}
		}
		puts(ans.c_str());
	}
	return 0;
}


Measured memory_bytes: 21504
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int a = sc.nextInt();
		int b = sc.nextInt();
		for (int i = a; i <= b; i++) {
			if (i % n == 0) {
				System.out.println("OK");
				return;
			}
		}
		System.out.println("NG");

	}

}


Measured memory_bytes: 35808
let rec floor_sqrt acc acc_x_2_x_r sq_acc_minus_z r sq_r =
  if r = 0 then acc
  else
    let sq_acc_minus_z' = sq_acc_minus_z + acc_x_2_x_r + sq_r in
    ( if sq_acc_minus_z' <= 0 then
        floor_sqrt (acc + r) ((acc_x_2_x_r lsr 1) + sq_r) sq_acc_minus_z'
      else
        floor_sqrt acc (acc_x_2_x_r lsr 1) sq_acc_minus_z) (r lsr 1) (sq_r lsr 2)
let floor_sqrt z = floor_sqrt 0 0 (~-z) (1 lsl 30) (1 lsl 60)

let () = Scanf.scanf "%d %d" @@ fun n m ->
  Printf.printf "%d\n" @@
  if n = 1 then m
  else Array.fold_left (List.fold_left max) 1 @@
    Array.init (floor_sqrt m) @@ fun i ->
      if 0 < m mod (i + 1)
      then []
      else (if m / (i + 1) < n then [] else [i + 1]) @ (if (i + 1) < n then [] else [m / (i + 1)])



Measured memory_bytes: 768
from collections import deque

def pow_two_more_than(a):
    # print(a, a & (a - 1), bin(a), 1 << (len(bin(a))-2))
    if (a & (a - 1)) == 0:
        return a
    # print(1 << (len(bin(a))-2))
    return 1 << (len(bin(a))-2)

class SegmentTree:
    def __init__(self, n, l):
        self.n = pow_two_more_than(n)
        self.tree = [2**31-1]*self.n + l + [2**31-1]*(self.n-len(l))
        for i in reversed(range(1, self.n)):
            self.update_one_node(i)

    def update(self, index, m):
        x = self.n+index
        self.tree[x] = m
        while x >= 1:
            x //= 2
            self.update_one_node(x)
        # print(self.tree)
    
    def find(self, rl, rr):
        # print(f"find: [{rl}, {rr})")
        # print(self.tree[self.n:])
        min_num = 2**31-1
        q = deque([1])
        c = 0
        while q:
            # print(q)
            t = q.popleft()
            # print(t)
            height = len(bin(t)) - 3
            x = t ^ (1<<height)
            w = (self.n>>height)
            l, r = w*x, w*(x+1)
            # print((l, r), height, end=" ")
            if rl <= l and r <= rr:
                # print("complatly in")
                min_num = min(min_num, self.tree[t])
            elif r <= rl or rr <= l:
                pass
                # print("out")
            else:
                # print((l, r), (rl, rr))
                # print("overlap")
                for c in self.get_childs(t):
                    if c < self.n*2:
                        q.append(c)
            c += 1
        # print(c)
        return min_num

    def update_one_node(self, m):
        self.tree[m] = min(self.tree[c] for c in self.get_childs(m))

    # def update(self)

    def get_childs(self, m):
        return [2*m, 2*m+1]

N, Q = map(int, input().split())
CXY = [list(map(int, input().split())) for _ in range(Q)]
# N, Q = 10**5, 10**5
# CXY = [[0, i, i] for i in range(Q//2)] + [[1, 0, 0] for i in range(Q-Q//2)]

segtree = SegmentTree(N, [2**31-1]*N)

for c, x, y in CXY:
    if c == 0:
        segtree.update(x, y)
    else:
        x, y = x, y+1
        r = segtree.find(x, y)
        print(r)


Measured memory_bytes: 29056
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vec;
typedef vector<vec> mat;
typedef pair<ll,ll> pll;
const ll mod=1e9+7;
//const ll mod=998244353;
const ll inf=5e18;

int main() {
  ll h,w;
  cin >> h >> w;
  vector<string> s(h);
  for(ll i=0;i<h;i++) {
    cin >> s[i];
  }
  for(ll i=0;i<w+2;i++) {
    cout << "#";
  }
  cout << endl;
  for(ll i=0;i<h;i++) {
    cout << '#' << s[i] << '#' << endl;
  }
  for(ll i=0;i<w+2;i++) {
    cout << "#";
  }
  cout << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long int
#define pb push_back
#define MAX INT_MAX
#define MIN INT_MIN
#define MOD 1000000007
#define FO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
void solve() {
 	int size;
 	cin >> size;
 	vector <pair <int, int> > v;
 	for(int i=0;i<size;i++) {
 		int x, y;
 		cin >> x >> y;
 		v.pb(make_pair(x+y, x-y));
 	}  
 	sort(v.begin(), v.end());
 	int cur = -INT_MAX, count = 0;
 	for(int i=0;i<size;i++) {
 		if(cur <= v[i].second) {
 			count++;
 			cur = v[i].first;
 		}
 	}
 	cout << count;
    return;
}
int32_t main() {
    FO;
    solve();
    return 0;
}

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

typedef long long int llint;

int main()
{
  int f[101][100];
  int p[101][100];

  int n;
  cin>> n;

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < 10; j++) cin>> f[i][j];
  }

  for(int i = 0; i < n; i++) {
    for(int j = 0; j < 11; j++) cin>> p[i][j];
  }

  int mx = 1 << 31;

  for(int i = 1; i < 1024; i++) {

    //if(((i & 31) | (i >> 5)) != 31) continue;

    int sum = 0;
    for(int j = 0; j < n; j++) {
      int cnt = 0;
      for(int k = 0; k < 10; k++) {
        if(f[j][k] && (i >> (9 - k) & 1)) cnt++;
      }
      sum += p[j][cnt];
    }

    mx = max(mx, sum);

  }

  cout<< mx <<endl;

  return 0;
}



Measured memory_bytes: 384
f = input().split()
stack = []
for v in f:
  if v == "+":
    stack.append(stack.pop()+stack.pop())
  elif v == "-":
    stack.append(-stack.pop()+stack.pop())
  elif v == "*":
    stack.append(stack.pop()*stack.pop())
  else:
    stack.append(int(v))
print(stack.pop())
  


Measured memory_bytes: 5596
#include<stdio.h>
int main()
{
    int h,m,s,k;
    scanf("%d",&k);
    h=k/3600;
    m=k%3600/60;
    s=k%3600%60;
    printf("%d:%d:%d\n",h,m,s);
    return 0;
    
}


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

int main(void)
{
    long long N;
    cin >> N;
    vector<long long> A(N);
    for (long long i = 0; i < N; i++)
    {
        cin >> A[i];
    }
    long long Q;
    cin >> Q;
    vector<long long> B(Q);
    vector<long long> C(Q);
    for (long long i = 0; i < Q; i++)
    {
        cin >> B[i] >> C[i];
    }

    vector<long long> cnt(100001);
    for (long long i = 0; i < 100001; i++)
    {
        cnt[i] = 0;
    }
    long long ans = 0;
    for (long long i = 0; i < N; i++)
    {
        cnt[A[i]] ++;
        ans += A[i];
    }

    for (long long i = 0; i < Q; i++)
    {
        ans += cnt[B[i]] * (C[i] - B[i]);
        cnt[C[i]] += cnt[B[i]];
        cnt[B[i]] = 0;
        cout << ans << endl;
    }
}

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

int main() {
  int N;
  cin >> N;
  
  vector<tuple<string, int, int>> data(N);
  
  for (int i = 0; i < N; i++) {
    string s;
    int x;
    cin >> s >> x;
    data.at(i) = make_tuple(s, -x, i+1);
  }
  
  sort(data.begin(), data.end());
  
  for (auto a: data) {
    cout << get<2>(a) << endl;
  }
}

Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
  public static void main(String[] args){
    Scanner sc=new Scanner(System.in);
    int a=sc.nextInt(), b=sc.nextInt();
    if(a<b){
      System.out.println("a < b");  
    }
    else if(a>b){
      System.out.println("a > b");
    }
    else{
      System.out.println("a == b");
    }
  }
}


Measured memory_bytes: 26256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  bool ans = false;
  cin >> a >> b;
  if(a*2 <= b && b <= a*4){
    if(b%2 == 0){
      ans = true;
    }
  }
  if(ans){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}


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

template<typename T>
void out(T x) { cout << x << endl; exit(0); }
#define watch(x) cout << (#x) << " is " << (x) << endl





typedef long long ll;
const ll mod = 1e9+7;
const int maxn = 1e6 + 5;


struct segment_tree {

    int fuck;
    bool mx;
    int merge(int x, int y) {
	if (mx) return max(x,y);
	return min(x,y);
	
    }
    ///////////////////////////////////
    int n;
    vector<int> t;
    segment_tree() {}
    void init(int n, int fuck=-1e9, bool mx=true) {
	this->n = n;
	this->fuck = fuck;
	this-> mx = mx;
	t.resize(4*n+10);
    }
    int get(int v, int tl, int tr, int l, int r) {
	if (l > tr || r < tl) {
	    return fuck;
	} else if (l <= tl && tr <= r) {
	    return t[v];
	} else {
	    int tm = (tl + tr)/2;
	    return merge(get(2*v, tl, tm, l, r), get(2*v+1, tm+1, tr, l, r));
	}
    }
    void update(int v, int tl, int tr, int idx, int val) {
	if (tl == tr) {
	    t[v] = val;
	} else {
	    int tm = (tl + tr)/2;
	    if (idx <= tm) {
		update(2*v, tl, tm, idx, val);
	    } else {
		update(2*v+1, tm+1, tr, idx, val);
	    }
	    t[v] = merge(t[2*v], t[2*v+1]);
	}
    
    }
};



int n;
int a[maxn];
ll ans;

int nl[maxn],nr[maxn];
int nl2[maxn], nr2[maxn];


int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);  cout.tie(0);
    cin>>n;
    for (int i=0; i<n; i++) {
	cin>>a[i];
    }
    fill(nl,nl+n,-1); fill(nl2,nl2+n,-1);
    fill(nr,nr+n,n); fill(nr2,nr2+n,n);

    segment_tree tl;
    tl.init(n+10, -1e9, true);
    
    for (int i=1; i<=n; i++) {
	tl.update(1,1,n,i,-1e9);
    }
    
    for (int i=0; i<n; i++) {
	int j=i-1;
	while (j>=0 && a[i]>a[j]) {
	    j=nl[j];
	}
	nl[i]=j;

	if (nl[i] != -1) {
	    tl.update(1,1,n,a[nl[i]],-1e9);
	    int j2 = tl.get(1,1,n,a[i]+1,n);
	    if (j2 >= 0) {
		nl2[i] = j2;
	    }
	    tl.update(1,1,n,a[nl[i]],nl[i]);
	}
	tl.update(1,1,n,a[i],i);
    }

    ////////////////////////////////////////////////////////////////////////////////////////////////////////////
    segment_tree tr; tr.init(n+10, 1e9, false);
    for (int i=1; i<=n; i++) {
	tr.update(1,1,n,i,1e9);
    }

    for (int i=n-1; i>=0; i--) {
	int j=i+1;
	while (j<n && a[i]>a[j]) {
	    j=nr[j];
	}
	nr[i]=j;

	if (nr[i] != n) {
	    tr.update(1,1,n,a[nr[i]],1e9);
	    int j2 = tr.get(1,1,n,a[i]+1,n);
	    if (j2 < n) {
		nr2[i] = j2;
	    }
	    tr.update(1,1,n,a[nr[i]],nr[i]);
	}
	tr.update(1,1,n,a[i],i);
    }


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

	int L = nl[i];
	int R = nr[i];

	//cout<<L<<" "<<i<<" "<<R<<endl;

	ll x=0;

	if (L != -1) {
	    int Lp = nl2[i];
	    //Lp...L...i....R
	    ll cur = 1LL*(R-i)*(L-Lp);
	    x += cur;
	}

	if (R != n) {
	    int Rp = nr2[i];
	    //L....i....R....Rp
	    ll cur = 1LL*(Rp-R)*(i-L);
	    x += cur;
	}

	//cout<<a[i]<<": "<<x<<endl;
	
	ans += 1LL*a[i]*x;
    }

    cout<<ans<<endl;

    return 0;
}





// for (int i=0; i<n; i++) {
// 	for (int j=i+1; j<n; j++) {
// 	    vector<int> v;
// 	    for (int k=i; k<=j; k++) v.push_back(a[k]);
// 	    sort(v.rbegin(), v.rend());
// 	    ans += v[1];
// 	}
// }


// cout<<ans<<endl;


Measured memory_bytes: 16128
/* ex3_2
    riverstone*/

#include<stdio.h>
 
int main(void){
    //nをint型で定義して入力する。
    int number;
    scanf("%d", &number);
 
    // nを10で割った余りをswitchで場合分け
    switch (number % 10){
    case 2: case 4: case 5: case 7: case 9:
        printf("hon\n");
        break;
    
    case 0: case 1: case 6: case 8:
        printf("pon\n");
        break;
 
    case 3:
        printf("bon\n");
        break;
    }
    return 0;
}

Measured memory_bytes: 1660
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int k = sc.nextInt();
        char[][] c = new char[h][w];
        for(int i=0; i<h; i++) {
            String s = sc.next();
            for(int j=0; j<w; j++) {
                c[i][j] = s.charAt(j);
            }
        }
        sc.close();

        int ans = 0;
        for(int biti=0; biti<(1<<h); biti++) {
            for(int bitj=0; bitj<(1<<w); bitj++) {
                int cnt = 0;
                for(int i=0; i<h; i++) {
                    for(int j=0; j<w; j++) {
                        if((biti >> i & 1) == 1) continue;
                        if((bitj >> j & 1) == 1) continue;
                        if(c[i][j] == '#') cnt++;
                    }
                }
                if(cnt == k) ans++;
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 35832
#include<algorithm>
#include<iostream>
#include<cstring>
#include<cstdio>
#include<cmath>
#define LL long long
#define M 400100
#define mid (l+r>>1)
using namespace std;
int read(){
	int nm=0,fh=1;char cw=getchar();
	for(;!isdigit(cw);cw=getchar()) if(cw=='-') fh=-fh;
	for(;isdigit(cw);cw=getchar()) nm=nm*10+(cw-'0');
	return nm*fh;
}
struct pt{int ps,id;}t[M];
bool cmp(pt i,pt j){return i.ps<j.ps;}
int n,m,X[M][2],sz[M],MAXN,MINN=2000000000,rt;
int pos[M],fs[M<<3],nt[M<<4],to[M<<4],be[M],top,S[M],cur;
int dfn[M<<2],low[M],L[M<<2],R[M<<2],tmp,cnt,tot;
void link(int x,int y){nt[tmp]=fs[x],fs[x]=tmp,to[tmp++]=y;}
void build(int &x,int l,int r){
	x=++cnt;
	if(l==r){pos[l]=x;return;}
	build(L[x],l,mid),link(x,L[x]);
	build(R[x],mid+1,r),link(x,R[x]);
}
void addedge(int x,int l,int r,int ls,int rs,int from){
	if(r<ls||rs<l||rs<ls) return;
	if(ls<=l&&r<=rs) return link(from,x);
	addedge(L[x],l,mid,ls,rs,from);
	addedge(R[x],mid+1,r,ls,rs,from);
}
void TAR(int x){
	cur++,dfn[x]=low[x]=cur,S[++top]=x,S[top+1]=0;
	for(int i=fs[x];i!=-1;i=nt[i]){
		if(!dfn[to[i]]) TAR(to[i]);
		if(!be[to[i]]) low[x]=min(low[x],low[to[i]]);
	}
	if(low[x]<dfn[x]) return;
	else ++tot;
	while(S[top+1]!=x) be[S[top]]=tot,top--;
}
bool check(int dt){
	memset(fs,-1,sizeof(fs)),memset(low,0,sizeof(low));
	memset(dfn,0,sizeof(dfn)),memset(be,0,sizeof(be));
	build(rt,1,m<<1),tot=top=0;
	for(int i=1;i<=n;i++){
		link(pos[X[i][0]],pos[X[i][1]+m]);
		link(pos[X[i][1]],pos[X[i][0]+m]);
		link(pos[X[i][0]+m],pos[X[i][1]]);
		link(pos[X[i][1]+m],pos[X[i][0]]);
	}
	int now=1;
	for(int i=1;i<=m;i++){
		while(t[i].ps-t[now].ps>=dt&&now<i) now++;
		addedge(1,1,m<<1,now,i-1,pos[i+m]);
	}
	now=m;
	for(int i=m;i>0;i--){
		while(t[now].ps-t[i].ps>=dt&&now>i) now--;
		addedge(rt,1,m<<1,i+1,now,pos[i+m]);
	}
	for(int i=1;i<=cnt;i++) if(!dfn[i]) TAR(i);
	for(int i=1;i<=m;i++) if(be[pos[i]]==be[pos[i+m]]) return false;
	for(int i=1;i<=n;i++) if(be[pos[X[i][0]]]==be[pos[X[i][1]]]) return false;
	return true;
}
int solve(){
	int l=1,r=(MAXN-MINN)/(n-1),md,fin=0;
	while(l<=r){
		md=mid,tmp=0,cnt=0;
		if(check(md)) l=md+1,fin=md;
		else r=md-1;
	}
	return fin;
}
int main(){
	n=read(),memset(fs,-1,sizeof(fs));
	for(int i=1;i<=n;i++){
		X[i][0]=read(),X[i][1]=read();
		m++,t[m].ps=X[i][0],t[m].id=i;
		m++,t[m].ps=X[i][1],t[m].id=i;
		MAXN=max(max(X[i][0],X[i][1]),MAXN);
		MINN=min(min(X[i][0],X[i][1]),MINN);
	}
	sort(t+1,t+m+1,cmp);
	for(int i=1;i<=m;i++) X[t[i].id][sz[t[i].id]++]=i;
	printf("%d\n",solve());
	return 0;
}

Measured memory_bytes: 46976
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    divisors.sort()
    return divisors


N = int(input())
N_div = make_divisors(N)[1:]
N1_div = make_divisors(N-1)[1:]

ans = len(N1_div)

for i in N_div:
    n = N
    while n % i == 0:
        n //= i
    if n % i == 1:
        ans += 1
print(ans)

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

int main(){
  int n;
  string s;
   
  string ans;
  cin >> n >> s;
  char now = s.at(0);
  for(int i=1;i<n;i++){
    if(now != s.at(i)) {
      ans += now;
      now = s.at(i);
    }
  }
  if(ans[ans.size()-1] != now) ans += now;

  cout << ans.size() << endl;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define de(x) cout<<#x<<"="<<x<<endl
const int N = 1e4+55;
map<int ,int >q;
map<int , int>::iterator it;
int main(){
    int n,a;
    cin>>n;
    for(int i=0;i<n;i++){
        scanf("%d",&a);
        if(q[a]==0 ) q[a]=1;
        else q[a]=0;
    }
    int ans=0;
    for(it=q.begin();it!=q.end();it++){
        ans+=it->second;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 4864
#include <iostream>
#include <vector>
#include <string>
#include <numeric>
#include <algorithm>
#include <utility>
#include <vector>
#include <array>
#include <map>
using std::cout;
using std::cin;
using std::string;


int main()
{
  int n;
  string s;
  int k;
  cin >> n >> k;
  cin >> s;
  std::map<char, char> map;
  map['A'] = 'a';
  map['B'] = 'b';
  map['C'] = 'c';
  s[k-1] = map[s[k-1]];
  cout << s << "\n";
  return 0;
}


Measured memory_bytes: 256
import itertools
s = int(input())
if s < 3:
    print(0)
    exit()

l = [1]*(s - 2)
total = 0
three_cnt = s // 3

for i in range(three_cnt):
    total += l[s - 3 - (i*3)]
    for j in range(s - 3):
        l[j + 1] += l[j]
print(total % ((10 ** 9) + 7))

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

using namespace std;

const double PI = 3.141592;
const double R = 6378.1;

int main() {
	double N1, E1, N2, E2, Rad;

	while (1) {
		cin >> N1 >> E1 >> N2 >> E2;
		if (N1 == -1 && E1 == -1 && N2 == -1 && E2 == -1) {
			break;
		}

		N1 = N1 * PI / 180.0;
		E1 = E1 * PI / 180.0;
		N2 = N2 * PI / 180.0;
		E2 = E2 * PI / 180.0;

		Rad = R * acos(cos(N1)*cos(N2)*cos(E1 - E2) + sin(N1)*sin(N2));
		cout << round(Rad) << endl;
	}

	return 0;
}


Measured memory_bytes: 3380
#include<iostream>
using namespace std;
int main()
{
  string s;
  cin>>s;
  int count=0;
  int i=0;
  int maxm=0;
  int n=3;
  while(i<n)
  {
    if(s[i]=='R')
    {
    while(s[i]=='R'&&i<n)
    {
      count++;
      i++;
    }
    }
    else 
    {
     i++; 
    }
    maxm=max(maxm,count);
    count=0;
  }
cout<<maxm;
}


Measured memory_bytes: 3124
#include<bits/stdc++.h>
#include<algorithm>
using namespace std;
#define ll long long

void solve(){
	int h1,s1,h2,s2;
	cin>>h1>>s1>>h2>>s2;
	while(true){
		h2-=s1;
		if(h2<=0){
			cout<<"Yes";
			break;
		}
		h1-=s2;
		if(h1<=0){
			cout<<"No";
			break;
		}
	}
}

int main(){
	solve();
	return 0;
}

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

listA=list(map(int,input().split()))
listB=list(map(int,input().split()))
listC=list(map(int,input().split()))

ans=0
for i in range(N):
	ans+=listB[i]
	if i==N-1:
		break
	if listA[i]+1==listA[i+1]:
		ans+=listC[listA[i]-1]

print(ans)

Measured memory_bytes: 3064
#include<cstdio>

int main(){
    int n;
    scanf("%d", &n);
    int a = 1;
    int ans = 0;
    while(a<n){
        int r = n / a;
        int q = n % a;
        if(q == 0) r--;
        ans += r;
        a++;
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 1732
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;
#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

fn calc_distance(x: &Vec<f64>, y: &Vec<f64>) -> f64{
    let mut ans: f64 = 0.0;

    for i in 0..x.len(){
        ans += (x[i] - y[i]) * (x[i] - y[i]);
    }

    return ans.sqrt();
}

fn main(){
    let line = read_as_vec::<usize>();
    let (n, d) = (line[0], line[1]);

    let mut dots: Vec<Vec<f64>> = vec![];

    for _ in 0..n{
        dots.push(read_as_vec::<f64>());
    }

    let mut ans = 0;
    for i in 0..n{
        for j in i+1..n{
            let value: f64 = calc_distance(&dots[i], &dots[j]);
            if value.ceil() == value.floor(){
                ans += 1;
            }
        }
    }

    println!("{}", ans);
}


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

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

seg_el=1<<(N.bit_length()) # Segment treeの台の要素数
SEG=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化
LAZY=[0]*(2*seg_el) # 1-indexedなので、要素数2*seg_el.Segment treeの初期値で初期化

def indexes(L,R): # 遅延伝搬すべきノードのリストを返す. （つまり, updateやgetvaluesで見るノードより上にあるノードたち）
    INDLIST=[]

    R-=1
    
    L>>=1
    R>>=1

    while L!=R:
        if L>R:
            INDLIST.append(L)
            L>>=1
        else:
            INDLIST.append(R)
            R>>=1

    while L!=0:
        INDLIST.append(L)
        L>>=1

    return INDLIST
        

def adds(l,r,x): # 区間[l,r)を +x 更新
        
    L=l+seg_el
    R=r+seg_el

    L//=(L & (-L))
    R//=(R & (-R))

    UPIND=indexes(L,R)
    
    while L!=R:
        if L > R:
            SEG[L]+=x
            LAZY[L]+=x
            L+=1
            L//=(L & (-L))

        else:
            R-=1
            SEG[R]+=x
            LAZY[R]+=x
            R//=(R & (-R))

    for ind in UPIND:
        SEG[ind]=min(SEG[ind<<1],SEG[1+(ind<<1)])+LAZY[ind]
        
def getvalues(l,r): # 区間[l,r)に関するminを調べる

    L=l+seg_el
    R=r+seg_el

    L//=(L & (-L))
    R//=(R & (-R))

    UPIND=indexes(L,R)
    
    for ind in UPIND[::-1]: # 遅延伝搬
        if LAZY[ind]!=0:
            plus_lazy=LAZY[ind]
            
            SEG[ind<<1]+=plus_lazy
            SEG[1+(ind<<1)]+=plus_lazy
            
            LAZY[ind<<1]+=plus_lazy
            LAZY[1+(ind<<1)]+=plus_lazy
            
            LAZY[ind]=0
            
    ANS=1<<31

    while L!=R:
        if L > R:
            ANS=min(ANS , SEG[L])
            L+=1
            L//=(L & (-L))

        else:
            R-=1
            ANS=min(ANS , SEG[R])
            R//=(R & (-R))

    return ANS

ANS=[]

for _ in range(Q):
    query=list(map(int,input().split()))
    if query[0]==0:
        adds(query[1],query[2]+1,query[3])

    else:
        ANS.append(getvalues(query[1],query[2]+1))

print("\n".join([str(ans) for ans in ANS]))



Measured memory_bytes: 25012
#include <iostream>
#include <string>
#include <sstream>
#include <cmath>
#include <fenv.h>
#include <algorithm>
#include <cstdio>

using namespace std;
unsigned int digitSum(unsigned long long x)
{
	unsigned int result = 0;
	while(x > 0)
	{
		result += x % 10;
		x /= 10;
	}
	return result;
}
void solve(int n,int a, int b)
{

	 int sum=0;
	 for(unsigned long long i=1; i <= n; ++i)
	 {
		 unsigned int ds = digitSum(i);
		 if(ds >= a && ds <=b) sum+=i;

	 }
	 cout << sum << endl;
}
int main()
{
	 int a,b,n;cin>> n>>a>>b;
//	 int a=2,b=5,n=20;
//	 int a=1,b=2,n=10;
//	 int a=4,b=16,n=100;
	 solve(n,a,b);

	 return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define lld long long int
#define pb push_back
#define in insert
#define mod 1000000007
#define pi 3.14159265358979

using namespace std;

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

    lld n,a,b;
    cin>>n>>a>>b;

    if(n==1)
    {
        if(a==b)cout<<1<<"\n";
        else cout<<0<<"\n";
        return 0;
    }

    if(b-a<0)cout<<0<<"\n";
    else if(b-a>=0)
    {
       cout<<((n-2)*(b-a))+1<<"\n";
    }
}


Measured memory_bytes: 3640
#include<iostream>
#include<string>
#include<vector>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<algorithm>
#include<functional>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cassert>
#include<ctime>
using namespace std;

#define mind(a,b) (a>b?b:a)
#define maxd(a,b) (a>b?a:b)
#define absd(x) (x<0?-(x):x)
#define pow2(x) ((x)*(x))
#define rep(i,n) for(int i=0; i<n; ++i)
#define repr(i,n) for(int i=n-1; i>=0; --i)
#define repl(i,s,n) for(int i=s; i<=n; ++i)
#define replr(i,s,n) for(int i=n; i>=s; --i)
#define repf(i,s,n,j) for(int i=s; i<=n; i+=j)
#define repe(e,obj) for(auto e : obj)

#define SP << " " <<
#define COL << " : " <<
#define COM << ", " <<
#define ARR << " -> " <<
#define PNT(STR) cout << STR << endl
#define POS(X,Y) "(" << X << ", " << Y << ")"
#define DEB(A) " (" << #A << ") " << A
#define DEBREP(i,n,val) for(int i=0; i<n; ++i) cout << val << " "; cout << endl
#define ALL(V) (V).begin(), (V).end()
#define INF 1000000007
#define INFLL 1000000000000000007LL
#define EPS 1e-9

typedef unsigned int uint;
typedef unsigned long ulong;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define P_TYPE int
typedef pair<P_TYPE, P_TYPE> P;
typedef pair<P, P_TYPE> PI;
typedef pair<P_TYPE, P> IP;
typedef pair<P, P> PP;
typedef priority_queue<P, vector<P>, greater<P> > pvqueue;

#define N 100007

int n, q;
ll a[N], s[N], t[N];

ll solve(ll x) {
  ll le = 0, ri = 2000000007LL;
  while(le + 1 < ri) {
    ll mid = (le + ri) >> 1;

    int p = x-mid > 0 ? lower_bound(a, a+n, x-mid) - a : 0;
    int q = x+mid <= a[n-1] ? lower_bound(a, a+n, x+mid) - a : n;

    if(q-p <= n-q) {
      le = mid;
    } else {
      ri = mid;
    }
  }
  int p = x-le > a[0] ? lower_bound(a, a+n, x-le) - a : 0;
  int q = x+le <= a[n-1] ? lower_bound(a, a+n, x+le) - a : n;
  int c1 = q-p, c2 = n-q;
  ll res = t[n] - t[q];
  if(c1 == c2) {
    res += s[p];
  } else if(c1+1 == c2) {
    if(p >= 1) {
      res += s[p-1];
    }
  }
  return res;
}

int main() {
  cin >> n >> q;
  rep(i, n) {
    cin >> a[i];
    a[i] <<= 1;
    //cout << i SP a[i] << endl;
    t[i+1] = t[i] + a[i];
  }
  rep(i, n) {
    s[i+1] = i >= 1 ? s[i-1] + a[i] : a[i];
  }
  rep(i, q) {
    ll x; cin >> x;
    cout << (solve(x << 1)>>1) << endl;
  }
  return 0;
}

Measured memory_bytes: 4096
/**
* Motto:   fight till end
* Author: fyter_112
**/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define fast ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pii pair<int,int>
#define mp make_pair
#define pb push_back
#define all(x) x.begin(),x.end()
#define mod 1000000007
int32_t main()
{
  fast;
  int t;
  int n,ae,b;
  cin>>n;
  int a[n],sum=0;
  map<int,int>m;
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    sum+=a[i];
    m[a[i]]++;
  }
  cin>>t;
  while(t--)
  {
    cin>>ae>>b;
    sum-=(ae*m[ae]);
    sum+=(b*m[ae]);
    m[b]+=m[ae];
    m[ae]=0;
    cout << sum <<'\n';
  }
}


Measured memory_bytes: 10312
#include<iostream>
 
using namespace std;
int main(void)
{
  int k,x;
	cin >> k >> x ;
  
  int min,max;
  
  // min
  if (x - k + 1< -1000000)
    min = -1000000;
  else
    min = x - k + 1;
  
  // max
  if (x + k - 1 > 1000000)
    max = 1000000;
  else
    max = x + k - 1;
  
  for(int i = min;i <= max ;i++)
    cout << i << " ";
  
}

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

int main(){
  int a,b,c,d;
  cin >> a >> b >> c >> d;
  if(max(a,c)-min(a,c)<=d)
    cout << "Yes" << endl;
  else if(max(a,b)-min(a,b)<=d&&max(b,c)-min(b,c)<=d)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <climits>
#include <iomanip>

using namespace std;


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

	int n;
	string s;
	cin >> n;
	cin >> s;

	int ans = 1;
	char now = s[0];
	for (int i = 1; i < n; i++) {
		if (s[i] != now) {
			ans++;
			now = s[i];
		}
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define long long ll
#define unsigne long long ull
int main()
{
	
	
	int i,j,k,l;
	
	int n,m;
	cin>>n>>m;
	if(n==0||n==1)
	i=0;
	else i=(n*(n-1))/2;
	if(m==0||m==1)
	j=0;
	else j=(m*(m-1))/2;
	cout<<i+j;
}

Measured memory_bytes: 256
import java.util.*;

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

        final Scanner sc = new Scanner(System.in);
        int i = sc.nextInt();

        boolean flg = false;
        while (i != 0) {
            if (i % 10 == 7) {
                flg = true;
            }
            i /= 10;
        }
        if (flg) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

        sc.close();
    }
}


Measured memory_bytes: 35540
#!/usr/bin/env python3

import sys
# import math
# from string import ascii_lowercase, ascii_upper_case, ascii_letters, digits, hexdigits
# import re                                    # re.compile(pattern) => ptn obj; p.search(s), p.match(s), p.finditer(s) => match obj; p.sub(after, s)
# from operator import itemgetter              # itemgetter(1), itemgetter('key')
# from collections import deque                # deque class. deque(L): dq.append(x), dq.appendleft(x), dq.pop(), dq.popleft(), dq.rotate()
# from collections import defaultdict          # subclass of dict. defaultdict(facroty)
# from collections import Counter              # subclass of dict. Counter(iter): c.elements(), c.most_common(n), c.subtract(iter)
# from heapq import heapify, heappush, heappop # built-in list. heapify(L) changes list in-place to min-heap in O(n), heappush(heapL, x) and heappop(heapL) in O(lgn).
# from heapq import nlargest, nsmallest        # nlargest(n, iter[, key]) returns k-largest-list in O(n+klgn).
# from itertools import count, cycle, repeat   # count(start[,step]), cycle(iter), repeat(elm[,n])
# from itertools import groupby                # [(k, list(g)) for k, g in groupby('000112')] returns [('0',['0','0','0']), ('1',['1','1']), ('2',['2'])]
# from itertools import starmap                # starmap(pow, [[2,5], [3,2]]) returns [32, 9]
# from itertools import product, permutations  # product(iter, repeat=n), permutations(iter[,r])
# from itertools import combinations, combinations_with_replacement
# from itertools import accumulate             # accumulate(iter[, f])
# from functools import reduce                 # reduce(f, iter[, init])
# from functools import lru_cache              # @lrucache ...arguments of functions should be able to be keys of dict (e.g. list is not allowed)
# from bisect import bisect_left, bisect_right # bisect_left(a, x, lo=0, hi=len(a)) returns i such that all(val<x for val in a[lo:i]) and all(val>-=x for val in a[i:hi]).
# from copy import deepcopy                    # to copy multi-dimentional matrix without reference
# from fractions import gcd                    # for Python 3.4 (previous contest @AtCoder)


def main():
    mod = 1000000007                # 10^9+7
    inf = float('inf')              # sys.float_info.max = 1.79...e+308
    # inf = 2 ** 64 - 1               # (for fast JIT compile in PyPy) 1.84...e+19
    sys.setrecursionlimit(10**6)    # 1000 -> 1000000
    def input(): return sys.stdin.readline().rstrip()
    def ii():    return int(input())
    def mi():    return map(int, input().split())
    def mi_0():  return map(lambda x: int(x)-1, input().split())
    def lmi():   return list(map(int, input().split()))
    def lmi_0(): return list(map(lambda x: int(x)-1, input().split()))
    def li():    return list(input())
    
    
    n = ii()
    p = [ii() for _ in range(n)]
    print(sum(p) - max(p)//2)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064