akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string.h>

void strrev(char* s)
{
    int len;
    int i;
    len = strlen(s);
    for (i = 0; i < len / 2; i++) {
        char tmp = s[len - i - 1];
        s[len - i - 1] = s[i];
        s[i] = tmp;
    }
}

int c2i(char c)
{
    int result = 0;
    if ('0' <= c && c <= '9') {
        result = c - '0';
    }
    return result;
}

int main(void)
{
    int N; // count of data sets
    int i, j; // used for 'for'
    int carry; // carryover
    char a[101]; // first input
    char b[101]; // second input
    char ans[101];
    int a_len, b_len, max_len; // string lengths

    scanf("%d%*c", &N);

    for (i = 0; i < N; i++) {
        // initialize arrays;
        carry = 0;
        for (j = 0; j < 101; j++) {
            a[j] = b[j] = ans[j] = 0;
        }

        scanf("%s%*c", a);
        scanf("%s%*c", b);

        a_len = strlen(a);
        b_len = strlen(b);
        max_len = a_len > b_len ? a_len : b_len;

        strrev(a);
        strrev(b);

        for (j = 0; j < max_len; j++) {
            int tmp = c2i(a[j]) + c2i(b[j]) + carry;
            carry = tmp >= 10 ? 1 : 0;
            tmp %= 10;
            ans[j] = tmp + '0';
        }
        if (carry == 1) {
            ans[j++] = '1';
        }
        ans[j] = '\0';

        strrev(ans);
        if (strlen(ans) > 80) {
            strcpy(ans, "overflow");
        }
        printf("%s\n", ans);
    }
    return (0);
}

Measured memory_bytes: 588
origin = [ "", "KIH", "", "B", "", "R", "" ]

candidate = []
for i in range(2**4):
    temp = [ j for j in origin ]
    bit = bin(i)[2:].zfill(4)
    for j, v in enumerate(bit):
        if v == "1":
            temp[2*j] = "A"
    candidate.append("".join(temp))

s = input()
print( "YES" if s in candidate else "NO" )

Measured memory_bytes: 38256
#include <stdio.h>
int cmpfunc (const void * a, const void * b) {
   return ( *(long long int*)a - *(long long int*)b );
}
int main()
{
    long long int test,n,i,j,sum1,k,m,a,flag=0,count=0,b,c[10]={6,2,5,5,4,5,6,3,7,6},a1[3]={0},b2;
  scanf("%lld%lld",&a,&b);
  a1[0]=a+b;
  a1[1]=a-b;
  a1[2]=a*b;
  qsort(a1,3,sizeof(long long int),cmpfunc);
  printf("%lld",a1[2]);
    return 0;
}




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

int main()
{
    int x;
    cin>>x;
    for(int i=1;i<=9;i++)
    {
        for(int j=1;j<=9;j++)
        {
            if(x==i*j)
            {
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
    return 0;
}

Measured memory_bytes: 3592
N, M = map(int, input().split())
import collections
henn = collections.defaultdict(list)

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

start_points = [1]
sirushi = {1: 0}

while len(sirushi.keys()) < N:
    next_points = []
    for start_point in start_points:
        for next_point in henn[start_point]:
            if next_point not in sirushi:
                sirushi[next_point] = start_point
                next_points.append(next_point)
    start_points = next_points

print('Yes')
for i in range(2, N+1):
    print(sirushi[i])

Measured memory_bytes: 120208
#include<bits/stdc++.h>
using namespace std;
using ll = int64_t;
int main(){
    ll N, M;
    cin >> N >> M;
    pair<ll, ll> a[M];
    for(ll i = 0; i < M; i++) cin >> a[i].first >> a[i].second;
    sort(a, a + M, [&](auto x, auto y){return x.second < y.second;});
    ll ans = 0, bridge = -1;
    for(ll i = 0; i < M; i++){
        if(a[i].first < bridge && bridge <= a[i].second) continue;
        ans++;
        bridge = a[i].second;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
	long long x, k, d;
    cin >> x >> k >> d;
    x = abs(x);
    if(k <= x/d) {
      cout << x - k * d << endl;
      return 0;
    }
  	k = k - x/d;
  	x = x - d * (x/d);
  	if(k % 2 == 0){
    	cout << x << endl;
    } else {
      	cout << abs(x - d) << endl;
    }
    
	return 0;
}

Measured memory_bytes: 3164
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <math.h>

typedef long long ll;
using namespace std;

ll DENOM = 1000000007L;

ll fib(int n){
    if(n < 1) return 1;
    vector<ll> res(n+1, 1);
    for(int i=3; i<n+1; ++i){
        res[i] = res[i-1] + res[i-2];
        res[i] = res[i] % DENOM;
    }
    return res[n];
}

int main() {
    int n, m;
    cin >> n >> m;
    if (m==0){
        cout << fib(n+1) << endl;
        return 0;
    }
    vector<int> a(m);
    for(int& aa : a){cin >> aa;}
    int pt = 0;
    ll score = 1;
    score *= fib(a[0] - pt);
    pt = a[0];
    score %= DENOM;
    for(int i=1; i<m; ++i){
        int stp = a[i] - pt;
        if(stp == 1){
            score = 0;
            break;
        }
        score *= (fib(stp-1));
        score %= DENOM;
        pt = a[i];
    }
    score *= (fib(n - pt));
    cout << score%DENOM << endl;
    return 0;
}


Measured memory_bytes: 1408
macro_rules! read {
	() => {{
		let mut buf = String::new();
		std::io::stdin().read_line(&mut buf).unwrap();
		buf
	}};
	( Vec<$t:ty> ) => {
		read!()
			.trim()
			.split_whitespace()
			.map(|x| x.parse::<$t>().unwrap())
			.collect::<Vec<_>>()
	};
	( $( $t:ty ),* ) => {{
		let buf = read!();
		let mut iter = buf.split_whitespace().collect::<Vec<_>>().into_iter();
		( $( iter.next().unwrap().parse::<$t>().unwrap() ),* )
	}};
}

fn main() {
    let (n, _) = read!(i32, i32);
    let a_sum = read!(Vec<i32>).iter().fold(0, |a, b| a + b);
    println!("{}", if n >= a_sum { n - a_sum } else { -1 })
}


Measured memory_bytes: 2216
import heapq
from sys import stdin

def read_graph(n):
    A = [ [] for _ in range(n) ]
    while True:
        try:
            line = stdin.readline().strip().split()
            u = line[0]
            v = line[1]
            w = line[2]
            A[int(u)].append((int(v), int(w)))
            A[int(v)].append((int(u), int(w)))
        except:
            break
    return A

def dijkstra(n, A, s):
    color = [ 'WHITE' for i in range(n) ]
    d = [ float('inf') for i in range(n) ]
    d[s] = 0
    pq = []

    heapq.heappush(pq, (0, s))

    while pq:
        costu, u = heapq.heappop(pq)
        color[u] = 'BLACK'

        if d[u] < costu:
            continue

        for v, costv in A[u]:
            if color[v] != 'BLACK':
                if d[u] + costv < d[v]:
                    d[v] = d[u] + costv
                    color[v] = 'GRAY'
                    heapq.heappush(pq, (d[v], v))
    return d

n = int(input())
A = read_graph(n)
a = dijkstra(n, A, 0)
b = dijkstra(n, A, a.index(max(a)))
print(max(b))


Measured memory_bytes: 50152
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<algorithm>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#include<cmath>



#define REP(i,n) for (int i = 0; (i) < (n); ++ (i))

using namespace std;
int n;
char c;

int main(){
  cin >> n;
  string ans = "Three";
  REP(i,n){
    cin >> c;
    if(c=='Y') ans = "Four";
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>
 
using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;
 
 
template<class T> inline bool chmin(T& a, T b) {
	if (a > b) {
		a = b;
		return true;
	}
	return false;
}
template<class T> inline bool chmax(T& a, T b) {
	if (a < b) {
		a = b;
		return true;
	}
	return false;
}
 
//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
 
void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

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

	ll n;
	cin>>n;
	vector<P> ab(n);
	REP(i,n) cin>>ab[i].first>>ab[i].second;

	sort(all(ab),[&](P x, P y){
		if(x.first+x.second==y.first+y.second) return x.first > y.first;
		else return x.first+x.second > y.first+y.second;
	});

	ll sum_a=0;
	ll sum_b=0;
	bool flag=true;
	REP(i,n){
		if(flag){
			sum_a+=ab[i].first;
			flag=false;
		}else{
			sum_b+=ab[i].second;
			flag=true;
		}
	}

	cout<<sum_a-sum_b<<endl;
	return 0;
}

Measured memory_bytes: 1792
from math import sqrt,ceil,gcd
def ii():return int(input())
def si():return input()
def mi():return map(int,input().split())
def li():return list(mi())


# for _ in range(ii()):

x=[599,799,999,1199,1399,1599,1799,1999]

n=ii()
for i in range(8):
    if n<=x[i]:
        print(8-i)
        break

Measured memory_bytes: 62120
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<complex>
using namespace std;
typedef long long ll;
typedef unsigned int ui;
const ll MOD = 1000000007;
const ll INF = (ll)1000000007 * 1000000007;
const double EPS = 1e-9;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef long double ld;
typedef complex<ld> Point;
const ld eps = 1e-11;
const ld pi = acos(-1.0);
typedef pair<ll, ll> LP;
typedef pair<ld, ld> LDP;
int main() {
	int n; cin >> n;
	char m[500][500] = {};
	bool f = true;
	rep(i, n) {
		rep(j, n) {
			cin >> m[i][j];
			if (m[i][j] == '#')f = false;
		}
	}
	if (f)cout << -1 << endl;
	else {
		int cnt = 0;
		rep(j, n) {
			f = true;
			rep(i, n) {
				if (m[i][j] == '.')f = false;
			}
			if (f)cnt++;
		}
		int mi = 1000;
		rep(i, n) {
			int sum = 0;
			rep(j, n) {
				if (m[i][j] == '#')sum++;
			}
			if (sum == n)mi = 0;
			else {
				f = true;
				rep(j, n) {
					if (m[j][i] == '#')f = false;
				}
				if (f)sum--;
				mi = min(mi, n - sum);
			}
		}
		cout << mi + n - cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 512
N = int(input())
A = list(map(int, input().split()))

B = [0] * N
for _ in range(N-1, -1, -1):
    if A[_] == 1:
        if sum(B[_::_+1]) % 2 == 0:
            B[_] = 1
    else:
        if sum(B[_::_+1]) % 2 == 1:
            B[_] = 1
print(sum(B))
for i, _ in enumerate(B):
    if _ == 1:
        print(i+1)

Measured memory_bytes: 8384
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<math.h>
using namespace std;
int main() {
	int N, K;	cin >> N >> K;
	vector<int> x(N);
	int answer = 0;
	for (int i = 0; i < N; ++i) {
		cin >> x[i];
	}

	for (int i = 1; i <= N; ++i) {
		if (x[i - 1] <= K - x[i - 1]) {
			answer += 2 * x[i - 1];
		}
		else {
			answer += 2 * (K - x[i - 1]);
		}
	}
	cout << answer << endl;
	cin >> N;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <cmath>
#include <string>
#include <vector>
#include <utility>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <numeric>
#include <array>
#include <float.h>
#include <memory>
#include <functional>
#include <iomanip>
#include <random>
#include <map>
#include <set>

using namespace std;


using ULL = decltype(0ull);
constexpr auto DIV = 1000000007ull;
constexpr auto MAX = numeric_limits<ULL>::max();


int main() {
  int x;
  cin >> x;
  if (x < 1200) {
    cout << "ABC" << endl;
  }
  else {
    cout << "ARC" << endl;
  }
  return 0;
}

Measured memory_bytes: 256
N, MOD = int(input()), 10 ** 9 + 7
dp = [[[[0 for k in range(4)] for k in range(4)] for j in range(4)] for i in range(101)]
' 長さ0の文字列は1である。        '
' 0,1,2に関する制約しかないので、 '
' Sは、333Sと考えても問題がない。 '
dp[0][3][3][3] = 1

for length in range(N):
  for c1 in range(4):
    for c2 in range(4):
      for c3 in range(4):
        if dp[length][c1][c2][c3] == 0: continue
        for c4 in range(4):
          ' ダメな5つの条件をカットする'
          if   True  and c2 == 0 and c3 == 1 and c4 == 2: continue
          if   True  and c2 == 1 and c3 == 0 and c4 == 2: continue
          if   True  and c2 == 0 and c3 == 2 and c4 == 1: continue
          if c1 == 0 and c2 == 1 and   True  and c4 == 2: continue
          if c1 == 0 and   True  and c3 == 1 and c4 == 2: continue

          ' ダメな条件を抜けたら、c4を足した文字列が作れる '
          ' S     = ...... c1 c2 c3                        '
          ' nextS = ...... c2 c3 c4                        '
          dp[length + 1][c2][c3][c4] += dp[length][c1][c2][c3]
          dp[length + 1][c2][c3][c4] %= MOD

ans = 0
for c1 in range(4):
  for c2 in range(4):
    for c3 in range(4):
      ans += dp[N][c1][c2][c3]
      ans %= MOD

print(ans)


Measured memory_bytes: 3316
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>
 
using ll = long long;
using P = std::pair<char, ll>;
 
#define rep(i, a, b) for (ll(i) = (a); (i) < (b); (i)++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << #i <<" "<<i<<std::endl;
 
template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << pa.first << " " << pa.second;
}
 
template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  for (int i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
  return os;
}
 
template<typename T1,typename T2>
inline bool chmax(T1& a,T2 b){return a<b && (a=b,true);}
 
template<typename T1,typename T2>
inline bool chmin(T1& a,T2 b){return a>b && (a=b,true);}

//非再帰累乗(mod付き)
ll pow_mod(ll a, ll b, ll mod=-1) {
  if ((a == 0)||(mod!=-1&&a%mod==0)) {
    return 0;
  }

  ll x = 1;

  while (b > 0) {
    if (b & 1) {
      x = (mod!=-1)?(x * a) % mod:x*a;
    }
    a = (mod!=-1)?(a * a) % mod:a*a;
    b >>= 1;
  }
  return x;
}
 
// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;
 
int main() {
  std::cin.tie(0);
  std::ios::sync_with_stdio(false);

  ll n;
  std::cin>>n;

  std::vector<ll> lsec(n),rsec(n);

  rep(i,0,n){
    std::cin>>lsec[i]>>rsec[i];
  }

  std::sort(all(rsec));
  std::sort(all(lsec),std::greater<ll>());

  std::vector<ll> rsum(n+1,0),lsum(n+1,0);

  rep(i,0,n){
    rsum[i+1]=rsum[i]+rsec[i];
    lsum[i+1]=lsum[i]+lsec[i];
  }

  ll ans=0;

  rep(r,0,(n+3)/2){
    rep(l,std::max(r-1,0ll),r+2){
      if(r>=0&&l>=0&&r+l<=n){
        chmax(ans,2*lsum[l]-2*rsum[r]);
      }
    }
  }

  std::cout<<ans;

  return 0;
}





Measured memory_bytes: 3456
import java.util.Scanner;

//How can I satisfy thee? Let me count the ways...
public class Main{

	static char[] s;
	static int index;
	static int[] table;
	
	static char c(){
		return s[index++];
	}
	
	static int formura(){
		int r = term();
		while(index < s.length){
			char c = c();
			if(c=='*'){
				int p = term();
				r = Math.min(r, p);
			}
			else if(c=='+'){
				int p = term();
				r = Math.max(r, p);
			}
			else break;
		}
		return r;
	}
	
	static int term(){
		char c = c();
		if(c=='('){
			int r = formura();
			return r;
		}
		if(c=='-'){
			int r = term();
			return r==0?2:r==1?1:0;
		}
		if(Character.isDigit(c))return c-'0';
		return table[c-'P'];
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			String str = sc.next();
			if(str.equals("."))break;
			s = (str+"$").toCharArray();
			table = new int[3];
			int ans = 0;
			for(int i=0;i<3;i++){
				table[0]=i;
				for(int j=0;j<3;j++){
					table[1]=j;
					for(int k=0;k<3;k++){
						table[2]=k;
						index = 0;
						ans += formura()==2?1:0;
					}
				}
			}
			System.out.println(ans);
		}
	}
}

Measured memory_bytes: 12000
#include <iostream>
#include <map>
#include <algorithm>
#include <string>
#include <vector> 
#include <numeric>
#include <cmath>
#include <queue>
#include <iomanip>
#include <functional>


#define CHMAX(a,b) a = std::max(a,b)
#define CHMIN(a,b) a = std::min(a,b)
#define MAXMIN(a,b,c) std::max(a,min(b,c))
#define CHABS(a) a = std::abs(a) 
#define COUT(a) std::cout << a << std::endl
#define CERR(a) std::cerr << a << std::endl
#define FOR(n) for(lli i = 0; i < n; i++)

using namespace std;
using lli = long long int;
using pll = pair<lli, lli>;
using tlll = tuple<lli, lli, lli>;
using vll = vector<lli>;

lli mod197 = 1000000007LL;
lli INF = 10000000000000;

// ax + by = gcd(a,b) 最大公約数
template< typename T >
T extgcd(T a, T b, T& x, T& y) {
	T d = a;
	if (b != 0) {
		d = extgcd(b, a % b, y, x);
		y -= (a / b) * x;
	}
	else {
		x = 1;
		y = 0;
	}
	return d;
}

int main(void) {

	lli n, m, sum = 0;
	cin >> n >> m;

	for (lli i = 0; i < m; i++) {
		lli a;
		cin >> a;
		sum += a;
	}

	if (n >= sum) {
		cout << n - sum << endl;
	}
	else {
		cout << -1 << endl;
	}

	return 0;
}

Measured memory_bytes: 3596
//include
//------------------------------------------
#include <bits/stdc++.h>
using namespace std;
//conversion
//------------------------------------------
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();}
//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}
//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> P;
typedef long long ll;
//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#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 SORT(c) sort((c).begin(),(c).end())
//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const long long INF = 1000000007;
//clear memory
#define CLR(a) memset((a), 0 ,sizeof(a))
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;
// chmax chmin
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; }

int main(void){
    int x,a,b; cin >> x >> a >> b;
    cout << (abs(x-a) > abs(x-b) ? "B" : "A") << endl;
    return 0;
}

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

using namespace std;

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  bool ans = (A == B && B != C) || (B == C && C != A) || (A == C && C != B);
  cout << (ans ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 256
import sys
for line in sys.stdin:
    g = int(line)
    now = 512
    ans = []
    while True:
        if g == 0:
            break
        elif g >= now:
            g -= now
            ans.append(now)
        now //= 2
    temp = ''
    for i in ans[::-1]:
        temp += str(i) + ' '
    print(temp[:-1])


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

#define fi first
#define se second
#define pb push_back
#define sz(a) (int)(a).size()
#define mp(a, b) make_pair((a), (b))
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vvi = vector<vi>;
using vll = vector<ll>;
using vvll = vector<vll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e18;
const ll IINF = INT_MAX;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    string s;
    cin >> s;
    int ans = 0;
    for (int i = 0; i < 3; i++) {
        if (s[i] == 'S') continue;
        int cnt = 0;
        for (int j = i; j < 3; j++) {
            if (s[j] == 'S') break;
            cnt++;
        }
        ans = max(ans, cnt);
    }
    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 3636
#include<bits/stdc++.h>
//#pragma GCC optimize("O3")
#define endl "\n"
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL)
#define all(x) x.begin(), x.end()
#define pb push_back
#define eb emplace_back

using namespace std;
using ll=long long;
// using ll=int;

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

typedef pair<ll, ll> ii;
typedef vector<ll> vi;
typedef vector<ii> vii;

int main(){

    /*
    #ifndef ONLINE_JUDGE
        freopen("input.txt", "r", stdin);
        freopen("myoutput.txt", "w", stdout);
    #endif
    */

    fast;
    ll t = 1;
    // cin >> t;
    while(t--){
        ll n, k; cin >> n >> k;
        cout << floor((log(n)/log(k)))+1 << endl;

    
        
    }
    // cerr << (double)clock()/CLOCKS_PER_SEC << endl;
    return 0;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
string s, t, ans; int dp[3002][3002];
int main(){
    cin >> s >> t;
    for(int i=1; i<=(int)s.size(); i++){
        for(int j=1; j<=(int)t.size(); j++){
            if(s[i-1] == t[j-1]) dp[i][j] = dp[i-1][j-1] + 1;
            else dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
        }
    }
    for(int i=(int)s.size(), j=(int)t.size(); i!=0 && j!=0; ){
        if(dp[i][j] == dp[i-1][j]) i --;
        else if(dp[i][j] == dp[i][j-1]) j--;
        else { ans.push_back(s[i-1]); i--; j--; }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
}

Measured memory_bytes: 35456
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
	int a, b, c, d;
	cin >> a >> b >> c >>d;
	while(a>0&&c>0){
		c-=b;
		if(c<=0){
			cout << "Yes";
			return 0;
		}
		a-=d;
		if(a<=0){
			cout << "No";
			return 0;
		}

	}
    return 0;
}

Measured memory_bytes: 3648
#include<iostream>
using namespace std;
#include<bits/stdc++.h>
#define lli long long int
int main(){
  lli n,sum=0,x;
  cin>>n;
  vector<lli>p(n+1);
  for(lli i=1;i<=n;i++){
    cin>>p[i];
  }
  lli i=1,u=1;
  while(1){
    //u=i;
    while(u<=n and p[u]!=i){
      sum++;
      u++;
    }u++;
    if(u>n)
      break;
    i++;
  }
  if(sum==n)
    cout<<"-1";
  else
    cout<<sum;
  return 0;
}

Measured memory_bytes: 1792
N = int(input())
cnt = 0
ans = 0
for i in range(N):
    d1, d2 = map(int, input().split())
    if d1 == d2:
        cnt += 1
        ans = max(ans, cnt)
    else:
        cnt = 0

if ans >= 3:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 62332
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define rep(i,n) for(ll i = 0; i < (ll)(n); i++)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
const int INF = 1<<30;
int main(){
    int k,n;
    cin >> k >> n;
    vector<int> a(n);
    rep(i,n) cin >> a[i];
    int mx = -1;
    rep(i,n-1) chmax(mx, a[i+1]-a[i]);
    chmax(mx,k-a[n-1]+a[0]);
    int ans = k - mx;
    cout << ans << endl;
    return 0;
}

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

namespace AtCoder
{
    class Program
    {
        static void Main()
        {
            var temp = ReadLine();
            var a = temp[1];
            var b = temp[2];

            if ((b - a) % 2 == 0)
            {
                Console.WriteLine("Alice");
            }
            else
            {
                Console.WriteLine("Borys");
            }
        }

        static List<int> ReadLine()
        {
            var line = Console.ReadLine();
            var array = line.Split(' ');

            return array.Select(x => int.Parse(x)).ToList();
        }
    }
}

Measured memory_bytes: 13268
#include <bits/stdc++.h>
using namespace std;
int main(){
  int a,b;
  cin>>a>>b;
  if((a+b)%3==0 || a%3==0 || b%3==0){
    cout<<"Possible"<<endl;
  }else{
    cout<<"Impossible"<<endl;
  }
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		int n = sc.nextInt();

		int i = 1;
		while (i * i <= n) {
			i++;
		}
		i--;

		System.out.println(i * i);

		sc.close();
	}
}


Measured memory_bytes: 25300
#include<iostream>
using namespace std;
int sum = 0;
void solve(int i, int j,int ma,int m,int n,bool a[90][90]) {
	if (i + 1 < n&&a[i + 1][j]) {
		a[i + 1][j] = false;
		if (sum < ma + 1) sum = ma + 1;
		solve(i + 1, j,ma + 1, m, n, a);
		a[i + 1][j] = true;
	}
	if (i - 1 >= 0&&a[i - 1][j]) {
		a[i - 1][j] = false;
		if (sum < ma + 1) sum = ma + 1;
		solve(i - 1, j, ma + 1, m, n, a);
		a[i - 1][j] = true;
	}
	if (j + 1 < m&&a[i][j + 1]) {
		a[i][j + 1] = false;
		if (sum < ma + 1) sum = ma + 1;
		solve(i, j + 1,  ma + 1, m, n, a);
		a[i][j + 1] = true;
	}
	if (j - 1 >= 0&&a[i][j - 1]) {
		a[i][j - 1] = false;
		if (sum < ma + 1) sum = ma + 1;
		solve(i, j - 1,  ma + 1, m, n, a);
		a[i][j - 1] = true;
	}
}
int main() {
	int n, m;
	bool a[90][90];
	while (cin >> m >> n&&m != 0 && n != 0) {
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < m; j++) {
				int b;
				cin >> b;
				if (b == 0) a[i][j] = false;
				else a[i][j] = true;
			}
		}
		sum = 1;
		for (int i = 00; i < n; i++) {
			for (int j = 0; j < m; j++) {
				if (a[i][j]) {
					a[i][j] = false;
					solve(i, j,  1, m, n, a);
					a[i][j] = true;
				}
			}
		}
		cout << sum << endl;
	}
}

Measured memory_bytes: 3076
#include <iostream>
#include <fstream>
#include <set>
#include <map>
#include <string>
#include <vector>
#include <queue>
#include <deque>
#include <stack>
#include <functional>
#include <algorithm>
#include <climits>
#include <cmath>
#include <iomanip>
#include <atcoder/fenwicktree>
using namespace std;
using namespace atcoder;
#define ll long long int
#define rep(i,n) for( int i = 0; i < n; i++ )
#define rrep(i,n) for( int i = n; i >= 0; i-- )
#define REP(i,s,t) for( int i = s; i <= t; i++ )
#define RREP(i,s,t) for( int i = s; i >= t; i-- )
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define INF 2000000000
#define mod 1000000007
#define INF2 1000000000000000000


int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N, Q;
    cin >> N >> Q;
    int a[500010];
    rep(i, N) cin >> a[i];
    fenwick_tree<long long> fw(N);
    rep(i, N) {
        fw.add(i, a[i]);
    }
    while(Q--) {
        int t; cin >> t;
        if(t == 0) {
            int p, x;
            cin >> p >> x;
            fw.add(p, x);
        } else {
            int l, r;
            cin >> l >> r;
            cout << fw.sum(l, r) << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 10220
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    string s;
    cin >> s;
    int cur = n;
    vector<int> ans;
    while(cur > 0){
        if(cur-m <= 0){
            ans.push_back(cur);
            break;
        }
        bool no = true;
        for(int nex = m; nex > 0; nex--){
            if(s[cur-nex] == '0'){
                ans.push_back(nex);
                cur -= nex;
                no = false;
                break;
            }
        }
        if(no){
            cout << -1 << endl;
            return 0;
        }
    }
    rep(i,ans.size()){
        cout << ans[ans.size()-1-i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 1096
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")

n,k = map(int, input().split())
a = [0] + list(map(int, input().split()))

import numpy as np
c = np.cumsum(a)
b = c.reshape(-1,1) - c
l = int(np.log2(b.max())) + 1
s = set()
for i in range(1,n+1):
    for j in range(i):
        s.add(bin(b[i,j])[2:].rjust(l, "0"))
ans = 0
for i in range(l):
    count = 0
    tmp = set()
    for item in s:
        if item[i]=="0":
            pass
        else:
            count += 1
            tmp.add(item)
    if count>=k:
        ans+= 2**(l-i-1)
        s = tmp
print(ans)

Measured memory_bytes: 95864
#include<iostream>
using namespace std;
int main()
{
    long n, a, l=0, cnt=1;
    cin >> n;
    while(n--)
    {
        cin >> a;
        if(l==0) l=a;
        else if(a<=l)
        {
            l=a;
            cnt++;
        }
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b&&a!=c&&b!=c)
    {
        printf("Yes");
    }
    else if(b==c&&b!=a&&c!=a)
    {
        printf("Yes");
    }
    else if(a==c&&a!=b&&c!=b)
    {
        printf("Yes");
    }
    else
    {
        printf("No");
    }
    printf("\n");

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e9;
const long long int mod = 1e9+7;
typedef pair<ll,ll> pairs;
vector<pairs> p;


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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

vector<vector<ll>> combination(ll n, ll r){
    vector<vector<ll>> v(n + 1, vector<ll>(n + 1, 0));
    for(ll i=0;i<v.size();++i){
        v[i][0] = 1;
        v[i][i] = 1;
    }
    for(ll i=1;i<v.size();++i){
        for(ll j=0;j<i;++j){
            v[i][j] = (v[i - 1][j - 1] + v[i - 1][j]);
        }
    }
    return v;
}
// ------------------------------------

int main(){
    ll n;
    cin>>n;
    ll a[n];
    for(ll i=0;i<n;++i){
        cin>>a[i];
    }
    ll ans=0;
    for(ll i=0;i<n;++i){
        if(i+1 == a[a[i]-1]){
            ans++;
        }
    }
    ans /= 2;
    cout<<ans<<endl;

    return 0;
}

Measured memory_bytes: 1024
import std.algorithm, std.container, std.conv, std.math, std.range, std.typecons, std.stdio, std.string;

auto rdsp(){return readln.splitter;}
void pick(R,T)(ref R r,ref T t){t=r.front.to!T;r.popFront;}
void readV(T...)(ref T t){auto r=rdsp;foreach(ref v;t)pick(r,v);}
void readA(T)(size_t n,ref T[]t){t=new T[](n);auto r=rdsp;foreach(ref v;t)pick(r,v);}

void main()
{
  int n, m; readV(n, m);
  int[] a; readA(m, a);
  auto b = [0, 2, 5, 5, 4, 5, 6, 3, 7, 6];
  auto as = a.map!(to!string).array;

  auto dp = new string[](n+1); dp[1..$][]= "x";
  foreach (i; 1..n+1)
    foreach (ai, asi; lockstep(a, as))
      if (i >= b[ai] && dp[i-b[ai]] != "x")
        dp[i] = maxS(dp[i], asi ~ dp[i-b[ai]]);

  writeln(dp[n]);
}

auto maxS(string s, string t)
{
  if (s == "x") swap(s, t);

  if (s == "x") return "x";
  if (t == "x") return s;
  if (s.length > t.length) return s;
  if (s.length < t.length) return t;

  return max(s, t);
}


Measured memory_bytes: 82428
#include"bits/stdc++.h"
using namespace std;
#define int long long
#define F first
#define S second
#define rep(i,n) for(int i=0;i<n;i++)
const long long mod = 10000000;
const long long inf = 11451419198109130;
typedef pair<int, int> P;
typedef pair<P, int> PP;
typedef pair<int,PP> PPP;
struct edge { int to; int to2; int cost; };
int bit[60];
int x[100005];
signed main() {
	int n, m; cin >> n >> m;
	rep(i, m)cin >> x[i];
	sort(x, x + m);
	vector<int>V;
	rep(i, m - 1)V.push_back(x[i + 1] - x[i]);
	int sum = 0;
	sort(V.begin(), V.end());
	rep(i, m - n)sum += V[i];
	cout << sum << endl;
}

Measured memory_bytes: 2168
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <string>
#include <cmath>
using namespace std;

int main(){
    while(true){
        int a,c;
        string b;
        cin >> a >> b >> c;
        
        if(b=="+"){
            cout<<a+c<<endl;
        }
        else if(b=="*"){
            cout<<a*c<<endl;
        }
        else if(b=="-"){
            cout<<a-c<<endl;
        }
        else if(b=="/"){
            cout<<a/c<<endl;
        }
        else{
            break;
        }
    }

    
    return 0;
}




Measured memory_bytes: 3160
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
		
		int n = Integer.parseInt(reader.readLine());
		int[] a = new int[n];
		int[] b = new int[n];
		int[] c = new int[10000];
		int k = Integer.MIN_VALUE;
		StringTokenizer st = new StringTokenizer(reader.readLine());
		for (int i = 0; i < n; i++) {
			a[i] = Integer.parseInt(st.nextToken());
			k = Math.max(k, a[i]);
			c[a[i]]++;
		}
		countingSort(a, b, c, k);
		StringBuilder sb = new StringBuilder();
		sb.append(b[0]);
		for (int i = 1; i < n; i++) {
			sb.append(' ').append(b[i]);
		}
		System.out.println(sb.toString());
	}

	private static void countingSort(int[] a, int[] b, int[] c, int k) {
		for (int i = 1; i <= k; i++) {
			c[i] += c[i - 1];
		}
		for (int i = a.length - 1; i >= 0; i--) {
			c[a[i]]--;
			b[c[a[i]]] = a[i];
		}		
	}
}



Measured memory_bytes: 165592
#include<bits/stdc++.h>
using namespace std;
int a[100005];
int n;
/*int check(int m){
	int s1=0,s2=0;
	for(int i=0;i<n;i++){
		if(a[i]>=m)
			s1++;
		else s2++;
	}
	if(s1==s2)
		return 1;
	return 0;
}*/
int main(){
	cin>>n;
	int mx=0;
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		//mx=max(mx,a[i]);
	}
	//int l=0,r=1e6,ans=0;
	/*while(l<=r){
		int m=(l+r)>>1;
		if(check(m)){
			l=m+1;
			ans=m;
		}	
		else r=m-1;
	}*/
	sort(a,a+n);
	int ans=0;
	if(n%2==0){
		//for(int i=a[n/2-1]+1;i<=a[n/2])
		ans=a[n/2]-a[n/2-1];
	}
	printf("%d",ans);
}

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

const long double EPS = 1e-10;
const long long INF = 1e18;
const long double PI = acos(-1.0L);


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


void solve(int a[],int n){
  int flag = 0;
  for(int i=0;i<n-1;i++){
    if(a[i+1]-a[i] > 1 ){
      cout<<"NO\n";
      flag = 1;
      break;
    }
  }

  if(!flag){
    cout<<"YES\n";
  }
  
}

ll min(ll a , ll b){   if (a > b){    return b; }  return a; }

ll freq_elem(unordered_map<ll,ll> umap){

ll num , freq_elem = 0;

for( auto i: umap){
  if(i.second > freq_elem){
    freq_elem = i.second;
    num = i.first;
  }
}


return freq_elem;
}

int main(){


int n,t;
cin>>n>>t;
vector<pair<int,int>> vect;
REP(i,n){
  int c,time;
  cin>>c>>time;  
  if(time <= t){
     vect.push_back({c, time});
  }
}

sort(vect.begin(),vect.end());

// REP(i,vect.size()){
//   cout<<vect[i].first<<" =>"<<vect[i].second<<"\n";
// }

if(vect.size() > 0){
cout<<vect[0].first<<"\n";
}
else{
  cout<<"TLE\n";
}




  return 0;
}




Measured memory_bytes: 3608
#!/usr/bin/perl
use strict;
use warnings;
use Data::Dumper;
use 5.010;
my @args;
for (<>) {
    chomp $_;
    push @args, $_;
}

my ($x1, $y1, $x2, $y2) = split " ", shift @args;

my $x3 = $x2 + ($y1 - $y2);
my $y3 = $y2 - ($x1 - $x2);
my $x4 = $x3 + ($x1 - $x2);
my $y4 = $y3 + ($y1 - $y2);

say "$x3 $y3 $x4 $y4";


__END__


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

int main(){
  int N;
  cin>>N;
  int j=0,k;
  for(int i=0;i<N;i++){
    int A,B;
    cin>>A>>B;
    if(j<A){
      j=A;
      k=B;
    }
  }
  cout<<j+k<<endl;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  cin >> N ;
  int c = 100;
  int d;
  for ( int i=0 ; i < N; i++ ) {
    int x; 
    cin >> x ;
    if (x%2 != 0){
      c=0;
        break ;
    }else if ( x%2 == 0){
   for ( int j=x ,y=0; j%2 == 0 ; ){
     y=y+1;
     j=j/2;
       d = min (y,c) ;
   }
    }
    c=min(d,c);
  }
  cout << c << endl ;
}



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

namespace AtCoder
{
    class _063B
    {
        static void Main()
        {
            List<char> str = Console.ReadLine().ToList();
            HashSet<char> strhash = new HashSet<char>(str);
            Console.WriteLine(str.Count == strhash.Count ? "yes" : "no");
        }
    }
}


Measured memory_bytes: 13396
#include<stdio.h>
 
char oc[] = "01235789";
 
void oct(int a){
  if(a == 0)return;
  oct(a / 8);
  putchar(oc[a % 8]);
}
 
int main(){
  int a;
  while(scanf("%d", &a)){
    if(a == 0)return 0;
    oct(a);
    puts("");
  }  
}

Measured memory_bytes: 588
N, M = map(int, input().split())
I = [list(map(int, input().split())) for _ in range(M)]
s = [0] * M
c = [0] * M
for i in range(M):
    s[i] = I[i][0]
    c[i] = I[i][1]
ans = -1
if N == 1:
    for i in range(0, 10):
        flg = 0
        for j in range(M):
            if c[j] != i:
                flg = 1
                break
        if flg == 1:
            continue
        if ans == -1:
            ans = i
        else:
            ans = min(ans, i)
else:
    for i in range(10**(N-1), 10**N):
        flg = 0
        for j in range(M):
            if (i%(10**(N+1-s[j])))//(10**(N-s[j])) == c[j]:
                continue
            flg = 1
            break
        if flg == 1:
            continue
        if ans == -1:
            ans = i
        else:
            ans = min(ans, i)

print(ans)

Measured memory_bytes: 9252
#include <bits/stdc++.h>
  using namespace std;
  #define FASTIO std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);

  int main () {
    int a, b, c;
    cin >> a >> b >> c;
    swap(a, b);
    swap(a, c);
    cout <<a << " " << b << " " << c;


  }


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<map>
#include<numeric>

using namespace std;

int main(){
    int n;
    cin >> n;
    n %= 1000;
    if(n == 0) cout << 0 << endl;
    else cout << 1000 - n << endl;

}

Measured memory_bytes: 3620
N = int(raw_input())
a = [int(t) for t in raw_input().split()]

def how_manys_2(a):
  count = 0
  while a % 2 == 0:
    a = a // 2
    count += 1
  return count

b = [how_manys_2(t) for t in a]
print(sum(b))

Measured memory_bytes: 3460
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const string yes = "Yes";
const string no = "No";

int main()
{
  ll K;
  cin >> K;
  ll X;
  cin >> X;

  if (500*K >= X) cout << yes << endl;
  else cout << no << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <cmath>
#include <map>
#include <vector>

#define REP(i,n) for(int i=0;i<(int)n;i++)
#define REP1(j,n) for(int j=0;j<(int)n;j++)
#define REPD(i,n) for(int i=n;i>=0;i--)
#define REPD1(j,n) for(int j=n;j=>0;j--)
#define REPS(i,n) for(int i=1;i<=(int)n;i++)
#define REPS1(j,n) for(int j=1;j<=(int)n;j++)
#define rep(i,a,n) for(int i=a;i<(int)n;i++)
#define SZ(x) ((int)(x).size())	//size() unsigned -> int
#define DescSort(a) sort(a.begin(),a.end(),std::greater<int>())

using namespace std;
typedef long long ll;


int main(void) {
	int a, b, c;
	cin >> a >> b >> c;
	int amax = max({ a,b,c });
	int amin = min({ a,b,c });
	cout << abs(amax - amin) << endl;
	return 0;
}



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

using namespace std;

int main(){

	ll n;
	
	string s;
	cin >> n >> s;
	set<ll> w;
	set<ll> r;
	bool allw = 1, allr= 1;
	for(int i = 0; i < n; i++){
		if(s[i] == 'W'){
			w.insert(i);
			allr = 0;
		}
		else{
			r.insert(i);
			allw = 0;
		}
	}

	if(allw || allr){
		cout << 0 << "\n";
	}
	else{
		ll c = 0;
		set<ll> :: iterator it = w.begin();
		for(int i = n-1; i >= 0; i--){
			if(s[i] == 'W'){
				continue;
			}
			else{
				if(it != w.end()){
					ll val = *it;
					if(val < i){				
						swap(s[i], s[val]);
						it++;
					}
					else{
						break;
					}				
				}
				else{
					break;
				}
				c++;
			}
		}
		cout << c << "\n";
			
	}

}

Measured memory_bytes: 12972
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
using namespace std;
	typedef long long int lli;
	const int MaxN=200005;
	#define fst first
	#define snd second
	int mcd(int a,int b){	
		if(a==0)return b;
		return mcd(b%a,a);
	}	
int main(){
	lli N,K,i,j,p,inf,sup,tot=0;
	cin>>K;
	for(i=1;i<=K;i++){
		for(j=1;j<=K;j++){
			for(p=1;p<=K;p++){
				tot+=mcd(mcd(i,j),p);
			}
		}
	}		
	cout<<tot;
}

Measured memory_bytes: 3228
#include <iostream>
#include <cmath>

int main() {
	int w;
	std::cin >> w;
	int a[100], b[100];
	for (int i = 0; i < w; i++) {
		std::cin >> a[i];
	}
	for (int i = 0; i < w; i++) {
		std::cin >> b[i];
	}
	int sum = 0;
	for (int i = 0; i < w;i++) {
		int suum = 0;
		for (int j = 0; j < w; j++) {
			if (j < i) {
				suum += a[j];
			}
			else if(j == i) {
				suum += a[j];
				suum += b[j];
			}
			else {
				suum += b[j];
			}
		}
		if (sum < suum) {
			sum = suum;
		}
	}
	std::cout << sum << std::endl;
}

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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

namespace SCC{
    void visit(const vector<vector<int>>&G,vector<int>&vs,vector<int>&used,int v){
        used[v]=true;
        for(auto u:G[v]){
            if(!used[u])visit(G,vs,used,u);
        }
        vs.push_back(v);
    }

    void visit2(const vector<vector<int>>&T,vector<int>&used,vector<int>&comp,vector<int>&vec,int k,int v){
        comp[v]=k;
        used[v]=true;
        vec.push_back(v);

        for(auto u:T[v]){
            if(!used[u])visit2(T,used,comp,vec,k,u);
        }
    }

    //G:?????£?????????????§£???????????°??????
    //H:?????£??????????????°??????1???????????????????´?????????°??????
    //comp:G????????????????????????H?????????????±????????????????
    void decompose(const vector<vector<int>>&G,vector<vector<int>>&H,vector<int>&comp){
        vector<vector<int>>T(G.size());
        for(int i=0;i<G.size();i++){
            for(auto v:G[i]){
                T[v].push_back(i);
            }
        }
        comp.resize(G.size());

        vector<int>vs(G.size());
        vector<int>used(G.size());
        for(int i=0;i<G.size();i++){
            if(!used[i])visit(G,vs,used,i);
        }
        reverse(vs.begin(),vs.end());
        fill(used.begin(),used.end(),0);

        int K=0;
        vector<vector<int>>S;
        for(auto v:vs){
            if(!used[v]){
                S.push_back(vector<int>());
                visit2(T,used,comp,S.back(),K++,v);
            }
        }

        H.resize(K);
        fill(used.begin(),used.end(),0);
        for(int i=0;i<K;i++){
            for(auto v:S[i]){
                for(auto u:G[v]){
                    if(used[comp[u]]||comp[v]==comp[u])continue;
                    used[comp[u]]=true;
                    H[comp[v]].push_back(comp[u]);
                }
            }
            for(auto v:H[i])used[v]=false;
        }

    }
}

int N;
double P[100];
signed main(){
    while(cin>>N,N){
        vector<vector<int>>G(N),H;
        rep(i,N){
            cin>>P[i];
            int t;cin>>t;
            rep(j,t){
                int a;cin>>a;G[i].pb(a-1);
            }
        }

        vint comp;
        SCC::decompose(G,H,comp);
        int deg[100]={};
        double PP[100];rep(i,H.size())PP[i]=1.0;
        rep(i,H.size())for(auto u:H[i])deg[u]++;
        rep(i,N)PP[comp[i]]*=P[i];
        double ans=1.0;
        rep(i,H.size())if(deg[i]==0)ans*=1.0-PP[i];
        printf("%.20f\n",ans);
    }
    return 0;
}

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

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

    vector<int> A(N);
    vector<double> Ad(N);

    for (int i = 0; i < N; i++)
    {
        //    int p;
        cin >> A.at(i);
        //      cout << A.at(i) << endl;
    }
    for (int i = 0; i < N; i++)
    {
        //   int p;
        //  cin >> p;
        Ad.at(i) = (double)(A.at(i) + 1.0) / 2.0;
        // cout << A.at(i) << endl;
    }

    double sm = 0;
    double stmp = 0;
    for (int i = 0; i < N - K + 1; i++)
    {
        //     double stmp = 0;
        if (i == 0)
        {
            for (int j = 0; j < K; j++)
            {
                stmp += Ad.at(i + j);
                //         cout << stmp << endl;
            }
        }
        else
        {
            stmp += Ad.at(i + K - 1);
        }
        sm = max(sm, stmp);
        stmp -= Ad.at(i);
    }
    cout << fixed << setprecision(10) << sm << endl;
}


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

#define ll long long
#define ar array
#define OJ \
    freopen("input.txt", "r", stdin); \
    freopen("output.txt", "w", stdout);
#define endl "\n"

int main(){
/////////////////////////////////////////////////////////////
/////////////////////////////////////////////////////////////
    ios::sync_with_stdio(0);
    cin.tie(0);
    int x,y;
    cin>>x>>y;
    if (y%2==0 && x<=y/2 && 2*x>=y/2){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}

Measured memory_bytes: 3604
#include<iostream>
#include<cstdio>
#include<string>
#include<algorithm>
#include<utility>
#include<numeric>
#include<vector>
#include<map>
#include<unordered_map>
#include<set>
#include<tuple>
#include<stack>
#include<queue>
#include<tuple>
#include<functional>
#include<iterator>
#include<cmath>
#include<cctype>

using namespace std;

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

const int INF = 1e9;
const ll LINF = 1e18;
const int MOD = INF+7;

struct edge{int to,cost;};

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

	int n,p;
	cin >> n >> p;

	int a;
	int parity[2]={};
	for(int i=0;i<n;i++){
		cin >> a;
		parity[a%2]++;
	}
	ll ans=pow(2LL,parity[0]);
	ll tmp=1,sum=0;
	if(p%2 == 1){
		for(int i=1;i<=parity[1];i+=2){
			for(int j=0;j<i;j++){
				tmp*=parity[1]-j;
				tmp/=j+1;
			}
			sum+=tmp;
			tmp=1;
		}
	}
	else{
		for(int i=0;i<=parity[1];i+=2){
			if(i==0){
				sum++;
				continue;
			}
			for(int j=0;j<i;j++){
				tmp*=parity[1]-j;
				tmp/=j+1;
			}
			sum+=tmp;
			tmp=1;
		}
	}
	cout << ans*sum << "\n";

	return 0;
}

Measured memory_bytes: 256