akhauriyash/Code-Regression huggingface dataset:
A,B,C,X,Y = map(int,input().split())
ans = 0
if((A+B)<C*2):
    ans += A*X
    ans += B*Y
    print(ans)
else:
    min_value=min(X,Y)
    ans+=C*min_value*2
    X-=min_value
    Y-=min_value
    if(A>=C*2):
        ans+=C*X*2
    else:
        ans+=A*X
    if(B>=C*2):
        ans+=C*Y*2
    else:
        ans+=B*Y
    print(ans)
    

Measured memory_bytes: 9052
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int x,y;
    cin>>x>>y;
    char a[x][y];
    for(int i=0;i<x;i++)
        for(int j=0;j<y;j++)
        cin>>a[i][j];

    for(int i=0;i<y+2;i++)
        cout<<"#";
    cout<<endl;

    for(int i=0;i<x;i++){
            cout<<"#";
        for(int j=0;j<y;j++)
        cout<<a[i][j];
    cout<<"#\n";

    }
   for(int i=0;i<y+2;i++)
        cout<<"#";
    return 0;
   }

Measured memory_bytes: 3628
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(int i=0;i<N;++i)
typedef long long int LL;

int a[3];
int main()
{
	in>>a[0]>>a[1]>>a[2];
	std::sort(a,a+3);
	if(a[0]!=a[1]){out<<a[0]<<std::endl;}
	else{out<<a[2]<<std::endl;}
	return 0;
}


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

dp = [False] * (K + 1)

for i in range(K + 1):
    for j in range(N):
        if i - A[j] >= 0:
            dp[i] |= not dp[i - A[j]]

if dp[K]:
    print('First')
else:
    print('Second')

# print(dp)


Measured memory_bytes: 43724
#include<bits/stdc++.h>
#define fs first
#define sc second
#define MOD 1000000007
#define N 200123
#define endl '\n'
#define mk make_pair
#define ll long long
#define ii pair<ll, ll>
#define pb push_back

using namespace std;

struct fish {
    ii ab, ba;
    
    fish() {}
    fish(ll a, ll b) { 
        ll gcd = __gcd(abs(a), abs(b));
        a /= gcd;
        b /= gcd;
        if(a < 0) {
            a *= -1;
            b *= -1;
        }

        ab = mk(a, b);
        if(b < 0) {
            ba = mk(-b, a);
        }
        else {
            ba = mk(b, -a);
        }
    }
} nemo;

vector<fish> v;
map<ii, int> f;
int n, zz, zy, xz;
ll x, y, ans, p, power[N];

int main() {
    ios_base::sync_with_stdio(0);

    cin >> n;

    power[0] = 1;

    for(int i=1; i <= n; ++i) {
        power[i] = (power[i - 1] * 2LL) % MOD;
    }

    for(int i=0; i < n; ++i) {
        cin >> x >> y;
        if(!x && !y) {
            zz++;
        }
        else if(!x) {
            xz++;
        }
        else if(!y) {
            zy++;
        }
        else {
            nemo = fish(x, y);
            f[nemo.ab]++;
            v.pb(nemo);
        }
    }

    ans = 1;

    for(fish dory : v) {
        if(f[dory.ab]) {
            p = (power[f[dory.ab]] + power[f[dory.ba]] - 1 + MOD) % MOD;
            ans = (ans * p) % MOD;
            f[dory.ba] = f[dory.ab] = 0;
        }
    }

    p = (power[zy] + power[xz] - 1 + MOD) % MOD;
    ans = (ans * p) % MOD;

    ans = (ans + zz - 1 + MOD) % MOD;

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


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

int main() {
    ll k;
    cin >> k;

    vector<ll> a(50);
    rep(i, 50) a[i] = 49 + k / 50;
    k %= 50LL;

    rep(i, k) {
        a[i] += 50+1;
        rep(j, 50) a[j]--;
    }

    cout << 50 << endl;
    for (auto t : a) cout << t << " ";
    cout << endl;
}


Measured memory_bytes: 384
#include <iostream>
using namespace std;
 
int main() {
    int K, S;
    int x, y, z;
    int cnt = 0;

    cin >> K >> S;

    for (x = 0; x <= K; ++x){
      for (y = 0; y <= K; ++y){
          if (S - x - y <= K && S - x - y >= 0) cnt++;
      }
    }
    cout << cnt << endl;
}

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


int main(){
  int N;
  cin >> N;
  vector<int> L(N);
  rep(i,N){cin >> L.at(i);}

  sort(L.begin(),L.end());
  
  int ans = 0;
  for(int b = 1; b<N; b++){
    for (int a = 0; a<b; a++){ // ここでaの範囲をbの左で制限しておくことで探索範囲が少し減る？bを固定して左をa、右を二分探索で調べる形
      int ab = L[a]+L[b];
      int r = lower_bound(L.begin(),L.end(),ab) - L.begin();
      //lower_boundの返り値はイテレータなのでLの頭のイテレータを減算することでインデックスに変換
      int l = b+1;

      // c = [l,r)
      ans += max(0,r-l);
    }
  }
  cout << ans << endl;
}

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


#define li          long long int
#define rep(i,to)   for(li i=0;i<((li)(to));i++)
#define repp(i,start,to)    for(li i=(li)(start);i<((li)(to));i++)
#define pb          push_back
#define sz(v)       ((li)(v).size())
#define bgn(v)      ((v).begin())
#define eend(v)     ((v).end())
#define allof(v)    (v).begin(), (v).end()
#define dodp(v,n)       memset(v,(li)n,sizeof(v))
#define bit(n)      (1ll<<(li)(n))
#define mp(a,b)     make_pair(a,b)
#define rin rep(i,n)
#define EPS 1e-12
#define ETOL 1e-8
#define MOD 1000000007
typedef pair<li, li> PI;

#define INF bit(60)

#define DBGP 1


#define idp if(DBGP)
#define F first
#define S second
#define p2(a,b)     idp cout<<a<<"\t"<<b<<endl
#define p3(a,b,c)       idp cout<<a<<"\t"<<b<<"\t"<<c<<endl
#define p4(a,b,c,d)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<endl
#define p5(a,b,c,d,e)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<endl
#define p6(a,b,c,d,e,f)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<endl
#define p7(a,b,c,d,e,f,g)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<endl
#define p8(a,b,c,d,e,f,g,h)     idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<endl
#define p9(a,b,c,d,e,f,g,h,i)       idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<endl
#define p10(a,b,c,d,e,f,g,h,i,j)        idp cout<<a<<"\t"<<b<<"\t"<<c<<"\t"<<d<<"\t"<<e<<"\t"<<f<<"\t"<<g<<"\t"<<h<<"\t"<<i<<"\t"<<j<<endl
#define foreach(it,v)   for(__typeof((v).begin()) it=(v).begin(); it!=(v).end(); ++it)
#define p2p(x)      idp p2((x).F, (x).S)
#define dump(x,n)   idp{rep(i,n){cout<<x[i]<<" ";}puts("");}
#define dump2(x,n)  idp{rep(i,n){cout<<"["<<x[i].F<<" , "<<x[i].S<<"] ";}puts("");}
#define dumpi(x)    idp{foreach(it, x){cout<<(*it)<<" ";}puts("");}
#define dumpi2(x)   idp{foreach(it, x){cout<<"["<<(it)->F<<" , "<<(it)->S<<"] ";}puts("");}

#define read2d(a,w,h)   rep(i,h)rep(j,w)cin>>a[i][j]
#define dump2d(a,w,h)   rep(i,h){rep(j,w)cout<<a[i][j]<<" ";puts("");}

typedef pair<li, li> PI;


string ans = "AKIHABARA";

inline bool ok(string s) {
    string ss;
    rep(i, sz(s)) {
        if (s[i] != 'A')ss = ss + s[i];
    }
    if (ss != "KIHBR") {
        return false;
    }
    if (s.find("KIH") == string::npos) {
        return false;
    }
    if (s.find("AA") != string::npos) {
        return false;
    }
    return true;
}

int main() {
    string s;
    cin >> s;
    cout << (ok(s) ? "YES" : "NO") << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const int INF = 1e9;

signed main(){
  int n, c; cin >> n >> c;
  vector<vector<int> > data(3, vector<int> (c + 1)), table(c + 1, vector<int> (c + 1));
  for(int i = 1; i <= c; i++){
    for(int j = 1; j <= c; j++) scanf("%d", &table[i][j]);
  }
  for(int i = 1; i <= n; i++){
    for(int j = 1; j <= n; j++){
      int x; scanf("%d", &x);
      data[(i + j) % 3][x]++;
    }
  }

  int ans = INF;
  for(int c1 = 1; c1 <= c; c1++){
    for(int c2 = 1; c2 <= c; c2++){
      for(int c3 = 1; c3 <= c; c3++){
        if(c1 == c2 || c2 == c3 || c1 == c3) continue;
        int ans1 = 0;
        for(int i = 1; i <= c; i++) ans1 += table[i][c1] * data[0][i];
        for(int i = 1; i <= c; i++) ans1 += table[i][c2] * data[1][i];
        for(int i = 1; i <= c; i++) ans1 += table[i][c3] * data[2][i];
        ans = min(ans, ans1);
      }
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>

using namespace std;

#define ll long long
#define ld long double
#define v vector

#define rep(i, n)      for (int i = 0; i < (int)(n); ++i)
#define rep3(i, m, n)  for (int i = (m); i < (int)(n); ++i)
#define rrep(i, n)     for (int i = (int)(n)-1; i >= 0; --i)
#define rrep3(i, m, n) for (int i = (int)(n)-1; i >= (m); --i)
#define all(x) x.begin(), x.end()
#define rall(x) x.end(x), x.begin()

#define endl '\n'


ll gcd(ll a, ll b) { return b ? gcd(b, a % b) : a; }

string solve(string S) {
  return S.substr(0, 3);
}

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

    string S;
    cin >> S;

    auto ans = solve(S);
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3124
#include <iostream>
#include <math.h>
#include <algorithm>
#include <functional> 
#include <string>
#include <vector>

#include <cstring>
#include <set>
#include <map>
#include <queue>
#include <utility>
#include <limits.h>

using namespace std;

typedef long long LL;

#define rep(i,n) for (int i = 0; i < (n); ++i)
#define dump(c) { for (auto it = c.begin(); it != c.end(); ++it) if (it == c.begin()) cout << *it; else cout << ' ' << *it; cout << endl; } 
#define dumpMap(m) { for (auto it: m) cout << it.first << "=>" << it.second << ' '; }

const int MOD = 1000000007;

int dp[100000];

int solve(const vector< vector<int> >& g, int from)
{
    int ret = dp[from];
    if (ret < 0) {
        if (g[from].empty()) {
            ret = 0;
        } else {
            int longest = 0;
            for (int to: g[from]) {
                longest = max(longest, solve(g, to));
            }
            ret = longest + 1;
        }
        dp[from] = ret;
    }
    return ret;
}

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

    vector< vector<int> > g(N);
    rep(i, M) {
        int x, y;
        cin >> x >> y;
        --x;
        --y;
        g[x].push_back(y);
    }

    rep(i, N) {
        dp[i] = -1;
    }

    rep(i, N) solve(g, i);

    int ans = 0;
    rep(i, N) ans = max(ans, dp[i]);

    cout << ans << endl;

    return 0;
}


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

using namespace std;


int main()
{
    int i,j=1;;
    string s;
    cin>>s;
    for(i=0;i<s.size();i++)
    {
        if(i%2==0)
        {
            if(s[i]=='h')
                continue;
        }
        else if(s[i] =='i')
            continue;
        j=0;
        break;
    }
    if(j==1 && s[s.size()-1]!='i')
        j=0;
    if(j==1)
        cout<<"Yes"<<endl;
    else
        cout<<"No"<<endl;






    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
using namespace std;
struct edge{int to,cost;};
int N;
vector<edge> G[100000];
int used[100000];
int d[100000];
void dfs(int v){
  used[v]=1;
  for(int i=0;i<G[v].size();i++){
    edge e=G[v][i];
    if(used[e.to]==0){
      d[e.to]=d[v]+e.cost;
      dfs(e.to);
    }
  }
}
int main(){
  scanf("%d",&N);
  for(int i=0;i<N-1;i++){
    int a,b,c;
    edge e;
    scanf("%d %d %d",&a,&b,&c);
    e.to=b;e.cost=c;
    G[a].push_back(e);
    e.to=a;
    G[b].push_back(e);
  }
  for(int i=0;i<N;i++){d[i]=0;}
  dfs(0);
  int x=0;
  for(int i=1;i<N;i++){
    if(d[x]<d[i])x=i;
  }
  for(int i=0;i<N;i++){d[i]=0;used[i]=0;}
  dfs(x);
  x=0;
  for(int i=1;i<N;i++){
    if(d[x]<d[i])x=i;
  }
  printf("%d\n",d[x]);
  return 0;
}

Measured memory_bytes: 12636
from itertools import combinations
n = int(input())
xy = [list(map(int, input().split())) for i in range(n)]

pair = list(combinations(xy,2))

ans = 0
for p in pair:
    ans += ((p[0][0]-p[1][0])**2 + (p[0][1]-p[1][1])**2)**0.5
print(ans*(n-1)/len(pair))


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

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N;
int ret;

void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	FOR(i,N) {
		cin>>x>>y;
		ret+=y-x+1;
	}
	cout<<ret<<endl;
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


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

using namespace std;
#define all(x) (x).begin(),(x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define chmin(x, y) (x) = min((x), (y))
#define chmax(x, y) (x) = max((x), (y))
#define endl "\n"
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec) {os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N;
    cin >> N;
    vector<string> S(3);
    for (int i = 0; i < 3; i++) {
        cin >> S[i];
    }
    ll ans = 0;
    for (int j = 0; j < N; j++) {
        set<int> ss;
        for (int i = 0; i < 3; i++) {
            ss.insert(S[i][j]);
        }
        if (ss.size() == 3) {
            ans += 2;
        } else if (ss.size() == 2) {
            ans += 1;
        }
    }
    cout << ans << endl;
}

int main() {
    #ifdef LOCAL_ENV
    cin.exceptions(ios::failbit);
    #endif
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    
    solve();

    #ifdef LOCAL_ENV
    assert(cin.rdstate() & ios_base::eofbit);
    #endif
}

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

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


// std::vector Declaration
template<typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
    return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}

// std::vector Initialization
template<typename T>
void fill_all(T& arr, const T& v) { arr = v; }
template<typename T, typename U>
void fill_all(T& arr, const U& v) { for (auto& i : arr) fill_all(i, v); }

// std::vector Debug
template<typename T>
ostream& operator<<(ostream& os, const vector<T>& v) {
    os << "[";
    bool a = 1;
    for (auto e : v ) {
        os << (a ? "" : " "); 
        os << e;
        a = 0;
    }
    os << "]";
    return os;
}

// std::pair Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const pair<T, U>& p) {
    os << "(" << p.first << " " << p.second << ")";
    return os;
}

// std::set Debug
template<typename T>
ostream& operator<<(ostream& os, const set<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::multiset Debug
template<typename T>
ostream& operator<<(ostream& os, const multiset<T>& st) {
    os << "{";
    bool a = 1;
    for (auto e : st) {
        os << (a ? "" : " ");
        os << e;
        a = 0;
    }
    os << "}";
    return os;
}

// std::map Debug
template<typename T, typename U>
ostream& operator<<(ostream& os, const map<T, U>& mp) {
    os << "{";
    bool a = 1;
    for (auto e : mp) {
        os << (a ? "" : " ");
        os << e.first << ":" << e.second;
        a = 0;
    }
    os << "}";
    return os;
}

// std::tuple Debug
template<int N, class Tuple>
void out(ostream& os, const Tuple& t){}
template<int N, class Tuple, class H, class ...Ts>
void out(ostream& os, const Tuple& t) {
    if (N) os << " ";
    os << get<N>(t);
    out<N+1,Tuple,Ts...>(os, t);
}
template<class ...Ts>
ostream& operator<<(ostream& os, const tuple<Ts...>& t) {
    os << "(";
    out<0,tuple<Ts...>,Ts...>(os, t);
    os << ")";
    return os;
}

// Debug
#define DUMP(x) cerr<<#x<<" = "<<(x)<<endl


struct edge { int to, cost; };
ostream& operator<<(ostream& os, const edge& e) {
    os << "(" << e.to << ", " << e.cost << ")";
    return os;
}

const LL LINF = 1LL<<60;
const int IINF = 1<<30;
const LL MOD = 1e9+7;

int main()
{
    string s; cin >> s;
    if (s[0] == s[1] ||
        s[1] == s[2] ||
        s[2] == s[3]) {
        cout << "Bad" << endl;
    } else {
        cout << "Good" << endl;
    }

    return 0;
}


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

//#define int long long
#define fi first
#define se second
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define rep11(i, n) for (int i = 1; i < (int)(n); ++i)
#define repo(i, o, n) for (int i = o; i < (int)(n); ++i)
#define repm(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define pb(n) push_back(n)
#define mp make_pair
#define MOD 1002000007
#define INF LONG_LONG_MAX

int main(){
    int N,A,B;
    cin >>N >> A >>B;
    if (N*A<B){
        cout<< N*A <<endl;
    }
    else {
    cout<< B <<endl;
    }
}

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

int main(){

int n,x=0,max=0;
cin>>n;
char arr[n];
for(int i=0;i<n;i++){
	
	cin>>arr[i];
}
for(int i=0;i<n;i++){
	if(arr[i]=='I')
	x++;
	else
	x--;
	if(x>max)
	max=x;
}
cout<<max;
	
	return 0;
} 


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

int main(){
  int n,h,w;
  cin >> n >> h >> w;
  cout << (n+1-h)*(n+1-w) << endl;
  return 0;
}


Measured memory_bytes: 256
import numpy as np
N = int(input())
A = np.array([0] + [int(x) for x in input().split()] + [0])
total = np.abs(np.diff(A)).sum()
saved = np.abs(A[1:-1] - A[:-2]) + np.abs(A[1:-1] - A[2:]) - np.abs(A[:-2] - A[2:])
answer = total - saved
print(*answer, sep='\n')

Measured memory_bytes: 22972
#include<bits/stdc++.h>
#define boost ios::sync_with_stdio(false); cin.tie(0)
#define ll              long long int
#define ld              long double
#define mk              make_pair
#define pb              push_back
#define f               first
#define s               second
#define fo(i,a,b)       for(i=a;i<b;i++)
#define foe(i,a,b)      for(i=a;i<=b;i++)
#define all(x)          x.begin(),x.end()
// #define vi               vector<int>
#define vl              vector <long long int>
// #define pii          pair <int,int>
#define pll             pair <long long int, long long int>
// #define vpii         vector< pair<int,int> >
#define vpll            vector < pair <long long int,long long int> >
#define MOD             1000000007
using namespace std;
const int inf = INT_MAX;
const ll inf64 = LLONG_MAX;


int main()
{
    boost;
    ll n;
    cin >> n;
    vl arr;
    ll i;
    fo(i, 0, n)
    {
        ll temp;
        cin >> temp;
        arr.pb(temp);
    }
    sort(all(arr));
    reverse(all(arr));
    vl ans;
    ans.pb(0);
    ans.pb(arr[0]);
    fo(i, 1, n) {
        ans.pb(arr[i]);
        ans.pb(arr[i]);
    }
    ll sum = 0;
    fo(i, 0, n)
    sum += ans[i];
    cout << sum;





    return 0;
}

Measured memory_bytes: 8984
function Main(input) {
  input = input.split("\n");//一行目はinput[0]に、二行目はinput[1]に
var N = input[0]; 
var LineA = input[1].split(" ").map(Number);
var LineB = input[2].split(" ").map(Number);
var LineC = input[3].split(" ").map(Number);
var sum  = function(Line) {
    var sum = 0;
    for (var i=0; i<Line.length; ++i) {
        sum += Line[i];
    };
    return sum;
};

Allsum = sum(LineB);
  
for(var j=0; j<N ; j++){
  if( LineA[j] == LineA[j-1] + 1){
    Allsum = Allsum + LineC[LineA[j-1]-1];
  }
}
console.log(Allsum);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 7372
N, M = map(int, input().split())
A = [0 for _ in range(N)]
B = [1 for _ in range(M)]
X = A + B

ans = 0
for i in range(N + M):
    for j in range(i + 1, N + M):
        if (X[i] + X[j]) % 2 == 0:
            ans += 1


print(ans)


Measured memory_bytes: 3060
#include"bits/stdc++.h"
using namespace std;
#define ll long long
#define LL long long
#define MOD 1000000007
#define INF 2000000000
int dx[4] = { 0,1,0,-1 };
int dy[4] = { 1,0,-1,0 };
ll N, M, K,H,W, ans, mi1,mi2,sum;
LL dp[1000001][13];
string s;

int main() {
	cin >> s;
	dp[0][0] = 1;
	for (int i = 0; i < s.size()+1; i++) {
		LL a = 0;
		if (s[i] == '?')a = -1;
		else a = s[i] - '0';

		for (int j = 0; j < 10; j++) {
			if (a != -1 && a != j)continue;
			for (int k = 0; k < 13; k++) {
				dp[i + 1][(k * 10 + j) % 13] += dp[i][k];
			}
		}
		for (int j = 0; j < 13; j++) dp[i + 1][j] %= MOD;
	}
	cout << dp[s.size()][5] << endl;
	return 0;
}



Measured memory_bytes: 10752
from itertools import permutations
n, m = map(int, input().split())
e = [[0] * n for i in range(n)]
v = [i for i in range(1, n)]
for i in range(m):
    a, b = map(int, input().split())
    e[a -1][b - 1] = e[b - 1][a - 1] = 1


ans = 0
for i in permutations(v):
    s = (0,)
    t = s + i
    flag = 1
    for j in range(n - 1):
        if e[t[j]][t[j + 1]] == 0:
            flag = 0
            break
    if flag:
        ans += 1
print(ans)    

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    ll H;
    ll ans = 0, a = 1;
    cin >> H;
    
    
    while (H > 0) {
        ans += a;
        a *= 2;
        
        H /= 2;
    }
    
    cout << ans << endl;
    
    
    

    return 0;
}


Measured memory_bytes: 3624
#include <bits/stdc++.h>
#define rep(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REP(i,n) for(int (i)=0;(i)<=(int)(n);(i)++)
#define rep1(i,x,n) for(int (i)=(x);(i)<(int)(n);(i)++)
#define REP1(i,x,n) for(int (i)=(x);(i)<=(int)(n);(i)++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
using namespace std;
using ll = long long;
using ull = unsigned long long;
using Int = long long;

//INT_MAX = 2147483647;
//LLONG_MAX = 9223372036854775807;
//ULLONG_MAX = 18446744073709551615;
const int MOD = 1000000007;
const ll INF = numeric_limits<ll>::max();
const int inf = 1e8;
typedef pair<int,int> P;
typedef std::priority_queue<int> IntPrioQueue;
typedef std::priority_queue<int, std::vector<int>, std::greater<int> > IntReversePrioQueue;

//少数点表示
//cout << std::fixed << std::setprecision(14) << 値

int main(){
    cin.tie( 0 ); ios::sync_with_stdio( false );
    int a,b,k;
    cin >> a >> b >> k;
    int cnt = 0;
    int i = min(a,b);
    while(1){
        if(a%i == 0 && b%i == 0){
            cnt++;
        }
        if(cnt == k) break;

        i--;
    }
    cout << i << endl;

    return 0;
}

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

using namespace std;
using ll = long long;
const double pi = acos(-1);
#define FOR(i,a,b) for (ll i=(a),__last_##i=(b);i<__last_##i;i++)
#define RFOR(i,a,b) for (ll i=(b)-1,__last_##i=(a);i>=__last_##i;i--)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define __GET_MACRO3(_1, _2, _3, NAME, ...) NAME
#define rep(...) __GET_MACRO3(__VA_ARGS__, FOR, REP)(__VA_ARGS__)
#define rrep(...) __GET_MACRO3(__VA_ARGS__, RFOR, RREP)(__VA_ARGS__)
template<typename T> ostream& operator<<(ostream& os, const vector<T>& v) {
	REP(i, v.size()) { if (i)os << " "; os << v[i]; }return os;
}
template<typename T> ostream& operator<<(ostream& os, const vector<vector<T>>& v) {
	REP(i, v.size()) { if (i)os << endl; os << v[i]; }return os;
}

const ll INF = 1LL << 60;
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

#define int long long

inline void my_io() {

	std::ios::sync_with_stdio(false);

	std::cin.tie(0);

	cout << fixed << setprecision(10);

}

signed main() {
	ll n, a;
	ll ans = 0;

	cin >> n;

	vector<ll> v(n, 0);

	REP(i, n) {
		cin >> a;
		v[i] = a - 1;
	}

	REP(i, n) {
		if (i == v[v[i]]) {
			ans++;
		}
	}

	cout << ans / 2 << endl;
}

Measured memory_bytes: 1024
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <cmath>
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
using namespace std;

int main(){
  int X;
  cin >> X;
  if(400 <= X && X <= 599){
    cout << 8 << endl;
  }else if(600 <= X && X <= 799){
    cout << 7 << endl;
  }else if(800 <= X && X <= 999){
    cout << 6 << endl;
  }else if(1000 <= X && X <= 1199){
    cout << 5 << endl;
  }else if(1200 <= X && X <= 1399){
    cout << 4 << endl;
  }else if(1400 <= X && X <= 1599){
    cout << 3 << endl;
  }else if(1600 <= X && X <= 1799){
    cout << 2 << endl;
  }else if(1800 <= X && X <= 1999){
    cout << 1 << endl;
  }
}


Measured memory_bytes: 3632
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <cmath>
#include <random>
#include <iomanip>
#include <functional>
#include <list>
#include <unordered_map>
#include <sstream>
#include <istream>
#include <iterator>
#include <numeric>
#include <tuple>
#include <cassert>
#include <bitset>
using namespace std;

int main()
{
	int a, b, c;
	cin >> a >> b >> c;

	cout << min(c, b / a);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

struct edge{ int to,cost; };

const int N = 800;
vector<edge> G[N];

const ll INF = LLONG_MAX/3;

ll dp[N][2];
ll dfs(int v, int par, int back){
    if(dp[v][back]>=0) return dp[v][back];

    ll c = 0;
    for(const auto &e:G[v])if(e.to != par){
        if(G[e.to].size()==1){
            // leaf
            c += e.cost;
        }
        else{
            c += 3*e.cost + dfs(e.to, v, 1);
        }
    }

    if(back) return dp[v][back] = c;

    ll ret = c;
    for(const auto &e:G[v])if(e.to != par){
        if(G[e.to].size()>1){
            ret = min(ret, c - e.cost - dfs(e.to,v,1) + dfs(e.to,v,0));
        }
    }

    return dp[v][back] = ret;
}

int main(){
    int n;
    while(scanf(" %d", &n),n){
        rep(i,N) G[i].clear();

        vector<int> p(n),d(n);
        for(int i=1; i<n; ++i) scanf(" %d", &p[i]);
        for(int i=1; i<n; ++i) scanf(" %d", &d[i]);

        for(int i=1; i<n; ++i){
            --p[i];
            G[p[i]].pb({i,d[i]});
            G[i].pb({p[i],d[i]});
        }

        ll ans = INF;
        rep(i,n){
            memset(dp,-1,sizeof(dp));
            ans = min(ans, dfs(i,-1,0));
        }

        printf("%lld\n", ans);
    }
    return 0;
}



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

void solv() {
    int D;
    cin >> D;
    cout << "Christmas";
    for (int i = 0; i <  25 - D; i++){
        cout << " Eve";
    }
    cout << endl;
}

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

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; ++i)
#define rep2(i, x, n) for(ll i = x, i##_len = (n); i < i##_len; ++i)
#define all(n) begin(n), end(n)
using ll = long long;
using P = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vs = vector<string>;
using vc = vector<char>;
using vb = vector<bool>;
using vd = vector<double>;
vi dir = {-1, 0, 1, 0, -1, -1, 1, 1, -1};

int main() {
  ll x, n;
  cin >> x >> n;
  vb p(101, false);
  rep(i, n) {
    ll a;
    cin >> a;
    p[a] = true;
  }
  ll ans = 0;
  rep(i, 102) {
    if(p[i]) continue;
    if(abs(i - x) < abs(ans - x)) ans = i;
  }
  cout << ans << endl;
}

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

long long n, a, b, c;
long long h[100010];

bool isOK(long long t){
	long long ans = 0;
	for(int i = 0;i < n;i++){
		long long tt = h[i] - b * t;
		if(tt > 0){
			ans += (tt+c-1)/c;
		}
	}
	return t >= ans;
}

int main(){
	cin >> n >> a >> b;

	for(int i = 0;i < n;i++){
		cin >> h[i];
	}

	c = a-b;

	long long left = 0, right = 1000000007;

	while(right-left > 1){
		long long mid = left + (right-left)/2;
		if(isOK(mid)) right = mid;
		else left = mid;
	}

	cout << right << endl;
	return 0;
}




Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <climits>
#include <sstream>

using namespace std;

int main(){
  string s;

  cin >> s;

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


Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using llu=unsigned long long;
#define mod 1000000007
#define mode 998244353
#define PI 3.14159265358979323846
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define mms(x,y) memset(x,y,sizeof(x))
#define pqm priority_queue<ll,vector<ll>,greater<ll>>
#define pb push_back
#define um unordered_map
#define pr pair
#define mm multimap
#define ms multiset
#define mp make_pair
#define vr vector
#define pq priority_queue
#define lb lower_bound
#define ub upper_bound
#define inf INT_MAX
#define ninf INT_MIN
#define ff first
#define ss second
#define gcd __gcd
ll dp[3005][3005][2];
int main()
{
    fast;
    ll t,n,m,i,j,k;
    cin>>n;
    ll a[n];
    for(i=0;i<n;i++)cin>>a[i];
    for(i=1;i<=n;i++)dp[i][i][0]=a[i-1];
    for(i=2;i<=n;i++)
    {
        for(j=1;j+i-1<=n;j++)
        {
            dp[j][j+i-1][0]=max(dp[j][j+i-2][1]+a[j+i-2],dp[j+1][j+i-1][1]+a[j-1]);
            if(dp[j][j+i-2][1]+a[j+i-2]>dp[j+1][j+i-1][1]+a[j-1])
            dp[j][j+i-1][1]=dp[j][j+i-2][0];
            else dp[j][j+i-1][1]=dp[j+1][j+i-1][0];
        }
    }
    cout<<dp[1][n][0]-dp[1][n][1];
}


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

int main(int argc, char const *argv[])
{
	int n;
	cin>>n;

	int a[100001]={},dp[100001]={0};

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

	dp[0]=0;
	dp[1]= abs(a[1]-a[0]);
	
	int first,second;
	
	for (int i = 2; i < n; i++)
	{
		first = dp[i-2]+ abs(a[i]-a[i-2]);
		second = dp[i-1]+ abs(a[i]-a[i-1]);
		dp[i] = min(first,second);
	}
	
	cout<<dp[n-1];
	return 0;
}

Measured memory_bytes: 1024
import sys

input = sys.stdin.readline

ri = lambda: int(input())
rs = lambda: input().rstrip()
ril = lambda: list(map(int, input().split()))
rsl = lambda: input().rstrip().split()
ris = lambda n: [ri() for _ in range(n)]
rss = lambda n: [rs() for _ in range(n)]
rils = lambda n: [ril() for _ in range(n)]
rsls = lambda n: [rsl() for _ in range(n)]


class Combinations:
    def __init__(self, max_num, mod):
        self.mod = mod
        self.factorials = [1]
        for i in range(1, max_num + 1):
            self.factorials.append((self.factorials[-1] * i) % mod)
        self.invs = [pow(self.factorials[-1], mod - 2, mod)]
        for i in reversed(range(1, max_num + 1)):
            self.invs.append(self.invs[-1] * i % mod)
        self.invs = self.invs[::-1]

    def __call__(self, n, k):
        if n < 0 or k < 0 or k > n:
            return 0
        return self.factorials[n] * self.invs[k] * self.invs[n - k] % self.mod


MOD = 10**9 + 7

n, k = ril()
ls = sorted(ril())

combinations = Combinations(n, MOD)
combs = [combinations(i, k - 2) for i in range(k - 2, n - 1)]

accs = [combs[0]]
for x in combs[1:]:
    accs.append(accs[-1] + x)

res = 0
for x, y in zip(ls, reversed(accs)):
    res -= x * y
    res %= MOD
for x, y in zip(reversed(ls), reversed(accs)):
    res += x * y
    res %= MOD
print(res)

Measured memory_bytes: 68904
#include <iostream>
#include <algorithm>
int main()
{
    int N,K;
    std::cin>>N>>K;
    int p[N];
    for(int i=0;i<N;i++)
        std::cin>>p[i];
    std::sort(p,p+N);
    int x=0;
    for(int i=0;i<K;i++)
        x=x+p[i];
    std::cout<<x<<std::endl;
}

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

using namespace std;
using ll = long long;

int main(void) {
  string s;
  cin >> s;
  ll n = s.length();

  ll ans = 0;
  ll cnt = 0;
  for (auto &p : s) {
    if (p == 'B') {
      cnt++;
    } else {
      ans += cnt;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 640
def BubbleSort(C, N):
    for i in range(N):
        for j in range(N-1, i, -1):
            if C[j][1] < C[j-1][1]:
                C[j], C[j-1] = C[j-1], C[j]
    print " ".join(map(str, C))
    print "Stable"

def SelectionSort(C, N):
    for i in range(N):
        minj = i
        for j in range(i, N):
            if C[j][1] < C[minj][1]:
                minj = j
        C[i], C[minj] = C[minj], C[i]
    print " ".join(map(str, C))


N = int(raw_input())
L = raw_input().split()

t1 = list(L)
BubbleSort(t1, N)

t2 = list(L)
SelectionSort(t2, N)

if  t1 == t2:
    print "Stable"
else:
    print "Not stable"

Measured memory_bytes: 6492
#include <bits/stdc++.h>
using namespace std;
#define itn int
#define nibu(K,x) binary_search(K.begin(),K.end(),x)
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) x.begin(),x.end()
#define sz(x) x.size()
#define pb push_back
#define mp make_pair
#define Fi first
#define Se second
#define out(x) cout<<x<<endl
#define put(x) out(x)
#define in(x) cin>>x
#define maxx(a,b,c) max(a,max(b,c))
#define minn(a,b,c) min(a,min(b,c))
using ll = long long;
using vl = vector<ll>;
using vs = vector<string>;
const double pi = 3.14159265358979;

int main() {
	string S;
  in(S);
  int N = sz(S);
  int a=3000000,b=0;
  rep(i,N){
    if(S[i]=='A') a = min(a,i);
    else if(S[i] == 'Z') b = max(b,i);
  }
  out(b-a+1);
}


Measured memory_bytes: 640
using System;

namespace myApp
{
    class Program
    {
        static void Main()
        {
            string s = Console.ReadLine();
            
            s=s.Replace("0","");

            Console.WriteLine(s.Length);

            // string[] input = Console.ReadLine().Split();

            // int a= int.Parse(input[0]);
            
            // int b=int.Parse(input[1]);

            // int c = a*b;

            // if(c%2==0){Console.WriteLine("Even");}

            // else if(c%2==1){Console.WriteLine("Odd");}
            
            // else{}
        }
    }
}


Measured memory_bytes: 11092
s = input()
count = 0
_max = 0
for i in range(len(s)):
    if s[i] == "A" or s[i] == "C" or s[i] == "G" or s[i] == "T":
        count += 1
        _max = max(_max, count)
    else:
        count = 0
print(_max)

Measured memory_bytes: 3060
program BannedK
  implicit none

  integer(kind=8) :: n, i, j, k, s, t
  integer(kind=8), allocatable :: a(:), b(:,:), c(:,:)

  read *, n
  allocate(a(n))
  read *, a

  call count(a, b)
  s = 0_8
  do i = 1, n
     call combi(b(2,i),2_8,t)
     s = s + t
  end do

  do k = 1, n
     print *, s-b(2,a(k))+1 !!!!
  end do

  deallocate(a)

  stop
contains

  subroutine count(array, dtb)
    implicit none
    integer(8), intent(in) :: array(:)
    integer(8), allocatable, intent(out) :: dtb(:,:)
    integer(8) :: n, i, j, s

    n = size(array)
    allocate(dtb(2_8,n))
    dtb = 0_8
    
    do i = 1, n
       dtb(1,i) = i
       dtb(2,array(i)) = dtb(2,array(i)) + 1
    end do
    
    return
  end subroutine count

  subroutine combi(n, m, rslt)
    implicit none
    integer(8), intent(in) :: n, m
    integer(8), intent(out) :: rslt
    integer(8) :: i

    rslt = 1_8
    do i = 1, m
       rslt = rslt*(n-i+1_8)
    end do
    do i = 1, m
       rslt = rslt/(m-i+1_8)
    end do

    return
  end subroutine combi
    
end program BannedK



  


Measured memory_bytes: 9728
import fractions
a,b,c,d = map(int,input().split())
lcm = c*d // fractions.gcd(c,d)
A = ((a-1) // c) + ((a-1) // d) - ((a-1) // lcm) 
B = (b // c) + (b // d) - (b // lcm)
ans = B-A
print(b-a+1-ans)

Measured memory_bytes: 10620
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <string.h>
#include <queue>
#include <algorithm>
#include<iostream>
#include<vector>
#include<map>
#include<string>
#include <iomanip>
#include<deque>
#include<stack>
#include<set>
#include <numeric>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
const int INF = 111111111;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const int DIV = 1000000007; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(15);
	//==================================


	int N;
	cin >> N;
	vector< int> A;
	A.emplace_back(0);
	for (int i = 0; i < N; i++) {
		int temp;
		cin >> temp;
		A.emplace_back(temp);
	}
	A.emplace_back(0);

	ll sum = 0;
	for (int i = 0; i < N + 2 - 1; i++) {
		sum += abs(A[i] - A[i + 1]);
	}

	for (int i = 1; i < N + 1; i++) {
		cout << sum - (abs(A[i] - A[i - 1]) + abs(A[i] - A[i + 1])) + abs(A[i - 1] - A[i + 1]) << endl;
	}





}	


Measured memory_bytes: 1784
#ifdef LOCAL
#define _GLIBCXX_DEBUG
#endif

#include <bits/stdc++.h>

using namespace std;
using ll = long long;

string reduce (const string &s)
{
	string ans;
	for (char ch : s)
	{
		if (ans.empty() || ans.back() != ch || ch != 'S')
			ans += ch;
		else
			ans.pop_back();
	}
	return ans;
}

vector<int> work (const int n, const string &s)
{
	vector<int> who_moves(3);
	vector<string> carry(3);

	for (int i = 0; i < 3; i++)
	{
		int cur = i;
		for (const char ch : s)
		{
			if (ch == 'S')
			{
				carry[i] += ch;
				if (cur != 0)
					cur = 3 - cur;
			}

			if (ch == 'R')
			{
				cur++;
				if (cur == 3)
				{
					carry[i] += ch;
					cur = 0;
				}
			}
		}

		who_moves[i] = cur;
	}

	if (n == 1)
		return who_moves;

	for (int i = 0; i < 3; i++)
		carry[i] = reduce(carry[i]);

	vector<vector<int>> old_anses(3);
	for (int i = 0; i < 3; i++)
		old_anses[i] = work(n - 1, carry[i]);
	for (int i = 0; i < 3; i++)
		assert(old_anses[i].size() == old_anses[0].size());

	vector<int> ans(3 * old_anses[0].size());
	for (int i = 0; i < 3; i++)
		for (int j = 0; j < int(old_anses[i].size()); j++)
			ans[3 * j + i] = 3 * old_anses[i][j] + who_moves[i];

	return ans;
}

void solve(istream &cin = std::cin, ostream &cout = std::cout)
{
	int n;

	while (cin >> n)
	{
		string s;
		cin >> s;
		for (const char ch : s)
			assert(ch == 'S' || ch == 'R');

		auto ans = work(n, s);
		for (int i = 0; i < int(ans.size()); i++)
			cout << ans[i] << " \n"[i + 1 == int(ans.size())];
	}
}

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

#ifdef LOCAL
	auto st = clock();
	ifstream fin("../input.txt");
	solve(fin);

	cout << "clock: " << (clock() - st) / (double) CLOCKS_PER_SEC << endl;
#else
	solve();
#endif

	return 0;
}

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

int num(string n) {
	int ans;
	ans = (n[0] - '0')*pow(10, n.size()-1);
	if (n.size() != 1) {
		ans += num(n.erase(0, 1));
	}
	return ans;
}

int main() {
	string n;
	cin >> n;
	int sn = 0;
	for (int i = 0; i < n.size(); i++) {
		sn += n[i] - '0';
	}
	int N=num(n);
	if (N % sn == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}

	return 0;
}

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

using namespace std;
using LL = long long;
using P = pair<int, int>;
using Tapris = tuple<int, int, int>;

#define REP(i, n) for(LL i = 0; i < n; ++i)
#define FOR(i, a, n) for(LL i = a; i < n; ++i)
#define pb(a) push_back(a)
#define all(x) (x).begin(),(x).end()

const int INF = (int)1e9;
const LL INFL = (LL)1e15;
const int MOD = 1e9 + 7;

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

//#define int long long

/*************** using variables ***************/
string s;
int k;
/**********************************************/

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

    cin >> s >> k;

    REP(i, s.size()){
        if(k <= 0) break;
        if(s[i] == 'a') continue;
        else if((int)'z'+1 - (int)s[i] <= k){
            k -= 'z'+1 - s[i];
            s[i] = 'a';
        }
    }
    k %= 26;
    s[s.size()-1] = (char)(s[s.size()-1] + k);
    cout << s << endl;
}


Measured memory_bytes: 592
#include <bits/stdc++.h>
#define pb push_back
#define MOD 1000000007
using namespace std;

// c == 0 white
// c == 1 black
int f(auto &e, auto &dp, auto &visited, int x, bool c) {
	if (dp[x][c] == -1) {
		dp[x][c] = 1;
		visited[x] = 1;
		for (int a : e[x]) {
			if (visited[a]) continue;
			if (c == 1) dp[x][c] *= f(e, dp, visited, a, 0);
			else dp[x][c] *= (f(e, dp, visited, a, 0) + f(e, dp, visited, a, 1)) % MOD;
			dp[x][c] %= MOD;
		}
		visited[x] = 0;
	}
	return dp[x][c];
}

int main() {
	int n, a, b;
	cin >> n;
	vector<vector<int>> e(n + 1, vector<int>());
	for (int i = 0; i < n-1; i++) { cin >> a >> b; e[a].pb(b); e[b].pb(a); }
	
	vector<vector<long long>> dp(n + 1, vector<long long>(2, -1));
	vector<bool> visited(n + 1, 0);
	cout << (f(e, dp, visited, 1, 0) + f(e, dp, visited, 1, 1)) % MOD << endl;
	//for (int i = 1; i <= n; i++) cout << '[' << i <<"]:" <<dp[i][0] << " " << dp[i][1]<<endl;
	return 0;
}

Measured memory_bytes: 20992
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <cassert>
#include <random>
using ll = long long;


int main() {
	int K; std::cin >> K;
	int ans = 0;
	for (int i = 1; i <= K; i++) {
		for (int j = 1; j <= K; j++) {
			for (int k = 1; k <= K; k++) {
				ans += std::gcd(i, std::gcd(j, k));
			}
		}
	}
	std::cout << ans << std::endl;
	return 0;
}


Measured memory_bytes: 3584
n,W = map(int,input().split())

w = []
v = []

for x in range(n):
    peso,valor = map(int,input().split())
    w.append(peso)
    v.append(valor)

dp = [0] * (W+1)

for i in range(n):
    for j in range(W,-1,-1):
        if j + w[i] <= W:
            dp[j+w[i]] = max(dp[j+w[i]], dp[j] + v[i])


resposta = 0

for x in dp:
    resposta = max(x,resposta)

print(resposta)


Measured memory_bytes: 70568
import java.util.*;
import java.io.PrintWriter;
import static java.lang.Integer.*;
import static java.lang.Long.*;
import static java.lang.Math.*;
import static java.lang.System.*;

public class Main {
	public static final int N = 5;
	public static final int MOD = 1000000007;
	public static void main(String[] args) {
		int i,j;
		Scanner sc = new Scanner(in);
		int[] x = new int[N];
		int ans=0;
		for (i = 0; i < N; i++) {
			x[i] = parseInt(sc.next());
			if(x[i]==0) ans=i+1;
		}
		sc.close();
		out.println(ans);
	}
}


Measured memory_bytes: 26904
#include <iostream>
#include <vector>
#include <queue>
#include <tuple>
using namespace std;
using P = pair<int,int>;
int main(){
    int dist[1<<15];
    fill(dist,dist+(1<<15),1000000000);
    int N,M;
    cin>>N>>M;
    int start=0,goalA=0,goalB=0;
    for(int i=0;i<N;i++){
        int b;
        cin>>b;
        start<<=1;
        start+=b;
    }
    for(int i=0;i<M;i++){
        int p;
        cin>>p;
        for(int j=0;j<p;j++){
            goalA<<=1;
            goalA+=int(i%2==0);
            goalB<<=1;
            goalB+=int(i%2==1);
        }
    }
    queue<P> Q;
    Q.push(P(start,0));
    dist[start]=0;
    while(!Q.empty()){
        int cur, cost;
        tie(cur,cost)=Q.front(); Q.pop();
        if(cur==goalA||cur==goalB){
            cout<<cost<<endl;
            return 0;
        }
        if(dist[cur]<cost) continue;
        for(int i=0;i<N-1;i++){
            if(((cur>>i)&1)==((cur>>(i+1))&1)) continue;
            int next = cur^(3<<i);
            if(dist[next]<=cost+1) continue;
            dist[next]=cost+1;
            Q.push(P(next,cost+1));
        }
    }
    return 0;
}

Measured memory_bytes: 3296
//author:luckYrat(twitter:@luckYrat_)
//#include <bits/stdc++.h>

//def
#include <iostream>

#include <cmath>
#include <algorithm>
#include <iomanip>

//array
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <utility>
#include <climits>



using namespace std;

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

#define anyfill(n,s) setw(n) << setfill(s)
#define loop(s) for(int i = 0; s > i; i++)
#define rep(i,q) for(int i = 0; (q) > i; i++)
#define repp(i,n,q) for(int i = n; (q) > i; i++)
#define dep(i,q) for(int i = (q); 0 < i; i--)


#define MAX 1000000000
const int mod = 1000000007;
#define EPS (1e-10)

#define pb push_back
#define fir first
#define scn second
#define ednl endl

#define YesNo(a) (a?"Yes":"No")
#define YESNO(a) (a?"YES":"NO")
#define yesno(a) (a?"yes":"no")


P ar4[4] = {{0,1},{0,-1},{1,0},{-1,0}};
P ar8[8] = {{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,-1},{1,0},{1,1}};
/*
確認ポイント
cout << fixed << setprecision(n) << 小数計算//n桁の小数表記になる
vector.unique()は隣接した同じ要素を削除するので先にソートをする

計算量は変わらないが楽できるシリーズ
C++11以降でmin({a,b,c...})で複数個のmic,maxを処理できる
min(max)_element(iter,iter)で一番小さい(大きい)値のポインタが帰ってくる
count(iter,iter,int)でintがiterからiterの間にいくつあったかを取得できる

*/
__attribute__((constructor))
void initial() {
 cin.tie(0);
 ios::sync_with_stdio(false);
}



int main(){
  int n;cin>>n;
  cout << fixed << setprecision(10);
  if(n==1)cout << 1 << endl;
  else cout << (double)((n-1)/2+1)/n << endl;
}


Measured memory_bytes: 256
void main() {
    string s1 = readln.chomp;
    string s2 = readln.chomp;
    string s3 = readln.chomp;
    writeln(s1[0], s2[1], s3[2]);
}

import std.stdio;
import std.string;
import std.array;
import std.conv;
import std.algorithm;
import std.range;
import std.math;
import std.numeric;
import std.container;
import std.typecons;
import std.ascii;
import std.uni;

Measured memory_bytes: 256