akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<vector>
#include<climits>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    int index=0;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
        if(v[i]<0){
            index=i;
        }
    }
    int startindex=max(index-k,0);
    int endindex=min(index+1,(int)v.size()-1);
    int result=INT_MAX;
    for(int i=startindex;i<=endindex;i++)
    {
        if(i+k-1<v.size()){
            int p=abs(v[i])+abs(v[i+k-1]-v[i]);
            if(result>p){
                result=p;
            }
            p=abs(v[i+k-1])+abs(v[i]-v[i+k-1]);
            if(result>p){;
                result=p;
            }
        }
        
    }
    cout<<result;
}

Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false), cin.tie(0)
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, a, b) for (int i = a; i < b; i++)
#define ALL(x) (x).begin(), (x).end()
#define dump(x) cout << (x) << endl
#define LMAX 9223372036854775807LL
#define LMIN -9223372036854775807LL
using ll = long long;
template<typename T>
using vec = vector<T>;
using P = pair<ll, ll>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
	fill((T *)array, (T *)(array + N), val);
}

const ll INF = 1e16;
const ll MOD = 1e9 + 7;
//int dx[4] = {1,0,-1,0};
//int dy[4] = {0,1,0,-1};
//ll pas[51][52];

ll n, ans = 0;

void calc(ll x){
	string s = to_string(x);
	int m = s.size();
	bool used[3] = {};
	REP(i, m){
		if(s[i] == '3')used[0]=true;
		if(s[i] == '5')used[1]=true;
		if(s[i] == '7')used[2]=true;
	}
	if(used[0] && used[1] && used[2])ans++;
	ll nx = x * 10 + 3;
	if(nx <= n)calc(nx);
	nx = x * 10 + 5;
	if(nx <= n)calc(nx);
	nx = x * 10 + 7;
	if(nx <= n)calc(nx);
}

signed main(){
	IOS;
	cin >> n;
	vec<ll> a(n + 1,0);
	for(ll i = 1;i <= n;i++){
		int j = i;
		for(int k = 2;k <= j;k++){
			while(j % k == 0){
				a[k]++;
				j /= k;
			}
		}
	}
	ll ans = 0;
	for(int i = 2;i <= n;i++){
		if(a[i] >= 74)ans++;
		if(a[i] >= 24){
			for(int j = 2;j <= n;j++){
				if(i == j)continue;
				if(a[j] >= 2)ans++;
			}
		}
		if(a[i] >= 14){
			for(int j = 2;j <= n;j++){
				if(i == j)continue;
				if(a[j] >= 4)ans++;
			}
		}

		if(a[i] >= 2){
			ll sum = 0;
			for(int j = 2;j <= n;j++){
				if(i == j)continue;
				if(a[j] >= 4)sum++;
			}
			ans += (sum - 1) * sum / 2;
		}
	}
	dump(ans);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define SORT(a) sort((a).begin(), (a).end())
#define RSORT(a) reverse((a).begin(), (a).end())
#define rep(i, n) for (int i = 0; i < n; i++)
#define all(a) ((a).begin(), (a).end())
typedef long long ll;
// const long long INF = 1LL << 60;
const int INF = 1010101010;
// using Graph = vector<vector<int>>;
const int MOD = 1000000007;

int dp[100015][13];

// 13で割って5余る数

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

  if (s[0] == '?')  // 0から9まで1通りずつ
    for (int i = 0; i < 10; i++) dp[0][i] = 1;
  else
    dp[0][s[0] - '0'] = 1;

  // 配るDP
  for (int k = 0; k < s.size() - 1; k++) {
    if (s[k + 1] == '?') {  // 次の文字が自由に決められる
      for (int i = 0; i < 13; i++) {
        for (int j = 0; j < 10; j++) {
          dp[k + 1][(i * 10 % 13 + j) % 13] += dp[k][i] % MOD;
          dp[k + 1][(i * 10 % 13 + j) % 13] %= MOD;
        }
      }
    } else {  // 次の文字が指定されている
      for (int i = 0; i < 13; i++) {
        dp[k + 1][(i * 10 % 13 + (s[k + 1] - '0')) % 13] += dp[k][i];
        dp[k + 1][(i * 10 % 13 + (s[k + 1] - '0')) % 13] %= MOD;
      }
    }
  }
  cout << dp[s.size() - 1][5] << endl;
}


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

class Main{
    public static void main(String[] args){
        FastScanner fsc=new FastScanner();
        int n=fsc.nextInt();
        char[] s=fsc.next().toCharArray();
        char[] t=fsc.next().toCharArray();
        fsc.close();
        for(int i=0;i<n;i++){
            System.out.print(s[i]);
            System.out.print(t[i]);
        }
        System.out.print("\n");
    }
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte(){
            if(ptr<buflen) return true;
            else{
                ptr = 0;
                try{
                    buflen = in.read(buffer);
                }
                catch(IOException e){
                    e.printStackTrace();
                }
                if(buflen<=0) return false;
            }
        return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            if (!hasNext()) throw new NoSuchElementException();
            long n = 0;
            boolean minus = false;
            int b = readByte();
            if (b == '-') {
                minus = true;
                b = readByte();
            }
            if (b < '0' || '9' < b) throw new NumberFormatException();
            while(true){
                if ('0' <= b && b <= '9') {
                    n *= 10;
                    n += b - '0';
                }
                else if(b == -1 || !isPrintableChar(b)) return minus ? -n : n;
                else throw new NumberFormatException();
                b = readByte();
            }
        }
        public int nextInt() {
            long nl = nextLong();
            if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
            return (int) nl;
        }
        public double nextDouble() { return Double.parseDouble(next());}
        public void close(){
            try{in.close();}
            catch(IOException e){e.printStackTrace();}
        }
    }
}


Measured memory_bytes: 21332
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>

#define MAX_A 100001

using namespace std;

int main(){

    int N, M;
    cin >> N >> M;
    vector<int> A[MAX_A];
    for(int i=0; i<N; i++){
        int a, b;
        cin >> a >> b;
        A[a].emplace_back(b);
    }

    priority_queue<int> que;

    int ans = 0;
    for(int i=1; i <= M; i++){
        for(int id : A[i]){
            que.push(id);
        }
        if(!que.empty()){
            ans +=que.top();
            que.pop();
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 5632
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
ans = []
for i in range(H):
    ans.append([0]*W)
m = 0
j = 0
k = 0
for i in range(len(a)):
    m = a[i]
    while m > 0:
        ans[j][k] = str(i+1)
        m -= 1
        if (j%2 == 0 and k == W-1) or (j%2 == 1 and k == 0):
            j += 1
        elif j%2 == 0:
            k += 1
        else:
            k -= 1
for i in range(H):
    print(" ".join(ans[i]))


Measured memory_bytes: 3700
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

ll gcd(ll a, ll b) {
	if (b == 0) { return a; }
	if (a < b) { return gcd(b, a); }
	return gcd(b, a % b);
}

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


///////////////////////////


int main() {

	ll N;
	cin >> N;

	ll ans = 1;

	for (ll i = 1; i * i < N - 1; i++) {
		if ((N - 1) % i == 0) { ans++; }
	}

	
	for (ll i = 2; i * i <= N; i++) {
		ll m = N;
		while (m % i == 0) { m /= i; }
		if (m % i == 1) { ans++; }
	}

	cout << ans;

	system("PAUSE");
}


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

using namespace std;

typedef long long ll;
typedef vector<int> ivec;
typedef pair<int, int> ipair;

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

    int count = 0;
    while (X <= Y) {
        count++;
        X *= 2;
    }

    cout << count << endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
//#include <iomanip>
//#include <string>
#include <vector>
#include <algorithm>
//#include <utility>
//#include <set>
//#include <map>
//#include <queue>
//#include <deque>
#include <bitset>
//#include <math.h>
using namespace std ;
using ll = long long ;
//using ld = long double ;
using vll = vector<ll> ;
//using vvll = vector<vll> ;
//using vc = vector<char> ;
//using vvc = vector<vc> ;
//using vb = vector<bool> ;
//using vvb = vector<vb> ;
//using pll = pair<ll,ll> ;
#define all(v) v.begin(),v.end()
//ll mod = 998244353 ;
//long double pie = acos(-1) ;
//ll INF = 1000000000000 ;

//void yorn(bool a){if(a) cout << "Yes" << endl ; else cout << "No" << endl ;}
//void YorN(bool a){if(a) cout << "YES" << endl ; else cout << "NO" << endl ;}
//ll gcd(long long a,long long b){if(b==0) return a ; return gcd(b,a%b) ;}
//ll lcm(long long a,long long b){return a/gcd(a,b)*b ;}
ll sa(long long a,long long b){if(a>b) return a-b ; return b-a ;}
//void fix_cout(){cout << fixed << setprecision(20) ;}
//ld dis(ll a,ll b,ll c,ll d){return sqrt((a-c)*(a-c)+(b-d)*(b-d)) ;}

int main(){
	ll n ; cin >> n ;
	vll cnt(13,0) ;
	cnt.at(0)++ ;
	for(int i=0;i<n;i++){
		ll a ; cin >> a ;
		cnt.at(a)++ ;
	}
	vll t,b ;
	for(int i=0;i<13;i++){
		if(cnt.at(i)==0) continue ;
		if(cnt.at(i)==1){
			if(i==0||i==12){
				t.emplace_back(i) ;
			}else{
				b.emplace_back(i) ;
			}
		}
		if(cnt.at(i)==2){
			if(i==0||i==12){
				cout << 0 << endl ;
				return 0 ;
			}
			t.emplace_back(i) ;
			t.emplace_back(24-i) ;
		}
		if(cnt.at(i)>=3){
			cout << 0 << endl ;
			return 0 ;
		}
	}
	ll ans = 0 ;
	for(int i=0;i<(1<<b.size());i++){
		bitset<15> bit(i) ;
		vll c = t ;
		for(int j=0;j<b.size();j++){
			if(bit[j]) c.emplace_back(b.at(j)) ;
			else c.emplace_back(24-b.at(j)) ;
		}
		sort(all(c)) ;
		c.emplace_back(0) ;
		ll d = 12 ;
		for(int j=0;j<c.size()-1;j++) d = min(d,min(sa(c.at(j),c.at(j+1)),24-sa(c.at(j),c.at(j+1)))) ;
		ans = max(ans,d) ;
	}
	cout << ans << endl ;
}


Measured memory_bytes: 256
MAX = 10000
NIL = -1

class Node:
    def __init__(self):
        self.parent = NIL
        self.left = 0
        self.right = 0

# 先行順巡回
def preParse(u):
    if u == NIL: return
    print(" %d" % u ,end="")
    preParse(T[u].left)
    preParse(T[u].right)

# 中間順巡回
def inParse(u):
    if u == NIL: return
    inParse(T[u].left)
    print(" %d" % u ,end="")
    inParse(T[u].right)
# 後行順巡回
def postParse(u):
    if u == NIL: return
    postParse(T[u].left)
    postParse(T[u].right)
    print(" %d" % u ,end="")

n = int(input())

T = []
# n個のノードを用意
for i in range(n):
    node = Node()
    T.append(node)




for i in range(n):
    v,l,r = map(int,input().split())
    T[v].left = l
    T[v].right = r
    if l != NIL:
        T[l].parent = v
    if r != NIL:
        T[r].parent = v


for i in range(n):
    if T[i].parent == NIL:
        root = i

print("Preorder")
preParse(root)
print()
print("Inorder")
inParse(root)
print()
print("Postorder")
postParse(root)
print()



Measured memory_bytes: 5612
import sys
import  math
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

A,B,C=nm()
print('bust' if 22<=(A+B+C) else 'win') 

Measured memory_bytes: 5076
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 
 
typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
//const long long MOD = 998244353;
using namespace std;

char str[100005];

int main(int argc, char* argv[])
{
    scanf("%s", str);
    int n=strlen(str);
    int i;
    int cnt=0;
    for(i=1; i<n; i++) {
        if(str[i]!=str[i-1]) cnt++;
    }
    printf("%d\n", cnt);
   


    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define f(i, x, n) for (int i = x; i < (int)(n); ++i)

int const N = 10;
char s[N + 1];
int tp[4], an;

int main(){
	int n;
	scanf("%d", &n);
	f(i, 0, n){
		scanf("%s", s);
		int m = strlen(s);
		f(i, 1, m)if (s[i - 1] == 'A' && s[i] == 'B')++an;
		int t = 0;
		if (s[0] == 'B')t |= 1;
		if (s[m - 1] == 'A')t |= 2;
		++tp[t];
	}
	int mn = max(0, tp[3] - 1);
	tp[3] -= mn;
	an += mn;
	mn = min(tp[1], tp[3]);
	an += mn;
	tp[3] -= mn;
	mn = min(tp[2], tp[3]);
	an += mn;
	tp[3] -= mn;
	mn = min(tp[1], tp[2]);
	an += mn;
	printf("%d\n", an);
}

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

const int MOD = 1000000007;
const int INF_32 = 1LL << 30;
const int64_t INF_64 = 1LL << 60;

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

typedef long long ll;

#define MAX_N 10000

struct Edge {
    int to;
    int weight;
    Edge(int t, int w)
        : to(t)
        , weight(w)
    {
    }
};
using Graph = vector<vector<int>>;
using Graph_e = vector<vector<Edge>>;

vector<int> dx = { 1, 0, -1, 0 };
vector<int> dy = { 0, 1, 0, -1 };
typedef pair<int, int> P;

template <typename T>
T GCD(T x, T y)
{
    return (y ? GCD<T>(y, x % y) : x);
}

int main()
{
    int N;
    cin >> N;
    vector<int> a(N);
    rep(i, N) cin >> a.at(i);

    vector<int> left(N + 1, 0), right(N + 1, 0);
    // left[p]:= [0, p)の最大公約数
    // right[p]:= [p, N)の最大公約数
    for (int i = 0; i < N; i++) {
        left.at(i + 1) = GCD(left.at(i), a.at(i));
    }
    for (int i = N - 1; i >= 0; i--) {
        right.at(i) = GCD(right.at(i + 1), a.at(i));
    }

    int res = 0;
    for (int i = 0; i < N; i++) {
        int l = left[i];
        int r = right[i + 1];

        chmax(res, GCD(l, r));
    }
    cout << res << endl;
}


Measured memory_bytes: 1408
using System;
using System.Collections.Generic;
using System.Text;

namespace agc038_a
{
  class Program
  {
    static void Main(string[] args)
    {
      var H = CIn.ReadInt();
      var W = CIn.ReadInt();
      var A = CIn.ReadInt();
      var B = CIn.ReadInt();

      var matrix = new byte[H, W];

      for (var i = 0; i < B; i++)
      {
        for (var j = A; j < W; j++)
        {
          matrix[i, j] = 1;
        }
      }

      for (var i = B; i < H; i++)
      {
        for (var j = 0; j < A; j++)
        {
          matrix[i, j] = 1;
        }
      }

      var output = new StringBuilder();

      for (var i = 0; i < H; i++)
      {
        for (var j = 0; j < W; j++)
        {
          output.Append(matrix[i, j]);
        }

        output.Append('\n');
      }

      Console.Write(output);
    }
  }

  class CIn
  {
    private static readonly Queue<string> fieldBuffer = new Queue<string>();

    public static string Read()
    {
      if (fieldBuffer.Count == 0)
      {
        foreach (var field in Console.ReadLine().Split())
        {
          fieldBuffer.Enqueue(field);
        }
      }

      return fieldBuffer.Dequeue();
    }

    public static int ReadInt() => int.Parse(Read());
    public static long ReadLong() => long.Parse(Read());
    public static double ReadDouble() => double.Parse(Read());

    public static string[] ReadStringArray(long n)
    {
      var array = new string[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = Read();
      }

      return array;
    }

    public static int[] ReadIntArray(long n)
    {
      var array = new int[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadInt();
      }

      return array;
    }

    public static long[] ReadLongArray(long n)
    {
      var array = new long[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadLong();
      }

      return array;
    }
    public static double[] ReadDoubleArray(long n)
    {
      var array = new double[n];

      for (var i = 0; i < n; i++)
      {
        array[i] = ReadDouble();
      }

      return array;
    }
  }
}

Measured memory_bytes: 21084
#include<bits/stdc++.h>
#define rep(i, n) for(int (i)=0 ;i <(n); ++(i))
#define REP(i,m,n) for(int (i) = (m); (i) <= (n); ++(i))
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)? "YES":"NO")
typedef long long ll;
using namespace std;

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int s = a*b;
  int t = c*d;
  s > t ? cout << s << endl : cout << t << endl; 
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    int temp;
    if(a>b){
        temp=a;
        a=b;
        b=temp;
    }
    if(b>c){
        temp=b;
        b=c;
        c=temp;
    }
    if(a>b){
        temp=a;
        a=b;
        b=temp;
    }
    cout << a <<" " << b << " "<< c << endl;
    return 0;
}


Measured memory_bytes: 3116
package main

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

var ar []int
var br []bool
var g map[int][]int
var qr []int

func main() {
	sc.Split(bufio.ScanWords)
	n, q := ri(), ri()
	g = map[int][]int{}
	for i := 1; i < n; i++ {
		a, b := ri(), ri()
		g[a] = append(g[a], b)
		g[b] = append(g[b], a)
	}
	qr = make([]int, n+1)
	for i := 0; i < q; i++ {
		p, x := ri(), ri()
		qr[p] += x
	}
	ar = make([]int, n+1)
	br = make([]bool, n+1)
	dfs(1, 0)
	for i := 1; i <= n; i++ {
		if i != 1 {
			fmt.Printf(" %d", ar[i])
		} else {
			fmt.Printf("%d", ar[i])
		}
	}
	fmt.Println()
}

func dfs(key, sum int) {
	if br[key] {
		return
	}
	br[key] = true
	sum += qr[key]
	ar[key] = sum
	for _, v := range g[key] {
		dfs(v, sum)
	}
}

var sc = bufio.NewScanner(os.Stdin)

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


Measured memory_bytes: 81024
def eye_test(eye, arr)
  case eye
  when 0...0.2
    arr[3] += 1
  when 0.2...0.6
    arr[2] += 1
  when 0.6...1.1
    arr[1] += 1
  else
    arr[0] += 1
  end
  
  return arr
end

l_arr, r_arr = Array.new(4, 0), Array.new(4, 0)

while gets
  l, r = $_.split.map(&:to_f)
  
  l_arr = eye_test(l, l_arr)
  r_arr = eye_test(r, r_arr)
end

4.times do |i|
  puts "#{l_arr[i]} #{r_arr[i]}"
end

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

using namespace std;
int a , b , c , d , n;
int main()
{
	string s;
	cin >> s;
	for(int i = 0; i < s.size(); i++){
		if(s[i] == 'N'){
			a = 1;
		}
		if(s[i] == 'E'){
			b = 1;
		}
		if(s[i] == 'S'){
			c = 1;
		}
		if(s[i] == 'W'){
			d = 1;
		}
	}
	if(((a + c) % 2 == 0) && ((b + d) % 2 == 0)){
		cout << "Yes";
	}
	else{
		cout << "No";
	}
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
using namespace std;
typedef long long unsigned int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

int main() {
    //cout.precision(10);
    int n;
    string s;
    cin >> n >> s;
    int ans = 0;
    for(int i = 1; i < n; i++){
        if(s[i] == 'E'){
            ans++;
        }
    }
    int ans_min = ans;
    for(int i = 1; i < n; i++){
        if(s[i - 1] == 'W'){
            ans++;
        }
        if(s[i] == 'E'){
            ans--;
        }
        ans_min = min(ans, ans_min);
    }
    cout << ans_min << endl;
    return 0;
}

Measured memory_bytes: 900
def prim():
    global M
    global n
    global INF
    color = ['w' for i in range(n)]
    d = [INF for i in range(n)]
    d[0] = 0
    p = [-1 for i in range(n)]

    while True:
        mincost = INF
        u = -1
        for i in range(n):
            if color[i] != 'b' and d[i] < mincost:
                mincost = d[i]
                u = i
        if u == -1:
            break
        color[u] = 'b'
        for v in range(n):
            if color[v] != 'b' and M[u][v] != INF:
                if M[u][v] < d[v]:
                    d[v] = M[u][v]
                    p[v] = u
                    color[v] = 'g'
    s = 0
    for i in range(n):
        if p[i] != -1:
            s += M[i][p[i]]
    return s


INF = 3000
n = int(input())

M = [[0 for j in range(n)] for i in range(n)]

for i in range(n):
    for j, x in enumerate(list(map(int, input().split()))):
        if x == -1:
            M[i][j] = INF
        else:
            M[i][j] = x
s = prim()
print(s)

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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<ll> cnt(100001);
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        cnt[a]++;
    }

    vector<ll> acc(100002);
    for (int i = 0; i < 100001; i++) {
        acc[i + 1] = acc[i] + cnt[i];
    }

    int ans = 0;
    for (int i = 0; i <= 100000; i++) {
        if (N / 2 == acc[i]) {
            ans++;
        }
    }

    cout << ans << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();
}

Measured memory_bytes: 1792
def 解():
    N = int(input())
    iD = 10**9+7

    #3210
    #***A
    #***G
    #***C
    #***T
    #*ACG
    #*GAC
    #*AGC
    #AGGC #A*GC AG*C から重複を消したもの
    #AGTC
    #ATGC

    A = [0]*(N+1)
    G = [0]*(N+1)
    C = [0]*(N+1)
    T = [0]*(N+1)
    AC = [0]*(N+1)
    GA = [0]*(N+1)
    AG = [0]*(N+1)
    AGG = [0]*(N+1)
    AGT = [0]*(N+1)
    ATG = [0]*(N+1)

    A[1]=G[1]=C[1]=T[1]=1 #種
    for i in range(2,N+1):
        #前の桁の末尾に一文字足したものから条件を満たすものを消す
        A[i] = A[i-1] + G[i-1] + C[i-1] +T[i-1]
        G[i] = A[i] - AC[i-1]
        C[i] = A[i] - GA[i-1] - AG[i-1] - AGG[i-1] - AGT[i-1] - ATG[i-1]
        T[i] = A[i]

        #この桁の末尾の場合の数を計算
        AC[i] = A[i-1] - GA[i-1]  # **AC を計算するために**A*を使うが*GAC の分(*GA*)はこの桁で消えるので消す
        AG[i] = A[i-1]
        GA[i] = G[i-1]

        AGG[i]= AG[i-1]
        AGT[i]= AG[i-1]
        ATG[i]= A[i-2]

        A[i] %= iD
        G[i] %= iD
        C[i] %= iD
        T[i] %= iD
        AC[i] %= iD
        GA[i] %= iD
        AG[i] %= iD
        AGG[i] %= iD
        ATG[i] %= iD
        AGT[i] %= iD

    print((A[N]+G[N]+C[N]+T[N])%iD)
解()


Measured memory_bytes: 3188
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

using namespace std;

typedef long long int lli;
typedef pair<int, int> ii;
typedef pair<int, lli> il;
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;}

#ifdef LOCAL
#define eprintf(...) printf(__VA_ARGS__)
#else 
#define eprintf(...) 1
#endif

#define ROUNDUP(a, b) 		( ((a) + ((b) - 1) ) / b)
#define SET_ZERO(a)	 		( memset((a), 0, sizeof(a)))
#define SET_NUM_ARRAY(a,b)	( memset((a), b, sizeof(a)))

int main() {
	int N, A;
	cin >> N >> A;
	int y[59];
	int max = 0;
	for (int i = 1; i <= N; i++) {
		int x;
		cin >> x;
		y[i] = x - A;
		max = max < y[i] ? y[i] : max;
	}
	int X = max;

	lli dp[59][2509]; // dp[k][t] := SUM(0->k y[i]) = t - NX
	SET_ZERO(dp);
	dp[0][N*X] = 1;
	for (int i = 1; i <= N; i++) {
		for (int j = 0; j <= 2*N*X; j++) {
			if (0 <= j - y[i] && j - y[i] <= 2 * N * X) {
				dp[i][j] = dp[i-1][j] + dp[i-1][j-y[i]];
			} else {
				dp[i][j] = dp[i-1][j];
			}
		}
	}

	cout << (dp[N][N*X] - dp[0][N*X]) << endl;
}


Measured memory_bytes: 1408
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.Scanner;
import java.util.Comparator;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        abc161_b solver = new abc161_b();
        solver.solve(1, in, out);
        out.close();
    }

    static class abc161_b {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            int N = in.nextInt();
            int M = in.nextInt();
            Integer A[] = new Integer[N];
            long ttl = 0;
            for (int i = 0; i < N; i++) {
                A[i] = in.nextInt();
                ttl += A[i];
            }

            Arrays.sort(A, Comparator.reverseOrder());
            if (A[M - 1] >= (double) ttl / (4.0 * (double) M)) {
                out.println("Yes");
            } else {
                out.println("No");
            }
        /*
        int count = 0;
        double quort = (double)ttl /(4.0 * M);
        for (double val: A
             ) {
            if (val >= quort) {
                count++;
            }
            if (count >= M) {
                out.println("Yes");
                return;
            }
        }
        out.println("No");
        */

        }

    }
}



Measured memory_bytes: 21844
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        int K = sc.nextInt();
        sc.close();
        List<String> ans = new ArrayList<String>();
        for(int i = 0; i < s.length(); i++){
            for(int j = 1; j <=K; j++){
                if(i+j > s.length()) break;
                if(!ans.contains(s.substring(i, i+j))) ans.add(s.substring(i, i+j));
            }
        }
        Collections.sort(ans);
        if(ans.size() < K)System.out.println(ans.get(ans.size()-1));
        else System.out.println(ans.get(K-1));
    }

}


Measured memory_bytes: 26052
#include <stdio.h>
#include <string.h>
 
int main()
{
    int i, n, m, len;
    char str[201], temp[201];

    for(;;) {
        scanf("%s", str);
        if (strcmp(str, "-") == 0) {
            break;
        }
        len = strlen(str);
        scanf("%d", &n);
        for (i = 0; i < n; i++) {
            scanf("%d", &m);
            strcpy(temp, str);
            strcpy(str, &temp[m]);
            strncpy(&str[len - m], temp, m);
            str[len] = '\0';
        }
        printf("%s\n", str);
    }
    return 0;
}

Measured memory_bytes: 596
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int c1 = scan.nextInt();
        int c5 = scan.nextInt();
        int c10 = scan.nextInt();
        int c50 = scan.nextInt();
        int c100 = scan.nextInt();
        int c500 = scan.nextInt();
        
       int a = c1+(c5*5)+(c10*10)+(c50*50)+(c100*100)+(c500*500);
        
        if( a >= 1000){
            System.out.println(1);
        }else{
            System.out.println(0);
        }
         
        }
    }   



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

int main() {
    string w;
    cin >> w;
    map<char, int> MP;
    for (int i = 0; i < w.length(); i++) MP[w[i]]++;
    bool is_correct = true;
    for (int i = 0; i < w.length(); i++) if (MP[w[i]] % 2 != 0) is_correct = false;
    if (is_correct) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

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

const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)


int main() {
  int a;
  cin >> a;
  int b = a/2 + (a%2!=0);
  cout << (double)b/a << endl;
}

Measured memory_bytes: 3780
#include<stdio.h>

int main(void)
{
	int i,j,k = 0;
	int a ,b ,c ;
	scanf("%d %d %d", &a ,&b ,&c);
	for(i=a;i<=b;i++){
		for(j=1;j<=c;j++){
			if((c%j)==0){
				if(i==j){
					k=k+1;
				}
			}
		}
	}
	printf("%d\n",k);
	return 0;
} 
	


Measured memory_bytes: 2104
import java.io.*;
import java.util.*;
public class Main{
    static int find(int bit[],int pos){
        int ans = 0;
        while(pos > 0){
            ans += bit[pos];
            pos -= (pos & -pos);
        }
        return ans;
    }
    static void update(int pos,int val,int bit[]){
        while(pos < bit.length){
            bit[pos] += val;
            pos += (pos & -pos);
        }
    }
    public static void main(String[] args) throws Exception {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        StringTokenizer st = new StringTokenizer(br.readLine());
        int n = Integer.parseInt(st.nextToken());
        int m = Integer.parseInt(st.nextToken());
        ArrayList<Node>list[] = new ArrayList[m + 1];
        for(int i = 1;i <= m;i++)
            list[i] = new ArrayList<>();
        for(int i = 1;i <= n;i++){
            st = new StringTokenizer(br.readLine());
            int start = Integer.parseInt(st.nextToken());
            int end = Integer.parseInt(st.nextToken());
            list[end - start + 1].add(new Node(start,end));
        }
        int bit[] = new int[m + 1];
        int fix = n;
        StringBuilder sb = new StringBuilder();
        for(int i = 1;i <= m;i++){
            int ans = 0;
            for(int j = i;j <= m;j += i){
                ans += find(bit,j);
                //System.out.println(ans + " " + i + " " + j);
            }
            for(Node temp : list[i]){
                update(temp.start,1,bit);
                update(temp.end + 1,-1,bit);
                //System.out.println(temp.start)
            }
            sb.append(ans + fix);
            sb.append('\n');
            fix -= list[i].size();
        }
        System.out.println(sb);
    }
    static class Node {
        int start;
        int end;
        Node(int start,int end){
            this.start = start;
            this.end = end;
        }
    }
}


Measured memory_bytes: 61812
#include<stdio.h>
int main (){
    int n,k,x,y,fee;
    scanf("%d %d %d %d",&n,&k,&x,&y);
    if(n<k){
        printf("%d\n",n*x);
    }
    else {
        fee=(n-k)*y+k*x;
        printf("%d\n",fee);
    }
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
typedef long long LL;
const int N=2005;
int n,tot,a[N],vis[N],h[N],ne[N<<1],to[N<<1],du[N];
vector<int> orz[N];
int gcd(int x,int y) {return y?gcd(y,x%y):x;}
void add(int x,int y) {to[++tot]=y,ne[tot]=h[x],h[x]=tot,++du[y];}
void dfs(int x) {
	vis[x]=1;
	for(RI i=0;i<orz[x].size();++i)
		if(!vis[orz[x][i]]) add(x,orz[x][i]),dfs(orz[x][i]);
}
priority_queue<int> q;
int main()
{
	n=read();
	for(RI i=1;i<=n;++i) a[i]=read();
	sort(a+1,a+1+n);
	for(RI i=1;i<=n;++i)
		for(RI j=i+1;j<=n;++j)
			if(gcd(a[i],a[j])>1) orz[i].push_back(j),orz[j].push_back(i);
	for(RI i=1;i<=n;++i) if(!vis[i]) dfs(i);
	for(RI i=1;i<=n;++i) if(!du[i]) q.push(i);
	while(!q.empty()) {
		int x=q.top();q.pop();printf("%d ",a[x]);
		for(RI i=h[x];i;i=ne[i]) {
			--du[to[i]];
			if(!du[to[i]]) q.push(to[i]);
		}
	}
	return 0;
}

Measured memory_bytes: 17792
/*{{{*/
#include <bits/stdc++.h>
#define SZ(X) ((int)(X).size())
#define ALL(X) (X).begin(), (X).end()
#define REP(I, N) for (int I = 0; I < (N); ++I)
#define REPP(I, A, B) for (int I = (A); I < (B); ++I)
#define FOR(I, A, B) for (int I = (A); I <= (B); ++I)
#define FORS(I, S) for (int I = 0; S[I]; ++I)
#define RS(X) scanf("%s", (X))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
#define MP make_pair
#define PB emplace_back
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define LEN(X) strlen(X)
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
typedef long double LD;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector<LL> VL;
typedef vector<PII> VPII;
typedef pair<LL,LL> PLL;
typedef vector<PLL> VPLL;
template<class T> void _R(T &x) { cin >> x; }
void _R(int &x) { scanf("%d", &x); }
void _R(int64_t &x) { scanf("%lld", &x); }
void _R(double &x) { scanf("%lf", &x); }
void _R(char &x) { scanf(" %c", &x); }
void _R(char *x) { scanf("%s", x); }
void R() {}
template<class T, class... U> void R(T &head, U &... tail) { _R(head); R(tail...); }
template<class T> void _W(const T &x) { cout << x; }
void _W(const int &x) { printf("%d", x); }
void _W(const int64_t &x) { printf("%lld", x); }
void _W(const double &x) { printf("%.16f", x); }
void _W(const char &x) { putchar(x); }
void _W(const char *x) { printf("%s", x); }
template<class T,class U> void _W(const pair<T,U> &x) {_W(x.F); putchar(' '); _W(x.S);}
template<class T> void _W(const vector<T> &x) { for (auto i = x.begin(); i != x.end(); _W(*i++)) if (i != x.cbegin()) putchar(' '); }
void W() {}
template<class T, class... U> void W(const T &head, const U &... tail) { _W(head); putchar(sizeof...(tail) ? ' ' : '\n'); W(tail...); }
#ifdef HOME
 #define DEBUG(...) {printf("# ");printf(__VA_ARGS__);puts("");}
#else
 #define DEBUG(...)
#endif
int MOD = 1e9+7;
void ADD(LL& x,LL v){x=(x+v)%MOD;if(x<0)x+=MOD;}
/*}}}*/
const int SIZE = 1e6+10;
int main(){
    string s;
    R(s);
    W(s[1]=='R'?"ABC":"ARC");
    return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
// type alias
typedef long long LL;
typedef pair<int,int> II;
typedef tuple<int,int,int> III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))
// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');
// debug cerr
template<class Iter> void __kumaerrc(Iter begin, Iter end) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; }
void __kumaerr(istream_iterator<string> it) { (void)it; cerr<<endl; }
template<typename T, typename... Args> void __kumaerr(istream_iterator<string> it, T a, Args... args) { cerr<<*it<<"="<<a<<", ",__kumaerr(++it, args...); }
template<typename S, typename T> std::ostream& operator<<(std::ostream& _os, const std::pair<S,T>& _p) { return _os<<"{"<<_p.first<<','<<_p.second<<"}"; }
#define __KUMATRACE__ true
#ifdef __KUMATRACE__
#define dump(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); __kumaerr(_it, args); }
#define dumpc(ar) { cerr<<#ar<<": "; FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
#define dumpC(beg,end) { cerr<<"~"<<#end<<": "; __kumaerrc(beg,end); }
#else
#define dump(args...)
#define dumpc(ar)
#define dumpC(beg,end)
#endif

// $ cp-batch Unification | diff Unification.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address Unification.cpp && ./a.out

/*
 
 3/14/2019
 
 10:19-
 
 */

//const int MAX_N=1e6+1;
string S;
int N;

void solve() {
  int res=0;
  VI st;
  REP(i,N) {
    st.push_back(S[i]);
    int M=SZ(st);
    if(M>=2&&(st[M-2]^st[M-1])==1) {
      res+=2,st.pop_back(),st.pop_back();
    }
  }
  cout<<res<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>S;
  N=SZ(S);
  solve();
  
  return 0;
}


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

using namespace std;

#define ll long long
int m = 1000000007;

ll bin_pow(int a, int pow) {
    if (pow == 1) return a % m;
    if (pow % 2 == 0) {
        ll tmp = bin_pow(a, pow / 2) % m;
        return tmp * tmp % m;
    }
    return (a % m) * (bin_pow(a, pow - 1) % m) % m;
}

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

    int h, w, n;
    cin >> h >> w >> n;


    if (w > h) swap(h, w);

    cout << ((n + h - 1) / h);
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <sstream>
#include <cmath>
#include <set>
#include <iomanip>
#include <deque>
#include <stdio.h>
using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
#define PB_VEC(Itr1,Itr2) (Itr1).insert((Itr1).end(),(Itr2).begin(),(Itr2).end())
#define UNIQUE(Itr) sort((Itr).begin(),(Itr).end()); (Itr).erase(unique((Itr).begin(),(Itr).end()),(Itr).end())
#define LBOUND(Itr,val) lower_bound((Itr).begin(),(Itr).end(),(val))
#define UBOUND(Itr,val) upper_bound((Itr).begin(),(Itr).end(),(val))
typedef long long ll;


int main(){
    
    int sx,sy,tx,ty;
    cin>>sx>>sy>>tx>>ty;
    
    int diff_x = abs(sx-tx);
    int diff_y = abs(sy-ty);
    
    REP(i,diff_x)cout<<'R';
    REP(i,diff_y)cout<<'U';
    REP(i,diff_x)cout<<'L';
    REP(i,diff_y)cout<<'D';
    cout<<'L';
    REP(i,diff_y+1)cout<<'U';
    REP(i,diff_x+1)cout<<'R';
    cout<<'D'<<'R';
    REP(i,diff_y+1)cout<<'D';
    REP(i,diff_x+1)cout<<'L';
    cout<<'U'<<endl;
    
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int a = sc.nextInt();
    sc.nextLine();
    String s = sc.nextLine();
    if(a<3200) {
      System.out.println("red");
    }
    else {
      System.out.println(s);
    }
  }
}

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

class ModWorld:
    def __init__(self, mod):
        self.mod = mod

    def prepare_factorial(self, N):
        self.f = [1] # f[n] := n!
        p = 1
        for i in range(1,N+1):
            p = (p*i) % self.mod
            self.f.append(p)

    def modpow(self, x, k):
        x %= self.mod
        k %= self.mod-1 # a^(p-1) = 1
        retval = 1
        while k:
            if k&1: retval = x * retval % self.mod
            k>>=1
            x = x*x % self.mod
        return retval % self.mod

    def modcomb(self, n, k):
        return self.f[n] * self.modpow(self.f[n-k], -1) * self.modpow(self.f[k], -1) % self.mod

mw = ModWorld(mod=10**9+7)
mw.prepare_factorial(N=10**5)

ans = 0
for i in range(N):
    if N-1-i<K-1: break
    comb = mw.modcomb(N-1-i, K-1)
    ans -= A[i] * comb
    ans += A[-(i+1)] * comb
    ans %= mw.mod
print(ans)

Measured memory_bytes: 14040
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<ll, ll>P;

class BF{
    public:
    ll N;
    ll INF;
    vector<vector<P> >path;
    vector<ll>dist;
    BF(ll n, ll inf){
        N = n + 1;
        INF = inf;
        path = vector<vector<P> >(N);
        dist = vector<ll>(N, INF);
    }
    void add(ll a, ll b, ll c){
        path[a].push_back(P(b, c));
    }
    bool make(ll s){
        dist[s] = 0;
        for(ll i = 0; i < N; i++){
            for(ll v = 0; v < N; v++){
                if(dist[v] == INF)continue;
                for(ll k = 0; k < path[v].size(); k++){
                    ll to = path[v][k].first;
                    ll w = path[v][k].second;
                    if(dist[to] > dist[v] + w){
                        dist[to] = dist[v] + w;
                        if(i == N - 1)return true;
                    }
                }
            }
        }
        return false;
    }
    ll get(ll t){
        return dist[t];
    }
};

int main(){

    ll N, M;
    cin >> N >> M;
    vector<vector<P> >path(N+1);
    vector<vector<ll> >rev(N+1);
    for(ll i = 0; i < M; i++){
        ll a, b, c;
        cin >> a >> b >> c;
        path[a].push_back(P(b, c));
        rev[b].push_back(a);
    }
    vector<ll>flg(N+1);
    queue<ll>Q;
    flg[N] = 1;
    Q.push(N);
    while(!Q.empty()){
        ll q = Q.front();
        Q.pop();
        for(ll i = 0; i < rev[q].size(); i++){
            ll j = rev[q][i];
            if(flg[j])continue;
            flg[j] = 1;
            Q.push(j);
        }
    }
    BF bf(N, 1e16);
    for(ll f = 1; f <= N; f++){
        for(ll i = 0; i < path[f].size(); i++){
            ll t = path[f][i].first;
            ll w = path[f][i].second;
            if(flg[f] == 1 && flg[t] == 1){
                bf.add(f, t, -w);
            }
        }
    }
    bool lp = bf.make(1);
    if(lp)cout << "inf" << endl;
    else cout << -bf.get(N) << endl;

    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define dbug(x) cout<<#x<<"="<<x<<endl
using namespace std;
template <typename T> void read(T &t) {
	t=0; char ch=getchar(); int f=1;
	while ('0'>ch||ch>'9') { if (ch=='-') f=-1; ch=getchar(); }
	do {(t*=10)+=ch-'0';ch=getchar();} while ('0'<=ch&&ch<='9'); t*=f;
}
typedef long long ll;
char s[210],t[210];
ll k,ans,t1,t2; int n,flag;
int main() {
	//freopen("1.txt","r",stdin);
	scanf("%s",s+1);
	read(k);
	n=strlen(s+1);
	for (int i=1;i<=n;i++) s[n+i]=s[i];
	for (int i=1;i<=n*2;i++) t[i]=s[i];
	for (int i=1;i<=n+1;i++)
		if (s[i]==s[i-1]) {
			if (k==1&&i==n+1) break;
			if (i==n+1) flag=1;
			s[i]=0,ans++;
		}
	ans*=k;
	if (flag) {
		char ch=s[n];
		for (int i=1;i<=n*2;i++) {
			if (t[i]==t[i-1]) {
				t[i]=0; t1++;
			}
			if (i==n) t2=t1;
		}
		t1-=t2; swap(t1,t2);
		if (t[n*2]!=ch) {
			if (k&1) ans=(t1+t2)*(k/2)+t1;
			else ans=(t1+t2)*(k/2);
		} else {
			ans=(k-1)*t2+t1;
		}
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 256
T[20][20],X,Y,x,y,p,q,i;
#define t T[y][x]
void R(x,y){(0<=x&&x<X&&0<=y&&y<Y&&!t)?t=1,i++,R(x-1,y),R(x+1,y),R(x,y-1),R(x,y+1):0;}
main(){for(;scanf("%d%d",&X,&Y),X;i=0,R(p,q),printf("%d\n",i))
for(i=0;i<X*Y;i++)switch(x=i%X,y=i/X,getchar()){
	case 10:i--;break;
	case'@':p=x;q=y;
	case'.':t=0;break;
	case'#':t=1;
}exit(0);}

Measured memory_bytes: 0
S = list(input())

count = 0
flag = 0

if S[0] == "R":
    flag = 1

for x in range(1,len(S)):
    if S[x] == "R":
        flag = 1
    if S[x-1] == "R" and S[x] == "R":
        count += 1

print(count + flag)

Measured memory_bytes: 9108
#include<stdio.h>
#include<stdlib.h>

struct node{
  struct node *right;
  struct node *left;
  struct node *parent;
  int key;
};
typedef struct node * Node;
#define NIL NULL

Node root;

Node treeMinimum(Node x){
  while(x->left != NIL)
    x = x->left;
  return x;
}

Node treeMaximum(Node x){
  while(x->right != NIL)
    x = x->right;
  return x;
}

Node treeSearch(Node u, int k){
  if(u == NIL || k == u->key)
    return u;
  if(k < u->key)
    return treeSearch(u->left, k);
  else
    return treeSearch(u->right, k);
}

Node treeSuccessor(Node x){
  if(x->right != NIL)
    return treeMinimum(x->right);
  Node y = x->parent;
  while(y != NIL && x == y->right){
    x = y;
    y = y->parent;
  }
  return y;
}

void treeDelete(Node z){
  Node y; // node to be deleted
  Node x; // child of y

  if(z->left == NIL || z->right == NIL)
    y = z;
  else
    y = treeSuccessor(z);
  if(y->left != NIL)
    x = y->left;
  else
    x = y->right;
  if(x != NIL)
    x->parent = y->parent;
  if(y->parent == NIL)
    root = x;
  else if(y == y->parent->left)
    y->parent->left = x;
  else
    y->parent->right = x;
  if(y != z){
    z->key = y->key;
    treeDelete(y);
  }
}

void insert(int k){
  Node y = NIL;
  Node x = root;
  Node z;

  z = malloc(sizeof(struct node));
  z->key = k;
  z->left = NIL;
  z->right = NIL;

  while(x != NIL){
    y = x;
    if(z->key < x->key)
      x = x->left;
    else
      x = x->right;
  }
  z->parent = y;

  if(y == NIL)
    root = z;
  else if(z->key < y->key)
    y->left = z;
  else
    y->right = z;
}

void inorder(Node u){
  if(u->left != NIL)inorder(u->left);
  printf(" %d", u->key);
  if(u->right != NIL)inorder(u->right);
}
void preorder(Node u){
  printf(" %d", u->key);
  if(u->left != NIL)preorder(u->left);
  if(u->right != NIL)preorder(u->right);
}


int main(){
  int n, i, x;
  char com[20];
  scanf("%d", &n);

  for ( i = 0; i < n; i++ ){
    scanf("%s", com);
    if ( com[0] == 'f' ){
      scanf("%d", &x);
      Node t = treeSearch(root, x);
      if ( t != NIL ) printf("yes\n");
      else printf("no\n");
    } else if ( com[0] == 'i' ){
      scanf("%d", &x);
      insert(x);
    } else if ( com[0] == 'p' ){
      inorder(root);
      printf("\n");
      preorder(root);
      printf("\n");
    } else if ( com[0] == 'd' ){
      scanf("%d", &x);
      treeDelete(treeSearch(root, x));
    }
  }

  return 0;
}

Measured memory_bytes: 19364
#include<iostream>
#include<queue>
#include<string>
#include<cmath>
#include<cstdio>
#include<cctype>
#include<cstring>
#include<iomanip>
#include<cstdlib>
#include<ctime>
#include<set>
#include<map>
#include<utility>
#include<vector>
#include<stack>
#include<sstream>
#include<algorithm>
using namespace std;
/****************************/
#define ll long long
#define vi vector<int>
#define pii pair<int,int>
#define vpii vector<pair<int,int> >
#define qi queue<int>
#define mii map<int,int>
#define msi map<string,int>
#define vs vector<string>
#define vc vector<char>
/****************************/
#define rep(i,n) for(ll i=0;i<(n);i++)
#define rep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define rep3(i,a,n) for(ll i=(a);i<(n);i++)
#define rep4(i,a,n) for(ll i=(n)-1;i>=a;i--)
#define mp make_pair
#define pb push_back
#define st first
#define nd second
#define pi 3.1415926535897932384626433832795
#define zero(n) memset(n,0,sizeof(n));
#define SZ(n) n.size()
#define mod 1000000007
#define INF 1000000000000000000
/****************************/
int n;
int a[200010];
vi v;
string s;
int main()
{
	zero(a);
	cin>>n;
	rep(i,n-1)
	{
		int b;
		cin>>b;
		a[b]++;
	}
	rep3(i,1,n+1)
	{
		cout<<a[i]<<endl;
	}
    return 0;
}

Measured memory_bytes: 4404