akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/multiprecision/cpp_int.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

using boost::multiprecision::cpp_int;
using cpp_dec_float_1000 = boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000, boost::int128_type>>;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;
constexpr int MOD = 1000'000'007;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }
template<class T> T modinv(T a, T m) { T b = m, u = 1, v = 0; while (b) { T t = a / b; a -= t * b; boost::swap(a, b); u -= t * v; boost::swap(u, v); } u %= m; if (u < 0) u += m; return u; }
template<class T> inline bool isSosuu(const T& n) { if (n == T(1)) { return false; } for (T i = 2; i*i <= n; ++i) { if (n % i == 0) { return false; } } return true; }
template<class T> vector<vector<T>> split (const vector<T>& S, T delim) { vector<vector<T>> ret{}; vector<T> buff{}; for (auto c : S) { if (c == delim) { if (!buff.empty()) ret.push_back(buff); buff.clear(); } else { buff.push_back(c); } } if (!buff.empty()) ret.push_back(buff); return ret; }
template<class T> inline void printYesNo(const T& t) { cout << (t ? "Yes" : "No") << CRLF; }
template<class T = int64_t> T modpow(T N, T P, T M) { T ret{1}; N %= M; while (P) { if (P & 0x01) { ret *= N; ret %= M; } P >>= 1; N *= N; N %= M; } return ret; }

/** code for assert debug begin */
int gErr = 0;
#define ASSERT(p) if(!(p)){ gErr = 1; }else{ ; }
/** code for assert debug end */

struct Tmp
{
public:
  int N;
  Tmp(int N)
  : N(N)
  {}
};

void solve(void)
{
  string S; cin >> S;
  char c = 0;
  int cnt{};
  int N = S.size();
  for (int i = 0; i < N; ++i) {
    if (c != S[i]) {
      c = S[i];
      ++cnt;
    } else {
      c = S[i];
    }
  }
  cout << (cnt - 1) << CRLF;
  return;
}

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

  solve();

  return 0;
}


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

int main() {
  int N;
  double ans;
  cin >> N;
  vector<double> A(N);
  for (int i=0; i<N; i++) {
  	cin >> A.at(i);
    ans += 1/A.at(i);
  }
  cout << 1/ans << 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;

int main(){
  int n; cin >>n;
  vector<int> a(n);
  rep(i,n) cin >>a[i];
  const int M = 1000005;
  vector<int> cnt(M);
  for(int x : a){
    if(cnt[x]!=0){
      cnt[x] = 2;
      continue;
    }
    for(int i = x; i<M; i+=x) cnt[i]++;
  }
  int ans = 0;
  for(int x : a){
    if(cnt[x]==1) ans++;
  }
  cout << ans << endl;
  return 0; 
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;

long long gcd(long long x,long long y){
	if(x==0) return y;
	return gcd(y%x, x);
}

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

	int a,b,k; cin >> a >> b >> k;

	int g = gcd(a,b);

	int c = 0;

	for (int i = g;i > 0;i--){
		if(g%i == 0)c++;
		if(c == k){
			cout << i << endl;
			break;
		}
	}

	return 0;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define pii pair<int,int>
#define pp pair<pair<ll, ll>,pair<ll, ll>>
#define pll pair<ll,ll>
#define ppll pair<ll,pll>
#define pdd pair<double,double>
#define vii vector<int>
#define vll vector<ll>
#define mat vector<vector<ll>>
#define lb lower_bound
#define ub upper_bound
#define pb push_back
#define eb emplace_back
#define fi first
#define sc second
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep2(i,a,b) for(ll i=a;i<b;i++)
#define repr(i,n) for(ll i=n-1;i>=0;i--)
#define all(x) x.begin(),x.end()
#define sz(x) (ll) (x).size()
#define pq priority_queue<ll>
#define pqg priority_queue<ll,vector<ll>,greater<ll>>
#define LB(v,x) (lower_bound(v.begin(),v.end(),x)-v.begin())
#define UB(v,x) (upper_bound(v.begin(),v.end(),x)-v.begin())
#define ERASE(v) sort(v.begin(),v.end());v.erase(unique(v.begin(),v.end()),v.end())
#define int ll
// #define ll int
using namespace std;
const ll INF = (1 << 30 ) - 1;
const ll LLINF = (1LL << 60LL);
const ll MOD = 1000000007;
// const ll mod = 998244353;
const ll MAX = 2100000;
const double pi = acos(-1);
const double eps = 1e-10;
ll dx[8] ={1,0,-1,0,1,-1,1,-1};
ll dy[8] ={0,1,0,-1,1,-1,-1,1};
 
template<class T> 
inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> 
inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }






void solve() {
    ll x,y,z;
    cin>>x>>y>>z;
    cout<<z<<" "<<x<<" "<<y<<endl;
}





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


    solve(); 


    return 0;
}


Measured memory_bytes: 3624
n, m = gets.split.map(&:to_i)
keys = []
m.times do
  a, b = gets.split.map(&:to_i)
  c = gets.split.map(&:to_i)
  v = 0
  c.each do |x|
    v += 1 << x - 1   
  end
  keys << [v, a]
end

prv = Hash.new(10 ** 10)
prv[0] = 0
nxt = nil

m.times do |i|
  nxt = prv.dup
  prv.each do |k, v|
    k1 = k | keys[i][0]
    v1 = v + keys[i][1]
    if nxt[k1] < v1
      v1 = nxt[k1]
    end
    nxt[k1] = v1
  end
  prv = nxt
end

if prv.has_key?((2 ** n) - 1)
  puts prv[(2 ** n) - 1]
else
  puts -1
end


Measured memory_bytes: 81660
import sys
n = int(input())
nums = [int(e) for e in input().split()]
g = 1;
for a in nums:
  if a == 0:
    print("0");
    sys.exit()
for i in nums:
  g*=i;
  if g>1000000000000000000:
    print("-1")
    sys.exit()
print(g)


Measured memory_bytes: 21748
a,v=map(int,input(). split())
b,w = map(int,input(). split())
t=int(input())


if a<=b:

    dist_a = a + t*v

    dist_b = b + t*w

    if dist_a>=dist_b:
        print('YES')
    else:
        print('NO')
else:

    dist_a = a - t*v

    dist_b = b - t*w

    if dist_a<=dist_b:
        print('YES')
    else:
        print('NO')

Measured memory_bytes: 9140
#include <bits/stdc++.h>
#define REP(i, s, n) for (int i = s; i < n; i++)
#define ALL(a) a.begin(), a.end()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main() {
    ll H; cin >> H;
    
    ll ans = 1;
    int i = 1;
    while (H > 1) {
        H /= 2;
        ans += 1LL << i;
        i++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>

int main(){
  int N,A[100],i,flag=1,temp,c=0;
  scanf("%d",&N);
  for(i=0;i<N;i++) scanf("%d",&A[i]);
  while(flag){
    flag=0;
    for(i=N-1;i>0;i--){
      if(A[i]<A[i-1]){
	temp=A[i];
	A[i]=A[i-1];
	A[i-1]=temp;
	c++;
	flag=1;
      }
    }
  }
  for(i=0;i<N;i++){
    printf("%d",A[i]);
    if(i!=N-1) printf(" ");
  }
  printf("\n");
  printf("%d\n",c);
  return 0;
}



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

typedef long long ll;

int main(){
    ll n,k;
    cin >> n >> k;
    
    ll tmp=k;
    
    for(int i=1;i<n;i++)
        tmp*=(k-1);
    
    cout << tmp << endl;

    return 0;
}



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

namespace AtCoder_Beginner_Contest_052_A
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] h = Console.ReadLine().Split().Select(int.Parse).ToArray();
            int a = h[0] * h[1];
            int y = h[2] * h[3];
            if (a > y) { Console.WriteLine(a); }
            else { Console.WriteLine(y); }
        }
    }
}


Measured memory_bytes: 3032
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdlib>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <string>
#include <vector>
#define DEBUG 1
using namespace std;
constexpr int kMod = 1000000007;
typedef long long LL;

template<typename T>
istream& operator >> (istream& is, vector<T>& vs){
  for(T& v: vs) is >> v;
  return is;
}

int main() {
  int N; cin >> N;
  vector<int> A(N); cin >> A;

  vector<int> l(N + 1); l[0] = 0;
  for (int i = 0; i < N; ++i) {
    l[i + 1] = gcd(A[i], l[i]);
  }
  vector<int> r(N + 1); r[N] = 0;
  for (int i = N-1; i >= 0; --i) {
    r[i] = gcd(A[i], r[i + 1]);
  }

  int vmax = 0;
  for (int i = 1; i <= N; ++i) {
    vmax = max(vmax, gcd(l[i - 1], r[i]));
  }
  cout << vmax << endl; }


Measured memory_bytes: 4524
fun main(args: Array<String>) {
  val (h, w) = readLine()!!.split(" ").map { it.toInt() }
  val board = Array(h, { readLine()!! })

  var ans = false

  val rowPairs = IntArray(h, { -1 })
  var remainingRows = h

  val colPairs = IntArray(w, { -1 })
  var remainingCols = w

  fun isSymmetryRow(r: Int): Boolean {
    return (0 until w).all { c -> board[r][c] == board[r][colPairs[c]] }
  }

  fun areReverseRows(r1: Int, r2: Int): Boolean {
    return (0 until w).all { c -> board[r1][c] == board[r2][colPairs[c]] }
  }

  fun searchRowPairs() {
    if (remainingRows == 0) {
      ans = true
    } else if (remainingRows == h && h % 2 == 1) {
      for (r in 0 until h) {
        if (isSymmetryRow(r)) {
          rowPairs[r] = r
          remainingRows -= 1
          searchRowPairs()
          rowPairs[r] = -1
          remainingRows += 1
        }
      }
    } else {
      val r1 = rowPairs.indexOfFirst { it == -1 }
      for (r2 in r1 + 1 until h) {
        if (areReverseRows(r1, r2)) {
          rowPairs[r1] = r2
          rowPairs[r2] = r1
          remainingRows -= 2
          searchRowPairs()
          rowPairs[r1] = -1
          rowPairs[r2] = -1
          remainingRows += 2
          break
        }
      }
    }
  }

  fun searchColPairs() {
    if (remainingCols == 0) {
      searchRowPairs()
    } else if (remainingCols == w && w % 2 == 1) {
      for (c in 0 until w) {
        colPairs[c] = c
        remainingCols -= 1
        searchColPairs()
        colPairs[c] = -1
        remainingCols += 1
      }
    } else {
      val c1 = colPairs.indexOfFirst { it == -1 }
      for (c2 in c1 + 1 until w) {
        if (colPairs[c2] == -1) {
          colPairs[c1] = c2
          colPairs[c2] = c1
          remainingCols -= 2
          searchColPairs()
          colPairs[c1] = -1
          colPairs[c2] = -1
          remainingCols += 2
        }
      }
    }
  }

  searchColPairs()

  println(if (ans) "YES" else "NO")
}


Measured memory_bytes: 47936
#include <iostream>
#include <vector>
#include <algorithm>
#include <unordered_map>
#include <ctime>
#include <set>
#include <sstream>
#include <bitset>
#include <queue>
#include <stack>
#include <deque>
#define ll long long
using namespace std;

int main() {
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    if (k > a) {
        k -= a;
        if ( k > b) {
            k -= b;
            if (k == 0) {
                cout<<a;
            }else {
                a -= k;
                cout<<a;
            }
        }else cout<<a;
    }else cout<<k;
}


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

int main(){
    string s;
    cin>>s;
    int res = 0;
    int ss = (int)s.size()/2;
    for(int i=0;i<ss;i++){
        if(s[i] != s[s.size()-1-i]){
            res++;
        }
    }cout<<res<<endl;
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
 
using namespace std;
 
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("Ofast")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
#pragma GCC optimize("-ffloat-store")
 
#define fastio ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define int long long
#define endl "\n"
 
#define sz(a) ((int)(a).size())
#define all(v) (v).begin(), (v).end()
#define tr(c, it) for (auto(it) = (c).begin(); (it) != (c).end(); it++)
#define pres(c, val) ((c).find(val) != (c).end())      //
#define cpres(c, val) (find(all(c), val) != (c).end()) //
 
#define pb push_back
#define mp make_pair
#define F first
#define S second
 
#define forf(i, a, b) for (int i = (a); i < (b); i++)
#define forb(i, a, b) for (int i = (b); i >= (a); i--)
#define fo(i, n) forf(i, 0, n)
#define fob(i, n) forb(i, 0, n - 1)
 
typedef vector<int> vi;
typedef pair<int, int> pii;
typedef vector<pair<int, int>> vpii;
 
const int INF = 9e18;
// const int N = 1e9 + 7;
const int N = 998244353;
 
const auto start_time = std::chrono::high_resolution_clock::now();
 
void zark() {
  #ifdef ZARK
  auto end_time = std::chrono::high_resolution_clock::now();
  std::chrono::duration<double> diff = end_time - start_time;
  cerr << "Time Taken : " << diff.count() << "s\n";
  #endif
}
 
#ifdef ZARK
#include "/home/aranjan/Desktop/CP/header.h"
#else
#define dbg(args...)
#endif
 
/* ------------------ Actual Coding Starts ------------------ */

void solve() {
  string s;
  cin >> s;
  int n = sz(s);
  vi rem(n+1);
  rem[0] = 0;
  int kk = 1;
  fo(i, n) rem[i+1] = (rem[i] + (s[n-1-i]-'0')*kk) % 2019, kk = (10*kk)%2019;
  map<int, int> f;
  fo(i,n+1) f[rem[i]]++;
  int ans = 0;
  tr(f, it) ans += (it->S * (it->S-1))/2;
  cout << ans << endl;
}
 
int32_t main() {
  fastio;
  #ifdef ZARK
  freopen("input.in", "r", stdin);
  #endif
 
  // freopen("txt.in", "r", stdin);
  // freopen("txt.out", "w", stdout);
  // cout << fixed << setprecision(35);
 
  solve();
  zark();
  return 0;
}

Measured memory_bytes: 5144
#include<bits/stdc++.h>
#define all(x) (x).begin(),(x).end()

using ll = long long;
using ld = long double;
using namespace std;

const ll inf = 2e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 5;

ll n;

ll fastpow(ll a, ll n, ll m) {
    ll res = 1;
    while (n) {
        if (n & 1)res = (res * a) % m;
        n >>= 1;
        a = (a * a) % m;
    }
    return res;
}
ll add(ll a, ll b, ll m) {
    return (a % m + b % m) % m;
}
ll sub(ll a, ll b, ll m) {
    return ((a - b) % m + m) % m;
}
ll mul(ll a, ll b, ll m) {
    return (a % m * b % m) % m;
}
ll div(ll a, ll b, ll m) {
    return mul(a, fastpow(b, m - 2, m), m);
}


void code() {
    cin >> n;
    ll x = fastpow(10, n, mod);
    ll y = fastpow(8, n, mod);
    ll z = fastpow(9, n, mod);

    cout << add(sub(x, mul(2, z, mod), mod), y, mod) << "\n";
}

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

    int t = 1;
    // cin>>t;

    while (t-- > 0) {
        code();
    }
}

Measured memory_bytes: 3644
#include<stdio.h>

int main(void)
{
   long long int n, a[100000], i, s=1, z=1;

   scanf("%lld",&n);
   for(i=0;i<n;i++){
      scanf("%lld",&a[i]);
      if(a[i]==0)
         z=0;
   }

   if(z==0){
      printf("0\n");
      return 0;
   }

   for(i=0;i<n;i++){
      if(a[i]<=1000000000000000000/s)
         s=s*a[i];
      else{
         printf("-1\n");
         return 0;
      }
   }

   printf("%lld\n",s);
   return 0;
}

Measured memory_bytes: 2484
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] as = new int[n];
		int[] bs = new int[n];
		for(int i=0; i<n; i++) {
			as[i] = sc.nextInt();
			bs[i] = sc.nextInt();
		}
		Arrays.sort(as);
		Arrays.sort(bs);
		if(n%2 != 0) {
			int i = n/2;
			int ans = bs[i] - as[i] + 1;
			System.out.println(ans);
		} else {
			int i = n/2;
			int ans = (bs[i-1]+bs[i]) - (as[i-1]+as[i]) + 1;
			System.out.println(ans);
		}
	}
}


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

count = 0
for i in range(1, N+1):
    if 10**0 <= i < 10**1:
        count += 1
    elif 10**2 <= i < 10**3:
        count += 1
    elif 10**4 <= i < 10**5:
        count += 1

print(count)

Measured memory_bytes: 3060
#include<stdio.h>
int main()
{  int n,a[200],i,j,t,s=0;
   scanf("%d",&n);
   for(i=0;i<2*n;i++)
   scanf("%d",&a[i]);
   for(i=0;i<2*n-1;i++)
   for(j=0;j<2*n-1-i;j++)
   if(a[j]>a[j+1])
   {  t=a[j];
      a[j]=a[j+1];
      a[j+1]=t;
   }
   for(i=0;i<2*n;i+=2)
   s=s+a[i];
   printf("%d",s);
}

Measured memory_bytes: 128
import sys
readline = sys.stdin.readline
from collections import Counter

def main():
    N = int(readline())
    A = list(map(int, readline().rstrip().split()))
    A1 = [i + a for i, a in enumerate(A)]
    A2 = [i - a for i, a in enumerate(A)]
    c1 = Counter(A1)
    c2 = Counter(A2)
    c2_keys = set(c2.keys())
    ans = 0
    for key, val in c1.items():
        if key in c2_keys:
            ans += val * c2[key]

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 71544
n = gets.to_i
vn = gets.split(' ').map{|a|a.to_i}
cn = gets.split(' ').map{|a|a.to_i}

val = 0
0.upto (vn.size-1) do |i|
  val += vn[i] - cn[i] if vn[i] > cn[i]
end
p val

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

#define rep2(x,fr,to) for(int (x)=(fr);(x)<(to);(x)++)
#define rep(x,to) for(int (x)=0;(x)<(to);(x)++)
#define repr(x,fr,to) for(int (x)=(fr);(x)>=(to);(x)--)
#define all(c) (c).begin(),(c).end()
#define sz(v) (int)(v).size()

using namespace std;
typedef long long ll; typedef vector<int> VI; typedef pair<int,int> pii;
const int MD = (int)1e9 + 7;
void dbg(){ cerr << "\n"; }  template <typename T,typename ...T2>
void dbg(const T& fst, const T2&...rst){ cerr << fst << ": "; dbg(rst...); }
template <class T> void amin(T& a,T b){ a=min(a,b);}


int main(){
	//cin.tie(0); ios_base::sync_with_stdio(false);
	int n;
	string s;
	cin >>n >>s;
	s = s+s;
	rep(i, 4){
		vector<uint8_t> t(n+4);
		t[0] = i&1;
		t[1] = i>>1 &1;

		rep2(j, 2, n+4){
			if(!t[j-1]) t[j] = s[j-1]=='o'? t[j-2]: !t[j-2];
			else        t[j] = s[j-1]=='o'? !t[j-2]: t[j-2];
		}
		//for(auto x :t) printf("%c ",x?'T':'F'); puts("");
		if(t[0]==t[n] && t[1]==t[n+1] && t[2]==t[n+2]){
			rep(j, n){
				cout << (t[j]? 'W':'S');
			}
			cout <<"\n";
			return 0;
		}   
	}
	
	cout << -1 <<endl;
	return 0;
}

Measured memory_bytes: 680
x, k, d = map(int, input().split())

a = [abs(x // d), x % d]

if a[0] > k:
   ans = min(abs(x+k*d) ,abs(x-k*d))
else:
    b = (k- a[0]) % 2
    ans = min(abs(a[1]+b*d) ,abs(a[1]-b*d))

print(ans)

Measured memory_bytes: 9088
n = int(input())
c = sorted(map(int, input().split()))

mod = 1000000007

ret = 0
for i in range(n):
    ret = (ret + (i + 2) * c[n - i - 1]) % mod

for i in range(n - 1):
    ret = (ret * 4) % mod

print(ret)


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

int main() {
	int h,w,n;
	cin >> h >> w >> n;
	int s1,s2;
	cin >> s1 >> s2;
	string s,t;
	cin >> s >> t;
	int l=0,r=0,u=0,d=0;
	int L=s2-1,R=w-s2,U=s1-1,D=h-s1;
	for(int i=0;i<n;i++){
		if(s[i]=='L'){
			l++;
		}
		else if(s[i]=='R'){
			r++;
		}
		else if(s[i]=='U'){
			u++;
		}
		else if(s[i]=='D'){
			d++;
		}
		if(l>L || r>R || u>U || d>D){
			cout << "NO";
			return 0;
		}
		if(t[i]=='L'){
			r--;
			r=max(r,-L);
		}
		else if(t[i]=='R'){
			l--;
			l=max(l,-R);
		}
		else if(t[i]=='U'){
			d--;
			d=max(d,-U);
		}
		else if(t[i]=='D'){
			u--;
			u=max(u,-D);
		}
		
	}
	cout << "YES";
	
	// your code goes here
	return 0;
}

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

int main(){
  string S,T;
  cin >> S >> T;
  string x;
  bool flag = false;

  if(S == T)flag = true;

  for(int i = 0;i < S.size();i++){
    x = S.substr(0,1);
    S.replace(0,1,"");
    S += x;
    if(S == T)flag = true;
  }

  if(flag)cout << "Yes" << endl;
  else cout << "No" << endl;

}

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

int l,r,ans=0,pos=1;

signed main()
{
	cin>>l>>r;
	pos=l;
	
	while (pos<=r)
	{
		pos*=2ll;
		ans++;
	}
	cout<<ans<<endl;
		
	return 0;
}

Measured memory_bytes: 384
//#define India

#ifndef India
#include <bits/stdc++.h>
#else
#include "total.h"
#endif
#define fori(n) for(long long i=0;i<n;i++)
#define forr(i,x,y) for(long long i=x;i<y;i++)
#define forj(n) for(long long j=0;j<n;j++)
#define ll long long
#define d7 1000000007
#define en cout<<"\n";

using namespace std;

ll x=-1,kk=-1;
bool jpo=false;
void dfs(ll s, vector<bool> &v, vector<ll> &pr, vector<ll> adj[]){
    if(v[s]) return;
    v[s]=true;
    //cout<<s+1<<" ";
    for(auto u: adj[s]){
        if(!v[u]){
            pr[u]=s;
            //cout<<u<<" ";
            dfs(u,v,pr,adj);}
        else{
            if(!jpo&&pr[s]!=u){jpo=true;x=u;kk=s;}
        }
    }
}
ll binomialCoeff(ll n, ll k){
   ll C[n + 1][k + 1];ll i, j;
   for (i = 0; i <= n; i++){
       for (j = 0; j <= min(i, k); j++){
           if (j == 0 || j == i){C[i][j] = 1;}
           else{C[i][j] = (C[i - 1][j - 1] + C[i - 1][j]);}}}
   return C[n][k];
}
void bfs(vector<ll> &dis, vector<ll> adj[], ll s, vector<ll> &parent){
    dis[s]=0;
    //parent[s]=-1;
    queue<ll> q;
    q.push(s);
    while(!q.empty()){
        ll z=q.front();
        //cout<<z<<" ";
        q.pop();
        for(auto v:adj[z]){
            if(dis[v]==0){
            q.push(v);
            dis[v]=dis[z]+1;
                parent[v]=z;
            }
        }
    }
}

ll modexp(ll x, ll n,ll m){
    if(n==0) return 1%m;
    ll u=modexp(x,n/2,m);
    u=(u*u)%m;
    if(n%2==1) u=(u*x)%m;
    return u;
}

ll modinv(ll x, ll mod) { return modexp(x, mod - 2, mod); }
const int Nx=1e6+5;
ll fact[Nx];
void factorial(){fact[0]=1;
    for(int i=1;i<Nx;i++)
    {
        fact[i]=(fact[i-1]*i)%d7;
    }
    return ;}
ll binomial(ll a,ll b,ll mod){
    return ((fact[a]*modinv(fact[b],mod))%mod*modinv(fact[a-b],mod))%mod;}

ll gcd(ll a, ll b){
    if(b==0) return a;
    return gcd(b, a%b);
}

tuple<ll,ll,ll,ll> expA(tuple<ll,ll,ll,ll> v, ll n){
    if(n==0){return {1,0,1,0};}
    if(n==1){return v;}
        ll x1,y1,z1,w1;
        ll x2,y2,z2,w2;
        tie(x1,y1,z1,w1) = expA(v, n/2);
        x2=(x1*x1+y1*z1)%d7;
        y2=(x1*y1+y1*w1)%d7;
        z2=(z1*x1+w1*z1)%d7;
        w2=(z1*y1+w1*w1)%d7;
    if(n%2==0){
        return {x2,y2,z2,w2};
    }
    else{
        return {x2+z2,y2+w2,x2,y2};
    }
}

//ll st[200010][30];
//ll loge2[200001];
//void logify(){
//loge2[1] = 0;
//for (ll i = 2; i <= 200001; i++)
//    loge2[i] = loge2[i/2] + 1;
//}

int main(){
    
    
    ll n;
    cin>>n;
    double s=6.28318530717958623200*n;
    cout<<setprecision(15)<<s;
    
    return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n) for(int i=0;i<(n);++i)
#define REPR(i,n) for(int i=n;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
#define ALL(obj) (obj).begin(),(obj).end()

#define P pair<int,int>
#define V vector<int>
#define M map<int,int>
#define S set<int>
#define PQ priority_queue<int>
#define PQG priority_queue<int,V,greater<int>>

#define pb(a) push_back(a)
#define mp make_pair

#define dump(x)  cout << #x << " = " << (x) << "\n";
#define COUT(x) cout<<(x)<<"\n"




int main()
{
	int x, y, z = 0;
	cin >> x >> y >> z;
	x -= z;
	int ct = 0;

	while (x >= (y + z))
	{
		x -= y;
		x -= z;
		ct++;
	}

	COUT(ct);

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
int64_t N,K,count;
cin >> N >> K;
count=0;
for(int64_t i=K;i<N+2;i++)
count += (N-i+1)*i+1;
cout << count % 1000000007 << endl;
}
    

Measured memory_bytes: 3648
import java.util.*;

public class Main{
	public static void main(String arg[]){
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();
		int b=sc.nextInt();
		int i=0;
		while(n>0){
			n=n/b;
			i++;
		}
		System.out.println(i);
	}
}

Measured memory_bytes: 23508
#include<bits/stdc++.h>
#define mxn 100010
using namespace std;
const int mod=1e9+7;
int n,m,sl,fh,a[mxn],dp[mxn];
int rd()
{
	sl=0;fh=1;
	char ch=getchar();
	while(ch<'0'||'9'<ch) {if(ch=='-') fh=-1; ch=getchar();}
	while('0'<=ch&&ch<='9') sl=sl*10+ch-'0',ch=getchar();
	return sl*fh;
}
void upd(int &x,int y) {x+=y; if(x>=mod) x-=mod;}
int main()
{
	n=rd();m=rd();
	for(int i=1;i<=m;++i) a[rd()]=1;
	dp[0]=1;
	for(int i=1;i<=n;++i)
		if(!a[i])
		{
			upd(dp[i],dp[i-1]);
			if(i>=2) upd(dp[i],dp[i-2]);
		}
	printf("%d\n",dp[n]);
	return 0;
}

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

int main()
{
    int a, b;
    cin >> a >> b;
    if ((a * b) % 2 == 0)
    {
        cout << "Even" << endl;
    }
    else
    {
        cout << "Odd" << endl;
    }
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using ll = long long;
constexpr int INF = 1e9;
constexpr long long LINF = 1e18;
constexpr long long MOD = 1e9 + 7;

signed main() {
    int k, q;
    cin >> k >> q;
    int d[k];
    rep(i, k) {
        cin >> d[i];
    }
    int n[q], x[q], m[q];
    rep(i, q) {
        cin >> n[i] >> x[i] >> m[i];
    }
    rep(i, q) {
        int t[k];
        rep(j, k) {
            t[j] = d[j] % m[i];
        }
        ll sum[k + 1] = {};
        int cnt[k + 1] = {};
        rep(j, k) {
            sum[j + 1] = sum[j] + t[j];
            cnt[j + 1] = cnt[j] + (t[j] == 0);
        }
        n[i]--;
        cout << n[i] - (n[i] / k * cnt[k] + cnt[n[i] % k]) -
                    (x[i] % m[i] + n[i] / k * sum[k] + sum[n[i] % k]) / m[i]
             << endl;
    }
    return 0;
}

Measured memory_bytes: 3756
#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>

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define ll long long
#define P pair<int, int>

using namespace std;

int N, M;
unordered_map<int, int> mp;
int main() {
  cin >> N >> M;
  ll sum = 0;
  mp[0]++;
  rep(i, N) {
    int a; cin >> a;
    sum = (sum + a)%M;
    mp[sum]++;
  }
  ll ans = 0;
  for(auto e: mp) {
    ll cnt = e.second;
    ans += cnt*(cnt-1)/2;
  }
  cout << ans << endl;
}


Measured memory_bytes: 3596
#include<bits/stdc++.h>
#define For(i,j,k) for(int i=j;i<=k;i++)
int read(){
	int x=0,l=1; char ch=getchar();
	while(!isdigit(ch)) {if (ch=='-') l=-1; ch=getchar();}
	while(isdigit(ch)) x=x*10+(ch^48),ch=getchar();
	return x*l;
}
using namespace std;
char s[100005],c[100005]; int a[30],sp[100005];
int main(){
	int n,ans=0,an=0,l,r; scanf("%s",s+1); n=strlen(s+1);
	For(i,1,n) if (s[i]!='x') a[s[i]-97]++,c[++ans]=s[i],sp[ans]=i;
	if (!ans) printf("0"),exit(0);
	For(i,1,ans/2)
		if (c[i]!=c[ans+1-i]) printf("-1"),exit(0);
	if (ans%2==0) l=ans/2,r=l+1;
	else l=r=(ans+1)/2;
	while(l>1){
		an+=abs(sp[l]-sp[l-1]-(sp[r+1]-sp[r])); l--; r++;
	}
	an+=abs(sp[1]-1-n+sp[ans]);
	printf("%d\n",an);
	return 0;
}

Measured memory_bytes: 768
import sys
from collections import defaultdict

graph = defaultdict(set)

n, m = map(int, sys.stdin.readline().split())

if m == 0:
    print(1)
    exit()

for _ in range(m):
    a,b = map(int, sys.stdin.readline().split())

    if not b in graph[a]:
        graph[a].add(b)
    if not a in graph[b]:
        graph[b].add(a)

visited = set()
maxi = 0

def dfs(start):
    stk = [start]
    visited.add(start)
    temp = 1

    while stk:
        cur = stk.pop()

        for c in graph[cur]:
            if not c in visited:
                visited.add(c)
                stk.append(c)
                temp += 1

    return temp

for j in graph:
    if not j in visited:
        cnt = dfs(j)
        maxi = max(cnt, maxi)

print(maxi)

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

using namespace std;

int main()
{
    int i,j,k,n,m,x,y,z,a,b;
    cin>>a>>b;

    x=0;
    y=1;
    while(y<b)
    {
        y=y+a-1;

        x++;


    }
    cout<<x<<endl;

}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
using namespace std;
int a,b,c,x,y,t;
int main()
{
	scanf("%d%d%d%d%d",&a,&b,&c,&x,&y);c*=2;
	a=min(a,c);b=min(b,c);
	if (a+b<=c) printf("%d\n",x*a+y*b);
	else t=min(x,y),printf("%d\n",t*c+(x-t)*a+(y-t)*b);
	return 0;
} 

Measured memory_bytes: 128
import sys
input = sys.stdin.readline
inf = 10**9
H, N = map(int, input().split())
AB = []
for n in range(N):
    a, b = map(int, input().split())
    AB.append((a, b))
AB.sort(reverse=True, key=lambda x: x[0])
dp = [inf] * (H + 10 ** 4)
dp[0] = 0
for a, b in AB:
    for h in range(H):
        if dp[h] != inf:
            tmp = dp[h] + b
            if tmp < dp[h + a]:
                dp[h + a] = tmp
print(min(dp[H:]))


Measured memory_bytes: 41068
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)

	N, K := getInt(), getInt()
	a := make([]bool, N)
	for i := 0; i < K; i++ {
		d := getInt()
		for j := 0; j < d; j++ {
			x := getInt() - 1
			a[x] = true
		}
	}
	ans := 0
	for i := 0; i < N; i++ {
		if a[i] == false {
			ans++
		}
	}
	out(ans)
}


Measured memory_bytes: 1756
#include <iostream>
#include <stdio.h>
#include <algorithm>
#include <vector>
#include <queue>
#include <deque>
#include <set>
#include <string>
#include <map>
#include <math.h>
#include <cmath>
#include <climits>

typedef long long ll;
using namespace std;

ll MOD = 1e9+7;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int ans = 0;
    if(h > w){
        int moves = 0;
        while(moves < n){
            moves += h;
            ans++;
        }
    }
    else{
        int sum = 0;
        while(sum < n){
            sum += w;
            ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define forn(i,a,b) for(int i=a;i<=b;i++)
#define INF 2147483647
#define LLINF 9223372036854775807
using namespace std;
int main(){
	double x;
	cin>>x;
	double cnt=(x/3)*(x/3)*(x/3);
	cout<<fixed<<setprecision(10)<<cnt<<endl;
	return 0;
}

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

typedef long long ll;

#define REP(i, n) for (int i = 0; i < (int)(n); i++)

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

int main() {
    int N;
    cin >> N;
    char c[N];
    ll Wnum = 0, Rnum = 0;
    REP(i,N){
        cin >> c[i];
        if ( c[i] == 'W' ) ++Wnum;
        else ++Rnum;
    }
    
    int ans = 0;
    REP(i,Rnum){
        if ( c[i] == 'W' ) ++ans;
    }
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 3792
#include <iostream>

using namespace std;

int main(){
    int a,b;
    cin >> a >> b;
    if(a < b){
        cout << "a < b" << endl;
    }else if(a > b){
        cout << "a > b" << endl;
    }else{
        cout << "a == b" << endl;
    }
}


Measured memory_bytes: 3084
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharpSample01
{

    

    class Program
    {
        
        static void Main(string[] args)
        {
            string s = Console.ReadLine();

            int red = 0;
            int blue = 0;

            for(int i = 0; i < s.Length; i++)
            {
                int tmp = int.Parse(s[i].ToString());

                if(tmp == 0)
                {
                    red++;
                }
                else
                {
                    blue++;
                }

            }

            Console.WriteLine(Math.Min(red, blue) * 2);

        }
    }
}


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

using namespace std;

using int64 = long long;

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

  int n;
  cin >> n;
  vector<int> bs(n - 1);
  for (int i = 0; i < n - 1; i++) {
    cin >> bs[i];
  }
  int64 sum = 0;
  sum += bs[0];
  sum += bs[n - 2];
  for (int i = 0; i + 1 < n - 1; i++) {
    sum += min(bs[i], bs[i + 1]);
  }
  cout << sum << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define rep1(i,n) for (int i = 1; i <= (n); ++i)

using namespace std;
using ll = long long;
using P = pair<int,int>;
using ull= unsigned long long;
const int INF=1e9;

int n;

int main(){
  cin>>n;
  bool judge=true;
  
  rep(i,n){
    int a;
    cin>>a;
    if(a%2==0){
      if(a%3!=0 && a%5!=0){
        judge=false;
        cout<<"DENIED"<<endl;
        return 0;
      }
    }
  }

  cout<<"APPROVED"<<endl;
  return 0;
}

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

using namespace std;

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

const int MM = 1e9 + 7;
const double eps = 1e-8;
const int MAXN = 2e6 + 10;

int n, m;
string s, t;


void read(){
	cin>>n>>s>>t;
	for(int j = n; j >= 0; j--){
		int flag = 1;
		for(int i = 1; i <= j; i++){
			if (s[n - i] != t[j - i])
				flag = 0;
		}
		if (flag){
			cout<<n * 2 - j<<endl;
			return ;
		}
	}
}

void solve(){

}

void printans(){

}
	

int main(){
	int T = 1;
//	cin>>T;
	while(T--){
		read();
		solve();
		printans();
	}
	return 0;
} 


Measured memory_bytes: 256
"use strict";
function main(input) {
  const args = input.split(' ');
  const a = parseInt(args[0], 10);
  const b = parseInt(args[1], 10);

  let count = 0;
  let d = new Date('2018/1/1');
  while (true) {
    const date = d.getDate();
    const month = d.getMonth() + 1;
    if (date === month) {
      count += 1;
    }
    d = new Date(d.getTime() + 60 * 60 * 24 * 1000);

    if (d.getFullYear() > 2018 || (month === a && date == b)) {
      break;
    }
  }
  console.log(count);
}
main(require('fs').readFileSync('/dev/stdin', 'utf8'));


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

#define fi first
#define se second

const int N = 2020;
const int MAGIC = 1000;
const long long mod = 998244353;

using namespace std;

int n;
char a[N];
int s[N];
int col[N];
vector < int > v[N];

int dfs(int x, int p, int g = 0)
{
        int res = 0;
        if(a[x] == '1'){
                res = g;
        }
        for(int y: v[x]){
                if(y == p){
                        continue;
                }
                res += dfs(y, x, g + 1);
        }
        s[x] = res;
        return res;
}

int good(int x, int p, int need, int f = 1)
{
        vector < int > g;
        s[x] = 0;
        if(a[x] == '1'){
                s[x] += f;
                col[x] = 1;
        } else{
                col[x] = 0;
        }
        for(int y: v[x]){
                if(y == p){
                        continue;
                }
                need = good(y, x, need, f + 1);
                g.push_back(s[y] - col[y] * f);
                col[x] += col[y];
                s[x] += s[y];
        }
        if(g.empty()){
                return need;
        }
        sort(g.begin(), g.end());
        int sum = 0;
        for(int i = 1; i < g.size(); i++) sum += g[i - 1];
        int can = 0;
        if(sum >= g.back()){
                can = sum + g.back();
        } else{
                can = sum * 2;
        }
        can -= can % 2;
        int gg = min(can, need);
        need -= gg;
        s[x] -= gg;
        return need;
}

int main()
{
        //freopen("input.txt", "r", stdin);
        //freopen("output.txt", "w", stdout);
        ios_base::sync_with_stdio(0);

        cin >> n;
        for(int i = 1; i <= n; i++){
                cin >> a[i];
        }
        for(int i = 1; i < n; i++){
                int x, y;
                cin >> x >> y;
                v[x].push_back(y);
                v[y].push_back(x);
        }
        int res = 1e9;
        vector < pair < int, int > > g;
        for(int i = 1; i <= n; i++){
                g.clear();
                for(int j: v[i]){
                        g.push_back({dfs(j, i, 1), j});
                }
                int s = 0;
                sort(g.begin(), g.end());
                for(auto x: g) s += x.fi;
                int need = max(0, g.back().fi - (s - g.back().fi));
                if(s % 2 == 0 && good(g.back().se, i, need) == 0){
                        res = min(res, s / 2);
                }
        }
        if(res == 1e9){
                res = -1;
        }
        cout << res << "\n";
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define ld long double
#define pii pair <int, int>
#define sz(a) (int)(a.size()) 
#define resize(v) v.resize(unique(all(v)) - v.begin()); 
#define all(a) a.begin(), a.end()
#define forit(it, s) for(__typeof(s.begin()) it = s.begin(); it != s.end(); it ++)

using namespace std;
 
void Fast_Read_Out()
{
    ios_base::sync_with_stdio(0);
    cin.tie(), cout.tie();
}
 
void Random()
{
    unsigned int seed;                                                                        
    asm("rdtsc" : "=A" (seed));
    srand(seed);        
}
 
unsigned int Time()
{
     unsigned int time = clock() / 1000.00;                           
     return time;
}
 
const int mod = (int)1e9 + 7;
const int N = int(1e5) + 123;

int a[N];
 
int main ()
{
	#ifdef JUDGE
		freopen("input.txt", "r", stdin);
	#endif		
	Fast_Read_Out();
	Random();
	int n;
	cin >> n;
	long long ans = 0, sum = 0;
	for(int i = 1; i <= n; i++) cin >> a[i];
	for(int i = 1; i <= n; i++)
	{
		sum += a[i];
		if(a[i] == 0 || n == i) 
		{
			ans += sum / 2;
			sum = 0;
		}
	}
	cout << ans;
}


Measured memory_bytes: 768
#include<iostream>
#include<vector>
#include<string>

using namespace std;

int main() {

	int K;
	cin >> K;
	string str;
	vector<uint64_t> tree;
	for (int i = 1; i <= 9; i++) {
		tree.push_back(i);
	}
	int amari = 0;
	int i = 0;
	while(1){
		amari = tree[i] % 10;
		if (amari == 0) {
			tree.push_back(tree[i] * 10);
			tree.push_back(tree[i] * 10+1);
		}
		else if (amari == 9) {
			tree.push_back(tree[i] * 10 + 8);
			tree.push_back(tree[i] * 10 + 9);
		}
		else {
			tree.push_back(tree[i] * 10 + amari - 1);
			tree.push_back(tree[i] * 10 + amari );
			tree.push_back(tree[i] * 10 + amari + 1);

		}
		if (tree.size() >= K) {
			cout << tree[K - 1];
			return 0;
		}
		i++;
	}




}

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

using namespace std;
using ll = long long;
using pii = pair<int, int>;

// struct P {
//   string name;
//   int MP;
//   string target;
//   int damage;
//   P() {}
//   P(string n, int m, string t, int d) : name(n), MP(m), target(t), damage(d) {}
// };

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  int N;
  while (cin >> N, N) {
    vector<int> HP(N);
    for (int i = 0; i < N; i++) {
      cin >> HP[i];
    }

    int M;
    cin >> M;

    vector<int> MP(M), target(M), damage(M);
    for (int i = 0; i < M; i++) {
      string na, ta;
      cin >> na >> MP[i] >> ta >> damage[i];
      target[i] = ta == "All";
    }

    vector<int> dp(2000010, 1 << 20), dp2(2000010, 1 << 20);
    dp[0] = 0, dp2[0] = 0;
    for (int i = 0; i <= 2000000; i++) {
      for (int j = 0; j < M; j++) {
        if (i + damage[j] <= 2000000) {
          if (target[j]) dp[i + damage[j]] = min(dp[i + damage[j]], dp[i] + MP[j]);
          else dp2[i + damage[j]] = min(dp2[i + damage[j]], dp2[i] + MP[j]);
        }
      }
    }
    for (int i = 2000000; i> 0; --i) {
      dp[i-1] = min(dp[i], dp[i-1]);
      dp2[i-1] = min(dp2[i], dp2[i-1]);
    }

    int ans = 1 << 20;
    for (int i = 0; i <= 200000; i++) {
      int sum = dp[i];
      for (int j = 0; j < N; j++) {
        int rem = max(0, HP[j] - i);
        if (rem < 0) continue;
        sum += dp2[rem];
      }
      ans = min(ans, sum);
    }
    cout << ans << endl;
  }

  return 0;
}


Measured memory_bytes: 18636
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
#define PRINT(x) cout<<(x)<<endl
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
#define PB push_back
#define MP make_pair

const int MAX_V = 100;

int V, E;
int s, t, d;

ll dp[MAX_V][MAX_V];

int main() {
    cin >> V >> E;
    REP(i, V) {
        REP(j, V) {
            if (i == j) dp[i][j] = 0;
            else dp[i][j] = INF;
        }
    }
    REP(i, E) {
        cin >> s >> t >> d;
        dp[s][t] = d;
    }

    REP(k, V) {
        REP(i, V) {
            REP(j, V) {
                if (dp[i][k] != INF && dp[k][j] != INF) dp[i][j] = min(dp[i][j], dp[i][k] + dp[k][j]);
            }
        }
    }
    bool has_negative_cycle = false;
    REP(i, V) {
        if (dp[i][i] < 0) has_negative_cycle = true;
    }
    if (has_negative_cycle) PRINT("NEGATIVE CYCLE");
    else {
        REP(i, V) {
            REP(j, V) {
                if (j == 0) {
                    if (dp[i][j] == INF) printf("INF");
                    else printf("%lld", dp[i][j]);
                }
                else {
                    if (dp[i][j] == INF) printf(" INF");
                    else printf(" %lld", dp[i][j]);
                }
            }
            printf("\n");
        }
    }
    return 0;
}


Measured memory_bytes: 3296
#include<iostream>                                                                            
using namespace std;                                                                          
int main(){                                                                                   
  int h, w;                                                                                   
  cin >> h >> w;                                                                              
  while(h!=0 or w!=0){                                                                        
    for (int i=0; i<h; i++){                                                                  
      for (int j=0; j<w; j++){                                                                
        if (i==0 or j==0 or i==h-1 or j==w-1){                                                
          cout << "#";                                                                        
        } else {                                                                              
          cout << ".";                                                                        
        }                                                                                     
      }                                                                                       
      cout << endl;                                                                           
    }                                                                                         
    cout << endl;                                                                             
    cin >> h >> w;                                                                            
  }                                                                                           
}                                                                                             
           


Measured memory_bytes: 3088
/*
 * =template=.cpp
 * Copyright (C) 2017 hzw <hzw@huzhenweideMacBook.local>
 *
 * Distributed under terms of the MIT license.
 */

#include<cstdio>
#include<iostream>
#include<cmath>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<string>
#include<cstring>
#include<sstream>
#define FR first
#define SC second
#define MP make_pair
#define rep(i,a,b) for (int i=a;i<=b;i++)
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int,int> PII;
const int N=200010,p=1000000007,inf=100000000;
int pow(int a,int b,int c)
{
    if (a==0)return 0;int d=a,e=1;
    while (b)
    {
        if (b&1) e=(1LL*e*d)%c;
        d=1LL*d*d%c;b>>=1;
    }
    return e;
}
int random(int n) { return 1LL*rand()*rand()%n+1;}
struct Edge {int y,ne;};
/*int read(int &x)
{
	while (buf[pt]<=32&&pt<len) pt++;
	if (pt>=len) return 0;
	x=0;
	while (buf[pt]>32) x=x*10+buf[pt++]-48;
	return 1;
}*/
int sg(int n,int k) { 
	if (n<k) return 0;
	if (n%k==0) return n/k;
	else 
	{
		int t=n/k+1;
		return sg(n-t*((n%k-1)/t+1),k);
	}
}
int main()
{
	int n,m,ans=0;
	scanf("%d",&n);
	while (n--)
	{
		int x,k;scanf("%d%d",&x,&k);
		ans^=sg(x,k);
	}
	if (ans) cout<<"Takahashi";
	else cout<<"Aoki";
	return 0;
}


Measured memory_bytes: 384
#include <iostream>

using namespace std;
int main(){
    int n;
    cin >> n;
    int xs[n];
    for(int i = 0; i < n; ++i){
        cin >> xs[i];
    }
    int q;
    cin >> q;
    int v = 0;
    int cnt = 0;
    for(int i = 0; i < q; ++i){
        cin >> v;
        for(int j = 0; j < n; ++j){
            if(xs[j] == v){
                ++cnt;
                break;
            }
        }
    }
    cout << cnt << '\n';
}

Measured memory_bytes: 1192
g1 = [1,3,5,7,8,10,12]
g2 = [4,6,9,11]

main = do
  [a,b] <- map read . words <$> getLine
  if (elem a g1 && elem b g1) || (elem a g2 && elem b g2) then putStrLn "Yes" else putStrLn "No"

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

int main(){
    int n;
    cin >> n;
    vector<vector<char>> c(2, vector<char>(n));
    ll ans = 0;
    rep(i, 2) rep(j, n) cin >> c[i][j];
    int idx = 0;
    bool v_flg = 0;
//    bool h_flg[2] = {0};
    bool h_flg = 0;
    if ( c[0][0] == c[1][0] ) {
        ans = 3;
        ++idx;
        v_flg = 1;
    }
    else {
        ans = 6;
        idx += 2;
//        h_flg[0] = 1;
        h_flg = 1;
    }
    while(1) {
        if ( idx >= n ) {
            break;
        }
        if ( c[0][idx] == c[1][idx] ) {
            if ( v_flg ) {
                ans = ans * 2 % mod;
            }
//            h_flg[0] = 0;
//            h_flg[1] = 0;
            h_flg = 0;
            v_flg = 1;
            ++idx;
        }
        else {
//            if ( h_flg[1] && h_flg[0] ) {
//                ans = ans * 4 % mod;
            if ( h_flg ) {
//                int tmp_num = 0;
//                if ( c[0][idx] == c[1][idx-1] ) {
//                    tmp_num += 1;
//                }
//                else {
//                    tmp_num += 2;
//                }
//                if ( c[1][idx] == c[0][idx-1] ) {
//                    tmp_num += 1;
//                }
//                else {
//                    tmp_num += 2;
//                }
                ans = ans * 3 % mod;
            }
//            else if ( h_flg[0] && !h_flg[1] ) {
//                h_flg[1] = 1;
//                ans = ans * 3 % mod;
//            }
            else if ( v_flg ) {
//                h_flg[0] = 1;
                h_flg = 1;
                v_flg = 0;
                ans = ans * 2 % mod;
            }
            idx += 2;
        }
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  int A, B, C, D;
  cin >> A >> B >> C >> D;
  
  if (A + B == C + D){
    cout << "Balanced" << endl;
  }
  else if (A + B < C + D){
    cout << "Right" << endl;
  }
  else {
    cout << "Left" << endl;
  }
}
    

Measured memory_bytes: 256