akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define GET_MACRO(_1,_2,_3,_4,_5,_6,_7,_8,NAME,...) NAME
#define pr(...) cerr<< GET_MACRO(__VA_ARGS__,pr8,pr7,pr6,pr5,pr4,pr3,pr2,pr1)(__VA_ARGS__) <<endl
#define pr1(a) (#a)<<"="<<(a)<<" "
#define pr2(a,b) pr1(a)<<pr1(b)
#define pr3(a,b,c) pr1(a)<<pr2(b,c)
#define pr4(a,b,c,d) pr1(a)<<pr3(b,c,d)
#define pr5(a,b,c,d,e) pr1(a)<<pr4(b,c,d,e)
#define pr6(a,b,c,d,e,f) pr1(a)<<pr5(b,c,d,e,f)
#define pr7(a,b,c,d,e,f,g) pr1(a)<<pr6(b,c,d,e,f,g)
#define pr8(a,b,c,d,e,f,g,h) pr1(a)<<pr7(b,c,d,e,f,g,h)
#define prArr(a) {cerr<<(#a)<<"={";int i=0;for(auto t:(a))cerr<<(i++?", ":"")<<t;cerr<<"}"<<endl;}
using namespace std;
using Int = long long;
using _int = int;
using ll = long long;
using Double = long double;
const Int INF = (1LL<<60)+1e9; // ~ 1.15 * 1e18
const Int mod = (1e9)+7;
const Double EPS = 1e-8;
const Double PI = 6.0 * asin((Double)0.5);
using P = pair<Int,Int>;
template<class T> T Max(T &a,T b){return a=max(a,b);}
template<class T> T Min(T &a,T b){return a=min(a,b);}
template<class T1, class T2> ostream& operator<<(ostream& o,pair<T1,T2> p){return o<<"("<<p.first<<","<<p.second<<")";}
template<class T1, class T2, class T3> ostream& operator<<(ostream& o,tuple<T1,T2,T3> t){
  return o<<"("<<get<0>(t)<<","<<get<1>(t)<<","<<get<2>(t)<<")";}
template<class T1, class T2> istream& operator>>(istream& i,pair<T1,T2> &p){return i>>p.first>>p.second;}
template<class T> ostream& operator<<(ostream& o,vector<T> a){Int i=0;for(T t:a)o<<(i++?" ":"")<<t;return o;}
template<class T> istream& operator>>(istream& i,vector<T> &a){for(T &t:a)i>>t;return i;}
//INSERT ABOVE HERE


signed main(){
  srand((unsigned)time(NULL));
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout << fixed << setprecision(12);

  Int N;
  cin>>N;
  Double ans = (1.0*((N-1)/2+1))/N;
  cout<<ans<<endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
A = list(map(int,input().split()))

SUM = [0]
ans = 10**20
for a in A:
    SUM.append(SUM[-1]+a)
for i in range(2,N-1): # [1,i]と(i,N]に分割
    low, high = 1, i
    while high - low > 1:
        mid = (low + high)//2
        if SUM[mid] >= SUM[i] - SUM[mid]: high = mid
        else: low = mid
    P1, Q1 = SUM[low], SUM[i]-SUM[low]
    P2, Q2 = SUM[high], SUM[i]-SUM[high]
    if abs(P1-Q1) < abs(P2-Q2): P, Q = P1, Q1
    else: P, Q = P2, Q2
    low, high = i+1, N
    while high - low > 1:
        mid = (low + high)//2
        if SUM[mid]-SUM[i] >= SUM[N]-SUM[mid]: high = mid
        else: low = mid
    R1, S1 = SUM[low]-SUM[i], SUM[N]-SUM[low]
    R2, S2 = SUM[high]-SUM[i], SUM[N]-SUM[high]
    if abs(R1-S1) < abs(R2-S2): R, S = R1, S1
    else: R, S = R2, S2
    ans = min(max(P,Q,R,S) - min(P,Q,R,S), ans)
print(ans)
    


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

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

#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define ALL(v) (v).begin(), (v).end()
#define p(s) cout<<(s)<<endl
#define p2(s, t) cout << (s) << " " << (t) << endl
#define br() p("")
#define pn(s) cout << (#s) << " " << (s) << endl
#define p_yes() p("Yes")
#define p_no() p("No")

const ll mod = 1e9 + 7;
const ll inf = 1e18;

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

    // input
    ll N;
    cin >> N;

    vector<ll> A(N);
    FOR(i, 0, N){
        cin >> A.at(i);
    }

    ll Q;
    cin >> Q;

    while(Q--){
        ll b, e, t;
        cin >> b >> e >> t;

        auto it = A.begin();
        swap_ranges(it+b, it+e, it+t);
    }

    FOR(i, 0, N){
        if(i){
            cout << ' ';
        }
        cout << A[i];
    }
    cout << endl;
    
    return 0;
}


Measured memory_bytes: 3228
#define _USE_MATH_DEFINES
#include<stdio.h>
#include<string>
#include<iostream>
#include<cctype>
#include<cstdio>
#include<vector>
#include<stack>
#include <algorithm>
#include<math.h>
#include<set>
#include<map>
#include<iomanip>
//#include<bits/stdc++.h>


using namespace std;




int main() {
	
	string p;
	cin>>p;
	string h;
	for(int i=0;i<p.size();i++){
		if(p[i]!='B')h+=p[i];
		else{
			if(h.size())h.erase(h.size()-1);
		}
	}
	cout<<h<<endl;
    return 0;
}

	
	


	

Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <algorithm>
#include <cstring>
#include <string>
#include <cctype>
#include <sstream>
#include <cmath>
#include <climits>
#include <set>
#include <iostream>
#include <map>
#include <functional>
#include <cstdlib>
#include <numeric>
#include <queue>
#include <complex>
#include <sstream>
#include <stack>

using namespace std;

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

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int, int> pii;
typedef complex<double> Point;

int main()
{
	int h, w;
	while(scanf("%d%d", &h, &w), h){
		int ans = 0;
		int tmp[512] = {0};
		rep(i, h){
			char field[512];
			scanf("%s", field);
			field[w] = '*';
			
			stack<pii> S;
			rep(j, w+1){
				tmp[j] = field[j] == '*' ? 0 : tmp[j]+1;
				pii rect(tmp[j], j);
				if(S.empty())
					S.push(rect);
				else{
					if(S.top().first < rect.first)
						S.push(rect);
					else if(S.top().first > rect.first){
						int target = j;
						while(!S.empty() && S.top().first >= rect.first){
							pii pre = S.top();
							S.pop();
							ans = max(ans, pre.first*(j-pre.second));
							target = pre.second;
						}
						rect.second = target;
						S.push(rect);
					}
				}
			}
		}

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

	return 0;
}

Measured memory_bytes: 0
import Data.List
import qualified Data.ByteString.Char8 as BC
import Data.Maybe (fromJust)
import Control.Monad
import Data.Functor
import qualified Data.IntSet as IntSet

readInts :: IO [Int]
readInts = map (fst . fromJust . BC.readInt) . BC.words <$> BC.getLine

main :: IO()
main = do
  _ <- fmap read getLine :: IO Int
  ss <- readInts
  _ <- fmap read getLine :: IO Int
  ts <- readInts
  print $ solve' ss ts

solve' :: [Int] -> [Int] -> Int
solve' ss ts = foldl' (\acc t -> acc + if IntSet.member t sSet then 1 else 0) 0 $ ts 
  where
    sSet = IntSet.fromList ss



Measured memory_bytes: 25644
#include <bits/stdc++.h>
using namespace std;
const int N=100005,mod=998244353;
int n,a[N];
int gcd(int a,int b){
    return b?gcd(b,a%b):a;
}
int main(){
    cin >> n;
    for (int i=0;i<n;i++)
        cin >> a[i];
    sort(a,a+n);
    int ans=1;
    for (int i=0;i<n;i++)
        ans=1LL*ans*gcd(a[i],i)%mod;
    cout << ans;
    return 0;
}

Measured memory_bytes: 640
from collections import defaultdict
import heapq

vertice,edge,source = map(int,input().split(" "))
link = defaultdict(dict)
weight = defaultdict(dict)
answer = [-1] * vertice
for e in range(edge):
    i,j,w = map(int,input().split(" "))
    link[i] = link.get(i,set()) | {j}
    weight[i].update({j:w})
queue = []
heapq.heappush(queue,(0,source))
heapq.heapify(queue)
while queue:
    #print(queue)
    now_cost,here = heapq.heappop(queue)
    #print(now_cost,here,queue)
    if answer[here] > -1:
        continue
    answer[here] = now_cost

    #print(v,here,now_cost,not_went,queue)
    for nw in link[here]:
        if answer[nw] == -1:
            heapq.heappush(queue,(now_cost + weight[here][nw],nw))

for a in answer:
    print(a if a != -1 else "INF")

Measured memory_bytes: 140500
#include<bits/stdc++.h>
using namespace std;
int main(){
int X;
  cin>>X;
  int x;
  for(int i=0;i*i<=X;i++)
    x=i;
  vector<int> M(x+1);
  M.at(0)=0;
  M.at(1)=1;
  for(int i=2;i<=x;i++){
  int sum=1;
    for(int j=0;sum<=X;j++){
    sum*=i; if(X<sum){
    sum/=i; break;
    }
    }M.at(i)=sum;
  
  }sort(M.begin(),M.end());
  cout<<M.at(x)<<endl;
    
 return 0;
}

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

using namespace std;

const long long MOD=1000000007;

long long add_mod(long long x,long long y){
	return (x+y)%MOD;
}

long long sub_mod(long long x,long long y){
	return (x-y+MOD)%MOD;
}

long long mul_mod(long long x,long long y){
	return x*y%MOD;
}

long long inv_mod(long long x){
	if(x == 1) return 1;
	long long d = MOD/x+1;
	return d*inv_mod(x-(MOD%x))%MOD;
}

long long div_mod(long long x, long long y){
	return x*inv_mod(y)%MOD;
}

vector<long long> kaijyo;
void init_conv(long long n){
    kaijyo.resize(n+1);
    kaijyo[0] = 1;
    kaijyo[1] = 1;
	for(int i = 2;i <= n;i++){
		kaijyo[i] = i*kaijyo[i-1]%MOD;
	}
}

long long conv_mod(long long n,long long r){
	return div_mod(div_mod(kaijyo[n],kaijyo[n-r]),kaijyo[r]);
}

long long pow_mod(long long x,long long y){
	long long r = 1;
	for(long long n = x;y != 0;y /= 2,n = mul_mod(n,n)){
		if(y % 2){
			r = mul_mod(r,n);
		}
	}
	return r;
}

int n,k;

void solve(){
    int i,j;
    string str;
    cin >> n >> k;
    long long ans = 0;
    init_conv(n);
    for(i = 0;i <= k;i++){
        if(i == n) break;
        ans = add_mod(ans,mul_mod(conv_mod(n-1,n-1-i),conv_mod(n,i)));
    }
    cout << ans << endl;
}

int main(){
    solve();
}


Measured memory_bytes: 1792
#![allow(non_snake_case, unused)]
use std::cmp::*;
use std::collections::*;
use std::f64::consts::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };

    ($next:expr, mut $var:ident : $t:tt $($r:tt)*) => {
        let mut $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, [ $t:tt ]) => {
        {
            let len = read_value!($next, usize);
            (0..len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
        }
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, bytes) => {
        read_value!($next, String).into_bytes()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: usize,
        h: [i64; n],
    }
    let mut dp = vec![std::i64::MAX; n];
    dp[0] = 0i64;
    for i in 0..n {
        if i + 1 < n {
            dp[i+1] = min(dp[i+1], dp[i] + (h[i] - h[i+1]).abs());
        }
        if i + 2 < n {
            dp[i+2] = min(dp[i+2], dp[i] + (h[i] - h[i+2]).abs());
        }
    }
    println!("{}", dp[n-1]);
}


Measured memory_bytes: 6396
while True:
    n = int(input())
    if n == 0:
        exit()
    s = [None] * n
    for i in range(n):
        s[i] = input()
    ans = [None] * n
    for i, ap in enumerate(s):
        code = [ap[0]]
        for j in range(len(ap) - 1):
            if ap[j] in 'aiueo':
                code.append(ap[j + 1])
        ans[i] = code
    m = max(len(x) for x in ans)
    for k in range(m):
        f = True
        for i in range(n):
            for j in range(i + 1, n):
                if ''.join(ans[i][:k + 1]) == ''.join(ans[j][:k + 1]):
                    f = False
        if f:
            print(k + 1)
            break
    else:
        print(-1)



Measured memory_bytes: 5620
N,M = (int(x) for x in input().split())
a = set(int(input()) for _ in range(M))
dp = [0] * N
broke = False
if N == 1:
    print('1')
    broke = True
elif 1 in a and 2 not in a:
    dp[1] = 1
elif 1 not in a and 2 in a:
    dp[0] = 1
else:
    dp[0] = 1
    dp[1] = 2
if 1 in a and 2 in a:
    print('0')
    broke = True
else:
    for i in range(3,N+1):
        if i-1 in a and i-2 in a:
            print('0')
            broke = True
            break
        elif i-1 in a:
            dp[i-1] = dp[i-3]
        elif i-2 in a:
            dp[i-1] = dp[i-2]
        else:
            dp[i-1] = (dp[i-2] + dp[i-3]) % 1000000007
if broke == False:
    print(dp[N-1])

Measured memory_bytes: 11884
#include <iostream>
#include <algorithm>
using namespace std;
int n,m,s;
int main(void){
    cin>>n;
    for(int i=0;i<n;i++){
        int a;
        cin>>a;
        if(a==0){
            m=max(s,m);
            s=0;
        }else s++;
    }
    cout<<max(m,s)+1<<endl;   
}



Measured memory_bytes: 3112
import java.util.Scanner

object Main extends App {
  val sc = new Scanner(System.in)
  val N = sc.nextInt
  val a = Array.fill(N)(sc.nextInt).sorted.reverse

  val x = (0 until N by 2).map(a(_)).sum
  val y = (1 until N by 2).map(a(_)).sum
  val z = x - y
  println(z)
}


Measured memory_bytes: 27456
import std.stdio, std.algorithm, std.conv, std.array, std.string, std.math, std.typecons, std.numeric;

void main()
{
    auto N = readln.chomp.to!int;
    auto S = readln.chomp.to!(char[]);
    foreach (ref c; S) {
        auto x = c - 'A';
        x = (x + N) % 26;
        c = ('A' + x).to!char;
    }
    writeln(S);
}

Measured memory_bytes: 256
import java.math.BigDecimal;
import java.math.RoundingMode;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {

        Scanner sc = new Scanner(System.in);

        long a = sc.nextLong();
        double b = sc.nextDouble();


        BigDecimal total = BigDecimal.valueOf(a);
        BigDecimal result = total.multiply(BigDecimal.valueOf(b));

        System.out.println(result.setScale(0, RoundingMode.DOWN));
    }
}

Measured memory_bytes: 29224
#include "bits/stdc++.h"
using namespace std;

#define ASC(vec) vec.begin(), vec.end()		// 昇順ソート 例：sort(ASC(vec));
#define DESC(vec) vec.rbegin(), vec.rend()	// 降順ソート 例:sort(DESC(vec));
#define rep(i, n) for(int i = 0; i < n; i++)
#define Rep(i, n) for(int i = 1; i < n; i++)
#define In(vec) rep(i, n) cin>>vec[i];
#define ANS(s) cout << s << endl
#define inc(a, b) cin >> a >> b;

const int mod = 1000000007;
const int inf = (int)1e9 + 7;
const long long INF = 1LL << 60;

typedef long long ll;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<pair<int, int>> vii;

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; }

ll GCD(ll a, ll b) { return b ? GCD(b, a % b) : a; }
int round_int(int a, int b) { return (a + (b - 1)) / b; }


// 4,8方向に探索する際に用いる配列
//int dx[4] = { 0,  0, 1, -1 };
//int dy[4] = { 1, -1, 0,  0 };
int dx[8] = { 1, 0, -1,  0, 1, -1, -1,  1 };
int dy[8] = { 0, 1,  0, -1, 1,  1, -1, -1 };

constexpr auto MAX = 100010;

// ────────────────────────────────────────────────────

int main() {
	int a;
	string s;
	cin >> a >> s;

	if (a >= 3200) cout << s << endl;
	else {
		cout << "red" << endl;
	}
}

Measured memory_bytes: 256
from collections import Counter
from itertools import product

n = int(input())
d = Counter(list(map(int, input().split())) + [0])

ans, cnt = [], []
for num in d:
    if d[num] > (2 - (num in {0, 12})):
        print(0)
        exit()
    elif ((num in {0, 12}) and d[num] == 1) or d[num] == 2:
        ans += list(set([num, (24 - num) % 24]))
    elif d[num] == 1:
        cnt.append(num)

s = 0
if len(cnt) == 0:
    s = min(ans[i] - ans[i - 1] for i in range(1, len(ans)))
for bit in product([1, -1], repeat=len(cnt)):
    tmp = ans[:]
    tmp += [(ci - 12) * bi + 12 for bi, ci in zip(bit, cnt)]
    tmp = sorted(tmp + [i + 24 for i in tmp])
    stmp = min(tmp[i] - tmp[i - 1] for i in range(1, len(tmp)))
    s = max(s, stmp)
print(s)


Measured memory_bytes: 68100
S=input()
Q=int(input())
fb=True
forward=""
back=""

for i in range(Q):
    query=input()
    if(query=="1"):
        fb=False if(fb) else True
    else:
        query, F, C =query.split()
        if((F=="1")==fb):
            forward=C+forward
        else:
            back=back+C
print((forward+S+back)[::1 if(fb) else -1])

Measured memory_bytes: 4404
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll mod = 1e9 + 7;

int main()
{
	int N, W;
	cin >> N >> W;
	vector<ll> w(N), sum(N);
	for (int i = 0; i < N; i++) {
		cin >> w[i];
	}
	sort(w.rbegin(), w.rend());
	sum[N - 1] = w[N - 1];
	for (int i = N - 2; i >= 0; i--) {
		sum[i] = sum[i + 1] + w[i];
	}
	vector<vector<ll>> dp(N + 1, vector<ll>(W + 1));
	dp[0][0] = 1;
	for (int i = 0; i < N; i++) {
		for (int j = 0; j <= W; j++) {
			if (j + sum[i] > W) {
				dp[i + 1][j] = dp[i][j];
			}
		}
		for (int j = 0; j <= W - w[i]; j++) {
			dp[i + 1][j + w[i]] = (dp[i + 1][j + w[i]] + dp[i][j]) % mod;
		}
	}
	ll res = 0;
	for (int i = 0; i <= W; i++) {
		res = (res + dp[N][i]) % mod;
	}
	cout << res << endl;
	return 0;
}

Measured memory_bytes: 18680
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <utility>
#include <vector>

#define REP(i,s,n) for(int i=(int)(s);i<(int)(n);i++)

using namespace std;
typedef long long int ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef pair<int, int> PI;
const ll mod = 1e9 + 7;

VL mul(const VL &a, const VL &b) {
  int n = a.size();
  VL ret(2 * n - 1);
  REP(i, 0, n) {
    REP(j, 0, n) {
      ret[i + j] += a[i] * b[j];
      ret[i + j] %= mod;
    }
  }
  for (int i = n - 2; i >= 0; --i) {
    ret[i] += ret[i + n];
    ret[i] %= mod;
  }
  return VL(ret.begin(), ret.begin() + n);
}


int main(void) {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, m, k;
  cin >> n >> m >> k;
  VL a(n, 0);
  VL sum(n, 0);
  a[0] = 1;
  sum[0] = 1;
  REP(et, 0, m) {
    int p;
    cin >> p;
    a[p % n] += 1;
  }
  VL cur(a);
  while (k > 0) {
    if (k % 2) {
      sum = mul(sum, cur);
    }
    cur = mul(cur, cur);
    k /= 2;
  }
  REP(i, 0, n) {
    cout << sum[i] << "\n";
  }
}

Measured memory_bytes: 3228
#include <bits/stdc++.h>
#include <sys/types.h>
#include <unistd.h>

#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)

#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=int(a)-1;i>=int(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)

#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define getidx(ary,key) lower_bound(_all(ary),key)-begin(ary)
#define clr(a,b) memset((a),(b),sizeof(a))
#define bit(n) (1LL<<(n))
#define popcount(n) (__builtin_popcountll(n))

using namespace std;

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

using ll=long long;
using R=long double;
const R EPS=1e-9L; // [-1000,1000]->EPS=1e-8 [-10000,10000]->EPS=1e-7
inline int sgn(const R& r){return(r > EPS)-(r < -EPS);}
inline R sq(R x){return sqrt(max(x,0.0L));}

template<typename T> vector<T> make_vector(size_t sz){
	return vector<T>(sz);
}

template<typename T,typename... Ts> 
auto make_vector(size_t sz, Ts... ts){
	return vector<decltype(make_vector<T>(ts...))>(sz, make_vector<T>(ts...));
}

template<typename T,typename U,typename... V> 
typename enable_if<is_same<T, U>::value!=0>::type 
fill_value(U &u, const V... v){
	u=U(v...);
}

template<typename T,typename U,typename... V>
typename enable_if<is_same<T, U>::value==0>::type
fill_value(U &u, const V... v){
	for(auto &e:u){
		fill_value<T>(e,v...);
	}
}

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 pid_t pid = getpid();
// Problem Specific Parameter:

int main(void){
	int m, d;
	cin >> m >> d;

	int ans = 0;
	rep(i, 1, m + 1) rep(j, 10, d + 1){
		if (j / 10 == 1 or j % 10 == 1) continue;
		const int p = (j / 10) * (j % 10);
		if (i == p) ans++;
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
def rren(): return list(map(int, input().split()))


N, M = rren()
road = [[0 for i in range(N+1)] for j in range(N+1)]

for i in range(M):
    a, b = rren()
    road[a][b] += 1
    road[b][a] += 1

for i in range(1, N+1):
    count = 0
    for j in range(1, N+1):
        count += road[i][j]
    print(count)


Measured memory_bytes: 3060
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s = scan.next();
		for (int i = 0; i < s.length(); i++) {
			if (i % 2 == 0) {
				System.out.print(s.charAt(i));
			}
		}
		System.out.println();
	}
}

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

//---- How Many Divisors?
int main(){
    int a, b, c, cnt=0;
    cin >> a >> b >> c;
    for (int i=a; i<=b; i++)
    {
        if((c%i)==0){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 3088
#include<cstdio>
#include<iostream>
#include<vector>
using namespace std;

bool binarySearch(vector<int> &S,int num){
    int l = 0;
    int r = S.size()-1;
    int mid = l+(r-l)/2;
    while(l<=r){
        if(S[mid]==num) return true;
        else if(S[mid] > num) r = mid-1;
        else l = mid+1;  //ever wrong  loss l
        mid =  l+(r-l)/2; //ever wrong loss
    }
    return false;
}

int numInS(vector<int> &S,vector<int> &T){
    if(S.size()==0 || T.size()==0) return 0;
    int res = 0;
    for(int i =0;i<T.size();i++){
        if(binarySearch(S,T[i])) res++;
    }
    //return 0;
    return res;
}

int main(){
    int n,q;

    cin >> n;
    vector<int> S(n);
    for(int i=0;i<n;i++) cin>>S[i];
    cin >> q;
    vector<int> T(q);
    for(int i=0;i<q;i++) cin>>T[i];
    /*
    n = 5;
    q = 2;
    vector<int> S={1,4,5,6};
    vector<int> T = {1,2};*/
    cout << numInS(S,T) << endl;
    return 0;
}



Measured memory_bytes: 3340
#include<bits/stdc++.h>
using namespace std;
#define FIO ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
int main()
{
    FIO;
    int n,i,c=0;
    cin>>n;
    vector<int>v(n);
    for(i=0; i<n; i++)
        cin>>v[i];
    for(i=0; i<n; i++)
        if(v[i]==c+1)
            c++;
    if(c==0)
        cout<<"-1"<<endl;
    else
        cout<<min(n-1,n-c)<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
using namespace std;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)

int main() {
	cin.tie(0); ios_base::sync_with_stdio(false);
	int n, m; cin >> n >> m;

	vector<pair<int, int>> p;
	rep(i, 0, n) {
		int a, b; cin >> a >> b;
		p.emplace_back(a, b);
	}
	sort(p.begin(), p.end());

	int j = 0;
	priority_queue<int, vector<int>> pq;
	int ans = 0;
	rep(i, 1, m + 1) {
		// 終了i日前
		while (j < n && p[j].first <= i) pq.push(p[j++].second);
		if (!pq.empty()) {
			ans += pq.top();
			pq.pop();
		}
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 4732
/* tempate
 *
 *
 */

#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <queue>
#include <deque>
#include <list>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>

using namespace std;


#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define repr(i,n) for(int (i)=(n); (i)>=(0); (i)--)
#define SIZE(x) ((int)(x).size())
#define GCD(a, b) int gcd(int a,int b){return b?gcd(b,a%b):a;}
#define QP(a, b) int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define all(v) (v).begin(),(v).end()


template<typename T> void chmax(T &a, T b) {a = max(a, b);}
template<typename T> void chmin(T &a, T b) {a = min(a, b);}
template<typename T> void chadd(T &a, T b) {a = a + b;}
template<typename A, size_t N, typename T>
void FILL(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

typedef vector<int, int> vint;
typedef pair<int,int> pint;
typedef vector<pint>vpint;
typedef long long ll;

int dx[] = {0, 0, 1, -1};
int dy[] = {1, -1, 0, 0};
const ll INF = 1LL << 60;
const ll MOD = 1000000007LL;


int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n; cin >> n;
    vector<ll> h(n);
    bool f = false;
    for(ll i = 0; i < n; i++){
        cin >> h[i];
        if(i == 0) continue;
        if(h[i - 1] <= h[i] - 1) h[i]--;
        if(h[i - 1] > h[i]) f = true;
    }
    if(f) cout << "No";
    else cout << "Yes";
    cout << endl;
    return 0;
}


Measured memory_bytes: 1024
s = input()
tapflag = True

for p in range(len(s)):
  if p % 2 == 0:
    if s[p] != 'R' and s[p] != 'U' and s[p] != 'D':
      tapflag = False
  if p % 2 == 1:
    if s[p] != 'L' and s[p] != 'U' and s[p] != 'D':
      tapflag = False
      
if tapflag:
  print('Yes')
else:
  print('No')

Measured memory_bytes: 9032
#include <iostream>
#include <queue>
#include <map>
#include <vector>
#include <cstring>
#include <algorithm>
using namespace std;

int R;
int x[2], y[2], w[2], h[2];
int level[2][501][501];
int seen[501][501];

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

struct state {
  int l,x,y;
  state(const int _l, const int _x, const int _y) : l(_l), x(_x), y(_y) {}
  bool operator<(const state &rhs) const {
    return (l != rhs.l) ? l > rhs.l : x < rhs.x;
  }
};

vector<pair<int,int> > bfs(int k) {
  memset(seen, 0, sizeof(seen));
  priority_queue<state> q; q.push(state(1, x[k], y[k]));
  vector<pair<int,int> > v(1, make_pair(0,0));
  seen[y[k]][x[k]] = 1;
  int cnt = 0, cl = 0;
  while(!q.empty()) {
    cl = q.top().l;
    while(!q.empty() && q.top().l <= cl) {
      const state s = q.top(); q.pop();
      int x = s.x, y = s.y;
      cnt++;
      for (int i=0; i<4; ++i) {
        int nx = x + dx[i], ny = y+dy[i];
        if (nx < 0 || nx >= w[k] || ny < 0 || ny >= h[k]) continue;
        if (seen[ny][nx]) continue; seen[ny][nx] = 1;
        q.push(state(level[k][ny][nx], nx, ny));
      }
    }
    v.push_back(make_pair(cl, cnt));
  }
  return v;
}

int main() {
  while(cin>>R, R) {
    for (int i=0; i<2; ++i) {
      cin>>w[i]>>h[i]>>x[i]>>y[i]; x[i]--, y[i]--;
      for (int j=0; j<h[i]; ++j)
        for (int k=0; k<w[i]; ++k) cin>>level[i][j][k];
    }

    vector<pair<int,int> > v1, v2;
    v1 = bfs(0);
    v2 = bfs(1);
    vector<int> l1, l2, r1, r2;
    for (int i=0; i<v1.size(); ++i) {
      l1.push_back(v1[i].first);
      r1.push_back(v1[i].second);
    }
    for (int i=0; i<v2.size(); ++i) {
      l2.push_back(v2[i].first);
      r2.push_back(v2[i].second);
    }

    int ans = 1<<29;
    for (int i=0; i<v1.size(); ++i) {
      int need = R-r1[i];
      int d = lower_bound(r2.begin(), r2.end(), need) - r2.begin();
      if (d == r2.size()) continue;
      //cout<<l1[i]<<" "<<l2[d]<<" "<<d<<" "<<r2[d]<<" "<<r1[i]<<endl;
      ans = min(ans, l1[i]+l2[d]);
    }
    cout<<ans<<endl;
  }
}

Measured memory_bytes: 8352
#include <cstdio>
#include <cstdlib>
using namespace std;

int main(){
    int N,M;
    long long a[50][2];
    long long c[50][2];
    long long d[50][2];

    scanf("%d",&N);
    scanf("%d",&M);

    for(int i=0;i<N;i++){
        scanf("%lld",&a[i][0]);
        scanf("%lld",&a[i][1]);
    }
    for(int i=0;i<M;i++){
        scanf("%lld",&c[i][0]);
        scanf("%lld",&c[i][1]);
    }

    for(int i=0;i<N;i++){
        d[i][0] = abs(a[i][0]-c[M-1][0])+abs(a[i][1]-c[M-1][1]);
        d[i][1] = M-1;
        for(int j=M-2;j>=0;j--){
            long long l = abs(a[i][0]-c[j][0])+abs(a[i][1]-c[j][1]);
            if(d[i][0]>=l){
                d[i][0] = l;
                d[i][1] = j;
            }
        }
    }

    for(int i=0;i<N;i++){
        //printf("%lld\n",d[i][0]);
        printf("%lld\n",d[i][1]+1);
    }

    return 0;
}


Measured memory_bytes: 128
#include <iostream>
using namespace std;
typedef long long ll;
ll n, h[100010], dp[100010];
int main(void){
    // Your code here!
    cin >> n;
    for (ll i = 0; i < n; i++) cin >> h[i];
    dp[1] = abs(h[1] - h[0]);
    for (ll i = 2; i < n; i++)
    {
        dp[i] = min(dp[i - 2] + abs(h[i] - h[i - 2]), dp[i - 1] + abs(h[i] - h[i - 1]));
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1792
/*input
7
1 2 3 1000000000 4 5 6
*/
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
using namespace std;
using namespace __gnu_pbds;
#define REP(i,j,k)     for(int i = j ; i < k ; ++i)
#define RREP(i,j,k)    for(int i = j ; i >=k ; --i)
#define A    first
#define B    second
#define mp   make_pair
#define pb   emplace_back
#define PII pair<int , int>
#define MEM(i,j)   memset(i , j , sizeof i)
#define ALL(i)     i.begin() , i.end()
#define DBGG(i,j)     cout << i << " " << j << endl
#define DB4(i,j,k,l)  cout << i << " " << j << " " << k << " " << l << endl
#define IOS cin.tie(0) , cout.sync_with_stdio(0)
#define endl "\n"
///------------------------------------------------------------
#define int long long
#define MAX 200800
#define INF 0x3f3f3f3f

int n , x[MAX] , pre[MAX];
PII fr[MAX] , ba[MAX];
int S(int ql , int qr){ return pre[qr] - pre[ql - 1]; }
int solve(int a , int b , int c , int d){ return abs(S(a , b) - S(c , d)); }
int C(int a , int b , int c , int d){
	int sol[] = {a , b , c , d} , big = a - b;
	REP(i , 0 , 4) REP(j , 0 , 4) big = max(big , sol[i] - sol[j]);
	return big;
}
int32_t main(){
	IOS;
	cin >> n;
	REP(i , 1 , n + 1) cin >> x[i];

	REP(i , 1 , n + 1) pre[i] = pre[i - 1] + x[i];

	int pos = 1;
	REP(i , 2 , n + 1){
		while(pos + 1 != i && solve(1 , pos , pos + 1 , i) > solve(1 , pos + 1 , pos + 2 , i)) pos ++;
		fr[i] = mp(S(1 , pos) , S(pos + 1 , i));
	}
	pos = n;
	RREP(i , n - 1 , 1){
		while(pos - 1 != i && solve(i , pos - 1 , pos , n) > solve(i , pos - 2 , pos - 1 , n)) pos --;
		ba[i] = mp(S(i , pos - 1) , S(pos , n));
	}
	int ans = 1e15;
	REP(i , 2 , n){
		if(i + 1 == n) continue;
		ans = min(ans , C(fr[i].A , fr[i].B , ba[i + 1].A , ba[i + 1].B));
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 9728
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} cout << a[a.size()-1] << endl;}
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<class T>void prarr(vector<vector<T>>& a){
rep(i, a.size()){
rep(j, a[i].size()){
cout << a[i][j]; printf(" ");}
printf("\n");} printf("\n");}

int getdigit(int n){
    int k = 10000;
    int dig = 5;
    while(k>0){
        if(n/k>0) return dig;
        dig--;
        k /= 10;
    }
    return -1;
}

int joint(int a, int b){
    int c = getdigit(b);
    a *= (int)pow(10, c);
    return a + b;
}

int main()
{
    int n; cin >> n;
    arr<int> a(5);

    rep(i, n){
        int t; cin >> t;
        a[getdigit(t)-1].push_back(t);
    }
    // prarr(a);

    arr<int> b;
    int num=0, ai=0;
    while(num<3){
        if(a[ai].size()==0) {
            ai++;
            continue;
        }
        num += a[ai].size();
        b.push_back(a[ai++]);
    }
    rep(i, b.size()) sort(ALL(b[i]));
    // prarr(b);
    if(b.size()==3){
        pr(min(joint(b[0][0], b[2][0]), joint(b[2][0], b[0][0])));
    }else if(b.size()==1){
        if(b[0].size()==3) pr(joint(b[0][1], b[0][0]));
        else pr(joint(b[0][0], b[0][3]));
    }else if(b[0].size()==2){
        pr(min(joint(b[0][0], b[1][0]), joint(b[1][0], b[0][0])));
    }else{
        //まず、b[1]の2つ目とb[0][0]のjointを全てとる。
        vector<int> c;
        rep(i, 2) {
            c.push_back(joint(b[0][0], b[1][i]));
            c.push_back(joint(b[1][i], b[0][0]));
        }
        // b[1]のサイズが3以上ならば、b[1][2]とのjointも含める。
        if(b[1].size()>2){
            c.push_back(joint(b[0][0], b[1][2]));
            c.push_back(joint(b[1][2], b[0][0]));
        }
        sort(ALL(c));
        pr(c[2]);
    }
    return 0;}


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

#define X first
#define Y second
#define MP make_pair

using namespace std;

typedef long long ll;

const int N = 1e5 + 1;

int n, q;
ll t[N], add[N], sq[N], sz;

int main () {
	scanf("%d %d\n", &n, &q);
	sq[0] = n;
	for(;q;q--){
		ll x;
		scanf("%lld\n", &x);
		while(sz >= 0 && sq[sz] > x){
			sz--;	
		}
		sq[++sz] = x;
	}
	for(int j = sz;j >= 0;j--){
		if(j == sz)
			t[j] = 1;
		for(int idx = j - 1;idx >= 0;idx--){
			int tl = 0, tr = idx;
			bool can = 0;	
			while(tl <= tr){
				int tm = (tl + tr) / 2;
				if(sq[tm] <= sq[j])
					tl = tm + 1, idx = tm, can = 1;	
				else
					tr = tm - 1;
			}
			if(!can)
				break;
			t[idx] += t[j] * (sq[j] / sq[idx]);
			sq[j] %= sq[idx];
		}	
		add[sq[j]] += t[j];
	}
	for(int i = n - 1;i >= 1;i--)
		add[i] += add[i + 1];
	for(int i = 1;i <= n;i++)
		printf("%lld\n", add[i]);
}

Measured memory_bytes: 6152
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str

def solve(N: int, L: "List[int]"):
    L.sort(reverse=True)
    print(YES) if(L[0] < sum(L[1:])) else print(NO)
    return


# Generated by 1.1.3 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    L = [ int(next(tokens)) for _ in range(N) ]  # type: "List[int]"
    solve(N, L)

if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
def main():
  n,k,*t=map(int,open(0).read().split())
  e=[set()for _ in[0]*n]
  for a,b in zip(t[::2],t[1::2]):
    e[a-1]|={b-1}
    e[b-1]|={a-1}
  c,q=k,[0]
  while q:
    v,i=q.pop(),1
    for w in e[v]:
      c=c*(k-i-(v>0))%(10**9+7)
      e[w].discard(v)
      q+=w,
      i+=1
  print(c)
main()

Measured memory_bytes: 49216
#include <bits/stdc++.h>
#include <boost/range/algorithm.hpp>
#include <boost/range/numeric.hpp>
#include <boost/integer/common_factor.hpp>
#include <boost/integer/common_factor_rt.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>

using std::string;
using std::vector;
using std::set;
using std::multiset;
using std::unordered_set;
using std::map;
using std::multimap;
using std::unordered_map;
using std::pair;
using std::cin;
using std::cout;

typedef uintmax_t    ull;
typedef intmax_t     ll;
typedef uint64_t     ul;
typedef uint32_t     ui;
typedef uint8_t      uc;

typedef boost::multiprecision::number<boost::multiprecision::cpp_dec_float<1000>> cpp_dec_float_1000;

constexpr char CRLF  = '\n';
constexpr char SPACE = ' ';
constexpr char VECTOR_COUT_SEPARATOR = SPACE;
constexpr ll INF = 1000'000'007;

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; }
template<class T> std::ostream& operator<< (std::ostream& os, const std::vector<T>& vc) { for(auto it = vc.begin(); it != vc.end(); ++it) { if (std::next(it) == vc.end()) os << *it; else os << *it << VECTOR_COUT_SEPARATOR; } return os; }
template<class T1, class T2> inline std::ostream & operator<< (std::ostream & os, const std::pair<T1, T2> & p) { return os << p.first << ' ' << p.second; }

void solve(void)
{
  int a, b; cin >> a >> b;
  ll res{};
  for (int i = a; i <= b; ++i) {
    std::string s = std::to_string(i);
    std::string t{s.rbegin(), s.rend()};
    if (s == t) {
      ++res;
    }
  }

  cout << res << CRLF;
  return;
}

int main(void)
{
  std::ios_base::sync_with_stdio(false);
  std::cin.tie(0);

  solve();

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <string>

using namespace std;

class Dice {
	private:
		map<char, int> dice;

	public:
		Dice(int _I, int _II, int _III, int _IV, int _V, int _VI);
		int GetNumber(char c);
		void roll_E();
		void roll_N();
		void roll_S();
		void roll_W();
};

Dice::Dice(int _I, int _II, int _III, int _IV, int _V, int _VI) {
	dice['T'] = _I;
	dice['S'] = _II;
	dice['E'] = _III;
	dice['W'] = _IV;
	dice['N'] = _V;
	dice['B'] = _VI;
}

int Dice::GetNumber(char c) {
	return dice[c];
}

void Dice::roll_E() {
	map<char, int> tmp = dice;	
	dice['T'] = tmp['W'];
	dice['E'] = tmp['T'];
	dice['W'] = tmp['B'];
	dice['B'] = tmp['E'];
}

void Dice::roll_N() {
	map<char, int> tmp = dice;	
	dice['T'] = tmp['S'];
	dice['S'] = tmp['B'];
	dice['N'] = tmp['T'];
	dice['B'] = tmp['N'];
}

void Dice::roll_S() {
	map<char, int> tmp = dice;	
	dice['T'] = tmp['N'];
	dice['S'] = tmp['T'];
	dice['N'] = tmp['B'];
	dice['B'] = tmp['S'];
}

void Dice::roll_W() {
	map<char, int> tmp = dice;	
	dice['T'] = tmp['E'];
	dice['E'] = tmp['B'];
	dice['W'] = tmp['T'];
	dice['B'] = tmp['W'];
}

int main() {
	int I, II, III, IV, V, VI;
	cin >> I >> II >> III >> IV >> V >> VI;
	Dice dice(I, II, III, IV, V, VI);

	string op;
	cin >> op;
	for (unsigned int i = 0; i < op.size(); i++) {
		if (op[i] == 'E') {
			dice.roll_E();
		}
		if (op[i] == 'N') {
			dice.roll_N();
		}
		if (op[i] == 'S') {
			dice.roll_S();
		}
		if (op[i] == 'W') {
			dice.roll_W();
		}
	}
	cout << dice.GetNumber('T') << endl;
	// std::cout << "\e[38;5;0m\e[48;5;40m --- end ---  \e[m" << std::endl; // debug
	return 0;
}



Measured memory_bytes: 3236
#include <iostream>
#include <set>

using namespace std;

int main()
{
	int n;
	string *str, old;
	set<string> s; 

	cin >> n;
	str = new string[n];
	cin >> str[0];
	s.insert(str[0]);
	old = str[0];
	for (int i = 1; i < n; i++) {
		cin >> str[i];
		if (old[old.size() - 1] != str[i][0]) {
			cout << "No" << endl;
			return 0;
		} else {
			if (s.count(str[i]) != 0) {
				cout << "No" << endl;
				return 0;
			} else {
				s.insert(str[i]);
				old = str[i];
			}
		}
	}

	cout << "Yes" << endl;

	delete[] str;
	return 0;
}


Measured memory_bytes: 256
from collections import deque
 
H, W = map(int, input().split())
S = [input() for _ in range(H)]

INF = 10**15
graph = [[] for _ in range(H * W)]
 
for i in range(H):
  for j in range(W):
    for ni, nj in [(i - 1, j), (i + 1, j), (i, j - 1), (i, j + 1)]:
      if 0 <= ni < H and 0 <= nj < W and S[ni][nj] != "#":
        graph[W * i + j].append((W * ni + nj, 1))

answer = 0
for i in range(H):
  for j in range(W):
    if S[i][j] == "#":
      continue
    else:
      dist = [INF for _ in range(H * W)]
      dist[W * i + j] = 0
      stack = deque([W * i + j])
      while stack:
        s = stack.popleft()
        for g, w in graph[s]:
          if dist[g] > dist[s] + w:
            dist[g] = dist[s] + w
            stack.append(g)
      for ii in range(H * W):
        if dist[ii] != INF:
          answer = max(answer, dist[ii])
      
print(answer)

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

public class Program
{
	public static void Main()
	{
        //int[] num = Console.ReadLine().Split(' ').Select(n => int.Parse(n)).ToArray();
        int a = int.Parse(Console.ReadLine());
        int b = int.Parse(Console.ReadLine());
        int c = int.Parse(Console.ReadLine());
        
        Console.WriteLine((a + b)*c/2);
	}
}

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

int64_t n;

void f(int64_t x,int64_t &res,int bit){
  if(x>n)return;
  if(bit==0b111)res++;
  
  f(x*10+5,res,bit|0b001);
  f(x*10+7,res,bit|0b010);
  f(x*10+3,res,bit|0b100);
}

int main(){
  cin >>n;
  int64_t res=0;
  f(0,res,0);
  cout <<res<<endl;
}

Measured memory_bytes: 256
import sys

read = sys.stdin.readline

N = int(read())
A = list(map(int, read().split()))
B = list(map(int, read().split()))

d = [i - j for i, j in zip(A, B)]
d.sort()
if d[0] >= 0:
    print(0)
    exit()
elif sum(d) < 0:
    print(-1)
    exit()

n = 0
below = 0
for i in d:
    if i < 0:
        below += i
        n += 1
    else:
        break

for i in d[::-1]:
    below += i
    n += 1
    if below > 0:
        print(n)
        exit()

Measured memory_bytes: 19124
#include <bits/stdc++.h>
#include <map>
#include <set>
#include <vector>
#include <algorithm>
#include <iostream>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <iomanip>
#include <math.h>
#include <time.h>
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)n; i++)
#define repf(i, a, b) for (ll i = (ll)a; i < (ll)b; i++)
#define repr(i, a, b) for (ll i = (ll)a; i > (ll)b; i--)
#define all(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define pb(x) push_back(x)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int infi = 2147483600;
const ll infl = 1e17;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    ll n, k;
    cin >> n >> k;
    vll a(n);
    ll A = 0;
    rep(i, n) {
        
        cin >> a[i];
        A += a[i];
    }
    set<ll> yaku;
    for (ll d = 1; d * d <= A;d++){
        if (A%d==0){
            yaku.insert(d);
            yaku.insert(A / d);
        }
    }
    ll ans = 1;
    for (auto y:yaku){
        vll res(n);
        rep(i, n) res[i] = a[i] % y;
        sort(all(res));
        vll s(n + 1, 0);
        rep(i, n) s[i + 1] = s[i] + res[i];
        int idx = 0;
        ll mae = 0;
        while (idx<n && mae+res[idx]<=k){
            mae += res[idx];
            idx++;
        }
        if (y * (n - idx) - s[n] + s[idx] <= k)
        {
            ans = y;
        }

    }
    cout << ans << endl;
}


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

#define ll long long int
#define ull unsigned long long int
#define pb push_back
#define mk make_pair
#define mod 1000000007
#define mo 998244353
string str;
//map<int, int>::iterator itr; 
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int x;cin>>x;
    if(x>=30){
        cout<<"Yes";
    }
    else{
        cout<<"No";
    }
    return 0;
}


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

int main(){
    string S;

    cin >> S;

    if (S == "SUN"){
        cout << 7;
    } else if (S == "MON")
    {
        cout << 6;
    } else if (S == "TUE")
    {
        cout << 5;
    } else if (S == "WED")
    {
        cout << 4;
    } else if (S == "THU")
    {
        cout << 3;
    } else if (S == "FRI")
    {
        cout << 2;
    } else if (S == "SAT")
    {
        cout << 1;
    }
    
    
    
    
    
    
}

Measured memory_bytes: 256
import java.util.*;

import javax.lang.model.util.ElementScanner6;

public class Main {
	public static void main(String[] args)  {
		Scanner scan = new Scanner(System.in);
		int n=Integer.parseInt(scan.next());
		int m=Integer.parseInt(scan.next());
		int sumA=0;
		for (int i=0;i<m;++i){
			sumA+=Integer.parseInt(scan.next());
		}
		if (sumA>n){
			System.out.print(-1);
		}else{
			System.out.print(n-sumA);
		}




	}
}
//end

Measured memory_bytes: 41732
#include <vector>
#include <iostream>
#include <cmath>
#include <map>
#include <algorithm>
#include <fstream>
#include <unistd.h>
#include <string>
#include <numeric>
#include <queue>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vector<int>> vvi;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<string> vs;
typedef vector<vector<string>> vvs;
typedef vector<char> vc;
typedef vector<vector<char>> vvc;
typedef pair<int, int> P;
typedef vector<P> vp;
typedef vector<vector<P>> vvp;
const int INF = 1001001001;
const ll LINF = 1e18;
const string endstr = "\n";

template <typename T>
T gcd(T a, T b) {
    if(a < b) gcd(b, a);
    T r;
    while((r=a%b)) {
        a = b; b = r;
    }
    return b;
}

bool isin(P p1, P p2){
    return p1.first < p2.first && p1.second < p2.second;
}

int main(){
    int N; cin >> N;
    vp rs(N, P(0, 0)), bs(N, P(0, 0));
    for (int i = 0; i < N; i++) {
        int x, y; cin >> x >> y;
        rs[i] = P(x,y);
    }
    for (int i = 0; i < N; i++) {
        int x, y; cin >> x >> y;
        bs[i] = P(x,y);
    }
    
    sort(bs.begin(), bs.end(), [](const P p1, const P p2){return p1.first < p2.first;});
    sort(rs.begin(), rs.end(), [](const P p1, const P p2){return p1.second > p2.second;});
    
    ll ret = 0;
    vb b_used(2 * N  + 1, false);  vb r_used(2 * N  + 1, false);
    for(int i = 0; i < N; i++){
        if(b_used[i]) continue;
        for (int j = 0; j < N; j++){
            if(r_used[j]) continue;
            if(isin(rs[j], bs[i])){
                ret++;
                b_used[i]= true; r_used[j] = true;
                break;
            }
        }
    }
    
    cout << ret << endstr;
    return 0;
}


Measured memory_bytes: 256
import heapq

X, Y, Z, K = map(int, input().split())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
C = list(map(int, input().split()))


A = sorted(A, reverse=True)
B = sorted(B, reverse=True)
C = sorted(C, reverse=True)
heap = []
already = [[[] for _ in range(Y)] for _ in range(X)]
maxv = A[0]+B[0]+C[0]
heapq.heapify(heap)
heapq.heappush(heap, (0, 0, 0, 0))


def ans(v):
    return maxv - v


for i in range(K):
    res, x, y, z = heapq.heappop(heap)
    print(ans(res))
    if x + 1 < X and z not in already[x+1][y]:
        heapq.heappush(heap, (ans(A[x+1]+B[y]+C[z]), x+1, y, z))
        already[x+1][y].append(z)
    if y + 1 < Y and z not in already[x][y+1]:
        heapq.heappush(heap, (ans(A[x]+B[y+1]+C[z]), x, y+1, z))
        already[x][y+1].append(z)
    if z + 1 < Z and z+1 not in already[x][y]:
        heapq.heappush(heap, (ans(A[x]+B[y]+C[z+1]), x, y, z+1))
        already[x][y].append(z+1)


Measured memory_bytes: 89052
#!/usr/bin/env python3
import sys


def solve(N: int, W: int, w: "List[int]", v: "List[int]"):
    dp = [[0] * (N + 1) for _ in range(W+1)]

    for i in range(1, W+1):
        for j in range(N):
            if i - w[j] >= 0:
                dp[i][j+1] = max(dp[i][j], dp[i-1][j], dp[i-w[j]][j] + v[j])
            else:
                dp[i][j+1] = max(dp[i][j], dp[i-1][j])

    print(dp[-1][-1])


def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    N = int(next(tokens))  # type: int
    W = int(next(tokens))  # type: int
    w = [int()] * (N)  # type: "List[int]"
    v = [int()] * (N)  # type: "List[int]"
    for i in range(N):
        w[i] = int(next(tokens))
        v[i] = int(next(tokens))
    solve(N, W, w, v)


if __name__ == '__main__':
    main()


Measured memory_bytes: 130524