akhauriyash/Code-Regression huggingface dataset:
#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;
using P = pair<int, int>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, -1, 0, 1};
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;
  }
}
struct edge {
  ll to, cost;
};

int main() {
  int D; cin >> D;
  vector<int> c(26); REP(i, 26) cin >> c[i];
  vector<vector<int>> s(D, vector<int>(26));
  REP(i, D) {
    REP(k, 26) {
      cin >> s[i][k];
    }
  }
  vector<int> t(D); REP(i, D) cin >> t[i];
  ll ans = 0;
  vector<int> last(27, 0);
  REP(i, D) {
    ans += s[i][t[i] - 1];
    last[t[i]] = i + 1;
    ll tmp = 0;
    for(int k = 1; k < 27; ++k) {
      tmp += (c[k - 1] * ((i + 1) - last[k]));
    }
    ans -= tmp;
    cout << ans << endl;
  }
}

Measured memory_bytes: 3648
#define _CRT_SECURE_NO_WARNINGS
#include "bits/stdc++.h"
#include <string>
using namespace std;

//宣言
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;

//数値
#define MOD 1000000007
#define INF (1<<20)
const double EPS = 1e-10;
const double PI = acos(-1.0);

//操作
#define FOR(i,a,b) for(int i=a;i<b;++i)
#define REP(i,n) FOR(i,0,n)
#define REPB(i,n) for(int i=n;i>=0;--i)
#define SORT(A) sort(A,A+sizeof(A)/sizeof(A[0]))
#define VSORT(A) sort(A.begin(),A.end())
#define EXIST(s,e) (s.find(e)!=s.end())
#define PB push_back
#define MP make_pair
#define Int(x) int x; scanf("%lld", &x);
#define int2(x, y) int x, y; scanf("%lld %lld", &x, &y);

//DEBUG
//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

ll gcd(ll a,ll b) {
	if (a < b) swap(a, b);
	while (b > 0) {
		ll r = a%b;
		a = b;
		b = r;
	}
	return a;
}

int main() {
	ll a, b; cin >> a >> b;
	if (a < 0 && b>0 || a == 0 || b == 0) cout << "Zero" << endl;
	else if (a > 0) cout << "Positive" << endl;
	else {
		if ((b - a) % 2) cout << "Positive" << endl;
		else cout << "Negative" << endl;
	}
}


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

#define ll long long int

int dp[100100];
int longest(vector<int> v[], int i)
{
	if(v[i].size() == 0)
		return 0;
	if(dp[i] >= 0)
		return dp[i];
	else
	{
		for (auto e : v[i])
		{
			dp[i] = max(dp[i], 1 + longest(v, e));
		}
		return dp[i];
	}
}

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	int n, m, x, y;
	cin >> n >> m;
	vector<int> v[n+1];
	for (int i = 0; i <= n ; ++i)
	{
		dp[i] = -1;	
	}
	for (int i = 1; i <= m; ++i)
	{
		cin >> x >> y;
		v[x].push_back(y);
	}
	int k = 0;
	for (int i = 1; i <= n; ++i)
	{
		k  = max(k, longest(v, i));
	}
	cout << k << "\n";
	return 0;
}

Measured memory_bytes: 8192
#include<bits/stdc++.h>
#include<set>
#define lli long long int
using namespace std;
int main()
{
	lli  n;
	cin>>n;
	if(n>=400&&n<=599)
	cout<<"8";
	if(n>=600&&n<=799)
	cout<<"7";
	if(n>=800&&n<=999)
	cout<<"6";
	if(n>=1000&&n<=1199)
	cout<<"5";
	if(n>=1200&&n<=1399)
	cout<<"4";
	if(n>=1400&&n<=1599)
	cout<<"3";
	if(n>=1600&&n<=1799)
	cout<<"2";
	if(n>=1800&&n<=1999)
	cout<<"1";
	return 0;
}

Measured memory_bytes: 3524
#include <iostream>
#include <string.h>
#include <cstring>

using namespace std;
int main()
{
	char s[20],a[2]={" "};
	
	cin.getline(s,20);
	for(int i=0;i<20;i++)
	{
	if( i == 5 || i == 13)
	{
		s[5]=a[0];
		s[13]=a[0];
	}
	}
	cout<<s<<endl;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		char[] S = sc.next().toCharArray();
		char[] T = sc.next().toCharArray();
		sc.close();

		int max = 0;
		for (int i = 0; i <= S.length - T.length; i++) {
			int cnt = 0;
			for (int j = 0; j < T.length; j++) {
				if (S[i + j] == T[j]) {
					cnt++;
				}
			}
			max = Math.max(max, cnt);
		}

		System.out.println(T.length - max);
	}
}


Measured memory_bytes: 35624
n, k = map(int, input().split())
mod = 10 ** 9 + 7

cnt = 0
L, R = 0, 0
for i in range(k-1):
    L += i
    R += n - i

for i in range(k-1, n+1):
    L += i
    R += n - i
    cnt += R - L + 1
print(cnt%mod)


Measured memory_bytes: 9184
package main

import (
	"bufio"
	"fmt"
	"os"
)

func main() {
	n := ReadInt()
	a := ReadInts(n + 1)

	m := make(map[int]int)
	var l, r int
	for i := 0; i < n+1; i++ {
		if j, exists := m[a[i]]; exists {
			l = j
			r = i
			break
		}
		m[a[i]] = i
	}

	for k := 1; k <= n+1; k++ {
		ans := ModCombination(n+1, k)
		if l+n-r >= k-1 {
			ans = ans + Mod - ModCombination(l+n-r, k-1)
			ans %= Mod
		}
		fmt.Println(ans)
	}
}

const Mod = int(1e9) + 7

func ModFactorial(n int) int      { return fac[n] }
func ModPermutation(n, r int) int { return fac[n] * finv[n-r] % Mod }
func ModCombination(n, k int) int { return fac[n] * (finv[k] * finv[n-k] % Mod) % Mod }

var fac, finv, inv []int

func init() {
	const MAX = 5 * 1e5
	fac, finv, inv = make([]int, MAX+1), make([]int, MAX+1), make([]int, MAX+1)
	fac[0], fac[1], finv[0], finv[1], inv[1] = 1, 1, 1, 1, 1
	for i := 2; i <= MAX; i++ {
		fac[i] = fac[i-1] * i % Mod
		inv[i] = Mod - inv[Mod%i]*(Mod/i)%Mod
		finv[i] = finv[i-1] * inv[i] % Mod
	}
}

var reader = bufio.NewReader(os.Stdin)

func Scan(a ...interface{}) {
	if _, err := fmt.Fscan(reader, a...); err != nil {
		panic(err)
	}
}
func ReadInt() (i int)       { Scan(&i); return }
func ReadString() (s string) { Scan(&s); return }
func ReadInts(n int) []int {
	v := make([]int, n)
	for i := 0; i < n; i++ {
		Scan(&v[i])
	}
	return v
}


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

using namespace std;

#define int long long
#define MOD 1000000007

#define FOR(i, a, b) for (int i = (a); i < (b); i++)
#define RFOR(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep1(i, n) for (int i = 1; i < (n); i++)
#define rrep(i, n) for (int i = (n)-1; i >= 0; i--)
#define all(i) (i).begin(), (i).end()
#define rall(i) (i).begin(), (i).end(), greater<int>()

#define elif else if
#define eb emplace_back
#define pb push_back
#define mp make_pair
#define fst first
#define sec second
template <typename T>
void print(T x)
{
    std::cout << x << '\n';
}

//typedef long long ll;
#define TENNINE 1000000005
#define TENFIVE 100005
//#define int long long

int n;
vector<int> h;

signed main()
{
    cin >> n;
    h.resize(n);
    rep(i, n)
    {
        cin >> h[i];
    }

    int temp = 0;

    if (n == 1)
    {
        cout << "Yes" << endl;
        return 0;
    }

    rep(i, n - 1)
    {
        int j = n - 1 - i;

        if (h[j - 1] > h[j])
        {
            if ((h[j - 1] - h[j]) == 1)
            {
                h[j - 1]--;
            }
            else
            {
                cout << "No" << endl;
                return 0;
            }
        }
    }

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


Measured memory_bytes: 1024
#! /usr/bin/env python3

n = int(input())
a = [int(input()) for _ in range(n)]

res = 0
for i in range(n):

    if a[i] > i:
        res = -1
        break
    
    if i > 0:
        if a[i] - a[i-1] > 1:
            res = -1
            break
        elif a[i] - a[i-1] != 1:
            res += a[i-1]

    if i == n - 1:
        res += a[i]

print(res)


Measured memory_bytes: 11052
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <algorithm>
#include <climits>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, k;
    cin >> n >> k;
    VL x(n);
    int zero_index = -1;
    REP(i, n) {
        cin >> x[i];
        if(x[i] < 0) {
            x[i] *= -1;
            zero_index = i;
        }
    }
    zero_index++;

    ll ans = LONG_MAX;
    FOR(neg_cnt, 1, zero_index) {
        int pos_cnt = k - neg_cnt;
        if(pos_cnt <= 0 or zero_index + pos_cnt - 1 >= n) continue;
        ans = min(ans, x[zero_index - neg_cnt] * 2 + x[zero_index + pos_cnt - 1]);
        ans = min(ans, x[zero_index - neg_cnt] + x[zero_index + pos_cnt - 1] * 2);
    }
    if(zero_index + k - 1 < n) ans = min(ans, x[zero_index + k - 1]);
    if(zero_index - k >= 0) ans = min(ans, x[zero_index - k]);

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
char c;
int main(){
    
    c=getchar();
    if(c=='a'||c=='e'||c=='i'||c=='o'||c=='u') {cout<<"vowel"<<endl; return 0;}
    cout<<"consonant"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
ll x,y,m;
P p[300005];
ll ans;
ll Y[300005],X[300005];
ll mx,my;
int main(void){
    cin>>x>>y>>m;
    for(ll i=0;i<m;i++){
        cin>>p[i].first>>p[i].second;
        X[p[i].first]++;
        Y[p[i].second]++;
    }
    sort(p,p+m);
    for(ll i=1;i<=x;i++){
        mx=max(X[i],mx);
    }
    for(ll i=1;i<=y;i++){
        my=max(Y[i],my);
    }
    vector<ll> a;
    for(ll i=1;i<=y;i++){
        if(Y[i]==my){
            a.push_back(i);
        }
    }
    for(ll i=1;i<=x;i++){
        if(X[i]==mx){
            for(ll j=0;j<a.size();j++){
                if(upper_bound(p,p+m,make_pair(i,a[j]))-lower_bound(p,p+m,make_pair(i,a[j]))==0){
                    cout<<mx+my<<endl;
                    return 0;
                }
            }
        }
    }
    cout<<mx+my-1<<endl;

}



Measured memory_bytes: 16728
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define __ ios_base::sync_with_stdio(0);cin.tie(0);
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define forn(i,a,n) for(int i=a; i < n; i++)
typedef long long int lli;
typedef long double Double;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
#define MAXN 3005
const int mod = 998244353;
lli dp[MAXN][MAXN];
int a[MAXN];

lli powmod(lli a, lli b){
	lli ans = 1ll;
	while(b){
		if(b&1) ans = (ans * a)%mod;
		b>>=1ll;
		a = (a * a) % mod;
	}
	return ans%mod;
}

lli inv(lli x){
	return powmod(x,mod-2) % mod;
}

int main(){__
	int n,s;
	cin >> n >> s;
	for(int i=1; i <=n; i++) cin >> a[i];

	dp[0][0] = powmod(2,n);

	lli dos = inv(2ll);
	for(int i =1; i <=n; i++){
		for(int j=0; j <= s; j++){
			dp[i][j]=(dp[i-1][j])%mod;
			if(j - a[i] >= 0){
				dp[i][j] = (dp[i][j] + (dp[i-1][j-a[i]] * dos)%mod)%mod;
			}
		}
	}

	cout << dp[n][s]%mod << endl;
	return 0;
}


Measured memory_bytes: 74068
//~ while (clock()<=69*CLOCKS_PER_SEC)
//~ #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//~ #pragma GCC target ("avx2")
//~ #pragma GCC optimize("Ofast")
//~ #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//~ #pragma GCC optimize("unroll-loops")
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;

template <typename T>
using ordered_set =
    tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "

#define shandom_ruffle random_shuffle

using ll=long long;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
using vi=vector<int>;
using vll=vector<ll>;
const int nax=1000*1007;
const ll mod=1000*1000*1000+7;
const ll inf=1e18;

int n;

ll h[nax];
ll a[nax];

ll drz[nax];

ll wyn;

ll czyt(int v)
{
	ll ret=0;
	for (int i=v; i; i-=(i&(-i)))
		ret=max(ret, drz[i]);
	return ret;
}

void pisz(int v, ll w)
{
	for (int i=v; i<=n; i+=(i&(-i)))
		drz[i]=max(drz[i], w);
}

int main()
{
	scanf("%d", &n);
	for (int i=1; i<=n; i++)
		scanf("%lld", &h[i]);
	for (int i=1; i<=n; i++)
		scanf("%lld", &a[i]);
	for (int i=1; i<=n; i++)
	{
		ll x=czyt(h[i])+a[i];
		wyn=max(wyn, x);
		pisz(h[i], x);
	}
	printf("%lld\n", wyn);
	return 0;
}


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

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

	int time = stoi(t);
	
	int h = time / 3600;
	int m = (time % 3600) / 60;
	int s = (time % 3600) % 60;

	cout << h << ":" << m << ":" << s << endl;
}



Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
#define pb push_back
#define mp make_pair
#define ll long long
#define x first
#define y second
#define sz(a) ((int)(a.size()))
#define OTIMIZA 2
#define INSERE 1
#define REMOVE 0
#define move aslzxc

int main()
{
	int k;
	cin >> k;
	set<ll> all;
	for(int i = 1; i <= 9; i++)
	{
		all.insert(i);
	}
	ll res;
	while(k--)
	{
		ll x = *all.begin();
		res = x;
		all.erase(all.begin());
		int lst = x % 10;
		for(int j = max(0 , lst - 1); j <= min(9 , lst + 1); j++)
			all.insert(x * 10 + j);
	}
	cout << res << endl;
}


Measured memory_bytes: 9216
import java.util.Scanner;

public class Main{
	private static final Scanner s=new Scanner(System.in);
	public static void main(String[] args){
		int n=s.nextInt(),a[]=new int[n];
		for(int i=0;i<n;i++)
			a[s.nextInt()]++;
		
		if(n%2==0) {
			for(int i=1;i<n;i+=2) {
				if(a[i]!=2) {
					System.out.println(0);
					return;
				}
			}
			int r=1;
			for(int i=n/2;i>0;i--) {
				r*=2;
				r%=1000000007;
			}
			System.out.println(r);
		}else {
			if(a[0]!=1) {
				System.out.println(0);
				return;
			}
			for(int i=2;i<n;i+=2) {
				if(a[i]!=2) {
					System.out.println(0);
					return;
				}
			}
			int r=1;
			for(int i=n/2;i>0;i--) {
				r*=2;
				r%=1000000007;
			}
			System.out.println(r);
		}
	}
}


Measured memory_bytes: 50900
n,k=map(int,input().split())
a=list(map(int,input().split()))
a.sort()
j=n-1
s=0
for i in range(k):
    a[j]=0
    j=j-1
    if(j<0):
        break
for i in range(n):
    s=s+a[i]
print(s)

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

int main() {
  int n;
  cin >> n;
  vector<int> a(n);

  rep(i,n) cin >> a[i];
  bool ok=true;
  rep(i,n) {
    if(a[i]%2 == 1) continue;
    if(a[i]%3!=0 && a[i]%5!=0) ok=false;
  }
  if (ok) cout<<"APPROVED"<<endl;
  else cout<<"DENIED"<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<map>
#include<list>
#include<vector>
#include<unordered_map>
#define int long long
using namespace std;

int a[200000];
int r[200000];
int c[100000];
signed main() {
	int K = 0;
	int n, m; cin >> n >> m;
	for (int i = 0; i < n; i++) {
		scanf("%lld", &a[i]);
	}
	for (int i = 1; i < n; i++) {
		int x = a[i - 1], y = a[i];
		if (x > y)y += m;
		K += y - x;
		r[x + 1]++;
		r[y]--;
	}
	int sum = 0;
	for (int i = 0; i < m*2; i++) {
		sum += r[i];
		r[i] = sum;
	}
	for (int i = 1; i < n; i++) {
		int x = a[i - 1], y = a[i];
		if (x > y)y += m;
		r[y] -= (y - x - 1);
	}
	for (int i = 0; i < m * 2; i++) {
		sum += r[i];
		c[i%m] += sum;
	}
	cout << K - *max_element(c, c + m) << endl;
}

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

int main()
{
  int H, W;
  cin >> H >> W;
  
  string board[50];
  for (int i = 0; i < H; ++i)
    cin >> board[i];
  
  const int dx[] = {-1, -1, -1, 0, 0, 1, 1, 1};
  const int dy[] = {-1, 0, 1, -1, 1, -1, 0, 1};
  
  for (int i = 0; i < H; ++i) {
    for (int j = 0; j < W; ++j) {
      if (board[i][j] == '#')
        continue;
      
      int numBomb = 0;
      
      for (int d = 0; d < 8; ++d) {
        const int neighbor_i = i + dy[d];
        const int neighbor_j = j + dx[d];
        
        if (neighbor_i < 0 or neighbor_i >= H) continue;
        if (neighbor_j < 0 or neighbor_j >= W) continue;
        if (board[neighbor_i][neighbor_j] == '#') ++numBomb;
      }
      
      board[i][j] = char(numBomb + '0');
    }
  }
  
  for (int i = 0; i < H; ++i)
      cout << board[i] << endl;
}


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

int main(){
	int A, B, K;
	cin >> A >> B >> K;
	if((A + B) % 2 == 0){
		cout << (A + B) / 2 << endl;
	} else {
		cout << "IMPOSSIBLE" << endl;
	}
}

Measured memory_bytes: 256
import java.util.ArrayList;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

class Main{

	public static void main(String[] args) {

		List<Integer> array = new ArrayList<>();


		Scanner scan = new Scanner(System.in);
		int N  = scan.nextInt();
		int[] ans  = new int[N+1];

		array.add(1);

		for(int i=6; i <=N; i *= 6){
			array.add(i);
		}

		for(int i=9; i <=N; i *= 9){
			array.add(i);
		}

		Collections.sort(array);

		for(int i = 0; i<=N; i++){
			ans[i] = 100000;
		}

		ans[0] = 0;

		for(int i = 1; i<= N;i++){
			for(int j: array){
				if(i < j) break;
				ans[i] = Math.min(ans[i], ans[i-j]+1);
			}
		}



		System.out.println(ans[N]);


	}


}

Measured memory_bytes: 26800
#include <stdio.h>
int main(void){
  int n,i;
  int money=100000;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
      money*=1.05;
     

      if(money%1000!=0){
          money=money-(money%1000)+1000;
      }


      
  }
  
  printf("%d\n",money);
}



Measured memory_bytes: 2048
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <queue>
#include <map>
#include <numeric>
#include <unordered_map>
#include <iomanip>
#include <functional>
#include <bitset>
#include <complex>
#include <stack>
#include <cstdint>



#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define rrep(i, n) for(ll i = (ll)(n-1); i >= 0; i--)
#define repi(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rrepi(i,a,b) for(ll i=(ll)(b);i>=(ll)(a);i--)

#define all(x) (x).begin(),(x).end()

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

typedef long long ll;

using namespace std;
template <std::uint_fast64_t Modulus> class modint {
  using u64 = std::uint_fast64_t;

public:
  u64 a;

  modint(const u64 x = 0) noexcept : a(x % Modulus) {}
  u64 &value() noexcept { return a; }
  const u64 &value() const noexcept { return a; }
  modint operator+(const modint rhs) const noexcept {
    return modint(*this) += rhs;
  }
  constexpr modint operator-(const modint rhs) const noexcept {
    return modint(*this) -= rhs;
  }
  constexpr modint operator*(const modint rhs) const noexcept {
    return modint(*this) *= rhs;
  }
  constexpr modint operator/(const modint rhs) const noexcept {
    return modint(*this) /= rhs;
  }
  modint &operator+=(const modint rhs) noexcept {
    a += rhs.a;
    if (a >= Modulus) {
      a -= Modulus;
    }
    return *this;
  }
  modint &operator-=(const modint rhs) noexcept {
    if (a < rhs.a) {
      a += Modulus;
    }
    a -= rhs.a;
    return *this;
  }
  modint &operator*=(const modint rhs) noexcept {
    a = a * rhs.a % Modulus;
    return *this;
  }
  modint &operator/=(modint rhs) noexcept {
    u64 exp = Modulus - 2;
    while (exp) {
      if (exp % 2) {
        *this *= rhs;
      }
      rhs *= rhs;
      exp /= 2;
    }
    return *this;
  }
};
using mint=modint<(ll)1e9+7>;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  ll h,w;cin>>h>>w;
  vector<vector<char>>hw(h+1,vector<char>(w+1,'#'));
  vector<vector<mint>>dp(h+1,vector<mint>(w+1,1));
  rep(i,h)rep(j,w)cin>>hw[i+1][j+1];
  rep(i,h+1)rep(j,w+1)if(hw[i][j]=='#')dp[i][j]=0;
  repi(i,1,h+1)repi(j,1,w+1){
    if(i==1&&j==1)continue;
    if(hw[i][j]!='#'){
      dp[i][j]=dp[i-1][j]+dp[i][j-1];
    }
  }
  cout<<dp[h][w].value()<<endl;

  return 0;

}


Measured memory_bytes: 9216
#include <iostream>
#include <string>
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <cmath>
#include <numeric>
#include <iomanip>
#include <deque>
#include <tuple>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_map>
#include <sstream>
#include <stdexcept>
#include <boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

#define rep(i, x) for (int i = 0; i < (int)(x); i++)
#define FOR(i, a, done) for (int i = (a); i < (done); ++i)
#define all(a) (a).begin(), (a).end()
#define x first
#define y second
#define debug(a) cout << (a) << endl
namespace mp = boost::multiprecision;
using cpp_int = mp::cpp_int;
using ll = long long;
using namespace std;
template <class T>
bool chmax(T &a, const T &b)
{
	if (a < b)
	{
		a = b;
		return 1;
	}
	return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
	if (a > b)
	{
		a = b;
		return 1;
	}
	return 0;
}

ll M = 1000000007;

void solve()
{
	int x;
	cin>>x;
	rep(i,8){
		if(x<600+i*200){
			cout<<8-i<<endl;
			break;
		}
	}
}

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


Measured memory_bytes: 3644
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO ?????????????????????????????????????????????
		Scanner sc = new Scanner(System.in);
		int num = sc.nextInt();
		
		int[] arr = new int[num];
		for(int i = 0; i < num; i++) {
			arr[i] = sc.nextInt();
		}
		
		int maxDif = Integer.MIN_VALUE;
		int maxNum;
		int smallerNum = arr[0];
		
		for(int i = 0; i < num; i++) {
			if (arr[i] <= smallerNum) {
				for(int j = i + 1; j < num; j++) {
					maxDif = Math.max(maxDif, arr[j] - arr[i]);
				}
			smallerNum = arr[i];
			}
		}
		
		System.out.println(maxDif);
	}
}

Measured memory_bytes: 101584
using System;
using static System.Console;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            long H = long.Parse(ReadLine());
            long twopower = 2;
            while (true)
            {
                if (H < twopower)
                {
                    WriteLine(twopower - 1);
                    break;
                }
                twopower *= 2;
            }
        }

        static int InputNum()
        {
            return int.Parse(ReadLine());
        }
        static List<int> InputNumList()
        {
            return ReadLine().Split(' ').Select(int.Parse).ToList();
        }
    }
}

Measured memory_bytes: 13140
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()
def rand_N(ran1, ran2):
    return random.randint(ran1, ran2)
def rand_List(ran1, ran2, rantime):
    return [random.randint(ran1, ran2) for i in range(rantime)]
def rand_ints_nodup(ran1, ran2, rantime):
  ns = []
  while len(ns) < rantime:
    n = random.randint(ran1, ran2)
    if not n in ns:
      ns.append(n)
  return sorted(ns)

def rand_query(ran1, ran2, rantime):
  r_query = []
  while len(r_query) < rantime:
    n_q = rand_ints_nodup(ran1, ran2, 2)
    if not n_q in r_query:
      r_query.append(n_q)
  return sorted(r_query)

from collections import defaultdict, deque, Counter
from sys import exit
from decimal import *
import heapq
import math
from fractions import gcd
import random
import string
import copy
from itertools import permutations
from operator import mul
from functools import reduce
from bisect import bisect_left, bisect_right

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7


#############
# Main Code #
#############

A, V = getNM()
B, W = getNM()
T = getN()

dis = abs(A - B)

rang = (V - W) * T


if rang >= dis:
    print('YES')
else:
    print('NO')

Measured memory_bytes: 78072
n=int(input())
a=list(map(int,input().split()))
choice=0
colour={}
for elements in a:
	if elements>=1 and elements<=399:colour[1]=1
	elif elements>=400 and elements<=799:colour[2]=2
	elif elements>=800 and elements<=1199:colour[3]=3
	elif elements>=1200 and elements<=1599:colour[4]=4
	elif elements>=1600 and elements<=1999:colour[5]=5
	elif elements>=2000 and elements<=2399:colour[6]=6
	elif elements>=2400 and elements<=2799:colour[7]=7
	elif elements>=2800 and elements<=3199:colour[8]=8
	else:choice+=1

m=len(colour)
if m==0 and choice!=0:m=1
print(m,len(colour)+choice)


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

#define pb push_back
#define pob pop_back
#define st first
#define nd second
#define test printf("test\n");
#define endll printf("\n")
#define mp make_pair
#define sol (node*2)
#define sag ((node*2)*1)
#define orta (bas+son)/2
#define eps 1e-6


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

#define FOR( i, L, U ) for(int i=(int)L ; i<=(int)U ; i++ )
#define FORD( i, U, L ) for(int i=(int)U ; i>=(int)L ; i-- )

typedef long long ll;
typedef long long int lli;
typedef long long unsigned llu;
typedef pair < int,int > pii;
typedef pair < ll,lli > plli;

const int MAX = -100, N=1e5+3;
double pi = cos(-1);
int r,l,k,m,n,ans;

//-------------END OF DRAFT-------------


int main() {
	cin>>n;
	vector<pair<string,int> > blue;
	string str;
	for(int i=0; i<n; i++) {
		cin>>str;
		blue.pb(mp(str,0));
	}
	cin>>m;
	vector<string> red;
	for(int i=0; i<m; i++) {
		cin>>str;
		red.pb(str);
	}
	int sum;
	ans=0;
	for(int i=0; i<n; i++) {
		sum=0;
		if(blue[i].nd == -100) continue;
		if(i!=n-1) {
		for(int j=i+1; j<n; j++) {
			if(blue[j].st == blue[i].st) {
				blue[j].nd = -100; blue[i].nd++;
			}
		}
		}
		blue[i].nd++;
		for(int j=0; j<m; j++) {
			if(red[j] == blue[i].st) {
				blue[i].nd--;
			}
		}
		if(blue[i].nd > ans) ans = blue[i].nd;
	}
	cout<<ans<<endl;
	return 0;
}

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

const int N=55, mod=1e9+7;
inline int add(int x,int y) {return (x+y>=mod) ? (x+y-mod) : (x+y);}
inline int mul(int x,int y) {return (LL)x*y%mod;}

inline void add1(int &x,int y) {x=add(x,y);}

int n,f[N][N],c[N][N],g[N][N];

int main() {
    cin>>n;
    f[1][0]=f[1][1]=1;
    for(int i=0;i<=n;i++) c[i][0]=1;
    for(int i=1;i<=n;i++)
        for(int j=1;j<=i;j++)
            c[i][j]=add(c[i-1][j-1],c[i-1][j]);
    for(int i=1;i<n;i++)
        for(int j=0;j<=i;j++) if(f[i][j]) 
            for(int x=0;x+i<=n;++x)
                for(int y=0;x+y+i<=n;++y) if((x+y) && (x+y>=j) && (!((x+y-j)&1)))
                    add1(f[i+x+y][abs((x+y-j)/2+j-x)],mul(f[i][j],mul(c[i+x+y][x+y],c[x+y][x])));
    cout<<f[n][0]<<'\n';
}

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

signed main() {
	int n;
	string a, b, c;
	cin >> n >> a >> b >> c;
	int ans = 0;
	rep(i, n) {
		if(a[i] == b[i] && b[i] == c[i]) {}
		else if(a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) {
			ans += 1;
		}
		else {
			ans += 2;
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n-1);i>=0;i--)
#define FOR(i,n,m) for(int i=n;i<=(int)(m);i++)
#define RFOR(i,n,m) for(int i=(int)(n);i>=m;i--)
#define all(x) (x).begin(),(x).end()
#define sz(x) int(x.size())
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;
using namespace std;
vector<int> dy={1,0,-1,0};
vector<int> dx={0,1,0,-1};
template<class T>
vector<T> make_vec(size_t a){
    return vector<T>(a);
}
template<class T, class... Ts>
auto make_vec(size_t a, Ts... ts){
    return vector<decltype(make_vec<T>(ts...))>(a, make_vec<T>(ts...));
}
int main(){
    int n,m;
    cin>>n>>m;
    auto a=make_vec<int> (n,m);
    rep(i,n) rep(j,m){
        cin>>a[i][j];
        a[i][j]--;
    }
    
    int ans=INF;
    vector<bool> sports(m,true);
    rep(i,m){
        vector<int> sanka(m);
        
        rep(j,n){
            int now=0;
            while(now<m && !sports[a[j][now]]) now++;
            sanka[a[j][now]]++;
        }
        
        int tmp;
        int maxi=0;
        rep(j,m){
            if(sanka[j]>=maxi){
                tmp=j;
                maxi=sanka[j];
            }
        }
        sports[tmp]=false;
        ans=min(ans,maxi);
    }
    cout<<ans<<endl;
}


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

int main(){
  int k,n;
  cin >> k >> n;
  int a[n-1] = {0};
  rep(i,n) cin >> a[i];
  int c=0;
  for(int i=0;i<n-1;++i){
    c = max(c,a[i+1]-a[i]);
  }
  c = max(c,k-a[n-1]+a[0]);
  printf("%d",k-c);
  return 0;
}


Measured memory_bytes: 4508
#include <iostream>

using namespace std;

int main(){
	
	cin.tie(0); ios_base::sync_with_stdio(0);
	int x;
	cin>>x;
	int f = x/500;
	x%=500;
	int s = x/5;
	cout<<1000*f+s*5<<endl;
	
	return 0;
}

Measured memory_bytes: 256
#include<set>  
#include<map>  
#include<stack>  
#include<cmath>  
#include<cstdio>  
#include<queue>  
#include<vector>  
#include<cstring> 
#include<climits>  
#include<iostream> 
#include<algorithm> 
using namespace std; 
int read(){ 
    int f=1,x=0; 
    char c=getchar(); 
    while(c<'0'||'9'<c){if(c=='-')f=-1;c=getchar();} 
    while('0'<=c&&c<='9'){x=x*10+c-'0';c=getchar();} 
    return f*x; 
}
#define MAXN 300
#define INF 0x3f3f3f3f
int pan[100];
bool check(int x){
	if(pan[x%10]) return 0;
	while(x){
		if(pan[x%10]) return 0;
		x/=10;
	}
	return 1;
}
int main(){
	int n=read(),k=read();
	for(int i=1;i<=k;i++)
		pan[read()]=1;
	while(1){
		if(check(n)){
			printf("%d\n",n);
			return 0;
		}
		n++;
	}
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define FOR(i, a, b) for (int i = (a); i < int(b); ++i)
#define RFOR(i, a, b) for (int i = (b)-1; i >= int(a); --i)
#define rep(i, n) FOR(i, 0, n)
#define rep1(i, n) FOR(i, 1, int(n) + 1)
#define rrep(i, n) RFOR(i, 0, n)
#define rrep1(i, n) RFOR(i, 1, int(n) + 1)
#define all(c) begin(c), end(c)
const int MOD = 1000000007;

template <typename T>
void __dump__(std::ostream &os, const T &first) {
    os << first;
}
template <typename First, typename... Rest>
void __dump__(std::ostream &os, const First &first, const Rest &... rest) {
    os << first << ", ";
    __dump__(os, rest...);
}
#define dump(...)                                         \
    do {                                                  \
        std::ostringstream os;                            \
        os << __LINE__ << ":\t" << #__VA_ARGS__ << " = "; \
        __dump__(os, __VA_ARGS__);                        \
        std::cerr << os.str() << std::endl;               \
    } while (0)


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

    int n;
    while(cin >> n){
        int mini[26];
        rep(i, 26) mini[i] = 100000;
        rep(i, n){
            string s;
            cin >> s;
            int cnt[26] = {};
            for(char c : s) ++cnt[c - 'a'];
            rep(j, 26) mini[j] = min(mini[j], cnt[j]);
        }
        string ans;
        rep(i, 26) {
            ans += string(mini[i], 'a' + i);
        }
        cout << ans << endl;
    }
}


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

using namespace std;

template <typename T = int>
struct UnionFind
{
	std::vector<T> data;
	UnionFind(int n) : data(n, -1) {}
	bool unite(T x, T y)
	{
		x = root(x);
		y = root(y);
		if (x != y)
		{
			if (data[y] < data[x])
				swap(x, y);
			data[x] += data[y];
			data[y] = x;
		}
		return x != y;
	}
	T root(T x) { return data[x] < 0 ? x : data[x] = root(data[x]); }
	bool same(T x, T y) { return root(x) == root(y); }
	T size(T x) { return -data[root(x)]; }
};

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> p(n);
	for (auto &&x : p)
	{
		cin >> x;
		x--;
	}
	UnionFind<int> uf(n);
	for (int i = 0; i < m; ++i)
	{
		int x, y;
		cin >> x >> y;
		uf.unite(x - 1, y - 1);
	}
	int ans = 0;
	for (int i = 0; i < n; ++i)
	{
		if (uf.same(p[i], i))
		{
			ans++;
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 1024
import bisect

n = int(input())
l = list(map(int, input().split()))
ans = 0
length = len(l)
l.sort()
 
for i in range(n):
    for j in range(i+1,n):
        k = bisect.bisect_left(l,l[i]+l[j])
        ans += max(k - (j+1),0)
print(ans)

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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> edge;

ll A[1000000];
ll x[1000000];
ll n;

bool comp(const ll& left, const ll& right) {
        return A[left] < A[right];
}

int main(){
    cin >> n;
    for(ll i=0; i<n; i++){
        cin >> A[i];
        x[i] = i;
    }

    sort(x, x+n, comp);

    for(ll i=0; i<n; i++){
        cout << x[i]+1 << " ";
    }

    cout << endl;
    return 0;
}

Measured memory_bytes: 5632
#include <iostream>
#include <stdio.h>
#include <vector>
#include <set>
#include <map>
#include <algorithm>

using namespace std;

void solve()
{
	int num, correct;
	map<int, int> data;
	set<int> kind;
	while(~scanf("%d,%d", &num, &correct))
	{
		if(num == 0 && correct == 0)
		{
			break;
		}
		data.insert(map<int, int>::value_type(num, correct));
		kind.insert(correct);
	}
	vector<int> correct_desc;
	set<int>::reverse_iterator it = kind.rbegin();
	while(it != kind.rend())
	{
		correct_desc.push_back(*it);
		++it;
	}
	int team;
	while(cin >> team)
	{
		for(int i = 0; i < correct_desc.size(); ++i)
		{
			if(data[team] == correct_desc[i])
			{
				cout << i + 1 << endl;
				break;
			}
		}
	}
}

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

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

typedef pair<int,int> P;
#define ll long long
#define ld long double
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define PI 3.14159265358979323846
#define sz(x) ((int)(x).size())
#define chmin(x,y) x = min(x,y)
#define chmax(x,y) x = max(x,y)

const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
int main()
{
    int n;
    ll otoshi;
    cin >> n >> otoshi;
    ll sum = 0;
    for (int x = 0; x <= n; x++)
    {
        for (int y = 0; y <= n; y++)
        {
            int z;
            z = n - x - y;
            if (z < 0)
            {
                continue;
            }
            sum = 10000 * (ll)x + 5000 * (ll)y + 1000 * (ll)z;
            if(sum == otoshi)
            {
                cout << x << " " << y << " " << z << " " << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << " " << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<set>
#include<map>
#include<queue>
#include<cmath>
#define REP(i,a) for (int i = 0;i < (a);++i)
#define FOR(i,a,b) for (int i = (a);i < (b); ++i)
#define FORR(i,a,b) for (int i = (a);i >= (b); --i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SORT(list) sort(ALL((list)));
#define MOD 1000000007
using namespace std;
using ll = long long;
int main(){
    int n;
    cin >> n;
    vector<ll>a(n);
    REP(i,n)cin >> a[i];
    ll answer = 0;
    FOR(i,1,n){
        int diff = a[i-1]-a[i];
        if(diff > 0){
            answer+=diff;
            a[i]+=diff;
        }
    }
    cout << answer << endl;
    return 0;
}

Measured memory_bytes: 4836
#include<stdio.h>
int main(void)
{
	int N, M, A[1001] = { 0 }, B[1001] = { 0 }, count[1001] = { 0 }, i, j;

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

	for (j = 1; j <= M; j++)
	{
		scanf("%d", &B[j]);
	}
	
	i = 1;
	j = 1;

		while(j<=M)
		{
			if (A[i] <= B[j])
			{
				count[i] = count[i] + 1;
				i = 1;
				j++;
			}
			else
			{
				i++;
			}
		}

		int max = 1,now=count[1];

		for (i = 2; i <= N; i++)
		{
			if (now < count[i])
			{
				now = count[i];
				max = i;
			}
		}

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

	return 0;
}

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

long N, v, t, maxV = 0;
#define Rep(i,n) for(int i = 0; i < n; ++i )

int main()
{
	cin >> N;
    Rep(i,N){
		cin >> v;
        t += v;
		if( maxV < v )
			maxV = v;
    }
    t -= maxV /2;
	cout << t << std::endl;
}

Measured memory_bytes: 256
from operator import itemgetter

n = int(input())

a = []
b = []
for i in range(n):
  _a, _b = map(int, input().split())
  a.append(_a)
  b.append(_b)

c = sorted(zip(a, b), key=itemgetter(1))
a, b = zip(*c)
a = list(a)
b = list(b)

for i in range(1, n):
  a[i] += a[i-1]

flag = True

for i in range(n):
  if a[i] > b[i]:
    flag = False
    break

print("Yes" if flag else "No")

Measured memory_bytes: 124552
N = int(input())

a = N % 10
if (a == 2 or a == 4 or a == 5 or a == 7 or a == 9):
    print('hon')
elif (a == 0 or a == 1 or a == 6 or a == 8):
    print('pon')
else:
    print('bon')


Measured memory_bytes: 9172
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef multiset<ll> S;
typedef priority_queue<ll> PQ;
typedef priority_queue<P,vector<P>,greater<P>> SPQ;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
const ll inf=1001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double pi=3.14159265358979323846;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<endl;}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<endl;}
template<class T> void outvv(T v){rep(i,v.size()){rep(j,v[i].size()){if(j)cout<<' ';cout<<v[i][j];}cout<<endl;}}
int main(){
    ll n,m;cin>>n>>m;
    vvi from(n),to(n);
    rep(i,m){
        ll a,b;cin>>a>>b;
        a--;b--;
        from[b].pb(a);
        to[a].pb(b);
    }
    vector<double> dp(n);
    dp[n-1]=0;
    for(ll i=n-2;i>=0;i--){
        for(ll x:to[i])dp[i]+=dp[x]+1;
        dp[i]/=to[i].size();
    }
    double ans=dp[0];
    for(ll i=n-2;i>=0;i--){
        double ma=0;
        if(to[i].size()==1)continue;
        vector<double> dp2=dp;
        rep(j,i+1)dp2[j]=0;
        for(ll x:to[i]){
            chmax(ma,dp2[x]+1);
            dp2[i]+=dp2[x]+1;
        }
        dp2[i]-=ma;
        dp2[i]/=to[i].size()-1;
        for(ll j=i-1;j>=0;j--){
            for(ll x:to[j])dp2[j]+=dp2[x]+1;
            dp2[j]/=to[j].size();
        }
        chmin(ans,dp2[0]);
    }
    cout<<fixed<<setprecision(10);
    cout<<ans<<endl;
}


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

int main(){
  int n, p; cin >> n >> p;
  string s; cin >> s;
  v1i v(n+1, 0), u(p-1, 1);
  rep(i, p-2){
    u[i+1] = u[i]*10;
    u[i+1] %= p;
  }
  rrep(i, n){
    v[i] = v[i+1] + u[(n-i-1)%(p-1)]*(s[i]-'0');
    v[i] %= p;
  }
  map<int, lint> m;
  rep(i, n+1) m[v[i]]++;
  lint a = 0;
  rep(i, p) a += m[i] * (m[i]-1) / 2;
  if(p == 2){
    a = 0;
    rep(i, n) if((s[i] - '0') % 2 == 0) a += i+1;
  }
  else if(p == 5){
    a = 0;
    rep(i, n) if((s[i] - '0') % 5 == 0) a += i+1;
  }
  cout << a << "\n";
  return 0;
}

Measured memory_bytes: 1796
#include <stdio.h>

int main(void)
{
	int a[10];
	int n = 10,i,j,tmp;
	
	for(i = 0;i < 10;i++){
		scanf("%d",&a[i]);
	}
	for(i = 0;i < n - 1;i++){
		for(j = n - 1;j > i;j--){
			if(a[j] > a[j-1]){
				tmp = a[j];
				a[j] = a[j -1];
				a[j-1] = tmp;
			}
		}
	}
	for(i = 0;i < 3;i++){
		printf("%d\n",a[i]);
	}
	return 0;
}

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

#define ALL(v) (v).begin(),(v).end()

using namespace std ;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;




int main()
{
  int x ;
  cin >> x ;
  
  if(x<1200){
    cout << "ABC" <<endl ;
  }
  else {
    cout << "ARC" <<endl ;
  }
    return 0 ;
}

/*　吾輩はやれば出来る子である。 
　　　　∩∩ 
　　　（´･ω･） 
　　 ＿|　⊃／(＿＿_ 
　／　└-(＿＿＿_／ 
　￣￣￣￣￣￣￣ 
　やる気はまだない 

　　 ⊂⌒／ヽ-、＿_ 
　／⊂_/＿＿＿＿ ／ 
　￣￣￣￣￣￣￣　　*/

Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.OutputStream;
import java.io.PrintWriter;
import java.util.Arrays;
import java.util.InputMismatchException;
import java.util.Map;
import java.util.StringTokenizer;
import java.util.TreeMap;

public class Main {

	public static void main(String[] args) throws IOException {
		InputStream inputStream = System.in;
		OutputStream outputStream = System.out;
		InputReader in = new InputReader(inputStream);
		PrintWriter out = new PrintWriter(outputStream);
		TaskX solver = new TaskX();
		solver.solve(1, in, out);
		out.close();
	}

	static int maxN = 1000;
	static int maxM = 2000;
	static int n;
	static int m;
	static long INF = Long.MAX_VALUE/2;
	static class TaskX {
		public void solve(int testNumber, InputReader in, PrintWriter out) {

			// input
			n = in.nextInt();
			m = in.nextInt();

			long[] d = new long[n];
			Edge[] edges = new Edge[m];

			for (int i = 0; i < m; i++) {
				int a = in.nextInt()-1;
				int b = in.nextInt()-1;
				long c = in.nextLong();
				edges[i] = new Edge(a, b, -c);
			}

			Arrays.fill(d, INF);

			d[0] = 0;

			boolean[] isNegative = new boolean[n];

			for (int now = 0; now < n; now++) {
				for (int j = 0; j < m; j++) {
					int u = edges[j].from;
					int v = edges[j].to;
					long c = edges[j].cost;
					if (d[u] + c < d[v]) {
						d[v] = d[u] + c;
						if (now == n-1) {
							isNegative[u] = true;
							isNegative[v] = true;
						}
					}
				}
			}

			if (isNegative[n-1]) {
				out.println("inf");
			} else {
				out.println(-d[n-1]);
			}


		}
	}

	static class Edge {
		int from;
		int to;
		long cost;

		public Edge(int from, int toNodeNum, long weight) {
			this.from = from;
			this.to = toNodeNum;
			this.cost = weight;
		}
	}

	static class ArrayUtils {
		public static Map<Integer, Integer> getCountMap(int[] array) {
			Map<Integer, Integer> map = new TreeMap<>();
			for (int x : array)
				map.merge(x, 1, Integer::sum);
			return map;
		}
	}

	static class InputReader {
		BufferedReader in;
		StringTokenizer tok;

		public String nextString() {
			while (!tok.hasMoreTokens()) {
				try {
					tok = new StringTokenizer(in.readLine(), " ");
				} catch (IOException e) {
					throw new InputMismatchException();
				}
			}
			return tok.nextToken();
		}

		public int nextInt() {
			return Integer.parseInt(nextString());
		}

		public long nextLong() {
			return Long.parseLong(nextString());
		}

		public int[] nextIntArray(int n) {
			int[] res = new int[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextInt();
			}
			return res;
		}

		public long[] nextLongArray(int n) {
			long[] res = new long[n];
			for (int i = 0; i < n; i++) {
				res[i] = nextLong();
			}
			return res;
		}

		public InputReader(InputStream inputStream) {
			in = new BufferedReader(new InputStreamReader(inputStream));
			tok = new StringTokenizer("");
		}

	}

}


Measured memory_bytes: 23764
#include <iostream>
#include <vector>
#include <string>
#include <cmath>
#include <set>
#include <algorithm>
#include <array>
#include <complex>
#include <utility>
#include <map>
int needleX[4] = { -1,0,1,0 };
int needleY[4] = { 0,1,0,-1 };

#define const INF=1<<21;
int main(){
	int N,a,sum=0,ave=0;
    std::cin >> N >> a;
    
    std::cout << N+a/2 << std::endl;
} 


Measured memory_bytes: 256
a, b, c, d, e = [int(input()) for _ in range(5)]
l = [0 if str(i)[-1] == '0' else 10 - int(str(i)[-1]) for i in [a, b, c, d, e]]
ll = [a, b, c, d, e]
arr = []
for i in range(5):
    arr.append([l[i], ll[i]])
arr.sort()
ans = 0
for index, (i, j) in enumerate(arr):
    if index == len(arr) - 1:
        ans += j
    else:
        ans += i + j
print(ans)

Measured memory_bytes: 3064
def show(A):
	for i in range(len(A)):
		if i != len(A) - 1:
			print(A[i], end=' ')
		else:
			print(A[i])

def insertionSort(n, A):
	for i in range(1,n):
		key = A[i]
		j = i - 1
		while (j >= 0 and A[j] > key):
			A[j+1] = A[j]
			j = j - 1
		A[j+1] = key
		show(A)
		
n = int(input())
nums = list(map(int, input().split()))
show(nums)
insertionSort(n, nums)


Measured memory_bytes: 5980
#include<bits/stdc++.h>
#define ri register int
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long Ull;
#define fi first
#define se second
#define pb push_back
const int rlen=1<<18|1;
char buf[rlen],*ib=buf,*ob=buf;
#define gc() (((ib==ob)&&(ob=(ib=buf)+fread(buf,1,rlen,stdin)),ib==ob)?-1:*ib++)
inline int read(){
	int ans=0;
	char ch=gc();
	while(!isdigit(ch))ch=gc();
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	return ans;
}
inline int Read(char*s){
	int ans=0;
	char ch=gc();
	while(ch!='.'&&ch!='#')ch=gc();
	while(ch=='.'||ch=='#')s[++ans]=ch,ch=gc();
	return ans;
}
namespace modular{
	const int mod=1e9+7;
	inline int add(int a,int b){return a+b<mod?a+b:a+b-mod;}
	inline int dec(int a,int b){return a<b?a-b+mod:a-b;}
	inline int mul(int a,int b){return (ll)a*b%mod;}
	inline void Add(int&a,int b){a=a+b<mod?a+b:a+b-mod;}
	inline void Dec(int&a,int b){a=a<b?a-b+mod:a-b;}
	inline void Mul(int&a,int b){a=(ll)a*b%mod;}
	inline int ksm(int a,int p){int ret=1;for(;p;p>>=1,Mul(a,a))(p&1)&&(Mul(ret,a),1);return ret;}
}
using namespace modular;
const int N=305;
int n,m,K,vl[N][N];
char s[N][N];
int ans[N][N];
pii a[N*N];
int main(){
	#ifdef ldxcaicai
	freopen("lx.in","r",stdin);
	#endif
	n=read(),m=read(),K=read();
	vector<int>psx;
	int idx=0;
	for(ri i=1;i<=n;++i){
		Read(s[i]);
		vector<int>ps;
		for(ri j=1;j<=m;++j)if(s[i][j]=='#')ps.pb(j);
		if(!((int)ps.size()))continue;
		psx.pb(i);
		++idx;
		for(ri t=0,j=1;j<=m;++j){
			if(t!=((int)ps.size())-1&&j>ps[t])++t,++idx;
			ans[i][j]=idx;
		}
	}
	for(ri i=1,t=0;i<=n;++i){
		if(t!=((int)psx.size())-1&&i>psx[t])++t;
		for(ri j=1;j<=m;++j)ans[i][j]=ans[psx[t]][j];
	}
	for(ri i=1;i<=n;++i,puts(""))for(ri j=1;j<=m;++j)cout<<ans[i][j]<<' ';
	return 0;
}

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

int main() {
    int N;
    int a[110];  // 最大 100 個ですが余裕をもたせます
    cin >> N;
    for (int i = 0; i < N; ++i) cin >> a[i];
  
  sort(a,a+N,greater<int>());
  int Alice=0;
  int Bob=0;
  for (int i=0; i<N;++i){
    if (i%2==0){
      Alice+=a[i];
    }
    else {
      Bob+=a[i];
    }
  }
  
  cout <<Alice-Bob <<endl;
}

   
      

Measured memory_bytes: 256