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

using namespace std;

int h, w, c;

bool isIn(int x, int y){
     return 0 <= x && x < h && 0 <= y && y < w;
}

int change(int n, int color, vector<vector<int> > field){
    vector<pair<int, int> > samecolor;
    samecolor.push_back(make_pair(0, 0));
    while(1){
        vector<pair<int, int> > v;
        for(int i=0; i < samecolor.size(); i++){
            v.push_back(samecolor[i]);
            int dx[4] = {1, 0, -1, 0};
            int dy[4] = {0, 1, 0, -1};
            for(int j=0; j < 4; j++){
                int nx = samecolor[i].first+dx[j], ny = samecolor[i].second+dy[j];
                if(isIn(nx, ny) && field[nx][ny] == field[0][0]){
                    bool is = true;
                    for(int k=0; k < v.size(); k++) if(nx == v[k].first && ny == v[k].second){is = false; break;}
                    for(int k=0; k < samecolor.size(); k++) if(nx == samecolor[k].first && ny == samecolor[k].second){is = false; break;}
                    if(is) v.push_back(make_pair(nx, ny));
                }
            }
        }
        if(v.size() == samecolor.size()) break;
        else samecolor = v;
    }
    if(n == 5) return samecolor.size();
    for(int i=0; i< samecolor.size(); i++) field[samecolor[i].first][samecolor[i].second] = color;

    int result = 0;
    if(n == 3) result = change(n+1, c, field);
    else for(int i=1; i <= 6; i++) if(field[0][0] != i)result = max(result, change(n+1, i, field));
    return result;
}

int main(){
    while(cin >> h >> w >> c, h+w+c){
        vector<vector<int> > field(8);
        for(int i=0; i< h; i++) {
            for(int j=0; j< w; j++){int t; cin >> t; field[i].push_back(t);}
        }
        int result = 0;
        for(int i=1; i <= 6; i++) if(field[0][0] != i) result = max(result, change(0, i, field));
        cout << result << endl;
    }
}

Measured memory_bytes: 1232
#include <iostream>
#include <vector>
using namespace std;
int main(void){
  int S;
  cin >> S;
  vector<long long> a(S);
  long long sum=0;
  for(int i=0;i<S;i++){
	cin >>a[i];
	sum += a[i];
  }
  int i;
  long long total=0;
  long long M = 1000000007;
  
  for(i=0;i<S-1;i++){
    sum -= a[i];
    total += (sum%M*a[i])%M;
    total %= M;
  }
  cout << total << endl;
}



Measured memory_bytes: 4760
import sys
sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().rstrip()

def main():
    N, Q = map(int, input().split())
    ki = [[] for _ in range(N + 1)]
    for _ in range(N-1):
        a, b = map(int, input().split())
        ki[a].append(b)
        ki[b].append(a)
    PX = [tuple(map(int, input().split())) for _ in range(Q)]

    ans = [0 for _ in range(N + 1)]
    for p, x in PX:
        ans[p] += x
    visited = set()
    def dfs(i):
        visited.add(i)
        for j in ki[i]:
            if j in visited:
                continue
            ans[j] += ans[i]
            dfs(j)
    dfs(1)
    print(*ans[1:])

if __name__ == '__main__':
    main()


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

int dp[105][105][105];

int solve(int a, int b, int c){
    if(a == b and b == c) return 0;
    if(a > 100 or b > 100 or c > 100) return 1e9;
    if(dp[a][b][c] != -1) return dp[a][b][c];
    int res = solve(a+2, b, c) + 1;
    res = min(res, solve(a, b+2, c) + 1);
    res = min(res, solve(a, b, c+2) + 1);
    res = min(res, solve(a+1, b+1, c) + 1);
    res = min(res, solve(a, b+1, c+1) + 1);
    res = min(res, solve(a+1, b, c+1) + 1);
    return dp[a][b][c] = res;
}

int main(){
    memset(dp, -1, sizeof dp);
    int a, b, c; cin >> a >> b >> c;
    cout << solve(a,b,c) << endl;
	return 0;
}


Measured memory_bytes: 4736
import sys
sys.setrecursionlimit(10**8)
def ii(): return int(sys.stdin.readline())
def mi(): return map(int, sys.stdin.readline().split())
def li(): return list(map(int, sys.stdin.readline().split()))
def li2(N): return [list(map(int, sys.stdin.readline().split())) for _ in range(N)]
def dp2(ini, i, j): return [[ini]*i for _ in range(j)]
#import bisect #bisect.bisect_left(B, a)
#from collections import defaultdict #d = defaultdict(int) d[key] += value
#from collections import Counter # a = Counter(A).most_common()
#from itertools import accumulate #list(accumulate(A))
'''
N = ii()
A = li2(N)
B = li2(N)

A = sorted(A, key=lambda x:x[0])
B = sorted(B, key=lambda x:x[0])

a_ind = 0
b_ind = 0
cnt = 0

while b_ind < N:
    if A[a_ind][0] < B[b_ind][0] and  A[a_ind][1] < B[b_ind][1]:
        cnt += 1
        a_ind += 1
        b_ind += 1
    else:
        b_ind += 1

print(cnt)
'''
'''
#global ans
ans = 0

def dfs(a_ind, b_ind, cnt):
    if a_ind >= N or b_ind >= N:
        global ans
        ans = max(ans, cnt)
        return
    if A[a_ind][0] < B[b_ind][0] and  A[a_ind][1] < B[b_ind][1]:
        dfs(a_ind+1, b_ind+1, cnt+1)
    else:
        dfs(a_ind+1, b_ind, cnt)
        dfs(a_ind, b_ind+1, cnt)
        dfs(a_ind+1, b_ind+1, cnt)

dfs(0, 0, 0)

print(ans)
'''

# XとYの二部グラフの最大マッチング X={0,1,2,...|X|-1} Y={0,1,2,...,|Y|-1}
#   edges[x]: xとつながるYの頂点のset
#   matched[y]: yとマッチングされたXの頂点(暫定)

def dfs(v, visited):
    """
    :param v: X側の未マッチングの頂点の1つ
    :param visited: 空のsetを渡す（外部からの呼び出し時）
    :return: 増大路が見つかればTrue
    """
    for u in edges[v]:
        if u in visited:
            continue
        visited.add(u)
        if matched[u] == -1 or dfs(matched[u], visited):
            matched[u] = v
            return True
    return False
 
 
# 標準入力からのグラフ読み取り
#xn, yn, e = map(int, input().split())
N = ii()
xn = N
yn = N
edges = [set() for _ in range(xn)]
matched = [-1] * yn
 
#for _ in range(e):
    #x, y = map(int, input().split())
    #edges[x].add(y)

A = li2(N)
B = li2(N)

for i in range(N):
    for j in range(N):
        if A[i][0] < B[j][0] and  A[i][1] < B[j][1]:
            edges[i].add(j)
 
# 増大路発見に成功したらTrue(=1)。合計することでマッチング数となる
print(sum(dfs(s, set()) for s in range(xn)))

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

#define rep(i, n) for(int (i) = 0; (i) < (n); (i)++)
#define repp(i, n, m) for(int (i) = (n); (i) < (m); (i)++)
#define repn(i, n) for(int (i) = 1; (i) <= (n); (i)++)
#define repr(i, n) for(int (i) = (n-1); (i) >= 0; (i)--)
#define all(x) (x).begin(), (x).end()
#define lint long long
#define ulint unsigned long long
#define ldou long double
#define fi first
#define se second
#define setpre(x) std::cout << fixed << setprecision(x)
#define ii(x) int x; cin >> (x)
#define ii2(x, y) int x, y; cin >> (x) >> (y)
#define ii3(x, y, z) int x, y, z; cin >> (x) >> (y) >> (z)
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define yn(x) cout << ((x)?("Yes"):("No")) << endl
#define YN(x) cout << ((x)?("YES"):("NO")) << endl
#define bit_c(x) __builtin_popcountll(x)

inline void logger(){ std::cout << " [LOGGER] " << endl; }
template<typename A, typename... B>
void logger(const A& a, const B&... b){
    cout << a << " , "; logger(b...);
}

typedef pair<lint, lint> P;
const lint MOD = 1000000007;
const lint MOD9 = 998244353;
const lint INF = MOD * MOD;
const int MAX = 200005;

/* ...o(^-^)o... */

const lint mod = MOD;
class mint{
    public:
        long long x;

    constexpr mint(long long _x = 0) : x((_x%mod+mod)%mod) {}
    constexpr mint operator-() const{
        return mint(-x);
    }
    constexpr mint& operator+=(const mint& a){
        if((x += a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator-=(const mint& a){
        if((x += mod-a.x) >= mod) x -= mod;
        return *this;
    }
    constexpr mint& operator*=(const mint& a){
        (x *= a.x) %= mod;
        return *this;
    }
    constexpr mint operator+(const mint& a) const{
        mint res(*this);
        return res+=a;
    }
    constexpr mint operator-(const mint& a) const{
        mint res(*this);
        return res-=a;
    }
    constexpr mint operator*(const mint& a) const{
        mint res(*this);
        return res*=a;
    }
    constexpr mint pow(long long x) const{
        if(!x) return 1;
        mint a = pow(x>>1);
        a *= a;
        if(x&1) a *= *this;
        return a; 
    }
    constexpr mint inv() const{
        return pow(mod-2);
    }
    constexpr mint& operator/=(const mint& a){
        return (*this) *= a.inv();
    }
    constexpr mint operator/(const mint& a) const{
        mint res(*this);
        return res/=a;
    }
    friend istream& operator>>(istream& is, mint& m){
        long long x; is >> x; m = x;
        return is;
    }
    friend ostream& operator<<(ostream& os, const mint& m){
        os << m.x; return os;
    }
};

int main(){
    int n; cin >> n;
    vector<mint> vec(n); rep(i,n) cin >> vec[i];

    mint ans = 0, sum = 0;
    rep(i,n) sum += vec[i];
    ans = sum * sum;

    mint prod = 0;
    rep(i,n) prod += vec[i]*vec[i];
    ans -= prod;
    ans /= 2;
    out(ans);
}

Measured memory_bytes: 4784
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <numeric>
#include <queue>
#include <string>
#include <vector>

using namespace std;

int main ()
{
    int k;
    cin >> k;
    int64_t sum = 0;
    for (int a = 1; a <= k; a++) {
        for (int b = 1; b <= k; b++) {
            int64_t g1 = gcd (a, b);
            for (int c = 1; c <= k; c++) {
                sum += gcd (g1, c);
            }
        }
    }
    cout << sum;
}


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

int main() {
	/*freopen("input.txt", "r", stdin);
	freopen("output.txt", "w", stdout);*/

	int n, l;
	cin >> n >> l;

	vector<int> apples;
	for (int i = 0; i < n; i++) 
		apples.push_back(l + i);

	int min_val = 2000000000;
	int pos = 0;
	for (int i = 0; i < n; i++) {
		if (abs(apples[i]) < min_val) {
			min_val = abs(apples[i]);
			pos = i;
		}
	}
	apples[pos] = 0;
	int ans = 0;
	for (int i = 0; i < n; i++)
		ans += apples[i];
	cout << ans;
}

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

int main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;
    if(abs(a-c)<=d or (abs(a-b)<=d and abs(b-c)<=d))cout << "Yes";
    else cout << "No";
}



Measured memory_bytes: 3564
#include <bits/stdc++.h>
#define ALL(V) V.begin(), V.end()
using namespace std;
using ll = int64_t;
using P = pair<ll, ll>;
template <typename T> using V = vector<T>;
template <typename T> using VV = vector<V<T>>;

int main() {
    ll N;
    cin >> N;
    V<ll> P(N);
    for(ll &e : P) cin >> e;
    V<ll> A(N);
    iota(ALL(A), 1ll);
    for(ll &e : A) e *= 3e4;
    V<ll> B = A;
    reverse(ALL(B));
    ll cnt = 0;
    for(ll e : P) {
        A[e - 1] += cnt;
        cnt++;
    }
    for(const auto &v : {A, B}) {
        for(ll e : v) cout << e << ' '; 
        cout << endl;
    }
    return 0;
}


Measured memory_bytes: 1408
/*
    Author - Param Kothari
    Ah shit, here we go again
*/

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

#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define mk make_pair

typedef long long ll;
typedef long double ld;

void solve(){
    int a;
    cin >> a;
    cout << (a + (a * a) + (a * a * a)) << "\n";
    return;
}

int main(){
    IOS;
    int t = 1;
    // cin >> t;
    for(int i = 1; i <= t; i++){
        solve();
    }
    return 0;
}

Measured memory_bytes: 3640
'use strict'

const main = (input) => {
    input = input.split('\n')
    const N = parseInt(input[0].split(' ')[0])
    const K = parseInt(input[0].split(' ')[1])
    const ls = input[1].split(' ').map(v => parseInt(v)).sort((a, b) => b - a)

    let sum = 0
    for(let i = 0; i < K; i++){
        sum += ls[i]
    }
    console.log(sum)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 21064
#include <set>
#include <iostream>
#define REP(i,n) for(int i=0; i<(int)(n); i++)

typedef long long ll;

#define IN(x,s,g) ((x) >= (s) && (x) < (g))
#define ISIN(x,y,w,h) (IN((x),0,(w)) && IN((y),0,(h)))

using namespace std;

const int _dx[] = { 0, 1, 0,-1};
const int _dy[] = {-1, 0, 1, 0};
int dir[256];

enum DIR{
  NORTH = 0,
  EAST  = 1,
  SOUTH = 2,
  WEST  = 3
};

string g[100];
int memo[100][100][4];
int h, w;
ll l;
string dir2str = "NESW";


bool cango(int x, int y, int d){
  int xx = x + _dx[d];
  int yy = y + _dy[d];

  return ISIN(xx, yy, w, h) && g[yy][xx] == '.';
}

int main(){
  dir['N'] = NORTH;
  dir['E'] = EAST;
  dir['S'] = SOUTH;
  dir['W'] = WEST;

  while(cin >> h >> w >> l, h + w + l){
    int sx, sy, sd;

    REP(i,h) cin >> g[i];

    REP(i,h) REP(j,w){
      if(g[i][j] != '.' && g[i][j] != '#'){
        sx = j; sy = i; sd = dir[g[i][j]];
        g[i][j] = '.';
      }
      REP(k, 4) memo[i][j][k] = -1;
    }

    for(ll turn = 0; turn < l; turn++){
      // cout << "turn: " << turn << " " << sy + 1 << " " << sx + 1 << " " << dir2str[sd] << endl;

      REP(k, 4){
        if(cango(sx, sy, sd)) break;
        sd = (sd + 1) % 4;
      }

      sx += _dx[sd];
      sy += _dy[sd];

      if(memo[sy][sx][sd] == -1){
        memo[sy][sx][sd] = turn + 1;
      }else{
        int cycle = (turn + 1) - memo[sy][sx][sd];
        ll tmp = (l - (turn + 1)) % cycle +  memo[sy][sx][sd];

        // cout << "tmp: " << tmp << endl;
        // cout << "cycle: " << cycle << endl;

        REP(i,h) REP(j,w) REP(k,4){
          if(memo[i][j][k] == tmp){
            sx = j; sy = i; sd = k;
            goto end;
          }
        }
      end:;
        break;
      }
    }

    cout << sy + 1 << " " << sx + 1 << " " << dir2str[sd] << endl;
  }

  return 0;
}

Measured memory_bytes: 0
Q,H,S,D = map(int,(input().split()))
N = int(input())
if Q*4 == min(Q*4,H*2,S,D/2):
    print(Q*4*N)
elif H*2 == min(Q*4,H*2,S,D/2):
    print(H*2*N)
elif S == min(Q*4,H*2,S,D/2):
    print(S*N)
else:
    p = 0
    p += D*(N//2)
    if Q*4 == min(Q*4,H*2,S):
        p += Q*4*(N%2)
    elif H*2 == min(Q*4,H*2,S):
        p += H*2*(N%2)
    elif S == min(Q*4,H*2,S):
        p += S*(N%2)
    print(p)

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

int main() {
    int a,b,c;
    cin >> a >> b >> c;
    
    if(c>0) {
    if(a%b ==0) {
     cout << "NO";
    } else if(a%2 == 0 && b%2 !=0){
        cout << "NO";
    } else if(c%gcd(a,b)) {
        cout << "NO";
    }        else {
     cout << "YES";
    }
    }
    
    else {
     cout << "YES";
    }
    
    
    }


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

using namespace std;

const int N = 100005;

int n, k;
int x[N];

int main(){

    scanf("%d %d", &n, &k);

    for(int i = 0; i < n; i++) scanf("%d", x+i);

    int ans = 1e9;

    for(int i = 0; i+k-1 < n; i++){
        int a = x[i], b = x[i+k-1];
        if(a <= 0 && b <= 0){
            ans = min(ans, -a);
        }
        else if(a >= 0 && b >= 0){
            ans = min(ans, b);
        }
        else{
            a = -a;
            if(a > b) swap(a, b);
            ans = min(ans, 2*a + b);
        }
    }

    printf("%d\n", ans);
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>

using namespace std;

const int MAX_N = 50;

int main () {
    int n;
    int V[MAX_N];

    cin >> n;

    for (int i = 0; i < n; i++) {
        cin >> V[i];
    }

    sort(V, V+n);

    double sum = 0.0;

    for (int i = 0; i < n; i++) {
        if (i == 0) {
            sum = V[i];
        } else {
            sum = (sum + V[i]) / 2.0;
        }
    }

    printf("%.10f\n", sum);
}


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 REPR(i,n) for(ll i = n;i >= 0;--i)
#define FOR(i,m,n) for(ll i = m, i##_len=(n);i <i##_len; ++i)
#define all(x) (x).begin(),(x).end()
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; }
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const int INF = 1e9;
const ll LLINF = 1e16;
 
ll modinv(ll a, ll m) {
    ll b = m, u = 1, v = 0;
    while (b) {
        ll t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

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

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

int main(){
    int n;
    cin >> n;
    int h[111] = {};
    for(int i=0; i<n; i++){
        cin >> h[i];
    }

    int ans = 0;
    while(true){
        //0じゃない区間の左端と右端のindex
        int left = -1, right;

        for(int i=0; i<n; i++){
            if(h[i] != 0){
                left = i;
                break;
            }
        }
        for(int i=left+1; i<=n; i++){
            if(h[i] == 0){
                right = i-1;
                break;
            }
        }
        if(left == -1){
            cout << ans << endl;
            break;
        }
        int minH = h[left];
        for(int i=left; i<=right; i++){
            minH = min(minH, h[i]);
        }
        ans += minH;
        for(int i=left; i<=right; i++){
            h[i] -= minH;
        }
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
  int i;
  long long x,h=0;
  cin>>x;
  while(x/500!=0){
    x-=500;
    h+=1000;
  }
  while(x/5!=0){
    x-=5;
    h+=5;
  }
  cout<<h<<endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
  int N;
  cin >> N;
  int ans;
  for(int i=1; i < 10; i++){
    int k;
    k=N-111*i;
    if(k<=0){
      ans = 111*i;
      break;
    }
    else if(k > 0){
      continue;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<queue>
#include<string>
#include<stack>
#include<cstdio>
#include<cstdlib>
#include<cmath>
#include<cstring>
#include<cassert>
#include<ctime>
#include<algorithm>
#include<utility>
#include<map>
#include<set>
#include<vector>
#include<functional>

using namespace std;

typedef  long long           ll;
typedef  unsigned            ui;
typedef  unsigned long long  ull;
typedef  pair<int,int>       i_i;
typedef  pair<ll,int>        ll_i;
typedef  pair<ll,ll>         ll_ll;
typedef  pair<double,int>    d_i;
typedef  pair<double,double> d_d;

#ifdef DEBUG
#define dprintf      printf
#define dputs        puts
#define dout(x)      cout<<#x" = "<<(x)<<endl
#define darray(x,n)  {int i;rep(i,n)cout<<#x"["<<i<<"] = "<<*((x)+i)<<endl;}
#define dloop(i,s,g) for(int (i)=(s);(i)<(g);(i)++)
#define drep(i,n)    for(int (i)=0;(i)<(n);(i)++)
#define dstop()      scanf("%*c")
#else
#define dprintf      (1)?0:printf
#define dputs        (1)?0:puts
#define dout(x)
#define darray(x,n)
#define dloop(i,s,g) if(int i=0){}else
#define drep(i,n)    if(int i=0){}else
#define dstop()
#endif

#define F    first
#define S    second
#define pb   push_back
#define mp   make_pair

#define loop(i,s,g) for((i)=(s);(i)<(g);(i)++)
#define rep(i,n)    for((i)=0;(i)<(n);(i)++)
#define all(x)      (x.begin(),x.end())
#define in(T,...) T __VA_ARGS__; impl(__VA_ARGS__)
#define array(T,id,n) T id[(n)]; for(int i=0;i<(n);i++)cin>>id[i]
#define putv(n)     cout<<(n)<<endl

//#define int long long
#ifndef int
#define INF __INT32_MAX__
#else
#define INF __INT64_MAX__
#endif

void impl(){};
template <typename T,typename... TS >
void impl(T &head,TS &... tail)
{
  cin>>head;
  impl(tail ...);
}
ll a[112345];
signed main(void)
{
  in(int,n);
  int i;
  rep(i,n)cin>>a[i];
  ll sum=0;
  ll bef=0;
  rep(i,n)
    {/*
      sum+=a[i]/2;
      a[i]=a[i]%2;
      if(a[i]==0)
	bef=0;
      else if(bef==1)
	sum++,bef=0;
      else
      bef=1;*//*
      a[i]+=bef;
      sum+=a[i]/2;
      if((a[i]-bef)%2==1)
	bef=a[i]%2-bef;
      else
      bef=a[i]%2;*/
      bef+=a[i];
      sum+=bef/2;
      if(a[i]!=0)
	bef%=2;
      else
	bef=0;	      
    }
  putv(sum);
  return 0;
}


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

int encode(char c) {
    if (c == 'R') return 0;
    if (c == 'G') return 1;
    if (c == 'B') return 2;
}

int main() {
    int N, S[4003], cnt[3][4003];

    cin >> N;

    memset(cnt, 0, sizeof(cnt));
    for (int i = 1; i <= N; i++) {
        char c;
        cin >> c;

        S[i] = encode(c);
        cnt[encode(c)][i] += 1;
    }

    for (int i = N - 1; i >= 1; i--) {
        for (int j = 0; j < 3; j++) {
            cnt[j][i] += cnt[j][i + 1];
        }
    }

    long long int answer = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = i + 1; j <= N; j++) {
            if (S[i] != S[j]) {
                int sk = 3 - (S[i] + S[j]);
                int count = cnt[sk][j + 1];

                if (j + (j - i) <= N && S[j + (j - i)] == sk)
                    count -= 1;

                answer += count;
            }
        }
    }

    cout << answer << endl;
}


Measured memory_bytes: 3684
#include<iostream>

using namespace std;

int main(){

    char s[3][3];

    for(int i = 0; i < 3; i++){
        for(int j = 0; j < 3; j++){
            cin >> s[i][j];
        }
    }

    cout << s[0][0] << s[1][1] << s[2][2] << endl;

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=2001;
int n,f[N][N],b[N],x,y,a[N];
int main()
{
	cin>>n>>x>>y;
	f[x][y]=1;
	for(int i=2;i<=n;i++)f[i-1][i]=1,b[i]=b[i-1]+1;
	for(int i=1;i<=n;i++)
	{
		for(int j=i+1;j<=n;j++)
		{
			if(!f[i][j])f[i][j]=b[j]-b[i];
			f[i][j]=min(f[i][j],abs(x-i)+1+abs(y-j));
			//cout<<i<<" "<<j<<' '<<x-i+1+abs(y-j)<<endl;
		}
	}
	for(int i=1;i<=n;i++)
		for(int j=i+1;j<=n;j++)
			a[f[i][j]]++;
	for(int i=1;i<=n-1;i++)cout<<a[i]<<endl;
}

Measured memory_bytes: 15360
#include<iostream>

using namespace std;

const int MAX_N=1e5+1;

int ans[MAX_N];
int data[MAX_N];
int main(){
	fill(ans,ans+MAX_N,0);
	ans[1]=1;
	fill(data,data+MAX_N,1);
	int n,m;
	cin>>n>>m;
	for(int i=0;i<m;i++){
		int x,y;
		cin>>x>>y;
		if(ans[x]==1)ans[y]=1;
		data[x]--;data[y]++;
		if(data[x]==0)ans[x]=0;
	}
	int cnt=0;
	for(int i=1;i<=n;i++)if(ans[i]==1)cnt++;
	cout<<cnt<<endl;
}


Measured memory_bytes: 1024
#include <iostream>
#include <cstring>
#include <string>
#include <cstdio>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>

using namespace std;

int main() {
    int N, M;

    cin >> N >> M;
    int a[M], b[M];
    int count[N] = {0};

    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i];
        count[a[i] - 1]++;
        count[b[i] - 1]++;
    }
    
    for (int i = 0; i < N; i++) {
        cout << count[i] << endl;
    }

    return 0;
}


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

struct node{
  unsigned int key;
  struct node *next;
  struct node *prev;
};

typedef struct node * NodePointer;

NodePointer nil;

NodePointer listSearch(int);
void init(void);
void printList(void);
void deleteNode(NodePointer);
void deleteFirst(void);
void deleteLast(void);
void delete(int);
void insert(int);

int main(){
  int key, n, i;
  int size = 0;
  char com[20];
  int np = 0, nd = 0;
  
  scanf("%d", &n);
  
  init();
  
  for (i = 0;i < n;i++){
    scanf("%s%d", com, &key);
    
    if (com[0] == 'i') {
      insert(key); np++;
      size++;
    }
    
    else if (com[0] == 'd') {
      if (strlen(com) > 6){
	if (com[6] == 'F')
	  deleteFirst();
	
	else if (com[6] == 'L')
	  deleteLast();
      }
      
      else 
	delete(key); nd++; 
      
      
      size--;
	
    }
    
  }

  printList();
  
  return 0;
}

NodePointer listSearch(int key){
  NodePointer cur = nil->next;

  while (cur != nil && cur->key != key)
    cur = cur->next;

  return cur;
}

void init(void){
  nil = (NodePointer)malloc(sizeof(struct node));
  nil->next = nil;
  nil->prev = nil;
}

void printList(void){
  NodePointer cur = nil->next;
  int isf = 1;
  while(1){
    if ( cur == nil ) break;
    if ( isf == 0)  printf(" ");
    printf("%d", cur->key);
    cur = cur->next;
    isf = 0;
  }
  printf("\n");
}

void deleteNode(NodePointer t){
  t->prev->next = t->next;
  t->next->prev = t->prev;
  free(t);
}

void deleteFirst(void){
  NodePointer t = nil->next;
  if ( t == nil )
    return;
  
  deleteNode(t);
}

void deleteLast(void){
  NodePointer t = nil->prev;
  if (t == nil)
    return;
  
  deleteNode(t);
}

void delete(int key){
  NodePointer t = listSearch(key);

  if (t == nil)
    return;

  deleteNode(t);
}


void insert(int key){
  NodePointer x;
  x = (NodePointer)malloc(sizeof(struct node));
  x->key = key;

  x->next = nil->next;
  nil->next->prev = x;
  nil->next = x;
  x->prev = nil;

}



Measured memory_bytes: 32996
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <cstdlib>
#include <cmath>
#define _GLIBCXX_DEBUG
#define rep(i,n) for(int i=0;i<n;i++)
using namespace std;
typedef long long ll;
const double pi=acos(-1);

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

int main(){
    int n;
    cin >> n;
    vector<int> A(n);
    for(int i=0;i<n;i++) cin >> A[i];
    sort(A.begin(),A.end());
    ll h=0,v=0;
    for(int i=n-1;i>0;i--){
        if(h==0){
            if(A[i]==A[i-1]){
                h=A[i];
                i--;
            }
        }else{
            if(A[i]==A[i-1]){
                v=A[i];
                break;
            }
        }
    }
    ll ans=h*v;
    cout << ans << endl;
}

Measured memory_bytes: 3780
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define n_l '\n'

#ifndef ONLINE_JUDGE
#define dbg(...) cout << "[" << #__VA_ARGS__ << "]: "; cout << to_string(__VA_ARGS__) << endl
template <typename T, size_t N> int SIZE(const T (&t)[N]){ return N; } template<typename T> int SIZE(const T &t){ return t.size(); } string to_string(const string s, int x1=0, int x2=1e9){ return '"' + ((x1 < s.size()) ? s.substr(x1, x2-x1+1) : "") + '"'; } string to_string(const char* s) { return to_string((string) s); } string to_string(const bool b) { return (b ? "true" : "false"); } string to_string(const char c){ return string({c}); } template<size_t N> string to_string(const bitset<N> &b, int x1=0, int x2=1e9){ string t = ""; for(int __iii__ = min(x1,SIZE(b)),  __jjj__ = min(x2, SIZE(b)-1); __iii__ <= __jjj__; ++__iii__){ t += b[__iii__] + '0'; } return '"' + t + '"'; } template <typename A, typename... C> string to_string(const A (&v), int x1=0, int x2=1e9, C... coords); int l_v_l_v_l = 0, t_a_b_s = 0; template <typename A, typename B> string to_string(const pair<A, B> &p) { l_v_l_v_l++; string res = "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; l_v_l_v_l--; return res; } template <typename A, typename... C> string to_string(const A (&v), int x1, int x2, C... coords) { int rnk = rank<A>::value; string tab(t_a_b_s, ' '); string res = ""; bool first = true; if(l_v_l_v_l == 0) res += n_l; res += tab + "["; x1 = min(x1, SIZE(v)), x2 = min(x2, SIZE(v)); auto l = begin(v); advance(l, x1); auto r = l; advance(r, (x2-x1) + (x2 < SIZE(v))); for (auto e = l; e != r; e = next(e)) { if (!first) { res += ", "; } first = false; l_v_l_v_l++; if(e != l){ if(rnk > 1) { res += n_l; t_a_b_s = l_v_l_v_l; }; } else{ t_a_b_s = 0; } res += to_string(*e, coords...); l_v_l_v_l--; } res += "]"; if(l_v_l_v_l == 0) res += n_l; return res; } void dbgm(){;} template<typename Heads, typename... Tails> void dbgm(Heads H, Tails... T){ cout << to_string(H) << " | "; dbgm(T...); } 
#define dbgm(...) cout << "[" << #__VA_ARGS__ << "]: "; dbgm(__VA_ARGS__); cout << endl
#endif

#define pb push_back
#define all(x) (x).begin(),(x).end()
#define fi first
#define se second
#define sz(x) ((int)(x).size())
#define forn(i,n) for(int i=0;i<n;i++)
#define for1(i,n) for(int i=1;i<=n;i++)
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
typedef double db;
typedef vector<vi> vvi;
const ll mod=1000000007;
const ll N=200005; //check this
int dx[] = {-1, 0, 1, 0, 1, 1, -1, -1};
int dy[] = {0, -1, 0, 1, 1, -1, 1, -1};

ll powmod(ll a,ll b) {ll res=1;a%=mod; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;}
ll powb(ll a,ll b) {ll res=1;a ; assert(b>=0); for(;b;b>>=1){if(b&1)res=res*a;a=a*a;}return res;}
ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;}

int main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);

    #ifndef ONLINE_JUDGE
    freopen("inputf.in", "r", stdin);
    freopen("outputf.in", "w", stdout);
    #endif
    int x;cin>>x;
    int ct=8;
    for(int i=400;i<2000;i+=200){
    	if(x>=i && x<i+200){
    		cout<<ct;
    		return 0;}
    	ct--;
    }
    cout<<1;
}


Measured memory_bytes: 3648
"use strict"
var input=require('fs').readFileSync('/dev/stdin','utf8');
var arr=input.split('\n');
var nm=arr[0].split(' ').map(Number);
var n=nm[0];
var m=nm[1];
var A=[];
var B=[];
for(var i=1;i<=n+m;i++){
  if(i<=n) A.push(arr[i].split(' ').map(Number));
  else B.push(Number(arr[i]));
}
for(var i=0;i<n;i++){
  var sum=0;
  for(var j=0;j<m;j++){
  	  sum+=A[i][j]*B[j];
  }
  console.log(sum);
}


Measured memory_bytes: 17472
#include<iostream>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<utility>
#include<vector>
#include<cmath>
#include<cstdio>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define mp make_pair
#define it ::iterator
#define all(in) in.begin(),in.end()
const double PI=acos(-1);
const double ESP=1e-10;
using namespace std;
int main(){
  int n;
  string s;
  cin>>n;
  getline(cin,s);
  rep(i,n){
    getline(cin,s);
    for(int j=7;j<=s.size();j++){
      if(s.substr(j-7,7)=="Hoshino")s[j-1]='a';
    }
    cout<<s<<endl;
  }

}

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

using namespace std;
typedef long long ll;

int main()
{
    ll n; cin >> n;
    ll b[n], sol = 0;
    for (ll i = 0; i < n; i++)
        cin >> b[i];

    ll ob[n];
    for (ll i = 0; i < n; i++)
        ob[i] = b[i];
    sort(ob, ob + n);

    for (int i = 0; i < n; i++){
        ll ji = 0, jf = n - 1;
        while (ji <= jf){
            if(b[i] < ob[(ji + jf) / 2])
                jf = (ji + jf) / 2;
            else if (b[i] > ob[(ji + jf) / 2])
                ji = (ji + jf) / 2 + (ji + jf) % 2;
            else{
                if (i % 2 != ((ji + jf) / 2) % 2) sol++;
                break;
            }
        }
    }

    cout << sol / 2 << '\n';
    return 0;
}


Measured memory_bytes: 1792
class Array
  def diff; (size-1).times.map { |i| self[i + 1] - self[i] } end
  def deru_kui(m); map{|t| t>m ? m : t } end
end

n,t = gets.split.map(&:to_i)
a = gets.split.map(&:to_i)

ans = a.diff.deru_kui(t).reduce(0){|s,t|s+=t} + t

p ans 

Measured memory_bytes: 19260
N,A,B = map(int,input().split())
S = input()

pass_num = 0
pass_fo = 0

for i in S:
    if i == 'a':
        if (A + B)-1 >= pass_num:
            print('Yes')
            pass_num += 1
        else:
            print('No')
    elif i == 'b':
        if ((A+B-1) >= pass_num)and(pass_fo <= B-1):
            print('Yes')
            pass_num += 1
            pass_fo += 1
        else:
            print('No')
    else:# i == 'c'
        print('No')

Measured memory_bytes: 9304
n = int(input())
p = list(map(int,input().split()))
cnt = 0
for i in range(1,n-1):
  if p[i] != max(p[i-1],p[i],p[i+1]) and p[i] != min(p[i-1],p[i],p[i+1]):
    cnt +=1
print(cnt)

Measured memory_bytes: 3060
import java.util.*;
public class Main{
  public static void main(String[] args){
    Scanner sc = new Scanner(System.in);
    String s = sc.next();
    char[] ss = s.toCharArray();
    String t = sc.next();
    char[] tt = t.toCharArray();
    int difmin = 100000;
    for(int i = 0;i<=s.length()-t.length();i++){
      int dif = 0;
      for(int j = 0;j<t.length();j++){
        if(ss[i+j]!=tt[j])dif++;
      }
      difmin = Math.min(dif,difmin);
    }
    System.out.println(difmin);
  }
}


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

#define pb push_back
#define mp make_pair
#define ll long long

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
     string s,t;
     cin>>s>>t;
     int f=0;
     int l=(int)t.length();
     for(int i=0;i<l-1;i++)
     {
		 if(s[i]==t[i])
		 continue;
		 else
		 {
			 f=1;
			 break;
		 }
	 }
	 if(f==1)
	 cout<<"No"<<'\n';
	 else
	 cout<<"Yes"<<'\n'; 
	  
}


Measured memory_bytes: 3648
// Vicfred
// https://atcoder.jp/contests/abc163/tasks/abc163_a
// math
import std.math;
import std.conv;
import std.stdio;
import std.string;

void main() {
    int r = readln.chomp.to!int;
    writefln("%0.12f", 2.0*PI*r);
}



Measured memory_bytes: 2912
#include <iostream>
#include <vector>
#include <algorithm>
#define INF 1000000000
using namespace std;
int main(void) {
  int n, k;
  cin >> n >> k;
  vector<int> h(n);
  for (int i = 0; i < n; i++) cin >> h[i];
  vector<int> cost(n, INF);
  cost[0] = 0;
  for (int i = 0; i < n; i++) {
    int m = min(k, n - 1 - i);
    for (int j = 1; j <= m; j++) {
      cost[i + j] = min(cost[i + j], cost[i] + abs(h[i + j] - h[i]));
    }
  }
  cout << cost[n - 1] << endl;
  return 0;
}

Measured memory_bytes: 4048
#include<stdio.h>

int main(){
  int h,w;
  int i,j;

  while (1){
    scanf("%d %d", &h, &w);
    if(h==0 && w==0){
      break;
    }
    for(i=0;i<h;i++){
      for(j=0;j<w;j++){
        printf("#");
      }
      printf("\n");
    }
    printf("\n");
  }

  return 0;
}


Measured memory_bytes: 2052
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
using namespace std;
int main(){
    int N, K, C;
    cin >> N >> K >> C;
    string S;
    cin >> S;
    vector<int> can;
    for(int i = 0; i < (int)S.size(); i++){
        if(S[i] == 'o') can.push_back(i + 1);
    }
    vector<int> L(K), R(K);
    int size = can.size();
    L[0] = can[0];
    for(int i = 1; i < K; i++){
        auto ite = lower_bound(can.begin(), can.end(), L[i - 1] + C + 1);
        if(ite == can.end()) L[i] = can[size - 1];
        else{
            int ind2 = ite - can.begin();
            L[i] = can[ind2];
        }
    }
    R[K - 1] = can[size - 1];
    for(int i = K - 2; i >= 0; i--){
        auto ite = upper_bound(can.begin(), can.end(), R[i + 1] - C - 1);
        if(ite == can.begin()) R[i] = can[0];
        else{
            int ind2 = ite - can.begin() - 1;
            R[i] = can[ind2];
        }
    }
    for(int i = 0; i < K; i++){
        if(L[i] == R[i]){
            cout << L[i] << endl;
        }
    }
}

Measured memory_bytes: 5676
#include<stdio.h>

int main(void){
	unsigned long int ihf,imf, isf, ihs, ims, iss;
	unsigned long int save, oh, om, os;
	int i;
	
	for(i=0;i<3;i++){
		scanf("%lu %lu %lu %lu %lu %lu", &ihf, &imf, &isf, &ihs, &ims, &iss);
			
		ihs = ihs*3600;
		ims = ims*60;
		iss = iss+ihs+ims;
		
		ihf = ihf*3600;
		imf = imf*60;
		isf = isf+ihf+imf;
		
		save = iss-isf;
		
		oh = save/3600;
		save = save%3600;
		
		om = save/60;
		save = save%60;
		
		os = save;
		
		printf("%lu %lu %lu\n",oh, om, os);
	}
	
	return 0;
}

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

#define ll long long
#define ld long double
#define pb push_back
#define x first
#define y second
#define sz(v) (int)(v.size())
#define all(v) v.begin(),v.end()

using namespace std;

map<ll,vector<ll>> mp;
unordered_set<ll> st;

void solve(ll a, ll b)
{
    if((a-1)%b==0) st.insert(b);
    for(ll x:mp[b])
        if((a-1)%x==0) st.insert(x);
    ll sq=sqrtl(b);
    if(sq*sq==b)
    {
        if((a-1)%sq==0) st.insert(sq);
    }
    sq--;
    if(sq*sq==b)
    {
        if((a-1)%sq==0) st.insert(sq);
    }
    sq+=2;
    if(sq*sq==b)
    {
        if((a-1)%sq==0) st.insert(sq);
    }
}

int main()
{
    //freopen("test.in","r",stdin);
    ios::sync_with_stdio(0); cin.tie(0);
    ll n; cin>>n;
    st.insert(n);
    if(n!=2)st.insert(n-1);
    for(ll i=2;i<=10005;++i)
    {
        ll cur=i*i;
        while(cur*i<=(ll)(1e13))
        {
            cur*=i;
            mp[cur].pb(i);
        }
    }
    for(ll i=2;i*i<=n-1;i++)
    {
        if((n-1)%i) continue;
        if(i*i==n-1) st.insert(i);
        else st.insert(i), st.insert((n-1)/i);
    }
    for(ll i=2;i*i<n;i++)
    {
        if(n%i) continue;
        solve(i,n/i); solve(n/i,i);
    }
    ll sq=sqrtl(n);
    if(sq*sq==n) st.insert(sq);

    cout<<sz(st)+sz(mp[n])<<'\n';
    return 0;
}


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

const int MAX_N = 100;

int main() {
	int n, k; cin >> n >> k;
	int x[MAX_N];
	for (int i = 0; i < n; i++) {
		cin >> x[i];
	}

	int ans = 0;
	for (int i = 0; i < n; i++) {
		int tmp = min(x[i], k - x[i]);
		ans += tmp;
	}
	cout << ans * 2 << endl;

	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
using namespace std;
typedef long long LL;
typedef pair<int, int> pii;

const LL INF=1e15;
int wei[105];
LL val[105];
LL memo[105][100005];
LL solve(int ix, int w)
{
	if(w < 0) return -INF;
	if(ix < 0) return 0;
	if(memo[ix][w]!=-1) return memo[ix][w];
	return memo[ix][w]=max(solve(ix-1, w), val[ix]+solve(ix-1, w-wei[ix]));
}

int main()
{
	int n, w;
	scanf("%d%d", &n, &w);
	for(int a=0;a<n;a++)
	{
		scanf("%d%lld", &wei[a], &val[a]);
	}
	memset(memo, -1, sizeof(memo));
	printf("%lld\n", solve(n-1, w));
	return 0;
}

Measured memory_bytes: 82432
# ABC 067 D
import sys
sys.setrecursionlimit(200000)

N = int(input())
G = [[] for k in range(N+1)]
for k in range(N-1):
    a, b = map(int,input().split())
    G[a].append(b)
    G[b].append(a)

kyori1 = [100000 for k in range(N+1)]
kyori2 = [100000 for k in range(N+1)]

def dfs1(now, dist):
    for tsugi in G[now]:
        if kyori1[tsugi] == 100000:
            kyori1[tsugi] = dist + 1
            dfs1(tsugi, dist+1)

def dfs2(now, dist):
    for tsugi in G[now]:
        if kyori2[tsugi] == 100000:
            kyori2[tsugi] = dist + 1
            dfs2(tsugi, dist+1)

kyori1[1] = 0
dfs1(1,0)

kyori2[N] = 0
dfs2(N,0)

s = 0
f = 0
for k in range(1,N+1):
    if kyori1[k] <= kyori2[k]:
        f += 1
    else:
        s += 1

print("Fennec" if f > s else "Snuke")


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

int n;

int main() {
    cin >> n;
    int a[n], L[n];
    for (int i=0; i<n; i++) cin >> a[i];
    L[0] = a[0];
    for (int i=1; i<n; i++) L[i] = L[i-1]*a[i]/__gcd(L[i-1],a[i]);
    cout << L[n-1] << endl;
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

using namespace std;

typedef long long ll;

const int MAX_N=1e5,MAX_Q=1e5;

int Q;
int l[MAX_Q],r[MAX_Q];

bool flg[MAX_N+1];
vector<int> p;
int cnt[MAX_N+1];

void era(){
	memset(flg,true,sizeof(flg));
	FOR(i,2,MAX_N+1){
		if (flg[i]){
			p.push_back(i);
			for(int j=i*2;j<=MAX_N;j+=i){
				flg[j]=false;
			}
		}
	}
}

int main(){
	cin>>Q;
	REP(i,Q){
		cin>>l[i]>>r[i];
	}
	era();
	FOR(i,1,MAX_N+1){
		cnt[i]=cnt[i-1];
		if (i%2 && binary_search(p.begin(),p.end(),i) && binary_search(p.begin(),p.end(),(i+1)/2)){
			cnt[i]++;
		}
	}
	/*
	REP(i,MAX_N+1){
		cout<<cnt[i]<<endl;
	}*/
	REP(i,Q){
		cout<<cnt[r[i]]-cnt[l[i]-1]<<endl;
	}
	return 0;
}

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

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)   FOR(i,0,n)
#define LL long long

#define MOD 1000000007
#define FACT_MAX 1000000

LL fact[FACT_MAX];

class Combinatrics{
private:
  long long mod = MOD;
  int fact_max = FACT_MAX;
public:
  Combinatrics(){
    fact[0]=1;
    for(int i=1;i<fact_max;i++)
      fact[i] = (fact[i-1]*i)%mod;
  }
  
  long long power(long long n, long long e){
    long long ret = 1;
    long long b = n;
    while(e){
      if(e%2!=0)
	ret*=b;
      ret%=mod;
      b*=b;
      b%=mod;
      e/=2;
    }
    return ret;
  }

  long long inv(long long n){
    return power(n,mod-2);
  }

  long long div(long long n1,long long n2){
    return n1*power(n2,mod-2)%mod;
  }
  
  long long nck(int n,int k){
    if(k>n || k<0) return 0LL;
    if(k==n || k==0) return 1LL;
    return (fact[n]*inv(fact[n-k])%mod)*inv(fact[k])%mod;
  }
};

int n;
int ar[100001],cnt[100001],dob;
int a,b;

int main(){
  cin>>n;
  int tmp;
  REP(i,n+1)cnt[i]=0;
  REP(i,n+1){
    cin>>tmp;tmp--;
    ar[i]=tmp;
    cnt[tmp]++;
    if(cnt[tmp]==2)dob=tmp;
  }
  bool bl=true;
  REP(i,n+1){
    if(bl&&ar[i]==dob){a=i;bl=false;}
    else if(ar[i]==dob)b=n-i;
  }
  Combinatrics comb;
  REP(i,n+1){
    cout<<(MOD+comb.nck(n+1,i+1)-comb.nck(a+b,i))%MOD<<endl;
  }
  return 0;
}


Measured memory_bytes: 9856
#include <iostream>
#include <algorithm>
using namespace std;
int main () {
    int a[10];
    for (int i = 0; i < 3; i++) cin >> a[i];
    sort(a, a + 3);
    if (a[0] == 5 && a[1] == 5 && a[2] == 7) puts("YES");
    else puts("NO");
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define FOR(i, a, b) for(int i=(a);i<(b);++i)
#define rep(i, n) FOR(i, 0, n)
#define whole(x) (x).begin(),(x).end()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
using ll = long long;
using P = pair<int, int>;
const int mod = 1000000007;


int main(){
    int n;
    cin >> n;
    vector<int> l(n);
    rep(i, n) cin >> l[i];
    sort(l.begin(), l.end());
    ll ans = 0;
    for (int i=0; i<n-1; i++) {
        for (int j=i+1; j<n; j++) {
            auto it = lower_bound(l.begin(), l.end(), l[i]+l[j]);
            int num = it - l.begin();
            ans += max(0, num-j-1);
        }
    }
    
    
    
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std; 
  
int main()
{
   long long int h,n,sum=0, a[200000],k, ans=0;
   cin >> n;
   cin >> k;
   
   for(int i=0;i<n;i++)
   {
       cin >> a[i];
   }
   sort(a,a+n);
   if(k>=n)
   {
       ans=0;
   }
   else
   {
       for(int i=0;i<n-k;i++)
       {
           ans+=a[i];
       }
       
   }
   cout << ans << endl;
  return 0;
  
}

Measured memory_bytes: 1792
a, b, c, d = (int(x) for x in input().split())

if a <= c <= b:
    if d <= b:
        print(d-c)
    else:
        print(b-c)
elif c <= a:
    if b <= d:
        print(b-a)
    elif a <= d <= b:
        print(d-a)
    else:
        print(0)
else:
    print(0)

Measured memory_bytes: 9136
#include <bits/stdc++.h>
using namespace std;
typedef int64_t i64;

int main()
{
  int A,B,C;
  cin >> A >> B >> C;

  if(A && B && A == C && B == C){
      cout << "No" << endl;
  }else if(A == B || A == C || B == C){
      cout << "Yes" << endl;
  }else{
      cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
using namespace std;
 
#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()
 
typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;
typedef vector<double> VD;
typedef vector<VD> VVD;

template<typename T> void chmin(T &a, T b) { if (a > b) a = b; }
template<typename T> void chmax(T &a, T b) { if (a < b) a = b; }

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }

const ll mod = 1e9 + 7;

int main() {
    string s;
    cin >> s;
    int n = s.length();

    VVL dp(n + 1, VL(2));
    dp[0][0] = 1;
    REP(i,n) REP(j,2){
        if (j == 0){
            REP(x,2) REP(y,2){
                if (x + y == 2) continue;
                int d = s[i] - '0';
                if (x + y > d) continue;
                (dp[i + 1][x + y < d] += dp[i][j]) %= mod;
            }
        }else{
            dp[i + 1][1] = (dp[i + 1][1] + 3 * dp[i][1]) % mod;
        }
    }

    ll ans = (dp[n][0] + dp[n][1]) % mod;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 5760
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p

s = int(input())
p = 10**9 + 7

if s < 3:
    print(0)
elif s < 6:
    print(1)
else:
    m = s // 3 - 2
    ans = 1
    for k in range(1, m + 2):
        ans += comb(s-3-2*k,k,p)
    print(ans%p)




Measured memory_bytes: 9184
#include <stdio.h>

int main() {
    int n, m, l;
    scanf("%d %d %d", &n, &m, &l);
    long int mat1[n][m], mat2[m][l], ans[n][l];
    for (int a=0; a<n; a++) {
        for (int b=0; b<l; b++) {
            ans[a][b] = 0;
        }
    }
    for (int i=0; i<n; i++) {
        for (int j=0; j<m; j++) {
            scanf("%ld", &mat1[i][j]);
        }
    }
    for (int p=0; p<m; p++) {
        for (int q=0; q<l; q++) {
            scanf("%ld", &mat2[p][q]);
        }
    }
    for (int x=0; x<n; x++) {
        for (int y=0; y<l; y++) {
            for (int z=0; z<m; z++) {
                ans[x][y] += (mat1[x][z] * mat2[z][y]);
            }
            printf("%ld", ans[x][y]);
            if (y < (l - 1)) {
                putchar(' ');
            } else {
                putchar('\n');
            }
        }
    }
    return 0;
}



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

// macro
#define rep(i,n) for(int i=0;i<n;i++)
#define all(v) v.begin(),v.end()
using ll = long long;
using P = pair<int,int>;

// code starts
int main()
{
	int n;
	cin >> n;
	int i;
	vector<int> a(n);
	rep(i,n) cin >> a[i];
	ll ans = 0;
	rep(i,n-1)
	{
		if(a[i] > a[i+1])
		{
			int dis = a[i]-a[i+1];
			ans += dis;
			a[i+1] += dis;
		}
	}
	cout << ans << endl;
}


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

int main() {
  int n,k; cin>>n>>k;
  vector<ll> v(n);
  rep(i, n) cin>>v[i];
  
  ll ans=0;
  rep(i, n+1) {
    rep(j, n+1) {
      if(i+j>n||i+j>k) break;
      ll tmp=0;
      priority_queue<ll> pq;
      rep(a, i){
        tmp+=v[a];
        pq.push(-v[a]);
      }
      rep(a, j) {
        tmp+=v[n-(a+1)];
        pq.push(-v[n-(a+1)]);
      }
      int d=k-(i+j);
      while (!pq.empty()&&d) {
        if (pq.top()<=0) break;
        tmp+=pq.top();
        pq.pop();
        d--;
      }
      ans=max(ans, tmp);
    }
  }
  cout<<ans<<endl;
  return 0;
}


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

#define ll long long int
#define endl '\n'
const long long inf=1e18;
ll dp[3005][3005];
string find(string a, string b )
{
    ll n=a.length();
    ll m=b.length();

    for(int i=0;i<=n;i++)
    {
        for(int j=0;j<=m;j++)
        {
            if(i==0 || j==0)
            {
                dp[i][j]=0;
            }
            else if(a[i-1]==b[j-1])
            {
                dp[i][j]=dp[i-1][j-1]+1;
            }
            else{
                dp[i][j]=max(dp[i-1][j],dp[i][j-1]);
            }
        }
    }
    
    ll i=n;
    ll j=m;
    string ans="";
    while(i>0 and j>0)
    {
        if(a[i-1]==b[j-1])
        {
            ans=a[i-1]+ans;
            i--;
            j--;
        }
        else
        if(dp[i-1][j]>dp[i][j-1])
        {
            i--;
        }
        else{
            j--;
        }

    }
    return ans;
    

}
void testCase()
{
   
    //ll t; cin>>t; while(t--)
    {
      string a,b;
      cin>>a>>b;
      cout<<find(a,b)<<endl;
    }      
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    testCase();
    return 0;
}

Measured memory_bytes: 74124