akhauriyash/Code-Regression huggingface dataset:
# でつoO(YOU PLAY WITH THE CARDS YOU'RE DEALT..)
import sys
def main(N, Q, C, LR):
    ans = [0] * Q
    LRi = [(l, r, i) for i, (l, r) in enumerate(LR)]
    LRi.sort(key=lambda x: x[1])
    bit = BinaryIndexedTree(N)
    MR = [-1] * (N + 1)
    p = 0
    for l, r, i in LRi:
        l, r = l - 1, r - 1
        while p <= r:
            c = C[p]
            mr = MR[c]
            if mr >= 0:
                bit.add(mr, -1)
            MR[c] = p
            bit.add(p, 1)
            p += 1
        ans[i] = bit.query(r) - bit.query(l - 1)
    for a in ans:
        print(a)

class BinaryIndexedTree:
    def __init__(self, n=None, f=lambda x, y: x + y, identity=0, initial_values=None):
        assert(n or initial_values)
        self.__f, self.__id, = f, identity
        self.__n = len(initial_values) if initial_values else n
        self.__d = [identity] * (self.__n + 1)
        if initial_values:
            for i, v in enumerate(initial_values): self.add(i, v)

    def add(self, i, v):
        n, f, d = self.__n, self.__f, self.__d
        i += 1
        while i <= n:
            d[i] = f(d[i], v)
            i += -i & i

    def query(self, r):
        res, f, d = self.__id, self.__f, self.__d
        r += 1
        while r:
            res = f(res, d[r])
            r -= -r & r
        return res

if __name__ == '__main__':
    input = sys.stdin.readline
    N, Q = map(int, input().split())
    *C, = map(int, input().split())
    LR = [tuple(map(int, input().split())) for _ in range(Q)]
    main(N, Q, C, LR)


Measured memory_bytes: 264676
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <iomanip>
#include <stdio.h>
#include <numeric>
#include <cmath>
#include <limits>
#include <bitset> 
#include <iterator> 
#include <map>
#include <queue>
#include <set>
#define rep(i,n) for(ll i=0;i<(n); ++i)
#define per(i,n) for(ll i=n-1;i>=0; --i)
#define all(x) (x).begin(),(x).end()
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const long long INF = 1LL << 60;
typedef long long ll;
ll MOD = 1000000007;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}

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

	ll n, X;
	cin >> n >> X;
	vector<ll>x(n), tmp;
	rep(i, n)cin >> x[i], tmp.push_back(abs(X - x[i]) == 0 ? NULL: abs(X - x[i]));
	for (ll d = *min_element(all(tmp)); d >= 1; d--) {
		for (ll i = 0; i < n; i++) {
			if (abs(x[i] - X) % d != 0)break;
			else if (i == n - 1)return cout << d << endl, 0;
		}
	}
}


Measured memory_bytes: 2168
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<algorithm>
#include<cmath>
#include<climits>
#include<string>
#include<set>
#include<map>
#include<iostream>
using namespace std;
#define rep(i,n) for(int i=0;i<((int)(n));i++)
#define reg(i,a,b) for(int i=((int)(a));i<=((int)(b));i++)
#define irep(i,n) for(int i=((int)(n))-1;i>=0;i--)
#define ireg(i,a,b) for(int i=((int)(b));i>=((int)(a));i--)
typedef long long int lli;
typedef pair<int,int> mp;
#define fir first
#define sec second
#define IINF INT_MAX
#define LINF LLONG_MAX
#define eprintf(...) fprintf(stderr,__VA_ARGS__)
#define pque(type) priority_queue<type,vector<type>,greater<type> >
#define memse(a,b) memset(a,b,sizeof(a))
#define iter(v,ite) for(auto ite=(v).begin();ite!=(v).end();ite++)
#define mimunum(v,x) distance((v).begin(),lower_bound((v).begin(),(v).end(),x))



int ds[205][205][6];

int obs[205][205]={};


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

typedef pair<mp,mp> mmp;

int main(void){
	int sy,sx,gy,gx,bn;
	memse(ds,-1);
	scanf("%d%d%d%d%d",&sx,&sy,&gx,&gy,&bn);
	int bx=100,by=100;
	sx += bx; sy += by;
	gx += bx; gy += by;
	rep(i,bn){
		int x,y;
		scanf("%d%d",&x,&y);
		obs[y+by][x+bx]=1;
	}
	int lx,ly;
	scanf("%d%d",&lx,&ly);
	
	pque(mmp) que;
	if(obs[sy][sx]==0){
		que.push(mmp(mp(0,0),mp(sy,sx)));
	}
	
	while(!que.empty()){
		mmp pa = que.top();
		que.pop();
		int nm = pa.fir.fir,
			nt = pa.fir.sec,
			y = pa.sec.fir,
			x = pa.sec.sec;
		
		//printf("%d %d %d %d\n",nm,nt,x-bx,y-by);
		if(x==gx && y==gy){
			printf("%d\n",nm);
			return 0;
		}
		
		int& nmd = ds[y][x][nt];
		if(nmd>=0 && nmd<=nm)continue;
		nmd = nm;
		int tt = (nt+1)%6;
		rep(i,7){
			int ty=y+dy[x%2][i],
				tx=x+dx[i];
			if(obs[ty][tx])continue;
			if(abs(tx-bx)>lx || abs(ty-by)>ly)continue;
			//printf("%d %d\n",ty-by,tx-bx);
			int tm=nm+1;
			if(abs((x-bx)*(y-by)*nt)%6 == i)tm--;
			
			int td = ds[ty][tx][tt];
			if(td>=0 && td<=tm)continue;
			que.push(mmp(mp(tm,tt),mp(ty,tx)));
		}
	}
	printf("-1\n");
	return 0;
}

Measured memory_bytes: 4556
import java.util.*;
 
class Main{
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    
    int n = sc.nextInt();
    int[] a = new int[n];
    for(int i=0; i<a.length; i++){
      a[i] = sc.nextInt();
    }
    Arrays.sort(a);
    int ans = 1;
    for(int i=0; i<n-1; i++){
      if(a[i] != a[i+1]){
        ans++;
      }
    }
    System.out.println(ans);

    sc.close();
  }
}

Measured memory_bytes: 21844
import math
input_data=input()
new_input = input_data.split(" ")
N=int(new_input[0])
X=int(new_input[1])
m_list=[]
for i in range(N):
    m = int(input())
    m_list.append(m)
m_sum_each = sum(m_list)
X_rest = X - m_sum_each
m_minimum = min(m_list)
add_dornuts = math.floor(X_rest / m_minimum)
all_dornuts = add_dornuts + N
print(all_dornuts)

Measured memory_bytes: 3064
#include<stdio.h>
#define MAX 105
#define WHITE 0
#define GRAY 1
#define BLACK 2
void DFS(void);
void DFSVisit(int);

int G[MAX][MAX];
int d[MAX];
int f[MAX];
int color[MAX];
int n;
int time;

int main(){

	int i,j,u,k,next;

	scanf("%d",&n);
	for(i = 1; i <= n; i++){
		for(j = 1; j <= n; j++){
			G[i][j] = 0;
		}
	}
	for(i = 1; i <= n;i++){
		scanf("%d%d",&u,&k);
		for(j = 1; j <= k; j++){
			scanf("%d",&next);
			G[i][next] = 1;
		}
	}
	DFS();
	for(i = 1; i <= n; i++){
		printf("%d %d %d\n",i,d[i],f[i]);
	}

	return 0;
}

void DFS(void){

	int u;

	for(u = 1; u <= n; u++){
		color[u] = WHITE;
	}
	time = 0;
	for(u = 1; u <= n; u++){
		if(color[u] == WHITE)
			DFSVisit(u);
	}
}

void DFSVisit(int u){

	int v;

	color[u] = GRAY;
	d[u] = ++time;
	for(v = 1; v <= n; v++){
		if(G[u][v] == 1 && color[v] == WHITE)
			DFSVisit(v);
	}
	color[u] = BLACK;
	f[u] = ++time;
}

Measured memory_bytes: 640
public class Main {
    public static void main(String[] args) throws Exception {
        try (java.io.BufferedReader br = new java.io.BufferedReader(new java.io.InputStreamReader(System.in))) {
            String line;
            while ((line = br.readLine()) != null) {
                int r=0;
                for(int i=0; i<3; i++){
                    if(line.charAt(i) == 'o')r++;
                }
                System.out.println(700 + 100*r);
            }
        }
    }
}

Measured memory_bytes: 22356
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <bitset>
#include <complex>
#include <iomanip>
using namespace std;
typedef long long ll;
typedef long long int llint;
#define MM 1000000000
#define MOD MM+7
#define pi pair<int,int>
#define pl pair<ll,ll>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
const long double PI = acos(-1);
const long long INF = 1e15;
const ll DEP = (1LL << 50);
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
template<typename T>
T GCD(T x,T y){
    return y ? GCD(y,x%y) : x;
}
ll N,M;
int main(){
    cin >> N;
    int p[N];
    for(int i = 0; i < N; i++){
        cin >> p[i];
    }
    int cnt = 0;
    for(int i = 1; i < N-1; i++){
        if (p[i] < max(p[i+1],p[i-1]) && min(p[i+1],p[i-1]) < p[i]){
            cnt++;
        }
    }
    cout << cnt << endl;
}


Measured memory_bytes: 384
#define LOCAL
#define _USE_MATH_DEFINES
#include <array>
#include <cassert>
#include <cstdio>
#include <cstring>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <complex>
#include <cmath>
#include <numeric>
#include <bitset>
#include <functional>
#include <random>
#include <ctime>

using namespace std;

template <typename A, typename B>
ostream& operator <<(ostream& out, const pair<A, B>& a) {
  out << "(" << a.first << "," << a.second << ")";
  return out;
}
template <typename T, size_t N>
ostream& operator <<(ostream& out, const array<T, N>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T>
ostream& operator <<(ostream& out, const vector<T>& a) {
  out << "["; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "]";
  return out;
}
template <typename T, class Cmp>
ostream& operator <<(ostream& out, const set<T, Cmp>& a) {
  out << "{"; bool first = true;
  for (auto& v : a) { out << (first ? "" : ", "); out << v; first = 0;} out << "}";
  return out;
}
#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
#else
#define trace(...) 42
#endif
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...);
}

typedef long long int64;
typedef pair<int, int> ii;
const int INF = 1 << 29;
const int MOD = 1e9 + 7;
mt19937 mrand(random_device{}());
int rnd(int x) { return mrand() % x; }

struct fast_ios {
  fast_ios() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(10);
  };
} fast_ios_;

int main() {
  string s;
  cin >> s;
  int mask = 0;
  for (int i = 0; i < 3; ++i) {
    if (s[i] == 'A') mask |= 1;
    else if (s[i] == 'B') mask |= 2;
  }
  if (mask == 3) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int H, A;
  cin >> H >> A;
  int Nattack;
  if(H % A ==0){
    Nattack = H/A;
  }
  else{
    Nattack = H/A+1;
  }
  cout << Nattack << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(){
    int n;
    scanf("%d",&n);
    int a[n+1],b[n];
    for(int c=0;c<n+1;c++){scanf("%d",&a[c]);}
    for(int d=0;d<n;d++){scanf("%d",&b[d]);}
    long count=0;
    for(int e=0;e<n;e++){
        if(a[e]<=b[e]){count+=a[e];if(a[e+1]<b[e]-a[e]){count+=a[e+1];a[e+1]=0;}
                                   else{count+=b[e]-a[e];a[e+1]-=b[e]-a[e];}
        }
        else{count+=b[e];}
    }
    printf("%ld\n",count);
    return 0;
}

Measured memory_bytes: 896
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
constexpr ll mod=1000000007;
constexpr ll mod998=998244353;


struct A{
	int k,l,r;
};

bool operator<(const A &a,const A &b){
	return a.l-a.r<b.l-b.r;
}

int T,N;
A S[200000];

ll tourist(){
	ll res=0;
	vector<A>p,q;
	for(int i=0;i<N;i++){
		if(S[i].l-S[i].r>=0)p.push_back(S[i]);
		else q.push_back(S[i]);
	}
	sort(p.begin(),p.end());
	sort(q.begin(),q.end());
	set<int>st;
	for(int i=0;i<p.size();i++){
		st.insert(i);
	}
	for(int i=p.size()-1;i>=0;i--){
		auto it=st.upper_bound(p[i].k);
		if(it==st.begin()){
			res+=p[i].r;
		}
		else{
			res+=p[i].l;
			it--;
			st.erase(it);
		}
	}
	st.clear();
	for(int i=p.size();i<N;i++){
		st.insert(i);
	}
	for(int i=0;i<q.size();i++){
		auto it=st.upper_bound(q[i].k);
		if(it==st.end()){
			res+=q[i].l;
		}
		else{
			res+=q[i].r;
			st.erase(it);
		}
	}
	return res;
}


int main(){
	cin>>T;
	for(int i=0;i<T;i++){
		cin>>N;
		for(int j=0;j<N;j++){
			cin>>S[j].k>>S[j].l>>S[j].r;
			S[j].k--;
		}
		cout<<tourist()<<endl;
	}
}


Measured memory_bytes: 12680
import sys
from itertools import product

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N, A, B, C = map(int, readline().split())
    (*L,) = map(int, read().split())

    def rec(i, a, b, c):
        if i == N:
            return abs(a - A) + abs(b - B) + abs(c - C) - 30 if min(a, b, c) > 0 else INF

        res0 = rec(i + 1, a, b, c)
        res1 = rec(i + 1, a + L[i], b, c) + 10
        res2 = rec(i + 1, a, b + L[i], c) + 10
        res3 = rec(i + 1, a, b, c + L[i]) + 10

        return min(res0, res1, res2, res3)

    print(rec(0, 0, 0, 0))
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9220
#include <bits/stdc++.h>
#define ll long long int
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define pb emplace_back
#define vi vector<int>
#define all(x) (x).begin(), (x).end()
#define pb emplace_back
#define deb(x) cout << #x << " - " << x << endl;

using namespace std;

int main()
{
	IOS;
// #ifndef ONLINE_JUDGE
// 	freopen("input.txt", "r", stdin);
// 	freopen("output.txt", "w", stdout);
// #endif
	int n, m; cin >> n >> m;
	ll sum = 0;
	vi v(n);
	for (int i = 0; i < n; i++) {
		cin >> v[i]; sum += v[i];
	}

	sort(all(v));
	int cnt = 0;
	double range = (double)(sum) / (double)(4 * m);
	for (int i = n - 1; i >= 0; i--) {
		if (v[i] >= range) cnt++;
	}
	if (cnt >= m) cout << "Yes";
	else cout << "No";

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,sum,ans;
char a;
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
    	cin>>a;
    	if(a=='I')sum++;
    	else if(a=='D')sum--;
    	ans=max(sum,ans);
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 384
#if !defined(__clang__) && defined(__GNUC__)
#include <bits/stdc++.h>
#else
#include <cstdlib>
#include <climits>
#include <iostream>
#include <cstdint>
#include <vector>
#include <string>
#include <complex>
#include <bitset>
#include <queue>
#include <deque>
#include <stack>
#include <utility>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <regex>
#endif //  !defined(__clang__) && defined(__GNUG__)
#include <boost/lexical_cast.hpp>
#include <boost/algorithm/string.hpp>
#include <boost/multi_array.hpp>
#include <boost/optional.hpp>

using namespace std;

int main()
{
    int N;
    std::cin >> N;

    std::map<int, bool> a;
    int insanes = 0;
    for (int i = 0; i < N; ++i) {
        int t;
        std::cin >> t;

        if (t >= 3200) {
            insanes++;
        }
        else if (t >= 2800) {
            a[2800] = true;
        }
        else if (t >= 2400) {
            a[2400] = true;
        }
        else if (t >= 2000) {
            a[2000] = true;
        }
        else if (t >= 1600) {
            a[1600] = true;
        }
        else if (t >= 1200) {
            a[1200] = true;
        }
        else if (t >= 800) {
            a[800] = true;
        }
        else if (t >= 400) {
            a[400] = true;
        }
        else {
            a[0] = true;
        }
    }

    if (a.empty()) {
        std::cout << 1 << " " << insanes << std::endl;
    }
    else {
        std::cout << a.size() << " " << a.size() + insanes << std::endl;
    }

    return 0;
}


Measured memory_bytes: 256
MOD = 10**9 + 7

s = input()
n = len(s)

sl = [[0] * 4 for _ in range(n+1)]
sr = [[0] * 4 for _ in range(n+1)]

for i in range(n):
  sl[i+1] = sl[i][:]
  if s[i] == 'A': sl[i+1][0] += 1
  elif s[i] == 'B': sl[i+1][1] += 1
  elif s[i] == 'C': sl[i+1][2] += 1
  else: sl[i+1][3] += 1

for i in range(n, 0, -1):
  sr[i-1] = sr[i][:]
  if s[i-1] == 'A': sr[i-1][0] += 1
  elif s[i-1] == 'B': sr[i-1][1] += 1
  elif s[i-1] == 'C': sr[i-1][2] += 1
  else: sr[i-1][3] += 1

ans = 0
for i in range(n):
  if s[i] == 'B' or s[i] == '?':
    a = c = 0
    a += sl[i][0] * pow(3, sl[i][3], MOD)
    if sl[i][3] > 0: a += sl[i][3] * pow(3, sl[i][3]-1, MOD)
    c += sr[i+1][2] * pow(3, sr[i+1][3], MOD)
    if sr[i+1][3] > 0: c += sr[i+1][3] * pow(3, sr[i+1][3]-1, MOD)
    ans = (ans + a*c) % MOD

print(ans)


Measured memory_bytes: 33012
#include<bits/stdc++.h>
using namespace std;
const int N = 1e5+1;
long long int tree[4*N]={0};
#define ff first
#define ss second
void update(long int node,long int l,long int r,long int ind,long long int val)
{
    if(l==r)
    {
        tree[node] = val;
    }
    else
    {
        long int mid = (l+r)/2;
        if(mid>=ind)
         update(2*node+1,l,mid,ind,val);
         else
         update(2*node+2,mid+1,r,ind,val);
         tree[node] = max(tree[2*node+1],tree[2*node+2]);
    }
}
long long int query(long int node,long int l,long int r,long int L,long int R)
{
    if(L>r || l>R)
    return 0;
    if(L<=l && R>=r)
    return tree[node];
    long int mid = (l+r)/2;
    return max(query(2*node+1,l,mid,L,R),query(2*node+2,mid+1,r,L,R));
}
long long int mod = 1e9+7;
bool compare(pair<long long int,long long int> a,pair<long long int,long long int> b)
{
    return a.ff>b.ff;
}

long long int power(long long int x,long long int y)
{
    long long int res=1;
    while(y>0)
    {
        if(y&1)res=(res*x)%mod;
        x=(x*x)%mod;
        y>>=1;
    }
    return res;
}
int main()
{
    long int t=1;
    // cin>>t;
    long int kk=0;
    while(t--)
    {
        long int n;
        cin>>n;
       long long int a[n],aa=0,bb=0;
       for(long int i=0;i<n;i++)
       {
           cin>>a[i];
           aa+=a[i];
           aa%=mod;
       }
       aa=(aa*aa)%mod;
       for(long int i=0;i<n;i++)
       {
           aa-=(a[i]*a[i]);
           aa%=mod;
           aa+=mod;
       }
       aa=(aa*power(2,mod-2))%mod;
       cout<<aa;
    }
}

Measured memory_bytes: 5156
#include<iostream>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<utility>
#include<string>
#include<stack>
#include<queue>
#include<set>
#include<math.h>
#include <map>
#include <typeinfo>
#include <cstdlib>

using namespace std;
typedef long long int ll;
#define repi(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,a) repi(i,0,a)
#define all(u) u.begin(),u.end()

struct Data{double x; string u;};

int main() {
    ll N; scanf("%lld",&N);
    Data date[15];
    rep(i,N){
        cin >> date[i].x;
        cin >> date[i].u;
    }
    double sum = 0;
    rep (i,N){
        if (date[i].u == "JPY") sum += date[i].x;
        else sum += date[i].x * 380000.0;
    }
    printf("%.8f\n",sum);
    return 0;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

N = str(int(input()))

#print("{}".format(N[len(N)-1]))

if N[len(N)-1]=='2' or N[len(N)-1]=='4' or N[len(N)-1]=='5' or N[len(N)-1]=='7' or N[len(N)-1]=='9':
    print("hon")

elif N[len(N)-1]=='0' or N[len(N)-1]=='1' or N[len(N)-1]=='6' or N[len(N)-1]=='8':
    print("pon")

elif N[len(N)-1]=='3':
    print("bon")


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

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

  if(A % 3 == 0 || B % 3 == 0 || (A + B) % 3 == 0){
    cout << "Possible" << endl;
  }
  else cout << "Impossible" << endl;

  return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env ruby

require 'pp'
attrs = Array.new
while line = $stdin.gets
  attrs << line.chomp.split
end

N = attrs[0][0].to_i
A = attrs[1].map{|a| a.to_i}

n = N - A.inject(:+)
puts n<0 ? -1 : n

Measured memory_bytes: 14952
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <cmath>
#include <random>
#include <queue>

using namespace std;


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

	int N = S.length();

	int cnt_1_g = 0;
	int cnt_1_k = 0;

	for (int ni = 0; ni < N; ni++){
		if (ni % 2 == 0 && S[ni] == '1'){
			cnt_1_g++;
		}
		if (ni % 2 == 1 && S[ni] == '1'){
			cnt_1_k++;
		}
	}

	int len_k = N/2;
	int len_g = (int)ceil( N/2.0);

	int ans_g = len_g - cnt_1_g + cnt_1_k;
	int ans_k = cnt_1_g + len_k - cnt_1_k;

	int ans = min(ans_g, ans_k);

	printf("%d", ans);

	return 0;
}



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

int fun(int cur, vector<int> &dp,vector<int> &h){
	if(dp[cur]!=-1) return dp[cur];
	dp[cur] = min(fun(cur-1,dp,h) + abs(h[cur]-h[cur-1]),fun(cur-2,dp,h) + abs(h[cur]-h[cur-2]));
	return dp[cur];
}
int main(){
	long long int n,x;
	cin>>n;
	vector<int> h;
	vector<int> dp(n,-1);
	for(int i=0;i<n;i++){
		cin>>x;
		h.push_back(x);
	}
	dp[0]=0;
	dp[1] = abs(h[1]-h[0]);
	cout<<fun(n-1,dp,h)<<endl;
}

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

#define MAX 1000000000000000000

int main()
{
  long long a[100005],ans=1;
  bool flag=false,zero=false;
  int N;
  cin >> N;
  
  rep(i,N)
  {
    cin >> a[i];
    if(a[i]==0)
      zero = true;
  }
  if(!zero)
  {
  	rep(i,N)
  	{
   	 if(MAX/ans < a[i]) 
     {
       	flag = true;
    	break;
     }
     	ans*=a[i];
  	}
  }
  
  if(zero) cout << 0 << endl;
  else if(flag) cout << -1 << endl;
  else cout << ans << endl;
}

Measured memory_bytes: 4368
N,K = map(int,input().split())
A = list(map(int,input().split()))
species = list(set(A))
dic = {}
for i in species:
    dic[i] = 0
for i in A:
    dic[i] += 1
if K >= len(species):
    print(0)
else:
    tmp = sorted(dic.values(),reverse=1)
    print(sum(tmp[K:]))

Measured memory_bytes: 99272
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define forn(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pb push_back
 
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 

void solve(){
	int n; cin >> n;
	int ac = 0, tle = 0, wa = 0, re = 0;
	forn(i,0,n){
		string s; cin >> s;
		if(s=="AC") ++ac;
		if(s=="TLE") ++tle;
		if(s=="WA") ++wa;
		if(s=="RE") ++re;
	}
	cout << "AC x " << ac << '\n';
	cout << "WA x " << wa << '\n';
	cout << "TLE x " << tle << '\n';
	cout << "RE x " << re;
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <map>
#include <math.h>

using namespace std;
using ll = long long int;

int main()
{
  int a, b, c, d, e;
  cin >> a >> b >> c >> d >> e;
  int ad = a % 10 == 0 ? 0 : 10 - a % 10;
  int bd = b % 10 == 0 ? 0 : 10 - b % 10;
  int cd = c % 10 == 0 ? 0 : 10 - c % 10;
  int dd = d % 10 == 0 ? 0 : 10 - d % 10;
  int ed = e % 10 == 0 ? 0 : 10 - e % 10;
  int maxd = max(ad, bd);
  maxd = max(maxd, cd);
  maxd = max(maxd, dd);
  maxd = max(maxd, ed);
  cout << a + ad + b + bd + c + cd + d + dd + e + ed - maxd << endl;
}


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

from math import gcd

def solve(a,b,c):
  d = gcd(a,b)
  if c % d == 0:
    return "YES"
  else:
    return "NO"



def main():
  a,b,c = map(int,input().split())
  print(solve(a,b,c))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9084
#include <bits/stdc++.h>
using namespace std;
#define endl "\n"
#define fo(i,s,e) for( i=s;i<e;i++)
#define rfo(i,s,e) for(i=s;i>e;i--)
#define LL long long int 
const LL MOD=1e9+7;
#define pb push_back
#define pob pop_back()
#define sp " "
#define ff first
#define ss second
//            When something is important enough, you do it even if the odds are not in your favor.

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);cout.tie(NULL);
    #ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    // code goes here
    int t=1;//cin>>t;
    while(t--){
      LL n,i;cin>>n;
      if(n>=30) cout<<"Yes";
      else cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3648
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef struct Maze{
  int y;
  int x;
  int time;
} MAZE;
#define rep(i,n) for(int i=0; i<(n); i++)
int dy[]={0,0,-1,1};
int dx[]={1,-1,0,0};
int main(){
  int h,w; cin >> h >> w;
  vector<vector<char>> grid(h, vector<char>(w));
  vector<vector<int>> turn(h, vector<int>(w,-1));
  vector<int> order;
  rep(i,h)rep(j,w) cin >> grid[i][j];
  queue<MAZE> q;
  q.push(MAZE{0,0,0});
  while(!q.empty()){
    int sy=q.front().y;
    int sx=q.front().x;
    int t=q.front().time;
    q.pop();
    if(grid[sy][sx]=='#') continue;
    if(turn[sy][sx]!=-1) continue;
    turn[sy][sx]=t;
    rep(dir,4){
      int ny=sy+dy[dir],nx=sx+dx[dir];
      if(ny>=h||ny<0||nx>=w||nx<0) continue;
      q.push(MAZE{ny,nx,t+1});
    }
  }
  int null_cnt=0;
  int need=turn[h-1][w-1];
  if(turn[h-1][w-1]<=0){
    cout << -1 << endl;
    return 0;
  }
  else{
    rep(i,h)rep(j,w){
      if(turn[i][j]>0){
        order.push_back(turn[i][j]);
      }
      if(turn[i][j]==-1&&grid[i][j]=='.'){
        null_cnt++;
      }
    }
    cout << order.size()-need+null_cnt << endl;
  }
}

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

char Letter(string &S, int &i);
string String(string &S, int &i);
string Cipher(string &S, int &i);

char Letter(string &S, int &i){
    if(isupper(S[i])||S[i]=='?'){
        i++;
        return S[i-1];
    }else{
        char c;
        if(S[i]=='+'){
            i++;
            c = Letter(S,i);
            if(c!='?'){
                if(c!='Z')c++;
                else c='A';
            }
        }else{
            i++;
            c = Letter(S,i);
            if(c!='?'){
                if(c!='A')c--;
                else c='Z';
            }
        }
        return c;
    }
}

string String(string &S, int &i){
    string ret;
    if(S[i]=='['){
        i++;
        ret=Cipher(S,i);
        reverse(ret.begin(), ret.end());
        i++;
        return ret;
    }else{
        return string(1,Letter(S,i));
    }
}

string Cipher(string &S, int &i){
    string ret;
    while(i<S.size()&&S[i]!=']'){
        ret+=String(S,i);
    }
    return ret;
}

int main(){
    while(true){
        string S;
        cin>>S;
        if(S[0]=='.') return 0;
        int i=0;
        string C = Cipher(S,i);
        for(auto &c:C) if(c=='?') c='A';
        cout<<C<<endl;
    }
}

Measured memory_bytes: 3168
# coding:utf-8

import math

base = 1000000007

def main():
    n,m = map(int,raw_input().split())
    ms = []
    for i in range(m):
        ms.append(int(raw_input()))
    prev = -1
    for i in ms:
        if i - prev <= 1:
            print 0
            return
        prev = i
    prev = 0
    fib = 1
    fib1 = 0
    fib2 = 1
    cur = 0
    total = 1
    for i in range(0,n+1):
        if len(ms) > cur:
            curM = ms[cur]
            if i < curM:
                if cur >= 1 and i == ms[cur-1]:
                    continue
                fib = fib1 + fib2
                fib1 = fib2
                fib2 = fib
            else:
                total = (total * fib1) % base
                fib = 1
                fib1 = 0
                fib2 = 1
                cur += 1
        else:
            if cur >= 1 and i == ms[cur-1]:
                continue
            if i != n:
                fib = fib1 + fib2
                fib1 = fib2
                fib2 = fib
            else:
                total = (total * fib) % base
    print total

if __name__ == "__main__":
    main()



Measured memory_bytes: 8964
#include <iostream>
#include <cstring>
#include <algorithm>
#include <vector>
#include <string>
#include <math.h>
#include <iomanip>
#include <limits>
#include <list>
#include <queue>
#include <tuple>
#include <map>
#include <stack>
#include <set>
#include <bitset>
#include <functional>
#include <cassert>
using namespace std;
#define fast_io ios_base::sync_with_stdio (false) ; cin.tie(0) ; cout.tie(0) ;
#define ll long long int
#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 REP(i,n) for(int i=n-1; i>=0; i--)
#define REPS(i,n) for(int i=n; i>0; i--)
#define MOD (long long int)(1e9+7)
#define INF (int)(1e9)
#define LINF (long long int)(1e18)
#define chmax(a, b) a = (((a)<(b)) ? (b) : (a))
#define chmin(a, b) a = (((a)>(b)) ? (b) : (a))
#define all(v) v.begin(), v.end()
typedef pair<int, int> Pii;
typedef pair<ll, ll> Pll;

ll mpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = mpow(a,b/2); return memo*memo%MOD;}
  else return mpow(a,b-1) * a % MOD;
}
ll lpow(ll a, ll b){
  if(b==0) return 1;
  else if(b%2==0){ll memo = lpow(a,b/2); return memo*memo;}
  else return lpow(a,b-1) * a;
}
ll gcd(ll a, ll b){
  if(b==0) return a;
  else return gcd(b, a%b);
}
vector<ll> kaijo_memo;
ll kaijo(ll n){
  if(kaijo_memo.size() > n) return kaijo_memo[n];
  if(kaijo_memo.size() == 0) kaijo_memo.push_back(1);
  while(kaijo_memo.size() <= n) kaijo_memo.push_back(kaijo_memo[kaijo_memo.size()-1] * kaijo_memo.size() % MOD);
  return kaijo_memo[n];
}
vector<ll> gyaku_kaijo_memo;
ll gyaku_kaijo(ll n){
  if(gyaku_kaijo_memo.size() > n) return gyaku_kaijo_memo[n];
  if(gyaku_kaijo_memo.size() == 0) gyaku_kaijo_memo.push_back(1);
  while(gyaku_kaijo_memo.size() <= n) gyaku_kaijo_memo.push_back(gyaku_kaijo_memo[gyaku_kaijo_memo.size()-1] * mpow(gyaku_kaijo_memo.size(), MOD-2) % MOD);
  return gyaku_kaijo_memo[n];
}

ll nCr(ll n, ll r){
  if(n == r) return 1;//0個の丸と-1個の棒みたいな時に時に効く？不安.
  if(n < r || r < 0) return 0;
  ll ret = 1;
  if(n <= 1e7){
    ret *= kaijo(n); ret %= MOD;
    ret *= gyaku_kaijo(r); ret %= MOD;
    ret *= gyaku_kaijo(n-r); ret %= MOD;
  }else{
    rep(i,r){
      ret *= n-i; ret %= MOD;
      ret *= mpow(r-i, MOD-2); ret %= MOD;
    }
  }
  return ret;
}



int main(void){
  fast_io
  cout<<fixed<<setprecision(15);
  string s;
  cin >> s;
  int ans = 0;
  int tmp = 0;
  rep(i,3){
	  if(s[i] == 'R'){
		  tmp++;
	  }else{
		  tmp = 0;
	  }
	  ans = max(ans,tmp);
  }
  cout << ans << endl;
  return 0;
}


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

const int INF = 1000000000;

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

        if(n ==0) break;

        int T[10][10];
        for(int i=0; i<10; i++){
            for(int j=0; j<10; j++){
                if(i == j){
                    T[i][j] = 0;
                }
                else{
                    T[i][j] = INF;
                }
            }
        }

        int m = 0;
        for(int i =0; i<n; i++){
            int a,b,c;
            cin >> a >> b >> c;
            T[a][b] = T[b][a] = c;
            if(a+1 > m){
                m = a+1;
            }
            if(b+1 > m){
                m = b+1;
            } 
        } 

        for(int k=0; k<m; k++){
            for(int i=0; i<m; i++){
                for(int j=0; j<m; j++){
                    if(T[i][j]>T[i][k]+T[k][j]){
                        T[i][j] = T[i][k]+T[k][j];
                    }
                }
            }
        }

        int z=INF;
        int v=0;

        for(int i=0; i<m; i++){
            int total(0);
            for(int j=0; j<m; j++){
                total += T[i][j];
            }
            if(total < z){
                v = i;
                z = total;
            }

        }

        cout << v << ' ' << z << endl; 



    }
    return 0;
}


Measured memory_bytes: 3068
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf = 1_001_001_001;
enum infl = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

void main() {
    int n, h, w;
    scan(n);
    scan(h);
    scan(w);
    int ans = (n - h + 1) * (n - w + 1);
    writeln(ans);
}


void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg ; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg ; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

long powmod(long x, long y, long mod = 1_000_000_007L) {
    long res = 1L;

    while (y > 0) {
        if (y & 1) {
            (res *= x) %= mod;
        }
        (x *= x) %= mod;
        y >>= 1;
    }

    return res;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // 入力受付
        Scanner scan = new Scanner(System.in);
        int n = scan.nextInt();
        int array[] = new int[n];
        for (int i = 0; i < n; i++) {
            array[i] = scan.nextInt();
        }

        int result = 0;

        for (int i = 0; i < n; i++) {
            for (int j = i + 1; j < n; j++) {
                result += array[i] * array[j];
            }
        }

        System.out.println(result);

    }

}

Measured memory_bytes: 23892
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <numeric>
#include <ctime>
#include <complex>
#include <bitset>
#include <random>
 
using namespace std;
 
typedef long long ll;
typedef long double ld;
 
#define int ll
#define double ld
#define loop(i, n) for(int i = 0; i < (int)n; ++i)
#define loop1(i, n) for(int i = 1; i <= (int)n; ++i)
#define F first
#define S second
#define pb push_back
#define pi pair <int, int>
#define all(x) begin(x), end(x)
#define ti tuple <int, int, int>
#define Point Vect

const int N = 2e5 + 7, INF = 1e15;

void solve() {
    string s;
    cin >> s;
    cout << (s[3] == s[2] && s[4] == s[5] ? "Yes" : "No");
}
 
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    //int t; cin >> t; loop(i, t)
    solve();
    return 0;
}

Measured memory_bytes: 256
use proconio::marker::Chars;
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        s: Chars,
        t: Chars,
    };

    let s: Vec<char> = s;
    let t: Vec<char> = t;

    let mut count = std::i32::MAX;

    for i in 0..s.len() - t.len() + 1 {
        let mut x = 0;
        for j in 0..t.len() {
            if t[j] != s[i + j] {
                x += 1;
            }
        }
        count = std::cmp::min(count, x);
    }

    println!("{}", count);
}


Measured memory_bytes: 2144
package main

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

var sc = bufio.NewScanner(os.Stdin)

func scanText() string {
	sc.Scan()
	return sc.Text()
}

func scanInt() int {
	sc.Scan()
	a, _ := strconv.Atoi(sc.Text())
	return a
}

func scanFloat() float64 {
	sc.Scan()
	a, _ := strconv.ParseFloat(sc.Text(), 64)
	return a
}

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

func max(a int, b int) int {
	if a < b {
		return b
	}
	return a
}

var (
	h int
	w int
	g [][]string
)

type Pair struct {
	x int
	y int
}

var inf int = 1000000007
var dx [4]int = [4]int{1, 0, -1, 0}
var dy [4]int = [4]int{0, 1, 0, -1}

func bfs(sy int, sx int) int {
	q := []Pair{{y:sy, x:sx}}
	dist := make([][]int, h)
	for i:=0; i<h; i++ {
		dist[i] = make([]int, w)
	}
	for i:=0; i<h; i++ {
		for j:=0; j<w; j++ {
			dist[i][j] = inf
		}
	}
	dist[sy][sx] = 0
	for len(q) > 0 {
		u := q[0]
		q = q[1:]
		for i:=0; i<4; i++ {
			nx := u.x + dx[i]
			ny := u.y + dy[i]
			if nx < 0 || nx >= w || ny < 0 || ny >= h {
				continue
			}
			if g[ny][nx] == "#" {
				continue
			}
			if dist[ny][nx] > dist[u.y][u.x] + 1 {
				dist[ny][nx] = dist[u.y][u.x] + 1
				q = append(q, Pair{y:ny, x:nx})
			}
		}
	}
	res := 0
	for i:=0; i<h; i++ {
		for j:=0; j<w; j++ {
			if dist[i][j] == inf {
				continue
			}
			res = max(res, dist[i][j])
		}
	}
	return res
}

func main() {
	sc.Split(bufio.ScanWords)
	h = scanInt()
	w = scanInt()
	g = make([][]string, h)
	for i:=0; i<h; i++ {
		g[i] = make([]string, w)
	}
	for i:=0; i<h; i++ {
		str := scanText()
		s := strings.Split(str, "")
		for j:=0; j<w; j++ {
			g[i][j] = s[j]
		}
	}

	res := 0
	for i:=0; i<h; i++ {
		for j:=0; j<w; j++ {
			if g[i][j] == "#" {
				continue
			}
			res = max(res, bfs(i, j))
		}
	}
	fmt.Println(res)
}


Measured memory_bytes: 5880
import java.util.*;
import java.io.*;

class Main {
   public static void main(String[] args) {
       Scanner sc = new Scanner(System.in);
  for(;;){
	  int ten[]= new int[10];
  int n=sc.nextInt();
  if(n==0)break;
  for(;n>0;n--){
	  int t=sc.nextInt();
	  ten[t]++;
  }
  for(int i=0; i<10; i++){
	 if(ten[i]==0)System.out.print("-"); 
	 else 
	 for(int j=0; j<ten[i]; j++) System.out.print("*");
	  System.out.println();
  }
   }
   }
}
 

Measured memory_bytes: 52428
import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
A = list(map(int,readline().split()))

MAX_VAL = 10 ** 5 + 1
hand = [0] * MAX_VAL
for a in A:
  hand[a] += 1
  
import numpy as np
def convolve(f, g):
    fft_len = 1
    while 2 * fft_len < len(f) + len(g) - 1:
        fft_len *= 2
    fft_len *= 2
    
    Ff = np.fft.rfft(f, fft_len)
    Fg = np.fft.rfft(g, fft_len)

    Fh = Ff * Fg

    h = np.fft.irfft(Fh, fft_len)
    h = np.rint(h).astype(np.int64)

    return h[:len(f) + len(g) - 1]

right_hand = np.array(hand, dtype = int)
left_hand = np.array(hand, dtype = int)

H = convolve(left_hand, right_hand)
# Hを大きいほうから見ていくと、
# 幸福度iの握手をH[i]種類できることが分かる
# 上から順に足していって、最後H[i]種類の握手を足せないときは、残りの握手回数だけ足す

ans = 0
for i in range(len(H) - 1, -1, -1):
  if H[i] == 0:
    continue
  if H[i] <= M: # H[i]回の握手ができる
    ans += i * H[i]
    M -= H[i]
  else: # H[i]回の握手ができないので、残った回数だけ握手する
    ans += M * i
    break

print(ans)

Measured memory_bytes: 49072
#include<bits/stdc++.h>
using namespace std;
int n,d[10000];
int tt(int x,int c){
  int y=x+1,k=n;
  x--;
  while(1){
    bool f=0;
    int t=1,nx=x,ny=y;
    for(int i=x;i>=0;i--)
      if(c==d[i])t++,nx=i,f=1;
      else break;
    if(f)nx--,f=0;
    for(int i=y;i<n;i++)
      if(c==d[i])t++,ny=i,f=1;
      else break;
    if(f)ny++;
    if(t<4)break;
     if(nx)c=d[nx],x=nx-1,y=ny;
    else if(ny!=n)c=d[ny],x=nx,y=ny+1;
    k-=t;
  }
  return k;
}

int main(){
  while(cin>>n,n){
    for(int i=0;i<n;i++)cin>>d[i];
    int ans=n;
    for(int i=0;i<n;i++)
      for(int j=1;j<=3;j++)
	ans=min(ans,tt(i,j));
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include<iomanip>

#define rep(i, n) for(ll i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(ll i=int(a);i<int(b);i++)
#define all(x) (x).begin(),(x).end()

typedef long long ll;

using namespace std;


#include <vector>
using namespace std;


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

int  main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout<<setprecision(10);
  ll N,M;
  cin>>N>>M;
  vector<pair<int,int>> edge(M);
  vector<ll>ans(M);
  rep(i,M)
  {
    ll a,b;
    cin>>a>>b;
    edge[i]=make_pair(a,b);
  }
  ans[M-1]=((ll)(N-1))*N/2;
  UnionFind uf(N);
  for(ll i=M-2;i>=0;i--)
  {
    //cout<<"samegroup"<<endl;
    //cout<<edge[i+1].first-1<<" "<<edge[i+1].second-1<<endl;
  //  cout<<is_same_group(edge[i+1].first-1-1,edge[i+1].second-1-1)<<endl;

    if(uf.findSet(edge[i+1].first-1,edge[i+1].second-1))
    {
      ans[i]=ans[i+1];
      uf.unionSet(edge[i+1].first-1,edge[i+1].second-1);
    }
    else
    {
    ll sa=uf.size(edge[i+1].first-1);
    ll sb=uf.size(edge[i+1].second-1);
    //cout<<sa<<" "<<sb<<endl;
    ans[i]=ans[i+1]-sa*sb;
    uf.unionSet(edge[i+1].first-1,edge[i+1].second-1);
    }
  }
  cout<<endl;
  rep(i,M)
  {
    cout<<ans[i]<<'\n';
  }
  cout<<endl;






  return 0;

}


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

int main() {
  int n,k;
  cin >> n >> k;
  vector<int> p(n);
  for(int i=0; i<n; i++) cin >> p[i];
  sort(p.begin(),p.end());
  
  int s = 0;
  for(int i=0; i<k; i++) s += p[i];
  
  cout << s << endl;
	return 0;
}


Measured memory_bytes: 3640
using System;
using static System.Console;
using System.Linq;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] tmp = ReadLine().Split(' ').Select(int.Parse).ToArray();
            int A = tmp[0];
            int B = tmp[1];
            Write(A >= 2 * B ? A - 2 * B : 0);
        }
    }
}

Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>

#define rep(i, n) for(int i = 0; i < n; ++i)

using namespace std;

int n;
char x[1001];
int d;
int s;
int c[1000];

int main(){
  cin >> n >> x >> d;
  rep(i, n){
    if(s == d){
      break;
    }
    if(x[i] == '0'){
      x[i] = '1';
      c[i] = 1;
      ++s;
    }
  }
  for(int i = n - 1; i >= 0; --i){
    if(s == d){
      break;
    }
    if(!c[i]){
      x[i] = '0';
      ++s;
    }
  }
  cout << x << endl;
  return 0;
}

Measured memory_bytes: 3088
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vll>;
using vc = vector<char>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using stkll = vector<pll>;
const ll INF = 1LL << 60;
const ll MOD = 1e9 + 7;
#define rep(i, n) for (ll i = 0; i < (n); i++)
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
#ifndef ONLINE_JUDGE
    #define debug(x) cerr << #x << ": " << x << endl;
#else
    #define debug(x)
#endif

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll n; cin >> n;
    vll a(n);
    vector<pll> v;
    rep(i, n) {
        cin >> a[i];
        v.emplace_back(i - a[i], i);
    }
    sort(v.begin(), v.end());

    ll ans = 0;
    rep(i, n) {
        ll x = i + a[i];
        ans += lower_bound(v.begin(), v.end(), pll(x+1, 0))
                - lower_bound(v.begin(), v.end(), pll(x, i+1));
    }
    cout << ans << endl;
}


Measured memory_bytes: 8952
#include<bits/stdc++.h>
#define ll long long 
using namespace std;
long long int m=1000000007;
long long int power(long long int p,long long int k)
{
long long int a=1;
while(k)
{
if(k&1)
a=(a*p)%m;
p=(p*p)%m;
k>>=1;
}
return a;
}
int main()
{
ll n,i;
cin>>n;
double a[n],ans=0;
for(i=0;i<n;i++)
{
cin>>a[i];
ans+=(1/a[i]);
}
printf("%.15f",(1/ans));
return 0;
}
 

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

bool judge(int s) {
	int tmp,sum=s;
	for (int i = 0;sum>0;i++) {
		sum = s-4*i;
		if (sum == 0) 
			return true;
		for (int j = 1,tmp=sum;tmp > 0;j++) {
			tmp -= 7*j;
			if (tmp == 0) {
				return true;
			}
		}
	}
	return false;
}
int main() {
	int N;
	cin >> N;

	cout<<(judge(N) ? "Yes" : "No") << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <queue>
using namespace std;
struct id{
    int c[101];
    int p=0;
    int d=-1;
    int u=0;
};
int n,t=0;
id a[101];
queue<int> q;
void bps(int e){
    q.push(e);
    while(!q.empty()){
        int f=q.front();
        for(int i=1;i<=n;i++){
            if(a[f].c[i]==1&&a[i].u==0){
                a[i].d=a[f].d+1;
                q.push(i);
                a[i].u++;
            }
        }
        q.pop();
        a[f].u++;
    }
    
}

int main(){
    int x,y,z;
    cin>>n;
    for(int i=0;i<n;i++){
        cin>>x>>y;
        for(int j=1;j<=y;j++){
            cin>>z;
            a[x].c[z]=1;
            a[z].p=x;
        }
    }
    a[1].d+=1;
    bps(1);
    for(int i=1;i<=n;i++){
        cout<<i<<" "<<a[i].d<<endl;
    }
    return 0;
}



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

#define MP make_pair
#define PB push_back
#define ALL(x)      (x).begin(),(x).end()
#define REP(i,n)    for(int i=0;i<(n);i++)
#define REP1(i,n)   for(int i=1;i<(n);i++)
#define REP2(i,d,n) for(int i=(d);i<(n);i++)
#define RREP(i,n)   for(int i=(n);i>=0;i--)
#define CLR(a)      memset((a),0,sizeof(a))
#define MCLR(a)     memset((a),-1,sizeof(a))
#define RANGE(x,y,maxX,maxY) (0 <= (x) && 0 <= (y) && (x) < (maxX) && (y) < (maxY))

typedef long long LL;
typedef unsigned long long ULL;
typedef vector<int> VI;
typedef vector<VI > VVI;
typedef vector<string> VS;
typedef vector<LL> VLL;
typedef pair<int,int> PII;

const int INF = 0x3f3f3f3f;
const LL INFL = 0x3f3f3f3f3f3f3f3fLL;
const double EPS = 1e-9;

const int DX[]={1,0,-1,0},DY[]={0,-1,0,1};


void solve(std::string T){
    REP(i, T.size()) {
        if(T[i] == '?') {
            cout << "D";
        } else {
            cout << T[i];
        }
    }

    cout << endl;
}

int main(){
    std::string T;
    std::cin >> T;
    solve(T);
    return 0;
}


Measured memory_bytes: 3924
#include <iostream>
#include <vector>
using namespace std;
using ll=long long;
#define rep(i,a,b) for(ll i=a;i<ll(b);i++)


// Union-Find
// 参考コードソース[https://github.com/atcoder/live_library/blob/master/uf.cpp]

// シンプルなUnion-Find木データ構造
// コンストラクタ: 要素数(頂点数)を指定
struct UnionFind {
    vector<int> data;
    UnionFind(int size = 0) : data(size, -1) {}
    int root(int x) {
        if(data[x] < 0) return x;
        return x = root(data[x]);
    }
    bool unite(int x, int y) {
        x = root(x); y = root(y);
        if(x == y) return false;
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y]; data[y] = x;
        return true;
    }
    bool same(int x, int y) { return root(x) == root(y); }
    int size(int x) { return -data[root(x)]; }
};


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

    UnionFind UF(n);

    rep(i, 0, m){
        int a, b; cin >> a >> b;
        a--;b--;
        UF.unite(a, b);
    }

    int ans = 0;
    rep(i, 0, n){
        ans = max(ans, UF.size(i));
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3672
X, Y, Z, K = map(int, input().split())

A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))

C.sort(reverse=True)
tmp = []
ans = []

for i in range(X):
	for j in range(Y):
		tmp.append(A[i]+B[j])

tmp.sort(reverse=True)
del tmp[min(K, X*Y):]

for i in range(len(tmp)):
	for j in range(min(Z, K)):
		ans.append(tmp[i]+C[j])

ans.sort(reverse=True)

for i in range(min(K, X*Y*Z)):
	print(ans[i])


Measured memory_bytes: 139452
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;

int main()
{
    int n, l;
    cin >> n >> l;
    ll count = 0;
    int x;
    int ans = 1000;
    int memo;
    for (int i = 1; i <= n; i++)
    {
        x = l + i - 1;
        count += x;
        ans = min(abs(x), ans);
        if (ans == abs(x))
        {
            memo = x;
        }
    }
    cout << count - memo << endl;
}


Measured memory_bytes: 256