akhauriyash/Code-Regression huggingface dataset:
// #pragma comment(linker, "/stack:200000000")
// #pragma GCC optimize("Ofast,no-stack-protector")
// #pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,avx2,tune=native")
// #pragma GCC optimize("unroll-loops")

#include <bits/stdc++.h>

#ifdef PERVEEVM_LOCAL
    #define debug(x) std::cerr << (#x) << ":\t" << (x) << std::endl
#else
    #define debug(x) 238;
#endif

#define fastIO std::ios_base::sync_with_stdio(false); std::cin.tie(0); std::cout.tie(0)
#define NAME "File"

using ll = long long;
using ld = long double;

#ifdef PERVEEVM_LOCAL
    std::mt19937 rnd(238);
#else
    std::mt19937 rnd(std::chrono::high_resolution_clock::now().time_since_epoch().count());
#endif

const double PI = atan2(0.0, -1.0);
const int INF = 0x3f3f3f3f;
const ll LINF = (ll)2e18;
const int N = 100100;
const int MOD = (int)1e9 + 7;

int add(int a, int b, int mod = MOD) {
    if (a + b >= mod) {
        return a + b - mod;
    }
    return a + b;
}

int sub(int a, int b, int mod = MOD) {
    if (a - b < 0) {
        return a - b + mod;
    }
    return a - b;
}

int mul(int a, int b, int mod = MOD) {
    return (int)(1ll * a * b % mod);
}

int binpow(int a, int n, int mod = MOD) {
    if (n == 0) {
        return 1;
    }
    if (n % 2 == 0) {
        return binpow(mul(a, a, mod), n / 2, mod);
    } else {
        return mul(binpow(a, n - 1, mod), a, mod);
    }
}

int rev(int a, int mod = MOD) {
    return binpow(a, mod - 2, mod);
}

std::vector<int> g[N];
int dp[N][2];

void dfs(int v, int p) {
    dp[v][0] = 1;
    dp[v][1] = 1;
    
    for (auto to : g[v]) {
        if (to != p) {
            dfs(to, v);

            dp[v][0] = mul(dp[v][0], dp[to][1]);
            dp[v][1] = mul(dp[v][1], add(dp[to][0], dp[to][1]));
        }
    }
}

void run() {
    int n;
    scanf("%d", &n);

    for (int i = 0; i < n - 1; ++i) {
        int from, to;
        scanf("%d%d", &from, &to);

        g[from - 1].push_back(to - 1);
        g[to - 1].push_back(from - 1);
    }

    dfs(0, -1);

    printf("%d\n", add(dp[0][0], dp[0][1]));
}

int main(void) {
    // freopen(NAME".in", "r", stdin);
    // freopen(NAME".out", "w", stdout);

    auto start = std::chrono::high_resolution_clock::now();
    run();
    auto end = std::chrono::high_resolution_clock::now();

    #ifdef PERVEEVM_LOCAL
        std::cerr << "Execution time: "
                  << std::chrono::duration_cast<std::chrono::milliseconds>(end - start).count()
                  << " ms" << std::endl;
    #endif

    return 0;
}


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

#define ARRAY_SIZE 100
#define MEMORY_ERROR 0
#define MEMORY_SUCCESS 1

void swap(int *a, int *b) {
  int tmp;
  tmp = *a;
  *a = *b;
  *b = tmp;
}

int insert(int **list, int *size, int *memSize, int x) {
  int i, tmpN;
  int *tmpP;
  i = ++*size;
  if (*size > ARRAY_SIZE * *memSize) {
    ++*memSize;
    tmpP = realloc(*list, sizeof(int) * (ARRAY_SIZE * *memSize + 1));
    if (tmpP == NULL) return MEMORY_ERROR;
    if (*list != tmpP) *list = tmpP;
  }
  
  (*list)[i] = x;
  while (i > 1 && (*list)[i/2] < (*list)[i]) {
    swap(&(*list)[i/2], &(*list)[i]);
    i = i / 2;
  }

  return MEMORY_SUCCESS;
}

void setValue(int *list, int size, int index) {
  int left, right, largest, tmp;

  left = 2 * index;
  right = 2 * index + 1;

  if (left <= size && list[left] > list[index]) largest = left;
  else largest = index;

  if (right <= size && list[right] > list[largest]) largest = right;

  if (largest != index) {
    swap(&list[index], &list[largest]);
    setValue(list,size,largest);
  }
}

void deleteMax(int *list, int *size) {
  int tmp;
  swap(&list[1], &list[*size]);
  --*size;
  setValue(list,*size,1);
}

void terminate(int **listAry, int *sizeAry, int *memAry, int size) {
  int i;
  for (i = 0; i < size; i++) free(listAry[i]);
  free(listAry);
  free(sizeAry);
  free(memAry);
}

int main() {
  int i, n, q, com, index, x;
  int **listAry;
  int *sizeAry;
  int *memAry;

  scanf("%d %d",&n,&q);
  ++n;

  listAry = (int**)malloc(sizeof(int*)*n);
  sizeAry = (int*)malloc(sizeof(int)*n);
  memAry = (int*)malloc(sizeof(int)*n);

  for (i = 0; i < n; i++) sizeAry[i] = 0;
  for (i = 0; i < n; i++) memAry[i] = 1;
  for (i = 0; i < n; i++) listAry[i] = (int*)malloc(sizeof(int)*(ARRAY_SIZE+1));

  for (i = 0; i < q; i++) {
    scanf("%d %d",&com,&index);
    switch (com) {
      case 0:
        scanf("%d",&x);
        if (!insert(&listAry[index],&sizeAry[index],&memAry[index], x)) {
          terminate(listAry,sizeAry,memAry, n);
          return EXIT_FAILURE;
        }
        break;
      case 1:
        if (sizeAry[index] == 0) continue;
        printf("%d\n",listAry[index][1]);
        break;
      case 2:
        if (sizeAry[index] == 0) continue;
        deleteMax(listAry[index], &sizeAry[index]);
        break;
    }
  }

  terminate(listAry,sizeAry,memAry, n);

  return 0;
}


Measured memory_bytes: 2636
S = input()
N = len(S)
n=0
e=0
w=0
s=0
for i in range(N):
  if S[i]=='N': n+=1
  elif S[i]=='W': w+=1
  elif S[i]=='E': e+=1
  elif S[i]=='S': s+=1
ok = True
if n>0 and s==0: ok=False
elif n==0 and s>0: ok=False
elif w==0 and e>0: ok=False
elif w>0 and e==0: ok=False
if ok: print("Yes")
else: print("No")

Measured memory_bytes: 3064
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD = 1e9+7;

int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    ll K;
    cin >> K;

    ll N = 50;
    ll A[N];

    ll a = K / 50;
    ll b = K % 50;

    REP(i, N) A[i] = a;

    REP(i, N) {
        if (b - i - 1 >= 0) A[i] += 2 * N - b;
        else A[i] += N - b - 1;
    }

    cout << N << endl;
    REP(i, N) {
        if(i > 0) cout << " ";
        cout << A[i];
    }
    cout << endl;
    
}


Measured memory_bytes: 256
n = int(input())
data1 = [list(map(int,input().split())) for _ in range(n)]
data2 = [list(map(int,input().split())) for _ in range(n)]
ans = []
trans = -1
for i in range(2**10):
    S = [0]*n
    l = 0
    for j in range(10):
        for k in range(n):
            S[k] += data1[k][j]*((i>>j)&1)
    for j in range(n):
        l += data2[j][S[j]]
    ans.append(l)
    if not i:
        trans = l
ans.sort()
print(ans[-1] if ans[-1] != trans else ans[-2])

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

int main() {
  int n;
  cin >> n;
  vi p(n), q(n);
  rep(i,n) cin >> p[i];
  rep(i,n) cin >> q[i];
  
  vi a(n);
  rep(i,n) a[i] = i+1;
  
  int cnt = 0, A, B;
  do {
    if (p==a) A = cnt;
    if (q==a) B = cnt;
    cnt++;
  }while(next_permutation(a.begin(), a.end()));
  
  cout << abs(A-B) << endl;
}

Measured memory_bytes: 3592
#include<bits/stdc++.h>
using namespace std;
    int main(){
        string S;
            cin >> S;
                if(S == "Sunny"){
                    cout << "Cloudy" << endl;
                }else if(S == "Cloudy"){
                    cout << "Rainy" << endl;
                }else if(S == "Rainy"){
                    cout << "Sunny" << endl;
                }
        return 0;
    }

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

const int N = 5e5 + 11;
int cnt[N];
int a[N];
int ans[N];
int n, Q, block;
int sum = 0;

struct query {
  int l, r, id;
  bool operator < (const query &lhs) const {
    int block_a = l / block;
    int block_b = lhs.l / block;
    return block_a == block_b ? r < lhs.r : block_a < block_b;
  }
};

query q[N];

void add(int x) {
  x = a[x]; cnt[x]++;
  sum += (cnt[x] == 1);
}

void remove(int x) {
  x = a[x]; cnt[x]--;
  sum -= (cnt[x] == 0);
}

void MO() {
  block = 1000;
  sort(q, q + Q);
  int l = 0, r = -1;
  for (int i = 0; i < Q; i++) {
      while (l > q[i].l) add(--l);
      while (r < q[i].r) add(++r);
      while (r > q[i].r) remove(r--);
      while (l < q[i].l) remove(l++);
      ans[q[i].id] = sum;
  }
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(nullptr); cout.tie(nullptr);    

  cin >> n >> Q;
  for (int i = 0; i < n; i++) cin >> a[i];
  for (int i = 0; i < Q; i++) {
    cin >> q[i].l >> q[i].r;
    q[i].l--, q[i].r--, q[i].id = i;
  }
  MO();
  for (int i = 0; i < Q; i++) cout << ans[i] << endl;
}

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

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

    for(int i=a;i<=a*b;i+=a){
        if(i%b==c){
            cout<<"YES"<<endl;
            return 0;
        }
    }
    cout<<"NO"<<endl;
}

Measured memory_bytes: 256
def main():
	N, M = map(int, input().split())
	INF = 2*31-1
	to = [[] for _ in range(N)]
	for _ in range(M):
		u, v = map(int, input().split())
		to[u-1].append(v-1)
	dist = [[INF, INF, INF] for _ in range(N)]

	S, T = map(int, input().split())
	queue = []
	for pos in to[S-1]:
		queue.append([pos, 1])
		dist[pos][1] = 1
	while queue:
		pos, l = queue.pop(0)
		next_positions = to[pos]
		for next_pos in next_positions:
			nl = (l+1)%3
			if dist[next_pos][nl] != INF:
				continue
			dist[next_pos][nl] = dist[pos][l]+1
			queue.append([next_pos, nl])
	ans = dist[T-1][0]
	if ans == INF:
		print(-1)
	else:
		print(ans//3)

if __name__ == '__main__':
	main()

Measured memory_bytes: 37680
#include<bits/stdc++.h>
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
int main(){
    int n;
    cin>>n;
    int a[n];
    double sum=0;
    rep(i,n){
     cin>>a[i];
     sum+=a[i];
    }
    sum/=(double)n;
    long double diff=100000.0;
    int ans=0;
    rep(i,n) {
        if(abs((double)a[i]-sum)<diff){
            diff=fabs((double)a[i]-sum);
           // cout<<diff<<endl;
            ans=i;
        }
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
//https://blog.csdn.net/hesorchen
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <string>
#include <queue>
#include <stack>
#include <map>
#include <set>
using namespace std;
#define ll long long
#define endl "\n"
#define lowbit(a) (a & (-a))
#define INF 0x3f3f3f3f
#define MAX 1010
#define mod 1000000007
#define PI 3.1415926

int main()
{
    ll n, m;
    while (cin >> n >> m)
    {
        m = m * 2 + 1;
        if (n % m == 0)
            cout << n / m << endl;
        else
            cout << n / m + 1 << endl;
    }

    return 0;
}

Measured memory_bytes: 256
a,b = list(map(int,input().split()))
mat = []
for i in range(10):
  mat.append(list(map(int,input().split())))

xs = []
for i in range(a):
  xs += list(map(int,input().split()))

import heapq  
d_ans = [0]*10

for i in range(10):
  d = [3000 *20] * 10
  d[i] = 0
  h = []
  heapq.heappush(h,(d[i],i))
  #print(h)
  while not len(h) == 0:
    (di, v) = heapq.heappop(h)
    if v == 1:
      break
    for j in range(10):
      #print(i,j,di,v)
      if d[j] > d[v] + mat[v][j]:
        d[j] = d[v] + mat[v][j]
        heapq.heappush(h,(d[j],j))
  #print(d)
  d_ans[i] = d[1]

ans = 0
for x in xs:
  if x != -1:
    ans += d_ans[x]
print(ans)

Measured memory_bytes: 43100
#include <bits/stdc++.h>
using namespace std;
 
#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define forn(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pb push_back
 
 
// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";
 
// 'a' -> 97
// 'A' -> 65
void solve(){
	char c; cin >> c;
	if((int)(c-'a') < 0) cout << 'A';
	else cout << 'a';
}
 
int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
	return 0;
}
 


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

using namespace std;

int main() {
	int n,k; scanf("%d %d", &n, &k);
	int h[n];
	int dp[n];

	for(int i=0; i<n; i++)
		scanf("%d", &h[i]);

	dp[0] = 0;
	dp[1] = abs(h[1]-h[0]);

	for(int i=2; i<n; i++) {
		dp[i] = abs(h[i]-h[i-1]) + dp[i-1];
		for(int j=2; j<=min(k,i); j++)
			dp[i] = min(dp[i], abs(h[i]-h[i-j]) + dp[i-j]);
	}

	printf("%d\n", dp[n-1]);

	return 0;
}

Measured memory_bytes: 1024
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        // Your code here!
        Scanner sc = new Scanner(System.in);
        String str = sc.next();
        char[] seq = str.toCharArray();
        for(int i = 0; i < seq.length; i++){
            if(seq[i] == 'A'){
                seq[i] = 't';
            } else if(seq[i] == 'T'){
                seq[i] = 't';
            } else if(seq[i] == 'G'){
                seq[i] = 't';
            } else if(seq[i] == 'C'){
                seq[i] = 't';
            } else {
                seq[i] = 'f';
            }
        }
        
        int end = 0;
        int ans = 0;
        int tmp = 0;
        while(end < seq.length){
            if(seq[end] == 't'){
                end ++;
                tmp ++;
            } else{
                if(ans < tmp){
                    ans = tmp;
                }
                end++;
                tmp=0;
            }
        }
        if(ans < tmp){
            ans = tmp;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
N, K = map(int, input().split())
V = list(map(int, input().split()))

ans = -10**9
R = min(N, K)
A = R
for a in range(0, A+1):
    B = R-a
    for b in range(0, B+1):
        if b>0:
            v = V[:a] + V[-b:]
        else:
            v = V[:a]
        
        v.sort()
        
        cnt = 0
        for vv in v:
            if vv<0:
                cnt += 1
            else:
                break
        ans = max(ans, sum(v[min(K-a-b, cnt):]))
        
print(ans)

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

int main(){
  int n;
  cin >> n;
  double sum=0;
  for(int i=0; i<n; i++){
    int a;
    double b;
    cin >> a;
    b = 1.000000/a;
    sum += b;
  }
  
  cout << setprecision(10) << 1/sum << endl; 
}

Measured memory_bytes: 256
#include <iostream>

using namespace std;
int main(int argc, char const *argv[]) {
  cin.tie(0);
  ios::sync_with_stdio(false);
  int H, W, h, w;
  cin >> H;
  cin >> W;
  cin >> h;
  cin >> w;
  cout << H*W - W*h - H*w + h*w << "\n";
  return 0;
}

Measured memory_bytes: 256
n = int(input())
task = []
for i in range(n):
    a,b = map(int,input().split())
    task.append([b,a])
sorted_task = sorted(task)
#print(sorted_task)
isOK = True
ans = 0
for i in range(n):
    ans += sorted_task[i][1]
    #print(sorted_task[i][0],ans)
    if ans > sorted_task[i][0]:
        isOK = False
        break
if isOK:
    print('Yes')
else:
    print('No')

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

int main(){
  ll n;
  cin>>n;
  ll ans=0;
  for(ll i=1;i*i<n;i++){
    ll res=n/i-1;
    if(n%i==0&&n/res==n%res) ans+=res;
  }
  cout<<ans<<endl;
}

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

void dfs(const vector<vector<int>> &e, vector<bool> &v, int k, unordered_set<int> &f) {
  for (int i = 0; i < e[k].size(); i++)
    if (!v[e[k][i]]) {
      v[e[k][i]] = true;
      f.insert(e[k][i]);
      dfs(e, v, e[k][i], f);
    }
}

int main() {
  int n, m, k;
  scanf("%d %d %d", &n, &m, &k);
  vector<vector<int>> friends(n), friends_or_foes(n);
  for (int i = 0; i < m; i++) {
    int a, b;
    scanf("%d %d", &a, &b);
    
    friends[a - 1].emplace_back(b - 1);
    friends[b - 1].emplace_back(a - 1);
    friends_or_foes[a - 1].emplace_back(b - 1);
    friends_or_foes[b - 1].emplace_back(a - 1);
  }
  for (int i = 0; i < k; i++) {
    int c, d;
    scanf("%d %d", &c, &d);
    
    friends_or_foes[c - 1].emplace_back(d - 1);
    friends_or_foes[d - 1].emplace_back(c - 1);
  }

  vector<int> ans(n);
  vector<bool> v(n);
  for (int i = 0; i < n; i++)
    if (!v[i]) {
      unordered_set<int> f;
      dfs(friends, v, i, f);

      for (int j : f) {
        int count = 0;
        for (int k : friends_or_foes[j])
          if (f.count(k)) count++;
        ans[j] = f.size() - 1 - count;
      }
    }
  for (int i = 0; i < n; i++)
    printf("%d%c", ans[i], " \n"[i + 1 == ans.size()]);

  return 0;
}

Measured memory_bytes: 17848
#include<algorithm>
#include<cstring>
#include<cctype>
#include<cstdio>
#define rep(i,x,y) for(int i=x; i<=y; ++i)

using namespace std;
const int N=3005,mod=1000000007;
typedef long long LL;
char S[N];
int n,m,s[N],x[N],y[N],c[N][N],tot,l[N],r[N],maxn;
LL f[N][N];
struct data{int x,y;} dat[N];

int getint()
{
	char ch;
	int f=1;
	while(!isdigit(ch=getchar())) if(ch=='-') f=-1;
	int x=ch-48;
	while(isdigit(ch=getchar())) x=x*10+ch-48;
	return x*f;
}

bool cmp(data a,data b)
{
	return a.x==b.x?a.y>b.y:a.x<b.x;
}

int main()
{
	
	n=getint(),m=getint(),scanf("%s",S+1);
	rep(i,0,n) c[i][0]=c[i][i]=1;
	rep(i,1,n) rep(j,1,i-1) c[i][j]=(c[i-1][j]+c[i-1][j-1])%mod;
	rep(i,1,n) s[i]=s[i-1]+S[i]-48;
	rep(i,1,m) dat[i].x=getint(),dat[i].y=getint();
	sort(dat+1,dat+1+m,cmp);
	rep(i,1,m) if(dat[i].y>maxn) ++tot,x[tot]=dat[i].x,y[tot]=dat[i].y,maxn=dat[i].y;
	f[0][0]=1,x[tot+1]=y[tot+1]=n+1;
	rep(i,1,tot)
	{
		int w=min(y[i]-x[i]+1,x[i+1]-x[i]),a=s[y[i]]-s[max(x[i]-1,y[i-1])];
		l[i]=max(0,l[i-1]+a-w),r[i]=min(y[i]-x[i]+1,min(max(y[i]-x[i+1]+1,0),r[i-1]+a));
		rep(j,l[i],r[i])
			rep(k,max(l[i-1],-(a-j)),r[i-1])
			{
				if(k+a-j>w) break;
				f[i][j]=(f[i][j]+f[i-1][k]*c[w][k+a-j])%mod;
			}
	}
	printf("%lld\n",f[tot][0]);
	return 0;
}

Measured memory_bytes: 65408
N, X = map(int, input().split())
L = list(map(int, input().split()))
D = []
for i in range(N+1):
  if i == 0:
    D.append(0)
  else:
    D.append(D[i-1]+L[i-1])
count = [1 for i in D if i <= X]
print(len(count))

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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    int d;
    cin >> d;
    for (int i = 1; i < n; ++i) {
        int x;
        cin >> x;
        d = __gcd(x, d);
    }
    cout << d << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <string>
#include <cmath>
#include <cctype>
#include <cstdlib>
#include <stack>
#include <queue>
#include <vector>
#include <algorithm>
#include <list>
using namespace std;

int main() {
    string s;
    cin >> s; cout << s[0];
    cin >> s; cout << s[1];
    cin >> s; cout << s[2] << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll a, b, c;
    cin >> a >> b >> c;
    if (((a + b) == c) || ((a + c) == b) || ((b + c) == a)) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;


public class Main {

    static void solve() {
        Scanner scan = new Scanner(System.in);

        int n = scan.nextInt();
        int[] arr = new int[n];
        for (int i=0;i<n;i++) {
            arr[i] = scan.nextInt();
        }
        int cnt = 0;
        for (int i=0;i<arr.length;i++) {
            for (int j=i+1;j<arr.length;j++) {
                for (int t = j+1;t<arr.length;t++) {
                    if(isTr(arr[i], arr[j], arr[t])) {
                        cnt++;
                    }
                }
            }
        }
        System.out.println(cnt);

//        int t = scan.nextInt();
//        for (int i = 0; i < t; i++) {
//            int n = scan.nextInt();
//            int[] arr1 = new int[n];
//            for (int j = 0; j < n; j++) {
//                arr1[j] = scan.nextInt();
//            }
////            scase(n, arr1);
//        }


//        long t = scan.nextLong();

//        for (int i = 0; i < t; i++) {
//            int n = scan.nextInt();
////            scase(n);
//        }
    }

    static boolean isTr(long a, long b, long c) {
        if(a == b || a == c || b == c) {
            return false;
        }
        if (a + b <= c || a + c <= b || b + c <= a)
            return false;
        else
            return true;
    }


    static void solveCase(int t, int x, String s) {

    }

    static void scase(int[] arr1, int[] arr2) {
    }



    public static void main(String[] args) {
        solve();
    }


    static class LoggerNode {
        String message;
        int ts;
    }


    static class TreeNode {
        int val;
        TreeNode left;
        TreeNode right;

        TreeNode(int x) {
            val = x;
        }
    }

    static class ListNode {
        int val;
        ListNode next;

        ListNode() {
        }

        ListNode(int val) {
            this.val = val;
        }

        ListNode(int val, ListNode next) {
            this.val = val;
            this.next = next;
        }
    }
}

Measured memory_bytes: 27756
#include <iostream>
#include <climits>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <bits/stdc++.h>
 
using namespace std;
typedef long long ll;
 
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REP1(i,n) for(ll i=1;i<=(ll)(n);i++)
 
ll gcd(int a, int b)
{
   if (a%b == 0)
   {
       return(b);
   }
   else
   {
       return(gcd(b, a%b));
   }
}
 
ll lcm(int a, int b)
{
   return a * b / gcd(a, b);
}
 
ll power(ll a, ll n)
{
    if (n == 0)
        return 1;
    ll p = power(a, n / 2);
    p = (p * p);
    if (n % 2)
        return (p * a);
    else
        return p;
}
 
int main() {
    ios_base::sync_with_stdio(false);    //for fast I/O operation
    cin.tie(NULL);
 
    double n;
    cin >> n;
 
    cout << n * M_PI * 2 << endl;
}

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

int main(){
  string word;
  cin>>word;
  int count = 0;
  for(int i=0; i<word.size()/2; i++){
    if(word[i] != word[word.size()-i-1]){
      count+=1;
    }
  }
  cout << count;
}
  

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
 
using namespace std;
using namespace __gnu_pbds;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;
 
typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;
 
typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;
 
template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;
 
#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)
 
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()
 
const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001; //check the limits, dummy
 
int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
 
    ll L, R; cin >> L >> R;
    if ((L-1) / 2019 != R / 2019) {
        cout << 0 << endl; return 0;
    }
    L = L%2019 ; R = R % 2019;
    int ans = 2018;
    FOR(i, L, R+1) {
        FOR(j, i+1, R+1) {
            ans = min(ans, (i*j)%2019);
        }
    }
    cout << ans << endl;
 
    return 0;
}
 
// read the question correctly (ll vs int)
// template by bqi343

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

#define rep(i,N) for(int i=0;i<N;i++)
#define rep2(i,N) for(int i=1;i<=N;i++)
using namespace std;
long long  INF=1e18;
long long mod=1e9+7;

//status unsolved
int main(){
    string s;
    cin>>s;
    int nl=0;
    int nr=0;
    long long ans[s.size()]={};
    rep(i,s.size()-1){
        if(s[i]=='L')nl++;
        else{
            nr++;
        }
        if(s[i]=='R'&& s[i+1]=='L'){
            ans[i]+=(nr+1)/2;
            ans[i+1]+=nr/2;
            nr=0,nl=0;
        }
    }

    nr=0,nl=0;
    for(int i=s.size()-1;i>0;i--){
        if(s[i]=='L')nl++;
        else{
            nr++;
        }
        if(s[i-1]=='R'&& s[i]=='L'){
            ans[i]+=(nl+1)/2;
            ans[i-1]+=nl/2;
            nr=0,nl=0;
        }
    }

    rep(i,s.size()){
        cout<<ans[i]<<" ";
    }
    cout<<endl;
    return 0;

}
/*


*/


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

int main() {
    int N, K, num = 1;
    cin >> N >> K;

    for(int i = 0; i < N; i++){
        if(2 * num < num + K) num *= 2;
        else                  num += K;
    }

    cout << num << endl;
}


Measured memory_bytes: 3604
import           Control.Monad
import           Data.Array.ST
import           Data.Array.Unboxed

main :: IO ()
main = do
  n <- readLn :: IO Int
  hs <- listArray (1,n) . map read . words <$> getLine :: IO (UArray Int Int)
  let solve = solve2
  print $ solve hs n ! n

solve1 :: UArray Int Int -> Int -> UArray Int Int
solve1 hs n = runSTUArray $ do
  dp <- newArray (1,n) 0
  forM_ [2..n] $ \x ->
    if x == 2
    then writeArray dp 2 . abs $ (hs!2) - (hs!1)
    else do
      a <- liftM2 (+) (readArray dp (x-1)) (return . abs $ hs!x - hs!(x-1))
      b <- liftM2 (+) (readArray dp (x-2)) (return . abs $ hs!x - hs!(x-2))
      writeArray dp x $ min a b
  return dp

solve2 :: UArray Int Int -> Int -> UArray Int Int
solve2 hs n = runSTUArray $ do
  dp <- newArray (1,n) maxBound
  writeArray dp 1 0
  forM_ [1..(n-1)] $ \x ->
    if x == n-1
    then do
      a <- liftM2 (+) (readArray dp x) (return . abs $ hs!x - hs!(x+1))
      readArray dp n >>= writeArray dp n . min a
    else do
      a <- liftM2 (+) (readArray dp x) (return . abs $ hs!x - hs!(x+1))
      b <- liftM2 (+) (readArray dp x) (return . abs $ hs!x - hs!(x+2))
      readArray dp (x+1) >>= writeArray dp (x+1) . min a
      readArray dp (x+2) >>= writeArray dp (x+2) . min b
  return dp

Measured memory_bytes: 16764
#include <queue>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <algorithm>
#include <stack>
#include <string>
#include <vector>
#include <stdlib.h>
#include <map>
#include <stdio.h>
using namespace std;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define FOR(i, a, b) for(int i = (a); i < (int)(b); i++)
#define MAX(a, b) ((ll)(a) > (ll)(b)) ? (ll)(a) : (ll)(b)
#define MIN(a, b) ((ll)(a) > (ll)(b)) ? (ll)(b) : (ll)(a)

typedef long long ll;
typedef unsigned long long ull;
typedef vector<ll> vint;
typedef vector<string> vstr;
typedef pair<ll, ll> pint;
unsigned long long inf = (1LL << 62);
ll mod = 1000000007;
pint dx[4] = { {1, 0}, {-1, 0}, {0, 1}, {0, -1}};

ll min(ll a, ll b){
	if (a < b)
		return a;


		return b;
}


ll N;
vector<ll> A;

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

		return gcd(b, a % b);
	}


}


int main() {
	cin >> N;

	ll v;



	for(int h = 1; h <= 3500; h++) {
		for(int n = 1; n <= 3500; n++) {

			if (4 * h * n - N * n - N * h > 0) {
				ll a = gcd(4 * h * n - N * n - N * h, N * h * n);
				if (a == 4 * h * n - N * n - N * h) {

					cout << h << " " << n << " " << N * h * n / a << endl;

					return 0;
				}

			}

    	}
	}



	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
const int64_t MOD = 1000000007;
const int64_t MAXN = 100010;
int64_t dp[MAXN][2]; // i桁目, isLess?

int main()
{
  string L;
  cin >> L;
  dp[0][0] = 1;
  int64_t n = L.size();
  for (int i = 0; i < n; i++)
  { // a + b = 0
    if (L[i] == '0')
    {
      dp[i + 1][0] = dp[i][0];
      dp[i + 1][1] = dp[i][1];
    }
    else
    {
      dp[i + 1][1] = (dp[i][0] + dp[i][1]) % MOD;
    }
    if (L[i] == '0')
    {
      (dp[i + 1][1] += dp[i][1] * 2 % MOD) %= MOD;
    }
    else
    {
      (dp[i + 1][0] += dp[i][0] * 2 % MOD) %= MOD;
      (dp[i + 1][1] += dp[i][1] * 2 % MOD) %= MOD;
    }
  }
  int64_t ans = (dp[n][0] + dp[n][1]) % MOD;
  cout << ans << endl;
}


Measured memory_bytes: 5320
/*input
5
3 11 14 5 13
*/
#include <bits/stdc++.h>
#pragma GCC optimize("unroll-loops,no-stack-protector")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef pair<double,double> pdd;
#define IOS ios_base::sync_with_stdio(0); cin.tie(0)
#define ALL(a) a.begin(),a.end()
#define SZ(a) ((int)a.size())
#define F first
#define S second
#define REP(i,n) for(int i=0;i<((int)n);i++)
#define pb push_back
#define MP(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())
#ifdef leowang
#define debug(...) do{\
	fprintf(stderr,"%s - %d : (%s) = ",__PRETTY_FUNCTION__,__LINE__,#__VA_ARGS__);\
	_DO(__VA_ARGS__);\
}while(0)
template<typename I> void _DO(I&&x){cerr<<x<<endl;}
template<typename I,typename...T> void _DO(I&&x,T&&...tail){cerr<<x<<", ";_DO(tail...);}
#else
#define debug(...)
#endif
template<typename T1,typename T2>
ostream& operator<<(ostream& out,pair<T1,T2> P){
	out<<'('<<P.F<<','<<P.S<<')';
	return out;
}

//}}}
const ll maxn=300005;
const ll maxlg=__lg(maxn)+2;
const ll INF64=8000000000000000000LL;
const int INF=0x3f3f3f3f;
const ll MOD=ll(1e9+7);
const double PI=acos(-1);
//const ll p=880301;
//const ll P=31;

ll mypow(ll a,ll b){
	ll res=1LL;
	while(b){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		
		b>>=1;
	}
	return res;
}

multiset<ll> st;

ll go(ll n){
	int cur=1;
	while(cur<=n){
		cur<<=1;
	}
	return cur-n;
}
ll a[maxn];
int main()
{
	IOS;
	int n;
	cin>>n;
	REP(i,n) cin>>a[i];
	REP(i,n) st.insert(a[i]);

	int ans=0;
	while(SZ(st)){
		int cur=*prev(st.end());
		st.erase(prev(st.end()));
		int tmp=go(cur);
		if(st.count(tmp)){
			st.erase(st.lower_bound(tmp));
			ans++;
		}
	}
	cout<<ans<<'\n';
	return 0;
}


Measured memory_bytes: 11264
def main():
    N = int(input())
    S = list(input())
    R = []
    G = []
    B = []
    Reval = {}
    Geval = {}
    Beval = {}
    for i in range(N):
        if S[i] == "R":
            R.append(i)
            Reval[2*i] = 2*i
        elif S[i] == "G":
            G.append(i)
            Geval[2*i] = 2*i
        elif S[i] == "B":
            B.append(i)
            Beval[2*i] = 2*i
    count = len(R)*len(G)*len(B)

    for a in R:
        for b in G:
            if (a + b) in Beval:
                count -= 1
    for a in G:
        for b in B:
            if (a + b) in Reval:
                count -= 1
    for a in B:
        for b in R:
            if (a + b) in Geval:
                count -= 1
    print(count)

if __name__ == "__main__":
    main()


Measured memory_bytes: 9528
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#define MAX 20000

typedef struct {
  int data[MAX+2];
  int head, tail;
} Stack;

void init(Stack *st) {
  st->head = st->tail = 0;
}

void push(Stack *st, int x) {
  if(st->tail == MAX+2) return;
  st->data[(st->tail)++] = x;
}

int pop(Stack *st) {
  return st->data[--(st->tail)];
}

int empty(Stack *st) {
  return st->head == st->tail;
}

int size(Stack *st) {
  return st->tail - st->head;
}

int main() {
  char buf[MAX+2];
  int len, ans = 0;  
  Stack st1, st2, st3, st4;
  int cnt = 0;
  int i, j;
  
  scanf("%s", buf);
  len = strlen(buf);

  init(&st1);
  init(&st2);
  init(&st3);
  init(&st4);
  
  for(i = 0; i < len; i++) {
    if(buf[i] == '\\') {
      push(&st1, i);
    } else if(buf[i] == '/') {
      if(size(&st1) > 0) {
	int sum = 0;
	j = pop(&st1);
	ans += i - j;
	sum += i - j;
	while(size(&st2) > 0) {
	  int top2 = pop(&st2), top3 = pop(&st3);
	  if(top2 < j) {
	    push(&st2, top2);
	    push(&st3, top3);
	    break;
	  }
	  sum += top3;
	}
	push(&st2, j);
	push(&st3, sum);
      }
    }
  }
  while(size(&st3) > 0) {
    push(&st4, pop(&st3));
    cnt++;
  }
  printf("%d\n%d", ans, cnt);    
  for(i = 0; i < cnt; i++) {
    printf(" %d", pop(&st4));
  }
  puts("");
  
  return 0;
}

Measured memory_bytes: 660
/*dismint|jjc*/
#include <bits/stdc++.h>
using namespace std;
#define forl(V, S, E) for(int V = S; V < E; V++)
#define ford(V, S, E) for(int V = S; V >= E; V--)
#define fore(E, X) for(auto &E:X)
#define println(X) cout << X << endl
#define printe(X) for(auto &E:X) cout << E << " "; cout << endl
typedef unordered_map<int, unordered_set<int>> graph;
typedef long long ll;

const ll mx = 1000000000000000000;
int main() {
	ios_base::sync_with_stdio(false); cin.tie(NULL);
	int n; cin >> n;
	ll m = 1;
	bool good = true, zc = false;
	forl(i, 0, n) {
		ll a; cin >> a;
		if(!a) zc = true;
		m *= a;
		if(m > mx or m <= 0) good = false;
	}
	if(zc) println("0");
	else {
		if(good) println(m);
		else println("-1");
	}
}


Measured memory_bytes: 3656
#include<iostream>
using namespace std;
main(){
int a,b,c;
/*cout<<"Cost of playing the sound once: ";cin>>a;
cout<<"Money with Takahashi: ";cin>>b;
cout<<"Number of times sound to be played to satisfy Takahashi: ";cin>>c;*/
cin>>a>>b>>c;
if((c*a)<=b)cout<<c;
else cout<<b/a;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdint>
#include <cctype>
#include <string>
#include <stdexcept>
#include <vector>
#include <algorithm>
#include <stack>
#include <iostream>
#include <map>

size_t parse(
    const std::string& s,
    const std::map<char, std::map<size_t, size_t>>& arrs) {

  std::stack<char> st;
  size_t idx=-1, pos;
  for (pos=0; isalpha(s[pos]); pos+=2) {
    st.push(s[pos]);
  }
  sscanf(s.substr(pos).c_str(), "%zu", &idx);
  while (!st.empty()) {
    char ch=st.top();
    st.pop();
    idx = arrs.at(ch).at(idx);
  }
  return idx;
}

void parse_line(
    const std::string& s, std::map<char, size_t>& lens,
    std::map<char, std::map<size_t, size_t>>& arrs) {

  size_t eq=s.find('=');
  if (eq != std::string::npos) {
    /* assignment */
    char name=s[0];
    size_t size=lens.at(name);
    size_t index=parse(std::string(s.begin()+2, s.begin()+eq), arrs);
    if (size <= index) throw std::out_of_range("");
    size_t value=parse(s.substr(eq+1), arrs);
    arrs[name][index] = value;
  } else {
    /* declaration */
    char name;
    size_t size;
    sscanf(s.c_str(), "%c[%zu]", &name, &size);
    lens[name] = size;
  }
}

int testcase_ends() {
  std::string s;
  std::cin >> s;
  if (s == ".") return 1;

  std::map<char, size_t> lens;
  std::map<char, std::map<size_t, size_t>> arrs;
  int line=1;
  while (s != ".") {
    try {
      parse_line(s, lens, arrs);
    } catch (std::out_of_range& e) {
      std::cout << line << std::endl;
      while (s != ".") std::cin >> s;
      return 0;
    }
    ++line;
    std::cin >> s;
  }
  std::cout << "0\n";
  return 0;
}

int main() {
  while (!testcase_ends()) {}
}



Measured memory_bytes: 3484
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i=0;i<static_cast<int>(n);++i)
#define per(i, n) for(int i=static_cast<int>(n)-1;i>=0;--i)
#define eee(a) (cerr<<"[@"<<__LINE__<<"] "<<(#a)<<": "<<(a)<<'\n');
#define ppp(a) (cout<<(a)<<'\n'); 
#define cop(a) for(auto x:(a)){cerr<<(x)<<'\n';}
using ll = long long;
constexpr int dx[4]={1,0,-1,0};
constexpr int dy[4]={0,1,0,-1};
constexpr ll MOD = 1e9+7;
constexpr ll Mod = 998244353;
constexpr int INF = 1e9;
constexpr ll LINF = 1e18;
constexpr double phi = (1+sqrt(5))/2;
constexpr double pi = 3.14159265358979323846264338327950288;
inline ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
inline ll lcm(ll a,ll b){return a/gcd(a,b)*b;}
inline ll inverse(ll n,ll m=MOD){ll a=n,b=m,x=1,y=0;while(b){ll t=a/b;a-=t*b;swap(a,b);x-=t*y;swap(x,y);}return (a%m+m)%m;}
inline void Yes(){puts("Yes");}
inline void No(){puts("No");}
inline void Judge(bool b){b?Yes():No();}
inline void YES(){puts("YES");}
inline void NO(){puts("NO");}
inline void JUDGE(bool b){b?YES():NO();}
inline ll powmod(ll b, ll e, ll m=MOD){ll r=1;while(e>0){if(e&1)r=(r%m)*(b%m)%m;b=(b%m)*(b%m)%m;e>>=1;}return r;}
inline double distance(ll x1, ll y1, ll x2, ll y2){return sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));}
inline double d2r(double d){return d*pi/180;}
inline double r2d(double r){return r*180/pi;}
template<class T>inline bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>inline bool chmin(T &a, const T &b){if(b<a){a=b;return 1;}return 0;}
template<typename T>inline int bs(int g,int k,T c){while(abs(k-g)>1){int m=(g+k)/2;(c(m)?k:g)=m;}return k;}
template<typename T1,typename T2>ostream& operator<<(ostream& s,const pair<T1, T2>& p){return s <<"("<<p.first<<", "<<p.second<<")";}
template<typename T> ostream& operator<<(ostream& s,const vector<T>& v){s<<'[';for(size_t i=0;i<v.size();++i){s<<v[i];if(i<v.size()-1)s<<", ";}s<<']';return s;}
template<typename T> istream& operator>>(istream& s,vector<T>& v){for(T& x:v)s>>x;return s;}

int dp[3010][3010];
int main(){
    cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(15);
    
    string s, t;
    cin >> s >> t;

    string ans = "";

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

    int i = s.size(), j = t.size();
    while(i > 0 and j > 0){
        if(dp[i][j] == dp[i-1][j]){
            --i;
        }
        else if(dp[i][j] == dp[i][j-1]) {
            --j;
        }
        else{
            ans = s[i-1] + ans;
            --i; --j;
        } 
    }
    cout << ans << '\n';

    

    
    return 0;
}


Measured memory_bytes: 35584
import java.util.*
import java.math.*
import java.lang.Math.*


private val readString: ()->String = {readLine()!!}
private val readInt: ()->Int = { readLine()!!.toInt() }
private val readLong: ()->Long = { readLine()!!.toLong() }
private val readListInt: ()->List<Int> = { readLine()!!.split(' ').map(String::toInt) }
private val readListLong: ()->List<Long> = { readLine()!!.split(' ').map(String::toLong) }
private val errPrintln: (String)->Unit = { msg -> System.err.println(msg) }


data class Position(var x: Int, var y: Int)

fun solveA(G: Array<String>): Int {
    val H = G.size
    val W = G[0].length
    val INF = Int.MAX_VALUE / 2
    val step = Array(H) { IntArray(W) }
    val starts = ArrayList<Position>()
    for (i in 0 until H) {
        for (j in 0 until W) {
            step[i][j] = INF
            if (G[i][j] == '#') {
                starts.add(Position(i, j))
            }
        }
    }
    val dx = intArrayOf(0, 1, 0, -1)
    val dy = intArrayOf(1, 0, -1, 0)
    val que = ArrayDeque<Position>()
    for (i in starts.indices) {
        que.addLast(starts[i])
        step[starts[i].x][starts[i].y] = 0
    }
    var res = 0
    while (!que.isEmpty()) {
        val pos = que.removeFirst()
        val x = pos.x
        val y = pos.y
        for (i in dx.indices) {
            val nx = x + dx[i]
            val ny = y + dy[i]
            if (nx < 0 || H <= nx || ny < 0 || W <= ny) {
                continue
            }
            if (step[nx][ny] > step[x][y] + 1) {
                step[nx][ny] = step[x][y] + 1
                que.addLast(Position(nx, ny))
                res = max(res, step[nx][ny])
            }
        }
    }
    return res
}


fun main(args: Array<String>) {
    val (H, W) = readListInt()
    val A = Array<String>(H){""}
    for (i in 0 until H) {
        A[i] = readString()
    }

    val ans = solveA(A)

    println(ans)
}


Measured memory_bytes: 91556
#include <iostream>
using namespace std;
#define MAX 21

string str[MAX];
int n,m,cnt,dx[4] = {1,0,-1,0},dy[4] = {0,1,0,-1};

void dfs(int x,int y){
  str[x][y] = '#';

  for(int i = 0 ; i < 4 ; i++){
    int nx = x + dx[i] , ny = y + dy[i];
    if(0 <= nx && nx < m && 0 <= ny && ny < n){
      if(str[nx][ny] == '.'){
	cnt++;
	dfs(nx,ny);
      }
    }
  }

  return;
}

int main(){
  while(cin >> n >> m , n + m){
    for(int i = 0 ; i < m ; i++)
      cin >> str[i];
    
    int x,y;
    for(int i = 0 ; i < n ; i++){
      for(int j = 0 ; j < m ; j++){
	if(str[j][i] == '@'){
	  x = j;
	  y = i;
	  break;
	}
      }
    }
    cnt = 1;
    dfs(x,y);
    cout << cnt << endl;

  }

  return 0;
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
#define rep(i,f,n) for(ll i=(f); (i) < (n); i++)
#define repe(i,f,n) for(ll i=(f); (i) <= (n); i++)
using namespace std;
using ll = long long;
#define MOD (ll)1000000007
#define PI 3.14159265359
#define debug(x) cout<<#x<<" :: "<<x<<"\n";
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\n";
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<"\n";
#define P pair<int, int>
#define Pl pair<ll, ll>
#define dvec vector<vector<ll>>
//printf("%.10f\n")
//cout << fixed << setprecision(10);
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;}
ll INF = 1e+18;
int iINF = 1e9;


int main()
{
  int N; cin >> N;
  vector<ll> arr(N);
  rep(i, 0, N) cin >> arr[i];
  sort(arr.begin(), arr.end(), greater<ll>());
  ll ans = arr[0];
  int index = 1;

  rep(i, 0, N - 2){
    if(i % 2 == 0 && i != 0) ++index;
    ans += arr[index];
  }

  cout << ans << endl;
}


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

typedef long long ll;
typedef long double ld;

#define imx INT_MAX
#define imn INT_MIN
#define llmx LLONG_MAX
#define llmn LLONG_MIN

#define fi first
#define se second
#define pb push_back
#define f_s(a) sort(a.begin(), a.end())
#define b_s(a) sort(a.rbegin(), a.rend())
#define p(a) cout<<a<<"\n"


// ll mod = 1000000007;
// #define l(i, )
// #define rl(i, a, b) for(int i = a; i < b; i++)

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


ll extended_gcd(ll a, ll b, ll& x, ll& y)
{
	if(b==0)
	{
		x=1;
		y=0;
		return a;
	}
	ll x1, y1;
	ll d = extended_gcd(b, a%b, x1, y1);
	x=y1;
	y=x1-y1*(a/b);
	return d;
}

////////////////////SIEVE OF ERATOSTHENES//////////////////////
vector<int> sieveoferatosthenes(int n)
{
	vector<bool> prime(n+1, true);
	for(int i = 2; i <= sqrt(n); i++)
	{
		if(prime[i])
		{
			for(int j = i*i; j<=n; j+=i)
			{
				prime[j]=false;
			}
		}
	}
	vector<int> all_primes;
	for(int i = 2; i <=n; i++)
	{
		if(prime[i]) all_primes.pb(i);
	}
	return all_primes;
}

////////////////////BINARY EXPONENTIATION///////////////////////
ll bin_exp(ll a, ll b, ll mod)
{
	ll ans = 1;
	while(b)
	{
		if(b%2)
		{
			b--;
			ans = (ans%mod*a%mod)%mod;
		}
		b/=2;
		a = (a%mod*a%mod)%mod;
	}
	return ans;
}

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	int n, f=0, x;
	cin>>n;
	map<int, int> count;
	for(int i = 0; i < n; i++)
	{
		cin>>x;
		count[x]++;
	}
	for(auto i:count)
	{
		// cout<<i.second<<endl;
		if(i.second>1)
		{
			f=1;
			break;
		}
	}
	if(f) cout<<"NO"<<endl;
	else cout<<"YES"<<endl;
}

Measured memory_bytes: 9600
#include <iostream>
#include <vector>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <algorithm>
#include <string>
#include <math.h>
#include <limits.h>
#include <stack>
#include <complex>

using namespace std;

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

#define MAX_N 160000
int par[MAX_N];
int myrank[MAX_N];

void init(int n){
    for(int i = 0; i < n; i++){
        par[i] = i;
        myrank[i] = 0;
    }
}

//木の根を求める
int find(int x){
    if(par[x] == x){
        return x;
    }
    else{
        return par[x] = find(par[x]);
    }
}

// xとyの属する集合を併合
void unite(int x, int y){
    x = find(x);
    y = find(y);
    if(x == y)  return;

    if(myrank[x] < myrank[y]){
        par[x] = y;
    }
    else{
        par[y] = x;
        if(myrank[x] == myrank[y])  myrank[x]++;
    }
}

//xとyが同じ集合に属するかどうか
bool same(int x, int y) {
    return find(x) == find(y);
}

int s[400][400];

int main(){
    int h, w;   cin >> h >> w;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++) {
            char c; cin >> c;
            if(c == '.'){
                s[i][j] = 0;
            }
            else{
                s[i][j] = 1;
            }
        }
    }

    init(h*w);
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(i+1 < h && s[i][j] + s[i+1][j] == 1){
                int num1 = i * w + j, num2 = (i+1)*w + j;
                unite(num1, num2);
            }
            if(j+1 < w && s[i][j] + s[i][j+1] == 1){
                int num1 = i * w + j, num2 = (i)*w + j+1;
                unite(num1, num2);
            }
        }
    }

    map<int, P> m;
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            int num = i * w + j;
            int r = find(num);
            if(m.find(r) == m.end()){
                P v;
                v.first = s[i][j]; v.second = 1 - s[i][j];
                m[r] = v;
            }
            else{
                P v = m[r];
                v.first += s[i][j];
                v.second += 1 - s[i][j];
                m[r] = v;
            }
        }
    }

    ll res = 0;
    for(auto it = m.begin(); it != m.end(); it = next(it, 1)){
        P v = it->second;
        // cout << it->first << " " << v.first * v.second << endl;
        res += (v.first * v.second);
    }
    cout << res << endl;

    return 0;

}



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

using namespace std;

template <class TH> void _dbg(const char *sdbg, TH h){cerr<<sdbg<<"="<<h<<"\n";}
template<class TH, class... TA> void _dbg(const char *sdbg, TH h, TA... a) {
  while(*sdbg!=',')
    cerr<<*sdbg++;
  cerr<<"="<<h<<","; 
  _dbg(sdbg+1, a...);
}

template<class T> ostream & operator<<(ostream & os, vector<T> V){
  os<<"[";
  for(auto vv: V) os << vv <<",";
  return os << "]";
}
template<class L, class R> ostream & operator <<(ostream & os, pair<L,R> P){
  return os <<"("<<P.first <<","<<P.second <<")";
}

#ifdef DEBUG
#define debug(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
#else
#define debug(...) (__VA_ARGS__)
#define cerr if(0)cout
#endif

int main() {
    
    string s;
    cin >> s;
    bool good = s[2] == s[3] && s[4] == s[5];
    cout << (good ? "Yes\n" : "No\n") << endl;
    
    return 0;
}


Measured memory_bytes: 256