akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
int field[606][606][2];
int D[2];
int N;
vector<int> dx[2];
vector<int> dy[2];

void bfs(int x, int y, int index, int val) {
    if(x < 0 || x >= 2 * N || y < 0 || y >= 2 * N) return;
    if(field[x][y][index] != 0) return;
    field[x][y][index] = val;
    for(int i = 0; i < dx[index].size(); i++) {
        bfs(x+dx[index][i], y+dy[index][i], index, 3 - val);
    }
}

void print(vector<l_l> in) {
    for(int i = 0; i < N * N; i++) {
        cout << in[i].first << " " << in[i].second << endl;
    }
}

int main() {
    //cout.precision(10);
    cin >> N >> D[0] >> D[1];
    for(int index = 0; index < 2; index++) {
        for(int x = 0; x < 2 * N; x++) {
            for(int y = 0; y < 2 * N; y++) {
                if(x * x + y * y == D[index]) {
                    dx[index].push_back(x);
                    dx[index].push_back(x);
                    dx[index].push_back(-x);
                    dx[index].push_back(-x);
                    dy[index].push_back(y);
                    dy[index].push_back(-y);
                    dy[index].push_back(y);
                    dy[index].push_back(-y);
                }
            }
        }
    }
    for(int index = 0; index < 2; index++) {
        for(int x = 0; x < 2 * N; x++) {
            for(int y = 0; y < 2 * N; y++) bfs(x, y, index, 1);
        }
    }
    /*
    for(int index = 0; index < 2; index++) {
        for(int x = 0; x < 2 * N; x++) {
            for(int y = 0; y < 2 * N; y++) cerr << field[x][y][index] << " ";
            cerr << endl;
        }
        cerr << endl;
    }
    */
    vector<l_l> ans;
    for(int val = 1; val <= 2; val++) {
        ans.clear();
        for(int x = 0; x < 2 * N; x++) {
            for(int y = 0; y < 2 * N; y++) {
                if(field[x][y][0] == 1 && field[x][y][1] == val) ans.push_back({x, y});
            }
        }
        if(ans.size() >= N * N) {
            print(ans);
            return 0;
        }
    }
    return 0;
}


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

using namespace std;

int main() {
  int N, x;
  vector<int> A(101);
  cin >> N >> x;
  for (int i = 0; i < N; ++i) {
    cin >> A[i];
  }
  sort(A.begin(), A.begin() + N);
  int cnt = 0;
  for (int i = 0; i < N; ++i) {
    x -= A[i];
    if (x < 0) break;
    cnt++;
  }
  if (x > 0) cnt--;
  cout << cnt << endl;
}

Measured memory_bytes: 256
X = int(input())

if 400 <= X < 600:
    print(8)
elif 600 <= X < 800:
    print(7)
elif 800 <= X < 1000:
    print(6)
elif 1000 <= X < 1200:
    print(5)
elif 1200 <= X < 1400:
    print(4)
elif 1400 <= X < 1600:
    print(3)
elif 1600 <= X < 1800:
    print(2)
elif 1800 <= X < 2000:
    print(1)

Measured memory_bytes: 9052
import itertools
import math
N = int(input())
XY = [list(map(int,input().split())) for i in range(N)]
L = 0#経路長の和
for i in list(itertools.permutations(XY)):#順列に対し
    distance = 0
    for n in range(N-1):#経路長を求める
        distance += math.sqrt((i[n+1][0]-i[n][0])**2 + (i[n+1][1]-i[n][1])**2)
    L += distance
print(L/math.factorial(N))


Measured memory_bytes: 13988
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
using vl = vector<ll>;
template<class T> using vc = vector<T>;
template<class T> using vvc = vector<vector<T>>;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define repr(i, n) for (ll i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (ll i = (l); i < (r); i++)
#define reper(i, l, r) for (ll i = (r)-1; i >= (l); i--)
#define repa(i,n) for (auto& i: n)

template<class T> inline bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> inline bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
void init() {cin.tie(0);ios::sync_with_stdio(false);cout << fixed << setprecision(15);}

#ifdef DEBUG
template <class T, class N> void verr(const T& a, const N& n) { rep(i, n) cerr << a[i] << " "; cerr << "\n" << flush; }
ll dbgt = 1; void err() { cerr << "passed " << dbgt++ << "\n" << flush; }
template<class H, class... T> void err(H&& h,T&&... t){ cerr<< h << (sizeof...(t)?" ":"\n") << flush; if(sizeof...(t)>0) err(forward<T>(t)...); }
#endif

const ll INF = 4e18;
const ld EPS = 1e-11;
const ld PI = acos(-1.0L);
const ll MOD = 1e9 + 7;
// const ll MOD = 998244353;
//--------------------------------------------------------------------------------//

// 時間計算量O(N^2), 空間計算量O(N)

ld dist(pair<ld,ld> p1, pair<ld,ld> p2){
    return hypot(p1.first - p2.first, p1.second - p2.second);
}

int main() {
    init();
    ll N;
    cin >> N;
    vc<pair<ld, ld>> P(N);
    repa(p, P) cin >> p.first >> p.second;

    // accd[i+1] = dist(v_0, v_1), ... , dist(v_i, v_{i+1})の累積和
    vc<ld> accd(N), D(N);
    rep(i, N - 1) D[i + 1] = dist(P[i], P[i + 1]), accd[i + 1] += D[i + 1] + accd[i];


    vc<ld> C(N, INF);   // 頂点iまで点を使ったときの最小のサイクルの長さ
    C[0] = 0, C[1] = 2 * accd[1];
    

    repe(i, 2, N){
        // p_0 ~ p_{i-2}
        rep(j, i - 1){
            ld d = C[j + 1] + dist(P[j], P[i]) - D[j+1] + accd[i] - accd[j + 1];
            chmin(C[i], d);
        }
    }

    cout << C[N - 1] << endl;
}


Measured memory_bytes: 3440
// Template {{{
#include <bits/stdc++.h>
#define REP(i,n) for(int i=0; i<(int)(n); ++i)
using namespace std;
typedef long long LL;

#ifdef LOCAL
#include "contest.h"
#else
#define error(args...) 
#endif

const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
inline bool valid(int x, int w) { return 0 <= x && x < w; }

void iostream_init() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.setf(ios::fixed);
    cout.precision(12);
}
//}}}

int main(){
    iostream_init();
    int N;
    cin >> N;
    vector<pair<LL, LL>> v;
    REP(i, N) {
        LL x, y;
        cin >> x >> y;
        if(x > y) swap(x, y);
        v.push_back(make_pair(x, y));
    }
    sort(v.begin(), v.end());

    vector<LL> a, b;
    REP(i, v.size()) {
        a.push_back(v[i].first);
        b.push_back(v[i].second);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());

    LL F1 = a.front();
    LL F2 = a.back();
    LL S1 = b.front();
    LL S2 = b.back();
    LL ans = (S2 - S1) * (F2 - F1);

    multiset<LL> s;
    REP(i, N) s.insert(v[i].first);
    for(int i = 0; i <= N; i++) {
        LL min_a = (*s.begin());
        LL max_a = (*(--s.end()));
        // cerr << max_a << " - " << min_a << endl;
        LL sub = (S2 - F1) * (max_a - min_a);
        if(ans > sub) {
            ans = sub;
        }
        if(i < N) {
            s.erase(s.find(v[i].first));
            s.insert(v[i].second);
        }
    }

    cout << ans << endl;

    return 0;
}



Measured memory_bytes: 17772
def examD():
    N, W = LI()
    w = [0]*N
    v = [0]*N
    w[0], v[0] = LI()
    wbasic = w[0]
    for i in range(1,N):
        a, b = LI()
        w[i] = a-wbasic
        v[i] = b
    w[0] = 0
    dp =[[[0]*(3*N+1) for _ in range(N+1)]for _ in range(N+1)]
    for i in range(N):
        for j in range(N+1):
            for k in range(3*N+1):
                dp[i+1][j][k] = max(dp[i][j][k], dp[i+1][j][k])
                if w[i]<=k and j>=1:
                    if j*wbasic+k<=W:
                        dp[i+1][j][k] = max(dp[i][j-1][k-w[i]]+v[i], dp[i+1][j][k])
    ans = 0
    for v in dp[N]:
        ans = max(ans,max(v))
#        print(v)
    print(ans)


import sys
import copy
import bisect
from collections import Counter,defaultdict,deque
def I(): return int(sys.stdin.readline())
def LI(): return list(map(int,sys.stdin.readline().split()))
def LS(): return sys.stdin.readline().split()
def S(): return sys.stdin.readline().strip()
mod = 10**9 + 7
inf = float('inf')

examD()


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

int main(){
  int n,x;
  cin >> n >> x;
  vector<int> D(110,0),L(110,0);
  for(int i=0; i<n; i++){
    cin >> L[i];
    D[i+1] = D[i] + L[i];
  }
  int ans = 0;
  for(int i=0; i<n+1 && D[i] <= x; i++){
    ans++;
  }
  cout << ans << endl;
}

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

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

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

const int mod = 1e9 + 7;


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

	int n;
	cin >> n;

	vi d(n);
	rep(i, n){
		cin >> d[i];
	}

	int ans = 0;
	rep(i, n-1){
		rept(j, i+1, n){
			ans += d[i] * d[j];
		}
	}

	cout << ans << endl;

    return 0;
}



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

int main(){
    int a,b;

    scanf("%d %d",&a, &b);

    if(a%3==0 || b%3==0 || (a+b)%3==0)
        printf("Possible");
    else
        printf("Impossible");

    return 0;
}

Measured memory_bytes: 128
#include <stdio.h>


int main() {
	int i;
	int n, N;
	int pre = 0;
	scanf("%d", &n);
	N = n;
	
	for (i = 2; i * i <= n; ) {
		if (n % i == 0) {
			n /= i;
			if (pre != i) {
				pre = i;
				N = N / i * (i - 1);
			}
		} else {
			++i;
		}
	}
	if (pre != n) {
		N = N / n * (n - 1);
	}

	printf("%d\n", N);
	
	return 0;
}

Measured memory_bytes: 592
#include <bits/stdc++.h>
using namespace std;
void Main();

using i8  = int8_t;   /* -128 ~ 127 */
using u8  = uint8_t;  /* 0 ~ 255 */
using i16 = int16_t;  /* -32,768 ~ 32,767 */
using u16 = uint16_t; /* 0 ~ 65,535 */
using i32 = int32_t;  /* -2,147,483,648 ~ 2,147,483,647 */
using u32 = uint32_t; /* 0 ~ 4,294,967,295 */
using i64 = int64_t;  /* -9,223,372,036,854,775,808 ~ 9,223,372,036,854,775,807 */
using u64 = uint64_t; /* 0 ~ 18,446,744,073,709,551,615 */
using f32 = float;    /* (-3.4 * 10^38) ~ (3.4 * 10^38) */
using f64 = double;   /* (-1.7 * 10^308) ~ (1.7 * 10^308) */
using f80 = __float80;
template <class T> using Vec = vector<T>;
constexpr i64 INF = 1010000000000000017;
constexpr i64 MOD = 1e9 + 7;
constexpr f64 EPS = 1e-12;
constexpr f64 PI = 3.14159265358979323846;
#define ALL(v) v.begin(), v.end()
#define YN(a, b, c) ((c)? a : b)
#define GCD(a, b) __gcd(a, b) /* 最大公約数 */
#define LCM(a, b) (i64)(a / (f64)__gcd(a, b) * b) /* 最小公倍数 */

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

void Main() {
    i32 N;
    cin >> N;
    Vec<i64> A(N), B(N);
    i64 sumA = 0, sumB = 0;
    for (i32 i = 0; i < N; i++) {
        cin >> A[i];
        sumA += A[i];
    }
    for (i32 i = 0; i < N; i++) {
        cin >> B[i];
        sumB += B[i];
    }
    if (sumA < sumB) {
        cout << -1 << endl;
        return;
    }
    priority_queue<i64> pq;
    for (i32 i = 0; i < N; i++) {
        if (A[i] - B[i] > 0) pq.push(A[i] - B[i]);
    }
    i32 ans = 0;
    i64 current = 0;
    for (i32 i = 0; i < N; i++) {
        if (A[i] >= B[i]) continue;
        ans++;
        while (A[i] < B[i]) {
            if (B[i] - A[i] <= current) {
                current -= B[i] - A[i];
                A[i] = B[i];
            } else {
                ans++;
                current += pq.top();
                pq.pop();
            }
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 5412
from collections import deque
import sys
input = lambda: sys.stdin.readline().rstrip() 
def main():
    moji=input()
    d=deque(moji)
    cycle=int(input())
    flont_or_back=0
    flont=""
    back=""
    for i in range(cycle):
        line=input()
        if line[0]=="1":
            flont_or_back+=1
        else:
            fi=line[2]
            ci=line[4]
            if flont_or_back%2==0:
                if fi=="1":
                    d.appendleft(ci)
                else:
                    d.append(ci)
            else:
                if fi=="1":
                    d.append(ci)
                else:
                    d.appendleft(ci)
    if flont_or_back%2==0:
        print("".join(d))
    else:
        d.reverse()
        print("".join(d))

if __name__ == '__main__':
    main() 
    


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

const int mod = 1000000007;

int main() {
  std::ios::sync_with_stdio(false);
  std::cin.tie(0);
  ll n, k;
  cin >> n >> k;
  vector<int> A(n);
  rep(i,n) cin >> A[i];
  ll ans = 0;
  k %= mod;
  rep(i,n) {
    ll left = 0, right = 0;
    rep(j,n) {
      if (A[i] > A[j]){
        if (i < j) right++;
        else left++;
      } 
    }
    ans += right*k % mod;
    ans %= mod;
    ans += (k-1)*k/2 % mod * (left + right) % mod;
    ans %= mod;
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
n = int(input())
a = [int(input()) for _ in range(n)]
a.sort()

a1 = []
a2 = []
a1.append(a[n//2])
a2.append(a[n//2])

for i in range((n-1)//2):
    a1.append(a[i])
    a1.append(a[n-i-1])
    
    a2.append(a[n-i-1])
    a2.append(a[i])
if not n%2:
    a1.append(a[n//2-1])
    a2.append(a[n//2-1])

ans1 = 0
ans2 = 0
for i in range(len(a1)-1):
    ans1 += abs(a1[i+1] -a1[i])
    ans2 += abs(a2[i+1]-a2[i])
print(max(ans1,ans2))

Measured memory_bytes: 62328
A,B,K=map(int,input().split())

for i in range(K//2):
    if(A%2==0):
        A=A//2
        B+=A
    else:
        A-=1
        A=A//2
        B+=A
    if(B%2==0):
        B=B//2
        A+=B
    else:
        B-=1
        B=B//2
        A+=B

if K%2 ==1:
    if(A%2==0):
        A=A//2
        B+=A
    else:
        A-=1
        A=A//2
        B+=A

print(A,B)

    

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

#define debug(x) cout << #x << " = " << x << endl
#define fori(i, ini, lim) for(int i = int(ini); i < int(lim); i++)
#define ford(i, ini, lim) for(int i = int(ini); i >= int(lim); i--)

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int, int> ii;

const int MAX = 2e5 + 5;
const ll MAX_VAL = (ll) 1e18;
ll pref[MAX];
int arr[MAX];
int n, x;

bool overflow(ll a, ll b) {
    return a > MAX_VAL / b;
}

int main() {
    scanf("%d %d", &n, &x);
    fori(i, 1, n + 1) {
        scanf("%d", arr + i);
        pref[i] = pref[i - 1] + arr[i];
    }
    ll ans = MAX_VAL;
    fori(i, 1, n + 1) { // group size
        ll cur = 1LL * i * x;
        int index = n;
        int it = 0;
        do {
            ll coef = it == 0 ? 5 : (3 + 2 * it);
            if(overflow(pref[index] - pref[max(0, index - i)], coef)) {
                cur = MAX_VAL;
                break;
            }
            cur += (pref[index] - pref[max(0, index - i)]) * coef;
            index -= i;
            it++;
        } while(index >= 1 && cur <= MAX_VAL);
        ans = min(ans, cur);
    }
    ans += 1LL * n * x;
    printf("%lld\n", ans);
    return 0;
}


Measured memory_bytes: 2560
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.StringTokenizer;

public class Main {
    public static void main(String[] args)throws Exception {
        BufferedReader input = new BufferedReader(new InputStreamReader(System.in));
        int n = Integer.parseInt((input).readLine());
        int [] problems  = new int[n];
        int sum = 0;
        StringTokenizer tokn = new StringTokenizer(input.readLine());
        for (int i = 0; i < n; i++) {
            problems[i]  = Integer.parseInt(tokn.nextToken());
            sum += problems[i];
        }
        int m = Integer.parseInt((input).readLine());
        StringBuilder out = new StringBuilder();
        for (int i = 0; i < m; i++) {
            tokn = new StringTokenizer(input.readLine());
            int p1 = Integer.parseInt(tokn.nextToken());
            int m1 = Integer.parseInt(tokn.nextToken());
            out.append((sum - problems[p1 - 1]) + m1).append("\n");
        }
        System.out.println(out);
    }
}


Measured memory_bytes: 22868
#include <bits/stdc++.h>
using namespace std;
long long A[3];
long long ans;
int main()
{
    cin >> A[0] >> A[1] >> A[2];
    sort(A, A+3);
    ans += A[1] - A[0];
    ans += A[2] - A[1];
    cout << ans << "\n";
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
	int h, w;
	int i, j;
	while (1){
		scanf("%d %d", &h, &w);
		if (h == 0 && w == 0){
			return 0;
		}

		for (i = 0; i < w; i++){
			printf("#");
		}
		printf("\n");
		for (i = 0; i < h-2; i++){
			printf("#");
			for (j = 0; j < w-2; j++){
				printf(".");
			}
			printf("#\n");
		}
		for (i = 0; i < w; i++){
			printf("#");
		}
		printf("\n\n");
	}
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
int H, W;
int main() {
    cin >> H >> W;
    vector<vector<char>> S(H+2, vector<char>(W+2, '.'));
    for(int i = 1; i <= H; ++i) {
        for(int j = 1; j <= W; ++j) {
            cin >> S.at(i).at(j);
        }
    }

    for(int i = 1; i <= H; ++i) {
        for(int j = 1; j <= W; ++j) {
            if(S.at(i).at(j) != '#') {
                int cnt = 0;
                for(int k = 0; k < 3; ++k) {
                    for(int l = 0; l < 3; ++l) {
                        if(S.at(i-1+k).at(j-1+l) == '#') cnt++;
                    }
                }
                S.at(i).at(j) = cnt + '0';
            }
        }
    }

    for(int i = 1; i <= H; ++i) {
        for(int j = 1; j <= W; ++j) {
            cout << S.at(i).at(j);
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int k = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        Long ans = Long.MAX_VALUE;
        for (int i = 0; i < 1<<n; i++) {
            if(Integer.bitCount(i) < k)continue;
            long t = 0L;
            int preh = -1;
            for (int j = 0; j < n; j++) {
                if((i>>j & 1) != 1){
                    if(preh < a[j]) preh = a[j];
                    continue;
                }
                if(a[j] < preh+1) t += preh+1-a[j];
                preh = Math.max(a[j], preh+1);
            }
            if(t < ans) ans = t;
        }
        System.out.println(ans);
        sc.close();

    }

}


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

int main() {
    int n;
    string s;
    cin >> n >> s;
    string s2 = s.substr(0,n/2);
    string t = s2 + s2;
    if(t == s)cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
import sys
input = sys.stdin.readline


a, v = list(map(int, input().split()))
b, w = list(map(int, input().split()))
t = int(input())

s = ""

if v - w <= 0:
    s = "NO"
else:
    if abs(a-b) // (v-w)  > t:
        s = "NO"
    elif abs(a-b) // (v-w)  == t and abs(a-b) % (v-w)  > 0:
        s = "NO"
    else:
        s = "YES"
    

print(s)

Measured memory_bytes: 61672
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var imp = Console.ReadLine().Split(' ');
            int N = int.Parse(imp[0]);
            int A = int.Parse(imp[1]);
            int B = int.Parse(imp[2]);
            int count = 0;
            int brank = 1;

            for (; N > 0; --N)
            {
                var coder = Console.Read();


                if (coder == 'a') 
                {
                    if(count<A+B)
                    {
                        count += 1;
                        Console.WriteLine("Yes");
                    }
                    else
                    {
                        Console.WriteLine("No");
                    }
                }

                if (coder == 'b')
                {
                    if((count<A+B)&&(brank<=B))
                    {
                        count += 1;
                        brank += 1;
                        Console.WriteLine("Yes");
                    }
                    else
                    {
                        Console.WriteLine("No");
                    }
                }

                if (coder == 'c')
                {
                    Console.WriteLine("No");
                }
            }


            //System.Threading.Thread.Sleep(500);
        }
    }
}


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

using namespace std;
int main(){
    int n;
    cin>>n;
    vector <int> a,b,c;
    for(int i = 0; i < n; i++){
        int t;
        cin>>t;
        a.push_back(t);
    }
    for(int i = 0; i < n; i++){
        int t;
        cin>>t;
        b.push_back(t);
    }
    c = a;
    sort(c.begin(), c.end());
    int p1 = 0, p2 = 0; 
    while(1){
        p1++;
        if(c == a) break;
        next_permutation(c.begin(), c.end());
    }
    sort(c.begin(), c.end());
    while(1){
        p2++;
        if(c == b) break;
        next_permutation(c.begin(), c.end());
    }
    cout<<abs(p1-p2);
    return 0; 
}

Measured memory_bytes: 256
#include<iostream>
#include<string.h>
#include<string>
#include<stdio.h>
#include<algorithm>
#include<vector>
#include<bitset>
#include<math.h>
#include<stack>
#include<queue>
#include<set>
#include<map>
using namespace std;
typedef long long ll;
typedef long double db;
typedef pair<int,int> pii;
const int N=100000;
const db pi=acos(-1.0);
#define lowbit(x) (x)&(-x)
#define sqr(x) (x)*(x)
#define rep(i,a,b) for (register int i=a;i<=b;i++)
#define per(i,a,b) for (register int i=a;i>=b;i--)
#define go(u,i) for (register int i=head[u];i;i=sq[i].nxt)
#define fir first
#define sec second
#define mp make_pair
#define pb push_back
#define maxd 998244353
#define eps 1e-8
inline int read()
{
    int x=0,f=1;char ch=getchar();
    while ((ch<'0') || (ch>'9')) {if (ch=='-') f=-1;ch=getchar();}
    while ((ch>='0') && (ch<='9')) {x=x*10+(ch-'0');ch=getchar();}
    return x*f;
}

namespace My_Math{
	#define N 100000

	int fac[N+100],invfac[N+100];

	int add(int x,int y) {return x+y>=maxd?x+y-maxd:x+y;}
	int dec(int x,int y) {return x<y?x-y+maxd:x-y;}
	int mul(int x,int y) {return 1ll*x*y%maxd;}
	ll qpow(ll x,int y)
	{
		ll ans=1;
		while (y)
		{
			if (y&1) ans=mul(ans,x);
			x=mul(x,x);y>>=1;
		}
		return ans;
	}
	int inv(int x) {return qpow(x,maxd-2);}

	int C(int n,int m)
	{
		if ((n<m) || (n<0) || (m<0)) return 0;
		return mul(mul(fac[n],invfac[m]),invfac[n-m]);
	}

	int math_init()
	{
		fac[0]=invfac[0]=1;
		rep(i,1,N) fac[i]=mul(fac[i-1],i);
		invfac[N]=inv(fac[N]);
		per(i,N-1,1) invfac[i]=mul(invfac[i+1],i+1);
	}
	#undef N
}
using namespace My_Math;

struct node{int to,nxt;}sq[400400];
int all=0,head[200200];
int n,ans[200200];
queue<int> q[2];

void addedge(int u,int v)
{
	all++;sq[all].to=v;sq[all].nxt=head[u];head[u]=all;
}

void dfs(int u,int fu,int c)
{
	q[c].push(u);
	go(u,i)
	{
		int v=sq[i].to;
		if (v==fu) continue;
		dfs(v,u,c^1);
	}
}

int solve(int c,int x)
{
	while ((x<=n) && (!q[c].empty()))
	{
		int u=q[c].front();q[c].pop();
		ans[u]=x;x+=3;
	}
	return x;
}

int main()
{
	n=read();
	rep(i,1,n-1)
	{
		int u=read(),v=read();
		addedge(u,v);addedge(v,u);
	}
	dfs(1,0,0);
	if (q[0].size()<q[1].size()) swap(q[0],q[1]);
	solve(0,1);
	if (q[0].size()<q[1].size()) swap(q[0],q[1]);
	solve(0,2);
	int now=solve(0,3);solve(1,now);
	rep(i,1,n) printf("%d ",ans[i]);
	return 0;
}
	



Measured memory_bytes: 15232
def myAnswer(N:int,S:list) -> None:
    dic = {}
    for s in S:
        if(s in dic.keys()):
            dic[s]+=1
        else:
            dic[s] = 1
    ans = []
    dic2 = sorted(dic.items(), key=lambda x:x[1],reverse = True)
    MAX = dic2[0][1]
    for key,value in dic2:
        if(MAX == value):
            ans.append(key)
        else:
            break
    ans.sort()
    for a in ans:
        print(a)




def main():
    N = int(input())
    S = [(input()) for _ in range(N)]
    myAnswer(N,S[:])
if __name__ == '__main__':
   main()

Measured memory_bytes: 48908
#include <iostream>
#include <vector>
#include <algorithm>
#include <map>
#include <queue>
#include <string>
#include <set>
#include <cstdint>
#include <numeric>
#define INF 1000000000
#define LLINF 2000000000000000
#define MOD 1000000007
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define LOOP(i,N) for(int i=0;i<N;i++)
#define LOOP1(i,N) for(int i=1;i<=N;i++)
typedef pair<int,int> P;
typedef pair<int,pair<int,int> > PP;
#define int long long

signed main(){
  int n;
  int m;
  int sum = 0;
  cin >> n >> m;
  int a[m];
  LOOP(i,m){
    cin >> a[i];
    sum += a[i];
  }
  if(sum > n){
    cout << -1 << endl;
  }else{
    cout << n-sum << endl;
  }
}


Measured memory_bytes: 3648
#include<bits/stdc++.h>
using namespace std;
int n;
long long f[87]={2,1};
int main(){
    cin>>n;
    for(int i=2;i<=n;i++)
        f[i]=f[i-1]+f[i-2];
    cout<<f[n]<<'\n';
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
int main(){
  ll l,r;
  cin >> l >> r;
  if (r-l >= 2018 or r%2019 <= l%2019) cout << 0;
  else{
    ll mini=INT_MAX;
    for (ll i=l; i<=r; ++i){
      for (ll j=i+1; j<=r; ++j){
        mini = min(mini,(i*j)%2019);
      }
    }
    cout << mini;
  }
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define REP(i, n) for(ll i=0; i<(ll)n; i++)
#define REPR(i, n) for(ll i=(ll)n-1; i>=0; i--)
#define FOR(i, m, n) for(ll i=(ll)m; i<(ll)n; i++)
#define FORR(i, m, n) for(ll i=(ll)m-1; i>=(ll)n; i--)
#define ALL(x) (x).begin(), (x).end()
#define ASC(v) sort(ALL(v));
#define DESC(v) sort(ALL(v), greater<int>());
#define UNIQ(a) sort(ALL(a));(a).resize(unique(ALL(a)) - a.begin());
#define PRINTD(x, d) cout << fixed << setprecision(d) << x << "\n";
#define DEBUG(x) cout<<#x<<": "<<x<<"\n"
const double PI = acos(-1);
ll lcm(ll a, ll b) { return a / __gcd(a, b) * b; }
bool isprime(int x){ int i; if(x<2)return 0; else if(x==2) return 1; if(x%2==0) return 0; for(i=3; i*i<=x; i+=2) if(x%i==0) return 0; return 1; }
int digsum(int n) { int r=0; while(n>0) { r+=n%10; n/=10; } return r; }
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a = b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a = b; return 1; } return 0; }

int main(){
    ll a, b, c, d;
    cin >> a >> b >> c >> d;
    string res = "No\n";
    if (abs(a-c)<=d) res = "Yes\n";
    else if (abs(a-b)<=d && abs(b-c)<=d) res = "Yes\n";
    cout << res;
}


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

int main() {
    int d,n;
    cin>>d>>n;
    int ans=1;
    for (int i=0;i<d;i++)
        ans*=100;
    cout<<ans*(n+(n==100?1:0))<<endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define endl '\n'
#define rep(i,n); for(long long i = 0;i < (n);i++)
using ll = long long;
using P = pair<long long,long long>;
template <class T> using vec = vector<T>;
const double pi = 3.141592653589;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    double a,b,h,m; cin >> a >> b >> h >> m;
    double deg = (60 * h + m)*pi/360 - m * pi/30;
    cout << fixed << setprecision(10);
    cout << sqrt(a*a + b*b - 2*a*b*cos(deg)) << endl;
}

Measured memory_bytes: 4208
fn main() {
    let stdin = std::io::stdin();
    let mut buf = String::new();
    stdin.read_line(&mut buf).unwrap();
    buf.clear();
    stdin.read_line(&mut buf).unwrap();
    let mut ds: Vec<i32> = buf.split_whitespace().map(|s| s.parse().unwrap()).collect();
    ds.sort();
    for i in 0..ds.len() {
        if i % 2 == 1 {
            ds[i] = 24 - ds[i];
        }
    }
    ds.insert(0, 0);
    ds.sort();
    let mut ps = vec![];
    for i in 0..ds.len() {
        let j = if 0 < i { i - 1 } else { ds.len() - 1 };
        let mut d = (ds[i] - ds[j]).abs();
        if 12 < d {
            d = 24 - d;
        }
        ps.push(d);
    }
    //println!("{:?}", ds);
    //println!("{:?}", ps);
    println!("{}", ps.iter().min().unwrap());
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n;
    cin>>n;
    int a[n],b[n],c[n-1];
    int i;
    for(i=0;i<n;i++){
     cin>>a[i];
     a[i]=a[i]-1;
    }
    for(i=0;i<n;i++)
      cin>>b[i];
    for(i=0;i<n-1;i++)
      cin>>c[i];
    int last=-2;
    long int sum=0;
    for(i=0;i<n;i++){
        if(a[i]!=last+1){
            sum+=b[a[i]];
        }
        else{
            sum = sum+b[a[i]]+c[last];
        }
       last = a[i];
    }
    cout<<sum<<endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define FLASH ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long int
#define debug(x) cerr<<#x<<'='<<(x)<<endl;
using namespace std;
int main()
{
    FLASH
    int a,b,c,d,i =0;
    cin >> a >> b >> c >> d;
    while(a > 0 && c > 0)
    {
        if(i%2 ==0 )
        {
            c-=b;
        }
        else
        {
            a-=d;
        }
        i++;
    }
    if(a > 0)
        cout <<"Yes";
    else
        cout << "No";
    return 0;
}



Measured memory_bytes: 3640
#include<stdio.h>
int main(void)
{
	int n,m,s[10001],x[10001],flg[10001],i,cnt;
	while(1){
		scanf("%d%d",&n,&m);
		if(n==0&&m==0) break;
		for(i=1;i<=m;i++){
			scanf("%d%d",&s[i],&x[i]);
		}
		for(i=1;i<=n;i++){
			flg[i]=0;
		}
		for(i=1;i<=m;i++){
			if(s[i]==1){
				flg[x[i]]=1;
			}
			if(x[i]==1){
				flg[s[i]]=1;
			}
		}
		for(i=1;i<=m;i++){
			if(flg[s[i]]==1 && flg[x[i]]==0){
				flg[x[i]]=2;
			}
			if(flg[x[i]]==1 && flg[s[i]]==0){
				flg[s[i]]=2;
			}
		}
		cnt=0;
		for(i=2;i<=n;i++){
			if(flg[i]==1||flg[i]==2){
				cnt++;
	//			printf("%d\n",i);
			}
		}
		printf("%d\n",cnt);
	}
	return 0;
}

Measured memory_bytes: 2656
#include <algorithm>
#include <bitset>
#include <climits>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

#define MOD 1000000007
#define MOD2 998244353
#define int long long
#define EPS 1e-9
//#define PI 3.14159265358979

#define rep(i, n) for (int i = 0; i < (int)(n); i++)

using namespace std;

template < typename T >
ostream &operator<<(ostream &os, const vector< T > &A) {
	for (int i = 0; i < A.size(); i++)
		os << A[i] << " ";
	os << endl;
	return os;
}
template <>
ostream &operator<<(ostream &os, const vector< vector< int > > &A) {
	int N = A.size();
	int M;
	if (N > 0)
		M = A[0].size();
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < M; j++)
			os << A[i][j] << " ";
		os << endl;
	}
	return os;
}

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

struct edge {
	int from, to, d, c;
	edge(int _from = 0, int _to = 0, int _d = 0, int _c = 0) {
		from = _from;
		to = _to;
		d = _d;
		c = _c;
	}
	bool operator<(const edge &rhs) const {
		return (d == rhs.d) ? (c < rhs.c) : (d < rhs.d);
	}
};
struct aabb {
	int x1, y1, x2, y2;
	aabb(int x1, int y1, int x2, int y2) : x1(x1), y1(y1), x2(x2), y2(y2) {}
};

typedef vector< edge > edges;
typedef vector< edges > graph;
struct flow {
	int to, cap, rev, cost;
	flow(int to = 0, int cap = 0, int rev = 0, int cost = 0) : to(to), cap(cap), rev(rev), cost(cost) {}
};
typedef vector< vector< flow > > flows;

const int di[4] = {0, -1, 0, 1};
const int dj[4] = {-1, 0, 1, 0};
const int ci[5] = {0, 0, -1, 0, 1};
const int cj[5] = {0, -1, 0, 1, 0};
const ll LINF = LLONG_MAX / 2;
const int INF = INT_MAX / 2;
const double PI = acos(-1);

int pow2(int n) { return 1LL << n; }
template < typename T, typename U >
bool chmin(T &x, const U &y) {
	if (x > y) {
		x = y;
		return true;
	}
	return false;
}
template < typename T, typename U >
bool chmax(T &x, const U &y) {
	if (x < y) {
		x = y;
		return true;
	}
	return false;
}

struct initializer {
	initializer() {
		cout << fixed << setprecision(20);
	}
};
initializer _____;

int N, M, K, T, Q, H, W;
signed main() {
	string S;
	cin >> S;
	int N = stoi(S.substr(0, 2));
	int M = stoi(S.substr(2, 4));
	string ans;
	if (1 <= N && N <= 12) {
		if (1 <= M && M <= 12) {
			ans = "AMBIGUOUS";
		} else {
			ans = "MMYY";
		}
	} else {
		if (1 <= M && M <= 12) {
			ans = "YYMM";
		} else {
			ans = "NA";
		}
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
	int i,a,b,c,s,k;
	while(true) {
		for (i=s=c=0;i<5;i++) {
			cin >> a >> b; k=a+b; if (k==0) break;
			if (k>s) { s=k; c=i;}
		}
		if (k==0) break;
		cout << (char)('A'+c) <<  ' ' <<  s << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
/*
 * Author:  heyuhhh
 * Created Time:  2019/11/18 18:16:10
 */
#include <bits/stdc++.h>
#define MP make_pair
#define fi first
#define se second
#define sz(x) (int)(x).size()
#define all(x) (x).begin(), (x).end()
#define INF 0x3f3f3f3f3f3f3f3f
#define Local
#ifdef Local
  #define dbg(args...) do { cout << #args << " -> "; err(args); } while (0)
  void err() { std::cout << '\n'; }
  template<typename T, typename...Args>
  void err(T a, Args...args) { std::cout << a << ' '; err(args...); }
#else
  #define dbg(...)
#endif
void pt() {std::cout << '\n'; }
template<typename T, typename...Args>
void pt(T a, Args...args) {std::cout << a << ' '; pt(args...); }
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
//head
const int N = 300 + 5;

int n, K;

int h[N];
ll dp[N][N];

void run(){
    for(int i = 1; i <= n; i++) cin >> h[i];
    memset(dp, INF, sizeof(dp));
    dp[0][0] = 0;
    for(int i = 1; i <= n - K; i++) {
        for(int j = i; j <= n; j++) {
            for(int k = 0; k < j; k++) {
                dp[j][i] = min(dp[j][i], dp[k][i - 1] + max(0, h[j] - h[k]));   
            }
        }   
    }
    ll ans = INF;
    for(int i = 1; i <= n; i++) ans = min(ans, dp[i][n - K]);
    if(ans == INF) ans = 0;
    cout << ans << '\n';
}

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0); cout.tie(0);
    cout << fixed << setprecision(20);
    while(cin >> n >> K) run();
    return 0;
}//others

Measured memory_bytes: 1024
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <set>
#include <tuple>

using namespace std;
typedef vector<int>VI;
typedef long long LL;

#define IOSWORK ios::sync_with_stdio(0); cin.tie(0)
#define FOR(x, b, e) for(int x = b; x<= (e); x++)
#define FORD(x, b, e) for(int x = b; x>= (e); x--)
#define REP(x, n) for(int x = 0; x<(n); ++x)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(x) ((int)(x).size())
#define VAR(v, n) typeof(n) v = (n)
#define FOREACH(i, c) for(VAR(i, (c).begin()); i != (c).end(); ++i)
#define SCAN_INT(n) scanf("%i",&n)
#define SCAN_P_INT(n,m) scanf("%i %i",&n,&m)
#define PRINT_P_INT(n,m) printf("%i %i\n",n,m);
#define PRINT_INT(n) printf("%i\n",n)

#define PB push_back
#define ST first
#define ND second
#define INF 1000000000


#define MAXSIZE
int a,b;

int main(){

   SCAN_P_INT(a,b);
   PRINT_INT(a*a-b);
}


Measured memory_bytes: 768
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i < (b); i++)
#define rrep(i, a, b) for (int i = a; i >= (b); i--)
#define all(x) (x).begin(), (x).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
template <class T>
inline bool chmin(T& a, T b) {
   if (a > b) {
      a = b;
      return true;
   }
   return false;
}
template <class T>
inline bool chmax(T& a, T b) {
   if (a < b) {
      a = b;
      return true;
   }
   return false;
}
void hr() { cerr << "--------------" << endl; }
const int INF = 1001001001;
const int MOD = 1e9 + 7;

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

   string s;
   cin >> s;
   int n;
   n = s.size();
   vector<int> ans(n);
   rep(ri, 0, 2) {
      {
         int cnt = 0;
         rep(i, 0, n) {
            if (s[i] == 'R')
               cnt++;
            else {
               ans[i] += cnt / 2;
               ans[i - 1] += (cnt + 1) / 2;
               cnt = 0;
            }
         }
      }
      reverse(ans.begin(), ans.end());
      reverse(s.begin(), s.end());
      rep(i, 0, n) {
         if (s[i] == 'L')
            s[i] = 'R';
         else
            s[i] = 'L';
      }
   }
   rep(i, 0, n) { printf("%d%c", ans[i], i != n - 1 ? ' ' : '\n'); }
   return 0;
}

Measured memory_bytes: 1104
#include <bits/stdc++.h>
        using namespace std;
        #define int long long
const int MAX = 200001;
const int MOD = 1000000007;
  int bit[('z'-'a')+1][500001];
        signed main() {
        int n;
        cin>>n;
        string s;
        cin>>s;
        int j,p,q;
        for(int i=1;i<=n;i++){
                j=i;
                while(j<=n){
                        bit[s[i-1]-'a'][j]++;
                        j+=j& -j;

                }
        }
        cin>>q;
        int  l,r,ans,g,l2,r2;char c;
        for(int i=0;i<q;i++){
                cin>>l;
                if(l==1){
                        cin>>l>>c;
                        j=l;
                while(j<=n){
                        bit[s[l-1]-'a'][j]--;
                        j+=j& -j;

                }
                j=l;
                
                while(j<=n){
                        bit[c-'a'][j]++;
                        j+=j& -j;

                }
                s[l-1]=c;
                }else{
                        ans=0;
                        cin>>l2>>r2;l2--;
                         for(int w=0;w<=('z'-'a');w++){
                                 l=l2;r=r2;g=0;
                                while(r){
                            g+=bit[w][r];
                                r-=r& -r;
                        }
                        while(l){
                                g-=bit[w][l];
                                l-=l& -l;
                        }
                        if(g)ans++;
                         } 
                        
                        cout<<ans<<endl;

                }
        }
        


      }


        


Measured memory_bytes: 102532
/**So..a**/
#include<bits/stdc++.h>

using namespace std;
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#define PB(x, v) x.push_back(v);
#define pll pair<ll, ll>
#define ll long long
#define mll map<ll, ll>
#define vl vector<ll>

#define fa(x, v) for(auto x: v)
#define fr(i, a, b) for(int i= a;i <=b; i++)

#define B_ begin()
#define E_ end()
#define all(a) a.begin(), a.end()
#define NL_ "\n"

#define MAX 2000000000
#define F first
#define S second
#define FF first.first
#define FS first.second
#define SF second.first
#define SS second.second

#define mod(a) a%1000000007


int main()
{
    FAST;
    ll n;
    cin >> n;
    ll arr[n];
    for(ll i=0; i< n; i++)
    {
        cin >> arr[i];
    }
    ll mn = LLONG_MAX;
    ll cnt= 0;
    for(int i = 0; i< n; i++)
    {
           mn = min(arr[i], mn);
           if(mn>=arr[i]) cnt++;
    }
     cout << cnt<<NL_;

    return 0;
}


Measured memory_bytes: 5152
#include<bits/stdc++.h>
#define ll long long

using namespace std;
int main(int argc, char const *argv[])
{
	int n,k;
	cin>>n>>k;
	if(k>n)
	{
		k=n-1;
	}
	int arr[100001];
	for(int i=1;i<=n;i++)
	{
		cin>>arr[i];
	}

	ll int dp[n+1];

	ll int dif[k+1];
	ll int mini;

	dp[1]=0;

	//cout<<dp[1]<<" ";
	for(int j=2;j<=k;j++)
	{
		dp[j]=abs(arr[j]-arr[1]);
		//cout<<dp[j]<<" ";
	}
	

	for(int i=k+1;i<=n;i++)
	{
		/*a=dp[i-1]+abs(arr[i]-arr[i-1]);
		b=dp[i-2]+abs(arr[i]-arr[i-2]);*/
		mini=100000000000000;
		for(int j=1;j<=k;j++)
		{
			dif[j]=(dp[i-j]+abs(arr[i]-arr[i-j]));
			if(dif[j]<mini)
				mini=dif[j];
		}
		
		dp[i]=mini;
		//cout<<dp[i]<<" ";
		//cout<<dp[i]<<" ";
	}
//
	//cout<<endl;
	cout<<dp[n]<<endl;
	return 0;
}

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

const int inf = 1e9;
const ll linf = 1e18;
const ll mod = 1e9 + 7;

int main()
{
    int N, M;
    cin >> N >> M;
    vector<ll> A(N);
    for (int i = 0; i < N; i++) cin >> A[i];
    vector<pair<ll, int>> BC(M);
    for (int i = 0; i < M; i++)
    {
        int B;
        ll C;
        cin >> B >> C;
        BC[i] = make_pair(C, B);
    }
    sort(A.begin(), A.end());
    sort(BC.begin(), BC.end());

    int iter = 0;
    for (int i = M - 1; i >= 0; i--)
    {
        for (int j = 0; j < BC[i].second; j++)
        {
            if (BC[i].first < A[iter])
            {
                ll ans = 0;
                for (int k = 0; k < N; k++)
                {
                    ans += A[k];
                }
                cout << ans << endl;
                return 0;
            }
            else
            {
                A[iter] = BC[i].first;
                iter++;
            }
            
        }
        
    }
    ll ans = 0;
    for (int k = 0; k < N; k++)
    {
        ans += A[k];
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2560
#include<iostream>
#include<cmath>
using namespace std;
#define MOD 1000000007
typedef long long ll;
ll sum = 0;
int prime[11000]; 
int main(){
	int n , a , b; cin >> n >> a >> b;
	if(n == 1){
		if(a == b) cout << 1;
		else cout << 0;
		return 0;
	}else if( a > b){
		cout << 0;
		return 0;
	}
	sum = (ll) (b - a) * (n - 2) + 1;
	cout << sum;
	return 0;
}

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

int main() {
	ll a,b,c,w1,w2,w3,cnt=1;
	cin>>a>>b>>c;
	if(a%2!=0 || b%2!=0 || c%2!=0){
		cout<<0<<endl;
		return 0;
	}
	while(1){
		w1=a/2;w2=b/2;w3=c/2;
		if(a==w2+w3 && b==w1+w3 && c==w1+w2 ){
			cout<<-1<<endl;
			return 0;
		}
		a=w2+w3;
		b=w1+w3;
		c=w1+w2;
		if(a%2!=0 || b%2!=0 || c%2!=0){
			break;
		}
		cnt++;
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
//package Dynamic;
import java.io.*;
import java.util.*;
class Main 
{
    static public void main(String[] args) throws IOException 
    {
        BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
        //int n=Integer.parseInt(br.readLine());
        //int ar[]=new int[n];
//        StringTokenizer st=new StringTokenizer(br.readLine());
//        int a=Integer.parseInt(st.nextToken());
//        int b=Integer.parseInt(st.nextToken());
//        int c=Integer.parseInt(st.nextToken());
        //int d=Integer.parseInt(st.nextToken());
//        int i=0;
//        while(st.hasMoreTokens())
//        {
//        	ar[i++]=st.nextToken();
//        }
        //System.out.println();
//        for(int x=0;x<n;x++)
//        {
//        	
//        }
        
        String s=br.readLine();
        char ch[]=s.toCharArray();
        Arrays.sort(ch);
        s=new String(ch);
        if((s.charAt(0)==s.charAt(1))&&(s.charAt(2)==s.charAt(3))&&s.charAt(0)!=s.charAt(2))
        	System.out.println("Yes");
        else
        	System.out.println("No");
    }
}


Measured memory_bytes: 21332
n = gets.to_i
s = n.times.map { gets.chomp }.uniq
h = s.each_with_object(Hash.new(0)) {|name, h| h[name[0]] += 1 if 'MARCH'.chars.include? name[0]}

if h.keys.size < 3
  puts 0
else
  puts h.values.combination(3).reduce(0) {|sum, arr| sum + arr.reduce(&:*)}
end

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

string devide[4] = {"dream","dreamer","erase","eraser"};

int main(){
  string S;
  cin >> S;
  
  reverse (S.begin(),S.end());
  for(int i=0;i<4;++i){
    reverse(devide[i].begin(),devide[i].end());
  }
  
  bool can = true;
  for(int i=0;i<S.size();){
    bool can2 =false;
    for(int j=0;j<4;++j){
      string d = devide[j];
      if(S.substr(i,d.size()) == d){
        can2 = true;
        i += d.size();
      }
    }
if(!can2){
  can = false;
  break;
}
  }
      
  if(can) cout << "YES" <<endl;
  else cout << "NO" << endl;
}



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

using namespace std;
#define ll long long
#define endl '\n'
int main()
{
string h,t;
cin>>h>>t;
int ans=0;
for( int i=0;i<3;i++){
        ans+=h[i]==t[i];
}
cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define IN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef long long ll;
/////////////////////////(๑•﹏•๑｀)/////////////////////////

int main(){
	vector<ll> wv[5];
	ll N,W; cin >> N >> W;
	ll w1,v1; cin >> w1 >> v1;
	wv[0].PB(v1);

	REP(i,N-1){
		ll w,v; cin >> w >> v;
		wv[w-w1].PB(v);
	}

	REP(i,4){
		sort(wv[i].begin(),wv[i].end(),greater<int> () );
	}

	int l0,l1,l2,l3;
	l0 = wv[0].size();
	l1 = wv[1].size();
	l2 = wv[2].size();
	l3 = wv[3].size();

	ll ans = 0;
	FORq(a,0,l0){
		FORq(b,0,l1){
			FORq(c,0,l2){
				FORq(d,0,l3){
					ll nans = 0;
					ll nweight = a * w1 + b * (w1+1) + c * (w1+2) + d * (w1+3);

					if (nweight > W) continue;

					REP(i,a){
						nans += wv[0][i];
					}
					REP(i,b){
						nans += wv[1][i];
					}
					REP(i,c){
						nans += wv[2][i];
					}
					REP(i,d){
						nans += wv[3][i];
					}

					ans = max(ans,nans);
				}
			}
		}
	}


	PRINTLLD(ans);

	return 0;
}
	
	


Measured memory_bytes: 256
//S.G.N.//
#include <bits/stdc++.h>
using namespace std;
typedef vector< long long > vi;
typedef long long ll;
#define sz(a) int((a).size())
#define pb push_back
#define all(c) (c).begin(),(c).end()
#define endl "\n"
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define fr(n) for(ll i=0;i<n;i++)
#define tr(a) for(auto it=a.begin();it!=a.end();it++)
#define N 998244353445 
#define PI 3.1415926535897932384
#define F first
#define S second
#define mp make_pair
#define FAST ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define mod 1000000007

void solve()
{
 ll n,k;
 cin>>n>>k;
 ll a[n];
 fr(n)
 {
  cin>>a[i];
 }
 ll dp[k+1]={0};
 dp[0]=0;
 fr(k+1)
 {
  if(i==0)
    continue;
  ll temp=1;
  rep(j,0,n)
  {
    if(i-a[j]>=0)
    temp=temp&dp[i-a[j]];
  }
  if(temp==1)
    dp[i]=0;
  else
    dp[i]=1;

 }
 cout<<(dp[k]?"First":"Second");
}
int main()
{
  
  #ifndef ONLINE_JUDGE
     * freopen("input.txt", "r", stdin);
      freopen("output.txt", "w", stdout);
  #endif
  FAST
  ll test;
test=1;
  //cin>>test;
  while(test--)
  {
    solve();
  }
  return 0;
}

Measured memory_bytes: 4360
function Main(input) {
  input = input.split("\n");
  var mod = Math.pow(10,9)+7;
  var H = parseInt(input[0].split(" ")[0]);
  var W = parseInt(input[0].split(" ")[1]);
  input.shift();
  var a = input.map(i => i.split(""));
  var map=new Array(H);
  for(var i=0;i<H;i++){
    var tmp=new Array(W);
    map[i]=tmp;
  }
  input.pop();
  for(var i=0;i<H;i++){
    for(var j=0;j<W;j++){
      if(a[i][j]=="."){
        if(i==0){
          if(j==0){
            map[i][j]=1;
          }else{
            map[i][j]=map[i][j-1];
          }
        }else if(j==0){
          map[i][j]=map[i-1][j];
        }else{
          map[i][j]=(map[i-1][j]+map[i][j-1])%mod;
        }
      }else{
        map[i][j]=0;
      }
    }
  }
  var ans=map[H-1][W-1];

  console.log('%s', ans);
  return ans;
}
// "実行する"ボタンを押した時に実行される関数 (デバッグ用)
function debug(n){
  var input = document.getElementById("input"+n).value;
  var ans=Main(input);
  var result="WA";
  if(ans==document.getElementById("output"+n).value.split("\n")[0]){
    result="AC";
  }
  document.getElementById("result"+n).innerHTML=result;
}
Main(require("fs").readFileSync("/dev/stdin", "utf8"));

Measured memory_bytes: 53052