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

void input(vector<int>& rvnHeight)
{
  int nHeightSiz;
  cin >> nHeightSiz;
  rvnHeight.resize(nHeightSiz);

  for (int& rnHeight : rvnHeight)
    cin >> rnHeight;
}

int calcMinExecCnt(vector<int>& rvnHeight)
{
  int nExecCnt = 0;
  int nPrevExecCnt = -1;

  while (nPrevExecCnt != nExecCnt)
  {
    nPrevExecCnt = nExecCnt;
    int nBgn = 0;
  
    while (nBgn < rvnHeight.size() )
    {
      int nFoward = nBgn;

      while (nFoward < rvnHeight.size() &&
             rvnHeight[nFoward]            )
      {
        rvnHeight[nFoward]--;
        nFoward++;
      }

      if (nBgn != nFoward) nExecCnt++;
      nBgn = nFoward + 1;
    }
  }
  return nExecCnt;
}
 
int main()
{
  vector<int> vnHeight;

  input(vnHeight);
  cout << calcMinExecCnt(vnHeight) << endl;

  return 0;
}

Measured memory_bytes: 3584
#include<stdio.h>

int min(int a, int b){
  return (a > b)?b:a;
}

int main(){
  int n, i = 0, j = 0, k = 0;
  scanf("%d", &n);
  int dp[n + 1][n + 1], p[n + 1];
  for (i = 0; i <= n; i++) {
    for (j = 0; j <= n; j++) {
      if(i == j)dp[i][j] = 0;
      else dp[i][j] = 1e9;
    }
  }
  int tmp;
  for (i = 0; i < n - 1; i++) {
    scanf("%d %d", &p[i], &tmp);
  }
  scanf("%d %d", &p[n - 1], &p[n]);
  
  for (k = 1; k <= n; k++) {
    for (i = 0; i + k <= n; i++) {
      int end = i + k - 1;
      for (j = 1; j < k; j++) {
        dp[i][end] = min(dp[i][end], dp[i][end - j] + dp[end - j + 1][end] + p[i]*p[end - j + 1]*p[end + 1]);
      }
    }
  }
  printf("%d\n", dp[0][n - 1]);
  return 0;
}

Measured memory_bytes: 636
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
using namespace std;
#define N (1000000000+7)
#define M (998244353)
#define INF 1e16
typedef long long ll;
typedef pair<int,int> P;
 

int  A(int x){
    if(x>=0)return x;
    else return -x;
}

int main(void){
    string s;
    cin>>s;
    int n = s.length();
    int num = 0;
    for(int i=0;i<n;i++){
        if(s[i]=='0')num++;
    }
    cout<<min(2*num,2*(n-num))<<endl;
    return 0;
}

Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <ctime>
#include <cassert>
#include <string>
#include <algorithm>
#include <vector>
#include <queue>
#include <stack>
#include <functional>
#include <iostream>
#include <iomanip>
#include <map>
#include <set>
#include <list>
#include <limits>
#include <numeric>
#include <utility>
#include <deque>
#include <valarray>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#include <array>
#include <bitset>
#include <complex>
#include <string>
#include <tuple>

using namespace std;
using ll = long long;
const int INF = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  int r, d, x;
  cin >> r >> d >> x;
  for (int i = 1; i <= 10; ++i)
  {
    x = r * x - d;
    cout << x << endl;
  }

  return 0;
}


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

int main() {
  int n;
  cin >> n;
  set<string> st;
  rep(i, n) {
    string s;
    cin >> s;
    st.insert(s);
  }
  cout << st.size() << endl;
  return 0;
}
      

Measured memory_bytes: 19204
#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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)*}
    };
}

#[allow(unused_macros)]
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, 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_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

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

const MOD: usize = 998244353;


#[doc = " b^power"]
pub fn mod_pow(mut b: usize, mut power: usize) -> usize {
    let mut result = 1;
    while power > 0 {
        if power & 1 == 1 {
            result = (result * b) % MOD;
        }
        b = (b * b) % MOD;
        power >>= 1;
    }
    result
}

fn main() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (write!(out,$($format)*).unwrap());
    }

    input!{
      n: usize,
      ds: [usize; n],
    }
    if ds[0] != 0 {
        return puts!("{}\n", 0);
    }

    let mut depth = vec![0; n+1];
    for i in 0..n {
        let d = ds[i];
        if d == 0 && i != 0 {
            return puts!("{}\n", 0);
        }
        depth[d] += 1;
    }

    let mut last_d = 0;
    for i in 0..n+1 {
        if depth[i] > 0 {
            last_d = i;
        }
    }

    let mut ans = 1usize;
    for d in 1..last_d+1 {
        ans *= mod_pow(depth[d-1], depth[d]);
        ans %= MOD;
    }
    puts!("{}\n", ans);
}


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

#define int long long
using namespace std;
#define rep(i, n) for(int i=0;i<(n);++i)
typedef pair<int, int> pii;
const int INF = 1l << 60;


signed main() {
    deque<char> s;
    string S;
    int Q;
    cin >> S >> Q;
    for (char c:S)s.push_back(c);
    bool rev = false;
    rep(i, Q) {
        int t;
        cin >> t;
        if (t == 1) {
            rev = !rev;
        } else {
            int f;
            char c;
            cin >> f >> c;
            bool ff = (f == 1);
            if (ff ^ rev) {
                s.push_front(c);
            } else {
                s.push_back(c);
            }
        }
    }
    if (!rev) {
        while (!s.empty()) {
            cout << s.front();
            s.pop_front();
        }
    } else {
        while (!s.empty()) {
            cout << s.back();
            s.pop_back();
        }
    }
    cout << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<math.h>
#include<algorithm>
using namespace std;

typedef long long ll;

int main() {

	int A;
	int B;

	cin >> A >> B;

	if (0 >= A - B * 2) {
		cout << 0 << endl;
	}

	else cout << A - B * 2 << endl;


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X, Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%(m))
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int A, B, C, D;

int main() {

    cin >> A >> B >> C >> D;

    int tAttack = (C + B - 1) / B;
    int aAttack = (A + D - 1) / D;

    if (tAttack <= aAttack) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3560
#include<stdio.h>
#include<algorithm>
#include<string.h>
#include<iostream>
using namespace std;
struct cm{
	int id,t;
	char name[101];
}a[10001];

int main(){
	int n;
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%s %d",a[i].name,&a[i].t);a[i].id=i;
	}
	for(int i=1;i<n;i++){
		for(int j=i+1;j<=n;j++){
			if(!strcmp(a[i].name,a[j].name)&&a[i].t<a[j].t) {
				cm pt;
				pt=a[i];a[i]=a[j];a[j]=pt;
			}
			else{
				for(int p=0;p<=min(strlen(a[i].name),strlen(a[j].name));p++){
					if(a[i].name[p]>a[j].name[p]){
						//printf("%d   %s->%s\n",p,a[i].name,a[j].name );
					cm pt;
					pt=a[i];a[i]=a[j];a[j]=pt;
					break;
					}
					if(a[i].name[p]<a[j].name[p]) break;
				}
			}
		}
	}
	for(int i=1;i<=n;i++){
		printf("%d\n",a[i].id );
	}
	return 0;
}

Measured memory_bytes: 256
(defun solver ()
  (let ((c1 (read-char)) (c2 (read-char)) (c3 (read-char))
        (yen 700))
    (when (char= c1 #\o) (setf yen (+ 100 yen)))
    (when (char= c2 #\o) (setf yen (+ 100 yen)))
    (when (char= c3 #\o) (setf yen (+ 100 yen)))
    (format t "~a~%" yen)))

(solver)


Measured memory_bytes: 12000
using System;
using System.Collections.Generic;
using System.Linq;

namespace AOJ
{
    class Program
    {
        static IEnumerable<string> ReadLines()
        {
            string line;
            while((line = Console.ReadLine()) != null)
            {
                yield return line;
            }
        }
        static void Main(string[] args)
        {
            var d = ReadLines()
                .Select(int.Parse)
                .GroupBy(x => x)
                .Select(x => new {x.Key, Length = x.Count()})
                .OrderByDescending(x => x.Length)
                .ToList();
            foreach(var v in
                d
                    .TakeWhile(x => x.Length == d.First().Length)
                    .OrderBy(x => x.Key))
            {
                Console.WriteLine(v.Key);
            }
        }
    }
}

Measured memory_bytes: 6744
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
char s1[100005];
int main()
{
	scanf("%s",s1);
	int n=strlen(s1);
	char c=s1[0];
	ll num=0;
	for(int i=1;i<n;i++)
	{
		if(s1[i]!=c)
		{
			num++;
			c=s1[i];
		}
	}
	printf("%lld\n",num);
	return 0;
}

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

l = 0
r = max(A)
for _ in range(30):
    mid = (r + l + 1) // 2
    count = 0
    for log in A:
        if log > mid:
            count += (log + mid - 1) // mid - 1
    if count <= K:
        r = mid
    else:
        l = mid

print(r)


Measured memory_bytes: 30984
import java.util.*;
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int K = sc.nextInt();
    int count = 0;
  	while (N > 0) {
      N /= K;
      count++;
    }
    System.out.println(count);
  }
}

Measured memory_bytes: 23380
#include<iostream>
#include<cmath>
#include <algorithm>
using namespace std;
vector<int> disx;
vector<int> disy;
int main(){
	int N;
	scanf("%d",&N);
	for(int i=0;i<N;i++){
		long long x,y;
		scanf("%lld %lld",&x,&y);
		disx.push_back(x+y);
		disy.push_back(x-y);
	}
	sort(disx.begin(),disx.end());
	sort(disy.begin(),disy.end());
	int d1=disx.back()-disx.front();
	int d2=disy.back()-disy.front();
	printf("%lld",max(d1,d2));
	return 0;
} 


Measured memory_bytes: 5044
#pragma GCC optimize("O3")
#include <bits/stdc++.h>

using namespace std;

#define F first
#define S second
#define PB emplace_back
#define ALL(x) (x).begin(),(x).end()
#define endl '\n'

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using pi = pair<int,int>;
using pll = pair<ll,ll>;

constexpr int IN = 1000005;
constexpr int INF = 1e9+5;
constexpr int INI = -1;


int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll x;
    cin >> x;
    ll am = 100;
    if(x == 100){
        cout <<0;
        return 0;
    }
    int i=0;
    while(am < x){
        am *= 1.01;
        ++i;
       // cout << am << endl;
    }
    cout << i;
    return 0;
}


Measured memory_bytes: 3664
N = int(input())
S = list(input())
ans = 0
#print(S)

for i in range(10):
    first = 0
    while S[first] != str(i) and first < N-1:
        first += 1
    if first > N-3:
        continue
    for j in range(10):
        second = first+1
        while S[second] != str(j) and second < N-1:
            second += 1
        if second > N-2:
            continue
        #print(i,first,j,second)
        ans += len(set(S[second+1:]))
print(ans)


Measured memory_bytes: 3572
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <cstring>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
typedef long long ll;
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}
int main(){
    int N; cin >> N;
    vector<ll> a(N+2),L(N+2),R(N+2);
    a[0] = 0, a[N+1] = 0;
    L[0] = 0, L[N+1] = 0, R[0] = 0, R[N+1] = 0;
    for (int i = 1; i <= N; i++){
        cin >> a[i];
    }
    for (int i = 1; i <= N; i++){
        R[i] = GCD(R[i-1],a[i]);
    }
    for (int i = N; i >= 1; i--){
        L[i] = GCD(L[i+1],a[i]);
    }
    ll ans = 0;
    for (int i = 1; i <= N; i++){
        ll mx = GCD(R[i-1],L[i+1]);
        ans = max(ans,mx);
    }
    cout << ans << endl;
}

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


int main(){
  
  int A,B;
  cin >> A >> B;
  
  int count;
  for(int i=A; i<B+1; i++){
    int s,t;
    s=i/10000;
    t=i/100;
    if(s==i%10 && i/1000-10*s==i/10-t*10){count++;}
  }
  cout << count << endl;
}


Measured memory_bytes: 256
# import numpy as np
# import math
import sys
input = sys.stdin.readline

def main():
    N,T = map(int,input().split())
    A = list(map(int,input().split()))

    maxgain = 0
    time = 0
    maxcost = A[0]
    mincost = A[0]

    for now in A:
        # print(now)
        maxcost = max(maxcost,now)
        mincost = min(mincost,now)
        temp = now - mincost
        # print(temp)
        if maxgain == temp:
            time += 1
        elif maxgain < temp:
            maxgain = temp
            time = 1
        # print(maxgain)
        # print(time)

    print(time)



main()


Measured memory_bytes: 14252
package main

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

func main() {
	var n, d int
	var x, y int

	fmt.Scan(&n, &d)
	dd := d * d

	sc := bufio.NewScanner(os.Stdin)

	c := 0
	for i := 0; i < n; i++ {
		sc.Scan()
		sp := strings.Split(sc.Text(), " ")
		x, _ = strconv.Atoi(sp[0])
		y, _ = strconv.Atoi(sp[1])
		distxdist := x*x + y*y
		if distxdist <= dd {
			c++
		}
	}

	fmt.Printf("%d", c)
}


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

int dp[100000];

int main(){
    ios::sync_with_stdio(0);
    cin.tie(0);
    int n; cin >> n;
    int a, b; cin >> a >> b;
    dp[0] = 0;
    dp[1] = abs(a-b);

    for (int i = 2; i < n; i++){
        int temp; cin >> temp;
        dp[i] = min(dp[i-2] + abs(a-temp), dp[i-1] + abs(b-temp));
        a = b;
        b = temp;
    }
    cout << dp[n-1];
}

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

#define mod 1000000007

using namespace std;
typedef long long ll; 
 
int main(void){
	
	int N;
	
	cin >> N;
	
	char S[N];
	bool yellow = false;
	
	for(int i=0; i<N; i++){
		cin >> S[i];
		if(S[i] == 'Y')
			yellow = true;
	}
	
	if(yellow)
		cout << "Four";
	else
		cout << "Three";
	
	return 0;
}

Measured memory_bytes: 256
#include <set>
#include <map>
#include <queue>
#include <ctime>
#include <cmath>
#include <cstdio>
#include <vector>
#include <string>
#include <cctype>
#include <bitset>
#include <cstring>
#include <cstdlib>
#include <utility>
#include <iostream>
#include <algorithm>
#define REP(i,a,b) for(int i=(a);i<=(b);i++)
#define PER(i,a,b) for(int i=(a);i>=(b);i--)
#define RVC(i,S) for(int i=0;i<(S).size();i++)
#define RAL(i,u) for(int i=fr[u];i!=-1;i=e[i].next)
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
     
template<class T> inline
void read(T& num) {
    bool start=false,neg=false;
    char c;
    num=0;
    while((c=getchar())!=EOF) {
        if(c=='-') start=neg=true;
        else if(c>='0' && c<='9') {
            start=true;
            num=num*10+c-'0';
        } else if(start) break;
    }
    if(neg) num=-num;
}
/*============ Header Template ============*/

int a[205];
int main() {
    int n;
    read(n);
    REP(i,1,n<<1) read(a[i]);
    sort(a+1,a+2*n+1);
    int res=0;
    REP(i,1,n) res+=a[(i<<1)-1];
    printf("%d\n",res);
    return 0;
}

Measured memory_bytes: 256
#define DIN freopen("input.txt","r",stdin);
#define DOUT freopen("output.txt","w",stdout);
#include <bits/stdc++.h>
#include <cstdio>
#define mem(a,b) memset(a,b,sizeof(a))
#define REP(i,a,b) for(int i=(a);i<=(int)(b);i++)
#define REP_(i,a,b) for(int i=(a);i>=(b);i--)
#define pb push_back
using namespace std;
typedef long long LL;
typedef std::vector<int> VI;
typedef std::pair<int,int> P;
int read()
{
    int x=0,flag=1; char c=getchar();
    while((c>'9' || c<'0') && c!='-') c=getchar();
    if(c=='-') flag=0,c=getchar();
    while(c<='9' && c>='0') {x=(x<<3)+(x<<1)+c-'0';c=getchar();}
    return flag?x:-x;
}

char s[1000005];

int main()
{
    scanf("%s",s);
    int a=0;
    for(int i=0;s[i];i++) a+=s[i]-'0';
    puts(a%9==0?"Yes":"No");

    return 0;
}


Measured memory_bytes: 3952
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <deque>
#include <queue>
#include <set>
#include <functional>
#include <cmath>
#include <set>
#include <map>


//マクロ
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
#define REPS(i,n) for(int i=1; i<=(int)(n); ++i)
#define RREP(i,n) for(int i=(int)(n)-1; i>=0; --i)
#define RREPS(i,n) for(int i=(int)(n); i>0; --i)
#define FOR(i,s,e) for(int i=(int)(s); i<(int)(e); ++i)
#define RFOR(i,s,e) for(int i=(int)(e)-1; i>=(int)(s); --i)
#define All(a) (a).begin(),(a).end()
#define RAll(a) (a).rbegin(),(a).rend()
#define dump(x)  cerr << #x << " = " << (x) << endl;

//定数
#define INF 1e9
#define INFL 1e18
#define MOD (int)(1e9+7)

typedef long long ll;
typedef unsigned long long ull;
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using pii = pair<int, int>;
using Graph = vector<vector<int>>;

//とりあえず書いておく変数
int dx[4] = { 1,0,-1,0 };
int dy[4] = { 0,1,0,-1 };

//今回の変数

//使用する関数
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 (a > b) { a = b; return 1; }
	return 0;
}

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

	int n;
	cin >> n;

	vi a = vi(n);
	REP(i, n) {
		cin >> a[i];
	}
	sort(All(a));
	reverse(All(a));

	ll ans = 0;
	queue<int> q;
	q.push(a[0]);
	REPS(i, n - 1) {
		ans += q.front();
		q.pop();

		q.push(a[i]);
		q.push(a[i]);
	}
	cout << ans << endl;

}

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

using namespace std;

const int maxv = 1e5;
pair<int, int> cnt1[maxv], cnt2[maxv];

bool cmp(pair<int, int> A, pair<int, int> B) {
	return A.first > B.first;
}

int main() {
	int n;
	cin >> n;
	for (int i = 1; i <= maxv; ++i) {
		cnt1[i].first = cnt2[i].first = 0;
		cnt1[i].second = cnt2[i].second = i;
	}
	for (int i = 0; i < n; ++i) {
		int a;
		cin >> a;
		if (i%2) cnt1[a].first++;
		else cnt2[a].first++;
	}
	sort(cnt1+1, cnt1+maxv+1, cmp);
	sort(cnt2+1, cnt2+maxv+1, cmp);
	if (cnt1[1].second != cnt2[1].second)
		cout << n - cnt1[1].first - cnt2[1].first << endl;
	else
		cout << min(n - cnt1[2].first - cnt2[1].first,
					n - cnt1[1].first - cnt2[2].first) << endl;
	return 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<deque>
#include<numeric>
#include<queue>
#include<stack>
#include<cstring>
#include<limits>
#include<functional>
#include<unordered_set>
#include<iomanip>
#include<cassert>
#include<regex>
#include<bitset>
#include<complex>
#include<chrono>
#include<random>
#define rep(i,a) for(int i=(int)0;i<(int)a;++i)
#define rrep(i,a) for(int i=(int)a-1;i>=0;--i)
#define REP(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RREP(i,a,b) for(int i=(int)a-1;i>=b;--i)
#define pb push_back
#define eb emplace_back
#define all(x) x.begin(),x.end()
using ll=long long;
constexpr ll mod = 1e9 + 7;
constexpr ll INF = 1LL << 60;

ll gcd(ll n, ll m) {
	ll tmp;
	while (m!=0) {
		tmp = n % m;
		n = m;
		m = tmp;
	}
	return n;
}

ll lcm(ll n, ll m) {
	return abs(n) / gcd(n, m)*abs(m);//gl=xy
}
 
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;
}
 
using namespace std;

template< class T >
struct CumulativeSum2D {
  vector< vector< T > > data;

  CumulativeSum2D(int W, int H) : data(W + 1, vector< int >(H + 1, 0)) {}

  void add(int x, int y, T z) {
    ++x, ++y;
    if(x >= data.size() || y >= data[0].size()) return;
    data[x][y] += z;
  }

  void build() {
    for(int i = 1; i < data.size(); i++) {
      for(int j = 1; j < data[i].size(); j++) {
        data[i][j] += data[i][j - 1] + data[i - 1][j] - data[i - 1][j - 1];
      }
    }
  }

  T query(int sx, int sy, int gx, int gy) {
    return (data[gx][gy] - data[sx][gy] - data[gx][sy] + data[sx][sy]);
  }
};

using P=pair<int,int>;
void solve(){
  int h,w,k;
  cin>>h>>w>>k;
  vector<string>s(h);
  ll ans=INF;
  rep(i,h)cin>>s[i];
  vector<vector<int>>t(h,vector<int>(w));
  rep(i,h)rep(j,w)t[i][j]=s[i][j]-'0';
  CumulativeSum2D<int>ss(h,w);
  rep(i,h){
    rep(j,w){
      ss.add(i,j,t[i][j]);
    }
  }
  bool ok=true;
  ss.build();
  for(int bit=0;bit<(1<<(h-1));++bit){
    int pre=0;
    ll sum=0;
    vector<P>v;
    bool ng=false;
    // if(bit==0){
    //   if(ss.query(0,0,h,w)<=k)chmin(ans,0LL);
    //   continue;
    // }
    rep(i,h-1){
      //cerr<<pre;
      if(bit&(1<<i)){
        sum++;
        v.eb(i+1,pre);
        pre=i+1;
      }
    }
    v.eb(h,pre);
    int prej=0;
    rep(j,w){
      while(j<w){
        bool bad=false;
        for(auto x:v){
          //cerr<<x.second<<" "<<x.first<<" "<<ss.query(x.second,prej,x.first,j+1)<<"\n";
          if(ss.query(x.second,prej,x.first,j+1)>k)bad=true;
        }
        if(!bad)++j;
        else break;
      }
      if(j==prej)ng=true;
      if(j==w)--sum;
      prej=j;
      ++sum;
    }
    if(!ng)chmin(ans,sum);
  }
  cout<<ans;
}

int main(){
	ios::sync_with_stdio(false);
  cin.tie(0);
	cout<<fixed<<setprecision(15);
  solve();
	return 0;
}


Measured memory_bytes: 384
#include <stdio.h>
main(){
   
  int x,y,i,a;
   
  for(i = 0 ; 1 ; i++){
    scanf("%d%d",&x,&y);
    if(x == 0 && y == 0) break;
     
    if(x > y){
      a = x;
      x = y;
      y = a;
    }
    printf("%d %d\n",x,y);
  }
return 0;
}

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

main(){
  string s;
  cin>>s;
  if ("SUN" == s) cout<<7<<endl;
  else if (s=="MON") cout<<6<<endl;
  else if (s == "TUE")  cout<<5<<endl;
  else if (s == "WED") cout<<4<<endl;
  else if (s == "THU") cout<<3<<endl;
  else if (s == "FRI") cout<<2<<endl;
  else cout<<1<<endl;
  return 0;
}

Measured memory_bytes: 3608
def find(x):
    if par[x] < 0:
        return x
    else:
        par[x] = find(par[x])
        return par[x]
def unite(x,y):
    x = find(x)
    y = find(y)
    
    if x == y:
        return False
    else:
        if par[x] > par[y]:
            x,y = y,x
        par[x] += par[y]
        par[y] = x
        return True

def same(x,y):
    return find(x) == find(y)

def size(x):
    return -par[find(x)]

n,m = map(int,input().split())
par = [-1]*n

for i in range(m):
    X,Y,Z = map(int,input().split())
    unite(X-1,Y-1)

tank = set([])
for i in range(n):
    tank.add(find(i))
print(len(tank))


Measured memory_bytes: 12780
import math

a,b,x = map(int,input().split())

# 弧度法を度数法に変換
def toDosu(x):
    return (x/math.pi) * 180

f = a**2*b/2

if x > f:
    t = toDosu(math.atan( (-2*x + 2*a**2*b)/(a**3) ))
elif x == f:
    t = 45.0
else:
    t = toDosu(math.atan( (a*b**2)/(2*x) ))

print(t)

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

int main()
{
  int N;
  int a[200001];
  int c[200001];
  int res=0;
  cin >> N;

  rep(i,N) cin >> a[i+1];
  rep(i,N+1) c[i] = 0;
  
  for(int i=N; i>0; i--){
    int j=2;
    int sum=0;
    while(j*i<=N){
      sum += c[j*i];
      j++;
    }
    if(sum %2 == a[i]) c[i]=0;
    else c[i]=1;
  }

  for(int i=1;i<=N;i++){
    res += c[i];
  }
  cout << res << endl;
  for(int i=1;i<=N;i++){
    if(c[i]>0) cout << i << " ";
  }
  cout << endl;
  
}


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

int main()
{
    int n;
    cin>>n;
    int arr[n];
    for(int i=0;i<n;i++)
    {
        cin>>arr[i];
    }
    int ans=1;
  int max=arr[0];
   for(int i=1;i<n;i++)
    {
      
      if(arr[i]>=max)
      {
    ans++;
    max=arr[i];
      }



    }
    cout<<ans;
}


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

int main()
{
    int a,b,c;
    cin >> a >> b >> c;
    int d;
  // 並べ替える
    if(a > b){
      d = a;
      a = b;
      b = d; 
    }
    if(b > c){
      d = b;
      b = c;
      c = d;
    }
    if(a > b){
      d = a;
      a = b;
      b = d; 
    }

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



Measured memory_bytes: 3120
#include<bits/stdc++.h>
using namespace std;
long long ss,ans=0;
map<long long,int>m;
int main()
{
	int n,x;
	scanf("%d",&n);
	m[0]++;
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&x);
		ss+=x;
		ans+=m[ss];
		m[ss]++;
	}
	printf("%lld",ans);
}


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

int main(){
  int n,ans=0; cin>>n;
  int num[n];
  bool flag = true;
  for(int i=0;i<n;i++){
    cin>>num[i];
    if(i+1==num[i]){
      ans++;
      if(i!=n-1){
        cin>>num[i+1];
        i++;
      }
    }
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n); i >= 0; i--)
#define REP(i, m, n) for (int i = (int)(m); i <= (int)(n); i++)
#define all(v) v.begin(), v.end()
typedef long long ll;

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

const long long INF = 1LL << 60;

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

  cout << min(a, b) + min(c, d) << endl;

  return 0;
}


Measured memory_bytes: 256
N, M = map(int, input().split())
S = [10 for _ in range(N)]
ans = 0

for i in range(M):
    s, c = map(int, input().split())
    if S[s-1] == 10:
        S[s-1] = c
    elif S[s-1] != c:
        ans = -1
        break

if ans == -1:
    pass
elif N == 1 and (S[0] == 0 or S[0] == 10):
    ans = 0
elif S[0] == 0:
    ans = -1
else:
    if S[0] == 10:
        S[0] = 1
    for i in range(N):
        if S[i] == 10:
            S[i] = 0
        ans = ans*10 + S[i]

print(ans)

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



int main() {
	string s;
	cin >> s;
	if (s[2] == s[3] && s[4] == s[5]) {
		cout << "Yes";
	}
	else {
		cout << "No";
	}
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<algorithm>
#include<set>
#include<cmath>
#include<stack>
using namespace std;
struct node
{
    int val;
    node* next;
};
/*
 99992149
      123
 */
int isSu(long long int x)
{
    long long int up = sqrt(x);
    for(int i = 2;i<=up;i++)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
int main()
{
    int a,b,ans;
    cin>>a>>b;
    if(2*b>=a)
        ans=0;
    else
        ans=a-2*b;
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<iostream>
#include<map>
#include<vector>

int main(){
    int N;
    std::cin >> N;
    int input;
    std::map<int, int> mp;
    for(int i = 0; i < N; i++){
        std::cin >> input;
        if(mp[input] != 0){
            std::cout << "NO" << std::endl;
            return 0;
        }
        mp[input]++;
    }

    std::cout << "YES" << std::endl;

    return 0;
}

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

using namespace std;

int main(){

	int k, n, mi=0;
	vector<int> v;

	cin>> k >> n;
	v.resize(n);
	for(int i=0;i<n;i++) cin>> v[i];

	v.emplace_back(v[0] + k);

	for (int i = 0;i < n;i++) {
		mi = max(mi, v[i + 1] - v[i]);
		//cout << v[i + 1] - v[i] << endl;
	}

	cout<< k-mi << endl;

	return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>

int main(void)
{
	int a, b;
	
	scanf("%d %d", &a, &b);
	
	if (a > b)
	{
		printf("a > b\n");
	}
	else if (a < b)
	{
		printf("a < b\n");
	}
	else
	{
		printf("a == b\n");
	}
	
	return 0;
}

Measured memory_bytes: 580
#include <iostream>
#include <cstring>
#include <cstdio>
using namespace std;
#define M 1046527
#define NIL (-1)
#define L 14

char H[M][L];

// 将字符转换为数值
int getChar(char ch)
{
	if(ch == 'A')	return 1;
	else if(ch == 'C')	return 2;
	else if(ch == 'G')	return 3;
	else if(ch == 'T')	return 4;
	else	return 0;
}

// 将字符串转换为数值并生成key 
long long getKey(char str[])
{
	long long sum = 0, p = 1, i;
	for(i = 0; i < strlen(str); ++ i)
	{
		sum += p * (getChar(str[i]));
		p *= 5;
	}
	return sum;
}

int h1(int key) { return key % M; }
int h2(int key)	{ return 1 + (key % (M - 1)); }

int find(char str[])
{
	long long key, i, h;
	key = getKey(str);	// 将字符串转换为数值
	for(i = 0; ; ++ i)
	{
		h = (h1(key) + i * h2(key)) % M;
		if(strcmp(H[h], str) == 0)	return 1;
		else if(strlen(H[h]) == 0)	return 0;
	} 
	return 0;
}

int insert(char str[])
{
	long long key, i, h;
	key = getKey(str);	// 将字符串转换为数值
	for(i = 0; ; ++ i)
	{
		h = (h1(key) + i * h2(key)) % M;
		if(strcmp(H[h], str) == 0)	return 1;
		else if(strlen(H[h]) == 0)
		{
			strcpy(H[h], str);
			return 0;
		}
	} 
	return 0;
}

int main()
{
	int i, n, h;
	char str[L], com[9];
	for(i = 0; i < M; ++ i)	H[i][0] = '\0';
	scanf("%d", &n);
	for(i = 0; i < n; ++ i)
	{
		scanf("%s %s", com, str);
		
		if(com[0] == 'i') 
		{
			insert(str);
		}
		else
		{
			if(find(str))
			{
				printf("yes\n");
			}
			else
			{
				printf("no\n");
			}
		}
	}
	
	return 0;
}


Measured memory_bytes: 17476
#!/usr/bin/env python3
#ABC89 C

import math

n = int(input())
s = [input() for _ in range(n)]

m,a,r,c,h = 0,0,0,0,0
for i in s:
    if i[0] == 'M':m += 1
    elif i[0] == 'A':a+= 1
    elif i[0] == 'R':r += 1
    elif i[0] == 'C':c += 1
    elif i[0] == 'H':h += 1

ans = m*a*r + m*a*c + m*a*h + m*r*c + m*r*h + m*c*h + a*r*c + a*r*h + a*c*h + r*c*h
print(ans)


Measured memory_bytes: 57432
#include <bits/stdc++.h>
using namespace std;
int main(){
  string n;
  cin >> n;
  int nm{};
  for(int i=0; i<n.size(); i++){
    nm = (nm + (n[i] - '0')) % 9;
  }
  cout << (nm == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define REP(i, n) for (int i=0, i##_lim=(n); i<i##_lim; ++i)
#define FOR(i, a, b) for (int i=(a), i##_lim=(b); i<i##_lim; ++i)
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;

int main()
{
    int N, K;
    string S;
    cin >> N >> K;
    cin >> S;

    S[K-1] = S[K-1] - 'A' + 'a';

    cout << S << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int hs(string);
int matoi(char);
int main(){
  int nma=1;
  for(int i=0;i<12;i++){
    nma*=4;
  }
  vector<int> a(nma+5,0);
  int n;
  cin >> n;
  for(int i=0;i<n;i++){
    string fu;
    string st;
    cin >> fu >> st;
    int h=hs(st);
    if(fu=="insert"){
      a[h]=1;
    }
    else{
      if(a[h])cout << "yes" << endl;
      else cout << "no" << endl;
    }
  }
  return 0;
}
int hs(string st){
  int re=0;
  for(int i=st.size()-1;i>=0;i--){
    re*=4;
    int a=matoi(st[i]);
    re+=a;
  }
  return re;
}
int matoi(char ch){
  if(ch=='A')return 1;
  if(ch=='C')return 2;
  if(ch=='G')return 3;
  return 4;
}

Measured memory_bytes: 68148
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int N; cin >> N;
    vector<int> p(N);
    for(int i = 0; i < N; i++)
    {
        cin >> p.at(i);
    }
    int max = 0;
    for(int i = 0; i < N; i++)
    {
        if(max < p.at(i))
        {
            max = p.at(i);
        }
    }
    int sum = 0;
    for(int i = 0; i < N; i++)
    {
        sum += p.at(i);
    }
    cout << sum - max / 2 << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
using namespace std;
int main(){
 
  vector <string> a,b;
  string tmp;
  int n,i;
 
  cin>>n;
  for(i=0;i<n;i++)
  {
    cin>>tmp;
    a.push_back(tmp);
  }

  b.assign(a.begin(),a.end());

  for(i=0;i<n-1;i++)
  {
   for(int j=n-2;j!=i-1;j--) 
   {
    if(a[j][1]>a[j+1][1])
    {
     swap(a[j],a[j+1]);
    }
   }
  }

  for(i=0;i<n-1;i++)
  {
   cout<<a[i]<<" ";
  }
  cout<<a[n-1]<<endl<<"Stable"<<endl;
 
  for(i=0;i<n-1;i++){
    int now,minnum=101;
    for(int j=i;j<n;j++) if(minnum>b[j].at(1)-'0'){
        now=j;
        minnum=b[j].at(1)-'0';
      }
    if(i!=now)  swap(b[i],b[now]);
  }
 
  for(i=0;i<n-1;i++) cout<<b[i]<<" ";
  cout<<b[n-1]<<endl;
  if(a==b) cout<<"Stable"<<endl;
  else cout<<"Not stable"<<endl;
 
  return 0;
 
}


Measured memory_bytes: 3196
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <cmath>
#include <deque>
#include <vector>
#include <queue> 
#include <string>
#include <cstring>
#include <map>
#include <stack>
#include <set>
using namespace std;
int main()
{
	long long n,ans=0;
	cin>>n;
	for (long long i=1;i<=sqrt(n)+sqrt(sqrt(n));i++)
		if (n%i==0&&n/i-1>i) ans+=n/i-1;
	cout<<ans;
}

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  int N; scanf("%d", &N);
  vector<int> A(N);
  vector<int> freqs(N, 0);
  for (int i = 0; i < N; ++i) {
    scanf("%d", &A[i]);
    ++freqs[A[i]];
  }

  bool ok = true;
  if (N % 2 == 0 and freqs[0] > 0) {
    ok = false;
  }
  else if (N % 2 == 1 and freqs[0] != 1) {
    ok = false;
  }

  if (ok) {
    if (N % 2 == 0) {
      for (int i = 1; ok and i < N; ++i) {
        if (i % 2 == 0 and freqs[i] != 0) { ok = false; }
        else if (i % 2 == 1 and freqs[i] != 2) { ok = false; }
      }
    }
    else {
      for (int i = 1; ok and i < N; ++i) {
        if (i % 2 == 0 and freqs[i] != 2) { ok = false; }
        else if (i % 2 == 1 and freqs[i] != 0) { ok = false; }
      }
    }
  }

  ll ans = ok ? 1 : 0;
  if (ok) {
    for (int i = 0; i < N / 2; ++i) {
      ans = (ans * 2) % MOD;
    }
  }
  printf("%lld\n", ans);
  return 0;
}


Measured memory_bytes: 1024
function main(input) {
  input = input.split("\n");
  const [n, m, x, y] = input[0].split(" ").map(n => Number(n));
  const xArr = input[1].split(" ").map(n => Number(n));
  const yArr = input[2].split(" ").map(n => Number(n));
  const maxX = Math.max(...xArr);
  const minY = Math.min(...yArr);
  let result = "War";
  for (let z = x + 1; z <= y; z++) {
  	if (maxX < z && z <= minY) {
    	result = "No War";
        break;
    }
  }
  console.log(result);
}
main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

ll dp[402][402];
ll sum[402][402]; // sum[i][j] =  total sum from i to j inclusive;

ll slime(vector<ll>&v, int i, int j){
      if(i == j)
         return 0;
      if(dp[i][j] != -1)
         return dp[i][j];
      ll minCost = INT64_MAX;
      for(int k = i; k<j; k++){
          minCost = min(minCost, sum[i][j] + slime(v,i,k)+slime(v,k+1,j)) ;
      }
       dp[i][j] = minCost;
       return dp[i][j];
}
void setsum(vector<ll>v,int n){
    for(int i = 0; i<n; i++){
    for(int j = i; j<n; j++){
         sum[i][j] = v[j] + ((j == i)? 0 : sum[i][j-1]);
     }
    }
  return ;
} 

void solve(){
   int n;
   cin >> n;
   vector<ll>v;
   for(int i=0; i<n; i++){
       ll x;
       cin >> x;
       v.push_back(x);
   }
    memset(dp,-1,sizeof dp);
    setsum(v,n);
    cout << slime(v,0,n-1);
}
int main(){
//  #ifndef ONLINE_JUDGE
//   freopen("input.txt", "r", stdin);
//   freopen("output.txt", "w", stdout);
// #endif 
solve();

return 0;
}

Measured memory_bytes: 6156
#include <bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef vector<lld> vi;
typedef pair<lld,lld> pi;
#define F first
#define S second
#define N 100009
#define PB push_back
#define MP make_pair
#define rep(i,a,b) for (lld i = a; i < b; i++)
lld r,j,l,x,y,m,n,s,q,i,z,p,d,k,t,w,sz;string s1,s2,s3;
int main()
{ 
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);cout.tie(NULL);
  cin>>s1>>x;n=s1.size();
  for(i=0;i<n;i+=x)cout<<s1[i];
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
typedef long long lint;
const int N=1e5+5;
int n,m,val[N],nxt[N],ans[N];
lint q;
bool vis[N];

template <class T> inline T nxi(){
	T x=0;
	char c;
	while(((c=getchar())>'9'||c<'0')&&c!='-');
	const bool f=c=='-'&&(c=getchar());
	while(x=x*10-48+c,(c=getchar())>='0'&&c<='9');
	return f?-x:x;
}

inline void solve(const int st){
	static int cyc[N];
	int pt=0;
	for(int x=st; !vis[x]; x=nxt[x]){
		vis[x]=1;
		cyc[++pt]=x;
	}
	for(int i=1; i<=pt; ++i){
		ans[cyc[i]]=val[cyc[(i+q%pt-1)%pt+1]];
	}
}

int main(){
	n=nxi<int>();
	for(int lst=0,x,i=1; i<=n; lst=x,++i){
		nxt[i]=i;
		x=nxi<int>();
		val[i]=x-lst;
	}
	m=nxi<int>(),q=nxi<lint>();
	for(int i=1; i<=m; ++i){
		const int x=nxi<int>();
		std::swap(nxt[x],nxt[x+1]);
	}
	for(int i=1; i<=n; ++i){
		if(!vis[i]) solve(i);
	}
	lint sum=0;
	for(int i=1; i<=n; ++i){
		printf("%lld\n",sum+=ans[i]);
	}
	return 0;
}

Measured memory_bytes: 2944
#pragma GCC optimize("O2")
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<stack>
#include<deque>
#include<map>
#include<unordered_map>
#include<set>
#include<cmath>
#include<climits>
#include<random>
#include <iomanip>
#include <bitset>
using namespace std;
 
#define pb push_back
#define ff first
#define ss second
#define endl '\n'
#define fast ios::sync_with_stdio(false); cin.tie(NULL);
 
/////////////////////////////////////////////
 
void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
 
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif
 
///////////////////////////////
#define int long long

int getIndex(int *a , int n , int val){

	int l = 0 , r = n-1;
	int ans = -1;
	while(l <= r){

		int mid = (l + r)/2;

		if(a[mid] <= val){

			ans = mid;
			l = mid + 1;
		}
		else r = mid - 1;
	}
	return ans;
}

void solve(){

	int n , m , k;
	cin>>n>>m>>k;
	int a[n] , b[m];

	for(int i = 0 ; i < n ; ++i)
		cin>>a[i];
	for(int i = 0 ; i < m ; ++i)
		cin>>b[i];


	for(int i = 1 ; i < n ; ++i)
		a[i] += a[i-1];
	for(int i = 1 ; i < m ; ++i)
		b[i] += b[i-1];

	int ans = 0;
	for(int i = 0 ; i <= n ; ++i){

		int val = 0;
		if(i)
			val = a[i-1];

		if(val > k)
			break;

		int rem = k - val;

		int num = getIndex(b , m , rem);

		ans = max(ans , i + num + 1);

	}

	cout<<ans<<endl;
}
 
signed main(){
 
	fast;
	int t = 1;
	//cin>>t;
	for(int i = 1 ; i <= t ; ++i)
		solve();
}


Measured memory_bytes: 6736
# 24
A,B,M = map(int,input().split())
a = list(map(int,input().split()))
b = list(map(int,input().split()))
Sum = float("inf")
for i in range(M):
    x,y,c = map(int,input().split())
    if a[x-1]+b[y-1]-c < Sum:
        Sum = a[x-1]+b[y-1]-c
    
a.sort()
b.sort()
if a[0]+b[0] < Sum:
    Sum = a[0]+b[0]
print(Sum)

Measured memory_bytes: 25308
#include <bits/stdc++.h>
using namespace std;
#define maxn 1000
#define fr(a) freopen(a,"r",stdin)
#define fw(a) freopen(a,"w",stdout)
vector<int> g[maxn];// vector lưu trữ đỉnh kề
/*queue<int> s;// hàng đợi
stack<int> s1;
int cl[maxn];//mảng đánh dấu
int distance1[maxn];
int dd[maxn]; // mảng đánh dấu
vector<bool> visited(100, false);
void clear( queue<int> &q )
{
   queue<int> empty;
   swap( q, empty );
}
void bfs(int u) // u là đỉnh xuất phát
{
    clear(s); // dọn sạch hàng đợi
    s.push(u); // bỏ đỉnh xuất phát vào
    distance1[u]=0;
    cl[u] = 1; // đánh dấu đỉnh xuất phát
    while(!s.empty()) // chừng nào hàng đợi còn chưa rỗng
    {
        int u = s.front(); // lấy ra đỉnh ở đầu queue
        s.pop(); // bỏ đỉnh ở đầu queue ra khỏi queue
        for(int v : g[u]) // với mỗi đỉnh v kề với đỉnh u
        {
            if(cl[v]==0) // nếu đỉnh v chưa được đánh dấu
            {
                s.push(v); // bỏ đỉnh v vào queue
                distance1[v]=distance1[u]+1;
                cl[v]=1; // đánh dấu đỉnh v

            }
        }
    }
}
void visit(int u) {
    cout << u << " ";
}
void dfs(int u) // dfs đệ quy
{   visit(u);
    dd[u]=1; // đánh dấu đỉnh u đã đi qua
    for(int v : g[u]) // với mỗi đỉnh v kề với đỉnh u // tương đương for(int i=0;i<g[u].size();i++) int v=g[u][i]
    {
        if(dd[v] == 0)
            dfs(v); // nếu v chưa đánh dấu, tới thăm đỉnh u
    }
}
map<int,int> sav;
void add_edge(int u, int v) {
    g[u].push_back(v);
    g[v].push_back(u);
}
int dem;
int main()
{
   int mon[] = {0,31,28,31,30,31,30,31,31,30,31,30,31};
   int monn[100];
   int n;
   cin>>n;
   while(n--){
    int r;
   cin>>r;
    if(r==28)
        r=r;
    else if(r==29)
        r=r-1;
    monn[dem++]=r;
   }
   int m=0,r;
    for(int i=1;i<=12;i++){
        if(monn[m]==mon[i]){
             r=m+1;
            for(int j=i+1;j<=14;j++){

                if(j==13)
                        j=1;
                if(r==dem)
                   {
                       cout<<"YES";
                       return 0;
                   }
                if(monn[r]!=mon[j])
                    break;
                r++;
            }
        }


    }
    cout<<"NO";
}*/
typedef long long int ll;

int main()
{
    string s;
    cin>>s;
    int dem=0;
    for(int i=0;i<s.length();i++)
        if(s[i]=='1')
            dem++;
    cout<<dem;
}




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

using namespace std;

const int INF = 1 << 29;	// 十分大きい値にする, INT_MAX にしないのはオーバーフロー対策

int main(void)
{
	int N;
	int A[100001];
	int min = INF;
	int minus_num = 0;
	long long sum = 0;

	cin >> N;
	for (int i = 0; i < N; i++) {
		long long tmp;
		cin >> tmp;

		if (tmp >= 0) {
			A[i] = tmp;
		}
		else {
			A[i] = -tmp;
			minus_num++;
		}
		if (A[i] < min) {
			min = A[i];
		}
		sum += A[i];
	}
	
	if (minus_num % 2 == 1) {
		sum -= min * 2;
	}
	
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
use std::env;
use std::io::*;
use std::str::*;
use std::mem;
use std::collections::HashMap;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let s = stdin.bytes().map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect::<String>();
    s.parse::<T>().ok().unwrap()
}
fn read_char() -> char {
    let c = read::<String>();
    let c = c.chars().collect::<Vec<char>>();
    c[0]
}
fn read_String_Vec() -> Vec<char> {
    let S = read::<String>();
    S.chars().collect::<Vec<char>>()
}

fn vecchar_to_String(Vs: Vec<char>) -> String {
    let mut S = String::new();
    for i in 0..Vs.len() {
        S.push(Vs[i]);
    }
    S
}

/*
A : 65
Z : 90
a : 97
z : 122
*/

/*
let N = read::<i32>();
let S = read::<String>();
let S = read_String_Vec();
let C = read_char();
*/

/*
 .to_string() : * -> String
 &*S          : String -> &str
*/

fn main() {
    // main の引数
    /*
        引数なしのときargs.len() = 1;
    */
    let args: Vec<String> = env::args().collect();

    let S = read_String_Vec();
    let mut array = Vec::new();
    array.resize(26, 0);
    let mut max = 0;
    for s in S {
        array[(s as u8 - 97) as usize] += 1;
        if max < array[(s as u8 - 97) as usize] {
            max = array[(s as u8 - 97) as usize];
        }
    }

    if max == 1 {
        println!("yes");
    } else {
        println!("no");
    }
}


Measured memory_bytes: 4352
def main():
  N, K = map(int, input().split())
  A = list(map(int, input().split()))

  l = [0] * (N+1)
  for i in range(N):
    l[A[i]] += 1
  l.sort(reverse=True)
  ans = N - sum(l[:K])
  print(ans)

if __name__ == '__main__':
  main()


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

int main()
{
    ll h , w ;
    while(cin >> h >> w)
    {
        if(h == 0 && w == 0) break ;
        for(int i = 0 ; i < h ; i++)
        {
            for(int j = 0 ; j < w ; j++) cout << '#' ;
            cout << endl ;
        }
        cout << endl ;
    }
}


Measured memory_bytes: 3104
function Main(input) {
	input = input.trim();
	//input = input.trim().split(" ");
	//input = input.trim().split("\n");
	input = input.trim().split(" ").map((a)=>Number(a));
	//input = input.trim().split("\n").map((a)=>Number(a));
  	if((input[0] * input[1]) % 2 == 0){
       console.log("Even");
       }else{
        console.log("Odd"); 
       }
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int kekka=0;
		char[] aa=new char[4];
		String bb="";
		bb=sc.next();
		for(int i=0; i<4; i++) {
			aa[i]=bb.charAt(i);
		}

		for(int i=0; i<4; i++) {
			if(aa[i]=='+') {
				kekka++;
			}
			else if(aa[i]=='-') {
				kekka--;
			}
		}

		System.out.println(kekka);
	}
}

Measured memory_bytes: 21844