akhauriyash/Code-Regression huggingface dataset:
import sys

input = sys.stdin.readline


def main():
    N, x = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]

    ans = 0
    for i in range(N):
        if i == 0:
            if A[0] > x:
                ans += A[0] - x
                A[0] = x
        elif A[i - 1] + A[i] > x:
            ans += A[i - 1] + A[i] - x
            A[i] -= A[i - 1] + A[i] - x

    print(ans)


    
    


if __name__ == '__main__':
    main()


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

const int MAXN = 200000 + 10;

int n;
int a[MAXN];
int32_t main() {
    ios_base::sync_with_stdio(0);
    cin >> n;

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

    int res = 0;
    for (int i = 0; i < n; i++) {
        if (a[i] == i) {
            res++;
            if (i < n-1)
                swap(a[i], a[i+1]);
        }
    }

    cout << res << "\n";

    return 0;
}


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


int N;
long long A[1000001];
long long B[1000000];

int main() {
    cin >> N;
    rep(i, N + 1) {
        cin >> A[i];
    }

    rep(i, N) {
        cin >> B[i];
    }

    long long ans = 0;
    for (int i = 0; i <= N - 1; i++) {
        // 現在
        long long current = min(A[i], B[i]); 
        A[i] -= current; 
        B[i] -= current;

        ans += current;

        // 1個先
        long long next = min(A[i + 1], B[i]);
        ans += next; 

        A[i + 1] -= next; 
        B[i] -= next;
    }

    cout << ans << endl;
}

Measured memory_bytes: 5120
s = input()
e = len(s)

while e > 0:
    if e >= 5 and (s[e-5:e] == 'dream' or s[e-5:e] == 'erase'):
        e -= 5
    elif e >= 6 and s[e-6:e] == 'eraser':
        e -= 6
    elif  e >= 7 and s[e-7:e] == 'dreamer':
        e -= 7
    else:
        break

if e == 0:
    print("YES")
else:
    print("NO")



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

using namespace std;
using ll=long long;

int main()
{
    int m,d;
    cin >>m>>d;
    int ans =0;
    for(int i=1;i<=m;i++){
        for(int j=1;j<=d;j++){
            int c=j;
            int a=c%10;
            c/=10;
            int b=c%10;
            if(a>=2&&b>=2&&a*b==i)ans++;
        }
    }
    cout << ans << endl;
    return 0;
}


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

template <typename Integer> Integer gcd(Integer x, Integer y){
    while(y) std::swap(x %= y, y); return x;
}

void solve(void){
    long long int a, b, c, d; std::cin >> a >> b >> c >> d;
    if(a < b or d < b){ std::cout << "No\n"; return; }
    if(c >= b){ std::cout << "Yes\n"; return; }
    a %= b; const long long int g = gcd(b, d);
    a %= g; const long long int criterion = b - (g - a);
    if(criterion > c) std::cout << "No\n"; else std::cout << "Yes\n";
}

int main(void){
    std::cin.tie(nullptr); std::cin.sync_with_stdio(false);
    std::cout.tie(nullptr); std::cout.sync_with_stdio(false);
    int t; std::cin >> t; while(t--) solve();
}

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

const int N = 100005, M = 100005;

int n, m, dp[N], ans = 0;
vector<int> adj[N], adjr[N], order;
bool vis[N];

void dfs(int u){
    vis[u] = true;
    for(int v : adjr[u])
        if(!vis[v]) dfs(v);

    order.push_back(u);
}

int main(){
    ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
    cin >> n >> m;
    for(int i = 0; i < m; i++){
        int u, v;
        cin >> u >> v;
        u--, v--;
        adj[u].push_back(v);
        adjr[v].push_back(u);
    }
    for(int i = 0; i < n; i++)
        if(!vis[i]) dfs(i);
    for(int i = n-1; i >= 0; i--){
        int u = order[i];
        for(int v : adj[u])
            dp[u] = max(dp[u], dp[v]+1);
        ans = max(ans, dp[u]);
    }
    cout << ans << "\n";
}

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

template<typename T> class Dijkstra {
public:
  struct edge {
    int to; T cost;
  };
  int V;
  vector<vector<edge>> G;
  vector<T> dist;
  using pti = pair<T,int>;
  Dijkstra(int n) : V(n), G(V), dist(V, numeric_limits<T>::max()) {}
  void add(int u, int v, T cost) {
    G.at(u).push_back((edge) {v, cost});
    G.at(v).push_back((edge) {u, cost});
  }
  void solve(int s) {
    priority_queue<pti, vector<pti>, greater<pti>> Q;
    dist.at(s) = 0;
    Q.push(pti(0, s));
    while (!Q.empty()) {
      pti p = Q.top();
      Q.pop();
      int v = p.second;
      if (dist.at(v) < p.first) continue;
      for (auto &w : G.at(v)) {
        if (dist.at(w.to) > dist.at(v) + w.cost) {
          dist.at(w.to) = dist.at(v) + w.cost;
          Q.push(pti(dist.at(w.to), w.to));
        }
      }
    }
  }
};

int main() {
  int N, X, Y;
  cin >> N >> X >> Y;
  X--, Y--;
  Dijkstra<int> D(N);
  for (int i = 0; i + 1 < N; i++) {
    D.add(i, i + 1, 1);
  }
  D.add(X, Y, 1);
  vector<int> ans(N);
  for (int i = 0; i < N; i++) {
    Dijkstra<int> tmp = D;
    tmp.solve(i);
    for (auto d : tmp.dist) ans.at(d)++;
  }
  for (int i = 1; i < N; i++) {
    cout << ans.at(i) / 2 << "\n";
  }
}

Measured memory_bytes: 3872
INT = lambda: int(input())
INTM = lambda: map(int,input().split())
STRM = lambda: map(str,input().split())
STR = lambda: str(input())
LIST = lambda: list(map(int,input().split()))
LISTS = lambda: list(map(str,input().split()))
def do():
    s=INT()
    aset=set()
    aset.add(s)
    ct=1
    while True:
        ct+=1
        if s%2==0:
            s=int(s/2)
        else:
            s=3*s+1
        aset.add(s)
        if len(aset)!=ct:
            break
    print(ct)
        
if __name__ == '__main__':
    do()

Measured memory_bytes: 3064
def binarySearch(l, key):
  left = 0
  right = len(l)
  while left < right:
    mid = (left + right) // 2
    if l[mid] == key:
      return mid
    elif key < l[mid]:
      right = mid
    else:
      left = mid + 1
  return "NOT_FOUND"

n = int(input())
S = list(map(int, input().split()))
q = int(input())
T = list(map(int, input().split()))
cnt = 0
for i in T:
  if type(binarySearch(S, i)) == int:
    cnt += 1
print(cnt)


Measured memory_bytes: 16712
#include<bits/stdc++.h>
using namespace std;
int main(){
    string s;
    long long k;
    cin>>s>>k;
    char ans='1';
    for(int i=0;i<s.size();i++){
        if(s[i]!='1'){
            ans=s[i];
            break;
        }
    }
    int i=0;
    for(i=0;s[i]=='1';i++);
    if(k<=i)ans='1';
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
int main(void){
    double i,n,p,ans=0;
    scanf("%lf %lf",&n,&p);
    if(n==1)ans=p;
    else if(n>=40 || n>=p)ans=1;
    else if(n==2){
        for(i=1; i<=1000000; i++){
            if(fmod(p,pow(i,2))==0)ans=i;
        }
    }
    else if(n==3){
        for(i=1; i<=10000; i++){
            if(fmod(p,pow(i,3))==0)ans=i;
        }
    }
    else for(i=1; i<=1000; i++){
        if(fmod(p,pow(i,n))==0)ans=i;
    }
    printf("%.0lf",ans);
    return 0;
}

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

#define REP(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define all(x) (x).begin(),(x).end()
using ll = long long;
string char_to_string(char val) {
  return string(1, val);
}
int char_to_int(char val) {
  return val - '0';
}
template<class T> inline bool chmin(T& a, T b) {
  if (a > b) {
    a = b;
    return true;
  }
  return false;
}
template<class T> inline bool chmax(T& a, T b) {
  if (a < b) {
    a = b;
    return true;
  }
  return false;
}
int vector_finder(std::vector<ll> vec, int number) {
  auto itr = std::find(vec.begin(), vec.end(), number);
  size_t index = std::distance( vec.begin(), itr );
  if (index != vec.size()) { // 発見できたとき
    return 1;
  }
  else { // 発見できなかったとき
    return 0;
  }
}

int main() {
  int H, W; cin >> H >> W;
  vector<string> a(H); REP(i, H) cin >> a[i];
  vector<string> tmp;
  int cnt = 0;
  REP(i, H) {
    int t = 0;
    REP(k, W) {
      if(a[i][k] == '.') t++;
    }
    if(t != W) {
      tmp.push_back(a[i]);
    } else {
      cnt++;
    }
  }
  vector<string> tmp2(H - cnt);
  REP(i, W) {
    int t = 0;
    REP(k, H - cnt) {
      if(tmp[k][i] == '.') t++;
    }
    if(t != H - cnt) {
      REP(m, H - cnt) {
        tmp2[m].push_back(tmp[m][i]);
      }
    }
  }
  REP(i, tmp2.size()) {
    REP(k, tmp2[i].size()) {
      cout << tmp2[i][k];
    }
    cout << endl;
  }
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
char a[51][51],b[51][51];
int main(){
	int n,m,i;
	cin>>n>>m;
	getchar();
	for(i=0;i<n;i++){
		cin>>a[i];
	}
	for(i=0;i<m;i++){
		cin>>b[i];
	}
	
	for(i=0;i+m-1<n;i++){
		for(int j=0;j+m-1<n;j++){
			bool flag=true;
			for(int k=0;k<m;k++){
				for(int l=0;l<m;l++){
					if(a[i+k][j+l]!=b[k][l]){
						flag=false;
					}
				}
			}
			if(flag){
				cout<<"Yes";
				return 0;
			}
			flag=true;
		}
	}
	cout<<"No";
	return 0;
}


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

// macro
#define rep(i,n) for(i=0;i<n;i++)
#define ll long long
#define all(v) v.begin(), v.end()

// code starts
int main()
{
  ll a,b,n;cin>>a>>b>>n;
  if(n>=b-1)
  {
    cout<<a*(b-1)/b<<endl;
  }
  else
  {
    cout<<a*n/b<<endl;
  }
  
}


Measured memory_bytes: 3604
import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {
    public static void main(String[] args) throws Exception {
        // Here your code !
        BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        int turn = Integer.parseInt(br.readLine());
        int taro=0,hanako=0;
        for(int i=0;i<turn;i++) {
            String[] line2 = br.readLine().split(" ");
            //引き分け
            if(line2[0].compareTo(line2[1]) == 0){
                taro++;
                hanako++;
            }
            else if(line2[0].compareTo(line2[1]) > 0){
                taro += 3;
            }
            else {
                hanako += 3;
            }
        }
        System.out.println(taro + " " + hanako);
    }
}

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

const int mx=100010;
int sp[mx][35];
ll cum[mx][35];
int main(){
	ll n,x,m;
	cin>>n>>x>>m;
	for(int i=0;i<m;i++){
		sp[i][0]=(i*1LL*i)%m;
		cum[i][0]=sp[i][0];
	}
	for(int j=1;j<35;j++){
		for(int i=0;i<m;i++){
			sp[i][j]=i;
			cum[i][j]+=cum[sp[i][j]][j-1];
			sp[i][j]=sp[sp[i][j]][j-1];

			cum[i][j]+=cum[sp[i][j]][j-1];
			sp[i][j]=sp[sp[i][j]][j-1];
		}
	}
	ll curr=x,an=x;
	for(int i=35;i>=0;i--){
		if((n-1)&(1LL<<i)){
			an+=cum[curr][i];
			curr=sp[curr][i];
		}
	}
	cout<<an<<endl;
}

Measured memory_bytes: 44696
#define _USE_MATH_DEFINES
#define INF 100000000
#include <iostream>
#include <sstream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <queue>
#include <stack>
#include <limits>
#include <map>
#include <string>
#include <cstring>
#include <set>
#include <deque>
#include <bitset>
#include <list>

using namespace std;

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

static const double EPS = 1e-8;


int main(){
	string str;
	while(cin >> str){
		int joi=0,ioi=0;
		for(int i=0;i+2<str.size();i++){
			string tmp = str.substr(i,3);
			if(tmp == "JOI") joi++;
			else if(tmp == "IOI") ioi++;
		}
		printf("%d\n%d\n",joi,ioi);
	}	
}

Measured memory_bytes: 0
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef string str;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector <pii> vpii;
typedef vector <pll> vpll;
typedef map <str,int> mapsi;
typedef map <str,int> :: iterator mapsitr;
typedef map <int , int> mint;
typedef map <ll , ll> mll;
typedef set <int> si;
typedef set <ll> sll;
typedef si :: iterator sitr;
typedef si :: reverse_iterator rsitr;
typedef sll :: iterator sltr;
typedef sll :: reverse_iterator rsltr;
#define mset multiset
typedef mset <int> msi;
typedef mset <ll> msll;
typedef msi :: iterator msitr;
typedef msi :: reverse_iterator msritr;
typedef msll :: iterator msltr;
typedef msll :: reverse_iterator mslritr;
#define mp make_pair
#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define fi first
#define se second
#define fs first.second
#define ss second.second
#define ff first.first
#define sf second.first
#define newl '\n'
char to_upper (char x){
    if( 97 <= int(x) && int(x) <= 126)return char(x-32);
    else if( 65 <= int(x) && int(x) <= 90)return x;
}
char to_lower (char x){
    if( 97 <= int(x) && int(x) <= 126)return x;
    else if( 65 <= int(x) && int(x) <= 90)return char(x+32);
}
int numerize (char x){
    if(48 <= int(x) && int(x) <= 57)return int(x-'0');
    else if( 97 <= int(x) && int(x) <= 126)return int(x-96);
    else if( 65 <= int(x) && int(x) <= 90)return int(x-64);
}
//void IO(){
//	#ifndef ONLINE_JUDGE
//	    freopen("input.txt", "r", stdin);
//	    freopen("output.txt", "w", stdout);
//	#endif
//}
// end of Template

int a,b,x;
int main(){
	//IO();
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin>>a>>b>>x;
    if(a<=x && x<=a+b){cout<<"YES\n";}
    else cout<<"NO\n";

}


Measured memory_bytes: 256
object Main extends App {
  import scala.io.StdIn._


  val q = readLine.trim.toInt
  for (_ ← 0 until q){
    val Array(s, t) = readLine.trim.split(' ')
    println(
      s.indices.find(p ⇒ s(p) != t(p)) match {
        case Some(firstMismatch) ⇒ abs(firstMismatch - s.lastIndexOf('1')) + abs(firstMismatch - t.lastIndexOf('1'))
        case None ⇒ 0
      }
    )
  }
  def abs(num: Int): Int = if (num > 0) num else -num
  implicit class ScopeFunc[T](value: T){
    def let[A](func: T ⇒ A): A = func(value)
    def also(func: T ⇒ Unit): T = {
      func(value)
      value
    }
  }
}


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

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

    ll kaihuku = 0;
    for (int i = 0; i < n; i++) {
        for (int j = i + 1; j < n; j++) {
            kaihuku += d[i] * d[j];
        }
    }

    cout << kaihuku << endl;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <algorithm>
#include <iostream>
#include <vector>
#include <assert.h>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <math.h>
#include <string>
#include <string.h>
#include <queue>
#include <complex>
#include <iomanip>
#include <stack>
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;
ll mod=1e9+7;
double eps=1e-7;
ll exp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=(x*x)%mod){if(y&1)ret=(ret*x)%mod;}return ret;}
ull pexp(ull x,ull y){if(y<0) return 0; ull ret=1; for(;y;y>>=1,x=(x*x)){if(y&1)ret=(ret*x);}return ret;}
ll gcd(ll x,ll y){if(!x||!y) return x+y; return x%y==0?y:gcd(y,x%y);}
ll lcm(ll x,ll y){return x*(y/gcd(x,y));}
ll bsum(ll u,ll b){ll ret=0;if(u<b)return u;while(u){ret+=u%b;u/=b;}return ret;}
ll prival(ll u,ll p){ll cn=0;while(u%p==0){cn++;u=u/p;}return cn;}
ll minv(ll a,ll b){return 1<a?b-minv(b%a,a)*b/a:1;}
ll extm(ll a,ll b){ll ret=0;while(a!=0){if(a%2==1){ret+=b;ret%=mod;}a>>=1;b=(2*b)%mod;}return ret;}   
ll eaphi(ll x){ll t=x,ret=x,i;for(i=2;i*i<=x;i++){if(t%i==0){ret-=ret/i;while(t%i==0) t/=i;}}if(t!=1) ret-=ret/t;return ret;}
ll eadivc(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=2;if(x%i==0 && i*i==x) ret+=1;}return ret;}
ll eadivs(ll x){ll ret=0;ll i;for(i=1;i*i<=x;i++){if(x%i==0 && i*i!=x) ret+=i+x/i;if(x%i==0 && i*i==x) ret+=i;}return ret;}
ll ndig(ll x, ll b){ll ret=0;while(x){x/=b; ret++;}return ret;}
ll rev(ll n, ll b){ll ret=0;while(n){ret=b*ret+n%b; n/=b;}return ret;}
ll sq(ll x){ll t=(ll)sqrt(x); for(ll i=t-2 ; i<=t+2 ; i++) if(i*i==x) return abs(i); return -1;}
ll extexp(ll x,ll y){if(y<0) return 0; ll ret=1;for(;y;y>>=1,x=extm(x,x)){if(y&1)ret=extm(ret,x);}return ret;}
bool isprime(ll x){if(x<=1) return false; for(ll i=2;i*i<=x;i++){if(x%i==0){return false;}}return true;}
ll dp[3][111];
ll vv[3][111];
int n;

int main(void)
{
	ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	cin>>n; int i, j;
	for(i=1 ; i<=2 ; i++)
		for(j=1 ; j<=n ; j++)
			cin>>vv[i][j];
	dp[1][1]=vv[1][1];
	for(i=1 ; i<=2 ; i++)
	{
		for(j=1 ; j<=n ; j++)
		{
			if(i==1 && j==1) continue;
			if(j!=1) dp[i][j]=max(dp[i][j],dp[i][j-1]+vv[i][j]);
			if(i!=1) dp[i][j]=max(dp[i][j],dp[i-1][j]+vv[i][j]);
		}
	}
	cout<<dp[2][n];
	return 0;
}

Measured memory_bytes: 256
#054_C
from itertools import permutations
n,m=map(int,input().split())
edges=[[False for _ in range(n)] for _ in range(n)]
for _ in range(m):
    a,b=map(int,input().split())
    a,b=a-1,b-1
    edges[a][b]=edges[b][a]=True

ans=0
for l in permutations(range(1,n),n-1):
    l=[0]+list(l)
    if all(edges[l[i]][l[i+1]] for i in range(n-1)):
        ans+=1
print(ans)

Measured memory_bytes: 3064
def solve(string):
    from itertools import accumulate
    n, k = map(int, string.split())
    *a, = accumulate(range(n + 1))
    ans, m = 0, 10**9 + 7
    for b, c in zip(a[:-k][::-1], a[k - 1:]):
        ans = (ans + a[-1] - b - c + 1) % m
    return str((ans + 1) % m)


if __name__ == '__main__':
    import sys
    print(solve(sys.stdin.read().strip()))


Measured memory_bytes: 22396
#include <iostream>
#include <vector>
#include <cmath>
#include <queue>
#include <cstdio>
#include <deque>
#include <algorithm>
#include <string>
#include <cstring>
#include <list>
#include <stack>

using namespace std;

int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	double x, y; cin >> x >> y;
	printf("%.10f", x / y);



}


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

namespace abc153
{
    class Program
    {
        static void Main(string[] args)
        {
            var n = Console.ReadLine().Split().Select(s => int.Parse(s)).ToArray();
            var h = Console.ReadLine().Split().Select(s => long.Parse(s)).ToList();
            long ans = h.OrderByDescending(o => o).Skip(n[1]).Sum();
            Console.WriteLine(ans);

        }
    }
}


Measured memory_bytes: 42880
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define P pair<int, int>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
template<class T> inline bool chmax(T& a, T b){if (a < b) { a = b; return true; } return false;}
template<class T> inline bool chmin(T& a, T b){if (a > b) { a = b; return true; } return false;}
ll INF = 1e+18;
int iINF = 1e9;


int main()
{

  int H, W; cin >> H >> W;
  vector<vector<char>> grid(H, vector<char>(W));
  rep(i, 0, H){
    rep(k, 0, W){
      cin >> grid[i][k];
    }
  }
  vector<vector<ll>> dp(H, vector<ll>(W, 0));
  dp[H - 1][W - 1] = 1;
  for(int i = W - 2; i >= 0; --i){
    if(grid[H - 1][i] == '.') dp[H - 1][i] = dp[H - 1][i + 1];
  }
  for(int i = H - 2; i >= 0; --i){
    if(grid[i][W - 1] == '.') dp[i][W - 1] = dp[i + 1][W - 1];
  }
  repe(i, 2, H){
    repe(k, 2, W){
      if(grid[H -i][W - k] == '.') dp[H - i][W - k] = dp[H - i + 1][W - k] + dp[H - i][W - k + 1];
      dp[H - i][W - k] %= MOD;
    }
  }

  cout << dp[0][0] << endl;

}


Measured memory_bytes: 12212
#include<iostream>
using namespace std;
int H;
int W;
int h;
int w;
int Sougou;
int ans;
int Kuro;
int main(){
  cin >> H;
  cin >> W;
  cin >> h;
  cin >> w;
  Sougou =H*W;
  Kuro=h*W+w*H-h*w;
  ans=Sougou-Kuro;
  cout << ans <<endl;
  }
  
  

Measured memory_bytes: 256
from collections import defaultdict

def C_Together():

    try:
        LOCAL_FLAG
        N = 3
        a = [6, 2, 6]
        # N = 4
        # numbers = [2, 5, 5, 2]
        N = 6
        a = [12, 22, 16, 22, 13, 12]

    except NameError:
        N = int(input())
        a = list(map(int, input().split()))

    counter = defaultdict(lambda: 0)
    for i in range(N):
        counter[a[i]] += 1

    results = 0
    key = -1

    for k, v in counter.items():
        temp = v + counter.get(k-1, 0) + counter.get(k+1, 0)
        if(temp > results):
            results = temp
            key = k

    print(results)
    

C_Together()

Measured memory_bytes: 14564
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define REP(i, n) for (ll i = 0; i < n; ++i)
#define rREP(i, n) for (ll i = n - 1; i >= 0; --i)
#define FOR(i, a, b) for (ll i = a; i <= b; ++i)
#define rFOR(i, a, b) for (ll i = a; i >= b; --i)
#define aFOR(i, V) for (auto i : V)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
#define INF 1'000'000'007 // 10^9 + 7
#define MOD 1'000'000'007 // 10^9 + 7
#define lINF 1'000'000'000'000'000'007 // 10^18 + 7
// ------------------------------

int main() {
    int N;
    cin >> N;
    ll a = 1, b = 1, c = 1, d = 1;
    REP(i, N) {
        a = a * 10 % MOD;
        b = b * 9 % MOD;
        c = c * 9 % MOD;
        d = d * 8 % MOD;
    }
    cout << ((a - b - c + d) % MOD + MOD) % MOD << endl;
    return 0;
}

Measured memory_bytes: 3632
#include <iostream>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <unordered_map>
#include <random>
#include <queue>
#include <iomanip>

#define BIG 1000000007
#define LLMAX 9223372036854775807
#define LLMIN (-9223372036854775808)
#define long long long

using namespace std;


int main(){
    long n,a,b,c,d;
    cin >> n >> a >> b >> c >> d;
    --a;
    --b;
    --c;
    --d;
    string s;
    cin >> s;

    for(long i = a;i < c;++i){
        if(s[i] == '#' && s[i + 1] == '#'){
            cout << "No" << endl;
            return 0;
        }
    }

    for(long i = b;i < d;++i){
        if(s[i] == '#' && s[i + 1] == '#'){
            cout << "No" << endl;
            return 0;
        }
    }

    if(c < d){
        cout << "Yes" << endl;
        return 0;
    }


    for(long i = b;i < d - 1;++i) {
        if(s[i] == '.'&&s[i + 1] == '.'&&s[i + 2] == '.'){
            cout << "Yes" << endl;
            return 0;
        }
    }

    if(s[b - 1] == '.' && s[b] == '.' && s[b + 1] == '.'){
        cout << "Yes" << endl;
        return 0;
    }

    if(s[d - 1] == '.' && s[d] == '.' && s[d + 1] == '.'){
        cout << "Yes" << endl;
        return 0;
    }

    cout << "No" << endl;
    return 0;
};







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

using namespace std;

#define ll long long 
#define ld long double
#define pii pair<int,int>
#define pll pair<ll,ll>
#define mkp make_pair
#define pb push_back
#define pf push_front
#define popb pop_back
#define popf pop_front
#define ff first
#define ss second
#define endl "\n"
#define MOD 1000000007
#define MOD1 998244353

ll GCD(ll x,ll y){if(y==0)return x;return GCD(y,x%y);}
ll LCM(ll x,ll y){return (x*y)/(GCD(x,y));}
ll LOGK(ll x,ll k){if(x>=k)return 1+LOGK(x/k,k);return 0;}
ll MPOW( ll a, ll b, ll m) { if(b==0) return 1; ll x=MPOW(a,b/2,m); x=(x*x)%m; if(b%2==1) x=(x*a)%m; return x;}
ll MINV(ll a,ll m) {return MPOW(a,m-2,m);}

class pnc{
  ll FACT_MAX,MODU;
  vector<ll> fact;
public:
  pnc( ll n, ll m) { FACT_MAX = n; fact.resize(FACT_MAX); MODU = m; MFACT_INIT(MODU);}
  void MFACT_INIT( ll m) { fact[0]=1; for(ll i=1;i<FACT_MAX;++i) fact[i]=(i*fact[i-1])%MODU;}
  ll MFACT( ll n) { return fact[n];}
  ll PERM( ll n, ll r) { return (fact[n]*::MINV(fact[n-r],MODU))%MODU;}
  ll COMB( ll n , ll r) { return (PERM(n,r)*::MINV(fact[r],MODU))%MODU;}
};

int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
    {
        ll n,m;
        cin>>n>>m;

        ll ar[n];
        ll total=0;

        for(ll i=0;i<n;i++)
        {
            cin>>ar[i];
            total+=ar[i];
        }

        ld no=(ld)total/((4.0)*m);

        ll flag=0;

        for(ll i=0;i<n;i++)
        {
            if((ld)ar[i]>=no)
            {
                flag++;
            }
        }

       if(flag>=m)
       cout<<"Yes";
       else
       {
           cout<<"No";
       }
       
    }
}

Measured memory_bytes: 256
import java.util.Scanner;
 
public class Main {
    public static void main(String args[]) {
        Scanner in = new Scanner(System.in);
        int a = in.nextInt();
        int b = in.nextInt();
        int c = in.nextInt();        
        if (a < b && b < c) System.out.println("Yes");
        else                System.out.println("No");

    }
}

Measured memory_bytes: 17160
#include <bits/stdc++.h>
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define fi first
#define se second
#define pb push_back
#define mk make_pair
using namespace std;
typedef long long ll;
typedef long double lld;
const ll INF = 1e18;
const ll MOD = 1e9+7;
 
ll fastpowMOD(ll a, ll p,ll MOD);
ll fastpowMOD(ll a, ll p,ll MOD){ if(p==0) return 1; a %= MOD; ll z = fastpowMOD(a,p/2,MOD); z = (z*z)%MOD; if(p%2) z = (z*a)%MOD; return z; }
 
ll lcm(ll a,ll b){
	return (a*b)/__gcd(a,b);
}

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

void solve(){
	ll n;
	cin>>n;
	vector< pair<ll,ll> > robot;
	
	for(ll i=0;i<n;i++){
		ll x,l;
		cin>>x>>l;
		robot.pb(mk(x+l,x-l));
	}
	
	sort(robot.begin(),robot.end());
	ll ans = 0;
	ll prev = INT_MIN;
	for(ll i=0;i<n;i++){
		if(robot[i].se>=prev){
			ans++;
			prev = robot[i].fi;
		}
	}
	cout<<ans<<"\n";
	
}



int main(){
    fastio;
    int t;
    t = 1;
    //cin>>t;
    
    for(int i=1;i<=t;i++)
	solve();
	
}




Measured memory_bytes: 5312
#include "bits/stdc++.h"
#pragma GCC optimize "03"
using namespace std;
 
#define int long long int
#define ld long double
#define pi pair<int, int>
#define pb push_back
#define fi first
#define se second
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
#ifndef LOCAL
#define endl '\n'
#endif
 
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
const int inf = 1e9 + 9;
 
signed main() {
    IOS;
    ld l;  cin >> l;
    l /= 3;
    cout << setprecision(10) << fixed << l*l*l;
    return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections;
using System.IO;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using System.Collections.Generic;
using System.Threading.Tasks;


class Program
{
	//Main
	static void Main(string[] args)
	{
		//読み込む
		string S = Console.ReadLine();
		long K = int.Parse(S);

		long ans = 0;

		//偶数の場合、-1となる
		if(K % 2 == 0){
			ans = -1;
		}
		//奇数の場合
		else{
			//n項目の余りがrのとき、n+1項目の余りは10r+7となる
			long rem = 7 % K;
			ans ++;

			//割り切れるまで試す
			while(rem != 0){
				rem = (10*rem + 7) % K;
				ans ++;

				//debug
				//Console.WriteLine("{0}:{1}", ans, rem);

				if(ans > 10000000){
					ans = -1;
					break;
				}
			}
		}
		//出力
		Console.WriteLine(ans);
	}
}



Measured memory_bytes: 17592
#include <iostream>
#include <algorithm>
#include <cstdlib>
#include <iostream>
#include <string>
#include <typeinfo>

using namespace std;

int div2(long long int x)
{
    int ans = 0;
    for (int i = 0; i < 31; i++)
    {
        if (x % 2 == 0)
        {
            ans += 1;
            x /= 2;
        }
        else
        {
            return ans;
        }
    }
    return ans;
}
int main()
{
    int n;
    cin >> n;
    long long int a[n];
    for (int i = 0; i < n; i++)
    {
        cin >> a[i];
    }
    int ans = 0;
    for (int i = 0; i < n; i++)
    {
        ans += div2(a[i]);
    }
    cout << ans;

    return 0;
}

Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
using namespace std;
int main(){
    string s;
    cin >> s;
    int n = s.length();
    int countera = 0;
    int counterb = 0;

    for(int i = 0; i < n; i++){
        if(i == 0 && s[i] != '1') countera++;
        else if(i%2 == 0 && s[i] != '1') countera++;
        else if (i%2 == 1 && s[i] != '0') countera++;
    }

    for(int i = 0; i < n; i++){
        if(i == 0 && s[i] != '0') counterb++;
        else if(i%2 == 0 && s[i] != '0') counterb++;
        else if(i%2 == 1 && s[i] != '1') counterb++;
    }

    if(countera > counterb) cout << counterb << endl;
    else cout << countera << endl;
}

Measured memory_bytes: 512
import math
x = int(input())
flag = 0
out = 0

for i in range(100000):
  t = x + i
  tr = int(math.sqrt(t)) + 1
  for j in range(2, tr):
    if t % j == 0:
      flag = 1
      break
  if flag == 0:
    out = t
    break
  else:
    flag = 0

if flag == 1:
  if x == 2 or x == 3 or x == 5 or x == 7:
    out = t
print(out)

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

const int MOD = 1e9+7;
int add(int a, int b){return ((ll)a + (ll)b)%MOD;}
int mul(int a, int b){return ((ll)a * (ll)b)%MOD;}

void solve(){
  int a, b, c, d;
  cin >> a >> b >> c >> d;
  while(true){
    c -= b;
    if(c <= 0){
      cout << "Yes" << '\n';
      return;
    }
    a -= d;
    if(a <= 0){
      cout << "No" << '\n';
      return;
    }
  }
  }

int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  solve();
  return 0;
}


Measured memory_bytes: 3656
/*我是萌新*/
#include<iostream>
#include<cmath>
#include<cstring>
#include<string>
#include<algorithm>
#include <iomanip>
#include<map>
typedef long long ll;
const int mod = 1e9 + 7;
using namespace std;
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; }
//fixed<< setprecision(2)
int main()
{
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll n, k;
    while (cin >> n >> k)
    {
        ll* p = new ll[n + 5],*pp=new ll[n+5];
        for (int i = 1; i <= n; i++)cin >> p[i],pp[i]=0;

        
        ll a = 1;
        while (k--)
        {
            pp[a]++;
            
            a = p[a];
            if (k <= 0) { cout << a << '\n'; return 0; }
            if (pp[a] >= 2)break;

            
        }
        
        ll res = 0;
        ll b = a;
        while (k--)
        {
            b = p[b];
            res++;
            if (k <= 0) { cout << b << '\n'; return 0; }
            if (p[b] == p[a])break;
        }

        k = k % res;

        while (k--)
        {
            b = p[b];
        }



        cout << b << '\n';
    }
}

Measured memory_bytes: 6328
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,N) for(int i=0;i<int(N);++i)
#define rep1(i,N) for(int i=1;i<int(N);++i)
#define all(a) (a).begin(),(a).end()
#define bit(k) (1LL<<(k))
#define SUM(v) accumulate(all(v), 0LL)

typedef pair<int, int> i_i;
typedef pair<ll, ll> l_l;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
struct fast_ios{ fast_ios(){ cin.tie(0); ios::sync_with_stdio(false); cout << fixed << setprecision(20); }; }fast_ios_;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

#define TOSTRING(x) string(#x)
template <typename T> istream &operator>>(istream &is, vector<T> &vec) { for (T &x : vec) is >> x; return is; }
template <typename T> ostream &operator<<(ostream &os, const vector<T> &v) { os  << "["; for(auto _: v) os << _ << ", "; os << "]"; return os; };
template <typename T> ostream &operator<<(ostream &os, set<T> &st) { os << "("; for(auto _: st) { os << _ << ", "; } os << ")";return os;}
template <typename T, typename U> ostream &operator<<(ostream &os, const pair< T, U >& p){os << "{" <<p.first << ", " << p.second << "}";return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const map<T, U> &mp){ os << "["; for(auto _: mp){ os << _ << ", "; } os << "]" << endl; return os; }

#define DUMPOUT cerr
void dump_func(){ DUMPOUT << endl; }
template <class Head, class... Tail> void dump_func(Head &&head, Tail &&... tail) { DUMPOUT << head; if (sizeof...(Tail) > 0) { DUMPOUT << ", "; } dump_func(std::move(tail)...); }

#ifdef DEBUG
#define dbg(...) dump_func(__VA_ARGS__)
#define dump(...) DUMPOUT << string(#__VA_ARGS__) << ": "; dump_func(__VA_ARGS__)
#else
#define dbg(...)
#define dump(...)
#endif

const int INF = (ll)1e9;
const ll INFLL = (ll)1e18+1;
const ll MOD = 1000000007;
// const ll MOD = 998244353;
const long double PI = acos(-1.0);

/*
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
const string dir = "DRUL";
*/


int main() {
    string s, t;
    cin >> s >> t;
    sort(all(t), greater<>());
    sort(all(s));
    dump(s, t);
    cout << (s < t ? "Yes" : "No") << endl;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef pair<ll, P> P3;
typedef pair<P ,P> PP;
constexpr ll MOD = ll(1e9) + 7;
constexpr int IINF = INT_MAX;
constexpr ll LLINF = LLONG_MAX;
constexpr int MAX_N = int(1e5) + 5;
constexpr double EPS = 1e-8;
constexpr int di[] = {0, 1, 0, -1}, dj[] = {1, 0, -1, 0};
#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 SORTR(v) sort((v).rbegin(), (v).rend())
#define ALL(v) (v).begin(), (v).end()


int main() {
    int k;
    vector<int> dmin;
    cin >> k;
    // bfs
    priority_queue<P, vector<P>, greater<P> > que;
    que.push({1,1});
    dmin.assign(k,IINF);
    dmin[1] = 1;
    while(!que.empty()){
        P p = que.top();
        int now = p.second, d = p.first;
        que.pop();
        if(dmin[now] < d)continue;
        if(dmin[now*10%k] > d){
            dmin[now*10%k] = d;
            que.push({d, now*10%k});
        }
        if(dmin[(now+1)%k] > d + 1){
            dmin[(now+1)%k] = d + 1;
            que.push({dmin[(now+1)%k],(now+1)%k});
        }
    }
    cout << dmin[0] << endl;
    return 0;
}


Measured memory_bytes: 1784
#設定
import sys
input = sys.stdin.buffer.readline

#ライブラリインポート
from collections import defaultdict

#入力受け取り
def getlist():
	return list(map(int, input().split()))

#処理内容
def main():
	N = int(input())
	P = getlist()
	S = [0] * N
	S[0] = P[0]
	for i in range(1, N):
		S[i] = min(S[i - 1], P[i])
	# print(S)
	ans = 0
	for i in range(N):
		if S[i] >= P[i]:
			ans += 1
	print(ans)
	
if __name__ == '__main__':
	main()

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

int main() {
  string s;
  cin >> s;
  int x = 0;
  for(int i=0;i<3;i++){
    if(s.at(i) == 'o'){
      x++;
    }
  }
  
  cout << 700 + 100*x << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using Graph = vector<vector<pii>>;
const int MOD = 1e9 + 7;

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

    int N;
    cin >> N;

    vector<bool> isprime(1305, true);
    isprime[0] = isprime[1] = false;
    for (int i = 2; i * i <= 1300; ++i)
        for (int j = 2; i * j <= 1300; ++j)
            if (isprime[i * j])
                isprime[i * j] = false;

    int cnt = 0;
    for (int i = 0; i <= 1300; ++i) {
        if (isprime[i] && i % 5 == 2) {
            cout << i << " ";
            cnt++;
        }
        if (cnt >= N) {
            cout << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 256
//A.cpp
#include <iostream>
#include <string>
#include <algorithm>
#include <set>
#include <map>
#include <vector>
#include <queue>
#include <stack>
#include <math.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;
ll gcd(ll a,ll b){return b!=0?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a*b/gcd(a,b);}
const ll mod=1e9+7;

int main(){
  int k,n;
  cin >> n >> k;
  double p[n+1];
  p[0] = 0.0;
  double a;
  for(int i = 1; i < n+1; i++){
    cin >> a;
    p[i] = p[i-1] + a + 1;
    // printf("%lf\n", p[i]);
  }
  double ans = 0;
  for(int i = 0; i <= n-k; i++){
    ans = max(ans,p[k+i]-p[i]);
  }
  printf("%lf\n", ans/2 );
  return 0;
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <vector>
#include <math.h>
#include <set>
#include <map>
#include <string>
#include <stack>
#include <queue>
#include <iomanip>
#include <numeric>
#include <tuple>
#include <bitset>
#include <complex>
#include <deque>
#include <unistd.h>
#define _USE_MATH_DEFINES
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef complex<double> xy_t;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
double pi = 3.141592653589793;
ll mod = 1000000007;
int intmax = 2147483647;
int intmin = -2147483648;
ll llmax = 9223372036854775807;
ll llmin = -9223372036854775807;
ll inf = llmax / 2;
double eps = 1e-11;

struct edge {
    int to, cost;
};

int V;
vector<edge> G[1000000];
ll d[1000000];

void BFS01(int n) {
    fill(d, d + V, llmax);
    deque<int> que;
    d[n] = 0;
    que.push_front(n);
    while (que.size() > 0) {
        int base = que.front();
        que.pop_front();
        int s = G[base].size();
        for (int i = 0; i < s; i++) {
            edge e = G[base][i];
            if (e.cost == 1 && d[e.to] > d[base] + 1) {
                d[e.to] = d[base] + 1;
                que.push_back(e.to);
            } else if (e.cost == 0 && d[e.to] > d[base]) {
                d[e.to] = d[base];
                que.push_front(e.to);
            }
        }
    }
}

int main() {
    ll K;
    cin >> K;
    V = K;
    for (int i = 0; i < K; i++) {
        edge e;
        e.to = (i * 10) % K;
        e.cost = 0;
        G[i].push_back(e);
        edge e2;
        e2.to = (i + 1) % K;
        e2.cost = 1;
        G[i].push_back(e2);
    }
    BFS01(1);
    ll ans = d[0] + 1;
    cout << ans << endl;
}


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

typedef long long ll;
#define vec vector<int>
#define vecll vector<ll>
#define vpair vector<pair<int, int>>
#define vpairll vector<pair<ll, ll>>
#define rep(i,n)   for(int i=(int)0; i<(int)n; i++)
#define llrep(i,n)   for(ll i=(ll)0; i<(ll)n; i++)
#define REP(i,m,n) for(int i=(int)m; i<(int)n; i++)
#define all(var)     (var).begin(), (var).end()
#define prt(var)     cout << var << endl
#define prt_dbl(i,var) cout<<fixed<<setprecision(i)<<var<<endl;
template <typename Val>
Val gcd(Val a, Val b) {
//use ll or int for gcd
    if (b==0) return a;
    else return gcd(b, a%b);
}
template <typename Val>
Val vec_max(vector<Val> v){
  return *max_element(v.begin(),v.end());
}
template <typename Val>
Val vec_min(vector<Val> v){
  return *min_element(v.begin(),v.end());
}
//---------------------------------------------------------------
int main(){
  int K;
  string S;
  cin>>K>>S;
  int R = S.size();
   R = min(K,R);
  rep(i,R){
    cout<<S.at(i);
  }
  if(K<S.size()){
    cout<<"..."<<endl;
  }else cout<<endl;




}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n;
  cin>>n;
  int a[n];
  int min1=INT_MAX;
  for(int i=0;i<n;i++)
    cin>>a[i];
  int sum1=0,sum2=0;
  for(int i=0;i<n;i++)
  {  
     sum1=0,sum2=0;
    for(int j=i+1;j<n;j++)
    {
      sum1=sum1+a[j];
    }
    for(int k=0;k<=i;k++)
    {
      sum2=sum2+a[k];
    }
    min1=min(min1,abs(sum1-sum2));
  }
  
  cout<<min1;
  

}


Measured memory_bytes: 256
def solve_f(n, g):
    e_base = [0.0] * (n + 1)
    p_base = [0.0] * (n + 1)

    # e_base
    for i in range(n - 1, 0, -1):
        e_base[i] = sum([e_base[j] for j in g[i]]) / len(g[i]) + 1.0

    # p_base
    p_base[1] = 1.0
    for i in range(1, n):
        for j in g[i]:
            p_base[j] += p_base[i] / len(g[i])

    # print(p_base, e_base)

    # find maximal gap
    gap = 0.0
    for i in range(1, n):
        if len(g[i]) == 1:
            continue
        total = sum([e_base[j] + 1 for j in g[i]])
        maxim = max([e_base[j] + 1 for j in g[i]])
        gap_i = (total / len(g[i]) - (total - maxim) / (len(g[i]) - 1)) * p_base[i]
        gap = max(gap_i, gap)

    return e_base[1] - gap


def main():
    # input
    n, m = map(int, input().split())
    g = [[] for _ in range(n)]
    for _ in range(m):
        s, t = map(int, input().split())
        g[s].append(t)
    res = solve_f(n, g)
    print(res)


def test():
    assert abs(solve_f(4, [[], [2, 3, 4], [3, 4], [4]]) - 1.5) < 0.000001
    assert abs(solve_f(3, [[], [2], [3]]) - 2.0) < 0.000001


if __name__ == "__main__":
    test()
    main()


Measured memory_bytes: 9420
#include <bits/stdc++.h>
using namespace std;
 
int main(void)
{
    string s;
    cin >> s;
    
    int count = 0;
    int cMax = 0;
    for (int i = 0; i < 3; ++i){
        if(s[i] == 'R'){
            ++count;
            if(cMax < count) cMax = count;
        }else{
            count = 0;
        }
    }
    cout << cMax << endl;
}

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

using namespace std;

#define MAXN 50000

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

	long long n, i, j, k, x, y, best, s, id;
	long double c, ans;
	vector<pair<long double, pair<long long, long long>>> plist;

	cin >> n;
	for (i = 0; i < n; i++) {
		cin >> x >> y;
		if ((x != 0) || (y != 0)) {
			c = atan2(y, x);
			plist.push_back({ c, {x, y} });
		}
	}
	n = plist.size();
	sort(plist.begin(), plist.end());

	best = 0;
	for (i = 0; i < n; i++) {
		x = 0; y = 0;
		for (j = 0; j < n; j++) {
			id = (i + j) % n;
			x += plist[id].second.first;
			y += plist[id].second.second;

			best = max(best, x * x + y * y);
		}
	}

	ans = sqrt(best * 1.0);
	cout << setprecision(20) << fixed << ans << "\n";

	return 0;
}


Measured memory_bytes: 640
#include<cstdio>
#include<iostream>
using namespace std;
int main(void){
  char a,b;
  scanf("%c %c",&a,&b);
  if(a>b){
    cout<<'>'<<endl;
  }else if(a==b){
    cout<<'='<<endl;
  }else{
    cout<<'<'<<endl;
  }
  return 0;
}
  

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

using ll = long long;
using ull = unsigned long long;
using ld = long double;

#define MOD 1000000007

#define rep(i, n) for(ll (i) = 0LL;(i) < (ll)(n);(i)++)
#define rep2(i, s, e) for(ll (i) = (ll)(s);(i) < (ll)(e);(i)++)
#define repi(i, n) for(ll (i) = 0LL;(i) <= (ll)(n);(i)++)
#define repi2(i, s, e) for(ll (i) = (ll)(s);(i) <= (ll)(e);(i)++)
#define per(i, n) for(ll (i) = (ll)(n) - 1LL;(i) >= 0LL;(i)--)
#define per2(i, s, e) for(ll (i) = (ll)(s) - 1LL;(i) >= (ll)(e);(i)--)
#define peri(i, n) for(ll (i) = (ll)(n);(i) >= 0LL;(i)--)
#define peri2(i, s, e) for(ll (i) = (ll)(s);(i) >= (ll)(e);(i)--)
#define iter(i, it) for(auto &(i): (it))

template<typename T, typename U> ostream& operator<<(ostream &s, const pair<T, U> m) {
    cout << "(" << m.first << ", " << m.second << ")";
    return s;
}
template<typename T, typename U> ostream& operator<<(ostream &s, const map<T, U> m) {
    ll c = 0;
    cout << "{ ";
    iter(i, m) cout << i << (c++ == m.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
    cout << "{ ";
    rep(i, v.size()) cout << v[i] << (i == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}
template<typename T> ostream& operator<<(ostream &s, const list<T> &v) {
    ll c = 0;
    cout << "{ ";
    iter(i, v) cout << i << (c++ == v.size() - 1 ? " " : ", ");
    cout << "}";
    return s;
}

int main(void) {
    ll a, b, x;
    ll A, B;
    ll count;
    cin >> a >> b >> x;
    A = a / x;
    B = b / x;
    count = B - A + 1;
    if(A * x < a) count--;
    if(B * x > b) count--;
    cout << count << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  int n,m,k;
  cin>>n>>m>>k;
  int kuro;
  string ans = "No";
  rep(i, n + 1) {
    rep(j, m + 1) {
      kuro = m * i + n * j - i * j * 2;
      if(kuro == k) {
        ans = "Yes";
      }
    }
  }
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
#include<stdio.h>
#include <string.h>
int main(void)
{
  char s[4];
  char x[4]="abc";
  scanf("%s",s);
  int n,m;
  
  
  for(n=0;n<3;n++)
  {
    for(m=0;m<3;m++)
    {
      if(s[m]==x[n])
        x[n]='o';
    }
        
  }
  if(strcmp(x,"ooo")==0)
    printf("Yes");
  else printf("No");
    
  
  return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
int main() 
{ 
int x,y,a,b;
int sum=0;
for(int i=1;i<=1000;i++)
{
cin >> x >> y;
if(x!=0)
{
if(x<3)
{cout << 0 << endl;}
else if (y<6)
{cout << 0 << endl;}
if(y%3!=0)
{
if(x<=(y/3+1))
{cout << 0 << endl;}
}
else if(y%3==0)
{
if(x<=(y/3))
{cout << 0 << endl;}
}
for(int i=1;i<=y/3-1;i++) 
{b=(y-2*i-1);
if((y-2*i-1)<x)
{x=b;}
a=x-(y-i)/2;
if(a<=0)
{a=0;}
sum=sum+a;
}
if(sum!=0)
{
cout << sum << endl;
}
sum=0;
}
}
}


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

using namespace std;

vector<int> a;

int main() {
  int ans_sum = 10000;
  
  for (int i = 0; i < 5; i++) {
    int _in;
    
    cin >> _in;
    
    a.push_back(_in);
  }
  
  vector<int> P{ 0, 1, 2, 3, 4 };
  
  do {
    int sum = 0;
    for (int i = 0; i < 5; i++) {
      if (i == 4) {
        sum += a[P[i]];
      } else {
        sum += a[P[i]] % 10 == 0 ? a[P[i]] : a[P[i]] + 10 - (a[P[i]] % 10);
      }
    }
    
    ans_sum = min(ans_sum, sum);
  } while (next_permutation(P.begin(), P.end()));
  
  cout << ans_sum << endl;
  
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define INF 1e9+7
#define ll long long
#define f(x) for(ull i=0;i<x;i++)
#define F first
#define S second
#define N 100005
#define M 1000000007
#define mp make_pair
#define ull unsigned long long
#define sc(n) scanf("%d",&n)
#define gcd __gcd
using namespace std;

int main() {
	ios::sync_with_stdio(false);
	ll n,k=1;
    cin>>n;
    for(int i=n;i>0;i--){
        k=(k*i)%M;
    }
    cout<<k<<endl;
    return 0;
}


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

#define ll long long

int main(){
    int n,k,a[1001];
    cin >> n >> k;
    for(int i=0; i<n; ++i){
        cin >> a[i];
    }
    sort(a,a+n);
    int sum=0;
    for(int i=0; i<k; ++i){
        sum+=a[i];
    }
    cout << sum;
}


Measured memory_bytes: 3652
#include <bits/stdc++.h>
using namespace std;
static const int MAX = 100000;
static const int INFTY = (1<<29);

vector<int> G[MAX];
list<int> out;
bool V[MAX];
int N;
int indeg[MAX];

void bfs(int s) {
	queue<int> q;
	q.push(s);
	V[s] = true;
	while (!q.empty()) {
		int u = q.front(); q.pop();
		out.push_back(u);
		for ( int i = 0; i < G[u].size(); i++) {
			int v = G[u][i];
			indeg[v]--;
			if( indeg[v] == 0 && !V[v]) {
				V[v] = true;
				q.push(v);
			}
		}
	}
}

void tsort() {
	for(int i = 0; i< N;i++) {
		indeg[i] = 0;
	}

	for(int u =0; u< N; u++) {
		for ( int i =0; i < G[u].size(); i++) {
			int v = G[u][i];
			indeg[v]++;
		}
	}

	for ( int u = 0; u < N; u++) {
		if( indeg[u] == 0 && !V[u]) bfs(u);
	}
	for (list<int>::iterator it = out.begin(); it != out.end(); it++) {
		cout << *it << endl;
	}
}

int main(){
	int s, t, M;
	cin >> N >> M;
	for (int i = 0; i < N; i ++) V[i] = false;
	for ( int i = 0; i < M; i++) {
		cin >> s >> t;
		G[s].push_back(t);
	}

	tsort();
	return 0;
}



Measured memory_bytes: 6252