akhauriyash/Code-Regression huggingface dataset:
n=int(input())
d=list()
for i in range(n):
    d.append(list(map(int,input().split())))

an=1
for i in range(n):
    if n > i+2:
        if d[i][0]==d[i][1] and d[i+1][0]==d[i+1][1] and d[i+2][0]==d[i+2][1]:
            an=0
            break
    else:
        an=1
if an==0:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 9152
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <queue>
#include <map>
#include <unordered_map>
#include <set>
#include <functional>
#include <bitset>
#include <numeric>
#include <complex>
#include <iomanip>
#include <cassert>
#include <random>


int main() {
    int n, m, x; std::cin >> n >> m >> x;
    std::vector<int> c(n);
    std::vector<std::vector<int>> a(n, std::vector<int>(m));
    for (int i = 0; i < n; i++) {
        std::cin >> c[i];
        for (int j = 0; j < m; j++) {
            std::cin >> a[i][j];
        }
    }
    int ans = 1e9;
    std::vector<int> s(m);
    for (int i = 0; i < (1 << n); i++) {
        int cost = 0;
        std::fill(s.begin(), s.end(), 0);
        for (int j = 0; j < n; j++) {
            if ((i >> j) & 1) {
                cost += c[j];
                for (int k = 0; k < m; k++) s[k] += a[j][k];
            }
        }
        bool ok = true;
        for (int j = 0; j < m; j++) ok &= s[j] >= x;
        if (ok) ans = std::min(ans, cost);
    }
    std::cout << (ans != 1e9 ? ans : -1) << std::endl;
    return 0;
}


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

int main() {
    string S;
    int count=0;
    cin >>S;
    for(int i=0;i<S.size();i++){
        if(S.at(i)=='+')count++;
        else count--;
    }
    cout << count <<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
#define dame { puts("-1"); return 0;}
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
const ll MOD = 1000000007;
ll table[401][401];
ll sum[401][401];

void init(){
    srep(i,1,401){
        ll tmp = 1;
        rep(j,401){
            table[i][j] = tmp;
            tmp *= i;
            tmp %= MOD;
            sum[i][j] = sum[i-1][j] + table[i][j];
            sum[i][j] %= MOD;
        }
    }
}

int main() {
    ll n, c;
    cin >> n >> c;
    ll a[n];
    rep(i,n)cin >> a[i];
    ll b[n];
    rep(i,n)cin >> b[i];

    init();

    ll dp[400][401];
    rep(i,n){
        rep(j,c+1){
            if(i == 0){
                dp[i][j] = sum[b[i]][j] - sum[a[i]-1][j] + MOD;
                dp[i][j] %= MOD;
            }else{
                dp[i][j] = 0;
                rep(k,j+1){
                    dp[i][j] += dp[i-1][k] * (sum[b[i]][j - k] - sum[a[i]-1][j - k] + MOD);
                    dp[i][j] %= MOD;
                }
            }
        }
    }
    cout << dp[n-1][c] << endl;
    return 0;
}
 
 


Measured memory_bytes: 3968
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
using namespace std;

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

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

// Self settings
// clang-format off
#define MAX_N 100000
#define REP(i, N) for (int i = 0; i < (int)(N); ++i)
#define SLN(i,N) (i == N-1 ? "\n" : " ")
ll fact(ll n) { ll res = 1; for(ll i=2;i<=n;++i) res = res * i; return res;}
ll nCr(ll n, ll r) {return (fact(n)/fact(n-r)*fact(r)) ;}
ll gcd(ll a,ll b){if(b==0)return a;return gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
const ll MOD = 1e9+7;
const ll INF = 1LL << 60;
const int inf = 1 << 31;
// clang-format on

int N;
char s[MAX_N];

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

  cin >> N;
  REP(i, N) { cin >> s[i]; }

  map<char, int> mp;
  REP(i, N) mp[s[i]]++;

  if (mp.size() == 3) {
    cout << "Three" << endl;
  }
  else {
    cout << "Four" << endl;
  }

  return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define endl "\n"
#define se second
#define ls( s) (s&(-s))
#define ll long long
const int N = 100030;
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))
const int mod =    1e9+7;

int main()
{ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
int n;
cin>>n;
int x=n/2;
int y=n/2;

if(n%2)
y++;
cout<<fixed<<setprecision(10)<<1.0*y/(x+y);
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define int long long
using namespace std;
typedef vector<int>   vint;
typedef pair<int,int> pint;

signed main()
{
    int N; cin>>N;
    vint a(N);
    REP(i,N) cin>>a[i];

    int sum=0;
    int ans1=0;
    REP(i,N){
        sum+=a[i];
        if(i%2==0 and sum<=0){
            ans1+=1-sum;
            sum=1;
        }
        if(i%2==1 and sum>=0){
            ans1+=sum+1;
            sum=-1;
        }
    }
    
    sum=0;
    int ans2=0;
    REP(i,N){
        sum+=a[i];
        if(i%2==0 and sum>=0){
            ans2+=sum+1;
            sum=-1;
        }
        if(i%2==1 and sum<=0){
            ans2+=1-sum;
            sum=1;
        }
    }
    cout<<min(ans1,ans2)<<endl;
 
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define int long long
using namespace std;

int32_t main() {
	int n;
	cin>>n;
	int a[n][3];
	for(int i=0;i<n;i++){
	    for(int j=0;j<3;j++){
	        cin>>a[i][j];
	    }
	}
	int dp[n][3];
	dp[0][0]=a[0][0];
	dp[0][1]=a[0][1];
	dp[0][2]=a[0][2];
	for(int i=1;i<n;i++){
	    dp[i][0]=a[i][0]+max(dp[i-1][1],dp[i-1][2]);
	    dp[i][1]=a[i][1]+max(dp[i-1][0],dp[i-1][2]);
	    dp[i][2]=a[i][2]+max(dp[i-1][0],dp[i-1][1]);
	}
	cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<endl;
}


Measured memory_bytes: 8208
#![allow(unused_imports)]
#![allow(non_snake_case)]
use std::cmp::*;
use std::collections::*;
use std::io::Write;

#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), std::io::stderr());
            writeln!(err, "{} = {:?}", e, $e).unwrap()
        })*
    };
}

fn main() {
    let v = read_vec::<usize>();
    let (a, b, q) = (v[0], v[1], v[2]);
    let mut s = vec![];
    for _ in 0..a {
        s.push(read::<i64>());
    }
    let mut t = vec![];
    for _ in 0..b {
        t.push(read::<i64>());
    }

    for i in 0..q {
        let x = read::<i64>();
        let s_lower = s.lower_bound(&x);
        let t_lower = t.lower_bound(&x);
        let mut ans = std::i64::MAX;
        if s_lower < s.len() && t_lower < t.len() {
            let temp = max(s[s_lower] - x, t[t_lower] - x);
            ans = min(ans, temp);
        }
        if s_lower > 0 && t_lower > 0 {
            let temp = max(x - s[s_lower - 1], x - t[t_lower - 1]);
            ans = min(ans, temp);
        }
        if s_lower < s.len() && t_lower > 0 {
            let temp1 = (s[s_lower] - x) * 2 + x - t[t_lower - 1];
            let temp2 = (s[s_lower] - x) + (x - t[t_lower - 1]) * 2;
            ans = min(ans, temp1);
            ans = min(ans, temp2);
        }
        if s_lower > 0 && t_lower < t.len() {
            let temp1 = (t[t_lower] - x) * 2 + x - s[s_lower - 1];
            let temp2 = (t[t_lower] - x) + (x - s[s_lower - 1]) * 2;
            ans = min(ans, temp1);
            ans = min(ans, temp2);
        }

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

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()
}

pub trait BinarySearch<T> {
    fn lower_bound(&self, &T) -> usize;
    fn upper_bound(&self, &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
    }
}


Measured memory_bytes: 7420
#include <stdio.h>
#include <vector>
#include <algorithm>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)

int n, x[5000], y[5000], m;
vector<int> xs, ys;
int sum[5010][5010];

int of(const vector<int>& xs, int x) {
    return lower_bound(xs.begin(), xs.end(), x) - xs.begin();
}

int solve(int x1, int y1, int x2, int y2) {
    if (x1 > xs.back() || x2 < xs[0]) return 0;
    if (y1 > ys.back() || y2 < ys[0]) return 0;
    const int ix1 = of(xs, x1), ix2 = of(xs, x2+1);
    const int iy1 = of(ys, y1), iy2 = of(ys, y2+1);
    return sum[ix2][iy2] - sum[ix2][iy1] - sum[ix1][iy2] + sum[ix1][iy1];
}

int main() {
    scanf("%d%d", &n, &m);
    rep (i, n) scanf("%d%d", x+i, y+i);
    rep (i, n) xs.push_back(x[i]), ys.push_back(y[i]);
    sort(xs.begin(), xs.end());
    xs.erase(unique(xs.begin(), xs.end()), xs.end());
    sort(ys.begin(), ys.end());
    ys.erase(unique(ys.begin(), ys.end()), ys.end());
    rep (i, n) sum[of(xs, x[i])+1][of(ys, y[i])+1]++;
    rep (i, xs.size()+1) rep (j, ys.size()+1) {
        if (i) sum[i][j] += sum[i-1][j];
        if (j) sum[i][j] += sum[i][j-1];
        if (i && j) sum[i][j] -= sum[i-1][j-1];
    }
    rep (_, m) {
        int x1, y1, x2, y2;
        scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
        printf("%d\n", solve(x1, y1, x2, y2));
    }
    return 0;
}

Measured memory_bytes: 99048
package main

import "fmt"

func main() {
	var k int
	fmt.Scanf("%d", &k)
	gu := k / 2
	ki := 0
	if k%2 == 0 {
		ki = gu
	} else {
		ki = gu + 1
	}
	fmt.Println(ki * gu)

}


Measured memory_bytes: 1832
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines
 
def main():
    N = int(readline())
    chars = readline().decode()

    cntW = [0]
    cntR = [0] 
    for i in range(N):
        cntW.append(cntW[i] + (1 if chars[i] == 'W' else 0))
        cntR.append(cntR[i] + (1 if chars[i] == 'R' else 0))

    ans = int(1e9)
    for i in range(N+1):
        leftW = cntW[i]
        rightR = cntR[N]-cntR[i] 

        if leftW <= rightR:
            tmp = leftW + (rightR - leftW)
        else:
            tmp = rightR + (leftW - rightR)
        ans = min(tmp, ans)
    print(ans)
if __name__ == '__main__':
    main()


Measured memory_bytes: 25080
using System;
class main{
    static void Main(string[] args){
        for (int i = 0; i < 200;i++ ){
            string input = Console.ReadLine();
            if(!String.IsNullOrEmpty(input)){
                string[] data = input.Split(' ');
                Console.WriteLine((int.Parse(data[0] )+ int.Parse(data[1])).ToString().Length);
            }else{
                break;
            }
        }
    }
}

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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

template<class t, class u> void chmax(t&a,u b){if(a<b)a=b;};
template<class t, class u> void chmin(t&a,u b){if(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vll h(N);
  REP(i,N) IN(h[i]);
  vll dp(N, INFLL);
  dp[0] = 0;
  REP(i,N-2){
    chmin(dp[i+1], dp[i]+abs(h[i]-h[i+1]));
    chmin(dp[i+2], dp[i]+abs(h[i]-h[i+2]));
  }
  chmin(dp[N-1], dp[N-2]+abs(h[N-2]-h[N-1]));

  OUT(dp[N-1]);

  return 0;
}

Measured memory_bytes: 1792
#include <cstdio>
#include <iostream>
#include <vector>
#include <set>
#include <cstring>
#include <string>
#include <map>
#include <cmath>
#include <ctime>
#include <algorithm>
#include <bitset>
#include <queue>
#include <sstream>
using namespace std;
#define mp make_pair
#define pb push_back
#define re return
#define fi first
#define se second
typedef vector<int> vi;
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<pii> vpii;
typedef vector<string> vs;
typedef vector<vi> vvi;
int f[5];
int a,b;
int main() {
    //freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	for(int i=0;i<3;i++){
		cin>>a>>b;
		f[a]++;
		f[b]++;
	}
	int co=0;
	for(int i=0;i<=4;i++)if(f[i]==2)co++;
	if(co==2)cout<<"YES"<<endl;
	else cout<<"NO"<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ll long long int
#define ull unsigned long long int
#define ld long double
#define pb push_back
#define pf pop_front
#define mp make_pair
#define mod 1000000007
#define fio ios_base::sync_with_stdio(false);cin.tie(NULL);
#define mat vector<vector<int>>
#define all(x) x.begin(),x.end()
#define F first
#define S second
#define fo(i,n) for(int i=0;i<n;i++)
#define inp(a) int a;cin>>a;
#define inpa(a,n)vector<int> a(n);fo(i,n)cin>>a[i];
#define printclock cerr<<"Time : "<<1000*(ld)clock()/(ld)CLOCKS_PER_SEC<<"ms\n";
using namespace std;
#define int ll


auto max(auto a){auto ans=a[0];for(auto i:a)if(i>ans)ans=i;return ans;}
auto min(auto a){auto ans=a[0];for(auto i:a)if(i<ans)ans=i;return ans;}
void print(auto a){for(auto i:a)cerr<<i<<' ';cerr<<'\n';}



signed main()
{
	fio
	inp(n)
	string s;
	cin>>s;
	vector<int> curr={1};
	for(int i=1;i<n;i++)
	{
		vector<int> pre(i+1);
		vector<int> suf(i+1);
		pre[0]=0;
		fo(j,i)
			pre[j+1]=(pre[j]+curr[j])%mod;
		suf[i]=0;
		for(int j=i-1;j>=0;j--)
			suf[j]=(suf[j+1]+curr[j])%mod;
		vector<int> temp(i+1);
		for(int j=0;j<=i;j++)
		{
			if(s[i-1]=='<')
			{
				temp[j]=pre[j];
			}
			else
			{
				temp[j]=suf[j];
			}
		}
		curr=temp;
	}
	int ans=0;
	fo(i,n)
		ans=(ans+curr[i])%mod;
	cout<<ans<<'\n';
	printclock;
}

Measured memory_bytes: 384
def getN():
    return int(input())
def getNM():
    return map(int, input().split())
def getList():
    return list(map(int, input().split()))
def getArray(intn):
    return [int(input()) for i in range(intn)]
def input():
    return sys.stdin.readline().rstrip()

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

import sys
sys.setrecursionlimit(1000000000)
mod = 10 ** 9 + 7
N = getN()
S = input()
# up 左にいるWの人数
up = [0 for i in range(N)]
# down 右にいるEの人数
down = [0 for i in range(N)]

for i in range(1, N):
    if S[i - 1] == "W":
        up[i] = up[i - 1] + 1
    else:
        up[i] = up[i - 1]

for i in range(2, N + 1):
    if S[-i + 1] == "E":
        down[-i] = down[-i + 1] + 1
    else:
        down[-i] = down[-i + 1]
ans = float('inf')
for i in range(N):
    opt = up[i] + down[i]
    ans = min(ans, opt)
print(ans)

Measured memory_bytes: 92124
/*input
12 3
1 1
1 1
1 1
1 1
1 2
1 3
2 1
2 2
2 3
3 1
3 2
3 3

*/

#include <bits/stdc++.h>
#pragma comment(linker, "/stack:200000000")
#pragma GCC optimize ("Ofast")
#pragma GCC target ("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstring>
#include <chrono>
#include <complex>

#define endl "\n"
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define vvi vector < vi >
#define pii pair<int,int>
#define pll pair<long long, long long>
#define vpll vector < pair<long long,long long> >
#define mod 1000000007
#define inf 1000000000000000001
#define all(c) c.begin(),c.end()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define pdd pair<double, double>
#define dbg(x) cout << #x << " = " << x << '\n'
#define dbg2(x,y) cout<<#x<<" = "<<x<<" & "<<#y<<" = "<<y<<endl
#define dbgstl(v) cout<<#v<<" = \n"; { int c=0; repS(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it<<endl;} cerr<<endl
#define dbgstlp(v) cout<<#v<<" = \n"; { int c=0; repS(it,v) \
cout<<"    "<<#v<<"["<< ++c <<"] = "<<it.f<<" , "<<it.s<<endl;} cerr<<endl
#define PI           3.14159265358979323846

#define rep(i, n)    for(i = 0; i < (n); ++i)
#define repA(i, a, n)  for(i = a; i <= (n); ++i)
#define repD(i, a, n)  for(i = a; i >= (n); --i)
#define repS(a, x) for(auto& a : x)
#define pdd pair<double, double>
#define in(v,n) vll v(n);rep(i,n) cin>>v[i]


using namespace std;

//function<void(int,int)> foo;
// foo = [&](int i,int j){};

int main(){
    std::ios::sync_with_stdio(false);
    cin.tie(0);
    cin.exceptions(cin.failbit);
    int T;
    // cout<<std::fixed<<std::setprecision(35);
    // cin>>T;while(T--)
    {
        ll t,n,i,j,x,y,m,l,d,k;
        cin>>n>>d;
        d = d*d;
        ll ans = 0;
        rep(i,n){
        	cin>>x>>y;
        	x = x*x + y*y;
        	if(x<=d) ans++;
        }
        cout<<ans<<endl;
    }
}

Measured memory_bytes: 3608
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds;
using namespace std;
typedef tree<pair<int,int>,null_type,less<pair<int,int>>,rb_tree_tag,tree_order_statistics_node_update> oset;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
  enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
	*this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
using ll = long long;

bool check(vector<pair<int,int>> s){
	int h = 0;
	for(auto p : s){
		int b = h+p.first;
		if( b < 0)
			return false;
		h += p.second;
	}
	return true;
}

void test_case(){
	int n; cin >> n;
	vector<pair<int,int>> ls , rs;
	int total = 0;
	string s;
	for(int i = 0 ; i < n ; i++){
		cin >> s;
		int h = 0,b=0;
		for(auto c : s){
			if(c == '(')
				++h;
			else
				--h;
			b = min(b,h);
		}
		if(h > 0)
			ls.emplace_back(b,h);
		else
			rs.emplace_back(b-h,-h);
		total+=h;
	}
	sort(ls.rbegin(),ls.rend());
	sort(rs.rbegin(),rs.rend());
	if(check(ls) && check(rs) && total == 0)
		cout<<"Yes\n";
	else
		cout<<"No\n";
}
 
int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	int T=1;
	//~ cin >> T;
	while(T--){
		test_case();
	}
	return 0;
}


Measured memory_bytes: 18908
H=int(input())

if H == 1:
  ans=1
  
H_list=[]
while H > 1:
    if H % 2 != 0:
        H=H-1
    H_list.append(H)
        
    H = H//2
    
H_list.sort()
 
ans_list=[]
for h in H_list:
    if h == 2:
        ans = 3
    else :
        ans = 2*ans+1
    ans_list.append(ans)
    
print(ans)

Measured memory_bytes: 38256
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <numeric>
#include <functional>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <memory>
#include <thread>
#include <tuple>
#include <limits>
#include <iostream>

using namespace std;

int main() {
  ios_base::sync_with_stdio(false);
  string s;
  cin >> s;
  int n = s.length();
  vector<int> dp1(n, -1), dp2(n, -1);
  if (n >= 1) dp1[0] = 1;
  if (n >= 2) dp2[1] = 1;
  for (int i = 0; i < n; i++) {
    if (dp1[i] >= 0) {
      if (i + 1 < n && s[i] != s[i + 1]) {
        dp1[i + 1] = max(dp1[i + 1], dp1[i] + 1);
      }
      if (i + 2 < n) {
        dp2[i + 2] = max(dp2[i + 2], dp1[i] + 1);
      }
    }
    if (dp2[i] >= 0) {
      if (i + 1 < n) {
        dp1[i + 1] = max(dp1[i + 1], dp2[i] + 1);
      }
      if (i + 2 < n && (s[i] != s[i+2]  || s[i-1] != s[i+1])) {
        dp2[i + 2] = max(dp2[i + 2], dp2[i] + 1);
      }
    }
  }
  int ans = 1;
  if (n >= 1) ans = max(dp1[n-1], dp2[n-1]);
  cout << ans << "\n";
  return 0;
}


Measured memory_bytes: 2196
import sys
N, X, M = map(int, input().split())

now = X
temp_answer = now
exists = set([now])
order = [now]
rewards = [now]

for i in range(N-1):
    now = now**2 % M
    #print(now, exists)
    if now in exists:
        pre = order.index(now)
        circle = i+1 - pre
        circle_reward = rewards[-1] + now - rewards[pre]
        stopped = i + 1
        temp_answer += now
        break
    exists.add(now)
    order.append(now)
    rewards.append(rewards[-1] + now)
    temp_answer += now
else:
    print(temp_answer)
    sys.exit()

N = N - (stopped)
answer = temp_answer

answer += circle_reward * ((N-1)//circle)
rest = (N-1) % circle

for i in range(rest):
    now = now**2 % M
    answer += now

print(answer)

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

ll n;
long double a[3005], dp[3005][3005];
long double ans = 0;

long double fn(ll i, ll r)
{
	if(dp[i][r] != -1.0)
		return dp[i][r];
	if(i == n)
		return 1.0;
	if(r > 0)
		dp[i][r] = (1-a[i])*fn(i+1, r-1) + a[i]*fn(i+1, r);
	else
		dp[i][r] = a[i]*fn(i+1, r);
	return dp[i][r];
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);

	cin >> n;
	for(ll i=0; i<n; i++)
	{
		cin >> a[i];
	}
	//memset(dp, -1, sizeof dp);
	for(ll i=0; i<3005; i++)
	for(ll j=0; j<3005; j++)
	dp[i][j] = -1.0;
	cout << setprecision(10);
	cout << fn(0, n/2) << "\n";

	return 0;
}

Measured memory_bytes: 141696
#include <stdio.h>

int main(void)
{
  int a,b,c,count;

  while(1){
    if(scanf("%d%d",&a,&b)==EOF)
      break;
    c = a+b;
    count=0;
    
    if(c == 0)
    count++;
    while(c!=0){
      count++;
      c /= 10;
    }
    printf("%d\n",count);
  }
    return(0);
  }

    

Measured memory_bytes: 600
#include <iostream>
#include <iomanip>
#include <string>
#include <vector>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <math.h>
#include <algorithm>
using namespace std;

typedef long long ll;
typedef vector<int> vi;

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

	if(x >= 30) 
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
#define repr(i, n) for (ll i = n; i >= 0; i--)
#define fi first
#define sc second
#define pb push_back
#define COUT(x) cout << (x) << "\n"
#define COUTF(x) cout << setprecision(15) << (x) << "\n"
#define ENDL cout << "\n"
#define DF(x) x.erase(x.begin())  // 先頭文字削除
#define ALL(x) x.begin(), x.end()
#define SZ(x) (ll) x.size()
#define SORT(x) sort(ALL(x))
#define REVERSE(x) reverse(ALL(x))
#define MAX(x, y, z) max(x, max(y, z))
#define MIN(x, y, z) min(x, min(y, z))
#define ANS cout << ans << "\n"
#define RETURN(x)    \
  cout << x << "\n"; \
  return 0
clock_t CLOCK;
#define START_TIMER CLOCK = clock()
#define SHOW_TIMER cerr << "time: " << (ld)(clock() - CLOCK) / 1000000 << "\n"
#define init() \
  cin.tie(0);  \
  ios::sync_with_stdio(false)
#define LINE cerr << "[debug] line: " << __LINE__ << "\n";
#define debug(x) cerr << "[debug] " << #x << ": " << x << "\n";
#define debugV(v)                       \
  cerr << "[debugV] " << #v << ":";     \
  rep(i, v.size()) cerr << " " << v[i]; \
  cerr << "\n";
using namespace std;
using ll = long long;
using ld = long double;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using mll = map<ll, ll>;
using qll = queue<ll>;
using P = pair<ll, ll>;

constexpr ll INF = 0x3f3f3f3f3f3f3f3f;
constexpr ld PI = 3.141592653589793238462643383279;
ll get_digit(ll x) {
  return to_string(x).size();
}

ll gcd(ll x, ll y) {
  return y ? gcd(y, x % y) : x;
}

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

vector<P> factorize(ll n) {
  vector<P> result;
  for (ll i = 2; i * i <= n; ++i) {
    if (n % i == 0) {
      result.pb({i, 0});
      while (n % i == 0) {
        n /= i;
        result.back().second++;
      }
    }
  }
  if (n != 1) {
    result.pb({n, 1});
  }
  return result;
}

vll divisor(ll n) {
  vll ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n) ret.push_back(n / i);
    }
  }
  SORT(ret);
  return (ret);
}

signed main() {
  init();
  ll x, a, b;
  cin >> x >> a >> b;

  ll d1 = abs(x - a);
  ll d2 = abs(x - b);

  if (d1 < d2) {
    COUT("A");
  } else {
    COUT("B");
  }
  return 0;
}

Measured memory_bytes: 3548
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, 0, n) cin >> l[i];
    sort(l.begin(), l.end());
    int sum = 0;
    rep(i, 0, n - 1) sum += l[i];
    if(sum > l[n - 1]) cout << "Yes" << endl;
    else cout << "No" << endl;
}

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

int main() {
  int n;
  cin >> n;
  map<string, int> mp;
  rep(i,n){
    string s;
    cin >> s;
    mp[s]++;
  }
  cout << mp.size() << endl;
}

Measured memory_bytes: 19180
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <iomanip>
#include <climits>
#include <cstring>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <stack>
#include <queue>

using namespace std;

#define LL long long
#define uLL unsigned long long
#define DD double
#define LDD long double
#define PI acos(-1)
#define modulo 10000007
#define MX 10000
#define EPS 1e-9

main()
{
    //freopen("INPUT.txt", "r", stdin);
    //freopen("OUTPUT.txt", "w", stdout);

    string line, s;
    getline(cin , line);
    stringstream ss(line);
    while(ss >> s) {
        char ch = s[0];
        if(ch >= 'a' && ch <='z') printf("%c", ch+32);
        else printf("%c", ch);
    }
    cout << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int l,i=0,n,ans=1;
  cin >> n;
  int a[n];
  while(cin>>l){
      a[i] = l;
      i++;
  }
  for (int i=0;i<n;i++){
    if (a[i]%2==0){
      if (a[i]%3!=0 && a[i]%5!=0) {
        ans = 0;
        break;
      }
    }
  }
  if (ans == 1){
    cout << "APPROVED" << endl;
  }
  else {
    cout << "DENIED" << endl;
  }
}
        

Measured memory_bytes: 256
N,K = map(int,input().split())
h = list(map(int,input().split()))
dp = [-1] * N
dp[0] = 0
 
for i in range(1, N):
    l = []
    m = min(K, i)
    for j in range(1, m+1):
        l.append(dp[i-j] + abs(h[i] - h[i-j]))
    dp[i] = min(l)
print(dp[-1])

Measured memory_bytes: 52448
#include<math.h>
#include <bits/stdc++.h>
#include <algorithm>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define ll long long int
#define ull unsigned long long
#define py printf("Yes\n")
#define pn printf("No\n")
#define in cin>>
using namespace std;
int INF = 1001001001;
const int MOD=1e9+7;

int main() {
  int N, D; cin >> N >> D;
  vector<vector<int>> X(N, vector<int>(D));
  for (int i = 0; i < N; ++i)
  {
    for (int j = 0; j < D; ++j){
      cin >> X[i][j];
    }
  }
  int ans = 0;
  for (int i = 0; i < N; ++i)
  {
    for (int j = i+1; j < N; ++j)
    {
      int norm = 0;
      for (int k = 0; k < D; ++k)
      {
        int diff = abs(X[i][k] - X[j][k]);
        norm += diff * diff;
      }
      bool flag = false;
      for (int k = 0; k <= norm; ++k)if (k * k == norm)flag = true;
      if (flag) ++ans;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int n,l;
string a[105];
int main(){
	scanf("%d%d",&n,&l);
	for(int i=1;i<=n;i++)cin>>a[i];
	sort(a+1,a+n+1);
	for(int i=1;i<=n;i++)cout<<a[i];
	return 0;
}

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

int main(){
  int n;
  cin >> n;
  long long lucas[n+1];
  lucas[0]=2;lucas[1]=1;
  for(int i=2;i<=n;++i){
    lucas[i]=lucas[i-1]+lucas[i-2];
  }
  cout << lucas[n] << endl;

  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rrep(i,n) for(int i=(int)(n)-1;i>=0;i--)
#define each(a,x) for(auto a : (x))
#define all(a) (a).begin(),(a).end()
#define chmin(a,b) ((a) = min((a),(b)))
#define chmax(a,b) ((a) = max((a),(b)))
#define in_range(x,l,r) ((l)<=(x) && (x)<(r))
#define printvec(a) rep(i,a) cout << a[i] << " \n"[i+1==(a).size()];
#define fs first
#define sc second
#define em emplace
#define eb emplace_back
#define sz size()
#define MP make_pair
using namespace std;
typedef long long ll;
typedef double D;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<string> vs;

const ll INF = 1e8;
const D EPS = 1e-8;
const ll MOD = 1e9+7;

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

bool validate(vi s, size_t n) {
  // 1. all elements are positive and no more than 30,000.
  for (int a : s) {
    if (a <= 0 or a > 30000) return false;
  }

  // 2. elements in s are distinct.
  if (s.size() != n) return false;
  sort(all(s));
  s.erase(unique(all(s)), s.end());
  if (s.size() != n) return false;

  // 3. check gcd of all elements.
  ll gcd_s = s[0];
  for (int a : s) {
    gcd_s = gcd(a, gcd_s);
  }
  if (gcd_s != 1) return false;

  // 4. s is special set.
  ll sum = 0;
  
  for (int a : s) sum += a;
  for (int a : s) {
    if (gcd(a, sum-a) == 1) return false;
  }
  return true;
}

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

  vi ans;
  if (n == 3) {
    ans = {2, 5, 63};
  } else if (n <= 5002) {
    int even_n = (n - 2) / 2 * 2;
    rep(i, even_n) {
      ans.push_back(3 * (2 * i + 1));
    }
    if (n % 2 == 0) {
      ans.push_back(2);
      ans.push_back(4);
    } else {
      ans.push_back(2);
      ans.push_back(8);
      ans.push_back(14);
    }
  } else {
    rep(i, 5000) {
      ans.push_back(3 * (2 * i + 1));
    }
    int rem = n - 5000;
    if (rem % 3 == 1) {
      rep(i, rem - 1) {
	ans.push_back(2 * (i + 1));
      }
      ans.push_back(2 * (rem + 2));
    } else {
      rep(i, rem) {
	ans.push_back(2 * (i + 1));
      }
    }
  }

  rep(i, n) {
    cout << ans[i] << " \n"[i == n-1];
  }
}


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

int main(){
    long long a,b,k;
    cin >> a >> b >> k;
    if(k - a >= 0){
        k -= a;
        a = 0;
    }else {
        a -= k;
        k = 0;
    }
    b = max(0ll,b - k);
    cout << a << " " << b << endl;
}


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

// 型定義
typedef long long ll;
typedef pair<ll, ll> P;

// forループ
#define REP(i,n) for(ll i=0; i<(ll)(n); ++i)

// 定数宣言
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

// グラフ表現
using Graph = vector<vector<int>>;

// グラフの辺表現
using Edge = map<pair<int,int>,int>;

// n次元配列の初期化。第２引数の型のサイズごとに初期化していく。
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main()
{
    cout << fixed << setprecision(15);
    int N, K;
    string S;
    
    cin >> N >> K;
    cin >> S;

    REP(i,N){
        if(i == K-1){
            char c = S[i];
            cout << char(tolower(c));
        }
        else{
            cout << S[i];
        }
    }
    cout << endl;
    return 0;
}

Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Collections;
import java.util.LinkedList;


public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.maximumSumCalculation();
		return;
	}
	
	//数値の列の中から、連続して並ぶk個の整数の和の最大値を求める
	private void maximumSumCalculation() {
		
		BufferedReader bufferedReader = new BufferedReader(new InputStreamReader(System.in)); //標準入力
		
		while (true) {
			
			try {

				String inputStr = bufferedReader.readLine();
				String[] inputStrs = inputStr.split(" ");
				int sequenceNum = Integer.parseInt(inputStrs[0]); //数列全体の数
				int integerColumnNum = Integer.parseInt(inputStrs[1]); //kの数
				
				if ((sequenceNum + integerColumnNum) == 0) {
					break;
				}
				
				int[] sequenceArray = new int[sequenceNum]; //数列
				LinkedList<Integer> integerColumnList = new LinkedList<Integer>(); //k個の整数の和のリスト

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

					String inputNumStr = bufferedReader.readLine();
					sequenceArray[i] = Integer.parseInt(inputNumStr);

				}

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

					int tmp = 0;

					try {

						for (int j = 0; j < integerColumnNum; j++) {
							tmp += sequenceArray[j + i];
						}

						integerColumnList.add(tmp);

					} catch (ArrayIndexOutOfBoundsException e) {

						break;

					}

				}

				Collections.sort(integerColumnList);
				Collections.reverse(integerColumnList);

				System.out.println(integerColumnList.get(0));

			} catch (IOException e) {
				// TODO 自動生成された catch ブロック
				e.printStackTrace();
			}
		}
		
	}
}

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

int main()
{
  int e;
  while(cin >> e && e>0)
    {
      int m=e;
      for(int z=0; z*z*z<=e; z++)
	for(int y=0; y*y<=e-z*z*z; y++)
	  {
	  int x = e-z*z*z-y*y;
	  m = min(m, x+y+z);
	  }
      cout << m << endl;
    }
}



Measured memory_bytes: 3016
import math
import copy
from operator import mul
from functools import reduce
from collections import defaultdict
from collections import Counter
from collections import deque
# 直積 A={a, b, c}, B={d, e}:のとき，A×B={(a,d),(a,e),(b,d),(b,e),(c,d),(c,e)}: product(A, B)
from itertools import product
# 階乗 P!: permutations(seq), 順列 {}_len(seq) P_n: permutations(seq, n)
from itertools import permutations
# 組み合わせ {}_len(seq) C_n: combinations(seq, n)
from itertools import combinations
# 一次元累積和
from itertools import accumulate
from bisect import bisect_left, bisect_right

import re
# import numpy as np
# from scipy.misc import comb

# 再帰がやばいとき
# import sys
# sys.setrecursionlimit(10**9)

def inside(y, x, H, W):
    return 0 <= y < H and 0 <= x < W

# 四方向: 右, 下, 左, 上
dy = [0, -1, 0, 1]
dx = [1, 0, -1, 0]
 
def i_inpl(): return int(input())
def l_inpl(): return list(map(int, input().split()))
def line_inpl(x): return [i_inpl() for _ in range(x)]

INF = int(1e50)
MOD = int(1e9)+7 # 10^9 + 7

# field[H][W]
def create_grid(H, W, value = 0):
    return [[ value for _ in range(W)] for _ in range(H)]

########

def main():
    N, M = l_inpl()
    xyz = []
    for _ in range(N):
        xyz_i = l_inpl()
        xyz.append(xyz_i)
    
    ans = -INF
    for i in [-1, 1]:
        for j in [-1, 1]:
            for k in [-1, 1]:
                tmp = []
                for xi, yi, zi in xyz:
                    tmp.append(xi*i+yi*j+zi*k)
                tmp = sorted(tmp, reverse=True)
                ans = max(ans, abs(sum(tmp[:M])))
    
    print(ans)
if __name__ == "__main__":
    main()


Measured memory_bytes: 40560
#include<bits/stdc++.h>
using ll = long long;
using namespace std;
const ll INF = 10000000000000000;
const ll mod = 1000000007;
ll test[1234][1234];
signed main() {
	ll n = 0, a, cnt = 1, ans = 1; cin >> n;
	for (int h = 0; h < n; h++) {
		cin >> a; ans *= 3;
		if (a % 2 == 0) { cnt *= 2; }
	}
	cout << ans - cnt << endl;
	cin >> n; return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
#define rep(begin, i, end) for (int i = begin; i < (int)(end); i++)
#define all(v) v.begin(), v.end()
const int MOD = 1000000007;

int f(int A, int B, int C);

int main()
{
    string S;
    cin >> S;
    int size = S.size();
    int ans = 1000;
    rep(0, i, size - 2)
    {
        int a, b, c;
        a = (int)S[i] - '0';
        b = (int)S[i + 1] - '0';
        c = (int)S[i + 2] - '0';
        ans = min(ans, abs(f(a, b, c) - 753));
    }
    cout << ans << endl;
}

int f(int A, int B, int C)
{
    return A * 100 + B * 10 + C;
}

Measured memory_bytes: 256
// #pragma GCC optimize("O3,unroll-loops")
// #pragma GCC target("avx2")

#include <iostream>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <cstring>
#include <chrono>
#include <vector>
#include <map>
#include <random>
#include <set>
#include <algorithm>
#include <math.h>
#include <cstdio>
#include <stdio.h>
#include <queue>
#include <bitset>
#include <cstdlib>
#include <deque>
#include <cassert>
#include <stack>
using namespace std;

#define mp make_pair
#define f first
#define se second
#define pb push_back
#define ppb pop_back
#define ll long long
#define ull unsigned long long
#define cntbit(x) __builtin_popcount(x)
#define endl '\n'
#define uset unordered_set
#define umap unordered_map
#define all(x) x.begin(), x.end()
#define pii pair<int, int>
#define ld long double
#define pll pair<long long, long long>

mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

inline void setin(string s) {
	freopen(s.c_str(), "r", stdin);
}

inline void setout(string s) {
	freopen(s.c_str(), "w", stdout);
}

template <typename T> inline T range(T l, T r) {
	return uniform_int_distribution <T>(l, r)(rng);
}

template <typename T> void Min(T &a, T b) {
    a = min(a, b);
}
 
template <typename T> void Max(T &a, T b) {
    a = max(a, b);
}

#define int long long

const int inf = 0x3f3f3f3f;
const int mod = 1e9 + 7;
const int N = 1e5 + 15;
int n, a[N];
int cnt[N];
map <int, set <int>> is;

main() {
	ios_base::sync_with_stdio(0); cout.tie(0); cin.tie(0);
	// setin("input.txt");
	cin >> n;
	for(int i = 1; i <= n; ++i) {
		cin >> a[i];
		is[a[i]].insert(i);
	}
	while(!is.empty()) {
		int cur = is.rbegin()->f;
		int i = *is[cur].begin();

		if(cur == is.begin()->f) {
			cnt[i] += 1ll * is[cur].size() * cur;
			break;
		}
		else {
			set <int> temp = {};
			temp.swap(is[cur]);

			is.erase(cur);

			assert(!is.empty());

			int prev = is.rbegin()->f;

			cnt[i] += 1ll * (temp.size()) * (cur - prev);
			// vector <int> temp1 = {};
			// temp1.swap(is[prev]);

			if(is[prev].size() < temp.size())
				swap(is[prev], temp);

			is[prev].insert(temp.begin(), temp.end());
		}
	}
	for(int i = 1; i <= n; ++i)
		cout << cnt[i] << endl;
	return 0;
}

Measured memory_bytes: 16768
#include<iostream>
#include<stdio.h>
#include<string.h>
#include<stdlib.h>
#include<algorithm>
#include <map>
#include <math.h>
#include <vector>
#define INF 1<<30
#define MO 100000007
using namespace std;
int a[100000],b[100000];
int main()
{
	int n,x;
	while(~scanf("%d %d",&n,&x))
	{
		for(int i=0;i<n;i++)
		{
			scanf("%d",&a[i]);
			if(i!=0)
			b[i-1]=a[i]+a[i-1];
		}
		long long sum=0;
		for(int i=0;i<n-1;i++)
		{
			if(b[i]>x)
			{
				if(b[i]-x<=a[i+1])
				 {
				 	 sum+=b[i]-x;a[i+1]-=b[i]-x;b[i+1]-=b[i]-x;b[i]=x;
				 }
				else
				 {
				 	 sum+=b[i]-x;b[i+1]-=a[i+1];a[i+1]=0;b[i]-=a[i+1];
				 	 a[i]-=b[i]-x;b[i]=x;
				 }
			}
		}
		printf("%lld\n",sum);
	}
	
}


Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

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

constexpr ll INF = 1ll<<60;

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

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N, M;
std::vector<ll> G[1010];
std::vector<P> ps;
bool used[1010];
ll d[1010], pre[1010];
std::vector<ll> ans, vs;

int main()
{
  std::cin >> N >> M;

  rep( i, M )
  {
    ll A, B;
    std::cin >> A >> B;
    --A; --B;

    G[A].emplace_back( B );

    ps.emplace_back( A, B );
  }

  for( auto p : ps )
  {
    ll u = p.first, v = p.second, t;

    std::fill( used, used+N, false );
    std::fill( d, d+N, INF );
    std::fill( pre, pre+N, -1 );

    std::queue<P> que;
    que.emplace( v, 0 );
    
    while( !que.empty() )
    {
      P p = que.front(); que.pop();
      ll w = p.first, dist = p.second;

      used[w] = true;
      d[w] = dist;

      //printf( "(%lld, %lld)\n", w, dist );

      if( w == u )
        goto end;

      for( auto s : G[w] )
      {
        if( w == u && s == v )
          continue;

        if( !used[s] )
          que.emplace( s, dist+1 ), pre[s] = w;
      }
    }

    continue;

end:;

    vs.clear();

    vs.emplace_back( v );

    for( t = u ; t != v; t = pre[t] )
      vs.emplace_back( t );

    if( ans.empty() || ans.size() > vs.size() )
      ans = vs;
  }

  if( ans.empty() )
  {
    std::cout << -1 << std::endl;

    return 0;
  }

  std::cout << ans.size() << std::endl;

  for( auto v : ans )
    std::cout << v+1 << std::endl;

  return 0;
}

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

int main(){
    int n,nmax=-1111111111,nmin=1111111111,x;long long sum=0;cin>>n;
    for (int i = 0; i < n; i++)
    {
        cin>>x;
        nmax=max(nmax,x);
        nmin=min(nmin,x);
        sum+=x;
    }
    cout<<nmin<<" "<<nmax<<" "<<sum<<endl;
}    


Measured memory_bytes: 3132
/*
        Author  : Malisetti Samrat
*/

#pragma GCC optimize ("O3")

#pragma GCC optimize("Ofast")

#include   <iostream>
#include   <algorithm>
#include   <queue>
#include   <list>
#include   <map>
#include   <math.h>
#include   <numeric>
using      namespace        std;
#define    endl             '\n'
#define    FAST             ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define    ipfile           ifstream cin ("input.txt");std::cin.rdbuf(std::cin.rdbuf())
#define    pb(x)            push_back(x)
#define    int              long long int
#define    ull              unsigned long long int
#define    db               long double
#define    mod              1000000007
#define    vll              vector<int>
#define    all(v)           v.begin(),v.end()
#define    GCD(m,n)         __gcd(m,n)
#define    LCM(m,n)         m*(n/GCD(m,n))
#define    REVVEC(v)        reverse(v.begin(),v.end())
#define    REVARR(a)        reverse(a,a+n)
#define    maxc(v)          max_element(all(v))
#define    minc(v)          min_element(all(v))
#define    inputarr(a,n)    for(int xxx=0;xxx<n;++xxx) cin>>a[xxx]
#define    outputarr(a,n)   for(int xxx=0;xxx<n;xxx++) cout<<a[xxx]<<" "
#define    rep(i,m, n)      for(int i = m; i < (n); ++i)
#define    sp               setprecison(10)


void solve1()
{
    
   
    string s;
    cin>>s;
    
    if(s[2]==s[3] and s[4]==s[5])
    cout<<"Yes\n";
    else
    cout<<"No\n";
    
    
}


signed main()
{
	FAST
	
//	int T; cin>>T; while( T -- ){
	    solve1();
//	}
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <utility>
#include <stack>
#include <numeric>
#include <algorithm>
#include <tuple>
#include <stdio.h>
#include <bitset>
#include <limits.h>
#include <complex>
#include <deque>
#include <iomanip>
#include <list>
#include <time.h>
using namespace std;
#define pi pair<int,int>
#define pl pair<long long,long long>
#define chmax(a,b) (a<b ? a=b:0)
#define chmin(a,b) (a>b ? a=b:0)
#define en cout << endl //セミコロンつけろ
//#define MM 1000000000
//#define MOD MM+7
const int MM = 1e9;
const int MOD = MM+7;
const long double PI = acos(-1);
const long long INF = 1e15;
int dx[8] = {-1,0,1,0,-1,-1,1,1};
int dy[8] = {0,-1,0,1,-1,1,1,-1};
// 'A' = 65, 'Z' = 90, 'a' = 97, 'z' = 122
template<typename T>
T GCD(T u,T v){
    return v ? GCD(v,u%v) : u;
}
template<typename T>
T LCM(T x,T y){
    T gc = GCD(x,y);
    return x*y/gc;
}

long long dfs(int K,const vector<vector<int>> &g, int now,int from){
    int num;
    if (from == -1) num = K-1;
    else num = K-2;

    if (K < g[now].size()) return 0;

    long long cnt = 1;
    for (auto i : g[now]){
        if (i == from) continue;
        cnt *= num;
        num--;
        cnt %= MOD;
    }
    for (auto i : g[now]){
        if (i == from) continue;
        cnt *= dfs(K,g,i,now);
        cnt %= MOD;
    }
    return cnt;
}

void dfs(const vector<vector<int> > &g, int now,int from,vector<long long> &weight){
    for (auto i : g[now]){
        if (i == from) continue;
        weight[i] += weight[now]; 
    }
    for (auto i : g[now]){
        if (i == from) continue;
        dfs(g, i, now,weight);
    }
}

int main(){
    int N,Q; cin >> N >> Q;
    vector<vector<int> > g(N);
    
    for (int i = 0; i < N-1; i++){
        int a,b; cin >> a >> b; a--, b--;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    vector<long long> weight(N,0);

    for (int i = 0; i < Q; i++){
        int p,x; cin >> p >> x; p--;
        weight[p] += x;
    }
    for (auto i : g[0]){
        weight[i] += weight[0];
        dfs(g,i,0,weight);
    }
    for (auto i : weight){
        cout << i << " ";
    }
    cout << endl;
}

Measured memory_bytes: 27392