akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int K, R, L;
double P, E, T;
double dfs(int time, double l, double r){
  assert(l <= r);
  double h = (l + r) / 2;
  if(time == 0){
    if(abs(h - T) <= E) return 1.0;
    else return 0.0;
  }
  if(T - E <= l && r <= T + E) return 1.0;
  if(r < T - E) return 0.0;
  if(T + E < l) return 0.0;
  if(h < T){
    return (1 - P) * dfs(time - 1, h, r) + P * dfs(time - 1, l, h);
  }else{
    return P * dfs(time - 1, h, r) + (1 - P) * dfs(time - 1, l, h);
  }
}

int main(){
  while(cin>>K>>L>>R>>P>>E>>T){
    printf("%.6f\n", dfs(K, L, R));
  }
  return 0;
}

Measured memory_bytes: 1252
#include <iostream>
#include <string>
#include <array>
#include <vector>
#include <queue>
#include <stack>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>
#include <iomanip>

#define FOR(i, a, b) for(decltype(b) i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned int uint;

using namespace std;

#ifdef INPUT
#include <sstream>
stringstream input(R"(
12001021211100201020
)");
#define cin input
#endif

int p[4096][4096];

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

	int n = s.size() * 2;

	p[0][0] = 1;

	int nr = 0, nb = 0;
	REP (i, n)
	{
		if (i < n / 2)
		{
			switch (s[i])
			{
			case '0':
				nr += 2;
				break;
			case '1':
				++nr;
				++nb;
				break;
			case '2':
				nb += 2;
				break;
			}
		}

		REP (j, i + 2)
		{
			int k = i + 1 - j;
			if (k > nb || j > nr)
				continue;
			if (j > 0)
				p[j][k] += p[j - 1][k];
			if (k > 0)
				p[j][k] += p[j][k - 1];
			p[j][k] %= 998244353;
		}

	}


	cout << p[nr][nb] << endl;

	return 0;
}


Measured memory_bytes: 64256
#include <stdio.h>
int main(void)
{
	int w;
	int m;
	int k = 1150;
	
	
	scanf("%d", &w);
	while (w != -1) {
		if(w <= 10) {
			m = k;
		}else if(w <= 20) {
			m = k + 125 * (w - 10);
		}else if(w <= 30) {
			m = k + 140 * (w - 20) + 1250;
		}else if(w > 30) {
			m = k + 160 * (w - 30) + 1250 + 1400;
		}
		printf("%d\n", 4280 - m);
		scanf("%d", &w);
	}
	
	return (0);
}

Measured memory_bytes: 0
n = int(input())
arr = [int(x) for x in input().split()]
cnt = [0] * (10 ** 5 + 1)
for a in arr:
    cnt[a] += 1
    cnt[a+1] += 1
    if a > 0:
        cnt[a-1] += 1

print(max(cnt))

Measured memory_bytes: 20104
#![allow(unused_imports)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;
use std::ops::Bound::*;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let n = read::<usize>();
    let mut a = read_vec::<i64>();
    let mut b = read_vec::<i64>();

    let mut ans = 0;
    for i in 0..n {
        let reduced = min(a[i], b[i]);
        a[i] -= reduced;
        b[i] -= reduced;
        ans += reduced;
        let reduced = min(a[i + 1], b[i]);
        a[i + 1] -= reduced;
        b[i] -= reduced;
        ans += reduced;
    }
    println!("{}", ans);
}

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()
}


Measured memory_bytes: 4940
n,d = map(int,input().split())

# d = 2   1 2 3 4 5

if n % (d * 2 + 1) != 0:
  print(int(n / (d * 2 + 1)) + 1)
  exit()
  
print(int(n / (d * 2 + 1)))

Measured memory_bytes: 2940
#include <algorithm>
#include <vector>
#include <array>
#include <set>
#include <map>
#include <climits>
#include <cmath>
#include <iostream>
#include <iomanip>
#include <numeric>
#include <fstream>
#include <math.h>

using namespace std;

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

	bool approved = true;
	for (int i = 0; i < n; i++) {
		if (a[i] % 2 == 0) {
			if (!(a[i] % 3 == 0 || a[i] % 5 == 0)) {
				approved = false;
				break;
			}

		}
	}
	if (approved)
		cout << "APPROVED" << endl;
	else
		cout << "DENIED" << endl;
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
int main() {
    int i,count=0;
	char s[3],t[3];
	scanf("%s\n",s);
	scanf("%s",t);
	for(i=0;i<3;i++)
	{
	    if(s[i]==t[i])
	    count++;
	}
	printf("%d",count);
	
	return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#define PI 3.141592653589
typedef long long ll;
const int MOD = 1000000007;
const int INF = 2002002002;
const int di[] = { -1, 0, 1, 0 };
const int dj[] = { 0, -1, 0, 1 };
using namespace std;

int main() {
	string s, t;
	cin >> s >> t;
	if (s == t.substr(0, s.size()) && t.size() == s.size() + 1)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}


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

const int N=100010;
#define INF 2147483647

int read() {
	int xx=0,ww=1;
	char ch=getchar();
	while(ch>'9'||ch<'0') {
		if(ch=='-') ww=-ww;
		ch=getchar();
	}
	while(ch>='0'&&ch<='9') {
		xx=10*xx+ch-48;
		ch=getchar();
	}
	return xx*ww;
}

int n;
int h[N],f[N];

int main() {
	n=read();
	for(int i=1; i<=n; i++) f[i]=INF,h[i]=read();
	f[0]=f[1]=0;
	for(int i=2; i<=n; i++) {
		if(i>2) {
			f[i]=min(f[i],f[i-1]+abs(h[i]-h[i-1]));
			f[i]=min(f[i],f[i-2]+abs(h[i]-h[i-2]));
		} else f[i]=min(f[i],f[i-1]+abs(h[i]-h[i-1]));
	}
	printf("%d\n",f[n]);
	return 0;
}

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

using namespace std;

int main(){
  int n, a[109], cnt=0;;
  cin >> n;
  for(int i=1;i<=n;i++){
    cin >> a[i];
    if(i%2==1&&a[i]%2==1)cnt++;
  }
  cout << cnt << endl;
}



Measured memory_bytes: 3612
#include <iostream>
#include<cmath>
#include<algorithm>
#include<vector>
#include<map>
using namespace std;

double pi = 2 * asin(1);

int main() {
	map<int, int>mp;
	int i,N, A;
	cin >> N;
	for (i = 1; i < N; i++) {
		cin >> A;
		mp[A]++;
	}
	
	for (i = 1; i < N + 1; i++) {
		cout << mp[i] << endl;
	}
}


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

#define endl '\n'

using namespace std;

struct custom_hash 
{
    static unsigned long long splitmix64(unsigned long long x) 
    {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(unsigned long long x) const 
    {
        static const unsigned long long FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

const int maxn = 4003; 

int n; 
string s;
void read()
{
	cin >> n >> s; 
}

int cnt[maxn][3];
void solve()
{
	for (int i = n; i >= 1; i--)
	{
		for (int j = 0; j < 3; j++)
			cnt[i][j] = cnt[i+1][j];

		if (s[i-1] == 'R')
			cnt[i][0]++;

		else 
			if (s[i-1] == 'G')
				cnt[i][1]++;

			else 
				cnt[i][2]++;
	}

	long long ans = 0;
	for (int i = 1; i <= n; i++)
		for (int j = i+1; j <= n; j++)
			if (s[i-1] != s[j-1])
			{
				bool is[3];
				memset(is, false, sizeof(is));
				if (s[i-1] == 'R' || s[j-1] == 'R')
					is[0] = true;

				if (s[i-1] == 'G' || s[j-1] == 'G')
					is[1] = true;

				if (s[i-1] == 'B' || s[i-1] == 'B')
					is[2] = true; 

				if (!is[0])
					ans += cnt[j+1][0];

				else 
					if (!is[1])
						ans += cnt[j+1][1];

					else 
						ans += cnt[j+1][2];

				int idx = 2 * j - i;
				if (idx <= n && s[idx-1] != s[i-1] && s[idx-1] != s[j-1])
					ans--; 
			}

	cout << ans << endl;
}

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

Measured memory_bytes: 3748
#include<bits/stdc++.h>
using namespace std;
#define IO ios_base::sync_with_stdio(false)
#define ll long long
#define dd double
#define vi vector<int> 
#define li list<int> 
#define pb push_back
 	char a[200009];
 	// int b[200009];
 	// int c[200009];

ll powr(int n)
{
	ll p =  1;
	for(int i = 1; i <= n; i++) p = p*26;

	return p;
}


 int main()
 {
 	ll n;

 	scanf("%lld", &n);

 	int cn= 0, i = 0;
 	int j = 1;
 	while(n)
 	{
 		int m = n % 26;
 		if(m == 0){ a[i] = 'z'; n = n/26 - 1;}

 		else {a[i] = m-1 +'a'; n = n / 26;}
 		cn++;
 		// n = n - a[i];
 		i++;
 	}

 	for(int j = cn-1; j >= 0; j--) printf("%c", a[j]);

 	return 0;
 }

Measured memory_bytes: 3736
use std::str::FromStr;

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

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}
fn get_vec_by_lines<T : FromStr>(n : usize) -> Vec<T> {
    let mut v : Vec<T> = Vec::new();
    for _i in 0..n {
        let x : T = get_one();
        v.push(x);
    }
    return v;
}


fn main() {
    let ab : Vec<f32> = get_vec();
    let a : f32 = ab[0];
    let b : f32 = ab[1];

    let mut ans = -1;
    for i in 1..1300 {
        if ((i as f32) * 0.08_f32).floor() == a && ((i as f32) * 0.1_f32).floor() == b {
            ans = i;
            break;
        }
    }
    println!("{}", ans);

}


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

#define pb push_back
#define pbk pop_back
#define mk_pr make_pair

typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vii;
typedef vector<string> vss;
typedef queue<int> qi;

const int MX = 123456;

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

        int n, a, mx = 0, mn = 123456;
        cin >> n;
        for(int i=0; i<n; i++) {
                cin >> a;
                mx = max(mx, a);
                mn = min(mn, a);
        }

        cout << mx-mn << endl;

        return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
 
using namespace std;
 
int main(){
    int n,m,l;
    scanf("%d %d %d",&n,&m,&l);
    int A[n][m],B[m][l];
    long long int C[n][l];
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l; j++){
            C[i][j] = 0;
        }
    }
 
    for(int i = 0; i < n; i++){
        for(int j = 0; j < m; j++){
            scanf("%d",&A[i][j]);
        }
    }
    for(int i = 0; i < m; i++){
        for(int j = 0; j < l; j++){
            scanf("%d",&B[i][j]);
        }
    }
 
    for(int i = 0; i < n; i++){
        for(int k = 0; k < l; k++){
            for(int j = 0; j < m; j++){
                C[i][k] += A[i][j]*B[j][k];
            }
        }
    }
 
    for(int i = 0; i < n; i++){
        for(int j = 0; j < l-1; j++){
            printf("%lld ",C[i][j]);
        }
        printf("%lld\n",C[i][l-1]);
    }
}


Measured memory_bytes: 2848
#include <bits/stdc++.h>
using namespace std;
// https://atcoder.jp/contests/abc166/tasks/abc166_a
int main()
{
    string in;
    cin >> in;

    if(strcmp("ABC",in.c_str())==0)
    {
        printf("ARC\n");
    }
    else
    {
        printf("ABC\n");

    }
    return 0;
}


Measured memory_bytes: 3592
/**akshaykumar99**/
 
#include<bits/stdc++.h>
using namespace std;
 
#define f(i,x,n) for(i=x;i<n;i++)
#define pu push_back           
#define pp pop_back
#define mp(a,b) make_pair(a,b)
#define F first
#define S second
#define all(v) v.begin(),v.end()
#define rall(v) v.rbegin(),v.rend()
#define IOS() ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
const int MOD=1e9+7 ;
const long long INF=INT_MAX;
const long long LINF=LLONG_MAX;
const long long N=1e5+11;
 
typedef long long ll;
typedef long double ld;
typedef vector<ll> ivc;
typedef pair<ll,ll> ipr;
 
int main()
{
    IOS();
  
    int n,i;
    cin>>n;
    int a[n+1],b[n+1],c[n]={0},ans=0,p=0;
    f(i,1,n+1)
      cin>>a[i];
    f(i,1,n+1)
      cin>>b[i];
    f(i,1,n)
      cin>>c[i];
    f(i,1,n+1)
    {
      if(i==1)
        ans=b[a[i]];
      else
      {  
        if(a[i]-1==a[i-1])
          ans+=b[a[i]]+c[a[i]-1];
        else
          ans+=b[a[i]];
      }
    }
    cout<<ans;


    return 0;
  
}

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

#define sws ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define INFINITO 1000000000
#define ll long long
#define vi vector<int>
#define pb push_back
#define pii pair<int, int>
#define mp make_pair
#define ff first
#define ss second
#define vvi vector<vi>
#define all(x) x.begin(), x.end()
#define fo(i, n) for( int i = 0; i < n; i++ )


int main() {

    int n, k;
    cin >> n >> k;
    vi h(n);
    fo(i, n) cin >> h[i];

    int menor = INFINITO;
    sort(all(h));
    for ( int i = 0; i < n - k + 1; i++ ) {
        menor = min(h[i + k - 1] - h[i], menor);
        // cout << h [i + k - 1] << endl;
    }

    cout << menor << endl;

    return 0;
}

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

class Program
{
    static void Main(string[] args) {
        int[] l = new int[5];
        for (int i = 0; i < 5; i ++) {
            l[i] = int.Parse(Console.ReadLine());
        }
        int[] t = new int[5];
        for(int i = 0; i < 5; i ++) {
            t[i] = l[i];
            for (int j = 0; j < 5; j ++) {
                if (j != i) {
                    if (l[j]%10 == 0) t[i] += l[j];
                    else t[i] += l[j] + 10 - l[j]%10;
                }
            }
        }
        Console.WriteLine(t.Min());
    }
}

Measured memory_bytes: 13268
n, y = map(int, input().split())
y //= 1000
c = -1
for i in range(min(n,y)+1):
    if (y - i) % 5 != 0: continue
    if n - i <= (y - i)/5 and (y - i)/5 <= 2*(n - i):
        c = i
        break
if c == -1:
    print(-1,-1,-1)
else:
    a = (y-c)//5 - n + c
    b = n - a - c
    print(a,b,c)

Measured memory_bytes: 3064
n, m = map(int, input().split())

tree = [0 for _ in range(n+1)]
for _i in range(m):
    a, b = map(int, input().split())
    tree[a] += 1
    tree[b] += 1
if all(i%2==0 for i in tree):
    print("YES")
else:
    print("NO")

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


int main(){
  int n;
  cin >> n;
  int a = 0, b = 0;
  string strt, strh; //taro, hanako
  for ( int i = 0; i < n; i++){
    cin >> strt >> strh;
    if (strt > strh) a += 3;
    else if (strt < strh) b += 3;
    else if (strt == strh) {
      a += 1;
      b += 1;
    }
  }

cout << a << " " << b << endl;

return 0;
}

Measured memory_bytes: 3164
#include <stdio.h>
#include <stdlib.h>
#define MAX 2000001
#define VMAX 10000

int main(){
  unsigned short *A, *B;
  int C[VMAX+1];
  int n, i, j;

  scanf("%d", &n);

  A = malloc(sizeof(short)*n+1);
  B = malloc(sizeof(short)*n+1);

  /* your code */
  for(i=0;i<=VMAX;i++) C[i]=0;

  for(i=0;i<n;i++){
    scanf("%d",&A[i+1]);
    C[A[i+1]]++;
  }

  for(i=1;i<=VMAX;i++) C[i]=C[i-1]+C[i];

  for(j=1;j<=n;j++){
    B[C[A[j]]]=A[j];
    C[A[j]]--;
  }

  for(j=1;j<=n-1;j++){
    printf("%d",B[j]);
    printf("%c",' ');
  }

  printf("%d\n",B[n]);


  return 0;
}



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

int main(int argc, char const *argv[]) {
    long long n, k;
    cin >> n >> k;
    vector<long long> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }

    deque<int> q;
    vector<bool> seen(n, false);
    int cur = 0;
    while (true) {
        if (seen[cur]) {
            while (cur != q[0]) {
                k--;
                q.pop_front();

                if (k == 0) {
                    cout << q[0]+1 << endl;
                    return 0;
                }
            }
            break;
        }

        q.push_back(cur);
        seen[cur] = true;
        cur = a[cur];
    }

    cout << q[k % q.size()] + 1 << endl;
    return 0;
}


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

using namespace std;
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define sz(x) ll(x.size())
typedef long long ll;
typedef pair<int, int> P;
//typedef pair<ll, ll> P;
const ll INF = 1001001001;

const int mod = 1000000007;

int main() {

    int n, k;
    cin >> n >> k;
    int mx = (n - 1) * (n - 2) / 2;

    if (mx < k) {
        cout << -1 << endl;
        return 0;
    }


    int add = mx - k;
    cout << n - 1 + add << endl;

    vector<P> ans;
    rep(i, n - 1) {
        cout << i + 1 << ' ' << n << endl;
    }

    if (add == 0) {
        return 0;
    }

    for (int i = 1; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            cout << i << ' ' << j << endl;
            add--;
            if (add == 0) {
                return 0;
            }
        }
    }
}

Measured memory_bytes: 256
#include <vector>
#include <math.h>
#include <iostream>

using namespace std;

#define MOD ((long long)(1000000000 + 7))
long long ways[2][100001];

long long dfs(vector<vector<int> > &child, int node, int color, int prev){
  
  if(ways[color][node] != -1){
    return ways[color][node] % (MOD);
  }

  ways[color][node] = 1;

  for(int i = 0; i < child[node].size(); i++){
        
    if(child[node][i] == prev) continue;
    if(color == 0){
      ways[color][node] = (ways[color][node] * dfs(child, child[node][i], 1, node)) % (MOD);
      ways[color][node] %= MOD;
    }
    else{
      ways[color][node] = (ways[color][node] * (dfs(child, child[node][i], 0, node) + dfs(child, child[node][i],1, node))) % (MOD);
      ways[color][node] %= MOD;
    }
  }
  
  return ways[color][node] % MOD;
  
}


int main(){

  int N;
  cin >> N;

  vector<vector<int> > child(N + 1);
  for(int i = 0; i < N - 1; i++){
    int a,b;
    cin >> a >> b;
    child[a].push_back(b);
    child[b].push_back(a);
  }

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

  
  dfs(child, 1, 0, -1);
  dfs(child, 1, 1, -1);

  cout << (ways[0][1] + ways[1][1]) % (MOD) << endl;
  
  return 0;
}


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

#define int long long

signed main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  int A, B, C, D;
  cin >> A >> B >> C >> D;

  int sum = B-A+1;  
  if ( C <= B ) {
    
    int e = ((A-1)/C + 1)*C;
    // cout << e << endl;
    sum -= (B-e) / C + 1;    
  }
  if ( D <= B ) {
    int e = ((A-1)/D + 1)*D;
    // cout << e << endl;
    sum -= (B-e) / D + 1;    
  }
  C = C*D/__gcd(C, D);    
  if ( C <= B ) {    
    int e = ((A-1)/C + 1)*C;
    sum += (B-e) / C + 1;    
  }

  cout << sum << endl;
  
  return 0;
}


Measured memory_bytes: 256
from collections import defaultdict

INF = float("inf")

N, X, D = map(int, input().split())

if D == 0:
    print(1 if X == 0 else N + 1)
    quit()

if D < 0:
    X, D = -X, -D

memo = defaultdict(list)
for k in range(N + 1):
    l = k * X + (k - 1) * k // 2 * D
    r = k * X + (N - k + N - 1) * k // 2 * D
    memo[l % D].append((l, r))

ans = 0
for LR in memo.values():
    LR.sort()

    cur = -INF
    for l, r in LR:
        if cur < l:
            ans += (r - l) // D + 1
            cur = r
        if cur < r:
            ans += (r - cur) // D
            cur = r

print(ans)

Measured memory_bytes: 72592
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <cmath>
#include <map>
#include <stdio.h>
using namespace std;
string s;
int  n, a, b, c, d;
int ans;
void dfs(int x, int y)
{
    if(x == y)
    {
        ans += 1;
        return;
    }
    if(x+1 < n && s[x+1] == '.')
    {
        dfs(x+1,y);
    }
    else if(x+2 < n && s[x+2] == '.')
    {
        dfs(x+2,y);
    }
}
 
int main()
{
    scanf("%d %d %d %d %d", &n, &a, &b, &c, &d);
    cin >> s;
    if(d > c)
    {
        dfs(a-1, c-1);
        dfs(b-1, d-1);
    }
    else
    {
        bool over = false;
        for (int i = b-1; i <= d-1; i++) {
            if (s[i-1] == '.' && s[i] == '.' && s[i+1] == '.') 
            {
                over = true;
            }
        }
        if(over)
        {
            dfs(a-1, c-1);
            dfs(b-1, d-1);
        }
    }
    
    if(ans == 2)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }
    
    return 0;
}
 
 
 
    
 

Measured memory_bytes: 640
// created_by  Rishi_Mohan

#include<bits/stdc++.h>

#define    ll           long long
#define    db1(x)       cout<<#x<<"="<<x<<'\n'
#define    db2(x,y)     cout<<#x<<"="<<x<<","<<#y<<"="<<y<<'\n'
#define    db3(x,y,z)   cout<<#x<<"="<<x<<","<<#y<<"="<<y<<","<<#z<<"="<<z<<'\n'
#define    rep(i,n)     for(int i=0;i<(n);++i)
#define    repA(i,a,n)  for(int i=a;i<=(n);++i)
#define    repD(i,a,n)  for(int i=a;i>=(n);--i)

using namespace std;

void solve()
{
  int days , ass;
  cin >> days >> ass;
  vector<int> v(ass);
  rep(i,ass) cin >> v[i];

  sort(v.begin(),v.end());
  int sum = 0;
  int ans = accumulate(v.begin(),v.end(),sum);
   (days-ans>=0) ? cout << days-ans << endl : cout << "-1" << endl;
 // rep(i,ass) cout << v[i] << " " ;
}

int main()
{
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	solve();
}

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,k;cin>>n>>k;
    string ss;cin>>ss;
    int tot=0;
    rep(i,ss.size()-1){
        if(ss[i]==ss[i+1])tot++;
    }
    cout<<min(tot+2*k,n-1)<<'\n';
    return 0;
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
#define ll long long
#define MODV 1000000007
#define INFLL LLONG_MAX // 9223372036854775807
#define EPS 1e-9
#define rep(i, n) for(ll i=0, i##_len=(ll)(n); i<i##_len; i++)
#define repf(i, n) for(ll i=1, i##_len=(ll)(n+1); i<i##_len; i++)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<ll>
#define vvi vector<vector<ll>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
#define Init() std::ios::sync_with_stdio(false); std::cin.tie(0); std::cout<<fixed<<setprecision(15);
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; }
using namespace std;

int main(){
    Init();
    ll x; cin >> x;
    ll k;
    for(k=1;; k++){
        if(k*x %360 == 0) break;
    }
    cout << k << endl;
}

Measured memory_bytes: 3624
#include <bits/stdc++.h>
using namespace std;
#define int         long long
#define mp          make_pair
#define pb          push_back
#define pii         pair<int,int>
#define vi          vector<int>
// #define vb          vector<bool>
// #define vc          vector<char>
#define vii         vector<pii>
//#define mi          map<int,int>
//#define mii         map<pii,int>
#define all(a)      (a).begin(),(a).end()
#define F           first
#define S           second
#define sz(x)       (int)x.size()
// #define ub(x)       upper_bound(x)
// #define lb(x)       lower_bound(x)
#define endl        '\n'
#define file        freopen("b1.in","r",stdin);freopen("output.txt","w",stdout)
#define fastio      ios::sync_with_stdio(false),cin.tie(0),cout.tie(0);
// #define N            1e5+5
// #define M           1e9+7
#define MAX         50000
#define mem0(a)     memset(a,0,sizeof(a))
#define prec        cout<<std::setprecision(9)<<std::fixed
#define forn(i,a,b)  for(int i=a;i<b;i++)
#define pi          3.14159265358979323

struct cmp { 
    bool operator() (pii a,pii b){
        return ((a.F-a.F/2)*a.S)<((b.F-b.F/2)*b.S);
    }
};
// priority_queue<pii,vector<pii>,cmp> q;
// 437235829
const int N=1e5+1;
int n,m,k;

const int MOD=1e9+7;

void Anon_mouS(){
    int n;
    long long cur = 0;
    long long sol = 0;
    cin>>n;
    for(int i=0;i<n;i++){
        int input;
        cin >> input;
        sol = (sol + input*cur%MOD) % MOD;
        cur = (cur + input) % MOD;
    }
    cout<<sol<<endl;
}
int32_t main(){
    fastio;
    int q=1;
    // sieve();
    // cin>>q;
    for(int it=1;it<=q;it++){
        // cout<<"Case #"<<it<<": ";
        Anon_mouS();
    }
    return 0;   
}

Measured memory_bytes: 3620
#include<iostream>
#include<math.h>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
using namespace std;

int main(){
    int n;
    cin>>n;
    string a,b;
    cin>>a>>b;

    rep(i,n){
        if(a.substr(i,n-i) == b.substr(0,n-i)){
            cout<<n+i;
            return 0;
        }
    }
    cout<<n*2;
}

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

using namespace std;

int main(){
    long long n, m;
    cin >> n >> m;
    if(abs(n - m) > 1)cout << 0;
    else{
        long long ans = 1;
        if(n == m){
            for(long long i = 1; i <= n; ++i){
                ans *= i;
                ans %= 1000000007;
            }
            for(long long i = 1; i <= m; ++i){
                ans *= i;
                ans %= 1000000007;
            }
            cout << ans * 2 % 1000000007;
        }else{
            for(long long i = 1; i <= n; ++i){
                ans *= i;
                ans %= 1000000007;
            }
            for(long long i = 1; i <= m; ++i){
                ans *= i;
                ans %= 1000000007;
            }
            cout << ans;
        }

    }

    return 0;

}


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

using namespace std;

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

    int a, b, c;
    cin >> a >> b >> c;

    if(a+b+c>=22) cout << "bust";
    else cout << "win";

    return 0;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()



int main() {
  int n, d, x;
  cin >> n >> d >> x;
  
  rep(i, n) {
    int a;
    cin >> a;
    x += (d-1)/a + 1;
  }
  cout << x << endl;
  return 0;
}

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

#define MOD 998244353
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;

const int MAX = 510000;
ll fac[MAX], finv[MAX], inv[MAX];
 
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
 
// 二項係数計算
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

ll modpow(ll x, ll n){
    ll res = 1;
    ll mul = x;
    while(n){
        if(n % 2) res = res * mul % MOD;
        mul = mul * mul % MOD;
        n /= 2;
    }
    return res;
}

ll modinv(ll x, ll n){
    return modpow(x, n - 2);
}


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

    ll ans = 0;

    rep(i, k+1){
        ll t = n - i - 1;
        ll tmp = COM(n-1, t);
        ll coeff = m * modpow(m-1, t);
        coeff %= MOD;
        ans += (tmp * coeff) % MOD;
        ans %= MOD;
    }

    cout << ans << endl;


    return 0;
}

Measured memory_bytes: 15544
#include<iostream>
#include<set>
using namespace std;
int main()
{
	int n;
	set<int>s;
	cin>>n;
	for(int i=0;i<n;++i){
		int a;
		cin>>a;
		s.insert(a);
	}
	cout<<s.size()<<endl;
	return 0;
}


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

using namespace std;

int main(){
    long N ;
    string S;
    cin >> N >> S;
    //long e, w;
    //e = w = 0;
    long a = 3 * 100000;
    vector<long> e = vector<long>(N);
    vector<long> w = vector<long>(N);
    if(S.at(0) == 'E'){
        e[0] = 1;
    } else {
        w[0] = 1;
    }

    for(int i = 1; i < N; i++) {
        e[i]= e[i-1];
        w[i] = w[i-1];
        if(S.at(i) == 'E'){
            e[i] += 1;
        }
        else{
            w[i]++;
        }
    }
    a = e[N-1] - e[0];

    for(int i = 1; i < N; i++){
        a = min(w[i-1] + e[N-1] - e[i], a);
    }
    cout << a << endl;
    return 0;
}

Measured memory_bytes: 5380
N, K = list(map(int, input().split()))
val_dict = dict()

for _ in range(N):
    a, b = list(map(int, input().split()))
    val_dict[a] = val_dict.get(a, 0) + b

val_keys = sorted(val_dict.keys())

K_rest = K
for key in val_keys:
    K_rest -= val_dict[key]
    if K_rest <= 0:
        print(key)
        break



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

using namespace std;

typedef long long ll;

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

	int N;
	cin >> N;

	vector<string> v(N);
	rep(i, N) cin >> v[i];

	ll ab = 0;
	ll sbea = 0;
	ll sb = 0;
	ll ea = 0;
	for(int i = 0; i < N; i++){
		string s = v[i];

		for(int j = 0; j < s.size()-1; j++){
			if(s[j] == 'A' && s[j+1] == 'B') ab++;
		}

		if(s[0] == 'B' && s[s.size()-1] == 'A') {
			sbea++;
		}else if(s[0] == 'B'){
			sb++;
		}else if(s[s.size()-1] == 'A'){
			ea++;
		}
	}

	ll ans = ab;
	if(sbea == 0){
		ans += min(sb, ea);
	}else{
		if(sb == 0 && ea == 0){
			ans += max(sbea - 1, 0LL);
		}else{
			ans += sbea + min(sb, ea);
		}
	}
	cout << ans << endl;
}


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

int main() {
  long long n;
  cin >> n;
  vector<long long> a(n);
  for(int i = 0; i < n; i++) cin >> a.at(i);
  
  vector<int> ans(n);
  int l = -1, lp = 300, r = -1, rp = -1;
  for(int i = 0; i < n; i++){
    if(r < 0){
      if(a.at(i) <= lp) lp = a.at(i), l = i;
      else rp = a.at(i), r = i;
    }
    else{
      if(a.at(i) >= rp) rp = a.at(i), r = i;
      else{
        ans.at(l) = 1, ans.at(r) = 2;
        l = i, lp = a.at(i), r = -1, rp = -1;
      }
    }
    if(i == n-1 && r > 0) ans.at(l) = 1, ans.at(r) = 2;
  }
  long long res = 1000, cnt = 0;
  for(int i = 0; i < n; i++){
    int now = ans.at(i);
    if(now == 1){
      cnt += res / a.at(i);
      res %= a.at(i);
    }
    if(now == 2){
      res += cnt * a.at(i);
      cnt = 0;
    }
  }
  
  cout << res << endl;
}

Measured memory_bytes: 3640
import std.stdio, std.string, std.conv, std.algorithm, std.numeric;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;

void main() {
    while (true) {
        int r0, w0, c, r;
        scan(r0, w0, c, r);
        if (!r0) return;

        int ans;

        while (r0 < w0*c) {
            r0 += r;
            ans++;
        }

        writeln(ans);
    }
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}



void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 2404
import java.util.*;


public class Main {
	class UnionFind{
		int [] pars;
		UnionFind(int n){
			pars = new int[n];
			for(int i=0; i<n; i++)
				pars[i] = i;
		}
		
		int getRoot(int x){
			if(x == pars[x]) return x;
			pars[x] = getRoot(pars[x]);
			return pars[x];
		}
		
		public void merge(int x, int y){
			pars[getRoot(x)] = getRoot(y);
		}
		
		public boolean isSame(int x, int y){
			return getRoot(x) == getRoot(y);
		}
	}

	int n;
	String strs[];

	void run(){
		Scanner in = new Scanner(System.in);
		for(;;){
			n = in.nextInt();
			if(n == 0) return;
			strs = new String[n];
			for(int i=0; i<n; i++)
				strs[i] = in.next();
			System.out.println(solve()?"OK":"NG");
		}
	}

	boolean solve(){
		int[] in = new int[26], out = new int[26];
		UnionFind uf = new UnionFind(26);
		for(int i=0; i<n; i++){
			int from = (int)(strs[i].charAt(0)-'a');
			int to = (int)(strs[i].charAt(strs[i].length()-1)-'a');
			in[from]++;
			out[to]++;
			uf.merge(from, to);
		}
		for(int i=0; i<26; i++)if(in[i] != out[i]) return false;
		for(int i=0; i<26; i++)if(in[i] > 0)
			for(int j=0; j<26; j++)if(in[j] > 0)
				if(!uf.isSame(i, j)) return false;
		return true;
	}

	
	public static void main(String args[]){
		new Main().run();
	}
}

Measured memory_bytes: 15000
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
#include <ctype.h>
#include <limits.h>	
#define inf (INT_MAX-1)
#define INF 9223372036854775807
#define sq(n) ((n)*(n))
#define rep(i,n) for(i=0;i<n;i++)
#define rev(i,n) for(i=n-1;i>=0;i--)
#define sort(a,n) qsort(a,n,sizeof(TYPE),cmp)
#define sort_r(a,n) qsort(a,n,sizeof(TYPE),cmp_r);
#define chsort(s,n) qsort(s,n,sizeof(char),cmp)
#define chsort_r(s,n) qsort(s,n,sizeof(char),char_cmp_r);
#define TYPE long long
#define MEMSET(a) memset(a,0,sizeof(a))
const int mod=(int)1e09+7;

int in(void){
	int i;scanf("%d",&i);
	return i;
}
long long llin(void){
	long long i;scanf("%lld",&i);
	return i;
}
double din(void){
	double i;scanf("%lf",&i);
	return i;
}
void chin(char s[]){
	scanf("%s",s);
}
void print(int a){
	printf("%d\n",a);
}
void llprint(long long a){
	printf("%lld\n",a);
}
void dprint(double a){
	printf("%.10f\n",a);
}
void print2(int a,int b){
	printf("%d %d\n",a,b);
}
long long max(long long a,long long b){
	return a>b?a:b;
}
long long min(long long a,long long b){
	return a<b?a:b;
}
long long llabs(long long a){
	return a>0?a:-a;
}
double dmax(double a,double b){
	return a>b?a:b;
}
int cmp(const void *a,const void *b){
	return *(TYPE *)a-*(TYPE *)b;
}
int cmp_r(const void *a,const void *b){
	return *(TYPE *)b-*(TYPE *)a;
}
int char_cmp(const void *a,const void *b){
	return strcmp((char *)a,(char *)b);
}
int char_cmp_r(const void *a,const void *b){
	return strcmp((char *)b,(char *)a);
}
void swap(int *a,int *b){
	int t=*a;
	*a=*b;
	*b=t;
}
long long gcd(long long x,long long y){
	return x%y?gcd(y,x%y):y;
}
long long lcm(long long x,long long y){
	return x/gcd(x,y)*y;
}

// konoshita kara kaku

int main(void){
	int i,j;
	char s[10][10];
	rep(i,3)chin(s[i]);
	printf("%c%c%c\n",s[0][0],s[1][1],s[2][2]);
	return 0;
}

Measured memory_bytes: 128
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
#####################################

n=int(input())
D=[0]*4
for i in  range(n):
    s=input()
    if s=="AC":
        D[0]+=1
    elif s=="WA":
        D[1]+=1
    elif s=="TLE":
        D[2]+=1
    else:
        D[3]+=1
print("AC x",D[0])
print("WA x",D[1])
print("TLE x",D[2])
print("RE x",D[3])


Measured memory_bytes: 69928
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

const ll MOD = 998244353;

ll calc_pow(ll x, ll y) {
    ll z = 1;
    while (y > 0) {
        if (y & 1) {
            z = (z * x) % MOD;
        }
        x = (x * x) % MOD;
        y /= 2;
    }
    return z;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<int> D(N);
    rep(i, 0, N) cin >> D[i];
    if (D[0] != 0) {
        cout << 0 << endl;
        return 0;
    }
    vector<int> cnt(N, 0);
    int max_d = 0;
    rep(i, 0, N) {
        ++cnt[D[i]];
        max_d = max(max_d, D[i]);
    }
    if (cnt[0] > 1) {
        cout << 0 << endl;
        return 0;
    }
    if (max_d == 0) {
        if (N == 1) cout << 1 << endl;
        else cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    rep(i, 1, max_d + 1) {
        ans = (ans * calc_pow(cnt[i - 1], cnt[i])) % MOD;
    }
    cout << ans << endl;
    return 0;
}

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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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

#define ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

/* Some Libraries */

//-------------------------------------------------

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int a,b,c; cin>>a>>b>>c;
    if (a==b && b==c){
        cout<<"No\n";
    }else{
        if (a==b || b==c || c==a){
            cout<<"Yes\n";
        }else{
            cout<<"No\n";
        }
    }
    return 0;
}


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

int main () {
	int n; cin >> n;
	int a[100000];
	bool b[100000] = {false};
	for (int i=0; i<n; i++) {
		cin >> a[i];
	}
	int x=0;
	int c=0;
	while (a[x]!=2 && b[x]==false) {
		b[x] = true;
		x=a[x]-1;
		c++;
	}
	if (b[x]==true) cout << -1; else cout << c+1;
	return 0;
} 

Measured memory_bytes: 4096
#include<stdio.h>

int main(void){
  int i,j;
  int n;
  int w,h;
  int map[100][100];
  int x,y;
  int s,t;
  int sum,max;
  
  while(1){	
    scanf("%d",&n);	
    if(!n)break;
    
    scanf("%d %d",&w,&h);
    
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
	map[i][j] = 0;
      }
    }
    
    for(i=0;i<n;i++){
      scanf("%d %d",&x,&y);
      map[y-1][x-1] = 1;
    }
    
    scanf("%d %d",&s,&t);
    
    max = 0;
    for(y=0;y<=h-t;y++){
      for(x=0;x<=w-s;x++){
	sum = 0;
	for(i=y;i<y+t;i++){
	  for(j=x;j<x+s;j++){
	    sum+=map[i][j];
	  }
	}
	if(max<sum)max = sum;
      }
    }
    
    printf("%d\n",max);
  }
  return 0;
}

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

#define INF 0x3f3f3f3f
#define int long long
#define pii pair<int, int>

const int N = 3005;


int dp[N][N];
int32_t main() {
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int i, j, n, m;
    string s, t, ans;

    cin >> s >> t;
    n = s.size();
    m = t.size();
    for(i = 0 ; i <= n ; i++) {
        for(j = 0 ; j <= m ; j++) {
            if(!i or !j) {
                dp[i][j] = 0;
                continue;
            }
            dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            if(s[i-1] == t[j-1])
                dp[i][j] = max(dp[i][j], dp[i-1][j-1] + 1);
        }
    }
    ans = "";
    i = n;
    j = m;
    while(dp[i][j]) {
        if(dp[i][j] == dp[i][j-1])
            j--;
        else if(dp[i][j] == dp[i-1][j])
            i--;
        else {
            ans += s[i-1];
            i--, j--;
        }
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 70784
<?php

fscanf(STDIN, '%d', $A);
fscanf(STDIN, '%d', $B);
fscanf(STDIN, '%d', $C);
fscanf(STDIN, '%d', $D);
fscanf(STDIN, '%d', $E);
fscanf(STDIN, '%d', $k);

if($E - $A > $k){
    echo ':('.PHP_EOL;
}else{
    echo 'Yay!'.PHP_EOL;
}

Measured memory_bytes: 4728
import numpy as np
n,m=map(int,input().split())
a=np.array([int(i) for i in input().split()])
bc=np.array([[int(i) for i in input().split()] for j in range(m)])

a.sort()
b=bc[:,0]
c=bc[:,1]

idx=np.argsort(c)
b=b[idx][::-1]
c=c[idx][::-1]

p=0
for b,c in zip(b,c):
    a[p:p+b]=np.maximum(a[p:p+b],c)
    p+=b
    
    
print(a.sum())

Measured memory_bytes: 32484
#include <stdio.h>
#include <string>
#include <vector>
#include <iostream>
#include <algorithm>

using namespace std;

int maxCard(vector<int>& cards)
{
  vector<int>::iterator itr = max_element(cards.begin(), cards.end());
  size_t index = distance(cards.begin(), itr);
  int maxCard = cards[index];
  cards.erase(itr);
  return maxCard;
}

int main(void) {
  int num, l;
  int a = 0;
  int b = 0;
  vector<int> cards;
  
  cin >> num;
  
  for (int i = 0;i < num;i++) {
    cin >> l;
    cards.push_back(l);
  }
  
  while (true) {
    a += maxCard(cards);
    if (cards.empty()) break;
    b += maxCard(cards);
    if (cards.empty()) break;
  }
  
  cout << a - b << endl;
  
  return 0;
}


Measured memory_bytes: 256
# coding: utf-8
A = sorted(list(map(ord, list(input()))))
B = sorted(list(map(ord, list(input()))), reverse=True)
ans = 'No'
for i in range(min(len(A), len(B))):
    if A[i] < B[i]:
        ans = 'Yes'
        break
    elif A[i] > B[i]:
        break
    if i == len(A) - 1 and len(A) != len(B):
        ans = 'Yes'
print(ans)

Measured memory_bytes: 3064
#include <iostream>
#include <iomanip>
#include<math.h>
#include<list>
#include <algorithm>
#include<set>
#include<vector>
#include<math.h>
#include<map>
#include<string>
#include <numeric>
#include <queue>
#include <sstream>
#include <bitset>
#include<stack>
#include<functional>
#include<unordered_set>
#include<unordered_map>

using namespace std;
using ll = long long;
using vll = vector<long long>;
using sll = set<long long>;
const long long ll_max = 9223372036854775807;
const long long ll_min = -9223372036854775807;
const int int_max = 2147483647;

template<typename T>
T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
template<typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }

template<typename T>
map<T, T> getPrimeFactor(T n) {
	map<T, T> ret;
	for (T i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i] ++;
			n /= i;
		}
	}
	if (n != 1) ret[n] = 1;
	return ret;
}

template<typename T>
bool IsPrimeNumber(T num)
{
	if (num <= 2) return true;
	else if (num % 2 == 0) return false;

	double sqrtNum = sqrt(num);
	for (int i = 3; i <= sqrtNum; i += 2)
	{
		if (num % i == 0)
		{
			return false;
		}
	}

	return true;
}

template<typename T>
T modinv(T a, T m) {
	T b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}



// 繰り返し二乗法
ll pow2(ll n, ll p, ll mod) {
	if (p == 0 || n == 1) {
		return 1;
	}
	else {
		ll ret = pow2(n * n % mod, p / 2, mod);
		if (p % 2 == 1) {
			ret *= n;
		}
		return ret % mod;
	}
}


#define rep(i,s,e) for(ll i=s;i<e;i++)
#define repeq(i,s,e) for(ll i=s;i<=e;i++)


map<ll, map<ll, ll>> dic;
map<ll, map<ll, ll>> dic3;
map<ll, ll> dic1;
map<ll, ll> dic2;
const ll mod = 1e9 + 7;

ll comb(ll a, ll b) {
	auto itr1 = dic.find(a);
	if (b == 1) {
		return a;
	}
	if (itr1 != dic.end()) {
		auto itr2 = itr1->second.find(b);
		if (itr2 != itr1->second.end()) {
			return itr2->second;
		}
	}
	ll ret = (((dic1[a] * dic2[a - b]) % mod)* dic2[b]) % mod;
	dic[a][b] = ret;
	return ret;
}
ll comb2(ll a, ll b) {
	if (a == b) {
		return 1;
	}
	if (a<b||a==0 || b == 0) {
		return 0;
	}
	else if (b == 1) {
		return 1;
	}
	else {
		return comb(a - 1, b - 1);
	}
}


int main() {
	ll n, k;
	cin >> n >> k;
	dic1[1] = 1;
	dic2[0]=dic2[1] = 1;
	
	repeq(i, 2, n) {
		dic1[i] = (dic1[i - 1] * i) % mod;
		dic2[i] = (dic2[i - 1] * modinv(i, mod)) % mod;
	}

	repeq(i, 1, k) {
		ll l = n - k;
		cout << comb2(k, i) * ((2 * comb2(l, i) % mod) + comb2(l, i + 1) + comb2(l, i - 1)) % mod << endl;
	}

	return 0;
}


Measured memory_bytes: 4012
///Bismillahir Rahamanir Rahim
#include<bits/stdc++.h>

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




using namespace std;

const int inf=1e18;
const int mod=1e9+7;
const int M=100009;
inline int bigmod(int B,int P){int R=1;while(P>0){if(P&1){R=(R*B)%mod;}P>>=1;B=(B*B)%mod;}return R;}


 main()

{
    fast
    string a;
    cin>>a;
    int sz=a.size();
    set<pi>s;
    set<int>ase;
    set<int>::iterator hi,lo;
    f(i,0,sz-1)ase.insert(i);
    f(i,0,sz-2)
   {
       if(a[i]=='S' && a[i+1]=='T')
       {
           s.insert(mp(i,i+1));
       }
   }
   int ses=0;
   while(!s.empty())
   {

        pi yo=*s.begin();
        s.erase(s.begin());
        int bam,dan;
        int idx=yo.fi;
        ase.erase(idx);
        ase.erase(yo.si);
        ses+=2;
        hi=ase.upper_bound(idx);
        if(hi==ase.end() || hi==ase.begin())continue;
        lo=hi;
        lo--;
        bam=*lo;
        dan=*hi;
        if(a[bam]=='S' && a[dan]=='T')
        {
            s.insert(mp(bam,dan));
        }
   }

   ses=sz-ses;
   cout<<ses<<endl;
    return 0;

}













Measured memory_bytes: 12948
/// [Amberjack] CUT BEGIN
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;

typedef int _loop_int;
#define __GET_REP_MACRO(_1,_2,_3,NAME,...) NAME
#define __REP0(i,n) for(_loop_int i=0;i<(n);++i)
#define __REP1(i,a,b) for(_loop_int i=(a);i<(b);++i)
#define __REPR0(i,n) for(_loop_int i=(n)-1;i>=0;--i)
#define __REPR1(i,a,b) for(_loop_int i=(b)-1;i>=(a);--i)
#define REP(...) __GET_REP_MACRO(__VA_ARGS__,__REP1,__REP0)(__VA_ARGS__)
#define REPR(...) __GET_REP_MACRO(__VA_ARGS__,__REPR1,__REPR0)(__VA_ARGS__)

#ifdef BURI
#define __DEBUG0() "Hello"
#define __DEBUG1(x) #x"("<<(x)<<")"
#define __DEBUG2(x,...) #x"("<<(x)<<"), " __DEBUG1(__VA_ARGS__)
#define __DEBUG3(x,...) #x"("<<(x)<<"), " __DEBUG2(__VA_ARGS__)
#define __DEBUG4(x,...) #x"("<<(x)<<"), " __DEBUG3(__VA_ARGS__)
#define __DEBUG5(x,...) #x"("<<(x)<<"), " __DEBUG4(__VA_ARGS__)
#define __GET_DEBUG_MACRO(_1,_2,_3,_4,_5,NAME,...) NAME
#define __DEBUG(...) __GET_DEBUG_MACRO(__VA_ARGS__,__DEBUG5,__DEBUG4,__DEBUG3,__DEBUG2,__DEBUG1,__DEBUG0)(__VA_ARGS__)
#define DEBUG(...) cerr<<__DEBUG(__VA_ARGS__)<<endl
#else
#define DEBUG(...)
#endif

#define gc getchar_unlocked
inline void getll(ll &x){
  int sgn=1;x=0;
  char c=gc();
  while(c!='-'&&(c<'0'||c>'9'))c=gc();
  if(c=='-') sgn=-1; else x=c-'0';
  c=gc();
  while('0'<=c&&c<='9'){
    x*=10;
    x+=c-'0';
    c=gc();
  }
  x*=sgn;
}
inline void read(ll &x){getll(x);}
inline void read(int &x){ll y;getll(y);x=y;}
inline void read(float &x){scanf("%f",&x);}
inline void read(double &x){scanf("%lf",&x);}
inline void read(long double &x){scanf("%Lf",&x);}
inline void read(char *s){scanf("%s",s);}
inline void read(string &s){int len=s.size();char *buf=(char*)malloc(len*sizeof(char));scanf("%s",buf);s=string(buf);free(buf);}
inline void read(char &c){char *buf=(char*)malloc(5*sizeof(char));scanf("%s",buf);c=buf[0];free(buf);}
inline void read(){}
template<typename S,typename ...T>
inline void read(S& first, T&... rest){
  read(first);
  read(rest...);
}
/// [/Amberjack] CUT END

int n;
int main(){
  ll ans;
  read(n,ans);
  ans-=1;
  int ban = 2;
  int a;
  REP(i,1,n){
    read(a);
    if(a==ban)ban++;
    else ans += (a-1)/ban;
  }
  printf("%lld\n",ans);
  return 0;
}


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

int main() {
	double x, h;
	while (cin >> x >> h, x) {
		double t = sqrt((x/2)*(x/2) + h*h);
		printf("%.6lf\n", x*x + x*t * 2);
	}
}

Measured memory_bytes: 3192