akhauriyash/Code-Regression huggingface dataset:
package main

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

)


func main() {
	solve(os.Stdin, os.Stdout)
}

type ReaderEx struct {
	baseScanner *bufio.Scanner
	words       []string
	nextWordIdx func() int
	initWordIdx func(int)
}

func NewScannerEx(stdin io.Reader) *ReaderEx {
	var this ReaderEx
	var idx int
	var wordsCnt int
	this.baseScanner = bufio.NewScanner(stdin)
	this.baseScanner.Buffer(make([]byte, 0), 1E+11)
	this.nextWordIdx = func() int {
		cur := idx
		idx = (idx + 1) % wordsCnt
		return cur
	}
	this.initWordIdx = func(wc int) {
		idx = 0
		wordsCnt = wc
	}
	return &this
}

func (me *ReaderEx) Scan(doSplit bool) (isScanned bool) {
	isScanned = me.baseScanner.Scan()
	if doSplit {
		me.words = strings.Fields(me.baseScanner.Text())
	} else {
		me.words = []string{me.baseScanner.Text()}
	}
	me.initWordIdx(len(me.words))
	return
}

func (me *ReaderEx) nextBytes() []byte {
	return []byte(me.words[me.nextWordIdx()])
}
func (me *ReaderEx) nextString() string {
	return me.words[me.nextWordIdx()]
}

type StringArray []string

func (me *ReaderEx) nextStringArray() StringArray {
	return me.words[me.nextWordIdx():]
}

func (me StringArray) toStrings() []string {
	return me
}

func (me StringArray) toInts() []int {
	strValues := me.toStrings()
	values := make([]int, len(strValues))
	for i, v := range strValues {
		n, err := strconv.Atoi(v)
		if err != nil {
			panic(err)
		}
		values[i] = n
	}
	return values
}
func (me *ReaderEx) nextInt() int {
	n, err := strconv.Atoi(me.words[me.nextWordIdx()])

	defer func() {
		if err != nil {
			panic(fmt.Sprintf("getInt(%d)", n))
		}
	}()
	return n
}

func pow(x, y, mod int) (ans int) {

	ans = 1
	for bit := 1 << uint(math.Floor(math.Log2(float64(y)))); ; bit >>= 1 {
		if y&bit != 0 {
			ans *= x
			if mod > 0 {
				ans %= mod
			}
		}
		if bit <= 1 {
			return
		}
		ans *= ans
		if mod > 0 {
			ans %= mod
		}
	}
}

type factType struct {
	prime int
	count int
}

func fact(n int) (facts []*factType) {

	for i := 2; i*i <= n; i++ {
		if n%i == 0 {
			fa := factType{prime: i}
			for n%fa.prime == 0 {
				n /= fa.prime
				fa.count++
			}
			facts = append(facts, &fa)
		}
	}
	if n > 1 {
		facts = append(facts, &factType{prime: n, count: 1})
	}
	return facts
}
func dec2bin(n int) (ret []bool) {
	for bit := 1 << uint(math.Floor(math.Log2(float64(n)))); ; bit >>= 1 {
		ret = append(ret, n&bit != 0)

		if bit <= 1 {
			return
		}
	}

}

func abs(v int) int {
	if v < 0 {
		v = -v
	}
	return v
}

func b2i(b bool) (i int) {
	if b {
		i = 1
	} else {
		i = 0
	}
	return
}

func solve(stdin io.Reader, stdout io.Writer) {

	r := NewScannerEx(stdin)
	r.Scan(true)
	al := r.nextString()

	ans := "a"
	if al[0] >= 'A' && al[0] <= 'Z' {
		ans = "A"
	}
	fmt.Fprintln(stdout, ans)
}


Measured memory_bytes: 1776
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>

//gcdをしっかり動くようにしたから自分のライブラリもこれに書き換えておいて
int gcd(int a, int b){
  int c;

  while (b > 0){
    c = a % b;
    a = b;
    b = c;
  }

  return a;
}

/****************************************\
| Thank you for viewing my code:)        |
| Written by RedSpica a.k.a. RanseMirage |
| Twitter:@asakaakasaka                  | 
\****************************************/

int main(void){
  /*
  全ての1<=i<j<=nについてgcd(A[i],A[j])=1なら当然全体のgcdも1になります

  よって，まず全体のgcdが1かそれ以外かを見て，"non coprime"であるケースを排除します

  次に，"pairwise coprime"かどうかを判定します．Aの最大値をmとおくと，
  2<=d<=mを満たす各dに対して，A[i]%d=0となるiの数が1個以下である必要があります．

  なぜかというと，i!=jでA[i]%d=0,A[j]%d=0となるような(i,j,d)の組み合わせがあったとすると，
  gcd(A[i],A[j])>=dになるのは定義より明らかだからです．

  これを純粋に実装すればよいです．

  フローチャートとしては

  ・全体のgcdは1か
  NO:non coprime->return
  YES:続く

  ・i!=jでgcd(A[i],A[j])>1となるペアが存在するか
  YES:setwise coprime->return
  NO:pairwise coprime

  計算量がO(n*m)くらいになりそうな感じがしますが，下のような実装をすることで
  O(m*log(m))まで抑えることができ，十分高速です


  コードの下になぜ計算量がこうなるのかの解説があるので，アルゴリズムが理解できて
  興味があったら読んでください．
  */

  int n;
  scanf("%d",&n);
  
  //どう頑張ってもA[i]<2e6なのでmをこれで設定する
  int m=2e6;
  int A[m];
  //初期化
  for(int i=0;i<m;i++){
    A[i]=0;
  }

  //全体のgcd
  int g=0;

  /*
  A[i]<=1e6なので
  A[i]:=i番目の要素の値
  ではなく
  A[i]:=iが何個現れるか
  という配列の使い方をする
  */

  for(int i=0;i<n;i++){
    int a;
    scanf("%d",&a);
    A[a]++;

    //ついでに全体のgcdを取る
    //gcdの単位元は0なので，gの初期化はg=0
    g=gcd(g,a);
  }

  //まずnot primeである可能性を消す
  if(g!=1){
    printf("not coprime\n");
    
    return 0;
  }

  /*
  Aの中のdの倍数の個数は
  A[d]+A[2*d]+A[3*d]+...
  で取得できる
  */
  for(int d=2;d<m;d++){
    int cnt=0;
    for(int i=d;i<m;i+=d){
      cnt+=A[i];
    }

    if(cnt>1){
      printf("setwise coprime\n");

      return 0;
    }
  }

  printf("pairwise coprime\n");

  return 0;
}

/*
～計算量がO(m*log(m))になるワケ～

上にも書いたように
  Aの中のdの倍数の個数は
  A[d]+A[2*d]+A[3*d]+...
  で取得できる
ので，
d=2:A[2]+A[4]+A[6]+...->O(m/2)
d=3:A[3]+A[6]+A[9]+...->O(m/3)
d=4:A[4]+A[8]+A[12]+...->O(m/4)
d=5:A[5]+A[10]+A[15]+...->O(m/5)
...

となるので最終的な計算量は
 (m/2)+(m/3)+(m/4)+(m/5)+...
=m*H_m
となる(ただし，H_nはnまでの調和級数)

一般的に，H_n>=log(n)であり，H_nの増加オーダーは高々log(n)であることがわかるので
このアルゴリズム全体の計算量はO(m*log(m))となります．
*/

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

int main() {
    int a ,b;
    cin >> a >> b;
    if (a >=13) {
        cout << b << endl;
    } else if ( a <= 12 && a >= 6) {
        cout << (b/2) << endl;
    } else {
        cout << 0 << endl;
    } 
}

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

using namespace std;
typedef long long ll;

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

  ll A[N], B[N], C[N];
  for (int i = 0; i < N; i++) cin >> A[i];
  for (int i = 0; i < N; i++) cin >> B[i];
  for (int i = 0; i < N; i++) cin >> C[i];

  sort(A, A + N);
  sort(B, B + N);
  sort(C, C + N);

  ll ans = 0;
  for (int i = 0; i < N; i++) {
    ll x = lower_bound(A, A + N, B[i]) - A;
    ll y = C + N - upper_bound(C, C + N, B[i]);
    ans += x * y;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2560
def examD():
    N, K =LI()
    cur = 0
    for i in range(K+1,N+1):
        cur +=((N//i)*(i-K) + max(0,N%i-K+1))
#        print(cur,i)
    if K==0:
        cur -=N
    print(cur)

import sys,copy,bisect,itertools,heapq,math
from heapq import heappop,heappush,heapify
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LSI(): return list(map(str,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()


Measured memory_bytes: 38896
//  ____            _                  _                       _       _
// |  _ \ _   _ ___| |_    ___ _ __   | |_ ___ _ __ ___  _ __ | | __ _| |_ ___
// | |_) | | | / __| __|  / __| '_ \  | __/ _ \ '_ ` _ \| '_ \| |/ _` | __/ _ \
// |  _ <| |_| \__ \ |_  | (__| |_) | | ||  __/ | | | | | |_) | | (_| | ||  __/
// |_| \_\\__,_|___/\__|  \___| .__/___\__\___|_| |_| |_| .__/|_|\__,_|\__\___|
//                            |_| |_____|               |_|

//https://github.com/manta1130/Competitive_Programming_Template_Rust

mod  binary_indexed_tree{

type VecType = isize;

///Binary Indexed Tree
pub struct BIT {
    v: Vec<VecType>,
}

impl BIT {
    ///BIT木を構築する。
    ///
    ///n:要素数
    pub fn new(n: usize) -> BIT {
        let v = vec![0; n + 1];
        BIT { v: v }
    }

    ///任意の要素に値を加算する。
    ///
    /// index:加算する場所(0-indexed)
    /// value:加算する値
    pub fn add(&mut self, index: usize, value: VecType) {
        let mut i = (index + 1) as isize;
        while i <= (self.v.len() - 1) as isize {
            self.v[i as usize] += value;
            i += i & -i;
        }
    }

    ///[0,index]の区間和を求める。
    pub fn get(&mut self, index: usize) -> VecType {
        let mut i = (index + 1) as isize;
        let mut res = 0 as VecType;
        while i > 0 {
            res += self.v[i as usize];
            i -= i & -i;
        }
        res
    }
}
}

use binary_indexed_tree::*;
#[allow(unused_imports)]
use proconio::{
    fastout, input,
    marker::{Bytes, Chars, Isize1, Usize1},
};


#[fastout]
fn main() {
    input! {
        n:usize,q:usize,
        c:[usize;n]
    }
    let mut query = vec![];
    for i in 0..q {
        input! {l:Usize1,r:Usize1}
        query.push((l, r, i));
    }
    query.sort_by_key(|x| x.1);
    let mut p = 0;
    let mut ft = BIT::new(n);
    let mut table = vec![None; n + 1];
    let mut ans = vec![];
    for (l, r, i) in query {
        while r >= p {
            if let None = table[c[p]] {
                table[c[p]] = Some(p);
                ft.add(p, 1);
            } else {
                ft.add(table[c[p]].unwrap(), -1);
                table[c[p]] = Some(p);
                ft.add(p, 1);
            }
            p += 1;
        }
        ans.push((i, ft.get(r) - if l == 0 { 0 } else { ft.get(l - 1) }));
    }
    ans.sort();
    for (_, x) in ans {
        println!("{}", x);
    }
}



Measured memory_bytes: 51096
from collections import deque
n = int(input())
a = list(map(int, input().split()))
a.sort(reverse=True)

ans = a[0]

cnt = len(a) - 2
if cnt % 2 == 0:
    for i in range(1, cnt // 2 + 1):
        ans += a[i] * 2

else:
    for i in range(1, cnt // 2 + 1):
        ans += a[i] * 2
    ans += a[i + 1]


print(ans)


Measured memory_bytes: 33116
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr ll MOD = 1000000007;
class SyntaxAnalysis
{
    using T = ll;

public:
    SyntaxAnalysis(const string& S) : S{S} {}
    T Expression() { return pos = 0, expression(); }

private:
    static constexpr char PLUS = '+';
    static constexpr char MINUS = '-';
    static constexpr char PRODUCT = '%';
    static constexpr char DIVIDE = '/';
    static constexpr char BRACE = '<';
    static T plus(const ll n, const ll k) { return n + k; }
    static T minus(const ll n, const ll k) { return n - k; }
    static T product(const ll n, const ll k) { return k >= 64 ? 0LL : n >> k; }
    static T divide(const ll n, const ll k) { return n / k; }
    static T brace(const ll n) { return n * n % MOD; }
    static bool is_digit(const char c) { return '0' <= c and c <= '9'; }
    static T encode(const char c) { return c - '0'; }
    ll number()
    {
        ll ans = 0;
        for (; pos < S.size() and is_digit(S[pos]); pos++) { ans = ans * 10LL + encode(S[pos]); }
        return ans;
    }
    ll factor()
    {
        if (S[pos] == BRACE) {
            ll ans = 0;
            return pos++, ans = brace(expression()), pos++, ans;
        } else {
            return number();
        }
    }
    ll term()
    {
        ll ans = factor();
        for (; pos < S.size();) {
            if (S[pos] == PRODUCT) {
                pos++, ans = product(ans, factor());
            } else if (S[pos] == DIVIDE) {
                pos++, ans = divide(ans, factor());
            } else {
                break;
            }
        }
        return ans;
    }
    ll expression()
    {
        ll ans = term();
        for (ll f = 0; pos < S.size();) {
            if (S[pos] == PLUS) {
                pos++, f = term(), ans = plus(ans, f);
            } else if (S[pos] == MINUS) {
                pos++, f = term(), ans = minus(ans, f);
            } else {
                break;
            }
        }
        return ans;
    }
    int pos = 0;
    string S;
};

int main()
{
    while (true) {
        auto input = []() {
            string s;
            getline(cin, s);
            string ans;
            for (ll i = s.size() - 1, st = 0, v = false; i >= 0; i--) {
                const char c = s[i];
                if (isdigit(c)) { ans.push_back(c), v = true; }
                if (c == '>') {
                    if (v) {
                        ans.push_back('%'), v = false, i--;
                    } else {
                        ans.push_back('>'), st++;
                    }
                }
                if (c == '<') { ans.push_back('<'), v = true, st--; }
            }
            reverse(ans.begin(), ans.end());
            return ans;
        };
        const string S = input();
        if (S.empty()) { break; }
        SyntaxAnalysis sy(S);
        cout << sy.Expression() << endl;
    }
    return 0;
}



Measured memory_bytes: 5368
#include <iostream>
#define UNKNOWN 2
#define CORRECT 1
#define WRONG 0
using namespace std;


int main() {
  while (true) {
    int a, b, c;
    cin >> a >> b >> c;
    if (a == 0 && b == 0 && c == 0) return 0;
    int n;
    cin >> n;
    int judge[a + b + c + 1];
    for (int i = 0; i <= a + b + c; i++)
      judge[i] = UNKNOWN;

    int p[n], q[n], r[n], s[n];
    for (int i = 0; i < n; i++)
      cin >> p[i] >> q[i] >> r[i] >> s[i];

    for (int i = 0; i < n; i++) {
      if (s[i] == CORRECT) {
	judge[p[i]] = judge[q[i]] = judge[r[i]] = CORRECT;
      }
    }

    for (int i = 0; i < n; i++) {
      if (s[i] == WRONG) {
	if (judge[p[i]] == UNKNOWN && judge[q[i]] == CORRECT &&
	    judge[r[i]] == CORRECT)
	  judge[p[i]] = WRONG;
	else if (judge[p[i]] == CORRECT && judge[q[i]] == UNKNOWN &&
	    judge[r[i]] == CORRECT)
	  judge[q[i]] = WRONG;
	else if (judge[p[i]] == CORRECT && judge[q[i]] == CORRECT &&
	    judge[r[i]] == UNKNOWN)
	  judge[r[i]] = WRONG;
      }
    }

    for (int i = 1; i <= a + b + c; i++)
      cout << judge[i] << endl;
  }
}

Measured memory_bytes: 3004
import java.util.Scanner;

public class Main {
	public static void main(String[] args){
		try(Scanner sc = new Scanner(System.in)) {
			
			String s = sc.next();
			String t = sc.next();
			
			int count = 0;
			for(int i = 0 ; i < s.length() ; i++ ) {
				
				if ( s.charAt(i) != t.charAt(i)) {
					count++;
				}
				
			}
			
			System.out.println(count);
			
		}
	}

}

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

int main(){
    ll n,x;
    cin >> n >> x;
    vector<int> l(n);
    int i,j;
    ll bo=1;
    ll sum=0;
    for(i=0;i<n;i++)cin >> l.at(i);
    for(i=0;i<n;i++){
        if(sum>x){
            cout << bo-1 << endl;
            return 0;
        }
        sum+=l.at(i);
        bo++;
        if(sum==x){
            cout << bo << endl;
            return 0;
        }
    }
    cout << n+1 << endl;
    return 0;
}

Measured memory_bytes: 256
N, A, B, C = map(int, input().split())
l = [int(input()) for _ in range(N)]

def dfs(depth, a, b, c):
    if depth == N:
        return abs(A-a)+abs(B-b)+abs(C-c)-30 if min(a, b, c) > 0 else 10**9

    ret0 = dfs(depth+1, a, b, c)# depth本目の棒を使わない
    ret1 = dfs(depth+1, a+l[depth], b, c)+10
    ret2 = dfs(depth+1, a, b+l[depth], c)+10
    ret3 = dfs(depth+1, a, b, c+l[depth])+10
    return min(ret0, ret1, ret2, ret3)

print(dfs(0, 0, 0, 0))


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

using namespace std;

/**
 *  Name: Chris M. Perez
 *  University: Interamerican University Metro Campus
 *
**/

#define endl '\n'
#define MOD 10e9
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define gcd(x , y) __gcd(x , y)
#define all(x) (x).begin() , (x).end()
#define forn(i , a , b) for(int i=(a);i<(b);i++)
#define forrange(j , a , b) for(int j=(a);j<=(b);j++)
#define nestedforn(i , a , b , j , c , d) for(int i=(a);i<=(b);i++) for(int j=(c);j<=(d);j++)
#define sort_all(x) sort(all(x))
#define zeros_at_beginning(x) __builtin_clz(x)
#define zeros_at_end(x) __builtin_ctz(x)
#define ones(x) __builtin_popcount(x)
#define parity_even_or_odd_ones __builtin_parity(x)

typedef vector<int> vi;
typedef pair<int , int> pii;
typedef tuple<int , int , int> tiii;
typedef vector<pii> vpii;
typedef vector<tiii> vtiii;
typedef unsigned int ui;
typedef unsigned long long ull;
typedef long long ll;
typedef long long int lli;

             
inline int input(){
  int n;
  scanf("%d" , &n);
  return n;
}

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  cout.precision(10);
  cout << fixed;

#ifdef LOCAL_DEFINE
  freopen("input.txt" , "rt" , stdin);
#endif
  
  string s; cin >> s;
  int a = 0, b = 0;
  forn(i , 0 , (int)s.size()){
    if(s[i] == '0') a++;
    else b++; 
  }   
  ll k = min(a , b);
  cout << k * 2 << endl;
  
#ifdef LOCAL_DEFINE
  cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif  
  return 0;
}

Measured memory_bytes: 512
#include<iostream>
#include<vector>
#include<string>
#include<array>
#include<cmath>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<numeric>
#include<iomanip>
#include<utility>
#include<cstdlib>
#include<typeinfo>


using namespace std;
#define INF 1000000005
int counter = 0;
int k = 0;
int flag = 0;

int graphlist[2004 * 2001] = {};

int graphsearch(int *g, int now,int depth){
    if(depth > k / 2){
        return 0;
    }
    int incre = 0;
    if(depth != 0 || flag != 1){
        counter++;
    }
    while(graphlist[2004 * g[2 + incre]] != 0){
        if(graphlist[2004 * g[2 + incre]] == now){
            incre++;
            continue;
        }
        graphsearch(graphlist + 2004 * g[2 + incre], g[0], depth + 1);
        incre++;
    }
    return 0;
}


int main()
{
int n;
std::cin >> n >> k;
for(int i = 1; i <= n; i++){
    graphlist[2004 * i] = i;
    graphlist[2004 * i + 1] = 0;
}

for(int i = 1; i <= n - 1; i++){
    int a;
    int b;
    std:cin >> a >> b;
    graphlist[2 + 2004 * a + graphlist[2004 * a + 1]] = b;
    graphlist[2 + 2004 * b + graphlist[2004 * b + 1]] = a;
    graphlist[2004 * a + 1]++;
    graphlist[2004 * b + 1]++;
}
int max = 0;

for(int i = 1; i <= n; i++){
    counter = 0;
    if(k % 2 == 0){
        flag = 0;
        graphsearch(graphlist + 2004 * i, i, 0);
        if(max < counter){
            max = counter;
        }
    } else {
        flag = 1;
        int ind = 0;
        while(graphlist[2 + 2004 * i + ind] != 0){
            counter = 2;
            graphsearch(graphlist + 2004 * graphlist[2 + 2004 * i + ind], graphlist[2004 * i], 0);
            graphsearch(graphlist + 2004 * i, graphlist[2004 * i + ind + 2], 0);
            ind++;
            if(max < counter){
                max = counter;
            }
        }    
    }
    if(max == n) break;
}

std::cout << n - max << std::endl;




return 0;
}

Measured memory_bytes: 14336
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
  if a[i]>=b[i]:
    ans=ans+b[i]
  elif a[i]+a[i+1]>=b[i]:
    ans=ans+b[i]
    a[i+1]=a[i+1]-b[i]+a[i]
  else:
    ans=ans+a[i]+a[i+1]
    a[i+1]=0
print(ans)

Measured memory_bytes: 18624
from math import pi, sin, cos, sqrt
a,b,h,m=map(int,input().split())
c=2*pi/12*h + pi/6/60*m
d=2*pi/60*m
ax=a*cos(c)
ay=a*sin(c)
bx=b*cos(d)
by=b*sin(d)
print(sqrt((ax-bx)**2 + (ay-by)**2))

Measured memory_bytes: 9508
import sys
import itertools
import pprint
input = lambda: sys.stdin.readline().rstrip()

H, W, K = map(int, input().split())
S = [[0 for _ in range(W)] for _ in range(H)]
for i in range(H):
    S[i] = list(map(int, input()))

Stsum = [[0 for _ in range(W + 1)] for _ in range(H + 1)]
for i in range(H):
    for j in range(W):
        Stsum[i + 1][j + 1] = Stsum[i + 1][j] + S[i][j]
for j in range(W):
    for i in range(H):
        Stsum[i + 1][j + 1] += Stsum[i][j + 1]


def count_white(l, r, u, b):
    return Stsum[b][r] - Stsum[u][r] - Stsum[b][l] + Stsum[u][l]


def solve():

    comb = list(itertools.product(range(2), repeat=H - 1))

    ans = 10 ** 9 + 7
    for c in comb:

        hc = [0] + [i + 1 for i, x in enumerate(c) if x == 1] + [H]
        l, w = 0, 1
        cut_count = 0
        search = False
        p_cut = True

        while w <= W:
            cut = True
            for h in range(0, len(hc) - 1):
                if count_white(l, w, hc[h], hc[h + 1]) > K:
                    cut = False
                    break
            else:
                search = True

            if not cut:
                if search:
                    l = w - 1
                    cut_count += 1
                    search = False
                else:
                    p_cut = False
                    break
            else:
                w += 1

        if p_cut:
            ans = min(ans, cut_count + len(hc) - 2)

    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 44892
def getlist():
	return list(map(int, input().split()))

N, K = getlist()
S = list(input())

L = []
v = S[0]
c = 0
for i in range(N):
	if S[i] == v:
		c += 1
	else:
		L.append(c)
		c = 1
	v = S[i]

L.append(c)

ans = 0
for i in L:
	ans += i - 1

ans += 2 * K
if ans >= N:
	print(N - 1)
else:
	print(ans)

Measured memory_bytes: 49520
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

class Main {
	public static void main(String[] args) throws IOException {
		// Input an array
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		int n = Integer.parseInt(br.readLine());
	
		Baggage[] a = new Baggage[n];
		String[] strs = br.readLine().split(" ");
	    for(int i = 0; i < n; ++i){
	        a[i] = new Baggage(i, Integer.parseInt(strs[i]));
	    }
	    
	    // Number the array
	    mergeSort(a, 0, n);
	    
	    // Calc. cost
	    int cost = 0;
	    int minw = a[0].weight;
	    int loss, cnt, j;
	    for(int i = 0; i < n; ++i) {
	    	if(a[i].flag == true){
		    	// search group key i
	    		continue;
	    	}
    		
	    	// count cost for group i
	    	cnt = 0; // swap count
	    	j = a[i].org;
	    	while(j != i) {
	    		// swap a[j] and a[i]
	    	    cost += a[j].weight + a[i].weight;
	    		cnt += 1;

	    	    a[j].flag = true;
		    	j = a[j].org;
	   	    }
	    	loss = (a[i].weight * cnt) - minw * cnt - 2 * (minw + a[i].weight);
	    	if(loss > 0){
	    		cost -= loss;
	    	}
	    }
	    
	    System.out.println(cost);
	}
	
	public static void mergeSort(Baggage[] s, int left, int right) {
		if(left + 1 < right) {
			int mid = (left + right) / 2;
			mergeSort(s, left, mid);
			mergeSort(s, mid, right);
			merge(s, left, mid, right);
		}
	}
	public static void merge(Baggage[] s, int left, int mid, int right) {
		Baggage[] s1 = Arrays.copyOfRange(s, left, mid + 1);
		Baggage[] s2 = Arrays.copyOfRange(s, mid, right + 1);
		
		s1[mid - left] = new Baggage(-1, Integer.MAX_VALUE);
		s2[right - mid] = new Baggage(-1, Integer.MAX_VALUE);
		int i = 0;
		int j = 0;
		for(int k = left; k < right; ++k) {
			if(s1[i].weight <= s2[j].weight){
				s[k] = s1[i];
				i += 1;
			}else{
				s[k] = s2[j];
				j += 1;
			}
		}
		
	}
}

class Baggage {
	public int org;
	public int weight;
	public boolean flag;
	public Baggage(int o, int w) {
		org = o;
		weight = w;
		flag = false;
	}
}

Measured memory_bytes: 25244
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
/* clang-format off */
#define MOD 1000000007
#define INF 1000000000
#define REP(i, n) for (ll i = 0, i##_len = (n); i < i##_len; ++i)
#define ALL(a) (a).begin(), (a).end()
#define __DEBUG__
#ifdef __DEBUG__
#define CH_P(a) cout <<"check_point("<<#a<<")" << "\n";
#define DEBUG(x) cout<<#x<<":"<<x<<"\n"
#define DEBUGS(v) cout << #v << ":";for(auto x:v){cout<<x<<" ";}cout<<"\n"
#endif
#ifndef __DEBUG__
#define CH_P(a) 
#define DEBUG(x) 
#define DEBUGS(v) 
#endif
#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() {
  ll l,r,d;
  cin >> l >> r >> d;
  ll ans=0;
  for (ll i = l; i <= r; i++) {
    if(i%d==0)ans++;
  }
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 3592
n, q = gets.chomp.split(" ").map(&:to_i)

queue = n.times.map do
  arr = gets.split(" ")
  arr[1] = arr[1].to_i
  arr
end

time = 0
result = []
while queue.size > 0 do
  process = queue.shift
  if process[1] > q
    process[1] = process[1] - q
    time += q
    queue.push(process)
  else process[1] <= q
    time += process[1]
    result << [process[0],time]
  end
end

result.each do |rs|
  puts rs.join(' ')
end


Measured memory_bytes: 20480
#include <iostream>
#include <utility>
#include <functional>
#include <math.h>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <tuple>
#include <stdlib.h>
using namespace std;
#define rep(i,n,x) for(int i=n;i<x;i++)
#define rem(i,n,x) for(int i=n;i>x;i--)
#define SORT(x) sort(x.begin(),x.end())
#define REV(x) reverse(x.begin(),x.end())
#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define setp(x) setprecision(x)
using LL = long long;
using ULL = unsigned long long;

int main() {
	int n, m, c;
	cin >> n >> m >> c;
	vector<int> b(m);
	rep(i, 0, m) cin >> b[i];
	vector<vector<int>> a(n, vector<int>(m));
	rep(i, 0, n) {
		rep(j, 0, m) cin >> a[i][j];
	}

	int count = 0;
	rep(i, 0, n) {
		int point = c;
		rep(j, 0, m)  point += a[i][j] * b[j];
		if (point > 0) count++;
	}
	cout << count << endl;
	
	return 0;
}

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

const char wall = '#';
vector<vector<char>> fields;
vector<vector<bool>> used;
vector<vector<ll>> dist;
const int dx[4] = {0, -1, 0, 1};
const int dy[4] = {1, 0, -1, 0};

vector<ll> A;
// vectorのリサイズ
// A.resize(N);

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

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

  ll r;
  cin >> r;
  cout << r*r << endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
 
using namespace std;
 
int main()
{
	ios_base::sync_with_stdio(false); 
	int n;
  	long long int temp,max=0,res=0;
  	cin>>n;
  	for(int i=0;i<n;i++)
    {
      cin>>temp;
	  if(temp>=max)
      max=temp;
      else if(max>temp)
      res+=(max-temp);
    }
  	cout<<res;
  
	return 0;
}

Measured memory_bytes: 3612
// lcm、__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
#include <bits/stdc++.h>
#define ll long long
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
using namespace std;

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

    ll i,j,k,l,m,n,w,x,y,z,p,q,tmp,sum=0;
    string str;
    cin>>n>>m;
    if(n<=m) cout<<"unsafe"<<endl;
    else cout<<"safe"<<endl; 

    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,n)   for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(long long i=(a);((a)<(b)?i<=(b):i>=(b));((a)<(b)?++i:--i))
#define ALL(v)     (v).begin(),(v).end()
#define debug(x)   cerr<<#x<<": "<<(x)<<endl
using namespace std;
typedef long long     llong;
typedef vector<int>   vi;
typedef vector<vi >   vvi;
typedef vector<vvi >  vvvi;
typedef pair<int,int> pii;
constexpr int    INF=1e9;
constexpr double EPS=1e-9;
constexpr int    MOD=1e9+7;
template<class Type>
void line(const Type &a){int cnt=0;for(const auto &elem:a){cerr<<(cnt++?' ':'>');cerr<<elem;}cerr<<endl;}

template<typename Type,typename Type_k>
Type ipow(Type n,Type_k k){//n^k. O(log n).
	if(k==0) return 1;
	Type res=ipow(n*n,k/2);
	if(k&1) res*=n;
	return res;
}

int main(){//Refering other editorials.
	int n,p;
	cin>>n>>p;
	
	int cnt[2]={};
	REP(i,n){
		int a;
		cin>>a;
		cnt[a&1]++;
	}
	
	llong ans;
	if(cnt[1]==0){
		if(p==1) ans=0LL;
		else ans=ipow(2LL,cnt[0]);
	}else{
		ans=ipow(2LL,n-1);
	}
	
	cout<<ans<<endl;
}

Measured memory_bytes: 3540
#include <cmath>
#include <iostream>

using namespace std;
typedef long long ll;



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

	ll n, k;
	cin >> n >> k;

	n = n % k;
	if ( n == 0 ) {
		n = k;
	}

	ll min = n;
	while ( true ) {
		n = abs(n - k);
		if ( min > n ) {
			min = n;
		}
		else {
			break;
		}
	}

	cout << min << '\n';
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<set>
using namespace std;
#define REP(i,b,n) for(int i=b;i<n;i++)
#define rep(i,n)   REP(i,0,n)
#define ALL(C)     (C).begin(),(C).end()

typedef long long ll;

int dp[100][101];
bool isbottom[101];

void calc(vector<int> in){
  rep(i,100)rep(j,101)dp[i][j]=0;
  dp[0][in[0]]=1;
  REP(i,1,in.size()){
    rep(j,101){
      dp[i][j]=dp[i-1][j];
      if (j-in[i]<0)continue;
      dp[i][j]+=dp[i-1][j-in[i]];
    }
  }

  rep(i,101)isbottom[i]=false;
  rep(i,in.size())if (dp[i][in[i]]==0)isbottom[in[i]]=true;
}

bool bt(int n,int now,int *inp,int *vol);

set<ll> D[100];
bool distribute(int n,int now,int *inp,int *vol){
  if (vol[now] == 0)return bt(n,now+1,inp,vol);

  ll state = 0;
  REP(i,now,n){
    state=(state<<1);
    if (vol[i] == inp[i])state++;
  }
  
  if (D[now].find(state) != D[now].end())return false;
  D[now].insert(state);
  if (vol[now] == 0)return false;



  REP(i,now+1,n){
    if (vol[i] != 0)continue;
    if (vol[now]-inp[i] < 0)continue;
    if (i-1 >= now+1 && inp[i-1] == inp[i] && vol[i-1] == 0)continue;
    vol[now]-=inp[i];
    vol[i]=inp[i];
    if (distribute(n,now,inp,vol))return true;
    vol[i]=0;
    vol[now]+=inp[i];
  }
  return false;
}

set<ll> S[100];
bool bt(int n,int now,int *inp,int *vol){
  if (now == n){
    return true;
  }

  ll state = 0;
  REP(i,now,n){
    state=(state<<1);
    if (vol[i] == inp[i])state++;
  }
  
  if (S[now].find(state) != S[now].end())return false;
  S[now].insert(state);
  if (vol[now] == 0)return false;

  //through
  if (bt(n,now+1,inp,vol))return true;

  if (isbottom[inp[now]]){
    //return false;
  }
  //distribute
  if (distribute(n,now,inp,vol))return true;
  return false;
}

main(){
  int n;
  while(cin>>n && n){
    int in[n];
    int vol[n];
    vector<int> a;
    rep(i,n){
      cin>>in[i];vol[i]=0;a.push_back(in[i]);
      S[i].clear();
      D[i].clear();
    }
    sort(in,in+n,greater<int>());
    sort(ALL(a));
    vol[0]=in[0];
    calc(a);
    if (bt(n,0,in,vol) == true)puts("YES");
    else puts("NO");

    //rep(i,n)cout << in[i] <<" set size: "<<S[i].size() << endl;
    
  }
  return false;
}

Measured memory_bytes: 3392
#include <bits/stdc++.h>
#include <stdio.h>
#include <math.h>
#include <cmath>
using namespace std;
#define vsort(vec) sort(vec.begin(), vec.end())
#define vreverse(vec) reverse(vec.begin(), vec.end())
using ll =long long;
const ll INF =1001001001;

//最大公約数
ll gcd(ll a, ll b){
   if (a%b==0){
       return(b);
   }else{
       return(gcd(b,a%b));
   }
}
//最小公倍数
ll lcm(ll a, ll b){
   return a*b/gcd(a,b);
}

//素数判定
ll isprime(ll n){
  bool prime=true;
  for(int i=2;i<n;i++){
    if(n%i==0){
      prime=false; break;
    }
  }
if(prime){cout<<n<<" is prime"<<endl;
         }else{cout<<n<<" is not prime"<<endl;}

}
//階乗　20くらいが限界
ll factorial(ll n){
  ll a=1;ll b=n;
  for(int i=0;i<n;i++){
    a*=b;
    b--;
  }
  return a;
}

//組み合わせ　nCr
ll comb(ll a,ll b){
  ll c;
  c=factorial(a)/(factorial(a-b)*factorial(b));
  return c; 
}




/*10億7。　　　100000007
2*2行列 H*W
vector<vector<int>> vec(H,vector<int>(W));
for(int i=0;i<H;i++){
for(int j=0;j<W;j++){
cin>>vec[i][j];
  }
}

文字列→数列
string S;int A=atoi(S.c_str());
数列→文字列
int A;string S=to_string(A);
数字判定　isdigit(a)
pair宣言　pair<int,int> p(5,7);
ソート　sort(vec.begin(),vec.end());
キュー　queue<int> q;
   q.push(7);　//７が入る
   cout << q.front() << endl;  // 先頭の値を出力
   q.pop();  // 先頭の値を削除
   q.empty();
*/
//座標　corrdinateト深さヲ保持スルタメノ構造体
struct Coor{
  ll y;
  ll x;
  ll depth;
};
 ll N,M;  
 ll sy,sx,gy,gx;
 ll y,x,depth;//キューから取り出した座標
vector<string> vec;
queue<Coor> q;
vector<ll> y_vec={0,0,-1,+1};//technique
vector<ll> x_vec={-1,+1,0,0};

int BFS(){
  while(!q.empty()){
    Coor now=q.front();q.pop();//キューの先頭を取り出す
    y=now.y,x=now.x,depth=now.depth;
    
    //停止条件
    if(y==gy&&x==gx){return depth;}
    
    //上下左右４方向を探索、進むことができればキューに格納
    for(int i=0;i<4;i++){
      Coor next={y+y_vec[i],x+x_vec[i],depth+1};
      if(0<=next.y&&next.y<=N-1&&0<=next.x&&next.x<=M-1&&vec[next.y][next.x]=='.'){
        vec[next.y][next.x]='x';//同じ場所を探索しないようにする
        q.push(next);
      }
    }
  }
  return 0;
}
                   
  


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

  

  ll N;cin>>N;
  int a,b;
  a=N/10;
  b=N%1000;
  if(a%111==0||b%111==0){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  
  
  
  
  
  
  
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    int n;
    while(cin>>n,n){
        map<int,pair<int,int>> sq,vec;
        sq[0]=make_pair(0,0);
        vec[0]=make_pair(-1,0);
        vec[1]=make_pair(0,1);
        vec[2]=make_pair(1,0);
        vec[3]=make_pair(0,-1);
        int wn=0,wx=0,hn=0,hx=0;
        for(int i=1;i<n;i++){
            int a,b;
            cin>>a>>b;
            sq[i]=make_pair(sq[a].first + vec[b].first, sq[a].second + vec[b].second);
            wn=min(wn,sq[i].first);
            wx=max(wx,sq[i].first);
            hn=min(hn,sq[i].second);
            hx=max(hx,sq[i].second);
        }
        cout<<wx-wn+1<<" "<<hx-hn+1<<endl;
    }
}

Measured memory_bytes: 3112
INF = int(1e18)


def main():
    N, *A, = map(int, open(0).read().split())
    ans = 1
    if 0 in A:
        print(0)
        return
    for a in A:
        ans *= a
        if INF < ans:
            print(-1)
            break
    else:
        print(ans)
    return


main()


Measured memory_bytes: 21616
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#define INF 1000000000
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;

// #define int long long

signed main(){
  int a,b,c,d,e,k;
  cin >> a>>b>>c>>d>>e>>k;
  if(e-a>k){
    cout << ":(" << endl;
  }else{
    cout << "Yay!" << endl;
  }
}


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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define pb push_back
#define ins insert
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n;
    cin>>n;

    vector <int> a(n);
    loop(i,0,n) cin>>a[i];

    sort(all(a));
    int ans=pinf;
    for(int x=a[0];x<=a[n-1];x++)
    {
        int st=0;
        for(int i=0;i<n;i++)
        {
            st+=(a[i]-x)*(a[i]-x);
        }
        ans=min(ans,st);
    }

    cout<<ans;


    return 0;
}


Measured memory_bytes: 3656
package main

import (
	"bufio"
	. "fmt"
	"io"
	"os"
	"sort"
)

// github.com/EndlessCheng/codeforces-go
func run(_r io.Reader, _w io.Writer) {
	in := bufio.NewReader(_r)
	out := bufio.NewWriter(_w)
	defer out.Flush()

	var n,k int
	Fscan(in, &n,&k)
	a := make([]int, n)
	for i := range a {
		Fscan(in, &a[i])
	}
	ans := sort.Search(1e9, func(x int) bool {
		if x == 0 {
			return false
		}
		cnt := 0
		for _, v := range a {
			cnt+=(v-1)/x
		}
		return cnt <=k
	})
	Fprintln(out, ans)
}

func main() { run(os.Stdin, os.Stdout) }


Measured memory_bytes: 5944
#include <iostream>
#include <string>
#include <map>

using namespace std;

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

    double money[n];
    string unit[n];
    for (int i = 0; i < n; i++)
    {
        cin >> money[i] >> unit[i];
    }

    double sum = 0.0f;
    for (int i = 0; i < n; i++)
    {
        if (unit[i] == "BTC")
        {
            sum += (money[i] * 380000.0f);
        }
        else
        {
            sum += money[i];
        }
    }

    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
N=int(input())
a=[]
for i in range(N):
    a.append(int(input()))

a.sort()

if sum(a)%10 != 0:
    print(sum(a))
    
else:
    for i in a:
        if (sum(a)-i)%10 != 0:
            print(sum(a)-i)
            exit()
    print(0)

Measured memory_bytes: 3064
X=int(input())
cnt_500=0
cnt_5=0
res=X

if res>0:
    cnt_500=res//500
    res=res-500*cnt_500
if res>0:
    cnt_5=res//5
    res=res-5*cnt_5

ans=1000*cnt_500+5*cnt_5
print(ans)

Measured memory_bytes: 3060
fun main(args: Array<String>) {
    val l = readLine()!!.split("").subList(1,5).map { it.toInt() }
    val res =
        if (l[0]+l[1]+l[2]+l[3] == 7) "${l[0]}+${l[1]}+${l[2]}+${l[3]}=7"
        else if (l[0]-l[1]+l[2]+l[3] == 7) "${l[0]}-${l[1]}+${l[2]}+${l[3]}=7"
        else if (l[0]+l[1]-l[2]+l[3] == 7) "${l[0]}+${l[1]}-${l[2]}+${l[3]}=7"
        else if (l[0]+l[1]+l[2]-l[3] == 7) "${l[0]}+${l[1]}+${l[2]}-${l[3]}=7"
        else if (l[0]+l[1]-l[2]-l[3] == 7) "${l[0]}+${l[1]}-${l[2]}-${l[3]}=7"
        else if (l[0]-l[1]+l[2]-l[3] == 7) "${l[0]}-${l[1]}+${l[2]}-${l[3]}=7"
        else if (l[0]-l[1]-l[2]+l[3] == 7) "${l[0]}-${l[1]}-${l[2]}+${l[3]}=7"
        else "${l[0]}-${l[1]}-${l[2]}-${l[3]}=7"
    println(res)
}


Measured memory_bytes: 38072
#include <iostream>

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

  for (int i=0; i<n; i++) {
    char c;
    std::cin >> c;

    if (c == 'Y') {
      std::cout << "Four" << std::endl;
      return 0;
    }
  }

  std::cout << "Three" << std::endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int a, b;
  string op;
  cin >> a >> b;
 
  if ((a*b)%2 == 0 ) {
    cout << "Even" << endl;
  }
  else {
    cout << "Odd" << endl;
  }
  }

Measured memory_bytes: 3596
#include <bits/stdc++.h>
#include <random>
using namespace std; typedef unsigned long long _ulong; typedef long long int lint; typedef pair<lint, lint> plint; typedef pair<double long, double long> pld;
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) ((lint)(x).size())
#define FOR(i, begin, end) for(lint i=(begin),i##_end_=(end);i<i##_end_;i++)
#define IFOR(i, begin, end) for(lint i=(end)-1,i##_begin_=(begin);i>=i##_begin_;i--)
#define REP(i, n) FOR(i,0,n)
#define IREP(i, n) IFOR(i,0,n)
#define endk '\n'
template<class T>bool chmax(T& a, const T& b) { if (a < b) { a = b; return 1; } return 0; }
template<class T>bool chmin(T& a, const T& b) { if (b < a) { a = b; return 1; } return 0; }
const lint MOD = 1e9 + 7, INF = 1e18;
lint dx[8] = { 0, -1, 1, 0, 1, -1, 1, -1 }, dy[8] = { 1, 0, 0, -1, -1, -1, 1, 1 };
typedef pair<lint, char> pa;

lint A, B, C, D;
int main() {
	cin >> A >> B >> C >> D;
	cout << max(max(A * C, A * D), max(B * C, B * D)) << endk;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-8;
const ll mod=1e9+7;
const int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int n,m;
vi s,t;

int main(){
	cin>>n>>m;
	s=t=vi(m);
	int res=0;
	for(int i=0;i<m;i++){
		int u,v;
		cin>>u>>v;
		s[i]=u-1;t[i]=v-1;
	}
	vi b(n);
	for(int i=0;i<n;i++){
		vi a(n);
		a[i]=1;
		for(int j=m-1;j>=0;j--){
			int u=s[j],v=t[j];
			if(a[u]&&a[v]){
				b[i]=1;
				break;
			}
			if(a[u]||a[v]) a[u]=a[v]=1;
		}
		if(!b[i]){
			for(int j=0;j<m;j++){
				if(a[s[j]]||a[t[j]]) a[s[j]]=a[t[j]]=1;
			}
			for(int j=0;j<i;j++) if(a[j]+b[j]==0) res++;
		}
	}
	cout<<res<<endl;
}

Measured memory_bytes: 1024
def solve():
    s = read()
    result = think(s)
    write(result)


def read():
    n = read_int(1)[0]
    return read_line(n=n)


def read_int(n):
    return list(map(lambda x: int(x), read_line().split(' ')))[:n]


def read_line(n=0):
    if n == 0:
        return input().rstrip()
    else:
        return input().rstrip()[:n]


def think(s):
    accumulated_count_facing_east, accumulated_count_facing_west = preprocess(s)
    member_count_needed_to_change_direction = len(s)  # as initial value

    n = len(s)

    for i in range(len(s)):
        if i == 0:
            change_to_west = accumulated_count_facing_east[n - 1] - accumulated_count_facing_east[0]
            member_count_needed_to_change_direction = min(change_to_west, member_count_needed_to_change_direction)
        elif i == len(s) - 1:
            change_to_east = accumulated_count_facing_west[n - 2]
            member_count_needed_to_change_direction = min(change_to_east, member_count_needed_to_change_direction)
        else:
            change_to_east = accumulated_count_facing_west[i - 1]
            change_to_west = accumulated_count_facing_east[n - 1] - accumulated_count_facing_east[i]
            member_count_needed_to_change_direction = min(change_to_east + change_to_west, member_count_needed_to_change_direction)
    return member_count_needed_to_change_direction


def preprocess(s):
    east_symbol = 'E'
    west_symbol = 'W'
    accumulated_count_facing_east = [0 for x in range(len(s))]
    accumulated_count_facing_west = [0 for x in range(len(s))]
    for i, elem in enumerate(s):
        if i == 0:
            if elem == east_symbol:
                accumulated_count_facing_east[i] = 1
            else:
                accumulated_count_facing_west[i] = 1
        else:
            if elem == east_symbol:
                accumulated_count_facing_east[i] = accumulated_count_facing_east[i - 1] + 1
                accumulated_count_facing_west[i] = accumulated_count_facing_west[i - 1]
            else:
                accumulated_count_facing_east[i] = accumulated_count_facing_east[i - 1]
                accumulated_count_facing_west[i] = accumulated_count_facing_west[i - 1] + 1
    return accumulated_count_facing_east, accumulated_count_facing_west

def write(result):
    print(result)


if __name__ == '__main__':
    solve()

Measured memory_bytes: 18044
#include<bits/stdc++.h>
using namespace std;
int main(){
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  int ans=min(b,d)-max(a,c);
  if(ans<=0)
    cout<<0;
  else
    cout<<ans;
  return 0;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(void){
    ll W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << fixed << setprecision(10) << W * H / 2.0 << " ";
    if (W / 2.0 == x && H / 2.0 == y)
        cout << 1 << endl;
    else
        cout << 0 << endl;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.*;

public class Main {

    void solve() throws IOException {
        int n = ni();
        int l = ni();
        int[] a = nia(n);

        long sum = 0;
        for (int i = 0; i < n; i++) {
            sum += a[i];
        }

        ArrayList<Integer> list = new ArrayList<>();

        int low = 1, high = n - 1;
        for (int i = 0; i < n - 1; i++) {
            if (sum < l) {
                out.println("Impossible");
                return;
            }
            if (a[low - 1] + a[low] < a[high - 1] + a[high]) {
                list.add(low);
                sum -= a[low - 1];
                low++;
            } else {
                list.add(high);
                sum -= a[high];
                high--;
            }
        }

        out.println("Possible");
        for (int i = 0; i < list.size(); i++) {
            out.println(list.get(i));

        }
    }

    String ns() throws IOException {
        while (!tok.hasMoreTokens()) {
            tok = new StringTokenizer(in.readLine(), " ");
        }
        return tok.nextToken();
    }

    int ni() throws IOException {
        return Integer.parseInt(ns());
    }

    long nl() throws IOException {
        return Long.parseLong(ns());
    }

    double nd() throws IOException {
        return Double.parseDouble(ns());
    }

    String[] nsa(int n) throws IOException {
        String[] res = new String[n];
        for (int i = 0; i < n; i++) {
            res[i] = ns();
        }
        return res;
    }

    int[] nia(int n) throws IOException {
        int[] res = new int[n];
        for (int i = 0; i < n; i++) {
            res[i] = ni();
        }
        return res;
    }

    long[] nla(int n) throws IOException {
        long[] res = new long[n];
        for (int i = 0; i < n; i++) {
            res[i] = nl();
        }
        return res;
    }

    class INA {
        int[][] a;

        INA(int n, int m) throws IOException {
            this(n, m, -1);
        }

        INA(int n, int m, int t) throws IOException {
            a = new int[m][n];

            for (int i = 0; i < n; i++) {
                for (int j = 0; j < m; j++) {
                    a[j][i] = ni() + t;
                }
            }
        }

        int[] get(int i) {
            return a[i - 1];
        }
    }

    static BufferedReader in;
    static PrintWriter out;
    static StringTokenizer tok;

    public static void main(String[] args) throws IOException {
        in = new BufferedReader(new InputStreamReader(System.in));
        out = new PrintWriter(System.out);
        tok = new StringTokenizer("");
        Main main = new Main();
        main.solve();
        out.close();
    }
}

Measured memory_bytes: 32156
n = int(input())
num = len(str(n))
ans = 0
if num%2==1:
    for i in range(num-1):
        if i%2==1:
            ans += 10**i
        else:
            ans -= 10**i
    ans += n-10**(num-1)+1
else:
    for i in range(num):
        if i%2==0:
            ans += 10**i*9
print(ans)

Measured memory_bytes: 38384
#include<bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); ++i) 
#define PI acos(-1)
#define pcnt __builtin_popcountll
#define rng(a) a.begin(), a.end()
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
#define fi first
#define se second

using namespace std;
using ll = long long;
using P = pair<int, int>;
using LP = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

template<typename T>inline istream& operator>>(istream&i,v(T)&v)
{rep(j,sz(v))i>>v[j];return i;}
template<typename T1,typename T2>inline istream& operator>>(istream&i,pair<T1,T2>&v)
{return i>>v.fi>>v.se;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false; }

ll INF = 1001001001;
ll LINF = 1001001001001001001ll;

ll n;
vector<vector<LP>> to;
vector<bool> cs;

void dfs(ll v, ll p, bool c) {
    cs[v] = c;

    for (auto nv : to[v]) {
        if (nv.fi == p) continue;
        if (nv.se % 2) dfs(nv.fi, v, !c);
        else dfs(nv.fi, v, c);
    }
}

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

    cin>>n;
    to = vector<vector<LP>>(n);
    rep(i, n - 1) {
        ll v1, v2, w;
        cin>>v1>>v2>>w; v1--; v2--;

        to[v1].emplace_back(v2, w);
        to[v2].emplace_back(v1, w);
    }

    if (n == 1) {
        cout<<'0'<<endl;
        return 0;
    }

    cs = vector<bool>(n);
    dfs(0, -1, true);
    rep(i, n) {
        if (cs[i]) cout<<'0'<<endl;
        else cout<<'1'<<endl;
    }
}

Measured memory_bytes: 10112