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

using namespace std;

const int MOD = 998244353;

int r[200005];
pair <int, int> a[200005];
bool vis[200005];
vector <int> edge[200005];

long long solve(int id, int p) {
    vis[id] = 1;
    
    long long product = 1LL;

    for (int i = 0; i < edge[id].size(); i++) {
        int to = edge[id][i];
        if (to == p) continue;
        product = product * solve(to, id) % MOD;
    }

    return (product + 1) % MOD;
}

int main() {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n; i++) {
        scanf("%d%d", &a[i].first, &a[i].second);
    }

    sort(a, a + n);
    
    for (int i = n - 1; i >= 0; i--) {
        int cur = a[i].first;
        int lim = a[i].first + a[i].second;
        r[i] = a[i].first + a[i].second;

        while (true) {
            auto itr = lower_bound(a + i + 1, a + n, make_pair(cur, -1));
            if (itr == a + n || a[itr - a].first >= lim) break;

            int id = itr - a;
            edge[i].push_back(id);
            r[i] = max(r[i], r[id]);
            cur = r[id];
        }
    }

    long long res = 1LL;

    for (int i = 0; i < n; i++) {
        if (!vis[i]) {
            res = (res * solve(i, -1)) % MOD;
        }
    }
    printf("%lld\n", res);
}


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

int main(){
    int N; cin >> N;
    string S; cin >> S;
    int ans = 0;
    for(int i=0; i<N; ++i){
        if(S[i]==S[i+1]) continue;
        ans++;
    }
    cout << ans << endl;
}


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

int main()
{
  string s;
  int k;
  cin >> s >> k;
  int hi = 0;

  for (int i = 0; i < s.size(); i++) {
    if (s[i] == '1') hi++;
    else break;
  }
  if (hi >= k) cout << 1 << endl;
  else cout << s[hi] << endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 55;
int x[N], y[N];

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

    int n;
    cin >> n;

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

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

    map<pair<int, int>, int> mp;

    for (int i = 0; i < n; i++) {
        for (int j = 0; j < n; j++) {
            if (i != j) {
                mp[{x[i] - x[j], y[i] - y[j]}]++;
            }
        }
    }

    int ans = 0;

    for (const auto &p : mp) {
        ans = max(ans, p.second);
    }

    ans = n - ans;

    cout << ans << "\n";

    return 0;
}

Measured memory_bytes: 384
N,K=map(int,input().split())
*A,=map(int,input().split())

argmin = A.index(1)

back = (argmin+(K-1)-1)//(K-1)
forward = (N-argmin-1+(K-1)-1)//(K-1)
ans1 = back+forward

ans2 = ((N-1)+(K-1)-1)//(K-1)

print(min(ans1,ans2))

Measured memory_bytes: 20632
#include <stdio.h>

int combRnums(int n, int r, int *ans);

int main()
{
  int n, ans;
  while(scanf("%d", &n) != EOF){
    ans=0;
    if(n>0 && n<=36) combRnums(n, 4, &ans);
    printf("%d\n", ans);
  }
  return(0);
}

int combRnums(int n, int r, int *ans)
{
  if(n==0){
    (*ans)++;
    return 1;
  }else if(r==0) return 0;
  
  int i, ret;
  for(i=0; i<10; i++){
    ret = combRnums(n-i, r-1, ans);
    if(ret==1) return 0;
  }
  return 0;
}

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

using lint = long long int;
using pint = pair<int, int>;
using plint = pair<lint, lint>;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define POW2(n) (1LL << (n))
#define FOR(i, begin, end) for (int i = (begin), i##_end_ = (end); i < i##_end_; i++)
#define IFOR(i, begin, end) for (int i = (end)-1, i##_begin_ = (begin); i >= i##_begin_; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)

int main()
{
    lint d,t,s;cin >> d >> t >>s;

    cout << ((t*s>=d)? "Yes" : "No") << "\n";
    return 0;
}

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

int main()
{
    string A, B;
    cin >> A >> B;

    if (A.size() > B.size())
    {
        cout << "GREATER" << endl;
        return 0;
    }
    else if (A.size() < B.size())
    {
        cout << "LESS" << endl;
        return 0;
    }
    else
    {
        for (int i = 0; i < A.size(); i++)
        {
            if (A[i] > B[i])
            {
                cout << "GREATER" << endl;
                return 0;
            }
            else if (A[i] < B[i])
            {
                cout << "LESS" << endl;
                return 0;
            }
        }
    }
    cout << "EQUAL" << endl;

    return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner scan = new Scanner(System.in);

		Integer a = scan.nextInt();
		Integer b = scan.nextInt();
		Integer h = scan.nextInt();

		int total = 0;

		if ((h & 1) == 0) {
			if (a >= 1 && b >= 1 && h >= 1 && a <= 100 && b <= 100 && h <= 100) {
				total = (a + b) * h / 2;
			}
			if (total > 0) {
				System.out.println(total);
			}
		} else {
			System.err.println("");
		}
	}

}

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

int main() {
    int N; cin >> N;
    vector<int> cnt(4);
    for(int i = 0; i < N; ++i) {
        string S; cin >> S;
        if(S == "AC") cnt[0]++;
        else if(S == "WA") cnt[1]++;
        else if(S == "TLE") cnt[2]++;
        else cnt[3]++;
    }
    cout << "AC" << " x " << cnt[0] << '\n';
    cout << "WA" << " x " << cnt[1] << '\n';
    cout << "TLE" << " x " << cnt[2] << '\n';
    cout << "RE" << " x " << cnt[3] << '\n';
    return 0;
}


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

int main() {
	ll a, b; int n; scanf("%lld%lld%d", &a, &b, &n);
	ll Min = LLONG_MAX;
	for (int i = 1; i <= n; i++) {
		if (b%i)continue;
		for (int j = 1; j <= n; j++)Min = min(Min, abs(a - b / i*j));
	}
	printf("%lld\n", Min);
}

Measured memory_bytes: 3180
#define _USE_MATH_DEFINES
#include<cmath>
#include<cstdio>
#include<cstring>
#include<bitset>
#include<iostream>
#include<algorithm>
#include<string>
#include<utility>
#include<tuple>
#include<vector>
#include<list>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<numeric>
#include<functional>
#include<iomanip>
#include<random>
using namespace std;


#define IOS ios::sync_with_stdio(false),cin.tie(0)
#define REP(i,n) for(int i = 0;i < n;i++)
#define FOR(i,a,b) for(int i = a;i < b;i++)
#define ALL(x) (x).begin(),(x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

struct UnionFind {
	vector<int> data;
	UnionFind(int size) : data(size, -1) {}
	void unionSet(int x, int y) {
		x = root(x), y = root(y);
		if (x != y) {
			if (data[y] < data[x])swap(x, y);
			data[x] += data[y]; data[y] = x;
		}
	}
	bool findSet(int x, int y) {
		return root(x) == root(y);
	}
	int root(int x) {
		return data[x] < 0 ? x : data[x] = root(data[x]);
	}
	int size(int x) {
		return -data[root(x)];
	}
};

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 digitsum(ll a) {
	int sum = 0;
	while (a) {
		sum += a % 10;
		a /= 10;
	}
	return sum;
}
int getdigit(ll a) {
	return to_string(a).size();
}
int countpow(ll a, ll b) {
	int ans = 0;
	if (b == 0)return -1;
	while (1) {
		if (a % b == 0) {
			a /= b;
			ans++;
		}
		else break;
	}
	return ans;
}
int to_num(char c) {
	if (c >= '0' && c <= '9')return (c - '0');
	else return -1;
}



int main() {
	IOS;
	int n;
	cin >> n;
	vector<int> a(n);
	REP(i, n) {
		cin >> a[i];
	}
	ll res = 0;
	ll sum = 0;
	int right = 0;
	REP(left, n) {
		while (right < n && (sum ^ a[right]) == (sum + a[right])) {
			sum += a[right];
			right++;
		}
		res += right - left;
		if (left == right)right++;
		sum -= a[left];
	}
	dump(res);
}




Measured memory_bytes: 1024
#include <algorithm> 
#include <iostream> 
using namespace std; 
int main(){
long long int n,m,yan,p[100],t[100000],x[100000],d;
cin>>n;
for(int i=0;i<n;i++){
cin>>t[i];
}
cin>>m;
for(int i=0;i<m;i++){
cin>>p[i]>>x[i];
}
for(int i=0;i<m;i++){
yan=t[p[i]-1];
t[p[i]-1]=x[i];
d=0;
for(int j=0;j<n;j++){
d+=t[j];
}
cout<<d<<endl;
t[p[i]-1]=yan;
}
}

Measured memory_bytes: 256
let () =
  Scanf.scanf "%d" @@ fun n ->
  Array.init n (fun _ -> Scanf.scanf " %d" ((+) 0)) |> Array.to_list
  |> List.sort_uniq (-) |> List.length
  |> fun l -> Printf.printf "%d\n" (l - (l+1) mod 2)

Measured memory_bytes: 8448
#include <bits/stdc++.h>
using namespace std;
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;
}
void debug() { cerr << "\n"; }
template <class T> void debug(const T &x) { cerr << x << "\n"; }
template <class T, class... Args> void debug(const T &x, const Args &... args) {
    cerr << x << " ";
    debug(args...);
}
template <class T> void debugVector(const vector<T> &v) {
    for(const T &x : v) {
        cerr << x << " ";
    }
    cerr << "\n";
}
using ll = long long;

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
const double EPS = 1e-7;
const int INF = 1 << 30;
const ll LLINF = 1LL << 60;
const double PI = acos(-1);
constexpr int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

//-------------------------------------

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    int ans = 0;
    for(int i = 0; i < n; i++) {
        ans += (i < k ? x : y);
    }
    cout << ans << endl;
}

Measured memory_bytes: 3612
#include <string.h>
#include <algorithm>
#include <vector>
#include <functional>
#include <fstream>
#include <iostream>
#define mod 1000000007
using namespace std;
ifstream f("rick.in");
ofstream g("rick.out");


long long int n,sol;
int main()
{
cin>>n;
sol=sol+(n/500)*1000+(n%500)/5*5;

cout<<sol;
}


Measured memory_bytes: 256
#!/usr/bin/env python3
import sys


def solve(N: int):
    ret = 1
    while ret <= N:
        ret *= 2
    ret //= 2
    print(ret)
    return


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    solve(N)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include<bits/stdc++.h>
#define ll long long
#define rep(i,a,b) for(ll i=a;i<=b;i++)
#define repn(i,n) for(ll i=0;i<n;i++)
#define all(v) v.begin(),v.end()
#define bac(i,a,b) for(ll i=a;i>=b;i--)
#define sz(v) (ll)v.size()
#define vi vector<ll>
#define pi pair<ll,ll>
#define vpi vector<pair<ll,ll>>
using namespace std;

ll MOD=1e9+7;
ll g,h,l;
const ll N=100005, inf=1e9+5;

ll add(ll a,ll b); ll mul(ll a,ll b); ll binpo(ll a,ll b);

int main(){
  ios_base::sync_with_stdio(false); cin.tie(NULL);
  ll x,k,d;cin>>x>>k>>d;
  ll ans =0;
  bool neg = x<0;

  if(k>=abs(x)/d){
    x = abs(x);
    ll turns = x/d;
    k-=turns;
    if(k%2){
      ans = abs((x-turns*d-d));
    }
    else{
      ans = abs((x-turns*d));
    }
  }
  else{
    if(x<0){
      ans = abs(x+k*d);
    }
    else{
      ans = abs(x-k*d);
    }
  }
  cout<<ans;
}

//1. Change N before submitting.
//2. Remove debug statements.

ll add(ll a,ll b)
{
  return (a%MOD+b%MOD)%MOD ;
}
ll mul(ll a,ll b)
{
  return (a* 1ll *b)%MOD ;
}
ll binpo(ll a,ll b)
{
  int ans = 1 ;
  while(b)
  {
    if( b % 2 != 0)
    {
      ans = mul(ans,a);
    }
    a = mul(a,a);
    b = b/2;
  }
  return ans;
}

Measured memory_bytes: 3648
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LS()
    return l
sys.setrecursionlimit(1000000)
mod = 1000000007

#A
def A():
    n,k = LI()
    print(n-k+1)
    return

#B
def B():
    r,g,b,n = LI()
    ans = 0
    for i in range(n+1):
        x = r*i
        for j in range(n+1-x):
            y = g*j
            z = n-x-y
            if z%b != 0 or z < 0:continue
            ans += 1
    print(ans)
    return

#C
def C():
    n = I()

    return

#D
def D():
    n = I()

    return

#E
def E():
    n = I()

    return

#F
def F():
    n = I()

    return

#G
def G():
    n = I()

    return

#H
def H():
    n = I()

    return

#I
def I_():
    n = I()

    return

#J
def J():
    n = I()

    return

#Solve
if __name__ == "__main__":
    B()


Measured memory_bytes: 39536
#![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 n: usize = sc.cin();
    let mut xs = vec![0; n + 1];
    for _ in 1..n {
        let a: usize = sc.cin();
        xs[a-1] += 1;
    }
    for i in 0..n {
        put!(xs[i]);
    }
}

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: 14156
#!/usr/bin/env python3
d, n = map(int, input().split())
if d == 0:
    if n == 100:
        print(101)
    else:
        print(n)
elif d == 1:
    l = []
    if n == 100:
       print(10100)
    else:
        for i in range(1, 100):
            l.append(100 * i)
        print(l[n-1]) 
else:
    if n == 100:
        print(1010000)
    else:
        l = []
        for i in range(1, 101):
            l.append(100 * 100 * i)
        print(l[n-1]) 

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

int main(){
	cin.tie(0),ios::sync_with_stdio(false);
	int d,n; cin>>d>>n;
	int base=1; for(int i=0;i<d;++i)base*=100;
	int ans=base;
	for(int i=1;i<n;++i){
		ans+=base;
		int div=ans,cnt=0;
		while(div%100==0){
			div/=100;
			++cnt;
		}
		if(cnt!=d)--i;
	}
	cout<<ans<<"\n"s;
}


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

using namespace std;

int main(){
    int S;
    cin >> S;
    int result1 = S / 3600 ;
    int result2 = (S - 3600 * result1) / 60 ;
    int result3 = S % 60;
    cout << result1 << ":" << result2 << ":" << result3 << endl;
}
    

Measured memory_bytes: 1164
var
	n,i,s,t,ans:Longint;
	a,b:array[1..100]of Longint;
begin
	read(n);
	for i:=1 to n do read(a[i]);
	for i:=1 to n do begin
		read(b[i]);
		inc(t,b[i]);
	end;
	for i:=1 to n do begin
		inc(s,a[i]);
		if ans<s+t then ans:=s+t;
		dec(t,b[i]);
	end;
	writeln(ans);
end.


Measured memory_bytes: 128
/*
    Author: Nguyen Tan Bao
    Status:
    Idea:
*/

#include <bits/stdc++.h>
#define FI first
#define SE second
#define EPS 1e-9
#define ALL(a) a.begin(),a.end()
#define SZ(a) int((a).size())
#define MS(s, n) memset(s, n, sizeof(s))
#define FOR(i,a,b) for (int i = (a); i <= (b); i++)
#define FORE(i,a,b) for (int i = (a); i >= (b); i--)
#define FORALL(it, a) for (__typeof((a).begin()) it = (a).begin(); it != (a).end(); it++)
//__builtin_ffs(x) return 1 + index of least significant 1-bit of x
//__builtin_clz(x) return number of leading zeros of x
//__builtin_ctz(x) return number of trailing zeros of x

using namespace std;
using ll = long long;
using ld = double;
typedef pair<int, int> II;
typedef pair<II, int> III;
typedef complex<ld> cd;
typedef vector<cd> vcd;

const ll MODBASE = 1000000007LL;
const int MAXN = 110;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    int x;
    cin >> x;
    cout << 1-x;
    return 0;
}


Measured memory_bytes: 3660
def read_input(trans=int):
    return list(map(trans, input().split()))


YES = "YES"
NO = "NO"

# 1行
A, V = read_input()
B, W = read_input()
T = int(input())

if W > V:
    print(NO)
elif (V-W)*T >= abs(B-A):
    print(YES)
else:
    print(NO)


Measured memory_bytes: 9176
"""
---アルゴリズム概要---
Mを構成する素因数を、a1~aNの各スロットにいくつ置くのか、を考える問題。
まずは試し割りによってMを素因数分解。
重複組合せの公式で各素因数の配置パターンを算出し累乗していく。

試し割りは、O(√M)の計算量で処理できる。
√Mを超える素因数は、多くても一つしか存在しないため、√Mを超える値で試し割りをする必要はない。
もし√Mまでの値で試し割りを終えた段階で、Mを素因数分解しきれていなければ、残った商こそが√Mを超える唯一の素因数である。

簡単に証明
もし√Mを超える素因数が２つ存在しているとしよう。
それらは、(√M + α)と(√M + β)というふうに表すことができる。
この２つの積は明らかにMの値を超えてしまう。つまり前提に矛盾する。
したがって、√Mを超える素因数は多くても一つ
"""
from collections import Counter
import math

N,M = map(int,input().split())
factors = []

while M%2 == 0:
    M//=2
    factors.append(2)
    
f = 3
while f**2 <= M:
    while M%f==0:
        M//=f
        factors.append(f)
    f+=2
if M!=1:
    factors.append(M)

factors = Counter(factors)

ans = 1
for k in factors.values():
    ans *= math.factorial(k+N-1)//(math.factorial(N-1)*math.factorial(k))

print(ans%(10**9+7))

Measured memory_bytes: 114396
#include<stdio.h>
   int l[200],d[200];
   int n,x;
   int main()
   {
   while(scanf("%d%d",&n,&x)!=EOF)
	  {
	  for(int i=1;i<=n;i++)
		 {
		 scanf("%d",&l[i]);
         }
	  d[1]=0;
	  for(int i=2;i<=n+1;i++)
		 {
		 d[i]=d[i-1]+l[i-1];
         }
      int t=0;
	  for(int i=1;i<=n+1;i++)
		 {
		 if(d[i]<=x)
		 t++;
		 }
	  printf("%d\n",t);
//	  for(int i=1;i<=n+1;i++)
//		 printf("%d ",d[i]);
//		 printf("\n");
      }
   return 0;
   }

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

int main() {
    int N; cin >> N;
    vector<int> A(N);
    rep(i, N){
        cin >> A[i];
    }

    ll ans = 0;
    int r = 0;
    int total = 0;
    for (int l = 0; l < N; l++){
        while((total + A[r]) == (total ^ A[r]) && r < N){
            total += A[r];
            r++;
        }
        ans += r - l;
        total -= A[l];
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 4004
N,K = list(map(int, input().split()))
p = list(map(int, input().split()))
p2 = [p[i]*0.5 + 0.5 for i in range(N)]
size = N + 1
cusum = [0] * size
max = 0

for i in range(N):
    cusum[i+1] = cusum[i] + p2[i]

for i in range(N-K+1):
    tmp = cusum[i+K] - cusum[i]
    if max < tmp:
        max = tmp
print(max)


Measured memory_bytes: 81800
// -- 霊長類の競プロ
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <numeric>

using namespace std;

int main(int argc, const char * argv[]) {
    
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    int a;
    
    cin >> a;
    cin >> s;
    
    cout << (a>=3200 ? s : "red") << endl;

    return 0;
}


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

using namespace std;

int dp[100005];

vector<int> edges[100005];
int n, m;

int dfs(int curr){
    if(dp[curr]!=0) return dp[curr];
    int res = 0;
    for(int k: edges[curr]){
        res = max(res, dfs(k));
    }
    return dp[curr] = res+1;
}

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

    cin>>n>>m;
    for(int i=0;i<m;i++){
        int x, y;
        cin>>x>>y;
        x--;y--;
        edges[x].push_back(y);
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        if(!dp[i]) ans = max(dfs(i), ans);
    }
    cout<<ans-1;
    return 0;
}

Measured memory_bytes: 8192
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
typedef long long ll;
//#define int ll
typedef ll Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<pii,int,int> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
//template<class C>constexpr int size(const C &c){return (int)c.size();}
//template<class T,size_t N> constexpr int size(const T (&xs)[N])noexcept{return (int)N;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
int main(){
	int n,p;
	cin>>n>>p;
	vp in(n);
	rep(i,n)cin>>in[i].first>>in[i].second;
	vp d(n);
	rep(i,n)d[i]={(p-100)*in[i].first-p*in[i].second,i};
	sort(all(d));
	ll sum=0;
	rep(i,n)sum-=p*in[i].second;
	rep(i,n){
		int t=d[i].second;
		sum+=(100-p)*in[t].first+p*in[t].second;
		if(sum>=0){
			cout<<i+1<<endl;
			break;
		}
	}
}




















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

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

struct p
{
	int x;
	int y;
};

p ara[10];

int sq(int x)
{
	return x*x;
}

ld dis(p a,p b)
{
	ld ans=sq(a.x-b.x)+sq(a.y-b.y);
	ans*=1.0;
	ans=sqrt(ans);
	
	return ans;
}

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

	int n;
	cin>>n;
	
	for(int i=1;i<=n;i++) cin>>ara[i].x>>ara[i].y;
	
	vector<int>v;
	
	for(int i=1;i<=n;i++) v.push_back(i);
	
	ld ans=0.0;
	
	while(next_permutation(v.begin(),v.end()))
	{
		//for(auto it: v) cout<<it<<" ";
		//cout<<"\n";
		ld d=0.0;
		for(int i=0;i<v.size()-1;i++)
		{
			d+=dis(ara[v[i]],ara[v[i+1]]);
			//cout<<v[i]<<" "<<v[i+1]<<"---"<<dis(ara[v[i]],ara[v[i+1]])<<"\n";
		}
		/*d+=dis(ara[v[0]],ara[v.back()]);
		cout<<v[0]<<" "<<v.back()<<"----"<<dis(ara[v[0]],ara[v.back()])<<"\n";*/
		
		//cout<<"---"<<d<<"\n";
		
		//d/=(ld)n;
		ans+=d;
	}
	
	//for(auto it: v) cout<<it<<" ";
	
	ld d=0.0;
	
	for(int i=0;i<v.size()-1;i++) d+=dis(ara[v[i]],ara[v[i+1]]);
	//d+=dis(ara[v[0]],ara[v.back()]);
	//d/=(ld)n;
	//cout<<"---"<<d<<"\n";
	
	ans+=d;
	
	for(int i=1;i<=n;i++) ans/=(ld)i;
	
	cout<<fixed<<setprecision(10)<<ans;
		
					                                				
	cerr<<"\nTime elapsed: " << 1000.0 * clock() / CLOCKS_PER_SEC << " ms\n";
	
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );
using namespace std;
using ll = long long;

int main(){
    int a, b;
    cin >> a >> b;
    
    int c = abs(a-b);
    if(c%2 == 1){
        cout << "IMPOSSIBLE" << endl;
        return 0;
    }

    cout << min(a,b) + c/2 << endl;
}

Measured memory_bytes: 256
/*                        ______
 _______   /\     |``\   |        |  /
    |     /  \    |__/   |____    |/
    |    / _ _\   |  \   |        |\
    |   /      \  |   \  |______  |  \

            Dept. of CSE
        Comilla  University

*/
#include<bits/stdc++.h>
#define pi 2*acos(0.0)
#define ll long long
#define FIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define Node struct node
#define spc " "
#define  E  2.71828182845904523536
#define pb push_back
#define pp pop_back
#define valid(nx,ny) nx>=0 && nx<n && ny>=0 && ny<m
#define ee endl
#define pii pair<int,int>
#define infinity 10000000000000000
#define mod 1000000007
int fx[]={0,0,+1,-1};
int fy[]={+1,-1,0,0};

using namespace std;
///check n=1;
///check corner case;
const int maX=1e5+1;
vector<ll>Graph[maX],cost[maX];
ll visit[maX];
ll x[10];
ll y[10];
double dist(ll i, ll j)
{
    double dx=x[i]-x[j];
    double dy=y[i]-y[j];
    return pow(dx*dx+dy*dy,0.5);
}

int main()
{
    ll n;cin>>n;
    cout<<pow(n,3)<<endl;
}


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

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input! {
        r: u32,
        d: u32,
        x: u32
    }
    let mut x = x;
    for _ in 0..10 {
        x = r * x - d;
        println!("{}", x);
    }
}


Measured memory_bytes: 4352
def validate(array)
  array.each do |x|
    if x < 1 || x > 10000
      raise 'out of range'
    end
  end
  if array[0] <= array[1]
    return array
  else
    raise 'a must be smaller than b'
  end
end

array = gets.split.map(&:to_i)
a, b, c = validate(array)
count = 0
(a..b).each do |x|
  if c % x == 0
    count += 1
  end
end
p count

Measured memory_bytes: 8692
#include <stdio.h>
#include <iostream>
#include <math.h>
#include <string>
#include <vector>
#include <algorithm>
#include <iomanip>

//#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define ll long long
#define pb push_back

int main() {
  int a, b;
  cin >> a >> b;

  if (a < 9 && b < 9) cout << "Yay!" << endl;
  else cout << ":(" << endl;
  
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
  int x,y,r,num;
  scanf("%d %d",&x,&y);
  if(x<y){
    r=x;
    x=y;
    y=r;
  }
  while((num=x%y)!=0){
    x=y;
    y=num;
  }
  printf("%d\n",y);
  return 0;
}

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

int main() {
  int n,m;
  cin >> n;
  m=n/2;
  vector<int>d(n);
  rep(i,n) cin>> d.at(i);
  sort(d.begin(),d.end());
  cout << d.at(m)-d.at(m-1) << endl; 
}


Measured memory_bytes: 640
#include<cstdio>
#include<cstring>
#include<string>
#include<iostream>
#include<cstdlib>
#include<set>
#include<algorithm>
#include<functional>
using namespace std;
long long x, y, a, b, c, qx[100005], qy[100005], qz[100005], t[200005];
inline void readAndSort(long long* arr, long long num) {
	for (int i = 0; i < num; i++) {
		scanf("%lld", arr + i);
	}
	sort(arr, arr + num, greater<long long>());
}
int main() {
	scanf("%lld%lld%lld%lld%lld", &x, &y, &a, &b, &c);
	readAndSort(qx, a);
	readAndSort(qy, b);
	readAndSort(qz, c);
	int j, px, py;
	j = px = py = 0;
	while (px < x && py < y) {
		if (qx[px] > qy[py]) {
			t[j] = qx[px];
			px++;
		}
		else {
			t[j] = qy[py];
			py++;
		}
		j++;
	}
	while (px < x) {
		t[j] = qx[px];
		j++;
		px++;
	}
	while (py < y) {
		t[j] = qy[py];
		j++;
		py++;
	}
	for (int i = 0; i < c; i++) {
		if (qz[i] > t[j - i - 1]) {
			t[j - i - 1] = qz[i];
		}
		else {
			break;
		}
	}
	long long sum = 0;
	for (int i = 0; i < j; i++) {
		sum += t[i];
	}
	printf("%lld\n", sum);
	return 0;
}

Measured memory_bytes: 7484
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <map>
#include <set>
#include <algorithm>
#include <ctime>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {0,1,0,-1,1,-1,1,-1};
ll dx[8] = {1,0,-1,0,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	int n; cin >> n;
	vector<int> V(n+1),W(n+1);
	rep(i,n) cin >> V[i+1] >> W[i+1];
	int M = 1<<12;
	vector<vector<pair<int,int>>> vp(M+1);
	vp[0].emplace_back(0,0);
	REP(i,1,M+1){
		if(i > n) break;
		vector<pair<int,int>> vv;
		for(auto b : vp[i/2]){
			vv.emplace_back(b);
			vv.emplace_back(b.first+W[i], b.second+V[i]);
		}
		sort(all(vv));
		int now = -1;
		for(auto b : vv){
			if(now < b.second){
				vp[i].push_back(b);
				now = b.second;
			}
		}
	}
	int q; cin >> q;
	while(q--){
		int v,L; scanf("%d%d",&v,&L);
		vector<pair<int,int>> acc;
		acc.emplace_back(0,0);
		while(v > M){
			vector<pair<int,int>> tmp;
			for(auto b : acc){
				tmp.emplace_back(b);
				tmp.emplace_back(b.first+W[v], b.second+V[v]);
			}
			acc = tmp;
			v >>= 1;
		}
		int ans = 0;
		for(auto b : acc){
			pair<int,int> pp = {L-b.first, inf};
			auto itr = lower_bound(all(vp[v]), pp);
			if(itr != vp[v].begin()){
				itr--;
				chmax(ans, (*itr).second + b.second);
			}
		}
		cout << ans << "\n";
	}
}

Measured memory_bytes: 88268
#include<cstdio>
#include<algorithm>
using namespace std;
int main(void)
{
	int n,m,p,d[10001],i,MIN=1000000001;
	scanf("%d %d %d",&n,&m,&p);
	for(i=1;i<=m;i++){
		scanf("%d",&d[i]);
		if(d[i]-p<0){
			d[i]=n+(d[i]-p);
		}
		else{
			d[i]=d[i]-p;
		}
	}
	sort(d,d+m+1);
	d[0]=0;
	for(i=0;i<=m;i++){
		if(i==m){
			MIN=min(d[i]*100,MIN);
		}
		else{
			MIN=min(d[i]*100*2+(n-d[i+1])*100,MIN);
		}
	}
	for(i=m;i>=0;i--){
		if(i==0){
			MIN=min((n-d[0])*100,MIN);
		}
		else{
			MIN=min((n-d[i])*100*2+d[i-1]*100,MIN);
		}
	}
	printf("%d\n",MIN);
	return 0;
}


Measured memory_bytes: 2828
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define agewari(a, b) ((ll)a + ((ll)b - 1)) / b
const int MOD = 1000000007;
const long long INF = 1LL << 60;
using Graph = vector<vector<ll>>;

int main()
{
    ll n, k, s;
    cin >> n >> k >> s;
    if(s<(ll)pow(10,9)){
        rep(i, k) cout << s << " ";
        rep(i, n - k) cout << s + 1 << " ";
        cout << endl;
    }else{
        rep(i,k)cout<<s<<" ";
        rep(i, n - k) cout << 1 << " ";
        cout << endl;
    }
}

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

int dp[105][10005], v[105], n;

int solve(int pos, int sum){
    if(pos == n) return (sum%10 == 0 ? 0 : sum);
    if(dp[pos][sum] != -1) return dp[pos][sum];
    return dp[pos][sum] = max(solve(pos+1, sum+v[pos]), solve(pos+1, sum));
}

int main(){
    memset(dp, -1, sizeof dp);
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> v[i];
    cout << solve(0,0) << endl;
	return 0;
}


Measured memory_bytes: 4352
#include <bits/stdc++.h>
/*#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>
*/#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")    
using namespace std;
/*namespace mp = boost::multiprecision;
using Bint = mp::cpp_int;
using Real = mp::number<mp::cpp_dec_float<1024>>;
*/
#define ll long long
#define INF 999999999999
#define rep(i,m,n) for(ll i = m;i < n;i++)
#define rrep(i,m,n) for(ll i=m-1;i>=n;i--)
#define pb(n) push_back(n)
#define UE(N) N.erase(unique(N.begin(),N.end()),N.end());
#define Sort(n) sort(n.begin(), n.end())
#define Rev(n) reverse(n.begin(),n.end())
#define Out(S) cout << S << endl
#define NeOut(S) cout << S
#define HpOut(S) cout << setprecision(50) << S << endl
#define Vec(K,L,N,S) vector<L> K(N,S)
#define DV(K,L,N,M,S) vector<vector<L>> K(N,vector<L>(M,S))
#define TV(K,L,N,M,R,S) vector<vector<vector<L>>> K(N,vector<vector<L>>(M,vector<L>(R,S)))
#define pint pair<lli,lli>
#define paf(L,R) pair<L,R>
#define mod 1000000007
#define MAX 10000000
#define ALL(a)  a.begin(),a.end()
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
vector<ll> A, ans, dp;
vector<bool> isSeen;
vector<vector<ll>> G;
void dfs(int v) {
	ll old, num;
	if(!v) {
		old = 0;
		num = INF;
		dp[0] = A[0];
		ans[0] = 0;
	} else {
		int ok = -1, ng = A.size();
	  	while(ng - ok > 1) {
		  	int mid = (ok + ng) / 2;
		  	if(dp[mid] < A[v]) ok = mid;
		  	else ng = mid;
	  	}
		old = ok + 1;
		num = dp[old];
	  	dp[ok + 1] = A[v];
		ok = -1, ng = A.size();
	  	while(ng - ok > 1) {
		  	int mid = (ok + ng) / 2;
		  	if(dp[mid] < INF) ok = mid;
		  	else ng = mid;
	  	}
		ans[v] = ok;
	}
	isSeen[v] = true;
	for(auto nv: G[v]) if(!isSeen[nv]) dfs(nv);
	dp[old] = num;
}
int main() {
  	ios::sync_with_stdio(false);
  	cin.tie(0);
	ll N, L, R;
	cin >> N;
  	A.resize(N);
  	G.resize(N);
  	ans.resize(N);
  	isSeen.resize(N);
  	dp.resize(N,INF);
  	rep(i, 0, N) cin >> A[i];
  	rep(i, 0, N - 1) {
		cin >> L >> R;
	  	G[L - 1].pb(R - 1);
	  	G[R - 1].pb(L - 1);
	  }
  	dfs(0);
  	rep(i, 0, N) cout << ans[i] + 1 << endl;
}


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

#define LL long long
#define N 110

using namespace std;

deque<int> ans1,ans2;
int modify[N],tot;

void solve(LL n)
{
	if(n==1) return;
	if((n-1)%2==0)
	{
		modify[++tot] = 1;
		solve((n-1)/2);
	}
	else
	{
		modify[++tot]=2;
		solve(n-1);
	}
}

int main()
{
	LL n;
	cin>>n;
	int tim=1;
	solve(n);
	ans1.push_back(1);
	for(int i=tot;i>=1;i--)
	{
		if(modify[i]==1) ans1.push_back(++tim);
		else ans1.push_front(++tim);
	}
	cout<<2*(int)ans1.size()<<endl;
	for(int i=0;i<(int)ans1.size();i++) printf("%d ",ans1[i]);
	for(int i=0;i<(int)ans1.size();i++) printf("%d%c",i+1,i==((int)ans1.size())-1? '\n':' ');
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    static int INF = 1001001009;
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int h = sc.nextInt();
        int w = sc.nextInt();
        int k = sc.nextInt();
        
        int sx = sc.nextInt() - 1;
        int sy = sc.nextInt() - 1;
        int gx = sc.nextInt() - 1;
        int gy = sc.nextInt() - 1;
        
        // board[i][j]: 迷路
        char[][] board = new char[h][w];
        for (int i = 0; i < h; i++) {
            String str = sc.next();
            for (int j = 0; j < w; j++) {
                board[i][j] = str.charAt(j);
            }
        }
        
        int[][] dist = new int[h][w];
        for (int[] d : dist) {
            Arrays.fill(d, INF);
        }
        
        // 上下左右
        int[] dx = new int[]{1, 0, -1, 0};
        int[] dy = new int[]{0, 1, 0, -1};
        
        // steps = BFS((0, 0)→(h, w)までの最短経路の深さ)
        int steps = -1;
        Queue<int[]> que = new ArrayDeque<int[]>();
        que.add(new int[]{sx, sy, 0});
        while (!que.isEmpty()) {
            int[] cur = que.poll();
            int x = cur[0];
            int y = cur[1];
            int depth = cur[2];
            
            // 移動可能ならそのマスに深さ+1を配ってキューに入れる
            for (int i = 0; i < 4; i++) {
                for (int j = 1; j <= k; j++) {
                    int nx = x + dx[i] * j;
                    int ny = y + dy[i] * j;
                    int ndepth = depth + 1;
                    
                    // System.out.println(nx + " " + ny + " " + ndepth);
                    
                    if (!(0 <= nx && nx < h && 0 <= ny && ny < w)) break;
                    if (board[nx][ny] != '.') break;
                    if (dist[nx][ny] < ndepth) break;
                    if (dist[nx][ny] == INF) {
                        que.add(new int[]{nx, ny, ndepth});
                    }
                    dist[nx][ny] = ndepth;
                    
                    if (nx == gx && ny == gy) {
                        System.out.println(ndepth);
                        return;
                    }
                }
            }
        }
        
        if (dist[gx][gy] == INF) {
            dist[gx][gy] = -1;
        }
        System.out.println(dist[gx][gy]);
    }
}

Measured memory_bytes: 63244
#include <bits/stdc++.h>
#define err(args...) {}
#ifdef DEBUG
#include "_debug.cpp"
#endif
using namespace std;
using ll = long long;
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    string s;
    cin >> s;
    ll ans = 0;
    for(int mask = 0; mask < 1 << (s.size() - 1); mask++) {
        ll cur = s[0] - '0';
        for(int i = 0; i < (s.size() - 1); i++) {
            if(mask & (1 << i)) {
                ans += cur;
                cur = s[i+1] - '0';
            } else {
                cur *= 10;
                cur += s[i+1] - '0';
            }
        }
        ans += cur;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define fr(i,j,k) for(int i=j;i<k;i++)
#define f(n) fr(i,0,n)
#define f1(n) fr(i,1,n+1)
#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
const int mod = 1e9 + 7;
const int maxn = 2000005;

void solve() {
    string s, t;
    cin >> s >> t;
    int n = s.size();
    int ret = 0;
    f(n) {
        if (s[i] != t[i]) {
            ret++;
        }
    }
    cout << ret << '\n';
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int c = 0;
    int t;
    if (!c) {
        t = 1;
    }
    else {
        cin >> t;
    }
    while (t--) {
        solve();
    }
}

Measured memory_bytes: 3732
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <map>
using namespace std;

int main(void)
{
    long long n, k;
    cin >> n >> k;

    long long ans = 0;
    for (long long i = k; i <= n+1; i++)
    {
        long long max = (2 * n - i + 1)*i/2;
        //If i is int, the result of (i-1)*i becomes int and the value will be messed up 
        long long min = (i-1)*i/2;
        long long tmp = max - min + 1;
        ans = (ans + tmp) % 1000000007;
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll MOD=1000000007;
const double PI=3.14159265358979;
const ll INF= pow(10,18);
typedef pair<ll,ll> P;
typedef vector<ll> vl;
typedef vector<vl> vvl;
#define FOR(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) FOR(i,0,n)
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
  
int main() {
  ll n,m,x,y;
  cin >> n >> m >> x >> y;
  vl a(n+1),b(m+1);
  rep(i,n){
    cin >> a[i];
  }
  a[n]=x;
  rep(i,m){
    cin >> b[i];
  }
  b[m]=y;
  sort(a.begin(),a.end());
  sort(b.begin(),b.end());
  if(a[n]<b[0])
    cout << "No War" << endl;
  else
    cout << "War" << endl;
}

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

int main(){
	while(1){
		int n, m;
		int taro=0, hanako=0;
		int t[100], h[100];
		
		scanf(" %d %d", &n ,&m);
		if(n==0 && m==0) break;
		for(int i=0; i<n; ++i){
			scanf(" %d", &t[i]);
			taro+=t[i];
		}
		for(int i=0; i<m; ++i){
			scanf(" %d", &h[i]);
			hanako+=h[i];
		}	
		
		bool flag=false;
		
		int a, b;
		for(int i=0; i<n; ++i){
			for(int j=0; j<m; ++j){
				if(taro-t[i]+h[j] == hanako-h[j]+t[i]){
					flag=true;
					a=i;
					b=j;
					break;	
				}
			}
			if(flag) break;
		}
		
		if(flag) printf("%d %d\n", t[a], h[b]);
		else printf("-1\n");
	}
	return 0;
}

Measured memory_bytes: 1196
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
//l={1,2,3,4}
//greater<int>()
//sort(l,l+n)

int main(void)
{
	int n, a;
	cin >> n >> a;
	n %= 500;

	if (n <= a)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

}

Measured memory_bytes: 256
def main():
    N = input()
    tmp = int(N[0])
    if int(N[1]) > tmp:
        print("{}{}{}".format(tmp+1, tmp+1, tmp+1))
    elif int(N[1]) < tmp:
        print("{}{}{}".format(tmp, tmp, tmp))
    else:
        if int(N[2]) > tmp:
            print("{}{}{}".format(tmp+1, tmp+1, tmp+1))
        elif int(N[2]) <= tmp:
            print("{}{}{}".format(tmp, tmp, tmp))

if __name__ == "__main__":
    main()

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define x first
#define y second
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll MAX=100005;
const ll INF=0x3f3f3f3f3f3f3f;
const ll MOD=1000000007;
ll n,l[MAX],r[MAX],p[MAX],q[MAX],ladd,radd,ans;
priority_queue<ll> lg,rg;
int main(){
    scanf("%lld",&n);
    for(ll i=0;i<n;i++) scanf("%lld%lld",&l[i],&r[i]);
    for(ll i=0;i<n-1;i++) p[i]=l[i]-r[i+1],q[i]=r[i]-l[i+1];
    lg.push(-INF),lg.push(0),rg.push(0),rg.push(-INF);
    for(ll i=0;i<n-1;i++){
        ladd+=p[i],radd+=q[i];
        if(lg.top()+ladd>0) {
            ans+=abs(lg.top()+ladd);
            lg.push(-ladd),lg.push(-ladd);
        }
        else if(-rg.top()+radd<0) {
            ans+=abs(-rg.top()+radd);
            rg.push(radd),rg.push(radd);
        }
        else lg.push(-ladd),rg.push(radd);
        if(lg.size()>rg.size()) {
            ll val=lg.top()+ladd;
            rg.push(-val+radd),lg.pop();
        }
        else if(rg.size()>lg.size()) {
            ll val=-rg.top()+radd;
            lg.push(val-ladd),rg.pop();
        }
    }
    printf("%lld\n",ans);
}


Measured memory_bytes: 5228
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

template <class T> inline T chmax(T &a, const T b) {return a = (a < b) ? b : a;}
template <class T> inline T chmin(T &a, const T b) {return a = (a > b) ? b : a;}

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;
constexpr double pi = acos(-1);
constexpr double EPS = 1e-10;

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

const int MAX_N = 2000010;

ll modpow(ll a, ll b){
    if(b == 0) return 1;
    else if(b % 2 == 0){
        ll d = modpow(a, b/2) % MOD;
        return (d * d) % MOD;
    }
    else{
        return (a * modpow(a, b-1)) % MOD;
    }
}

ll fact[MAX_N], finv[MAX_N];
ll comb(int n, int r){
    if(n < r || r < 0) return 0;
    return fact[n] * finv[n-r] % MOD * finv[r] % MOD;
}

void calc(int n){
    fact[0] = finv[0] = 1;
    for(int i=1; i<=n; i++){
        fact[i] = (fact[i-1] * i) % MOD;
        finv[i] = modpow(fact[i], MOD-2);
    }
}

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

    int r1, c1, r2, c2; cin>>r1>>c1>>r2>>c2;

    calc(2000005);

    ll all = 0;
    for(int i=1; i<=r2+1; i++){
        all += comb(i + c2, c2);
        all %= MOD;
    }

    for(int i=1; i<=r2+1; i++){
        all -= comb(i + c1 - 1, c1 - 1);
        all += MOD;
        all %= MOD;
    }

    for(int i=1; i<=r1; i++){
        all -= comb(i + c2, c2);
        all += MOD;
        all %= MOD;
    }

    for(int i=1; i<=r1; i++){
        all += comb(i + c1 - 1, c1 - 1);
        all += MOD;
        all %= MOD;
    }

    cout << all << endl;

    return 0;
}

Measured memory_bytes: 31488
#include <iostream>
#include <string>
#include <algorithm>
#include <stdlib.h>
#include <iomanip>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
//typedef long long unsigned int ll;
typedef long long ll;
typedef pair<ll, ll> edge;
typedef tuple<ll, ll, ll> tp;

int main() {
  string s;
  cin >> s;
  int n = s.length();
  ll p[n];
  ll v[n];
  fill(v, v+n, 0);
  char c = 'R';
  int count = 0;
  int counth = 0;
  int pn = 0;
  for (int i=0; i<n; i++){
    //cout << i << count << endl;
    if(s[i] != c && s[i] == 'L'){
      c = 'L';
      counth = count;
      count += 1;
      pn = i;
    }
    else if(s[i] != c && s[i] == 'R'){
      if (count%2 == 0){
        v[pn-1] = count/2;
        v[pn] = count/2;
      }
      else{
        if ((2*counth)%4 == 0){
          v[pn-1] = (count-1)/2;
          v[pn] = (count+1)/2;
        }
        else{
          v[pn-1] = (count+1)/2;
          v[pn] = (count-1)/2;
        }
      }
      c = 'R';
      count = 1;
    }
    else count += 1;
  }
  
  
  if (count%2 == 0){
    v[pn-1] = count/2;
    v[pn] = count/2;
  }
  else{
    if ((2*counth)%4 == 0){
      v[pn-1] = (count-1)/2;
      v[pn] = (count+1)/2;
    }
    else{
      v[pn-1] = (count+1)/2;
      v[pn] = (count-1)/2;
    }
  }
  
  for (int i=0; i<n; i++) cout << v[i] << ' ';
  cout << endl;
}

Measured memory_bytes: 1408
n=int(input())
a=[int(input()) for i in range(n)]
a.sort()
k=1
count=0
for i in range(1,n):
    if a[i]==a[i-1]:
        k+=1
    else:
        if k%2==1:
            count+=1
        k=1
if k%2==1:
    count+=1
print(count)

Measured memory_bytes: 50264