akhauriyash/Code-Regression huggingface dataset:
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <locale>
#include <iostream>
#include <map>
#include <memory>
#include <new>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

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

using namespace std;

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

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template <typename T> int len(const T &x) { return x.size(); }

template<typename T>
vector<T> table(int n, T v) { return vector<T>(n, v); }

template <class... Args>
auto table(int n, Args... args) {
  auto val = table(args...);
  return vector<decltype(val)>(n, move(val));
}

struct yes_no : numpunct<char> {
  string_type do_truename()  const { return "YES"; }
  string_type do_falsename() const { return "NO"; }
};

void solve(ll A, ll B) {
  if (A + B < 10) cout << A + B << endl;
  else cout << "error" << endl;
}

int main() {
  locale loc(locale(), new yes_no);
  cout << boolalpha << setprecision(12) << fixed;
  cout.imbue(loc);
	ll A;
	ll B;
	scanf("%lld", &A);
	scanf("%lld", &B);
	solve(A, B);
	return 0;
}


Measured memory_bytes: 256
// tested by Hightail - https://github.com/dj3500/hightail
import std.stdio, std.string, std.conv, std.algorithm;
import std.range, std.array, std.math, std.typecons, std.container, core.bitop;
import std.datetime, std.bigint;

int N;

void main() {
    char ans;
    int k = -1;

    foreach (i ; 0 .. 10) {
        writefln("? %s", 10^^i);
        stdout.flush();
        scan(ans);

        if (ans == 'N') {
            k = i - 1;
            break;
        }
    }

    if (k == -1) {
        foreach (i ; 1 .. 10) {
            writefln("? %s", 10^^i - 1);
            stdout.flush();
            scan(ans);

            if (ans == 'Y') {
                writefln("! %s", 10^^(i - 1));
                stdout.flush();
                return;
            }
        }

        writefln("! %s", 10^^9);
        stdout.flush();
        return;
    }

    long btm = 10L^^k - 1, top = 10L^^(k + 1);

    while (top - btm > 1) {
        long mid = btm + (top - btm) / 2;
        writefln("? %s", mid * 10L);
        stdout.flush();
        scan(ans);

        if (ans == 'Y') top = mid;
        else btm = mid;
    }

    writefln("! %s", top);
    stdout.flush();
    return;
}

void scan(T...)(ref T args) {
    string[] line = readln.split;
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}


void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

Measured memory_bytes: 852
#include <iostream>
#include <string>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
#include <unordered_map>
using namespace std;

bool can_stack_all(int k, queue<int> w, int p)
{
  int t = 0, tw = 0;
  while (t < k && w.size() > 0)
  {
    if (w.front() > p)
      return false;
    if ((tw + w.front()) > p)
    {
      t++;
      tw = w.front();
    }
    else
    {
      tw += w.front();
    }
    w.pop();
  }
  if (tw > 0)
    t++;

  return t <= k;
}

int main()
{
  int n, k;
  cin >> n >> k;

  queue<int> w;
  int wmax = 0, wsum = 0;
  for (int i = 0; i < n; i++)
  {
    int wi;
    cin >> wi;

    w.push(wi);

    wsum += wi;
    if (wi > wmax)
      wmax = wi;
  }

  int l = 0, r = wsum, p = 0;
  while (l + 1 < r)
  {
    p = (l + r) / 2;
    if (can_stack_all(k, w, p))
    {
      r = p;
    }
    else
    {
      l = p;
    }
  }
  cout << r << endl;
}



Measured memory_bytes: 3808
# Date [ 2020-09-08 00:14:49 ]
# Problem [ c.py ]
# Author Koki_tkg

import sys
# import math
# import bisect
# import numpy as np
# from decimal import Decimal
# from numba import njit, i8, u1, b1 #JIT compiler
# from itertools import combinations, product
# from collections import Counter, deque, defaultdict

sys.setrecursionlimit(10 ** 6)
MOD = 10 ** 9 + 7
INF = 10 ** 9
PI = 3.14159265358979323846

def read_str():      return sys.stdin.readline().strip()
def read_int():      return int(sys.stdin.readline().strip())
def read_ints():     return map(int, sys.stdin.readline().strip().split())
def read_ints2(x):   return map(lambda num: int(num) - x, sys.stdin.readline().strip().split())
def read_str_list(): return list(sys.stdin.readline().strip().split())
def read_int_list(): return list(map(int, sys.stdin.readline().strip().split()))
def GCD(a: int, b: int) -> int: return b if a%b==0 else GCD(b, a%b)
def LCM(a: int, b: int) -> int: return (a * b) // GCD(a, b)

def floor_sum(n, m, a, b):
    ret = 0
    if a >= m:
        ret += (n - 1) * n * (a // m) // 2
        a %= m
    if b >= m:
        ret += n * (b // m)
        bb %= m
    y_max = (a * n + b) // m; x_max = (y_max * m - b)
    if y_max == 0: return ret
    ret += (n - (x_max + a - 1) // a) * y_max
    ret += floor_sum(y_max, a, m, (a - x_max % a) % a)
    return ret

def Main():
    for _ in range(read_int()):
        n, m, a, b = read_ints()
        print(floor_sum(n, m, a, b))

if __name__ == '__main__':
    Main()

Measured memory_bytes: 9196
n,m=map(int,input().split())
a=[input() for _ in range(n)]
b=[input() for _ in range(m)]
ans="No"
for i in range(n-m+1):
    for j in range(n-m+1):
        C=[a[i+k][j:j+m] for k in range(m)] 
        if C==b:
            ans="Yes"

print(ans)

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

int main()
{
	long a = 0, b = 1;

	cin >> a >> b;

	cout << a / b << endl;
	cout << a % b << endl;
	cout << setprecision(5) << setiosflags(ios::fixed | ios::showpoint) 
		 << (double) a / (double) b << endl;

    return 0;
}

Measured memory_bytes: 3204
class SegTree:
    """
    内部実装1-indexed．
    set_valやfoldには0-indexedでアクセス．
    2べきに直さなくてよい．
    Range Minimum Query．
    X_unit 大きい数 X_f min
    """
    X_unit = 2147483647  # (1 << 31) - 1
    X_f = min

    def __init__(self, N):
        self.N = N
        self.X = [self.X_unit] * (N + N)

    def build(self, seq):
        for i, x in enumerate(seq, self.N):
            self.X[i] = x
        for i in range(self.N - 1, 0, -1):
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def set_val(self, i, x):
        i += self.N
        self.X[i] = x
        while i > 1:
            i >>= 1
            self.X[i] = self.X_f(self.X[i << 1], self.X[i << 1 | 1])

    def fold(self, L, R):
        L += self.N
        R += self.N
        vL = self.X_unit
        vR = self.X_unit
        while L < R:
            if L & 1:
                vL = self.X_f(vL, self.X[L])
                L += 1
            if R & 1:
                R -= 1
                vR = self.X_f(self.X[R], vR)
            L >>= 1
            R >>= 1
        return self.X_f(vL, vR)


def main():
    N, Q = (int(i) for i in input().split())
    seg = SegTree(N)
    for _ in range(Q):
        com, x, y = (int(i) for i in input().split())
        if com == 0:
            seg.set_val(x, y)
        else:
            print(seg.fold(x, y+1))


if __name__ == '__main__':
    main()



Measured memory_bytes: 8224
D, G = map(int, input().split())
P = []
C = []
for i in range(D):
    p, c = map(int, input().split())
    P.append(p)
    C.append(c)

b = 1 << D
ans = float("inf")
for i in range(b):
    score = 0
    cnt = 0
    for j in range(D):
        b2 = 1<<j
        if i & b2:
            score += C[j] + P[j] * (j+1) * 100
            cnt += P[j]
    if score >= G:
        ans = min(ans, cnt)
        continue
    for j in range(D-1, -1, -1):
        b2 = 1<<j
        if i & b2 == 0:
            for k in range(P[j]-1):
                score += (j+1)*100
                cnt += 1
                if score >= G:
                    break
            if score >= G:
                break
    if score >= G:
        ans = min(ans, cnt)
print(ans)


Measured memory_bytes: 3064
#include<stdio.h>
     
    int main(void) {
      char s[4];
      int i = 0,sum = 700;
      for (i = 0;i < 3;++i) {
        scanf("%s",&s[i]);
      }
      for (i = 0;i < 3;++i) {
        if(s[i] == 'o') {
          sum += 100;
        }
      }
      printf("%d",sum);
      return 0;
    }

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

using namespace std;

long long int gcd(long long int a,long long int b)
{
	if(a==0)
		return b;
	else
		return gcd(b%a,a);
}

int main()
{
    int tt;
    cin>>tt;
    while(tt--)
    {
        long long int a,b,c,d;
        cin>>a>>b>>c>>d;
        if(a<b)
        {
            cout<<"No"<<endl;
            continue;
        }
        if(d<b)
        {
            cout<<"No"<<endl;
            continue;
        }
        c++;
        if(c>=b)
        {
            cout<<"Yes"<<endl;
            continue;
        }
        long long int g=gcd(b,d);
        long long int tmp,tmp2;
        tmp=(a-b)/g;
        tmp2=(a-c)/g;
        tmp2-=tmp;
        if(tmp2<=0)
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;

    }

    return 0;
}


Measured memory_bytes: 256
/*
  _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ 
 |                                                                 |
 |   author : yash1399     Language : C ++                         | 
 |   college : MSIT                                                | 
 | _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ _ |  
*/
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cmath>
#include <cstring>
#include <cctype>
#include <string>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <algorithm>
#include <functional>
using namespace std;
# define ll  long long int 
# define TEST int t ; cin>>t; while(t--)
# define line cout<<endl;
# define fast ios_base::sync_with_stdio(false) ; cin.tie(0) ; cout.tie(0);
# define loop(i,a,b) for(long long int i=a;i<b;i++)
# define loopIn(i,a,b) for(long long int i=a;i<=b;i++)
#define MAX_SIZE 10000000
vector<bool> V(MAX_SIZE,false);
int main(){
      fast
      ll x ,y;
      cin>>x>>y;
      ll s =0;
      if(x==1) s=s+300000;
      if(x==2) s=s+200000;
      if(x==3) s=s+100000;
      if(y==1) s=s+300000;
      if(y==2) s=s+200000;
      if(y==3) s=s+100000;
      if(x==1 && y==1) s=s+400000;
      cout<<s<<endl;
}

Measured memory_bytes: 1536
#include<iostream>
#include<string>
using namespace std;
int main(){
	int N, T, c[100], t[100], ans=1001;
	cin >> N >> T;
	for (int i = 0; i < N; i++){
		cin >> c[i] >> t[i];
	}
	for (int i = 0; i < N; i++){
		if (t[i] <= T){
			if (ans > c[i]){
				ans = c[i];
			}
		}
	}
	if (ans < 1001){
		cout << ans << endl;
	}
	else cout << "TLE" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{    
    long long A, B;
    long long V, W;
    long long T;
    cin >> A >> V;
    cin >> B >> W;
    cin >> T;

    string ans = "NO";

    long long dis = abs(A - B);
    
    long long dis_minus = (V - W) * T;
    if (dis_minus >= dis) {
        ans = "YES";
    }

    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3624
#include <stdio.h>

int main(){
	int a, satuan = 0, puluhan = 0;
	scanf("%d",&a);
	satuan = a%10;
	puluhan = a/10;
	
	if(satuan == 9 || puluhan == 9){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}	
	
	return 0;
}

Measured memory_bytes: 128
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {

		new Main().run();
	}

	private void run() {
		Scanner scanner = new Scanner(System.in);
		while (true) {
			int n = scanner.nextInt();
			if (n == 0)
				break;
			List<Integer> list = new ArrayList<Integer>();
			for (int i = 0; i <= n; i++)
				list.add(scanner.nextInt());
			for (int i = 0; i <= n; i++) {
				List<Integer> tmp = new ArrayList<Integer>();
				tmp.addAll(list);
				tmp.remove(i);
				if (slove(tmp)) {
					System.out.println(list.get(i));
					break;
				}
			}
		}
	}

	private boolean slove(List<Integer> tmp) {
		int ans = tmp.get(1) - tmp.get(0);
		for (int i = 2; i < tmp.size(); i++)
			if (tmp.get(i) - tmp.get(i - 1) != ans)
				return false;
		return true;
	}
}

Measured memory_bytes: 43604
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
int main() {
  int N;
  cin >> N;
  int ans = 0;
  vector<vector<int>> x(N);
  for (int i = 0; i < N; i++) {
    int a;
    cin >> a;
    for (int j = 0; j < a; j++) {
      int b,c;
      cin >> b >> c;
      x[i].push_back(b);
      x[i].push_back(c);
    }
  }
  for (int bit = 0; bit < (1 << N); bit++) {
    bool OK = true;
    for (int i = 0; i < N; i++) {
      if (bit & (1 << i)) {
        for (int j = 0; j < x[i].size(); j+=2) {
          if (bit & (1 << (x[i][j]) - 1) && x[i][j + 1] == 0) {
            OK = false;
          }
          else if (!(bit & (1 << (x[i][j]) - 1)) && x[i][j + 1] == 1) {
            OK = false;
          }
        }
      }
    }
    if (OK) {
      ans = max(ans,__builtin_popcount(bit));
    }
  }
  cout << ans << endl;
  return 0;
}

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

#define INF 2147483647
#define N 100


int main() {
  int n, p[N + 1], m[N + 1][N + 1];
  int l, i, j, k, q;
  
  scanf("%d", &n);
  for ( i = 1; i <= n; i++ ) {
    scanf("%d%d", &p[i-1], &p[i]);
  }
  
  for ( i = 1; i <= n; i++ ) m[i][i] = 0;
  for ( l = 2; l <= n; l++ ) {
    for ( i = 1; i <= n - l + 1; i++ ) {
      j = i + l - 1;
      m[i][j] = INF;
      for ( k = i; k <= j - 1; k++ ) {
	q =  m[i][k] + m[k + 1][j] + p[i - 1] * p[k] * p[j];
	m[i][j] = (m[i][j] < q ? m[i][j] : q );
      }
    }
  }
  
  printf("%d\n", m[1][n]);
  
  return 0;
}

Measured memory_bytes: 636
#include <string>
#include <vector>
#include <map>
#include <iostream>
#define ll long long
using namespace std;


// numb=3,B=4,left=5
// (yen=0,numb=3,left=5)
// (yen=1,numb=0,left=4)
// (yen=0,numb=4,left=3)
// (yen=1,numb=1,left=2)
// (yen=0,numb=5,left=1)




int main() {
    ll K,A,B;
    cin>>K>>A>>B;
    
    // if B-A=2
    // (yen=0,numb=A,left=K)
    // (yen=1,numb=0,left=K-1)
    // (yen=0,numB=A+2,left=K-2)
    
    if (B > A) {
        ll lazy = 1+K;
        
        
        ll numb=1;
        
        // increase the buscuits to A
        ll numops = min(A-numb,K);
        
        numb += numops;
        K-= numops;
        

        // A-1-B
        
        numb += (K/2)*(B-A);
        if (K&1) {
            numb++;
        }
        cout << max(numb,lazy) << endl;
        return 0;
    } else {
        // B <= A.
        cout << 1+K << endl;
        return 0;
    }
    
}

Measured memory_bytes: 256
using System;

class MyClass
{
    static void Main(string[] args)
    {
        int s = int.Parse(Console.ReadLine());
        int h = (int)Math.Floor(s / 3600.0);
        s -= h * 3600;
        int m = (int)Math.Floor(s / 60.0);
        s -= m * 60;
        Console.WriteLine("{0}:{1}:{2}", h, m, s);
    }
}


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

using namespace std;

int main() {
    while(true) {
        vector<int> v(5, 0);
        vector<int> cnt(3, 0);
        for(int i = 0; i < 5; ++i) {
            cin >> v[i];
            if(v[i] == 0) return 0;
            v[i]--;
            cnt[v[i]]++;
        }

        if((cnt[0] > 0 && cnt[1] > 0 && cnt[2] > 0) || cnt[0] == 5 || cnt[1] == 5 || cnt[2] == 5) {
            for(int i = 0; i < 5; ++i) v[i] = 3;
        }
        else {
            for(int i = 0; i < 5; ++i) v[i] = cnt[(v[i]+1)%3]>0 ? 1 : 2;
        }

        for(int i = 0; i < 5; ++i) cout << v[i] << endl;
    }
    return 0;
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define all(x) (x).begin(),(x).end()
#define cyes cout<<"YES"<<endl
#define cno cout<<"NO"<<endl
#define sp <<" "<<
#define cst(x) cout<<fixed<<setprecision(x)
#define pi 3.14159265359
#define mod 1000000007
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vl = vector<ll>;
using Graphi = vector<vi>;
using que_a = priority_queue<int, vector<int>, greater<int> >;
using que_d = priority_queue<int>;
using pint = pair<int,int>;
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; }
struct edge {
    int to; 
    int weight;
    edge(int t, int w) : to(t),weight(w) {}
};

int main(){

    ll a; cin >> a;
    ld b; cin >> b;
    int nb = b;
    int nnb = 100*(b-nb);
    ll x = a*nnb/100;
    ll ans = a*nb + x;
    cout << ll(a*b) << endl;
    return 0;

}

Measured memory_bytes: 3712
#include <stdio.h>

int main(void){
  int max=0, min=0, i, n, a[200005];
  scanf("%d", &n);
  for(i=1; i<=n; i++){
    scanf("%d", &a[i]);
    if(a[i]>=max){
      min = max;
      max = a[i];
    }
    else if(a[i]>min) min = a[i];
  }
  
  for(i=1; i<=n; i++){
    if(a[i]==max) printf("%d\n", min);
    else printf("%d\n", max);
  }
  
  return 0;
}

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

#define CEIL(a,b) ((a) / (b) + ((a) % (b) == 0 ? 0 : 1))
#define X first
#define Y second

using namespace std;
using ll = long long;
using pii = pair<int, int>;
using vl = vector<ll>;
using vs = vector<string>;

constexpr int MOD = int(1e9 + 7);
constexpr int INF = int(1e9 + 1);
constexpr ll LLINF = ll(4 * 1e18 + 1);
// constexpr int INF = 2147483647; // 2 * 1e9
// constexpr ll LLINF = 9223372036854775807; // 9 * 1e18

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

int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout << fixed << setprecision(10);
	int n, m, o;
	string s;
	cin >> n >> m;
	cout << n + m / 2 << "\n";
	return 0;
}


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

using namespace std;

#define ll long long
#define lop(a, b) for(int i = a; i < b; i++)
#define lopj(a, b) for(int j = a; j < b; j++)

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

    //freopen("input.txt", "r", stdin)

    ll n, k;

    cin >> n >> k;

    ll a[n];

    lop(0, n) cin >> a[i];

    sort(a, a + n);

    ll sum = 0;

    lop(0, k) sum += a[i];

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define in(x) cin >> x
#define inv(x) for (auto &t : (x)) cin >> t
#define out(x) cout << (x) << endl
#define outs(x) cout << (x) << " "
#define outv(x) for (auto &t : (x)) out((x))
#define outsv(x) for (auto &t : (x)) outs((x))
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, n) for (int i = (int)(n)-1; i >= 0; i++)
#define repf(i, x, n) for (int i = (int)(x); i < (int)(n); i++)
#define repfr(i, x, n) for (int i = (int)(n)-1; i < (int)(x); i++)
#define sz(x) ((int)(x).size())
#define sz(x) ((int)(x).size())
#define inf 1e9
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 (b < a) {a = b;return 1;}return 0;}
using ll = int64_t;

void Main() {
  int x, y, z;
  in(x);
  in(y);
  in(z);

  int space = y + z;
  out((x - z) / space);

  return;
}

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


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main(){
long n;
long t[1000],a[1000];
scanf("%ld",&n);
for(int i=0;i<n;i++){
	scanf("%ld %ld",&t[i],&a[i]);
}
 
long tsuu=t[0];
long asuu=a[0];
for(int i=1;i<n;i++){
	long ttemp=tsuu/t[i];
	long atemp=asuu/a[i];
	if(tsuu%t[i]!=0){
		ttemp++;
	}
	if(asuu%a[i]!=0){
		atemp++;
	}
	long temp=max(ttemp,atemp);
	tsuu=temp*t[i];
	asuu=temp*a[i];
}
 
printf("%ld\n",tsuu+asuu);
 
return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b, c float64
	fmt.Scan(&a, &b, &c)
	max := math.Max(a, math.Max(b, c))
	if a+b+c == 2*max {
		fmt.Println("Yes")
	} else {
		fmt.Println("No")
	}
}


Measured memory_bytes: 512
#include <bits/stdc++.h>
using namespace std;
#define __ <<" "<<
#define ___ <<" "
#define bash push_back
#define ALL(x) x.begin(),x.end()
//#define int long long

struct IoSetup {
    IoSetup() {
        cin.tie(0);
        ios::sync_with_stdio(false);
        cout <<fixed<<setprecision(12);
        cerr <<fixed<<setprecision(12);
    }
}IoSetup;

typedef long long ll;
typedef pair < int , int >  pii;
static constexpr const signed int INF = 0x3f3f3f3f;
static constexpr const signed long long LINF = 0x3f3f3f3f3f3f3f3fLL;
static constexpr const signed int SMOD = 1000000007;
static constexpr const signed int NMOD = 998244353;
static constexpr const signed int dx[]={1,0,-1,0,1,1,-1,-1};
static constexpr const signed int dy[]={0,-1,0,1,-1,1,-1,1};

inline bool inside(int x,int y,int w,int h){return (x>=0 && y>=0 && x<w && y<h);}
template<class T>bool chmax(T &a, const T &b){return(a=max(a,b))==b;}
template<class T>bool chmin(T &a, const T &b){return(a=min(a,b))==b;}
inline int qp(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}

vector<int> e[10010];
int cost[10010];

signed main() {

    int n;
    cin >> n;
    vector<int> a(n), b(n);
    for(int i = 0; i < n-1; i++) {
        cin >> a[i] >> b[i];
        a[i]--, b[i]--;
        e[a[i]].bash(b[i]);
        e[b[i]].bash(a[i]);
    }
    vector<int> c(n);

    for(int i = 0; i < n; i++) cin >> c[i];

    sort(ALL(c), greater<int>());
    
    queue<int> que;
    que.push(a[0]);
    que.push(b[0]);
    cost[a[0]] = c[0];
    cost[b[0]] = c[1];
    int k = 2;
    while(!que.empty()) {
        int v = que.front();
        que.pop();
        for(auto&&u:e[v]) {
            if(cost[u]) continue;
            cost[u] = c[k++];
            que.push(u);
        }
    }
    
    ll sum = 0;
    for(int i = 0; i < n-1; i++)
        sum += min(cost[a[i]], cost[b[i]]);
    
    cout << sum << endl;
    for(int i = 0; i < n; i++)
        cout << cost[i] << " \n"[i+1 == n];

  
    return 0;
}



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

set<int> t;

int main(){

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

    for(int i=0;i<=5;i++)t.insert(i);
    for(int i=0;i<5;i++){
        int a;
        cin>>a;
        t.erase(a);
    }
    cout<<*t.begin()<<endl;

    return 0;
}

Measured memory_bytes: 3548
N, C = map(int, input().split())
D = [list(map(int, input().split())) for _ in range(C)]
grid = [list(map(int, input().split())) for _ in range(N)]
grid1 = []
grid2 = []
grid3 = []
ans = float('inf')
for i in range(N):
    for k in range(N):
        tmp = grid[i][k]
        tmp2 = i + k
        if tmp2 % 3 == 1:
            grid1.append(tmp)
        elif tmp2 % 3 == 2:
            grid2.append(tmp)
        else:
            grid3.append(tmp)
sum1 = sum(grid1)
sum2 = sum(grid2)
sum3 = sum(grid3)
tmp1 = [sum1]*C
tmp2 = [sum2]*C
tmp3 = [sum3]*C
for i in range(C):
    for k in grid1:
        tmp1[i] = tmp1[i] - k + D[k-1][i]
for i in range(C):
    for k in grid2:
        tmp2[i] = tmp2[i] - k + D[k-1][i]
for i in range(C):
    for k in grid3:
        tmp3[i] = tmp3[i] - k + D[k-1][i]
for i in range(C):
    for k in range(C):
        if i == k:
            continue
        for l in range(C):
            if i == l or k == l:
                continue
            ans = min(ans,tmp1[i]+tmp2[k]+tmp3[l])
print(ans)

Measured memory_bytes: 56540
#include<iostream>
using namespace std;
int main(){
	double a,b,c,d,e,f,g,h;
	int n;
	int x,y;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a>>b>>c>>d>>e>>f>>g>>h;
		x=(d-b)/(c-a);
		y=(h-f)/(g-e);
		if((d-b)/(c-a)==(h-f)/(g-e)){cout<<"YES"<<endl;}
		else {cout<<"NO"<<endl;}
	}
}

Measured memory_bytes: 0
#include <iostream>
#include <cstdint>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <cctype>
#include <cassert>
#include <climits>
#include <string>
#include <bitset>
#include <cfloat>
#include <unordered_set>
#pragma GCC optimize("Ofast")
using namespace std;
typedef long double ld;
typedef long long int ll;
typedef unsigned long long int ull;
typedef vector<int> vi;
typedef vector<char> vc;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef vector<string> vs;
typedef vector<ll> vll;
typedef vector<pair<int, int>> vpii;
typedef vector<vector<int>> vvi;
typedef vector<vector<char>> vvc;
typedef vector<vector<string>> vvs;
typedef vector<vector<ll>> vvll;

#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define rrep(i, n) for (ll i = 1; i <= (n); ++i)
#define irep(it, stl) for (auto it = stl.begin(); it != stl.end(); it++)
#define drep(i, n) for (ll i = (n)-1; i >= 0; --i)
#define mes(a) cout << (a) << endl
#define dmes(a, b) cout << (a) << " " << (b) << endl
#define re0 return 0
#define mp(p, q) make_pair(p, q)
#define pb(n) push_back(n)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
#define Sort(a) sort(a.begin(), a.end())
#define rSort(a) sort(a.rbegin(), a.rend())
#define Rev(a) reverse(a.begin(), a.end())
#define MATHPI acos(-1)
#define itn int
int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
template <class T>
inline bool chmax(T &a, T b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
inline bool chmin(T &a, T b)
{
    if (a > b)
    {
        a = b;
        return 1;
    }
    return 0;
}
struct io
{
    io()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
};
const int INF = INT_MAX;
const ll LLINF = 1LL << 60;
const ll MOD = 1000000007;
const double EPS = 1e-19;





signed main() {
    ll n;
    cin >> n;
    
    map <ll, ll> mp0;
    map <ll, ll> mp1;
    
    
    vll v(n);
    rep(i, n) {
        cin >> v[i];
        if (i % 2 == 0) {
            mp0[v[i]] ++;
        } else {
            mp1[v[i]] ++;
        }
    }
    
    ll i01 = 0;
    ll i02 = 0;
    ll i11 = 0;
    ll i12 = 0;
    
    for (auto i : mp0) {
        if (i.second >= mp0[i01]) {
            i02 = i01;
            i01 = i.first;
        } else if (i.second >= mp0[i02]) {
            i02 = i.first;
        }
    }
    
    for (auto i : mp1) {
        if (i.second >= mp1[i11]) {
            i12 = i11;
            i11 = i.first;
        } else if (i.second >= mp1[i12]) {
            i12 = i.first;
        }
    }
    
    
    if (i01 == i11) {
        mes( min (n - mp0[i02] - mp1[i11], n - mp0[i01] - mp1[i12]) );
    } else mes(n - mp0[i01] - mp1[i11]);
    
    
    
    
    
    
    
}

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

#define int long long
#define pb push_back 
#define pf push_front 
#define mp make_pair
#define fr first
#define sc second
#define Rep(i,n) for(int i=0;i<(n);i++)
#define All(v) v.begin(),v.end()

typedef pair<int, int> Pii; typedef pair<int, Pii> Pip;
const int INF = 1107110711071107;

int N, M, K;
vector<Pii> ab;
int a[16], b[16];
int dp[16][10001][16];

int dfs(int n, int m, int k) {
  if ( n == N || k == K || m == 0 ) return m;
  if ( dp[n][m][k] >= 0 ) return dp[n][m][k];

  int a = ab[n].fr, b = ab[n].sc;
  return dp[n][m][k] = max(dfs(n+1, max(0LL, m-b), k+1) + min(m, b)*a, dfs(n+1, m, k));
}

signed main() {
  memset(dp, -1, sizeof(dp));
  cin >> N >> M >> K;
  Rep(i, N) cin >> a[i];
  Rep(i, N) cin >> b[i];
 
  Rep(i, N) {
    ab.pb(Pii(a[i], b[i]));
  }
  
  sort(All(ab), greater<Pii>());

  cout << dfs(0, M, 0) << endl;
  
  return 0;
}

Measured memory_bytes: 23108
import java.util.*;

public class Main {

    static Scanner sc = new Scanner(System.in);

    public static void main(String[] args) {
        int N = sc.nextInt();
        int M = sc.nextInt();
        int X = sc.nextInt();
        int Y = sc.nextInt();

        int[] xs = new int[N];
        int maxX = -100;
        for (int i = 0; i < N; i++) {
            xs[i] = sc.nextInt();
            maxX = Math.max(xs[i], maxX);
        }

        int[] ys = new int[M];
        int minY = 100;
        for (int i = 0; i < M; i++) {
            ys[i] = sc.nextInt();
            minY = Math.min(ys[i], minY);
        }

        if (Y <= X) {
            System.out.println("War");
            return;
        }

        for (int i = X + 1; i <= Y; i++) {
            if ((maxX < i) && (minY >= i)) {
                System.out.println("No War");
                return;
            }
        }
        System.out.println("War");

    }
}

Measured memory_bytes: 23636
#include<math.h>
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define    ll   long long int
#define    py   printf("Yes\n")
#define    pn   printf("No\n")
#define    in   cin>>
using namespace std;

int main()
{
  string s;
  string ans="AC";
  int cnt=0;
  in s;
  if(s[0]!='A')ans="WA";
    for(int i=1;i<s.size();i++)
    {
      if(isupper(s[i]))
      {
        if(i==1||i==s.size()-1||s[i]!='C')
        {
          ans="WA";
        }
        cnt++;
      }
    }
    if(cnt!=1)ans="WA";
    cout<<ans<<endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <set>
#include <string>
#include <vector>
#define rep(i, x, n) for(int i = x; i < n; i++)
using namespace std;
const long long INF = 1LL << 60;
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;
}
const int MOD = 1000000007;
int rui(int a, int b) {
    if(b == 0) {
        return 1;
    }
    return rui(a, b - 1) * a;
}
int main() {
    int N, M;
    cin >> N >> M;
    vector<int> a(N);
    int sum = 0;
    rep(i, 0, N) {
        cin >> a[i];
        sum += a[i];
    }
    int ok = 0;
    rep(i, 0, N) {
        if(sum <= 4 * M * a[i]) {
            ok++;
        }
    }
    if(ok >= M) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

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

int main(){
	int n;
	while(true){
		cin>>n;
		if(n==0)	return 0;
		vector<int> a(n);
		rep(i,0,n)	cin>>a[i];
		int ans=(1<<30);
		rep(i,0,n){
			rep(j,1,4){
				vector<int> b(a);
				if(b[i]==j)	continue;
				b[i]=j;
				int m=n,cur=i;
				while(true){
					int cnt=0;
					int o=cur,u=cur;
					while(o-1>=0&&b[cur]==b[o-1])	o--,cnt++;
					while(u<m&&b[cur]==b[u])	u++,cnt++;
					if(cnt<4)	break;
					b.erase(b.begin()+o,b.begin()+u);	m-=cnt;
					cur=o;
				}
				ans=min(ans,m);
			}
		}
		cout<<ans<<endl;
	}
}
			

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

using namespace std;

int main() {
    int N,K; cin >> N >> K;
    if(K > (N-1)*(N-2)/2) {
        cout << -1 << endl;
        return 0;
    }

    int M = N-1;
    vector<pair<int,int>> edge;
    for(int i=0;i<N-1;i++) {
        edge.push_back(make_pair(1,i+2));
    }

    int lim = (N-1)*(N-2)/2 - K;
    for(int i=2;i<=N;i++) {
        for(int j=i+1;j<=N;j++) {
            if(lim) {
                lim--;
                edge.push_back(make_pair(i,j));
            }
        }
    }

    cout << edge.size() << endl;
    for(auto e : edge) {
        cout << e.first << " " << e.second << endl;
    }

    return 0;
}


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

int main()
{
    int n;
    double a[100], b[100];
    cin >> n;
    
    for (int i = 0; i < n; i++)
        cin >> a[i];    

    for (int i = 0; i < n; i++)
        cin >> b[i];    

    cout << fixed;

    // p1
    double p1 = 0;
    for (int i = 0; i < n; i++)
        p1 += abs(a[i] - b[i]);
    
    cout << p1 << endl;

    // p2
    double p2 = 0;
    for (int i = 0; i < n; i++)
        p2 += pow( abs(a[i] - b[i]),2.0);
    cout << sqrt(p2) << endl;

    // p3
    double p3 = 0;
    for (int i = 0; i < n; i++)
        p3 += pow( abs(a[i] - b[i]),3.0);
    cout << pow (p3,1/3.0) << endl;

    //  infinite
    double pmax = 0;
    double calc;
    for (int i = 0; i < n; i++)
    {
        calc = abs(a[i]-b[i]); 
        if (pmax < calc) {
            pmax = calc;
        }
    }
    cout << pmax << endl;

    return 0;
}


Measured memory_bytes: 3424
#include<iostream>
#include<string>
#include<map>
#include<cstring>
#include<cstdio>
using namespace std;
int main()
{
  map<string,int> str;
  string word;
  int big = 0;
  int cnt = 0;
  string keepword;
  string keepstr = "";
  string many = "";
  
  while(!cin.eof()){
    cin >> word;
    string kari(word);
    str[kari]++;
    
    if(cnt < str[kari]){
      cnt = str[kari];
      keepstr = kari;
    }
    
    if(big < word.size()){
      big = word.size();
      keepword = word;
    }
  }
  cout << keepstr << " " << keepword << endl;
}

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

using namespace std;

int main() {
  int N;
  cin >> N;
  int a, b, c, d;
  a = N /1000;
  b = (N%1000)/100;
  c = (N%100)/10;
  d = N%10;
  
  if (a == b && b == c && c != d) {
	cout << "Yes" << endl;
  } else if (b == c && c == d && d !=a) {
    cout << "Yes" << endl;
  } else if (a == b && b == c && c == d) {
	cout << "Yes" << endl;
  } else {
	cout << "No" <<endl;
  }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
constexpr double EPS = 1e-12;
constexpr int INF = numeric_limits<int>::max()/2;
constexpr int MOD = 1e9+7;

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

    int x,a,b;cin>>x>>a>>b;
    x-=a;
    cout<<x%b<<endl;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
int a[200005];
int T, N, cnt, now;
int main()
{
    cnt = 0;
    now = -1;
    scanf("%d %d", &N, &T);
    for(int i = 0; i < N; i++)
    {
        scanf("%d", &a[i]);
        if(now <= a[i]){
            now = a[i]+T;
            cnt += T;
        }
        else if(now > a[i]){
            cnt += T +a[i] - now;
            now = a[i]+T;
        }
    }
    printf("%d\n", cnt);
    return 0;
}


Measured memory_bytes: 896
'use strict';
(function(stdin) {
    var inputs = stdin.toString().split(' ').map(Number);
    var a = inputs[0];
    var b = inputs[1];
    var d = Math.floor(a / b);
    var r = a % b;
    var f = Number((a / b).toFixed(5));
    console.log(d,r,f);
}(require('fs').readFileSync('/dev/stdin', 'utf8')));

Measured memory_bytes: 15840
N=int(input())
T=[int(i) for i in input().split()]
M=int(input())
time=[]
for i in range(M):
    x=[int(j) for j in input().split()]
    time+=[sum(T)-T[x[0]-1]+x[1]]
for i in range(M):
    print(time[i])

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <algorithm>
#include <ctime>
#include <cmath>
#include <string>
#include <stdlib.h>
#include <fstream>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <iterator>
#include <iomanip>
#include <climits>
using namespace std; 
#define ll long long int
 
 
int main(){
    ll h, w, n;
    cin >> h >> w >> n;
    map<pair<ll, ll>, ll> m;
    ll a, b, x, y;
    vector<int> px = {0, 0, 0, -1, -1, -1, -2, -2, -2},
                py = {0, -1, -2, 0, -1, -2, 0, -1, -2};
    for(int i = 0; i < n; ++i){
        cin >> x >> y;
        for(int j = 0; j < 9; ++j){
            a = x + px[j], b = y + py[j];
            if(a >= 1 && a + 2 <= h && b >= 1 && b + 2 <= w) m[{a, b}]++;
        }
    }
    vector<ll> ans(10);
    ans[0] = (w - 2) * (h - 2) - m.size();
    for(auto an: m){
        ans[an.second]++;
    }
    for(int i = 0; i < 10; ++i) cout << ans[i] << endl;
}

Measured memory_bytes: 56448
var input = require('fs').readFileSync('/dev/stdin', 'utf8');
var Arr=input.split("\n");
var str="";
for(var i=0;i<Arr.length;i++){
var arr=Arr[i].split(" ").map(Number);
var h=arr[0];
var w=arr[1];
if(h===0 && w===0)break;
if(i!==0)str+="\n";
var W=Array(w+1).join("#")+"\n";
str+=W;
for(var j=1;j<h-1;j++)str+="#"+Array(w-1).join(".")+"#"+"\n";
str+=W;
}
console.log(str);

Measured memory_bytes: 10068
/*
    飲んだ魔剤で家が建つ。
    created at: 2020-05-10 21:01:33
*/

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

#define all(x) (x).begin(),(x).end()
#define MOD 1000000007
#define INF 1000000000

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

    long p, q, r;
    p = min(a, k);
    k -= p;
    q = min(b, k);
    k -= q;
    r = min(c, k);
    
    long ans = p - r;

    cout << ans << endl;

    return 0;
}


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

int main() {
  int H, W, N;
  cin >> H >> W >> N;
  int useing;
  if (H > W){
    useing = H;
  } else {
    useing = W;
  }
  int count = 1;
  while(true){
    if(count * useing >= N){
      break;
    } else {
      count ++;
      continue;
    }
  }
  cout << count << endl;
}

Measured memory_bytes: 256
h,w,a,b=map(int,input().split())
mod=10**9+7
ans=0
def cmb(n, r, mod):
    if ( r<0 or r>n ):
        return 0
    r = min(r, n-r)
    return g1[n] * g2[r] * g2[n-r] % mod

mod = 10**9+7 #出力の制限
N = h+w+1
g1 = [1, 1] # 元テーブル
g2 = [1, 1] #逆元テーブル
inverse = [0, 1] #逆元テーブル計算用テーブル

for i in range( 2, N + 1 ):
    g1.append( ( g1[-1] * i ) % mod )
    inverse.append( ( -inverse[mod % i] * (mod//i) ) % mod )
    g2.append( (g2[-1] * inverse[-1]) % mod )

#a = cmb(n,r,mod)
for i in range(h-a):
    p=(i)+(b-1)
    q=(h-i-1)+((w-b)-1)
    ans+=cmb(p,i,mod)*cmb(q,h-i-1,mod)
    ans%=mod
    #print(p,q)
print(ans)


Measured memory_bytes: 81008
N = gets.chomp.to_i
A = gets.chomp.split.map(&:to_i)
ans = 0

(1...N).each do |i|
  if A[i] >= A[i-1]
    next
  else
    ans += (A[i-1] - A[i])
    A[i] = A[i-1]
  end
end

puts ans

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

// エイリアス
using  ll = long signed long;
using ull = long unsigned long;
using  ld = long double;
using   P = pair<int, int>;
using llP = pair<ll, ll>;
using DoP = pair<double, double>;

// 汎用マクロ
#define ALL(a) (a).begin(), (a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOREACH(i,q) for (auto &i : q)
#define UNIQUE(v) do { sort((v).begin(), (v).end()); (v).erase(unique((v).begin(), (v).end()), (v).end()); } while (false)
#define SZ(x) ((int)(x).size())
template <class T>inline bool chmin(T &a, const T b) {if (a > b) { a = b; return true;} return false;}
template <class T>inline bool chmax(T &a, const T b) {if (a < b) { a = b; return true;} return false;}
template <class T>inline void line_out(const vector<T> vec) {int n = SZ(vec); rep(i, n) { cout << vec[i]; if(i < n-1) cout << " ";}cout << endl;}
const int di[] = {0, 1, 0, -1, 1, 1, -1, -1};
const int dj[] = {1, 0, -1, 0, 1, -1, 1, -1};
const int INF = 1 << 28;
const ll INF64 = 1ll << 60;
const int mod = 1000000007;
//const int mod = 998244353;
//const int mod = 100000;
struct mint
{
  ll x; // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint &operator+=(const mint a)
  {
    if ((x += a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator-=(const mint a)
  {
    if ((x += mod - a.x) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator*=(const mint a)
  {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const
  {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const
  {
    mint res(*this);
    return res -= a;
  }
  mint &operator++()
  {
    if ((x += 1) >= mod)
      x -= mod;
    return *this;
  }
  mint &operator--()
  {
    if ((x += mod - 1) >= mod)
      x -= mod;
    return *this;
  }
  mint operator*(const mint a) const
  {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const
  {
    if (!t)
      return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1)
      a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const
  {
    return pow(mod - 2);
  }
  mint &operator/=(const mint a)
  {
    return (*this) *= a.inv();
  }
  mint operator/(const mint a) const
  {
    mint res(*this);
    return res /= a;
  }
};

int main()
{
  int n; cin >> n;
  bool ok = true;
  rep(i, n) {
    int a; cin >> a;
    if(a%2 == 0) {
      if(a%3 != 0 && a%5 != 0) ok = false;
    }
  }
  if(ok) cout <<"APPROVED" << endl;
  else cout << "DENIED" << endl;
}


Measured memory_bytes: 3616
import sys

input = sys.stdin.readline
N, K = map(int, input().split())
LR = [list(map(int, input().split())) for _ in range(K)]
P = 998244353

class SegmentTree:
    def __init__(self, n, segfunc=min, ele=10**10):
        self.ide_ele = ele
        self.num = pow(2, (n-1).bit_length())
        self.seg = [self.ide_ele] * 2 * self.num
        self.segfunc = segfunc

    def init(self, init_val):
        #set_val
        for i in range(len(init_val)):
            self.seg[i+self.num-1] = init_val[i]
        #built
        for i in range(self.num - 2, -1, -1):
            self.seg[i] = self.segfunc(self.seg[2*i+1], self.seg[2*i+2])

    def update(self, k, x):
        k += self.num-1
        self.seg[k] = x
        while k:
            k = (k-1)//2
            self.seg[k] = self.segfunc(self.seg[k*2+1], self.seg[k*2+2])

    def query(self, p, q):
        if q <= p:
            return self.ide_ele
        p += self.num-1
        q += self.num-2
        res = self.ide_ele
        while q-p > 1:
            if p & 1 == 0:
                res = self.segfunc(res, self.seg[p])
            if q & 1 == 1:
                res = self.segfunc(res, self.seg[q])
                q -= 1
            p = p//2
            q = (q-1)//2
        if p == q:
            res = self.segfunc(res, self.seg[p])
        else:
            res = self.segfunc(self.segfunc(res, self.seg[p]), self.seg[q])
        return res


dp = SegmentTree(N, segfunc=lambda x, y: x+y%P, ele=0)
dp.update(0, 1)
for i in range(1, N):
    tmp = 0
    for l, r in LR:
        tmp = (tmp + dp.query(max(0, i - r), max(0, i - l + 1)))%P
    dp.update(i, tmp)
print(dp.seg[N - 1 + dp.num - 1])


Measured memory_bytes: 79428
from collections import deque
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
n = int(input())
edges = [[]for _ in range(n)]
for i in range(n):
    s = list(map(int, list(input().rstrip())))
    for j in range(n):
        if s[j]:
            edges[i].append(j)


def dfs(v, c=0):
    color[v] = c
    for v2 in edges[v]:
        if color[v2] != -1:
            if color[v] == color[v2]:
                global is_ok
                is_ok = 0
            continue
        dfs(v2, color[v] ^ 1)


color = [-1]*n
is_ok = 1
dfs(0)


def bfs(init_v):
    next_v = deque([init_v])
    INF = 10**18
    dist = [INF]*n
    dist[init_v] = 0
    while next_v:
        v = next_v.popleft()
        for v2 in edges[v]:
            if dist[v2] <= dist[v]+1:
                continue
            dist[v2] = dist[v]+1
            next_v.append(v2)
    return dist

if is_ok:
    ans = 0
    for i in range(n):
        dist = bfs(i)
        x = max(dist)
        if ans < x:
            ans = x
    print(ans+1)
else:
    print(-1)

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

using namespace std;
const int N = 3e3 + 3;
int a[N], dp[N];
vector <int> g[N];

void dfs(int v, int p = 0) {
    dp[v] = 0;
    for (int u : g[v]) if (u != p && a[u] < a[v])
        dfs(u, v), dp[v] |= (!dp[u]);
    return ;
}
int main() {
    int n; cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i < n; i++) {
        int u, v; cin >> u >> v;
        g[u].push_back(v), g[v].push_back(u);
    }
    for (int i = 1; i <= n; i++) {
        dfs(i);
        if (dp[i]) cout << i << '\n';
    }

    return 0;
}


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

int main()
{
    ll n;
    cin >> n;
    vector<ll> a;
    rep(i,n) a.push_back(i+1);
    sort(a.begin(),a.end());

    do{
        rep(i,n){
            cout << (i ? " " : "") << a[i];
        }
        cout << endl;
    }while( next_permutation(a.begin() , a.end() ));

    return 0;
}


Measured memory_bytes: 3156
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"sort"
	"strconv"
)

const pi = math.Pi

var mod int = pow(10, 9) + 7
var Umod uint64 = 1000000007
var ans, cnt int

func main() {
	reader.Split(bufio.ScanWords)
	N, _ := strconv.Atoi(read())
	v := make([]int, N)
	for i := 0; i < N; i++ {
		v[i], _ = strconv.Atoi(read())
	}
	sort.Ints(v)
	a := float64(v[0])
	//var sum float64
	for i := 0; i < N-1; i++ {
		a = (a + float64(v[i+1])) / 2
	}
	fmt.Println(a)
}

/*  ----------------------------------------  */

var reader = bufio.NewScanner(os.Stdin)

func read() string {
	reader.Scan()
	return reader.Text()
}

func lcm(x, y int) int {
	return (x / gcd(x, y)) * y
}

func gcd(x, y int) int {
	if x%y == 0 {
		return y
	} else {
		r := x % y
		return gcd(y, r)
	}
}

var fac [1000000]int
var finv [1000000]int
var inv [1000000]int

func combination_init() {
	fac[0], fac[1] = 1, 1
	finv[0], finv[1] = 1, 1
	inv[1] = 1

	// invは a^(-1) mod p
	// pをaで割ることを考える

	// p/a*(a) + p%a = p
	// p/a*(a) + p%a = 0          (mod p)
	// -p%a = p/a*(a)             (mod p)
	// -p%a *a^(-1)= p/a          (mod p)
	// a^(-1)= p/a * (-p%a)^(-1)  (mod p)
	// a^(-1) =

	for i := 2; i < 1000000; i++ {
		fac[i] = fac[i-1] * i % mod
		inv[i] = mod - inv[mod%i]*(mod/i)%mod
		finv[i] = finv[i-1] * inv[i] % mod
	}
}

func combination(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[y] * finv[x-y] % mod) % mod
	//return fac[x] / (fac[y] * fac[x-y])
}

func permutation(x, y int) int {
	if x < y {
		return 0
	}
	if fac[0] != 1 {
		combination_init()
	}
	return fac[x] * (finv[x-y] % mod) % mod
	//return fac[x] / fac[x-y]
}

func max(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Max(float64(x[i]), float64(res)))
	}
	return res
}

func min(x ...int) int {
	var res int = x[0]
	for i := 1; i < len(x); i++ {
		res = int(math.Min(float64(x[i]), float64(res)))
	}
	return res
}
func pow(x, y int) int { return int(math.Pow(float64(x), float64(y))) }
func abs(x int) int    { return int(math.Abs(float64(x))) }
func floor(x int) int  { return int(math.Floor(float64(x))) }
func ceil(x int) int   { return int(math.Ceil(float64(x))) }

type SortBy [][]int

func (a SortBy) Len() int      { return len(a) }
func (a SortBy) Swap(i, j int) { a[i], a[j] = a[j], a[i] }
func (a SortBy) Less(i, j int) bool {
	return a[i][1] < a[j][1]
}

type PriorityQueue []int

func (h PriorityQueue) Len() int            { return len(h) }
func (h PriorityQueue) Less(i, j int) bool  { return h[i] < h[j] }
func (h PriorityQueue) Swap(i, j int)       { h[i], h[j] = h[j], h[i] }
func (h *PriorityQueue) Push(x interface{}) { *h = append(*h, x.(int)) }
func (h *PriorityQueue) Pop() interface{} {
	old := *h
	n := len(old)
	x := old[n-1]
	*h = old[0 : n-1]
	return x
}


Measured memory_bytes: 640