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

using namespace std;

#define ll long long
#define ull unsigned ll
#define all(x) x.begin(), x.end()
const int M = 1e9 + 7;

ll FindLCM(ll a, ll b) {
    return (a * b) / __gcd(a, b);
}

ll rangeDivisor(ll m, ll n, ll a, ll b) {
    ll lcm = FindLCM(a, b);

    ll a_divisor = n / a - (m - 1) / a;
    ll b_divisor = n / b - (m - 1) / b;


    ll common_divisor = n / lcm - (m - 1) / lcm;

    ll ans = a_divisor + b_divisor - common_divisor;
    return ans;
}

int main() {
    ll a, b, c, d;
    cin >> a >> b >> c >> d;

    cout << (b - a + 1) - rangeDivisor(a, b, c, d) << endl;
}

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

using namespace std;

int n, a[100], ans = 1000000000;

int cost(int p){
	int res = 0;
	for(int i = 0; i < n; ++i) res += (p-a[i])*(p-a[i]);
	return res;
}

int main(){
	cin >> n;
	for(int i = 0; i < n; ++i) cin >> a[i];
	
	for(int i = -100; i <= 100; ++i){
		ans = min(ans, cost(i));
	}
	
	cout << ans << endl;
}

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

int main(){
    int N, Q;
    cin >> N >> Q;
    set<int, greater<int> > values;
    for(int i = 0; i < N; i++){
        int v;
        cin >> v;
        values.insert(v);
    }
    int max_value = *values.begin();
    for(int i = 0; i < Q; i++){
        int q;
        cin >> q;
        int ans = max_value % q;
        for(int j = q; j <= max_value; j += q){
            set<int, greater<int> >::iterator it = values.upper_bound(j);
            if(it == values.end()) continue;
            ans = max(ans, *it % q);
        }
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 15252
#include <stdio.h>

char S[100000];

void Do(int N){
  int i, c;
  scanf("%s", S);
  c = 1;
  for(i = 1;i < N;i++) if(S[i-1] != S[i]) c++;
  printf("%d\n", c);
}

int main(void){
  int N;
  scanf("%d", &N);
  Do(N);
  return 0;
}


Measured memory_bytes: 256
n,k=map(int,input().split())
p=list(map(int,input().split()))

e=[(i+1)/2 for i in p]

s=[0]*(n+1)
for i in range(n):
    s[i+1]=s[i]+e[i]

ans=0
for i in range(n-k+1):
    total=s[i+k]-s[i]
    if total >= ans:
        ans=total
        
print(ans)

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

using namespace std;

typedef long long ll;

int main(){
    int N,K;
    int input;
    cin >> N >> K;
    
    vector<int> l;
    for (int i = 0; i<N; i++){
        cin >> input;
        l.push_back(input);
    }

    sort(l.begin(), l.end(),std::greater<int>());
    
    int ans = 0;
    for(int i = 0; i < K; i++){
        ans += l[i];
    }
    cout << ans;
    return 0;
}

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

typedef long long ll;

const int MOD = 1000000007;
const int INF = 1001001001;

ll gcd(ll a, ll b) { return b ? gcd(b,a%b) : a;}

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

int main() {
    ll n, h;
    cin >> n >> h;
    vector<ll> a(n), b(n);
    rep(i, n) cin >> a[i] >> b[i];
    sort(all(a));
    sort(all(b));
    reverse(all(a));
    reverse(all(b));
    ll at1 = a[0];
    ll index = 0;
    ll ans = 0;
    while(b[index] > at1 and h > 0 and index < n) {
        ans += 1;
        h -= b[index];
        index += 1;
    }
    
    if(h > 0) {
        if(h % at1 == 0) ans += h / at1;
        else ans += h / at1 + 1;
    }

    cout << ans << endl;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
int main()
{
	int n;
	cin>>n;
	vector<int>arr(n);
	for(int i=0; i<n; i++){
		cin>>arr[i];
	}
	ll ans=1000;
	for(int i=0; i<n-1; i++){
		if(arr[i]<arr[i+1]){
			ll num=ans/arr[i];
			ans=ans%arr[i];
			ans+=num*arr[i+1];
		}
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 3616
#include <stdio.h>
#include <iostream>
#include <vector>
#include <assert.h>
#include <set>
#include <map>
#include <cmath>
#include <queue>
#include <stack>
#include <string>
#include <sstream>
#include <memory.h>
#include <time.h>
#include <string.h>
#include <stdlib.h>
#include <algorithm>
using namespace std;
typedef long long ll;
const int N = 15;
int n, m, edgeSum[1 << N][N], compSum[1 << N], cost[N][N], dp[N][1 << N], DP[1 << N], vis[1 << N], vs, lg[1 << N];
vector<int> nodes;
int calc(int u, int mask) {
	if (u == n - 1)
		return mask ? -1e9 : 0;
	int &ret = dp[u][mask];
	if (ret != -1)
		return ret;
	ret = -1e9;
	for (int i = 1; i < n; ++i)
		if ((mask >> i) & 1)
			ret = max(ret, cost[u][i] + calc(i, mask ^ (1 << i)));
	return ret;
}
int calc(int mask) {
	if (!mask)
		return 0;
	int &ret = DP[mask];
	if (vis[mask] == vs)
		return ret;
	vis[mask] = vs;
	ret = 0;
	for (int cur, sub = mask; sub > 0; sub = (sub - 1)&mask) {
		cur = 0;
		for (int i = 0; i < nodes.size(); ++i)
			cur = max(cur, edgeSum[sub][nodes[i]]);
		cur += compSum[sub];
		ret = max(ret, cur + calc(mask^sub));
	}
	return ret;
}
int main()
{
	for (int i = 0; i < 15; ++i)
		lg[1 << i] = i;
	scanf("%d%d", &n, &m);
	int all = 0;
	for (int i = 0; i < n; ++i)
		for (int j = 0; j < n; ++j)
			cost[i][j] = -1e9;
	for (int a, b, c, i = 0; i < m; ++i) {
		scanf("%d%d%d", &a, &b, &c);
		--a; --b;
		cost[a][b] = cost[b][a] = c;
		all += c;
	}
	for (int mask = (1 << n) - 1; mask > 0; --mask) {
		if (mask & 1)
			continue;
		if (mask >> (n - 1))
			continue;
		for (int i = 0; i < n; ++i)
			if ((mask >> i) & 1) {
				for (int j = i + 1; j < n; ++j)
					if (cost[i][j] > 0 && ((mask >> j) & 1))
						compSum[mask] += cost[i][j];
				for (int j = 0; j<n; ++j)
					if (cost[i][j] > 0 && !((mask >> j) & 1))
						edgeSum[mask][j] += cost[i][j];
			}
	}
	memset(dp, -1, sizeof(dp));
	int res = 1e9;
	for (int i = (1 << n) - 1; i >= 1; --i) {
		if (!((i & 1)))
			continue;
		if (!((i >> (n - 1)) & 1))
			continue;
		int cur = calc(0, i ^ 1);
		if (cur < 0)
			continue;
		++vs;
		nodes.clear();
		for (int j = 0; j < n; ++j)
			if ((i >> j) & 1)
				nodes.push_back(j);
		cur += calc((~i)&((1 << n) - 1));
		res = min(res, all - cur);
	}
	printf("%d\n", res);
	return 0;
}

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

const long long INF = 1e18;

void Main() {
  int N, K;
  cin >> N >> K;

  vector<int> P(N), C(N);
  for (int i = 0; i < N; i++) {
    cin >> P[i];
    P[i]--;
  }
  for (int i = 0; i < N; i++) {
    cin >> C[i];
  }

  long long ans = -INF;

  for (int i = 0; i < N; i++) {
    long long sum = 0;
    int count = 0;

    int next = i;
    while (true) {
      count++;
      sum += C[next];
      next = P[next];
      if (next == i) break;
    }

    long long score = 0;
    long long step = 0;
    while (true) {
      score += C[next];
      step++;
      if (step > K) break;

      ans = max(ans, score + max(0ll, sum) * ((K - step) / count));

      next = P[next];
      if (next == i) break;
    }
  }
  cout << ans << endl;
}

int main() {
  std::cin.tie(nullptr);
  std::ios_base::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);
  Main();
  return 0;
}



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

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}
#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        s: String,
    }
    let mut start: usize = 0;
    for (i, c) in s.chars().into_iter().enumerate() {
        if c == 'A' {
            start = i;
            break;
        }
    }
    let mut end: usize = 0;
    for (i, c) in s.chars().into_iter().rev().enumerate() {
        if c == 'Z' {
            end = s.len() - i - 1;
            break;
        }
    }
    println!("{}", end - start + 1);
} 


Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
const long long inf = 1000000001; // const 書き換え禁止
using ll = long long;

const int MX = 100005;

int main(void){
    int n;
    cin >> n;
    vector<ll> cnt(MX);
    ll sum = 0;
    rep(i,n){
        int k;
        cin >> k;
        cnt[k]++;
    }
    rep(i,MX){
        sum += i * cnt[i];
    }

    int q;
    cin >> q;
    rep(i,q){
        int b,c;
        cin >> b >> c;
        sum += (c-b) * cnt[b];
        cnt[c] += cnt[b];
        cnt[b] = 0;
        cout << sum << endl;
    }
}

Measured memory_bytes: 3960
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <queue>
#include <bitset>
#include <cmath>
#include <set>
#include <map>
#include <iostream>

using namespace std;
 
#define rep(i, l, r) for(int i=l; i<=r; i++)
#define dow(i, l, r) for(int i=l; i>=r; i--)
#define clr(x, c) memset(x, c, sizeof(x))
#define travel(x) for(edge *p=fir[x]; p; p=p->n)
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define l(x) Left[x]
#define r(x) Right[x]
#define lowbit(x) (x&-x)
 
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,int> Pli;
typedef long double ld;
typedef unsigned long long ull;
 
inline int read()
{
	int x=0, f=0; char ch=getchar();
	while (ch<'0' || '9'<ch) f|=ch=='-', ch=getchar();
	while ('0'<=ch && ch<='9') x=x*10+ch-'0', ch=getchar();
	return f?-x:x;
}

int main()
{
	ll n; scanf("%lld", &n);
	rep(i, 1, 3500) rep(j, 1, 3500)
	{
		if (4LL*i*j-n*i-n*j>0 && n*i*j%(4LL*i*j-n*i-n*j)==0)
		{
			printf("%d %d %lld\n", i, j, n*i*j/(4LL*i*j-n*i-n*j));
			return 0;
		}
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<map>
#include<algorithm>
#define FAST ios::sync_with_stdio(false),cin.tie(0),cout.tie(0)
using namespace std;
typedef long long ll;
const int Max = 1e6 + 5;
int c[Max], s[Max], f[Max];

int main()
{
	FAST;
	int n;
	cin >> n;
	for (int i = 1;i < n;i++)
	{
		cin >> c[i] >> s[i] >> f[i];
	}
	for (int i = 1;i <= n;i++)
	{
		int ans = 0;
		for (int j = i;j < n;j++)
		{
			ans = max(ans, s[j]);
			if (ans % f[j] != 0)ans = ans + f[j] - ans % f[j];
			ans += c[j];
		}
		cout << ans << endl;
	}

}

Measured memory_bytes: 3208
#include<iostream>
#include<algorithm>
#include<cmath>
#include<cstring>
using namespace std;
typedef long long ll;
int main(){
	ll m,n;
	cin>>m>>n;
	ll i,j;
	ll s=0,t;
	while(n--){
		cin>>t;
		s+=t;
	}
	if(s<m)
		cout<<"No"<<endl;
	else
		cout<<"Yes"<<endl;
}


Measured memory_bytes: 256
import sys
sys.setrecursionlimit(2 * 10 ** 5 + 10)

mod = 10 ** 9 + 7

N, *AB = map(int, open(0).read().split())

E = [[] for _ in range(N)]
for i, (a, b) in enumerate(zip(*[iter(AB)] * 2)):
    E[a - 1].append((b - 1, i))
    E[b - 1].append((a - 1, i))

X = [0] * N

def dfs(u, p):
    res = 1
    for v, c in E[u]:
        if p != c:
            res += dfs(v, c)
    X[p] = res
    return res

dfs(0, -1)

I = [1]
inv = pow(2, mod - 2, mod)
for i in range(N):
    I.append(I[-1] * inv % mod)

ans = - inv * N - I[N] + 1 + sum((1 - I[x]) * (1 - I[N - x]) for x in X)
ans %= mod

print(ans)

Measured memory_bytes: 214436
import itertools
n, k = map(int, input().split())
num = list(map(int, input().split()))
sumNum = [(1+i)/2 for i in num]
res = [0] + list(itertools.accumulate(sumNum))
ans = -1
for i in range(n-k+1):
  r = res[i+k] - res[i]
  ans = max(ans, r)
print(ans)


Measured memory_bytes: 26236
#pragma GCC optimize ("O3")
#pragma GCC optimize ("unroll-loops")
#pragma comment(linker, "/STACK:2000000")

#include "bits/stdc++.h"

using namespace std;

#define pb push_back
#define F first
#define S second
#define f(i,a,b)  for(int i = a; i < b; i++)
// #define endl '\n'
using ll = long long;
using db = long double;
using ii = pair<int, int>;

const int N = 2e5 + 5, LG = 19, MOD = 998244353;
const int SQ =320;
const long double EPS = 1e-7;
vector<ll> sum;
int n, k, x;
int bit[N];
void upd(int x){for(++x;x<N;x+=x&-x)bit[x]++;}
int get(int x, int res = 0){for(;x;x-=x&-x)res+=bit[x];  return res;}
int32_t main(){
#ifdef ONLINE_JUDGE
    ios_base::sync_with_stdio(0);
    cin.tie(0);
#endif

  cin >> n >> k;
  sum.push_back(0);
  f(i,0,n){
    cin >> x;
    sum.push_back(sum.back()+x-k);
  }

  auto ord=sum;
  sort(ord.begin(),ord.end());
  ord.resize(unique(ord.begin(),ord.end())-ord.begin());

  ll ans = 0;

  upd(lower_bound(ord.begin(),ord.end(),0)-ord.begin());
  ////sum-x>=0
  f(i,1,n+1){
    ans+=get(upper_bound(ord.begin(),ord.end(),sum[i])-ord.begin());
    upd(lower_bound(ord.begin(),ord.end(),sum[i])-ord.begin());
  }

  cout << ans << '\n';


  return 0;
}


Measured memory_bytes: 4336
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;
using ll = long long;

int main()
{
  string S; cin >> S;
  for (int i = 0; i < S.size()-1; ++i) {
    if (S[i] == S[i+1]) {
      printf("%d %d\n", i+1, i+2);
      return 0;
    }
  }

  for (int i = 0; i < S.size()-2; ++i) {
    if (S[i] == S[i + 2]) {
      printf("%d %d\n", i+1, i+3);
      return 0;
    }
  }

  printf("-1 -1\n");
}

Measured memory_bytes: 512
#include <cmath>
#include <cstdio>
#include <vector>
#include <iostream>
#include <algorithm>
#include <unordered_map>
#include <cstring>
#include <ctime>
#include <queue>
#include <map>
using namespace std;
typedef long long ll;
const int maxn = 505;

int n;
string a[maxn],b[maxn];

int main() {
 // freopen("in.cpp","r",stdin);
  cin>>n;
  for(int i=0; i<n; i++) {
    cin>>a[i];
    //b[i]=a[i];
  }
  bool sign=0;
  for(int i=0; i<n; i++)
    for(int j=0; j<n; j++)
      if(a[i][j]=='#')sign=1;
  if(!sign) {
    cout<<-1<<endl;
    return 0;
  }
  int ret=1000000007;
  for(int r=0; r<n; r++) {
    for(int i=0; i<n; i++)b[i]=a[i];
    int ans=0;
    for(int j=0; j<n; j++) {
      if(b[r][j]=='#')continue;
      int pos=-1;
      for(int i=0; i<n; i++)
        if(b[i][r]=='#') {
          pos=i;
          break;
        }
      if(pos==-1) {
        ans++;
        if(j) {
          string tmp=b[r];
          for(int i=0; i<n; i++)b[i][r]=tmp[i];
          pos=0;
        } else {
          int x=-1,y;
          for(int p=0; p<n; p++)
            for(int q=0; q<n; q++)
              if(b[p][q]=='#') {
                x=p,y=q;
              }
          string tmp=b[x];
          for(int i=0; i<n; i++)b[i][r]=tmp[i];
          pos = y;
        }
      }
      ans++;
      string tmp=b[pos];
      for(int i=0; i<n; i++)b[i][j]=tmp[i];
    }
    for(int j=0; j<n; j++) {
      for(int i=0; i<n; i++)
        if(b[i][j]!='#') {
          ans++;
          break;
        }
    }
    ret=min(ret,ans);
  }
  cout<<ret<<endl;
  return 0;
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,n,s) for(int i=(s);i<(n);i++)
#define rrep(i,n) for(int i=(n-1);i>=0;i--)
#define rreps(i,n,s) for(int i=s;i>=n;i--)
#define MOD 1000000007
using ll = long long;
using namespace std;
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }

int main(){
cin.tie(0);
ios::sync_with_stdio(false);
int n;
cin >> n;
char s;
string ans = "Three";
rep(i,n){
    cin >> s;
    if(s=='Y'){
        ans = "Four";
        break;
    }    
}
cout << ans << endl;
//system("pause");
return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define mod 1000000007
#define endl "\n" 
#define p pair<int, int>
#define arrinp(i, a, start, end); for(ll i = start; i <= end; i++) cin >> a[i];
#define arrout(i, a, start, end); for(ll i = start; i <= end; i++) cout << a[i] << " ";
#define swap(a, b) {a = a + b; b = a - b; a = a - b;
#define forfront(i, start, end) for(ll i = start; i <= end; i++)
#define forback(i, start, end) for(ll i = start; i >= end; i--)
#define out(x) cout << x << " "
#define outline(x) cout << x << endl;
int main()
{
    #ifdef LOCAL
        freopen("input.txt", "r", stdin);
        freopen("output.txt", "w", stdout);
    #endif
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    int n;
    cin >> n;
    int a[n];
    set<int> s;
    int count = 0;
    int maxele = 0;
    map<int, int> m;
    for(int i=0; i < n; i++)
    {  
        cin >> a[i];
        m[a[i]]++;
        s.insert(a[i]);
        maxele = max(maxele, a[i]);
    }
    set<int> f;
    for(int x : s)
    {
        for(int i = x; i <= maxele; i += x)
        {
            if(i != x)
            {
                if(s.find(i) != s.end())
                {
                    f.insert(i);
                }
            }
        }
        if(m[x] > 1)
        {
            if(f.find(x) != f.end()) count += m[x] - 1;
            else count += m[x]; 
        }
    }
    int ans = count + f.size();
    // outline(count);
    // outline(f.size());
    ans = n - ans;
    outline(ans);
    return 0;
}

Measured memory_bytes: 32412
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define until(x) while(!(x))
#define unless(x) if(!(x))
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define pc __builtin_popcount

int32_t main(){
	int n;
	cin>>n;
	vector<int> ar(n+1);
	vector<int> v;
	for(int i=1;i<=n;i++){
		cin>>ar[i];
	}
	while(!ar.empty()){
		for(int i=ar.size()-1;i>=0;i--){
			if(ar[i]==i){
				v.push_back(i);
				ar.erase(ar.begin()+i);
				goto cont;
			}
		}
		cout<<"-1";
		return 0;
		cont:1;
	}
	for(int i=v.size()-2;i>=0;i--){
		cout<<v[i]<<"\n";
	}
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<int, int>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
ll power(ll num, ll g, ll mod) {
	if (g == 0)return 1;
	if (g % 2 == 1)return (num * power((num * num) % mod, g / 2, mod)) % mod;
	return power( (num * num) % mod, g / 2, mod);
}

int main(){
	ll n;
	cin >> n;
	ll a[n];
	unordered_map<ll, ll> mp;
	ll sum = 0;
	FOR0(i, n) {
		cin >> a[i];
		mp[a[i]]++;
		sum += a[i];
	}
	ll q, b, c;
	cin >> q;
	FOR0(i, q){
		cin >> b >> c;
		ll num;
		if (mp.find(b) == mp.end()) num = 0;
		else num = mp[b];
		mp[b] = 0;
		mp[c] += num;
		sum += num*(c-b);
		cout << sum << endl;
	}


}	

Measured memory_bytes: 7896
#include <cstdio>
#include <iostream>
#include <cassert>
#include <vector>
#include <queue>
#include <stack>
#include <algorithm>
#define REP(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;

int nNode;
int vs[100000+10];
int parity[100000+10];
int lbs[100000+10];
int ubs[100000+10];
vector<int> g[100000+10];

bool go(int si) {
  stack<pair<int,int> > q; 
  q.push(make_pair(si, -1));
  while(!q.empty()) { // 対象ノード。親ノード。
    pair<int,int> cur = q.top(); q.pop();
    int u = cur.first;
    int parent = cur.second;
    if(u < 0) { // 帰り。子たちの範囲とパリティが判明済み
      u = ~u;
      if(lbs[u] > ubs[u] || parity[u] == 0) { // 無理
        return false;
      }
      if(lbs[u] == ubs[u] && (parity[u] & (1 << (lbs[u] % 2))) == 0) {
        return false;
      }
      if(parent >= 0) {
        REP(i, 2) {
          if((parity[u] & (1 << i)) == 0) {
            parity[parent] &= ~(1 << !i);
          }
        }
        lbs[parent] = max(lbs[parent], lbs[u]-1);
        ubs[parent] = min(ubs[parent], ubs[u]+1);
      }
    } else { // 行き。
      q.push(make_pair(~u, parent));
      REP(i, g[u].size()) {
        int v = g[u][i];
        if(v != parent) {
          q.push(make_pair(v, u));
        }
      }
    }
  }
  return true;
}

void go2(int si) {
  queue<pair<int,int> > q; // 対象ノード。親ノード。
  q.push(make_pair(si, -1));
  while(!q.empty()) {
    pair<int,int> cur = q.front(); q.pop();
    int u = cur.first;
    int parent = cur.second;
    int value;
    if(parent < 0) {
      value = lbs[u];
      if((parity[u] & (1 << (value%2))) == 0) {
        ++value;
      }
    } else {
      value = lbs[parent]-1;
      if(value < lbs[u]) {
        value += 2;
      }
    }
    lbs[u] = ubs[u] = value;
    REP(i, g[u].size()) {
      int v = g[u][i];
      if(v != parent) {
        q.push(make_pair(v, u));
      }
    }
  }
}

int main(void) {
  scanf("%d", &nNode);
  REP(i, nNode-1) {
    int a, b;
    scanf("%d%d", &a, &b);
    --a;
    --b;
    g[a].push_back(b);
    g[b].push_back(a);
  }
  REP(i, nNode) {
    parity[i] = 3;
    lbs[i] = 0;
    ubs[i] = 1000000;
  }
  int nInit;
  scanf("%d", &nInit);
  REP(i, nInit) {
    int v, p;
    scanf("%d%d", &v, &p);
    --v;
    lbs[v] = ubs[v] = p;
    parity[v] = 1 << (p % 2);
  }

  bool ok = go(0);
  if(ok) {
    puts("Yes");
    go2(0);
    REP(i, nNode) {
      assert(lbs[i] == ubs[i]);
      printf("%d\n", lbs[i]);
    }
  } else {
    puts("No");
  }
  return 0;
}


Measured memory_bytes: 8128
/*    特徴    */

/*    教訓    */

#include <bits/stdc++.h>
using namespace std;

using ll = long long;
using ld  = long double;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using pld = pair<ld, ld>;
const int INF=1e9+7;
const ll LINF=9223372036854775807;
const ll MOD=1e9+7;
const ld PI=acos(-1);
const ld EPS = 1e-9; //微調整用（EPSより小さいと0と判定など）

int ii() { int x; if (scanf("%d", &x)==1) return x; else return 0; }
long long il() { long long x; if (scanf("%lld", &x)==1) return x; else return 0; }
string is() { string x; cin >> x; return x; }
char ic() { char x; cin >> x; return x; }
void oi(int x) { printf("%d ", x); }
void ol(long long x) { printf("%lld ", x); }
void od_nosp(double x) { printf("%.15f", x); } // 古い問題用
void od(double x) { printf("%.15f ", x); }
// long doubleで受け取り、fをLfなどに変えて出力すると、変な数値が出る
// それをなんとかするには独自の出力を作らなければならなそう
void os(const string &s) { printf("%s ", s.c_str()); }
void oc(const char &c) { printf("%c ", c); }
#define o_map(v){cerr << #v << endl; for(const auto& xxx: v){cout << xxx.first << " " << xxx.second << "\n";}} //動作未確認
void br() { putchar('\n'); }

#define gcd __gcd //llは受け取らない C++17~のgcdと違うので注意
int lcm(int a, int b){return a / gcd(a, b) * b;}
#define begin_end(a) a.begin(),a.end() //sort(begin_end(vec));
#define REP(i,m,n) for(ll i=(ll)(m) ; i < (ll) (n) ; i++ )
#define rep(i,n) REP(i,0,n)
#define m_p(a,b) make_pair(a,b)
#define SORT_UNIQUE(c) (sort(c.begin(),c.end()), c.resize(distance(c.begin(),unique(c.begin(),c.end()))))
#define GET_POS(c,x) (lower_bound(c.begin(),c.end(),x)-c.begin())
#define p_b push_back
#define SZ(x) ((int)(x).size) //size()がunsignedなのでエラー避けに

//4近傍（上下左右） rep(i, 2) にすると右・下だけに進む
vector<int> dx_4 = {1, 0, -1, 0};
vector<int> dy_4 = {0, 1, 0, -1};

// coutによるpairの出力（空白区切り）
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << " " << p.second << ")";}
// coutによるvectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) {
  int len = v.size();
  for (int i = 0; i < len; ++i) {
    s << v[i]; if (i < len - 1) s << " "; //"\t"に変えるとTabで見やすく区切る
  }
  return s;
}
// coutによる多次元vectorの出力（空白区切り）
template<typename T> ostream& operator<<(ostream& s, const vector< vector<T> >& vv) {
  int len = vv.size();
  for (int i = 0; i < len; ++i) {
    s << vv[i] << endl;
  }
  return s;
}

//最大値、最小値の更新。更新したor等しければtrueを返す
template<typename T>
bool chmax(T& a, T b){return (a = max(a, b)) == b;}
template<typename T>
bool chmin(T& a, T b){return (a = min(a, b)) == b;}

// -------- template end - //




// - library ------------- //




// --------- library end - //



// - main() -------------- //

int main(){

  string str = is();
  
  cout << regex_replace(str, regex("\\?"), "D") << endl;


// ---------- main() end - //
}


Measured memory_bytes: 4024
N,K = map(int,input().split())
arr = []

for i in range(N):
  a = int(input())
  arr.append(a)
  
arr.sort()
ans = 10**10

for i in range(N-K+1):
  a = arr[i]
  b = arr[i+K-1]
  c = b-a
  ans = min(ans,c)
  
print(ans)


Measured memory_bytes: 50776
function Main(input) {
    const line = input.split("\n")[0].split(" ");
    let A = parseInt(line[0]);
    let B = parseInt(line[1]);
    let K = parseInt(line[2]);
    
    if(A>=K){
        A -= K;
    } else {
        K -= A;
        A = 0;
        B = B>=K ? B-K : 0;
    }

    console.log(A+" "+B);
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

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

int A[5][5];
int n;

int main(){
    for(int i = 1; i <= 3; i++){
        for(int j = 1; j <= 3; j++)cin >> A[i][j];
    }
    cin >> n;
    set<int> S;
    for(int i = 0; i < n; i++){
        int b;
        cin >> b;
        S.insert(b);
    }

    bool ans = false;
    bool B[5][5];
    for(int i = 1; i <= 3; i++){
        for(int j = 1; j <= 3; j++){
            B[i][j] = false;
            if (S.find(A[i][j]) != S.end()) B[i][j] = true;
        }
    }
    for(int i = 1; i <= 3; i++){
        if (B[i][1] && B[i][2] && B[i][3]) ans = true;
        if (B[1][i] && B[2][i] && B[3][i]) ans = true;
    }
    if (B[1][1] && B[2][2] && B[3][3]) ans = true;
    if (B[3][1] && B[2][2] && B[1][3]) ans = true;

    if (ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS

#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <cstring>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <unordered_set>
#include <unordered_map>
#include <array>
#include <cassert>
#include <bitset>
#include <cstdint>
using namespace std;
using LL = long long;

int A, B;

int main() {
	string S, T;
	int N;
	cin >> N;
	cin >> S >> T;
	for (int i = 0; i < N; ++i) {
		cout << S[i] << T[i];
	}
	cout << endl;
	return 0;
}

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


int main(){
    int64_t N,M,K;
    cin >> N >> M >> K;
    vector<int64_t> A(N+1);
    vector<int64_t> B(M+1);
    A.at(0) = 0;
    B.at(0) = 0;

    for(int64_t i = 1; i < N+1; i++){
        cin >> A.at(i);
        A.at(i) += A.at(i-1);
    }
    for(int64_t j = 1; j < M+1; j++){
        cin >> B.at(j);
        B.at(j) += B.at(j-1);
    }
    int64_t a = N;
    int64_t b = 0;
    int64_t cnt = 0;

    while(A.at(a) > K){
        a--;
    }
    cnt = a;
    //cout << "ini_a" << a << endl;
    //ここでA.at(a) <= Kになる
    for(int64_t i = a; i >= 0; i--){
        while(A.at(i) + B.at(b) <= K){
            b++;
            if(b == M+1){
                break;
            }
        }
        //cout << i << " " << b-1 << endl;
        cnt = max(cnt,i+b-1);
        if(b == M+1){
            break;
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 6372
import java.util.*;
class Main{
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int[] a = new int[3];
		for(int i = 0; i < a.length; i++) {
			a[i] = sc.nextInt();
		}
		int max = 0;
		int sub = 0;
		for(int i = 0; i < a.length; i++) {
			if( a[i] > max ) {
				max = a[i];
				sub = i;
			}
		}
		int ans = 0;
		for(int i = 0; i < a.length; i++) {
			if( i != sub ) {
				ans += a[i];
			}
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 22868
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <set>
#include <map>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <cassert>

using namespace std;

#define FOR(i,k,n) for(int i=(k); i<(int)n; ++i)
#define REP(i,n) FOR(i,0,n)
#define FORIT(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)

template<class T> void debug(T begin, T end){ for(T i = begin; i != end; ++i) cout<<*i<<" "; cout<<endl; }

typedef long long ll;
const int INF = 100000000;
const double EPS = 1e-8;
const int MOD = 1000000007;
int memo[8][8][7];
int d[8][8];
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
int w, h;
int dfs(int x, int y, int hp){
  int time = memo[y][x][hp];
  if(hp == 0) return INF;
  if(d[y][x] == 3) return time;
  int res = INF;
  if(d[y][x] == 4){
    int &nt = memo[y][x][6];
    if(nt == -1 || nt > time){
      nt = time;
      res = min(res, dfs(x, y, 6));
    }
  }
  REP(r, 4){
    int nx = x + dx[r];
    int ny = y + dy[r];
    if(0 <= nx && 0 <= ny && nx < w && ny < h && d[ny][nx] != 0){
      int &nt = memo[ny][nx][hp-1];
      if(nt == -1 || nt > time + 1){
        nt = time + 1;
        res = min(res, dfs(nx, ny, hp-1));
      }
    }
  }
  return res;
}

int main(){
  while(cin>>w>>h && w || h){
    int ans;
    memset(memo, -1, sizeof(memo));
    REP(y, h)REP(x, w) cin>>d[y][x];
    REP(y, h)REP(x, w)if(d[y][x] == 2){
      memo[y][x][6] = 0;
      ans = dfs(x, y, 6);
    }
    if(ans == INF) ans = -1;
    cout<<ans<<endl;
  }
  return 0;
}

Measured memory_bytes: 0
import java.util.Scanner;

class Main{
	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		int kosu=sc.nextInt();
		String[] arare= {"P","W","G","Y"};
		int[] syr= {0,0,0,0};
		String tmp="";

		for(int i=0; i<kosu; i++) {
			tmp=sc.next();
			for(int j=0; j<4; j++) {
				if(tmp.equals(arare[j])) {
					syr[j]++;
				}
			}
		}
		int syuruisu=0;
		for(int i=0; i<4; i++) {
			if(syr[i]>0) {
				syuruisu++;
			}
		}
		if(syuruisu==4) {
			System.out.println("Four");
		}

		else if(syuruisu==3) {
			System.out.println("Three");
		}
	}
}

Measured memory_bytes: 21844
#!/usr/bin/env python3

import sys
import math
from bisect import bisect_right as br
from bisect import bisect_left as bl
sys.setrecursionlimit(2147483647)
from heapq import heappush, heappop,heappushpop
from collections import defaultdict
from itertools import accumulate
from collections import Counter
from collections import deque
from operator import itemgetter
from itertools import permutations
mod = 10**9 + 7
inf = float('inf')
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))

r, c, k = LI()
maze = [[0] * c for _ in range(r)]
for _ in range(k):
    R, C, V = LI()
    maze[R-1][C-1] = V

dp1 = [[0] * (c+1) for _ in range(r+1)]
dp2 = [[0] * (c+1) for _ in range(r+1)]
dp3 = [[0] * (c+1) for _ in range(r+1)]

for i in range(1, r+1):
    for j in range(1, c+1):
        dp1[i][j] = max(dp1[i][j-1], dp1[i-1][j] + maze[i-1][j-1], maze[i-1][j-1], dp2[i-1][j] + maze[i-1][j-1], dp3[i-1][j] + maze[i-1][j-1])
        dp2[i][j] = max(dp2[i][j-1], dp2[i-1][j] + maze[i-1][j-1], dp1[i][j-1] + maze[i-1][j-1])
        dp3[i][j] = max(dp3[i][j-1], dp3[i-1][j] + maze[i-1][j-1], dp2[i][j-1] + maze[i-1][j-1])
ans = max(dp1[-1][-1], dp2[-1][-1], dp3[-1][-1])
print(ans)

Measured memory_bytes: 353864
import java.util.*;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner (System.in);
        int count = sc.nextInt();
        long Max = -1000000;
        long Min = 1000000;
        long sum = 0;
        for(int i=0;i<count;i++){
            int num = sc.nextInt();
            Max = Math.max (Max, num);
            Min = Math.min (Min, num);
            sum+=num;
        }
       System.out.println(Min + " " + Max + " " + sum);
    }
}


Measured memory_bytes: 42516
#include <bits/stdc++.h>
#define ss second
#define ff first
#define all(x) x.begin(), x.end()
 
using namespace std;
using ll = long long;
using pii = pair<ll, ll>;
 
const ll oo = 1e18 + 7;
const ll mod = 1e9 + 7, maxn = 2e5 + 10;  
const long double PI = acos(-1);
int p[maxn], sz[maxn];

void init(){
    for (int i=0; i<maxn; i++){
        p[i] = i;
        sz[i] = 1;
    }
}

int find_parent(int x){
    if (x == p[x]) return x;
    return p[x] = find_parent(p[x]);
}

void union_set(int a, int b){
    a = find_parent(a);
    b = find_parent(b);

    if (a == b) return;
    if (sz[a] < sz[b]) swap(a, b);

    p[b] = a;
    sz[a] += sz[b];
}

int solve (int n){
    set<pii>  st;

    for (int i=1; i<=n; i++){
        int pai = find_parent(i);
        // cout << pai << endl;
        st.insert({pai, sz[pai]});
    }

    int ans = 0;

    for (auto it: st) ans = max((ll)ans, it.ss);
    return ans;
}

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

    for (int i=0; i<m; i++){
        int a, b;
        cin >> a >> b;
        union_set(a, b);
    }
    cout << solve(n) << endl;
    return 0;   
}

Measured memory_bytes: 17612
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long LL;
const int maxn=20;
int n,A[maxn];LL ans=1e18;
struct Sol
{
	LL Ld,Rd;
	inline bool operator < (const Sol& b)const{return Ld<b.Ld||(Ld==b.Ld&&Rd<b.Rd);}
};
vector<Sol> F[maxn][maxn];
inline void Clean(vector<Sol>& vec)
{
	sort(vec.begin(),vec.end());
	LL mi=1e18;F[0][0].clear();
	for(int i=0;i<(int)vec.size();i++)
	{
		if(vec[i].Rd<mi)
		{
			mi=vec[i].Rd;
			F[0][0].push_back(vec[i]);
		}
	}
	vec=F[0][0];
}
int main()
{
	scanf("%d",&n);if(n==2) ans=0;
	for(int i=1;i<=n;i++) scanf("%d",&A[i]);
	for(int i=2;i<n;i++)
		F[i][i].push_back((Sol){A[i],A[i]});
	for(int len=2;len<=n-2;len++)
	{
		for(int i=2;i+len-1<n;i++)
		{
			int j=i+len-1;
			for(int k=i;k<=j;k++)
			{
				if(k==i)
				{
					for(int t=0;t<(int)F[i+1][j].size();t++)
						F[i][j].push_back((Sol){F[i+1][j][t].Ld+A[k],F[i+1][j][t].Ld+F[i+1][j][t].Rd+A[k]});
				}
				else if(k==j)
				{
					for(int t=0;t<(int)F[i][j-1].size();t++)
						F[i][j].push_back((Sol){F[i][j-1][t].Rd+A[k]+F[i][j-1][t].Ld,F[i][j-1][t].Rd+A[k]});
				}
				else
				{
					for(int t1=0;t1<(int)F[i][k-1].size();t1++)
					{
						for(int t2=0;t2<(int)F[k+1][j].size();t2++)
						{
							F[i][j].push_back((Sol){F[i][k-1][t1].Rd+F[k+1][j][t2].Ld+A[k]+F[i][k-1][t1].Ld,F[i][k-1][t1].Rd+F[k+1][j][t2].Ld+A[k]+F[k+1][j][t2].Rd});
						}
					}
				}
			}
			Clean(F[i][j]);
		}
	}
	for(int i=0;i<(int)F[2][n-1].size();i++)
		if(F[2][n-1][i].Ld+F[2][n-1][i].Rd<ans)
			ans=F[2][n-1][i].Ld+F[2][n-1][i].Rd;
	printf("%lld\n",ans+A[1]+A[n]);
	return 0;
}

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

int main() {
  vector<ll> A(4);
  rep(i, 4) cin >> A.at(i);
  
  ll maxi=A.at(0)*A.at(2);
  maxi = max(maxi, A.at(0)*A.at(3));
  maxi = max(maxi, A.at(1)*A.at(2));
  maxi = max(maxi, A.at(1)*A.at(3));
  
  cout << maxi << endl;
  return 0;
}




Measured memory_bytes: 3624
#include<iostream>
int main(void) {
	int a, b, max = 0, temp = 0;
	int num;
	std::cin >> num;
	for(int l1 = 0;l1 < num;l1++){
		std::cin >> a >> b;
		if (max < a) {
			max = a;
			temp = b;
		}
	}
	std::cout << max + temp << std::endl;
	return 0;

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main() {
	long long A,B;
	cin>>A>>B;
	long long a=4-A%4,b=B%4,n=0;
	for(long long i=A;i<A+a;i++) n=n^i;
	for(long long i=B-b;i<=B;i++) n=n^i;
	cout<<n<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long long ll;
typedef pair<ll, ll> PLL;
typedef vector<int> VI;
typedef vector<char> VC;
typedef vector<double> VD;
typedef vector<string> VS;
typedef vector<ll> VLL;
typedef vector<PLL> VP;
const static int INF = 1000000000;
const static int MOD = 1000000007;
const int dx[4]={1, 0, -1, 0};
const int dy[4]={0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
#define rep(i,n) for (ll i=0; i<(ll)(n); i++)
#define repd(i,n) for (ll i=n-1; i>=0; i--)
#define rept(i,m,n) for(ll i=m; i<n; i++)
#define stl_rep(itr, x) for (auto itr = x.begin(); itr != x.end(); ++itr)
#define all(x) (x).begin(), (x).end()
#define F first
#define S second
#define PF push_front
#define PB push_back
#define SORT(V) sort((V).begin(), (V).end())
#define RVERSE(V) reverse((V).begin(), (V).end())
#define paired make_pair
#define PRINT(V) for(auto v : (V)) cout << v << " "
//charを整数に
int ctoi(char c) { if (c >= '0' && c <= '9') { return c - '0'; } return 0; }
// 累積和 for (int i = 0; i < N; ++i) s[i+1] = s[i] + a[i]; 
void cum_sum(int N,vector<double> a, vector<double> &s){ for(int i=0; i<N; i++){ s[i+1]=s[i]+a[i];}}
//ユークリッドの控除法
ll gcd(ll a,ll b){
    if(b == 0) return a;
    return gcd(b,a%b);
}
//最小公倍数
ll lcm(ll a,ll b){
    ll g = gcd(a,b);
    return a / g * b; // Be careful not to overflow
}
//素数判定
bool is_prime(long long n) {
    if (n <= 1) return false;
    for (long long p = 2; p * p <= n; ++p) {
        if (n % p == 0) return false;
    }
    return true;
}
int getdigit(ll num){
    unsigned digit=0;
    while(num!=0){
        num /= 10;
        digit++;
    }
    return digit;
}
//空白文字も入力 getline(cin, S);
//桁数指定 setprecision
VLL a,b,c,d;
ll N, M, Q;
ll score(const vector<ll> &A){
    ll res=0;
    rep(i,Q) if(A[b[i]]-A[a[i]]==c[i]) res+=d[i];
    return res;
}

ll dfs(vector<ll> &A)
{
    if(A.size()==N){
        return score(A);
    }
    ll res=0;
    int prev_last=(A.empty() ? 0 : A.back());
    for(int i=prev_last; i<M; i++){
        A.push_back(i);
        res=max(res,dfs(A));
        A.pop_back();
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(0); 
    cin.tie(0); 
    cout.tie(0);
    cin >> N >> M >> Q;
    a.resize(Q);
    b.resize(Q);
    c.resize(Q);
    d.resize(Q);
    rep(i,Q){
        cin >> a[i] >> b[i] >> c[i] >> d[i];
        a[i]--;
        b[i]--;
    }
    VLL A;
    cout << dfs(A) << endl;
}

Measured memory_bytes: 3648
/*---> 01 November 2019 <--- > 00:19:10 <---*/
// #pragma GCC optimize("Ofast")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
// #pragma GCC optimize("unroll-loops")
// #pragma comment(linker, "/stack:200000000")
#pragma GCC optimize("O3")
//#pragma GCC target ("sse4")
#include <bits/stdc++.h>
//#include <ext/pb_ds/tree_policy.hpp>
//boot#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
//template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
#define int long long
#define F first
#define S second
#define mod 1000000007
#define inf (int)1e18+5
#define sz(x) (int)x.size()
#define PI 3.141592653589793238510
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define __ ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define vi vector<int>
#define vpii vector<pair<int,int> > 
#define vvi vector<vector<int> >
#define PRINT_TIME cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s." <<endl;
#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__) << "] "
typedef long double ld;
typedef pair<int,int> pii;
///////////////////////////////////////////////////////////////////////////////////////////////////
///////////////////////////////////////////////////////////////////////////////////////////////////
const int N=1e5+5;

int32_t main(){__
	int n;
	cin>>n;
	vi a(n-1);
	for(int i=0;i<n-1;i++)
		cin>>a[i];
	int ans=0;
	for(int i=1;i<n-1;i++){
		ans+=min(a[i],a[i-1]);
	}
	ans+=a[0];
	ans+=a.back();
	cout<<ans<<"\n";
return 0;
}

Measured memory_bytes: 256
import java.util.*;

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

        long a = sc.nextLong();
        long b = sc.nextLong();
        long k = sc.nextLong();

        if (a>0) {
            if (a>k){
                a -= k;
            }else {
                k -= a;
                a = 0;
                b = Math.max(b-k, 0);
            }
        }else {
            b = Math.max(b-k, 0);
        }

        System.out.println(a+" "+b);

    }
}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define plint pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if((a==b && b!=c) || (b==c && a!=b) || (c==a && a!=b)){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define int long long
int c[10000000];
signed main(){
  int a,b=0,c=0;
  cin>>a;
  for(int j=1;j<=a;j++){
    b=0;
    if(j%2==1){
      for(int i=1; i<=j; i++ ) {
        if( j%i == 0 ){
         b++;
        }
      }
    }
    if(b==8) c++;
  }
  cout<<c<<"\n";
}

Measured memory_bytes: 256
n=int(input())
l=[[] for i in range(n+1)]
for i in range(n-1):
  a,b,c=map(int,input().split())
  l[a].append([b,c])
  l[b].append([a,c])
q,k=map(int,input().split())
from heapq import heappush,heappop
inf=10**20
def dijkstra(s):
  q=[(0,s)]
  dist=[inf]*(n+1)
  dist[s]=0
  while q:
    c,v=heappop(q)#cは始点からvまでのコスト vは頂点
    if dist[v]<c:
      continue
    for i in l[v]:
      t=i[0]
      cost=i[1]
      if dist[v]+cost<dist[t]:
        dist[t]=dist[v]+cost
        heappush(q,[dist[t],t])
  return dist
d=dijkstra(k)
for i in range(q):
  x,y=map(int,input().split())
  print(d[x]+d[y])


Measured memory_bytes: 109540
r = lambda : map(int, raw_input().split())

n = r()[0]
a = r()

i = n-1 ;
while i >= 0 :
    print a[i],
    i -= 2 
    
if n % 2 == 0 : 
    i = 0
else :
    i = 1 
    
while i < n:
    print a[i],
    i += 2 

Measured memory_bytes: 19956
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty |) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty | $n:expr) => {
        (0..$n).map(|_| get!($t |)).collect::<Vec<_>>()
    };
}

fn main() {
    let (r, D, x2000) = get!(u64, u64, u64);
    let mut x = x2000;
    for i in 2001..(2010+1) {
        x = r * x - D;
        println!("{}", x);
    }
}


Measured memory_bytes: 4352
N, L = map(int, input().split())

ans = 0
lst = []
for i in range(N):
    lst += [[abs(L + (i+1) -1), L + (i+1) -1]]
    ans += L + (i+1) -1

lst.sort()
# print (lst)
print (ans - lst[0][1])

Measured memory_bytes: 3060
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <string>
#include <vector>
#include <math.h>
#include <queue>
#include <deque>
#include <map>
const int MOD = 1e9+7;
typedef long long ll;
using namespace std;


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


Measured memory_bytes: 19256
use strict;
use warnings;

my $a = <STDIN>;
chomp($a);
$a = int($a);

my $result;
my $tmp;
if ($a <= 1000){
    $result = 1000 - $a;
}else{
    $tmp = $a % 1000;
    $result = $tmp;
    if ($tmp > 0){
        $tmp = 1000 - $tmp;
        $result = $tmp;
    }
}
print("$result\n");



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

typedef long long ll;

int main(){
    string t = "";
    cin >> t;
    int count = 0;
    for (int i = 0; i < t.length(); i++){
        if (t[i]=='?'){
            count++;
        }
    }
    // cout << count << endl;
    while(count != 0){
        int check = count;
        for (int i = 0; i < t.length(); i++){
            if (t[i] == '?' && i != 0 && t[i-1] == 'P'){
                t[i] = 'D';
                count--;
            } else if (t[i] == '?' && i != t.length()-1 && t[i+1] == 'D'){
                t[i] = 'P';
                count--;
            } else if (t[i] == '?' && i != t.length()-1 && t[i+1] == '?'){
                t[i] = 'P';
                t[i+1] = 'D';
                count = count-2;
            }
        }
        if (check == count){
            break;
        }
    }
    for (int i = 0; i < t.length(); i++){
        if (t[i]=='?'){
            t[i] = 'D';
        }
    }
    cout << t << endl;
}

Measured memory_bytes: 3484
n=int(input())
s=input()
w=[0]*n
b=[0]*n
if s[0]=='.':
    w[0]=1
else:
    b[0]=1
for i in range(1, n):
    if s[i]=='.':
        w[i]=w[i-1]+1
        b[i]=b[i-1]
    else:
        b[i]=b[i-1]+1
        w[i]=w[i-1]
ans=min(w[n-1], b[n-1])
for i in range(1, n):
    ans=min(ans, b[i-1]+w[n-1]-w[i-1])
print(ans)


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

int main(){
	int x,y,z;
	cin >>x;
	z=x;
	y=x%10;
	while(x!=0){
		x/=10;
		y+=x%10;
	}
	if(z%y==0)
		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;
//using ll = long long;
//using P = pair<int, int>;

int main() {
    int n;
    cin >> n;
    string ans;
    if (n%10 == 7) ans = "Yes";
    else {
        n /= 10;
        if (n%10 == 7) ans = "Yes";
        else {
            n /= 10;
            if (n%10 == 7) ans = "Yes";
            else ans = "No";
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628