akhauriyash/Code-Regression huggingface dataset:
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use num::*;
use proconio::input;
#[allow(unused_imports)]
use proconio::marker::*;
#[allow(unused_imports)]
use std::collections::*;

use rand::prelude::*;

const CN: usize = 26;

fn calc(cv: &[isize], sv: &[Vec<isize>], tv: &[usize]) -> isize {
    let mut last = vec![0; CN];
    let mut res = 0;
    for i in 0..sv.len() {
        let t = tv[i];
        res += sv[i][t];
        last[t] = i + 1;
        for j in 0..CN {
            res -= cv[j] * (i + 1 - last[j]) as isize;
        }
    }
    res
}

fn gen_tv(rng: &mut rand::rngs::ThreadRng, d: usize) -> Vec<usize> {
    (0..d)
        .into_iter()
        .map(|_| rng.gen::<usize>() % CN)
        .collect::<Vec<_>>()
}

fn main() {
    input! {
        d: usize,
        cv: [isize; CN],
        sv: [[isize; CN]; d],
    };

    let mut rng = rand::thread_rng();
    let mut tv = gen_tv(&mut rng, d);
    let mut res = calc(&cv, &sv, &tv);
    for _ in 0..10000 {
        let tv2 = gen_tv(&mut rng, d);
        let p = calc(&cv, &sv, &tv2);
        if p > res {
            tv = tv2;
            res = p;
        }
    }
    for _ in 0..340000 {
        let di = rng.gen::<usize>() % d;
        let q = rng.gen::<usize>() % CN;
        let old = tv[di];
        tv[di] = q;
        let p = calc(&cv, &sv, &tv);
        if p > res {
            res = p;
        } else {
            tv[di] = old;
        }
    }
    println!("{}", tv.into_iter().map(|x| x + 1).join("\n"));
}


Measured memory_bytes: 2748
import sys
N=input()
A=[ map(int, sys.stdin.readline().split()) for i in range(N) ]

if N==1:
	print max( A[-1] )
	quit()

dp=[ [ 0 for t in range(3) ]  for i in range(N) ] 

#Initialize
a,b,c=A[0][0],A[0][1],A[0][2]

dp[0][0]=a
dp[0][1]=b
dp[0][2]=c


#next
for i in range(N-1):
	a,b,c=A[i+1][0],A[i+1][1],A[i+1][2]

	dp[i+1][1]=max(dp[i+1][1], dp[i][0]+b)
	dp[i+1][2]=max(dp[i+1][2], dp[i][0]+c)

	dp[i+1][0]=max(dp[i+1][0], dp[i][1]+a)
	dp[i+1][2]=max(dp[i+1][2], dp[i][1]+c)

	dp[i+1][0]=max(dp[i+1][0], dp[i][2]+a)
	dp[i+1][1]=max(dp[i+1][1], dp[i][2]+b)

print  max( dp[-1] )


Measured memory_bytes: 52508
#include <algorithm>
#include <iostream>
#include <unordered_map>
#include <vector>
int main(int argc, char *argv[]) {
	size_t n;
	std::cin >> n;
	const size_t n2 = n / 2;
	std::vector<int> e(n2), o(n2);
	for (size_t i = 0; i < n2; i++) {
		std::cin >> e[i] >> o[i];
	}
	std::unordered_map<int, size_t> ume, umo;
	for (size_t i = 0; i < n2; i++) {
		const bool fe = (ume.find(e[i]) != ume.end());
		if (!fe) {
			ume.insert(std::pair<int, size_t>(e[i], 1));
		} else {
			ume[e[i]]++;
		}
		const bool fo = (umo.find(o[i]) != umo.end());
		if (!fo) {
			umo.insert(std::pair<int, size_t>(o[i], 1));
		} else {
			umo[o[i]]++;
		}
	}
	std::vector<std::pair<int, size_t>> ve(ume.begin(), ume.end()), vo(umo.begin(), umo.end());
	std::sort(
		ve.begin(), ve.end(),
		[] (const auto &l, const auto &r) {
			return (l.second > r.second);
		}
	);
	ve.push_back(std::pair<int, size_t>(0, 0)); // NOTE: sentinel
	std::sort(
		vo.begin(), vo.end(),
		[] (const auto &l, const auto &r) {
			return (l.second > r.second);
		}
	);
	vo.push_back(std::pair<int, size_t>(0, 0)); // NOTE: sentinel
	const size_t na =
		(ve[0].first != vo[0].first) ? n - ve[0].second - vo[0].second :
		std::min(
			n - ve[1].second - vo[0].second,
			n - ve[0].second - vo[1].second
		);
	std::cout << na << std::endl;
	return 0;
}

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

int main() {
  int a, b, c, t;
  cin >> a >> b >> c;
  if (b > c) {
    t = c;
    c = b;
    b = t;
  }
  if (a > b) {
    t = b;
    b = a;
    a = t;
  }
  if (b > c) {
    t = c;
    c = b;
    b = t;
  }
  printf("%d %d %d\n", a, b, c);
}


Measured memory_bytes: 3192
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define MOD (1000000007)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()

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

int gcd(int a, int b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int main(){
  string S; cin >> S;
  reverse(all(S));

  vector<string> list = {"resare", "esare", "remaerd", "maerd"};
  string t;

  rep(i, S.size()){
    t += S[i];
    for(auto s : list){
      if(t == s) t = "";
    }
  }

  string ans;
  if(t == "") ans = "YES";
  else ans = "NO";

  std::cout << ans << '\n';
}


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

int main(void){
  int n;
  string s;
  vector<int> a(2,0);
  cin >> n >> s;
  for(int i = 0; i < n; i++){
    if(s[i] == 'R')a[0]++;
    else a[1]++;
  }
  if(a[0] > a[1])cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
    string n;

    cin >> n;
    if (n[0]==n[1] && n[1] == n[2])
    {
        cout << "Yes" << endl;
    }
    else if(n[1]==n[2] && n[2] == n[3])
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    
    
    
}

Measured memory_bytes: 256
def main():
    N = int(input())
    A = [0] + [int(i) for i in input().split()] + [0]
    l = [abs(A[i + 1] - A[i]) for i in range(N + 1)]
    num = sum(l)
    print("\n".join(
        [str(num - l[i] - l[i + 1] + abs(A[i] - A[i + 2]))
         for i in range(N)]))

    return


main()


Measured memory_bytes: 19144
import java.util.*

fun main(args: Array<String>) {
    var scan = Scanner(System.`in`)
    var a=scan.nextLong()
    var count : Long =1
    var ans : Long =0

    while(a>0)
    {
        ans+=count
        a/=2
        count*=2
    }

    print(ans)
}


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

void solve()
{
	int a, b;
	cin >> a >> b;
	
	string s1, s2;
	
	for(int i = 0; i < a; i++)
	{
		s1 += b + '0';
	}
	
	for(int i = 0; i < b; i++)
	{
		s2 += a + '0';
	}
	
	if(s1 < s2)
	{
		cout << s1;
	}
	else
	{
		cout << s2;
	}
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	
	solve();
	
	return 0;
}

Measured memory_bytes: 256
/* package whatever; // don't place package name! */
 
import java.util.*;
import java.lang.*;
import java.io.*;
 
public class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
		Scanner in = new Scanner(System.in);
		String s = in.next();
		System.out.println("2018"+ s.substring(4));
	}
}

Measured memory_bytes: 22612
#define _USE_MATH_DEFINES
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <cassert>
#include <string>
#include <vector>
#include <utility>
#include <complex>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <tuple>
#include <bitset>
#include <limits>
#include <algorithm>
#include <array>
#include <random>
#include <complex>
#include <regex>
#include <iomanip>
using namespace std;
typedef long double ld;
typedef long long ll;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
#define fcout cout << fixed << setprecision(10)
#define rep(i,n)    for(int i=0; i<(int)n; i++)
#define mp(a,b) make_pair(a,b)
#define pb push_back
#define all(x) x.begin(), x.end()
#define F first
#define S second
const ll inf = 1e18;
const ll mod = 1e9 + 7;

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

// mod.m での a の逆元 a^(-1) を計算する。
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while(b){
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

ll modpow(ll a, ll n){
    ll res = 1;
    while(n>0){
        if(n&1){
            res = res * a % mod;
        }
        a = a * a % mod;
        n >>=1;
    }
    return res;
}


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



Measured memory_bytes: 3628
def bingo(board):
    for i in range(3):
        if all(board[i][j] for j in range(3)):
            return True
    for j in range(3):
        if all(board[i][j] for i in range(3)):
            return True
    if all(board[i][i] for i in range(3)):
        return True
    if all(board[i][2-i] for i in range(3)):
        return True

a = []
for _ in range(3):
    a.append(list(map(int, input().split())))

seen = {}
for i in range(3):
    for j in range(3):
        seen[a[i][j]] = (i, j)

board = [[False] * 3 for _ in range(3)]

n = int(input())
for _ in range(n):
    b = int(input())
    if b in seen:
        board[seen[b][0]][seen[b][1]] = True

if bingo(board):
    print('Yes')
else:
    print('No')


Measured memory_bytes: 3064
import sys

def main():
    input = sys.stdin.readline
    N = int(input())
    e, o = 0, 0
    for i in range(1, N+1):
        if i % 2 == 0:
            e += 1
        else:
            o += 1

    return (o) / (e + o)

if __name__ == '__main__':
    print(main())

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

#define SIZE 8

//????????????????????????
bool isWithin(int x, int y){
	return 0 <= x && x < SIZE && 0 <= y && y < SIZE;
}

//x,y:??????????????§?¨?
void explode(int field[SIZE][SIZE], int x, int y){
	field[y][x] = 0;
	int dx[4] = {1, 0, -1, 0};
	int dy[4] = {0, 1, 0, -1};
	for(int i=1;i<=3;i++){//??????????????????3???????¢¨????±????
		for(int j=0;j<4;j++){
			int dstX = x + i * dx[j];
			int dstY = y + i * dy[j];
			if(isWithin(dstX, dstY)){
				if(field[dstY][dstX] == 1){
					explode(field, dstX, dstY);
				}
			}
		}
	}
}


void solve(){
	int field[SIZE][SIZE];
	for(int y=0;y<SIZE;y++){
		char line[9];
		scanf("%s", &line);
		for(int x=0;x<SIZE;x++){
			//'0'?????´???0, '1'?????´???1?????£??\?????????
			field[y][x] = line[x] - '0';
		}
		scanf("\n");
	}
	int fx, fy;//???????????????????????§?¨?(??\??????-1)
	scanf("%d\n%d\n\n", &fx, &fy);
	fx--;
	fy--;
	explode(field,fx,fy);
	
	for(int y=0;y<SIZE;y++){
		for(int x=0;x<SIZE;x++){
			printf("%d", field[y][x]);
		}
		printf("\n");
	}
}

int main() {
	int n;
	scanf("%d\n\n", &n);
	for(int i=0;i<n;i++){
		printf("Data %d:\n", i+1);
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1200
#include <iostream>
#include <string>
#define ll long long
using namespace std;

bool allLettersSame(string s){
  for(char c:s) if(c!=s[0]) return false;
  return true;
}

int main(){
    ll score=0, x=1, n;
    int len, size=1;
    string a;
    cin >> a;
    cin >> n;
    if(allLettersSame(a)){
      cout << n * a.size() / 2 << endl;
      return 0;
    }
    len=a.size()-1;
    for(int i=1; i<=len; i++){
        if(a[i]==a[i-1]){
            size++;
        }
        else{
            score+=size/2;
            size=1;
        }
    }
    score+=size/2;

    int front = 0, back = 0;
    if(a[len]==a[0]){
      for(int i=0; a[i]==a[0]; i++) front++;        
      for(int i=a.size()-1; a[i]==a[0]; i--) back++;
    }
    score*=n;
    if(front%2 == 1 && back%2 == 1){
      score+=(n-1);
    }
    cout << score << endl;
    return 0;
}   

Measured memory_bytes: 3628
package main

import "fmt"

type Point struct {
	x int
	y int
}

const max = 1000000000001

func myAbs(a int, b int) (c int) {
	c = a - b
	if c < 0 {
		return -c
	} else {
		return c
	}
}

func man(p Point, q Point) int {
	return myAbs(p.x, q.x) + myAbs(p.y, q.y)
}

func main() {
	var n, m int
	fmt.Scan(&n, &m)
	s := make([]Point, n)
	for i:=0; i<n; i++ {
		fmt.Scan(&s[i].x, &s[i].y)
	}
	c := make([]Point, m)
	for i:=0; i<m; i++ {
		fmt.Scan(&c[i].x, &c[i].y)
	}
	for _, p := range s {
		min_p := 1
		min := max
		for i, q := range c {
			t := man(p, q)
			if min > t {
				min_p = i
				min = t
			}
		}
		fmt.Println(min_p + 1)
	}

}


Measured memory_bytes: 512
'use strict'

const main = input => {
	const args = input.split('\n').map(t => t.split(' '))
	const n = parseInt(args[0][0], 10)
	const l = parseInt(args[0][1], 10)
	let min = Infinity
	let res = null

	let all = 0

	for (let i = 0; i < n; i++) {
		all += l + i
	}

	for (let i = 0; i < n; i++) {
		let eat = 0

		for (let j = 0; j < n; j++) {
			if (i === j) continue
			eat += l + j
		}

		const t1 = Math.abs(eat - all)

		if (t1 < min) {
			min = t1
			res = eat
		}
	}

	console.log(res)
}

main(require('fs').readFileSync('/dev/stdin', 'utf8'))


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

int main() {
  int N;
  cin >> N;
  string S;
  cin >> S;
  
  bool isA = false;
  bool isAB = false;
  int count = 0;
  for (char c : S) {
    if (c == 'A') {
      isA = true;
      isAB = false;
    } else if (c == 'B' && isA) {
      if (isAB) {
        isA = false;
        isAB = false;
        continue;
      }
      isAB = true;
    } else if (c == 'C' && isAB) {
      count++;
      isA = false;
      isAB = false;
    } else {
      isA = false;
      isAB = false;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const ll mod = 1e9 + 7;
int main() {
    int n,k;
    cin>>n>>k;
    vector<int> a(n+1);
    vector<vector<ll>>dp(n+1,vector<ll>(k+1,0));
    vector<vector<ll>>sum(n+1,vector<ll>(k+1,0));

    for(int i = 1;i<=n;i++) {
        cin>>a[i];
    }
    dp[0][0] = 1;
    for(int i = 0;i<=k;i++) {
        sum[0][i] = 1;
    }

    for(int i = 1;i<=n;i++) {
        for(int j = 0;j<=k;j++) {
            if(j == 0) dp[i][j] = sum[i-1][j];
            else dp[i][j] = sum[i-1][j] - (j>a[i]?sum[i-1][j-a[i]-1]:0) + mod;
            dp[i][j] = dp[i][j]%mod;
            if(j!=0) sum[i][j] = (sum[i][j-1] + dp[i][j])%mod ;
            if(j == 0) sum[i][0] = 1;
            //printf("dp[%d][%d] = %lld\n",i,j,dp[i][j]);
        }
    }
    cout<<dp[n][k]<<endl;
}

Measured memory_bytes: 159088
#include <stdio.h>
int a[200001];
int main()
{
    int n,m,ai=0;
    scanf("%d",&n);
    for(int i=0;i<n;i++)
    {
        scanf("%d",&m);
        if(m==0)
        {
            scanf("%d",&m);
            a[ai++]=m;
        }else if(m==2)
        {
            if(ai>0)
            {
                ai--;
            }
        }else if(m==1)
        {
            scanf("%d",&m);
            printf("%d\n",a[m]);
        }
    }
    return 0;
}



Measured memory_bytes: 2624
#include <cstdio>
#include <algorithm>
using namespace std;
int main(){
	long long int n, k;
	scanf("%lld %lld", &n, &k);
	long long int a[n], f[n];
	for (long long int i = 0; i < n; i++){
		scanf("%lld", &a[i]);
	}
	for (long long int i = 0; i < n; i++){
		scanf("%lld", &f[i]);
	}
	sort(a, a + n);
	sort(f, f + n);
	reverse(f, f + n);
	long long int l = 0, r = 10000000000000001;
	while (l < r){
		long long int mid = (l + r) / 2, c = 0;
		for (long long int i = 0; i < n; i++){
			if (a[i] > mid / f[i]){
				c += a[i] - mid / f[i];
			}
		}
		if (c <= k){
			r = mid;
		}else{
			l = mid + 1;
		}
	}
	printf("%lld\n", l);
}

Measured memory_bytes: 3328
#include <bits/stdc++.h>
using namespace std;
const double PI  = acos(-1.0);
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define print(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl; 
int main()
{

    int L, R, D;
    cin >> L >> R >> D;
    int ans = 0;
    for (int i = L; i <= R; i++){
        if (i % D == 0){
            ans++;
        }
    }
    cout << ans;
    return 0;
}



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

bool f(const long kind, const size_t n, const vector<long>& a){
    map<long,long> c;
    long len = a[0];
    for(size_t i=1; i<n; i++){
        const long n_len = a[i];
        if(len>=n_len){
            c.erase(c.lower_bound(n_len), c.end());
            long j=n_len-1;
            auto oit = c.end();
            for(;;){
                auto it = c.find(j);
                if(it == c.end()){
                    it = c.insert(oit, make_pair(j, 1));
                }else{
                    it->second++;
                }
                if(it->second<kind){
                    c.erase(oit, c.end());
                    break;
                }else if(j<=0){
                    return false;
                }
                oit = it;
                j--;
            }
        }
        len = n_len;
    }
    return true;
}

bool strict_increasing(const vector<long>& a){
    size_t n = a.size();
    for(size_t i=1; i<n; i++){
        if(a[i-1]>=a[i]){
            return false;
        }
    }
    return true;
}

int main(void){
    long n;
    cin >> n;
    vector<long> a(n);
    for(long i=0; i<n; i++){
        cin >> a[i];
    }
    if(strict_increasing(a)){
        cout << 1 << endl;
        return 0;
    }
    long left=1, right=n;
    for(;;){
        const long mid = (left+right)/2;
        if(right-left<=1){
            if(f(right, n, a)){
                cout << right << endl;
            }else{
                cout << left << endl;
            }
            return 0;
        }
        const bool b = f(mid, n, a);
        //printf("[%ld, %ld] %ld %s\n", left, right, mid, b ? "true" : "false");
        if(b){
            right=mid;
        }else{
            left=mid;
        }
    }
}


Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include<unordered_map>
#include<unordered_set>
#pragma warning(disable:4996)
using namespace std;
using ld = long double;
const ld eps = 1e-9;

//// < "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\a.txt" > "d:\d_download\visual studio 2015\projects\programing_contest_c++\debug\b.txt"


int main() {
	/*string st; cin >> st;
	for (int i = 0; i < 4; ++i) {
		cout << st[i];
	}
	cout << " ";
	for (int i = 4; i < 12; ++i) {
		cout << st[i];
	}
	cout << endl;
*/
	int N; cin >> N;
	int ans = 0;
	vector<int>vs(N);
	for (int i = 0; i < N; ++i) {
		cin >> vs[i];
		vs[i]--;
	}
	for (int i = 0; i < N; ++i) {
		if (vs[vs[i]] == i)ans++;
	}
	cout << ans / 2 << endl;
	return 0;
}

Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main m = new Main();
		m.run();
	}

	Scanner sc = new Scanner(System.in);

	void run() {

		int n = sc.nextInt();
		int m = sc.nextInt();
		
		
		long base = n*100+m*1800;
		
		System.out.println(base << m);
		
	}
}


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

int main() {

	int r; cin >> r;
	string ans;
	if (r < 1200) ans = "ABC";
	else if (r < 2800) ans = "ARC";
	else ans = "AGC";
	cout << ans << endl;
	return 0;
}

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

ll ctoi(const char c){
    if('0' <= c && c <= '9')
        return (c-'0');
    return -1;
}

string S;
ll stoi(int l, int r){
    ll sum = 0;
    for(int i=l;i<=r;i++){
        sum = sum*10;
        sum += ctoi(S[i]);
    }
    return sum;
}

int main(){
    cin >> S;

    int N;
    N = S.length();
    ll ans = 0;
    int l;
    // bit全探索
    for(int i=0;i < 1<<(N-1);i++){
        l = 0;
        // '0':等号を入れない, '1':等号を入れる
        vector<int> vec;
        for(int j=0;j<N-1;j++){
            if(i & (1<<j))
                vec.push_back((N-2) - j);
        }
        sort(vec.begin(), vec.end());
        int size = vec.size();
        for(int j=0;j<size;j++){
            // cout << stoi(l, vec[j]) << endl;
            ans += stoi(l, vec[j]);
            l = vec[j] + 1;
        }
        // cout << stoi(l, N-1) << endl;
        ans += stoi(l, N-1);
    }
   
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <random>
#include <bitset>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;
const ll MOD = 1000000007LL;

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

    string s;
    cin >> s;
    int n = s.size();

    string t = "";
    for (int i = 0; i < n; i++) {
        if (s[i] == 'A') {
            t += 'A';
        } else if (i < n - 1 && s[i] == 'B' && s[i+1] == 'C') {
            t += 'E';
            i++;
        } else {
            t += 'F';
        }
    }
    
    n = t.size();
    ll a = 0;
    ll ans = 0;
    for (int i = 0; i < n; i++) {
        if (t[i] == 'A') {
            a++;
        } else if (t[i] == 'E') {
            ans += a;
        } else if (t[i] == 'F') {
            a = 0;
        }
    }

    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 1020
# ABC149 B - Greedy Takahashi
a,b,k = map(int,input().split())

if a-k>=0:
    a -=k
else:
    k -= a
    a=0
    if b-k>=0:
        b -=k
    else:
        b=0
print(str(a)+' '+str(b))
        
        
        

Measured memory_bytes: 61708
K,A,B=map(int, input().split())
if A+2>=B:
  print(K+1)
else:
  if K==1 or K<=A:
    print(K+1)
  else:
    cnt=0
    K-=(A-1)
    a=K//2
    cnt=a*(B-A)+A
    if K%2==1:
      cnt+=1
    print(cnt)
    

Measured memory_bytes: 3060
#include <iostream>
#include <cstdio>
#include <iomanip>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <bitset>
#include <stack>
#include <utility>
#include <numeric>
#include <algorithm>
#include <functional>
#include <cctype>
#include <complex>
#include <string>
#include <sstream>

using namespace std;

#define all(c) c.begin(),c.end()
#define rall(c) c.rbegin(),c.rend()
#define mp(a,b) make_pair((a),(b))
#define eq ==

typedef long long ll;
typedef complex<double> point;
typedef pair<int,int> pii;

// →↑←↓
const int dx[] = {1,0,-1,0};
const int dy[] = {0,-1,0,1};


const double EPS = 1e-9;

int main(){
    int N;
    cin >> N;
    vector<vector<ll> > vec(N,vector<ll>(N));
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            cin >> vec[i][j];
        }
    }
    ll ret = 0;
    for(int i=0;i<N;i++){
        for(int j=0;j<N;j++){
            ret += min(vec[i][j],vec[j][i]);
        }
    }
    ret /= 2;
    cout << ret << endl;
    return 0;
}

Measured memory_bytes: 1300
#include <stdio.h>
#include <cstdio>
#include <iostream>
#include <iomanip>
#include <queue>
#include <set>
#include <vector>
#include <string>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <complex>

int main(){
  std::string S;
  std::cin >> S;

  if(S[0] != S[1] || S[1] != S[2]){
    std::cout << "Yes" << std::endl;
  }
  else{
    std::cout << "No" << std::endl;
  }

  return 0;
}


Measured memory_bytes: 764
#include<stdio.h>
int main(){
char a[1000];
int b=0,c,d=0;
while(1){
scanf("%s",a);
if(a[0]=='0'){
break;
}
else{
while(a[b]!='\0'){
c=a[b]-'0';
d=d+c;
b++;
}
scanf("\n");
printf("%d\n",d);
}
b=0;
d=0;
}
return 0;
}



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

using namespace std;
#define fi first
#define se second

const int maxn = 123456;

typedef long long ll;
typedef pair<int,int> pii;

int p[12];
int c[12][12];
int main(){
    // freopen("input.txt", "r", stdin);
    int N, M, K;
    cin>>N>>M;
    for (int i = 0; i < M; ++i)
    {
        cin >> K;
        c[i][0] = K;
        for (int j = 1; j <= K; ++j)
        {
            cin >> c[i][j];
            c[i][j]--;
        }
    }
    for (int i = 0; i < M; ++i)
    {
        cin >> p[i];
    }
    int res = 0;
    for (int i = 0; i < (1<<N); ++i)
    {
        // cout << i << endl;
        bool flag = true;
        for(int j = 0; j < M; ++j){
            int num = 0;
            for(int k = 1; k <= c[j][0]; ++k){
                if(i&(1<<c[j][k])){num ++;}               
            }
            if((p[j]%2) == (num%2))continue;
            else {flag = false; break;}
        }
        if(flag){res ++;}
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
// C
#ifndef _GLIBCXX_NO_ASSERT
#include <cassert>
#endif
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>

#if __cplusplus >= 201103L
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
// #include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#endif

// C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>

#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;
typedef long long int ll;
typedef unsigned long long ull;
typedef long double ld;
#define REP(i,n) for(ll i=0; i<(n); i++)
#define REPR(i, n) for(ll i = n;i >= 0;i--)
#define FOR(i, m, n) for(ll i = m;i < n;i++)
#define ALL(n) begin(n),end(n)
#define IN(a, x, b) (a<=x && x<b)
#define INIT std::ios::sync_with_stdio(false);std::cin.tie(0);
template<class T> inline T CHMAX(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T CHMIN(T & a, const T b) { return a = (a > b) ? b : a; }

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);
const long long MOD = 1000000007;

ll field[10][10];

int main(void){
    ll h=0;
    ll w=0;
    ll value =0;
    cin >> h >> w;
    REP(i, w){
        REP(j, h){
            char math;
            cin >> math;
            if(math == '#'){
                value++;
            }
        }
    }
    if(value == (h+w-1)){
        cout << "Possible" << endl;
    }else{
        cout << "Impossible" << endl;
    }
    return 0;
}

Measured memory_bytes: 3120
#include<cstdio>
#include<cstring>
#include<stack>
struct p{
	int x;
	int y;
};
using namespace std;
int main(){
	int w,h,sx,sy,gx,gy,n,c,d,x,y,i,j,k,o;
	int map[100][100];
	int used[100][100];
	int mx[4]={-1,0,1,0};
	int my[4]={0,-1,0,1};
	p v,u;
	stack<p> s;
	while(1){
		scanf("%d %d",&w,&h);
		if(w==0&&h==0){
			break;
		}
		memset(map,0,sizeof(map));
		memset(used,0,sizeof(used));
		scanf("%d %d",&sx,&sy);
		sx--;
		sy--;
		scanf("%d %d",&gx,&gy);
		gx--;
		gy--;
		scanf("%d",&n);
		for(i=0;i<n;i++){
			scanf("%d %d %d %d",&c,&d,&x,&y);
			x--;
			y--;
			if(!d){
				for(j=y;j<y+2;j++){
					for(k=x;k<x+4;k++){
						map[j][k]=c;
					}
				}
			}
			else{
				for(j=y;j<y+4;j++){
					for(k=x;k<x+2;k++){
						map[j][k]=c;
					}
				}
			}
		}
		if(map[sy][sx]!=map[gy][gx]){
			printf("NG\n");
			continue;
		}
		v.x=sx;
		v.y=sy;
		s.push(v);
		o=0;
		while(!s.empty()){
			v=s.top();
			s.pop();
			if(used[v.y][v.x]){
				continue;
			}
			else{
				used[v.y][v.x]=1;
			}
			if(v.x==gx&&v.y==gy){
				o=1;
				while(!s.empty()){
					s.pop();
				}
				break;
			}
			for(i=0;i<4;i++){
				u=v;
				u.x+=mx[i];
				u.y+=my[i];
				if(u.x>=0&&u.x<w&&u.y>=0&&u.y<h&&map[u.y][u.x]==map[sy][sx]){
					s.push(u);
				}
			}
		}
		if(o){
			printf("OK\n");
		}
		else{
			printf("NG\n");
		}
	}
	return 0;
}

Measured memory_bytes: 2612
//C
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdalign>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>

//C++
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>

//Others
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;
}
const int dx[8] = { -1,0,1,-1,1,-1,0,1 };
const int dy[8] = { 1,1,1,0,0,-1,-1,-1 };


//LOVE NyantakoGG	https://www.youtube.com/channel/UC6XdFs8T6Ei54O0FYl3PVVA


using namespace std;



int main() {
	int N;
	cin >> N;
	vector<int>H(N);
	int MH = 0;
	int ans = 0;
	for (int i = 0; i < N; i++) {
		cin >> H[i];
		if (MH <= H[i]) {
			ans++;
		}
		chmax(MH, H[i]);
	}
	cout << ans << endl;
}


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

using namespace std;

int n,s;
long long seq[100050],cnt[100050];

int main()
{
	scanf("%d%d",&n,&s);
	for(int i = 1;i <= n; ++ i) scanf("%lld %lld",&seq[i],&cnt[i]);
	int l = 1,r = n;
	long long ans = 0;
	while(seq[l] <= s && seq[r] > s)
	{
		if(cnt[l] >= cnt[r])
		{
			ans += seq[r] - seq[l];
			while(cnt[l] >= cnt[r] && seq[r] > s)
			{
				cnt[l] += cnt[r];
				r --;
			}
		}
		else
		{
			ans += seq[r] - seq[l];
			while(cnt[r] > cnt[l] && seq[l] <= s)
			{
				cnt[r] += cnt[l];
				l ++;
			}
		}
	}
	if(seq[l] <= s) ans += s - seq[l];
	else ans += seq[r] - s;
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define lli long long int
using namespace std;
vector<vector<int>> adj(100001);
vector<int> visited(100001);
void addEdge(int a,int b){
	adj[a].push_back(b);
	adj[b].push_back(a);
}
void dfs(int curr){
	visited[curr]=1;
	for(int child: adj[curr]){
		if(visited[child]==0)
		dfs(child);
	}
}
int main()
{
    int n,m;
    cin>>n>>m;
    int l=m;
    while(l--){
    	int a,b;
    	cin>>a>>b;	
    	addEdge(a,b);
	}
	int c=0;
	for(int i=1;i<=n;i++){
		if(visited[i]==0){
			dfs(i);
			c++;
		}
	}
	cout<<c-1;
}

Measured memory_bytes: 9532
#include<bits/stdc++.h>
#define ULL unsigned long long
#define LL long long
#define Max 105
#define mem(a,b) memset(a,(int)b,sizeof(a));
#define pb push_back
#define mp make_pair
#define debug printf("debug\n");
const LL mod=1e9+7;
const ULL base=131;
const LL LL_MAX=9223372036854775807;
using namespace std;
int n,k;
LL a[Max];
priority_queue<LL,vector<LL>,greater<LL> >p;
LL fun(int l,int r){
    for(int i=1;i<=l;i++)
        p.push(a[i]);
    for(int j=1,t=n;j<=r;j++,t--)
        p.push(a[t]);
    int opt=k-l-r;
    while(p.size() && p.top()<0 && opt)
        p.pop(),opt--;
    LL sum=0;
    while(p.size())
        sum+=p.top(),p.pop();
    return sum;
}
int main()
{
    scanf("%d%d",&n,&k);
    for(int i=1;i<=n;i++){
        scanf("%lld",&a[i]);
    }
    LL sum=0;
    for(int i=0;i<=k;i++){
       for(int j=0;(i+j)<=min(n,k);j++){
            sum=max(fun(i,j),sum);
       }
    }
    printf("%lld\n",sum);
    return 0;
}



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

int GetPrimeElements(int n)
{
  int num = 0;
  for (int i = 1; i <= n; i++)
  {
    if (n % i == 0)
    {
      num++;
    }
  }
  return num;
}

int main()
{
  int N;
  cin >> N;
  int ans = 0;

  for (int i = 1; i <= N; i += 2)
  {
    if (GetPrimeElements(i) == 8)
    {
      ans += 1;
    }
  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <numeric>
#include <cmath>
#include <cassert>

using namespace std;

typedef long long int ll;
typedef pair<int,int> P;

#define rep(i,n) for(int i=0;i<(n);++i)
#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

int main()
{
	ll n;
	cin>>n;
	cout<<(n-1)*n/2<<endl;
	return 0;
}

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

int main() {
  int n,m;cin>>n>>m;
  vector<int>v(n);int o=0;
  for(int i=0;i<n;i++){
    cin>>v.at(i);o+=v.at(i);
  }
  sort(v.begin(),v.end());
  reverse(v.begin(),v.end());
  int a=4*m;
  o=(o+a-1)/a;
  for(int i=0;i<m;i++){
    if(v.at(i)<o){
      cout<<"No"<<endl;
      exit (0);
    }
  }cout<<"Yes"<<endl;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define gsort(x) sort(x, x+n, greater<ll>()); 
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define sync2 cout<<fixed<<setprecision(10)
const ll inf=1e9+7;
#define pi 3.14159265358979323846
#define REP(i,j,n) for (int i = (int)j; i <=(int)n; i++)
#define REPD(i,n,j) for (int i = (int)n; i>=(int)j; i--)
#define all(vv) vv.begin(),vv.end()
//priority_queue <int, vector<int>, greater<int>> mnheap;

ll arr[200005],brr[200005];
ll ans=0;
int n;

int main()
{
    sync;
    ll area2;
    cin>>area2;
    ll x2=1000000000,x3,y2=1,y3;
    if(area2%x2==0)
    {    
        x3=0;
        y3=area2/x2;
    }
    else
    {
        x3=x2-area2%x2;
        y3=(area2+x3)/x2;
    }
    cout<<0<<" "<<0<<" "<<x2<<" "<<1<<" "<<x3<<" "<<y3<<endl;

}


Measured memory_bytes: 256
from itertools import permutations as p

N = int(input())
P = tuple(map(int,input().split()))
Q = tuple(map(int,input().split()))

j = 0

for i in p(range(1, N + 1)):
  j += 1
  if i == P: a = j
  if i == Q: b = j

if a - b >= 0: print(a - b)
else: print(b - a)  

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

struct UnionFind {
    vector<int> par;
    vector<bool> is_namori;
    
    UnionFind(int n) : par(n, -1), is_namori(n, 0) {}
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    // e = (x, y) を結んで良いかどうかも含めて判定
    bool merge(int x, int y) {
        x = root(x); y = root(y);

        // x と y が同じ連結成分
        if (x == y)  {
            if (is_namori[x]) return false;
            is_namori[x] = true;
            return true;
        }

        // x も y もなもりはダメ
        if (is_namori[x] && is_namori[y]) return false;
        
        if (par[x] > par[y]) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        if (is_namori[x] || is_namori[y]) is_namori[x] = true;   
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};

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

int main() {
    int N, H, W; cin >> N >> H >> W;
    vector<Edge> edges;
    for (int i = 0; i < N; ++i) {
        int r, c, a; cin >> r >> c >> a; --r, --c;
        c += H;
        edges.push_back(Edge(a, pint(r, c)));
    }
    sort(edges.begin(), edges.end(), greater<Edge>());

    UnionFind uf(H + W);
    long long res = 0;
    for (auto e : edges) {
        int u = e.second.first;
        int v = e.second.second;
        long long w = e.first;

        if (uf.merge(u, v)) res += w;
    }   
    cout << res << endl;
}


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std; 
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define REP(i,n) for(int i=0;i<(n);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)
#define ff first
#define ss second
#define END "\n"
#define pb push_back
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
inline bool EQ(double a, double b) { return fabs(a-b) < 1e-9; }
const int INF = 1<<29;
typedef long long ll;
typedef vector<int> vi;
typedef unsigned long long ull;
typedef pair<int,int> ii;
typedef vector<ii> vii;
inline int two(int n) { return 1 << n; }
inline int test(int n, int b) { return (n>>b)&1; }
inline void set_bit(int & n, int b) { n |= two(b); }
inline void unset_bit(int & n, int b) { n &= ~two(b); }
inline int last_bit(int n) { return n & (-n); }
inline int ones(int n) { int res = 0; while(n && ++res) n-=n&(-n); return res; }
template<class T> void chmax(T & a, const T & b) { a = max(a, b); }
template<class T> void chmin(T & a, const T & b) { a = min(a, b); }
/////////////////////////////////////////////////////////////////////



int main()
{
    fast
    #ifdef ANUBHAB
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
    #endif
    ll n, a, b, ans;
    cin >> n >> a >> b;
    if (a == 0)
      cout << 0;
    else
    {
      ans = n / (a + b);
      ans *= a;
      if (n % (a + b) > a)
        ans += a;
      else ans += n % (a + b);
      cout << ans;
    }
    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int n, k, x, y;
	int i;
	int ans = 0;
	
	scanf("%d %d %d %d", &n, &k, &x, &y);
	
	for (i = 1; i <= n; i++){
		if (i <= k){
			ans += x;
		}
		else {
			ans += y;
		}
	}
	printf("%d", ans);
	
	return (0);
}

Measured memory_bytes: 128
L = []
for _ in range(5):
    L.append(int(input()))

#print('L is ', L)

m = 10
t = 0
for a in L:
    mod = a % 10
    if mod == 0:
        t = t + a
    else:
        t = t + (a // 10 + 1) * 10
        m = min(m, (a % 10))

if m == 10:
    print(t)
else:
    print(t - 10 + m)
    

Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

struct SegmentTree {
    struct Node {
        Node operator*(const Node &o) const {
            return { min(u, o.u), max(v, o.v) };
        }
        int u, v;
    };
    SegmentTree(int n) : e({ 1 << 30, -1 }), n(n) {
        for (m = 2; m < n; m *= 2);
        t = vector<Node>(m + n + n % 2, e);
    }
    Node &operator[](int i) {
        return t[m + i];
    }
    const Node &root() const {
        return t[1];
    }
    void build() {
        for (int i = (n - 1 + m) / 2; i > 0; i--) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    void update(int i, const Node &o) {
        for (t[i += m] = o; i /= 2, i > 0;) t[i] = t[i * 2] * t[i * 2 + 1];
    }
    Node query(int l, int r) {
        Node o[2] = { e, e };
        for (l += m, r += m; l < r; l /= 2, r /= 2) {
            if (r & 1) o[1] = t[--r] * o[1];
            if (l & 1) o[0] = o[0] * t[l++];
        }
        return o[0] * o[1];
    }
    void print() {
        for (int j = 1; j <= m; j *= 2) {
            int k = min(j * 2, m + n);
            for (int i = j; i < k; i++) {
                cout << t[i].v << " \n"[i == k - 1];
            }
        }
    }
    vector<Node> t;
    const Node e;
    int n, m;
};

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

    int n, k;
    cin >> n >> k;

    SegmentTree st(n);
    vector<int> a(n), b(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        st[i].u = st[i].v = a[i];
        if (i > 0) b[i] = b[i - 1] + (a[i - 1] > a[i]);
    }
    st.build();

    int r = n - k + 1;
    int x = 0;
    for (int i = 0; i < n - k + 1; i++) {
        if (b[i + k - 1] - b[i] == 0) x++;
    }
    for (int i = 0; i < n - k; i++) {
        auto o = st.query(i, i + k + 1);
        if (o.u == a[i] && o.v == a[i + k]) {
            r--;
            if (b[i + k - 1] - b[i] == 0) x--;//iとi+1を比較してる
        }
        
    }
    
    if (x > 0) x--;
    cout << r - x << endl;

    //答えは高々N-K+1
    //連続するK個で昇順になってるものを数えればいいのか？昇順になっていれば変化しない
    //昇順になっていないとき、離れてれば大丈夫 K=4で124356これはどう取っても同じにしかならない
    //変化するとき、最初の数が移動するかどうか 最大値と最小値
    //隣と同じになる条件は？左の先頭も右の末尾も移動しないこと 左の先頭が最小値
    //変化しないのが複数か所あっても減るかあ それが被ってるケースは？それはその間全部変化しないので
    //1243576 76で減ってるのでこの後しばらく変化する
    //変化しないのをまとめていくつかの区間にして

    return 0;
}

Measured memory_bytes: 5504
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;

public class Prog
{
    private const int INF = 1000000007;
    public static void Main()
    {
        int N = Cin<int>();
        string a = Console.ReadLine();
        string b = Console.ReadLine();
        string c = Console.ReadLine();
        int ans = 0;
        for (int i = 0; i < N; i++)
        {
            if (a[i] == b[i] && b[i] == c[i]) ;
            else if (a[i] == b[i]) { ans += 1; }
            else if (b[i] == c[i]) { ans += 1; }
            else if (a[i] == c[i]) { ans += 1; }
            else ans += 2;
        }
        Console.WriteLine(ans);
    }
}

public class Input
{
    private static Queue<string> queue = new Queue<string>();
    public static T Cin<T>()
    {
        if (queue.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) queue.Enqueue(s);
        if (typeof(T) == typeof(int)) return (T)(object)int.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(long)) return (T)(object)long.Parse(queue.Dequeue());
        else if (typeof(T) == typeof(string)) return (T)(object)(queue.Dequeue());
        else if (typeof(T) == typeof(double)) return (T)(object)double.Parse(queue.Dequeue());
        else return (T)(object)(-1);
    }
    public static T Line<T>()
    {
        if (typeof(T) == typeof(int[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').Select(int.Parse).ToArray();
        }
        else if (typeof(T) == typeof(long[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        }
        else if (typeof(T) == typeof(string[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').ToArray();
        }
        else if (typeof(T) == typeof(double[]))
        {
            return (T)(object)Console.ReadLine().Split(' ').Select(double.Parse).ToArray();
        }
        else return (T)(object)(-1);
    }
}

Measured memory_bytes: 13268
#pragma warning(disable:4996)
#pragma comment(linker, "/STACK:336777216")
#pragma GCC optimize("Ofast")

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <functional>

using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
#define int long long int
typedef complex<long double> cd;
const long double pi=acos(-1);
typedef double db;
typedef long double ldb;
typedef pair <int,int> pii;
typedef pair <db,db> pdd;
typedef vector<int> vi;
typedef vector<vector<int> > matrix;

#define m1 make_pair
#define pb push_back
#define flush fflush(stdout)
#define IOS std::ios::sync_with_stdio(false); cin.tie(NULL);cout.tie(NULL);
#define reset(x,v) memset(x,v,sizeof(x))

#define fi first
#define se second
#define endl "\n"
#define debug(x) (cerr << #x << ": " << x << "\n")
#define setbits(x) __builtin_popcount(x)
#define setbitsll(x) __builtin_popcountll(x)
#define all(x) x.begin(),x.end()
#define pii pair<int,int>

inline int gcd(int a,int b){if(a==0) return b;return gcd(b%a,a);}
inline int power(ll a,ll n,ll m){if(n==0)return 1;ll p=power(a,n/2,m);p=(p%m*p%m)%m;if(n%2) return (p%m*a%m)%m;else return p;}
const double EPS = 1e-9;
const ll MOD =998244353;
const ll hell=1000000007;
const int INF = 1e18;
const ll LL_INF = 0x3f3f3f3f3f3f3f3f;
template<typename T>
using ordered_set=tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
std::mt19937 rng(seed);

double startTime;
double getCurrentTime() {
    return ((double)clock() - startTime) / CLOCKS_PER_SEC;
}
const int dx[] = { -1, 0, 1, 0 };
const int dy[] = { 0, 1, 0, -1 };

const int N=200005;

void solve()
{
    int k;
    cin>>k;
    set<int>s;
    int x=0;
    for(int i=0;i<k;i++)
    {
        x=(x*10+7)%k;
        if(!x)
        {
            cout<<i+1<<endl;
            return;
        }
        if(s.find(x)!=s.end())
        {
            cout<<-1<<endl;
            return;
        }
        s.insert(x);
    }
    
    
    
}

int32_t main()
{
    IOS;
    int t;
    t=1;
    //cin>>t;
    while(t--)
    {
        
        solve();
    }
    return 0;
}


Measured memory_bytes: 50420
gets
num_map = gets.split.map(&:to_i).sort.each_with_object(Hash.new(0)) { |n, arr| arr[n] = arr[n] + 1 }
xs = num_map.flat_map do |n, _|
  [
    num_map[n - 2] + num_map[n - 1] + num_map[n],
    num_map[n - 1] + num_map[n] + num_map[n + 1],
    num_map[n] + num_map[n + 1] + num_map[n + 2],
  ]
end

puts xs.max

Measured memory_bytes: 17264
h, w = list(map(int, input().split()))
s = ['.'*(w+2)]

for i in range(h):
	s.append('.'+input()+'.')
s.append('.'*(w+2))

ans = True

for i in range(1, h+1):
	for j in range(1, w+1):
		if s[i][j]=='#':
			if s[i-1][j]=='.' and s[i+1][j]=='.' and s[i][j-1]=='.' and s[i][j+1]=='.':
				ans = False

print('Yes' if ans else 'No')

Measured memory_bytes: 3064
from operator import itemgetter
N = int(input())
X = list(map(int,input().split()))
X_ = sorted(enumerate(X),key=itemgetter(1))
lesser_med = X_[(N//2)-1]
greater_med = X_[N//2]
for x in X:
    if x <= lesser_med[1]:
        print(greater_med[1])
    else:
        print(lesser_med[1])


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

int main(){
  ll n,m,ans=0;
  cin >> n >> m;
  vector<ll> h(n+10),a(m),b(m),check(n+10,1);
  rep(i,n){
    cin >> h.at(i+1);
  }
  rep(i,m){
    cin >> a.at(i) >> b.at(i);
  }
  
  rep(i,m){
    if(h.at(a.at(i)) <= h.at(b.at(i))){
      check.at(a.at(i)) = 0;
    }
    if(h.at(a.at(i)) >= h.at(b.at(i))){
      check.at(b.at(i)) = 0;
    }
  }
  
  rep(i,n){
    if(check.at(i+1) == 1){
      ans++;
    }
  }
  
  cout << ans << endl;
  
  return 0;
}


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

int V[100010];
int N;
vector<int> mem(100010,1e9+1);

int main(){
    cin>>N;
    for(int i=0;i<N;i++){
        cin>>V[i];
    }
    mem[0]=0;
    for(int i=0;i<N;i++){
        for(int j:{i+1,i+2}){
            if(j<N){
                mem[j]=min(mem[j],mem[i]+abs(V[i]-V[j]));
            }
        }
    }
    cout<<mem[N-1]<<endl;
    return 0;
}

Measured memory_bytes: 1024
N=int(input())
chars=['M','A','R','C','H']
dict={}
for c in chars:
  dict[c]=0
  
ans=0
  
for i in range(N):
  s=input()
  if (s[0] in chars):
    dict[s[0]]+=1

L=list(dict.values())
    
for i in range(2**5):
  usedchars=[]
  for j in range(5):
    if i>>j&1==1:
      usedchars.append(L[j])
    
  if len(usedchars)==3:
    ans+=usedchars[0]*usedchars[1]*usedchars[2]

print(ans)

Measured memory_bytes: 3064