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

int main() {

	int num = 0;
	int a[100000];
	int cha = 0;
	int ans = 0;

	cin >> num;

	a[num] = -5;

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

	sort(a, a + num);

	for (int i = 0; i < num; i++) {
		cha += 1;
		if (a[i] != a[i+1] && cha % 2 == 1) { 
			ans += 1; 
			cha = 0;
		}
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
#define all(x) x.begin(),x.end()
#define rep(i,j,n) for (long long i = j; i < (long long)(n); i++)
#define _GLIBCXX_DEBUG
#define MOD 1000000007
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
//(a+b-1)/b

signed main(){
	int a,b,c,d; cin>>a>>b>>c>>d;
	if(a+b==c+d)cout<<"Balanced";
	else if(a+b>c+d)cout<<"Left";
	else cout<<"Right";

}

Measured memory_bytes: 3552
#include<stdio.h>
int main()
{
	int a,b,c,d,d1,d2,d3,d4;
	scanf("%d%d %d %d",&a,&b,&c,&d);
	
    if(c>a) d1=c-a;
    if(c<a) d1=a-c;
    if(b>a) d2=b-a;
    if(b<a) d2=a-b;
    if(b<c) d3=c-b;
    if(b>c) d3=b-c;
 
 
    if((d1<=d)||((d2<=d)&&(d3<=d)))
    printf("Yes\n");
    
    else
    printf("No\n");
    
	return 0;
}

Measured memory_bytes: 1996
import Data.Char
f y = (g 0 y == 1)
  where
    g n [] = n
    g n ('C':xs) = g (n+1) xs
    g n (x:xs) = if isLower x then g n xs else 100
main = do
  (x:x1:xss) <- getLine
  let xs = init xss; y = last xss
  putStrLn $ if x == 'A' && isLower y && isLower x1 && f xs then "AC" else "WA"


Measured memory_bytes: 380
#include<cstdio>

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

using namespace std;

const int dx[]={1,0,-1,0},dy[]={0,1,0,-1};

int main(){
	for(int n;scanf("%d",&n),n;){
		bool jewel[21][21]={};
		rep(i,n){
			int x,y;	scanf("%d%d",&x,&y);
			jewel[y][x]=true;
		}

		int m,x=10,y=10,cnt=0;	scanf("%d ",&m);
		rep(i,m){
			char c;
			int s,d;	scanf("%c%d ",&c,&s);
			switch(c){
				case 'N': d=1; break;
				case 'E': d=0; break;
				case 'S': d=3; break;
				case 'W': d=2; break;
			}
			rep(j,s){
				x+=dx[d],y+=dy[d];
				if(jewel[y][x]) jewel[y][x]=false,cnt++;
			}
		}

		puts(cnt==n?"Yes":"No");
	}

	return 0;
}

Measured memory_bytes: 0
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.NoSuchElementException;

public class Main {

	static PrintWriter out;
	static InputReader ir;
	static int[] par, dep, ch;

	static void solve() {
		int a=Integer.parseInt(ir.next()+ir.next());
		out.println(a==Math.pow((int)Math.sqrt(a),2)?"Yes":"No");
	}

	public static void main(String[] args) throws Exception {
		ir = new InputReader(System.in);
		out = new PrintWriter(System.out);
		solve();
		out.flush();
	}

	static class InputReader {

		private InputStream in;
		private byte[] buffer = new byte[1024];
		private int curbuf;
		private int lenbuf;

		public InputReader(InputStream in) {
			this.in = in;
			this.curbuf = this.lenbuf = 0;
		}

		public boolean hasNextByte() {
			if (curbuf >= lenbuf) {
				curbuf = 0;
				try {
					lenbuf = in.read(buffer);
				} catch (IOException e) {
					throw new InputMismatchException();
				}
				if (lenbuf <= 0)
					return false;
			}
			return true;
		}

		private int readByte() {
			if (hasNextByte())
				return buffer[curbuf++];
			else
				return -1;
		}

		private boolean isSpaceChar(int c) {
			return !(c >= 33 && c <= 126);
		}

		private void skip() {
			while (hasNextByte() && isSpaceChar(buffer[curbuf]))
				curbuf++;
		}

		public boolean hasNext() {
			skip();
			return hasNextByte();
		}

		public String next() {
			if (!hasNext())
				throw new NoSuchElementException();
			StringBuilder sb = new StringBuilder();
			int b = readByte();
			while (!isSpaceChar(b)) {
				sb.appendCodePoint(b);
				b = readByte();
			}
			return sb.toString();
		}

		public int nextInt() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			int res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public long nextLong() {
			if (!hasNext())
				throw new NoSuchElementException();
			int c = readByte();
			while (isSpaceChar(c))
				c = readByte();
			boolean minus = false;
			if (c == '-') {
				minus = true;
				c = readByte();
			}
			long res = 0;
			do {
				if (c < '0' || c > '9')
					throw new InputMismatchException();
				res = res * 10 + c - '0';
				c = readByte();
			} while (!isSpaceChar(c));
			return (minus) ? -res : res;
		}

		public double nextDouble() {
			return Double.parseDouble(next());
		}

		public int[] nextIntArray(int n) {
			int[] a = new int[n];
			for (int i = 0; i < n; i++)
				a[i] = nextInt();
			return a;
		}

		public long[] nextLongArray(int n) {
			long[] a = new long[n];
			for (int i = 0; i < n; i++)
				a[i] = nextLong();
			return a;
		}

		public char[][] nextCharMap(int n, int m) {
			char[][] map = new char[n][m];
			for (int i = 0; i < n; i++)
				map[i] = next().toCharArray();
			return map;
		}
	}
}


Measured memory_bytes: 21332
import java.util.InputMismatchException;
import java.util.Scanner;

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

			int A = scanner.nextInt();
			int B = scanner.nextInt();
			int C = scanner.nextInt();

			int answer = B / A;

			if (C < answer)
				answer = C;

			System.out.println(answer);
			scanner.close();
		} catch (InputMismatchException e) {
			System.out.println("整数を入力してください。");
		}
	}
}


Measured memory_bytes: 23124
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
#define int long long 
const long long inf=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long, long > > vpll;
typedef vector<pair<int, int > > vpii;
#define FORR(x,arr) for(auto& x:arr)
#define ZERO(a) memset(a,0,sizeof(a))





//3111111111111111111111111111111





bool isprime(int x){
	for(int i = 2;i*i<=x;i++){
		if(x%i == 0)return false;
	}
	return x!=1;
}
	void solve(){


		ini(n);
		set<int>set1;
		int tmp = 0;
		if(isprime(n))return out(tmp+1);
		int tmp_ = n;
		for(int i = 2;i*i<=n;i++){
			if(n%i == 0){
				if(isprime(i)){
					//out(i);
					int tmpp = n;
					int i1 = i;
					while(tmpp%i1 == 0){
						tmpp/=i1;
						tmp_/=i1;
						set1.insert(i1);
						i1*=i;
						tmp++;
					}
				}
				int i2 = n/i;
              if(i2!=i){
				if(isprime(i2)){
					//out(i);
					int tmpp = n;
					int i1 = i2;
					while(tmpp%i1 == 0){
						tmpp/=i1;
						tmp_/=i1;
						set1.insert(i1);
						i1*=i2;
						tmp++;
					}
				}
              }
			}		
		}
		//out(tmp_);
		out(tmp);
	}























int32_t main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall 
	oneforall

	solve();
	


	return 0;
}


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

#define FOR(i,l,r) for(int i = (int) (l);i < (int) (r);i++)
template<typename T> bool chmax(T& a,const T& b){ return a < b ? (a = b,true) : false; }
template<typename T> bool chmin(T& a,const T& b){ return b < a ? (a = b,true) : false; }
typedef long long ll;

ll N,M;
ll fact [200001];
const ll MOD = 1e9 + 7;

int main()
{
	scanf("%lld%lld",&N,&M);

	fact [0] = 1;
	FOR(i,1,200001){
		fact [i] = fact [i - 1] * i % MOD;
	}

	ll ans = 0;
	if(N == M){
		ans = fact [N] * fact [M] * 2 % MOD;
	}
	else if(abs(N - M) == 1){
		ans = fact [N] * fact [M] % MOD;
	}

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

	return 0;
}


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

int main()
{
  string S;
  cin >> S;
  string weather[] = {"Sunny", "Cloudy", "Rainy"};
  for (int i = 0; i < 3; ++i)
  {
    if (weather[i] == S)
    {
      cout << weather[(i + 1)%3];
      break;
    }
  }
  return 0;
}


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

int main() {
  int n;
  cin >> n;
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    s.at(i) += n;
    if (s.at(i) > 'Z') s.at(i) -= 26;
  }
  cout << s << endl;
}


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

using i64 = long long int;

int main(){
    int n, s;
    cin >> n >> s;
    vector<int> v;
    for(int i=0;i<n;++i){
        int a;
        cin >> a;
        v.push_back(a);
    }

    int left = 0, right = 1, acc = v[0];
    int ans = INT_MAX;
    while(right <= n){
        if(acc < s){
            acc += v[right];
            right++;
        }else if(acc >= s){
            ans = min(ans, right - left);
            acc -= v[left];
            left++;
            if(right <= left)right++;
        }
    }

    cout << (ans == INT_MAX ? 0 : ans) << endl;

    return 0;
}



Measured memory_bytes: 3528
import sys

n = int(input())
a = list(map(int,input().split()))
mi,ma = 10 ** 6,0
cnt = [0] * n
for v in a:
    cnt[v] += 1
    mi = min(mi,v)
    ma = max(ma,v)
if ma - mi >= 2:
    print("No")
    sys.exit()
if mi != ma:
    if cnt[mi] == ma or (n - cnt[mi]) // (ma - cnt[mi]) < 2:
        print("No")
    else:
        print("Yes")
else:
    if mi == n - 1 or mi * 2 <= n:
        print("Yes")
    else:
        print("No")


Measured memory_bytes: 52804
#include <iostream>
#include <string>


using namespace std;


int main()
{
	string str;

	getline(cin, str);

	// 変換
	for(int i = 0; i < str.length(); i++){
		if(97 <= str[i] && str[i] <= 122)
			str[i] -= 32;
		else if(65 <= str[i] && str[i] <= 90)
			str[i] += 32;
	}

	cout << str << endl;

	return 0;
}


Measured memory_bytes: 3188
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int Q = sc.nextInt();
    int[] a = new int[Q];
    int[] b = new int[Q];
    int[] c = new int[Q];
    int[] d = new int[Q];
    for (int i = 0; i < Q; i++) {
      a[i] = sc.nextInt();
      b[i] = sc.nextInt();
      c[i] = sc.nextInt();
      d[i] = sc.nextInt();
    }
    sc.close();

    int[] A = new int[N];
    Arrays.fill(A, 1);

    boolean ok = false;
    long ans = 0;

    while (!ok) {
      long sum = 0;
      for (int i = 0; i < Q; i++)
        if (A[b[i] - 1] - A[a[i] - 1] == c[i]) sum += d[i];

      ans = Long.max(ans,  sum);

      for (int i = N - 1; -1 < i; i--) {
        A[i]++;
        if (A[i] <= M) break;
        if (i == 0) ok = true;
        if (!ok)
          for (int j = i; j < N; j++)
            A[j] = A[i - 1] + 1;
      }
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 36996
s = input()

n = int(s)

a = []
total = 0


def is_753(a):
    return set(a) == set([7,5,3])

def get_int(a):
    result = 0
    for i in range(len(a)):
        result = result * 10 + a[len(a) - i - 1]
    return result

def dfs(a, k):
    global total
    if is_753(a):
        total += 1
    for next_x in [3,5,7]:
        a.append(next_x)
        if get_int(a) <= k:
            dfs(a, k)
            a.pop()
        else:
            a.pop()
            break

dfs(a, n)
print(total)


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

int main(){
    int a, b;
    char op;
    while(cin >> a >> op >> b){
        if(op == '?')return 0;
        else if(op == '+')cout << a + b << endl;
        else if(op == '-')cout << a - b << endl;
        else if(op == '*')cout << a * b << endl;
        else if(op == '/')cout << a / b << endl;
    }
}



Measured memory_bytes: 3080
#include<iostream>
#include<string.h>
using namespace std;

int main()
{
  string str;
  cin>>str;
  if(str=="SSS")
  	cout<<"0\n";
  else if(str=="SSR"||str=="RSS"||str=="SRS"||str=="RSR")
  	cout<<"1\n";
  else if(str=="RRS"||str=="SRR")
  	cout<<"2\n";
  else if(str=="RRR")
    cout<<"3\n";
return 0;
}

Measured memory_bytes: 3620
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)*}
    };
    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $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")
    };
}
use std::collections::HashMap;
use std::cmp::{max,min};
fn main(){
    input!{
        n:usize,
        mut an:[usize;n],
    }
    let mut flag = true;
    let mut ans = 0;
    while flag {
        flag = false;
        for j in (1..n).rev() {
            if an[j] < an[j-1] {
                an.swap(j-1,j);
                flag = true;
                ans += 1;
            }
        }
    }
    for j in 0..n-1{
        print!("{} ",an[j]);
    }
    println!("{}",an[n-1]);
    println!("{}",ans);
}


fn is_prime(x:i64) -> bool {
    if x == 2 {return true;}
    if x < 2 || x % 2 == 0 {return false;}
    let mut j = 3;
    while j <= (x as f64).sqrt() as i64 {
        if x % j == 0 {
            return false;
        }
        j += 2;
    }
    true
}



Measured memory_bytes: 5036
import numpy as np
import scipy.sparse as sps
import scipy.misc as spm
import collections as col
import functools as func
import itertools as ite
import fractions as frac
import math as ma
from math import cos,sin,tan
import cmath as cma
import copy as cp
import sys
def sinput(): return sys.stdin.readline().strip()
def iinput(): return int(sinput())
def imap(): return map(int, sinput().split())
def fmap(): return map(float, sinput().split())
def iarr(n=0):
    if n: return [0 for _ in range(n)]
    else: return list(imap())
def farr(): return list(fmap())
def sarr(n=0):
    if n: return ["" for _ in range(n)]
    else: return sinput().split()
def barr(n): return [False for _ in range(n)]
sys.setrecursionlimit(10**7)
MOD = 10**9 + 7; EPS = sys.float_info.epsilon
PI = np.pi; EXP = np.e; INF = np.inf

s = sinput()[::-1]

a = "dream"[::-1]
b = "dreamer"[::-1]
c = "erase"[::-1]
d = "eraser"[::-1]

s = "".join(s.split(d))
s = "".join(s.split(c))
s = "".join(s.split(b))
s = "".join(s.split(a))

ans = "YES" if s=="" else "NO"
print(ans)


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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

int main()
{
    ll N;
    cin >> N;
    vec L(N);
    REP(i,0,N) cin >> L[i];

    ASC(L);
    ll cnt = 0;
    REP(i,0,N-2) {
        REP(j,i+1,N-1) {
            cnt += lower_bound(ALL(L), L[i]+L[j]) - L.begin() - j - 1;
        }
    }
    PR(cnt);

    return 0;
}

/*

1 2 3 4

*/ 

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

MOD= 10**9+7

f = [1]*(n+1)
inv = [1]*(n+1)

for i in range(1, n+1):
  f[i] = f[i-1]*i%MOD
  
inv[n] = pow(f[n], MOD-2, MOD)
for i in range(n-1, 0, -1):
  inv[i] = inv[i+1]*(i+1)%MOD

def nCr(n, r):
  return f[n]*inv[n-r]%MOD*inv[r]%MOD
    
ans = 0
for i in range(n):
  if i+1<k:
    continue
  cnt = nCr(i, k-1)
  ans += cnt*A[i]%MOD
  ans %= MOD
  
for i in range(n-1, -1, -1):
  if n-i<k:
    continue
  cnt = nCr(n-i-1, k-1)
  ans -= cnt*A[i]%MOD
  ans %= MOD
  
print(ans)

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

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>
bool chmin(T &a, const T &b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

template <typename T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 X;
    cin >> X;

    if(X==3 or X==5 or X==7) cout << "YES" << endl;
    else cout << "NO" << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	solve(os.Stdin, os.Stdout)
}

func solve(in io.Reader, out io.Writer) {
	bs := NewBufScanner(in)
	bw := NewBufWriter(out)
	defer bw.w.Flush()

	left := bs.IntScan() + bs.IntScan()
	right := bs.IntScan() + bs.IntScan()
	if left == right {
		bw.Printf("Balanced")
	} else if left > right {
		bw.Printf("Left")
	} else {
		bw.Printf("Right")
	}
}

// BufScanner original scanner
type BufScanner struct {
	s *bufio.Scanner
}

// NewBufScanner constructer
func NewBufScanner(in io.Reader) *BufScanner {
	s := bufio.NewScanner(in)
	s.Buffer(make([]byte, 1024), 1e+9)
	s.Split(bufio.ScanWords)
	return &BufScanner{
		s: s,
	}
}

// Scan Scan Data
func (b *BufScanner) Scan() string {
	b.s.Scan()
	return b.s.Text()
}

// IntScan Scan Data
func (b *BufScanner) IntScan() int {
	v, err := strconv.Atoi(b.Scan())
	if err != nil {
		panic(err)
	}
	return v
}

// BufWriter original writer
type BufWriter struct {
	w *bufio.Writer
}

// NewBufWriter constructer
func NewBufWriter(out io.Writer) *BufWriter {
	w := bufio.NewWriter(out)
	return &BufWriter{
		w: w,
	}
}

// Printf Output file
func (b *BufWriter) Printf(format string, a ...interface{}) {
	fmt.Fprintf(b.w, format, a...)
}

Measured memory_bytes: 640
# include <bits/stdc++.h>
# define rep(i,a,b) for(int i=(a);i<=(b);++i)
typedef long long ll;
using namespace std;
const int maxn = 1e5+10;
int n;
int a[maxn];
int main(){
	scanf("%d",&n);ll sum=0;
	rep(i,1,n){ scanf("%d",a+i);sum+=a[i]; }
	if(sum % (1ll*n*(n+1)/2)!=0){puts("NO");return 0;}
	ll k=sum / (1ll*n*(n+1)/2);
	a[0]=a[n];
	ll ans = 0;
	rep(i,1,n){
		ll now=k-a[i]+a[i-1];
		if (now%n ||now<0){puts("NO");return 0;}
		ans+=now/n;
	}
	if (ans!=k) puts("NO"); else printf("YES\n");
	return 0;
}

Measured memory_bytes: 640
#include <iostream>

using namespace std;

int main()

{

  int a,b,c,d,e,f;

 cin >>a;

  cin >>b;

  cin >>c;

  cin >>d;

  e=(a+b);

  f=(c+d);

  

  if (e>f)

  {

    cout << "Left"<< endl;

  }

  if (f>e)

  {

    cout << "Right"<< endl;

  }

  if (e==f)

  {

    cout << "Balanced"<< endl;

  }

  return 0;

}

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

int main()
{
	int N;
	int A[200010] = {0};
	int M[200010] = {0};
	cin >> N;
	for(int i = 1; i <= N; i++) cin >> A[i];

	for(int i = N; i > 0 ; i--)
	{
		long long int sum = 0;
		for(int s = 2; i * s <= N; s++)
		{
			int k = i * s;
			sum += M[k];
		}
		
		int ans = sum % 2;
		if(ans != A[i]) M[i] = 1;
		//else M[i] = -1;
	}

	int cnt = 0;
	for(int i = 1; i <= N; i++)
	{
		if(M[i] == 1) cnt++;
	}
	cout << cnt << endl;
	for(int i = 1; i <= N; i++)
	{
		if(M[i] == 1) cout << i << " ";
	}
	cout << endl;

	return 0;
}


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

typedef long long ll;

// static const int MAX = 1e6;
// static const int NIL = -1;
// static const ll INF = 1<<21;
// static const ll MOD = 1e9 + 7;

bool compPair(const pair<int, int>& arg1, const pair<int, int>& arg2) {
    return arg1.first > arg2.first;
}

int main(void) {
    int n;
    cin >> n;

    int now;
    for(int i=0;i<n;i++) {
        cin >> now;
        if(now%2==1) {
            cout << "first" << endl;
            return 0;
        }
    }

    cout << "second" << endl;

    return 0;
}


Measured memory_bytes: 256
import javax.print.DocFlavor;
import java.awt.*;
import java.io.PrintWriter;
import java.lang.reflect.Array;
import java.math.BigInteger;
import java.util.*;
import java.util.List;

public class Main {

    static String br = System.getProperty("line.separator");
    static Scanner sc = new Scanner(System.in);
    static PrintWriter out = new PrintWriter(System.out);

    public static void main(String[] args) {
        int N = nextInt();
        String S = next();

        S = S.replace("ABC", "");
        println((N-S.length())/3);
    }

    static int nextInt() {
        return Integer.parseInt(next());
    }

    static Long nextLong() {
        return Long.parseLong(next());
    }

    static String next() {
        return sc.next();
    }

    static String nextLine(){
        return sc.nextLine();
    }

    static void println(Object o) {
        out.println(o);
        out.flush();
    }

    static void print(Object o) {
        PrintWriter out = new PrintWriter(System.out);
        out.print(o);
        out.flush();
    }
}


Measured memory_bytes: 21332
using System;

namespace AtCoder_Beginner_Contest_144_A_9_9
{
    class Program
    {
        static void Main(string[] args)
        {
            int A, B;
            var word =Console.ReadLine().Split(' ');
            A = int.Parse(word[0]);
            B = int.Parse(word[1]);
           
            if (A < 10 && A > 0 && B < 10 && B > 0)
            {
                Console.Write(A * B);
            }
            else
            { 
                Console.Write(-1);
            }
            Console.ReadKey();
        }
    }
}


Measured memory_bytes: 13140
#include <iostream>
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <string>
#include <tuple>
#include <utility>
#include <functional>
#include <sys/time.h>
#include <iomanip>

using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define REP(i, m, n) for(int i = (m); i < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(s) (s).begin(), (s).end()
#define pb push_back
#define fs first
#define sc second
template <typename T>
bool chmax(T &a, const T b){if(a < b){a = b; return true;} return false;}
template <typename T>
bool chmin(T &a, const T b){if(a > b){a = b; return true;} return false;}
template <typename T>
ll pow2(const T n){return (1LL << n);}
void setp(const int n){cout << fixed << setprecision(n);}
constexpr int INF = 1e9+1;
constexpr ll LINF = 1e18+1;
constexpr ll MOD = 1e9+7;
//constexpr ll MOD = 998244353;
constexpr ld EPS = 1e-11;
const ld PI = acos(-1);

constexpr int BEAM_SIZE = 100;
constexpr int SZ = 26;
constexpr int D = 365;
array<int, SZ> C;
array<array<int, SZ>, D> S;

struct State {
	array<int, SZ> last = {};
	array<int, D> ans;
	int score = 0;

	void update_score(int d, int t) {
		score += S[d][t];
		rep(i, SZ) score -= C[i] * (d + 1 - last[i]);
	}

	int eval() const {
		return score;
	}

	State place(int d, int t) {
		State res = *this;
		ans[d] = t;
		res.last[t] = d + 1;
		res.update_score(d, t);
		return res;
	}

	array<int, D> answer() {
		return ans;
	}
};

array<int, D> solve() {
	State initial_state;
	using f = function<bool(State&, State&)>;
	priority_queue<State, vector<State>, f> cur([](State& a, State& b){return a.eval() > b.eval();});
	cur.push(initial_state);
	priority_queue<State, vector<State>, f> nxt([](State& a, State& b){return a.eval() > b.eval();});
	rep(d, D){
		while(!nxt.empty()) nxt.pop();
		while(!cur.empty()){
			State now = cur.top(); cur.pop();
			rep(t, SZ){
				if(nxt.size() < BEAM_SIZE || now.place(d, t).eval() > nxt.top().eval()) nxt.push(now.place(d, t));
				if(nxt.size() > BEAM_SIZE) nxt.pop();
			}
		}
		swap(cur, nxt);
	}

	State res;
	while(!cur.empty()){
		if(cur.size() == 1) res = cur.top();
		cur.pop();
	}
	cerr << res.eval() << endl;
	return res.answer();
}

int main(void){
	int tmp;
	cin >> tmp;
	rep(i, SZ) cin >> C[i];
	rep(i, D) rep(j, SZ) cin >> S[i][j];

	auto ans = solve();
	for (int i : ans) cout << i + 1 << endl;

	return 0;
}


Measured memory_bytes: 3800
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define reps(i,n) for(int i = 1; i <= n; i++)
#define rrep(i,n) for(int i = n-1; i >= 0; i--)
#define rreps(i,n) for(int i = n; i >= 1; i--)
#define mrep(i,from,n) for(int i = from; i < n; i++)
#define mreps(i,from,n) for(int i = from; i <= n; i++)
#define all(x) (x).begin(),(x).end()
#define sz(x) ((int)(x).size())
#define ERASE(x,val) x.erase(remove(ALL(x), val), x.end())
typedef long long ll;
typedef pair<int, int> P;
template<class T>inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; }return false; }
template<class T>inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; }return false; }
ll MOD = 1000000007;
int INF = 1001001001;

void solve()
{
	int n, x, y; cin >> n >> x >> y;
	x--;y--;
	vector<vector<int>> dist(n, vector<int>(n, INF));
	rep(i, n)mrep(j,i,n)
	{
		if(i==j)dist[i][j] = 0;
		else dist[i][j] = min(j-i,abs(x-i)+abs(y-j)+1);	
	}
	vector<int> ans(n, 0);
	rep(i, n)mrep(j,i,n)ans[dist[i][j]]++;
	reps(i,n-1)cout << ans[i] << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	solve();
	return 0;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i,n) for(int i=n; i>-1; --i)
#define ALL(a) (a).begin(),(a).end()
#define FILL(a,n,x); REP(i,(n)){ (a)[i]=(x); }
#define CINA(a,n); REP(i,(n)){ cin >> (a)[i]; }
#define FILL2(a,n,m,x); REP(i,(n)){ REP(j,(m)){(a)[i][j]=(x);} }
#define CINA2(a,n,m); REP(i,(n)){ REP(j,(m)){cin >> (a)[i][j];} }
#define Liny "Yes\n"
#define Linn "No\n"
#define LINY "YES\n"
#define LINN "NO\n"

//cout << setfill('0') << right << setw(4) << 12; // "0012"
int keta(ll x){ if(x<10){return 1;} else{return keta(x/10) + 1;}}
int keta_wa(ll x){ if(x<10){return x;} else{return keta_wa(x/10) + x%10;} }
int ctoi(char c){ return ( (c>='0' && c<='9')? c - '0': 0 );}
int __stoi(string s){ return atoi(s.c_str()); }
ll sum(ll a[],ll N){ return accumulate(a,a+N,0LL);}
ll gcd(ll a,ll b){if(a<b)swap(a,b); return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){if(a<b){swap(a,b);} return a/gcd(a,b)*b;}
template<class T> void chmax(T& a, T b){ if(a<b){a=b;} }
template<class T> void chmin(T& a, T b){ if(a>b){a=b;} }
template<class T> bool isIn(T a,vector<T> v){ for(T x:v){ if(a==x){return true;}} return false;}
string strReplace(string s,string target, string replacement){
    if (!target.empty()) {
      std::string::size_type pos = 0;
      while ((pos = s.find(target, pos)) != std::string::npos) {
        s.replace(pos, target.length(), replacement);
        pos += replacement.length();
      }
    }
    return s;
}
const ll MOD = 1e9+7;
#define pii pair<int,int>
#define pll pair<ll,ll>
#define MP make_pair

int main(){
    ll N; cin>>N;
    map<ll,ll> mp;
    ll ans = 0;
    REP(count,N){
        ll a; cin>>a;
        ans += a;
        ++mp[a];
    }
    
    
    ll Q; cin>>Q;
    REP(count,Q){
        ll b,c; cin>>b>>c;
        ans += (c-b)*mp[b];
        mp[c] += mp[b];
        mp[b] = 0;
        cout << ans << "\n";
    }
    
}

Measured memory_bytes: 9360
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;
const int N = 1001;

int num, res;

struct Node
{
	int x, y, flag;
	Node(int a = -1, int b = -1, int f = 0)
	{
		x = a;
		y = b;
		flag = f;
	}
};

bool cmp(Node a, Node b)
{
	return a.x < b.x;
}

vector<Node> vn;

void work()
{
	multiset<int> ms;
	for (int i = 0; i < vn.size(); i++)
	{
		if (!vn[i].flag)
			ms.insert(vn[i].y);
		else
		{
			int k = -1;
			for (int j = vn[i].y - 1; j >= 0; j--)
			{
				if (ms.count(j))
				{
					k = j;
					break;
				}
			}
			if (k >= 0)
			{
				ms.erase(k);
				res++;
			}
		}
	}
}


int main()
{


	scanf("%d", &num);
	for(int i = 0;i < 2 * num;i++)
	{
		int a, b, flag = 0;
		scanf("%d%d", &a, &b);

		if (i >= num)
			flag = 1;
		vn.push_back(Node(a, b, flag));
	}
	sort(vn.begin(), vn.end(), cmp);
	work();

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

Measured memory_bytes: 256
import sys
sys.setrecursionlimit(10**6)
def main():
    N = int(input())
    bl = []
    d = {i:0 for i in range(1,N+1)}
    d1 = {i:[] for i in range(1,N+1)}
    d2 = {}
    d3 = [0] * (N-1)
    for i in range(N-1):
        a, b = map(int, input().split())
        d2[tuple(sorted([a,b]))] = i
        d[a] += 1
        d[b] += 1
        d1[a].append(b)
        d1[b].append(a)
    m = 0
    for i in d:
        m = max(m, d[i])
    dfs(1, d1, d2, d3, 0)
    print(m)
    for i in d3:
        print(i)

def dfs(n, d1, d2, d3, c):
    count = 1
    for i in d1[n]:
        if d3[d2[tuple(sorted([n,i]))]] > 0:
            continue
        if count == c:
            count += 1
        d3[d2[tuple(sorted([n,i]))]] = count
        dfs(i, d1, d2, d3, count)
        count += 1
main() 


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

//定数
const long long MOD1=1000000007;
const long long MOD2=998244353;
const long double PI=3.1415926535897932;
const long long MAXLL=9223372036854775807;
const long long INF=2305843009213693951;
const long long dx[]={0,1,0,-1,1,-1,1,-1};
const long long dy[]={1,0,-1,0,1,1,-1,-1};

//型名省略
#define ll long long
#define ull unsigned long long
#define ld long double
#define uld unsigned long double
#define pll pair<long long,long long>
#define tll(n) array<long long,(int)(n)>
#define pcc pair<char,char>
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define vc vector<char>
#define vvc vector<vector<char>>
#define vb vector<bool>
#define vvb vector<vector<bool>>
#define vp vector<pair<long long,long long>>
#define vt(n) vector<array<long long,(int)(n)>>
#define umap unordered_map
#define uset unordered_set
#define Lqueue priority_queue<long long>
#define Squeue priority_queue<long long,vector<long long>,greater<long long>>
#define Fi first
#define Se second
#define mp make_pair
#define eb emplace_back

//マクロ
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rbf(a,x) for(auto& a:x)
#define rep(i,n) for(long long i=0;i<(long long)(n);i++)
#define rep2(i,s,n) for(long long i=(s);i<(long long)(n);i++)
#define Maxe(x) *max_element((x).begin(),(x).end())
#define Mine(x) *min_element((x).begin(),(x).end())
#define Size(x) ((long long)(x).size())
#define lin(s) getline(cin,(s))

//MAX,MIN
template<class T,class U> auto max(T a,U b){return a>b?a:b;}
template<class T,class U> auto min(T a,U b){return a<b?a:b;}

//最大公約数,最小公倍数
long long gcd(long long a,long long b){return b?gcd(b,a%b):a;}
long long lcm(long long a,long long b){return a/gcd(a,b)*b;}

//累乗
template<typename t>
constexpr t mypow(t a,long long b){
    if(b==0)return 1;
    if(a==0)return 0;
    t x=1;
    while(b>0){
        if(b&1LL)x*=a;
        a*=a;
        b>>=1LL;
        }
    return x;
}
#define pow mypow

//chmin,chmax
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;}

//組み合わせ O(r)
template<typename t>
constexpr t nCr(t n,long long r){
    if(r==0)return 1;
    if(n==0)return 0;
    if(n<r)return 0;
    t x=1;
    for(long long i=1;i<=r;i++){
        x*=n-i+1;
        x/=i;
    }
    return x;
}

//main関数
signed main(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n,x;
    cin>>n>>x;
    vl L(n);
    rep(i,n)cin>>L[i];
    ll res=1;
    ll now=0;
    rep(i,n){
        now+=L[i];
        if(now<=x)res++;
    }
    cout<<res<<endl;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
#define int long long
#define uint unsigned int
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define FORR(i, a, b) for (int i = (a); i >= (b); --i)
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define SZ(a) ((int)(a).size())
#define PB(a) push_back(a)
#define EB(...) emplace_back(__VA_ARGS__)
#define MP(a, b) make_pair(a, b)
#define MT(...) make_tuple(__VA_ARGS__)
using namespace std;
using pii = pair<int, int>;
template <class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template <class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
const int MOD = 1000000007;
const int INF = 1LL << 30;
const double EPS = 1e-10;

int N;
int a[21][21];
int used[21][1LL<<21];
int memo[21][1LL<<21];

int dfs(int v, int ms) {
  if (v == N) return 1;
  if (used[v][ms]) return memo[v][ms];
  used[v][ms] = 1;
  int res = 0;
  REP(i, N) if (a[v][i] && (ms & (1LL << i))) {
    (res += dfs(v+1, ms - (1LL << i))) %= MOD;
  }
  return memo[v][ms] = res;
}

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  REP(i, N) REP(j, N) cin >> a[i][j];
  cout << dfs(0, (1LL<<N)-1) << endl;

  return 0;
}

Measured memory_bytes: 614656
#include <bits/stdc++.h>
using namespace std;
int n,m,S,T,cnt,inf=1e9,sx,sy,tx,ty,hed[1005],d[1005],nex[50005],to[50005],val[50005],ans;queue<int>q;char ch;
void add(int x,int y,int z)
{
	to[cnt]=y;val[cnt]=z;nex[cnt]=hed[x];hed[x]=cnt++;
	to[cnt]=x;val[cnt]=0;nex[cnt]=hed[y];hed[y]=cnt++;
}
bool bfs()
{
	while(!q.empty()) q.pop();memset(d,0,sizeof(d));d[S]=1;q.push(S);
	while(!q.empty())
	{
		int x=q.front();q.pop();
		for(int i=hed[x];i!=-1;i=nex[i]) if(!d[to[i]]&&val[i]){d[to[i]]=d[x]+1;if(to[i]==T) return 1;q.push(to[i]);}
	}
	return 0;
}
int dfs(int x,int mf)
{
	if(x==T) return mf;int tmp=mf;
	for(int i=hed[x];i!=-1;i=nex[i]) if(d[to[i]]==d[x]+1&&val[i])
	{
		int k=dfs(to[i],min(val[i],tmp));
		if(!k) d[to[i]]=0;
		tmp-=k;val[i]-=k;val[i^1]+=k;
		if(!tmp) break;
	}
	return mf-tmp;
}
int main()
{
	scanf("%d%d",&n,&m);T=n+m+1;memset(hed,-1,sizeof(hed));
	for(int i=1;i<=n;i++) for(int j=1;j<=m;j++)
	{
		cin>>ch;
		if(ch=='S') add(S,i,inf),add(S,j+n,inf),sx=i,sy=j;
		if(ch=='T') add(i,T,inf),add(j+n,T,inf),tx=i,ty=j;
		if(ch=='o') add(i,j+n,1),add(j+n,i,1);
	}
	if(sx==tx||sy==ty) return puts("-1"),0;
	while(bfs()) ans+=dfs(0,inf*2);
	printf("%d\n",ans);
}

Measured memory_bytes: 768
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <numeric>
#include <utility>
#include <tuple>

#define REP(i, a, b) for (int i = int(a); i < int(b); i++)
using namespace std;
using ll = long long int;
using P = pair<int, int>;

// clang-format off
#ifdef _DEBUG_
#define dump(...) do{ cerr << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; PPPPP(__VA_ARGS__); cerr << endl; } while(false)
template<typename T> void PPPPP(T t) { cerr << t; }
template<typename T, typename... S> void PPPPP(T t, S... s) { cerr << t << ", "; PPPPP(s...); }
#else
#define dump(...) do{ } while(false)
#endif
template<typename T> vector<T> make_v(size_t a, T b) { return vector<T>(a, b); }
template<typename... Ts> auto make_v(size_t a, Ts... ts) { return vector<decltype(make_v(ts...))>(a, make_v(ts...)); }
template<typename T> bool chmin(T &a, T b) { if (a > b) {a = b; return true; } return false; }
template<typename T> bool chmax(T &a, T b) { if (a < b) {a = b; return true; } return false; }
template<typename T> void print(T a) { cout << a << endl; }
template<typename T, typename... Ts> void print(T a, Ts... ts) { cout << a << ' '; print(ts...); }
template<typename T> istream &operator,(istream &in, T &t) { return in >> t; }
// clang-format on

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int n;
    cin, n;
    vector<int> cnt(n, 0);
    REP(i, 0, n - 1) {
        int a;
        cin, a;
        a--;
        cnt[a]++;
    }
    REP(i, 0, n) {
        cout << cnt[i] << endl;
    }
    return 0;
}


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

int main(){
    int N;
    string S;
    cin>>N;
    cin>>S;
    int l[N],m[N];
    fill(m,m+N,0);
    for(int i=0;i<N;i++){
        if(S[i]=='W'){l[i]=-1;}
        else{l[i]=1;}
        if(!i){m[i]=l[i];}
        else{m[i]=m[i-1]+l[i];}
    }
    auto itr=max_element(m,m+N);
    size_t max_idx=distance(m,itr);
    int cnt=0;
    for(int i=0;i<N;i++){
        if(i<max_idx){
            if(l[i]!=l[max_idx]){cnt++;}
        }
        else if(i>max_idx){
            if(l[i]==1 && l[max_idx]==1){cnt++;}
            else if(l[i]==1 && l[max_idx]==-1){cnt++;}
        }
    }
    auto it=min_element(m,m+N);
    size_t min_idx=distance(m,it);
    int c=0;
    for(int i=0;i<N;i++){
        if(i<min_idx){
            if(l[i]!=l[min_idx]){c++;}
        }
        else if(i>min_idx){
            if(l[i]==1 && l[min_idx]==1){c++;}
            else if(l[i]==1 && l[min_idx]==-1){c++;}
        }
    }
    cout<<min(cnt,c)<<endl; 
    return 0;
}


Measured memory_bytes: 2948
import numpy as np

n, l = map(int, input().split())
knot = list(map(int, input().split()))

flg = 0
li = []
for i in range(0, int(n) - 1):
    if(knot[i] + knot[i + 1] >= l):
        flg = 1
        print("Possible")
        li.append(i + 1)

        for j in range(i + 2, n):
            li.append(j)
        for j in reversed(range(1, i + 1)):
            li.append(j)
        break

if flg == 0:
    print("Impossible")

for i in reversed(li):
    print(i)


Measured memory_bytes: 24312
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>
#include <chrono>
#include <random>
#include <functional>

using namespace std;


typedef long long ll;

#define int ll

const int INF = 1e12 + 239;

int n;
vector<int> a;
vector<ll> ps;
vector<ll> s;

ll get_sum(int l, int r) {
	r++;
	return ps[r] - ps[l];
}

ll solve(int x1) {
	// if (abs(x1 - a[n - 2]) > abs(x1 - a[n - 1])) {
	// 	return s[n - 1];
	// } else {
		int l = -1;
		int r = INF;
		while (r - l > 1) {
			int m = (r + l) >> 1;
			int tl = lower_bound(a.begin(), a.end(), x1 - m) - a.begin();
			int tr = prev(upper_bound(a.begin(), a.end(), x1 + m)) - a.begin();
			if (tr - tl + 1 >= n - 1 - tr) {
				r = m;
			} else {
				l = m;
			}
		}
		{
			int m = r;
			int tl = lower_bound(a.begin(), a.end(), x1 - m) - a.begin();
			int tr = prev(upper_bound(a.begin(), a.end(), x1 + m)) - a.begin();
			if (tr - tl + 1 == n - 1 - tr) {
				//
			} else {
			 	tr--;
			}
			int l1, l2, r1, r2;
			l1 = tl;
			r1 = tr;
			l2 = tr + 1;
			r2 = n - 1;
			int len = (n - l1);
			ll ans = get_sum(l2, r2);
			if (len % 2 == 0 && l1 > 0) {
				ans += s[l1 - 1];
			} else if (len % 2 == 1 && l1 > 1) {
				ans += s[l1 - 2];
			}
			return ans;
		}
	// }
}

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

	int q;
	cin >> n >> q;
	a.resize(n);
	for (auto &t : a) {
		cin >> t;
	} 
	s.resize(n);
	for (int i = 0; i < n; i++) {
		if (i > 1) {
			s[i] = s[i - 2];
		}
		s[i] += a[i];
	}
	ps.resize(n + 1);
	for (int i = 0; i < n; i++) {
		ps[i + 1] = ps[i] + a[i];
	}
	while (q--) {
		int x;
		cin >> x;
		cout << solve(x) << '\n';
	}
}


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

using namespace std;

#define inf 1<<30
#define pqueue priority_queue
#define mp make_pair
#define pb push_back
#define fn fill_n
typedef long long llong;
typedef unsigned long long ullong;
typedef pair<int, int> P;

llong gcd(llong a, llong b){
	while(a<b?swap(a,b):swap(a,a), b){
		a %= b;
	}
	return a;
}

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

int main(){
	int N;
	llong T[100], ans;
	cin >> N;
	for(int i = 0; i < N; i++)
		cin >> T[i];
	for(int i = 1; i < N; i++)
		T[i] = lcm(T[i-1], T[i]);

	cout << T[N-1] << endl;

	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++)

int main()
{
  int N, cnt=0, cnt2=0;
  cin >> N;
  for(int i=1; i<=N; i++){
    if(i%2==0) continue;
    for(int j=1; j<=i; j++){
      if(i%j==0)cnt++;
    }
    if(cnt==8) cnt2++;
    cnt=0;
  }
  cout << cnt2 << endl;
}

Measured memory_bytes: 256
#ifdef DEBUG

#else

#    pragma GCC optimize("O3,no-stack-protector")
#    pragma GCC optimize("unroll-loops")

#    if __cplusplus >= 201703L
#        pragma GCC target("avx2")
#    else
#        pragma GCC target("avx")
#    endif

#endif
// 実数の場合
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")

#define _USE_MATH_DEFINES
#include <bits/stdc++.h>
#define dump(x) cout << x << endl
typedef int64_t Int;

using namespace std;
using Graph = vector<vector<Int>>;

const double pi = M_PI;
const Int MOD = 1000000007;

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

    string a, b, c;
    cin >> a >> b;

    c = a + b;
    Int x = stoll(c);
    bool ans = false;
    for (Int i = 0; i < 317 + 1; i++) {
        if (i * i == x) {
            ans = true;
            break;
        }
    }

    if (ans) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


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

int main(){
    long long h;
    cin>>h;
    long long ans;
    long long cnt=1;
    while(true){
        if(h==1)break;
        h/=2;
        cnt++;
    }
    ans=pow(2,cnt)-1;
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>
int main(){
	int n,x,i,sum =0,min =1000,y;
	scanf("%d %d",&n,&x);
	int m[n];
	for(i=0;i<n;i++){
		scanf("%d",&m[i]);
		sum = sum +m[i];
		if(min > m[i]) min = m[i];
	}
	y = floor((x-sum)/min) + n;
	printf("%d",y);

}

Measured memory_bytes: 128
#include<stdio.h>
int main()
{
  int n=0,i=0,cnt=0,x=0;
  int a[200]={};
  /*値の入力*/
  scanf("%d",&n);
  for(i=0;i<n;i++){
  	scanf("%d",&a[i]);
  }  
  while(1){
    for(i=0;i<n;i++){
      if(a[i]%2==0){
      	cnt++;
      }  	
  	}
    if(n==cnt){
      for(i=0;i<n;i++){
        a[i]=a[i]/2;        
      }
      x++;
      cnt=0;
    }
    else
    {
      break;
    }
  }
  printf("%d",x);
  
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) rep2(i,0,n)
#define rep2(i,m,n) for(int i=m;i<(n);i++)
#define all(a) (a).begin(), (a).end()
typedef long long ll;
#define INF 1e9
typedef pair<int, int> P;

/* 　"assert"    assert(A：条件式)で　Aが真なら処理は続行、偽ならプログラムを終了する　*/

/*　　ラムダ式　　 auto a = [キャプチャ](パラメータ){ 処理 }  */

/* string型　メンバ関数　substr()    replace()  */

int main(){
    int n; cin >> n;
    int k; cin >> k;
    vector<ll> h(n);
    rep(i,n) cin >> h[i];
    sort(h.begin(), h.end());
    ll cnt = 0;
    ll sum = 0;
    for(int i=n-1; i>=0; i--){
        if(cnt >= k){
            sum += h[i];
        }
        
        cnt++;
    }
    cout << sum << endl;
}







Measured memory_bytes: 1792
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()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let r = read_as_vec::<f64>()[0];

    println!("{}", 2.0*r*std::f64::consts::PI);
}


Measured memory_bytes: 2192
# -*- coding: utf-8 -*-
H, N = map(int, input().split(' '))
nums = [float('inf') for _ in range(H+1)]
nums[0] = 0

for _ in range(N):
    a, b = map(int, input().split(' '))
    for i in range(H + 1):
        j = min(H, i+a)
        nums[j] = min(nums[j], nums[i] + b)

print(nums[H])

Measured memory_bytes: 74692
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod =  998244353

lim = 2*10**5
fact = [1]*(lim+1)
for n in range(1, lim+1):
	fact[n] = n*fact[n-1]%mod

fact_inv = [1]*(lim+1)
fact_inv[lim] = pow(fact[lim], mod-2, mod)
for n in range(lim, 0, -1):
	fact_inv[n-1] = n*fact_inv[n]%mod

def C(n, r):
	return (((fact[n]*fact_inv[r])%mod)*fact_inv[n-r])%mod


N, M, K = MAP()

ans = 0
for i in range(K+1):
	ans += M*pow(M-1, N-1-i, mod)%mod*C(N-1, i)
	ans %= mod 

print(ans)


Measured memory_bytes: 25436