akhauriyash/Code-Regression huggingface dataset:
s=input()

s=s[::-1]

X=['maerd','remaerd','esare','resare']
ans='YES'
i=0
while i<=len(s)-5:
    if s[i:i+5] in X:
        i+=5
    else:
        if s[i:i+6] in X:
            i+=6
        else:
            if s[i:i+7]  in X:
                i+=7
            else:
                ans='NO'
                break

print(ans)

Measured memory_bytes: 3188
#include<iostream>
using namespace std;
int main(void){
    for(int i = 0; i < 5; i++){
        long long n, k, a, sum = 0, ans = 0; 
        cin >> n >> k;
        if(n==0&&k==0){
            return 0;
        }
      int test[100001] = { 0 };
      for(int h = 0; h < n; h++){
          cin >> a;
          test[h] = a;
          if(h < k){
            sum += a;
            ans += a;
          }
      }
      for(int h = 0; h < n - k; h++){
        ans = max(ans, sum - test[h] + test[h + k]);
        sum = sum - test[h] + test[h + k];
      }
       cout << ans << endl;
   }
}


Measured memory_bytes: 3432
import java.util.*;
import java.io.*;

public class Main {
    public static void main(String... args) {
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String password = null;
        try {

            password = br.readLine();
            br.close();
        } catch(IOException e) {
            e.printStackTrace();
        }

        System.out.println(isDifficultToInput(password) ? "Bad" : "Good");
    }

    private static boolean isDifficultToInput(String word){
        String[] splitWord = word.split("");

        for(int i = 0; i < splitWord.length - 1; i++){
            String rear = splitWord[i];
            String front = splitWord[i+1];
            if(front.equals(rear)){
                return true;
            }
        }
        return false;
    }
}

Measured memory_bytes: 22484
[N,M] = list(map(int,input().split()))
pS=[]
for i in  range(M):
    [p,S] = list(input().split())
    pS.append([int(p),S])


ACflag=[0]*N
WAcount=[0]*N

for i in range(M):
    if ACflag[pS[i][0] -1] ==0:
        if pS[i][1]=="AC":
            ACflag[pS[i][0] -1] = 1
        else:
            WAcount[pS[i][0] -1] +=1

for j in range(N):
    WAcount[j] *= ACflag[j]

print(sum(ACflag), sum(WAcount))


Measured memory_bytes: 67544
import java.util.*;
public class Main {

	public static void main(String[] args) {

Scanner sc=new Scanner(System.in);
			String s=sc.next();
			
			int j=s.length()-1;
			int ind1=0;
			int count=0;
			int count2=0;
			int ind2=0;
			for(int i=0;i<j+1;i++) {
				if(s.charAt(i)=='A') {
					ind1=i;
					break;
				}
			}	for(int i=j;i>=0;i--) {
				if(s.charAt(i)=='Z') {
					ind2=i;
					break;
				}
			}
			if(ind2-ind1!=0) {
			System.out.println(ind2-ind1+1);
			}

	}

}


Measured memory_bytes: 40124
use std::io::prelude::*;

fn input<T: std::str::FromStr>() -> T {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

#[allow(dead_code)]
fn with_stdout_lock<F: FnOnce(std::io::BufWriter<std::io::StdoutLock>)>(f: F) {
    let out = std::io::stdout();
    let w = std::io::BufWriter::new(out.lock());
    f(w);
}

#[allow(unused_macros)]
macro_rules! debug {
    ($var:expr) => {
        match &$var { v => eprintln!(concat!(stringify!($var), "={:?}"), v) }
    };
    ($var:expr, $($vars:expr),*) => {
        match &$var { v => eprint!(concat!(stringify!($var), "={:?} "), v) }
        debug!($($vars),*);
    };
}

fn main() {
    let d: i32 = input();
    let g: i32 = input();
    let pc: Vec<(i32, i32)> = (0..d).map(|_| (input(), input())).collect();

    let mut ans = i32::max_value();
    for i in 0..1 << d {
        let mut score = 0;
        let mut cnt = 0;
        for j in 0..d {
            if (i >> j) & 1 == 1 {
                let (p, c) = pc[j as usize];
                score += (j + 1) * 100 * p + c;
                cnt += p;
            }
        }
        if score < g {
            let mut highest = -1;
            for j in 0..d {
                if (i >> j) & 1 == 0 {
                    highest = j;
                }
            }
            if highest >= 0 {
                let (p, _) = pc[highest as usize];
                let pmin = (g - score + (highest + 1) * 100 - 1) / ((highest + 1) * 100);
                if pmin < p {
                    score += (highest + 1) * 100 * pmin;
                    cnt += pmin;
                }
            }
        }
        if score >= g {
            ans = std::cmp::min(ans, cnt);
        }
    }

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


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

int main (){
  char C;
  
  cin >> C;
  
  if (C == 'a'||
      C == 'i'||
      C == 'u'||
      C == 'e'||
      C == 'o'){
    cout << "vowel" << endl;
  } 
  else {
    cout << "consonant" << endl;
  }
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <math.h>
#include <queue>
using namespace std;
typedef long long ll;

ll count(vector<int> &R, vector<int> &G, vector<int> &B) {
  ll sum = 0;
  for (int i = 0; i < R.size(); i ++) {
    for (auto j = std::lower_bound(G.begin(), G.end(), R[i]); j < G.end(); j ++) {
      int a = *j - R[i];
      for (auto k = std::lower_bound(B.begin(), B.end(), *j); k < B.end(); k ++) {
        if (a == *k - *j) {
          continue;
        }
        sum ++;
      }
    }
  }
  return sum;
}

int main() {
  int N;
  char S;
  vector<int> R, G, B;
  cin >> N;
  for (int i = 0; i < N; i++) {
    cin >> S;
    if (S == 'R') {
      R.push_back(i);
    } else if(S == 'G') {
      G.push_back(i);
    } else if(S == 'B') {
      B.push_back(i);
    }
  }
  ll sum = 0;
  sum += count(R, B, G);
  sum += count(R, G, B);
  sum += count(B, R, G);
  sum += count(B, G, R);
  sum += count(G, R, B);
  sum += count(G, B, R);
  cout << sum << endl;
  return 0;
}

Measured memory_bytes: 3640
from heapq import heappush,heappop,heapify
from collections import deque,defaultdict,Counter
import itertools
from itertools import permutations,combinations,groupby
import sys
import bisect
import string
import math
import time
import random
def S_():
    return input()
def LS():
    return [i for i in input().split()]
def I():
    return int(input())
def MI():
    return map(int,input().split())
def LI():
    return [int(i) for i in input().split()]
def LI_():
    return [int(i)-1 for i in input().split()]
def NI(n):
    return [int(input()) for i in range(n)]
def NI_(n):
    return [int(input())-1 for i in range(n)]
def StoI():
    return [ord(i)-97 for i in input()]
def ItoS(nn):
    return chr(nn+97)
def LtoS(ls):
    return ''.join([chr(i+97) for i in ls])
def GI(V,E,Directed=False,index=0):
    org_inp=[]
    g=[[] for i in range(n)]
    for i in range(E):
        inp=LI()
        org_inp.append(inp)
        if index==0:
            inp[0]-=1
            inp[1]-=1
        if len(inp)==2:
            a,b=inp
            g[a].append(b)
            if not Directed:
                g[b].append(a)
        elif len(inp)==3:
            a,b,c=inp
            aa=(inp[0],inp[2])
            bb=(inp[1],inp[2])
            g[a].append(bb)
            if not Directed:
                g[b].append(aa)
    return g,org_inp
def bit_combination(k,n=2):
    rt=[]
    for tb in range(n**k):
        s=[tb//(n**bt)%n for bt in range(k)]
        rt+=[s]
    return rt
def show(*inp,end='\n'):
    if show_flg:
        print(*inp,end=end)
YN=['Yes','No']
mo=10**9+7
inf=float('inf')
l_alp=string.ascii_lowercase
u_alp=string.ascii_uppercase
ts=time.time()
sys.setrecursionlimit(10**5)
input=lambda: sys.stdin.readline().rstrip()

def ran_input():
    import random
    n=random.randint(4,16)
    rmin,rmax=1,10
    a=[random.randint(rmin,rmax) for _ in range(n)]
    return n,a

show_flg=False
show_flg=True

ans=0

n,k,s=LI()
ans=[]

c=[s-1,1]

if s==1:
    ans=[1]*k+[10**9]*(n-k)
    print(*ans)
    exit()

if k==0 and s==10**9:
    print(*[10**9-1]*(n))
    exit()
if s==10**9:
    ans=[10**9]*(k)+[10**9-1]*(n-k)
    print(*ans)
    exit()
    
if n==k:
    ans=[s]*n
else:
    t=0
    for i in range(n):
        if i<k+1:
            ans.append(c[t])
        else:
            ans.append(10**9)
        t=1-t
        


print(*ans)



Measured memory_bytes: 49900
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
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;
}
void hr() {
   cerr << "--------------" << endl;
}
const int INF = 1001001001;
const int MOD = 1000000007;

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

   int n;
   cin >> n;
   vector<int> a(n);
   rep(i, 0, n) cin >> a[i];
   rep(i, 0, n) a[i]--;
   vector<int> id(n);
   rep(i, 0, n) id[a[i]] = i;

   set<int> s;
   ll ans = 0;
   rrep(x, n - 1, 0) {
      int i = id[x];
      ll c = 0;

      s.insert(i);
      vector<int> l(2, -1), r(2, n);
      auto it = s.find(i);
      rep(j, 0, 2) {
         if (it == s.begin()) break;
         it--;
         l[j] = *it;
      }
      it = s.find(i);
      rep(j, 0, 2) {
         it++;
         if (it == s.end()) break;
         r[j] = *it;
      }
      vector<int> ls(2);
      ls[0] = i - l[0];
      ls[1] = l[0] - l[1];
      vector<int> rs(2);
      rs[0] = r[0] - i;
      rs[1] = r[1] - r[0];
      c = ls[0] * rs[1] + (ll)ls[1] * rs[0];
      ans += c * (x + 1);
   }
   cout << ans << endl;
   return 0;
}

Measured memory_bytes: 5760
//============================================================================
// Name        : JOI.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;
typedef long long ll;
ll A,B;
int main() {
	cin>>A>>B;


	cout<<(A+B)/2<<endl;

	return 0;
}

Measured memory_bytes: 3116
#include<iostream>
#include<algorithm>
#include<vector>
#include<functional>
#include<string>
#include<cmath>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<cstdio>
using namespace std;
using ll = long long;
int main(){
  string s;
  cin >> s;
  if(s[0] == s[1] && s[1] == s[2]){
    cout << "Yes\n";
  }else if(s[1] == s[2] && s[2] == s[3]){
    cout << "Yes\n";
  }else{
    cout << "No\n";
  }
  return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#define MAX 2000000

int H,A[MAX+1];

void  swap(int *x, int *y)
{
    int  work;        /* ????\???¨ */

    work = *x;        /* x????????????????????? */
    *x = *y;          /* x?????????y???????????????????????? */
    *y = work;        /* y?????????x???????????????????????? */
}

void maxHeapify(int i) {
  int l,r,largest;
  l = 2*i;
  r = 2*i+1;

  if(l <= H && A[l] > A[i]) largest = l;
  else largest = i;
  if(r <= H && A[r] > A[largest]) largest = r;

  if(largest != i){
    swap(&A[i], &A[largest]);
    maxHeapify(largest);
  }
}

int main() {
  int i;
  scanf("%d\n", &H);

  for( i = 1;i<=H;i++) scanf("%d\n", &A[i]);
  for( i = H/2; i>= 1;i--) maxHeapify(i);
  for( i=1;i<=H;i++) printf(" %d", A[i]);
  printf("\n" );

  return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<string>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
#include<vector>
#include<math.h>
#include<time.h>

using namespace std;

#define INF 1000000007
#define LINF (1LL << 62)

typedef long long i64;
typedef pair<i64,i64> P;


int n, a[10], b[10];
bool used[10];
int cnt = 0;
int A,B;

void dfs(int now, string s){
	if(now == n){
		cnt++;
		bool aa = 1, bb = 1;
		for(int i = 0; i < n; i++){
			if(s[i]-'0' != a[i]){
				aa = 0;
			}
			if(s[i]-'0' != b[i]){
				bb = 0;
			}
		}
		if(aa) A = cnt;
		if(bb) B = cnt;
		return;
	}
	for(int i = 1; i <= n; i++){
		if(used[i]) continue;
		used[i] = 1;
		dfs(now+1, s+(char)('0'+i));
		used[i] = 0;
	}
}

int main(){
	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	for(int i = 0; i < n; i++){
		cin >> b[i];
	}
	string s;
	dfs(0,s);
	
	cout << abs(A - B) << endl;
	
	return 0;
}

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

using namespace std;

#define N 100

int n,ans,c,a[N];
pair<int,int> out[N];

int main(){
	scanf("%d",&n);
	c=0;
	for (int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		if (abs(a[i])>=abs(a[c])) c=i;
	}
	for (int i=1;i<=n;i++){
		out[++ans]=make_pair(c,i);
		a[i]+=a[c];
	}
	if (a[1]>=0){
		for (int i=2;i<=n;i++)
			if (a[i]<a[i-1]){out[++ans]=make_pair(i-1,i); a[i]+=a[i-1];}
	}
	else{
		for (int i=n-1;i>=1;i--)
			if (a[i]>a[i+1]){out[++ans]=make_pair(i+1,i); a[i]+=a[i+1];}
	}
	printf("%d\n",ans);
	for (int i=1;i<=ans;i++) printf("%d %d\n",out[i].first,out[i].second);
	
	return 0;
}
			

Measured memory_bytes: 256
# Bubble Sort

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

cnt = 0
flag = 1
while flag:
    flag = 0
    for j in range(n-1,0,-1):
        if a[j] < a[j-1]:
            tmp = a[j]
            a[j] = a[j-1]
            a[j-1] = tmp
            flag = 1
            cnt += 1

print(*a)
print(cnt)


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

const int MXN = 1e2 + 1, MXW = 1e5 + 1;

long long n, w, dp[MXN][MXW];
vector< pair<int, int> > wv;

void npt() {
	cin >> n >> w;
	for (int i = 0; i < n; i++) {
		int w, v;
		cin >> w >> v;
		wv.push_back({w, v});
	}
}

void fill() {
	for (int i = 0; i <= n; i++) {
		for (int k = 0; k <= w; k++) {
			if (i == 0 || k == 0)
				dp[i][k] = 0;
			else if (wv[i - 1].first <= k)
				dp[i][k] = 
					max(wv[i - 1].second + dp[i - 1][k - wv[i - 1].first],
						   	dp[i - 1][k]);
			else
				dp[i][k] = dp[i - 1][k];
		}
	}
}

void tpt() {
	cout << dp[n][w] << endl;
}

int main() {
	npt();
	fill();
	tpt();
	return 0;
}


Measured memory_bytes: 79104
#include <iostream>
    #include <vector>
    #include <bitset>
    #include <string>
    #include <array>
    #include <random>
    #include <chrono>
    #include <algorithm>
     
    int main(void){
    	int n, k;
    	std::cin >> n >> k;
    	int max = n * (n -1) / 2 - (n-1);
    	if(max < k){
    		std::cout << -1 << std::endl;
    	}
    	else{
    		std::cout << (n-1) + (max - k) << std::endl;
    		for(int i=2;i<=n;i++){
    			std::cout << 1 << " " << i << std::endl;
    		}
    		int cnt = max-k;
    		for(int i=2;i<=n;i++){
    			if(cnt == 0)break;
    			for(int j=i+1;j<=n;j++){
    				if(cnt == 0)break;
    				std::cout << i << " " << j << std::endl;
    				cnt--;
    			}
    		}
    	}
    	return 0;
    }


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

typedef pair<long long, long long> P;
long long INF = 1145141919810364364;

int main() {
	int N, M, S, T;
	static long long YenDis[100000], SnuukDis[100000], ANS[100000];
	static vector<P> Yen[100000], Snuuk[100000];
	priority_queue<P> PQYen, PQSnuuk;
	cin >> N >> M >> S >> T;
	S--, T--;
	for (int i = 0; i < N; i++) {
		YenDis[i] = INF;
		SnuukDis[i] = INF;
	}
	YenDis[S] = 0;
	SnuukDis[T] = 0;
	for (int i = 0; i < M; i++) {
		long long U, V, A, B;
		cin >> U >> V >> A >> B;
		U--, V--;
		Yen[U].push_back(P(A, V));
		Yen[V].push_back(P(A, U));
		Snuuk[U].push_back(P(B, V));
		Snuuk[V].push_back(P(B, U));
	}
	for (P p : Yen[S]) PQYen.push(p), YenDis[p.second] = p.first;
	for (P p : Snuuk[T]) PQSnuuk.push(p), SnuukDis[p.second] = p.first;
	while (PQYen.size()) {
		P p = PQYen.top();
		PQYen.pop();
		for (P q : Yen[p.second]) {
			if (YenDis[q.second] > YenDis[p.second] + q.first) {
				YenDis[q.second] = YenDis[p.second] + q.first;
				PQYen.push(q);
			}
		}
	}
	while (PQSnuuk.size()) {
		P p = PQSnuuk.top();
		PQSnuuk.pop();
		for (P q : Snuuk[p.second]) {
			if (SnuukDis[q.second] > SnuukDis[p.second] + q.first) {
				SnuukDis[q.second] = SnuukDis[p.second] + q.first;
				PQSnuuk.push(q);
			}
		}
	}
	ANS[0] = YenDis[N - 1] + SnuukDis[N - 1];
	for (int i = 1; i < N; i++) {
		ANS[i] = min(ANS[i - 1], YenDis[N - 1 - i] + SnuukDis[N - i - 1]);
	}
	for (int i = N - 1; i >= 0; i--) {
		cout << 1000000000000000 - ANS[i] << endl;
	}
}

Measured memory_bytes: 27376
import java.util.*;
import java.lang.*;
import java.io.*;

/* Name of the class has to be "Main" only if the class is public. */
class Main
{
	public static void main (String[] args) throws java.lang.Exception
	{
	     Scanner SC=new Scanner(System.in);
	     BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
	     PrintWriter pw=new PrintWriter(System.out);
	     int t=0;
	     
	     /*if(SC.hasNext())
	     t=SC.nextInt();
	     
	     for(int i=0;i<t;i++)
	     {
	          
	     }*/
	     
	     //int n;
	     //int a,b;
	     
	     String s;
	     
	     
	     s=br.readLine();
	     
	     int n=s.lastIndexOf("Z")-s.indexOf("A");
	     
	     
	     //x=(int)Math.max(0,x);
	     pw.println((n+1));
	     
	     //code for reading n long from bfreader in one line
	    /* String inp2=br.readLine();
	         for(int j=0;j<n-1;j++)
     	    {
     	         arr[j]=Long.parseLong(inp2.substring(0,inp2.indexOf(" ")));
     	         inp2=inp2.substring(inp2.indexOf(" ")+1);
     	    }
     	    arr[(int)n-1]=Long.parseLong(inp2);*/
	     
	     pw.close();     
		
}
}


Measured memory_bytes: 39504
# Author: cr4zjh0bp
# Created: Sun Mar  8 12:16:38 UTC 2020
import sys
 
stdin = sys.stdin
inf = 1 << 60
mod = 1000000007
 
ni = lambda: int(ns())
nin = lambda y: [ni() for _ in range(y)]
na = lambda: list(map(int, stdin.readline().split()))
nan = lambda y: [na() for _ in range(y)]
nf = lambda: float(ns())
nfn = lambda y: [nf() for _ in range(y)]
nfa = lambda: list(map(float, stdin.readline().split()))
nfan = lambda y: [nfa() for _ in range(y)]
ns = lambda: stdin.readline().rstrip()
nsn = lambda y: [ns() for _ in range(y)]
ncl = lambda y: [list(ns()) for _ in range(y)]
nas = lambda: stdin.readline().split()

s = ns()
n = len(s)
if n % 2 == 1:
    print("No")
else:
    i = 0
    cnt = 0
    while i < n - 1:
        if s[i] == 'h' and s[i + 1] == 'i':
            cnt += 2
        i += 2
    if cnt == n:
        print("Yes")
    else:
        print("No")

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

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"
#define PI 3.14159265358979
#define MOD 1000000007 // = 10^9 + 7

using namespace std;
using ll = long long;


void solve()
{
	ll n, a, b;
	cin >> n >> a >> b;

	ll loop_cnt = n / (a + b);
	ll cnt = n % (a + b);

	cout << loop_cnt * a + min(cnt, a);
}

int main()
{
	fastio;
	solve();

	return 0;
}

Measured memory_bytes: 256
#import<cstdio>
#import<cmath>
int main(){int q;float x;for(;scanf("%d",&q),~q;printf("%f\n",x))for(x=q/2.;fabs(x*x*x-q)>1e-5*q;x-=(x*x*x-q)/(3*x*x));}

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

int main() {
    string S,T;
    cin >> S >> T;
    int count = 0;
    if(S.at(0) == T.at(0)){
        count++;
    }
    if(S.at(1) == T.at(1)){
        count++;
    }
    if(S.at(2) == T.at(2)){
        count++;
    }
    cout << count;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <functional>
#include <vector>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cassert>
#define InfL 2000000000
#define InfLL 4000000000000000000LL
#define mod 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
using namespace std;
typedef long long ll;
typedef double db;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<bool> vb;
typedef vector<db> vd;

int main() {
	int N;
	cin >> N;
	vl L(N);
	rep(i, N)
		cin >> L[i];

	ll ans = 0;
	rep(i, N) {
		rep(j, N) {
			if (i >= j)
				continue;
			rep(k, N) {
				if (j >= k)
					continue;
				if (L[i] == L[j])
					continue;
				if (L[j] == L[k])
					continue;
				if (L[k] == L[i])
					continue;
				if (L[i] + L[j] <= L[k])
					continue;
				if (L[k] + L[j] <= L[i])
					continue;
				if (L[i] + L[k] <= L[j])
					continue;
				ans++;
			}
		}
	}

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

Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int N=114514;
int fa[N],u[N],v[N],t[N];
int n,q;
ll num,cnt,m;
int find(int x){
	return fa[x]==x?x:fa[x]=find(fa[x]);
}
void merge(int x,int y){
	if(x!=y) num--,fa[x]=y,cnt++;
} 
int main(){
	scanf("%d%d%d",&n,&m,&q);num=n;
	for(int i=1;i<=n;i++)fa[i]=i;
	for(int i=1;i<=q;i++){
		scanf("%d%d%d",&u[i],&v[i],&t[i]);u[i]++,v[i]++;
		if(!t[i]) merge(find(u[i]),find(v[i])),q--,i--;
	}
	if(m<=n-1){
		if(m<n-1)puts("No");
		else if(!q) puts("Yes");
		else puts("No");
		return 0;
	}for(int i=1;i<=q;i++){
		if(find(u[i])==find(v[i])){
			puts("No");return 0;
		}
	}ll r=1ll*cnt+((num*(num-1))/2);
	if(m>=n&&m<=r)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 5216
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main() {
    int n, l;
    cin >> n >> l;
    vector<string> s(n);
    for (int i = 0; i < n; ++i) cin >> s.at(i);
    sort(s.begin(), s.end());
    for (int i = 0; i < n; ++i) cout << s.at(i);
    cout << endl;
    return 0;
}


Measured memory_bytes: 256
import fractions
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)

a,b,c,d = map(int,input().split())
count = 0
i = b//c - a//c 
if(a%c == 0):
  i += 1
j = b//d - a//d
if(a%d == 0):
  j += 1
k = b//lcm(c,d) - a//lcm(c,d)
if(a%lcm(c,d) == 0):
  k += 1

print(b-a+1-(i+j-k))

Measured memory_bytes: 5428
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
typedef long long ll;
typedef pair<int, int> P;
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main() {
  double N, K;
  cin >> N >> K;
  vector<ll> A(N);
  ll zero = 0;

  REP(i, N) {
    cin >> A[i], A[i]--;
    if (A[i] == 0) zero = i;
  }/*
  //double a = N / K;
  ll ans = 0;
  if (zero < K || N - K <= zero) {
    ans += 1;
    //cout << "once" << ceil(a) << endl;
  } else {
    ans += 2;
    //cout << ceil(a) + 1 << endl;
  }
  N -= K;
  while(N>0){
    ans++;
    N -= (K - 1);
  }*/
  cout << ceil((N-1)/(K-1)) << endl;
  return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String[] vals = sc.nextLine().split(" ");
        long N = getLong(vals[0]);
        long X = getLong(vals[1]);
        String[] city = sc.nextLine().split(" ");

        // 出発地との最小の差を取得する
        long minDiff = (long)Math.pow(10, 10);
        for(String val : city){
            long n = Long.parseLong(val);
            long diff = Math.abs(X - n);
            if(diff <= minDiff && diff != 0) minDiff = diff;
        }

        for(String val : city){
            long n = Long.parseLong(val);
            long diff = Math.abs(X - n);
            while(diff % minDiff != 0){
                minDiff = minDiff - 1;
            }
        }
        System.out.println(minDiff);
        sc.close();
    }
    static long getLong(String val) {return Long.parseLong(val);}
}

Measured memory_bytes: 45072
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<cstdlib>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_set>
#include<unordered_map>
#include<bitset>
using namespace std;
#define INF 2147483647
#define lINF 9223372036854775807
#define MODE 1
#ifdef MODE
#define DEB(X) cout<< #X <<": "<<X<<" ";
#define ARDEB(i,X) cout<< #X <<"["<<i<<"]: "<<X[i]<<" ";
#define END cout<<endl;
#else
#define DEB(X) {}
#define ARDEB(i,X) {}
#define END {}
#endif
typedef long long int ll;

ll n,a[111111],b[111111],c[111111],m[111111][4];
ll dp(int i,int ke){
	if(m[i][ke]!=-1)return m[i][ke];
	if(i==n)return 0;
	ll sum=0,sum2=0,sum3=0;
	if(ke!=1)sum=dp(i+1,1)+a[i];
	if(ke!=2)sum2=dp(i+1,2)+b[i];
	if(ke!=3)sum3=dp(i+1,3)+c[i];
	
	return m[i][ke]=max({sum,sum2,sum3});
	
}

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

}

Measured memory_bytes: 10752
#include <bits/stdc++.h>
#define PI 3.141592653589793238462
using namespace std;
typedef long long ll;
typedef double long db;
vector<int> a,b;
int main(){
    int n;cin>>n;
    string s;cin>>s;
    for(int i=0;i<s.length();i++){
        if(s[i]=='R') a.push_back(i);
        else b.push_back(i);
    }
    int p1=a.size()-1,p2=0,num=0;
    while(p1>=0&&p2<b.size()){
        if(b[p2]<a[p1]){
            num++;p1--;p2++;
        }
        else break;
    }
    cout<<num<<endl;
}

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

int main()
{
	int N, K;
	cin >> N;
	cin >> K;
	
	int ashiba[100010];
	for(int i = 0; i < N; i++){
		cin >> ashiba[i];
	}
	
	int l[100010];
	l[0] = 0;
	for (int i = 1; i < N; i++){
		l[i] = 1000000000;
	}
	
	int cost;
	for(int i = 0; i < N; i++){
		if (K > N - i - 1){
			K = N - i - 1;
		}
		for (int j = i + 1; j < i + K + 1; j++){
			cost = abs(ashiba[j] - ashiba[i]) + l[i];
			if(l[j] > cost){
				l[j] = cost;
			}
		}
	}
	
	cout << l[N - 1] << endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <iomanip>
#include <cassert>

#include <cstring>
#include <vector>
#include <algorithm>
#include <string>
#include <cmath>
#include <limits>
#include <queue>
#include <unordered_map>
using namespace std;

#define rep_init(i, init, n) for(int i = (init); i < (n); ++i)
#define rep(i, n) rep_init(i, 0, n)

using ll = long long;

void Main()
{
	ll A;
	string Bs, B1s, B2s;

	cin >> A >> Bs;
	int i = 0;
	for (; i < Bs.size(); ++i)
	{
		if (Bs[i] == '.') break;
		B1s.push_back(Bs[i]);
	}
	++i;
	for (; i < Bs.size(); ++i)
	{
		B2s.push_back(Bs[i]);
	}

	cout << A * static_cast<ll>(atoi(B1s.c_str())) + A * static_cast<ll>(atoi(B2s.c_str())) /100 << endl;
}

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

	Main();
	return 0;
}

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

int main(void) {
    int n, k, x, y;
    cin >> n >> k >> x >> y;
    if (n >= k) {
    cout << k * x + (n - k) * y << endl;
    } else {
        cout << n * x << endl;
    }
    return 0;
}


Measured memory_bytes: 3624
if __name__ == "__main__":
    ct = 0
    while True:
        nums = map( int, raw_input().split())
        H = nums[0]
        W = nums[1]
        if H == 0:
            if W == 0:
                break

        sf = ""
        sb = ""
        j = 0
        while j < W:
            if j == 0:
                sb += "#"
            elif j == W-1:
                sb += "#"
            else:
                sb += "."
            sf += "#"
            j += 1

        i = 0
        while i < H:
            if i == 0:
                print sf
            elif i == H-1:
                print sf
            else:
                print sb
            i += 1
        print

Measured memory_bytes: 4232
#include <iostream>

using namespace std;

int g;

void solve() {
	int A = g / 200, B = g / 300, C = g / 500;
	int ans = (int)1e9;
	
	for (int a = 0; a <= A; a++) {
		for (int b = 0; b <= B; b++) {
			if (200 * a + 300 * b > g) break;
			
			for (int c = 0; c <= C; c++) {
				if (200 * a + 300 * b + 500 * c > g) break;
				
				if (200 * a + 300 * b + 500 * c == g) {
					int unitA = a % 5, discA = a - unitA;
					int unitB = b % 4, discB = b - unitB;
					int unitC = c % 3, discC = c - unitC;
					
					int buyA = (380 * discA) * 80 / 100 + 380 * unitA;
					int buyB = (550 * discB) * 85 / 100 + 550 * unitB;
					int buyC = (850 * discC) * 88 / 100 + 850 * unitC;
					
					ans = min(ans, buyA + buyB + buyC);
				}
			}
		}
	}
	
	cout << ans << endl;
}

int main() {
	while (1) {
		cin >> g; if (g == 0) break;
		solve();
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
void swap(int & a, int & b){
	int t=a;
	a=b;
	b=t;
}
int n;
bool g(int * a){
	for(int i=0;i<n;i++){
		if(a[i] != i+1) return false;
	}
	return true;
}
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	cin>>n;
	ll a[n+1],b[n];
	for(int i=0;i<n+1;i++) cin>>a[i];
	for(int i=0;i<n;i++) cin>>b[i];
	ll ans=0;
	ll pre=0;
	for(int i=0;i<n;i++){
		if(pre >= a[i]){
			ans+=a[i];
			pre=b[i];
			continue;
		}
		if(pre+b[i] <= a[i]){
			ans+=pre+b[i];
			pre=0;
			continue;
		}
		ans+=a[i];
		pre=pre+b[i]-a[i];
	}
	ans+=min(pre,a[n]);
	cout<<ans;
}

Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <cstring>
#include <cstdio>

using namespace std;

const int N = 1e5 + 10;

char s[N];

int main() {

	scanf(" %s", s + 1);
	int n = strlen(s + 1);
	char l = 0;
	int m = 0;
	for (int i = 1; i <= n; ++i) {
		if (s[i] != l || i == 1) {
			l = s[i];
			++m;
		}
	}
	printf("%d\n", m - 1);

	return 0;
}


Measured memory_bytes: 384
#include<stdio.h>
#include<math.h>

int main(){
  int i,j,k,sx,sy,tx,ty;
  
  scanf("%d %d %d %d",&sx,&sy,&tx,&ty);
  int difx = abs(tx-sx);
  int dify = abs(ty-sy);
  
  for(i=0;i<dify;i++)
    printf("U");
  for(i=0;i<difx;i++)
    printf("R");
  for(i=0;i<dify;i++)
    printf("D");
  for(i=0;i<difx+1;i++)
    printf("L");
  difx+=1;
  dify+=1;
  for(i=0;i<dify;i++)
    printf("U");
  for(i=0;i<difx;i++)
    printf("R");
  printf("DR");
  for(i=0;i<dify;i++)
    printf("D");
  for(i=0;i<difx;i++)
    printf("L");
  printf("U");
  
  puts("");
  return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=2e5+20;
const ll mod=1e9+7;
ll n,m;
int main()
{
	while(cin>>n>>m)
	{
		if(n<m)
			swap(n,m);
		if(n>m+1)
		{
			puts("0");
			continue;
		}
		ll ans=1;
		ll a=n,b=m;
		for(int i=1;n&&m;i++)
		{
			if(i%2)
				ans=(ans*n)%mod,n--;
			else
				ans=(ans*m)%mod,m--;
		}
		if(a==b)
			ans=(ans*2ll)%mod;	
		cout<<ans<<endl;
	}
	return 0;
}
 

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

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);

    int n, a[200001];
    cin >> n;
    map<llong,llong> M;
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
        ++M[a[i]];
    }

    vector<llong> P2;
    llong k = 2;
    while (1) {
        P2.push_back(k);
        k *= 2;
        if (k > 2 * 1000000000) break;
    }

    sort(a, a + n, greater<int>());
    int ans = 0;
    for (int i = 0; i < n; ++i) {
        if (M.find(a[i]) == M.end()) continue;
        if (M[a[i]] == 1) M.erase(a[i]);
        else --M[a[i]];
        for (vector<llong>::reverse_iterator itr = P2.rbegin(); itr != P2.rend(); ++itr) {
            llong target_key = *itr - a[i];
            // cout << *itr << " " << a[i] << endl;
            if (target_key <= 0) break;
            if (M.find(target_key) != M.end()) {
                // cout << "find" << " " << a[i] << " " << target_key << " " << M[target_key] << endl;
                ++ans;
                if (M[target_key] == 1) M.erase(target_key);
                else --M[target_key];
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 13568
#include <iostream>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <string>
#include <map>
using namespace std;
int main() {
	long long int ans;
	int N,start;
	bool flag;
	string s1, s2;
	cin >> N >>  s1 >> s2;
	if (N == 1) {
		cout << 3;
		return 0;
	}
	if (s1[0] == s1[1]) {
		flag = true;
		ans = 6;
		start = 2;
	}
	else {
		flag = false;
		ans = 3;
		start = 1;
		flag = false;
	}

	for (int i = start; i < N;i++) {
		if (i == N-1 && flag) {
		}
		else if(i == N-1){
			ans *= 2;
			ans %= 1000000007;
		}
		else if (s1[i] == s1[i+1] && flag) {
			ans *= 3;
			ans %= 1000000007;
			i++;
		}
		else if(s1[i] == s1[i+1]){
			ans *= 2;
			ans %= 1000000007;
			i++;
			flag = true;
		}
		else if(flag){
			flag = false;
		}
		else {
			ans *= 2;
			ans %= 1000000007;
		}
	}
	cout << ans << endl;
	return 0;
}



Measured memory_bytes: 256
#ifndef Local
#pragma GCC optimize("Ofast,no-stack-protector")
#pragma GCC target("sse4,sse4.2,popcnt,abm,mmx,avx")
#endif
#include <bits/stdc++.h>

using namespace std;

#define popCnt(x) (__builtin_popcountll(x))
#define sz(x) ((int)(x.size()))
#define all(v) begin(v), end(v)
#define rall(v) rbegin(v), rend(v)
typedef long long Long;
typedef double Double;

template <class U, class V>
istream& operator>>(istream& is, pair<U, V>& p) {
  is >> p.first >> p.second;
  return is;
}
template <class T>
istream& operator>>(istream& is, vector<T>& v) {
  for (auto& x : v) {
    is >> x;
  }
  return is;
}

template <class T>
ostream& operator<<(ostream& os, vector<T>& v) {
  for (auto& x : v) {
    os << x << " ";
  }
  return os;
}

vector<int> a, b, res;

int n;
const int N = 2e5 + 5;
int cnt_a[N], cnt_b[N];

const int RANDOM =
    chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937 rng(RANDOM);

bool validate() {
  bool valid = true;
  for (int i = 0; i < n; ++i) {
    valid &= (a[i] != res[i]);
  }
  return valid;
}

bool solve() {
  res = b;
  for (int t = 0; t < 30; ++t) {
    rotate(begin(res), begin(res) + rng() % n, end(res));
    if (validate()) return true;
  }
  res = b;
  reverse(all(res));
  for (int t = 0; t < 30; ++t) {
    if (validate()) return true;
    shuffle(all(res), rng);
  }
  return false;
}

int main() {
  ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#ifdef Local
  freopen("test.in", "r", stdin);
#else
#define endl '\n'
#endif
  cin >> n;
  a.resize(n), b.resize(n), res.resize(n);
  cin >> a >> b;
  for (int x : b) ++cnt_b[x];
  for (int x : a) {
    ++cnt_a[x];
    if (cnt_b[x] + cnt_a[x] > n) {
      cout << "No" << endl;
      return 0;
    }
  }
  if (solve()) {
    cout << "Yes" << endl;
    cout << res << endl;
    return 0;
  }

  cout << "No" << endl;
  return 0;
}


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

using ll = long long;

int main() {
    int N, abssum = 0, amax = -10001, amin = 10001;
    cin >> N;
    vector<int> A(N);
    rep(i, N) {
        cin >> A[i];
        abssum += abs(A[i]);
        amax = max(amax, A[i]);
        amin = min(amin, A[i]);
    }
    cout << abssum - abs(amax) - abs(amin) + abs(amax - amin) << endl;
    sort(A.begin(), A.end());
    int i = 0, j = N - 1;
    while (i + 1 < j) {
        if (A[i + 1] > 0) {
            cout << A[i] << " " << A[j] << endl;
            A[i] -= A[j];
            j--;
        } else {
            cout << A[j] << " " << A[i] << endl;
            A[j] -= A[i];
            i++;
        }
    }
    cout << A[j] << " " << A[i] << endl;
}


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

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

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

    for (int i = 0; i < n;) {
        if (i == n - 1) {
            ans++;
            break;
        }
        if (a[i] < a[i + 1]) {
            while (a[i] <= a[i + 1]) {
                i++;
                if (i == n - 1) {
                    break;
                } 
            }
            ans++;
            i++;
        } else if (a[i] > a[i + 1]) {
            while (a[i] >= a[i + 1]) {
                i++;
                if (i == n - 1) {
                    break;
                } 
            }
            ans++;
            i++;
        } else {
            while (a[i] == a[i + 1]) {
                i++;
                if (i == n - 1) {
                    break;
                } 
            }
        }
    }
    
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstring>
#include<cstdio>
#include<time.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double EPS=1e-10;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
int main(){
	int a,b;
	while(cin>>a>>b,a||b){
		vector<int>in(b);
		rep(i,b)cin>>in[i];
		sort(all(in));
		bool h=false;
		if(in[0]==0){
			h=true;
			in.erase(in.begin());
		}
		vector<int>out;
		vector<bool>q;
		int co=1;
		loop(i,1,in.size()){
			if(in[i]-in[i-1]==1)
				co++;
			else{
				out.pb(co);
				if(in[i]-in[i-1]==2)
					q.pb(true);
				else q.pb(false);
				co=1;
			}
			if(i==in.size()-1){
				out.pb(co);
			}
		}
		int ma=-1;
		rep(i,out.size())ma=max(ma,out[i]);
		if(h){
			rep(i,q.size())if(q[i])ma=max(ma,out[i]+out[i+1]+1);
		}
		cout<<ma<<endl;
	}
}

Measured memory_bytes: 1532
#include <iostream>
#include <iomanip>
#include <vector>
#include <cmath>
#include <algorithm>
#include <climits>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <list>
#include <ctime>
#include <complex>
#include <bitset>
#include <tuple>
#include <functional>

using namespace std;

#define IOS ios::sync_with_stdio(false);cin.tie(0)
#define all(x) x.begin(), x.end()
#define ff first
#define ss second
#define MOD 1000000007LL
#define rep(i,a,n) for (int i=a ; i<n ; i++)
#define per(i,a,n) for (int i=n-1 ; i>=a ; i--)
#define LLINF 100000000000000005LL
#define INF (int)1e9+1
#define endl '\n'
#define pb push_back

// debug 도구

template <typename A, typename B>
string to_string(pair<A, B> p);

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p);

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p);

string to_string(const string& s) {
    return '"' + s + '"';
}

string to_string(const char* s) {
    return to_string((string)s);
}

string to_string(bool b) {
    return (b ? "true" : "false");
}

string to_string(vector<bool> v) {
    bool first = true;
    string res = "{";
    for (int i = 0; i < static_cast<int>(v.size()); i++) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(v[i]);
    }
    res += "}";
    return res;
}

template <size_t N>
string to_string(bitset<N> v) {
    string res = "";
    for (size_t i = 0; i < N; i++) {
        res += static_cast<char>('0' + v[i]);
    }
    return res;
}

template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto& x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}\n";
    return res;
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A, typename B, typename C>
string to_string(tuple<A, B, C> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ")";
}

template <typename A, typename B, typename C, typename D>
string to_string(tuple<A, B, C, D> p) {
    return "(" + to_string(get<0>(p)) + ", " + to_string(get<1>(p)) + ", " + to_string(get<2>(p)) + ", " + to_string(get<3>(p)) + ")";
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:\n", debug_out(__VA_ARGS__)

// debug 도구 end

using llong = long long;
using VI = vector<int>;
using VVI = vector<vector<int>>;
using VPII = vector<pair<int, int>>;
using VLL = vector<long long>;
using PII = pair<int, int>;


int main() {
    int a, b, c;
    cin >> a >> b >> c;
    if (a + b + c <=21) cout << "win";
    else cout << "bust";
    return 0;
}

Measured memory_bytes: 3580
fun main(args: Array<String>) {
    val (H, W, N) = readInputLine().split(" ").map { it.toInt() }
    val (sy, sx) = readInputLine().split(" ").map { it.toInt() }
    val S = readInputLine().toCharArray()
    val T = readInputLine().toCharArray()

    // 右に出そうとする
    var xTmp = sx
    for (i in 0 until N) {
        if (S[i] == 'R') {
            xTmp++
            if (xTmp > W) {
                println("NO")
                return
            }
        }
        if (T[i] == 'L') {
            xTmp--
            if (xTmp == 0) {
                xTmp = 1
            }
        }
    }

    // 左に出そうとする
    xTmp = sx
    for (i in 0 until N) {
        if (S[i] == 'L') {
            xTmp--
            if (xTmp == 0) {
                println("NO")
                return
            }
        }
        if (T[i] == 'R') {
            xTmp++
            if (xTmp > W) {
                xTmp = W
            }
        }
    }

    // 上に出そうとする
    var yTmp = sy
    for (i in 0 until N) {
        if (S[i] == 'U') {
            yTmp--
            if (yTmp == 0) {
                println("NO")
                return
            }
        }
        if (T[i] == 'D') {
            yTmp++
            if (yTmp > H) {
                yTmp = H
            }
        }
    }

    // 下に出そうとする
    yTmp = sy
    for (i in 0 until N) {
        if (S[i] == 'D') {
            yTmp++
            if (yTmp > H) {
                println("NO")
                return
            }
        }
        if (T[i] == 'U') {
            yTmp--
            if (yTmp == 0) {
                yTmp = 1
            }
        }
    }

    println("YES")
}

fun readInputLine(): String {
    return readLine()!!
}


Measured memory_bytes: 41436
#include <bits/stdc++.h>
#include<vector>
using namespace std;
#define rep(i, n)        for(int i=0; i<(int)(n); ++i)
int sub(int i,int j){
  int b=1;
  if(j==3)return 0;
  for(int a=1;a<=i;a++){
    b*2;
  }
  return 1/b+(i+1)*sub(i+1,j+1);
}
int main() {
  int a,b;
  int c,d=1;
  cin>>a>>b;
  c=a-b;
  cout<<b*2-a;
}

Measured memory_bytes: 256
S = input()

i = 1
flag = True
for s in S:
    if i % 2 == 1 and (s == 'R' or s == 'U' or s == 'D'):
        i += 1
        continue
    elif i % 2 == 0 and (s == 'L' or s == 'U' or s == 'D'):
        i+= 1
    else:
        flag = False
        break
if flag:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
#include<iostream>
#include<cmath>

using namespace std;

typedef long long ll;

ll power(ll b, ll p){//bのp乗
  if( p == 0){ return 1;}
  return b * power(b, p - 1);}

int main(){ ll max_int = 1;
  int N; cin >> N; int c = (int)sqrt((double) N);
  for(ll p = 2; p <= 9; p++){
    for(ll b = 1; b <= (ll)c; b++){
      if( power(b,p) <= N){ max_int = max(max_int,power(b,p));}}}
           
           cout << max_int << endl;
           
           return 0;
          }
  

Measured memory_bytes: 256
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

n = int(readline())
ab = list(map(int,read().split()))
a = ab[::2]
b = ab[1::2]
a.sort()
b.sort()

if(n%2==1):
    n_min = a[n//2]
    n_max = b[n//2]
    ans = n_max-n_min+1
else:
    n_min = a[n//2 -1] + a[n//2]
    n_max = b[n//2 -1] + b[n//2]
    ans = n_max-n_min+1

print(ans)

Measured memory_bytes: 112512
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <utility>
#include <cstdio>
#include <iomanip>
#include <cmath>
#include <string>
#include <stack>
#include <queue>
#include <map>
#include <stdlib.h>
#include <set>
typedef long long ll;
using namespace std;

int main() {
	int a,b;
	cin>>a>>b;
	cout<<6-a-b<<endl;

	return 0;
}



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

if n==1:print(0);exit()


#12だったら[[2,2],[3,1]]みたいな、[素因数、次数]みたいに格納したい

import sys
import math
mod=10**9+7
inf=float("inf")
from math import sqrt
from collections import deque
input=lambda: sys.stdin.readline().strip()
sys.setrecursionlimit(11451419)
from functools import lru_cache
#メモ化再帰defの冒頭に毎回 @lru_cache(maxsize=10**10)
#引数にlistはだめ
#######ここまでテンプレ#######
#######ここから天ぷら########
from math import sqrt
def eratosu(n):
  if not isinstance(n,int):
    raise TypeError("nがint型になってねえぞ")
  if n<2:
    raise ValueError('nが2よりちっちぇえぞ')
  prime = []
  limit = sqrt(n)
  data = [i+1 for i in range(1, n)]  #2,3,4,...,n
  while True:
    p = data[0]
    if limit <= p:
        return prime + data
    prime.append(p)
    data = [e  for e in data if e % p != 0]
def bunkai(n):
    if n==2:
        return [[2,1]]
    if n==3:
        return [[3,1]]
    ans=[]
    temp=n
    #そんな早くしなくてよかったり、何回もするわけじゃないなら、
    #for i in range(2,int(sqrt(n))+1): とかで
    primelist=eratosu( int(sqrt(n)) )
    for i in primelist:
        if temp % i ==0:
            ji=0
            while temp%i==0:
                ji+=1
                temp//=i
            ans.append([i,ji])
    if ans==[]:return([[n,1]])  #素数のとき
    if temp!=1:
        ans.append([temp,1])  #4*5882353とか
    return ans

a=bunkai(n)

ans=0
import bisect as bi
p=[1,3,6,10,15,21,28,36,45,55]
for l in a:
  q=l[1]
  ans+=bi.bisect_right(p,q)
print(ans)
  


Measured memory_bytes: 52572
mod=10**9+7
n,m=map(int,input().split())
arr1=list(map(int,input().split()))
arr2=list(map(int,input().split()))
edge1=[]
for i in range(n-1):
  edge1.append(arr1[i+1]-arr1[i])
edge2=[]
for i in range(m-1):
  edge2.append(arr2[i+1]-arr2[i])
c1=[0]*(m-1)
tmp=0
if (m-1)%2==0:
  for i in range((m-1)//2):
    tmp+=(m-1)-2*i
    c1[i]=tmp
    c1[-(i+1)]=tmp
else:
  for i in range((m-1)//2+1):
    tmp+=(m-1)-2*i
    if i==(m-1)//2:
      c1[i]=tmp
    else:
      c1[i]=tmp
      c1[-(i+1)]=tmp
area=0
if (m-1)%2==0:
  for i in range((m-1)//2):
    area+=edge2[i]*c1[i]
    area+=edge2[-(i+1)]*c1[i]
else:
  for i in range((m-1)//2+1):
    if i==(m-1)//2:
      area+=edge2[i]*c1[i]
    else:
      area+=edge2[i]*c1[i]
      area+=edge2[-(i+1)]*c1[i]
c2=[0]*(n-1)
tmp=0
if (n-1)%2==0:
  for i in range((n-1)//2):
    tmp+=(n-1)-2*i
    c2[i]=tmp
    c2[-(i+1)]=tmp
else:
  for i in range((n-1)//2+1):
    tmp+=(n-1)-2*i
    if i==(n-1)//2:
      c2[i]=tmp
    else:
      c2[i]=tmp
      c2[-(i+1)]=tmp
ans=0
if (n-1)%2==0:
  for i in range((n-1)//2):
    ans+=area*edge1[i]*c2[i]
    ans+=area*edge1[-(i+1)]*c2[i]
    ans%=mod
else:
  for i in range((n-1)//2+1):
    if i==(n-1)//2:
      ans+=area*edge1[i]*c2[i]
    else:
      ans+=area*edge1[i]*c2[i]
      ans+=area*edge1[-(i+1)]*c2[i]
print(ans%mod)

Measured memory_bytes: 24372