akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cstring>
#include <iostream>
#include <algorithm>
using namespace std;
#define N 105
int n, m, A[N][N];
char S[N][N];
int main()
{
	scanf("%d%d", &n, &m);
	for (int i = 1; i <= n; i++)
		scanf("%s", S[i] + 1);
	A[1][1] = (S[1][1] == '#');
	for (int i = 1; i <= n; i++)
	{
		for (int j = 1; j <= m; j++)
		{
			if (i == 1 && j == 1)
			{
				A[i][j] = (S[i][j] == '#');
				continue;
			}
			if (i == 1)
			{
				A[i][j] = A[i][j - 1] + (S[i][j] == '#' && S[i][j - 1] == '.');
				continue;
			}
			if (j == 1)
			{
				A[i][j] = A[i - 1][j] + (S[i][j] == '#' && S[i - 1][j] == '.');
				continue;
			}
			A[i][j] = min(A[i][j - 1] + (S[i][j] == '#' && S[i][j - 1] == '.'), A[i - 1][j] + (S[i][j] == '#' && S[i - 1][j] == '.'));
		}
	}
	printf("%d\n", A[n][m]);
}


Measured memory_bytes: 256
n = int(input())

a = list(map(int, input().split()))

b = list(map(int, input().split()))

count = 0

for i in range(n):
    if a[i] < b[i]:
        count += a[i]
        if a[i+1] >= (b[i] - a[i]):
            count += (b[i] - a[i])
            a[i+1] -= (b[i] - a[i])
        else:
            count += a[i+1]
            a[i+1] = 0
    else:
        count += b[i]
print(count)

Measured memory_bytes: 82020
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N = 1e5 + 5;
int fr[N][2];
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	int ma1 = 0, ma2 = 0;
	for (int i = 0, a; i < n; i++) {
		cin >> a;
		if (i & 1) fr[a][1]++;
		else fr[a][0]++;
	}
	vector<pair<int, int> > v1, v2;
	for (int i = 0; i < N; i++) {
		v1.push_back( { fr[i][0], i });
		v2.push_back( { fr[i][1], i });
	}
	sort(v1.rbegin(), v1.rend());
	sort(v2.rbegin(), v2.rend());
	int ans = 0;
	for (int i = 0; i < 2; i++) {
		for (int j = 0; j < 2; j++) {
			if (v1[i].second == v2[j].second) continue;
			ans = max(ans, v1[i].first + v2[j].first);
		}
	}
	cout << n - ans << endl;

	return 0;
}


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

using namespace std;

int n, m;
vector<tuple<int, int, int> > edges;
vector<int> adj[2510], adjRev[2510];
int p;
long long dist[2510];
const long long INF = 1e18;
bitset<2510> isInf, vis1, visN;

void dfs(int u){
    if(vis1[u]) return;

    vis1[u] = 1;

    for(auto v : adj[u]) dfs(v);
}

void dfsRev(int u){
    if(visN[u]) return;

    visN[u] = 1;

    for(auto v : adjRev[u]) dfsRev(v);
}

int main(){
    scanf("%d%d%d", &n, &m, &p);

    while(m--){
        int u, v, w;
        scanf("%d%d%d", &u, &v, &w);
        w -= p;

        edges.emplace_back(u, v, w);
        adj[u].emplace_back(v);
        adjRev[v].emplace_back(u);
    }

    fill(dist + 1, dist + 1 + n, -INF);

    dist[1] = 0;
    for(int i = 0; i < n; i++){
        for(auto k : edges){
            int u, v, w; tie(u, v, w) = k;

            if(dist[u] != -INF && dist[v] < dist[u] + w){
                dist[v] = dist[u] + w;
            }
        }
    }

    for(auto k : edges){
        int u, v, w; tie(u, v, w) = k;

        if(dist[u] != -INF && dist[v] < dist[u] + w){
            dist[v] = dist[u] + w;

            isInf[v] = true;
        }
    }

    dfs(1);
    dfsRev(n);

    for(int i = 1; i <= n; i++){
        if(vis1[i] && visN[i] && isInf[i]) printf("-1\n"), exit(0);
    }

    if(dist[n] == -INF) printf("-1\n");
    else printf("%lld\n", max(0LL, dist[n]));
    
    return 0;
}

Measured memory_bytes: 640
N = input()
s1 = N[1:len(N)]
s2 = N[0:len(N) - 1]
isOk = True
for i in range(1, len(N)-1):
    if s1[i] != s1[i - 1]:
        isOk = False
        break
    else:
        continue

if isOk:
    print('Yes')
    exit(0)

isOk = True
for i in range(1, len(N)-1):
    if s2[i] != s2[i - 1]:
        isOk = False
        break
    else:
        continue

if isOk:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 9016
#include <iostream>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

ll N, T[100];

ll gcd(ll a, ll b) {
  return b > 0 ? gcd(b, a % b) : a;
}

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

int main(void) {
  cin >> N;
  REP(i, 0, N) cin >> T[i];

  ll ans = 1;
  REP(i, 0, N) ans = lcm(ans, T[i]);
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        String s = in.next();
        int ans = 0;
        int mostLeftRed = -1;
        int mostRightRed = -1;
        int mostRightWhite = -1;
        for(int i=0; i<n; i++) {
            char c = s.charAt(i);
            if(mostLeftRed<0 && c=='R') {
                mostLeftRed = i;
            }
            if(c=='R') {
                mostRightRed = i;
            }
            if(c=='W') {
                mostRightWhite = i;
            }
        }
        
        // 石の色反転の技は、使わなくても一緒（未証明）なので、入れ替え操作のことだけ考える。
        int rightRedIndex = mostRightRed;
        for(int i=0; i<=mostRightWhite && i<rightRedIndex; i++) {
            char c = s.charAt(i);
            if(c=='W') {
                ans++;
                // 右から赤を探してくる
                boolean updated = false;
                for(int j=rightRedIndex-1; j>=i; j--) {
                    char c2 = s.charAt(j);
                    if(c2=='R') {
                        rightRedIndex = j;
                        updated = true;
                        break;
                    }
                }
                if(!updated) {
                    // もう除くべき赤は無い
                    break;
                }
            }
        }
        System.out.println(ans);
    }
}


Measured memory_bytes: 40596
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
set<int> a[200005];
int vis[200005]={0};
int cnt=0,minIndex=1;
void dfs(int node)
{
    if (vis[node]==1)
    return;
    vis[node]=1;
    cnt++;
    for (int x: a[node])
    dfs(x);
}
int main()
{
    int n,m;
    scanf("%d%d",&n,&m);
    for (int i=0;i<m;i++)
    {
        int u,v;
        scanf("%d%d",&u,&v);
        a[u].insert(v);
        a[v].insert(u);
    }
    int prev=0,maxi=INT_MIN;
    while (true)
    {
        dfs(minIndex);
        maxi=max(maxi,(cnt-prev));
        if (cnt==n)
        break;
        prev=cnt;
        for (int i=minIndex;i<=n;i++)
        {
            if (vis[i]==0)
            {
                minIndex=i;
                break;
            }
        }
    }
    printf("%d\n",maxi);
    return 0;
}

Measured memory_bytes: 38916
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
//#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    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;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        ll a,b;
        cin>>a>>b;
        cout<<max({a+b,a-b,a*b})<<endl;
    }

Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <vector>
#include <list>

using std::list;
using std::max;
using std::min;
using std::vector;

long long color_table[31][31];
long long cell[501][501];

long long cost[3][31];

void try_color(int edge_len, int group, int color)
{
  for(int x = 1; x <= edge_len; x++) {
    for(int y = 1; y <= edge_len; y++) {
      int remainder = (x + y) % 3;
      if(remainder != group) {
        continue;
      }
      cost[group][color] += color_table[cell[x][y]][color];
    }
  }
}

void try_all_color(int edge_len, int group, int ncolor)
{
  for(int color = 1; color <= ncolor; color++) {
    try_color(edge_len, group, color);
  }
}

void try_all_groups(int edge_len, int ncolor)
{
  for(int group = 0; group < 3; group++) {
    try_all_color(edge_len, group, ncolor);
  }
}

long long solve(int edge_len, int ncolor)
{
  try_all_groups(edge_len, ncolor);
  long long result = LLONG_MAX;
  for(int x = 1; x <= ncolor; x++) {
    for(int y = 1; y <= ncolor; y++) {
      for(int z = 1; z <= ncolor; z++) {
        if(x == y || y == z || z == x) { // not a permutation
          continue;
        }
        result = min(result, cost[0][x] + cost[1][y] + cost[2][z]);
      }
    }
  }
  return result;
}

void init_arrays()
{
  memset(cost, 0, sizeof(cost));
}

int main()
{
  int edge_len, ncolor;
  scanf("%d%d", &edge_len, &ncolor);
  for(int x = 1; x <= ncolor; x++) {
    for(int y = 1; y <= ncolor; y++) {
      scanf("%lld", &color_table[x][y]);
    }
  }
  for(int x = 1; x <= edge_len; x++) {
    for(int y = 1; y <= edge_len; y++) {
      scanf("%lld", &cell[x][y]);
    }
  }
  printf("%lld\n", solve(edge_len, ncolor));
  return 0;
}


Measured memory_bytes: 2176
class UF:
    def __init__(self, N):
        self.uf = [-1]*N
        self.n = N

    def find(self, x):
        if self.uf[x]<0: return x
        self.uf[x] = self.find(self.uf[x])
        return self.uf[x]

    def size(self, x):
        return -self.uf[self.find(x)]

    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x==y: return
        if self.size(x) > self.size(y): x, y = y, x
        self.uf[y] += self.uf[x]
        self.uf[x] = y
        self.n -= 1

N, M, K = map(int, input().split())
uf = UF(N)

F = [0]*N # number of friends
for _ in range(M):
    A, B = map(int, input().split())
    uf.union(A-1, B-1)
    F[A-1] += 1
    F[B-1] += 1

G = [0]*N # number of candidates
for i in range(N):
    G[i] = uf.size(i) - F[i] - 1

for _ in range(K):
    C, D = map(int, input().split())
    if uf.find(C-1)!=uf.find(D-1): continue

    G[C-1] -= 1
    G[D-1] -= 1

print(*G)

Measured memory_bytes: 10984
# -*- coding: utf-8 -*-
s = input()
t = input()

ans = len(t)

for i in range(len(s)-len(t)+1):
    dif = 0
    for j in range(len(t)):
        if s[j+i] != t[j]:
            dif += 1

    ans = min(ans, dif)

print(ans)


Measured memory_bytes: 9092
use std::vec::Vec;
use std::collections::VecDeque;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let (h, w) = {
        let v: Vec<usize> = read_vec();
        (v[0], v[1])
    };


    for i in 0..h+2 {
        if i == 0 || i == h+1 {
           let line: String = vec!['#'; w+2].into_iter().collect();
           println!("{}", line);
        } else {
            let line: String = read();
            println!("#{}#", line);
        }
    }
}


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


void solve(long long N, std::vector<std::string> S){
    bool y_flag = false;
    // for (int i=0; i<N; i++) {
    //     if (S[i] == "Y") {
    //         y_flag = true;
    //         break;
    //     }
    // }
    for (auto s: S) {
        if (s == "Y") {
            y_flag = true;
            break;
        }
    }
    if (y_flag) cout << "Four" << endl; else cout << "Three" << endl;
}

// Generated by 1.1.7.1 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    std::vector<std::string> S(N);
    for(int i = 0 ; i < N ; i++){
        std::cin >> S[i];
    }
    solve(N, std::move(S));
    return 0;
}


Measured memory_bytes: 3660
#include <iostream>
#include <vector>

using namespace std;

int gcd(int n, int m) {
	if (n < m) {
		swap(n,m);
	}
	if (m == 0) {
		return n;
	}
	return gcd(m,n%m);
}

int main(void) {
	int n,m;
	cin >> n >> m;
	cout << gcd(n,m) << endl;
	return 0;
}



Measured memory_bytes: 3104
n=int(input())
s=input()
ans=0
for i in range(1000):
  a=[str(i//100),str(i//10%10),str(i%10)]
  
  k=0
  b=0
  for j in range(n):
    if a[b]==s[j]:
      b+=1
    if b==3:
      k=1
      break
  if k:
    ans+=1
print(ans)

Measured memory_bytes: 41436
N,M=map(int, input().split())
L=[[] for _ in range(N)]
for i in range(M):
    a,b=map(int, input().split())
    L[a-1].append(b-1)
    L[b-1].append(a-1)

first=L[0]
ok=False
for f in first:
    if N-1 in L[f]:
        ok=True
        break
if ok:
    print("POSSIBLE")
else:
    print("IMPOSSIBLE")

Measured memory_bytes: 38296
#include <cstdio>

const int MAXN = 55;

int n, cnt;
int arr[MAXN];

int main() {
    scanf("%d", &n);
    for (int i = 1; i <= n; ++i) {
        scanf("%d", &arr[i]);
        if (arr[i] != i) 
            ++cnt;
    }
    if (cnt > 2)
        printf("NO");
    else 
        printf("YES");
    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
    int S;
    scanf("%d", &S);
    int h = S / (60 * 60);
    int m = (S % 3600) / 60;
    int s = S % 60;
    printf("%d:%d:%d\n", h, m, s);
    return 0;
}


Measured memory_bytes: 2692
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n, i, k, j, p;
    cin>>n>>k;
    int arr[n], dp[n];
    for(i = 0; i < n; i++)
    {
        dp[i] = INT_MAX;
        cin>>arr[i];
    }
    dp[0] = 0;
    for(i = 1; i < n; i++)
    {
        j = i - 1;
        p = 0;
        while(p < k && j >= 0)
        {
         	dp[i] = min(dp[i], dp[j] + abs(arr[i] - arr[j]));
            p++;
            j--;
        }
    }
    cout<<dp[n-1];
return 0;
}
  

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<cstdlib>
using namespace std;
template<class T> inline bool chmax(T& a, T b){
    if (a < b){
        a = b;
        return 1;
    }
    return 0;
}
template<class T> inline bool chmin(T& a, T b){
    if(a > b){
        a = b;
        return 1;
    }
    return 0;
}

const long long INF = 1LL << 60;

int N;
long long h[100010];
long long dp[100010];

int main(){
    int N;
    cin >> N;
    for (int i = 0; i < N; ++i){
        cin >> h[i];
    }

    for (int i = 0; i < 100010; ++i) {
        dp[i] = INF;
    }

    dp[0] = 0;

    for (int i = 1; i < N; ++i){
        chmin(dp[i], dp[i - 1] + abs(h[i] - h[i - 1]));
        if(i > 1){
            chmin(dp[i], dp[i - 2] + abs(h[i] - h[i - 2]));
        }
    
    }


    cout << dp[N-1] << endl;

}








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

int main() {
    int A, B, C, X, Y;
    cin >> A >> B >> C >> X >> Y;
    long long ans = 1LL << 40;
    for (int i = 0; i <= 2 * max(X, Y); i += 2) {
        ans = min(ans, (long long)(max(0, X - i / 2) * A + max(0, Y - i / 2) * B + i * C));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
open Printf
open Scanf

let solve s t =
  let l = String.length s in
  let rec loop ct i =
    if i = l then ct else
      if s.[i] = t.[i] then loop ct (i + 1)
      else loop (ct + 1) (i + 1) in
  loop 0 0

let () =
  scanf "%s %s " solve |> printf "%d\n"


Measured memory_bytes: 4600
package main

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

func main() {
	N := nextInt()
	A := nextString()
	B := nextString()
	C := nextString()
	cnt := 0
	for i := 0; i < N; i++ {
		if A[i] == B[i] && A[i] == C[i] {
			cnt += 0
		} else if A[i] == B[i] || A[i] == C[i] || B[i] == C[i] {
			cnt += 1
		} else {
			cnt += 2
		}
	}
	fmt.Println(cnt)
}

var dy = []int{1, 0, -1, 0, 0}
var dx = []int{0, 1, 0, -1, 0}
var intmax = int(1e9)

func pow(a, b int) int {
	return int(math.Pow(float64(a), float64(b)))
}

func lcm(a, b int) int {
	return a * b / gcd(a, b)
}
func gcd(a, b int) int {
	if a < b {
		a, b = b, a
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}
func max(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r < a[i] {
			r = a[i]
		}
	}
	return r
}
func min(a ...int) int {
	r := a[0]
	for i := 0; i < len(a); i++ {
		if r > a[i] {
			r = a[i]
		}
	}
	return r
}
func sum(a []int) (r int) {
	for i := range a {
		r += a[i]
	}
	return r
}
func abs(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

type pair struct {
	a, b int
}

type pairs []pair

func (p pairs) Len() int {
	return len(p)
}
func (p pairs) Swap(i, j int) {
	p[i], p[j] = p[j], p[i]
}

func (p pairs) Less(i, j int) bool {
	return p[i].b < p[j].b
}

var nextReader func() string

func init() {
	nextReader = newScanner()
	log.SetFlags(log.Lshortfile)
}

func newScanner() func() string {
	r := bufio.NewScanner(os.Stdin)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)
	return func() string {
		r.Scan()
		return r.Text()
	}
}
func nextString() string {
	return nextReader()
}
func nextInt64() int64 {
	v, _ := strconv.ParseInt(nextReader(), 10, 64)
	return v
}
func nextInt() int {
	v, _ := strconv.Atoi(nextReader())
	return v
}
func nextInts(n int) []int {
	r := make([]int, n)
	for i := 0; i < n; i++ {
		r[i] = nextInt()
	}
	return r
}
func nextFloat64() float64 {
	f, _ := strconv.ParseFloat(nextReader(), 64)
	return f
}


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

const long long mod = 1e9 + 7;

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

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

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

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

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

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

struct UnionFind {
  vector<int> d;
  UnionFind(int n=0): d(n,-1) {}
  int find(int x) {
    if (d[x] < 0) return x;
    return d[x] = find(d[x]);
  }
  bool unite(int x, int y) {
    x = find(x); y = find(y);
    if (x == y) return false;
    if (d[x] > d[y]) swap(x,y);
    d[x] += d[y];
    d[y] = x;
    return true;
  }
  bool same(int x, int y) { return find(x) == find(y);}
  int size(int x) { return -d[find(x)];}
};

int main(){
    int n, m;
    cin >> n >> m;
    UnionFind uf(n);
    rep(i, m) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        uf.unite(a, b);
    }
    int ans = 0;
    rep(i, n) {
        ans = max(ans, uf.size(i));
    }
    cout << ans << endl;
    return 0;
}


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

#define pb push_back

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

const ll INF = 1<<30;
const ll MOD = 1e9+7;

int main(){
	string s;
	vector<int> dp[2];

	cin>>s;

	int n = s.size();
	dp[0].assign(n+1, 0);
	dp[1].assign(n+1, 0);

	for(int i=n-1;i>=0;i--){
		dp[0][i] = min(s[i]-'0'+dp[0][i+1], 1+10-(s[i]-'0')+dp[1][i+1]);
		dp[1][i] = min(-1+10-(s[i]-'0')+dp[1][i+1], s[i]-'0'+dp[0][i+1]);
	}

	cout<<dp[0][0]<<"\n";

	return 0;
}

/*

93
100-10

53

*/

Measured memory_bytes: 12100
#pragma once
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <iostream>
#include <utility>
#include <set>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <deque>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
int t[101];
int pri[26];
int res = 0;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int pr[100010];
void uini(int n) {
	for (size_t i = 0; i <= n; i++)
	{
		pr[i] = i;
	}
}

int parent(int x) {
	if (x == pr[x]) return x;
	return pr[x] = parent(pr[x]);
}

bool unit(int x, int y) {
	int px = parent(x);
	int py = parent(y);

	if (px == py) return false;
	if (px < py) {
		pr[py] = px;
	}
	else {
		pr[px] = py;
	}
	return true;
}
bool comp(string left, string right) {
	if (left.size() != right.size()) return false;
	
	for (size_t i = 0; i < left.size(); i++)
	{		
		if (left[i] != right[i]) return false;
	}
	return true;
}
bool rec(string s, string ori, int in) {
	if (ori.size() < in) {

		if (comp(s ,"AKIHABARA")) {
			return true;
		}
		return false;
	}
	bool res = rec(s + "A" + (in < ori.size() ? string(1,ori[in]) : ""), ori, in + 1);
	res |= rec(s + (in < ori.size() ? string(1, ori[in]) : ""), ori, in + 1);
	return res;
}
void solv() {
	string ak = "AKIHABARA";

	string s;
	cin >> s;
	if (s.size() > ak.size()) {
		cout << "NO" << endl;
		return;
	}
	if (s == ak) {
		cout << "YES" << endl;
		return;
	}
	bool res = rec("", s, 0);
	if (res) {
		cout << "YES" << endl;
	}
	else cout << "NO" << endl;
}


int main() {
	solv();

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define FOr(i,x,y)  for(ll i=x;i>=y;--i)
#define For(i,x,y)	for(ll i=x;i<=y;++i)
using namespace std;
namespace SHENZHEBEI{
#ifdef LOCAL
	struct szb{	szb(){	freopen("shenzhebei.in","r",stdin);	}	}shenzhebei;
#endif
#define NEG 1
	const int L=2333333;
	char SZB[L],*S=SZB,*T=SZB;
	inline char gc(){	if (S==T){	T=(S=SZB)+fread(SZB,1,L,stdin);	if (S==T) return '\n';	}	return *S++;	}
#if NEG
	inline ll readint(){	ll x=0,f=1;	char ch=gc();	for (;!isdigit(ch);ch=gc())	if (ch=='-') f=-1;	for (;isdigit(ch);ch=gc())	x=x*10-48+ch;	return x*f;	}
	inline void write(ll x){	if (x<0)	putchar('-'),x=-x;	if (x>=10)	write(x/10);	putchar(x%10+'0');	}
#else
	inline ll readint(){	ll x=0;	char ch=gc();	for (;!isdigit(ch);ch=gc());	for (;isdigit(ch);ch=gc())	x=x*10-48+ch;	return x;	}
	inline void write(ll x){	if (x>=10)	write(x/10);	putchar(x%10+'0');	}
#endif
	inline char readchar(){	char ch=gc();	for(;isspace(ch);ch=gc());	return ch;	}
	inline ll readstr(char *s){	char ch=gc();	int cur=0;	for(;isspace(ch);ch=gc());		for(;!isspace(ch);ch=gc())	s[cur++]=ch;	s[cur]='\0';	return cur;	}
	inline void writeln(ll x){	write(x);	puts("");	}
}using namespace SHENZHEBEI;
const ll N=200010;
ll n,m,a[N],ans,sum1[N],anst[N],sum2[N],answ;
ll calc(ll x,ll y){	return x>=y?x-y:(x+m-y);	}
int main(){
	n=readint();	m=readint();
	For(i,1,n)	a[i]=readint();
	For(i,2,n){
		ll t=calc(a[i],a[i-1]);
		ans+=calc(a[i],a[i-1]);
		if (t>=2){
			sum1[a[i-1]+2]++;
			sum1[a[i-1]+t+1]--;
			sum2[a[i-1]+t+1]-=t-1;
		}
	}
	ll sum=0,sgr=0;
	For(i,1,2*m){
		sgr+=sum1[i];
		sum=sum+sgr+sum2[i];
		anst[i>m?i-m:i]+=sum;
	}answ=ans;
	For(i,1,m)	answ=min(answ,ans-anst[i]);
	writeln(answ);
}

Measured memory_bytes: 7680
A,B,C,X,Y=list(map(int, input().split()))
mini=1*10**10
Z=max(X,Y)
for i in range(Z+1):
  sum=A*(max(X-i,0))+B*max(Y-i,0)+C*2*i
  if sum<mini:
    mini=sum
print(mini)

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

using i64 = int64_t;

#define rep(i, x, y) for (i64 i = i64(x), i##_max_for_repmacro = i64(y); i < i##_max_for_repmacro; ++i)
#define debug(x) #x << "=" << (x)

#ifdef DEBUG
#define _GLIBCXX_DEBUG
#define print(x) std::cerr << debug(x) << " (L:" << __LINE__ << ")" << std::endl
#else
#define print(x)
#endif

const int inf = 1.01e9;
const i64 inf64 = 4.01e18;
const double eps = 1e-9;

template <typename T, typename U>
ostream &operator<<(ostream &os, const pair<T, U> &p) {
    os << "(" << p.first << ", " << p.second << ")";
    return os;
}

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

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

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

template<typename T, size_t size> void fill(T (&ary)[size], const T& val){
    fill_n((T*)ary, size, val);
}
i64 gcd(i64 a, i64 b) {
    if (b == 0) return a;
    return gcd(b, a % b);
}
i64 lcm(i64 a, i64 b) {
    return a / gcd(a, b) * b;
}



i64 f(i64 n,i64 c,i64 d){
    return n-n/c-n/d+n/lcm(c,d);
}

void solve() {
    //const i64 mod = 1'000'000'007;

    i64 A,B,C,D;
    cin >> A >> B >> C >> D;

    cout << f(B,C,D) - f(A-1,C,D) << endl;
}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}


Measured memory_bytes: 256
import bisect
n = int(input())
lis = list(map(int, input().split()))
lis.sort()

mid = (lis[-1] + 1) // 2
p = bisect.bisect_left(lis, mid)
x = abs(lis[p] - mid)
y = abs(lis[p-1] - mid)

if x >= y:
    print(lis[-1], lis[p-1])
else:
    print(lis[-1], lis[p])


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

int main()
{
    int n,a =0,b=0;
    cin>>n ;
    int arr [n];
    for (int i=0;i<n;i++)
        cin>>arr[i];

    sort (arr,arr+n);

   for (int i=0;i<n;i++)
   {
       if(i%2==1)
        a=a+arr[i];
       else if (i%2==0)
         b=b+arr[i];
   }
   cout<<abs(a-b) ;
}


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

int main(){
    int n; cin >> n; int a[n], b[n], c[n], i;
    for(i = 0; i < n; i++)  cin >> a[i] >> b[i] >> c[i];
    for(i = 1; i < n; i++){
        a[i] += max(b[i-1], c[i-1]);
        b[i] += max(a[i-1], c[i-1]);
        c[i] += max(a[i-1], b[i-1]);
    }
    cout << max(a[n-1], max(b[n-1], c[n-1])) << endl;
    return 0;
}


Measured memory_bytes: 1408
#include<iostream> 
#include<iomanip> 
#include<vector> 
#include<map> 
#include<set> 
#include<algorithm> 
#include<numeric> 
#include<limits> 
#include<bitset> 
#include<functional> 
#include<type_traits> 
#include<queue> 
#include<stack> 
#include<array> 
#include<random> 
#include<utility> 
#include<cstdlib> 
#include<ctime>
//#define _LIBCPP_DEBUG 0
//#define _GLIBCXX_DEBUG
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
#define all(a) (a).begin(),(a),end()
#define rep(i,n) for (ll i = 0; i < (ll)(n); ++i)	

int max(int a, int b) {
	int max;
	if (a > b) max = a;
	else max = b;
	return max;
}
int min(int a, int b) {
	int min;
	if (a < b) min = a;
	else min = b;
	return min;
}


int main(){
	int x, y, z;
	cin >> x >> y >> z;

	cout << z << " " << x << " " << y << endl;
} 

Measured memory_bytes: 3168
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main() 
{
	long N;
	cin >> N;
	vector<string> W(N);
	for (long i = 0; i < N; i++) cin >> W[i];
	string ans = "Yes";
	for (long i = 1; i < N; i++) {
		//過去に使用した文字列をつかっていないか
		for (long j = 0; j < i; j++)
			if (W[i] == W[j]) ans = "No";
		//前回の文字列の最後の文字を最初に使っているか
		if (W[i - 1].back() != W[i].front()) ans = "No";
		//ルールを破っていれば脱出
		if (ans == "No") break;		
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define eb emplace_back
#define pb push_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define chmin(x,y) if(x>y)x=y
#define chmax(x,y) if(x<y)x=y
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll,vector<ll>,greater<ll>> SPQ;
using vi=vector<ll>;
using vvi=vector<vector<ll>>;
using vc=vector<char>;
using vvc=vector<vector<char>>;
const ll inf=1001001001001001;
const int Inf=1001001001;
const int mod=1000000007;
int main(){
    string s;cin>>s;
    ll n=s.size();
    if(s[n-1]=='1'){
        cout<<-1<<endl;
        return 0;
    }
    rep(i,n/2){
        if(s[i]!=s[n-i-2]){
            cout<<-1<<endl;
            return 0;
        }
    }
  	if(s[0]=='0'){
      cout<<-1<<endl;
      return 0;
    }
    cout<<1<<' '<<2<<endl;
    int a=2,b;
    rep(i,n-2){
        if(s[i]=='0')cout<<b<<' '<<i+3<<endl;
        else{
            cout<<a<<' '<<i+3<<endl;
          	b=a;
            a=i+3;
        }
    }
}

Measured memory_bytes: 1664
#include <iostream>
#include <cstdio>
#include <algorithm>

using namespace std;

#define NIL -1
#define MAX 10000

struct Node{
	int parent,
		left,
		right;
};

struct Node T[MAX];
int H[MAX],D[MAX],type[MAX];

void setDepth(int u, int d){
	//if(u = NIL) return; 
	D[u] = d;
	if(T[u].left != NIL) setDepth(T[u].left, d+1);
	if(T[u].right != NIL) setDepth(T[u].right, d+1);
}

int setHight(int u){
	int h1=0,h2=0;
	if(T[u].left != NIL){
		h1 = setHight(T[u].left)+1;
	}
	if(T[u].right != NIL){
		h2 = setHight(T[u].right)+1;
	}
	return H[u]=max(h1,h2);
}

void print(int u){
	int sib;
	if(T[u].parent==NIL){
		sib = -1;
	}else{
		if(u == T[T[u].parent].left){
			if(T[T[u].parent].right != NIL){
				sib = T[T[u].parent].right;
			}else{
				sib = -1;
			}
		}else{
			if(T[T[u].parent].left != NIL){
				sib = T[T[u].parent].left;
			}else{
				sib = -1;
			}
		}
	}
	
	int deg=0;
		if(T[u].left != NIL) deg++;
		if(T[u].right != NIL) deg++;
	
	cout<<"node "<<u<<": "<<"parent = "<<T[u].parent;
	cout<<", sibling = "<<sib<<", degree = "<<deg<<", depth = "<<D[u]<<", height = "<<H[u];
	
	if(T[u].parent == NIL){
		cout<<", root"<<endl;
	}else if(T[u].left==NIL && T[u].right==NIL){
		cout<<", leaf"<<endl;
	}else{
		cout<<", internal node"<<endl;
	}

}

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

	for(int i=0; i<n; i++){
		T[i].parent = NIL;
	}

	int v,l,r;
	for(int i=0; i<n; i++){
		scanf("%d %d %d",&v,&l,&r);
		T[v].left = l;
		T[v].right = r;
		if(l!=NIL) T[l].parent = v;
		if(r!=NIL) T[r].parent = v;
	}
	
	int root;
	for(int i=0; i<n; i++){
		if(T[i].parent == NIL) root=i;	
	}
	
	setHight(root);
	setDepth(root, 0);
	
	for(int i=0; i<n; i++){
		print(i);
	}

	return 0;
}

Measured memory_bytes: 1260
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

int D;
vector<int> c(26);
vector<vector<int>> s;

struct Data{
	vector<int> t;
	vector<vector<int>> penalty;
	int score;
	
	Data(){
		t.resize(D,0);
		penalty.resize(D+1,vector<int>(26,0));
		score = 0;
	}
};

void init(){
	cin>>D;
	for(int i=0;i<26;i++)scanf("%d",&c[i]);
	
	s.resize(D,vector<int>(26));
	for(int i=0;i<D;i++){
		for(int j=0;j<26;j++)scanf("%d",&s[i][j]);
	}
}

Data generate(vector<int> t){
	Data ret;
	ret.t = t;
	vector<int> last(26,0);
	for(int i=0;i<t.size();i++){
		int temp = t[i];
		ret.score += s[i][temp];
		last[temp] = i+1;
		
		for(int j=0;j<26;j++){
			ret.penalty[i+1][j] = ret.penalty[i][j] + c[j];
			if(temp==j)ret.penalty[i+1][j] = 0;
			ret.score -= ret.penalty[i+1][j];
		}
	}
	return ret;
}

int change(Data &d,int ind,int nv){
	int o_score = d.score;
	int ov = d.t[ind];
	d.score += s[ind][nv];
	d.score -= s[ind][ov];
	d.t[ind] = nv;
	for(int i=ind+1;i<=D;i++){
		d.score += d.penalty[i][nv];
		d.score += d.penalty[i][ov];
		if(i==ind+1){
			d.penalty[i][nv] = 0;
			d.penalty[i][ov] = d.penalty[i-1][ov] + c[ov];
		}
		else{
			if(d.penalty[i][nv]!=0){
				d.penalty[i][nv] = d.penalty[i-1][nv]+c[nv];
			}
			if(d.penalty[i][ov]!=0){
				d.penalty[i][ov] = d.penalty[i-1][ov]+c[ov];
			}
		}
		d.score -= d.penalty[i][nv];
		d.score -= d.penalty[i][ov];
	}
	
	return d.score - o_score;
}

int main(){
	
	init();
	
	vector<int> t(D);
	for(int i=0;i<D;i++){
		int maxi = -1;
		int ind = 0;
		for(int j=0;j<26;j++){
			if(maxi < s[i][j]){
				maxi = s[i][j];
				ind = j;
			}
		}
		t[i] = ind;
	}
	Data d = generate(t);

	for(int i=0;i<D;i++){
		printf("%d\n",d.t[i]+1);
	}
	
	return 0;
}

Measured memory_bytes: 3896
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<ll, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << #i <<" "<<i<<std::endl;
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;


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

  std::string s;
  std::cin>>s;

  ll n=s.size();

  if(s[0]=='0'||s[n-1]=='1'){
    std::cout<<-1;
    return 0;
  }

  rep(i,0,n-1){
    if(s[i]!=s[n-2-i]){
      std::cout<<-1;
      return 0;
    }
  }

  s[n-1]='1';

  ll min=n-1;

  for(ll i=n-2;i>=0;i--){
    std::cout<<i+1<<" "<<min+1<<"\n";
    if(s[i]=='1')min=i;
  }

  return 0;
}





Measured memory_bytes: 1616
h, w, a, b = map(int, input().split())
mod = 1000000007

def modpow(x, y):   
    if   y == 0     : return 1
    elif y == 1     : return x % mod
    elif y % 2 == 0 : return modpow(x, y//2)**2 % mod
    else            : return modpow(x, y//2)**2 * x % mod

stairs = [1]
for i in range(1, h+w+1):
    stairs.append(stairs[i-1]*i%mod)

inverse_stairs = [0]*(h+w)
inverse_stairs[h+w-1] = modpow(stairs[h+w-1], mod-2)
for i in range(h+w-2, -1, -1):
    inverse_stairs[i] = inverse_stairs[i+1] * (i+1) % mod
    
ret = 0
for i in range(w-b):
    com = stairs[w-i+h-a-2]%mod
    com = com*inverse_stairs[w-i-1]%mod
    com = com*inverse_stairs[h-a-1]%mod
    com = com*stairs[i+a-1]%mod
    com = com*inverse_stairs[i]%mod
    com = com*inverse_stairs[a-1]%mod
    ret += com

print(ret%mod)

Measured memory_bytes: 18988
#include <bits/stdc++.h>
#define REP(i, a, n) for(ll i = ((ll) a); i < ((ll) n); i++)
using namespace std;
typedef long long ll;

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

  if(S.length() == 26) {
    for(ll i = 25; i > 0; i--) if(S[i] > S[i - 1]) {
      char t = 'z';
      REP(j, i, 26) if(S[i - 1] < S[j]) t = min(t, S[j]);
      cout << S.substr(0, i - 1) << (char) t << endl;
      return 0;
    }
    cout << -1 << endl;
    return 0;
  } else {
    REP(i, 0, 26) {
      bool ok = true;
      REP(j, 0, S.length()) if(S[j] == 'a' + i) ok = false;
      if(ok) {
        cout << S << (char) ('a' + i) << endl;
        return 0;
      }
    }
  }
}


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

int main(void){
  int N,M; 
  cin>>N>>M;
  
  string A[N],B[M];
  rep(i,0,N) cin >>A[i];
  rep(i,0,M) cin >>B[i];
  
  bool exist=false;
  rep(ly,0,N){
    rep(lx,0,N){
      if(ly+M-1>=N or lx+M-1>=N) continue;
      bool match=true;
      rep(y,0,M){
        rep(x,0,M){
          if(A[ly+y][lx+x]!=B[y][x]) match=false;
        }
      }
      if(match) exist=true;
    }
  }
  string ans;
  if(exist) ans = "Yes";
  else ans = "No";
  
  cout <<ans<< endl;
}

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

int main() {
	int a, b, c; cin >> a >> b >> c;
	if(c == max({a, b, c}) || c == min({a, b, c})) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
inline int read()
{
	int x=0,f=1;
	char ch=getchar();
	while(ch<'0'||ch>'9')
	{
		if(ch=='-')f=-1;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9')
	{
		x=(x<<3)+(x<<1)+ch-'0';
		ch=getchar();
	}
	return x*f;
}


int main()
{
	int a=read(),b=read();
	int c=a+b,d=a-b,e=a*b;
	int ans=max(c,max(d,e));
	printf("%d",ans); 
	return 0;
 } 

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

int main(){
    int N,_max = 0, count = 0, num, prev = 0;
    cin >> N;
    cin >> prev;
    rep(i, N-1){
        cin >> num;
        if(prev < num){
            _max = max(_max, count);
            count = 0;
        }else{
            count++;
        }
        prev = num;
    }
    _max = max(_max, count);
    cout << _max;
}


Measured memory_bytes: 256
from heapq import heappop, heappush

N, M = map(int, input().split())
A = list(map(lambda x: (-1)*int(x), input().split()))

H = []

for i in A:
  heappush(H, i)

for _ in range(M):
  m = (-1) * heappop(H)
  m //= 2
  heappush(H, (-1)*m)

print((-1)*sum(H))

Measured memory_bytes: 14180
#include <stdio.h>

int main(void)
{
    int m, f, r;
    
    while(1){
        scanf("%d %d %d", &m, &f, &r);
        if(m == -1 && f == -1 && r == -1){
            break;
        }else if(m == -1 || f == -1){
            printf("F\n");
        }else if(m + f >= 80){
            printf("A\n");
        }else if(m + f >= 65 && m + f < 80){
            printf("B\n");
        }else if(m + f >= 50 && m + f < 65){
            printf("C\n");
        }else if(m + f >= 30 && m + f < 50){
            if(r >= 50){
                printf("C\n");
                continue;
            }
            printf("D\n");
        }else if(m + f < 30){
            printf("F\n");
        }
    }

    return 0;
}


Measured memory_bytes: 2096
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef vector<pair<ll, ll>> pll;
 
#define mod 1000000007
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
ll stringcount(string s, char c){return count(s.cbegin(), s.cend(), c);}
bool isInteger(double x){return floor(x) == x;}

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

  ll a, b;
  cin >> a >> b;
  cout << max({a+b, a-b, a*b}) << endl;
  return 0;
}

Measured memory_bytes: 256
// atcoder/abc175/A/main.cpp
// author: @___Johniel
// github: https://github.com/johniel/

#include <bits/stdc++.h>

#define each(i, c) for (auto& i : c)
#define unless(cond) if (!(cond))

using namespace std;

template<typename P, typename Q> ostream& operator << (ostream& os, pair<P, Q> p) { os << "(" << p.first << "," << p.second << ")"; return os; }
template<typename P, typename Q> istream& operator >> (istream& is, pair<P, Q>& p) { is >> p.first >> p.second; return is; }
template<typename T> ostream& operator << (ostream& os, vector<T> v) { os << "("; for (auto& i: v) os << i << ","; os << ")"; return os; }
template<typename T> istream& operator >> (istream& is, vector<T>& v) { for (auto& i: v) is >> i; return is; }
template<typename T> ostream& operator << (ostream& os, set<T> s) { os << "#{"; for (auto& i: s) os << i << ","; os << "}"; return os; }
template<typename K, typename V> ostream& operator << (ostream& os, map<K, V> m) { os << "{"; for (auto& i: m) os << i << ","; os << "}"; return os; }

template<typename T> inline T setmax(T& a, T b) { return a = std::max(a, b); }
template<typename T> inline T setmin(T& a, T b) { return a = std::min(a, b); }

using lli = long long int;
using ull = unsigned long long;
using point = complex<double>;
using str = string;
template<typename T> using vec = vector<T>;

constexpr array<int, 8> di({0, 1, -1, 0, 1, -1, 1, -1});
constexpr array<int, 8> dj({1, 0, 0, -1, 1, -1, -1, 1});
constexpr lli mod = 1e9 + 7;

int main(int argc, char *argv[])
{
  ios_base::sync_with_stdio(0);
  cin.tie(0);
  cout.setf(ios_base::fixed);
  cout.precision(15);

  str s;
  while (cin >> s) {
    int cnt = 0;
    int mx = 0;
    each (c, s) {
      if (c == 'R') ++cnt;
      else cnt = 0;
      setmax(mx, cnt);
    }
    cout << max(mx, cnt) << endl;
  }

  return 0;
}


Measured memory_bytes: 3652
import sys
sys.setrecursionlimit(10000)


def integrate(x, i, j):
    if x[i-1][j-1] != 1 and x[i-1][j] != 1 and x[i-1][j+1] != 1 \
        and x[i][j-1] != 1 and x[i][j+1] != 1 and x[i+1][j-1] != 1 \
            and x[i+1][j] != 1 and x[i+1][j+1] != 1:
            return 0
    if x[i-1][j] == 1:
        x[i-1][j] = 0
        integrate(x, i-1, j)
    if x[i-1][j-1] == 1:
        x[i-1][j-1] = 0
        integrate(x, i-1, j-1)
    if x[i+1][j] == 1:
        x[i+1][j] = 0
        integrate(x, i+1, j)
    if x[i+1][j+1] == 1:
        x[i+1][j+1] = 0
        integrate(x, i+1, j+1)
    if x[i][j-1] == 1:
        x[i][j-1] = 0
        integrate(x, i, j-1)
    if x[i+1][j-1] == 1:
        x[i+1][j-1] = 0
        integrate(x, i+1, j-1)
    if x[i][j+1] == 1:
        x[i][j+1] = 0
        integrate(x, i, j+1)
    if x[i-1][j+1] == 1:
        x[i-1][j+1] = 0
        integrate(x, i-1, j+1)
    return 0


answer = []

while True:
    w, h = map(int, input().split())
    if w == 0 and h == 0:
        break
    c = [[] for i in range(h+2)]
    c[0] = [2 for i in range(w+2)]

    for i in range(1, h+1):
        c[i].append(2)
        c_i = list(map(int, input().split()))
        c[i].extend(c_i)
        c[i].append(2)

    c[h+1] = [2 for i in range(w+2)]

    count = 0

    for i in range(1, h+1):
        for j in range(1, w+1):
            if c[i][j] == 1:
                c[i][j] = 0
                integrate(c, i, j)
                count += 1

    answer.append(count)

for i in range(len(answer)):
    print(answer[i])



Measured memory_bytes: 7644
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc=new Scanner(System.in);
        int n=sc.nextInt();
        
        if(n>=0){
            if(n==0||n==1)System.out.println(n);
            else{
                n-=2;
                String po="";
                while(n>=0){
                    po=((n%4==0)?"10":(n%4==1)?"11":(n%4==2)?"00":"01")+po;
                    n/=4;
                    n--;
                }
                System.out.println(1+po);
            }
        }
        else{
            n=-2*n;
            n-=2;
            String po="";
            while(n>=0){
                po=((n%4==0)?"10":(n%4==1)?"11":(n%4==2)?"00":"01")+po;
                n/=4;
                n--;
            }
            System.out.println(1+po.substring(0,po.length()-1));
        }
    }
}

Measured memory_bytes: 25172
#include<bits/stdc++.h>
#define mod 1000000007
#define ll long long int
#define mp make_pair
using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int a,b;
	cin>>a>>b;
	int g = b-a;
	if(b>=0 && a<=0)
		cout<<"Zero"<<endl;
	else if(a<0 && b<0) 
	{
		g = abs(g);
		if(g&1) cout<<"Positive"<<endl;
		else
			cout<<"Negative"<<endl;
	}
	else
		cout<<"Positive"<<endl;
	return 0;
}

Measured memory_bytes: 256
def next_arr(a,n,m):
    a[-1] += 1
    for i in range(n)[::-1]:
        if(a[i] > m):
            if(i == 0):
                return(False)
            a[i-1] += 1
            a[i] = a[i-1]
    for i in range(1,n):
        if(a[i] > m):
            a[i] = a[i-1]
    return(True)


n,m,q = map(int,input().split())

a = [0 for _ in range(q)]
b = [0 for _ in range(q)]
c = [0 for _ in range(q)]
d = [0 for _ in range(q)]

for i in range(q):
    A,B,C,D = map(int,input().split())
    a[i] = A
    b[i] = B
    c[i] = C
    d[i] = D

arr = [1 for _ in range(n)]
arr[-1] = 0
ma = 0
while(next_arr(arr,n,m)):
    sc = 0
    for i in range(q):
        if(arr[b[i]-1] - arr[a[i]-1] == c[i]):
            sc += d[i]
    ma = max(sc,ma)
print(ma)

Measured memory_bytes: 9304
// by adiforluls
#pragma GCC optimize ("-O2")
#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define FAST            ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0)
#define ll              long long
#define ld              long double
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define all(a)          (a).begin(),(a).end()
#define clz(a)          __builtin_clz(a) // count leading zeroes
#define ctz(a)          __builtin_ctz(a) // count trailing zeroes
#define popc(a)         __builtin_popcount(a) // count set bits (for ints only diff for ll)
#define rep(i,a,b)      for(ll i=a;i<b;i++)
#define rfor(i,a,b)     for(ll i=a; i>=b; i--)
#define debug(x)        cerr << #x << " = " << x << endl;
#define F               first
#define S               second
#define endl            '\n'
#define SIZE            1000005
#define deci(n)         cout<<fixed<<setprecision(n)
#define ordered_set     tree<pll, null_type,less<pll>, rb_tree_tag,tree_order_statistics_node_update>
// order_of_key(k)
// find_by_order(k)
const ld PI = acos(-1.0);
const int INF = 0x3f3f3f3f;
const ll lul2 = 998244353;
const ll lul = 1000000007;

void mod(ll &x)
{
    if(x>=lul) x-=lul;
    if(x<0) x+=lul;
}

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

ll expo(ll n, ll p)
{
    if(p == 0) return 1;
    ll x = expo((n*n)%lul, p/2)%lul;
    if(p&1) return (x*n)%lul;
    return x;
}
//---------------------------------------------------------------------

ll get(ll n)
{
    ll l = 0, r = 100;
    ll ans = 0;
    while(l<=r)
    {
        ll mid = l + (r-l)/2;
        if(mid*mid + mid<=2*n) ans = mid, l = mid+1;
        else r = mid-1;
    }
    return ans;
}
unordered_map<ll,ll> ma;
void solve()
{
    ll n; cin>>n;
    for(ll i = 2; i*i<=n; i++)
    {
        int cnt = 0;
        while(n%i == 0)
        {
            cnt++;
            n/=i;
        }
        if(cnt!=0) ma[i] = cnt;
    }
    if(n>1) ma[n] = 1;
    ll ans = 0;
    for(auto i:ma)
    {
        ans+=get(i.S);
    }
    cout<<ans;
}
int main()
{   
    FAST;
   //  #ifndef ONLINE_JUDGE
     // freopen("input.txt", "r", stdin);
     // freopen("output.txt", "w", stdout);
   //  #endif
    int t; t=1;
    rep(i,1,t+1){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3660
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;

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

        int N = scanner.nextInt();
        int M = scanner.nextInt();

        Map<Integer, Boolean> isAc = new HashMap<>();
        Map<Integer, Integer> penalties = new HashMap<>();

        for (int i = 1 ; i <= M ; i++) {
            int p = scanner.nextInt();
            String S = scanner.next();

            if (S.equals("WA") && !isAc.getOrDefault(p, false)) {
                penalties.put(p, penalties.getOrDefault(p, 0) + 1);
            } else {
                isAc.put(p ,true);
            }
        }

        int acCount = 0;
        int pCount = 0;
        
        for (int p : isAc.keySet()) {
            acCount++;
            pCount += penalties.getOrDefault(p, 0);
        }

        System.out.printf("%d %d%n", acCount, pCount);

    }
}


Measured memory_bytes: 64732
S=raw_input()
L=len(S)
ans=L


if L%2==0: loop=L/2
else: loop=L/2+1

prev=None
for i in range(loop):
#	print i,L-i-1,S[i],S[L-i-1],S[i]==S[L-i-1],ans
	if S[i]==S[L-i-1]:
		if prev is None:
			pass
		elif prev!=S[i]:
			ans=L-i
		prev=S[i]
	else:
		ans=L-i-1

print ans



Measured memory_bytes: 32284
#include<bits/stdc++.h>
using namespace std;
 
#define REP(i,a,b) for(i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)

int main(){
	int n, m;
	cin >> n >> m;
	cout << (n-1) * (m-1) << endl;

}

Measured memory_bytes: 256