akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
 
#define all(x) x.begin(), x.end()
#define allr(x) x.rbegin(), x.rend()
#define speedhack() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define form(i, n) for (size_t i = 0; i < size_t(n); ++i)
#define forn(i, n) for (size_t i = 1; i <= size_t(n); ++i)
template<class T> using ordered_set=tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
long long mod(long long a, long long b) { return (a%b+b)%b; }
long long gcd(long long x, long long y) { return __gcd(x, y); }
long long lcm(long long x, long long y) { return x * 1ll * y / gcd(x, y); }
 
 
const long long MAXN = 1e9 + 9;
const long long SIZE = 3e5 + 5;
const long long MOD = 1e9 + 7;


long long N, K, T, res = -(long long)(2e18), P[5050], C[5050];
vector<long long> cycles[5050];
bool used[5050];

void dfs (int v) {
	used[v] = true;
	cycles[T].push_back(C[v]);
	if (!used[P[v]]) 
		dfs (P[v]);
}


long long calc (int I, int k) {

	long long cur = 0, mx = 0;
	for (int i = 0; i < k; i++) 
		cur += cycles[I][i];
	mx = cur;
	for (int i = k, j = 0; i < (int)cycles[I].size(); i++) {
		cur -= cycles[I][j++];
		cur += cycles[I][i];
		mx = max (mx, cur);
	}
	return mx;

}



int main() { speedhack()

	cin >> N >> K;

	forn (i, N) cin >> P[i];
	forn (i, N) cin >> C[i];


	forn (i, N) {
		if (!used[P[i]]) {
			++T;
			dfs (P[i]);
		}
	}

	forn (i, T) {

		long long sum = 0, rem = -2e18, mx = -2e18;
		int len = cycles[i].size();
		long long t = K / len;
		long long r = K - (t * len);
		

		for (int j = 0; j < len; j++) {
			sum += cycles[i][j];
			cycles[i].push_back(cycles[i][j]);
		}

		for (int j = 1; j <= min ((int)K, len); j++) {
			long long cur = calc(i, j);
			res = max(res, cur);
			mx = max(mx, cur);
			if (j <= r) 
				rem = max(rem, cur);
		}

		if (r == 0) 
			res = max(res, sum * (t - 1) + mx);
		else 
			res = max(res, rem + sum * t);
	}

	cout << res << endl;

	
	return 0;
}


Measured memory_bytes: 3992
import itertools
n = int(input())
d = {x: 0 for x in ["M","A","R","C","H"]}
s = []
for _ in range(n):
    st = input()
    if st[0] in d.keys():
        d[st[0]] += 1

nonzero = sum([1 for x in d.values() if x > 0])
if nonzero == 5:
    cases = 10
elif nonzero == 4:
    cases = 4
elif nonzero == 3:
    cases = 1
else:
    cases = 0

if cases == 0:
    print(0)
elif cases == 1:
    ans = cases
    for x in d.values():
        if x == 0 or x == 1:
            pass
        else:
            ans *= x
    print(ans)
elif cases > 3:
    ans = 0
    for i in ["M","A","R","C","H"]:
        if d[i] == 0:
            del d[i]
    for v in itertools.combinations(d.values(),3):
        tmp = 1
        for x in v:
            tmp *= x
        ans += tmp
    print(ans)


Measured memory_bytes: 3064
import sys
sys.setrecursionlimit(100000000)
input = sys.stdin.readline
MOD = 10 ** 9 + 7
INF = 10 ** 15
from itertools import accumulate

def equal_l(cumsum,i):
    f = lambda j:abs(cumsum[i + 1] - 2*cumsum[j])
    l = 1
    r = i + 1
    while r - l > 1:
        mid = (l + r)//2
        if f(mid) - f(mid - 1) >= 0:
            r = mid
        else:
            l = mid
    #print('equeal_l:{0},{1}'.format(l,r))
    return cumsum[i + 1] - cumsum[l],cumsum[l]

def equal_r(cumsum,i,N):
    f = lambda j:abs(cumsum[-1] - cumsum[i + 1] - 2*(cumsum[j] - cumsum[i + 1]))
    l = i + 2
    r = N
    while r - l > 1:
        mid = (l + r)//2
        if f(mid) -  f(mid - 1) >= 0:
            r = mid
        else:
            l = mid
    #print('equeal_r:{0},{1}'.format(l,r))
    return  cumsum[-1] - cumsum[l],cumsum[l] - cumsum[i + 1]

def main():
    N = int(input())
    A = list(map(int,input().split()))
    cumsum = list(accumulate([0] + A))
    ans = INF
    for i in range(1,N - 2):
        a,b = equal_l(cumsum,i)
        c,d = equal_r(cumsum,i,N)
        ret = max(a,b,c,d) - min(a,b,c,d)
        ans = min(ans,ret)
    print(ans)
    
if __name__ == '__main__':
    main()
    


Measured memory_bytes: 95196
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int n,m;
  cin>>n>>m;
  if(n>=1 && n<=9 && m>=1 && m<=9)
  {
    cout<<n*m<<endl;
  }
  else
  {
    cout<<-1<<endl;
  }
  
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N, O, S = 0, W = 10000000;
  cin >> N;
  O = N;
  for (int i = 0; i < 8; i++) {
    S += N / W;
    N %= W;
    W /= 10;
    if (W == 0) W = 1;
  }
  if (O % S == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<complex>
#include<cstdlib>
#include<algorithm>
#include<functional>
using namespace std;
int main() {
    int a,b,c,k,max;
    cin>>a>>b>>c>>k;
    if(a<b)swap(a,b);
    if(a<c)swap(a,c);
    if(b<c)swap(b,c);
    a=pow(2,k)*a;
    cout<<a+b+c<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
int main(){
  int N;
  scanf("%d",&N);
  
  int a[N];
  for(int i=0;i<N;i++){
    scanf("%d",&a[i]);
  }
  
  int j=0;
  int evencnt=0;
  int cnt=0;
  while(j<N){
    if(a[j] % 2 == 0){
      evencnt++;
      if((a[j] % 3 == 0) || (a[j] % 5 == 0)){
        cnt++;
      }
    }
    j++;
  }
 
  if(evencnt++ == cnt) printf("APPROVED");
  else printf("DENIED");
}
 

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

const int N = 1e5 + 100;

int n, m, u, v, cnt[N];

int main() {
	ios::sync_with_stdio(false), cin.tie(0);
	cin >> n >> m;
	while(m--) {
		cin >> u >> v;
		cnt[--u]++;
		cnt[--v]++;
	}
	for (int i = 0; i < n; i++)
		if(cnt[i] & 1) {
			cout << "NO";
			return 0;
		}
	cout << "YES";
	return 0;
}

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

#define int long long
#define ct(n) cout << n << endl;
#define cts(n) cout << n << " ";
#define cte cout << endl;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define repo(i,o,n) for(int i=o;i<n;i++)
#define repm(i,n) for(int i=n-1;i>=0;i--)
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define sperase(v,n) (v).erase(remove(all(v), n), (v).end());
#define vdelete(v) (v).erase(unique(all(v)), (v).end());
#define vcopy(v1,v2) copy((v1).begin(), (v1).end(), back_inserter((v2)));
#define pb(n) push_back(n);

int a,b,c;
char abc;

main() {
    rep(i,3) {
        cin >> abc;
        if (abc == 'a') a++;
        else if (abc == 'b') b++;
        else c++;
    }
    if (a && b && c) ct("Yes")
    else ct("No")
}






Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
#define REP(i,N) for(int i = 0; i < (int)N; i++)

int main(){
	int n;
	while(cin >> n){
		if(n==0)break;
		map<char,char> mp;
		REP(i,n){
			char from,to;
			cin >> from >> to;
			mp[from] = to;
		}
		int n;
		cin >> n;
		REP(i,n){
			char c;
			cin >> c;
			if(mp[c] == 0){
				cout << c;
			}else{
				cout << mp[c];
			}
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 3020
#include <bits/stdc++.h>
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define f first
#define s second

using namespace std;

typedef long long ll;

const int INF = 1e9 + 7;

ostream& operator << (ostream &os, vector <int> &v) {
    for (int i : v)
        os << i << " ";
    os << "\n";
    return os;
}

main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);
    int n;
    cin >> n;
    vector <int> h(n), dp(n + 1, INF);
    for (int& i : h)
        cin >> i;
    dp[0] = 0;
    for (int i = 0; i < n; ++i) {
        dp[i + 1] = min(dp[i] + abs(h[i] - h[i + 1]), dp[i + 1]);
        dp[i + 2] = min(dp[i] + abs(h[i] - h[i + 2]), dp[i + 2]);
    }
    cout << dp[n - 1] << "\n";
    return 0;
}


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

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

#define overload3(_1, _2, _3, name, ...) name
#define rep1(i, n) for(i64 i = 0LL; i < (n); ++i)
#define rep2(i, a, b) for(i64 i = (a); i < (b); ++i)
#define rep(...) overload3(__VA_ARGS__, rep2, rep1)(__VA_ARGS__)
#define all(v) v.begin(), v.end()

void solve(long long x) {
    if(x == 0)
        cout << 1 << endl;
    else
        cout << 0 << endl;
}

struct IoSetup {
    IoSetup() {
        // cin.tie(nullptr);
        // ios::sync_with_stdio(false);
        cout << fixed << setprecision(10);
        cerr << fixed << setprecision(10);
    }
} iosetup;

int main() {
    long long x;
    scanf("%lld", &x);
    solve(x);
    return 0;
}


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

int main(){
	int n=0, m=1;
	int a[101], b[101], x=0, y=0;
	int p,q;
	
	while(1){
	
	cin >> n >> m;
	x=0;
	y=0;
	p=-1;
	q=-1;
	
	
	if(0== n + m) break;
	
	for(int i=0;i<n;i++){
		cin >> a[i];
		x+=a[i];
	}
	for(int j=0;j<m;j++){
		cin >> b[j];
		y+=b[j];
	}
	
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			if((a[i]-b[j])*2==(x-y)){
				if(p==-1){
					p = a[i];
					q = b[j];
				}else if(p+q>a[i]+b[j]){
					p = a[i];
					q = b[j];
				}
			}
		}
	}
	
	if(p==-1) cout << p << endl;
	else cout << p << " " << q << endl;
	}
	
	return 0;
}

Measured memory_bytes: 1160
#include<bits/stdc++.h>
#define ll long long
#define mp make_pair
#define pii pair<int,int>
#define pb push_back
#define r1 rt<<1
#define r2 rt<<1|1
#define fi first
#define se second
#define ri register int
#define rep(i,a,b) for(ri i=(a);i<=(b);++i)
#define rep2(i,a,b,c) for(ri i=(a);i<=(b);i+=(c))
#define REP(i,a,b) for(ri i=(a);i>=(b);--i)
#define REP2(i,a,b,c) for(ri i=(a);i>=(b);i-=(c))
using namespace std;

inline ll read(){
	ll x=0,f=1;char c=getchar();
	while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
	while(c>='0'&&c<='9') x=(x<<1)+(x<<3)+(c^'0'),c=getchar();
	return x*f;
}
inline void write(ll x){
	if(x<0) putchar('-'),x=-x;
	if(x>9) write(x/10);
	putchar(x%10+'0');
}

int main()
{
	ri n=read();
	rep(i,1,50000){
		ri x=floor((double)i*1.08);
		if(x==n){
			cout<<i;return 0;
		}
	}cout<<":(";
	return 0; 
}

Measured memory_bytes: 256
N = int(input())

a = []
temp = N
for i in range(2, int(-(-N**0.5//1))+1):
    if temp%i==0:
        cnt=0
        while temp%i==0:
            cnt+=1
            temp //= i
        a.append([i, cnt])

if temp!=1:
    a.append([temp, 1])

ans = 0
for i in range(len(a)):
    e = 1
    while 1:
        if N % a[i][0]**e == 0:
            N /= a[i][0]**e
            a[i][1] -= e
            e+=1
            ans += 1
        else:
            break
        if a[i][1] < e:
            break

print(ans)

Measured memory_bytes: 9488
N = int(input())
high = list(map(int, input().split()))
dai = []
est = high[0]
for i in range(N):
  if est > high[i]:
    
    
    dai.append(est-high[i])
  elif est <= high[i]:
    est = high[i]
print(sum(dai))
    
               

Measured memory_bytes: 32368
n = int(input())
v = []
c = []
tmp = input().split()
for i in range(n):
    v.append(int(tmp[i]))
tmp = input().split()
for i in range(n):
    c.append(int(tmp[i]))

ans = 0
for i in range(n):
    if v[i] > c[i]:
       ans += v[i] - c[i] 

print(ans)


Measured memory_bytes: 3060
from sys import stdin, stdout, setrecursionlimit
from collections import deque, defaultdict, Counter
import math

rl = lambda: stdin.readline()
rll = lambda: stdin.readline().split()
rli = lambda: map(int, stdin.readline().split())
rlf = lambda: map(float, stdin.readline().split())

INF, NINF = float('inf'), float('-inf')

def main():
	S, T = rll()[0], rll()[0]
	ans = 0
	for a, b in zip(S, T):
		if a != b: ans += 1
	print(ans)
	stdout.close()

if __name__ == "__main__":
	main()

Measured memory_bytes: 68748
#include    <iostream>
#include    <map>

using namespace std;

int main() {
    int n;
    const char mark[4] = {'S', 'H', 'C', 'D'};
    map<pair<char,int>, int> playingCard;

    cin >> n;
    for(int i = 0; i < n; i++) {
        char c;
        int x;
        
        cin >> c >> x;
        playingCard[make_pair(c,x)]++;
    }
    for(int i = 0; i < 4; i++) {
        for(int j = 1; j <= 13; j++) {
            if(playingCard[make_pair(mark[i], j)] == 0) cout << mark[i] << ' ' << j << endl;
        }
    }

    return 0;
}


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

using namespace std;
using ll = long long;

int main() {
	int n, d, a;
	scanf("%d %d %d", &n, &d, &a);

	vector<pair<int, int>> vec(n);
	for(auto &p : vec) scanf("%d %d", &p.first, &p.second);

	sort(vec.begin(), vec.end());

	d = 2 * d;

	queue<pair<int, int>> q;
	ll ans = 0;
	ll sum = 0;
	for(int i = 0; i < n; i++) {
		while(!q.empty() and vec[i].first - q.front().first > d) {
			sum -= q.front().second;
			q.pop();
		}
		ll now = vec[i].second - a * sum;
		if(now <= 0) continue;
		int cnt = int((now + a - 1) / a);
		ans += cnt;
		q.emplace(vec[i].first, cnt);
		sum += cnt;
	}
	printf("%lld\n", ans);
}


Measured memory_bytes: 5548
import sys
from collections import Counter
from typing import Iterator

def traial_division(n: int) -> Iterator[int]:
    while not n % 2:
        yield 2
        n //= 2
    v = 3
    while v * v <= n:
        if not n % v:
            yield v
            n //= v
        else:
            v += 2
    if n != 1:
        yield n

n = int(sys.stdin.read())
c = Counter(traial_division(n))
# print(c)
ans = 0
for i, k in c.items():
    j = 1
    while k >= j:
        k -= j
        ans += 1
        j += 1
print(ans)

Measured memory_bytes: 10164
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>

using namespace std;

//Nayeem Shahriar Joy ,Applied Physics And Electronic Engineering , University of Rajshahi.

int main(){

	int a, b, sum;

	while ( cin >> a >> b ) {
		sum=a+b;
		int ans = 0;
		while( sum > 0  )
        {
            sum=sum/10;
            ans++;
        }
		cout << ans << endl;
	}
	return 0;
}

Measured memory_bytes: 3068
#[allow(unused_imports)]
use std::char::*;
#[allow(unused_imports)]
use std::cmp::*;
use std::io::*;
use std::str::FromStr;
#[allow(unused_imports)]
use std::collections::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

#[derive(PartialEq, PartialOrd)]
pub struct Total<T>(pub T);

impl<T: PartialEq> Eq for Total<T> {}

impl<T: PartialOrd> Ord for Total<T> {
    fn cmp(&self, other: &Total<T>) -> std::cmp::Ordering {
        self.0.partial_cmp(&other.0).unwrap()
    }
}

//const MAX:usize = 100006;
//const INF:u64 = u64::max_value();

fn main() {
    let n:usize = read();
    let t:f64 = read();
    let a:f64 = read();
    let mut h:Vec<f64> = (0..n).map(|_| read()).collect();

    let mut ans:i32 = -1;
    let mut mn:f64 = 2000000000.0;
    for (i,el) in h.iter_mut().enumerate() {
        *el = t - *el * 0.006;
        //debug!(el);
        if mn > (a - *el).abs() {
            mn = (a - *el).abs();
            ans = i as i32 + 1;
        }
    }

    println!("{}", ans);

}


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

const int mod = 1e9+7;

vector<string> split(string s){
  vector<string> res;
  string tmp;
  rep(i,s.size()){
    if(isalpha(s[i]))tmp += s[i];
    else if(s[i] == ' '){
      if(isupper(tmp[0])){
	sort(all(tmp));
	tmp.erase(unique(all(tmp)),tmp.end());
      }
      res.push_back(tmp);
      tmp = "";
    }
  }
  res.push_back(tmp);
  return res;
}

int n;
int a,t,g,c,m;
map<string,int> id;
vector<string> rule[55];

void parse(int cur, vector<string> &seq){
  for(string s : rule[cur]){
    if((int)seq.size()>n)return;
    if(isupper(s[0]))seq.push_back(s);
    else parse(id[s],seq);
  }
}

int dp[2][55][55][55];

int main(){
  cin >> a >> t >> g >> c >> m; cin.ignore();
  n = a+t+g+c;

  rep(i,m){
    string s;
    getline(cin,s);

    vector<string> vs = split(s);
    id[vs[0]] = i;
    rep(j,vs.size()-1)rule[i].push_back(vs[j+1]);
  }
  /*
  rep(i,m){
    rep(j,rule[i].size())cout << rule[i][j] << " ";
    cout << endl;
  }
  */

  vector<string> seq;
  parse(0,seq);
  if((int)seq.size()!=n){
    cout << 0 << endl;
    return 0;
  }

  dp[0][0][0][0] = 1;
  rep(i,n){
    int cur = i&1, nxt = 1-cur;
    rep(A,a+1)rep(T,t+1)rep(G,g+1)dp[nxt][A][T][G] = 0;

    rep(A,a+1)rep(T,t+1)rep(G,g+1){
      rep(j,seq[i].size()){
	if(seq[i][j] == 'A' && A+1<=a){
	  (dp[nxt][A+1][T][G] += dp[cur][A][T][G]) %= mod;
	}
	if(seq[i][j] == 'T' && T+1<=t){
	  (dp[nxt][A][T+1][G] += dp[cur][A][T][G]) %= mod;
	}
	if(seq[i][j] == 'G' && G+1<=g){
	  (dp[nxt][A][T][G+1] += dp[cur][A][T][G]) %= mod;
	}
	if(seq[i][j] == 'C' && i-A-T-G<=c){
	  (dp[nxt][A][T][G] += dp[cur][A][T][G]) %= mod;
	}
      }
    }
  }
  cout << dp[n&1][a][t][g] << endl; 
}

Measured memory_bytes: 2484
#include<bits/stdc++.h>
using namespace std;
int main()
{
	char s[101];
	int n=1;
	while(cin>>s[n])
	{
		if(s[n]=='F')
		{
			for(int i=1;i<=n;i++)
			{
				if(s[i]=='C')
				{
					cout<<"Yes";
					return 0;
				}
			}
		}
		n++;
	}
	cout<<"No";
	return 0;
}

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

int main(){
  int N; cin >> N;
  long long sum[200001];
  sum[0]=0;
  long long a;
  for(int i=1; i<=N; i++){
    cin >> a;
    sum[i]=a+sum[i-1];
  }
  sort(sum,sum+N+1);
  //同じ数字の連続列m個→mC2個の区間で和が0になる
  long long result=0;
  long long now=sum[0];
  long long seq=1;
  for(int i=1; i<=N; i++){
    if(now==sum[i]){
      seq++;
    }else{
      result+=(seq*(seq-1)/2);
      now=sum[i];
      seq=1;
    }
  }
  cout << result+(seq*(seq-1)/2) << endl;
}

Measured memory_bytes: 1792
#include <stdio.h>
#include <string.h>

int main(){
  char s1[101], s2[101];
  int taro=0,hana=0;
  int i,n;
  
  scanf("%d",&n);
 // printf("");
  for(i=0;i<n;i++)
  {
  	scanf("%s %s", s1, s2);
	  if ( strcmp(s1, s2) == 0 ) {
 	 //	printf("s1 == s2\n");
	  	taro+=1;
	  	hana+=1;
	  }
	  else if ( strcmp(s1, s2) > 0 ) {
  	//	printf("s1 > s2\n");
  		taro+=3;
 	  }
 	  else if ( strcmp(s1, s2) < 0 ) {
  	//	printf("s1 < s2\n");
  		hana+=3;
	 }
  }
	  printf("%d %d\n",taro,hana);
  return 0;
}



Measured memory_bytes: 2724
#include <bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)n; i++)
#define rfor(i, a, b) for(int i = a; i < (int)b; i++)
#define all(ary) (ary).begin(), (ary).end()
#define debug(x) cerr << #x << ": " << x << '\n'
const long long INF = 1LL << 60;
const int MOD = 1000000007;
using namespace std;
using vec = vector<int>;
using ll = long long;
template <class T = int> T in(){ T x; cin >> x; return (x);}
const int dy[4] = {-1, 0, 0, 1};
const int dx[4] = {0, -1, 1, 0};

ll dp[100010];
ll 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;
}

int main(int argc, char *argv[]){
    cin >> N;
    vector<ll> H(N);
    rep(i, N) cin >> H[i];
    rep(i, 100010) dp[i] = INF;
    dp[0] = 0;
    dp[1] = dp[0] + abs(H[1] - H[0]);
    rfor(i, 2, N){
        chmin(dp[i], dp[i - 1] + abs(H[i] - H[i - 1]));
        chmin(dp[i], dp[i - 2] + abs(H[i] - H[i - 2]));
    }
    cout << dp[N - 1] << endl;
    return 0;
}

Measured memory_bytes: 1792
import java.util.Scanner;

/**
 * Created by nakatsukatakahiro on 2017/06/22.
 */
class Main {
    public static void main(String[] args) {
        Scanner scanner = new Scanner(System.in);

        int H = scanner.nextInt();
        int W = scanner.nextInt();

        for (int i = 0; i < W + 2; i++) {
            System.out.print("#");
        }
        System.out.println();

        for (int i = 0; i < H; i++) {
            String str = scanner.next();
            System.out.print("#");
            for (int j = 0; j < W; j++) {
                System.out.print(str.substring(j, j + 1));
            }
            System.out.println("#");
        }

        for (int i = 0; i < W + 2; i++) {
            System.out.print("#");
        }
        System.out.println();
    }
}


Measured memory_bytes: 23380
#ifdef _CONSOLE
#include "bits/stdc++.h"
#else
#include <bits/stdc++.h>
#endif
using namespace std;

typedef long long ll;

#define rep(i,a,b) for(int i = a; i < b; ++i)
#define mp make_pair
#define pb push_back
#define fi first
#define se second
#define mod 1000000007

int n, t, now = -1;
int a[200001];
int ans;
int main() {
    ios_base::sync_with_stdio(false); cin.tie(0);
#ifdef _CONSOLE
     freopen("sample.txt", "r", stdin);
     freopen("output.txt", "w", stdout);
#endif
    // your code goes here
    cin >> n >> t;
    rep(i, 0, n) {
        cin >> a[i];
    }
    ans += t;
    now = t;
    rep(i, 1, n) {
        if (now >= a[i]) { // 0 3
            ans += a[i] - a[i-1];
            now = a[i] + t;
        }
        else { // 0 5
            ans += t;
            now = a[i] + t;
        }
    }

    cout << ans << '\n';
    return 0;
}

Measured memory_bytes: 1024
def main():
    n = int(input())
    cards = [int(i) for i in input().split()]

    alice = 0
    bob = 0

    for i, c in enumerate(sorted(cards, reverse=True)):
        if i == 0 or i % 2 == 0:
            alice += c
        else:
            bob += c

    print(alice - bob)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
// =================================
//   author: memset0
//   date: 2019.03.21 15:35:21
//   website: https://memset0.cn/
// =================================
#include <bits/stdc++.h>
#define ll long long
#define debug(...) ((void)0)
#ifndef debug
#define debug(...) fprintf(stderr,__VA_ARGS__)
#endif
namespace ringo {
template <class T> inline void read(T &x) {
	x = 0; register char c = getchar(); register bool f = 0;
	while (!isdigit(c)) f ^= c == '-', c = getchar();
	while (isdigit(c)) x = x * 10 + c - '0', c = getchar();
	if (f) x = -x;
}
template <class T> inline void print(T x) {
	if (x < 0) putchar('-'), x = -x;
	if (x > 9) print(x / 10);
	putchar('0' + x % 10);
}
template <class T> inline void print(T x, char c) { print(x), putchar(c); }

const int N = 1e6 + 10;
int n, m, ans, flag = 1;
char a[N], b[N];
std::queue <int> q;

void main() {
	read(n), scanf("%s%s", a + 1, b + 1);
	for (int i = 1; i <= n; i++) flag &= a[i] == b[i];
	if (flag) { puts("0"); return; }
	for (int i = n, j = n; i >= 1; i--) {
		if (b[i] == b[i - 1]) continue;
		while (j >= 1 && j > i) j--;
		while (j >= 1 && b[i] != a[j]) j--;
		if (j < 1) { puts("-1"); return; }
		while (q.size()) {
			// printf(">> %d %d %d\n", q.front(), q.size(), i);
			if (q.front() - q.size() >= i) q.pop();
			else break;
		}
		q.push(j);
		if (i != j) ans = std::max(ans, (int)q.size());
	}
	print(ans + 1, '\n');
}

} signed main() { return ringo::main(), 0; }

Measured memory_bytes: 6272
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
#define ll long long
#define pii pair<int,int>
#define pll pair<ll int,ll int>
#define pb push_back
#define sbit __builtin_popcount
#define vec vector <int>
#define vecp vector <pii>
#define ub upper_bound
#define lb lower_bound
#define bs binary_search
#define bg begin()
#define en end()
#define endl "\n"
#define ff first
#define ss second
#define sz(a) (int)a.size()
#define min3(a,b,c) min(a,min(b,c))
#define max3(a,b,c) max(a,max(b,c))
#define sp(x) setprecision(x)
#define fill(a,b) memset(a,b,sizeof(a))
#define fr(i,n) for(int i=0;i<n;i++)
#define rp(i,a,b) for(int i=a;i<b;i++)
#define rr(i,a,b) for(int i=a;i>=b;i--)
#define ft(it,x) for(auto it : x)
#define dbg(x) cerr<<#x<<" "<<x<<endl;
#define dbga(arr,n) cerr<<#arr<<": "; rep(tt,0,n)cerr<<arr[tt]<<" "; cerr<<endl;
#define mapi map<int,int>
#define mapl map<ll int,ll int>
#define val_at(x) find_by_order(x)
#define idx_of(x) order_of_key(x)
#define scni(x) scanf("%d",&x)
#define prt(x) printf("%d\n",x)
#define test(t) int t;cin>>t;while(t--)
#define fast ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const int mod=1e9+7;
const int mex=1e6+1;
inline ll power(ll a,ll b)
{
    ll ans=1,temp=a;
    while(b!=0)
    {
        if(b&1)
        ans=ans*temp;
        ans=ans%mod;
        temp=temp*temp;
        temp=temp%mod;
        b/=2;
    }
    return ans;
}
int pr[mex];
vec prime;
inline void seive()
{
    rp(i,2,mex) pr[i]=1;
    for(int i=2;i*i<mex;i++)
    {
        if(pr[i])
        for(int j=i*i;j<mex;j+=i)
        pr[j]=0;
    }
    vec prime;
    rp(i,2,mex)
    {
        if(pr[i]) prime.pb(i);
    }
}
ll int xx,xy,d1;
void exeu(ll int a1,ll int b1)
{
    if(b1==0)
    {
        xx=1;
        xy=0;
        d1=a1;
    }
    else
    {
        exeu(b1,a1%b1);
        ll int temp=xx;
        xx=xy;
        xy=temp-(a1/b1)*xy;
    }
}
ll int modinv(ll int A,ll int M)
{
    exeu(A,M);
    return (xx%M+M)%M;
}
int main()
{
    fast
    int n,fg=1;
    cin>>n;
    int a[n];
    mapi mp;
    fr(i,n) cin>>a[i];
    fr(i,n)
    {
        if(mp[a[i]]) {
            fg=0;
            break;
        }
        mp[a[i]]++;
    }
    if(fg) cout<<"YES\n";
    else cout<<"NO\n";
    return 0;
}


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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair
#define F first
#define S second

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;



#define MAX_N 100000
i64 N, K;
i64 H[MAX_N];

int main() {
  cin >> N >> K;
  REP(i, N) cin >> H[i];

  i64 cnt = 0;
  REP(i, N) {
    if (H[i] >= K) cnt++;
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 1024
def main():
  import sys
  num,capacity=map(int,input().split())
  items=tuple([list(map(int,sys.stdin.readline().split())) for _ in range(num)])
  DP=[-1]*(capacity+1)
  DP[0]=0
  for item in items:
    weight=item[0]
    value=item[1]
    left=capacity-weight
    for i in range(left,-1,-1):
      if DP[i]<0:
        continue
      DP[i+weight]=max(DP[i]+value,DP[i+weight])
  print(max(DP))
      
if __name__=="__main__":
  main()

Measured memory_bytes: 40048
n,w=map(int,input().split())
item=[]
for i in range(n):
    tmp=list(map(int,input().split()))
    item.append(tmp)

dp=[[0]*(w+1) for i in range(n+1)]
for i in range(n):
    for j in range(w+1):
        if j >= item[i][0]:
            dp[i+1][j]=max(dp[i][j],dp[i][j-item[i][0]]+item[i][1])
        else:
            dp[i+1][j]=dp[i][j]
print(dp[n][w])


Measured memory_bytes: 120300
a,b=map(int,input().split())
if b==1:
  print(0)
if 1<b<=a:
  print(1)
for i in range(a):
  if (a-i+i*a)<b<=(a-(i+1)+(i+1)*a):
    print(1+(i+1))
for i in range(a**2):
  if ((a**2)-i+i*a)<b<=((a**2)-(i+1)+(i+1)*a):
    print(1+a+(i+1))
for i in range(a**3):
  if ((a**3)-i+i*a)<b<=((a**3)-(i+1)+(i+1)*a):
    print(1+a+(a**2)+(i+1))
for i in range(a**4):
  if ((a**4)-i+i*a)<b<=((a**4)-(i+1)+(i+1)*a):
    print(1+a+(a**2)+(a**3)+(i+1))
for i in range(a**5):
  if ((a**5)-i+i*a)<b<=((a**5)-(i+1)+(i+1)*a):
    print(1+a+(a**2)+(a**3)+(a**4)+(i+1))
  
 
 
 



Measured memory_bytes: 3064
#include <cstdio>
#include <climits>
#include <cassert>
#include <cmath>
#include <iostream>
#include <string>
#include <algorithm>
#include <numeric>
#include <functional>
#include <tuple>
#include <list>
#include <map>
#include <queue>
#include <stack>
#include <set>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)
#define FOR(x,xs) for(auto &x: xs)

using namespace std;
typedef long long ll;
typedef pair<int,int> PI;
typedef pair<ll,ll> PL;
typedef vector<int> VI;
typedef vector<ll> VL;

int main() {
  ios::sync_with_stdio(false);
  ll N, M;
  cin >> N >> M;
  ll t = 100 * (N - M) + 1900 * M;
  cout << t * (1 << M) << endl;
  
  return 0;
}


Measured memory_bytes: 256
N = int(input())
NN = input().split()
mini = 100
for i in range(N):
  total1 =0
  total2 =0
  for j in range(i+1):
    total1 +=  int(NN[j])
  for k in range(i+1,N):
    total2 += int(NN[k])
  ans = abs(total1-total2)
  if mini >ans:
    mini =ans
print(mini)

Measured memory_bytes: 9148
#include <iostream>

using namespace std;

int main() {
	int x;
	const int mx = 123456 * 2;
	int a[mx + 1];
	for (int i = 0; i <= mx; i++) a[i] = true;
	a[0] = false;
	a[1] = false;
	for (int i = 2; i <= mx; i++) {
	    if (a[i]) {
	        for (int j = i * 2; j <= mx; j += i) {
	            a[j] = false;
	        }
	    }
	}
	while(cin >> x, x) {
	    int y = 0;
	    for (int i = x + 1; i <= 2 * x; i++) {
	        if (a[i]) y++;
	    }
	    cout << y << endl;
	}
}


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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define fi first
#define se second

typedef pair<lint, lint> P;
const lint MOD = 1e9+7;
const lint INF = MOD * MOD;
const int MAX = 100005;

int main(){
    long n, k, s; cin>>n>>k>>s;
    rep(i, n){
        if(i < k) cout << s << " ";
        else{
            if(s == 1e9) cout << s-1 << " ";
            else cout << s+1 << " ";
        }
    }
    cout << endl;
}

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

using namespace std;
// ascending order
#define vsort(v) sort(v.begin(), v.end())
// descending order
#define vsort_r(v) sort(v.begin(), v.end(), greater<int>())
#define vunique(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define ts(x) to_string(x)
#define rep(i, a, b) for(int i = (int)a; i < (int)b; i++)
#define repm(i, a, b) for(int i = (int)a; i > (int)b; i--)
#define bit(a) bitset<8>(a)
#define des_priority_queue priority_queue<int, vector<int>, greater<int> >
typedef long long ll;
typedef pair<int, int> P;
const ll INF = 1e18;

#define MAX_V 1000000

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

  int h, n;
  cin >> h >> n;
  int a[n], b[n];
  rep(i, 0, n) cin >> a[i] >> b[i];

  int dp[n + 1][h + 10001];
  rep(i, 0, n + 1) rep(j, 0, h + 10001) dp[i][j] = 1<<29;
  dp[0][0] = 0;

  rep(i, 0, n) {
    rep(j, 0, h + 10001) {
      if(j - a[i] >= 0) {
        dp[i + 1][j] = min(dp[i][j], dp[i + 1][j - a[i]] + b[i]);
      } else {
        dp[i + 1][j] = dp[i][j];
      }
    }
  }
  int rsl = 1<<29;
  rep(j, h, h + 10001) rsl = min(rsl, dp[n][j]);
  cout << rsl << endl;
}


Measured memory_bytes: 78464
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
using namespace std;
char hi[5][5];

int main()
{
    for (int i = 0; i < 2; i++)
    {
        for (int j = 0; j < 3; j++){
            scanf("%c",&hi[i][j]);
        }
        getchar();
    }
    if (hi[0][0] == hi[1][2] && hi[0][2] == hi[1][0] && hi[0][1] == hi[1][1])
        printf("YES\n");
    else
        printf("NO\n");
}

Measured memory_bytes: 128
#include <stdio.h>

int main()
{
  int n;
  scanf("%d",&n);
  int v[n],c[n];
  int i;
  i = 0;
  while (i < n)
  {
    scanf("%d",&v[i]);
    i++;
  }
  i = 0;
  while (i < n)
  {
    scanf("%d",&c[i]);
    i++;
  }
  i = 0;
  int value;
  int cost;
  cost = 0;
  value = 0;
  while (i < n)
  {
    if (v[i] - c[i] > 0)
    {
      value += v[i] - c[i];
    }
    i++;
  }
  printf("%d",value);
}


Measured memory_bytes: 128
//This program is written by Brian Peng.
#pragma GCC optimize("Ofast","inline","no-stack-protector")
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define Rd(a) (a=read())
#define Gc(a) (a=getchar())
#define Pc(a) putchar(a)
int read(){
	int x;char c(getchar());bool k;
	while(!isdigit(c)&&c^'-')if(Gc(c)==EOF)exit(0);
	c^'-'?(k=1,x=c&15):k=x=0;
	while(isdigit(Gc(c)))x=(x<<1)+(x<<3)+(c&15);
	return k?x:-x;
}
void wr(int a){
	if(a<0)Pc('-'),a=-a;
	if(a<=9)Pc(a|'0');
	else wr(a/10),Pc((a%10)|'0');
}
signed const INF(0x3f3f3f3f),NINF(0xc3c3c3c3);
long long const LINF(0x3f3f3f3f3f3f3f3fLL),LNINF(0xc3c3c3c3c3c3c3c3LL);
#define Ps Pc(' ')
#define Pe Pc('\n')
#define Frn0(i,a,b) for(int i(a);i<(b);++i)
#define Frn1(i,a,b) for(int i(a);i<=(b);++i)
#define Frn_(i,a,b) for(int i(a);i>=(b);--i)
#define Mst(a,b) memset(a,b,sizeof(a))
#define File(a) freopen(a".in","r",stdin),freopen(a".out","w",stdout)
int n,k;
signed main(){
	Rd(n),Rd(k);
	wr(min(n%k,k-(n%k)));
	exit(0);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#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;}
const int NM = 1e5+1;
vector<int> ab[NM];
vector<P> ipt;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;cin>>n;
    rep(i, n-1){
        int a,b;cin>>a>>b;
        ipt.push_back(make_pair(a,b));
        ab[a].push_back(b);
        ab[b].push_back(a);
    }
    map<P, int> color; // 辺の色
    int ngcol[NM] = {0}; //頂点に紐づく色
    // 幅優先探索
    queue<int> q;
    q.push(1); // 頂点1からはじめる
    int mx = 0;
    while(!q.empty()){
        int now = q.front(); q.pop();
        int col = 1;
        for(int next : ab[now]){
            int x=now, y=next; 
            if(x>y) swap(x,y);
            P pa = make_pair(x, y);
            if(color[pa] == 0){
                // 彩色
                if(col == ngcol[now]) col++;
                color[pa] = col; 
                ngcol[next]=col; mx = max(mx, col);
                q.push(next);
                col++;
            }
        }
    }
    cout<<mx<<endl;
    for(P p : ipt){
        cout<<color[p]<<endl;
    }

}

Measured memory_bytes: 13432
import java.io.*;
import java.lang.*;
import java.util.*;
import java.math.*;

class Main {
	static BufferedReader jvin = new BufferedReader(new InputStreamReader(System.in));
	static PrintWriter jvout = new PrintWriter(System.out);

	static int maxN = (int)1E5+5;
	int n;
	int[] a;

	public static void main(String[] args) throws IOException {
		Main instance = new Main();
		instance.passStaticVar();
	}

	public void passStaticVar() throws IOException {
		n = Integer.parseInt(jvin.readLine());
		a = new int[n+1];
		for (int i = 1; i <= n; ++i) 
			a[i] = Integer.parseInt(jvin.readLine());
		
		boolean[] marked = new boolean[n+1];
		for (int i = 1; i <= n; ++i)
			marked[i] = false;
		int result = 0, i = 1;
		for ( ; !marked[i] && i != 2; i = a[i]) {
			marked[i] = true;
			++result;
		}
		if (i == 2) jvout.println(result);
		else jvout.println("-1");
		jvout.flush();
	}
}


Measured memory_bytes: 34516
#include<iostream>
using namespace std;
int n;
char c[200001];
int main(){
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>c[i];
  }
  int j=n-1,cnt=0;
  for(int i=0;i<j;i++){
    if(c[i]=='W'){
      for(j;j>i && c[j]!='R';j--);
      if(j>i){
        swap(c[i],c[j]);
        j--;
        cnt++;
      }else if(c[j]=='R'){
        cnt++;
        break;
      }
    }
  }
  cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 3760
#include<cstdio>
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<map>

using namespace std;

#define reps(i,f,n) for(int i=f;i<int(n);i++)
#define rep(i,n) reps(i,0,n)

typedef vector<int> vi;
typedef vector<vi> vii;
typedef pair<int,int> pii;

class T{
	public:
	int x,y,ans;
	T(int x,int y,int ans):x(x),y(y),ans(ans){}
};

int main(){
	int w,h;
	A:cin>>w>>h;
	if(w==0)return 0;
	
	int t[31][31]={0};
	int z[31][31]={0};
	rep(i,h){
		rep(j,w-1){
			cin>>t[j][i];
		}
		if(i!=h-1)rep(j,w){
			cin>>z[j][i];
		}
	}
	
	/*
	rep(i,h){
		rep(j,w)printf("%d ",t[i][j]);puts("");
		rep(j,w)printf("%d ",y[i][j]);puts("");
		puts("");
	}*/
	
	queue<T> que;
	que.push(T(0,0,0));
	
	int visit[31][31]={0};
	int ans = -1;
	
	while(1){
		if(que.empty())break;
		
		T u = que.front();
		que.pop();
		
		if(visit[u.x][u.y]==1)continue;
		visit[u.x][u.y]=1;
		
		if(u.x==w-1 && u.y==h-1){
			ans = u.ans;
			break;
		}
		
		int x = u.x;
		int y = u.y;
		if(x<w-1 && t[x][y]!=1)que.push(T(x+1,y,u.ans+1));
		if(y<h-1 && z[x][y]!=1)que.push(T(x,y+1,u.ans+1));
		if(x>0 && t[x-1][y]!=1)que.push(T(x-1,y,u.ans+1));
		if(y>0 && z[x][y-1]!=1)que.push(T(x,y-1,u.ans+1));
	}
	
	printf("%d\n",ans+1);
	
	goto A;
}

Measured memory_bytes: 1208
#include "iostream"
#include "string"
#include "algorithm"
using namespace std;
/*string shuffle(string a, int b) {
	string c;
	for (int i = 0; i < a.size(); i++) {
		if (i < b) {
			c[a.size() - b + i] = a[i];
		}
		else {
			c[i-b] = a[i];
		}
	}
	for (int i = 0; i < a.size(); i++) {
		a[i] = c[i];
	}
	return a;
}
int main(){
	string str;
	int m, a[100];
	while (cin >> str && str != "-") {
		cin >> m;
		for (int i = 0; i < m; i++) {
			cin >> a[i];
			str = shuffle(str, a[i]);
		}
		cout << str << endl;
	}
}

*/

struct dice {
	int s[6];
	void roll(char c) {
		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 == '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;
		}
		if (c == 'W') {
			b = s[0];
			s[0] = s[2];
			s[2] = s[5];
			s[5] = s[3];
			s[3] = b;
		}
	}
	int top() {
		return s[0];
	}
};

int main() {
	dice d;
	for (int i = 0; i < 6; i++) {
		cin >> d.s[i];
	}
	string order;
	cin >> order;
	for (int i = 0; i < order.size(); i++) {
		d.roll(order[i]);
	}
	cout << d.top() << endl;
}


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,k,n) for(int i = (int)(k); i < (int)(n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(a) a.begin(), a.end()
#define MS(m,v) memset(m,v,sizeof(m))
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<string> vs;
typedef pair<int, int> pii;
const int MOD = 1000000007;
const int INF = MOD + 1;
const ld EPS = 1e-12;
template<class T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<class T> T &chmax(T &a, const T &b) { return a = max(a, b); }

/*--------------------template--------------------*/
typedef int Weight;
struct Edge
{
	int from, to; Weight cost;
	bool operator < (const Edge& e) const { return cost < e.cost; }
	bool operator > (const Edge& e) const { return cost > e.cost; }
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;
typedef vector<Weight> Array;
typedef vector<Array> Matrix;
void add_edge(Graph &g, int from, int to, Weight cost)
{
	g[from].push_back(Edge{ from, to, cost });
}

ll pow(ll x, ll n, ll mod)
{
	ll res = 1;
	while (n > 0)
	{
		if (n & 1) res = res * x % mod;
		x = x*x%mod;
		n >>= 1;
	}
	return res;
}


int main()
{
	cin.sync_with_stdio(false); cout << fixed << setprecision(10);
	int n, m;
	while (cin >> n >> m, n)
	{
		Graph g(n);
		REP(i, m)
		{
			int a, b; cin >> a >> b;
			a--; b--;
			add_edge(g, a, b, 0);
			add_edge(g, b, a, 0);
		}
		vector<bool> vis(n);
		ll cnt = 0;
		REP(i, n)
		{
			if (vis[i]) continue;
			vis[i] = true;
			cnt++;
			queue<int> que;
			que.push(i);
			while (!que.empty())
			{
				int t = que.front();
				que.pop();
				for (auto j : g[t])
				{
					int u = j.to;
					if (vis[u]) continue;
					vis[u] = true;
					que.push(u);
				}
			}
		}
		ll ans = pow(2, cnt, MOD);
		if (cnt != n) ans++;
		cout << ans % MOD << endl;
	}
	return 0;
}

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

#define forn(i, n) for (int i = 0; i < int(n); ++i)
#define for1(i, n) for (int i = 1; i <= int(n); ++i)
#define ms(a, x) memset(a, x, sizeof(a))
#define F first
#define S second
#define all(x) (x).begin(),(x).end()

using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int INF = 0x3f3f3f3f;
mt19937 gen(chrono::steady_clock::now().time_since_epoch().count());
template<typename... Args> void rd(Args&... args) {((cin >> args), ...);}
template<typename... Args> void write(Args... args) { ((cout << args << " "), ...); cout<<endl;}

int n,m,q;
vector<array<int,4>> v;
vector<int> ans;
int mx;
void dfs(int x,int num){
    if(x==n){
        ans[x]=num;
        int sum=0;
        for(auto [d,a,b,c]:v){
            if(ans[b]-ans[a]==c) sum+=d;
        }
        mx=max(mx,sum);
        return;
    }
    ans[x]=num;
    for(int i=ans[x];i<=m;i++) dfs(x+1,i);
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    rd(n,m,q);
    v.resize(q);
    ans.resize(n+1);
    for(auto& [d,a,b,c]:v){
        cin>>a>>b>>c>>d;
    }
    dfs(0,1);
    cout<<mx;
    return 0;
}



Measured memory_bytes: 3640
#include <iostream>
#include <math.h>
using namespace std;

int main()
{
    int N;
    cin >> N;
    int A[N];
    int max_num = 0;
    int max_i = 0;
    for(int i=0; i<N; i++){
        cin >> A[i];
        if(max_num < A[i]){
            max_num = A[i];
            max_i = i;
        }
    }
    bool flags = false;
    for(int i=0; i<N; i++){
        if(i == max_i) continue;
        if(A[i] == max_num){
            flags = true;
            break;
        }
    }
    for(int i=0; i<N; i++){
        if((A[i] != max_num) || (flags == true)){
            cout << max_num << endl;
        }else{
            int ans = 0;
            for(int j=0; j<N; j++){
                if(i == j) continue;
                ans = max(ans, A[j]);
            }
            cout << ans << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
 
#define si(x) scanf("%d",&x)
#define sf(x) scanf("%lf",&x)
#define sl(x) scanf("%lld",&x)
#define pr(x) printf("%d\n",x)
#define prll(x) printf("%lld\n",x)
 
#define ll long long int
#define ull unsigned long long int
#define F first
#define S second
 
#define rep(i,x,y) for(int i=x;i<y;i++)
#define ii pair<int,int> 
#define pll pair<ll,ll> 
#define vi vector<int> 
#define vvi vector< vi > 
#define vl vector<long long int>
#define vvl vector< vl >
#define vii vector< ii >
#define vvii vector< vii >
#define priority_queue pq;
#define sz(a) ll((a).size()) 
#define pb push_back 
#define mp make_pair
 
#define ROUNDOFFINT(d) d = (int)((double)d + 0.5)
#define SET(a,b) memset(a,b,sizeof(a))
#define all(c) (c).begin(),(c).end() 
#define tr(i,c) for(typeof((c).begin()) i = (c).begin(); i != (c).end(); i++) 
#define present(c,x) ((c).find(x) != (c).end()) 
#define cpresent(c,x) (find(all(c),x) != (c).end())
#define ison(x,i) (((x) >> (i)) & 1)	//checks if ith bit is on
#define set0(x,i) (x & ~(1 << i))		//set ith bit in x to be zero
#define clr(a) memset(a,0,sizeof(a))
 
#define MOD 1000000007
#define INF 4000000000000000000
#define MAX 100000+5
using namespace std;



int main()
{
	string s;
	cin>>s;
	int n = s.size();
	rep(i,0,n-1)
	if(s[i]=='A' && s[i+1]=='C')
	{
		printf("Yes\n");
		return 0;
	}
	printf("No\n");
	return 0;
}

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

using namespace std;

int main(void) {
	string A, B, C;
	cin >> A >> B >> C;
	if (A.back() == B.front() &&
		B.back() == C.front()) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}






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

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

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

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

const int MOD = 1000000007;

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

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

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

using Graph = vector<vector<int>>;

Graph G;

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

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

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

    vector<ll> a(q);
    vector<ll> cnt(n, 0);

    rep(i, q) cin >> a[i], cnt[a[i] - 1]++;

    rep(i, n)
    {
        ll temp = cnt[i];
        ll other = q - temp;
        if (k - other > 0)
        {
            cout << "Yes" << endl;
        }
        else
        {
            cout << "No" << endl;
        }
    }
}


Measured memory_bytes: 2176
s = input()
t = input()
l_s = [s[i] for i in range(len(s))]
l_t = [t[i] for i in range(len(t))]
l_s.sort()
l_t.sort(reverse=True)
s_new = ''.join(l_s)
t_new = ''.join(l_t)
if s_new < t_new:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>
using namespace std;

int main()
{
  int a,b,d,r;
  double f;
  
  cin >>a>>b;
  d = a/b;
  r = a%b;
  f = (double)a/b;

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

Measured memory_bytes: 1184
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

inline int getbit(int mask, int v) {
    return (mask >> v) & 1;
}

inline int newmask(int mask, int v) {
    return mask | (1 << v);
}

const int INF = 1e9;

int main()
{
    int n, m;
    cin >> n >> m;
    int cost[n][n];
    vector <int> g[n];
    int x, y, c;
    for (int i = 0; i < m; i++) {
        cin >> x >> y >> c;
        g[x].push_back(y);
       // g[y].push_back(x);
        cost[x][y] = c;
       // cost[y][x] = c;
    }
    int P = pow(2, n);
    int d[P + 1][n];
    for (int i = 1; i < P; i++) {
        for (int j = 0; j < n; j++) {
            d[i][j] = INF;
        }
    }
    d[1][0] = 0;
    int ans = INF;
    for (int mask = 1; mask < P; mask++) {
        for (int v = 0; v < n; v++) {
            if (d[mask][v] != INF) {
                for (int i = 0; i < (int)g[v].size(); i++) {
                    int u = g[v][i];
                    if (mask < P - 1) {
                        if (!getbit(mask, u)) {
                            d[newmask(mask, u)][u] = min(d[newmask(mask, u)][u], d[mask][v] + cost[v][u]);
                        }
                    } else {
                        if (u == 0) {
                            ans = min(ans, d[mask][v] + cost[v][0]);
                        }
                    }
                }
            }
        }
    }
    if (ans == INF) {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
}

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

using namespace std;

using ll = long long;

bool Solve() {
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = 0; i <= b; ++i)
        if (i * a % b == c) return true;
    return false;
}

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

    if (Solve()) cout << "YES\n";
    else cout << "NO\n";

    return 0;
}


Measured memory_bytes: 256