akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<ll,ll>;

ll solve() {
    ll N ,a ;
    cin >> N;
    vector<pii> A(N);
    for ( int i = 0; i < N; i++ ) {
        cin >> a;
        A[i] = pii(a,i);
    }
    sort(A.rbegin(), A.rend());
    vector<vector<ll>> dp(N, vector<ll>(N));
    ll ans = 0;
    for ( int i = 0; i < N; i++ ) {
        a = A[i].first;
        ll p = A[i].second;
        for ( int j = 0; j <= i; j++ ) {
            int k = N-1-i+j;
            if ( i < N-1 ) {
                dp[j+1][k] = max(dp[j+1][k], dp[j][k] + a * abs(p-j));
                dp[j][k-1] = max(dp[j][k-1], dp[j][k] + a * abs(k-p));
            } else {
                ans = max(ans, dp[j][k] + a * abs(p-j));
                ans = max(ans, dp[j][k] + a * abs(k-p));
            }
        }
    }
    return ans;
}

int main() {
    auto ans = solve();
    cout << ans << "\n";
    return 0;
}

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

using namespace std;

using llong = long long int;

#define rep(i, n) for (int i = 0; i < n; ++i)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()

const static int MOD = 1000000007;
const static int INF = 1<<30;
const static int dx[4] = {1, 0, -1, 0};
const static int dy[4] = {0, 1, 0, -1};

int main (int argc, char *argv[]) {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    int h, w, k;
    cin >> h >> w >> k;
    vector<string> c(h);
    rep(i, h) cin >> c[i];
 
    int num_black = 0;
    rep(i, h) rep(j, w) num_black += static_cast<int>(c[i][j] == '#');

    int ans = 0;
    for (int bi = 0; bi < (1<<h); ++bi) {
        for (int bj = 0; bj < (1<<w); ++bj) {
            int tmp = num_black;
            for (int i = 0; i < h; ++i) {
                for (int j = 0; j < w; ++j) if ((bi&(1<<i) || bj&(1<<j)) && c[i][j] == '#') --tmp;
            }
            // cout << bi << ' ' << bj << ' ' << tmp << endl;
            ans += static_cast<int>(tmp == k);
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3600
use proconio::{input, marker::Chars};

fn main() {
    input!(s: Chars, t: Chars);

    let m = t.len();
    let eval = |s: &[char]| (0..m).filter(|&i| s[i] != t[i]).count();
    let sub_s = s.windows(m);
    let ans = sub_s.map(eval).min().unwrap();

    println!("{}", ans);
}


Measured memory_bytes: 2112
using System;
class AOJ{
public static void Main(){
String[] st=Console.ReadLine().Split(' ');
int a=int.Parse(st[0]);
int b=int.Parse(st[1]);
if(a==b)
Console.WriteLine("a == b");
else if(a<b)
Console.WriteLine("a < b");
else 
Console.WriteLine("a > b");

}
}

Measured memory_bytes: 8848
#include<bits/stdc++.h>
#include <math.h>
#include <algorithm>
#include <functional>
#include<iostream>
#include <string>
using namespace std;
typedef long long ll;
#define pb pushback
#define fr(i,n) for(int i=0;i<n;i++)
#define fro(i,j,n) for(int i=j;i<n;i++)
#define ifr(i,n) for(int i=n-1;i>=0;i--)


int main() {
    int n;
	cin >> n;
    int a[n];
    int ans[n];
    fr(i,n){
      cin >> a[i];
      ans[i]=0;
    }
    for(int i=n;i>1;i--){
      int kai=n/i;
      int sum=0;
      fro(j,1,kai){
        sum+=ans[(j+1)*i-1];
      }
      ans[i-1]=(a[i-1]+sum)%2;
    }
    int sum=0;
    fro(i,1,n){
      sum+=ans[i];
    }
    ans[0]=(sum+a[0])%2;
    int an=0;
    fr(i,n){
      if(ans[i]==1)an++;
    }
    cout<<an<<endl;
    fr(i,n){
      if(ans[i]==1)cout<<i+1<<" ";
    }
}


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

using namespace std;
typedef long long ll;
const int N = 2e5 + 10;
ll a[N];

int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(nullptr);
    int n;
    cin >> n;
    ll t;
    cin >> t;
    for (int i = 0; i < n; i++)
        cin >> a[i];
    ll res = 0;
    ll prev = 0;
    for (int i = 0; i < n; i++) {
        res += min(a[i] - prev, t);
        prev = a[i];
    }
    res += t;
    cout << res << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<stdio.h>
#include<algorithm>
#include<iostream>
#include<math.h>
#include<set>
#include<map>
#include<time.h>
#include<stack>
#include<queue>
#include<stdlib.h>
#include<string.h>
#include<vector>
#define LL long long
#define mem(a,b) memset(a,b,sizeof(a))
using namespace std;
const LL mod=998244353;
const int inf=1e9;
const double INF=1e9;
const int maxn=120;
int min(int a,int b) {return a<b?a:b;}
int main()
{
    int a,b;
    scanf("%d%d",&a,&b);
    if(b%a==0)
        printf("%d\n",a+b);
    else printf("%d\n",b-a);
    return 0;
}


Measured memory_bytes: 256
N,M=map(int,input().split())
PS=[input().split() for i in range(M)]
ACzumi=set()
WA_count=[]
for i in range(M):
    if not PS[i][0] in ACzumi:
        if PS[i][1]=="AC":
            ACzumi.add(PS[i][0])
        else:
            WA_count.append(PS[i][0])
yokei=0            
for i in range(len(WA_count)):
    if not WA_count[i] in ACzumi:
        yokei+=1
        
#print(ACzumi)
print(len(ACzumi),len(WA_count)-yokei)

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

int main(){
  int a,b,c;
  cin >> a >> b >> c;
  if(a==b && b==c) cout << 1 << endl;
  else if(a!=b && (b!=c && c!=a)) cout << 3 << endl;
  else cout << 2 << endl;
}

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

h = sorted(h)
t = [0] * N
for i in range(N - 1):
    t[i + 1] = t[i] + (h[i + 1] - h[i])
ans = float('inf')
for j in range(N - K + 1):
    ans = min(ans, t[j + K - 1] - t[j])
print(ans)


Measured memory_bytes: 10864
#include <bits/stdc++.h>
using i64 = long long;

int main() {
    constexpr i64 mod = 1000000007;
    int n;
    std::cin >> n;
    std::vector<std::pair<int, int>> v;
    for (int i = 0; i < 2 * n; i++) {
        int a;
        std::cin >> a;
        v.emplace_back(a, i / n);
    }
    std::sort(v.begin(), v.end());

    int t[] { 0, 0 };
    i64 ret = 1;
    for (auto e : v) {
        auto &c = t[!e.second];
        if (c) ret = ret * c-- % mod;
        else t[e.second]++;
    }

    std::cout << ret << std::endl;

    return 0;
}


Measured memory_bytes: 2420
main :: IO ()
main = do
  nl <- words <$> getLine
  let n = read $ head nl
  ss <- getStrs n
  putStr $ concat $ qsort ss 

getStrs :: Int -> IO [String]
getStrs n = sequenceA(replicate n getLine)

qsort :: Ord a => [a] -> [a]
qsort [] = []
qsort (x:xs) = (qsort (filter (<=x) xs)) ++ [x] ++ (qsort (filter (>x) xs))


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

#define ld long double
#define ll long long int
#define ull unsigned long long int
#define vi vector<int>
#define vl vector<ll>
#define vvi vector< vector<int> >
#define vvl vector< vector<ll> >
#define repd(i, a, b) for (int i=(a);i<(b);i++)
#define rep(i, n) repd(i,0,n)
#define ALL(v) v.begin(), v.end()
#define INF 1e9

using namespace std;

/**
 * calculate GCD(greatest common divisor)
 * @param a
 * @param b
 * @return
 */
unsigned euclidean_gcd(unsigned a, unsigned b) {
    if (a < b) return euclidean_gcd(b, a);
    unsigned r;
    while ((r = a % b)) {
        a = b;
        b = r;
    }
    return b;
}

/**
 * change minimum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T> inline bool changeMinimum(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * change maximum
 * @tparam T
 * @param a
 * @param b
 * @return bool
 */
template<class T> inline bool changeMaximum(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

/**
 * output answer
 * @tparam T
 * @param answer
 * @return
 */
template<typename T>
T output(T answer) {
    cout << answer << endl;
    return 0;
}

/** ----from here ---------------------------------------------------------- */

int main() {

    ld A,B;
    cin >>A>>B;

    ld an = A*B;
    ll ans = an;


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

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

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

int n;
const int N = 200001;
const int MOD = (int) 1e9 + 7;
ll fact[N];
ll inv[N];
ll dp[N];
int sz[N];
vector<int> v[N];

ll power(ll a, int x) {
  ll res = 1;
  while (x) {
    if (x & 1) res = (res * a) % MOD;
    a = (a * a) % MOD;
    x >>= 1;
  }
  return res;
}

void init() {
  fact[0] = 0;
  fact[1] = 1;
  for (int i = 2; i < N; ++i) {
    fact[i] = fact[i - 1] * i % MOD;
  }

  inv[1] = 1;
  for (int i = 2; i < N; ++i) {
    inv[i] = (MOD - MOD / i) * inv[MOD % i] % MOD;
  }
}

void dfs(int x, int par) {
  sz[x] = 1;
  for (auto y : v[x]) {
    if (y == par) continue;
    dfs(y, x);
    sz[x] += sz[y];
  }
}

void reroot(int x, int par) {
  dp[x] = dp[par] * sz[x] % MOD * inv[n - sz[x]] % MOD;
  for (auto y : v[x]) {
    if (y == par) continue;
    reroot(y, x);
  }
}

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

  int x, y;
  cin >> n;
  for (int i = 1; i < n; ++i) {
    cin >> x >> y;
    v[x].push_back(y);
    v[y].push_back(x);
  }

  dfs(1, -1);
  dp[1] = fact[n];
  for (int i = 1; i <= n; ++i) {
    dp[1] = (dp[1] * inv[sz[i]]) % MOD;
  }
  for (auto p : v[1]) {
    reroot(p, 1);
  }
  for (int i = 1; i <= n; ++i) {
    cout << dp[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 19444
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <iomanip>
using namespace std;

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

#define Yes cout << "Yes" << endl
#define No cout << "No" << endl
#define p(x) cout << (x) << endl
#define FOR(i,r,n) for(ll i=(ll)(r); i < (ll)(n); i++)
#define RFOR(i,r,n) for(ll i=(ll)(n); i>=r; i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) REP(i,0,n)
#define ALL(x) (x).begin(), (x).end()
#define RALL(x) (x).rbegin(), (x).rend()
#define pb push_back

const int inf = (int)1e9;
const ll INF = (ll)1e18;

// vectorの中身をcout << vs;で表示
template <class T>
ostream &operator<<(ostream &o, const vector<T> &v)
{
    o << "{";
    for (int i = 0; i < (int)v.size(); i++) o << (i > 0 ? ", " : "") << v[i];
    o << "}";
    return o;
}

ll gcd (ll a, ll b) {
	while (b > 0) {
		ll t = a % b;
		a = b, b = t;
	}
	return a;
}

ll lcm (ll a, ll b) {
	return (a / gcd (a, b)) * b;
}

bool is_prime (ll n) {
		if (n < 2) return false;
		else if (n == 2) return true;
		else if (n % 2) return false;
		
		double sqrtn = sqrt(n);
		for (ll i = 3; i < sqrtn; i += 2) {
			if (n % i == 0) return false; 
		}
		return true;
}

ll ctoi(char c) {
	return (ll)(c - 48);
}

ll n, k, cnt=0, ans=0;
string s,t;

// ==================== template ============================

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

	cin >> n;
	if (n < 1000) {
		cout << "ABC" << endl;
		// cout << "ABC" << setfill('0') << right << setw(3) << n << endl;
	} else {
		// cout << "ABD" << setfill('0') << right << setw(3) << n - 999 << endl;
		cout << "ABD" << endl;

	}
}



Measured memory_bytes: 256
N,K = [int(x) for x in input().split()]
x = [int(x) for x in input().split()]
#%% input
inf = 10**10
ans = inf
for i in range(N-K+1):
    if(x[i+K-1]<0):
        if(len(x)>i+K):
            if(x[i+K]<=0):
                continue
        ans = min(ans,-x[i])
    elif(x[i]>0):
        if(i>0):
            if(x[i-1]>=0):
                continue
        ans = min(ans,x[i+K-1])
    else:
        ans = min(ans,2*x[i+K-1]-x[i],x[i+K-1]-2*x[i])
print(ans)


Measured memory_bytes: 14568
// Optimise
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

// #define MULTI_TEST
#ifdef LOCAL
#define db(...) ZZ(#__VA_ARGS__, __VA_ARGS__);
#define pc(...) PC(#__VA_ARGS__, __VA_ARGS__);
template <typename T, typename U>
ostream &operator<<(ostream &out, const pair<T, U> &p)
{
    out << '[' << p.first << ", " << p.second << ']';
    return out;
}
template <typename Arg>
void PC(const char *name, Arg &&arg)
{
    while (*name == ',' || *name == ' ')
        name++;
    std::cerr << name << " { ";
    for (const auto &v : arg)
        cerr << v << ' ';
    cerr << " }\n";
}
template <typename Arg1, typename... Args>
void PC(const char *names, Arg1 &&arg1, Args &&... args)
{
    while (*names == ',' || *names == ' ')
        names++;
    const char *comma = strchr(names, ',');
    std::cerr.write(names, comma - names) << " { ";
    for (const auto &v : arg1)
        cerr << v << ' ';
    cerr << " }\n";
    PC(comma, args...);
}
template <typename Arg1>
void ZZ(const char *name, Arg1 &&arg1)
{
    std::cerr << name << " = " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void ZZ(const char *names, Arg1 &&arg1, Args &&... args)
{
    const char *comma = strchr(names + 1, ',');
    std::cerr.write(names, comma - names) << " = " << arg1;
    ZZ(comma, args...);
}
#else
#define db(...)
#define pc(...)
#endif

using ll = long long;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define f first
#define s second
#define pb push_back
#define all(v) v.begin(), v.end()
auto TimeStart = chrono::steady_clock::now();
auto seed = TimeStart.time_since_epoch().count();
std::mt19937 rng(seed);
template <typename T>
using Random = std::uniform_int_distribution<T>;

const int NAX = 2e5 + 5, MOD = 1000000007;

void solveCase(int caseNo)
{
    char c;
    cin >> c;
    cout << ++c << '\n';
    
}

int main()
{
#ifndef LOCAL
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif
    int t = 1;
#ifdef MULTI_TEST
    cin >> t;
#endif
    for (int i = 1; i <= t; ++i)
    {
        solveCase(i);
#ifdef TIME
        cerr << "Case #" << i << ": Time " << chrono::duration<double>(chrono::steady_clock::now() - TimeStart).count() << " s.\n";
        TimeStart = chrono::steady_clock::now();
#endif
    }
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <algorithm>
#include <iomanip>
#include <cmath>
typedef long long ll;
using namespace std;

ll n, m, x, ans = 100000000000;
vector<ll> c(12);
vector<vector<ll> > a(12, vector<ll>(12));

void func(vector<int>& v){
  if(v.size() == n){
    ll p = 0;
    vector<ll> t(m, 0);
    for(int i = 0; i < n; i++){
      //cout << v[i] << " ";
      if(v[i] == 1){
        p += c[i];
        for(int j = 0; j < m; j++){
          t[j] += a[i][j];
        }
      }
    }
    //cout << endl;
    for(int j = 0; j < m; j++){
      if(t[j] < x) return;
    }
    ans = min(ans, p);
    return;
  }
  v.push_back(0);
  func(v);
  v.pop_back();
  v.push_back(1);
  func(v);
  v.pop_back();
  return;
}

void solve(){
  cin >> n >> m >> x;
  for(int i = 0; i < n; i++){
    cin >> c[i];
    for(int j = 0; j < m; j++){
      cin >> a[i][j];
    }
  }
  /*for(int i = 0; i < n; i++){
    cout << c[i] << " ";
    for(int j = 0; j < m; j++){
      cout << a[i][j] << " ";
    }
    cout << endl;
  }*/
  vector<int> v;
  func(v);
  if(ans == 100000000000) ans = -1;
  cout << ans << endl;
  return;
}

int main(){
  solve();
  return 0;
}


Measured memory_bytes: 3632
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

using ll = long long;
using vi = vector<int>;
using vd = vector<double>;
using vb = vector<bool>;
using vl = vector<ll>;
using vs = vector<string>;
using vvi = vector<vector<int> >;
using vii = vector<pair<int, int> >;

template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

string s, t;

bool match(int d) {
	for (int i = 0; i < t.size(); ++i) {
		if (t[i] != s[i + d] && s[i + d] != '?') {
			return false;
		}
	}
	return true;
}

int main() {
	cin >> s >> t;

	int minD = -1;
	rep(i, s.size()) {
		if (match(i)) minD = i;
	}

	if (minD == -1) {
		cout << "UNRESTORABLE" << endl;
		return 0;
	}

	string ans;

	rep(i, s.size()) {
		if (minD <= i && i < minD + t.size()) ans.push_back(t[i - minD]);
		else if (s[i] == '?') ans.push_back('a');
		else ans.push_back(s[i]);
	}
	cout << ans << endl;
}

/*
?huge????ho??geheg?
huge
*/

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

int main() {
  int n, l; cin >> n >> l;
  vector<string>s(n);
  for(int i=0; i<n; i++) cin >> s[i];
  
  sort(s.begin(),s.end());
  
  for(int i=0; i<n; i++) cout << s[i];
  
  return 0;
}

Measured memory_bytes: 256
n=int(input())
p=[0]
p+=list(map(float,input().split()))

dp=[[0]*(n+1) for _ in range(n+1)]
dp[0][0]=1
for k in range(1,n+1):
    dp[0][k]=0
for i in range(1,n+1):
    for j in range(0,i+1):
        if j!=0:
            dp[i][j]=dp[i-1][j-1]*p[i]
        dp[i][j]+=dp[i-1][j]*(1-p[i])

res=0
for x in range((n+1)//2,n+1):
    res+=dp[n][x]
print(res)

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

template <typename T>
inline T read(){
	T x=0,f=1;char c=getchar();
	while(!isdigit(c)){	if(c=='-') f=-f;c=getchar();}
	while(isdigit(c)){x=(x<<3)+(x<<1)+(c-48);c=getchar();}
	return x*f;
}

#define lint long long int
#define ulint unsigned lint
#define readint read<int>()
#define readlint read<lint>()
const int inf=1e9+1e7,MAXN=300+1e1;

lint dp[MAXN][MAXN][MAXN],w[MAXN],v[MAXN],V,Ans=0;
int n;

int main(void){

	// freopen("testdata.in","r",stdin);
	// freopen("testdata.out","w",stdout);

	scanf("%d%lld",&n,&V);
	for(int i=1;i<=n;i++) v[i]=readint,w[i]=readint;
	for(int i=1;i<=n;i++) for(int j=0;j<=i;j++) for(int k=0;k<=3*j;k++){
		dp[i][j][k]=max(dp[i-1][j][k],dp[i][j][k]);
		if(j && k>=v[i]-v[1]) dp[i][j][k]=max(dp[i-1][j-1][k+v[1]-v[i]]+w[i],dp[i][j][k]);
	}
	for(int i=0;i<=n;i++) for(int j=0;j<=3*i;j++) if(i*v[1]+j<=V) Ans=max(dp[n][i][j],Ans);
	printf("%lld\n",Ans);

	return 0;
}


Measured memory_bytes: 16472
#include <iostream>
using namespace std;
int n, a[200001], r=0;
int main() {
	cin >> n;
	for(int i=1;i<=n;i++){
		cin >> a[i];
	}
	for(int i=1;i<n;i++){
		if(a[i]==i){
			swap(a[i],a[i+1]);
			r++;
		}
	}
	if(a[n]==n){
		swap(a[n],a[n-1]);
		r++;
	}
	cout << r;
	return 0;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#include <queue>
using namespace std;
int main(void){
    string s,t;
    cin >> s >> t;
    sort(s.begin(),s.end());
    sort(t.begin(),t.end());
    for(int i = 0; i < min(s.size(),t.size()); i++){
        if(s[i] < t[t.size()-1-i]){
            cout << "Yes" << endl;
            return 0;
        }
        else if(s[i] > t[t.size()-1-i]) break;
        if(i == s.size()-1 && s.size() < t.size()){
            cout << "Yes" << endl;
            return 0;
        }
        else if(s[i] == t[t.size()-1-i]) continue;
    }
    cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod=1e9+7;
 
int main(){
    int N;
    cin >> N;
    vector<ll> C(N-1), S(N-1), F(N-1);
    for(int i=0; i<N-1; i++){
        cin >> C[i] >> S[i] >> F[i];
    }
    
    for(int i=0; i<N-1; i++){
        ll time=0;
        time += S[i];
        for(int j=i; j<N-1; j++){
            if(time < S[j]){
                time = S[j];
            }else if((time-S[j])%F[j]!=0){
                time += F[j]-(time-S[j])%F[j];
            }
            time += C[j];
        }
        cout << time << endl;
    }
    cout << 0;
}

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

#define int long long
//struct Fast {Fast(){cin.tie(0);ios::sync_with_stdio(0);}} fast;
const int MOD = 10000;
using intpair = pair<int, int>;

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define reps(i, n, m) for (int i = (int)(n); i <= (int)(m); i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define rALL(obj) (obj).rbegin(), (obj).rend()
#define ceiv(a, b) ((int)((a) + (b) - 1)/(int)(b))
int gcd(int x,int y){if(y==0) return x; return gcd(y, x%y);}
int lcm(int x,int y){return x/gcd(x,y)*y;}

signed main() {
    int r; cin >> r;
    cout << r*r << endl;
}

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

using namespace std;

using ll = long long;
using ld = long double;
using P = pair<int, int>;
constexpr ld EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max() / 2;
constexpr int MOD = 1e9 + 7;

template <typename T>
void printv(const vector<T> &v)
{
    int sz = v.size();
    for (int i = 0; i < sz; i++)
    {
        cout << v[i] << " \n"[i == sz - 1];
    }
}

// dp1[i] := i個以下のドングリを使ってAで購入, Bで売却したとき手元に残るドングリmax
vector<ll> dp1(5010 * 5010, -1e15);
vector<ll> dp2(5010 * 5010, -1e15);

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

    int n;
    cin >> n;
    // gold, silver, bronze
    int ga, sa, ba;
    int gb, sb, bb;
    cin >> ga >> sa >> ba;
    cin >> gb >> sb >> bb;
    dp1[0] = dp2[0] = 0;
    for (ll i = 1; i <= 5001 * 5001; i++)
    {
        dp1[i] = max(i, dp1[i - 1]);
        if (i >= ga)
        {
            dp1[i] = max(dp1[i], dp1[i - ga] + gb);
        }
        if (i >= sa)
        {
            dp1[i] = max(dp1[i], dp1[i - sa] + sb);
        }
        if (i >= ba)
        {
            dp1[i] = max(dp1[i], dp1[i - ba] + bb);
        }
    }
    for (ll i = 1; i <= 5001 * 5001; i++)
    {
        dp2[i] = max(i, dp2[i - 1]);
        if (i >= gb)
        {
            dp2[i] = max(dp2[i], dp2[i - gb] + ga);
        }
        if (i >= sb)
        {
            dp2[i] = max(dp2[i], dp2[i - sb] + sa);
        }
        if (i >= bb)
        {
            dp2[i] = max(dp2[i], dp2[i - bb] + ba);
        }
    }
    ll ret = dp1[n];
    cout << dp2[ret] << endl;
}


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

using namespace std;

int main(){
  int n, k, p[1009];
  cin >> n >> k;
  for(int i=0;i<n;i++)cin >> p[i];
  sort(p, p+n);
  int sm=0;
  for(int i=0;i<k;i++)sm+=p[i];
  cout << sm << endl;
}



Measured memory_bytes: 3636
#include <iostream>
#include <iomanip>
#include <vector>
#include <set>
#include <string>
#include <queue>
#include <algorithm>
#include <map>
#include <cmath>
#include <numeric>
#include <list>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <tuple>
#include <deque>
#include <complex>

using namespace std;

/*
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
*/

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<long long, long long> pll;
typedef vector<pll> vpll;

typedef long double ld;
typedef vector<ld> vld;

typedef vector<bool> vb;

#define rep(i, n) for (ll i = 0; i < (n); i++)
#define reps(i, n) for (ll i = 1; i <= (n); i++)
#define rrep(i, n) for (ll i = (n) - 1; i >= 0; i--)
#define rreps(i, n) for (ll i = (n); i >= 1; i--)
#define all(v) (v).begin(), (v).end()

template <class T> void chmin(T& a, T b) { a = min(a, b);}
template <class T> void chmax(T& a, T b) { a = max(a, b);}

constexpr int INF = 1 << 30;
constexpr ll INFL = 1LL << 60;
constexpr ll MOD = 1000000007;
constexpr ld EPS = 1e-12;
ld PI = acos(-1.0);

void solve() {
    ll a, b, c, k;
    cin >> a >> b >> c >> k;
    ll cnt = 0;
    while(a >= b) {
        cnt++;
        b *= 2;
    }
    while(b >= c) {
        cnt++;
        c *= 2;
    }
    cout << (cnt <= k ? "Yes" : "No") << endl;
    return;
}

int main() {
    std::cin.tie(nullptr);
    std::ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}

Measured memory_bytes: 3648
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		String inStr;
		inStr = inp();
		String[] in;
		in = inStr.split(" ");

		int a = Integer.valueOf(in[0]);
		int b = Integer.valueOf(in[1]);
		int c = Integer.valueOf(in[2]);

		if (a < b && b < c)
			System.out.println("Yes");
		else
			System.out.println("No");

	}

	private static String inp() throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		return br.readLine();
	}

}

Measured memory_bytes: 24444
def main():
    n, m = map(int, input().split())
    import itertools
    full = itertools.combinations(range(n), m)
    l = [list(map(float, input().split())) for i in range(n)]
    # print(l)
    differ = [[0] * n for _ in range(n)]
    for i in range(n):
        for k in range(i + 1, n):
            tmp = 0
            for j in range(3):
                tmp += (l[i][j] - l[k][j]) ** 2
                # print(tmp,l[i][j] , l[k][j])
            differ[i][k] = tmp
            differ[k][i] = tmp
    # print(differ)
    ans = 0
    for f in full:
        tmp = 0
        f = list(f)
        for f1i in range(len(f)):
            for f2i in range(f1i + 1, len(f)):
                tmp += differ[f[f1i]][f[f2i]]
                # print(tmp)
        ans = max(ans, tmp)
    print(ans)



if __name__ == "__main__":
    main()


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

const ll INF = 1e17;
ll const MOD = 998244353;

// modをとりながらpowする
ll modpow( ll a, ll b)
{
    ll layer=1;
    for (ll i=0; i< b; i++)
    {
        layer *= a;
        layer %= MOD;
    }
    return layer;
}

int main() {
    // input
    ll N;
    ll d;
    cin >> N;
    cin >> d;
    if (d !=0)
    {
        cout << 0 << endl;
        return 0;
    }    
    map<ll,ll> map_D;
    map_D[d]++;
    for (ll i=1; i < N; i++)
    {
        cin >> d;
        map_D[d]++;
    }

    // 頂点は一か所でないとダメ
    if (map_D[0] !=1)
    {
        cout << 0 << endl;
        return 0;
    }

    // resolve
    ll n = map_D.size();
    ll ans = 1;
    for(ll i =1; i<n; i++)
    {  
        if (map_D[i] == 0)
        {
            cout << 0 << endl;
            return 0;
        }
        ans *= modpow(map_D[i-1], map_D[i]);
        ans %= MOD;
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 6528
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;

template<typename Monoid,typename F>
class SegmentTree{
private:
    int sz;
    vector<Monoid> seg;
    const F op;
    const Monoid e;
public:
    SegmentTree(int n,const F op,const Monoid &e):op(op),e(e){
        sz = 1;
        while(sz<=n) sz <<= 1;
        seg.assign(2*sz,e);
    }
    void set(int k, const Monoid &x){
        seg[k+sz] = x;
    }
    void build(){
        for(int i=sz-1;i>0;i--){
            seg[i] = op(seg[2*i],seg[2*i+1]);
        }
    }
    void update(int k,const Monoid &x){
        k += sz;
        seg[k] = x;
        while(k>>=1){
            seg[k] = op(seg[2*k],seg[2*k+1]);
        }
    }
    Monoid query(int l,int r){
        Monoid L = e,R = e;
        for(l+=sz,r+=sz;l<r;l>>=1,r>>=1){
            if(l&1) L = op(L,seg[l++]);
            if(r&1) R = op(seg[--r],R);
        }
        return op(L,R);
    }
    Monoid operator[](const int &k)const{
        return seg[k+sz];
    }
    template<typename C>
    int find_subtree(int a,const C &check,Monoid &M,bool type) {
        while(a<sz) {
            Monoid nxt = type ? op(seg[2*a+type],M) : op(M,seg[2*a+type]);
            if(check(nxt)) a = 2*a+type;
            else M = nxt, a = 2*a+1-type;
        }
        return a - sz;
    }

    template<typename C>
    int find_first(int a,const C &check) {
        Monoid L = e;
        if(a <= 0) {
            if(check(op(L,seg[1]))) return find_subtree(1,check,L,false);
            return -1;
        }
        int b = sz;
        for(a+=sz,b+=sz;a<b;a>>=1,b>>=1) {
            if(a&1) {
                Monoid nxt = op(L,seg[a]);
                if(check(nxt)) return find_subtree(a,check,L,false);
                L = nxt;
                ++a;
            }
        }
        return -1;
    }

    template<typename C>
    int find_last(int b,const C &check) {
        Monoid R = e;
        if(b >= sz) {
            if(check(op(seg[1], R))) return find_subtree(1, check, R, true);
            return -1;
        }
        int a = sz;
        for(b+=sz; a<b; a>>=1,b>>=1) {
            if(b&1) {
                Monoid nxt = op(seg[--b],R);
                if(check(nxt)) return find_subtree(b,check,R,true);
                R = nxt;
            }
        }
        return -1;
    }
};

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N,Q;
    cin >> N >> Q;
    SegmentTree seg(N,[](int a,int b){return max(a,b);},-1);
    for(int i=0;i<N;i++){
        int a;
        cin >> a;
        seg.set(i,a);
    }
    seg.build();
    while(Q--){
        int t;
        cin >> t;
        if(t==1){
            int x,v;
            cin >> x >> v;
            x--;
            seg.update(x,v);
        }else if(t==2){
            int l,r;
            cin >> l >> r;
            l--,r--;
            cout << seg.query(l,r+1) << "\n";
        }else{
            int x,v;
            cin >> x >> v;
            x--;
            int res = seg.find_first(x,[&](int a){return v<=a;});
            cout << (res==-1? N+1:res+1) << "\n";
        }
    }
}

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

#define ff              first
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)


void aryan_p() {
	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
	return;
}


int32_t main() {


	int n ;
	cin >> n;

	mk(a, 20, int);
	mk(b, 20, int);
	mk(c, 20, int);
	for (int  i = 0 ; i < n ; i++) {
		cin >> a[i];
	}
	for (int i = 0 ; i < n ; i++) {
		cin >> b[i];
	}
	for (int i = 0 ; i < n - 1 ; i++) {
		cin >> c[i];
	}

	int sum = 0;
	for (int i = 0 ; i < n ; i++) {
		int d1 = a[i];
		sum += b[d1 - 1];
		if (i != 0) {
			if (a[i] - a[i - 1] == 1) {
				sum += c[d1 - 2];
			}
		}
	}
	cout << sum;





	return 0;
}

Measured memory_bytes: 256
def rotate(s,k):
    s_ = [[s[i][j] for j in range(8)] for i in range(6)]
    if k == "R":
        s_[0][3] = s[2][3]
        s_[1][3] = s[3][3]
        s_[2][3] = s[4][3]
        s_[3][3] = s[5][3]

        s_[4][3] = s[3][6]
        s_[5][3] = s[2][6]
        s_[3][6] = s[0][3]
        s_[2][6] = s[1][3]

        s_[2][4] = s[3][4]
        s_[3][4] = s[3][5]
        s_[3][5] = s[2][5]
        s_[2][5] = s[2][4]

    elif k == "L":
        s_[0][2] = s[3][7]
        s_[1][2] = s[2][7]
        s_[2][2] = s[0][2]
        s_[3][2] = s[1][2]

        s_[4][2] = s[2][2]
        s_[5][2] = s[3][2]
        s_[3][7] = s[4][2]
        s_[2][7] = s[5][2]

        s_[2][1] = s[2][0]
        s_[2][0] = s[3][0]
        s_[3][0] = s[3][1]
        s_[3][1] = s[2][1]

    elif k == "U":
        s_[2][0] = s[2][2]
        s_[2][1] = s[2][3]
        s_[2][2] = s[2][4]
        s_[2][3] = s[2][5]

        s_[2][4] = s[2][6]
        s_[2][5] = s[2][7]
        s_[2][6] = s[2][0]
        s_[2][7] = s[2][1]

        s_[0][2] = s[1][2]
        s_[1][2] = s[1][3]
        s_[1][3] = s[0][3]
        s_[0][3] = s[0][2]

    elif k == "D":
        s_[3][0] = s[3][6]
        s_[3][1] = s[3][7]
        s_[3][2] = s[3][0]
        s_[3][3] = s[3][1]

        s_[3][4] = s[3][2]
        s_[3][5] = s[3][3]
        s_[3][6] = s[3][4]
        s_[3][7] = s[3][5]

        s_[4][2] = s[5][2]
        s_[5][2] = s[5][3]
        s_[5][3] = s[4][3]
        s_[4][3] = s[4][2]

    elif k == "F":
        s_[1][2] = s[3][1]
        s_[1][3] = s[2][1]
        s_[3][1] = s[4][3]
        s_[2][1] = s[4][2]

        s_[4][3] = s[2][4]
        s_[4][2] = s[3][4]
        s_[2][4] = s[1][2]
        s_[3][4] = s[1][3]

        s_[2][2] = s[3][2]
        s_[3][2] = s[3][3]
        s_[3][3] = s[2][3]
        s_[2][3] = s[2][2]

    else:
        s_[0][2] = s[2][5]
        s_[0][3] = s[3][5]
        s_[2][5] = s[5][3]
        s_[3][5] = s[5][2]

        s_[5][3] = s[3][0]
        s_[5][2] = s[2][0]
        s_[3][0] = s[0][2]
        s_[2][0] = s[0][3]

        s_[2][6] = s[3][6]
        s_[3][6] = s[3][7]
        s_[3][7] = s[2][7]
        s_[2][7] = s[2][6]
    return s_
a = input()
s = ["..rr....", "..rr....","ggyybbww","ggyybbww","..oo....","..oo...."]
for k in a:
    s = rotate(s,k)

for i in s:
    for j in i:
        print(j,end = "")
    print()



Measured memory_bytes: 5832
#include <iostream> 
#include <iomanip> 
#include <vector> 
#include <algorithm> 
#include <numeric> 
#include <functional> 
#include <cmath> 
#include <queue> 
#include <stack> 

#define Ford(i,a,b) for (int i=(a);i<(b);i++) 
#define For(i,n) Ford(i,0,n) 
typedef long long ll; 

using namespace std;

int main(){
  int y,m,d;
  char c1,c2;
  string ans;
  cin>>y>>c1>>m>>c2>>d;
  if(m>4){
    ans = "TBD";
  }
  else{
    ans = "Heisei";
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for (int i = (a); i < (b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define ALL(x) x.begin(), x.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
random_device rnd;
mt19937 mt(rnd());
using ll = long long;
using lld = long double;
using VI = vector<int>;
using VVI = vector<VI>;
using VL = vector<ll>;
using VVL = vector<VL>;
using PII = pair<int, int>;
const int IINF = 1 << 30;
const ll INF = 1ll << 60;
const ll MOD = 1000000007;

int main()
{
    int n;
    cin >> n;
    VVL d(n, VL(n, 0));
    ll ans = 0;
    rep(i, n) rep(j, n)
    {
        cin >> d[i][j];
    }
    auto war = d;
    rep(k, n) rep(i, n) rep(j, n)
    {
        chmin(war[i][j], war[i][k] + war[k][j]);
    }
    rep(i, n) rep(j, n)
    {
        if (war[i][j] < d[i][j])
        {
            cout << -1 << endl;
            return 0;
        }
    }
    rep(i, n) rep(j, n)
    {
        bool add = true;
        rep(k, n)
        {
            if (k != i && k != j && d[i][j] == d[i][k] + d[k][j])
            {
                add = false;
            }
        }
        if (add)
        {
            ans += d[i][j];
        }
    }
    cout << ans / 2 << endl;
    return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

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

    int k,t;
    cin>>k>>t;
    int num=-1;
    for(int i=0;i<t;i++){
        int a;
        cin>>a;
        num=max(num,a);
    }
    int ans=0;
    if(num>(k+1)/2){
        num-=(k+1)/2;
        if(k%2==0)ans=2*num-1;
        else ans=2*num+1;
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(a) (a).begin(), (a).end()
// #define sort(a) sort(all(a))
using P = pair<int, int>;
using ll = long long;
using ld = long double;
typedef vector<int> vi;
int dx[4] = { 0, 1, 0,-1 };
int dy[4] = { 1, 0,-1, 0 };
const ll MOD = 1000000007;
#define PI 3.14159265358979323846264338327950L


using Graph = vector<vector<int>>;

signed main() {
    // 頂点数と辺数
    int N, M; cin >> N >> M;
    int H[N];
    int ans = 0;
    for (int i = 0; i < N; i++) cin >> H[i];
    Graph G(N);
    for (int i = 0; i < M; ++i) {
        int a, b;
        cin >> a >> b;
        G[a-1].push_back(b-1);
        G[b-1].push_back(a-1);
    }
    for (int i = 0; i < N; i++) {
      bool flag = true;
      for (int j = 0; j < G[i].size(); j++) {
        if(H[i]<=H[G[i][j]]) flag=false;
      }
      if (flag) ans++;
    }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 9844
import re
import sys
import math
import itertools
import bisect
from copy import copy
from collections import deque,Counter
from decimal import Decimal
import functools
def s(): return input()
def k(): return int(input())
def S(): return input().split()
def I(): return map(int,input().split())
def X(): return list(input())
def L(): return list(input().split())
def l(): return list(map(int,input().split()))
def lcm(a,b): return a*b//math.gcd(a,b)
sys.setrecursionlimit(10 ** 9)
mod = 10**9+7
cnt = 0
ans = 0
inf = float("inf")

n=k()
print(math.ceil(n/2))


Measured memory_bytes: 10404
N, W = map(int, input().split())
dp = {}
for i in range(W + 1):
    dp[i] = 0
for i in range(N):
    w, v = map(int, input().split())
    for j in range(W - w, -1, -1):
        dp[j + w] = max(dp[j + w], dp[j] + v)
print(dp[W])

Measured memory_bytes: 87652
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const long long INF = 1LL << 60;
using Graph = vector<vector<int>>;

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

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

inline int gcd(int a, int b) { return (a%b == 0) ? b : gcd(b, a%b); }
inline int fac(int n) { return (n==0) ? 1 : n * fac(n - 1); }

int main() {
    int n;
    cin >> n;
    int p, q;
    p = q = 0;
    for (int i = n - 1; i >= 0; i--) {
        int temp;
        cin >> temp;
        p += temp * pow(10, i);
    }
    for (int i = n - 1; i >= 0; i--) {
        int temp;
        cin >> temp;
        q += temp * pow(10, i);
    }

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

    int b_size = fac(n);
    int b[b_size] = {};
    int i = 0;
    do {
        for (int j = 0; j < n; j++) {
            b[i] += a[j] * pow(10, j);
        }
        i++;
    } while (next_permutation(a, a + n));

    sort(b, b + b_size);

    int a_pos = distance(b, lower_bound(b, b + b_size, p));
    int b_pos = distance(b, lower_bound(b, b + b_size, q));
    
    cout << abs(a_pos - b_pos) << endl;

    return 0;
}

Measured memory_bytes: 4192
n=int(input())
a_list=[int(i) for i in input().split()]
total=sum(a_list)
diff=sum(abs(a_list[i]) for i in range(n))
left=0
for i in range(n-1):
    left+=a_list[i]
    right=total-left
    diff=min(diff,abs(left-right))
print(diff)

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

#include<bits/stdc++.h>

using namespace std;

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

#define SPEED ios_base::sync_with_stdio(false);cin.tie(nullptr)
#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;

constexpr long double PI = 3.14159265358979323846264338327950288L;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());

class CStrangeDance {
public:
    int calc(vector<vector<vector<int>>>& v, int k) {
      int w = 0;
      if (k > 0) {
        w = calc(v, k-1);
      }
      auto ret = v[2][k][w];

      auto w0 = v[0][k][w];
      auto w1 = v[1][k][w];
      auto w2 = v[2][k][w];

      v[1][k][w] = w0;
      v[2][k][w] = w1;
      v[0][k][w] = w2;
      return ret;
    }

    void solve(istream& cin, ostream& cout) {
      SPEED;
      int n;
      cin >> n;
      string t;
      cin >> t;

      // initialize vector size
      vector<vector<vector<int>>> v(3, vector<vector<int>>(n));
      int k = 1;
      rep(i, n) {
        rep(j, 3) {
          v[j][i].resize(k);
        }
        k *= 3;
      }
      int K = k;

      // initialize vector
      rep(i, n) {
        int idx = 0;
        rep(j, 3) {
          for(auto& e: v[j][i]) {
            e = idx;
            idx++;
          }
        }
      }

      for(auto c: t) {
        if (c=='S') {
          // swap vector
          swap(v[1], v[2]);
        } else {
          // swap by point recursively
          calc(v, n-1);
        }
      }

      // recover
      vector<int> ans(K);
      k = 1;
      rep(i, n) {
        for(int j=1; j<=2; j++) {
          for(auto e: v[j][i]) {
            for(int idx=e; idx<K; idx+=(k*3)) {
              ans[idx] += j*k;
            }
          }
        }
        k *= 3;
      }

      for(auto e: ans) {
        cout << e << ' ';
      }
      cout << endl;

    }
};

signed main() {
  CStrangeDance solver;
  std::istream& in(std::cin);
  std::ostream& out(std::cout);
  solver.solve(in, out);
  return 0;
}

Measured memory_bytes: 9380
#include <iostream>
#include <string>

using namespace std;

int main()
{
  int n; cin >> n;
  
  int c[10][10] = {};
  for (int i = 1; i <= n; ++i) {
    string s = to_string(i);
    ++c[s[0]-'0'][s.back()-'0'];
  }
  
  long long ans = 0;
  for (int i = 1; i <= 9; ++i) for (int j = 1; j <= 9; ++j)
    ans += c[i][j] * c[j][i];
  
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
#ランレングス圧縮
def rle(l):
    ret = []
    n = len(l)
    cnt = 1
    for i in range(1,n):
        if l[i - 1] == l[i]:
            cnt+=1
        else:
            ret.append([l[i - 1],cnt])
            cnt = 1
        if i == n - 1:
            ret.append([l[i],cnt])
    return ret

n = int(input())
a = list(map(int,input().split()))

a.sort()

ans = n

r = rle(a)

for i in range(len(r)):
    if r[i][1] % 2 == 0:
        ans-=r[i][1]
        if i != len(r) - 1:
            r[i + 1][1]-=1
    else:
        ans-=r[i][1] - 1
print(ans)


Measured memory_bytes: 64236
import std.string;
import std.stdio;

const(bool)[] sieve(size_t length) {
	auto primes = new bool[length];
	primes[2..$] = true;

	foreach (size_t i, e;primes) {
		if (!e) {
			continue;
		}
		for (auto j = i * 2;j < primes.length;j += i) {
			primes[j] = false;
		}
	}

	return primes;
}

const(bool)[] like2017(size_t length) {
	auto primes = sieve(length);
	auto like2017s = new bool[length];

	for (auto i = 3;i < like2017s.length;i += 2) {
		if (primes[i] && primes[(i + 1) / 2]) {
			like2017s[i] = true;
		}
	}

	return like2017s;
}

const(int)[] totalLike2017s(size_t length) {
	auto l = like2017(length);
	auto totals = new int[length + 1];

	foreach (size_t i, e;l) {
		if (e) {
			totals[i + 1] = totals[i] + 1;
		} else {
			totals[i + 1] = totals[i];
		}
	}

	return totals;
}

void main() {
	enum Max = 100000;

	int n;
	readf(" %s", &n);

	static totals = totalLike2017s(Max);

	foreach (i;0..n) {
		int l, r;
		readf(" %s %s", &l, &r);
		writeln(totals[r + 1] - totals[l]);
	}
}


Measured memory_bytes: 636
#include<iostream>
#include<vector>
#include<queue>
using namespace std;

int main(){
    int n, m, x;
    cin >> n >> m >> x;
    vector<int> t(n);
    for(int i = 0; i < n; i++)  cin >> t[i];
    vector<pair<int,int>> v[n];
    for(int i = 0; i < m; i++){
        int a, b, d;
        cin >> a >> b >> d;
        a--, b--;
        v[a].push_back({b, d});
        v[b].push_back({a, d});
    }
    vector<vector<int>> dp(n, vector<int>(401, 1<<30));
    priority_queue<pair<int, pair<int,int>>> pq;
    pq.push({-0, {0, -x}});
    while(!pq.empty()){
        auto p = pq.top();  pq.pop();
        int cost = -p.first, pos = p.second.first, tmp = p.second.second;
        if(dp[pos][tmp+200] <= cost)    continue;
        dp[pos][tmp+200] = cost;
        for(pair<int,int> q : v[pos]){
            int next = q.first, ntmp = tmp, ncost = cost + q.second;
            if(tmp < 0){
                if(tmp+q.second < 0 && t[next]==2)  continue;
                ntmp = min(0, tmp+q.second);
            }else if(tmp > 0){
                if(tmp-q.second > 0 && t[next]==0)  continue;
                ntmp = max(0, tmp-q.second);
            }
            if(t[next] == 2)    ntmp = x;
            if(t[next] == 0)    ntmp = -x;
            if(ncost < dp[next][ntmp+200])  pq.push({-ncost, {next, ntmp}});
        }
    }
    int ans = 1<<30;
    for(int tmp = 0; tmp < 401; tmp++)  ans = min(ans, dp[n-1][tmp]);
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;

int main() {
	ll x, q = 100, ans = 0;
	cin >> x;
	while (1) {
		if (q >= x) {
			cout << ans << '\n';
			return 0;
		}
		q += q / 100;
		++ans;
	}
}


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

/*
code credits : ਜ਼ੈਲਦਾਰ
dashan jot singh
*/
using namespace std;
#define ll long long int
#define fast ios_base::sync_with_stdio(0), cin.tie(NULL), cout.tie(NULL)
#define pb push_back
#define mp make_pair
#define inf LLONG_MAX
#define p pair<ll,ll>
ll n;
ll a[100010];
ll b[100010];
ll c[100010];
ll dp[100010][3];
ll solve(){
	dp[0][0]=a[0];
	dp[0][1]=b[0];
	dp[0][2]=c[0];
	for(ll i=1;i<n;i++){
		dp[i][0]=a[i]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=b[i]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=c[i]+max(dp[i-1][0],dp[i-1][1]);
	}
	ll ans=max(dp[n-1][0],max(dp[n-1][1],dp[n-1][2]));
	return ans;
}
int main(){
	fast;
	cin>>n;
	for(ll i=0;i<n;i++){
		cin>>a[i]>>b[i]>>c[i];
	}
	cout<<solve()<<endl;
	return 0;
}

Measured memory_bytes: 4992