akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
using namespace std;

int main() {
  string s,t;cin>>s>>t;
  bool exist=false;
  for(int i=s.size()-1;i>=t.size()-1;--i){
    for(int j=0;j<t.size();++j){
      if(s[i-j]!='?' && s[i-j]!=t[t.size()-j-1]) break;
      if(j==t.size()-1){
        exist=true;
        for(int k=0;k<t.size();++k) s[i-k]=t[t.size()-k-1];
      }
    if(exist) break;
    }
  if(exist) break;
  }
  
  if(exist){
    for(int i=0;i<s.size();++i){
      if(s[i]=='?') cout<<"a";
      else cout<<s[i];
    }
    cout<<endl;
  }
  else cout<<"UNRESTORABLE"<<endl;
}

Measured memory_bytes: 256
s=input()
cnt_a=s.count('a')
cnt_b=s.count('b')
cnt_c=s.count('c')
ac=abs(cnt_a-cnt_c)
ab=abs(cnt_a-cnt_b)
bc=abs(cnt_b-cnt_c)
if ab<=1 and ac<=1 and bc<=1:
    print('YES')
else:
    print('NO')


Measured memory_bytes: 3316
import re

s = input()
p1 = '^keyence$'
p2 = '.*'

for i in range(1, 9):
    p = '{0}{1}{2}'.format(p1[:i], p2, p1[i:])
    if re.match(p, s):
        print('YES')
        break
else:
    print('NO')


Measured memory_bytes: 3188
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = 1'000'000'007;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	string s; cin >> s; s += "T";
	int x, y; cin >> x >> y;

	int t = 0;
	int d = 0;
	bool first = true;
	vector<vector<int>> v(2);
	rep(i, 0, s.size()) {
		if (s[i] == 'T') {
			if (t) {
				if (first)
					x -= t;
				else
					v[d].push_back(t);
				t = 0;
			}
			d ^= 1;
			first = false;
		}
		else
			t++;
	}
	vector<set<int>> st(2);

	rep(i, 0, 2) {
		st[i].insert(0);
		for (auto x : v[i]) {
			set<int> nst;
			for (auto y : st[i]) {
				nst.insert(y + x);
				nst.insert(y - x);
			}
			st[i] = nst;
		}
	}
	if (st[0].count(x) && st[1].count(y)) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

Measured memory_bytes: 768
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define rep(i,m,n) for(int (i)=(m);(i)<(n);++(i))
#define rREP(i,m,n) for(int (i)=(n)-1;(i)>=(m);--(i))
#define all(x) (x).begin(),(x).end()
#define out(y,x,h,w) (y)<0||(x)<0||(y)>=(h)||(x)>=(w)
constexpr int INF = 1000000001;
constexpr ll mod = 1000000007;
constexpr double PI = 3.1415926535897932;
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;
}
inline void init() {
	cin.tie(nullptr); cout.tie(nullptr);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(15);
}

ll gcd(ll x, ll y) { return (y ? gcd(y, x % y) : x); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main() {
	init();

	ll A, B, C, D; cin >> A >> B >> C >> D;
	ll ans = B - A + 1;
	ans -= (B / C - (A - 1) / C);
	ans -= (B / D - (A - 1) / D);
	ans += (B / lcm(C, D) - (A - 1) / lcm(C, D));
	cout << ans << "\n";

	return 0;
}

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

const int N_MAX = 100;

int n, l;
string str[N_MAX + 2];

int main()
{
    cin >> n >> l;
    for(int i = 1; i <= n; i++)
        cin >> str[i];

    sort(str + 1, str + n + 1);

    for(int i = 1; i <= n; i++)
        cout << str[i];

    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
    int a ,b ;
    scanf("%d", &a);
    scanf("%d", &b);
    if(a >= 1 && b <= 10000){
    if((a*b) % 2 == 0 ){
        printf("Even");
    }
    else{
        printf("Odd");
    }
    }
    else{
    printf("1 isn't less then a and b is not less then 10000 is not true");
    }
}


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

using namespace std;

int a[100005],amap[100005];

int main(){
    int n;
    scanf("%d",&n);
    for(int i = 0; i<n; i++){
        scanf("%d",&a[i]);
        amap[a[i]]++;
    }
    long long MOD = 1000000007ll;
    long long ans = 1;
    for(int i = n-1; i>=0; i-=2){
        if(i&&amap[i]==2){
            ans*=2;
            ans%=MOD;
        }else if((!i)&&amap[i]==1){

        }else
            ans = 0;
    }
    printf("%lld\n",ans);
    return 0;
}

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

using namespace std;
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

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

void solve() {
    int N;
    cin >> N;
    set<string> S;
    for(int i = 0; i < N; i++) {
        string s, t;
        cin >> s >> t;
        if (s == "insert") {
            S.insert(t);
        } else {
            if (S.find(t) == S.end()) {
                cout << "no" << endl;
            } else {
                cout << "yes" << endl;
            }
        }
    }
}

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


Measured memory_bytes: 29000
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextString() string {
	if !sc.Scan() {
		panic("failed scan string")
	}
	return sc.Text()
}

func nextInt() int {
	if !sc.Scan() {
		panic("failed scan int")
	}
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

type item struct {
	i   int
	sum int
}

type items []item

func (it *items) Len() int {
	return len(*it)
}

// Less reports whether the element with
// index i should sort before the element with index j.
func (it *items) Less(i, j int) bool {
	return (*it)[i].sum > (*it)[j].sum
}

// Swap swaps the elements with indexes i and j.
func (it *items) Swap(i, j int) {
	(*it)[i], (*it)[j] = (*it)[j], (*it)[i]
}

func main() {
	sc.Split(bufio.ScanWords)

	n := nextInt()

	buf := make([]item, n)
	a := make([]int, n)
	b := make([]int, n)

	for i := 0; i < n; i++ {
		a[i] = nextInt()
		b[i] = nextInt()
		buf[i].sum = a[i] + b[i]
		buf[i].i = i
	}

	is := items(buf)
	sort.Sort(&is)

	var sum int
	for i := 0; i < n; i++ {
		if i%2 == 0 {
			sum += a[buf[i].i]
		} else {
			sum -= b[buf[i].i]
		}
	}
	fmt.Println(sum)
}


Measured memory_bytes: 6400
import java.util.*;

class Main {

    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long A = sc.nextInt();
        long B = sc.nextInt();
        //ここまで入力

        long ans = lcm(A,B);

        System.out.println(ans);
    }
        //AとBの最小公倍数を求める
    static long lcm (long a, long b) {
        long temp;
        long c = a;
        c *= b;
        while((temp = a%b)!=0) {
            a = b;
            b = temp;
        }
        return (long)(c/b);
    }
}

Measured memory_bytes: 23252
N, K = map(int, input().split())
A = [int(x) for x in input().split()]

when = [-1 for _ in range(N+1)]
new = 1
i = 0

while when[new] == -1:
    when[new] = i
    new = A[new - 1]
    i += 1

line = when[new]
roop = i - when[new]

if K > line:
    K = (K - line) % roop
    for j in range(N+1):
        when[j] -= line
    
for j in range(N+1):
    if when[j] == K:
        print(j)
        break

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

int main() {
  int A,B,C,D,E;
  cin>>A>>B>>C>>D>>E;
  vector<int>a={10-A%10,10-B%10,10-C%10,10-D%10,10-E%10};
  for(int i=0;i<5;i++){
    if(a.at(i)==10){
      a.at(i)=0;
    }
  }
  int b=0;
  sort(a.begin(),a.end());
  for(int i=0;i<4;i++){
    b=b+a.at(i);
  }
  cout<<A+B+C+D+E+b<< endl;
}
    



Measured memory_bytes: 256
import java.util.*;
 
class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int x = sc.nextInt();
    int y = sc.nextInt();
    
    if ( x*2 <= y && x*4 >= y ) {
      if ( y % 2 == 0 ) {
        System.out.println("Yes");
        return;
      }
    } 
    
    System.out.println("No");
  }
}

Measured memory_bytes: 35412
# include <iostream>
# include <string>
# include <numeric>

int main()
{
    std::string s;
    std::cin >> s;
    int digit = stoi(s);
    int total = (std::accumulate(s.cbegin(), s.cend(), 0)) - s.size() * 48;    // 第三引数は加算の初期値, charから数値への補正
    std::cout << ((digit % total == 0) ? "Yes" : "No") << std::endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#define N 100

int main(){
  int i,j,n,minj,cnt=0,tmp,A[N];

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);

  for(i=0;i<n;i++){
    minj=i;
    for(j=i;j<n;j++)
      if(A[j]<A[minj])
	minj=j;
    if(i!=minj){
      tmp=A[i];
      A[i]=A[minj];
      A[minj]=tmp;
      cnt++;
    }
  }

  printf("%d",A[0]);
  for(i=1;i<n;i++)
    printf(" %d",A[i]);
  printf("\n%d\n",cnt);

  return 0;
}

Measured memory_bytes: 600
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<cstdio>
#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;
const int inf=1e9;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
int main(){
	#define MAX 1000010
	bool sosu[MAX]={0};
	for(int i=4;i<MAX;i+=2)sosu[i]=1;
	for(int i=3;i*i<=MAX;i+=2)if(!sosu[i])
	for(int j=i*3;j<MAX;j+=i*2)sosu[j]=1;
	
	int a,b;
	while(cin>>a>>b,a+b){
		int A=0,B=0;
		bool ha=true;
		for(int i=a;i>1;i--)if(sosu[i]==0&&a%i==0){
			if(ha){
				A+=i;
				ha=false;
			}else A-=i;
		}
		ha=true;
		for(int i=b;i>1;i--)if(sosu[i]==0&&b%i==0){
			if(ha){
				B+=i;
				ha=false;
			}else B-=i;
		}
		if(A>B)cout<<'a'<<endl;
		else cout<<'b'<<endl;		
	}
}

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

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

  int N, K; cin >> N >> K;
  long long ans = 0;
  for (int b = K+1; b <= N; b++) {
    ans += N / b * (b - K) + max(0, N % b - K + (K ? 1 : 0));
  }
  cout << ans << "\n";
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define M 200007
using namespace std;
int n,a[M],mx[M],Mx[M];
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	for(int i=1;i<=n;i++)mx[i]=max(mx[i-1],a[i]);
	for(int i=n;i>=1;i--)Mx[i]=max(Mx[i+1],a[i]);
	for(int i=1;i<=n;i++)
		printf("%d\n",max(mx[i-1],Mx[i+1]));
	return 0;
}

Measured memory_bytes: 3968
#include <iostream>
#include <cstdio>
char mapp[105][105];
int main(){
    int n,w;
    scanf("%d%d",&n,&w);
    for(int i = 1; i <= n; ++ i){
        scanf("%s", mapp[i] + 1);
    }
    for(int i = 1; i <= 2 * n; ++ i){
        for(int j = 1; j <= w; ++ j){
            putchar(mapp[(i + 1) / 2][j]);
        }
        putchar('\n');
    }
}

Measured memory_bytes: 256
import sys

N = int(input())
C = [int(sys.stdin.readline()) for _ in range(N)]
MOD = 10**9 + 7
A = []
for c in C:
    if A and A[-1] == c:
        continue
    A.append(c)
NA = len(A)
last = [-1] * 200001
B = [-1] * 200001
for i, a in enumerate(A):
    B[i] = last[a]
    last[a] = i

dp = [0] * NA
dp[0] = 1
for i in range(1, NA):
    prev = 0 if B[i] < 0 else dp[B[i]]
    dp[i] = (dp[i - 1] + prev) % MOD
print(dp[-1])

Measured memory_bytes: 29876
#![allow(dead_code)]
fn solve(src: &str) -> String {
    let mut sc = Scanner::from_str(src);

    let n: usize = sc.read();
    let d: Vec<usize> = sc.vec(n);

    let sum: usize = d.iter().sum();
    let ans: usize = d.iter().map(|x| x*(sum-x)).sum();

    format!("{}\n", ans/2)
}
#[test]
fn test_solve() {
   assert_eq!(solve("3\n3 1 2\n"), "11\n");
   assert_eq!(solve("7\n5 0 7 8 3 3 2\n"), "312\n");
}
fn main() {
    let mut buf = String::new();
    use std::io::Read;
    std::io::stdin().read_to_string(&mut buf).unwrap();
    use std::io::Write;
    std::io::stdout().write_all(solve(&buf).as_bytes()).unwrap();
}
struct Scanner<I> {
    src: I,
}
impl<'a> Scanner<std::str::SplitWhitespace<'a>> {
    fn from_str(src: &'a str) -> Self {
        Scanner {
            src: src.split_whitespace(),
        }
    }
}
impl<'a, I> Scanner<I>
where
    I: std::iter::Iterator<Item = &'a str>,
{
    fn read<T: std::str::FromStr>(&mut self) -> T {
        self.src.next().unwrap().parse().ok().expect("Parse error")
    }
    fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    fn chars(&mut self) -> Vec<char> {
        self.src.next().unwrap().chars().collect()
    }
}

Measured memory_bytes: 4352
#include<iostream>

using namespace std;

int main () {
    int a, b, c, t;
    cin >> a >> b >> c;
    if (a > b) {
        t = a;
        a = b;
        b = t;
    }
    if (b > c) {
        t = b;
        b = c;
        c = t;
    }
    if (a > b) {
        t = a;
        a = b;
        b = t;
    }
    cout << a << " " << b << " " << c << endl;
    return 0;
}

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

int main()
{
  int n, m;
  cin >> n >> m;
  vector<int> a(n, -1);
  int ans = 0;
  for (int i = 0; i < m; i++) {
    int s, c;
    cin >> s >> c;
    s--;
    if (a[s] < 0 || a[s] == c) {
      a[s] = c;
    } else goto noans;
  }
  if (n > 1 && a[0] == 0) goto noans;
  ans = a[0] >= 0 ? a[0] : n > 1 ? 1 : 0;
  for (int i = 1; i < n; i++) {
    ans = ans * 10 + max(a[i], 0);
  }
  cout << ans << endl;
  return 0;
 noans:
  cout << -1 << endl;
}


Measured memory_bytes: 256
//
// Created by TakahiroYamaji on 2020/08/04.
//
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
int N;
string S;

int main(){
    cin >> N;
    cin >> S;
    int a = 0, b = 0;
    for (int i=0;i<N;i++){
        if (S[i] == 'R') a++;
    }
    int res = max(a, b);
    for (int i=0;i<N;i++){
        //cout << i << endl;
        if (S[i] == 'R'){
            a--;
        }else{
            b++;
        }
        res = min(res, max(a, b));
    }
    //cout << a << " " << b << endl;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 3480
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
	    int n = scan.nextInt();
	    int m = scan.nextInt();
	    int x = scan.nextInt();
	    int a[]=new int[m];
	    for(int i=0;i<m;i++) {
	    	a[i]=scan.nextInt();
	    }
	    scan.close();
	    int check=0;
	    int cnt[]= {0,0};
		for(int j=0;j<m;j++) {
			if(a[j]>x)check=1;
			cnt[check]+=1;
		}
	    System.out.println(Math.min(cnt[0], cnt[1]));
	}

}

Measured memory_bytes: 21204
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

ll gcd(ll x, ll y) {
    if(y == 0) {
        return x;
    }
    return gcd(y, x%y);
}

ll GCD(vl &v) {  // vの全要素のgcd
    ll res = v[0];
    rep(i, v.size()) {
        res = gcd(res, v[i]);
    }
    return res;
}
 
int main() {
    ll n;
    cin >> n;

    vl x(n+1);
    rep(i, n+1) {
        cin >> x[i];
    }
    sort(all(x));

    vl y(n);
    rep(i, n) {
        y[i] = x[i+1] - x[i];
    }
    
    out(GCD(y));
    re0;
}

Measured memory_bytes: 1792
#include<iostream>
using namespace std;
int main()
{
	int n;
	cin>>n;
	char arr[100000];
	char brr[100000];
	for(int i=0;i<n;i++)
	{
		cin>>arr[i];
	}
	brr[1]='S';
	brr[0]='W';
	for(int i=1;i<n-1;i++)
	{
		if(brr[i]=='S'&&arr[i]=='o'||brr[i]=='W'&&arr[i]=='x')
		{
			brr[i+1]=brr[i-1];
		}
		else
		{
			if(brr[i-1]=='S')
			{
				brr[i+1]='W';
			}
			else
			{
				brr[i+1]='S';
			}
		}
	}
	char t;
	if(brr[n-1]=='S'&&arr[n-1]=='o'||brr[n-1]=='W'&&arr[n-1]=='x')
	{
		t=brr[n-2];
	}
	else
	{
		if(brr[n-2]=='S')
		{
			t='W';
		}
		else
		{
			t='S';
		}
	}
	if(t==brr[0])
	{
		if(brr[0]=='S'&&arr[0]=='o'||brr[0]=='W'&&arr[0]=='x')
		{
			if(brr[1]==brr[n-1])
			{
				for(int i=0;i<n;i++)
				{
					cout<<brr[i];
				}
				return 0;
			}
		}
		else
		{
			if(brr[1]!=brr[n-1])
			{
				for(int i=0;i<n;i++)
				{
					cout<<brr[i];
				}
				return 0;
			}
		}
	}
	brr[1]='S';
	brr[0]='S';
	for(int i=1;i<n-1;i++)
	{
		if(brr[i]=='S'&&arr[i]=='o'||brr[i]=='W'&&arr[i]=='x')
		{
			brr[i+1]=brr[i-1];
		}
		else
		{
			if(brr[i-1]=='S')
			{
				brr[i+1]='W';
			}
			else
			{
				brr[i+1]='S';
			}
		}
	}
	if(brr[n-1]=='S'&&arr[n-1]=='o'||brr[n-1]=='W'&&arr[n-1]=='x')
	{
		t=brr[n-2];
	}
	else
	{
		if(brr[n-2]=='S')
		{
			t='W';
		}
		else
		{
			t='S';
		}
	}
	if(t==brr[0])
	{
		if(brr[0]=='S'&&arr[0]=='o'||brr[0]=='W'&&arr[0]=='x')
		{
			if(brr[1]==brr[n-1])
			{
				for(int i=0;i<n;i++)
				{
					cout<<brr[i];
				}
				return 0;
			}
		}
		else
		{
			if(brr[1]!=brr[n-1])
			{
				for(int i=0;i<n;i++)
				{
					cout<<brr[i];
				}
				return 0;
			}
		}
	}
	brr[1]='W';
	brr[0]='W';
	for(int i=1;i<n-1;i++)
	{
		if(brr[i]=='S'&&arr[i]=='o'||brr[i]=='W'&&arr[i]=='x')
		{
			brr[i+1]=brr[i-1];
		}
		else
		{
			if(brr[i-1]=='S')
			{
				brr[i+1]='W';
			}
			else
			{
				brr[i+1]='S';
			}
		}
	}
	if(brr[n-1]=='S'&&arr[n-1]=='o'||brr[n-1]=='W'&&arr[n-1]=='x')
	{
		t=brr[n-2];
	}
	else
	{
		if(brr[n-2]=='S')
		{
			t='W';
		}
		else
		{
			t='S';
		}
	}
	if(t==brr[0])
	{
		if(brr[0]=='S'&&arr[0]=='o'||brr[0]=='W'&&arr[0]=='x')
		{
			if(brr[1]==brr[n-1])
			{
				for(int i=0;i<n;i++)
				{
					cout<<brr[i];
				}
				return 0;
			}
		}
		else
		{
			if(brr[1]!=brr[n-1])
			{
				for(int i=0;i<n;i++)
				{
					cout<<brr[i];
				}
				return 0;
			}
		}
	}
	brr[1]='W';
	brr[0]='S';
	for(int i=1;i<n-1;i++)
	{
		if(brr[i]=='S'&&arr[i]=='o'||brr[i]=='W'&&arr[i]=='x')
		{
			brr[i+1]=brr[i-1];
		}
		else
		{
			if(brr[i-1]=='S')
			{
				brr[i+1]='W';
			}
			else
			{
				brr[i+1]='S';
			}
		}
	}
	
	if(brr[n-1]=='S'&&arr[n-1]=='o'||brr[n-1]=='W'&&arr[n-1]=='x')
	{
		t=brr[n-2];
	}
	else
	{
		if(brr[n-2]=='S')
		{
			t='W';
		}
		else
		{
			t='S';
		}
	}
	if(t==brr[0])
	{
		if(brr[0]=='S'&&arr[0]=='o'||brr[0]=='W'&&arr[0]=='x')
		{
			if(brr[1]==brr[n-1])
			{
				for(int i=0;i<n;i++)
				{
					cout<<brr[i];
				}
				return 0;
			}
		}
		else
		{
			if(brr[1]!=brr[n-1])
			{
				for(int i=0;i<n;i++)
				{
					cout<<brr[i];
				}
				return 0;
			}
		}
	}
	cout<<-1;
}

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

public class Main {

	public static void main(String[] a){

		String str;
		BufferedReader bf = new BufferedReader(new InputStreamReader(System.in));

		try {
			while(null != ( str = bf.readLine() )){
				long n = Long.parseLong(str);
				long ans = 100;
				while(n-- > 0){
					ans = (long) Math.ceil(ans * 1.05);
				}
				System.out.println(ans * 1000);
			}
		} catch (IOException e) {
			e.printStackTrace();
		} finally {
			try {
				bf.close();
			} catch (IOException e) {
			}
		}
	}

}

Measured memory_bytes: 8932
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <limits>
#include <queue>
#include <iomanip>

using namespace std;
using ll = long long int;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<vvll> vvvll;
const int MOD=1000000007;
//const int MOD=998244353;
const int INTMAX=1001001000;
const ll LLMAX=1010010010010010000;

ll GCD(ll a, ll b) {
  if(a < b) return GCD(b, a);
  ll r;
  while ((r=a%b)) {
    a = b;
    b = r;
  }
  return b;
}

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    ll K;
    cin>>K;
    
    ll ans=0;
    for(int a=1;a<=K;a++){
        for(int b=1;b<=K;b++){
            for(int c=1;c<=K;c++){
                ans+=GCD(a, GCD(b,c));
            }
        }
    }
    cout<<ans<<endl;
    
    return 0;
}


Measured memory_bytes: 3692
# -*- coding: utf-8 -*-
from itertools import permutations

n = int(input())
p = "".join(input().split())
q = "".join(input().split())

l = []
for s in permutations(range(1,n+1)):
    l.append("".join(map(str,s)))

l = sorted(l)

a = 0
b = 0
for i in range(len(l)):
    if l[i]==p:
        a = i+1
    if l[i]==q:
        b = i+1

print(abs(a-b))

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

int main(){
  int H,W;
  cin>>H>>W;
  char board[50][50]={0};
  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      cin>>board[i][j];

    }
  }

  for(int i=0;i<H;i++){
    for(int j=0;j<W;j++){
      if(board[i][j]=='#'){
        if((j>0&&board[i][j-1]=='#')||(j<W-1&&board[i][j+1]=='#')||(i>0&&board[i-1][j]=='#')||(i<H-1&&board[i+1][j]=='#')){
          continue;
        }
        cout<<"No"<<endl;
        return 0;
      }
    }
  }
  cout<<"Yes"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fr first
#define sc second
#define pb push_back
#define maxheap priority_queue<int>
#define minheap priority_queue<int, vector<int>, greater<int> >
#define ll long long
const int inf = 1e8;
const ll INF = 1e18;
const int MAXN = 3e5 + 200;
const  long double eps = 1e-9;
const long double pi = acos(-1.0);
using namespace std;

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

int n, m;
bool can[MAXN];
int kol[MAXN];
void solve() {
    cin >> n >> m;
    for (int i = 1; i <= n; i++)
        kol[i] = 1;
    can[1] = true;
    for (int i = 1; i <= m; i++){
        int x, y;
        cin >> x >> y;
        kol[x]--;
        kol[y]++;
        if (can[x])
            can[y] = true;
        if (can[x] && kol[x] == 0){
            can[x] =false;
        }
    }
    int ans = 0;
    for (int i = 1; i <= n; i++)
        if (can[i]) ans++;
        cout << ans << endl;
}


int main(){
    ios::sync_with_stdio(NULL), cin.tie(0), cout.tie(0);
    cout.setf(ios::fixed), cout.precision(40);
    //freopen("inevit.in", "r", stdin);
    //freopen("inevit.out", "w", stdout);
    int step;
    step = 1;
    //cin >> step;
    for (int i = 1; i <= step; i++)
        solve();


}

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

int res;

void dfs(int n, int index, int s) {
    if (n == 0 && s == 0) {
        res++;
        return;
    } else if (n == 0 || s < 0 || s < index || 9 < index) {
        return;
    }
    dfs(n - 1, index + 1, s - index);
    dfs(n, index + 1, s);
    return;
}

int main() {
    while (true) {
        int n, s;
        cin >> n >> s;
        if ((n | s) == 0) {
            break;
        }
        res = 0;
        dfs(n, 0, s);
        cout << res << endl;
    }
}

Measured memory_bytes: 0
'''import os
import sys
from io import BytesIO, IOBase
 
BUFSIZE = 8192
 
 
class FastIO(IOBase):
    newlines = 0
 
    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None
 
    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()
 
    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()
 
    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)
 
 
class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")
 
 
sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")'''
#######################################################################
n,k=map(int,input().split())
l=[]
c=0
for i in range(n+1):
    c+=i
    l.append(c)
ans=0
for i in range(k,n+1):
    ans+=l[-1]-l[n-i]-l[i-1]+1
    ans=ans%1000000007
ans+=1
print(ans)



Measured memory_bytes: 19356
#include <bits/stdc++.h>
using namespace std;
const int N=1e5+5;
int n,h;
int ans,last,sum;
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		scanf("%d",&h);
		if(last>=h) ++sum;
		else sum=0;
		last=h;
		ans=max(ans,sum);
	}
	printf("%d",ans);
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define SORT(v) sort(v.rbegin() , v.rend())
#define si(n) scanf( "%d" , &n)
#define sii(n , m) scanf( "%d %d" , &n , &m)
#define sl(n) scanf( "%lld" , &n)
#define sll(n , m) scanf( "%lld %lld" , &n, &m)
#define ss(cad) scanf( "%s" , cad)
#define sz(x) (int)x.size()
#define PB push_back
#define fst first
#define scn second
#define DBG(x) cerr << #x << " = " << (x) << endl
#define M 1000000007
#define N_MAX 1000010
#define EPS 1e-9

using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector<bool> vb;
typedef vector<ll> vll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef vector<pi> vp;

int ft[200100];
int frec[200100];

void update(int pos, int val){
	while(pos <= 200010){
		ft[pos] += val;
		pos += pos&-pos;
	}
}

int query(int pos){
	int ans = 0;
	while(pos > 0){
		ans += ft[pos];
		pos -= pos&-pos;
	}
	return ans;
}

int minimo(){
	int ini = 1, fin = 200010;
	while(ini != fin){
		int med = (ini+fin)/2;
		if(query(med) == 0)
			ini = med + 1;
		else
			fin = med;
	}
	return ini;
}

void mostrar(set<pi> ls){
	for(auto x: ls)
		printf("(%d, %d) ", x.fst, x.scn);
}

int main(){
	int h, w;
	sii(h, w);
	set<pi> lista;
	for(int i = 1; i <= w; i++){
		lista.insert({i, 1});
		frec[1]++;
		update(1, 1);
	}
	//mostrar(lista);
	//cout << endl;
	int cnt = 0;
	while(h--){
		int a, b;
		sii(a, b);
		bool sw = 0;
		auto pt = lista.lower_bound(pi(a, -1));
		auto pt2 = pt;
		pi mitad = {-1, -1};
		pi inicio;
		if(pt != lista.begin()){
			sw = 1;
			pt--;
			mitad = *pt;
			inicio = *pt;
			pt++;
		}
		while(pt != lista.end() && pt->fst <= b){
			pt2 = pt;
			mitad = *pt;
			update(mitad.scn, -1);
			frec[mitad.scn]--;
			pt++;
			lista.erase(pt2);
		}
		pt2 = lista.lower_bound(pi(b+1, -1));
		if(mitad.fst != -1 && b != w){
			if(pt2 != lista.end() && pt2->fst != b+1){
				int val = mitad.scn + b-mitad.fst+1;
				update(val, 1);
				lista.insert({b+1, val});
			}
			else if(pt2 == lista.end()){
				int val = mitad.scn + b-mitad.fst+1;
				update(val, 1);
				lista.insert({b+1, val});
			}
		}
		if(sw){
			int val = inicio.scn + a-inicio.fst;
			update(val, 1);
			lista.insert({a, val});
		}
		int ans = minimo();
		if(ans == 200010)
			printf("-1\n");
		else
			printf("%d\n", ans+cnt);
		cnt++;
		//mostrar(lista);
		//cout << endl;
	}
    return 0;
}


Measured memory_bytes: 14452
#include<bits/stdc++.h>
#define For(i,k,n) for(ll i=k;i<n;i++)
#define endl "\n"
#define ll long long int
using namespace std;
#define test int t; cin>>t; while(t--)
#define vi vector<int>
#define vl vector<ll>
#define umapii unordered_map<int,int>
#define umapll unordered_map<ll,ll>
#define p_b push_back
#define m_p make_pair 
#define fst first
#define snd second

void dummy(){
    for(int i=0;i<23;i++);
}void scanArr(ll a[],ll n){
    For(i,0,n)cin>>a[i];
}void scanArr(int a[],int n){
    For(i,0,n)cin>>a[i];
}void printl(){
  cout<<endl;
}void dummy2(){
  For(i,0,10)cout<<"";
}void dummy3(int n){
  int p = 0,q=0;
  p=n;n = q;q = p;n++;q--;
}

ll mexp(ll a,ll b){
  if(a==0) return 0;
  if (b==0) return 1;
  ll ans=1;
  while(b>0){
    if(b&1){
      ans*=a;b--;
    }
    else{
      a*=a;b=b>>1;
    }
  }
  return ans;
}

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

  //        ------Code Here------

    string s1,s2;
    cin>>s1>>s2;
    int n=s1.size(),m=s2.size(), res=INT_MAX;
    for(int i=0;i<=n-m;i++)
    {
        int k=0,p=0;
        for(int j=0;j<m;j++)
        {
            if(s1[i+k]!=s2[j])
            {
                p++;
                k++;
            }
            else
            {
                k++;
            }
        }
        
        res=min(res,p);
        
    }
    cout<<res<<endl;
}

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

int main(){
    int n;
    cin>>n;
    vector<int> p(n);
    rep(i,n) cin>>p.at(i);
    int min=INT_MAX;
    int ans=0;
    rep(i,n){
        if(min>p.at(i)){
            ans++;
            min=p.at(i);
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 1024
L, R = map(int, input().split())
MOD = 10 ** 9 + 7
l = '{:060b}'.format(L)[::-1] # 0左詰の二進数６０桁のstr　を逆向きにスライス
r = '{:060b}'.format(R)[::-1] # (桁数60 は　R<=10**18<2**60 より)

memo = [[[[-1 for l in range(2)] for k in range(2)] for j in range(2)] for i in range(60)]

# flagZは、既にx＝y＝1の位があったかチェックしている(MSB)
def f(pos, flagX, flagY, flagZ):
    if pos == -1:
        return 1
    if memo[pos][flagX][flagY][flagZ] != -1:
        return memo[pos][flagX][flagY][flagZ]
    ret = 0
    # x 0, y 0
    if flagX or l[pos] == '0':
        ret += f(pos - 1, flagX, 1 if r[pos] == '1' else flagY, flagZ)
    # x 0, y 1
    if (flagX or l[pos] == '0') and (flagY or r[pos] == '1') and flagZ:
        ret += f(pos - 1, flagX, flagY, flagZ)
    # x 1, y 1
    if flagY or r[pos] == '1':
        ret += f(pos - 1, 1 if l[pos] == '0' else flagX, flagY, 1)
    ret %= MOD
    memo[pos][flagX][flagY][flagZ] = ret
    return ret

ans = f(59, 0, 0, 0) #最大桁からスタート
print(ans)



Measured memory_bytes: 3064
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::cmp::{max, min};
use std::collections::HashMap;

fn main() {
  let s = read::<String>();
  let ss = &s[4..];
  let mut year = String::from("2018");
  year.push_str(ss);

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



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

#define max(a,b) ((a)>(b)?(a):(b))
#define min(a,b) ((a)<(b)?(a):(b))

typedef long long LL;

vector<int> uf;

int find(int n){
  if(uf[n]==n) return n;
  else return uf[n]=find(uf[n]);
}

void uni(int a,int b){
  a=find(a);
  b=find(b);
  if(a==b) return;
  uf[a]=b;
  return;
}

int main(){
  int n;
  cin >> n;
  int x=0;
  vector<int> a(n),b(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
    x^=a[i];
  }
  int count=0;
  for(int i=0;i<n;i++){
    cin >> b[i];
    if(a[i]!=b[i]) count++;
  }
  vector<int> c(count),d(count);
  map<int,pair<int,int>> e,f;
  map<int,pair<int,int>>::iterator itr,itr2;
  uf=vector<int>(count);
  for(int i=0;i<count;i++){
    uf[i]=i;
  }
  count=0;
  for(int i=0;i<n;i++){
    if(a[i]!=b[i]){
      c[count]=a[i];
      d[count]=b[i];
      itr=e.find(a[i]);
      if(itr==e.end()) e[a[i]]={1,count};
      else itr->second.first++;
      itr=f.find(b[i]);
      if(itr==f.end()) f[b[i]]={1,count};
      else{
        itr->second.first++;
        uni(count,itr->second.second);
      }
      count++;
    }
  }
  bool xflag=false;
  for(itr=f.begin();itr!=f.end();itr++){
    if(itr->first==x) xflag=true;
    itr2=e.find(itr->first);
    if(itr2==e.end()){
      if(itr->first!=x||itr->second.first>1){
        cout << -1 << endl;
        return 0;
      }
    }else{
      if(itr->second.first>itr2->second.first+1||(itr->first!=x&&itr->second.first==itr2->second.first+1)){
        cout << -1 << endl;
        return 0;
      }
    }
  }
  for(int i=0;i<count;i++){
    itr=f.find(c[i]);
    if(itr!=f.end()){
      uni(i,itr->second.second);
    }
  }
  vector<bool> isroot(n,false);
  for(int i=0;i<count;i++){
    isroot[find(i)]=true;
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(isroot[i]) ans++;
  }
  // cout << ans << " " << count << endl;
  if(xflag){
    cout << count+ans-1 << endl;
  }else{
    cout << count+ans << endl;
  }
  return 0;
}


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

int main()
{
	ll x, k, d;
	cin >> x >> k >> d;

	x = abs(x);
	if (x > 0 && (x/d) >= k)
	{
		//cout<<x-k*d<<"\n";
		printf("%lld\n", x-k*d);
		return 0;
	}
	ll y = x/d;
	x -= y*d;
	k -= y;

	if (k % 2 == 0)
		printf("%lld\n", abs(x));
	else
		printf("%lld\n", min(abs(x-d), abs(x+d)));

	return 0;
}

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

int main() {
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  int x = a * b;
  int y = c * d;

  if (x >= y) {
    cout << x << endl;
  } else {
    cout << y << endl;
  }
}


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

if n == 1:
    print(0)

else:    
    ans = 0
    for i in range(1, n+1, 2):
        count = 0
        for j in range(1, i+1):
            if i % j == 0:
                count += 1
        if count == 8:
            ans += 1

    print(ans)

Measured memory_bytes: 3060
package main

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

var sc = bufio.NewScanner(os.Stdin)

func init() {
	const maxWord = (1 << 30)
	buf := []byte{}
	sc.Buffer(buf, maxWord)
	sc.Split(bufio.ScanWords)
}

func input() string {
	sc.Scan()
	return sc.Text()
}

func solve(n int, a []int) int {
	mod := 1000000000 + 7
	ans := 0
	sum := 0
	for i := 0; i < n-1; i++ {
		sum += a[i]
		sum %= mod
		ans += (sum * a[i+1]) % mod
		ans %= mod
	}

	return ans % mod
}

func main() {
	n, _ := strconv.Atoi(input())
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i], _ = strconv.Atoi(input())
	}
	fmt.Println(solve(n, a))
}


Measured memory_bytes: 5848
def gcd(a, b)
  a, b = b, a % b while b > 0
  a
end

while line = STDIN.gets
  a, b = line.chomp!.split.map!(&:to_i).sort.reverse
  g = gcd(a, b)
  l = a * b / g
  puts "#{g} #{l}"
end

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

typedef long long ll;

int N, S, W, Q, a[100005];

ll mod_pow(ll x,ll n){
  ll res=1;
  while(n){
    if(n%2) res=res*x%Q;
    x=x*x%Q;
    n/=2;
  }
  return res;
}

void init(){
  int g = S;
  for(int i=0; i<N; i++) {
    a[i] = (g/7) % 10;
    if( g%2 == 0 ) { g = (g/2); }
    else           { g = (g/2) ^ W; }
  }
}

signed main(){

  while(1){
    
    cin>>N>>S>>W>>Q;
    if( !N && !S && !W && !Q ) break;
    
    init();
    
    map<int,int> cnt;
    
    int ans = 0, A = 1, B = 0;
    int sum = 0;
    
    if( a[0] != 0 ){
      cnt[ a[0] % Q ]++;
      sum++;
      if( a[0] % Q == 0 ) ans++;
    }
    
    for(int i=1;i<N;i++){
      
      A = A * 10 % Q;
      B = ( B * 10 + a[i] ) % Q;
      
      if( a[i] != 0 ){
	
	int num = ( mod_pow( A, Q - 2 ) * ( a[i] + ( Q - B ) ) ) % Q;
	
	if( !( A == 0 && ( a[i] + ( Q - B ) ) % Q != 0 ) ){
	  cnt[num]++;
	  sum++;
	  assert( ( num * A + B ) % Q == a[i] % Q );
	}
	
      }
      
      int num = ( mod_pow( A, Q - 2 ) * ( Q - B ) ) % Q;
            
      if( !( A == 0 && ( Q - B ) % Q != 0 ) ){
	if( A != 0 ) ans += cnt[num];
	else ans += sum;
	assert( ( num * A + B ) % Q == 0 );
      }
      
    }
    
    cout<<ans<<endl;
    
  }
  
  return 0;
}



Measured memory_bytes: 9496
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define endl '\n'
#define SPEED ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
signed main()
{
    SPEED;
    int k;
    cin>>k;
    string str;
    cin>>str;
    if(k>=str.size())
    cout<<str;
    else
    {
        str=str.substr(0,k);
        cout<<str<<"...";
    }
}

Measured memory_bytes: 3636
# input()
# int(input())
# map(int, input().split())
# list(map(int, input().split()))
# list(map(int, list(input()))) # スペースがない数字リストを読み込み
import math
import fractions
import sys
import bisect
import heapq  # 優先度付きキュー(最小値取り出し)
import collections
from collections import Counter
from collections import deque
import pprint
import itertools

sr = lambda: input()
ir = lambda: int(sr())
lr = lambda: list(map(int, sr().split()))

"""nを素因数分解"""
"""2以上の整数n => [[素因数, 指数], ...]の2次元リスト"""


def factorization(n):
    arr = []
    temp = n
    if n == 1:
        return arr

    for i in range(2, int(-(-n ** 0.5 // 1)) + 1):
        if temp % i == 0:
            cnt = 0
            while temp % i == 0:
                cnt += 1
                temp //= i
            arr.append([i, cnt])

    if temp != 1:
        arr.append([temp, 1])

    if arr == []:
        arr.append([n, 1])

    return arr


# a^n
def power(a, n, mod):
    x = 1
    while n:
        if n & 1:
            x *= a % mod
        n >>= 1
        a *= a % mod
    return x % mod


# n*(n-1)*...*(l+1)*l
def kaijo(n, l, mod):
    if n == 0:
        return 1
    a = n
    tmp = n - 1
    while (tmp >= l):
        a = a * tmp % mod
        tmp -= 1
    return a


inf = 10 ** 18
mod = 10 ** 9 + 7

s = input()
pre = s[0]
if len(s) == 1:
    print(0)
    sys.exit()
else:
    ans=0
    for i in range(1,len(s)):
        if pre != s[i]:
            ans+=1
            pre = s[i]
    print(ans)

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

#define int long long
#define double long double

using namespace std;

template<class T> string tostr(T x) { stringstream o; o << x; return o.str(); }
template<class T> T sqr(T x) { return x*x; }
template<class T> T mypow(T x, int n) { T r = 1; while (n > 0) { if (n & 1)r = r*x; x = x*x; n >>= 1; }return r; }

int toint(string s) { int v; stringstream i(s); i >> v; return v; }
bool check(int x, int y, int w, int h) { return x >= 0 && y >= 0 && w > x && h > y; }
int gcd(int a, int b) { return b ? gcd(b, a%b) : a; }
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define REP(i,a,b)	for(int (i) = (a);i < (b);(i)++)
#define rep(i,n)	REP(i,0,n)
#define PER(i,a,b)	for(int (i) = (a-1);i >= (b);(i)--)
#define per(i,n)	PER(i,n,0)
#define each(i,n)	for(auto &i : n)
#define clr(a)		memset((a), 0 ,sizeof(a))
#define mclr(a)		memset((a), -1 ,sizeof(a))
#define all(a)		(a).begin(),(a).end()
#define dump(val) 	cerr << #val " = " << val << endl;
#define dum(val)	cerr << #val " = " << val;
#define FILL(a,v)	fill(a,a+sizeof(a)/sizeof(*a),v)

const int dx[8] = { +1,+0,-1,+0,+1,+1,-1,-1 };
const int dy[8] = { +0,-1,+0,+1,-1,+1,-1,+1 };
const int mod = 1e9 + 7;
const int INF = 1e9;

int a[501][501];

signed main() {

	int H, W, h, w;
	cin >> H >> W >> h >> w;

	int count = 0;
	rep(y, H) rep(x, W){
		if(y % h == h-1 && x % w == w-1){
			a[y][x] = -1e9;
		}else
		if(y % h == 0 && x % w == 0){
			a[y][x] = 1e9-1;
		}else{
			a[y][x] = 0;
		}
		count += a[y][x];
	}

	if(count <= 0) {
		cout << "No" << endl; return 0; 
	}
	cout << "Yes" << endl;
	rep(y, H){
		rep(x, W){
			if(x == W - 1){
				cout << a[y][x] << endl;
			}else{
				cout << a[y][x] << " ";
			}
		}
	}


	return 0;
}

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

int dp[10001][722];

int main() {
    int N, M;
    while (cin >> N >> M, N || M) {
        memset(dp, 0, sizeof dp);
        int r;
        cin >> r;
        for (int i=0; i<r; ++i) {
            int t, n, m, s;
            cin >> t >> n >> m >> s;
            if (s == 1) {
                dp[m][t-540] += 1;
            } else {
                dp[m][t-540] -= 1;
            }
        }
        for (int i=1; i<=M; ++i) {
            for (int j=1; j<722; ++j) {
                dp[i][j] = dp[i][j-1] + dp[i][j];
            }
        }
        int q;
        cin >> q;
        for (int i=0; i<q; ++i) {
            int ts, te, m;
            cin >> ts >> te >> m;
            int cnt = 0;
            for (int j=ts; j<te; ++j) {
                cnt += (0 < dp[m][j-540]);
            }
            cout << cnt << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 29372
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int x = sc.nextInt();
		int y = sc.nextInt();
		int t[] = {0, 1,3,1,2,1,2,1,1,2,1,2,1};
		System.out.println(t[x] == t[y] ? "Yes" : "No");
	}
}


Measured memory_bytes: 21844
#include <cassert>
#include <cctype>
#include <cerrno>
#include <cfloat>
#include <ciso646>
#include <climits>
#include <clocale>
#include <cmath>
#include <csetjmp>
#include <csignal>
#include <cstdarg>
#include <cstddef>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <ccomplex>
#include <cfenv>
#include <cinttypes>
#include <cstdbool>
#include <cstdint>
#include <ctgmath>
#include <cwchar>
#include <cwctype>
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#include <array>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
typedef long long int ll;
#define FOR(i, a, b) for (ll i = (signed)(a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define EREP(i, n) for (int i = (n)-1; i >= 0; --i)
#define MOD 1000000007
#define pb push_back
#define INF 93193111451418101
#define MIN -93193111451418101
#define EPS 1e-11
#define tp(a, b, c) make_tuple(a, b, c)
#define lb(a, b) lower_bound((a).begin(), (a).end(), (b))
#define ub(a, b) upper_bound((a).begin(), (a).end(), (b))
#define bitcnt(a) (ll) __builtin_popcount((a))

ll N, A, B;

int main() {

	std::cin >> N >> A >> B;

	if ((B - A) % 2 == 0) puts("Alice");
	else puts("Borys");

	return 0;

}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>
#include <map>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <limits>
#include <numeric>

using ld = long double;
using ll = long long int;
using ul = unsigned long long int;

namespace lamlib
{
	/* constant */
	constexpr double epsilon = std::numeric_limits<double>::epsilon();

	/* math */
	template<class T> inline T abs(const T &a){ return (a>0) ? a : -a; }
	ul inline digit(const ul &num){ return static_cast<ul>(std::log10(num+epsilon))+1; }

	/* algorithm */
	ul gcd(const ul &a,const ul &b) { return (!b) ? a : gcd(b,a%b); }
	ul lcm(const ul &a,const ul &b) { return (a/gcd(a,b))*b; } // a/gcd(a,b)*b <=> (a*b)/gcd(a,b)
	std::vector<bool> eratosthenes(const ul &n)
	{
		std::vector<bool> prime_candidate(n,true);
		prime_candidate[0] = prime_candidate[1] = false;
		for(ul i = 2;i*i < n;++i)
		{
			if(!prime_candidate[i]) continue;
			for(ul j = 2;i*j < n;++j) prime_candidate[i*j] = false;
		}
		return prime_candidate;
	}
	ll rho_method(const ll &n)
	{
		auto f = [&](const ll &xi){ return (xi*xi+1)%n; };
		ll x = 2, y = 2, d = 1;
		while(d == 1)
		{
			x = f(x);
			y = f(f(y));
			d = lamlib::gcd(lamlib::abs(x-y),n);
		}
		return d;
	}
	// 素因数分解(試し割)
	std::vector<ll> prime_factorization_trial(const ll &n)
	{
		ll num = n;
		std::vector<ll> prime;
		for(ll i = 2;i*i <= n;++i)
		{
			while((num%i) == 0)
			{
				prime.emplace_back(i);
				num /= i;
			}
		}
		if(num > 1) prime.emplace_back(num);
		return prime;
	}

	/* string */
	inline ul same_char_count(const std::string s,const char &ch){ return std::count(std::cbegin(s),std::cend(s),ch); }
}

// std::cout << std::fixed << std::setprecision(15) << std::endl;

#define ANS(false)

int main(int argc,char *argv[])
{
	ld a,b,h,m;
	std::cin >> a >> b >> h >> m;

	ld alpha = ((60.0*h + m)/720.0) * (2*std::acos(-1));
	ld beta = (m/60.0) * (2*std::acos(-1));
#if ANS
	ld rad = alpha - beta;
	ld ans = std::sqrt((a*a+b*b) - 2.0*a*b*std::cos(rad));
#else
	ld x_a = a*std::cos(alpha);
	ld y_a = a*std::sin(alpha);
	ld x_b = b*std::cos(beta);
	ld y_b = b*std::sin(beta);
	ld ans = std::sqrt((x_a-x_b)*(x_a-x_b) + (y_a-y_b)*(y_a-y_b));
#endif
	
	std::cout << std::fixed << std::setprecision(15) << ans << std::endl;

	return 0;
}

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

int main()
{
	int n, m = 0;
	string s;

	cin >> s >> n;

	for (int i = 0; i < n; i++) {
		string t;

		cin >> t;
		t = t + t;

		if (t.find(s) != string::npos)
			m++;
	}

	cout << m << endl;

	return 0;
}


Measured memory_bytes: 3156
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

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

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor)) void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int X, A, B;
    cin >> X >> A >> B;

    if (B <= A) {
        cout << "delicious" << endl;
    } else if ( B <= (A + X) ) {
        cout << "safe" << endl;
    } else {
        cout << "dangerous" << endl;
    }
}

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

#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

typedef long long ll;

const int INF = 1 << 30;
const ll LLINF = 1LL << 62;

int mod = 1000000007;

int main(void){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N, M; cin >> N >> M;
    int cnt[100001] = {};
    int same[M] = {};
    int X[M] = {};
    rep(i, N){
        int x; cin >> x;
        cnt[x]++;
        X[x%M]++;
    }
    rep(i, 100001){
        int md = i % M;
        same[md] += cnt[i]/2;
    }
    int ans = X[0]/2;
    if(M%2 == 0) ans += X[M/2]/2;

    int ulim = (M-1)/2;
    for(int i = 1; i <= ulim; i++){
        int l = i, r = M-i;
        int acc = min(X[l], X[r]);
        X[l] -= acc; X[r] -= acc;
        acc += min(X[l]/2, same[l]);
        acc += min(X[r]/2, same[r]);
        ans += acc;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1408