akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <functional>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef pair<ll, ll> P;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define exrep(i, a, b) for(ll i = a; i <= b; i++)
#define out(x) cout << x << endl
#define exout(x) printf("%.10f\n", x)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define pb push_back
#define re0 return 0
const ll mod = 1000000007;
const ll INF = 1e16;
const ll MAX_N = 100010;

int main() {
    ll n;
    string s;
    cin >> n >> s;

    ll x = 0;
    ll ans = 0;
    rep(i, n) {
        if(s[i] == 'I') {
            x++;
        }
        else {
            x--;
        }
        chmax(ans, x);
    }

    out(ans);
    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define all(x) (x).begin(),(x).end()
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; }
typedef long long ll;
const long long INF = 1e9;
typedef pair<int, int> P;
int main()
{
    int N, W;
    cin >> N >> W;
    vector<int> v(N), w(N);
    rep(i, N) cin >> v[i] >> w[i];

    vector<vector<int>> dp(N + 1, vector<int>(W + 1, -INF));
    dp[0][0] = 0;
    rep(i, N) {
        rep(j, W + 1) {
            if (dp[i][j] != -INF && w[i] + j <= W) {
                chmax(dp[i + 1][j + w[i]], dp[i][j] + v[i]); 
            }
            chmax(dp[i + 1][j], dp[i][j]);
        }
    }

    int ans = 0;
    rep(i, W + 1) {
        chmax(ans, dp[N][i]);
    }

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


Measured memory_bytes: 6796
n, k = map(int,input().split())
res = 0

for i in range(n + 2 - k):
    max_n = n * (n + 1) / 2 - (n - (k + i)) * (n + 1 - (k + i)) / 2
    min_n = (k + i) * (k + i - 1) / 2
    res = (res + max_n - min_n + 1) % 1000000007

print(int(res))


Measured memory_bytes: 9192
#include <bits/stdc++.h>
using namespace std;
const int INF = 1000000000;
#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);++i)
#define rep(i,n) REP(i, 0, n)
typedef long long int i64;
typedef pair<int, int> pint;

struct UnionFind {
    vector<int> data; int group;
    UnionFind(int N) : data(N, -1), group(N) {}
    void init(int N) {
        data.assign(N, -1);
        group = N;
    }
    void unite(int x, int y) {
        x = root(x); y = root(y);
        if(x != y){
            data[x] += data[y];
            data[y] = x;
            --group;
        }
    }
    int root(int x) { return data[x] < 0 ? x : data[x] = root(data[x]);}
    bool same(int a, int b) { return root(a) == root(b);}
};

struct Edge {
    int from, to, cost;
    Edge(int f, int t, int c)
         :from(f), to(t), cost(c) {}
    bool operator< (const Edge& E) const {
        return cost < E.cost;
    }
};

int main() {
    cin.tie(0); ios::sync_with_stdio(false);
    int N, M;
    while(cin >> N >> M && N) {
        vector<pint> h(N);
        rep(i, N) {
            cin >> h[i].first;
            h[i].second = i;
        }
        sort(h.begin(), h.end(), greater<pint>());
        vector<vector<int>> mat(N, vector<int>(N, 0));
        int a, b, c;
        rep(i, M) {
            cin >> a >> b >> c;
            --a; --b;
            mat[a][b] = mat[b][a] = c;
        }
        UnionFind uf(N);
        int ans = 0;
        bool is_spt = false;
        vector<int> notsink;
        multiset<Edge> edges; int edgemax = 0;
        rep(i, N) {
            int i2 = i;
            for(; i2 < N && h[i].first == h[i2].first; ++i2);
            multiset<Edge> bridge;
            REP(j, i, i2) notsink.push_back(h[j].second);
            REP(j, i, i2) {
                for(int k : notsink) if(mat[h[j].second][k]) {
                    bridge.insert(Edge(h[j].second, k, mat[h[j].second][k]));
                    edges.insert(Edge(h[j].second, k, mat[h[j].second][k]));
                }
            }
            if(is_spt) {
                for(const auto& e : bridge)
                  if(!uf.same(e.from, e.to)) {
                      uf.unite(e.from, e.to);
                      ans += e.cost;
                  }
            }else {
                uf.init(N); ans = 0;
                for(const auto& e: edges) {
                    if(!uf.same(e.from, e.to)) {
                        uf.unite(e.from, e.to);
                        ans += e.cost;
                    }
                }
            }
            if(uf.group == N - notsink.size() + 1) is_spt = true; else is_spt = false;
            i = i2 - 1;
            int k = edges.size();
            edgemax = max(edgemax, k);
        }
        if(is_spt) cout << ans << endl;
        else cout << 0 << endl;
    }
    return 0;
}

Measured memory_bytes: 8192
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define eps LDBL_EPSILON
#define int long long
#define ll long long
#define moder 1000000007
#define INF LLONG_MAX/3
#define P std::pair<int,int>
#define prique priority_queue<int,vector<int>,greater<int>>
using namespace std;
int n,k,a[1010],b[1000010];
set<int> st;
signed main(){
	cin>>n>>k;
	for(int i=1;i<=n;i++)cin>>a[i];
	for(int i=2;i<=n;i++)a[i]+=a[i-1];
	int cnt=0;
	for(int i=1;i<=n;i++){
		for(int j=i;j<=n;j++){
			b[cnt]=a[j]-a[i-1];
			cnt++;
		}
	}
	int ans=0;
	for(int keta=45;keta>=0;keta--){
		int c=0;
		rep(i,cnt){
			if(((b[i]>>keta)&(ll)1)&&st.find(i)==st.end())c++;
		}
		if(c>=k){
			rep(i,cnt){
				if((b[i]>>keta)&(ll)1)b[i]-=(ll)1<<keta;
				else{
					st.insert(i);
				}
			}
			ans+=(ll)1<<keta;
		}
		else{
			rep(i,cnt){
				if((b[i]>>keta)&(ll)1)b[i]-=(ll)1<<keta;
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 29824
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<int, int>;
using Vec  =vector<int>;

void	my_swap(ll &a, ll &b)
{
	ll	tmp;
	tmp = a;
	a = b;
	b = tmp;
}

ll		gcd(ll a, ll b)
{
	if (a < b)
		my_swap(a, b);
	if (b)
		return (gcd(b, a % b));
	return (a);
}

ll		lcm(ll a, ll b)
{
	return (a * b / gcd(a, b));
}
 
int		main(void)
{
	ll	 a, b;
	cin >> a >> b;
	cout << lcm(a, b) << endl;
}


Measured memory_bytes: 256
N = int(input())
P = [list(map(int, input().split())) for i in range(N)]
P.sort(key=lambda x: x[0]+x[1])

L = 10**5
dp = [0]*L
for w, s, v in P:
    for i in range(s, -1, -1):
        dp[i+w] = max(dp[i+w], dp[i] + v)
print(max(dp))

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

int main()
{
    int N;
    cin >> N;
    string S;
    cin >> S;
   
    int counter = 0;
    int l = 0;
    int m = 1;
    int n = 2;

    for (int x = 0; x <= N; ++x) {
    if (S[l] == 'A' && S[m] == 'B' && S[n] == 'C') {
        ++l;
        ++m;
        ++n;
        ++counter;
        }
        else {
            ++l;
            ++m;
            ++n;
        }
    }
    cout << counter << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
//C
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int inf=0x3f,INF=0x3f3f3f3f; const ll LLINF=0x3f3f3f3f3f3f3f3f;
        ///memset   ///regular use
inline ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b);}
inline ll lcm(ll a, ll b) { return a * b / gcd(a, b);}



int main()
{
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int n,m;
    cin>>n>>m;
    ll ans = 0;
    set<int> st[n+1];//switch i affects which bulbs

    for(int i =0; i<m; i++){
        int k, swt;
        cin>>k;
        for(int j =0; j<k; j++){
            cin>>swt;
            swt--;
            st[swt].insert(i);//switch swt, affects bulb i
        }
    }
    int parity[m];
    for(int i =0; i<m; i++){
        cin>>parity[i];
    }

    for(int i =0; i<(1<<(n)); i++){
        int cnt[m];
        for(int j =0; j<m; j++){
            cnt[j] = 0;
        }
        for(int j =0; j<=n; j++){
            if(((1<<j)&i)){//switch is used in this combo
                for(auto it = st[j].begin(); it!=st[j].end(); it++){
                    cnt[*it]++;
                    //cout<<"iter " <<*it<<"\n";
                }
            }
        }
        bool ok = true;
        for(int j =0; j<m; j++){
            if(cnt[j]%2!= parity[j]){
                //cout<<"mask "<<i<<"\n";
                //cout<<j<<" " << cnt[j]<<"\n";
                ok = false;
                break;
            }
        }
        if(ok){
            ans++;
        }
    }
    cout<<ans<<"\n";
}


Measured memory_bytes: 3572
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int a, b, c;
    cin >> a >> b >> c;
    set<int> s;
    s.emplace(a);
    s.emplace(b);
    s.emplace(c);
    cout << (sz(s) == 2 ? "Yes" : "No") << endl;
}


Measured memory_bytes: 256
import std.stdio, std.conv, std.string, std.array, std.math, std.regex, std.range, std.ascii, std.numeric, std.random;
import std.typecons, std.functional, std.traits,std.concurrency;
import std.algorithm, std.container;
import core.bitop, core.time, core.memory;
import std.bitmanip;
import std.regex;

enum INF = long.max/3;
enum MOD = 10L^^9+7;

//辞書順順列はiota(1,N),nextPermituionを使う


void end(T)(T v)
if(isIntegral!T||isSomeString!T||isSomeChar!T)
{
    import core.stdc.stdlib;
    writeln(v);
    exit(0);
}

T[] scanArray(T = long)()
{
    static char[] scanBuf;
    readln(scanBuf);
    return scanBuf.split.to!(T[]);
}

dchar scanChar()
{
    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    return cast(dchar)c;
}

T scanElem(T = long)()
{
    import core.stdc.stdlib;
    static auto scanBuf = appender!(char[])([]);

    scanBuf.clear;

    int c = ' ';
    while (isWhite(c) && c != -1)
    {
        c = getchar;
    }
    while (!isWhite(c) && c != -1)
    {
        scanBuf ~= cast(char) c;
        c = getchar;
    }
    return scanBuf.data.to!T;
}

dchar[] scanString(){
    return scanElem!(dchar[]);
}


void main()
{
  auto a=scanChar;
  foreach(e;['a','i','u','e','o'])if(e==a)end("vowel");end("consonant");
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace::std;
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;

// #include <boost/multiprecision/cpp_dec_float.hpp>
// #include <boost/multiprecision/cpp_int.hpp>
// #include <boost/numeric/interval.hpp>
// #include <boost/numeric/interval/io.hpp>
// #include <boost/intrusive/rbtree.hpp>
// #include <boost/geometry.hpp>
// #include <boost/geometry/geometries/linestring.hpp>
// #include <boost/geometry/geometries/polygon.hpp>
// #include <boost/geometry/geometries/point_xy.hpp>
// namespace mp = boost::multiprecision;
// typedef mp::number<mp::cpp_dec_float<0>> cfloat;
// typedef mp::cpp_int cint;

#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
#include<ext/pb_ds/tag_and_trait.hpp>
using namespace __gnu_pbds;
template<typename T=long long>using pbds=tree<T,null_type,less<T>,rb_tree_tag,tree_order_statistics_node_update>;

typedef long long lint;
typedef long long ll;
typedef long double ldouble;
typedef vector<lint> vec;
typedef vector<vector<lint>> mat;
typedef vector<vector<vector<lint>>> mat3;
typedef vector<double> dvec;
typedef vector<vector<double>> dmat;
typedef vector<vector<vector<double>>> dmat3;
typedef vector<string> svec;
typedef vector<vector<string>> smat;
typedef vector<vector<vector<string>>> smat3;
typedef vector<pair<lint,lint>> pvec;
typedef vector<vector<pair<lint,lint>>> pmat;
typedef vector<vector<vector<pair<lint,lint>>>> pmat3;
#define rep(i, n) for(lint i = 0; i < (lint)(n); i++)
#define irep(i) for(lint i = 0;; i++)
#define irep1(i) for(lint i = 1;; i++)
#define irep2(i) for(lint i = 2;; i++)
#define rrep(i, n) for(lint i = (lint)(n-1); i >-1; i--)
#define rrepi(i,a,b) for(lint i = (lint)(b-1); i >a-1; i--)
#define repi(i,a,b) for(lint i=lint(a);i<lint(b);i++)
#define rep2(i,a,b,c) for(lint i=lint(a);i>lint(b);i+=c)
#define all(x) (x).begin(),(x).end()
#define PI 3.141592653589793
#define dist(x1,y1,x2,y2) (pow(pow(x2-x1,2)+pow(y2-y1,2),0.5))
#define output(v) do{bool f=0;for(auto i:v){cout<<(f?" ":"");if(i>INF/2)cout<<"INF";else cout<<i;f=1;}cout<<"\n";}while(0)
#define output2(v) for(auto j:v)output(j);
#define _output(v) do{bool f=0;rep(i,v.size()){cout<<(f?" ":"");if(v[i]>INF/2)cout<<"INF";else cout<<v[i];f=1;}cout<<"\n";}while(0)
#define _output2(v) rep(j,v.size()){_output(v[j]);}
#define input(a,n) lint n;cin>>n;vector<lint>a(n);rep(i,n)cin>>a[i];
#define SUM(v) accumulate(all(v),0LL)
#define INF (1LL<<60)
#define IINF (1<<30)
#define EPS (1e-10)
#define LINF 9223372036854775807
#define MOD 1000000007
#define endl "\n"
template<typename T=lint>T in(){return *istream_iterator<T>(cin);}
inline lint gcd(lint a,lint b){return b?gcd(b,a%b):a;}
inline lint lcm(lint a,lint b){return a*b/gcd(a,b);}
inline bool chmin(auto& s,const auto& t){bool res=s>t;s=min(s,t);return res;}
inline bool chmax(auto& s,const auto& t){bool res=s<t;s=max(s,t);return res;}
vector<lint> dx={-1,1,0,0,1,1,-1,-1};
vector<lint> dy={0,0,-1,1,1,-1,1,-1};

int main(){
    lint n;
    cin>>n;
    cout<<(n+1)/2*1./n;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define per1(i,n) for(int i=n;i>0;i--)
#define all(v) v.begin(), v.end()
typedef long long ll;
typedef pair<ll,ll> P;
typedef vector<ll> vec;
typedef vector<vec> mat;
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int h,w,k;
    cin>>h>>w>>k;
    char C[10][10];
    rep(i,h)rep(j,w) cin>>C[i][j];
    int ans=0;
    rep(i,pow(2,h+w)){
        vec H(h,0),W(w,0);
        int p=i;
        rep(j,h) H[j]=(p%2),p/=2;
        rep(j,w) W[j]=(p%2),p/=2;
        int a=0;
        rep(i,h)rep(j,w){
            if(!H[i]&&!W[j]&&C[i][j]=='#') a++;
        }
        if(a==k) ans++;
    }
    cout<<ans;
}

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

#ifdef LOCAL
#include "debug.h"
#else
#define DEBUG(...)
#endif

template <class T, class Op = multiplies<T>>
constexpr T power(T a, long long n, Op op = Op(), T e = {1}) {
  assert(n >= 0);
  while (n) {
    if (n & 1) e = op(e, a);
    if (n >>= 1) a = op(a, a);
  }
  return e;
}

template <unsigned M> struct modular {
  using m = modular;
  static constexpr unsigned mod = M;
  unsigned v;
  modular(long long x = 0) : v((x %= mod) < 0 ? x + mod : x) {}
  m operator-() const { return m() -= *this; }
  m& operator+=(m b) { if ((int)(v += b.v - mod) < 0) v += mod; return *this; }
  m& operator-=(m b) { if ((int)(v -= b.v) < 0) v += mod; return *this; }
  m& operator*=(m b) { v = (uint64_t)v * b.v % mod; return *this; }
  m& operator/=(m b) { return *this *= power(b, mod - 2); }
  friend m operator+(m a, m b) { return a += b; }
  friend m operator-(m a, m b) { return a -= b; }
  friend m operator*(m a, m b) { return a *= b; }
  friend m operator/(m a, m b) { return a /= b; }
  friend bool operator==(m a, m b) { return a.v == b.v; }
};

using mint = modular<power(10, 9) + 7>;

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int n, k;
  cin >> n >> k;
  vector<long long> a(n);
  int pos = 0, zero = 0, neg = 0;
  for (auto&& e : a) {
    cin >> e;
    pos += e > 0;
    zero += e == 0;
    neg += e < 0;
  }
  bool ok = k <= n - zero;
  ok &= k < n - zero or neg % 2 == 0;
  ok &= pos > 0 or k % 2 == 0;
  DEBUG(ok);
  if (ok) {
    sort(begin(a), end(a), [](int x, int y) {
      return abs(x) > abs(y);
    });
    while (a.back() == 0) {
      a.pop_back();
    }
    DEBUG(a, k);
    int cnt = count_if(begin(a), begin(a) + k, [](int x) { return x < 0; });
    if (cnt & 1) {
      int p = k - 1;
      while (a[p] > 0) {
        --p;
      }
      int q = find_if(begin(a) + k, end(a), [](int x) { return x > 0; }) - begin(a);
      DEBUG(p, q);
      int r = k - 1;
      while (r >= 0 and a[r] < 0) {
        --r;
      }
      int s = find_if(begin(a) + k, end(a), [](int x) { return x < 0; }) - begin(a);
      DEBUG(r, s);
      if (q < n - zero and (r == -1 or a[r] < 0 or s == n - zero or abs(a[q] * a[r]) > abs(a[p] * a[s]))) {
        swap(a[p], a[q]);
      } else {
        swap(a[r], a[s]);
      }
    }
    mint res = accumulate(begin(a), begin(a) + k, mint(1), multiplies<>());
    cout << res.v << '\n';
  } else if (zero) {
    cout << "0\n";
  } else {
    sort(begin(a), end(a), [](int x, int y) {
      return abs(x) < abs(y);
    });
    mint res = accumulate(begin(a), begin(a) + k, mint(1), multiplies<>());
    cout << res.v << '\n';
  }
}


Measured memory_bytes: 4776
import itertools
import copy
yoko,tate,left = map(int,input().split())
clist = []
ylist = [];tlist = []

for i in range(yoko+1):
    ylist += list(itertools.combinations(range(yoko),i))
for i in range(tate+1):
    tlist += list(itertools.combinations(range(tate),i))

for i in range(yoko):
    clist.append(list(input()))

counter = 0
def color(y,t,clist):
    global yoko,tate
    black = 0
    temp = copy.deepcopy(clist)
    if len(y) == 0:
        for tcomb in t:
            for j in range(yoko):
                temp[j][tcomb] = 'r'

    for ycomb in y:
        temp[ycomb][:] = ['r' for i in range(tate)]
        for tcomb in t:
            for j in range(yoko):
                    temp[j][tcomb] = 'r'

    for yokol in temp:

        black += yokol.count('#')
    if black == left:
        return True
    else:
        return False

for y in ylist:
    for t in tlist:
        if color(y,t,clist):
            counter += 1

print(counter)


Measured memory_bytes: 9228
(R,C,K),*RCV = $<.map{|ln| ln.split.map(&:to_i) }

Rs = Array.new(R){ [] }
RCV.each{|s,d,v|
	Rs[s-1] << [d-1,v]
}

r0 = [0]*C
while r = Rs.shift
	r.empty? and next or r.sort!

	c0,vs = 0,[0]*4
	until r.empty?
		c,v = r.shift
		vs[0] = [vs[0],r0[c0..c].max].max
		vs[3] = vs[2]+v if vs[3] < vs[2]+v
		vs[2] = vs[1]+v if vs[2] < vs[1]+v
		vs[1] = vs[0]+v if vs[1] < vs[0]+v
		r0[c] = vs.max
		c0 = c+1
	end
end

p r0.max


Measured memory_bytes: 188724
#include <iostream>

// 1 2 3 => -1
// 5 4 3 => 1
// 7 8 9 => -1
// 17 16 15 => 1

// 1 3 5 => -2
// 8 6 6 => 2

int main(int argc, char *argv[]) {
  long long a, b, c, k;
  std::cin >> a >> b >> c >> k;
  long long ans = a - b;
  if (k % 2 == 0)
    std::cout << ans << std::endl;
  else
    std::cout << -ans << std::endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main(void){
	int a,b,c;
	char op;
	while(1){
	scanf("%d %c %d",&a,&op,&b);
	if(op == '+'){
		c=a+b;
	}else if(op == '-'){
		c=a-b;
	}else if(op == '*'){
		c=a*b;
	}else if(op == '/'){
		c=a/b;
	}else {
		break;
	}
		printf("%d\n",c);
	}
	
	
	return 0;
}

Measured memory_bytes: 600
def main():
	S = input()
	N = len(S)
	ans = 0
	for i in range(2**(N-1)):
		p = 0
		current = S
		for j in range(N-1):
			if (i>>j) & 1 == 1:
				ans += int(current[p:j+1])
				p = j+1
		if p != N:
			ans += int(current[p:N+1])
	print(ans)

if __name__ == '__main__':
	main()

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

const int maxn = 20;
int N;
int num[maxn];
int cnt;
int ans;

bool check(int no)
{
	//cout << no << endl;
	int a = 0, b = 0, c = 0;
	int tmp = no;
	int res;
	for(int i = 0; i < cnt; i++)
	{
		res = tmp % 10; 
		if(res == 3) a++;
		else if(res == 5) b++;
		else if(res == 7) c++;
		tmp = tmp / 10;
	}
	if(a && b && c) return true;
	else return false;
}

void dfs(int cur)
{
	if(cur >= 3 && cur <= cnt)
	{
		//cout << cur<< endl;
		int sum = 0;
		for(int i = 0; i < cur; i++)
		{
			if(i == 0) sum += num[i]; 
			else sum += num[i] * pow(10, i);
		}
		if(sum <= N && check(sum)) 
		{ 
			//cout << sum << endl;  
			ans++; 
		}
	}
	else if(cur > cnt) return;

	num[cur] = 3; dfs(cur+1);
	num[cur] = 5; dfs(cur+1);
	num[cur] = 7; dfs(cur+1);
}

int main()
{
	cin >> N;
	int tmp = N;
	while(1)
	{
		tmp /= 10;
		cnt++;
		if(!tmp) break;
	}
	dfs(0);
	printf("%d\n",ans);
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
"""
AtCoder A
"""

import sys, math, random
import numpy as np

# N = int(input())
# A = list(map(int,input().split())) # N row 1 column
# A = [int(input()) for _ in range(N)] # 1 row N column
# S = str(input()) # str(input()) == input() -> 'abc'
# S = list(input()) # abc -> ['a','b','c']
# S.replace('ABC','X') # "testABCABC" -> "testXX"
 
inf = 10**20
eps = 1.0 / 10**10
mod = 10**9+7
dd = [(-1,0),(0,1),(1,0),(0,-1)]
ddn = [(-1,0),(-1,1),(0,1),(1,1),(1,0),(1,-1),(0,-1),(-1,-1)]
 
def LI(): return list(map(int, sys.stdin.readline().split()))
def LLI(): return [list(map(int, l.split())) for l in sys.stdin.readlines()]
def LI_(): return [int(x)-1 for x in sys.stdin.readline().split()]
def LF(): return [float(x) for x in sys.stdin.readline().split()]
def LS(): return sys.stdin.readline().split()
def I(): return int(sys.stdin.readline())
def F(): return float(sys.stdin.readline())
def S(): return input()


def main():
    W, H, x, y = list(map(int,input().split()))
    if W==x*2 and H==y*2:
        print("%f 1"%(W*H/2))
    else:
        print("%f 0"%(W*H/2))
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 23620
#pragma GCC optimize("O3")
#pragma GCC optimize ("unroll-loops")
#pragma GCC target ("avx")
#include <bits/stdc++.h>
constexpr int INF = 2147483647;
constexpr long long int INF_LL = 9223372036854775807;
constexpr int MOD = 1000000007;
constexpr double PI = 3.14159265358979323846;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;

//modint
template<typename T> T modinv(T a, T m) {
	T b = m, u = 1, v = 0;
	while (b) {
		T t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
template<typename T> T modpow(T x, int k) {
	if (k == 0)return 1;
	if (k % 2 == 0) return modpow(x * x, k / 2);
	else return x * modpow(x, k - 1);
}

template<int mod> class modint {
public:
	ll val;
	modint(ll a) {
		val = a % mod;
	}
	modint operator+(const modint& r) {
		return modint((this->val + r.val) % mod);
	}
	modint operator-(const modint& r) {
		return modint((this->val - r.val) % mod + ((this->val - r.val) % mod < 0) * mod);
	}
	modint operator*(const modint& r) {
		return modint((((this->val % mod) * (r.val % mod))) % mod);
	}
	modint operator/(const modint& r) {
		return modint(this->val * modinv<ll>(r.val, mod) % mod);
	}
	modint& operator+=(const modint& r) {
		*this = *this + r;
		return *this;
	}
	modint& operator-=(const modint& r) {
		*this = *this - r;
		return *this;
	}
	modint& operator*=(const modint& r) {
		*this = *this * r;
		return *this;
	}
	modint& operator/=(const modint& r) {
		*this = *this / r;
		return *this;
	}

};


int main() {
	int N, A, B;
	cin >> N >> A >> B;
	modint<MOD> ans = modpow(modint<MOD>(2), N);
	modint<MOD> a = 1, b = 1;
	for (int i = N; i > N - A; i--) a *= modint<MOD>(i);
	for (int i = N; i > N - B; i--) b *= modint<MOD>(i);
	for (int i = 1; i <= A; i++)a /= modint<MOD>(i);
	for (int i = 1; i <= B; i++)b /= modint<MOD>(i);
	//cout << ans.val << " " << a.val << " " << b.val << endl;
	ans -= a + b;
	cout << ans.val - 1 << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    ll a,b,c,d;
    cin >> a >> b >> c >> d;
    bool canzero = false;
    if((a < 0 and b > 0)or(c < 0 and d > 0)){
        canzero = true;
    }
    
    ll answer = -1000000000000000000;
    answer = max(answer,a*c);
    answer = max(answer,a*d);
    answer = max(answer,b*c);
    answer = max(answer,b*d);
    if(canzero){
        answer = max(answer,0ll);
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 3628
#include <iostream>
#include <string>
#include <vector>
#include <numeric>
#include <queue>
#include <unordered_map>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <sstream>
#include <stack>
#include <map>
#include <set>
#include <ios>
#include <cctype>
#include <cstdio>

#define REP(i,a) for(int i = 0;i < (a);++i)
#define FOR(i,a,b) for(int i = (a);i < (b); ++i)
#define FORR(i,a,b) for(int i = (a) - 1;i >=(b);--i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SIZE(obj) (int)(obj).size()
#define YESNO(cond,yes,no){cout <<((cond)?(yes):(no))<<endl; }
#define SORT(list) sort(ALL((list)));
#define RSORT(list) sort((list).rbegin(),(list).rend())

using namespace std;

template<typename T>
T round_up(const T& a, const T& b) {
    return (a + (b - 1)) / b;
}

template <typename T1, typename T2>
istream& operator>>(istream& is, pair<T1, T2>& p) {
    is >> p.first >> p.second;
    return is;
}

template <typename T1, typename T2>
ostream& operator<<(ostream& os, pair<T1, T2>& p) {
    os << p.first << p.second;
    return os;
}

template <typename T>
istream& operator>>(istream& is, vector<T>& v) {
    REP(i, (int)v.size())is >> v[i];
    return is;
}

template <typename T>
ostream& operator<<(ostream& os, vector<T>& v) {
    REP(i, (int)v.size())os << v[i] << endl;
    return os;
}

using ll = long long;
constexpr int mod = 1'000'000'007;
constexpr int INF = 1'050'000'000;

template <typename T>
T clamp(T& n, T a, T b) {
    if (n < a)n = a;
    if (n > b)n = b;
    return n;
}

template <typename T>
static T GCD(T u, T v) {
    T r;
    while (v != 0) {
        r = u % v;
        u = v;
        v = r;
    }
    return u;
}

template <typename T>
static T LCM(T u, T v) {
    return u * v / gcd(u, v);
}

struct City {
    int cityNum;
    int prefNum;
    int year;
    string ID = "";
};

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    std::cout << fixed << setprecision(20);

    ll N, K;
    cin >> N >> K;

    ll ans = N / K;
    ans *= ans * ans;
    if (K % 2 == 0) {
        ll x = (N + (K / 2)) / K;
        x *= x * x;
        ans += x;
    }
    cout << ans << endl;
    return 0;

}

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

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

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

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

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

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


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

constexpr auto MAX = 100010;

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

int main() {
	int n; cin >> n;
	vi b(n - 1);
	rep(i, n - 1) cin >> b[i];

	ll ans = 0;
	ans += b[0];
	if (n > 2) ans += b[n - 2];
	else ans += b[0];

	Rep(i, n - 1) {
		ans += min(b[i - 1], b[i]);
	}

	cout << ans << endl;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
W = [int(input()) for _ in range(n)]
def can_load(W, k, q, n):
    i = 0
    for _ in range(k):
        s = 0
        while i < n and s + W[i] <= q:
            s += W[i]
            i += 1
    if i == n:
        return True
    else:
        return False

# 積載量をmidと仮定して二分探索
hi = 10 ** 9  # OK
lo = 0  # NG
while hi - lo > 1:
    mid = (hi + lo) // 2
    if can_load(W, k, mid, n):
        hi = mid
    else:
        lo = mid
print(hi)


Measured memory_bytes: 9560
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0;i< (n);++i)
using namespace std;
using ll=long long;
ll choose2(ll n){
	return n*(n-1)/2;//nCk
} 
int main(){
  int n;
  cin >> n;
  vector<int> a(n); //可変長配列の宣言
  rep(i,n) cin >>a[i];
  rep(i,n) a[i]--;
  vector<int> cnt(n);//vectorにいれた配列の数え上げ
  rep(i,n) cnt[a[i]]++;
  ll total=0;
  rep(i,n){
    total+= choose2(cnt[i]);
  }
  rep(i,n){
  ll ans=total;
    ans-= choose2(cnt[a[i]]);
    ans+= choose2(cnt[a[i]]-1);
    cout<< ans << endl;
  		}
}

Measured memory_bytes: 4096
import java.io.OutputStream;
import java.io.IOException;
import java.io.InputStream;
import java.io.PrintWriter;
import java.util.Scanner;

/**
 * Built using CHelper plug-in
 * Actual solution is at the top
 */
public class Main {
    public static void main(String[] args) {
        InputStream inputStream = System.in;
        OutputStream outputStream = System.out;
        Scanner in = new Scanner(inputStream);
        PrintWriter out = new PrintWriter(outputStream);
        B solver = new B();
        solver.solve(1, in, out);
        out.close();
    }

    static class B {
        public void solve(int testNumber, Scanner in, PrintWriter out) {
            // 入力
            String s = in.next();
            String ans = "";

            for (int i = 0; i < s.length(); i++) {
                char tmp = s.charAt(i);
                if (tmp == '0' || tmp == '1') {
                    ans += s.charAt(i);
                } else {
                    if (ans.length() > 0) ans = ans.substring(0, ans.length() - 1);
                }
            }

            out.println(ans);

        }

    }
}



Measured memory_bytes: 21844
from collections import Counter
n = int(input())
S = [input() for i in range(n)]
L = Counter(S).most_common()
ans = []
for i in range(len(L)):
  if L[i][1] == L[0][1]:
    ans.append(L[i][0])
  else:
    break
ans.sort()
for i in range(len(ans)):
  print(ans[i])

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

typedef long long ll;


#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define ALL(obj) (obj).begin(), (obj).end()
#define INF 1e9
#define LINF 1e18


const int MOD = 1e9+7;
const int MAXR = 510000;

template<ll mod> class modint{
public:
    ll val=0;
    //コンストラクタ
    modint(ll x=0){while(x<0)x+=mod;val=x%mod;}
    //コピーコンストラクタ
    modint(const modint &r){val=r.val;}
    //算術演算子
    modint operator -(){return modint(-val);} //単項
    modint operator +(const modint &r){return modint(*this)+=r;}
    modint operator -(const modint &r){return modint(*this)-=r;}
    modint operator *(const modint &r){return modint(*this)*=r;}
    modint operator /(const modint &r){return modint(*this)/=r;}
    //代入演算子
    modint &operator +=(const modint &r){
        val+=r.val;
        if(val>=mod)val-=mod;
        return *this;
    }
    modint &operator -=(const modint &r){
        if(val<r.val)val+=mod;
        val-=r.val;
        return *this;
    }
    modint &operator *=(const modint &r){
        val=val*r.val%mod;
        return *this;
    }
    modint &operator /=(const modint &r){
        ll a=r.val,b=mod,u=1,v=0;
        while(b){
            ll t=a/b;
            a-=t*b;swap(a,b);
            u-=t*v;swap(u,v);
        }
        val=val*u%mod;
        if(val<0)val+=mod;
        return *this;
    }
    //等価比較演算子
    bool operator ==(const modint& r){return this->val==r.val;}
    bool operator <(const modint& r){return this->val<r.val;}
    bool operator !=(const modint& r){return this->val!=r.val;}
};

using mint = modint<MOD>;

//入出力ストリーム
istream &operator >>(istream &is,mint& x){//xにconst付けない
    ll t;is >> t;
    x=t;
    return (is);
}
ostream &operator <<(ostream &os,const mint& x){
    return os<<x.val;
}

//累乗
mint modpow(const mint &a,ll n){
    if(n<=0)return 1;
    mint t=modpow(a,n/2);
    t=t*t;
    if(n&1)t=t*a;
    return t;
}

//二項係数の計算
mint fac[MAXR+1],finv[MAXR+1],inv[MAXR+1];
//テーブルの作成
void com_init() {
    fac[0]=fac[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    FOR(i,2,MAXR){
        fac[i]=fac[i-1]*mint(i);
        inv[i]=-inv[MOD%i]*mint(MOD/i);
        finv[i]=finv[i-1]*inv[i];
    }
}
//演算部分
mint com(ll n,ll k){
    if(n<k)return 0;
    if(n<0)return 0;
    if(k==0) return 1;
    return fac[n]*finv[k]*finv[n-k];
}

int main() {
    string S; cin >> S;
    int N = S.size();
    vector<vector<mint>> dp(N+1, vector<mint>(4,0));
    dp[0][0] = 1;
    
    REP(i,N){
        //進める
        REP(j,4){
            if(S[i]=='?') dp[i+1][j] += dp[i][j]*3;
            else dp[i+1][j] += dp[i][j];
        }

        //進めない
        if(S[i]=='A' || S[i]=='?')dp[i+1][1] += dp[i][0];
        if(S[i]=='B' || S[i]=='?')dp[i+1][2] += dp[i][1];
        if(S[i]=='C' || S[i]=='?')dp[i+1][3] += dp[i][2];
    }


    cout << dp[N][3] << endl;
    return 0;
}

Measured memory_bytes: 22256
import sys
sys.setrecursionlimit(10**7)
from bisect import bisect_left as bl
def main(n,a):
  ans=[0]*n
  ki=[[] for _ in range(n)]
  for _ in range(n-1):
    u,v=map(int,input().split())
    u,v=u-1,v-1
    ki[u].append(v)
    ki[v].append(u)
  inf=float('inf')
  p={}
  dp=[inf]*(n+1)
  dp[0]=0
  # dp[i]:長さiのLISの末尾の数値の最小値
  maxa=max(a)+1

  def dfs(v,p,dp):
    x=a[v]
    idx=bl(dp,x)
    tmp=dp[idx]
    dp[idx]=x
    # ans[v]=idx こっちだと頂点vで終わるLISの長さになる。下が正しい
    ans[v]=bl(dp,maxa)-1
    for nv in ki[v]:
      if nv==p:continue
      dfs(nv,v,dp)
    dp[idx]=tmp
  dfs(0,-1,dp)
  print(*ans,sep='\n')

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


Measured memory_bytes: 273168
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-11;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 11100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int a;scanf("%d",&a);
	printf("%d\n",8-(a-400)/200);
}

Measured memory_bytes: 1704
using System;

class Program
{
    static void Main(string[] args)
    {
        var s = Console.ReadLine();
        var t = Console.ReadLine();
        for (int i = 0; i < s.Length; i++)
        {
            s = s[s.Length - 1] + s.Substring(0, s.Length - 1);

            if (s == t)
            {
                Console.WriteLine("Yes");
                return;
            }
        }
        Console.WriteLine("No");
    }
}


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

using namespace std;

#define dump(n) cout<<"# "<<#n<<"="<<(n)<<endl
#define debug(n) cout<<__FILE__<<","<<__LINE__<<": #"<<#n<<"="<<(n)<<endl
#define repi(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,n) repi(i,0,n)
#define iter(c) __typeof((c).begin())
#define foreach(i,c) for(iter(c) i=(c).begin();i!=(c).end();i++)
#define allof(c) (c).begin(),(c).end()
#define mp make_pair

typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef pair<int,int> pii;

struct Dice{
	int face[6]; // top,bottom,left,right,front,back
	void Rotate(int a,int b,int c,int d){
		int temp=face[a];
		face[a]=face[b];
		face[b]=face[c];
		face[c]=face[d];
		face[d]=temp;
	}
	void TurnF(int n){rep(i,n)Rotate(0,2,1,3);}
	void TurnR(int n){rep(i,n)Rotate(0,4,1,5);}
	void TurnU(int n){rep(i,n)Rotate(4,3,5,2);}
	void TurnF(){TurnF(1);}
	void TurnR(){TurnR(1);}
	void TurnU(){TurnU(1);}
};

int main()
{
	for(int n;cin>>n,n;){
		Dice d={1,6,4,3,2,5};
		int res=1;
		rep(i,n){
			string s;
			cin>>s;
			if(s=="North")
				d.TurnR();
			if(s=="East")
				d.TurnF();
			if(s=="South")
				d.TurnR(3);
			if(s=="West")
				d.TurnF(3);
			if(s=="Right")
				d.TurnU();
			if(s=="Left")
				d.TurnU(3);
			res+=d.face[0];
		}
		cout<<res<<endl;
	}
	
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <map>
#include <queue> 
#include <stack>
#include <set>

using namespace std;
typedef long long ll;
#define rep(i, s, e) for (int(i) = (s); (i) <= (e); ++(i))
#define all(x) x.begin(),x.end()


int main()
{
	int n; cin>>n;
	vector<int> b(100010);
	rep(i,0,n-2){
	    cin>>b[i];
	}
	int ans = b[0];
	rep(i,1,n-2){
	    ans+=min(b[i-1],b[i]);
	}
	ans+=b[n-2];
	cout<<ans<<endl;
}


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

using namespace std;
 
typedef long long ll;
typedef long double ld;
typedef pair<int, int> Pii;
typedef pair<int, ll> Pil;
typedef pair<ll, ll> Pll;
typedef pair<ll, int> Pli;

#define fi first
#define se second

const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll MOD3 = 1812447359;
const ll INF = 1ll << 62;
const double PI = 2 * asin(1);

void yes() {printf("yes\n");}
void no() {printf("no\n");}
void Yes() {printf("Yes\n");}
void No() {printf("No\n");}
void YES() {printf("YES\n");}
void NO() {printf("NO\n");}

int X, Y, Z, K;
ll A[1005], B[1005], C[1005];
vector <ll> ans;

int main(){
  cin >> X >> Y >> Z >> K;
  for (int i = 1; i <= X; i++) cin >> A[i];
  sort(A+1, A+X+1, greater<ll>());
  for (int i = 1; i <= Y; i++) cin >> B[i];
  sort(B+1, B+Y+1, greater<ll>());
  for (int i = 1; i <= Z; i++) cin >> C[i];
  sort(C+1, C+Z+1, greater<ll>());

  for (int i = 1; i <= X; i++){
    for (int j = 1; j <= Y; j++){
      for (int k = 1; i * j * k <= K && k <= Z; k++){
        ans.push_back(A[i]+B[j]+C[k]);
      }
    }
  }
  sort(ans.begin(), ans.end(), greater<ll>());
  for (int i = 0; i < K; i++) cout << ans[i] << endl;

  return 0;
}


Measured memory_bytes: 4292
using System;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Math;

namespace CSharpSpiral {
	class Program {
		static void Main(string[] args) {
			var sw = new StreamWriter(Console.OpenStandardOutput()) {
				AutoFlush =
#if DEBUG
			true
#else
			false
#endif
			};
			Console.SetOut(sw);
			new Program().Solve(new ConsoleInput(
#if DEBUG
			new StreamReader("../../../inputData.txt")
#else
			Console.In
#endif
			, ' '));
			Console.Out.Flush();
		}
		public void Solve(ConsoleInput cin) {
			var K = cin.ReadInt;
			if(K <= 9) { Console.WriteLine(K); return; }

			var lunlun = new List<long>();
			for(int i = 1; i < 10; i++) {
				lunlun.Add(i);
			}
			var lls = 9;
			while(true) {
				var newLL = new List<long>();
				foreach(var ll in lunlun) {
					var llt = ll * 10;
					var last = ll % 10;
					if(last != 0) newLL.Add(llt + last - 1);
					newLL.Add(llt + last);
					if(last != 9) newLL.Add(llt + last + 1);
				}
				if(lls + newLL.Count() >= K) {
					Console.WriteLine(newLL[K - lls - 1]);
					return;
				}
				lls += newLL.Count();
				lunlun = newLL;
			}
		}
	}
	static class ExtendClass {
		public static string Join<T>(this IEnumerable<T> X, string separator = " ") => string.Join(separator, X);

	}
	class ConsoleInput {
		private readonly TextReader _stream;
		private readonly char _separator = ' ';
		private readonly Queue<string> inputStream;
		public ConsoleInput(TextReader stream, char separator = ' ') {
			this._separator = separator;
			this._stream = stream;
			inputStream = new Queue<string>();
		}
		public string Read {
			get {
				if(inputStream.Count != 0) return inputStream.Dequeue();
				string[] tmp = _stream.ReadLine().Split(_separator);
				for(int i = 0; i < tmp.Length; ++i)
					inputStream.Enqueue(tmp[i]);
				return inputStream.Dequeue();
			}
		}
		public string ReadLine { get { return _stream.ReadLine(); } }
		public int ReadInt { get { return int.Parse(Read); } }
		public long ReadLong { get { return long.Parse(Read); } }
		public double ReadDouble { get { return double.Parse(Read); } }
		public string[] ReadStrArray(long N) {
			var ret = new string[N];
			for(long i = 0; i < N; ++i)
				ret[i] = Read;
			return ret;
		}
		public int[] ReadIntArray(long N) { var ret = new int[N]; for(long i = 0; i < N; ++i) ret[i] = ReadInt; return ret; }
		public long[] ReadLongArray(long N) { var ret = new long[N]; for(long i = 0; i < N; ++i) ret[i] = ReadLong; return ret; }
		public double[] ReadDoubleArray(long N) { var ret = new double[N]; for(long i = 0; i < N; ++i) ret[i] = ReadDouble; return ret; }
		public bool isEOF {
			get { return _stream.Peek() == -1; }
		}
	}

}


Measured memory_bytes: 14688
#include <iostream>
#include <algorithm>
#include <vector>
#include <cmath>
#include <cstring>
#include <string>
#include <numeric>
#include <limits>
#include <set>
#include <map>
using namespace std;

struct union_find {
    std::vector<int> parent;
    int __size;
    union_find(int size_) : parent(size_, -1), __size(size_) {}
    void unite(int x, int y) {
        if ((x = find(x)) != (y = find(y))) {
            if (parent[y] < parent[x]) swap(x, y);
            parent[x] += parent[y];
            parent[y] = x;
            __size--;
        }
    }
    bool is_same(int x, int y) { return find(x) == find(y); }
    int find(int x) { return parent[x] < 0 ? x : parent[x] = find(parent[x]); }
    int size(int x) { return -parent[find(x)]; }
    int size() { return __size; }
};

int n, m;
vector<int> lang[100010];

int main() {
    while (cin >> n >> m) {
        for (int i = 0; i < 100010; i++) {
            lang[i].clear();
        }
        union_find uf(n);
        for (int i = 0; i < n; i++) {
            int k;
            cin >> k;
            for (int j = 0; j < k; j++) {
                int l;
                cin >> l;
                --l;
                lang[l].push_back(i);
            }
        }
        for (int i = 0; i < m; i++) {
            for (int j = 0; j < (int)lang[i].size() - 1; j++) {
                int a = lang[i][j];
                int b = lang[i][j + 1];
                uf.unite(a, b);
            }
        }
        cout << (uf.size() == 1 ? "YES" : "NO") << endl;
    }
}

Measured memory_bytes: 4608
#define _USE_MATH_DEFINES
#define _CRT_SECURE_NO_WARNINGS

#include <iostream>
#include <string>
#include <sstream>
#include <iomanip>
#include <cmath>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <queue>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <bitset>
#include <utility>
#include <numeric>

using namespace std;

using ll = long long;
using ull = unsigned long long;

const ll inf = (ll)1e9;
const ll mod = (ll)1e9 + 7;

#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()

int main()
{
	int n, y;
	cin >> n >> y;

	for (int i = 0; i <= n; i++)
	{
		for (int j = 0; j <= n; j++)
		{
			int k = n - (i + j);
			if (k >= 0)
			{
				if (1000 * i + 5000 * j + 10000 * k == y)
				{
					cout << k << " " << j << " " << i << endl;
					return 0;
				}
			}
		}
	}


	cout << -1 << " " << -1 << " " << -1 << endl;
}

Measured memory_bytes: 256