akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        String[] params = in.nextLine().split(" ");
        int a = Integer.parseInt(params[0]);
        int b = Integer.parseInt(params[1]);
        int c = Integer.parseInt(params[2]);

        if( a < b + c ){
            System.out.println( c - a + b );
        }
        else {
            System.out.println( 0 );
        }

    }

}

Measured memory_bytes: 22612
import java.io.PrintStream;
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {
    static final Scanner     sc = new Scanner(System.in);
    static final PrintStream so = System.out;

    static int K;
    static int[] v; 
    static int[] revV; 
    static long[] left;
    static long[] right;
    
    public static void main(String[] args) {
        int n = ni();
        K = ni();
        v = new int[n+2];
        revV = new int[n+2];
        left = new long[n+2];
        right = new long[n+2];
        
        for (int i = 1; i <= n; i++) {
            v[i] = ni();
            revV[n+1-i] = v[i];
            left[i] = left[i-1] + v[i];
        }
        
        for (int i = 1; i <= n; i++) {
            right[i] = right[i-1] + v[n+1-i];
        }
        
        long ans = 0;
        long maxI = Math.min(K, n);
        for (int i = 1; i <= maxI; i++) {
            ans = Math.max(ans, calcMax(left, right, i));
        }
        
        so.println(ans);
    }
    
    private static long calcMax(long[] left, long[] right, int k /* 0 to K */) {
        
        long max = 0;
        for (int i = 0; i <= k; i++) {
            long sumI = left[i] + right[k-i];
            long minus = calcMinus(i, k);
            max = Math.max(max, sumI - (minus));
        }
        
        return max;
    }

    private static long calcMinus(int i, int k) {
        List<Integer> minus = new ArrayList<>();
        for (int j = 1; j <= i; j++)
            if (v[j] < 0)
                minus.add(v[j]);
        
        for (int j = 1;  j <= k-i; j++)
            if (revV[j] < 0)
                minus.add(revV[j]);
        
        minus.sort((i1, i2) -> i1 - i2);
        long ans = 0;
        for (int j = 0; j < K - k && j < minus.size(); j++) {
            ans += minus.get(j);
        }
        return ans;
    }

    private static int ni() {
        return sc.nextInt();
    }

    private static long nl() {
        return sc.nextLong();
    }

    private static String ns() {
        return sc.next();
    }

    private static char[] nsToChars() {
        return sc.next().toCharArray();
    }

    private static long[] nlongs(int n) {
        return nlongs(n, 0);
    }

    private static long[] nlongs(int n, int padding) {
        long[] a = new long[padding + n];
        for (int i = 0; i < n; i++)
            a[padding + i] = ni();
        return a;
    }
}


Measured memory_bytes: 28372
import sys
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
N,M = LI()
a = set([I() for _ in range(M)])
if N==1:
    print(1)
    exit()
dp = [0]*(N+1) #1_indexed
dp[1] = 0 if 1 in a else 1
dp[2] = 0 if 2 in a else (1+dp[1])
for i in range(3,N+1):
    if i in a:
        dp[i] = 0
        continue
    dp[i] = (dp[i-2]+dp[i-1])%1000000007
print(dp[-1])


Measured memory_bytes: 13224
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <cfloat>
#include <stack>
#include <queue>
#include <vector>
#include <string>
#include <iostream>
#include <set>
#include <map>
#include <time.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


int N;
int check_point[101];
double min_time[101][101];
double B,R,V,E,F;


double calcTime(int x){
	if(x >= R){

		return 1.0/(V-E*((double)x-R));
	}else{

		return 1.0/(V-F*(R-(double)x));
	}
}

void func(){

	check_point[0] = 0.0;
	for(int i = 1; i <= N; i++)scanf("%d",&check_point[i]);
	scanf("%lf",&B);
	scanf("%lf %lf %lf %lf",&R,&V,&E,&F);

	for(int i = 0; i <= N; i++){
		for(int k = 0; k <= i; k++)min_time[i][k] = DBL_MAX;
	}

	min_time[0][0] = 0;

	int x;
	double add_time;

	for(int point = 1; point <= N; point++){
		for(int changed_loc = 0; changed_loc <= point-1; changed_loc++){
			add_time = 0.0;
			for(int loc = check_point[point-1]; loc <= check_point[point]-1; loc++){
				x = loc - check_point[changed_loc];
				add_time += calcTime(x);
			}

			min_time[point][changed_loc] = min(min_time[point][changed_loc],min_time[point-1][changed_loc]+add_time);

			min_time[point][point] = min(min_time[point][point],min_time[point-1][changed_loc]+add_time+B);
		}
	}

	double ans = DBL_MAX;
	for(int i = 0; i < N; i++)ans = min(ans,min_time[N][i]);

	printf("%.10lf\n",ans);
}


int main(){

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}

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

int N, M;
int WA[105000];
bool AC[105000];

void solve() {
    cin >> N >> M;
    int WAnum = 0;
    int ACnum = 0;
    for(int i = 1; i <= N; i++) {
        WA[i] = 0;
        AC[i] = false;
    }
    while(M--) {
        int p;
        string S;
        cin >> p >> S;
        if(AC[p]) continue;
        if(S == "AC") {
            AC[p] = true;
            ACnum++;
            WAnum += WA[p];
        } else if(S == "WA") {
            WA[p]++;
        }
    }
    cout << ACnum << " " << WAnum << endl;
    return;
}

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


Measured memory_bytes: 768
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <string>
#include <algorithm>
#include <iostream>
#include <string>
#include <map>
#include <set>
#include <functional>
#include <iostream>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

int n;
ll a[100001];
vector<int> G[100001];
bool flag;
bool used[100001];

ll dfs(int v){
	used[v]=true;
	if(G[v].size()==1)return a[v];
	ll pass=0;
	ll maxi=0;
	for(int i=0;i<G[v].size();i++){
		if(!used[G[v][i]]){
			ll get=dfs(G[v][i]);
			pass+=get;
			maxi=max(get,maxi);
		}
	}
	ll va=pass-maxi;
	va=min(va,pass/2LL);
	ll vb=pass-a[v];
	if(pass<a[v])flag=false;
	if(vb>va)flag=false;
	pass-=2LL*vb;
	return pass;
}

int main(void){
	scanf("%d",&n);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	if(n==2){
		printf("%s\n",a[0]==a[1]?"YES":"NO");
		return 0;
	}
	for(int i=0;i<n-1;i++){
		int f,t;
		scanf("%d%d",&f,&t);
		f--;
		t--;
		G[f].push_back(t);
		G[t].push_back(f);
	}
	flag=true;
	memset(used,false,sizeof(used));
	int s=0;
	while(G[s].size()==1)s++;
	ll d=dfs(s);
	printf("%s\n",((d==0LL) && flag)?"YES":"NO");
	return 0;
}


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

int gcd(int a, int b){
    if(b == 0) return a;

    return gcd(b, a%b);
}

int main(void){
    int N; cin >> N;
    ll A[N];
    rep(i,N) cin >> A[i];
    ll L[N],R[N];
    L[0] = A[0];
    R[N-1] = A[N-1];
    for (int i = 1; i < N; i++)
    {
        L[i] = gcd(L[i-1],A[i]);
        R[N-1-i] = gcd(R[N-i],A[N-1-i]);
    }
    ll ANS[N];
    ANS[0] = R[1];
    ANS[N-1] = L[N-2];
    for (int i = 1; i < N-1; i++)
    {
        ANS[i] = gcd(L[i-1],R[i+1]);
    }
    ll ans = 0;
    rep(i,N) ans = max(ans,ANS[i]);
    cout << ans << endl;
}

Measured memory_bytes: 3328
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp> 
//using namespace boost::multiprecision; 
using namespace std;
#define ll long long int
#define ld long long double
#define vi vector<int>
#define vl vector<ll>
#define pi pair<int, int>
#define pl pair<ll, ll>
#define pb push_back
#define pf push_front
#define pob pop_back
#define pof pop_front
#define nl '\n'
#define mp make_pair
#define debug1(x) cout <<#x<<" "<<x<<'\n';
#define debug2(x,y) cout <<#x<<" "<<x <<" "<<#y<<" "<<y <<'\n';
#define debug3(x,y,z) cout<<#x<<" "<<x<<" "<<#y<<" "<<y<<" "<<#z<<" "<<z<<'\n';
#define fi first
#define se second
#define boost ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define inf 1e18
const int mod = (int)1e9+7;
pair<ll,ll>s4[4]={{-1,0},{1,0},{0,-1},{0,1}};
pair<ll,ll>s8[8]={{-1,-1},{-1,0},{-1,1},{0,-1},{0,1},{1,1},{1,0},{1,-1}};

void solve() {
    int a,b,c,d;
    cin >> a>> b >>c >> d;
    while(a>0 && c>0) {
        c = c-b;
        if(c<=0) {
            break;
        }
        a=a-d;
        if(a<=0) {
            break;
        }
    }
    if(c<=0) {
        cout << "Yes"<<nl;
    }
    else{
        cout << "No"<<nl;
    }
}

signed main() {
    boost;
    solve();
}

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

int main() {
  int N;
  scanf("%d", &N);

  int ans = 0;
  int max_p = 0;
  for (int i = 0; i < N; i++) {
    int p = 0;
    scanf("%d", &p);
    ans += p;
    max_p = max(max_p, p);
  }

  printf("%d", ans - (max_p / 2));
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> ii;
typedef vector<ll> vi;
typedef long double ld;

#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define INF ll(1e18)
#define MOD (ll)1e9+7
#define print(a); for(auto x:a)cout<<x<<" "; cout<<"\n";
#define mset(a); memset(a,0,sizeof(a));

int main(){
	ios_base::sync_with_stdio(0);cin.tie(0);
    ll x;cin>>x;
    for(ll i=-118;i<=119;i++){
        for(ll j=-119;j<=118;j++){
            if(pow(i,5)-pow(j,5)==x){
                cout<<i<<" "<<j<<"\n";return 0;
            }
        }
    }

}



Measured memory_bytes: 4040
#include<map>
#include<cmath>
#include<stack>
#include<queue>
#include<cstdio>
#include<vector>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long ll;
template<class AC>void r(AC &x){
    x=0;
    int f=0;
    char ch=getchar();
    while(ch<'0'||ch>'9'){
        f|=(ch=='-');
        ch=getchar();
    }
    while(ch>='0'&&ch<='9'){
        x=(x<<1)+(x<<3)+(ch^48);
        ch=getchar();
    }
    x=f?-x:x;
    return;
}
map<char,int>m;
int ans;
string s;
int main(){
	cin>>s;
    for(int i=0;s[i];i++)m[s[i]]=1;
    for(char i='a';i<='z';i++)if(m[i]==0)break;else ans++;
    if(ans==26)puts("None");
    else cout<<char('a'+ans)<<endl; 
    return 0;
}

Measured memory_bytes: 512
import sys
input = sys.stdin.buffer.readline

#sys.setrecursionlimit(10**9)
#from functools import lru_cache

def RD(): return input().rstrip().decode()
def II(): return int(input())
def FI(): return int(input())
def MI(): return map(int,input().split())
def MF(): return map(float,input().split())
def LI(): return list(map(int,input().split()))
def LF(): return list(map(float,input().split()))
def TI(): return tuple(map(int,input().split()))
# rstrip().decode()


def main():
	n=II()
	A=LI()

	X=[-10**10]*(n+1)
	Y=[-10**10]*(n+1)
	X[0]=0
	Y[1]=A[0]
	X[1]=0

	for i in range(2,n+1):
		if i%2==0:
			X[i]=max(Y[i-1],X[i-2]+A[i-1])
		else:
			X[i]=max(X[i-1],X[i-2]+A[i-1])
			Y[i]=Y[i-2]+A[i-1]
	print(X[n])




















if __name__ == "__main__":
	main()


Measured memory_bytes: 35512
#include <bits/stdc++.h>
using namespace std;
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
template<typename x>
using ordered_set = tree<x,null_type,less<x>,rb_tree_tag,tree_order_statistics_node_update>;
#define sorta(a,n) sort(a,a+n)
#define sortad(a,n) sort(a,a+n,greater<__typeof(a[0])>())
#define all(x) (x).begin(),(x).end()
#define ms0(x) memset((x),0,sizeof((x)))
#define ms1(x) memset((x),-1,sizeof((x)))
typedef pair<int,int> pi;
#define inarr(arr,n) for(int i=0;i<n;i++)cin>>arr[i];
#define prinarr(arr) {for(int x:arr)cout<<x<<" ";} cout<<"\n";
#define cout1(a) cout<<a<<"\n";
#define cout2(a,b) cout<<a<<" "<<b<<"\n";
#define cout3(a,b,c) cout<<a<<" "<<b<<" "<<c<<"\n";
#define setpre(n) cout<<fixed<<setprecision(8)<<n<<"\n";
#define filldp(arr,n,m,k) for(int i=0;i<n;i++){for(int j=0;j<m;j++) arr[i][j]=k;}

#define mod 1000000007
#define mod1 998244353


vector<vector<int>> adj;
vector<int> dis;
vector<int> parent;
vector<bool> visited;

void newgr(int n){
    n+=10;
    adj=vector<vector<int>>(n);
    dis=vector<int>(n,0);
    //parent=vector<int>(n,-1);
    visited=vector<bool>(n,false);
}

void dfs(int s){
    visited[s]=true;
    for(auto u:adj[s]){
        if(!visited[u]){
            //parent[u]=s;
            dis[u]=dis[s]+1;
            dfs(u);
        }
    }
}

void bfs(int s){
    queue<int> q;
    q.push(s);
    visited[s]=true;
    dis[s]=0;
    while(!q.empty()){
        auto u=q.front();
        q.pop();
        for(auto x:adj[u]){
            if(!visited[x]){
                //parent[x]=u;
                visited[x]=true;
                dis[x]=dis[u]+1;
                q.push(x);
            }
        }
    }
}

long long power(long long x,long long y){  
    long long ans=1;
    x%=mod;
    while(y>0){
        if(y&1) ans=(ans*x)%mod;
        y>>=1;
        x=(x*x)%mod;
    }
    return ans;
}

long long modinv(long long b){ 
    return power(b,mod-2);
}



int main(){
    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
    int n,k;
    cin>>n>>k;
    int arr[n];
    inarr(arr,n);
    int dp[k+1]={};
    for(int i=0;i<=k;i++){
        for(int x:arr){
            if((i-x)>=0 and dp[i-x]!=1){
                dp[i]=1;
            }
        }
    }
    if(dp[k]){
        cout1("First")
    }
    else{
        cout1("Second")
    }
    return 0;
}

Measured memory_bytes: 3956
import Control.Applicative
import Control.Monad.State
import Data.Array.IO

main = do
  n <- getLine
  list <- map read.words<$>getLine :: IO [Int]
  let (res,swaps) = bubbleSort list
  putStrLn.unwords.map show $ res
  print swaps

bubbleSort :: Ord a => [a] -> ([a], Int)
bubbleSort xs = runState (bubbles xs) 0

bubbles [] = return []
bubbles xs = do
        (y:ys) <- bswap xs
        ys' <- bubbles ys
        return (y:ys')

bswap :: (Ord a) => [a] -> State Int [a]
bswap [x] = return [x]
bswap (x:xs) = do
        (y:ys) <- bswap xs
        if x > y
            then do
                modify (+1)
                return $ y:x:ys
            else return $ x:y:ys


Measured memory_bytes: 4948
#include<bits/stdc++.h>
using namespace std;
#define ff first
#define ss second
#define pll pair<ll,ll>
#define sll set<ll>
#define msll multiset<ll>
#define mll map<ll,ll>
#define vll vector<ll>
#define vpl vector<pll>
#define gll greater<ll>
#define spl set<pll>
#define mspl multiset<pll>
#define lb lower_bound
#define ub upper_bound
#define prq priority_queue
#define mp make_pair
#define pb push_back
#define mem(x,y) memset(x, y, sizeof x)
#define endl "\n"
#define sz(x) (ll)x.size()
#define sqr(x) x*x
#define rapido ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
typedef long long ll;
typedef long double ld;
ll mx=INT_MIN;
ll mn=INT_MAX;
ll MOD=1e9+7;
ll INF = 1e18;
const int maxs=2e5+10;
const int lg=22;

void code_idhr_h(){
    ll A; cin>>A; 
    ld B; cin>>B;
    ll ans=A*B;
    cout<<ans;
}

int main(){
    rapido;
    ll T=1; //cin>>T;
    while(T--){
        code_idhr_h();
    }
    return 0;
}

Measured memory_bytes: 3744
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
using namespace std;
//#define rep(i,n) for(int i=0;i<(int)(n);i++)
//using ll = long long;
//typedef long long ll;

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int i=1;
    int taka=0,ao=0;
    while(a>0&&c>0){
        if(i%2==0) {
            a=a-d;
            taka=0;
            ao=1;
        }
        else {
            c=c-b;
            taka=1;
            ao=0;
        }
        i++;
        //cout << "i:" << i << endl;
    }
    if(taka==1) cout << "Yes" << endl;
    else cout << "No" << endl;
}


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

int main () {
    long long a, b, k;
    cin >> a >> b >> k;

    if (a >= k)
    {
        cout << a - k << " " << b << endl;
    }

    else if (a + b >= k)
    {
        cout << 0 << " " << b - (k - a) << endl;
    }

    else if (a + b < k)
    {
        cout << 0 << " " << 0 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
# coding: utf-8
N, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
for i in range(N - 1): # 貪欲法で解く
    if a[i] + a[i + 1] > x and a[i + 1] >= 1: # 左の組から順に、組の右側から食べていく
        ans += min(a[i] + a[i + 1] - x, a[i + 1])
        a[i + 1] -= min(a[i] + a[i + 1] - x, a[i + 1])
    if a[i] + a[i + 1] > x: # それでも足りないなら組の左側も食べる
        ans += a[i] + a[i + 1] - x
        a[i] -= a[i] + a[i + 1] - x
print(ans)

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

int main(){
        int a , b , d , r ;
		double  f ;
		cin >> a >> b ;
		
		d = a/b ;
        r = a%b ;
        f = 1.0*a/b ;		
		printf("%d %d %.5f", d, r, f );
		 
		 return 0 ;
		 
		 
	 }

Measured memory_bytes: 1176
if isfile("mystdin.txt");mystdin=open("mystdin.txt","r");redirect_stdin(mystdin);end
pI(x)=parse(Int,x)
pM(x::Array{SubString{String},1})=map(pI,x)
function main()
  a,b=pM(split(readline()))
  print(*(a,b))
end
main()
if isdefined(Base, :mystdin);close(mystdin);end

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

int main(){
    double num;

    while(cin >> num, num >= 0){
        long long tmp = (long long)num;

        string ans = "";
        stack<char> st;
        for(int i = 0;i < 8;i++){
            st.push((tmp % 2) + '0');
            tmp /= 2;
        }

        if(tmp != 0){
            cout << "NA" << endl;
            continue;
        }

        while(!st.empty()){
            ans.push_back(st.top());
            st.pop();
        }

        double t2 = num - (long long)num;

        ans.push_back('.');

        for(int i = 0;i < 4;i++){
            t2 *= 2;
            if(t2 >= 1){
                ans.push_back('1');
                t2 -= 1;
            }else{
                ans.push_back('0');
            }
        }

        if(t2 > 0){
            cout << "NA" << endl;
            continue;
        }

        cout << ans << endl;

    }

    return 0;
}





Measured memory_bytes: 3296
S = input()
T = input()
T_high = len(T) - 1

ans = []

for i in range(T_high, len(S)):
    flg = False
    for j in range(T_high + 1):
        c = S[i + j - T_high]
        if c != '?' and c != T[j]:
            flg = True
            break
    if not flg:
        buf = S.replace("?", "a")
        ans.append(buf[:(i - T_high)] + T + buf[(i + 1):])

if len(ans) == 0:
    print("UNRESTORABLE")
else:
    print(sorted(ans)[0])

Measured memory_bytes: 3064
def main():
    # input
    n = int(input())
    s = input()

    ans = 0
    for i in range(0, 1000):
        num = str(i).rjust(3, '0')
        index = 0
        for i in s:
            if index == 3:
                ans += 1
                break
            elif num[index]==i:
                index += 1
        else:
            if index == 3:
                ans += 1

    print(ans)

    # calc


if __name__ == '__main__':
    main()


Measured memory_bytes: 40684
fn main() {
    let n: i32 = read();
    println!("{}", (1000 - n % 1000) % 1000);
}

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


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

long n, ans = 0;
void dfs(long s, int n3, int n5, int n7)
{
  if(s <= n){
    dfs(s * 10 + 3, 1, n5, n7);
    dfs(s * 10 + 5, n3, 1, n7);
    dfs(s * 10 + 7, n3, n5, 1);
    ans += (n3 & n5 & n7);
  }
}
int main(void)
{
  cin >> n;
  dfs(0, 0, 0, 0);
  cout << ans << endl;
  return 0;
}

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

using namespace std;

#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define REV(i,n) for(ll (i) = (n) - 1;(i) >= 0;--i)
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {REP(WW,n)cerr << v[WW] << ' ';cerr << endl << endl;}
#define SHOW2d(v,WW,HH) {REP(W_,WW){REP(H_,HH)cerr << v[W_][H_] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

typedef long long ll;
typedef pair<ll,ll> P;

ll n;
ll mp[5555];
vector<vector<int>> v(5555);
ll dp1[5555][5555];
ll dp2[5555][5555];
ll tmp1[5555];
ll tmp2[5555];
ll subNum[5555];

void dfs(int node, int pre){
	subNum[node] = 1;
	
	if(mp[node] > 0)dp1[node][0] = mp[node];
	dp2[node][0] = mp[node];
	
	REP(i,v[node].size())if(v[node][i] != pre){
		int now = v[node][i];
		dfs(now, node);
		
		REP(j,subNum[node] + subNum[now] + 1){
			tmp1[j] = LLINF;
			tmp2[j] = LLINF;
		}
		REP(j,subNum[node]){
			REP(k,subNum[now]){
				if(dp1[now][k] != LLINF || dp2[now][k] < 0){
					tmp1[j+k+1] = min(tmp1[j+k+1],dp1[node][j]);
					tmp2[j+k+1] = min(tmp2[j+k+1],dp2[node][j]);
				}
				
				tmp1[j+k] = min(tmp1[j+k],dp1[node][j] + dp1[now][k]);
				tmp2[j+k] = min(tmp2[j+k],dp1[node][j] + dp2[now][k]);
				tmp2[j+k] = min(tmp2[j+k],dp2[node][j] + dp1[now][k]);
				tmp2[j+k] = min(tmp2[j+k],dp2[node][j] + dp2[now][k]);
			}
		}
		
		subNum[node] += subNum[now];
		REP(j,subNum[node]){
			dp1[node][j] = tmp1[j];
			dp2[node][j] = tmp2[j];
		}
	}
}

int main(){
	
	REP(i,5555){
		REP(j,5555){
			dp1[i][j] = LLINF;
			dp2[i][j] = LLINF;
		}
	}	
	
	cin >> n;
	REP(i,n)cin >> mp[i];
	REP(i,n-1){
		int a, b;cin >> a >> b;
		a--;b--;
		v[a].PB(b);
		v[b].PB(a);
	}
	
	dfs(0, -1);
	
	for(int i = 0;i <= n;i++){
		if(dp1[0][i] != LLINF){
			cout << i << endl;
			return 0;
		}
		if(dp2[0][i] < 0){
			cout << i << endl;
			return 0;
		}
	}

	return 0;
}


Measured memory_bytes: 483328
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
typedef long long ll;
#define all(x) (x).begin(),(x).end()
int INF = 1000000000;

int main() {
  int H, W; cin >> H >> W;
  vector<vector<char>> b(H+2, vector<char>(W+2));
  vector<vector<int>> ans(H, vector<int>(W, 0));
  rep(i, H+2) {
    rep(j, W+2) {
      if (i == 0 || i == H+1 || j == 0 || j == W+1) {
        b[i][j] = '.';
      }
      else {
        cin >> b[i][j];
      }
    }
  }
  rep2(i, 1, H+1) {
    rep2(j, 1, W+1) {
      int cnt = 0;
      if (b[i][j] == '.') {
        ans[i-1][j-1] += 1;
      }
      else {
        if (b[i-1][j] == '#') {
          cnt++;
        }
        if (b[i+1][j] == '#') {
          cnt++;
        }
        if (b[i][j-1] == '#') {
          cnt++;
        }
        if (b[i][j+1] == '#') {
          cnt++;
        }
        ans[i-1][j-1] += cnt;
      }
    }
  }
  bool flag = true;
  rep(i, H) {
    rep(j, W) {
      if (ans[i][j] == 0) {
        flag = false;
        break;
      }
    }
  }
  if (flag) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}

Measured memory_bytes: 256
/*
Task:
Author: John_05
State: Unknown
Lang: C++
Solution:
*/
#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
const int INF=2e9+10;
#define fi first
#define se second
#define pb push_back
#define mp make_pair

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

char a;

int main() {
	a=getchar();
	if(a=='A') printf("T\n");
	if(a=='T') printf("A\n");
	if(a=='C') printf("G\n");
	if(a=='G') printf("C\n");
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<ll, ll>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
ll power(ll num, ll g, ll mod) {
	if (g == 0)return 1;
	if (g % 2 == 1)return (num * power((num * num) % mod, g / 2, mod)) % mod;
	return power( (num * num) % mod, g / 2, mod);
}

const int N = 200005;
bool visited[N];

int main(){
	ll n, k;
	cin >> n >> k;
	ll a[n+5];
	FOR0(i,n){
		cin >> a[i];
	}
	memset(visited,false,sizeof(visited));
	ll cnt = 0, val =1;
	while(!visited[val]){
		visited[val] = true;
		val = a[val-1];
	}
	ll cycbegin = val;
	val = 1;
	//cout << cycbegin << endl;
	while(val!=cycbegin){
		val = a[val-1];
		k--;
		if(k == 0){
			cout << val << endl;
			return 0;
		}
	}
	val = cycbegin;
	while(val!=cycbegin || cnt==0){
		val = a[val-1];
		cnt++;
	}
	//cout << val sp cnt sp cycbegin<< endl;
	k %= cnt;
	FOR0(i,k){
		val = a[val-1];
	}
	cout << val << endl;

}



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

class Cmondai
{
    static void Main()
    {
        var line = Console.ReadLine().ToCharArray().Select(x=>Int32.Parse(x.ToString())).ToArray();
        var A = line[0];
        var B = line[1];
        var C = line[2];
        var D = line[3];
        var count = Math.Pow(2, 4);
        for(int i = 0; i < count; ++i)
        {
            var isPlus = new bool[4];
            for (int j = 0; j < 4; ++j) isPlus[j] = ((1 & i >> j) == 1);
            var a = isPlus[0] ? A : A * (-1);
            var b = isPlus[1] ? B : B * (-1);
            var c = isPlus[2] ? C : C * (-1);
            var d = isPlus[3] ? D : D * (-1);
            if (a + b + c + d == 7)
            {
                var strA = A==0?"0":isPlus[0] ? $"{A}" : $"-{A}";
                var strB = isPlus[1] ? $"+{B}" : $"-{B}";
                var strC = isPlus[2] ? $"+{C}" : $"-{C}";
                var strD = isPlus[3] ? $"+{D}" : $"-{D}";
                Console.WriteLine($"{strA}{strB}{strC}{strD}=7");
                return;
            }
        }
    }
}



Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,n) for(int i=0;i<n;i++)
#define why(n,x) int n;while(cin >>n,n!=x)
#define iFOR(i,x,n)for(int i=x;i<n;i++)
#define unless(flg) if ( !(flg) )
#define read cin<<
#define echo cout<<
#define fin <<'\n'
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
#define SWAP(a,b) ((a != b) && (a += b,b = a - b,a -= b))
#define cinf(n,x) for(int UNCH=0;UNCH<(n);UNCH++) cin >> x[UNCH];
#define fcin(n,x) for(int UNCH=1;UNCH<=(n);UNCH++) cin>> x[UNCH];
#define memmin(x) memset((x),-1,sizeof((x)))
#define memzer(x) memset((x), 0,sizeof((x)))
#define meminf(x) memset((x),0x3f,sizeof((x)))

typedef long long ll;
typedef pair < int , int >  pii;
typedef vector < int > vit;
typedef map < string , int > mstit;
typedef vector < pii > vpi ;
typedef greater < pii > gpi;
typedef priority_queue < pii , vpi , gpi > dijk ;
static const signed int INF = 0x3f3f3f3f;
static const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static const signed int SMOD = 1000000007;
static const signed int NMOD = 1000000009;
static const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static const signed int dy[]={0,-1,0,1,-1,1,-1,1};

bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>T abs(T &x){return x<0 ? -x : x;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
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;}
//#define int long long

inline void solve(){

    ll n, m;
    cin >> n >> m;
    ll ans = 0;
    if(n==1 && m== 1){
        ans = 1;
    }else if(n==1){
        ans = m-2;
    }else if(m==1){
        ans = n-2;
    }else{
        n-=2,m-=2;
        ans = n*m;
    }

    cout << ans fin;
}

struct xyz{ xyz(){ cin.tie(0), ios::sync_with_stdio(false); cout <<fixed<<setprecision(12);};}xyzzy;signed main(){solve();return 0;}



Measured memory_bytes: 256
//              +-- -- --++-- +-In the name of ALLAH-+ --++-- -- --+              \\

#include <bits/stdc++.h>

#define F first
#define S second
#define _sz(x) (int)x.size()
#define pb push_back

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

const int N = 2e3 + 20 , mod = 1e9 + 7 ;
int n , m , a[N] , b[N] , d1[N] , d2[N] , ans = 1 ;

inline void add (int &a , int b) {
	a += b ;
	if (a >= mod) a -= mod ;
}

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

	cin >> n >> m ;
	for (int i = 0 ; i < n ; i ++) cin >> a[i] ;
	for (int i = 0 ; i < m ; i ++) cin >> b[i] ;


	for (int i = 0 ; i < n ; i ++) {
		int sum = 1 ;

		for (int j = 0 ; j < m ; j ++) {
			int c = d2[j] ;
			if (a[i] == b[j]) add(d1[i] , sum) , add(d2[j] , sum) ;
			add(sum , c) ;
		}
	}

	for (int i = 0 ; i < n ; i ++) add(ans , d1[i]) ;

	cout << ans << '\n' ;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int N, M, i, j, cnt, ans = 0;

	cin >> N;
	vector <string> s(N);
	for (i = 0; i < N; i++)
		cin >> s[i];

	cin >> M;
	vector <string> t(M);
	for (i = 0; i < M; i++)
		cin >> t[i];

	for (i = 0; i < N; i++) {

		cnt = 1;
		for (j = i+1; j < N; j++) {
			if (s[i] == s[j])
				cnt++;
		}

		for (j = 0; j < M; j++) {
			if (s[i] == t[j])
				cnt--;
		}
		ans = max(ans,cnt);
	}

	if (ans < 0)
		cout << 0 << endl;
	else
		cout << ans << endl;

	return 0;
}

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

#define rep(i,a,b)                for(ll i=a;i<b;i++)
#define re(i,b)                for(ll i=0;i<b;i++)
#define repr(i,n)                for(ll i=n-1;i>=0;i--)
#define ll long long
#define ld long double
#define llu long long unsigned
#define pll std::pair<ll, ll> 
#define ppll std::pair<ll, pll>
#define vll std::vector<ll> 
#define vpll std::vector<pll> 
#define vppll std::vector<ppll> 
#define mll std::unordered_map<ll, ll> 
#define mpll std::unordered_map<pll, ll>
#define mppll std::unordered_map<ppll, ll>
#define sll std::set<ll>
#define ff first
#define ss second
#define msll std::multiset<ll>
#define all(c) c.begin(), c.end()
#define allr(c) c.rbegin(), c.rend()
#define srt(x) sort(all(x))
#define rsrt(x) sort(allr(x))
#define eb emplace_back
#define pb push_back
#define s(yy) ll yy;cin>>yy
#define mod 1000000007
#define maxlong 1e18+5


/*#################################################### 
#                                                    #
#                     @author                        #
#                  Parth Lathiya                     #
#      https://www.cse.iitb.ac.in/~parthiitb/        #
#                                                    #
####################################################*/


int main()
{

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

	#ifdef PARTH_LATHIYA_HOME

		freopen("A_in.txt","r",stdin);
	
		ll ttt,bkkk;
		cin>>ttt;
		bkkk=ttt;
		while(ttt--) {
			cout<<"Testcase - "<<bkkk-ttt<<"\n";
	#endif

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

	ll n,a,b,c,d;
	cin>>a>>b>>c>>d;
	std::vector<pair<ld,ll>> v; 
	v.pb({a*4,25});
	v.pb({b*2,50});
	v.pb({c,100});
	v.pb({d/2.0,200});
	cin>>n;
	// n*=100;
	srt(v);
	if(v[0].ff==v[1].ff && v[0].ss==200)
	{
		swap(v[0],v[1]);
	}

	if(v[0].ss==200)
	{
		if(n%2)
			cout<<(ll)(v[0].ff*(n-1)+v[1].ff);
		else
			cout<<(ll)(v[0].ff*n);
	}
	else
		cout<<(ll)(v[0].ff*n);

//--------------------------------------------------------------------------------------
	
	#ifdef PARTH_LATHIYA_HOME
		cout<<"\n"; }
	#endif

	return 0;
}

Measured memory_bytes: 256
n, k = map(int, input().split())
l = [[0, 0] for _ in range(n)]
for i in range(n):
    l[i][0], l[i][1] = map(int, input().split())
l.sort()
c = 0
for i in range(n):
    c += l[i][1]
    if c >= k:
        print(l[i][0])
        break


Measured memory_bytes: 20036
#include<bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin>>n;
    int arr[n+1];
    for(int i=0;i<n+1;i++)
    {
        arr[i]=0;
    }
    for(int i=2;i<=n;i++)
    {
        int x;
        cin>>x;
        arr[x]++;
    }
    for(int i=1;i<n+1;i++)
    {
        cout<<arr[i]<<endl;
    }
    return 0;
}

Measured memory_bytes: 4420
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define In_The_Name_Of_Allah_The_Merciful ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define Alhamdulillah return 0;
#define loop(i,k,n) for (ll i = k ; i < n ; ++i)
#define all(v) v.begin(),v.end()
#define debug(n) cerr << "[" << #n << " = " << n << "]" << endl

void Suhaib_Sawalha (){

    int n;
    cin >> n;
    int k = 1000;
    while (k < n)
        k += 1000;
    cout << k - n;

}

int main(){
                                In_The_Name_Of_Allah_The_Merciful   /* بسم الله الرحمن الرحيم  */
#ifndef ONLINE_JUDGE
    freopen("SuhaibSawalha1.txt","r",stdin);
#endif
//int _;for(cin>>_;_;--_,cout<<'\n')
        Suhaib_Sawalha();
                                         Alhamdulillah                    /* الحمد لله */
}


Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cstring>
#include<algorithm>
using namespace std;
int n,ans;
int minn=1e9,maxx=-1;
int a[1234567];
int main()
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++){int shuru;
		scanf("%d",&shuru);
		a[shuru]++;
		minn=min(minn,shuru);maxx=max(maxx,shuru);
	}
	for(int i=minn;i<=maxx;i++)
	{
		ans=max(ans,a[i]+a[i-1]+a[i+1]);
	}cout<<ans;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
#define arep(i,x,n) for(int i=int(x);i<(int)(n);i++)
#define rep(i,n) for(long long i = 0;i < n;++i)
#define pi 3.141592653589793
#define eps 0.00000001
#define INF 1e9+7  
using ll = long long; 
using P=pair<int,int>;
using lP=pair<ll,ll>;
using fP=pair<double,double>;
ll const mod=998244353;
const ll MAX=300000;
using vi=vector<int>;
using vc=vector<char>;
using vs=vector<string>;
using vvi =vector<vector<int>>;
using vvc=vector<vector<char>>;
using vvp =vector<vector<P>>;

int f(ll b){
    int ret=0;
    while(b>0){
        b/=10;
        ret++;
    }
    return ret;
}


vector< ll > divisor(ll n) {
  vector< ll > ret;
  for(ll i = 1; i * i <= n; i++) {
    if(n % i == 0) {
      ret.push_back(i);
      ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}
int main(){
    ll n;
    cin>>n;
    vector<ll> div=divisor(n);
    int l=0,r=div.size()-1;
    int ans=INF;
    
    while(l<r){
        
        ans=min(ans,f(div[r]));
        l++,r--;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,m,i,leap=0;
	while(~scanf("%d",&n))
	{
		for(i=0;i<n;i++)
		{
			scanf("%d",&m);
			if(m%2==0)
			{
//				printf("%d\n",m);
				if(m%3!=0&&m%5!=0)
					leap=1;
			}
		}
		if(leap)
			printf("DENIED\n");
		else
			printf("APPROVED\n");
		leap=0;
	}
}

Measured memory_bytes: 128
from collections import deque
N = int(input())
S = list(input())
A = deque()
B = []

left_cnt = 0
right_cnt = 0
for s in S:
    if s == "(":
        left_cnt += 1
        A.append("(")
    else:
        A.append(")")
        if right_cnt + 1 > left_cnt:
            B.append("(")
        else:
            right_cnt += 1

C = [")"] * (left_cnt - right_cnt)
B.extend(A)
B.extend(C)
print("".join(B))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
 
using ll = long long;
using ld = long double;
#define FOR(i, m, n) for (int i = (m); i < (n); i++)
#define FORR(i, m, n) for (int i = (m); i >= (n); i--)
#define REP(i, n) FOR(i, 0, (n))
#define REPR(i, n) FORR(i, (n) - 1, 0)
#define REP1(i, n) FOR(i, 1, (n) + 1)
#define REPS(c, s) for (char c : s)
#define ALL(c) (c).begin(), (c).end()
#define SORT(c) sort(ALL(c))
#define REV(c) reverse(ALL(c))
#define sz(v) (int)v.size()
#define endl '\n'
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;}
const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000001000000001LL;
 
void solve();
 
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout << fixed << setprecision(numeric_limits<double>::max_digits10);
    solve();
    return 0;
}

void solve() {
    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    vector<int> sum(n + 1, 0);
    REP(i, n) {
        cin >> a[i];
        sum[i + 1] = sum[i] + a[i];
    }
    int mx = 0;
    int idx = -1;
    REP(i, n - k + 1) {
        if (chmax(mx, sum[k + i] - sum[i])) idx = i;
    }
    double ans = 0.0;
    FOR(i, idx, k + idx) {
        ans += (double)(a[i] + 1) / 2.0;
    }
    cout << ans << endl;
}


Measured memory_bytes: 1792
N,M,X=map(int,input().split())
A=list(map(int,input().split()))
S=0
L=0

for i in range(X):
  for j in A:
    if i == j:
      S+=1

for i in range(X,N+1):
  for j in A:
    if i == j:
      L+=1

print(S if S <= L else L)

Measured memory_bytes: 3064
def g_c_d(x, y):
    if x == 0:
        return y
    elif y == 0:
        return x
    else:
        return g_c_d(y, x % y)


a = int(input())
b = list(map(int, input().split()))
c = 0
for i in range(a):
    c = g_c_d(c, b[i])
d = 0
while True:
    if c % 2 == 0:
        c = c // 2
        d += 1
    else:
        break
print(d)


Measured memory_bytes: 3064
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		// 整数の入力
		int s = sc.nextInt();
        int w = sc.nextInt();
      
      	String result;
      
      if(w >= s){
        result = "unsafe";
      } else {
        result = "safe";
      }
      
		// 文字列の入力
		System.out.println(result);
	}
}

Measured memory_bytes: 27088
# -*- coding: utf-8 -*-
import sys, copy, math, itertools
from copy import *
from collections import deque
import numpy as np
from heapq import *
from bisect import *
import scipy as sp

A, B, C = list( map(int, input().split() ) )

if A==B: print(C)
if B==C: print(A)
if C==A: print(B)

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


typedef long long ll;
#define MOD 1000000007

ll dp[13];
ll dp1[13];
signed main() {
    ios_base::sync_with_stdio(false);
    #ifdef bhartiya
        cin.exceptions(cin.failbit);
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
        string s;
        cin>>s;
        reverse(s.begin(),s.end());
        dp[0]=1;
        ll m=1;
        for(ll i=0;i<s.length();i++)
        {
        	ll l=0,r=9;
        	if(s[i]!='?')
        	{
        		l=s[i]-'0';
        		r=l;
        	}
        	for(ll j=l;j<=r;j++)
        	{
        		ll bt=j*m%13;
        		for(ll k=0;k<=12;k++)
        		{
        			dp1[(k+bt)%13]=(dp1[(k+bt)%13]+dp[k])%MOD;
        		}
        	}
        	m=m*10%13;
        	for(ll j=0;j<13;j++)
        	{
        		dp[j]=dp1[j];
        		dp1[j]=0;
        	}
        }
        cout<<dp[5]<<endl;
    
}

Measured memory_bytes: 512
#include<stdio.h>
int main(void) {
	int a,b,c;
	int ans = 0;
	scanf("%d %d %d", &a,&b,&c);
	if (a > b) {
		a= a - b;
		c = c - a;
	}
	
	if (c < 0) {
		c = 0;
	}
	printf("%d\n", c);
	return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {


		Scanner sc = new Scanner(System.in);
		String[] s = sc.next().split("");

		if(!s[2].equals(s[3])) {
			System.out.println("No");
			return;
		}

		if(!s[4].equals(s[5])) {
			System.out.println("No");
			return;
		}
		System.out.println("Yes");

	}
}

Measured memory_bytes: 23636
Tap = input()
len_Tap = len(Tap)
count = 0

for i in range(len_Tap):
    if (i+1) % 2 == 1:
        if Tap[i] == 'R' or Tap[i] == 'U' or Tap[i] == 'D':
            count += 1
    
    else:
        if Tap[i] == 'L' or Tap[i] == 'U' or Tap[i] == 'D':
            count += 1

if count == len_Tap:
    print('Yes')

else:
    print('No')

Measured memory_bytes: 3064
#include <bits/stdc++.h>
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<int, int> ii;
typedef pair<ll, int> li;
typedef pair<int, ll> il;
typedef pair<ll , ll> lli;
typedef vector<ii> vii;
typedef vector<il> vil;
typedef vector<li> vli;
typedef vector<lli> vlli;
typedef pair < ll , pair < ll , ll > > cm;

#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define in insert
#define f0(b) for(int i=0;i<(b);i++)
#define f00(b) for(int j=0;j<(b);j++)
#define f1(b) for(int i=1;i<=(b);i++)
#define f11(b) for(int j=1;j<=(b);j++)
#define f2(a,b) for(int i=(a);i<=(b);i++)
#define f22(a,b) for(int j=(a);j<=(b);j++)
#define sf(a) scanf("%lld",&a)
#define sff(a,b) scanf("%lld %lld", &a , &b)
#define pf(a) printf("%lld\n",a)
#define pff(a,b) printf("%lld %lld\n", a , b)
#define PI 3.14159265359
#define bug printf("**!\n")
#define mem(a , b) memset(a, b ,sizeof(a))
#define front_zero(n) __builtin_clzll(n)
#define back_zero(n) __builtin_ctzll(n)
#define total_one(n) __builtin_popcountll(n)
#define clean cout.flush()

const ll mod = (ll)1e9+7;
const ll maxn = (ll)2e5+5;
const int nnn = 1048590;
const int inf = numeric_limits<int>::max()-1;
//const ll INF = numeric_limits<ll>::max()-1;
const ll INF = 1e18;

ll dx[]={0,1,0,-1};
ll dy[]={1,0,-1,0};
ll dxx[]={0,1,0,-1,1,1,-1,-1};
ll dyy[]={1,0,-1,0,1,-1,1,-1};

char a[10][10];
ll n , m , k;
ll ans = 0;
void dp(char b[10][10] , ll pos){
	
	if(pos > n && pos > m){
		ll res = 0;
		f1(n){
			f11(m){
				if(b[i][j] == '#') res++;
			}
		}
		if(res == k) ans++;
		return;
	}
	dp(b , pos+1);
	if(pos <= n && pos <= m){
		char c[10][10];
		f1(n){
			f11(m) c[i][j] = b[i][j];
		}
		f1(m) c[pos][i] = '.';
		f1(n) c[i][pos] = '.';
		dp(c , pos+1);
	}
	if(pos <= n){
		char c[10][10];
		f1(n){
			f11(m) c[i][j] = b[i][j];
		}
		f1(m) c[pos][i] = '.';
		dp(c, pos+1);
	}
	if(pos <= m){
		char c[10][10];
		f1(n){
			f11(m) c[i][j] = b[i][j];
		}
		f1(n) c[i][pos] = '.';
		dp(c , pos+1);
	}
	return;
	
}


void solve(){
	cin >> n >> m >> k;
	f1(n){
		f11(m) cin >> a[i][j];
	} 
	dp(a, 1);
	cout << ans;
	return;
}


int main(int argc, char *argv[]) {
   
   ios_base::sync_with_stdio(0); cin.tie(NULL); cout.tie(NULL);
    ll T;
    T=1;
    //cin >> T;
    //scanf("%lld",&T);
    ll CT = 0;
    //work();
    while(T--){
    	//cout << "Case " << ++CT <<": " ;
    //	printf("Case %lld: \n",++CT);
		solve();
	}
    
    return 0;
}

Measured memory_bytes: 3640
# -*- coding: utf-8 -*-
"""
Created on Sat May 25 20:54:19 2019

@author: Yamazaki Kenichi
"""

N,M = map(int,input().split())
lr = [list(map(int,input().split())) for i in range(M)]

left, right = 1, N
for c in lr:
    left = max(left,c[0])
    right = min(right,c[1])
ans = max(right - left + 1, 0)
print(ans)
    

Measured memory_bytes: 27332
t = input()
before_is_zero = True
n0 = 0
n1 = 0
keeped_1 = 0
ans = 0
for i, x in enumerate(t):
    if x == '0':
        n0 += 1
        before_is_zero = True
    elif x == '1':
        if before_is_zero:
            tmp_add = -(n0 - (i+1)%2)//2
            ans += tmp_add
            n1 += 1
            before_is_zero = False
        else:
            ans -= tmp_add
            n1 += 1
            keeped_1 += 1
            before_is_zero = True
ans += (n1 - keeped_1) * n0
ans += ((n1+1)//2) * (n1//2 + 1)
print(ans)

Measured memory_bytes: 9380
#include <cstdio>
#include <algorithm>

using namespace std;

char get(int a, int b, int c) {
    if (abs(a - b) <= 1) {
        if (b > a) c++;
        
        if (c % 2 == 0) {
            return 'A';
        } else {
            return 'B';
        }
    } else {
        long long a1, a2, b1, b2, x, y, l, r, m;
        
        l = 0, r = max(a, b), m = (l + r) / 2;
        
        while (r - l > 1) {
            a1 = (a + m - 1) / m;
            a2 = a;
            b1 = (b + m - 1) / m;
            b2 = b;
            
            if (a1 > b2 + 1 || b1 > a2 + 1) {
                l = m;
                m = (l + r) / 2;
            } else {
                r = m;
                m = (l + r) / 2;
            }
        }
        
        x = r;
        
        if (b > a * x) {
            if (b % x == 0) {
                if (c % (x + 1) == x) {
                    return 'A';
                } else {
                    return 'B';
                }
            } else {
                if (c < b % x) {
                    return 'B';
                } else {
                    c -= b % x;
                    if (c % (x + 1) == 0) {
                        return 'A';
                    } else {
                        return 'B';
                    }
                }
            }
        }
        
        l = 0, r = a / x + 1, m = (l + r) / 2;
        
        while (r - l > 1) {
            long long aa = a - m * x;
            long long bb = b - m;
            
            if (aa < 0 || bb < 0 || bb > aa * x) {
                r = m;
                m = (l + r) / 2;
            } else {
                l = m;
                m = (l + r) / 2;
            }
        }
        
        y = l;
        
        if (c < y * (x + 1)) {
            if (c % (x + 1) == x) {
                return 'B';
            } else {
                return 'A';
            }
        }
        
        a -= y * x;
        b -= y;
        c -= y * (x + 1);
        
        if (b == 0) return 'A';
        
        if (b % x == 0) {
            long long z = b / x - 1;
            
            if (c < a - z) {
                return 'A';
            } else {
                c -= a - z;
                if (c % (x + 1) == x) {
                    return 'A';
                } else {
                    return 'B';
                }
            }
        } else {
            long long z = b / x;
            
            if (c < a - z) {
                return 'A';
            } else if (c < a - z + b % x) {
                return 'B';
            } else {
                c -= a - z + b % x;
                if (c % (x + 1) == 0) {
                    return 'A';
                } else {
                    return 'B';
                }
            }
        }
    }
}

int main() {
    int q, i, j;
    
    scanf("%d", &q);
    
    for (i = 0; i < q; i++) {
        int a, b, c, d;
        
        scanf("%d %d %d %d", &a, &b, &c, &d);
        
        for (j = c; j <= d; j++) putchar(get(a, b, j - 1));
        puts("");
    }
    
    return 0;
}


Measured memory_bytes: 256
S = input()

if  '01' <= S[:2] <= '12' and '01' <= S[2:] <= '12':
    print('AMBIGUOUS')
elif '01' <= S[:2] <= '12':
    print('MMYY')
elif '01' <= S[2:] <= '12':
    print('YYMM')
else:
    print('NA')


Measured memory_bytes: 2940
#include<iostream>
#include<algorithm>
using namespace std;
int parent[200005];

int root(int a);
void unite(int a,int b);

int main(){
  int n,m;
  cin>>n>>m;
  for(int i=0;i<=n;i++){
    parent[i]=i;
  }
  for(int i=0;i<m;i++){
    int a,b;
    cin>>a>>b;
    unite(a,b);
  }
  
  int maxim=0;
  int cnt[200005]={0};
  for(int i=1;i<=n;i++){
    cnt[root(i)]++;
    maxim=max(maxim,cnt[root(i)]);
  }
  
  cout<<maxim<<endl;
  return(0);
}

int root(int a){
  if(parent[a]==a){
    return(a);
  }
  return(parent[a]=root(parent[a]));
}

void unite(int a,int b){
  a=root(a);
  b=root(b);
  parent[a]=b;
  return;
}

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

using namespace std;

int a, b, c, x, y;

int main(){
	scanf("%d%d%d%d%d", &a, &b, &c, &x, &y);
	
	if(2 * c >= a + b)
	return 0 * printf("%d\n", a * x + b * y);
	
	int tot = 0;
	int mn = min(x, y);
	
	tot = 2 * mn * c;
	x -= mn;
	y -= mn;
	
	if(x == 0)
	tot += y * min(2 * c, b);
	else if(y == 0)
	tot += x * min(2 * c, a);
	
	printf("%d\n", tot);
}


Measured memory_bytes: 256
program probB
  implicit none
  integer n,x,i,j,tmp,res,ans
  integer,allocatable :: m(:)

  read(*,*) n,x
  allocate(m(n))
  do i = 1,n
     read (*,*) m(i)
  end do

  ans = n
  res = x-sum(m)

  ans = ans + res/minval(m)

  write (*,*) ans

     
end program probB



Measured memory_bytes: 256