akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int,int> pii;
 
long long MOD = 1000000000 + 7;
 
template<typename T>
T gcd(T a, T b) {
  if(a < b) swap(a,b);
    
  if(b == 0) return a;
  return gcd(b, a % b);
}
// セグメントツリー
typedef long long ll;
int const inf = INT_MAX / 2;
 
enum query_type { min_query, max_query, sum_query, gcd_query};
 
template<class T> struct segtree {
  int N;
  vector<T> dat, sum;
  function<T(T, T)> func;
  T ngvalue;
 
  void init(int n, function<T(T, T)> const& f, T ng) {
    N = 1;
    while(N < n) N <<= 1;
    dat.assign(2 * N - 1, 0);
    sum.assign(2 * N - 1, 0);
    func = f;
    ngvalue = ng;
  }
 
  segtree() = default;
 
  segtree(int n, query_type qtype) {
    if(qtype == min_query) {
      init(n, [](T a, T b){return min(a, b);}, numeric_limits<T>::max());
    }
    else if(qtype == max_query) {
      init(n, [](T a, T b){return max(a, b);}, numeric_limits<T>::min());
    }
    else if(qtype == sum_query) {
      init(n, [](T a, T b){return a + b;}, 0);
    }
    else if(qtype == gcd_query) {
      init(n, [](T a, T b){return gcd(a,b);}, 0);
    }
    else {
      runtime_error("no matching query type");
    }
  }
 
  void add(int i, T x) {
    add(i, i + 1, x);
  }
 
  void add(int a, int b, T x) {
    add(a, b, x, 0, 0, N);
  }
 
  T add(int a, int b, T x, int k, int l, int r) {
    if(b <= l || r <= a) return dat[k];
    if(a <= l && r <= b) {
      sum[k] += x;
      return dat[k] += x;
    }
    int m = (l + r) / 2;
    return dat[k] = func(add(a, b, x, 2 * k + 1, l, m), add(a, b, x, 2 * k + 2, m, r)) + sum[k];
  }
 
  T operator()(int a, int b) {
    return query(a, b, 0, 0, N);
  }
 
  T query(int a, int b, int k, int l, int r) {
    if(b <= l || r <= a) return ngvalue;
    if(a <= l && r <= b) return dat[k];
    int m = (l + r) / 2;
    return func(query(a, b, 2 * k + 1, l, m), query(a, b, 2 * k + 2, m, r)) + sum[k];
  }
};


int main(){
  cout << setprecision(10);
  int N;
  ll K;
  cin >> N >> K;

  segtree<int> st(N+2, sum_query);

  vector<ll> S(N);
  for(int i = 0; i < N; i++){
    cin >> S[i];
    S[i] -= K;
  }
  vector<ll> SS(N+1), SSS(N+1);
  SS[0] = 0;
  for(int i = 0; i < N; i++){
    SS[i+1] = SS[i] + S[i];
  }

  map<ll,int> m;
  SSS = SS;
  sort(SS.begin(), SS.end());
  for(int i = 0; i <= N; i++){
    if(m.count(SS[i]) == 0){
      m[SS[i]] = i;
    }
  }

  vector<int> target(N+1);
  for(int i = 0; i <= N; i++){
    target[i] = m[SSS[i]] + 1;
    // cerr << "SS: " << SSS[i] << " rank: " << target[i] << endl;
  }

  // target[i]を足した時に、0~i-1でtarget[i]以下の個数を足していく
  ll ans = 0;
  for(int i = 0; i <= N; i++){
    ans += st(0, target[i]+1);
    // cerr << "i: " << i << " target[i]: " << target[i] << " now: " << st(target[i], target[i]+1) << " query: " << st(0, target[i]+1) << endl;
    st.add(target[i], 1);
  }
  cout << ans << endl;
  


}


Measured memory_bytes: 25452
# ans=true
# start_p=[0,0,0]

# n=gets.strip.to_i
# ps=[]
# (1..n).each do 
#     ps.push(gets.strip)
# end

# (0..n-1).each do |i|
#     t,x_end,y_end=ps[i].split.map(&:to_i)
#     t_diff=t-start_p[0]
#     puts "t_diff:#{t_diff}"
#     (0..t_diff).each do |x|
#         x_current=start_p[1]+x
#         y_current=start_p[2]+(t_diff-x)
#         if x_current==x_end&&y_current==y_end
#             ans=true
#             start_p[0]=t
#             start_p[1]=x_end
#             start_p[2]=y_end
#             puts "true:#{i+1}回目:x:#{x_current}y:#{y_current}"
#             break
#         else
#             ans=false
#             puts "false:#{i+1}回目:x:#{x_current}y:#{y_current}"
#         end
#     end
#     break if !ans
# end

# puts ans ? 'Yes' : 'No'

def is_reachable(current,next_data)
    tc,xc,yc=current
    tn,xn,yn=next_data

    dist=(xn-xc).abs+(yn-yc).abs
    
    return false if dist>tn-tc

    (dist-(tn-tc)).even?
end

n=gets.strip.to_i
data=n.times.map {gets.strip.split.map(&:to_i)}
current=[0,0,0]

data.each do |d|
    unless is_reachable(current,d)
        puts "No"
        exit 0
    end
    current=d
end

puts "Yes"

Measured memory_bytes: 20836
from heapq import heappop,heappush;import sys;input=sys.stdin.readline
x,y,z,k=map(int,input().split());a,b,c=list(map(int,input().split())),list(map(int,input().split())),list(map(int,input().split()))
q,h,l=[],[],0
for i in a:
  for j in b:heappush(q,-(i+j));l+=1
for _ in range(min(l,k)):
  t=heappop(q)
  for i in c:heappush(h,t-i)
for i in range(k):print(-heappop(h))

Measured memory_bytes: 152792
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        sc.close();

        if (S.charAt(2) == S.charAt(3) && S.charAt(4) == S.charAt(5)) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 23764
#include <stdio.h>
int main(void){
    int a[3],b,c;
    scanf("%d %d %d",&a[0],&a[1],&a[2]);
    for(int j=0;j<4;j++){
        for(int i=0;i<2;i++){
            if(a[i]<a[i+1]){
                
            }else{
                b=a[i];
                a[i]=a[i+1];
                a[i+1]=b;
            }
        }
    }

    printf("%d %d %d\n",a[0],a[1],a[2]);
    
    return 0;
}


Measured memory_bytes: 2044
x, y=map(int, input().split())
l1=[1, 3, 5, 7, 8, 10, 12]
l2=[4, 6, 9, 11]
l3=[2]
if x in l1 and y in l1:
  print("Yes")
elif x in l2 and y in l2:
  print("Yes")
elif x in l3 and y in l3:
  print("Yes")
else:
  print("No")

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

int main() {
	int n; cin >> n; 
	vector<int>h(n);
	for (int i = 0; i < n; i++) cin >> h[i];
	int ans = 1;
	int border = h[0];
	for (int i = 1; i < n; i++) {
		int maxi = h[i];
		for (int j = i - 1; j >= 0; j--) {
			maxi = max(maxi, h[j]);
		}
		if (maxi == h[i]) ans++;
	}
	cout << ans << endl;

	return 0;
}

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

class Plogram
{
    static void Main()
    {
        int[] line = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
        if(line[1] % line[0] == 0)
        {
            Console.WriteLine(line[0] + line[1]);
        }
        else
        {
            Console.WriteLine(line[1] - line[0]);
        }
    }
}

Measured memory_bytes: 13268
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<pair<int, int> > v(n);
    for(int i=0; i<n; ++i)
        cin >> v[i].second >> v[i].first;
    sort(v.begin(), v.end());

    int t = 0;
    for(int i=0; i<n; ++i){
        t += v[i].second;
        if(t > v[i].first){
            cout << "No" << endl;
            return 0;
        }
    }

    cout << "Yes" << endl;
    return 0;
}


Measured memory_bytes: 1792
#!usr/bin/env python3
from collections import defaultdict,deque
from heapq import heappush, heappop
from itertools import permutations
import sys
import math
import bisect
def LI(): return [int(x) for x in sys.stdin.readline().split()]
def I(): return int(sys.stdin.readline())
def LS():return [list(x) for x in sys.stdin.readline().split()]
def S():
    res = list(sys.stdin.readline())
    if res[-1] == "\n":
        return res[:-1]
    return res
def IR(n):
    return [I() for i in range(n)]
def LIR(n):
    return [LI() for i in range(n)]
def SR(n):
    return [S() for i in range(n)]
def LSR(n):
    return [LS() for i in range(n)]

sys.setrecursionlimit(1000000)
mod = 1000000007

def solve():
    A,B,m = LI()
    a = LI()
    b = LI()
    ans = min(a)+min(b)
    g = LIR(m)
    for i,j,c in g:
        i -= 1
        j -= 1
        k = a[i]+b[j]-c
        if k < ans:
            ans = k
    print(ans)
    return

#Solve
if __name__ == "__main__":
    solve()


Measured memory_bytes: 76944
from collections import Counter

n = int(input())
ans = 0
k = set()
c = Counter()

for _ in range(n):
    s = ''.join(sorted(list(input().rstrip())))
    if s in k:
        c[s] += 1
    k.add(s)

ans = 0
for ck in c.keys():
    ans += c[ck] * (c[ck] + 1) // 2

print(ans)


Measured memory_bytes: 15128
//Factors of Factorial

#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define int long long
#define rep(i,x,y) for(ll i=x;i<y;i++)
#define nvarep(n,a) ll n;cin>>n;vector<ll>a(n);rep(i,0,n)cin>>a[i]
#define vecrep(n,a,type) vector<type>a(n);rep(i,0,n)cin>>a[i]
#define lcm(a,b) (a/__gcd(a, b)*b)
#define range(a) (a).begin(),(a).end() 
#define pb push_back
#define mp make_pair
#define nnn "\n"
#define spa " "
using p = pair<ll, string>;
using garph = vector<vector<ll>>;
const int inf = 2147483647;//2*10^9
const ll INF = 9223372036854775807;//9*10^18

signed main (){
    int n;cin>>n;
    map<int,int>m{};
    rep(i,1,n+1){
        int a = i;
        rep(j,2,n+1){
            while(a%j==0){
                m[j]++;
                a/=j;
            }
        }
    }
    int ans = 1;
    for(auto i:m){
        ans=(ans*(i.second+1))%1000000007;
    }
    cout<<ans<<nnn;
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
#include<string>
using namespace std;
int main() {
	int n;
	string s;
	cin >> n;
	cin >> s;
	int a[7][4] = { 0 }, b[7][4] = { 0 }, p[1004] = { 0 };
	for (int i = 0; i < 7; i++) {
		if (i >= 3) {
			a[i][0] = 1;
			b[i][0] = 1;
		}
		if (i == 1 || i == 2 || i == 5 || i == 6) {
			a[i][1] = 1;
			b[i][1] = 1;
		}
		if (i == 0 || i == 2 || i == 4 || i == 6) {
			a[i][2] = 1;
			b[i][2] = 1;
		}

	}

	for (int i = 0; i < n; i++){
		if (s[i] == 'J') {
			p[i] = 0;
		}
		else if (s[i] == 'O') {
			p[i] = 1;
		}
		else {
			p[i] = 2;
		}
		/*cout<< i << "(day)" << p[i] << endl;*/
	}

	for (int i = 0; i < 7; i++) {
		if (a[i][0] == 1 && a[i][p[0]] == 1) {
			a[i][3] = 1;
		}
		/*cout << "j " << i << " baainokazu " << a[i][3] << endl;*/
	}
	for (int i = 1; i < n; i++) {
		for (int j = 0; j < 7; j++) {
			for (int k = 0; k < 7; k++) {
				for (int l = 0; l < 3; l++) {

					if (a[j][l] == b[k][l] && a[j][l] == 1) {
						if (a[j][p[i - 1]] == 1 && b[k][p[i]] == 1){
							if (a[j][3] != 0){
								/*cout << j << " " << l << endl;*/
								b[k][3] += a[j][3];
								if (b[k][3] >= 10007) {
									b[k][3] = b[k][3] % 10007;
								}


								break;
							}
						}

					}

				}


			}
			for (int d = 0; d < 7; d++) {

				/*cout << "j " << j << "d" << d << " baainokazu " << b[d][3] << endl;*/
			}
		}
		for (int e = 0; e < 7; e++) {
			a[e][3] = b[e][3];
			/*cout << "saishuu" << a[e][3] << endl;*/
			b[e][3] = 0;
			/*cout << b[e][3] << endl;*/
		}
	}
	int out = 0;
	for (int i = 0; i < 7; i++) {
		/*cout << a[i][3] << endl;*/
		out += a[i][3];
		/*cout << " " << out << endl;*/

		if (out >= 10007) {
			out = out % 10007;
		}
	}
	cout << out << endl;
	return 0;
}

Measured memory_bytes: 3152
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (int) n; i++)
using ll = long long;
template <class T>
using vt = vector<T>;
using vvi = vector<vt<int>>;

int main(){
  /*****************
      うわぁ^~ん
  ******************/

  int X;
  cin >> X;
  int k = X;
  int tmp;
  rep(i,X+1){
    if(k - i >= 0){
      k -= i;
      tmp = i;
    }
  }


  cout << (k == 0 ? tmp : tmp + 1) << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
/* run this program using the console pauser or add your own getch, system("pause") or input loop */

int main(int argc, char** argv) {
	char s[12];
	cin>>s;
	for(int i=0;i<12;i++){
		cout<<s[i];
		if(i==3){
			cout<<" ";
		}
	}
	cout<<"\n";
	return 0;
}

Measured memory_bytes: 256
class Union_Find:
  def __init__(self,n=0):
    self.vertices=n
    self.mother=[-1 for i in range(self.vertices)]
    self.size_temp=[1 for i in range(self.vertices)]
  
  def root(self,x):
    normalize_v=[]
    while x!=-1:
      normalize_v.append(x)
      y=x
      x=self.mother[x]
    for i in normalize_v[:-1]:
      self.mother[i]=y
    return y
  
  def union(self,x,y):
    root_x=self.root(x)
    root_y=self.root(y)
    if root_x!=root_y:
      self.mother[root_x]=root_y
      self.size_temp[root_y]+=self.size_temp[root_x]
  
  def find(self,x,y):
    if self.root(x)==self.root(y):
      return True
    else:
      return False
  
  def size(self,x):
    return self.size_temp[self.root(x)]


n,m=map(int,input().split())
uf=Union_Find(n)
for i in range(m):
  x,y,z=map(int,input().split())
  x-=1
  y-=1
  uf.union(x,y)

c=0
for i in range(n):
  c+=i==uf.root(i)
print(c)

Measured memory_bytes: 84928
def main():
    N = int(input())
    # Nが奇数(2 * M + 1)
    #    ノード n と N - n の間に枝が無く、それ以外のすべての枝があるグラフでOK。
    # Nが偶数(2 * M)
    #    ノード n と N + 1 - n の間に枝が無く、それ以外のすべての枝があるグラフでOK。
    # 両ケースとも、枝は N * (N - 1) // 2 - M = N * (N - 1) // 2 - N // 2 本。
    edges = list()
    if N % 2 == 1:
        for i in range(1, N):
            for j in range(i + 1, N + 1):
                if i + j != N:
                    edges.append((i, j))
    else:
        for i in range(1, N):
            for j in range(i + 1, N + 1):
                if i + j != N + 1:
                    edges.append((i, j))
    print(len(edges))
    for e in edges:
        print('{} {}'.format(e[0], e[1]))


if __name__ == '__main__':
    main()

Measured memory_bytes: 9460
#include<bits/stdc++.h>
#define for0(n) for(int i=0; i<n; i++)
#define _int64 long long int
using namespace std;
const int N = 3100;
_int64 dp[N][N];

_int64 max_diff(int i, int j, const _int64 arr[]){
    if(dp[i][j]!= -1)
        return dp[i][j];
    if(i==j)
        return dp[i][j] = arr[i];
    else if(i > j)
        return dp[i][j] = 0;
    return dp[i][j] = max(arr[i]-max_diff(i+1, j, arr), arr[j]-max_diff(i, j-1, arr));
}

int main(){
    memset(dp, -1, sizeof dp);
    int n;
    cin >> n;
    _int64 arr[N];
    for0(n) cin >> arr[i];
    cout << max_diff(0, n-1, arr) << endl;
}


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


unordered_map<long long, long long> m;
int main() {
	int n;
	cin >> n;
	vector<long long> v;
	for (int i = 0;i < n;i++) {
		long long x;
		cin >> x;
		v.push_back(x);
		m[x]++;
	}
	long long ans = 0;
	for (auto i : m) {
		ans = ans + (i.second * (i.second - 1)) / 2;

	}
	for (int i = 0;i < n;i++) {
		cout << ans - m[v[i]] + 1<<endl;

	}
}

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

int sumofdigit(int n){
  int sum = 0;
  while(n > 0){
    sum += n % 10;
    n /= 10;
  }
  return sum;
}

int main(){
  int N,A,B;
  cin >> N >> A >> B;
  int total = 0;
  for(int i = 1;i <= N;i++){
    int sum = sumofdigit(i);
    if(sum >= A && sum <= B){
      total += i;
    }
  }
  cout << total << endl;
}

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

using namespace std;

#define ll long long int 
#define F first
#define S second
#define pb push_back

const ll N = 1e5 + 5;
const ll MOD = 1e9 + 7;
const ll oo = 1e9;
int n, k;
vector <int> all;
ll dp[2][2 * N], f[2 * N];
int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> k;
    for (int i = 1; i * i <= n; i++){
        all.pb(i);
        if (i * i == n) continue;
        all.pb(n / i);
    }
    sort(all.begin(), all.end());
    int sz = all.size();
    for (int i = 0; i < sz; i++){
        if (i == 0){
            dp[1][i] = 1;
            f[i] = 1;
        }
        else{
            dp[1][i] = all[i] - all[i - 1];
            f[i] = all[i] - all[i - 1];
        }
    }
    for (int i = 2; i <= k; i++){
        ll sum = 0;
        for (int j = 0; j < sz; j++){
            dp[0][j] = dp[1][j];
            dp[1][j] = 0;
            sum = (sum + dp[0][j]) % MOD;
        }
        int p = sz - 1;
        for (int j = 0; j < sz; j++){
            dp[1][j] = (sum * f[j]) % MOD;
            sum = ((sum - dp[0][p]) % MOD + MOD) % MOD;
            p --;
        }
    }
    ll ans = 0;
    for (int i = 0; i < sz; i++){
        ans = (ans + dp[1][i]) % MOD;
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 5124
S = input()
if len(S) % 2 == 0:
    if S == "hi":
        print("Yes")
    elif S == "hihi":
        print("Yes")
    elif S == "hihihi":
        print("Yes")
    elif S == "hihihihi":
        print("Yes")
    elif S == "hihihihihi":
        print("Yes")
    else:
        print("No")
else:
    print("No")

Measured memory_bytes: 3060
#include <cmath>
#include <string>
#include <iostream>
using namespace std;
long long goods[100000];

bool isgood(long long n)
{

    long long a = n;
    int b;
    while (a != 0) {
        b = a % 10;
        a = a / 10;
        if (b != 2 && b != 8) {
            return false;
        }
    }
    return true;
}
int ma(long long n, int mi, int nowma)
{
    if (n == 1)
        return 0;
    if (n % 2 != 0)
        return -1;
    int mama = int(pow(n, 1.0 / nowma));
    long long g = 2;
    int i = mi;
    int mamama = -1;
    if (isgood(n))
        mamama = 1;
    while (g < mama + 3) {
        if (n % g == 0) {
            long long k = n / g;
            int newnowma = 2;
            if (mamama > 2)
                newnowma = mamama;
            if (newnowma < nowma - 1)
                newnowma = nowma - 1;
            int tma = ma(k, i, newnowma);
            int t = tma != -1 ? tma + 1 : -1;
            if (t > mamama)
                mamama = t;
        }
        i++;
        g = goods[i];
    }
    return mamama;
}
int main()
{
    goods[0] = 2;
    goods[1] = 8;
    int k = 2;
    for (int i = 0; i < 9; i++) {
        int tmp = k;
        for (int j = 0; j <= tmp; j++) {
            long long g = goods[j];
            goods[k] = 10 * g + 2;
            k++;
            goods[k] = 10 * g + 8;
            k++;
        }
    }
    long long N;
    cin >> N;
    if (N == 1) {
        cout << -1 << endl;
    } else {
        cout << ma(N, 0, 2) << endl;
    }
}

Measured memory_bytes: 3728
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<cstdlib>
#include<queue>

using namespace std;

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

int main(){
    long int n, m;
    cin >> n >> m;
    if (n >= m / 2){
        cout << (m / 2) << endl;
    }else{
        long int num = n * 2 + m;
        cout << num / 4 << endl;
    }
    
}


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

using namespace std;
#define sf(n) scanf("%d", &n)
#define pd(n) printf("%.12lf", n)
#define pf(n) printf("%d", n)
#define p() printf("\n")
#define ps() printf(" ")
#define ll long long
#define ull unsigned long long
#define MAX 1e9
#define mod 1000 * 1000 * 100 + 7
#define pi 3.1415926536
#define ex 1e18
#define dbl 2e09
#define qu(q) queue<int> q
#define pqu(q) priority_queue<int> q
#define len(s) s.length()
#define sz(x) int(x.size())
#define pb(x) push_back(x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()

int dx[4]={0,0,1,-1};
int dy[4]={-1,1,0,0};
int a[1005][1005];
vector<pair<int,int>>v;

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


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

#define LL long long
#define VI vector<int>
#define VVI vector<vector<int>>
#define VVVI vector<vector<vector<int>>>
#define VL vector<LL>
#define VVL vector<vector<LL>>
#define VVVL vector<vector<vector<LL>>>
#define VB vector<bool>
#define FOR(i,a,b) for(int i= (a); i<((int)b); ++i)
#define RFOR(i,a) for(int i=(a); i >= 0; --i)
#define FOE(i,a) for(auto i : a)
#define ALL(c) (c).begin(), (c).end()
#define RALL(c) (c).rbegin(), (c).rend()
#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v,x) (std::find(v.begin(), v.end(), x) != v.end())
#define BIT(n) (1LL<<(n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());
#define EPS 1e-14

template<class T> T ceil(T a, T b) { return (a + b - 1) / b; }
template<class T> void print(T x) { std::cout << x << std::endl; }

const std::string YES = "YES", Yes = "Yes", NO = "NO", No = "No";
const std::vector<int> dy = { 0, -1, 0, 1 }, dx = { 1, 0, -1, 0 };    // 4近傍（右, 下, 左, 上）

using namespace std;

const int MOD = 10000;

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

    int N, K;
    cin >> N >> K;
    map<int, int> m;
    FOR(i, 0, K) {
        int a, b;
        cin >> a >> b;
        m[a] = b;
    }

    VVVL dp(N + 1, VVL(4, VL(4, 0)));
    if (m[1]) {
        dp[1][0][m[1]] = 1;
    }
    else {
        dp[1][0][1] = 1;
        dp[1][0][2] = 1;
        dp[1][0][3] = 1;
    }

    FOR(i, 1, N) {
        FOR(j, 0, 4) {
            FOR(k, 0, 4) {

                if (m[i + 1]) {
                    if (j == k and k == m[i + 1]) {
                    }
                    else {
                        (dp[i + 1][k][m[i + 1]] += dp[i][j][k]) %= MOD;
                    }
                    continue;
                }

                if (j == k) {
                    if (j == 1) {
                        (dp[i + 1][k][2] += dp[i][j][k]) %= MOD;
                        (dp[i + 1][k][3] += dp[i][j][k]) %= MOD;
                    }
                    else if (j == 2) {
                        (dp[i + 1][k][1] += dp[i][j][k]) %= MOD;
                        (dp[i + 1][k][3] += dp[i][j][k]) %= MOD;
                    }
                    else if (j == 3) {
                        (dp[i + 1][k][1] += dp[i][j][k]) %= MOD;
                        (dp[i + 1][k][2] += dp[i][j][k]) %= MOD;
                    }

                }
                else {
                    (dp[i + 1][k][1] += dp[i][j][k]) %= MOD;
                    (dp[i + 1][k][2] += dp[i][j][k]) %= MOD;
                    (dp[i + 1][k][3] += dp[i][j][k]) %= MOD;
                }
            }
        }
    }

    LL ans = 0;
    FOR(j, 0, 4) {
        FOR(k, 0, 4) {
            (ans += dp[N][j][k]) %= MOD;
        }
    }
    print(ans % MOD);
}




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

int main() {
  int x, y, point = 0;
  cin >> x >> y;
  if (x == 1) {
    point += 300000;
  }
  else if (x == 2) {
    point += 200000;
  }
  else if (x == 3) {
    point += 100000;
  }
  if (y== 1) {
    point += 300000;
  }
  else if (y ==2) {
    point += 200000;
  }
  else if (y ==3) {
    point += 100000;
  }
  if (x * y == 1) {
    point += 400000;
  }
  cout << point << endl;
}

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

int main(){
  int n,m,x;cin>>n>>m>>x;
  int u=0,b=0;
  for(int i=0;i<m;i++){
    int c;cin>>c;
    if(c>x)u++;
    else b++;
  }
  cout<<min(u,b)<<endl;
}

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

#define endl '\n'
#define lfs cout<<fixed<<setprecision(10)
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define fi first
#define se second
#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define rep(i,n,m) for(ll i = (n); i < (ll)(m); i++)
#define rrep(i,n,m) for(ll i = (m) - 1; i >= (ll)(n); i--)
using ll = long long;
using ld = long double;
const ll MOD1 = 1e9+7;
const ll MOD9 = 998244353;
const ll INF = 1e18;
using P = pair<ll, ll>;
template<typename T>
bool chmin(T &a,T b){if(a>b){a=b;return true;}else return false;}
template<typename T>
bool chmax(T &a,T b){if(a<b){a=b;return true;}else return false;}
ll median(ll a,ll b, ll c){return a+b+c-max({a,b,c})-min({a,b,c});}
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
template<typename T1,typename T2>
void ans(bool x,T1 y,T2 z){if(x)cout<<y<<endl;else cout<<z<<endl;}  
template<typename T>
void debug(vector<vector<T>>&v,ll h,ll w){for(ll i=0;i<h;i++)
{cout<<v[i][0];for(ll j=1;j<w;j++)cout spa v[i][j];cout<<endl;}};
void debug(vector<string>&v,ll h,ll w){for(ll i=0;i<h;i++)
{for(ll j=0;j<w;j++)cout<<v[i][j];cout<<endl;}};
template<typename T>
void debug(vector<T>&v,ll n){if(n!=0)cout<<v[0];
for(ll i=1;i<n;i++)cout spa v[i];cout<<endl;};
template<typename T>
vector<vector<T>>vec(ll x, ll y, T w){
  vector<vector<T>>v(x,vector<T>(y,w));return v;}
ll gcd(ll x,ll y){ll r;while(y!=0&&(r=x%y)!=0){x=y;y=r;}return y==0?x:y;}
vector<ll>dx={1,0,-1,0,1,1,-1,-1};
vector<ll>dy={0,1,0,-1,1,-1,1,-1};
template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
  return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}
ostream &operator<<(ostream &os, pair<ll, ll>&p){
  return os << p.first << " " << p.second;
}  
int main(){
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  ll res=0,buf=0;
  bool judge = true;
  ll n,m;cin>>n>>m;
  ll mi=INF,mx=-INF;
  rep(i,0,m){
    ll l,r;cin>>l>>r;r--;l--;
    chmax(mx,l);
    chmin(mi,r);
  }
  cout<<max(0LL,mi-mx+1)<<endl;
  return 0;
}

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

#define foreach(i,v) for(auto&& i: v)
#define all(x) (x).begin(), (x).end()

typedef std::vector< std::string > VS;
typedef std::vector<int> VI;
typedef long long ll;

template <class C> C& mini(C& a, C b) { if (b < a) a = b; return a; }
template <class C> C& maxi(C& a, C b) { if (a < b) a = b; return a; }

using namespace std;

ll solve(const VI& A) {
	int N = A.size();
	ll r = 0;
	int have = 0;

	for (int i = N-1; i >= 0; i--) {
		if (A[i] < have)
			return -1;
		else if (A[i] == have)
			have = max(0, have-1);
		else {
			if (A[i] > i)
				return -1;
			have = A[i] - 1;
			r += A[i];
		}
	}
	return r;
}

int main(int argc, const char* argv[]) {
	int N;
	scanf("%d", &N);
	VI A(N);
	foreach (a, A)
		scanf("%d", &a);
	printf("%lld\n", solve(A));
	return 0;
}


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

int main() {
    vector<int> v(3);
    for(auto& d : v)cin >> d;
    sort(v.begin(), v.end());

    for(auto ite = v.begin(); ite != v.end(); ite++){
        cout << *ite;
        if(ite!=v.end()-1) cout << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 3112
S = list(input())
A = int("".join(S[0:2]))
B = int("".join(S[2:4]))

def isMonth(num):
    if 1<= num <= 12:
        return True
    else:
        return False

if isMonth(A) and isMonth(B):
    print("AMBIGUOUS")
elif isMonth(A) and not isMonth(B):
    print("MMYY")
elif not isMonth(A) and isMonth(B):
    print("YYMM")
else:
    print("NA")
    


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
#include<string>
#include<fstream>

#define SIZE 9

using namespace std;

int main(){
	int step[31]={0};
	int n;
	step[0] = 1;
	step[1] = 1;
	step[2] = 2;
	for(int i=3;i<=30;i++){
		step[i]=step[i-3]+step[i-2]+step[i-1];
	}
	for(int i=0;i<=30;i++){
		step[i]/=10;
	}
	while(cin>>n,n){
		if(step[n]!=0 && step[n]%365==0){
			cout<<step[n]/365<<endl;
		}else{
			cout<<step[n]/365+1<<endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1160
#include<iostream>

using namespace std;

int main() {
	int N, K;
	int Q = 0;
	cin >> N >> K;

	for (int i = 0; i < N; i++) {
		int h;
		cin >> h;

		if (h >= K) {
			Q++;
		}
	}

	cout << Q << endl;

	return 0;
}

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

int main() {
  int n;
  cin >> n;
  int min, max, sum;
  
  int i;
  for(i=0; i<n; i++){
    cin >> min >> max;
    sum += max - min + 1;
  }
  
  cout << sum << endl;
  
  return 0;
  
}


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

using  namespace std;
const int maxn = 2e5+2;
const int mod = 1e9+7;
const int inf = 1e9;

typedef long long II;

int n;
int arr[maxn], dp[maxn];

int solve_dp (int pos){
    if (pos > n){
        return inf;
    }

    if(pos == n - 1){
        return 0;
    }

    if (dp[pos] != -1)
    {
        return dp[pos];
    }

    int ans = inf;

    ans = min(ans, solve_dp(pos + 1)+abs(arr[pos + 1] - arr[pos])); 
    ans = min(ans, solve_dp(pos + 2)+abs(arr[pos + 2] - arr[pos]));

    return dp[pos] = ans;
}

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

    cin >> n;

    for (int i = 0; i < n; i++)
    {
        cin >> arr[i];
    }

    memset(dp,-1,sizeof dp);

    cout << solve_dp(0) << "\n";
    
}

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

const long long mod = 1e9 + 7;

using ll = long long;
using pii  = pair<int, int>;
using pll = pair<ll, ll>;
#define ull unsigned long long
#define ld long double
#define vi vector<int>
#define vll vector<ll>
#define vc vector<char>
#define vs vector<string>
#define vpii vector<pii>
#define vpll vector<pll>

#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; i++)
#define rep1(i, n) for (int i = 1, i##_len = (n); i <= i##_len; i++)
#define repr(i, n) for (int i = ((int)(n)-1); i >= 0; i--)
#define rep1r(i, n) for (int i = ((int)(n)); i >= 1; i--)

#define sz(x) ((int)(x).size())
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

#define SORT(v, n) sort(v, v + n);
#define VSORT(v) sort(v.begin(), v.end());
#define RSORT(x) sort(rall(x));
#define pb push_back
#define mp make_pair

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

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

int main(){
    int n, w;
    cin >> n >> w;
    vi wi(n), v(n);
    rep(i, n) cin >> wi[i] >> v[i];
    vector<vll> dp(n+5, vll(2e5+5, INF));
    dp[0][0] = 0;
    rep(i, n) rep(j, 1e5+1) {
        dp[i+1][j+v[i]] = min(dp[i][j+v[i]], dp[i][j]+wi[i]);
        dp[i+1][j] = min(dp[i+1][j], dp[i][j]);
    }
    int ans = 0;
    rep(i, 1e5+1) if (dp[n][i] <= w) ans = max(ans, i);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 168944
import sys
from collections import defaultdict

sys.setrecursionlimit(10 ** 7)
input = sys.stdin.readline
f_inf = float('inf')
mod = 10 ** 9 + 7


def resolve():
    n = int(input())
    A = [int(input()) for _ in range(n)]
    A_S = sorted(A)
    IDX = defaultdict(int)
    for idx, a in enumerate(A_S):
        IDX[a] = idx + 1

    res = 0
    for i in range(n):
        if IDX[A[i]] % 2 != (i + 1) % 2:
            res += 1
    print(res // 2)


if __name__ == '__main__':
    resolve()


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

#define count_ones __builtin_popcountl
typedef long long ll;
using namespace std;

int main() {
    ios::sync_with_stdio(false);

    int n;
    cin >> n;

    vector<vector<pair<int, int>>> inp(n, vector<pair<int, int>>());

    for (int i = 0; i < n; ++i) {
        int k;
        cin >> k;
        for (int j = 0; j < k; ++j) {
            int x, y;
            cin>>x >> y;
            x--;
            inp[i].push_back({x, y});
        }
    }

    int ans = 0;
    for (int m = 0; m < (1 << n); ++m) {
        bool check = true;
        for (int i = 0; i < n && check; ++i) {
            if ((m >> i) & 1) {
                for (auto p : inp[i]) {
                    if (((m >> p.first) & 1) != p.second) {
                        check = false;
                        break;
                    }
                }
            }
        }
        if (check) {
            ans = max(ans, count_ones(m));
        }
    }

    cout << ans;

    return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<vector>
#include<queue>
#include<map>
#include<functional>
#include<algorithm>
#define INF (1<<28)
using namespace std;

int pass[3001][3001], maxpass[3001][3001];
int saitan[3001], ans;
int n, m, k;
priority_queue<pair<int, int> , vector<pair<int, int> >,greater<pair<int, int> > > que;
vector<int> neib[3001];



int main(){
  scanf("%d%d%d", &n, &m, &k);
  fill(saitan, saitan + 3001, INF);
  for(int i = 0;i < m;i++){
    int a, b, l;
    scanf("%d%d%d", &a, &b, &l);
    neib[a].push_back(b);
    neib[b].push_back(a);
    pass[a][b] = pass[b][a] = l;
  }
  for(int i = 0;i < k;i++){
    int s;
    scanf("%d", &s);
    saitan[s] = 0;
    que.push(make_pair(0, s));
    saitan[s] = 0;
  }
  while(!que.empty()){
    pair<int, int> tmp = que.top(); que.pop();
    if(saitan[tmp.second] < tmp.first)continue;
    for(int i = 0;i < neib[tmp.second].size();i++){
      int from = tmp.second;
      int to = neib[from][i];
      if(saitan[to] > saitan[from] + pass[from][to]){
	saitan[to] = saitan[from] + pass[from][to];
	que.push(make_pair(saitan[to], to));
      }    
    }    
  }
  for(int i = 1;i <= n;i++){
    for(int j = 0;j < neib[i].size();j++){
      int to = neib[i][j];
      ans = max(ans, (1 + saitan[i] + saitan[to] + pass[i][to]) / 2);
    }
  }
  printf("%d\n", ans);
  return 0;
}

Measured memory_bytes: 38280
using System;
using System.Collections.Generic;
using System.Linq;
using System.Numerics;
using System.Runtime.ExceptionServices;
using System.Security.Cryptography.X509Certificates;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            var DTS = ReadInts();
            var D = DTS[0];
            var T = DTS[1];
            var S = DTS[2];

            if (D <= T * S)
            {
                WriteLine("Yes");
            }
            else
            {
                WriteLine("No");
            }
        }

        private static string Read() { return ReadLine(); }
        private static string[] Reads() { return (Read().Split()); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


Measured memory_bytes: 27484
# Reference: https://note.nkmk.me/python-union-find/
class UnionFind:
    # if x is root: self.parents[x] = -(the number of the group nodes)
    # else: self.parents[x] = the parent of x
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n

    # return the parent of x
    def find(self, x):
        history = []
        while self.parents[x] >= 0:
            history.append(x)
            x = self.parents[x]
        for node in history:
            self.parents[node] = x
        return x

    # merge the group of x and the group of y
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

    # return the size of the group of x
    def size(self, x):
        return -self.parents[self.find(x)]

    # return whether x and y in a same group
    def same(self, x, y):
        return self.find(x) == self.find(y)

    # return [all nodes which is in the group of x]
    # O(n)
    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    # return [all roots]
    # O(n)
    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    # return {root: members of the group}
    # O(n * n)
    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

from bisect import bisect
from sys import stdin
input = stdin.buffer.readline

def main():
    n = int(input())

    l = [0] * n
    for i in range(n):
        x, y = map(int, input().split())
        l[x-1] = (y - 1, i)

    # iで管理
    uf = UnionFind(n)
    roots = []

    for y, i in l:
        if len(roots) == 0 or -roots[-1][0] > y:
            roots.append((-y, i))
        else:
            ind = bisect(roots, (-y, i))
            new_y = roots[-1][0]
            for old_y, old_i in roots[ind:]:
                uf.union(i, old_i)
            roots = roots[:ind]
            roots.append((new_y, i))

    for i in range(n):
        print(uf.size(i))

main()

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

using namespace std;

#define DUMP(x) std::cout << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()

using ll = long long;
using vint = vector<int>;

void Main() {
    int a, b, c;
    cin >> a >> b >> c;

    int ans = c - (a - b);
    ans < 0 ? cout << 0 << endl : cout << ans << endl;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}


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

int main() {
  string s;
  cin >> s;
  int k = s.size();
  bool flag = 1;
  if (k==1) {
    cout << s << endl;
    return 0;
  }
  for (int i=1; i<k; i++) {
    if (s[i] != '9') {
      flag = false;
    }
  }
  int top = (s[0]-'0');
  if (flag) {
     cout << top + 9 * (k-1) << endl;
  } 
  else {
    cout << top - 1 + 9 * (k-1) << endl;
  }
}

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

int main(){
  int H, W;
  while(cin>> H >> W){
    if(H==0 && W==0)break;
    else{
      for(int i=0; i<H; i++){
	if(i%2==1){
	  for(int j=0; j<W; j++){
	    if(j%2==1)
	      cout << "#";
	    else
	      cout << ".";
	  }
	  cout << endl;
	}
	else{
	  for(int j=0; j<W; j++){
	    if(j%2==1)
	      cout << ".";
	    else
	      cout << "#";
	  }
	  cout << endl;
	}
	
      }
      cout << endl;
    }
  }
  return 0;
}

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

string alp = "zabcdefghijklmnopqrstuvwxy";

int main()
{
    
    ll n;
    cin >> n;
    string ans;
    while (n > 0) {
        int amari = n % 26;
        ans += alp[amari];
        if (n % 26 == 0) {
            n /= 26;
            n--;
        } else n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
object Main extends App {
  val sr = new StdinReader
  val h, w, d = sr.nextInt
  val table: Map[Int, (Int, Int)] = (for {
        y <- 0 until h
        x <- 0 until w
      } yield sr.nextInt -> (x, y)).toMap

  val tbl = new Array[Int](h * w + 1)
  (1 to d).flatMap{dd =>
    ((dd + d) to (h * w) by d).map {p => 
      val lPos = table(p - d)
      val rPos = table(p)
      val mp = Math.abs(lPos._1 - rPos._1) + Math.abs(lPos._2 - rPos._2)
      tbl(p) = mp + tbl(p - d)
    }
  }

  println(
    (1 to sr.nextInt).map{i =>
      val l, r = sr.nextInt
      tbl(r) - tbl(l)
    }.mkString("\n"))
}


class StdinReader {
  val is = System.in
  val buffer = new Array[Byte](1024 * 1024)
  var size = 0
  var pos = 0

  private def readByte: Byte = {
    if (pos >= size) {
      pos = 0;
      size = is.read(buffer);
    }
    if (size < 0) -1
    else {
      val ret = buffer(pos)
      pos += 1
      ret
    }
  }

  // support single byte char only
  def next: String = {
    val sb = new StringBuilder
    var reading = false
    var completed = false
    while(!completed) {
      val b = readByte

      if ('!' <= b && b <= '~') {
        sb.append(b.asInstanceOf[Char])
        reading = true
      } else {
        if (reading) completed = true
      }
    }
    sb.toString
  }

  def nextInt: Int = {
    @scala.annotation.tailrec
    def r(i: Int, reading: Boolean): Int = {
      readByte match {
        case '-' => r(i * -1, true)
        case b if '0' <= b && b <= '9' => r(i * 10 + (b - '0'), true)
        case _ => if (reading) i else r(i, false)
      }
    }
    r(0, false)
  }
}

Measured memory_bytes: 82120
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
#include<string>
#include<queue>
#include<map>
#include<stack>
#include<set>
using namespace std;
int main(){
	int k,s,ans=0;
	cin >> k >> s;
	for(int i = 0;i <= k;i++){
		for(int j = 0;j <= k;j++){
			if(i+j+k>=s&&i+j<=s)ans++;
			}
		}
		cout << ans << endl;
	return 0;
	}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main() {
    int x;
    int c;
    c=0;
    while(1){
        c++;
        cin>>x;
        if(x==0){
            break;
        }
        cout<<"Case "<<c<<": "<<x<<endl;
    }
    return 0;
}


Measured memory_bytes: 3072
#include <stdio.h>
#include <string.h>
#include <algorithm>

using namespace std;

int main() {
    while (1) {
        int i;
        int n;
	int now = 0;
	int cards[10];
	int table = 0;

	memset(cards, '\x00', sizeof(cards));

        scanf("%d", &n);
        if (n == 0) return 0;

	for (i=0; i<100; i++) {
	    char c;

	    scanf(" %c", &c);

            if (c == 'S') {
                table += cards[now] + 1;
		cards[now] = 0;
	    } else if (c == 'M') {
		cards[now] += 1;
	    } else if (c == 'L') {
		cards[now] += table + 1;
		table = 0;
	    }

	    ++now;
	    now %= n;
	}

        sort(cards, cards + n);

	for (i=0; i<n; i++) {
	    printf("%d ", cards[i]);
	}

	printf("%d\n", table);
    }
}

Measured memory_bytes: 1044
unittest
{
	assert( [ "CSS", "CSR" ].parse.expand.solve == 2 );
	assert( [ "SSR", "SSR" ].parse.expand.solve == 3 );
	assert( [ "RRR", "SSS" ].parse.expand.solve == 0 );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto s = input.front.to!( dchar[] );
	input.popFront;
	auto t = input.front.to!( dchar[] );
	return tuple( s, t );
}

auto solve( dchar[] s, dchar[] t )
{
	auto ans = 0L;
	foreach( sc, tc; lockstep( s, t ) )
	{
		ans += ( sc == tc );
	}
	return ans;
}


Measured memory_bytes: 256
#include <stdio.h>
#define MAX 100005
#define N -1
struct Node{int p, l, r;};
struct Node T[MAX];

int n, D[MAX],H[MAX];
void setDepth(int x,int d){
  if(x==N)
    return;
  D[x]=d;
  setDepth(T[x].l,d+1);
  setDepth(T[x].r,d+1);
}

int setHeight(int x){
  int h1=0,h2=0;
  if(T[x].l!=N)
    h1=setHeight(T[x].l)+1;
  if(T[x].r!=N)
    h2=setHeight(T[x].r)+1;
  return H[x]=(h1 > h2 ? h1 : h2);
}

int getSibling(int x){
  if(T[x].p==N)
    return N;
  if(T[T[x].p].l!=x&&T[T[x].p].l!=N)
    return T[T[x].p].l;
  if(T[T[x].p].r!=x&&T[T[x].p].r!=N)
    return T[T[x].p].r;
  return N;
}

void print(int x){
  printf("node %d: ",x);
  printf("parent = %d, ",T[x].p);
  printf("sibling = %d, ",getSibling(x));
  int deg =0;
  if(T[x].l!=N)
    deg++;
  if(T[x].r!=N)
    deg++;
  printf("degree = %d, ",deg);
  printf("depth = %d, ",D[x]);
  printf("height = %d, ",H[x]);
  if(T[x].p==N){
    printf("root\n");
  }
  else if(T[x].l==N&&T[x].r==N){
    printf("leaf\n");
  }
  else{
    printf("internal node\n");
  }
}

int main(){
  int i,v,l,r,root=0;
  scanf("%d",&n);
  for(i=0;i<n;i++){
    T[i].p=N;
  }
  for(i=0;i<n;i++){
    scanf("%d%d%d",&v,&l,&r);
    T[v].l=l;
    T[v].r=r;
    if(l!=N)
      T[l].p=v;
    if(r!=N)
      T[r].p=v;
  }
  for(i=0;i<n;i++){
    if(T[i].p==N){
      root=i;
    }
  }
  setDepth(root,0);
  setHeight(root);
  for(i=0;i<n;i++){
    print(i);
  }
  return 0;
}
  

Measured memory_bytes: 624
digits = gets.chomp.split('').map(&:to_i)
 
if digits.length == 1 then
  puts digits[0]
  exit
end
 
length =digits.length - 1
max = (2**length) - 1
 
sum = (0..max).map {|n|
  sprintf('%0'+length.to_s+'b', n).split('')
}.map {|p|
  f = []
  (0..length + 1).each {|i|
    f.push digits[i]
 
    if i < length + 1 then
      f.push (p[i] == '1') ? '+' : '';
    end
  }
 
  fomula = f.reduce{|acc, c| acc.to_s + c.to_s}
 
  eval(fomula)
}.reduce(&:+)
 
puts sum

Measured memory_bytes: 2428
using System;
using System.Linq;
using System.Collections.Generic;
class ProgramC
    {
        static void Main(string[] args)
        {
            
            string input = Console.ReadLine();
            int n = int.Parse(input);
            
            var dic = new Dictionary<string, int>();
            long sum = 0;
            int count = 0;

            for(int i = 0;i < n;i++)
            {
                //var s = new string(Console.ReadLine().OrderBy(x => x).ToArray());
                //これで文字列に並べる
                string s = Console.ReadLine();
                string[] sub = new string[10];
                for(int j = 0;j < 10;j++)
                {
                    sub[j]= s.Substring(j,1);
                }
                Array.Sort(sub);
                string sa = sub[0] + sub[1] + sub[2] + sub[3] + sub[4] + sub[5] + sub[6] + sub[7] + sub[8] + sub[9];
                if(dic.ContainsKey(sa))
                {
                    sum += dic[sa];
                    dic[sa]++;
                }
                else
                {
                    dic.Add(sa, 1);
                }
            }

            Console.WriteLine(sum);
        }
    }

Measured memory_bytes: 31140
#include<stdio.h>
#include<string.h>
int main(void)
{
	int n,m,d,x[100][100],i,k,v,y,flg;
	char a[101];
	scanf("%d %d %d",&n,&m,&d);
	
	for(i=0;i<n;i++){
		scanf("%s",a);
		for(k=0;k<m;k++){
			x[i][k]=0;
			if(a[k]=='#') x[i][k]=1;
		}
	}
	y=0; 
	for(i=0;i<n;i++){
		for(k=0;k<m-(d-1);k++){
			flg=0;
			for(v=k;v<k+d;v++){
				if(x[i][v]==1){
					flg=1; break;
				}
			}
			if(flg==0) y++; 
		}
	}
	for(k=0;k<m;k++){
		for(i=0;i<n-(d-1);i++){
			flg=0;
			for(v=i;v<i+d;v++){
				if(x[v][k]==1){
					flg=1; break;
				}
			}
			if(flg==0) y++;
		}
	}
	printf("%d\n",y);
	return 0;
}

Measured memory_bytes: 2784
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define PRINT(v) for (auto x : (V)) cout <<x <<" " <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 1};
template<class T> struct edge { int from, to; T cost;};
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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }


int main() {
  int n,m; cin >>n >>m;
  priority_queue<int> pq;
  rep(i, n){ int a; cin >>a; pq.push(a); }
  rep(i, m){
    int a = pq.top(); pq.pop();
    pq.push(a/2);
  }
  ll res = 0;
  while (!pq.empty()){
    res += pq.top();
    pq.pop();
  }
  cout <<res <<endl;
}

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

#define repo(i,n) for (int i = 0; i < n; i++)
using namespace std;
using ll = long long;

int main(){
    ll K;
    ll N;
    cin >> K >> N;
    vector<ll> sa(N);
    vector<ll> A(N);
    ll sum =0;
    //     B
//     ll A;
    for(ll i = 0; i< N; i++){
        cin >> A[i];
        if(i != 0){
            sa[i-1] = A[i] - A[i-1]; 
        } 
    }
    sa[N-1] = K - A[N-1] + A[0];

//     repo(i,N){
//         cout << sa[i] << endl;
//     }    

    sort(sa.begin(),sa.end());
    for(ll i = 0;i  < N-1; i++ ){
        sum += sa[i];
    }
    cout << sum << endl;
    return 0;
}



Measured memory_bytes: 3328