akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
string s;
string strd(int n){
    string x;
    while(n){
        int d=n%10;
        x+=(d+'0');
        n/=10;
    }
    reverse(x.begin(),x.end());
    return x;
}
void digit()
{
    cin>>s;
    ll sum=0;
    for(int i=0;i<s.size();i++){
        char a=(char)s[i];
        int d=(int) a-'0';
        sum+=d;
    }
    if(sum%9==0)cout<<"Yes\n";
    else cout<<"No\n";
}
int main()
{
    ll n;
    cin>>n;
    ll a[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    ll d=0;
    for(ll i=1;i<n;i++){
       if(a[i-1]>a[i]){
        d+=a[i-1]-a[i] ;
       /// cout<<a[i-1]<<' '<<a[i]<<endl;;
        a[i]=a[i-1];
       }
    }
    cout<<d<<endl;
}


Measured memory_bytes: 5164
#include <bits/stdc++.h>
 
using namespace std;
 
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > ii;
#define ll	long long
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define tr(c,i) for(typeof((c)).begin() i = (c).begin(); i != (c).end(); i++)
#define present(c,x) ((c).find(x) != (c).end())
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ios	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define hell 1000000007

bool check (string s, string t) {
	int n = sz(s);
	int count = 0;
	for (int i = 0; i < n; i++) {
		if(s[i] == t[i]) count++; 
	}
	return count == n;
}

int main() {
	string s, t;
	cin>>s>>t;
	if (sz(s) + 1 == sz(t) && check(s, t)) {
		cout<<"Yes";
	}
	else cout<<"No";
	
	return 0;
}


Measured memory_bytes: 3628
#include <algorithm>
#include <bitset>
#include <complex>
#include <cstdio>
#include <deque>
#include <exception>
#include <fstream>
#include <functional>
#include <iomanip>
#include <ios>
#include <iosfwd>
#include <iostream>
#include <istream>
#include <iterator>
#include <limits>
#include <list>
#include <locale>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <ostream>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <stdexcept>
#include <streambuf>
#include <string>
#include <typeinfo>
#include <utility>
#include <valarray>
#include <vector>
#if __cplusplus >= 201103L
#include <array>
#include <atomic>
#include <chrono>
#include <condition_variable>
#include <forward_list>
#include <future>
#include <initializer_list>
#include <mutex>
#include <random>
#include <ratio>
#include <regex>
#include <scoped_allocator>
#include <system_error>
#include <thread>
#include <tuple>
#include <typeindex>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#endif

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

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

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << min(a, b) + min(c, d) << '\n';

    return 0;
}


Measured memory_bytes: 256
a, b, c, x = int(input()), int(input()), int(input()), int(input())

res = 0
for i in range(a+1):
    rem = x
    rem -= 500 * i
    tempA = rem
    if rem == 0:
        res += 1
        continue
    for j in range(b+1):
        rem = tempA
        rem -= 100 * j
        tempB = rem
        if rem == 0:
            res += 1
            continue
        for k in range(c+1):
            rem = tempB
            rem -= 50 * k
            if rem == 0:
                res += 1
                break

print(res)

Measured memory_bytes: 9204
#include<cstdio>
#include<cmath>
#include<iostream>
#include<numeric>
using namespace std;
typedef long long llong;

int main(void)
{
  llong a, b, tmp, r;
  cin >> a >> b;

  llong x = a * b;
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;

  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }

  /* 最小公倍数を出力 */
  cout << x / b << endl;
 
  return 0;
}

Measured memory_bytes: 256
from collections import deque


def solve(n, edge_list, m, cond_list):

    g = [[] for _ in range(n)]

    for a, b in edge_list:
        g[a - 1].append(b - 1)
        g[b - 1].append(a - 1)

    cond_mat = [[0] * m for _ in range(n - 1)]

    for i in range(m):
        u, v = cond_list[i]
        parent_list = [-1] * n
        p = u - 1
        parent_list[p] = p
        queue = deque([p])
        while len(queue) > 0:
            p = queue.popleft()
            for q in g[p]:
                if parent_list[q] == -1:
                    parent_list[q] = p
                    queue.append(q)
        q = v - 1
        p = parent_list[q]
        while q != u - 1:
            if (p + 1, q + 1) in edge_list:
                k = edge_list.index((p + 1, q + 1))
            else:
                k = edge_list.index((q + 1, p + 1))
            cond_mat[k][i] = 1
            p, q = parent_list[p], parent_list[q]

    # cond_vec
    cond_vec = [0] * (n - 1)
    for k in range(n - 1):
        for i in range(m):
            cond_vec[k] += cond_mat[k][i] * (2 ** i)
    # print(cond_vec)
    # bit DP
    dp = [[0] * (2 ** m) for _ in range(n)]
    dp[0][0] = 1
    for k in range(n - 1):
        for i in range(2 ** m):
            dp[k + 1][i] += dp[k][i]
            dp[k + 1][i | cond_vec[k]] += dp[k][i]
    # print(dp)
    return dp[-1][-1]


def main():
    n = int(input())
    edge_list = []
    for _ in range(n - 1):
        a, b = map(int, input().split())
        edge_list.append((a, b))
    m = int(input())
    cond_list = []
    for _ in range(m):
        u, v = map(int, input().split())
        cond_list.append((u, v))
    res = solve(n, edge_list, m, cond_list)
    print(res)


def test():
    assert solve(3, [(1, 2), (2, 3)], 1, [(1, 3)]) == 3
    assert solve(2, [(1, 2)], 1, [(1, 2)]) == 1
    assert solve(5, [(1, 2), (3, 2), (3, 4), (5, 3)], 3, [(1, 3), (2, 4), (2, 5)]) == 9


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 443548
#pragma region template
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const long long MOD = 1e9 + 7, MAX = 1e18, larg = 1e5, INF = -1e18;
long long A, B, C, D, E, F, G, H, I, J, K, L, N, M, O, P, Q, R, S, T, U, V, W, x, y, z;
long long max_value = INF, max_index = -1;
long long min_value = MAX, min_index = -1;
typedef long long ll;

ll val[12][12];
ll cost[12];

int main() {
	cin >> N >> M >> K;
	rep(i, N) {
		cin >> cost[i];
		rep(j, M) {
			cin >> val[i][j];
		}
	}
	ll minv = MAX;
	rep(i, (1 << N)) {
		ll skill[12];
		ll _cost = 0;
		rep(j, M) {
			skill[j] = 0;
		}
		rep(j, N) {
			if ((i >> j) % 2 == 1) {
				rep(k, M) {
					skill[k] += val[j][k];
				}
				_cost += cost[j];
			}
		}
		bool flag = true;
		rep(j, M) {
			flag &= (skill[j] >= K);
		}
		if (flag) minv = min(minv, _cost);
	}
	if (minv == MAX) cout << -1;
	else cout << minv;
}


Measured memory_bytes: 3636
#include <iostream>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int main() {
    int N,Q;
    cin >> N;
    vector<int> S(N);
    rep(i,N) cin >> S[i];
    int ans=0;
    cin >> Q;
    int t;
    rep(i,Q) {
        cin >> t;
        if (t== *lower_bound(S.begin(),S.end(),t)) ans++;
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3108
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>

// Acknowledgement: Special thanks to kyomukyomupurin, who developed this
// template.
template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::pair<T, U>& p) {
  return os << '(' << p.first << ", " << p.second << ')';
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::vector<T>& vec) {
  int n = 0;
  for (auto e : vec) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::ostream& operator<<(std::ostream& os, const std::set<T>& st) {
  int n = 0;
  for (auto e : st) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T, class U>
std::ostream& operator<<(std::ostream& os, const std::map<T, U>& mp) {
  int n = 0;
  for (auto e : mp) os << (n++ ? ", " : "{") << e;
  return os << (n ? "}" : "{}");
}

template <class T>
std::istream& operator>>(std::istream& is, std::vector<T>& vec) {
  for (T& e : vec) is >> e;
  return is;
}

#ifdef LOCAL
#define debug(...) \
  std::cerr << "[" << #__VA_ARGS__ << "]: ", debug_out(__VA_ARGS__)
#else
#define debug(...)
#endif

void debug_out() { std::cerr << '\n'; }

template <class Head, class... Tail>
void debug_out(Head&& head, Tail&&... tail) {
  std::cerr << head;
  if (sizeof...(Tail) != 0) std::cerr << ", ";
  debug_out(std::forward<Tail>(tail)...);
}
using namespace std;
using int64 = long long;

void bfs(int start_node_id, const vector<vector<int>>& g,
         vector<int>& visit_status, vector<int>& distance, vector<int>& parent,
         int col = 1) {
  int node_id;
  queue<int> q;
  visit_status[start_node_id] = col;
  distance[start_node_id] = 0;
  q.push(start_node_id);
  while (!q.empty()) {
    node_id = q.front();
    q.pop();
    for (int i = 0; i < (int)g[node_id].size(); i++) {
      int next_node_id = g[node_id][i];
      if (visit_status[next_node_id] == 0) {
        q.push(next_node_id);
        visit_status[next_node_id] = col;
        distance[next_node_id] = distance[node_id] + 1;
        parent[next_node_id] = node_id;
      }
    }
    visit_status[node_id] = col;
  }
}

int main() {
  int n, k, u, v;
  cin >> n;
  vector<vector<int>> g(n);
  for (int i = 0; i < n; i++) {
    cin >> u >> k;
    for (int j = 0; j < k; j++) {
      cin >> v;
      g[i].push_back(v - 1);
    }
  }
  debug(g);
  vector<int> visit_status(n), distance(n, -1), parent(n);
  bfs(0, g, visit_status, distance, parent);
  for (int i = 0; i < n; i++) {
    cout << i + 1 << ' ' << distance[i] << endl;
  }
  return 0;
}


Measured memory_bytes: 3160
n=int(input())
count=0
ab=[[0]*10 for i in range(10)]
for i in range(1,n+1):
  k=str(i)
  a=int(k[0])
  b=int(k[-1])
  ab[b][a]+=1
#print(ab)
for i in range(10):
  for j in range(10):
    count+=ab[i][j]*(ab[j][i])
print(count)

Measured memory_bytes: 9192
#include<bits/stdc++.h>
using namespace std;
int main(){
  string W,T;
  cin >> W;
  int count = 0;
  while(1){
	cin >> T;
	if(T == "END_OF_TEXT") break;

	for(int i=0; i<(int)T.size(); i++){
	    T[i] = tolower(T[i]);
	}
	if(T==W) count++;
  }
  cout << count << endl;
  return 0;
}



Measured memory_bytes: 3100
s = input()
t = ["A", "C", "G", "T"]
c = [0]
n = 0
for i in s:
    d = 0
    for j in t:
        if i == j:
            d = 1
            n += 1
    if d == 0:
        c.append(n)
        n = 0
c.append(n)
c.sort()
print(c[len(c) - 1])

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

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

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
char p[3],a[3];
  int i,count;
  count = 0;
  for(i=0;i<3;i++)
  {
    cin>>p[i];
  }
  for(i=0;i<3;i++)
  {
    cin>>a[i];
  }
  
  for(i=0;i<3;i++)
  {
    if(p[i]==a[i])
      count++;
  }
  cout<<count;
  return 0;
}
  
    

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

typedef long long ll;
static const ll INF = 1e9;

int main(){
    int K,N;
    cin>>K>>N;
    vector<ll> A(N);
    vector<ll> rev(N);
    vector<ll> dis(N);
    vector<ll> sum(N,0);
    vector<ll> rsum(N,0);

    for(int i=0; i<N; i++) cin>>A[i];
    rev = A;

    ll len = K - A[N-1] + A[0];
    
    for(int i=0; i<N-1; i++) rev[i] = abs(A[i]-A[i+1]);
    for(int i=0; i<N-1; i++) dis[i] = A[i+1]-A[i];
    for(int i=1; i<N; i++) rsum[i] = rsum[i-1]+rev[i-1];
    for(int i=1; i<N; i++) sum[i] = sum[i-1]+(dis[i-1]);

    ll ans=INF;

    for(int i=0; i<N; i++){
        ll tmp1 = 0,tmp2=0;
        tmp1 += sum[N-1] - sum[i];
        tmp1 += rsum[i];

        if(i == N-1)tmp2 += rsum[N-1];
        else tmp2 += (rsum[N-1] - rev[i]);

        if(i != 0) tmp1 += len;
        if(i !=  N-1) tmp2 += len;

        ans = min({ans,tmp1,tmp2});
    }

    cout<<ans<<endl;

    return 0;
}

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

ll solve() {
    string S, T;
    cin >> S >> T;
    ll Q, a,b,c,d;
    cin >> Q;

    vector<int> sm(S.size()+1), tm(T.size()+1);
    sm[0] = 0;
    for ( int i = 0; i < S.size(); i++ ) {
        int d = S[i] == 'A' ? 1 : 2;
        sm[i+1] = (sm[i] + d) % 3;
    }
    tm[0] = 0;
    for ( int i = 0; i < T.size(); i++ ) {
        int d = T[i] == 'A' ? 1 : 2;
        tm[i+1] = (tm[i] + d) % 3;
    }

    vector<bool> ans;
    for ( int q = 0; q < Q; q++ ) {
        cin >> a >> b >> c >> d;
        int sd = (sm[b] + 3 - sm[a-1]) % 3;
        int td = (tm[d] + 3 - tm[c-1]) % 3;
        ans.push_back(sd == td);
    }
    
    for ( int q = 0; q < Q; q++ ) {
        string s = ans[q] ? "YES" : "NO";
        cout << s << "\n";
    }
    return 0;
}

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

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

int main() {
long long k,a,b,c=1;
cin>>k>>a>>b;
if(a<k){
    if(a-b<=0){
        c=-1;
    }else{
        c+=2*((k-b-1)/(a-b));
    }
}
cout<<c<<endl;
	return 0;
}


Measured memory_bytes: 256
import math
n,d = (int(i) for i in input().split())
vecs = []
for i in range(n):
    vec = list(map(int,input().split()))	
    vecs.append(vec)

count = 0
sum_max  = (40**2) * d
int_list = [ i**2 for i in range(int(math.sqrt(sum_max))) ]

for i in range(n):
    for j in range(i+1,n):
        sum = 0
        for k in range(d):
            sum += (vecs[i][k] - vecs[j][k]) ** 2
        if sum in int_list:
            count += 1

print(count)

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

typedef long long ll;
typedef vector<long long> vll;
typedef vector<int> vi;
typedef pair<int, int> pi;

#define pb push_back
#define rep(i, l, n) for (int i = (l); i < n; i++)
#define rep_cs(i, l, n) for (int i = (l); i <= n; i++)
#define rep_d(j, n) for (int j = n; j >= 0; j--)
#define rep_d_op(j, n, a) for (int j = n; j >= a; j--)

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;
}

const int MOD = 1000000007;
const vector<int> dx = {1, 0};
const vector<int> dy = {0, 1};
const ll INF = 1LL << 60;

// int max = *std::max_element(vec.begin(), vec.end());
// int sum = accumulate(list, list + size, 0);

int GCD(int a, int b) { return b ? GCD(b, a % b) : a; }

using Graph = vector<vector<int>>;
Graph G;
vector<bool> seen;
void dfs(const Graph &G, int v)
{
    seen[v] = true;

    for (auto next_v : G[v])
    {
        if (seen[next_v])
            continue;
        dfs(G, next_v);
    }
}

ll dp[110][110000] = {0};
ll w[110];
ll v[110];

int main()
{
    int N, W;
    cin >> N >> W;
    rep(i, 0, N) cin >> w[i] >> v[i];
    rep(i, 0, 110) rep(j, 0, 110000) dp[i][j] = INF;

    dp[0][0] = 0;
    ;

    rep(i, 0, N)
    {
        rep_cs(sum_v, 0, 110000)
        {
            if (sum_v - v[i] >= 0)
            {
                chmin(dp[i + 1][sum_v], dp[i][sum_v - v[i]] + w[i]);
            }
            chmin(dp[i + 1][sum_v], dp[i][sum_v]);
        }
    }

    ll res = 0;
    rep(sum_v, 0, 110000)
    {
        if (dp[N][sum_v] <= W)
        {
            res = sum_v;
        }
    }
    cout << res << endl;
}

Measured memory_bytes: 94720
/**In the name of Allah, the Most Merciful, the Most Merciful.**/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define INF 9223372036854775806
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define PI 2*acos(0.0)
#define EPS 1e-9
ll max(ll a,ll b) {if(a>b) return a; else return b;}
ll min(ll a,ll b) {if(a<b) return a; else return b;}
bool check(int a,int b,int c){
    if(a+b>c && a+c>b && b+c>a) return true;
    return false;
}
int main()
{
    int n;
    cin>>n;
    int a[n+1];
    for(int i=1;i<=n;i++){
        cin>>a[i];
    }

    ll cnt=0;

    for(int i=1;i<=n;i++){
        for(int j=i+1;j<=n;j++){
            for(int k=j+1;k<=n;k++){
                if(a[i]!=a[j] && a[i]!=a[k] && a[j]!=a[k] && check(a[i],a[j],a[k])){
                    //cout<<i<<" "<<j<<" "<<k<<endl;
                    cnt++;
                }
            }
        }
    }
    cout<<cnt<<endl;

    return 0;
}




Measured memory_bytes: 3600
#include "bits/stdc++.h"
using namespace std;
#define long int64_t

struct Solver {
	void solve() {
		int N;
		cin >> N;

		long sum = 0;
		vector<int> cnt( 100001 );
		for( int i = 0; i < N; ++i ) {
			int a;
			cin >> a;
			sum += a;
			cnt[a] += 1;
		}

		int Q;
		cin >> Q;
		while( Q-- ) {
			int B, C;
			cin >> B >> C;
			int x = cnt[B];
			cnt[B] = 0;
			cnt[C] += x;
			sum += C*x - B*x;
			cout << sum << '\n';
		}
	}
};

int main() {
	ios::sync_with_stdio( false );
	cout << fixed << setprecision( 10 );
	Solver().solve();
	return 0;
}


Measured memory_bytes: 3756
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<algorithm>
#include<iostream>
#include<bitset>
#include<functional>
#include<numeric>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<cassert>
#include<cmath>
#include<random>
#include<ctime>
#include<complex>
using namespace std;
typedef long long LL;
mt19937 gene(233);
typedef complex<double> Complex;
#define fi first
#define se second
#define ins insert
#define pb push_back
inline char GET_CHAR(){
	const int maxn = 131072;
	static char buf[maxn],*p1=buf,*p2=buf;
	return p1==p2&&(p2=(p1=buf)+fread(buf,1,maxn,stdin),p1==p2)?EOF:*p1++;
}
inline int getInt() {
	int res(0);
	char c = getchar();
	while(c < '0') c = getchar();
	while(c >= '0') {
		res = res * 10 + (c - '0');
		c = getchar();
	}
	return res;
}

inline int fastpo(int x, int n, int mod) {
	int res(1);
	while(n) {
		if(n & 1) {
			res = res * (LL)x % mod;
		}
		x = x * (LL) x % mod;
		n /= 2;
	}
	return res;
}

inline string itoa(int x, int width = 0) {
  string res;
  if(x == 0) res.push_back('0');
  while(x) {
    res.push_back('0' + x % 10);
    x /= 10;
  }
  while((int)res.size() < width) res.push_back('0');
  reverse(res.begin(), res.end());
  return res;
}

const int N = 59049 * 9;
const int LOG = 20;
const int mod = 1e9 + 7;
const int inf = 1e9 + 7;
int n, m;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int s[N * 2][3], num[N * 2];
int np = 0;
inline void app(string & s) {
	if(!s.empty() && s.back() == 'S') {
		s.pop_back();
	}else s.push_back('S');
}
int build(int dep, int cur, int pw) {
	int res = ++np;
	if(dep < n) {
		s[res][0] = build(dep + 1, cur, pw * 3);
		s[res][1] = build(dep + 1, cur + pw, pw * 3);
		s[res][2] = build(dep + 1, cur + pw * 2, pw * 3);
	}else {
		num[res] = cur;
		//cout << np << ' ' << cur << endl;
	}
	return res;
}
int _ = 0;
void process(int v, const string & t) {
	if(s[v][0] == 0) return;
	
	_ += t.size();
	string s[3];
	for(char c : t) {
		if(c == 'S') {
			for(int d = 0; d < 3; d++) app(s[d]);
			swap(s[1], s[2]);
			swap(::s[v][1], ::s[v][2]);
		}else {
			s[2].push_back('R');
			swap(s[1], s[2]);
			swap(s[0], s[1]);
			swap(::s[v][1], ::s[v][2]);
			swap(::s[v][0], ::s[v][1]);
		}
		/*for(int d = 0; d < 3; d++) {
			printf("s[%d][%d] = %d\n", v, d, ::s[v][d]);
		}*/
	}
	for(int d = 0; d < 3; d++) {
		process(::s[v][d], s[d]);
	}
}
vector<int> ans;
void dfs(int v, int cur, int pw) {
	if(s[v][0] == 0) {
		ans[num[v]] = cur;
	}else {
		for(int d = 0; d < 3; d++) {
			//printf("s[%d][%d] = %d\n", v, d, s[v][d]);
			dfs(s[v][d], cur + pw * d, pw * 3);	
		}
	}
}
int main() {
	scanf("%d", &n);
	string t;
	cin >> t;
//t.clear();
//for(int i = 0; i < 200000; i++) t.push_back(i % 2 ? 'S' : 'R');
	build(0, 0, 1);
	process(1, t);
	ans.resize(fastpo(3, n, mod));
	dfs(1, 0, 1);
	for(int i = 0; i < (int)ans.size(); i++) printf("%d%c", ans[i], i == (int)ans.size() - 1 ? '\n' : ' ');
	//cout << clock() << endl;
	//cout << _ << endl;
}




Measured memory_bytes: 18984
#include <ctype.h>
#include <string>
#include <iostream>
using namespace std;
int main()
{
	string s;
	cin >> s;
	if (s[0] != 'A') {
		cout << "WA" << endl;
		return 0;
	}
	int tmp;
	bool b = 0;
	for (int i = 2; i < s.length(); i++)
	{
		if (s[i] == 'C') {
			b = 1;
			tmp = i;
		}
	}
	if (!b) {
		cout << "WA" << endl;
		return 0;
	}
	for (int i = 1; i < s.length(); i++) {
		if (i == tmp) continue;
		if (isupper(s[i])) {
			cout << "WA" << endl;
			return 0;
		}
	}
	if (s[s.length() - 1] == 'C') {
		cout << "WA" << endl;
		return 0;
	}
	cout << "AC" << endl;
    return 0;
}



Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        int[][] ary1 = new int[n][2];
        for (int i = 0; i < n; i++) {
            ary1[i][0] = sc.nextInt();
            ary1[i][1] = sc.nextInt();
        }
        int[][] ary2 = new int[m][2];
        for (int i = 0; i < m; i++) {
            ary2[i][0] = sc.nextInt();
            ary2[i][1] = sc.nextInt();
        }
        
        for (int i = 0; i < n; i++) {
            int ans = -1;
            int min = 1000000000;
            for (int j = 0; j < m; j++) {
                int tmp = (int)Math.abs(ary1[i][0] - ary2[j][0]) + Math.abs(ary1[i][1] - ary2[j][1]);
                if (tmp < min) {
                    min = tmp;
                    ans = j;
                }
            }
            System.out.println(ans+1);
        }
    }
}


Measured memory_bytes: 21844
#include <algorithm>
#include <iostream>
#include <vector>

int main()
{
	constexpr int MAX_NUMBER = 3;

	std::vector<int> numberVec(MAX_NUMBER);

	for (int index = 0; index < MAX_NUMBER; ++index)
	{
		int num = 0;
		std::cin >> num;
		numberVec.at(index) = num;
	}

	std::sort(numberVec.begin(), numberVec.end());

	// 2つが等しく残りの1つが等しいとき、
	// vec[1]はvec[0]かvec[2]のいずれかと必ず等しくなる
	if (numberVec.at(1) != numberVec.at(0) && numberVec.at(1) != numberVec.at(2))
	{
		std::cout << "No" << std::endl;
		return 0;
	}

	// ここまで到達し、vec[0] == vec[2]ならすべて等しいのでNo
	if (numberVec.at(0) == numberVec.at(2))
	{
		std::cout << "No" << std::endl;
		return 0;
	}

	std::cout << "Yes" << std::endl;
}



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

const int maxn = 2e5 + 5;

int n, k, l, u, v, visited[maxn], comp[maxn], sz[maxn];
vector<int> adj[2][maxn];   // adj[road / rail]

void dfs(int x, int type, int compid, vector<int>& cities)
{
    visited[x] = 1;
    if(type == 0)
        comp[x] = compid;
    else
        cities.push_back(x);
    for(auto v : adj[type][x])
        if(!visited[v])
            dfs(v, type, compid, cities);
}

int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> k >> l;
    for(int i = 0; i < k; i++)
    {
        cin >> u >> v;
        u--; v--;
        adj[0][u].push_back(v);
        adj[0][v].push_back(u);
    }
    for(int i = 0; i < l; i++)
    {
        cin >> u >> v;
        u--; v--;
        adj[1][u].push_back(v);
        adj[1][v].push_back(u);
    }
    for(int i = 0; i < n; i++)
    {
        visited[i] = 0;
        comp[i] = -1;
        sz[i] = 0;
    }
    int curcomp = 0;
    vector<int> cities;
    for(int i = 0; i < n; i++)
        if(!visited[i])
        {
            dfs(i, 0, curcomp, cities);
            curcomp++;
        }
    assert(cities.empty());
    for(int i = 0; i < n; i++)
        visited[i] = 0;
    for(int i = 0; i < n; i++)
        if(!visited[i])
        {
            dfs(i, 1, -1, cities);
            vector<pii> order;
            for(auto x : cities)
                order.push_back({comp[x], x});
            sort(order.begin(), order.end());
            for(int i = 0; i < order.size(); )
            {
                int j = i;
                while(j < order.size() && order[j].first == order[i].first)
                    j++;
                int compsz = (j - i);
                for(int cur = i; cur < j; cur++)
                {
                    assert(sz[order[cur].second] == 0);
                    sz[order[cur].second] = compsz;
                }
                i = j;
            }
            cities.clear();
        }
    for(int i = 0; i < n; i++)
        assert(comp[i] != -1 && sz[i] != 0);
    for(int i = 0; i < n; i++)
        cout << sz[i] << " ";
    cout << "\n";
    return 0;
}

Measured memory_bytes: 26536
N = int(input())
def f(a,count):
    a2 = 10**a
    if a2 <= N:
        if a % 2 == 1:
            count = count + a2 - (10**(a-1))
        return f(a+1,count)
    else:
        if a % 2 == 1:
            return count+ (N- (10**(a-1))) + 1
        else:
            return count
print(f(1,0))

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = (0); i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(x) (x).begin(),(x).end()
#define rrng(x) (x).rbegin(),(x).rend()
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define show(x) cout << #x << " = " << (x) << endl
#define show2(x,y) cout << #x << " = " << (x) << ", " << #y << " = " << (y) << endl
#define show3(x,y,z) cout << #x << " = " << (x) << ", " << #y << " = " << (y) <<  ", " << #z << " = " << (z) << endl
#define showv(v) rep(i,v.size()) printf("%d%c", v[i], i==v.size()-1?'\n':' ')
#define showv2(v) rep(j,v.size()) showv(v[j])
#define showt(t,n) rep(i,n) printf("%d%c", t[i], i==n-1?'\n':' ')
#define showt2(t,r,c) rep(j,r) showt(t[j],c)
#define showvp(p) rep(i,p.size()) printf("%d %d\n", p[i].first, p[i].second);
#define printv(v) rep(i,v.size()) printf("%d\n", v[i])
#define printt(t,n) rep(i,n) printf("%d\n", t[i])
#define incl(v,x) find(rng(v),x)!=v.end()
#define incls(s,c) s.find(c)!=string::npos
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define bit(n,k) ((n>>k)&1) // nのk bit目
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define uni(x) x.erase(unique(rng(x)),x.end())
#define SP << " " <<
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vs = vector<string>;
using P = pair<int, int>;
using T = tuple<int, int, int>;
using vp = vector<P>;
using vt = vector<T>;
const int mod = 1000000007;
const double EPS = 1e-9;
const int INF = (1<<30)-1;
//const ll INF = (1LL<<62)-1;
#define dame { puts("No"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
inline int in() { int x; scanf("%d",&x); return x;}
template<typename T>inline ll suma(const v(T)& a) { ll res(0); for (auto&& x : a) res += x; return res;}
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; }
//1 2 3 3
int main () {
  int n;
  cin >> n;
  set<int> st;
  rep(i,n) {
    int a;
    cin >> a;
    st.insert(a);
  }
  int k = st.size();
  int ans = (k&1 ? k : k-1);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 4992
k = int(input())
gcd = [[0]*k for _ in range(k)]
def f(a,b):
    if a == b:
        return a
    else:
        if a > b:
            return f(a-b,b)
        else:
            return f(b-a,a)
for a in range(k):
    for b in range(k):
        gcd[a][b]=f(a+1,b+1)

ans = 0
for a in range(k):
    for b in range(k):
        for c in range(k):
            ans += gcd[gcd[a][b]-1][c]
        
print(ans)

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

template <typename T>
T gcd(T a, T b){ return b%a==0 ? a : gcd(b%a, a); }

template <typename T>
T lcm(T a, T b){ return (a/gcd(a, b))*b; }

int main()
{    
    i64 n,m;
    cin >> n >> m;
    vector<i64> a(n);
    rep(i,n) cin >> a[i];

    i64 g = 1;
    rep(i,n)
    {
        g = lcm<i64>(g, a[i]/2);
        if(g > m)
        {
            cout << 0 << endl;
            return 0;
        }
    }

    rep(i,n)
    {
        if((g/(a[i]/2))%2 == 0)
        {
            cout << 0 << endl;
            return 0;
        }
    }

    int cnt = (m/g+1)/2; 

    cout << cnt << endl;
    return 0;
}

Measured memory_bytes: 1024
#include<stdio.h>
#include<algorithm>
using namespace std;
int main(){
	int a,b;
	scanf("%d%d",&a,&b);
	int r=0;
	int l=0;
	for(int i=0;i<a;i++){
		int c,d;scanf("%d%d",&c,&d);
		b=b+c-d;
		r=max(r,b);
		l=min(l,b);
	}
	if(l<0)printf("0\n");
	else printf("%d\n",r);
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int a[n+2];
    int i, cnt = 0, mx = 0;
    for(i = 0; i < n; i++)
        cin>>a[i];
    for(i = 0; i < n-1; i++)
    {
        if(a[i] >= a[i+1])
        {
            while(a[i] >= a[i+1])
            {
                cnt++;
                i++;
                if(i == n - 1)
                    break;
            }
            mx = max(mx, cnt);
            cnt = 0;
        }
    }
    cout<<mx<<endl;
    return 0;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <stdlib.h>

void msort();
void merge();

void mergesort(long deta[], int size){
	long temp[size];
	msort(deta, temp, 0, size-1);
}

void msort(long date[], long temp[], int left, int right){
	int mid;

	if(left >= right) return;
	else{
		mid = (left + right)/2;

		msort(date, temp, 	 left, mid  );
		msort(date, temp, mid + 1, right);

		merge(date, temp, left, mid, right);		
	}
}

void merge(long date[], long temp[], int left, int mid, int right){
	int i, j, tmp_pos;

	i = left;
	j = mid + 1;

	tmp_pos = left;

	while(i<=mid && j<=right){
		if(date[i] > date[j]){
			temp[tmp_pos] = date[j];
			j++;
			tmp_pos++;
		}else{
			temp[tmp_pos] = date[i];
			i++;
			tmp_pos++;
		}
	}

	while(i<=mid){
		temp[tmp_pos] = date[i];
		i++;
		tmp_pos++;
	}

	while(j<=right){
		temp[tmp_pos] = date[j];
		j++;
		tmp_pos++;
	}

	for(i=left; i<=right; i++){
		date[i] = temp[i];
	}
}

int main(){
	long A[100000];
	int i,N,now,result,ct;

	scanf("%d", &N);

	for(i=0; i<N; i++){
		scanf("%ld", &A[i]);
	}

	mergesort(A,N);

	i = 0;
	result = 0;

	while(i<N){
		now = A[i];

		ct = 1;
		i++;
		while(A[i] == now){
			ct++;
			i++;
		}
		if(ct%2 == 1) result++;

	}

	printf("%d\n", result);

  return 0;
}

Measured memory_bytes: 1664
#pragma GCC optimize("Ofast")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")
#pragma GCC target("avx")
#include <bits/stdc++.h>
using namespace std;
static const int rdata_sz = (1 << 22), wdata_sz = (1 << 22);
    char rdata[rdata_sz], wdata[wdata_sz], *rb, *wb;
struct FastIO
{
    FastIO()
    {
        fread(rdata, 1, rdata_sz, stdin);
        rb = rdata;
        wb = wdata;
    }
    ~FastIO()
    {
        fwrite(wdata, 1, wb - wdata, stdout);
    }

    template <typename T>
    inline void read(T &x)
    {
        bool neg = false;
        x = 0;
        while ((*rb < '0' || *rb > '9') && *rb != '-')
            ++rb;
        while ('0' <= *rb && *rb <= '9')
        {
            x = 10 * x + (*rb - '0');
            ++rb;
        }
        if (neg)
            x = -x;
    }
};
#define pc(x) *(wb++) = x
int par[500001];
int ran[500001];
//要素xが所属する木の根を再帰的に発見する
inline int root(int x)
{
    if (par[x] == x)
        return x;
    return par[x] = root(par[x]); //経路圧縮
}
//要素xが属する木と要素yが属する木の併合
inline void unite(int x, int y)
{
    int rx = root(x);
    int ry = root(y);
    if (rx == ry)
        return; //同じ木に属してたらそのまま
    if (ran[rx] < ran[ry])
    {
        par[rx] = ry; //根がryの木に併合
    }
    else
    {
        par[ry] = rx; //根がrxの木に併合
        if (ran[rx] == ran[ry])
            ran[rx]++;
    }
}
//要素xが属する木と要素yが属する木が同じならtrueを返す
inline bool same(int x, int y)
{
    return root(x) == root(y);
}
int main()
{
    FastIO io;
    int N, Q;
    io.read(N);
    io.read(Q);
    for (int i = 0; i < N; i++)
    {
        par[i] = i;
        ran[i] = 0;
    }
    for (int i = 0; i < Q; i++)
    {
        int a, b, c;
        io.read(a);
        io.read(b);
        io.read(c);
        if (a == 1)
            if (same(b, c)){
              pc('1');
              pc(' ');
            }
            else{
              pc('0');
              pc(' ');
            }
        if (a == 0)
            unite(b, c);
    }
    return 0;
}


Measured memory_bytes: 7236
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.lang.reflect.Array;
import java.util.*;


public class Main {
    
         
    static FastReader in;
    static StringBuilder out;
    
    public  static void main(String[] args) {
        
        in = new FastReader();
        int k=in.nextInt();
        String n=in.nextLine();
        if(n.length()>k){
            System.out.println(n.substring(0,k)+"...");
        }else{
            System.out.println(n);
        }
    }
    static class FastReader {
        BufferedReader br;
        StringTokenizer st;
 
        public FastReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
 
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
 
        int nextInt() {
            return Integer.parseInt(next());
        }
 
        long nextLong() {
            return Long.parseLong(next());
        }
 
        double nextDouble() {
            return Double.parseDouble(next());
        }
 
        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
 
     
    
}

Measured memory_bytes: 36416
N,K,Q= map(int,input().split())
A = []
point = [K-Q]*N
for i in range(Q):
    A.append(int(input()))

for j in A:
    point[j-1] +=1
# print(point)

for k in point:
    if k > 0:
        print("Yes")
    else:
        print("No")

Measured memory_bytes: 10452
/*
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⣴⣄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⢀⠀⠀⠺⣿⣿⠃⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⢀⣀⣀⣀⠀⠈⢿⣦⣄⣈⣁⣀⣠⣴⣦⡀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⣠⣶⣿⣿⣿⣿⣿⣿⣶⡄⠙⢿⣿⣿⣿⣿⣿⡿⠓⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠙⣿⣿⠿⠛⠛⠛⠛⣿⣿⡄⠀⠈⠉⠉⠉⣁⣀⡀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠈⠁⠀⠀⠀⠀⠀⣸⣿⡇⠀⠀⠀⣴⣿⣿⡿⠿⢷⣄⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠠⣤⣤⣴⣾⣿⡿⠁⠀⢀⣾⣿⣿⠏⠀⠀⠈⣿⣧⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠹⣿⣿⣿⣏⠀⠀⣠⣾⣿⣿⠏⠀⠀⠀⠀⢹⣿⡄⠀⠀
⠀⠀⢀⠀⠀⠀⠀⠀⠀⠀⠉⠉⠻⣿⣿⡟⠻⠿⠛⠁⠀⠀⠀⠀⠀⣾⣿⡇⠀⠀
⠀⠀⠘⡄⠀⠀⠀⠀⠀⠀⠀⠀⠀⠘⣿⣿⡄⠀⣄⠀⠀⠀⠀⠀⣰⣿⣿⠇⠀⠀
⠀⠀⠀⢿⡄⠀⠀⠀⠀⠀⠀⠀⠀⣰⣿⣿⠇⠀⠹⣷⣤⣤⣤⣾⣿⣿⡟⠀⠀⠀
⠀⠀⠀⠈⢿⣦⣄⣀⠀⠀⣀⣠⣾⣿⣿⡟⠀⠀⠀⠘⠻⣿⣿⣿⠿⠋⠀⠀⠀⠀
⠀⠀⠀⠀⠈⠻⣿⣿⣿⣿⣿⣿⣿⡿⠏⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠉⠙⠛⠛⠛⠉⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀
⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀⠀

           KRISHNA ASHOK⠀
*/

#include <bits/stdc++.h>
using namespace std;

//#include <ext/pb_ds/assoc_container.hpp>
//#include <ext/pb_ds/tree_policy.hpp>
//using namespace __gnu_pbds; 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> Tree;
// order_of_key(k), find_by_order(k)


#define dbg(x) cout<<#x<<"="<<x<<'\n'
#define ll long long
#define pr pair<int,int>
#define pb push_back
#define ff first
#define ss second
#define vi vector<int>
#define For(i,n) for(int i=0;i<(n);++i)
#define Forr(i,n) for(int i=n-1;i>=0;i--)
#pragma GCC optimization("Ofast")
#pragma GCC optimization("unroll-loops")
#define fin ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define MOD 1000000007
#define all(x) (x).begin(),(x).end()
#define sz(a) (int)a.size()
#define Fill(a,b) memset(a,b,sizeof(a));
#define fileio freopen("http://in.in", "r", stdin),freopen("out.out", "w", stdout);
const int INF=1e9;
//#define endl '\n'
#define fit(i,x) for(auto i:x)
#define gcd(a,b) __gcd(a,b)
#define Max(a,b) a=max(a,b)
#define Min(a,b) a=min(a,b)
#define vt vector
#define ppr pair<int,pair<int,int>>



void solve(){
	string s,t;
	cin>>s>>t;
	int ans=0;
	for(int i=0;i<sz(s);i++){
		if(s[i]!=t[i])ans++;
	}
	cout<<ans<<endl;
}



int main()
{
    fin;
    int t=1;
    //cin>>t;
    while(t--){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3792
import sys

input_methods=['clipboard','file','key']
using_method=0
input_method=input_methods[using_method]

IN=lambda : map(int, input().split())
mod=1000000007

#+++++

def main():
	n = int(input())
	al = list(IN())
	bl=list(IN())
	mm=[]
	for i in range(n):
		mm.append([0,0])
	im=0
	for i, h in enumerate(al):
		if im < h:
			mm[i] = [h,h]
			im=h
		else:
			mm[i] = [1,h]
	jm=0
	for i, h in enumerate(bl[::-1]):
		j=n-i-1
		if jm < h:
			if mm[j][0]<= h and h <= mm[j][1]:
				mm[j] = [h,h]
				jm=h
			else:
				return 0
		else:
			if mm[j][0]<= h and h <= mm[j][1]:
				mm[j][1]=h
			elif h < mm[j][0]:
				return 0
			else:
				pass
	r=1
	for a,b in mm:
		r *= (b-a+1)
		r %= mod
	print(r)
		
	
	
	
#+++++
isTest=False

def pa(v):
	if isTest:
		print(v)
		
def input_clipboard():
	import clipboard
	input_text=clipboard.get()
	input_l=input_text.splitlines()
	for l in input_l:
		yield l

if __name__ == "__main__":
	if sys.platform =='ios':
		if input_method==input_methods[0]:
			ic=input_clipboard()
			input = lambda : ic.__next__()
		elif input_method==input_methods[1]:
			sys.stdin=open('inputFile.txt')
		else:
			pass
		isTest=True
	else:
		pass
		#input = sys.stdin.readline
			
	ret = main()
	if ret is not None:
		print(ret)

Measured memory_bytes: 98916
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <iterator>
#include <numeric>
#include <cstdint>
#include <cmath>
#include <bitset>
#include <string>
#include <list>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>

#define N_TIMES(i, n)     for ( uint64_t i = 0;     i <  n; ++i )
#define N_TIMES_REV(i, n) for (  int64_t i = n - 1; i >= 0; --i )

using namespace std;

const uint64_t INF = 1e+18;

struct Edge
{
  uint64_t A, B;
  Edge(uint64_t A = INF, uint64_t B = INF) : A(A), B(B) {}
};

istream& operator>>(istream &is, Edge &edge)
{
  is >> edge.A >> edge.B;
  return is;
}

struct Exchange
{
  uint64_t C, D;
  Exchange(uint64_t C = INF, uint64_t D = INF) : C(C), D(D) {}
  long double rate() const {
    return static_cast<long double>(C) / static_cast<long double>(D);
  }
  bool operator<(const Exchange &ex) const {
    return C * ex.D < D * ex.C;
  }
};

istream& operator>>(istream &is, Exchange &exchange)
{
  is >> exchange.C >> exchange.D;
  return is;
}

struct SearchItem
{
  uint64_t pos, silver, time;
  SearchItem(uint64_t pos, uint64_t silver, uint64_t time)
    : pos(pos), silver(silver), time(time) {}
  bool operator<(const SearchItem &item) const {
    return time > item.time;
  }
};

int main()
{
  uint64_t N, M, S;
  cin >> N >> M >> S;

  uint64_t A_max = 0;
  vector<vector<Edge>> edges(N, vector<Edge>(N));
  N_TIMES(m, M) {
    uint64_t U, V;
    Edge E;

    cin >> U >> V >> E;
    --U; --V;
    edges[U][V] = E;
    edges[V][U] = E;
    A_max = max(A_max, E.A);
  }

  vector<Exchange> exchanges(N);
  N_TIMES(n, N) { cin >> exchanges[n]; }

  vector<vector<uint64_t>> times(N, vector<uint64_t>(A_max * N, INF));
  if (S > A_max * N) { S = A_max * N - 1; }
  times[0][S] = 0;

  priority_queue<SearchItem> q;
  q.emplace(0, S, 0);

  while (!q.empty()) {
    SearchItem item = q.top(); q.pop();
    if (item.time == INF) { continue; }

    // 移動
    N_TIMES(v, N) {
      Edge edge = edges[item.pos][v];
      // 線路があり，かつ運賃を支払える
      if ((edge.B != INF) && (edge.A <= item.silver)) {
        SearchItem new_item(v, item.silver - edge.A, item.time + edge.B);
        if (new_item.time < times[new_item.pos][new_item.silver]) {
          times[new_item.pos][new_item.silver] = new_item.time;
          q.push(new_item);
        }
      }
    }

    // 両替
    Exchange exchange = exchanges[item.pos];
    if (item.silver + exchange.C < A_max * N) {
      SearchItem new_item(item.pos, item.silver + exchange.C, item.time + exchange.D);
      if (new_item.time < times[new_item.pos][new_item.silver]) {
        times[new_item.pos][new_item.silver] = new_item.time;
        q.push(new_item);
      }
    }
  }

  for (uint64_t n = 1; n < N; ++n) {
    uint64_t ans = INF;
    N_TIMES(s, A_max * N) { ans = min(ans, times[n][s]); }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 7448
use std::io::*;

fn main() {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    let mut iter = line.trim().split_whitespace();
    let (a, p) = (
        iter.next().unwrap().parse::<i32>().unwrap(),
        iter.next().unwrap().parse::<i32>().unwrap(),
    );

    let ap = a * 3 + p;
    println!("{}", if ap == 0 { 0 } else { ap / 2 });
}

Measured memory_bytes: 4352
n = int(input())
A = [list(map(int,input().split())) for _ in range(2)]

ans = 0
for i in range(n):
  cnt = 0
  for j in range(n):
    if j <= i:
      cnt += A[0][j]
    if j >= i:
      cnt += A[1][j]
  ans = max(ans,cnt)
print(ans)


Measured memory_bytes: 3060
import sys

sys.setrecursionlimit(10**7)
def I(): return int(sys.stdin.readline().rstrip())
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり
def LI2(): return list(map(int,sys.stdin.readline().rstrip()))  #空白なし
def S(): return sys.stdin.readline().rstrip()
def LS(): return list(sys.stdin.readline().rstrip().split())  #空白あり
def LS2(): return list(sys.stdin.readline().rstrip())  #空白なし


S = LS2()
if S[0] == S[1] == S[2] == S[3]:
    print('No')
elif S[0] == S[1] and S[2] == S[3]:
    print('Yes')
elif S[0] == S[2] and S[1] == S[3]:
    print('Yes')
elif S[0] == S[3] and S[1] == S[2]:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 61768
#include <bits/stdc++.h>
using namespace std;
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
//#define int long long
#define ll long long
#define ull unsigned long long
#define ld long double
#define vl vector<long long>
#define vvl vector<vector<long long>>
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define drep(i, x) for (ll i = ((ll)(x)-1); i >= 0; i--)
#define pll pair<long long,long long>
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define vvc vector<vector<char>>
#define vc vector<char>
#define vvb vector<vector<bool>>
#define vb vector<bool>
#define Maxe(x) *max_element(all(x))
#define Mine(x) *min_element(all(x))
#define Size(x) ((ll)(x).size())
#define umap unordered_map
const long long INF = 1LL << 60;
const long double pi = 3.1415926535897932;
#define Fi first
#define Se second
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

    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;
    }

//lis,modpow,uf,modncr,soinsubunkai,yakusurekkyo
//mint,dijkstra,gyakugen

    signed main(){
        ios::sync_with_stdio(false);
        cin.tie(nullptr);
        string s;
        cin>>s;
        cout<<s[0]<<s[1]<<s[2]<<endl;
    }

Measured memory_bytes: 3636
#include <iostream>
#include <bits/stdc++.h>
#include <string>
#include <math.h>
#include <vector>
using namespace std;

int main(){
  int h,a; cin>>h>>a;
  if(h%a==0) cout<<h/a<<endl;
  else cout<<h/a+1<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef double db;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> pii;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pw(x) (1ll << (x))
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define rep(i,l,r) for(int i=(l);i<(r);++i)
#define per(i,l,r) for(int i=(r)-1;i>=(l);--i)
#define dd(x) cout << #x << " = " << x << ", "
#define de(x) cout << #x << " = " << x << endl

//-----
const int N = 2e5 + 7, MOD = 1e9 + 7;
int add(int a, int b) { if ((a += b) >= MOD) a -= MOD; return a; }
int mul(int a, int b) { return a * 1ll * b % MOD; }
int qpow(int a, int b) {
	int r = 1;
	for (; b; b >>= 1) {
		if (b & 1) r = mul(r, a);
		a = mul(a, a);
	}
	return r;
}
int jc[N], ijc[N];
void pre() {
	jc[0] = 1; 
	rep(i, 1, N) jc[i] = mul(jc[i - 1], i);
	ijc[N - 1] = qpow(jc[N - 1], MOD - 2); 
	per(i, 0, N - 1) ijc[i] = mul(ijc[i + 1], i + 1);
}
int C(int n, int m) {
	return mul(jc[n], mul(ijc[n - m], ijc[m]));
}
int gao(int n, int m) { return C(n + m - 2, n - 1); }
int h, w, a, b;
int main() {
	std::ios::sync_with_stdio(false);
	std::cin.tie(0);
	pre();
	//rep(i, 0, 10) rep(j, 0, i + 1) cout << C(i, j) << " \n"[j == i];
	cin >> h >> w >> a >> b;
	int ans = 0;
	rep(i, b + 1, w + 1)
		ans = add(ans, mul(gao(h - a, i), gao(a, w - i + 1)));
	cout << ans;
	return 0;
}

Measured memory_bytes: 1792