akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;

int CNT[100001];
bool isPrime[100001];

int main() {
	int Q; cin >> Q;

	for (int i = 2; i < 100001; i++) {
		int x = i;
		bool flag = true;
		for (int j = 2; flag && j*j <= x; j++) {
			if (x%j == 0)flag = false;
		}

		isPrime[i] = flag;
	}

	for (int i = 2; i < 100001; i++) {
		if (isPrime[i] && isPrime[(i + 1) / 2])CNT[i]++;
	}

	for (int i = 2; i < 100001; i++)CNT[i] += CNT[i - 1];

	for (int i = 0; i < Q; i++) {
		int l, r; cin >> l >> r;

		cout << CNT[r] - CNT[l - 1] << endl;
	}

	return 0;
}

Measured memory_bytes: 1152
// reference: https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
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 count(x: u64, k: u32) -> u64 {
    let n = x + 1;
    let p = 2u64.pow(k);
    let q = p / 2;
    let r = (n / p) * q;
    let s = std::cmp::max((n % p) as i64 - q as i64, 0) as u64;
    r + s
}

fn main() {
    input! {
        a: u64,
        b: u64
    }

    let mut ans = 0u64;
    for k in (1..40 + 1).rev() {
        let x = count(std::cmp::max(a - 1, 0), k);
        let y = count(b, k);
        ans <<= 1;
        ans |= (y - x) % 2;
    }

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


Measured memory_bytes: 4352
#![allow(non_snake_case)]
#[allow(unused_imports)]
use std::io::{self, Write};
#[allow(unused_imports)]
use std::collections::{BTreeMap, BTreeSet, BinaryHeap, HashMap, HashSet, VecDeque};
#[allow(unused_imports)]
use std::cmp::{max, min, Ordering};
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};
    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };
    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };
    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };
    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
     };
     ($next:expr, $t:ty) => {
         $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(dead_code)]
const MOD: u64 = 1000000007;
#[allow(dead_code)]
fn to_num(c: char) -> i64 {
    c as i64 - 48
}


fn main() {
    input!{
        N: usize, T: usize,
        A: [usize; N]
    }

    let mut B = vec![0; N];
    B[0] = A[0];
    let mut minA = A[0];

    for i in 1..N {
        minA = min(minA, A[i]);
        B[i] = minA;
    }

    let C: Vec<usize> = A.iter().zip(B.iter()).map(|(a, b)| a - b).collect();
    let maxC = C.iter().max().unwrap();
    println!("{:?}", C.iter().fold(0, |acc, c| acc + if c == maxC { 1 } else { 0 }));
}

Measured memory_bytes: 6396
#include<bits/stdc++.h>
using namespace std;
int main() {
  int n, m, X, Y;
  int mx = -101, mn = 101;
  cin >> n >> m >> X >> Y;
  bool flag = true;
  int x[101], y[101];
  for(int i = 0; i < n; ++i) {
    cin >> x[i];
    mx = max(x[i], mx);
  }

  for(int j = 0; j < m; ++j) {
    cin >> y[j];
    mn = min(y[j], mn);
  }
  if(mx >= mn) flag = false;
  else {
    if(mn > Y || mx <= X) flag = false;
  }
  if(flag) cout << "No War" << endl;
  else cout << "War" << endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int gcd(int x, int y) {
	if (x < y) swap(x, y);
	if (y == 0) return x;
	return gcd(y, x % y);
}
int A[100010];
int L[100010], R[100010];
int main()
{
	int N;
	cin >> N;
	for (int i = 0; i < N; i++) cin >> A[i];
	L[0] = A[0];
	R[N - 1] = A[N - 1];
	for (int i = 1; i < N; i++) {
		L[i] = gcd(L[i - 1], A[i]);
		R[N - i - 1] = gcd(R[N - i], A[N - i - 1]);
	}
	int ans = 0;
	for (int i = 0; i < N; i++) {
		if (i == 0) ans = max(ans, R[i + 1]);
		else if (i == N - 1) ans = max(ans, L[i - 1]);
		else  ans = max(ans, gcd(L[i - 1], R[i + 1]));
	}
	cout << ans << endl;
}

Measured memory_bytes: 1408
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Map;

public class Main {

  public static void main(String[] args) {
    new Main().run();
  }

  public void run() {
    
    try(BufferedReader in = new BufferedReader(new InputStreamReader(System.in))) {

      int n = Integer.parseInt(in.readLine());
      String line = in.readLine();
      int nHalf = n >> 1;

      Integer num;
      Map<Integer,Integer> mapA = new HashMap<>();
      Map<Integer,Integer> mapB = new HashMap<>();
      List<Map<Integer,Integer>> aMap = new ArrayList<>();
      aMap.add(mapA);
      aMap.add(mapB);
      int offset=0,next=0;
      char regx = ' ';

      for(int i=0; i<n; i++) {
        if((next = line.indexOf(regx,offset)) == -1)
          next = line.length();
        num = new Integer(line.substring(offset, next));
        offset = ++next;

        // aMap.get(i&1).merge(num, 1, Integer::sum);
        if(aMap.get(i&1).containsKey(num))
          aMap.get(i&1).replace(num, aMap.get(i&1).get(num) + 1);
        else
          aMap.get(i&1).put(num, 1);
      }

      int[] vm1 = {0,0};
      int[] vm2 = {0,0};
      int[] x   = {0,0};

      for (int i=0; i<aMap.size(); i++) {
        for (Map.Entry<Integer,Integer> m : aMap.get(i).entrySet()) {
          int val = m.getValue();
          if(vm1[i] <val) {
            vm2[i] = vm1[i];
            vm1[i] = val;
            x[i]  = m.getKey();
          } else if(vm2[i] < val) {
            vm2[i] = val;
          }
        }
      }

      int ans = 0;
      int cca1 = nHalf - vm1[0];
      int ccb1 = nHalf - vm1[1];
      int cca2 = nHalf - vm2[0];
      int ccb2 = nHalf - vm2[1];

      if(x[0] == x[1])
        ans = cca2 > ccb2 ? cca1 + ccb2 : cca2 + ccb1;
      else
        ans = cca1 + ccb1;

      System.out.println(ans);
    }
    catch(IOException e) {
      System.err.println(e);
    }
  }
}

Measured memory_bytes: 49416
#include<bits/stdc++.h>
using namespace std;
 
#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define spa << " " <<
ll MOD = 1e9+7;
void chmin(ll &a, ll b) { if (a > b) a = b; }
void chmax(ll &a, ll b) { if (a < b) a = b; }
 
int main(){
  ll i, j;
  ll n, k;
  cin >> n >> k;
  cout << (n % k != 0) << endl;
 
  return 0;
}

Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;


void main() {
    int n;
    scan(n);

    double ans = 0;

    foreach (i ; 0 .. n) {
        double x; string t;
        scan(x, t);
        if (t == "JPY") {
            ans += x;
        }
        else {
            ans += x * 380000;
        }
    }

    writefln("%.12f", ans);
}




int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i ; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i ; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {writeln(b ? "Yes" : "No");}
void YES(bool b) {writeln(b ? "YES" : "NO");}
T[] readArr(T)() {return readln.split.to!(T[]);}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}


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

using pii = pair <int, int>;

#define N 300000

int n, m;
int dp[N], val[N], w[N];

int D, Q;

vector <pii> can[N];

void query(int &ans, int v, int L, int cur) {
	if (v <= m) {
		ans = max(ans, cur + (--lower_bound(can[v].begin(), can[v].end(), pii(L + 1, 0))) -> second);
		return;
	}
	query(ans, v >> 1, L, cur);
	if (L >= w[v]) query(ans, v >> 1, L - w[v], cur + val[v]);
	return;
}

int main() {
	D = 9;
	scanf("%d", &n);
	for (int i = 1; i <= n; i ++) scanf("%d %d", &val[i], &w[i]);
	dp[1] = 0;
	for (int i = 2; i <= n; i ++) dp[i] = dp[i>>1] + 1;
	m = min(n, (1<<D) - 1);
	can[0] = {{0, 0}};
	for (int i = 1; i <= m; i ++) {
		auto &res = can[i];
		auto &from = can[i>>1];
		vector <pii> tmp;
		tmp = from;
		for (auto x : from) {
			tmp.emplace_back(x.first + w[i], x.second + val[i]);
		}
		sort(tmp.begin(), tmp.end());
		for (auto x : tmp) {
			if (!res.empty() && res.back().second >= x.second) continue;
			res.push_back(x);
		}
	}
	scanf("%d", &Q);
	while (Q --) {
		int v, L, ans = 0;
		scanf("%d %d", &v, &L);
		query(ans, v, L, 0);
		printf("%d\n", ans);
	}
	return 0;
}


Measured memory_bytes: 15292
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<numeric>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i = 0;i<((int)(n));i++)
#define reg(i,a,b) for(int i = ((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i = ((int)(n)-1);i>=0;i--)
#define ireg(i,a,b) for(int i = ((int)(b));i>=((int)(a));i--)
typedef long long ll;
typedef pair<ll, ll> mp;

/*
ac
含まれない部分文字列の最後の文字をαに固定する．
すると，最後に出てきたαよりも前の文字列の中に含まれない最短部分文字列を求める問題に帰着された．
順番に気をつけよう（右から左へのdpでないと辞書順にならない）
*/

int dp[200010]={},before[200010][26];
string a;

int f(int i){
	if(i>a.size())return 0;
	if(dp[i]!=0)return dp[i];
	int smallest=1e9;
	rep(j,26){
		smallest=min(smallest,f(before[i][j]+1));//最後がj種類目のアルファベットで終わる最短文字列
	}
	return dp[i]=smallest+1;
}

string g(int i){
	if(i>a.size())return "";
	rep(j,26){
		if(f(before[i][j]+1)+1==dp[i])return (char)('a'+j)+g(before[i][j]+1);
	}
	return "ああああああ！！！！！！！！！";
}

int main(void){
	cin>>a;
	rep(j,26)before[a.size()][j]=a.size();//まだ出てない
	dp[a.size()]=1;
	irep(i,a.size()){//文字列を1-originにする
		rep(j,26)before[i][j]=before[i+1][j];
		before[i][a[i]-'a']=i;
	}
	f(0);
	cout<<g(0)<<endl;
	// reg(i,1,a.size())cout<<i<<":"<<dp[i]<<endl;
	return 0;
}

Measured memory_bytes: 22276
#include <bits/stdc++.h>
using namespace std;
#define INF 0x3f3f3f3fLL
#define endl '\n'
typedef long long ll;
int cnt[30];
int main(){
    ios::sync_with_stdio(0);
    int n, m; cin >> n >> m;
    for (int i = 0; i < n; i++){
        for (int j = 0; j < m; j++){
            char s; cin >> s;
            cnt[s - 'a']++;
        }
    }
    int p1 = 0, p2 = 0, p4 = 0;
    for (int i = 1; i <= (n + 1) / 2; i++){
        for (int j = 1; j <= (m + 1) / 2; j++){
            int ans = 4;
            if ((n & 1) && i == (n + 1) / 2) ans /= 2;
            if ((m & 1) && j == (m + 1) / 2) ans /= 2;
            if (ans == 4) p4++;
            else if (ans == 2) p2++;
            else p1++;
        }
    }
    for (int i = 0; i < 26; i++){
        while (cnt[i] >= 4 && p4){ cnt[i] -= 4; p4--;}
        while (cnt[i] >= 2 && p2){ cnt[i] -= 2; p2--;}
        while (cnt[i] >= 1 && p1){ cnt[i] -= 1; p1--;}
        if (cnt[i]){cout << "No" << endl; return 0;}
    }
    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))

dp = [0]*(10**6 + 1)
ans = 0

for i in a:
    if dp[i] == 0:
        for j in range(1,10**6+1):
            if i * j > 10**6:
                break
            dp[i*j] += 1
    elif dp[i] == 1:
        dp[i] += 1

for i in a:
    if dp[i] == 1:
        ans += 1


print(ans)


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

int N;
int K;
int A[100005];
int maximum=0;
int factor;

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

    else
    {
        return gcd(b, a%b);
    }
}

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

    for (int i=1; i<=N; i++)
    {
        cin>>A[i];
        maximum=max(maximum, A[i]);
        if (i==1)
        {
            factor=A[i];
        }

        else
        {
            factor=gcd(factor, A[i]);
        }
    }

    if (K>maximum)
    {
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }

    if (K%factor!=0)
    {
        cout<<"IMPOSSIBLE"<<endl;
        return 0;
    }

    cout<<"POSSIBLE"<<endl;
}

Measured memory_bytes: 3948
#include "bits/stdc++.h"

#define REP(i, n ,N) for(ll i = (n); i < (N); i++)
#define p(s) cout<<(s)<<endl
#define p2(a, b) cout<<(a)<<" "<<(b)<<endl
using namespace std;
typedef long long ll;
ll mod = 1e9+7;
ll inf = 1e18;

ll N;
ll A[100010];
ll odd_sum[100010];
ll even_sum[100010];
int main(){
	cin >> N;
	REP(i,0,N){
		cin>>A[i];
	}

	even_sum[0] = A[0];
	even_sum[1] = A[0];
	odd_sum[1] = A[1];
	odd_sum[0] = 0;
	REP(i,2,N){
		if(i%2) {
			odd_sum[i] += odd_sum[i-2] + A[i];
			even_sum[i] += even_sum[i-1];
		}
		else {
			odd_sum[i] += odd_sum[i-1];
			even_sum[i] += even_sum[i-2] + A[i];
		}

	}
	cout << even_sum[N-1] - odd_sum[N-2];
	REP(i,1,N){
		if(i%2==0) {
			cout <<" "<< (even_sum[N-1] - even_sum[i-1])
						 - (odd_sum[N-2] - odd_sum[i-1])
						 + (odd_sum[i-1] - even_sum[i-1]);
		}
		else {
			cout <<" "<< -(even_sum[N-1] - even_sum[i-1])
						 + (odd_sum[N-2] - odd_sum[i-1])
						 + (even_sum[i-1] - odd_sum[i-1]);
		}
	}
	cout<<endl;
	return 0;
}

Measured memory_bytes: 3712
import java.util.*;
import java.util.HashSet;

public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);

	    int N = sc.nextInt();
        HashSet list = new HashSet();
      
      for(int i=0 ;i < N; i++){
        String prize = sc.next();
        list.add(prize);
      }
      
      System.out.println(list.size());
      
    }
}


Measured memory_bytes: 67116
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
int main(){	
	ios_base::sync_with_stdio(false);
	    cin.tie(NULL);
	    int n;
	    cin >> n;
	    for(int i = 1; i <= 9 ; i++){
	    	for(int j = i ; j <= 9 ; j++){
	    		if(i * j == n){
	    			cout << "Yes" << endl;
	    			return 0;
	    		}
	    	}
	    }
	    cout << "No" << endl;
		return 0; 
}

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

#define llong long long
#define fr(i,l,r) for(i=(l);i<(r);i++)
#define min(p,q) ((p)<(q)?(p):(q))
#define max(p,q) ((p)>(q)?(p):(q))
#define INF 1000000000000//10^12



int main(void)
{
	//変数の宣言
	llong int n,p;
	int num;
	
	//よく使う変数
	int i,j,k,l;
	int flag=0;
	llong int ans=0;
	int count=0;
	int temp,temp1,temp2;
	int max,min;
	int len;
	int sum=0;
	int under,upper,middle;

	//データの読み込み
	scanf("%lld %lld",&n,&p);

	
//	printf("nは%dです\n", n);
//	printf("データの読み込み終了\n");
	//実際の処理
	
	if(n==1){
		printf("%lld",p);
		return 0;
	}
	
	ans=1;
	
	for(i=2;i<1000000;i++){
		num=0;
		while(p%i==0){
			num++;
			p=p/i;
		}
		while(num>=n){
	//		printf("i=%d\n",i);
			ans=ans*i;
			num=num-n;
		}
	}
	
	
	
//	printf("計算部分終了\n");
	//出力
	
	printf("%lld",ans);
	
	
//	printf("結果の出力終了\n");
	
	return 0;
	
}



Measured memory_bytes: 128
#include<deque>
#include<queue>
#include<vector>
#include<algorithm>
#include<iostream>
#include<set>
#include<cmath>
#include<tuple>
#include<string>
#include<chrono>
#include<functional>
#include<iterator>
#include<random>
#include<unordered_set>
#include<unordered_map>
#include<array>
#include<map>
#include<bitset>
#include<iomanip>
using namespace std;
typedef long long int llint;
typedef long double lldo;
#define mp make_pair
#define mt make_tuple
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define fir first
#define sec second
#define res resize
#define ins insert
#define era erase
//ios::sync_with_stdio(false);
//std::cin.tie(0);
//<< setprecision(20)
const int mod=1e9+7;
const llint big=1e15+100;
const long double pai=3.141592653589793238462643383279502884197;
const long double ena=2.71828182845904523536;
const long double eps=1e-7;
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
template <class T> void soun(T& ar)
{sort(ar.begin(),ar.end());ar.erase(unique(ar.begin(),ar.end()),ar.end());}
llint gcd(llint a,llint b){if(a%b==0){return b;}else return gcd(b,a%b);}
llint lcm(llint a,llint b){return a/gcd(a,b)*b;}
int n;
vector<int>oya;
vector<vector<int>>ko;
vector<int>siz;
vector<llint>wa;
vector<llint>naga;
vector<pair<int,int>> henban;
int make_tree(int ter,int per){
	if(per!=-1){ko[ter].era(find(ko[ter].begin(),ko[ter].end(),per));}
	oya[ter]=per;
	int kos=1;
	for(auto it:ko[ter]){kos+=make_tree(it,ter);}
	siz[ter]=kos;
	return kos;
}
int main(void){
	int i;
	cin>>n;
	oya.res(n);
	ko.res(n);
	siz.res(n);
	wa.res(n);
	naga.res(n);
	henban.res(n-1);
	for(int i=0;i<n-1;i++){
		int a,b;cin>>a>>b;a--;b--;
		henban[i]=mp(a,b);
		ko[a].pub(b);
		ko[b].pub(a);
	}
	for(int i=0;i<n;i++){cin>>wa[i];}
	make_tree(0,-1);
	int wakaran=-1;
	for(i=1;i<n;i++){//0は親のため除く
		if(siz[i]+siz[i]==n){wakaran=i;continue;}
		naga[i]=(wa[i]-wa[oya[i]])/(n-siz[i]-siz[i]);
	}
	if(wakaran!=-1){
		llint nok=wa[wakaran];
		for(i=1;i<n;i++){nok-=siz[i]*naga[i];}
		int now=oya[wakaran];
		while(now!=0){nok-=(n-siz[now]-siz[now])*naga[now];now=oya[now];}
		naga[wakaran]=nok/(n/2);
	}
	for(i=0;i<n-1;i++){
		int a,b;a=henban[i].fir;b=henban[i].sec;
		if(oya[a]!=b){swap(a,b);}
		cout<<naga[a]<<endl;
	}
	return 0;
}

Measured memory_bytes: 14080
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG
typedef long long ll;
typedef pair<int, int> P;
typedef pair<pair<int, int>, int> PP;
typedef bitset<61> Bitset;
const ll INFL = 1LL << 60;
const ll MOD = 1000000007;
const int INF = INT_MAX;
const int MAX = 300000;
ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
ll LCM(ll a, ll b) { return (a * b) / GCD(a, b); }
//------------------------------------------------------------------------------------------------------------------------------
int main(void) {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;cin>>N;
    vector<int>A(N+1);
    A[N] = INT_MAX;
    for(int i = 0; i < N; i++) cin>>A[i];
    sort(A.begin(),A.end());
    bool seen[1000010];
    for(int i = 0; i <= 1000000; i++) seen[i] = 0;
    int ans = 0;
    for(int i = 0; i < N; i++) {
        if(!seen[A[i]]){
            if(A[i]<A[i+1]) ans++;
            for(int j = A[i]; j <= 1000000; j+=A[i]) {
                seen[j] = 1;
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5036
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        static void Main(string[] args)
        {
            SolveA(args);
            //SolveB(args);
            //SolveC(args);
            //SolveD(args);


        }
        private const long MOD = 1000000007;
        static void SolveA(string[] args)
        {
            var nk = ReadAndParseIntArr();
            int n = nk[0];
            int k = nk[1];

            long total = 0;
            for(int b = 1;b<=n;++b)
            {
                total += Calc(b, n, k);
            }
            Console.WriteLine(total);
        }
        private static int Calc(int b , int n, int k)
        {
            int total = 0;
            int block = Math.Max(b - k, 0);
            total += block * (n / b);
            total += Math.Max ((n % b) - k + 1, 0);
            if( k == 0)
            {
                total -= 1;
            }
            return Math.Max(0, total);
        }
    }
}

Measured memory_bytes: 11220
#include <iostream>
#include <vector>
#include <algorithm>
#include <list>
#include <iomanip>
#include <string>
#include <cctype>
#include <cstdio>
#include <cmath>


using namespace std;



int main() {
	double PI = acos(-1);
	double a, b, c;
	double S, L, h;
	cin >> a >> b >> c;
	double rad = c * PI / 180;
	
	S = a * b * sin(rad) / 2;
	L = a + b + sqrt(a * a + b * b - 2 * a * b * cos(rad));
	h = b * sin(rad);

	cout << fixed << S << endl;
	cout << fixed << L << endl;
	cout << fixed << h << endl;
}


Measured memory_bytes: 3620
#include<bits/stdc++.h>
using namespace std ;
int main(){
/*	#ifndef ONLINE_JUDGE
	freopen("/home/yash/Desktop/CPP/input.txt","r",stdin);
    freopen("/home/yash/Desktop/CPP/output.txt","w",stdout);
	#endif*/

	int n , k ;

	cin >> n >> k ;

	vector<int> v(n);

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

	long long int ans = 0 ;

	sort(v.begin() , v.end());

	for( int i=0 ; i<k ; i++ ){
		ans = ans + v[i];
	}

	cout<<ans<<endl;
}

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

const int maxn=1e5+100;

int dp[maxn],n;
vector <int> v;

int main(){
	scanf("%d",&n);
	for(int i=0;i<maxn;i++) dp[i]=1e9;
	dp[n]=0;
	for(int i=n;i>=0;i--){
		for(int j=6;j<=i;j*=6)
			dp[i-j]=min(dp[i-j],dp[i]+1);
		for(int j=9;j<=i;j*=9)
			dp[i-j]=min(dp[i-j],dp[i]+1);
	}
	int ans=1e9;
	for(int i=0;i<=n;i++) ans=min(ans,dp[i]+i);
	printf("%d",ans);
	return 0;
}

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

using namespace std;
typedef long long ll;

#define MOD (long long)(1e9+7)
#define INF (1LL<<60)
#define rep(i,n) for(ll i = 0; i < (n); i++)
#define rep1(i,n) for(ll i = 1; i <= (n); i++)

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


// 最大公約数
ll gcd(ll a, ll b)
{
  if(b == 0) return a;
  return gcd(b, a % b);
}

// mod m におけるa の逆元
ll modinv(ll a, ll m) {
  ll b = m, u = 1, v = 0;
  while (b) {
    ll t = a / b;
    a -= t * b; swap(a, b);
    u -= t * v; swap(u, v);
  }
  u %= m;
  if (u < 0) u += m;
  return u;
}

// 素因数分解
vector<pair<ll, ll>> prim;
void pf(ll n)
{
  ll s = sqrt(n);
  ll r = 0;
  for(ll i = 2; i <= s; i++) {
    if((n % i) == 0) {
      r = 0;
      do {
	r++;
	n = n / i;
      } while((n % i) == 0);
      prim.push_back({i, r});
    }
  }
  if(n > s) {
    prim.push_back({n, 1});
  }
}

void solve()
{
  ll n, k; cin >> n >> k;
  vector<ll> h(n); rep(i, n) cin >> h[i];
  vector<ll> dp(n, INF);

  dp[0] = 0;
  rep1(i, n - 1) {
    rep1(j, k) {
      if(i - j >= 0) {
	chmin(dp[i], dp[i - j] + abs(h[i] - h[i - j]));
      }
    }
  }
  
  cout << dp[n-1] << endl;
}


int main(void)
{
  // ll t; cin >> t; REP(i, t)
  solve();
}


Measured memory_bytes: 1792
def main():
  info = input()
  info = info.split()
  
  join_num = int(info[0])
  rating = int(info[1])
  
  if join_num < 10:
    rating = rating + 100*(10-join_num)
  
  print(rating)

if __name__ == "__main__":
  main()
  

Measured memory_bytes: 2940
#include <iostream>
#include <cmath>
#include <complex>
#include <string>
#include <sstream>
#include <limits>
#include <algorithm>
#include <functional>

using namespace std;

long long width[30];

long long process(long long x1, long long y1, long long x2, long long y2, int level)
{
	if (level == 0) return abs(y1 - y2);
	
	long long w = width[level - 1];
	long long x1_id = x1 / w;
	long long x2_id = x2 / w;
	long long y1_id = y1 / w;
	long long y2_id = y2 / w;

	if (x1_id != x2_id) return abs(x1 - x2) + abs(y1 - y2);
	if (x1_id == 1 && abs(y1_id - y2_id) > 1)
	{
		return abs(y1 - y2) + min(x1 % w + 1 + x2 % w + 1, (w - x1 % w) + (w - x2 % w));
	}

	return process(x1 % w, y1, x2 % w, y2, level - 1);
}

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

	width[0] = 1;
	for (int i = 1; i < 30; i++)
	{
		width[i] = width[i - 1] * 3;
	}

	int Q;
	cin >> Q;

	while (Q--)
	{
		long long x1, y1, x2, y2;
		cin >> x1 >> y1 >> x2 >> y2;

		x1--;
		y1--;
		x2--;
		y2--;

		if (abs(x1 - x2) > abs(y1 - y2))
		{
			swap(x1, y1);
			swap(x2, y2);
		}

		cout << process(x1, y1, x2, y2, 30) << "\n";
	}

	return 0;
}

Measured memory_bytes: 384
def ind(S):
  L4=list()
  for i in range(len(S)):
    if S[len(S)-i-1]=="1":
      L4.append(i)
  return set(L4)
N=int(input())
L=list(map(int,input().split()))
L=[ind(bin(i)[2:]) for i in L]
ans=0
n=0
i=0
T=set()
while True:
  if i==N and n==N:
    break
  elif i==N:
    ans+=i-n
    n+=1
    continue
  if T&L[i]==set():
    T=T|L[i]
    ans+=1
    i+=1
  else:
    T=T-L[n]
    n+=1
    ans+=i-n
  if i==N and n!=N:
    n+=1
print(ans)

Measured memory_bytes: 176684
n = gets.chomp.to_i
x = gets.chomp.split.map(&:to_f)
y = gets.chomp.split.map(&:to_f)

p1 = 0
p2 = 0
p3 = 0
p4 = Array.new
x.size.times do |i|
   p1 += (x[i] - y[i]).abs
   p2 += ((x[i] - y[i]).abs) ** 2
   p3 += ((x[i] - y[i]).abs) ** 3
   p4 << (x[i] - y[i]).abs
end
p2 = p2 ** 0.5
p3 = p3 ** Rational(1,3)

printf("%.8f%s", p1, "\n")
printf("%.8f%s", p2, "\n")
printf("%.8f%s", p3, "\n")
printf("%.8f%s", p4.max_by {|num| num}, "\n")

Measured memory_bytes: 8860
while True:
    list = input().split()
    a = int(list[0])
    op = list[1]
    b = int(list[2])
    if op == "?":
        break
    if op == "+":
        print("%d" %(a+b))
    if op == "-":
        print("%d" %(a-b))
    if op == "*":
        print("%d" %(a*b))
    if op == "/":
        print("%d" %(a/b))


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

using namespace std;
using ll = long long int;
#define long ll

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

    ll n;
    cin >> n;

    vector<ll> cnt(5);
    for (ll i=0; i<n; i++) {
        string s;
        cin >> s;
        
        ll idx = 0;
        switch(s[0]) {
            default:
                idx++;
            case 'M':
                idx++;
            case 'A':
                idx++;
            case 'R':
                idx++;
            case 'C':
                idx++;
            case 'H':
                ;
        }
        if(idx < 5)
            cnt[idx]++;
    }

    ll r = 0;
    for(ll i=0; i<5; i++)
        for(ll j=i+1; j<5; j++)
            for(ll k=j+1; k<5; k++)
                r += cnt[i] * cnt[j] * cnt[k];
    cout << r << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,sum;
long long t[201];
int main()
{
    cin>>n;
    for(int i=0;i<n;i++)
	{
		cin>>t[i];
	}
	for(int i=0; ;i++)
	{
	   for(int j=0;j<n;j++)
	   {
		   if(t[j]%2)
		   {
			   cout<<sum<<endl;
			   return 0;
		   }
	   }
	   sum++;
	   for(int j=0;j<n;j++)
	   {
		  t[j]/=2;
	   }
	}
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}
ll n,m,x,num;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin>>n>>m;
	while(m--)cin>>x,num+=x;
	if(num>n)cout<<-1;
	else cout<<n-num;
	return 0;
}


Measured memory_bytes: 3640
n = input()
k = int(input())
nl = len(n)

dp = [[[0]*(k+1) for _ in range(2)]for _ in range(nl+1)]
#dp[i][j][k] i:上からの桁数、j:smaller flag、k:0以外の数字の個数
dp[0][0][0] = 1

for i in range(nl):
  for j in range(2):
    for l in range(k+1):
      c = int(n[i])
      if j == 1:
        dp[i+1][j][l] += dp[i][j][l]
        if l < k:
          dp[i+1][j][l+1] += dp[i][j][l]*9
      else:
        if c == 0:#0しか選べない上にsmallを確定できない
          dp[i+1][0][l] += dp[i][j][l]
        else:
          dp[i+1][1][l] += dp[i][j][l]#cより確実に小さい0を使う。small確定
          if l < k:
            dp[i+1][1][l+1] += dp[i][j][l]*(c-1) #c以下の数字を使えばsmall確定
            dp[i+1][0][l+1] += dp[i][j][l] #cを使ったらsmall確定できない
            
print(dp[nl][0][k]+dp[nl][1][k])

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<ll> A(N + 1), B(N);
    for (int i = 0; i < N + 1; i++) {
        cin >> A[i];
    }
    for (int i = 0; i < N; i++) {
        cin >> B[i];
    }

    ll ans = min(A[0], B[0]);
    B[0] -= min(A[0], B[0]);
    A[0] -= min(A[0], B[0]);

    for (int i = 0; i < N; i++) {
        ans += min(B[i], A[i]);
        B[i] -= min(B[i], A[i]);
        ans += min(B[i], A[i + 1]);
        A[i + 1] -= min(B[i], A[i + 1]);
    }

    cout << ans << endl;

}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <unistd.h>
#include <cassert>
#include <cctype>
#include <random>
#define _USE_MATH_DEFINES
#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
int iinf = intmax / 8;
ll inf = llmax / 8;
double eps = 1e-11;

int main() {
    ll N;
    cin >> N;
    ll a[N];
    ll keta[32];
    fill(keta, keta + 32, 0);
    ll num = 0;
    for (int i = 0; i < N; i++) {
        cin >> a[i];
        for (int j = 0; j < 32; j++) {
            if (a[i] & (1 << j)) {
                keta[j]++;
                break;
            }
        }
        num = num ^ a[i];
    }
    //cout << num << endl;
    ll ans = 0;
    bool ok = true;
    for (int i = 31; i >= 0; i--) {
        if ((num & ((ll)1 << i)) > 0 && keta[i] == 0) {
            ok = false;
            break;
        }
        if (num & (1 << i)) {
            //cout << i << endl;
            ans++;
            for (int j = i; j >= 0; j--) {
                num = num ^ ((ll)1 << j);
            }
        }
    }
    if (ok) {
        cout << ans << endl;
    } else {
        cout << -1 << endl;
    }
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef pair<long long, long long> p;

int main() {
    long long n,m; cin >> n >> m;
    vector<long long> a(n);
    for(int i = 0; i < n; i ++) cin >> a[i];
    vector<p> bc(m);
    for(int i = 0; i < m; i ++) {
        long long b, c; cin >> b >> c;
        bc[i] = make_pair(c,b);
    }
    sort(a.begin(), a.end());
    sort(bc.begin(), bc.end());
    long long sum = 0;
    for(int i = 0; i < n; i ++) {
        if(bc.back().first<= a[i] || bc.empty()) {
            sum += a[i];
            continue;
        }
        sum += bc.back().first;
        bc.back().second --;
        if(bc.back().second == 0) bc.pop_back();
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 2560
//Resting_Prince
#include<bits/stdc++.h>
#define mod 1000000007
#define inf 1e18
#define PI 3.141592653589
#define fi first
#define se second 
#define sv(v) sort(all(v));reverse(all(v))
#define all(v) v.begin(),v.end()
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repr(i,a,b) for(ll i=a;i>=b;i--)
#define pb push_back
#define mk make_pair
#define en '\n'
#define ios ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pll;
typedef long double ld;

ll ceil1(ll a,ll b)
{
    if(b%a==0)
        return b/a;
    return (b/a+1);
}

int main()
{
    string s,t;
    ll a,b,c,d;
    cin>>a>>b;
    if(b==1){cout<<0;return 0;}
    if(a>=b){cout<<1;return 0;}
    c=a;
    a--;
    cout<<(1+ceil1(a,(b-c)));
    return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

#define umap unordered_map 
#define uset unordered_set 

#define F0r(i, a, b) for(int i=a; i<(b); i++)
#define For(i, a)    for(int i=0; i<(a); i++)
#define F0rb(i,a,b)  for(int i = (b); i >= a; i--)
#define Forb(i,a)    for(int i = (a); i >= 0; i--)

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define setbits(x)  __builtin_popcountll(x)
#define zrobits(x)  __builtin_ctzll(x)
#define all(x) x.begin(), x.end()
#define ins insert
#define w(x) int x; cin >> x ; while(x--)
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const char nl = '\n';



int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	int n;
	cin >> n;
	int p = n % 1000 == 0 ? 1000 : n % 1000;
	cout << 1000 - p << nl;
	return 0;
}


Measured memory_bytes: 3608
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        int[] menu = new int[5];
        for (int i = 0; i < 5; i++)
        {
            menu[i] = int.Parse(Console.ReadLine());
        }
        int ans = 0;
        int tmp;
        for (int i = 0; i < 4; i++)
        {
            int min = 10 - menu[i] % 10;
            int index = i;
            for (int j = i + 1; j < 5; j++)
            {
                if (menu[j] % 10 == 0)
                {
                    index = j;
                    break;
                }
                else if (min > 10 - menu[j] % 10)
                {
                    min = 10 - menu[j] % 10;
                    index = j;
                }
            }
            if (index != i)
            {
                tmp = menu[i];
                menu[i] = menu[index];
                menu[index] = tmp;
            }
        }
        for (int i = 0; i < 4; i++)
        {
            ans += (int)Math.Ceiling(menu[i] / 10.0) * 10;
        }
        ans += menu[4];
        Console.WriteLine(ans);
    }
}

Measured memory_bytes: 11092
use proconio::input;

const MOD: usize = 1_000_000_007;


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

    let mut after: Vec<usize> = vec![];
    let mut before: Vec<usize> = vec![];

    for i in 0..n {
        let mut count = 0;
        for j in 0..i {
            if aa[j] < aa[i] {
                count += 1;
            }
        }
        before.push(count);

        let mut count = 0;
        for j in i+1..n {
            if aa[j] < aa[i] {
                count += 1;
            }
        }
        after.push(count);
    }
    dbg!(&before, &after);
    for b in before.iter_mut() {
        if k % 2 == 0 {
            *b *= k / 2;
            *b %= MOD;
            *b *= k - 1;
            *b %= MOD;
        } else {
            *b *= k;
            *b %= MOD;
            *b *= (k - 1) / 2;
            *b %= MOD;
        }
    }
    for a in after.iter_mut() {
        let temp = *a * k;
        if k % 2 == 0 {
            *a *= k / 2;
            *a %= MOD;
            *a *= k - 1;
            *a %= MOD;
        } else {
            *a *= k;
            *a %= MOD;
            *a *= (k - 1) / 2;
            *a %= MOD;
        }
        *a += temp;
        *a %= MOD;
    }

    let mut count = 0;
    for (a, b) in after.into_iter().zip(before.into_iter()) {
        count += a;
        count += b;
        count %= MOD;
    }
    println!("{}", count);
}


Measured memory_bytes: 2212
#include <iostream>
#include <vector>
#include <bitset>

using namespace std;

void solve()
{
	int N, M;
	while(cin >> N >> M, N || M)
	{
		vector<bitset<721> > used(M + 1);
		vector< vector<int> > login(M + 1, vector<int>(N + 1));
		int r;
		cin >> r;
		for(int i = 0; i < r; ++i)
		{
			int t, n, m, s;
			cin >> t >> n >> m >> s;
			if(s == 0)
			{
				for(int j = login[m][n]; j < t - 540; ++j)
				{
					used[m].set(j);
				}
			}
			else
			{
				login[m][n] = t - 540;
			}
		}
		int q;
		cin >> q;
		for(int i = 0; i < q; ++i)
		{
			int ts, te, m;
			cin >> ts >> te >> m;
			int count = 0;
			for(int j = ts - 540; j < te - 540; ++j)
			{
				if(used[m][j])
				{
					++count;
				}
			}
			cout << count << endl;
		}
	}
}

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

Measured memory_bytes: 32268
#include <bits/stdc++.h>
using namespace std;
int main (){
  int N,x;
 
  cin>>N;
  vector <int> v(N);
    for(int i=0;i<N;i++){
      cin>>v.at (i);
    }    
   
  vector <int> c(N);
    for(int i=0;i<N;i++){
      cin>>c.at (i);
    }
  for(int i=0;i<N;i++){
    if(c.at(i)<v.at(i)){
     x+=v.at(i)-c.at(i);
  }
  }
    cout<<x<<endl;
  
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>
#include<queue>
#include<cmath>

using namespace std;

typedef long long int64;

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

    vector<int> num(100001);

    for (int64 i = 0; i < 100001; i++)
    {
        num[i]=0;
    }

    for (int64 i = 0; i < N; i++)
    {
        num[A[i]]++;
    }
    
    for (int64 i = 0; i < Q; i++)
    {
        sum+=(num[B[i]])*(C[i]-B[i]);
        num[C[i]]+=num[B[i]];
        num[B[i]]=0;
        cout<<sum<<endl;
    }
    
    
    
    
    return 0;
}

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

if N<10:
    print(N)
elif N<100:
    print(9)
elif N<1000:
    X=9+(N-99)
    print(X)
elif N<10000:
    print(909)
elif N<100000:
    X=909+(N-9999)
    print(X)
else:
    print(90909)


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

int main()
{
    int N, M;
    cin >> N >> M;
    vector<vector<int>> A(N, vector<int>(N, 0));
    int a, b;
    rep(i, M)
    {
        cin >> a >> b;
        A.at(a - 1).at(b - 1) += 1;
        A.at(b - 1).at(a - 1) += 1;
    }
    int sum = 0;
    rep(i, N)
    {
        sum = 0;
        rep(j, N)
        {
            sum += A.at(i).at(j);
        }
        cout << sum << endl;
    }
}

Measured memory_bytes: 256
/*
https://img.atcoder.jp/cf17-final/editorial.pdf
贪心+dp
关于为什么按 hi + pi 升序排列，官方题解说的很有道理。
这边提供另外一种证明：考虑一个合法的选的序列，对于每一个 i 必须满足 sum_{j <= i}{h_j} <= h_i + p_i,
因为前缀和递增所以 hi + pi 也必须递增。
*/
#include <bits/stdc++.h>
#define rep(i, x, y) for (int i = x; i <= y; i++)
using namespace std;

const int N = 5005;
typedef long long ll;
const ll inf = 0x3f3f3f3f3f3f3f3f;
int n, a[N], b[N], c[N], id[N];
ll mn[N];

bool cmp(int x, int y) { return c[x] == c[y] ? b[x] < b[y] : c[x] < c[y]; }

int main() {
    cin >> n;
    rep(i, 1, n) scanf("%d%d", &a[i], &b[i]), c[i] = a[i] + b[i], id[i] = i;
    sort(id + 1, id + n + 1, cmp);
    memset(mn, 0x3f, sizeof(mn));
    mn[0] = 0;
    rep(i, 1, n) {
        for (int j = n - 1; j >= 0; j--)
            if (mn[j] != inf && mn[j] <= a[id[i]])
                mn[j + 1] = min(mn[j + 1], mn[j] + b[id[i]]);
    }
    for (int i = n; i >= 0; i--) if (mn[i] != inf) return printf("%d\n", i), 0;
	return 0;
}

Measured memory_bytes: 3988
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  string p;
  cin>>n>>p;
  for(int i=0;i<p.size();i++)
  {
    p[i]=p[i]+n;
    if(p[i]>90)
      p[i]=p[i]-26;
  }
  cout<<p;
  
  return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
  int N, K, sum=1;
  scanf("%d%d", &N ,&K);
  for (int i=0; i<N ; i++){
    if (sum < K){
    sum *= 2;
    }
    else{
      sum += K;
    }
  }
  printf("%d", sum);
  return 0;
}

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


int main(){
  int n; cin>>n;
  int ans=0;
  vector<int> v(n);
  
  for(int i=0;i<n;i++)cin>>v[i];
   for(int i=0;i<n;i++){
     int c; cin>>c;
     int sa; sa=v[i]-c;
     if(sa>0)ans+=sa;
   }
   cout<<ans<<endl;
}

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

using ll = long long;
using vll = vector<ll>;
using pl4 = pair<ll,ll>;
using str = string;

#define sz size()
#define be begin()
#define en end()
#define fi first
#define se second
#define pb push_back

#define llin(x) ll (x);cin >>(x);
#define stin(x) str (x);cin >>(x);
#define FOR(i,a,b) for(ll i = a ; i <= b ; i++)
#define rFOR(i,b,a) for(ll i = a; i >= b ; i--)
#define SORT(x) sort(x.be, x.en)
#define rSORT(x) sort(x.rbegin(), x.rend())
#define say(x) cout<<(x);
#define sal(x) cout<<(x)<<endl;
#define yn(a) cout <<((a)?"yes":"no")<<endl;
#define Yn(a) cout <<((a)?"Yes":"No")<<endl;
#define YN(a) cout <<((a)?"YES":"NO")<<endl;
#define Imp(a) cout <<((a)?"Possible":"Impossible")<<endl;
#define IMP(a) cout <<((a)?"POSSIBLE":"IMPOSSIBLE")<<endl;

signed main(){
    llin(d);
    say("Christmas");
    FOR(i,1,25-d){
        say(' ');
        say("Eve");
    }
    cout <<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long ll;
#define rep(i,a,n) for(ll i = a;i < n;i++)
#define rrep(i,a,n) for(ll i = n; i >= a;i--)
#define LINF (ll)1e18
#define INF (int)1e9
#define ll_1e9 (ll)1e9
using namespace std;


int main(){
    ll n;
    cin >> n;
    ll l = 0,r = n,m,i = 0;
    
    string res_0,res_m;

    cout << 0 << endl;
    cin >> res_0;
    if(res_0 == "Vacant") return 0;
    
    while(i++ < 19){
        
        m = (r+l)/2;

        cout << m << endl;
        cin >> res_m;

        if(res_m == "Vacant") break;

        if(m % 2){
            if(res_0 == res_m) r = m;
            else l = m+1;
        }
        else{
            if(res_0 == res_m) l = m;
            else r = m+1;
        }
    }
    return 0;
}


Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
const ll MOD = 1000000007;
const ld PI = acos(-1);  
const ld EPS = 0.0000000001;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define rep(i, n) for(ll i=0; i<(ll)(n); i++)
#define repd(i, n) for(ll i=n-1; 0<=i; i--)
#define FOR(i, a, b) for(ll i=a; i<(ll)(b); i++)
#define FORD(i, a, b) for(ll i=b-1; (ll)(a)<=i; i--)
#define ALL(x) x.begin(), x.end()
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
string YES[2] = {"NO", "YES"};
string yes[2] = {"No", "Yes"};


int main(){
    ll n;   cin >> n;
    vector<ll> x(n), y(n);
    ll maxm=-LINF, maxp=0-LINF, minim=LINF, minip=LINF;
    rep(i, n){
        cin >> x[i] >> y[i];
        maxp = max(maxp, x[i]+y[i]);
        minip = min(minip, x[i]+y[i]);
        maxm = max(maxm, x[i]-y[i]);
        minim = min(minim, x[i]-y[i]);
    }
    cout << max(maxp-minip, maxm-minim) << endl;
    
}

Measured memory_bytes: 6396