akhauriyash/Code-Regression huggingface dataset:
while True:
    h,w=map(int,input().split())
    if h==0 and w==0:
        break
    for i in range(1,w+1):
        print("#",end="")
    print()
    for j in range(2,h):
        for k in range(1):
            print("#",end="")
        for k in range(1,w-1):
            print(".",end="")
        for k in range(1):
            print("#")
    for l in range(1,w+1):    
        print("#",end="")
    print()
    print()


Measured memory_bytes: 7000
#pragma GCC optimize("O2")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx,avx2,sse,sse2,fma,tune=native")
#include<bits/stdc++.h>
#define all(x) x.begin(), x.end()
#define pb push_back
#include <x86intrin.h>
#define pb push_back
using namespace std;
using ll = long long;
using pi = pair<int, int>;
using vi = vector<int>;
const int maxn = 1e6 + 3;
bool pal(string s) {
	for(int i = 0; i < s.size(); i++) if(s[i] != s[s.size()-1-i]) return false;
	return true;
}
int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	int n;
	map<int, ll> cnt;
	ll ans = 0;
	vi a;
	cin >> n;
	a.resize(n);
	for(auto &i : a) cin >> i, cnt[i]++;
	for(auto i : cnt) ans += i.second*(i.second-1)/2;
	for(auto i : a) {
		cout << ans - cnt[i] + 1 << '\n';
	}
}


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


float func(float x,float y){
    return (x+y)/2;
}

int main(){
    int N;
    cin >> N;
    vector<float>v(N);
    for (int i=0;i<N;++i) cin >> v[i];
    sort(v.begin(),v.end());
    float ans = func(v[0],v[1]);
    for (int i=2;i<N;++i){
        ans = func(ans,v[i]);
    }
    cout << ans << endl;
}




Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    string s;
    cin>>s;
    if(s=="Sunny"){
            cout<< "Cloudy" <<endl;
    }
    else if(s=="Cloudy"){
            cout<< "Rainy" <<endl;
    }
    else{
            cout<< "Sunny" <<endl;
    }    
}


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

using namespace std;

int main(int argc, char *argv[]) {
    int N, M;
    cin >> N >> M;
    vector<pair<int, int>> arr(M);
    for (int j = 0; j < M; j++) {
        int s, c;
        cin >> s >> c;
        arr[j] = make_pair(s, c);
    }
    int ans = -1;
    for (int i = 0; i <= (pow(10, N) - 1); i++) {
        string si = to_string(i);
        if (N != si.size()) {
            continue;
        } else {
            bool ok(true);
            for (auto &p: arr) {
                int s = p.first;
                int c = p.second;
                if (si[s - 1] != c + '0') {
                    ok = false;
                    break;
                }
            }
            if (!ok) {
                continue;
            } else {
                ans = i;
                break;
            }
        }
    }
    cout << ans << endl;
    return 0;
}


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

struct UnionFind {
    int parent[200001];

    UnionFind(int n) {
        for (int i = 1; i <= n; i++) parent[i] = i;
    }

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

    bool same(int x, int y) {
        return parent[x] == parent[y];
    }

    void unite(int x, int y) {
        if (same(x, y)) return;
        parent[root(x)] = root(y);
    }
};

int main() {
    int n, m;
    int a[200000], b[200000];
    cin >> n >> m;
    for (int i = 0; i < m; i++) cin >> a[i] >> b[i];

    UnionFind uf(n);
    for (int i = 0; i < m; i++) uf.unite(a[i], b[i]);

    int count[200001];
    for (int i = 1; i <= n; i++) count[i] = 0;
    for (int i = 1; i <= n; i++) count[uf.root(i)]++;
    
    int ans = 0;
    for (int i = 1; i <= n; i++) {
        if (count[i] > ans) ans = count[i];
    }

    cout << ans << endl;
}


Measured memory_bytes: 9700
from collections import deque

N = int(input())
A = list(map(int, input().split()))

A = deque(A)
left = 0
right = 0
while len(A) > 1:
    if (left <= right):
        left += A.popleft()
    else:
        right += A.pop()
if left < right:
    left += A.pop()
else:
    right += A.pop()

print(max(left, right) - min(left, right))


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

int main()
{
  ll x, y;

  cin >> x >> y;

  ll ans = 0, n = x;

  while(y>=n){
    ans += 1;
    n *= 2;
  }

  cout << ans;

}


Measured memory_bytes: 3608
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<iomanip>
#include <math.h>
using namespace std;
int main(){
    string s,t,n,ans;
    int a=-1;
    cin>>s>>t;
    n="abcdefghijklmnopqrstuvwxyz";
    ans="Yes";
    for(int i=0;i<26;i++){
        for(int j=0;j<s.size();j++){
            if(s[j]==n[i]){
                if(a==-1){
                    a=j;
                }
                else{
                    if(t[j]!=t[a]){
                        ans="No";
                        break;
                    }
                    else{
                        a=j;
                    }
                }
            }
        }
        if(ans=="No"){
            break;
        }
        a=-1;
    }
    for(int i=0;i<26;i++){
        if(ans=="No"){
            break;
        }
        for(int j=0;j<t.size();j++){
            if(t[j]==n[i]){
                if(a==-1){
                    a=j;
                }
                else{
                    if(s[j]!=s[a]){
                        ans="No";
                        break;
                    }
                    else{
                        a=j;
                    }
                }
            }
        }
        if(ans=="No"){
            break;
        }
        a=-1;
    }
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3832
#include<bits/stdc++.h>
//#pragma GCC optimize ("-O3")

using namespace std;
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
//const long double PI = 3.14159265358979323846;  /* pi */

int main() {
    //ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr);
    int n;
    cin >> n;
    string s;
    cin >> s;

    int i = 0, j = n-1;
    int ans = 0;
    while (i <= j)
    {
        if (s[i] == 'R')
            i ++;
        else if (s[j] == 'W')
            j --;
        else
        {
            ans ++;
            i ++;
            j --;
        }
    }
    cout << ans << "\n";

    return 0;
}


Measured memory_bytes: 3724
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for (int i = (a); i <= (b); ++ i)
#define rrp(i,a,b) for (int i = (a); i >= (b); -- i)
#define gc() getchar()
#define fir first
#define sec second
typedef pair<int,int> pii;
typedef double db;
typedef long long ll;
template <typename tp>
inline void read(tp& x) {
  x = 0; char tmp; bool key = 0;
  for (tmp = gc(); !isdigit(tmp); tmp = gc())
    key = (tmp == '-');
  for (; isdigit(tmp); tmp = gc())
    x = (x << 3) + (x << 1) + (tmp ^ '0');
  if (key) x = -x;
}
template <typename tp>
inline void ckmn(tp& x,tp y) {
  x = x < y ? x : y;
}
template <typename tp>
inline void ckmx(tp& x,tp y) {
  x = x < y ? y : x;
}

const int MOD = (int)(1e9 + 7);
inline void Add(int& x,int y) {
  x = x + y >= MOD ? x + y - MOD : x + y;
}
inline void Sub(int& x,int y) {
  x = x - y < 0 ? x - y + MOD : x - y;
}
int power(int a,int b) {
  int ret = 1;
  while (b) {
    if (b&1) ret = 1ll * ret * a % MOD;
    a = 1ll * a * a % MOD;
    b >>= 1;
  }
  return ret;
}
const int N = 200010;
int n, val[N], cnt[N], rec[N], lp[N], rp[N], pre[N], sum, ans;
struct BIT {
#define lowbit(x) ((x) & (-(x)))
  int v[N];
  void add(int p,int val) {
    for (; p <= n; p += lowbit(p))
      Add(v[p], val);
  }
  int ask(int p) {
    int ret = 0;
    for (; p; p -= lowbit(p))
      Add(ret, v[p]);
    return ret;
  }
  int query(int l,int r) {
    int ret = ask(r);
    Sub(ret, ask(l-1));
    return ret;
  }
} b1, b2, b3;
int main() {
  read(n);
  rep (i, 1, n) read(val[i]);
  rep (i, 1, n) ++ cnt[val[i]];
  rrp (i, n-1, 1) cnt[i] += cnt[i+1];
  rep (i, 1, n) cnt[i] -= (n-i);
  sum = 1;
  rep (i, 1, n) sum = 1ll * sum * cnt[i] % MOD;
  rep (i, 1, n) rec[i] = 1ll * (cnt[i]-1) * power(cnt[i], MOD - 2) % MOD;
  for (int i = 1, j = 1; i <= n; ++ i) {
    if (rec[i] == 0) pre[i] = 1, j = i;
    else pre[i] = 1ll * pre[i-1] * rec[i] % MOD;
    lp[i] = j;
  }
  for (int i = n, j = n; i >= 1; -- i) {
    rp[i] = j;
    if (rec[i] == 0) j = i-1;
  }
  rep (i, 1, n) {
    // pre[Aj] / pre[Ai]
    int tmp = b2.query(lp[val[i]], val[i]);
    Add(ans, 1ll * tmp * pre[val[i]] % MOD * sum % MOD * (MOD + 1) / 2 % MOD);
    // sum - pre[Ai] / pre[Aj] * sum / 2
    tmp = b3.query(val[i] + 1, n);
    Add(ans, 1ll * tmp * sum % MOD);
    tmp = b1.query(val[i] + 1, rp[val[i]]);
    Sub(ans, 1ll * tmp * power(pre[val[i]], MOD-2) % MOD * sum % MOD * (MOD+1)/2 % MOD);
    b1.add(val[i], pre[val[i]]);
    b2.add(val[i], power(pre[val[i]], MOD - 2));
    b3.add(val[i], 1);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 7296
N = int(input())
csf = [list(map(int,input().split())) for i in range(N-1)]
for i in range(N-1):
    ans = csf[i][1]+csf[i][0]
    for j in range(i+1,N-1):
        if ans <= csf[j][1]:
            ans = csf[j][1]
        else:
            f = ans%csf[j][2]
            if f != 0:
                ans += csf[j][2]-f
        ans += csf[j][0]
    print(ans)
print(0)

Measured memory_bytes: 9080
#include <iostream>
#include <string>
using namespace std;
int main(void) {
	int  i,n, l[100000],p=0;
	cin >> n ;
	for (i = 1; i < n+1; i++) {
		cin >> l[i];
	}
	for (i = 1; i < n; i++) {
		if (i == l[l[i]]) {
			p++;
			l[i] = -10;
			l[l[i]] = -1;
		}
	}

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

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define sz(arr) (int)arr.size()
#define all(arr) arr.begin(), arr.end()

using namespace std;
typedef long long ll;

void _cin() {}
template <class Head, class... Tail>
void _cin(Head&& head, Tail&&... tail) {
  cin >> head;
  _cin(forward<Tail>(tail)...);
}

#define Cin(T, ...) \
  T __VA_ARGS__;    \
  _cin(__VA_ARGS__)

int main() {
  Cin(int, n);

  int ans = 1;
  while (1) {
    if ((ans + 1) * (ans + 1) > n) break;
    ans++;
  }

  cout << ans * ans << endl;

  return 0;
}

Measured memory_bytes: 256
import math
N, H = map(int, input().split())
A = []
r = []
for _ in range(N):
    a, b = map(int, input().split())
    A.append([a, 0])
    A.append([b, 1])
A.sort()
ans = 0
while H > 0:
    p = A.pop()
    if p[1] == 1:
        H -= p[0]
        ans += 1
    else:
        ans += math.ceil(H / p[0])
        break
print(ans)


Measured memory_bytes: 30656
#include <bits/stdc++.h>
#define repz(i, z, n) for (decltype(n) i = (z); i < (n); i++)
#define rep(i, n) for (decltype(n) i = 0; i < (n); i++)

#define REPZ(i, z, n) for (decltype(n) i = (z); i <= (n); i++)
#define REP(i, n) for (decltype(n) i = 0; i <= (n); i++)
#define ALL(v) v.begin(), v.end()
#define SIZE(v) ((ll)(v).size())
#define MAX(v) (*max_element(ALL(v)))
#define MIN(v) (*min_element(ALL(v)))
#define INF 1000000000000  // 1E+12

// 略
#define PB push_back
#define F first
#define S second
#define MP make_pair
#define READ cin >>
#define PRINT cout <<
#define PYES cout << "YES" << endl
#define pyes cout << "Yes" << endl
#define POK cout << "OK" << endl
#define PNO cout << "NO" << endl
#define pno cout << "No" << endl
#define PNG cout << "NG" << endl
#define ret return 0

using namespace std;

// デバッグ用
void debug_out() { cout << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cout << H << " ";
  debug_out(T...);
}

template <class T>
bool chmax(T &a, const T &b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
template <class T>
bool chmin(T &a, const T &b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}

#ifdef _DEBUG
#define debug(...) debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

// typedef
typedef long long ll;
typedef unsigned long long ul;
typedef long double ld;
typedef pair<ll, ll> pl;

// const
// 円周率
const ld pi = acos(-1);
// mod用
// 1E+9 +7
const ll mod = (int)1e+9 + 7;
// 1s間で可能なループ回数2E+8回
// int        最大値2147483647         〜2E+9
// long long  最大値9223372036854775807〜9E+18
// 総和accumulate
// 単純リストvector<type> push_back
// 連想配列map<key,value> insert,
// 集合set<type>
// pair キーとバリューを格納 firstとsecondでアクセス
// 小数点指定 cout << fixed << setprecision(15) << endl;
// to_string<->stoi
// stoll(longlong)
// stod(double)
// deep copy v1->v2 copy(v1.begin(), v1.end(), back_inserter(v2) );
// 大文字65-90(-32)
// 小文字97-122(+32)
//  priority_queue<pair<ll, ll>, vector<pair<ll, ll>>, greater<pair<ll, ll>>>
//  ba;
signed main() {
  // faster
  // C言語流の入出力は使用できない
  ios::sync_with_stdio(false);
  std::cin.tie(nullptr);
  char a; cin >> a;
  if(97<=a and a<=122) cout <<'a' << endl;
  else cout << 'A' << endl;
  ret;
}


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

typedef long long int ll;

int main()
{
    ll n, k;
    double ans;
    cin >> n >> k;
    vector<ll> p(n);
    for(ll i = 0;i < n;i++){
        cin >> p[i];
        //p[i] = 1000;
    }

    ans = 0;
    vector<ll> sum(n);
    sum[0] = p[0];
    for(ll i = 1;i < n;i++){
        sum[i] += sum[i - 1] + p[i];
    }

    ans = (double)(sum[k - 1] + k) / 2;
    //cout << ans << endl;
    for(ll i = k;i < n;i++){
        double t = (double)(sum[i] - sum[i - k] + k) / 2;
        //cout << t << endl;
        ans = max(ans, t);
    }

    cout << setprecision(10) << ans;
   
    return 0;
}

Measured memory_bytes: 3328
//ABC065C
#include <bits/stdc++.h>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <math.h>
#include <stdio.h>
#include <climits>
#include <cfloat>
#include <string>
#include <unordered_map>
using namespace std;

int main(){
	int n, m;
	cin >> n >> m;
	long long int mod = 1e9+7;
	if(abs(n-m) >= 2){
		cout << 0 << endl;
	}else{
		long long int ans = 1;
		if(n == m){
			ans *= 2;
		}
		while(n > 0){
			ans *= n;
			ans %= mod;
			n--;
		}
		while(m > 0){
			ans *= m;
			ans %= mod;
			m--;
		}
		cout << ans << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,o,n) for(long long i = o;i<n;i++)
#define oneforall ios::sync_with_stdio(false);cin.tie(0);
#define all(v) (v).begin(),(v).end()
#define ini(...) int __VA_ARGS__; in(__VA_ARGS__)
#define inl(...) long long __VA_ARGS__; in(__VA_ARGS__)
#define ins(...) string __VA_ARGS__; in(__VA_ARGS__)
const long long INF=1e18;
void in(){} template <typename T,class... U> void in(T &t,U &...u){ cin >> t; in(u...);}
void out(){cout << "\n";} template <typename T,class... U> void out(const T &t,const U &...u){ cout << t; if(sizeof...(u)) cout << " "; out(u...);}
typedef vector<int> vi;
typedef vector<long long> vl;
typedef long long ll;
typedef vector<pair<long,long>> vpll;
typedef vector<pair<int,int>> vpii;
int main() {
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	oneforall
	ini(n);
	vi a(n);
	vi satisfaction(n);
	vi moresatis(n);
	FOR(i,0,n){in(a[i]);}
	FOR(i, 0, n) { in(satisfaction[i]); };
	FOR(i, 0, n - 1) { in(moresatis[i]); };
	int total = satisfaction[a[0]-1];
	FOR(i,1,n){
		total+=satisfaction[a[i]-1];
		if(a[i] == a[i-1]+1)total+=moresatis[a[i-1]-1];
	}
	out(total);
	return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;cin>>N;
  map<string,int>mp;
  vector<pair<int,string>>V(0);
  for(int X=0;X<N;X++){
    string S;cin>>S;mp[S]++;
  }
  int D=0;
  for (auto p : mp) {
    auto k=p.first;auto v=p.second;
    V.push_back(make_pair(v,k));
  }
  sort(V.begin(),V.end());
  int U;
  vector<string>VE(0);
  for(int X=V.size()-1;X>=0;X--){
    int C;string D;tie(C,D)=V[X];
    if(X==V.size()-1)U=C;
    else if(C!=U)break;
    VE.push_back(D);
  }
  for(int X=VE.size()-1;X>=0;X--)cout<<VE[X]<<endl;
}

Measured memory_bytes: 41084
/// 0002: Digit Number

use std::io;

pub fn main() {
    loop {
        let mut buf = String::new();
        let _ = io::stdin().read_line(&mut buf);

        if buf == "" { break; }

        let v: Vec<_> = buf.split_whitespace().collect();
        let a: i32 = v[0].parse().unwrap();
        let b: i32 = v[1].parse().unwrap();
        println!("{}", (a + b).to_string().len())
    }
}

Measured memory_bytes: 5048
def main():
  while True:
    n,k = map(int,input().split())
    if n == 0 and k == 0:
      break
    lst = []
    for i in range(n):
      lst.append(int(input()))
    count = 0
    for i in range(k):
      count += lst[i]
    ans = count
    for i in range(k, n):
      count += lst[i]
      count -= lst[i - k]
      ans = max(ans,count)
    print(ans)

if __name__ == '__main__':
  main()  


Measured memory_bytes: 9612
S = str(input())
odd_number = [word for i, word in enumerate(S) if (i + 1) % 2 == 1]
even_number = [word for i, word in enumerate(S) if (i + 1) % 2 == 0]

odds = set(odd_number) - set(["R", "U", "D"])
evens = set(even_number) - set(["L", "U", "D"])
del odd_number, even_number, S

if len(odds) == 0 and len(evens) == 0:
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
using ll = long long;

int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	ll x[n];
	for (int i = 0;i < n;i++)cin >> x[i];
	ll ans = 0;
	for (int i = 1;i < n;i++) {
		ans += min((x[i] - x[i - 1])*a, b);
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) {
        int N, CR=0,CG=0,CB=0;
        String S;
        int[] R =new int[4000];
        int[] G =new int[4000];
        int[] B =new int[4000];
        Scanner sc = new Scanner(System.in);
        N = sc.nextInt();
        S= sc.next();

        for(int i=0; i<S.length(); i++) {
            if (S.charAt(i) == 'R') {
                R[CR] = i;
                CR++;
            }
            if (S.charAt(i) == 'G') {
                G[CG] = i;
                CG++;
            }
            if (S.charAt(i) == 'B') {
                B[CB] = i;
                CB++;
            }
        }
        Long res = (long)CR*CG*CB;
        for(int i=0; i< CR; i++){
            for(int j=0; j<CG; j++){
                if((R[i]+G[j])%2==0 && Arrays.binarySearch(B,0,CB,(R[i]+G[j])/2)>=0)
                    res--;
            }
        }
        for(int i=0; i< CG; i++){
            for(int j=0; j<CB; j++){
                if((G[i]+B[j])%2==0 && Arrays.binarySearch(R,0,CR,(G[i]+B[j])/2)>=0)
                    res--;
            }
        }
        for(int i=0; i< CB; i++){
            for(int j=0; j<CR; j++){
                if((B[i]+R[j])%2==0 && Arrays.binarySearch(G,0,CG,(B[i]+R[j])/2)>=0)
                    res--;
            }
        }
        System.out.println(res<0?0:res);

    }
}


Measured memory_bytes: 52904
//n 人の学生を含むクラスでプログラミングの試験を行った。それぞれの得点をs1, s2 ... snとしたときの、標準偏差を求めるプログラムを作成せよ。
//得点の平均値をｍとすれば、分散α2は以下の式で得られる：
//α2 = (∑ni=1(si - m)2)/n
//分散の正の平方根が標準偏差αとなる。

//\

#include <iostream>
#include <stdio.h>
#include <math.h>

using namespace std;

int main()
{
    
    int N = -1;
    
    cin >> N;
       
    while( N != 0)
    {
       double s[N];
       double m = 0;
       for(int i = 0; i < N; ++i)
       {
          int a;
          cin >> a;
          s[i] = a;
          m += a;
       }
       m /= N;
       
       double alpha = 0.0;
       for(int i = 0; i < N; ++i)
       {
           alpha += (s[i] - m) * (s[i] - m) / N;
       }

        printf("%f\n", sqrt(alpha));
        cin >> N;
       
    }
    return 0;
    
}


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

int main() {
    string s;
    int n;
    int max=0;
    cin>>n>>s;
    for(int i=0; i<n; i++) {
        vector<bool> a(256, false);
        int sum=0;
        for(int j=0; j<i; j++) {
            a[s[j]] = true;
        }
        for(int j=i; j<n; j++) {
            if(a[s[j]]) {
                sum++;
                a[s[j]]=false;
            }
        }
        if(sum>max) max=sum;
    }
    cout<<max<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long
#define endl "\n"


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  string s,t;
  cin>>s>>t;
  int ans=0;
  rep(i,3){
    if(s[i]==t[i]) ans++;
  }
  cout<<ans<<endl;

  return 0;
}

Measured memory_bytes: 764
#include <bits/stdc++.h>
//登録しよう！→ https://www.youtube.com/channel/UCRXsI3FL_kvaVL9zoolBfbQ
using namespace std;
using ll = long long;
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}//a,bの最大公約数(gcd)を求める
ll lcm(ll a,ll b){return abs(a*b)/gcd(a,b);}//a,bの最小公倍数(lcm)を求める
vector<ll> enum_div(ll n){vector<ll> ret;for(int i=1 ; i*i<=n ; i++){if(n%i == 0){ret.push_back(i);if(i!=1 && i*i!=n)ret.push_back(n/i);}}ret.push_back(n);return ret;}
//↑nの約数を求める
vector<bool> IsPrime; void sieve(size_t max){if(max+1 > IsPrime.size())IsPrime.resize(max+1,true);IsPrime[0] = false;IsPrime[1] = false;for(size_t i=2; i*i<=max; ++i)if(IsPrime[i])for(size_t j=2; i*j<=max; ++j)IsPrime[i*j] = false;}
//↑エラトステネスの篩で素数を求める
#define roundup(divisor,dividend) (divisor + (dividend - 1)) / dividend //切り上げ割り算
#define all(x) (x).begin(),(x).end() //xの初めから終わりまでのポインタ
#define size_t ll //size_tは自動でllに変換される
#define pb(x) push_back(x)
#define gre greater //sortを降順にする
#define pri_queue priority_queue //優先度付きキュー
#define syo(x) fixed << setprecision(x) //iostreamで小数をx桁表示

void solve(std::string S){
  ll ans = 0;
  for (ll i = 1; i <= S.length(); i++) {
    for (ll l = 0; l < S.length() - i + 1; l++) {
      string s = S.substr(l,i);
      bool x = true;
      for (ll n = 0; n < i; n++) {
        if(!(s[n] == 'A' || s[n] == 'C' || s[n] == 'G' || s[n] == 'T')){
          x = false;
          break;
        }
      }
      if(x)ans = max(ans,i);
    }
  }
  cout << ans << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    std::string S;
    std::cin >> S;
    solve(S);
}


Measured memory_bytes: 256
// Problem : F - path pass i
// Contest : AtCoder - AtCoder Beginner Contest 163
// URL : https://atcoder.jp/contests/abc163/tasks/abc163_f
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define rep(i,a,n) for (int i=a;i<n;i++)
#define per(i,a,n) for (int i=n-1;i>=a;i--)
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define SZ(x) ((int)(x).size())
typedef vector<int> VI;
typedef long long ll;
typedef pair<int,int> PII;
typedef double db;
//mt19937 mrand(random_device{}()); 
const ll mod=1000000007;
const int INF = 0x3f3f3f3f;
//int rnd(int x) { return mrand() % x;}
ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

const int maxn = 2e5 + 10; 

// hdu 6035

int n,c[maxn];
ll ans[maxn],sum[maxn],sz[maxn];
vector<int>g[maxn];

void dfs(int u = 1, int fa = 0) {
	sz[u] = 1;
	ll allson = 0;
	for(int i = 0; i < (int) g[u].size(); ++i) {
		int v = g[u][i];
		if(v == fa) continue;
		ll last = sum[c[u]];
		dfs(v,u);
		ll add = sum[c[u]] - last;
		allson += sz[v] - add;
		ans[c[u]] -= (sz[v] - add + 1) * (sz[v] - add) / 2;
		sz[u] += sz[v];
	}
	sum[c[u]] += allson + 1;
}


int main()
{
	fastIO;
	cin >> n;
	rep(i,1,n + 1) cin >> c[i];
	rep(i,0,n - 1) {
		int u,v;
		cin >> u >> v;
		g[u].pb(v);
		g[v].pb(u);
	}	
	rep(i,1,n + 1) ans[i] = (ll) n * (n + 1) / 2;
	dfs();
	rep(i,1,n + 1) {
		ans[i] = ans[i] - (n - sum[i] + 1) * (n - sum[i]) / 2;
		cout << ans[i] << endl;
	}
	return 0;
}

Measured memory_bytes: 38724
s=input()
K=1
tmp=s[0]
i=0
if len(s)==1:
    print(1)
elif len(s)==2:
    if s[0]==s[1]:
        print(1)
    else: print(2)
else:
    while i<len(s)-1:
        if tmp==s[i+1] and i<len(s)-2:
            tmp=s[i+1]+s[i+2]
            K+=1
            i=i+2
        elif tmp!=s[i+1]:
            K+=1
            tmp=s[i+1]
            i=i+1
        elif i==len(s)-2:
            break
    print(K)

Measured memory_bytes: 3500
#include <iostream>
#include <cmath>
#include <vector>
#include <algorithm>

using namespace std;

vector<int> Vec;
int n;
int Ans;
static const int INF = 1e+9;

void DFS(int a, int b, int depth)
{
	if(depth == n)
	{
		Ans = min(Ans, abs(a - b));
	}
	else
	{
		DFS(a + Vec[depth], b, depth + 1);
		DFS(a, b + Vec[depth], depth + 1);
	}
}

void solve()
{
	while(cin >> n, n)
	{
		Vec.resize(n);
		for(int i = 0; i < n; ++i)
		{
			cin >> Vec[i];
		}
		Ans = INF;
		DFS(0, 0, 0);
		cout << Ans << endl;
	}
}

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

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

constexpr int inf = 1e9;
constexpr ll linf = 1e18;

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

    int n, W; cin >> n >> W;
    vector<int> v(n), w(n);
    for (int i = 0; i < n; i++) cin >> v[i] >> w[i];

    vector<int> dp(W + 1, 0);
    for (int i = 0; i < n; i++) {
        for (int j = w[i]; j <= W; j++) {
            dp[j] = max(dp[j], dp[j - w[i]] + v[i]);
        }
    }

    cout << dp[W] << endl;
    return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	int N; cin >> N;

	int ans = INT_MAX;

	for (int i = 0;i <= N;i++){
		int cnt = 0;
		int A = i;
		while(A){
			cnt += A%6; A /= 6;
		}
		int B = N-i;
		while(B){
			cnt += B%9; B /= 9;
		}
		ans = min(ans,cnt);
	}

	cout << ans << endl;

	return 0;

}


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

typedef long long ll;

const ll MOD = 1000000007;

int main() {
    ll N;
    string s1, s2;
    ll i = 0;
    ll ans = 1;
    bool state;
    cin >> N;
    cin >> s1;
    cin >> s2;

    if (s1[i]== s2[i]) {
        state = true;
        ans *= 3;
        i++;
    } else {
        state = false;
        ans *= 6;
        i += 2;
    }
    while (i < N) {
        if (s1[i] == s2[i]) {
            if (state) {
                ans *= 2;
            } else {
                state = true;
            }
            i++;
        } else {
            if (state) {
                ans *= 2;
                state = false;
            } else {
                ans *= 3;
            }
            i += 2; 
        }
    }

    cout << ans % MOD << endl;
}


Measured memory_bytes: 256
n,y = map(int,input().split())
if y % 1000 != 0:
    print('-1 -1 -1')
    exit()
y /= 1000

for i in range(int(y//10+1)):
    for j in range(int(y//5+1)):
        k = n-i-j
        if 10*i + 5*j + k == y and k>=0:
            print(i,j,k)
            exit()
print('-1 -1 -1')

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

char str[112345];

int main() {
  scanf("%s", &str);
  int n = strlen(str);
  int res = 0;
  for(int i = 1; i < n; ++i) {
    if( str[i-1] != str[i] ) res += 1;
  }

  printf("%d\n", res);
  
  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
int main()
{
    int n,m;
    uint32_t total = 0;
    std::cin >> n >>m;
    std::vector<int> vals;
    vals.reserve(n);
    for (int i = 0; i < n; ++i) {
        auto tmp = 0;
        std::cin >> tmp;
        vals.emplace_back(tmp);
        total += tmp;
    }

    std::sort(vals.rbegin(), vals.rend());
    if (vals[m - 1]* 4 * m < total) {
        std::cout << "No" << std::endl;
    }
    else {
        std::cout << "Yes" << std::endl;
    }


    return 0;
}

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

#define int long long
typedef pair<int, int> P;
#define mod 1000000007
#define INF (1LL<<60)
 
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define repi(itr, ds) for (auto itr = ds.begin(); itr != ds.end(); itr++)
#define YES puts("YES")
#define Yes puts("Yes")
#define NO  puts("NO")
#define No  puts("No")
int gcd(int a, int b) { return b ? gcd(b, a % b) : a; }
 
const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
 
 
#if 1
//-------------
// DUMPマクロ
// https://www.creativ.xyz/dump-cpp-652/
 
// 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
#endif


signed main() {

    int n;
    cin>>n;
    string s;
    cin>>s;
    int x=0;
    int ans=0;
    rep(i,s.size()){
        if(s[i]=='I')x++;
        else x--;
        ans = max(ans,x);
    }
    cout <<ans<<endl;
    
    
    return 0;
}


Measured memory_bytes: 256
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use itertools::Itertools;
use num::clamp;
use proconio::{input, marker::*, fastout};
use superslice::*;

#[fastout()]
fn main() {
    input! {
        n: usize,
        s: [String; n],
    }

    let mut map = BTreeMap::new();
    for s in s {
        *map.entry(s).or_insert(0) += 1i64;
    }
    let most = *map.values().max().unwrap();
    for (k, v) in map {
        if v == most {
            println!("{}", k);
        }
    }
}


Measured memory_bytes: 27552
#include <stdio.h>

int main(void)
{
	int sx,sy,tx,ty,i;
	scanf("%d%d%d%d",&sx,&sy,&tx,&ty);

	for(i=0;i<tx-sx;i++)
		printf("%c",'R');
	for(i=0;i<ty-sy;i++)
		printf("%c",'U');
	for(i=0;sx-tx<i;i--)
		printf("%c",'L');
	for(i=0;sy-ty<i;i--)
		printf("%c",'D');
	printf("%c",'D');
	for(i=0;i<tx-sx+1;i++)
		printf("%c",'R');
	for(i=0;i<ty-sy+1;i++)
		printf("%c",'U');
	printf("%c",'L');
	printf("%c",'U');
	for(i=0;sx-tx-1<i;i--)
		printf("%c",'L');
	for(i=0;sy-ty-1<i;i--)
		printf("%c",'D');
	printf("%c\n",'R');

	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define PB push_back
#define rep(i,a,b) for(int i=(a);i<=(b);++i)
#define per(i,a,b) for(int i=(a);i>=(b);--i)
using namespace std;
typedef vector<int>VI;
typedef long long LL;
const int N=100005,P=998244353,B=(LL)1e18%P;
int n,pw[N],m[3],sg[3][N],mx[3],f[3][N];VI G[N];bool ban[N];
int main(){
	scanf("%d",&n);
	pw[0]=1;rep(i,1,N-1)pw[i]=1LL*pw[i-1]*B%P;
	rep(i,0,2){
		scanf("%d",&m[i]);
		rep(j,1,n)G[j].clear();
		rep(j,1,m[i]){
			int k1,k2;scanf("%d%d",&k1,&k2);
			if(k2<k1)swap(k1,k2);
			G[k1].PB(k2);
		}
		per(k1,n,1){
			for(auto j:G[k1])ban[sg[i][j]]=1;
			int&k=sg[i][k1];
			while(ban[k])++k;
			for(auto j:G[k1])ban[sg[i][j]]=0;
		}
		rep(j,1,n){
			(f[i][sg[i][j]]+=pw[j])%=P;
			mx[i]=max(mx[i],sg[i][j]);
		}
	}
	int ans=0;
	rep(i,0,mx[0])rep(j,0,mx[1])(ans+=1LL*f[0][i]*f[1][j]%P*f[2][i^j]%P)%=P;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 7936
N,M = map(int, input().split())
S = input()
cnt = 0
for s in S:
    if s == "0":
        cnt = 0
    else:
        cnt += 1
        if cnt >= M:
            print(-1)
            exit()


"""
辞書順最小
・より少ない回数でゴール
・同じ回数なら、低い数字ほど左にくる

N歩先がゴール　→　出目の合計がNになったらOK
iマス目を踏むとゲームオーバー　→　途中で出目の合計がiになるとアウト

ただ、辞書順が厄介
N=4, 00000があったとして、M=3の場合、3->1より1->3の方が辞書順で若い。なので、スタート地点から貪欲に進めるだけ進む、は条件を満たさない。
→　ゴールからスタートに帰る。移動方法は貪欲にする。
"""

ans = []
rS = S[::-1]
l = 0
r = 1
while l < N:
    r = l + 1
    stoppable = l
    while r - l <= M and r <= N:
        if rS[r] == "0":
            stoppable = r
        r += 1
    
    ans.append(stoppable - l)

    l = stoppable

print(*ans[::-1])

Measured memory_bytes: 51056
#include <iostream>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <algorithm>	// require sort next_permutation count __gcd reverse etc.
#include <cstdlib>	// require abs exit atof atoi 
#include <cstdio>		// require scanf printf
#include <functional>
#include <numeric>	// require accumulate
#include <cmath>		// require fabs
#include <climits>
#include <limits>
#include <cfloat>
#include <iomanip>	// require setw
#include <sstream>	// require stringstream 
#include <cstring>	// require memset
#include <cctype>		// require tolower, toupper
#include <fstream>	// require freopen
#include <ctime>		// require srand
#define rep(i,n) for(int i=0;i<(n);i++)
#define ALL(A) A.begin(), A.end()
#define INF 1<<30

using namespace std;

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

const int dr[] = { -1, 0, 1, 0  };
const int dc[] = {  0, 1, 0, -1 };
int grid[8][8];
int tmin[8][8][7];

struct Ant{
	int t, hp, row, col;
	Ant (int _t, int _hp, int _row, int _col ) : t(_t), hp(_hp), row(_row), col(_col){}
};

bool operator>(const Ant & a, const Ant & b ){return a.t > b.t; }

int main()
{
//	cut here before submit 
//	freopen ("testcase.WA", "r", stdin );
	int w, h;

	while (scanf ("%d %d", &w, &h ), w, h ){
		int srow, scol;
		rep (i, h ) rep (j, w ){
			scanf (" %d", &grid[i][j] );
			if (grid[i][j] == 2 ){
				srow = i, scol = j;
			} // end if
		} // end rep
		rep (i, h ) rep (j, w ) rep (h, 7 ) tmin[i][j][h] = INF;
		tmin[srow][scol][6] = 0;

		int res = -1;
		priority_queue<Ant, vector<Ant>, greater<Ant> > que;
		que.push (Ant(0, 6, srow, scol ) );
		while (!que.empty() ){
			Ant curr = que.top(); que.pop();
			int t  = curr.t;
			int hp = curr.hp;
			int cr = curr.row;
			int cc = curr.col;
			if (hp == 0 ) continue;
			if (grid[cr][cc] == 3 ){ res = t; break; }
			if (tmin[cr][cc][hp] < t ) continue;
			if (grid[cr][cc] == 4 ) hp = 6;
			
			rep (k, 4 ){
				int nr = cr + dr[k];
				int nc = cc + dc[k];
				if (nr < 0 || nr >= h || nc < 0 || nc >= w ) continue;
				if (grid[nr][nc] == 0 ) continue;
				if (tmin[nr][nc][hp-1] <= t + 1 ) continue;
				que.push (Ant(t+1, hp-1, nr, nc ) );
				tmin[nr][nc][hp-1] = t+1;
			} // end rep
		} // end while

		printf ("%d\n", res );
	} // end while

	return 0;
}

Measured memory_bytes: 1192
//#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>

#define IOS ios::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define endl '\n'
#define elif else if
#define lli long long int
#define ld long double
#define vec vector
#define forn(a) for(lli a=0; a<n; a++)
#define all(x) x.begin(), x.end()
#define deb(x) cerr<<#x<<" = "<<x<<endl

using namespace std;

int main(){
  IOS;

  lli n; cin>>n;
  vec<lli> v(n);
  forn(i) cin>>v[i];
  sort(all(v));

  if(n%2==0){//caso par
    // - igual a 0, 2, 4, ...
    lli sum = 0;
    lli i;
    for(i=0; i<n-1; i+=2){
      if(v[i]>=0) break;
      if( -v[i+1]-v[i] < 0 ) break;
      sum += -v[i]-v[i+1];
    }
    for(; i<n; i++) sum+=v[i];
    cout<<sum<<endl;
  }else{//caso impar
    // - igual a 1, 3, 5, ...
    lli sum = -v[0]-v[1];//max((v[0]+ v[1]), (-v[0]-v[0]));
    lli i;
    for(i=2; i<n-1; i+=2){
      if(v[i]>=0) break;
      if( -v[i+1]-v[i] < 0 ) break;
      sum += -v[i]-v[i+1];
    }
    for(; i<n; i++) sum+=v[i];
    cout<<sum<<endl;
  }

  return 0;
}

/*
  int n; cin>>n;
  vec<int> v(n);
  forn(i) cin>>v[i];
  sort(all(v));//??

  vec< map<int, int> > divisores(n);
  forn(i){
    int x = v[i];
    int hasta = sqrtl(x);
    for(int d=2; d<=hasta+1; d++){
      if(x%d==0){
        divisores[i][d]++;
        x/=d;
      }
    }
    if(x!=1 && x!=0) divisores[i][x]++;
  }

  int min_size = divisores[0].size();
  for(auto &it: divisores){
    if(min_size < it.size()) min_size = it.size();
  }

  map<int, int> divisores_comunes = divisores[0];
  forn(i){
    map<int, int> intersec;
    for(auto it: divisores[i]){
      if( divisores_comunes.count(it.first) ) intersec[it.first] = min(it.second, divisores_comunes[it.first]);
    }
    divisores_comunes = {};
    divisores_comunes = intersec;
  }

  int asegurado = 1;
  for(auto it: divisores_comunes) asegurado *= (it.first*it.second);

  forn(i) v[i] /= asegurado;

  cout<<asegurado<<endl;
 */

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <cstring>
#include <algorithm>
#include <functional>
#include <cmath>
#include <set>
#include <queue>
#include <deque>
#include <vector>
#include <climits>
#include <sstream>
#include <iomanip>
#include <map>
#include <stack>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;

int main()
{
	int N;
	cin >> N;
	vector<int> p(N);
	for (auto i = 0; i < N; ++i)
	{
		cin >> p[i];
		--p[i];
	}

	vector<ll> a;
	vector<ll> b;
	for (auto i = 0; i < N; ++i)
	{
		a.push_back((ll)2 * N * i + 1);
		b.push_back((ll)2 * N * (N - i - 1) + 1);
	}

	for (auto i = 0; i < N; ++i)
	{
		b[p[i]] += i;
	}

	for (auto i = 0; i < N; ++i)
	{
		cout << a[i];
		if (i < N - 1)
		{
			cout << " ";
		}
	}
	cout << endl;
	for (auto i = 0; i < N; ++i)
	{
		cout << b[i];
		if (i < N - 1)
		{
			cout << " ";
		}
	}
	cout << endl;


	return 0;
}

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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n,a[20],x[20][20],y[20][20];
    cin>>n;
    for(int i=1;i<=n;i++)
    {
        cin>>a[i];
        for(int j=1;j<=a[i];j++)
        {
            cin>>x[i][j]>>y[i][j];
        }
    }
    int ans=0;
    bool flag=true;
    for(int bits=1;bits<(1<<n);bits++)
    {
        flag=true;
        for(int i=1;i<=n;i++)
        {
            if(!(bits&(1<<(i-1))))continue;
            for(int j=1;j<=a[i];j++)
            {
                if(((bits>>x[i][j]-1)&1)^y[i][j])flag=false;
            }
        }
        if(flag)ans=max(ans,__builtin_popcount(bits));
    }
    cout<<ans;
    return 0;
}

Measured memory_bytes: 256
from logging import getLogger, StreamHandler, DEBUG
logger = getLogger(__name__)
handler = StreamHandler()
handler.setLevel(DEBUG)
logger.setLevel(DEBUG)
logger.addHandler(handler)

import sys

def match(s, sw, index, N):
    if s[index]=='o':
        if sw[index]=='S':
            return sw[(index - 1 + N) % N] == sw[(index + 1 + N) % N]
        else:
            return sw[(index - 1 + N) % N] != sw[(index + 1 + N) % N]
    else:
        if sw[index]=='W':
            return sw[(index - 1 + N) % N] == sw[(index + 1 + N) % N]
        else:
            return sw[(index - 1 + N) % N] != sw[(index + 1 + N) % N]


N = int(input())
s = input()


	 
    

for j in range(4):
    sw = ""
    if j%2==0:
        sw+= 'S'
    else:
        sw+= 'W'

    if (int(j/2))%2==0:
        sw+= 'S'
    else:
        sw+= 'W'
#    logger.debug(sw)


    for i in range(N-2):
        if (sw[i+1] == 'S' and s[i+1] == 'o') or (sw[i+1] == 'W' and s[i+1] == 'x'):
            sw+=sw[i]
        else:
            if sw[i] == 'S':
                sw+='W'
            else:
                sw+='S'

#        logger.debug(sw)

    if match(s,sw,0,N) and match(s,sw,N-1,N):
        print(sw)
        sys.exit()

print(-1)


Measured memory_bytes: 4588
#include <iostream>
#include<string>
#include<cmath>
#include<algorithm>
#include<cctype>
#include<queue>
#include<stack>
#include<stdio.h>
#include<vector>
#include<set>
#include<map>
#include<iomanip>
using namespace std;
int main(){
    int n;
    cin>>n;
    int kn[n+2];
    kn[0]=0;
    kn[n+1]=0;
    int sa[n+1];
    int sum=0;
    for(int i=1;i<n+2;i++){
        if(i!=n+1){
            cin>>kn[i];
        }
        sa[i]=kn[i]-kn[i-1];
        sum+=abs(sa[i]);
    }
    sa[0]=0;
    for(int i=0;i<n+2;i++){
        //cout<<sa[i]<<endl;
    }
    //cout<<sum<<endl;
    //cout<<"a"<<endl;
    for(int i=1;i<n+1;i++){
        if((sa[i]>=0&&sa[i+1]>=0)||(sa[i]<=0&&sa[i+1]<=0)){
            cout<<sum<<endl;
        }else{
            int ans=sum;
            ans=ans-abs(sa[i])-abs(sa[i+1]);
            ans+=abs(sa[i]+sa[i+1]);
            cout<<ans<<endl;
        }
        
        
    }





return 0;
}


Measured memory_bytes: 2048
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<iomanip>
#include<math.h>
#include<complex>
#include<queue>
#include<deque>
#include<stack>
#include<map>
#include<set>
#include<bitset>
#include<functional>
#include<assert.h>
#include<numeric>
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
using ll = long long;
const int inf=1e9+7;
const ll longinf=1LL<<60 ;
const ll mod=1e9+7 ;

int main(){
	int n,m;
	cin>>n>>m;
	priority_queue<pair<ll,ll>> que;
	rep(i,n){
		int x;
		cin>>x;
		que.emplace(x,1);
	}
	rep(i,m){
		int y,x;
		cin>>y>>x;
		que.emplace(x,y);
	}
	ll ans=0;
	ll cnt=n;
	while(cnt){
		auto p=que.top();que.pop();
		ans+=p.first*min(p.second,cnt);
		cnt-=min(cnt,p.second);
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 6536
#include<bits/stdc++.h>
#include<vector>
#include<list>
#include<stack>
#include<queue>
#include<algorithm>
using namespace std;

/**
 * vector<int>ar(3);
 * for(auto&e:ar){
 *     scanf("%d",&e);
 * }
 * sort(ar.begin(),ar.end())
 * int sum=accumulate(ar.begin(),ar.end(),0);
 **/

char sute[1];
char m[8][8];
int w[12][2]={{-3,0},{-2,0},{-1,0},{3,0},{2,0},{1,0},{0,-3},{0,-2},{0,-1},{0,1},{0,2},{0,3}};
void bomb(int i,int j){
    int ni,nj;
    for (int k=0;k<12;++k) {
        m[i][j]='0';
        ni=i+w[k][0];
        nj=j+w[k][1];
        if (ni>=0 && ni<8 && nj>=0 && nj<8) {
            if (m[ni][nj]=='1') {
                bomb(ni,nj);
            } else {
                m[ni][nj]='0';
            }
        }
    }
    return;
}

int main(){
    int mod=1000000007;
    int n,cnt=1,x,y;
    scanf("%d",&n);
    for (int i=0;i<n;++i){
        fgets(sute,1,stdin);
        for (int j=0;j<8;++j) {
            scanf("%s",m[j]);
        }
        scanf("%d",&x);
        scanf("%d",&y);
        bomb(y-1,x-1);
        printf("Data %d:\n",cnt);
        cnt++;
        for (int j=0;j<8;++j) {
            for (int k=0;k<8;++k) {
                printf("%c",m[j][k]);
            }
            printf("\n");
        }
    }
    return 0;
}

Measured memory_bytes: 3164
#include "bits/stdc++.h"
#include <sys/timeb.h>
#include <fstream>

using namespace std;

#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define replrev(i,a,b) for(int i=(int)(b)-1;i>=(int)(a);i--)
#define reprev(i,n) replrev(i,0,n)
#define repi(itr,ds) for(auto itr=ds.begin();itr!=ds.end();itr++)
#define all(a) a.begin(),a.end()
#define mp make_pair
#define mt make_tuple
#define INF 2000000000
#define INFL 1000000000000000000LL
#define EPS 1e-9
#define MOD 1000000007
#define PI 3.1415926536
#define RMAX 4294967295

typedef long long ll;
typedef pair<int, int> P;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<bool> vb;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<P> vP;
typedef vector<vector<int> > vvi;
typedef vector<vector<bool> > vvb;
typedef vector<vector<ll> > vvll;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<double> > vvd;
typedef vector<vector<P> > vvP;
typedef priority_queue<int, vector<int>, greater<int> > pqli;
typedef priority_queue<ll, vector<ll>, greater<ll> > pqlll;
typedef priority_queue<P, vector<P>, greater<P> > pqlP;
typedef pair<int, pair<int, int> > Edge;
typedef vector<Edge> vE;
typedef priority_queue<Edge, vector<Edge>, greater<Edge> > pqlE;

// モジュラ逆数を求める(modが素数と仮定)
void ModInv(int n, vector<ll> &inv, int mod)
{
	inv[0] = 0;
	inv[1] = 1;
	for (int i = 2; i <= n; i++)
	{
		inv[i] = mod - ((mod / i) * inv[mod % i] % mod);
	}
}

// n!をmodで割った余り
void FacInv(int n, vector<ll> &inv, vector<ll> &fac, vector<ll> &facInv, int mod)
{
	fac[0] = facInv[0] = 1;
	for (int i = 1; i <= n; i++)
	{
		fac[i] = (fac[i - 1] * i) % mod;
		facInv[i] = (facInv[i - 1] * (int)inv[i]) % mod;
	}
}

// nCkをmodで割った余りを求める。mod素数限定
// ModInv()とFacInv()が必要
long CombiMod(int n, int k, int mod ,vll &fac, vll &facInv)
{
	if (n == 0 && k == 0) return 1;
	if (n <= 0 || k < 0 || k > n) return 0;
	if (k == 0) return 1;

	return (((fac[n] * facInv[k]) % mod) * facInv[n - k]) % mod;
}

int main() {
	int N;
	cin >> N;
	vector<ll> inv(N + 2);
	vector<ll> fac(N + 2);
	vector<ll> facInv(N + 2);

	ModInv(N+1, inv, MOD);
	FacInv(N+1, inv, fac, facInv, MOD);

	vi a(N + 1);
	vi pos(N + 1);
	set<int> used;
	int p1, p2;
	rep(i, N + 1) {
		cin >> a[i];
		if (used.find(a[i]) != used.end()) {
			p1 = pos[a[i]];
			p2 = i;
			break;
		}
		used.insert(a[i]);
		pos[a[i]] = i;
	}
	int x = p1;
	int y = p2 - p1 - 1;
	int z = N + 1 - x - y - 2;

	repl(k, 1, N + 2) {
		cout << (CombiMod(N + 1, k, MOD, fac, facInv) - CombiMod(x + z, k - 1, MOD, fac, facInv) + MOD) % MOD << endl;
	}

	return 0;
}

Measured memory_bytes: 9088
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>
#include <numeric>
#include <set>
#include <iomanip>
#include <functional>
#define FOR(i, a, n) for (long long i = (a); i < (n); i++)
#define REP(i, n) for(long long i = 0; i < (n); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define pb push_back
#define PI 3.14159265358979323846264338327950L
using namespace std;

typedef long long ll;
typedef long double ld;


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

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

long long myLcm(long long a, long long b)
{
	return a * b / myGcd(a, b);
}

int myLcm(int a, int b)
{
	return a * b / myGcd(a, b);
}

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

	ll A, B;
	cin >> A >> B;

	cout << A * B << endl;

	return 0;
}

Measured memory_bytes: 3648
import sys
stdin = sys.stdin

sys.setrecursionlimit(10 ** 7)

def li(): return map(int, stdin.readline().split())
def li_(): return map(lambda x: int(x) - 1, stdin.readline().split())
def lf(): return map(float, stdin.readline().split())
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(stdin.readline())
def nf(): return float(stdin.readline())


from heapq import heappush, heappop

n = ni()
a = list(li())
b = list(li())

# n = 10**5
# a = [1]*(10**5)
# b = [5] + [1]*(10**5-2) + [7]

que = []

for i, bi in enumerate(b):
    heappush(que, (-bi, i))

ans = 0
while que:

    cur, position = heappop(que)
    cur = -cur

    if cur - b[(position-1)%n] - b[(position+1)%n] < a[position]:
        continue

    ope = (cur - a[position]) // (b[(position-1)%n] + b[(position+1)%n])

    ans += ope
    b[position] -= ope * (b[(position-1)%n] + b[(position+1)%n])
    heappush(que, (-b[position], position))

ok = True
for ai, bi in zip(a, b):
    if ai != bi:
        ok = False

if ok:
    print(ans)
else:
    print(-1)

Measured memory_bytes: 126932