akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <random>
#include <iomanip>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int,int> > vpii;
typedef vector<pair<ll,ll> > vpll;
typedef vector<vector<int> > vvi;
typedef vector<vector<char> > vvc;
typedef vector<vector<string> > vvs;
typedef vector<vector<ll> > vvll;
typedef map<int,int> mii;
typedef set<int> si;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define arep(i,v) for(auto i : v)
#define irep(it, stl) for(auto it = stl.begin(); it != stl.end(); it++)
#define drep(i,n) for(int i = (n) - 1; i >= 0; --i)
#define fin(ans) cout << (ans) << '\n'
#define STLL(s) strtoll(s.c_str(), NULL, 10)
#define mp(p,q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define Rort(a) sort(a.rbegin(), a.rend())
#define MATHPI acos(-1)
#define itn int
// #define endl '\n';
#define fi first
#define se second
#define NONVOID [[nodiscard]]
constexpr int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
constexpr int 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;}
template <class T> inline void dump(T &v){irep(i, v){cout<<*i<<((i==--v.end())?'\n':' ');}}
inline string getline(){string s; getline(cin,s); return s;}
inline void yn(const bool b){b?fin("yes"):fin("no");}
inline void Yn(const bool b){b?fin("Yes"):fin("No");}
inline void YN(const bool b){b?fin("YES"):fin("NO");}
struct io{io(){ios::sync_with_stdio(false);cin.tie(0);}};
const int INF = INT_MAX;
constexpr ll LLINF = 1LL<<60;
constexpr ll MOD = 1000000007;
constexpr double EPS = 1e-9;


int lis(vi& v) {
    vi dp(1, v[0]);
    for(int i = 1; i < v.size(); i++) {
        if(v[i] > dp[dp.size() - 1]) {
            dp.push_back(v[i]);
        } else {
            int pos = distance(dp.begin(), lower_bound(dp.begin(), dp.end(), v[i]));
            dp[pos] = v[i];
        }
    }
    return dp.size();
}

int main() {

    int n;
    cin>>n;
    vi v(n);
    rep(i,n)cin>>v[i];
    fin(lis(v));
}


Measured memory_bytes: 3768
#include <iostream>
#include <string>
#include <map>
#include <sstream>
using namespace std;

int main() {
    map<int,pair<int,int> > cnt;
    int n, date;
    char c;
    string s;
    while (getline(cin, s), s != "") {
        stringstream ss(s);
        ss >> n >> c >> date;
        cnt[n].first ++;
    }
    while (getline(cin, s), s != "") {
        stringstream ss(s);
        ss >> n >> c >> date;
        cnt[n].second ++;
    }
    map<int,pair<int,int> >::iterator it;
    for (it = cnt.begin(); it != cnt.end(); ++it) {
        if (1 <= (*it).second.first && 1 <= (*it).second.second) {
            cout << it->first << " " << (*it).second.first + (*it).second.second << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 1228
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;

int main() {
    int n, m;
    cin>>n>>m;

    vector<int> v(n);
    int total = 0;
    for(auto& it: v) {
        cin>>it;
        total+=it;
    }

    double barrier = 1/(4.0*m);

    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());

    for(int i=0; i<m; i++) {
        if((v[i]*1.0/total)<barrier) {
            cout<<"No"<<endl;
            return 0;
        }
    }
    cout<<"Yes"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>

using namespace std;

int n;
long long dp[100005];
int h[100005];
const long long INF = 1LL << 60;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

int main() {
    cin >> n;
    for(int i=0;i<n;i++) cin >> h[i];

    for (int i = 0; i < 100005; ++i) dp[i]=INF;
    dp[0] = 0;

    for(int i=1;i<n;i++){
        // printf("at %d, abs: %d \n", i, abs(h[i]-h[i-1]));
        chmin(dp[i], dp[i-1]+abs(h[i]-h[i-1]));
        if(i > 1) chmin(dp[i], dp[i-2]+abs(h[i]-h[i-2]));
    }

    cout << dp[n-1] << endl;
    return 0;
}

Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<ll> vi;
typedef vector<bool> vb;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define sq(x) ((x)*(x))
#define fo(i,n) for(int i=0;i<n;i++)
#define fp(i,k,n) for(int i=k;i<n;i++)
#define Fo(i,n) for(int i=1;i<=n;i++)
#define all(x) x.begin(),x.end()
#define deb(x) cout<<#x<<"="<<x<<"\n"
#define deb2(x,y) cout<<#x<<"="<<x<<" "<<#y<<"="<<y<<"\n"
#define fi first
#define se second
const double pi = 3.14159265358979323846;
#define uni(c) (c).resize(unique(all(c))-(c).begin())
#define fast ios_base::sync_with_stdio(0);cin.tie(NULL)
//pair <int, int> w[4] = {mp(-1, 0), mp(0, -1), mp(1, 0), mp(0, 1)};   // for matrix movement:
void cp()
{
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif // ONLINE_JUDGE
}
void solve()
{

	ll n, k; cin >> n >> k;
	ll a[n];
	ll ans = 0;
	fo(i, n)cin >> a[i];
	sort(a, a + n);
	fo(i, k)
	ans += a[i];
	cout << ans;

}
int main()
{
	fast;
	//cp();
	ll t = 1;
	//cin >> t;
	while (t--)
		solve();


	return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using Pair = pair<int, int>;
using Vec = vector<int>;
using Graph = vector<Vec>;

int		main(void)
{
	string s, t;
	cin >> s >> t;
	int len = s.size();
	bool f = true;
	for (int i = 0; i < len; i++)
	{
		if (s[i] != t[i])
			f = false;
	}
	cout << (f ? "Yes" : "No") << endl;
}


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

int main() {
  int A, B, C, N;
  cin >> A >> B >> C >> N;
  
  int res = 0;
  for(int a = 0; a <= A; a++) {
    for(int b = 0; b <= B; b++) {
      for(int c = 0; c <= C; c++) {
        int total = 500 * a + 100 * b + 50 * c;
        if(total == N) res++;
      }
    }
  }
  
  cout << res << endl;
}


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

const int N = 1000;
const int INF = 1e9;
int a[N];
int main()
{
    int n;
    cin >> n;
    int sum = 0;
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
        sum += a[i];
    }
    int minn = INF;
    ;
    for (int i = 0; i < n; i++)
    {
        minn = min(minn, abs(a[i] * n - sum));
    }
    for (int i = 0; i < n; i++)
    {
        if (abs(a[i] * n - sum) == minn)
        {
            cout << i;
            return 0;
        }
    }
}

Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<algorithm>

using namespace std;
int main()
{
	int n;
	int i;
	int p[3] = { 0, };
	int a, b;
	int input;
	int sol;

	scanf("%d %d %d", &n, &a, &b);

	for (i = 0; i < n; i++)
	{
		scanf("%d", &input);

		if (input <= a)
		{
			p[0]++;
		}

		else if (input <= b)
		{
			p[1]++;
		}

		else
		{
			p[2]++;
		}
	}

	sol = p[0];

	if (p[1] < sol)
	{
		sol = p[1];
	}

	if (p[2] < sol)
	{
		sol = p[2];
	}

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

	return 0;
}

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

int main() {
  int a, b, t; cin >> a >> b >> t;
  cout << t / a * b << endl;
  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
int w,h;
const int INF = 1<<29;
char tbl[70][70];
int cost[2][70][70];
bool used[2][70][70];

/*
  f=0 -> left
  f=1 -> right
*/
struct V{
  int f,x,y;
  V(int f=0,int x=0,int y=0):f(f),x(x),y(y){}
};

bool operator <(const V& a,const V& b){
  return cost[a.f][a.y][a.x] > cost[b.f][b.y][b.x];
}

int dijkstra(int sx,int sy,int f){
  for(int i=0;i<h;++i)
    for(int j=0;j<w;++j)
      cost[0][i][j]=cost[1][i][j]=INF,
	used[0][i][j] = used[1][i][j]=false;

  priority_queue<V,vector<V> > Q;
  Q.push(V(f,sx,sy));
  cost[f][sy][sx] = 0;
  while(!Q.empty()){
    V v = Q.top(); Q.pop();
    if(used[v.f][v.y][v.x]) continue;
    used[v.f][v.y][v.x] = true;
    int mf = 1-v.f;
    for(int dx=1;dx<=3;++dx){
      for(int dy=-3+dx;dy<=3-dx;++dy){
	int mx = (v.f)?(v.x+dx):(v.x-dx);
	int my = v.y+dy;
	if(mx<0 || my<0) continue;
	if(mx>=w || my>=h) continue;
	if(tbl[my][mx]=='X') continue;
	int nxtcost = cost[v.f][v.y][v.x];
	if(tbl[my][mx]!='T') nxtcost+=tbl[my][mx]-'0';
	cost[mf][my][mx] = min(cost[mf][my][mx],nxtcost);
	Q.push(V(mf,mx,my));
      }
    }
  }
  int ret = INF;
  for(int i=0;i<h;++i)
    for(int j=0;j<w;++j)
      if(tbl[i][j]=='T'){
	ret = min(ret,cost[0][i][j]);
	ret = min(ret,cost[1][i][j]);
      }

  return ret;
}
int main(){
  while(cin>>w>>h,w||h){
    for(int i=0;i<h;++i)
      for(int j=0;j<w;++j)
	cin>>tbl[i][j];

    int ans = INF;
    for(int j=0;j<w;++j)
      if(tbl[h-1][j]=='S'){
	ans = min(ans,dijkstra(j,h-1,0));
	ans = min(ans,dijkstra(j,h-1,1));
      }
    if(ans==INF) ans=-1;
    cout << ans << endl;
  }
  return 0;
}

Measured memory_bytes: 1296
#include<iostream>

using namespace std;

void trace(int matrix[], int N){
  for(int i=0;i<N;i++){
    if(i>0){
      cout << " ";
    }
    cout << matrix[i];
  }
  cout << endl;
}

void insertSort(int matrix[], int N){
  
  int temp;

  for(int i=1;i<N;i++){
    temp = matrix[i];
    int j = i-1;

    while( j>=0 && matrix[j] > temp){
      matrix[j+1] = matrix[j];
      j = j-1;
    }
    matrix[j+1] = temp;  
    trace(matrix, N);
  }

}


int main(void){
  
  //Input Unit
  int N_tot=0;

  cin >> N_tot;

  int* matrix = new int [N_tot];

  for(int i=0;i<N_tot;i++){
    cin >> matrix[i];
  }

  //Sort Unit
  trace(matrix, N_tot);
  insertSort(matrix, N_tot);

  delete [] matrix ;

  return 0;
}


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

int main(void)
{
	int numA, numB;
	cin >> numA >> numB;

	if (numA == numB) {
		cout << "Draw" << endl;
	}
	else if (numA == 1) {
		cout << "Alice" << endl;
	}
	else if (numB == 1) {
		cout << "Bob" << endl;
	}
	else if (numA > numB) {
		cout << "Alice" << endl;
	}
	else {
		cout << "Bob" << endl;
	}
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long int;
using ld=long double;
using VI=vector<ll>;
using VD=vector<ld>;
using VVI=vector<VI>;
using VC=vector<char>;
using VVC=vector<VC>;
using VS=vector<string>;
using PLL =pair<ll,ll>;
using PLD=pair<ld,ld>;
using VPLL=vector<PLL>;
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=(ll)(n)-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(b);i--)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element((x).begin(),(x).end())
#define MIN(x) *min_element((x).begin(),(x).end())
#define SORTR(x) sort((x).rbegin(),(x).rend())
#define SORT(x) sort((x).begin(),(x).end())
#define SUM(x) accumulate((x).begin(),(x).end(), 0)
#define FILL(x,a) fill(x.begin(),x.end(),a)
#define EACH(i,x) for(typeof((x).begin()) i=(x).begin(); i!=(x).end(); ++i)

const int INF  = 1<<30;
const ld EPS   = 1e-10;
const int MOD  = int(1e9)+7;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template <class BidirectionalIterator>
bool next_partial_permutation(BidirectionalIterator first, BidirectionalIterator middle,BidirectionalIterator last){reverse(middle, last); return next_permutation(first , last);}
#define COUT(x) cout<<x<<"\n"

void Main()
{
	ll S,W;
	string result="safe";
	cin>>S>>W;
	if(S<=W)result="unsafe";
	cout << result << "\n";
	return;
}

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


Measured memory_bytes: 3640
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N = 1e6 + 5;
const ll MOD = 1e9 + 7;
ll a[N];
ll prime[N];

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

ll add(ll a, ll b) {
	return ((a % MOD) + (b % MOD)) % MOD;
}

ll mul(ll a, ll b) {
	return ((a % MOD) * (b % MOD)) % MOD;
}

ll exgcd(ll a, ll b, ll &x, ll &y)
{
    if (a == 0) {
        x = 0; y = 1;
        return b;
    }
    ll x1, y1;
    ll d = exgcd(b % a, a, x1, y1);
    x = y1 - (b / a) * x1;
    y = x1;
    return d;
}

ll inverse(ll a)
{
	ll x, y, g = exgcd(a, MOD, x, y);
	return (x % MOD + MOD) % MOD;
}

void prime_division(ll x)
{
	for (ll i = 2; i * i <= x; i++) {
		ll cnt = 0;
		while (x % i == 0) {
			cnt++;
			x /= i;
		}
		prime[i] = max(prime[i], cnt);
	}
	if (x > 1)
		prime[x] = max(prime[x], 1LL);
}

ll quick_mod(ll a, ll b, ll mod)
{
    ll res = 1;
    while (b) {
        if (b % 2)
            res = res * a % mod;
        b >>= 1;
        a = a * a % mod;
    }
    return res % mod;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n;
	cin >> n;
	ll max_val = 0;
	for (int i = 0; i < n; i++) {
		cin >> a[i];
		prime_division(a[i]);
		max_val = max(max_val, a[i]);
	}
	ll t = 1;
	for (int i = 2; i <= max_val; i++) {
		t = mul(t, quick_mod(i, prime[i], MOD));
	}
	ll ans = 0;
	for (int i = 0; i < n; i++) {
		ans = add(ans, mul(t, inverse(a[i])));
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 8192
#include <algorithm>  
#include <iostream>  
#include <sstream>  
#include <string>  
#include <cstring>
#include <vector>  
#include <queue>  
#include <set>  
#include <map>  
#include <cstdio>  
#include <cstdlib>  
#include <cctype>  
#include <cmath>  
#include <list>  
#include <cassert>
#include <ctime>
#include <climits>
using namespace std;  

#define PB push_back  
#define MP make_pair  
#define SZ(v) ((int)(v).size())  
#define FOR(i,a,b) for(int i=(a);i<(b);++i)  
#define REP(i,n) FOR(i,0,n)  
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)  
#define REPE(i,n) FORE(i,0,n)  
#define FORSZ(i,a,v) FOR(i,a,SZ(v))  
#define REPSZ(i,v) REP(i,SZ(v))  
typedef long long ll;
typedef unsigned long long ull;
ll gcd(ll a,ll b) { return b==0?a:gcd(b,a%b); }

const int MAXN=10000000;
const int MOD=998244353;
void inc(int &a,int b) { if((a+=b)>=MOD) a-=MOD; }

int n;

int inv[MAXN+1];
int fac[MAXN+1];
int ifac[MAXN+1];
int p2[MAXN+1];

int twoexact[MAXN/2+1];
int oneexact[MAXN/2+1];
int twoatleast[MAXN/2+1];
int oneatleast[MAXN/2+1];

int choose(int n,int k) { if(k<0||k>n) return 0; return (ll)fac[n]*ifac[k]%MOD*ifac[n-k]%MOD; }


int solvestupid() {
	int ret=0;
	REPE(x,n/2) REPE(y,n/2) {
		if(x<y) {
			FORE(z,y-x,n/2-x) {
				int cur=choose(n/2,x)*choose(n/2,y)*choose(n/2-x,z)*p2[n/2-y];
				printf("x=%d y=%d z=%d -> %d\n",x,y,z,cur);
				ret+=cur;
			}
		}
		if(y<x) {
			FORE(z,x-y,n/2-y) {
				int cur=choose(n/2,x)*choose(n/2,y)*choose(n/2-y,z)*p2[n/2-x];
				printf("x=%d y=%d z=%d -> %d\n",x,y,z,cur);
				ret+=cur;
			}
		}
		if(x==y) {
			int cur=choose(n/2,x)*choose(n/2,y)*p2[n-x-y];
			printf("x=%d y=%d -> %d\n",x,y,cur);
			ret+=cur;
		}
	}
	return ret;
}

int solve() {
	inv[1]=1; FORE(i,2,n) inv[i]=(ll)(MOD-MOD/i)*inv[MOD%i]%MOD;
	fac[0]=1; FORE(i,1,n) fac[i]=(ll)fac[i-1]*i%MOD;
	ifac[0]=1; FORE(i,1,n) ifac[i]=(ll)ifac[i-1]*inv[i]%MOD;
	p2[0]=1; FORE(i,1,n) p2[i]=(ll)p2[i-1]*2%MOD;

	REPE(i,n/2) twoexact[i]=(ll)p2[i]*choose(n/2,i)%MOD;
	REPE(i,n/2) oneexact[i]=(ll)p2[n/2-i]*choose(n/2,i)%MOD;
	for(int i=n/2;i>=0;--i) twoatleast[i]=(twoexact[i]+(i+1<=n/2?twoatleast[i+1]:0))%MOD;
	for(int i=n/2;i>=0;--i) oneatleast[i]=(oneexact[i]+(i+1<=n/2?oneatleast[i+1]:0))%MOD;

	int ret=0;
	REPE(x,n/2) {
		int yzways=(twoatleast[x]+MOD-oneatleast[x])%MOD;
		//printf("%d: %d (%d-%d)\n",x,yzways,twoatleast[x],oneatleast[x]);
		int cur=(ll)yzways*choose(n/2,x)%MOD*p2[n/2-x]%MOD;
		inc(ret,cur);
		inc(ret,cur);
	}
	REPE(x,n/2) {
		int cur=(ll)choose(n/2,x)*choose(n/2,x)%MOD*p2[n-2*x]%MOD;
		inc(ret,cur);
	}
	return ret;
}


void run() {
	scanf("%d",&n);
	printf("%d\n",solve());
}

int main() {
	run();
	return 0;
}


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

const string YES = "Yes";
const string NO = "No";

void solve(string N){
    bool flg = false;
    rep(i, N.size()) {
        if(N[i] == '7') {
            flg = true;
            break;
        }
    }

    if(flg)
        cout <<YES << endl;
    else
        cout << NO << endl;
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    string N;
    cin >> N;
    solve(N);
    return 0;
}


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

int N;
vector<int> B;

int main() {
  cin >> N;
  B.resize(N + 1, 1e6);
  for (int i = 1; i <= N - 1; ++i) {
    cin >> B[i];
  }
  ll ans = 0;
  rep(i, N) { ans += min(B[i], B[i + 1]); }

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


Measured memory_bytes: 256
#include<iostream>
#include<bits/stdc++.h>
using namespace std;
int main()
{
long long n,sum=0;
cin>>n;
long long arr[n];
long long arr1[n];
for(long long i=0;i<n;i++)
    cin>>arr[i];
    for(long long i=0;i<n;i++)
        cin>>arr1[i];

    for(long long i=0;i<n;i++)
    {
        if(arr[i]>=arr1[i])
            sum=sum+(arr[i]-arr1[i]);
    }
    cout<<sum;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<n; i++)
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
long long mo = 1e9 + 7;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
template<class A>void PR(A a,ll n){rep(i,n){if(i)cout<<' ';cout<<a[i];}cout << "\n";}
ld PI=3.14159265358979323846;

int main(){
    ll H,W,N,sr,sc;
    cin >> H >> W >> N;
    cin >> sr >> sc;
    string S,T;
    cin >> S >> T;
    map<char, ll> SS, TT;
    bool flag = false;
    ll L,R,U,D;
    L=sc-1;
    R=sc-1;
    U=sr-1;
    D=sr-1;
    rep(i,N){
        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 < 0 || W <= L){
            flag = true;
            break;
        }else if(R < 0 || W <= R){
            flag = true;
            break;
        }else if(U < 0 || H <= U){
            flag = true;
            break;
        }else if(D < 0 || H <= D){
            flag = true;
            break;
        }
        if(T[i]=='L'){
            R--;
        }else if(T[i]=='R'){
            L++;
        }else if(T[i]=='U'){
            D--;
        }else if(T[i]=='D'){
            U++;
        }
        if(W <= L){
            L = W-1;
        }
        if(R < 0){
            R = 0;
        }
        if(H <= U){
            U = H -1;
        }
        if(D < 0){
            D = 0;
        }
        /*
        SS[S[i]]++;
        TT[T[i]]++;
        if(sc <= SS['L'] - max(TT['R'], W-1) ||
            W-sc < SS['R'] - max(TT['L'], W-1) ||
            sr <= SS['U'] - TT['D'] ||
            H-sr < SS['D'] - TT['U']){
            flag = true;
            break;
        }*/   
    }
    cout << (flag?"NO":"YES") << endl;
}


Measured memory_bytes: 3928
#include<bits/stdc++.h>
using namespace std;
//#include<boost/multiprecision/cpp_int.hpp>
//using boost::multiprecision::cpp_int;

#define int long long
#define cint cpp_int
#define endl "\n"
#define REP(i,a,n) for(int i=a;i<n;++i)
#define REPR(i,a,n) for(int i=a;i>n;--i)
#define RUP(a,b) ((a+b-1)/(b))
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define MOD 1000000007
#define INF LLONG_MAX/2
#define PI acos(-1.0)

typedef long long ll;
typedef pair<int,int> Pii;
typedef tuple<int,int,int> Tiii;
typedef vector<int> Vi;
typedef vector<Vi> VVi;
typedef vector<Pii> VPii;
typedef vector<string> Vs;

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;}
template<class T> void YesNo(T a) {cout<<(a?"Yes":"No")<<endl;}
template<class T> void YESNO(T a) {cout<<(a?"YES":"NO")<<endl;}
void vout(Vi &v){for(int i=0;i<(v).size();i++) cout<<v[i]<<" ";cout<<endl;}
void vvout(VVi &v){for(int i=0;i<(v).size();i++) vout(v[i]);}
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a,int b){return a/gcd(a,b)*b;}
int mypow(int x, int n, int m){if(n==0)return 1;if(n%2==0)return mypow(x*x%m,n/2,m);else return x*mypow(x,n-1,m)%m;}
int digit(int k,int i){string s = to_string(k);return s[s.size()-i]-'0';}
void uniq(Vi &v){sort(v.begin(),v.end()); v.erase(unique(v.begin(),v.end()),v.end());}
int ctoi(char c){if(c>='0'&&c<='9'){return c-'0';}return 0;}
Vi accum(Vi v){Vi ret((v).size());ret[0]=v[0];REP(i,1,(v).size()) ret[i]=ret[i-1]+v[i];return ret;}
bool comp(Pii a,Pii b){
    if(a.second != b.second) return a.second<b.second;
    else return a.first<b.first;
}




// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
signed main(){
    int n;
    cin>>n;
    Vi a(n);
    REP(i,0,n) cin>>a[i];
    bool check=true;
    REP(i,0,n){
        if(a[i]%2==0){
            if(a[i]%3!=0 && a[i]%5!=0) check=false;
        }
    }
    if(check) cout<<"APPROVED"<<endl;
    else cout<<"DENIED"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long 
#define ld long double
#define X first
#define Y second
#define pb push_back
#define max_el(x) max_element(x.begin(),x.end())-x.begin()
#define min_el(x) min_element(x.begin(),x.end())-x.begin()
#define mp make_pair
#define endl '\n'
#define fastread ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
// DONT USE MEMSET, USE VECTORS

void solve(){
	int x;
	cin>>x;
	if(x<1200){
		cout<<"ABC"<<endl;
	}
	else{
		cout<<"ARC"<<endl;
	}
}

int main(){
	fastread;
	int t = 1;
	// cin>>t;
	for(int i=1;i<=t;i++){
		// cout<<"Case #"<<i<<": ";
		solve();
	}
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

ll pow_mod(ll a, ll x, ll p) {
    ll res = 1;
    for (ll i = 0; (x >> i) > 0 ; i++) {
        if ((x >> i) & 1) res = (res * a) % p;
        a = (a * a) % p;
    }
    return res;
}

int main()
{
    ll N;
    cin >> N;
    vector<ll> A(N);
    for (ll i = 0; i < N; i++) cin >> A[i];
    sort(A.begin(), A.end());

    bool valid = true;
    if (A[0] == 0 && N % 2 == 1) { // 0, 2, 2, 4, 4, ..., 2m, 2m
        for (ll i = 1; i < N; i += 2) {
            if (A[i] != i + 1 || A[i + 1] != i + 1) valid = false;
        }
    }
    else if (A[0] == 1 && N % 2 == 0) { // 1, 1, 3, 3, ..., 2m, 2m
        for (ll i = 0; i < N; i += 2) {
            if (A[i] != i + 1 || A[i + 1] != i + 1) valid = false;
        }
    }
    else valid = false;

    if (valid) {
        ll p = 1000000007;
        cout << pow_mod(2, N / 2, p) << endl;;
    }
    else {
        cout << 0 << endl;
    }

    return 0;
}


Measured memory_bytes: 1024
use std::vec::Vec;
use std::iter::FromIterator;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple4<T: std::str::FromStr + Copy>() -> (T, T, T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 4);
  (v[0], v[1], v[2], v[3])
}

fn main() {
    let (sx, sy, tx, ty) = read_touple4::<i64>();
    let mut ans = Vec::new();
    let u = 'U';
    let d = 'D';
    let l = 'L';
    let r = 'R';
    let mut step_1_1 = vec![r; (tx - sx) as usize];
    let mut step_1_2 = vec![u; (ty - sy) as usize];

    let mut step_2_1 = vec![l; (tx - sx) as usize];
    let mut step_2_2 = vec![d; (ty - sy) as usize];

    let mut step_3_1 = vec![l; 1];
    let mut step_3_2 = vec![u; (ty - sy) as usize + 1];
    let mut step_3_3 = vec![r; (tx - sx) as usize + 1];
    let mut step_3_4 = vec![d; 1];

    let step_4_1 = vec![r; 1];
    let step_4_2 = vec![d; (ty - sy) as usize + 1];
    let step_4_3 = vec![l; (tx - sx) as usize + 1];
    let step_4_4 = vec![u; 1];

    let v = vec![
      step_1_1, step_1_2,
      step_2_1, step_2_2,
      step_3_1, step_3_2, step_3_3, step_3_4,
      step_4_1, step_4_2, step_4_3, step_4_4,
    ];

    for step in v {
      for x in step {
        ans.push(x);
      }
    }
    let s = String::from_iter(ans);
    println!("{}", s);

}


Measured memory_bytes: 4352
#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 map<int, int> mi;
typedef pair<int, int> pi;
typedef long long ll;

void solve() {
  int N, M;
  cin >> N >> M;
  if (N > M) {
    cout << 0 << endl;
    return;
  }
  vi X(M, 0);
  vi L(M - 1, 0);
  for (int i = 0; i < M; i++) {
    cin >> X[i];
  }
  sort(all(X));
  for (int i = 0; i < M - 1; i++) {
    L[i] = X[i + 1] - X[i];
  }
  sort(rall(L));
  int ans = X[X.size() - 1] - X[0];
  for (int i = 0; i < N - 1; i++) {
    ans -= L[i];
  }
  cout << ans << endl;
}

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

  solve();

  return 0;
}

Measured memory_bytes: 1024
#include<iostream>

using namespace std;

bool isPrime (int x) {
    for(int i=2; i*i<=x; i++) {
        if(x%i==0) return false;
    }
    return true;
}

int N;
int main () {
    cin >> N;
    long long int ans = 1;
    int mod = 1000000007;
    for(int i=2; i<=N; i++) {
        if(isPrime(i)) {
            int ret = 1;
            for(int j=N; j/=i; ret+=j);
            ans = ans * ret  % mod;

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

Measured memory_bytes: 256
#include <stdio.h>
#define REP(i,n) for(int i=0; i< int(n); (i)++)

int main()
{
    int n,a=0,b=0,tmp_a,tmp_b;
    scanf("%d",&n);
    REP(i,n)
    {
        scanf("%d %d",&tmp_a,&tmp_b);
        if(a < tmp_a)
        {
            a = tmp_a;
            b = tmp_b;
        }
    }
    printf("%d\n",a+b);
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <complex>
#include <utility>
#include <vector>
#include <string>
#include <stack>
#include <queue>
#include <tuple>
#include <cmath>
#include <bitset>
#include <cctype>
#include <set>
#include <map>
#include <unordered_map>
#include <numeric>
#include <functional>
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(ll i=ll(a);i<ll(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define PRINT(V) cout << V << "\n"
#define SORT(V) sort((V).begin(),(V).end())
#define RSORT(V) sort((V).rbegin(), (V).rend())
using namespace std;
using ll = long long;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
inline void Yes(bool condition){ if(condition) PRINT("Yes"); else PRINT("No"); }
template<class itr> void cins(itr first,itr last){
    for (auto i = first;i != last;i++){
        cin >> (*i);
    }
}
template<class itr> void array_output(itr start,itr goal){
    string ans = "",k = " ";
    for (auto i = start;i != goal;i++) ans += to_string(*i)+k;
    if (!ans.empty()) ans.pop_back();
    PRINT(ans);
}
ll gcd(ll a, ll b) {
    return a ? gcd(b%a,a) : b;
}
const ll INF = 1e15;
const ll MOD = 1000000007;
const ll MOD2 = 998244353;
typedef pair<ll,ll> P;
typedef pair<double,double> point;
const ll MAX = 200005;
constexpr ll nx[8] = {1,0,-1,0,1,-1,1,-1};
constexpr ll ny[8] = {0,1,0,-1,1,1,-1,-1};
int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,m;
    cin >> n >> m;
    vector<bool> a(m,1);
    vector<vector<ll>> sport(n,vector<ll>(m,0));
    rep(i,n){
        rep(j,m){
            cin >> sport[i][j];
            sport[i][j]--;
        }
    }
    ll ans = INF;
    rep(i,m){
        vector<ll> cnt(m,0);
        ll ma = 0;
        rep(j,n){
            rep(k,m){
                ll s = sport[j][k];
                if (a[s]){
                    cnt[s]++;
                    chmax(ma,cnt[s]);
                    break;
                }
            }
        }
        chmin(ans,ma);
        rep(j,m){
            if (cnt[j] == ma){
                a[j] = 0;
                break;
            }
        }
    }
    PRINT(ans);
}


Measured memory_bytes: 3960
S = list(input().strip())

odd_cond = ("R", "U", "D")
even_cond = ("L", "U", "D")


for i, s in enumerate(S):
    if i % 2 == 0:
        cond = s in odd_cond
    else:
        cond = s in even_cond

    if not cond:
        print("No")
        break

if cond:
    print("Yes")


Measured memory_bytes: 2940
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <cmath>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <stdio.h>
#include <bitset>
#include <cstring>
using namespace std;
#define FOR(I,A,B) for(int I = (A); I < (B); ++I)
#define CLR(mat) memset(mat, 0, sizeof(mat))
typedef long long ll;

int main()
{
  int A, B; cin >> A >> B;
  int a[A], b[B];
  FOR(i,0,A) cin >> a[i];
  FOR(i,0,B) cin >> b[i];
  int ans = 0;
  FOR(i,0,B) {
    // [i,kb]?????????
    int cnt = 0;
    int ka = 0, kb = i;
    while(ka < A) {
      if(b[kb] == a[ka]) {
        cnt++;
        kb++;
      }
      ka++;
    }
    ans = max(ans, cnt);
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 3172
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define INF 0x3f3f3f3f
int main(){
	int n,x,t; 
	scanf("%d %d %d",&n,&x,&t);
	if(x>=n)
	cout<<t<<endl;
	else
	{
	int y;
	y=n/x;
	if(n%x!=0)
	y++;
	cout<<y*t;	
	}
    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
int main()
{
  int N, A, ans = 0;
  cin >> N;
  vector<vector<pair<int, bool>>> P(N);
  rep(i, N) {
    cin >> A;
    rep(j, A) {
      int x, y;
      cin >> x >> y;
      P.at(i).push_back({x-1, y});
    }
  }

  for (int bit = 0; bit < (1 << N); bit++) {
    vector<int> S(N, 0);
    for (int i = 0; i < N; i++) if (bit & (1 << i)) S.at(i) = 1;
    bool ok = true;
    rep(i, S.size()) {
      if (S[i]) {
        for (auto p : P[i]) {
          if (S[p.first] != p.second) {
            ok = false;
            break;
          }
        }
      }
    }
    if (ok) {
      int cnt = 0;
      for (auto b : S) if (b) cnt++;
      ans = max(ans, cnt);
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        @SuppressWarnings("resource")
        Scanner sc = new Scanner(System.in);
        int k = sc.nextInt();
        String s = sc.next();
        if (s.length() <= k) {
            System.out.println(s);
        } else {
            System.out.println(s.substring(0, k) + "...");
        }
    }

}

Measured memory_bytes: 38664
/* template.cpp {{{ */
#include <bits/stdc++.h>
using namespace std;
#define get_macro(a, b, c, d, name, ...) name
#define rep(...) get_macro(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep(...) get_macro(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define rep1(n) rep2(i_, n)
#define rep2(i, n) rep3(i, 0, n)
#define rep3(i, a, b) rep4(i, a, b, 1)
#define rep4(i, a, b, s) for (ll i = (a); i < (ll)(b); i += (ll)(s))
#define rrep1(n) rrep2(i_, n)
#define rrep2(i, n) rrep3(i, 0, n)
#define rrep3(i, a, b) rrep4(i, a, b, 1)
#define rrep4(i, a, b, s) for (ll i = (ll)(b) - 1; i >= (ll)(a); i -= (ll)(s))
#define each(x, c) for (auto &&x : c)
#define fs first
#define sc second
#define all(c) begin(c), end(c)
using ui = unsigned;
using ll = long long;
using ul = unsigned long long;
using ld = long double;
const int inf = 1e9 + 10;
const ll inf_ll = 1e18 + 10;
const ll mod = 1e9 + 7;
const ll mod9 = 1e9 + 9;
const int dx[]{-1, 0, 1, 0, -1, 1, 1, -1};
const int dy[]{0, -1, 0, 1, -1, -1, 1, 1};
template<class T, class U> void chmin(T &x, const U &y){ x = min<T>(x, y); }
template<class T, class U> void chmax(T &x, const U &y){ x = max<T>(x, y); }
struct prepare_ { prepare_(){ cin.tie(nullptr); ios::sync_with_stdio(false); cout << fixed << setprecision(12); } } prepare__;
/* }}} */

int main(){
  int d, e;
  while (cin >> d >> e, d){
    double res = 1e8;
    rep(x, d + 1){
      int y = d - x;
      chmin(res, abs(sqrt(x * x + y * y) - e));
    }
    cout << res << endl;
  }
}

Measured memory_bytes: 3284
import sys
def MI(): return map(int,sys.stdin.readline().rstrip().split())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり


N,M = MI()
a = LI()

count = 0  # 順送りボタンだけを用いたときのボタンを押す回数
X = [0]*(2*M+1)
Y = [0]*(2*M+1)
# (X[0]+…+X[i])*i+(Y[0]+…+Y[i]) = お気に入りボタンをiに設定した時に、ボタンの押す回数を何回節約できるか

for i in range(N-1):
    a0,a1 = a[i],a[i+1]
    count += (a1-a0) % M
    if a0 > a1:
        a1 += M
    if a0 == a1:
        continue
    X[a0+2] += 1
    X[a1+1] -= 1
    Y[a0+2] -= a0+1
    Y[a1+1] += a0+1

from itertools import accumulate

X = list(accumulate(X))
Y = list(accumulate(Y))

A = [0]*(M+1)
for i in range(1,M+1):
    A[i] = (X[i]*i+Y[i]) + (X[i+M]*(i+M)+Y[i+M])

print(count-max(A))


Measured memory_bytes: 114664
import qualified Data.Text as T
import qualified Data.Text.IO as T
import qualified Data.Text.Read as T

main :: IO ()
main = do
  let
    modulus = 1000000007 :: Int
    modAdd :: Int -> Int -> Int
    modAdd x y = (x + y) `mod` modulus
    modMul :: Int -> Int -> Int
    modMul x y = (x * y) `mod` modulus
  n <- unsafeTextToInt <$> T.getLine :: IO Int
  as <- map unsafeTextToInt . T.words <$> T.getContents :: IO [Int]
  let
    bs = scanl modAdd 0 as :: [Int]
  print . foldl modAdd 0 $ zipWith modMul bs as

unsafeTextToInt :: T.Text -> Int
unsafeTextToInt s = case T.signed T.decimal s of
  Right (n, _) -> n
{-# INLINE unsafeTextToInt #-}


Measured memory_bytes: 17712
#include<bits/stdc++.h>
#include<algorithm>
#include<math.h>
#define ll long long int
#define ld long double
using namespace std;
ll arr[2006][3];
ll num[2006];
ll play[100][3];
int main(){
    ll n, x;
    cin >> n;
    ll cnt = 1;
    for(ll i = 1; i <= n; i++) {
        cin >> x;
        if(x % 2) continue;
        if(x % 3 && x % 5){
            cnt = 0;
            break;
        }
    }

    if(cnt) cout << "APPROVED";
    else cout << "DENIED";
}


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

using namespace std;

typedef long long ll;

int main () {
  int n, W;
  cin >> n >> W;
  vector <ll> v(n), w(n);
  for (int i = 0; i < n; i++) cin >> w[i] >> v[i];
  vector <ll> dp(W + 1, 0);
  for (int i = 0; i < n; i++) {
    vector <ll> newDP(W + 1, 0);
    if (w[i] <= W) newDP[w[i]] = v[i];
    for (int j = 1; j <= W; j++) {
      newDP[j] = max(newDP[j], dp[j]);
      if (dp[j] > 0 and j +  w[i] <= W) newDP[j + w[i]] = max(newDP[j + w[i]], dp[j] + v[i]);
    }
    dp = newDP;
  }
  cout << *max_element(begin(dp), end(dp)) << endl;
  return (0);
}


Measured memory_bytes: 1804
#include <iostream>

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

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "YES";
const string NO = "NO";

void solve(ll A, ll B, ll X) {
  bool pred = A <= X && X <= A+B;
  cout << (pred ? YES : NO) << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll X;
  cin >> X;
  solve(A, B, X);
  return 0;
}


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

int main(){
  int N;
  cin >> N;
  vector<int> value(N);
  
  for(int i=0; i<N; i++){
    cin >> value.at(i);
  }
  
  sort(value.begin(), value.end());
  
  double answer = value.at(0);
  for(int i=0; i<N-1; i++){
    answer = (answer + value.at(i+1))/2;
  }
  cout << answer << endl;
  
  return 0;
}

Measured memory_bytes: 256
import  java.util.Scanner;
        public   class Main {
               public static void main(String[] args) {
                   Scanner scan = new Scanner(System.in);
                   String S;
                   S = scan.nextLine();
                   if (S.charAt(S.length() - 1) == 's') System.out.println(S + "es");
                   else System.out.println(S + "s");
               }
           }


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

using ll = long long int;

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

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

int n;
ll a[MAX_N];
ll b[MAX_N];

ll ans;

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

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

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

  ans = 0LL;

  for (int i = n - 1; i >= 0; --i) {
    ll tmp = min(b[i], a[i + 1]);

    ans += tmp;

    a[i + 1] -= tmp;
    b[i] -= tmp;

    if (b[i] == 0) continue;

    tmp = min(b[i], a[i]);

    ans += tmp;

    a[i] -= tmp;
    // b[i] -= tmp;
  }

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


Measured memory_bytes: 1792
/**< 🤣🤣🤣 */
#include<bits/stdc++.h>
using namespace  std ;
typedef long long  ll;
typedef pair<ll, ll> Pll;
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define deb(X) cout << (X) << endl
#define ASH(X) cout << (X) << " "
#define all(x) x.begin(),x.end()
#define deb1(x) cout << #x << " " << x << endl;
#define deb2(x,y) cout << #x << " " << x << " " << #y << " " << y << endl;
#define deb3(x,y,z) cout << #x << " " << x << " " << #y << " " << y << #z << " " << z << endl;
#define FOR(I,A,B) for(ll I = (A); I <= (B); I++)
#define RFOR(I,B,A) for(ll I = (B); I >=(A); I--)
#define Time cerr<<"Time elapsed: "<<1.0*clock()/CLOCKS_PER_SEC<< "sec \n"
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define SORT(c) (sort(c.begin(),c.end()))
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define CASES int ___T; cin >> ___T; for(int cs=1;cs<=___T;cs++)
#define IOS  ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
template<typename T>T gcd(T x, T y){if(y==0)return x;else return gcd(y,x%y);}
ll fx[] = {1, 1, 0, -1, -1, -1, 0, 1};
ll fy[] = {0, 1, 1, 1, 0, -1, -1, -1};
const long long INF = 1e18;
const int mod = 1e9 + 7;
const int inf = 1e9;
const int mx = 32000;
vector<ll>a1,b1,c1;
map<ll,ll>m1,m2,m3;
bool isPrime[mx];

ll POWER(ll y,ll z){ll res=1;while(z){if(z%2==1){res=(res*y)%mod;}y=(y*y)%mod;z>>=1LL;}return res;}
void sieve(){for(ll i=2; i<=mx; i++)isPrime[i]=true;for(ll i=3; i<=mx; i+=2){if(isPrime[i]==true)
{for(ll J=i*i; J<=mx; J+=i)isPrime[J]=false;}}}

/************************************************/

void Execute()
{
      ll n, nb, val, q, a, b, c, l, r, d, x, y, p, m;
      map<string,ll>MAP;
      cin >> n;
      string s;
      while(n--){
        cin >> s;
        MAP[s]++;
      }

      cout << "AC x " << MAP["AC"] <<endl;
      cout << "WA x " << MAP["WA"] <<endl;
      cout << "TLE x " << MAP["TLE"] <<endl;
      cout << "RE x " << MAP["RE"] <<endl;





}

int32_t main()
{
  //  #ifndef ONLINE_JUDGE
    //freopen("atomm.txt", "r", stdin);
    //#endif

    IOS
    //CASES
    //{
        Execute();
      //  Time;
  //  }
}
/**< 🤣🤣🤣 */


Measured memory_bytes: 3660
from collections import defaultdict, deque

N = int(input())
X = defaultdict(list)
for i in range(N - 1):
    ai, bi = map(lambda s: int(s) - 1, input().split())
    X[ai].append(bi)
    X[bi].append(ai)
c = list(map(int, input().split()))

c.sort(reverse=True)
print(sum(c[1:]))
d = [0] * N
q = deque([0])
i = 0
while len(q) > 0:
    v = q.popleft()
    d[v] = c[i]
    i += 1
    for x in X[v]:
        if d[x] != 0:
            continue
        q.append(x)
print(' '.join(list(map(str, d))))


Measured memory_bytes: 6576
package main

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

var sc = bufio.NewScanner(os.Stdin)

func nextInt() (int, error) {
	sc.Scan()
	s := sc.Text()
	return strconv.Atoi(s)
}

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

	a, _ := nextInt()
	b, _ := nextInt()

	o := "=="
	if a < b {
		o = "<"
	} else if a > b {
		o = ">"
	}

	fmt.Printf("a %s b\n", o)
}



Measured memory_bytes: 1080
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;

int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);

    int x, y, z;
    cin >> x >> y >> z;

    int K;
    cin >> K;
    vector<long long> A(x);
    vector<long long> B(y);
    vector<long long> C(z);
    for (int i = 0; i < x; ++i) {
        cin >> A[i];
    }
    for (int i = 0; i < y; ++i) {
        cin >> B[i];
    }
    for (int i = 0; i < z; ++i) {
        cin >> C[i];
    }

    if (A.size() > B.size()) {
        swap(A, B);
    }
    if (A.size() > C.size()) {
        swap(A, C);
    }
    if (B.size() > C.size()) {
        swap(B, C);
    }
    int n = A.size();
    int m = B.size();
    int l = C.size();

    vector<long long> sums;
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < m; ++j) {
            sums.push_back(A[i] + B[j]);
        }
    }
    sort(sums.begin(), sums.end(), greater<long long>());
    if (sums.size() > K) {
        sums.resize(K);
    }
    vector<long long> X;
    for (auto x : C) {
        for (auto y : sums) {
            X.push_back(x + y);
        }
    }
    sort(X.begin(), X.end(), greater<long long>());

    for (int i = 0; i < K; ++i) {
        cout << X[i] << '\n';
    }


    return 0;
}

Measured memory_bytes: 43368
#include <stdio.h>

const int Mod = 1000000007;
long long bit[61], pow[61];

long long recursion(long long L, long long R)
{
	int i, j;
	if (L > R) return 0;
	else if (L == R) return 1;
	else if (L == 0) {
		for (i = 0; bit[i] <= R; i++);
		return (recursion(0, R ^ bit[i-1]) * 2 + pow[i-1]) % Mod;
	} else {
		for (i = 0; bit[i] <= L; i++);
		for (j = 0; bit[j] <= R; j++);
		if (i == j) return recursion(L ^ bit[i-1], R ^ bit[j-1]);
		else return (recursion(0, R ^ bit[j-1]) + recursion(L, R ^ bit[j-1]) + recursion(0, L ^ (bit[j-1] - 1))) % Mod;
	}
}

int main ()
{
	long long L, R;
	scanf("%lld %lld", &L, &R);

	int i, j, k;
	long long ans;
	for (i = 1, bit[0] = 1, pow[0] = 1; i <= 60; i++) {
		bit[i] = bit[i-1] << 1;
		pow[i] = pow[i-1] * 3 % Mod;
	}
	for (i = 0; bit[i] <= L; i++);
	for (j = 0; bit[j] <= R; j++);
	if (i == j) ans = recursion(L ^ bit[i-1], R ^ bit[j-1]);
	else {
		ans = recursion(0, L ^ (bit[i] - 1)) + recursion(0, R ^ bit[j-1]);
		for (k = i + 1; k < j; k++) ans += pow[k-1];
		ans %= Mod;
	}
	printf("%lld\n", ans);
	fflush(stdout);
	return 0;
}

Measured memory_bytes: 1640
def run(n, s):
    '''
    文字列sを半分に分けて、右半分を逆順に並び替える
    さらに色の塗分けを逆にすると、左半分と右半分は
    同じになる
    '''
    sl = s[0:n]
    sr = s[n:2*n][::-1]

    dic = {}
    keys = []
    cnt = 0

    for i in range(2**n):
        red, blue, red2, blue2 = '', '', '', ''
        bits = bin(2**n+i)[3:]
        for j in range(n):
            if bits[j] == '0':
                red += sl[j]
                red2 += sr[j]
            else:
                blue += sl[j]
                blue2 += sr[j]
        keys.append(red2 + '-' + blue2)
        key = red + '-' + blue
        if key not in dic.keys():
            dic[key] = 1
        else:
            dic[key] += 1

    for key in keys:
        cnt += dic.get(key, 0)
    return cnt

    '''
    keys1 = [c[0]+'-'+c[1] for c in comb(sl)]
    keys2 = [c[0]+'-'+c[1] for c in comb(sr)]
    cnt = 0
    for key1 in keys1:
        cnt += keys2.count(key1)
    return cnt
    '''
    '''
    dict = {}
    for t0, t1 in keys:
        key = t0 + '-' + t1
        cnt = has_key(sr, t0, t1)
        if key in dict:
            dict[key] += cnt
        else:
            dict[key] = cnt
    return sum(dict.values())
    '''


'''
def comb(s):
    if len(s) == 1:
        return [(s, ''), ('', s)]
    else:
        ret = []
        for c in comb(s[0:len(s)-1]):
            ret.append((c[0]+s[-1], c[1]))
            ret.append((c[0], c[1]+s[-1]))
        return ret
'''


'''
def has_key(s, t0, t1):
    cnt = 0
    if len(s) == 1:
        if s == t0:
            return 1
        elif s == t1:
            return 1
        else:
            return 0
    else:
        a = s[0]
        if len(t0) != 0 and a == t0[0]:
            cnt += has_key(s[1:len(s)], t0[1:len(t0)], t1)
        if len(t1) != 0 and a == t1[0]:
            cnt += has_key(s[1:len(s)], t0, t1[1:len(t1)])
    return cnt
'''


def read_line():
    n = int(input())
    s = input()
    return (n, s)


def main():
    n, s = read_line()
    print(run(n, s))


if __name__ == '__main__':
    main()


Measured memory_bytes: 56660
#include <iostream>
#include <cmath>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

#define FOR(i, a, b) for(int i = (a); i < (b); i++)
#define REP(i, n)  FOR(i, 0, n)
#define ASC(c) sort((c).begin(), (c).end())
#define DESC(c) sort((c).begin(), (c).end(), greater<int>())

#define DUMP(x)  cerr << #x << " = " << (x) << endl;
#define DEBUG(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef long long ll;
typedef unsigned long long ull;
struct edge { int u, v; ll w; };
 
ll MOD = 1000000007;
ll _MOD = 1000000009;
double EPS = 1e-10;

int main() {
    int n; cin >> n;
    vector<int> p(n);
    REP(i, n) cin >> p[i];
    int ans = 1, min_val = p[0];
    FOR(i, 1, n) {
        if (p[i] < min_val) {
            ans++;
            min_val = p[i];
        }
    }
    cout << ans << endl;
}


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

int main(){
  
  int N, M, i;
  cin >> N >> M;
  
  vector<int> s(M), c(M);
  
  for (i = 0; i < M; i++){
    
    cin >> s.at(i) >> c.at(i);
  }
  
  string Suuji;
  for (i = 0; i < 1001; i++){
    
    bool flag = 0;
    Suuji     = to_string(i);
    
    if(Suuji.size() != N) continue;
    //if(Suuji.size() <  M) continue;
    
    for (int j = 0; j < M; j++){
      
      if(Suuji.at(s.at(j) - 1) != to_string(c.at(j)).at(0)){
        flag = 1;
        break;
      }
    }
    
    if(!flag){
       cout << i << endl;
       return 0;
    }
  }
  cout << -1 << endl;
  return 0;
}

Measured memory_bytes: 256