akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Collections.Generic;
using System.Linq;

namespace ConsoleApp15
{
    class Class102
    {
        static void Main()
        {
            var NM = Console.ReadLine().Split();
            int N = int.Parse(NM[0]);
            int M = int.Parse(NM[1]);
            bool[] Table = new bool[N];
            int[] wa = new int[N];
            int WA = 0;
            for(int i = 0; i < M; i++)
            {
                var r = Console.ReadLine().Split();
                int p = int.Parse(r[0]);
                string S = r[1];
                if (!Table[p - 1])
                {
                    if (S == "WA") wa[p - 1]++;
                    else { Table[p - 1] = true; WA += wa[p - 1]; }
                }
            }
            int ac = Table.Count(x=>x==true);
            Console.WriteLine($"{ac} {WA}");
        }
    }
}


Measured memory_bytes: 17616
#include <stdio.h>

int main(void)
{
    int a, b;

    scanf("%d%d",&a,&b);

    if (a == 1) a+=13;
    if (b == 1) b+=13;

    if (a > b) {
        puts("Alice");
    } else if (a < b) {
        puts("Bob");
    } else {
        puts("Draw");
    }

    return 0;
}


Measured memory_bytes: 128
fun main() {
    val (h, w, k) = readLine()!!.split(" ").map { it.toInt() }
    val c = Array(h){""}
    for (i in 0 until h) {
        c[i]= readLine()!!
    }

    var count = 0
    for(a in 0 until 1.shl(h)) {
        for(b in 0 until 1.shl(w)) {
            var black = 0
            for(i in 0 until h) {
                for(j in 0 until w) {
                    if(a.and(1.shl(i)) != 0 && b.and(1.shl(j)) != 0 && c[i][j] == '#') {
                        black++
                    }
                }
            }
            if(black == k) count++
        }
    }

    println(count)

//    var n = 5
//    for(bit in 0 until 1.shl(n)) {
//        print("$bit: ")
//        for(i in 0 until n) {
//            if(bit.and(1.shl(i)) != 0) {
//                print("$i ")
//            }
//        }
//        println()
//    }
}

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

long long n, a, b;

int main() {
  scanf("%lld %lld %lld", &n, &a, &b);
  if (b - a & 1) {
    printf("%lld\n", min(a-1, n-b) + ((b-a+1) >> 1));
  } else printf("%lld\n", b-a >> 1);
  return 0;
}


Measured memory_bytes: 256
n = int(input())
heights = list(map(int, input().split()))

max_move = 0
move = 0
for i in range(1, n):
	if heights[i] <= heights[i-1]:
		move += 1
	else:
		max_move = max(max_move, move)
		move = 0
max_move = max(max_move, move)
print(max_move)

Measured memory_bytes: 63984
// https://atcoder.jp/contests/abc118/tasks/abc118_c
 
// http://ctylim.hatenablog.com/entry/2015/08/30/191553
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
 
#define ALL(a) (a).begin(), (a).end()
#define EACH(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define EXIST(s, e) ((s).find(e) != (s).end())
#define SORT(c) sort((c).begin(), (c).end())
#define RSORT(c) sort((c).rbegin(), (c).rend())
#define MAXINDEX(c) distance((c).begin(), max_element((c).begin(), (c).end()))
#define MININDEX(c) distance((c).begin(), min_element((c).begin(), (c).end()))
#define DEBUG(x) std::cerr << #x << " = " << (x) << " (" << __FILE__ << "::" << __LINE__ << ")" << std::endl;
#define ERROR(s) std::cerr << "Error::" << __FILE__ << "::" << __LINE__ << "::" << __FUNCTION__ << "::" << (s) << std::endl;
#define FOR(i, a, b) for (auto i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
 
 
#define repd(i, a, b) for (int i = (a); i < (b); i++)
#define rep(i, n) repd(i, 0, n)
typedef long long ll;
 
int inputValue(){
  int a;
  std::cin >> a;
  return a;
}
 
void inputArray(int *p, int a){
    rep(i, a){
        std::cin >> p[i];
        // scanf("%d",p+i);
    }
}
 
void inputVector(std::vector<int> *p, int a){
  rep(i, a){
    int input;
    // std::cin >> input;
    scanf("%d",&input);
    p->push_back(input);
  }
}
 
template <typename T>
void output(T a, int precision){
  if (precision > 0){
    std::cout << std::setprecision(precision) << a << "\n";
  }else{
    std::cout << a << "\n";
  }
}
 
using namespace std;
 
int gcd(int a,int b){
  while(1) {
    if(a < b) swap(a, b);
    if(!b) break;
    a %= b;
  }
  return a;
}
 
 
int main(int argc ,char **argv){
 
  int N = inputValue();
  vector <int> v;
  inputVector(&v, N);
 
  // cout << gcd(5,13) << endl;
  int d = 0;
  EACH(k, v) {
    d = gcd(d, *k);
  }
  cout << d << endl;
 
	return 0;
}



Measured memory_bytes: 892
N = int(input())
A = list(map(int, input().split()))
S = sum(A)

x1 = S - 2 * sum(A[1:N - 1:2])
xs = [x1]

for i in range(1, N):
    xs.append(2 * A[i - 1] - xs[i - 1])

print(' '.join(map(str, xs)))

Measured memory_bytes: 19096
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptor/reversed.hpp>
#include<boost/operators.hpp>
namespace adaptor = boost::adaptors;
template<class T>using p_queue = std::priority_queue<T, std::vector<T>, std::greater<>>;

void Main()
{
	int N, M;
	std::cin >> N >> M;
	std::vector<std::vector<int>> sw(M);
	std::vector<int> ps(M);
	for (auto& vec : sw)
	{
		int k;
		std::cin >> k;
		for (int j : boost::irange(0, k))
		{
			int s;
			std::cin >> s;
			vec.emplace_back(s - 1);
		}
	}
	for (auto& p : ps)
	{
		std::cin >> p;
	}
	std::vector<int> state(N);
	int count = 0;
	for (int i : boost::irange(0, 1 << N))
	{
		for (int k : boost::irange(0, N))
		{
			state[k] = (i & (1 << k)) != 0;
		}
		int t = 0;
		for (int j : boost::irange(0, M))
		{
			auto p = ps[j];
			auto&& vec = sw[j];
			int c = 0;
			for (auto index : vec)
			{
				c += state[index];
			}
			if (c % 2 == p)
			{
				++t;
			}
		}
		if (t == M)
		{
			++count;
		}
	}
	std::cout << count << std::endl;
}

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

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
#include <tuple>
#define mkp make_pair
#define mkt make_tuple
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
const ll MOD=998244353;

#define MAX_N 10000010
ll inv[MAX_N+10],fac[MAX_N+10],ifac[MAX_N+10];

void setComb(){
  inv[0]=1;inv[1]=1;fac[1]=1;ifac[1]=1;fac[0]=1;ifac[0]=1;
  for(int i=2;i<MAX_N;i++){
    inv[i]=(-MOD/i)*inv[MOD%i]%MOD;
    fac[i]=fac[i-1]*i%MOD;
    ifac[i]=ifac[i-1]*inv[i]%MOD;

    inv[i]=(inv[i]+MOD)%MOD;
    fac[i]=(fac[i]+MOD)%MOD;
    ifac[i]=(ifac[i]+MOD)%MOD;
  }
  return;
}

ll comb(ll n,ll k){
  if(n<k||n<0||k<0) return 0;
  else return ((fac[n]*ifac[k]%MOD*ifac[n-k]%MOD+MOD)%MOD);
}

ll hcomb(ll n,ll r){
  if(n==0&&r==0) return 1;
  else if(n<0||r<0) return 0;
  else return comb(n+r-1,r-1);
}


ll two[10000010];

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

  two[0]=1;
  for(int i=1;i<=N;i++) two[i]=two[i-1]*2%MOD;

  ll minus=0;
  for(int i=N/2+1;i<=N;i++){
      ll res=comb(N,i);
      res=res*two[N-i]%MOD;
      minus=(minus+res)%MOD;
  }
  minus=minus*2%MOD;

  ll ans=1;
  for(int i=1;i<=N;i++) ans=ans*3%MOD;

  ans=(ans-minus+MOD)%MOD;
  cout<<ans<<endl;

  return 0;
}


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


using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//math
//-------------------------------------------
template<class T> inline T sqr(T x) { return x*x; }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef long long LL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define EXISTch(s,c) ((((s).find_first_of(c)) != std::string::npos)? 1 : 0)//cがあれば1 if(1)
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  FOR(i,0,n)
#define loop(n) FOR(i,0,n)
#define rrep(i,a,b) for(int i=(a);i>=(b);--i)

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int INF = (int)1000000007;
const LL MOD = (LL)1000000007;//10^9+7
const LL INF2 = (LL)100000000000000000;//10^18

int main() {
	
	double r; cin >> r;

	cout << fixed;
	cout << setprecision(8) << PI*r*r << " " << 2 * PI*r << endl;
	return 0;
}


Measured memory_bytes: 3276
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
    int n,s;
    cin >> n >> s;
    for(int i=n-1;i>0;i--){
        cout << s-i << " ";
    }
    for(int i=0;i<n;i++){
        cout << s+i << " ";
    }
    return 0;
}


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


int main(){
	int s, w;
	cin >> s >> w;
	if (s <= w)cout << "unsafe" << endl;
	else cout << "safe" << endl;
	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int N = 1e5 + 1;
int a[N], ans, k;
vector<int> g[N];
int dfs(int v, int pr = -1)
{
    int h = 0;
    for (int i : g[v])
    {
        h = max(dfs(i, v), h);
    }
    h++;
    if (v == 1)
        return 0;
    if (h == k)
    {
        if (pr != 1)
            ans++;
        return 0;
    }
    else
    {
        return h;
    }
}
signed main()
{
#ifdef home
    freopen(".in", "r", stdin);
    freopen(".out", "w", stdout);
#else
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
#endif
    ios_base::sync_with_stdio(0);
    int n;
    cin >> n >> k;
    for (int i = 1; i <= n; i++)
    {
        cin >> a[i];
    }
    if (a[1] != 1)
    {
        a[1] = 1;
        ans++;
    }
    for (int i = 2; i <= n; i++)
    {
        g[a[i]].push_back(i);
    }
    dfs(1);
    cout << ans;
}

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

int main() {
  int N, cnt = 0;
  cin >> N;
  string S, T = "";
  cin >> S;
  for (int i = N - 1; i >= 0; i--) {
    if (S[i] == ')') {
      T += S[i];
      cnt++;
    } else {
      cnt--;
      if (cnt < 0) {
        T = ")" + T;
        cnt++;
      }
      T += S[i];
    }
  }

  for (int j = 0; j < cnt; j++) {
    T += '(';
  }
  reverse(T.begin(), T.end());
  cout << T << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int A,B,N;
    cin >> A >> B >> N;
    int count=0;
    for(int i=A; i<=B; i++)
    {
        if(i%N==0)
        count++;
    }
    cout << count << endl;
}

Measured memory_bytes: 3560
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int kosuu = sc.nextInt();
        int[] flower2 = new int[kosuu];
        for (int i = 0; i < kosuu; i++) {
            flower2[i] = sc.nextInt();
        }
        
        saiki(flower2);
        System.out.println(counter);
    }
    static int counter = 0;
        private static void saiki(int[] hikisuu){
            int[] hairetu;
            int min = Integer.MAX_VALUE;
            for (int k = 0; k < hikisuu.length; k++) {
                int v = hikisuu[k];
                if (v < min) {
                    min = v;
                }
            }
            counter += min;
            for(int h = 0;h < hikisuu.length;h++) {
                hikisuu[h] = hikisuu[h] - min;
            }
            int kioku = 0;
            for (int i = 0; i < hikisuu.length; i++) {
                if (hikisuu[i] == 0) {
                    if (kioku != i) {
                        hairetu = Arrays.copyOfRange(hikisuu, kioku, i);
                        saiki(hairetu);
                    }
                    kioku = i + 1;
                } 
            }
            if (kioku != hikisuu.length) {
                hairetu = Arrays.copyOfRange(hikisuu, kioku, hikisuu.length);
                saiki(hairetu);
            }

//            for(int j = 1; j < hairetu.length; j++){
//                saikihairetu[j] = hairetu[j] - min;
//                counter += min;
//            }
//            saiki(hairetu);
        }
        //System.out.println(counter);
    }

Measured memory_bytes: 23764
from itertools import permutations
N, C = map(int, input().split())
D = []
for i in range(C):
    D.append([int(i) for i in input().split()])
c = []
for i in range(N):
    c.append([int(i) for i in input().split()])

counter = {i: {} for i in range(3)}
for i in range(N):
    for j in range(N):
        m = (i+j) % 3
        color = c[i][j] - 1
        if counter[m].get(color) is None: counter[m][color] = 0
        counter[m][color] += 1

ans = float('inf')

for i,j,k in permutations(range(C), 3):
    tmp = 0
    for l in range(C):
        tmp += D[l][i] * counter[0].get(l, 0)
        tmp += D[l][j] * counter[1].get(l, 0)
        tmp += D[l][k] * counter[2].get(l, 0)
    ans = min(tmp, ans)

print(ans)

Measured memory_bytes: 5492
from collections import deque

H, W = map(int, input().split())
Ss = []
for _ in range(H):
  Ss.append(input())

mp = [[0]*W for _ in range(H)]
dxy = [[-1,0],[1,0],[0,-1],[0,1]]
lst = []

q = deque([])
num = 1
for i in range(H):
  for j in range(W):
    if mp[i][j] == 0:
      q.append((i,j))
      mp[i][j] = num
      dic = {'#':0, '.':0}
      while q:
        t = q.popleft()
        dic[Ss[t[0]][t[1]]] += 1
        for k in range(4):
          if t[0] + dxy[k][0] >= 0 and t[0] + dxy[k][0] < H \
             and t[1] + dxy[k][1] >= 0 and t[1] + dxy[k][1] < W \
             and Ss[t[0]][t[1]] != Ss[t[0]+dxy[k][0]][t[1]+dxy[k][1]]\
             and mp[t[0]+dxy[k][0]][t[1]+dxy[k][1]] == 0:
            
            mp[t[0]+dxy[k][0]][t[1]+dxy[k][1]] = num
            q.append((t[0]+dxy[k][0],t[1]+dxy[k][1]))
      lst.append(dic)
      num += 1

rlt = 0
for d in lst:
  rlt += d['#']*d['.']

print(rlt)

Measured memory_bytes: 121464
#include<cstdio>
#include<cstring>
#include<algorithm>
using namespace std;
char s[100005];
int main(){
	scanf("%s",s);
	int n=strlen(s);
	int ans=0;
	for(int i=1;i<n;i++)ans+=s[i]!=s[i-1];
	printf("%d",ans);
	return 0;
}


Measured memory_bytes: 384
s = input()
t = ''

i = 0

while True:
    if s == t:
        print('YES')
        exit();
    elif s[i:i+7] == 'dreamer' and s[i+7:i+8] != 'a':
        t += 'dreamer' 
        i += 7
    elif s[i:i+5] == 'dream':
        t += 'dream'
        i += 5
    elif s[i:i+6] == 'eraser':
        t += 'eraser'
        i += 6
    elif s[i:i+5] == 'erase':
        t += 'erase'
        i += 5
    else:
        print('NO')
        exit()


Measured memory_bytes: 9248
#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 N,M; cin>>N>>M;
    vector<int> l(N),r(N);
    REP(i,N)cin>>l[i]>>r[i];
    
    
    
    return 0;
}
*/

int main(){
    
    int N; cin>>N;
    vector<int> A(N);
    REP(i,N)cin>>A[i];
    
    map<int,int> cnt;
    REP(i,N){
        if(cnt.find(A[i])==cnt.end()){
            cnt[A[i]]=1;
        }else{
            cnt[A[i]]++;
        }
    }
    
    vector< pair<int,int> > p;
    for(auto itr=cnt.begin();itr!=cnt.end();itr++){
        p.push_back(make_pair(itr->second, itr->first));
    }
    
    int sum = 0;
    REP(i,p.size())sum += p[i].first-1;
    
    cout<<p.size()-sum%2<<endl;
    
    return 0;
}


Measured memory_bytes: 6520
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
#include <stack>
#define pi pair<int, int>
#define mkp make_pair
#define fi first
#define se second
#define N 202

using namespace std;

const int mod = 1e9 + 7;

struct edge{
	int to, nxt;
}e[N << 1];

int n, m, k, cnt, tot, num;
int fir[N], col[N], sze[N], szp[N], fac[N << 1], ifac[N << 1], dfn[N], low[N];

stack<pi> st;

void add(int ,int);
int gcd(int ,int);
int quick_pow(int ,int);
int C(int ,int);
void init();
void tarjan(int ,int);

int main(){
	scanf("%d%d%d", &n, &m, &k); init();
	for(int i = 1; i <= m; ++i){
		int u, v; scanf("%d%d", &u, &v);
		add(u, v); add(v, u);
	}
	for(int i = 1; i <= n; ++i)
		if(!dfn[i]) tarjan(i, 0);
	int ans = 1;
	for(int i = 1; i <= num; ++i){
		if(sze[i] == 1) ans = 1ll * ans * k % mod;
		else if(sze[i] == szp[i]){
			int tmp = 0;
			for(int j = 1; j <= sze[i]; ++j)
				(tmp += quick_pow(k, gcd(j, sze[i]))) %= mod;
			tmp = 1ll * tmp * quick_pow(sze[i], mod - 2) % mod;
			ans = 1ll * ans * tmp % mod;
		}
		else ans = 1ll * ans * C(sze[i] + k - 1, k - 1) % mod;
	}
	cout << ans << endl;
	return 0;
}

void init(){
	int lim = m + k; fac[0] = ifac[0] = 1;
	for(int i = 1; i <= lim; ++i)
		fac[i] = 1ll * fac[i - 1] * i % mod, ifac[i] = quick_pow(fac[i], mod - 2);
	return ;
}

int C(int x, int y){
	return 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}

int gcd(int x, int y){
	return !y ? x : gcd(y, x % y);
}

int quick_pow(int x, int y){
	int sum = 1;
	for(; y; y >>= 1, x = 1ll * x * x % mod)
		if(y & 1) sum = 1ll * sum * x % mod;
	return sum;
}

void add(int u, int v){
	e[++cnt] = (edge){v, fir[u]}; fir[u] = cnt;
	return ;
}

void tarjan(int u, int fa){
	dfn[u] = low[u] = ++tot;
	for(int i = fir[u]; i; i = e[i].nxt){
		int v = e[i].to; if(v == fa) continue;
		if(!dfn[v]){
			st.push(mkp(u, v)); tarjan(v, u);
			low[u] = min(low[u], low[v]);
			if(dfn[u] <= low[v]){
				int x, y; ++num;
				do{ 
					x = st.top().fi, y = st.top().se;
					++sze[num]; st.pop();
					if(col[x] != num) col[x] = num, ++szp[num];
					if(col[y] != num) col[y] = num, ++szp[num];
				}while(!st.empty() && (x != u || y != v));
			}
		}
		else if(dfn[v] < dfn[u]) st.push(mkp(u, v)), low[u] = min(low[u], dfn[v]);
	}
	return ;
}

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

#ifndef LOCAL_
#define fprintf if( false ) fprintf
#endif // LOCAL_
// #define dump() fprintf(stderr, "#%s.%d\n", __func__, __LINE__);
#define dumpl(x1) fprintf(stderr, "#%s.%d (%s) = (%ld)\n", __func__, __LINE__, #x1, x1);
#define dumpll(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%ld, %ld)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define dumplll(x1, x2, x3) fprintf(stderr, "#%s.%d (%s, %s, %s) = (%ld, %ld, %ld)\n", __func__, __LINE__, #x1, #x2, #x3, x1, x2, x3);
#define dumpd(x1) fprintf(stderr, "#%s.%d (%s) = (%lf)\n", __func__, __LINE__, #x1, x1);
#define dumpdd(x1, x2) fprintf(stderr, "#%s.%d (%s, %s) = (%lf, %lf)\n", __func__, __LINE__, #x1, #x2, x1, x2);
#define loop for(;;)
typedef std::vector<long> LI;

template<typename T> void scan1(T& x) { fprintf(stderr, "unknown type\n"); }
template<> void scan1(long& x) { if( scanf("%ld", &x) < 0 ) exit(0); }
template<> void scan1(std::string& x) { if( not ( std::cin >> x ) ) exit(0); }
void scan() {}
template<typename Head, typename... Tail>
void scan(Head& x, Tail&... xs) {
  scan1(x); scan(xs...);
}

typedef std::complex<double> P2;
using std::norm;
using std::real;
using std::conj;
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_A
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2376299#1
P2 projection(P2 p1, P2 p2, P2 p) {
   P2 t = p2 - p1;
   return p1+(t)/norm(t)*real((p-p1)*conj(t));
}
// http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_1_B
// http://judge.u-aizu.ac.jp/onlinejudge/review.jsp?rid=2376317#1
P2 refrection(P2 p1, P2 p2, P2 p) {
   P2 t = p2 - p1;
   return p1+conj((p-p1)/t)*t;
}
P2 cc(P2 p1, P2 p2, P2 p) {
   P2 t = p2 - p1;
   return (p-p1)/t;
}


struct Solver {
   Solver() { fprintf(stderr, "--------Solver begin--------\n"); }
   ~Solver() { fprintf(stderr, "--------Solver end--------\n"); }
   void solve() {
      long x1, y1, x2, y2; scan(x1, y1, x2, y2);
      long q; scan(q);
      for(long i = 0; i < q; ++i) {
         long x, y; scan(x, y);
         auto res = cc(P2(x1,y1), P2(x2, y2), P2(x,y));
         double eps = 1e-10;
         if( res.imag() > eps ) puts("COUNTER_CLOCKWISE");
         else if( res.imag() < -eps ) puts("CLOCKWISE");
         else if( res.real() < -eps ) puts("ONLINE_BACK");
         else if( -eps < res.real() and res.real() < 1.0+eps ) puts("ON_SEGMENT");
         else if( 1.0+eps < res.real() ) puts("ONLINE_FRONT");
         else puts("error");
      }
   }
};

int main() {
  loop std::unique_ptr<Solver>(new Solver())->solve();
}

Measured memory_bytes: 3156
import sys

readline = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = float('INF')
sys.setrecursionlimit(10 ** 5)


def main():
    n, k = map(int, readline().split())
    a = list(map(int, readline().split()))
    a.sort()

    print(sum(a[:k]))


if __name__ == '__main__':
    main()


Measured memory_bytes: 62288
#include"bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef vector<int> vi;

int main(void) {
	int a, b, c, d, k;
	cin >> a >> b >> c >> d >> k;

	int m = a * 60 + b;
	int n = c * 60 + d;

	cout << n - m - k << endl;
	
	return 0;
}

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

const int N = 1e5 + 10;
const int inf = INT_MAX;

#define ll long long
#define FOR(i,a,b) for(int i = a;i <= b;i++)
#define _FOR(i,a,b) for(int i = a;i >= b;i--)

template<typename T> void read(T &x)
{
    x = 0;int f = 1;
    char c = getchar();
    for(;!isdigit(c);c = getchar()) if(c == '-') f = -1;
    for(;isdigit(c);c = getchar()) x = x * 10 + c - '0';
    x *= f;
}

int n;
int a[60];
ll ans = 0;
int main()
{
    //freopen(".in","r",stdin);
    //freopen(".out","w",stdout);
	read(n);
	FOR(i,1,n) read(a[i]);
	FOR(i,1,n)
		FOR(j,i + 1,n)
			ans += a[i] * a[j];
	cout << ans << endl;
    return 0;
}




Measured memory_bytes: 256
using System;

class Program {
    static void Main() {
        for (string line; (line = Console.ReadLine()) != "0";) {
            var n = int.Parse(line);
            var sum = 0;

            for (var i = 0; i < n; i++) {
                var l = Console.ReadLine().Split(' ');
                
                sum += GetFee(int.Parse(l[0]), int.Parse(l[1]), int.Parse(l[2]), int.Parse(l[3]));
            }
            
            Console.WriteLine(sum);
        }
    }

    static int GetFee(int x, int y, int h, int w) {
        var size = x + y + h;
        
        if (size <= 60 && w <= 2)
            return 600;

        else if (size <= 80 && w <= 5)
            return 800;

        else if (size <= 100 && w <= 10)
            return 1000;

        else if (size <= 120 && w <= 15)
            return 1200;

        else if (size <= 140 && w <= 20)
            return 1400;
            
        else if (size <= 160 && w <= 25)
            return 1600;
            
        return 0; 
    }
}

Measured memory_bytes: 9212
#include <algorithm>
#include <cmath>
#include <iostream>
#include <limits>
#include <numeric>
#include <queue>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
bool compare_by_a(pair<int, int> a, pair<int, int> b) {
    if(a.first != b.first) {
        return a.first < b.first;
    } else {
        return a.second < b.second;
    }
}

int main() {
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i, 0, N) { cin >> L[i]; }
    sort(L.begin(), L.end());
    int count = 0;
    rep(a, 0, N - 2) {
        int c = a + 2;
        int tmp = 0;
        rep(b, a + 1, N - 1) {
            count += c - b - 1;
            for(; c < N; c++) {
                if(L[a] + L[b] > L[c]) {
                    count++;
                } else {
                    break;
                }
            }
        }
    }
    cout << count << endl;
}

Measured memory_bytes: 256
from collections import deque
n, m = map(int, input().split())
INF = 100000000

to = [[] for _ in range(100005)]
for i in range(m):
    a, b = map(int, input().split())
    a -= 1
    b -= 1
    to[a].append(b)
    to[b].append(a)
print('Yes')
q = deque([])
dist = [INF] * n
pre = [-1] * n
dist[0] = 0
q.append(0)

while len(q) > 0:
    v = q.popleft()
    for i in to[v]:
        if dist[i] != INF:
            continue
        dist[i] = dist[v] + 1
        pre[i] = v
        q.append(i)

for i in range(1, n):
    ans = pre[i]
    ans += 1
    print(ans)


Measured memory_bytes: 34792
#include<bits/stdc++.h>
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
#define all(v) v.begin(), v.end()
using ll = long long;
using namespace std;

int main(){
  ll x;cin>>x;
  ll a,b=0,c,d,e,f;

  while(1){
    e=pow(b,5);
    c=x+e;
    d=x-e;
    a=pow(c,0.20);
    f=pow(a,5);   
    if(f==c){
      cout<<a<<" "<<b;
      return 0;
    }
    a=pow(d,0.20);
    f=pow(a,5);
    if(f==d){
      cout<<a<<" "<<b*-1;
      return 0;
    }
    b++;
    //cout<<a<<" "<<b<<" "<<c<<" "<<d<<endl;
  }
  
}



Measured memory_bytes: 3932
#pragma GCC optimize("Ofast", "unroll-loops")
#include <bits/stdc++.h>
using namespace std;
constexpr int MAXN = 500000, INF = 1e8;
pair<int, int> st[MAXN * 4];
int N, K, a[MAXN + 1], b[MAXN + 1];
void modify(int x, int v, int l, int r, int o) {
    if (l == r) {
        st[o] = make_pair(v, x);
    } else {
        int m = (l + r) / 2;
        if (x <= m) modify(x, v, l, m, o * 2);
        else modify(x, v, m + 1, r, o * 2 + 1);
        st[o] = max(st[o * 2], st[o * 2 + 1]);
    }
}
void modify(int x, int v) {
    modify(x, v, 1, N, 1);
}
pair<int, int> query(int ql, int qr, int l, int r, int o) {
    if (ql == l && qr == r) {
        return st[o];
    } else {
        int m = (l + r) / 2;
        if (qr <= m) return query(ql, qr, l, m, o * 2);
        if (ql > m) return query(ql, qr, m + 1, r, o * 2 + 1);
        return max(query(ql, m, l, m, o * 2), query(m + 1, qr, m + 1, r, o * 2 + 1));
    }
}
pair<int, int> query(int ql, int qr) {
    ql = max(ql, 1);
    qr = min(qr, N);
    if (ql > qr) return {-INF, -INF};
    return query(ql, qr, 1, N, 1);
}
bool test_max(int x) {
    return x == query(x - K + 1, x + K - 1).second;
}
priority_queue<int> pq;
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> K;
    for (int i = 1; i <= N; i++) {
        cin >> a[i];
        modify(i, a[i]);
    }
    for (int i = 1; i <= N; i += K) {
        auto p = query(i, i + K - 1);
        if (p.first != -INF && test_max(p.second)) {
            pq.push(p.second);
        }
    }
    int t = N;
    while (!pq.empty()) {
        int x = pq.top();
        pq.pop();
        if (a[x] == -INF) continue;
        b[x] = t--;
        modify(x, -INF);
        a[x] = -INF;
        x = (x - 1) / K * K + 1;
        for (int i = -1; i <= 1; i++) {
            auto p = query(x + i * K, x + i * K + K - 1);
            if (p.first != -INF && test_max(p.second)) {
                pq.push(p.second);
            }
        }
    }
    for (int i = 1; i <= N; i++) cout << b[i] << '\n';
    return 0;
}


Measured memory_bytes: 17904
s=input()
if s.count("A")==1 and s.count("C")==1:
    if "C" in s[2:-1] and s[0]=="A":
        s=s.replace("A","a")
        s=s.replace("C","b")
        t=s.lower()
        if s==t:
            print("AC")
        else:
            print("WA")
    else:
        print("WA")
else:
    print("WA")

Measured memory_bytes: 3060
#include "stdio.h"
int main(int argc, char const *argv[])
{
	int a,b,c,count,i;
	char result[10000];
	for(i=0;;i++){
		scanf("%d",&a); scanf("%d",&b); scanf("%d",&c);
		if(a == -1 && b == -1 && c == -1){
			count = i;
			break;
		}
		if(a == -1 || b == -1)
			result[i] = 'F';
		else if(a + b >= 80)
			result[i] = 'A';
		else if(a +b < 80 && a + b >= 65)
			result[i] = 'B';
		else if(  (a +b < 65 && a + b >= 50)  ||   ( a +b < 50 && a + b >= 30 && c >= 50)  )
			result[i] = 'C';
		else if(a +b < 50 && a + b >= 30 && c < 50)
			result[i] = 'D';
		else
			result[i] = 'F';
	}

	for(i=0;i<count;i++)
		printf("%c\n",result[i]);
	return 0;
}


Measured memory_bytes: 608
#d
a,b = map(int,input().split())
for aa in range(a,a+4):
    if aa%4==0:
        break
for bb in range(b,b-4,-1):
    if bb%4==0:
        break

bins=[]
for ia in range(a,aa):
    bins.append(bin(ia)[2:])
for ib in range(bb,b+1):
    bins.append(bin(ib)[2:])
    
l = max(len(bi) for bi in bins)
bins_fill = [bi.zfill(l) for bi in bins]
ans=[]
for i in range(l):
    bit =sum( int(bi[i]) for bi in bins_fill )%2
    ans.append( str( bit ) )
ans = "".join(ans)

print( int( ans,2) )

Measured memory_bytes: 38384
#include<iostream>
#include<stdio.h>
#include<queue>
#include<algorithm>
#include<math.h>
#include<stack>
#include<map>
#include<limits.h>
#include<vector>
#include<string.h>
#include<string>
using namespace std;
typedef long long LL;
typedef pair<int,int> pii;
const int N = 1e6+5;
const int Mod = 1e9+7;
#define pi acos(-1)
#define INF 1e9+5
#define INM INT_MIN
#define pb(a)  push_back(a)
#define mk(a,b) make_pair(a,b)
#define dbg(x) cout << "now this num is " << x << endl;
#define met0(axx) memset(axx,0,sizeof(axx));
#define metf(axx) memset(axx,-1,sizeof(axx));
#define sd(ax) scanf("%d",&ax)
#define sld(ax) scanf("%lld",&ax)
#define sldd(ax,bx) scanf("%lld %lld",&ax,&bx)
#define sdd(ax,bx) scanf("%d %d",&ax,&bx)
#define sddd(ax,bx,cx) scanf("%d %d %d",&ax,&bx,&cx)
#define sfd(ax) scanf("%lf",&ax)
#define sfdd(ax,bx) scanf("%lf %lf",&ax,&bx)
#define pr(a) printf("%d\n",a)
#define plr(a) printf("%lld\n",a)
LL get(LL x)
{
	return x*x*x*x*x;
}
int main()
{
	int x,f = 0;sd(x);
	LL i = 0;
	LL t1,t2;
	while(get(i) < 1e18)
	{
		if(f) break;
		LL ma = get(i)-x;//b^5.
		for(LL j=0;j<=i;++j)
		{
			if(get(j) == abs(ma)) 
			{
				f = 1;
				t1 = i;
				t2 = j*(ma < 0 ? -1:1);
				break;
			}
		}
		++i;
	}
	printf("%lld %lld\n",t1,t2);
	//system("pause");
	return 0;
}


Measured memory_bytes: 3792
#include <iostream>
#include <string>

using namespace std;

int main()
{
    int n;
    cin >> n;
    string str;
    cin >> str;
    int ans = 0;
    for (int i = 0; i + 3 <= n; i++)
    {
        ans += str.substr(i, 3) == "ABC";
    }
    cout << ans << "\n";
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 101
#define WHITE -4
#define GRAY -3
#define BLACK -2
#define INF -1

typedef struct{
  int Adj[N];
  int k;
  int color;
  int d;
  int id;
}Node;

Node node[N];
int head, tail, n, Q[N];

void enqueue(int x){
  Q[tail] = x;
  if(tail == n)
    tail = 0;
  else
    tail++;
}

int dequeue(void){
  int y;
  y = Q[head];
  if(head == n)
    head = 0;
  else
    head++;
  return y;
}

void BFS(){
  int i, u;
  for(i = 1;i < n+1;i++){
    node[i].color = WHITE;
    node[i].d = INF;
  }
  node[1].color = GRAY;
  node[1].d = 0;
  head = tail = 0;
  enqueue(node[1].id);
  while(head != tail){
    u = dequeue();
    for(i = 0;i < node[u].k;i++){
      if(node[node[u].Adj[i]].color == WHITE){
	node[node[u].Adj[i]].color = GRAY;
	node[node[u].Adj[i]].d = node[u].d + 1;
	enqueue(node[u].Adj[i]);
      }
    }
    node[u].color = BLACK;
  }
}
  

int main(){
  int i, j, l;
  scanf("%d", &n);
  for(i = 1;i < n+1;i++){
    scanf("%d%d", &node[i].id, &node[i].k);
    for(j = 0;j < node[i].k;j++)
      scanf("%d", &node[i].Adj[j]);   
  }
    BFS();
  for(i = 1;i < n+1;i++)
    printf("%d %d\n", i, node[i].d);
  return 0;
}

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

import sys
from itertools import accumulate

def input(): return sys.stdin.readline().strip()
def list2d(a, b, c): return [[c] * b for i in range(a)]
def list3d(a, b, c, d): return [[[d] * c for j in range(b)] for i in range(a)]
def list4d(a, b, c, d, e): return [[[[e] * d for j in range(c)] for j in range(b)] for i in range(a)]
def ceil(x, y=1): return int(-(-x // y))
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(N=None): return list(MAP()) if N is None else [INT() for i in range(N)]
def Yes(): print('Yes')
def No(): print('No')
def YES(): print('YES')
def NO(): print('NO')
sys.setrecursionlimit(10 ** 9)
INF = 10 ** 18
MOD = 10 ** 9 + 7

N, M = MAP()
C = [[] for i in range(M)]
for i in range(N):
    l, r, c = MAP()
    c -= 1
    C[c].append((l, r))

# 同チャンネルで連続する区間をまとめる
LR = []
for i in range(M):
    if C[i]:
        C[i].sort()
        LR.append(C[i][0])
        for j in range(1, len(C[i])):
            l1, r1 = C[i][j-1]
            l2, r2 = C[i][j]
            if r1 == l2:
                LR.pop()
                LR.append((l1, r2))
                # 3連続以上を考慮して更新
                C[i][j] = (l1, r2)
            else:
                LR.append((l2, r2))

# いもす法
MAX = 10 ** 5 + 7
imos = [0] * MAX
for l, r in LR:
    imos[l-1] += 1
    imos[r] -= 1
imos = list(accumulate(imos))
print(max(imos))


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

#define ROUND_UP(a, b) ((a) + (b)-1)/(b)

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

	int len = s.size();
	char last = s[s.size()-1];
	s.erase(s.begin()+1, s.end());
	s += to_string(len-2);
	//s.insert(s.begin()+1, to_string(len-2));
	s += last;
	cout << s << endl;

	return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
int main(){
	int a,b,c,d,e,f,g,aiueo[100],w,n;
	for(a=0;a<100;a++)aiueo[a]=a;
	scanf("%d",&w);
	scanf("%d",&n);
	for(a=0;a<n;a++){
		scanf("%d,%d",&b,&c);
		f=aiueo[b];
		g=aiueo[c];
		aiueo[b]=g;
		aiueo[c]=f;
	}
	for(a=1;a<=w;a++)printf("%d\n",aiueo[a]);
	

	return 0;
}

Measured memory_bytes: 596
#include <cmath>
#include <cstdio>
#include <cstring>
#include <cassert>
#include <iostream>
#include <algorithm>
#include <string>
#include <queue>
#include <set>
#include <map>
using namespace std;
typedef long long int64;
typedef pair<int,int> pii;
typedef pair<int64, int64> pll;

const int INF = 0x3f3f3f3f;
const int MOD = 998244353;

int power(int64 a,int b){
	int64 ret = 1;
	assert(b >= 0);
	while(b){
		if(b&1)	ret = ret*a%MOD;
		a = a*a%MOD;
		b /= 2;
	}
	return ret;
}

int main(){
	int64 N,M,K;	
	cin >> N >> M >> K;
	int64 ans = 0;
	int64 C = 1;
	for (int k = 0; k <= K; ++k){
		ans += M*power(M-1,N-k-1)%MOD*C%MOD;
		ans %= MOD;
		C = C*(N-k-1)%MOD*power(k+1,MOD-2)%MOD;
	}
	printf("%lld\n",ans);
}



Measured memory_bytes: 3248
#include <bits/stdc++.h>
using namespace std;
int main(){
    string W, T;
    int count = 0;
    cin >> W;
    while(1){
        cin >> T;
        if (T == "END_OF_TEXT") break;
        else{
            for (char &c : T){
                if (c >= 'A' && c <= 'Z'){
                    c = c + 32;
                }
            }
            if (T == W) count += 1;
        }
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3080
#B
N,W = map(int,input().split())
VW = [list(map(int,input().split())) for i in range(N)]

dp = [[0 for j in range(W+1)] for i in range(N+1)]
for i in range(N):
    v,w = VW[i]
    dp[i+1] = dp[i][0:W+1]
    for j in range(W+1):
        if j+w <= W:
            dp[i+1][j+w] = max(dp[i][j+w],dp[i][j]+v)
        else:
            dp[i+1][j] = max(dp[i+1][j],dp[i][j])
    
print(max(dp[N]))



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

string s[50];

int f[50][50];

int n;

int main()
{
	cin >> n;
	for(int i = 0;i < n;i++)
	{
		cin >> s[i];
		sort(s[i].begin(),s[i].end());
	}

	string result = "";

	for(int i = 0;i < s[0].size();i++)
	{
		char base = s[0][i];
		bool ok = true;
		for(int j = 1;j < n;j++)
		{
			string& st = s[j];
			string::iterator ite = find(st.begin(),st.end(),base);
			if(ite == st.end())
			{
				ok = false;
				break;
			}
			else
			{
				st.erase(ite);
			}
		}
		if(ok)
		{
			result+= base;
		}
	}

	cout << result << endl;
	return 0;



}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
typedef long long ll;
typedef pair<int, int> pii;
const ll INF = 1ll<<30;
const ll longINF = 1ll<<60;
const ll MOD = 1000000007;
const bool debug = 0;
//---------------------------------//

struct RollingHash {
	vector<ll> mod;
	vector<vector<ll> > hs, pw;
	string s;
	ll base;
	int n;
	
	RollingHash() {}
	RollingHash(string s) { init(s); }
	
	void init(string _s) {
		s = _s;
		n = s.size();
		
		mod.clear();
		hs.clear();
		pw.clear();
		
		mod.push_back(999999937);
		mod.push_back(1000000007);
		
		base = 9973;
		
		hs.resize(mod.size(), vector<ll>(n + 1));
		pw.resize(mod.size(), vector<ll>(n + 1));
		
		REP(i, mod.size()) {
			pw[i][0] = 1;
			REP(j, n) {
				hs[i][j + 1] = (hs[i][j] + s[j]) * base % mod[i];
				pw[i][j + 1] = pw[i][j] * base % mod[i];
			}
		}
	}
	
	inline ll hash(int l, int r, int i) {
		return (hs[i][r] - hs[i][l] * pw[i][r - l] % mod[i] + mod[i]) % mod[i];
	}
	
	inline bool match(int l1, int r1, int l2, int r2) {
		bool res = true;
		REP(i, mod.size()) if (hash(l1, r1, i) != hash(l2, r2, i)) res = false;
		return res;
	}
	
	int lcp(int i, int j) {
		int l = 0, r = min(n - i, n - j) + 1;
		while (r - l > 1) {
			int m = (l + r) / 2;
			if (match(i, i + m, j, j + m)) l = m;
			else r = m;
		}
		return l;
	}
};

typedef pair<ll, ll> pll;

int main() {
	int N;
	string S;
	cin >> N >> S;
	
	RollingHash rh(S);
	
	int l = 0, r = N / 2 + 1;
	
	while (r - l > 1) {
		int m = (l + r) / 2;
		map<pll, int> mm;
		bool ok = false;
		REP(i, N - m + 1) {
			pll cur(rh.hash(i, i + m, 0), rh.hash(i, i + m, 1));
			auto it = mm.find(cur);
			if (it == mm.end()) mm[cur] = i;
			if (it->se + m <= i) {
				ok = true;
				break;
			}
		}
		(ok ? l : r) = m;
	}
	
	cout << l << endl;
	return 0;
}

Measured memory_bytes: 768
package main

import (
	"fmt"
)

type ll int64


func main() {

	var N int
	fmt.Scan(&N)

	slice := make([]int,N)

	for i:= 0;i < N  ;i++  {
		fmt.Scan(&slice[i])
	}

	var sum int = 0
	var max_discount int = 0
	for i:=0;i<N ;i++  {
		sum += slice[i]
		if max_discount <= slice[i] {
			max_discount = slice[i]
		}
	}

	sum -= max_discount / 2


	//out
	fmt.Println(sum)



}


Measured memory_bytes: 512
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdio.h>
using namespace std;
#define ll long long
int main(int argc, char const *argv[])
{
    int a, b;
    char str[20];
    cin >> a >> b;
    cin >> str;
    int len = strlen(str);
    if (len != a+b+1)
        puts("No");
    else {
        for (int i = 0; i < len; i++)
            if ((str[i] < '0' || str[i] > '9') && i != a)
                return 0*puts("No");
        if (str[a] != '-')
            puts("No");
        else
            puts("Yes");
    }
    return 0;
}

Measured memory_bytes: 888
#include<bits/stdc++.h>
using namespace std;
typedef string::const_iterator State;

struct node{
    int item;
    struct node *left, *right;
};

node *make_node(){
    node *d = new node;
    d -> left = NULL;
    d -> right = NULL;
    return d;
}

int number(State &begin){
    int ret = 0;
    while (isdigit(*begin)){
        ret *= 10;
        ret += *begin - '0';
        begin++;
    }
    return ret;
}

node *read(State &begin){
    node *d = make_node();
    begin++;
    if (*begin != ')'){
        d -> left = read(begin);
    }
    begin += 2;
    d -> item = number(begin);
    begin += 2;
    if (*begin != ')'){
        d -> right = read(begin);
    }
    begin++;
    return d;
}

void out(node *d1, node *d2){
    cout << "(";
    if (d1 -> left != NULL && d2 -> left != NULL) out(d1 -> left, d2 -> left);
    printf(")[%d](", d1 -> item + d2 -> item);
    if (d1 -> right != NULL && d2 -> right != NULL) out(d1 -> right, d2 -> right);
    cout << ")";
}

int main() {
    string s1, s2;
    cin >> s1 >> s2;
    node *r1, *r2;
    State begin = s1.begin();
    r1 = read(begin);
    begin = s2.begin();
    r2 = read(begin);
    out(r1, r2);
    cout << endl;
    return 0;
}

Measured memory_bytes: 3284
local mce, mfl, msq, mmi, mma = math.ceil, math.floor, math.sqrt, math.min, math.max

local n = io.read("*n")
local ga, sa, ba = io.read("*n", "*n", "*n")
local gb, sb, bb = io.read("*n", "*n", "*n")

local dp = {}
for i = 1, n do
  dp[i] = i
end
if ga < gb then
  local max = mfl(n / ga)
  for i = 1, max do
    dp[i * ga] = i * gb
  end
end
if sa < sb then
  for i = n - 1, 1, -1 do
    local addable = mfl((n - i) / sa)
    for j = 1, addable do
      dp[i + j * sa] = mma(dp[i + j * sa], dp[i] + j * sb)
    end
  end
  local max = mfl(n / sa)
  for i = 1, max do
    dp[i * sa] = mma(dp[i * sa], i * sb)
  end
end
if ba < bb then
  for i = n - 1, 1, -1 do
    local addable = mfl((n - i) / ba)
    for j = 1, addable do
      dp[i + j * ba] = mma(dp[i + j * ba], dp[i] + j * bb)
    end
  end
  local max = mfl(n / ba)
  for i = 1, max do
    dp[i * ba] = mma(dp[i * ba], i * bb)
  end
end
local newn = n
for i = 1, n do
  newn = mma(newn, dp[i] + n - i)
end

local changed = n ~= newn
n = newn

local function remchange(xb, xa, yb, ya)
  if xa * yb < ya * xb then
    xb, xa, yb, ya = yb, ya, xb, xa
  end
  local maxmul = mfl(n / xb)
  local maxrem = n % xb
  local maxrem_mul = mfl(maxrem / yb)
  local maxrem_rem = maxrem % yb
  local cand = maxrem_rem + maxrem_mul * ya + maxmul * xa
  -- if maxrem_rem == 0 then print(cand)
  -- else
    for i = maxmul, 0, -1 do
      local base = i * xa
      local rem_mul = mfl((n - i * xb) / yb)
      local rem_rem = (n - i * xb) % yb
      -- if maxrem_rem == rem_rem then break end
      cand = mma(cand, base + rem_mul * ya + rem_rem)
    end
    print(cand)
  -- end
end

-- B to A
if changed then
  if gb < ga then
    if sb < sa then
      remchange(gb, ga, sb, sa)
    elseif bb < ba then
      remchange(gb, ga, bb, ba)
    else
      local rem, mul = n % gb, mfl(n / gb)
      print(rem + mul * ga)
    end
  elseif sb < sa then
    if bb < ba then
      remchange(sb, sa, bb, ba)
    else
      local rem, mul = n % sb, mfl(n / sb)
      print(rem + mul * sa)
    end
  elseif bb < ba then
    local rem, mul = n % bb, mfl(n / bb)
    print(rem + mul * ba)
  else
    print(newn)
  end
else
  for i = 1, n do
    dp[i] = i
  end
  if gb < ga then
    local max = mfl(n / gb)
    for i = 1, max do
      dp[i * gb] = i * ga
    end
  end
  if sb < sa then
    for i = n - 1, 1, -1 do
      local addable = mfl((n - i) / sb)
      for j = 1, addable do
        dp[i + j * sb] = mma(dp[i + j * sb], dp[i] + j * sa)
      end
    end
    local max = mfl(n / sb)
    for i = 1, max do
      dp[i * sb] = mma(dp[i * sb], i * sa)
    end
  end
  if bb < ba then
    for i = n - 1, 1, -1 do
      local addable = mfl((n - i) / bb)
      for j = 1, addable do
        dp[i + j * bb] = mma(dp[i + j * bb], dp[i] + j * ba)
      end
    end
    local max = mfl(n / bb)
    for i = 1, max do
      dp[i * bb] = mma(dp[i * bb], i * ba)
    end
  end
  newn = n
  for i = 1, n do
    newn = mma(newn, dp[i] + n - i)
  end
  print(newn)
end


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < n; ++i)
using namespace std;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef pair<int, int> pii;  // pair<int, int> に pii という別名を付ける
typedef long long ll;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  string S;
  cin >> S;
  bool ans = true;
  if (S.size()%2 != 0){
    ans = false;
  }
  else{
    for(int i=0; i<S.size()-1; i++){
      if(i%2 == 0){
        if(S.at(i) != 'h' || S.at(i+1) != 'i'){
            ans = false;
        }
      }
    }
  }
  puts (ans? "Yes":"No");
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
int main(void){
  ll k;
  string s;
  cin>>s>>k;
  int now=1;
  ll tmp=1;
  vl nums={};
  int flag2=0;
  while(now<=s.size()-1){
    if(s[now-1]==s[now]){
      tmp++;
    }else{
      nums.pb(tmp);
      tmp=1;
      flag2=1;
    }
      now++;
  }
  nums.pb(tmp);
  ll sub1=0;
  ll sub2=0;
  ll sub3=0;
  ll sum1=0;
  ll ans=0;
  for(int i=1;i<nums.size()-1;i++){
    if(i==0)i=1;
    if(nums.size()<=i)break;
    sum1+=nums[i]/2;
  }
  ans+=sum1*k;
  /*if(k==1|| flag2==0){
    ll an=0;
    rep(i,nums.size()){
      an+=nums[i]/2;
    }
    cout<<an;
    return 0;
  }*/
  //cout<<ans<<endl;
  if(s[0]==s[s.size()-1] && k!=1){
    ans+=(nums[0])/2;
    ans+=(nums[nums.size()-1])/2;
    ans+=(k-1)*((nums[0]+nums[nums.size()-1])/2);
  }else{
    if(nums.size()-1==0){
      ans+=k*(nums[0]/2);

    }else{
      ans+=k*((nums[0])/2+(nums[nums.size()-1])/2);
    }
  }
  if(nums.size()==1){
    ans=(s.size()*k)/2;
  }
  cout<<ans<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>

using namespace std;

int main() {
    int n, l;

    scanf("%d%d", &n, &l);

    int sum = n*(l-1) + n*(n+1)/2;
    int ans = sum;
    int x = abs(sum);
    for (int i = 1; i <= n; i++) {
      if (x > abs((l+i-1))) {
        x = abs((l+i-1));
        ans = sum - (l+i-1);
      }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 128