akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  
  int N;
  cin >> N;
  
  int h[N + 1] = {};
  for (int i = 0; i < N; i++) {
    cin >> h[i];
  }
  
  int maxh = 0;
  for (int i = 0; i < N; i++) {
    maxh = max(maxh, h[i]);
  }
  
  int count;
  for (int i = 1; i <= maxh; i++) {
    for (int j = 0; j < N; j++) {
      if (h[j] >= i && h[j + 1] < i) {
        count += 1;
      }
    }
  }
  
  cout << count << endl;
  
}

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





int main(){

  int n,m,a,b;
  cin>>n>>m>>a>>b;
vector<long long>x(n);
for(int i=0;i<n;i++){
  cin>>x[i];
}
vector<long long>y(m);
for(int i=0;i<m;i++){
  cin>>y[i];
}

bool s=true;
for(int i=a+1;i<=b;i++){
  int ans1=0,ans2=0;
  
  
  for(int j=0;j<n;j++){
    if(x[j]<i){
      ans1++;
    }
  }

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

  if(ans1==n && ans2==m){
    cout<<"No"<<" "<<"War"<<endl;
    s=false;
    break;
  }else{
    s=true;
  }

  
}


if(s){
  
  cout<<"War"<<endl;
}



}


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

int main() {
    int N, T, ci, ti;
    int min_c = MAX + 1;
    cin >> N >> T;
    for (int i = 0; i < N; i++) {
        cin >> ci >> ti;
        if (ti <= T && ci < min_c) min_c = ci;
    }

    if (min_c > MAX) cout << "TLE" << endl;
    else cout << min_c << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fs first
#define sc second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define ALL(A) A.begin(),A.end()
#define RALL(A) A.rbegin(),A.rend()
typedef long long ll;
typedef pair<ll,ll> P;
const ll mod=1000000007;
const ll LINF=1LL<<60;
const int INF=1<<30;

int main(){
	ll n,m;cin>>n>>m;
	string s,t;cin>>s>>t;
	ll gcd = __gcd(n,m);
	ll lcm = n / gcd * m;
	for(ll i = 0; i < gcd; i++) {
		if (s[n / gcd * i] != t[m / gcd * i]){
			cout << -1 << endl;
			return 0;
		}
	}
	cout << lcm << endl;

	return 0;
}

Measured memory_bytes: 512
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""


H, W = map(int, sys.stdin.readline().split())
x = ["x" for _ in range(W + 2)]
DL = [x]

for _ in range(H):
    L = list(sys.stdin.readline().rstrip())
    L = ["x"] + L + ["x"]
    DL.append(L)
DL.append(x)

for i in range(1, H + 1):
    for j in range(1, W + 1):
        if DL[i][j] == ".":
            cnt = 0
            for k in range(i - 1, i + 2):
                for l in range(j - 1, j + 2):
                    if DL[k][l] == "#":
                        cnt += 1
            DL[i][j] = cnt

ans = []
for d in DL[1:len(DL) - 1]:
    print(''.join([str(x) for x in d if x != "x"]))

Measured memory_bytes: 67564
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        String s = sc.next();
        final long MOD = 1_000_000_007L;
        int[] alpha = new int[26];
        for (int i = 0; i < n; i++) {
            char c = s.charAt(i);
            alpha[c - 'a']++;
        }
        long ans = 1;
        for (int i = 0; i < alpha.length; i++) {
            ans *= alpha[i] + 1;
            ans %= MOD;
        }
        System.out.println((ans + MOD - 1) % MOD);
    }
}


Measured memory_bytes: 27428
inputs = input().split(" ")
n = int(inputs[0])
k = int(inputs[1])
h = input().split(" ")
for i in range(n):
    h[i] = int(h[i])
h = sorted(h)[::-1]

all = 0
for i in range(k, n):
    all += h[i]

print(all)


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

int main() {
    int h,w,r,x,y;
    cin>>w>>h>>x>>y>>r;
    if(x-r>=0&&x+r<=w&&y-r>=0&&y+r<=h)
        cout<<"Yes"<< endl;
        else
        cout<<"No"<< endl;
}


Measured memory_bytes: 3124
sx, sy, tx, ty = tuple(map(int, input().split()))

x = tx-sx
y = ty-sy

s = ['U']*y + ['R']*(x+1) + ['D']*(y+1) + ['L']*(x+1) + ['U'] + ['R']*x + ['U']*(y+1) + ['L']*(x+1) + ['D']*(y+1) + ['R']
print(''.join(s))


Measured memory_bytes: 3188
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#define ll long long
using namespace std;

int n, m, ans = 0;
bool a[8][8] = {}, b[8] = {};


int dfs(int x, int t) {
	if (t == n - 1) return ans += 1;
	for (int i = 0; i < n; i++) {
		if (a[x][i] && !b[i]) {
			b[i] = true;
			ans = dfs(i, t + 1);
			b[i] = false;
		}
	}
	return ans;
}

int main() {
	cin >> n >> m;
	for (int i = 0; i < m; i++) {
		int tmp1, tmp2;
		cin >> tmp1 >> tmp2;
		tmp1--; tmp2--;
		a[tmp1][tmp2] = a[tmp2][tmp1] = true;
	}
	b[0] = true;
	cout << dfs(0, 0) << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SZ(v) int((v).size())
#define ALL(vec) begin(vec), end(vec)
typedef long long i64;
template<typename T> inline bool uax(T &x, T y) {return (y > x) ? x = y, true : false;}
template<typename T> inline bool uin(T &x, T y) {return (y < x) ? x = y, true : false;}
#ifdef Rahul
# define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); \
  stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#else
# define error(...) 42;
#endif
string to_string(char c) { return "'" + string(1, c) + "'";}
string to_string(string s) { return '"' + s + '"';}
string to_string(const char* s) { return to_string((string) s);}
template<typename A> string to_string(A);
template<typename A, typename B> string to_string(pair<A, B> p){
  return "(" + to_string(p.first) + ": " + to_string(p.second) + ")";}
template<typename A> string to_string(A v) {bool f = false; string r = "{"; 
  for (auto x: v) {if (f) r += ", "; r += to_string(x); f = true;} return r += "}";}
template<typename A> string to_string(vector<vector<A>> v) {string r; 
  for (auto x: v) r += "\n" + to_string(x); return r;}
int Nerr;
template<typename A> string to_string(A *p) {return to_string(vector<A>(p, p + Nerr));}
void err(istream_iterator<string>) { cerr << endl; }
template<typename T,typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " =: " << to_string(a) << "; "; err(++it, args...); }
template<typename T> void kek(T ans) {cout << ans << endl; exit(0);}
#define Lu(...) [&] (auto &&u) { return __VA_ARGS__; }
#define Luv(...) [&] (auto &&u, auto &&v) { return __VA_ARGS__; }
int const MOD = 1e9 + 7;
long long const INF = 1e18 + 42;
/***********************************************************************/
const int N = 2e5 + 42;
int a[N], b[N];
i64 c(i64 n) {
  return n * (n - 1) / 2;
}
int32_t main() {
  cin.tie(nullptr) -> sync_with_stdio(false);
  
  int n; cin >> n;
  i64 ans = 0;
  for (int i = 1; i <= n; ++i) {
    int x; cin >> x;
    ans += a[x];
    b[i] = x;
    a[x]++;
  }
  error(ans);
  for (int i = 1; i <= n; ++i) {
    cout << ans - c(a[b[i]]) + c(a[b[i]] - 1) << '\n';
  }
}


Measured memory_bytes: 3712
#include <iostream>
#include <algorithm>
#include <math.h>
#include <vector>
#include <map>
using namespace std;

int main(){
  int a, b; cin >> a >> b;
  int xa = 0, xb = 0;
  for(int i = 0; i < b; i++){
    xa += a * pow(10, i);
  }
  for(int i = 0; i < a; i++){
    xb += b * pow(10, i);
  }
  if(xa >= xb) cout << xa << endl;
  else cout << xb << endl;
  return 0;
}


Measured memory_bytes: 256
package main

import "fmt"

var max int
var ans int

func check753(n int) bool {
	seven := false
	five := false
	three := false
	for i := n; i > 0; i /= 10 {
		k := i % 10
		if k == 3 {
			three = true
		}
		if k == 5 {
			five = true
		}
		if k == 7 {
			seven = true
		}
	}
	return seven && five && three
}

func find(n int) {
	if n > max {
		return
	}
	if check753(n) {
		ans++
	}
	for i := 3; i <= 7; i += 2 {
		find(n*10 + i)
	}
}

func main() {
	ans = 0
	fmt.Scanf("%d", &max)
	find(0)
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
int main (){
	char ch [6];
	scanf ( "%s" , ch ) ;
	int len = strlen ( ch ) ;
	for ( int i = 1 ; i < len ; ++ i )
		if ( ch [i-1] == 'A' && ch [i] == 'C' ) {
			printf ( "Yes" );
			return 0 ;
		}
	printf ( "No" );
	return 0 ;
}

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

class Solution
{
    static void Main()
    {
        var s = Console.ReadLine();
        var left = 0;
        var right = s.Length - 1;
        int count = 0;

        while (left < right)
        {
            if (s[left] == s[right])
            {
                left++;
                right--;
                continue;
            }

            if (s[left] == 'x')
            {
                left++;
                count++;
            }
            else if (s[right] == 'x')
            {
                right--;
                count++;
            }
            else
            {
                count = -1;
                break;
            }
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13280
H, W = map(int, input().split())
map = [list('.' * (W + 2)) for _ in range(H + 2)]
Smap = [input() for _ in range(H)]

# mapping

for line in range(1, H + 1):
    for row in range(1, W + 1):
        mapper = Smap[line - 1][row - 1]
        map[line][row] = mapper

for line in range(1, H + 1):
    for row in range(1, W + 1):

        bomb_counter = 0
        for counter_line in range(-1, 2):
            for counter_row in range(-1, 2):
                if counter_line == 0 and counter_row == 0:
                    pass
                elif map[counter_line + line][counter_row + row] == '#':
                    bomb_counter += 1
        if map[line][row] != '#':
            map[line][row] = str(bomb_counter)

for i in range(1, len(map)):
    print('.'.join(map[i]).replace('.', ''))


Measured memory_bytes: 3188
#include <bits/stdc++.h>
using namespace std;
 
int main(){
  //input
  string S;  cin>> S;
  vector<int>vec(S.size());
 
  //compute
  for(int i=0;i<S.size();i++){
    if(S[i]=='A' ||S[i]=='T' ||S[i]=='G' ||S[i]=='C'){
    vec[i]=1;
    }
    else{
      vec[i]=0;
    }    
  }
  
  vector<int>vec_ans;
  int sum=0;
  for(int i=0;i<S.size();i++){   
    if(vec[i]!=1){
      vec_ans.push_back(sum);
      sum=0;
    }
    else{
      sum++;
      vec_ans.push_back(sum);
    }
  } 
  sort(vec_ans.begin(),vec_ans.end());
  reverse(vec_ans.begin(),vec_ans.end());

  //output
  cout<<vec_ans[0]<<endl;  
}
  


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<queue>
#include<random>
#include<set>
#include<map>
#include<functional>
using namespace std;
#define int long long
#define inf 1145141919
#define rep(i,n) for(int i=0;i<n;i++)
typedef pair<int, int>P;
typedef pair<int, P> PP;
struct edge { int u, v, cost; };
int par[114514], rnk[114514];

void init(int n) {
	for (int i = 0; i<n; i++) {
		par[i] = i;
		rnk[i] = 0;
	}
}
int find(int x) {
	if (par[x] == x)return x;
	return par[x] = find(par[x]);
}
void unite(int x, int y) {
	x = find(x);
	y = find(y);
	if (x == y)return;
	if (rnk[x]<rnk[y])par[x] = y;
	else {
		par[y] = x;
		if (rnk[x] == rnk[y])rnk[x]++;
	}

}

int x[1141], y[1141], z[1141];
PP p1[1141], p2[1141], p3[1141];
int absa(int a, int b, int c) {
	return abs(a) + abs(b) + abs(c);
}
vector<int>V[8];
signed main() {
	int n, m; cin >> n >> m;
	rep(i, n)cin >> x[i] >> y[i] >> z[i];
	int ans = 0;
	rep(X, 8) {
		vector<int>V;
		int r = 0;
		rep(i, n) {
			int sum = 0;
			if (X & 1)sum += x[i];
			else sum -= x[i];
			if (X & 2)sum += y[i];
			else sum -= y[i];
			if (X & 4)sum += z[i];
			else sum -= z[i];
			V.push_back(sum);
		}
		
		sort(V.begin(), V.end());
		for (int i = n - 1; i > n - m-1; i--) {
			r += V[i];
		}
		ans = max(ans, r);
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())

counter = 0
for a in range(A+1):
    for b in range(B+1):
        c = X//50 - 10*a - 2*b
        if (0<=c<=C) and 500*a+100*b+50*c == X:
            counter += 1

print(counter)


Measured memory_bytes: 3060
import math


def inputIntList():
    return [int(s) for s in input().split()]


def inputInt():
    return int(input())


def main():
    N = inputInt()
    h = inputIntList()
    h.append(0)
    dp = [float("inf") for _ in range(N + 2)]
    dp[0] = 0
    for i in range(N - 1):
        if abs(h[i] - h[i + 1]) + dp[i] < dp[i + 1]:
            dp[i + 1] = abs(h[i] - h[i + 1]) + dp[i]

        if abs(h[i] - h[i + 2]) + dp[i] < dp[i + 2]:
            dp[i + 2] = abs(h[i] - h[i + 2]) + dp[i]

    return dp[N - 1]


if __name__ == "__main__":
    print(main())


Measured memory_bytes: 14108
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF (INT_MAX / 4)
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
/* clang-format off */
#define TIMER_S(start) chrono::system_clock::time_point start = chrono::system_clock::now();
#define TIMER_E(end) chrono::system_clock::time_point end = chrono::system_clock::now();
#define TIME(start, end) cout << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count()) << "ms" << "\n";
/* clang-format on */

int main() {
  int n, ans = 0;
  cin >> n;
  vector<vector<int>> des(n, vector<int>(n,-1));
  REP(i, n) {
    int a;
    cin >> a;
    REP(j, a) {
      int x, y;
      cin >> x >> y;
      x--;
      des.at(i).at(x) = y;
    }
  }

  for (int bit = 0; bit < (1 << n); bit++) {
    bool f = true;
    REP(i, n) {
      REP(j, n) {
        if (bit & (1 << i)) {
          if ((des.at(i).at(j) == 0 && bit & (1 << j)) ||
              (des.at(i).at(j) == 1 && !(bit & (1 << j)))) {
            f = false;
            break;
          }
        }
      }
      if (!f) break;
    }
    if (f) {
      ans=max(ans,__builtin_popcount(bit));
     // cout << bitset<5>(bit) << "\n";
    }
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000
#define int long long
const int MAX_N = 1 << 18;

int n, dat[2 * MAX_N - 1];

void init(int n_) {
    n = 1;
    while(n < n_) n *= 2;
    rep(i, 2 * n - 1) dat[i] = 0;
}

// k番目の値(0-indexed)をaに変更
void update(int k, int a) {
    k += n - 1;
    dat[k] = a;
    while(k > 0) {
        k = (k - 1) / 2;
        dat[k] = max(dat[k * 2 + 1], dat[k * 2 + 2]);
    }
}
// [a, b)の最大値を探す．
int query(int a, int b, int k, int l, int r) {
    if(r <= a || b <= l) return 0;
    if(a <= l && r <= b) return dat[k];
    else {
        int vl = query(a, b, k * 2 + 1, l, (l + r) / 2);
        int vr = query(a, b, k * 2 + 2, (l + r) / 2, r);
        return max(vl, vr);
    }
}
int h[200010];
int a[200010];

signed main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N; cin >> N;
    init(N);
    rep(i, N) cin >> h[i];
    rep(i, N) cin >> a[i];
    rep(i, N) {
       int tmp = query(0, h[i], 0, 0, n);
       update(h[i] - 1, tmp + a[i]);
       //rep(i, N) cout << dat[n - 1 + i] << " ";
       //cout << endl;
    }
    cout << query(0, N, 0, 0, n) << endl;

    return 0;
}

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

import sys
import os

N = int(input())

def is_A(s):
    if s[0:2] != ">'":
        return False

    if s[-1] != '~':
        return False

    body = s[2:-1]

    if len(body) % 2 == 0:
        return False

    # body = '==#=='
    center_index = len(body) // 2
    if body[center_index] != '#':
        return False

    if body.count('#') != 1:
        return False

    lst = body.split('#')
    if len(lst) != 2:
        return False

    if len(lst[0]) > 0 and lst[0] == lst[1] and len(lst[0]) == lst[0].count('='):
        return True
    else:
        return False

def is_B(s):
    if s[0:2] != ">^":
        return False

    if s[-2:] != '~~':
        return False

    body = s[2:-2]

    if len(body) % 2 != 0:
        return False
    elif body.count('Q=') > 0 and body.count('Q=') == len(body) // 2:
        return True
    else:
        return False

for s in sys.stdin:
    s = s.strip()

    if is_A(s):
        print('A')
    elif is_B(s):
        print('B')
    else:
        print('NA')

Measured memory_bytes: 7788
#include <bits/stdc++.h>
#define ll long long int
#define pr pair<ll, ll>
#define tp tuple<ll, ll, ll>
using namespace std;
long long int mod = 1e9 + 7;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    ll n, k;
    cin >> n >> k;
    ll a[n + 1];
    for (ll i = 1; i <= n; i++)
        cin >> a[i];
    set<ll> s;
    vector<ll> v;
    ll cur = 1;
    s.insert(1);
    v.push_back(1);
    while (3)
    {
        cur = a[cur];
        if (s.count(cur) == 1)
            break;
        s.insert(cur);
        v.push_back(cur);
    }
    ll ans = 1, i = 0;
    while (k && v[i] != cur)
    {
        i++;
        k--;
    }
    ll size = v.size() - i;
    k = k % size;
    while (k)
    {
        i++;
        k--;
    }
    cout << v[i] << endl;
    return 0;
}

Measured memory_bytes: 15428
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

class Program
{
    static void Main()
    {
        SetOut(new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false });

        var nq = ReadLine().Split().Select(int.Parse).ToArray();
        var uf = new UnionFind(nq[0]);
        for (int i = 0; i < nq[1]; i++)
        {
            var line = ReadLine().Split(' ');
            if (line[0] == "0") uf.Unite(int.Parse(line[1]), int.Parse(line[2]));
            else WriteLine(uf.Same(int.Parse(line[1]), int.Parse(line[2])) ? "1" : "0");
        }
        Out.Flush();
    }
}

public class UnionFind
{
    int[] parent;
    int count;
    public int Count => count;

    public UnionFind(int length)
    {
        parent = new int[length];
        for (int i = 0; i < parent.Length; i++)
        {
            parent[i] = -1;
        }
        count = length;
    }

    public int Root(int x) => parent[x] < 0 ? x : parent[x] = Root(parent[x]);

    public bool Same(int x, int y) => Root(x) == Root(y);

    public void Unite(int x, int y)
    {
        x = Root(x);
        y = Root(y);
        if (x == y) return;
        count--;
        if (parent[x] < parent[y])
        {
            parent[x] += parent[y];
            parent[y] = x;
        }
        else
        {
            parent[y] += parent[x];
            parent[x] = y;
        }
    }

    public int Size(int x) => -parent[Root(x)];
}



Measured memory_bytes: 22520
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/range/irange.hpp>
#include <boost/range/adaptor/indexed.hpp>

using namespace std;
using namespace boost::adaptors;
using ll = int64_t;
using vecint = vector<int>;
using vecll = vector<ll>;
using boost::irange;

int main()
{
  int n,k,q;
  cin>>n>>k>>q;
  vecint v(n, k-q);
  for(int i : irange(0, q)) {
    int a;
    cin>>a;
    --a;
    v[a]++;
  }
  for (auto a : v) {
    if (a > 0) {
      cout<<"Yes"<<endl;
    } else {
      cout<<"No"<<endl;
    }
  }
  return 0;
}


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

#define ll long long int
#define pb push_back
#define endl "\n"



int main()
{
    int x;
    cin>>x;
    if(x == 0) cout<<1<<endl;
    else if(x == 1) cout<<0<<endl;
    return 0;        
}


Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;;
#define ll long long
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define INF 1<<30
#define LINF 1LL<<62
#define all(x) (x).begin(), (x).end()
#define mp make_pair
#define pb push_back
const int MOD = 1000000007;
 
typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  string s;cin >> s;
  ll tmp = 0;
  REP(i,s.size()){
      if(s[i] == '0'){
          tmp++;
      }
  }
    ll ans = 2 * min(tmp, (ll)s.size()-tmp);
    cout << ans << endl;


}

Measured memory_bytes: 512
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
const int INF = (int)1e9 + 7;
#define rep(i, n) for (int i = 0; i < n; i++)

int n;
vector<int> r;
vector<vector<int>> spc;

bool check() {
    vector<int> total(n);
    for (int k = 0; k < 3; k++) {
        vector<int> rank(n, 0);
        rep(i, n) rep(j, n) if (spc[k][i] < spc[k][j]) rank[i]++;
        rep(i, n) total[i] += r[rank[i]];
    }
    vector<int> rank(n, 0);
    rep(i, n) rep(j, n) if (total[i] < total[j]) rank[i]++;
    return rank[0] <= 8 - 1;
}

int main() {
    while (cin >> n) {
        r.resize(n); spc.assign(3, vector<int>(n));
        rep(i, n) cin >> r[i];
        rep(i, n) cin >> spc[0][i] >> spc[1][i] >> spc[2][i];
        int ans = INF;
        rep(k, 3) for (int p = 1; p <= 100; p++) {
            spc[k][0] += p;
            if (check()) ans = min(ans, p);
            spc[k][0] -= p;
        }
        if (ans == INF) cout << "Saiko" << endl;
        else cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 3168
#include<bits/stdc++.h>
#define rep(i,n) for(int i=1;i<n;i++)


using namespace std;

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

  rep(i,10){
    if(n % i == 0 && n / i < 10) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
using namespace std;

typedef int64_t ll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define vll vector<ll>
#define all(v) v.begin(), v.end()



int main() {
	string sa, sb, sc;
	cin >> sa; cin >> sb; cin >> sc;
	reverse(all(sa)); reverse(all(sb)); reverse(all(sc));
	char turn = 'a';
	while (true) {
		if (turn == 'a') {
			if (sa.empty()) break;
			turn = sa.back();
			sa.pop_back();
		}
		else if (turn == 'b') {
			if (sb.empty()) break;
			turn = sb.back();
			sb.pop_back();
		}
		else {
			if (sc.empty()) break;
			turn = sc.back();
			sc.pop_back();
		}
	}

	cout << char(turn + ('A' - 'a')) << endl;
}


Measured memory_bytes: 256
// spnauT
//
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int _b=(b),i=(a);i<_b;++i)
#define ROF(i,b,a) for(int _a=(a),i=(b);i>_a;--i)
#define REP(n) for(int _n=(n);_n--;)
#define _1 first
#define _2 second
#define PB(x) push_back(x)
#define SZ(x) int((x).size())
#define ALL(x) (x).begin(),(x).end()
#define MSET(m,v) memset(m,v,sizeof(m))
#define MAX_PQ(T) priority_queue<T>
#define MIN_PQ(T) priority_queue<T,vector<T>,greater<T>>
#define IO(){ios_base::sync_with_stdio(0);cin.tie(0);}
#define nl '\n'
#define cint1(a) int a;cin>>a
#define cint2(a,b) int a,b;cin>>a>>b
#define cint3(a,b,c) int a,b,c;cin>>a>>b>>c
typedef long long LL;typedef pair<int,int> PII;
typedef vector<int>VI;typedef vector<LL>VL;typedef vector<PII>VP;
template<class A,class B>inline bool mina(A &x,const B &y){return(y<x)?(x=y,1):0;}
template<class A,class B>inline bool maxa(A &x,const B &y){return(x<y)?(x=y,1):0;}

#define MAXN ()

int D[10];

int main()
{
	IO();
	cint2(N,K);
	REP(K)
	{
		cint1(a);
		D[a] = 1;
	}

	for(int n = N; 1; ++n)
	{
		int a = n;
		int v = 1;
		while(a > 0)
		{
			int d = a % 10;
			a /= 10;
			if(D[d])
			{
				v = 0;
				break;
			}
		}
		if(v)
		{
			cout << n << nl;
			return 0;
		}
	}

	return 0;
}

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

const int MAXN = 1e3 + 10; //dummy
const ll MOD = 1e9 + 7;

template<typename T>
T fast_powerModulo( T a, T b, T M){T res = (T)1;a %= M;while( b ){if( b & 1 ) res = (res * a) % M;b >>= 1;a *= a;a %= M; }return res;}

int H, n;
vector<ll> a(MAXN), b(MAXN), dp((int)(1e4 + 10), __LONG_LONG_MAX__);

void solve(){
	cin >> H  >> n;
	for(int i = 0; i < n; ++i){
		cin >> a[i] >> b[i];
	}
	dp[0] = 0;
	for(int hlth = 0; hlth <= H; ++hlth){
		for(int i = 0; i < n; ++i){
			dp[hlth] = min(dp[max(0LL, hlth - a[i])] + b[i], dp[hlth] );
		}
	}
	cout << dp[H] << '\n';

}

int main(){
	ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr); 
	//int t; cin >> t;
	//while( t-- )
		solve();
	return 0;
}

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

int main() {
    int n;
    cin >> n;
    vector<int> vec(n, 0);
    rep(i, n-1){
        int num;
        cin >> num;
        vec[num-1]++;
    }
    rep(i, n){
        cout << vec[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 4052
import java.io.*;
import java.util.ArrayList;

public class Main {
	public static void main( String[] args ) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		Integer N = Integer.valueOf( br.readLine() );
		String[] A = br.readLine().split( " " );
		ArrayList< Integer > list = new ArrayList< Integer >();

		for( int i = 0; i < N; i++ ) {
			list.add( Integer.valueOf( A[i] ) );
		}
		boolean flg = true;
		int cnt = 0;
		while( flg ) {
			for( int i = 0; i < list.size(); i++ ) {
				if( ( list.get( i ) % 2 ) != 0 ){
					flg =  false;
					break;
				} else {
					list.set( i, ( list.get( i ) / 2 ) );
				}
			}
			cnt++;
		}
		System.out.println( cnt - 1 );
	}
}

Measured memory_bytes: 23252
//include
//------------------------------------------
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <complex>
#include <regex>

using namespace std;

#define SHOW_VECTOR(v) {std::cerr << #v << "\t:";for(const auto& xxx : v){std::cerr << xxx << " ";}std::cerr << "\n";}
#define SHOW_MAP(v){std::cerr << #v << endl; for(const auto& xxx: v){std::cerr << xxx.first << " " << xxx.second << "\n";}}


int main() {

    while (true) {

        int N, T, L, B;
        cin >> N >> T >> L >> B;

        if (!(N | T | L | B)) break;

        map<int, bool> Lose, Back;
        for (int i = 0; i < L; i++) {
            int l;
            cin >> l;
            Lose[l] = true;
        }
        for (int i = 0; i < B; i++) {
            int b;
            cin >> b;
            Back[b] = true;
        }

        vector<vector<double>> dp(T + 1, vector<double>(N + 1, 0));
        dp[0][0] = 1.0;

        for (int i = 0; i < T; i++) {
            for (int j = 0; j < N; j++) {
                int turn = i + 1;
                if (Lose[j]) {
                    if (i + 2 > T) continue;
                    turn = min(i + 2, T);
                }
                for (int k = 1; k <= 6; k++) {
                    int to = j + k;
                    if (to >= N) to = N - (j + k - N);
                    if (Back[to]) to = 0;
                    dp[turn][to] += dp[i][j] * (1.0 / 6.0);
                }
            }
            dp[i + 1][N] += dp[i][N];
        }

        cout << fixed << setprecision(10) << dp[T][N] << endl;

    }

    return 0;
}






























































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

int main() {
    int H, W;
    cin >> H >> W;
    string pre, now, next;
    cin >> now;
    for (int i = 0; i < H; i++) {
        if (i != H - 1) cin >> next;
        
        for (int j = 0; j < W; j++) {
            if (now[j] == '#') {
                cout << "#";
                continue;
            }
            int ans = 0;
            if (i != 0) {
                if (j > 0 && pre[j - 1] == '#') ans++;
                if (pre[j] == '#') ans++;
                if (j < W - 1 && pre[j + 1] == '#') ans++;
            }
            
            if (j > 0 && now[j - 1] == '#') ans++;
            if (j + 1 < W && now[j + 1] == '#') ans++;
            
            if (i != H - 1) {
                if (j > 0 && next[j - 1] == '#') ans++;
                if (next[j] == '#') ans++;
                if (j + 1 < W && next[j + 1] == '#') ans++;
            }
          
            cout << ans;
        }
        cout << endl;
        
        pre = now;
        now = next;
    }
}

Measured memory_bytes: 256
N, H, D = map(int,input().split())
MOD = 10**9 + 7

fact = [1]
fact_cum = [0] # 1! to N!
for i in range(1,N+1):
  fact.append((fact[-1]*i)%MOD)
  fact_cum.append((fact_cum[-1] + fact[-1])%MOD)

dp = [0] * (H+1)
dp_cum = [0] * (H+1)
dp[0] = 1
dp_cum[0] = 1

for n in range(1,H+1):
  x = dp_cum[n-1]
  if n > D:
    x -= dp_cum[n-D-1]
  x *= fact_cum[N]
  x %= MOD
  dp[n] = x
  dp_cum[n] = (dp_cum[n-1] + x)%MOD


answer = dp[H]
answer *= fact[N]
answer %= MOD
answer *= pow(fact_cum[N],MOD-2,MOD)
answer %= MOD

print(answer)

Measured memory_bytes: 133872
'''
自宅用PCでの解答
'''
import math
#import numpy as np
import itertools
import queue
import bisect
from collections import deque,defaultdict
import heapq as hpq
from sys import stdin,setrecursionlimit
#from scipy.sparse.csgraph import dijkstra
#from scipy.sparse import csr_matrix
ipt = stdin.readline
setrecursionlimit(10**7)

def main():
    n = int(ipt())
#    n = 10**5
    ls_by = [[] for i in range(n+1)]
    for i in range(2,n+1):
        a = int(ipt())
        ls_by[a].append(i)
    def dpt(k):
        st = []
        for i in ls_by[k]:
            st.append(dpt(i)+1)
        st.sort(reverse=True)
        ma = 0
        for i,si in enumerate(st):
            if si+i > ma:
                ma = si+i
        return ma

    print(dpt(1))


    return None

if __name__ == '__main__':
    main()


Measured memory_bytes: 143224
import java.util.*;

public class Main{
	public static void main(String[] args){
		//new Main().printHelloWorld();
		//System.out.println(new Main().ITP1_1_B(Integer.parseInt(new Scanner(System.in).next())));
		//new Main().ITP1_1_C();
		//new Main().ITP1_1_D();
		//new Main().ITP1_2_A();
		//new Main().ITP1_2_B();
		//new Main().ITP1_2_C();
		//new Main().ITP1_2_D();
		//new Main().ITP1_3_A();
		new Main().ITP1_3_B();
	}

	public void printHelloWorld(){
		System.out.println("Hello World");
	}

	public int ITP1_1_B(int x){
		return x*x*x;
	}

	public void ITP1_1_C(){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		System.out.println(a*b + " " + 2*(a+b));
	}

	public void ITP1_1_D(){
		int seconds = new Scanner(System.in).nextInt();
		System.out.println(seconds/3600 + ":" + (seconds%3600)/60 + ":" + (seconds%3600)%60);
	}

	public void ITP1_2_A(){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		System.out.println((a==b)?"a == b":(a > b)?"a > b":"a < b");
	}

	public void ITP1_2_B(){
		Scanner scan = new Scanner(System.in);
		int a = scan.nextInt();
		int b = scan.nextInt();
		int c = scan.nextInt();
		System.out.println((a < b && b < c)?"Yes":"No");
	}

	public void ITP1_2_C(){
		Scanner scan = new Scanner(System.in);
		int[] a = new int[3];
		a[0] = scan.nextInt();
		a[1] = scan.nextInt();
		a[2] = scan.nextInt();
		for(int i=0;i<a.length-1;i++){
			for(int j=i+1;j<a.length;j++){
				if(a[i] > a[j]){
					int t=a[i];a[i]=a[j];a[j]=t;
				}
			}
		}
		System.out.println(a[0] + " " + a[1] + " " + a[2]);
	}

	public void ITP1_2_D(){
		Scanner scan = new Scanner(System.in);
		int w = scan.nextInt();
		int h = scan.nextInt();
		int x = scan.nextInt();
		int y = scan.nextInt();
		int r = scan.nextInt();
		System.out.println((x+r<=w && x-r>=0 && y+r<=h && y-r>=0)?"Yes":"No");
	}

	public void ITP1_3_A(){
		for(int i=0;i<1000;i++){
			System.out.println("Hello World");
		}
	}

	public void ITP1_3_B(){
		Scanner scan = new Scanner(System.in);
		int i = 1;
		while(scan.hasNext()){
			int x = scan.nextInt();
			if(x == 0){
				break;
			}
			System.out.println("Case " + i + ": " + x);
			i++;
		}
	}
}

Measured memory_bytes: 42992
#include <algorithm>
#include <cmath>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <vector>
#define rep(i, f, n) for (int i = (f); i < (int)(n); i++)
#define repe(i, f, n) for (int i = (f); i <= (int)(n); i++)
using namespace std;
using ll = long long;
using pint = pair<int, int>;

const int INF = 1001001001;

int main() {
  int D, N;
  cin >> D >> N;

  if (D == 0) {
    if (N == 100)
      cout << 101 << endl;
    else
      cout << N << endl;
  } else if (D == 1) {
    if (N == 100)
      cout << 10100 << endl;
    else
      cout << N * 100 << endl;
  } else {
    if (N == 100)
      cout << 1010000 << endl;
    else
      cout << N * 10000 << endl;
  }

  return 0;
}


Measured memory_bytes: 3596
class node:
    def __init__(self, num):
        self.number     = num
        self.distance   = -1
        self.link_node  = []
        self.is_serched = False

class queue:
    def __init__(self):
        self.top = 0
        self.bottom = 0
        self.que = []
    
    def dequeue(self):
        self.top = self.top + 1
        return self.que[self.top - 1]
    
    def enqueue(self, item):
        self.que.append(item)
        self.bottom = self.bottom + 1
    
    def is_empty(self):
        if self.top == self.bottom:
            return True
        else:
            return False

n = input()
node_list = [None] * (n + 1)

for i in xrange(1, n + 1):
    node_list[i] = node(i)

for i in xrange(1, n + 1):
    line = raw_input().split()
    for node_num in line[2 : ]:
        node_list[i].link_node.append(node_list[int(node_num)])

node_que = queue()

node_list[1].distance = 0
node_que.enqueue(node_list[1])
while node_que.is_empty() == False:
    top_item = node_que.que[node_que.top]
    top_item.is_serched = True
    for item in top_item.link_node:
        if item.is_serched == False:
            node_que.enqueue(item)
            if item.distance == -1:
                item.distance = top_item.distance + 1
            elif item.distance > top_item.distance + 1:
                item.distance = top_item.distance + 1
    node_que.dequeue()

for item in node_list[1 : ]:
    print '%s %s' % (str(item.number), str(item.distance))
    

Measured memory_bytes: 7700
#include<bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
int main() {
    string S; cin >> S;
    int N = S.length();
    int res = 999999999;
    REP(i, N-2){
        res = min(res, abs(753 - stoi(S.substr(i,3))));
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
m = 10**9 + 7
n = int(input())
seq = [bin(int(x))[2:].zfill(61) for x in input().split()]
cnt = [[0,0] for i in range(61)]
for s in seq:
    for i in range(len(s)):
        if s[i] == '0':
            cnt[i][0] += 1
        else:
            cnt[i][1] += 1
ans = 0
for i in range(61):
  ans += cnt[-i-1][0]*cnt[-i-1][1]*(2**i)
  ans = ans % m
print(ans)

Measured memory_bytes: 155228
#include "bits/stdc++.h"

#pragma warning(disable:4996)
using namespace std;
using ld=long double;

struct Node {
	char var;
	vector<shared_ptr<Node>>chs;
	Node(char ch):var(ch) {

	}
	Node() :var('@') {

	}
};

shared_ptr<Node> term(const vector<int>&ways,map<char,int>mp,string st, int&a,int k) {
	shared_ptr<Node>no;
	if (st[a] == '(') {
		a++;
		auto ans=term(ways,mp,st,a,0);
		assert(st[a]==')');
		a++;
		no=ans;
	}
	else {
		assert(isalpha(st[a]));
		char var = st[a];
		a++;
		no = make_shared<Node>(var);
	}
		
	while (a != st.size() && st[a] != ')') {
		char op = st[a];
			
		if (mp[op] >= k) {
			a++;
			shared_ptr<Node>ans;
			if (ways[mp[op]] == 1) {
				ans = term(ways, mp, st, a, mp[op] + 1);
			}
			else {
				ans = term(ways, mp, st, a, mp[op]);
			}
			shared_ptr<Node>pa(make_shared<Node>(op));
			pa->chs = vector<shared_ptr<Node>>{ no,ans };
			no = pa;
		}
		else {
			break;
		}
	}
	return no;
		
	
}

string get_st(shared_ptr<Node>n) {
	if (isalpha(n->var)) {
		return string(1,n->var);
	}
	else {
		return "("+get_st(n->chs[0])+n->var+get_st(n->chs[1])+")";
	}
}

void solve(string st,map<char,int>ch_mp,const vector<int>&ways) {
	int k=0;
	int a=0;
	shared_ptr<Node>root(term(ways,ch_mp,st,a,0));
	string answer=get_st(root);
	cout<<answer<<endl;
}

int main() {


	int T;cin>>T;
	for (int t = 0; t < T; ++t) {
		int N; cin >> N;
		map<char, int>ch_mp;
		vector<int>ways(N);
		for (int i = 0; i < N; ++i) {
			char way; cin >> way;
			ways[i] = way == 'L';
			int K; cin >> K;
			for (int j = 0; j < K; ++j) {
				char ch; cin >> ch;
				ch_mp[ch] = i;

			}
		}
		int M; cin >> M;
		for (int i = 0; i < M; ++i) {
			string st; cin >> st;
			solve(st,ch_mp,ways);
		}
		if(t!=T-1)cout<<endl;
	}
	return 0;
}


Measured memory_bytes: 3152
while 1:
	H,W = map(int,raw_input().split())
	if H == 0: break
	M = [raw_input() for i in range(H)]
	A = [[0]*W for i in range(H)]
	B = [[0]*W for i in range(H)]
	ans = 0
	for h in range(H):
		L = 0
		for w in range(W):
			if M[h][w] == ".":
				L += 1
			else:
				L = 0
			A[h][w] = L
			B[h][w] = (B[h-1][w] if h > 0 else 0) + 1 if L > 0 else 0
			if L*B[h][w] > ans:
				a = min([A[h-i][w] for i in range(ans/L+1)])
				for hi in range(B[h][w]):
					a = min(a,A[h-hi][w])
					if a*B[h][w] <= ans:
						break
					ans = max(ans,a*(hi+1))
	print ans

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

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

	int N;
	int i,k;
	int ans=0;
	int ctr=0;
	string S;

	cin >> S;
	if(S=="SSS") cout << 0 << endl;
	if(S=="SSR") cout << 1 << endl;
	if(S=="SRS") cout << 1 << endl;
	if(S=="SRR") cout << 2 << endl;
	if(S=="RSS") cout << 1 << endl;
	if(S=="RSR") cout << 1 << endl;
	if(S=="RRS") cout << 2 << endl;
	if(S=="RRR") cout << 3 << endl;

	return 0;
}



Measured memory_bytes: 3656
import sys
def input(): return sys.stdin.readline().rstrip()


from collections import deque  #listよりdequeの方が両端へのアクセスは計算量が少ない
def main():
    a = input()
    if a.isupper() == True:
        print('A')
    else:
        print('a')


if __name__=='__main__':
    main()

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

#define int long long
#define ll long long
#define f1(i,a,b) for(i=a;i<b;i++)
#define f2(i,a,b) for(i=a;i>=b;i--)
#define endl '\n'
#define pb push_back
#define gp " "
#define ff first
#define ss second
#define mp make_pair

const int mod=1000000007;
int i,j;
ll temp;

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // #ifndef ONLINE_JUDGE
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/in.txt","r",stdin);
    // 	freopen("/home/akmittal/Desktop/Competitive Programming/out.txt","w",stdout);
    // #endif
    int h,w;
    cin>>h>>w;
    vector<string> a(h);
    f1(i,0,h)
    {
    	cin>>a[i];
    }
    int an[h][w];
    f1(i,0,h)
    {
    	f1(j,0,w)
    	{
    		if(a[i][j]=='#')
    			an[i][j]=0;
    		else
    			an[i][j]=1;
    	}
    }
    int ans[h][w];
    f1(i,0,h)
    {
    	f1(j,0,w)
    	{
    		if(an[i][j]==0)
    			ans[i][j]=0;
    		else
    			ans[i][j]=1;
    	}
    }

    f1(i,0,h)
    {
    	f1(j,1,w)
    	{
    		if(an[i][j]!=0&&an[i][j-1]!=0)
    		{
    			an[i][j]=an[i][j]+an[i][j-1];
    		}
    	}
    	f2(j,w-2,0)
    	{
    		if(ans[i][j]!=0&&ans[i][j+1]!=0)
    		{
    			ans[i][j]=ans[i][j]+ans[i][j+1];
    		}
    	}
    }
    // f1(i,0,h)
    // {
    // 	f1(j,0,w)
    // 	{
    // 		if(an[i][j]!=0)
    // 			cout<<an[i][j]+ans[i][j]-1;
    // 		else
    // 			cout<<an[i][j]+ans[i][j];
    // 	}
    // 	cout<<endl;
    // }
    int h1[h][w];
    int h2[h][w];
    f1(i,0,h)
    {
    	f1(j,0,w)
    	{
    		if(an[i][j]==0)
    			h1[i][j]=h2[i][j]=0;
    		else
    			h1[i][j]=h2[i][j]=1;
    	}
    }
    f1(i,0,w)
    {
    	f1(j,1,h)
    	{
    		if(h1[j][i]!=0&&h1[j-1][i]!=0)
    		{
    			h1[j][i]=h1[j][i]+h1[j-1][i];
    		}
    	}
    	f2(j,h-2,0)
    	{
    		if(h2[j][i]!=0&&h2[j+1][i]!=0)
    		{
    			h2[j][i]=h2[j][i]+h2[j+1][i];
    		}
    	}
    }
    int s=0;
    f1(i,0,h)
    {
    	f1(j,0,w)
    	{
    		s=max(s,an[i][j]+ans[i][j]+h1[i][j]+h2[i][j]-3);
    	}
    }
    cout<<s;
    return 0;
}

Measured memory_bytes: 129536
import sys
input=sys.stdin.buffer.readline
sys.setrecursionlimit(10**7)
n=int(input())
edges=[[] for i in range(n)]
dis=[-1]*n
for _ in range(n-1):
  a,s,d=map(int,input().split())
  a-=1;s-=1
  edges[a].append((s,d))
  edges[s].append((a,d))
q,k=map(int,input().split())
dis[k-1]=0
def dfs(now):
  for i,d in edges[now]:
    if dis[i]==-1:
      dis[i]=dis[now]+d
      dfs(i)
dfs(k-1)
for _ in range(q):
  a,s=map(int,input().split())
  print(dis[a-1]+dis[s-1])

Measured memory_bytes: 131736
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#define PI 3.14159265359
typedef long long ll;
const int MOD = 1e9+7;
const ll LLINF = 7e18;
using namespace std;


int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	for (int i = 0; i < n; i++) cin >> a[i];
	sort(a.begin(), a.end(), greater<int>());
	int ans1 = 0, ans2 = 0;
	for (int i = 0; i < n; i++){
		if (i % 2 == 0) ans1 += a[i];
		else ans2 += a[i];
	}
	cout << ans1 - ans2 << endl;
	return 0;
}

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

const ll MAX = 2000005;
ll mod = 1000000007;
ll fac[MAX];
ll finv[MAX];
ll inv[MAX];

// 階乗、逆階乗のテーブル作成
void conInit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (ll i = 2; i < MAX; i++){
    fac[i] = fac[i - 1] * i % mod;
    inv[i] = mod - inv[mod%i] * (mod / i) % mod;
    finv[i] = finv[i - 1] * inv[i] % mod;
  }
}
// nCk mod
ll con(ll n, ll k){
  if (n < k) return 0;
  if (n < 0 || k < 0) return 0;
  return fac[n] * (finv[k] * finv[n - k] % mod) % mod;
}

// a^n mod を計算する
ll modPow(ll a, ll n){
  ll res = 1;
  while (n > 0) {
    if (n & 1) res = res * a % mod;
    a = a * a % mod;
    n >>= 1;
  }
  return res;
}

int main(){
  conInit();

  ll K;
  string S;
  ll sum = 0;

  cin >> K;
  cin >> S;
  ll sNum = S.size();



  for(int i=0;i <= K;i++){
    ll sumsub = (modPow(25,i) % mod *  modPow(26, K - i) % mod ) % mod;

    ll r = sNum - 1;
    ll n = i + r;
    sumsub *=  con(n, r) % mod;
    sum += sumsub % mod;
  }
  cout << sum % mod << endl;
}

Measured memory_bytes: 52132
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int a,b;
	cin>>a>>b;
	int s=max(a,b);
	int z=min(a,b);
	if(a>0&&b>0) cout<<"Positive"<<endl;
	else if(a<0&&b>0) cout<<"Zero"<<endl;
	else if(a==0||b==0) cout<<"Zero"<<endl;
	else if((s-z)%2==0) cout<<"Negative"<<endl;
	else if((s-z)%2==1) cout<<"Positive"<<endl;
	return 0;
}


Measured memory_bytes: 256
str1 = gets.split
N,K = str1[0].to_i, str1[1].to_i

S = gets.chomp
p = []
p[0] = 0
x = 1

if S[0] == "0"
  p[1] = 0
  x = 2
end

for i in 1...N
  if S[i] != S[i-1]
    p[x] = i
    x += 1
  end
end

p[p.size] = N

if p.size % 2 == 1
  p[p.size] = N
end

if p.size/2 - 1 <= K
  puts N
  exit
end

answer = 0
i = 1 + 2*K
j = 0

while i < p.size do
  if answer < p[i] - p[j]
    answer = p[i] - p[j]
  end
  i += 2
  j += 2
end

puts answer

Measured memory_bytes: 4988
#include<bits/stdc++.h>
using namespace std;
 
int main()
{
    long long x,y,z,a,b;
    cin>>x;
    y=x/500;
    z=x%500;
    a=z/5;
 
    cout<<y*1000+a*5<<endl;
 
 
    return 0;
}

Measured memory_bytes: 256
package main

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

var sc *bufio.Scanner
var out *bufio.Writer

func main() {
	sc = bufio.NewScanner(os.Stdin)
	out = bufio.NewWriter(os.Stdout)
	buf := make([]byte, 1024*1024*1024)
	sc.Buffer(buf, bufio.MaxScanTokenSize)
	sc.Split(bufio.ScanWords)
	defer out.Flush()

	n := nextInt()
	c := next()

	result := 0
	jstart := n - 1
	for i := 0; i < n-1; i++ {
		if c[i] == 'R' {
			continue
		}
		for j := jstart; j >= i+1; j-- {
			jstart--
			if c[j] == 'W' {
				continue
			}
			result++
			break
		}
	}

	fmt.Fprintln(out, result)
}

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


Measured memory_bytes: 36132
#include <bits/stdc++.h>
#define int long long
#define For(i,a,b) for(register int i=a;i<=b;i++)
using namespace std;
int read() {
	register int x=0,f=0;
	register char ch=getchar();
	while(!isdigit(ch)) {
		f|=(ch=='-');
		ch=getchar();
	}
	while(isdigit(ch)) {
		x=x*10+ch-'0';
		ch=getchar();	
	}
	return f?-x:x;
}
void write(int x) {
	if(x<0) {
		putchar('-');
		x*=-1;
	}
	if(x>=10) write(x/10);
	putchar(x%10+'0');
}
int n,a[120000],he,ans[120000];
signed main() {
	n=read();
	For(i,1,n) {
		a[i]=read();
		he+=a[i];
	}
	ans[1]=he;
	for(int i=2;i<=n;i+=2) ans[1]-=a[i]*2;
	for(int i=2;i<=n;i++)
		ans[i]=a[i-1]*2-ans[i-1];
	for(int i=1;i<=n;i++) cout<<ans[i]<<" ";
	return 0;
}

Measured memory_bytes: 2944
import sys
import os

ii = lambda: int(sys.stdin.buffer.readline().rstrip())
il = lambda: list(map(int, sys.stdin.buffer.readline().split()))
fl = lambda: list(map(float, sys.stdin.buffer.readline().split()))
iln = lambda n: [int(sys.stdin.buffer.readline().rstrip()) for _ in range(n)]

iss = lambda: sys.stdin.buffer.readline().decode().rstrip()
sl = lambda: list(map(str, sys.stdin.buffer.readline().decode().split()))
isn = lambda n: [sys.stdin.buffer.readline().decode().rstrip() for _ in range(n)]


def main():
    if os.getenv("LOCAL"):
        sys.stdin = open("input.txt", "r")

    A = iss()
    l, r = A[:len(A) // 2], A[len(A) // 2:]
    r = r[::-1]
    ans = 0
    for n in range(len(l)):
        if l[n] != r[n]:
            ans += 1

    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3064
from collections import Counter


def main():
    n = int(input())
    *v, = map(int, input().split())

    v0 = Counter(v[::2]).most_common()
    v1 = Counter(v[1::2]).most_common()

    if len(v0) == 1 and len(v1) == 1:
        if v0[0][0] == v1[0][0]:
            print(n // 2)
        else:
            print(0)
        return

    l0 = min(2, len(v0))
    l1 = min(2, len(v1))
    INF = 10 ** 9
    score = [[n - v0[i][1] - v1[j][1] if v0[i][0] != v1[j][0]
              else INF for j in range(l1)] for i in range(l0)]
    print(min([min(s) for s in score]))


main()


Measured memory_bytes: 20692