akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
int n,a[101010],b[101010];
string s;
bool check(int x,int y)
{
	a[0]=x;
	a[1]=y;
	for(int i=1;i<n;i++)
	{
		a[i+1]=b[i]*a[i-1]*a[i];
	}
	if(a[n]==a[0] && a[1]==b[0]*a[n-1]*a[0])
	{
		for(int i=0;i<n;i++)
		{
			if(a[i]==1)
			{
				cout<<'S';
			}
			else
			{
				cout<<'W';
			}
		}
		return true;
	}
	return false;
}
int main()
{
	cin>>n>>s;
	for(int i=0;i<n;i++)
	{
		if(s[i]=='o')
		{
			b[i]=1;
		}
		else
		{
			b[i]=-1;
		}
	}
	if(check(1,1))
	{
		return 0;
	}
	if(check(1,-1))
	{
		return 0;
	}
	if(check(-1,1))
	{
		return 0;
	}
	if(check(-1,-1))
	{
		return 0;
	}
	cout<<-1<<endl;
	return 0;
}

Measured memory_bytes: 1408
import java.util.Scanner;

public class Main {
	public static void main(String[]args) {
		try(Scanner scan = new Scanner(System.in)){
			
			int N = scan.nextInt();
			String S = scan.next();
			
		
			StringBuffer sc = new StringBuffer();
		
			
			if(N==1) {
				System.out.println(1);
			}else {
				sc.append(S.substring(0,1));
				
				for(int i = 1;i<=N-1;i++) {
					String s1 = S.substring(i-1, i);
				    String s2 = S.substring(i, i+1);
				    
				    if(s1.equals(s2)) {
				    	sc.append("X");
				    }else{
				    	sc.append(s2);
				    }
				}
				
				
				int count = 0;
				
				
				for(int i = 0;i<N;i++) {
					String s5 = sc.toString().substring(i, i+1);
					
					if(!s5.equals("X")) {
						count++;
					}
					
				}
				 
				System.out.println(count);
				
			
			
			}
			
			
			
			
			
			
			
			
		}
		
		
	}
		

}


Measured memory_bytes: 44312
#include<stdio.h>
int per(int a)
{
  int fact;
  int b=a-1;
  fact=b*a;
  return fact;
}
void main()
{
  int n,m,a,b,c,d,g;
  scanf("%d %d",&n,&m);
  a=n-2;
  b=m-2;
  {
    if(a>=0)
  {
    c=per(n)/2;
  }
  else
    c=0;
  }
  {
    if(b>=0)
  {
    d=per(m)/2;
  }
 else
   d=0;
  }
  g=d+c;
  printf("%d",g);
}
 


Measured memory_bytes: 1696
import java.util.*;

public class Main {
	public static void main (String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] base = sc.next().toCharArray();
		char[] test = sc.next().toCharArray();
		for (int i = base.length - test.length; i >= 0; i--) {
		    boolean flag = true;
		    for (int j = 0; j < test.length; j++) {
		        if (base[i + j] != test[j] && base[i + j] != '?') {
		            flag = false;
		            break;
		        }
		    }
		    if (flag) {
		        for (int j = 0; j < test.length; j++) {
		            base[i + j] = test[j];
		        }
    		    for (int j = 0; j < base.length; j++) {
    		        if (base[j] == '?') {
    		            base[j] = 'a';
    		        }
    		    }
    		    System.out.println(base);
    		    return;
		    }
		}
		System.out.println("UNRESTORABLE");
    }
}



Measured memory_bytes: 23124
#include        "algorithm"
#include        "iostream"
#include        "numeric"
#include        "iomanip"
#include        "cstring"
#include        "math.h"
#include        "bitset"
#include        "string"
#include        "vector"
#include        "ctime"
#include        "queue"
#include        "stack"
#include        "map"
#include        "set"

#include        "ext/pb_ds/assoc_container.hpp" // Common file
#include        "ext/pb_ds/tree_policy.hpp" // Including tree_order_statistics_node_update
#include        "ext/pb_ds/detail/standard_policies.hpp"

using namespace std;
using namespace __gnu_pbds;


#define          f first
#define          lgn 25
#define          endl '\n'
#define          sc second
#define          N (int)2e5+5
#define          pb push_back
#define          mod 1000000007
#define          ld long double
#define          vi vector<int>
#define          eb emplace_back
#define          vpii vector<pii>
#define          mii map<int,int>
#define          int long long 
#define          pii pair<int,int>
#define          pq priority_queue
#define          BLOCK (int)sqrt(N)
#define          test(x) while(x--)
#define          all(x) begin(x),end(x)
#define          allr(x) rbegin(x),rend(x)
#define          fo(i,a,n) for(int i=a;i<n;i++)
#define          rfo(i,n,a) for(int i=n;i>=a;i--)
#define          FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define          time() cerr << "Time : " << (double)clock() / (double)CLOCKS_PER_SEC << "s\n"
#define          PI acos(-1.0)
#define 		 bug(...)       __f (#__VA_ARGS__, __VA_ARGS__)

typedef tree< int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update > 
OS ;

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
     const char* comma = strchr (names + 1, ',');
     cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

inline void INP()
{
	#ifndef ONLINE_JUDGE
	    freopen("input.txt","r",stdin);   
	    freopen("output.txt","w",stdout);
	#endif 
}

const int inf = 0x3f3f3f3f;
const int INF = 0x3f3f3f3f3f3f3f3f;

int n,m,k,q;
string s;
vi adj[N];
int vis[N],par[N],a[N];

void go()
{
	cin >> n >> k;

	fo(i,1,n+1) cin >> a[i];

	sort( a+1 , a+n+1);
	int ans = 0;
	
	rfo(i,n-k,1)
	{
		ans += a[i];
	}	

	cout << ans << endl;
}

int32_t main()
{
	//INP(); 
	FAST;     
	int t=1; 
	// cin>>t;
	test(t) go();
}



Measured memory_bytes: 7168
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int n = in.nextInt();
		int t = in.nextInt();
		int e = in.nextInt();
		int t1 = t - e;
		int t2 = t + e;
		for (int i = 0; i < n; i++) {
			int x = in.nextInt();
			int a = t % x;
			if (a <= e || x - a <= e) {
				System.out.println(i + 1);
				System.exit(0);
			}
		}
		System.out.println(-1);
	}
}

Measured memory_bytes: 12000
#include<iostream>
using namespace std;
#define MAX 500000
#define SENTINEL 2000000000

int L[MAX/2+2],R[MAX/2+2];
int cnt;

void merge(int A[], int n, int left, int mid, int right){
	int n1 = mid -left;
	int n2 = right - mid;
	for(int i = 0; i < n1; i++) L[i] = A[left + i];
	for(int i = 0; i < n2; i++) R[i] = A[mid + i];
	L[n1] = R[n2] = SENTINEL;
	int i = 0, j = 0;
	for(int k = left; k < right; k++){
		cnt++;
		if(L[i] <= R[j]){
			A[k] = L[i++];
		}else{
			A[k] = R[j++];
		}
	}
}

void mergeSort(int A[], int n, int left, int right){
	if(left + 1 < right){
		int mid = (left + right) / 2;
		mergeSort(A,n,left,mid);
		mergeSort(A,n,mid,right);
		merge(A,n,left,mid,right);
	}
}

int main(){
	int A[MAX],n,i;
	cnt = 0;
	
	cin >> n;
	for(i = 0; i < n; i++) cin >> A[i];
	
	mergeSort(A,n,0,n);
	
	for(i = 0; i < n;i++){
		if(i) cout << " ";
		cout << A[i];
	}
	
	cout << endl;
	
	cout << cnt << endl;
	
	return 0;
}

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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

const int MAX = 510000;
long long fac[MAX], finv[MAX], inv[MAX];
bool initialized = false;

/**
 * @fn
 * This function must be called at first.
 */
void combination_init() {
    initialized = true;
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++) {
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

/**
 * @fn
 * Calculates the combination  ( nCK % p: N choose K mod p).
 *
 * @brief constraint: 1 ≤ k ≤ n ≤ 10^7
 * @return nCK % MOD
 */
long long combination(int n, int k) {
    assert(initialized);
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

/**
 * @fn
 * Calculates the factorial of the number.
 *
 * @return N! % MOD
 */
long long factorial(int n) {
    assert(initialized);
    if (n < 0) return 0;
    return fac[n] % MOD;
}

/**
 * @fn
 * Calculates the combination ( nCK % p: N choose K mod p).
 *
 * @brief constraint: 1 ≤ k ≤ 10^7 and 1 ≤ n ≤ 10^9
 * @return nCK % MOD
 */
long long combination2(int n, int k) {
    assert(initialized);
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    ll res = 1;
    k = min(k, n - k);
    for (long long x = 1; x <= k; x++) {
        res *= (n - x + 1);
        res %= MOD;
        res *= inv[x];
        res %= MOD;
    }
    return res;
}


void Main() {
    ll N, M; cin >> N >> M;
    combination_init();
    if (N == M){
        cout << 2 * factorial(N) % MOD * factorial(M) % MOD << endl;
    } else if (N == M - 1 || N == M + 1){
        cout << factorial(N) * factorial(M) % MOD << endl;
    } else {
        cout << 0 << endl;
    }
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
    return 0;
}


Measured memory_bytes: 12160
#include <bits/stdc++.h>
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define ll long long int
#define dbg(x) cout<<"( "<<#x<<" -> "<<x<<" )"<<endl;
using namespace std;
int main()
{
    int n;
    scanf("%d",&n);
    double val=((n+1)/2)/(1.0*(n));
    cout<<fixed<<setprecision(10)<<val<<endl;
    return 0;
}

Measured memory_bytes: 3796
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>
#include <math.h>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)
static const ll maxLL = (ll)1 << 62;

///////////////////////////
////Prime Creator//////////
///////////////////////////
//bool Prime[100001] = {};
//void createPrime() {
//	ll n = 100001;
//	rep(i, 0, n) Prime[i] = true;
//	Prime[0] = false;
//	Prime[1] = false;
//	rep(i, 2, n) {
//		if (Prime[i]) {
//			rep(j, 2, n) {
//				if (j*i >= n)break;
//				Prime[j*i] = false;
//			}
//		}
//	}
//}
///////////////////////////
///////////////////////////

//Minimum Value
static const ll MIN_LL = (ll)1 << 55;

////Warshall Floyid
////All value should be initialized by MIN_LL
//static const ll wf_size = 300;
//ll wf[wf_size][wf_size];
//void WarshalFloyid() {
//	rep(k, 0, wf_size)rep(i, 0, wf_size)rep(j, 0, wf_size)wf[i][j] = min(wf[i][j], wf[i][k] + wf[k][j]);
//}

ll N, A, B;
ll C;
ll h[100001] = {};
ll k[100001] = {};
bool t(ll n) {
	ll cnt = 0;
	rep(i, 0, N) {
		ll p = h[i];
		p -= B * n;
		if (p > 0) {
			cnt += p / C + (p % C != 0 ? 1 : 0);
		}
	}
	return cnt <= n;
}

int main() {
	cin >> N >> A >> B;
	C = A - B;
	rep(i, 0, N)cin >> h[i];

	ll lb = 0, ub = 1000000001;// (ll)1 << 55;
	ll m = 0;

	rep(i, 0, 1000) {
		m = (lb + ub) / 2;
		if (t(m)) {
			//success
			ub = m;
		}
		else {
			//fail
			lb = m;
		}
	}

	cout << ub << endl;

	return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
# define pi 3.141592653589793238462643383279502884
int main(){
    double A,B,h,m;
    cin>>A>>B>>h>>m;
    double a1,a2;
    a1=(h*30)+double(m/2);
    a2=6*m;
    double a=abs(a1-a2);
    if(a==180){
        cout<<A+B<<endl;
        return 0;
    }
    if(a>180)a=360-a;
    double rad=(double)(pi*a)/180;
    double ans=sqrt((A*A)+(B*B)-(2*A*B*cos(rad)));
    cout<<fixed<<setprecision(15)<<ans;
    return 0;
}


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


struct pond{
    int index;
    int area;
};

// main
int main(){
   // 入力
   string input;
   cin >> input;

   stack<int> s1;
   stack<pond> s2;
   int index;

   for(int i = 0; i < (int)input.size(); ++i){
       if(input[i] == '\\'){
           s1.push(i);
       }
       if(input[i] == '/'){
           if(s1.empty()){
               continue;
           }
           index = s1.top();
           s1.pop();
           pond new_pond = {index, i-index};
           while(!s2.empty() && s2.top().index > index){
               new_pond.area = new_pond.area + s2.top().area;
               s2.pop();
           }
           s2.push(new_pond);
       }else if(input[i] == '_'){
           // 何もしない
       }
   }

   // 水たまりの個数
   int num_pond = s2.size();

    // 総面積の計算, 各水たまりの面積の保存
    int all_area = 0;
    vector<int> pond_area(num_pond, 0);
    for(int i = 0; i < num_pond; ++i){
        pond_area[i] = s2.top().area;
        all_area += pond_area[i];
        s2.pop();
    }

    reverse(pond_area.begin(), pond_area.end());
    // 出力s
    cout << all_area << "\n" << num_pond;
    if(num_pond > 0){
        cout << " ";
        for (auto iter = pond_area.begin(); iter != pond_area.end()-1; ++iter){
            cout << *iter << " ";
        }
        cout <<  *(pond_area.end()-1);
    }
    cout << "\n";
    return 0;
}





Measured memory_bytes: 3224
<?php
$count = 0;
$loop = 0;
while ($line = fgets(STDIN)) {
    $data = explode(" ", rtrim($line));
    if ($count == 0) {
    	$loop = $data[0];
    } else {
    	$list = array();
    	for ($i = 0; $i < $loop; $i++) {
    		$list[] = $data[$i];
    	}
    	printf("%d %d %d\n", min($list), max($list), array_sum($list));
    }
    $count++;
}

Measured memory_bytes: 18396
N = int(input())
btn = []
for i in range(N):
    btn.append(int(input()))

tmp = 0
con = 0
for i in range(N):
    if btn[tmp] == 2:
        con += 1
        print(con)
        break
    
    elif btn[tmp] != 0:
        tmp2 = btn[tmp] - 1
        btn[tmp] = 0
        tmp = tmp2
        con += 1
    
    else:
        print(-1)
        break
    

Measured memory_bytes: 7084
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a)  (a).begin(),(a).end()
#define pb push_back
#define INF 99999999
#define eps 1e-9


int main(){
    double xa1,ya1,xa2,ya2,xb1,yb1,xb2,yb2;
    while(cin>>xa1>>ya1>>xa2>>ya2>>xb1>>yb1>>xb2>>yb2){
        bool f=false;
        if(xa2<xb1)f=true;
        if(xa1>xb2)f=true;
        if(ya1>yb2)f=true;
        if(ya2<yb1)f=true;
        if(f)cout<<"NO"<<endl;
        else cout<<"YES"<<endl;
    }
}

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

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

    
    long long r=0;
    long long g=0;
    long long b=0;
    for(int i=0;i<n;i++)
    {
      if(s[i]=='R')
        r++;
      if(s[i]=='G')
        g++;
      if(s[i]=='B')
        b++;
    
    }    
    
    long long ans=r*g*b;
    
    for(int i=1;i<n;i++)
    {
        for(int j=0;j<n;j++)
        {
            if(j+i+i>n-1)
              break;
            if(s[j]!=s[j+i] and s[j+i]!=s[j+i+i] and s[j]!=s[j+i+i])
               ans--;
        }
        
    }
    
    
    // ans=-1;
    
    

    cout<<ans;
    
    
}

Measured memory_bytes: 3600
import sys
import math  # noqa
import bisect  # noqa
import queue  # noqa


def input():
    return sys.stdin.readline().rstrip()


def main():
    X = int(input())

    n = 0
    a = 100
    while a < X:
        a = int(a * 1.01)
        n += 1

    print(n)


if __name__ == '__main__':
    main()


Measured memory_bytes: 69152
while 1:
  h,w = map(int, raw_input().split())
  if h==w==0: break
  M = [0]*(h+1)
  a=[0]*w
  for i in range(h):
    x = raw_input()
    b=[0]*w
    sp=-1
    C = [-1]*(h+1)
    for j in range(w):
      if x[j]=="*": c=0
      else: c=a[j]+1
      b[j]=c
      dw=c-sp
      if dw>0: C[sp+1:c+1]=[j]*dw
      elif dw<0:
        for k in range(c+1,sp+1): M[k]=max(M[k],j-C[k])
        C[c+1:sp+1]=[-1]*(-dw)
      sp=c
    for k in range(1,sp+1):
      if C[k]>=0: M[k]=max(M[k],w-C[k])
    a=b
  s=max([a*b for a,b in zip(M, range(h+1))])
  print s

Measured memory_bytes: 4304
use std::io::stdin;
use std::vec::Vec;

mod utils {
    use std::io::BufRead;
    use std::str::{self, FromStr};

    pub struct StdinReader<R: BufRead> {
        reader: R,
        buf: Vec<u8>,
    }

    impl<R: BufRead> StdinReader<R> {
        pub fn new(reader: R) -> StdinReader<R> {
            StdinReader {
                reader: reader,
                buf: Vec::new(),
            }
        }

        #[allow(unused)]
        #[inline]
        pub fn reads<T: FromStr>(&mut self) -> T {
            self.read_until(b' ')
        }

        #[allow(unused)]
        #[inline]
        pub fn readl<T: FromStr>(&mut self) -> T {
            self.read_until(b'\n')
        }

        #[allow(unused)]
        #[inline]
        pub fn read_vec<T: FromStr>(&mut self) -> Vec<T> {
            return self.read_until::<String>(b'\n').trim().split_whitespace().map(|c| c.parse().ok().unwrap()).collect();
        }

        #[inline]
        pub fn read_until<T: FromStr>(&mut self, delim: u8) -> T {
            loop {
                self.buf.clear();
                let len = self.reader
                    .read_until(delim, &mut self.buf)
                    .expect("failed reading bytes");
                match len {
                    0 => panic!("early eof"),
                    1 if self.buf[0] == delim => (),
                    _ => {
                        if self.buf[len - 1] == delim {
                            self.buf.truncate(len - 1);
                        }
                        break;
                    }
                }
            }

            let elem = unsafe { str::from_utf8_unchecked(&self.buf) };
            elem.parse().unwrap_or_else(|_| panic!(format!("failed parsing: {}", elem)))
         }
    }
}


fn main(){
    let stdin = stdin();
    let mut r = utils::StdinReader::new(stdin.lock());
    let n:usize = r.readl();
    let d:Vec<usize> = r.read_vec();
    let mut ans:usize = 0;
    for i in 0..n-1 {
        let b_i = d.get(i).unwrap();
        for j in i+1..n{
            ans += b_i * d.get(j).unwrap();
        }
    }
    println!("{}",ans);
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    
    string s, t, l;
    int r, b;
    
    cin >> s >> t >> r >> b >> l;
    if(s == l){
        r--;
    }else{
        b--;
    }
    
    cout << r << ' ' << b;
    
}


Measured memory_bytes: 256
N, K = map(int, input().split())
h = [0] * N 
for i in range(N):
    h[i] = int(input())

h.sort()

ans_list = []

for i in range(N-K+1):
    tmp = h[i+K-1] - h[i]
    ans_list.append(tmp)

ans = min(ans_list)
print(ans)


Measured memory_bytes: 11252
#include <iostream>
#include <vector>
#include <algorithm>
#include <utility>

using namespace std;

typedef long long ll;

int main(){
	vector<vector<pair<double, int> >> v(3, vector<pair<double, int> >(8));
	vector<pair<double, int> > u;
	for (int i = 0; i < 3; i++){
		for (int j = 0; j < 8; j++){
			cin >> v[i][j].second >> v[i][j].first;
		}
		sort(v[i].begin(), v[i].end());
		cout << v[i][0].second << " " << v[i][0].first << endl;
		cout << v[i][1].second << " " << v[i][1].first << endl;
		for (int j = 2; j < 8; j++){
			u.push_back(v[i][j]);
		}
	}
	sort(u.begin(), u.end());
	cout << u[0].second << " " << u[0].first << endl;
	cout << u[1].second << " " << u[1].first << endl;
}

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N, M, X, Y;
  cin >> N >> M >> X >> Y;
  int xm = -10000;
  int ym = 10000;
  bool war = true;
  REP(i, N) {
    int tmp;
    cin >> tmp;
    xm = max(xm, tmp);
  }
  REP(i, M) {
    int tmp;
    cin >> tmp;
    ym = min(ym, tmp);
  }
  for(int i = X + 1; i <= Y; i++) {
    if(xm < i && i <= ym) {
      war = false;
      break;
    }
  }
  if(war) {
    cout << "War" << endl;
  } else {
    cout << "No War" << endl;
  }
  return 0;
}

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

#define ll long long 
#define pb push_back
#define mp make_pair
#define F first
#define S second 
#define pl pair<long long ,long long >
#define pi pair<int ,int >
#define lb(v,x) lower_bound(v.begin(),v.end(),x)-v.begin()
#define ub(v,x) upper_bound(v.begin(),v.end(),x)-v.begin()
#define ct(i) cout<< i << "\n"
#define sv(v) sort(v.begin(),v.end())
#define mod 1000000007
#define M 100005
#define endl "\n"

int test=1;
void answer(){
    ll n,m=0,k,ans=0;
    cin>>n;
    string s;
    cin>>s;
    int l=0,r=n-1;
    while(l<r){
        if(s[r]=='W'){
            r--;
        }
        else if(s[l]=='R'){
            l++;
        }
        else{
            swap(s[l],s[r]);
            r--,l++;
            ans++;
        }
    }
    cout<<ans;
}

int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL); cout.tie(NULL);
    //freopen("test2.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    int q;
    //cin>>q; while(q--)
        answer();
    return 0;
}


Measured memory_bytes: 3720
/* created   : 2019-10-28 23:57:16
 * accepted  : 2019-10-29 00:16:18
 * author    : landcold7
 */
#include <bits/stdc++.h>
using namespace std;
#define x first
#define y second
#define mt make_tuple
#ifndef LOCAL
#define trace(...)
#endif
typedef long long ll;

vector<int> a;
vector<int> b;
int n;
ll k;

bool check(ll md) {
  ll cnt = 0;
  for (int i = 0; i < n; i++) {
    if ((ll) a[i] * b[i] > md) {
      cnt += a[i] - md / b[i];
    }
  }
  return cnt <= k;
}

void solve() {
  cin >> n >> k;
  a.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> a[i];
  }
  b.resize(n);
  for (int i = 0; i < n; i++) {
    cin >> b[i];
  }
  sort(a.begin(), a.end());
  sort(b.begin(), b.end(), greater<int>());
  ll mx = 0;
  for (int i = 0; i < n; i++) {
    mx = max(mx, (ll) a[i] * b[i]);
  }
  ll lo = 0;
  ll hi = mx;
  while (lo + 1 < hi) {
    ll md = lo + (hi - lo) / 2;
    if (check(md)) {
      hi = md;
    }
    else {
      lo = md;
    }
  }
  trace(lo, hi, check(lo));
  cout << (check(lo) ? lo : hi) << '\n';
}

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


Measured memory_bytes: 1792
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String str =sc.nextLine();
		int count = 0;

		for(int i = 0 ;i<str.length();i++){
			if(str.charAt(i)=='o'){
				count++;

			}

		}

		int check = 0;
		boolean lastcount =false ;
		check = 15 - str.length();

		if( check + count>=8){
			lastcount = true;
		}

		if(lastcount){
			System.out.println("YES");
		}else{
			System.out.println("NO");
		}

	}
}

Measured memory_bytes: 23252
#include<bits/stdc++.h>
using namespace std;
const int N=1e5+10;
typedef long long ll;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int n,m,id[N],st[N],top=0;
ll a[N],ans[N],k;
bool vis[N];
int main() {
	//freopen("rabbit.in","r",stdin);
	//freopen("rabbit.out","w",stdout);
    cin>>n;
    for(int i=1;i<=n;i++) a[i]=gi(),id[i]=i;
    for(int i=n;i;i--) a[i]-=a[i-1];
    cin>>m>>k;
    for(int i=1,x;i<=m;i++) x=gi(),swap(id[x],id[x+1]);
    for(int i=1;i<=n;i++)
        if(!vis[i]) {
            top=0;
            for(int j=i;!vis[j];j=id[j]) st[++top]=j,vis[j]=1;
            for(int j=1;j<=top;j++) ans[st[j]]=a[st[(k+j-1)%top+1]];
        }
    for(int i=1;i<=n;i++) ans[i]+=ans[i-1],printf("%lld\n",ans[i]);
    return 0;
}

Measured memory_bytes: 3712
import java.util.stream.IntStream;
import java.io.*;
import java.util.*;

public class Main {

    public static void main(String[] args) {
        FastScanner sc = new FastScanner();
        PrintWriter out = new PrintWriter(System.out);

        final int A = sc.nextInt();
        final int B = sc.nextInt();
        final int K = sc.nextInt();
        int cnt = 0;
        int ans = 0;
        
        for (int i = Math.max(A, B); i > 0; i--) {
            if (A % i == 0 && B % i == 0) cnt++;
            if (cnt == K) {
                ans = i;
                break;
            }
        }
        
        out.println(ans);

        out.flush();
    }
}

// https://qiita.com/p_shiki37/items/a0f6aac33bf60f5f65e4
class FastScanner {

    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;

    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        } else {
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }

    private int readByte() {
        if (hasNextByte()) {
            return buffer[ptr++];
        } else {
            return -1;
        }
    }

    private static boolean isPrintableChar(int c) {
        return 33 <= c && c <= 126;
    }

    public boolean hasNext() {
        while (hasNextByte() && !isPrintableChar(buffer[ptr])) {
            ptr++;
        }
        return hasNextByte();
    }

    public String next() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while (isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }

    public long nextLong() {
        if (!hasNext()) {
            throw new NoSuchElementException();
        }
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while (true) {
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            } else if (b == -1 || !isPrintableChar(b)) {
                return minus ? -n : n;
            } else {
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }

    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) {
            throw new NumberFormatException();
        }
        return (int) nl;
    }

    public double nextDouble() {
        return Double.parseDouble(next());
    }
}

Measured memory_bytes: 22356
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce
#from fractions import gcd
#from math import gcd
import sys
def I(): return int(input())
def Is(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def TI(): return tuple(map(int, input().split()))
def IR(n): return [I() for _ in range(n)]
def LIR(n): return [LI() for _ in range(n)]
def TIR(n): return [TI() for _ in range(n)]
def S(): return input()
def Ss(): return input().split()
def LS(): return list(input())
def SR(n): return [S() for _ in range(n)]
def SsR(n): return [Ss() for _ in range(n)]
def LSR(n): return [LS() for _ in range(n)]
sys.setrecursionlimit(10**6)
MOD = 10**9+7
INF = float('inf')



n = I()
s = S()

if n % 2 == 1:
    print("No")
    exit()

if s[:int(n/2)] == s[int(n/2):]:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 38256
S = input()
if S == "MON":
    print(6)
elif S == "TUE":
    print(5)
elif S == "WED":
    print(4)
elif S == "THU":
    print(3)
elif S == "FRI":
    print(2)
elif S == "SAT":
    print(1)
else :
    print(7)

Measured memory_bytes: 2940
//memory test

#include <iostream>
#include <algorithm>

using namespace std;

typedef long long ll;

struct seg
{
	ll l, r, d;
	inline int operator<(const seg &a) const {return d > a.d;}
} s[10010];

const ll inf = (1ll<<62) - 1;
int n, m;
ll f[3510][3510][2];

int main()
{
	ios::sync_with_stdio(0);
	
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> s[i].l >> s[i].r;
		s[i].d = s[i].l + s[i].r;
	}
	sort(s+1, s+n+1);
	m = n >> 1;
	for (int i = 0; i <= m; ++i)
		for (int j = 0; j <= m; ++j)
			f[i][j][0] = f[i][j][1] = inf;
	f[0][0][0] = 0;
	
	for (int i = 0; i <= m; ++i)
		for (int j = 0; j <= m && i+j < n; ++j)
			for (int k = 0; k <= 1 && i+j+k < n; ++k)
			{
				const ll tmp = f[i][j][k]; const seg p = s[i+j+k+1];
				if (i < m)	f[i+1][j][k] = min(f[i+1][j][k], tmp + p.r + i*p.d);
				if (j < m)	f[i][j+1][k] = min(f[i][j+1][k], tmp + p.l + j*p.d);
				if (!k)		f[i][j][k|1] = min(f[i][j][k|1], tmp + m * p.d);
			}
	
	cout << f[m][m][n&1] << endl;
	
	return 0;
}

Measured memory_bytes: 139264
#include <iostream>
#include <vector>

using namespace std;

#define rep(i, n) for (int i = 0; i < n; i++)
#define vec vector
#define ll long long

int n, m;
ll k;
vec<ll> x;
vec<int> a;
vec<int> keep;

vec<int> mul(ll time, vec<int> go)
{
	if (time == 1) return go;
	vec<int> ret(n - 1);
	go = mul(time / 2, go);
	rep(i, n - 1) {
		ret[i] = go[go[i]];
		if (time % 2) ret[i] = keep[ret[i]];
	}
	return ret;
}
	

int main(void)
{
	cin >> n;
	x.resize(n);
	rep(i, n) cin >> x[i];
	cin >> m >> k;
	a.resize(m);
	rep(i, m) cin >> a[i];
	rep(i, m) a[i]--;

	vec<ll> aida(n - 1);
	rep(i, n - 1) {
		aida[i] = x[i + 1] - x[i];
	}

	vec<int> go(n - 1);
	rep(i, n - 1) go[i] = i;
	rep(i, m) {
	   int temp = go[a[i]];
	   go[a[i]] = go[a[i] - 1];
	   go[a[i] - 1] = temp;
	}
	keep = go;
	go = mul(k, go);

	cout << x[0] << endl;
	rep(i, n - 1) {
		x[i + 1] = x[i] + aida[go[i]];
		cout << x[i + 1] << endl;
	}
	return 0;
}

Measured memory_bytes: 49664
#include<stdio.h> 

int main(void) { 

int a,b,c,B,C;  

scanf("%d %d %d",&a,&b,&c); 

if(a>b){  B=b;  b=a;  a=B; } 

if(a>c){  C=c;  c=a;  a=C; } 

if(b>c){  C=c;  c=b;  b=C; }  

printf("%d %d %d\n",a,b,c); 

 return 0; 

}

Measured memory_bytes: 596
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;

int main(int argc, const char * argv[]) {
    int n, a;
    cin >> n >> a;
    
    n = n - (n / 500) * 500;
    
    if (n <= a) {
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(void){
    // Your code here!
    int x,y,z;
    cin>>x>>y>>z;
    if(x>y){
        swap(x,y);
    }
    if(y>z){
        swap(y,z);
    }
    if(x>y){
        swap(x,y);
    }
    cout<<x<<" "<<y<<" "<<z<<endl;
}




Measured memory_bytes: 3096
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <climits>
#include <cassert>
#include <iostream>
#include <iomanip>
#include <sstream>
#include <algorithm>
#include <numeric>
#include <complex>
#include <stack>
#include <queue>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <functional>
#include <iterator>

using namespace std;

#define dump(n) cout<<"# "<<#n<<'='<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define peri(i,a,b) for(int i=int(b);i-->int(a);)
#define rep(i,n) repi(i,0,n)
#define per(i,n) peri(i,0,n)
#define iter(c) __typeof__((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<string> vs;
typedef pair<int,int> pii;

const int INFTY=1<<29;
const double EPS=1e-9;

template<typename T1,typename T2>
ostream& operator<<(ostream& os,const pair<T1,T2>& p){
	return os<<'('<<p.first<<','<<p.second<<')';
}
template<typename T>
ostream& operator<<(ostream& os,const vector<T>& a){
	os<<'[';
	rep(i,a.size()) os<<(i?" ":"")<<a[i];
	return os<<']';
}

int main()
{
	vi isp(2000,1); isp[0]=isp[1]=0;
	for(int i=2;i*i<isp.size();i++)
		if(isp[i])
			for(int j=i*i;j<isp.size();j+=i)
				isp[j]=0;
	vi ps;
	rep(i,isp.size()) if(isp[i])
		ps.push_back(i);
	
	for(int n,k;cin>>n>>k,n|k;){
		vvi dp(k+1,vi(n+1));
		dp[0][0]=1;
		for(int p:ps){
			per(i,k) rep(j,n){
				if(j+p>n) break;
				dp[i+1][j+p]+=dp[i][j];
			}
		}
		cout<<dp[k][n]<<endl;
	}
	
	return 0;
}

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

using namespace std;


int main() {
    string S;
    cin >> S;
    auto sample = "CODEFESTIVAL2016";

    int ans = 0;
    for (int i = 0; i < S.size(); ++i) {
        if (S[i] != sample[i]) ans++;
    }

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

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

//最大公約数
ll gcd(ll a,ll b) {
  if (b == 0){
    return a;
  }
  return gcd(b, a % b);
}

//最小公倍数
ll lcm(ll a, ll b) {
  return a * b / gcd(a, b);
}

map<ll,ll> prime_factor(ll n){
  map<ll,ll> res;
  for (ll i(2);i*i<=n;i++){
    while(n%i==0){
      ++res[i];
      n/=i;
    }
  }
  if (n!=1) res[n]=1;
  return res;
}

int main(){
  ll a,b;
  cin>>a>>b;
	ll x = gcd(a,b);
	ll cnt(1);
	map<ll,ll> s = prime_factor(x);
	for (auto e: s) {
  //  cout << e.first << " " << e.second << endl;
    bool flag = false;
    while(x%e.first == 0){
      flag = true;
      x/=e.first;
    }
    if (flag) cnt++;
  }
  cout << cnt << endl;
}



Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <vector>
using namespace std;
using ll = int64_t;
#define rep(i, j, n) for (int i = j; i < (int)n; ++i)

ll dp[3003][3003][4];
ll gs[3003][3003];
int main() {
  int r, c, k, y, x, v;
  cin >> r >> c >> k;

  rep(i, 0, k) {
    cin >> y >> x >> v;
    --y, --x;
    gs[y][x] = v;
  }

  rep(i, 0, r) rep(j, 0, c) rep(a, 0, 4) {
    if (a + 1 < 4) {
      dp[i][j + 1][a + 1] = max(dp[i][j + 1][a + 1], dp[i][j][a] + gs[i][j]);
      dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][a] + gs[i][j]);
    }
    dp[i][j + 1][a] = max(dp[i][j + 1][a], dp[i][j][a]);
    dp[i + 1][j][0] = max(dp[i + 1][j][0], dp[i][j][a]);
  }

  ll ans = 0;
  rep(a, 0, 4) {
    ans = max(ans, dp[r][c - 1][a]);
    ans = max(ans, dp[r - 1][c][a]);
  }
  cout << ans << '\n';

  return 0;
}

Measured memory_bytes: 355380
A, B, C, D = map(int, input().split())

if B <= C or A >= D:
    print('0')
    exit()
elif B <= D:
    if A >= C:
        print('{}'.format(B-A))
        exit()
    else:
        print('{}'.format(B-C))
        exit()
else:
    if A >= C:
        print('{}'.format(D-A))
        exit()
    else:
        print('{}'.format(D-C))
        exit()

Measured memory_bytes: 3064
#include<stdio.h>

int main(){
	int a,b,c;
	int cnt=0;
	scanf("%d %d %d",&a,&b,&c);
	if(a==b){
		cnt=cnt+1;
	}
	if(b==c){
		cnt=cnt+1;
	}
	if(a==c){
		cnt=cnt+1;
	}
	if(cnt==3){
		printf("%d\n",1);
	}
	else{
		printf("%d\n",3-cnt);
	}
	return 0;
}

Measured memory_bytes: 128
N = int(input())
X = []
Y = []
sum=0
#距離の和を計算
for _ in range(N):
  x,y=map(int,input().split())
  for i, [x_,y_] in enumerate(zip(X,Y)):
    sum+=((x-x_)**2+(y-y_)**2)**(0.5)
  X.append(x)
  Y.append(y)

print(sum*2/N)

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

#define rep(i,z) for(int i = 0; i<(int)(z); i++)
#define rep1(i,z) for(int i = 1; i<=(int)(z); i++)
 
using namespace std;

typedef long long ll;
const ll MOD=1e9+7;
using pear = pair<int,int>;

int main(){
    int n; cin>>n;
    vector<int> ans(n);
    rep(i,n-1){
        int now; cin>>now; now--;
        ans[now]++;
    }
    rep(i,n) cout<<ans[i]<<endl;
}


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

typedef long long ll;
#define rep(i,x) for(int i=0;i<x;i++)
#define put(ans)    cout << ans << endl;

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

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

    return 0;
}

Measured memory_bytes: 3568
#include <bits/stdc++.h>
#define IO             freopen (task".inp", "r", stdin), freopen (task".out", "w", stdout)
#define FORR(i, a, b)  for (int i = (a), _b = (b); i <= _b; i++)
#define FORD(i, a, b)  for (int i = (b), _a = (a); i >= _a; i--)
#define REPP(i, a, b)  for (int i = (a); _b = (b); i < _b; ++i)
#define REPD(i, a, b)  for (int i = (b); _a = (a); i > _a; --i)
#define mem(a, x)      memset(x, (a), sizeof(x))
#define cmin(a, b)     if ((a) > (b)) (a) = (b)
#define cmax(a, b)     if ((a) < (b)) (a) = (b)
#define reset(x)       memset(x, 0, sizeof(x))
#define bitcount(x)    __builtin_popcountll((x))
#define all(a)         (a).begin(), (a).end()
#define debug(x)       cout << (x) << "\n"
#define BIT(x, i)      (((x) >> (i)) & 1)
#define sz(a)          ((int) (a).size())
#define ii             pair<int, int>
#define MASK(i)        (1LL << (i))
#define pf             push_front
#define mp             make_pair
#define pb             push_back
#define se             second
#define fi             first
#define task           ""

using namespace std;

const int MOD = 1000000007;
const int inf = 2000000000;
const int mod = 1007050321;
const int base = 521;
const int N = 200005;

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

    int a;
    cin >> a;
    cout << a + a * a + a * a * a;
    return 0;
}


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


int main(){
  vector<int> a(5);
  int k;
  string s = "Yay!";
  for(int i=0;i<5;++i)
    cin >> a.at(i);
  cin >> k;
  for(int i=0;i<5;++i){
    for(int j=i+1;j<5;++j){
      if(abs(a.at(i)-a.at(j))>k){
        s = ":(";
        break;
      }
    }
    if(s==":(")
      break;
  }
  cout << s;
}


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

using namespace std;

int main(){
        int n,m,x,y;
        int X[110],Y[110];

        cin>>n>>m>>x>>y;

        for(int i=0; i<n; ++i)cin>>X[i];
        for(int i=0; i<m; ++i)cin>>Y[i];

        sort(X,X+n);
        sort(Y,Y+m);

        int xmax=max(X[n-1],x),ymin=min(Y[0],y);

        if(xmax<ymin)cout<<"No War"<<endl;
        else cout<<"War"<<endl;

        return 0;
}

Measured memory_bytes: 256
import sys
from bisect import *
from heapq import *
from collections import *
from itertools import *
from functools import *

sys.setrecursionlimit(100000000)


def input(): return sys.stdin.readline().rstrip()


N = int(input())


def f(x):
    ans = set()
    i = 1
    while i * i <= x:
        if x % i == 0:
            ans.add(i)
        i += 1
    for i in ans.copy():
        ans.add(x // i)
    return ans

ans = set()
for K in f(N) | f(N - 1):
    if K == 1:
        continue
    n = N
    while n % K == 0:
        n //= K
    if n % K == 1:
        ans.add(K)

print(len(ans))


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

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

   char s = S.at(0); 
  
  if (s == 'a'||s == 'i'||s == 'u'||s == 'e'|| s == 'o') {
    cout << "vowel" << endl;
  }
    else cout << "consonant" << endl;
}
    

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
  int x,y,a,b;
  cin>>x>>y>>a>>b;
  int s=a-x;
  int t=b-y;
  int c=a-t;
  int d=b+s;
  int e=c-s;
  int f=d-t;
  cout<<c<<' '<<d<<' '<<e<<' '<<f;
}

Measured memory_bytes: 3620
#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 fi first
#define se second
#define mp make_pair
#define pb push_back
 
typedef long long ll;
typedef pair<int,int> ii;
typedef vector<int> vi;
typedef long double ld; 
typedef tree<ii, null_type, less<ii>, rb_tree_tag, tree_order_statistics_node_update> pbds;


int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0);
	vi c(4,0);
	for(int i=0;i<3;i++)
	{
		int x,y; cin>>x>>y; x--; y--;
		c[x]++; c[y]++;
	}
	sort(c.begin(),c.end());
	if(c[0]==1&&c[1]==1&&c[2]==2&&c[3]==2){cout<<"YES\n";}
	else cout<<"NO\n";
}



Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int sz=1e5+5;
#define ll long long
int n;
ll a[sz],ans,dis[sz];
ll z(ll v){
	return v>0?v:-v;
}
int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++)scanf("%lld",&a[i]),dis[i]=z(a[i]-a[i-1]),ans+=dis[i];
	dis[n+1]=z(a[n]);
	ans+=dis[n+1];
	for(int i=1;i<=n;i++){
		printf("%lld\n",ans-dis[i]-dis[i+1]+z(a[i+1]-a[i-1]));
	}
	return 0;
}

Measured memory_bytes: 2816
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		int n, ans;
		List<Integer> heights = new ArrayList<>();
		
		Scanner scanner = new Scanner(System.in);
		
		n = scanner.nextInt();
		
		for (int i = 0; i < n; i++) {
			heights.add(scanner.nextInt()); 
		}
		scanner.close();
		
		int nW, nS = 0;
		boolean higher = true;
		ans = 1;
		
		for (int j = n - 1; 1 <= j; j--) {
			nS = heights.get(j);
			
			for (int k = 0; k <= j -1; k++) {
				if (higher) {
					nW = heights.get(k);
					if (nW > nS) {
						higher = false;
					}
				}
			}
			if (higher) {
				ans++;
			}
			higher = true;
		}
		System.out.println(ans);
		
	}
}


Measured memory_bytes: 23124
#include <algorithm>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
vector<pii>a[100004];
int ans[100004];
int main(){
    int n,m;
    cin >> n >> m;
    vector<int>p(m),y(m);
    rep(i,m){
        cin >> p[i] >> y[i];
        a[p[i]].push_back(pii(y[i],i));
    }
    rep(i,n){
        sort(a[i+1].begin(),a[i+1].end());
    }
    rep(i,n){
        rep(j,a[i+1].size()){
            ans[a[i+1][j].second] = j+1;
        }
    }
    rep(i,m){
        string s;
        s = to_string(p[i]);
        s = "0000000000"+s;
        for(int j = s.size()-6;j < s.size() ; j++){
            cout << s[j];
        }
        s = to_string(ans[i]);
        s = "0000000000"+s;
        for(int j = s.size()-6;j < s.size() ; j++){
            cout << s[j];
        }
        cout << endl;
    }
}

Measured memory_bytes: 8192
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author Sagor
 */

#include <fstream>

#include <iostream>
#include <cstring>
#include <cmath>
#include <algorithm>
        using namespace std;

        class p{
                public:
                void solve(std::istream& in, std::ostream& out) {
                    string s;
                    in>>s;
                    int l = s.size(),c=0;
                    for(int i = 0;i<l/2;i++)
                    {
                        if(s[i]!=s[l-i-1])
                            c++;
                    }
                    out<<c<<endl;

                }
        };

int main() {
    std::ios_base::sync_with_stdio(0);
    std::cin.tie(0);
	p solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

const LL mod = 1000000007;

int main()
{
	LL N;
	in >> N;
	std::vector<LL>C(N);
	rep(i, N) in >> C[i];

	std::vector<LL>dp(N), memo(212345);
	dp[0] = 1; memo[C[0]] = 1;
	for (LL i = 1; i < N; ++i)
	{
		if (C[i] == C[i - 1]) dp[i] = dp[i - 1];
		else
		{
			dp[i] = (dp[i - 1] + memo[C[i]]) % mod;
			(memo[C[i]] += dp[i - 1]) %= mod;
		}
	}
	out << dp[N - 1] << std::endl;
}


Measured memory_bytes: 5120
def burst(S):
    S += "_" #dummyを追加
    st,sp,ep = S[0],0,0
    S0,S1 = [],[]
    for i in range(1,len(S)):
        if st == S[i]:
            ep += 1
        else:
            if st == "0":
                S0.append((sp,ep))
            else:
                S1.append((sp,ep))
            st,sp,ep = S[i],i,i

    return [S0,S1]

def connect(S0,S1,K,len_S):
    if len(S0) == 0 or len(S1) == 0:
        return len_S
    else:
        if S1[0][0] != 0:
            S1 = [(0,0)] + S1
        if S1[len(S1)-1][1] != len_S-1:
            S1.append((len_S-1,len_S-1))
        if len(S1)-1 <= K:
            return len_S
        else:
            output = 0
            for i in range(len(S1)-K):
                output = max(output,S1[i+K][1]-S1[i][0]+1)
            return output

def main():
    N,K = map(int,input().split())
    S = input()

    T = burst(S)
    S0,S1 = T[0],T[1]
    print(connect(S0,S1,K,N))

if __name__ == "__main__":
    main()


Measured memory_bytes: 13912
/******************************************************************************

                              Online C++ Compiler.
               Code, Compile, Run and Debug C++ program online.
Write your code in this editor and press "Run" button to compile and execute it.

*******************************************************************************/

#include <iostream>
#include <cstring>
using namespace std;

int main()
{
   char a[255], b[255] , u[255];
   int x , y;
   cin>>a;
for(int i=0; i < strlen(a); ++i)
{
    a[i]='x';
}
cout<<a;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
int main(void){
    // Here your code !
    int a,b,c,d;
    scanf("%d %d %d %d",&a,&b,&c,&d);
    int s = a*b;
    int t = c*d;
    if(s>t){
        printf("%d\n",s);
    }
    else {
        printf("%d\n",t);
    }
    return 0;
    
}


Measured memory_bytes: 128
s = int(input())
if s <= 10 ** 9:
    print(0, 0, s, 0, s, 1)
else:
    a = s // (10 ** 9)
    b = s % (10 ** 9)
    if b == 0:
        print(0, 0, 10 ** 9, 1, 0, a)
    else:
        print(0, 0, 10 ** 9, 1, 10 ** 9 - b, a + 1)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int main() {
    int N, Q;
    cin >> N >> Q;
    vector<queue<int> > edges(N+1);
    for (int i = 0; i < N-1; i++) {
        int a, b;
        cin >> a >> b;
        edges[a].push(b);
        edges[b].push(a);
    }
    vector<int> counter(N+1, 0);
    for (int i = 0; i < Q; i++) {
        int p, x;
        cin >> p >> x;
        counter[p] += x;
    }
    queue<int> current;
    current.push(1);
    vector<int> distances(N+1, -1);
    distances[1] = counter[1];
    while (!current.empty()) {
        int a = current.front();
        while(!edges[a].empty()) {
            int b = edges[a].front();
            if (distances[b] == -1) {
                distances[b] = distances[a]+counter[b];
                current.push(b);
            }
            edges[a].pop();
        }
        current.pop();
    }
    for (int i = 1; i < N+1; i++) {
        printf("%d\n", distances[i]);
    }
    return 0;
}

Measured memory_bytes: 139008
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc =new Scanner(System.in);
    String S =sc.next();
    String T =sc.next();
    int A =sc.nextInt();
    int B =sc.nextInt();
    String U =sc.next();
    if(U.equals(S)){System.out.println((A-1) +" "+B);}
    else{System.out.println(A +" "+ (B-1));}
  }
}

Measured memory_bytes: 38556
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int n = Integer.parseInt(sc.next());
    long ans = 0;
    String str = "";
    char[] ch = new char[10];
    Map<String, Integer> map = new HashMap<>();
    for(int i = 0; i < n; i++) {
      str = sc.next();
      for(int j = 0; j < 10; j++) {
        ch[j] = str.charAt(j);
      }
      Arrays.sort(ch);
      str = String.valueOf(ch);
      if(map.containsKey(str)) {
        map.put(str, map.get(str) + 1);
      } else {
        map.put(str, 1);
      }
    }
    long num;
    for(String temp : map.keySet()) {
      num = map.get(temp);
      ans += num * (num - 1) / 2;
    }
    System.out.println(ans);
  }
}


Measured memory_bytes: 54132