akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

int main () {
    string s, t;
    getline(cin, s);
    getline(cin, t);

    int dp[s.size()+1][t.size()+1];
    for(int i=0; i<=s.size(); i++) {
        for(int j=0; j<=t.size(); j++) {
            if(i==0 || j==0) {
                dp[i][j] = 0;
            } else if(s[i-1] == t[j-1]) {
                dp[i][j] = 1 + dp[i-1][j-1];
            } else {
                dp[i][j] = max(dp[i-1][j], dp[i][j-1]);
            }
        }
    }

    string answer = "";

    int times = dp[s.size()][t.size()];
    int i = s.size();
    int j = t.size();
    while(dp[i][j]) {
        if(dp[i][j-1] == dp[i][j]) {
                --j;
        } else if(dp[i-1][j] == dp[i][j]) {
            i--;
        } else if(dp[i][j] == dp[i-1][j-1] + 1) {
            answer+=s[i-1];
            --i;--j;
        }
    }
    reverse(answer.begin(), answer.end());
    cout << answer;

    return 0;
}


Measured memory_bytes: 35456
S = gets.chomp.scan(/.{1,#{2}}/).map(&:to_i)
if S[0] >= 13 && S[1] >= 13 || S[0] >= 13 && S[1] == 0 || S[0] == 0 && S[1] >= 13 || S[0] == 0 && S[1] == 0
  puts "NA"
elsif S[0] <= 12 && S[1] <= 12 && S[0] != 0 && S[1] != 0
  puts "AMBIGUOUS"
elsif S[0] <= 12 && S[1] >= 12 || S[0] <= 12 && S[1] == 0
  puts "MMYY"
else
  puts "YYMM"
end

Measured memory_bytes: 1916
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n, s, c, a[N], b[N];
int main()
{
	ll i;
	cin >> n;
	for (i = 1; i <= n; i++) scanf("%lld", &a[i]), s += a[i], b[i] = a[i] - a[i - 1];
	b[1] = a[1] - a[n];
	if (s % (n * (n + 1) / 2)) {cout << "NO"; return 0;}
	s /= n * (n + 1) / 2;
	for (i = 1; i <= n; i++) {
		if (s < b[i] || (s - b[i]) % n) {cout << "NO"; return 0;}
//		c += (s - b[i]) / n;
	}
//	if (c != s) {cout << "NO"; return 0;}
    cout << "YES" << endl;
    return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int n,k,ans;
char s[100005];
int main(){
    cin>>n>>k;
    for(int i=1;i<=n;i++) cin>>s[i];
    for(int i=1;i<=n;i++)
        if(s[i]==s[i-1]&&s[i]=='L') ans++;
    for(int i=n;i>=1;i--)
        if(s[i]==s[i+1]&&s[i]=='R') ans++;
    ans=min(n-1,ans+2*k);
    cout<<ans;
}

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

#define ll long long
#define vvi vector<vector<int>>
#define vec vector
#define pq priority_queue
#define all(v) (v).begin(), (v).end()
#define uniqueV(x) sort(x.begin(), x.end()); x.erase(unique(x.begin(), x.end()), x.end());
#define rep(i, n) for (int (i) = (0); (i) < (n); ++(i))
#define repp(i, m, n) for (int (i) = (m); (i) < (n); ++(i))
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) cerr<<"("<<#x<<", "<<#y<<") = "<<"("<<x<<", "<<y<<")"<<endl;
#define debug3(x, y, z) cerr<<"("<<#x<<", "<<#y<<", "<<#z<<") = "<<"("<<x<<", "<<y<<", "<<z<<")"<<endl;
#define debugB(value, size) cerr<<#value<<": "<<bitset<size>(value) << endl;
#define line() cerr << "---------------" << endl;

const int dx[] = {1, -1, 0, 0};
const int dy[] = {0, 0, -1, 1};
const double PI = 3.14159265358979323846;

template<typename T>
void printA(vector<T> &printArray, char between = ' ') {
   int paSize = printArray.size();
   for (int i = 0; i < paSize; i++) { cerr << printArray[i] << between;}
   if (between != '\n') {cerr << endl;}
}

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

int n, m;
ll x[1111], y[1111], z[1111];
ll val[1111];

int main() {
   cin >> n >> m;
   rep (i, n) cin >> x[i] >> y[i] >> z[i];

   ll ans = -1e18;
   rep (mask, 8) {
      int a = (mask & 1) ? -1 : 1;
      int b = (mask & 2) ? -1 : 1;
      int c = (mask & 4) ? -1 : 1;
      rep (i, n) {
         val[i] = a * x[i] + b * y[i] + c * z[i];
      }
      sort(val, val + n);
      reverse(val, val+n);
      ll cur = 0;
      rep (i, m) cur += val[i];
      ans = max(ans, cur);
   }
   cout << ans << endl;

   return 0;
}

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

#define f first
#define s second
#define ins insert
#define eb emplace_back
#define endl '\n'
#define ll long long
#define ld long double
#define vl vector<ll>
#define no cout << "NO" << endl
#define yes cout << "YES" << endl
#define tc ll t; cin >> t; while (t--)
#define sz(c) (ll) (c).size()
#define trav(x,c) for(auto &x : c)
#define all(c) (c).begin(), (c).end()
#define rll(c) (c).rbegin(), (c).rend()
#define _for(i,a,n) for(ll i = a ; i < n; ++i)
#define _rfor(i,a,n) for(ll i = n-1 ; i >= a; --i)
#define dx(x) cout << #x << ": " << x << endl;
#define dc(c) trav(x,c) cout << x << " "; cout << endl;
#define godspeed ios::sync_with_stdio(0); cin.tie(0);

int main() {
    godspeed;
    double n; cin >> n;
    double prob = 1;

    prob = fmod(n,2) ? (n/2 + 0.5) / n : 0.5;

    cout << setprecision(6) << fixed << prob;
}

Measured memory_bytes: 3788
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;    using vvi = vector<vi>;
using vb = vector<bool>;   using vvb = vector<vb>;
using vl = vector<ll>;     using vvl = vector<vl>;
using vd = vector<double>; using vvd = vector<vd>;

#define REP(i,n) for(ll i = 0; i < (n); ++i)
#define ALL(c) (c).begin(), (c).end()
#define FOR(i,s,e) for (ll i = s; i < (ll)e; i++)
#define TEN(x) ((ll)1e##x)

struct Edge{ ll weight, to; };
// tuple<ll, ll, ll> = { distance, v1, v2 }
tuple<ll, ll, ll> diameter(const vector<vector<Edge>> & g) {
	// pair<ll, ll> = { distance, node_id }
	function<pair<ll, ll>(ll, ll)> farthest_leaf = [&](ll subtree_root, ll parent_node) {
		if (g[subtree_root].size() == 1 && parent_node != -1) return make_pair(-g[subtree_root][0].weight, subtree_root);
		auto ans = make_pair(0ll, subtree_root);
		for (auto e : g[subtree_root]) if (e.to != parent_node) {
			auto dn = farthest_leaf(e.to, subtree_root);
			dn.first += e.weight;
			if(ans.first < dn.first) ans = dn;
		}
		return ans;
	};

	auto a = farthest_leaf(0, -1);
	auto b = farthest_leaf(a.second, -1);
	return tuple<ll, ll, ll>{ b.first, b.second, a.second };
}


int main() {
#ifdef INPUT_FROM_FILE
	ifstream cin("sample.in");
	ofstream cout("sample.out");
#endif
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(50);
	while (true) {
		ll n; cin >> n;
		if (n == 0) break;

		vl p(n - 1), d(n - 1);
		REP(i, n - 1) cin >> p[i], p[i]--;
		REP(i, n - 1) cin >> d[i];
		vector<vector<Edge>> paths(n);
		REP(i, n - 1) {
			paths[i + 1].push_back({ d[i], p[i] });
			paths[p[i]].push_back({ d[i], i + 1 });
		}

		ll distance, v1, v2;
		tie(distance, v1, v2) = diameter(paths);

		ll sum = 0;
		REP(i, n) for (auto e : paths[i]) if(e.to > i) {
			sum += e.weight * (paths[e.to].size()==1 || paths[i].size() == 1 ? 1 : 3);
		}
		cout << sum - distance << endl;
	}
	return 0;
}

Measured memory_bytes: 3280
// エラトステネスの篩, フェルマーの小定理
package main

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

const (
	m = 1000000007
)

func mpow(x, y int) int {
	result := 1
	for y != 0 {
		if y&1 == 1 {
			result *= x
			result %= m
		}
		x *= x
		x %= m
		y >>= 1
	}
	return result
}

func main() {
	maxA := 1000000

	N := readInt()
	A := make([]int, N)
	for i := 0; i < N; i++ {
		A[i] = readInt()
	}

	sieve := make([]int, maxA+1)
	sieve[0] = -1
	sieve[1] = -1
	for i := 2; i <= maxA; i++ {
		if sieve[i] != 0 {
			continue
		}
		sieve[i] = i
		for j := i * i; j <= maxA; j += i {
			if sieve[j] == 0 {
				sieve[j] = i
			}
		}
	}

	lcmFactors := map[int]int{}
	for i := 0; i < N; i++ {
		t := map[int]int{}
		a := A[i]
		for a != 1 {
			t[sieve[a]]++
			a /= sieve[a]
		}
		for k, v := range t {
			if lcmFactors[k] < v {
				lcmFactors[k] = v
			}
		}
	}

	lcm := 1
	for k, v := range lcmFactors {
		for i := 0; i < v; i++ {
			lcm *= k
			lcm %= m
		}
	}

	result := 0
	for i := 0; i < N; i++ {
		result += lcm * mpow(A[i], m-2)
		result %= m
	}
	fmt.Println(result)
}

const (
	ioBufferSize = 1 * 1024 * 1024 // 1 MB
)

var stdinScanner = func() *bufio.Scanner {
	result := bufio.NewScanner(os.Stdin)
	result.Buffer(make([]byte, ioBufferSize), ioBufferSize)
	result.Split(bufio.ScanWords)
	return result
}()

func readString() string {
	stdinScanner.Scan()
	return stdinScanner.Text()
}

func readInt() int {
	result, err := strconv.Atoi(readString())
	if err != nil {
		panic(err)
	}
	return result
}


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

int n;
long long arr[3005];
long long memo[3005][3005];

long long dp(int p,int x,int y){
	if(x>y)return 0;
	if(x==y){
		if(p==0)return arr[x];
		else return -arr[x];
	}
	if(memo[x][y]!=-1)return memo[x][y];
	if(p==0){
		return memo[x][y]=max(dp(1,x+1,y)+arr[x],dp(1,x,y-1)+arr[y]);
	}else{
		return memo[x][y]=min(dp(0,x+1,y)-arr[x],dp(0,x,y-1)-arr[y]);
	}
}

int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%lld",&arr[i]);
	memset(memo,-1,sizeof(memo));
	printf("%lld",dp(0,0,n-1));
}


Measured memory_bytes: 70912
a,b,m=map(int,input().split())
s=list(map(int,input().split()))
t=list(map(int,input().split()))
d=min(s)+min(t)
for i in range(m):
    p,q,r=map(int,input().split())
    d=min(d,s[p-1]+t[q-1]-r)
print(d)


Measured memory_bytes: 18736
#include <iostream>
#include <set>
#define int long long
using namespace std;
set<int>s, t;
int n, p;
signed main() {
	cin >> n; for (int i = 0; i < n; i++) { cin >> p; s.insert(p); }
	cin >> n; for (int i = 0; i < n; i++) { cin >> p; if (s.count(p))t.insert(p); }
	for (int i : t)cout << i << endl;
}


Measured memory_bytes: 14252
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
typedef long long ll;

using namespace std;

int main(){
	ll h;
	cin >> h;
	ll ans = 1;
	ll szorzo = 1;
	while(h > 1){
		h /= 2;
		ans += pow(2,szorzo);
		szorzo += 1;
	}
	cout << ans;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.next();
		char[] str = s.toCharArray();
		StringBuilder sb = new StringBuilder();
		for(int i = 0;i < str.length ; i += 2) {
			sb.append(str[i]);
		}
		System.out.println(sb);
	}
}

Measured memory_bytes: 25768
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i < (n); i++)
#define RREP(i, s, n) for (int i = s; i < (n); i++)
#define ALL(a) a.begin(), a.end()
#define RALL(a) a.rbegin(), a.rend()
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
using namespace std;
using ll = long long;
typedef pair<int, int> pint;
typedef pair<ll, ll> pll;
const ll MOD = 1000000007;
const ll INF = MOD * MOD;
const int inf = (1<<29);

int main() {

    ll a, b, k;
    cin >> a >> b >> k;

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

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

Measured memory_bytes: 256
#!/usr/bin/env python
# encoding: utf-8


class Solution:
    def __init__(self):
        self.count = 0

    def shell_sort(self):
        array_length = int(input())
        array = []
        # array_length = 10
        # array = [15, 12, 8, 9, 3, 2, 7, 2, 11, 1]
        for m in range(array_length):
            array.append(int(input()))

        G = [1]
        while True:
            g = G[0] * 3 + 1
            if g > array_length:
                break
            G.insert(0, g)

        g_length = len(G)
        result = []
        for j in range(g_length):
            result = self.insertion_sort(array=array, array_length=array_length, g=G[j])
            # print(result, 'r', G[j])

        print(g_length)
        print(" ".join(map(str, G)))
        print(self.count)
        for k in range(array_length):
            print(result[k])

    def insertion_sort(self, array, array_length, g):
        # write your code here

        for i in range(g, array_length):
            v = array[i]
            j = i - g
            while j >= 0 and array[j] > v:
                array[j + g] = array[j]
                j -= g
                self.count += 1
            array[j + g] = v

        # print(" ".join(map(str, array)))
        return array


if __name__ == '__main__':
    solution = Solution()
    solution.shell_sort()

Measured memory_bytes: 47560
#include <iostream>
#include <vector>
#include <cmath>

using namespace std;

int main(int argc, char const *argv[])
{
    int n;
    cin >> n;
    if(n > 100){
        return -1;
    }

    // Parse W[0] .. W[N-1]
    vector<unsigned int> w;
    for(int i=0; i<n; i++){
        unsigned int tmp;
        cin >> tmp;
        //cout << tmp << endl;
        w.push_back(tmp);
    }

    // [0..n-1]
    int t;
    int result = -1;
    for(t=0; t<n-1; t++) {
        //cout << "t:" << t << endl;
        int a=0,b=0;
        for(int i=0; i<=t; i++){
            a+=w[i];
        }
        for(int i=t+1; i<n; i++) {
            b+=w[i];
        }
        //cout << "a:" << a << " b:" << b << endl;
        const int c = abs(a-b);
        if( result < 0 || c < result) {
            result = c;
        }
    }
    // Result
    cout << result << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100000
#define INF 100000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 100005;
const int MOD = 1000000007;
int main(){
    string s;
    cin>>s;
    int n=SZ(s)-1;
    ll ans=0;
    for(int bit=0;bit<(1<<n);bit++){
        vector<int> S;
        REP(i,n){
            if(bit & (1<<i)){
                S.push_back(i);
            }
        }
        ll tmp=0;
        int cnt=0;
        REP(i,SZ(s)){
            tmp=10*tmp+s[i]-'0';
            if(cnt<SZ(S)&&i==S[cnt]){
                ans+=tmp;
                tmp=0;
                cnt++;
            }
        }
        ans+=tmp;
    }
    OUT(ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define maxn 110
#define LL long long
#define pb push_back
#define mp make_pair
#define fi first
#define se second
typedef pair<int,LL> pii;
const int inf=0x3f3f3f3f;
const int mod=1e9+7;
const int tot=1<<15;

int n;
int t[maxn],x[maxn],y[maxn],s[maxn];
int qry(int p){
	printf("? ");
	if(p==0){
		for(int i=1;i<n;i++) printf("%d ",t[i]);
		printf("%d\n",t[n]);
	}else if(p==1){
		for(int i=1;i<n;i++) printf("%d ",x[i]);
		printf("%d\n",x[n]);
	}else{
		for(int i=1;i<n;i++) printf("%d ",y[i]);
		printf("%d\n",y[n]);
	}
	fflush(stdout);
	string s;
	cin>>s;
	if(s=="Red") return 1;
	else return -1;
} 

int a,b,beg,en;

int main(){
	//freopen("test.txt","r",stdin);
	
	cin>>n;

	
	int l=1,r=n+1,mid;
	for(int i=1;i<=n;i++) t[i]=i;
	a=qry(0);b=-1*a;
	while(l<r-1){
		mid=(l+r)>>1;
		for(int i=1;i<=n;i++) t[i]=mid+i-1;
		int tt=qry(0);
		if(tt!=a){
			r=mid;
		}else{
			l=mid;
		}
	}
	s[l]=a;s[l+n]=b;
	beg=l;en=l+n;
	int cnt=0;
	
	for(int i=1;i<n;i++) x[i]=i+beg;
//	cerr<<"beg=="<<beg<<" "<<en<<endl;
	
	for(int i=1;i<=2*n;i++)if(i<beg||i>en){
		x[n]=i;
		s[i]=qry(1);
		t[++cnt]=i;
	}
	
	for(int i=1;i<=2*n;i++)if(i>beg&&i<en){
		t[n]=i;
		s[i]=qry(0);
	}
	
	printf("! ");
	for(int i=1;i<2*n;i++) printf("%c",(s[i]==1)?'R':'B');
	printf("%c\n",(s[2*n]==1)?'R':'B');

	
	return 0;
} 

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

int main()
{
    int N;
    cin >> N;
    long long A[N];
    for (int i = 0; i < N; i++) cin >> A[i];
    
    long long ans = 0;
    for (int i = 0; i < N; i++)
    {
        if (A[i] % 2 == 1) continue;

        while (A[i] % 2 == 0)
        {
            A[i] = A[i] / 2;
            ans++;
        }

    }

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

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

int main(int argc, char **argv) {
  int N;
  cin >> N;
  vector<int> A(N), B(N);

  for (int i = 0; i < N - 1; i++) {
    cin >> B[i];
  }
  B[N - 1] = B[N - 2];

  int prev;
  A[0] = B[0];
  for (int cur = 1; cur < N; cur++) {
    prev = cur - 1;
    A[cur] = min(B[prev], B[cur]);
  }

  int ans = 0;
  for (int i = 0; i < N; i++)
    ans += A[i];

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256
using System;

namespace A___Airplane
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Array.ConvertAll(Console.ReadLine().Split(' '),int.Parse);

            var AB = read[0];
            var BC = read[1];
            var CA = read[2];

            Console.WriteLine(Math.Min(AB+BC,Math.Min(BC+CA,CA+AB)));
        }
    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(),(v).end()
using ll = long long;
using P = pair<int, int>;
const int INF = 1e9;
const long long LINF = 1e18;
const long long MOD = 1e9 + 7;

#define MAX_A 200000
#define MAX 40

signed main(){
    ll n,k;
    cin >> n >> k;
    int a[n];
    rep(i,n){
        cin >> a[i];
    }
    vector<vector<ll>> dp(MAX + 1, vector<ll>(n));
    int nxt[MAX_A + 1];
    for(int i = 2 * n - 1; i >= 0; i--){
        dp[0][i % n] = nxt[a[i % n]] - i + 1;
        nxt[a[i % n]] = i;
    }
    for(int i = 0; i < MAX; i++){
        for(int j = 0; j < n; j++){
            dp[i + 1][j] = dp[i][j] + dp[i][(dp[i][j] + j) % n];
        }
    }
    int now = 0;
    ll sum = n * k;
    while(sum > 0){
        for(int i = MAX; i >= 0; i--){
            if(dp[i][now] < sum){
                sum -= dp[i][now];
                now = (now + dp[i][now]) % n;
                goto ok;
            }
        }
        break;
        ok:;
    }
    bool exist[MAX_A + 1] = {};
    vector<int> ans;
    for(int i = now; i < n; i++){
        if(exist[a[i]]){
            while(exist[a[i]]){
                exist[ans.back()] = false;
                ans.pop_back();
            }
        }else{
            ans.emplace_back(a[i]);
            exist[a[i]] = true;
        }
    }
    for(int i = 0; i < ans.size(); i++){
        cout << ans[i] << " ";
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 69220
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
using ll = long long;
using vec = vector<ll>;
using vect = vector<double>;
using Graph = vector<vector<ll>>;
#define loop(i, n) for (ll i = 0; i < n; i++)
#define Loop(i, m, n) for (ll i = m; i < n; i++)
#define pool(i, n) for (ll i = n; i >= 0; i--)
#define Pool(i, m, n) for (ll i = n; i >= m; i--)
#define mod 1000000007ll
#define flagcount __builtin_popcount
#define flag(x) (1 << x)
#define flagadd(bit, x) bit |= flag(x)
#define flagpop(bit, x) bit &= ~flag(x)
#define flagon(bit, i) bit &flag(i)
#define flagoff(bit, i) !(bit & (1 << i))
#define all(v) v.begin(), v.end()
#define low2way(v, x) lower_bound(all(v), x)
#define high2way(v, x) upper_bound(all(v), x)
#define idx_lower(v, x) (distance(v.begin(), low2way(v, x)))  //配列vでx未満の要素数を返す
#define idx_upper(v, x) (distance(v.begin(), high2way(v, x))) //配列vでx以下の要素数を返す
#define idx_lower2(v, x) (v.size() - idx_lower(v, x))         //配列vでx以上の要素数を返す
#define idx_upper2(v, x) (v.size() - idx_upper(v, x))         //配列vでxより大きい要素の数を返す
#define putout(a) cout << a << endl
#define Gput(a, b) G[a].push_back(b)
#define Sum(v) accumulate(all(v), 0ll)
#define gcd(x, y) __gcd(x, y)
ll ctoi(char c)
{
    if (c >= '0' && c <= '9')
    {
        return c - '0';
    }
    return 0;
}
template <typename T>
T lcm(T x, T y)
{
    T z = gcd(x, y);
    return x * y / z;
}
template <typename T>
bool primejudge(T n)
{
    if (n < 2)
        return false;
    else if (n == 2)
        return true;
    else if (n % 2 == 0)
        return false;
    double sqrtn = sqrt(n);
    for (T i = 3; i < sqrtn + 1; i++)
    {
        if (n % i == 0)
        {
            return false;
        }
        i++;
    }
    return true;
}
//場合によって使い分ける
//const ll dx[4]={1,0,-1,0};
//const ll dy[4]={0,1,0,-1};
const ll dx[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll dy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//2次元配列の宣言
//vector<vector<ll>> field(h, vector<ll>(w));

int main()
{
    cout << fixed << setprecision(30);
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    loop(i, 10000)
    {
        if (i % 2 == 0)
        {
            c -= b;
        }
        else
        {
            a -= d;
        }
        if (a <= 0)
        {
            putout("No");
            return 0;
        }
        if (c <= 0)
        {
            putout("Yes");
            return 0;
        }
    }
    return 0;
}


Measured memory_bytes: 3624
import java.util.*;
import java.io.*;

public class Main {
	static int mod = (int) 1e9 + 7;
	static int DX[] = { -1, 0, 1, 0 }, DY[] = { 0, -1, 0, 1 };

	public static void main(String[] args) {
		FastScanner fs = new FastScanner(System.in);
		int N = fs.nextInt();
		int A[] = fs.nextIntArray(N);
		
		TreeMap<Integer,Integer> tm = new TreeMap<>();
		for(int i=0;i<N;i++) {
			int now = A[i];
			if(tm.lowerKey(now)==null) {
				if(tm.containsKey(now)){
					tm.put(now, tm.get(now)+1);
				}else {
					tm.put(now, 1);					
				}
			}
			else {
				int before = tm.lowerKey(now);
				if(tm.get(before)==1)tm.remove(before);
				else tm.put(before, tm.get(before)-1);
				if(tm.containsKey(now)) {
					tm.put(now, tm.get(now)+1);
				}else {
					tm.put(now, 1);
				}
			}
		}
		int ans = 0;
		Set<Integer> keySet = tm.keySet();
		for(int key:keySet) {
			int value = tm.get(key);
			ans += value;
		}
		System.out.println(ans);
	}
}

//高速なScanner
class FastScanner {
	private BufferedReader reader = null;
	private StringTokenizer tokenizer = null;

	public FastScanner(InputStream in) {
		reader = new BufferedReader(new InputStreamReader(in));
		tokenizer = null;
	}

	public String next() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				tokenizer = new StringTokenizer(reader.readLine());
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken();
	}

	public String nextLine() {
		if (tokenizer == null || !tokenizer.hasMoreTokens()) {
			try {
				return reader.readLine();
			} catch (IOException e) {
				throw new RuntimeException(e);
			}
		}
		return tokenizer.nextToken("\n");
	}

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

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

	public double nextDouble() {
		return Double.parseDouble(next());
	}

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

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

Measured memory_bytes: 43120
//18:22-
#include <assert.h>
#include <stdio.h>
#include <string.h>
#include <algorithm>
typedef struct tuple tuple;
struct tuple{
	int time;
	int channel;
	char kind; //'S','T'
	bool operator< ( const tuple & another) const{
		return time < another.time;
	}
};


tuple tuples[2*100001];
int s[100001];
int t[100001];
int c[100001];
int N, C;
int recorder[30];
int channel_recorder[31];
int main(){
	int ind = 0;
	scanf("%d %d",&N,&C);
	for(int i = 0; i < N; i++){
		scanf("%d %d %d",s+i,t+i,c+i);	
		tuples[ind].time= s[i];
		tuples[ind].channel= c[i];
		tuples[ind].kind='S';
		ind++;
		tuples[ind].time= t[i];
		tuples[ind].channel= c[i];
		tuples[ind].kind='T';
		ind++;
	}
	std::sort(tuples,tuples+ind);
	
	int x = 0;
	while(x < ind){
		int sx = x;
		int ex = x;
		char ch[31];
		memset(ch,0,sizeof(ch));
		while(tuples[ex].time == tuples[sx].time && ex < ind){
			ch[tuples[ex].channel]++;
			 ex++;
		}
		for(int i = sx; i < ex; i++){
			if(ch[tuples[i].channel] == 2) tuples[i].kind = 'X';
		}
		x = ex;
	}
/*
	for(int i = 0; i < ind; i++){
		printf("time=%d, channel=%d, kind=%c\n",
			tuples[i].time,tuples[i].channel,tuples[i].kind);
	}
*/

	for(int r = 0; r < 30; r++) recorder[r] = 0;

	for(int i = 0; i < ind; i++){
		if(tuples[i].kind == 'X') continue;

		if(tuples[i].kind == 'S'){
			for(int r = 0; r < 30; r++){
				if(recorder[r]!=-1 && recorder[r] < tuples[i].time){
					recorder[r]=-1;
					channel_recorder[tuples[i].channel] = r;
					//printf("t[%d]:assigned recorder %d to channel %d\n",tuples[i].time, r, tuples[i].channel);
					break;
				}
			}
			assert("1==0");
		}else /*'T'*/{
			//printf("t[%d]:terminated recorder %d\n",tuples[i].time, channel_recorder[tuples[i].channel] );
			recorder[channel_recorder[tuples[i].channel]] = tuples[i].time;
		}
	}
	int max_recorder = 0;
	for(int r = 0; r < 30; r++){ if(recorder[r] != 0) max_recorder++;}
	printf("%d\n",max_recorder);
}


Measured memory_bytes: 3712
#include <cstdio>
#include <cstring>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>

#define rep(i, j) FOR(i, 0, j)
#define FOR(i, j, k) for(int i = j; i < k; ++i)

using namespace std;

int main(){
  int n, k, in;

  while(scanf("%d%d", &n, &k) && (n || k)){
    vector<int>s;
    vector<int>b(100);
    rep(i, k) scanf("%d", &in), s.push_back(in);
    rep(i, n) rep(j, k){
      scanf("%d", &in);
      b[j] += in;
    }
    bool flag = false;
    rep(i, k) if(s[i] < b[i]) flag = true;
    if(flag) puts("No");
    else puts("Yes");
  } 
  return 0;
}

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

int main() {
    int n, q;
    int x;
    vector<int> v;
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> q;
        if(q == 0){
            cin >> x;
            v.push_back(x);
        }
        else if(q == 1){
            cin >> x;
            cout << v[x] << endl;
        }
        else {
            v.pop_back();
        }

    }
    
    


}


Measured memory_bytes: 3936
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int n,c=0,m=0;
  cin>>n;
  int a[n];
  for(int i=0;i<n;i++)
  {
    cin>>a[i];
    int j;
    for(j=m;j<i;j++)
    {
      if(a[i]>a[j])
        break;
    }
    if(j==i)
    {
        c++;
        m=j;
    }
  }
  cout<<c;
  return 0;
}
    

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

typedef pair<int,int> P;
typedef long long ll;
const int INF=1e9;
const int MAX=100010;

int N;
int d[3][MAX];
bool used[MAX];
vector<int> G[MAX];

void BFS(int s){
    for(int i=0;i<3;i++){
        for(int j=0;j<N;j++){
            d[i][j]=-1;
        }
    }
    queue<P> que;
    d[0][s]=0;
    que.push(P(0,s));
    while(!que.empty()){
        P p=que.front(); que.pop();
        int v=p.second; //頂点
        int parity=p.first;
        for(auto it : G[v]){
            int np=(parity+1)%3;
            if(d[np][it]==-1){
                d[np][it]=d[parity][v]+1;
                que.push(P(np,it));
            }
        }
    }
}


int main(){
    int M;
    cin >> N >> M;
    for(int i=0;i<M;i++){
        int u,v; cin >> u >> v;
        u--;v--;
        G[u].push_back(v);
    }
    int s,t;
    cin >> s >> t;
    s--;t--;
    BFS(s);
    if(d[0][t]==-1){
        cout << -1 << endl;
    }else{
        cout << d[0][t]/3 << endl;
    }
}

Measured memory_bytes: 6912
#include<iostream>
#include<algorithm>
#include<functional>
#include<cmath>
#include<string>
#include<vector>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<deque>
using namespace std;
#define ll long long
const int mod = 1000000007;
const ll INF = 1000000000000000000;

int main()
{
	ll N, A, B, C, D, E;
	cin >> N >> A >> B >> C >> D >> E;
	ll num = min({ A,B,C,D,E });
	ll ans = 4;
	ans += (N + num - 1) / num;
	cout << ans << endl;
}

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

template <typename T>
T _max(
  T lhs
  , T rhs
  )
{
  return lhs < rhs ? rhs : lhs;
}

int main()
{
  int N, W;
  cin >> N >> W;
  vector<int> w(N), v(N);
  for (int i = 0; i < N; ++i)
    cin >> w[i] >> v[i];
  typedef long long ll;
  vector<vector<ll>> value(2);
  for (auto & v : value)
    v.resize(W + 1);
  int which = 0;
  for (int i = 0; i < N; ++i)
  {
    for (int j = 0; j <= W; ++j)
    {
      if (j - w[i] < 0)
        value[which^1][j] = value[which][j];
      else
        value[which^1][j] = _max(value[which][j], value[which][j - w[i]] + v[i]);
    }
    which ^= 1;
  }
  cout << value[which][W];
  return 0;
}


Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
int a[100010],c,n;
void No()
{
	puts("No");
	exit(0);
}
void Yes()
{
	puts("Yes");
	exit(0);
}
int main(void)
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i]);
	}
	stable_sort(a+1,a+1+n);
	if(a[n]>a[1]+1)
		No();
	if(a[n]==a[1])
	{
		if(a[n]==n-1)
			Yes();
		if(a[n]*2<=n)
			Yes();
		No();
	}
	for(int i=1;i<n;i++)
		c+=a[i]==a[1];
	if(a[n]*2-c<=n&&c<a[n])
		Yes();
	No();
}

Measured memory_bytes: 768
#include <cstring>
#include <iostream>
#include <queue>
#include <vector>

#define forn(i, n) for (int i = 0; i < (int)n; ++i)
#define for1(i, n) for (int i = 1; i <= (int)n; ++i)
#define fore(i, l, r) for (int i = (int)(l); i <= (int)(r); ++i)
#define ford(i, n) for (int i = (int)(n)-1; i >= 0; --i)
#define pb push_back
#define fi first
#define se second
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define INF (1 << 20)

using namespace std;

typedef long long i64;
typedef vector<int> vi;
typedef vector<i64> vi64;
typedef vector<vi> vvi;
typedef vector<vi64> vvi64;
typedef double ld;

int d[100][100];

int main() {

  ios::sync_with_stdio(false);
  cin.tie(0);
  cout.precision(10);
  cout << fixed;

  int N, M;
  cin >> N >> M;

  forn(i, 100) forn(j, 100) d[i][j] = INF;
  forn(i, 100) d[i][i] = 0;

  vi a(M), b(M), c(M);
  forn(i, M) {
    cin >> a[i] >> b[i] >> c[i];
    a[i]--;
    b[i]--;

    d[a[i]][b[i]] = c[i];
    d[b[i]][a[i]] = c[i];
  }

  forn(k, N) {
    forn(i, N) {
      forn(j, N) { d[i][j] = min(d[i][j], d[i][k] + d[k][j]); }
    }
  }

  int ans = 0;
  forn(k, M) {
    if (d[b[k]][a[k]] != c[k]) {
      ans++;
    }
  }
  cout << ans << endl;

  return 0;
}


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

int main() {
  int h;
  cin >> h;
  int w;
  cin >> w;
  vector<string> a(h);
  for (int i = 0; i < h; i++) {
    cin >> a[i];
  }

  vector<bool> row(h, false);
  vector<bool> col(w, false);
  for (int i = 0; i < h; i++) {
    for (int j = 0; j < w; j++) {
      if (a[i][j] == '#') {
        row[i] = true;
        col[j] = true;
      }
    }
  }

  for (int i = 0; i < h; i++) {
    if (row[i]) {
      for (int j = 0; j < w; j++) {
        if (col[j]) {
          cout << a[i][j];
        }
      }
      cout << endl;
    }
  }
}


Measured memory_bytes: 256
import java.util.*;


class Main{
	public static void main(String args[]){
		
		Scanner sc=new Scanner(System.in);
		
		int x=sc.nextInt();
		
		int happy = (x/500)*1000+(x%500/5)*5;
		
		System.out.println(happy);
		
		
	}
}
	




Measured memory_bytes: 21844
import math

a, b, h, m = map(int, input().split())

ml = m * 6
mp = m / 60
hl = h * 30 + 30 * mp

# print(ml,hl)

ras = abs(ml - hl)
if ras > 180:
    ras = 360 - ras
# print(ras)

cos = math.cos(math.radians(ras))
ans = a ** 2 + b ** 2 - 2 * a * b * cos

ans = math.sqrt(ans)

print(ans)

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

int main(){
  char c,s[6];
  int a=0,n=0;
  for(;cin>>c;) s[n++]=c;
  fr(i,n){
    a*=10;
    a+=s[i]-'0';
  }
  cout<<((int)sqrt(a)*(int)sqrt(a)<a?"No":"Yes")<<endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
import sys
import math
import os
import itertools
import string
import heapq
import _collections
from collections import Counter
from collections import defaultdict
from collections import deque
from functools import lru_cache
import bisect
import re
import queue
import decimal


class Scanner():
    @staticmethod
    def int():
        return int(sys.stdin.readline().rstrip())

    @staticmethod
    def string():
        return sys.stdin.readline().rstrip()

    @staticmethod
    def map_int():
        return [int(x) for x in Scanner.string().split()]

    @staticmethod
    def string_list(n):
        return [Scanner.string() for i in range(n)]

    @staticmethod
    def int_list_list(n):
        return [Scanner.map_int() for i in range(n)]

    @staticmethod
    def int_cols_list(n):
        return [Scanner.int() for i in range(n)]


class Math():
    @staticmethod
    def gcd(a, b):
        if b == 0:
            return a
        return Math.gcd(b, a % b)

    @staticmethod
    def lcm(a, b):
        return (a * b) // Math.gcd(a, b)

    @staticmethod
    def divisor(n):
        res = []
        i = 1
        for i in range(1, int(n ** 0.5) + 1):
            if n % i == 0:
                res.append(i)
                if i != n // i:
                    res.append(n // i)
        return res

    @staticmethod
    def round_up(a, b):
        return -(-a // b)

    @staticmethod
    def is_prime(n):
        if n < 2:
            return False
        if n == 2:
            return True
        if n % 2 == 0:
            return False
        d = int(n ** 0.5) + 1
        for i in range(3, d + 1, 2):
            if n % i == 0:
                return False
        return True

    @staticmethod
    def fact(N):
        res = {}
        tmp = N
        for i in range(2, int(N ** 0.5 + 1) + 1):
            cnt = 0
            while tmp % i == 0:
                cnt += 1
                tmp //= i
            if cnt > 0:
                res[i] = cnt
        if tmp != 1:
            res[tmp] = 1
        if res == {}:
            res[N] = 1
        return res


def pop_count(x):
    x = x - ((x >> 1) & 0x5555555555555555)
    x = (x & 0x3333333333333333) + ((x >> 2) & 0x3333333333333333)
    x = (x + (x >> 4)) & 0x0f0f0f0f0f0f0f0f
    x = x + (x >> 8)
    x = x + (x >> 16)
    x = x + (x >> 32)
    return x & 0x0000007f


MOD = int(1e09) + 7
INF = int(1e15)


def solve():
    S = Scanner.string()
    if S == S.lower():
        print('a')
    else:
        print('A')


def main():
    # sys.stdin = open("sample.txt")
    # T = Scanner.int()
    # for _ in range(T):
    #     solve()
    # print('YNeos'[not solve()::2])
    solve()


if __name__ == "__main__":
    main()


Measured memory_bytes: 10656
#include <bits/stdc++.h>
#include <iostream>
#include <cstdio>
#include <vector>
#include <tuple>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <iomanip>
using namespace std;
#define reps(i,s,n) for(int i = s; i < n; i++)
#define rep(i,n) reps(i,0,n)
#define fi first
#define se second
typedef long long ll;

int N,M,H,W,K,A,B;
string S;
string alpha = "abcdefghijklmnopqrstuvwxyz";
string ALPHA = "ABCDEFGHIJKLMNOPQRSTUVWXYZ";

#include <vector>
#include <iostream>
#include <cstdio>

using namespace std;

const int MAX_V = 200000;

struct edge {int to, cost; };
vector<vector<edge>> G(MAX_V,vector<edge>(0));
vector<int> color(MAX_V,-1);

//頂点を色０と１で塗っていく
void dfs(int v,int c){
    color.at(v) = c;
    rep(i,G.at(v).size()){
        edge e = G.at(v).at(i);
        if(color.at(e.to) == -1) dfs(e.to,e.cost^c);
    }
}

int main() {
    int V;
    scanf("%d", &V);
    int E = V-1;
    for(int i = 0; i < E; i++) {
        // sからtへの辺を張る
        int s,t,w;
        scanf("%d %d %d", &s, &t, &w);
        w = w&1;
        s--;
        t--;
        G.at(s).push_back(edge{t,w});
        G.at(t).push_back(edge{s,w});
    }

    dfs(0,1);
    /*rep(i,V){
        rep(j,G.at(i).size()){
            cout 
            << i << ' ' 
            << G.at(i).at(j).to << ' ' 
            << G.at(i).at(j).cost << ' ' 
            << G.at(i).size() 
            << endl;
        }
    }*/
    rep(i,V) cout<<color.at(i)<<endl;
    return 0;
}

Measured memory_bytes: 11136
#include<bits/stdc++.h>
#define mod 1000000007
using namespace std;
int n,k,add;
int f[100005],cnt,d[100005];
int dp[105][100005];

int main(){
	cin>>n>>k;
	for(int l=1,r;l<=n;l=r+1){
		r=n/(n/l);
		f[++cnt]=n/l;
		d[cnt]=r;
	}
	for(int i=1;i<=cnt;i++) dp[1][i]=d[i]-d[i-1];
	for(int i=2;i<=k;i++){
		int add=0;
		for(int j=cnt;j>=1;j--){
			add+=dp[i-1][cnt-j+1];
			add%=mod;
			dp[i][j]=1LL*(d[j]-d[j-1])*add%mod;
		}
	}
	int ans=0;
	for(int i=1;i<=cnt;i++) ans+=dp[k][i],ans%=mod;
	cout<<ans;
	
	return 0;
}

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

char info[50][50];
int main(){
    int H,W;cin>>H>>W;
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++)cin>>info[i][j];
    }
    int flag=0;
    const int dx[4]={1,0,-1,0},dy[4]={0,-1,0,1};
    for(int i=0;i<H;i++){
        for(int j=0;j<W;j++){
            if(info[i][j]=='.')continue;
            int count=0;
            for(int k=0;k<4;k++){
                if(0<=i+dy[k] and i+dy[k]<H and 0<=j+dx[k] and j+dx[k]<W){
                    if(info[i+dy[k]][j+dx[k]]=='#')count++;
                }
            }
            if(count==0){
                i=H;
                flag++;
                break;
            }
        }
    }
    if(flag)cout<<"No"<<endl;
    else cout<<"Yes"<<endl;
    
    return 0;
}

Measured memory_bytes: 256
from collections import deque

n = int(input())
tree = [[] for _ in range(n)]
color = dict()
edge = [(0, 0)] * (n-1)
for i in range(n-1):
    a, b = map(lambda x : int(x) - 1, input().split())
    tree[a].append(b)
    tree[b].append(a)
    edge[i] = (a, b)
color_n = max(map(len, tree))

q = deque()
q.append((0, -1))

visited = set()
while q:
    i, prev_c = q.popleft()
    visited.add(i)
    c = 0
    for x in tree[i]:
        if not x in visited:
            if c == prev_c:
                c = (c + 1) % color_n
            p = (i, x) if i < x else (x, i)
            color[p] = c
            q.append((x, c))
            c = (c + 1) % color_n

print(color_n)
for e in edge:
    print(color[e] + 1)


Measured memory_bytes: 120944
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        String s1 = scan.next();
        String s2 = scan.next();
        String s3 = scan.next();
        s1 = s1.toUpperCase();
        s2 = s2.toUpperCase();
        s3 = s3.toUpperCase();
        System.out.print(s1.charAt(0));
        System.out.print(s2.charAt(0));
        System.out.print(s3.charAt(0));
    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
#define syosu(x) fixed<<setprecision(x)
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef pair<double,double> pdd;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<string> vs;
typedef vector<P> vp;
typedef vector<vp> vvp;
typedef vector<pll> vpll;
typedef pair<int,P> pip;
typedef vector<pip> vip;
const int inf=1<<30;
const ll INF=1ll<<60;
const double pi=acos(-1);
const double eps=1e-9;
const ll mod=1e9+7;
const int dx[4]={0,1,0,-1},dy[4]={1,0,-1,0};

ll n;
vl a;
vvl g;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cin>>n;
	a=vl(n);
	g=vvl(n);
	vl dp(n,inf);
	for(int i=0;i<n;i++) cin>>a[i];
	ll L=0;
	for(int i=0;i<n;i++){
		ll it=lower_bound(dp.begin(),dp.end(),a[i])-dp.begin();
		dp[it]=min(dp[it],a[i]);
		g[it].push_back(i);
		L=max(L,it);
	}
	ll res=0,x=inf,y=inf;
	for(int i=L;i>=0;i--){
		ll X,Y;
		reverse(g[i].begin(),g[i].end());
		for(auto j:g[i]) if(j<x&&a[j]<y) X=j,Y=a[j];
		res+=Y;
		x=X;y=Y;
	}
	cout<<res<<endl;
}


Measured memory_bytes: 9840
#include <stdio.h>
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <numeric>
#include <algorithm>
#include <sstream>
#include <string>
#include <map>
using namespace std;

//ABC127 B
int main() {
	int r, D, x;
	cin >> r >> D >> x;

	for (int i=0; i<10; i++) {
		x = r * x - D;
		cout << x << endl;
	}
}

Measured memory_bytes: 256
//Darker and Darker
#include<bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
vector<int> dy = {1, 0, -1, 0};
vector<int> dx = {0, 1, 0, -1};
typedef pair<int, int> PII;


int main() {
    int h, w;
    cin >> h >> w;
    vector<string> grah(h);
    rep(i, h) cin >> grah.at(i);
    queue<PII> q;
    vector<vector<int>> dist(h, vector<int>(w, -1));
    rep(i,h) rep(j, w){
        if(grah.at(i).at(j) == '#'){
            q.emplace(i, j);
            dist.at(i).at(j) = 0;
        }

    }

    while(!q.empty()){
        PII v = q.front();
        q.pop();
        rep(i, 4){
            int ny = v.first + dy.at(i);
            int nx = v.second + dx.at(i);
            if(ny >= 0 && nx >= 0 && ny < h && nx < w && dist.at(ny).at(nx) == -1 && grah.at(ny).at(nx) != '#'){
                dist.at(ny).at(nx) = dist.at(v.first).at(v.second) + 1;
                q.emplace(ny, nx);
            }
        }
    }
    int res = 0;
    rep(i, h) rep(j, w){
        res = max(res, dist.at(i).at(j));
    }

    cout << res << endl;

    return 0;

}


Measured memory_bytes: 17072
#include <stdio.h>

int main(void){
  int N;
  int A, B;
  int i, j, k;
  int sum = 0;
  int buf;

  scanf("%d %d %d", &N, &A, &B);

  for(i = 1; i <= N; i++){
    buf = i%10 + (i/10)%10 + (i/100)%10 + (i/1000)%10 + (i/10000)%10;
    if(buf >= A && buf <= B){
      sum += i;
    }
  }

  printf("%d\n", sum);
  return 0;
}


Measured memory_bytes: 128
#include<stdio.h>
#include<string.h>
int main() {
	char str[1000], ord[7], p[1000], tmp[1000];
	int q, i, j, a, b;
	scanf("%s", str);
	scanf("%d", &q);
	for (i = 0;i < q;i++) {
		scanf("%s", ord);
		if (strcmp(ord, "print") == 0) {
			scanf("%d %d", &a, &b);
			for (j = a;j <= b;j++) {
				printf("%c", str[j]);
				if(j==b){
					printf("\n");
				}
			}
		}
			strcpy(tmp, str);
			if (strcmp(ord, "reverse")==0) {
			scanf("%d %d", &a, &b);
			int l = b - a + 1;
			for (j = 0;j < l;j++) {
				str[a + j] = tmp[b - j];
			}
		}
		if (strcmp(ord, "replace")==0) {
			scanf("%d %d %s", &a, &b, p);
			for (j = 0;j < b-a+1;j++) {
				str[a+j] = p[j];
			}
		}
	}
	return 0;
}

Measured memory_bytes: 588
#include<stdio.h>
int main(void)
{
	char s[3];
	int i,x,o,cnt,c;
	scanf("%s",&s);
	o=100;
	x=0;
	cnt=0;
	for(i=0;i<3;i++){
		if(s[i]=='o'){
				cnt++;
		}
	}
	c=700+o*cnt;
	printf("%d\n",c);
	return 0;
}


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

int main() {
    int W, H, N, cur_x, cur_y;
    cin >> W >> H >> N >> cur_x >> cur_y;
    int ans = 0;
    for(int i = 0; i < N - 1; ++i) {
        int X, Y; cin >> X >> Y;
        int dx = abs(cur_x - X), dy = abs(cur_y - Y);
        if(cur_x < X && cur_y < Y || X < cur_x && Y < cur_y) {
            int dz = min(dx, dy);
            ans += dz + (dx - dz) + (dy - dz);
        } else {
            ans += dx + dy;
        }
        cur_x = X, cur_y = Y;
    }
    cout << ans << endl;
}



Measured memory_bytes: 3032
H,W,K = map(int,input().split())
C = []
for i in range(H):
    C.append(input())
A = 0
for i in range(H):
    for j in range(W):
        if C[i][j] == "#":
            A += 1
cnt = 0
for i in range(2**H):
    I = bin(i)[2:]
    I = "0"*(H-len(I))+I
    for j in range(2**W):
        J = bin(j)[2:]
        J = "0"*(W-len(J))+J
        A1 = A
        for i1 in range(len(I)):
            if I[i1] == "0":
                continue
            for i2 in range(W):
                if C[i1][i2] == "#":
                    A1 -= 1
        for j1 in range(len(J)):
            if J[j1] == "0":
                continue
            for j2 in range(H):
                if C[j2][j1] == "#":
                    A1 -= 1
        for i1 in range(len(I)):
            if I[i1] == "0":
                continue
            for j1 in range(len(J)):
                if J[j1] == "0":
                    continue
                if C[i1][j1] == "#":
                    A1 += 1
        if A1 == K:
            cnt += 1
print(cnt)

Measured memory_bytes: 69196
#include<bits/stdc++.h>
using namespace std;
const int maxn=3006;
const int inf=1e9+7; 
typedef long long ll;
int dir[][2]={1,0,-1,0,0,1,0,-1};
int a[maxn],b[maxn],c[maxn],D[maxn],e[maxn],f[maxn];
int u[maxn][maxn],d[maxn][maxn],l[maxn][maxn],r[maxn][maxn],vis[maxn][maxn];
vector<int>xx({-inf,inf}),yy({-inf,inf});
void bfs(int x,int y){
	vis[x][y]=1;
	queue<pair<int,int>>q;
	q.push({x,y});
	while(!q.empty()){
		x=q.front().first,y=q.front().second;
		q.pop();
		for(int i=0;i<4;i++){
			if(i==0&&r[x][y]) continue;
			if(i==1&&l[x][y]) continue;
			if(i==2&&u[x][y]) continue;
			if(i==3&&d[x][y]) continue;
			int nx=x+dir[i][0];
			int ny=y+dir[i][1];
			if(nx<0||ny<0) continue;
			if(nx>xx.size()-1||ny>yy.size()-1) continue;
			if(vis[nx][ny]) continue;
			vis[nx][ny]=1;
			q.push({nx,ny});
		}
	}
}
int main(){
	int n,m;
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%d",&a[i]);
		scanf("%d",&b[i]);
		scanf("%d",&c[i]);
		xx.push_back(a[i]);
		xx.push_back(b[i]);
		yy.push_back(c[i]);
	}
	for(int i=0;i<m;i++){
		scanf("%d",&D[i]);
		scanf("%d",&e[i]);
		scanf("%d",&f[i]);
		xx.push_back(D[i]);
		yy.push_back(e[i]);
		yy.push_back(f[i]);
	}
	sort(xx.begin(),xx.end());
	sort(yy.begin(),yy.end());
	xx.resize(unique(xx.begin(),xx.end())-xx.begin());
	yy.resize(unique(yy.begin(),yy.end())-yy.begin());
	for(int i=0;i<n;i++){
		int aa=lower_bound(xx.begin(),xx.end(),a[i])-xx.begin();
		int bb=lower_bound(xx.begin(),xx.end(),b[i])-xx.begin();
		int cc=lower_bound(yy.begin(),yy.end(),c[i])-yy.begin();
		for(int x=aa;x<bb;x++){
			u[x][cc-1]=1;
			d[x][cc]=1;
		}
	}
	for(int i=0;i<m;i++){
		int dd=lower_bound(xx.begin(),xx.end(),D[i])-xx.begin();
		int ee=lower_bound(yy.begin(),yy.end(),e[i])-yy.begin();
		int ff=lower_bound(yy.begin(),yy.end(),f[i])-yy.begin();
		for(int y=ee;y<ff;y++){
			l[dd][y]=1;
			r[dd-1][y]=1;
		}
	}
	int x=lower_bound(xx.begin(),xx.end(),0)-xx.begin();
	int y=lower_bound(yy.begin(),yy.end(),0)-yy.begin();
	bfs(x-1,y-1);
	if(vis[0][0]){
		printf("INF\n");return 0;
	}
	ll ans=0;
	for(int i=0;i<xx.size()-1;i++){
		for(int j=0;j<yy.size()-1;j++){
			if(vis[i][j]) ans+=(ll)(xx[i+1]-xx[i])*(yy[j+1]-yy[j]);
		}
	}
	printf("%lld\n",ans);
}

Measured memory_bytes: 113888
#include <iostream>
#include <algorithm>
#include <cstring>
#include <iomanip>
#include <fstream>
#include <cmath>
#include <vector>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <map>
#include <stack>
#include <queue>
#include <assert.h>
#include <limits>
#include <cstdio>
using namespace std;

//#define RDEBUG 1
#ifdef RDEBUG
#define D(x) x
#else
#define D(x)
#endif
#define inf 0x7fffffff
#define MOD 1000000007

int N,M;

vector<int> adjlist[100010];
int indeg[100010];
int order[100010];
int currp = 0;
int dp[100010];


int main() {
    ios_base :: sync_with_stdio(false);
    cin.tie(nullptr);
    cin >> N >> M;
    for (int i = 0; i<M; i++) {
        int a, b;
        cin >> a >> b;
        adjlist[a].push_back(b);
        indeg[b]++;
    }
    queue<int> q;
    for (int i = 1; i<=N; i++) {
        if (indeg[i] == 0) {
            q.push(i);
        }
    }
    while (!q.empty()) {
        int u = q.front();
        order[currp] = u;
        currp++;
        q.pop();
        for (int v:adjlist[u]) {
            indeg[v]--;
            if (indeg[v] == 0) {
                q.push(v);
            }
        }
    }
    for (int i = currp-1; i>=0; i--) {
        int u = order[i];
        for (int v:adjlist[u]) {
            dp[u] = max(dp[u], 1+dp[v]);
        }
    }
    int best = 1;
    for (int i = 1; i<=N; i++) {
        best = max(best, dp[i]);
    }
    cout << best << endl;
    return 0;
}





Measured memory_bytes: 6912
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=1e5+5,mod=1e9+7;
int n,a[N];
ll f[N],sum[N];
ll inv(ll x){return x<=1?x:(mod-mod/x)*inv(mod%x)%mod;}
ll qpow(ll a,ll n)
{
    ll ans=1;
    while(n)
    {
        if(n&1) ans=ans*a%mod;
        a=a*a%mod;
        n>>=1;
    }
    return ans;
}
int main()
{
    f[0]=1;
    for(int i=1;i<N;i++) f[i]=f[i-1]*i%mod;
    scanf("%d",&n);
    for(int i=1;i<N;i++) sum[i]=(sum[i-1]+f[n-1]*inv((ll)i*(i+1)%mod)%mod)%mod;
    for(int i=1;i<=n;i++) scanf("%d",&a[i]);
    ll ans=0;
    /*//400分
    for(int i=1;i<n;i++)
        for(int j=i+1;j<=n;j++)
        if(j==n)
        ans=(ans+(a[j]-a[i])*f[n-1]%mod*inv(j-i)%mod)%mod;
        else ans=(ans+(a[j]-a[i])*f[n-1]%mod*inv((ll)(j-i)*(j-i+1)%mod)%mod)%mod;
    */
    for(int i=1;i<n;i++)
    {
        ans=(ans-a[i]*(sum[n-1-i])%mod)%mod;
        ans=(ans-a[i]*f[n-1]%mod*inv(n-i)%mod)%mod;
    }
    ans=(ans+mod)%mod;
    for(int i=2;i<n;i++)
        ans=(ans+a[i]*sum[i-1]%mod)%mod;;
    for(int i=1;i<n;i++)
        ans=(ans+a[n]*f[n-1]%mod*inv(n-i)%mod)%mod;
    printf("%lld\n",ans);
}



Measured memory_bytes: 5552