akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;
template<class T, class U> void assign(V<T>& v, int n, const U& a) { v.assign(n, a); }
template<class T, class... Args> void assign(V<T>& v, int n, const Args&... args) { v.resize(n); for (auto&& e : v) assign(e, args...); }


int main() {
  cin.tie(nullptr); ios_base::sync_with_stdio(false);
  int n, m; cin >> n >> m;
  V<> c{2, 5, 5, 4, 5, 6, 3, 7, 6};
  V<> a(m); for (int i = 0; i < m; ++i) cin >> a[i], --a[i];
  sort(rbegin(a), rend(a));
  V<> dp(n + 1, -1e9);
  V<> prev(n + 1);
  dp[0] = 0;
  for (int x = 1; x <= n; ++x) {
    for (int i = 0; i < m; ++i) if (x - c[a[i]] >= 0) {
      int curr = dp[x - c[a[i]]] + 1;
      if (curr > dp[x]) {
        dp[x] = curr;
        prev[x] = a[i];
      }
    }
  }
  string res;
  while (n > 0) {
    res += '1' + prev[n];
    n -= c[prev[n]];
  }
  cout << res << '\n';
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define rep(i, s, n) for (int i = (s); i < (int)(n); i++)
#define per(i, n, s) for (int i = (n-1); i >= (int)(s); i--)
#define all(x) (x).begin(),(x).end()
#define debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
using ll = long long;
const ll MOD = 1e9+7;
const ll LINF = LLONG_MAX;
const int INF = INT_MAX;

int main(){
    string s; cin>>s;
    ll ans=0;
    ll length=1;
    vector<int> v;
    if(s[0]=='>') v.push_back(0);
    rep(i,1,s.size()){
        if(s[i]==s[i-1]){
            length++;
        }else {
            v.push_back(length);
            length=1;
        }
    }
    v.push_back(length);
    if(s.back()=='<') v.push_back(0);
    // rep(i,0,v.size()) debug(v[i]);
    for(int i=0; i<v.size(); i+=2){
        ll large=max(v[i],v[i+1]);
        ll small=min(v[i],v[i+1]);
        // debug(large);
        // debug(small);
        ans+=large*(large+1)/2;
        ans+=small*(small-1)/2;
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <map>
#include <cmath>
#include <queue>
#include <utility>
#include <functional>
#include <deque>
#include <cctype>
#include <stack>
#include <bitset>

using ll = long long;
typedef unsigned long long ull;
typedef std::pair<int, int>p;
struct edge { int to, cost; };
std::vector<edge>v[1000];
typedef std::vector<std::vector<int>>ma;
ma d;

ll min(ll a, ll b) {
	if (a >= b)return b;
	else return a;
}
ll max(ll a, ll b) {
	if (a >= b)return a;
	else return b;
}
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}

const ll Z = 1000000007;
const ll INF = 1 << 30;
const ll INF2 = 9000000000000000000LL;
bool flag = true;
bool fl = true;
bool f = true;
int dx[4] = { 1,0,-1,0 }, dy[4] = { 0,1,0,-1 };
std::string abc = "abcdefghijklmnopqrstuvwxyz";

int main() {
	ll n, m;
	std::cin >> n >> m;
	ll ans = 0;
	if (n == 1 && m == 1)ans = 1;
	else {
		if (n == 1)ans = m - 2;
		else if (m == 1)ans = n - 2;
		else ans = (n - 2)*(m - 2);
	}
	std::cout << ans << std::endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
int main(){
  int n,m;
  cin >> n >> m;
  int arr[n];
  int count = 0;
  for(int i=0; i<n; i++){
    cin >> arr[i];
    count+=arr[i];
  }
  sort(arr,arr+n,greater<int>());
  float cutoff = (count)/(4.0*m);
  for(int i=0; i<m; i++){
    if(arr[i]<cutoff){
      cout << "No" <<endl;
      return 0;
    }
  }
  cout << "Yes" << endl;
  return 0;
}

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

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(){
  string str;
  while(cin >> str && str != "0"){
    int sum = 0;
    for(int i = 0; i < str.size(); i++){
      sum += str[i] - '0';
    }
    cout << sum << endl;
  }
}






Measured memory_bytes: 3204
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stdio.h>
#include <cstring>
#include <queue>
#include <stack>
#include <functional>
#include <math.h>
#include <iomanip>
using namespace std;
#define Would
#define you
const int INF = 999999999;
const int MOD = 1e9 + 7;
const double pi = 3.141592653589793238;

int a, b, c, mon[100005], ans = INF;
int main() {
	cin >> a >> b >> c;
	for (int i = 0; i < c; ++i) {
		int n, m;
		cin >> n >> m;
		mon[n] = max(mon[n], m);
	}
	for (int i = 0; i < a; ++i) { mon[a - i - 1] = max(mon[a - i - 1], mon[a - i]); }
	for (int i = 0; i < a; ++i) { ans = min(ans, mon[i + 1] + i); }
	cout << ans << endl;
}



Measured memory_bytes: 3484
#include <iostream>

using namespace std;

int main() {
    int a,b,c;
    cin>>a>>b>>c;
    if(a==b && b==c){
        cout<<"No";
        return 0;
    }
    if(a!=b && b!=c && c!=a){
        cout<<"No";
        return 0;
    }
    cout<<"Yes";
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define set_zero(a) memset(a,0,sizeof(a));
#define ll long long
#define PI 2 * acos(0.0)
#define MAX 1000000000
#define INF 1000000 
#define M 1000000007
using namespace std;
int main(){
   fast_io
   ll n;
   cin>>n;
   ll a[n];
   for(ll i = 0;i<n;i++) cin>>a[i];
   ll ans = 0;
   for(ll i = 1;i<n;i++){
      if(a[i] < a[i-1]){
         ans += a[i-1]-a[i];
         a[i] = a[i-1];
      }
   }
   cout<<ans<<endl;
   return 0;
}

Measured memory_bytes: 5140
Sprime = input()
T = input()
Slist = list(Sprime)
Tlist = list(T)
s = len(Sprime)
indexis = []
possibilities = set()
for i in range(s):
  if(Slist[i] != "?"):
    indexis.append(i)
    
for i in range(s- len(T)+ 1):
  key = []
  for p in range(i):
    key.append("?")
  key.extend(Tlist)
  for q in range(s- i- len(T)):
    key.append("?")
  flag = 0
  for j in indexis:
    if(Sprime[j] != key[j] and key[j] != "?"):
      flag = 1
      break
  if(flag == 0):
    for k in indexis:
      if(key[k] == "?"):
        key[k] = Sprime[k]
    for l in range(s):
      if(key[l] == "?"):
        key[l] = "a"
    ans = ""
    for r in range(s):
      ans+= key[r]
    possibilities.add(ans)
    
if(possibilities == set()):
  print("UNRESTORABLE")
else:
  
  print(min(possibilities))

Measured memory_bytes: 3064
#include <string>
#include <iostream>
#include <algorithm>
int main(){
	int n,m;
	using namespace std;
	cin>>n>>m;
	string Str_1;
	cin>>Str_1;
	if (Str_1[n]!='-')
		return (cout<<"No\n")&&0;
	for (int i=0;i<=n+m;i++){
		if (i==n)
			continue;
		if (!isdigit (Str_1[i]))
			return (cout<<"No\n")&&0; 
	}
	return (cout<<"Yes\n")&&0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = a; i < n; i++)
#define repr(i, a, n) for (int i = n - 1; i >= a; i--)
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }

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

  int n;
  cin >> n;
  for (int i = 111; i <= 999; i += 111) {
    if (n <= i) {
      cout << i << endl;
      return 0;
    }
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
using uint = unsigned int;
using ll = long long;
 
int main() {
	int N;
	cin >> N;
	
	vector<pair<ll, ll>> XL(N, pair<ll, ll>());
	
	for(uint i=0; i<N; i++) {
		ll X, L;
		cin >> X >> L;
		XL[i] = make_pair(X - L, X + L);
	}
	
	sort(XL.begin(), XL.end());
	
	// ll bais = XL[0].first;
	// for(uint i=0; i<N; i++) { // 0 origin
		// XL[i].first -= bais;
		// XL[i].second -= bais;
	// }
	
	ll front = XL[0].first;
	uint findx = 0;
	vector<uint> ans(N + 1);
	
	for(uint i=0; i<N; i++) {
		ll le = XL[i].first;
		ll re = XL[i].second;
		
		//cout << front << " ";
		if(front <= le) {
			ans[i+1] = ans[findx] + 1;
			front = re;
			findx = i + 1;
		} else if(re <= front) {
			ans[i+1] = ans[findx];
			front = re;
			findx = i + 1;
		} else {
			ans[i+1] = ans[findx];
		}
		
		//cout << le << " " << re << " " << ans[i+1] << " " << front << endl;
	}
	
	cout << ans[N];
	
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <bits/stdc++.h>
#define ll long long
#define inf 100000000
#define mod 1000000007
#define ld long double
#define point complex<double>
#define pi  acos(-1)
#define IO                    \
	ios_base::sync_with_stdio(false); \
	cin.tie(NULL);                    \
	cout.tie(NULL);
using namespace std;


vector<int>sieve;
void sie()
{
	int arr[1000001]={};
	arr[0]=1;
	arr[1]=1;
	int cur=2;
	for(int i=2;i<1000001;i++)
	{
		if(arr[i]==0)
		{
			sieve.push_back(i);
			for(int ii=2;ii*i<1000001;ii++)
			{
				arr[i*ii]=1;
			}
		}
	}
	
}
	int main(){
		
		
		int n;
		cin>>n;
		int arr[n];
		int bef[1000001]={};
		bool sor[1000001]={};
		for(int i=0;i<n;i++)
		{
			cin>>arr[i];
			sor[arr[i]]=1;
			if(bef[arr[i]]==0)
			bef[arr[i]]=1;
			else if(bef[arr[i]]==1)bef[arr[i]]=2;
		}
		int p=0;
		for(int i=0;i<1000001;i++)
		{
			if(sor[i])
			{
				arr[p]=i;
				p++;
			}
		}
		ll res=0;
		for(int i=0;i<p;i++)
		{
			ll tmp=arr[i];
			if(bef[tmp]==1)res++;
			for(int ii=2;ii*tmp<1000001;ii++)
			{
				bef[tmp*ii]=0;
			}
		}
		cout<<res<<endl;
		

    return 0;
}


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

int main() {
    string s, t;
    cin >> s >> t;

    string res = "No", tmp;
    int size = 0;
    while (size < s.size()) {
        tmp = s.substr((s.size()-size), s.size());
        if ((tmp + s.substr(0, (s.size()-size))) == t) {
            res = "Yes";
            break;
        }
        size++;
    }

    cout << res << endl;    

    return 0;
}


Measured memory_bytes: 3632
fun main(args: Array<String>) {
    val (h, w) = readIntList()
    val a = mutableListOf<CharArray>()
    for (i in 0 until h) {
        val row = readString()
        if (row != (1..w).joinToString(separator = "") { "." }) {
            a.add(row.toCharArray())
        }
    }

    val col = MutableList(w) { false }
    for (j in 0 until w) {
        for (i in a.indices) {
            if (a[i][j] == '#') {
                col[j] = true
            }
        }
    }

    for (i in a.indices) {
        for (j in 0 until w) {
            if (col[j]) {
                print(a[i][j])
            }
        }
        println()
    }

}

// Tools
fun readString() = readLine()!!
fun readInt() = readLine()!!.toInt()
fun readLong() = readLine()!!.toLong()
fun readStringList() = readLine()!!.split(" ")
fun readIntList() = readLine()!!.split(" ").map(String::toInt)
fun readLongList() = readLine()!!.split(" ").map(String::toLong)

Measured memory_bytes: 39504
<?php
//error_reporting(0);
$N = trim(fgets(STDIN));
//list($A,$B) =  explode(" ",trim(fgets(STDIN)));
$A = explode(" ",trim(fgets(STDIN)));
$B = explode(" ",trim(fgets(STDIN)));
$C = explode(" ",trim(fgets(STDIN)));

$m=0;
$prev=-1;
for($i=0;$i<$N;$i++) {
  //満足度
  $m += $B[$A[$i]-1];
  if ($i > 0 && $A[$i-1] == $A[$i]-1) {
    $m+=$C[$A[$i-1]-1];
  }
}
printf("%d\n",$m);


Measured memory_bytes: 4856
/*siddharth goyal*/
#include<bits/stdc++.h>
using namespace std;
#define   pb              push_back
#define   REP(i,n)        for(int i=1;i<=n;i++)
#define   FOR(i,a,b)      for(int i=a;i<=b;i++)
#define   all(v)          v.begin(),v.end()
#define   F               first
#define   S               second
#define   vl              vector<LL>
#define   itr             ::iterator it
#define   lb              lower_bound
#define   ub              upper_bound
#define   LL              long long
#define   ULL             unsigned long long
#define   ret             return 
#define   sz(x)           (LL)x.size()
LL n,i,j,ans = 0,k;
string s ; 
LL dp[1000000][5] ; 
LL a[1000000][5] ;
LL f(LL ind,LL pre) 
{ 
} 
int main()
{   // Read the constraints,highlights,Time Limit,Test Cases
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>n ; 
    //memset(dp,-1,sizeof(dp)) ; 
    REP(i,n) REP(j,3) cin>>a[i][j] ; 
    dp[1][1] = a[1][1] ; 
    dp[1][2] = a[1][2] ; 
    dp[1][3] = a[1][3] ; 
    for(int i=2;i<=n;i++)
    {  dp[i][1] = a[i][1] + max(dp[i-1][3],dp[i-1][2]) ; 
       dp[i][2] = a[i][2] + max(dp[i-1][1],dp[i-1][3]) ; 
       dp[i][3] = a[i][3] + max(dp[i-1][2],dp[i-1][1]) ; 
    }   
   cout<<max(dp[n][1],max(dp[n][2],dp[n][3])) ; 
}
//Check for 0,1 and other corner cases.

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

#define rep(i,n) for (int i=0; i<(n); i++)
const int INF =1001001001;
const ll BIG = 1000000007;

int main(){
    int k;
    string s;
    cin >> k >> s;
    if(s.size()<=k) cout << s << endl;
    else{
        cout << s.substr(0,k) << "..." << endl;
    }
    return 0;
}

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

typedef long long ll;

#define cin(argument) cin >> argument
#define cout(argument) cout << argument << "\n"
#define kaigyou cout << "\n"
#define REP(i,a,b) for(ll i=a;i<b;i++)
#define rep(i,n) REP(i,0,n)
#define REPR(i,a,b) for(ll i=b;i>=a;i--)
#define repr(i,n) REPR(i,0,n)
#define size(n) (n).size()
#define EPS (1e-7)
#define INF (1e9)

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

    ll a,b,c,d;
    cin(a);cin(b);cin(c);cin(d);
    if(a+b > c+d) cout("Left");
    if(a+b==c+d) cout("Balanced");
    if(a+b < c+d) cout("Right");
    return 0;
}

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

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    vector<ll> sum(N + 1);
    rep(i, N) {
        cin >> A[i];
        sum[i + 1] = A[i];
    }
    sum.push_back(__LONG_LONG_MAX__);

    for (int i = 0; i < N; i++) {
        sum[i + 1] += sum[i];
    }

    ll ans = __LONG_LONG_MAX__;
    for (int i = 0; i < N; i++) {
        if (i < 2) continue;
        if (i > N - 2) continue;

        ll X = sum[i];
        int l = 0;
        int r = i + 1;
        while (r - l >= 1) {
            int mid = (r + l) / 2;
            if (2 * sum[mid] >= X) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }
         
        ll P, Q;
        // rかr-1が候補
        ll p1 = sum[r]; ll q1 = X - p1; 
        ll p2 = sum[r - 1]; ll q2 = X - p2;
        if (abs(q1 - p1) > abs(q2 - p2)) {
            P = p2; Q = q2;
        } else {
            P = p1; Q = q1;
        }
// cout << "  i: " << i << ", P: " << P << ", Q: " << Q << endl;

        ll Y = sum[N] - X;
        l = i + 1;
        r = N + 1;
        while (r - l >= 1) {
            int mid = (r + l) / 2;
            if (2 * (sum[mid] - sum[i]) >= Y) {
                r = mid;
            } else {
                l = mid + 1;
            }
        }

        ll R, S;
        ll r1 = sum[r] - sum[i]; ll s1 = Y - r1;
        ll r2 = sum[r - 1] - sum[i]; ll s2 = Y - r2;
        if (abs(s1 - r1) > abs(s2 - r2)) {
            R = r2; S = s2;
        } else {
            R = r1; S = s1;
        }
        // cout << "  i: " << i << ", R: " << R << ", S: " << S << endl;

        ans = min(ans, max(P, max(Q, max(R, S))) - min(P, min(Q, min(R, S))));
    }
    cout << ans << endl;
}

Measured memory_bytes: 7120
/*
https://www.cnblogs.com/PsychicBoom/p/11779587.html
https://www.qaq-am.com/AGC021E/
*/
#include <bits/stdc++.h>

using namespace std;

typedef long long LL;
const int N = 5e5 + 10, Mod = 998244353;

int n, K, fac[N + 10], ifac[N + 10];

inline int Pow(int x, int y, int res = 1) {
	for (; y; y >>= 1, x = (LL)x * x % Mod)
		(y & 1) && (res = (LL)res * x % Mod);
	return res % Mod;
} 

inline int C(int x, int y) { return (LL)fac[x] * ifac[x - y] % Mod * ifac[y] % Mod; }

int main()
{
	fac[0] = ifac[0] = 1;
	for (int i = 1; i <= N; ++i) fac[i] = (LL)fac[i - 1] * i % Mod;
	ifac[N] = Pow(fac[N], Mod - 2);
	for (int i = N - 1; i >= 1; --i) ifac[i] = (LL)ifac[i + 1] * (i + 1) % Mod;
	scanf("%d%d", &n, &K);
	int fans = 0;
	for (int i = n; i <= K; ++i)
		fans = (fans + C(K - 1, i - 1)) % Mod;
	printf("%d\n", fans);

	return 0;
}


Measured memory_bytes: 4096
n, m = map(int, input().split())
h = list(map(int, input().split()))

table = [[] for _ in range(n)]
for _ in range(m):
    a, b = map(lambda x: int(x) - 1, input().split())
    table[a].append(b)
    table[b].append(a)

ans = set()
for i in range(n):
    stack = table[i]
    highest = h[i]
    flag = True
    for t in table[i]:
        if highest <= h[t]:
            flag = False
            break
    if flag:
        ans.add(i)
print(len(ans))


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

struct UnionFind{
	vector<int> rnk,par,num;
	UnionFind(int N) : rnk(N),par(N),num(N){
		init();
	}
	void init(){
		for(int i = 0;i < rnk.size();i++){
			rnk[i] = 0;
			par[i] = i;
			num[i] = 1;
		}
	}
	int find(int x){
		if(par[x] == x) return x;
		return par[x] = find(par[x]);
	}
	void unite(int x,int y){
		x = find(x);
		y = find(y);
		if(x == y) return;
		if(rnk[x] < rnk[y]){
			par[x] = y;
			num[y] += num[x];
		}
		else{
			par[y] = x;
			num[x] += num[y];
			if(rnk[x] == rnk[y]) rnk[x]++;
		}
	}
	bool same(int x,int y){
		return (find(x) == find(y));
	}
	int size(int x){
		return num[find(x)];
	}
};

struct edge{int u, v, cost;};

bool comp(const edge& e1, const edge& e2){
  return e1.cost < e2.cost;
}
typedef pair<int, int> P;
int main(){
    int N, K, L; cin >> N >> K >> L;
    vector<int> number(N, 1);
    UnionFind tree(N), tree1(N);
    for(int i = 0; i < K; i++){
      int p, q; cin >> p >> q; --p; --q;
      tree.unite(p, q);
    }
    for(int i = 0; i < L; i++){
        int p, q; cin >> p >> q; --p; --q;
        tree1.unite(p, q);
    }
    map<P, int> E;
    for(int i = 0; i < N; i++){
       E[P(tree.find(i), tree1.find(i))]++;
    }
    for(int i = 0; i < N; i++){
        cout << E[P(tree.find(i), tree1.find(i))] << " ";
    }
    cout << endl;
}

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

int main(){
	int N;
	cin >> N;
	vector<int> H(N);
	for(auto &i:H)cin >> i;
	
	int ans=0,tmp=0;
	for(int i=0;i<N;i++){
		if(i==N-1)ans=max(ans,tmp);
		else{
			if(H[i]>=H[i+1])tmp++;
			else{
				ans=max(ans,tmp);
				tmp=0;
			}
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main(){
  string s;
  cin >> s;
  int t_i=0, s_i=0;
  for(char c : s){
    if(s_i == 0){
      if(c == 'T'){
        t_i++;
      }else{
        s_i++;
      }
    }else{
      if(c == 'S'){
        s_i++;
      }else{
        s_i--;
      }
    }
  }
  cout << t_i + s_i;
}

Measured memory_bytes: 640
import collections
S = collections.deque(input())
Q = int(input())
reverse = False
for i in range(Q):
  q = input()
  if q == "1":
    reverse = not reverse
  else:
    q,f,c = q.split()
    if (f == "1" and not reverse) or (f == "2" and reverse):
      S.appendleft(c)
    else:
      S.append(c)
if not reverse:
  print("".join(S))
else:
  print("".join(reversed(S)))

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

int main(){
	long long int   N ,a, b, c, d, e;
	string S;
	cin >> a >> b >> c >> d >> e;
	
  	if(a == 0) cout << 1 << endl;
  	if(b == 0) cout << 2 << endl;
  	if(c == 0) cout << 3 << endl;
	if(d == 0) cout << 4 << endl;
  	if(e == 0) cout << 5 << endl;
}


Measured memory_bytes: 3636
#include <iostream>
#include <cmath>
#include <iomanip>

#define NUM_S 6

class Dice {
public:
	Dice(const int n[NUM_S]);
	int roll(char);
	int rollS();
	int rollE();
	int rollW();
	int rollN();

	void show();

private:
	int top, south, east, west, north, bottom;
};
using namespace std;


int main(void){
	int surface[NUM_S];
	char ch;
	
	for (int i = 0; i < NUM_S; i++) {
		cin >> surface[i];
	}

	Dice dice(surface);
	while (cin >> ch) {
		dice.roll(ch);
	}
	dice.show();

	return 0;
}


Dice::Dice(const int n[NUM_S]) {
	top = n[0];
	south = n[1];
	east = n[2];
	west = n[3];
	north = n[4];
	bottom = n[5];
}

int Dice::roll(char c) {
	if (c == 'S') {
		rollS();
	}
	else if (c == 'E') {
		rollE();
	}
	else if (c == 'W') {
		rollW();
	}
	else if (c == 'N') {
		rollN();
	}
}

int Dice::rollS() {
	int buf = top;
	top = north;
	north = bottom;
	bottom = south;
	south = buf;
	return top;
}

int Dice::rollE() {
	int buf = top;
	top = west;
	west = bottom;
	bottom = east;
	east = buf;
	return top;
}

int Dice::rollW() {
	int buf = top;
	top = east;
	east = bottom;
	bottom = west;
	west = buf;
	return top;
}

int Dice::rollN() {
	int buf = top;
	top = south;
	south = bottom;
	bottom = north;
	north = buf;
	return top;
}

void Dice::show() {
	cout << top << "\n";
}

Measured memory_bytes: 3104
#include<bits/stdc++.h>
 #include <ext/pb_ds/tree_policy.hpp>
 #include <ext/pb_ds/assoc_container.hpp>
 #include<chrono>
 using namespace std;
 using namespace std::chrono;      
 using namespace __gnu_pbds; 
 #define fastio     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
 #define fi         first
 #define se         second
 #define int         long long 
 #define pb         push_back
 #define emp        emplace_back
 #define vv(x)      vector<x>
 #define mp(x,y)    map<x,y>
 #define dq(x)      deque<x>
 #define pql(x)     priority_queue<x>
 #define pqs(x)     priority_queue<x,vv(x),greater<x> >
 #define M          1000000007
 #define forf(i,a,b) for(int i=a;i<b;i++)
 #define it(x)      x::iterator
 #define ll         long long 
 #define debug(...) fprintf(stderr, __VA_ARGS__), fflush(stderr)
 #define time__(d)  for(long blockTime = 0; (blockTime == 0 ? (blockTime=clock()) != 0 : false); debug("%s time : %.4fs", d, (double)(clock() - blockTime) / CLOCKS_PER_SEC))
 #define vii        vector<int>
 #define big        3e18
 #define sm         -2e9
 #define mkr        make_pair
 #define vpi        vector<pair<int,int> >
 #define pii        pair<int,int>
 #define rng        500005
 #define sz(x)      (int)x.size()
 #define rv(x)      reverse(x.begin(),x.end())
 #define out(x)     cout<<x.fi<<" "<<x.se<<endl;

//#define ordered_set tree<pii, null_type,less<pii>, rb_tree_tag,tree_order_statistics_node_update> 
  
void pr_init()
{
   
    #ifndef ONLINE_JUDGE
    freopen("gin.txt", "r", stdin);
    freopen("gout.txt", "w", stdout);
   
    #endif
}




void solve()
{
  
  int n;
  cin >> n;

  int dp[n+1] , h[n+1];
  
  

  forf(i,1,n+1) cin >> h[i];
  dp[1]=0;

  forf(i,2,n+1)
  {
    dp[i] = INT_MAX;
    if(i>2) dp[i] = min(dp[i] , dp[i-2]+abs(h[i]-h[i-2]));
    dp[i] = min(dp[i],dp[i-1]+abs(h[i]-h[i-1]));

  }

  cout<<dp[n];
}


int32_t main()
{
  pr_init();
  //fastio;
  
  auto start = high_resolution_clock::now(); 
 
  solve();
  auto stop = high_resolution_clock::now();
  auto duration = duration_cast<microseconds>(stop - start); 
   // cout << "Time taken by function: "
   //       << duration.count() << " microseconds" << endl; 

 }
      
      

Measured memory_bytes: 5204
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;++i)
typedef long long ll;
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 n;
   cin >> n;
   cout << pow(n,3)<<endl;
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define FOR(i, m, n) for (ll i = m; i < n; i++)
#define IFOR(i, m, n) for (ll i = n - 1; i >= m; i--)
#define REP(i, n) FOR(i, 0, n)
#define IREP(i, n) IFOR(i, 0, n)
#define FOREACH(x, a) for (auto&(x) : (a))
#define ALL(v) (v).begin(), (v).end()
#define SZ(x) ll(x.size())

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  vector<ll> s(n + 1, 0), t(m + 1, 0);
  REP(i, n) {
    ll a;
    cin >> a;
    s[i + 1] = s[i] + a;
  }
  REP(i, m) {
    ll a;
    cin >> a;
    t[i + 1] = t[i] + a;
  }

  ll ans = 0;
  FOR(i, 0, n + 1) {
    if (s[i] > k) {
      continue;
    }
    ll ok = 0, ng = m + 1;
    while (ok + 1 < ng) {
      ll mid = (ok + ng) / 2;
      (s[i] + t[mid] <= k ? ok : ng) = mid;
    }
    ans = max(ans, i + ok);
  }
  cout << ans << endl;
}

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

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

  int N, D;
  cin >> N >> D;
  int x = D * 2 + 1;
  if(N % x == 0){
    cout << N / x <<endl;
  } else{
    cout << N / x + 1 <<endl;
  }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<(int)(n);i++)
#define all(x)    (x).begin(),(x).end()
typedef long long ll;
const int MOD = (int)1e9 + 7;

int main(){
  int n,k;
  cin>>n>>k;
  vector<vector<int> > bi(n+10,vector<int>(n+10,0));
  rep(i,n+1){
    bi[i][0] = 1;
    bi[i][i] = 1;
  }
  for(int i=1;i<n+1;i++)
    for(int j=1;j<i;j++)
      bi[i][j] = (bi[i-1][j] + bi[i-1][j-1]) % MOD;

  for(int i=1;i<=k;i++) cout<<((ll) bi[k-1][i-1]*bi[n-k+1][i])%MOD<<endl;
}



Measured memory_bytes: 16128
import sys
import numpy as np

input = sys.stdin.readline

n, k = map(int, input().split())
h = [int(i) for i in input().split()]

dp = np.zeros(n, dtype=int)
h = np.array(h)


for i in range(1, n):
    start = max(0, i-k)
    dp[i] = min(dp[start: i] + np.abs(h[i] - h[start: i]))

print(dp[n-1])

Measured memory_bytes: 23052
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<cstring>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
#define rep(i, n) for(int i=0;i<n;++i)
#define rrep(i, n) for(int i=n;i>=0;--i)
const int inf=1e9+7;
const ll mod=1e9+7;
const ll mod1=998244353;
const ll big=1e18;
const double PI=2*asin(1);

int main() {
  int N, M;
  cin>>N>>M;
  ll a[N];
  for(int i=0;i<N;++i) cin>>a[i];
  vector<vector<int> > edge(N);
  int x, y;
  for(int i=0;i<M;++i) {
    cin>>x>>y;
    edge[x].push_back(y);
    edge[y].push_back(x);
  }
  map<int, int> amap;
  int num = 1;
  queue<int> que;
  int state;
  for(int i=0;i<N;++i) {
    if(amap[i]==0) {
      que.push(i);
      while(!que.empty()) {
        state = que.front();que.pop();
        if(amap[state]>0) continue;
        amap[state] = num;
        for(int j=0;j<edge[state].size();++j) {
          if(amap[edge[state][j]]>0) continue;
          que.push(edge[state][j]);
        }
      }
      num++;
    }
  }
  num--;
  if(num==1) cout<<0<<endl;
  else {
    vector<vector<ll> > arr(num);
    for(int i=0;i<N;++i) {
      arr[amap[i]-1].push_back(a[i]);
    }
    for(int i=0;i<num;++i) sort(arr[i].begin(), arr[i].end());
    priority_queue<pair<ll, int>, vector<pair<ll, int> >, greater<pair<ll, int> > > que;
    ll ans = 0;
    map<int, int> amap;
    for(int i=0;i<num;++i) {
      amap[i]++;
      ans += arr[i][0];
      for(int j=1;j<arr[i].size();++j) {
        que.push(mp(arr[i][j], i));
      }
    }
    pair<ll, int> state1;
    bool can = true;
    for(int i=num;i<2*(num-1);++i) {
      if(que.empty()) {
        can = false;
        break;
      }
      state1 = que.top();que.pop();
      if(amap[state1.se]==num-1) {
        i--;
        continue;
      }
      ans += state1.fi;
      amap[state1.se]++;
    }
    if(!can) cout<<"Impossible"<<endl;
    else cout<<ans<<endl;
  }
}


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

pattern = 0

for i in range(a + 1):
    for j in range(b + 1):
        for k in range(c + 1):
            if 500 * i + 100 * j + 50 * k == x:
                pattern += 1

print(pattern)

Measured memory_bytes: 3064
import java.util.LinkedList;
import java.util.List;
import java.util.Scanner;

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

        if (n == m) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }

    }

}


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

using namespace std;

#define DUMP(x) std::cerr << (#x) << " = " << (x) << "\n"
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define REP(i, k, n) for (int i = (k); i < (int)(n); ++i)
#define ALL(r) r.begin(), r.end()
#define YES puts("YES")
#define Yes puts("Yes")
#define NO puts("NO")
#define No puts("No")
#define IMP puts("IMPOSSIBLE")
#define Imp puts("Impossible")
#define imp puts("impossible")
#define M1 puts("-1")
#define pb push_back

template <typename T>
T dup(T x, T y)
{
    return (x + y - 1) / y;
};
template <typename A, size_t N, typename T>
inline void arrayFill(A (&array)[N], const T &val) { std::fill((T *)array, (T *)(array + N), val); }

using ll = int64_t;
using vint = vector<int32_t>;
using vvint = vector<vint>;
using vll = vector<ll>;
using vvll = vector<vll>;
using vstr = vector<string>;
using pint = pair<int32_t, int32_t>;
using pll = pair<ll, ll>;
using setint = set<int32_t>;
using setstr = set<string>;
using qint = queue<int32_t>;
using qpint = queue<pint>;

constexpr std::int32_t INF = 1001001001;
constexpr std::int64_t LINF = 1001001001001001001;

void Main()
{
    int n;
    cin >> n;

    vvint f(n, vint(10));
    vvint p(n, vint(11));

    rep(i, n)
    {
        rep(j, 10)
        {
            cin >> f[i][j];
        }
    }
    rep(i, n)
    {
        rep(j, 11)
        {
            cin >> p[i][j];
        }
    }

    ll score = -INF;
    rep(bit, (1 << 10))
    {
        ll cur_score = 0;
        vint cnt(n, 0);
        if (bit == 0)
            continue;
        rep(i, 10)
        {
            if (bit & (1 << i))
            {
                rep(j, n)
                {
                    if (f[j][i] == 1)
                    {
                        ++cnt[j];
                    }
                }
            }
        }
        rep(i, n)
        {
            cur_score += p[i][cnt[i]];
        }
        score = max(score, cur_score);
    }
    cout << score << endl;
}

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


Measured memory_bytes: 256
def ok(s):
    stack = []
    for c in s:
        if c in '([':
            stack.append(c)
        elif c in ')]':
            if len(stack) == 0: return False
            e = stack.pop()
            if (e+c) not in ('()','[]'):
                return False
    return False if stack else True

while True:
    S = input()
    if S == '.': break
    print('yes' if ok(S) else 'no')

Measured memory_bytes: 5580
#include <bits/stdc++.h>
using namespace std;
 
typedef pair<int,int> P;
int dx[8]={-1,-1,-1,0,0,1,1,1},dy[8]={-1,0,1,-1,1,-1,0,1};
bool check(int n, int m, int x, int y) {return (x>=0&&x<n&&y>=0&&y<m);}
 
int main() {
  int n,m;
  cin >> n >> m;
  string s[n];
  for(int i=0; i<n; i++) cin >> s[i];
  queue<P> que;
  int d[n][m],a[n][m];
  memset(d,0,sizeof(d));
  for(int i=0; i<n; i++) {
    for(int j=0; j<m; j++) {
      if(s[i][j]=='.') {
        que.push(P(i,j));
        a[i][j]=0;
      } else a[i][j]=s[i][j]-'0';
    }
  }
  int ans=0;
  while(!que.empty()) {
    P p=que.front();que.pop();
    ans=max(ans,d[p.first][p.second]);
    for(int i=0; i<8; i++) {
      int x=p.first+dx[i],y=p.second+dy[i];
      if(!check(n,m,x,y) || !a[x][y]) continue;
      a[x][y]--;
      if(!a[x][y]) {
        d[x][y]=d[p.first][p.second]+1;
        que.push(P(x,y));
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 10172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll n,k,i,x,sum=0;
  	cin>>n>>k;
  	vector<ll> a(n);
  	for(i=0;i<n;i++){
		cin>>x;
      	a[x-1]++;
    }
  
  	sort(a.begin(),a.end());
  	reverse(a.begin(),a.end());
  
  	for(i=k;i<n;i++){
      sum+=a[i];
      if(a[i]==0){
        break;
      }
    }
  
  cout<<sum<<endl;
}

Measured memory_bytes: 1792
#include "bits/stdc++.h"
#include <stdint.h>
 
#pragma optimize("O3")
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long double ld;
 
#define sync                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, b, a) for(ll i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define MP make_pair
const ll MOD = 1e9+7;
const ll INF = 1e9 + 7;
const int base = 2e5+1;
const int MAX =1e5+2;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 32000+5;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
ull k;
map<int, int> start_index;
int t[800000 + 47];
void build(vector<pair<int, int>> a, int v, int l, int r){
    if(l == r){
        t[v] = a[l].second;
    }else{
        int mid = (l+r)/2;
        build(a, v*2, l, mid);
        build(a, v*2 + 1, mid + 1, r);
        t[v] = max(t[v*2], t[v*2 + 1]);
    }
}
int get_max(int v, int tl, int tr, int l, int r){
        if(l > r){
            return -1;
        }
        if(l == tl && r == tr){
            return t[v];
        }
        int mid = (tl + tr)/2;
        return max(get_max(v*2, tl, mid, l, min(r, mid)), get_max(v*2+1, mid+1, tr, max(l, mid + 1 ), tr));
}
multiset<int> setHero;
int main()
{   
    int n;
    cin >> n;
    vector<int> monster(n+1);
    for(int i = 0;i<=n;i++){
        cin >> monster[i];
    }
    vector<int> hero(n);
    for(int i = 0;i<n;i++){
        cin >> hero[i];
    }
    long long res = 0;
    for(int i = 0;i<n;i++){
        int cur_r =(min(monster[i], hero[i]));
        hero[i]-=cur_r;
        res+=cur_r;
        if(hero[i] != 0){
            cur_r =(min(monster[i + 1], hero[i]));
            hero[i]-=cur_r;
            monster[i+1]-=cur_r;
            res+=cur_r;
        }
    }
    cout<<res;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define mod 1000000007
#define pb push_back
#define ll long long
#define mp make_pair
using namespace std;
vector<ll> a;
int main(){
	int n;
	cin>>n;
	for(int i=0;i<n;i++){
		ll x;
		cin>>x;
		a.pb(x);
	}
	sort(a.begin(),a.end());
	int fl=0;
	for(int i=0;i<n;i++){
		if(a[i]%2==1){
			fl=1;
		}
	}
	if(fl==1){
		cout<<"first"<<endl;
	}
	else{
		cout<<"second"<<endl;
	}
	return 0;
}

Measured memory_bytes: 1400
#dt = {} for i in x: dt[i] = dt.get(i,0)+1
import sys;input = sys.stdin.readline
inp,ip = lambda :int(input()),lambda :[int(w) for w in input().split()]

def lcs(X,Y):
    m,n = len(X),len(Y)
    L = [[0]*(n+1) for i in range(m+1)]
    for i in range(1,m+1):
        for j in range(1,n+1):
            if X[i-1] == Y[j-1]:
                L[i][j] = L[i-1][j-1] + 1
            else:
                L[i][j] = max(L[i-1][j], L[i][j-1])
    size = L[m][n] 
    lcs = []
    i,j = m,n
    while i > 0 and j > 0:
        if X[i-1] == Y[j-1]: 
            lcs.append(X[i-1]) 
            i-=1
            j-=1
        elif L[i-1][j] > L[i][j-1]: 
            i-=1
        else: 
            j-=1
    return ''.join(lcs[::-1])

s = input().strip()
t = input().strip()
ans = lcs(s,t)
print(ans)
    


Measured memory_bytes: 144320
//Author: Rahul Purohit

#include<bits/stdc++.h>
#define vi vector<int>
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define ll  long long int
#define pi pair<ll,ll>
#define f first
#define mp make_pair
#define mod 1000000007
#define s second
#define pb push_back
#define mp make_pair
#define N 100001
using namespace std;
int gcd(int a, int b)
{
	if(b==0)
		return a;
	else
		return (b,a%b);
}
/*ll isp[N]={1};
void sieve(int n)
{
	isp[0]=isp[1]=0;
	for(int i=2;i<=n;i++)
	{
		if(isp[i]==1)
		{
			for(int j=i*i;j<=n;j+=i)
			{
				isp[j]==0;
			}
		}
	}
}*/
ll pow(int x,int  y,int m)
{
	ll ans=1;
	while(y!=0)
	{
		if(y%2==1)
		{
			ans=(ans*x)%m;
		}
		x=(x*x)%m;
		y/=2;
	}
	return ans;
}
template <class x>
void swap(x &a,x &b)
{
	x tp;
	tp=a;
	a=b;
	b=tp;
}
int main(void)
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);

    ll a,b,c;
    cin>>a>>b>>c;
    if(a==b&&b==c)
    {
        cout<<"Yes\n";
    }
    else
    {
        cout<<"No\n";
    }
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
using namespace std;
int main(){
    int w,h;
    while(scanf("%d%d",&w,&h),w,h){

        int dp[128][128][2][2] ={{{{0}}}};

        dp[1][1][0][0] = 1;
        dp[1][1][0][1] = 1;

        for(int j = 1;j <= h; j++){
            for(int i = 1;i <= w; i++){
                dp[j][i][0][0] %= 100000;
                dp[j][i][0][1] %= 100000;
                dp[j][i][1][0] %= 100000;
                dp[j][i][1][1] %= 100000;

                dp[j][i+1][0][0] += dp[j][i][1][0];
                dp[j+1][i][0][1] += dp[j][i][1][1];
                dp[j][i+1][0][0] += dp[j][i][0][0];
                dp[j+1][i][0][1] += dp[j][i][0][1];

                if(i == 1 && j == 1) continue;

                dp[j+1][i][1][1] += dp[j][i][0][0];
                dp[j][i+1][1][0] += dp[j][i][0][1];
            }
        }
        int ans = 0;
        ans = dp[h][w][0][0]+dp[h][w][0][1]+dp[h][w][1][0]+dp[h][w][1][1];
        printf("%d\n",ans%100000);
    }
    return 0;
}

Measured memory_bytes: 1292
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>

int main(void){
    int i,N,s[4];
    scanf("%d",&N);
    char c;
    for(i=0;i<N;i++){
        scanf("%c ",&c);
        if(c == 'P'){
            s[0] = 1;
        }else if(c == 'W'){
            s[1] = 1;
        }else if(c == 'G'){
            s[2] = 1;
        }else if(c == 'Y'){
            s[3] = 1;
        }
    }
    int n=0;
    for(i=0;i<4;i++){
        n+=s[i];
    }
    if(n==3){
        printf("Three\n");
    }else{
        printf("Four\n");
    }
    return 0;
}


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

int main() {
    string W, T;
    
    cin >> W;
    
    for (int i = 0; i < W.size(); i++) {
        if ('A' <= W[i] && W[i] <= 'Z') W[i] += 'a' - 'A';
    }
    
    int count = 0;
    while(cin >> T) {
        if (T == "END_OF_TEXT") break;
        for (int i = 0; i < T.size(); i++){
            if ('A' <= T[i] && T[i] <= 'Z') T[i] += 'a' - 'A';
        }
        if (W == T) count++;
    }
    
    printf("%d\n", count);
}


Measured memory_bytes: 3276
#include<iostream>
#include<vector>
#include<cstdio>
#include<algorithm>
typedef long long ll;
int main()
{
	int a[4] = {1,2,4,8};
	ll c[4];
	ll t,t1;
	for(t=0;t<4;t++)
		scanf("%lld",&c[t]);
	for(t=0;t<4;t++)
	{
		for(t1=t+1;t1<4;t1++)
		{
			if(c[t]*a[t1] > c[t1]*a[t])
			{
				ll ex;
				ex = a[t];
				a[t] = a[t1];
				a[t1] = ex;
				ex = c[t];
				c[t] = c[t1];
				c[t1] = ex;
			}
		}
	}
	ll n;
	scanf("%d",&n);
	n *= 4;
	ll v=0;
	for(t=0;t<4;t++)
	{
		v += n/a[t]*c[t];
		n %= a[t];
	}
	printf("%lld\n",v);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int a = sc.nextInt();
      	int b = sc.nextInt();
		// スペース区切りの整数の入力
		String answer;
      	if(a+b==15)answer="+";
      	else if(a*b==15)answer="*";
      	else answer="x";
		
		// 出力
		System.out.println(answer);
	}
}

Measured memory_bytes: 23764
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < n; i++)
typedef long long ll;
using namespace std;
#define llMAX numeric_limits<long long>::max()
#define intMAX numeric_limits<int>::max()
#define d_5 100000
#define d9_7 1000000007
#define vll vector<vector<long long>>
#define vl vector<long long>
#define vi vector<int>
#define vii vector<vector<int>>
#define pb push_back
#define pf push_front
int main(void){
  string s;
  cin>>s;
  int x,y;
  cin>>x>>y;
  vi xs={};
  vi ys ={};
  int mode=0;
  int tmp=0;
  rep(i,s.size()){
    if(s[i]=='F'){
      tmp++;

    }else{
      if(mode==0){
        xs.pb(tmp);
      }else{
        ys.pb(tmp);
      }
      tmp=0;
      mode++;
      mode%=2;
    }
  }
  if(mode==0){
    xs.pb(tmp);
  }else{
    ys.pb(tmp);
  }
  if(s[0]=='F'){
    x-=xs[0];
    xs.erase(xs.begin());
  }
  vi dp1=vi(16000,0);
  vi dp2=vi(16000,0);
  int origin = 8000;
  dp1[origin]=1;
  rep(i,xs.size()){
    dp2=dp1;
    dp1=vi(16000,0);
    rep(j,16000){
      if(dp2[j]==1){
        dp1[j+xs[i]]=1;
        dp1[j-xs[i]]=1;
      }
    }
  }
  if(dp1[origin+x]==0){
    cout<<"No"<<endl;
    return 0;
  }
  dp1=vi(16000,0);
  dp2=vi(16000,0);
  dp1[origin]=1;
  rep(i,ys.size()){
    dp2=dp1;
    dp1=vi(16000,0);
    rep(j,16000){
      if(dp2[j]==1){
        dp1[j+ys[i]]=1;
        dp1[j-ys[i]]=1;
      }
    }
  }
  if(dp1[origin+y]==0){
    cout<<"No"<<endl;
    return 0;
  }
  cout<<"Yes"<<endl;
  return 0;
}

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

#define ll long long
#define Fi first
#define Se second
#define Pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvp vector<vector<pair<int,int>>>

const int INF = 1e9;
const int MOD = 1e9+7;

#define all(v) v.begin(),v.end()
#define output_s(a) printf("%s\n",(a).c_str())

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define Rep(i,n,m) for(int i=(int)(n);i<(int)(m);i++)
#define RepS(i,n,m) for(int i=(int)(n);i<=(int)(m);i++)
#define RRepS(i,n,m) for(int i=(int)(n);i>=(int)(m);i++)
#define RepA(x) for(auto &item:(x))

void CINT(){}
template <class Head,class... Tail>
void CINT(Head&& head,Tail&&... tail){
    cin>>head;
    CINT(move(tail)...);
}    
#define CIN(...) int __VA_ARGS__;CINT(__VA_ARGS__)
#define LCIN(...) ll __VA_ARGS__;CINT(__VA_ARGS__)
#define SCIN(...) string __VA_ARGS__;CINT(__VA_ARGS__)

template<typename TypeInt> //最大公約数
TypeInt GCD(TypeInt a,TypeInt b){
    if(a%b==0) return b;
    else return GCD(b,a%b);
}
template<typename TypeInt> //最小公倍数
TypeInt LCM(TypeInt a,TypeInt b){
    return a*b/GCD(a,b);
}

//library----------------------------------------------

//string->intにsplit
void split_int(vector<int> &v,string s){
    for(auto item:s){
        v.emplace_back(item-'0');
    }
}

signed main(){
    SCIN(s);
    vi v;
    split_int(v,s);
    if(v[0]+v[1]+v[2]+v[3]==7) printf("%d+%d+%d+%d=7\n",v[0],v[1],v[2],v[3]);
    else if(v[0]+v[1]+v[2]-v[3]==7) printf("%d+%d+%d-%d=7\n",v[0],v[1],v[2],v[3]);
    else if(v[0]+v[1]-v[2]+v[3]==7) printf("%d+%d-%d+%d=7\n",v[0],v[1],v[2],v[3]);
    else if(v[0]-v[1]+v[2]+v[3]==7) printf("%d-%d+%d+%d=7\n",v[0],v[1],v[2],v[3]);
    else if(v[0]+v[1]-v[2]-v[3]==7) printf("%d+%d-%d-%d=7\n",v[0],v[1],v[2],v[3]);
    else if(v[0]-v[1]+v[2]-v[3]==7) printf("%d-%d+%d-%d=7\n",v[0],v[1],v[2],v[3]);
    else if(v[0]-v[1]-v[2]+v[3]==7) printf("%d-%d-%d+%d=7\n",v[0],v[1],v[2],v[3]);
    else if(v[0]-v[1]-v[2]-v[3]==7) printf("%d-%d-%d-%d=7\n",v[0],v[1],v[2],v[3]);

    return 0;
}

Measured memory_bytes: 256
n=int(input())
t=[int(i) for i in input().split()]
x=t
m=int(input())
px=[]
for i in range(m):
    px.append([int(j) for j in input().split()])
#print("____")
#print("px==",px)
#print("x==",x)
#print("____")
for i in range(m):
    c=t[px[i][0]-1]
    t[px[i][0]-1]=px[i][1]
    print(sum(t))
    t[px[i][0]-1]=c

Measured memory_bytes: 3064
import sys
readline = sys.stdin.readline

N,M = map(int,readline().split())
S = list(map(int,readline().split()))
T = list(map(int,readline().split()))
DIV = 10 ** 9 + 7

# dp[i][j] = Sのi文字目、Tのj文字目まで見たときの組み合わせ総数
# dp[i][j] に対してはdp[i - 1][j - 1]の数がdp[i - 1][j]からきた数とdp[i][j - 1]から来たのでダブルカウントされている
# 従い、
# dp[i][j] += dp[i][j - 1]
# dp[i][j] += dp[i - 1][j]
# をした後で、ダブルカウント分を
# dp[i][j] -= dp[i - 1][j - 1]
# 引く(i > 0 and j > 0)
# S[i] == T[j]の場合、dp[i - 1][j - 1]から直接遷移することが出来るので、この通り数を足したうえでダブルカウントを引く
# ので、結局S[i] == T[j]の場合はダブルカウント分を引かないのと同じ挙動になる

dp = [[0] * (M + 1) for i in range(N + 1)]

for i in range(N + 1):
  dp[i][0] = 1
for j in range(M + 1):
  dp[0][j] = 1

for i in range(1, N + 1):
  for j in range(1, M + 1):
    dp[i][j] += dp[i][j - 1]
    dp[i][j] += dp[i - 1][j]
    if S[i - 1] != T[j - 1]:
      dp[i][j] -= dp[i - 1][j - 1]
    dp[i][j] %= DIV

print(dp[-1][-1])

Measured memory_bytes: 98700
#include<stdio.h>
int main(){
  int H,W,i,j;
  while(1){
 scanf("%d %d\n",&H,&W);
 if(H==0 && W==0)break;
 else {for(i=0;i<H;i++){
    printf("#");
    for(j=1;j<W-1;j++){
      if(i==0 ||i==H-1){
	printf("#");
      }else {
	printf(".");
      }
    }
    printf("#");
    printf("\n");
  }
 }
 printf("\n");
  }
  return 0;
}

Measured memory_bytes: 576
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt(), b = sc.nextInt();
        if (Math.abs(a - b) > 1) System.out.println(":(");
        else System.out.println("Yay!");
    }
}

Measured memory_bytes: 21844
import sys
 
n = int(input())
minv = int(input())
maxv = -1000000000
 
for r in map(int,sys.stdin.readlines()):
  m = r-minv
  if maxv < m: 
    maxv = m
    if m < 0: minv = r
  elif m < 0: minv = r
 
print(maxv)

Measured memory_bytes: 21832
rows, cols, k = map(int, input().split())
items = [[] for _ in range(rows+1)]
best = [0]*(cols+1)
for _ in range(k):
	r, c, v = map(int, input().split())
	items[r].append([c, v])
for i in range(rows+1):
	items[i].sort()
ans = 0
for r in range(1, rows+1):
	dp = []
	best1, best2 = 0, 0
	Row = items[r]
	for c, v in Row:
		v1 = best[c] + v
		v2 = best1 + v
		v3 = best2 + v
		V = max(v1, v2, v3)
		dp.append(V)
		if v1 > best1:
			best1 = v1
		if v2 > best2:
			best2 = v2
		if ans < V:
			ans = V
	for j in range(len(dp)):
		if best[Row[j][0]] < dp[j]:
			best[Row[j][0]] = dp[j]
	for j in range(2, cols+1):
		if best[j] < best[j-1]:
			best[j] = best[j-1]
print(ans)


Measured memory_bytes: 100824
using System;
using System.Collections;
using System.Collections.Generic;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;

namespace AtCoder.ABC069
{
    class Program
    {
        static void Main()
        {
            int[] inputs = Console.ReadLine().Split(' ')
                        .Select(int.Parse)
                        .ToArray();
            int H = inputs[0];
            int W = inputs[1];
            int n = int.Parse(Console.ReadLine());
            int[] a = Console.ReadLine().Split(' ')
                        .Select(int.Parse)
                        .ToArray();
            var onelinec = new List<int>();
            for (int i = 0; i < n; i++)
            {
                var tmpc = Enumerable.Repeat(i + 1, a[i]);
                onelinec.AddRange(tmpc);
            }
            Console.Error.WriteLine(string.Join(" ", onelinec));
            var c = new int[H, W];
            for (int i = 0; i < H * W; i++)
            {
                if ((i / H) % 2 == 0)
                {
                    c[i % H, i / H] = onelinec[i];
                }
                else
                {
                    c[H - 1 - (i % H), i / H] = onelinec[i];
                }
            }
            for (int i = 0; i < H; i++)
            {
                for (int j = 0; j < W; j++)
                {
                    if (j != 0) Console.Write(" ");
                    Console.Write(c[i, j]);
                }
                Console.WriteLine();
            }
        }
    }
}

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

using namespace std;
 
int main(){
    string s;
 
    cin >> s;

    int a = s.size();
    int z = 0;

    for(int i = 0; i < s.size(); i++){
        if(s[i] == 'A' && i <= a){
            a = i;
        }
        if(s[i] == 'Z' && i >= z){
            z = i;
        }
    }

    cout << z - a + 1 << endl;

    return 0;
}


Measured memory_bytes: 640