akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#define ll long long
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define vi vector<int>
using namespace std;
int mod = 1'000'000'000 + 7;
namespace uf {
    vector<int> par, rank;

    void init(int n) {
        par.resize(n);
        rank.resize(n);
        for (int i = 0; i < n; i++) {
            par[i] = i;
            rank[i] = 0;
        }
    }

    int root(int x) {
        if (par[x] == x) {
            return x;
        } else {
            return par[x] = root(par[x]);
        }
    }

    bool same(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x);
        y = root(y);
        if (x == y)return;
        if (rank[x] < rank[y]) {
            par[x] = y;
        } else {
            par[y] = x;
            if (rank[x] == rank[y])rank[x]++;
        }
    }
}

ll pow_mod(ll n, ll k, ll m) {
    ll r = 1;
    for (; k > 0; k >>= 1) {
        if (k & 1) r = (r * n) % m;
        n = (n * n) % m;
    }
    return r;
}

ll gcd(ll a, ll b) {
    if (b == 0)return a;
    return gcd(b, a % b);
} // C++17


void COME_LET_THE_GAMES_BEGIN() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << setprecision(20);
}

int N, M;
int a[50], b[50], c[50], d[50];
int ans[50], m[50];

int main() {
    COME_LET_THE_GAMES_BEGIN();
    cin >> N >> M;
    for (int i = 0; i < 50; i++) {
        m[i] = mod;
    }
    rep(i, N) {
        cin >> a[i] >> b[i];
    }
    rep(i, M) {
        cin >> c[i] >> d[i];
        rep(j, N) {
            int k = abs(c[i] - a[j]) + abs(d[i] - b[j]);
            if (k < m[j]) {
                ans[j] = i + 1;
                m[j] = k;
            }
        }
    }
    rep(i, N) {
        cout << ans[i] << endl;
    }
}

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

#ifndef M_PI
#define M_PI 3.14159265358979
#endif
#define deg_to_rad(deg) (((deg) / 360) * 2 * M_PI)
#define rad_to_deg(rad) (((rad) / 2 / M_PI) * 360)

using namespace std;

typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;
typedef long double ld;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
    ll i, j, k;
    ll N;
    cin >> N;
    vll A(N, 0);
    for(i = 1; i < 101; i++) {
        for(j = 1; j < 101; j++) {
            for(k = 1; k < 101; k++) {
                ll n = i * i + j * j + k * k + i * j + j * k + k * i;
                if(n <= N) {
                    A[n - 1]++;
                }
            }
        }
    }
    for(i = 0; i < N; i++) {
        cout << A[i] << endl;
    }

    return 0;
}


Measured memory_bytes: 3624
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>
#include <queue>
#include <set>
#include <stdio.h>
#include <string>
using namespace std;
#define ll long long

int n;
ll ans = 0;
string s[100010];

int binary_search(int i) {
	int left = i + 1, right = n - 1;
	while (right >= left) {
		int mid = left + (right - left) / 2;
		if ((mid == n - 1 && s[i] == s[mid]) || (s[i] == s[mid] && s[i] != s[mid + 1]))return mid;
		else if (s[i] != s[mid] && mid == i + 1)return -100;
		else if (s[i] == s[mid])left = mid + 1;
		else if (s[i] != s[mid])right = mid - 1;
	}
	return -100;
}


int main() {
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> s[i];
		sort(s[i].begin(), s[i].end());
	}
	sort(s, s + n);
	for (int i = 0; i < n; i++) {
		int hoge = binary_search(i);
		if (hoge > 0) {
			ans += hoge - i;
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
 while(1){
	string stra,strb;
	cin>>stra>>strb;
	int h=0,b=0;

	if((stra=="0")&&(strb=="0")){
	 break;}

	for(int i=0;i<4;i++){
	 if(stra[i]==strb[i]){
		h++;
	 }
	 for(int j=0;j<4;j++){
		if(stra[i]==strb[j]){
			b++;
		}
	 }
	}

  b=b-h;
  cout<<h<<' '<<b<<'\n';
 }
return 0;
}

Measured memory_bytes: 1184
#include <bits/stdc++.h>
using std::cout;
using std::endl;
using std::cin;

int main(){
	int n; cin >> n; std::vector<int> a(n);
	for(int i = 0; i < n; i++) cin >> a[i];
	
	int m; cin >> m;
	for(int i = 0; i < m; i++){
		int A, b; cin >> A >> b;
		
		long ans = 0;
		for(int i = 0; i < n; i++){
			if(i == A - 1) ans += b;
			else ans += a[i];
		}
		
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports, unused_macros, dead_code)]

macro_rules! min {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| min!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = min!($($ys),*);
        if $x < t { $x } else { t }
    }}
}
macro_rules! max {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        it.next().map(|z| it.fold(z, |x, y| max!(x, y)))
    }};
    ($x:expr) => ($x);
    ($x:expr, $($ys:expr),*) => {{
        let t = max!($($ys),*);
        if $x > t { $x } else { t }
    }}
}
macro_rules! ewriteln {
    ($($args:expr),*) => { let _ = writeln!(&mut std::io::stderr(), $($args),*); };
}
macro_rules! trace {
    ($x:expr) => { ewriteln!(">>> {} = {:?}", stringify!($x), $x) };
    ($($xs:expr),*) => { trace!(($($xs),*)) }
}
macro_rules! put {
    (.. $x:expr) => {{
        let mut it = $x.iter();
        if let Some(x) = it.next() { print!("{}", x); }
        for x in it { print!(" {}", x); }
        println!("");
    }};
    ($x:expr) => { println!("{}", $x) };
    ($x:expr, $($xs:expr),*) => { print!("{} ", $x); put!($($xs),*) }
}

const M: i64 = 1_000_000_007;

fn main() {
    let mut sc = Scanner::new();
    let a: usize = sc.cin();
    let b: usize = sc.cin();
    let c: usize = sc.cin();
    put!(min!(
        if a % 2 == 0 { 0 } else { b * c },
        if b % 2 == 0 { 0 } else { c * a },
        if c % 2 == 0 { 0 } else { a * b }
    ));
}

use std::io::{self, Write};
use std::str::FromStr;
use std::collections::VecDeque;

struct Scanner { stdin: io::Stdin, buffer: VecDeque<String>, }
impl Scanner {
    fn new() -> Self { Scanner { stdin: io::stdin(), buffer: VecDeque::new() } }
    fn cin<T: FromStr>(&mut self) -> T {
        while self.buffer.len() == 0 {
            let mut line = String::new();
            let _ = self.stdin.read_line(&mut line);
            for w in line.split_whitespace() {
                self.buffer.push_back(String::from(w));
            }
        }
        self.buffer.pop_front().unwrap().parse::<T>().ok().unwrap()
    }
    fn chars(&mut self) -> Vec<char> { self.cin::<String>().chars().collect() }
    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T> { (0..n).map(|_| self.cin()).collect() }
}


Measured memory_bytes: 4352
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	string a, s;
	cin >> a >> s >> a;
	cout << "A" << s[0] << "C" << endl;
	return 0;
}

Measured memory_bytes: 256
/*
 * wafuIroha.cpp
 *
 *  Created on: 2020/02/23
 *      Author: black
 */
#include <iostream>
#include <algorithm>
#include <utility>
using namespace std;

int main(){
	int n;
	string s;
	cin >> n;
	cin >> s;

	int x = 0;
	int max = 0;


	for (int i = 0; i<n; ++i){
		if (s[i] == 'I'){
			x++;
		}
		else{
			x--;
		}

		if (x > max){
			max = x;
		}
	}

	cout << max << endl;



	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>

using namespace std;

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

    int d = S % 10;
    S /= 10;
    int c = S % 10;
    S /= 10;
    int b = S % 10;
    int a = S / 10;

    int ans;
    for (int i = 0; i < 8; i++){
        int A = a, B = b, C = c, D = d;
        int count = i;
        if (count >= 4){
            B *= -1;
            count -= 4;
        }
        if (count >= 2){
            C *= -1;
            count -= 2;
        }
        if (count >= 1){
            D *= -1;
            count -= 1;
        }
        if(A + B + C + D == 7){
            ans = i;
            break;
        }
    }

    char op1 = '+', op2 = '+', op3 = '+';
    if (ans >= 4){
        op1 = '-';
        ans -= 4;
    }
    if (ans >= 2){
        op2 = '-';
        ans -= 2;
    }
    if (ans >= 1){
        op3 = '-';
        ans -= 1;
    }
    
    cout << a << op1 << b << op2 << c << op3 << d << "=7" << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
using namespace std;
typedef long long ll;

#define rep(i, n) for(ll i = 0; i < n; i++)
#define REP(i, n) for(ll i = 1; i < n + 1; i++)
#define PI 3.14159265359
#define EPS 0.0000000001
#define MOD 1000000007
//cout << std::fixed << std::setprecision(15) << y << endl;


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

    ll sumL = 0;
    ll Lmax = 0;
    ll L[N];
    rep(i, N){
        cin >> L[i];
        Lmax = max(Lmax, L[i]);
        sumL += L[i];
    }

    if(sumL - Lmax > Lmax){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 3600
#include <iostream>
#include <limits>

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n, a;
	long long int mina, maxa, suma;
	cin>>n>>a;
	mina=maxa=suma=a;
	for(int i=1; i<n; i++) {
		cin>>a;
		if(mina>a) mina=a;
		if(maxa<a) maxa=a;
		suma+=a;
	}
	cout<<mina<<' '<<maxa<<' '<<suma<<'\n';
	return 0;
}



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

using namespace std;

const int INF = 1e9 + 9;

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

    int n;
    cin >> n;

    vector<int> h(n);
    vector<int> dp(n, INT_MAX);

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

    dp[0] = 0;

    for (int i = 0; i < n; i++)
        for (int j : {i + 1, i + 2})
            if (j < n)
                dp[j] = min(dp[j], dp[i] + abs(h[j] - h[i]));

    cout << dp[n - 1] << endl;
    return 0;
}

Measured memory_bytes: 1024
import java.util.ArrayList;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int s = sc.nextInt();
		sc.close();

		ArrayList<Integer> list = new ArrayList<Integer>();
		int i=1;
		list.add(s);
		while(true) {
			i++;
			if(s%2==0) {
				s = s/2;
			}else {
				s = 3*s+1;
			}
			if(list.contains(s)) {
				System.out.println(i);
				return;
			}
			list.add(s);
		}
	}
}

Measured memory_bytes: 35676
#include <iostream>
#include <stdio.h>
#include <string>
#include <algorithm>
#include <vector>
#include <math.h>
#include <numeric>
#include <queue>
#include <numeric>
#include <iomanip>
#include <sstream>
#include <cmath>
#include <map>
#include <functional>
#include <limits>
#include <set>
#include <stack>
#include <cctype>
#define rep(i,a,b) for((i)=a;i<(int)(b);i++)

#define AAA (1000000007) 


using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pairII;


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

ll lcm(ll a, ll b) {
	return a / gcd(a, b) * b;
}
ll powD(ll a, ll b) {
	ll ans = 1;
	a %= AAA;
	for (int i = 0; i < b; i++)
	{
		ans *= a;
		ans %= AAA;
	}
	return ans;
}

int primeNumber(const int n) {
	//上から確認する
	for (int N = n; N >= 1; N--) {

		bool isPrime = true;
		//素数判定 i < sqrt(N)+1
		for (int i = 2; i * i <= N; i++) {
			if (N % i == 0) {
				isPrime = false;
				break;
			}
		}
		//もし素数なら
		if (isPrime) {
			return N;
		}
	}
}


int main() {
	int i, j, k;

	int N, M, K;

	map<string, int> Map;

	cin >> N;
	for (i = 0; i < N; i++) {
		string S;
		cin >> S;
		Map[S] += 1;
	}
	cout << "AC x "  << Map["AC"] << endl;
	cout << "WA x " <<Map["WA"] << endl;
	cout << "TLE x " <<Map["TLE"] << endl;
	cout << "RE x " <<Map["RE"] << endl;
	return 0;
}


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

int main() {
    string S;
    cin >> S;
    bool even = (S.size() % 2 == 0);
    bool same = (S[0] == S[S.size() - 1]);

    if(even ^ same == 0) cout << "First" << endl;
    else cout << "Second" << endl;
}

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

int N, M;
vector<vector<int>> A;

void dfs (vector<int> v, int dep, int pre) {
  if (dep == N) {
    A.push_back(v);
    return;
  }
  for (int i = pre; i <= M; i++) {
    vector<int> nv = v;
    nv.push_back(i);
    dfs(nv, dep + 1, i);
  }
}

int main() {
  cin >> N >> M;
  vector<int> start;
  dfs(start, 0, 1);

  int Q;
  cin >> Q;
  vector<int> a(Q), b(Q), c(Q), d(Q);
  for (int i = 0; i < Q; i++) cin >> a.at(i) >> b.at(i) >> c.at(i) >> d.at(i);

  int ans = 0;
  for (int i = 0; i < A.size(); i++) {
    int sum = 0;
    for (int j = 0; j < Q; j++) {
      if (A.at(i).at(b.at(j) - 1) - A.at(i).at(a.at(j) - 1) == c.at(j)) {
        sum += d.at(j);
      }
    } 
    ans = max(ans, sum);
  }
  cout << ans << "\n";
}

Measured memory_bytes: 9836
#include "bits/stdc++.h"
// Begin Header {{{
#define all(x) (x).begin(), (x).end()
#define rep(i, s, n) for (i64 i = (s), i##_limit = (n); i < i##_limit; ++i)
#define repr(i, s, t) for (i64 i = (s), i##_limit = (t); i >= i##_limit; --i)
#define var(type, ...) \
    type __VA_ARGS__;  \
    read(__VA_ARGS__);
#ifndef DBG
#define dump(...)
#endif
using namespace std;
using i64 = int_fast64_t;
using pii = pair<i64, i64>;
template <class T, class U>
inline bool chmax(T &a, const U &b) {
    return b > a && (a = b, true);
}
template <class T, class U>
inline bool chmin(T &a, const U &b) {
    return b < a && (a = b, true);
}
constexpr int INF = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;

template <class T>
inline vector<T> makeV(const T &initValue, size_t sz) {
    return vector<T>(sz, initValue);
}

template <class T, class... Args>
inline auto makeV(const T &initValue, size_t sz, Args... args) {
    return vector<decltype(makeV<T>(initValue, args...))>(
        sz, makeV<T>(initValue, args...));
}

template <class T>
inline istream &operator>>(istream &is, vector<T> &vec) {
    for (auto &e : vec) is >> e;
    return is;
}

inline void read() {}

template <class Head, class... Tail>
inline void read(Head &head, Tail &... tail) {
    cin >> head;
    read(tail...);
}

inline void print() { cout << "\n"; }

template <class Head, class... Tail>
inline void print(Head &&head, Tail &&... tail) {
    cout << head;
    if (sizeof...(tail)) cout << ' ';
    print(forward<Tail>(tail)...);
}

template <class T>
inline ostream &operator<<(ostream &os, const vector<T> &vec) {
    static constexpr const char *delim[] = {" ", ""};
    for (const auto &e : vec) os << e << delim[&e == &vec.back()];
    return os;
}

template <class Container>
struct Rev {
    Container &x_;
    inline Rev(Container &x) : x_(x) {}
    inline auto begin() { return rbegin(x_); }
    inline auto end() { return rend(x_); }
};
// }}} End Header

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

    var(int, N, M);
    vector<i64> a(N);
    read(a);
    const i64 sum = accumulate(all(a), 0LL);

    int cnt = 0;
    rep(i, 0, N) {
        if (a[i] * 4 * M >= sum) ++cnt;
    }

    print(cnt >= M ? "Yes" : "No");

    return 0;
}


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

int main()
{
  string N;
  cin >> N;
  if (N.at(2)==N.at(3) && N.at(4)==N.at(5)){
    cout << "Yes" << endl;
  }else {
    cout << "No" << endl;
  }
  
  return 0;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

signed main(){
    int N;
    cin>>N;
    vint L(N*2);
    rep(i,N*2)cin>>L[i];
    sort(all(L));
    int ans=0;
    rep(i,N)ans+=L[i*2];
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanLines)

	sc.Scan()
	str := sc.Text()
	r := []rune(str)

	sc.Scan()
	q, _ := strconv.Atoi(sc.Text())

	for i := 0; i < q; i++ {
		sc.Scan()
		s := sc.Text()
		instruction := strings.Split(s, " ")
		a, _ := strconv.Atoi(instruction[1])
		b, _ := strconv.Atoi(instruction[2])
		switch instruction[0] {
		case "print":
			fmt.Println(string(r[a : b+1]))
		case "reverse":
			s := make([]rune, len(r[a:b+1]))
			copy(s, r[a:b+1])
			for i := 0; i < b-a+1; i++ {
				r[a+i] = s[len(s)-1-i]
			}
		case "replace":
			s := []rune(instruction[3])
			for i := 0; i < b-a+1; i++ {
				r[a+i] = s[i]
			}
		}
	}
}



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

vector<ll> c(51),p(51);
ll ans=0;

void dfs(ll x,ll n){
    if(n==0) {ans++;return;}
    if(x==1) return;
    else if(x==c[n-1]+2) {ans += 1+p[n-1];return;}
    else if(x==c[n]) {ans+= p[n];return;}
    else if(x<c[n-1]+2) dfs(x-1,n-1);
    else {ans+=1+p[n-1];dfs(x-c[n-1]-2,n-1);}
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n,x;
    cin >> n >> x;
    c[0] = 1;p[0] = 1;
    for(int i = 1;i <= n;i ++){
        c[i] = 2*c[i-1]+3;
        p[i] = 2*p[i-1]+1;
    }
    dfs(x,n);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#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
#define mod 200003
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
//priority_queue<ll, vector<ll>, greater<ll>> q;
using pl = pair<ll,ll>;
using vvb=vector<vector<bool>>;
using vb= vector<bool>;
ll f(ll a,ll b,ll p){
	if(b==0) return 1;
	if(b%2==0){
		ll t=f(a,b/2,p);
		return t*t%p;
	}
	return a*(f(a,b-1,p))%p;
} 

//__builtin_popcount()
signed main(){
	ll n; cin>>n;
	ll x,y; cin>>x>>y;
	--x; --y;
	vl ans(n+10);
	vvl g(n,vl(0));
	rep(i,0,n-1){
		g[i].push_back(i+1);
		g[i+1].push_back(i);
	}
	g[x].push_back(y);
	g[y].push_back(x);
	rep(i,0,n){
		queue<pl> q;
		q.push(make_pair(i,0));
		vector<bool> seen(n);
		seen[i]=1;
		while(!q.empty()){
			pl p=q.front(); q.pop();
			ll a,b; tie(a,b)=p;
			for(auto c:g[a]){
				if(seen[c])continue;
				seen[c]=1;
				ans[b]++;
				q.push(make_pair(c,b+1));
			}
		}
	}
	rep(i,0,n-1)cout<<ans[i]/2<<endl;


	return 0;
}

Measured memory_bytes: 3756
//g++ -std=gnu++14 a.cpp

#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <random>
#include <math.h>
#include <stdio.h>

using namespace std;

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

ll MODP = 998244353;


int main(){
  int n;
  cin >> n;
  n %= 1000;
  if(n) cout << 1000 - n <<endl;
  else cout << n << endl;

  return 0;
}


Measured memory_bytes: 3576
import sys
sys.setrecursionlimit(10**7)

n, m = map(int, input().split())
ans = [0 for _ in range(n)]
trees = [[] for _ in range(n)]

for _ in range(m):
    a,b=map(int,input().split())
    trees[a-1].append(b-1)
    trees[b-1].append(a-1)

visited = [False]*n
def dfs(n):
    visited[n] = True
    global temp
    temp+=1
    for i in trees[n]:
        if visited[i]:
            continue
        dfs(i)

ans=0
for x in range(n):
    if visited[x]:
        continue
    temp=0
    dfs(x)
    ans=max(temp,ans)
print(ans)

Measured memory_bytes: 750880
N=int(input())
A=list(map(int,input().split()))
Q=int(input())
BC=[]
for i in range(Q):
    b,c=(map(int,input().split()))
    BC.append([b,c])

#最初に全探索で位置をインデックスに登録する
DP=[0]*(10**5+1)
for i in A:
    DP[i]+=1#
ans=sum(A)
for i in BC:
    target=i[0]
    nex=i[1]
    num=DP[target]
    DP[target]=0
    DP[nex]=DP[nex]+num
    ans=ans+num*nex-num*target
    print(ans)


Measured memory_bytes: 90248
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using vi = vector<int>;
using vll = vector<ll>;
using vii = vector<ii>;
const ll MOD = 1e9+7;
const int INF = 1e9+9;
const int MAXN = 200005;


int n, p[MAXN];
vi children[MAXN];
ll siz[MAXN], good[MAXN], bad[MAXN], sum[MAXN], prod[MAXN], in[MAXN], h[MAXN];

inline ll binPow(ll base, ll e) {
  ll r = 1;
  while (e>0) {
    if (e&1) {
      r=r*base%MOD;
    }
    base=base*base%MOD;
    e>>=1;
  }
  return r;
}

inline ll inverse(ll n) {return binPow(n, MOD-2);}

struct cmp {
  inline bool operator()(int u, int v) {
    return h[u] < h[v];
  }
};


int main () {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cin >> n;
  for (int i = 1; i <= n; i++) {
    cin >> p[i];
    h[i] = h[p[i]]+1;
    children[p[i]].push_back(i);
  }

  vi level(1, 0), nextLevel;
  priority_queue<int, vi, cmp> myq;
  ll ans = 0;

  while (!level.empty()) {
    for (int u : level) {
      myq.push(p[u]);
      if (in[p[u]] == 0) {
        in[p[u]] = 1;
        myq.push(p[u]);
      }
    }
    while(!myq.empty()) {
      int u = myq.top();
      myq.pop();
      in[u] = 0;
      siz[u] = prod[u] = 1;
      sum[u] = 0;
      if (u && in[p[u]] == 0) {
        in[p[u]] = 1;
        myq.push(p[u]);
      }
    }
    for (int u : level) {
      sum[u] = prod[u] = 1;
      siz[u] = 2;
      in[u] = 1;
      myq.push(u);
    }
    while (!myq.empty()) {
      int u = myq.top();
      myq.pop();
      in[u] = 0;
      good[u] = sum[u]*prod[u]%MOD;
      bad[u] = (siz[u]-good[u]+MOD)%MOD;
      assert((good[u]+bad[u])%MOD==siz[u]);
      //cerr << u << "->  " << p[u] << " " << good[u] << " " << bad[u] << endl;
      if (u == 0) break;
      sum[p[u]] = (sum[p[u]]+good[u]*inverse(bad[u])%MOD)%MOD;
      prod[p[u]] = prod[p[u]]*bad[u]%MOD;
      siz[p[u]] = siz[p[u]]*siz[u]%MOD;
      if (in[p[u]] == 0) {
        in[p[u]] = 1;
        myq.push(p[u]);
      }
    }
    ans = (ans+good[0]*binPow(2, n+1-level.size())%MOD)%MOD;
    //cerr << "ans: " << good[0] << ' ' << n+1-level.size() << ' ' << ans << endl;

    nextLevel.clear();
    for (int u : level) {
      while (p[u] && siz[p[u]]==2) p[u] = p[p[u]];
      for (int v : children[u]) {
        nextLevel.push_back(v);
      }
    }
    swap(level, nextLevel);
  }

  
  cout << ans << endl;
}


Measured memory_bytes: 22912
N, X = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
cnt=0
for i in range(N):
    if A[i]<=X:
        X-=A[i]
        cnt+=1
    else:
        break
if X>0 and cnt==N:
    cnt-=1
print(cnt)


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

    int x; cin >> x;
    cout << !x << endl;
    return 0;
}


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

int main(){
  string str; cin >> str;
  int n; cin >> n;
  for(int i=0; i<n; i++){
    string op; cin >> op;
    int a, b;
    cin >> a >> b;

    if(op == "print")
      cout << str.substr(a, b-a+1) << endl;

    else if (op == "replace"){
      string p; cin >> p;
      str = str.substr(0, a) + p + str.substr(b+1);
      //cout << str << endl;

    }else if(op == "reverse"){
      string p = str.substr(a, b-a+1);
      reverse(p.begin(), p.end());
      str = str.substr(0, a) + p + str.substr(b+1);
      //cout << str <<endl;
    }

  }

  return 0;
}

Measured memory_bytes: 3232
//
//  main.cpp
//  ALDS1_4_B
//
//  Created by ptyuan on 2018/10/23.
//  Copyright © 2018 YY. All rights reserved.
//

#include <iostream>
#include <cstdio>
static const int kNotFound = -1;

int binarySearch(int *array, int n, int key) {
    int low = 0;
    int hight = n - 1;
    
    
    while (low <= hight) {
        int middle = (low + hight) * 0.5;
        int middleValue = array[middle];
        if (middleValue == key) {
            return middle;
        } else if (key > middleValue) {
            low = middle + 1;
        } else {
            hight = middle - 1;
        }
    }
    
    return kNotFound;
}

int main(int argc, const char * argv[]) {
    int n = 0;
    int s[100010] = {0};
    scanf("%d", &n);
    for (int i = 0; i < n; ++i) {
        scanf("%d", s + i);
    }
    
    int q = 0;
    int sum = 0;
    scanf("%d", &q);
    for (int i = 0; i < q; i++) {
        int temp = 0;
        scanf("%d", &temp);
        if (kNotFound != binarySearch(s, n, temp)) {
            sum++;
        }
    }
    printf("%d\n", sum);
    return 0;
}



Measured memory_bytes: 3624
// inputに入力データ全体が入る
function Main(input) {
    input = input.split("\n");
    N = parseInt(input[0]);
    answer = 0;
    moto_word = [];
    for(i = 0; i < N; i++){
        answer += new Set([input[1][i], input[2][i], input[3][i]]).size-1
    }
    console.log('%d',answer);
}
//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7728
M, D = list(map(int, input().split()))
ans = 0

for i in range(1, M + 1):
  for j in range(1, D + 1):
    d1 = j % 10
    d10 = j // 10
    m = d1 * d10
    if d1 >= 2 and d10 >= 2 and i == m:
      ans += 1

print(ans)


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

#define int long long
#define fi first
#define se second
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rep1(i,n) for(int i=1;i<=(int)(n);++i)
#define rep11(i,n) for(int i=1;i<(int)(n);++i)
#define repo(i,o,n) for(int i=o;i<(int)(n);++i)
#define repm(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end())
#define vdelete(v) (v).erase(unique(all(v)), (v).end())
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1000000007
#define INF 9223372036854775807

int a,b;
string s,hoge,huga;

signed main() {
    cin >> s;
    rep(i,2) hoge.pb(s[i]);
    repo(i,2,4) huga.pb(s[i]);
    a = stoll(hoge);
    b = stoll(huga);
    if((a>12 && b>12) || (!a && b>12) || (!b && a>12) || (!a && !b)) cout << "NA" << endl;
    else if (a > 12 || !a) cout << "YYMM" << endl;
    else if (b > 12 || !b) cout << "MMYY" << endl;
    else cout << "AMBIGUOUS" << endl;
}


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

int main() {
  string S; cin >> S;
  long long L = S.size();
  long long K; cin >> K;
  int head = 0;
  for (int i = 0; i < S.size(); i++) {
    if (S.at(i) == S.at(0)) head++;
    else break;
  }
  if (head == S.size()) {
    cout << (L * K) / 2 << endl;
    return 0;
  }
  if (S.at(0) == S.at(L-1)) {
    int tail = 0;
    for (int i = L-1; i >= 0; i--) {
      if (S.at(i) == S.at(L-1)) tail++;
      else break;
    }
    int mid = 0;
    int tmp = 1;
    char c = S.at(head);
    for (int i = head+1; i < L-tail; i++) {
      if (S.at(i) == c) tmp++;
      else {
        mid += tmp / 2;
        tmp = 1;
        c = S.at(i);
      }
    }
    mid += tmp / 2;
    cout << head/2 + ((head+tail)/2) * (K-1) + mid*K + tail/2 << endl;
  }
  else {
    int mid = 0;
    int tmp = 1;
    char c = S.at(0);
    for (int i = 1; i < L; i++) {
      if (S.at(i) == c) tmp++;
      else {
        mid += tmp / 2;
        tmp = 1;
        c = S.at(i);
      }
    }
    mid += tmp / 2;
    cout << K*mid << endl;
  }
}

Measured memory_bytes: 256
import java.util.Arrays;
import java.util.Scanner;
import java.util.stream.Stream;

public class Main {
    Scanner sc = new Scanner(System.in);

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

    void run(){
        String s = sc.next();
        if("AAA".equals(s) || "BBB".equals(s)){
            System.out.println("No");
        }else{
            System.out.println("Yes");
        }
    }
}

Measured memory_bytes: 23636
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Atcoder
{
    class Program
    {
        private static string Read() { return Console.ReadLine(); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }

        private static void print(object obj) { Console.WriteLine(obj); }

        static void Main(string[] args)
        {
            var n = ReadInt();
            var a = ReadLongs();
            long c = 0;
            for(int i = 0; i< n; i++)
            {
                c += a[i] - 1;
            }
            print(c);
        }

        public static int Lcm(int a, int b)
        {
            return a * b / Gcd(a, b);
        }

        // ユークリッドの互除法 
        public static int Gcd(int a, int b)
        {
            if (a < b)
                // 引数を入替えて自分を呼び出す
                return Gcd(b, a);
            while (b != 0)
            {
                var remainder = a % b;
                a = b;
                b = remainder;
            }
            return a;
        }
    }
}

Measured memory_bytes: 11220
import std.stdio;
import std.ascii;
import std.range;
import std.array;
import std.functional;
import std.algorithm;
import std.conv;
import std.container;
import std.math;
import std.numeric;
import std.string;
import std.c.string;
import std.random;
import std.regex;
import std.typecons;

struct Edge {
    int from, to, cost;
}

int N, M, P, A, B;
int[] T;
Edge[][] G;

bool input() {
    scanf("%d %d %d %d %d\n", &N, &M, &P, &A, &B);
    if (N == 0) return false;
    A--; B--;
    T = readln.chomp.split(" ").map!(to!int).array;
    G = new Edge[][M];
    foreach (i; 0 .. P) {
        int x, y, z;
        scanf("%d %d %d\n", &x, &y, &z);
        x--; y--;
        G[x] ~= Edge(x, y, z);
        G[y] ~= Edge(y, x, z);
    }
    return true;
}

double INF = 1e10;

void solve() {
    auto memo = new double[][](M, 1 << N);
    foreach (i; 0 .. M) memo[i][] = -1;

    double dfs(int v, int bit) {
        if (v == B) return 0.0;
        if (memo[v][bit] >= 0) return memo[v][bit];
        auto ret = INF;
        foreach (e; G[v]) {
            auto next = e.to;
            auto dist = e.cost;
            foreach (i; 0 .. N) {
                if (bit & (1 << i)) {
                    ret = min(ret, dfs(next, bit & ~(1 << i)) + cast(double)(dist) / T[i]);
                }
            }
        }
        return memo[v][bit] = ret;
    }

    auto ans = dfs(A, (1 << N) - 1);
    if (ans == INF) {
        writeln("Impossible");
    } else {
        writefln("%.8f", ans);
    }
}

void main() {
    while (input) solve;
}

Measured memory_bytes: 2356
#include<iostream>
#include<algorithm>
#define fi        first
#define se        second
#define pb        push_back
#define PI        acos(-1)
#define LC(a)     ((a<<1))
#define RC(a)     ((a<<1)+1)
#define MID(a,b)  ((a+b)>>1)
#define mem(a, b) memset(a, b, sizeof(a))
#define IOS()     std::ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
typedef unsigned long long ULL;
typedef pair<int,int> PII;
typedef pair<ll,ll>   PLL;
typedef pair<ll,int>  PLI;
const int INF = 0X3F3F3F3F;
const int MIN = -(1<<30);
const ll N = 1e5+7;
int cmp(int a,int b)
{
	return a>b;
}
inline void solve()
{
	int n,m;
	cin>>n>>m;
	int a[1005];
	int sum = 0;
	for(int i=0;i<n;i++) cin>>a[i],sum+=a[i];
	
	sort(a,a+n,cmp);
	for(int i=0;i<m;i++)
	{
		if(a[i]*4*m<sum)
		{
			cout<<"No"<<endl;
			return;
		}
	}
	cout<<"Yes"<<endl;

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




Measured memory_bytes: 256
import java.util.*;
import java.math.*;
public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int a=sc.nextInt();
		int b=sc.nextInt();
		if(a<b){
			for(int i=0; i<b; i++){
				System.out.print(a);
			}
		}else{
			for(int i=0; i<a; i++){
				System.out.print(b);
			}
		}
	}
}


Measured memory_bytes: 22864
#include  <bits/stdc++.h>
using namespace std;
#define    error(args...){string _s=#args;replace(_s.begin(), _s.end(), ',', ' ');stringstream _ss(_s);istream_iterator<string> _it(_ss);err(_it,args);}
void err  (istream_iterator<string> it) {}
template  <typename T, typename... Args>
void err  (istream_iterator<string> it, T a, Args... args)
{
    cerr << *it << " = " << a <<" ; ";
    err(++it, args...);
    cout << endl;
}
/*----------------------------------------------------------------------------------------------------------------------------------------------------*/
/*Let's start.............*/
#define   ll                long long
#define   pb                push_back
#define   ff                first
#define   ss                second
#define   srt(v)            sort(v.begin(),v.end())
#define   inf               200000000000000000
#define   mxn               1000009
#define   MOD               1000000007
#define   pi                acos(-1)

int main()
{
    ll n;
    cin >> n;
    ll arr[n+10];
    memset(arr,0,sizeof arr);
    for(ll i = 1;i < n;i++){
        ll x;cin >> x;
        arr[x]++;
    }
    for(ll i = 1;i <= n;i++) cout << arr[i] << endl;
    return 0;
}

/*-------------------------------------------------------------------------------------------------------------------------------------------------------
".....but the truth is that you can increase it slightly."
Day 34.

// Learn to calculate the number of paths going through it
6
1 2 2 2 1 3
1 2
2 3
3 4
4 5
3 6

*/


Measured memory_bytes: 5160
n = gets.strip.to_i
a = gets.strip.split.map(&:to_i)

odds = a.map.with_index {|x, index| x if (index+1).odd? }.compact
evens = a.map.with_index {|x, index| x if !(index+1).odd? }.compact

# default n=odd
result = odds.reverse + evens
result=result.reverse if n.even?

puts result.join(' ')




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

using LL = long long;

#define ALL(a) begin((a)), end((a))
#define FOR(i, a, b) for (int(i) = (a); (i) < (b); (i)++)
#define RFOR(i, a, b) for (int(i) = (a); (i) > (b); (i)--)
#define debug(x) cerr << #x << " : " << x << '\n'

const int INF = 1e9;
const int MOD = 1e9 + 7;
const LL LINF = 1e16;

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

  string ans = "";
  int n;
  cin >> n;
  vector<vector<int>> count(n, vector<int>(26));
  string S;

  FOR(i, 0, n) {
    cin >> S;
    int size = S.size();

    FOR(j, 0, size) {
      int num = (int)(S[j] - 'a');
      count[i][num]++;
    }
  }

  FOR(i, 0, 26) {
    int minimum = 100;

    FOR(j, 0, n) { minimum = min(minimum, count[j][i]); }

    FOR(j, 0, minimum) {
      char ch = 'a' + i;
      ans.push_back(ch);
    }
  }

  cout << ans << '\n';

  return 0;
}

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

using namespace std;

int main() {

    char s;

    cin >> s;

    if(s=='A')
        cout<<'T'<<endl;
    else if(s=='T')
        cout <<'A'<<endl;
    else if(s=='C')
        cout<<'G'<<endl;
    else
        cout << 'C'<<endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long a[100001], dp[61];
int main(){
    int n;
    scanf("%d", &n);
    long long sum = 0;
    for(int i=1;i<=n;i++){
        scanf("%lld", &a[i]);
        sum ^= a[i];
    }

    for(int i=60;i>=0;i--){
        if((sum>>i)&1){
            for(int j=1;j<=n;j++){
                if((a[j]>>i)&1) a[j] ^= (1ll<<i);
            }
        }
    }

    long long ans = 0;
    memset(dp, -1, sizeof(dp));
    for(int i=1;i<=n;i++){
        long long tmp = a[i];
        for(int j=60;j>=0;j--){
            if(!((tmp>>j)&1)){
                if(dp[j] != -1) tmp ^= dp[j];
            }
        }
        ans = max(ans, tmp);
        tmp = a[i];
        for(int j=60;j>=0;j--){
            if((tmp>>j)&1){
                if(dp[j] != -1) tmp ^= dp[j];
                else{
                    dp[j] = tmp;
                    break;
                }
            }
        }
    }
    printf("%lld\n", ans + (sum^ans));
}

Measured memory_bytes: 1024
import java.util.*;
 
public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        int N = 0;
        int[] a_i;
        int mas=0;
        Scanner scan = new Scanner(System.in);
        N = scan.nextInt();
        //if(!(1<=N))System.out.println("Nを1以上の数にしてね");
        a_i = new int[N];
        for(int i = 0;i<N;i++){
            a_i[i] = scan.nextInt();
        }
        for(int i = 0;i<N;i++){
            //if(!(a_i[i] <= 100))System.out.println("a_" + i + "を100いかにしてね");
           if(!((i+3)%2==0)){
               if(!((a_i[i]+2)%2==0))mas++;
           }
        }
        System.out.println(mas);
    }
}

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

#define lli long long int
#define REP(i,s,n) for(int i=s;i<n;i++)
#define NUM 2520
#define INF (1LL<<50)
#define DEBUG 0
#define mp(a,b) make_pair(a,b)
#define SORT(V) sort(V.begin(),V.end())
#define PI (3.141592653589794)
#define TO_STRING(VariableName) # VariableName
#define LOG(x) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<endl;
#define LOG2(x,y) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<endl;
#define LOG3(x,y,z) if(DEBUG)cout<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;
#define LOG4(w,x,y,z) if(DEBUG)cout<<TO_STRING(w)<<"="<<w<<" "<<TO_STRING(x)<<"="<<x<<" "<<TO_STRING(y)<<"="<<y<<" "<<TO_STRING(z)<<"="<<z<<endl;

template<class T>bool chmax(T & a, const T & b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }

double diff(lli x,lli y,lli xx,lli yy){
    lli diffX = x-xx;
    lli diffY = y-yy;
    LOG(sqrt(diffX*diffX+diffY*diffY));
    return sqrt(diffX*diffX+diffY*diffY);
}


void func(long long N, std::vector<long long> x, std::vector<long long> y){

    vector<lli> per(N);
    REP(i,0,N)per[i] = i;

    double ans = 0;
    lli cnt = 0;
    do{
        REP(i,1,N)ans += diff(x[per[i-1]],y[per[i-1]],x[per[i]],y[per[i]]);
        cnt++;
    }while(next_permutation(per.begin(),per.end()));

    cout<<setprecision(15);
    cout<<ans/(double)cnt<<endl;

}

int main(){
    // cout << fixed << setprecision(5);

    long long N;
    scanf("%lld",&N);
    std::vector<long long> x(N);
    std::vector<long long> y(N);
    for(int i = 0 ; i < N ; i++){
        scanf("%lld",&x[i]);
        scanf("%lld",&y[i]);
    }
    func(N, std::move(x), std::move(y));
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>

using namespace std;

typedef long long ll;
const int maxn = 1e5 + 10 , oo = 1e9 + 7;
int n , s;
int x[maxn];
ll p[maxn];
int main(){
	ios::sync_with_stdio(0);
	cin >> n >> s;
	for(int i = 1 ; i <= n ; ++ i)
		cin >> x[i] >> p[i];
	x[n + 1] = oo;
	int mid;
	for(int i = 0 ; i <= n ; ++ i)
		if(x[i] < s && x[i + 1] > s){
			mid = i;
			break;
		}
	ll ans = 0;
	int l = 1 , r = n;
	int last = -1;
	while(l <= mid && r > mid){
		if(p[l] < p[r]){
			if(last != 0){
				ans += x[r] - x[l];
				last = 0;
			}
			p[r] += p[l];
			l ++;
		}
		else{
			if(last != 1){
				ans += x[r] - x[l];
				last = 1;
			}
			p[l] += p[r];
			r --;
		}
	}
	if(l <= mid)
		ans += s - x[l];
	if(r > mid)
		ans += x[r] - s;
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1408
#!/usr/bin/python3
# -*- coding:utf-8 -*-

def main():
  h, w = map(int, input().split())  
  if h%3 == 0 or w%3 == 0:
    print(0)
  elif h == 1 or w == 1:
    print(1)
  else:
    def f(h, w):
      y = h//2
      x = 2 * (w // 3)
      score = 10**9
      for dx in range(2):
        cands = [(x+dx)*y, (x+dx)*(h-y), (w - (x+dx))*h]
        score = min(score, max(cands) - min(cands))
      return score
    print(min([f(h, w), f(w, h), h, w]))

if __name__=='__main__':
  main()



Measured memory_bytes: 3064
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<string>
#include<cstring>
#include<cmath>
#include<ctime>
#include<algorithm>
#include<utility>
#include<stack>
#include<queue>
#include<vector>
#include<set>
#include<map>
#define EPS 1e-9
#define PI acos(-1.0)
#define INF 0x3f3f3f3f
#define LL long long
const int MOD = 1E9+7;
const int N = 50+5;
const int dx[] = {0,0,-1,1,-1,-1,1,1};
const int dy[] = {-1,1,0,0,-1,1,-1,1};
using namespace std;

int main() {
    LL n,s;
    scanf("%lld%lld",&n,&s);
    if(n==s)
        printf("%lld\n",s+1);
    else if(n<s)
        printf("-1\n");
    else {
        LL mid=sqrt(n)+1;
        bool flag=false;

        //b>sqrt(n)
        LL res;
        for(LL i=2; i<=mid; i++) { //枚举b
            res=0;
            LL temp=n;
            while(temp) {
                res+=temp%i;
                temp/=i;
            }
            if(res==s) {
                printf("%lld\n",i);
                flag=true;
                break;
            }
        }

        //b<=sqrt(n)
        if(!flag) {
            LL factor=n-s;
            LL res;
            mid=sqrt(factor)+1;
            for(LL i=mid; i>=1; i--) {//枚举x1
                if(factor%i==0) {
                    res=factor/i+1;
                    LL j=s-i;//x2
                    if(i<res&&res>=2&&j<res&&j>=0) { //判断b的合法性
                        printf("%lld\n",res);
                        flag=true;
                        break;
                    }
                }
            }
        }

        //其他情况
        if(!flag)
            printf("-1\n");
    }

    return 0;
}


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

B = [[float("inf")] * n for i in range(n)]
for i in range(n):
    for j in range(n):
        B[i][j] = min(B[i-1][j], A[(j-i)%n])

ans = float("inf")
for i in range(n):
    ans = min(ans, sum(B[i])+x*i)        
print(ans)

Measured memory_bytes: 140892
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define all(x) (x).begin(), (x).end()

using namespace __gnu_pbds;
using namespace std;

using ull = unsigned long long;
using ll = long long;
using ld = long double;
template <typename T> using ordered_set = tree<T, null_type, less<>, rb_tree_tag, tree_order_statistics_node_update>;

const int mod = 1e9 + 7;
const int inf = INT_MAX;

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

    int n;
    cin >> n;

    int c1 = 0, c2 = 0, c3 = 0, c4 = 0;
    while (n--) {
        string s;
        cin >> s;

        if (s == "AC")
            c1++;
        else if (s == "WA")
            c2++;
        else if (s == "TLE")
            c3++;
        else if (s == "RE")
            c4++;
    }

    cout << "AC x " << c1 << "\n";
    cout << "WA x " << c2 << "\n";
    cout << "TLE x " << c3 << "\n";
    cout << "RE x " << c4 << "\n";
    return 0;
}

Measured memory_bytes: 3656
#include <bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
const int INF = 1e9;
typedef long long ll;
typedef pair<ll, ll> P;

int main() {
    ll n; cin >> n;
    string s; cin >> s;
    ll r_cnt,g_cnt,b_cnt;
    r_cnt = count(all(s),'R');
    g_cnt = count(all(s),'G');
    b_cnt = count(all(s),'B');
    
    ll ans = r_cnt*g_cnt*b_cnt;
    for(ll i=0;i<n;i++){
        for(ll d=0;d<n;d++){
            ll j = i + d;
            ll k = j + d;
            if(k >= n) break;
            if(s[i] != s[j] and s[j] != s[k] and s[k] != s[i]) ans -= 1;
        }
    }
    cout << ans << endl;
}

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

static const int N = 100;
static const int INFTY = (1<<21);
int n, M[N][N];
int d[N];

void bfs(int s) {
	queue<int> q;
	q.push(s);
	for ( int i = 0; i < n; i++ ) d[i] = INFTY;
	d[s] = 0;
	int u;
	while ( !q.empty() ) {
		u = q.front(); q.pop();
		for ( int v = 0; v < n; v++ ) {
			if ( M[u][v] == 0 ) continue;
			if ( d[v] != INFTY ) continue;
			d[v] = d[u] + 1;
			q.push(v);
		}
	}
	for (int i = 0; i<n; i++ ) {
		cout << i+1 << " " << ( (d[i] == INFTY) ? (-1) : d[i] ) << endl;
	}
}

int main() {
	int u, k, v;

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

	for ( int i = 0; i <n; i++ ) {
		cin >> u >> k;
		u--;
		for ( int j = 0; j < k; j++ ) {
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}

	bfs(0);

	return 0;
}


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

int main(){
	int h, w, d; cin >> h >> w >> d;
	vector<vector<char>> g(h, vector<char> (w));
	rep(i,h) rep(j,w) cin >> g[i][j];

	ll ans = 0;
	rep(H,h-d+1){
		rep(W,w){
			bool jud = true;
			rep(i,d){
				if(g[H+i][W] == '#') jud = false; 
			}
			if(jud) ans++;
		}
	}

	rep(H,h){
		rep(W,w-d+1){
			bool jud = true;
			rep(i,d){
				if(g[H][W+i] == '#') jud = false; 
			}
			if(jud) ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 3168