akhauriyash/Code-Regression huggingface dataset:
use io::*;
use std::*;

const YES: &'static str = "Yes";
const NO: &'static str = "No";
fn solve(N: i64, K: i64, A: Vec<i64>) {
    for w in A.windows(K as usize + 1) {
        if w[0] < w[w.len()-1] {
            println!("{}", YES);
        } else {
            println!("{}", NO);
        }
    }
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
fn main() {
    let con = read_string();
    let mut scanner = Scanner::new(&con);
    let mut N: i64;
    N = scanner.next();
    let mut K: i64;
    K = scanner.next();
    let mut A: Vec<i64> = vec![0i64; (N) as usize];
    for i in 0..(N) as usize {
        A[i] = scanner.next();
    }
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(move || solve(N, K, A)).unwrap().join().unwrap();
}

pub mod io {
    use std;
    use std::str::FromStr;

    pub struct Scanner<'a> {
        iter: std::str::SplitWhitespace<'a>,
    }

    impl<'a> Scanner<'a> {
        pub fn new(s: &'a str) -> Scanner<'a> {
            Scanner {
                iter: s.split_whitespace(),
            }
        }

        pub fn next<T: FromStr>(&mut self) -> T {
            let s = self.iter.next().unwrap();
            if let Ok(v) = s.parse::<T>() {
                v
            } else {
                panic!("Parse error")
            }
        }

        pub fn next_vec_len<T: FromStr>(&mut self) -> Vec<T> {
            let n: usize = self.next();
            self.next_vec(n)
        }

        pub fn next_vec<T: FromStr>(&mut self, n: usize) -> Vec<T> {
            (0..n).map(|_| self.next()).collect()
        }
    }

    pub fn read_string() -> String {
        use std::io::Read;

        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }

    pub fn read_line() -> String {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        s.trim_right().to_owned()
    }
}


Measured memory_bytes: 5736
#include<cstdio>
#include<algorithm>
#define REP(i,s,n) for(int i=s;i<n;i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

int main(){
  int N;
  scanf("%d",&N);
  int C[N+1][N+1];

  rep(i,N)
      rep(j,N)
    scanf("%d",&C[i][j]);

  long long cost = 0;
  rep(i,N)
    {
      for(int j=i+1;j<N;j++)
	{
	  cost += min((int)C[i][j],(int)C[j][i]);
	}
    }    

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

return 0;
}

Measured memory_bytes: 1068
#include <iostream>
#include <string>
int main() {
  std::string s;
  std::cin >>s;
  std::string sep[] = {"dream", "dreamer", "erase", "eraser"};
  int dp[100100] = {};
  dp[0] = 1;
  for(int i=0;i < s.size(); ++i) {
    if(dp[i]) {
      for(std::string t : sep)(s.substr(i,t.size())==t?dp[i+t.size()]=1:0);
    }
  }
  std::cout << (dp[s.size()]?"YES":"NO") << "\n";
}

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

# import numpy as np
# from itertools import *
# from collections import *

# S = input().split()
# N = int(input().split())
# K, N = [int(x) for x in input().split()]

A, B, C, D = [int(x) for x in input().split()]

while True:
    C -= B
    if C <= 0:
        print("Yes")
        break

    A -= D
    if A <= 0:
        print("No")
        break




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

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

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

#define INF 1e16

ll n;
string s;
ll dp[1000011][10];

ll calc(ll m){
//  return min((m+4)/5+(((m+4)/5)*5-m),m/5+m%5);
  return min((m+9)/10+(((m+9)/10)*10-m),m/10+m%10);
}

int main(){
	cin>>s;
  s="0"+s;
  n=s.size();
  rep(i,1000011)rep(j,10)dp[i][j]=INF;
  dp[0][0]=0;
  rep(i,n)rep(j,10){
    if(dp[i][j]==INF)continue;
    rep(k,10){
      ll r=j*10-(s[i]-'0')-k;
      if(r>0){
        minch(dp[i+1][k],dp[i][j]+calc(r));
      }else{
        r=-r;
        minch(dp[i+1][k],dp[i][j]+calc(r));
      }
    }
  }
  cout<<dp[n][0]<<endl;
	return 0;
}


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

using namespace std;

#define uint unsigned int
#define llong long long int
#define ullong unsigned long long int
#define rep(i, n) for (int i = 0; i < n; ++i)

const static long long int MOD = 1000000000 + 7;
const static int dy[] = {0, 1, 0, -1};
const static int dx[] = {1, 0, -1, 0};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin >> s;
    if (s == "KIHBR"
        || s == "KIHBRA"
        || s == "KIHBAR"
        || s == "KIHBARA"
        || s == "KIHABR"
        || s == "KIHABRA"
        || s == "KIHABAR"
        || s == "KIHABARA"
        || s == "AKIHBR"
        || s == "AKIHBRA"
        || s == "AKIHBAR"
        || s == "AKIHBARA"
        || s == "AKIHABR"
        || s == "AKIHABRA"
        || s == "AKIHABAR"
        || s == "AKIHABARA") {
            cout << "YES" << endl;
        } else {
            cout << "NO" << endl;
        }

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define ll long long
#define pp pair<ll,ll>
#define ld long double
#define all(a) (a).begin(),(a).end()
#define mk make_pair
ll mod=998244353;
int inf=1000001000;
ll INF=1e18+5;
ll MOD=INF;

int Pow(int b, int e) {
  if (e < 0) e += MOD - 1;
  int ret = 1;
  while (e) {
    if (e & 1) ret = 1LL * ret * b % MOD;
    b = 1LL * b * b % MOD;
    e >>= 1;
  }
  return ret;
}
 
int main() {
    ll x;
    cin >> x;
    for (ll i=1;i<inf;i++){
        for (ll j=0;j<=i;j++){
            if (Pow(i,5)-Pow(j,5)==x){
                cout << i << " " << j << endl;
                return 0;
            }
            if (Pow(i,5)+Pow(j,5)==x){
                cout << i << " " << -j << endl;
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3676
use std::io::*;

const SP: u8 = b' ';
const LF: u8 = b'\n';

struct CharacterInput<'a> {
    locked_stdin: StdinLock<'a>,
    bytes_buffer: Vec<u8>,
}

impl<'a> CharacterInput<'a> {
    fn read(&mut self, delimiter: u8) -> &[u8] {
        self.bytes_buffer.clear();

        let len = self
            .locked_stdin
            .read_until(delimiter, &mut self.bytes_buffer)
            .unwrap();

        let end_index = match self.bytes_buffer.last() {
            Some(byte) => {
                if *byte == delimiter {
                    len - 1
                } else {
                    len
                }
            }
            None => len,
        };

        &self.bytes_buffer[0..end_index]
    }

    fn scan_u(&mut self, delimiter: u8) -> u32 {
        self.read(delimiter)
            .into_iter()
            .fold(0, |accumulator, byte| {
                (byte - b'0') as u32 + accumulator * 10
            })
    }

    fn scan_u_vec(&mut self, n: usize, separator: u8, delimiter: u8) -> Vec<u32> {
        let mut vector = Vec::with_capacity(n as usize);
        for _i in 0..n - 1 {
            vector.push(self.scan_u(separator));
        }
        vector.push(self.scan_u(delimiter));
        vector
    }
}

fn create_cin<'a>(input: StdinLock<'a>, buffer_capacity: usize) -> CharacterInput {
    CharacterInput {
        locked_stdin: input,
        bytes_buffer: Vec::with_capacity(buffer_capacity),
    }
}

fn println<T: std::string::ToString>(s: T) {
    println!("{}", s.to_string());
}

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

fn count_smaller_numbers(slice: &[u32], max_value: u32) -> usize {
    slice.iter().filter(|&&v| v < max_value).count()
}

fn safe_add(a: usize, b: usize) -> usize {
    (a + b) % 1000000007
}

fn safe_mult(base_value: usize, repetition: usize) -> usize {
    (0..repetition).fold(0, |acc, _| safe_add(acc, base_value))
}

fn main() {
    let cin = stdin();
    let cin = &mut create_cin(cin.lock(), 64);

    let n = cin.scan_u(SP) as usize;
    let k = cin.scan_u(LF) as usize;
    let a = cin.scan_u_vec(n, SP, LF);

    let k_triangular = k * (k + 1) / 2;
    let k_minus_one_triangular = (k - 1) * k / 2;
    let count: usize = (0..n).fold(0, |acc, i| {
        let current_value = a[i];
        let former_count = count_smaller_numbers(&a[0..i], current_value);
        let latter_count = count_smaller_numbers(&a[i + 1..n], current_value);
        let count_to_add = safe_add(
            safe_mult(k_minus_one_triangular, former_count),
            safe_mult(k_triangular, latter_count),
        );
        safe_add(acc, count_to_add)
    });

    println(count);
}


Measured memory_bytes: 4352
#include <iostream>
#include <algorithm>
using namespace std;
typedef long long ll;
int D[32][32];
ll s[3][32];
int main( void )
{
  ios::sync_with_stdio(false);
  int N, C;
  cin >> N >> C;
  for( int i=1; i<=C; i++ ){
    for( int j=1; j<=C; j++ ){
      cin >> D[i][j];
    }
  }
  for( int i=1; i<=N; i++ ){
    for( int j=1; j<=N; j++ ){
      int idx = (i+j) % 3;
      int c;
      cin >> c;
      for( int k=1; k<=C; k++ ){
        s[idx][k] += D[c][k];
      }
    }
  }
  ll ret = 1LL << 50;
  for( int i=1; i<=C; i++ ){
    for( int j=1; j<=C; j++ ){
      if( i == j ) continue;
      for( int k=1; k<=C; k++ ){
        if( i == k ) continue;
        if( j == k ) continue;
        ll r = s[0][i] + s[1][j] + s[2][k];
        ret = min( ret, r );
      }
    }
  }
  cout << ret << endl;
}

Measured memory_bytes: 256
#!/usr/bin/env python3
N = int(input())

def query(x):
    print(x, flush=True)
    res = input()
    if res == 'Vacant':
        exit()
    return res

l, r = 0, N - 1
ql = query(l)
qr = query(r)
while True:
    m = (l + r) // 2
    qm = query(m)
    if (qm == ql) == (m % 2 == l % 2):
        l = m
        ql = qm
    else:
        r = m


Measured memory_bytes: 3660
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
#include <vector>
#include <utility>
#define ms(a,b) memset(a,b,sizeof(a))
using namespace std;
typedef long long ll;
typedef pair<int,int> PII;
const int mod = 998244353;
const int inf = 1 << 30;
const int maxn = 100000 + 5;

int a, b, c;

int main() {
    cin >>a >> b >> c;
    if (a == b && b == c) puts("Yes");
    else puts("No");
    return 0;
}

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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
#define rirep(i, x) for (auto i = (x).rbegin(); i != (x).rend(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1LL << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class A, class B>
bool chmax(A &a, const B &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class A, class B>
bool chmin(A &a, const B &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

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

  int n;
  cin >> n;
  int k;
  cin >> k;
  vector<int> x(n);
  int ans = 0;
  arep(i, x) {
    cin >> i;
    ans += min(2 * i, 2 * (k - i));
  }
  cout << ans << '\n';
  return 0;
}

Measured memory_bytes: 3620
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	r := bufio.NewReader(os.Stdin)
	var x, y int
	fmt.Fscan(r, &x)
	fmt.Fscan(r, &y)

	mod := 1000000007

	if (x+y)%3 != 0 {
		fmt.Println(0)
		return
	}

	n := (x + y) / 3
	x -= n
	y -= n
	if x < 0 || y < 0 {
		fmt.Println(0)
		return
	}

	ans := modcomb(x+y, x, mod)
	fmt.Println(ans)

	/* DPで行けるのかと思って書いたもの
	dp := make([][]int, 3)
	for i := 0; i < 3; i++ {
		dp[i] = make([]int, y+1)
	}
	dp[0][0] = 1
	dp[1][2] = 1

	for i := 2; i < x+1; i++ {
		for j := 0; j < y+1; j++ {
			// (i+1,j+2)
			if j-2 >= 0 {
				dp[2][j] += dp[1][j-2]
				dp[2][j] %= mod
			}
			// (i+2,j+1)
			if j-1 >= 0 {
				dp[2][j] += dp[0][j-1]
				dp[2][j] %= mod
			}
		}

		dp[0] = dp[1]
		dp[1] = dp[2]
		dp[2] = make([]int, y+1)
	}

	fmt.Println(dp[1][y])
	*/
}

// Utility

func modpow(a, n, mod int) int {
	res := 1
	for n > 0 {
		if n%2 != 0 {
			res = res * a % mod
		}
		a = a * a % mod
		n = n / 2
	}
	return res
}

func modcomb(n, a, mod int) int {
	x := 1
	y := 1
	for i := 0; i < a; i++ {
		x = x * (n - i)
		x %= mod
		y = y * (i + 1)
		y %= mod
	}
	return x * modpow(y, mod-2, mod) % mod
}

func modfactorial(n, mod int) int {
	result := 1
	for i := 1; i <= n; i++ {
		result = (result * i) % mod
	}
	return result
}

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func max(x, y int) int {
	if x > y {
		return x
	}
	return y
}

func abs(x int) int {
	if x < 0 {
		return -x
	}
	return x
}

func primeFactor(x int) map[int]int {
	res := make(map[int]int)
	for i := 2; i*i <= x; i++ {
		for x%i == 0 {
			res[i]++
			x = x / i
		}
	}
	if x != 1 {
		res[x] = 1
	}
	return res
}

func divisor(x int) []int {
	res := make([]int, 0)
	for i := 1; i*i <= x; i++ {
		if x%i == 0 {
			res = append(res, i)
			if i != x/i {
				res = append(res, x/i)
			}
		}
	}
	return res
}

func gcd(x, y int) int {
	if y == 0 {
		return x
	}
	return gcd(y, x%y)
}

func lcm(x, y int) int {
	return x / gcd(x, y) * y
}


Measured memory_bytes: 640
#include <stdio.h>

int main(void)
{
	char cups[4] = {0};
	char swap_a, swap_b;
	int i;
	
	cups[0] = 1;
	
	while (scanf(" %c,%c", &swap_a, &swap_b) != EOF){
		if (cups[swap_a - 'A'] == 1){
			cups[swap_b - 'A'] = 1;
			cups[swap_a - 'A'] = 0;
			continue;
		}
		if (cups[swap_b - 'A'] == 1){
			cups[swap_a - 'A'] = 1;
			cups[swap_b - 'A'] = 0;
		}
	}
	
	for (i = 0; i < 4; i++){
		if (cups[i] == 1){
			 break;
		}
	}
	
	printf("%c\n", 'A' + i);
	
	return (0);
}

Measured memory_bytes: 540
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<n; i++)
#define PI 3.14159265359
#define INF 1000100100
#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
 

int main(){
  int n; cin >> n;
  vector<double> p(n);
  rep(i,n) cin >> p[i];
  double dp[(n/2)+1][n];
  dp[0][0]=p[0];
  rep(i,n-1) dp[0][i+1]=dp[0][i]*p[i+1];
    for(int i=1; i<=n/2; i++){
      rep(j,n){
        if(i>j+1) continue;
        if(i==1 && j==0){
          dp[i][j]=1-p[j];
          continue;
        }
        if(j+1!=i) dp[i][j]=dp[i][j-1]*p[j];
        dp[i][j]+=dp[i-1][j-1]*(1-p[j]);
    }
  }
  double ans=0;
  rep(i,(n/2)+1){
    ans+=dp[i][n-1];
  }
  printf("%.20lf",ans);
return 0;
}

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

int main()
{
    int x, y, z; cin >> x >> y >> z;
    int a = x,b = y,c = z;

    a = b;
    b = x;

    a = c;
    c = y;

    cout << a << " " << b << " " << c << endl;
}

Measured memory_bytes: 3552
#define _CRT_SECURE_NO_WARNINGS
#pragma comment(linker, "/STACK:108777216")
#define _FORTIFY_SOURCE 0
#pragma GCC optimize("Ofast")
#pragma GCC optimize("no-stack-protector")
#pragma GCC optimize("fast-math")
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <string>
#include <cmath>
#include <vector>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <utility>
#include <algorithm>
#include <ctime>
using namespace std;

int const MAX_N = 512 * 1024;

void my_gets(char * st) {
	int len = 0;
	char ch = getc(stdin);
	while (ch != '\n' && ch != '\r' && ch != 0 && !feof(stdin)) {
		st[len++] = ch;
		ch = getc(stdin);
	}
	st[len] = 0;
}

int main() {
	//freopen("input.txt", "r", stdin);
	//freopen("output.txt", "w", stdout);

	long long n, h, w;
	cin >> n >> h >> w;
	cout << ((n - h + 1)*(n - w + 1));
	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(){
  int n,a[100],temp,turn=0,i,j;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(i=0;i<n;i++){
    for(j=0;j<n-1;j++){
      if(a[j]>a[j+1]){
	temp=a[j];
	a[j]=a[j+1];
	a[j+1]=temp;
	turn++;
      }
    }
  }
  for(i=0;i<n;i++){
    printf("%d",a[i]);
    if(i!=n-1)printf(" ");
  }
  printf("\n%d\n",turn);
  return(0);
}

Measured memory_bytes: 604
#define _CRT_SECURE_NO_WARNINGS
#pragma GCC target("avx")
#pragma GCC optimize("O3")
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define rep(i,n) for(int i=0;i<(lint)(n);i++)
#define REP(i,n) for(int i=1;i<=(lint)(n);i++)
#define all(V) V.begin(),V.end()
#define stackReplaceBegin(size)\
	void* p=malloc(size);\
	esp_new=(lint)p+size-1;\
	void * stack_extend_memory_ = malloc(size);\
	void * stack_extend_origin_memory_;\
	char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);\
	*stack_extend_dummy_memory_ = 0;\
	asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
typedef long long lint;
typedef unsigned long long ulint;
typedef std::pair<int, int> P;
constexpr int INF = INT_MAX/2;
constexpr lint LINF = LLONG_MAX/2;
constexpr double eps = DBL_EPSILON;
constexpr double PI=3.141592653589793238462643383279;
lint esp_new;
template<class T>
class prique :public std::priority_queue<T, std::vector<T>, std::greater<T>> {};
template <class T, class U>
inline bool chmax(T& lhs, const U& rhs) {
	if (lhs < rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
template <class T, class U>
inline bool chmin(T& lhs, const U& rhs) {
	if (lhs > rhs) {
		lhs = rhs;
		return 1;
	}
	return 0;
}
inline lint gcd(lint a, lint b) {
	while (b) {
		lint c = a;
		a = b; b = c % b;
	}
	return a;
}
inline lint lcm(lint a, lint b) {
	return a / gcd(a, b) * b;
}
bool isprime(lint n) {
	if (n == 1)return false;
	for (int i = 2; i * i <= n; i++) {
		if (n % i == 0)return false;
	}
	return true;
}
template<typename T>
T mypow(T a, unsigned int b) {
	T res(1),now(a);
	while(b){
		if(b&1)res*=now;
		b>>=1;
		now*=now;
	}
	return res;
}
template<typename T>
void printArray(std::vector<T>& vec) {
	rep(i, vec.size() - 1)std::cout << vec[i] << " ";
	std::cout << vec.back() << std::endl;
}
template<typename T>
void printArray(T l, T r) {
	T rprev = r;
	rprev--;
	for (T i = l; i != rprev; i++) {
		std::cout << *i << " ";
	}
	std::cout << *rprev << std::endl;
}
int n,m,k;
lint a[200010],b[200010];
int main() {
	std::cin>>n>>m>>k;
	rep(i,n){
		std::cin>>a[i];
		if(i)a[i]+=a[i-1];
	}
	rep(i,m){
		std::cin>>b[i];
		if(i)b[i]+=b[i-1];
	}
	int c=m-1,ans=0;
	while(0<=c&&k<b[c])c--;
	chmax(ans,c+1);
	rep(i,n){
		while(0<=c&&k<a[i]+b[c])c--;
		if(a[i]<=k)chmax(ans,i+c+2);
	}
	std::cout<<ans<<std::endl;
	return 0;
}

Measured memory_bytes: 6716
n = int(input())
w = list(map(int, input().split()))

ans = 1000000000
for i in range(n - 1):
  a1 = sum(w[:i + 1])
  a2 = sum(w[i + 1:])
  ans = min(ans, abs(a1 - a2))
  
print(ans)



Measured memory_bytes: 2940
#include<stdio.h>
 
struct Card{
  char mark;
  int num;
};
 
typedef struct Card card;
 
int main(){
  int n,i,j,min,flag=0;
  card c1[36],c2[36],temp;
  char a;
 
  scanf("%d%c",&n,&a);
  for(i=0;i<n;i++){
    scanf("%c%d%c",&c1[i].mark,&c1[i].num,&a);
    c2[i]=c1[i];
  }
   
  for(i=0;i<n;i++){
    for(j=n-1;j>i;j--){
      if(c1[j].num < c1[j-1].num){
    temp=c1[j];
    c1[j]=c1[j-1];
    c1[j-1]=temp;
      }
    }
  }
 
     
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(c2[j].num < c2[min].num) min=j;
    }
    temp=c2[min];
    c2[min]=c2[i];
    c2[i]=temp;
  }
 
 
  for(i=0;i<n;i++){
    if(i==n-1) printf("%c%d\n",c1[i].mark,c1[i].num);
    else  printf("%c%d ",c1[i].mark,c1[i].num);
  }
  printf("Stable\n");
   
  for(i=0;i<n;i++){
    if(i==n-1) printf("%c%d\n",c2[i].mark,c2[i].num);
    else  printf("%c%d ",c2[i].mark,c2[i].num);
  }
   
  for(i=0;i<n;i++){
    if(c1[i].mark != c2[i].mark) flag=1;
  }
  if(flag==1)printf("Not stable\n");
  else printf("Stable\n");
   
  return 0;
}

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

using namespace std;
typedef long long int ll;

#define INF 100000

int main()
{
    int num[100001];
    for(int i = 0; i <= INF; i++) num[i] = 1;
    for(int i = 2; i <= sqrt(INF); i++)
    {
        for(int j = 1; i*(j+1) <= INF; j++)
        {
            if(num[i*(j+1)]) num[i*(j+1)] = 0;
        }
    }
    int ans[INF+1];
    ans[0] = 0;
    ans[1] = 0;
    ans[2] = 0;
    for(int i = 3; i <= INF; i++)
    {
        if(i % 2 && num[i] && num[(i+1)/2]) ans[i] = ans[i-1] +1;
        else ans[i] = ans[i-1];
    }
    int Q; cin >> Q;
    for(int i = 0; i < Q; i++)
    {
        int l,r; cin >> l >> r;
        cout << ans[r] - ans[l-1] << endl;
    }
}

Measured memory_bytes: 4340
s = list(input())
n = len(s)
ans = [1]*n
for i in range(n-1):
    if s[i] == s[i+1] == "R":
        ans[i+2] += ans[i]
        ans[i] = 0
for j in range(n-1,0,-1):
    if s[j] == s[j-1] == "L":
        ans[j-2] += ans[j]
        ans[j] = 0
print(' '.join([str(a) for a in ans]))


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

#define int long long

const int INF = 0x3f3f3f3f3f3f3f3f;
const int INITIAL = 1000000000000000LL;

struct edge {
	int v, w;
	bool operator>(const edge &other) const {
		return w > other.w;
	}
};

void dijkstra(int source, vector< vector<edge> > &adj, vector<int> &dist) {
	priority_queue<edge, vector<edge>, greater<edge> > pq;
	pq.push({source, 0});
	dist[source] = 0;
	while (pq.size()) {
		int u = pq.top().v;
		int w = pq.top().w;
		pq.pop();
		if (w > dist[u]) 
			continue;

		for (edge e: adj[u]) {
			if (w + e.w < dist[e.v]) {
				dist[e.v] = w+e.w;
				pq.push({e.v, w+e.w});
			}
		}
	}
}

signed main() {
	int N, M, S, T;
	cin >> N >> M >> S >> T;
	--S, --T;
	vector< vector<edge> > adj(N), inv(N);
	for (int i = 0; i < M; ++i) {
		int u, v, a, b;
		cin >> u >> v >> a >> b;
		--u, --v;
		adj[u].push_back({v, a});
		adj[v].push_back({u, a});
		inv[u].push_back({v, b});
		inv[v].push_back({u, b});
	}
	vector<int> distS(N, INF), distT(N, INF);
	dijkstra(S, adj, distS);
	dijkstra(T, inv, distT);
	int mn = INF;
	vector<int> outp;
	for (int i = N-1; i >= 0; --i) {
		mn = min(mn, distS[i]+distT[i]);
		outp.push_back(INITIAL-mn);
	}
	for (int i = N-1; i >= 0; --i) {
		cout << outp[i] << endl;
	}
}


Measured memory_bytes: 19964
import itertools
from scipy.sparse.csgraph import floyd_warshall

N, M, R = map(int, input().split())
r = tuple(map(int, input().split()))

INF = 10**10

d = [[INF] * N for _ in range(N)]

for i in range(N):
    d[i][i] = 0

for _ in range(M):
    a, b, c = map(int, input().split())
    a -= 1
    b -= 1
    if d[a][b] > c:
        d[a][b] = c
        d[b][a] = c


def warshall(d):
    for k in range(N):
        for i in range(N):
            for j in range(N):
                if d[i][j] > d[i][k] + d[k][j]:
                    d[i][j] = d[i][k] + d[k][j]


# d = floyd_warshall(d)
warshall(d)


ans = INF
for p in itertools.permutations(r):
    dist = 0
    for i in range(R-1):
        dist += d[p[i]-1][p[i+1]-1]

    if ans > dist:
        ans = dist

print(int(ans))

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

using namespace std;

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

#define each(i,a) for (auto&& i : a)
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
#define pb push_back
#define all(a) (a).begin(),(a).end()
#define chmin(x,v) x = min(x, v)
#define chmax(x,v) x = max(x, v)

const ll linf = 1e18;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    each(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& vec) {
    rep(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, const vector< vector<T> >& vec) {
    rep(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    string s; cin >> s;
    const ll n = s.size();
    set<ll> s0;
    ll ans = n;
    {
        string str = "0" + s + "0";
        rep(i, 1, str.size()) {
            // if (str[i-1] != str[i]) s0.insert(i);
            if (str[i-1] != str[i]) {
                chmin(ans, max(i, n+2-i)-1);
            }
        }
        // cout << vector<ll>(all(s0)) << endl;
    }
    cout << ans << endl;
    // assert(s0.size() % 2 == 0);
    // auto check = [&](ll K) {
    //     set<ll> S = s0;
    //     while ( S.size() > 0 ) {
    //         auto it = S.lower_bound(*S.begin() + K);
    //         if (it == S.end()) return false;
    //         S.erase(it);
    //         S.erase(S.begin());
    //     }
    //     return true;
    // };
    // ll lb = 0, ub = n+1;
    // rep(t, 30) {
    //     ll mid = (lb + ub) / 2;
    //     if ( check(mid) ) {
    //         lb = mid;
    //     }
    //     else {
    //         ub = mid;
    //     }
    // }
    // cout << lb << endl;
}


Measured memory_bytes: 512
#include <iostream>

using namespace std;

long long gcf (long long a, long long b)
{
    long long n,i=max(a,b),j=min(a,b);
    while (1)
    {
        n=i%j;
        if (n==0) break;
        i=j; j=n;
    }
    return j;
}

int main()
{
    long long a, b;
    cin>>a>>b;
    cout<<gcf(a, b)<<'\n';
    return 0;
}



Measured memory_bytes: 3100
#include <iostream>

int main() {
  int n, x;

  while (std::cin >> n >> x) {
    if (n==0&&x==0) break; 
    int count = 0;
    for (int i = 1; i <= n; i++) {
      for (int j = i + 1; j <= n; j++) {
        for (int k = j + 1; k <= n; k++) {
          if (i != j && j != k && k != i && i + j + k == x)
            count++;
        }
      }
    }
    std::cout << count << std::endl;
  }
}



Measured memory_bytes: 3104
#include <iostream>
#include <algorithm>
using namespace std;
int main()
{
	int x , y;
	cin >> x >> y;
	int a = x + y;
	int b = x - y;
	int c = x * y;
	int m = max (c , b);
	m = max (m , a);
	cout << m;
}

Measured memory_bytes: 256
D = int(input())
value = [0]*D
max = 0
total = 0

for i in range(D):
    value[i] = int(input())
    if(max < value[i]):
        max = value[i]

for i in range(D):
    total += value[i]
    
total -= (max/2)
print(int(total))

Measured memory_bytes: 3064
#include <iostream>
using namespace std;
int main(void){
  int i,t,s,r=10;
  for (i=0;i<5;i++){
    cin >> t;
    //ひとまず全て切り上げる
    s+=(t+9)/10;
    // if ステートメントの中で論理演算に使われる項は
    // 0以外の数値の場合true 0の場合falseと認識される．
    // ただし数値 && 数値の場合，ビット演算だと認識されるのでNG
    if (t%10 && r>t%10) r=t%10;
  }
  //切り上げを全て足し合わせたものを10倍する．
  //最後のオーダ（一桁目が最小）のみ１桁目を足せば良い
  cout << s*10-10+r << endl;
  return 0;
}



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

int abs(int a, int b) {
  if (a >= b) return a - b;
  else return b - a;
}

int main() {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  rep(i,n) cin >> h[i];
  vector<ll> d(n);
  rep(i, n-1) d[i+1] = pow(10, 9) + 5;
  d[0] = 0;
  rep(i,n-1) {
    for (int j = i; j >= max(0, i-k+1); j--) {
      int dtemp = d[j] + abs(h[j], h[i+1]);
      if (d[i+1] > dtemp) d[i+1] = dtemp;
    }
  }
  cout << d[n-1];
}


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

int main() {
  int h, w;
 cin >> h >> w;
  vector<string> vec(h);
for(int i=0;i<=w+1;i++){
  cout<<"#";
}
cout <<endl;
for(int i=0;i<h;i++){
  cin >> vec.at(i);
  cout << "#"<< vec.at(i)<<"#"<<endl;
}
for(int i=0;i<=w+1;i++){
  cout<<"#";
}
cout <<endl;
 
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int W,H;
    cin>>W>>H;
    
    vector<pii> nums(H+W);
    rep(i,W) cin>>nums[i].first,nums[i].second=0;
    rep(i,H) cin>>nums[i+W].first,nums[i+W].second=1;
    
    W++,H++;
    sort(all(nums));
    ll sum=0;
    for(auto p:nums){
        if(p.second) sum+=W*p.first,H--;
        else sum+=H*p.first,W--;
    }
    cout1(sum);
}

Measured memory_bytes: 1792
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <iomanip>
#include <limits>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <tuple>
#include <deque>
#include <algorithm>
#include <numeric>
#include <iomanip>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
const int MOD = 1000000007;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
//setprecision(15)有効数字15桁
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b)
{
    return a * b / gcd(a, b);
}
int n;
ll c;
vector<p> x;

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n>>c;
    for (int i = 0; i < n; i++)
    {
        ll tempx, tempv;
        cin >> tempx>>tempv;
        x.push_back(make_pair(tempx,tempv));
    }
    vector<ll> sumr, suml, sumbr, sumbl;
    sumr.push_back(0);
    suml.push_back(0);
    sumbr.push_back(0);
    sumbl.push_back(0);

    ll ans=0;
    for(int i=0;i<n;i++){
        sumr.push_back(sumr[i]+x[i].second);
        ans=max(ans,sumr[i+1]-x[i].first);
        sumbr.push_back(max(sumbr[i],sumr[i+1]-2*x[i].first));
    }
    //cout << ans << "\n";
    for(int i=0;i<n;i++){
        suml.push_back(suml[i]+x[n-1-i].second);
        ans=max(ans,suml[i+1]-(c-x[n-1-i].first));
        sumbl.push_back(max(sumbl[i],suml[i+1]-2*(c-x[n-1-i].first)));
    }
    //cout << ans << "\n";
    for(int i=1;i<n;i++){
        ans=max(ans,sumr[i]-x[i-1].first+sumbl[n-i]);
    }
    //cout << ans << "\n";
    for(int i=1;i<n;i++){
        //cout<<suml[i]-x[i-1].first+sumbr[n-i-1]<<"\n";
        ans=max(ans,suml[i]-(c-x[n-i].first)+sumbr[n-i]);
    }
    cout << ans << "\n";
}


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

int main(){
    int w,h,n; cin >> w >> h >> n;
    vector<vector<int>> S(h,vector<int>(w,0));
    rep(i,n){
        int x,y,a; cin >> x >> y >> a;
        if(a == 1){
            rep(i,h){
                rep(j,x){
                    S[i][j] = 1;
                }
            }
        }else if(a == 2){
            rep(i,h){
                for(int j = x; j < w; j++){
                    S[i][j] = 1;
                }
            }
        }else if(a == 3){
            rep(i,y){
                rep(j,w){
                    S[i][j] = 1;
                }
            }
        }else if(a == 4){
            for(int i = y; i < h; i++){
                rep(j,w){
                    S[i][j] = 1;
                }
            }
        }
    }
    
    int ans = 0;
    rep(i,h){
        rep(j,w){
            if(S[i][j] == 0){
                ans++;
            }
        }    
    }
    cout << ans << endl;
}


Measured memory_bytes: 892
N = int(input())
S = input()

black = []
white = []

for i in range(N):
    prev = 0 if i == 0 else white[i-1]
    if S[N-i-1] == '.':
        white.append(prev + 1)
    else:
        white.append(prev)
    prev = 0 if i == 0 else black[i-1]
    if S[i] == '#':
        black.append(prev + 1)
    else:
        black.append(prev)
white = [0] + white
black = [0] + black
mn = 1e9

for i in range(N+1):
    res = white[N-i] + black[i]
    if res < mn:
        mn = res

print(mn)


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

#define ul unsigned long long
#define ll long long
#define ld long double


int main()
{
  ll n,k,x1,x2,x3;

  cin>>n>>k;

  if (n>=k) n%=k;


  while (n*2>k)
  {
    n=abs(k-n);
  }
  cout<<n<<endl;

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef vector<int> vi;
typedef pair<int,int> pii;
const int N=300000+100;
const db pi=acos(-1.0);
#define lowbit(x) ((x)&(-x))
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u],v=sq[i].to;i;i=sq[i].nxt,v=sq[i].to)
#define fir first
#define sec second
#define mkp make_pair
#define pb push_back
#define maxd 1000000007
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

inline ll readll()
{
    ll x=0;int f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

namespace My_Math{
    #define N 100000

    int fac[N+100],invfac[N+100];

    int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
    int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
    int mul(int x,int y) {return 1ll*x*y%maxd;}
    ll qpow(ll x,int y)
    {
        ll ans=1;
        while (y)
        {
            if (y&1) ans=mul(ans,x);
            x=mul(x,x);y>>=1;
        }
        return ans;
    }
    int getinv(int x) {return qpow(x,maxd-2);}

    int C(int n,int m)
    {
        if ((n<m) || (n<0) || (m<0)) return 0;
        return mul(mul(fac[n],invfac[m]),invfac[n-m]);
    }

    void math_init()
    {
        fac[0]=invfac[0]=1;
        rep(i,1,N) fac[i]=mul(fac[i-1],i);
        invfac[N]=getinv(fac[N]);
        per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
    }
    #undef N
}
using namespace My_Math;

int n,f[N][3][3];
char s[N];

int main()
{
    scanf("%s",s+1);
    n=strlen(s+1);
    f[0][0][0]=1;
    rep(i,0,n-1) rep(j,0,2) rep(k,0,2)
    {
        if (s[i+1]!='1')
        {
            if (j==2) f[i+1][j-1][k]=add(f[i+1][j-1][k],f[i][j][k]);
            else f[i+1][j+1][k]=add(f[i+1][j+1][k],f[i][j][k]);
        }
        if (s[i+1]!='0')
        {
            if (j) f[i+1][j-1][k]=add(f[i+1][j-1][k],f[i][j][k]);
            else f[i+1][j][min(2,k+1)]=add(f[i+1][j][min(2,k+1)],f[i][j][k]);
        }
    }
    int ans=0;
    rep(i,0,2) rep(j,i,2) ans=add(ans,f[n][i][j]);
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 11136
#pragma region Macros
#include <bits/stdc++.h>

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define IN(x, a, b) x >= a and x < b

using namespace std;
using ll = long long;

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;
}
template <typename T> constexpr T INF = numeric_limits<T>::max() / 2;
#pragma endregion

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

  int N;
  cin >> N;
  vector<char> S(N);
  REP(i, N) { cin >> S[i]; }
  char s = S[0];
  int ans = 1;
  FOR(i, 1, N) {
    if (s != S[i]) {
      ans++;
    }
    s = S[i];
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 384
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <stdbool.h>

#define lli long long int
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))



int main(void){
	int i,j;
	int n;
	int *a;
	int ans = 1000000;
	int sum;
	scanf("%d",&n);
	a = calloc(sizeof(int),n+1);
	for(i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for(i = -100;i<=100;i++){
		sum = 0;
		for(j = 1;j <= n;j++){
			sum += (a[j] - i) * (a[j] - i);
		}
		ans = min(sum,ans);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 128
n = int(input())
w = list(map(int,input().split()))

ans = []
for i in range(0,n):
  tmp1 = sum(w[i:])
  #print(w[i:],w[:i])
  tmp2 = sum(w[:i])
  ans.append(abs(tmp1-tmp2))
  #print(tmp1,tmp2)
print(min(ans))

Measured memory_bytes: 38384
from fractions import gcd
# from datetime import date, timedelta
from heapq import*
import math
from collections import defaultdict, Counter, deque
from bisect import *
import itertools
import sys
sys.setrecursionlimit(10 ** 7)
MOD = 10 ** 9 + 7
# input = sys.stdin.readline


def main():
    n = int(input())
    a = list(map(int, input().split()))

    ans = 0
    for i in range(60):
        one,zero = 0,0
        for j in range(n):
            if ((1 << i) & a[j]) == (1 << i):
                one +=1
            else:
                zero += 1
        ans += (1 << i) * one * zero
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 121428
#include<iostream>
#include<math.h>

using namespace std;

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

    int i=1;
    while(1){
        min_ = pow(k,i);
        max_ = pow(k,i+1) - 1;
        if(n < k) {
            i = 0;
            break;
        }
        if(min_ <= n && n <= max_)
            break;
        i++;
    }
    cout << i+1 << endl;
    return 0;
    
}

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

int main() {
	
	string a;

	cin >> a;

	int cou = 0;

	for (int i = 0;i < 3;i++) {
		if (a[i] == 'o') {
			cou++;
		}
	}

	cout << 700 + (cou * 100) << endl;

}

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

#define ll long long
#define ldb long double
#define rep(i, x, n, j) for(int i=x;i<(int)n;i+=j)
#define F first
#define S second
#define per(i, x, n, j) for(int i=(int)n-1;i>=0;i-=j)
#define all(v) v.begin(),v.end()
#define sz(a) (int)a.size()

const int N = 2000100;
const ll MOD = 1e9+7;
const ll inf = 1e18+5;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<ll> vl;
typedef pair<ll, ll> pll;

int _;

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, k, s; cin >> n >> k >> s;
	vector<int> a;
	rep(i,0,k,1) a.push_back(s);
	rep(i,0,n-k,1){
		if(s==1e9) a.push_back(1);
		else a.push_back((int)1e9);
	}
	rep(i,0,sz(a),1) cout << a[i] << " ";
	cout << endl;
	return 0;
}


Measured memory_bytes: 1912
#include <bits/stdc++.h>
using namespace std;
#define maxn 400
#define int long long
int n, dis[maxn][maxn], Map[maxn][maxn];
int ans, mark[maxn][maxn];

int read()
{
	int x = 0, k = 1;
	char c; c = getchar();
	while(c < '0' || c > '9') { if(c == '-') k = -1; c = getchar(); }
	while(c >= '0' && c <= '9') x = x * 10 + c - '0', c = getchar();
	return x * k; 
}

signed main()
{
	n = read();
	for(int i = 1; i <= n; i ++)
		for(int j = 1; j <= n; j ++)
			dis[i][j] = dis[j][i] = read();
	for(int k = 1; k <= n; k ++)
		for(int i = 1; i <= n; i ++)
			for(int j = 1; j <= n; j ++)
			{
				if(dis[i][k] + dis[k][j] < dis[i][j]) { puts("-1"); return 0; }
				if(dis[i][k] + dis[k][j] == dis[i][j] && i != k && j != k) mark[i][j] = 1;
			}
	for(int i = 1; i <= n; i++)
		for(int j = i + 1; j <= n; j ++) 
			if(!mark[i][j]) ans += dis[i][j];
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 2176
#include <bits/stdc++.h>
using namespace std;
int main(){
  	char str[4];
  	scanf("%s",str);
  	int ans = (str[0] == 'R') + (str[1] == 'R') + (str[2] == 'R');
  	if (ans == 2){
    	if (str[1] == 'S') ans = 1;
    }
  	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 3752
/*
    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 = 200010;
const int MAXM = 1000;
const int MAXK = 16;
const int MAXQ = 200010;

int n;
ll l[MAXN][2], r[MAXN][2];
string s;

ll binPowMod(ll a, ll b, ll MOD) {
    a %= MOD;
    ll res = 1;
    while (b > 0) {
        if (b & 1LL) res = res * a % MOD;
        a = a * a % MOD;
        b >>= 1LL;
    }
    return res;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(nullptr);
    cin >> n;
    cin >> s;
    s = " " + s;

    int p = 0;
    FOR(i,1,n) p += s[i] == '1';

    FOR(i,1,n) {
        l[i][1] = (l[i-1][1] * 2 + s[i] - '0') % (p+1);
        if (p-1 > 0) l[i][0] = (l[i-1][0] * 2 + s[i] - '0') % (p-1);
    }

    ll x = 1, y = 1;
    FORE(i,n,1) {
        r[i][1] = (r[i+1][1] + (s[i] - '0') * x) % (p+1);
        x = x * 2 % (p+1);
        if (p-1 > 0) {
            r[i][0] = (r[i+1][0] + (s[i] - '0') * y) % (p-1);
            y = y * 2 % (p-1);
        }
    }

    FOR(i,1,n)
        if (s[i] == '0') {
            ll x = (l[i-1][1] * binPowMod(2, n-i+1, p+1) + r[i+1][1] + binPowMod(2, n-i, p+1)) % (p+1);
            // cout << x << endl;
            ll res = 1;
            while (x) {
                x %= __builtin_popcountll(x);
                res++;
            }
            cout << res << "\n";
        } else {
            if (p - 1 == 0) {
                cout << 0 << "\n";
                continue;
            }
            ll x = (l[i-1][0] * binPowMod(2, n-i+1, p-1) + r[i+1][0]) % (p-1);
            // cout << x << endl;
            ll res = 1;
            while (x) {
                x %= __builtin_popcountll(x);
                res++;
            }
            cout << res << "\n";
        }
    return 0;
}


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

int main()
{
	int N;
	cin >> N;
	vector<pair<long long, long long>> XL( N );
	for( int i = 0; i < N; i++ ) {
		long long X, L;
		cin >> X >> L;
		XL[i] = make_pair( X - L, X + L );
	}

	priority_queue<pair<long long, long long>> que;
	for( int i = 0; i < N; i++ ) {
		que.push( XL[i] );
	}
	int ans = 0;
	while( !que.empty() ) {
		long long L, H;
		tie( L, H ) = que.top();
		que.pop();
		if( que.empty() ) break;
		long long LL, HH;
		tie( LL, HH ) = que.top();
		que.pop();
		if( HH <= L ) {
			ans++;
			que.push( make_pair( LL, HH ) );
		}
		else {
			que.push( make_pair( L, H ) );
		}
	}
	ans++;

	cout << ans << endl;
}


Measured memory_bytes: 3956
import sys
n, a, b = [int(i) for i in sys.stdin.readline().split()]
x_ls = [int(i) for i in sys.stdin.readline().split()]
diff_ls = []
for i, x in enumerate(x_ls[:-1]):
    diff_ls.append((x_ls[i+1] - x) * a)
diff_ls = [i if i < b else b for i in diff_ls]
print(sum(diff_ls))

Measured memory_bytes: 61848
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.List;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        String S = scan.next();
        char[] oceros = S.toCharArray();
        List<Pair> pairs = make(oceros);
        long ans = 0;
        long prev = 0;
        for (int i = 0; i < pairs.size(); i++) {
            Pair p = pairs.get(i);
            if (p.value == 'W') {
                ans += prev * p.count;
                continue;
            }
            prev += p.count;
        }
        System.out.println(ans);
    }

    private List<Pair> make(char[] oceros) {
        char current = oceros[0];
        int index = 0;
        int[] summary = new int[oceros.length];
        for (int i = 0; i < oceros.length; i++) {
            if (current != oceros[i]) {
                index += 1;
            }
            summary[index] += 1;
            current = oceros[i];
        }
        List<Pair> result = new ArrayList<>();
        char value = oceros[0];
        for (int i = 0; i < summary.length; i++) {
            if (summary[i] == 0) {
                break;
            }
            Pair p = new Pair();
            p.count = summary[i];
            p.value = value;
            result.add(p);
            value = value == 'W' ? 'B' : 'W';
        }
        return result;
    }

    class Pair {
        char value;
        int count;
    }
}


Measured memory_bytes: 32816