akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
  if(n==1){
    return false;
  }else if(n==2){
    return true;
  }else{
    for(int i=2;i<=sqrt(n);i++){
      if(n%i==0){
        return false;
      }
    }
    return true;
  }
}

long long gcd_(long long a, long long b){
  if(a<b){
    swap(a,b);
  }
  if(a%b==0){
    return b;
  }else{
    return gcd_(b,a%b);
  }
}
 
long long lcm_(long long x, long long y){
  return (x/gcd_(x,y))*y;
}
 
class UnionFind {
    public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;
    
    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }
    
    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }
    
    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }
    
    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }
        
        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);
        
        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;
        
        return true;
    }
};


int main(){
  
  int l;
  cin>>l;
  bool used[20][20]={};
  vector<int> cost[20][20];
  int msb;
  for(int i=19;i>=0;i--){
    if((l>>i) & 1){
      msb = i;
      break;
    }
  }
  int n=1;
  int m=0;
  for(int i=msb;i>=1;i--){
    REP(j,20){
      REP(k,20){
        if(!used[j][k])continue;
        for(int& c:cost[j][k]){
          c *= 2;
        }
      }
    }
    n++;
    used[n-2][n-1] = true;
    m += 2;
    cost[n-2][n-1].push_back(0);
    cost[n-2][n-1].push_back(1);
    if((l>>(i-1)) & 1){
      used[0][n-1] = true;
      m++;
      cost[0][n-1].push_back((l>>(i-1))-1);
    }
  }
    
  cout<<n<<' '<<m<<endl;
  REP(i,20){
    REP(j,20){
      if(used[i][j]){
        for(int c:cost[i][j]){
          cout<<i+1<<' '<<j+1<<' '<<c<<endl;
        }
      }
    }
  }
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <string.h>
using namespace std;
int a[105][105],p[105],b[105];
int main()
{
    int n,m,i,j,k,t,ans=0;
    cin>>n>>m;
     memset(a,0,sizeof(a));
    for(i=0;i<m;i++)
	{
		cin>>t;
		for(j=0;j<t;j++)
		{
			cin>>a[i][j];
		}
	}
	for(i=0;i<m;i++)
		cin>>p[i];
	for(i=0;i<(1<<n);i++)
	{        memset(b,0,sizeof(b));
	    for(j=0;j<n;j++)
		{
			if(i&(1<<j))
			{
				// 打开这个开关  枚举每一个灯
				for(k=0;k<m;k++)
				{
					int index=0;
					while(a[k][index])
					{
						if(a[k][index]==j+1) //这个灯和这个开关关联
							b[k]++;//记录这个灯关联的开关on的个数
						index++;
					}
				}
			}
		}
		for(j=0;j<m;j++)
		{
			b[j]%=2;
			if(b[j]!=p[j])
				break;
			if(j==m-1)
				ans++;
		}
	}
	cout<<ans<<endl;

    return 0;
}


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

int main(void) {
    int N,A;
    cin >> N; 
    for(int i=9;i>=1;i--){ 
        if((N%i) == 0) {
           A = N/i; 
            if(A < 10) cout << "Yes\n";
            else cout << "No\n";
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#define TEMPLATE_USED
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll,ll> pl;
typedef vector<pl> vp;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
const ll D4[]={0,1,0,-1,0};
const ll D8[]={0,1,1,0,-1,-1,1,-1,0};
#define _overload3(_1,_2,_3,name,...) name
#define _rep2(i,n) for(ll i=0;i<(n);++i)
#define _rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(...) _overload3(__VA_ARGS__,_rep3,_rep2)(__VA_ARGS__)
#define _repe2(i,n) for(ll i=0;i<=(n);++i)
#define _repe3(i,a,b) for(ll i=(a);i<=(b);++i)
#define repe(...) _overload3(__VA_ARGS__,_repe3,_repe2)(__VA_ARGS__)
#define _rrep2(i,n) for(ll i=(n)-1;i>=0;i--)
#define _rrep3(i,a,b) for(ll i=(b)-1;i>=(a);i--)
#define rrep(...) _overload3(__VA_ARGS__,_rrep3,_rrep2)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
template<class T>
bool chmax(T &a,const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>
bool chmin(T &a,const T &b){if(b<a){a=b;return 1;}return 0;}
template<class T>
using pq=priority_queue<T,vector<T>,greater<T>>;


void solve();

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

ll n,d;
vl a(3),b={2,3,5};
map<ll,ll> dp;

ll f(ll x){
    if(x==0)return 0;
    if(x==1)return d;
    if(dp.count(x))return dp[x];
    
    ll ret=LINF;
    if(x<LINF/d)chmin(ret,x*d);
    rep(i,3){
        chmin(ret,f(x/b[i])+a[i]+x%b[i]*d);
        chmin(ret,f((x+b[i]-1)/b[i])+a[i]+((x+b[i]-1)/b[i]*b[i]-x)*d);
    }
    return dp[x] = ret;
}

void solve(){
    /* (´~`) */
    ll t;cin>>t;
    while(t--){
        dp.clear();
        cin>>n;
        rep(i,3)cin>>a[i];
        cin>>d;
        cout<<f(n)<<endl;
    }
}


Measured memory_bytes: 4384
#include <bits/stdc++.h>
using namespace std;
const int N = 1e5 + 55;
int n, a[N], mn = N, mx, cmx, cm1;
int main(){
    ios::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for(int i = 0; i < n; ++i) cin >> a[i], mn = min(mn, a[i]), mx = max(mx, a[i]);
    if(mx - mn <= 1){
        for(int i = 0; i < n; ++i){
            cmx += (a[i] == mx);
            cm1 += (a[i] == mx - 1);
        }
        if(cmx == 1) return puts("No"), 0;
        if(!cm1 && mx == n - 1) return puts("Yes"), 0;
        int l = cm1 + 1, r = cm1 + (n - cm1) / 2;
        if(mx >= l && mx <= r) puts("Yes");
        else puts("No");
    }
    else
        puts("No");
    return 0;
}


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

int main(){
	int x, n;
	cin >> x >> n;
	
	if (n == 0) {
		cout << x << endl;
		return 0;
	}
	
	vector<int> p(n);
	rep(i, n) cin >> p[i];
	
  bool judge = true;
	rep(i, n) {
		if (p[i] == x) {
			judge = false;
          break;
		}
	}
  if (judge) {
    cout << x << endl;
    return 0;
  }
	
	int a = 1;
	int plus;
	while (true) {
		bool judgep = true;
		rep(i, n) {
			if (p[i] == x + a) {
				judgep = false;
				break;
			}
		}
		if (judgep) {
			plus = x + a;
			break;
		}
		a++;
	}

	int b = 1;
	int minus;
	while (true) {
		bool judgem = true;
		rep(i, n) {
			if (p[i] == x - b) {
				judgem =  false;
				break;
			}
		}
		if (judgem) {
			minus = x - b;
			break;
		}
		b++;
	}
	
	if (plus - x < x - minus) {
		cout << plus << endl;
	} else {
		cout << minus << endl;
	}
}


Measured memory_bytes: 3628
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1]*n
    
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)

        if x == y:
            return

        if self.parents[x] > self.parents[y]:
            x, y = y, x

        self.parents[x] += self.parents[y]
        self.parents[y] = x
    
    def size(self, x):
        return -self.parents[self.find(x)]

    def same(self, x, y):
        return self.find(x) == self.find(y)

    def members(self, x):
        root = self.find(x)
        return [i for i in range(self.n) if self.find(i) == root]

    def roots(self):
        return [i for i, x in enumerate(self.parents) if x < 0]

    def group_count(self):
        return len(self.roots())

    def all_group_members(self):
        return {r: self.members(r) for r in self.roots()}

    def __str__(self):
        return '\n'.join('{}: {}'.format(r, self.members(r)) for r in self.roots())


N, M = map(int, input().split())
root = []
for i in range(M):
    a, b = map(int, input().split())
    root.append((a-1,b-1))

uf = UnionFind(N)
ans_list = []
ans = N*(N-1)//2
ans_list.append(ans)
for a, b in reversed(root[1:]):
    if uf.same(a,b):
        ans_list.append(ans)
        continue
    a_nakama = uf.size(a)
    b_nakama = uf.size(b)
    ans = ans - a_nakama*b_nakama
    uf.union(a,b)
    ans_list.append(ans)

for ans in reversed(ans_list):
    print(ans)


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

using namespace std;

typedef long long	ll;

int main(){
	ll h, w;

	cin >> h >> w;

	ll tot = h * w;

	if(h == 1LL || w == 1LL){
		cout << 1 << endl;
	}else{
		cout << ((tot + 1LL) / 2LL) << endl;
	}

	return 0;
}

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

int main(){
    int n;
    string s;
    cin >> n;
    cin >> s;
    string ans;
    int k=0;
    string ss;
    rep(i,n){
        ss=s[i];
        if(ss=="("){
            ++k;
            ans=ans+"(";
        }
        else{
            if(k==0){
                ans="("+ans+")";
            }
            else{
                ans=ans+")";
                --k;
            }
        }
    }

    rep(i,k){
        ans=ans+")";
    }

    cout << ans << endl;
    

    return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
ll const mod = 998244353;

#define p_ary(ary,a,b) do { cout << "["; for (int count = (a);count < (b);++count) cout << ary[count] << ((b)-1 == count ? "" : ", "); cout << "]\n"; } while(0)
#define p_map(map,it) do {cout << "{";for (auto (it) = map.begin();;++(it)) {if ((it) == map.end()) {cout << "}\n";break;}else cout << "" << (it)->first << "=>" << (it)->second << ", ";}}while(0)

int main() {
    ll n;
    cin >> n;
    string s;
    cin >> s;
    ll ans = 0;
    unordered_map<int,ll> mp;
    for (int x = n/2*2+1;x > 0;x -= 2)  if (n%x == 0) {
        ll b = 1;
        ll cnt = 0;
        for (int i = n/x-1;i >= 0;--i) {
            if (s[i] == '1') (cnt += b) %= mod;
            (b *= 2) %= mod;
        }
        string t = "",u = s.substr(0,n/x),revu = "";
        for (int i = 0;i < n/x;++i) {
            if (s[i] == '1') revu += '0';
            else revu += '1';
        }
        for (int i = 0;i < x;++i) {
            if (i&1) t += revu;
            else t += u;
        }
        if (t <= s) cnt++;
        (cnt -= mp[x]) %= mod;
        (ans += (n*2/x)*cnt%mod) %= mod;
        for (int i = x-2;i > 0;i -= 2) if (x%i == 0 && n%i == 0) (mp[i] += cnt) %= mod;
    }
    cout << (ans+mod)%mod << endl;
}

Measured memory_bytes: 1140
s=input()
t=input()
q=int(input())
acums=[[0,0] for _ in range(len(s)+1)]
for i in range(1,len(s)+1):
  if s[i-1]=='A':
    acums[i][0]=acums[i-1][0]+1
    acums[i][1]=acums[i-1][1]
  else:
    acums[i][0]=acums[i-1][0]
    acums[i][1]=acums[i-1][1]+1
acumt=[[0,0] for _ in range(len(t)+1)]
for i in range(1,len(t)+1):
  if t[i-1]=='A':
    acumt[i][0]=acumt[i-1][0]+1
    acumt[i][1]=acumt[i-1][1]
  else:
    acumt[i][0]=acumt[i-1][0]
    acumt[i][1]=acumt[i-1][1]+1
for _ in range(q):
  a,b,c,d=map(int,input().split())
  cnt1=(acums[b][0]-acums[a-1][0])*2+(acums[b][1]-acums[a-1][1])
  cnt2=(acumt[d][0]-acumt[c-1][0])*2+(acumt[d][1]-acumt[c-1][1])
  if (cnt1-cnt2)%3==0:
    print('YES')
  else:
    print('NO')

Measured memory_bytes: 32904
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int k = in.nextInt();
		int q = in.nextInt();
		int[] p = new int[n+1];
		for(int i=0;i<q;i++) {
			int a = in.nextInt();
			p[a]++;
		}
		for(int i=1;i<=n;i++) {
			boolean ans = true;
			if(k-q+p[i]>0) ans = true;
			else ans = false;
			System.out.println(ans?"Yes":"No");
		}
		
		in.close();

	}

}


Measured memory_bytes: 55980
#include <bits/stdc++.h>
#include <numeric>
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define SORT_INV(c) sort((c).begin(), (c).end(), greater<int>())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
#define LL long long
#define Num 1000000007
// sort(a.begin(), a.end(), std::greater<int>());
using namespace std;

int main()
{
  int a,b,c,d;
  cin>>a>>b>>c>>d;
  if(abs(a-c)<=d|(abs(a-b)<=d&&abs(b-c)<=d)){
      cout<<"Yes"<<endl;
  }else{
      cout<<"No"<<endl;
  }
  return 0;
}

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

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <map>
#include <climits>

using namespace std;


int main(){
	vector<vector<int>> c(3, vector<int>(3));
	
	for (int i = 0; i < 3; i++) {
		for (int j = 0; j < 3; j++)
			cin >> c[i][j];
	}

	bool ok = false;

	for (int i = 0; i < 101;i++) {
		
			for (int k = 0; k < 101; k++){
				
					for (int m = 0; m < 101; m++){
						
							if (i + (c[1][1]-k) == c[0][1] && i + (c[2][2] - m) == c[0][2] && k + (c[0][0]-i) == c[1][0]
								&& k + (c[2][2]-m) == c[1][2] && m + (c[0][0] - i) == c[2][0] && m + (c[1][1] - k) == c[2][1]) {
								ok = true;
								break;
							}
						
					}
				
			}

		
	}

	if (ok) cout << "Yes" << endl;
	else cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
 
int main() {
int h,w;
cin >> h >> w;
vector<vector<char>> a(h,vector<char>(w));
rep(i,h)rep(j,w) cin >> a.at(i).at(j);
int hcnt = 0,wcnt = 0;
vector<int> s;
vector<int> t;
rep(i,h){
  bool flag = true;
  rep(j,w){
    if(a.at(i).at(j) == '#') flag = false;
  }
  if(flag) hcnt++;
  else s.push_back(i);
}
rep(j,w){
  bool flag = true;
  rep(i,h){
    if(a.at(i).at(j) == '#') flag = false;
  }
  if(flag) wcnt++;
  else t.push_back(j);
}
for(int i: s)for(int j: t){
  if(j < t.back())cout << a.at(i).at(j);
  else cout << a.at(i).at(j) << endl;
}
}

Measured memory_bytes: 3608
#include <set>
#include <cstdio>
#include <numeric>
#include <algorithm>
#include <queue>

inline int getInt(){ int s; scanf("%d", &s); return s; }

typedef long long ll;

using namespace std;

int check(int a, int m){
  vector<int> visit(m);
  int now = 0;

  while(!visit[now]){
    visit[now] = 1;
    now = (now + a) % m;
  }

  return accumulate(visit.begin(), visit.end(), 0);
}

int main(){
  int m = getInt();
  int n = getInt();
  int a = getInt();
  int b = getInt();
  int c = getInt();
  int d = getInt();

  a %= m;
  b %= n;
  c %= m;
  d %= n;

  int acnt = check(a, m);
  int bcnt = check(b, n);

  ll ans1 = ((ll)acnt * bcnt) / __gcd(acnt, bcnt);
  ll ans2 = 0;

  vector<int> h(m, -1);
  int hh = 0;
  int xx = 0;
  int yy = 0;

  while(h[xx] == -1){
    h[xx] = yy;
    xx = (xx + a) % m;
    yy = (yy + b) % n;
    hh++;
  }

  int ym = ans1 / hh;
  int yd = n / ym;

  xx = c;
  yy = d;

  while(true){
    ans2++;

    if(ans2 == 350 * n){
      int ccnt = check(c, m);
      int dcnt = check(d, n);
      ans2 = ((ll)ccnt * dcnt) / __gcd(ccnt, dcnt);
      break;
    }

    if(h[xx] != -1){
      if((yy - h[xx] + n) % yd == 0)
        break;
    }

    xx = (xx + c) % m;
    yy = (yy + d) % n;
  }

  printf("%lld\n", ans1 * ans2 - 1);

  return 0;
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
const int mod=1e9+7;
#define N 2000005
struct Combin{
	int fac[N],rv[N],facrv[N];
	Combin(){
		fac[0]=rv[1]=facrv[0]=1;
		for(int i=2;i<N;i++) rv[i]=((-(mod/i)*1LL*rv[mod%i]%mod)+mod)%mod;
		for(int i=1;i<N;i++) fac[i]=1LL*fac[i-1]*i%mod;
		for(int i=1;i<N;i++) facrv[i]=1LL*facrv[i-1]*rv[i]%mod;
	}
	int C(int r1,int n1){
		if(r1>n1) return 0;
		return fac[n1]*1LL*facrv[r1]%mod*facrv[n1-r1]%mod;
	}
}C;
int g(int x,int y){//[0,0] to [x,y]
    return C.C(x+1,x+y+2)-1;
}
int f(int xl,int yb,int xr,int yt){
    return 1LL*g(xr,yt)-g(xl-1,yt)-g(xr,yb-1)+g(xl-1,yb-1);
}
int x[8],y[8];
int calcS(int px,int py){//column
    return f(px-x[2],py-y[2],px-x[1],py-y[1])%mod;
}
int calcT(int px,int py){
    return f(x[5]-px,y[5]-py,x[6]-px,y[6]-py)%mod;
}

int main(){
    for(int i=1;i<=6;i++) scanf("%d",&x[i]);
    for(int i=1;i<=6;i++) scanf("%d",&y[i]);
    long long ans=0;
    for(int i=x[3];i<=x[4];i++) 
        ans-=calcS(i,y[3]-1)*1LL*calcT(i,y[3])%mod*(y[3]+i)%mod,
        ans+=calcS(i,y[4])*1LL*calcT(i,y[4]+1)%mod*(y[4]+i+1)%mod;
    for(int i=y[3];i<=y[4];i++) 
        ans-=calcS(x[3]-1,i)*1LL*calcT(x[3],i)%mod*(x[3]+i)%mod,
        ans+=calcS(x[4],i)*1LL*calcT(x[4]+1,i)%mod*(x[4]+i+1)%mod;
    cout<<(ans%mod+mod)%mod<<endl;
    return 0;
}

Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define MOD			1000000007
#define FOR(i,l,r)	for(int i=l;i<=r;i++)
#define REP(i,n)	for(int i=1;i<=n;i++)
#define REP0(i,n)	for(int i=0;i<n;i++)
#define PB			push_back
#define MP			make_pair
#define PII			pair<int,int>
#define VI			vector<int>
#define ALL(x)		(x).begin(),(x).end()
long long n;
int main(){
	cin>>n;
	cout<<1ll*n*(n-1)/2<<endl;
	return 0;
}

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

using namespace std;

int main()
{
    int n, x;
    cin >> n;

    int mn = INT_MAX, cnt = 0;

    for (int i = 0; i < n; i++)
    {
        cin >> x;

        if (x <= mn)
            mn = x;

        else
            cnt--;
    }
    cout << n + cnt << endl;
    return 0;
}

Measured memory_bytes: 256
n = int(input())
arr = list(map(int, input().split()))
arr.sort(reverse = True)

valid = True
t = n-1
for i in range(n):
	if arr[i] != t :
		valid = False
	if i % 2 == 1 :
		t -= 2 

if not valid:
	print(0)
else:
	print(2 ** (n//2) % (10 ** 9 + 7))


Measured memory_bytes: 14008
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define REP(X, Y, Z) for (ll(X) = (Y); (X) < (Z); (X)++)
#define REV(X, Y, Z) for (ll(X) = (Y); (X) > (Z); (X)--)

using namespace std;
using ll = long long;
using dll = deque<ll>;
using pll = pair<ll, ll>;
using qll = queue<ll>;
using usll = unordered_set<ll>;
using umll = unordered_map<ll, ll>;
using sll = stack<int>;
using vll = vector<ll>;
using vvll = vector<vll>;

constexpr ll kMax = 1e12 + 1;
constexpr ll kMod = 1e9 + 7;
constexpr long double kPI = 3.14159265358979323846;

ll gcd(ll a, ll b) {
  if (a < b) {
    return gcd(b, a);
  }
  ll c = a % b;
  while (c != 0) {
    a = b;
    b = c;
    c = a % b;
  }
  return b;
}

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

void init() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(15);
}

int main() {
  init();

  ll N, Q;
  string S;
  cin >> N >> Q >> S;
  vll cnt(N + 1, 0);
  REP(i, 1, N) {
    if (S[i - 1] == 'A' && S[i] == 'C') {
      cnt[i + 1] = 1;
    }
    cnt[i + 1] += cnt[i];
  }
  REP(i, 0, Q) {
    int l, r;
    cin >> l >> r;
    cout << cnt[r] - cnt[l] << endl;
  }

  return 0;
}


Measured memory_bytes: 1872
#include<iostream>

using namespace std;

int main(){
	string a,b,c;
	cin >> a >> b >> c;
	if(a[a.size()-1] == b[0] && b[b.size()-1] == c[0]){
		cout << "YES" << endl;
	}else{
		cout << "NO" << endl;
	}
	return 0;
	 
}


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

const int MAXK = 1e5 + 10;
const int MOD = 1e9 + 7;

int pref[MAXK],dp[MAXK],N,K;

int calc(int a,int b){
	if(a < 0) a = 0;
	int ans = pref[b];
	if(a != 0) ans -= pref[a-1];
	return ans % MOD;
}

int main(){

	cin >> N >> K;

	dp[0] = 1;

	for(int kid = 1;kid<=N;kid++){

		int c;
		cin >> c;

		pref[0] = dp[0];
		dp[0] = 0;
		for(int i = 1;i<=K;i++){
			pref[i] = (pref[i-1] + dp[i]) % MOD;
		}

		for(int i = 0;i<=K;i++){
			dp[i] = calc(i-c,i);
		}

	}

	int ans = dp[K];
	if(ans < 0) ans += MOD; 
	printf("%d\n",ans);

	return 0;

}


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

int main(){
  int n; cin >> n;
  int a[n]; cin>>a[0];
  int c=1; int sum=0;
  for(int i=1; i<n; i++){
    cin >> a[i];
    if(a[i]==a[i-1]){c++;}
    else if(c>1){sum=sum+c/2; c=1;}
  }
  if(c>1){sum=sum+c/2;}
  
  cout<<sum;
  
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <utility>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  string s;
  cin>>s;

  if(s.size() == 2) {
    cout << s << endl;
    return 0;
  }
  cout << s[2] << s[1] << s[0] << endl;

  return 0;
}


Measured memory_bytes: 256
//Name: Pankaj Mandrawal (pankaj_m05)
//Problem: Popular Vote
#include<bits/stdc++.h>
using namespace std;
                                 
int arr[105];
 
int main(void) {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int n, m, ans = 0, sum = 0; cin >> n >> m;
	for(int it = 0; it < n; ++it) {
		cin >> arr[it]; sum += arr[it];
	}
	for(int it = 0; it < n; ++it) {
		if(4 * m * arr[it] >= sum)
			++ans;         
	}
	if(ans >= m) cout << "Yes" << '\n';
	else cout << "No" <<'\n';
    return 0;
}


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

int main () {
  string A,B;
  cin >> A >> B;
  if (A[0] == B[2] && A[1] == B[1] && A[2] == B[0]) {
    cout << "YES" << endl;
  }
  else {
    cout << "NO" << endl;
  }
}

Measured memory_bytes: 384
import sys
sys.setrecursionlimit(100000)

N,K=map(int,input().split())
SIZE=10**5+1; MOD=10**9+7 #998244353 #ここを変更する
 
SIZE += 1
inv = [0]*SIZE  # inv[j] = j^{-1} mod MOD
fac = [0]*SIZE  # fac[j] = j! mod MOD
finv = [0]*SIZE # finv[j] = (j!)^{-1} mod MOD
inv[1] = 1
fac[0] = fac[1] = 1
finv[0] = finv[1] = 1
for i in range(2,SIZE):
  inv[i] = MOD - (MOD//i)*inv[MOD%i]%MOD
  fac[i] = fac[i-1]*i%MOD
  finv[i]= finv[i-1]*inv[i]%MOD

def narabekae(n,r): #nPr mod MOD の計算
  if n-r<0:
    return 0
  return fac[n]*finv[n-r]%MOD

branch=[[] for _ in range(N)]
for i in range(N-1):
  a,b=map(int,input().split())
  branch[a-1].append(b-1)
  branch[b-1].append(a-1)

ans=1

def draw(parent,nord):
  global ans
  children=len(branch[nord])-(parent !=-1)
  if children==0:
    return
  #(K-2)*(K-1)*... をchildrenの数だけ掛ける。
  ans=ans*narabekae(K-1-(parent !=-1),children)%MOD
  for b in branch[nord]:
    if b != parent:
      draw(nord,b)

draw(-1,0)
print(ans*K%MOD)

Measured memory_bytes: 104112
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <ctime>
#include <climits>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <algorithm>
#include <utility>
#include <cstdlib>

using namespace std;
long int pow107 = (int)pow(10, 9) + 7;
int ilimit = INT_MAX;
long int llimit = LONG_MAX;

bool comp(pair<int, string> a, pair<int, string> b){
    if(a.first != b.first) return a.first > b.first;
    else return a.second < b.second;
}

long int jou(long int x, long int y){
    long int f = 1;
    for(int i = 0; i < y; ++i){
        f = f * x % pow107;
    }
    return f;
}

bool pn(long int x){
    if(x != 2 && x % 2 == 0)
        return false;
    for(int i = 3; i < x; ++i){
        if(x != i && x % i == 0)
            return false;
    }
    return true;
}

long int factorial(long int n){
    long int f = 1;
    for(long int i = 1; i <= n; ++i){
        f = f * i % pow107;
    }
    return f;
}

int Func2(int n,int m){
    long int s2 = 1,
        r = 1;


    for(int i = 1; i <= m; ++i){
        s2 = (s2*(n - (i - 1))/i) % pow107;
    }

    return s2;
}

//long intの最大llimit
//intの最大ilimit
//10^9+7    pow107
//素数pn
//n乗jou
//階乗factorial
//コンビネーションFunc2

int main(){
    string s;
    cin >> s;
    int r = 0,n = s.size();
    int ans[int(pow(10,5))] = {};

    for(int i = 0; i < n; ++i){
        if(s[i] == 'R'){
            r++;
            if(s[i + 1] == 'L'){
                ans[i + 1] += r / 2;
                ans[i] += (r + 1) / 2;
            }
        }else{
            r = 0;
        }
    }

    r = 0;

    for(int i = n - 1; i >= 0; --i){
        if(s[i] == 'L'){
            r++;
            if(s[i - 1] == 'R'){
                ans[i - 1] += r / 2;
                ans[i] += (r + 1)/2;
            }
        }else{
            r = 0;
        }
    }

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

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

#define Max 1000000
int Prime[Max] = {};

int main()
{
	//?????????
	for (int i = 2; i < Max; i++)
	{
		Prime[i] = 1;
	}
	//??¨??????????????????????????????
	for (int i = 2; i*i < Max; i++)
	{
		if (Prime[i] == 1)
		{
			for (int j = i * 2; j < Max; j += i)
			{
				Prime[j] = 0;
			}
		}
	}
	//?´???????????¨????
	for (int i = 2; i < Max; i++)
	{
		Prime[i] += Prime[i - 1];
	}

	int n;
	while (cin >> n)
	{
		cout << Prime[n] << endl;
	}

	return 0;
}

Measured memory_bytes: 5064
#include<iostream>
#include<math.h>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;


int inf;
int n, m, R; int answer = inf = 300000000;
int r[10];
int d[210][210];


void wf() {
	for (int k = 0; k < n; k++) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
			}
		}
	}
}

int main() {
	cin >> n >> m >> R;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			d[i][j] = inf;
		}
	}
	for (int i = 0; i < n; i++) {
		d[i][i] = 0;
	}
	for (int i = 0; i < R; i++) {
		cin >> r[i];
	}
	int a, b, c;
	for (int i = 0; i < m; i++) {
		cin >> a >> b >> c;
		d[a - 1][b - 1] = c;
		d[b - 1][a - 1] = c;
	}
	wf();
	sort(r, r + R);
	do {
		int ans = 0;
		for (int i = 1; i < R; i++) {
			ans += d[r[i - 1] - 1][r[i] - 1];
		}
		answer = min(ans, answer);
	} while (next_permutation(r, r + R));
	cout << answer << endl;
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
const int N=1000;
 
int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	string s;cin >> s;
	ll l;l=s.size();
	ll ans = 0;
	char c;
	c=s[0];
	FOR(i,1,l){
		if(s[i]!=c){
			c=s[i];
			ans++;
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <cmath>
#include <iomanip>
#include <stack>
#include <queue>
#include <numeric>
#include <map>
#include <unordered_map>
#include <set>
#include <fstream>
#include <chrono>
#include <random>
#include <bitset>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(x) ((int)(x).size())
#define pb push_back
#define mod 1000000007
using ll = long long;
using namespace std;
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 a, b; cin >> a >> b;
  rep(i,max(a, b))cout << min(a,b);
  cout  << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>

using std::cout;
using std::cin;
using std::endl;
using std::vector;
using std::sort;

void input(vector<int>& v, int number) {
    for (int i = 0; i < number; i ++) { 
        int value;
        cin >> value;
        v.push_back(value);
    }   
    sort(v.begin(), v.end());
}

void calc(vector<int> v) {
    int total = 0;
    int average;
    int size = v.size();
    for (int i = 1; i < size - 1; i ++) {
        total += v[i];
    }   
    average = total / (size - 2); 
    cout << average << endl;
}

int main(void) {
    int number;
    cin >> number;
    while (number != 0) {
        vector<int> v(0);
        input(v, number);
        calc(v);
        cin >> number;
    }   
    return 0;
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> W(N);
    REP(i,N)cin >> W.at(i);
    int sum = 0;
    REP(i,N)sum += W.at(i);
    int now = 0,past = 0,ans;
    REP(i,N){
        now += W.at(i);
        if(sum - now <=now){
            ans = min(abs(sum - now * 2),sum - past * 2);
            break;
        }
        past = now;
    }
    cout <<ans<< "\n";
}

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

int main() {
    int X,Y,Z,K;
    cin >> X >> Y >> Z >> K;
    vector<ll>A(X);
    vector<ll>B(Y);
    vector<ll>C(Z);
    for (int i = 0; i < X; ++i) cin >> A[i];
    for (int i = 0; i < Y; ++i) cin >> B[i];
    for (int i = 0; i < Z; ++i) cin >> C[i];

    sort(A.begin(), A.end(), greater<ll>());
    sort(B.begin(), B.end(), greater<ll>());
    sort(C.begin(), C.end(), greater<ll>());

    priority_queue<vector<ll>> q;
    vector<vector<vector<bool>>> flag (X, vector<vector<bool>>(Y, vector<bool>(Z,true)));
    q.push({A[0]+B[0]+C[0],0,0,0});
    for (int i = 0; i < K; ++i){
        cout << q.top()[0] << endl;
        ll qx = q.top()[1];
        ll qy = q.top()[2];
        ll qz = q.top()[3];
        q.pop();
        
        if(qx+1 < X && flag[qx+1][qy][qz]){
            q.push({A[qx+1] + B[qy] + C[qz], qx+1, qy, qz});
            flag[qx+1][qy][qz] = false;
        }
        if(qy+1 < Y && flag[qx][qy+1][qz]) {
            q.push({A[qx] + B[qy+1] + C[qz], qx, qy+1, qz});
            flag[qx][qy+1][qz] = false;
        }
        if(qz+1 < Z && flag[qx][qy][qz+1]) {
            q.push({A[qx] + B[qy] + C[qz+1], qx, qy, qz+1});
            flag[qx][qy][qz+1] = false;
        }
        

        /*
         * flag作らずにこれやるとA_i = A_(i+1)みたいなのでバグる?
        while( q.top()[1] == qx && q.top()[2] == qy && q.top()[3] == qz) {
            q.pop();
            if(q.empty()) break;
        }
         */
    }
    return 0;
}

Measured memory_bytes: 180480
#include<algorithm>
#include<string>
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;
 
int dy[]={0, 0, 1, -1, 0};
int dx[]={1, -1, 0, 0, 0};

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

    cout << x + y/2 << endl;

    return 0;
}

Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
  // 1行目がinput[0], 2行目がinput[1], …に入る
  var ans = "Yes";
  input = input.trim().split("\n");
  const [N, M] = input[0].split(" ").map((n) => parseInt(n));
  var a = input[1].split(" ").map((n) => parseInt(n));
  a.sort((a, b) => b - a);
  var top = a.slice(0, M);
  const lim = arrsum(a) / 4 / M;

  if (top[top.length - 1] < lim) {
    ans = "No";
  }

  function arrsum(arr) {
    return arr.reduce((c, a, i, self) => {
      return c + a;
    });
  }

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


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

int main(){
    string W;
    cin >> W;
    transform(W.begin(), W.end(), W.begin(), ::toupper);
    int len = W.length();
    int count = 0;
    string line;
    getline(cin, line, '\n');
    while(true){
        cin >> line;
        if (line == "END_OF_TEXT") break;
        transform(line.begin(), line.end(), line.begin(), ::toupper);
        count += (line == W);
    }
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 3180
#include <bits/stdc++.h>
#define forn(i,b) for(int i=0 ; i< b ;i++)
#define for1(i,b) for(int i=1 ; i<=b ;i++)
#define reps(i,a,b) for(int i=a ; i< b.length() ;i++)
typedef long long ll;
#define MOD 1000000007

using namespace std;

bool checkIfPrime(int& a){
  for (int i=2;i<a;i++){
    if((a%i)==0)return 0;
  }
  return 1;
}

int main()
{
  int a;
  cin>>a;
  if(checkIfPrime(a))cout<<a;
  else {
    while(!checkIfPrime(++a));
    cout<<a;
  }

  return 0 ;
}


Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))

total_a = 0
total_b = 0

count = 0

while len(a) > 0:
    if count % 2 == 0:
        max_value = max(a)
        total_a += max_value
        a.remove(max_value)
        count += 1
    else:
        max_value = max(a)
        total_b += max_value
        a.remove(max_value)
        count += 1
    
print(total_a - total_b)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int value = scanner.nextInt();
        int maxTime = scanner.nextInt();
        int tempCost = 1001;
        for(int k = 0;k < value;k++){
            int cost = scanner.nextInt();
            int time = scanner.nextInt();
            if(time <= maxTime&&cost <= tempCost){
                tempCost = cost;
            }
        }
        if(tempCost == 1001) System.out.println("TLE");
        else System.out.println(tempCost);
    }
}


Measured memory_bytes: 21844
#include <math.h>
#include <assert.h>
#include <algorithm>
#include <set>
#include <iostream>
#include <vector>
#include <queue>
#include <map>
#include <string>
#include <cstring>
#include <functional>
#include <stack>
#include <array>
#include <random>
#include <chrono>
#include <climits>
#include <bitset>
using namespace std ;
#define ld long double
#define int long long
#define ii pair<int,int>
#define FAST_IO ios_base::sync_with_stdio(false) ;cin.tie(NULL);cout.tie(NULL); clock_t beg = clock()
#define dbg(x) cerr << #x << " is " << x << endl;
#define ms(x,a) memset(x,(int)(a),sizeof(x))
#define all(x) (x).begin(), (x).end()
#define sz(x) ((int)(x).size())
#define vi vector<int >
#define pb push_back
#define endl '\n'
#define ff first
#define ss second
//const int N = 3e5+7 ;
const int INF = 1e18 ;
//const int MOD = 1e9 + 7 ;
void solve(){
	int n , m , x ;
	cin >> n >> m >> x ;
	vector<int> cost(n) ;
	vector<vector<int>> val(n,vi(m)) ;
	for(int i = 0 ; i < n ; i++){
		cin >> cost[i] ;
		for(int j = 0 ; j < m ; j++){
			cin >> val[i][j] ;
		}
	}
	int ans = INF ;
	for(int i = 0 ; i < 1<<n ; i++){
		int mask = i ;
		bool ok = 1 ;
		int ans0 = 0 ;
		vector<int> cur(m) ;
		for(int j = 0 ; j < n ; j++){
			if(mask&(1<<j)){
				ans0 += cost[j] ;
				for(int k = 0 ; k < m ; k++){
					cur[k] += val[j][k] ;
				}
			}
		}
		for(int j = 0 ; j < m ; j++){
			if(cur[j] < x){
				ok =0 ;
				break ;
			}
		}
		if(ok) ans = min(ans,ans0) ;
	}
	cout << (ans==INF ? -1 : ans) ;
}

int32_t main(){
	FAST_IO ;
	int t = 1 ;
//	cin >> t ;
	while(t--){
		solve() ;
	}
    cerr << "\nExecution time: " << (clock() - beg) / 1000 << '\n';
}


Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
int main(){
	int a,b,c;
	char d='/';
	cin>>a>>d>>b>>d>>c;
	if(a<=2019){
		if(b<=04){
			if(c<=30){
				cout<<"Heisei"<<endl;
			}
			else{
				cout<<"TBD"<<endl;
			}
		}
		else{
			cout<<"TBD"<<endl;
		}
	}
	else{
		cout<<"TBD"<<endl;
	}
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
/**
******************* Author:Bisnu sarkar ****************************
**/
/*
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
*/
#define fRead(x)       freopen(x,"r",stdin)
#define fWrite(x)      freopen (x,"w",stdout)
#define ull            unsigned long long
#define ll             long long
#define pii            pair<int,int>
#define sit            set<int> :: iterator
#define vrit           vector<int> :: reverse iterator
#define ff             first
#define ss             second
#define endl           '\n';
#define sz(s)          (int)s.size()
#define all(s)         s.begin(),s.end()
#define IO             ios_base::sync_with_stdio(false),cin.tie(NULL);  
#define what_is(x)     cerr << #x << " is " << x << endl;
///*....Debugger....*///
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }
void err(istream_iterator<string> it) {cout << endl;}
template<typename T, typename... Args> void err(istream_iterator<string> it, T a, Args... args) {
  cerr << *it << " = " << a << ", ";
  err(++it, args...);
}
///*....Input....*///
template <typename T> inline void Int(T &n) {
  n = 0; int f = 1; register int ch = getchar();
  for (; !isdigit(ch); ch = getchar()) if (ch == '-') f = -1;
  for (; isdigit(ch); ch = getchar()) n = (n << 3) + (n << 1) + ch - '0';
  n = n * f;
}
 
template <typename T, typename TT> inline void Int(T &n, TT &m) { Int(n); Int(m); }
template <typename T, typename TT, typename TTT> inline void Int(T &n, TT &m, TTT &l) { Int(n, m); Int(l);}
double ind(){double x; scanf("%lf",&x);return x;}

///*....Bitmask....*///
int set_1(int n,int pos){return n = (n | (1<<pos));}
int reset_0(int n,int pos){return n= n & ~(1<<pos);}
bool check_bit(int n,int pos){return n = n & (1<<pos);}

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

///*....Constraints....*///
const int N = (int) 1e6 + 5;
const int M = (int) 1e9 + 7;
const double pi=2* acos(0.0);
const double eps=1e-9;

ll a[N];
ll n,k;
bool valid(ll x){
    ll op=0ll;
    for(int i=1;i<=n;++i){
        ll p=a[i]/x;
        if(a[i]%x ==0)p-=1;
        op+=p;
     //   error(a[i],x,p)
    }
    return op<=k;
}

int main()
{
    
    Int(n,k);
    ll ma=0ll;

    for(int i=1;i<=n;++i){
        Int(a[i]);
        ma=max(a[i],ma);
    }

    ll l=1,r=ma,ans;

    while(l<=r){
        ll mid =(l+r)/2;

        if(valid(mid)){
            ans=mid;
            r=mid-1;
        }
        else{
            l=mid+1;
        }
    }
    printf("%lld\n", ans);


    return 0;
}






Measured memory_bytes: 5212
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	string s;
	cin>>n>>s;
	string ans;
	string cand[4]={"SS","SW","WS","WW"};
	for(int i=0;i<4;i++)
	{
		for(int j=2;j<=n;j++)
		{
			if(cand[i][j-1]=='S'&& s[j-1]=='o'){
				if(cand[i][j-2]=='S')
				   cand[i]+='S';
				else 
				   cand[i]+='W';
			}
			else  if(cand[i][j-1]=='S'&& s[j-1]=='x'){
				if(cand[i][j-2]=='S')
				   cand[i]+='W';
				else 
				   cand[i]+='S';
			}
			else  if(cand[i][j-1]=='W'&& s[j-1]=='o'){
				if(cand[i][j-2]=='S')
				   cand[i]+='W';
				else 
				   cand[i]+='S';
			}
			else  if(cand[i][j-1]=='W'&& s[j-1]=='x'){
				if(cand[i][j-2]=='S')
				   cand[i]+='S';
				else 
				   cand[i]+='W';
			}
		}
		if(cand[i][0]!=cand[i][n])continue;
		if((cand[i][0]=='S'&& s[0]=='o'&& cand[i][1]==cand[i][n-1])||
		  (cand[i][0]=='S'&& s[0]=='x'&& cand[i][1]!=cand[i][n-1])||
		  (cand[i][0]=='W'&& s[0]=='o'&& cand[i][1]!=cand[i][n-1])||
		  (cand[i][0]=='W'&& s[0]=='x'&& cand[i][1]==cand[i][n-1])){
		  	ans=cand[i].substr(0,n);
		  	break;
		  }	
	} 
	if(ans.size()>0)cout<<ans;
	else cout<<-1;  
	return 0;
} 

Measured memory_bytes: 1024
<?php
//error_reporting(0);
//$N = (int)trim(fgets(STDIN));
//$R = trim(fgets(STDIN));
list($N,$M) = array_map('intval',explode(" ",trim(fgets(STDIN))));
//$s = trim(fgets(STDIN));
$A = array_map('intval',explode(" ",trim(fgets(STDIN))));

$sum = array_sum($A);
printf("%d\n",max(-1,$N-$sum));

Measured memory_bytes: 16988
H,W=map(int,input().split())
S=[list(input()) for i in range(H)]

dp=[[H*W]*W for i in range(H)]
dp[0][0]=0
for i in range(1,W):
    if S[0][i]==S[0][i-1]:
        dp[0][i]=dp[0][i-1]
    else:
        dp[0][i]=dp[0][i-1]+1
for i in range(1,H):
    if S[i][0]==S[i-1][0]:
        dp[i][0]=dp[i-1][0]
    else:
        dp[i][0]=dp[i-1][0]+1

for i in range(1,H):
    for j in range(1,W):
        if S[i][j]==S[i][j-1]:
            dp[i][j]=min(dp[i][j],dp[i][j-1])
        else:
            dp[i][j]=min(dp[i][j],dp[i][j-1]+1)
        if S[i][j]==S[i-1][j]:
            dp[i][j]=min(dp[i][j],dp[i-1][j])
        else:
            dp[i][j]=min(dp[i][j],dp[i-1][j]+1)

if S[0][0]==S[-1][-1] and S[0][0]==".":
    print(dp[-1][-1]//2)
elif S[0][0]==S[-1][-1] and S[0][0]=="#":
    print(dp[-1][-1]//2+1)
else:
    print((dp[-1][-1]+1)//2)

Measured memory_bytes: 42224
#include<bits/stdc++.h>
using namespace std;
 
int main(){
  int n;
  cin >> n;
  vector<int> score(n,0);
  int ans = 0;
  for(int i = 0; i < n; i++){
    cin >> score.at(i);
    ans += score.at(i);
  }
  
  sort(score.begin(),score.end());
  for(int i = 0; i < n; i++){
    if(ans % 10 != 0){
      cout << ans << endl;
      return 0;
    }
    else{
      if(score.at(i) % 10 != 0){
      ans = ans - score.at(i);
      }
    }
  }
  if(ans % 10 == 0){
    cout << 0 << endl;
    return 0;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  char i;
  cin >> i;
  if(i == 'a' || i == 'i' || i == 'u' || i == 'e' || i == 'o' ){
    cout << "vowel" << endl;
  }else{
    cout << "consonant" << endl;
  }
} 

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const double PI = 3.1415926535;
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;


int main(){
    string s;
    int k;
    cin >> s >> k;
    int n = s.size();
    vector<vector<vector<ll>>>dp(10010,vector<vector<ll>>(2, vector<ll>(5)));
    dp[0][0][0] = 1;
    rep(i, 0, n){
        rep(j, 0, k+1){
            dp[i+1][1][j+1] += dp[i][1][j]*9;
            dp[i+1][1][j] += dp[i][1][j];
            int p = s[i]-'0';
            if(p>0){
                dp[i+1][1][j+1] += dp[i][0][j]*(p-1);
                dp[i+1][1][j] += dp[i][0][j];
                dp[i+1][0][j+1] = dp[i][0][j];
            }else{
                dp[i+1][0][j] = dp[i][0][j];
            }
        }
    }
    cout << dp[n][1][k]+dp[n][0][k] << endl;
}

Measured memory_bytes: 5160
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#define maxn 600000
#define maxm 5000000
using namespace std;

int n,i,j,k,ans[maxn];
int tot,t[maxm][3],tag[maxm],_3[13],p[maxm];

void maketree(int x,int dep,int s){
	if (dep==n) {p[x]=s;return;}
	for(int i=0;i<3;i++){
		t[x][i]=++tot;
		maketree(t[x][i],dep+1,s+i*_3[dep]);
	}
}

void change(int x,int dep){
	if (dep==n) return;
	if (tag[x]) {
		swap(t[x][1],t[x][2]),tag[x]^=1;
		for(int i=0;i<3;i++) tag[t[x][i]]^=1;
	} 
	int tmp=t[x][2]; t[x][2]=t[x][1],t[x][1]=t[x][0],t[x][0]=tmp;
	change(t[x][0],dep+1);
}

void downtag(int x,int dep,int s){
	if (dep==n) {ans[p[x]]=s;return;}
	if (tag[x]){
		swap(t[x][1],t[x][2]),tag[x]^=1;
		for(int i=0;i<3;i++) tag[t[x][i]]^=1;
	}
	for(int i=0;i<3;i++) downtag(t[x][i],dep+1,s+i*_3[dep]);
}

int main(){
	_3[0]=1;for(i=1;i<=12;i++) _3[i]=_3[i-1]*3;
	scanf("%d",&n);
	tot=1,maketree(1,0,0);
	char ch;
	while (ch!='S'&&ch!='R') ch=getchar();
	while (ch=='S'||ch=='R'){
		if (ch=='S') tag[1]^=1; 
		else change(1,0);
		ch=getchar();
	}
	downtag(1,0,0);
	for(i=0;i<_3[n];i++) printf("%d ",ans[i]);
}


Measured memory_bytes: 21560
w,a,b=map(int,input().split())
if len(sorted(set(range(a,a+w+1)) & set(range(b,b+w+1)))) !=0:
  print("0")
elif b>=a+w:
  print(b-a-w)
elif a>=b+w:
  print(a-b-w)

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

int main(){

  int n;
  int m;
  string s;
  long long int ans = 0;
  bool d = false;

  cin >> n;

  for(int i=0;i<n;i++){
    cin >> s >> m;

    if(s == "(") ans += m;
    if(s == ")") ans -=m;

    if(ans < 0) d = true;
  }

  if(ans == 0 && !d) cout << "YES" << endl;
  else cout << "NO" << endl;

}

Measured memory_bytes: 1200
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<map>
#include<cstdio>
#include<stack>
#include<queue>
#include<fstream>
#include<cstdio>
#include<deque>
#include<iomanip>
#include <numeric>
//#include<bits/stdc++.h>

using namespace std;
#define ok1 printf("ok1\n");
#define ok2 printf("ok2\n");
#define M 1000000000000000000LL
#define rep(i,n) for(int i=0;i<n;++i)
#define REP(i,s,n) for(int i=(s);i<(n);++i)
#define repr(i,n) for(int i=n-1;i>=0;--i)
#define REPR(i,s,n) for(int i=(s);i>=(n);--(i))
#define all(a) (a).begin(),(a).end()
#define reall(a) (a).rbegin(),(a).rend()
#define pb push_back
#define pf push_front
#define MIN(a,b) a=min((a),(b))
#define MAX(a,b) a=max((a),(b))
#define SIZE(v) (int)v.size()
const double pi = acos(-1.0);

typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vll> vvll;
typedef vector<char> vc;
typedef vector<double> vd;
typedef vector<bool> vb;
typedef deque<ll> dll;
typedef pair<ll, ll> P;
typedef vector<P> vP;
using Edge = pair<int, ll>;
using Graph = vector<vector<Edge> >;
const ll mod = 1e9 + 7;
ll dx[4] = { 1,0,-1,0 };
ll dy[4] = { 0,1,0,-1 };

void printvll(vll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) cout << v[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}
void printvvll(vvll v) {
	cout << "------------------------------------------------\n";
	rep(i, v.size()) {
		rep(j, v[i].size()) {
			cout << v[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void prints(string s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) cout << s[i] << " ";
	cout << endl;
	cout << "------------------------------------------------\n";
}

void printvs(vs s) {
	cout << "------------------------------------------------\n";
	rep(i, s.size()) {
		rep(j, s[i].size()) {
			cout << s[i][j] << " ";
		}
		cout << endl;
	}
	cout << "------------------------------------------------\n";
}

void Yes(bool x) {
	if (x) cout << "Yes\n";
	else cout << "No\n";
}

void YES(bool x) {
	if (x) cout << "YES\n";
	else cout << "NO\n";
}

void yes(bool x) {
	if (x) cout << "yes\n";
	else cout << "no\n";
}

void Yay(bool x) {
	if (x) cout << "Yay!\n";
	else cout << ":(\n";
}
ll gcd(ll x, ll y)
{
	ll r;
	while ((r = x % y) != 0)
	{
		x = y;
		y = r;
	}
	return y;
}
ll lcm(ll x, ll y)
{
	x /= gcd(x, y);
	y /= gcd(x, y);
	return (x * y);
}



ll  d, n, r, l, k, ans = 0, ret = M;
bool flag = false, flag2 = false, flag3 = false;
string s, t;
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll a, b;
	cin >> a >> b;
	if (a == b) ans = a + b;
	else ans = max(a, b) + max(a, b)-1;
	cout << ans << endl;
	return 0;

}


Measured memory_bytes: 256
#include <iomanip>
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;

int main(void) {
  ios::sync_with_stdio(false);
  int N, X, T;
  cin >> N >> X >> T;
  int answer = (N + X - 1) / X * T;
  cout << answer << endl;
  return 0;
}


Measured memory_bytes: 3632