akhauriyash/Code-Regression huggingface dataset:
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, m = sc.nextInt()
    val ss = new Array[Int](m)
    val cs = new Array[Int](m)
    val num = Array.fill[Int](n)(-1)
    var flg = true
    for (i <- 0 until m) {
      ss(i) = sc.nextInt()
      cs(i) = sc.nextInt()

    }

    for (i <- 0 until m) {
      if (num(ss(i) - 1) == -1) {
        num(ss(i) - 1) = cs(i)
      } else if (num(ss(i) - 1) != cs(i)) {
        flg = false
      }
    }

    if (!flg) {
      println(-1)
      return
    } else if (n > 1 && num(0) == 0) {
      println(-1)
      return
    }

    // これはひどい。。
    if (n == 1 && m == 0) {
      num(0) = 0
    }

    if (num(0) == -1) {
      num(0) = 1
    }
    for (i <- 1 until n) {
      if (num(i) == -1) {
        num(i) = 0
      }
    }

    println(num.mkString(""))
  }
}


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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;

int main() {
  string s, t;
  cin >> s >> t;
  ll a, b;
  cin >> a >> b;
  string u;
  cin >> u;
  if (u == s)
    --a;
  else
    --b;
  cout << a << " " << b << endl;
  return 0;
}

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

int main(void){
  int a, b;
  scanf("%d", &a);
  scanf("%d", &b);
  
  if( b % a ==0){
    printf("%d", a+b);
  }else{
    printf("%d", b-a);
  }
  
  return 0; 
}

Measured memory_bytes: 128
def main():
    def greed(s):
        workday = []
        start = 0
        while start < n:
            if s[start] == 'x':
                start += 1
            else:
                workday.append(start+1)
                start += c + 1
        return workday

    n, k, c = map(int, input().split())
    s = input().strip()

    front = greed(s)
    back = [n+1-i for i in greed(s[::-1])[::-1]]

    if len(front) > k or len(back) > k:
        return
    for i, j in zip(front, back):
        if i == j:
            print(i)

if __name__ == "__main__":
    main()


Measured memory_bytes: 26892
#A
if False:
    A=[1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
    K=int(input())
    print(A[K-1])

#B
if False:
    H,W=map(int,input().split())
    ans=0
    if H==1 or W==1:
        ans+=1
    else:
        ans+=(H//2)*W
        if H%2!=0:
            ans+=W//2
            ans+=W%2
    print(ans)

#C
if False:
    A,B,C=map(int,input().split())
    if 4*A*B<(C-A-B)**2:
        if C-A-B>=0:
            print('Yes')
        else:
            print('No')
    else:
        print('No')

#D
from collections import deque

N=int(input())
alp='abcdefghijkl'
q=deque()
q.append(['a',1])
ans=[]
while q:
    s,i=q.popleft()
    if len(s)==N:
        ans.append(s)
    else:
        for j in range(i+1):
            # print(j)
            tmp=[]
            tmp.append(s+alp[j])
            tmp.append(max(i,j+1))
            q.append(tmp)
            # print(tmp)
ans.sort()
for i in range(len(ans)):
    print(ans[i])

Measured memory_bytes: 25716
#include<stdio.h>

#include<math.h>


int main(void){


  double r,c,s;


  while(scanf("%lf\n",&r)!=EOF)


{


    c = 2.0*r*M_PI;


    s = r*r*M_PI;


    printf("%.6lf %lf\n",s,c);


  }


return 0;


}

Measured memory_bytes: 656
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin>>s;
  long long int res=0,i;
  for(i=0;i<s.size();i++){
    res+=(s[i]-'0');
  }
  cout<<(res%9==0? "Yes":"No");
}

Measured memory_bytes: 3724
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<climits>
#include<iostream>
#include<sstream>
#include<utility>
#include<map>
#include<vector>
#include<queue>
#include<algorithm>
#include<set>
#include<stack>
using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<double,double> pdd;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef set<int> si;
typedef map<int, int> mii;
#define INF (1<<29)

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

    int ans;
    ans=(x-z)/(y+z);


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

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

int m[N][N], n, d[N], f[N], count=0;
char color[N];
void dfs(int);



int main(){
  int i, j, a, b, c;

  scanf("%d",&n);

  for(i=0;i<n;i++){
    for(j=0;j<n;j++){
      m[i][j] = 0;
    }
  }

  for(i=0;i<n;i++){
    scanf("%d%d",&a,&b);
    a--;
    for(j=0;j<b;j++){
      scanf("%d",&c);
      c--;
      m[a][c] = 1;
    }
  }

  for(i=0;i<n;i++) color[i] = 'w';
  for(i=0;i<n;i++){
    if(color[i] == 'w'){
      dfs(i);
    }
  }

  for(i=0;i<n;i++){
    printf("%d %d %d\n",i+1,d[i],f[i]);
  }

  return 0;
}


void dfs(int x){
  int i;

  color[x] = 'g';
  ++count;
  d[x] = count;

  for(i=0;i<n;i++){
    if(m[x][i] == 0){
      continue;
    }
    if(color[i] == 'w'){
      dfs(i);
    }
  }
  color[x] = 'b';
  count++;
  f[x] = count;
}




Measured memory_bytes: 2108
#include<iostream>
#include<string>
#include<vector>
#include<math.h>
#include<cmath>
#include<stack>
#include <algorithm>
#include <functional>
//#include<stdlib.h>
using namespace std;
int main() {
	int n,m,p=0;
	cin >> n; m = n * (n-1)/2;
	vector<int>x(n);
	vector<int>y(n);
	for (int a = 0; a < n; a++) { cin >> x[a] >> y[a]; }
	vector<vector<int>>l(m, vector<int>(2, 0));//p1p2xy
	vector<vector<int>>s(m, vector<int>(2, 0));
	for (int a = 0; a < n; a++) 
	{
		for (int b = a+1; b < n; b++) 
		{
			if (x[a] > x[b])
			{
				l[p][0] = x[a]-x[b];
				l[p][1] = y[a]-y[b];
			}
			else if (x[a] == x[b]) 
			{
				if (y[a] > y[b])
				{
					l[p][0] = 0;
					l[p][1] = y[a] - y[b];
				}
				else
				{
					l[p][0] = 0;
					l[p][1] = y[b] - y[a];
				}
			}
			else
			{
				l[p][0] = x[b] - x[a];
				l[p][1] = y[b] - y[a];
			}
			p++;
		}
	}
	for (int a = 0; a < m; a++)
	{
		for (int b = 0; ; b++)
		{
			if (s[b][1] == 0)
			{
				s[b][0] = a;
				s[b][1] = 1;
				break; 
			}
			else if (l[s[b][0]][0] == l[a][0] && l[s[b][0]][1] == l[a][1])
			{
				s[b][1]++;
				break;
			}
		}
	}
	p = 0;
	for (int a = 0;a<m; a++) { if (s[a][1] > p) { p = s[a][1]; } else if (s[a][1] == 0) { break; } }
	cout << n - p;
	return 0;
}

Measured memory_bytes: 384
#include<iostream>
#include<algorithm>
#include<vector>
using namespace std;
#define LL long long
int N, K;
LL L;
int a[200010];
 
bool judge(int x){
    LL cnt = 0;//x以下となる区間を数える
    vector<int> sum = { 0 };//sum[i]には区間[1, i]までのｘ以下の数の個数を保存
    LL r = 0;

	for(int i = 1; i <= N; i++){
        sum.push_back(sum[i - 1]);
        if(a[i] <= x) sum[i]++;
        if(sum[i] - K < 0) continue;

		while(r <= i - K){
			if(sum[r] <= sum[i] - K) r++;
			else break;
		}
        cnt += r;
    }
    return cnt >= L;
}
 
int solve(){
    int lb = 0, ub = N;
    while(ub - lb > 1){
        int mid = (ub + lb) / 2;
        if(judge(mid)){
            ub = mid;
        }else{
            lb = mid;
        }
    }
    return ub;
}
 
void input(){
    cin >> N >> K >> L;
    for(int i = 1; i <= N; i++){
        cin >> a[i];
    }
}
 
int main(){
    input();
    cout << solve() << endl;
    return 0;
}


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


#define debug(x) cerr<< #x << ": "<< x << endl;
#define print(x) cerr<< x << endl;

#define mp make_pair
#define pb push_back
#define all(x) (x).begin() , (x).end()
#define rall(x) (x).rbegin() , (x).rend()
#define REP(i,x,y) for(int i=x;i<y;i++)
#define REPIT(it,A) for(typeof(A.begin()) it = (A.begin()); it!=A.end();it++)
#define fst first
#define snd second
#define sqr(x) ((x)*(x))

#define fastio ios_base::sync_with_stdio(0);cin.tie(0);
#define ones(x) __builtin_popcountll(x)
using namespace std;

typedef pair<int,int> ii ;
typedef long long ll ;
typedef vector<int> vi;
typedef vector<ii> vii;


int n;

void out(){
	cout<<"No"<<endl;
	exit(0);
}

int main(){
   fastio;
	cin >> n;
	int uno = 0;
	int dos = 0;
	int cero = 0;
	for (int i = 0; i < n; i++) {
		int a;
		cin >> a;
		a %= 4;
		if(a == 1 || a == 3) uno++;
		else if(a == 2) dos++;
		else cero++;
	}
	int lst = 0;
	while(uno > 0){
		if(lst != 0) out();
		uno--;
		lst = 1;
		if(cero > 0){
			cero--;
			lst = 0;
		}
	}
	if(lst == 1 && dos > 0) out();

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



Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
long long mod=1000000007;
long long ans=0;
int fac[2020202];
int ifac[2020202];
int C(int n,int m)
{
	if(n<m)
		return 0;
	return (long long)fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}
int main()
{
	int n,cnt,d,d1;
	scanf("%d",&n);
	n--;
	fac[0]=1;
	for(int i=1;i<=2000000;i++)
		fac[i]=(long long)fac[i-1]*i%mod;
	ifac[0]=ifac[1]=1;
	for(int i=2;i<=2000000;i++)
		ifac[i]=(long long)(mod-mod/i)*ifac[mod%i]%mod;
	for(int i=2;i<=2000000;i++)
		ifac[i]=(long long)ifac[i-1]*ifac[i]%mod;
	ans=(long long)(n+1)*fac[n]%mod;
	d=(n+1)/2;
	cnt=n/2+1;
	for(int i=cnt;i<=n;i++)
	{
		d1=d-(i-cnt);
		(ans-=(long long)fac[i]*C(i-d1+d1-1,d1-1)%mod*fac[n-i])%=mod;
	}
	printf("%lld",(ans+mod)%mod);
	return 0;
}

Measured memory_bytes: 16000
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned ll
#define PI acos(-1)
#define vi vector<int>
#define pi pair<int, int>
#define pl pair<ll, ll>
template<typename T> using v2 = vector<vector<T>>;
template<typename T> using v3 = vector<vector<vector<T>>>;
template<class T> istream &operator>>(istream&is,vector<T>&v){for(auto &elemnt:v)is>>elemnt;return is;}
template<class T,class U> istream &operator>>(istream&is,pair<T,U>&p){is>>p.first>>p.second;return is;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int MOD = 1e9 + 7;
const int INF = 1e9 + 200;
const ll INFLL = 2e18 + 200;

bool check(vector<string> temp, int K) {
    int cnt = 0;
    for (auto a : temp) for (auto b : a) if (b == '#') cnt++;
    return cnt == K;
}

int main() {
    int H, W, K;
    cin >> H >> W >> K;
    vector<string> base(H);
    for (int i = 0; i < H; i++) cin >> base[i];
    int ans = 0;
    auto calc = [&](int h, int w) {
        vector<string> temp = base;
        for (int i = 0; i < H; i++) {
            for (int j = 0; j < W; j++) {
                if (((h>>i)&1)||((w>>j)&1)) temp[i][j] = '0';
            }
        }
        ans += check(temp, K);
    };
    for (int i = 0; i < (1<<H); i++) {
        for (int j = 0; j < (1<<W); j++) {
            calc(i, j);
        }
    }
    cout << ans << endl;
}


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

int main(void) {
	double x = 0;
	double y = 0;
	int t_now = 90;
	int len;
	int theta;

	while (1) {
		scanf("%d,%d", &len, &theta);
		if (len == 0 && theta == 0) break;
		x += len * cos(t_now * M_PI / 180);
		y += len * sin(t_now * M_PI / 180);

		t_now += theta * -1;
	}

	printf("%d\n", (int)x);
	printf("%d\n", (int)y);

	return (0);
}

Measured memory_bytes: 604
using System;
using static System.Console;

class Program
{
    static void Main(string[] args)
    {
        int N = int.Parse(ReadLine());
        string[] W = new string[N];
        string[] W_ini = new string[N];
        string[] W_end = new string[N];
        string ans = "Yes";
        for (int i = 0; i < N; i++)//文字取得
        {
            W[i] = ReadLine();
            W_ini[i] = W[i].Substring(0,1);
            W_end[i] = W[i].Substring(W[i].Length-1);
        }
       
        for(int i = 0; i < N-1; i++)//しりとり判定
        {
            if (W_end[i] != W_ini[i+1])
            {
                ans = "No";
                break;
            }
        }
        if (ans == "Yes")
        {
            for (int i=0;i<N;i++) //重複判定
            {
                for(int j =1; j < N-i; j++)
                {
                    if (W[i] == W[i + j])
                    {
                        ans = "No";
                        break;
                    }
                }
            }
        }                
        WriteLine(ans);
        
    }
}

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

namespace atcoder.abc170.b
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] inputArray = getIntParams();
            int X = inputArray[0];
            int Y = inputArray[1];

            for (int i = 0; i <= X; i++)
            {
                int j = X - i;

                if (4 * i + 2 * j == Y)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }
            Console.WriteLine("No");
        }

        //↓↓↓ shared function ↓↓↓
        static int getIntParam()
        {
            return int.Parse(Console.ReadLine());
        }
        static int[] getIntParams()
        {
            return Console.ReadLine().Split(' ').Select(i => int.Parse(i)).ToArray();
        }
        static long getLongParam()
        {
            return long.Parse(Console.ReadLine());
        }
        static long[] getLongParams()
        {
            return Console.ReadLine().Split(' ').Select(i => long.Parse(i)).ToArray();
        }
        static string getStringParam()
        {
            return Console.ReadLine();
        }
        static string[] getStringParams()
        {
            return Console.ReadLine().Split(' ');
        }
    }
}


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


int main() {
    string s;
    cin>>s;

    rep(i,3){
        if(s[i]=='1') s[i]='9';
        else if(s[i]=='9') s[i]='1';
    }
    
    cout<<s<<endl;

    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <tuple>
#include <unordered_map>

using namespace std;
typedef tuple<int, int, int> tiii;

int main(){
	ios_base::sync_with_stdio(false);
	int n, a, d, m;
	cin >> n >> a >> d >> m;
	vector<tiii> queries;
	unordered_map<int, int> mp;
	for(int i = 0; i < m; ++i){
		int x, y, z;
		cin >> x >> y >> z;
		queries.emplace_back(x, y, z);
		mp[y] = a + (y - 1) * d;
		mp[z] = a + (z - 1) * d;
	}
	for(const auto &q : queries){
		if(get<0>(q) == 0){
			swap(mp[get<1>(q)], mp[get<2>(q)]);
		}else{
			mp[get<1>(q)] = mp[get<2>(q)];
		}
	}
	int k;
	cin >> k;
	if(mp.find(k) != mp.end()){
		cout << mp[k] << endl;
	}else{
		cout << a + (k - 1) * d << endl;
	}
	return 0;
}

Measured memory_bytes: 1212
#include <iostream>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <math.h>
#include <queue>
using namespace std;

#define REP(i, a, b) for (int i = (int)a; i <= (int)b; i++)
#define fi first
#define sc second
#define pb push_back
#define double long double
#define all(x) x.begin(), x.end()

using namespace std;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pair<int, int>> vpii;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<int, int> pii;
typedef pair<i64, i64> pi64;
typedef vector<pi64> vpi64;

const i64 MOD = 1000000007;
const i64 INF = 2e15;

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

	int r;
	cin >> r;

	cout << 3 * r * r << endl;

	return 0;
}

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

using namespace std;

int main(){
    string s, t;

    cin >> s >> t;

    int n = s.length();

    for(int i = 0; i < n; ++i){
        string s2 = s.substr(i) + s.substr(0, i);

        if(s2 == t){
            cout << "Yes" << endl;
            return 0;
        }
    }

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


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

int main()
{
  string S;
  cin >> S;
  int64_t N = S.size(), ans = 0;
  vector<pair<int64_t, char>> v;
  v.emplace_back(1, S.at(0));
  for (int64_t i = 1; i < N; i++)
  {
    if (S.at(i) == S.at(i - 1))
    {
      v.at(v.size() - 1).first++;
    }
    else
    {
      v.emplace_back(1, S.at(i));
    }
  }
  for (int64_t i = 0; i < (int64_t)(v.size() - 1); i++)
  {
    if (v[i].second == '<' && v[i + 1].second == '>')
    {
      if (v[i].first >= v[i + 1].first)
      {
        v[i + 1].first--;
      }
      else
      {
        v[i].first--;
      }
    }
  }
  for (int64_t i = 0; i < (int64_t)(v.size()); i++)
  {
    ans += v[i].first * (v[i].first + 1) / 2;
  }
  cout << ans << endl;
}


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

#define ALL(a) begin(a),end(a)
#define COUNTOF(a) (sizeof(a)/sizeof(a[0]))
#define SP << " " <<
#define FMT(a) #a<<":"<<a 
#define FMT2(a,b) #a<<":"<<a<<", "<<#b<<":"<<b 
#define FMT3(a,b,c) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c 
#define FMT4(a,b,c,d) #a<<":"<<a<<", "<<#b<<":"<<b<<", "<<#c<<":"<<c<<", "<<#d<<":"<<d 
typedef long long ll;
template<class T> istream& operator >> (istream& s, vector<T>& v) {
  for (T& x: v) s >> x;
  return s;
}
inline void Yes(bool f=true){cout<<(f?"Yes":"No")<<endl;}
inline void YES(bool f=true){cout<<(f?"YES":"NO")<<endl;}
#define ANS(a) cout<<a<<endl

int main()
{
    cin.tie(0); ios::sync_with_stdio(false);
    //cout<<std::fixed<<std::setprecision(10);

    int A,B; cin >> A>>B;

    if (A>=13) cout<<B<<endl;
    else if (A>=6) cout<<B/2<<endl;
    else cout<<0<<endl;
}


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

int main(){
  int a;
  cin >> a;
  double ans;
  ans = 0;
  vector<pair<double, string>> M(a);
  rep(i, a){
    cin >> M.at(i).first;
    cin >> M.at(i).second;
    if (M.at(i).second == "BTC") M.at(i).first *= 380000.0;
    ans += M.at(i).first;
  }
  cout << ans << endl;
}

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

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

int main() {
	long long int a, b;
	while(cin>>a>>b){
		if(a<b) swap(a, b);
		
		cout<<gcd(a, b)<<" "<<a*b/gcd(a, b)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3060
<?php

class Scanner {
    private $arr = [];
    private $count = 0;
    private $pointer = 0;
    public function next() {
        if($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }
    public function hasNext() {
        return $this->pointer < $this->count;
    }
    public function nextInt() {
        return (int)$this->next();
    }
    public function nextDouble() {
        return (double)$this->next();
    }
}

class out {
    public static function println($str = "") {
        echo $str . PHP_EOL;
    }
}

$sc = new Scanner();

$s = $sc->next();

$array = [
    'ABC' => 'ARC',
    'ARC' => 'ABC'
    ];

out::println($array[$s]);

?>

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


#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()


using namespace std;
using namespace __gnu_pbds;

template<class T> using ordered_set = tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;
using ll  = long long;

using point = complex<double>;


void err(istream_iterator<string> it) {cerr << endl;}
template<typename T, typename... Args>void err(istream_iterator<string> it, T a, Args... args) {cerr << *it << " = " << a << endl;err(++it, args...);}


const double EPS = 1e-8;
const long long mod = 1e9 + 7;

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

const int N = 1e6 + 5;
const long long inf = 1e18;



int n,a;
vector<int>vec;
int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n;
    for(int i = 0; i < n; ++i){
        cin >> a;
        vec.push_back(a);
    }
    sort(all(vec));
    ll ans = 0;
    int x,y,to_add;
    for(int i = 0; i < n; ++i){
        for(int j = i + 1; j < n; ++j){
            x = vec[i];
            y = vec[j];
            to_add = upper_bound(vec.begin() + j + 1,vec.end(),y+x-1) - lower_bound(vec.begin() + j + 1, vec.end(),y-x + 1);
            ans += to_add;
        }
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#define N 100
main()
{
  int n, A[N], i, j, k,flag=1, c=0;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&A[i]);
  }
  while(flag){
    flag = 0;
    for(j=n-1; j>=1; j--){
      if(A[j] < A[j-1]){
	k = A[j];
	A[j] = A[j-1];
	A[j-1] = k;
	c++;
	flag = 1;
      }
    }
  }
  for(j=0; j<n; j++){
    printf("%d",A[j]);
    if(j == n-1)printf("\n");
    else printf(" ");
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 604
#include <iostream>

using namespace std;

int main(){
  long long L,R;
  long long ans = 2019;
  cin >> L >> R;

  for(long long i=L; i<=L+2019; i++){
    for(long long j=i+1; j<=i+2019 && j<=R; j++){
      ans = min(ans, (i * j) % 2019);
    }
  }

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


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

using namespace std;

int main()
{
    int c[10][10],a[300][300],h,w,ans=0;
    scanf("%d%d",&h,&w);

    for (int i=0;i<10;i++)
        for (int j=0;j<10;j++)
            scanf("%d",&c[i][j]);

    for (int k=0;k<10;k++)
        for (int i=0;i<10;i++)
            for (int j=0;j<10;j++)
                c[i][j]=min(c[i][j],c[i][k]+c[k][j]);

    for (int i=0;i<h;i++)
        for (int j=0;j<w;j++)
            {
                scanf("%d",&a[i][j]);
                if (a[i][j]>-1) ans=ans+c[a[i][j]][1];
            }

    printf("%d",ans);



    return 0;
}


Measured memory_bytes: 512
using System;

public class Program
{
    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int m = sc.NextInt();

        Console.WriteLine(n == m ? "Yes" : "No");
    }

    public static void Main(string[] args)
    {
        new Program().Solve();
    }
}

class Scanner
{
    public Scanner()
    {
        _pos = 0;
        _line = new string[0];
    }

    const char Separator = ' ';
    private int _pos;
    private string[] _line;

    #region スペース区切りで取得

    public string Next()
    {
        if (_pos >= _line.Length)
        {
            _line = Console.ReadLine().Split(Separator);
            _pos = 0;
        }

        return _line[_pos++];
    }

    public int NextInt()
    {
        return int.Parse(Next());
    }

    public long NextLong()
    {
        return long.Parse(Next());
    }

    public double NextDouble()
    {
        return double.Parse(Next());
    }

    #endregion

    #region 型変換

    private int[] ToIntArray(string[] array)
    {
        var result = new int[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = int.Parse(array[i]);
        }

        return result;
    }

    private long[] ToLongArray(string[] array)
    {
        var result = new long[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = long.Parse(array[i]);
        }

        return result;
    }

    private double[] ToDoubleArray(string[] array)
    {
        var result = new double[array.Length];
        for (int i = 0; i < array.Length; i++)
        {
            result[i] = double.Parse(array[i]);
        }

        return result;
    }

    #endregion

    #region 配列取得

    public string[] Array()
    {
        if (_pos >= _line.Length)
            _line = Console.ReadLine().Split(Separator);

        _pos = _line.Length;
        return _line;
    }

    public int[] IntArray()
    {
        return ToIntArray(Array());
    }

    public long[] LongArray()
    {
        return ToLongArray(Array());
    }

    public double[] DoubleArray()
    {
        return ToDoubleArray(Array());
    }

    #endregion
}

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

#define gc( ) std::getchar( )
#define pc( i ) std::putchar( i )
#define RE cout << "Passing [" << __FUNCTION__ << "] on " << __LINE__ << '\n'
#define DEBUG(...) for( auto &i: __VA_ARGS__ ) cout << i << " "; cout << '\n'
#define space ' '
#define enter '\n'
using std::make_pair;

template < typename T >
inline T read( )
{
 T x = 0;
 char ch = gc( );
 bool f = 0;
 while( !std::isdigit( ch ) )
 {
  f = ( ch == '-' );
  ch = gc( );
 }
 while( std::isdigit( ch ) )
 {
  x = x * 10 + ( ch - '0' );
  ch = gc( );
 }
 return f ? -x : x;
}

template < typename T >
void print( T x )
{
 if( x < 0 )
 {
  x = -x;
  pc( '-' );
 }
 if( x < 10 )
 {
  pc( x + 48 );
  return;
 }
 print < T > ( x / 10 );
 pc( x % 10 + 48 );
 return ;
}

namespace Solution
{
#define IOS std::ios::sync_with_stdio( false ), std::cin.tie( 0 ), std::cout.tie( 0 )
#define Rep( i, j, k ) for( int i = j; i >= k; --i )
#define rdi( ) read < int > ( )
#define rdl( ) read < long long > ( )
#define pti( i ) print < int > ( i ), putchar( space )
#define ptl( i ) print < long long > ( i ), putchar( space )
#define For( i, j, k ) for( int i = j; i <= k; ++i )
 using std::cin;
 using std::cout;
 using std::endl;
 using std::vector;
 using std::map;
 using std::queue;
 using std::deque;
 using std::set;
 using std::pair;
 const int N = 204001, mod = 1e9 + 7;
 long long n, k, a[ N ];
 long long check( long long v )
 {
  long long P = 0;
  For( i, 1, n )
   P += ( a[ i ] / v ) - ( a[ i ] % v == 0 ); 
  return P;
 }
 void Fakemain( )
 {
  IOS;
  cin >> n >> k;
  For( i, 1, n )
   cin >> a[ i ];
  long long L = 1, R = 1e9, ans = -1;
  while( L <= R )
  {
   int mid = L + R >> 1;
   if( check( mid ) <= k )
    ans = mid, R = mid - 1;
   else
    L = mid + 1;
  }
  cout << ans;
  return;
 }

} // namespace Solution

int main( int argc, char* argv[] )
{
 Solution::Fakemain( );
 return 0;
}

Measured memory_bytes: 5204
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#include<cstring>
#include<math.h>
#include<bitset>
#include<queue>
#include<set>
#include<iomanip>
#include<math.h>
#include<assert.h>
#include<string>
#include<cstdlib>
#include<cctype>
#include<unordered_map>
#include<sstream>
#include<numeric>
#include<stack>
// #include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1LL<<60;
const double INFD = 1e100;
const ll mod = 1000000007;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
};
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
};

// intやllをstringに変換
template<typename T> inline string toString(const T &a){
  ostringstream oss;
  oss << a;
  return oss.str();
};
// ----------------------------------------------------------------------------

int main(){
  int N,K;
  cin >> N >> K;
  vector<int> h(N);
  for(int i=0; i<N; i++){
    cin >> h[i];
  }
  sort(h.begin(),h.end());
  int ans = 1e9+10;
  for(int i=0; i<N-K+1; i++){
    chmin(ans,h[i+K-1]-h[i]);
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
ll a,b,c,k;
cin>>a>>b>>c>>k;
int xa = min(a,k);
k-=xa;
int xb = min(b,k);
k -=xb;
int xc = min(c,k);
cout<<xa-xc<<endl;
return 0;
}

Measured memory_bytes: 3636
n=int(input())
a,b,c,d=0,0,0,0
for _ in range(n):
  s=input()
  if(s=="AC"):
    a+=1
  elif(s=="WA"):
    b+=1
  elif(s=="TLE"):
    c+=1
  else:
    d+=1
print("AC x",a)
print("WA x",b)
print("TLE x",c)
print("RE x",d)

Measured memory_bytes: 9096
#include <iostream>
#include <vector>
using namespace std;
#define rep2(x,from,to) for(int x=(from);x<(to);++(x))
#define rep(x,to) rep2(x,0,to)
int main() {
	int n;
	while(cin >> n, n) {
		int a[10000]={};
		int c[5000]={};
		rep2(i,1,n) {
			a[(i*i)%n]++;
		}
		vector<int> v;
		rep(i,n) {
			if(a[i]!=0) v.push_back(i);
		}
		rep(i,v.size()) {
			rep(j,v.size()) {
				if(i==j) continue;
				int s = v[i]-v[j];
				if(s<0) s+=n;
				if(s>(n-1)/2) c[n-s]++;
				else c[s]++;
			}
		}
		rep2(i,1,(n+1)/2) {
			cout << c[i] << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 1332
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<ll, ll>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr double eps = 1e-9;
constexpr ll MOD = 1000000007LL;
template <typename T>
bool chmin(T& a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
bool chmax(T& a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
};
template <typename T>
ostream& operator<<(ostream& os, vector<T> v) {
    for(int i = 0; i < v.size(); i++) {
        os << v[i] << (i + 1 == v.size() ? "\n" : " ");
    }
    return os;
}
template <typename T>
vector<T> make_v(size_t a) {
    return vector<T>(a);
}
template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type fill_v(T& t, const V& v) {
    t = v;
}
template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type fill_v(T& t, const V& v) {
    for(auto& e : t) {
        fill_v(e, v);
    }
};
template <typename T>
struct BinaryIndexedTree {
    vector<T> dat;
    size_t n;
    int h;
    BinaryIndexedTree(size_t n) : n(n) {
        h = 1;
        while(h <= n) {
            h <<= 1;
        }
        h >>= 1;
        dat.assign(++n, 0);
    }
    void add(int k, T x) {
        for(++k; k < n; k += k & -k) {
            dat[k] += x;
            dat[k] %= MOD;
        }
    }
    T sum(int k) {
        if(k < 0) {
            return 0;
        }
        T res = 0;
        for(++k; k > 0; k -= k & -k) {
            res += dat[k];
            res %= MOD;
        }
        return res;
    }
    T get(int l, int r) {
        if(l > r) {
            return 0;
        }
        return (sum(r) - sum(l - 1) + MOD) % MOD;
    }
};
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n, a, b;
    cin >> n >> a >> b;
    vector<ll> x(n + 1), ra(n + 1), rb(n + 1);
    x[0] = -LINF;
    for(int i = 1; i <= n; i++) {
        cin >> x[i];
        ra[i] = ra[i - 1];
        rb[i] = rb[i - 1];
        while(ra[i] < i - 1 && x[i] - x[ra[i]] >= a) {
            ra[i]++;
        }
        while(rb[i] < i - 1 && x[i] - x[rb[i]] >= b) {
            rb[i]++;
        }
        if(x[i] - x[ra[i]] < a) {
            ra[i]--;
        }
        if(x[i] - x[rb[i]] < b) {
            rb[i]--;
        }
    }
    BinaryIndexedTree<ll> ta(n + 10), tb(n + 10);
    ta.add(0, 1);
    tb.add(0, 1);
    int la = 0, lb = 0;
    for(int i = 2; i <= n; i++) {
        chmin(ra[i], i - 2LL);
        chmin(rb[i], i - 2LL);
        ta.add(i - 1, tb.get(lb, rb[i]));
        tb.add(i - 1, ta.get(la, ra[i]));
        //  cout << la << " " << ra[i] << endl;
        if(x[i] - x[i - 1] < a) {
            lb = i - 1;
        }
        if(x[i] - x[i - 1] < b) {
            la = i - 1;
        }
    }
    cout << (ta.get(la, n - 1) + tb.get(lb, n - 1)) % MOD << endl;
}


Measured memory_bytes: 4224
N,H=map(int,input().split())
B=[]
A=0
for _ in range(N):
    a,b = map(int,input().split())
    A = max(A,a)
    B.append(b)
B = sorted(B, reverse=True) + [0]

i = 0
while B[i] >= A:
    i += 1
B = B[:i]

ans = 0
for i in range(len(B)):
    H -= B[i]
    ans += 1
    if H <= 0:
        print(ans)
        exit()
print(ans + (H -1)//A + 1)


Measured memory_bytes: 14448
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines

MOD = 10**9+7
d = {}
def prime_factorization(n):
    i = 2
    while i * i <= n:
        if n % i == 0:
            if d.get(i) is None:
                d[i] = 1
                n //= i
            while n % i == 0:
                n //= i
                d[i] += 1
        i += 1
    if n > 1:
        if d.get(n) is None:
            d[n] = 1
        else:
            d[n] += 1


def main():
    N = int(readline())

    for i in range(1,N+1):
        prime_factorization(i)
    
    ans = 1
    for v in d.values():
        ans *= v + 1
        ans %= MOD

    print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 3064
'''
Created on 2020/08/21

@author: harurun
'''
def main():
  import sys
  pin=sys.stdin.readline
  pout=sys.stdout.write
  perr=sys.stderr.write
  
  N=int(pin())
  A=list(map(int,pin().split()))
  cnt=0
  for i in A:
    if i%2==1:
      cnt+=1
  if cnt%2==0:
    print("YES")
  else:
    print("NO")
  return 

main()

Measured memory_bytes: 19900
#include<stdio.h>
#define M 1000000000
int r,h[6000]={-M};
int main(){
  int ta[25]={0};
  int to[500],ne[500],co[500];
  int a,b,c,d,e,i,j,k,l,n,m,mi;
  scanf("%d %d",&n,&m);
  n++;
  for(i=1;i<=m*2;i++){
    scanf("%d,%d,%d,%d",&a,&b,&c,&d);
    ne[i]=ta[a];
    to[i]=b;
    co[i]=c;
    ta[a]=i++;
    ne[i]=ta[b];
    to[i]=a;
    co[i]=d;
    ta[b]=i;
  }
  scanf("%d,%d,%d,%d",&e,&b,&c,&d);
  c-=d;
  a=e;
  for(l=0;l<2;l++){
    int u[30];
    for(i=r=1;i<6000;i++)h[i]=M;
    for(i=0;i<n;i++)u[i]=M;
    h[u[a]=0]=-M;
    while(1){
      for(j=ta[a];j;j=ne[j]){
	if(u[to[j]]>u[a]+co[j]){
	  u[to[j]]=u[a]+co[j];
	  for(k=r++;h[k/2]>u[to[j]]*30+to[j];k/=2)h[k]=h[k/2];
	  h[k]=u[to[j]]*30+to[j];
	}
      }
      a=h[j=1]%30;
      d=h[--r];
      for(h[r]=M;d>h[j];j=mi){
	h[j]=h[mi=j*2];
	if(h[j]>h[j*2+1])h[j]=h[mi=j*2+1];
      }
      if(r==1)break;
      h[j/2]=d;
    }
    c-=u[b];
    a=b;
    b=e;
  }
  printf("%d\n",c);
  return 0;
}

Measured memory_bytes: 628
T = int(input())

def solve():
    def dist(x):
        if x == 0:
            return 0
        if x == 1:
            return D
        if x in dic:
            return dic[x]
        tmp = min(
            D * x,
            D * abs(x - x // 5 * 5) + C + dist(x // 5),
            D * abs(x - (x + 5 - 1) // 5 * 5) + C + dist((x + 5 - 1) // 5),
            D * abs(x - x // 3 * 3) + B + dist(x // 3),
            D * abs(x - (x + 3 - 1) // 3 * 3) + B + dist((x + 3 - 1) // 3),
            D * abs(x - x // 2 * 2) + A + dist(x // 2),
            D * abs(x - (x + 2 - 1) // 2 * 2) + A + dist((x + 2 - 1) // 2)
        )
        dic[x] = tmp
        return tmp

    N, A, B, C, D = map(int, input().split())
    
    dic = dict()
    print (dist(N))

for _ in range(T):
    solve()

Measured memory_bytes: 20100
n,a=map(int,input().split())
x=list(map(int,input().split()))
X=max(max(x),a)
dp=[[[0]*(X*n+1)for j in range(n+1)]for i in range(n+1)]
dp[0][0][0]=1
for i in range(1,n+1):
  xi=x[i-1]
  for j in range(i+1):
      for h in range(j*X+1):
        if h<xi:dp[i][j][h]=dp[i-1][j][h]
        if xi<=h and j>=1:dp[i][j][h]=dp[i-1][j][h]+dp[i-1][j-1][h-xi]
ans=0
for j in range(1,n+1):ans+=dp[n][j][j*a]
print(ans)

Measured memory_bytes: 62956
N, K = map(int, input().split())
h = []
for _ in range(N):
    h.append(int(input()))
h.sort()
mindiff = 10000000000
for i in range(len(h) - K + 1):
    mindiff = min(mindiff, h[i + K - 1] - h[i])
print(mindiff)


Measured memory_bytes: 7384
using System;
using System.Linq;
using System.Collections.Generic;

class Program
{
    static void Main()
    {
        var d = new Dictionary<string, int>(){{"SUN", 7},{"MON", 6},{"TUE", 5},{"WED", 4},{"THU", 3},{"FRI", 2},{"SAT", 1}};
        var s = Console.ReadLine();
        Console.WriteLine(d[s]);
    }
}

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

using namespace std;
typedef vector<int> vi;
typedef vector<char> vc;
double dp[110][110];
int main() {
	while (true) {
		for (int i = 0; i < 110; i++) {
			for (int j = 0; j < 110; j++) {
				dp[i][j] = 0;
			}
		}
		int n, l, t, b;
		cin >> n >> t >> l >> b;
		if (n == 0 && t == 0 && l == 0 && b == 0) {
			return 0;
		}
		vc A(n + 1, 'n');
		for (int i = 0; i < l; i++) {
			int L;
			cin >> L;
			A[L] = 'l';
		}
		for (int i = 0; i < b; i++) {
			int B;
			cin >> B;
			A[B] = 'b';
		}
		dp[0][0] = 1;
		for (int i = 0; i <= t; i++) {
			for (int j = n - 1; j >= 0; j--) {
				if (A[j] == 'n') {
					for (int k = 1; k <= 6; k++) {
						dp[i + 1][(j + k) <= n ? j + k : 2 * n - j - k] += dp[i][j] / 6;
					}
				}
				else if (A[j] == 'l') {
					for (int k = 1; k <= 6; k++) {
						dp[i + 2][(j + k) <= n ? j + k : 2 * n - j - k] += dp[i][j] / 6;
					}
				}
			}
			for (int j = 0; j <= n; j++) {
				if (A[j] == 'b') {
					dp[i + 1][0] += dp[i + 1][j];
				}
			}
		}
		double ans = 0;
		for (int i = 0; i <= t; i++) {
			ans += dp[i][n];
		}
		//for (int i = 0; i <= t; i++) {
		//	for (int j = 0; j <= n; j++) {
		//		cout << dp[i][j] << " ";
		//	}
		//	cout << endl;	
		//}
		cout << fixed<<ans << endl;
	}

}

Measured memory_bytes: 3260
e = list(input())
t = list(input())
password = ""
count_e = 0
count_t = 0
for i in range(len(e) + len(t)):
    if i % 2 == 0:
        password += e[count_e]
        count_e += 1
    else:
        password += t[count_t]
        count_t += 1
print(password)


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

int main(){
    int K;
    string S;

    cin >> K;
    cin >> S;

    if(S.length()>K){
        S.erase(S.begin()+K,S.begin()+S.length());
        cout << S << "..." << endl;
    }
    else cout << S << endl;

    return 0;
}

Measured memory_bytes: 3540
/**************
*	Shell Sort
*************/

#include <cstdio>
#include <vector>	//??£?¨?
#include <algorithm>
using namespace std;
typedef vector<int> TList;	//??????????????????

void insertionSort(TList& A, int g, int& cnt ){

	for(unsigned int i=g ; i<(A.size()); i++){
		int v = A[i];
		int j = i-g;
		while(j>=0 && A[j]>v){
			A[j+g] = A[j];
			j = j-g;
			cnt++;
		}
		A[j+g] =v;
	}
	return ;
}
//---------------------------------------------------------
void shellSort(TList& A, TList& G, int& cnt){

	for(unsigned int i=0; i<(G.size()); i++){
		insertionSort(A, G[i], cnt);
	}

	return;
}
//--<<???????????¢??°>>-------------------------------------------------------
int main(){

	//??????????¨????
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	//??\???
	int n;
	scanf("%d\n",&n);
//	cin >> n;
	vector<int> A;
	A.resize(n);
	for(unsigned int i=0; i< A.size(); i++){
	//	cin >> A[i];
		scanf("%d\n", &A[i]);
	}
	
	//??????
	TList G;
//	G.reserve(100);//????????????????´???°???????????£??????????????¨????????????
	int sum = 1;
	while(sum <= n){
	    G.push_back(sum);
		sum = sum * 3 + 1;
	}
	reverse(G.begin(), G.end());

	int cnt = 0;
	shellSort(A, G, cnt);

	//??????
//	cout << G.size() << endl;
	printf("%d\n", G.size());
	for(unsigned int i=0; i<(G.size()); i++){
		printf("%d", G[i]);
//		cout << G[i];
		if(i!=(G.size()-1)){
//			cout <<" " ;
			printf(" ");
		}
	}
//	cout << endl;
	printf("\n");
	printf("%d\n", cnt);
//	cout << cnt << endl;
	for(int i=0; i< n; i++){
//		cout << A[i]<< endl;
		printf("%d\n", A[i]);
	}
	return 0;
}
//-----------------------------------------------

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

#define FOR(i,s,e) for(ll (i)=(s);(i)<(e);(i)++)
typedef long long ll;

/* 2017/01/20 問題 -----  ABC047 C /Link http://abc047.contest.atcoder.jp/tasks/arc063_a */
/* -----解説等-----
問題: きつねの次郎と三郎が一次元リバーシで遊んでいます。
一次元リバーシでは、盤面には白か黒の石が一列に並んだ状態となっており、列の右端か左端に新たに石を打っていきます。
通常のリバーシと同じように、たとえば白の石を打つことで黒の石を挟むと、挟まれた黒の石は白い石に変わります。

ゲームの途中で三郎に急用ができて帰ってしまうことになりました。
このとき、盤面の状態は文字列 S で表されます。石は |S| (文字列の長さ) 個並んでおり、
左から i (1≦i≦|S|) 個目の石の色は、S の i 文字目が B のとき黒、W のとき白です。

次郎は現在の盤面に対して、できるだけ少ない個数の石を新たに打つことで全ての石を同じ色にしようと考えました。
最小で何個の石を打てばよいかを求めてください。


*/

string S;
stack<int>sta;
int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(false);


    cin >> S;
    sta.push(S[0]);
    FOR(i, 0, S.size()) {
        if (sta.top() != S[i]) {
            sta.push(S[i]);
        }
    }

    cout << sta.size()-1 << endl;

    return 0;
}

Measured memory_bytes: 720
#include <iostream>
#include <algorithm>
#include <string>

using namespace std;
inline int positive(int n) {
	return n < 0 ? 2000000000 : n;
}

int main() {
	int x, y;
	int c=0;
	cin >> x >> y;
	c = min({ positive(y - x),
		1 + positive(y + x),
		1 + positive(-y - x),
		2 + positive(x - y) });
	cout << c;
}

Measured memory_bytes: 256
import sys


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(20000000)

MOD = 10 ** 9 + 7
INF = float("inf")


def main():
    X = int(input())
    if X >= 30:
        print("Yes")
    else:
        print("No")


if __name__ == "__main__":
    main()


Measured memory_bytes: 9080
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cassert>
#include <climits>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <fstream>

using namespace std;
#define TOSTRING(x) #x
#define SZ(x) (int)(x).size()
#define REP(i, n) for (int i = 0; i < (n); i++)
#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define REPR(i, n) for (int i = (n)-1; i >= 0; i--)
#define ALL(s) (s).begin(), (s).end()
#define so(V) sort(ALL(V))
#define rev(V) reverse(ALL(V))
#define uni(v) v.erase(unique(ALL(v)), v.end());

typedef long long unsigned int llu;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<vb> vvb;
const double EPS = 1e-9;
const int MOD = 1e9 + 7;
const int INF = (1 << 28);
const ll LINF = 2e18;
const double PI = acos(-1);

int main()
{
	cin.tie(0);
	ios::sync_with_stdio(false);
	string S;
	cin >> S;
	int a = 0, b = 0;
	REP(i, SZ(S))
	{
		if (S[i] == '0')
			a++;
		else
			b++;
	}
	cout << min(a, b) * 2 << endl;
	return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
const long long MOD = 1000000007;
const long long INF = 9999999999999999;
using ll = long long;
int main(){
  string s;
  cin>>s;
  bool t = 0;
  for(int i = 0;i<s.size();i++){
    if(i%2 == 0){
      if(s.at(i) == 'L'){
        t = 1;
        break;
      }
    }
    else{
      if(s.at(i) == 'R'){
        t = 1;
        break;
      }
    }
  }
  if(t == 0){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <numeric>
#include <bitset>
using namespace std;


int main()
{
     int N;
     long long a;
     long long s=0;
     cin >> N;
     int bits [31] = {0};
     string binaries[N];
     for (int i=0; i<N; i++){
        cin >> a;
        binaries[i] = bitset<31>(a).to_string();
        for (int j=0; j<31; j++){
            bits[j] += binaries[i][j] - '0';
        }
    }
    for (int i=0; i<N; i++){
        for (int j=0; j<31; j++){
            if (!(binaries[i][j] - '0' == (bits[j] % 2))){
                int x = 1;
                for (int k=0; k<30-j; k++){
                    x *= 2;
                }
                s += x;
            }
        }
    cout << s << " ";
    s = 0;
    }
}


Measured memory_bytes: 19228
a,b,x = map(int,input().split())
import math

if( x*2 < a*a*b):
    tan_y = 2*x/(b*b*a)
    ans = 90 - math.degrees(math.atan(tan_y))

else:
    tan_x = 2*(a*a*b - x)/(a*a*a)
    ans = math.degrees(math.atan(tan_x))

print(ans)

Measured memory_bytes: 38384
//
// コッホ曲線
//
#include <cstdio>
#include <cmath>

struct Point {
    double x;
    double y;
};

void koch(int n, Point a, Point b) {
    if (n == 0) return;
    Point s, t, u;
    // 単位を度からラジアンへ変換 th: theta
    double th = M_PI * 60.0 / 180.0;

    // 三角形の頂点
    s.x = (2.0 * a.x + 1.0 * b.x) / 3.0;
    s.y = (2.0 * a.y + 1.0 * b.y) / 3.0;
    t.x = (1.0 * a.x + 2.0 * b.x) / 3.0;
    t.y = (1.0 * a.y + 2.0 * b.y) / 3.0;
    u.x = (t.x - s.x) * cos(th) - (t.y - s.y) * sin(th) + s.x;
    u.y = (t.x - s.x) * sin(th) + (t.y - s.y) * cos(th) + s.y;

    // aとsの間に作成する三角形の頂点
    koch(n - 1, a, s);
    printf("%.8f %.8f\n", s.x, s.y);
    // sとuの間に作成する三角形の頂点
    koch(n - 1, s, u);
    printf("%.8f %.8f\n", u.x, u.y);
    // uとtの間に作成する三角形の頂点
    koch(n - 1, u, t);
    printf("%.8f %.8f\n", t.x, t.y);
    // tとbの間に作成する三角形の頂点
    koch(n - 1, t, b);
}

int main()
{
    Point a, b;
    int n;

    scanf("%d", &n);

    // 初期状態の2点の座標 (0, 0), (100, 0)
    a.x = 0;
    a.y = 0;
    b.x = 100;
    b.y = 0;

    printf("%.8f %.8f\n", a.x, a.y);    // (0, 0)
    koch(n, a, b);                      // n=0ならば何もしない
    printf("%.8f %.8f\n", b.x, b.y);    // (100, 0)

    return (0);

}


Measured memory_bytes: 2684
import sys
input = sys.stdin.readline

n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
cnt = b[a[0] - 1]
for i in range(1, n):
    cnt += b[a[i] - 1]
    if a[i] == a[i - 1] + 1:
        cnt += c[a[i - 1] - 1]
print(cnt)


Measured memory_bytes: 3064
def factorize(a: int) -> dict:
    """素因数分解 O(sqrt(N))
    return 素因数のdict
    """
    ps = {}
    i = 2
    nokori = a
    while i*i <= nokori:
        if nokori % i == 0:
            cnt = 0
            while nokori % i == 0:
                cnt += 1
                nokori //= i
            ps[i] = cnt
        i += 1
    if nokori != 1:
        ps[nokori] = 1
    return ps


A, B = map(int, input().split())
factor_of_a = factorize(A).keys()
factor_of_b = factorize(B).keys()
ans = len(set(factor_of_a) & set(factor_of_b))
ans += 1  # 1も
print(ans)


Measured memory_bytes: 38512