akhauriyash/Code-Regression huggingface dataset:
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <algorithm>

using namespace std;
typedef long long ll;

struct UnionFind {
  vector<int> data;
  UnionFind(int size) : data(size, -1) { }
  bool connect(int x, int y) {
    x = root(x); y = root(y);
    if (x != y) {
      if (data[y] < data[x]) swap(x, y);
      data[x] += data[y]; data[y] = x;
    }
    return x != y;
  }
  bool isSame(int x, int y) {
    return root(x) == root(y);
  }
  int root(int x) {
    return data[x] < 0 ? x : data[x] = root(data[x]);
  }
  int size(int x) {
    return -data[root(x)];
  }
};

UnionFind uf = UnionFind(400030);

int main(int argc, char *argv[]) {
  int n,m;cin>>n>>m;
  for(int i=0;i<n;i++){
    int t;
    cin>>t;
    uf.connect(t, i + 200000);
  }
  for(int i=0;i<m;i++){
    int t1,t2;
    cin>>t1>>t2;
    uf.connect(200000 + t1 -1, 200000 + t2 -1);
  }
  int ans=0;
  for(int i=0;i<n;i++){
    if(uf.isSame(i+1, 200000+i))ans++;
  }
  cout<<ans<<endl;

  return 0;
}


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

#define int long long

int32_t main()
{
  
    int n,m;
    cin>>n>>m;
    vector <int> adj[n+1];

    while(m--)
    {
        int x,y;
        cin>>x>>y;

        adj[x].push_back(y);
        adj[y].push_back(x);
    }

    bool vis[n+1];
    map <int,vector <int> > prev;

    for(int i=1;i<=n;i++)
        vis[i]=false;


    queue <int> q;
    q.push(1);
    prev[1].push_back(-1);
    vis[1]=true;

    while(not q.empty())
    {
        int v=q.front();
        q.pop();

        for(int i=0;i<adj[v].size();i++)
        {
            if(not vis[adj[v][i]])
            {
                vis[adj[v][i]]=true;
                q.push(adj[v][i]);
                prev[adj[v][i]].push_back(v);
            }
        }
    }

    for(int i=2;i<=n;i++)
    {
        if(prev[i].size()!=1)
        {
            cout<< "No";
            return 0;
        }
    }
    cout<< "Yes\n";

    for(int i=2;i<=n;i++)
        cout<<prev[i][0]<< "\n";






    return 0;
}


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

int main() {
	int N, M;
	while (cin >> N >> M) {
		if (N == 0 && M == 0) return 0;
		vector<int> A(N);
		for (int i = 0; i < N; i++) cin >> A[i];
		int MAX = -1;
		for (int i = 0; i < N; i++) {
			for (int j = 0; j < N; j++) {
				if (i == j) continue;
				if (A[i] + A[j] <= M) MAX = max(MAX, A[i] + A[j]);
			}
		}
		if (MAX == -1) cout << "NONE" << endl;
		else cout << MAX << endl;
	}
}


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

int count_digit(int num){
  if(num==0)return 1;
  int res=0;
  while(num>0){
    num/=10;
    res++;
  }
  return res;
}

int a[10],n,c,l,maxn,minn,ans;
int ch[21];

void deb() {

  for(int i=0;i<l;i++)
    cout << a[i] <<" ";
  cout << endl;
      
}

void suji() {
  int t = 1;
  maxn = 0;
  minn = 0;
  for(int i=0;i<l-1;i++) t *=10;
  for(int i=0;i<l;i++){
    maxn += a[i] * t;
    minn += a[l-1-i] * t;
    t /= 10;
  }

  //printf("max(%d) - min(%d) = %d\n",maxn,minn,maxn-minn);
  
}
    

void buble() {
  int t;
  for(int i=0;i<l;i++) {
    for(int j=i;j<l;j++) {
      if(a[i] < a[j] ) {
	t = a[i];
	a[i] = a[j];
	a[j] = t;
      }
      
    }
  }
  
}

void  bunkai() {
  //cout << "bunkai " << n << endl;
  int t = n;
  int keta=1;
  for(int i=0;i<l-1;i++) keta *=10;
  for(int i=0;i<l;i++) {
    a[i] = t / keta;
    t %= keta;
    keta /= 10;
  }
   
}


void check(int x) {

  for(int i=0;i<x;i++) {
    if(n == ch[i]) {
      ans = i;
      break;
      //printf("n(%d) = ch[%d](%d)\n",n,i,ch[i]);

    }
  }

  
}




int main() {

  while(1) {

    cin >>n >> l;
    if(n==0&&l==0)break;

    int count = -1;
    int t = n;


    for(int i=0;i<21;i++) ch[i] = -1;


    c=count_digit(t);

    for(int i=0;i<l-c;i++)  n *= 10;
    ans = -1;

    while(1) {
      count++;
      check(count);
      ch[count] = n;
      if(ans != -1) break;

      bunkai();
      buble();
      suji();
      n = maxn - minn;

      //cout<<n<<' '<<maxn<<' '<<minn<<endl;
    }
    
    cout << ans <<" " << n << " " <<count - ans<< endl;
    
  } 
  
  
  
  return 0;
 
}
      
    
 

Measured memory_bytes: 1160
#include <bits/stdc++.h>
#define f(i, j) f[i][j+3000]
#define int long long 
using namespace std;
const int N = 6100;
int n, P;
int f[N][N+3000];
signed main(void){
	cin >> n >> P;
	f(0, 0) = 1;
	for (int i = 0; i < n * 3; ++ i)
		for (int j = -n; j <= 3 * n; ++ j) {
			f(i+1, j+1) = (f(i+1, j+1) + f(i, j)) % P;
			f(i+2, j-1) = (f(i+2, j-1) + f(i, j) * (i + 1) % P) % P;
			f(i+3, j) = (f(i+3, j) + f(i, j) * (i + 1) % P * (i + 2) % P) % P; 
		}
	int res = 0;
	for (int i = 0; i <= n; ++ i) res = (res + f(n*3, i*3)) % P;
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 402892
#include <bits/stdc++.h>
#define LL long long 
#define N 1000005
using namespace std;
int n,w,e,s;
char c[N];
int main()
{
	scanf("%s",c+1);
	int a=strlen(c+1);
	for(int i=1;i<=a;i++)
	{
		if(c[i]=='N')
			n=1;
		if(c[i]=='S')
			s=1;
		if(c[i]=='W')
			w=1;
		if(c[i]=='E')
			e=1;		
	}
	if(n==s && e==w)
		printf("Yes");
	else
		printf("No");
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
#define all(x) (x).begin(), (x).end()
using namespace std;
using Graph = vector<vector<int>>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9+7;
const ll LINF = 1LL<<60;

const int MAXN = 100000;

bool seen[MAXN];

void dfs(Graph &G, int v) {
    seen[v] = 1;
    for (auto nv : G[v]) {
        if (seen[nv] == 1) continue;
        dfs(G, nv);
    }
}

int main()
{
    cin.tie(0);
    ios_base::sync_with_stdio(0);
    int n, m;
    cin >> n >> m;
    Graph G(n);
    rep(i, m) {
        int x, y, z;
        cin >> x >> y >> z;
        --x, --y;
        G[x].push_back(y);
        G[y].push_back(x);
    }

    int res = 0;
    rep(i, n) {
        if (seen[i] != 0) continue;
        dfs(G, i);
        res++;
    }

    cout << res << endl;

    return 0;
}

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

int main() {

	int N, D;

	cin >> D >> N;

	int result;

	if (N < 100) {
		result = pow(100, D) * N;
	}
	else {
		result = pow(100, D)*(N + 1);
	}

	cout << result << endl;
	
	return 0;

}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace _001_FindingMissingCards
{
    /*
     */

    class Program
    {
        static void Main()
        {
            string line1st = Console.ReadLine();
            string []line1stSplit = line1st.Split(' ');
            int r = Convert.ToInt32(line1stSplit[0]);
            int c = Convert.ToInt32(line1stSplit[1]);
            int[,] m = new int[r + 1, c + 1];

            for (int i = 0; i < r; i++)
            {
                string lineElement = Console.ReadLine();
                string[] lineElementSplit = lineElement.Split(' ');
                for (int j = 0; j < c; j++)
                {
                    m[i, j] = Convert.ToInt32(lineElementSplit[j]);
                    m[i, c] += m[i, j];
                }
            }

            for (int j = 0; j < c + 1; j++)
            {
                for (int i = 0; i < r; i++)
                {
                    m[r, j] += m[i, j];
                }
            }

            for (int i = 0; i < r + 1; i++)
            {
                for (int j = 0; j < c ; j++)
                {
                    Console.Write("{0} ", m[i, j]);
                }
                Console.WriteLine("{0}",m[i,c]);
            }
            
        }
    }
}

Measured memory_bytes: 9412
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define FOR(i, b, n) for (ll i = b; i < n; ++i)

using namespace std;
using ll = long long;
using P = pair<int, int>;
const ll MOD = 1000000007;

ll repSquare(ll N, ll P, ll M) {
  if (P == 0)
    return 1;
  else if (P % 2 == 0) {
    ll half = repSquare(N, P / 2, M);
    return half * half % M;
  } else
    return N * repSquare(N, P - 1, M) % MOD;
}


void solve(ll n, ll a, ll b) {
  // 2^n - nCa - nCb
  // nCa mod = n! / (n-a)! a! = n! * ((n-a)!a!)^(MOD-2)
  
  ll all = repSquare(2, n, MOD) - 1;

  vector<ll> fact(b + 1);
  fact[1] = 1;
  FOR(i, 2, b + 1)
    fact[i] = fact[i - 1] * i % MOD;
  ll na(1), nb(1);
  REP(i, a)
    na = na * (n - i) % MOD;
  REP(i, b)
    nb = nb * (n - i) % MOD;

  ll nCa = na * repSquare(fact[a], MOD - 2, MOD) % MOD;
  ll nCb = nb * repSquare(fact[b], MOD - 2, MOD) % MOD;

  ll ans = (all - nCa) % MOD;
  ans = (ans - nCb) % MOD;
  if (ans < 0)
    ans += MOD;
  cout << ans << endl;
}

int main(){
  // int 3E4  long 2E9  ll 9E18
  cin.tie(0);
  ios::sync_with_stdio(false);

  ll n, a, b;
  cin >> n >> a >> b;

  solve(n, a, b);

  return 0;
}


Measured memory_bytes: 4700
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>   
using namespace std;
using namespace __gnu_pbds;
typedef long long ll; 
#define int long long
typedef unsigned long long lu;
typedef vector<ll> v;
typedef vector<vector<ll> > vv;
typedef vector<string>  vs;
typedef vector<pair<ll,ll>> vpr;
typedef vector<bool>vb;
typedef vector<double>vd;
typedef long double ld;
#define f(i,n) for(ll i = 0; i < n; i++)
#define ff(i,n) for(ll i=1;i<=n;i++)
#define pb push_back
#define mp make_pair
#define endl "\n"
#define fi first
#define se second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(),x.rend()
#define amax(x,y) if(y>x) x=y;
#define amin(x,y) if(y<x)x=y;
#define bg(x) x.begin()
#define sz(x) (ll)x.size()
#define in(x,n) for(ll i=0;i<n;i++)cin>>x[i]
#define out(x,n) for(ll i=0;i<n;i++)cout<<x[i]<<" " 
#define mxt(a) *(max_element(a.begin(),a.end()))
#define mnt(a) *(min_element(a.begin(),a.end())
#define tc ll t;cin>>t;while(t--)
typedef pair<ll,ll> pi;
#define yes cout<<"YES\n";
#define no cout<<"NO\n";
#define yesno(f) if(f) yes else no
const v dx = {1, -1, 0, 0};
const v dy = {0, 0, 1, -1};
const ld PI = 2 * acos(0.0);
ll cel(ll x1,ll y1){if((x1%y1)==0)return x1/y1;else return x1/y1+1;}
ll power(ll a,ll b,ll m)
{
    if(b==0)
        return 1;
    ll d=power(a,b/2,m);
    d=(d*d)%m;
    if(b&1)
        d=(d*a)%m;
    return d;
}
const ll mod=1e9+7;
int MOD(int a)
{
    if(a<0)
        a+=mod;
    if(a>=mod)
        a%=mod;
    return a;
}
// set_name.find_by_order(k) It returns to an iterator to the kth element (counting from zero) in the set in O(logn) time
// set_name.order_of_key(k) It returns to the number of items that are strictly smaller than our item k in O(logn) time.
/*string operations :
str.substr (x,y) : returns a substring str[x],str[x+1],...str[x+y-1]
str.substr (x) : returns a substring str[x],... end of string
str.find(qtr) : returns the first occurenece of qtr in str */
int ans=0;
int n;
void dfs(int u,int pa,vv &gr)
{
    int i=u;
    // int n=sz(gr);
    int c=i*(n-i+1);
    if(pa!=0)
    {
        int a=i,b=pa;
        if(a > b)
            swap(a,b);
        int c1=a*(n-b+1);
        c-=c1;
    }
    ans+=c;
    for(auto it:gr[u])
    {
        if(it!=pa)
        {
            dfs(it,u,gr);
        }
    }
}
int32_t main()
{
    ios::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    // freopen("input.txt", "r", stdin);
    // freopen("output.txt", "w", stdout);
    cin>>n;
    vv gr(n+1);
    f(i,n-1)
    {
        int a,b;cin>>a>>b;
        gr[a].pb(b);
        gr[b].pb(a);
    }
    dfs(1,0,gr);
    cout<<ans<<endl;
    return 0;
}

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

int main(){
  int i,j,cnt;
  string s;
  cin>>s;
  if(s=="SUN")cout<<7;
  else if(s=="MON")cout<<6;
  else if(s=="TUE")cout<<5;
  else if(s=="WED")cout<<4;
  else if(s=="THU")cout<<3;
  else if(s=="FRI")cout<<2;
  else cout<<1;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
long long A,B,C;
int main(){
  cin >> A >> B >> C;
  if(A+B<C) cout << min(A+B,C)+min(B,A+B)+1 << endl;
  else cout << min(A+B,C)+min(B,A+B) << endl;
  return 0;
}


Measured memory_bytes: 256
// 演習４−２
import java.util.Scanner;

public class Main{
  public static void main(String[] args) {
    Scanner scan = new Scanner(System.in).useDelimiter("[,\\s]+");
    int w=scan.nextInt();
    int n=scan.nextInt();
    int[] F;
    int i;

    F= new int[w+1];
    for(i=1;i<w+1;i++){
    F[i]=i;
    }
    for(i=0;i<n;i++){
     int a=scan.nextInt();
     int b=scan.nextInt();
     int temp = F[a];
     F[a]=F[b];
     F[b]= temp;
    }
    for (i=1;i<w+1;i++) {
            System.out.println(F[i]);
        }


    }
  }



Measured memory_bytes: 26140
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define INF 1000000000
typedef long long ll;
typedef pair<int, int> P;

ll dp[3001][3001] = {};

int main(){
    int i, j;
    string s, t, res = "";
    cin >> s >> t;
    for(i=0; i<s.length(); i++){
        for(j=0; j<t.length(); j++){
            dp[i+1][j+1] = max(dp[i+1][j], dp[i][j+1]);
            if(s[i] == t[j]){
                dp[i+1][j+1] = max(dp[i+1][j+1], dp[i][j] + 1);
            }
        }
    }
    while(i > 0 && j > 0){
        if(dp[i][j] == dp[i-1][j-1]+1 && s[i-1] == t[j-1]){
            i--;
            j--;
            res = s[i] + res;
        }else if(dp[i][j] == dp[i-1][j]){
            i--;
        }else{
            j--;
        } 
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 70656
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const double EPS = 1e-9;
typedef vector<int> vint;
typedef pair<int, int> pint;
#define rep(i, n) REP(i, 0, n)
#define ALL(v) v.begin() , v.end()
#define REP(i, x, n) for(int i = x; i < n; i++)


int main(){
    string a,b; cin >> a >> b;
    auto s = stoi(a + b);
    long x = sqrt(s);
    if(x * x == s) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(void){
    // Your code here!
    int N,a[109];
    cin >> N;
    for (int i =0 ; i<N ;i++) {
        cin >> a[i];
    }
    sort(a, a + N, greater<int>());
     /*for (int i = 0; i<N;i++) {
         cout <<a[i] << endl;
     }*/
     int ret = 0;
     for (int i = 0;i <N; i++) {
         if (i%2 == 0) {
             ret += a[i];
         } 
         else {
             ret -=a[i];
         }
     }
     cout << abs(ret) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1; (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

//Union-Find Tree
class UnionFind{
public:
    int N;              //頂点数
    vector<int> par;    //par[i]:iの親の番号
    vector<int> size;   //size[i]:iが属するグループと同じグループに属する頂点数

    UnionFind(int n) : N(n), par(n), size(n, 1){  //初期化時はすべて根とする
        for(int i=0; i<n; i++){
            par.at(i) = i;
        }
    }

    int root(int x){    //データxが属する木の根を再帰で得る
        if(par.at(x) == x){
            return x;
        }else{
            return par.at(x) = root(par.at(x)); //経路圧縮を同時に実行
        }
    }

    void unite(int x, int y){   //xの属する木とyの属する木を併合
        int rx = root(x), ry = root(y);
        if(rx != ry){   //xとyの属する木が異なるとき
            par.at(rx) = ry;    //xの木の根をyの根につける
            size.at(ry) += size.at(rx);   //sizeを更新
        }
    }

    int getSize(int x){         //xの属する木のサイズを返す
        return size.at(x) = size.at(root(x));
    }

    bool same(int x, int y){    //x,yが同じ木に属するときtrue, そうでなければfalse
        return root(x) == root(y);
    }
};

int main(){
    ios();
    int N, K, L;
    cin >> N >> K >> L;

    UnionFind UF1(N), UF2(N);

    REP(i, K){
        int a, b;
        cin >> a >> b;
        UF1.unite(a-1, b-1);
    }
    REP(i, L){
        int a, b;
        cin >> a >> b;
        UF2.unite(a-1, b-1);
    }

    vector<map<int,int>> mp(N);
    REP(i, N){
        mp[UF1.root(i)][UF2.root(i)]++;
    }

    REP(i, N){
        cout << mp[UF1.root(i)][UF2.root(i)] << " ";
    }
    cout << endl;

    return 0;
}

Measured memory_bytes: 21248
#include <stdio.h>

int main()
{
	int a, b, n, sum = 0, temp = 0, t;
	
	scanf("%d %d %d", &n, &a, &b);
	
	for(int i = 1; i <= n; i++){
		t = i;
		while(t / 10 || t % 10){
			temp += t % 10;
			t /= 10;
		}
		
		if(temp >= a && temp <= b){
			sum += i;
		}
		
		temp = 0;
	}
	
	printf("%d", sum);
	
	return 0;
}

Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long int
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;


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


signed main()
{
    int k;
    cin >> k;
    ll sum = 0;
    repi(a, k+1)
    repi(b, k+1)
    repi(c, k+1) {
        sum += gcd(gcd(a, b), c);
    }
    put(sum);
    return 0;
}

Measured memory_bytes: 3640
import sys, math
from pprint import pprint
input = sys.stdin.readline
rs = lambda: input().strip()
ri = lambda: int(input())
rl = lambda: list(map(int, input().split()))
mod = 10**9 + 7

N = ri()
points = []
for i in range(N):
	x, y = rl()
	points.append((x,y))

def get_len(p):
	x, y = p[0]
	l = 0
	for i in range(len(p)-1):
		d = ((p[i][0]-p[i+1][0])**2+(p[i][1]-p[i+1][1])**2)**0.5
		l += d
	return l

import itertools
sl = 0
n = 0
for p in itertools.permutations(points):
	l = get_len(p)
	sl += l
	n += 1
print(sl/n)


Measured memory_bytes: 41068
#include <bits/stdc++.h>
#include<algorithm>
#define int long long
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define INF 1000000000000
int MOD=1000000007;

signed main() {
int n;
cin>>n;
vector<int>a(n);
vector<int>b(n);
vector<int>c(n);
rep(i,n)cin>>a[i];
rep(i,n)cin>>b[i];
rep(i,n)cin>>c[i];
sort(a.begin(),a.end());
sort(b.begin(),b.end());
sort(c.begin(),c.end());
int ans=0;
rep(i,n){
  int d1,d2;
  d1=distance(a.begin(),lower_bound(a.begin(),a.end(),b[i]));
  d2=n-distance(c.begin(),upper_bound(c.begin(),c.end(),b[i]));
  ans+=d1*d2;
}
cout<<ans<<endl;
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define all(x) (x).begin(), (x).end()
using ll = long long;
using namespace std;
template <typename T> using vec = std::vector<T>;

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){
    return a/gcd(a,b)*b;
}

int main() {
    int N;
    cin >> N;
    
    vec<ll> T(N);
    ll ans = 1;
    rep(i, N) {
        cin >> T[i];
        ans = lcm(ans,T[i]);
    }

    cout << ans << endl;

}


Measured memory_bytes: 3636
import sys
import math
from collections import defaultdict

sys.setrecursionlimit(10**7)
def input():
    return sys.stdin.readline()[:-1]

mod = 10**9 + 7

def I(): return int(input())
def II(): return map(int, input().split())
def III(): return list(map(int, input().split()))
def Line(N):
    read_all = [tuple(map(int, input().split())) for _ in range(N)]
    return map(list,zip(*read_all))

#################

S = str(input())
N = len(S)

h_all = 0
for i in range(N):
    if S[i]=='?':
        h_all += 1

a = 0
b = 0
h = 0
numAB = 0
numAH = 0
numHB = 0
numHH = 0
dp = [0]*N

beki3 = pow(3,h_all-3,mod) if h_all>=4 else 1
beki2 = beki3*3 % mod if h_all>=3 else 1
beki1 = beki2*3 %mod if h_all>=2 else 1
beki0 = beki1*3 %mod if h_all>=1 else 1

for i in range(N):
    if S[i]=='A':
        if i>=1:
            dp[i] = dp[i-1]
        a += 1
    elif S[i]=='B':
        if i>=1:
            dp[i] = dp[i-1]
        numAB += a
        numHB += h
        b += 1
    elif S[i]=='?':
        if i>=1:
            if h_all>=1:
                dp[i] = (dp[i-1]+numAB*beki1) %mod
            if h_all>=2:
                dp[i] = (dp[i]+numAH*beki2) %mod
                dp[i] = (dp[i]+numHB*beki2) %mod
            if h_all>=3:
                dp[i] = (dp[i]+numHH*beki3)%mod
        numAH += a
        numHH += h
        h += 1
    else:
        if i>=1:
            dp[i] = (dp[i-1]+numAB*beki0) %mod
            if h_all>=1:
                dp[i] = (dp[i]+numAH*beki1) %mod
                dp[i] = (dp[i]+numHB*beki1) %mod
            if h_all>=2:
                dp[i] = (dp[i]+numHH*beki2)%mod

print(dp[N-1])

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

class Pt{
    public:
    double x, y;
    Pt(double x = 0, double y = 0):x(x),y(y){}
    Pt operator + (Pt p){return Pt(x + p.x, y + p.y);}
    Pt operator - (Pt p){return Pt(x - p.x, y - p.y);}
    Pt operator / (double d){return Pt(x / d, y / d);}
    Pt operator * (double d){return Pt(x * d, y * d);}
    Pt operator * (Pt p){return Pt(x * p.y, -y * p.x);}
    bool operator > (Pt p){return ((abs(x - p.x) > 1e-7) ? x > p.x: y > p.y);}
    double norm(){return hypot(x, y);}
    Pt rot90(){return Pt(-y, x);}
    Pt rot180(){return Pt(-x, -y);}
    Pt rot270(){return Pt(y, -x);}
    string str(){stringstream ss;ss<<x<<", "<<y;return ss.str();}
};

vector<Pt>cc_cross(Pt p1, double r1, Pt p2, double r2){
    double d = (p1 - p2).norm();
    double rc = (d * d + r1 * r1 - r2 * r2) / (2 * d);
    double rs = sqrt(max(r1 * r1 - rc * rc, 0.0));
    Pt diff = (p2 - p1) / d;
    vector<Pt>points = {p1 + diff * rc + diff.rot90() * rs, p1 + diff * rc + diff.rot270() * rs};
    return points;
}

int main(){
    
    Pt p1, p2;
    double r1, r2;
    cin >> p1.x >> p1.y >> r1;
    cin >> p2.x >> p2.y >> r2;
    vector<Pt>points = cc_cross(p1, r1, p2, r2);
    if(points[0] > points[1])swap(points[0], points[1]);
    printf("%.10f %.10f %.10f %.10f\n", points[0].x, points[0].y, points[1].x, points[1].y); 

    return 0;
}


Measured memory_bytes: 3264
#include<stdio.h>
int main(){

char s[3],i,flag=0;
scanf("%s",&s);
for(i=0;i<3;i++){
    if(s[i]=='7'){
        flag=1;
        break;
    }
}
if(flag){
    printf("Yes");
}
else{
    printf("No");
}


}


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

int main() {
    int n,m;
    cin >> n >> m;
    vector<int> x (m);
    for(int i=0; i<m; i++){
        cin >> x.at(i);
    }
    sort(x.begin(),x.end());
    reverse(x.begin(),x.end());
    priority_queue<int> pq;
    if(m == 1 || n >= m) cout << 0 << endl;
    else{
        for(int i=0;i<m-1; i++){
            pq.push(x.at(i) - x.at(i+1));
        }
        ll ans = 0;
        for(int i=0; i<n-1; i++){
            pq.pop();
        }
        while(!pq.empty()){
            ans += pq.top();
            pq.pop();
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 1276
n, x, y = map(int, input().split())
dis_n = [0] * (n-1)

for i in range(1, n+1):
    for j in range(i+1, n+1):
        dis_n[min([abs(j-i), abs(x-i)+1+abs(j-y), abs(y-i)+1+abs(j-x)])-1] += 1

for d in dis_n:
    print(d)


Measured memory_bytes: 3444
#include<bits/stdc++.h>
using namespace std;
#define intt long long int
#define intu unsigned long long int
#define vi vector<int>
#define ii pair<int,int>
#define pb push_back
//#define mp make_pair
#define ff first
#define ss second
#define fast_io ios::sync_with_stdio(0);cin.tie(NULL);std::cout.tie(NULL);
# define PI           3.14159265358979323846 
#define all(a) a.begin(),a.end()
#define for0(i, n) for (int i = 0; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define loop(i,a,b) for (int i = a; i < b; i++)
#define bloop(i,a,b) for (int i = a ; i>=b;i--)
#define tc(t) int t; cin >> t; while (t--)
int mod = 1000000007;
int gcd(int a, int b) {return b ? gcd(b, a % b) : a;}
int lcm(int a, int b) {return a * b / gcd(a, b); }
intt bpow(intt a,intt b) 
{
  intt res = 1;
  while (b > 0) {
    if (b & 1)res = ((res%mod) * (a%mod))%mod;
      a = ((a%mod) * (a%mod))%mod;
      b >>= 1;
  }
  return res;
}
intt fact(intt n) { 
   if ((n==0)||(n==1))
      return 1; 
   else
      return n*fact(n-1);
}
void go()
{
#ifndef ONLINE_JUDGE
  freopen("inn.txt","r",stdin);
  freopen("ouut.txt","w",stdout);
  #endif
}
///////////U L R D
int dx[4]={0,-1,1,0};
int dy[4]={1,0,0,-1};


int main() 
{ 
    fast_io
    go();
    vector<vector<int>> vec(3,vector<int>(3));
    for0(i,3)
    {
      for0(j,3)
      {
        cin>>vec[i][j];
      }
    }
   vector<vector<bool>> vis(3,vector<bool>(3,false));
   int n;cin>>n;
    for0(i,n)
    {
      int a;cin>>a;
      for(int i=0;i<3;i++)
      {
        for(int j=0;j<3;j++)
        {
          if(vec[i][j]==a)
          {
            vis[i][j]=true;
            break;
          }
        }
      }
    }
    bool f=0;
    for0(i,3)
    {
      
      for0(j,3)
      {
        if(!vis[i][j])
        {
          f=0;
          break;
        }
        else
          f=1;
      }
      if(f)
      {
        cout << "Yes" <<"\n";
        return 0;
      }
    }
    
    for0(i,3)
    {
     
      for0(j,3)
      {
        if(!vis[j][i])
        {
          f=0;
          break;
        }
        else
          f=1;
      }
      if(f)
      {
        cout << "Yes" <<"\n";
        return 0;
      }
    }
    
    if((vis[0][0] && vis[1][1] && vis[2][2])||(vis[0][2]&&vis[1][1]&&vis[2][0]))
    {
      cout << "Yes" <<"\n";
      return 0;
    }
    cout << "No" <<"\n";
}

/*!
    You are under no obligation to be the same person you were a minute ago,
    You have the right to grow !
*/




















Measured memory_bytes: 3616
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <time.h>
#include <list>

using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define reps(x,c) for(auto x:c)
#define all(x) begin(x), end(x)
#define pb(a) emplace_back(a) 
#define mp(a,b) make_pair((a),(b))
#define pl pair<ll,ll>
#define INF 2147483600
#define MOD 1000000007
#define fi first
#define se second
#define dbg(x) cout << #x"="<< (x) << endl
#define dbgv(x) cout<<#x<<endl;reps(y,x){cout<<y<<" ";}cout<<endl

int main(){
  ll n,k;cin>>n>>k;
  ll ans=0;
  ll r;
  FOR(i,k+1,n+1){
    r=n/i;
    ans+=r*(i-k);
    ans+=max(n%i-k+1,0ll);
    if(k==0){
      ans--;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

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

const double PI = 3.14159265358979323846;
const double EPS = 1e-12;
const ll INF = 1LL<<29;
const ll mod = 1e9+7;

#define rep(i, a, b) for(ll (i) = (a); (i) < (b);++i)

int main() {
	ll N, C;
	cin >> N >> C;
	ll p[C];
	rep(i,0,C) cin >> p[i];
	ll sum = 0;
	rep(i,0,C) sum += p[i];
	if (sum % (N+1) == 0)
		cout << sum/(N+1) << endl;
	else
		cout << sum/(N+1) + 1 << endl;
	return 0;
}



Measured memory_bytes: 3136
#include <iostream>

int main()
{
	int bingo[3][3];
	int N;
	int* x;
	bool tf[3][3] = { {0,0,0} ,{0,0,0}, {0,0,0} };

	for(int i = 0; i < 3;i++)
	{
		std::cin >> bingo[i][0] >> bingo[i][1] >> bingo[i][2];
	}

	std::cin >> N;
	x = new int[N];

	for (int n = 0; n < N; n++)
	{
		std::cin >> x[n];
		for (int i = 0; i < 3; i++) {
			for (int j = 0; j < 3; j++) {
				if (x[n] == bingo[i][j])
				{
					tf[i][j] = 1;
				}
			}
		}
	}



	int sum = 0;
	for (int i = 0; i < 3; i++)
	{
		sum = 0;
		for (int j = 0; j< 3; j++)
			sum += tf[i][j];
		if (sum == 3)
		{
			std::cout << "Yes";
			return 0;
		}
	}
	
	sum = 0;
	for (int i = 0; i < 3; i++)
	{
		sum = 0;
		for (int j = 0; j < 3; j++)
			sum += tf[j][i];
		if (sum == 3)
		{
			std::cout << "Yes";
			return 0;
		}
	}
	
	sum = tf[0][0] + tf[1][1] + tf[2][2];
	if (sum == 3)
	{
		std::cout << "Yes";
		return 0;
	}

	sum = tf[0][2] + tf[1][1] + tf[2][0];
	if (sum == 3)
	{
		std::cout << "Yes";
		return 0;
	}


	std::cout << "No";
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define mmp make_pair
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
typedef vector<ll> vl;
typedef vector<pl> vpl;
const int MN = 100100;
ll pr[MN];
ll sid[MN];
ll sz;
ll sc[MN],pot[MN];
pl get(ll tar, int id) {
	int st = 0,ed = sz;
	int ls = -1;
	while(st <= ed) {
		int m = (st+ed)/2;
		ll val = pr[m];
		if(m > sid[id]) {
			val -= pot[id];
		}
		if(val >= tar) {
			ed = m-1;
			ls = m;
		} else {
			st = m+1;
		}
	}
	if(ls == -1) {
		return mmp(-1,-1);
	}
	ll ret = pr[ls];
	if(ls > sid[id]) {
		ls--;
		ret -= pot[id];
	}
	return mmp(ls,ret);
}

pl lr[MN];
int main() {
vpl pa;
	ios::sync_with_stdio(0);cin.tie(0);
	memset(pr,0,sizeof(pr));
	ll n,x;
	cin >> n >> x;
	sz = n;
	ll tot = 0;
	ll res = 0;
	for(int i=0;i<n;i++) {
		ll a,b,c;
		cin >> a >> b >> c;
		tot += a*b;
		res += a;
		sc[i] = a;
		lr[i] = mmp(b,c);
		pot[i] = c*x+a*b-a*c;
		pa.push_back(mmp(pot[i],i));
	}
	sort(pa.begin(),pa.end(),greater<pl>());
	for(int i=0;i<pa.size();i++) {
		sid[pa[i].second] = i;
		pr[i+1] = pr[i]+pa[i].first;
	}
	for(int rev=0;rev<2;rev++) {
		for(int i=0;i<n;i++) {
			ll gol;
			ll val;
			ll a = sc[i];
			ll b = lr[i].first,c = lr[i].second;
			ll co;
			ll tar;
			if(rev) {
				gol = tot-b*x;
				val = 0;
				co = b;
				tar = tot;
			} else {
				tar = tot+a*c-a*b;
				ll a = sc[i];
				ll b = lr[i].first;
				val = 0;
				gol = tot-c*(x-a)-a*b;
				co = c;
			}
			ll ls = n;
			pl dat = get(gol,i);
			if(dat.first == -1) {
				continue;
			}
			ll run = dat.second;
			ls = dat.first;
			val += ls*x+max((tar-run+co-1)/co,0LL);
			res = min(val,res);
		}
	}
	cout << res << '\n';
}


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


int main(void) {
	string S;
	int sx, sy, tx,ty;
	cin >> sx >> sy >> tx >> ty;

	for (int x = sx; x < tx; x++) {
		S += 'R';
	}
	for (int y = sy; y < ty; y++) {
		S += 'U';
	}

	for (int x = tx; x > sx; x--) {
		S += 'L';
	}
	for (int y = ty; y > sy; y--) {
		S += 'D';
	}

	S += 'D';
	for (int x = sx; x < tx+1; x++) {
		S += 'R';
	}
	for (int y = sy-1; y < ty; y++) {
		S += 'U';
	}
	S += 'L';
	S += 'U';
	for (int x = tx; x > sx-1; x--) {
		S += 'L';
	}
	for (int y = ty+1; y > sy; y--) {
		S += 'D';
	}
	S += 'R';
	
	cout << S << endl;

	return 0;
}


Measured memory_bytes: 384
n = int(input())
s = input()
# B_map = set()
R, G, B = 0, 0, 0
for i in range(n):
	if s[i] == 'R':
		R += 1
	elif s[i] == 'G':
		G += 1
	else:
		B += 1

res = R * G * B

for i in range(n):
	for j in range(i+1, n):
		temp = 2*j - i
		if temp < n and s[i] != s[j] and s[j] != s[temp] and s[temp] != s[i]:
			res -= 1
print(res)

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

public class Main {

	public static void main (String[] args) {
	   InputReader in = new InputReader(System.in);
	   long x = in.readLong();
	   long y = in.readLong();
	    int sum = 0; 
	   for(long i = x; i<=y; i = i*2) {
		   sum++;
	   }
	   System.out.println(sum);
	}
}

class InputReader {

	private InputStream stream;
	private byte[] buf = new byte[1024];
	private int curChar;
	private int numChars;
	private SpaceCharFilter filter;

	public InputReader(InputStream stream) {
		this.stream = stream;
	}

	public int read() {
		if (numChars == -1)
			throw new InputMismatchException();
		if (curChar >= numChars) {
			curChar = 0;
			try {
				numChars = stream.read(buf);
			} catch (IOException e) {
				throw new InputMismatchException();
			}
			if (numChars <= 0)
				return -1;
		}
		return buf[curChar++];
	}

	public int readInt() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		int res = 0;
		do {
			if (c < '0' || c > '9')
				throw new InputMismatchException();
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}

	public String readString() {
		int c = read();
		while (isSpaceChar(c))
			c = read();
		StringBuilder res = new StringBuilder();
		do {
			res.appendCodePoint(c);
			c = read();
		} while (!isSpaceChar(c));
		return res.toString();
	}

	public long readLong() {
		int c = read();
		while (isSpaceChar(c)) {
			c = read();
		}
		int sgn = 1;
		if (c == '-') {
			sgn = -1;
			c = read();
		}
		long res = 0;
		do {
			if (c < '0' || c > '9') {
				throw new InputMismatchException();
			}
			res *= 10;
			res += c - '0';
			c = read();
		} while (!isSpaceChar(c));
		return res * sgn;
	}
	
	public boolean isSpaceChar(int c) {
		if (filter != null)
			return filter.isSpaceChar(c);
		return c == ' ' || c == '\n' || c == '\r' || c == '\t' || c == -1;
	}

	public String next() {
		return readString();
	}

	public interface SpaceCharFilter {
		public boolean isSpaceChar(int ch);
	}
}


Measured memory_bytes: 22996
#include<bits/stdc++.h>
#include<unordered_map>
using namespace std;
#define REP(i,m,n) for(int i=(m);i<(n);i++)
#define rep(i,n) REP(i,0,n)
#define pb push_back
#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
const ll inf=1e9+7;
const ll mod=998244353;
int main(){
    ll n,m;
    cin>>n>>m;
    unordered_map<ll,int>mp;
    ll aa=0,ai,ans=0;
    mp[0]=1;
    rep(i,n){
        cin>>ai;
        aa+=ai;
        aa%=m;
        ans+=mp[aa];
        mp[aa]=mp[aa]+1;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 3596
import numpy as np
n,m,c = map(int, input().split())
b = np.array(list(map(int, input().split())))
cnt = 0
for _ in range(n):
    a = np.array(list(map(int, input().split())))
    if np.sum(b*a) + c > 0:
        cnt += 1
print(cnt)

Measured memory_bytes: 27236
function Main(input) {
  input=input.split("\n");
  const N=input[0]-0;
  var array=input[1].split(' ').map(e=>{
    return e-0;
  }).sort((a,b)=>{
    return a-b;
  });
  var ans=0;
  //console.log(array);
  for(var i=0;i<N-2;i++){
    for(var j=i+1;j<N-1;j++){
      for(var k=j+1;k<N;k++){
        if(array[i]===array[j]){
          break;
        }
        if(array[j]===array[k]){
          continue;
        }
        if(array[i]+array[j]<=array[k]){
          break;
        }
        //console.log(i,j,k);
        ans++;
      }
    }
  }
  console.log(ans);
}


//*この行以降は編集しないでください（標準入出力から一度に読み込み、Mainを呼び出します）
Main(require("fs").readFileSync("/dev/stdin", "utf8"));
  
  


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

int main() {

	int n;
	scanf("%d", &n);
	char s[n];
	scanf("%s", s);
	int sco = 0;
	int ans = 0;
	for(int i = 0; i < n; i++) {
		if(s[i] == 'I') {
			sco++;
		}else if(s[i] == 'D') {
			sco--;
		}
		ans = max(ans, sco);
	}
	printf("%d\n", ans);
}

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] args) 	{
		Scanner sc = new Scanner(System.in);
		while(0 < 1){
			int a = sc.nextInt();
			int b = sc.nextInt();
			int c = sc.nextInt();
			if(a == -1 && b == -1 && c == -1) break;
			int sum = a + b;
			if(a == -1 || b == -1) System.out.printf("F\n");
			else if(a + b >= 80)  System.out.printf("A\n");
			else if(a + b >= 65)  System.out.printf("B\n");
			else if(a + b >= 50 || c >= 50)  System.out.printf("C\n");
			else if(a + b >= 30)  System.out.printf("D\n");
			else System.out.printf("F\n");
			}
		sc.close();
	}	
} 


Measured memory_bytes: 26376
///AC

#include<bits/stdc++.h>

using namespace std;

int arr[100005], dp[100005], n,k,t;

int solve(int pos)
{
    if(pos==n) return 0;

    int &res=dp[pos];

    if(res!=-1)
        return res;

    res=1e9;

    for(int i=1; i<=k; i++)
    {
        if(pos+i<=n)
        {
            res = min(res, solve(pos+i)+abs(arr[pos+i]-arr[pos]));
        }
    }
    return res;
}

int main()
{
    cin >> n >> k;

    for(int i=1; i<=n; i++)
    {
        cin >> arr[i];
    }

    memset(dp, -1, sizeof(dp));

    int ans=solve(1);

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rrep(i,n) for(int (i)=((n)-1);(i)>=0;(i)--)
#define itn int
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
const long long INF = 1LL << 60;
const int MOD = 1000000007;
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; }
//https://www.creativ.xyz/dump-cpp-652/
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
 
// vector
template <typename T>
istream &operator>>(istream &is, vector<T> &vec) {
    for (T &x : vec) is >> x;
    return is;
}
// pair
template <typename T, typename U>
ostream &operator<<(ostream &os, pair<T, U> &pair_var) {
    os << "(" << pair_var.first << ", " << pair_var.second << ")";
    return os;
}
// vector
template <typename T>
ostream &operator<<(ostream &os, const vector<T> &vec) {
    os << "{";
    for (int i = 0; i < vec.size(); i++) {
        os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
    }
    os << "}";
    return os;
}
// map
template <typename T, typename U>
ostream &operator<<(ostream &os, map<T, U> &map_var) {
    os << "{";
    repi(itr, map_var) {
        os << *itr;
        itr++;
        if (itr != map_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
// set
template <typename T>
ostream &operator<<(ostream &os, set<T> &set_var) {
    os << "{";
    repi(itr, set_var) {
        os << *itr;
        itr++;
        if (itr != set_var.end()) os << ", ";
        itr--;
    }
    os << "}";
    return os;
}
 
#define DUMPOUT cerr
 
void dump_func() {
    DUMPOUT << endl;
}
template <class Head, class... Tail>
void dump_func(Head &&head, Tail &&... tail) {
    DUMPOUT << head;
    if (sizeof...(Tail) > 0) {
        DUMPOUT << ", ";
    }
    dump_func(std::move(tail)...);
}

#ifdef DEBUG_
#define DEB
#define dump(...)                                                              \
    DUMPOUT << "  " << string(#__VA_ARGS__) << ": "                            \
            << "[" << to_string(__LINE__) << ":" << __FUNCTION__ << "]"        \
            << endl                                                            \
            << "    ",                                                         \
        dump_func(__VA_ARGS__)
#else
#define DEB if (false)
#define dump(...)
#endif

signed main(void) { cin.tie(0); ios::sync_with_stdio(false);
    string s; cin>>s;
    string t = "keyence";
    int n = s.size();
    int now = 0;
    if(s == t) {cout<<"YES"<<endl; return 0;}
    rep(i,n){
        rep(j,n){
            if(i > j) continue;
            string tmp="";
            rep(k,n){
                if(k >= i && k <= j) continue;
                tmp += s[k];
            }
            if(tmp == t) {cout<<"YES"<<endl; return 0;}
        }
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
import sys
N=int(input())
s=str(input())
t=s.replace("o","2")
t=t.replace("x","0")
t=str(t)

ans="22"
for i in range(1,N):
  ans+=str( (int(t[i])-1) * (int(ans[i-1])-1)*(int(ans[i])-1)+1 )
if ans[0]==ans[N] and (int(ans[0])-1)*(int(t[0])-1)==(int(ans[1])-1)*(int(ans[N-1])-1):
  ans=ans.replace("2","S")
  ans=ans.replace("0","W")
  print(ans[0:N])
  sys.exit()

ans="20"
for i in range(1,N):
  ans+=str( (int(t[i])-1) * (int(ans[i-1])-1)*(int(ans[i])-1)+1 )
if ans[0]==ans[N] and (int(ans[0])-1)*(int(t[0])-1)==(int(ans[1])-1)*(int(ans[N-1])-1):
  ans=ans.replace("2","S")
  ans=ans.replace("0","W")
  print(ans[0:N])
  sys.exit()

ans="02"
for i in range(1,N):
  ans+=str( (int(t[i])-1) * (int(ans[i-1])-1)*(int(ans[i])-1)+1 )
if ans[0]==ans[N] and (int(ans[0])-1)*(int(t[0])-1)==(int(ans[1])-1)*(int(ans[N-1])-1):
  ans=ans.replace("2","S")
  ans=ans.replace("0","W")
  print(ans[0:N])
  sys.exit()

ans="00"
for i in range(1,N):
  ans+=str( (int(t[i])-1) * (int(ans[i-1])-1)*(int(ans[i])-1)+1 )
if ans[0]==ans[N] and (int(ans[0])-1)*(int(t[0])-1)==(int(ans[1])-1)*(int(ans[N-1])-1):
  ans=ans.replace("2","S")
  ans=ans.replace("0","W")
  print(ans[0:N])
  sys.exit()

print(-1)


Measured memory_bytes: 3828
import scala.collection.mutable.ArrayBuffer
import scala.io.StdIn
object Main extends App {
  val List(n, k, q) = StdIn.readLine().split(" ").map(_.toInt).toList
  val players = ArrayBuffer.fill(n)(0)
  var max = 0
  for (i <- 0 until q){
    val pl = StdIn.readLine().toInt - 1
    players(pl) += 1
    if (players(pl) > max) max = players(pl)

  }
  for (pl <- players){
    if(pl - q + k <= 0) println("No")
    else println("Yes")
  }
}


Measured memory_bytes: 40500
n = int(input())
s = input()

R = s.count('R')
G = s.count('G')
B = s.count('B')
ans = R*G*B

for i in range(n):
    for d in range(n):
        j = i + d
        k = j + d
        if k >= n: break
        if s[i] != s[j] and s[i] != s[k] and s[j] != s[k]:
            ans -= 1

print(ans)

Measured memory_bytes: 9204
#include<stdio.h>
#include<queue>
#include<utility>
#define For(i,a,b) for(register long long i=(a);i<=(b);i++)
#define ll long long
#define mp make_pair
#define fi first
#define se second
using namespace std;
const ll maxn=2e5+10;
ll n,a[maxn],b[maxn],l[maxn],r[maxn],ans;
priority_queue< pair<ll,ll> > q;
signed main(){
	scanf("%lld",&n);
	For(i,1,n){
		scanf("%lld",&a[i]);
		l[i]=i-1,r[i]=i+1;
	}
	For(i,1,n){
		scanf("%lld",&b[i]);
		q.push(mp(b[i],i));
	}
	l[1]=n,r[n]=1;
	while(!q.empty()){
		int x=q.top().se;
		//printf("%d %d %d\n",x,b[x],a[x]);
		q.pop();
		if(a[x]==b[x]) continue ;
		if(b[x]-b[l[x]]-b[r[x]]<a[x]){
			printf("-1\n");return 0;
		}
		ans+=(b[x]-a[x])/(b[l[x]]+b[r[x]]);
		b[x]=(b[x]-a[x])%(b[l[x]]+b[r[x]])+a[x];
		if(b[x]!=a[x]) q.push(mp(b[x],x));
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 12656
#include <bits/stdc++.h>
#define ff { ios_base::sync_with_stdio(false);cin.tie(NULL);}
using namespace std;

typedef long long ll;
 ll  pp=1e9+7; 
double pi=3.141592653589793238;
  
 int main() {
        ff;
        ll a;
        cin>>a;
        cout<<a+a*a+a*a*a<<endl;
    return 0;
}

            
		
        
           
  

Measured memory_bytes: 3644
//#define _GLIBCXX_DEBUG
#include<bits/stdc++.h>
#define PI 3.14159265359
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
const long long INF= 1e+18+1;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll> >vvl;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> T;
const ll MOD=1000000007LL;
string abc="abcdefghijklmnopqrstuvwxyz";
string ABC="ABCDEFGHIJKLMNOPQRSTUVWXYZ";
int main(){
  ll n,k;
  cin>>n>>k;
  vl a(n);
  rep(i,n)cin>>a[i];
  ll g=0;
  ll MAX=0;
  rep(i,n){
    MAX=max(MAX,a[i]);
    g=__gcd(g,a[i]);
  }
  if(k<=MAX&&k%g==0){
    cout<<"POSSIBLE"<<endl;
  }
  else {
    cout<<"IMPOSSIBLE"<<endl;
  }
}

Measured memory_bytes: 1024
# coding:utf-8
number = input()
# ABCD 隙間の数は3
n = 3

for bit in range(2 ** n):
    ope = ['-'] * n
    for i in range(n):
        if ((bit >> i) & 1):
            ope[n - 1 - i] = '+'
    # print(ope)
    ans = ''

    for num, op in zip(number, ope):
        ans += num + op
    ans += number[-1]
    if eval(ans) == 7:
        print(ans + '=7')
        exit()


Measured memory_bytes: 3060
#include <iostream>
#include <vector>
using namespace std;
int main() {
 int a,b,c,x,y;
 vector<int> lcm,gcm;
 while(cin >> a >> b) {
 if (a<b) swap(a,b); 
 x=a; y=b;
 while( a % b!=0) { c=b; b=a % b; a=c; }
 lcm.push_back(b); y=y/b; gcm.push_back(y*x);
 }
 for (c=0;c<lcm.size();c++) cout << lcm[c] << " " << gcm[c] << endl; 
 return 0;
}

Measured memory_bytes: 1220
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		int n, i;
		
		Scanner scan = new Scanner(System.in);
		n = scan.nextInt();
		
		int a[] = new int[n];
		
		for(i = 0; i < n; i++) {
			a[i] = scan.nextInt();
		}
		
		for(i = n-1; i >= 0; i--) {
			System.out.print(a[i]);
			if(i > 0) System.out.print(" ");
		}
		System.out.println();
		
	}

}


Measured memory_bytes: 26196
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        String s = sc.nextLine();
        int num = s.length();
        int [] n = new int [num];
        int [] a1 = new int [num];
        int [] a2 = new int [num];
        int cnt1  = 0;
        int cnt2 = 0;
        if (num == 1) {
            System.out.println("0");
        } else if (num == 2) {
            if (n[0] != n[1]) {
                System.out.println("0");
            } else {
                System.out.println("1");
            }
        } else {
            
            for (int i = 0;i<num;i++)  {
                n[i] = Integer.parseInt(s.substring(i,i+1));
                if (0 == (i%2)) {
                    a1[i] = 0;
                    a2[i] = 1;
                } else {
                    a1[i] = 1;
                    a2[i] = 0;
                }
            }
            
            for (int i = 0;i <num;i++){
                if (n[i] !=a1[i]) {
                    cnt1++;
                }
                if (n[i] !=a2[i]) {
                    cnt2++;
                }
            }
            System.out.println(Math.min(cnt1,cnt2));
        }
    }
}


Measured memory_bytes: 36016
def main():
    a = [input() for i in range(2)]
    S = a[0]
    T = a[1]
    count = 1001
    # 網羅的に一致しない文字数をカウント
    for i in range(len(S) - len(T) + 1):
        count_temp = 0
        for j in range(len(T)):
            if S[i + j] != T[j]:
                count_temp += 1
        count = min(count, count_temp)
        if count == 0:
            break
    print(count)


if __name__ == '__main__':
    main()

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

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

    UnionFind(int N) : par(N), cnt(N) {  // 初期化
        for (int i = 0; i < N; i++) {
            par[i] = i;
            cnt[i] = 1;
        }
    }

    void print() {
        for (int i = 0; i < par.size(); i++)
            printf("par[%d] = %d\n", i, par[i]);

        for (int i = 0; i < par.size(); i++)
            printf("cnt[%d] = %d\n", i, cnt[i]);
    }

    int root(int x) {
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) {  // xとyの木を併合
        int rx = root(x);
        int ry = root(y);
        if (rx == ry) return;
        if (cnt[rx] < cnt[ry]) {
            par[rx] = ry;
            cnt[ry] += cnt[rx];
        } else {
            par[ry] = rx;
            cnt[rx] += cnt[ry];
        }
    }

    bool same(int x, int y) {
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }

    int size() {
        int N = par.size();
        set<int> s;
        for (int i = 0; i < N; i++) {
            s.insert(root(i));
        }
        return s.size();
    }

    int count(int x) {
        return cnt[root(x)];
    }
};

int main() {
    int N, M;
    cin >> N >> M;
    UnionFind uf(N);
    vector<int> A(M), B(M);
    rep(i, M) {
        int a, b;
        cin >> a >> b;
        a--;
        b--;
        A[i] = a;
        B[i] = b;
    }
    ll ans = (ll)N * (N - 1) / 2;
    vector<ll> anss(M);
    rep(i, M){
        int now = M - i - 1;
        anss[now] = ans;
        if (!uf.same(A[now], B[now])) {
            ans -= (ll)uf.count(A[now]) * (ll)uf.count(B[now]);
            uf.unite(A[now], B[now]);
        }
    }
    rep(i, M) {
        cout << anss[i] << endl;
    }
}

Measured memory_bytes: 3712