akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n)  for(int i = 0; i < n; i++)
#define all(cont) cont.begin(), cont.end()
#define rall(cont) cont.rbegin(), cont.rend()
#define unique(a)  (a).erase(unique((a).begin(), (a).end()),(a).end())
#define fastio          ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define PB push_back
#define endl "\n"
#define mod 1000000007
typedef long long LL;
typedef long double LD;
typedef vector<int> VI;
inline LL add(LL x, LL y) { x += y; if (x >= mod) x -= mod; return x; }
inline LL moduloMultiplication(LL x, LL y) {
	return (x%mod * 1LL * y%mod) %

		mod;
}
inline LL power(LL a, LL b) {
	LL x = 1 % mod;
	while (b) {
		if (b & 1) x = moduloMultiplication(x, a);
		a = moduloMultiplication(a, a);
		b >>= 1;
	}
	return x % mod;
}
inline LL inv(LL a) { return power(a, mod - 2) % mod; }
LL gcd(LL a, LL b)
{
	if (!a)
		return b % mod;
	return gcd(b%a, a) % mod;
}
int main()
{

	int n;
	cin >> n;
	VI v(n);
	rep(i, n)cin >> v[i];
	int avg = accumulate(all(v), 0);
	avg = avg / n;
	LL ans = 0;
	LL ans1 = 0;
	LL ans2 = 0;
	rep(i, n) {
		ans += (avg - v[i])*(avg - v[i]);
		ans1 += (avg - 1-v[i])*(avg - 1-v[i]);
		ans2+= (avg +1 - v[i])*(avg + 1 - v[i]);
	}
	cout << min({ ans,ans1,ans2 }) << endl;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll ze(ll x,ll y=0){
    return max(x,y)-min(x,y);
};
int main(){
    int n;
    cin >> n;
    int a[n];
    int cnt=0;
    ll sum=0;
    int mn=100000000;
    for(int i=0; i<n; i++){
        cin >> a[i];
        if(a[i]<0)cnt++;
        sum+=ze(a[i]);
        if(mn>ze(a[i]))mn=ze(a[i]);
    }
    if(cnt%2==0)cout << sum << endl;
    else cout << sum-2*mn << endl;
}

Measured memory_bytes: 640
Ps = []

while True:
    i = int(input())
    if i == 0:
        break
    P = []
    P.append(i)
    for ii in range(i):
        P.append(int(input()))

    Ps.append(P)

for p in Ps:
    p[0] = 0
    p.sort()
    p[1] = 0
    p[-1] = 0
    print(int(sum(p) / (len(p) - 3)))


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

int main()
{
  int H, W;
  cin>>H>>W;
  vector<string> S(H);
  for(int i=0; i<H; i++){
    cin>>S[i];
  }

  vector<vector<int>> A(H+2, vector<int>(W+2, 0));

  for(int i=0; i<H; i++){
    for(int j=0; j<W; j++){
      if(S[i][j]=='#'){
        int i_=i+1;
        int j_=j+1;
        A[i_-1][j_-1]++;
        A[i_-1][j_]++;
        A[i_-1][j_+1]++;
        A[i_][j_-1]++;
        A[i_][j_]=-9999;
        A[i_][j_+1]++;
        A[i_+1][j_-1]++;
        A[i_+1][j_]++;
        A[i_+1][j_+1]++;
      }
    }
  }

  vector<string> Ans(H);
  for(int i=1; i<=H; i++){
    for(int j=1; j<=W; j++){
      if(A[i][j]<0){
        int i_=i-1;
        int j_=j-1;
        Ans[i_]+='#';
      }else{
        int i_=i-1;
        int x=A[i][j];
        if(x==0)  Ans[i_]+='0';
        else if(x==1)  Ans[i_]+='1';
        else if(x==2)  Ans[i_]+='2';
        else if(x==3)  Ans[i_]+='3';
        else if(x==4)  Ans[i_]+='4';
        else if(x==5)  Ans[i_]+='5';
        else if(x==6)  Ans[i_]+='6';
        else if(x==7)  Ans[i_]+='7';
        else Ans[i_]+='8';
      }
    }
  }

  for(int i=0; i<H; i++)  cout<<Ans[i]<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, k, n) for(int i = k; i < int(n); i++)
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
Graph G;
vector<int> ans;

void dfs(int v, int p, int c){
    ans[v] = c;
    for (auto e: G[v]){
        if (e.first == p) continue;
        if (e.second & 1) dfs(e.first, v, 1-c);
        else dfs(e.first, v, c);
    }
}

int main(){
    int N;
    cin >> N;
    G.assign(N, vector<Edge>());
    rep(i, 0, N-1){
        int u, v, w;
        cin >> u >> v >> w;
        --u;
        --v;
        G[u].push_back(Edge(v, w));
        G[v].push_back(Edge(u, w));
    }
    ans.assign(N, 0);
    dfs(0, -1, 1);
    for (auto a:ans) cout << a << endl;
    return 0;
}   

Measured memory_bytes: 8960
#include <iostream>
#include <stdio.h>
#include <cstring>
#include <cstdio>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string>
#include <stdlib.h>
#include <queue>
#include <stack>
#include <utility>
#include <fstream>
#include <random>
#include <map>
#include <unordered_map>
#include <cstdlib>
#include <functional>
#include <random>
#include <time.h>
#include <chrono>
#include <sstream>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ll long long
#define INF 1000000001
#define mod 1000000007
#define sort(s) sort(s.begin(), s.end());
#define reverse(s) reverse(s.begin(), s.end());
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
using namespace std;
int POW(int x, int y) { return int(pow(double(x), double(y))); }
double log(double a, double b) { return log(b) / log(a); }

unsigned int randxor()
{
	static unsigned int x = 123456789, y = 362436069, z = 521288629, w = 88675123;
	unsigned int t;
	t = (x ^ (x << 11)); x = y; y = z; z = w; return(w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}


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

	if (k == 1) {
		cout << 2 << endl;
		return 0;
	}

	if (b - a <= 2) {
		cout << 1 + k << endl;
	}
	else {
		if (k - (a - 1) <= 0) {
			cout << 1 + k << endl;
		}
		else {
			k -= a - 1;
			if (k % 2 == 1) {
				ll q = (b - a);
				ll w = (k - 1) / 2;
				ll e = q * w;
				ll r = 2 + (b - a)*(k - 1) / 2;
				cout << fixed << a + 1 + (b - a)*(k - 1) / 2 << endl;
			}
			else {
				cout << fixed << a + (b - a) * k / 2 << endl;
			}
		}




	}


	return 0;
}




Measured memory_bytes: 256
#include <stdio.h>

int main(int argc, const char * argv[]) {
    
    int n,i,j,sum=0,count=0,x=1,h=0;
    while (1) {
        
        scanf("%d",&n);
        
        if (n==0) {
            break;
        }
        for (h = 0; h < n; h++) {
            for (i = 1; i < n-h; i++) {
                for (j = n-h; j >= i; j--) {
                    sum+=j;
                }
            
                if (sum == n) {
                    count++;
                }
                sum=0;
            
            }
        }
        
        printf("%d\n",count);
        count=0;
    }
    return 0;
}

Measured memory_bytes: 600
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define _GLIBCXX_DEBUG
#define V vector<ll>
using namespace std;
using ll = long long;


int main(){
    ll n; cin >> n;
    vector<string> w(n);
    rep(i,0,n) cin >> w[i];
    set<string> s;

    bool f = true;
    rep(i,0,n-1){
        if(w[i].back() != w[i+1].front()) f = false;
    }
    rep(i,0,n){
        s.insert(w[i]);
        if(s.size() != i+1) f = false;
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
  char S[100000];
  cin >> S;

  int count_bw = 0, count_wb = 0, i = 0;
  while (S[i] != '\0') {
    if (i % 2 == 0) {
      // 偶数の場合
      if (S[i++] == '0') count_wb++;
      else count_bw++;
    } else {
      // 奇数の場合
      if(S[i++] == '1') count_wb++;
      else count_bw++;
    }
  }
  cout << min(count_bw, count_wb) << endl;
  return 0;
}

Measured memory_bytes: 384
import sys
from io import StringIO
import unittest

def resolve():
    n, c, k = map(int, input().split())
    t = [int(input()) for _ in range(n)]

    t.sort()
    ans = 1
    bus_base = t[0] + k
    cnt_bus = 0

    for i in range(n):
        if cnt_bus == c:
            cnt_bus = 0
            bus_base = t[i] + k
            ans += 1

        if t[i] <= bus_base:
            cnt_bus += 1
            continue
        else:
            bus_base = t[i] + k
            ans += 1
            cnt_bus = 1

    print(ans)

class TestClass(unittest.TestCase):
    def assertIO(self, input, output):
        stdout, stdin = sys.stdout, sys.stdin
        sys.stdout, sys.stdin = StringIO(), StringIO(input)
        resolve()
        sys.stdout.seek(0)
        out = sys.stdout.read()[:-1]
        sys.stdout, sys.stdin = stdout, stdin
        self.assertEqual(out, output)
    def test_入力例_1(self):
        input = """5 3 5
1
2
3
6
12"""
        output = """3"""
        self.assertIO(input, output)
    def test_入力例_2(self):
        input = """6 3 3
7
6
2
8
10
6"""
        output = """3"""
        self.assertIO(input, output)

if __name__ == "__main__":
    # unittest.main()
    resolve()

Measured memory_bytes: 10184
#define _LIBCPP_DEBUG 0
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
ll MOD = 1e9 + 7;


int main(void){

    int X; cin>>X;
    ll ans = 0;

    for (int i = X; i<X*2; ++i) {
        bool sosu = true;
        for (int j = 2; j*j <= i; ++j) {
            if(i % j==0){
                sosu = false;
                break;
            }
        }
        if(sosu){
            cout<<i<<endl;
            return 0;
        }
    }
    cout<<X*2<<endl;


}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(ll I=ll(A);I<ll(B);++I)

int main(){
	int n,a,b;
	string s,q;
	cin >> s >> n;
	FOR(i,0,n){
		cin >> q;
		if(q=="print"){
			cin >> a >> b;
			cout << s.substr(a,b-a+1) << endl;
		}else if(q=="reverse"){
			cin >> a >> b;
			string t = s.substr(a,b-a+1);
			reverse(t.begin(), t.end());
			s = s.substr(0,a)+t+s.substr(b+1,s.size()-b-1);
		}else{
			cin >> a >> b;
			string t;
			cin >> t;
			s = s.substr(0,a)+t+s.substr(b+1,s.size()-b-1);
		}
	}
}


Measured memory_bytes: 3224
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashSet;
import java.util.Scanner;

public class Main {
  Scanner sc;

  int MAX = 1000000;

  void run() {
    for ( ;; ) {
      int n = ni();
      int p = ni();

      if ( ( n & p ) == -1 ) {
        break;
      }

      ArrayList<Integer> pl = new ArrayList<Integer>( p );
      for ( int i = n + 1; pl.size() < p; ++i ) {
        boolean f = i > 1;
        for ( int j = 2; f && j * j <= i; ++j ) {
          f &= i % j != 0;
        }
        if ( f ) {
          pl.add( i );
        }
      }
      ArrayList<Integer> list = new ArrayList<Integer>();
      for ( int i = 0; i < p; ++i ) {
        for ( int j = i; j < p; ++j ) {
          list.add( pl.get( i ) + pl.get( j ) );
        }
      }
      Collections.sort( list );

      System.out.println( list.get( p - 1 ) );
    }
  }

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

  int ni() {
    return sc.nextInt();
  }

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

  void debug(Object... os) {
    System.err.println( Arrays.deepToString( os ) );
  }

}

Measured memory_bytes: 69004
#include <iostream>
#include <iomanip>
using namespace std;
int main()
{
    double n, k;
    cin >> n >> k;
    double ans=1;
    for (int i = 0; i < n; i++)
    {
        if(i==0) ans*=k;
        else ans*=(k-1);
    }
    cout <<setprecision(32)<<ans;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
sys.setrecursionlimit(10**9)
INF=10**18
MOD=10**9+7
input=lambda: sys.stdin.readline().rstrip()
YesNo=lambda b: bool([print('Yes')] if b else print('No'))
YESNO=lambda b: bool([print('YES')] if b else print('NO'))
int1=lambda x:int(x)-1

def main():
    s=list(input())
    t=list(input())
    s.sort()
    t.sort(reverse=1)
    l=[s,t]
    l.sort()
    YesNo(l[0]==s and s!=t)

if __name__ == '__main__':
    main()


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


int main() {
    ll X;

    cin >> X;

    ll money = 100;
    ll ans = 0;

    while (money < X) {
        money = money *1.01;
        ans++;
    }


    cout << ans << endl;
    
    
    return 0;
}

Measured memory_bytes: 3592
#[allow(unused_imports)]
use std::cmp::{max, min};
use std::io::{stdin, stdout, BufWriter, Write};

const K: usize = 60;
const MOD: i64 = 1e9 as i64 + 7;

fn i64_to_bit_vec(x: i64) -> Vec<i64> {
    let mut ret: Vec<i64> = vec![];
    for i in 0..K {
        ret.push(x >> i & 1);
    }
    ret
}

fn main() {
    /* START INIT IO */
    let stdin_obj = stdin();
    let mut scan = Scanner {
        stdin: stdin_obj.lock(),
    };
    let out = &mut BufWriter::new(stdout());
    /* END INIT IO */

    // Code starts here
    let n: usize = scan.read();
    let a: Vec<i64> = scan.read_vec(n);
    let mut cnt_1: [i64; K] = [0; K];

    for i in 0..a.len() {
        let curr_bit_vec = i64_to_bit_vec(a[i]);
        for j in 0..K {
            if curr_bit_vec[j] == 1 {
                cnt_1[j] += 1;
            }
        }
    }

    let mut p: i64 = 1;
    let mut res: i64 = 0;
    for j in 0..K {
        let total_pairs = cnt_1[j] * (n as i64 - cnt_1[j]) % MOD;
        res += total_pairs * p % MOD;
        res %= MOD;
        p <<= 1;
        p %= MOD;
    }

    writeln!(out, "{}", res).ok();
}

/* IO SNIPPET */
/*
Example uses:
let n: usize = scan.read();
let k: i64 = scan.read();
let mut a: Vec<i64> = scan.vec(n);
wri teln!(out, "{}", l).ok();
*/

#[derive(Default)]
pub struct Scanner<R> {
    stdin: R,
}
impl<R: std::io::Read> Scanner<R> {
    // Reads single token
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    // Reads whole line
    pub fn read_line(&mut self) -> String {
        use std::io::Read;
        let buf = self
            .stdin
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b'\n' || b == b'\r')
            .take_while(|&b| b != b'\n' && b != b'\r')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    // Reads a vector with elements of type T by token (uses self.read to read)
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    // Read token but returns Vec<char> instead of inferred type
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 8444
h, w, k = map(int, input().split())
C = []
for _ in range(h):
    C.append(input())
ans = 0
for hbit in range(1<<h): # red row bit
    for wbit in range(1<<w): # red col bit
        c = 0
        for i in range(h):
            for j in range(w):
                if hbit>>i & 1 and wbit>>j & 1:
                    if C[i][j] =='#': c += 1
        if c == k: ans += 1
print(ans)


Measured memory_bytes: 9192
import numpy as np
import math
import functools
import operator
N=int(input())
A = list(map(int, input().split()))
#AA=A.sort()
if A.count(0)>0:
    ans=0
elif N>30 and A.count(1)<10:
    ans=-1
    
else:
    ans=functools.reduce(operator.mul, A)
if ans>10**18 :
    ans=-1
print(ans)

Measured memory_bytes: 39848
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int) n; i++)
#define repb(i, n) for (int i = (int) n; i >= 0; i--)
#define reps(i, m, n) for (int i = (int) m; i < (int) n; i++)
#define repsb(i, m, n) for (int i = (int) m; i >= (int) n; i--)
#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.begin(), v.end(),greater<int>());
#define pb(a) push_back(a)
#define ll long long int
const ll LLINF = 1e18 + 10;
int dy[] = { 0, 0, 1, -1, 0 };
int dx[] = { 1, -1, 0, 0, 0 };
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; }
//vector<vector<int>> vec(n_rows, vector<int>(n_cols, value));
using namespace std;
int main(int argc, char const * argv[]){
    int n;
    cin>>n;
    vector<int> v(n,-1);
    rep(i,n) cin>>v[i];
    VSORT(v)
    if(v[n/2-1]==v[n/2]){
        cout<<0<<endl;
        return 0;
    }
    cout<<v[n/2]-v[n/2-1]<<endl;

    return 0;
}

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

namespace A
{
    class Program
    {
        static void Main(string[] args)
        {
            var S = Console.ReadLine();
            var devide = new[] { "dream", "dreamer", "erase", "eraser" };

            S = new string(S.Reverse().ToArray());
            devide = devide.Select(d => new string(d.Reverse().ToArray())).ToArray();

            var can = true;
            for (var i = 0; i < S.Length; i++)
            {
                var b = false;
                foreach (var d in devide)
                {
                    if (d.Length <= S.Length - i
                        && d == S.Substring(i, d.Length))
                    {
                        i += d.Length - 1;
                        b = true;
                        break;
                    }
                }

                if (!b)
                {
                    can = false;
                    break;
                }
            }

            var output = can ? "YES" : "NO";
            Console.WriteLine(output);
        }
    }
}


Measured memory_bytes: 14944
#include<stdio.h>
#include<stdlib.h>


int euclid(int a, int b){
  if(a < b){
    int tmp = a;
    a = b;
    b = tmp;
  }
  int r = a % b;
  if(r < 0){
    r += b;
  }
  while(r != 0){
    a = b;
    b = r;
    r = a % b;
    if(r < 0){
      r += b;
    }
  }
  return b;
}

int main(){
  int N,X,d;
  scanf("%d %d",&N,&X);
  int x[N];
  for(int i=0;i<N;i++) scanf("%d",&x[i]);
  d= abs(x[0]-X);
  for(int i=1;i<N;i++){
    d=euclid(d,abs(x[i]-X));
  }
  printf("%d\n",d );
  }


Measured memory_bytes: 512
#include <bits/stdc++.h>
#include <numeric>
#define ll long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

#define pr pair<int, int>

using namespace std;

const ll mod = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;

#define DEBUG

#ifdef DEBUG
#define PRINT(A) std::cout << (#A) << ":" << (A) << std::endl;
#else
#define PRINT(A)
#endif

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

// int a[10010][10010], b[1000];
// int dp[10010][3];

int main() {
    
    ll X; cin >> X;
    ll money = 100;
    ll year = 0;
    while(true){
        if(money >= X){
            break;
        }
        else{
            money = (ll)(money * 1.01);
            year ++;
        }

    }   
    cout << year << endl;
    return 0;
}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < n; i++)
#define per(i,n) for(int i = n-1; i >= 0; i--)
typedef long long ll;
typedef pair<int, int> P;
typedef pair<long long, long long> Pll;
typedef vector<int> vi;
typedef vector<ll> vll;
const long long mod = 1000000007LL;

int main() {
  vi v(5);
  rep(i,5) cin >> v[i];
  rep(i,5) if(v[i]!=i+1) cout << i+1 << endl;
  return 0;
}

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


int main () {
    int n, q ;
    ll k ;
    cin >> n >> k >> q ;
    vector<int> a (q) ;
    vector<ll> ans (n) ;
    rep(i, q) {cin >> a[i] ;
    ans[a[i] - 1]++ ;}

    rep(i, n){
        if(k > q - ans[i]){
            cout << "Yes" << endl ;
        }
        else {
            cout << "No" << endl ;
        }
    }
    
}

Measured memory_bytes: 4556
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <climits>
#include <cmath>
#include <utility>
#include <string>
#include <cstring>
#include <functional>

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	
	long long k, a, b, ans = 1;
	cin >> k >> a >> b;

	if (a+2 >= b || k < a)
		ans = k+1;
	else {
		long long rem = k - a + 1;
		ans = a + rem / 2 * (b-a);
		if (rem&1)
			++ans;
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <cmath>
#include <vector>

typedef long long ll;

using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<double> v(n);

    for (ll i=0; i<n; i++)
        cin >> v[i];

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

    for (ll i=1; i<n; i++)
        v[i] = 0.5 *(v[i-1] + v[i]);

    cout << v[n-1] << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> P;
const ll mod = 1000000007;
const ll INF = 1e+14;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define _GLIBCXX_DEBUG

int main(){
    int n; cin>>n;
    vector<ll> a;
    rep(i,n){
        ll p;
        cin>>p;
        a.push_back(p);
    }

    ll ans=0;
    ll memory=a[0];
    rep(i,n-1){
        if(a[i+1]>memory) memory=a[i+1];
        else{
            ans+=memory-a[i+1];
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 5372
import sys
sys.setrecursionlimit(1000000000)
from fractions import gcd
from itertools import count
from functools import lru_cache
from collections import defaultdict
from pprint import pprint
ii = lambda: int(input())
mis = lambda: map(int, input().split())
lmis = lambda: list(mis())
INF = float('inf')
N1097 = 10**9 + 7

def meg(f, ok, ng):
    while abs(ok-ng)>1:
        mid = (ok+ng)//2
        if f(mid):
            ok=mid
        else:
            ng=mid
    return ok
#

def main():
    x = ii()
    ps = []
    for i in count(2):
        is_prime = True
        for p in ps:
            if i % p == 0:
                is_prime = False
                break
            if i**0.5 < p:
                break 
        if is_prime:
            if x <= i:
                print(i)
                return
            else:
                ps.append(i)

main()


Measured memory_bytes: 5512
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<(n);i++)
#define MOD 1000000007
#define all(n) (n).begin(),(n).end()
typedef long long ll;
template <class T> inline bool chmax(T& a,T b){if(a<b){a=b;return 1;}else{return 0;}}
template <class T> inline bool chmin(T& a,T b){if(a>b){a=b;return 1;}else{return 0;}}
template <class T> inline T GCD(T a,T b){T c;while(b!=0){c=a%b;a=b;b=c;}return a;}
template <class T> inline T LCM(T a,T b){return a*b/GCD(a,b);}

int main(){
	ll n,a[400][400],d[400][400],sum=0;
	cin >> n;
	FOR(i,n){
		FOR(j,n){
			cin >> a[i][j];
			d[i][j]=a[i][j];
			sum+=a[i][j];
		}
	}

	bool ans=1;

	FOR(i,n){
		FOR(j,n){
			FOR(k,n){
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}

	FOR(i,n){
		FOR(j,n){
			if(i>j)continue;
			if(a[i][j]>d[i][j])ans=0;
			
		}
	}

	if(ans){
		
		FOR(i,n){
			FOR(j,n){
				bool x=1;
				FOR(k,n){
					if(i==k || j==k)continue;
					if(d[i][k]+d[k][j]==d[i][j]){
						if(x){sum-=d[i][j];x=0;}
					}
				}
			}
		}
		cout << sum/2 << endl;
	}else{
		cout << -1 << endl;
	}


}

Measured memory_bytes: 2688
#include <string.h>
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
// #include <unordered_map>
// #include <unordered_set>
#include <utility>
#include <vector>

#define pb push_back
#define mp make_pair
#define sqr(x) ((x) * (x))

#ifdef ONLINE_JUDGE
#define link renamelink
#define next renamenext
#define prev renameprev
#endif

using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef pair<int, int> pii;
typedef pair<LL, LL> pll;
typedef long double ld;

inline void EnableFileIO(const string& fileName, bool local = 0) {
  if (fileName.empty()) return;
  if (local) {
    freopen((fileName + ".in").c_str(), "r", stdin);
    freopen((fileName + ".out").c_str(), "w", stdout);
    return;
  }
#ifdef ONLINE_JUDGE
  freopen((fileName + ".in").c_str(), "r", stdin);
  freopen((fileName + ".out").c_str(), "w", stdout);
#endif
}

const int INF = (1 << 30) - 1;
const LL LINF = (1LL << 61) - 1;
const double EPS = 1e-10, PI = acos(-1);
const int N = 2e5 + 100;

int n;
int a[N], l[N];
stack<int> st;

int main() {
  // srand((int)time(0));
  // printf("Hello, world!\n");
  // EnableFileIO("");

  cin >> n;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < n; i++) {
    while (!st.empty() && a[st.top()] > a[i]) st.pop();
    l[i] = (st.empty() ? 0 : st.top() + 1);
    st.push(i);
  }
  while (!st.empty()) st.pop();
  LL ans = 0;
  for (int i = n - 1; i >= 0; i--) {
    while (!st.empty() && a[st.top()] > a[i]) st.pop();
    ans += a[i] * 1LL * ((st.empty() ? n : st.top()) - i) * (i - l[i] + 1);
    st.push(i);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 2688
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;

int ty[2][6] = {{0, 7, 7, 7, 7, 14}, {0, 7, 7, 7, 7, 14}};
int tx[2][6] = {{7, 0, 7, 14, 21, 7}, {36, 29, 36, 43, 50, 36}};
char input[21][57];
string tmp[7];
string data[9][7] = {
  {"#######",
   "#.....#",
   "#...|.#",
   "#.....#",
   "#...|.#",
   "#..-..#",
   "#######",},
  {"#######",
   "#..-..#",
   "#...|.#",
   "#..-..#",
   "#.|...#",
   "#..-..#",
   "#######",},
  {"#######",
   "#..-..#",
   "#...|.#",
   "#..-..#",
   "#...|.#",
   "#..-..#",
   "#######",},
  {"#######",
   "#.....#",
   "#.|.|.#",
   "#..-..#",
   "#...|.#",
   "#.....#",
   "#######",},
  {"#######",
   "#..-..#",
   "#.|...#",
   "#..-..#",
   "#...|.#",
   "#..-..#",
   "#######",},
  {"#######",
   "#..-..#",
   "#.|...#",
   "#..-..#",
   "#.|.|.#",
   "#..-..#",
   "#######",},
  {"#######",
   "#..-..#",
   "#...|.#",
   "#.....#",
   "#...|.#",
   "#.....#",
   "#######",},
  {"#######",
   "#..-..#",
   "#.|.|.#",
   "#..-..#",
   "#.|.|.#",
   "#..-..#",
   "#######",},
  {"#######",
   "#..-..#",
   "#.|.|.#",
   "#..-..#",
   "#...|.#",
   "#..-..#",
   "#######",
  }
};

int judge(){
  for(int i=0;i<9;i++){
    bool f = true;
    for(int j=0;j<7;j++){
      if(tmp[j] != data[i][j]){
        f = false;
        break;
      }
    }
    if(f) return i+1;
  }
  return -1;
}

int calc1(int y, int x, int d){
  for(int i=0;i<7;i++){
    tmp[i] = "";
    for(int j=0;j<7;j++){
      tmp[i] += input[i+y][j+x];
    }
  }
  for(int i=0;i<7;i++) reverse(tmp[i].begin(), tmp[i].end());
  if(d != 0){
    string tmp2[7];
    for(int i=0;i<7;i++) tmp2[i] = tmp[i];
    if(d == 270){
      for(int i=0;i<7;i++){
        for(int j=0;j<7;j++){
          tmp[i][j] = tmp2[6-j][i];
          if(tmp[i][j] == '-') tmp[i][j] = '|';
          else if(tmp[i][j] == '|') tmp[i][j] = '-';
        }
      }
    }else{
      for(int i=0;i<7;i++){
        for(int j=0;j<7;j++){
          tmp[i][j] = tmp2[j][6-i];
          if(tmp[i][j] == '-') tmp[i][j] = '|';
          else if(tmp[i][j] == '|') tmp[i][j] = '-';
        }
      }
    }
  }
  return judge();
}

int calc2(int y, int x){
  for(int i=0;i<7;i++){
    tmp[i] = "";
    for(int j=0;j<7;j++){
      tmp[i] += input[i+y][j+x];
    }
  }
  reverse(tmp, tmp+7);
  for(int i=0;i<7;i++) reverse(tmp[i].begin(), tmp[i].end());
  return judge();
}

main(){
  while(cin >> input[0][0]){
    if(input[0][0] == '0') break;
    for(int i=0;i<21;i++){
      for(int j=0;j<57;j++){
        if(i == 0 && j == 0) continue;
        cin >> input[i][j];
      }
    }
    int point[2][6];
    for(int i=0;i<2;i++){
      for(int j=0;j<6;j++){
        if(j == 5) point[i][j] = calc2(ty[i][j], tx[i][j]);
        else{
          int d = 0;
          if(j == 1) d = 90;
          if(j == 3) d = 270;
          point[i][j] = calc1(ty[i][j], tx[i][j], d);
        }
      }
    }
    int ans1 = 0, ans2 = 0;
    for(int i=0;i<6;i++){
      for(int j=0;j<6;j++){
        if(point[0][i] > point[1][j]) ans1++;
        else if(point[0][i] < point[1][j]) ans2++;
      }
    }
    cout << (ans1<ans2 ? "LOW" : "HIGH") << endl;
  }
}

Measured memory_bytes: 0
#include<string>
#include<vector>
#include<algorithm>
#include<iostream>
#include<cstdio>
#include<cassert>

#define REP(i, n) for (int i=0;i<int(n);++i)
#define ALL(A) (A).begin(),(A).end()
#define SZ(A) int(A.size())

using namespace std;

typedef unsigned long long ull;

struct RollingHash{
  static const ull p=100000007;
  string s;
  int n;
  vector<ull> pow, phash;
  
  RollingHash(const string &s) : s(s), n(SZ(s)),pow(n+1),phash(n+1){
    pow[0]=1,phash[0]=0;
    REP(i, n) {
      phash[i+1] = s[i] + phash[i] * p;
      pow[i+1] = pow[i] * p;
    }
  }

  inline bool operator()(const int& i, const int& j) const { 
    const int k=lcp(i,j);
    return i+k >= n ? true : j+k >= n ? false : s[i+k] <= s[j+k];
  }

  /*
  static ull hash(const string &t) {
    ull h=0;
    REP(i,SZ(t))h=t[i]+h*p;
    return h;
  }  
  */

  inline ull hash(const int& b, const int& e) const {
    return phash[e]-phash[b]*pow[e-b];
  }
  /*
  inline int find(string t) {
    int w=t.size(),count=0;
    if(w > SZ(s))return 0;
    ull h=hash(t);
    REP(i,n-w+1)count+=(hash(i,i+w)==h);
    return count;
  }
  */
  
  inline int lcp(const int& i, const int& j) const {
    int l=0,r=n-i+1;
    while(l+1<r) {
      const int m=(l+r)>>1;
      (hash(i,i+m) == hash(j,j+m) ? l : r) = m;
    }
    return l;
  }
};

int L[1000000],R[1000000];

inline void merge(int *A, const int left, const int mid, const int right, const RollingHash &rh){
  const int n1 = mid - left, n2 = right - mid;
  REP(i,n1)L[i]=A[left+i];
  REP(i,n2)R[i]=A[mid+i];
  for(int k =left,i=0,j=0;k<right;k++){
    if(n2<=j)A[k]=L[i++];
    else if(n1<=i)A[k]=R[j++];
    else A[k]=rh(L[i],R[j])?L[i++]:R[j++];
  }
}

void mergeSort(int *A,const int left,const int right, const RollingHash &rh){
  if(left+1<right){
    const int mid = (left+right)>>1;
    mergeSort(A,left,mid, rh);
    mergeSort(A,mid,right, rh);
    merge(A,left,mid,right, rh);
  }
}

//O(n (log n)^2)
vector<int> suffixArray(const RollingHash &rh){
  int n=rh.n+1,sa[n];
  REP(i,n)sa[i]=i;
  mergeSort(sa,0,n,rh);
  vector<int>res(n);
  REP(i,n)res[i]=sa[i];
  return res;
}

bool contain(const string &S, const vector<int> &sa, const string &T){
  int a=0, b=SZ(S);
  while(b-a>1){
    const int c=(a+b)/2;
    (S.compare(sa[c],T.length(),T)<0 ? a : b ) = c;
  }
  return S.compare(sa[b], T.length(), T) == 0;
}

int main(void){

  char str[1000002];
  string s,t;
  scanf("%s",str);
  s=str;
  
  RollingHash rh=RollingHash(s);
  vector<int>sa=suffixArray(rh);
  
  int n;
  cin >> n;

  while(n--){
    scanf("%s",str);
    t=str;
    printf("%d\n",contain(s,sa,t));
  }

  return 0;
}

Measured memory_bytes: 32600
#include <stdio.h>

int main(void){
	int a,b;
	int day[]={0,31,29,31,30,31,30,31,31,30,31,30,31};

	while(scanf("%d %d",&a,&b),a){
		int youbi=0; // 0ismokuyou
		for(int i=1;i<a;i++) youbi=(youbi+day[i])%7;
		youbi=(youbi+b-1)%7;
		switch (youbi) {
			case 0:
				printf("Thursday\n");
				break;
			case 1:
				printf("Friday\n");
				break;
			case 2:
				printf("Saturday\n");
				break;
			case 3:
				printf("Sunday\n");
				break;
			case 4:
				printf("Monday\n");
				break;
			case 5:
				printf("Tuesday\n");
				break;
			case 6:
				printf("Wednesday\n");
				break;
		}
	}
	return 0;
}

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

char s[105];
int a[125];

int main(){
    int i,p,l,flag=0,count=0;

    scanf(" %s",s);

    l=strlen(s);

    for(i=0;i<l;i++){
        p=s[i];
        a[p]++;
    }
    for(i=97;i<=122;i++){
        if(a[i]>1){
            flag=1;
            break;
        }
    }

    if(flag==1)
        printf("no\n");
    else{
        printf("yes\n");
    }





    return 0;
}



Measured memory_bytes: 128
import sys
input = sys.stdin.readline
n,m = map(int, input().split())
es = [[] for _ in range(n)]
for i in range(m):
    a,b=map(int, input().split())
    es[a].append(b)
# Strongly Connected Component
def scc(n_node,es): # DFSを2回行う
    esinv = [[] for _ in range(n_node)]
    for i in range(n_node):
        for e in es[i]:
            esinv[e].append(i)
    used = [False]*n_node
    dim = [len(es[i]) for i in range(n_node)]
    order = []
    for st in range(n_node): # DFS 1回目, postorderを求める
        if not used[st]:
            stack = [(st, 0)] # [(index, 既に辿ったエッジの数)]
            while stack:
                now, i = stack.pop() 
                if not i and used[now]:
                    continue
                else:
                    used[now] = True
                    if i < dim[now]: # nowから延びるエッジを辿りきってない
                        stack.append((now,i+1))
                        stack.append((es[now][i],0))
                    else: # nowから延びる全てのエッジを辿った
                        order.append(now)
    res = [-1]*n_node # 各ノードが所属するグループのidを保存
    used = [False]*n_node 
    cnt = -1 # idカウンター
    for st in order[::-1]:  # DFS 2回目, postorderの逆順から
        if not used[st]:    # 逆向き矢印を辿って通れるノードを記録していく
            cnt += 1
            stack = [st]
            res[st] = cnt
            used[st] = True
            while stack:
                now = stack.pop()
                for e in esinv[now]:
                    if not used[e]:
                        used[e] = True
                        res[e] = cnt
                        stack.append(e)
    n_group = cnt+1
    components = [[] for _ in range(n_group)]
    for i in range(n_node):
        components[res[i]].append(i)
    return res, components # 各ノードの所属グループid, 各グループの構成ノード

res, comp=scc(n,es)
row=max(res)+1
print(row)
for i in range(row):
    length = len(comp[i])
    print(length, *comp[i])

Measured memory_bytes: 250356
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using ll = long long;
using namespace std;

int main() {
    int n;
    cin >> n;
    int h[n];
    rep(i, n) { cin >> h[i]; }

    int count = 0;
    int maxcount = 0;

    for(int i = 1; i < n; ++i) {
        if(h[i - 1] >= h[i]) {
            count++;
            maxcount = max(count, maxcount);
        } else {
            maxcount = max(count, maxcount);
            count = 0;
        }
    }

    cout << maxcount << endl;
}


Measured memory_bytes: 640
import math
import sys
n=int(input())
k=int(input())
s=str(n)
l=len(s)
dp0=[[0 for j in range(k+1)] for i in range(l)]
dp1=[[0 for j in range(k+1)] for i in range(l)]

x=int(s[0])
dp0[0][1]=x-1
dp0[0][0]=1
dp1[0][1]=1
for i in range(1,l):
    x=int(s[i])
    dp0[i][0]=1

    for j in range(1,k+1):
        dp0[i][j]+=dp0[i-1][j-1]*9+dp0[i-1][j]
        if x>0:
            dp0[i][j]+=dp1[i-1][j-1]*(x-1)+dp1[i-1][j]
            dp1[i][j]=dp1[i-1][j-1]
        else:
            dp1[i][j]=dp1[i-1][j]

print(dp0[l-1][k]+dp1[l-1][k])


Measured memory_bytes: 38384
#include <stdio.h>

int main(){
	double n;
	double high,low;
	double ans;
	scanf("%lf",&n);
	high = n;
	low = n;
	while(scanf("%lf",&n) != EOF){
		if(high < n){
			high = n;
		}
		if(low > n){
			low = n;	
		}
	}
	ans = high - low;
	printf("%f\n",ans);
	return 0;
}

Measured memory_bytes: 1076
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <functional>
#include <algorithm>
#include <string>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
using namespace std;
using llong = long long;

llong a, b;

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

    for (int i = 0; i <= 10000; i++) {
        if ((i * 8 / 100) == a &&
            (i * 10 / 100) == b) {
            cout << i << endl;
            return 0;
        }
    }

    cout << -1 << endl;

    return 0;
}


Measured memory_bytes: 256
package main

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

// const abcd = "abcdefghijklmnopqrstuvwxyz"
// const ABCD = "ABCDEFGHIJKLMNOPQRSTUVWXYZ"

// var dy = [...]int{1, 1, 0, -1, -1, -1, 0, 1}
// var dx = [...]int{0, 1, 1, 1, 0, -1, -1, -1}

// var dx = [...]int{0, 1, 0, -1}
// var dy = [...]int{1, 0, -1, 0}

var inf int = 1e13
var mod = 1000000007

// ---------------------------------------------------------
func main() {
	log.SetFlags(log.Lshortfile)
	next := newScanner()
	s := next.next()
	if strings.Contains(s, "AC") {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}

}

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

// Pair is liked C++ pair
type Pair struct {
	a, b int
}

// Pairs is sorted by []Pair struct
type Pairs []Pair

func (p Pairs) Len() int {
	return len(p)
}
func (p Pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p Pairs) Less(i, j int) bool {
	if p[i].a < p[j].a {
		return true
	} else if p[i].a == p[j].a {
		return p[i].b < p[j].b
	}
	return false
}

// -------------------------------
func in(c, a, z int) bool {
	return c >= a && c < z
}

func btoi(b bool) int {
	if b {
		return 1
	}
	return 0
}

func itob(a int) bool {
	if a == 0 {
		return false
	}
	return true
}

func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}

func sum(a ...int) int {
	r := a[0]
	if len(a) > 1 {
		for i := 1; i < len(a); i++ {
			r += a[i]
		}
	}
	return r
}

func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}

func minmax(a, b int) (int, int) {
	if a > b {
		return b, a
	}
	return a, b
}

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

// ---------- buffered scanner -----------------------------------------
type scanner struct {
	r   *bufio.Reader
	buf []byte
	p   int
}

func newScanner() *scanner {
	rdr := bufio.NewReaderSize(os.Stdin, 10000)
	return &scanner{r: rdr}
}
func (s *scanner) next() string {
	s.pre()
	start := s.p
	for ; s.p < len(s.buf); s.p++ {
		if s.buf[s.p] == ' ' {
			break
		}
	}
	result := string(s.buf[start:s.p])
	s.p++
	return result
}
func (s *scanner) Line() string {
	s.pre()
	start := s.p
	s.p = len(s.buf)
	return string(s.buf[start:])
}
func (s *scanner) Int() int {
	v, _ := strconv.Atoi(s.next())
	return v
}
func (s *scanner) Int64() int64 {
	v, _ := strconv.ParseInt(s.next(), 10, 64)
	return v
}
func (s *scanner) pre() {
	if s.p >= len(s.buf) {
		s.readLine()
		s.p = 0
	}
}
func (s *scanner) readLine() {
	s.buf = make([]byte, 0)
	for {
		l, p, e := s.r.ReadLine()
		if e != nil {
			panic(e)
		}
		s.buf = append(s.buf, l...)
		if !p {
			break
		}
	}
}


Measured memory_bytes: 640
import java.util.*;

class Main {
    public static void main(String[] args){
        Scanner s = new Scanner(System.in);
        int a = s.nextInt();
        int b = s.nextInt();
        
        if (a > b) {
            System.out.println("a > b");
        } else if (a < b) {
            System.out.println("a < b");
        } else {
            System.out.println("a == b");
        }
    }
}


Measured memory_bytes: 26108
#include <stdio.h>

int main(void)
{
    int a, b, c, empty = 0;
    scanf("%d%d%d", &a, &b, &c);

    if (a <= b){
        empty = a;
        a = b;
        b = empty;
    }

    if (b <= c){
        empty = b;
        b = c;
        c = empty;
    }

    if (a <= b){
        empty = a;
        a = b;
        b = empty;
    }

    printf ("%d",10 * a + b + c);

    return (0);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define int long long
#define P(x) {if (debug) cout << x << endl;}
#define H(x) P(#x << ": " << (x))
#define FR(i,a,b) for (int i=(a); i<(b); i++)
#define F(i,n) FR(i,0,n)
#define D(i,n) for (int i=(n); i-->0;)
#define S(s) (int)(s).size()
#define ALL(v) v.begin(), v.end()
#define V vector
#define pb push_back
#define mt make_tuple
using namespace std;
template<class T> ostream& operator<<(ostream& os, V<T> v) {
    F(i,S(v)) os<<(i?" ":"")<<v[i]; return os;}
const bool debug = 1;

int n;
V<int> a;
V<V<int>> mem;

int dp(int i, bool x, int v) {
    int &res = mem[x][i];
    if (res == -1) {
        res = abs(v-a[n-1]);
        FR(j,i,n-1) {
            int par = dp(j+1, !x, a[j]);
            res = x ? max(res, par) : min(res, par);
        }
    }
    return res;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL);
    int z,w; cin>>n>>z>>w;
    a.resize(n);
    F(i,n) cin>>a[i];
    mem.assign(2, V<int>(n+1, -1));
    cout<<dp(0, true, w)<<endl;
}

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

using namespace std;
typedef long long ll;

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

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

  ll all = a[0] ^ a[1];
  for (int i = 2; i < n; ++i) {
    all = all ^ a[i];
  }

  vector<ll> ans(n, -1);
  for (int i = 0; i < n; ++i) {
    ans[i] = a[i] ^ all;
  }

  for (int i = 0; i < n; ++i) {
    cout << ans[i];
    if (i == n - 1) puts("");
    else cout << ' ';
  }
  return 0;
}



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

using namespace std;

#define int long long
#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define INF 1e9
#define LINF 1e18

typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> Pi;
typedef pair<P, P> PP;

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

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int H, W;
int a[510][510];
vector<PP> res;

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

    cin >> H >> W;
    FOR(i, 1, H + 1) FOR(j, 1, W + 1) cin >> a[i][j];
    FOR(i, 1, H + 1) FOR(j, 1, W) {
        if(a[i][j] % 2) {
            ++a[i][j + 1];
            --a[i][j];
            res.push_back(PP(P(i, j), P(i, j + 1)));
        } 
    }
    FOR(i, 1, H) {
        if(a[i][W] % 2) {
            ++a[i + 1][W];
            --a[i][W];
            res.push_back(PP(P(i, W), P(i + 1, W)));
        }
    }
    cout << res.size() << endl;
    rep(i, res.size()) {
        cout << res[i].first.first << " " << res[i].first.second << " ";
        cout << res[i].second.first << " " << res[i].second.second << endl;
    }
    return 0;
}

Measured memory_bytes: 8432
#include<stdio.h> 
#define N 105

int main(){
  int x;
  int n,k;
  int i,j;
  int v,a[N][N];

  for(i=0; i < N; i++){
    for(j=0; j < N; j++){
      a[i][j]=0;
    }
  }
scanf("%d",&n);
  for(i=1; i <=n; i++){
    scanf("%d%d",&x,&k);
    for(j=1; j <=k; j++){
      scanf("%d",&v);
      a[x][v]=1;
    }
  }

  for(i=1; i <=n; i++){
    for(j=1; j <=n; j++){
      printf("%d",a[i][j]);
      if(j==n) printf("\n");
      else printf(" ");
    }
  }

  return 0;
}

Measured memory_bytes: 648
#include <cstdio>
#define N (int)(2e4+10)
#define INF (int)(1e9)
int n;
int a[N];
int val[N];
int b[N];

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;++i)scanf("%d",&val[i]);
	a[n]=INF,b[1]=INF;
	for(int i=2;i<=n;++i)b[i]=b[i-1]-n;
	for(int i=n-1;i;--i)a[i]=a[i+1]-n;
	for(int i=1;i<=n;++i)a[val[i]]-=(n-i);
	for(int i=1;i<=n;++i)printf("%d ",a[i]);
	printf("\n");
	for(int i=1;i<=n;++i)printf("%d ",b[i]);
}

Measured memory_bytes: 768
#include<iostream>
using namespace std;
int main()
{
	int n;
	int sum=0;
	cin>>n;
	int a[2][n];
	for(int j=0;j<2;j++)
		for(int i=0;i<n;i++)
		{
		cin>>a[j][i];
		sum+=a[j][i];
		}
	
	int b[n-1];
	for(int i=0;i<n;i++)
	{
		b[i]=sum;
		for(int j=0;j<n;j++)
		{
			if(j<i)
			b[i]-=a[1][j];
			else if(j>i)
			b[i]-=a[0][j];
		}
	}
	int max=-1;
	for(int i=0;i<n;i++)
	{
		if(b[i]>max)
		max=b[i];
	}
	
	cout<<max<<endl;
	return 0;
}

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

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


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

typedef long long ll;
typedef unsigned long long ull;

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout.precision(12);
    cout.setf(ios_base::fixed, ios_base::floatfield);
    
    string s, t, a, ans = "UNRESTORABLE";
    cin >> s >> t;
    if(s.size()<t.size()) goto output;
    for(int i=0;i<=s.size()-t.size();i++){
        for(int j=0;j<t.size();j++){
            if(s[i+j] != '?' && s[i+j] != t[j]) goto next;
        }
        a = "";
        for(int j=0;j<i;j++) a.push_back(s[j]=='?'?'a':s[j]);
        a = a + t;
        for(int j=i+t.size();j<s.size();j++) a.push_back(s[j]=='?'?'a':s[j]);
        ans = ans=="UNRESTORABLE"?a:min(ans, a);
next:   ;
    }
output:
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <stdlib.h>
int main(void){
int n;
char s[105];
int count=0;
int max=0;
scanf("%d",&n);
scanf("%s",s);

for(int count2=0;s[count2]!='\0';count2++){
if(s[count2]=='I'){count++;}
else{count--;}
if(max<=count){max=count;}
}
printf("%d",max);
}

Measured memory_bytes: 128
#include <cstdlib>
#include <iostream>

int main(int argc, char *argv[]) {
  std::string n;
  std::cin >> n;
  int sum = 0;
  for (char c : n) {
    sum += c - '0';
  }
  std::cout << (sum % 9 == 0 ? "Yes" : "No") << std::endl;
}


Measured memory_bytes: 3292
#include<iostream>
#include <string>
#include<algorithm>
#include <set>
#include <cmath>
using namespace std;

int main(void){
	ios::sync_with_stdio(false);
	int N, H, W, sum, j, k;
	cin >> N;
	cin >> H;
	cin >> W;
	sum = (N - W + 1)*(N - H + 1);
	cout << sum;
	return 0;
}


Measured memory_bytes: 256