akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i = (a); i < (b); ++i)
#define REP(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const int INF = 1e9;
const double PI = acos(-1.0);

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

	string s;
	string p;
	cin >> s >> p;
	
	string t1, t2;
	REP(i, p.size()) t1 += s[i];
	for(int i = p.size(); i > 0; --i) t2 += s[s.size() - i];
	
	s = t2 + s + t1;
	
	if((int)s.find(p) == -1) cout << "No";
	else cout << "Yes";
	
	cout << "\n";
	
	return 0;
}

Measured memory_bytes: 1196
n = int(input())
a = list(map(int, input().split()))

def f(isPosi):
    total = 0
    cnt = 0
    for i in a:
        total += i
        if isPosi:
            if total >= 0:
                cnt += 1 + total
                total = -1
            isPosi = False
        else:
            if total <= 0:
                cnt += 1 - total
                total = 1
            isPosi = True
    return cnt

print(min(f(True), f(False)))

Measured memory_bytes: 14332
#include<iostream>
using namespace std;
int main(){
  int a,b,c;
  while(cin >> a >> b >> c && a!=-1||b!=-1||c!=-1){
    if(a==-1||b==-1)cout<<"F"<<endl;
    else if(a+b>=80)cout<<"A"<<endl;
    else if(a+b>=65)cout<<"B"<<endl;
    else if((a+b>=50)||(a+b>=30&&c>=50))cout<<"C"<<endl;
    else if(a+b>=30)cout<<"D"<<endl;
    else cout << "F" << endl;
  }
}

Measured memory_bytes: 1156
#include <iostream>
#include <cstdio>
#include <queue>
#include <cstring>

using namespace std;

char field[52][52];
bool black[52][52];
bool white[52][52];

typedef pair<int, int> p;

int t_x[] = {1, 0, -1, 0};
int t_y[] = {0, 1, 0, -1};

void search(int h, int w)
{
  char c = field[h][w];
  queue<p> que;
  que.push( p(h, w) );
  while ( !que.empty() ) {
    p n_c = que.front();
    //cout << n_c.first << " " << n_c.second << endl;
    que.pop(); 

    for ( int i = 0; i < 4; i++ ) {
      int t_h = n_c.first + t_x[i];
      int t_w = n_c.second + t_y[i];
      if ( field[t_h][t_w] == '#' ) continue;
      if ( field[t_h][t_w] == c || field[t_h][t_w] == '.' ) {
	if ( c == 'W') { 
	  if(!white[t_h][t_w]) {
	    white[t_h][t_w] = true;
	  } else {
	    continue;
	  }
	}
 	if (c == 'B') {
	  if (!black[t_h][t_w]) {
	    black[t_h][t_w] = true;
	  } else {
	    continue;
	  }
	}
	que.push( p(t_h, t_w) );
      }
    }
  }
}


int main()
{
  while ( true ) {
    int width, height;
    cin >> width >> height;

    if ( width == 0 && height == 0 ) break;

    memset(field, '#', sizeof field);
    memset(black, false, sizeof black);
    memset(white, false, sizeof white);

    for ( int i = 1; i <= height; i++ ) {
      for ( int j = 1; j <= width; j++ ) {
	cin >> field[i][j];
      }
    }
    
    for ( int i = 1; i <= height; i++ ) {
      for ( int j = 1; j <= width; j++ ) {
	if ( field[i][j] == 'W' && !white[i][j] || field[i][j] == 'B' && !black[i][j]) {
	  search(i, j);
	}
      }
    }
    for (int i = 1; i <= height; i++) {
      for (int j = 1; j <= width; j++) {
	//cout << ((black[i][j]) ? "B" : ".");
      }
      //cout << endl;
    }
    for (int i = 1; i <= height; i++) {
      for (int j = 1; j <= width; j++) {
	//cout << ((white[i][j]) ? "W" : ".");
      }
      //cout << endl;
    }
    int b_counter = 0, w_counter = 0;
    for (int i = 1; i <= height; i++) {
      for (int j = 1; j <= width; j++) {
	if (field[i][j] != '.') continue;
	if (!black[i][j] && white[i][j]) w_counter++;
	if (black[i][j] && !white[i][j]) b_counter++;
      }
    }
    cout << b_counter << " " << w_counter << endl;
  }
  return 0;
}

Measured memory_bytes: 0
### constant

MAX_INT = 1 << 30
DRCS = [[1, 0], [0, -1], [-1, 0], [0, 1]]

### main

h, w, n = gets.strip.split(' ').map{|s| s.to_i}

brd = (h + 2).times.map{(w + 2).times.map{0}}
(0..(h + 1)).each{|y| brd[y][0] = brd[y][w + 1] = -1}
(0..(w + 1)).each{|x| brd[0][x] = brd[h + 1][x] = -1}

start = nil
dests = []

for y in (1..h)
  hl = gets.strip
  for x in (1..w)
    case hl[x - 1]
    when 'S'
      start = [y, x]
    when 'X'
      brd[y][x] = -1
    when '1'..'9'
      dests[hl[x - 1].to_i - 1] = [y, x]
    end
  end
end
#p brd
#p start
#p dests

total = 0

for dest in dests
  dists = (h + 2).times.map{(w + 2).times.map{MAX_INT}}
  dists[start[0]][start[1]] = 0

  q = [start]

  while ! q.empty?
    u = q.min{|a, b| dists[a[0]][a[1]] <=> dists[b[0]][b[1]]}
    q.delete u

    y, x = u
    du = dists[y][x]

    break if u == dest

    for drc in DRCS
      y0 = y + drc[0]
      x0 = x + drc[1]

      if brd[y0][x0] != -1
        dv = dists[y0][x0]
        if dv > du + 1
          dists[y0][x0] = du + 1
          q << [y0, x0] if dv >= MAX_INT
        end
      end
    end
  end

  total += du
  start = dest
end

puts total

Measured memory_bytes: 40680
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String {
            bytes
                .by_ref()
                .map(|r| r.unwrap() as char)
                .skip_while(|c| c.is_whitespace())
                .take_while(|c| !c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

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

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

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_imports)]
use std::cmp::{min, max};

fn main() {
    input!{
        k: usize
    }
    if k <= 10 {
        println!("{}", k);
        return;
    }
    let mut a: Vec<usize> = vec![0, 1];
    for _ in 10..k {
        a[0] += 1;
        for i in 0..a.len() - 1 {
            if a[i] == 10 || a[i] > a[i + 1] + 1 {
                a[i] = 0;
                a[i + 1] += 1;
            } else {
                break;
            }
        }
        let l = a.len();
        if a[l - 1] == 10 {
            a[l - 1] = 0;
            a.push(1);
        }
        let mut f = false;
        for i in (0..a.len() - 1).rev() {
            if f && a[i] > 0 || a[i + 1] > a[i] + 1 {
                a[i] = a[i + 1] - 1;
                f = true;
            }
        }
    }
    let mut ans = 0;
    a.reverse();
    for &x in &a {
        ans = ans * 10 + x;
    }
    println!("{}", ans);
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,m;
    cin>>n>>m;
    int x[m],y[m],z[m];
    vector<vector<int>>pas(n);
    for(int i=0;i<m;i++){
        cin>>x[i]>>y[i]>>z[i];
        pas[x[i]-1].push_back(y[i]-1);
        pas[y[i]-1].push_back(x[i]-1);
    }
    int check[n]={};
    int cost=0;
    for(int i=0;i<n;i++){
        if(check[i])continue;
        cost++;
        queue<int>q;
        q.push(i);
        check[i]=1;
        while(q.size()){
            int f=q.front();
            q.pop();
            for(int j=0;j<pas[f].size();j++){
                if(check[pas[f][j]]==0){
                    check[pas[f][j]]=1;
                    q.push(pas[f][j]);
                }
            }
        }
    }
    cout<<cost<<endl;
    return 0;
}

Measured memory_bytes: 8056
package main

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

var mod int = 1e9 + 7

func main() {
	io := NewIo(os.Stdin, os.Stdout)
	defer io.Flush()
	n := io.NextInt()
	ans := ModPow(10, n, mod)
	ans = (ans - ModPow(9, n, mod) + mod) % mod
	ans = (ans - ModPow(9, n, mod) + mod) % mod
	ans = (ans + ModPow(8, n, mod)) % mod
	io.Println(ans)
}

// ModMul returns a*b with mod
func ModMul(a, b, mod int) int {
	a, b = a%mod, b%mod
	if b == 0 {
		return 0
	}
	if a*b/b == a {
		return a * b % mod
	}
	panic("overflow")
}

// ModPow returns base^n with mod
func ModPow(base, n, mod int) int {
	ans := 1
	for ; n > 0; n >>= 1 {
		if n&1 == 1 {
			ans = ModMul(ans, base, mod)
		}
		base = ModMul(base, base, mod)
	}
	return ans
}

// Io is I/O object
type Io struct {
	reader    *bufio.Reader
	writer    *bufio.Writer
	tokens    []string
	nextToken int
}

// NewIo returns a new Io instance
func NewIo(r io.Reader, w io.Writer) *Io {
	return &Io{
		reader: bufio.NewReader(r),
		writer: bufio.NewWriter(w),
	}
}

// Flush flushes writer
func (io *Io) Flush() {
	err := io.writer.Flush()
	if err != nil {
		panic(err)
	}
}

// NextLine scans a line from stdin
func (io *Io) NextLine() string {
	var buffer []byte
	for {
		line, isPrefix, err := io.reader.ReadLine()
		if err != nil {
			panic(err)
		}
		buffer = append(buffer, line...)
		if !isPrefix {
			break
		}
	}
	return string(buffer)
}

// Next return a word from stdin
func (io *Io) Next() string {
	for io.nextToken >= len(io.tokens) {
		line := io.NextLine()
		io.tokens = strings.Fields(line)
		io.nextToken = 0
	}
	r := io.tokens[io.nextToken]
	io.nextToken++
	return r
}

// NextInt returns an integer from stdin
func (io *Io) NextInt() int {
	i, err := strconv.Atoi(io.Next())
	if err != nil {
		panic(err)
	}
	return i
}

// Println is a wrapper of fmt.Fprintln
func (io *Io) Println(a ...interface{}) {
	fmt.Fprintln(io.writer, a...)
}


Measured memory_bytes: 1780
A,B,C,X,Y = map(int, input().split())
cost1 = A*X + B*Y
cost2 = max(X,Y)*2*C
cost3 = X*2*C
if Y - X > 0:
	cost3 += (Y-X) * B
cost4 = Y*2*C
if X-Y > 0:
	cost4 += (X-Y) * A
print(min(cost1, cost2, cost3, cost4))

Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef unsigned long long llu;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define sz(a) int((a).size())
#define trace(x) cerr<<#x<<": "<<x<<" "<<endl;
#define pb push_back
#define mp make_pair
#define ft first
#define sd second
#define lp(i, a, b) for(ll i = a; i < b; i++)
#define lpr(i, a, b) for(ll i = a; i >= b; i--)
#define all(c) c.begin(), c.end()
#define tr(container, it) for(typeof(container.begin()) it = container.begin(); it != container.end(); it++)
void yes(){
    cout << "YES" << endl;
}
void no(){
    cout << "NO" << endl;
}
void nl(){
    cout << endl;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    int n, k;
    cin >> k >> n;
    vector <ll> a(n), b;
    lp(i, 0, n)
        cin >> a[i];
    ll o = a[n - 1] - a[0];
    b.pb(o);
    lp(i, 0, n - 1){
        o = k + a[i];
        o -= a[i + 1];
        b.pb(o);
    }
    sort(all(b));
    cout << b[0] << endl;
}


Measured memory_bytes: 3956
n, t = map(int,input().split())
a = list(map(int,input().split()))
amax = [a[-1]] * n

for i in range(n-2, -1, -1):
    amax[i] = max(amax[i+1], a[i])

cnt = 0
v = -10**10
for i in range(n-1):
    b = amax[i+1] - a[i]
    if b > v:
        v = b
        cnt = 1
    elif b == v:
        cnt += 1
print(cnt)

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

ll n,w;
ll dp[105][100005];
const ll INF=1LL<<60;

int main(){
    cin >> n >> w;
    ll weight[n];
    ll value[n];
    for(ll i=0;i<n;i++) cin >> weight[i] >> value[i];
    for(ll i=0;i<=n;i++){
        for(ll j=0;j<=100000;j++) dp[i][j]=INF;
    }
    dp[0][0]=0;
    for(ll i=0;i<n;i++){
        for(ll sum_v=0;sum_v<=100000;sum_v++){
            if(sum_v-value[i]>=0) dp[i+1][sum_v]=min(dp[i][sum_v-value[i]]+weight[i],dp[i+1][sum_v]);
            dp[i+1][sum_v]=min(dp[i+1][sum_v],dp[i][sum_v]);
        }
    }
    ll res=0;
    for(ll sum_v=0;sum_v<=100000;sum_v++){
        if(dp[n][sum_v]<=w) res=sum_v;
    }
    cout << res << endl;
}


Measured memory_bytes: 82520
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
typedef long long ll;

int main()
{
    long N;
    string S;
    cin >> N >> S;

    long count = 1;
    rep(i, N - 1) {
        if (S[i] == S[i + 1]) {
            continue;
        }
        count++;
    }

    cout << count << endl;

    return 0;
}

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

using namespace std;
using ll = long long;

void insertion_sort(vector<int> &a, int n, int g, int &cnt) {
    for(int i = g; i < n; ++i) {
        for(int j = i; j >= g; j -= g) {
            if(a[j] < a[j - g]) {
                swap(a[j], a[j - g]);
                cnt++;
            }
            else break;
        }
    }
}

void shell_sort(vector<int> &a, int n, int &cnt, vector<int> G) {
    for(int i = G.size() - 1; i >= 0; --i) insertion_sort(a, n, G[i], cnt);
}

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

    int n, cnt = 0;
    cin >> n;
    vector<int> a(n);
    for(int i = 0; i < n; ++i) cin >> a[i];

    vector<int> G = {1};
    for(int i = 0; G[i] <= n; ++i) G.emplace_back(3 * G[i] + 1);
    G.pop_back();
    int m = G.size();

    shell_sort(a, n, cnt, G);

    printf("%d\n", m);
    for(int i = m - 1; i >= 0; --i) {
        printf("%d", G[i]);
        printf(i == 0 ? "\n" : " ");
    }
    printf("%d\n", cnt);
    for(int i: a) printf("%d\n", i);

    return 0;
}


Measured memory_bytes: 6796
using System;
using System.IO;
using System.Collections.Generic;
using System.Numerics;

namespace abc139
{
    class Program
    {
        static void Main(string[] args)
        {
            //Console.SetIn(new StreamReader("input.txt"));
            solve_abc139A();
        }

        public static void solve_abc139A()
        {
            string s1 = Console.ReadLine();
            string s2 = Console.ReadLine();

            int c = 0;

            if (s1[0] == s2[0])
            {
                c++;
            }
            if (s1[1] == s2[1])
            {
                c++;
            }
            if (s1[2] == s2[2])
            {
                c++;
            }
            Console.WriteLine(c);
        }
    }
}


Measured memory_bytes: 13140
#pragma GCC optimize("Ofast")
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using ull = unsigned long long;
#define PI 3.141592
#define all(a) (a).begin(), (a).end()


int main(){
    int N, K;
    cin >> N >> K;
    vector<int> H(N);
    for(int i = 0; i < N; i++) cin >> H[i];
    int count = 0;
    for(int h : H){
        if(h >= K) count++;
    }
    cout << count << endl;
}


Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> lpair;
const ll MOD = 1e9 + 7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " ";} cout<<endl;
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    string S;
    cin >> N >> S;
    ll ans = INF;
    ll sum[200010] = {};
    rep(i,0,N){
        if(S[i] == '#'){
            sum[i+1] = sum[i]+1;
        }else{
            sum[i+1] = sum[i]; 
        }
    }
    rep(p,0,N+1){
        ll tt = 0;
        tt += sum[p];
        tt += (N - p - (sum[N] - sum[p]));
        ans = min(ans, tt);
    }
    print(ans);
}

Measured memory_bytes: 2196
import numpy as np
from math import modf

N, D = [int(i) for i in input().split(" ")]

vectors = np.empty((N, D))
for i in range(N):
    vectors[i, :] = np.array([int(i) for i in input().split(" ")])

count = 0
for i, u in enumerate(vectors):
    for v in vectors[i+1:, :]:
        if modf(np.linalg.norm(u - v))[0] < 1e-7:
            count += 1

print(count)

Measured memory_bytes: 12500
import sys
input = sys.stdin.buffer.readline

from bisect import bisect_right

N, D, A = map(int, input().split())
XH = [list(map(int, input().split())) for _ in range(N)]

XH.sort()
X = [x for x, h in XH]

check = [0] * (N + 1)


index = 0
pt = XH[index][0] + 2 * D
ht = (-(-XH[index][1] // A)) * A
minus = ht
answer = -(-XH[index][1] // A)
bi = bisect_right(X, pt)
check[bi] += ht

while 1:
  flag = 1
  for i in range(index, N):
    minus -= check[i]
    XH[i][1] -= minus
    check[i] = 0
    if XH[i][1] > 0:
      index = i
      flag = 0
      break
  if flag:
    break
  pt = XH[index][0] + 2 * D
  ht = (-(-XH[index][1] // A)) * A
  minus += ht
  answer += -(-XH[index][1] // A)
  bi = bisect_right(X, pt)
  check[bi] += ht
                 
print(answer)

Measured memory_bytes: 84864
n = gets.to_i
ryori = gets.split.map &:to_i
manzoku = gets.split.map &:to_i
add = gets.split.map &:to_i
sum = 0

n.times do |i|
    eat = ryori[i]-1
    sum += manzoku[eat]
    if ryori[i]+1 == ryori[i+1]
        sum += add[eat]
    end
end

puts sum


Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#include <string>
const int mxN=1e5;
const int maxN=5e3;
#define ld long double
#define pb push_back
#define mp make_pair
#define ins insert
#define vi vector<int>

int main()
{
    ll n;
    cin >> n;
    string s="";
    while(n>0)
    {
        ll ost=n%26;
        n/=26;
        if(ost==0)
        {
            n--;
            s='z'+s;
        }
        else
            s=(char('a'+ost-1))+s;
    }
    cout << s;
}

Measured memory_bytes: 3612
//高知能系Vtuberの高井茅乃です。
//Twitter: https://twitter.com/takaichino
//YouTube: https://www.youtube.com/channel/UCTOxnI3eOI_o1HRgzq-LEZw

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

#define INF INT_MAX
#define LLINF LLONG_MAX
#define REP(i,n) for(int i=0;i<n;i++)
#define REP1(i,n) for(int i=1;i<=n;i++)
#define MODA 1000000007 

template <typename T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
    for (T& x: vec) { is >> x; }
    return is;
}

int main() {
	ll ans = 0;
	ll tmp;
	int n;
	cin >> n;
	if (n>= 30) cout << "Yes" << endl;
	else cout << "No" << endl;
	
	//cout << ans << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
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 <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for (int i = 0; i < sz(v); i++) {
        os << v[i];
        if (i < sz(v) - 1) os << " ";
    }
    return os;
}
int main() {
    int l, r, d;
    cin >> l >> r >> d;
    int ans = 0;
    for (int i = l; i <= r; i++)
        if (i % d == 0) ans++;
    cout << ans << endl;
}

Measured memory_bytes: 3520
//#pragma comment(linker, "/stack:200000000") //  (UNCOMMENT WHEN HAVING LOTS OF RECURSIONS)
#pragma GCC optimize("O3")
#pragma GCC optimize("Ofast")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("unroll-loops")  // $ (UNCOMMENT WHEN TRYING TO BRUTEFORCE WITH A LOT OF LOOPS)\

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

#define fast_cin ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define pb push_back
#define all(con) (con).begin(), (con).end()
#define fi first
#define se second
#define rep(i,a,b) for(int i=a;i<b;++i)
#define fre(i,a,b) for(int i=a;i<=b;i++)
#define rpe(i,a,b) for(i=a-1;i>=b;i--)
#define rp(i,n) rep(i,0,n)
#define fr(i,n) fre(i,1,n)
#define ff(i,a,b) for(int i=a;i<=b;i++)

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

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
// order_of_key (val): returns the no. of values less than val
// find_by_order (k): returns the iterator to kth largest element.(0-based)

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

#define TRACE
#ifndef ONLINE_JUDGE
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
	cerr << name << " : " << arg1 << endl;}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
	const char* comma = strchr(names + 1, ',');cerr.write(names, comma - names) << " : " << arg1<<"  ";__f(comma+1, args...);}
#else
#define trace(...)
#endif

template<class S,class T> ostream& operator<<(ostream& o,const pair<S,T> &p){
	return o<<"("<<p.fs<<","<<p.sc<<")";
}
template<class T> ostream& operator<<(ostream& o,const vector<T> &vc){
	o<<"{";
	for(const T& v:vc) o<<v<<",";
	o<<"}";
	return o;
}

int modpow(int x, int n, int m) {
	x %= m;
	int res = 1;
	while(n > 0) {
		if(n & 1)
		res = res * x % m;
		x = x * x % m;
		n >>= 1;
	}
	return res;
}

const long long inf = 2e18 ;
const int mod = 1e9+7 ;
// const int mod = 998244353 ;

const int N = 1e5 + 10 ;

void solve() {
        int x,n;
        cin>>n>>x;
        int s=0;
        int a[n];
        for(int i=0;i<n;i++) {
                int y;
                cin>>y;
                a[i]=y;
        }
        sort(a,a+n);
        int f=n-x;
        int sum=0;
        for(int i=0;i<f;i++) {
                sum+=a[i];
        }
        cout<<sum<<endl;
}

signed main() {
        fast_cin;
	srand(chrono::high_resolution_clock::now().time_since_epoch().count());
        #ifndef ONLINE_JUDGE
        // freopen("input.txt", "r", stdin);
        // freopen("output.txt", "w", stdout);
    	#endif

	int tests=1;
	// cin>>tests;
	while(tests--) {
		solve();
	}

return 0 ;
}



Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,q,s,t,a,b,l,r,x;
  long long ans=0;
  cin >> n >> q >> s >> t;
  vector<long long> vec;
  for(int i=0;i<=n;i++){
    cin >> a;
    if(i != 0){
      vec.push_back(a-b);
      if(vec[i-1] > 0) ans -= vec[i-1]*s;
      else ans -= vec[i-1]*t;
    }
    b = a;
  }
  vec.push_back(0);
  for(int i=0;i<q;i++){
    cin >> l >> r >> x;
    if(vec[l-1] > 0) ans += vec[l-1]*s;
    else ans += vec[l-1]*t;
    if(vec[r] > 0) ans += vec[r]*s;
    else ans += vec[r]*t;
    vec[l-1] += x;
    if(r != n) vec[r] -= x;
    if(vec[l-1] > 0) ans -= vec[l-1]*s;
    else ans -= vec[l-1]*t;
    if(vec[r] > 0) ans -= vec[r]*s;
    else ans -= vec[r]*t;
    cout << ans << endl;
  }
  return (0);
}

Measured memory_bytes: 4968
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace __gnu_pbds;
using namespace std;
     
#define mp make_pair
#define sz(x) (int)((x).size())
#define all(x) (x).begin(),(x).end()
#define FO(x) {freopen(#x".in","r",stdin);freopen(#x".out","w",stdout);}
#define eb emplace_back
 
typedef pair< int, int > pii;
typedef pair< long long, long long > pll;
typedef long long ll;
typedef unsigned long long ull;
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef vector< ll > vll;
typedef vector< vll > vvll;
typedef vector< pii > vpii;
typedef vector< vpii > vvpii;
typedef vector< pll > vpll;
typedef long double ld;
typedef vector< ld > vld;
typedef unsigned int uint;
 
const ll MOD2 = 1e9 + 7;
const int MOD = 1e9 + 7;
 
const ull infull = numeric_limits<unsigned long long>::max();
 
void fix(int &x, ll MOD) {
    x = (x % MOD);
    if(x < 0) x += MOD;
    return;
}
 
ll lgput(ll a, ll b, ll MOD) {
    ll ret = 1;
    a %= MOD;
    while(b) {
        if(b&1) ret = ret*a % MOD;
        a = a*a % MOD;
        b >>= 1;
    }
 
    return ret;
}
 
ll inv(ll a, ll MOD) {
    return lgput(a, MOD-2, MOD);
}
 
template <uint MD> struct ModInt {
    using M = ModInt;
    const static M G;
    uint v;
    ModInt(ll _v = 0) { set_v(uint(_v % MD + MD)); }
    M& set_v(uint _v) {
        v = (_v < MD) ? _v : _v - MD;
        return *this;
    }
    explicit operator bool() const { return v != 0; }
    M operator-() const { return M() - *this; }
    M operator+(const M& r) const { return M().set_v(v + r.v); }
    M operator-(const M& r) const { return M().set_v(v + MD - r.v); }
    M operator*(const M& r) const { return M().set_v(uint(ull(v) * r.v % MD)); }
    M operator/(const M& r) const { return *this * r.inv(); }
    M& operator+=(const M& r) { return *this = *this + r; }
    M& operator-=(const M& r) { return *this = *this - r; }
    M& operator*=(const M& r) { return *this = *this * r; }
    M& operator/=(const M& r) { return *this = *this / r; }
    bool operator==(const M& r) const { return v == r.v; }
    const bool operator<(const M& o) const {return v < o.v; }
    M pow(ll n) const {
        M x = *this, r = 1;
        while (n) {
            if (n & 1) r *= x;
            x *= x;
            n >>= 1;
        }
        return r;
    }
    M inv() const { return pow(MD - 2); }
    friend ostream& operator<<(ostream& os, const M& r) { return os << r.v; }
};
 
using Mint = ModInt<(int)1e9 + 7>;

int main() { 
    #ifdef BLAT
        freopen("stdin", "r", stdin);
        freopen("stderr", "w", stderr);
    #endif
 
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cout.precision(12);
    srand(time(NULL));

    int n; ll k;
    cin >> n >> k;

    vvi nxt(63, vi(n));

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


    for(int i = 1; i < 63; ++i) {
        for(int j = 0; j < n; ++j) {
            nxt[i][j] = nxt[i-1][nxt[i-1][j]];
        }
    }

    int node = 0;

    for(int i = 0; i < 63; ++i) {
        if(k&(1LL<<i)) node = nxt[i][node];
    }

    cout << node + 1 << '\n';
    return 0;
}

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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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

int n;
string s;

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

	cin>>n>>s;
	int now=0,ans=0;
	REP(i,s.size()) {
		if(s[i]=='I') now++;
		else now--;
		ans=max(ans,now);
	}
	cout<<ans<<endl;

	return 0;
}


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

int main()
{
  int a, b, c, d;
  scanf("%d%d%d%d", &a, &b, &c, &d);

  if (abs(a - c) <= d || (abs(a - b) <= d && abs(c - b) <= d))
    puts("Yes");
  else
    puts("No");

  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define F first
#define S second
ll mod=1000000007;

int main(){
    std::ios::sync_with_stdio(false);
    int a,b;
    cin>>a>>b;
    int mi=max(a,b);
    int ans=mi;
    mi--;
    int mi1=min(a,b);
    if(mi<=mi1)ans+=mi1;
    else ans+=mi;
    cout<<ans<<endl;

    return 0;
}


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


int N;
int abc[100010][3];
int dp [100010][3];
int main()
{
    cin >> N;
    for(int i = 0; i < N; i++)
    {
        for(int j = 0; j < 3; j++) cin >> abc[i][j];
    }

    for(int k = 0; k < 3; k++) dp[0][k] = 0;

    for(int l = 0; l <= N; l++)
    {
        for(int m = 0; m < 3; m++)
        {
            dp[l + 1][m] = max(dp[l][(m + 1) % 3] + abc[l][m], dp[l][(m + 2) % 3] + abc[l][m]);
        }
    }
    
    cout << max(max(dp[N][0], dp[N][1]), dp[N][2]) << endl;
}

Measured memory_bytes: 2560
#include<bits/stdc++.h>
#include<vector>
using namespace std;
int main(void){

  while(true){
    int n, r;   cin >> n >> r;
    if(n == 0 && r == 0)    break;

    vector<int> yamahuda(n);
    for(int i = 0 ; i < n ; i++)  yamahuda[i] = i + 1;

    for(int i = 0 ; i < r ; i++){

      int p, c;   cin >> p >> c;
      vector<int> keep(c);
      for(int i = 0 ; i < c ; i++)
        keep[i] = yamahuda[n - p - c  + 1 + i];

      for(int i = 0 ; i < p - 1 ; i++)
        yamahuda[n - p - c + 1 + i] = yamahuda[n - p + 1 + i];

      for(int i = 0 ; i < c ; i++)
        yamahuda[n - c + i] = keep[i];

    }

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

  }

  return 0;
}


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

int main(){
	int N, M;
	cin >> N >> M;
	int road[N+1][N+1];
	rep(i,N+1)rep(j,N+1) road[i][j] = 0;
	rep(i,M) {
		int a, b;
		cin >> a >> b;
		road[a][b] += 1;
		road[b][a] += 1;
	}
	for (int i = 1; i <= N; i++) {
		int tot = 0;
		for (int j = 1; j <= N; j++) {
			tot += road[i][j];
		}
		cout << tot << endl;
	}
	return 0;
}


Measured memory_bytes: 3608
import java.io.*;
import java.util.ArrayList;
import java.util.HashMap;

class Main{
    public static void main(String[] args) throws IOException{
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String str = br.readLine();
        int N = Integer.parseInt(str);
        str = br.readLine();
        ArrayList<Long> cml = new ArrayList<>();
        cml.add((long)0);
        int cont = 0;
        for (String s:str.split(" ")){
            cml.add(cml.get(cont)+Integer.parseInt(s));
            cont++;
        }
        HashMap<Long,Long> map = new HashMap<>();
        for (long key:cml){
            if (map.containsKey(key)){
                map.put(key,map.get(key)+1);
            } else {
                map.put(key,(long)1);
            }
        }
        long ans = 0;
        for (long key:map.keySet()){
            ans += (map.get(key) * (map.get(key)-1))/2;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 93384
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define  all(x) (x).begin(),(x).end()
typedef long long ll;

#define MAX 100005

int partition(int A[], int p, int r){
    int x = A[r];
    int i = p - 1;
    for (int j = p; j < r; j++){
        if (A[j] <= x){
            i++;
            swap(A[i], A[j]);
        }
    }
    i++;
    swap(A[i], A[r]);
    return i;
}

void print(int A[], int n, int q){
    rep(i,n){
        if (i) cout << " ";
        if (i == q) cout << "[";
        cout << A[i];
        if (i == q) cout << "]";
    }
    cout << endl;
}

int main(){
    int n;
    cin >> n;
    int A[MAX];
    rep(i,n) cin >> A[i];
    int q = partition(A, 0, n-1);
    print(A, n, q);
}


Measured memory_bytes: 3408
#include<stdio.h>

int main(){

    unsigned int n, i, data;

    scanf("%d", &n);

    unsigned int reverse_list[n];

    for( i = n; i > 0; i--){
        scanf("%d", &data);
        reverse_list[i-1] = data;
    }

    for( i = 0; i < n; i++){
        printf("%d", reverse_list[i]);
        if ( i != n-1){
            printf(" ");
        }
    }

    printf("\n");

    return 0;

}


Measured memory_bytes: 2724
#include<bits/stdc++.h>
using namespace std;
typedef long long unsigned int ll;
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define rep(i, start, end) for(int i = start; i < (int)(end); ++i)

int main(){
    string n;
    cin >> n;
    for(auto c: n){
        if(c == '7'){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3592
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
using namespace std;
int main(int argc, char *argv[])
{
	int n,k;
	while(scanf("%d %d",&n,&k)!=EOF)
	{
		int a[52],s=0,i,j;
		for(i=0;i<n;i++)
		scanf("%d",&a[i]);
		sort(a,a+n);
		for(i=n-1,j=0;i>=0;i--,j++)
		{
			s=s+a[i];
			if(j==(k-1))break;
		}
		printf("%d\n",s);
	}
	return 0;
}

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

#define PI 3.14159265359
#define INF 1e9
#define LINF 1e18
#define IMOD 1000000007 
#define irep(i,n) for(int i = 0; i < (int)(n); i++)
#define irep2(i,a,n) for(int i = (int)(a); i <= (int)(n); i++)
#define lrep(i,n) for(long long  i = 0; i < (long long)(n); i++)
#define lrep2(i,a,n) for(long long i = (long long)(a); i <= (long long)(n); i++)

#define irrep(i,n) for(int i = (int)(n); i > -1; i--)
#define irrep2(i,a,n) for(int i = (int)(n); i >= (int)(a); i--)

typedef long long ll;
typedef std::vector<char> v_char;
typedef std::vector<v_char > v2_char;
typedef std::vector<double> v_double;
typedef std::vector<v_double > v2_double;
typedef std::vector<int> v_int;
typedef std::vector<v_int > v2_int;
typedef std::vector<ll> v_ll;
typedef std::vector<v_ll > v2_ll;
typedef std::vector<std::string> v_string;
typedef std::vector<v_string > v2_string;
typedef std::vector<bool> v_bool;
typedef std::vector<v_bool > v2_bool;
typedef std::pair<ll, ll> pll;
typedef std::pair<int, int> pii;

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

using namespace std; 

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

    v_string s(n+2);
    
    irep(i, m+2) {
        s[0] += "#"; 
        s[n+1] += "#"; 
    }

    irep2(i, 1, n) {
        string t;
        cin >> t;
        s[i] += "#";
        s[i] += t;
        s[i] += "#";
    }

    irep(i, n+2) {
        cout << s[i] << endl;
    }

    return 0;
}   
/** atcoder **/


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
 
 
 
void change(char *str){
  int len=strlen(str);
  int i;
  for(i=0;i<len;i++){
    if('a'<=str[i]&&str[i]<='z'){
      str[i]-=32;
    }
  }
}
 
int main(){
  char t[10000];
  char key[10000];
  char eofstr[]={"END_OF_TEXT"};
  int ans=0;
 
  scanf("%s",key);
  change(key);
 
  while(1){
    scanf("%s",t);
    if(strcmp(t,eofstr)==0){
      break;
    }
    change(t);
    if(strcmp(t,key)==0){
      ans++;
    }
  }
 
  printf("%d\n",ans);
  return 0;
}


Measured memory_bytes: 2044
n,m=map(int, input().split())
l=[]
for i in range(m):
    l.append(list(map(int, input().split())))
    l[i].append(i)
l.sort(key=lambda x:(x[0],x[1]))
t=1
l[0].append(str(l[0][0]).zfill(6)+str(1).zfill(6))
for i in range(1,m):
    if l[i][0]>l[i-1][0]:
        t=1
        l[i].append(str(l[i][0]).zfill(6)+str(1).zfill(6))
    else:
        t+=1
        l[i].append(str(l[i][0]).zfill(6)+str(t).zfill(6))

l.sort(key=lambda x:x[2])
for i in range(m):
    print(l[i][3])


Measured memory_bytes: 38600
import sys
import math
import itertools
import collections


def solve(N,K,D,A):
    ans = []
    for a in A:
        for n in a:
            ans.append(n)
    
    return N - len(set(ans))
def main():
    N,K = map(int,input().split())
    D = []
    A = []
    for _ in range(K):
        D.append(int(input()))
        A.append(list(map(int,input().split())))

    # solve()
    print(solve(N,K,D,A))

if __name__ == "__main__":
    main()


Measured memory_bytes: 9500
/*
 * To change this license header, choose License Headers in Project Properties.
 * To change this template file, choose Tools | Templates
 * and open the template in the editor.
 */

import java.util.Scanner;

/**
 *
 * @author c0117321c5
 */
public class Main {

    /**
     * @param args the command line arguments
     */
    public static void main(String[] args) {
        // TODO code application logic here
        Scanner sc=new Scanner(System.in);
        int number=sc.nextInt();
        int sum=0;
        for(int i=1; i<=number;i++){
            for(int j=1;j<=number;j++){
                for(int k=1;k<=number;k++){
                    sum++;
                }
            }
        }
        System.out.println(sum);
    }
    
}


Measured memory_bytes: 21588
typedef struct {
    char name[100];
    int t;
} data;
   
data array[100001];
int head=0,tail=0;


int main(void){
	int N,q,i,sum=0,cnt=0;
	scanf("%d %d",&N,&q);
	for(i=0;i<N;i++){
		scanf("%s %d",array[i].name,&array[i].t);
	}
	while(cnt!=N){
		if(q<array[head].t){
			array[head].t=array[head].t-q;
			sum+=q;
			array[tail]=array[head];
			if(tail==N-1) tail=0;
			else tail++;
		}
		else if(array[head].t!=0){
			sum+=array[head].t;
			array[head].t=0;
			printf("%s %d\n",array[head].name,sum);
			cnt++;
		}
		if(head==N-1) head=0;
		else	head++;
	}
    return 0;
}

Measured memory_bytes: 6736
#include<bits/stdc++.h>
#define eps 1e-9
#define MOD1 998244353
#define MOD2 1000000007
#define INV_10 299473306
#define INF 2000000000
#define PI 3.14159265358979323846
using namespace std;
int n, w;
pair<int, int> a[105];
long long dp[105][100005];
long long solve(int idx, int rem)
{
	long long imp=50000000000000LL;
	if(rem<=0)
		return 0;
	if(idx==n-1)
	{
		if(a[idx].second >= rem)
			return a[idx].first;
		return imp;
	}
	if(dp[idx][rem]!=-1)
		return dp[idx][rem];
	dp[idx][rem]=min(solve(idx+1, rem), a[idx].first+solve(idx+1, rem-a[idx].second));
	return dp[idx][rem];
}
int main()
{
	ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	cin >> n >> w;
	int sum=0;
	for(int i = 0; i < n; i++)
	{
		cin >> a[i].first >> a[i].second;
		sum+=a[i].second;
	}
	for(int i = 0; i < n; i++)
		for(int j = 0; j <= sum; j++)
			dp[i][j]=-1; 
	int ma=0;
	for(int i = 1; i <= sum; i++)
	{
		long long cu=solve(0, i);
		if(cu <= w)
			ma=i;
	}
	cout << ma << '\n';
}

Measured memory_bytes: 80128
#include <bits/stdc++.h>
using namespace std;
//#pragma GCC optimize ("O3")
//#pragma GCC target ("sse4")
#define endl "\n"
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
template<class T, class T2> inline bool chkmax(T &x, const T2 &y) { return x < y ? x = y, 1 : 0; }
template<class T, class T2> inline bool chkmin(T &x, const T2 &y) { return x > y ? x = y, 1 : 0; }
const ll mod = 1e9 + 7;
template<class T> inline void fix(T &x) {if(x >= mod | x <= -mod) {x %= mod;} if(x < 0) {x += mod;}}
#define out(x) cout << __LINE__ << ": " << (#x) << " = " << (x) << endl
  
signed main() {
    //ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
    ll n;
    cin >> n;
    ll ans = 0;
    for(ll a = 1; a <= n; a ++) {
    	ans += n / a;
    	if(n % a == 0) {
    		ans --;
    	}
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3632
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace atcorder_BeginnerContest_120
{
    class Program
    {

        static void Main(string[] args)
        {
            int[] dataArr = Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
            int a = dataArr[0];
            int b = dataArr[1];
            int k = dataArr[2];

            int retCnt = 0;
            if (a < b)
            {
                retCnt = a;
            }
            else
            {
                retCnt = b;
            }

            int endCnt = 0;
            while (true)
            {
                if ((0 == a % retCnt) && (0 == b % retCnt))
                {
                    endCnt++;
                }
                if (endCnt == k)
                {
                    break;
                }
                retCnt--;
            }

            Console.WriteLine(retCnt);

        }
    }
}



Measured memory_bytes: 13140
a, b, c = map(int, input().split())
cou = 0
abc = []
for i in a, b, c:
    m = (max(a, b, c) - i) // 2
    cou += m
    abc.append(2 * m + i)
if abc.count(max(abc)) == 2:
    cou += 2
elif abc.count(max(abc)) == 1:
    cou += 1


print(cou)

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

int main() {
  int X,A,B;
  string ans;
  cin >> X >> A >> B;
  if(B<=A){
    ans="delicious";
  }else if(B<=A+X){
    ans="safe";
  }else{
    ans="dangerous";
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#pragma GCC optimize ("O2")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define FFOR(i, a, b) FOR(i, a, b+1)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) FOR(i, 1, n+1)
#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
#define LEN(x) (int)(x).size()
#define DUMP(x) cerr<<__LINE__<<' '<<#x<<"="<<(x)<<endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair

using namespace std;
using lint = long long;
using pii =  pair<int, int>;
using pll =  pair<lint, lint>;
template <typename T> using vc = vector<T>;
template <typename T> using vvc = vector<vector<T>>;
template <typename T> inline bool chmax(T &a, T b){if(a<b){a = b; return true;} return false;}
template <typename T> inline bool chmin(T &a, T b){if(a>b){a = b; return true;} return false;}

const double PI = acos(-1);
constexpr lint ten(int n) {return n==0 ? 1 : ten(n-1)*10;}

class Task{
public:
    void solve(istream& in, ostream& out){
        int N;
        in>>N;
        vc<lint> A(N);
        lint X = 0;
        for(auto& a : A) in>>a, X ^= a;
        X ^= A[0] ^ A[1];
        lint S = A[0] + A[1];
        vvc<lint> dp(45, vc<lint>(4, -1));
        dp[0][0] = 0;
        REP(i, 44){
            REP(j, 4){
                if(dp[i][j]==-1) continue;
                // c: 繰り上がり
                // d: 0ならA[0]以下、1ならAより大きい
                int c = j >> 1 & 1, d = j & 1, e = A[0] >> i & 1;
                REP(a, 2){
                    int b = (X>>i&1) ^ a;
                    if((S>>i&1)!=(a^b^c)) continue;
                    int nxt = 0;
                    if((d==0 and a>e) or (d==1 and a>=e)) nxt = 1;
                    if(a+b+c>1) nxt += 2;
                    chmax(dp[i+1][nxt], dp[i][j]+((1ll*a)<<i));
                }
            }
        }
        if(dp[44][0]<=0) out<<"-1\n";
        else out<<A[0]-dp[44][0]<<'\n';
    }
};

int main(){
    istream& in(cin);
    ostream& out(cout);
    ios_base::sync_with_stdio(false);
    in.tie(nullptr), out.tie(nullptr);
    Task solver;
    solver.solve(in, out);
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<deque>
#include<regex>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
typedef int long long ll;
#define rep(i,n) for(int i=0;i<n;i++)

int main(){



   ll n;
   cin>>n;
   vector<ll> v(n+1);
   v[0]=0;
   rep(i,n){cin>>v[i+1];}


 int tail=1;

   vector<ll> sum(n+1);
   vector<ll> xo(n+1);


    for (int i = 1; i <=n ; ++i) {
        sum[i]=sum[i-1]+v[i];
        xo[i]=xo[i-1]^v[i];
    }

    ll ans=0;

   for(int i=1;i<n+1;i++){
       while(sum[i]-sum[tail-1]!=(xo[i]^xo[tail-1])){
           tail++;
     }
       ans+=(i-tail+1);
      // cout<<i<<" "<<tail<<endl;
   }
cout<<ans<<endl;




}

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

int main()
{
  int n;
  cin>>n;
  char ar[n][4];
  for(int i=0;i<n;i++)
    cin>>ar[i];

    int ac=0,wa=0,tle=0,re=0;
  for(int i=0;i<n;i++)
  {
      if(ar[i][0] == 'A')
        ac++;
      else if(ar[i][0] == 'W')
        wa++;
      else if(ar[i][0] == 'T')
        tle++;
      else if(ar[i][0] == 'R')
        re++;
  }
  cout<<"AC x "<<ac<<endl;
  cout<<"WA x "<<wa<<endl;
  cout<<"TLE x "<<tle<<endl;
  cout<<"RE x "<<re<<endl;

    return 0;
}


Measured memory_bytes: 3960
using System;
namespace a
{
  class b
  {
  	static void Main(string[] args)
    {
      string write = Console.ReadLine();
      if (write == "22"){
        Console.WriteLine("Christmas Eve Eve Eve");
      }else if (write == "23"){
        Console.WriteLine("Christmas Eve Eve");
      }else if (write == "24"){
        Console.WriteLine("Christmas Eve");
      }else if (write == "25"){
        Console.WriteLine("Christmas");
      }
    }
  }
}


Measured memory_bytes: 11092
import sys

def solve():
    pass

def main():
    N = int(input())
    A = [ (i, int(input())) for i in range(N) ]
    A.sort(key=lambda x: x[1], reverse=True)
    
    for i in range(N):
        if i == A[0][0]:
            print(A[1][1])
        else:
            print(A[0][1])

if __name__ == "__main__":
    main()

Measured memory_bytes: 33464
type tree = Nil | Node of int * tree * tree

let create () = Nil

let insert x t =
  let rec doit = function
    | Nil -> Node (x, Nil, Nil)
    | Node (y, l, r) ->
      if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let preorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> f x; doit l; doit r in
  doit t

let inorder f t =
  let rec doit = function
    | Nil -> ()
    | Node (x, l, r) -> doit l; f x; doit r in
  doit t

let print t =
  inorder (fun e -> print_string " "; print_int e) t;
  print_newline ();
  preorder (fun e -> print_string " "; print_int e) t;
  print_newline ()

let find x t =
  let rec doit = function
    | Nil -> false
    | Node (y, _, _) when x = y -> true
    | Node (y, l, _) when x < y -> doit l
    | Node (_, _, r) -> doit r in
  doit t

let delete x t =
  let rec doit = function
    | Nil -> assert false
    | Node (y, l, r) ->
      if x = y then
        if l = Nil then r
        else if r = Nil then l
        else
          let rec balance = function
            | Nil -> assert false
            | Node (x, Nil, r) -> (x, r)
            | Node (x, l, r) ->
              let (m, l) = balance l in
              (m, Node (x, l, r)) in
          let (m, r) = balance r in
          Node (m, l, r)
      else if x < y then Node (y, doit l, r)
      else Node (y, l, doit r) in
  doit t

let split_on_char sep s =
  let open String in
  let r = ref [] in
  let j = ref (length s) in
  for i = length s - 1 downto 0 do
    if get s i = sep then begin
      r := sub s (i + 1) (!j - i - 1) :: !r;
      j := i
    end
  done;
  sub s 0 !j :: !r

let () =
  let m = read_int () in
  let t = ref (create ()) in
  for _ = 0 to m - 1 do
    match read_line () |> split_on_char ' ' with
    | ["insert"; n] -> t := insert (int_of_string n) !t
    | ["find"; n] -> print_endline (if find (int_of_string n) !t then "yes" else "no")
    | ["delete"; n] -> t := delete (int_of_string n) !t
    | _ -> print !t
  done

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

using namespace std;

#define x first
#define y second
typedef long long ll;
const int N = 100010;
const int mod = 1000000007;
const int oo = 1e9;
const int base = 27;
typedef pair<int,int> pii;

int deg[5];

int main() {
  for (int a,b,i = 0; i < 3; ++i){
    cin >> a >> b;
    deg[a]++,deg[b]++;
  }
  int cnt = 0;
  for(int i = 1 ; i <= 4 ; ++i)
    if(deg[i]%2 == 1)cnt++;
  if(cnt != 0 && cnt != 2){
    puts("NO");
  }else{
    puts("YES");
  }
  return 0;
}

Measured memory_bytes: 256