akhauriyash/Code-Regression huggingface dataset:
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees, log2, gcd
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from heapq import heappush, heappop
from functools import reduce, lru_cache
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def TUPLE(): return tuple(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = 10**6#float('inf')
mod = 10 ** 9 + 7 
#mod = 998244353
#from decimal import *
#import numpy as np
#decimal.getcontext().prec = 10

a, b, c, d = MAP()
print(max(a*c, a*d, b*c, b*d))

Measured memory_bytes: 10044
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll L[100010], R[100010];
int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int X, Y, Z;
	cin >> X >> Y >> Z;
	int n = X + Y + Z;
	vector<int> a(n), b(n), c(n), idx(n);
	for (int i = 0; i < n; i++){
		cin >> a[i] >> b[i] >> c[i];
		idx[i] = i;
	}
	sort(idx.begin(), idx.end(), [&](const int& i1, const int& i2){return a[i1] - b[i1] < a[i2] - b[i2];});
	priority_queue<int> pq;
	for (int i = 1; i <= n; i++){
		L[i] = L[i - 1] + b[idx[i - 1]];
		pq.push(c[idx[i - 1]] - b[idx[i - 1]]);
		if (i > Y) {
			L[i] += pq.top();
			pq.pop();
		}  
	}
	priority_queue<int> pq2;
	for (int i = n - 1; i >= 0; i--){
		R[i] = R[i + 1] + a[idx[i]];
		pq2.push(c[idx[i]] - a[idx[i]]);
		if (n - i > X) {
			R[i] += pq2.top();
			pq2.pop();
		}
	}
	ll ans = 0;
	for (int i = Y; i <= n - X; i++) {
		ans = max(ans, L[i] + R[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 3964
#include <cstdio>
#include <string>

using namespace std;

string s;
char a[20];

int main()
{
	s="CODEFESTIVAL2016";
	scanf("%s",a);
	int ans=0;
	for (int i=0;i<16;i++) if (a[i]!=s[i]) ans++;
	printf("%d\n",ans);
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<map>
#define MAXN 100010
typedef long long LL;
using namespace std;
map<int,int>ti,vis;
int N;
bool f1=0,f2=0;
LL a[100010],x=1,y=1,now=0;
int main()
{
    scanf("%d",&N);
    for(int i=1;i<=N;i++)
	{
		scanf("%lld",&a[i]);
        ti[a[i]]++;
    }
    sort(a+1,a+1+N);
    for(int i=N;i>=1;i--)
	{
        if(ti[a[i]]>=2&&!vis[a[i]])
		{
            vis[a[i]]=1;
            x*=a[i];
            now++;
        }
        if(now==2)
		{
            f1=1;
            break;
        }
    }
    for(int i=N;i>=1;i--)
        if(ti[a[i]]>=4)
		{
            y*=(a[i]*a[i]);
            f2=1;
            break;
        }
    if(f1||f2) printf("%lld\n",max(x,y));
	else printf("0\n");
    return 0;
}


Measured memory_bytes: 5760
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
typedef long long LL;
int main()
{
	LL a,b,c,x,ans;
	cin>>a>>b>>c>>x;
	ans=0;
	for(int i=0;i<=a;i++)
	{
		for(int j=0;j<=b;j++)
		{
			for(int k=0;k<=c;k++){
				if(i*500+j*100+k*50==x)
					ans++;
			}		
		}
	}
	cout<<ans<<endl;
	return 0;
}

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

int main() {
	// your code goes here
	string s, t;
	cin >> s >> t;
	int cnt , ans = 50000;
	for(int i = 0; i < s.length() - t.length()+1; ++i)
	{
	    cnt = 0;
	    for(int j = i; j < i + t.length(); ++j)
	    {
	        if(s[j] != t[j - i])
	            cnt++;
	    }
	    ans = min(ans, cnt);
	}
	cout << ans;
	return 0;
}


Measured memory_bytes: 3608
#include <iostream>
#include <math.h>
#include <iomanip>

const long double PI = (acos(-1));

using namespace std;
int main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);


    double side, height, volume;

    cin >> side >> height >> volume;

    double answer;
    if(side * side * height / 2.0 <= volume)
    {
        answer = atan(2 * (side *side* height - volume) / (side * side * side));
    }
    else
    {
        answer = PI / 2 - atan(2 * volume / (side * height * height));
    }

    // convert to degress


    cout << setprecision(10) << answer * 180.0 / PI;

}


Measured memory_bytes: 640
N, C = map(int, input().split())
imos = [0] * 100002
channel = [[0] * 100002 for i in range(C)]

for i in range(N):
    s, t, c = map(int, input().split())
    channel[c - 1][s] += 1
    channel[c - 1][t] -= 1

for i in range(C):
    for j in range(100001):
        channel[i][j + 1] += channel[i][j]

for i in range(C):
    for j in range(100001):
        if channel[i][j] == 0 and channel[i][j + 1] == 1:
            imos[j] += 1
        elif channel[i][j] == 1 and channel[i][j + 1] == 0:
            imos[j + 1] -= 1

for j in range(100001):
    imos[j + 1] += imos[j]

print(max(imos))


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

#define all(v) v.begin(), v.end()
#define V vector
#define P pair
typedef long long ll;
const int INT_INF = 1e9;
const ll INF = 1LL << 30;

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

    int ans = v[0];
    for(int i = 1; i < n; i++){
        if(v[i] > v[i - 1]){
            ans += v[i] - v[i - 1];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
string s,t;
vector<int>pos[26];
int main(){
	cin>>s>>t;
	rep(i,s.size()) pos[s[i]-'a'].pb(i);
	int pre = -1;
	int cur = 0;
	rep(i,t.size()){
		int id = t[i]-'a';
		int x = POSU(pos[id],pre);
		if(x == pos[id].size()){
			if(x == 0) { puts("-1"); return 0; }
			else { cur++; pre = pos[id][0]; }
		}
		else{
			pre = pos[id][x];
		}
	}
	cout << 1LL*cur*s.size()+pre+1 << endl;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n)  for(long long i=0;i<(long long)(n);i++)
#define REP(i,k,n) for(long long i=k;i<(long long)(n);i++)
#define all(a) a.begin(),a.end()
#define pb push_back
#define eb emplace_back
#define lb(v,k) (lower_bound(all(v),k)-v.begin())
#define ub(v,k) (upper_bound(all(v),k)-v.begin())
#define fi first
#define se second
#define pi M_PI
#define PQ(T) priority_queue<T>
#define SPQ(T) priority_queue<T,vector<T>,greater<T>>
#define dame(a) {out(a);return 0;}
#define decimal cout<<fixed<<setprecision(15);
typedef long long ll;
typedef pair<ll,ll> P;
typedef tuple<ll,ll,ll> PP;
typedef tuple<ll,ll,ll,ll> PPP;
typedef multiset<ll> S;
using vi=vector<ll>;
using vvi=vector<vi>;
using vvvi=vector<vvi>;
using vp=vector<P>;
using vvp=vector<vp>;
using vb=vector<bool>;
using vvb=vector<vb>;
const ll inf=1001001001001001001;
const int INF=1001001001;
const int mod=1000000007;
const double eps=1e-10;
template<class T> bool chmin(T&a,T b){if(a>b){a=b;return true;}return false;}
template<class T> bool chmax(T&a,T b){if(a<b){a=b;return true;}return false;}
template<class T> void out(T a){cout<<a<<'\n';}
template<class T> void outp(T a){cout<<'('<<a.fi<<','<<a.se<<')'<<'\n';}
template<class T> void outvp(T v){rep(i,v.size())cout<<'('<<v[i].fi<<','<<v[i].se<<')';cout<<'\n';}
template<class T> void outvvp(T v){rep(i,v.size())outvp(v[i]);}
template<class T> void outv(T v){rep(i,v.size()){if(i)cout<<' ';cout<<v[i];}cout<<'\n';}
template<class T> void outvv(T v){rep(i,v.size())outv(v[i]);}
template<class T> bool isin(T x,T l,T r){return (l)<=(x)&&(x)<=(r);}
template<class T> void yesno(T b){if(b)out("yes");else out("no");}
template<class T> void YesNo(T b){if(b)out("Yes");else out("No");}
template<class T> void YESNO(T b){if(b)out("YES");else out("NO");}
template<class T> void noyes(T b){if(b)out("no");else out("yes");}
template<class T> void NoYes(T b){if(b)out("No");else out("Yes");}
template<class T> void NOYES(T b){if(b)out("NO");else out("YES");}
void outs(ll a,ll b){if(a>=inf-100)out(b);else out(a);}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll modpow(ll a,ll b){a%=mod;if(b==0)return 1;if(b&1)return a*modpow(a,b-1)%mod;ll k=modpow(a,b/2);return k*k%mod;}
int main(){
    /*ll n,k;cin>>n>>k;
    ll ans=0;
    vi v(k+1);
    REP(i,1,k+1){
        ll t=i;
        REP(j,1,sqrt(i)+1){
            if(i%j==0)t-=v[j];
        }
        v[i]=t;
        ans=(ans+modpow(k/i,n)*t)%mod;
        out(ans);
    }
    out(ans);
    outv(v);*/
    ll n,k;cin>>n>>k;
    ll ans=0;
    vi dp(k+1);
    for(ll i=k;i>=1;i--){
        dp[i]=modpow(k/i,n);
        REP(j,2,k/i+1)dp[i]=(dp[i]+mod-dp[j*i])%mod;
    }
    REP(i,1,k+1){
        ans+=dp[i]*i;
        ans%=mod;
    }
    out(ans);
}

Measured memory_bytes: 4052
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
#include <string>
#include <queue>
#include <unordered_map>
#include <iterator>
#include <stack>
#include <unordered_set>
#include <iomanip>
#include <ctime>
#include <cstring>
#include <bitset>

#include <random>

using namespace std;
void dout() { cerr << endl; }
typedef long long ll;
template <typename Head, typename... Tail>
void dout(Head H, Tail... T) {
    cerr << H << ' ';
    dout(T...);
}

using ll = long long;
using pii = pair<ll, ll>;
using ld = long double;
using pll = pair<long long, long long>;

void precalc() {}

//#define solvsh
//#define multi
#ifdef solvsh

const int MAXN = 5e5 + 10;

vector<int> vals;

int n;

bool check_bit(int bt) {
    vector<int> crr;
    int mod = 1 << (bt + 1);

    for (int i = 0; i < n; ++i) {
        crr.push_back(vals[i] % mod);
    }

    ll cnt = 0;

    sort(crr.begin(), crr.end());

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

        int min = 0;
        int max = 0;

        int left = -1;
        int right = n;

        while (right - left > 1){
            int mid = (left + right) >> 1;

            if (crr[i] + crr[mid])

        }


        cnt += max - min + 1;

    }

    return cnt % 2 == 1;
}

void solve() {
    cin >> n;

    for (int i = 0; i < n; ++i) {
        int curr;
        cin >> curr;
        vals.push_back(curr);
    }

    int answr = 0;

    for (int k = 0; k < 25; ++k) {
        if (check_bit(k)) {
            answr |= 1 << k;
        }
    }

    cout << answr << "\n";
}

#else

void solve(){

    string s;
    cin >> s;

    int n = s.size();
    if (n % 2 == 1){
        cout << "No";
        return;
    }
    for (int i = 0; i < n / 2; ++i){
        if (s[2 * i] != 'h' || s[2 * i + 1] != 'i') {

            cout << "No";
            return;
        }
    }


    cout << "Yes";
    return;
}

#endif

void multisolve() {
    int t;
    cin >> t;

    while (t--)
        solve();
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr), cout.tie(nullptr);
    cout << fixed << setprecision(20);

    precalc();

#ifdef multi
    multisolve();
#else
    solve();
#endif

#ifdef LOCAL
    //cout << '\n' << (double)clock() / CLOCKS_PER_SEC << '\n';
#endif
}

Measured memory_bytes: 760
import sys
import bisect

sys.setrecursionlimit(10**7)
INF = 10 ** 18
MOD = 10 ** 9 + 7
def LI(): return list(map(int, sys.stdin.readline().split()))
def II(): return int(sys.stdin.readline())
def LS(): return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]

def main():
    n = II()
    ls = LI()
    ls = sorted(ls)
    ans = 0
    for i in range(n):
        for j in range(i):
            ans += j - (bisect.bisect_right(ls[:j], ls[i] - ls[j]))

            # ans += a
            # print(ls[i], ls[j], bisect.bisect_left(ls[:j], ls[i] - ls[j]))
            # if ls[i] < ls[j] + ls[h]:
            #     # print(ls[i], ls[j], ls[h])

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 50140
#include <bits/stdc++.h>
#define all(v) v.begin(), v.end()
#define rall(v) v.rbegin(), v.rend()
#define rep(i,n) for (int i=0;i<(int)(n);i++)
#define codefor int test;scanf("%d",&test);while(test--)
#define INT(...) int __VA_ARGS__;in(__VA_ARGS__)
#define LL(...) ll __VA_ARGS__;in(__VA_ARGS__)
#define yn(ans) if(ans)printf("Yes\n");else printf("No\n")
#define YN(ans) if(ans)printf("YES\n");else printf("NO\n")
#define vector2d(type,name,h,...) vector<vector<type>>name(h,vector<type>(__VA_ARGS__))
#define umap unordered_map
#define uset unordered_set
using namespace std;
using ll = long long;
const int MOD=1000000007;
//入力系
void scan(int& a){scanf("%d",&a);}
void scan(long long& a){scanf("%lld",&a);}
template<class T> void scan(T& a){cin>>a;}
template<class T> void scan(vector<T>& vec){for(auto&& it:vec)scan(it);}
void in(){}
template <class Head, class... Tail> void in(Head& head, Tail&... tail){scan(head);in(tail...);}
//出力系
void print(const int& a){printf("%d",a);}
void print(const long long& a){printf("%lld",a);}
void print(const double& a){printf("%.15lf",a);}
template<class T> void print(const T& a){cout<<a;}
template<class T> void print(const vector<T>& vec){if(vec.empty())return;print(vec[0]);for(auto it=vec.begin();++it!= vec.end();){putchar(' ');print(*it);}}
void out(){putchar('\n');}
template<class T> void out(const T& t){print(t);putchar('\n');}
template <class Head, class... Tail> void out(const Head& head,const Tail&... tail){print(head);putchar(' ');out(tail...);}
//デバッグ系
template<class T> void dprint(const T& a){cerr<<a;}
template<class T> void dprint(const vector<T>& vec){if(vec.empty())return;cerr<<vec[0];for(auto it=vec.begin();++it!= vec.end();){cerr<<" "<<*it;}}
void debug(){cerr<<endl;}
template<class T> void debug(const T& t){dprint(t);cerr<<endl;}
template <class Head, class... Tail> void debug(const Head& head, const Tail&... tail){dprint(head);cerr<<" ";debug(tail...);}
ll intpow(ll a, ll b){ ll ans = 1; while(b){ if(b & 1) ans *= a; a *= a; b /= 2; } return ans; }
ll modpow(ll a, ll b, ll p){ ll ans = 1; while(b){ if(b & 1) (ans *= a) %= p; (a *= a) %= p; b /= 2; } return ans; }

int main(){
    INT(n,q);
    vector<vector<int>> tree(n);
    int x,y,a;
    rep(i,n-1){
        in(x,y);
        tree[x-1].push_back(y-1);
        tree[y-1].push_back(x-1);
    }
    map<int,ll> map1;
    rep(i,q){
        in(x,y);
        if(map1.count(x-1)){
            map1[x-1]+=(ll)y;
        }else{
            map1[x-1]=(ll)y;
        }
    }
    vector<ll> ans(n,-1);
    queue<int> next;
    next.push(0);
    ans[0]=0;
    while(!next.empty()){
        a=next.front();
        next.pop();
        if(map1.count(a)){
            ans[a]+=(ll)map1[a];
        }
        if(tree[a].size()==0)continue;
        rep(i,tree[a].size()){
            if(ans[tree[a][i]]==-1){
                ans[tree[a][i]]=ans[a];
                next.push(tree[a][i]);
            }
        }
    }
    out(ans);
}

Measured memory_bytes: 29872
#include <iostream>

using namespace std;

int main(){
	int x1,x2,y1,y2;
	cin >> x1>>y1>>x2>>y2;
	int heny=y2-y1,henx=x1-x2;
	cout<<x2-heny<<" "<<y2-henx<<" "<<x1-heny<<" "<<y1-henx<<endl;
	return 0;
}

Measured memory_bytes: 256
use std::cmp::Ordering;

/// Equivalent to std::lowerbound and std::upperbound in c++
pub trait BinarySearch<T> {
    fn lower_bound(&self, x: &T) -> usize;
    fn upper_bound(&self, x: &T) -> usize;
}

impl<T: Ord> BinarySearch<T> for [T] {
    fn lower_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less => {
                    low = mid + 1;
                }
                Ordering::Equal | Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }

    fn upper_bound(&self, x: &T) -> usize {
        let mut low = 0;
        let mut high = self.len();

        while low != high {
            let mid = (low + high) / 2;
            match self[mid].cmp(x) {
                Ordering::Less | Ordering::Equal => {
                    low = mid + 1;
                }
                Ordering::Greater => {
                    high = mid;
                }
            }
        }
        low
    }
}

// 標準入力から一行を読み取り、指定の型に変換する
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

// 標準入力から一行を読み取り、空白文字で分割し、各要素を指定の型に変換する関数
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace()
        .map(|e| e.parse().ok().unwrap()).collect()
}

fn main() {
    let nm: Vec<usize> = read_vec();
    let n = nm[0];
    let m = nm[1];

    let mut data: Vec<Vec<u64>> = vec![Vec::new(); m];
    for i in 0..m
    {
        let e: Vec<u64> = read_vec();
        data[i] = e;
    }

    // Piの値ごとの配列に分ける...元のデータとは別に用意しなければならない(最後のprintで使うため)
    let mut vals = vec![Vec::new(); n];
    for e in &data
    {
        vals[(e[0] - 1) as usize].push(e[1]);
    }

    // Piごとにソート
    for i in 0..n
    {
        vals[i].sort();
    }

    // 二分探索を用いて求める結果を出力
    for i in 0..m
    {
        print!("{:06}", data[i][0]);
        println!("{:06}", vals[data[i][0] as usize - 1].lower_bound(&data[i][1]) + 1);
    }
}


Measured memory_bytes: 17916
package main

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

var sc = bufio.NewScanner(os.Stdin)
var out = bufio.NewWriter(os.Stdout)

func main() {
	sc.Split(bufio.ScanWords)
	defer out.Flush() // !!!!coution!!!! you must use Fprint(out, ) not Print()
	/* --- code ---*/
	N := nextInt()
	fmt.Fprintln(out, N*N*N)
}

func next() string {
	sc.Scan()
	return sc.Text()
}

func nextInt() int {
	a, _ := strconv.Atoi(next())
	return a
}

func nextFloat64() float64 {
	a, _ := strconv.ParseFloat(next(), 64)
	return a
}

func nextInts(n int) []int {
	ret := make([]int, n)
	for i := 0; i < n; i++ {
		ret[i] = nextInt()
	}
	return ret
}
func nextFloats(n int) []float64 {
	ret := make([]float64, n)
	for i := 0; i < n; i++ {
		ret[i] = nextFloat64()
	}
	return ret
}
func nextStrings(n int) []string {
	ret := make([]string, n)
	for i := 0; i < n; i++ {
		ret[i] = next()
	}
	return ret
}

// Genericsがないので筋肉で...
// interfaceでの取扱がようわからんし
func containStr(arr []string, target string) bool {
	for _, v := range arr {
		if v == target {
			return true
		}
	}
	return false
}

func PrintOut(src interface{}, joinner string) {
	switch reflect.TypeOf(src).Kind() {
	case reflect.Slice:
		s := reflect.ValueOf(src)
		for idx := 0; idx < s.Len(); idx++ {
			fmt.Fprintf(out, "%v", s.Index(idx))
			if idx < s.Len()-1 {
				fmt.Fprintf(out, "%s", joinner)
			} else {
				fmt.Fprintln(out)
			}
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
}

// mapからkeysとvaluesを返す感じのやつ
// なんかしらんけどmap[interface{}]interface{}しか受け付けない。なんのためのinterface{}やねん
// なので呼ぶときのmapはmap[int]stringとかじゃダメ
func splitKeyValue(m map[interface{}]interface{}) (keys, values []interface{}) {
	switch reflect.TypeOf(m).Kind() {
	case reflect.Map:
		s := reflect.ValueOf(m)
		for _, v := range s.MapKeys() {
			keys = append(keys, v)
			values = append(values, s.MapIndex(v))
		}
	default:
		fmt.Fprintln(out, "fuck")
	}
	return
}


Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FOR(i, m, n) for (int i = m; i < (n); i++)
#define RFOR(i, m, n) for (int i = (m - 1); i >= 0; i--)
#define REP(i, n) FOR(i, 0, n)
#define RREP(i, n) RFOR(i, n, 0)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define print(ele) cout << ele << endl
#define print10(ele) cout << fixed << setprecision(10) << ele << endl

using namespace std;
typedef long long ll;
typedef vector<int> ivec;
typedef vector<string> svec;
typedef vector<ll> lvec;

const int mod = 1e9 + 7;
const ll INF = 1000000000000000000LL;

int main() {
  int n, a, b, c, d;
  char s[1001000];
  // cin >> n >> a >> b >> c >> d >> s;

  scanf("%d%d%d%d%d", &n, &a, &b, &c, &d);
  scanf("%s", s + 1);

  FOR(i, a, c) {
    if (s[i] == '#' && s[i + 1] == '#') return print("No"), 0;
  }
  FOR(i, b, d) {
    if (s[i] == '#' && s[i + 1] == '#') return print("No"), 0;
  }

  if (c > d) {
    bool bo = false;
    for (int i = b; i <= d; i++)
      if (s[i] == '.' && s[i + 1] == '.' && s[i - 1] == '.') bo = true;
    if (!bo) return puts("No"), 0;
  }
  print("Yes");
  return 0;
}

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

#define rep(i,n) for(int i=0; i<(n); ++i)
using ll = long long;
using P = pair<int, int>;
template<class T> inline bool chmin(T& a, T b) {if (a > b) { a = b; return true; } return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) { a = b; return true; } return false;}

const int MAX_N = 10 + 3;

int main() {
  vector<ll> dp(MAX_N, 0);
  dp[0] = 1;
  dp[1] = 2;
  dp[2] = 4;
  for (int i=3; i<30; ++i) {
    dp[i] = dp[i-1] + dp[i-2] + dp[i-3];
    //    printf("[*] dp[%d] = %lld\n", i, dp[i]);
  }
  
  while (true) {
    int n;
    cin >> n;
    if (n == 0) break;
    cout << (dp[n-1] + 3650 - 1) / 3650 << endl;
  }
  return 0;
}



Measured memory_bytes: 3000
#include <stdio.h>
#include <math.h>
 
int main(void)
{
    int a, b, c;
    double d;
    double S, L, h;
    double sinc, cosc;
     
    scanf("%d%d%d", &a, &b, &c);
     
    sinc=sin(c/180.0*3.14159265);
    cosc=cos(c/180.0*3.14159265);
    d=sqrt(a*a+b*b-2*a*b*cosc);
     
    S=a*b*sinc/2.0;
    L=a+b+d;
    h=b*sinc;
     
    printf("%f\n%f\n%f\n", S, L, h);
     
    return 0;
}

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

using namespace std;

#define rep(i, n) for(int i = 0; i < (int)n; ++i)
#define FOR(i, a, b) for(int i = a; i < (int)b; ++i)

typedef long long ll;

const int Inf = 1e9;
const double EPS = 1e-9;

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

int lcm(int a, int b) {
    return a * b / gcd(a, b);
}

int bitCount(long bits) {
    bits = (bits & 0x55555555) + (bits >> 1 & 0x55555555);
    bits = (bits & 0x33333333) + (bits >> 2 & 0x33333333);
    bits = (bits & 0x0f0f0f0f) + (bits >> 4 & 0x0f0f0f0f);
    bits = (bits & 0x00ff00ff) + (bits >> 8 & 0x00ff00ff);
    return (bits & 0x0000ffff) + (bits >>16 & 0x0000ffff);
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int x, y, z;  cin >> x >> y >> z;
    x -= z;
    cout << x / (y + z) << '\n';

    return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
lr=[]
for i in range(m):
    lr.append(list(map(int,input().split())))
zen=[1,n]
for i in range(m):
    if lr[i][0]>zen[0]:
        zen[0]=lr[i][0]
    if lr[i][1]<zen[1]:
        zen[1]=lr[i][1]
print(max(0,zen[1]-zen[0]+1))

Measured memory_bytes: 27344
#include <bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;

using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int g[15][15];

int main() {
    int n;
    cin >> n;
    rep(i, n) rep(j, n) g[i][j] = -1;
    rep(i, n) {
        int a;
        cin >> a;
        rep(j, a) {
            int x, y;
            cin >> x >> y;
            --x;
            g[i][x] = y;
        }
    }

    int ans = 0;
    for(int bit = 0; bit < (1 << n); bit++) {
        vi d(n);
        rep(j, n) {
            if(bit & (1 << j)) d[j] = 1;
        }

        bool ok = true;
        rep(j, n) {
            if(d[j]) {
                rep(k, n) {
                    if(g[j][k] == -1) continue;
                    if(g[j][k] != d[k]) ok = false;
                }
            }
        }

        int cnt = 0;
        if(ok) {
            rep(j, n) {
                if(bit & (1 << j)) cnt++;
            }
            ans = max(ans, cnt);
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 256
// 7/4 Tuesday
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
	int n,ans;
	cin >> n;
	vector <int> A(n);
	for (int i = 0; i < n; i++) {
		cin >> A[i];
	}

	sort(A.begin(), A.end());
	ans = A[n-1] - A[0];
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<stdlib.h>

int compare_int(const void *a, const void *b)
{
    return *(int*)a - *(int*)b;
}

int main(void){
  int N; scanf("%d", &N);
  int d[N];
  for(int i1=0;i1<N;i1++){
    scanf("%d", &d[i1]);
  }
  qsort(d, N, sizeof(int), compare_int);

  printf("%d", d[N/2]-d[N/2-1]);

  return 0;
}

Measured memory_bytes: 892
#include <iostream>
#include <sstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <climits>
#include <cfloat>
using namespace std;

int main()
{
    for(;;){
        int n;
        cin >> n;
        if(n == 0)
            return 0;

        string s;
        cin >> s;

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

        for(int i=n-1; i>=0; --i){
            swap(s[a[i]], s[b[i]]);
            s[a[i]] = (s[a[i]] - 'a' + b[i] - a[i]) % 26 + 'a';
            s[b[i]] = (s[b[i]] - 'a' + b[i] - a[i]) % 26 + 'a';
        }

        cout << s << endl;
    }
}

Measured memory_bytes: 0
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace exawizards2019
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ').Select(int.Parse);
            if (input.All(x => x == input.First())) Console.WriteLine("Yes");
            else Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 11220
#include <bits/stdc++.h>
#define ll long long
#define Max(a,b) (a>b?a:b)
const int N=100050;
using namespace std;
inline int gi(){
  char ch=getchar();int x=0,q=0;
  while(ch<'0' || ch>'9') ch=='-'?q=1:0,ch=getchar();
  while(ch>='0' && ch<='9') x=x*10+ch-'0',ch=getchar();
  return q?(-x):x;
}
int a[N];
ll t[N],sum,ans;
int main(){
  int n=gi(),m=gi();
  for (int i=1; i<=n; ++i){
    a[i]=gi();
    if (a[i]>a[i-1]) sum+=a[i]-a[i-1];
    else sum+=m+a[i]-a[i-1];
  }
  sum-=a[1];
  for (int i=2; i<=n; ++i)
    if (a[i]>a[i-1]){
      if (a[i]>a[i-1]+1)
	++t[a[i-1]+2],t[a[i]+1]-=a[i]-a[i-1],t[a[i]+2]+=a[i]-a[i-1]-1;
    }
    else{
      if (a[i-1]==m&&a[i]==1) continue;
      ++t[a[i-1]+2];
      if (a[i-1]==m) ++t[2];
      else t[1]+=m-a[i-1],t[2]-=m-a[i-1]-1;
      t[a[i]+1]-=m-a[i-1]+a[i],t[a[i]+2]+=m-a[i-1]+a[i]-1;
    }
  for (int i=1; i<=m; ++i) t[i]+=t[i-1];
  for (int i=1; i<=m; ++i)
    t[i]+=t[i-1],ans=Max(ans,t[i]);
  cout<<sum-ans;
  return 0;
}


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

int main() {
    //
    int sx, tx, sy, ty;

    cin >> sx >> sy >> tx >> ty;

    int x, y;

    //①↑→最短
    x = abs(ty - sy);
    y = abs(tx - sx);
    for (int i = 0; i < x; i++) cout << "U";
    for (int i = 0; i < y; i++) cout << "R";

    //②↓←最短(①と同じ値)
    x = abs(ty - sy);
    y = abs(tx - sx);
    for (int i = 0; i < x; i++) cout << "D";
    for (int i = 0; i < y; i++) cout << "L";

    //③↑→ ①+1ずつ
    x = abs(ty - sy)+1;
    y = abs(tx - sx)+1;
    cout << "L";//+1分
    for (int i = 0; i < x; i++) cout << "U";
    for (int i = 0; i < y; i++) cout << "R";
    cout << "D";//+1分

    //④↑→ ②+1ずつ
    x = abs(ty - sy)+1;
    y = abs(tx - sx)+1;
    cout << "R";//+1分
    for (int i = 0; i < x; i++) cout << "D";
    for (int i = 0; i < y; i++) cout << "L";
    cout << "U";//+1分

    cout << endl;
    //
}


Measured memory_bytes: 3616
// ------------------------------------
// Date:2018/ 2/23
// Problem:ABC 048 BetweenAAndB... b.cpp
//
// ------------------------------------

#include <bits/stdc++.h>

using namespace std;

#define EACH(i,a) for (auto&& i : a)
#define FOR(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define RFOR(i,a,b) for(int i=(int)b-1;i>=(int)a;--i)
#define REP(i,n) FOR(i,0,n)
#define RREP(i,n) RFOR(i,0,n)
#define ALL(a) (a).begin(),(a).end()

using ll = long long;

#define MOD 1000000007

int main()
{
  ll a,b,x;
  cin >> a >> b >> x;
  b = b/x;
  a = (a?a-1:-x)/x;
  cout << b-a << endl;
  return 0;
}


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

int main()
{
    ll n, ans = 0;
    cin >> n;
    vector<int> a(n);
    vector<int> b(n);
    vector<int> c(n);
    rep(i, n) cin >> a[i];
    rep(i, n) cin >> b[i];
    rep(i, n) cin >> c[i];
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());
    rep(i, n)
    {
        ll A = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        ll C = c.end() - upper_bound(c.begin(), c.end(), b[i]);
        ans += A * C;
    }
    cout << ans << endl;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<ll, ll> P;

#define EACH(i,a) for (auto& i : a)
#define FOR(i,a,b) for (ll i=(a);i<(b);i++)
#define RFOR(i,a,b) for (ll i=(b)-1;i>=(a);i--)
#define REP(i,n) for (ll i=0;i<(n);i++)
#define RREP(i,n) for (ll i=(n)-1;i>=0;i--)
#define debug(x) cout<<#x<<": "<<x<<endl
#define pb push_back
#define ALL(a) (a).begin(),(a).end()

const ll linf = 1e18;
const int inf = 1e9;
const double eps = 1e-12;
const double pi = acos(-1);

template<typename T>
istream& operator>>(istream& is, vector<T>& vec) {
    EACH(x,vec) is >> x;
    return is;
}
template<typename T>
ostream& operator<<(ostream& os, vector<T>& vec) {
    REP(i,vec.size()) {
        if (i) os << " ";
        os << vec[i];
    }
    return os;
}
template<typename T>
ostream& operator<<(ostream& os, vector< vector<T> >& vec) {
    REP(i,vec.size()) {
        if (i) os << endl;
        os << vec[i];
    }
    return os;
}

int main() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(0);
    ll W, H; cin >> W >> H;
    vector<ll> p(W), q(H); cin >> p >> q;
    vector<P> v;
    REP(i, p.size()) {
        v.pb({p[i], 0});
    }
    REP(i, q.size()) {
        v.pb({q[i], 1});
    }
    sort( ALL(v) );
    vector<ll> rest = {W+1, H+1};
    ll ans = 0;
    EACH(pr, v) {
        ll cost, type; tie(cost, type) = pr;
        ll otype = (type+1)%2;
        ans += rest[otype] * cost;
        rest[type]--;
    }
    cout << ans << endl;
}


Measured memory_bytes: 6128
n, k = map(int,input().split())
lis = []
for _ in range(n):
  lis.append(int(input()))
ans = 100000000000000
lis.sort()
for i in range(n-k+1):
  s = lis[i+k-1]-lis[i]
  if s < ans:
    ans = s
print(ans)

Measured memory_bytes: 7484
# 最大公約数
def gcd(a, b):
    while b != 0:
        a, b = b, a % b
    return a

N = int(input())
A= list(map(int,input().split()))

g = gcd(A[0],A[1])
for i in range(2,N):
    g = gcd(g,A[i])
print(g)


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

#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;

int main()
{
    using vi = vector<int>;
    using vvi = vector<vi>;
    using vvvi = vector<vvi>;
    using ll = long long;

    int N;
    cin >> N;
    vi d(N);
    rep(i, N) cin >> d[i];

    int sum = 0;
    for(int i = 0; i < N; i++)
    {
        for(int j = i + 1; j < N; j++)
        {
           sum += d[i] * d[j];
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <sstream>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <cmath>
#include <cstring>
#include <typeinfo>
#include <numeric>
#include <functional>
#include <unordered_map>
#include <bitset>
#include <stack>
#include <assert.h>
#include <unordered_set>
#include <random>


using namespace std;
using ll = long long;
using ull = unsigned long long;

const ll INF = 1e18;
const ll MOD = 1e9 + 7;

#define REP(i, n) for(ll i = 0; i < n; i++)



















int main(){
    ll n, a, b, c;
    cin >> n >> a >> b >> c;
    vector<string> s(n);
    REP(i, n){
        cin >> s[i];
    }
    vector<char> ans(n);
    [&, dfs = [&](auto &&dfs, ll now, ll a, ll b, ll c){
        if(a < 0 || b < 0 || c < 0) return;
        if(now == n){
            cout << "Yes" << endl;
            REP(i, n){
                cout << ans[i] << endl;
            }
            exit(0);
        }
        if(s[now] == "AB"){
            ans[now] = 'A';
            dfs(dfs, now + 1, a + 1, b - 1, c);
            ans[now] = 'B';
            dfs(dfs, now + 1, a - 1, b + 1, c);
        }
        else if(s[now] == "AC"){
            ans[now] = 'A';
            dfs(dfs, now + 1, a + 1, b, c - 1);
            ans[now] = 'C';
            dfs(dfs, now + 1, a - 1, b, c + 1);
        }
        else{
            ans[now] = 'B';
            dfs(dfs, now + 1, a, b + 1, c - 1);
            ans[now] = 'C';
            dfs(dfs, now + 1, a, b - 1, c + 1);
        }
    }](){ dfs(dfs, 0, a, b, c); }();
    cout << "No" << endl;
}


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

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<pii> vpii;

int main() {

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

    unsigned int n, k;
    cin >> n >> k;

    map<unsigned int, ll> m;
    rep(i, 30) {
        if (k & (1 << i)) {
            unsigned int x = k - (1 << i);
            m[x | ((1 << i) - 1)] = 0;
        }
    }
    m[k] = 0;

    rep(i, n) {
        unsigned int a, b;
        cin >> a >> b;
        for(auto& p : m) {
            if ((p.first & a) == a) {
                p.second += b;
            }
        }
    }

    ll ans = 0;
    for(auto& p: m) {
        // cout << p.first << endl;
        ans = max(ans, p.second);
    }

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


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long   signed int LL;
typedef long long unsigned int LU;
#define incID(i, l, r) for(LL i = (l)    ; i <  (r); ++i)
#define incII(i, l, r) for(LL i = (l)    ; i <= (r); ++i)
#define decID(i, l, r) for(LL i = (r) - 1; i >= (l); --i)
#define decII(i, l, r) for(LL i = (r)    ; i >= (l); --i)
#define inc(i, n)  incID(i, 0, n)
#define inc1(i, n) incII(i, 1, n)
#define dec(i, n)  decID(i, 0, n)
#define dec1(i, n) decII(i, 1, n)
#define inID(v, l, r) ((l) <= (v) && (v) <  (r))
#define inII(v, l, r) ((l) <= (v) && (v) <= (r))
#define PB push_back
#define EB emplace_back
#define MP make_pair
#define FI first
#define SE second
#define  ALL(v)  v.begin(),  v.end()
#define RALL(v) v.rbegin(), v.rend()
template<typename T> bool setmin  (T & a, T b) { if(b <  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmax  (T & a, T b) { if(b >  a) { a = b; return true; } else { return false; } }
template<typename T> bool setmineq(T & a, T b) { if(b <= a) { a = b; return true; } else { return false; } }
template<typename T> bool setmaxeq(T & a, T b) { if(b >= a) { a = b; return true; } else { return false; } }
LL mo(LL a, LL b) { assert(b > 0); a %= b; if(a < 0) { a += b; } return a; }
LL fl(LL a, LL b) { assert(b > 0); return (a > 0 ? a / b : (a - b + 1) / b); }
LL ce(LL a, LL b) { assert(b > 0); return (a < 0 ? a / b : (a + b - 1) / b); }
template<typename T> T gcd(T a, T b) { return (b == 0 ? a : gcd(b, a % b)); }
template<typename T> T lcm(T a, T b) { return a / gcd(a, b) * b; }
#define bit(b, i) (((b) >> (i)) & 1)
#define BC __builtin_popcountll
#define SC static_cast
#define SI(v) SC<int>(v.size())
#define SL(v) SC<LL >(v.size())
#define RF(e, v) for(auto & e: v)
#define ef else if
#define UR assert(false)

// ---- ----

int n;

int main() {
	cin >> n;
	
	bool ans = false;
	incII(i, 1, 9) {
	incII(j, 1, 9) {
		ans |= (n == i * j);
	}
	}
	
	cout << (ans ? "Yes" : "No") << endl;
	
	return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <math.h>

int main()
{
    int x[5]={0},y[5]={0};
    scanf("%d %d %d %d",&x[1],&y[1],&x[2],&y[2]);
    x[0]=x[2]-x[1];
    y[0]=y[2]-y[1];
    x[3]=x[2]-y[0];
    y[3]=y[2]+x[0];
    x[4]=x[3]-x[0];
    y[4]=y[3]-y[0];
    printf("%d %d %d %d",x[3],y[3],x[4],y[4]);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define FASTio ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long int 
#define endl '\n'
ll mod=1e9+7;

int main()
{
   FASTio;
    #ifndef ONLINE_JUDGE                    //file start
    freopen("input.txt","r",stdin);
    freopen("output.txt","w",stdout);   
    #endif                                  //file end
    int t,i;
    cin>>t;
    string s="";
    while(t--)
        s+= "ACL";
    cout<<s<<"\n";
    return 0;
}

Measured memory_bytes: 3640
#include <vector>
#include <stack>
#include <queue>
#include <list>
#include <bitset>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <iostream>
#include <iomanip>
#include <string>
#include <chrono>
#include <random>
#include <cmath>
#include <cassert>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <functional>
#include <sstream>

using namespace std;


int main(int argc, char** argv) {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(12);


    int n;
    cin >> n;
    vector<int> X(n);
    vector<int> Y(n);
    vector<long long> P(n);
    for (int i = 0; i < n; ++i) {
        cin >> X[i] >> Y[i] >> P[i];
    }

    int N = 1 << n;
    const long long INF = 1LL << 50;
    vector<vector<long long>> DX(N, vector<long long>(n, INF));
    vector<vector<long long>> DY(N, vector<long long>(n, INF));
    for (int i = 0; i < N; ++i) {
        for (int j = 0; j < n; ++j) {
            DX[i][j] = min(DX[i][j], abs(0LL + X[j]));
            DY[i][j] = min(DY[i][j], abs(0LL + Y[j]));

            for (int k = 0; k < n; ++k) {
                if ((i >> k) & 1) {
                    DX[i][j] = min(DX[i][j], abs(0LL + X[j] - X[k]));
                    DY[i][j] = min(DY[i][j], abs(0LL + Y[j] - Y[k]));
                }
            }
        }
    }

    vector<long long> res(n + 1, INF);

    for (int i = 0; i < N; ++i) {
        int cnt = 0;
        for (int j = 0; j < n; ++j) {
            if ((i >> j) & 1) {
                ++cnt;
            }
        }

        for (int s = i; s >= 0; --s) {
            s &= i;
            long long ans = 0;
            for (int j = 0; j < n; ++j) {
                if ((i >> j) & 1) {
                    continue;
                }
                ans += min(DX[s][j], DY[s ^ i][j]) * 1LL * P[j];
            }
            res[cnt] = min(res[cnt], ans);
        }


    }



    for (int i = 0; i <= n; ++i) {
        cout << res[i] << '\n';
    }


    return 0;
}

Measured memory_bytes: 12932
#pragma warning(disable:4786)
#pragma warning(disable:4996)
#include<list>
#include<bitset>
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<functional>
#include<string>
#include<cstring>
#include<cstdlib>
#include<queue>
#include<utility>
#include<fstream>
#include<sstream>
#include<cmath>
#include<stack>
#include<assert.h>
using namespace std;

#define MEM(a, b) memset(a, (b), sizeof(a))
#define CLR(a) memset(a, 0, sizeof(a))
#define MAX(a, b) ((a) > (b) ? (a) : (b))
#define MIN(a, b) ((a) < (b) ? (a) : (b))
#define ABS(X) ( (X) > 0 ? (X) : ( -(X) ) )
#define S(X) ( (X) * (X) )
#define SZ(V) (int )V.size()
#define FORN(i, n) for(i = 0; i < n; i++)
#define FORAB(i, a, b) for(i = a; i <= b; i++)
#define ALL(V) V.begin(), V.end()
#define IN(A, B, C)  ((B) <= (A) && (A) <= (C))

typedef pair<int,int> PII;
typedef pair<double, double> PDD;
typedef vector<int> VI;
typedef vector<PII > VP;

#define AIN(A, B, C) assert(IN(A, B, C))

//typedef int LL;
typedef long long int LL;
//typedef __int64 LL;

VP V;

int main()
{
	int n;
	int a;

	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d", &a);
		V.push_back(PII(a, i));
	}

	sort(ALL(V));
	set<int> S;
	S.insert(-1);
	S.insert(n);
	LL ans = 0;
	for (int i = 0; i < n; i++) {
		int pos = V[i].second;
		set<int>::iterator iS = S.lower_bound(pos);
		int right = *iS;
		iS--;
		int left = *iS;
		ans += 1LL * V[i].first * (pos - left) * (right - pos);
		S.insert(pos);
	}

	printf("%lld\n", ans);
	return 0;
}


Measured memory_bytes: 11248
class UnionFind:
    def __init__(self, size):
        self.parent = [i for i in range(size)]
        self.size = [1]*size

    def find(self, x):
        if self.parent[x] == x:
            return x
        # path compression
        self.parent[x] = self.find(self.parent[x])
        return self.parent[x]
    
    def unite(self, x, y):
        x, y = self.find(x), self.find(y)
        if x == y:
            return
        # union by size
        if self.size[x] < self.size[y]:
            self.size[y] += self.size[x]
            self.parent[x] = y
        else:
            self.size[x] += self.size[y]
            self.parent[y] = x
    
    def same(self, x, y):
        return self.find(x) == self.find(y)
    
    def sizeofset(self, x):
        return self.size[self.find(x)]


if __name__ == "__main__":
    N, M = map(int,input().split())
    uf = UnionFind(N)
    for _ in range(M):
        a, b = map(int,input().split())
        uf.unite(a-1, b-1)
    print(max([uf.sizeofset(a) for a in range(N)]))

Measured memory_bytes: 20128
import java.util.Scanner;

public class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		long x = sc.nextLong();
		long cnt = 0;
		long mon = 100;
		while(true) {
			if(x <= mon) {
				System.out.println(cnt);
				break;
			}
			mon+=mon/100;
			cnt++;
		}
	}
	
}


Measured memory_bytes: 27036
#include <cstdio>
#include <climits>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <cmath>
#include <stack>
#include <algorithm>
#include <iomanip>
#include <map>
#include <queue>
#include <functional>
#include <numeric>
#include <chrono>
#include <cstdlib>
using ll = long long;
using namespace std;

const ll MOD = 1e9 + 7;
const double pi = acos(-1);
typedef pair<int, int> P;
#define REP(i, n) for (int(i) = 0; (i) < (n); ++(i))
#define repi(i, a, b) for (int i = int(a); i < int(b); ++i)
#define EPS 1e-4
#define OUTPUT(i) (cout << (ll)i << endl)
#define ALL(a) ((a).begin(), (a).end())

bool operator<(const pair<ll, ll> &a, const pair<ll, ll> &b)
{

    if (a.first == b.first)
        return a.second < b.second;

    return a.first < b.first;
}

struct table
{
    int c, s, f;
};
double dp[100010];
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);

    cout << fixed << setprecision(15);

    ll N, Y;
    cin >> N >> Y;

    for (int i = N; i >= 0; i--)
    {
        for (int j = 0; j <= N - i; ++j)
        {
            if ((10000 * i + 5000 * j + 1000 * (N - i - j)) == Y)
            {
                cout << i << " " << j << " " << N - i - j << endl;
                return 0;
            }
        }
    }
    cout << -1 << " " << -1 << " " << -1 << endl;
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>
#include<complex>

using namespace std;

typedef long long            ll;
typedef unsigned             ui;
typedef unsigned long long   ull;
typedef pair<int,int>        i_i;
typedef pair<ll,int>         ll_i;
typedef pair<ll,ll>          ll_ll;
typedef pair<double,int>     d_i;
typedef pair<double,double>  d_d;
typedef vector<int>          vi;
typedef vector<vector<int> > vii;

#ifdef DEBUG
#define dprintf      printf
#define dputs        puts
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dputs        (1)?0:puts
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long
#ifndef int
#define INF __INT32_MAX__
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}


int a[334][334];
int where[334*334][2];
int dp[100000]={};
signed main(void)
{
  int h,w,d;
  cin>>h>>w>>d;
  int i,j;
  rep(i,h){
    rep(j,w){
      cin>>a[i][j];
      where[a[i][j]][0]=i;
      where[a[i][j]][1]=j;
    }
  }
  int n=h*w;

  rep(i,d){
    for(j=i+d;j<=n;j+=d){
      dp[j]=
        dp[j-d]                          // 1ステップ前のコスト
        +abs(where[j][0]-where[j-d][0])  // 1ステップ前の地点からのdx
        +abs(where[j][1]-where[j-d][1]); // 1ステップ前の地点からのdy
    }
  }

  in(int,q);
  rep(i,q){
    in(int,l,r);
    putv(dp[r]-dp[l]);
  }
  return 0;
}


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

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

    vector<int> a(n);
    a[0] = b[0];
    for(int i = 1; i < n - 1; ++i)
        a[i] = min(b[i], b[i - 1]);
    
    ll res = 0;
    a[n - 1] = b[n - 2];
    for(int i = 0; i < n; ++i)
        res += a[i];

    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
const long long int MOD=1e9+7;
int main() {
	int n,m;
	cin>>n>>m;
	if(abs(n-m)>1){
		cout<<0;
		return 0;
	}
	long long int ans=1;
	for(int i=1;i<=n;i++){
		ans=(ans*i)%MOD;
	}
	for(int i=1;i<=m;i++){
		ans=(ans*i)%MOD;
	}
	if(n==m) cout<<(2*ans)%MOD;
	else cout<<ans;
}

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

int main(){
  int n,k,ans=1e9;cin>>n>>k;
  vector<int> x(n,0);
  REP(i,n) cin>>x.at(i);
  REP(i,n-k+1){
    if(x.at(i)<0 && x.at(i+k-1)>=0) ans=min(ans,-x.at(i)*2+x.at(i+k-1));
    else if(x.at(i)>=0 && x.at(i+k-1)>=0) ans=min(ans,x.at(i+k-1));
  }
  for(int i=n-1;i>=k-1;i--){
    if(x.at(i)>0 && x.at(i-k+1)<=0) ans=min(ans,x.at(i)*2-x.at(i-k+1));  
    else if(x.at(i)<=0 && x.at(i-k+1)<=0) ans=min(ans,-x.at(i-k+1));
  }  
  cout<<ans;
}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define endl '\n'
using namespace std;

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    
    int s,w;
    cin>>s>>w;
    if(w>=s){
    	cout<<"unsafe";
	}
	else{
		cout<<"safe";
	}
    
//system("pause");
return 0;

}


Measured memory_bytes: 3652