akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<stdio.h>
#include<fstream>
#include<algorithm>
using namespace std;
struct mlist{
  int pre,zhi,next;
}x[20000007];
int l=0,head=-1;int u=0;int tail=0;
void cs(int n)
{
    if(l==0||head==-1)
    {
        x[l].next=-1;
        x[l].zhi=n;
        head=l;
        tail=l;
    }
    else {
            x[l].zhi=n;
            x[head].pre=l;
            x[l].next=head;
            head=l;
    }
    l++;
}
int pos(int n)
{
    int hd=head;
    while(x[hd].zhi!=n&&hd!=-1)
    {
        hd=x[hd].next;
    }
    return hd;
}
void ffd();
void dfs(int n)
{
    int k=pos(n);
    if(k==-1)
    {
        return;
    }
    if(k==head)
    {
         ffd();
    }
    if(x[k].next==-1)
    {
        if(x[head].next==-1)
        {
            head=-1;
        }
        else {
            tail=x[tail].pre;
            x[tail].next=-1;
        }

    }
    else
    {
      x[x[k].pre].next=x[k].next;
      x[x[k].next].pre=x[k].pre;
    }
}
void ffs()
{
    //int hd=head;
    //while(x[hd].next!=-1&&hd!=-1)
    //{
    //    hd=x[hd].next;
    //}
    //if(hd==head)
    //{
      //head=-1;
    //}
   //else x[x[hd].pre].next=-1;
   //x[tail].next=-1;
   if(head==-1||head==tail)
   {
       head=-1;
   }
   else {
    tail=x[tail].pre;
   x[tail].next=-1;
   }

}
void  ffd()
{
    if(head!=-1)
     head=x[head].next;
}
int main()
{
   char a[20];int p;
   int n;
   scanf("%d",&n);
   for(int i=0;i<n;i++)
   {
       scanf("%s",a);

        if(a[0]=='i')
        {
            scanf("%d",&p);
            cs(p);
        }
        else if(a[6]=='F')
        {
            ffd();
        }
        else if(a[6]=='L')
        {
            ffs();
        }
        else
            {
            scanf("%d",&p);
            dfs(p);
        }
   }
   while(head!=-1)
   {
       if(x[head].next!=-1)
       printf("%d ",x[head].zhi);
       else printf("%d",x[head].zhi);
       head=x[head].next;
   }
   printf("\n");
   return 0;
}

Measured memory_bytes: 16092
#include<bits/stdc++.h>
#define taskname ""
#define int long long
using namespace std;

main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);   cout.tie(nullptr);
    if (ifstream("test.inp"))
    {
        freopen("test.inp", "r", stdin);
        #ifdef CHECKING
            freopen(taskname".out", "w", stdout);
        #else
            freopen("test.out", "w", stdout);
        #endif //CHECKING
    }
    else if (ifstream(taskname".inp"))
    {
        freopen(taskname".inp", "r", stdin);
        freopen(taskname".out", "w", stdout);
    }

    string s;   getline(cin, s);
    int ans = 0;
    for (char c : s) ans += c - '0';
    cout << ((ans % 9)? "No" : "Yes");
}


Measured memory_bytes: 3772
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

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

#define REP(i, n) for(ll i = 0; i < n; i++)



















int main(){
    ll a, b, n;
    cin >> a >> b >> n;
    cout << a * min(b - 1, n) / b << endl;
}

Measured memory_bytes: 3588
program main;
type
    ar = array [1..200000] of string;
var n,i,c : longint;
    a : ar;
procedure QuickSort(var A : ar; left,right : longint);
var i,j : longint;
    p,temp : string;
begin
    i := left;
    j := right;
    p := A[(left + right) div 2];
    while i <= j do begin
        while A[i] < p do
            inc(i);
        while A[j] > p do
            dec(j);
        if i <= j then begin
            temp := A[i];
            A[i] := A[j];
            A[j] := temp;
            inc(i);
            dec(j);
        end;
    end;
    if left < j
        then QuickSort(A, left, j);
    if right > i
        then QuickSort(A, i, right);
end;

begin
    c := 1;
    readln(n);
    for i := 1 to n do
        readln(a[i]);
    QuickSort(a, 1, n);
    for i := 2 to n do
        if a[i] > a[i-1]
        then inc(c);
    writeln(c);
end.

Measured memory_bytes: 58436
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < n; i++)
#define repr(i, n) for(int i = n;i >= 0;i--)
#define for1(i, m, n) for(int i = m;i < n;i++)
#define ll long long
#define endl '\n'
using namespace std;


int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
    string s;
    cin >> s;
    rep(i, s.size() - 8) {
        cout << s[i];
    }
    cout << endl;
	return 0;
}

Measured memory_bytes: 256
import math
import sys
input = sys.stdin.readline

N = int(input())
A = list(map(int, input().split()))
Nums = [0]*(10**6 + 1)

for a in A:
  Nums[a] += 1

GCD = A[0]
for i in range(N-1):
  GCD = math.gcd(GCD, A[i+1])

if GCD != 1:
  print("not coprime")
else:
  for d in range(2, 10**6+1):
    cnt = sum(Nums[d::d])
    if cnt > 1:
      print("setwise coprime")
      exit()
  print("pairwise coprime")

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

class O
{
	static void Main()
	{
		var n = int.Parse(Console.ReadLine());
		var a = new int[n].Select(_ => Console.ReadLine().Split().Select(s => s == "1").ToArray()).ToArray();
		var p2 = Enumerable.Range(0, n + 1).Select(i => 1 << i).ToArray();

		var dp = new int[n + 1, p2[n]];
		dp[0, 0] = 1;
		for (int i = 0, i2 = 1; i < n; i++, i2++)
			for (int f = 0, f2; f < p2[n]; f++)
			{
				if (dp[i, f] == 0) continue;
				for (int j = 0; j < n; j++)
				{
					if (!a[i][j]) continue;
					if ((f2 = f | p2[j]) == f) continue;
					dp[i2, f2] = (dp[i2, f2] + dp[i, f]) % 1000000007;
				}
			}
		Console.WriteLine(dp[n, p2[n] - 1]);
	}
}


Measured memory_bytes: 175072
n = int(input())
a = list(map(int,input().split()))

a_2 = [0 for i in range(n)]
for i in range(n):
    a_2[a[i]-1] += 1

al = [0 for i in range(n)]
c = 0
for i in a_2:
    if i > 1:
        al[c] += i * (i-1) / 2
    c += 1

sine = sum(al)
for i in range(n):
    f = a[i]
    t = a_2[f-1] - 1
    print(int(sine-(al[f-1]-t*(t-1)/2)))
    


Measured memory_bytes: 121548
/**
*	  Name: Ajay Subhash Jadhav
*	  Institute: International Institute of Technology Hyderabad 
*/

#include <iostream>
#include <cstdio>
#include <algorithm>
#include <deque>
#include <vector>
#include <cstdlib>
#include <iomanip>
#include <cmath>
#include <queue>
#include <map>
#include <set>
#include <ctime>
#include <string.h>
#define LL long long
#define inf 0x7fffffff
#define mod 1000000007
#define pb push_back
#define ppi pair<int,int>
#define vi vector<int>
#define vii vector<ppi>
#define vll vector<LL>
#define mp make_pair
using namespace std;

void fastio()
{
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout.tie(0);
}
void inputread()
{
  #ifndef ONLINE_JUDGE
  freopen("input.txt","r",stdin);
  freopen("output.txt","w",stdout);
  #endif
}

bool check(int n)
{
	int dig=n%10;
	n=n/10;
	while(n>0)
	{
		int temp=(n%10);
		n=n/10;
		if(temp==dig)
			dig=temp;
		else
			return 0;
	}
	return 1;
}

int main(){
      
  fastio();
  int n,m,i,j,t;
  cin>>n;

  while(true)
  {
  	if(check(n))
  		break;
  	n++;
  }
  cout<<n;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		int ans = 0;
		for (int i = 0; i < n; i++) {
			int l = sc.nextInt();
			int r = sc.nextInt();
			ans += r - l + 1;
		}
		System.out.println(ans);
		sc.close();
	}
}

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

int main() {
    int Osize, Esize;
    string O, E;
    cin >> O >> E;

    Osize = O.size();
    Esize = E.size();

    vector<char> ans(Osize + Esize);

    for(int i = 0; i < Osize; i++){
        ans.at(i*2) = O.at(i);
        if(i != Esize){
            ans.at(i*2+1) = E.at(i);
        }else{
            break;
        }
    }

    for(int i = 0; i < Osize + Esize; i++){
        cout << ans.at(i);
    }
    cout << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
#include<algorithm>
#include<string.h>
#include<math.h>
#include <cstdlib>
#include <stdlib.h>
#define FasterIO     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define PI acos(-1)
#define all(a) a.begin(),a.end()
#define f first
#define s second
#define pb push_back
#define ppb pop_back
#define pf push_front
#define ppf pop_front
#define mp make_pair
#define f0(i,n) for(i=0;i<n;i++)
#define f1(i,n) for(i=1;i<n;i++)
#define f1n(i,n) for(i=1;i<=n;i++)
#define szf sizeof()
#define sz size()
#define ln length()
#define MOD 1000000007
using namespace std;
using ll=long long;
int cnt,element;
int main()
{
    string str;
    cin>>str;
    if(str[1]=='B')
    {
        cout<<"ARC"<<endl;
    }
    else
    {
        cout<<"ABC"<<endl;
    }
    return 0;
}


Measured memory_bytes: 3592
#include <iostream>

 

 

 

using namespace std;

 

 

 

int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    if (a <= b && b <= c)
        cout << a << " " << b << " " << c << endl;
    else if (a <= c && c <= b)
        cout << a << " " << c << " " << b << endl;
    else if (b <= a && a <= c)
        cout << b << " " << a << " " << c << endl;
    else if (b <= c && c <= a)
        cout << b << " " << c << " " << a << endl;
    else if (c <= a && a <= b )
        cout << c << " " << a << " " << b << endl;
    else
        cout << c << " " << b << " " << a << endl;
}


Measured memory_bytes: 3104
import java.util.*;
import static java.util.Arrays.*;
import static java.lang.Math.*;

// AOJ 0039
public class Main {

	static Scanner sc = new Scanner(System.in);
	public static void main(String[] args) {
		HashMap<String, Integer> hm = new HashMap<String, Integer>();
		hm.put("I", 1);
		hm.put("V", 5);
		hm.put("X", 10);
		hm.put("L", 50);
		hm.put("C", 100);
		hm.put("D", 500);
		hm.put("M", 1000);
		while (sc.hasNext()) {
			String str = sc.next();
			int cur, prev, res;
			cur = prev = hm.get(str.substring(0, 1));
			res = 0;
			for (int i = 1; i < str.length(); i++) {
				cur = hm.get(str.substring(i, i + 1));
				if (prev < cur) {
					cur -= prev;
				} else {
					res += prev;
				}
				prev = cur;
			}
			res += prev;
			System.out.println(res);
		}
	}
}

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

int main() {
  int a,b;

  cin >> a >> b;

  if((1<=a && a<=9)&&(1<=b && b<=9)){
    cout << a * b << endl;
    return 0;
  }
  else {
    cout << -1 << endl;
    return 0;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
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; }

class SegmentTree {
  vector<int> dat;
  int n, def;
public:
  SegmentTree(int num, int x) {
    n = 1;
    while (n < num)
      n <<= 1;
    dat.resize(2 * n - 1, x);
    def = x;
  }
  void update(int i, int x) {
    i += (n - 1);
    dat[i] = x;
    while (i > 0) {
      i = (i - 1) / 2;
      dat[i] = max(dat[2 * i + 1], dat[2 * i + 2]);
    }
  }
  int query(int a, int b, int i = 0, int li = 0, int ri = -1) {
    if (!i) ri = n;
    if (ri <= a || li >= b) return def;
    if (li >= a && ri <= b) return dat[i];
    int vl = query(a, b, 2 * i + 1, li, (li + ri) / 2);
    int vr = query(a, b, 2 * i + 2, (li + ri) / 2, ri);
    return max(vl, vr);
  }
};

const int MOD = 998244353;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<pair<ll, ll>> x(n);
  rep(i, n) cin >> x[i].first >> x[i].second;
  sort(x.begin(), x.end());
  vector<int> seq(n);
  seq[n-1] = n-1;
  SegmentTree seg(n, 0);
  seg.update(n-1, seq[n-1]);
  for (int i = n-2; i >= 0; i--) {
    int r = lower_bound(x.begin(), x.end(), make_pair(x[i].first+x[i].second, 0LL))-x.begin();
    seq[i] = max(i, seg.query(i+1, r));
    seg.update(i, seq[i]);
  }
  vector<ll> dp(n+1, 0);
  dp[n] = 1;
  for (int i = n-1; i >= 0; i--) 
    dp[i] = (dp[i+1]+dp[seq[i]+1])%MOD;
  cout << dp[0] << endl;
  return 0;
}

Measured memory_bytes: 7808
#include <bits/stdc++.h>
 
using namespace std;
 
class Dice {
  private:
    void roll(int a, int b, int c, int d) {
	swap(x[a], x[b]);
	swap(x[b], x[d]);
	swap(x[c], x[d]);
    }
  public:
    char x[6];
    void roll_N(){ roll(0, 1, 4, 5); }
    void roll_E(){ roll(0, 3, 2, 5); }
    void roll_S(){ roll(0, 4, 1, 5); }
    void roll_W(){ roll(0, 2, 3, 5); }
    void rotation(){ roll(1, 2, 3, 4); }
};
 
Dice d[8], e[2][2][2];
 
int diff(char a, char b)
{
    return abs(a-b) == 32;
}
 
bool check(int idx)
{
    bool res = true;
    if (idx == 0) return res;
    if (idx == 1) {
	return diff(e[0][0][0].x[1], e[1][0][0].x[4]);
    }
    if (idx == 2) {
	return diff(e[0][0][0].x[2], e[0][1][0].x[3]);
    }
    if(idx == 3) {
	res &= diff(e[1][0][0].x[2], e[1][1][0].x[3]);
	res &= diff(e[0][1][0].x[1], e[1][1][0].x[4]);
    }
    if (idx == 4) {
	return diff(e[0][0][0].x[5], e[0][0][1].x[0]);
    }
    if (idx == 5) {
	res &= diff(e[1][0][0].x[5], e[1][0][1].x[0]);
	res &= diff(e[0][0][1].x[1], e[1][0][1].x[4]);
    }
    if (idx == 6) {
	res &= diff(e[0][0][1].x[2], e[0][1][1].x[3]);
	res &= diff(e[0][1][0].x[5], e[0][1][1].x[0]);
    }
    if (idx == 7) {
	res &= diff(e[1][0][1].x[2], e[1][1][1].x[3]);
	res &= diff(e[0][1][1].x[1], e[1][1][1].x[4]);
	res &= diff(e[1][1][0].x[5], e[1][1][1].x[0]);
    }
    return res;
}
 
bool rec(int idx, int S)
{
    if (S == (1<<8)-1) return true; 
    for (int i = 0; i < 8; i++) {
	if((S >> i) & 1) continue; 
	for (int j = 0; j < 4; j++) {
	    for (int k = 0; k < 4; k++) {
		d[i].roll_N();
		e[idx%2][(idx%4)>1][idx>3] = d[i];
		if (check(idx) && rec(idx+1,S|(1<<i))) {
		    return true;
		}
	    }
	    for (int k = 0; k < 4; k++) {
		d[i].roll_E();
		e[idx%2][(idx%4)>1][idx>3] = d[i];
		if (check(idx) && rec(idx+1,S|(1<<i))) {
		    return true;
		}
	    }
	    d[i].rotation();
	}
    }
    return false;
}
 
int main()
{
    while (cin >> d[0].x[0],d[0].x[0] != '0') {
	for (int i = 0; i < 8; i++) {
	    for (int j = (i == 0); j < 6; j++) {
		cin >> d[i].x[j];
	    }
	}
	cout << (rec(0, 0) ? "YES" : "NO") << endl;
    }
    return 0;
}

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

int main() {
  int N;
  cin >> N;
  double ans = 0;
  for (int i = 0; i < N; i++) {
    double a;
    string s;
    cin >> a >> s;
    if (s == "JPY") ans += a;
    else ans += a*380000;
  }
  cout << ans << endl;
}


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

struct UnionFind {
    std::vector<int> par, sizes; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2

    UnionFind(int N) : par(N), sizes(N, 1){ //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
	if (sizes[rx] < sizes[ry]) std::swap(x, y);
        par[ry] = rx; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
	sizes[rx] += sizes[ry];
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size(int x) {
	    return sizes[root(x)];
    }
};

using Graph = std::vector<std::vector<int>>;

int main(int, char**) {
	int N, M, K;
	std::cin >> N >> M >> K;
	
	UnionFind tree(N);
	Graph G(N);

	for (int i=0; i<M; i++) {
		int a, b;
		std::cin >> a >> b;
		a--;
		b--;
		tree.unite(a, b);
		G[a].push_back(b);
		G[b].push_back(a);
	}

	for (int i=0; i<K; i++) {
		int c, d;
		std::cin >> c >>d;
		c--;
		d--;
		if (tree.same(c, d)) {
			G[c].push_back(d);
			G[d].push_back(c);
		}
	}

	for (int i=0; i<N; i++) {
		std::cout << tree.size(i) - G[i].size() - 1 << " ";
	}
	std::cout << std::endl;
	
	return 0;
}


Measured memory_bytes: 8440
import java.util.Scanner

object Main extends App {

  val sc = new Scanner(System.in)
  val n = sc.nextLine().toInt
  val s = sc.nextLine()

  println(m(0, 0))
  
  def m(i: Int, count: Int): Int = {
    s.indexOf("ABC", i) match {
      case -1 => count
      case ni => m(ni + 1, count + 1)
    }
  }
  
}


Measured memory_bytes: 25424
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
const int maxn =2e5+10;
const int mod=1e9+7;




int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    vector<int>a,b;
    for(int i=1;i<=n;i++)
    {
        int x,y;
        cin>>x>>y;
        int t=x+y;
        int t2=x-y;
        a.pb(t);
        b.pb(t2);
    }
    sort(a.begin(),a.end());
    sort(b.begin(),b.end());
    cout<<max(a.back()-a.front(),b.back()-b.front())<<'\n';







}


Measured memory_bytes: 5128
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
	"strings"
)

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func rScan() []rune {
	return []rune(Scan())
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func mod(x, d int) int {
	x %= d
	if x < 0 {
		x += d
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}
func bPrint(f bool, x string, y string) {
	if f {
		fmt.Println(x)
	} else {
		fmt.Println(y)
	}
}
func iSSPrint(x []int) {
	fmt.Println(strings.Trim(fmt.Sprint(x), "[]"))
}

var lp int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, lp)
	sc.Split(bufio.ScanWords)
	n := Scan()
	k := iScan()
	ans := 0
	if k == 3 && k <= len(n) {
		ans += (len(n) - 1) * (len(n) - 2) * (len(n) - 3) / 6 * 9 * 9 * 9
		ans += (stringToInt(string(n[0])) - 1) * (len(n) - 1) * (len(n) - 2) / 2 * 9 * 9
		for i := 1; i < len(n); i++ {
			if string(n[i]) != "0" {
				n = n[i:]
				break
			}
			if i == len(n)-1 {
				n = ""
			}
		}
		k--
	}
	if k == 2 && k <= len(n) {
		ans += (len(n) - 1) * (len(n) - 2) / 2 * 9 * 9
		ans += (stringToInt(string(n[0])) - 1) * (len(n) - 1) * 9
		for i := 1; i < len(n); i++ {
			if string(n[i]) != "0" {
				n = n[i:]
				break
			}
			if i == len(n)-1 {
				n = ""
			}
		}
		k--
	}
	if k == 1 && k <= len(n) {
		ans += stringToInt(string(n[0])) + (len(n)-1)*9
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1776
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	H, W := ReadInt(), ReadInt()
	grid := make([]string, H)
	for i := 0; i < H; i++ {
		grid[i] = ReadString()
	}

	dirX := []int{-1, 0, 1, 0}
	dirY := []int{0, 1, 0, -1}
	for h := 0; h < H; h++ {
		for w := 0; w < W; w++ {
			if grid[h][w] == '.' {
				continue
			}
			foundBlack := false
			for i := 0; i < 4; i++ {
				nw := w + dirX[i]
				nh := h + dirY[i]
				if nw < 0 || nw >= W || nh < 0 || nh >= H {
					continue
				}
				if grid[nh][nw] == '#' {
					foundBlack = true
					break
				}
			}
			if !foundBlack {
				fmt.Println("No")
				return
			}
		}
	}
	fmt.Println("Yes")
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


Measured memory_bytes: 1852
#include<iostream>
#include<string>
#include<map>
#include<vector>
using namespace std;
int n,a[100100];
int b[100100];
string s;
int main()
{
	cin>>n;
	for(int i=0;i<n;i++)
		cin>>a[i];	
	long long ans=1;	
	for(int i=0;i<n;i++)
	{
		if(a[i]==0)
			ans*=(3-b[a[i]]);
		else
			ans*=min((3-b[a[i]]),b[a[i]-1]-b[a[i]]);
		b[a[i]]++;
		ans%=1000000007;
	}	
	cout<<ans<<endl;	
} 

Measured memory_bytes: 1024
#include<iostream>
#include<vector>
#include<algorithm>
#include<string.h>
#include<complex>
using namespace std;
typedef long long int llint;
int main(){
	int a, b;
	cin >> a >> b;
	int c = a + b;
	if (c >= 24){
		c -= 24;
	}
	cout << c << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <vector>
#include <set>
#include <queue>
#include <map>
#include <string>
#include <complex>

#define rep(i, a, b) for ( int i = (a); i < (b); i++ )
#define per(i, a, b) for ( int i = (b)-1; i >= (a); i--)
#define pb push_back
#define mp make_pair
#define bg begin()
#define en end()
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define sz(v) (int)(v).size()

using namespace std;

typedef long long ll;
typedef long double ld;

using P = pair<int, int>;

static const long long MOD = 1000000007;
static const long long LINF = (ll)(1e18+99);
static const int INF = 1e9+99;

ll ans;

int main(void) {
    int N;
    ll M;
    cin >> N >> M;
    vector<ll> A, S;
    rep(i, 0, N) {
      ll a;
      cin >> a;
      A.pb(a);
    }
    
    sort(all(A));
    S.pb(0);
    rep(i, 1, N+1) {
      S.pb(S[i-1]+A[i-1]);
    }
    
    ll l = 0, r = 2000000;
    while (r-l>1) {
      ll m = (r+l)/2;
      ll c = 0;
      rep(i,0, N) {
        ll t = A.en - upper_bound(all(A), m - A[i]);
        c += t;
      }
      if (c<M) r = m;
      else l = m;
    }
    
    
    ll c = 0;
    ll sn = (ll)sz(S);
    rep(i,0, N) {
      auto itr = lower_bound(all(A), r - A[i]);
      int p = itr - A.bg;
      ll num = A.en-itr;
      ans += S[sn-1] - S[p] + A[i]*num;
      c += num;
    }
    

    ans -= (c-M)*r;
  
    cout << ans << endl;
    return 0;
}




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

int main(){
    size_t X, Y, Z, N;
    cin >> X >> Y >> Z;
    N = X + Y + Z;
    vector<pair<long, long>> coins(N);
    long ans{0};
    for(auto& i : coins){
        long a;
        cin >> a >> i.first >> i.second;
        i.first -= a;
        i.second -= a;
        ans += a;
    }
    sort(coins.begin(), coins.end());
    vector<long> A(Z + 1), C(Z + 1);
    priority_queue<long> pq;
    for(size_t i = 0; i < X; ++i)pq.push(coins[i].second);
    for(size_t i = 0; i < Z; ++i){
        pq.push(coins[X + i].second);
        A[i + 1] = A[i] + pq.top();
        pq.pop();
    }
    pq = priority_queue<long>();
    reverse(coins.begin(), coins.end());
    for(size_t i = 0; i < Y; ++i){
        C[0] += coins[i].first;
        pq.push(coins[i].second - coins[i].first);
    }
    for(size_t i = 0; i < Z; ++i){
        pq.push(coins[Y + i].second - coins[Y + i].first);
        C[i + 1] = C[i] + pq.top() + coins[Y + i].first;
        pq.pop();
    }
    vector<long> B(Z + 1);
    transform(A.begin(), A.end(), C.rbegin(), B.begin(), plus<>());
    cout << *max_element(B.begin(), B.end()) + ans << endl;
    return 0;
}

Measured memory_bytes: 3572
#include<stdio.h>
#include<math.h>
int main(){
 double x1,x2,y1,y2;
 double d;

 scanf("%lf %lf %lf %lf",&x1,&y1,&x2,&y2);

 d=sqrt(pow(x2-x1,2)+pow(y2-y1,2));

 printf("%lf\n",d);

return 0;
}

Measured memory_bytes: 652
#pragma GCC optimize("Ofast")
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <functional>
#include <math.h> 
#define enld '\n'
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
// constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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; }
// ---------------------------------------------------------------------------


int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int N;
  cin >> N;
  bool can = false;
  int mn = inf;
  ll sum = 0;
  for(int i=0; i<N; i++){
    int a,b;
    cin >> a >> b;
    sum += a;
    if(a != b) can = true;
    if(a > b) chmin(mn,b);
  }
  if(can){
    cout << sum - mn << "\n";
  }else{
    cout << 0 << "\n";
  }
  return 0;
}


Measured memory_bytes: 3600
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <algorithm>

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

using namespace std;

int main() {
  while(1) {
    int n;
    cin>>n;
    if(!n)break;
    vector<pair<int,int>> g;
    REP(i,n) {
      int m,l;
      cin>>m>>l;
      int bits = 0;
      REP(j,m) {
        int s,e;
        cin>>s>>e;
        s-=6;
        e-=6;
        for(int k=s;k<e;++k) {
          bits |= 1 << k;
        }
      }
      g.emplace_back(bits, l);
    }
    vector<int> dp(1<<16,0);
    REP(i,1<<16){
      REP(j,n) {
        if ((i&g[j].first) == 0) {
          int b=i|g[j].first;
          dp[b] = max(dp[b], dp[i] + g[j].second);
        }
      }
    }
    cout<<*max_element(begin(dp),end(dp))<<endl;
  }
  return 0;
}

Measured memory_bytes: 1452
import java.util.Scanner;

public class Main{
	  public static void main(String[] args){
		    Scanner sc = new Scanner(System.in);
		    int N = sc.nextInt();
		    int A = sc.nextInt();
		    int B = sc.nextInt();
		    int total = 0;

		    for(int i = 1; i <= N; i++){
		    	int sum = findSumOfDigits(i);
		    	if (sum >= A && sum <= B) {
		    		total += i;
		      }
		    }
		    System.out.println(total);
	  }

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

}

Measured memory_bytes: 21716
use std::io::*;
use std::str::FromStr;

pub fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

use std::collections::HashSet;

fn main() {
    let n: usize = read();
    let mut hs: HashSet<char> = HashSet::new();

    for _ in 0..n {
        let ni = read::<String>().chars().nth(0).unwrap();
        hs.insert(ni);
    }
    println!(
        "{}",
        match hs.len() {
            3 => "Three",
            4 => "Four",
            _ => "",
        }
    )
}


Measured memory_bytes: 4352
from sys import stdin, stdout
from collections import deque

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	n, k = rli()
	A = list(rli())
	for i in range(n):
		A[i] -= 1
	L, seen = 0, set()
	cycle = deque()
	curr, cnt = 0, 0
	final = 0
	init = 0
	while cnt <= k:
		if cnt == k:
			print(curr + 1)
			return
		seen.add(curr)
		cycle.append(curr)
		L += 1
		curr = A[curr]
		if curr in seen:
			final = curr
			break
		cnt += 1
	while cycle and cycle[0] != final:
		init += 1
		cycle.popleft()
	L = len(cycle)
	last = (k-init) % L
	print(cycle[last] + 1)
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 106076
# -*- coding: utf-8 -*-
import sys
input = sys.stdin.readline

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

cur = 1
kudaku = 0
for i in a:
    if i == cur:
        cur+=1
    else:
        kudaku+=1
if kudaku==n:
    kudaku = -1
print(kudaku)

Measured memory_bytes: 24988
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
const ll INF = 1000000000000000000;
int main(){
    int n;
    cin >> n;
    bool ok =true;
    vector<ll> a(n);
    rep(i,n) cin >> a[i];
    rep(i,n){
        if(a[i] == 0){
            cout << 0 <<endl;
            return 0;
        }
    }
    __int128 ans=1;
    rep(i,n){
        ans *= __int128(a[i]);
        if((ans)>INF){
            ok =false;
            break;
        }
        
    }
    if(ok) cout << ll(ans) <<endl;
    else cout << -1 <<endl;
    
}

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

long long ans = 0;
int n;
string x;

void solve(string form)
{
    int p[n], cnt = 0;
    memset(p, 0, sizeof p);
    char c = form[2];
    for (int i = n - 1; i >= 0; i--) {
        if (c == x[i]) p[i] = ++cnt;
    }
    long long re = 0;
    for (int i = 1; i < n - 1; i++) {
        for (int j = 0; j < n; j++) {
            if (!(j + i < n)) break;

            if (x[j] == form[0] && x[j + i] == form[1]) {
                bool ok = false;
                if (j + 2 * i < n && x[j + 2 * i] == form[2]) {
                    ok = true;
                }
                int nxt = -1;
                for (int k = j + i + 1; k < n; k++) {
                    if (x[k] == form[2]) {
                        nxt = k;
                        break;
                    }
                }
                if (nxt == -1) break;
                else {
                    re += p[nxt];
                    if (ok) re--;
                }
            }
        }
    }
    ans += re;
}

int main()
{
    cin >> n >> x;
    solve("RGB");
    solve("BGR");
    solve("BRG");
    solve("GBR");
    solve("GRB");
    solve("RBG");
    cout << ans << "\n";
}


Measured memory_bytes: 3648
#include<stdio.h>
#define MAX 100
int main()
{
    int n,i;
    int b[MAX-1];
    int a[MAX];
    int ans=0;
    scanf("%d", &n);

    for (i = 1; i <= n-1 ; i++ )
        scanf("%d", &b[i]);
    a[1] = b[1];
    for (i = 1; i < n - 1; i++)
    {
        if(b[i]<=b[i+1])
            a[i+1] = b[i];
        else if(b[i]>b[i+1])
            a[i+1] = b[i + 1];
    }
    a[n] = b[n - 1];
    
    for (i = 1; i <= n; i++)
        ans += a[i];
    printf("%d\n", ans);
    return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rrep(i, n) for (int i = (int)(n - 1); i >= 0; i--)
#define all(x) (x).begin(), (x).end()
#define sz(x) int(x.size())
#define get_unique(x) x.erase(unique(all(x)), x.end());
typedef long long ll;
typedef complex<double> Complex;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll LINF = 1e18;
template <class T>
bool chmax(T& a, const T& b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T& a, const T& b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
vector<T> make_vec(size_t a) {
    return vector<T>(a);
}
template <class T, class... Ts>
auto make_vec(size_t a, Ts... ts) {
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}

int main() {
    int n;
    cin >> n;
    vector<int> a(n), b(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    int ans = 0;
    rep(i, n) {
        int now = 0;
        for (int j = 0; j <= i; j++) now += a[j];
        for (int j = i; j < n; j++) now += b[j];
        chmax(ans, now);
    }
    cout << ans << endl;
}

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

using namespace std;
vector<int>v;
int  main()
{ long long n,k;
cin>>n>>k;
for (long long i=0;i<n;i++)
{
    long long x;
    cin>>x;
    v.push_back(x);
}
sort (v.begin(),v.end());
while (!v.empty())
{
    if (k==0)break;
    v.pop_back();
    k--;
}
  long long sum=0;
  for (long long i=0;i<v.size();i++)
  {
      sum+=v[i];
  }
  cout <<sum;
}


Measured memory_bytes: 1400
use std::str::FromStr;
use std::fmt::Debug;
use std::cmp;

#[allow(dead_code)]
fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()

}

#[allow(dead_code)]
fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn main(){
    let line = read_as_vec::<usize>();
    let (n, k) = (line[0], line[1]);

    let line = read_as_vec::<usize>();
    let (r, s, p) = (line[0], line[1], line[2]);

    let t = read_as_string().chars().collect::<Vec<char>>();

    let mut table: Vec<Vec<(char, usize)>> = vec![vec![];k];

    for i in 0..t.len(){
        if let Some(last_elem) = table[i%k].last_mut(){
            if last_elem.0 == t[i]{
                last_elem.1 += 1;
                continue;
            }
        }
        table[i%k].push((t[i], 1));

    }

    let mut point = 0;
    for i in 0..table.len(){
        for j in 0..table[i].len(){
            let mypoint: usize;
            if table[i][j].0 == 'r'{
                mypoint = p;
            }else if table[i][j].0 == 's'{
                mypoint = r;
            }else{
                mypoint = s;
            }

            point += (table[i][j].1+1)/2*mypoint;
        }
    }

    println!("{}", point);
}


Measured memory_bytes: 14588
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)(n);++i)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;--i)
#define srep(i,s,t) for(int i=(int)(s);i<(int)(t);++i)
#define each(a,b) for(auto& (a): (b))
#define all(v) (v).begin(),(v).end()
#define len(v) (int)(v).size()
#define zip(v) sort(all(v)),v.erase(unique(all(v)),v.end())
#define cmx(x,y) x=max(x,y)
#define cmn(x,y) x=min(x,y)
#define fi first
#define se second
#define pb push_back
#define show(x) cout<<#x<<" = "<<(x)<<endl
#define spair(p) cout<<#p<<": "<<p.fi<<" "<<p.se<<endl
#define sar(a,n) cout<<#a<<":";rep(pachico,n)cout<<" "<<a[pachico];cout<<endl
#define svec(v) cout<<#v<<":";rep(pachico,v.size())cout<<" "<<v[pachico];cout<<endl
#define svecp(v) cout<<#v<<":";each(pachico,v)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl
#define sset(s) cout<<#s<<":";each(pachico,s)cout<<" "<<pachico;cout<<endl
#define smap(m) cout<<#m<<":";each(pachico,m)cout<<" {"<<pachico.first<<":"<<pachico.second<<"}";cout<<endl

using namespace std;

typedef pair<int,int> P;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<P> vp;
typedef vector<string> vs;

const int MAX_N = 1000005;

ll inv[MAX_N],fac[MAX_N],finv[MAX_N];

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

ll comb(int a,int b)
{
	if(a<b){
		return 0;
	}
	return fac[a] * (finv[b] * finv[a-b] % MOD) % MOD;
}

ll add(ll x,ll y)
{
    return (x + y)%MOD;
}

ll sub(ll x,ll y)
{
    return (x+MOD-y)%MOD;
}

ll mul(ll x,ll y)
{
    return x*y%MOD;
}

int f[MAX_N];

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    if(n == 2){
        cout << "1\n";
        return 0;
    }
    make();
    int ans = 0;
    srep(i,(n+1)/2,n){
        f[i] = mul(comb(i-1,n-1-i),mul(fac[i],fac[n-1-i]));
    }
    rep(i,n){
        ans = add(ans,mul(i,sub(f[i],f[i-1])));
    }
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 26496
#include<cstdio>
#include<iostream>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<queue>
#include<stack>
#include<map>
#include<set>
#include<vector>
#define ll long long
#define INF 0x3f3f3f3f
using namespace std;
const int N=1e5+5;
template<class T>inline void read(T &res)
{
char c;T flag=1;
while((c=getchar())<'0'||c>'9')if(c=='-')flag=-1;res=c-'0';
while((c=getchar())>='0'&&c<='9')res=res*10+c-'0';res*=flag;
}
int n;
int f[15][15];
int main(){	
	read(n);
	for(int i=1;i<=n;i++){
		int t=i,st=-1,la=-1;
		while(t){
			if(la==-1)la=t%10;
			st=t%10;
			t/=10;
		}
		f[st][la]++;
		//printf("st=%d la=%d i=%d\n",st,la,i);
	}
	ll ans=0;
	for(int i=1;i<=n;i++){
		int t=i,st=-1,la=-1;
		while(t){
			if(la==-1)la=t%10;
			st=t%10;
			t/=10;
		}
		if(st==0||la==0)continue;
		ans+=f[la][st];
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 256
o = input()
e = input()
if len(o) > len(e):
  a = o[0]+e[0]
  for i in range(1,len(e)):
    a += o[i] + e[i]
  print(a+o[-1])
elif len(o) == len(e):
  a = o[0]+e[0]
  for i in range(1,len(e)):
    a += o[i] + e[i]
  print(a)
else:
  a = e[0]+o[0]
  for i in range(1,len(o)):
    a += e[i] + o[i]
  print(a+e[-1])

Measured memory_bytes: 3064
k,q=map(int,input().split())
d=list(map(int,input().split()))
n=[0 for i in range(q)]
x=[0 for i in range(q)]
m=[0 for i in range(q)]
for i in range(0,q):
    n[i],x[i],m[i]=map(int,input().split())
x=[x[i]%m[i] for i in range(0,q)]
S=sum(d)
for i in range(0,q):
    p=[d[j]%m[i] for j in range(0,k)]
    test=0
    subtest=0
    for j in range(0,k):
        if p[j]!=0:
            test+=1
    s=x[i]%m[i]+sum(p)*((n[i]-1)//k)+sum(p[j] for j in range(0,(n[i]-1)%k))
    for j in range(0,(n[i]-1)%k):
        if p[j]!=0:
            subtest+=1
    if s%m[i]==0:
        print(test*((n[i]-1)//k)+subtest-(s//m[i]))
    else:
        print(test*((n[i]-1)//k)+subtest-(s//m[i]))


Measured memory_bytes: 72408
#include<iostream>
#include<vector>
#include<string>
#include <algorithm>
#include <cmath>

using namespace std;
const long long INF = (long long) (1e18)+1;

int main() {
  long long k;
  long long n;
  // k meter, n こ
  cin >> k >> n;

  vector<int> nums(n);
  for(int i=0; i<n; ++i) {
    cin >> nums[i];
  }
  int ans=k;
  int next_left = nums.size()-1;
  int next_right = 1;

  for (int i = 0; i<n; ++i) {
    // left or right
    // 
    // cout << "starting " << i << endl;
    // cout << i << " " << nums[next_left] << " " << nums[i] << endl;
    // cout << i << " " << nums[next_right] << " " << nums[i] << endl;
    int left;
    int right;
    if (nums[next_left] < nums[i]) {
      left = k - nums[i] + nums[next_left];
    } else {
      left = nums[next_left] - nums[i];
    }
    if (nums[next_right] > nums[i]) {
      right = abs(nums[next_right] - nums[i] - k);
    } else {
      right = abs(nums[next_right] - nums[i]);
    }
    // cout << "left" << left << " right " << right << endl;
    
    int temp = min(left, right);
    // cout << temp << endl;

    ans = min(ans, temp);
    if (i == 0) {
      next_left = 0;
    } else {
      next_left++;
    }
    if (next_right == n-1) {
      next_right = 0;
    } else {
      next_right++;
    }
  }

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

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#include <string>
using namespace std;
 
int main(){
 
    string s,ans;

    cin >> s;

    for(int i=0;i<=s.size();i++){
        if(s[i]=='0'){
            ans += '0';
        }else if(s[i]=='1'){
            ans += '1';
        }else if(s[i]=='B'){
            if(ans.size()!=0){
                ans.pop_back();
            }
        }
    }

    cout << ans <<endl;

}

Measured memory_bytes: 256
S = input()
N = len(S) 
P = []
var = 0
for k in range(N-1):
  if S[k] == 'R':
    if S[k+1] == 'R':
      var = var+1
      P.append(0)
    elif S[k+1] == 'L':
      if var%2 == 0:
        P.append(1 + var//2)
        P.append(1 + var//2)
        var = 0
      else:
        P.append(1 + (var-1)//2)
        P.append(1 + (var+1)//2)
        var = 0
  elif S[k] == 'L':
    if S[k+1] == 'R':
      if var%2 == 0:
        P[-1] = P[-1] + (var//2)
        P[-2] = P[-2] + (var//2)
        for j in range(var):
          P.append(0)
        var = 0
      else:
        P[-1] = P[-1] + ((var-1)//2)
        P[-2] = P[-2] + ((var+1)//2)
        for j in range(var):
          P.append(0)
        var = 0        
    elif k == N-2:
      var = var+1
      if var%2 == 0:
        P[-1] = P[-1] + (var//2)
        P[-2] = P[-2] + (var//2)
        for j in range(var):
          P.append(0)
        var = 0
      else:
        P[-1] = P[-1] + ((var-1)//2)
        P[-2] = P[-2] + ((var+1)//2)
        for j in range(var):
          P.append(0)
        var = 0
    elif S[k+1] == 'L':
      var = var+1    
print(*P, sep=" ")

Measured memory_bytes: 6640
S=input()
T=input()
NS=len(S)
NT=len(T)
ans=pow(10,9)
for n in range(NS-NT):
    suuji=0
    for m in range(NT):
        if S[n+m]!=T[m]:
            suuji+=1
    ans=min(ans,suuji)
if NS==NT:
    suuji=0
    for n in range(NS):
        if S[n]!=T[n]:
            suuji+=1
    ans=min(suuji,ans)
print(ans)


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

using namespace std;

int main() {
  	int n, x;
  	cin >> n >> x;
  	vector<int> a;
  	a.push_back(0);
  	for (int i = 0; i < n; i++) {
      	int z;
      	cin >> z;
      	a.push_back(z);
    }
  	long long ans = 0;
  	for (int i = 0; i < n; i++) {
        long long s = a[i] + a[i + 1];
    	if (s > x) {
        	a[i + 1] -= s - x;
            ans += s - x;
        }
    }
  	cout << ans;    
}

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

struct UnionFind {
  vector<int> parent;
  vector<int> size;

  UnionFind(int n) : parent(n, -1), size(n, 1) {}

  int find(int i) {
    if (parent[i] == -1) {
      return i;
    }
    return parent[i] = find(parent[i]);
  }

  int get_size(int i) {
    return size[find(i)];
  }

  void unite(int i, int j) {
    i = find(i);
    j = find(j);
    if (i == j) {
      return;
    }
    if (size[i] < size[j]) {
      parent[i] = j;
      size[j] += size[i];
    } else {
      parent[j] = i;
      size[i] += size[j];
    }
  }
};

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

  UnionFind uf(n);
  for (int i=0; i<m; i++) {
    int x, y;
    cin>>x>>y;
    uf.unite(x, y);
  }
  set<int> forest;
  for (int i=0; i<n; i++) {
    forest.insert(uf.find(i));
  }
  if (forest.size() * 2 - 2 > n) {
    cout<<"Impossible"<<endl;
    return 0;
  }
  if (forest.size() == 1) {
    cout<<0<<endl;
    return 0;
  }
  map<int, vector<int>> ws;
  for (int i=0; i<n; i++) {
    ws[uf.find(i)].push_back(a[i]);
  }
  long long ans = 0;
  vector<int> rests;
  for (auto e: ws) {
    sort(e.second.begin(), e.second.end());
    ans += e.second[0];
    for (int i=1; i<e.second.size(); i++) {
      rests.push_back(e.second[i]);
    }
  }
  sort(rests.begin(), rests.end());
  int x = forest.size() - 2;
  for (int i=0; i<x; i++) {
    ans += rests[i];
  }
  cout<<ans<<endl;
}

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

using namespace std;

int main(){
   int n,a,b;
   int ans=0;
   cin>>n>>a>>b;
   
   for(int i=1; i<=n; i++){
       string strnum=to_string(i);
       int sum=0;
       for(int j=0; j<strnum.length(); j++){
          sum+=strnum[j]-'0';
       }
       if((a<=sum)&&(sum<=b)) ans+=i;
   }
   cout<<ans<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstdlib>
#include <cstdio>
#include <queue>
#include <stack>
#include <list>
#include <utility>
#include <vector>
#include <set>
#include <algorithm>
#include <cmath>
#include <climits>
#include <map>
#include <unordered_map>
#include <string.h>
#include<iomanip>
#include <iterator>
#include <locale>

#define all(a) a.begin(),a.end()
#define VV(T) vector<vector< T > >
#define rep(i,N) for(int i = 0; i <N; i++)
#define repsg(i,s,g) for(int i = s; i <g; i++)
#define name(x) #x
using namespace std;

const int INF = INT_MAX;
const long long INFL = 1LL<<40;
const double PI = atan(1)*4;
const long long MOD = pow(10,9)+7;
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

typedef long long ll,LL;
typedef vector<int> vint;
typedef vector<vector<int> > vvint;
typedef vector<long long> vll, vLL;
typedef vector<vector<long long> > vvll, vvLL;
typedef pair<int,int> pii;
typedef pair<LL, LL> pLL;


// vector入力
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
    for(T& x: vec) is >> x;
    return is;
}
// vector出力
template<typename T>
ostream& operator << (ostream& os, vector<T>& vec){
    for(int i=0; i<vec.size(); i++){
        os << vec[i] << ( i+1 == vec.size() ? "" : " " );
    }
    return os;
}


int main() {
    int k,t;cin>>k>>t;
    vector<int> a(t);cin>>a;
    int s=0;
    rep(i,t){
        s+=a[i];
    }
    int v = *max_element(all(a));
    
    int c = max(v-(s-v)-1,0);
    
    cout<<c<<endl;
    
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (int i = (a); i >= (b); i--)
#define LFOR(i, a, b) for (long long int i = (a); i <= (b); i++)
#define LRFOR(i, a, b) for (long long int i = (a); i >= (b); i--)
#define MOD 1000000007
#define INF 1000000000           // 2000000000
#define LINF 1000000000000000000 // 9000000000000000000
#define DINF 1000000000000000.0
#define PI 3.14159265358979

//.size()はunsigned int　0-1をするとオーバーフローする

using namespace std;
typedef long long int ll;
typedef pair<long long int, long long int> P;

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

int main(void) {
    int a,b;

    cin>>a>>b;

    if(2*b>=a){
        cout<<0<<endl;
    }else{
        cout<<a-2*b<<endl;
    }
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>

#include <iostream>
#include <complex>
#include <string>
#include <algorithm>
#include <numeric>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>

#include <functional>
#include <cassert>

typedef long long ll;
using namespace std;

#ifndef LOCAL
#define debug(x) ;
#else
#define debug(x) cerr << __LINE__ << " : " << #x << " = " << (x) << endl;

template <typename T1, typename T2>
ostream &operator<<(ostream &out, const pair<T1, T2> &p) {
  out << "{" << p.first << ", " << p.second << "}";
  return out;
}

template <typename T>
ostream &operator<<(ostream &out, const vector<T> &v) {
  out << '{';
  for (const T &item : v) out << item << ", ";
  out << "\b\b}";
  return out;
}
#endif

#define mod 1000000007 //1e9+7(prime number)
#define INF 1000000000 //1e9
#define LLINF 2000000000000000000LL //2e18
#define SIZE 200010


int main(){
  string s;

  cin >> s;

  for(int i=0; i<s.size(); i++) {
    if((i%2 == 0 && s[i] == 'L') ||
       (i%2 == 1 && s[i] == 'R')) {
      puts("No");
      return 0;
    }
  }

  puts("Yes");

  return 0;
}


Measured memory_bytes: 256