akhauriyash/Code-Regression huggingface dataset:
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int[] ary = new int[n];
		for(int i = 0; i < n; i++){
			ary[i] = -1;
		}
		int m = sc.nextInt();
		boolean isPossible = true;
		for(int i = 0; i < m; i++){
			int s = sc.nextInt();
			int c = sc.nextInt();
			if(ary[s - 1] != c && ary[s - 1] != -1){
				isPossible = false;
			}else{
				ary[s - 1] = c;
			}
		}
		if(n > 1 && ary[0] == 0){
			isPossible = false;
		}
		if(ary[0] == -1){
			if(n == 1){
				ary[0] = 0;
			}else{
				ary[0] = 1;
			}
		}
		for(int i = 1; i < n; i++){
			if(ary[i] == -1){
				ary[i] = 0;
			}
		}
		String ans = "";
		for(int i = 0; i < n; i++){
			ans += ary[i];
		}
		System.out.println(isPossible ? ans : "-1");
	}
}


Measured memory_bytes: 23636
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
    string s[100];
    cin >> n;
    for(int i = 0; i < n; i++){
        cin >> s[i];
    }
    for(int i = 0; i < n; i++){
        for(int j = i + 1; j < n; j++){
             if(s[i] == s[j]){
                 cout << "No" << endl;
                return 0;
             }
        }
    }
    for(int i = 0; i < n - 1; i++){
        if(s[i][s[i].size() - 1] != s[i + 1][0]){
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
}

Measured memory_bytes: 256
open Scanf
open Printf

let flip f x y = f y x

let rec range a b = if a >= b then [] else a :: range (a+1) b

let read_int () = scanf " %d" (fun x -> x)
let rec read_ints n = if n = 0 then [] else let i = read_int () in i :: read_ints (n-1)

let rec rep n f =
  if n = 0 then []
  else let h = f () in h :: rep (n-1) f

let solve n m graph =
  let pos = Array.make n None in
  let rec visit v p x =
    Array.fold_left (fun res (w, d) ->
      res && (
      match pos.(w) with
      | None   -> pos.(w) <- Some (x + d); visit w v (x+d)
      | Some y -> y = x + d
      )) true graph.(v) in
  List.for_all (fun v ->
    match pos.(v) with
    | None -> visit v (-1) 0
    | _ -> true
  ) (range 0 n)

let () =
  let [n; m] = read_ints 2 in
  let idcs = Array.make n 0 in
  let edges = rep m (fun () ->
    let [l; r; d] = read_ints 3 in
    idcs.(l-1) <- idcs.(l-1) + 1;
    idcs.(r-1) <- idcs.(r-1) + 1;
    (l-1, r-1, d)) in
  let graph = Array.init n (fun i -> Array.make idcs.(i) (-1, -1)) in
  Array.fill idcs 0 n 0;
  flip List.iter edges (fun (l, r, d) ->
    graph.(l).(idcs.(l)) <- (r, d);
    graph.(r).(idcs.(r)) <- (l, -d);
    idcs.(l) <- idcs.(l) + 1;
    idcs.(r) <- idcs.(r) + 1;
  );
  let result = solve n m graph in
  printf "%s\n" (if result then "Yes" else "No")


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

using namespace std;

#define int long long

constexpr int INF = 1LL << 60;
constexpr double EPS = 1.0e-11;

typedef pair<int, int> pii;
typedef pair<int, pii> pipii;

signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(16);

    double a, b, x;
    cin >> a >> b >> x;
    double l = 0, r = M_PI / 2.0;
    while (EPS < r - l)
    {
        auto mid = (r + l) / 2.0;
        auto h = a * tan(mid);
        double v;
        if (b < h) {
            auto ph = M_PI / 2.0 - mid;
            auto h2 = b * sin(ph);
            auto d = h2 * tan(ph) + b * cos(ph);
            v = a * d * h2 / 2.0;
        } else {
            v = a * a * h / 2.0 + a * a * (b - h);
        }
        if (x <= v)
        {
            l = mid;
        }
        else
        {
            r = mid;
        }
    }

    cout << l / M_PI * 180.0 << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
  
int main(void){
    int n, d, x;
    cin >> n >> d >> x;
    
    int A[105];
    for(int i=0; i<n; i++) cin >> A[i];
    
    int ans = 0;
    
    for(int i=0; i<n; i++){
        ans++;
        for(int j=1; j<=d; j++){
            if(j*A[i]+1 <= d) ans++;
        }
    }
    ans += x;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict, deque, Counter
from heapq import heappush, heappop, heapify
from itertools import permutations, accumulate, combinations, combinations_with_replacement
from math import sqrt, ceil, floor, factorial
from bisect import bisect_left, bisect_right, insort_left, insort_right
from copy import deepcopy
from operator import itemgetter
from functools import reduce, lru_cache  # @lru_cache(None)
from fractions import gcd
import sys  # def input(): return sys.stdin.readline().rstrip() # sys.setrecursionlimit(10**6)

A = [26**i for i in range(1, 13)]
Acc = list(accumulate(A))
n = int(input())
l = bisect_left(Acc, n)
# a = ord("a")

ANS = []
for i in range(l+1):
    tmp = n % 26 if n % 26 != 0 else 26
    ANS.append(chr(ord("a")-1+tmp))
    n -= tmp
    n //= 26
ANS.reverse()
print("".join(ANS))


Measured memory_bytes: 10572
def end_check(score):
    end_judge = False
    if(score.count("-1") == 3):
        return True
    return end_judge

def evalution_check(score):
    total_score= int(score[0]) + int(score[1])
    re_test_score = int(score[2])

    score_evalution = "F"

    if (score.count("-1") > 1):
        score_evalution = "F"
    elif (total_score >= 80):
        score_evalution = "A"
    elif (total_score >= 65):
        score_evalution = "B"
    elif (total_score >= 50 or re_test_score >= 50):
        score_evalution = "C"
    elif (total_score >= 30):
        score_evalution = "D"


    return score_evalution

def print_evalutions(evalutions):
    for evalution in evalutions:
        print(evalution)

evalutions =[]

while True:
    score = list(input().split())

    if(end_check(score)):
        break

    evalutions.append(evalution_check(score))

print_evalutions(evalutions)

    


Measured memory_bytes: 5600
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < n; ++i)
#define ALL(c) (c).begin(), (c).end()
#define SUM(x) std::accumulate(ALL(x), 0LL)
#define MIN(v) *std::min_element(v.begin(), v.end())
#define MAX(v) *std::max_element(v.begin(), v.end())
#define EXIST(v, x) (std::find(v.begin(), v.end(), x) != v.end())
#define FORV(i, v) for (auto i = v.begin(); i != v.end(); i++)
using namespace std;

typedef long long ll;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
const ll INF = 1e9;
const long long INFL = 1LL<<60;

int main() {
  int a, b;
  cin >> a >> b;
  if (a <= b) {
    cout << a << endl;
  } else {
    cout << a - 1 << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define fo(i,a,b) for((i)=(a);i<=(b);i++)
#define rfo(i,a,b) for((i)=(a);i>=(b);i--)
#define inrange(x,y,z) (((x)>=(y))&&((x)<=(z)))
#define ALL(vec) ((vec).begin(),(vec).end())
#define SOR(vec) sort(ALL(vec))
#define UNI(vec) (vec).erase(unique(ALL(vec)),(vec).end())
using namespace std;
int n;
int a[200100],pmin,cnt;
int main(){
	#ifdef FILIN
		#ifndef DavidDesktop
			freopen(FILIN,"r",stdin);
			freopen(FILOUT,"w",stdout);
		#endif
	#endif
	ios::sync_with_stdio(0);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n;
	for(int i=1;i<=n;i++)
		cin>>a[i];
	pmin=1e9;
	for(int i=1;i<=n;i++){
		if(a[i]<=pmin) cnt++;
		pmin=min(pmin,a[i]);
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 1024
h, w = map(int, input().split())
grid = [list(input()) for _ in range(h)]

for i in range(h):
    for j in range(w):
        if grid[i][j] == '.':
            grid[i][j] = 0

dict = (
    (-1, -1),
    (-1, 0),
    (-1, 1),
    (0, -1),
    (0, 1),
    (1, -1),
    (1, 0),
    (1, 1),
)

for i in range(h):
    for j in range(w):
        t = grid[i][j]
        if t == '#':
            continue

        for dy, dx in dict:
            y = i - dy
            x = j - dx
            if y >= 0 and h > y and x >= 0 and w > x:
                z = grid[y][x]
                if z == '#':
                    grid[i][j] += 1

answer = '\n'.join(map(lambda el: ''.join(map(str, el)), grid))
print(answer)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define fio ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define pb push_back
#define mp make_pair
typedef long long ll;
const int INF = 1<<29;
const int N = 1e6 + 9;
ll a[N];
int main()
{
    fio;
   ll n, k = 0;
   cin >> n;
   for(int i = 0; i < n; i ++)
   {
       cin >> a[i];
       if(a[i] % 2 == 0){
        if(a[i] % 3 == 0 || a[i] % 5 == 0){
            k = 1;
        }
        else{
            cout << "DENIED";
            return 0;
        }
       }
   }
  cout << "APPROVED";
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

    public static void main(String[] args) {

        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int y = in.nextInt();
        if (n >= 10) {
            System.out.println(-1);
        } else if (y >= 10) {
            System.out.println(-1);
        } else {
            System.out.println(n * y);
        }

    }

}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
int n,w;
long long dp[101000];
int a,b;
int main()
{
	cin>>n>>w;
	for(int i=0;i<n;i++)
	{
		cin>>a>>b;
		for(int j=w-a;j>=0;j--)
			dp[j+a]=max(dp[j]+b,dp[j+a]);
	}
	long long res;
	for(int i=0;i<=w;i++)
		res=max(res,dp[i]);
	cout<<res<<"\n";
	return 0;
}

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

struct Node{
  int k;
  Node *r, *l, *p;
};

Node *T;
Node *NIL;

void insert(int key){

  Node *x = T;
  Node *y = NIL;
  Node *z;
  z = new Node;
  z->k = key;
  z->l = z->r = NIL;

  while(x != NIL){
    y = x;
    if(z->k > x->k){
      x = x->r;
    }else if(z->k < x->k){
      x = x->l;
    }

  }
    z->p = y;

    if(y == NIL){
      T = z;
    }else if(z->k < y->k){
      y->l = z;
    }else if(z->k > y->k){
      y->r = z;
    }
}

void in_print(Node *r){
  if(r == NIL) return;
  in_print(r->l);
  cout << " " << r->k;
  in_print(r->r);
}

void pre_print(Node *r){
  if(r == NIL) return;
  cout << " " << r->k;
  pre_print(r->l);
  pre_print(r->r);
}


int main(){

  int n;
  cin >> n;

  for(int i = 0; i < n; i++){
    string str;
    int k;
    cin >> str;

    if(str == "insert"){
      cin >> k;
      insert(k);
    }else if(str == "print"){
      in_print(T);
      cout << endl;
      pre_print(T);
      cout << endl;
    }
  }



}

Measured memory_bytes: 24652
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define fi first
#define se second

int L,R;
vector<int> rem;
signed main(){
	cin >> L >> R;
	for(int i = L ; i <= min(R, L + 2018) ; i ++)
		rem.push_back(i%2019);
	int ans = 2018;
	for(int i = 0 ; i < rem.size() ; i ++)
		for(int j = i + 1 ; j < rem.size() ; j ++)
			ans = min(ans, (rem[i] * rem[j])%2019);
	cout << ans;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<cstdlib>
template<typename T>
void fin(T const& t){ std::cout << t << std::endl; exit(0); }

int main() {
  int N; std::cin >> N;
  std::vector<int> d(N);
  for(int i = 0; i < N; ++i) std::cin >> d[i];
  std::sort(d.begin(), d.end());
  int l = d[N/2-1], r = d[N/2];
  fin(r-l);
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <string>
#include <sstream>
#include <iomanip> 
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <queue>
#include <stack>
#include <vector>
#include <map>
#include <set>
#include <functional>
#include <algorithm>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <random>

using namespace std;


// range query using fenwick tree
// note index starts at 1

class fenwick_tree {
	vector<long long> t;
	long long size;
public:
	fenwick_tree(long long n) {
		t.assign(n + 1, 0);
		size = n + 1;
	}

	long LSOne(long long k) {	// least significant 1-bit
		return k & (-k);
	}

	void update(long long index, long long val) {	// can go up or go down
		for (; index < size; index += LSOne(index)) t[index] += val;
	}

	long long query_full(long long a, long long b) {		// range query
		return query(b) - ((a <= 1) ? 0 : query(a - 1));
	}

	long long query(long long b) {	// range query 1..b
		if (b < 1) return 0;

		long long sum = 0;
		for (; b; b -= LSOne(b)) sum += t[b];
		return sum;
	}
};



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

	long long n, i, j, k, ans, aa, bb, cc, ss, x, goal;
	cin >> n;
	vector<long long> a(n), b(n), s(n + 1);
	for (i = 0; i < n; i++) cin >> a[i]; 

	goal = (n * (n + 1) / 2 + 1) / 2;

	aa = 1; bb = 1E9;
	while (aa < bb) {
		cc = (aa + bb + 1) / 2;

		// reprocess a->b, s
		s[0] = n + 1;
		for (i = 0; i < n; i++) {
			if (a[i] >= cc) b[i] = 1;
			else b[i] = -1;
			s[i + 1] = s[i] + b[i];
		}

		fenwick_tree ft(2 * n + 1);
		ss = 0;		// # of medians >= cc
		for (i = 0; i <= n; i++) {
			x = ft.query_full(1, s[i]);
			ss += x;
			ft.update(s[i], 1);
		}

		if (ss < goal) bb = cc - 1;
		else aa = cc;
	}

	cout << aa << "\n";


	return 0;
}


Measured memory_bytes: 6848
#include <iostream>

using namespace std;
using ll = long long;
using ld = long double;

#define ALL(x) begin(x), end(x)
#define REP(i, n) for (size_t i = 0, i##_len = (n); i < i##_len; ++i)

const string YES = "Yes";
const string NO = "No";

void solve(ll A, ll B, ll C) {
  bool pred = A + B >= C;
  cout << (pred ? YES : NO) << endl;
}

int main() {
  ll A;
  cin >> A;
  ll B;
  cin >> B;
  ll C;
  cin >> C;
  solve(A, B, C);
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
int a[1000005];
using namespace std;


int main(){
    long long n,m;
    int i,j;
    long long x;
    cin>>m>>n;
    for(i=1;i<=n;i++)
    {
        scanf("%lld",&x);
        m-=x;
    }
    if(m>=0)printf("%lld\n",m);
    else puts("-1");
    return 0;
}


Measured memory_bytes: 3760
#include <iostream>

using namespace std;

int main() {
    int x, a, b;
    cin >> x >> a >> b;
    a *= -1;
    if(a+b <= 0){
        cout << "delicious" << endl;
    }
    else if(a+b <= x){
        cout << "safe" << endl;
    }
    else{
        cout << "dangerous" << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#pragma GCC diagnostic ignored "-Wsign-compare"
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (int i = 1; i <= int(n); ++i)

void solve() {
    int N, X;
    for (;;) {
        cin >> N >> X;
        if (N == 0 && X == 0) {
            break;
        }
        int cur = 0;
        rep(i, N) {
            for (int j = i + 1; j <= N; ++j) {
                for (int k = j + 1; k <= N; ++k) {
                    if (i + j + k == X) {
                        cur++;
                    }
                }
            }
        }
        cout << cur << "\n";
    }
}
int main() {
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();
}


Measured memory_bytes: 3176
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <cstdio>
#include <cstring>
#include <cmath>
#define For(i,a,b) for(int i=(a); i<(b); i++)
using namespace std;

const double pi=3.1415926;

int main(){
	double r;
	cin>>r;
	cout<<2*pi*r;
	return 0;
}

Measured memory_bytes: 3784
=begin
n, k
考えられる和は、{ i*1e100 + j | i in k .. n+1; j in 

=end
M = 1_000_000_007
require "openssl"
n, k = gets.split.map &:to_i
p (k .. n+1).sum { |i| (n-i+1)*i+1 } % M
#l = n-k+1
#p (0 .. l).sum { |i| (l*k+1 -(l-k)*i -i*i) % M } % M

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

for i in range(1, min(N, K)+1):
    for j in range(i+1):
        holdings = []
        holdings.extend(V[:j])
        holdings.extend(V[N-i+j:])
        if i < K:
            holdings.sort(reverse = True)
            for _ in range(K-i):
                if holdings and holdings[-1] < 0:
                    holdings.pop()
        maxVal = max(maxVal, sum(holdings))
print(maxVal)


Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define pb push_back
#define all(con) (con).begin(), (con).end()
const int N = 1e5 + 5;
const int mod = 1e9 + 7;
void solve();
signed main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int tests = 1;
    // cin >> tests;
    while (tests--)
        solve();

    return 0;
}
void solve()
{
    int x,y;
    cin >> x >> y;
    for(int i = 0;i<=x;i++){
        if(i*2 + (x-i)*4 == y){
            cout << "Yes" << endl;
            return;
        }
    }
    cout<<"No"<<endl;
}


Measured memory_bytes: 3640
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
using namespace std;

int main(){
    bool ansb = true;
    int ansi = 0;
    int p = 0;
    int n,k;
    cin >> n >> k;
    if((n-1)*(n-2)/2 < k){
        ansb = false;
    }
    int M = n-1 +(n-1)*(n-2)/2 -k;
    if(ansb){
        cout << M << endl;
        for(int i = 1; i < n+1; i ++){
            for(int j = i +1; j < n+1; j ++){
                if(p < M){
                    cout << i << " " << j << endl;
                    p++;
                }
            }
        }
    }else{
        cout << -1 << endl;
    }
}

Measured memory_bytes: 256
N,M=map(int,input().split())
H = list(map(int,input().split()))
A,B=[],[]
good = N
for m in range(M):
    a,b = map(int,input().split())
    A.append(a)
    B.append(b)
routes = [[] for i in range(N)]
for m in range(M):
    routes[A[m]-1].append(B[m]-1)
    routes[B[m]-1].append(A[m]-1)

for n in range(N):
    L = len(routes[n])
    for l in range(L):
        if H[n] <= H[routes[n][l]]:
            good -=1
            break
print(good)

Measured memory_bytes: 37776
#include <bits/stdc++.h>
using namespace std;
#define REP(i, s, n) for (int i = s; i < n; ++i)
#define rep(i, n) REP(i, 0, n)
#define SORT(c) sort((c).begin(), (c).end())
#define IINF INT_MAX
#define LLINF LLONG_MAX
#define DEBUG false
// sort(a.begin(), a.end(), std::greater<int>());

/*
std::vector<std::string> split(const std::string &input, char delimiter)
{
    std::istringstream stream(input);

    std::string field;
    std::vector<std::string> result;
    while (std::getline(stream, field, delimiter))
    {
        result.push_back(field);
    }
    return result;
}
*/
/*
int dfs(int foo, int timer)
{
    //foo is node number
    if (finds[foo].first != -1)
        return timer;
    finds[foo].first = ++timer;
    int result = timer;
    if (data[foo].size() != 0)
    {
        rep(i, data[foo].size())
        {
            result = dfs(data[foo][i], result);
        }
    }
    finds[foo].second = ++result;
    return result;
}
*/
int main()
{
    string a, b;
    cin >> a;
    b = "000";
    if (a.find(b) != string::npos)
    {
        cout << "Yes" << endl;
        return 0;
    }
    REP(i, 1, 9)
    {
        if (a.find(b) != string::npos)
        {
            cout << "Yes" << endl;
            return 0;
        }
        b = to_string(111 * i);
    }

    cout << "No" << endl;
    return 0;
}


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

using namespace std;

using ll = long long;
using P = pair<ll, ll>;
using Graph = vector<vector<ll>>;
#define rep(i, n) for(ll i=0;i<(ll)(n);i++)
#define rep2(i, m, n) for(ll i=m;i<(ll)(n);i++)
#define rrep(i, n, m) for(ll i=n;i>=(ll)(m);i--)
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};
const int ddx[8] = {0, 1, 1, 1, 0, -1, -1, -1};
const int ddy[8] = {1, 1, 0, -1, -1, -1, 0, 1};
const ll MOD = 1000000007;
const ll INF = 1000000000000000000L;
#ifdef __DEBUG

/**
 * For DEBUG
 * https://github.com/ta7uw/cpp-pyprint
 */
#include "cpp-pyprint/pyprint.h"

#endif

vector<ll> divisor(ll N) {
    vector<ll> res;
    for (ll i = 1L; i * i <= N; ++i) {
        if (N % i == 0) {
            res.push_back(i);
            ll j = N / i;
            if (j != i)  {
                res.push_back(j);
            }
        }
    }
    sort(res.begin(), res.end());
    return res;
}

void solve() {
    ll N;
    cin >> N;
    vector<ll> A(N);
    rep(i, N) cin >> A[i];

    map<ll, ll> B;
    rep(i, N) {
        ll a = A[i];
        B[a] ++;
    }

    ll ans = 0;
    rep(i, N) {
        ll a = A[i];
        bool ok = true;
        for (ll d : divisor(a)) {
            if (B.count(d)) {
                if (d == a && B[d] == 1) continue;
                ok = false;
                break;
            }
        }
        if (ok) {
            ans ++;
        }
    }
    cout << ans << '\n';
}

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


Measured memory_bytes: 17120
def make_divisors(n):
    divisors = []
    for i in range(1, int(n**0.5)+1):
        if n % i == 0:
            divisors.append(i)
            if i != n // i:
                divisors.append(n//i)

    # divisors.sort()
    return divisors


n = int(input())
divisors = make_divisors(n)

ans = 10**12
if len(divisors) % 2 == 0:
    for i in range(0, len(divisors), 2):
        ans = min(ans, divisors[i]+divisors[i+1])

else:
    for i in range(0, len(divisors)-1, 2):
        ans = min(ans, divisors[i]+divisors[i+1])
    ans = min(ans, divisors[-1]*2)
print(ans-2)


Measured memory_bytes: 3268
#include<iostream>
#include<string.h>
using namespace std;
int main() 
{
  string s,t;
  cin >> s >> t;
  
  int l = s.length();
  
  for(int i = 0;i<=l; i++){
    if(s[i] != t[i]){
      cout << "No";
      break;
    }
    else if (i == l - 1){
	  cout << "Yes";
      break;
    }
  }
}


Measured memory_bytes: 3632
from sys import stdin
import sys
import math

N = int(input())
A = [int(input()) for i in range(N)]

h = {}

for i in A:
    h[i] = 0

for j in A:
    h[j] += 1


count = 0
for val in h.values():
    if val % 2 == 1:
        count += 1

print(count)


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


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

typedef set<int>::iterator sit;
typedef map<int,int>::iterator mit;
typedef vector<int>::iterator vit;

const int INF = 1e9 + 7;
const int MOD = 1e9 + 7;
const int MAXN = 1e6 + 3;

#define _  %  MOD
#define __ %= MOD

#define      each(it,s)        for(auto it = s.begin(); it != s.end(); ++it)
#define      sortA(v)          sort(v.begin(), v.end())
#define      sortD(v)          sort(v.begin(), v.end(), greater<auto>())
#define      fill(a)           memset(a, 0, sizeof (a))

#define      swap(a,b)        {a=a+b;b=a-b;a=a-b;}
#define      rep(i, n)         for(ll i = 0; i < (n); ++i)
#define      repA(i, a, n)     for(ll i = a; i <= (n); ++i)
#define      repD(i, a, n)     for(ll i = a; i >= (n); --i)
#define watch(x) cout << (#x) << " is " << (x) <<endl

#define fi first
#define se second
#define mp make_pair
#define pb push_back

#define fbo find_by_order
#define ook order_of_key

ll gcd(ll a,ll b){if(b==0) return a; else return gcd(b,a%b);}
ll power(ll x,ll y){ll res=1; while(y>0){if(y&1) res=res*x;y=y>>1;x=x*x;}return res;} // modular exponent

int main()
{
    ios_base::sync_with_stdio(false); // don't use printf and scanf
    cin.tie(NULL); // cout<<fixed<<setprecision
    ll n;
    cin>>n;
    ll ans=(n)*(n+1)*(n+2);
    ans/=6ll;
    rep(i,n-1)
    {
      ll a,b;
      cin>>a>>b;
      if(a>b) swap(a,b);
      ans-=(a)*(n-b+1);
    }
    cout<<ans<<'\n';
    return 0;
}
// JUST ASK YOURSELF DID YOU GIVE YOUR BEST ? ISSE ZYADA
// KUCH KAR BHI NAHI SAKTE !! ENJOY AND GIVE YOUR BEST!!


Measured memory_bytes: 3624
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <math.h>
#include <time.h>
#include <iostream>
#include <algorithm>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <iomanip>
#include <assert.h>
#include <fstream>

using namespace std;

typedef long long ll;

const int MAXN = 200005;

int n;
int a[MAXN];
int b[MAXN];

ll ans;

queue<int> Q;

void check(int i)
{
	if (b[i] - b[(i - 1 + n) % n] - b[(i + 1) % n] >= a[i])
		Q.push(i);
}

int main()
{
	scanf("%d",&n);
	for (int i = 0;i < n;i++)
		scanf("%d",&a[i]);
	for (int i = 0;i < n;i++)
		scanf("%d",&b[i]);
	for (int i = 0;i < n;i++)
		check(i);
	while (!Q.empty())
	{
		int cur = Q.front(),v = b[(cur - 1 + n) % n] + b[(cur + 1) % n],t = (b[cur] - a[cur]) / v;
		Q.pop();
		b[cur] -= t * v;
		check((cur - 1 + n) % n);
		check((cur + 1) % n);
		ans += t;
	}
	for (int i = 1;i <= n;i++)
		if (b[i] != a[i])
		{
			puts("-1");
			return 0;
		}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 2176
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <numeric>
#include <cmath>
#include <vector>
#include <list>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <map>
#include <tuple>
#include <cstring>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<long long, long long> P;
#define rep(i, n) for(long long i=0; i<n; i++)
#define reps(i, s, e) for(long long i=s; i<e; i++)
#define repr(i, n) for(long long i=n-1; i>=0; i--)
#define reprs(i, s, e) for(long long i=e-1; i>=s; i--)

int main(){

    cin.tie(0);
    ios::sync_with_stdio(false);

    ll n; cin >> n;
    string s, t; cin >> s >> t;

    string ans;
    rep(i, n){
        ans.push_back(s[i]);
        ans.push_back(t[i]);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
/*
  Motto - try hard to become an expert
*/
#include <bits/stdc++.h>
#include <map>
#include <algorithm>
#include <vector>
#include <string.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <chrono>
#include <thread>
#include <iomanip>
 
//define
#define rep(i,n)    for(int i=0;i<n;i++)
#define repu(i,k,n) for(int i=k;i<=n;i++)
#define repd(i,k,n) for(int i=k;i>=n;i--)
#define se second
#define fi first
#define pb push_back
#define mp make_pair
#define INF (int)INT_MAX
#define all(v)  v.begin(), v.end()
#define endl "\n"
 
//typedef
typedef long long int ll;
typedef long double ld;
typedef std::pair<int, int> pii;
typedef std::vector<int> vi;
typedef std::vector< pii > vii;
typedef std::vector< ll > vll;
typedef std::vector< std::pair < pii, int > > vpp;
 
const int N = 3*1e5 +5 ;
const long long MOD = 1e9 + 7;
const long long inf = 1e18;
 
using namespace std;
 

ll modpow(ll x,ll n){
    ll res=1;
    while(n>0){
        if(n&1) res=res*x%MOD;
        x=x*x%MOD;
        n>>=1;
    }
    return res;
}
 
ll modFact(ll n, ll p) 
{ 
    if (n >= p) 
        return 0; 
  
    ll result = 1; 
    for (ll i = 1; i <= n; i++) 
        result = (result * i) % p; 
  
    return result;  
} 
 
bool isPrime(int x)
{
    if(x%2==0)
        return 0;
    for(int i=3;i<=sqrt(x);i+=2)
    {
        if(x%i==0)
            return 0;
    }
    return 1;
}
 
ll binomialCoeff(ll n, ll k) 
{ 
	ll C[n + 1][k + 1]; 
	ll i, j; 


	for (i = 0; i <= n; i++) 
	{ 
		for (j = 0; j <= min(i, k); j++) 
		{ 
			
			if (j == 0 || j == i) 
				C[i][j] = 1; 

			else
				C[i][j] = (C[i - 1][j - 1] + 
										C[i - 1][j])%MOD; 
		} 
	} 

	return C[n][k]; 
}
bool compare(const string &a , const string&b){
	
}
 
void solve()
{
    ll n , w ;
    cin>>n>>w ;
    ll weight[n+1] , value[n+1] ;
    rep(i , n)cin>>weight[i+1]>>value[i+1] ;
    ll N = 1e5 + 1 ;
    ll dp[N+1] ;
    rep(i , N+1){
    	dp[i] = 1e18 ;
    }
    ll V = 0 ;
    rep(i , n){
    	V += value[i+1] ;
    }
    // cout<<dp[N]<<endl;
    dp[0] = 0 ;
    for(int i = 1  ;  i<=n;i++){
    	repd(j , V , 0){
    		if(j-value[i]>=0){
    			dp[j] = min(dp[j] , dp[j-value[i]]+weight[i]) ;
    		}
    	}
    }
    
    repd(i , V , 0){
    	if(dp[i]<=w){
    		cout<<i;
    		return;
    	}
    }
}
 
int main() {
    #ifndef ONLINE_JUDGE
        // for getting input from input.txt
        freopen("input.txt", "r", stdin);
        // for writing output to output.txt
        freopen("output.txt", "w", stdout);
    #endif
    
    ios_base::sync_with_stdio(0);
    cin.tie(NULL);
    int t = 1;
    //cin>>t;
    while(t--)
    {
        solve();
    } 
    cerr << "Time : " << 1000 * ((double)clock()) / (double)CLOCKS_PER_SEC << "ms\n";
}

Measured memory_bytes: 4632
#include <cstdio>
#include <algorithm>

typedef long long ll;
const int maxn=16,maxm=18,maxk=(1<<maxn)+maxn,mod=1000000007;
int key[maxm],cnt[maxk];
ll fac[maxk],ifac[maxk],f[maxm][maxk],g[maxm];

ll power(ll a,ll b){
	ll ret=1;
	while(b){
		if(b&1)ret=ret*a%mod;
		a=a*a%mod;
		b>>=1;
	}
	return ret;
}

ll inv(ll a){
	return power(a,mod-2);
}

ll C(int n,int m){
	if(n<m)return 0;
	else return fac[n]*ifac[m]%mod*ifac[n-m]%mod;
}

int main(){
	// freopen("in.txt","r",stdin);
	int n,m,lim;
	scanf("%d%d",&n,&m);lim=1<<n;
	for(int i=1;i<=m;++i)scanf("%d",key+i);
	std::sort(key+1,key+m+1);
	fac[0]=ifac[0]=1;
	for(int i=1;i<=lim;++i)fac[i]=fac[i-1]*i%mod;
	ifac[lim]=inv(fac[lim]);
	for(int i=lim-1;i>=1;--i)ifac[i]=ifac[i+1]*(i+1)%mod;
	for(int i=1;i<lim;++i)cnt[i]=cnt[i>>1]+(i&1);
	f[m+1][0]=1;
	for(int i=m;i>=1;--i){
		for(int j=0;j<lim;++j)if(f[i+1][j]){
			f[i][j]+=f[i+1][j];
			for(int k=0;k<n;++k)if(!(j&(1<<k)))
				f[i][j|(1<<k)]+=f[i+1][j]*C(lim-key[i]-j,(1<<k)-1)%mod*fac[1<<k]%mod;
		}
		for(int j=0;j<lim;++j)
			f[i][j]%=mod;
	}
	for(int i=0;i<lim;++i)
		g[cnt[i]]=(g[cnt[i]]+f[1][i]*fac[lim-i-1]%mod)%mod;
	ll ans=0;
	for(int i=0;i<=n;++i)
		ans=(ans+g[i]*(i%2?-1:1)+mod)%mod;
	printf("%lld\n",ans*lim%mod);
	// printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 10112
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;
typedef vector<LL> VI;
typedef vector<VI> VVI;
typedef pair<LL, LL> PII;
typedef vector<string> VS;
inline LL toInt(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(x,c) for(auto x: (c))
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define REVERSE(c) reverse((c).begin(), (c).end())
#define SORT(c) sort((c).begin(),(c).end())
#define RSORT(c) sort((c).rbegin(),(c).rend())
#define STABLE_SORT(c) stable_sort((c).begin(),(c).end())
#define STABLE_RSORT(c) stable_sort((c).rbegin(),(c).rend())
#define UNIQUE(c) SORT(c); (c).erase(unique((c).begin(), (c).end()), (c).end());
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
const double INF = 1e7;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
#define dump(x)  cerr << #x << " = " << (x) << endl;


int main() {
	LL N;
	cin >> N;
	VI h(N);
	REP(i, N) {
		cin >> h[i];
	}

	LL count = 0;
	while (1) {
		LL i, j;
		for (i = 0; i < N; i++) {
			if (h[i] > 0) {
				break;
			}
		}
		if (i == N) {
			break;
		}
		for (j = i + 1; j < N; j++) {
			if (h[j] == 0) {
				break;
			}
		}
		for (LL k = i; k < j; k++) {
			h[k]--;
		}
		count++;
	}

	cout << count << endl;
	
    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Main main = new Main();
		main.solve();
	}

	void solve() {
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		double[]val = new double [n];
		String[] type = new String[n];
		for(int i= 0;i<n;i++) {
			val[i] = Double.parseDouble(sc.next());
			type[i] = sc.next();
		}
		sc.close();
		long Yen = 0;
		double BTC = 0;
		for(int i=0;i<n;i++) {
			if(type[i].equals("JPY")) {
				Yen += val[i];
			}else if(type[i].equals("BTC")){
				BTC += val[i];
			}
		}

		BTC *= 380000;
		System.out.println(Yen+BTC);
	}

}




Measured memory_bytes: 23252
#include <stdio.h>

int S[100000];
int T[50000];

int binarySearch(int length , int key){
  int left = 0;
  int right = length ;
  int mid;

  while(left < right){
    mid = (left + right)/2;
    if(key == S[mid]){
      return 1;
      break;
    }
    else if(key > S[mid])left = mid + 1;
    else if(key < S[mid])right = mid;
  }

  return 0;
}

int main(){

  int i;
  int n,q;
  int ansCounter = 0;
  int tof;

  scanf("%d",&n);
  for(i = 0 ; i < n ; i++){
    scanf("%d",&S[i]);
  }
  scanf("%d",&q);
  for(i = 0 ; i < q ; i++){
    scanf("%d",&T[i]);
  }


for(i = 0 ; i < q ; i++){
  tof = binarySearch(n ,T[i]);
  if (tof == 1)ansCounter++;
}

printf("%d\n",ansCounter);

return 0;
}



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

int main (void){
  long long int a,v,b,w,t,s;

  cin >> a >> v >> b >> w >>t;

  if(a >= b){
    s = a;
    a = b;
    b = s;
  }

  if(w > v){
    cout << "NO\n";
    return 0;
  }

  if(v-w == 0){
    if(b-a == 0){
      cout << "YES\n";
      return 0;
    } else{
      cout << "NO\n";
      return 0;
    }
  }

  if((v - w) * t >= (b - a)){
    cout << "YES\n";
    return 0;
  }

  cout << "NO\n";
  return 0;
}

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

#define PI 3.1415926535897932
#define MOD 1000000007
#define INF 1e9

#define REP(i, n) for(int i = 0; i < (n); i++)
#define REP1(i, n) for(int i = 1; i <= (n); i++)
#define FOR(i, start, end) for(int i = (start); i < (end); i++)
#define ALL(v) (v).begin(), (v).end()

using namespace std;

typedef long long ll;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<string> vs;
typedef vector<bool> vb;


void solve()
{
    int N; cin >> N;
    cout << "ABC" << N << endl;
}

int main()
{
    cin.tie(nullptr);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(15);
    solve();

    return 0;
}

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

const int maxn = 2e5;
int ans[maxn + 11],col[maxn + 11];
vector <int> edge[maxn + 11],ver[maxn + 11];
int cnt[5];

int R = 0 , B = 0;

void dfs(int x,int fa,int d) {
	col[x] = d % 2;
	if (d % 2 == 1) R++; else B++;
	ver[d].pb(x);
	for (auto v : edge[x]) {
		if (v == fa) continue;
		dfs(v , x , d + 1);
	}
}

int main(){
	int n;
	scanf("%d" , &n);
	for (int i = 1; i < n; i++) {
		int u,v;
		scanf("%d %d",&u,&v);
		edge[u].pb(v);
		edge[v].pb(u);
	} 
	dfs(1 , 0 , 0);
	if (R > B) {
		swap(R , B);
		for (int i = 1; i <= n; i++) col[i] ^= 1;
	}
	if (R <= n / 3) {
		int l = 1; int r = 3;

		for (int i = 1; i <= n; i++) {
			if (col[i]) ans[i] = r , r += 3;
			else {
				if (l <= n) {
					ans[i] = l;
					l++; if (l % 3 == 0) l++;
				}
				else {
					ans[i] = r , r += 3;
				}
			}
		}
	}
	else {
		cnt[1] = 1; cnt[2] = 2; cnt[3] = 3;
		for (int i = 1; i <= n; i++) {
			if (col[i]) {
				if (cnt[1] <= n) ans[i] = cnt[1] , cnt[1] += 3;
				else ans[i] = cnt[3] , cnt[3] += 3;
			}
			else {
				if (cnt[2] <= n) ans[i] = cnt[2] , cnt[2] += 3;
				else ans[i] = cnt[3] , cnt[3] += 3;
			}
		}
	}
	for (int i = 1; i <= n; i++) printf("%d " , ans[i]);
} 


Measured memory_bytes: 31104
#include<iostream>
#include<cstdlib>

#include<cmath>
#include<map>
#include<string>
#include<vector>
#include<algorithm> 

using namespace std;

# define p(s) cout << s << endl;
# define printIf(j,s1,s2) cout << (j ? s1 : s2) << endl;
# define YES(j) cout << (j ? "YES" : "NO") << endl;
# define Yes(j) cout << (j ? "Yes" : "No") << endl;
# define rep(n,i) for(i = 0 ; i < n ; i++)

int main()
{
    int w,h,n;cin >> w >> h >> n;

    int b[101][101];
    for(int i = 0 ; i < w ; i++){
        for(int j = 0 ; j < h ; j++){
            b[i][j]=1;
        }
    }


    for(int i=0 ; i < n ; i++){
        int x,y,a;cin >> x >> y >> a;

        int from,to;
        if(a==1){from=0;to=(x-1);} 
        else if(a==2){from=x;to=(w-1);} 
        else if(a==3){from=0;to=(y-1);} 
        else if(a==4){from=y;to=(h-1);} 

        if(a==1 || a==2){
            for(int j = from ; j <= to ; j++){
                for(int k = 0 ; k < h ; k++){
                   b[j][k]=0;
                }
            }
        } else {
            for(int j = from ; j <= to ; j++){
                for(int k = 0 ; k < w ; k++){
                    b[k][j]=0;
                }
            }
        }
   }

    int res = 0;
    for(int i = 0 ; i < w ; i++){
        for(int j = 0 ; j < h ; j++){
            res += b[i][j];
        }
    }
    p(res)
}

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

public class Main {
	public static void main(String[] args) throws NumberFormatException,
			IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		while ((str = br.readLine()) != null) {
			String inputs[] = str.split(" ");
			int a = Integer.parseInt(inputs[0]);
			int b = Integer.parseInt(inputs[1]);
			int c = Integer.parseInt(inputs[2]);
			int k = Integer.parseInt(br.readLine());
			for (int i = 0; i < k; i++) {
				if (a > b && a>c) {
					a *= 2;
				} else if (b > c) {
					b *= 2;
				} else {
					c *= 2;
				}
			}
			System.out.println(a+b+c);
		}
	}
}


Measured memory_bytes: 23124
N = int(input())
st = []
for _ in range(N):
    s, t = input().split()
    t = int(t)
    st.append((s, t))
X = input()

flag = False
ans = 0
for s, t in st:
    if s == X:
        flag = True
        continue
    if flag:
        ans += t
print(ans)


Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define ll long long
#define INF 1000000005
#define MOD 1000000007
#define EPS 1e-10
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define each(a, b) for(auto (a): (b))
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
#define pb push_back
#define show(x) cout <<#x<<" = "<<(x)<<endl
#define spair(p) cout <<#p<<": "<<p.fi<<" "<<p.se<<endl
#define svec(v) cout<<#v<<":";rep(i,v.size())cout<<" "<<v[i];cout<<endl
#define sset(s) cout<<#s<<":";each(i,s)cout <<" "<<i;cout<<endl

using namespace std;

typedef pair<int,int>P;

const int MAX_N = 100005;

int main()
{
    while(1){
        int e;
        cin >> e;
        if(e == 0){
            break;
        }
        int z = 0;
        while(z*z*z <= e){
            z++;
        }
        int ans = INF;
        for(int i=0;i<z;i++){
            int rem = e - i*i*i;
            int y = 0;
            while(y*y <= rem){
                y++;
            }
            for(int j=0;j<y;j++){
                int x = rem - j*j;
                ans = min(ans,x+i+j);
            }
        }
        cout << ans << "\n";
    }

}

Measured memory_bytes: 3076
#include <stdio.h>
typedef long long ll;
using namespace std;

int main(void) {
  ll i, j, k, n, ans = 0;
  char s[10];
  scanf("%s", s);
  for(i = 0; i < 4; ++i) {
    if(s[i] == '+') ++ans;
    else --ans;
  }
  printf("%lld", ans);
  return 0;
}

Measured memory_bytes: 128
#include <cstdio>
using namespace std;

int n;
int t[101];
int m;
int p[101];
int x[101];
int ans;

int main(){
	scanf("%d", &n);
	for(int i=0; i<n; ++i) scanf("%d", &t[i]),ans+=t[i];
	scanf("%d", &m);
	for(int i=0; i<m; ++i) scanf("%d %d", &p[i], &x[i]),printf("%d\n", ans-t[p[i]-1]+x[i]);
}

Measured memory_bytes: 128
#pragma GCC optimize("O3")
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef  unsigned long long int ull;
typedef pair<ll,ll> P;
template<class T> using V=vector<T>; 
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
const ll inf=(1e18);
//const ll mod=998244353;
const ll mod=1000000007;
//ios_base::sync_with_stdio(false);
//cin.tie(NULL);
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
struct __INIT{__INIT(){cin.tie(0);ios::sync_with_stdio(false);cout<<fixed<<setprecision(15);}} __init;
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(){
int n;
cin>>n;
V<ll> a(n);
int cnt=0;
ll sum=0;
for(int i=0;i<n;i++){
	cin>>a[i];
	if(a[i]<0){
		a[i]=-a[i];
		cnt++;
	}
	sum+=a[i];
}
sort(all(a));
if(cnt%2==0)cout<<sum<<endl;
else cout<<sum-a[0]*2<<endl;
}



Measured memory_bytes: 1024
#include <bits/stdc++.h>
 
using namespace std;
 
#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define pvec(v) rep(i,v.size()){cout << v[i] << " ";};cout<<endl;
#define pb push_back
#define pf push_front
#define mod 1e9+7
 
typedef vector<int> vi;
typedef vector<string> vs;
typedef long long ll;
typedef vector<ll> vll;

const double pi = acos(-1.0);
 
ll gcd(ll x, ll y) { return (y == 0) ? x : gcd(y, x % y); }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
	int h,w,ans;
	string s;
	char key;
	cin >> h >> w;
	rep(i,h){
		char c='A';
		rep(j,w){
			cin >> s;
			if(s=="snuke"){
				ans=i+1;
				key=c;
			}
			c++;
		}
	}
	cout << key << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
double x[31],y[31],z[31];
double g(int i,int j){
  double X=x[i]-x[j],Y=y[i]-y[j],Z=z[i]-z[j];
  return sqrt(X*X+Y*Y+Z*Z);
}
int main(){
  int m,n,a1,a2,a3;
  cin>>m;
  while(m--){
    double Q,R,P;
    cin>>Q>>R>>P;
    cin>>n;
    for(int i=0;i<n;i++)
      cin>>x[i]>>y[i]>>z[i];
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
        for(int k=0;k<n;k++){
          double p1=g(i,j),p2=g(j,k),p3=g(k,i);
          if(abs(R/Q-p2/p1)<0.001&&abs(P/Q-p3/p1)<0.001){
            a1=i+1;
            a2=j+1;
            a3=k+1;
          }
        }L:;
    cout<<a3<<' '<<a1<<' '<<a2<<endl;
  }
}

Measured memory_bytes: 3128
#include <algorithm>
#include <bits/stdc++.h>
#include <bitset>
#include <cassert>
#include <cstring>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <math.h>
#include <memory>
#include <queue>
#include <set>
#include <stack>
#include <utility>
#include <vector>
using namespace std;
#define REP(i, n) for (int64_t i = 0; i < (int64_t)n; i++)
#define REP_FOR(i, a, b) for (int64_t i = (int64_t)a; i < (int64_t)b; i++)
#define REP_REV(i, a, b) for (int64_t i = (int64_t)a; i > (int64_t)b; i--)
#define FORALL(v) (v).begin(), (v).end()
#define mp(a, b) make_pair(a, b)
#define eb(x) emplace_back(x)
#define F first
#define S second
typedef long long ll;
typedef long double ld;
typedef pair<int64_t, int64_t> pii;
typedef pair<ll, ll> pll;
typedef pair<ld, ld> pdd;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef vector<int64_t> vii;
typedef vector<vii> vvii;
const ll mod = 1e9 + 7;
const int64_t infi = 1147483600;
const ll infl = 4e18 + 5;
const char EOL = '\n';
//cout << fixed << setprecision(17) << res << endl;
const ll MOD = 998244353;

int main() {
    int n;
    cin >> n;
    int a[n];
    int b[n];
    int c[n];
    for (int i = 0; i < n; i++) {
	cin >> a[i]; a[i]--;
    }
    for (int i = 0; i < n; i++) {
	cin >> b[i];
    }
    for (int i = 0; i < n-1; i++) {
	cin >> c[i];
    }
    c[n-1] = 0;
    
    int ans = 0;

    for (int i = 0; i < n; i++) {
	ans += b[a[i]];
	if (a[i] + 1 == a[i+1]) {
	    ans += c[a[i]];
	}
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
program name
    use,intrinsic :: iso_fortran_env
    implicit none
    integer(int32):: n,m,ti,di
    integer(int32), allocatable:: d(:),t(:)

    read*, n
    allocate(d(n))
    read*, d(:)
    read*, m
    allocate(t(m))
    read*, t(:)
    call merge_sort(d,1,n)
    call merge_sort(t,1,m)
    di=1
    do ti=1,m
        do while(t(ti) /= d(di))
            di=di+1
            if (di > n) then
                print'(a)', 'NO'
                stop
            end if
        end do
        di=di+1
    end do
    print'(a)', 'YES'
contains
recursive subroutine merge_sort(ar, fst, lst)
integer(int32),intent(inout):: ar(:)
integer(int32),intent(in):: fst,lst
integer(int32):: mdl

if (lst-fst < 2) then
    if (ar(fst) > ar(lst)) call swap(ar(fst),ar(lst))
    return
end if

mdl = (fst+lst)/2
call merge_sort(ar, fst, mdl)
call merge_sort(ar, mdl+1, lst)
call merge_(ar, fst, mdl, lst)
end subroutine

subroutine merge_(ar, fst, mdl, lst)
integer(int32),intent(inout):: ar(:)
integer(int32),intent(in):: fst, mdl, lst
integer(int32),allocatable:: tmp(:)
integer(int32):: li, ri, ti

allocate(tmp(lst-fst+1))

li=fst
ri=mdl+1   
ti=1

do while (li <= mdl .and. ri <= lst)
    if (ar(li) <= ar(ri)) then
        tmp(ti) = ar(li)
        li=li+1
    else
        tmp(ti) = ar(ri)
        ri=ri+1
    end if
    ti=ti+1
end do

if (li <= mdl) then
    tmp(ti:) = ar(li:mdl)
else
    tmp(ti:) = ar(ri:lst)
end if

ar(fst:lst) = tmp(:)
deallocate(tmp)
end subroutine

subroutine swap(x,y)
integer(int32),intent(inout):: x,y
integer(int32):: tmp
tmp = x
x = y
y = tmp
end subroutine
end program name

Measured memory_bytes: 3508
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rad_to_deg(rad) (((rad)/2/M_PI)*360)
using ll = long long;
using namespace std;
int main(){
    string s;cin>>s;
    int a=(s[0]-'0')*10+s[1]-'0';
    int b=(s[2]-'0')*10+s[3]-'0';
    if(a<=12&&b<=12&&a>0&&b>0){
        cout<<"AMBIGUOUS"<<endl;
    }
    else if(a<=12&&a>0){
        cout<<"MMYY"<<endl;
    }
    else if(b<=12&&b>0){
        cout<<"YYMM"<<endl;
    }
    else{
        cout<<"NA"<<endl;
    }
}


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

using namespace std;

const int MaxN = 100005;
const long long Mod = 1000000007;

int n;
vector<int> Adj[MaxN];
long long f[MaxN][2];

void DFS(int u, int p)
{
    f[u][0] = f[u][1] = 1;
    for (auto v : Adj[u])
    {
        if (v != p)
        {
            DFS(v, u);
            f[u][0] = (f[u][0] * (f[v][0] + f[v][1])) % Mod;
            f[u][1] = (f[u][1] * f[v][0]) % Mod;
        }
    }
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin >> n;
    int u, v;
    for (int i = 1; i < n; i++)
    {
        cin >> u >> v;
        Adj[u].push_back(v);
        Adj[v].push_back(u);
    }
    DFS(1, -1);
    cout << (f[1][0] + f[1][1]) % Mod;
    return 0;
}

Measured memory_bytes: 17452
X,Y,Z,K = map(int,input().split())
A = list(map(int,input().split()))
B = list(map(int,input().split()))
C = sorted(list(map(int,input().split())),reverse=True)
D = []
for i in range(X):
    for j in range(Y):
        D.append(A[i]+B[j])
D = sorted(D,reverse=True)
E = []
for i in range(min(K,X*Y)):
    for j in range(Z):
        E.append(D[i]+C[j])
E = sorted(E,reverse=True)
for i in range(K):
    print(E[i])

Measured memory_bytes: 148736
from collections import defaultdict, deque

N, Q = map(int, input().split())
tree = defaultdict(list)
counter = [0] * N
for i in range(N-1):
    a, b = map(int, input().split())
    tree[a-1].append(b-1)
    tree[b-1].append(a-1)

for j in range(Q):
    p, x = map(int, input().split())
    counter[p-1] += x

visited = [False] * N

queue = deque()
queue.append(0)
while queue:
    parent = queue.popleft()
    visited[parent] = True
    for child in tree[parent]:
        if not visited[child]:
            counter[child] += counter[parent]
            queue.append(child)

print(' '.join(map(str, counter)))


Measured memory_bytes: 84120
#include <bits/stdc++.h>
#define all(x) (x).begin() , (x).end();
#define rall(x) (x).rbegin() , (x).rend();
#define fi first
#define se second

using namespace std;

void deb(){
    cerr<<endl;
}
template<typename T , typename... t>
void deb(T a , t...b){
    cerr<<a<<" ";
    deb(b...);
}
template<typename T>
void dev(vector<T>v){
    int c = 0;
    for(auto i : v){
        cerr<<i<<" ";
        c++;
    }
    cerr<<endl;
}
const int N = 1e5 + 8;
int dp[N][3];
int C[N][3];
int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0);cout.tie(0);
    int n ; cin>>n;
    
    for(int i = 0 ; i < n; ++i){
        cin>>C[i][0]>>C[i][1]>>C[i][2];
    }
    for(int i = 0 ; i < n; ++i){
        for(int j = 0 ; j < 3 ; ++j){
            if(!i){
                dp[i][j] = C[i][j];
            }
            else{
                for(int k = 0 ; k < 3; ++k){
                    if(j != k)dp[i][j] = max(dp[i][j] , dp[i - 1][k] + C[i][j]);
                }
            }
        }
    }
    cout<<max({dp[n - 1][0] , dp[n - 1][1] , dp[n - 1][2]})<<"\n";
}

Measured memory_bytes: 2560