akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <string>
#include <map>
#include <vector>
#include <array>
#include <algorithm>

using namespace std;

#define int long long

signed main()
{
    string a;
    string b;

    cin >> a >> b;

    std::sort(a.begin(), a.end());
    std::sort(b.rbegin(), b.rend());

    string ans = "No";
    bool flag = true;

    int i;
    for (i = 0; i < a.size() && i < b.size(); ++i)
    {
        if (a[i] == b[i])
        {
            continue;
        }
        if (a[i] < b[i])
        {
            ans = "Yes";
            break;
        }
        if (a[i] > b[i])
        {
            flag = false;
            break;
        }
    }

    //cout << a << " " << b << endl;

    if (ans == "No" && flag)
    {
        if (i == a.size() && a.size() < b.size())
        {

            ans = "Yes";
        }
    }

    cout << ans << endl;

    return 0;
}


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

const int MAXN = 1000;
int N;
const int MAXC = 50;
int C;
int cnt[3][MAXC];
int D[MAXC][MAXC];

int main() {
	cin >> N >> C;
	for (int i = 0; i < C; i++) {
		for (int j = 0; j < C; j++) {
			cin >> D[i][j];
		}
	}

	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			int v; cin >> v; v--;
			cnt[(i+j)%3][v] ++;
		}
	}

	int res = int(1.2e9);
	for (int a = 0; a < C; a++) {
		for (int b = 0; b < C; b++) {
			if (b == a) continue;
			for (int c = 0; c < C; c++) {
				if (c == b || c == a) continue;
				int v = 0;
				for (int x = 0; x < C; x++) {
					v += cnt[0][x] * D[x][a];
					v += cnt[1][x] * D[x][b];
					v += cnt[2][x] * D[x][c];
				}
				res = min(res, v);
			}
		}
	}
	cout << res << '\n';

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <cstdio>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cmath>
#include <functional>
#include <numeric>
#include <iomanip>
#define fi first
#define se second
#define fcout(n) cout<<fixed<<setprecision((n))
#define cinl(str) getline(cin,(str))
using namespace std;
bool value(int y,int x,int R,int C){return 0<=y&&y<R&&0<=x&&x<C;}
typedef pair<int,int> pii;
typedef long long ll;
typedef vector<int> vi;
typedef vector<long long > vll;
typedef vector< vi > vvi;
double pie=acos(-1);
int INF=1000000007;
int dx[4] = { 0,-1,0,1 };
int dy[4] = { -1,0,1,0 };


int main() {
	int n,a;
	cin>>n>>a;
	if(n%500 <= a) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}


Measured memory_bytes: 256
import java.io.*;
import java.nio.file.WatchEvent;
import java.util.PriorityQueue;
import java.util.Queue;

public class Main {
    private static int A, B, C;

    private static String solver(int a, int b, int c) {

        if (a == b && b == c) {
            return "Yes";
        } else {
            return "No";
        }
    }


    public static void main(String[] args) {

        InputStreamReader is = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(is);

        try {
            String[] inputArray = br.readLine().split(" ");
            A = Integer.parseInt(inputArray[0]);
            B = Integer.parseInt(inputArray[1]);
            C = Integer.parseInt(inputArray[2]);
        } catch (Exception e) {
            e.printStackTrace();
        }

        System.out.println(solver(A, B, C));

    }
}

Measured memory_bytes: 20436
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define o(a) cout << a << endl
#define int long long
#define first fi;
#define second se;
using namespace std;
typedef pair<int, int> P;

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

signed main(){
    int p, q;
    cin >> p >> q;
    q /= gcd(p, q);
    int ans = 1;
    for(int i = 2; i * i <= q; i++){
        if(q % i == 0) ans *= i;
        while(q % i == 0){
            q /= i;
        }
    }
    if(q != 1) ans *= q;
    cout << ans << endl;
}

Measured memory_bytes: 3104
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T
import Data.Bits (xor)

main :: IO ()
main = do
  [a, b] <- map unsafeTextToInt . T.words <$> T.getLine :: IO [Int]
  print $ f a b

f :: Int -> Int -> Int
f i j = g i `xor` g (succ j)
{-# INLINE f #-}

g :: Int -> Int
g i | r == 0    = 0
    | r == 1    = i `xor` 1
    | r == 2    = 1
    | otherwise = i
  where
    r = i `mod` 4
{-# INLINE g #-}

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 508
<?php
$N = (int)fgets(STDIN);
$A = explode(" ", fgets(STDIN));
$a = [0];
for ($i=0; $i < $N; $i++) {
    $a[$i+1] = (int)$A[$i];
}
$a[] = 0;

$sum = 0;
for ($i=0; $i <= $N; $i++) {
    $sum += abs($a[$i] - $a[$i+1]);
}

for ($i=1; $i <= $N; $i++) {
    echo $sum - abs($a[$i] - $a[$i-1]) - abs($a[$i] - $a[$i+1]) + abs($a[$i-1] - $a[$i+1]);
    echo "\n";
}
//print_r($a);
//print $sum;


Measured memory_bytes: 18932
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)

const ll MOD = (ll)1e9 + 7;
const ll HIGHINF = (ll)1e18;

int main() {
  ll n, m; cin >> n >> m;
  vvll nodes(n, vll());
  vll h(n, 0);
  REP(i, n+m-1) {
    ll a, b; cin >> a >> b;
    nodes.at(a-1).push_back(b-1);
    h.at(b-1)++;
  }

  queue<ll> q;
  vll par(n, -1);
  REP(i, n) if (h.at(i)==0) {
    q.push(i);  // 根は1個だけだけど
    par.at(i) = 0;
  }

  while(!q.empty()) {
    ll i = q.front(); q.pop();
    REP(j, nodes.at(i).size()) {
      ll to = nodes.at(i).at(j);
      h.at(to)--;
      if (h.at(to) == 0) {
        q.push(to);
        par.at(to) = i + 1;
      }
    }
  }

  REP(i, n) {
    cout << par.at(i) << endl;
  }
  return 0;
}


Measured memory_bytes: 7808
#include <string>
#include <queue>
#include <stack>
#include <vector>
#include <sstream>
#include <algorithm>
#include <deque>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <list>
#include <cstdio>
#include <iostream>
#include <cmath>
#include <climits>
#include <bitset>
#include <functional>
#include <numeric>
#include <ctime>
#include <cassert>
#include <cstring>
#include <fstream>

#define FOR(i, a, b) for(int (i)=(a); (i)<(b); (i)++)
#define IFOR(i, a, b) for(int (i)=(a);(i)<=(b);(i)++)
#define RFOR(i, a, b) for(int (i)=(a);(i)>=(b);(i)--)

using namespace std;

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

    int res=0;
    if (x == y) {
        res = 0;
    }
    else if (x == 0 && y != 0) {
        if (y > 0) {
            res = y - x;
        }
        else {
            res = x - y + 1;
        }
    }
    else if (x != 0 && y == 0) {
        if (x > 0) {
            res = x + 1;
        }
        else {
            res = y - x;
        }
    }


    else  if (x >= 0 && y >= 0) {
        if (x <= y) {
            res = y - x;
        }
        else {
            res = x - y + 2;
        }
    }
    else if (x < 0 && y >= 0) {
        if (abs(x) <= y) {
            res = 1 + y - abs(x);
        }
        else {
            res = 1 + abs(x) - y;
        }
    }
    else if (x >= 0 && y < 0) {
        if (x >= abs(y)) {
            res = 1 + x - abs(y);
        }
        else {
            res = abs(y) - x + 1;
        }
    }
    else {
        if (abs(x) >= abs(y)) {
            res = abs(x) - abs(y);
        }
        else {
            res = 2 + abs(y) - abs(x);
        }

    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
int main(){
	string S;
	cin>>S;
	int a=S.size()/2;
	int b=(S.size()+1)/2;
	int c=0;
	int d=0;
	REP(i,S.size()){
	    if(S[i]=='p')c++;
	    if(S[i]=='q')d++;
	}
        cout<<a-c<<endl;
	return(0);
}

Measured memory_bytes: 512
#include<stdio.h>
int main() {
  int n, s=0;
  scanf("%d", &n);
  char c[n+1];
  scanf("%s", &c);

  int i, j=0;
  for(i=0; i<n;){
//    if(j==n-1) break;
	for(j=i+1; j<n; j++){
      if(c[i]==c[j]){
        if(j==n) s++; break;
      }
      else{
        s++; i=j; break;        
      }
    }
    i=j;
  }
  printf("%d", s+1);
  return 0;
}

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

int main() {
  
  string S;
  cin >> S;
  
  if( S.at(2) == S.at(3) && S.at(4) == S.at(5)){
    cout << "Yes";
  }
    
    else{
      cout << "No";
    }
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,m,q = map(int,input().split())
chk = []
for i in range(q):
  a = [int(i) for i in input().split()]
  chk.append(a)

ans = 0
import itertools
for i in itertools.combinations_with_replacement(range(1, m+1), n):
  dd = 0
  for j in chk:
    a,b,c,d = j
    if i[a-1] + c == i[b-1]:
      dd += d
  ans = max(dd,ans)
print(ans)

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

public class Hello
{
    public static void Main()
    {
        string s;
        string[] str;

        while((s = Console.ReadLine() ) != null)
        {
            str = s.Split(' ');
            int x = int.Parse(str[0]);
            int y = int.Parse(str[2]);
            char c = Convert.ToChar(str[1]);

            if (c == '?') break;

            switch (c)
            {
                case '+':
                    Console.WriteLine(x + y);
                    break;
                case '-':
                    Console.WriteLine(x - y);
                    break;
                case '*':
                    Console.WriteLine(x * y);
                    break;
                case '/':
                    Console.WriteLine(x / y);
                    break;
            }
        }
    }
}

Measured memory_bytes: 9212
#include<bits/stdc++.h>
using namespace std;
int TEST=0,CASE=1;
#define         pf              printf
#define         si(x)           scanf("%d",&x)
#define         si2(x,y)        scanf("%d %d",&x,&y)
#define         si3(x,y,z)      scanf("%d %d %d",&x,&y,&z)
#define         sl(x)           scanf("%lld",&x)
#define         sl2(x,y)        scanf("%lld %lld",&x,&y)
#define         sl3(x,y,z)      scanf("%lld %lld %lld",&x,&y,&z)
#define         sd(x)           scanf("%lf ",&x)
#define         pb(x)           push_back(x)
#define         mp(x,y)         make_pair(x,y)
#define         clr(x,y)        memset(x,y,sizeof(x))
#define         all(x)          x.begin(),x.end()
#define         MX              401000
#define         left            (indx<<1)
#define         right           left+1
#define         mid             ((l+r)>>1)
#define         call            left,l,mid
#define         lnd             tree[left]
#define         calr            right,mid+1,r
#define         rnd             tree[right]
#define         cnd             tree[indx]
#define         speed           (ios::sync_with_stdio(false),cin.tie(0))
#define         fpoint(x)       (cout.precision(x),cout<<fixed)
#define         FOR(i,n)       	for(int i=1;i<=n;++i)
#define         FOR0(i,n)      	for(int i=0;i<n;++i)
#define		dx		xx+dirx[i]
#define		dy		yy+diry[i]
long long int         mod  =    1000000007LL;
const long double     pi   =    2.0*acos(0.0);
typedef long long int ll;
typedef long double ld;
int dirx[9]={0,0,0,-1,+1,+1,+1,-1,-1};
int diry[9]={0,-1,+1,0,0,-1,+1,-1,+1};
struct vpair{
        int a,b;
        vpair(int a,int b){this->a=a,this->b=b;}
};
bool cmp(int &a,int &b){
        return a<b;                ///ascending order
        return a>b;                ///descending order
}
int n,m,a,b,c,d,k,x,y,z,ans=0,total=0;
int arr[300001];
string s;
vector<int> v;
int main(void){
	cin>>a>>b>>k;
	v.pb(0);
	for(int i=1;i<=min(a,b);i++){
		if(a%i==0 && b%i==0)v.pb(i);
	}
	cout<<v[v.size()-k]<<endl;
        return 0;
}

/**
"G:\Work Station\OnlineJudge\Atcoder\B.cpp"
**/


Measured memory_bytes: 256
import numpy as np
n = int(input())
l = [[int(i) for i in input().split()] for _ in range(n)]

distance = 0
for i in l:
    for j in l:
        distance += np.sqrt((i[0] - j[0])**2 + (i[1] - j[1])**2)
        
print(distance/n)

Measured memory_bytes: 12408
#include <iostream>

using namespace std;

int main() {
  int a,b;
  cin >> a >> b;
  for (int i = 1; i <= 3; i++) {
    if ((a * b * i) % 2 == 1) {
      cout << "Yes" << endl;
      return 0;
    }
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 256
# include <bits/stdc++.h>
using namespace std;
 
int main()
{
	string b;
	string a;
	cin >> b;
	if ( b == "A")
	{
		a = "T";
	}
	else if (b == "T")
	{
		a = "A";
	}
	else if (b == "G")
	{
		a = "C";
	}
	else if (b == "C")
	{
		a = "G";
	}
	cout << a << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;


signed main() {
  int N, K; 
  cin >> N >> K;

  vector<int> A(N+1, 0);
  REP(i, N) cin >> A[i+1];
  REP(i, N) A[i+1] += A[i];

  REP(i, N+1){
    A[i] = (A[i]-i)%K;
  }

  int ans = 0;
  map<int, int> m;
  REP(i, N+1){
    ans += m[A[i]]++;
    if(i-K+1 >= 0) m[A[i-K+1]]--;
  }

  cout << ans << "\n";

  return 0;
}

Measured memory_bytes: 14336
#include <iostream>
#include <cstdio>

using namespace std;

int main()
{
  int n, c = 1;
  while (scanf(" %d ", &n) == 1) {
    if (n == 0) {break;}
    int x, y, px, py;
    double S = 0.0;
    scanf("%d %d ", &px, &py);
    int x0 = px, y0 = py;
    for (int i = 1; i < n; i++) {      
      scanf("%d %d ", &x, &y);      
      S +=  (py + y) * (x - px);
      px = x, py = y;
    }
    S += (y + y0) * (x0 - x);
    printf("%d %.1lf\n", c++, S / 2);
  }
  return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, k;
  cin >> n >> k;
  vector <int> v(n + 1, 0);
  for (int i = 1; i <= n; i++) {
	  cin >> v[i];
	}
  int ans = -1e9;
  for (int i = 0; i < n; i++) {
	  for (int j = i + 1; j <= n + 1; j++) {
		  if (i + n - j + 1 > k) {
			  continue;
			}
		  int rem = k - (i + n - j + 1);
		  vector <int> v2;
		  for (int a = 1; a <= i; a++) {
			  v2.push_back(v[a]);
			}
		  for (int b = n; b >= j; b--) {
			  v2.push_back(v[b]);
			}
		  sort(v2.begin(), v2.end());
		  int sc = 0;
		  for (auto itr = v2.begin(); itr != v2.end(); itr++) {
			  if (rem > 0 && (*itr) < 0) {
				  rem--;
				  continue;
				}
			  sc += *itr;
			}
		  ans = max(sc, ans);
		}
	}
  cout << ans << endl;
  return 0;
}


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

const long long INF = 1000000000;

typedef long long ll;

#define writeln(n) cout<<n<<"\n"
#define rep(i,n) for(int i=0; i<(n); ++i)

typedef pair<int, int> P;
typedef pair<string, int> Psi;



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

	int n; cin>>n;

	ll sum=0;
	rep(i,n+1){
		sum +=i;

		if(sum >=n){
			writeln(i);
			return 0;
		}
	}
}


Measured memory_bytes: 256
def ipt(N=0,switch=0):
    if N == 0:
        return list(map(int,input().split()))
    else:
        if switch==0:
            return [list(map(int,input().split())) for _ in range(N)]
        else:
            return [int(input()) for _ in range(N)]

a,b=ipt()
s=input()

flag=0
for i in range(a):
    if s[i] == "-":
        flag=1
        break

if s[a] != "-":
    flag=1
        
for i in range(a+1,a+b+1):
    if s[i] == "-":
        flag=1
        break
if flag==0:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
// マクロ
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
// 型エイリアス
using ll = long long;
using vi = vector<int>;
using vs = vector<string>;
using vvi = vector<vi>;
using vvs = vector<vs>;

int main() {
    string s, t;
    cin >> s >> t;
    int rot = s.size();
    bool flag = false;
    if(s == t) flag = true;
    for(int i = 1; i < rot; i++) {
        string newstr = s.substr(rot - i, i) + s.substr(0, rot - i);
        if(t == newstr) {
            flag = true;
            break;
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 764
#include <stdio.h>
int main(){
    int n,m;
    int a,b[100001],ans=0;
    int i,k;
    scanf("%d%d",&n,&m);
    for(i=0;i<n;i++){
        scanf("%d",&k);
        while(k--){
            scanf("%d",&a);
            b[a]++;
        }
    }
    for(i=1;i<=m;i++)if(b[i]==n)ans++;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<cstring>
#include<cstdio>
#include<algorithm>
using namespace  std;
int pos[500010],n,m;
int main()
{
    scanf("%d",&n);
    for (int i=1;i<=n;i++)
    {
        scanf("%d",&m);
        pos[m]=i;
    }
    int len=1,ans=5000000;
    for (int i=1;i<n;i++)
    {
        if (pos[i+1]>pos[i]) len++;
        else
        {
            ans=min(ans,n-len);
            len=1;
        }
    }
    ans=min(ans,n-len);
    printf("%d\n",ans);
}


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

int main() {
  int n;
  cin >> n;
  int ans = 0;
  for (int i=n; i>0; i--){
    if ((to_string(i).length())%2==1) ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,n) for(int i=0;i<(int)(n);i++)
#define FORR(i,m,n) for(int i=(int)(m);i<(int)(n);i++)
#define pb(a) push_back(a)
#define ZERO(a) memset(a,0,sizeof(a))
#define len(a) sizeof(a)
#define ll long long
#define INF 1<<29
#define MAX 4002
using namespace std;

int dp[MAX][MAX];

void solve(){
 string s,t;
 while(cin>>s>>t){
  ZERO(dp);
  FOR(i,s.size()){
   FOR(j,t.size()){
    if(s[i]==t[j]){
     dp[i+1][j+1]=max(dp[i+1][j+1],dp[i][j]+1);
    }
   }
  }
  int ma=0;
  FOR(i,s.size()+1){
   FOR(j,t.size()+1){
    ma=max(ma,dp[i][j]);
   }
  }
  printf("%d\n",ma);
 }
}

int main(){
 solve();
 return 0;
}

Measured memory_bytes: 63772
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <unordered_set>
#include <vector>

using namespace std;
using LLONG = long long;
const LLONG MOD = 1000000007;

int main()
{
	int N, M, K; cin >> N >> M >> K;
	// O(NM) <= O(1e6)
	for (int r = 0; r <= N; ++r)
	{
		for (int c = 0; c <= M; ++c)
		{
			int blackNum = r * (M - c) + (N - r) * c;
			if (blackNum == K)
			{
				cout << "Yes" << endl;
				return 0;
			}
		}
	}
	cout << "No" << endl;
}

Measured memory_bytes: 3552
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

const mod = 1000000007

func main() {
	sc.Split(bufio.ScanWords)
	sc.Buffer([]byte{}, 1000000)
	N := getInt()
	s := getString()
	a := make([]int, N*2)
	if s[0] == 'W' || s[len(s)-1] == 'W' {
		out(0)
		return
	}
	L := 1
	R := 0
	for i := 1; i < len(s); i++ {
		if s[i] != s[i-1] {
			a[i] = a[i-1]
			if a[i] == 1 {
				R++
			} else {
				L++
			}
		} else {
			if a[i-1] == 1 {
				a[i] = 0
				L++
			} else {
				a[i] = 1
				R++
			}
		}
	}
	// out(a)
	// out(L, R)
	if L != R {
		out(0)
		return
	}
	cnt := 0
	ans := 1
	for i := 0; i < len(s); i++ {
		if a[i] == 0 {
			cnt++
		} else {
			ans *= cnt
			ans %= mod
			cnt--
		}
	}
	for i := 1; i <= N; i++ {
		ans *= i
		ans %= mod
	}
	out(ans)
}


Measured memory_bytes: 2944
import java.util.Scanner;

class Main {

    public static void main(String[] args) {
        Scanner scan = new Scanner(System.in);
        int W = scan.nextInt();
        int H = scan.nextInt();
        int x = scan.nextInt();
        int y = scan.nextInt();
        int r = scan.nextInt();

        if (W >= x + r && 0 <= x - r && H >= y + r && 0 <= y - r) {
            System.out.println("Yes");

        } else {
            System.out.println("No");
        }
    }
}



Measured memory_bytes: 26256
#include<bits/stdc++.h>
using namespace std;
#define ll long long 
#define ld long double
int main(){
	/*
	#ifndef ONLINE_JUDGE
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);
	#endif
	*/
	ios_base::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	string s;
	cin>>s;
	map<char,int> m;
	for(int i=0;i<4;i++){
		m[s[i]]++;
	}
	if(m.size()==2){
		for(auto x : m){
			if(x.second != 2){
				cout<<"No"; return 0;
			}
		}
		cout<<"Yes";
		return 0;
	}
	cout<<"No";
}

Measured memory_bytes: 256
def insertion_sort(A):
    for i in range(1, len(A)):
        print(A)
        v = A[i]
        j = i - 1
        while (j >= 0) and A[j] > v:
            A[j+1] = A[j]
            j -= 1
        A[j+1] = v
    return A


def bubble_sort(A):
    cnt = 0
    flag = True
    while flag:
        flag = False
        for i in sorted(range(1, len(A)), reverse=True):
            if A[i] < A[i - 1]:
                cnt += 1
                tmp = A[i]
                A[i] = A[i - 1]
                A[i - 1] = tmp
                flag = True
    return A, cnt


def selection_sort(A):
    for i in range(len(A)):
        minj = i
        for j in range(i, len(A)):
            if A[j] < A[minj]:
                minj = j
        tmp = A[i]
        A[i] = A[minj]
        A[minj] = tmp
    return A


def insertion_sort_for_shell(A, g):
    cnt = 0
    for i in range(g, len(A)):
        v = A[i]
        j = i - g
        while (j >= 0) and (A[j] > v):
            A[j + g] = A[j]
            j -= g
            cnt += 1
        A[j + g] = v
    return A, cnt

def shell_sort(A):
    cnt = 0
    G = []
    g = 1
    while True:
        G.append(g)
        g = g *3 + 1
        if g > len(A):
            break
    G = sorted(G, reverse=True)
    for g in G:
        A, c = insertion_sort_for_shell(A, g)
        cnt += c
    return A, G, cnt


def print_shell_sort_result(A, G, cnt):
    print(len(G))
    print(' '.join(map(str, G)))
    print(cnt)
    [print(a) for a in A]

if __name__ == '__main__':
    N = int(input())
    A = [0] * N
    for i in range(N):
        A[i] = int(input())
    print_shell_sort_result(*shell_sort(A))

Measured memory_bytes: 53212
import java.util.*;
public class Main
{
	public static void main(String[] args)
	{
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] arr = new int[n];
		for(int i = 0;i<n;i++)
		{
			arr[i] = 0;
		}
		for(int i = 0;i<n-1;i++)
		{
			int input = sc.nextInt()-1;
			arr[input]++;
		}
		for(int i = 0;i<n;i++)
		{
			System.out.println(arr[i]);
		}
	}
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;A++)
#define mp make_pair
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll Sn;
char S[111];
ll i, j, k,ans;
int main(){
    scanf("%s", S);
    Sn = strlen(S);
    fornum (i,0, Sn){
        if(S[i]!=S[Sn-1-i]){
            S[Sn - 1 - i] = S[i];
            ans++;
        }
    }
    printf("%lld", ans);
    return 0;
}

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

using namespace std;

int main(){
  std::map<long long,long long> mp;
  long long n,i,q,b,c,s=0;
  long long a[524288];
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&a[i]);
    s+=a[i];
    mp[a[i]]++;
  }
  scanf("%lld",&q);
  for(i=0;i<q;i++){
    scanf("%lld%lld",&b,&c);
    s-=b*mp[b];s+=c*mp[b];
    mp[c]+=mp[b];mp[b]=0;
    printf("%lld\n",s);
  }
  return 0;
}

Measured memory_bytes: 10488
S=list(input())
N=len(S)
ans = 0
for b in range(2**(N-1)):
  bit = list(str(bin(b))[2:].zfill(N-1).replace('0','_').replace('1','+'))
  f = S[0]
  for bi, si in zip(bit, S[1:]):
    f += str(bi) + str(si)
  ans += eval(f.replace('_', ''))
print(ans)

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

int main(){
  string s; cin>>s;
  string base="abcdefghijklmnopqrstuvwxyz";
  vector<bool> flag(26,true);
  for(int i=0;i<s.size();i++){
    flag[s[i]-'a']=false;
  }
  if(s=="zyxwvutsrqponmlkjihgfedcba"){
     cout<<-1<<endl;
     return 0;
  }
  if(s.size()!=26){
    cout<<s;
    for(int i=0;i<26;i++){
      if(flag[i]){
        cout<<base[i]<<endl;
        return 0;
      }
    }
  }else{
    for(int i=25;i>0;i--){
      if(s[i]>s[i-1]){
        flag[s[i]-'a']=true;
        cout<<s.substr(0,i-1);
        for(int j=s[i-1]-'a'+1;j<26;j++){
          if(flag[j]){
            cout<<base[j]<<endl;
            return 0;
          }
        }
      }else{
        flag[s[i]-'a']=true;
      }
    }
  }
}

Measured memory_bytes: 256
let c = [|'0'; '1'|]
let () =
  Scanf.scanf "%s" @@ fun s ->
  let n = String.length s in
  let s = Array.init n (fun i -> i, s.[i]) in
  Array.fold_left (fun (p, q) (i, x) -> if x = c.(i mod 2) then (p+1, q) else (p, q+1)) (0, 0) s
  |> fun (p, q) -> Printf.printf "%d\n" (min p q)



Measured memory_bytes: 7040
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<string.h>
#include<queue>
using namespace std;
typedef pair<int,int>P;

int main(){
    int k,x;cin>>k>>x;
    int left=max(-1000000,x-k+1);
    int right=min(1000000,x+k-1);
    for(int i=left;i<=right;i++){
        cout<<i<<' ';
    }
    cout<<endl;
    return 0;
}


Measured memory_bytes: 256
using System;

namespace SortThreeNum
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] str = Console.ReadLine().Split(' ');
            int[] num = new int[3];
            num[0] = int.Parse(str[0]);
            num[1] = int.Parse(str[1]);
            num[2] = int.Parse(str[2]);
            
            Array.Sort(num);

            Console.WriteLine("{0} {1} {2}", num[0], num[1], num[2]);


        }
    }
}

Measured memory_bytes: 5764
n = int(input())
l = list(map(int, input().split()))
l.sort()

def check(x, a):
    if a < x:
        return True
    else:
        return False

def bin_search(x, ok, ng, l):
    while ng - ok > 1:
        mid = (ng + ok) // 2
        if check(x, l[mid]):
            ok = mid
        else:
            ng = mid
    return ok + 1

ans = 0
for i in range(n - 2):
    for j in range(i + 1, n - 1):
        ans += bin_search(l[i] + l[j], -1, n - j - 1, l[j + 1:])
print(ans)

Measured memory_bytes: 52828
_ = readLine()!
var a = readLine()!.split(separator: " ").compactMap { Int($0) }

let minusCount = a.lazy.filter { $0 < 0 }.count

if minusCount % 2 == 0 {
    print(a.lazy.map(abs).reduce(0, +))
} else {
    let sorted = a.lazy.map(abs).sorted()
    let head = sorted.first!
    let tail = sorted.lazy.dropFirst()
    print(tail.reduce(-head, +))
}


Measured memory_bytes: 14408
#include <bits/stdc++.h>
typedef long long LL;
#define SORT(c) sort((c).begin(),(c).end())

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

using namespace std;
double dd(double a) {return a*a;}
int main(void)
{
  for(;;){
    int n;
    cin >> n;
    if(!n) return 0;
    vector<double> x,y,z,r;
    x.resize(n);
    y.resize(n);
    z.resize(n);
    r.resize(n);
    REP(i,n) cin >> x[i] >> y[i] >> z[i] >> r[i];
    vector<vector<double> > dist;
    dist.resize(n);
    REP(i,n) dist[i].resize(n);
    REP(i,n) REP(j,n) dist[i][j]=max(0.0,sqrt(dd(x[i]-x[j])+dd(y[i]-y[j])+dd(z[i]-z[j]))-r[i]-r[j]);
    priority_queue<pair<double,int> > prim;
    // negc,next
    prim.push(make_pair(0.0,0));
    set<int> already;
    double answer=0.0;
    while(!prim.empty()){
      double negc=prim.top().first;
      int tmp=prim.top().second;
      prim.pop();
      if(!already.insert(tmp).second) continue;
      answer-=negc;
      REP(j,n) prim.push(make_pair(-dist[tmp][j],j));
    }
    cout << fixed << setprecision(3) << answer << endl;
  }
}

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

using namespace std;
int main() {
    string s ,ans="";
    cin>>s;
    if(s=="Sunny")ans="Cloudy";
    if(s=="Cloudy")ans="Rainy";
    if(s=="Rainy")ans="Sunny";
    cout<<ans<<endl;
    return 0;
}


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

using namespace std;

#define fRead(x)        freopen(x,"r",stdin)
#define fWrite(x)       freopen (x,"w",stdout)

#define LL              long long
#define ULL             unsigned long long
#define ff              first
#define ss              second
#define pb              push_back
#define INF             5e13
#define PI              acos(-1.0)
#define mk              make_pair
#define pii             pair<int,int>
#define pll             pair<LL,LL>
#define all(a)          a.begin(),a.end()
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(a,min(b,min(c,d)))
#define max4(a,b,c,d)   max(a,max(b,max(c,d)))
#define SQR(a)          ((a)*(a))
#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define MEM(a,x)        memset(a,x,sizeof(a))
#define ABS(x)          ((x)<0?-(x):(x))

#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(nullptr);

int main()
{
   LL a,b,c;
   while(cin >> a >> b >> c)
   {
       if(a % 2 == 0 or b % 2 ==0 or c % 2==0){
         cout << 0 << "\n";
         continue;
       }
       LL ans = min3(b*c,a*b,a*c);
       cout << ans << "\n";

   }


}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
 
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy

const ll identity = 0;
const ll SZ = 131072*2;

ll sum[2*SZ], lazy[2*SZ];

ll combine(ll A, ll B) {
    return A+B;
}

ll combineUpd(ll A, ll B) {
    return A+B;
}

void push(int index, ll L, ll R) {
    sum[index] = combineUpd(sum[index], lazy[index]);
    if (L != R) lazy[2*index] = combineUpd(lazy[2*index], lazy[index]), lazy[2*index+1] = combineUpd(lazy[2*index+1], lazy[index]);
    lazy[index] = identity;
}

void pull(int index) {
    sum[index] = combine(sum[2*index], sum[2*index+1]);
}

ll query(int lo, int hi, int index = 1, ll L = 0, ll R = SZ-1) {
    push(index, L, R);
    if (lo > R || L > hi) return 0;
    if (lo <= L && R <= hi) return sum[index];

    int M = (L+R) / 2;
    return combine(query(lo, hi, 2*index, L, M), query(lo, hi, 2*index+1, M+1, R));
}

void update(int lo, int hi, ll increase, int index = 1, ll L = 0, ll R = SZ-1) {
    push(index, L, R);
    if (hi < L || R < lo) return;
    if (lo <= L && R <= hi) {
        lazy[index] = increase;
        push(index, L, R);
        return;
    }

    int M = (L+R) / 2;
    update(lo, hi, increase, 2*index, L, M); update(lo, hi, increase, 2*index+1, M+1, R);
    pull(index);
}
int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);    
	
    int N; cin >> N;
    ll D; cin >> D;
    ll A; cin >> A;
    vpl data(N);
    F0R(i, N) {
        ll A, B; cin >> A >> B; data[i] = {A, B};
    }
    F0R(i, 2*SZ) {
        sum[i] = 0; lazy[i] = 0;
    }

    sort(all(data));
    map<ll, ll> coords; F0R(i, N) coords.insert({data[i].f, i});

    F0R(i, N) {
        update(i, i, data[i].s);
    }
    ll ans = 0;
    F0R(i, N) {
        if (query(i, i) <= 0) continue;
        ll cur = (query(i, i) + A - 1) / A;
        ans += cur;
        ll maxBound = (--coords.ub(data[i].f+2*D))->s;
        update(i, maxBound, -1*cur*A);
    }

    cout << ans << endl;
	
	return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343



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

typedef double ld;
ld pi = acos(-1);
void solved(){
	double a,b,c,d;cin>>a>>b>>c>>d;
	double ang1 = (c * 60.0 + d) / 720.0 * 2 *pi;
	double ang2 = d / 60.0 * 2 * pi;
	double ans = fabs(ang1 - ang2);
	printf("%.9lf\n",sqrt(a*a+b*b-2*a*b*cos(ans)));
}
int main(){
	solved();
	return 0;
}

Measured memory_bytes: 4192
n = gets.to_i
name = gets.chomp
boards = []
n.times { boards << gets.chomp }

ans = 0
boards.each do |board|
  w = 0
  # p board
  catch :a do
    loop do
      board.chars.each_with_index do |c, c_i|
        break if c_i + name.size + w * (name.size - 1) > board.size

        match = true
        name.chars.each_with_index do |ch, ch_i|
          nxt = board[c_i + (w+1) * ch_i]
          # puts [c_i, ch_i, c_i + (w+1) * ch_i].to_s
          unless nxt == ch
            match = false
            break
          end
        end

        if match
          ans += 1
          # puts "found ans"
          throw :a
        end
      end
      w += 1
      break if name.size + w * (name.size - 1) >= board.size
    end
  end
end

puts ans

Measured memory_bytes: 8832
#include <bits/stdc++.h>
#include <numeric>
#include <iomanip>

using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
typedef long long ll;
#define INF 1e9


int x[8], y[8];

double calc_distance(int i, int j){
    return pow(pow(x[i]-x[j],2)+pow(y[i]-y[j], 2), 0.5);
}

int factorial(int n){
    if(n == 1){
        return 1;
    }
    return n*factorial(n-1);
}


int main(){
    int n; cin >> n;
   
    rep(i,n) {
        int a,b; cin >> a >> b;
        x[i] = a; y[i] = b;
    }
    vector<int> v(n);
    rep(i,n){
        v[i] = i;
    }
    
    double ans;
    double temp = 0;
    do {
        rep(i,n-1){
            temp += calc_distance(v[i], v[i+1]);
            
        }
        
    } while (next_permutation(v.begin(), v.end()));
    
    ans = temp/factorial(n);
  
    cout << fixed << setprecision(10) << ans << endl;
}


Measured memory_bytes: 256
#include<cstdio>
const int N=105;
int n,i,dn,d[3],an,a[N];
int read(){
	char c=getchar();int k=0;for (;c<48||c>57;c=getchar());
	for (;c>47&&c<58;c=getchar()) k=(k<<3)+(k<<1)+c-48;return k;
}
void write(int x){if (x>9) write(x/10);putchar(x%10+48);}
int main(){
	read();n=read();
	for (i=1;i<=n;i++){
		int x=read();
		if (x&1){
			d[++dn]=x;
			if (dn>2){
				puts("Impossible");
				return 0;
			}
		}
		else a[++an]=x;
	}
	int lt=1;
	if (dn) a[lt=0]=d[1];
	if (dn==2) a[++an]=d[2];
	for (i=lt;i<=an;i++)
		write(a[i]),putchar(' ');
	putchar('\n');
	if (n==1) an++;
	a[lt]--;a[an]++;
	write(a[0]>0?an+1:an);putchar('\n');
	for (i=a[0]>0?0:1;i<=an;i++)
		write(a[i]),putchar(' ');
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
 
/// Typedef
typedef long long           ll;
typedef unsigned long       ul;
typedef unsigned long long  ull;
typedef vector<int>         vi;
typedef vector<vi>          vvi;
typedef vector<ll>          vll;
typedef pair<int,int>       pii;
typedef pair<ll,ll>         pll;
 
#define pb                  push_back
#define ppb                 pop_back
#define MP                  make_pair
#define ff                  first
#define ss                  second
#define sf                  scanf
#define pf                  printf
#define SQR(x)              ((x)*(x))
#define loop(i, y)          for(int i=0; i<int(y); i++)
#define FOR(i, x, y)        for(int i=int(x); i<int(y); i++)
#define ROF(i, x, y)        for(int i=int(x); i>=int(y); i--)
#define all(c)              c.begin(), c.end()
#define sz(c)               int(c.size())
#define clr(x, y)           memset(x, y, sizeof(x))
#define si(x)               scanf("%d", &x)
#define sii(x, y)           scanf("%d %d", &x, &y)
#define siii(x, y, z)       scanf("%d %d %d", &x, &y, &z)
#define sl(x)               scanf("%lld", &x)
#define sll(x, y)           scanf("%lld %lld", &x, &y)
#define slll(x, y, z)       scanf("%lld %lld %lld", &x, &y, &z)
#ifdef VAMP
     #define dbg(...) __f(#__VA_ARGS__, __VA_ARGS__)
    template < typename Arg1 >
    void __f(const char* name, Arg1&& arg1){
        cout << name << " = " << arg1 << std::endl;
    }
    template < typename Arg1, typename... Args>
    void __f(const char* names, Arg1&& arg1, Args&&... args){
        const char* comma = strchr(names+1, ',');
        cout.write(names, comma - names) << " = " << arg1 <<" | ";
        __f(comma+1, args...);
    }
#else
    #define dbg(...)
#endif
/// Constants
#define N                   111
#define MOD                 1000000007
#define base                1000000007
#define eps                 1e-9
#define INF                 1llu<<61    // 2,305,843,009,213,693,952
#define inf                 (ll)1e18     // 536,870,912
#define PI                  acos(-1.0)  // 3.1415926535897932
// #define INF              0x3f3f3f3f3f3f3f3f
// #define inf              0x3f3f3f3f
#define U  0
#define L  1
#define D  2
#define R  3

int main(){
    #ifdef VAMP
        clock_t tStart = clock();
        freopen("C:\\Users\\raiha.DESKTOP-5M3GJRN\\Videos\\Raihan\\input.txt", "r", stdin);
        freopen("C:\\Users\\raiha.DESKTOP-5M3GJRN\\Videos\\Raihan\\output.txt", "w", stdout);
    #endif
    int r;
    si(r);
    cout<<r*r<<endl;
    #ifdef VAMP
       printf("\n>>Runtime: %.10fs\n", (double) (clock() - tStart) / CLOCKS_PER_SEC);
    #endif
    return 0;
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 10.01.2020 23:11:35       
**/
#include <bits/stdc++.h>

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> a(3 * n);
  for (int i = 0; i < 3 * n; i++) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  long long s = 0;
  for (int i = 3 * n - 2; i >= n; i -= 2) {
    s += a[i];
  }
  cout << s << '\n';
  return 0;
}


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0; i<n; i++)
#define rep1(i, n) for(int i=1; i<=n; i++)
#define repr(i, n) for(int i=n-1; i>=0; i--)
#define repr1(i, n) for(int i=n; i>=1; i--)
#define all(v) v.begin(),v.end()
using ll = long long;
using pii = pair<int, int>;
using pil = pair<int, ll>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = 1e9+7;
const double EPS = 1e-10;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

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

    rep(i, 2) rep(j, 2) {
        vector<bool> v;
        v.push_back(i);
        v.push_back(j);

        for (int k = 1; k < n-1; k++) {
            if (v[k]) { // 羊
                if (s[k] == 'o') v.push_back(v[k-1]);
                else v.push_back(!v[k-1]);
            } else {
                if (s[k] == 'x') v.push_back(v[k-1]);
                else v.push_back(!v[k-1]);
            }
        }

        bool ok = true;
        rep(k, n) {
            int r = k + 1;
            int l = k - 1;
            if (k == 0) l = n - 1;
            if (k == n-1) r = 0;
            if (v[k]) {
                if (s[k] == 'o' && v[l] != v[r]) ok = false;
                if (s[k] == 'x' && v[l] == v[r]) ok = false;
            } else {
                if (s[k] == 'o' && v[l] == v[r]) ok = false;
                if (s[k] == 'x' && v[l] != v[r]) ok = false;
            }
        }
        if (ok) {
            // printf("(i, j) = (%d, %d)\n", i, j);
            rep(k, n) cout << (v[k] ? "S" : "W");
            cout << endl;
            return 0;
        }
    }
    cout << -1 << endl;
}


Measured memory_bytes: 512
N,M=map(int,input().split())
p=list(map(int,input().split()))
p=[0]+p

par=[i for i in range(N+1)]
size=[1 for i in range(N+1)]

def find(x):
    if par[x]==x:
        return x
    else:
        return find(par[x])

def union(x,y):
    if size[x]>size[y]:
        size[x]+=size[y]
        par[y]=find(x)
    elif size[y]>size[x]:
        size[y]+=size[x]
        par[x]=find(y)
    elif size[x]==size[y]:
        size[x]+=size[y]
        par[y]=find(x)
        
for i in range(M):
    a,b=map(int,input().split())
    if find(a)==find(b):
        pass
    else:
        union(find(a),find(b))
#print(par)
ans=0
for i in range(1,N+1):
    if find(i)==find(p[i]):
        ans+=1
        #print(i,find(i))
print(ans)



Measured memory_bytes: 13812
package main

import (
	"fmt"
	"sort"
)

func main() {
	var n, k int
	fmt.Scan(&n, &k)

	as := make(map[int]int)
	for i := 0; i < n; i++ {
		var a int
		fmt.Scan(&a)
		as[a]++
	}

	var cnts []int
	for _, a := range as {
		cnts = append(cnts, a)
	}

	sort.Ints(cnts)

	result := 0
	for i:=0; i<len(cnts)-k; i++ {
		result += cnts[i]
	}
	fmt.Println(result)
}


Measured memory_bytes: 16896
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define ff(i,n) for(i=0;i<n;i++)
#define pb push_back
ll bg =  998244353;
ll fac[300000];
ll power(ll x,ll y)
{
    if(y==0)
	    return 1;
	ll d = power(x,y/2)%bg;
	ll f = (d*d)%bg;
	if(y%2==0)
	  return f;
	else
	  return (f*x)%bg;	 	
}
ll modinv(ll m)
{
	return power(m,bg-2);	
}
ll ncr(ll n,ll r)
{
	ll s1 = fac[n],s2 = fac[r],s3 = fac[n-r];
	ll d1 = (s1*modinv(((s2*s3)%bg)))%bg;
	return d1;
}
int main()
{
	fac[0]=1;
	for(ll j=1;j<300000;j++)
	  fac[j] = (j*fac[j-1])%bg;
	ll t;
	t=1;
	while(t--)
	{
		string a,b;
		cin>>a>>b;
		if(b.length()!=(a.length()+1))
		{
			cout<<"No"<<endl;
		}
		else
		{
			for(ll i=0;i<a.length();i++)
			   if(a[i]!=b[i])
			   {
			   	   cout<<"No";
			   	   return 0;
			   }
			   cout<<"Yes";	
		}
	}
	 return 0;
}

Measured memory_bytes: 5976
#include <stdio.h>

int main(void){
	int N,a,b,c,i;
	scanf("%d",&N);
	for(i=0;i<N;i++){
		scanf("%d %d %d",&a,&b,&c);
		if(a*a+b*b==c*c || a*a+c*c==b*b || b*b+c*c==a*a){printf("YES\n");}
		else{printf("NO\n");}
	}
}

Measured memory_bytes: 1008
#define _GLIBCXX_DEBUG
#define _USE_MATH_DEFINES
#include <iostream>
#include <cmath>
#include <cassert>
#include <vector>
#include <map>
#include <string>
#include <algorithm>
#include <numeric>
#include <queue>
#include <type_traits>
//#include <bits/stdc++.h>

typedef long long ll;
const ll INF = (ll)1e18 + 1;
const ll MAX_V = 100100;
const ll MOD = 1000000007;

void print(){ std::cout << std::endl; }
template <typename Head> void print(Head&& head) { std::cout << head << std::endl; }
template <typename Head, typename... Tail> void print(Head&& head, Tail&&... tail)
{
  std::cout << head << " ";
  print(std::forward<Tail>(tail)...); // or print(tail...);
}
template<typename Iterator> void printVec(Iterator begin, Iterator end)
{
  for (Iterator it = begin; it != end; it++) {
    std::cout << "[" << std::distance(begin, it) << "] " << *it << " ";
    if (std::distance(begin, it) % 20 == 19) { std::cout << std::endl; }
  }
  std::cout << std::endl;
}

ll fact[MAX_V + 1], invfact[MAX_V + 1];

template <typename T, typename U>
T mypow(T b, U n) {
    if (n == 0) return 1;
    if (n == 1) return b % MOD;
    if (n % 2 == 0) {
        return mypow(b * b % MOD, n / 2);
    } else {
        return mypow(b, n - 1) * b % MOD;
    }
}

void precalc() {
    invfact[0] = fact[0] = 1;
    for (ll i = 1; i <= MAX_V; ++i) {
        fact[i] = fact[i - 1] * i % MOD;
    }

    invfact[MAX_V] = mypow(fact[MAX_V], MOD - 2);
    for (ll i = MAX_V - 1; i >= 0; --i) {
        invfact[i] = invfact[i + 1] * (i + 1) % MOD;
    }
    return;
}

ll comb(ll a, ll b) {
    if (a < b) return 0;
    if (a == 0) return 1;  // a = b = 0

    return fact[a] * invfact[a - b] % MOD * invfact[b] % MOD;
}

int main(int argc, char* argv[])
{
  precalc();

  ll N, M;
  std::cin >> N >> M;

  ll ans = 1;
  ll M_raw = M;
  for (ll i = 2; i * i <= M; i++) {
    ll cnt = 0;
    while (M_raw % i == 0) {
      M_raw /= i;
      cnt++;
    }

    ans *= comb(N + cnt - 1, cnt);
    ans %= MOD;

    //print(i, M_raw);
  }

  if (M_raw > 1) {
    ll cnt = 1;
    ans *= comb(N + cnt - 1, cnt);
    ans %= MOD;
  }

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


Measured memory_bytes: 1792
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	int a[3];
	cin >> a[0] >> a[1] >> a[2];
	sort(a, a + 3);
	int ans = 0;
	ans += a[2] - a[1];
	a[1] = a[2];
	a[0] += ans;
	if ((a[1] - a[0]) % 2 == 0) ans += (a[1] - a[0]) / 2;
	else ans += (a[1] - a[0]) / 2 + 2;
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <utility>
#include <map>
#include <set>
#include <functional>
typedef long long ll;
typedef std::pair<int,int> P;
using namespace std;
const int MOD = 1000000007;
int main(){
    int n,m,q;
    cin >> n >> m >> q;

    vector<vector<int>> sum(n,vector<int>(n,0));

    for(int i = 0;i < m;i++){
        int l,r;
        cin >> l >> r;
        l--,r--;
        sum[l][r]++;
    }

    //縦方向に累積和.
    for(int i = 0;i < n;i++){
        for(int j = 1;j < n;j++){
            sum[i][j] += sum[i][j-1];
        }
    }


    vector<int> ans(q,0);
    for(int i = 0;i < q;i++){
        int p,q;
        cin >> p >> q;
        p--,q--;
        for(int j = p;j < n;j++){
            ans[i] += sum[j][q];
        }
    }

    for(int i = 0;i < q;i++){
        cout << ans[i] << endl;
    }
}


Measured memory_bytes: 2304
#include<stdio.h>

int main(void) {
	int N, L;
	scanf("%d%d", &N, &L);

	int i;
	int v = 0;

	for (i = 0;i < N;i++) {
		v += L + i;
	}

	if (N + L - 1 < 0) {
		v -= N + L - 1;
	}else if(L > 0) {
		v -= L;
	}else{}

	printf("%d", v);

	return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))

m = {}
for a in A:
	if not a in m:
		m[a] = 1
	else:
		m[a] += 1

c = 0
for k in m:
	if k < m[k]:
		c += m[k] - k
	elif m[k] < k:
		c += m[k]

print(c)


Measured memory_bytes: 17780