akhauriyash/Code-Regression huggingface dataset:
#include <iostream>

#define INF 100000000

using namespace std;

int min(int a,int b){
	if(a>=b)return b;
	else return a;
}

int main(){



	//dp[i][j],i:????????¢???????????????????????°???j,????????¢?????????????????????bit????????????
	//????????¶??????????°????????????????
	int dp[20][100000];
	int n;
	int t[20][20];

	int bit[20];
	bit[0]=1;
	for(int i=1;i<20;i++){
		bit[i] = bit[i-1]*2;
	}

	while(cin>>n){
		if(n==0)break;

		for(int i=0;i<n;i++){
			for(int j=0;j<=n;j++){
				cin>>t[i][j];
			}
		}

		for(int i=0;i<=n;i++){
			for(int j=0;j<=bit[n];j++){
				
				dp[i][j]=INF;
				
			}
		}
		dp[0][0]=0;

		for(int i=0;i<n;i++){
			for(int j=0;j<bit[n];j++){
				if(dp[i][j]!=INF){

					//???????????????????????§????????¢?????????
					for(int k=0;k<n;k++){
						//????????¢???????????´???????¨???????????????????
						if((j&bit[k])>0){
							//cout<<"j="<<j<<" k="<<k<<endl;
							//cout<<"unko"<<endl;
							continue;
						}
						//????????¢?????????????????????????????¢?´¢?????????????°???????????????£??\?????????
						for(int l=0;l<n;l++){
							dp[i+1][j+bit[k]] = min(dp[i+1][j+bit[k]],dp[i][j]+t[k][(j&bit[l])/bit[l]*(l+1)]);
						}
					}


				}
			}
		}

/*
		for(int i=0;i<=n;i++){
			for(int j=0;j<=bit[n];j++){
				cout<<dp[i][j]<<" ";
			}
			cout<<endl;
		}
*/		
		int ans=INF;
		for(int i=0;i<=bit[n];i++){
			ans = min(ans,dp[n][i]);
		}

		cout<<ans<<endl;



	}
	return 0;


}

Measured memory_bytes: 8016
#define _USE_MATH_DEFINES

#include <stdio.h>
#include <iostream>
#include <algorithm>
#include <cmath>
#include <string>
#include <utility>
#include <climits>
#include <vector>
#include <map>
#include <queue>
#include <set>
using namespace std;

#define ll long long
const int MOD = 1000000007;//10^9+7
const string SPACE = " ";

ll powsur(ll a, ll b, ll p) {

	if (b == 0) {

		return 1;

	}
	else if (b % 2 == 0) {

		ll d = powsur(a, b / 2, p);
		return ((d%p)*(d%p)) % p;

	}
	else {

		return ((a%p)*powsur(a, b - 1, p) % p) % p;

	}

}
//pは素数,aのb乗をpで割った余り

ll CMOD(ll n, ll r, ll p) {

	ll a = 1, b = 1, c = 1, re;
	for (int i = 1; i <= n; i++) {

		a *= i;
		a = a%p;

	}
	for (int i = 1; i <= r; i++) {

		b *= i;
		b = b%p;

	}
	for (int i = 1; i <= n - r; i++) {

		c *= i;
		c = c%p;

	}
	b = powsur(b, p - 2, p);
	c = powsur(c, p - 2, p);
	re = ((a%p)*(b%p)) % p;
	re = ((re%p)*c%p) % p;

	return re;

}
//pは素数,(nCr)%p

ll gcd(ll a, ll b) {

	if (a > b) {

		ll tmp = a;
		a = b;
		b = tmp;

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

}
//最大公約数

ll lcm(ll a, ll b) {

	return (a / gcd(a, b))*b;

}
//最小公倍数

ll MAX(ll a, ll b) {

	if (a > b)return a;
	else return b;

}
//MAX

int main() {

	ll N, t[100005], x[100005], y[100005];
	bool check = true;

	cin >> N;
	t[0] = x[0] = y[0] = 0;
	for (int i = 1; i <= N; i++) {

		cin >> t[i] >> x[i] >> y[i];
		int d = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
		if (d > t[i] - t[i - 1] || abs(d - (t[i] - t[i - 1])) % 2 == 1)check = false;

	}

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

	return 0;
}

Measured memory_bytes: 2560
/*input

*/

#include <bits/stdc++.h>
#include <unistd.h>

#define rep(i,j,n) for(i=j;i<n;i++)
#define repi(i,j,n) for(i=j;i>n;i--)
#define inf 1e18
#define M 1000000007
#define pie 3.141592653589793238
#define ll long long
#define ld long double
#define vll vector<ll>
#define pll pair<ll,ll>
#define vpll vector<pll>
#define pb push_back
#define F first
#define S second
#define endl '\n'
#define UQ(x) (x).resize(distance((x).begin(),unique(x.begin(),x.end())))

using namespace std;

mt19937 rnd(chrono::high_resolution_clock::now().time_since_epoch().count());
mt19937_64 rnd64(chrono::high_resolution_clock::now().time_since_epoch().count());

ll power(ll a,ll m,ll mod){
	ll ans=1;
	while(m){
		if(m%2) ans*=a, ans%=(mod);
		a=(a*a)%(mod);
		m>>=1;
	}
	return ans;
}


void init(ll* a,ll n,ll val){
	for(ll i=0;i<n;i++)
		a[i]=val;
}

void solve(){
	ll i,j,_;
	ll n;
	cin>>n;
	if(!(n%2)) {
		cout << -1 << endl;
		return;
	}
	ll ans = 1,now = 7%n;
	const ll t = 1e7;
	while(now && ans < t) {
		++ans;
		now *= 10;
		now += 7;
		now %= n;
	}
	if(ans == t) ans = -1;
	cout << ans << endl;
}

int main()
{
	ios::sync_with_stdio(0);
 	cin.tie(0);
	ll T=1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}




Measured memory_bytes: 3604
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <queue>
#include <vector>
#include <utility>
#define maxn 105
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int num[5];
int n,a,b,p[maxn];
int main(){
	scanf("%d",&n);
	scanf("%d%d",&a,&b);
	for(int i=1;i<=n;i++){
		scanf("%d",&p[i]);
		if(p[i] <= a) num[1]++;
		else if(p[i] <= b) num[2]++;
		else num[3]++;
	}
	printf("%d\n",min(num[1],min(num[2],num[3])));
	return 0;
}


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

using namespace std;

#define int long long
long long sv[16];
signed main(){
	int n;
	long long a = 0;
	char rp;
	bool br = 0;
	int dg;
	dg = 0;
	for(int i = 10; i >= 1; i--){
		cout << "? " << (int)pow(10, i) - 1 << "\n";
		fflush(stdout);
		cin >> rp;
		if(rp == 'N'){
			dg = i + 1;
			break;
		}
	}
	if(dg == 0){
		for(int i = 10; i >= 0; i--){
			cout << "? " << (int)pow(10, i) << "\n";
			fflush(stdout);
			cin >> rp;
			if(rp == 'Y' && i == 10){
				cout << "! 1\n";
				exit(0);
			}
			if(rp == 'Y'){
				dg = i + 1;
				break;
			}
		}
	}
	for(int i = 1; i < dg; i++){
		int l = 0, r = 9;
		a = a * 10;
		while(l != r){
			int mid = (l + r + 1) / 2;
			cout << "? " << a + mid << "\n";
			fflush(stdout);
			cin >> rp;
			if(rp == 'Y'){
				l = mid;
			}
			else{
				r = mid - 1;
			}
		}
		a += l;
	}
	a = a * 10;
	if(a == 0) a = 1;
	for(int i = 0; i <= 9; i++){
		cout << "? " << (a + i) * 10 << "\n";
		fflush(stdout);
		cin >> rp;
		if(rp == 'Y'){
			a = a + i;
			break;
		}
	}
	cout << "! " << a << "\n";
	fflush(stdout);
	exit(0);
	
}

Measured memory_bytes: 596
# ARC089C - Traveling (ABC086C)
def main():
    n = int(input())
    for _ in range(n):
        t, x, y = list(map(int, input().split()))
        if x + y > t or (t + x + y) % 2 != 0:
            print("No")
            break
    else:
        print("Yes")


if __name__ == "__main__":
    main()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <algorithm>  
#include <unordered_set>
#include <cmath>

#define ll long long

using namespace std;

int main() {

	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	ll N;

	string str;

	cin >> N;
	cin >> str;

	int start = 0;
	int ops = 0;
	int reds = 0;

	for (int i = 0; i < N; i++) {
		if (str[i] == 'R') {
			reds++;
		}
	}

	for (int i = 0; i < reds; i++) {
		if (str[i] == 'W') {
			ops++;
		}
	}

	cout << ops << endl;
	return 0;
}


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

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

int main()
{
    int N; cin >>N;
    unordered_set<int> s;
    rep(i, N) {
        int A; cin >> A;
        s.insert(A);
    }
    int uniq = s.size();
    int dup = N-uniq;

    cout << uniq-(dup%2) << endl;
}


Measured memory_bytes: 4388
n = int(input())
v = [int(i) for i in input().split()] 
import collections
if len(set(v))  == 1:
    print(int(len(v) / 2))
else:
    a = collections.Counter(v[0::2]).most_common()
    b = collections.Counter(v[1::2]).most_common() 
    if a[0][0] == b[0][0]:
        print(min((len(v[0::2]) - a[1][1] + len(v[1::2]) - b[0][1]),(len(v[0::2]) - a[0][1] + len(v[1::2]) - b[1][1])))
    else:
        print(len(v[0::2]) - a[0][1] + len(v[1::2]) - b[0][1])

Measured memory_bytes: 20512
a = [list(map(int,input().split())) for i in range(3)]
n = int(input())
for k in range(n):
    b = int(input())
    for i in range(3):
        for j in range(3):
            if b == a[i][j]:
                a[i][j] = 0
for i in a:
    if sum(i) == 0:
        print('Yes')
        exit()
for i in range(3):
    sum_tate = a[0][i]+a[1][i]+a[2][i]
    if sum_tate == 0:
        print('Yes')
        exit()
if a[0][0]+a[1][1]+a[2][2] == 0:
    print('Yes')
    exit()
if a[0][2]+a[1][1]+a[2][0] == 0:
    print('Yes')
    exit()
print('No')


Measured memory_bytes: 3064
//Compete against Yourself.
#include <bits/stdc++.h>
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define int long long
#define pb push_back
#define sz(i) (int)(i.size())
#define F first
#define S second
#define L long double
#define P pair<int, int>
const int inf = 0x3f3f3f3f3f3f3f3LL;
const int mod = (int)1e9 + 7;
using namespace std;
#if LOCAL
#include "../../tr.h"
#else
#define tr(...)
#define endl '\n'
#endif
template<class T> void smin(T& a, T val) {if (a > val) a = val;}template<class T> void smax(T& a, T val) {if (a < val) a = val;}
const int N = 30000 + 10;

int n, a[N];

void solve(){
   cin>>n;

   string s;
   cin >> s;

   bool suff[N][20];//iske age koon
   memset(suff, 0, sizeof suff);
   

   for (int i = n - 2; i >= 0; --i)
   {
      for (int j = 0; j <= 9; ++j)
      {
         suff[i][j] = suff[i+1][j];  
      }
      suff[i][s[i+1]-'0'] = 1;
   }

   int ans = 0;   

   set<int> ms;
   ms.insert(s[0] - '0');
   set<int> vals;
   for (int i = 1; i < n; ++i)
   {
      int size = sz(ms);
      int ok = 0;

      for(auto it: ms){
         for (int j = 0; j <= 9; ++j)
         {
            if(suff[i][j]){
               int ok = it * 100 + (s[i] - '0') * 10 + j;
               vals.insert(ok);
            }  
         }
      }

      ms.insert(s[i] - '0');
   }

   cout<<sz(vals);
}

int32_t main(){_
   
   int t = 1;
//   cin >> t;

   while(t--){
     solve();
     cout << endl;
   }
   

   return 0;
}

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

int main() {
	int n;
	cin >> n;
	vector <int> arr(2 * n);
	for(int i = 0; i < 2 * n; i++)
		cin >> arr[i];
	sort(arr.begin(), arr.end());
	int ans = 0;
	for(int i = 2 * n - 2; i >= 0; i -= 2)
		ans += arr[i];
	cout << ans;
}

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


int main()
{
    int n, m[101][101] = {0};
    cin >> n;
    for(int i = 0; i < n; i++){
        int u, k;
        cin >> u >> k;
        for(int j = 0; j < k; j++){
            int v;
            cin >> v;
            m[u][v] = 1;
        }
    }
    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= n; j++) {
            if(j != 1) cout << " ";
            cout << m[i][j];
        
        }
        cout << endl;
    }
    
    
    
    
    return 0;
}


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

int main() {
    int n;
    cin >> n;
    vector<int> x(n), y(n);
    rep(i,n) cin >> x[i] >> y[i];

    vector<int> t(n);
    rep(i,n) t[i] = i;

    auto d = [&](int x1, int x2, int y1, int y2) {
        return sqrt(double(pow(x1-x2, 2) + pow(y1-y2, 2)));
    };

    double ans = 0;
    int count = 0;
    do {
        double dis = 0;
        for (int i = 1; i < t.size(); i++) {
            dis += d(x[t[i-1]], x[t[i]], y[t[i-1]], y[t[i]]);
        }
        ans += dis;
        count++;
    } while (next_permutation(t.begin(), t.end()));

    printf("%.10f\n", ans / count);
    return 0;
}

Measured memory_bytes: 3760
import math
a, b = map(float, input().split())

a_min = math.ceil(a/0.08)
a_max = math.floor((a+1)/0.08)

b_min = math.ceil(b/0.1)
b_max = math.floor((b+1)/0.1)

a_list = set(list(range(a_min, a_max, 1)))
b_list = set(list(range(b_min, b_max, 1)))

ab_list = a_list & b_list
if len(ab_list) > 0:
    print(min(ab_list))
else:
    print(-1)


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

ans = 0
for i in range(1, n + 1):
    if b[i - 1] < a[i - 1]:
        ans += b[i - 1]
    else:
        ans += a[i - 1]
        b[i - 1] -= a[i - 1]
        if b[i - 1] > a[i]:
            ans += a[i]
            a[i] = 0
        else:
            ans += b[i - 1]
            a[i] -= b[i - 1]
print(ans)


Measured memory_bytes: 19156
use std::cmp;

fn main() {
    let mut sc = Scanner::new();
    let n: usize = sc.read();
    let a: usize = sc.read();
    let b: usize = sc.read();

    let mut v: Vec<usize> = (0..n).map(|_| sc.read()).collect();
    v.sort();
    v.reverse();

    let mut sum = 0;
    for i in 0..a {
        sum += v[i];
    }

    let mut selectable = 0;
    for i in 0..n {
        if v[i] == v[a - 1] {
            selectable += 1;
        }
    }

    let mut big_count = 0;
    for i in 0..n {
        if v[i] > v[a - 1] {
            big_count += 1;
        }
    }

    let mut ans = 0;


    let from = a - big_count;
    let to = if v[a - 1] * a != sum { from } else { cmp::min(b - big_count, selectable) };
    for i in from..(to + 1) {
        let mut combination: usize = 1;
        for j in 0..i {
            combination *= (selectable - j);
            combination /= (j + 1);
        }
        ans += combination;
    }

    println!("{}", (sum as f64) / (a as f64));
    println!("{}", ans);
}

struct Scanner {
    ptr: usize,
    length: usize,
    buf: Vec<u8>,
    small_cache: Vec<u8>,
}

impl Scanner {
    fn new() -> Scanner {
        Scanner { ptr: 0, length: 0, buf: vec![0; 1024], small_cache: vec![0; 1024] }
    }

    fn load(&mut self) {
        use std::io::Read;
        let mut s = std::io::stdin();
        self.length = s.read(&mut self.buf).unwrap();
    }

    fn byte(&mut self) -> u8 {
        if self.ptr >= self.length {
            self.ptr = 0;
            self.load();
            if self.length == 0 {
                self.buf[0] = b'\n';
                self.length = 1;
            }
        }

        self.ptr += 1;
        return self.buf[self.ptr - 1];
    }

    fn is_space(b: u8) -> bool { b == b'\n' || b == b'\r' || b == b'\t' || b == b' ' }

    fn read<T>(&mut self) -> T where T: std::str::FromStr, T::Err: std::fmt::Debug, {
        let mut b = self.byte();
        while Scanner::is_space(b) {
            b = self.byte();
        }

        for pos in 0..self.small_cache.len() {
            self.small_cache[pos] = b;
            b = self.byte();
            if Scanner::is_space(b) {
                return String::from_utf8_lossy(&self.small_cache[0..(pos + 1)]).parse().unwrap();
            }
        }

        let mut v = self.small_cache.clone();
        while !Scanner::is_space(b) {
            v.push(b);
            b = self.byte();
        }
        return String::from_utf8_lossy(&v).parse().unwrap();
    }
}



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


 const int MAX = 1001;
const int MOD = 1000000007;



signed main(){
    int n;
    
    cin>>n;
    int m=0;
   while(n>(1<<m))m++;
   int k;
   for(int i=0;i<n;i++){
       for(int j=i+1;j<n;j++){
           k=m-1;
           while((i^j)<(1<<k))k--;
           cout<<k+1<<' ';
       }
       cout<<endl;
   }

   return 0;
}

Measured memory_bytes: 512
#define _GIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define all(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;


int main(void) {
  ll N;
  cin >> N;

  ll sqrtN = sqrt(N);

  ll ans = 1000000000001;
  for (ll a = 1; a <= sqrtN; ++a) {
    if (N % a != 0) {
      continue;
    }
    ll b = N / a;
    ans = min(ans, a + b - 2);
  }

  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 256
import sys

def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))  #空白あり

N,M,L = LI()

class WarshallFloyd():
    def __init__(self,N):  # Nは頂点の個数
        self.N = N
        self.d = [[float('inf')]*N for _ in range(N)]  # d[i][j] = iからjへの最短距離,0-indexed
    def add(self,u,v,c,directed = False):
        if directed is False:  # 無向グラフの場合
            self.d[u][v] = c
            self.d[v][u] = c
        else:  # 有向グラフの場合
            self.d[u][v] = c
    def WarshallFloyd_search(self):
        for k in range(self.N):
            for i in range(self.N):
                for j in range(self.N):
                    self.d[i][j] = min(self.d[i][j],self.d[i][k] + self.d[k][j])
        for i in range(self.N):
            self.d[i][i] = 0
        return self.d

G1 = WarshallFloyd(N)

for i in range(M):
    a,b,c = LI()
    G1.add(a-1,b-1,c,directed=False)

G1.WarshallFloyd_search()

G2 = WarshallFloyd(N)

for i in range(N-1):
    for j in range(i+1,N):
        if G1.d[i][j] <= L:
            G2.add(i,j,1,directed=False)

G2.WarshallFloyd_search()

Q = I()
for i in range(Q):
    s,t = LI()
    if G2.d[s-1][t-1] == float('inf'):
        print(-1)
    else:
        print(G2.d[s-1][t-1]-1)



Measured memory_bytes: 84212
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <functional>
#include <set>
#include <numeric>
#include <queue>
#include<map>
#define ll long long int
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
#define PI 3.14159265358979323846264338327950


int main() {
	ll N, mod = 1000000007, x = 0, num = 0, ans = 0;

	cin >> N;
	vector<ll> a(N);
	rep(i, N)cin >> a[i];

	rep(i, N){
		num += a[i];
	}

	rep(i, N-1){
		num = num - a[i];
		x += (num%mod)*a[i] % mod;
	}
	x = x%mod;

	cout << x << endl;
	return 0;
}

Measured memory_bytes: 4808
n=int(input())
a=list(map(int,input().split()))
b=list(map(int,input().split()))
ans=0
for i in range(n):
    x=a.pop()
    y=b.pop()
    if x<=y:
        ans+=x
        y-=x
        if a[-1]>y:
            ans+=y
            a[-1]-=y
        else:
            ans+=a[-1]
            a[-1]=0
    else:
        ans+=y
print(ans)

Measured memory_bytes: 24180
/*********************
*  Author: xuziyuan  * 
*********************/

#include <bits/stdc++.h>

#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define LL long long
#define pii pair <int,int>
#define fi first
#define se second
#define pb push_back
#define mpr make_pair

using namespace std;

const LL MOD=1e9+7;

string s;
LL d,dp[100010][110],dp2[100010][110][2],res;

int main()
{
  cin>>s>>d;
  dp[0][0]=1;
  rep(i,s.size()-1)
  {
    rep(j,d)
    {
      if(dp[i][j]==0) continue;
      rep(k,10) dp[i+1][(j+k)%d]=(dp[i+1][(j+k)%d]+dp[i][j])%MOD;
    }
  }
  res=(dp[s.size()-1][0]-1+MOD)%MOD;
  dp2[0][0][0]=1;
  rep(i,s.size())
  {
    rep(j,d)
    {
      rep(k,2)
      {
        if(dp2[i][j][k]==0) continue;
        if(k==0)
        {
          for(int p=(i==0 ? 1:0);p<=s[i]-'0';p++)
          {
            if(p==s[i]-'0') dp2[i+1][(j+p)%d][0]=(dp2[i+1][(j+p)%d][0]+dp2[i][j][k])%MOD;
            else dp2[i+1][(j+p)%d][1]=(dp2[i+1][(j+p)%d][1]+dp2[i][j][k])%MOD;
          }
        }
        else
        {
          for(int p=(i==0 ? 1:0);p<10;p++)
          dp2[i+1][(j+p)%d][1]=(dp2[i+1][(j+p)%d][1]+dp2[i][j][k])%MOD;
        }
      }
    }
  }
  cout<<(dp[s.size()-1][0]-1+dp2[s.size()][0][0]+dp2[s.size()][0][1]+MOD)%MOD<<endl;
  return 0;
}

Measured memory_bytes: 30976
while line = gets
  xa, ya, xb, yb, xc, yc, xd, yd = line.split(",").map(&:to_f)
  v1x = xc - xa
  v1y = yc - ya
  b = v1x*(yb-ya) - v1y*(xb-xa) > 0 ? 1 : -1
  d = v1x*(yd-ya) - v1y*(xd-xa) > 0 ? 1 : -1
  if b * d == 1
    puts "NO"
    next
  end
  v2x = xd - xb
  v2y = yd - yb
  a = v2x*(ya-yb) - v2y*(xa-xb) > 0 ? 1 : -1
  c = v2x*(yc-yb) - v2y*(xc-xb) > 0 ? 1 : -1
  if a * c == 1
    puts "NO"
    next
  end
  puts "YES"
end

Measured memory_bytes: 8564
#include<stdio.h>
#include<string.h>
#define n 100000
int main(){
    char s[n];
    scanf("%s",s);
    long int m;
    m=strlen(s);
    long int i=m-1;
    int flag=0;
    while(flag==0 && i>=0){
        if(s[i]=='m'){
            if(s[i-1]!='a'||s[i-2]!='e'||s[i-3]!='r'||s[i-4]!='d')flag=1;
            else i-=5;
        }else if(s[i]=='r' && s[i-1]=='e'){
            if(s[i-2]=='m'){
                if(s[i-3]!='a'||s[i-4]!='e'||s[i-5]!='r'||s[i-6]!='d')flag=1;
                else i-=7;
            }else if(s[i-2]=='s'){
                if(s[i-3]!='a'||s[i-4]!='r'||s[i-5]!='e')flag=1;
                else i-=6;
            }else{
                flag=1;
            }
        }else if(s[i]=='e'){
            if(s[i-1]!='s'||s[i-2]!='a'||s[i-3]!='r'||s[i-4]!='e')flag=1;
            else i-=5;
        }else{
            flag=1;
        }
    }
    if(flag==0){
        printf("YES");
    }else{
        printf("NO");
    }
    return 0;
}

Measured memory_bytes: 384
s = input()
sl = int(s[0:2])
sr = int(s[2:4])
if 1<= sl <= 12:
  if 1 <= sr <= 12:
    print("AMBIGUOUS")
  else:
    print("MMYY")
else:
  if 1 <= sr <= 12:
    print("YYMM")
  else:
    print("NA")

Measured memory_bytes: 3060
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#include <stack>

const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};

int memo[210][210];
int gcd(int a, int b){ return (a%b ? gcd(b, a%b): b);}

using namespace std;
int main() {
	int n;
	cin >> n;
	long long res = 0;
	for (int i = 0; i < 210; i++){
		for (int j = 0; j < 210; j++){
			memo[i][j] = 10000;
		}
	}
	for (int i = 1; i <= n; i++){
		for (int j = 1; j <= n; j++){
			int a, b;
			if (memo[i][j] != 10000){
				a = memo[i][j];
			} else {
				memo[i][j] = gcd(i, j);
				a = memo[i][j];
			}
			for (int k = 1; k <= n; k++){
				if (memo[a][k] != 10000){
					b = memo[a][k];
				} else {
					memo[a][k] = gcd(a, k);
					b = memo[a][k];
				}
				res += b;
			}
		}
	}

	cout << res << endl;


}


Measured memory_bytes: 3800
#include <algorithm>
#include <cassert>
#include <cfloat>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <deque>
#include <iostream>
#include <limits>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
 
#define FOR(i,k,n) for (int (i)=(k); (i)<(n); ++(i))
#define rep(i,n) FOR(i,0,n)
#define all(v) begin(v), end(v)
#define debug(x) cerr<< #x <<": "<<x<<endl
#define debug2(x,y) cerr<< #x <<": "<< x <<", "<< #y <<": "<< y <<endl
 
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<vector<int> > vvi;
typedef vector<ll> vll;
typedef vector<vector<ll> > vvll;
typedef deque<bool> db;
template<class T> using vv=vector<vector< T > >;

// cout vector
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size(); s << "\n";
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << "\t";
  }
  s << "\n"; return s;
}

// cout 2-dimentional vector
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) { s << vv[i]; }
  return s;
}

int n, m;;
vvll x;

ll calc() {
  vll sumx(n, 0);
  rep (i, n) {
    rep (j, 3) {
      sumx[i] += x[i][j];
    }
  }
  sort(all(sumx), std::greater<>());
  ll ret = 0;
  rep (i, m) {
    ret += sumx[i];
  }
  return ret;
}


int main() {
  scanf("%d %d", &n, &m);
  x.assign(n, vll(3, 0));
  rep (i, n) {
    rep (j, 3) {
      scanf("%lld", &x[i][j]);
    }
  }
  /*
  vi gray(8);
  rep (i, 8) {
    gray[i] = (i ^ (i >> 1));
  }
  debug(gray);
  */
  vi change = {0, 1, 0, 2, 0, 1, 0};
  ll ans = 0;
  ans = max(ans, calc());
  rep (i, 7) {
    rep (j, n) {
      x[j][change[i]] *= (-1);
    }
    ans = max(ans, calc());
  }
  printf("%lld\n", ans);

  return 0;
}


Measured memory_bytes: 888
#include <stdio.h>

int main(){
	int n, p[20], i, cnt=0;

	scanf("%d", &n);

	for(i=0; i<n; i++)
		scanf("%d", &p[i]);

	for(i=2; i<n; i++){
		if((p[i-2] < p[i-1] && p[i-1] < p[i]) || (p[i] < p[i-1] && p[i-1] < p[i-2]))
			cnt++;
	}

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

	return 0;
}



Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); ++i)
#define REPR(i, n) for (int i = (int)(n - 1); i >= 0; --i)
#define FOR(i, x, n) for (int i = x; i < (int)(n); ++i)
#define ALL(n) begin(n), end(n)
#define ll long long
#define INF 1e9
int main() {
    char a;
    cin >> a;
    if (islower(a))
        cout << "a" << endl;
    else
        cout << "A" << endl;
    return 0;
}

Measured memory_bytes: 3576
o = list(input())
e = list(input())
ls = []
for x in range(min(len(o), len(e))):
    ls.append(o[x])
    ls.append(e[x])
else:
    if len(o) < len(e):
        for i in range(x+1, len(e)):
            ls.append(e[i])
    elif len(o) > len(e):
        for i in range(x+1, len(o)):
            ls.append(o[i])
print(''.join(ls))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define log(x) cout<<x<<endl
#define pb push_back
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
using namespace std;
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; }
const long long INF = 1LL << 60;
using Graph=vector<vector<int>>;

int gcd(lint x, lint y){
  return y==0 ? x:gcd(y,x % y);
}

int digsum(int n) {
  int res = 0;
  while(n > 0) {
    res += n%10;
    n /= 10;
  }
  return res;
}

int dignum(int n) {
  int res = 0;
  while(n > 0) {
    res++;
    n /= 10;
  }
  return res;
}

int stringcount(string s, char c) {
  return count(s.cbegin(), s.cend(), c);
}

int lcm(lint x, lint y){
  return x/ gcd(x, y) * y;
}

int combi(int n, int r){
  int num = 1;
  for(int i = 1; i <= r; i++){
    num = num * (n - i + 1) / i;
  }
  return num;
}

int main(){
  int n,x;
  int sum=0;
  int count=1;
  cin>>n>>x;
  int l[110];
  rep(i,n){
    cin>>l[i];
    sum+=l[i];
    if(sum>x) break;
    else count++;
  }
  cout<<count<<endl;

}

Measured memory_bytes: 3628
from heapq import heappop, heappush

n, nDays = map(int, input().split())
a = sorted(tuple(map(int, input().split())) for _ in range(n))
ret = 0
pq = []
pos = 0
for day in range(nDays + 1):
    while pos < n and a[pos][0] <= day:
        heappush(pq, -a[pos][1])
        pos += 1
    if pq:
        ret -= heappop(pq)
print(ret)

Measured memory_bytes: 77144
#include <iostream>
#include <map>
using namespace std;
using ll = long long;

ll N, K;
int main() {
  cin >> N >> K;
  map<ll, ll> M;
  for(int i = 0; i < N; ++i){
    ll a,b;
    cin >> a >> b;
    M[a] += b;
  }
  
  ll sum = 0;
  ll ans = 0;
  auto it = M.begin();
  while(sum < K) {
    sum += it->second;
    ans = it->first;
    ++it;
  }
  cout << ans << endl;
}


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

int main(){
    int N,W; cin>>N>>W;
    vector<int> w(N+1),v(N+1);
    rep(i,N) cin>>w[i+1]>>v[i+1];

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

    for(int i=1; i<=N; i++){
        for(int j=1; j<=W; j++){
            if(j-w[i]<0){
                dp[i][j] = dp[i-1][j];
                continue;
            }
            dp[i][j] = max(dp[i-1][j], dp[i-1][j-w[i]]+v[i]);
        }
    }
    cout << dp[N][W] << endl;

    // for(int i=0; i<=N; i++){
    //     for(int j=0; j<=W; j++){
    //         cerr << dp[i][j] << " ";
    //     }
    //     cerr << endl;
    // }
}


Measured memory_bytes: 83100
#include <iostream>

using namespace std;

int main() {
	string x, y;
	cin >> x >> y;

	int result = 0;
	if (x[0] == y[0]) result++;
	if (x[1] == y[1]) result++;
	if (x[2] == y[2]) result++;

	cout << result << '\n';

	return 0;	
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <math.h>
int compare_int(const void *a, const void *b)
{
	return *(int *)a - *(int *)b;
}

int main(void)
{
	int i, j;
	//  dic_t dic[200000];
	int ii[100];
	int ilen[100];
	int min, max;
	int len, flg;
	int cnt, maxcnt;
	int X,Y,Z;
  scanf("%d %d %d", &X,&Y,&Z);
  
	printf("%d %d %d\n", Z,X,Y);
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define ll long long
#define ld long double
#define endl "\n"
using namespace std;

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);

    int a,b;
    cin >> a >> b;
    cout << a*b << endl;

    return 0;
}

Measured memory_bytes: 3652
// Copyright 2020 yaito3014
#include <bits/stdc++.h>

int main() {
  using namespace std;
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  int N, M, X;
  cin >> N >> M >> X;
  vector<int> C(N);
  vector<vector<int>> A(N, vector<int>(M));
  constexpr int INF = INT_MAX;
  int ans = INF;
  for (int i = 0; i < N; ++i) {
    cin >> C[i];
    for (auto& e : A[i]) cin >> e;
  }
  const int Max = 1 << N;
  for (int mask = 0; mask < Max; ++mask) {
    int sum = 0;
    vector<int> algos(M, 0);
    for (int i = 0; i < N; ++i) {
      if (~(mask >> i) & 1) continue;
      for (int j = 0; j < M; ++j) algos[j] += A[i][j];
      sum += C[i];
    }
    bool ok = all_of(cbegin(algos), cend(algos), [&](int v) { return v >= X; });
    if (ok) ans = min(ans, sum);
  }
  if (ans == INF) ans = -1;
  cout << ans << endl;
}


Measured memory_bytes: 3664
#include<bits/stdc++.h>
#define ll                      long long int
#define pb                      push_back
#define mp                      make_pair
#define in                      insert
#define all(x)                  (x).begin(),(x).end() 
#define rep(i,a,n)              for(int i=0;i<n;++i)
#define per(i,a,n)              for(int i=n-1;i>=0;--i)
#define mod                     1000000007
using namespace std;

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

    int n;
    cin>>n;
    int t=n;
    n-=1;
    int a[n];
    rep(i,0,n) cin>>a[i];
    
    int freq[t+1]={0};
    rep(i,0,n) freq[a[i]]++;
    for(int i=1;i<=t;++i){
    	cout<<freq[i]<<'\n';
    }


    
    return 0;
}


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

int main(){
    int n,m;
    cin >> n >> m;
    int answer = 0;
    for(int i = 1; i < n; i++){
        answer = answer + i;
    }
    for(int i = 1; i < m; i++){
        answer = answer + i;
    }
    cout << answer;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#pragma comment(linker, "/STACK:16777216")
#pragma warning( disable : 6031)
#include <climits>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <iostream>
#include <map>
#include <stack>
#include <set>
#include <queue>
#include <numeric>
#include <algorithm>
#include <utility>
#include <bitset>
#include <cmath>
#include <sstream>
#include <functional>
#include <iomanip>
#include <limits>

#define all(a) (a).begin(),(a).end()
#define sz(a) (int)(a).size()
#define eps (1e-9)
using namespace std;

typedef long long ll;
typedef vector<int> vi;
typedef vector< vi > vvi;
typedef vector<double> vd;
typedef vector< vd > vvd;
typedef vector< string > vs;
typedef pair< int, int > pii;
typedef vector< pii > vpii;
typedef tuple<int, int, int> tiii;


int main()
{
#ifdef LOCAL_MACHINE
	freopen("input.txt", "rt", stdin);
	freopen("output.txt", "wt", stdout);
#endif
	ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0); cout << setprecision(18) << fixed;
	int n;
	cin >> n;
	double res = 0;
	for (int i = 0; i < n; i++)
	{
		int cur;
		cin >> cur;
		res += 1.0 / cur;
	}
	cout << 1 / res;


	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int maxn = 1e5 + 5;
vector<int> edges[maxn];
int in_degree[maxn];
int dist[maxn];
bool visited[maxn];

void dfs(int u){
    visited[u] = true;
    for(int v : edges[u]){
        dist[v] = max(dist[v], dist[u]+1);
        in_degree[v]--;
        if(in_degree[v] == 0){
            dfs(v);
        }
    }
}

int main(){
    int V, E;
    cin >> V >> E;
    while(E--){
        int u, v;
        cin >> u >> v;
        edges[u].push_back(v);
        in_degree[v]++;
    }
    for(int i=1; i<=V; i++){
        if(!visited[i] && in_degree[i] == 0){
            dfs(i);
        }
    }
    int ans = 0;
    for(int i=1; i<=V; i++){
        ans = max(ans, dist[i]);
    }
    cout << ans << "\n";
}

Measured memory_bytes: 9728
#include<stdio.h>
#include<string.h>

int compare(char *, char *, int);

int main(){
    int length, i;
    char A[200001], B[200001];
    scanf("%s %s", A, B);

    //配列の長さを取得
    length = strlen(A);

    if(compare(A,B,length)) printf("Yes\n");
    else printf("No\n");

    return 0;
}

//判定関数 引数は文字列2つと文字列の長さ
int compare(char *A, char *B, int length){
    int alphabet[26];
    for(int i=0; i<26; i++) alphabet[i]=1;
    for(int i=0; i<length; i++){
        if(alphabet[A[i] - 'a']){
            for(int j=i+1; j<length;j++){
                if(A[i] == A[j]){
                    if(B[i] != B[j]) return 0;
                }
                if(B[i] == B[j]){
                    if(A[i] != A[j]) return 0;
                }
            }
            alphabet[A[i] - 'a'] = 0;
        }
        else;
    }
    return 1;
}


Measured memory_bytes: 512
# B - Construct Sequences
N = int(input())
p = list(map(int,input().split()))
a = [40000*i for i in range(1,N+1)]
b = [40000*i for i in range(N,0,-1)]
for i in range(N):
    b[p[i]-1] += i
print(' '.join(map(str,a)))
print(' '.join(map(str,b)))

Measured memory_bytes: 7216
#include <bits/stdc++.h>
  
using namespace std;
  
#define rep(i,n) REP(i,0,n)
#define REP(i,s,e) for(int i=(s); i<(int)(e); i++)
#define repr(i, n) REPR(i, n, 0)
#define REPR(i, s, e) for(int i=(int)(s-1); i>=(int)(e); i--)
#define pb push_back
#define all(r) (r).begin(),(r).end()
#define rall(r) (r).rbegin(),(r).rend()
#define fi first
#define se second
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
 
const int INF = 1e9;
const ll MOD = 1e9 + 7;
double EPS = 1e-8;

const int MAX_N = 1e5+10;
vector<int> isPrime;
void setPrime() {
    isPrime = vector<int>(MAX_N, 1);
    isPrime[0] = isPrime[1] = 0;
    REP(i, 2, MAX_N) {
        if(isPrime[i]) {
            for(int j = i+i; j < MAX_N; j += i) {
                isPrime[j] = 0;
            }
        }
    } 
}

int main(){
#ifdef LOCAL_TEST
    freopen("in", "r", stdin);
    freopen("out", "w", stdout);
#endif
    setPrime();
    int q;
    cin >> q;
    vector<int> sum(MAX_N);
    rep(i, MAX_N-1) {
        if(isPrime[i] && isPrime[(i+1)/2]) sum[i] = 1;
    }
    REP(i, 1, MAX_N-1) sum[i] += sum[i-1];
    rep(i, q) {
        int l, r;
        cin >> l >> r;
        cout << sum[r] - sum[l-1] << endl;
    }
    return 0;
}

Measured memory_bytes: 1408
#include <iostream>
#include <iomanip>
#include <fstream>
#include <sstream>
#include <vector>
#include <algorithm>
#include <math.h>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <bitset>

#define _GLIBCXX_DEBUG
#define rep(i, n) for (int64_t i = 0; i < (int64_t)(n); i++)
using namespace std;
using vi = vector<int64_t>;
using vvi = vector<vi>;

int main(int argc, const char * argv[]) {
    // fasten cin
    cin.tie(0);
    ios::sync_with_stdio(false);
    // implement
    int64_t n,x;
    cin >> n >> x;
    vi m(n);
    rep(i,n) cin >> m.at(i);
    int64_t sum = 0;
    rep(i,n) sum+=m.at(i);
    sort(m.begin(), m.end());
    cout << n + (x-sum)/m.at(0) << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <queue>
using namespace std;

using Position = pair<int,int>;

int main() {
  int h, w;
  cin >> h >> w;
  vector<string> field(h);
  for (int i = 0; i < h; ++i)
    cin >> field[i];

  int num_white = 0;
  for (auto& line : field) {
    for (char c : line) {
      num_white += (c == '.');
    }
  }

  vector<vector<int>> dp(h, vector<int>(w, h * w + 1));
  queue<Position> q;

  dp[0][0] = 0;
  q.push(Position(0, 0));
  while (!q.empty()) {
    Position pos = q.front();
    q.pop();
    static const int dirs[][2] = {{-1, 0}, {1, 0}, {0, -1}, {0, 1}};
    int dist = dp[pos.first][pos.second] + 1;
    for (auto dir : dirs) {
      Position p {pos.first + dir[0], pos.second + dir[1]};
      if (p.first < 0 || p.second < 0 || p.first >= h || p.second >= w)
        continue;
      if (field[p.first][p.second] == '#')
        continue;
      if (dp[p.first][p.second] <= dist)
        continue;
      dp[p.first][p.second] = dist;
      q.push(p);
    }
  }

  if (dp[h-1][w-1] >= h * w) {
    cout << "-1\n";
  } else {
    cout << (num_white - dp[h-1][w-1] - 1) << "\n";
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define rep(i,n) for(int i=0;i<(n);++i)
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
int gcd(int a,int b) { return b ? gcd(b,a%b) : a;}
int lcm(int a,int b) { return a/gcd(a,b)*b;}
void printb(unsigned int v) {
  unsigned int mask = (int)1 << (sizeof(v) * CHAR_BIT - 1);
  do putchar(mask & v ? '1' : '0');
  while (mask >>= 1);
}
void putb(unsigned int v) {putchar('0'), putchar('b'), printb(v), putchar('\n');}
#define ALL(W) (W).begin(),(W).end()

int r,D,x;
void solve(int x,int depth){
  x=r*x-D;
  cout << x << endl;
  if(depth<9) solve(x,depth+1);
}

signed main(){
  cin >> r >> D >> x;
  solve(x,0);
  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#define LEN 1000000
 
typedef struct pp{
  char name[100];
  int t;
}P;

P Q[LEN+1];
 
int main(){
  int n, i, q, sum =0, last, cnt=0;
  scanf("%d %d", &n, &q);
 
  for ( i = 1; i <= n; i++){
    scanf("%s", Q[i].name);
    scanf("%d", &Q[i].t);
  }
  i = 1;
  last = n;
  while(1){
    if(Q[i].t > q){
      sum += q;
      strcpy(Q[last+1].name, Q[i].name);
      Q[last+1].t = Q[i].t - q;
      last++;
    } else {
      sum += Q[i].t;
      printf("%s %d\n", Q[i].name, sum);
      cnt++;
    }
    i++;
    if(cnt == n) break;
  }   
  return 0;
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int k, a, b;
    cin >> k >> a >> b;
    for(int i=a; i<=b; i++) {
        if(i%k == 0) {
            cout << "OK";
            return 0;
        }
    }
    cout << "NG";
    return 0;
}


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

typedef long long ll;
#define REP(i,n) for(int i=0,_n=(int)(n);i<_n;++i)
#define ALL(v) (v).begin(),(v).end()
#define CLR(t,v) memset(t,(v),sizeof(t))
template<class T1,class T2>ostream& operator<<(ostream& os,const pair<T1,T2>&a){return os<<"("<<a.first<<","<<a.second<< ")";}
template<class T>void pv(T a,T b){for(T i=a;i!=b;++i)cout<<(*i)<<" ";cout<<endl;}
template<class T>void chmin(T&a,const T&b){if(a>b)a=b;}
template<class T>void chmax(T&a,const T&b){if(a<b)a=b;}


const ll MOD = 998244353;



const int SZ = 1000000;
ll inv[SZ];
ll fact[SZ];
ll fact_inv[SZ];
ll choose(int n, int r) {
  if (n < 0 || r < 0 || n < r) return 0;
  return fact[n] * fact_inv[n-r] % MOD * fact_inv[r] % MOD;
}

int main2() {
  int N; cin >> N;
  ll A, B; cin >> A >> B;
  ll K; cin >> K;

  ll ans = 0;
  for (ll r = 0; r <= N; r++) {
    if (K >= A * r) {
      ll remain = K - A * r;
      if (remain % B == 0) {
        ll b = remain / B;
        if (0 <= b && b <= N) {
          ans += choose(N, r) * choose(N, b);
          ans %= MOD;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

int main() {

  inv[1] = 1;
  for (int i = 2; i < SZ; i++) inv[i] = inv[(int) (MOD % i)] * (MOD - MOD / i) % MOD;
  fact[0] = 1;
  for (int i = 1; i < SZ; i++) fact[i] = fact[i-1] * i % MOD;
  fact_inv[0] = 1;
  for (int i = 1; i < SZ; i++) fact_inv[i] = fact_inv[i-1] * inv[i] % MOD;


  for (;!cin.eof();cin>>ws)
    main2();
  return 0;
}


Measured memory_bytes: 23680
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef double D;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int,int> PII;
typedef pair<ll,ll> PLL;
typedef long double ld;

#define rd(x) scanf("%d",&x)
#define rd2(x,y) scanf("%d %d",&x,&y)
#define rd3(x,y,z) scanf("%d %d %d",&x,&y,&z)
#define rl(x) scanf("%lld",&x)
#define rl2(x,y) scanf("%lld %lld",&x,&y)
#define rl3(x,y,z) scanf("%lld %lld %lld",&x,&y,&z)
#define wd(x) printf("%d" ,x)
#define wd2(x,y) printf("%d %d",x,y)
#define wl(x) printf("%lld",x)
#define wl2(x,y) printf("%lld %lld",x,y)
#define PC(x) putchar(x)
#define GC() getchar()
#define NL printf("\n")
#define SP printf(" ")
 
#define SZ(a) (int)a.size()
#define ALL(a) a.begin(), a.end()
#define ITER(it,a) for (__typeof(a.begin()) it = a.begin(); it != a.end(); it++)
#define FILL(a,value) memset(a, value, sizeof(a))

#define F first
#define S second
#define MP make_pair
#define PB push_back


#define L_B lower_bound
#define U_B upper_bound

#define SPEED ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#define fastio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define fast_cin() ios_base::sync_with_stdio(false); cin.tie(NULL)
#define fr(i,s,e) for(int i=s;i<e;i++)
#define frl(i,s,e) for(ll i=s;i<e;i++)
#define frr(i,s,e) for(int i=s-1;i>=e;i--)
#define frv(i,a) for(int i = 0;i<(int)a.size();i++)
#define frvr(i,a) for(int i = a.size()-1;i>=0;i--)
#define tr(i,a) for(typeof(a.begin()) i = a.begin(); i != a.end();i++)

#define inf (1000*1000*1000+5)
#define mod 1000000007
#define maxn 100009
#define maxr 100009
int main(){
	//sstd::ios::sync_with_stdio(false); cin.tie(NULL);
	ll n,k;
	rl2(n,k);
	VL p(n);
	vector<double> ex(n);
	fr(i,0,n)
	{
		rl(p[i]);
		ex[i]=((double)(p[i]+1))/2;
	}
	double sum=0;
	ll end=0;
	double ans=-inf;
	fr(i,0,k)
	{
		sum+=ex[i];
	}
	ans=max(ans,sum);
	fr(i,k,n)
	{
		sum+=ex[i];
		sum-=ex[end];
		end++;
		ans=max(ans,sum);
	}
	cout<<fixed<<setprecision(30);
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 3328
#include<cstdio>
#include<algorithm>
#include<vector>
#include<deque>
#include<stack>
#include<queue>
#include<string>
#include<iostream>
#include<tuple>
#include<utility>
#include<set>
#include<queue>
#include<iomanip>
#include<iterator>
//#include<chrono>
//cout<<setprecision(12)
//fixed
#include<random>
using namespace std;
typedef long long int llint;
typedef long double lldo;
const int big=1e9+100000;
const int mod=1e9+7;
const lldo eps=1e-9;
const long double pai=3.141592653589793238462643;
#define mt make_tuple
#define mp make_pair
#define fir first
#define sec second
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define res resize
#define ins insert
#define era erase
template <class T,class U>void mineq(T& a,U b){if(a>b){a=b;}}
template <class T,class U>void maxeq(T& a,U b){if(a<b){a=b;}}
int main(void){
	int i,n;cin>>n;
	vector<pair<lldo,lldo>>ise(n);
	lldo bmax=1e6+10,bmin=0;
	for(i=0;i<n;i++){cin>>ise[i].fir>>ise[i].sec;mineq(bmax,ise[i].sec);}
	for(int h=0;h<500;h++){
		lldo lef=-big,rig=big,gen=(bmax+bmin)/2;
		for(i=0;i<n;i++){
			maxeq(lef,ise[i].fir-sqrt(ise[i].sec*ise[i].sec-gen*gen));
			mineq(rig,ise[i].fir+sqrt(ise[i].sec*ise[i].sec-gen*gen));
		}
		if(lef<=rig){bmin=gen;}
		else{bmax=gen;}
	}
	cout<<fixed<<setprecision(12)<<bmax<<endl;
	return 0;
}

Measured memory_bytes: 6008
#pragma GCC optimize("Ofast", "unroll-loops")
#pragma GCC target("avx2,fma")
#include <bits/stdc++.h>
using namespace std;
#define rep(i, a, b) for (__typeof(a) i = (a); i < (b); ++i)
#define iter(it, c) \
  for (__typeof((c).begin()) it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
const int INF = ~(1 << 31);

#define sc second
#define fs first
#define pb push_back

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T>
T smod(T a, T b) {
  return (a % b + b) % b;
}
// vim: cc=60 ts=2 sts=2 sw=2:

int h[100'050];
int memo[100'050];
int k;

ll dp(int at) {
  if (at == 0) return 0;
  if (at < 0) return INF;
  if (memo[at] != -1) return memo[at];
  ll bst = INF;
  rep(i, 1, k + 1) {
    if (at - i >= 0) bst = min(bst, dp(at - i) + abs(h[at] - h[at - i]));
  }
  return memo[at] = bst;
}

int main() {
  // code
  memset(memo, -1, sizeof(memo));

  int n;
  cin >> n >> k;

  rep(i, 0, n) cin >> h[i];

  cout << dp(n - 1) << endl;

  // codend
}


Measured memory_bytes: 4096
#include<stdio.h>
int main()
{
    int a,b,c,k,s=0;
  scanf("%d%d%d%d",&a,&b,&c,&k);

     if(k<=a)
       printf("%d",k);
  else if(k<=a+b)
    printf("%d",a);
  else
    printf("%d",a-(k-a-b));
     
     return 0;
     }


Measured memory_bytes: 1732
use std::io::{stdin, Read, StdinLock};
use std::str::FromStr;
use std::cmp::Ordering;
use std::f64::consts::PI;
use std::cmp;


fn get_line() -> String {
    let mut line = String::new();
    stdin().read_line(&mut line).ok();
    line
}

fn get_num() -> i32 {
    let mut x = String::new();
    stdin().read_line(&mut x).unwrap();
    let x = x.trim().parse().unwrap();
    x
}

fn get_vector() -> Vec<i64> {
    let line = get_line();
    let vec : Vec<i64> = line.split_whitespace().map(|x| i64::from_str(x).unwrap()).collect();
    return vec;
}

fn main() {

    let n: i32 = get_num();
    let v = get_vector();

    let min = v.iter().min().unwrap();
    let max = v.iter().max().unwrap();
    let sum: i64 = v.iter().sum();

    println!("{} {} {}", min, max, sum);
}



Measured memory_bytes: 5044
#include <iostream>
#define ll long long
using namespace std;
ll n, sum, num, x;
int main () {
	ios::sync_with_stdio(0);
	cin >> n;
	for(int i = 1; i <= n; i++) {
		cin >> x;
		if(x % 4 == 0)
			sum ++;
		if(x % 2 == 0 && x % 4 != 0)
			num ++;
	} 
	if(num % 2 == 1)
		num --;
	n -= num;
	if(sum >= n / 2) cout << "Yes" << endl;
	else cout << "No" << endl;
	return 0; 
}

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

using namespace std;

int main(){
    long long int n,k,a,b;
    map<long long int, long long int> mp;
    cin >> n>>k;
    for(int i=0;i<n;i++){
        cin >> a >>b;
        if(mp[a]>0)mp[a]+=b;
        else mp[a]=b;
    }
    for(auto itr = mp.begin(); itr != mp.end(); ++itr) {
         k -= itr->second;
        if(k<=0){
            cout<<itr->first<<endl;
            break;
        }
    }


    return 0;
}


Measured memory_bytes: 4224
#include <stdio.h>

int main(){
    int H,W;
    scanf("%d %d",&H,&W);
    while(!(H==0&&W==0)){
        for(int i=0;i<H;i++){
            for(int f=0;f<W;f++){
                if(i==0||i==H-1){
                    printf("#");
                }else{
                    if(f==0||f==W-1){
                        printf("#");
                    }else{
                        printf(".");
                    }
                }
            }
            printf("\n");
        }
        printf("\n");
        scanf("%d %d",&H,&W);
    }
}


Measured memory_bytes: 2032
H, W = (list)(map(int, input().split()))
N = 10
mp = [[l for l in (list)(map(int, input().split()))] for _ in range(N)]

wall = [[l for l in (list)(map(int, input().split()))] for _ in range(H)]


def dijkstra(s, g):
    '''
        s:start node
        g:foal node
        return cost from s to g
    '''
    return 0


def war(mp):
    for i in range(N):
        for j in range(N):
            for k in range(N):
                mp[j][k] = min(mp[j][k], mp[j][i]+mp[i][k])
    return mp


mp = war(mp)
cost = 0
for l in wall:
    for i in l:
        if i == -1:
            continue
        else:
            cost += mp[i][1]
print(cost)


Measured memory_bytes: 40432
#include<stdio.h>
int main(void){
   int t, n, s, f, i, sum;
   scanf("%d", &t);
   while ( t ) {
      sum = 0;
      scanf("%d", &n);
      for ( i = 0; i < n; i++ ) {
         scanf("%d %d", &s, &f);
         sum += f - s;
      }
      if ( sum >= t) printf("OK\n");
      else printf("%d\n", t - sum);
      scanf("%d", &t);
   }
   return 0;
}

Measured memory_bytes: 1856
#include <stdio.h>

int reversedigit(int n)
{
  int reverse = 0;
  while (n) {
    reverse = reverse * 10 + n % 10;
    n /= 10;
  }
  return reverse;
}

int main(void)
{
  int a, b, i, j;
  int count = 0;
  
  scanf("%d%d", &a, &b);
  
  for (i = a; i <= b; i++) 
    if (reversedigit(i) == i)
      count++;
  
  printf("%d", count);
  return 0;
}
    

Measured memory_bytes: 128