akhauriyash/Code-Regression huggingface dataset:
// ref. https://img.atcoder.jp/arc094/editorial.pdf

#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <unordered_map>
#include <vector>
#include <string.h>
#include <set>

using namespace std;

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl

template<class T> void printvec(const vector<T>& v) {
  for (auto x : v) { cout << x << " "; }
  cout << endl;
}
template<class T> void printtree(const vector< vector<T> >& tree) {
  for (long long i = 0; i < tree.size(); ++i) {
    cout << i + 1 << ": "; printvec(tree[i]);
  }
}
template<class T, class U> void printmap(const map<T, U>& mp) {
  for (auto x : mp) { cout << x.first << "=>" << x.second << endl; }
}

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 < n; ++i)
#define all(s) s.begin(), s.end()
#define fr first
#define sc second
#define mp make_pair
#define pb push_back

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> triple;
typedef double D;

const ll INF = 1e9;
const ll MOD = 1000000007;  // 1e9 + 7

int main(int argc, char** argv) {
  cin.tie(NULL);
  cout.tie(NULL);
  ios_base::sync_with_stdio(false);
  //cout << setprecision(10) << fixed;

  ll n;
  cin >> n;

  bool same = true;
  ll minB = INF;
  ll sum = 0;
  rep(i, n) {
    ll a, b;
    cin >> a >> b;

    if (a != b) {
      same = false;
    }
    if (a > b) {
      minB = min(minB, b);
    }
    sum += a;
  }
  if (same) {
    cout << 0 << endl;
  } else {
    cout << sum - minB << endl;
  }
}


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

#define INF 100000000001
#define INFS 1000000
#define PI 3.141592653589793238

int main() {
    int n;
    cin >> n;
    cout << n+n*n+n*n*n << endl;


    return 0;
}

Measured memory_bytes: 3620
def solve():
	N,K = map(int,raw_input().split())
	P = [0]*26
	for i in xrange(N):
		P[ord(raw_input()[0])-65] += 1
	P.sort()
	ans = 0
	for i in xrange(N):
		pos = 25
		cnt = K
		while pos >= 0:
			if cnt == 0:
				ans += 1
				break
			if P[pos] > 0:
				P[pos] -= 1
				cnt -= 1
			pos -= 1
		else:
			return ans
		P.sort()
	return ans
print solve()

Measured memory_bytes: 13936
main=do
 s<-getLine
 putStrLn$if f s 0 then"YES"else"NO"
f[]i=i>=8
f s@(c:d) i
 |i==0=if c=='A' then f d(i+1)else f s(i+1)
 |i==1=if c=='K' then f d(i+1)else False
 |i==2=if c=='I' then f d(i+1)else False
 |i==3=if c=='H' then f d(i+1)else False
 |i==4=if c=='A' then f d(i+1)else f s(i+1)
 |i==5=if c=='B' then f d(i+1)else False
 |i==6=if c=='A' then f d(i+1)else f s(i+1)
 |i==7=if c=='R' then f d(i+1)else False
 |i==8=if c=='A' then f d(i+1)else f s(i+1)
 |i==9=False

Measured memory_bytes: 380
N,a,b = map(int,input().split())
MOD = 10**9 + 7
c = pow(2,N,MOD) - 1
 
def comb(n,k):
    fac,finv = 1,1
    for i in range(k):
        fac = fac*(n-i)%MOD
        finv = finv*(i+1)%MOD
    return fac * pow(finv,MOD-2,MOD) % MOD

print((c - comb(N,a) - comb(N,b)) % MOD)

Measured memory_bytes: 3064
import sys
from fractions import gcd


def input():
    return sys.stdin.readline().strip()


sys.setrecursionlimit(10 ** 9)


def main():
    N, M = map(int, input().split())
    S = input()
    T = input()
    g = gcd(M, N)
    n = N // g
    m = M // g
    s = []
    t = []
    for i in range(N):
        if i % n == 0:
            s.append(S[i])
    for j in range(M):
        if j % m == 0:
            t.append(T[j])
    for x, y in zip(s, t):
        if x != y:
            print(-1)
            return
    print(M * N // g)


if __name__ == "__main__":
    main()


Measured memory_bytes: 5820
sums = 0
k = []
for i in range(5):
  g = int(input())
  if g%10 != 0:
      sums += g + 10 - g%10
      k.append(g%10)
  else:
      sums += g
      k.append(11)
j = min(k)
if j != 11:
    print(sums - 10 + j)
else:
    print(sums)

Measured memory_bytes: 3060
#include <cstdio>
#include <algorithm>
#include <queue>
#include <vector>
#include <utility>
#include <stdexcept>

struct Person {
  int id, t, h;
  Person(int id, int t, int h): id(id), t(t), h(h) {}
};

struct Machine {
  int T, H, L;
  int S=0;
  Machine(int T, int H, int L): T(T), H(H), L(L) {}
  std::pair<int, int> add(int x) {
    if (x == 10) {
      ++T;
      S += 10;
      if (T > L) throw 1;
    } else if (x == 100) {
      ++H;
      S += 100;
    }
    
    if (S >= 90) {
      S -= 90;
      std::pair<int, int> res;
      while (T > 0 && S > 0) {
        S -= 10;
        --T;
        ++res.first;
      }
      // if (H > 0 && S > 90) {
      //   S -= 100;
      //   --H;
      //   ++res.second;
      // }
      if (S > 0) throw 2;
      return res;
    }

    return {0, 0};
  }
};

int main() {
  int N, T, H, L;
  scanf("%d %d %d %d", &N, &T, &H, &L);

  std::queue<Person> q;
  for (int i=0; i<N; ++i) {
    int t, h;
    scanf("%d %d", &t, &h);
    q.emplace(i+1, t, h);
  }

  Machine m(T, H, L);
  while (true) {
    int id=q.front().id;
    int t=q.front().t, h=q.front().h;
    q.pop();
    //fprintf(stderr, "%d %d %d (%d)\n", id, t, h, m.S);

    try {
      std::pair<int, int> back;
      if (t > 0) {
        --t;
        back = m.add(10);
      } else if (h > 0) {
        --h;
        back = m.add(100);
      } else {
        printf("%d\n", id);
        break;
      }
      t += back.first;
      h += back.second;
      q.emplace(id, t, h);
    } catch (int) {
      printf("%d\n", id);
      break;
    }
  }
}



Measured memory_bytes: 2784
#include <iostream>
#include <vector>
#include <string>
#include <cstdlib>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <stack>
#include <math.h>
#define rep(i, n) for(int i = 0; i < (n); ++i)

// int H[N]; rep(i,N) scanf("%d", &H[i]);
// int max_x = *std::max_element(x.begin(), x.end());
// int min_y = *std::min_element(y.begin(), y.end());
using namespace std;

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

int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
const long long INF = 1LL << 60;
// spring s; cin >> s;
// cout << res << endl;
// --------write my code!!!!!----------//

// I'm trying to ~~~
int main(){
    long A; cin>>A;
    char op; cin>>op;
    long B; cin>>B;
    
    if(op=='+') cout << A+B << endl;
    else cout << A-B << endl;
    
}



Measured memory_bytes: 256
#include <assert.h>
#include <limits.h>
#include <algorithm>
#include <bitset>
#include <cctype>
#include <cmath>
#include <complex>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

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

template <typename T1, typename T2>
std::ostream& operator<<(std::ostream& os, std::pair<T1, T2> pa) {
  return os << "[" << pa.first << ", " << pa.second << "]";
}

template <typename T>
std::ostream& operator<<(std::ostream& os, std::vector<T> vec) {
  os << "{";
  for (int i = 0; i < vec.size(); i++)
    os << vec[i] << (i + 1 == vec.size() ? "" : ", ");
  os << "}";
  return os;
}

#define rep(i, a, b) for (ll(i) = (a); i < (b); i++)
#define all(i) i.begin(), i.end()
#define debug(i) std::cerr << "debug " << i << std::endl

// const ll MOD = 998244353;
const ll MOD = 1e9 + 7;

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

  ll n;
  std::cin>>n;

  ll odd=(n+1)/2;

  std::cout<<std::setprecision(10)<<std::fixed<<(double)odd/(double)n;

  return 0;
}

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


signed main() {
    int n;
    cin >> n;
    vi h(n);
    rep(i, n) cin >> h[i];
    int tmpmax = 0;
    bool isok = true;
    rep(i, n){
        tmpmax = max(tmpmax, h[i]);
        if(h[i]<tmpmax-1) isok = false;
    }

    if(isok) cout << "Yes";
    else cout << "No";
}

Measured memory_bytes: 4056
#include<bits/stdc++.h>
using namespace std;
#define rep(i,n); for(int i = 0;i < (int)(n);i++)
#define all(x) (x).begin(),(x).end()
typedef long long ll;
ll lucas(ll n){
    if(n == 0)return 2;
    else if(n == 1)return 1;
    else return lucas(n-1)+lucas(n-2);
}

int main(){
    int h,w;
    cin >> h >> w;
    vector<vector<char>> data(h,vector<char>(w));
    rep(i,h){rep(j,w){cin >> data[i][j];}}
    rep(i,h+2){
        rep(j,w+2){
            if(i == 0 || i == h+1)cout << "#";
            else if(j == 0 || j == w+1)cout << "#";
            else cout << data[i-1][j-1];
            if(j == w+1)cout << endl;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
#define chmin(a, b) ((a)=min((a), (b)))
#define chmax(a, b) ((a)=max((a), (b)))
#define fs first
#define sc second
#define eb emplace_back
using namespace std;

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

const ll MOD=1e9+7;
const ll INF=1e18;
const double pi=acos(-1);
const double eps=1e-10;

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

int main(){
    while(1){
        int sx, sy; cin>>sx>>sy;
        if(sx == 0 && sy == 0) return 0;

        vector<vector<int>> bo(10, vector<int>(10));
        int n; cin>>n;
        vector<int> x(n), y(n);
        for(int i=0; i<n; i++) cin>>x[i]>>y[i];

        queue<P> que;
        que.push(P(sy, sx));
        for(int i=0; i<n; i++){
            int queSize = (int)que.size();
            while(queSize--){
                int cy, cx;
                tie(cy, cx) = que.front();
                que.pop();

                for(int j=0; j<12; j++){
                    int ny = cy + dy[j];
                    int nx = cx + dx[j];

                    if(0 <= ny && ny < 10 && 0 <= nx && nx < 10){
                        if(abs(ny - y[i]) <= 1 && abs(nx - x[i]) <= 1){
                            que.push(P(ny, nx));
                        }
                    }
                }
            }
        }

        if(que.size()) cout << "OK" << endl;
        else cout << "NA" << endl;
    }
}


Measured memory_bytes: 3160
#include <bits/stdc++.h>
#define IOS             ios::sync_with_stdio(false); cin.tie(nullptr)
#define deb(x)          cout << #x << " = " << x << endl
#define deb2(x, y)      cout << #x << " = " << x << ", " << #y << " = " << y << endl
#define f0(i, a, n)     for(i = a; i < n; i++)
#define f1(i, a, n)     for(i = a; i <= n; i++)
#define tc(t)           int t; cin >> t; while(t--)
#define ini(x, y)       memset(x, y, sizeof(x))
#define all(x)          x.begin(),x.end()
#define sz(x)           x.size()
#define ll              long long int
#define vi              vector<int>
#define si              set<int>
#define pb              emplace_back
#define ppb             pop_back
#define mp              make_pair
#define M               1000000007
#define endl            '\n'
#define bits(x)         __builtin_popcountll(x)
#define zrbits(x)       __builtin_ctzll(x)

using namespace std;

void solve() {
    ll n, i, sum = 0, mx;
    cin >> n;
    ll a[n];
    f0(i, 0, n) cin >> a[i];
    mx = a[0];
    f0(i, 0, n) {
            if(mx >= a[i]) sum += mx - a[i];
            else mx = a[i];
    }
    cout << sum << endl;
}

int main () {
    IOS;
    // tc(t)
    solve();
    return 0;
}

Measured memory_bytes: 5176
N = gets.to_i
a = Array.new
2.times do
  a.push(gets.split(' ').map(&:to_i))
end

b = Array.new(N)
N.times do |i|
  b[i] = a[0][0..i].inject(:+) + a[1][i..N-1].inject(:+)
end

p b.max

Measured memory_bytes: 1788
//
// Created on 2020/01/26.
//

//#include <bits/stdc++.h>
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <math.h>
#include <ios>
#include <iomanip>
#include <numeric>

#define all(x) (x).begin(),(x).end()
typedef long long ll;
using namespace std;
const long long LINF =1e18;
const int INF = 1e9;
using gragh = vector<vector<int>>;

int main() {
    ll ans;
    int n;
    int k;
    cin>>n>>k;
    vector<int>h(n);
    for (int i = 0; i < n; ++i) {
        cin>>h[i];
    }
    sort(all(h));
    reverse(all(h));

    if(k>= n){
        ans = 0;
        cout<<ans<<endl;
        return 0;
    }
    ans = 0;
    for (int j = k; j < n; ++j) {
        ans += h[j];
    }

    cout<<ans<<endl;
}


Measured memory_bytes: 1024
/*input
3
500 300 200
*/
#include<bits/stdc++.h>
#define int long long
#define MOD 1000000007
#define MAX 100005
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#define mii map<int,int>
#define vi vector<int>
#define ff first
#define ss second
#define T int t;cin>>t;while(t--)
#define ld long double
using namespace std;

signed main(){
	int n;
	cin>>n;
	priority_queue<ld,vector<ld>,greater<ld> >pq;
	while(n--){
		ld x;
		cin>>x;
		pq.push(x);
	}
	while(!pq.empty()){
		ld x = pq.top();
		pq.pop();
		if(pq.empty()){
			cout<<x<<"\n";
			break;
		}
		ld y = pq.top();
		pq.pop();
		pq.push((x+y)/(ld)2);
	}
    return 0;
}


Measured memory_bytes: 256
n=int(input())
k=int(input())

if n<10:
    if k==0:
        print(1)
    elif k==1:
        print(n)
    else:
        print(0)
    exit()

#10
#0の数は高々3つまでなので、jは0,1,2,3の配列だけ持てば良い
#i桁目までは高々100
#
#dp[i][j][smaller]=

lenn=len(str(n))

dp=[[[0]*2 for _ in range(4)]  for _ in range(lenn)]
#smallerは、0：:通常、1:未満の2パターン

if int(str(n)[0])==1:
    dp[0][0][0]=1
    dp[0][1][1]=1
else:
    dp[0][0][0]=1
    dp[0][1][0]=int(str(n)[0])-1
    dp[0][1][1]=1

#print(dp)

for i in range(lenn-1):
    dp[i+1][0][0]+=dp[i][0][0]
    dp[i+1][1][0]+=dp[i][0][0]*9+dp[i][1][0] #+dp[i][0][1]*max(0,(int(str(n)[i])-1))
    dp[i+1][2][0]+=dp[i][1][0]*9+dp[i][2][0] #+dp[i][1][1]*max(0,(int(str(n)[i])-1))
    dp[i+1][3][0]+=dp[i][2][0]*9+dp[i][3][0] #+dp[i][2][1]*max(0,(int(str(n)[i])-1))
    #print(dp)
    if int(str(n)[i+1])==0:
        dp[i+1][0][1]+=dp[i][0][1]
        dp[i+1][1][1]+=dp[i][1][1]
        dp[i+1][2][1]+=dp[i][2][1]
        dp[i+1][3][1]+=dp[i][3][1]

    elif int(str(n)[i+1])==1:
        dp[i+1][1][1]+=dp[i][0][1]
        dp[i+1][2][1]+=dp[i][1][1]
        dp[i+1][3][1]+=dp[i][2][1]

        dp[i+1][1][0]+=dp[i][1][1]
        dp[i+1][2][0]+=dp[i][2][1]
        dp[i+1][3][0]+=dp[i][3][1]
    else:
        dp[i+1][1][1]+=dp[i][0][1]
        dp[i+1][2][1]+=dp[i][1][1]
        dp[i+1][3][1]+=dp[i][2][1]

        dp[i+1][1][0]+=dp[i][1][1]
        dp[i+1][2][0]+=dp[i][2][1]
        dp[i+1][3][0]+=dp[i][3][1]

        dp[i+1][1][0]+=dp[i][0][1]*(int(str(n)[i+1])-1)
        dp[i+1][2][0]+=dp[i][1][1]*(int(str(n)[i+1])-1)
        dp[i+1][3][0]+=dp[i][2][1]*(int(str(n)[i+1])-1)
    #print(dp)

print(sum(dp[-1][k]))

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

int main() {
	int a, b, k,max,min,count=0;
	cin >> a >> b >> k;
	if (a < b) {
		max = b;
		min = a;
	}
	else {
		max = a;
		min = b;
	}
	for (int loop = min; 0< loop; loop--) {
		if (a%loop == 0 && b%loop == 0) {
			count++;
			if (count == k) {
				cout << loop << endl;
			}
		}
	}
}
//K番目に「大きい」もの、小さいもの順ではない

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

using namespace std;

int main() {
	vector< vector< vector<int> > > data(31);
	for (int i = 1; i <= 30; i++) {
		vector<int> d;
		d.push_back(i);
		data[i].push_back(d);
		for (int j = i-1; j > 0; j--) {
			for (int k = 0; k < data[i-j].size(); k++) {
				d.clear();
				d.push_back(j);
				if (data[i-j][k][0] <= j) {
					d.insert(d.end(), data[i-j][k].begin(), data[i-j][k].end());
					data[i].push_back(d);
				}
			}
		}
	}
	int n;
	while (cin >> n) {
		if (n == 0) {
			break;
		}
		for (int i = 0; i < data[n].size(); i++) {
			cout << data[n][i][0];
			for (int j = 1; j < data[n][i].size(); j++) {
				cout << ' ' << data[n][i][j];
			}
			cout << endl;
		}
	}
	return 0;
}

Measured memory_bytes: 3404
using System;
using System.Collections.Generic;
using System.Collections;
using System.Linq;
using System.IO;

class Program
{
    static void Main(string[] args)
    {
        var N = int.Parse(Console.ReadLine());

        var A = Console.ReadLine().Split(' ').Select(x => float.Parse(x)).ToArray();

        float denominator = 0.0f;

        for (var i = 0; i < N; i++)
        {
            denominator = denominator + 1 / A[i];
        }

        Console.WriteLine(1 / denominator);
    }
}


Measured memory_bytes: 13268
#-*- coding: utf-8 -*-

import numpy as np

#input
N, M = map(int, raw_input().split())
list = [map(int, raw_input().split()) for i in range(0, N)]

#print(N, M)
#print(list)

#print(min(list, key=(lambda x: x[0])))

arr = np.array(list)

#print(arr)

#arrsort = np.sort(arr, axis=0)
arrsort = arr[arr[:,0].argsort()]

#print(arrsort)

yen = arrsort[0,0] * arrsort[0,1]

#print(yen)

#for i in range(0,arrsort[0,1]+1):
    #yen2 = arrsort[0,0] * i

#print(yen2)

hon = 0
yen2 = 0
yen3 = 0

for x in range(0,N):
            yen3 += yen2
            #print(x)
            #print("hon", hon)
            #print("yen3", yen3)
            for i in range(0,arrsort[x,1]):
                yen2 = arrsort[x,0] * (i+1)
                #print("yen2", yen2)
                hon += 1
                if hon == M:
                    break
                else:
                    continue
                break
            else:
                continue
            break

#print(hon)
#print(yen2)
#print(yen3)
print(yen3 + yen2)

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

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

  if(a + b == c || b + c == a || a + c == b) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;

}

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

using namespace std;

#define sqr(x) ((x) * (x))
#define pb push_back
#define mp make_pair
#define ins insert
#define X first
#define Y second
#define fin(name) freopen(name, "r", stdin)
#define fout(name) freopen(name, "w", stdout)
#define files(name) fin(name".in"); fout(name".out")
#define endl "\n"
#define fi(st,n) for (int i = (st); i <= (int)(n); ++i)
#define fj(st,n) for (int j = (st); j <= (int)(n); ++j)
#define fk(st,n) for (int k = (st); k <= (int)(n); ++k)
#define fq(st,n) for (int q = (st); q <= (int)(n); ++q)
#define fw(st,n) for (int w = (st); w <= (int)(n); ++w)
#define ff(i, st, n) for (int (i) = (st); (i) <= (int)(n); ++(i))
#define ei(st,n) for (int i = (st); i >= (int)(n); --i)
#define ej(st,n) for (int j = (st); j >= (int)(n); --j)
#define ek(st,n) for (int k = (st); k >= (int)(n); --k)
#define ef(i, st, n) for (int (i) = (st); (i) >= (int)(n); --(i))
#define ri(st,n) for (int i = (st); i < (int)(n); ++i)
#define rj(st,n) for (int j = (st); j < (int)(n); ++j)
#define rk(st,n) for (int k = (st); k < (int)(n); ++k)
#define rq(st,n) for (int q = (st); q < (int)(n); ++q)
#define rf(i, st, n) for (int (i) = (st); (i) < (int)(n); ++(i))
#define clean(a) memset((a),0,sizeof (a))
#define sync ios_base::sync_with_stdio(0);cin.tie(0)
#define y1 dsklmlvmd

typedef long long ll;
typedef unsigned long long ull;
typedef double dbl;
typedef long double ldbl;

const int inf = (int)1e9;
const ll linf = (ll)1e18;
const dbl eps = (dbl) 1e-8;
const int mod = (int) 1e9 + 7;
const int maxn = (int) 1e5 + 5;
//const dbl M_PI = (dbl)2 * (dbl)acos(0);

//cout<<fixed<<setprecision(10);
//srand(time(0));

ll n, k, a[maxn], g, mx;

int main()
{
//    fin("t.in");
    sync;
    cin >> n >> k;
    mx = 0;
    fi(1, n)
    {
    	cin >> a[i];
    	mx = max(mx, a[i]);
    }
    g = a[1];
    fi(2, n)
    {
    	g = __gcd(g, a[i]);
    }
    if (k % g != 0 || k > mx)
    	cout << "IMPOSSIBLE" << endl;
    else
    	cout << "POSSIBLE" << endl;
    return 0;
}

Measured memory_bytes: 1024
N = int(input())
src = [tuple(map(int,input().split())) for i in range(N)]

dp = [[0]*3 for i in range(N)]
dp[0] = src[0]
for i,(a,b,c) in enumerate(src[1:]):
    dp[i+1][0] = a + max(dp[i][1], dp[i][2])
    dp[i+1][1] = b + max(dp[i][2], dp[i][0])
    dp[i+1][2] = c + max(dp[i][0], dp[i][1])
print(max(dp[-1]))

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

int main() {
  string s;
  cin >> s;
  for (int i = 0; i < s.size(); i++) {
    cout << s[i];
    if (i == 3) {
      cout << " ";
    }
  }
  cout << endl;
  return 0;
}

Measured memory_bytes: 256
/*input
2 2 4
*/

#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
const double PI = 3.14159265358979323846;

double atan_arc(double x) {
    double res = atan(x);
    if (res < 0.0) res += PI;
    return res*180.0/PI;
}

int main() {
    double a, b, x;
    cin >> a >> b >> x;
    double v = a*a*b;
    double ans;
    if (x > v/2) {
        ans = atan_arc(2.0*(v-x)/a/a/a);
    }
    else {
        ans = atan_arc(a*b*b/2.0/x);
    }
    printf("%lf10\n", ans);
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <string.h>
#include <vector>
#include <cstdio>
#include <cmath>

using namespace std;

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    string n;
    cin>>n;
    int ans;
    int k=n.length();
    if(k==1){
        ans=ctoi(n[0]);
    }else{
        int p=ctoi(n[0]);
        bool jud=true;
            for(int i=1;i<k;i++){
                if(n[i]=='9'){
                }else{
                    jud=false;
                }
            }
        if(jud==true){
                ans=(k-1)*9+p;
            }else{
        ans=(k-1)*9+p-1;
        }
    }
    cout<<ans;
    return 0;
}


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

using namespace std;

#ifdef DEBUG_MODE
	#define DBG(n) n;
#else
	#define DBG(n) ;
#endif
#define REP(i,n) for(ll (i) = (0);(i) < (n);++i)
#define PB push_back
#define MP make_pair
#define FI first
#define SE second
#define SHOW1d(v,n) {for(int W = 0;W < (n);W++)cerr << v[W] << ' ';cerr << endl << endl;}
#define SHOW2d(v,i,j) {for(int aaa = 0;aaa < i;aaa++){for(int bbb = 0;bbb < j;bbb++)cerr << v[aaa][bbb] << ' ';cerr << endl;}cerr << endl;}
#define ALL(v) v.begin(),v.end()
#define Decimal fixed<<setprecision(20)
#define INF 1000000000
#define LLINF 1000000000000000000LL
#define MOD 1000000007

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

class RangeAddRangeMinTree {
public:
	vector<ll> node;
	vector<ll> add;
	ll sz;
	RangeAddRangeMinTree(vector<ll> v) {
		sz = 1;
		while(sz < v.size())sz *= 2;
		node = vector<ll>(2*sz,LLINF);
		add = vector<ll>(2*sz,0);
		for(int i = 0;i < v.size();i++){
			node[sz + i - 1] = v[i];
		}
		for(int i = node.size() - 1;i > 0;i--){
			node[(i - 1) / 2] = min(node[(i - 1) / 2],node[i]);
		}
	}

	void rangeAdd(int a, int b, int x, int k = 0, int l = 0, int r = -1) {
		if(r == -1)r = sz;
		if (r <= a || b <= l) return;
		if (a <= l && r <= b){
			add[k] += x;
			return;
		}
		rangeAdd(a, b, x, k * 2 + 1, l, (l + r) / 2);
		rangeAdd(a, b, x, k * 2 + 2, (l + r) / 2, r);

		node[k] = min(node[k * 2 + 1] + add[k * 2 + 1], node[k * 2 + 2] + add[k * 2 + 2]);
	}

	ll getMin(int a, int b, int k = 0, int l = 0, int r = -1) {
		if(r == -1)r = sz;
		if (r <= a || b <= l) return (LLINF);
		if (a <= l && r <= b) return (node[k] + add[k]);

		ll left = getMin(a, b, k * 2 + 1, l, (l + r) / 2);
		ll right = getMin(a, b, k * 2 + 2, (l + r) / 2, r);

		return (min(left, right) + add[k]);
	}
};

int main(){

	int n,q;cin >> n >> q;
	string str;cin >> str;
	set<int> s;
	vector<ll> v(str.size());
	int now = 0;
	for(int i = str.size()-1;i >= 0;i--){
		if(str[i] == '('){
			now--;
		}
		else{
			now++;
			s.insert(i);
		}
		v[i] = now;
	}
	RangeAddRangeMinTree seg(v);

	REP(seica,q){
		int t;cin >> t;t--;
		if(str[t] == '(') {
			str[t] = ')';
			seg.rangeAdd(0,t+1,2);
			s.insert(t);
			int ans = *s.begin();
			str[ans] = '(';
			seg.rangeAdd(0,ans+1,-2);
			cout << ans + 1 << endl;
			s.erase(s.begin());
		}
		else{
			str[t] = '(';
			auto it = s.lower_bound(t);
			s.erase(it);
			seg.rangeAdd(0,t+1,-2);
			int l = 0;
			int r = n;
			while(r - l > 1){
				int mid = (l + r) / 2;
				if(seg.getMin(mid, n+1) < 0) l = mid;
				else r = mid;
			}
			cout << l + 1 << endl;
			seg.rangeAdd(0,l+1,2);
			str[l] = ')';
			s.insert(l);
		}
	}

	return 0;
}



Measured memory_bytes: 31440
#include<stdio.h>
#include<vector>
#include<algorithm>
using namespace std;
typedef long long ll;
int main()
{
	int num;
	scanf("%d", &num);
	ll s1 = 0, s2 = 0;
	for (int i = 0; i < num; i++)
	{
		ll za, zb;
		scanf("%lld%lld", &za, &zb);
		s1 += zb, s2 += za*zb;
	}
	printf("%lld\n", (s1 - 1 + (s2 - 1) / 9));
}

Measured memory_bytes: 888
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws NumberFormatException, IOException {
		// TODO Auto-generated method stub
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] as = br.readLine().split(" ");
		long n = Long.parseLong(as[0]);
		long a = Long.parseLong(as[2]);
		long b = Long.parseLong(as[1]);
		long p = n %(a+b);
		if(p > b ) {p = b;}
		System.out.println((n/(a+b))*b + p);
	}

}


Measured memory_bytes: 22484
// 失敗するからこそ そこから立ち向かって行く強さがあってそんな強さが本当の強さだと私は思うから
// ぜったいあきらめない
#if defined(DAIJOBU)
#include "/home/ichigo/includes.hpp"
#include "/home/ichigo/debug.hpp"
#define deb(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#include <bits/stdc++.h>
#define deb(x...)
#endif
#define FIO {ios::sync_with_stdio(0);cin.tie(nullptr);cout.tie(nullptr);}

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


int main(){
	FIO
	
	int a, b, c, d;
	cin >> a >> b >> c >> d;
	int l = a + b, r = c + d;
	if(l < r)puts("Right");
	else if(l == r)puts("Balanced");
	else puts("Left");
	return 0; 
}


Measured memory_bytes: 384
//2017.11.18

#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main() {
  int n,heihou=0;
  cin >> n;
  while(n>=heihou*heihou){
    heihou++;
  }

  cout << (heihou-1)*(heihou-1);
	return 0;
}



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

typedef long long int in; 

in dp[405][405],sum[405];

int main() 
{
    in n,i,j,ans=0,k=1,l;
    cin>>n;
    
    in a[n];
    
    for(i=0;i<405;++i)
    for(j=0;j<405;++j)
    {
        dp[i][j]=1e15;
    }
    
    for(i=0;i<n;++i)
    {
        cin>>a[i];
        
        if(i==0)
        sum[i]=a[i];
        else
        sum[i]=sum[i-1]+a[i];
        
        dp[i][i]=0;
    }
    
    for(i=0;i<n-1;++i)
    {
        dp[i][i+1]=a[i]+a[i+1];
    }
    
    for(i=0;i<n;++i)
    {
        ++k;
        for(j=0;j<n;++j)
        if(j+k<n)
        {
            for(l=j;l<j+k;++l)
            {
                in r;
                
                if(j==0)
                r=sum[j+k];
                else
                r=sum[j+k]-sum[j-1];
                dp[j][j+k]=min(dp[j][j+k],dp[j][l]+dp[l+1][j+k]+r);
            }
        }
    }
    
    // for(i=0;i<n;++i)
    // {
    //     for(j=0;j<n;++j)
    //     {
    //         cout<<dp[i][j]<<" ";
    //     }
    //     cout<<"\n";
    // }
    
    cout<<dp[0][n-1];
    
	return 0;
}


Measured memory_bytes: 1536
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = s; i < (ll)(n); i++)
typedef long long ll;
typedef vector<vector<ll>> vvl;
typedef vector<ll> vl;
typedef vector<vector<char>> vvc;
typedef vector<char> vc;
typedef pair<ll,ll> pll;
ll max(ll x,ll y){
if(x>y)return x;
else return y;
}
ll min(ll x,ll y){
  return x+y-max(x,y);
}


int main() {
    int n,a,b;cin >> n >> a >> b;
    int A,B;
    A=0;B=0;
    rep(i,n){
        char k;cin >> k;
        string ans;
        if(k=='c')ans="No";
        else if(k=='a'){
            if(A+B<a+b){ans="Yes";A++;}
            else ans="No";
        }
        else if(k=='b'){
            if(A+B<a+b&&B<b){ans="Yes";B++;}
            else ans="No";
        }
        printf("%s\n",ans.c_str());
    }
}

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

int main() {
    int H, W, i , j;

    while (cin >> H >> W) {
        if (H == 0 && W == 0) return 0;

        for (i = 1; i <= H; i++) {
            for (j = 1; j <= W; j++) {
                cout << "#";
            }
            cout << endl;
        }
        cout << endl;
    }
}


Measured memory_bytes: 3100
# -*- coding: utf-8 -*-

import numpy as np

def main(p1,p2):
    L_np = np.sort(np.array(p2))
    x_total = 0
    for i in range(p1):
        x_total += L_np[2*i]
    print(x_total)

if __name__ == "__main__":
    #a = [int(input()) for i in range(5)]
    N = int(input())
    L = [int(item) for item in input().split()]
    main(N,L)

Measured memory_bytes: 13212
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
using namespace std;
inline void rd(int &x){
  int k;
  int m=0;
  x=0;
  for(;;){
    k = getchar_unlocked();
    if(k=='-'){
      m=1;
      break;
    }
    if('0'<=k&&k<='9'){
      x=k-'0';
      break;
    }
  }
  for(;;){
    k = getchar_unlocked();
    if(k<'0'||k>'9'){
      break;
    }
    x=x*10+k-'0';
  }
  if(m){
    x=-x;
  }
}
inline void wt_L(char a){
  putchar_unlocked(a);
}
inline void wt_L(int x){
  int s=0;
  int m=0;
  char f[10];
  if(x<0){
    m=1;
    x=-x;
  }
  while(x){
    f[s++]=x%10;
    x/=10;
  }
  if(!s){
    f[s++]=0;
  }
  if(m){
    putchar_unlocked('-');
  }
  while(s--){
    putchar_unlocked(f[s]+'0');
  }
}
int X;
int dp[100001];
int main(){
  int k;
  rd(X);
  dp[0] = 1;
  for(k=(100);k<(106);k++){
    int i;
    for(i=(k);i<(X+1);i++){
      dp[i] |= dp[i-k];
    }
  }
  wt_L(dp[X]);
  wt_L('\n');
  return 0;
}
// cLay varsion 20191125-1

// --- original code ---
// int X;
// int dp[100001];
// {
//   rd(X);
//   dp[0] = 1;
//   rep(k,100,106){
//     rep(i,k,X+1) dp[i] |= dp[i-k];
//   }
//   wt(dp[X]);
// }


Measured memory_bytes: 640
def change_count (array, multiple)
  chars = array * multiple
  change_count = 0
  (1...chars.size).each do |i|
    if chars[i - 1] == chars[i]
      chars[i] = 'A'
      change_count += 1
    end
  end
  change_count
end

INF = 10 ** 9
s = gets.chomp.split("")
k = gets.to_i
first_change_count = change_count(s, 1)
cycle = []
(2..INF).each do |i|
  increment_change_count = change_count(s, i) - (first_change_count + cycle.sum)
  break if cycle.first == increment_change_count
  cycle << increment_change_count
end

ans = first_change_count
k -= 1

div, mod = k.divmod(cycle.size)
ans += cycle.sum * div
ans += cycle[0...mod].sum

puts ans


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

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int N, M;
    cin >> N >> M;
    vector<int> A(M), B(M);
    for(int i=0; i<M; i++) cin >> A[i] >> B[i], A[i]--;

    vector<vector<int>> vals(N);
    for(int i=0; i<M; i++) vals[A[i]].push_back(B[i]);

    for(int i=0; i<N; i++)
    {
        sort(vals[i].begin(), vals[i].end());
        vals[i].erase(unique(vals[i].begin(), vals[i].end()), vals[i].end());
    }

    for(int i=0; i<M; i++)
    {
        printf("%06d", A[i]+1);
        int id = lower_bound(vals[A[i]].begin(), vals[A[i]].end(), B[i]) - vals[A[i]].begin();
        printf("%06d\n", id + 1);
    }


    return 0;
}


Measured memory_bytes: 9356
#! /usr/bin/env python
# -*- coding: utf-8 -*-

import pdb
import sys
F = sys.stdin

N = int(F.readline().rstrip())
A = list(map(int,F.readline().rstrip().split()))

for a in A:
    if a % 2 == 0:
        if a % 3 == 0 or a % 5 == 0:
            continue
        print('DENIED')
        sys.exit()

print('APPROVED')


Measured memory_bytes: 5632
S = [ ord(i)-ord('a') for i in input() ]

ms = 100000000000
for i in range(26):
  if i not in S:
    continue
  V = [ 1 if (i==j) else 0 for j in S ]
  
  s = 0
  for c in range(1000):
    if ( len(V)==sum(V) ):
      s = c
      break
    Vn = [0]*( len(V)-1 )
    for j in range( len(V)-1 ):
      Vn[j]=max(V[j],V[j+1])
    V = Vn
  
  ms = min(s,ms)
print (ms)

Measured memory_bytes: 40432
object Main{
  def main(args: Array[String]){
    val input=io.Source.stdin.getLines().mkString("\n")
    println(solve(input).trim())
  }

  def solve(input:String):String={
    val Array(s1,s2)=input.split("\n").map(_.toList)
    if(s1(1)==s2(1) && s1(0)==s2(2) && s1(2)==s2(0)){
      "YES"
    }else{
      "NO"
    }
  }
}


Measured memory_bytes: 25412
n,x,y=map(int,input().split())
x-=1;y-=1
fl=[0 for i in range(n-1)]
for i in range(n):
    for j in range(i+1,n):
        fl[min(abs(j-i),abs(j-x)+1+abs(y-i),abs(i-x)+1+abs(y-j))]+=1
print(*fl[1:],sep="\n")
print(0)


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

#define fr first
#define sc second
#define OK puts("OK");
#define pb push_back
#define mk make_pair

using namespace std;

typedef long long ll;

const int inf = (int)1e9 + 7;
const int N = (int)3e5 + 7;

int n;
int a[N];
int p[N];
int ans;

int main () {
      cin >> n;

      for (int i = 1; i <= n; i ++) {
            cin >> a[i];
            p[i] = p[i - 1] + abs(a[i] - a[i - 1]);
      }
      ans = p[n] + abs(a[n]);

      for (int i = 1; i <= n; i ++) {
            if (i < n) {
                  cout << ans - abs(a[i] - a[i - 1]) - abs(a[i + 1] - a[i]) + abs(a[i + 1] - a[i - 1]) << endl;
            }
            else {
                  cout << ans - abs(a[n]) + abs(a[n - 1]) - abs(a[n] - a[n - 1]) << endl;
            }
      }
}


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

string Comp(int x[26], int y[26]){
    string flag = "Yes";
    bool boo = false;
    for(int i = 0; i < 26; ++i){
        if(x[i] == 0){
            boo = true;
        }
    }
    
    if(boo){
        for(int i = 0; i < 26; ++i){
            for(int j = 0; j < 26; ++j){
                if(x[i] == y[j]){
                    y[j] = -1;
                    break;
                }
            }
        }
        for(int i = 0; i < 26; ++i){
                if(y[i] != -1){
                    flag = "No";
                }
        }
    } else {
        sort(x, x+26);
        sort(y, y+26);
        int num = -1;
        int num_count = 0;
        for(int i = 0; i < 26; ++i){
//            cout << x[i] << " ";
            for(int j = 0; j < 26; ++j){
                if(x[i] == y[j]){
                    y[j] = -1;
                }
            }
            if(num == x[i]){
                ++num_count;
            } else {
                if(num_count % 2 == 1){
                    flag = "No";
                    return flag;
                }
                num = x[i];
                num_count = 1;
            }
            
        }
    }
    return flag;
}

int main() {
    string S, T;
    cin >> S >> T;
    
    const int sizeS = S.length();
    const int sizeT = T.length();
    
    int listS[26];
    int listT[26];
    
//    cout << sizeS << sizeT << endl;
    
    int i = 0;
    for(char alph = 'a'; alph <='z'; ++alph){
        int count = 0;
        for(int j = 0; j < sizeS; ++j){
            if(alph == S[j]){
                ++count;
            }
        }
        listS[i] = count;
//        cout << count << " ";
        ++i;
    }
//    cout << endl;
    
    i = 0;
    for(char alph = 'a'; alph <='z'; ++alph){
        int count = 0;
        for(int j = 0; j < sizeT; ++j){
            if(alph == T[j]){
                ++count;
            }
        }
        listT[i] = count;
//        cout << count << " ";
        ++i;
    }
    
    cout << Comp(listS, listT) << endl;
    
    return 0;
}


Measured memory_bytes: 1020
#include<bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (int)n; i++)
const int MOD = 1000000007;
// long long a;
int main(){
  int a,b,c;
  cin >> a>>b >>c;
  if(a + c == 2*b) cout << "YES" << endl;
  else cout << "NO" << endl;
}


Measured memory_bytes: 256
package main

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

func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Split(bufio.ScanWords)

	n := nextInt(sc)
	m := nextInt(sc)
	l := nextInt(sc)

	a := make([][]int64, n)
	for i := int64(0); i < n; i++ {
		a[i] = make([]int64, m)
		for j := int64(0); j < m; j++ {
			a[i][j] = nextInt(sc)
		}
	}

	b := make([][]int64, m)
	for i := int64(0); i < m; i++ {
		b[i] = make([]int64, l)
		for j := int64(0); j < l; j++ {
			b[i][j] = nextInt(sc)
		}
	}

	for i := int64(0); i < n; i++ {
		o := make([]string, l)
		for j := int64(0); j < l; j++ {
			var v int64
			for k := int64(0); k < m; k++ {
				v += a[i][k] * b[k][j]
			}
			o[j] = strconv.FormatInt(v, 10)
		}
		fmt.Println(strings.Join(o, " "))
	}
}

func nextString(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func nextInt(sc *bufio.Scanner) int64 {
	i, err := strconv.ParseInt(nextString(sc), 10, 64)
	if err != nil {
		panic(err)
	}
	return i
}



Measured memory_bytes: 2012
import sys
import math
import itertools
import numpy

rl = sys.stdin.readline

n = rl().rstrip()
if n[-1] == '3':
  print('bon')
elif n[-1] == '0' or n[-1] == '6' or n[-1] == '8' or n[-1] == '1':
  print('pon')
else:
  print('hon')

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

int main(void){
    int count=0;
    string X;
    cin >> X;
   
  if(X[0]==X[1]){
     if(X[1] != X[2] && X[2]==X[3]){
       cout << "Yes";
       count = 1;
     }
   }
  
  if(X[0]==X[2]){
     if(X[2] != X[3] && X[1]==X[3]){
       cout << "Yes";
       count = 1;
     }
   }
  
  if(X[0]==X[3]){
     if(X[3] != X[1] && X[1]==X[2]){
       cout << "Yes";
       count = 1;
     }
   }
  
  
  if(count != 1){
  cout << "No";}
  
  return 0;
}

Measured memory_bytes: 256
#import sys
#import numpy as np
import math
#from fractions import Fraction
import itertools
from collections import deque
from collections import Counter
import heapq
from fractions  import gcd
#input=sys.stdin.readline
#import bisect

n,m=map(int,input().split())
d=[list(map(int,input().split())) for _ in range(m)]
c_0={}
c_1={}
c_2={}

for i in range(n):
    c=list(map(int,input().split()))
    for j in range(n):
        if (i+j+2)%3==0:
            if c[j] not in c_0:
                c_0[c[j]]=1
            else:
                c_0[c[j]]+=1
        elif (i+j+2)%3==1:
            if c[j] not in c_1:
                c_1[c[j]]=1
            else:
                c_1[c[j]]+=1
        else:
            if c[j] not in c_2:
                c_2[c[j]]=1
            else:
                c_2[c[j]]+=1
color=[i for i in (range(1,m+1))]
ans=10**9
for l in itertools.permutations(color,3):
    x,y,z=l
    res=0
    for cr in c_0:
        res+=d[cr-1][x-1]*c_0[cr]
    for cr in c_1:
        res+=d[cr-1][y-1]*c_1[cr]
    for cr in c_2:
        res+=d[cr-1][z-1]*c_2[cr]
    ans=min(ans,res)
print(ans)

Measured memory_bytes: 80284
#include <iostream>
using namespace std;
#define MAX 100001
#define NIL -1
struct Node{int parent,right,left;};
struct Node D[MAX];
int T[MAX];
void rec(int u,int p){
    T[u]=p;
    if(D[u].right!=NIL)rec(D[u].right,p);
    if(D[u].left!=NIL)rec(D[u].left,p+1);
}
void print(int u){
    int p;
    cout<<"node "<<u<<": parent = "<<D[u].parent<<", depth = "<<T[u]<<", ";
    if(D[u].parent==-1)cout<<"root, ";
    else if(D[u].parent!=-1&&D[u].left!=-1)cout<<"internal node, ";
    else if(D[u].left==-1)cout<<"leaf, ";
    if(D[u].left!=-1){
        p=D[u].left;
        cout<<"["<<p;
        while(true){
            if(D[p].right!=NIL){
                p=D[p].right;
                cout<<", "<<p;
            }
            else break;
        }
        cout<<"]"<<endl;
    }
    else if(D[u].left==-1)cout<<"[]"<<endl;
    
    
}
int main(void){
    int i,n,a,m,c,l,j;
    
    cin>>n;
    for(i=0;i<n;i++)D[i].parent=D[i].right=D[i].left=NIL;
    for(i=0;i<n;i++){
        cin>>a>>m;
        for(j=0;j<m;j++){
            cin>>c;
            if(j==0)D[a].left=c;
            else D[l].right=c;
            l=c;
            D[c].parent=a;
        }
    }
    for(i=0;i<n;i++){
        if(D[i].parent==NIL){
            break;
        }
    }
    rec(i,0);
    for(i=0;i<n;i++)print(i);
    return 0;
}

Measured memory_bytes: 7696
#include<cstdio>
#include<map>
#include<vector>
#include<set>
#include<algorithm>
using namespace std;
#define N 400600
map<int,int> tp1;
set<int> tp3;
struct sth{int l,r,lb,rb;friend bool operator <(sth a,sth b){return a.l<b.l;}};
vector<sth> v[N];
int su[N][2],vl[N][2],tp[N][2],ct,n,k,s[N],cnt;
long long as;
int main()
{
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&s[i]);
		tp3.insert(s[i]);if(!tp1[s[i]])tp1[s[i]]=++cnt;
		v[tp1[s[i]]].push_back((sth){i,i,1,1});
	}
	int lb=*tp3.lower_bound(1);
	while(1)
	{
		int st=tp1[lb];
		sort(v[st].begin(),v[st].end());
		int sz=v[st].size(),las=v[st][0].l;
		for(int i=0;i<sz;i++)
		{
			if(ct&&v[st][i].l!=v[st][i-1].r+1)
			{
				su[ct+1][0]=su[ct+1][1]=0;
				int s1=ct/k;
				if(s1)
				{
					for(int j=1;j<=ct;j++){int r1=j+k-1;if(r1<=ct)as+=1ll*vl[j][1]*(su[ct][0]-su[r1-1][0]);}
					for(int j=1;j<s1;j++)tp[j][0]=su[(j+1)*k-1][0]-su[j*k-1][0];
					tp[s1][0]=su[ct][0]-su[s1*k-1][0];
					for(int j=1;j<s1;j++)tp[s1-j+1][1]=-su[ct-(j+1)*k+1][1]+su[ct-j*k+1][1];
					tp[1][1]=su[ct-s1*k+1][1];
					if(!tp1[lb+1])tp1[lb+1]=++cnt,tp3.insert(lb+1);
					for(int j=1;j<=s1;j++)v[tp1[lb+1]].push_back((sth){las+j-1,j==s1?v[st][i-1].r:las+j-1,tp[j][0],tp[j][1]});
					for(int j=1;j<=s1;j++)vl[j][0]=tp[j][0],vl[j][1]=tp[j][1],su[j][0]=su[j-1][0]+vl[j][0];
					for(int j=1;j<=s1;j++){int r1=j+k-1;if(r1<=s1)as-=1ll*vl[j][1]*(su[s1][0]-su[r1-1][0]);}
				}
				ct=0;las=v[st][i].l;
			}
			vl[++ct][0]=v[st][i].lb;vl[ct][1]=v[st][i].rb;
			su[ct][0]=su[ct-1][0]+vl[ct][0];su[ct][1]=su[ct-1][1]+vl[ct][1];
		}
		su[ct+1][0]=su[ct+1][1]=0;
		int s1=ct/k;
		if(s1)
		{
			for(int j=1;j<=ct;j++){int r1=j+k-1;if(r1<=ct)as+=1ll*vl[j][1]*(su[ct][0]-su[r1-1][0]);}
			for(int j=1;j<s1;j++)tp[j][0]=su[(j+1)*k-1][0]-su[j*k-1][0];
			tp[s1][0]=su[ct][0]-su[s1*k-1][0];
			for(int j=1;j<s1;j++)tp[s1-j+1][1]=-su[ct-(j+1)*k+1][1]+su[ct-j*k+1][1];
			tp[1][1]=su[ct-s1*k+1][1];
			if(!tp1[lb+1])tp1[lb+1]=++cnt,tp3.insert(lb+1);
			for(int j=1;j<=s1;j++)v[tp1[lb+1]].push_back((sth){las+j-1,j==s1?v[st][sz-1].r:las+j-1,tp[j][0],tp[j][1]});
			for(int j=1;j<=s1;j++)vl[j][0]=tp[j][0],vl[j][1]=tp[j][1],su[j][0]=su[j-1][0]+vl[j][0];
			for(int j=1;j<=s1;j++){int r1=j+k-1;if(r1<=s1)as-=1ll*vl[j][1]*(su[s1][0]-su[r1-1][0]);}
		}
		ct=0;
		set<int>::iterator it=tp3.lower_bound(lb+1);
		if(it==tp3.end())break;
		lb=*it;
	}
	printf("%lld\n",as+n);
}//

Measured memory_bytes: 26728
#include <stdio.h>
#define MAXN 100100
int solve(int* a, int n) {
	int ans = 0;
	static int cnt[MAXN];
	for(int i = 0; i < n; i++)
		cnt[a[i]]++;
	for(int i = 0; i < MAXN; i++) {
		int s = cnt[i] + cnt[i + 1] + cnt[i + 2];
		if(ans < s) ans = s;
	}
	return ans;
}
int main(void) {
	int n;
	static int a[MAXN];
	scanf("%d", &n);
	for(int i = 0; i < n; i++) scanf("%d", &a[i]);
	printf("%d\n", solve(a, n));
	return 0;
}

Measured memory_bytes: 896
import sys
from bisect import bisect_left as bl
input = sys.stdin.readline
N = int(input())
a = list(map(int,input().split()))
cs = [0] * N
cs[0] = a[0]
for i in range(N - 1): cs[i + 1] = cs[i] + a[i + 1]
res = float("inf")
for m in range(1, N - 1):
  l = bl(cs, cs[m] // 2, hi = m)
  r = bl(cs, cs[m] + (cs[-1] - cs[m]) // 2, lo = m)
  l -= l == m
  r += r == m
  nl = l + 0
  nr = r + 0
  for i in range(3):
    if i == 1: continue
    if 0 <= l + i - 1 < m:
      if abs(cs[m] - 2 * cs[l + i - 1]) < abs(cs[m] - 2 * cs[l]):
        nl = l + i - 1
    if m < r + i - 1 < N:
      if abs(cs[-1] - 2 * cs[r + i - 1] + cs[m]) < abs(cs[-1] - 2 * cs[r] + cs[m]):
        nr = r + i - 1
  l = nl
  r = nr
  res = min(res, max(cs[l], cs[m] - cs[l], cs[r] - cs[m], cs[-1] - cs[r]) - min(cs[l], cs[m] - cs[l], cs[r] - cs[m], cs[-1] - cs[r]))
print(res)

Measured memory_bytes: 92536
#include<bits/stdc++.h>
using namespace std;
#define fastio std::ios::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL)
#define ll long long int
#define F first
#define S second
#define pb push_back
#define M 1000000007
#define inf 1e18
#define jam(x) cout<<"Case #"<<x<<": "

int32_t main() {
	fastio;
#ifndef ONLINE_JUDGE
	freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);
#endif

	ll n, k = 3;
	int i, j;
	cin >> n;
	vector< vector<int> > mat(n, vector<int>(k));
	vector< vector<int> > dp(n, vector<int>(k, 0));
	for (i = 0; i < n; i++) {
		for (j = 0; j < k; j++) {
			cin >> mat[i][j];
		}
	}
	for (i = 0; i < n; i++) dp[0][i] = mat[0][i];
	for (i = 1; i < n; i++) {
		for (j = 0; j < k; j++) {
			for (int op = 0; op < k; ++op) {
				if (op != j) {
					dp[i][j] = max(dp[i][j] , mat[i][j] + dp[i - 1][op]) ;
				}
			}

		}
	}

	int ans = 0;
	for (i = 0; i < k; i++) {
		ans = max( ans , dp[n - 1][i] );
	}
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 14240
#include <bits/stdc++.h>
#define sz(c)      int(c.size())
#define rep(i,a,b) for (int i=a; i<(b); ++i)
#define per(i,a,b) for (int i=(b)-1; i>=(a); --i)
using namespace std;
using ll = long long;

int const MD=int(1e9)+7;
ll f[4];

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  string s;
  cin>>s;
  f[0]=1;
  rep(i,1,4) f[i]=0;
  for (char c:s) {
    switch (c) {
      case 'A':
        f[1]=(f[1]+f[0])%MD;
        break;
      case 'B':
        f[2]=(f[2]+f[1])%MD;
        break;
      case 'C':
        f[3]=(f[3]+f[2])%MD;
        break;
      case '?':
        f[3]=(f[3]*3+f[2])%MD;
        f[2]=(f[2]*3+f[1])%MD;
        f[1]=(f[1]*3+f[0])%MD;
        f[0]=(f[0]*3)%MD;
        break;
      default:
        assert(false);
    }
  }
  cout<<f[3]<<endl;
}


Measured memory_bytes: 512