akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Text;
using System.Linq;
using System.Collections;
using System.Collections.Generic;
using static System.Console;
using static System.Math;

namespace AtCoder
{
    public class Program
    {
        public static void Main(string[] args)
        {
            new Program().Solve(new ConsoleInput(Console.In, ' '));
        }

        public void Solve(ConsoleInput cin)
        {
            var S = cin.Read;
            var chars = S.ToCharArray();

            var prev = chars[0];
            var count = 0;
            for (int i = 1; i < chars.Length; i++)
            {
                if (chars[i] == prev)
                {
                    count++;
                    prev = chars[i] == '0' ? '1' : '0';
                }
                else
                {
                    prev = chars[i];
                }
            }

            Console.WriteLine(Min(count, S.Length - count));
        }
    }

    public class ConsoleInput
    {
        private readonly System.IO.TextReader _stream;
        private char _separator = ' ';
        private Queue<string> inputStream;
        public ConsoleInput(System.IO.TextReader stream, char separator = ' ')
        {
            this._separator = separator;
            this._stream = stream;
            inputStream = new Queue<string>();
        }
        public string Read
        {
            get
            {
                if (inputStream.Count != 0) return inputStream.Dequeue();
                string[] tmp = _stream.ReadLine().Split(_separator);
                for (int i = 0; i < tmp.Length; ++i)
                    inputStream.Enqueue(tmp[i]);
                return inputStream.Dequeue();
            }
        }
        public string ReadLine { get { return _stream.ReadLine(); } }
        public int ReadInt { get { return int.Parse(Read); } }
        public long ReadLong { get { return long.Parse(Read); } }
        public double ReadDouble { get { return double.Parse(Read); } }
        public string[] ReadStrArray(long N) { var ret = new string[N]; for (long i = 0; i < N; ++i) ret[i] = Read; return ret; }
        public int[] ReadIntArray(long N) { var ret = new int[N]; for (long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
        public long[] ReadLongArray(long N) { var ret = new long[N]; for (long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
    }
}

Measured memory_bytes: 13296
#include<cstdio>
#include<iostream>
using namespace std;
#define MAX 100000
#define SENTINEL 2000000000
struct H{char suit; int value;};
struct H L[MAX/2+2],R[MAX/2+2];
void merge(struct H A[],int n,int left,int mid,int right)
{
    int i,j,k;
    int n1=mid-left;
    int n2=right-mid;
    for(i=0;i<n1;i++) L[i]=A[left+i];
    for(i=0;i<n2;i++) R[i]=A[mid+i];
    L[n1].value=R[n2].value=SENTINEL;
    i=j=0;
    for(k=left;k<right;k++)
    {
        if(L[i].value<=R[j].value)
            A[k]=L[i++];
        else A[k]=R[j++];
    }
}
void me(struct H A[],int n,int left,int right)
{
    int mid;
    if(left+1<right)
    {
        mid=(left+right)/2;
        me(A,n,left,mid);
        me(A,n,mid,right);
        merge(A,n,left,mid,right);
    }
}
int part(struct H A[],int n,int p,int r)
{
    int i,j;
    struct H t,x;
    x=A[r];
    i=p-1;
    for(j=p;j<r;j++)
    {
        if(A[j].value<=x.value)
        {
            i++;
            swap(A[i],A[j]);
        }
    }
    swap(A[i+1],A[r]);
    return i+1;
}
void quick(struct H A[],int n,int p,int r)
{
    int q;
    if(p<r)
    {
        q=part(A,n,p,r);
        quick(A,n,p,q-1);
        quick(A,n,q+1,r);
    }
}
int main()
{
    int n,i,v;
    struct H A[MAX],B[MAX];
    char S[10];
    int stable=1;
    scanf("%d",&n);
    for(i=0;i<n;i++)
    {
        scanf("%s %d",S,&v);
        A[i].suit=B[i].suit=S[0];
        A[i].value=B[i].value=v;
    }
    me(A,n,0,n);
    quick(B,n,0,n-1);
    for(i=0;i<n;i++)if(A[i].suit!=B[i].suit) stable=0;
    if(stable==1) printf("Stable\n");
    else printf("Not stable\n");
    for(i=0;i<n;i++)
    {
        printf("%c %d\n",B[i].suit,B[i].value);
    }
    return 0;
}

Measured memory_bytes: 5412
# encoding:utf-8
import copy
import random
import bisect #bisect_left　これで二部探索の大小検索が行える
import fractions #最小公倍数などはこっち
import math
import sys
import numpy as np

mod = 10**9+7
sys.setrecursionlimit(mod) # 再帰回数上限はでdefault1000

N = int(input())
xy = [[] for i in range(N)]
for i in range(N):
    xy[i] = [int(i) for i in input().split()]

xy = np.array(xy)

count_dic = {}
for i in range(N):
    for j in range(i+1,N):
        diff = xy[i] - xy[j]
        p,q = diff
        if p == 0 and q == 0:
            pass
        else:
            p = int(p)
            q = int(q)
            pq = str(p)+str(q)
            pq2 = str(-p)+str(-q)
            if pq in count_dic:
                count_dic[pq] += 1
            else:
                count_dic[pq] = 1
            if pq2 in count_dic:
                count_dic[pq2] += 1
            else:
                count_dic[pq2] = 1
# print(count_dic)
ans = 1
for k,v in sorted(count_dic.items(), key = lambda x:-x[1]):
    ans = N - v
    break
print(max(1,ans))


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

typedef struct {
  char mark;
  int value;
} Card;

Card *S, *L, *R;
int N, count=0;
void merge(int, int, int);
void mergeSort(int, int);
int partition(Card *, int, int);
Card *quicksort(Card *, int, int);


int main() {
  int i, stable=1;
  Card *IN, *OUT;
  
  scanf( "%d" , &N );
  IN = OUT = malloc(N * sizeof(Card));
  S = malloc((N+1) * sizeof(Card));
  for ( i=0; i<N; i++ ) {
    scanf( " %c" , &(S[i].mark) );
    scanf( "%d" , &(S[i].value) );
    OUT[i] = S[i];
  }

  OUT = quicksort(OUT, 0, N-1);
  mergeSort(0, N);
  for ( i=0; i<N; i++ ) if ( S[i].mark != OUT[i].mark ) stable = 0;
  if ( stable == 1 ) printf( "Stable\n" );
  else printf( "Not stable\n" );
  for ( i=0; i<N; i++ ) printf( "%c %d\n" , OUT[i].mark , OUT[i].value );
  
  return 0;
}


void merge(int left, int mid, int right) {
  int n1 = mid - left, n2 = right - mid, i, j=0, k;

  L = malloc((n1+1) * sizeof(Card));
  R = malloc((n2+1) * sizeof(Card));
  for ( i=0; i<n1; i++ ) L[i] = S[left+i];
  for ( i=0; i<n2; i++ ) R[i] = S[mid+i];
  L[n1].value = R[n2].value = 1000000001;
  i = 0;
  for ( k=left; k<right; k++ ) {
    if ( L[i].value <= R[j].value ) {
      S[k] = L[i];
      i++;
    }
    else {
      S[k] = R[j];
      j++;
    }
    count++;
  }
}

void mergeSort(int left, int right) {
  int mid, i;

  if ( (left+1) < right ) {
    mid = (left + right) / 2;
    mergeSort(left, mid);
    mergeSort(mid, right);
    merge(left, mid, right);
  }
}

int partition(Card *A, int p, int r) {
  int x, i, j;
  Card temp;
  
  x = A[r].value;
  i = p-1;
  for ( j=p; j<r; j++ )
    if ( A[j].value <= x ) {
      i = i+1;
      temp = A[i];
      A[i] = A[j];
      A[j] = temp;
    }
  temp = A[i+1];
  A[i+1] = A[r];
  A[r] = temp;
  
  return i+1;
}

Card *quicksort(Card *A, int p, int r) {
  int q;
  
  if ( p < r ) {
    q = partition(A, p, r);
    quicksort(A, p, q-1);
    quicksort(A, q+1, r);
  }

  return A;
}



Measured memory_bytes: 20680
#include <iostream>
#include <algorithm>
using namespace std;
static const int MAX = 1000;
static const int VMAX = 10000;

int n, A[MAX],s;
int B[MAX], T[VMAX+1];

int solve() {
    int ans = 0;
    
    bool V[MAX];
    for(int i=0; i<n; i++) {
        B[i] = A[i];
        V[i] = false;
    }
    
    sort(B, B+n);
    for (int i=0; i<n; i++) T[B[i]] = i;
    for (int i=0; i<n; i++) {
        if (V[i] ) continue;
        int cur = i;
        int S = 0;
        int m = VMAX;
        int an = 0;
        while (1) {
            V[cur] = true;
            an++;
            int v = A[cur];
            m = min(m,v);
            S += v;
            cur = T[v];
            if (V[cur]) break;
        }
        ans += min(S+(an-2)*m, m+S+(an+1)*s);
    }
    return ans;
}

int main() {
    cin >> n;
    s = VMAX;
    for(int i= 0; i<n; i++) {
        cin >> A[i];
        s= min (s,A[i]);
    }
    int ans = solve();
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
  int a[3], ans;
    for(int i=0; i<3; i++) cin >> a[i];

    if(a[0]==a[1] && a[1]==a[2]) ans = 1;
    else if(a[0]==a[1] || a[1]==a[2] || a[0]==a[2]) ans = 2;
    else ans = 3;

    cout << ans << endl;

}


Measured memory_bytes: 256
N, Q = gets.split.map &:to_i

tree = (N+1).times.map{ [] }
(N-1).times{
  a, b = gets.split.map &:to_i
  tree[a] << b
}
counters = [0] * (N+1)
Q.times{
  vortex, cnt = gets.split.map &:to_i
  counters[vortex] += cnt
}
# p counters
ans = [0] * (N+1)

st = [[1,0]]
while !st.empty?
  from, n = st.pop
  ans[from] = n+counters[from]
  tree[from].each{|to|
    st << [to, ans[from]]
  }
end

puts ans[1..-1]*" "

Measured memory_bytes: 34016
#include<bits/stdc++.h>
using namespace std;
///Welcome to Nasif's Code
#define bug printf("bug\n");
#define bug2(var) cout<<#var<<" "<<var<<endl;
#define co(q) cout<<q<<endl;
typedef long long int ll;
typedef unsigned long long int ull;
const int MOD = (int)1e9+7;
const int MAX = 1e6;
#define pi acos(-1)
#define inf 1000000000000000LL
#define FastRead    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

int main()
{
    FastRead
    //freopen("output.txt", "w", stdout);

    int t;
    cin>>t;
    while(t--)
    {
        ll a,b,mx=0,c;
        cin>>a>>b;
        if(a==b)
        {
            cout<<(a*2ll)-2<<endl;
        }
        else
        {
            c=a*b;
            ll l=0,r=INT_MAX;
            while(r-l>1)
            {
                ll mid=(l+r)>>1;
                ll val=mid/2;
                ll x=(mid+1)/2;
                ll y=(mid+1)-x;
                if(x*y>c-1)
                    r=mid;
                else
                    l=mid;
            }
            cout<<l-1<<endl;
        }
    }


    return 0;
}


Measured memory_bytes: 3656
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{
    

    class Program
    {


        static long Euclid(long a, long b)
        {
            long tmp;
            
            while(a % b != 0)
            {
                tmp = b;
                b = a % b;
                a = tmp;
                
            }

            
            return b;
        }

        static long Solve(long a, long b)
        {
            return a / Euclid(a, b) * b;
        }       

        static void Main(string[] args)
        {
            int N = int.Parse(Console.ReadLine());

            long a;
            long b;
            a = long.Parse(Console.ReadLine());
            for(int i = 1; i < N; i++)
            {
                b = long.Parse(Console.ReadLine());
                
                if(a < b)
                {
                    long tmp = a;
                    a = b;
                    b = tmp;
                }
                
                a = Solve(a, b);
                
            }

            Console.WriteLine(a);

        }
    }
}


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

int solve[100010];
bool prime[100010];


int like(int p) { // p以下の整数で2017に似た数の個数
    if (solve[p] >= 0) return solve[p];
    else {
        if (prime[p] && prime[(p + 1) / 2]) {
            solve[p] = like(p - 2) + 1;
        }
        else solve[p] = like(p - 2);
        return solve[p];
    }
}


int main(void){
    int q, l, r;
    cin >> q;
    
    solve[1] = 0; prime[1] = false;
    for (int i = 3; i <= 100000; i++) solve[i] = -1;
    for (int i = 2; i <= 100000; i++) prime[i] = true;
    
    for (int j = 1; j <= 100000; j++) {
        if (prime[j] == true) {
            for (int i = j * 2; i <= 100000; i += j) {
                prime[i] = false;
            }
        }
    }
    
    for (int i = 0; i < q; i++) {
        cin >> l >> r;
        if (l != 1) cout << like(r) - like(l - 2) << endl;
        else cout << like(r) << endl;
    }
}


Measured memory_bytes: 1920
unittest
{
	assert( [ "SAT" ].parse.expand.solve == 1 );
	assert( [ "SUN" ].parse.expand.solve == 7 );
}



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[] );
	return tuple( s );
}

auto solve( dchar[] s )
{
	final switch( s )
	{
		case "SUN": return 7;
		case "MON": return 6;
		case "TUE": return 5;
		case "WED": return 4;
		case "THU": return 3;
		case "FRI": return 2;
		case "SAT": return 1;
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define F first
#define S second
#define pii pair<int, int>
#define eb emplace_back
#define all(v) v.begin(), v.end()
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rep3(i, l, n) for (int i = l; i < (n); ++i)
#define sz(v) (int)v.size()
#define endl '\n'
const int inf = 1000000007;
const ll INF = 1e18;
int mod = 998244353;
// int mod = 1000000007;
#define abs(x) (x >= 0 ? x : -(x))
#define lb(v, x) (int)(lower_bound(all(v), x) - v.begin())
#define ub(v, x) (int)(upper_bound(all(v), x) - v.begin())
template<typename T1, typename T2> inline bool chmin(T1 &a, T2 b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T1, typename T2> inline bool chmax(T1 &a, T2 b) { if (a < b) { a = b; return 1; } return 0; }
ll gcd(ll a, ll b) { if (b == 0) return a; return gcd(b, a % b); }
ll lcm(ll a, ll b) { return a / gcd(a, b) * b; }
template<typename T, typename U> T pow_(T a, U b) { return b ? pow_(a * a, b / 2) * (b % 2 ? a : 1) : 1; }
ll modpow(ll a, ll b, ll _mod) { return b ? modpow(a * a % _mod, b / 2, _mod) * (b % 2 ? a : 1) % _mod : 1; }
template<class T, class U> ostream& operator << (ostream& os, const pair<T, U>& p) { os << p.F << " " << p.S; return os; }
template<class T> ostream& operator << (ostream& os, const vector<T>& vec) { rep(i, sz(vec)) { if (i) os << " "; os << vec[i]; } return os; }
template<typename T> inline istream& operator >> (istream& is, vector<T>& v) { rep(j, sz(v)) is >> v[j]; return is; }
template<class T, class T2> inline void add(T &a, T2 b) { a += b; if (a >= mod) a -= mod; }


void solve();

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
  cout << fixed << setprecision(10);
  int T;
  T = 1;
  while (T--) solve();
}

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

  int cnt = 0;
  rep(i, a + 1) rep(j, b + 1) rep(k, c + 1) {
    if (i * 500 + j * 100 + k * 50 == x) cnt++;
  }
  cout << cnt << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    char s[n+1];
    cin>>s;
    int i ;
    int c=0;
    for(i=0;i<strlen(s);i++)
    {
        if(s[i]==s[i+1])
            s[i]=' ';
    }
    for(i=0;i<strlen(s);i++)
    {
        if(s[i]>='a'&&s[i]<='z')

            c++;
    }
    cout<<c<<endl;
    return 0;
}



Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int N,K,Q;
  cin>>N>>K>>Q;
  vector<int>fg(N);
  vector<int>df(Q);
  for(int i=0;i<Q;i++)
    {
   int a;
    cin>>a;
    df.at(i)=a;
  }
  for(int i=0;i<Q;i++)
  {
  fg.at(df.at(i)-1)=fg.at(df.at(i)-1)+1;
  }  
for(int i=0;i<N;i++)
{
if( K-Q+fg.at(i)>0 ) cout<<"Yes"<<endl;
  else cout<<"No"<<endl;
}


}

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

int main() {
  int N,M;
  cin >> N >> M;
  vector<vector<int>> data(M);
  for(int i=0;i<M;i++){
    int x;
    cin >> x;
    for(int j=0;j<x;j++){
      int y;
      cin >> y;
      data.at(i).push_back(--y);
    }
  }
  vector<int> p(M);
  for(int i=0;i<M;i++) cin >> p[i];
  int ans=0;
  for(int bit = 0;bit<(1<<N);bit++){//スイッチのon,offを決める
    bool all = true;
    vector<int> onsuu(M);
    for(int j=0;j<M;j++){// j+1番目の電球について調べる
      for(int i=0;i<N;i++){// どこがついているかしらべる
        if(bit & (1<<i)){// i+1番目がついている
          for(int k=0;k<data.at(j).size();k++){
            if(data.at(j).at(k)==i) onsuu[j]++; 
          }
        }
      }
      if(onsuu[j]%2 != p[j]) all = false;
    }
    if(all) ans++;
  }
  cout << ans;
}


Measured memory_bytes: 256
#include<iostream>
//#include<vector>
//#include<algorithm>
//#include<map.h>
//#include<string.h>
//#include<climits>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"

int main(){
  
  int d,t,s;
  cin>>d>>t>>s;
  
  if(d<=s*t)
    cout<<"Yes";
  else
    cout<<"No";}

Measured memory_bytes: 3620
#include <bits/stdc++.h>
#include <unordered_map>
#include <unordered_set>
#define pb push_back
#define mpr make_pair
#define pii pair<int, int>
#define pll pair<ll, ll>
#define ll long long
#define ld long double
#define all(arr) arr.begin(), arr.end()
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define fo(i, l, r) for (int i = l; i <= r; i++)
#define INF 1000000001
#define inf1 1000000000000000001
#define mod 1000000007
#define pie 3.14159265358979323846264338327950L
#define N 100005
#define mid(l, r) l + (r - l) / 2
#define vec vector<int>
#define vecl vector<ll>
#define umap unordered_map<ll,ll>
#define yes cout << "Yes" << endl;
#define no cout << "No" << endl;
#define endl "\n"
using namespace std;
 
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};  
int ddx[8]={1,1,0,-1,-1,-1,0,1},ddy[8]={0,1,1,1,0,-1,-1,-1};
ll gcd(ll a,ll b){ if(!a)return b;return gcd(b%a,a);}




 
    
void test_case() {

    int n, m, sum = 0;
	cin >> n >> m;
	vector<int> a(n);
	rep(i, n) {
		cin >> a[i];
		sum += a[i];
	}
	sort(a.begin(), a.end());
	string ans;
	a[n - m] >= (4 * m + sum - 1) / (4 * m) ? ans = "Yes" : ans = "No";
	cout << ans << endl;
	return ;









}
 
 
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    cout<<fixed<<setprecision(20);
 
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
 
 
    int t = 1;
    // cin >> t;
    while (t--)
    {
        test_case();
    }
}

Measured memory_bytes: 3624
N=int(input())
L=list(map(int,input().split()))

print(' '.join(map(str,L)))
for i in range(1,N):
    for j in range(i):
        if L[i] < L[j]:
            v=L.pop(i)
            L.insert(j,v)
            
    print(' '.join(map(str,L)))


Measured memory_bytes: 5596
#include<iostream>
using namespace std;
int main(){
    int a,b,c,n;
    cin >> a >> b >> c;
    n = 0;
    for(int i = a;i <= b;i++){
        if (c%i != 0)continue;
        else n++;
    }
    cout << n << endl;
    return 0;
}


Measured memory_bytes: 3112
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String o = sc.next();
        String e = sc.next();
        for (int i = 0; i < e.length(); i++) {
            System.out.print(o.substring(i, i + 1));
            System.out.print(e.substring(i, i + 1));
        }
        if(o.length() != e.length()) {
            System.out.println(o.substring(o.length() - 1, o.length()));
        }
    }
}


Measured memory_bytes: 35572
N = int(input())
S = input()
E = [0 for i in range(N)]
W = [0 for i in range(N)]
for i in range(N):
    if S[i] == 'E':
        E[i] = 1
    else:
        W[i] = 1
for i in range(1,N):
    E[i] += E[i-1]
for i in range(N-2,-1,-1):
    W[i] += W[i+1]
ans = [W[i]+E[i]-1 for i in range(N)]
print(N-1-max(ans))

Measured memory_bytes: 39248
import sys
from io import StringIO
import unittest

def resolve():
    a,b = list(map(str,input().split()))
    c,d = list(map(int,input().split()))
    e=input()

    if a==e:
        c-=1

    if b==e:
        d-=1 

    print(str(c)+" "+str(d))

    return

resolve()

Measured memory_bytes: 6220
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		char c[] = s.toCharArray();
		if (c[0] != c[1] && c[1] != c[2] && c[0] != c[2]) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

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

int main(){
    int in[5], k;

    for(int i = 0 ; i < 5 ; i++){
        cin >> in[i];
    }
    cin >> k ;
    for(int i = 1 ; i < 5 ; i++){
        if(in[i]- in[0] > k){
            cout << ":(" << endl;
            return 0;
        }
    }
    cout << "Yay!" <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a), i##_max = (b); i < i##_max; ++i)
#define RFOR(i, a, b) for (int i = (b)-1, i##_min = (a); i >= i##_min; --i)
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define RREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define ALL(obj) (obj).begin(), (obj).end()

using namespace std;
using i64 = int64_t;
using u64 = uint64_t;
using vi = vector<int>;
using vl = vector<i64>;
using vd = vector<double>;
using pi = pair<int, int>;
using pl = pair<i64, i64>;
using pd = pair<double, double>;

constexpr int INF = 1 << 30;
constexpr int MOD = 1000000007;

template <typename T>
void print(vector<T> &v) {
  REP(i, v.size()) {
    if (i) cout << " ";
    cout << v[i];
  }
  cout << endl;
}

int main() {
  std::string s;
  cin >> s;
  auto n = s.size();
  i64 ans = 0;
  vi a_rep(n, 0);
  if (s[0] == 'A') {
    a_rep[0] = 1;
  }
  FOR(i, 1, n) {
    if (s[i] == 'A') {
      a_rep[i] = a_rep[i - 1] + 1;
      continue;
    }
    if (i < 2) continue;
    if (s[i] == 'C' && s[i - 1] == 'B' && s[i - 2] == 'A') {
      ans += a_rep[i - 2];
      a_rep[i] = a_rep[i - 2];
      s[i - 1] = 'B';
      s[i] = 'A';
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 1412
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
            get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
            get!($($t),*)
        ).collect::<Vec<_>>()
    };
}

fn main() {
    let mut s = get!(String).chars().collect::<Vec<_>>();
    s.sort();
    let sp = s.into_iter().collect::<String>();
    let mut t = get!(String).chars().collect::<Vec<_>>();
    t.sort_by(|a, b| b.cmp(a));
    let tp = t.into_iter().collect::<String>();
    println!("{}", if sp < tp { "Yes" } else { "No" });
}

Measured memory_bytes: 2152
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REP1(i,n) for(int i = 1; i < n+1 ;i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define SZ(x) ((int)(x).size())
#define ARRAY_LENGTH(array) (sizeof(array) / sizeof(array[0]))
using namespace std;
typedef long long ll;
using p = pair<int, int>;
using P = pair<ll, ll>;
using V = vector<int>;
using VV = vector<vector<int>>;
using VVV = vector<vector<vector<int>>>;
using VL = vector<ll>;
using VVL = vector<vector<ll>>;
using VVVL = vector<vector<vector<ll>>>;
using Graph = VV;


int main(){
    ios::sync_with_stdio(false); cin.tie(0);
    string s;
    cin >> s;
    if(s.at(0)!='7' and s.at(1)!= '7' and s.at(2) != '7'){
        cout << "No" << endl;
    }
    else cout << "Yes" << endl;

}


Measured memory_bytes: 3672
n,m=map(int,input().split())
P=[i-1 for i in list(map(int,input().split()))]

class UnionFind():
    def __init__(self,num):
        self.n = num         #class内変数nに、外部から入力した値numを代入
        self.parents = [-1 for i in range(self.n)]
          #parentsは要素の親(1こ上のやつ)番号0~n-1を格納、自分が最親なら-(要素数)を格納(初期値は-1)

    #xの最親は誰？
    def find(self,x):
        if self.parents[x]<0:
            return x
        else:
            self.parents[x]=self.find(self.parents[x]) #再帰して1番上までいってる
                #調べながらparentsの値を更新してる！（経路圧縮）
            return self.parents[x]

    #結合せよ
    #xの親とyの親をくっつける
    def union(self,x,y):
        xx=self.find(x)  #xxはxの最親
        yy=self.find(y)  #yyはyの最親
        if xx==yy:
            return     #同じ屋根の下にあった場合は何もしない
        else:
            size_xx=abs(self.parents[xx]) #xが含まれる木のサイズ
            size_yy=abs(self.parents[yy]) #yが含まれる木のサイズ
            if size_xx>size_yy:
                xx,yy=yy,xx  #yyの方が大きい木、ってことにする

            self.parents[yy]+=self.parents[xx] #大きい木のサイズ更新
            self.parents[xx]=yy   #サイズが小さい木を大きい木に接ぐ

    #xの属する木の大きさ（まあunionでも使ったけど）
    def size(self,x):
        xx=self.find(x)
        return abs(self.parents[xx])

    #xとyはこの空の続く場所にいますか　いつものように笑顔でいてくれますか　今はただそれを願い続ける
    def same(self,x,y):
        return 1 if self.find(x)==self.find(y) else 0

    #xと　同じ木にいる　メンバーは？
    def members(self,x):
        xx=self.find(x)
        return [i for i in range(self.n) if self.find(i)==xx]
             #ifの条件式に漏れたら無視

    #最親だけを並べあげる
    def roots(self):
        return [i for i,x in enumerate(self.parents) if x < 0]
        #いやこれは天才すぎる、basisのenumerate.py参照

    #すべての最親について、メンバーを辞書で
    def all_group_members(self):
        return {r:self.members(r) for r in self.roots()}

    #グループ分けどうなりましたか、２重リストで
    def state_grouping(self):
        return list(self.all_group_members().values())


uf=UnionFind(n)
for i in range(m):
    a,b=map(int,input().split())
    a-=1;b-=1
    uf.union(a,b)
ans=0
for i in range(n):
    ans+= uf.same(i,P[i])
print(ans)

Measured memory_bytes: 96992
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
		// スペース区切りの整数の入力
		int b = sc.nextInt();
		// 出力
      if(( b / a == 2 || b / a == 3 || b == 4 * a) && b % 2 == 0){
      		System.out.println("Yes");
      }else{
		System.out.println("No");
      }
	}
}


Measured memory_bytes: 35796
/*  ex9_2
    pptenshi  */

#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#define SIZE 100001


typedef struct stack {
    char elem;
    struct stack *next;
}stack;


void push(stack **first, char elem)  {
    stack *new = calloc(1, sizeof(stack));
    if (new == NULL) exit(1);

    new->elem = elem;
    new->next = *first;
    *first = new;
}


char pop(stack **first) {
    char elem;
    stack *tmp = *first;

    if (tmp == NULL) exit(1);

    elem = tmp->elem;
    *first = tmp->next;
    free(tmp);
    return elem;
}


int main(void) {
    char string[SIZE];    // S
    int len_string;       // N
    int num_remove = 0;   // 取り除く数
    stack *first = NULL;  // キューブを積むスタック


    // input 
    scanf("%s", string);
    len_string = strlen(string);

    
    // calculate
    for (int i = 0; i < len_string; i++) {
        
        // スタックに要素がない場合
        if (first == NULL) {
            push(&first, string[i]);
            continue;
        }

        // スタックの先頭と積み木のi番目を比較
        char first_elem = first->elem;
        if (first_elem != string[i]) {
            // 異なる場合は先頭を削除しカウント
            pop(&first);
            num_remove += 2;
        } else {
            // 同じ場合は追加
            push(&first, string[i]);
        }

    }


    // output
    printf("%d\n", num_remove);

    return 0;
}

Measured memory_bytes: 4948
#include <iostream>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
#define rep(i, n) for (int i = 0; i < n; i++)
int main()
{
   int n, a;
   cin >> n >> a;
   cout << n * n - a << endl;

   return 0;
}


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

public class Main {

	public static void main(String[] args) {
		try {
			BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
			int roopNum = Integer.parseInt(br.readLine());
			StringBuilder input = new StringBuilder();
			for (int i = 0; i < roopNum; ++i) {
				input.append(br.readLine()+"\n");
			}
			System.out.print(calc(new String(input)));
		} catch (IOException ioex) {
			ioex.printStackTrace();
		}
	}

	private static String calc(String input) {
		return input.replaceAll("Hoshino", "Hoshina");
	}
}

Measured memory_bytes: 9364
class Factorials:
    # nに十分大きい数を入力
    def __init__(self, n, mod):
        self.mod = mod

        # self.fac[i] ≡ i! (factorial:階乗)
        self.fac = [1]
        num = 1
        for i in range(1, n+1):
            num *= i
            num %= mod
            self.fac.append(num)

        # self.rec[i] ≡ 1 / i! (reciprocal:逆数)
        num = pow(num, mod-2, mod)
        self.rec = [1 for i in range(n+1)]
        self.rec[n] = num
        for i in range(n-1, 0, -1):
            num *= i + 1
            num %= mod
            self.rec[i] = num

    # comb(n, r) ≡ nCr
    def comb(self, n, r):
        return self.fac[n] * self.rec[r] * self.rec[n - r] % self.mod
    
    # perm(n, r) ≡ nPr
    def perm(self, n, r):
        return self.fac[n] * self.rec[n-r] % self.mod

    # fact(n) ≡ n!
    def fact(self, n):
        return self.fac[n]

h, w, a, b = map(int, input().split())
mod = 10**9 + 7

f = Factorials(2 * (10 ** 5), mod)
if h - a < w - b:
    num = h - a
else:
    num = w - b

ans = 0
for i in range(num):
    x = h - a - i
    y = b + i + 1

    ans += f.comb(x + y - 2, x - 1) * f.comb(h + w - x - y, h - x)
    ans %= mod

print(ans)

Measured memory_bytes: 100400
s = input()
L = len(s)
for i in range(L-2) :
    if s[i+1] == s[i] or s[i+2] == s[i] :
        print(i+1, i+3)
        exit()
else :
    if s[L-2] == s[L-1] :
        print(L-1, L)
    else :
        print(-1, -1)

Measured memory_bytes: 3188
#include<bits/stdc++.h>
#define IOS ios::sync_with_stdio(false);cin.tie(0);
using namespace std;
const int INF=1e9+5;
int main(){ IOS;
	int n;
	cin>>n;
	int k;
	cin>>k;
	vector<int>dp(n,INF);
	vector<int>h(n);
	dp[0]=0;
	for(int i=0;i<n;i++){
		cin>>h[i];
	}
	for(int i=0;i<n;i++){
		for(int j=i+1;j<=i+k;j++){
			if(j<n)
		dp[j]=min(dp[j],dp[i]+abs(h[i]-h[j]));
	}}
	cout<<dp[n-1];
} 

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
#define rep(i, n) for(int i = 0; i < n; i++)

int main(){
    int sx, sy, tx, ty;
    cin >> sx >> sy >> tx >> ty;
    const int dx = tx - sx, dy = ty - sy;

    cout << string(dy, 'U') << string(dx, 'R');
    cout << string(dy, 'D') << string(dx, 'L');
    cout << 'L' << string(dy + 1, 'U') << string(dx + 1, 'R') << 'D';
    cout << 'R' << string(dy + 1, 'D') << string(dx + 1, 'L') << 'U';
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
typedef long long ll;
const long long INF = 1LL << 60;
int main()
{
    int N;
    cin >> N;

    if (N / 100 == N % 10) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    char str[20001];
    int m,tmp,length;
    while(true){
        scanf("%s",str);
        if(str[0] == '-') break;
        length = 0;
        for(int k = 0; str[k] != '\0';k++) length++;
        scanf("%d",&m);
        int index = 0;
        for(int i = 0; i < m; i++){
            scanf("%d",&tmp);
            for(int j = 0; j < tmp; j++){
                str[index+length] = str[index];
                index++;
            }
        }
        for(int p = 0; p < length; p++){
            printf("%c",str[index+p]);
        }
        printf("\n");
    }
}


Measured memory_bytes: 2608
n = int(input())
s = input()
r = s.count("R")
g = s.count("G")
b = s.count("B")
ret = 0
for i in range(1,n-1):
    m = min(i,n-i-1)
    for j in range(1,m+1):
        A,B,C = s[i],s[i-j],s[i+j]
        if A != B and A != C and B != C:
            ret += 1
ans = r*g*b - ret
print(ans)


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

using namespace std;

//#define _FILES
#define PB push_back
#define MP make_pair
#define X first
#define Y second

const int MAXN = 100005;

int a[MAXN];

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

    #ifdef _FILES
        freopen("","r",stdin);
        freopen("","w",stdout);
    #endif // _FILES
    int n;
    cin >> n;
    for (int i=0;i<n;i++)
    {
        cin >> a[i];
    }

    pair<int, int> cur = {a[0], -1};
    int ans = 1;

    for (int i=1;i<n;i++)
    {
        if (a[i] == cur.X) continue;
        if (a[i] > cur.X)
        {
            cur.X = a[i];
            if (cur.Y == 1) continue;
            if (cur.Y == -1)
            {
                cur.Y = 1;
                continue;
            }
            ans++;
            cur = {a[i], -1};
        }
        else
        {
            cur.X = a[i];
            if (cur.Y == 0) continue;
            if (cur.Y == -1)
            {
                cur.Y = 0;
                continue;
            }
            ans++;
            cur = {a[i], -1};
        }
    }
    cout << ans << endl;
    return 0;
}



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

const ll MAX = 200000;
const ll INF = 1001001001;
const ll MOD = 1000000007;
const double PI=3.1415926535897932;

ll N, X, T, ans=0, tmp=0;
vector<ll> A;
string S;

signed main(){
    cin >> N >> X >> T;
    ans = N/X;
    if(N%X!=0) ans++;
    cout << ans*T << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i,n) for(int i=(0);i<(n);i++)

using namespace std;

typedef long long ll;

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

	int R, G, B, N;
	cin >> R >> G >> B >> N;

	ll ans = 0;
	for(int r = 0; r <= N / R; r++){
		for(int g = 0; g <= N / G; g++){
			int rem = N - r * R - g * G;
			if(rem < 0) continue;
			if(rem % B == 0) ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 998244353;

void mod(long long&a) { if (a >= MOD) a %= MOD; }

int main() {
    int N;
    long long M = 0;
    cin >> N;
    vector<long long> D(N);
    for (int i = 0; i < N; i++) {
        cin >> D[i];
        M = max(M, D[i]);
    }

    vector<long long> cnt(M + 1, 0);
    for (int i = 0; i < N; i++) {
        long long d = D[i];
        cnt[d]++;
    }

    bool judge = true;
    if (D[0] != 0) judge = false;
    for (int i = 0; i <= M; i++) {
        if (cnt[i] == 0 || cnt[0] != 1) {
            judge = false;
        }
    }

    long long ans = 0;
    if (judge == true) {
        ans = 1;
        for (int i = 0; i < M; i++) {
            long long a = cnt[i], b = cnt[i + 1];
            long long res = 1; mod(res);
            for (long long i = 0; i < b; i++) {
                res *= a; mod(res);
            }
            ans *= res;
            mod(ans);
        }
    }
    ans %= MOD;
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1792
/* Dynamic Programming implementation of LCS problem */
#include<iostream> 
#include<cstring> 
#include<cstdlib> 
using namespace std; 

/* Returns length of LCS for X[0..m-1], Y[0..n-1] */
void lcs( string X, string Y, int m, int n ) 
{ 
int L[m+1][n+1]; 

/* Following steps build L[m+1][n+1] in bottom up fashion. Note 
	that L[i][j] contains length of LCS of X[0..i-1] and Y[0..j-1] */
for (int i=0; i<=m; i++) 
{ 
	for (int j=0; j<=n; j++) 
	{ 
	if (i == 0 || j == 0) 
		L[i][j] = 0; 
	else if (X[i-1] == Y[j-1]) 
		L[i][j] = L[i-1][j-1] + 1; 
	else
		L[i][j] = max(L[i-1][j], L[i][j-1]); 
	} 
} 

// Following code is used to print LCS 
int index = L[m][n]; 

// Create a character array to store the lcs string 
char lcs[index+1]; 
lcs[index] = '\0'; // Set the terminating character 

// Start from the right-most-bottom-most corner and 
// one by one store characters in lcs[] 
int i = m, j = n; 
while (i > 0 && j > 0) 
{ 
	// If current character in X[] and Y are same, then 
	// current character is part of LCS 
	if (X[i-1] == Y[j-1]) 
	{ 
		lcs[index-1] = X[i-1]; // Put current character in result 
		i--; j--; index--;	 // reduce values of i, j and index 
	} 

	// If not same, then find the larger of two and 
	// go in the direction of larger value 
	else if (L[i-1][j] > L[i][j-1]) 
		i--; 
	else
		j--; 
} 

// Print the lcs 
cout <<  lcs; 
} 

/* Driver program to test above function */
int main() 
{ 
    string X,Y;
    cin>>X>>Y;
int m = X.size(); 
int n = Y.size(); 
lcs(X, Y, m, n); 
return 0; 
} 


Measured memory_bytes: 35456
#include<bits/stdc++.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	if(a<0||a>8){
		cout<<":(";
	}
	else if(b<0||b>8){
		cout<<":(";
	}
	else{
		cout<<"Yay!"; 
	}
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LOOP(n) for (int _i = 0; _i < (n); _i++)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define FOR(i, r, n) for (int i = (r); i < (n); ++i)
#define ALL(obj) begin(obj), end(obj)
using namespace std;
using ll = long long;
using ull = unsigned long long;

const int INF = 2100100100;
const int MOD = 1e9 + 7;

// 多次元 vector 生成
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
template <class T>
bool chmax(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}

int main() {
    // cin.tie(0);
    // ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    vector<ll> A(N);
    ll sum = 0;
    REP(i, N) {
        cin >> A.at(i);
        A[i] -= (i + 1);
        sum += A[i];
    }

    sort(ALL(A));
    ll median = (N % 2 == 0) ? (A[N / 2 - 1] + A[N / 2]) / 2 : A[N / 2];
    // cout << median << endl;
    ll ans = 0;
    REP(i, N) { ans += abs(A[i] - median); }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
using System;
using System.Collections.Generic;
using System.Linq;
using static System.Console;
using static System.Math;

namespace B_ABC171
{
    class MainClass
    {

        static int[] s, p;

        public static void Main(string[] args)
        {
            s = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            p = Array.ConvertAll(ReadLine().Split().ToArray(), int.Parse);
            var pl = p.ToList();
            // pl.Sort((x, y) => y - x);
            pl.Sort();
            int ans = 0;
            for (int i = 0; i < s[1]; i++)
            {
                ans += pl[i];
            }
            WriteLine(ans);
        }
    }
}


Measured memory_bytes: 28672
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#define int long long
using namespace std;

typedef pair<int, int> Pii;

void readline(int N, vector<int> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atoi(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atoi(s.c_str());
}
void readline(int N, vector<double> &a){
    string s;
    for(int i = 0; i < N - 1; i++){
        getline(cin, s, ' ');
        a[i] = atof(s.c_str());
    }
    getline(cin, s, '\n');
    a[N - 1] = atof(s.c_str());
}

int calccost(vector<vector<int>> &colnum, vector<vector<int>> &D, int n, int C, int color){
    int tmp = 0;
    for(int i = 0; i < C; i++){
        tmp += colnum[n][i] * D[i][color];
    }
    return tmp;
}

signed main(){

    int N, C;
    cin >> N >> C;
    vector<vector<int>> D(C, vector<int>(C));
    for(int i = 0; i < C; i++){
        readline(C, D[i]);
    }
    vector<vector<int>> c(N, vector<int>(N));
    for(int i = 0; i < N; i++){
        readline(N, c[i]);
        for(int j = 0; j < N; j++){
            c[i][j]--;
        }
    }

    vector<vector<int>> colnum(3, vector<int>(C, 0));
    for(int i = 0; i < N; i++){
        for(int j = 0; j < N; j++){
            colnum[(i + j) % 3][c[i][j]]++;
        }
    }


    int ans = 100000000000000;
    int color[3], tmp[3];
    for(color[0] = 0; color[0] < C; color[0]++){
        tmp[0] = calccost(colnum, D, 0, C, color[0]);
        for(color[1] = 0; color[1] < C; color[1]++){
            tmp[1] = calccost(colnum, D, 1, C, color[1]);
            for(color[2] = 0; color[2] < C; color[2]++){
                tmp[2] = calccost(colnum, D, 2, C, color[2]);
                if(color[0] == color[1] || color[0] == color[2] || color[1] == color[2]) continue;
                int tmp2 = tmp[0] + tmp[1] + tmp[2];
                if(tmp2 < ans) ans = tmp2;
            }
        }
    }

    cout << ans;

    return 0;
}

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

using namespace std;

typedef long long ll;

ll gauss(ll x) {
  return x * (x + 1) / 2;
}

ll gauss(ll x, ll y) {
  return gauss(y) - gauss(x - 1);
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  ll sol = 0;
  int i = 1;
  while (i <= n) {
    int j = n / (n / i);
    sol += gauss(i, j) * gauss(n / i);
    i = j + 1;
  }
  cout << sol << "\n";
  return 0;
}



Measured memory_bytes: 3652
def isMoneyJudge(money, z):
    if z >= 0:
        if money % 1000 == 0:
            if money//1000 == z:
                return True
    
    return False

N, Y = [int(i) for i in input().split()]

flag = 0
for x in range(N + 1):
    for y in range(N + 1):
        money = Y - 10000*x - 5000*y
        z = N - x - y
        if isMoneyJudge(money, z):
            if flag == 0:
                flag = 1
                print(x, y, z)
                
if flag == 1:
    pass
else:
    print(-1, -1 , -1)

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

using ll = long long;
using pint = pair<int, int>;

const ll INF = 1e12;
const ll MOD = 1e9 + 7;

ll N, M;
vector<ll> a;

int main()
{
    cin >> N >> M;
    a.resize(M);
    for (int i = 0; i < M; ++i)
    {
        cin >> a[i];
    }

    vector<bool> safe(N + 1, true);
    for (int i = 0; i < M; ++i)
    {
        safe[a[i]] = false;
    }

    vector<ll> dp(N + 1);
    dp[0] = 1;
    for (int i = 0; i < N + 1; ++i)
    {
        if ((i + 1) < N + 1 && safe[i + 1])
            dp[i + 1] += (dp[i] % MOD);
        if ((i + 2) < N + 1 && safe[i + 2])
            dp[i + 2] += (dp[i] % MOD);
    }

    cout << dp[N] % MOD << endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <string>
#include <queue>
#include <algorithm>
using namespace std;
int d[100005];
int main() {
	priority_queue<int> que;
	int n;
	int m;
	cin >> n;
	cin >> m;
	int a[100005];
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		que.push(a[i]);
	}
	for (int i = 0; i < m; i++) {
		int y = que.top();
		que.pop();
		y = y / 2;
		que.push(y);
	}
	long long int u = 0;
	for (int i = 0; i < n; i++) {
		u += que.top();
		que.pop();
	}
	cout << u;
}

Measured memory_bytes: 1148
package main

import "fmt"

func min(x, y int) int {
	if x < y {
		return x
	}
	return y
}

func main() {
	var n int
	fmt.Scan(&n)
	b := make([]int, n-1)
	for i := range b {
		fmt.Scan(&b[i])
	}

	ans := b[0] + b[len(b)-1]
	for i := range b[:len(b)-1] {
		ans += min(b[i], b[i+1])
	}
	fmt.Println(ans)
}


Measured memory_bytes: 512
#include <cassert>
#include <cstdio>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;
using lint = long long;
constexpr int MOD = 1000000007, INF = 1010101010;
constexpr lint LINF = 1LL << 60;

template <class T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
	for (const auto &e : vec) os << e << (&e == &vec.back() ? "" : " ");
	return os;
}

#ifdef _DEBUG
template <class T>
void dump(const char* str, T &&h) { cerr << str << " = " << h << "\n"; };
template <class Head, class... Tail>
void dump(const char* str, Head &&h, Tail &&... t) {
	while (*str != ',') cerr << *str++; cerr << " = " << h << "\n";
	dump(str + (*(str + 1) == ' ' ? 2 : 1), t...);
}
#define DMP(...) dump(#__VA_ARGS__, __VA_ARGS__)
#else 
#define DMP(...) ((void)0)
#endif

int main() {

	cin.tie(nullptr);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> L(N);
	for (int i = 0; i < N; i++) cin >> L[i];
	sort(L.begin(), L.end());

	int ans = 0;
	for (int i = 0; i < N; i++) {
		for (int j = i + 1; j < N; j++) {
			ans += (lower_bound(L.begin(), L.end(), L[i] + L[j]) - (L.begin() + j + 1));
		}
	}

	cout << ans << "\n";

	return 0;
}

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

int main(){
  int n,m; cin>>n>>m;
  vector<int> num(n+1,0);
  for(int i=0;i<m;i++){
    int x,y; cin>>x>>y;
    num[x]++; num[y]++;
    if(num[x]==2) num[x]-=2;
    if(num[y]==2) num[y]-=2;
  }
  sort(num.begin(),num.end());
  if(0==num[n]){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
} 

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define MOD 1000000007
#define PI 3.141592653589793

int main(){
    int n, a;
    cin >> n >> a;
    cout << (n % 500 <= a ? "Yes" : "No") << endl;
}


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

//#define int long long
typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 1000000007;
const ll INF = mod * mod;
const int INF_N = 1e+9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
#define all(v) (v).begin(),(v).end()
typedef pair<ll, ll> LP;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-12;
const ld pi = acos(-1.0);
//typedef vector<vector<ll>> mat;
typedef vector<int> vec;

//繰り返し二乗法
ll mod_pow(ll a, ll n, ll m) {
	ll res = 1;
	while (n) {
		if (n & 1)res = res * a%m;
		a = a * a%m; n >>= 1;
	}
	return res;
}

struct modint {
	ll n;
	modint() :n(0) { ; }
	modint(ll m) :n(m) {
		if (n >= mod)n %= mod;
		else if (n < 0)n = (n%mod + mod) % mod;
	}
	operator int() { return n; }
};
bool operator==(modint a, modint b) { return a.n == b.n; }
modint operator+=(modint &a, modint b) { a.n += b.n; if (a.n >= mod)a.n -= mod; return a; }
modint operator-=(modint &a, modint b) { a.n -= b.n; if (a.n < 0)a.n += mod; return a; }
modint operator*=(modint &a, modint b) { a.n = ((ll)a.n*b.n) % mod; return a; }
modint operator+(modint a, modint b) { return a += b; }
modint operator-(modint a, modint b) { return a -= b; }
modint operator*(modint a, modint b) { return a *= b; }
modint operator^(modint a, int n) {
	if (n == 0)return modint(1);
	modint res = (a*a) ^ (n / 2);
	if (n % 2)res = res * a;
	return res;
}

//逆元(Eucledean algorithm)
ll inv(ll a, ll p) {
	return (a == 1 ? 1 : (1 - p * inv(p%a, a)) / a + p);
}
modint operator/(modint a, modint b) { return a * modint(inv(b, mod)); }

const int max_n = 1 << 18;
modint fact[max_n], factinv[max_n];
void init_f() {
	fact[0] = modint(1);
	for (int i = 0; i < max_n - 1; i++) {
		fact[i + 1] = fact[i] * modint(i + 1);
	}
	factinv[max_n - 1] = modint(1) / fact[max_n - 1];
	for (int i = max_n - 2; i >= 0; i--) {
		factinv[i] = factinv[i + 1] * modint(i + 1);
	}
}
modint comb(int a, int b) {
	if (a < 0 || b < 0 || a < b)return 0;
	return fact[a] * factinv[b] * factinv[a - b];
}
using mP = pair<modint, modint>;

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




void solve() {
    int N; cin >> N;
    vec a(N);
    int sum = 0;
    rep(i, N){
        cin >> a[i];
        sum += a[i];
    }
    int res = INF_N;
    int now = 0;
    rep(i, N-1){
        now += a[i];
        sum -= a[i];
        res = min(res, abs(sum-now));
    }
    cout << res << endl;
}

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  //cout << fixed << setprecision(10);
  //init_f();
  //init();
  //int t; cin >> t; rep(i, t)solve();
  solve();
//   stop
    return 0;
}


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

int main(){
  int A,B;
  cin >> A >> B;
  if(A<=5){
    cout << 0 << endl;
  }
  else if(6<=A && A<=12){
    cout << B/2 << endl;
  }
  else{
    cout << B << endl;
  }
}

Measured memory_bytes: 256