akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


int main(int argc, char* argv[])
{
    char str[15]={0};
    int a;
    scanf("%d", &a);
    scanf("%s", str);
    if(a>=3200) {
        printf("%s\n", str);
    }
    else {
        printf("red\n");
    }



    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n) for(ll i=0;i<n;i++)
#define repl(i,l,r) for(ll i=(l);i<(r);i++)
#define per(i,n) for(ll i=n-1;i>=0;i--)
#define perl(i,r,l) for(ll i=r-1;i>=l;i--)
#define fi first
#define se second
#define pb push_back
#define ins insert
#define pqueue(x) priority_queue<x,vector<x>,greater<x>>
#define all(x) (x).begin(),(x).end()
#define CST(x) cout<<fixed<<setprecision(x)
#define rev(x) reverse(x);
using ll=long long;
using vl=vector<ll>;
using vvl=vector<vector<ll>>;
using pl=pair<ll,ll>;
using vpl=vector<pl>;
using vvpl=vector<vpl>;
const ll MOD=1000000007;
const ll MOD9=998244353;
const int inf=1e9+10;
const ll INF=4e18;
const ll dy[9]={1,0,-1,0,1,1,-1,-1,0};
const ll dx[9]={0,-1,0,1,1,-1,1,-1,0};
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;
}
vl topsort(vvl &g){
    ll n=g.size();
    vl ans,ind(n);
    rep(i,n)for(auto e:g[i])ind[e]++;
    queue<ll> que;
    rep(i,n)if(!ind[i])que.push(i);
    while(!que.empty()){
        ll v=que.front();que.pop();
        ans.pb(v);
        for(auto nv:g[v]){
            ind[nv]--;if(!ind[nv])que.push(nv);
        }
    }
    return ans;
}
int main(){
    ll n,m;cin >> n >>m;
    vvl g(n);rep(i,m){
        ll a,b;cin >> a >> b;a--;b--;
        g[a].pb(b);
    }
    vl ord=topsort(g);
    vl dp(n);
    rep(i,n){
        ll v=ord[i];
        for(auto nv:g[v]){
            chmax(dp[nv],dp[v]+1);
        }
    }
    cout << *max_element(all(dp)) <<endl;
}

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

int main(){
	int c;
	cin >> c;
	if ( c>0 ) {
		int a[100];
		for ( int b = 0; b < c; b++ ) {
			cin >> a[ b ];
		}
		for ( int b = 0; b < c; b++ ) {
			cout << a[ c-1-b ];
			if ( b != c-1 ) {
				cout << " ";
			}
		}
		cout << endl;
	}
    return 0;
}

Measured memory_bytes: 1160
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>
#include <vector>
#include <utility>
#include <functional>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <deque>
#include <ctime>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define pb push_back
#define mp make_pair
#define all(r) r.begin(),r.end()
#define rall(r) r.rbegin(),r.rend()
#define fi first
#define se second
#define println(X) cout<<X<<endl;
#define DBG(X) cout<<#X<<" : "<<X<<endl;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vii;
typedef vector<ll> vl;
typedef vector<vl> vll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;
const double PI = acos(-1);

int main(){
	int n, x;
	cin>>n>>x;
	vi a(n);
	rep(i, n) cin>>a[i];
	ll ans = 0LL;
	for(int i = 1; i < n; i++){
		if(a[i]+a[i-1] > x){
			int dif = a[i]+a[i-1] - x;
			if(dif <= a[i]){
				a[i]-=dif;
				ans += dif;
			}
			else{
				ans += dif;
				a[i] = 0;
			}
		}
	}
	cout<<ans<<endl;
}

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

void insert(int _value);
void delete(int _value);
void deleteFirst(void);
void deleteLast(void);

struct Node{

  struct Node* next;
  struct Node* prev;
  int value;

};

struct Node* head;
struct Node* tail;
main(){

  int i;
  int n;
  int tmpValue;
  char str[20];
  struct Node* node;

  head = (struct Node*)malloc(sizeof(struct Node));
  tail = (struct Node*)malloc(sizeof(struct Node));
  head->next = tail;
head->prev = tail;

  scanf("%d",&n);

  for(i=0; i<n; i++){
    scanf("%s",str);
    if(!strcmp(str,"insert")){
      scanf("%d",&tmpValue);
      insert(tmpValue);
    }else if(!strcmp(str,"deleteFirst")){
      deleteFirst();
    }else if(!strcmp(str,"deleteLast")){
      deleteLast();
    }else if(!strcmp(str,"delete")){
      scanf("%d",&tmpValue);
      delete(tmpValue);
    }
  }

  for(node=head->next; node != tail; node=node->next){
    printf("%d",node->value);
    if(node->next!=tail){
      printf(" ");
    }
  }
  printf("\n");

  return 0;

}

void insert(int _value){

  struct Node* newNode;
  struct Node* tmpNode;

  newNode = (struct Node*)malloc(sizeof(struct Node));

  tmpNode = head->next;
  if(tmpNode != NULL){
    tmpNode->prev = newNode;
  }
  head->next = newNode;
  newNode->next = tmpNode;
  newNode->prev = head;

  newNode->value = _value;

}

void delete(int _value){

  struct Node* node;
  struct Node* tmpNode;
  for(node=head->next; node != NULL; node=node->next){
    if(node->value == _value){
      tmpNode = node->prev;
      if(tmpNode != NULL){
	tmpNode->next = node->next;
      }
      if(node->next != NULL){
	node->next->prev = tmpNode;
      }
      break;
    }
  }

}

void deleteFirst(){

  struct Node* node;
  node=head->next;

  if(head != NULL){
    head->next= node->next;
  }
  if(node->next != NULL){
    node->next->prev = head;
  }
  free(node);

}

void deleteLast(){

  struct Node* tmpNode;

  tmpNode=tail->prev;
  tail->prev=tmpNode->prev;
  tmpNode->prev->next=tail;

  free(tmpNode);

}

Measured memory_bytes: 15000
#include<bits/stdc++.h>
#define endl '\n'
#define int long long
#define eps 1e-9
#define oo 1e7+5

using namespace std;

typedef unsigned long long ull;
typedef vector<pair<int,pair<int,int>>> dirgraph;
typedef vector<vector<int>> graph;

int32_t main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);cout.tie(0);

	int n;
	string s;
	cin>>n>>s;
	int ans=0;

	for(int i=0;i<n-2;i++){
		if(s[i]=='A' && s[i+1]=='B' && s[i+2]=='C'){
			ans++;
		}
	}

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

Measured memory_bytes: 3612
# coding: utf-8
import math

def main():
    a, b = map(int, input().split())
    tmp_a_min = math.ceil(a / 0.08)
    tmp_a_max = math.ceil((a+1) / 0.08)
    tmp_b_min = math.ceil(b / 0.1)
    tmp_b_max = math.ceil((b+1) / 0.1)
    tmp_a = list(range(tmp_a_min, tmp_a_max))
    tmp_b = list(range(tmp_b_min, tmp_b_max))
    tmp = set(tmp_a) & set(tmp_b)
    if len(tmp) != 0:
        print(min(tmp))
    else:
        print(-1)
main()

Measured memory_bytes: 9180
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#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 = 1e18;
const double pi = acos(-1);

ll dp[2][42];  /* dp[id][i+1] : xの先頭からiビット目まで決めたときのf(x)の最大値。
                                ただし、id = 0 のときxは現時点でkと等しい。
                                id = 1 のときxは現時点でkより小さいことが確定。 */

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

    vl v0(41);  // v0[i] : 先頭からiビット目の0の個数
    vl v1(41);  // v1[i] : 先頭からiビット目の1の個数
    rep(loop, n) {
        ll a;
        cin >> a;
        exrep(i, 0, 40) {
            ll mask = 1LL<<(40 - i);
            if(mask & a) {
                v1[i]++;
            }
            else {
                v0[i]++;
            }
        }
    }

    rep(id, 2) {
        rep(i, 42) {
            dp[id][i] = -INF;
        }
    }
    
    dp[0][0] = 0;
    exrep(i, 0, 40) {
        ll mask = 1LL<<(40 - i);
        if(k & mask) {  // kの先頭からiビット目が1のとき
            chmax(dp[0][i+1], dp[0][i] + mask*v0[i]);
            chmax(dp[1][i+1], max(dp[1][i] + mask*max(v0[i], v1[i]), dp[0][i] + mask*v1[i]));
        }
        else {  // kの先頭からiビット目が0のとき
            chmax(dp[0][i+1], dp[0][i] + mask*v1[i]);
            chmax(dp[1][i+1], dp[1][i] + mask*max(v0[i], v1[i]));
        }
    }
    
    out(max(dp[0][41], dp[1][41]));
    re0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define var auto
#define Max std::max
#define Min std::min

#ifdef _MSC_VER
#define getchar_unlocked getchar
#define putchar_unlocked putchar
#define fseek_unlocked fseek
#endif

inline int read()
{
	int x = 0;
	int k;
	while (true)
	{
		k = getchar_unlocked();
		if (k < '0') break;
		x = x * 10 + k - '0';
	}
	return x;
}

void writeline(int x) {
	int s = 0;
	char f[8];
	while (x) {
		f[s++] = x % 10;
		x /= 10;
	}
	while (s--)
		putchar_unlocked(f[s] + '0');
	putchar_unlocked('\n');
}

#pragma optimization_level 3
int main()
{
	int h = read(), w = read();
	int columnAccum[2000] = {};
	int rowMax[2000] = {};
	int max = 0;
	for (int i = 0; i < h; i++)
	{
		int currentChain = 0;
		for (int j = 0; j < w; j++)
		{
			var c = getchar_unlocked() & 1;
			if (c)
			{
				max = Max(max, columnAccum[j] + rowMax[j]);
				for (int k = j - currentChain; k < j; k++)
					rowMax[k] = Max(rowMax[k], currentChain);
				currentChain = 0;
				rowMax[j] = 0;
				columnAccum[j] = 0;
			}
			else
			{
				currentChain++;
				columnAccum[j]++;
			}
		}
		getchar_unlocked();
		for (int j = w - currentChain; j < w; j++)
			rowMax[j] = Max(rowMax[j], currentChain);
	}
	for (int i = 0; i < w; i++)
		max = Max(max, columnAccum[i] + rowMax[i]);
	writeline(max - 1);
	return 0;
}


Measured memory_bytes: 256
n=int(input())
l=list(map(int,input().split()))
l.sort()
ans=0
for i in range(n):
  k=i
  for j in range(i+1,n):
    while k<n and l[k]<l[i]+l[j]:
      k+=1
    ans+=k-(j+1)
print(ans)

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

const int MAX_N = (int)(2e5 + 5);

int n;
string s;

int white[MAX_N];
int black[MAX_N];

int ans;

int main(void) {
  // Here your code !
  scanf("%d", &n);
  cin >> s;

  for (int i = 0; i < n; ++i) {
    if (s[i] == '#') {
      black[i] = 1;
    }
    else {
      white[i] = 1;
    }
  }

  for (int i = 1; i < n; ++i) {
    black[i] = black[i] + black[i - 1];
  }

  for (int i = 1; i < n; ++i) {
    white[i] = white[i] + white[i - 1];
  }

  int all_black = black[n - 1];
  int all_white = white[n - 1];

  ans = min(n - all_black, n - all_white);

  for (int i = 0; i < n; ++i) {
    int left_b = black[i];
    int left_w = white[i];

    int right_b = all_black - left_b;
    int right_w = all_white - left_w;

    // case: w, w
    ans = min(ans, left_b + right_b);

    // case: w, b
    ans = min(ans, left_b + right_w);

    // case: b, b
    ans = min(ans, left_w + right_w);
  }

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

  return 0;
}


Measured memory_bytes: 2180
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <stack>
#include <queue>
#include <map>
#include <algorithm>
#include <iomanip>
#include <math.h>
#include <string.h>
#include <cstdio>
using namespace std; using ll = long long; using pll = pair<ll, ll>;
using vl = vector<ll>; using vll = vector<vl>; using vpll = vector<pll>;
//**デバッグ準備**//
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
void debug_out() { cerr << endl; }
template<typename Head, typename... Tail>
void debug_out(Head h, Tail... t) {
	cerr << " " << h;
	if (sizeof...(t) > 0) cerr << " :";
	debug_out(t...);
}
template <typename T>
ostream& operator<<(ostream& os, vector<T> vec) {
	for (size_t i = 0; i < vec.size(); i++)os << vec[i] << (i + 1 == vec.size() ? "" : " ");
	return os;
}
ll ctoi(char c) {
	switch (c) {
	case '0': return 0; case '1': return 1; case '2': return 2;
	case '3': return 3; case '4': return 4; case '5': return 5;
	case '6': return 6; case '7': return 7; case '8': return 8;
	case '9': return 9;  default: return 0;
	}
}
bool pairCompare(const pll firstElof, pll secondElof)
{
	return firstElof.first > secondElof.first;
}
//**Snippetリスト**//
//rep, vin, all, iteLoop//
//gcdlcm, isPrime, eratos, divisor, modinv, bitSearch, bitList, dfs, bfs//
//dijkstra, UnionFind, COM, digitDP//
ll i, j, k, l; ll N, M, K, H, W, L, X, Y, Z;
ll MOD = 1000000007; ll INF = 9999999999999; ll ans = 0;
vl flag, color; vll path; ll start = 0;
//***********//
ll gcd(ll x, ll y) {
	ll r;
	if (x < y) {
		swap(x, y);
	}
	while (y > 0) {
		r = x % y;
		x = y;
		y = r;
	}
	return x;
}
ll lcm(ll x, ll y) {
	return x * y / gcd(x, y);
}
int main() {
	cin >> K;
	for (i = 1; i <= K; i++) {
		for (j = 1; j <= K; j++) {
			for (k = 1; k <= K; k++) {
				ans += gcd(gcd(i, j), k);
			}
		}
	}
	cout << ans;
}


Measured memory_bytes: 3640
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n,k;
    cin>>n>>k;
    vector<int>a(n);
    for(int &x:a)
    {
        cin>>x;
    }
    int dp[100005];
    dp[0]=0;
    for(int i=1;i<=k;i++)
    {
        dp[i]=0;
        for(int it:a)
        {
            if(i>=it and dp[i-it]==0)
            {
                dp[i]=1;
                break;
            }
        }
    }
    if(dp[k]==1)
    {
        cout<<"First";
    }
    else
    {
        cout<<"Second";
    }
    return 0;
}

Measured memory_bytes: 4000
using System;

namespace A_HonestOrDishonest {
    class Program {
        static void Main(string[] args) {
            // スペース区切りの整数の入力
            string[] input = Console.ReadLine().Split(' ');
            string a = input[0];
            string b = input[1];
            string ans = (a == b)? "H": "D";
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 11092
#include"bits/stdc++.h"
#include<boost/multi_array.hpp>
#include<boost/optional.hpp>
#include<boost/range/irange.hpp>
#include<boost/range/algorithm.hpp>
#include<boost/range/adaptors.hpp>
using namespace std;
namespace adaptor = boost::adaptors;


#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep3(i,m,n) for(int (i)=m;(i)<=(n);(i)++)
#define rep3rev(i,m,n) for(int (i)=m;(i)>=(n);(i)--)
typedef long long ll;


void Main()
{
  int h, n;
  cin >> h >> n;
  int a;
  ll sum;
  rep(i,n){
    cin >> a;
    sum += a; 
  }
  if(h<=sum) puts("Yes");
  else puts("No");

 return;
}


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


Measured memory_bytes: 256
while True:
	m,f,r = map(int,input().split(" "))

	#終了判定
	if m == -1 and f == -1 and r == -1:
		break

	if (m == -1 or f == -1):
		print("F")
	else:
		if m + f >= 80:
			print("A")
		elif m + f >= 65 and m + f < 80:
			print("B")
		elif m + f >= 50 and m + f < 65:
			print("C")
		elif m + f >= 30 and m + f < 50:
			if r >= 50:
				print("C")
			else:
				print("D")
		elif m + f < 30:
			print("F")




Measured memory_bytes: 5592
/**
 * author:    Ziel
 * created:   22.04.2020 20:29:29
**/

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll n,x,y,z,m,k,to,len,d[100100];
set<pair<ll,ll>>q;
vector<pair<ll,ll>>g[100100];
int main()
{
	scanf("%lld",&n);
	for(ll i=1;i<n;i++)
		scanf("%lld%lld%lld",&x,&y,&z),g[x].push_back({y,z}),g[y].push_back({x,z});
	scanf("%lld%lld",&m,&k);
	q.insert({0,k});
	for(ll i=1;i<=n;i++)
		d[i]=2000000000000000009;
	d[k]=0;
	while(q.size())
	{
		int v=q.begin()->second;
		q.erase(q.begin());
		for(auto edge:g[v])
		{
			to=edge.first,len=edge.second;
			if(d[to]>d[v]+len)
			{
				q.erase({d[to], to});
				d[to]=d[v]+len;
				q.insert({d[to], to});
			}
		}
	}
	while(m--)
	{
		scanf("%lld%lld",&x,&y);
		printf("%lld\n",d[x]+d[y]);
	}
	return 0;
}

/*
	Raise your standard.
*/

Measured memory_bytes: 15344
n=int(input())
a=[0]+list(map(int,input().split()))
for i in range(n):
  a[i+1]+=a[i]
mod=10**9+7
ans=0
for i in range(1,n+1):
  ans+=(a[i]-a[i-1])*(a[-1]-a[i])%mod
  ans%=mod
print(ans)

Measured memory_bytes: 93980
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define all(c) (c).begin(),(c).end()
#define pb push_back
#define dbg(...) do{cerr<<__LINE__<<": ";dbgprint(#__VA_ARGS__, __VA_ARGS__);}while(0);

using namespace std;

namespace std{template<class S,class T>struct hash<pair<S,T>>{size_t operator()(const pair<S,T>&p)const{return ((size_t)1e9+7)*hash<S>()(p.first)+hash<T>()(p.second);}};template<class T>struct hash<vector<T>>{size_t operator()(const vector<T> &v)const{size_t h=0;for(auto i : v)h=h*((size_t)1e9+7)+hash<T>()(i)+1;return h;}};}
template<class T>ostream& operator<<(ostream &os, const vector<T> &v){os<<"[ ";rep(i,v.size())os<<v[i]<<(i==v.size()-1?" ]":", ");return os;}template<class T>ostream& operator<<(ostream &os,const set<T> &v){os<<"{ "; for(const auto &i:v)os<<i<<", ";return os<<"}";}
template<class T,class U>ostream& operator<<(ostream &os,const map<T,U> &v){os<<"{";for(const auto &i:v)os<<" "<<i.first<<": "<<i.second<<",";return os<<"}";}template<class T,class U>ostream& operator<<(ostream &os,const pair<T,U> &p){return os<<"("<<p.first<<", "<<p.second<<")";}
void dbgprint(const string &fmt){cerr<<endl;}template<class H,class... T>void dbgprint(const string &fmt,const H &h,const T&... r){cerr<<fmt.substr(0,fmt.find(","))<<"= "<<h<<" ";dbgprint(fmt.substr(fmt.find(",")+1),r...);}
typedef long long ll;typedef vector<int> vi;typedef pair<int,int> pi;const int inf = (int)1e9;const double INF = 1e12, EPS = 1e-9;

int main(){
	int n, q; scanf("%d%d", &n, &q);
	vi v(300001, -1);
	rep(i, n){ int x; scanf("%d", &x); v[x] = x; }
	for(int i = 1; i < v.size(); i++) v[i] = max(v[i], v[i - 1]);
	
	while(q--){
		int x, ans = 0; scanf("%d", &x);
		for(int i = x - 1, m = 0; i < v.size(); i += x, m += x){
			ans = max(ans, v[i] - m);
		}
		cout << ans << endl;
	}
	return 0;
}


Measured memory_bytes: 3888
if __name__ == '__main__':
	n, m, x = map(int, input().split(' '))
	a = [int(x) for x in input().split(' ')]

	p = x
	cost = 0
	while p > 0:
		if p in a:
			cost += 1
		p -= 1
	cost_left = cost

	p = x
	cost = 0
	while p < n:
		if p in a:
			cost += 1
		p += 1
	cost_right = cost

	print(min((cost_left, cost_right)))

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

using namespace std;

#define sz(a) int(a.size())

typedef long long ll;
struct Line {
	mutable ll k, m, p;

	bool operator<(const Line &o) const { return k >= o.k; }

	bool operator<(ll x) const { return p < x; }
};

struct LineContainer : multiset<Line, less<>> {
	const ll inf = LLONG_MAX;

	ll div(ll a, ll b) { return a / b - ((a ^ b) < 0 && a % b); }

	bool isect(iterator x, iterator y) {
		if (y == end()) { x->p = inf; return false;}
		if (x->k == y->k) x->p = x->m > y->m ? inf : -inf;
		else x->p = div(y->m - x->m, x->k - y->k);
		return x->p >= y->p;
	}

	void add(ll k, ll m) {
		auto z = insert({k, m, 0}), y = z++, x = y;
		while (isect(y, z)) z = erase(z);
		if (x != begin() && isect(--x, y)) isect(x, y = erase(y));
		while ((y = x) != begin() && (--x)->p >= y->p)
			isect(x, erase(y));
	}

	ll query(ll x) {
		assert(!empty());
		auto l = *lower_bound(x);
		return l.k * x + l.m;
	}
};


int main() {
	int n;
	long long c;
	cin >> n >> c;
	vector <int> h (n);
	for (int &t : h) cin >> t;
	LineContainer CHT;
	CHT.add(2*h[n-1],c+1LL*h[n-1]*h[n-1]);

	vector <long long> ans (n);
	for (int i = n-2; i >= 0; i--) {
		ans[i] = CHT.query(-h[i]) + 1LL*h[i]*h[i];
		CHT.add(2*h[i],ans[i]+1LL*h[i]*h[i]+c);
	}
	cout << ans[0] << endl;
}

Measured memory_bytes: 15104
from math import gcd
N,K = map(int,input().split())
MOD = 10**9+7

dp = [1] * (K+1)
for n in range(K//2,0,-1):
    p = pow(K//n,N,MOD)
    for m in range(2*n,K+1,n):
        p -= dp[m]
    dp[n] = p%MOD

ans = 0
for i,n in enumerate(dp):
    ans += i*n
    ans %= MOD
print(ans)

Measured memory_bytes: 11296
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
ll GCD(ll a, ll b) { return b ? GCD(b, a%b) : a; }
int main() {
    int n,k;
    cin>>n>>k;
    vector<ll> h(n);
    for(int i=0; i<n; i++) cin>>h[i];
    priority_queue<ll> p;
    for(int i=0; i<n; i++){
        p.push(h[i]);
    }
    ll ans=0;
    for(int i=0; i<n; i++){
        ans+=h[i];
    }
    for(int i=0; i<k; i++){
        if(p.empty()) break;
        ans-=p.top();
        p.pop();
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 3956
#include <stdio.h>

int main(int argc, char **argv)
{
	int i, s, t, u, r, l;
	l = r = 0;
	
	while(scanf("%d,%d,%d", &s, &t, &u) != EOF){
		if((s*s+t*t) == u*u){
			r++;
		}
		if(s == t){
			l++;
		}
	}
	printf("%d\n%d\n", r, l);
	
	return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define F first
#define S second
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;
const LL INF = 0x3f3f3f3f3f3f3f3fLL;
const LL MOD = 1e9 + 7;
LL solve(int L, int R, auto &dp, auto &arr, auto &preS) {
    if (~dp[L][R]) return dp[L][R];
    if (R - L <= 1) return dp[L][R] = 0;
    dp[L][R] = INF;
    for (int i = L + 1 ; i < R ; i++) {
        LL l = solve(L, i, dp, arr, preS);
        LL r = solve(i, R, dp, arr, preS);
        dp[L][R] = min(dp[L][R], l + r + preS[R] - preS[L]);
    }
    return dp[L][R];
}
void marmot0814() {
    int n; cin >> n;
    vector<LL> arr(n), preS{0};
    for (auto &v : arr)
        cin >> v, preS.push_back(preS.back() + v);
    vector<vector<LL>> dp(n + 1, vector<LL>(n + 1, -1));
    cout << solve(0, n, dp, arr, preS) << '\n';
}
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
    int t = 1, kase = 0; // cin >> t;
    while (t--) {
        // cout << "Case #" << ++kase << ":";
        marmot0814();
    }
}

Measured memory_bytes: 4520
//***The night is the darkest just before the dawn***
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

bool cp(pair<ll,ll> a,pair<ll,ll> b){
	if(a.fi>b.fi) return(0);
	else{
		if(a.se>b.se) return (0);
		return(1);
	}
}

int main()
{
	ll n;
	cin>>n;
	vector<pair<ll,ll>> v;
	
	forn(i,n){
		ll l,r;
		cin>>l>>r;
		v.pb(mp(l-r,l+r-1));
	}
	sort(v.begin(),v.end());

	/*forn(i,n){
		cout<<v[i].fi<<" "<<v[i].se<<endl;
	}*/
	ll x=0,ans=0;
	for(ll i=1;i<n;i++){
		if(v[i].fi<=v[x].se) //Think greedily and try the make the [l...r] right as  small as possible
		{
			ans++;
			if(v[i].se<=v[x].se) x=i;
		}
		else x=i; //Before i there is no contradiction..so the problem reduces to the similar problem starting from i
	}
	cout<<(n-ans);
}

Measured memory_bytes: 3444
#include <cstdio>
long long a,b,k,t;
int main()
{
    scanf("%lld%lld%lld",&k,&a,&b);
    if(a>=k){printf("1");return 0;}
    if(b>=a){printf("-1");return 0;}
    if((k-a)%(a-b)>=1)t=1;
    printf("%lld",((k-a)/(a-b)+t)*2+1);
}


Measured memory_bytes: 128
import java.util.*;

class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);

    String s = sc.next();
    String t = sc.next();

    if (s.length() != (t.length() - 1)) {
      System.out.println("No");
      return;
    }
    for (int i = 0; i < s.length(); i++) {
      if (s.charAt(i) != t.charAt(i)) {
        System.out.println("No");
        return;
      }
    }
    System.out.println("Yes");
  }
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, ll b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

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

    if (a == b)
        cout << c << endl;
    else if (b == c)
        cout << a << endl;
    else
        cout << b << endl;
}


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

whole=0
for i in range(n+1):
    whole+=abs(X[i+1]-X[i])

for i in range(n):
    t=whole
    t-=abs(X[i+1]-X[i])+abs(X[i+2]-X[i+1])
    t+=abs(X[i+2]-X[i])
    print(t)

Measured memory_bytes: 14040
#include <bits/stdc++.h>
#define SORT(x) sort((x).begin(), (x).end())
#define ALL(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < n; i++)
#define reps(i, m, n) for (ll i = m; i < n; i++)
#define repr(i, m, n) for (ll i = m; i >= n; i--)
template <class T> bool maxi(T &a, const T &b) {
    if (a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <class T> bool mini(T &a, const T &b) {
    if (b < a) {
        a = b;
        return 1;
    }
    return 0;
}
#define dame {cout<< "No" <<"\n"; return;}
#define INF2 1000000000000000037
#define INF  1000000007
#define MOD  1000000007
#define PI (acos(-1))
using namespace std;
using ll = long long;
using ld = long double;
using P  = pair<ll,ll>;
//--GLOBAL---------------------------------
vector<ll> ans;
struct edge{ll to;};
struct graph{
    ll N;
    vector<vector<edge> > G;
    vector<bool> used;

    graph(ll n): N(n), G(N), used(N,false) {}

    void add_edge(ll s, ll t){
        G[s].emplace_back((edge){t});
        G[t].emplace_back((edge){s}); //無向ならON
    }

    void dfs(ll v=0){
        used[v]=true;
        ans.emplace_back(v);
        for(auto E : G[v]){
            if(!used[E.to]){
                dfs(E.to);
            }
        }
    }
};
//--MAIN-----------------------------------
void Main() {
    ll N; cin>>N;
    graph g(N);
    rep(i,N-1){
        ll a,b; cin>>a>>b;
        g.add_edge(--a,--b);
    }
    g.dfs();
    vector<ll> c(N);
    rep(i,N) cin>>c[i];
    sort(ALL(c),greater<ll>());
    ll anss=0;
    rep(i,N-1) anss+=c[i+1];
    cout<< anss <<"\n";
    vector<ll> ansss(N);
    rep(i,N) ansss[ans[i]]=c[i];
    rep(i,N) cout<< ansss[i] <<" ";
    cout<<"\n";
}
//--START----------------------------------
int main() {
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    Main();
}
//-----------------------------------------


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

int main() {
  int n, a, b, c;
  cin >> n >> a >> b >> c;
  vector<string> s(n+1);
  vector<string> ans(n);
  for (int i = 0; i < n; i++) cin >> s[i];
  for (int i = 0; i < n; i++) {
    if (s[i] == "AB") {
      if (a == 0 && b == 0) {
        cout << "No" << endl;
        return 0;
      } else if (a == 1 && b == 1) {
        if (s[i+1] == "AC") {
          ans[i] = "A";
          a++;
          b--;
        } else {
          ans[i] = "B";
          a--;
          b++;
        }
      } else if (a < b) {
        ans[i] = "A";
        a++;
        b--;
      } else {
        ans[i] = "B";
        a--;
        b++;
      }
    } else if (s[i] == "AC") {
      if (a == 0 && c == 0) {
        cout << "No" << endl;
        return 0;
      } else if (a == 1 && c == 1) {
        if (s[i+1] == "AB") {
          ans[i] = "A";
          a++;
          c--;
        } else {
          ans[i] = "C";
          a--;
          c++;
        }
      } else if (a < c) {
        ans[i] = "A";
        a++;
        c--;
      } else {
        ans[i] = "C";
        a--;
        c++;
      }
    } else if (s[i] == "BC") {
      if (b == 0 && c == 0) {
        cout << "No" << endl;
        return 0;
      } else if (b == 1 && c == 1) {
        if (s[i+1] == "AB") {
          ans[i] = "B";
          b++;
          c--;
        } else {
          ans[i] = "C";
          b--;
          c++;
        }
      } else if (b < c) {
        ans[i] = "B";
        b++;
        c--;
      } else {
        ans[i] = "C";
        b--;
        c++;
      }
    }
  }
  cout << "Yes" << endl;
  for (string &i : ans) cout << i << endl;
  return 0;
}

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

#define ONLINE_JUDGE
#define pb(a) push_back(a)
#define ALL(a) (a.begin(), a.end())
#define FOR(x,to) for(x=0;x<(to);x++)

using ll = long long;

const int E5 = 1e5;

//////////// Solution /////////////////////////////////

int a[10000];

void solve() {
	int n;
	cin >> n;
	ll cnt = 0;
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
		while (a[i]%2==0) {
			++cnt;
			a[i]/=2;
		}
	}

	cout << cnt << '\n';
}	

/////////// End Solution ///////////////////////////////////////

//////// Initialization ////////////////////////////////////

int main() {

	#ifndef ONLINE_JUDGE
	FILE *FIN = freopen("/home/danil/prog/input.txt", "r", stdin);
	clock_t time_start = clock();
	#endif

	ios::sync_with_stdio(false);
	cin.tie(NULL);

	solve();

	#ifndef ONLINE_JUDGE
	fclose(FIN);
	cerr << "\x1b[031m\n-----------------\nTime=" << (ll)((double)(clock()-time_start) / CLOCKS_PER_SEC * 1000) << "ms\n\x1b[0m";
	#endif

	return 0;
}

//////// End Initialization ///////////////////////////////////////

Measured memory_bytes: 256
n, m = map(int, input().split())
X = list(map(int, input().split()))
if n < m:
    X.sort()
    diff = [X[i]-X[i-1] for i in range(1,len(X))]
    diff.sort()
    p = sum([diff[-i] for i in range(1,n)])
    print(sum(diff) - p)
else:
    print(0)

Measured memory_bytes: 13968
#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()

#define print(s) cout << s;
#define println(s) cout << s << endl;
#define printd(s, f) cout << fixed << setprecision(f) << s << endl;


int main()
{
	int x;
	cin >> x;

	string res = "NO";
	if (x == 3 || x == 5 || x == 7)
	{
		res = "YES";
	}

	println(res);
}

Measured memory_bytes: 256
//

#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
// const int INF = 2147483647;
// const ll INF = 9223372036854775807;
// const ll MOD = 1e9 + 7;

int main(){
	double R;
	cin >> R;

	double ans = M_PI * R * 2.0;

	cout << fixed << setprecision(10);
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 3792
/*  -*- coding: utf-8 -*-
 *
 * c.cc: C - Cell Inversion
 */

#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
#include<iostream>
#include<string>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<list>
#include<queue>
#include<deque>
#include<algorithm>
#include<numeric>
#include<utility>
#include<complex>
#include<functional>

using namespace std;

/* constant */

const int MAX_N = 100000;
const int MAX_N2 = MAX_N * 2;
const int MOD = 1000000007;

/* typedef */

typedef long long ll;

/* global variables */

char s[MAX_N2 + 4];
bool ls[MAX_N2];

/* subroutines */

/* main */

int main() {
  int n;
  scanf("%d%s", &n, s);
  int n2 = n * 2;

  int br = 0;
  bool cp = false;
  for (int i = 0; i < n2; i++) {
    bool bk = (s[i] == 'B');
    if (bk != cp) {
      ls[i] = true;
      br++;
    }
    else {
      ls[i] = false;
      br--;
      if (br < 0) {
	puts("0");
	return 0;
      }
    }
    cp ^= true;
  }
  if (br != 0) {
    puts("0");
    return 0;
  }

  int m = 1;
  for (int i = 0, l = 0, r = 0; i < n2; i++) {
    if (ls[i])
      l++;
    else {
      m = (ll)m * (l - r) % MOD;
      r++;
    }
  }

  for (int i = 2; i <= n; i++)
    m = (ll)m * i % MOD;

  printf("%d\n", m);
  return 0;
}


Measured memory_bytes: 640
import java.io.*;
 
class Main{
    public static void main(String[] args){
        BufferedReader reader = new BufferedReader(new InputStreamReader(System.in));
        try {
                int W, H, x, y, r;
 
                String line = reader.readLine();
                String[] strAry = line.split(" ");
 
                W = Integer.parseInt(strAry[0]);
                H = Integer.parseInt(strAry[1]);
                x = Integer.parseInt(strAry[2]);
                y = Integer.parseInt(strAry[3]);
                r = Integer.parseInt(strAry[4]);
 
                if((x + r) <= W && (y + r) <= H && (x - r) >= 0 && (y - r) >= 0 )
                    System.out.println("Yes");
                else
                    System.out.println("No");
                
 
                 
        } catch (IOException e) {
            System.out.println(e);
        }
    }
}

Measured memory_bytes: 24332
N = int(input())
count_max = 0
count_i = 0

for i in range(1,N+1):
  count = 0
  ii = i
  for j in range(i):
    if i%2 == 0:
      i = int(i/2)
      count += 1
    else:
      break
  if count > count_max:
    count_max = count
    count_i = ii
  elif i == 1:
    count_i = 1
print(count_i)

Measured memory_bytes: 9200
#include <bits/stdc++.h>
#define bear ryan
#define fi first
#define se second
#define all(v) v.begin(), v.end()
#define pb push_back
#define eb emplace_back
#define endl '\n'
#define ends ' '
#define fastio ios_base::sync_with_stdio(0), cin.tie(0)
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

const ll inf = 1e9;

ll n;

int main(void) {
    fastio;
    cin >> n;
    ll ans = 0;
    for(int i = 1; i <= n; ++i) if(i % 3 != 0 && i % 5 != 0) ans += i;
    cout << ans;
    return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <bitset>
using namespace std;

#ifdef LOCAL
	#define eprintf(...) fprintf(stderr, __VA_ARGS__);fflush(stderr);
#else
	#define eprintf(...) 42
#endif

using ll = long long;
using ld = long double;
using uint = unsigned int;
using ull = unsigned long long;
template<typename T>
using pair2 = pair<T, T>;
using pii = pair<int, int>;
using pli = pair<ll, int>;
using pll = pair<ll, ll>;
mt19937_64 rng(chrono::steady_clock::now().time_since_epoch().count());
ll myRand(ll B) {
	return (ull)rng() % B;
}

#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second

clock_t startTime;
double getCurrentTime() {
	return (double)(clock() - startTime) / CLOCKS_PER_SEC;
}

int main()
{
	startTime = clock();
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);

	int h1, m1, h2, m2, t;
	cin >> h1 >> m1 >> h2 >> m2 >> t;
	cout << max(0, (h2 - h1) * 60 + (m2 - m1) - t) << endl;

	return 0;
}


Measured memory_bytes: 3196
#include <iostream>
#include <vector>
using namespace std;
const long long Mod = 998244353;
long long powerr(int k,int n,long long MOD){
    long long a = k;
    long long x = 1;
    while(n>0){
        if(n%2==1)x*=a;
        x%=MOD;
        a=a*a;
        a%=MOD;
        n/=2;
    }
    return x;
}
int main(){
    int n;
    cin >> n;
    int a[n];
    int suma = 0;
    for(int i = 0;i<n;i++){
        cin >> a[i];
        suma+=a[i];
    }
    vector<vector<long long>> dp;
    vector<vector<long long>> dp2;
    vector<long long> tmp;
    for(int i = 0;i<suma+500;i++) tmp.push_back(0);
    for(int i = 0;i<n+1;i++) dp.push_back(tmp);
    for(int i = 0;i<n+1;i++) dp2.push_back(tmp);
    dp[0][0] = 1;
    dp2[0][0] = 1;
    for(int i = 1;i<=n;i++){
        for(int j = 0;j<=suma;j++){
            dp[i][j+a[i-1]] += dp[i-1][j];
            dp[i][j] += 2*dp[i-1][j];
            dp[i][j+a[i-1]]%=Mod;
            dp[i][j]%=Mod;
            dp2[i][j+a[i-1]] += dp2[i-1][j];
            dp2[i][j] += dp2[i-1][j];
            dp2[i][j+a[i-1]]%=Mod;
            dp2[i][j]%=Mod;
        }
    }
    long long cnt = 0;
    for(int i = (suma+1)/2;i<=suma;i++){
        cnt+=dp[n][i];
        cnt%=Mod;
    }
    long long ans;
    if(suma%2==1){
        ans = powerr(3,n,Mod) - 3*cnt;
        ans%=Mod;
        if(ans<0) ans+=Mod;
        cout << ans << endl;
    }
    else{
        ans = powerr(3,n,Mod) - 3*cnt + 3*dp2[n][suma/2];
        ans%=Mod;
        if(ans<0) ans+=Mod;
        cout << ans << endl;
    }
}

Measured memory_bytes: 427252
#include <cstdio>
#include <cstring>
#include <iostream>
#include <string>
#include <cmath>
#include <bitset>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>
#include <complex>
#include <unordered_map>
#include <random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
vector<int> v;
int m;
void solve(int i){
	if(i==10) return;
	m*=10;
	m+=3;
	v.push_back(m);
	solve(i+1);
	m+=2;
	v.push_back(m);
	solve(i+1);
	m+=2;
	v.push_back(m);
	solve(i+1);
  m/=10;
}

int main()
{
	solve(1);
	sort(v.begin(), v.end());
	int n; cin>>n;
	int ans=0;
	for(int i=0; i<v.size(); i++){
		if(v[i]>n) break;
		int c[10]={};
		int n0=v[i];
		while(n0>0){
			c[n0%10]++;
			n0/=10;
		}
		if(c[3] && c[5] && c[7]) ans++;
	}
	cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 512
use proconio::input;

fn main() {
    input! {
        n: usize,
        mut k: i64,
        mut ab: [(i64, i64); n],
    };
    ab.sort();
    for &(a_i, b_i) in ab.iter() {
        k -= b_i;
        if k <= 0 {
            println!("{}", a_i);
            return;
        }
    }
}


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

#define FOR(i,s,t) for(int i = s ; i < t ; i ++)
#define SZ(a) (int)a.size()
using LL = long long;

//BEGIN CUT HERE
struct Dice {
	int s[6];
	void roll(char c) {
		//the view from above
		// N
		//W E
		// S
		//s[0]:top
		//s[1]:south
		//s[2]:east
		//s[3]:west
		//s[4]:north
		//s[5]:bottom
		int b;
		if (c == 'E') {
			b = s[0];
			s[0] = s[3];
			s[3] = s[5];
			s[5] = s[2];
			s[2] = b;
		}
		if (c == 'W') {
			b = s[0];
			s[0] = s[2];
			s[2] = s[5];
			s[5] = s[3];
			s[3] = b;
		}
		if (c == 'N') {
			b = s[0];
			s[0] = s[1];
			s[1] = s[5];
			s[5] = s[4];
			s[4] = b;
		}
		if (c == 'S') {
			b = s[0];
			s[0] = s[4];
			s[4] = s[5];
			s[5] = s[1];
			s[1] = b;
		}

		// migi neji 
		if (c == 'R') {
			b = s[1];
			s[1] = s[2];
			s[2] = s[4];
			s[4] = s[3];
			s[3] = b;
		}

		if (c == 'L') {
			b = s[1];
			s[1] = s[3];
			s[3] = s[4];
			s[4] = s[2];
			s[2] = b;
		}

	}
	int top() {
		return s[0];
	}
	int hash() {
		int res = 0;
		for (int i = 0; i<6; i++) res = res * 256 + s[i];
		return res;
	}
};
vector<Dice> makeDices(Dice d) {
	vector<Dice> res;
	for (int i = 0; i<6; i++) {
		Dice t(d);
		if (i == 1) t.roll('N');
		if (i == 2) t.roll('S');
		if (i == 3) t.roll('S'), t.roll('S');
		if (i == 4) t.roll('L');
		if (i == 5) t.roll('R');
		for (int k = 0; k<4; k++) {
			res.push_back(t);
			t.roll('E');
		}
	}
	return res;
}
//END CUT HERE

void solve_AOJ_ITP1_11_A() {
	int N = 6;
	Dice D;
	FOR(i, 0, N) {
		int val; cin >> val;
		D.s[i] = val;
	}
	string s; cin >> s;
	FOR(i, 0, SZ(s)) {
		D.roll(s[i]);
	}
	cout << D.top() << endl;
}

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

	return 0;
}




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

using namespace std;
typedef long long  ll;
typedef long double ld;
typedef pair<ll,ll> pp;
typedef tree<ll,null_type,less<ll>,rb_tree_tag,tree_order_statistics_node_update> super_set;
typedef tree<ll,null_type,less_equal<ll>,rb_tree_tag,tree_order_statistics_node_update> multi_set;
#define x1 dfds
#define y1 dsfdsfe
#define pb push_back
#define forn(i,n) for(ll i = 1;i<=n;++i)
#define fi first
#define sc second
#define endl '\n'
#define po(x) (1ll<<x)
const ll DIM = 2E5+7;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    ll n;
    cin>>n;
    ll res = 0;
    res+=(n/500)*1000;
    n%=500;
    res+=(n/5)*5;
    cout<<res<<endl;
    return 0;
}



Measured memory_bytes: 256
#include<stdio.h>
 
#define MAX 200000
#define SENTINEL 1000000001
 
long long gA[MAX+1],gn,gcnt;
long long gL[ (MAX/2)+1 ],gR[ (MAX/2)+1 ];
  
void merge( long long left, long long mid, long long right )
{
    long long i,j,k;
    long long n1=mid-left;
    long long n2=right-mid;
  
    for( i=0; i<n1; i++ ) {
        gL[i]=gA[ left+i ];
    }
    for( i=0; i<n2; i++ ) {
        gR[i]=gA[ mid+i ];
    }
      
    gL[n1]=gR[n2]=SENTINEL;
    i=j=0;
    for( k=left; k<right; k++ ) {
        if( gL[i] <= gR[j] ) {
            gA[k]=gL[i++];
        } else {
            gcnt+=(n1-i);
            gA[k]=gR[j++];
        }
    }
    return;
}
  
void mergeSort( long long left, long long right )
{   
    long long mid;
    if( left+1 < right ) {
        mid=(left+right)/2;
        mergeSort( left, mid );
        mergeSort( mid, right );
        merge( left, mid, right );
    }
      
    return;
}
 
int main( void ) 
{   
    long long i;
     
    scanf( "%lld", &gn );
 
    for( i=0; i<gn; i++ ) {
        scanf( "%lld", &gA[i] );
    }
    gcnt=0;
    mergeSort( 0, gn );
    printf( "%lld\n",  gcnt );
 
    return 0;
}

Measured memory_bytes: 3720
#include <iostream>
#include <vector>
#include <queue>
#include <stack>
#include <utility>
#include <cmath>
#include <cfloat>
using namespace std;

typedef pair<double, int> di;

struct Node {
    int x, y;
    int from;
    double c;
    bool d;
    vector<di> tos;
};

int n;
vector<Node> ns;

bool dijkstra(int s, int t) {
    for (int i = 1; i <= n; i++) {
        ns[i].from = -1;
        ns[i].c = DBL_MAX;
        ns[i].d = false;
    }
    ns[s].c = 0.0;
    priority_queue<di, vector<di>, greater<di> > q;
    q.push(make_pair(0, s));
    while (!q.empty()) {
        di p = q.top();
        q.pop();
        int i = p.second;
        if (ns[i].d) {
            continue;
        }
        ns[i].d = true;
        if (i == t) {
            return true;
        }
        for (vector<di>::iterator it = ns[i].tos.begin(); it != ns[i].tos.end(); it++) {
            double cost = ns[i].c + it->first;
            int to = it->second;
            if (!ns[to].d && cost < ns[to].c) {
                ns[to].from = i;
                ns[to].c = cost;
                q.push(make_pair(cost, to));
            }
        }
    }
    return false;
}

int dist2(int x1, int y1, int x2, int y2) {
    return (x1-x2)*(x1-x2) + (y1-y2)*(y1-y2);
}

int main() {
    while (cin >> n, n) {
        ns.clear();
        ns.resize(n+1);
        for (int i = 1; i <= n; i++) {
            int b;
            cin >> b;
            cin >> ns[b].x >> ns[b].y;
        }
        for (int i = 1; i <= n - 1; i++) {
            for (int j = i + 1; j <= n; j++) {
                int d2 = dist2(ns[i].x, ns[i].y, ns[j].x, ns[j].y);
                if (d2 <= 2500) {
                    double d = sqrt(d2);
                    ns[i].tos.push_back(make_pair(d, j));
                    ns[j].tos.push_back(make_pair(d, i));
                }
            }
        }
        int m;
        cin >> m;
        for (int i = 0; i < m; i++) {
            int s, t;
            cin >> s >> t;
            if (dijkstra(s, t)) {
                stack<int> ans;
                while (t != s) {
                    ans.push(t);
                    t = ns[t].from;
                }
                cout << s;
                while (!ans.empty()) {
                    cout << " " << ans.top();
                    ans.pop();
                }
                cout << endl;
            } else {
                cout << "NA" << endl;
            }
        }
    }
}

Measured memory_bytes: 1216
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <iomanip>
#include <math.h>
#include <complex>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <unordered_map>
#include <set>
#include <bitset>
#include <functional>
#include <assert.h>
using ll=long long;
#define int ll
#define rng(i,a,b) for(int i=int(a);i<int(b);i++)
#define rep(i,b) rng(i,0,b)
#define gnr(i,a,b) for(int i=int(b)-1;i>=int(a);i--)
#define per(i,b) gnr(i,0,b)
#define eb emplace_back
#define all(x) x.begin(),x.end()
#define SZ(x) x.size()
#define fi first
#define se second
const int INF = 1e9;
using namespace std;

template<class T> using vc=vector<T>;
template<class T> using vvc=vc<vc<T>>;

using pi=pair<int,int>;
using vi=vc<int>;

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

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

    while(true){
        int N,M,P; cin >> N >> M >> P;
        if(N==0 && M==0 && P==0) break;
        int A[N];
        int sum=0;
        rep(i,N) {
            cin >> A[i];
            sum+=A[i];
        }
        if(A[M-1]==0) cout << 0 << "\n";
        else cout << (sum*(100-P))/A[M-1] << endl;
    }
}


Measured memory_bytes: 3108
#include<stdio.h>
 int main(){
   int m,n,k,num;
   int sum=0;
   scanf("%d %d",&m,&n);
   for(k=0;k<n;k++){
     scanf("%d",&num);
     sum+=num;
   }
   if(sum>=m){
     printf("Yes\n");
   }
   else{
     printf("No\n");
   }
   return 0;
 }

Measured memory_bytes: 256