akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cstdlib>
#include<vector>
#include<map>
#include<queue>
#include<string>
#include<sstream>
#include<cmath>
#include<numeric>
#include<random>
using namespace std;

int main(){

  string s;
  cin >> s;

  if( s[0] == s[1] ){
    cout << 1 << " " << 2 << endl;
    return 0;
  }
  for(int i=2; i<s.size(); i++){
    if( s[i-2] == s[i] ){
      cout << i-1 << " " << i+1 << endl;
      return 0;
    }
    if( s[i-1] == s[i] ){
      cout << i << " " << i+1 << endl;
      return 0;
    }
  }
  cout << "-1 -1" << endl;

  return 0;
}




// EOF


Measured memory_bytes: 512
import sys
n = int(input())
li = sorted(map(lambda x: list(map(int, x.split()[::-1])), sys.stdin.readlines()))
sum = 0
flag = "Yes"
for x, y in li:
  sum += y
  if x < sum:
    flag = "No"
    break
    
print(flag)
    

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

using namespace std;
 
int main(){
    int N, M, i;
    cin >> N >> M;

    int A[50], B[50], CNT[50];

    for (i = 1; i <= M; i++){
      cin >> A[i] >> B[i];
    }

    for (i = 1; i <= N; i++){
       CNT[i] = 0;
    }
 
    for (i = 1; i <= M; i++){
      CNT[A[i]] += 1;
      CNT[B[i]] += 1;
    }
    
    for (i = 1; i <= N; i++){
      cout << CNT[i] << endl;    
    }
}

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

using namespace std;
int main(void){

    int n;
    cin >> n;
    
    if(n==1) {
        cout << 1 << endl;
        return 0;
    }
    
    long long counts[1001];
    for(int i=0; i<=1000; i++) counts[i] = 0;

    for(int i=2; i<=n; i++) {
        int temp_i = i;
        for(int j=2; j<=1000; j++) {
            if(temp_i%j==0) {
                counts[j]++;
                temp_i/=j;
                j--;
            }
        }
    }
    
    long long limit = 1000000000+7;
    long long result = 0;
    for(int i=0; i<=1000; i++) {
        if(counts[i]!=0) {
//            cout << i << " " << counts[i] << " " << result << endl;
            if(result == 0) {
                result += counts[i]+1;
                continue;
            }
            long long temp_result = result;
            for(int j=0; j<counts[i]; j++) {
                result += temp_result;
                if(limit<result) result -= limit;
            }
        }
    }
    
    cout << result << endl;

}


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

signed  main(){
	int n;
	cin >> n;
	vector<pair<int,int>> v;
	set<pair<int,int>> pot;
	map<pair<int,int>,bool> m;
	for (int i=0; i<n; ++i){
		int a,b;
		cin >> a >> b;
/*		set<pair<int,int>> pot2;
		for (auto& k:pot){
			pot2.emplace(k.first-a,k.second-b);
			pot2.emplace(k.first-a,b-k.second);
			pot2.emplace(a-k.first,b-k.second);
			pot2.emplace(a-k.first,k.second-b);			
		}
		for (auto& k:pot2) pot.emplace(k.first,k.second);
*/		for (auto& k:v){
			pot.emplace(k.first-a,k.second-b);
			pot.emplace(k.first-a,b-k.second);
			pot.emplace(a-k.first,b-k.second);
			pot.emplace(a-k.first,k.second-b);
		}
		v.emplace_back(a,b);
		m[{a,b}]=true;
		pot.emplace(a,b);
		pot.emplace(-a,b);
		pot.emplace(a,-b);
		pot.emplace(-a,-b);
	}
	int ret=INT_MAX;
	for (auto& i:pot){
		int cnt=0;
		for (auto& k:v){
			if (!m.count({k.first+i.first,k.second+i.second})){
				++cnt;
			}
		}
		ret = min(ret,cnt);
	}
	cout << ret;
}

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

#define ll long long
#define F first
#define S second
#define ii pair < int , int >
#define ever (;;)

const int N = 200100;

ll n,k,a[N];

bool ok(ll mid)
{
    ll cnt = 0;

    for(int i=1;i<=n;i++)
        cnt += (a[i]+mid-1)/mid - 1;

    return cnt <= k;
}

int main()
{
    scanf("%lld%lld",&n,&k);
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]);

    ll low = 1,high = 1000000000;
    while( low < high )
    {
        int mid = (low+high)/2;

        if( ok(mid) )
            high = mid;
        else
            low = mid+1;
    }

    printf("%lld\n",low);
}


Measured memory_bytes: 5272
import sys
stdin = sys.stdin
sys.setrecursionlimit(10**6)
 
ni = lambda: int(ns())
na = lambda: list(map(int, stdin.readline().split()))
nn = lambda: list(stdin.readline().split())
ns = lambda: stdin.readline().rstrip()

n = ni()
a = na()
b = [1/i for i in a]
print(1/sum(b))

Measured memory_bytes: 3064
N,M = map(int,input().split())

acli = [0]*N
wali = [0]*N

for _ in range(M):
  P,S = map(str,input().split())
  P = int(P)-1
  if acli[P] == 1:
    continue
  if S == "AC":
    acli[P] = 1
  else:
    wali[P] += 1
    
for i in range(N):
  if acli[i] == 0:
    wali[i] = 0
    
print(sum(acli),sum(wali))

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

num_count = [0]*(10**5+1)
tmp_sum = sum(A)
for i in A:
    num_count[i] += 1

for q in range(int(input())):
    B,C = map(int,input().split())
    gain = C*(num_count[B])
    loss = B*(num_count[B])
    num_count[C] += num_count[B]
    num_count[B] = 0
    tmp_sum = tmp_sum + gain - loss
    print(tmp_sum)


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

int main(void)
{
	int H, W;
	cin >> H >> W;
	char *s = new char[(H + 2)*(W + 2)];
	for (int i = 0; i < H+2; ++i) {
		for (int j = 0; j < W+2; ++j) {
			if (i == 0 || i == H + 1 || j == 0 || j == W + 1)	s[i*(W + 2) + j] = '.';
			else	cin >> s[i*(W + 2) + j];
		}
	}

	bool flg = false;
	for (int i = 1; i <= H; ++i) {
		for (int j = 1; j <= W; ++j) {
			if (s[i*(W + 2) + j] == '.')	continue;
			if (s[(i - 1)*(W + 2) + j] == '.' && s[(i + 1)*(W + 2) + j] == '.' && s[i*(W + 2) + j - 1] == '.' && s[i*(W + 2) + j + 1] == '.')	flg = true;
			if (flg) {
				cout << "No" << endl;
				return 0;
			}
		}
	}

	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<cctype>
#include<cmath>
#include<cstdio>
#include<list>
#include<set>
#include<stack>
#include<string>
#include<sstream>
#include<map>
#include<queue>
#include<vector>
using namespace std;

int main() {
	double x = 0, y = 0, rad = 90 * M_PI / 180;
	int a, b;
	while (scanf("%d,%d", &a, &b) && (a || b)) {
		x += a*cos(rad);
		y += a*sin(rad);
		//????????????
		rad -= b*M_PI / 180;
	}
	cout << (int)x << endl << (int)y << endl;
	return 0;
}

Measured memory_bytes: 1212
#include "bits/stdc++.h"
#define rep(i,b) for(ll i=0;i<b;i++)
#define ll long long
using namespace std;
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vvvl vector<vector<vector<ll>>>

int main() {
ll n;bool flag=true; cin>>n;
vl a(n);
rep(i,n)cin>>a[i];
sort(a.begin(),a.end());
if(n%2==0){
    if(a[0]==0)flag=false;
    for(int i=0;i<n-1;i+=2)if(a[i]!=a[i+1])flag=false;
}else {
    if(n==1)if(a[0]!=0)flag=false;
    if (n > 1) {
        if (a[1] == 0)flag = false;
        for (int i = 1; i < n - 1; i += 2)if (a[i] != a[i + 1])flag = false;
    }
}
ll ans=1;rep(i,n/2)ans=ans*2%1000000007;
if(flag)cout<<ans<<endl;
else cout<<0<<endl;
}

Measured memory_bytes: 1024
N = int(input())
s = input()
ans = 0
for i in range (N):
    for j in range(i+1,(i+N+1)//2):
        if s[i] != s[j]:
            if s[2*j-i] != s[i] and s[2*j-i] != s[j]:
                ans -= 1

r = s.count("R")
g = s.count("G")
ans += r*g*(N-r-g)
print(ans)




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

using namespace std;
struct m{
	int a,b;
}k[200005];
bool cmp(m x,m y){
	if(x.b<y.b)return true;
	else{
		if(x.b==y.b){
			if(x.a>y.a)return true;
			return false;
		}
	}
	return false;
}
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++)cin>>k[i].a>>k[i].b;
	sort(k,k+n,cmp);
	int ans=0;
	for(int i=0;i<n;i++){
		ans+=k[i].a;
		if(ans>k[i].b){
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
}

Measured memory_bytes: 1792
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
fn main(){
    let s:Vec<char> = read::<String>().chars().collect();
    let ans = if s.len() ==3 {
        s.into_iter().rev().collect::<String>()
    } else{
        s.into_iter().collect::<String>()
    };
    println!("{}", ans);
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
 
using namespace std;
inline void prep ()
{
  cin.tie (0);
  cin.sync_with_stdio (0);
};
const double pi = acos(-1.);
//printf(%.12lf\n,mid);
// __builtin_popcount(int) count 1's in binary
// get decimal part of number
/*
double intpart;
double thiss = modf((double)(n*m)/(double)k, &intpart);
*/
// round = (int)(num+.5)
long long mod = 1000000007;
 
// 32 mil = ~1 sec 
long long mymod(long long num){
  if (num< 0 && !(num%mod == 0)){
    if (mod == 1){
      return 0;
    }
    return mod-abs(num)%mod;
  }else{
    return num%mod;
  }
}
 
/*string sentence = And I feel fine...;
    istringstream iss(sentence);
*/  
const int biggg = 2000000000;
const long long bigggest = 1000000000000000000LL;
const double eps = .0000000001;

vector<long long> pos;
vector<long long> neg;
long long n, k;
long long func(long long goal, vector<long long>& vec){
    // for each
    long long sum = 0;
    int r = vec.size()-1;
    for (int i=0; i<vec.size(); i++){
        while (r > i && vec[i]*vec[r] >= goal) r--;
        sum += max(0, r-i);
    }
    return sum;
}
long long func2(long long goal){
    long long sum = 0;
    int r = 0;
    for (int i=neg.size()-1; i>=0; i--){
        while (r < pos.size() && neg[i]*pos[r] >= goal) r++;
        sum += pos.size()-r;
    }
    return sum;
}

int main ()
{
  prep();
  
  cin >> n >> k;
  long long arr[n];
  for (int i=0; i<n; i++){
      cin >> arr[i];
      if (arr[i] >= 0) pos.push_back(arr[i]);
      else neg.push_back(arr[i]);
  }
  sort(pos.begin(), pos.end());
  sort(neg.rbegin(), neg.rend());
  long long l = -bigggest-1, r = bigggest+1, lastgood = -1;
  while (l<=r){
    long long mid = (l+r)/2;
    // how many are over mid, if it's less than k, is good
    long long sum = func(mid, pos)+func(mid, neg)+func2(mid);
    //cout << mid << " " << sum << endl;
    if (sum >= k) r = mid-1;
    else{
        l = mid+1;
        lastgood = mid;
    }
  }
  cout << lastgood;
  return 0;
}

Measured memory_bytes: 3700
### main

while true
  n = gets.strip.to_i
  break if n == 0

  ns = []
  n.times.each do
    k = gets.strip.to_i
    ns << k
  end

  s = gets.strip.to_i

  i0 = 0
  i1 = n - 1
  count = 0

  while i0 <= i1
    #p [i0, i1]
    i = (i0 + i1) / 2
    cmp = ns[i] <=> s
    count += 1

    if cmp == 0
      break
    elsif cmp < 0
      i0 = i + 1
    else
      i1 = i - 1
    end
  end

  puts count
end

Measured memory_bytes: 6104
#include <iostream>
#include <vector>
#include <stack>

using namespace std;

typedef long long ll;

vector<ll> pot(50);
int n, m;

ll Licz(vector< vector<int> >& zb, int mask)
{
    int kr = 0;
    for (int i = 0; i < n; ++i)
        for (int j = i + 1; j < n; ++j)
            if ((mask & zb[i][j]) != 0)
                ++kr;
    return pot[n - 1 - kr];
}

bool dfs(vector< vector<bool> >& T, int a, int b)
{
    stack<int> S;
    vector<bool> odw(n, false);
    S.push(a);
    odw[a] = true;
    while (!S.empty())
    {
        int akt = S.top();
        S.pop();
        for (int i = 0; i < n; ++i)
        {
            if (T[akt][i] && !odw[i])
            {
                S.push(i);
                odw[i] = true;
            }
        }
    }
    return odw[b];
}

int main()
{
    ios_base::sync_with_stdio(0);
    pot[0] = 1;
    for (ll i = 1; i < 50; ++i)
        pot[i] = pot[i - 1] * 2;
    cin >> n;
    vector< vector<bool> > T(n, vector<bool>(n, false));
    for (int i = 0; i < n - 1; ++i)
    {
        int a, b;
        cin >> a >> b;
        --a;
        --b;
        T[a][b] = true;
        T[b][a] = true;
    }
    cin >> m;
    vector<int> a(m), b(m);
    for (int i = 0; i < m; ++i)
    {
        cin >> a[i] >> b[i];
        --a[i];
        --b[i];
    }
    vector< vector<int> > zb(n, vector<int>(n, 0));
    for (int i = 0; i < n; ++i)
    {
        for (int j = i + 1; j < n; ++j)
        {
            if (!T[i][j])
                continue;
            for (int k = 0; k < m; ++k)
            {
                T[i][j] = false;
                T[j][i] = false;
                bool ok = dfs(T, a[k], b[k]);
                if (!ok)
                    zb[i][j] |= (1 << k);
                T[i][j] = true;
                T[j][i] = true;
            }
        }
    }
    ll odp = pot[n - 1];
    for (int mask = 1; mask < (1 << m); ++mask)
    {
        ll il = Licz(zb, mask);
        if (__builtin_popcount(mask) % 2 == 1)
            odp -= il;
        else
            odp += il;
    }
    cout << odp;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main() {
    int N, M, X;
    cin >> N >> M >> X;
    int C[N], A[N][M];
    for (int i = 0; i < N; i++) {
        cin >> C[i];
        for (int j = 0; j < M; j++) {
            cin >> A[i][j];
        }
    }
    
    int ans = INT32_MAX;
    for (int i = 1; i < (1<<N); i++) {
        int a[M]{};
        int v = 0;
        for (int j = 0; j < N; j++) {
            if (i & (1<<j)) {
                v += C[j];
                for (int k = 0; k < M; k++) {
                    a[k] += A[j][k];
                }
            }
        }
        for (int j = 0; j < M; j++) {
           if (a[j] < X) break;
           if (j == M - 1) {
               ans = min(ans, v);
           }
        }
    }
    if (ans != INT32_MAX) {
        cout << ans << "\n";
    } else {
        cout << "-1\n";
    }
    return 0;
}

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

int main(){
  long n;
  cin >> n;
  vector<long> vec(5);
  rep(i,5) cin >> vec.at(i);
  sort(vec.begin(), vec.end());
  long t;
  t = vec.at(0);
  cout << (n+t-1)/t + 4;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <climits>
#include <cmath>
#include <string>
#include <vector>
#include <algorithm>
#include <queue>
#include <map>
#include <functional>
#include <set>
#include <numeric>
#include <stack>
#include <utility>
#include <time.h>
#include <iterator>
//#include "util.h"

using namespace std;
typedef unsigned uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef pair<int, int> pii;

//呪文
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const pair<_KTy, _Ty>& m) { cout << "{" << m.first << ", " << m.second << "}"; return ostr; }
template <typename _KTy, typename _Ty> ostream& operator << (ostream& ostr, const map<_KTy, _Ty>& m) { if (m.empty()) { cout << "{ }"; return ostr; } cout << "{" << *m.begin(); for (auto itr = ++m.begin(); itr != m.end(); itr++) { cout << ", " << *itr; } cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const vector<_Ty>& v) { if (v.empty()) { cout << "{ }"; return ostr; }	cout << "{" << v.front(); for (auto itr = ++v.begin(); itr != v.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _Ty> ostream& operator << (ostream& ostr, const set<_Ty>& s) { if (s.empty()) { cout << "{ }"; return ostr; } cout << "{" << *(s.begin()); for (auto itr = ++s.begin(); itr != s.end(); itr++) { cout << ", " << *itr; }	cout << "}"; return ostr; }
template <typename _KTy, typename _Ty> istream& operator >> (istream& istr, pair<_KTy, _Ty>& m) { cin >> m.first >> m.second; return istr; }
ll modpow(ll n, ll p, ll m) { ll result = 1; while (p > 0) { if (p & 1) result = (result * n) % m; p >>= 1; n = (n * n) % m; } return result; }
#define PI 3.14159265358979323846
#define EPS 1e-8
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define all(x) (x).begin(), (x).end()
#define fake false



int ManhattanDistance(pii& p, pii& q) {
	return abs(p.first - q.first) + abs(p.second - q.second);
}

int main() {
	int N, M;
	cin >> N >> M;
	vector<pii> student(N);
	vector<pii>	checkpoint(M);
	REP(i, N) cin >> student[i];
	REP(i, M) cin >> checkpoint[i];
	REP(i, N) {
		pii p = student[i];
		int mind = INT_MAX, minpos;
		for (int j = M - 1; j >= 0; j--) {
			int d = ManhattanDistance(p, checkpoint[j]);
			if (d <= mind) {
				mind = d;
				minpos = j;
			}
		}
		cout << minpos + 1 << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<queue>
#define absi(n) (n>0?(n):-(n))
typedef long long ll;
bool lunlun(ll);
std::queue<ll> qll;
int main(){
  ll K, i, j;
  scanf("%lld",&K);
  for(i=1;i<10;i++){
    qll.push(i);
  }
  for(j=0;j<K;j++){
    i = qll.front();
    qll.pop();
    if(i%10!=0){
      qll.push(i*10+i%10-1);
    }
    qll.push(i*10+i%10);
    if(i%10!=9){
      qll.push(i*10+i%10+1);
    }
  }
  printf("%lld",i);

  //for(i=1;;){
  //  if(lunlun(i)){
  //    j++;
  //    if(j == K){
  //      printf("%lld",i);
  //      return 0;
  //    }
  //  }
  //}
}

bool lunlun(ll X){
  int d, od;
  od = X%10;
  X = X/10;
  while(X!=0){
    d = X%10;
    if(absi(d-od) > 1){
      return false;
    }
    od = d;
    X = X/10;
  }
  return true;
}

Measured memory_bytes: 1792
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<string>
#include<utility>
#include<map>
#include<set>
#include<queue>
#include<stack>
#include<functional>
#include<math.h>
#include<random>
#include <bitset>
#include <cassert>
#include <complex>
using namespace std;
//#define N (1000000000+7)
//#define N 998244353
#define INF 1e16
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<int,P> Q;
#include<complex>
struct FFT{
    using CP = complex<double>;
    const double PI = acos(-1);
    int base = 1;
    vector<CP> roots{CP(0,0),CP(1,0)};
    vector<int> rv{0,1};
    FFT(){}
    void ensure_base(int nb){
        if(nb<=base)return;
        rv.resize(1<<nb);
        roots.resize(1<<nb);
        for(int i=0;i<(1<<nb);++i){
            rv[i] = (rv[i>>1] >> 1)+((i&1)<<(nb-1));
        }
        while(base<nb){
            double arg = PI*2.0/(1<<(base+1));
            for(int i=1<<(base-1);i<(1<<base);++i){
                roots[i<<1]=roots[i];
                double narg = arg*(2*i+1-(1<<base));
                roots[(i<<1)+1]=CP(cos(narg),sin(narg));
            }
            ++base;
        }
    }
    void fft(vector<CP> &a,int n,bool sg = 0){
        assert((n&(n-1))==0);
        for(int i=0;i<n;++i){
            if(i<rv[i])swap(a[i],a[rv[i]]);
        }
        for(int k=1;k<n;k<<=1){
            for(int i=0;i<n;i+=2*k){
                for(int j=0;j<k;j++){
                    CP z = a[i+j+k]*(sg?roots[j + k] : conj(roots[j + k]));
                    a[i+j+k]=a[i+j]-z;
                    a[i+j]=a[i+j]+z;
                }
            }
        }
        if(sg){
            for(int i=0;i<n;i++)a[i]/=n;
        }
    }
    vector<ll>mul(const vector<int> &a,const vector<int> &b){
        int need = a.size()+b.size()-1;
        int nb = 1;
        while((1<<nb)<need)++nb;
        ensure_base(nb);
        int sz = 1<<nb;
        vector<CP>fa(sz),fb(sz);
        for(int i=0;i<sz;i++){
            if(i<a.size())fa[i]=CP(a[i],0);
            if(i<b.size())fb[i]=CP(b[i],0);
        }
        fft(fa,sz);
        fft(fb,sz);
        for(int i=0;i<sz;i++)fa[i]*=fb[i];
        fft(fa,sz,1);
        vector<ll>res(need);
        for(int i=0;i<need;i++)res[i]=llround(fa[i].real());
        return res;
    }
};

const int p = 200003;

int main() {
    int n;
    cin>>n;
    vector<ll>cnt(p);
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        cnt[a]++;
    }
    int now = 2;
    vector<int> memo(1,1),tmp(p);
    for(int i=1;i<p;i++){
        tmp[i]=cnt[now];
        memo.push_back(now);
        (now<<= 1)%= p;
    }
    for(int i=0;i<p;i++){
        memo.push_back(now);
        (now<<=1)%=p;
    }
    FFT fft;
    auto A = fft.mul(tmp,tmp);
    ll ans = 0;
    for(ll i=0;i<2*p;i++){
        ans+=A[i]*memo[i];
        if(i<p)ans-=cnt[i]*((i*i)%p);
    }
    cout<<ans/2<<endl;
}


Measured memory_bytes: 37344
#include<stdio.h>
#include<bitset>
int main()
{
	int h,w,n,x,i,j,s;
	std::bitset<1001>b[1001];
	while(scanf("%d%d%d",&h,&w,&n),n)
	{
		int a[2][1001]={0};
		for(i=0;i<h;++i)for(j=0;j<w;++j)scanf("%d",&x),b[i][j]=x;
		a[0][0]=n-1;
		for(s=i=0;i<h;++i,s=!s)for(j=0;j<w;++j)
		{
			a[s][j+1]+=(a[s][j]+b[i][j])/2;
			a[!s][j]=(a[s][j]+!b[i][j])/2;
			if(a[s][j]&1)b[i].flip(j);
		}
		for(i=j=0;i<h&&j<w;)
		{
			if(b[i][j])++j;
			else ++i;
		}
		printf("%d %d\n",i+1,j+1);
	}
	return 0;
}

Measured memory_bytes: 896
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using P = pair<ll, ll>;
const ll INF = 1e18;
#define print(x) cout << (x) << endl;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<pair<int,int>> vec;
    for (int i = 0; i < N; i++) {
        int B, A;
        cin >> B >> A;
        vec.push_back(make_pair(A, B));
    }
    sort(vec.begin(), vec.end());
    ll time = 0;
    ll task = 0;
    string answer = "Yes";
    for (int i = 0; i < N; i++) {
        task = vec.at(i).first;
        time += vec.at(i).second;
        if(task < time) answer = "No";
    }
    print(answer);
}

Measured memory_bytes: 2420
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner stdIn = new Scanner(System.in);

		int N = stdIn.nextInt();

		if(N % 2 == 0)
		{
			System.out.println(N);
		}
		else
		{
			System.out.println(N*2);
		}

	}

}


Measured memory_bytes: 35608
# ABC116b
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

s = int(input())


def f(n):
    if(n % 2 == 0):
        return n//2
    else:
        return 3*n+1


a = [0, s]

for i in range(2, 10**6):
    num = f(a[i-1])
    a.append(num)
    idx = a.index(num)
    #print(a)
    if(idx+1 < i):
        print(i)
        exit()

Measured memory_bytes: 3064
# -*- coding: utf-8 -*-


def main():
    """Function."""
    a, b, c = map(int, input().split())

    check = set()
    temp = a
    flag = 0
    while temp % b not in check:
        if c in check:
            flag = 1
            break
        else:
            check.add(temp % b)
            temp = temp + a

    if flag == 1:
        print("YES")
    else:
        print("NO")


if __name__ == "__main__":
    main()


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int main(){
    int n,k;
    cin>>n>>k;
    vector<int>v(n);
    for(int i=0;i<n;i++)
    {
        cin>>v[i];
    }
    sort(v.begin(),v.end());
    int i=0;
    vector<pair<int,int>>vp;
    while(i<v.size()){
        int prev=v[i];
        int count=0;
        while((i<n)&&(prev==v[i]))
        {
            i++;
            count++;
        }
        vp.push_back({count,prev});
    }
    sort(vp.begin(),vp.end());
    int count=0;
    for(auto it=vp.rbegin();it!=vp.rend();it++)
    {
        if(k>0)
        count+=it->first;
        else
        break;
        k--;
    }
    cout<<n-count;
}

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

int main() {
    string s; cin >> s;
    int cnt = 0;
    for (int i = 0; i < s.size()-1; i++)
    {
        if(s[i]==s[i+1])cnt++;
        else cnt = 0;
        if(cnt==2){
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>                                                                                                              
using namespace std;
using pint = pair<int, int>;
int N;
vector<vector<pint>> v;

bool judge(int hoge){
        for(int i = 0; i < N; ++i){
                if(!(hoge & (1<<i))) continue;

                for(pint xy : v[i]){
                        if(xy.second == 1 && !(hoge & (1<<xy.first))) return false;
                        if(xy.second == 0 && (hoge & (1<<xy.first)))  return false;
                }
        }
        return true;
}

int main(){
        cin >> N;
        v.resize(N);
        for(int i = 0; i < N; i++){
                int A;  cin >> A;
                v[i].resize(A);
                for(int j = 0; j < A; j++){
                        cin >> v[i][j].first >> v[i][j].second;
                        --v[i][j].first; //０からはじまるから
                }
        }

        int ans = 0;
        for(int bit = 0; bit < (1<<N); bit++){
                int count = 0;
                if(judge(bit)){
                        for(int i = 0; i < N; ++i){
                                if(bit & (1<<i)) count++;
                        }
                }
                          ans = max(ans, count);
        }
        
        cout << ans << endl;
        return 0;
}     

Measured memory_bytes: 256
import sys
input=sys.stdin.readline
h, w, d = map(int, input().split())
p = dict()

for i in range(h):
    for j, x in enumerate(map(int, input().split())):
        p[x] = (i, j)

dp = [0]*(h*w+1)
for i in range(h*w+1):
    if d < i:
        dp[i] = dp[i-d] + abs(p[i][0]-p[i-d][0])+abs(p[i][1]-p[i-d][1])

q = int(input())
for i in range(q):
    a, b = map(int, input().split())
    ans = dp[b]-dp[a]
    print(ans)


Measured memory_bytes: 64088
#include<iostream>
#include<cmath>
#include<algorithm>

using namespace std;

int main(void){

  long long X,K,D,ans;

  cin >> X >> K >> D;

  X = fabs(X);

  long long t = min(X/D,K);

  X = X - D*t;
  K = K - t;

  if(K == 0 || K%2 == 0){
    ans = X;
    cout << ans << endl;
    return 0;
  }

  else{
    ans = fabs(D-X);
    cout << ans << endl;
    return 0;
  }

}


Measured memory_bytes: 3640
#define _GLIBCXX_DEBUG
#include"bits/stdc++.h"

using namespace std;

//loops
#define REP(i,n) for(int i=0;i<(ll)(n);i++)
#define REPD(i,n) for(int i=(ll)(n)-1;i>=0;i--)
#define OneToN(i,n) for(int i=1;i<(ll)(n+1);i++)
#define ZeroToN(i,n) for(int i=0;i<(ll)(n+1);i++)
#define FOR(i,a,b) for(int i=(a);i<=(b);i++)
#define FORD(i,a,b) for(int i=(a);i>=(b);i--)

//arrays
#define ALL(x) (x).begin(),(x).end() //sortなどの引数を省略したい
#define SIZE(x) ((ll)(x).size()) //sizeをsize_tからllに直しておく
#define add push_back

#define remove_unique(v) v.erase(unique(ALL(v)), v.end())

//pair
#define fir first
#define sec second

//types
#define ll long long
#define vec vector
//UNCOMMENT WHEN NEEDED
//#define int ll

//input
template <class T> T get(){ T s; cin >> s; return(s);}
#define gi get<int>()
#define gs get<string>()

template <class T> vector<T> getv(int n) { vec<T> v(n); REP(i, n) cin >> v[i]; return v; }
#define gim(n) getv<int>(n)
#define gsm(n) getv<string>(n)

//output
void print(int a){ cout << a << endl; }
void print(string a){ cout << a << endl; }
void print(double a, int dig){ cout << std::setprecision(dig) << a << endl; }

template <class T = int>
void print(vec<T> v){ for (T item: v) { cout << item << " "; } cout << endl; }

void YesNo1(bool i = true){ return print(i?"Yes":"No"); }
void YESNO2(bool i = true){ return print(i?"YES":"NO"); }

//debug output
#define var_name(var) #var
template <class T> void debug(T &var, int nest = 0, string before = "") { cout << string("          ", nest) << before; print(var); }

//name replacement
#define y0 y0__
#define y1 y1__
#define j0 j0__
#define j1 j1__
#define next next__
#define prev prev__

//bool lambdas
#define lamb(exp) [](auto i){return exp;}
#define isEven [](int i){return i % 2 == 0;}
#define isOdd [](int i){return i % 2 != 0;}

//constants
const ll INF = 1e18;
const int MOD = 10000007;

void Main() {
    //code here
    string s = gs;
    vec<string> words = {"dream", "dreamer", "erase", "eraser"};
    bool cont = true;
    while (cont) {
        cont = false;
        for (string word: words) {
            if (s.size() >= word.size()) {
                if (s.substr(s.size()-word.size(), word.size()) == word) {
                    s = s.substr(0, s.size() - word.size());
                    cont = true;
                }
            }
        }
    }
    YESNO2(s == "");
    //debug(s);
}

signed main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    Main();
}

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

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

    long long count_t = 0;
    long long count_s = 0;
    for(long long i = 0; i < x.size(); i++){
        if(x[i] == 'S'){
            count_s++;
        }
        else{
            if(count_s > 0){
                count_s--;
            }
            else{
                count_t++;
            }
        }
    }

    cout << count_t + count_s << endl;

    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define faster_io ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef long long ll;
#define bug(a)       cerr << #a << " : " << a << endl;
template<class T>void ExEuclid(T n, T m, T &a, T &b, T &gcd){if(m==0){gcd=n;a=1;b=0;return;}ExEuclid(m,n%m,a,b,gcd);T x=a;a=b;b=x-(n/m)*a;}
template<class T>T gcd(T n, T m){if(m==0){return n;}gcd(m,n%m);}
template<class T>T lcm(T n, T m){return (n*m)/gcd(n,m);}
template<class T>string to_string(T n){string s="";while(n)s+=((n%10)+'0'),n/=10;reverse(s.begin(),s.end());return s;}
template<class T>ll to_int(T s){ll num=0,power=0;for(int i=s.size()-1; i>=0; i--)num+=(pow(10.0,power++)*(s[i]-'0'));return num;}
template<class T>bool is_mod(T n, T m){if(n%m==0)return true;return false;}
template<class T>bool is_upper(T s){for(int i=0; i<s.size(); i++)if(s[i]>90 || s[i]<65)return false;return true;}
template<class T>bool is_lower(T s){for(int i=0; i<s.size(); i++)if(s[i]>122 || s[i]<97)return false;return true;}
template<class T>T mod(T n, T m){return ((n%m)+m)%m;}
template<class T>T Big_mod(T base, T power, T MOD){
    if(power==1)return base;
    if(power & 1)return ((base%MOD)*(Big_mod(base,power-1,MOD))%MOD)%MOD;
    else {T temp=(Big_mod(base,power>>1,MOD));return ((temp%MOD)*(temp%MOD))%MOD;}
}



int main()
{
    //freopen("in.txt","r",stdin);
    //freopen("out.txt","w",stdout);
    faster_io;
    int n,m;
    cin>>n>>m;
    vector<int>a[n+5];
    for(int i=0; i<n; i++){
        int k,x;
        cin>>k;
        for(int j=0; j<k; j++){
            cin>>x;
            a[i].push_back(x);
        }
        sort(a[i].begin(),a[i].end());
    }
    ///cout<<endl;
//    for(int i=0; i<n; i++){
//        for(int j=0; j<a[i].size(); j++)cout<<a[i][j]<<" ";
//        cout<<endl;
//    }
    int cnt=0;
    for(int i=1; i<=m; i++){
        int j=0;
        for(j=0; j<n; ++j){
            if(!binary_search(a[j].begin(),a[j].end(),i))break;
            if(j==n-1)cnt++;
        }

    }
    cout<<cnt<<endl;

    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
/**  I'm Klaus, NicKlaus :v **/
using namespace std;
#define ms(a,v) memset(a,v,sizeof a)
#define ll long long
#define LOG2(X) ((unsigned) (8*sizeof(int) - __builtin_clz((X)) - 1))
ll gcd(ll x, ll y){return (y ? gcd(y, x%y) : x); }
ll lcm(ll x, ll y){return x*(y/gcd(x,y));}
//~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
int main(){
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	#ifdef LOCAL_JUDGE
		//freopen("in_out/in.txt", "rt", stdin);
		//freopen("int_out/out.txt", "wt", stdout);
	#endif
	bool f = true;
	string s;
	cin>>s;
	for(int i=1; i<=s.size(); i++){
		if(s[i-1] == 'L' && i&1) f= false;
		if(s[i-1] == 'R' && !(i&1)) f= false;
	}
	cout<<(f ? "Yes" : "No")<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int L = sc.nextInt();
        int res=0;
        if(L>=0){
            res = (N+2*L)*(N-1)/2;
        }else if(L+N-1>=0){
            res = N*(2*L+N-1)/2;
        }else{
            res = N*(2*L+N-1)/2 - (L+N-1);
        }
        
        System.out.println(res);
        
        }
    }

Measured memory_bytes: 35396
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        InputReader in = new InputReader(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        Task solver = new Task();
        solver.solve(in, out);
        out.close();
    }

    static class Task {
        void solve(InputReader in, PrintWriter out) {
            // write your code here
            int N = in.nextInt();
            int ans = N;

            for (int i = 0; i <= N; i++) {
                int min = 0;
                int payBy6 = i;
                while (payBy6 > 0) {
                    min += payBy6 % 6;
                    payBy6 /= 6;
                }
                int payBy9 = N - i;
                while (payBy9 > 0) {
                    min += payBy9 % 9;
                    payBy9 /= 9;
                }
                ans = Math.min(ans, min);
            }

            out.println(ans);
        }
    }

    static class InputReader {
        BufferedReader reader;
        StringTokenizer tokenizer;

        InputReader(InputStream stream) {
            reader = new BufferedReader(new InputStreamReader(stream));
            tokenizer = null;
        }

        String next() {
            while (tokenizer == null || !tokenizer.hasMoreTokens()) {
                try {
                    tokenizer = new StringTokenizer(reader.readLine());
                } catch (IOException e) {
                    throw new RuntimeException(e);
                }
            }
            return tokenizer.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }
    }
}

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

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

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

    // start
    int n, k, res = 0;
    cin >> n >> k;
    vector<int> l(n);
    rep(i, n) cin >> l.at(i);
    sort(all(l));
    reverse(all(l));
    rep(i, k) res += l.at(i);
    cout << res << endl;
    // end

    return 0;
}


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

using namespace std;
int main(){
    long long N;
    vector<long long> v(5);

    for(auto &x:v){
        cin>>x;
    }
    long long ans=0;
    vector<long long> tes;
    long max=0;

    for(int i=1;i<5;++i){
        if((v[max]%10)>(v[i]%10)&&v[i]%10!=0){
            max=i;
        }
    }


    for(int i=0;i<5;++i){
        if(max==i){
            ans+=v[i];
        }else{
            if(v[i]%10==0){
                ans+=v[i];
            }else{
                ans+=v[i]+(10-v[i]%10);
            }
        }
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define mod pow(10,9)+7
#define pb push_back
#define ff first
#define ss second
#define ii pair<int,int>
#define vi vector<int>

#define mii map<int,int>
#define int long long
#define inf 2000000000000000000
#define re(i,x,n) for(i=x;i<=n;i++)

using namespace std;
#define int long long
void c_p_c()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef  ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif
}
// struct edge
// {
// 	int a;
// 	int b;
// 	int w;
// };
// edge ar[100000];
// int par[10001];
// bool comp(edge a, edge b)
// {
// 	if (a.w < b.w)
// 		return true;
// 	else
// 		return false;
// }
// int find(int a)
// {
// 	if (par[a] == -1)
// 		return a;
// 	else
// 		return par[a] = find(par[a]);
// }
// void merge(int a, int b)
// {
// 	par[a] = b;
// }
//
int maxProductSubarrayOfSizeK(int A[], int n, int k)
{
	// sorting given input array
	sort(A, A + n);

	// variable to store final product of all element
	// of sub-sequence of size k
	int product = 1;

	// CASE I
	// If max element is 0 and
	// k is odd then max product will be 0
	if (A[n - 1] == 0 && (k & 1))
		return 0;

	// CASE II
	// If all elements are negative and
	// k is odd then max product will be
	// product of rightmost-subarray of size k
	if (A[n - 1] <= 0 && (k & 1)) {
		for (int i = n - 1; i >= n - k; i--)
			product *= A[i];
		return product;
	}

	// else
	// i is current left pointer index
	int i = 0;

	// j is current right pointer index
	int j = n - 1;

	// CASE III
	// if k is odd and rightmost element in
	// sorted array is positive then it
	// must come in subsequence
	// Multiplying A[j] with product and
	// correspondingly changing j
	if (k & 1) {
		product *= A[j];
		j--;
		k--;
	}

	// CASE IV
	// Now k is even
	// Now we deal with pairs
	// Each time a pair is multiplied to product
	// ie.. two elements are added to subsequence each time
	// Effectively k becomes half
	// Hence, k >>= 1 means k /= 2
	k >>= 1;

	// Now finding k corresponding pairs
	// to get maximum possible value of product
	for (int itr = 0; itr < k; itr++) {

		// product from left pointers
		int left_product = A[i] * A[i + 1];

		// product from right pointers
		int right_product = A[j] * A[j - 1];

		// Taking the max product from two choices
		// Correspondingly changing the pointer's position
		if (left_product > right_product) {
			product *= left_product;
			i += 2;
		}
		else {
			product *= right_product;
			j -= 2;
		}
	}

	// Finally return product
	return product;
}
int32_t main()
{

	

	int n;
	cin >> n;
	double a[n];
	int i;
	double sum = 0;
	for (i = 0; i < n; i++)
		cin >> a[i];

	for (i = 0; i < n; i++)
	{
		sum += (1 / a[i]);
	}
	cout << 1 / sum;


}


Measured memory_bytes: 3656
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
string a,b;
int main()
{
    cin>>a;
    b=a;
    reverse(b.begin(),b.end());
    for(int i=0;i<b.size();i++)
    {
        if(b[i]=='b') b[i]='d';
        else if(b[i]=='d') b[i]='b';
        else if(b[i]=='p') b[i]='q';
        else if(b[i]=='q') b[i]='p';
    }
    a==b ? cout<<"Yes\n":cout<<"No\n";
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define inf 1000000005
#define all(a) (a).begin(), (a).end()
#define ms(a,x) memset(a, x, sizeof(a))
#define mod 1000000007
#define sz(a) ((ll)(a).size())

template<class T> int getbit(T s, int i) { return (s >> i) & 1; }
template<class T> T onbit(T s, int i) { return s | (T(1) << i); }
template<class T> T offbit(T s, int i) { return s & (~(T(1) << i)); }
template<class T> int cntbit(T s) { return __builtin_popcount(s);}
#define Rep(i,n) for(int i = 0; i < (n); ++i)
#define Repd(i,n) for(int i = (n)-1; i >= 0; --i)
#define For(i,a,b) for(int i = (a); i <= (b); ++i)
#define Ford(i,a,b) for(int i = (a); i >= (b); --i)

typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define eps 1e-9
typedef pair<int, int> II;
typedef pair<ll, ll> LL;
template<class T> T gcd(T a, T b){ T r; while (b != 0) { r = a % b; a = b; b = r; } return a;}
template<class T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define PI (2 * acos((ld)0))
#define linf (1ll << 60)
#define y1 y32432
#define y0 y435346

#define maxn 505

int a[maxn * maxn], x[maxn], flag[maxn * maxn], d[maxn * maxn];
int num[maxn], n;

bool lonhon(II P0, II P1){
	return P0.fi * 1ll * P1.se > P0.se * 1ll * P1.fi;
}

int main()
{
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(0);
    cin.tie(0);

    cin >> n;
    ms(x, 0);
    For(i, 1, n){
    	cin >> x[i];
    	flag[x[i]] = i;
    }

    d[0] = 0;
    For(i, 1, n * n) d[i] = d[i - 1] + (flag[i] != 0);

    bool ok = true; ms(num, 0);
    For(i, 1, n * n){
    	ll Max = inf;
    	int vt = 1;
    	For(j, 1, n){
    		ll P;
    		if(x[j] > i) {
    			if(num[j] + 1 == j) P = inf;
    			else P = x[j] - i - (d[x[j] - 1] - d[i - 1]) - (j - num[j] - 1);
    		}
    		else if(x[j] == i) P = -1;
    		else P = num[j] + 100000000;
    		if(P < Max){
    			Max = P;
    			vt = j;
    		}
    	}

    	a[i] = vt;
    	num[vt]++;
//    	cout << i << " " << vt << endl;
    	if(flag[i]){
    		if(flag[i] != vt || num[vt] != vt){
    			ok = false;
    		}
    	}
    }
    For(i, 1, n) if(num[i] != n) ok = false;
    if(!ok){
    	cout << "No" << endl;
    } else{
    	cout << "Yes" << endl;
    	For(i, 1, n * n) cout << a[i] << " ";
    }

    return 0;
}


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

bool check(string s, string t){
    int n = s.length();

    for(int i = 0; i < n; i++){
        if(s[i] == 'o'){
            if(t[i] == 'S' && t[(i+n-1)%n] != t[(i+1)%n])   return false;
            if(t[i] == 'W' && t[(i+n-1)%n] == t[(i+1)%n])   return false;
        }
        if(s[i] == 'x'){
            if(t[i] == 'S' && t[(i+n-1)%n] == t[(i+1)%n])   return false;
            if(t[i] == 'W' && t[(i+n-1)%n] != t[(i+1)%n])   return false;
        }
    }

    return true;
}

int main(){
    int n;
    string s;

    cin >> n >> s;

    string ans = "-1";

    for(int i = 0; i < 2; i++){
        for(int j = 0; j < 2; j++){
            string tmp = "";
            if(i == 0)  tmp.push_back('S');
            else        tmp.push_back('W');
            if(j == 0)  tmp.push_back('S');
            else        tmp.push_back('W');
            for(int k = 1; k < n-1; k++){
                if(tmp[k] == 'S'){
                    if(s[k] == 'o')   tmp.push_back(tmp[k-1]);
                    else              tmp.push_back((tmp[k-1] == 'S' ? 'W' : 'S'));
                }else if(tmp[k] == 'W'){
                    if(s[k] == 'o')   tmp.push_back((tmp[k-1] == 'S' ? 'W' : 'S'));
                    else              tmp.push_back(tmp[k-1]);
                }
            }

            if(check(s, tmp)){
                ans = tmp;
                break;
            }
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 872
function update(dp,i,k)
  for j=1:k,l=1:k
    if j==l;continue;end
    dp[i,j]+=dp[i-1,l]
  end
  true
end
function main()
  n,k=parse.(split(readline()))
  dp=zeros(Int,n,k)
  for j=1:k;dp[1,j]=1;end
  for i=2:n
    update(dp,i,k)
  end
  print(sum(dp[n,:]))
end
main()

Measured memory_bytes: 130864
#include <bits/stdc++.h>
#define int long long
using namespace std;

int n,ans=0,last;
int rt[200005],b[200005];

struct node
{
	int rt;
	int num;
}a[200005];

bool cmp(node a,node b)
{
	return a.num<b.num;
}

int Binary_search2(int l,int r,int k)//找到最后一个等于k的b序列中的数 
{
	if (l>r)  return last;
	if (l==r||l+1==r)
	{
		if (b[l]==k)  return min(l,last);
		if (b[r]==k)  return min(r,last);
		else return last;
	}
	int mid=(l+r)>>1;
	if (b[mid]>=k)
	{
		if (b[mid]==k)  last=mid;
		return Binary_search2(l,mid,k);
	}
	if (b[mid]<k)  return Binary_search2(mid,r,k);
}

int Binary_search(int l,int r,int k)//找到最后一个等于k的b序列中的数 
{
	if (l>r)  return last;
	if (l==r||l+1==r)
	{
		if (b[r]==k)  return max(r,last);
		if (b[l]==k)  return max(l,last);
		else return last;
	}
	int mid=(l+r)>>1;
	if (b[mid]<=k)
	{
		if (b[mid]==k)  last=mid;
		return Binary_search(mid,r,k);
	}
	else if (b[mid]>k)  return Binary_search(l,mid,k);
} 

signed main()
{
	cin>>n;
	for (int i=1;i<=n;i++)
	{
		cin>>a[i].num;
		a[i].rt=i;
		a[i].num-=(i-1);
	}
	sort(a+1,a+n+1,cmp);
	
	for (int i=1;i<=n;i++)  rt[a[i].rt]=i;
	for (int i=1;i<=n;i++)  b[i]=a[i].num;
	for (int i=1;i<=n;i++)
	{
		int now=rt[i],sum=2-i*2;
		last=1e9+7;
		int p1=Binary_search2(1,now,sum-b[now]);
		last=-1;
		int p2=Binary_search(1,now-1,sum-b[now]);
		last=1e9+7;
		int p3=Binary_search2(now+1,n,sum-b[now]);
		last=-1;
		int p4=Binary_search(now+1,n,sum-b[now]);
		
		if (p1!=1e9+7&&b[p1]+b[now]==sum)  ans+=(p2-p1)+1;
		if (p3!=1e9+7&&b[p3]+b[now]==sum)  ans+=(p4-p3)+1;
	}
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 9840
X, Y = map(int, input().split())

#print(X, Y)

if Y < 2 * X:
    print('No')
    exit()
elif Y > 4 * X:
    print('No')
    exit()

y = (Y - 2 * X)

#print(y, y / 2)
if y >= 0 and (y % 2 == 0):
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9208
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
const ll INF=1001001001;
const ll LINF=1001001001001001001;
#define overload4(_1,_2,_3,_4,name,...) name
#define rep1(n) for(ll i=0;i<(n);++i)
#define rep2(i,n) for(ll i=0;i<(n);++i)
#define rep3(i,a,b) for(ll i=(a);i<(b);++i)
#define rep4(i,a,b,c) for(ll i=(a);i<(b);i+=(c))
#define rep(...) overload4(__VA_ARGS__,rep4,rep3,rep2,rep1)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define vec vector<ll>
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;}

void solve(){
    string s;cin>>s;
    ll ans=0;
    rep(i,3)if(s[i]=='1')ans++;
    cout<<ans<<endl;
}

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


Measured memory_bytes: 256
#include<iostream>
#include<vector>
using namespace std;
int main(){
	int N,M,k,S,p[10],pre,sum,res=0;
	bool flag;
	vector<int> s[10];
	cin>>N>>M;
	for(int i=0;i<M;i++){
		cin>>k;
		for(int j=0;j<k;j++){
			cin>>S;
			s[i].push_back(S-1);
		}
	}
	for(int i=0;i<M;i++)cin>>p[i];
	for(int i=0;i<(1<<N);i++){
		flag=true;
		for(int j=0;j<M;j++){
			sum=0;
			for(int l:s[j])sum+=(i&(1<<l))>0;
			flag &= sum%2==p[j];
		}
		res+=flag;
	}
	cout<<res;
	return 0;
}

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

int main(){
    int a[4], b[4];
    
    while(cin >> a[0] >> a[1] >> a[2] >> a[3] >> b[0] >> b[1] >> b[2] >> b[3]){
        int hit = 0, blow = 0;
        
        for(int i = 0;i < 4;i++){
            for(int j = 0;j < 4;j++){
                if(a[i] == b[j]){
                    if(i == j){
                        hit++;
                    }else{
                        blow++;
                    }
                }
            }
        }
        
        cout << hit << " " << blow << endl;
    }
          
    return 0;
}

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

int cnt = 0;
int idx = 0;
int G[100] = {0};

void insertionSort(int a[], int n, int g){

    for(int i=g; i<n; ++i){
        int tmp = a[i];
        int j = i - g;
        while(j>=0 && a[j]>tmp){
            a[j+g] = a[j];
            j = j - g;
            cnt++;
        }
        a[j+g] = tmp;
    }
}

void shellSort(int a[], int n){
    
    for(int i=1; i<=n; i=3*i+1){
        int tmp = idx;
        while(tmp>0){
            G[tmp] = G[tmp-1];
            tmp--;
        }
        G[0] = i;
        idx++;
    }

    for(int i=0; i<idx; i++){
        insertionSort(a, n, G[i]);
    }
}

int main()
{
    int n;
    cin >> n;
    int a[1000000];
    rep(i, n){
        cin >> a[i];
    }

    
    shellSort(a, n);

    cout << idx << endl;
    rep(i, idx){
        cout << G[i];
        if(i != idx-1){
            cout << " ";
        }
        else{
            cout << "\n";
        }
    }

    cout << cnt << "\n";

    rep(i, n){
        cout << a[i] << "\n";
    }

    return 0;
}


Measured memory_bytes: 6984