akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <algorithm>
#include <deque>
#include <utility>
using namespace std;
typedef long long ll;
#define for1(i,n) for (ll i=0;i<(n);i++)
#define for2(i,m,n) for (ll i=(m);i<(n);i++)
#define for3(i,m,n,d) for (ll i=(m);i<(n);i+=(d))

ll X[16][16];

void solve()
{
    ll N,D;
    cin >> N >> D;
    for1(i,N) {
        for1(d,D) {
            ll x;
            cin >> X[i][d];
        }
    }
    ll ans = 0;
    for1(i,N) {
        for2(j,i+1,N) {
            ll distance = 0;
            for1(d,D) {
                ll a = X[i][d] - X[j][d];
                distance += a * a;
            }
            ll r = (ll)pow((double)distance, 0.5);
            if (r*r == distance) {
                ++ans;
            }
        }
    }

    cout << ans << endl;
}

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


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

using namespace std;

#define rep(i,n) for(int i=0;i<(n);i++)
#define repa(i,a,n) for(int i=(a);i<(n);i++)
#define rrep(i,n) for(int i=n;i>=0;i--)
#define rrepa(i,a,n) for(int i=n;i>=(a);i--)
#define all(a) (a).begin(),(a).end()
#define MOD 1000000007
#define maxs(a,b) a=max(a,b);
#define mins(a,b) a=min(a,b);

typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<int,int> pi;

int main(){
   
    int n,m;cin>>n>>m;
    vector<vector<pair<ll,int>>> to(n);
    int l,r,c;
    repa(i,1,n)to[i].emplace_back(i-1,0);
    rep(i,m){
        cin>>l>>r>>c;
        l--;
        r--;
        to[l].emplace_back(r,c);
    } 

    priority_queue<pair<ll,int>,vector<pair<ll,int>>,greater<pair<ll,int>>> que;
    que.emplace(0,0);
    vi checked(n,0);
    vl cost(n,LLONG_MAX);
    cost[0]=0;

    while(!que.empty()){
        auto v=que.top();que.pop();
        if(checked[v.second])continue;
        checked[v.second]=1;
        // cerr<<"checking "<<v.second<<endl;
        rep(i,to[v.second].size()){
            if(cost[to[v.second][i].first] > cost[v.second]+to[v.second][i].second){
                cost[to[v.second][i].first] = cost[v.second]+to[v.second][i].second;
                // cerr<<" cost["<<i<<"]="<<cost[i]<<endl;
                que.emplace(cost[to[v.second][i].first],to[v.second][i].first);
            }
        }
    }

    // rep(i,n){
    //     cerr<<i<<" "<<cost[i]<<endl;
    // }

    if(cost[n-1]==LLONG_MAX){
        cout<<-1<<endl;
    }else{
        cout<<cost[n-1]<<endl;
    }
    
    return 0;
}

Measured memory_bytes: 10488
#include<iostream>
#include<vector>

using namespace std;

int main()
{
	int n;
	vector<int> prime;
	int i,j;
	
	for(i=0;i<1000000;i++)
	{
		prime.push_back(1);
	}
	prime[0]=prime[1]=0;
	
	for(i=0;i<1000000;i++)
	{
		if(prime[i]==1)
		{
			for(j=2;j*i<1000000;j++)
			{
				prime[i*j]=0;
			}
		}
	}
	
	for(;;)
	{
		cin >> n ;
		if(n==0)
			break;
		
		int ans=0;
		
		for(i=0;i<=n-i;i++)
		{
			if(prime[i]==1)
			{
				if(prime[n-i]==1)
				{
					ans++;
//					cout << "f1:" << i << " f2:" << n-i << " ans:" << ans << endl;
				}
			}
		}
		
		cout << ans << endl;
		
	}
}

Measured memory_bytes: 4940
from fractions import gcd
N = int(input())
A = [int(i) for i in input().split()]
g = A[0]
mini_index_1 = 0
mini_index_2 = 0
glist = [0]
for i in range(N):
    ng = gcd(g, A[i])
    if ng < g:
        mini_index_1 = i
        mini_index_2 = i-1
        g = ng
        glist.append(i)
# print(mini_index_1)

ans = 1
gcddd = 0

for gindex in glist:
    gcddd = 0
    for i in range(N):
        if gindex == i:
            continue
        else:
            if gcddd == 0:
                gcddd = A[i]
            else:
                gcddd = gcd(gcddd, A[i])
    ans = max(ans, gcddd)
print(ans)


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

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

#define FOR(i, n, m) for (ll(i) = (m); (i) < (n); ++(i))
#define REP(i, n) FOR(i, n, 0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll)1e15;

ll K[1005];

int main()
{
    int N, T, A;
    cin >> N >> T >> A;
    int mini = 0;
    A *= 1000;
    REP(i, N)
    {
        ll h;
        cin >> h;
        K[i] = T * 1000 - h * 6;
        if (abs(A - K[i]) < abs(A - K[mini]))
            mini = i;
    }
    cout << mini + 1 << endl;
    return 0;
}

Measured memory_bytes: 256
import bisect,collections,copy,heapq,itertools,math,string
import sys
def S(): return sys.stdin.readline().rstrip()
def M(): return map(int,sys.stdin.readline().rstrip().split())
def I(): return int(sys.stdin.readline().rstrip())
def LI(): return list(map(int,sys.stdin.readline().rstrip().split()))
def LS(): return list(sys.stdin.readline().rstrip().split())
x = I()
if x < 600:
    print('8')
elif x < 800:
    print('7')
elif x < 1000:
    print('6')
elif x < 1200:
    print('5')
elif x < 1400:
    print('4')
elif x < 1600:
    print('3')
elif x < 1800:
    print('2')
else:
    print('1')

Measured memory_bytes: 68224
#include <stdio.h>
#include <string.h>
#define MAX 101
int main(void)
{
	int n, len, len_t, len_h, pt=0, ph=0, i, j;
	char card[3][MAX];
	scanf("%d", &n);
	for(i=0; i<n; i++){
		scanf("%s%s", card[0], card[1]);
		len_t = strlen(card[0]);
		len_h = strlen(card[1]);
		len = (len_t > len_h) ? len_t : len_h;
		
		for(j=0; j<len; j++){
			if(strcmp(card[0], card[1]) == 0){
				pt += 1;
				ph += 1;
				break;
			}else if(card[0][j] > card[1][j]){
				pt += 3;
				break;
			}else if(card[0][j] < card[1][j]){
				ph += 3;
				break;
			}
		}
	}
	printf("%d %d\n", pt, ph);
	return 0;
}

Measured memory_bytes: 612
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using pli = pair<ll, int>;
using pil = pair<int, ll>;
using pdd = pair<double, double>;
using uint = unsigned int;
template <typename T>
using Graph = vector<vector<T>>;
const int MOD = 1e9 + 7;
const ld PI = acosl(-1);

struct UnionFind {
    vector<int> par, rnk, cnt;

    UnionFind(int N) : par(N), rnk(N), cnt(N) {
        for (int i = 0; i < N; ++i)
            par[i] = i, cnt[i] = 1;
    }

    int root(int x) {
        return par[x] == x ? x : par[x] = root(par[x]);
    }

    bool issame(int x, int y) {
        return root(x) == root(y);
    }

    void unite(int x, int y) {
        x = root(x), y = root(y);
        if (x == y)
            return;
        if (rnk[x] < rnk[y])
            swap(x, y);
        if (rnk[x] == rnk[y])
            rnk[x]++;
        cnt[x] += cnt[y];
        par[y] = x;
    }
};

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

    int N;
    cin >> N;
    int agcd = 1;
    multiset<int> st;
    for (int i = 0; i < N; ++i) {
        int A;
        cin >> A;
        st.insert(A);
        if (i > 0)
            agcd = gcd(agcd, A);
        else
            agcd = A;
    }

    if (agcd != 1) {
        cout << "not coprime\n";
        return 0;
    }

    vector<bool> isprime(1000005, true);
    for (int i = 2; i <= 1000000; ++i) {
        if (!isprime[i])
            continue;
        int cnt = 0;
        for (int j = i; j <= 1000000; j += i) {
            cnt += st.count(j);
            if (j == i)
                continue;
            isprime[j] = false;
        }
        if (cnt >= 2) {
            cout << "setwise coprime\n";
            return 0;
        }
    }

    cout << "pairwise coprime\n";

    return 0;
}


Measured memory_bytes: 50656
class BIT:

    def __init__(self, x):
        """
        Args:
            x (list)
        """
        len_array = len(x)
        self.tree = [0] * (len_array + 1)
        
        # update BIT
        for i, _x in enumerate(x, 1):
            while i <= len_array:
                self.tree[i] += _x
                i += i&-i

    def __call__(self, i, j):
        """
        return the sum from i to j including i and j.
        """
        ret = self.cumsum(j) - self.cumsum(i-1)
        return ret

    def cumsum(self, i):
        """
        cumulative sum from 1 to i.
        """
        ret = 0
        while i > 0:
            ret += self.tree[i]
            i -= i&-i
        return ret


def main():
    # count first
    # calc the combinations
    # create three BIT and count the num
    # if S[0] == 'R', S[1] == 'G', then I have to count the number of 'B' in S[3:].
    # O(4000 * 4000 * log4000) = O(10^8). it's gonna be a realistic choice.
    N = int(input())
    S = input()

    BIT_R = [0] * N
    BIT_G = [0] * N
    BIT_B = [0] * N
    for i, s in enumerate(S):
        if s == 'R':
            BIT_R[i] = 1
        elif s == 'G':
            BIT_G[i] = 1
        else:
            BIT_B[i] = 1
    BIT_R = BIT(BIT_R)
    BIT_G = BIT(BIT_G)
    BIT_B = BIT(BIT_B)

    count = 0
    for i in range(N):
        first = S[i]
        for j in range(i+1, N):
            second = S[j]
            if first == second:
                continue
            else:
                exclude_i = 2 * j - i
                if {first, second} == {'R', 'G'}:
                    _count = BIT_B(j+1, N)
                    if (exclude_i < N 
                        and S[exclude_i] == 'B'):
                        _count -= 1
                    
                elif {first, second} == {'R', 'B'}:
                    _count = BIT_G(j+1, N)
                    if (exclude_i < N 
                        and S[exclude_i] == 'G'):
                        _count -= 1

                else:
                    _count = BIT_R(j+1, N)
                    if (exclude_i < N 
                        and S[exclude_i] == 'R'):
                        _count -= 1
                
                count += _count

    print(count)


if __name__=='__main__':
    main()

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

using namespace std;

#ifdef Lin1043
    #define DEBUG(msg, ...) printf("(%s #%d) " msg, __FUNCTION__, __LINE__, __VA_ARGS__)
    #define massert(...) assert(...)
#else
    #define DEBUG(...)
    #define massert(...)
#endif

#define rep(i , l , r) for(int i = (l) , ___ = (r) ; i <= ___ ; ++i )
#define per(i , r , l) for(int i = (r) , ___ = (l) ; i >= ___ ; --i )

struct iopener
{
    iopener()
    {
#ifdef Lin1043
        freopen("./in" , "r" , stdin);
#endif
    }
} iop;

typedef long long LL;

template<typename T>inline bool chkmin(T &x , const T &y) { return x > y ? (x = y , 1) : 0; }
template<typename T>inline bool chkmax(T &x , const T &y) { return x < y ? (x = y , 1) : 0; }

template<typename T>inline T read(T &f)
{
    f = 0; int x = 1 ; char c = getchar();
    while(!isdigit(c)) x = (c == '-' ? -1 : 1) , c = getchar();
    while(isdigit(c)) (f *= 10) += c & 15 , c = getchar();
    return f = x * f;
}

const int N = 2000 + 5;

int n , m , A[N] , mn[N][N];

LL Ans = 1ll << 60;

int main()
{
    read(n) , read(m);
    rep(i , 1 , n) read(A[i]);
    rep(i , 1 , n)
    {
        int x = A[i];
        rep(j , i , n)
            chkmin(x , A[j]) , mn[i][j] = x;
    }
    rep(i , 0 , n - 1)
    {
        LL res = 1ll * i * m;
        rep(j , 1 , n)
        {
            res += j > i ? mn[j - i][j] :
                   min(mn[1][j] , mn[j - i + n][n]);
        }
        chkmin(Ans , res);
    }
    cout << Ans << endl;
    return 0;
}



Measured memory_bytes: 15360
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
#include <utility>
typedef long long ll;
ll MOD = 1e9+7;

using namespace std;
pair<ll,ll> ab[100000];
int main()
{
	int n;
	ll k;
	ll s=0;
	ll ans=0;
	int index=0;
	
	cin>>n>>k;
	for(int i=0;i<n;i++)
		cin>>ab[i].first>>ab[i].second;

	sort(ab,ab+n);

	while(s<k)
	{
		if(index==n)
			break;
		s+=ab[index].second;
		index++;
	}
	index--;
	ans = ab[index].first;
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
import java.util.*
import kotlin.collections.ArrayDeque
import kotlin.collections.HashSet

fun main(args: Array<String>){

    var (N,Q) = readLine()!!.split(" ").map{it.toInt()}
    var ans = LongArray(N){0}
    var checked = BooleanArray(N){false}
    var connectSet = Array(N){HashSet<Int>()}

    for(i in 1 until N){
        var(a,b) = readLine()!!.split(" ").map{it.toInt()}
        connectSet[a-1].add(b-1)
        connectSet[b-1].add(a-1)
    }

    for(i in 0 until Q){
        var (p,x) = readLine()!!.split(" ").map{it.toInt()}
        ans[p-1] = ans[p-1] + x
    }

    var queue: Queue<Int> = LinkedList<Int>()

    queue.add(0)
    checked[0] = true

    while(queue.peek() != null){
        var n = queue.poll()

        connectSet[n].forEach { i ->
            if(!checked[i]){
                ans[i] += ans[n]
                checked[i] = true
                queue.add(i)
            }
        }
    }

    for(i in ans.indices){
        print("${ans[i]} ")
    }



}

Measured memory_bytes: 140160
//https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8 より
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };
    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };
    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };
    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };
    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

//

use std::cmp::*;

fn run() {
    input! {
        n: i64,
        a: i64,
        b: i64,
    }
    let ans = if (b - a) % 2 == 0 {
        (b - a) / 2
    } else {
        let d = (b - a) / 2 + 1;
        min(d + a - 1, d + (n - b))
    };
    println!("{}", ans);
}

fn main() {
    run();
}


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

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int n;
  cin >> n;
  if (n <= 999) {
    cout << "ABC" << endl;
  } else {
    cout << "ABD" << endl;
  }
  return 0;
}


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

using namespace std;

using ll = long long;

const int DAY = 5, TIME = 2, ALL = DAY * TIME;

bool Open(int s, int d, int t) {
    s >>= (1 - t) * DAY;
    return (s >> (DAY - (d + 1))) & 1;
}

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

    int n;
    cin >> n;
    vector<vector<vector<int>>> f(n, vector<vector<int>>(DAY, vector<int>(TIME)));
    vector<vector<int>> p(n, vector<int>(ALL + 1));
    for (int i = 0; i < n; ++i)
        for (int j = 0; j < DAY; ++j)
            cin >> f[i][j][0] >> f[i][j][1];
    for (int i = 0; i < n; ++i)
        for (int j = 0; j <= ALL; ++j)
            cin >> p[i][j];

    int max_p = -1e9;
    vector<int> c(n);
    for (int s = 1; s < (1 << ALL); ++s) {
        fill(c.begin(), c.end(), 0);

        for (int i = 0; i < n; ++i)
            for (int d = 0; d < DAY; ++d)
                for (int t = 0; t < TIME; ++t)
                    if (Open(s, d, t) && f[i][d][t] == 1) ++c[i];

        int sum_p = 0;
        for (int i = 0; i < n; ++i)
            sum_p += p[i][c[i]];

        max_p = max(max_p, sum_p);
    }

    cout << max_p << endl;

    return 0;
}


Measured memory_bytes: 256
import sys
from sys import exit
from math import gcd, factorial, ceil, floor, sqrt
from bisect import bisect_left, bisect_right
from copy import deepcopy
from heapq import heapify, heappop, heappush
from itertools import permutations, combinations, product, accumulate
from collections import defaultdict, deque, Counter
sys.setrecursionlimit(10**7)

ii = lambda: int(input())
mi = lambda: map(int, input().split())
li = lambda: list(map(int, input().split()))

N = ii()
A = li()
mod = 10**9+7

ans = 0
m = list(accumulate(A))
for i, x in enumerate(m[:-1]):
    ans += ((A[i]%mod) * ((m[-1] - m[i])%mod))%mod
    ans %= mod
print(ans)


Measured memory_bytes: 32704
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

//		int a = sc.nextInt();
//		int b = sc.nextInt();
//		int res = 0;
		String s = sc.next();
		String res = "";
		boolean r = false;
		int len = s.length();



		r = isKaibun(s);

		if(r) {
			String tmp = s.substring(0, (len-1)/2 );
//			System.out.println(tmp);
			r = isKaibun(tmp);
		}
//		if(true) {
		if(r) {
			String tmp = s.substring((len+3)/2-1, len );
//			System.out.println(tmp);
			r = isKaibun(tmp);
		}

		//System.out.printf("%d\n", res);
		//System.out.printf("%d", res);
		if(r) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}


	static boolean isKaibun(String s) {
		if(s.length() <= 1) {
			return true;
		}

		if(s.charAt(0) == s.charAt(s.length()-1)) {
			if(s.length() == 2) {
				return true;
			} else {
				String tmp = s.substring(1, s.length()-1);
//				System.out.println(tmp);
				return isKaibun(tmp);
			}
		} else {
			return false;
		}

	}
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<int, lint> pil;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(const T a, const T b){return a>=0 ? a/b : (a+1)/b-1;}
template<class T> T div_ceil(const T a, const T b){return a>=0 ? (a-1)/b+1 : a/b;}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod*mod;
constexpr int MAX = 100010;

int main(){
    int n;
    scanf("%d", &n);
    int w[n];
    rep(i, n) scanf("%d", &w[i]);
    int ans = mod;
    For(i, 1, n){
        int a = 0, b = 0;
        rep(j, i) a += w[j];
        For(j, i, n) b += w[j];
        chmin(ans, max(a, b) - min(a, b));
    }
    printf("%d\n", ans);
}

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


typedef long long int ll;

vector<ll> adj[1000001]; 

ll i,tc;
#define mod 1000000007
#define pb push_back
#define endl cout<<"\n";
#define prt1(a) cout<<a<<" "
#define prt2(a,b) cout<<a<<" "<<b<<" "
#define prt3(a,b,c) cout<<a<<" "<<b<<" "<<c<<" "
#define rep(i,st,end) for( i=st;i<end;i+=2)
#define repv(i,st,end) for( i=st;i>=end;i-=2)
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define TEST cin>>tc;while(tc--)


int main() 
{ 
    ll a,b,c,k;
    cin>>a>>b>>c>>k;
    ll ans = a-(k-(a+b));
    if(k<=a)
        prt1(k);
    else if(k<=a+b)
        prt1(a);
    else
        prt1(ans);

} 



Measured memory_bytes: 27032
import sys
import heapq
import math
import fractions
import bisect
import itertools
from collections import Counter
from collections import deque
from operator import itemgetter
def input(): return sys.stdin.readline().strip()
def mp(): return map(int,input().split())
def lmp(): return list(map(int,input().split()))

n=input()
l=[0]*len(n)
l[0]=int(n[0])
for i in range(1,len(n)):
    l[i]=l[i-1]+int(n[i])
ans=l[-1]
for i in range(len(n)):
    ans=max(ans,l[i]-1+9*(len(n)-1-i))
print(ans)

Measured memory_bytes: 10444
(defun solve (str1 str2)
  (loop for l on (concatenate 'list str1)
        repeat (- (length str1)
                  (length str2)
                  -1)
        minimize (loop for x in l
                       for y across str2
                       count (not (eq x y)))))

(princ (solve (read-line) (read-line)))

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

using ll = long long int;
using P = std::pair<int, int>;

#define rep(i, n) for (int i = 0; i < (n); ++i)
#define rag(con) std::begin(con), std::end(con)

int main()
{
    std::string s;

    std::cin >> s;

    int x = 0;

    for (char ch : s)
    {
        x += atoi(&ch);
    }
    std::cout << ((x % 9 == 0) ? "Yes" : "No") << std::endl;

    return 0;
}

Measured memory_bytes: 3736
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef vector<ll> vl;
typedef pair<ll, ll> PP;
#define rep(i, n) for(ll i = 0; i < ll(n); i++)
#define ITR(x, c) for(__typeof(c.begin()) x = c.begin(); x != c.end(); x++)
#define all(v) v.begin(), v.end()
#define inputv(v, n)                                                           \
    vl v;                                                                      \
    rep(i, n) {                                                                \
        ll x;                                                                  \
        cin >> x;                                                              \
        v.push_back(x);                                                        \
    }
const ll INF = 999999999999999;
const ll MOD = 1000000007;
ll a, b, c, d, e, f, p, t, x, y, z, q, m, n, r, h, k, w, l, ans = 0;
ll mark(ll x,ll y){
    if(x==0)return y;
    if(y==c)return x+c;
    if(x==r)return (c-y)+r+c;
    if(y==0)return (r-x)+c+r+c;
    return -1;
}
int main() {
    cin>>r>>c>>n;
    vector<PP> A;
    rep(i,n){
        cin>>a>>b>>e>>f;
        x=mark(a,b);
        y=mark(e,f);
        if(x>=0&&y>=0){
            A.push_back({x,i});
            A.push_back({y,i});
        }
    }

    sort(all(A));
    vl K(n,0);

    stack<ll> S;
    ITR(x,A){
        a=(*x).second;
        if(K[a]==0){
            S.push(a);
            K[a]=1;
        }
        else{
            if(!S.empty()&&S.top()==a)S.pop();
            else {
                cout<<"NO"<<endl;
                goto finish;
            }
        }
    }
    cout<<"YES"<<endl;
    finish:x=1;
}

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

using namespace std;

long long n, k, ans, grps, last;

int main()
{
    cin>>n>>k;
    if (k==0)
    {
        cout<<n*n;
        return 0;
    }
    for (int i=k+1; i<=n; i++)
    {
        ans += i-k;
        grps = (n-i+1)/i; // grupuri de 0->(i-1)
        ans += grps * (i-k);
        last = (n-i+1)%i;
        if (last-1 >=k)
            ans+=last-k;
    }
    cout<<ans;
    return 0;
}


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

long long A, B, C, D, E, F; bool a1[3009], a2[3009];

int main() {
	cin >> A >> B >> C >> D >> E >> F;
	for (int i = 0; i <= 3000; i++) {
		for (int j = 0; j <= 3000; j++) {
			int G = A*i + B*j; G *= 100;
			if (G > 3000) continue;
			a1[G] = true;
		}
	}
	for (int i = 0; i <= 3000; i++) {
		for (int j = 0; j <= 3000; j++) {
			int G = C*i + D*j;
			if (G > 3000) continue;
			a2[G] = true;
		}
	}
	pair<int, int>maxid = make_pair(0, 0); long double maxn = -1;
	for (int i = 1; i <= 3000; i++) {
		for (int j = 0; j <= 3000; j++) {
			if (a1[i] == false || a2[j] == false) continue;
			if (i + j > F)continue;
			long double T1 = 1.0L*E / 100;
			long double T2 = 1.0L*j / i;
			if (T2 - T1 > 1e-9) continue;
			if (T2 > maxn) {
				maxn = T2;
				maxid = make_pair(i, j);
			}
		}
	}
	cout << maxid.first + maxid.second << " " << maxid.second << endl;
	return 0;
}

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

#define debug(x) cerr<<#x<<"="<<x<<endl;
#define m(a,b) memset(a,b,sizeof(a))
typedef long long ll;
const int MAXN=1e5+10;

int main(){
	int a,b,c,x;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	int 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++;
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include<cstdio>
using namespace std;
int main(void){
   long long n,max,min,sum,k;
   
       cin>>n;
       cin>>max;
       min=max;
       sum=max;
   for(int i=2;i<=n;i++){
      cin>>k;
      sum+=k;
      if(max<k)max=k;
      if(min>k)min=k;
       
   }
   cout<<min<<" "<<max<<" "<<sum<<"\n";
 
   }
   



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

int main() {
	int h, w, a, b;
	cin >> h >> w >> a >> b;
	for (int i = 0; i < h; i++) {
		for (int j = 0; j < w; j++) {
			if ((i < b) ^ (j < a))
				cout << 1;
			else
				cout << 0;
		}
		cout << "\n";
	}

	return 0;
}

Measured memory_bytes: 1280
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, M): (usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let A: Vec<i64> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.split_whitespace()
            .map(|x| x.parse().unwrap())
            .collect()
    };

    let mut q = std::collections::BinaryHeap::new();
    for &a in &A { q.push(a); }
    for _ in 0..M {
        let x = q.pop().unwrap();
        q.push(x / 2);
    }
    let ans = {
        let mut s = 0;
        while !q.is_empty() {
            s += q.pop().unwrap();
        }
        s
    };

    println!("{}", ans);
}


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

typedef long long ll;
using namespace std;

#define _overload(_1, _2, _3, name, ...) name
#define _rep(i, n) for(ll i = 0; i < (ll)n; i++)
#define _repi(i, s, n) for(ll i = (ll)(s); i < (ll)n; i++)
#define REP(...) _overload(__VA_ARGS__, _repi, _rep,)(__VA_ARGS__)
#define all(v) (v).begin(),(v).end()
#define UNIQUE(v) (v).erase( unique( all(v) ), (v).end() );
#define MOD 1000000007

int main(){
	string s, t;	cin >> s >> t;
	ll ans = 1001;

	REP(i, s.length() - t.length() + 1){
		ll tmp = 0;
		REP(j, t.length()){
			if( s[i+j] != t[j] ){
				tmp++;
			}
		}
		ans = min(ans, tmp);
	}

	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 3628
#coding:utf-8

n = int(input())
a = list(map(int,input().split()))

while len(a)>1:
  for i in range(1,len(a)):
    a[i] %= a[0]
  a.sort()
  while True:
    if a[0] == 0:
      a.remove(0)
    else:
      break;

print(a[0])

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
long long intceil(long long a, long long b) {
    if (a % b == 0) return a / b;
    else return a / b + 1;
}
int main() {
    long long n;
    cin >> n;
    long long a[n], t[n], k, p = 1, q = 1;
    for (long long i = 0; i < n; i++) cin >> t[i] >> a[i];
    for (long long i = 0; i < n; i++)
    {
        k = max(intceil(p, t[i]), intceil(q, a[i]));
        p = k * t[i];
        q = k * a[i];
    }
    cout << p + q;
}

Measured memory_bytes: 3612
n, x = map(int, input().split())
a = list(map(int, input().split()))
ans = 0
ans += max(0, a[0] - x)
a[0] = min(x, a[0])
for i in range(1, n):
    tmp = a[i]
    a[i] = min(x - a[i - 1], a[i])
    ans += tmp - a[i]
print(ans)

Measured memory_bytes: 15888
#include <algorithm>
#include <iostream>
#include <vector>

using namespace std;

int main()
{
  int N;
  cin >> N;

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

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

  int b = B[ N / 2 ];

  auto abs = []( int a )
  {
    return ( a >= 0 ) ? a : - a;
  };

  long sadness = 0;
  for( int i = 0; i < N; ++i )
  {
    sadness += abs( A[ i ] - ( b + ( i + 1 ) ) );
  }

  cout << sadness << endl;

  return 0;
}


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

int main(void) {
	int N;
	cin >> N;
	string str;
	cin >> str;
	int flag;
	if (N % 2 == 1) { flag = 0; }
	else if (str.substr(0, N / 2) == str.substr(N / 2, N / 2)) { flag = 1; }
	else { flag = 0; }

	switch (flag) {
	case 0:
		cout << "No" << endl;
		break;
	case 1:
		cout << "Yes" << endl;
		break;
	}

	return 0;
}

Measured memory_bytes: 256
S=input()
T=input()
SS,TT,possible=len(S),len(T),[]

for i in range(SS-TT+1):
    key,memo=S,0
    for j in range(TT):
        if key[i+j]==T[j]:pass
        elif key[i+j]=="?":key=key[:i+j]+T[j]+key[i+j+1:]
        else:
            memo=1
            break
    if memo==0:
        key=key.replace("?","a")
        possible.append(key)

possible.sort()
possible=possible+["UNRESTORABLE"]
print(possible[0])

Measured memory_bytes: 3064
#!/usr/bin/env python3
import numpy as np

w = input()
alpha = np.full(26,0)

for i in range(len(w)):
    alpha[ord(w[i])-ord('a')] += 1

flg = True
for i in range(26):
    if alpha[i]%2 != 0:
        flg = False

if flg:
    print('Yes')
else:
    print('No')


Measured memory_bytes: 20500
#include <bits/stdc++.h>
using namespace std;
#define _GLIBCXX_DEBUG //これつけるとA[N]でもいいらしい
//for文のマクロ
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define big 1000000007
#define all(a) sort((a).begin(),(a).end()) //ソートのマクロ
#define Re(a) reverse((a).begin(),(a).end())
#define YN(a) if(a){cout<<"Yes"<<endl;}else cout<<"No"<<endl;//条件によってYes、Noを出力する
const int MOD=1000000007;
const double pi = 3.141592653589793;
int main(){
    int h1,m1,h2,m2,k;
    cin>>h1>>m1>>h2>>m2>>k;
    if(m1<=m2){
        cout<<max(0,60*(h2-h1)+(m2-m1)-k)<<endl;
    }
    else{
        cout<<max(0,60*(h2-1-h1)+(m2+60-m1)-k)<<endl;
    }
}

Measured memory_bytes: 3636
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;

class Team {
public:
	int id;
	int correct;
	int wrong[10];
	int penalty;

	Team()
	{
		id = 0;
		correct = 0;
		penalty = 0;
		for (int i = 0; i < 10; i++) {
			wrong[i] = 0;
		}
	}

	bool operator < (const Team obj) const
	{
		if (correct != obj.correct) {
			return correct > obj.correct;
		}
		if (penalty != obj.penalty) {
			return penalty < obj.penalty;
		}
		return id < obj.id;
	}
};

int main()
{
	while (true) {
		int T, P, R;
		cin >> T >> P >> R;

		if (T == 0 && P == 0 && R == 0) {
			break;
		}

		vector<Team> team(T);

		for (int i = 0; i < T; i++) {
			team[i].id = i + 1;
		}

		for (int i = 0; i < R; i++) {
			int tID, pID, time;
			string message;

			cin >> tID >> pID >> time >> message;

			if (message == "CORRECT") {
				team[tID - 1].correct++;
				team[tID - 1].penalty += 1200 * team[tID - 1].wrong[pID - 1] + time;
				team[tID - 1].wrong[pID - 1] = 0;
			}
			else {
				team[tID - 1].wrong[pID - 1]++;
			}
		}

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

		for (int i = 0; i < T; i++) {
			cout << team[i].id << " " << team[i].correct << " " << team[i].penalty << endl;
		}
	}

	return 0;
}

Measured memory_bytes: 3204
def solve():
    Height = 10**9
    for i in range(0,N-K+1):
        hmax = h[i+K-1]
        hmin = h[i]
        Height = min(Height, hmax-hmin)
#        print(h[i:i+K])
#        print(Height)

    print(Height)

if __name__=="__main__":
    N,K = list(map(int, input().split()))
    h = [int(input()) for _ in range(N)]
    h.sort()
    solve()


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

const int mod = 1000000007;
struct mint {
    ll x;  // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

struct combination {
    vector<mint> fact, ifact;
    // init struct with "n" of "nCk" (maximum number in other words)
    combination(int n) : fact(n + 1), ifact(n + 1) {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i) fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i) ifact[i - 1] = ifact[i] * i;
    }
    // c(n,k) returns mint that contains nCk (mod p (= 1e9+7)) in x
    // i.e.) mint num = c(n,k), then num.x == nCk (mod p (= 1e9+7))
    mint operator()(int n, int k) {
        if (k < 0 || k > n) return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
};

int main() {
    int n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    sort(a.begin(), a.end());

    mint ans(0);
    combination choose(n - 1);
    for (int i = k - 1; i < n; i++) {
        mint maxi(a[i]);
        maxi *= choose(i, k - 1);
        ans += maxi;
    }
    for (int i = 0; i <= n - k; i++) {
        mint mini(a[i]);
        mini *= choose(n - i - 1, k - 1);
        ans -= mini;
        if (ans.x < 0) ans += mod;
    }
    cout << ans.x << endl;
}


Measured memory_bytes: 2560
#include <cstdio>
#include <cstdlib>

int *pre;
int *in;
int *post;

int postorder(int prel, int inl,int n, int p){
    if(n==0)return p;
    p--;
    int i;
    int value = pre[prel];
    post[p]=value;
    for(i=0;i<n;i++)if(in[inl + i]==value)break;
    if(i==n){perror("tree error\n");return -1;}
    p = postorder(prel+1+i,inl+1+i,n-1-i,p);
    p = postorder(prel+1,inl,i,p);
    return p;
}

int main(){
    int i, n;
    scanf("%d",&n);
    pre = (int*)malloc(sizeof(int)*n);
    in = (int*)malloc(sizeof(int)*n);
    post = (int*)malloc(sizeof(int)*n);
    for(i=0;i<n;i++)scanf("%d",pre+i);
    for(i=0;i<n;i++)scanf("%d",in+i);
    if(postorder(0,0,n,n)!=0){perror("error\n");return -1;}
    for(i=0;i<n;i++){
        printf("%d",post[i]);
        if(i<n-1)printf(" ");
        else printf("\n");
    }
    return 0;
}



Measured memory_bytes: 2768
import java.util.Scanner;
public class Main{
 public static void main(String[] args){
  Scanner sc = new Scanner(System.in);
  String data = sc.nextLine();
  int distance = 'A' - 'a';
  for(int i = 0 ; i < data.length() ; i++)
  {
   char c = data.charAt(i);
   if(c >= 'a' && c <= 'z'){
    c += distance;
    System.out.print(c);
   }
   else if(c >= 'A' && c <= 'Z'){
    c -= distance;
    System.out.print(c);
   }
   else
    System.out.print(c);
  }
  System.out.println();
 }
}


Measured memory_bytes: 26792
#include <iostream>
#include <complex>
#include <vector>
#include <string>
#include <algorithm>
#include <cstdio>
#include <numeric>
#include <cstring>
#include <ctime>
#include <cstdlib>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <list>
#include <cmath>
#include <bitset>
#include <cassert>
#include <queue>
#include <stack>
#include <deque>
#include <random>
#include <iomanip>
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long int ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<P,P> PP;
const ll MOD=998244353;
const ll MAX_N=500010;
const ll INF=100100100100100;
ll dp1[110][5];
ll dp2[110][5];

int main(){
    string s;
    cin>>s;
    int k;
    cin>>k;
    dp1[0][0]=1;   
    int n=s.length();
    for(int i=0;i<n;i++){
        int now=s[i]-'0';
        //cout<<now<<endl;
        if(now==0){
            for(int j=0;j<=3;j++){
                dp1[i+1][j]+=dp1[i][j];
                dp2[i+1][j]+=dp2[i][j];
                dp2[i+1][j+1]+=dp2[i][j]*9;
            }
        }else{
            for(int j=0;j<=3;j++){
                dp1[i+1][j+1]+=dp1[i][j];
                dp2[i+1][j]+=dp1[i][j];
                dp2[i+1][j+1]+=dp1[i][j]*(now-1);
                dp2[i+1][j]+=dp2[i][j];
                dp2[i+1][j+1]+=dp2[i][j]*9;
            }
        }
    }
    cout<<dp1[n][k]+dp2[n][k]<<endl;
}

Measured memory_bytes: 3176
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <map>
#include <numeric>
#include <string>
#include <cmath>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
#include <stack>
#include <cctype>
#include <cmath>
#include <bitset>

using namespace std;

/* typedef */
typedef long long ll;

/* constant */
const int INF = 1 << 30;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;

/* struct for mod Calculation*/
struct mint {
    ll x;
    mint(ll x = 0):x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint& operator+=(const mint a) {
        if ((x += a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += mod - a.x) >= mod) x -= mod;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res += a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res -= a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res *= a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1) a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const {
        return pow(mod - 2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res /= a;
    }
};

/* global variables */

/* function */
mint choose(int n, int k) {
    mint x = 1, y = 1;
    for (int i = 0; i < k; i++) {
        x *= n - i;
        y *= i + 1;
    }
    return x / y;
}

/* main */
int main(){
    ll n, a, b;
    cin >> n >> a >> b;
    mint two = 2;
    mint ans = two.pow(n);
    ans -= 1;
    ans -= choose(n, a);
    ans -= choose(n, b);
    cout << ans.x << '\n';

}


Measured memory_bytes: 256
import sys
int1 = lambda x: int(x) - 1
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
sys.setrecursionlimit(500000)

A, B, C, K = map(int, read().split())

ans = 0
a = min(A, K)
K -= a
b = min(B, K)
K -= b
c = K

print(a - c)


Measured memory_bytes: 9148
#include <climits>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <queue>
#include <string>
#include <vector>

using namespace std;

using ll = long long;

int main()
{
    int k, x;
    cin >> k >> x;
    if (k* 500 >= x) {
        cout << "Yes";
    } else {
        cout << "No";
    }
    cout << endl;
    return 0;
}


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

using namespace std;

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

#define FOR(i, n, m) for(ll (i)=(m);(i)<(n);++(i))
#define REP(i, n) FOR(i,n,0)
#define OF64 std::setprecision(10)

const ll MOD = 1000000007;
const ll INF = (ll) 1e15;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N, M;
    cin >> N >> M;
    if (N % 2 == 1) {
        REP(i, M) {
            cout << i + 1 << " " << N - 1 - i << endl;
        }
        return 0;
    }

    vector<pll> v;
    ll ev = (M / 2) * 2;
    ll od = ((M - 1) / 2) * 2 + 1;
    REP(i, N) {
        if (od <= 0)
            break;
        v.push_back(pll(i + 1, i + 1 + od));
        od -= 2;
    }
    for (ll i = N; i >= 0; --i) {
        if (ev <= 0)
            break;
        v.push_back(pll(i, i - ev));
        ev -= 2;
    }

    REP(i, v.size()) {
        cout << v[i].first << " " << v[i].second << endl;
    }
    return 0;
}

Measured memory_bytes: 5216
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline
N = int(input())
A = list(map(int,input().split()))
A.sort()
M = 10**6+1
is_prime = [True] * (M)
is_prime[0] = False

freq = dict()
for a in A:
    if a not in freq:
        freq[a] = 1
    else:
        freq[a] += 1
if 1 in freq and freq[1]>1:
    print(0)
    exit()
for i in A:
    if not is_prime[i]:
        continue
    for cur in range(i*2, M, i):
        is_prime[cur] = False
ans = 0
for a in A:
    if is_prime[a] and freq[a]==1:
        ans += 1
print(ans)

Measured memory_bytes: 121784
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
using ll = long long;
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;

const ll INF = ll(1e18)+1;

int main(){
  int n; ll k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) cin >> a[i];
  sort(a.begin(), a.end());
  ll l = -INF, r = INF;
  while(l+1 < r){
    ll x = (l+r)/2;
    bool ok = [&]{
      ll tot = 0;
      rep(i, n){
        if (a[i] < 0){
          int l = -1, r = n;
          while(l+1<r){
            int c = (l+r)/2;
            if (a[c]*a[i] < x) r = c;
            else l = c;
          }
          tot += n-r;
        }
        else{
          int l = -1, r = n;
          while(l+1<r){
            int c = (l+r)/2;
            if (a[c]*a[i] < x) l = c;
            else r = c;
          }
          tot += r;
        }
        if (a[i] * a[i] < x) tot--;
      }
      tot /= 2;
      return tot < k;
    }();
    if (ok) l = x;
    else r = x;
  }
  cout << l << endl;
  
  return 0;
}

Measured memory_bytes: 1920
#include <iostream>
#include <fstream>
#include <sstream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <bitset>
#include <limits>
#include <random>
#include <complex>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <string.h>
#include <iomanip>
using namespace std;
 
#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define RREP(i,n) for(int (i)=(int)(n)-1;i>=0;i--)
#define REMOVE(Itr,n) (Itr).erase(remove((Itr).begin(),(Itr).end(),n),(Itr).end())
typedef long long ll;
 
int main() {
 
    int N; cin >> N;
    vector < int > t(N), v(N);
    REP(i,N) cin >> t[i];
    REP(i,N) cin >> v[i];
 
    REP(i,N) t[i] *= 2;
    REP(i,N) v[i] *= 2;

    int vel[41000] = {};
    int limit[41000] = {};
    int cnt = 1;
    REP(i,N) REP(j,t[i]) {
        limit[cnt] = v[i];
        cnt++;
    }
 
    cnt = 0;
    REP(i,N - 1) {
        cnt += t[i];
        limit[cnt] = min(v[i], v[i + 1]);
    }
 
    int sum = 0;
    REP(i,N) sum += t[i];
 
    limit[sum] = 0;
 
    REP(kai,400) for (int i = 1; i <= sum; i++) {
        int val = vel[i];
        val++;
        if (abs(val - vel[i - 1]) <= 1 && abs(val - vel[i + 1]) <= 1 && val <= limit[i]) {
            vel[i] = val;
        }
    }
 
    double ans_vel[41000];
    REP(i,41000) ans_vel[i] = (double) vel[i];
 
    double ans = 0.0;
    REP(i,sum) {
        double area = (ans_vel[i] + ans_vel[i + 1]);
        ans += area / 2.0;
    }

    ans /= 4.0;
 
    //REP(i,sum + 1) cout << i << " " << vel[i] << " " << limit[i] << endl;
 
    cout << fixed << setprecision(10) << ans << endl;
 
    return 0;
}

Measured memory_bytes: 1024
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
  let mut s = String::new();
  std::io::stdin().read_line(&mut s).ok();
  s.trim().split_whitespace()
    .map(|e| e.parse().ok().unwrap()).collect()
}
 
fn main() {
  let abc: Vec<String> = read_vec();
  let ans = if abc[0].chars().last().unwrap() == abc[1].chars().next().unwrap()
    && abc[1].chars().last().unwrap() == abc[2].chars().next().unwrap() {
      "YES"
    } else {
      "NO"
    };

  println!("{}", ans);
}


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

#define FOR(i,a,b) for (int i = (a); i < (b); ++i)
#define F0R(i,a) FOR(i,0,a)
#define ROF(i,a,b) for (int i = (b)-1; i >= (a); --i)
#define R0F(i,a) ROF(i,0,a)

using ll = long long;
using ld = long double;
ll INF = LLONG_MAX;

using vi = vector<int>;
using vll = vector<ll>;
using pii = pair<int, int>;

namespace output {
	void pr(int x) { cout << x; }
	void pr(long x) { cout << x; }
	void pr(ll x) { cout << x; }
	void pr(unsigned x) { cout << x; }
	void pr(unsigned long x) { cout << x; }
	void pr(unsigned long long x) { cout << x; }
	void pr(float x) { cout << x; }
	void pr(double x) { cout << x; }
	void pr(ld x) { cout << x; }
	void pr(char x) { cout << x; }
	void pr(const char* x) { cout << x; }
	void pr(const string& x) { cout << x; }
	void pr(bool x) { pr(x ? "true" : "false"); }
	template<class T> void pr(const complex<T>& x) { cout << x; }
	
	template<class T1, class T2> void pr(const pair<T1,T2>& x);
	template<class T> void pr(const T& x);
	
	template<class T, class... Ts> void pr(const T& t, const Ts&... ts) { 
		pr(t); pr(ts...); 
	}
	template<class T1, class T2> void pr(const pair<T1,T2>& x) { 
		pr("{",x.f,", ",x.s,"}"); 
	}
	template<class T> void pr(const T& x) { 
		pr("{"); // const iterator needed for vector<bool>
		bool fst = 1; for (const auto& a: x) pr(!fst?", ":"",a), fst = 0; 
		pr("}");
	}
	
	void print() { pr("\n"); } // print w/ spaces
	template<class T, class... Ts> void print(const T& t, const Ts&... ts) { 
		pr(t); if (sizeof...(ts)) pr(" "); print(ts...); 
	}
}

using namespace output;

int main() {
    ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
	int N, A, B, C, D; cin >> N >> A >> B >> C >> D;
	string S; cin >> S;
	
	--A; --B; --C; --D;

	vector<bool> AR (N);
	vector<bool> BR (N);
	
	int c;
	c = A;
	AR[c] = true;
	while (true) {
		if (c + 1 < N && S[c+1] == '.') c += 1;
		else if (c + 2 < N && S[c+2] == '.') c += 2;
		else break;
		AR[c] = true;
	}

	c = B;
	BR[c] = true;
	while (true) {
		if (c + 1 < N && S[c+1] == '.') c += 1;
		else if (c + 2 < N && S[c+2] == '.') c += 2;
		else break;
		BR[c] = true;
	}

	
	if (!AR[C] || !BR[D]) {
		print("No");
		return 0;
	}

	if ((A < B) != (C < D)) {
		bool canDo = false;
		FOR(i, max(A, B) - 1, min(C, D)) {
			if (S[i] == '.' && S[i+1] == '.' && S[i+2] == '.') canDo = true;
		}
		print(canDo ? "Yes" : "No");
	} else {	
		print("Yes");
	}
}

Measured memory_bytes: 592