akhauriyash/Code-Regression huggingface dataset:
use std::fmt::{Debug, Display};
use std::io::{self, Read};
use std::str::{self, FromStr};

fn main() {
    let stdin = io::stdin();
    let mut sc = Scanner::new(stdin.lock().bytes());
    let n = sc.next();
    println!("{}", solve(sc.vec(n)));
}


fn solve(a: Vec<i64>) -> i64 {
    let sum = a.iter().map(|&x| x).sum::<i64>();
    let mut left = a[0];
    let mut diff = (sum - 2 * left).abs();
    let mut result = diff;
    for x in (1..a.len() - 1).map(|i| a[i]) {
        left += x;
        if (sum - 2 * left).abs() < diff {
            diff = (sum - 2 * left).abs();
            result = diff;
        }
    }
    result
}


struct Scanner<R: Read> {
    buf: Vec<u8>,
    bytes: io::Bytes<R>,
}

#[allow(dead_code)]
impl<R: Read> Scanner<R> {
    fn new(bytes: io::Bytes<R>) -> Self {
        Scanner {
            buf: Vec::with_capacity(256),
            bytes: bytes,
        }
    }

    fn next<T: FromStr>(&mut self) -> T
        where <T as FromStr>::Err: Debug
    {
        self.buf.clear();
        let mut c = self.bytes.next().unwrap().unwrap();
        while c == ' ' as u8 || c == '\n' as u8 {
            c = self.bytes.next().unwrap().unwrap();
        }
        while !(c == ' ' as u8 || c == '\n' as u8) {
            self.buf.push(c);
            c = self.bytes.next().unwrap().unwrap();
        }
        str::from_utf8(&self.buf).unwrap().parse().unwrap()
    }

    fn vec<T: FromStr>(&mut self, n: usize) -> Vec<T>
        where <T as FromStr>::Err: Debug
    {
        (0..n).map(|_| self.next()).collect()
    }

    fn pairs<A: FromStr, B: FromStr>(&mut self, n: usize) -> Vec<(A, B)>
        where <A as FromStr>::Err: Debug,
              <B as FromStr>::Err: Debug
    {
        (0..n).map(|_| (self.next(), self.next())).collect()
    }

    fn trios<A: FromStr, B: FromStr, C: FromStr>(&mut self, n: usize) -> Vec<(A, B, C)>
        where <A as FromStr>::Err: Debug,
              <B as FromStr>::Err: Debug,
              <C as FromStr>::Err: Debug
    {
        (0..n)
            .map(|_| (self.next(), self.next(), self.next()))
            .collect()
    }

    fn mat<T: FromStr>(&mut self, m: usize, n: usize) -> Vec<Vec<T>>
        where <T as FromStr>::Err: Debug
    {
        (0..n).map(|_| self.vec(m)).collect()
    }
}


#[allow(dead_code)]
fn print_foreach<T: Display>(answer: &[T]) {
    for x in answer {
        println!("{}", x);
    }
}


#[allow(dead_code)]
fn print_yn(answer: bool, yes: &str, no: &str) {
    println!("{}", if answer { yes } else { no });
}


#[allow(dead_code)]
fn print_or<T: Display>(answer: &Option<T>, or: &T) {
    match *answer {
        Some(ref x) => println!("{}", x),
        None => println!("{}", or),
    }
}


Measured memory_bytes: 6396
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define ll long long
#define lb lower_bound
#define ub upper_bound
#define endl "\n"
#define ff first
#define ss second
#define prec(y,x) fixed<<setprecision(y)<<x
#define inf 1e18
#define pi 3.1415926535

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	int x, y;
	cin >> x >> y;
	for (int i = 0; i <= x; i++)
	{
		int a = i * 2;
		a += 4 * (x - i);
		if (a == y)
		{cout << "Yes"; return 0;}
	}
	cout << "No";

	return 0;
}

Measured memory_bytes: 3644
day=input()
if (day=="SUN"):
  print(7)
elif (day=="MON"):
  print(6)
elif (day=="TUE"):
  print(5)
elif(day=="WED"):
  print(4)
elif(day=="THU"):
  print(3)
elif(day=="FRI"):
  print(2)
elif(day=="SAT"):
  print(1)

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


// type definitions
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > vvi;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef complex<int> ci;
typedef complex<double> cd;
typedef complex<long double> cld;
typedef long double ld;

// macros
#define rep(i, a, b) for(int i=a; i<b; i++)
#define TIME clock() * 1.0 / CLOCKS_PER_SEC
#define all(c) c.begin(), c.end()
#define tr(c, it) for(auto it=(c).begin(); it!=c.end(); it++)
#define PB push_back
#define MP make_pair
#define bitcount __builtin_popcount
#define watch(x) cerr<< (#x) << " is " << (x) <<"\n";
#define sz(x) ((int)((x).size()))
#define UNIQUE(c) (c).resize(unique(all(c)) - (c).begin())
#define pii2ll(p) ((ll)(p).first<<32 | (p).second)

// template functions
template <typename T>
inline void printV(vector<T>& a) { rep(i, 0, sz(a)) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printV(vector<T>& a, int n) { rep(i, 0, n) { cout<<a[i]<<" "; } cout<<"\n"; }
template <typename T>
inline void printVV(vector<vector<T>>& a)
{
	rep(i, 0, sz(a)) {
		printV(a[i]);
	}
	cout<<"\n";
}

template <typename T>
inline void clearVV(vector<vector<T>>& a)
{
	for(auto& x:a) {
		x.clear();
	}
	a.clear();
}
template <typename T>
inline void assignVV(vector<vector<T>> &a, T val)
{
	for(int i=0; i<sz(a); i++) {
		for(int j=0; j<sz(a[i]); j++) {
			a[i][j]=val;
		}
	}
}

// random number generation
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

// constants
const long double eps = LDBL_EPSILON;
const int inf = 5e8;
const int modn = 1e9+7;
const int MAX = 1e5;



int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    // Your code here
	string s;
	cin>>s;
	int ans1=0, ans2=0;
	int i1=0, i2=1;
	for(int i=0; i<sz(s); i++) {
		if(s[i]-'0'!=i1) {
			ans1++;
		}
		if(s[i]-'0'!=i2) {
			ans2++;
		}
		i1=1-i1;
		i2=1-i2;
	}
	cout<<min(ans1, ans2)<<"\n";
    return 0;
}



Measured memory_bytes: 512
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
 	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
    ll n,t;cin>>n>>t;
    ll arr[n];
    for(ll i=0; i<n; i++) cin>>arr[i];
    ll ans=0, prev = 0;
    for(int i=0; i<n; i++){
        if(arr[i]<=prev){
        ll tem = arr[i] + t;
        ans = ans + (tem-prev);
        prev = prev + (tem - prev);
        }
        else{
            prev = arr[i] + t;
            ans = ans+t;
        }
    }
    cout<<ans<<endl;

	return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;

typedef pair<int, int> PII;
typedef map<int, int> MII;
typedef priority_queue<int> P_QI;
typedef priority_queue<string> P_QS;
typedef vector<int> VI;
typedef vector<long long> VLL;
typedef vector< int > :: iterator $$;

#define SET(arr) memset(arr, -1, sizeof(arr))
#define CLR(arr) memset(arr, 0, sizeof(arr))

#define READ(f) freopen(f, "r", stdin)
#define WRITE(f) freopen(f, "w", stdout)

#define $ vector< int > :: iterator
#define m_p make_pair
#define p_b push_back
#define rep(i, n) for(int i=0; i<(n); i++)
#define forn(i, n) for (int i = 1; i <=(int)(n); ++i)
#define forab(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define forba(i, b, a) for (int i = (int)(b); i >= (int)(a); --i)

#define forv(i,v) rep(i,SZ(v))
#define forit(i,s) for(auto i=(s).begin();i!=(s).end();++i)

#define Boost ios_base::sync_with_stdio(0); cin.tie(0)
#define all(a) (a).begin(), (a).end()
#define SZ(x) ((int)(x).size())
#define F first
#define S second
#define _ <<" "<<
#define CS(i) cout<<"Case "<<(int)(i)<<": "

const int MOD = 1e9+7;
const int inf = 1e9+9;
const long long INF = 1e18+3;
const ld eps = 1e-9;
const ld PI=acos(-1.0);


int main() {
Boost;
//READ("in.txt");
//WRITE("out.txt");
    int a,b,ans=0;
    cin>>a>>b;
    forab(i,a,b){
        if(i%10==i/10000 && ((int)i/10)%10== ((int)i/1000)%10) ans++;
    }
    cout<<ans<<endl;

return 0;
}


Measured memory_bytes: 256
import math

A, B, H, M = map(int, input().split())

sp_s = math.radians(360 / (12 * 60) * (H*60 + M))
sp_l = math.radians(int(6 * M))

sx = A * math.sin(sp_s)
sy = A * math.cos(sp_s)

lx = B * math.sin(sp_l)
ly = B * math.cos(sp_l)

val1 = (lx - sx) ** 2
val2 = (ly - sy) ** 2

print(((lx - sx) ** 2 + (ly - sy) ** 2) ** .5)




Measured memory_bytes: 9516
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long int ll;
 
#define pii pair<int, int>
#define F first
#define S second
#define pb push_back
 
const int N = 1e5 + 5;
const int mod = 1e9+7;
const ll INF = (ll)1e18;

int main(){
    ios_base :: sync_with_stdio(0);
    cin.tie(0);
 
    string s, t;
    cin >> s >> t;
    int n = s.length();
    int m = t.length();
    vector< vector<int> > dp(m+1, vector<int>(n+1, 0));
    for(int ii = 1; ii <= m; ii ++){
        char i = t[ii - 1];
        vector<int> &cur = dp[ii];

        for(int j = 1; j <= n; j++){
            cur[j] = dp[ii - 1][j];
            if(cur[j-1] > cur[j]) cur[j] = cur[j-1];

            if(s[j-1] == i && (1+dp[ii - 1][j-1]) > cur[j]){
                cur[j] = dp[ii - 1][j-1] + 1;
            } 
        }
        // for(int j = 1; j <= n; j++) cout << "(" << dp[j] << " " << bck[j] << ") "; cout << endl;
    }
    string ans = "";
    // cout << dp[m][n] << endl;
    int r = m, c = n;
    while(r > 0 && c > 0){
        if(dp[r][c] == dp[r-1][c]){
            r --;
            continue;
        }
        if(dp[r][c] == dp[r][c-1]){
            c--;
            continue;
        }
        ans += s[c-1];
        r --, c --;
    }
    reverse(ans.begin(), ans.end());
    cout << ans ;
    return 0;
}

Measured memory_bytes: 35584
import sys
def input(): return sys.stdin.readline().strip()

def resolve():
    def main():
        s=input()
        for i in range(len(s)):
            for j in range(i+1,len(s)):
                if s[i]==s[j]:
                    return 'no'
        return 'yes'
    print(main())
resolve()

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
int main() {
    int n;
    cin >> n;

    vector<int> a(n+1);

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

    int right = 0;
    long ans = 0;
    long sum = a[0];

    for (int i = 0; i< n; i++) {
        while (right < n - 1 && (xo ^ a[right + 1]) == (sum + a[right + 1])) {
            right++;
            xo ^= a[right];
            sum += a[right];
        }
        ans += right - i + 1;
        xo ^= a[i];
        sum -= a[i];
        if (i == right) {
            right++;
            xo = a[right];
            sum = a[right];
        }
    }
    cout << ans << endl;
    return 0;
}



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


int main() {
    int d[5];
    int k;
    for (int i=0; i < 5; i++) {
        cin >> d[i];
    }
    cin >> k;
    bool flag = true;
    for (int i=0; i < 5; i++) {
        for (int j = i+1; j < 5; j++) {
            if (d[j] - d[i] > k) {
                printf(":(\n");
                flag = false;
                break;
            }
        }
        if(!flag) {
            break;
        }
    }
    if (flag) printf("Yay!\n");
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<cmath>
#include<queue>
#include<map>
#include<set>
#include<list>
#include<iomanip>
#include<vector>
#include<functional>
#include<algorithm>
#include<cstdio>
#include<unordered_map>
using namespace std;
//---------------------------------------------------
//????????????????????????????????????
#define int long long
#define str string
typedef long long ll;
typedef long double ld;
const ll inf = 999999999999999999;
struct P {
	ll pos, cost;
};
bool operator<(P a, P b) { return a.cost < b.cost; }
bool operator>(P a, P b) { return a.cost > b.cost; }
struct B {
	ll to, cost;
};
ll gcm(ll i, ll j) {//?????§??¬?´???°
	if (i > j) swap(i, j);
	if (i == 0) return j;
	return gcm(j%i, i);
}

//---------------------------------------------------
//+++++++++++++++++++++++++++++++++++++++++++++++++++
int n, s;
int dp[11][331][1024];
signed main() {
	dp[0][0][0] = 1;
	for (int i = 0; i < 10; i++) 
		for (int j = 0; j < 331; j++) 
			for (int z = 0; z < 1024; z++) 
				if (dp[i][j][z] > 0) 
					for (int x = 0; x < 10; x++) 
						if (!((1 << x)&z))
							dp[i + 1][j + x*(i + 1)][z | (1 << x)] += dp[i][j][z];
	while (cin >> n >> s) {
		if (s > 330) {
			cout << 0 << endl;
			continue;
		}
		int ans = 0;
		for (int i = 0; i < 1024; i++)
			ans += dp[n][s][i];
		cout << ans << endl;
	}
	//getchar(); getchar();
}

Measured memory_bytes: 9788
from itertools import combinations_with_replacement
q=int(input())
AB=[list(map(int,input().split())) for _ in range(q)]

for a,b in AB:
    a,b=min(a,b),max(a,b)
    criteria=a*b
    left,right=a,b
    while right>left+1:
        mid=(left+right)//2
        if mid**2>criteria:right=mid
        else:left=mid

    cnt,point=0,0
    for i,j in enumerate(combinations_with_replacement([left,right],2)):
        if point<j[0]*j[1]<=criteria:
            point=j[0]*j[1]
            cnt=i

    #print(left,right)
    if cnt==0:
        if point==criteria:
            if a!=b:print((left-1)*2-1)
            else:print(left*2-2)
        else:print(left*2-2)
    else:
        if point==criteria:print(left*2-2)
        else:print(left*2-1)

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

//using th
//using if(from==0){};

namespace agc010_a
{
    class Program
    {
        static void Main(string[] args)
        {
           
            long kinokosuu = 0;
            long gunokosu=0;
            //long kiwomatomeyou=0;
            long s = Int64.Parse(Console.ReadLine());
            long[] a = Console.ReadLine().Split().Select(long.Parse).ToArray();
            for (long
              i = 0; i < s; i++) { if (a[i] % 2 == 0) {  gunokosu++; }
                else { kinokosuu++; }
            }
            if (kinokosuu % 2 == 0) {
              //  if (gunokosu % 2 == 0) { Console.WriteLine("Yes"); }
                Console.WriteLine("YES"); }

            else { Console.WriteLine("NO"); }

            //{ kiwomatomeyou = kinokosuu / 2; } else { kiwomatomeyou =( kinokosuu/2)+1; }
            //  if ((kiwomatomeyou + gunokosu )%2== 0)
            /*          { Console.WriteLine("Yes"); }
                  {Console.WriteLine("No"); }

                  Console.ReadLine();
             */
        }
    }
}

Measured memory_bytes: 14424
#include <bits/stdc++.h>
using namespace std;
int main(void){
    long long int x,k,d,n,a,ans;
    cin>>x>>k>>d;
    n=k-x/d;
    if(n>=2*k)ans=abs(x+d*k);
    else if (n<0)ans=abs(x-d*k);
    else{
        n/=2;
        ans=min(abs(x+d*(2*n-k)),abs(x+d*(2*(n+1)-k)));
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 3600
#include<bits/stdc++.h>
#include<unordered_map>
#include<unordered_set>

using namespace std;

int n,ans;
int a[100010][4];
int f[100010][4];

int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=3;j++)
		{
			scanf("%d",&a[i][j]);
		}
	}
	for(int i=1;i<=n;i++)
	{
		f[i][1]=max(f[i-1][2],f[i-1][3])+a[i][1];
		f[i][2]=max(f[i-1][1],f[i-1][3])+a[i][2];
		f[i][3]=max(f[i-1][2],f[i-1][1])+a[i][3];
	}
	for(int i=1;i<=3;i++)
	{
		ans=max(ans,f[n][i]);
	}
	printf("%d",ans);
	return 0;
}


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

#define ll long long int
#define rep(i, a, n) for (int i = a; i < n; i++)
#define INF 1e9
#define LINF 1e17
#define MOD (int)(1e9 + 7)
#define pi 3.141592653589
#define pii pair<int, int>
#define pll pair<ll, ll>
#define vi vector<int>
#define vll vector<ll>
#define ALL(a) (a).begin(), (a).end()
#define sort_v(a) sort(a.begin(), a.end())
#define fi first
#define se second

void print(bool c)
{
    if (c)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
}

ll gcdll(ll a, ll b)
{
    while (1)
    {
        if (a < b)
            swap(a, b);
        if (b == 0)
            break;
        a %= b;
    }
    return a;
}

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

bool cmp(const pii &a, const pii &b)
{
    if (a.second != b.second)
        return a.second < b.second;
    return a.first < b.first;
}

int main()
{
    double n, d;
    cin >> n >> d;
    cout << ceil(n / (2 * d + 1)) << endl;
}


Measured memory_bytes: 256
#include <fstream>
#include <iostream>
#include <functional>
#include <algorithm>
#include <sstream>
#include <cstring>
#include <vector>
#include <string>
#include <cstdio>
#include <cmath>
#include <queue>
#include <stack>
#include <deque>
#include <ctime>
#include <list>
#include <set>
#include <map>
using namespace std;

typedef long long ll;
#define eps 1e-10
#define LL_INF 0x3fffffffffffffff
#define INF 0x3f3f3f3f
#define mem(a, b) memset(a, b, sizeof(a))
#define pper(i,n,m) for(int i = n;i >= m; i--)
#define repp(i, n, m) for (int i = n; i <= m; i++)
#define rep(i, n, m) for (int i = n; i < m; i++)
#define sa(n) scanf("%d", &(n))
#define mp make_pair
#define ff first
#define ss second
#define pb push_back

const int maxn = 1e5 + 5;
const double PI = acos(-1.0);
const ll mod = 1e9 + 7;
ll po(ll a, ll b,ll mod) { ll res = 1; a %= mod; for (; b; b >>= 1) { if (b & 1)res = res*a%mod; a = a*a%mod; }return res; }
ll gcd(ll a,ll b){ if(a==0){return b;}else{ return gcd(b%a,a);}}

ll n;
ll a[maxn],b[maxn];
ll vis[maxn],v[maxn];

void solve()
{
	scanf("%lld",&n);
	repp(i,1,n)
	{
		scanf("%lld",&a[i]);
	}
	repp(i,1,n)
	{
		scanf("%lld",&b[i]);
	}
	repp(i,1,n)
	{
		if(a[i]<a[i-1])
		{
			puts("0");
			return;
		}
	}
	for(int i=n-1;i>=1;i--)
	{
		if(b[i]<b[i+1])
		{
			puts("0");
			return;
		}
	}

	for(int i=1;i<=n;i++)
	{
		if(a[i]>a[i-1])
		{
			vis[i]=1;
			v[i]=a[i];
		}
	}
	for(int i=n;i>=1;i--)
	{
		if(b[i]>b[i+1])
		{
			if(vis[i])
			{
				if(b[i]!=v[i])
				{
					puts("0");
					return;
				}
			}
			else
			{
				vis[i]=1;
				v[i]=b[i];
			}
		}
	}
	ll maxx=0;
	repp(i,1,n)
	{
		if(vis[i])
		{
			maxx=max(maxx,v[i]);
		}
		if(a[i]<maxx)
		{
			puts("0");
			return;
		}
	}
	maxx=0;
	for(int i=n;i>=1;i--)
	{
		if(vis[i])
		{
			maxx=max(maxx,v[i]);
		}
		if(b[i]<maxx)
		{
			puts("0");
			return;
		}
	}
	ll res=1;
	for(int i=1;i<=n;i++)
	{
		if(vis[i]==0)
		{
			res=res*min(a[i],b[i])%mod;
		}
	}

	printf("%lld\n",res);
}

int main()
{

    solve();
    return 0;
}

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

#define rng(i, a, b) for (int i = int(a); i < int(b); i++)
#define rep(i, b) rng(i, 0, b)
#define gnr(i, a, b) for (int i = int(b) - 1; i >= int(a); i--)
#define per(i, b) gnr(i, 0, b)

using namespace std;

using ll = long long;
using P = pair<int, int>;

int main() {
  string s;
  cin >> s;
  vector<int> cnt(26, 0);
  for (char c : s) {
    cnt.at(c - 'a')++;
  }
  bool exists = false;
  string res(s);
  bool nextExists = false;
  char next;
  rep(i, cnt.size()) {
    if (cnt.at(i) == 0) {
      nextExists = true;
      next = 'a' + i;
      break;
    }
  }
  if (nextExists) {
    res.push_back(next);
    exists = true;
  } else {
    while (!res.empty()) {
      char c = res.substr(res.size() - 1, 1).c_str()[0];
      res.pop_back();
      cnt.at(c - 'a')--;
      bool replaceExists = false;
      char replace;
      for (int i = c - 'a' + 1; i < cnt.size(); i++) {
        if (cnt.at(i) == 0) {
          replaceExists = true;
          replace = 'a' + i;
          break;
        }
      }
      if (replaceExists) {
        res.push_back(replace);
        exists = true;
        break;
      }
    }
  }
  if (exists) {
    cout << res << endl;
  } else {
    cout << -1 << endl;
  }
  return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <stdio.h>
#include <vector>
#include <cmath>
#include <algorithm>
#include <string>
#include <queue>
#include <stack>
#include <functional>
#include <list>
#include <utility>
#include <map>
#include <vector>
using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> Pii;
typedef pair<ll, ll> Pll;
typedef pair<int, Pii > P1;

#define rep(i,n) for(int i=0;i<n;i++)
#define rep1(i,x) for(int i=1;i<=x;i++)
#define rrep(i,x) for(int i=x-1;i>=0;i--)
#define rrep1(i,x) for(int i=x;i>0;i--)
#define sor(v) sort(v.begin(),v.end())
#define rev(s) reverse(s.begin(),s.end())
#define lb(vec,a) lower_bound(vec.begin(),vec.end(),a)
#define ub(vec,a) upper_bound(vec.begin(),vec.end(),a)
#define mp1(a,b,c) P1(a,P(b,c))
#define get_arsize(a) (sizeof(a)/sizeof(a[0]))
const double eps = 1e-10;
const int MOD = 1000000007;

ll modPow(int n, ll base) {
  if (n == 1) return base % MOD;
  if (n % 2) return base * (modPow(n-1, base)) % MOD;
  ll tmp = modPow(n/2, base) % MOD;
  return tmp * tmp % MOD;
}

ll invPow(int k) {
  return modPow(MOD - 2, k);
}

ll choose(int n, int k) {
  ll x = 1, y = 1;
  rep(i,k) {
    x *= n - i;
    x %= MOD;
    y *= i + 1;
    y %= MOD;
  }
  return x * invPow(y) % MOD;
}

int main() {
	ll n;
  int a, b;
	cin >> n >> a >> b;
  cout << (((modPow(n, 2) - 1 - choose(n, a) + MOD) % MOD) - choose(n, b) + MOD) % MOD << endl;
  return 0;
}

Measured memory_bytes: 256
#include <math.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <ostream>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;

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

typedef int _lcint;
#define REP(i, n) for (_lcint i = 0; i < n; i++)
#define FOR(i, a, b) for (_lcint i = (_lcint)(a); i < (_lcint)(b); i++)
#define FORREV(i, a, b) for (_lcint i = (_lcint)(b)-1; i >= (_lcint)(a); i--)
#define DEBUG(x) cout << #x << ": " << x << endl;
#define DEBUG_VEC(v)  \
  cout << #v << ": "; \
  REP(i, v.size()) cout << " " << v[i] << endl;

#define ALL(a) (a).begin(), (a).end()
#define CHMIN(a, b) a = min((a), (b))
#define CHMAX(a, b) a = max((a), (b))

// permutation
ll mPn(ll m, ll n) {
  ll a = 1;
  REP(i, n) { a *= m - i; }
  return a;
}

// excrametion
ll exc(ll m) {
  ll a = 1;
  FOR(i, 1, m) { a *= i + 1; }
  return a;
}

// combination
ll mCn(ll m, ll n) {
  ll a = 1, b = 1;
  REP(i, n) {
    a *= m - i;
    b *= n - i;
  }
  return a / b;
}

int main() {
  int A, B, C;
  cin >> A >> B >> C;

  if (A == B && B == C) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#define DEBUG 0
#include <bits/stdc++.h>
#define all(v) (v).begin(), (v).end()
#define pb push_back
#define REP(i,n) for(int i=0; i<(n); i++)
#define REP2(i,x,n) for(int i=x; i<(n); i++)
using namespace std;
using ll = long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template<class T>using numr=std::numeric_limits<T>;
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; }
const int INF = 1e9;
const ll LLINF = 1e16;
const int mod = 1000000007;
const int mod2 = 998244353;
void debug_impl() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_impl(Head head, Tail... tail) { std::cerr << " " << head; debug_impl(tail...); }
#if DEBUG
#define debug(...)\
    do {\
        std::cerr << std::boolalpha << "[" << #__VA_ARGS__ << "]:";\
        debug_impl(__VA_ARGS__);\
        std::cerr << std::noboolalpha;\
    } while (false)
#else
#define debug(...) {}
#endif

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr>
std::istream& operator>> (std::istream& is, Container& v)
    { for (auto & x : v) { is >> x; } return is; }

template < typename Container, typename Value = typename Container::value_type, std::enable_if_t<!std::is_same< Container, std::string >::value, std::nullptr_t> = nullptr >
std::ostream& operator<< (std::ostream& os, Container const& v) {
os << "{";
    for (auto it = v.begin(); it != v.end(); it++)
        {os << (it != v.begin() ? "," : "") << *it;}
    return os << "}";
}

int main() {
    std::cin.tie(nullptr);
    std::ios::sync_with_stdio(false);
    int n;
    cin >> n;
    vector<pii> v(n);
    for(auto &p : v) cin >> p.second >> p.first;
    sort(all(v));
    ll now = 0;
    REP(i,n){
        now += v[i].second;
        if(now > v[i].first){
            cout << "No" << endl;
            return 0;
        }
    } 
    cout << "Yes" << endl;
}

Measured memory_bytes: 4748
#include<iostream>
#include<climits>
#include<vector>
#include<list>
#include<functional>
#include<algorithm>
#include<string>
#include<cmath>
#include<complex>
#include<set>
#include<map>
#include<stack>
#include<queue>
#include<deque>
#include<tuple>
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) for(int i=0;i<(n);i++)
using namespace std;
typedef long long ll;
typedef pair<int, int> P;



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

	int n;
	cin >> n;
	vector<ll> a(n);
	REP(i, n) cin >> a[i];
	ll res = INT64_MAX;
	REP(i, 2) {
		ll tmp = 0;
		ll sum = 0;
		REP(j, n) {
			if (j % 2 == i) {
				if (sum + a[j] > 0) sum = sum + a[j];
				else {
					tmp += 1 - sum - a[j];
					sum = 1;
				}
			}
			else {
				if (sum + a[j] < 0) sum = sum + a[j];
				else {
					tmp += 1 + sum + a[j];
					sum = -1;
					
				}
			}	
		}
		res = min(res, tmp);
	}
	cout << res << "\n";

	return 0;
}

Measured memory_bytes: 1024
using System; 
using System.Text;
using System.Collections.Generic; 
using System.Linq; 
using E = System.Linq.Enumerable; 


class Program {
    //最短ステップ記録用
    static List<string> OpPattern;
    static void Main(string[] args) {
        
        var v = new int[4];
        //入力を受け取る
        var num1 = int.Parse(Console.ReadLine());
        v[num1] +=1;
        var num2 = int.Parse(Console.ReadLine());
        v[num2] +=1;
        
        for(int i = 1;i <= 3;i++){
            if(v[i] == 0){
                Console.WriteLine(i);
            }
        }
        
        
     }
     
     //全ての営業パターンを列挙
     static void MakePattern(string str){
         if(str.Length == 10){
             OpPattern.Add(str);
         }else{
             MakePattern(str+"0");
             MakePattern(str+"1");
         }
     }
}
     
     
                   


Measured memory_bytes: 11092
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
using namespace std;
struct str
{
	char ss[10];
	int ll;
	bool operator<(const str &s)const
	{
		for(int i=0;i<min(ll,s.ll);i++)
			if(ss[i]!=s.ss[i])
				return ss[i]<s.ss[i];
		return ll<s.ll;
	}
	bool operator==(const str &s)const
	{
		if(ll!=s.ll)
			return false;
		for(int i=0;i<ll;i++)
			if(ss[i]!=s.ss[i])
				return false;
		return true;
	}
}a[505050];
char s[5050];
int main()
{
	int k,l,cnt=0;
	scanf("%s",s);
	l=strlen(s);
	scanf("%d",&k);
	for(int i=0;i<l;i++)
		for(int j=0;j<k&&i+j<l;j++)
		{
			cnt++;
			a[cnt].ll=j+1;
			for(int kk=i;kk<=i+j;kk++)
				a[cnt].ss[kk-i]=s[kk];
		}
	sort(a+1,a+1+cnt);
	for(int i=1;i<=cnt;i++)
		if(i==1||(!(a[i]==a[i-1])))
		{
			k--;
			if(k==0)
			{
				for(int j=0;j<a[i].ll;j++)
					printf("%c",a[i].ss[j]);
				return 0;
			}
		}
}

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

int main(){
    int W, H, x, y, r;
    cin >> W >> H >> x >> y >> r;
    
    if(r <= x && x <= W - r && r <= y && y <= H-r){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}



Measured memory_bytes: 3124
#include<bits/stdc++.h>
#include<algorithm>
#include<map>
using namespace std;
string a[200010],b[200010];
int main()
{
	map<string,int>mp1;
	map<string,int>mp2;
	int n,i,j,k=0,mc=0;cin>>n;
	for(i=1;i<=n;i++)
	{
		cin>>a[i];
		mp1[a[i]]++;
		if(mp1[a[i]]>mc)mc=mp1[a[i]];
	}
	for(i=1;i<=n;i++)
	{
		if(!mp2[a[i]]&&mp1[a[i]]==mc)
		{
			b[++k]=a[i];
			//strcpy(b[++k],a[i]);
			mp2[a[i]]=1;
		}
	}
	/*for(i=1;i<=k-1;i++)
	for(j=i+1;j<=k;j++)
	{
		if(strcmp(b[i],b[j])>0)
		{
			char c[20];
			strcpy(c,b[i]);
			strcpy(b[i],b[j]);
			strcpy(b[j],c);
		}
	}*/
	sort(b+1,b+1+k);
	for(i=1;i<=k;i++)
	    cout<<b[i]<<endl;
}

Measured memory_bytes: 41728
#include<stdio.h>
#include<string.h>
int main(void){
  int n;
  scanf("%d",&n);
  char s[10000];
  scanf("%s",s);
  char abc[26] = {'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z'};
  int i=0,j;
  while(s[i]!='\0'){
    j=0;
    while(s[i]!=abc[j])j++;
    //printf("%d\n",j);
    printf("%c",abc[(j+n)%26]);
    i++;
  }
  return(0);
}

Measured memory_bytes: 128
#include <iostream>
#include <iomanip>
#include <vector>
#include <algorithm>
#include <numeric>
#include <functional>
#include <cmath>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <sstream>
#include <string>
#define _repargs(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _repargs(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)
#define all(x) (x).begin(),(x).end()
#define mod 1000000007
#define inf 2000000007
#define mp make_pair
#define pb push_back
typedef long long ll;
using namespace std;
template <typename T>
inline void output(T a, int p = 0) {
    if(p) cout << fixed << setprecision(p)  << a << "\n";
    else cout << a << "\n";
}
// end of template

int main() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    // source code
    ll N, K;
    cin >> N >> K;
    vector<pair<ll, ll>> A(N);
    rep(i, N){
        cin >> A[i].first >> A[i].second;
    }
    
    
    vector<ll> B(32);
    ll b = 0;
    rep(i, 32){
        b += 1LL << (32 - i - 1);
        B[i] = b;
    }
    vector<ll> C(32);
    rep(i, 32){
        C[i] = K & B[i];
    }
    
    
    ll ret = 0;
    rep(j, N){
        if((A[j].first | K) == K){
            ret += A[j].second;
        }
    }
//    output(ret);
    
    rep(i, 32){
        if(C[i] == 0) continue;
        ll sum = 0;
        rep(j, N){
            if((A[j].first | (C[i] - 1)) == C[i] - 1){
                sum += A[j].second;
            }
        }
        ret = max(ret, sum);
//        cout << i << ":" << sum << endl;
    }
    
    output(ret);
    
    return 0;
}

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

/*............................*/

#define uint            uint64_t
#define mx              200001
#define ll              long long int
#define ull             unsigned long long int
#define                 pii pair<int,int>
#define mp              make_pair
#define pb              push_back
#define inf             INT_MAX
#define pi              acos(-1)
#define eps             1e-8
#define gcd(a,b)        __gcd(a,b)
#define sc(a)           scanf("%d",&a)
#define scc(a,b)        scanf("%d %d",&a,&b)
#define sccdbl(a,b)     scanf("%lf %lf",&a,&b)
#define sccc(a,b,c)     scanf("%d %d %d",&a,&b,&c)
#define scccdbl(a,b,c)  scanf("%lf %lf %lf",&a,&b,&c)
#define scl(a)          scanf("%lld",&a)
#define sccl(a,b)       scanf("%lld %lld",&a,&b)
#define scccl(a,b,c)    scanf("%lld %lld %lld",&a,&b,&c)
using namespace std;
//int X[]={1,-1,0,0}; //co-ordinate move
//int Y[]={0,0,1,-1}; //co-ordinate move
//int X[]={1,1,2,2,-1,-1,-2,-2}; //Knights move
//int Y[]={2,-2,1,-1,2,-2,1,-1}; //Knights move
int main()
{
    int n;
    sc(n);
    int ara[n];
    for(int i=0;i<n;i++)
    {
        sc(ara[i]);
    }
    sort(ara,ara+sizeof(ara)/sizeof(ara[0]));
    int k=n/2;
    if(ara[k-1]==ara[k])
        cout<<0<<endl;
    else
    {
        int l=ara[k]-ara[k-1];
        cout<<l<<endl;
    }
    return 0;
}



Measured memory_bytes: 640
/* Author: Rennan Rocha
 * Time: $%Y%$-$%M%$-$%D%$ $%h%$:$%m%$:$%s%$
**/

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

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

#define ll long long
#define vi vector<int>
#define vll vector<ll>
#define pi pair<int,int>
#define pll pair<ll, ll>
#define vpi vector<pi>
#define vpll vector<pll>

using namespace std;
using namespace __gnu_pbds;

typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;
//*find_by_order(); order_of_key();

int n;
double p[3000];
double dp[3000][3000];

double solve(int i, int cara) {
    if(i == n) return cara > n/2;
    if(dp[i][cara] != -1) return dp[i][cara];
    return dp[i][cara] = p[i] * solve(i+1, cara + 1) + (1 - p[i]) * solve(i+1, cara);
}

int main() {
    ios_base::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    cin >> n;
    for(int i = 0; i < n; i++) {
        cin >> p[i];
        for(int j = 0; j <= n; j++) dp[i][j] = -1;
    }
    cout << solve(0,0) << "\n";
}


Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
int n,AC,WA,TLE,RE;
int main()
{
    cin>>n;
	string a[n+1];
	for(int i=1;i<=n;i++)
	{
		cin>>a[i];
		if(a[i]=="AC")AC++;
		if(a[i]=="WA")WA++;
		if(a[i]=="TLE")TLE++;
		if(a[i]=="RE")RE++;
	}
	cout<<"AC x "<<AC<<endl;
	cout<<"WA x "<<WA<<endl;
	cout<<"TLE x "<<TLE<<endl;
	cout<<"RE x "<<RE<<endl;
	return 0;
}


Measured memory_bytes: 6768
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef pair<P,P> PP;
const ll MOD = 1000000007;
const int IINF = INT_MAX;
const ll LLINF = LLONG_MAX;
const int MAX_N = int(1e5 + 5);
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define SORT(v) sort((v).begin(), (v).end())
#define ALL(v) (v).begin(), (v).end()

int main() {
    ll n, m, c, l[MAX_N], ans=0;
    cin >> n >> m >> c;
    REP(i,c) cin >> l[i+1];
    vector<P> v(n);
    REP(i,n) cin >> v[i].second >> v[i].first;
    SORT(v);
    reverse(ALL(v));
    REP(i,n){
        ll wi = v[i].first, ci = v[i].second;
        if(l[ci]>0){
            ans += wi;
            l[ci]--;
            m--;
        }
        if(m==0)break;
    }
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 4296
//繝・Φ繝励Ξ
#include <bits/stdc++.h>
#define int long long
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define FOR(i, a, b) for (int i = (a); i <= (b); ++i)
#define ALL(v) (v).begin(), (v).end()
#define PAIR pair<int, int>
#define ios() ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
using namespace std;
//constexpr int MOD = 10e9+7;
constexpr int INF = 1LL << 60;
template <class T>
inline bool chmin(T &a, T b)
{
  if (a > b)
  {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
inline bool chmax(T &a, T b)
{
  if (a < b)
  {
    a = b;
    return 1;
  }
  return 0;
}
//UP = 0;RIGHT = 1; DOWN = 2; LEFT =3;
const int dx[] = {0, 1, 0, -1, 1, -1, 1, -1}, dy[] = {1, 0, -1, 0, 1, -1, -1, 1};
int gcd(int a, int b)
{
  if (a < b)
    gcd(b, a);
  int r;
  while ((r = a % b))
  {
    a = b;
    b = r;
  }
  return b;
}

void eratos(bool * isPrime,int max){
  fill(isPrime,isPrime + max,true);
  isPrime[0] = false; 
  isPrime[1] = false; 

  for(int i=2; i<=max/i; ++i) 
      if(isPrime[i]) 
          for(int j=2; j<=max/i; ++j) 
              isPrime[i*j] = false;    
}
//

signed main()
{
  ios();
  string S ;
  cin >> S;
  S[3] = '8';
  cout << S << endl;

}

//N縺薙・荳ｭ縺九ｉ騾｣邯壹☆繧橘蛟九ｒ驕ｸ縺ｶ縺ｨ縺阪・驕ｸ縺ｳ譁ｹ縺ｯ髯舌ｌ繧峨ｌ繧九・ S T L

//驛ｨ蛻・・譛蟆丞､
//譖ｴ譁ｰ縺励↑縺・ｴ蜷遺・邏ｯ遨阪ｏ REP(i,N) ruiseki[i+1] += ruiseki[i];
//莠梧ｬ｡蜈・↓縺励◆縺・・縺・ｂ縺呎ｳ・
//荳邂・園繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Segment Tree(縺溘□縺怜叙蠕涌(logN))
//遽・峇繧剃ｽ募屓繧よ峩譁ｰ縺励◆縺・・Lazy Segment Tree


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#include <complex>
#include <string.h>
#include <numeric>
using namespace std;

//#define int long long
#define reps(i,s,n) for(int (i)=(s);(i)<(n);++(i))
#define rep(i,n) reps(i,0,n)
#define rept(i,n) rep(i,(n)+1)
#define repst(i,s,n) reps(i,s,(n)+1)
#define reprt(i,n,t) for(int (i)=(n);(i)>=(t);--(i))
#define repr(i,n) reprt(i,n,0)
#define each(i,v) for(auto &(i):(v))
#define eachr(i,v) for(auto &(i)=(v).rbegin();(i)!=(v).rend();(i)++)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define tmax(x,y,z) max(x,max(y,z))
#define tmin(x,y,z) min(x,min(y,z))
#define chmin(x,y) x=min(x,y)
#define chmax(x,y) x=max(x,y)
#define ln '\n'
#define bln(i,n) (((i)==(n)-1)?'\n':' ')
#define dbg(x) cout<<#x" = "<<(x)<<ln<<flush
#define dbga(x,n) {cout<<#x" : ";for(int (i)=0;i<(n);++i){cout<<((x)[i])<<(i==((n)-1)?'\n':' ')<<flush;}}
#define zero(a) memset(a,0,sizeof(a))
#define unq(a) sort(all(a)),a.erase(unique(all(a)),a.end())
#define endl "\n"

//typedef complex<double> P;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vst;
typedef vector<pii> vpii;
typedef vector<pll> vpll;
typedef vector<vector<int> > mat;

const ll inf = (ll)1e9+10;
const ll linf = (ll)1e18+10;
const ll mod = (ll)(1e9+7);
const int dx[] = {0, 1, 0, -1};
const int dy[] = {1, 0, -1, 0};
const int ddx[] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[] = {1, 1, 0, -1, -1, -1, 0, 1};
const double eps = 1e-10;

ll mop(ll a,ll b=mod-2,ll m=mod) {ll r=1;a%=m;for(;b;b>>=1){if(b&1)r=r*a%m;a=a*a%m;}return r;}
ll gcd(ll a,ll b) {return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b) {return a/gcd(a,b)*b;}
bool ool(int x,int y,int h,int w) {return((x<0)||(h<=x)||(y<0)||(w<=y));}
bool deq(double a,double b) {return abs(a-b)<eps;}

struct oreno_initializer {
    oreno_initializer() {
        cin.tie(0);
        ios::sync_with_stdio(0);
    }
} oreno_initializer;



int x, a;

signed main() {
    cin >> x >> a;
    cout << (x<a ? 0 : 10) << endl;
}


Measured memory_bytes: 256
import java.util.*;

class Main{
    static long gcd(long a, long b){
        return b == 0 ? a : gcd(b,a % b); 
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long A = sc.nextLong();
        long B = sc.nextLong();

        long g = gcd(A, B);
        int count = 1;
        for(long i = 2; i*i <= g; i++){
            if(g % i == 0){
                count++;
                while(g % i == 0){
                    g /= i;
                }
            } 
        }
        if(g > 1) count++;

        System.out.println(count);
    }
}

Measured memory_bytes: 22612
#include<iostream>

using namespace std;

int main(){
    int n,work;
    cin>>n;
    int* a=new int[n];
    for(int i=0;i<n;i++){
        cin>>a[i];
    }
    for(int i=0;i<n - 1;i++){
        cout<<a[i]<<" ";
    }
    cout<<a[n-1]<<"\n";
    for(int i=1;i<n;i++){
        work=a[i];
        int j=i-1;
        while(j>=0 && a[j]>work){
            a[j+1]=a[j];
            j--;
        }
        a[j+1]=work;
        for(int j=0;j<n-1;j++){
            cout<<a[j]<<" ";
        }
        cout<<a[n-1]<<"\n";
    }
}


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

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,D;
vint A[100];

void solve(){
    rep(i,N)A[i].clear();
    rep(i,N){
        int m;
        scanf("%lld",&m);
        A[i].resize(m);
        rep(j,m)scanf("%lld",&A[i][j]);
    }

    priority_queue<pint>que;
    rep(i,N)que.push(pint(accumulate(all(A[i]),0ll),i));

    while(que.size()){
        int c,idx;
        tie(c,idx)=que.top();
        que.pop();
        if(c==0){
            puts("Yes");
            return;
        }
        if(A[idx].back()<=D){
            c-=A[idx].back();
            A[idx].pop_back();
            que.push(pint(c,idx));
            continue;
        }
        while(que.top().fi>D+c-A[idx].back()){
            int cc,jdx;
            tie(cc,jdx)=que.top();
            que.pop();
            cc-=A[jdx].back();
            A[jdx].pop_back();
            if(c-cc>D){
                puts("No");
                return;
            }
            que.push(pint(cc,jdx));
        }
        c-=A[idx].back();
        A[idx].pop_back();
        que.push(pint(c,idx));
    }
}

signed main(){
    while(scanf("%lld%lld",&N,&D),N||D)solve();
    return 0;
}

Measured memory_bytes: 3236
import java.util.Scanner;

public class Main{
    public static void main(String[] args){
        int[] max = new int[3];
        for(int i=0;i<3;i++){
            max[i]=0;

        }
        Scanner scan = new Scanner(System.in);
        for(int i=0;i<10;i++){

            int val = scan.nextInt();
            int tmp,tmp2;
            if(max[0]<val){
                if(max[1]<val){
                    if(max[2]<val){
                        tmp = max[2];
                        tmp2 = max[1];
                        max[2]=val;
                        max[1] = tmp;
                        max[0] = tmp2;


                    }
                    else{
                        tmp = max[1];
                        max[1]=val;
			max[0] =tmp;

                    }
                }
                else{
                    max[0]=val;
		}
            }
	}

        for(int i=0;i<3;i++){
            System.out.println(max[2-i]);
	}
    }
}

Measured memory_bytes: 17168
#include <stdio.h>

int main(void)
{
	int W[15], L[15], r;
	int i, j, n, max;
	char t[15];
	
	while (1){
		
		scanf("%d", &n);
		
		if (n == 0){
			break;
		}
		
		for (i = 0; i < n; i++){
			scanf(" %c", &t[i]);
			W[i] = 0;
			L[i] = 0;
			
			for (j = 0; j < n - 1; j++){
				scanf ("%d", &r);
				
				if (r == 0){
					W[i]++;
				}
				else if (r == 1){
					L[i]++;
				}
			}
		}
		
		for (i = 0; i < n; i++){
			max = 0;
			for (j = 0; j < n; j++){
				
				if (W[max] < W[j]){
					max = j;
				}
				else if (W[max] == W[j]){
					if (L[max] > L[j]){
						max = j;
					}
				}
			}
			printf("%c\n", t[max]);
			W[max] = -1;
		}
	}
	return (0);
}
				
					
				

Measured memory_bytes: 596
#include<bits/stdc++.h>
using namespace std;
int main(){
  int n,a[200000]={};
  long long sum=0,tsum=0,x,ans=1000000000000000000;
  cin>>n;
  for(int i=0;i<n;i++){cin>>a[i];tsum+=a[i];}
  
  for(int i=0;i<n-1;i++){
    sum+=a[i];
    x=abs(sum-(tsum-sum));
    if(x<ans) ans=x;
  }
  cout<<ans<<endl;
  
  return 0;
}


Measured memory_bytes: 1024
#include<cstdio>
using namespace std;
double dp[305][305][305];
int n,a[4];
int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
	{
		int x;
		scanf("%d",&x);
		a[x]++;
	}
	for(int k=0;k<=n;k++)
	{
		for(int j=0;j<=n;j++)
		{
			for(int i=0;i<=n;i++)
			{
				if(i==0 && j==0 && k==0) continue;
				if(i!=0) dp[i][j][k]+=dp[i-1][j][k]*i/(i+j+k);
				if(j!=0) dp[i][j][k]+=dp[i+1][j-1][k]*j/(i+j+k);
				if(k!=0) dp[i][j][k]+=dp[i][j+1][k-1]*k/(i+j+k);
				dp[i][j][k]+=n/(double)(i+j+k);
			}
		}
	}
	printf("%.10lf\n",dp[a[1]][a[2]][a[3]]);
	return 0;
} 

Measured memory_bytes: 219264
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <utility>
#include <cmath>
#include <vector>
#include <queue>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
ll mod = 1000000007;

int main() {
    int h, w, n;
    cin >> h >> w >> n;
    int a[n], c[h][w];
    rep(i, n) {
        cin >> a[i];
    }

    int s = h*w;
    int y[s], x[s];
    rep(i, h) {
        rep(j, w) {
            y[i*w+j] = i;
        }
    }
    rep(i, s) {
        int m = i%(2*w);
        if(m < w) {
            x[i] = m;
        }
        else {
            x[i] = (2*w - 1) - m;
        }
    }

    int k = 0;
    rep(i, n) {
        for(int j = k; j < k + a[i]; j++) {
            c[y[j]][x[j]] = i+1;
        }
        k += a[i];
    }
    
    rep(i, h) {
        rep(j, w) {
            cout << c[i][j];
            if(j == w-1) {
                cout << "\n";
            }
            else {
                cout << " ";
            }
        }
    }

    return 0;
}

Measured memory_bytes: 384
N = int(input())
A = list(map(int,input().split()))
i = 0
count = 0
flag = False
while (True):
  for i in range(N):
    if A[i] % 2 != 0:
      flag = True
      break
      
  if flag == True:
    break
    
  for i in range(N):
    A[i] = A[i] // 2
  
  count += 1

print(count)

Measured memory_bytes: 3064
import java.util.*;
public class Main {

  public static void main(String[] args) { 
      Scanner sc = new Scanner(System.in);
      long a = sc.nextLong();
      long b = sc.nextLong();
      long c = sc.nextLong();
      if(c - a - b > 0 && 4 * a * b < (c - a - b) * (c - a - b))
        System.out.println("Yes");
      else
        System.out.println("No");
  }
}


Measured memory_bytes: 23380
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int mark[1000004];

int main()
{
    int n,i,rt,cnt,ans=0,j,k;
    cin>>n;
    int arr[n+3];
    for(i=0; i<n; i++)
    {
        cin>>arr[i];
        mark[arr[i]]++;
    }
    for(i=0; i<n; i++)
    {
        rt=sqrt(arr[i]);
        cnt=0;
        if(arr[i]==1)
        {
            if(mark[1]>1)cnt++;

        }
        else
        {
            for(j=1; j<=rt; j++)
            {
                if(arr[i]%j==0)
                {
                    if(mark[j]>=1)
                        cnt++;
                    else if(mark[arr[i]/j]>=1)
                    {
                        if(j==1 && mark[arr[i]/j]==1)
                        {
                            k=9;
                        }
                        else
                            cnt++;
                    }
                }
            }
        }
        if(cnt==0)
            ans++;
    }
    cout<<ans<<endl;


    return 0;
}



Measured memory_bytes: 8276
N = int(input())
H = list(map(int, input().split()))

H_bi = ["1" if H[i+1] <= H[i] else "0" for i in range(len(H)-1)]
H_bi.append("0")
H_bi = "".join(H_bi)
H_bi = H_bi.split("0")

max = 0
for h in H_bi:
    if max < len(h):
        max = len(h)

print(max)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
#include <string>
#include <algorithm>
#include <string.h>
#include <ctype.h>
#include <math.h>
#include <float.h>
#include <iomanip>
#include <iostream>
using namespace std;

int main(){

    string S;
    cin >> S;

    if(S[2]==S[3]&&S[4]==S[5]){
        cout << "Yes"<<endl;
    }else{
    cout << "No"<<endl;
    }

    return 0;
}


Measured memory_bytes: 256
#ifndef ___CLASS_MODINT
#define ___CLASS_MODINT

#include <cstdint>

template<std::uint32_t mod>
class modint {
private:
	std::uint32_t n;
public:
	modint() : n(0) {};
	modint(std::uint64_t n_) : n(n_ % mod) {};
	bool operator==(const modint& m) const { return n == m.n; }
	bool operator!=(const modint& m) const { return n != m.n; }
	std::uint32_t get() const { return n; }
	modint& operator+=(const modint& m) { n += m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator-=(const modint& m) { n += mod - m.n; n = (n < mod ? n : n - mod); return *this; }
	modint& operator*=(const modint& m) { n = std::uint64_t(n) * m.n % mod; return *this; }
	modint operator+(const modint& m) const { return modint(*this) += m; }
	modint operator-(const modint& m) const { return modint(*this) -= m; }
	modint operator*(const modint& m) const { return modint(*this) *= m; }
	modint binpow(std::uint64_t b) const {
		modint ans = 1, m = modint(*this);
		while (b) {
			if (b & 1) ans *= m;
			m *= m;
			b >>= 1;
		}
		return ans;
	}
	modint inv() { return (*this).binpow(mod - 2); }
};

#endif // ___CLASS_MODINT

#include <vector>
#include <iostream>
using namespace std;
using modulo = modint<1000000007>;
int main() {
	int N, K;
	cin >> N >> K;
	vector<int> A(N);
	for (int i = 0; i < N; ++i) {
		cin >> A[i];
	}
	vector<modulo> dp(K + 1);
	dp[0] = 1;
	for (int i = 0; i < N; ++i) {
		modulo sum = 0;
		for (int j = K + A[i]; j >= 0; --j) {
			if (j >= A[i]) {
				sum += dp[j - A[i]];
			}
			if (j <= K) {
				sum -= dp[j];
				dp[j] += sum;
			}
		}
	}
	cout << dp[K].get() << '\n';
	return 0;
}

Measured memory_bytes: 640