akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <math.h>
#include <stdlib.h>
#include <set>
#include <map>
#include <iterator>

using namespace std;

long long build(long long k)
{
    long long sum = 0;
    for (long long i = 0;i <= k;i++){
        sum += i;
    }
    return sum;
}

int main()
{
    vector <long long> m(0);
    vector <long long> M(0);
    string s;
    cin >> s;
    long long n = s.length();
    if (s[0] == '<'){
        m.push_back(0);
    }
    else if (s[0] == '>') {
        M.push_back(0);
    }
    for  (long long i = 0;i < s.length()-1;i++){
        if (s[i] == '>' && s[i+1] == '<'){
            m.push_back(i+1);
        }
        if (s[i] == '<' && s[i+1] == '>'){
            M.push_back(i+1);
        }
    }
    if (s.back() == '>'){
        m.push_back(n);
    }
    else {
        M.push_back(n);
    }
    long long ans = 0;
    if (m[0] < M[0]){
        for (long long i = 0;i < m.size()-1;i++){
            ans += build(m[i+1]-M[i]-1)+build(M[i]-m[i]-1)+max(m[i+1]-M[i],M[i]-m[i]);
        }
        if (m.size() == M.size()){
            ans += build(M.back()-m.back());
        }
        cout << ans << endl;
    }
    else {
        ans += build(m[0]-M[0]);
        for (long long i = 0;i < m.size()-1;i++){
            ans += build(m[i+1]-M[i+1]-1)+build(M[i+1]-m[i]-1)+max(m[i+1]-M[i+1],M[i+1]-m[i]);
        }
        if (M.size() > m.size()){
            ans += build(M.back()-m.back());
        }
        cout << ans << endl;
    }
    
    
}


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end())
int main(){
    vector<int> a(3);
    cin>>a[0]>>a[1]>>a[2];
    int k;
    cin>>k;
    all(a);
    rep(i,k){
        a[2] = a[2]*2;
    }
    int sum=0;
    rep(i,3){
        sum += a[i];
    }
    cout<<sum<<endl;
}
    

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

#define inf  1e18
#define int  long long
#define float double
#define endl  "\n"
#define w(t)  int t;cin>>t;while(t--)
#define str  to_string
#define vci  vector<int>
#define vcs  vector<string> 
#define mp   make_pair
#define pb   push_back
#define pii   pair<int,int>
#define pis   pair<int,string>
#define fastio() ios::sync_with_stdio(0);cin.tie(0)
#define mod   1000000007
random_device rd;
mt19937 rand_gen(rd());
#define setbits(x)     __builtin_popcountll(x)
#define trailzero(x)   __builtin_ctzll(x)
#define shuffle(vc) shuffle(vc.begin(), vc.end(), rand_gen);
#define decimal(x,value)  cout<<fixed<<setprecision(x)<<value
void io()
{
	ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
	#ifndef ONLINE_JUDGE
		freopen("/home/kashif/cp/input.txt","r",stdin);
		
		freopen("/home/kashif/cp/output.txt","w",stdout);
	#endif

}
int n,p;
int dp[100005];
int h[100005]={0};
int ans(int h[],int k)
{
	
	if(k>=n)
		return dp[k]=0;
	if(k==n-1)
		return dp[k]=abs(h[k]-h[k+1]);
	int &a=dp[k];
	if(a!=-1)
		return a;
	
	else
	{
		a=inf;
		for(int i=1;i<=p && (k+i)<=n;i++)
		{
			a=min(a,abs(h[k]-h[k+i])+ans(h,k+i));
		}
	}
	return a;

}
//


int32_t main()
{
	
	fastio();
	io();
	memset(dp,-1,sizeof(dp));
	cin>>n>>p;
	
	for(int i=1;i<=n;i++)
	{
		cin>>h[i];
	}
	cout<<ans(h,1)<<endl;


	
	
}


Measured memory_bytes: 11396
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef  long long ll;
ll gcd(ll x,ll y){
   if(y==0) return x;
   else return gcd(y,x%y);
}
ll lcm(ll x,ll y){
   return x/gcd(x,y)*y;
}
using namespace std;
int main(){ 
   int a,b;
   cin>>a>>b;
   int c=a%2;
   int d=b%2;
   c==d? cout<<(a+b)/2:cout<<"IMPOSSIBLE";

   

   


   
   return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

void trace(int a[], int n){
    int i;
    for(i=0;i<n;i++){
        if(i>0) printf(" ");
        printf("%d",a[i]);
    }
    printf("\n");
}

void insertionSort(int a[], int n){
    int j,i,v;
    for(i=1;i<n;i++){
        v=a[i];
        j=i-1;
        while(j>=0&&a[j]>v){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=v;
        trace(a,n);
    }
}

int main(){
    int n,i,j;
    int a[100];
    
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&a[i]);
    
    trace(a,n);
    insertionSort(a,n);
    
    return 0;
}


Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define endl '\n';
using namespace std;
typedef long long int LL;

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

  //freopen("input.in","r",stdin);
 
  int n,res=0;
  cin>>n;
  string a,b;
  cin>>a>>b;
  for(int i=0;i<n;i++)
  {
  	bool fnf=true;
  	for(int j=i,c=0;j<n;j++,c++)
  	{
  		if(a[j]!=b[c])
  		{
  			fnf=false;break;
  		}
  	}
  	if(fnf)
  		break;
  	res++;
  }
          
 cout<<res+n<<endl;
  
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef pair<string , int> s_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define puf push_front
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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 (a>b) { a=b; return 1; } return 0; }
template<typename T> void remove(T & vector, unsigned int index){vector.erase(vector.begin() + index);}

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

  int N; ll C, K; cin >> N >> C >> K;
  vel T(N); rep(i,N) cin >> T[i];
  sort(all(T));
  
  ll ans = 0;
  while(!T.empty()) {
    ll fast = T[0];
    rep(i,C) {
      if(T.empty()) break;
      if(T[0] <= fast + K ) remove(T, 0);
      if(T[0] > fast + K) break;
    }
    ans++;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
struct Line{
	int p;
	int start;
	int end;
	bool operator<(const Line& another )const {
        return p > another.p;
    }
    int getS()	{
    	return start-1;
    };
    int getE()	{
    	return end-1;
    };
};

int main(){


	int n, m, a;
	cin >> n >> m >> a;
while(n !=0 || m!= 0 || a!= 0){
	int s[100];
	for(int i = 0; i < n; i++){
		s[i] = 0;
	}
	s[a-1] = 1;
	Line line[1000];
	for(int i = 0; i < m; i++){
		int x,a,b;
		cin >> x>>a>>b;
		line[i].p=x, line[i].start=a, line[i].end=b;
	}
	sort(line, line+m);
	for(int i = 0; i < m; i++){
		swap(s[line[i].getS()],s[line[i].getE()]);
	}
	for(int i = 0; i < n; i++){
		if(s[i] == 	1)cout << i+1 << endl;
	}
	cin >> n >> m >> a;
}
	return 0;
}



Measured memory_bytes: 3036
#include <iostream>
#include <algorithm>
#include <vector>
#include <set>
#include <cmath>
#include <deque>
#include <iterator>
#include <map>
#include <queue>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <limits>
#include <iomanip>
using namespace std;

using ll=long long;
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
using vll = V<ll>;
using vvll = V<vll>;
#define rep(i, k, n) for (ll i=k; i<(ll)n; ++i)
#define REP(i, n) rep(i, 0, n)
template<class T> inline bool chmax(T& a, T b) {if (a<b) {a=b; return true;} return false;}
template<class T> inline bool chmin(T& a, T b) {if (a>b) {a=b; return true;} return false;}

const ll MOD = 1000000007;
const ll HIGHINF = (ll)1e18;

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

int main() {
  ll n, x; cin >> n >> x;
  cout << 3 * (n-gcd(n, x)) << endl;
  return 0;
}


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

int main () {
  string s;
  cin >> s;
  
  for(int i=0;i<3;i++){
    if(s[i]=='1'){
      s[i]='9';
    }
    else if(s[i]='9'){
      s[i]='1';
    }
  }
  
  cout << s;
}


Measured memory_bytes: 256
#include<stdio.h>

#define INFTY -1
#define WHITE 0
#define GRAY 1
#define BLACK 2
#define N 105

typedef struct{
  int data[N];
  int head;
  int tail;
}queue;

queue Q;

int n;
int M[N][N];
int d[N] = {INFTY};
int color[N] = {WHITE};

void BFS(int);
void enqueue(int);
int dequeue();

int main(){
  int i, j;
  int u, k, v;

  scanf("%d",&n);

  for(i = 0 ; i < n ; i++){
    scanf("%d %d",&u,&k);
    for(j = 0 ; j < k ; j++){
      scanf("%d",&v);
      M[u-1][v-1] = 1;
    }
  }

  for(i = 0 ; i < n ; i++) d[i] = INFTY;

  BFS(0);

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

  return 0;
}

void BFS(int s){
  int v, u;

  d[s] = 0;
  color[s] = GRAY;
  Q.head = Q.tail = 0;

  enqueue(s);

  while(Q.tail < n){
    u = dequeue();
    if(u == INFTY) break;
    for(v = 0 ; v < n ; v++){
      if(M[u][v] == 0) continue;
      if(color[v] == WHITE){
	d[v] = d[u] + 1;
	color[v] = GRAY;
	enqueue(v);
      }
    }
		color[u] = BLACK;
  }
}

void enqueue(int x){

  if(Q.tail >= n) return;

  Q.data[Q.tail] = x;
  Q.tail++;
}

int dequeue(){
  int s;

  if(Q.head == Q.tail) return INFTY;

  s = Q.data[Q.head];
  Q.head++;

  return s;
}



Measured memory_bytes: 2140
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func floatSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	l := iSScan(n)
	sort.Ints(l)
	ans := 0
	for i := 0; i < n; i++ {
		for j := i + 1; j < n; j++ {
			a, b := l[i], l[j]
			r := sort.SearchInts(l, a+b)
			l := sort.SearchInts(l, abs(a-b))
			ans += r - larger(l, j+1)
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 1876
#include<iostream>
#include<algorithm>
#include<queue>
#include<cstring>
#include<cstdio>
#include<cmath>
#include<set>
#include<map>
#include<vector>
#include<cmath>
#include<ctime>

using namespace std;
const int maxn = 1e5 + 7;
const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const double pi = acos(-1.0);
typedef long long ll;
#define pb push_back

int n;
int W;
int w[150], v[150];
int dp[150][maxn];
int main(){
	memset(dp, 0x3f, sizeof dp);
	scanf("%d%d", &n, &W);
	for(int i = 1; i <= n; ++i)scanf("%d%d", &w[i], &v[i]);
	dp[0][0] = 0;
	for(int i = 1; i <= n; ++i){
		for(int j = 0; j <= 100005; ++j){
			if(j < v[i]) dp[i][j] = dp[i-1][j];
			else dp[i][j] = min(dp[i-1][j], dp[i-1][j-v[i]] + w[i]);
		}
	}

	int ans = 0;
	for(int i = 0; i <= 100005; ++i)
		if(dp[n][i] <= W) ans = i;
	printf("%d\n", ans);
}

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

int main() {
	// your code goes here
	int n;long long int d;
	cin>>n>>d;
//if(t>=30)
    long long int x[n];
    long long int y[n];
    for(int i=0;i<n;i++)
    {
     cin>>x[i];
     cin>>y[i];
    }
    int a=0;
    for(int i=0;i<n;i++)
     {
     	if(x[i]*x[i]+y[i]*y[i]<=d*d)
     	 a++;
     }
     cout<<a<<endl;
	return 0;
}

Measured memory_bytes: 6708
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define re return
#define mp map<int,int>
using namespace std;
struct ABC{
	int time;
	int dead;
}a[200005];
bool cmp(ABC x,ABC y){
	re x.dead<y.dead;
}
ll ans=0;
int main() {
	int n;
	cin>>n;
	rep(i,0,n) cin>>a[i].time>>a[i].dead;
	sort(a,a+n,cmp);
	rep(i,0,n){
		ans+=a[i].time;
		if(ans>a[i].dead){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	re 0;
}

Measured memory_bytes: 1792
#include<iostream>
#include <vector>
#include<string.h>
#include<cmath>
using namespace std;


int main(){
   long long int a,b,k;
   cin>>a>>b>>k;
   if(a-k>0){
      cout<<a-k<<" "<<b<<endl;
   }
   else if(a+b-k<=0){
      cout<<0<<" "<<0<<endl;
   }
   else
   {
      cout<<0<<" "<<b-(k-a)<<endl;
   }
   
   return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define r(i,n) for(int i=0;i<n;i++)
using namespace std;
int imos1[200009],imos2[200009],ans,sum,SUM;
vector<int>v;
string s;
stack<int>st;
int main(){
  cin>>s;
  r(i,s.size()){
    if(s[i]=='_')continue;
    if(s[i]=='\\')st.push(i);
    if(s[i]=='/'){
      if(st.empty())continue;
      int x=st.top();st.pop();
      imos1[x]+=(i-x);
      imos2[i]-=(i-x);
    }
  }
  r(i,200009){
    sum+=imos1[i];
    ans+=imos1[i];
    sum+=imos2[i];
    if(sum==0){
      SUM+=ans;
      if(ans!=0)v.push_back(ans),ans=0;
    }
  }
  cout<<SUM<<endl<<v.size();
  r(i,v.size()) cout<<' '<<v[i];
  cout<<endl;
}



Measured memory_bytes: 3440
#include<stdio.h>
int main()
{
 int a[100]={0};
  int N,i,j,tmp,Alice=0,Bob=0,point;
  scanf("%d",&N);
   for(i=0;i<N;i++)
  {
   scanf("%d",&a[i]);
  }
   for(j=0;j<N;j++)
  {
  for(i=0;i<N-1;i++)
  {
    if(a[i]<=a[i+1])
    {
      tmp=a[i];
      a[i]=a[i+1];
      a[i+1]=tmp;
    }
  }
  } 
     for(i=0;i<=N;i=i+2)
     {
      Alice=Alice+a[i]; 
     }
     for(i=1;i<=N;i=i+2)
     {
       Bob=Bob+a[i];
     }
     point=Alice-Bob;
  printf("%d",point);
  return 0;
}

Measured memory_bytes: 2080
import collections

N=int(input())
List=sorted(list(map(int, input().split())))

c = collections.Counter(List) #要素と出現回数の辞書
value, count = zip(*c.most_common())


newList=[]

for i in range(len(value)):
    if N-len(newList)>=value[i] and count[i]>=value[i]:
        for j in range(value[i]):
            newList.append(value[i])
    else:
        continue

#print(newList)

Ans=len(List)-len(newList)
print(Ans)

Measured memory_bytes: 27760
import bisect

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

bl = [bisect.bisect_left(A, b) for b in B]
for i in range(1, N):
    bl[i] += bl[i-1]
cl = [bisect.bisect_left(B, c) for c in C]

ans = 0
for c in cl:
    if c < 1:
        continue
    ans += bl[c-1]
print(ans)


Measured memory_bytes: 112356
#include <iostream>
#include <queue>

int main(void) {
    u_int m, n;

    std::cin >> n >> m;
    for (; m != 0 && n != 0; std::cin >> n >> m) {
        std::priority_queue<u_int> p;
        for (u_int i = 0, tmp; i < n; ++i) {
            std::cin >> tmp;
            p.push(tmp);
        }

        u_int sum = 0;
        for (u_int i = 1; i <= n; ++i) {
            if (i % m) {
                sum += p.top();
                p.pop();
            } else {
                if (!p.empty()) p.pop();
            }
        }

        std::cout << sum << std::endl;
    }

    return 0;
}

Measured memory_bytes: 1220
import heapq
n= int(input())
al = list(map(int,input().split()))
bl = list(map(int,input().split()))
suma,sumb = sum(al),sum(bl)
if suma<sumb:print(-1)
else:
    hpl=[]
    heapq.heapify(hpl)
    hml=[]
    heapq.heapify(hml)
    for i in range(n):
        if (dif:=al[i]-bl[i])>=0:heapq.heappush(hpl,-dif)
        else:heapq.heappush(hml,-dif)
    if len(hml)==0:
        print(0)
    else:
        count=0
        usem=False
        usep=False
        while len(hpl)!=0 and len(hml)!=0:
            pp = -hpl[0]
            mm = hml[0]
            if pp>mm:
                hpl[0]+=hml[0]
                heapq.heappop(hml)
                usem=False
                count +=1                    
                usep=True
            elif pp<mm:
                hml[0]+=hpl[0]
                heapq.heappop(hpl)
                usep=False
                count +=1
                usem=True
            else:
                heapq.heappop(hpl)
                usep=False
                count+=1
                heapq.heappop(hml)
                usem=False
                count+=1                 
        if usem:count+=1
        if usep:count+=1
        print(count)

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

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int res=0;
    auto f=[&](char x){
        int cnt=0;
        for(int i=0;i<s.size();i++){
            if(s[i]==x) cnt++;
            else break;
        };
        res=max(res,n-cnt);
    };
    f('<');
    reverse(s.begin(),s.end());
    f('>');
    cout<<res<<endl;
    return 0;
}


Measured memory_bytes: 3300
#include <bits/stdc++.h>
#define sz(x) (int)(x).size()
#define For(i, a, b) for (int i = int(a); i < int(b); i++)
#define Dor(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define Foz(i, a) For(i, 0, a)
#define Doz(i, a) Dor(i, 0, a)
#define Trav(e, v) for (auto& e : v)
#define pb push_back
#define mp make_pair
#define all(x) begin(x), end(x)
using namespace std;
using ll = long long;
using ii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vii = vector<ii>;
template <typename T> bool ckmin (T& a, T b) { return (b < a) ? a = b, 1 : 0; }
template <typename T> bool ckmax (T& a, T b) { return (b > a) ? a = b, 1 : 0; }
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#ifdef XVENOM
	#define errp(...) fprintf(stderr, __VA_ARGS__)
	#define dbg(...) errp("[%s]: ", #__VA_ARGS__), dbg_str(__VA_ARGS__)
#else
	#define errp(...)
	#define dbg(...)
#endif
template <typename U, typename V> string to_string (pair<U, V>);
string to_string (string& e) { return "\"" + e + "\""; }
string to_string (char e) { return "\'" + string(1, e) + "\'"; }
string to_string (bool e) { return e ? "true" : "false"; }
template <typename T> string to_string (T e) {
	string s = "[ ";
	for (auto& x : e) s += to_string(x) + " ";
	return s + "]";
}
template <typename U, typename V> string to_string (pair<U, V> e) {
	return "(" + to_string(e.first) + ", " + to_string(e.second) + ")";
}
void dbg_str () { errp(" \n"); }
template <typename U, typename... V> void dbg_str (U u, V... v) {
 	errp(" %s", to_string(u).c_str()); dbg_str(v...);
}
/* --- */
const int N = 100010;
string s, t, c = "SW";
int n;

char opp (char x) { return (x == 'W') ? 'S' : 'W'; }

bool can(char c1, char c2) {
	t = s;
	t[0] = c1; t[1] = c2;
	For(i, 2, n + 2) {
		if (t[i - 1] == 'W') {
			t[i] = (s[i - 1] == 'o') ? opp(t[i - 2]) : t[i - 2];	
		}
		else {
			t[i] = (s[i - 1] == 'o') ? t[i - 2] : opp(t[i - 2]);
		}
	}
	return t[0] == t[n] && t[1] == t[n + 1];
}

int main() {
	ios_base::sync_with_stdio(0); cin.tie(0);
	/* --- */
	cin >> n >> s;
	s += s[0]; s += s[1];
	string ans = "-1";
	Foz(i, 2) Foz(j, 2) if (can(c[i], c[j])) {
		ans = t; 
		ans.pop_back();  
		ans.pop_back();  
	}
	cout << ans << '\n';
}



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

long long gcd(long long a,long long b){
    while(b>0){
        long long x=a;
        a=b;
        b=x%a;
    }
    return a;
}

long long lcm(long long a,long long b){
    long long g=gcd(a,b);
    return a*(b/g);
}

int main() {
    int N=0; cin >> N;
    vector<long long> V(N);
    for(int i=0;i<N;i++){
        cin >> V.at(i);
    }
    long long ans=1;
    for(int i=0;i<N;i++){
        ans=lcm(ans,V.at(i));
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        sc.close();

        int l = s.length();
        int ans = Integer.MAX_VALUE;

        for (int i = 0; i < l - 2; i++) {
            int num = Integer.parseInt(s.substring(i, i + 3));
            ans = Math.min(ans, Math.abs(753 - num));
        }

        System.out.print(ans);
    }
}

Measured memory_bytes: 21716
#include<bits/stdc++.h>
using namespace std;
const int N=2e5+5;
int a[N]={0},n,x,res,i;
int main(){
	cin>>n;
	for(i=1;i<=n;i++){
		cin>>x;
		a[x]++;
	}
	for(i=1;i<100000;i++)res=max(res,a[i-1]+a[i]+a[i+1]);
	cout<<res;
}

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

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

  int cnt=0;
  for (int i=1; i<str.size(); i++) {
    if (str[i-1] != str[i]) {
      cnt++;
    }
  }

  cout << cnt << endl;
  return 0;
}


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()

using vi = vector<int>;
using vvi = vector<vi>;
using vd = vector<long double>;
using vvd = vector<vd>;

void pdp(vvd dp) {
  int n_ = dp.size();
  cout << "----------s------------" << endl;
  rep(i, n_) {
    rep(j, n_) {
      cout << dp.at(i).at(j);
      if (j == n_-1) {
        cout << endl;
      } else {
        cout << " ";
      }
    }    
  }
  cout << "----------e------------" << endl;
}

int main() {
  int n; cin >> n;
  int n_ = n+1;

  vd p(n_);
  rep(i, n_) {
    cin >> p.at(i);
  }
  
  vvd dp = vvd(n_, vd(n_));
  dp.at(0).at(0) = 1;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j <= i; j++) {
      if (j > i) continue;
      dp.at(i+1).at(j) += dp.at(i).at(j) * p.at(i);
      dp.at(i+1).at(j+1) += dp.at(i).at(j) * (1.0 - p.at(i));
      //cout << "i: " << i << ", j: " << j << ", p_i: " << p.at(i) << endl;
      //pdp(dp);
    }
  }
  
  double result = 0.0;
  int m = n/2 + 1;
  for (int j = 0; j < m; j++) {
    result += dp.at(n).at(j);
    //cout << "inc cout: " << result << endl;
  }
  
  cout << setprecision(10) << (double)result << endl;
}


Measured memory_bytes: 141056
n = gets.to_i
hs = gets.split.map &:to_i

cost = Array.new(n + 1, Float::INFINITY)

cost[0] = 0
cost[1] =(hs[0] - hs[1]).abs

(2...n).each{ |i|
	this1 = cost[i - 2] + (hs[i] - hs[i - 2]).abs
	this2 = cost[i - 1] + (hs[i] - hs[i - 1]).abs
	
	if cost[i] > this1 then
		cost[i] = this1
	end

	if cost[i] > this2 then
		cost[i] = this2
	end
}

puts cost[n-1]

Measured memory_bytes: 8716
in_line = raw_input().split()
r = int(in_line[0])
c = int(in_line[1])
data = []
for i in range(0,r):
    in_line = raw_input().split()
    data.append([])
    for j in range(0,c):
        data[i].append(int(in_line[j]))
for data_r in data:
    sum_r = 0
    for data_c in data_r:
        sum_r += data_c
        print data_c,
    data_r.append(sum_r)
    print sum_r
for j in range(0,c+1):
    sum_c = 0
    for i in range(0,r):
        sum_c += data[i][j]
    print sum_c,

Measured memory_bytes: 6468
#include <bits/stdc++.h>
using namespace std;
using i64 = long long;
#define rep(i,s,e) for(int (i) = (s);(i) <= (e);(i)++)
#define all(x) x.begin(),x.end()

int N,M;
int X[10101];
int Y[10101];
i64 T[10101];
char L[10101];
int R;
int Z[1010];

i64 land[202][202];
i64 sea[202][202];

int solve(){
  rep(i,0,N - 1) rep(j,0,N - 1) land[i][j] = sea[i][j] = 1e9;
  rep(i,0,N - 1) land[i][i] = sea[i][i] = 0;
  rep(i,0,M - 1){
    cin >> X[i] >> Y[i] >> T[i] >> L[i];
    X[i]--;
    Y[i]--;
    if(L[i] == 'L'){
      land[X[i]][Y[i]] = min(land[X[i]][Y[i]],T[i]);
      land[Y[i]][X[i]] = min(land[Y[i]][X[i]],T[i]);
    }
    else{
      sea[X[i]][Y[i]] = min(sea[X[i]][Y[i]],T[i]);
      sea[Y[i]][X[i]] = min(sea[Y[i]][X[i]],T[i]);
    }
  }
  cin >> R;
  rep(i,0,R - 1){
    cin >> Z[i];
    Z[i]--;
  }
  rep(k,0,N - 1) rep(i,0,N - 1) rep(j,0,N - 1)
    land[i][j] = min(land[i][j] , land[i][k] + land[k][j]);
  rep(k,0,N - 1) rep(i,0,N - 1) rep(j,0,N - 1)
    sea[i][j] = min(sea[i][j] , sea[i][k] + sea[k][j]);
  vector<vector<i64>> dp(R,vector<i64>(N,1e18));
  dp[0][Z[0]] = 0;

  rep(i,1,R - 1){
    rep(j,0,N - 1){
      rep(k,0,N - 1){
        dp[i][j] = min(dp[i][j],dp[i - 1][k] + land[Z[i - 1]][k] + sea[k][j] + land[j][Z[i]]);
        dp[i][k] = min(dp[i][k],dp[i - 1][k] + land[Z[i - 1]][Z[i]]);
      }
    }
  }
  i64 ans = 1e18;
  rep(i,0,N - 1){
    ans = min(ans , dp[R - 1][i]);
  }
  cout << ans << endl;
}

int main(){
  while(cin >> N >> M,N && M) solve();
}



Measured memory_bytes: 5132
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
int main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	string s;
	cin >> n >> s;
	vector<int> dp(n+1, 0), sum(n+1, 1);
	dp[1] = 1, sum[0] = 0;
	for (int i = 1; i < n; i++) {
		for (int j = 1; j <= i+1; j++) {
			if (s[i-1]=='>')
				dp[j] = (sum[i] - sum[j-1] + mod) % mod;
			else
				dp[j] = sum[j-1];
		}
		for (int j = 1; j <= n; j++)
			sum[j] = (sum[j-1] + dp[j]) % mod;
	}
	cout << sum[n] << "\n";
	return 0;
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(void){
    long min;
    long n,a[5];
    cin >> n >> a[0] >> a[1] >> a[2] >> a[3] >> a[4];
    min = a[0];
    for(int i=0;i<5;i++){
        if(a[i] < min)min = a[i];
    }
    long res = n/min + 5;
    if(n%min == 0)res--;
    cout << res << endl;
    return 0;
}

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

int main()
{
    int a, b, c, x;
    cin >> a >> b >> c >> x;
    int ans = 0;
    for (size_t i = 0; i <= a; i++)
    {
        for (size_t j = 0; j <= b; j++)
        {
            for (size_t k = 0; k <= c; k++)
            {
                if (500 * i + 100 * j + 50 * k == x)
                {
                    ans++;
                }
            }

            /* code */
        }
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include <numeric>
using namespace std;
int a, b, c;
char s;
int main() {
    cin >> s;
    if(s=='a'||s=='i'||s=='u'||s=='e'||s=='o') cout << "vowel" << endl;
    else cout <<"consonant" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define frst first
#define sec second
#define fast cin.tie(0) , ios_base :: sync_with_stdio(0)
#define db double
#define mod 1000000007
void online_judge()
{
#ifndef ONLINE_JUDGE
	freopen("Input.txt", "r", stdin);
	freopen("Output.txt", "w", stdout);
#endif
}



ll dp[101][100001];
ll solve(ll wt[] , ll p[] , ll n , ll w)
{
	if (n == 0)return 0;
	if (dp[n][w] != -1)return dp[n][w];
	ll ans = solve(wt , p , n - 1 , w);
	if (wt[n - 1] <= w) {
		ans = max(ans , p[n - 1] + solve(wt , p , n - 1, w - wt[n - 1]));
	}
	return dp[n][w] = ans;
}

void go() {
	ll n , w;
	cin >> n >> w;
	ll wt[n] , p[n];
	for (int i = 0; i < n; ++i)cin >> wt[i] >> p[i];
	memset(dp , -1 , sizeof dp);
	cout << solve(wt , p , n , w);
}


int main() {
	fast;
	//online_judge();
	go();
}

Measured memory_bytes: 79232
using System;
using System.IO;
using System.Linq;
using System.Collections.Generic;

public class Program
{

	public void Proc()
	{
        int num = int.Parse(Reader.ReadLine());
        Call(num);

    }

    private void Call(int num) {
        /*
         *   int i = 1;
 CHECK_NUM:
  int x = i;
  if ( x % 3 == 0 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
 INCLUDE3:
  if ( x % 10 == 3 ){
    cout << " " << i;
    goto END_CHECK_NUM;
  }
  x /= 10;
  if ( x ) goto INCLUDE3;
 END_CHECK_NUM:
  if ( ++i <= n ) goto CHECK_NUM;

  cout << endl;
         * 
         * 
         */
        System.Text.StringBuilder ret = new System.Text.StringBuilder();
        int i = 1;
        do
        {
            int x = i;
            if(x % 3==0) {
                ret.Append(" " + i);
                continue;
            }
            int x2 = x;
            while(x2 > 0) {
                if(x2 % 10 == 3) {
                    ret.Append(" " + i);
                    break;
                }
                x2 = x2 / 10;
            }
        } while (++i <= num);
        Console.WriteLine(ret.ToString());
	}

    public class Reader
	{
		private static StringReader sr;
		public static bool IsDebug = false;
		public static string ReadLine()
		{
			if (IsDebug)
			{
				if (sr == null)
				{
					sr = new StringReader(InputText.Trim());
				}
				return sr.ReadLine();
			}
			else
			{
				return Console.ReadLine();
			}
		}
		private static string InputText = @"



30



";
	}

	public static void Main(string[] args)
	{
#if DEBUG
		Reader.IsDebug = true;
#endif
		Program prg = new Program();
		prg.Proc();
	}
}

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

#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()

using namespace std;

typedef long long ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
typedef long double ld;

const ll mod = (ll)1e9 + 7;
const ll mxN = 200200;

string red(string s) {
	stack<char> st;
	for(auto i: s)
		if(i=='(')
			st.push('(');
		else if(i==')' && (st.size()==0 || st.top()==')'))
			st.push(')');
		else
			st.pop();
	string ans="";
	while(st.size())
		ans+=st.top(),st.pop();
	reverse(all(ans));
	return ans;
}


int main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.precision(20);
	cout << fixed;
	
	ll n,ans=0;
	cin>>n;
	string s;
	cin>>s;
	for(int i=0;i+2<n;i++)
		if(s.substr(i,3)=="ABC")
			ans++;
	cout<<ans<<"\n";


}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main(){

    int a, b, c;
    cin >> a >> b >> c;

    if(a>b) cout << "a > b" << endl;
    else if (a<b) cout << "a < b" << endl;
    else cout << "a == b" << endl; 

    return 0;
}


Measured memory_bytes: 3068
#include <bits/stdc++.h>
#define MAX 100001
#define M 1000000007
#define ll long long
#define ld long double

// #define left (2*i+1)
// #define right (2*i+2)
// #define mid ((l+r)>>1)

using namespace std;

int n, m;
ll a[MAX];
vector<int> e[MAX];
int p[MAX], rnk[MAX];

int getRoot(int x) {
	if (p[x]==x) return x;
	return getRoot(p[x]);
}

int union_(int x, int y) {
	int rx = getRoot(x);
	int ry = getRoot(y);
	if (rx==ry) return 0;
	if (rnk[rx]>rnk[ry]) {
		p[ry] = rx;
		rnk[rx]++;
	}
	else {
		p[rx] = ry;
		rnk[ry]++;
	}
	return 0;
}

vector<int> component[MAX];
int done[MAX];

int isConnected() {
	for (int i=0;i<n;i++) {
		if (component[i].size()==n) return 1;
	}
	return 0;
}

int main() {
	cin >> n >> m;
	for (int i=0;i<n;i++) p[i] = i;
	for (int i=0;i<n;i++) cin >> a[i];
	for (int i=0;i<m;i++) {
		int u, v;
		cin >> u >> v;
		union_(u, v);
	}
	for (int i=0;i<n;i++) {
		component[getRoot(i)].push_back(i);
	}
	if (isConnected()) {
		cout << 0;
		return 0;
	}
	ll sum = 0;
	int comp = 0;
	for (int i=0;i<n;i++) {
		if (component[i].size()!=0) {
			comp++;
			int idx = -1;
			ll mn = INT_MAX;
			for (int j=0;j<component[i].size();j++) {
				if (a[component[i][j]]<mn) {
					mn = a[component[i][j]];
					idx = component[i][j];
				}
			}
			done[idx] = 1;
			sum+=mn;
		}
	}
	vector<ll> v;
	for (int i=0;i<n;i++) {
		if (component[i].size()!=0) {
			for (int j=0;j<component[i].size();j++) {
				if (!done[component[i][j]]) v.push_back(a[component[i][j]]);
			}
		}
	}
	sort(v.begin(), v.end());
	int left = (comp-1)*2-comp;

	if (v.size()<left) {
		cout << "Impossible";
		return 0;
	}
	for (int i=0;i<left;i++) {
		sum+=v[i];
	}
	cout << sum;
	return 0;
}

Measured memory_bytes: 9984
n=int(input())

def dfs(now):
    if int(now)>n:
        return 0
    for i in "753":
        if i not in now:
            ret=0
            break
    else:
        ret=1
    for i in "753":
        ret+=dfs(now+i)
    return ret
print(dfs("0"))

Measured memory_bytes: 3060
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<random>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<bitset>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//ライブラリゾーン！！！！
typedef long long ll;
typedef long double ld;
#define str string
#define rep(i,j) for(ll i=0;i<(long long)(j);i++)
#define all(a) (a).begin(),(a).end()
const ll Mod = 1000000007;
const ll gosenchou = 5000000000000000;
short gh[2][4] = { { 0,0,-1,1 },{ -1,1,0,0 } };
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {//隣接リスト表現
	ll to, cost;
};
struct E {//辺の情報を入れる変数
	ll from, to, cost;
};
bool operator<(E a, E b) {
	return a.cost < b.cost;
}
struct H {
	ll x, y;
};
bool operator<(H a, H b) {
	if (a.x != b.x) return a.x < b.x;
	return a.y < b.y;
}
bool operator>(H a, H b) {
	if (a.x != b.x) return a.x > b.x;
	return a.y > b.y;
}
bool operator==(H a, H b) {
	return a.x == b.x&&a.y == b.y;
}
bool operator!=(H a, H b) {
	return a.x != b.x || a.y != b.y;
}
ll gcm(ll i, ll j) {//最大公約数
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}
ld rad(H a, H b) {
	return sqrt(pow(a.x - b.x, 2.0) + pow(a.y - b.y, 2.0));
}//rad＝座標上の2点間の距離
ll ari(ll a, ll b, ll c) {
	return (a + b)*c / 2;
}//等差数列の和
ll fact(ll x, ll k, ll p) {//最大値、個数、あまり
	ll sum = 1;
	for (int i = 0; i < k; i++) {
		sum *= (x--);
		sum %= p;
	}
	return sum;
}//階乗(正）
ll mod_pow(ll x, ll n, ll p) {
	ll res = 1;
	while (n > 0) {
		if (n & 1) res = res*x%p;
		x = x*x%p;
		n >>= 1;
	}
	return res;
}//x^n%p
short ctos(char a) {
	return (int)(a - '0');
}
#define int long long
const long long Inf = 4523372036854775807;
const int inf = 15000000000;
//----------------------------------------------------
//++++++++++++++++++++++++++++++++++++++++++++++++++++
signed main() {
	int a, b;
	cin >> a >> b;
	int ans = 0;
	ans = a - 1;
	if (a <= b) ans++;
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;
 
int main() {
    int64_t x, y, ans;
    cin >> x >> y;
    ans = 0;
    switch (x)
    {
    case 1:
        ans += 300000;
        break;
    case 2:
        ans += 200000;
        break;
    case 3:
        ans += 100000;
        break;
    default:
        break;
    }
    switch (y)
    {
    case 1:
        ans += 300000;
        break;
    case 2:
        ans += 200000;
        break;
    case 3:
        ans += 100000;
        break;
    default:
        break;
    }
    if (x == 1 && y == 1) ans += 400000;
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    char s[5];
    cin >> s;
    int flag = 0;
    for(int i = 0; i <= 2; i++)
    {
        if(s[i] == s[i+1])
        {
            flag = 1;
            break;
        }
    }
    if (flag == 0)
    cout << "Good";
    else
    cout << "Bad";

}

Measured memory_bytes: 256
n = int(input())
a = [int(x) for x in input().split()]

if a.count(0) > 0:
    print(0)
    exit()

ans = 1

for i in range(n):
    ans *= a[i]
    if ans > 10**18:
        print(-1)
        exit()


if ans > 10**18:
    print(-1)
else:
    print(ans)


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

namespace ABC168D
{
    class Program
    {
        static void Main(string[] args)
        {
            var NM = ReadInt();
            int N = NM[0];
            int M = NM[1];

            int S = 0;//スタート
            List<int>[] edges = new List<int>[N].Select(x => new List<int>()).ToArray();
            for (int i = 0; i < M; i++)
            {
                var input = ReadInt();
                int A = input[0] - 1;
                int B = input[1] - 1;
                edges[A].Add(B);
                edges[B].Add(A);
            }

            //幅優先探索
            Queue<int> que = new Queue<int>();
            que.Enqueue(S);
            int[] distance = new int[N].Select(x => int.MaxValue).ToArray();
            int[] befere = new int[N];
            distance[S] = 0;

            while (que.Count > 0)
            {
                int q = que.Dequeue();

                foreach (var to in edges[q])
                {
                    int dis = distance[q] + 1;//コストの加算
                    if (distance[to] > dis)
                    {
                        distance[to] = dis;
                        befere[to] = q;
                        que.Enqueue(to);
                    }
                }
            }

            Console.WriteLine("Yes");
            for (int i = 1; i < N; i++)
            {
                Console.WriteLine(befere[i]+1);
            }
            Console.ReadKey();
        }

        static int[] ReadInt()
        {
            int[] ret = Console.ReadLine().Split().Select(int.Parse).ToArray();
            return ret;
        }
        static long[] ReadLong()
        {
            long[] ret = Console.ReadLine().Split().Select(long.Parse).ToArray();
            return ret;
        }
    }
}


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

using namespace std;

inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
template<class T> inline T sqr(T x) {return x*x;}

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int, int> pii;
typedef long long ll;

#define all(a)  (a).begin(),(a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define pb push_back
#define mp make_pair
#define each(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define exist(s,e) ((s).find(e)!=(s).end())
#define range(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)  range(i,0,n)
#define clr(a,b) memset((a), (b) ,sizeof(a))
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

const double eps = 1e-10;
const double pi  = acos(-1.0);
const ll INF =1LL << 62;
const int inf =1 << 29;

string board[8];

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

inline bool ranges(int x,int y){
	if(x<0||8<=x)
		return false;
	if(y<0||8<=y)
		return false;
	return true;
}

void move(char f,char e){
	int cmax=0;
	pii ans;
	bool rev=(f=='x');
	int s=(rev?-7:0);
	int t=(rev? 0:7);

	for(int ii=s;ii<=t;ii++){
		for(int jj=s;jj<=t;jj++){
			int i=abs(ii),j=abs(jj);
			if(board[i][j]!='.')
				continue;
			int cur=0;
			rep(k,8){
				int cx=i,cy=j;
				int tmp=0;
				while(ranges(cx+dx[k],cy+dy[k])){
					cx+=dx[k],cy+=dy[k];
					if(board[cx][cy]==e)
						tmp++;
					else
						break;
				}
				if(ranges(cx,cy)&&board[cx][cy]==f)
					cur+=tmp;
			}
			if(cur>cmax){
				cmax=cur;
				ans.first=i;
				ans.second=j;
			}
		}
	}
	if(cmax>0){
		rep(i,8){
			int cx=ans.first,cy=ans.second;
			board[cx][cy]=f;
			while(ranges(cx+dx[i],cy+dy[i])){
				cx+=dx[i],cy+=dy[i];
				if(board[cx][cy]!=e)
					break;
			}
			if(board[cx][cy]==f){
				cx=ans.first,cy=ans.second;
				while(ranges(cx+dx[i],cy+dy[i])){
					cx+=dx[i],cy+=dy[i];
					if(board[cx][cy]==e)
						board[cx][cy]=f;
					else
						break;
				}
			}
		}
	}
	return;
}

int main(void){
	rep(i,8) cin >> board[i];
	char f='o',e='x';
	rep(loop,128){
		move(f,e);
		swap(f,e);
	}
	rep(i,8) cout <<  board[i] << endl;
	return 0;
}

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

using namespace std;
typedef unsigned long long ll;
vector<pair<int ,int > > v;
int main(){
    ll n;
    cin>>n;
    for(ll i=2;i*i<=n;i++){
    	if(n%i==0){
    		int s = 0;
    		while(n%i ==0) n/=i,++s;
    		v.push_back(make_pair(i,s));
		}
	}
	if(n!=1) v.push_back(make_pair(n,1));
	ll ans = 0;
	for(auto x:v){
		int fir = x.first,sec = x.second;
		ll now = 0,nsum = 0;
		for(ll k =1;k<=1000000;k++){
			nsum += k;
			if(nsum>sec) {
				now = k-1;
				break;
			}
		}
		ans += now;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3640
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<stack>
#include<string>
#include<map>
#include<set>
#include<tuple>
#include<cmath>
#include<iomanip>


#define MOD 1000000007
#define INF 1001001001
#define MIN -1001001001
#define rep(i,k,N) for(int i=k;i<N;i++)
#define MP make_pair
#define MT make_tuple //tie,make_tuple は別物
#define PB push_back
#define PF push_front
#define all(x) (x).begin(),(x).end()


using namespace std;
typedef long long ll;
typedef vector<ll> v;
typedef vector<vector<ll>> vv;

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

int main(){
    ll N,K;
    cin>>N>>K;
    v a;
    map<ll,ll> ans;
    rep(i,0,K){
        ll d;
        cin>>d;
        a.clear();
        a.resize(d);
        rep(j,0,d){
            cin>>a[j];
            ans[a[j]]++;
        }
    }
    ll sum = 0;
    rep(i,1,N+1){
        if(ans[i] == 0)sum++;
    }
    cout<<sum;
    return 0;
}

Measured memory_bytes: 3632
using System;
using System.Collections.Generic;

public class Program
{
    public static void Main(string[] args)
    {
        var s = Console.ReadLine().ToCharArray();
        var t = Console.ReadLine().ToCharArray();

        var dicS2T = new Dictionary<char, char>();
        var dicT2S = new Dictionary<char, char>();


        //Array.Sort(sa);
        //Array.Sort(st);

        for (int i = 1; i < s.Length; i++)
        {
            if (!dicS2T.ContainsKey(s[i]) && !dicT2S.ContainsKey(t[i]))
            {
                dicS2T[s[i]] = t[i];
                dicT2S[t[i]] = s[i];
            }
            else if (dicS2T.ContainsKey(s[i]) && dicT2S.ContainsKey(t[i]))
            {
                if (dicS2T[s[i]]!= t[i] || dicT2S[t[i]] != s[i])
                {
                    Console.WriteLine("No");
                    return;
                }
            }
            else
            {
                Console.WriteLine("No");
                return;
            }
        }

        Console.WriteLine("Yes");
    } // Main
}

Measured memory_bytes: 15584
#include <bits/stdc++.h>
#define maxn 3000
using namespace std;

int n;
double ans;
double p[maxn];
double dp[maxn][maxn];

int main() {
	cin >> n;
	for( int i = 0 ; i < n ; i++ )
		cin >> p[i];
	dp[n][0] = 1;
	for( int i = n-1 ; i >= 0 ; i-- )
		for( int j = 0 ; j < n-i ; j++ ) {
			dp[i][j+1] += dp[i+1][j] * p[i];
			dp[i][j] += dp[i+1][j] * (1-p[i]);
		}
	for( int i = n/2 ; i <= n ; i++ )
		if( i > n-i )
			ans += dp[0][i];
	printf( "%.10lf\n" , ans );
}


Measured memory_bytes: 70016
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;
using vb = vector<bool>;
using vs = vector<string>;
using vp = vector<pii>;
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define sz(x) (ll)((x).size())
#define all(x) (x).begin(), (x).end()
#define each(a, x) for (auto&& a : (x))
#define _overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) rep2(_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, n) rep4(i, a, n, 1)
#define rep4(i, a, n, s) for (ll i = (a); i < (n); i += (s))
#define rep(...) _overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
const int INF = 1e9;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
const double PI = acos(-1.0);
const int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
const int dy[] = {0, 1, 0, -1, 1, -1, 1, -1};
template<typename T> inline void chmax(T& a, const T& b) {if (a < b) a = b;}
template<typename T> inline void chmin(T& a, const T& b) {if (a > b) a = b;}
template<typename T> inline void print(const T& x) {cout << x << "\n";}
struct Init {Init() {cin.tie(0); ios::sync_with_stdio(0); cout << fixed << setprecision(10);}} init;

int main() {
    string s;
    cin >> s;
    reverse(all(s));
    ll idx = 0;
    bool isOk = true;
    while (idx < sz(s)) {
        string sub5 = s.substr(idx, 5);
        string sub6 = s.substr(idx, 6);
        string sub7 = s.substr(idx, 7);
        if (sub5 == "maerd") idx += 5;
        else if (sub7 == "remaerd") idx += 7;
        else if (sub5 == "esare") idx += 5;
        else if (sub6 == "resare") idx += 6;
        else {
            isOk = false;
            break;
        }
    }
    if (isOk) print("YES");
    else print("NO");
}

Measured memory_bytes: 512
# C
import collections
from operator import mul
from functools import reduce

def cmb(n,r):
    r = min(n-r,r)
    if r == 0: return 1
    over = reduce(mul, range(n, n - r, -1))
    under = reduce(mul, range(1,r + 1))
    return over // under


N = int(input())
s = []
for i in range(N):
    tmp = list(input())
    tmp = sorted(tmp)
    tmp = ','.join(tmp)
    s.append(tmp)
c = collections.Counter(s)
ans_list = c.values()
ans_list = [i for i in ans_list if i >= 2]
ans = 0
if len(ans_list) != 0:
    for i in ans_list:
        ans += cmb(i, 2)
    print(ans)
else:
    print(ans)

Measured memory_bytes: 20756
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define IOS                  \
    ios::sync_with_stdio(0); \
    cin.tie(0);              \
    cout.tie(0);
#define ll long long
#define endl "\n"
#define ar array
#define deb(x) cout << #x << " = " << x << endl
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll MOD = 998244353;
const ll N = 2e5 + 1;

template <class T>
using oset = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
//order_of_key (k) : Number of items strictly smaller than k .
//find_by_order(k) : K-th element in a set (counting from zero).
inline ll add(ll a, ll b) { return ((a % mod) + (b % mod)) % mod; }
inline ll sub(ll a, ll b) { return ((a % mod) - (b % mod) + mod) % mod; }
inline ll mul(ll a, ll b) { return ((a % mod) * (b % mod)) % mod; }
struct comp
{
    bool operator()(const pair<ll, ll> &x, const pair<ll, ll> &y) const
    {
        return x.first < y.first;
    }
};
ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}
ll pwr(ll x, ll n)
{
    if (n == 0)
        return 1;
    if (n & 1)
        return mul(x, pwr(mul(x, x), (n - 1) / 2));
    else
        return pwr(mul(x, x), n / 2);
}
ll modInv(ll n)
{
    return pwr(n, mod - 2);
}
ll modInverse(ll a, ll m)
{
    ll m0 = m;
    ll y = 0, x = 1;

    if (m == 1)
        return 0;

    while (a > 1)
    {
        ll q = a / m;
        ll t = m;
        m = a % m, a = t;
        t = y;
        y = x - q * y;
        x = t;
    }

    if (x < 0)
        x += m0;

    return x;
}

int main()
{
    IOS;
    int t = 1;
    // cin >> t;
    while (t--)
    {
        int n;
        cin >> n;
        int ans = 0;
        for (int i = 1; i < n; i++)
        {
            int temp = n - i;
            for (int j = 1; j * j <= temp; j++)
            {
                if (temp % j == 0)
                {
                    ans++;
                    if (j * j != temp)
                        ans++;
                }
            }
        }
        cout << ans << endl;
    }
}

Measured memory_bytes: 3688