akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef vector<int,vector<int>> vvec;
typedef long double ld;

//----***Like a Pythonista***----
#define REP(i,j,n) for (ll i=j;i<(n);i++)
#define RREP(i,n,j) for (ll i = n; j<i;i--)
#define each(i,...) for(auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(all(__VA_ARGS__),0LL)
#define dsum(...) accumulate(all(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(all(a)); }
template<class T> inline auto min(const T& a){ return *min_element(all(a)); }
inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
#define MOD 1000000007;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***----
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

typedef pair<ll,ll> P;
vector<vector<ll>> DYX{{-1,0},{1,0},{0,-1},{0,1}};

signed main(){
  int N,K,R,S,P;cin>>N>>K>>R>>S>>P;
  string a;
  vector<vector<char>> v(K,vector<char>(N/K+3,'e'));
  cin>>a;
  REP(i,K,N+K){
    char tmp=a.at(i-K);
    if(tmp=='r'){v[i%K][i/K]='p';}
    if(tmp=='s'){v[i%K][i/K]='r';}
    if(tmp=='p'){v[i%K][i/K]='s';}
  }
  int ans=0;
  REP(i,0,K){
    char bf='b';
    REP(k,1,N/K+2){
      if(v[i][k]==bf){
        bf='b';
      }
      else{
        if(v[i][k]=='r'){ans+=R;bf='r';}
        if(v[i][k]=='s'){ans+=S;bf='s';}
        if(v[i][k]=='p'){ans+=P;bf='p';}
      }
    }
  }
  print(ans)

}


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

// ----------- define --------------
#define int long long
#define ii pair<int,int>
#define fi first
#define sc second
#define all(x) (x).begin(),(x).end()
// ---------------------------------

void MAIN() {
  int n, m;
  cin >> n >> m;
  vector<int> a(m);
  for (auto &i : a) cin >> i;
  sort(all(a));
  vector<int> v;
  int s = 0;
  for (int i = 1; i < m; i++) {
    v.push_back(a[i] - a[i - 1]);
    s += v.back();
  }
  sort(all(v), greater<int>());
  for (int i = 0; i < min(n - 1, m - 1); i++) {
    s -= v[i];
  }
  cout << s << '\n';
}

signed main() {
  ios::sync_with_stdio(0); cin.tie(0);
  int T = 1;
  // cin >> T;
  while (T--) MAIN();
}


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

using namespace std;

//#define FILE_IO

int N, M;
int per[100005][2];
bool can[405];
bitset<405> f[405];

int main()
{
    #ifdef FILE_IO
    freopen("1.in", "r", stdin);
    freopen("1.out", "w", stdout);
    #endif

    cin >> N >> M;
    for(int i = 1; i <= M; i++)
    {
        int x, y;
        cin >> x >> y;
        per[i][0] = x; per[i][1] = y;
    }

    for(int i = 1; i <= N; i++)
    {
        f[i][i] = 1;
        can[i] = true;
        for(int j = M; j >= 1; j--)
        {
            int x = per[j][0], y = per[j][1];

            if(f[i][x] && f[i][y]) { can[i] = false; break; }
            if(!f[i][x] && !f[i][y])    continue;

            if(f[i][y]) swap(x, y);
            f[i][y] = 1;
        }
    }

    int ans = 0;
    for(int i = 1; i <= N; i++)
        if(can[i])
            for(int j = i + 1; j <= N; j++)
                if(can[j])
                {
                    auto x = f[i] & f[j];
                    if(x.count() == 0)  ans++;
                }
    cout << ans;

    return 0;
}


Measured memory_bytes: 1024
#include "bits/stdc++.h"

using namespace std;

void solve(void)
{
	int n;
	cin >> n;
	vector<int> ps(n);
	for (int i = 0; i < n; i++)
	{
		cin >> ps[i];
	}
	int ans = 0;
	for (int i = 0; i + 2 < n; i++)
	{
		if (ps[i+1] < *max_element(ps.begin()+i, ps.begin()+i+3) && ps[i+1] > *min_element(ps.begin()+i, ps.begin()+i+3))
		{
			ans++;
		}
	}
	cout << ans << endl;
}

int main()
{
	solve();
	//cout << "yui(*-v・)yui" << endl;
	return 0;
}


Measured memory_bytes: 256
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "unordered_map"
#include "unordered_set"
#include "iomanip"
#include "cmath"
#include "random"
#include "bitset"
#include "cstdio"
#include "numeric"
#include "ctime"

using namespace std;

const long long int MOD = 1000000007;
//const int MOD = 998244353;

//long long int N, M, K, H, W, L, R;
long long int N, M, K, H, W, L, R;



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

	cin >> N >> K;
	vector<long long int>v(N);
	for (auto &i : v)cin >> i;
	auto w = v;
	auto a = v;
	if (N % 2) {
		for (int i = 2; i < N; i += 2)v[i] += v[i - 2];
	}
	else {
		for (int i = 3; i < N; i += 2)v[i] += v[i - 2];
	}
	for (int i = N - 2; i >= 0; i--) {
		w[i] += w[i + 1];
	}
	vector<pair<int,int>>query(K);
	for (int i = 0; i < K; i++) {
		cin >> query[i].first;
		query[i].second = i;
	}
	vector<long long int>ans(K);
	sort(query.begin(), query.end(), greater<pair<int, int>>());
	int con = 0;
	for (auto i : query) {
		int cn = i.first;
		while (N - con * 2 - 3 >= 0) {
			R = N - con - 2;
			L = R - con - 1;
			if (abs(cn - a[L]) > abs(cn - a[R]))break;
			else con++;
		}
	//	cout << cn << "# " << con << endl;
		ans[i.second] = w[N - 1 - con];
		if (N % 2) {
			if(N-3-con*2>=0)ans[i.second] += v[N - 3 - con * 2];
		}
		else {
			if (N - 3 - con * 2 >= 0)ans[i.second] += v[N - 3 - con * 2];
		}
	}
	for (auto i : ans)cout << i << endl;
	return 0;
}

Measured memory_bytes: 5632
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < n; i++)
#define vi vector<int>
#define vvi vector<vi>
#define pii pair<int, int>
#define mod 1000000007
using ll = long long;
using namespace std;
int main(){
  int n,m;
  cin >> n >> m;
  vector<bool> checked(n, false);
  vi miss(n);
  int penalty = 0;
  int ans = 0;
  rep(i, m){
    int p;
    string s;
    cin >> p >> s;
    p--;
    if(s == "AC"){
      if(!checked[p]){
        ans++;
        checked[p] = true;
        penalty += miss[p];
      }
    }else{
      if(!checked[p]) miss[p]++;
    }
  }
  cout << ans << " " << penalty << endl;
}

Measured memory_bytes: 640
#include <algorithm>
#include <cmath>
#include <iostream>
#include <set>
#include <vector>
using namespace std;

int main() {
  int N;
  cin >> N;
  multiset<int> A;
  int atmp;
  while (cin >> atmp) {
    A.insert(atmp);
  }

  int nr_of_pairs = 0;

  while (!A.empty()) {
    auto itr_max = --A.end();
    auto max = *itr_max;
    A.erase(itr_max);
    int i;
    for (i = 1; i <= max; i *= 2);
    if (A.find(i - max) != A.end()) {
      A.erase(A.find(i - max));
      ++nr_of_pairs;
    }
  }

  cout << nr_of_pairs << endl;
  return 0;
}

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

int main() {
  string s,t;
  cin >> s;
  cin >> t;
  int res=0;
  rep(i,s.length()){
    if (s[i]!=t[i]){
      res+=1;
    }
  }
  cout << res << endl;
  return 0;
}


Measured memory_bytes: 3828
#define _USE_MATH_DEFINES
#include <bits/stdc++.h>

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define reps(i, n) for (int i = 1; i <= (n); ++i)
#define repd(i, n) for (int i = (n)-1; i >= 0; --i)
#define repds(i, n) for (int i = (n); i > 0; --i)
#define loop(i, x, n) for (int i = (x); i < (n); ++i)
#define loops(i, x, n) for (int i = (x); i <= (n); ++i)
#define loopd(i, x, n) for (int i = (x); i > (n); --i)
#define loopds(i, x, n) for (int i = (x); i >= (n); --i)
#define itrep(i, a) for (auto i = begin(a); i != end(a); ++i)
#define itrepd(i, a) for (auto i = rbegin(a); i != rend(a); ++i)
#define each(i, x) for (auto &&i : x)
#define all(x) x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define sz(a) ((int)a.size())
#define pow2(n) (n * n)
#define int ll
using namespace std;
using ll = long long;
using ld = long double;
using ull = unsigned long long;
template <class T>
using p_queue = priority_queue<T, vector<T>, greater<T>>;
constexpr ll inf = static_cast<ll>(1e18);
constexpr int iinf = static_cast<int>(1e9);
constexpr double dinf = 1e10;
constexpr ld ldinf = 1e18;
constexpr double eps = 1e-8;
ll mod = static_cast<ll>(1e9 + 7);
template <class T, class... Args>
constexpr void mins(T &a, Args... args) { a = min<T>({a, args...}); }
template <class T, class... Args>
constexpr void maxs(T &a, Args... args) { a = max<T>({a, args...}); }
template <class F>
class FixPoint : private F {
public:
    explicit constexpr FixPoint(F &&f) : F(std::forward<F>(f)) {}
    template <class... Args>
    constexpr decltype(auto) operator()(Args &&... args) const { return F::operator()(*this, std::forward<Args>(args)...); }
};
template <class F>
constexpr decltype(auto) funcs(F &&f) { return FixPoint<F>{std::forward<F>(f)}; }
template <class T>
std::vector<T> vecs(int n, T &&val) { return std::vector<T>(std::forward<int>(n), std::forward<T>(val)); }
template <class... Args>
decltype(auto) vecs(int n, Args &&... args) { return std::vector<decltype(vecs(std::forward<Args>(args)...))>(std::forward<int>(n), vecs(std::forward<Args>(args)...)); }
template <class V, class T>
void fill(V &x, const T &val) { x = val; }
template <class V, class T>
void fill(vector<V> &vec, const T &val) {
    for (auto &&v : vec)
        fill(v, val);
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<ld> a(n);
    rep(i, n) cin >> a[i];

    auto f = [&](int t) {
        int res = 0;
        rep(i, n) {
            int cnt = int(ceil(a[i] / t)) - 1;
            res += cnt;
        }
        return res <= k;
    };

    int l = 0, r = int(1e9 + 5);
    while (r - l > 1) {
        auto mid = (l + r) / 2;
        if (f(mid))
            r = mid;
        else
            l = mid;
    }
    cout << r << endl;
}

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

Measured memory_bytes: 6380
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
#define NUM_OF_CONTESTS 26
int main(){
     int D;
    cin >> D;
    vector<int>c(NUM_OF_CONTESTS);
    REP(i,NUM_OF_CONTESTS)cin >> c[i];

    int s[D][NUM_OF_CONTESTS];
    REP(i,D){REP(j,NUM_OF_CONTESTS){cin >> s[i][j];}}

    REP(i,D){
        int today = 0,remi;
        REP(j,NUM_OF_CONTESTS){
            if(today < s[i][j]){
                today = s[i][j];
                remi = j;
            }
        }
        cout << remi+1 << endl;
    }
    return 0;
}

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

int main() {
    int x1, y1, x2, y2;
	cin >> x1 >> y1 >> x2 >> y2;
	int dx=x2-x1;
	int dy=y2-y1;
	int x=x2;
	int y=y2;
	for (int i=0; i<2; i++){
	    swap(dx, dy);
	    dx=-dx;
	    x+=dx;
	    y+=dy;
	    cout << x << " " << y << " ";
	}
}

Measured memory_bytes: 256
use std::io::*;
use std::str::FromStr;

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("filed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n:usize = read();
    let arr:Vec<usize> = (0..n).map(|_| read()).collect();
    let mut c = arr.clone();
    c.sort();

    let mut cnt = 0;
    for i in 0..n {
        if c[i] != arr[i] {
            cnt += 1;
        }
    }
    if cnt > 2 {
        println!("NO");
    } else {
        println!("YES");
    }
}


Measured memory_bytes: 2172
ar = []
br = [[],[],[]]
cr = [[],[]]
for i in range(3):
    r = list(map(int,input().split(" ")))
    for i in range(3):
        br[i].append(r[i])
    ar.append(r)
cr[0].append(ar[0][0])
cr[0].append(ar[1][1])
cr[0].append(ar[2][2])
cr[1].append(ar[2][0])
cr[1].append(ar[1][1])
cr[1].append(ar[0][2])
a = int(input())
dr = []
for i in range(a):
    l = int(input())
    dr.append(l)
for rr in ar:
    count = 0
    for r in rr:
        if r in dr:
            count += 1
    if count == 3:
        print("Yes")
        exit()
for rr in br:
    count = 0
    for r in rr:
        if r in dr:
            count += 1
    if count == 3:
        print("Yes")
        exit()
for rr in cr:
    count = 0
    for r in rr:
        if r in dr:
            count += 1
    if count == 3:
        print("Yes")
        exit()
print("No")

Measured memory_bytes: 3064
#include<stdio.h>
#include<string.h>
int main(){
  int n,i,count=0,count2=0,m;
  char a[1000],t[10];
    
    scanf("%s",t);
  n=strlen(t);
  
  while(1){
    
    scanf("%s",a);
  m=strlen(a);
  
  if(n==m){
    count=0;
    for(i=0;i<m;i++){
      if(t[i]==a[i] || t[i]+32==a[i] ||t[i]==a[i]+32) count++;
      if(count==m) count2++;
    }
  }
  
  if(a[0]=='E' && a[1]=='N' && a[2]=='D' && a[3]=='_' && a[4]=='O' && a[5]=='F' && a[6]=='_' && a[7]=='T' && a[8]=='E' && a[9]=='X' && a[10]=='T') break;
  }
  
  printf("%d\n",count2);
  
  return 0;
}

Measured memory_bytes: 540
#include<bits/stdc++.h>
#define ll long long
#define REP(i,a,n) for(ll i=a;i<(n);i++)
#define RE return
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    long double n;
    cin>>n;
    cout<<n*6.28;
    RE 0;
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
int n;
const int N= 1e6+5;
int32_t main()
{
    IOS;
    cin>>n;
    int x=1,flag=0;;
    map<int, int>mp;
    vector<int>v(n,0);
    for(int i=0;i<n;i++){
        cin>>v[i];
        mp[v[i]]++;
    }
    if(mp[0]>0)
        cout<<0<<endl;
    else{
        int prod=1, flag=0;;
        for(int i=0;i<n;i++){
            int next= ((1000000000000000000)/prod);
            if(v[i]>next){
                cout<<-1<<endl;
                flag=1;
                break;
            }
            prod*=v[i]; 
        }
        if(flag==0){
            cout<<prod<<endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 10308
import sys
sys.setrecursionlimit(10 ** 7)
read = sys.stdin.buffer.read 
inp = sys.stdin.buffer.readline
def inpS(): return inp().rstrip().decode()
readlines = sys.stdin.buffer.readlines 
MOD = 10**9+7


def resolve():
    def dfs(l, r):
        if r - l == 1:
            dp[l][r] = A[l] + A[r]
            return dp[l][r]

        if dp[l][r] is not None:
            return dp[l][r]

        ret = 1<<60
        for x in range(l,r):
            cost = cum_A[r+1] - cum_A[l]
            ret = min(ret, dfs(l, x) + dfs(x+1, r) + cost)

        dp[l][r] = ret
        return ret

    N = int(input())
    A = list(map(int, input().split()))
    cum_A = [0]*(N+1)
    for i in range(N):
        cum_A[i+1] = cum_A[i] + A[i]

    dp = [[None]*(N+1) for _ in range(N+1)]
    for i in range(N+1):
        dp[i][i] = 0

    return print(dfs(0, N-1))

if __name__ == "__main__":
    resolve()

Measured memory_bytes: 50520
from collections import defaultdict

N = int(input())
nums = list(map(int, input().split()))

counter = defaultdict(list)
for i in range(len(nums)):
  counter[nums[i]].append(i)

total = 0
for _,v in counter.items():
  v = len(v)
  total += (v * (v-1)) // 2

for k in range(len(nums)):
  print(total - (len(counter[nums[k]])-1))

Measured memory_bytes: 39292
#include <iostream>
#include <queue>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>

using namespace std;

#define REP(i,n) for(ll (i) = (0); (i) < (n); ++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define ALL(v) v.begin(),v.end()
#define Decimal fixed << setprecision(20)
#define SHOWP(x) cerr<<"["<<(x).FI<<", "<<(x).SE<<"]";
#define SHOWX(x) cerr<<#x<<": "<<x<<endl;
#define SHOWVEC(v, e) REP(i, e) cerr << (v[i]) << ' '; cerr << endl;
#define SHOW2D(a, h, w) REP(i, h){REP(j, w)cerr<<setw(3)<<(a[i][j])<<' ';cerr<<endl;}
constexpr int INF = 1 << 30 - 1;
constexpr long long LLINF = 1LL << 60;
constexpr long long MOD = 1000000007;

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


int main()
{
  int N;
  cin >> N;
  string S;
  cin >> S;
  int cnt = 1;
  vector<int> b(N, 0), w(N, 0);
  for (int i = 0; i < N; i++) {
    if (i - 1 >= 0)  b[i] = b[i - 1];
    if (S[i] == '#') b[i]++;
  }
  for (int i = N - 1; i >= 0; i--) {
    if (i + 1 < N) w[i] = w[i + 1];
    if (S[i] == '.') w[i]++;
  }
  SHOWVEC(b, b.size());
  SHOWVEC(w, w.size());

  int ans = INF;
  REP(i, N) {
    int sum = w[i];
    if (i - 1 >= 0) sum += b[i-1];
    ans = min(ans, sum);
  }
  ans = min(ans, b[N-1]);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 2180
N, M = map(int,input().split())
a = [] 

for i in range(M):
    a.append(int(input()))
a.sort()
diff = [a[i+1]-a[i] for i in range(M-1)] if M!=1 else []
if diff and min(diff)==1 :
    print(0)
else:
    if M==0:
        stairs = [N]
    elif not(diff):
        stairs = [a[0]-1,N-a[0]-1]
    else :
        stairs = [a[0]-1]+[diff[i]-2 for i in range(M-1)]+[N-a[-1]-1]
    
    t = [1,1]
    for i in range(max(stairs)-1):
        t.append(t[-1]+t[-2])
    ans = 1
    for i in stairs:
        ans *= t[i]
    print(ans%1000000007)

Measured memory_bytes: 460020
fig = input()
a = int(fig[0])
b = int(fig[1])
c = int(fig[2])
d = int(fig[3])

if a + b + c + d == 7:
    op1 = "+"
    op2 = "+"
    op3 = "+"
elif a - b + c + d == 7:
    op1 = "-"
    op2 = "+"
    op3 = "+"
elif a - b - c + d == 7:
    op1 = "-"
    op2 = "-"
    op3 = "+"
elif a - b + c - d == 7:
    op1 = "-"
    op2 = "+"
    op3 = "-"    
elif a + b - c + d == 7:
    op1 = "+"
    op2 = "-"
    op3 = "+"
elif a + b - c - d == 7:
    op1 = "+"
    op2 = "-"
    op3 = "-"
elif a + b + c - d == 7:
    op1 = "+"
    op2 = "+"
    op3 = "-"

print("{0}{1}{2}{3}{4}{5}{6}=7".format(a,op1,b,op2,c,op3,d))

Measured memory_bytes: 3064
#include <cstdio>
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
#include <string>
#include <cmath>
#include <functional>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#define rep(i,n) for (int i=0;i<n;i++)
using ll = long long;
using namespace std;

void solve(){

}
int main (){
    ios::sync_with_stdio(0);
    cin.tie(0);
    string s;
    cin >> s;
    rep(i,s.size()){
        cout << 'x';
    }

    return 0;
}

Measured memory_bytes: 3628
n,m=map(int,input().split())
a=list(map(int,input().split()))
a.sort(reverse=True)
d=[]
for i in range(m):
  if len(a)>0:
    if len(d)==0:
      d.append(a[0]//2)
      a.pop(0)
    else:
      if a[0]>=d[0]:
        d.append(a[0]//2)
        a.pop(0)
      else:
        d.append(d[0]//2)
        d.pop(0)
  else:
    if len(a)==0:
      a.append(d[0]//2)
      d.pop(0)
    else:
      if d[0]>=a[0]:
        a.append(d[0]//2)
        d.pop(0)
      else:
        a.append(d[0]//2)
        a.pop(0)
print(sum(d)+sum(a))

Measured memory_bytes: 14480
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define ppb pop_back
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)>>1)
#define all(x) x.begin(),x.end()
#define dbgs(x) cerr<<(#x)<<" --> "<<(x)<<" "
#define dbg(x) cerr<<(#x)<<" --> "<<(x)<<endl;getchar()
#define pw(x) (1<<(x))
#define inf 1005000000
#define MOD 1000000007
#define N 100005
#define M 1000005
#define LOG 20
#define KOK 32000
using namespace std;

int n,tot;
vector<int> s[1005];

int main() {

	//freopen("input.txt","r",stdin);

	scanf("%d",&n);

	n*=2;

	int sq=sqrt(n);

	if(sq*(sq+1)!=n) {

		printf("No");

	}
	else {

		printf("Yes\n");

		printf("%d\n",sq+1);

		for(int i=1;i<=sq+1;i++) {

			for(int j=i+1;j<=sq+1;j++) {

				++tot;

				s[i].pb(tot);
				s[j].pb(tot);

			}

		}

		for(int i=1;i<=sq+1;i++,puts("")) {

			printf("%d ",sq);
	
			for(auto x:s[i]) printf("%d ",x);
	
		}	

	}

}

Measured memory_bytes: 2304
#include <bits/stdc++.h>
using namespace std;
int INF = 1000000007;

int main(){
  int N, K;
  cin >> N >> K;
  string S;
  cin >> S;
  int A[N] = {};
  bool ans;
  if(S[0] == 'L'){
    ans = true;
  }
  else{
    ans = false;
  }
  int M = 0;
  A[0] = 1;
  int ans2 = 0;
  for(int i=1;i<N;i++){
    if(ans){
      if(S[i] == 'L'){
        A[M]++;
        ans2++;
      }
      else{
        M++;
        ans = false;
        A[M] = 1;
      }
    }
    else{
      if(S[i] == 'R'){
        A[M]++;
        ans2++;
      }
      else{
        M++;
        A[M] = 1;
        ans = true;
      }
    }
  }
  for(int i=0;i<K;i++){
    ans2 += 2;
    if(ans2 >= N-1){
      ans2 = N-1;
      break;
    }
  }
  cout << ans2 << endl;
}

Measured memory_bytes: 896
#include<stdio.h>
#include<algorithm>
using namespace std;

int partition(int* A, int p, int r){
    int x = A[r];
    int i = p-1;
    for(int j=p; j<r; j++){
        if(A[j] <= x){
            i++;
            swap(A[i], A[j]);
        }
    }
    swap(A[i+1], A[r]);
    return i+1;
}

int main(){

    int n;
    scanf("%d", &n);
    int A[100000];
    for(int i=0; i<n; i++) scanf("%d", &A[i]);

    int p = partition(A, 0, n-1);

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

    return 0;
}


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

int main(){
    int n;
    cin >> n;
    vector<long long int> l(n+1);
    l.at(0)=2;
    l.at(1)=1;
    for(int i=0; i<n-1; i++){
        l.at(i+2)=l.at(i)+l.at(i+1);
    }
    cout << l.at(n) << endl;
}

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

#define ll long long
#define vll vector<ll>
#define vvll vector<vll>
#define pii pair<int,int>
template<typename T, typename U> 
static inline void amin(T &x, U y){
	if(x>y)
		x = y;
}
template<typename T, typename U> 
static inline void amax(T &x, U y){
	if(x<y)
		x = y;
}
#define rep(i,n) for(int i = 0; i < n; ++i)
#define irep(i,k,n) for(int i = k; i <= n; ++i)
#define irepr(i,k,n) for(int i = k; i >= n; --i)

int inf = 2e9;
ll INF = 2e18;
const ll mod = 1e9+7;
vvll A;
int n;

void add_self(ll & x,ll y){
	x = (x+y)%mod;
}
ll mul_mod(ll &x,ll &y){
	return (x*y)%mod;
}
vvll mul(vvll x,vvll y){
	int a = x.size(), b = x[0].size(), c = y[0].size();
	vvll ans(a,vll(c,0));
	rep(rx,a){
		rep(cy,c){
			rep(i,b){
				add_self(ans[rx][cy], mul_mod(x[rx][i],y[i][cy]));
			}
		}
	}
	return ans;
}

vvll solve(ll k){
	if(k==1){
		return A;
	}
	vvll x = solve(k/2);
	vvll ret;
	if(k%2==0){
		ret = mul(x,x);
	}else{
		ret = mul(x,x);
		ret = mul(ret,A);
	}
	return ret;
}

int main(){
	ll k;
	cin >> n>> k;
	A.resize(n,vll(n));
	rep(i,n){
		rep(j,n){
			cin >> A[i][j];
		}
	}
	vvll kmat = solve(k);
	ll ans = 0;
	rep(i,n){
		rep(j,n){
			add_self(ans,kmat[i][j]);
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 384
import java.util.*;

public class Main {
    public static void main(final String[] args) {
        final Scanner sc = new Scanner(System.in);
        // 整数の入力
        // final int a = sc.nextInt();
        // 文字列の入力
        // final String s1 = sc.next();
        final double x = sc.nextDouble();
        final int n = sc.nextInt();
        List<Double> ngList = new ArrayList<Double>();
        for (int i = 0; i < n; i++) {
            ngList.add(sc.nextDouble());
        }
        sc.close();
        double diff = 101;
        int result = 0;
        for (int i = 0; i <= 101; i++) {
            if (diff > Math.abs(x - i) && !ngList.contains((double) i)) {
                diff = Math.abs(x - i);
                result = i;
            }

        }
        System.out.println(result);
    }
}


Measured memory_bytes: 37736
#include <stdio.h>
int main()
{
  int a, b, c;
  scanf("%d%d%d",&a,&b,&c);
  if((a==b&&b==c)||(a!=b&&b!=c&&c!=a)) {
    puts("No");
  } else {
    puts("Yes");
  }
  return 0;
}


Measured memory_bytes: 1616
// inputに入力データ全体が入る
function Main(input) {
    var N, M;
    input = input.split("\n");
    input = input[0].split(" ");
    N = input[0];
    M = input[1];
    
    var mod = 1000000000 + 7;
/*    var ret = 1;
    if (N == M || M - N == 1) {
      for (var i = 1; i <= N; i ++) {
        ret *= i;
        ret %= mod;
      }
      for (var i = 1; i <= M; i ++) {
        ret *= i;
        ret %= mod;
      }
      
      if (N == M) {
        ret *= 2;
        ret %= mod;
      }
    } else {
      ret = 0;
    }
    
    console.log(ret)
    */
    
    var result = 1;
    if(Math.abs(N - M) >= 2) {
        console.log(0);
    } else if(Math.abs(N - M) == 1) {
        for(var i = 1; i <= N; i++) {
            result *= i;
            result %= mod;
        }
        
        for(var i = 1; i <= M; i++) {
            result *= i;
            result %= mod;
        }
        
        console.log(result);
    } else if(Math.abs(N - M) == 0) {
        
        result = 1;
        for(var i = 1; i <= N; i++) {
            result *= i;
            result %= mod;
        }
        
        for(var i = 1; i <= M; i++) {
            result *= i;
            result %= mod;
        }
        result *= 2;
        result %= mod;
        
        console.log(result);
    }

}


function factorial(n) {
    var result = 1;
    for (var i = 1; i <= n; i++) {
        result = (result * i) % 1000000007;
    }
    return result;
}

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


Measured memory_bytes: 21192
#include<bits/stdc++.h>
clock_t t=clock();
namespace my_std{
	using namespace std;
	#define pii pair<int,int>
	#define fir first
	#define sec second
	#define MP make_pair
	#define rep(i,x,y) for (int i=(x);i<=(y);i++)
	#define drep(i,x,y) for (int i=(x);i>=(y);i--)
	#define go(x) for (int i=head[x];i;i=edge[i].nxt)
	#define templ template<typename T>
	#define sz 101010
	typedef long long ll;
	typedef double db;
	mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
	templ inline T rnd(T l,T r) {return uniform_int_distribution<T>(l,r)(rng);}
	templ inline bool chkmax(T &x,T y){return x<y?x=y,1:0;}
	templ inline bool chkmin(T &x,T y){return x>y?x=y,1:0;}
	templ inline void read(T& t)
	{
		t=0;char f=0,ch=getchar();double d=0.1;
		while(ch>'9'||ch<'0') f|=(ch=='-'),ch=getchar();
		while(ch<='9'&&ch>='0') t=t*10+ch-48,ch=getchar();
		if(ch=='.'){ch=getchar();while(ch<='9'&&ch>='0') t+=d*(ch^48),d*=0.1,ch=getchar();}
		t=(f?-t:t);
	}
	template<typename T,typename... Args>inline void read(T& t,Args&... args){read(t); read(args...);}
	char __sr[1<<21],__z[20];int __C=-1,__zz=0;
	inline void Ot(){fwrite(__sr,1,__C+1,stdout),__C=-1;}
	inline void print(register int x)
	{
		if(__C>1<<20)Ot();if(x<0)__sr[++__C]='-',x=-x;
		while(__z[++__zz]=x%10+48,x/=10);
		while(__sr[++__C]=__z[__zz],--__zz);__sr[++__C]='\n';
	}
	void file()
	{
		#ifdef NTFOrz
		freopen("a.in","r",stdin);
		#endif
	}
	inline void chktime()
	{
		#ifdef NTFOrz
		cout<<(clock()-t)/1000.0<<'\n';
		#endif
	}
	#ifdef mod
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x%mod) if (y&1) ret=ret*x%mod;return ret;}
	ll inv(ll x){return ksm(x,mod-2);}
	#else
	ll ksm(ll x,int y){ll ret=1;for (;y;y>>=1,x=x*x) if (y&1) ret=ret*x;return ret;}
	#endif
//	inline ll mul(ll a,ll b){ll d=(ll)(a*(double)b/mod+0.5);ll ret=a*b-d*mod;if (ret<0) ret+=mod;return ret;}
}
using namespace my_std;

int n;
int L[sz],R[sz];
int sum[sz];
struct hh{int t,nxt;}edge[sz<<1];
int head[sz],ecnt;
void make_edge(int f,int t)
{
	edge[++ecnt]=(hh){t,head[f]};
	head[f]=ecnt;
	edge[++ecnt]=(hh){f,head[t]};
	head[t]=ecnt;
}

#define v edge[i].t
void dfs1(int x,int fa){go(x) if (v!=fa) dfs1(v,x),sum[x]+=sum[v];}
int calc(int x){return (x%2+2)%2;}
void dfs2(int x,int fa)
{
	go(x) if (v!=fa&&sum[v])
	{
		dfs2(v,x);
		int l=L[v]-1,r=R[v]+1;
		if (L[x]==-1e9&&R[x]==1e9) { L[x]=l,R[x]=r; continue; }
		if (calc(L[x])!=calc(l)) exit(puts("No")&0);
		if (l>R[x]||L[x]>r) exit(puts("No")&0);
		chkmax(L[x],l),chkmin(R[x],r);
	}
}
int ans[sz];
void dfs3(int x,int fa)
{
	go(x) if (v!=fa)
	{
		if (ans[x]+1>=L[v]&&ans[x]+1<=R[v]) ans[v]=ans[x]+1;
		else ans[v]=ans[x]-1;
		dfs3(v,x);
	}
}

int main()
{
//	file();
	read(n);
	int x,y;
	rep(i,1,n-1) read(x,y),make_edge(x,y);
	rep(i,1,n) L[i]=-1e9,R[i]=1e9;
	int K;read(K);
	while (K--) read(x,y),++sum[x],L[x]=R[x]=y;
	dfs1(1,0);dfs2(1,0);ans[1]=L[1];dfs3(1,0);
	puts("Yes");
	rep(i,1,n) printf("%d\n",ans[i]);
	return 0;
}

Measured memory_bytes: 9728
#include<bits/stdc++.h>
using namespace std;
typedef		long long       ll;
typedef		vector<ll>      vll;
#define         fi              first
#define         se              second
#define		pb              push_back
#define		nn              "\n"
#define		all(p)          p.begin(),p.end()
#define		zz(v)           (ll)v.size()
#define 	S(a)            scanf("%lld",&a)
#define 	SS(a,b)         scanf("%lld %lld",&a,&b)
#define 	SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define		ss              ' '
#define     pii             pair<ll,ll>
const double eps = 1e-8;


int main()
{

//     ios::sync_with_stdio(0);
//	cin.tie(0);

  ll k;
  string s;
  cin>>k>>s;
  for(ll i = 0;i<k&&i<zz(s);i++) cout<<s[i];
  if(zz(s)>k)cout<<"..."<<nn;
  else cout<<nn;





}



Measured memory_bytes: 3636
#include<iostream>
#include<iomanip>
#include<string>
#include<array>
#include<cmath>
#include<vector>
#include<utility>
#include<algorithm>
#include<ctype.h>
using namespace std;


int main() {
	int n, d, x, a[110];
	cin >> n >> d >> x;
	int ans = x;
	for (int i = 1; i <= n;i++) {
		cin >> a[i];
	}
	for (int i = 1; i <= n;i++) {
		int k = 0;
		while (k*a[i]+1<=d) {
			ans++;
			k++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
static const int N = 100;

int main() {
	int M[N][N];
	int n, u, k, v;

	cin >> n;

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) M[i][j] = 0;
	}

	for (int i = 0; i < n; i++) {
		cin >> u >> k;
		u--;
		for (int j = 0; j < k; j++) {
			cin >> v;
			v--;
			M[u][v] = 1;
		}
	}

	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			if (j) cout << " ";
			cout << M[i][j];
		}
		cout << endl;
	}
	return 0;
}


Measured memory_bytes: 3116
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<math.h>
#include<stack>
#include<queue>
using namespace std;
int main(){
	int a[100000];
	int m=0;
	int mm=0;
	int n=0;
	int c=0;
	int k=0;
	scanf("%d %d", &n, &k);
	for (int i = 0; i < 100000; i++){
		a[i] = 0;
	}
	scanf("%d", &a[0]);
	m = a[0];
	for (int i = 1; i < n; i++){
		scanf("%d", &a[i]);
		if (a[i]<m){
			m = a[i];
		}
		if (a[i] - m>mm){
			mm = a[i] - m;
			c = 0;
		}
		if (a[i] - m == mm)c++;
	}
	printf("%d", c);
	return 0;
}

Measured memory_bytes: 512
n,m,x=map(int,input().split())
c=[list(map(int,input().split())) for _ in range(n)]

ans=float('inf')
for i in range(2**n):
  data=[0]*(m+1)
  for j in range(n):
    if i&(1<<j):
      for k in range(m+1):
        data[k]+=c[j][k]
    cnt=0
    for l in range(1,m+1):
      if data[l]>=x:
        cnt+=1
    if cnt==m:
      ans=min(ans,data[0])
if ans==float('inf'):
  print(-1)
  exit()
print(ans)

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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

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

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

int main()
{
    cout << fixed << setprecision(15);
    string S;
    cin >> S;

    ll N = S.length();

    map<char, bool> A;

    REP(i, N){
        A[S[i]] = true;
    }
    if(N<26){
        cout << S;
        REP(i, 26){
            // cout << char(i+'a') << endl;
            char c = char(i+'a');
            if(!A.count(c)){
                cout << c << endl;
                return 0;
            }
        }
    }

    vector<char> T;
    for(ll i=25; i>=0; i--){
        if(i ==25){
            T.push_back(S[i]);
            continue;
        }
        // cout << S[i] << endl;
        sort(T.begin(), T.end());
        // cout << T[0] << endl;
        if(i==0){
            if(S[0] != 'z'){
                cout << char(S[0]+1) << endl;
            }
            else{
                cout << -1 << endl;
            }
            return 0;
        }
        else if(S[i] < T[T.size()-1]){
            REP(j, i){
                cout << S[j];
            }
            for(auto v: T){
                if(v > S[i]){
                    cout << v << endl;
                    return 0;
                }
            }
        }
        T.push_back(S[i]);
    }
    return 0;
}

Measured memory_bytes: 3608
# coding: utf-8

#N = map(int, input().split())
N = int(input())
class_list = list(map(int, input().split()))

d = {}
list = []
for value,key in enumerate(class_list):
    d[key]=value+1
for i in range(N):
    list.append(d[i+1])
print(' '.join(map(str, list)))

Measured memory_bytes: 73256
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
using namespace std;
typedef long long int ll;

constexpr ll mod=1e9+7;

ll mod_pow(ll a,ll b){
	a%=mod;
	if(b==0)return 1;
	if(b==1)return a;
	ll res=mod_pow(a,b/2)%mod;
	res*=res; res%=mod;
	if(b%2)res*=a;
	return res%mod;
}

struct perm{
private:
	int sz;
	vector<ll> p,invp;
public:
	perm(int n){
		sz=n+1;
		p.resize(sz),invp.resize(sz);
		p[0]=1;
		for(int i=1;i<=sz-1;i++){
			p[i]=p[i-1]*i%mod;
		}
		invp[sz-1]=mod_pow(p[sz-1],mod-2);
		for(int i=sz-2;i>=0;i--){
			invp[i]=invp[i+1]*(i+1)%mod;
		}
	}
	ll comb(ll x,ll y){
		if(x<y||y<0)return 0;
		return (p[x]*invp[x-y]%mod)*invp[y]%mod;
	}
};
perm p(1<<20);

int main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
	int n,k; cin >> n >> k;
	if(k>n){
		printf("0\n");
		return 0;
	}
	ll res=0;
	for(int i=0;i<k;i++){
		if(i%2==0){
			(res+=mod_pow(k-i,n)*p.comb(k,i)%mod)%=mod;
		}else{
			(res-=mod_pow(k-i,n)*p.comb(k,i)%mod)%=mod;
		}
	}
	if(res<0)res+=mod;
	cout << res << endl;
}



Measured memory_bytes: 19036
#include <algorithm>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
#include <queue>
#define MOD (1000000007l)
#define rep(i, n) for(long i = 0; i < n; i++)

using namespace std;

void solve() {
  long N;
  cin >> N;
  cout << N * (N+1) / 2 << endl;
}

int main(void) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout.precision(12);
  solve();
  return 0;
}


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

namespace _0633
{
	class Program
	{
		static int limit;
		static int list_int(List<int> list)
		{
			int ret = 0;
			for (int i = 0; i < limit; i++)
			{
				if (list.Contains(i)) ret += 1 << i;
			}
			return ret;
		}
		static void Main(string[] args)
		{
			int[] x = Console.ReadLine().Split().Select(int.Parse).ToArray();
			limit = x[1];
			int[] toys = new int[x[0]]; int[] counts = new int[limit];
			for (int i = 0; i < x[0]; i++)
			{
				int b = int.Parse(Console.ReadLine());b--;
				toys[i] = b; counts[b]++;
			}
			List<List<int>>[] kouho = new List<List<int>>[limit + 1];
			for (int i = 0; i <= limit; i++) kouho[i] = new List<List<int>>();
			for (int i = 0; i < (1 << limit); i++)
			{
				List<int> now = new List<int>(); int count = 0;
				for (int j = 0; j < limit; j++)
				{
					if ((i & 1 << j) > 0) { now.Add(j); count++; }
				}
				kouho[count].Add(now);
			}
			int[,] changesum = new int[limit, x[0]+1];
			for (int i = 0; i < limit; i++)
			{
				for (int j = 0; j < x[0]; j++)
				{
					changesum[i, j + 1] = changesum[i, j];
					if (toys[j] != i) changesum[i, j + 1]++;
				}
			}
			Tuple<int, int>[] dp = new Tuple<int, int>[(int)Math.Pow(2, limit)];//cost count
			dp[0] = new Tuple<int, int>(0, 0);
			for (int i = 1; i <= x[1]; i++)
			{
				foreach (var list in kouho[i])
				{
					int code = list_int(list);
					Tuple<int, int> min = new Tuple<int, int>(int.MaxValue, 0);
					for (int j = 0; j < limit; j++)
					{
						if ((code & 1 << j) > 0)
						{
							var before = dp[code ^ (1 << j)];
							int now = before.Item1;
							now += changesum[j, before.Item2 + counts[j]] - changesum[j, before.Item2];
							if (now < min.Item1) min = new Tuple<int, int>(now, before.Item2 + counts[j]);
						}
					}
					dp[code] = min;
				}
			}
			Console.WriteLine(dp[(1 << limit) - 1].Item1);
		}
	}
}


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

int main() {
  int a,b;
  	cin>>a>>b;
  int sum=0;
 for(int i=0;i<2;i++){
  if(max(a,b)==a){
    sum+=a;
    a=a-1;
  }
  else{
    sum+=b;
    b=b-1;
  }
 }
  cout<<sum<<endl;
}


Measured memory_bytes: 256
s = input()

ans = [0] * len(s)

cnt = 0
for i in range(len(s)):
    if s[i] == 'R':
        cnt += 1
        continue
    even = cnt // 2
    odd = cnt - even
    ans[i-1] += odd
    ans[i] += even
    cnt = 0

cnt = 0
for i in range(len(s)-1, -1, -1):
    if s[i] == 'L':
        cnt += 1
        continue
    even = cnt // 2
    odd= cnt - even
    ans[i] += even
    ans[i+1] += odd
    cnt = 0

print(*ans, sep=' ')

Measured memory_bytes: 78304
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define sc(x) cin >> x
#define sc2(x, y) cin >> x >> y
#define sc3(x, y, z) cin >> x >> y >> z
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define debugn(i, n, a) rep(i, n)cout << " --- " << a[i] << "\n";
#define debugin(i, n, a) rep(i, n)printf(" --- %10d\n", a[i])
#define debugi2n(i, n, a, b) rep(i, n)printf(" --- %10d %10d\n", a[i], b[i])
#define debugiin(i, n, a) rep(i, n)printf(" --- %10d %10d\n", a[i].first, a[i].second)
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)


signed main(void){
  int i, j;
  for(int testcase = 0;;testcase++){
    int(w);
    string res;

    for(int x = 3;w;x *= 3){
      if(w % x == x / 3){
        res += '+';
        w -= x / 3;
      }else if(w % x == x / 3 * 2){
        res += '-';
        w += x / 3;
      }else res += '0';
    }
    reverse(all(res));
    pri(res);

/*/

//*/ break;
  }
  return 0;
}

Measured memory_bytes: 1192
#include <iostream>
#include <stack>
#include <map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <string.h>

using namespace std;

int N;
char S[1000];

int main(int argc, char** argv) {
    cin >> N >> S;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int buf[1000];
        int s = 0;
        for (int j = 0; j < 1000; j++) buf[j] = 0;
        for (int j = 0; j < i; j++) buf[S[j]] = 1;
        for (int j = i; j < N; j++) if (buf[S[j]]) {
            s += 1;
            buf[S[j]] = 0;
        }
        // cout << s << endl;
        ans = max(s, ans);
    }
    cout << ans << endl;;
}

Measured memory_bytes: 256
// @gaurav_512
#include<bits/stdc++.h>
using namespace std;
 
typedef long long int ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<pii> vii;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
 
#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define bs(v,val) binary_search(v.begin(),v.end(),val)
#define mod 1e9+7
#define ff first
#define ss second
#define fi(n) for(int i=0;i<n;i++)
#define fj(n) for(int j=0;j<n;j++)
#define all(v) v.begin(),v.end()
#define pb push_back
#define m_p make_pair
#define endl '\n'
 
ll power(ll x, ll y, ll p)
{  
    ll res = 1;
    x = x % p;  
    if (x == 0) return 0;
    while (y > 0){  
        if (y & 1)  res = (res*x) % p;  
        y = y>>1;
        x = (x*x) % p;  
    }  
    return res;  
}
ll modInverse(ll n, ll p)
{
    return power(n, p-2, p); 
}
// ********** CODE STARTS HERE ****************//
 
 
void solve()
{
	string s, t;
	cin >> s >> t;
	int slen = s.length(), tlen = t.length();
	vector<vector<int>>dp(slen+1,vector<int>(tlen+1,0));
	for(int i=1; i<=slen; i++)
	{
		for(int j=1; j<=tlen; j++)
		{
			dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
			if(s[i-1]==t[j-1])
				dp[i][j] = max(dp[i][j], 1+dp[i-1][j-1]);
		}
	}
//	string lcs = "";
//	int i=slen, j=tlen;
//	while(i!=0 && j!=0)
//	{
//		if(dp[i][j] == 1+dp[i-1][j-1])
//		{
//			lcs += s[i-1];
//			i--;
//			j--;
//		}
//		else if(dp[i-1][j] == dp[i][j])
//			i--;
//		else
//			j--;
//	}
//	reverse(all(lcs));
//	cout << lcs;
	int i = s.length(), j = t.length();
 	string ans="";
	while (i > 0 && j > 0) {
		if (dp[i][j] == dp[i][j - 1])
			j--;
		else if (dp[i][j] == dp[i - 1][j])
			i--;
		else {
			ans = s[i - 1] + ans;
			i--, j--;
		}
	}
 
	cout << ans << endl;
}
 
int main()
{
	fastio;
//    int T;
//    cin>>T;
//    while(T--)
        solve();
	return 0;
}

Measured memory_bytes: 38896
n, k = gets.chomp.split.map(&:to_i)
s = gets.chomp

asyuku_ary = []
count = 0
# now
# first
for i in 0..(n-1)
    if i == 0
        # first = s[i]
        asyuku_ary << [s[i],1]
        now = s[i]
    else
        if now == s[i]
            asyuku_ary[-1][-1] += 1
        else
            now = s[i]
            asyuku_ary << [s[i], 1]
        end
    end
end
ruisekiwa = []
asyuku_ary.each do |item|
    if ruisekiwa == []
        ruisekiwa << item[1].to_i
    else
        ruisekiwa << item[1].to_i + ruisekiwa[-1]
    end
end
# p asyuku_ary
# p ruisekiwa
flag = false
if s[0].to_i == 1
    if 2 * k >= asyuku_ary.length
        flag = true
    else
        max = ruisekiwa[2 * k]
        now = 2*k
        last = -1
    end
else
    if 2 * k - 1 >= asyuku_ary.length
        flag = true
    else
        max = ruisekiwa[2 * k - 1]
        now = 2*k-1
        last = -2
    end
end

# p asyuku_ary.length
# p ruisekiwa
# p now
# p ruisekiwa[now]
if flag
    puts n
else
    while true
        # p max
        if now + 2 >= asyuku_ary.length
            now = asyuku_ary.length - 1
            last += 2
            max = [max, ruisekiwa[now] - ruisekiwa[last]].max
        else
            now += 2
            last += 2
            max = [max, ruisekiwa[now] - ruisekiwa[last]].max
        end
        if now >= asyuku_ary.length - 1
            break
        end
    end
    puts max
end


Measured memory_bytes: 16124
#include<iostream>
using namespace std;
 
int main() {
	int N, i, A[200], k = 0;
	cin >> N;
	for (i = 0; i < N; i++) {
		cin >> A[i];
	}
  
    while(true){
      bool odd = false;
      for(i = 0;i < N; i++){
        if(A[i]%2 != 0){
        odd = true;
      }
      }
      
      if(odd == true){
      break;
      }
      
	 for (i = 0; i < N; i++) {
			A[i] = A[i] / 2;
		}  
  	k += 1;
	}
	cout << k << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
// #include <ext/pb_ds/assoc_container.hpp> //gp_hash_table

#define all(a) a.begin(), a.end()
#define pb push_back
#define eb emplace_back
#define sz(a) (int) a.size()

using namespace std;
// using namespace __gnu_pbds;


typedef long long int ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<double, double> pdd;

const int N = (int) 1e5 + 10;

void solve() {
    ll n, a, b;
    cin >> n >> a >> b;
    ll d = b - a >> 1;
    if(a % 2 != b % 2) {
        ll go_to_1 = ((a - 1) + 1) + (b - a) / 2;
        ll go_to_2 = ((n - b) + 1) + (b - a) / 2;
        d = min(go_to_1, go_to_2);
    }
    cout << d << '\n';
}

int main() {
    // freopen("input.in", "r", stdin);
    // freopen("input.out", "w", stdout);
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(20);
    cout << fixed;
    // int t; cin >> t; while(t--)
    solve();
    cout.flush();
    return 0;
}

Measured memory_bytes: 3632
from sys import stdin
input = stdin.buffer.readline

n = int(input())
*a, = map(int, input().split())
b = 1000
for i in range(n - 1):
	if a[i] < a[i + 1]:
		b = b // a[i] * a[i + 1] + b % a[i]
print(b)


Measured memory_bytes: 61048
#include <iostream>
using namespace std;
int main()
{
        long long m,n;
	cin>>m>>n;
	long long ans=0;
	if(m==1&&n==1)
	ans=1;
	else if(m==1)
	ans=n-2;
	else if(n==1)
	ans=m-2;
	else
	ans=m*n-2*n-2*m+4;
	cout<<ans;
	return 0;
}
  

Measured memory_bytes: 256
A, B, M = [int(x) for x in input().split()]
A_price_list = [int(x) for x in input().split()]
B_price_list = [int(x) for x in input().split()]

discount_list = []

for i in range(M):
    x, y, c = [int(x) for x in input().split()]
    discount_list.append([x-1, y-1, c])


amount = min(A_price_list) + min(B_price_list)

for x, y, c in discount_list:
    tmp_price = A_price_list[x] + B_price_list[y] - c
    amount = min(tmp_price, amount)

print(amount)

Measured memory_bytes: 30704
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
#include <climits>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;



long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}


//約数をベクトル形式で返す
vector<int> vect_yakusuu(int n) {
	vector<int> ret;
	for (int i = 1; i*i <= n; i++) {
		if (n%i == 0) {
			ret.push_back(i);
			if (i*i != n) ret.push_back(n / i);
		}
	}
	sort(begin(ret), end(ret));
	return ret;
}

int popcount(int A) {
	int count = 0;
	while (1) {
		if (A == 0) {
			break;
		}
		if (A % 2 == 1) {
			count++;
		}
		A = A / 2;
	}
	return count;
}

int main() {


	long long N;
	string C;

	cin >> N >>C;

	int rb, lb;
	lb = 0;
	rb = N - 1;

	int count = 0;

	while (1) {
		if (lb > rb) {
			break;
		}
		if (C[lb] == 'W' && C[rb]=='R') {
			count++;
			lb++;
			rb--;
		}
		if (C[lb] == 'R') {
			lb++;
		}
		if (C[rb] == 'W') {
			rb--;
		}
	}

	cout <<count <<endl;

	cin >> N;

	return 0;


}

Measured memory_bytes: 3696