akhauriyash/Code-Regression huggingface dataset:
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF =1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(),(x).end()
#define pb push_back
int main(){
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    cout << max(0, min(b, d) - max(a, c));
    return 0;
}

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

int main() {
    int N;
    std::cin >> N;

    for (int i = 1; i <= 9; ++i) {
        for (int j = 1; j <= 9; ++j) {
            if (i * j == N) {
                std::cout << "Yes" << std::endl;
                return 0;
            }
        }
    }

    std::cout << "No" << std::endl;

    return 0;
}


Measured memory_bytes: 256
##create with UTF-8

n = int( input() )
da=list(map(int, input(). split()))
li=[da[i]%(n+1) for i in range(n)]
su=0
ans=0
for i in range(n):
	su+=da[i]
for i in range(n):
	div=(n-1)-(da[i]%(n+1))
	now=0
	ju=True
	for j in range(n):
		if (n+1+div+da[j])%(n+1)==n:
			ju=False
			break
		now+=(n+1+div+da[j])%(n+1)
	if ju and su >= now:
		#print(now)
		ans = max(ans,now)
print(su-ans)

Measured memory_bytes: 3064
n=int(input())

Renzoku=0
icchiAri=0
for i in range(n):
  a,b=map(int,input().split())
  if a==b:
    Renzoku+=1
  else:
    Renzoku=0
    
  if Renzoku==3:
    icchiAri=1

if icchiAri==0:
  print("No")
else:
  print("Yes")

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

using namespace std;

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

  int ans=0;
  for (int i = 0; i <= a; i++) {
    for (int j = 0; j <= b; j++) {
      for (int k = 0; k <= c; k++) {
        if(500*i + 100*j + 50*k == x) {
          ans++;
        }
      }
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
const double EPS = 1e-8;
#define Scan(a) int a;scanf("%d", &a);
#define ScanS(a) char a[500];scanf("%s", a);
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}


int main() {
	int n, f;
	cin >> n >> f;
	int an = 0;
	map<pair<string,string>, int> cou;
	REP(i, n) {
		int m;
		scanf("%d", &m);
		vector<string> c(m);
		char str[31];
		REP(i, m) {
			scanf("%s", str);
			c[i] = str;
		}

		REP(i, m) {
			rep(j, i + 1, m) {
				if (c[i] > c[j])
					cou[{c[j], c[i]}]++;
				else
					cou[{c[i], c[j]}]++;
			}
		}
	}

	for (auto itr : cou) {
		if (itr.second >= f) {
			an++;
		}
	}
	cout << an << endl;
	for (auto itr : cou) {
		if (itr.second >= f) {
			printf("%s %s\n", itr.first.first.c_str(), itr.first.second.c_str());
		}
	}
	return 0;
}

Measured memory_bytes: 3612
import math
a, b, x = map(int, input().split())
if x < a**2*b/2:
    theta = math.atan(a*b**2/2/x)/math.pi*180
else:
    theta = math.atan(2*(a**2*b-x)/(a**3))/math.pi*180
print('{:.12g}'.format(theta))

Measured memory_bytes: 3060
#include <stdio.h>
int main(){
	int a=0,b=0,c=0,i,n,tmp;
	for(i=1;i<=10;i++){
		scanf("%d",&n);
		if(a<n){
			c=b;
			b=a;
			a=n;
		}
		else if(b<n){
			c=b;
			b=n;
		}
		else if(c<n){
			c=n;
		}
	}
	printf("%d\n%d\n%d\n",a,b,c);
	return 0;
}


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

int main() {
  int n;
  while(cin>>n,n){
    string s[n],t[n];
    for(int i=0;i<n;i++){
      cin>>s[i];
      t[i]=s[i][0];
      for(int j=1;j<s[i].size();j++){
        char c=s[i][j-1];
        if(c=='a'||c=='i'||c=='u'||c=='e'||c=='o')t[i]+=s[i][j];
      }
    }
    int k;
    for(k=1;k<51;k++){
      set<string> se;int f=1;
      for(int i=0;i<n;i++){
        string r=t[i].substr(0,min((int)t[i].size(),k));
        if(se.count(r)) f=0;se.insert(r);
      }
      if(f) break;
    }
    cout<<(k<51?k:-1)<<endl;
  }
  return 0;
}


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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

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

void solve(long long X, long long Y, long long A, long long B, long long C, std::vector<long long> p, std::vector<long long> q, std::vector<long long> r) {
    sort(rall(p));
    sort(rall(q));
    sort(rall(r));

    priority_queue<int, vector<int>, greater<int>> pq1, pq2;
    rep(i, X) pq1.emplace(p[i]);
    rep(i, Y) pq2.emplace(q[i]);

    rep(i, r.size()) {
        int p1 = pq1.top();
        int p2 = pq2.top();

        if (r[i] > p1 and r[i] > p2) {
            if (p1 > p2) {
                pq2.pop();
                pq2.emplace(r[i]);
            } else {
                pq1.pop();
                pq1.emplace(r[i]);
            }
        } else if (r[i] > p1) {
            pq1.pop();
            pq1.emplace(r[i]);
        } else if (r[i] > p2) {
            pq2.pop();
            pq2.emplace(r[i]);
        }
    }

    int ans = 0;
    while (!pq1.empty()) {
        ans += pq1.top();
        pq1.pop();
    }
    while (!pq2.empty()) {
        ans += pq2.top();
        pq2.pop();
    }
    cout << ans << endl;
}

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long X;
    scanf("%lld", &X);
    long long Y;
    scanf("%lld", &Y);
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    std::vector<long long> p(A);
    for (int i = 0; i < A; i++) {
        scanf("%lld", &p[i]);
    }
    std::vector<long long> q(B);
    for (int i = 0; i < B; i++) {
        scanf("%lld", &q[i]);
    }
    std::vector<long long> r(C);
    for (int i = 0; i < C; i++) {
        scanf("%lld", &r[i]);
    }
    solve(X, Y, A, B, C, std::move(p), std::move(q), std::move(r));
    return 0;
}


Measured memory_bytes: 4852
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
//const int64 INF = 1LL << 58;
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 (a>b) { a=b; return 1; } return 0; }


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

    int n; cin >> n;
    vei v(n); rep(i,n) cin >> v[i];
    ll sum = acc(all(v), 0LL);
    int ma = maxel(v);
    int mi = minel(v);
    cout << mi << " " << ma << " " << sum << endl;


    
}


Measured memory_bytes: 3208
#include <iostream>
#include <string>
#include <vector>
#include <climits>
#include <set>
#include <algorithm>
#include <unordered_map>
#include <queue>
#include <iomanip>
#include <map>
#include <utility>
#include <numeric>
#include <chrono>
#include <ctime>
#include <bitset>
#include <iterator>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define P pair<long long, int>
#define debug(x) cerr << #x << ": " << x << ", "
#define debugln(x) cerr << #x << ": " << x << '\n'

using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

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

  int n; cin >> n;
  int nnn = 3*n;
  vector<ll> a(nnn);
  rep(i, nnn) {
    cin >> a[i];
  }
  sort(a.rbegin(), a.rend());
  ll ans = 0;
  rep(i, 2*n) {
    if (i&1) {
      ans += a[i];
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 2560
n,k = map(int,input().split())
s = input()
li = [0]
count = 1

for i in range(n-1):
    if s[i] != s[i+1]:
        li.append(count)
    count += 1
li.append(count)

m = len(li)

if s[0] == '1':
    li.append(li[-1])
    li.append(li[-1])
    t = int(m/2-1)
    if k >= t:
        print(n)
    else:
        max1 = 0
        for i in range(t-k+2):
            max1 = max(li[2*(i+k)+1] - li[2*i],max1)
        print(max1)
else:
    li.append(li[-1])
    t = int(m/2)
    if k >= t:
        print(n)
    else:
        max1 = li[2*k]
        for i in range(t-k):
            max1 = max(li[2*(i+k+1)] - li[2*i+1],max1)
        print(max1)


Measured memory_bytes: 7160
#!/usr/bin/env python3

import sys
# from IPython import embed

N, K, Q = map(int, input().split(" "))

A = []
for i in range(0, Q):
  A.append(int(input()))

wins = [0] * N
for i in A:
  wins[i - 1] = wins[i - 1] + 1

# sys.stdin = open('/dev/tty')
# embed()

for i in range(0, N):
  score = K - Q + wins[i]
  if score > 0:
    print("Yes")
  else:
    print("No")


Measured memory_bytes: 8592
import java.util.Map;
import java.util.Scanner;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ

		Scanner sc = new Scanner(System.in);

		int n = Integer.parseInt(sc.nextLine());
		int max = 0;
		Map<String, Integer> map = new TreeMap<>();

		for (int i = 0; i < n; i++) {

			String n1 = sc.nextLine();
			int val = map.containsKey(n1) ? map.get(n1) + 1 : 1;
			map.put(n1, val);
			max = Math.max(max, val);

		}

		for (var entry : map.entrySet()) {
			if (entry.getValue() == max) {
				System.out.println(entry.getKey());
			}
		}
	}

}


Measured memory_bytes: 79616
#include<iostream>
using namespace std;
int main(){
	char a,b;
	cin>>a>>b;
	if(a=='H'&&b=='H'){
		cout<<"H"<<endl;
	}
    
	if(a=='H'&&b=='D'){
		cout<<"D"<<endl;
	}
    
	if(a=='D'&&b=='H'){
		cout<<"D"<<endl;
	}
    
	if(a=='D'&&b=='D'){
		cout<<"H"<<endl;
	}
}

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

int main() {
    int a,b; cin>>a>>b;
    string s; cin>>s;
    for(int i=0;i<a+b+1;i++){
       if(i<a){
           if(!(s[i]>='0'&&s[i]<='9')){
            cout<<"No"<<endl;
            return 0;
        }
       }
      else if(i==a){
           if(s[i]!='-'){
               cout<<"No"<<endl;
               return 0;
           }
       }
       else {
           if(!(s[i]>='0'&&s[i]<='9')){
               cout<<"No"<<endl;
               return 0;
           }
       }

    }
    cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define X first
#define Y second
#define mp make_pair
typedef pair <int, int> pii;
typedef long long cc;
const int N = 200005, oo = 1000 * 1000 * 1000;
int a[N], n;
int main() {
    ios_base :: sync_with_stdio(false); cin.tie(0);
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    int pos = n;
    while (pos > 0) {
        cout << a[pos] << " ";
        pos -= 2;
    }
    if (n % 2 == 0) pos = 1; else pos = 2;
    while (pos <= n) {
        cout << a[pos] << " ";
        pos += 2;
    }
    return 0;
}


Measured memory_bytes: 2944
n = int(input())
a = list((map(int,input().split())))

def __main__():
    ans = 1
    if(0 in a):
        print(0)
        return
    else:
        for i in a:
            ans *= i
            if(ans > 10**18):
                print(-1)
                return
        print(ans)
        return

if(__name__=="__main__"):
    __main__()

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

A = list(map(int,input().split()))[:N]

def J(x,y):
    ans = 1
    for i in range(y):
        ans *= x
    return ans

L = len(A)
E = len(list(filter(lambda x:x%2==0,A)))

print(J(3,L)-J(2,E))

Measured memory_bytes: 3060
#include<iostream>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
int main()
{
    int x;
    cin>>x;
    int a=0;
    if(x/500!=0)
    {
        a=x/500;
        x=x-500*a;
    }
    int b=0;
    if(x/5!=0)
    {
        b=x/5;
    }
    
    cout<<1000*a+5*b<<endl;

    return 0;
}

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

#pragma GCC target("avx")
#pragma GCC optimize("O3")
#pragma GCC optimize("unroll-loops")

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, s, n) for (int i = (s); i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define debug(x) cerr << #x << ": " << x << '\n'

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

const long long INF = 3e18 + 12;
const int inf = 1e9;

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

  int n;
  cin >> n;

  ll ans = 0;

  rep(i, n) {
    int a, b;
    cin >> a >> b;
    ans += (b - a) + 1;
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
count = 0
for i in range(N):
  if B[i] >= A[i]:
    s = B[i] - A[i]
    count += A[i]
    A[i] = 0
    if s >= A[i + 1]:
      count += A[i + 1]
      A[i + 1] = 0
    else:
      count += s
      A[i + 1] -= s
  else:
    count += B[i]
    A[i] -= B[i]
print(count)

Measured memory_bytes: 18476
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<queue>
#include<cstdio>
#include<string>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
#define inf 0x3f3f3f3f
using namespace std;

int a[100005], sum[100005], b[100005], n;
long long t1, t2;

void ms(int l, int r)
{
	if (l == r) return;
	int m = (l + r) >> 1;
	ms(l, m);
	ms(m + 1, r);
	int x = l, y = m + 1, z = l;
	while ((x <= m) && (y <= r))
	{
		if (sum[x] < sum[y]) b[z++] = sum[x++];
		else
		{
			t2 += x - l;
			b[z++] = sum[y++];
		}
	}
	while (x <= m) b[z++] = sum[x++];
	while (y <= r)
	{
		t2 += x - l;
		b[z++] = sum[y++];
	}
	for (int i = l; i <= r; i++) sum[i] = b[i];
}

bool check(int x)
{
	t2 = 0;
	for (int i = 1; i <= n; i++) sum[i] = sum[i - 1] + (a[i] <= x ? 1 : -1);
	ms(0, n);
	return t2 >= (t1 / 2 + 1);
}

int main()
{
	int l = inf, r = -inf;
	scanf("%d", &n);
	for (int i = 1; i <= n; i++)
	{
		scanf("%d", &a[i]);
		l = min(l, a[i]);
		r = max(r, a[i]);
		t1 += i;
	}
	while (l < r)
	{
		int m = (l + r) >> 1;
		if (check(m)) r = m;
		else l = m + 1;
	}
	printf("%d", r);
	return 0;
}

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

using namespace std;

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

typedef vector<int> vi;
typedef long long ll;

void solve() {
  int N;
  string S, T;
  cin >> N >> S >> T;
  for (int i = 0; i < N; i++) {
    cout << S[i] << T[i];
  }
  cout << endl;
}

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

  solve();

  return 0;
}


Measured memory_bytes: 256
N, M = map(int, raw_input().split())
s = [[int(t)-1 for t in raw_input().split()[1:]] for _ in range(M)]
p = map(int, raw_input().split())

ans = 0
for b in range(1<<N):
  ok = True
  for i in range(M):
    c = 0
    for t in s[i]:
      if b>>t&1:
        c += 1
    if c%2!=p[i]:
      ok = False
  if ok:
    ans += 1
print ans


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

string S;

void solve(){
    int n=S.size();
    set<string> cnt;
    for (int i=0;i<n;++i){
        string T=S.substr(0,i),U=S.substr(i,n-i);
        for (int j=0;j<2;++j){
            string V=T;
            if (j) reverse(V.begin(),V.end());
            for (int k=0;k<2;++k){
                string W=U;
                if (k) reverse(W.begin(),W.end());
                cnt.emplace(V+W);
                cnt.emplace(W+V);
            }
        }
    }
    cout << cnt.size() << '\n';
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int m; cin >> m;
    for (;m--;){
        cin >> S;
        solve();
    }
}


Measured memory_bytes: 3296
// D.

#include <iostream>
#include <sstream>
#include <algorithm>
#include <vector>

using namespace std;

typedef long long LL;

static LL f(LL x) {
/*
	switch (x & 3) {
	case 0:
		return x;
	case 1:
		return 1;
	case 2:
		return x | 1;
	default:
		return 0;
*/
	LL r = 0;
	for (LL i = max(0LL, ((x - 4) | 3) + 1); i <= x; ++i) {
		r ^= i;
	}
	return r;
}

int main(int argc, char *argv[]) {
	LL a, b;
	cin >> a >> b;
	LL ans = f(b) ^ f(a - 1);
	cout << ans << endl;
	return 0;
}


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

int main(){
  ll n, q, sum = 0;
  cin >> n;
  vector<int> vec(100000, 0);
  rep(i, n){
    int temp;
    cin >> temp;
    vec[temp] += 1;
    sum += temp;
  }
  cin >> q;
  rep(i, q){
    int a, b;
    cin >> a >> b;
    sum += (b - a) * vec[a];
    cout << sum << endl;
    vec[b] += vec[a];
    vec[a] = 0;

  }
}


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

class dice{
public:
  dice(int* m);
  void putm(int* m);
  int* getm();
  int* getj();
  void rollDice(char s);
private:
  int m[6];
  int j[6];
};

dice::dice(int* m){
  for(int i=0; i<6; i++){
    this->m[i] = m[i];
    j[i] = m[i];
  }
}

void dice::putm(int* m){
  for(int i=0; i<6; i++) this->m[i] = m[i];
}

int* dice::getm(){
  return m;
}

int* dice::getj(){
  return j;
}

void dice::rollDice(char s){
  //cout << s << endl;
  if(s!='N' && s!='S' && s!='W' && s!='E'){
    cout << "your input: " << s << " roll miss!! " << endl;
  }

  else if(s=='N'){
    int buf=j[0];
    j[0]=j[1];
    j[1]=j[5];
    j[5]=j[4];
    j[4]=buf;
  }
  else if(s=='S'){
    int buf=j[0];
    j[0]=j[4];
    j[4]=j[5];
    j[5]=j[1];
    j[1]=buf;
  }
  else if(s=='W'){
    int buf=j[0];
    j[0]=j[2];
    j[2]=j[5];
    j[5]=j[3];
    j[3]=buf;
  }
  else if(s=='E'){
    int buf=j[0];
    j[0]=j[3];
    j[3]=j[5];
    j[5]=j[2];
    j[2]=buf;
  }
}

int main(){
  int m[6];
  string roll;
  for(int i=0; i<6; i++) cin >> m[i];

  cin >> roll;

  dice d(m);
  for(int i=0; i<roll.length(); i++){
    d.rollDice(roll[i]);
  }

  cout << d.getj()[0] << endl;

  return 0;
}



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

#define rep(n) for(int i=0;i<n;i++)
#define repp(j, n) for(int j=0;j<n;j++)
#define reppp(i, m, n) for(int i=m;i<n;i++)
#define all(c) c.begin(), c.end()
#define rall(c) c.rbegin(), c.rend()
#define MOD 1000000007
#define EPS 1e-9

using namespace std;

typedef long long ll;
typedef pair<ll, ll> Pll;
typedef pair<int, int> Pii;
struct edge{int from, to; ll cost;};

int n,m,a,b;
int is = 0, js = 0;
char ans[1000][1000];

void puta(int i, int j){
    if(
        a == 0 ||
        j+1 >= m ||
        ans[i][j] != '.' || ans[i][j+1] != '.'
    ) return;
    ans[i][j] = '<';
    ans[i][j+1] = '>';
    a--;
}

void putb(int i, int j){
    if(
        b == 0 ||
        i+1 >= n ||
        ans[i][j] != '.' || ans[i+1][j] != '.'
    ) return;
    ans[i][j] = '^';
    ans[i+1][j] = 'v';
    b--;
}

void solve(){
    for(int i=is;i<n-1;i+=2){
        for(int j=js;j<m-1;j+=2){
            if(a){
                puta(i, j);
                puta(i+1, j);
            }else if(b){
                putb(i, j);
                putb(i, j+1);
            }
        }
    }
}

void odd_a(int start){
    is = 1;
    for(int j=start;j<m;j+=2){
        puta(0, j);
    }
}

void odd_b(int start){
    js = 1;
    for(int i=start;i<n;i+=2){
        putb(i, 0);
    }
}

int main(){
    std::ios::sync_with_stdio(0); cin.tie(0);
    cin >> n >> m >> a >> b;
    int aa = a, bb = b;
    if(2*(a+b) > n*m){
        cout << "NO" << endl;
        return 0;
    }

    fill(ans[0], ans[n], '.');
    if(n%2){
        odd_a(0);
        if(m%2){
            odd_b(1);
        }
    }else if(m%2){
        odd_b(0);
    }
    solve();

    if((a||b) && n%2 && m%2){
        a = aa;
        b = bb;
        fill(ans[0], ans[n], '.');
        puta(0, 0);
        puta(2, 1);
        putb(0, 2);
        putb(1, 0);
        if(m-3 > 0){
            odd_a(3);
        }
        if(n-3 > 0){
            odd_b(3);
        }
        solve();
    }

    if(a || b){
        cout << "NO" << endl;
        return 0;
    }
    cout << "YES" << endl;
    rep(n){
        repp(j, m){
            cout << ans[i][j];
        }
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 2176
using System;

namespace atcoderA
{
    class MainClass
    {
        public static void Main(string[] args)
        {
            int X = int.Parse(Console.ReadLine());
            int A = int.Parse(Console.ReadLine());
            int B = int.Parse(Console.ReadLine());
            Console.WriteLine(X - A - (B * ((X - A) / B)));
        }
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
ll a,b,c,d;
int main()
{
	cin>>a>>b>>c>>d;
	ll x1=a*c,x2=a*d,x3=b*c,x4=b*d;
	ll ans1=max(x1,x2),ans2=max(x3,x4);
	cout<<max(ans1,ans2)<<endl;
	return 0;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(ll i = 0; i < (n); ++i)
#define repA(i, a, n) for(int  i = a; i <= (n); ++i)
#define all(x) x.begin(), x.end()
#define sz(x) (int) (x).size()
#define fill(a) memset(a, 0, sizeof(a))
#define fst first
#define snd second
#define mp make_pair
#define pb push_back
#define endl '\n'
#define init(n) int n;cin>>n;int a[n];rep(i,n)cin>>a[i];
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long int> vll;
typedef vector<pii> vii;
ll p=1000000007;
ll const N=1e6+5;
int main() {
  
    cin.sync_with_stdio(0); cin.tie(0);
    cin.exceptions(cin.failbit);
    int T;T=1;
    // cin>>T;
    while(T--){
   		int  h,n;
   		cin>>h>>n;
   		int s=0;
   		rep(i,n){int x;
   			cin>>x;s=s+x;	
   		}
   		string ans="Yes";
   		if(s<h)ans="No";
   		cout<<ans<<endl;
    }
    return 0;   
}
 


Measured memory_bytes: 256
import sys
s = input()
counts = [0] * 26

for num in s:
    counts[ord(num) - 97] += 1
    
for i in range(26):
    if counts[i] == 0:
        print(s + chr(i + 97))
        sys.exit()

d = []
for i in reversed(range(len(s))):
    for num in d:
        if s[i] < num:
            print(s[0: i] + num)
            sys.exit()
        
    d.append(s[i])
    d.sort()

print(-1)

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

int main(){
    int h,w,k;
    cin >> h >> w >> k;
    vector<string> s(h);
    int ans = mod;
    for(int i = 0; i < h; i++) cin >> s[i];
    for(int bit = 0; bit < (1<<h-1); bit++){
        vector<int> hdiv;
        hdiv.clear();
        for(int i = 0; i < h-1; i++){
            if(bit & (1<<i)) hdiv.push_back(i);
        }
        map<int,int> box;
        map<int,bool> flag;
        flag.clear();
        bool end = false;
        int can = 0;
        for(int i = 0; i < w; i++){
            for(int j = 0; j < h; j++){
                if(s[j][i] == '1'){
                    auto itr = lower_bound(hdiv.begin(),hdiv.end(),j);
                    if(itr == hdiv.end()){
                        box[h-1]++;
                        if(box[h-1] > k){
                            if(flag[i]){
                                end = true;
                            } else {
                                can++;
                                flag[i] = true;
                                box.clear();
                                i--;
                            }
                            break;
                        }
                    } else {
                        box[*itr]++;
                        if(box[*itr] > k){
                            if(flag[i]){
                                end = true;
                            } else {
                                flag[i] = true;
                                can++;
                                box.clear();
                                i--;
                            }
                            break;
                        }
                    }
                }
            }
            if(end) break;
        }
        if(end) continue;
        //cout << can << endl;
        can += hdiv.size();
        if(ans > can) ans = can;
    } 
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdlib>
#include <vector>
#include <queue>
#include <utility>
using namespace std;

typedef long long ll;
typedef pair<ll, ll> P;

#define For(i, a, b) for(int i = (a); i < (b); i++)
#define Rep(i, n) For(i, 0, (n))

const int inf = 999999999;
const int mod = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int main(){
	ll n, s = 0, t = 0; cin >> n;
	//ll a[n];
	Rep(i, n){
		//cin >> a[i];
		ll a; cin >> a;
		if(a % 4 == 0){
			s += 1;
		}else if(a % 2 == 0){
			t += 1;
		}
	}
	if((s * 2 + t) >= n || n <= s * 2 + 1){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
h = list(map(int, input().split()))
f = True
for i in range(n-1):
    if h[n-2-i] - 1 == h[n-1-i]:
        h[n-2-i] -= 1
    elif h[n-2-i] > h[n-1-i]:
        f = False
        break;

if f:
    print("Yes")
else:
    print("No")

Measured memory_bytes: 20704
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector> 
#include <cstring>
#include <queue>
#include <stack>
#include <ctime>
#include <set>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<int,ll> pil;

const int maxN = 110; 
char s[maxN];
ll k;
int main()
{
	scanf("%s",s+1);
	scanf("%lld",&k);
	int len = strlen(s+1);
	int pos = 0;
	char ch;
	for(int i=1;i<=len;i++)
	{
		if(s[i] == '1') continue;
		else
		{
			pos = i;
			ch = s[i];
			break;
		}
	}
	if(pos == 1)
	{
		printf("%c\n",s[1]);
	}
	else if(pos == 0)
	{
		puts("1");	
	} 
	else if(k < pos)
	{
		puts("1");
	}
	else
	{
		printf("%c\n",s[pos]);
	}
	return 0;
}

Measured memory_bytes: 256
n = int(input())
march = 'MARCH'
c = [0] * 5

for _ in range(n):
    s = input()
    for i in range(5):
        if s[0] == march[i]:
            c[i] += 1

ans = 0
for i in range(5):
    for j in range(i+1, 5):
        for k in range(j+1, 5):
            ans += c[i] * c[j] * c[k]

print(ans)


Measured memory_bytes: 3060
using System;
using System.Linq;

public class Program
{
    static void Main()
    {
        var nt = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
        var cost = int.MaxValue;
        for (int i = 0; i < nt[0]; i++)
        {
            var route = Console.ReadLine().Split().Select(x => int.Parse(x)).ToArray();
            if (nt[1] >= route[1])
            {
                cost = Math.Min(cost, route[0]);
            }
        }

        if (cost == int.MaxValue)
        {
            Console.WriteLine("TLE");
        }
        else
        {
            Console.WriteLine(cost);
        }
    }
}


Measured memory_bytes: 13268
#include<stdio.h>

int main(){
  int n;
  scanf("%d",&n);
  int a[n],min=200001,count=0,i;
  for(i=0;i<n;i++){
    scanf("%d",&a[i]);
    if(a[i]<min){
      min=a[i];
      count++;
    }
  }
  printf("%d",count);
  return 0;
}


Measured memory_bytes: 896
#include <bits/stdc++.h>
#include <cstring>
#define ll long long
const int mod = 1e9 + 7;
const int MAXN = 2e5+5;
using namespace std;
int main()
{
    ios::sync_with_stdio(0);
    cin.tie(0);
    ll n;
    cin>>n;
    
    if(n == 1) {
        return cout<<0<<endl,0;
    }

    ll ans = 0;
    bool is_prime = 1;
    for(ll i =2;i*i<=n;i++) {
        if(n%i == 0) {
          is_prime = 0;
          ll cnt = 0;
          while (n%i==0) {
              cnt ++;
              n /=i;
          }
          ll j = 0;
          while ( j*(j+1)/2 <= cnt) j++;
          //cout<<i<<' '<<cnt<<' '<<j-1<<endl;
          ans += j-1;
        }
    }
    if(n != 1) ans++;
    cout<<ans<<endl;
}


Measured memory_bytes: 3640
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int ans = 0;
        for (int i = 0; 0 < n; i++) {
            int a = n % 10;
            if (a == 2) {
                ans++;
            }
            n = n / 10;
        }
        System.out.println(ans);
    }
}

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

using namespace std;

int main(){
	int x, n;
	map <int, bool> mp;
	scanf("%d %d", &x, &n);
	for (int i = 0; i < n; i++){
		int c;
		scanf("%d", &c);
		mp[c] = true;
	}
	for (int i = x, j = x; true; i++, j--){
		if (!mp[j]){
			printf("%d\n", j);
			return 0;
		}
		if (!mp[i]){
			printf("%d\n", i);
			return 0;
		}
	}
}


Measured memory_bytes: 3784
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <iomanip>
#include <map>
#include <set>
#include <ctype.h>
#include <numeric>
#include <math.h>
using namespace std;

typedef long long ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
const ll MOD = 1e9 + 7;
const int INF = 1e9;

int dx4[4] = { 0, -1, 1, 0 };
int dy4[4] = { -1, 0, 0, 1 };
int dx8[8] = { 0, -1, 1, 0, -1, 1, -1, 1 };
int dy8[8] = { -1, 0, 0, 1, -1, -1, 1, 1 };

int main() {
  int a, p; cin >> a >> p;

  cout << (3 * a + p) / 2 << endl;
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repi(i, s, n) for (int i = (s); i < (n); i++)
#ifdef LOCAL
#define INPUT_FILE                              \
  ifstream in("atcoder-problems/arc080_b.txt"); \
  cin.rdbuf(in.rdbuf());
#else
#define INPUT_FILE
#endif
#define print_vec(v)                        \
  rep(l, v.size()) { cout << v[l] << " "; } \
  cout << endl;
#define CIN_OPTIMIZE \
  cin.tie(0);        \
  ios::sync_with_stdio(false);
typedef pair<int, int> P;
typedef long long ll;
typedef pair<ll, ll> pl;
const int INF = 100100100;
const ll LINF = 1e18 + 100;
const int MOD = 1e9 + 7;

int W, H;
void dfs(int w, int h, int i, vector<vector<int>> &ans, vector<int> &col) {
  // printf("%d %d %d\n", w, h, i);
  if (w < 0 || w >= W || h < 0 || h >= H || ans[h][w] != 0) return;
  ans[h][w] = col[i];
  dfs(w + 1, h, i + 1, ans, col);
  dfs(w, h + 1, i + 1, ans, col);
  dfs(w - 1, h, i + 1, ans, col);
  dfs(w, h - 1, i + 1, ans, col);
}

int main() {
  INPUT_FILE CIN_OPTIMIZE;

  cin >> H >> W;
  int N;
  cin >> N;

  vector<int> c(N);
  rep(i, N) { cin >> c[i]; }

  vector<int> col(H * W, 0);
  int j = 0, cur = 0;
  rep(i, H * W) {
    cur++;
    col[i] = j + 1;
    if (cur == c[j]) {
      cur = 0;
      j++;
    }
  }

  vector<vector<int>> ans(H, vector<int>(W, 0));
  dfs(0, 0, 0, ans, col);
  rep(i, H) { print_vec(ans[i]); }
}

Measured memory_bytes: 1408
#include <iostream>
#include <algorithm>
#include <set>
#include <map>
#include <string>

using namespace std;
typedef long long ll;
#define rep(i,s,n)for(ll i = s;i<n;i++)
#define repe(i,s,n)for(ll i = s;i<=n;i++)

/*template*/
int main() {
	string s; cin >> s;
	ll K; cin >> K;
	set<string> se;

	//sort(s.begin(), s.end());

	repe(i, 0, s.size()) {
		repe(j, i, s.size()) {
			if (j - i > 5) {
				break;
			}
			se.insert(s.substr(i, j - i));
		}
	}

	ll i = 0;
	for (set<string>::iterator it = se.begin(); it != se.end(); it++) {
		if (i++ == K) {
			cout << *it << endl;
			return 0;
		}
	}

	return 0;
}

Measured memory_bytes: 1664
#include<bits/stdc++.h>
using namespace std;
vector<int>tt;
bool p=true;
int n,c,k,t,ans,ss,si;
int main()
{
    scanf("%d %d %d",&n,&c,&k);
    for(int i=1;i<=n;i++)
    {
    	scanf("%d",&t);
    	tt.push_back(t);
	}
	sort(tt.begin(),tt.end());
	for(int i=0;i<n;i++)
	{
		if(p)
		{
			si=1;
			ss=tt[i];
			ans++;
			p=false;
		}
		else
		{
			if(si<c)
			{
				if(ss+k>=tt[i])
				{
					si++;
				}
				else
				{
					si=1;
					ss=tt[i];
					ans++;	
				}
			}
			else
			{
				si=1;
				ss=tt[i];
				ans++;
			}
		}
	}
	printf("%d",ans);
}


Measured memory_bytes: 892
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{ios_base::sync_with_stdio(false);
cin.tie(NULL);
cout.tie(NULL);
/*ll t;
cin>>t;
while(t--)
{
}*/
ll a,b,c,d;
//ll f=0,f1=0;
cin>>a>>b>>c>>d;
while(a>0 and c>0)
{
    c=c-b;
    if(c<=0)
    break;
    //cout<<c<<endl;
    a=a-d;
    if(a<=0)
    break;
    //cout<<a<<endl;
}
//cout<<a<<" "<<c<<endl;
if(a<=0)
{
   cout<<"No"<<endl;
}
if(c<=0)
{cout<<"Yes"<<endl;
    
}


return 0;
}


Measured memory_bytes: 3652
use v5.18; # strict say state
use warnings;
use List::Util qw(reduce first max min sum0);

chomp (my ($h, $w) = split / /, <STDIN>);
my (@s, @que);
for my $i (0..$h-1) {
  chomp (my $in = <STDIN>);
  my @b = split //, $in;
  for my $j (0..$w-1) {
    if ($b[$j] eq '#') {
      $s[$i][$j] = -1;
    }
  }
}
push @que, 0;
push @que, 0;
$s[0][0] = 0;
sub check {
  my ($i, $j, $k) = @_;
  if (0<=$i && $i<$h && 0<=$j && $j<$w && $s[$i][$j] == $k) {
    return 1;
  }
  return 0;
}
while (@que) {
  my ($i, $j);
  $i = shift @que;
  $j = shift @que;
  my $cnt = $s[$i][$j];
  if (check($i+1, $j, -1)) {
    if (check($i, $j+1, -1) || check($i+1, $j-1, -1)) {
      say 'Impossible';
      exit;
    }
    $s[$i+1][$j] = $cnt + 1;
    push @que, $i+1;
    push @que, $j;
  }
  if (check($i, $j+1, -1)) {
    if (check($i+1, $j, -1) || check($i-1, $j+1, -1)) {
      say 'Impossible';
      exit;
    }
    $s[$i][$j+1] = $cnt + 1;
    push @que, $i;
    push @que, $j+1;
  }
}
say 'Possible' if $s[$h-1][$w-1]>=0;
say 'Impossible' unless $s[$h-1][$w-1]>=0;

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

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

    int n;
    cin >> n;
    string s;
    cin >> s;
    for (auto &c : s) {
        for (int i = 0; i < n; i++) {
            if (c == 'Z') c = 'A';
            else c++;
        }
    }
    cout << s << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <numeric>
#include <bitset>
#include <cmath>

static const int MOD = 1000000007;
using ll = long long;
using u32 = uint32_t;
using namespace std;

template<class T> constexpr T INF = ::numeric_limits<T>::max()/32*15+208;

int main() {
    string s;
    cin >> s;
    string a, b;
    int ans = 0;
    for (int i = 0; i < s.size(); ++i) {
        b += s[i];
        if(a != b) {
            ans++;
            a = b;
            b = "";
        }
    }
    cout << ans << "\n";
    return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define inf (1e9)
using namespace std;
const int maxn=2010;
int n,m,a[maxn][maxn],b[maxn][maxn],mx=-inf;
char iomap[maxn][maxn];
int main()
{
	cin>>n>>m;
	for(int i=0;i<n;i++)
	{
		for(int j=0;j<m;j++)
		{
			cin>>iomap[i][j];
		}
	}
	for(int i=0;i<n;i++)
	{
		int cnt=0;
		for(int j=0;j<m;j++)
		{
			if(iomap[i][j]=='.')
			{
				++cnt;
				a[i][j]=cnt;
			}
			else
			{
				cnt=0;
			}
		}
	}
	for(int j=0;j<m;j++)
	{
		int cnt=0;
		for(int i=0;i<n;i++)
		{
			if(iomap[i][j]=='.')
			{
				++cnt;
				b[i][j]=cnt;
			}
			else
			{
				cnt=0;
			}
		}
	}
	for(int i=n-1;i>=0;i--)
	{
		for(int j=m-1;j>=0;j--)
		{
			if(iomap[i][j]=='#')
			{
				continue;
			}
			if(i<n-1)
			{
				b[i][j]=max(b[i][j],b[i+1][j]);
			}
			if(j<m-1)
			{
				a[i][j]=max(a[i][j],a[i][j+1]);
			}
			mx=max(mx,a[i][j]+b[i][j]-1);
		}
	}
	cout<<mx<<endl;
	return 0;
}

Measured memory_bytes: 35712
N = int(input())
y = []
for i in range(1, int(N ** .5) + 1):
    if N % i == 0:
        y.append(i)
ans = float('inf')
for n in y:
    ans = min(ans, max(len(list(str(n))), len(list(str(N // n)))))
print(ans)

Measured memory_bytes: 3188
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
#include <string>
#include <cstdio>
#include <cstdlib>
#include <cctype>
using namespace std;
int main()
{
    int a, b, c;
    cin >> a >> b >> c;
    for (int i = 1; i <= 1000; i++)
    {
        if ((a * i % b == c))
        {
            cout << "YES" << endl;
            return 0;
        }
    }
    cout << "NO" << endl;
    return 0;
}

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


	int main() {
		int a,b,c,d,r,l;
		cin >> a >> b >> c >> d;
		l= a + b; 
		r = c + d;
		if (l>r) { cout << "Left" << endl;}
		else if (l < r) { cout << "Right" << endl; }
		else { cout << "Balanced"<<endl; }
	}

Measured memory_bytes: 256
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scanner = new Scanner(System.in);
        int r = scanner.nextInt();
        
        if(r<1200){
            System.out.print("ABC");
        }else if(r<2800){
            System.out.print("ARC"); 
        }else{
            System.out.print("AGC");
        }
    }
}

Measured memory_bytes: 22612
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N; cin >> N;
    int ans = 0;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        while (a % 2 == 0) {
            ans++;
            a /= 2;
        }
    }
    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3616
import java.util.*;

public class Main{
  public static void main(String[] args) {
    try {
      Scanner sc = new Scanner(System.in);
      int a,b,c,x,y,pay;

      a=Integer.parseInt(sc.next());
      b=Integer.parseInt(sc.next());
      c=Integer.parseInt(sc.next());
      x=Integer.parseInt(sc.next());
      y=Integer.parseInt(sc.next());

      pay=a*x + b*y;

      if(x>=y){
        if(pay>(a*x-a*y+2*c*y)){
          pay=a*x-a*y+2*c*y;
        }
        if(pay>(2*c*x)){
          pay=2*c*x;
        }
      }else{
        if(pay>(2*c*x+b*y-b*x)){
          pay=2*c*x+b*y-b*x;
        }
        if(pay>2*c*y){
          pay=2*c*y;
        }
      }

      System.out.println(pay);
      
      
    }
    catch (Exception e) {
      
    }
  }
}

Measured memory_bytes: 21844
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);

    int n = sc.nextInt();
    double ans = 0;

    for (int i = 0; i < n; i++) {
      double a = sc.nextInt();
      ans += 1.0 / a;
    }

    System.out.println(1.0 / ans);

  }
}

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

int main() {
  int a,b,c;
  int sum=0, min = 300;
  cin >>a >>b >>c;
  
  if ((a + b) < min) {
    min = (a +b);
  }
  if ((b + c) < min) {
    min = (b + c);
  }
  if ((a + c) < min) {
    min = (a + c);
  }
  
  cout << min;

  // ここにプログラムを追記
}


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

using namespace std;

int main(){

    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    
    long long N, W;
    cin >> N >> W; 

    vector<long long> w(N);
    vector<long long> c(N);

    for(int i = 0; i < N; ++i ){
        cin >> w[i]>> c[i];
    }


    vector<vector<long long>> dp(N+1,vector<long long>(W+1));

    for(int i = 1; i <= N; ++i){
        for(int j = 1; j <= W; ++j){
            if (j - w[i-1] >= 0){
                dp[i][j] = max(dp[i-1][j], dp[i-1][j -w [i-1]] +  c[i-1]);
            }
            else {
                dp[i][j] = dp[i-1][j];
            }
        }
    }

    cout << dp[N][W] << "\n";
    
    /*
    
    for(auto i : dp){
        for(long long j :  i){
            cout << j << " ";
        }
        cout << "\n";
    }

    */
    

   
    
    
    
    return 0;
}

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

int main() {
  int N, K, x, P=0;
  cin >> N >> K;
  
  for(int i=0;i<N;i++){
    cin >> x;
    if(x<=K-x){
      P+=x;
    }
    else{
      P+=K-x;
    }
  }
  
  cout << P*2 << endl;
}


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

int main(void){
    int a1, a2, a3;
    cin >> a1 >> a2 >> a3;
    if(a1+a2+a3 >= 22) cout << "bust" << endl;
    else cout << "win" << endl;    
    return 0;
}


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

#define                           ll                          long long
#define                           int                         ll
#define                           fi                          first
#define                           si                          second
#define                           mp                          make_pair
#define                           pb                          push_back
#define                           pi                          pair<ll,ll>
#define                           clr(x)                      memset(x,0,sizeof(x));
#define                           f(i,l,r)                    for(int i=l;i<=r;i++)
#define                           rf(i,r,l)                   for(int i=r;i>=l;i--)
#define                           done(i)                     cout<<"done = "<<i<<endl;
#define                           show(x,y)                   //cout<<x<<" : ";for(auto z:y)cout<<z<<" ";cout<<endl;
#define                           fast                        ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);

using namespace std;

const ll inf=1e18;
const int mod=1e9+7;
const int M=1003;
int n,m;
vector<int>adj[M];
int vis[M];
vector<int>cycle;
int prv[M];
vector<pi>edg;
int id[M];
void work(vector<int>vec)
{

      int cur=1;
      memset(id,-1,sizeof id);
      for(auto x:vec)
      {
          id[x]=cur;
          cur++;
      }
      vector<int>nw;
      for(auto x:edg)
      {
          int u=x.fi;
          int v=x.si;
          u=id[u];
          v=id[v];
          if(u==-1 || v==-1)continue;
          if(u+1==v)continue;
          if(u==cur-1 && v==1)continue;
          if(u<v)
          {
              for(int j=1;j<=u;j++)nw.pb(vec[j-1]);
              nw.pb(vec[v-1]);
              for(int j=v+1;j<cur;j++)nw.pb(vec[j-1]);
              work(nw);
          }
          else
          {
              for(int j=v;j<=u;j++)
              {
                  nw.pb(vec[j-1]);
              }
              work(nw);
          }

      }
      int sz=vec.size();
      if(sz==1)
      {
          printf("-1\n");
          exit(0);
      }
      printf("%lld\n",sz);
      for(auto x:vec)
      {
          printf("%lld\n",x);
      }
      exit(0);

}
void dfs(int u,int par)
{
    vis[u]=1;
    prv[u]=par;
    for(auto v:adj[u])
    {
        if(v==par)continue;
        if(vis[v]==0)
        {
            dfs(v,u);
        }
        else if(vis[v]==1)
        {
             while(1)
             {
                 cycle.pb(u);
                 if(u==v)break;
                 u=prv[u];
             }
             reverse(cycle.begin(),cycle.end());
             show("eta cycle ",cycle);
             work(cycle);
        }
    }
    vis[u]=2;
}
 main()

{
    scanf("%lld%lld",&n,&m);
    f(i,1,m)
    {
        int u,v;
        scanf("%lld%lld",&u,&v);
        adj[u].pb(v);
        edg.pb(mp(u,v));
    }
    for(int i=1;i<=n;i++)
    {
        if(vis[i]==0)
        {
            dfs(i,-1);
        }
    }
    printf("-1\n");
    return 0;

}





































Measured memory_bytes: 4012
#include<stdio.h>
 
static const int MAX = 500;
static const int INFTY = (1<<21);
 
int main(void){
    int n, i, j, e, sum;
    int x,y;
    
    int M[MAX][MAX];
    int d[MAX];
    int key[MAX],PI[MAX];
  scanf("%d", &n);
 
  for ( i = 0; i< n; i++ ){
    for ( j = 0; j < n; j++ ){
      scanf("%d", &e);
      M[i][j] = (e==-1)?INFTY:e;
    }
  }
    for(i=0;i<n;i++){
        PI[i]=-1;
        key[i]=INFTY;
        d[i]=0;
    }    
    key[0]=0;
     
    while(1){
        x=-1;
        y=INFTY;
         
        for(i=0;i<n;i++){
            if(y>key[i] && (d[i]==0)){
                x=i;
                y=key[i];
            }
        }        
         
        if(x==-1)break;
        d[x]=1;
         
         
         
        for(i=0;i<n;i++){
            if(key[i]>=M[x][i] && (d[i]==0)){
                PI[i]=x;
                key[i]=M[x][i];
            }
             
        }
                 
    }
  sum = 0;

  for ( i = 0; i < n; i++ ){
    if ( PI[i] != -1 ) sum += M[i][PI[i]];
  }
  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 804
#include <bits/stdc++.h>
#define ll long long
using namespace std;

const int N=1000005;
char s[N];

int main(){
	int oo=0,x;

	string ans="";

	scanf("%d%s",&x,s);

	for(int i=0;s[i];++i){

		ans+=s[i];

		if(s[i]=='(')++oo;
		else if(oo<=0)ans='('+ans;
		else --oo;
	}

	while(oo--)ans+=')';

	cout<<ans;

	return 0;

}


Measured memory_bytes: 256