akhauriyash/Code-Regression huggingface dataset:
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n = sc.nextInt
    val k = sc.nextInt
    val s = sc.nextLong
    for (i <- 0 until k) {
      print(s + " ")
    }
    val nn = if (s == 1000000000L) s - 1 else s + 1
    for (i <- 0 until n - k) {
      print(nn + " ")
    }
  }

}


Measured memory_bytes: 43792
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
const ll INF = 1LL << 60;
const ll MOD = 1e9+7;

int main(){
  double a,b,c;
  cin >> a >> b;
  cout << 2*b-a << endl;


  return 0;
}


Measured memory_bytes: 256
"use strict"
function Main(input) {
  input = input.trim().split('\n');
  const N = Number(input[0].trim())
  const T = input.slice(-N);

  let ret = 'Yes';
  for(let i=0; i<N; i++){
    let arr = T[i].trim().split(' ').map(Number);
    let t = arr[0];
    let x = arr[1];
    let y = arr[2];
    
    if(t%2 !== 0 && (x+y)%2 === 0){
      ret = 'No';
    }

    if(t%2 === 0 && (x+y)%2 !== 0){
      ret = 'No';
    }

    if((x+y) > t){
      ret = 'No';
    }
  }

  console.log(ret);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 30028
use std::collections::*;
use std::io;
use std::io::prelude::*;

fn main() {
    let t_cases = 1usize;
    (0..t_cases).for_each(|_| solve()); // run every test case
}

// solve every test case
fn solve(){
    let mut buf  = String::new();
    io::stdin().read_line(&mut buf).unwrap();
    let n = buf.trim().to_owned().parse::<f64>().unwrap();
    println!("{}",2f64*3.14159265*n);
}

Measured memory_bytes: 2180
N = int(input())
X = list(map(int,input().split()))
s = sum(X)
l = len(X)
ave = s/l
if ave - float(int(ave)) <= 0.5:
  avei = int(s/l)
else:
  avei = int(s/l) + 1
ans = 0
for i in range(N):
  ans += (X[i] - avei)**2
print(ans)

Measured memory_bytes: 3064
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
 
using namespace std;
 
int comp(const void* a, const void *b) {
	return *(int*)a - *(int*)b;
}
 
int main(){
    int X, N, p[102], num;
    bool flag = 1;
 
    cin >> X >> N;
    for(int i = 0; i < N; i ++){
        cin >> p[i];
    }
    qsort(p, N, sizeof(int), comp);
    for(int j = 0; j < N; j ++){
        if(X == p[j]){
            flag = 0;
            num = j;
        }
    }
    if(flag){
        cout << X << endl;
        return 0;
    }
    for(int k = 1; k <= (N + 1) / 2; k ++){
        if(p[max(num - k, 0)] != (p[num] - k)){
            cout << p[num] - k << endl;
            break;
        }
        if(p[min(num + k, N - 1)] != (p[num] + k)){
            cout << p[num] + k << endl;
            break;
        }
    }
    return 0;
}

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

const int MAXN = 1e5;
vector<int> a(MAXN, -1);
vector<vector<pair<int, int>>> g(MAXN);
vector<bool> used(MAXN, false);
bool fl = false;

void dfs(int u) {
    used[u] = true;
    for (auto it : g[u]) {
        int v = it.first, d = it.second;
        //cout << u << " " << v << " " << d << "\n";
        if (!used[v]) {
            a[v] = a[u] + d;
            dfs(v);
        } else {
            if (a[v] != -1 && a[u] != -1 && a[v] - a[u] != d) {
                fl = true;
            }
        }
    }
}

void solve() {
    int n, m;
    cin >> n >> m;
    for (int i = 0; i < m; ++i) {
        int l, r, d;
        cin >> l >> r >> d;
        g[l - 1].push_back({r - 1, d});
        g[r - 1].push_back({l - 1, -d});
    }
    for (int i = 0; i < n; ++i) {
        if (!used[i]) {
            a[i] = 0;
            dfs(i);
        }
    }
    if (fl) {
        cout << "No\n";
    } else {
        cout << "Yes\n";
    }
}

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



Measured memory_bytes: 12032
#include <iostream>
#include <cstdio>
#include <vector>
#include <set>
#include <unordered_set>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>

using namespace std;
using lli = long long int;
// #define DEBUG
#ifdef DEBUG
#define debug(var) cout << (#var) << ": " << (var) << endl;
template<class T> void dump_array_impl(const T& a) {
  bool first = true;
  for (auto&& x : a) {
    if (!first) { cout << ", "; first = false; }
    cout << x;
  }
}
#define debug_array(a) cout<<(#a)<<": ";dump_array_impl(a);cout<<endl
#else
#define debug(var) {}
#define debug_array(a) {}
#endif
template<class T> void read_n(vector<T>& v, size_t n) {
  v = vector<T>(n);
  for (lli i=0; i<n; ++i) cin >> v[i];
}
/*
template<class T> const T& gabs(const T& x) { return max(x, -x); }
#define abs gabs
*/
lli n;
vector<lli> v;
int main() {
  cin >> n;
  read_n(v, n);
  lli p=v[0], q=v[1], r=v[2], s=accumulate(begin(v)+3, end(v), 0ll);
  lli x=1, y=2, z=3;
  lli ans=1e17;
  while (y <= v.size()-2) {
    while (x+1<y && abs(q-p) > abs(q-v[x] - (p+v[x]))) {
      p+=v[x]; q-=v[x]; ++x; 
    }
    while (z+1<n && abs(s-r) > abs(s-v[z] - (r+v[z]))) {
      r+=v[z]; s-=v[z]; ++z; 
    }

    // printf("x:%lld, y:%lld, z:%lld %lld %lld %lld %lld\n", x, y, z,p,q,r,s);

    lli cur = max(max(p,q), max(r,s)) - min(min(p,q), min(r,s));
    ans = min(ans, cur);

    q+=v[y]; r-=v[y]; ++y;
    if (y == z) {
      r+=v[z]; s-=v[z]; ++z; 
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1792
A,B = [int(i) for i in input().split()]
c = 0
if 1 <= A <= 99999:
    if 1 <= B <= 99999:
        for p in range(A, B + 1):
            if p // 10000 == p % 10 and p // 1000 - 10 * ( p // 10000 ) == p % 100 // 10:
                c += 1
            elif p // 100 == p % 10:
                c += 1            
print(c)           

Measured memory_bytes: 3060
import sys
S=input()
N=len(S)
L=['B','D','E','F','G','H','I','J','K','L','N','M','O','P','Q','R','S','T','U','V','W','X','Y','Z']
if S[0]!='A':
    print('WA')
    sys.exit()
ans=0
for i in range(2,N-1) :
    if S[i]=='C':
        ans+=1
if ans!=1:
    print('WA')
    sys.exit()
for i in range(N) :
    if S[i] in L:
        print('WA')
        sys.exit()
print('AC')

Measured memory_bytes: 38384
#include <stdio.h>
#include <string.h>
int main(void){
    int n=999999,a,b,c;
    int x[1000000];
    memset(x,0,sizeof(x));
    for(a=2,c=0;a<=n;a++){
        if(x[a]){x[a]=c;continue;}
        x[a]=++c;
        for(b=a*2;b<=n;b+=a)x[b]=-1;
    }
    while(~scanf("%d",&n)){
        printf("%d\n",x[n]);
    }
    return 0;
}

Measured memory_bytes: 4936
process.stdin.resume();
process.stdin.setEncoding("utf8");

const reader = require("readline").createInterface({
  input: process.stdin,
  output: process.stdout,
});

const lines = [];

reader.on("line", (line) => {
  lines.push(line);
});

reader.on("close", () => {
  let disp = "";
  const s = lines[0];
  for (let i = 0; i < s.length; i++) {
    const c = s[i];
    if ("A" <= c && c <= "Z") disp += c.toLowerCase();
    else disp += c.toUpperCase();
  }
  console.log(disp);
});



Measured memory_bytes: 16316
def binary_search(*, ok, ng, func):
    while abs(ok - ng) > 1:
        mid = (ok + ng) // 2
        if func(mid):
            ok = mid
        else:
            ng = mid
    return ok


def main():
    N, K = map(int, input().split())
    *A, = sorted(map(int, input().split()))
    *F, = sorted(map(int, input().split()), reverse=True)

    def is_ok(score):
        rest = K
        for a, f in zip(A, F):
            exceed = max(0, a * f - score)
            if exceed:
                need = (exceed + f - 1) // f
                if need > a or need > rest:
                    return False
                rest -= need
        return True

    ans = binary_search(ok=10 ** 12, ng=-1, func=is_ok)
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 122900
area a b = a*b
leng a b = 2*(a+b)

main = do
    line <- getLine ::IO String
    let xs = map read $ words line
    let a = xs !! 0
    let b = xs !! 1
     
   
   
   
    putStr $ show $ area a b
    putStr " "
    putStrLn $ show $ leng a b


Measured memory_bytes: 3616
#include <iostream>
#include <math.h>

using namespace std;

int main()
{
    int a,b,c,d,f,q,w;
    cin >> a >> b >> c;
    d=a-c;
    w=fabs(d);
    f=a-b;
    q=fabs(f);
    if(q<w){
        cout << "A";}
    else


    cout << "B";
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>

int main(){
    int s;
    int a[1100000];
    int i,j,end=0;

    scanf("%d", &s);
    a[0] = s;

    for(i=1; i<1000000; i++){
        if(a[i-1]%2 == 0){
            a[i] = a[i-1]/2;
        }else{
            a[i] = 3*a[i-1]+1;
        }
        for(j=0; j<i; j++){
            if(a[j]==a[i]){
                end = 1;
            }
        }
        if(end == 1){
            break;
        }
    }

    printf("%d", i+1);

    return 0;

}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
#define ll long long
#define ld long double
#define zeros(x) x^(x-1)&x
#define pii pair<ll,ll>
#define cd complex<double>
#define dbg(x) cerr<<#x<<": "<<x<<endl;ll
#define Nmax 400005
#define OFF 100001
using namespace std;

ll a,b,c,d,e,f,g,ans;

int main()
{
    cin >> a >> b >> c >> d >> e >> f >> g;
    ll ans1 = 0;
    if (d && a && e) ans1 = (d-1) / 2 * 2 + (e-1) / 2 * 2 + (a-1) / 2 * 2 + 3;
    ll ans2 = d / 2 * 2 + e / 2 * 2 + a / 2 * 2;
    cout << b + max(ans1,ans2) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define INF 0x7fffffff
using namespace std;
vector<int> a; 
int main()
{
	int a,b,c,x,y;
	long long sum=0;
	long long allc;
	scanf("%d %d %d %d %d",&a,&b,&c,&x,&y);
	if(c*2<=a+b)
	{
		if(x>y)
		{
			sum+=c*2*y;
			sum+=a*(x-y);
		}
		else
		{
			sum+=c*2*x;
			sum+=b*(y-x);
		}
	} 
	else
	{
		sum+=a*x+b*y;
	}
	allc=max(x,y)*2*c;
	sum=min(sum,allc);
	printf("%lld\n",sum);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#include <string>

using namespace std;

#define rep(i,j) REP((i), 0, (j))
#define REP(i,j,k) for(int i=(j);(i)<(k);++i)
#define MP make_pair
#define PB push_back
#define F first
#define S second
int n, m;
vector<pair<int, pair<string, string> > >rule;

int judge(string src, string dst){
  for(int i = n-1; i >= 0; i--){
    int p;
    for(p = 0; p < 8; p++){
      if(rule[i].S.F[p] != '?' && src[p] != rule[i].S.F[p]) break;
      if(rule[i].S.S[p] != '?' && dst[p] != rule[i].S.S[p]) break;
    }
    if(p == 8) return rule[i].F;
  }
  return 0;
}

int main(){
  while(scanf("%d%d", &n, &m) && n+m){
    rule.clear();
    string r, src, dst, mes;
    rep(i, n){
      cin >> r >> src >> dst;
      rule.PB(MP((r[0]=='p')?1:0, MP(src, dst)));
    }

    vector<pair<string, pair<string, string> > >res;
    rep(i, m){
      cin >> src >> dst >> mes;
      if(judge(src, dst)) res.PB(MP(src, MP(dst, mes)));
    }

    printf("%d\n", (int)res.size());
    rep(i, res.size()) cout << res[i].F << " " << res[i].S.F << " " << res[i].S.S << endl;
  }
  return 0;
}

Measured memory_bytes: 1456
from itertools import accumulate

n, k = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)
goukei = sum(A)


# 約数列挙
def divide(n):  # unsort
    ans = []
    for i in range(1, int(n ** 0.5) + 1):
        if n % i == 0:
            ans.append(i)
            if n // i == i:
                continue
            ans.append(n // i)
    return ans


kouho = divide(goukei)
kouho.sort(reverse=True)
ans = 0
for num in kouho:
    delta = 0
    outflag = 0
    d = [0] * n
    for i in range(n):
        d[i] = A[i] % num
    d.sort()
    SD = list(accumulate([0] + d))
    for i in range(n + 1):
        sageru = SD[i]
        ageru = num * (n - i) - (SD[n] - SD[i])
        delta = ageru - sageru
        if delta % num == 0 and max(sageru, ageru) <= k:
            print(num)
            exit()
print(1)


Measured memory_bytes: 74328
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cstdio>
#include<cstring>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(n) rep(i,n)
#define all(n) n.begin(),n.end()
#define foreach(it,c) for(typeof(c.begin()) it=c.begin();it!=c.end();++it)

int main()
{
    vector<int> h; 
    int t;
    REP(10){ cin >> t; h.push_back(t);}
    sort(all(h));
    cout << h[9] << endl;
    cout << h[8] << endl;
    cout << h[7] << endl;

    return 0;
}

Measured memory_bytes: 1216
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

typedef long long Int;
typedef pair<Int,Int> P;

#define rep(i,n) for(int i=0;i<n;++i)
#define mp(a,b) make_pair(a,b)
#define srt(a, b) sort(a.begin(), a.end(), b)

bool cmp(const P& a, const P& b){
  return a.first < b.first;
}

int main(){
  Int N, M, ans = 0;
  cin >> N >> M;
  vector<P> A(N);
  rep(i,N) cin >> A[i].first >> A[i].second;
  srt(A,cmp);
  for (auto& x: A){
    Int l = x.first, r = x.second;
    if (r <= M) { ans += r*l; M -= r;}
    else if (r > M) { ans += M*l; break; }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1792
#include <iostream>
#include <math.h>
#include <queue>
#include <algorithm>
#include <map>
#include <cstdlib>

using namespace std;

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

ll dp[(1 << 12) + 10];
ll ma = INT32_MAX;

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

    int a[1100], b[1100];
    int c[1100];
    for(int i = 0; i < M; i++){
        cin >> a[i] >> b[i];
        int state = 0;
        for(int j = 0; j < b[i]; j++){
            int k;
            cin >> k;
            k--;
            state += (1 << k);
        }
        c[i] = state;
    }

    fill(dp, dp+(1 << 12) + 10, ma);
    dp[0] = 0;

    for(int i = 0; i < M; i++){
        for(int j = 0; j < (1 << N); j++){
            int nextState = j | c[i];
            if(dp[j] != ma) {
                dp[nextState] = min(dp[nextState], dp[j] + a[i]);
            }
        }
    }

    if(dp[(1<<N)-1] == ma){
        cout << -1 << endl;
    }
    else{
        cout << dp[(1<<N)-1] << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <stdio.h>
using namespace std;

void matrix_input(int a, int b, int v[][100])
{
	for(int i=0; i<a; i++)
		for(int j=0; j<b; j++)
			cin >> v[i][j];
}

void matrix_output(int a, int b, int v[][100])
{
	for(int i=0; i<a; i++){
		for(int j=0; j<b; j++){
			cout << v[i][j];
			if(j<b-1)
				cout << ' ';
		}
		if(i<a-1)
			cout << endl;
	}
}

void matrix_multi(int a, int b, int c, int s[][100], int v[][100], int x[][100])
{
	for(int i=0; i<a; i++)
		for(int j=0; j<c; j++)
			for(int k=0; k<b; k++)
				s[i][j] += v[i][k] * x[k][j];
}

int main()
{
	int n,m;
	int a[100][100], b[100][100], c[100][100] = {0};
	
	cin >> n >> m;
	matrix_input(n, m, a);
	matrix_input(m, 1, b);
	matrix_multi(n, m, 1, c, a, b);
	matrix_output(n, 1, c);
	cout << endl;
	
	return 0;
}



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

using namespace std;
const int mod = 1e9 + 7;
int main(){
	string k; int D; cin >> k >> D;
	int n = k.size();
	vector<vector<int>> dp(D, vector<int>(2));
	dp[0][0] = 1;
	for(int i = 0; i < n; ++i){
		vector<vector<int>> new_dp(D, vector<int>(2));
		int t = k[i] - '0';
		for(int j = 0; j < D; ++j){
			for(int d = 0; d <= 9; ++d){
				new_dp[(j+d)%D][1] += dp[j][1] + (d<t?dp[j][0]:0);
				new_dp[(j+d)%D][1] %= mod;
			}
			new_dp[(j+t)%D][0] += dp[j][0];
			new_dp[(j+t)%D][0] %= mod;
		}
		dp = new_dp;
	}
	int ans = (dp[0][0] + dp[0][1]) % mod; ans = (ans-1+mod)%mod;
	cout << ans;
}

Measured memory_bytes: 3620
#include <iostream>

using namespace std;

int main(){
    int num1, num2;
    cin >> num1 >> num2;
    string symbol;
    if(num1 < num2){
        symbol = " < ";
    }
    else if(num1 > num2){
        symbol = " > ";
    }
    else{
        symbol = " == ";
    }
    cout << "a" << symbol << "b" << endl;
}

Measured memory_bytes: 1196
//----------------------------------------------------------------------
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
//----------------------------------------------------------------------

using namespace std;
using ll = long long;
using P = pair<int,int>;
using Graph = vector<vector<int>>;

int main(void) {
    int n; cin >> n;
    vector<int> p;
    vector<int> a;
    ll ans = 0;

    for(int i = n-1; i >=2; --i) {
        ans += i;
    }

    ll add = max(1, n % 2);

    ans += add;
    if(n == 1) ans--;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    int a;
    int b;
    int c;
    scanf("%d %d %d",&a,&b,&c);
    if(a<=b && b<= c) printf("%d %d %d\n",a,b,c);
    else if (a<=c && c<=b) printf("%d %d %d\n",a,c,b);
    else if (b<=a && a<=c) printf("%d %d %d\n",b,a,c);
    else if (b<=c && c<=a) printf("%d %d %d\n",b,c,a);
    else if (c<=a && a<=b) printf("%d %d %d\n",c,a,b);
    else if (c<=b && b<=a) printf("%d %d %d\n",c,b,a);
    
    return 0;
}


Measured memory_bytes: 2068
#include <cstdio>
using namespace std;
int main(){
  int *p,i,n,j,a1,b1,buf;
  scanf("%d",&n);
  p=new int[n];
  scanf("%d",&i);
  for(j=0;j<n;j++)p[j]=j+1;
  for(j=0;j<i;j++){
    scanf("%d,%d",&a1,&b1);
    a1--;b1--;
    buf=p[a1];
    p[a1]=p[b1];
    p[b1]=buf;
  }
  for(i=0;i<n;i++)printf("%d\n",p[i]);
}

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

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

int saitan(int a, int b, int &X, int &Y);

int main(){
  int N, X, Y;
  cin >> N >> X >> Y;

  vector<int64_t> ans(N);

  for(int i=0; i<N-1; i++){
    for(int j=i; j<N; j++){
      int k = saitan(i, j, X, Y);
      int64_t now = ans.at(k);
      ans.at(k) = now + 1; 
    }
  }

  for(int i=1;i<N;i++){
    cout << ans.at(i) << endl;
  }

  
}

int saitan(int a, int b, int &X, int &Y){
  int nowarp = b - a;
  int warp = abs(X-1-a) + 1 + abs(Y-1-b); 
  return min(nowarp, warp);
}

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

a, b = [0], [0]
for i in range(N):
  a.append(a[i] + A[i])
for i in range(M):
  b.append(b[i] + B[i])

ans, j = 0, M
for i in range(N + 1):
  if a[i] > K:
    break
  while b[j] > K - a[i]:
    j -= 1
  ans = max(ans, i + j)
print(ans)


Measured memory_bytes: 47544
import java.util.Scanner;
import java.util.Stack;

public class Main {
	public static void main(String[] args){
		Scanner stdIn = new Scanner(System.in);
		Stack<Integer> st = new Stack<Integer>();
		while(stdIn.hasNextInt()){
			int n = stdIn.nextInt();
			if(n==0){
				System.out.println(st.pop());
			}
			else{
				st.push(new Integer(n));
			}
		}
	}
}

Measured memory_bytes: 12000
import java.util.*;
import java.util.Map.Entry;

import javax.swing.text.Segment;

import java.io.*;
import java.lang.reflect.Array;
import java.math.BigInteger;

import static java.lang.Math.*;
import static java.util.Arrays.*;
import static java.util.Collections.*;
 
public class Main //implements Runnable
{
//    static int dx[]={-1,0,1,0};
//    static int dy[]={0,-1,0,1};

    public static void main(String[] args)   throws Exception, IOException{        
        long mod=1000000007;
        Reader sc = new Reader(System.in);
        PrintWriter out=new PrintWriter(System.out);

        int n=sc.nextInt();
        int m=sc.nextInt();
        int a=sc.nextInt()-1;
        int b=sc.nextInt()-1;
        char c[][]=new char[n][m];
        for (int i = 0; i < c.length; i++) {
			fill(c[i],'0');
		}
        for (int i = 0; i < b+1; i++) {
			for (int j = 0; j < a+1; j++) {
				c[i][j]='1';
			}
		}
        for (int i = b+1; i < n; i++) {
			for (int j = a+1; j < m; j++) {
				c[i][j]='1';
			}
		}
        for (int i = 0; i < c.length; i++) {
        	for (int j = 0; j < m; j++) {
                out.print(c[i][j]);							
			}
            out.println();
		}
        
        out.println();
     	out.flush();
    }
    
    static void ret(String ans) {
    	System.out.println(ans);
    	System.exit(0);
    }
    
    static boolean validpos(int x,int y,int r, int c){
        return x<r && 0<=x && y<c && 0<=y;
    }

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

//class P {
//	int x, y;
//	P(int  x, int y) {
//	  this.x=x;
//	  this.y=y;
//	}
//}

class P implements Comparable<P>{
    int a,b;
    P(int a, int b) {
    	this.b=b;
    	this.a=a;
    }

    public int compareTo(P p){
        return p.a-a;//des
    }
}

class Reader
{ 
    private BufferedReader x;
    private StringTokenizer st;
    
    public Reader(InputStream in)
    {
        x = new BufferedReader(new InputStreamReader(in));
        st = null;
    }
    public String nextString() throws IOException
    {
        while( st==null || !st.hasMoreTokens() )
            st = new StringTokenizer(x.readLine());
        return st.nextToken();
    }
    public int nextInt() throws IOException
    {
        return Integer.parseInt(nextString());
    }
    public int[] nextIntArray(int size) throws IOException{
        int r[] = new int[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextInt(); 
        }
        return r;
    }
    public long[] nextLongArray(int size) throws IOException{
        long r[] = new long[size];
        for (int i = 0; i < size; i++) {
            r[i] = this.nextLong(); 
        }
        return r;
    }
    public char[] getCharSet() throws IOException{
        return this.nextString().toCharArray();
    }    
    public long nextLong() throws IOException
    {
        return Long.parseLong(nextString());
    }
    public double nextDouble() throws IOException
    {
        return Double.parseDouble(nextString());
    }
}


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

int test(int *a, int *b, int *c, int n){
	int **dp = new int*[3];
	for(int i = 0; i < 3; i++){
		dp[i] = new int[n];
	}
	dp[0][0] = a[0];
	dp[1][0] = b[0];
	dp[2][0] = c[0];
	for(int i = 1; i < n; i++){
		dp[0][i] = a[i] + max(dp[1][i-1], dp[2][i-1]);
		dp[1][i] = b[i] + max(dp[0][i-1], dp[2][i-1]);
		dp[2][i] = c[i] + max(dp[0][i-1], dp[1][i-1]);
	}
	return max(dp[0][n-1], max(dp[1][n-1], dp[2][n-1]));
}

int main(){
	#ifndef ONLINE_JUDGE
	freopen("/home/afzalrao/Desktop/Academics/2nd Year/3rd Sem/ESO207/CP/Text Files/input.txt", "r", stdin);
	freopen("/home/afzalrao/Desktop/Academics/2nd Year/3rd Sem/ESO207/CP/Text Files/output.txt", "w", stdout);
	#endif
	int n, *a, *b, *c;
	cin >> n;
	a = new int[n];
	b = new int[n];
	c = new int[n];
	for(int i = 0;i < n; i++){
		cin >> a[i] >> b[i] >> c[i];
	}
	cout << test(a, b, c, n);
	return 0;
}

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

int main()
{
    int A, B, C;

    cin >> A >> B >> C;

    int listen = 0;

    while (1)
    {
        if (listen == C)
        {
            break;
        }

        if (B >= A)
        {
            listen++;
            B = B - A;
        }
        else
        {
            break;
        }
    }

    cout << listen << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,a,n) for (int i=a;i<=n;i++)
#define per(i,a,n) for (register int i=n;i>=a;i--)
#define FOR(i,a,n,x) for (register int i=a;i<=n;i+=x)
#define ROF(i,a,n,x) for (register int i=n;i>=a;i-=x)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
#define pii pair<int, int>
#define pil pair<int, long long>
#define pll pair<long long, long long>
#define VI vector<int>
#define ll long long
#define ull unsigned long long
#define lowbit(x) ((x)&(-x))
#define mem(i, a) memset(i, a, sizeof(i))
#define sqr(x) ((x)*(x))
#define ls (p << 1)
#define rs (p << 1 | 1)
using namespace std;

template <typename T>

inline void read(T &X) {
  X = 0; char ch = 0; T op = 1;
  for(; ch > '9' || ch < '0'; ch = getchar())
    if(ch == '-') op = -1;
  for(; ch >= '0' && ch <= '9'; ch = getchar())
    X = (X << 3) + (X << 1) + ch - 48;
  X *= op;
}

const int INF = 0x3f3f3f3f;
const int MAXN = 1e5 + 5;

char s[MAXN];
int n;
vector<int> st[5];

ll slove(int p, int l, int r) {
  if (st[p].size() == 0) return 0;
  // cout << l << " " << r << endl;
  int inx = upper_bound(st[p].begin(), st[p].end(), r) - st[p].begin();
  // cout << st[p].size() << " " << inx << endl;
  auto it = lower_bound(st[p].begin(), st[p].end(), r + (r-l));
  bool fd = (*it == r+(r-l));
  return st[p].size() - inx - fd;
}

int main() {
#ifdef WiLe
  freopen ("input.txt", "rt", stdin);
#endif

  read(n);
  scanf("%s", s+1);
  
  rep (i, 1, n) {
    // cout << s[i] << endl;
    if (s[i] == 'R') st[1].pb(i);
    if (s[i] == 'G') st[2].pb(i);
    if (s[i] == 'B') st[3].pb(i);
  }
  // cout << st[1].size()<<endl;

  ll ans = 0;
  rep (i, 1, n) rep (j, i+1, n) {
    // cout << s[i] << " " << s[j] << endl;
    if (s[i] != 'R' && s[j] != 'R' && s[i] != s[j]) {
      ans += slove(1, i, j);
    }else if (s[i] != 'G' && s[j] != 'G' && s[i] != s[j]) {
      ans += slove(2, i, j);
    }else if (s[i] != 'B' && s[j] != 'B' && s[i] != s[j]) {
      ans += slove(3, i, j);
    }
    // cout << i << " " << j << " " << ans <<endl;
  }

  cout << ans << endl;

#ifdef WiLe
  cerr << "\nTime elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
  return 0;
}
/*
# author : WiLe
# date : 2020/04/16
*/

Measured memory_bytes: 3720
#include <bits/stdc++.h>
using namespace std;
int main(){
    int N;
    cin >> N;
    vector<string> s(N);
    for(int i=0;i<N;i++){ cin >> s.at(i); }
    int M;
    cin >> M;
    vector<string> t(M);
    for(int i=0;i<M;i++){ cin >> t.at(i); }
    
    int count;
    int max = 0;

    for(int i=0;i<N;i++){
        count = 0;
        for(int j=0;j<N;j++){
            if(s.at(i) == s.at(j)){ count++; }
        }
        for(int j=0;j<M;j++){
            if(s.at(i) == t.at(j)){ count--; }
        }
        if(count > max){ max = count; }
    }
    cout << max << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int a;
	char s;
	int b;
	scanf(" %d",&a);
	scanf(" %c",&s);
	scanf(" %d",&b);
	if(s=='+')
	printf("%d\n",a+b);
	else
	printf("%d\n",a-b);
}

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

int sumEachNum(int num) {
  int sum = 0;
  while(true) {
    if(num > 0) {
      int dig = num % 10;
      sum += dig;
      num = num / 10;
    } else return sum;
  }
}

int main() {
  int n, a, b; cin >> n >> a >> b;
  int ans = 0;
  for(int i = 1; i <= n; ++i) {
    int sum = sumEachNum(i);
    if(a <= sum && sum <= b) ans += i;
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
	string S;
	for(int i=0;i<4;i++){
		cin>>S[i];
	}
	sort(S.begin(),S.begin()+4);
	int cont=1;
	for(int i=0;i<3;i++){
		if(S[i]!=S[i+1]){
			cont++;
		}
	}
	if(cont==2){
		if(S[1]!=S[2]){
			cout<<"Yes";
			return 0;
		}
	}
	cout<<"No";
	return 0;
}

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

using namespace std;
using ll = long long int;

void Next(string &s)
{
	int i = s.length() - 1;
	int nextValue = s[i] - '0' + 1;
	if (nextValue == 10 || (i - 1 >= 0 && abs(s[i - 1] - '0' - nextValue) > 1))
	{
		i--;
		while (i >= 0)
		{
			s[i]++;
			if (s[i] >= '0' + 10 || (i > 0 && abs(s[i] - s[i - 1]) > 1))
			{
				i--;
			}
			else
			{
				i++;
				while (i < s.length())
				{
					s[i] = max((char) (s[i - 1] - 1), '0');
					i++;
				}
				return;
			}
		}

		if (i < 0)
		{
			s = "1" + string(s.length(), '0');
			return;
		}
	}
	else
	{
		s[i]++;
		return;
	}
}

int main()
{
	int n;
	cin >> n;
	string s = "1";

	for (int i = 0; i < n - 1; i++)
	{
		//cout << s << endl;
		Next(s);
	}

	cout << s << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main()
{
    ll n,i,j,arr[100000],count;
    cin>>n;
    for(i=0; i<n; i++)
    {
        cin>>arr[i];
    }
    ll l,r;
    sort(arr,arr+n);
    count=0;
    for(i=n-1;i>=1;i--)
    {
        l=0;
        r=i-1;
        while(l<r)
        {
            if(arr[l]+arr[r]>arr[i])
            {
                count+=r-l;
                r--;
            }
            else
            {
                l++;
            }
        }
    }
    cout<<count<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll	    long long
#define vi      vector <ll>
#define vii     vector <pair<int,int>>
#define ii      pair<int,int>
#define loop(n)	for(int i=0;i<n;i++)
#define pb      push_back
const ll mod=1e9+7;
void fast();
ll power(ll a,ll b){
    ll res=1;
    while(b){
        if(b&1)
            res*=a;
        a*=a;
        b>>=1;
    }
    return res;
}
int main()
{
    fast();
    ll n,k,res=0;
    cin>>n>>k;
    ll a[n],vis[41]={};
    loop(n){
        cin>>a[i];
        for(ll j=0;j<=40;j++){
            if((a[i]&power(2,j)))
                vis[j]++;
        }
    }
    for(ll j=40;j>=0;--j){
        if(vis[j]<(n+1)/2&&power(2,j)<=k){
            k-=power(2,j);
            res+=(n-vis[j])*power(2,j);
        }
        else
            res+=vis[j]*power(2,j);
    }
    cout<<res;
}
void fast(){
std::ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    cout.tie(NULL);
}
/*

*/


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

using namespace std;

int main(){

	int n;
   cin>>n;
   int arr[n][3];
   int i,j;
   int ans=0;
   for(i=0;i<n;i++){
    for(j=0;j<3;j++){
        cin>>arr[i][j];
        if(i!=0){
            int x;
            if(j==0) x=max(arr[i-1][1],arr[i-1][2]);
            if(j==1) x=max(arr[i-1][0],arr[i-1][2]);
            if(j==2) x=max(arr[i-1][1],arr[i-1][0]);
            arr[i][j]+=x;
        }
        if(i==n-1) ans=max(ans,arr[i][j]);
    }
   }
   cout<<ans<<endl;
	return 0;
}

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

typedef long long ll;
#define all(x) (x).begin(),(x).end()

template<typename T>
T mod(T a, T b){
    return (a + b) % b;
}

template<typename T>
T gcd(T a, T b){
    if (b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b){
    return a * b / gcd(a,b);
}

// n を素因数分解
map<ll, ll> factor(ll n){
    map<ll, ll> mp;
    for (ll i = 2; i*i <= n; i++) {
        while (n % i == 0) {
            mp[i]++;
            n /= i;
        }
    }

    if (n > 1) {
        mp[n]++;
    }

    return mp;
}

// 文字列に "hoge" が含まれているか
// string str = "hogepiyo";
// if (str.find("hoge") != string::npos) {
//     cout << "文字列が含まれています" << endl;
// }

// char to string
// char c = 'a';
// string str = {c};

void solve(){
    string str;
    cin >> str;

    if (str == "Sunny") {
        cout << "Cloudy" << endl;
    } else if (str == "Cloudy") {
        cout << "Rainy" << endl;
    } else {
        cout << "Sunny" << endl;
    }

    return;
}

int main(int argc, char const* argv[])
{
    solve();
    return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
typedef pair<int,int> P;
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define rep(i, n) for (lint i = 0; i < (n); i++)
#define INF LLONG_MAX
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    string s;
    cin>>s;
    /*
    while(1){
        auto itr=s.find("ST");
        if(itr==string::npos){
           break; 
        }else{
            s.erase(itr,2);
        }
    }
    cout<<s.size()<<endl;*/
    int m=0;
    int e=0;
    for(int i=0;i<s.size();i++){
        if(s[i]=='S'){
            m++;
        }else if(s[i]=='T' && m>0){
            m--;
            e++;
        }
    }
    cout<<s.size()-2*e<<endl;
    return 0;
}


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

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using pint = pair<int, int>;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
    int n;
    cin >> n;
    map<string, int> s;
    for (int i = 0; i < n; ++i) {
        string str;
        cin >> str;
        s[str]++;
    }
    cout << s.size() << endl;
    return 0;
}

Measured memory_bytes: 19100
n, m = map(int,input().split())
A = [list(map(int,input().split())) for i in range(m)]

B = [[] for i in range(n+1)]

for i in range(m) :
    B[A[i][0]].append(A[i][1])
    B[A[i][1]].append(A[i][0])

co = 0
ok = 0
while ok == 0 :
    ok = 1
    for i in range(1,n+1) :
        if len(B[i]) == 1 :
            ok = 0
            k = B[i][0]
            B[i].remove(k)
            B[k].remove(i)
            co += 1

print(co)


Measured memory_bytes: 3064
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;

const ll INF = 5e15;
const ll MOD = 1e9 + 7;

vector<ll> dp(1 << 20, -INF);
vector<ll> group(1 << 20, 0);
vector<vector<ll>> A;

int main(){
    ll N;
    cin >> N;
    for(ll i = 0; i < N; i++){
        vector<ll> tmp(N);
        for(ll &t : tmp) cin >> t;
        A.push_back(tmp);
    }
    for(ll i = 0; i < (1 << N); i++) for(ll j = 0; j < N; j++) for(ll k = j + 1; k < N; k++) if((i & (1 << j)) && (i & (1 << k))) group[i] += A[j][k];
    dp[0] = 0;
    for(ll i = 0; i < N; i++){
        ll upper = 1;
        for(ll j = 0; j < i; j++) upper *= 3;
        for(ll S = 0; S < upper; S++){
            bitset<16> sa(0), sb(0);
            ll cpy = S;
            for(ll k = 0; k < i; k++){
                bitset<16> b(1 << k);
                if(cpy % 3 == 1) sa |= b;
                else if(cpy % 3 == 2) sb |= b;
                cpy /= 3;
            }
            auto upd = (sa | sb | bitset<16>(1 << i));
            auto orig = upd ^ sb;
            dp[upd.to_ullong()] = max(dp[upd.to_ullong()], group[orig.to_ullong()] + dp[sb.to_ullong()]);
        }
    }
    cout << dp[(1 << N) - 1] << endl;
    return 0;
}


Measured memory_bytes: 16640
#include <iostream>
#include <iomanip>
#include <cstring>
#include <algorithm> 
#include <math.h>
#include <queue>
#include <functional>
#include <map>
#include <vector>
#include <string>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
int dx[] = { 1, 0, -1, 0 };
int dy[] = { 0, 1, 0, -1 };
 
const ll MOD = 1000000007;
const ll INF = 1000000000;
 
int main(void){
    int n;
    int dp[100010][3],play[100010][3]; // dp[i+1][j] i日目にj番目の活動をした時の最大値
    
    cin >> n;
    for(int i = 0; i < n; i++)
        for(int j = 0; j < 3; j++) cin >> play[i][j];
        
        

    dp[0][0] = dp[0][1] = dp[0][2] = 0;
    
    for(int i = 0; i < n; i++){
        for(int j = 0; j < 3; j++){
            for(int k = 1; k < 3; k++){
                dp[i+1][j] = max(dp[i+1][j],dp[i][(j+k)%3] + play[i][j]);
            }
        }
    }
            
    
    int ans = 0;
    
    for(int i = 0; i < 3; i++) ans = max(ans,dp[n][i]);
    
    cout << ans << endl;
}


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

int main() {
    string s1, s2, s3;
    cin >> s1 >> s2 >> s3;

    string ans;
    ans.push_back(s1[0] - 0x20);
    ans.push_back(s2[0] - 0x20);
    ans.push_back(s3[0] - 0x20);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner scanner = new Scanner(System.in);

		long a, b, m, n,tmp;

		while(scanner.hasNext()){
			a = m = scanner.nextInt();
			b = n = scanner.nextInt();
			if(m < n){
				tmp = m;
				m = n;
				n = tmp;
			}

			for(;;){
				if(n == 0) break;

				tmp = n;
				n = m % n;
				m = tmp;
			}

			System.out.println(m +" " + a * b / m);

		}
	}
}

Measured memory_bytes: 12000
package main

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

type pair struct {
	b int
	c int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}

func (p pairs) Less(i, j int) bool {
	return p[i].c > p[j].c
}

func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	a := make([]int, n)
	v := make(pairs, m)

	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)
	for i := range a {
		sc.Scan()
		a[i], _ = strconv.Atoi(sc.Text())
	}
	var p pair
	for i := range v {
		sc.Scan()
		p.b, _ = strconv.Atoi(sc.Text())
		sc.Scan()
		p.c, _ = strconv.Atoi(sc.Text())
		v[i] = p
	}
	sort.Ints(a)
	sort.Sort(v)

	ans := int64(0)
	j := 0
	for _, e := range a {
		if j < m && e < v[j].c {
			ans += int64(v[j].c)
			v[j].b--
			if v[j].b == 0 {
				j++
			}
		} else {
			ans += int64(e)
		}
	}
	fmt.Println(ans)
}


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

int main(void){
    int h,w;
    cin >> h >> w;
    char c[h][w];
    for(int i = 0;i < h;i++){
        for(int j = 0;j < w;j++)cin >> c[i][j];
    }
    bool check = true;
    for(int i = 0;i < h;i++){
        if(h == 1)continue;
        for(int j = 0;j < w;j++){
            if(w == 1)continue;
            if(c[i][j] == '.')continue;
            
            bool check2 = false;
            
            if(i != 0)if(c[i][j] == c[i-1][j])check2 = true;
            if(i != h-1)if(c[i][j] == c[i+1][j])check2 = true;
            if(j != 0)if(c[i][j] == c[i][j-1])check2 = true;
            if(j != w-1)if(c[i][j] == c[i][j+1])check2 = true;
            
            if(!check2){
                check = false;
            }
        }
    }
    
    if(check)cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout<<fixed<<setprecision(15);

    int n,ac=0,wa=0,tle=0,re=0;
    string s;
    cin>>n;
    for(int i=0; i<n; i++){
        cin>>s;
        if(s=="AC"){
            ac++;
        }else if(s=="WA"){
            wa++;
        }else if(s=="TLE"){
            tle++;
        }else if(s=="RE"){
            re++;
        }
    }
    cout<<"AC x "<<ac<<endl;
    cout<<"WA x "<<wa<<endl;
    cout<<"TLE x "<<tle<<endl;
    cout<<"RE x "<<re<<endl;
    return 0;
}

Measured memory_bytes: 3648
import std.stdio, std.conv, std.string, std.math, std.regex, std.range, std.ascii, std.algorithm;

void main(){
	auto ip = readln.chomp;

	switch(ip){
		case "A":
			writeln("T");
			break;
		case "T":
			writeln("A");
			break;
		case "C":
			writeln("G");
			break;
		case "G":
			writeln("C");
			break;
		default:
	}
}

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

bool f(const long kind, const size_t n, const vector<long>& a){
    map<long,long> c;
    long len = a[0];
    for(size_t i=1; i<n; i++){
        const long n_len = a[i];
        if(len>=n_len){
            c.erase(c.lower_bound(n_len), c.end());
            long j=n_len-1;
            auto oit = c.end();
            for(;;){
                auto it = c.find(j);
                if(it == c.end()){
                    it = c.insert(oit, make_pair(j, 1));
                }else{
                    it->second++;
                }
                if(it->second<kind){
                    for_each(oit, c.end(), [](pair<const long, long>& x){x.second=0;});
                    break;
                }else if(j<=0){
                    return false;
                }
                oit = it;
                j--;
            }
        }
        len = n_len;
    }
    return true;
}

bool strict_increasing(const vector<long>& a){
    size_t n = a.size();
    for(size_t i=1; i<n; i++){
        if(a[i-1]>=a[i]){
            return false;
        }
    }
    return true;
}

int main(void){
    long n;
    cin >> n;
    vector<long> a(n);
    for(long i=0; i<n; i++){
        cin >> a[i];
    }
    if(strict_increasing(a)){
        cout << 1 << endl;
        return 0;
    }
    long left=1, right=n;
    for(;;){
        const long mid = (left+right)/2;
        if(right-left<=1){
            if(f(right, n, a)){
                cout << right << endl;
            }else{
                cout << left << endl;
            }
            return 0;
        }
        const bool b = f(mid, n, a);
        //printf("[%ld, %ld] %ld %s\n", left, right, mid, b ? "true" : "false");
        if(b){
            right=mid;
        }else{
            left=mid;
        }
    }
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int N = 1e3 + 7, mod = 1e9 + 7;
#define debug(x) cerr << #x << " " << x << "\n";
int t[N][N];

int32_t main() {
	ios_base::sync_with_stdio(0);
	cin.tie();
	int n, m, a, b;
	cin >> n >> m >> a >> b;
	for(int i = 0; i < n; i++) {
		int flip = 0;
		if(i >= b) flip = 1;
		for(int j = 0; j < m; j++) {
			if(j < a) t[i][j] = 1 ^ flip;
			else t[i][j] = 0 ^ flip;
			cout << t[i][j] << "";
		}
		cout << "\n";
	}
}

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

int main(){
	string s;
	cin >> s;
	int count=0;
	for (int i = 0; i < (int) s.length(); i++){
		if ((i%2==0 && s[i] == '0') || (i%2 == 1 && s[i] == '1')) count ++;
	}
	cout << min((int)s.length() - count,count);
}


Measured memory_bytes: 512
function Main(input) {
  let s = parseInt(input, 10);
  let h = parseInt(s / 3600, 10);
  s -= 3600 * h;
  let m = parseInt(s / 60, 10);
  s -= 60 * m;
  console.log(String(h) + ":" + String(m) + ":" + String(s));
}

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


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

max_a = [0]
for i in range(n):
    max_a.append(max(max_a[-1], a[-i - 1]))
max_a.reverse()
profit = []
for i in range(n):
    profit.append(max_a[i] - a[i])
print(profit.count(max(profit)))

Measured memory_bytes: 15020
#include <iostream>
using namespace std;
#define out(v) cout<<v<<"\n"
#define rep(i,n) for(int i=0;i<(n);++i)

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  int N; cin >> N;
  string S; cin >> S;

  if (N % 2 != 0) {
    out("No");
    return 0;
  }
  rep(i, N/2) {
    if (S[i] != S[N/2 + i]) {
      out("No");
      return 0;
    }
  }
  out("Yes");

  return 0;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int,input().split()))
x = sum(a)
now = 0
key = 0
for i in range(n):
    now += a[i]
    if 2*now >= x:
        key = i
        break
if key == 0:
    ans = 2*now-x
elif key == n-1:
    ans = 2*a[n-1]-x
else:
    ans = min(2*now-x,x-2*(now-a[key]))

print(ans)

Measured memory_bytes: 26220
extern crate core;

use std::io::{self, Read};

fn main() {
    let mut input = String::new();
    io::stdin().read_to_string(&mut input).unwrap();
    let output = run(input);
    println!("{}", output);
}

fn run(input: String) -> String {
    let list: Vec<i64> = input
        .split_whitespace()
        .map(|x| x.parse::<i64>().unwrap())
        .collect();
    let x = list[0];
    let y = list[1];

    let mut vec: Vec<i64> = Vec::new();
    vec.push(x);
    loop {
        let &last = vec.last().unwrap();
        let last2 = last * 2;
        if last2 <= y {
            vec.push(last2);
        } else {
            break;
        }
    }

    vec.len().to_string()
}

Measured memory_bytes: 4352
use std::collections::VecDeque;

fn main() {
  let (n, m): (usize, usize) = read_tuple();
  let edges: Vec<(usize, usize)> = read_tuples(m);

  let mut graph: Vec<Vec<usize>> = vec![vec![]; n];
  for &(a, b) in &edges {
    graph[a-1].push(b-1);
    graph[b-1].push(a-1)
  }

  let mut visited: Vec<bool> = vec![false; n];
  let mut path: VecDeque<usize> = VecDeque::new();
  let &(s1, s2) = edges.first().unwrap();
  visited[s1-1] = true;
  visited[s2-1] = true;
  path.push_front(s1-1);
  path.push_back(s2-1);

  loop {
    let &front = path.front().unwrap();  
    let next_front = graph[front].iter().filter(|&&w|!visited[w]).next();
    let &back = path.back().unwrap();
    let next_back = graph[back].iter().filter(|&&w|!visited[w]).next();
  
    match (next_front, next_back) {
      (None, None) => {break},
      (Some(&w), _) => {visited[w] = true; path.push_front(w)},
      (_, Some(&w)) => {visited[w] = true; path.push_back(w)}
    }
  }
  
  println!("{}", path.len());
  print_vec(&path, " ");
}

fn read_tuple<T1: std::str::FromStr, T2: std::str::FromStr>() -> (T1, T2) {
  let mut buf = String::new();
  std::io::stdin().read_line(&mut buf).ok();
  let mut it = buf.trim().split_whitespace();
  let x = it.next().unwrap().parse::<T1>().ok().unwrap();
  let y = it.next().unwrap().parse::<T2>().ok().unwrap();
  (x, y)
}

fn read_tuples<T1: std::str::FromStr, T2: std::str::FromStr>(n: usize) -> Vec<(T1, T2)> {
  let mut vec: Vec<(T1, T2)> = vec![];
  for _ in 0 .. n {
    vec.push(read_tuple());
  }
  vec
}

fn print_vec(vec: &VecDeque<usize>, sep: &str) {
  let out = vec.iter().map(|e| (e+1).to_string()).collect::<Vec<_>>().as_slice().join(sep);
  println!("{}", out);
}


Measured memory_bytes: 18684
N, W = map(int, input().split())
item = [tuple(map(int, input().split())) for _ in range(N)]

w1 = item[0][0]
V = [[] for _ in range(4)]
for w, v in item:
    V[w - w1].append(v)
for i in range(4):
    V[i].sort(reverse=True)

cnt = [0] * 4
for i in range(4):
    cnt[i] = len(V[i])

ans = 0
for i in range(cnt[0] + 1):
    S0 = sum(V[0][:i])
    W0 = i * w1
    for j in range(cnt[1] + 1):
        S1 = sum(V[1][:j])
        W1 = j * (w1 + 1)
        for k in range(cnt[2] + 1):
            S2 = sum(V[2][:k])
            W2 = k * (w1 + 2)
            for l in range(cnt[3] + 1):
                S3 = sum(V[3][:l])
                W3 = l * (w1 + 3)
                if W0 + W1 + W2 + W3 <= W:
                    ans = max(ans, S0 + S1 + S2 + S3)

print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <climits>
#include <vector>
#include <map>
#include <set>
#include <list>
#include <stack>
#include <queue>
#include <algorithm>
#include <iostream>
#include <string>

#define REP(i,n) for(auto i=0;i<n;++i)
#define REPR(i,n) for(auto i=n;i>=0;--i)
#define REPI(itr,v) for(auto itr=v.begin();itr!=v.end();++itr)
#define REPIR(itr,v) for(auto itr=v.rbegin();itr!=v.rend();++itr)
#define FOR(i,a,b) for(auto i=a;i<b;++i)
#define SORT(v,n) sort(v, v+n)
#define SORTV(v) sort(v.begin(), v.end())
#define ALL(v) v.begin(),v.end()
#define llong long long
#define ll long long
#define INF 999999999
#define MOD 1000000007
#define pb push_back
#define pf push_front
#define MP make_pair
#define SV(n,v) {int tmp;for(int i=0;i<n;++i){scanf("%d",&tmp);v.push_back(tmp);}}

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

using namespace std;

typedef pair<int,int> pii;

int main(){

  string s;
  cin >> s;

  int len = s.length();
  int ans = INF;
  int color = 1;

  int num = 0;
  //010...
  REP(i,len){
    if(color == 1){
      if(s[i] == '0'){
        num++;
      }
    }else{
      if(s[i] == '1'){
        num++;
      }
    }
    color *= -1;
  }

  ans = min(ans, num);

  //101..
  num = 0;
  color = 1;
  REP(i,len){
    if(color == 1){
      if(s[i] == '1'){
        num++;
      }
    }else{
      if(s[i] == '0'){
        num++;
      }
    }
    color *= -1;
  }

  ans = min(ans, num);
  cout << ans << endl;

  return 0;
}



Measured memory_bytes: 512