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

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

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define what_is(x) cerr << #x << " is " << x << endl;
#define MT make_tuple
#define eb emplace_back
#define rep(i, begin, end) for (__typeof(end) i = (begin) - ((begin) > (end)); i != (end) - ((begin) > (end)); i += 1 - 2 * ((begin) > (end)))

#define REP(i,a,b) for (int i = a; i <= b; i++)
#define FOR(i,n) for (int i=0;i < n ; i++)
#define error(args...) { string _s = #args; replace(_s.begin(), _s.end(), ',', ' '); stringstream _ss(_s); istream_iterator<string> _it(_ss); err(_it, args); }

void err(istream_iterator<string> it) {}
template<typename T, typename... Args>
void err(istream_iterator<string> it, T a, Args... args) {
	cerr << *it << " = " << a << endl;
	err(++it, args...);
}
clock_t startTime;
long double getTime(){
	return (long double)(clock()-startTime)/CLOCKS_PER_SEC;
}

int main(){
	startTime=clock();
	int n,k;
	cin >> n  >> k;
	ll ans=0;
	
	
	for(int b=k+1;b<=n;b++){
			ans+=(b-k)*(n/b)+(int)((n%b < k)?0 : n%b-k+1);
	}
	if(k==0){
		ans-=(n-k);
	}
	cout << ans;

	return 0;
}

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

int main() {
  int N;
  cin >> N;

  int calc = 0;
  int tmp = N;
  while (tmp > 0) {
    calc += tmp % 10;
    tmp /= 10;
  }
  if (N % calc == 0)
    cout << "Yes" << endl;
  else
    cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3512
#include<bits/stdc++.h>
#define ll long long int
ll a[1000000+9];
using namespace std;
int main()
{
    ll n,i,j,x=0,c=0;
    cin>>n;
    set<ll>s;
    for(i=0; i<n; i++)
    {
        cin>>a[i];
        if(a[i]<400)
        {
            s.insert(1);
        }
        else if(a[i]<800)
        {
            s.insert(2);
        }
        else if(a[i]<1200)
        {
            s.insert(3);
        }
        else if(a[i]<1600)
        {
            s.insert(4);
        }
        else if(a[i]<2000)
        {
            s.insert(5);
        }
        else if(a[i]<2400)
        {
            s.insert(6);
        }
        else if(a[i]<2800)
        {
            s.insert(7);
        }
        else if(a[i]<3200)
        {
            s.insert(8);
        }
        else if(a[i]>=3200)
        {
            x++;
        }
    }

    ll minn,maxx;

    if (s.size()==0)
    {
        minn=1;
    }
    else
    {
        minn=s.size();
    }
    maxx=s.size()+x;
    cout<<minn<<" "<<maxx<<endl;
    return 0;
}


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


void solve(long long N, long long A, long long B){
    ll ans = N / (A + B) * A;
   // cout<<ans<<endl;
    ans += min(A, N % (A + B));
    cout<<ans<<endl;
}

int main(){
    long long N;
    scanf("%lld",&N);
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(N, A, B);
    return 0;
}


Measured memory_bytes: 256
// B - A to Z String
#include <bits/stdc++.h>
using namespace std;
#define lli long long int
#define uli unsigned long long int
#define rep(i, m, n) for (lli i = m; i < (n); i++)
#define repe(i, m, n) for (lli i = m; i <= (n); i++)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((lli)(x).size())
#define MAX(x) *max_element(ALL(x))
#define _GLIBCXX_DEBUG
const lli INF = 2147483647;
const lli MINF = -2147483648;
const lli LINF = 9223372036854775807;
const lli MOD = 1000000007; //10^9+7
const long double PI = acos(-1);
#define SORT(n) sort(n.begin(), n.end())
#define SORTR(n) sort(n.begin(), n.end(), greater<int>())
#define REV(n) reverse(n.begin(), n.end())
#define Vec(K, L, N, S) vector<L> K(N, S)
#define rt sqrt
#define pb push_back
#define ppb pop_back
#define eb emplace_back
#pragma GCC optimize("Ofast")
using vi = vector<int>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vlli = vector<lli>;
using P = pair<lli, lli>;
// vector<P> vp;
// vp.emplace_back(a[i], b[i]);
using vs = vector<string>;
using ll = long long;
// vector入力
template <typename T>
istream &operator>>(istream &is, vector<T> &vec)
{
  for (T &x : vec)
    is >> x;
  return is;
}
// vector出力
template <typename T>
ostream &operator<<(ostream &os, vector<T> &vec)
{
  // os << '{';
  for (int i = 0; i < vec.size(); i++)
  {
    os << vec[i] << (i + 1 == vec.size() ? "" : "");
  }
  // os << '}';
  return os;
}
// aよりもbが大きいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T &b)
{
  if (a < b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する(更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T &b)
{
  if (a > b)
  {
    a = b; // aをbで更新
    return true;
  }
  return false;
}

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(0);
  lli a, b, c, h, k, n, w, ans = 0, count = 0;
  string s, t;
  cin >> s;
  auto itr = find(s.begin(), s.end(), 'A');
  lli dis = distance(s.begin(), itr);
  t = s;
  REV(s);
  auto itr2 = find(s.begin(), s.end(), 'Z');
  REV(s);
  lli dis2 = distance(s.begin(), itr2);
  dis2 = s.size() - dis2;
  // cout << "dis2: " << dis2 << endl;
  cout << dis2 - dis << endl;
}

Measured memory_bytes: 788
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<list>
#include<set>
#include<map>
#include<utility>
#include<cmath>
#include <iomanip>
#include<stack>


#define rep(i,x) for(int i=0;i<(int)(x);i++)
#define reps(i,x) for(int i=1;i<=(int)(x);i++)
#define rrep(i,x) for(int i=((int)(x)-1);i>=0;i--)
#define rreps(i,x) for(int i=((int)(x));i>0;i--)

#define all(x) (x).begin(),(x).end()
#define SZ(x) ((int)(x).size())
#define INF 2e9

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; }
typedef long long ll;
typedef long double ld;
int gcd(int a,int b){return b?gcd(b,a%b):a;}

using namespace std;

int main()
{
    ll n;
    cin >> n;
    vector<ll> a(n);
    vector<ll> b(n);

    rep(i, n){
        ll tmp;
        cin >> tmp;
        a[i] = tmp;
        b[i] = tmp;
    }
    sort(all(b));
    reverse(all(b));
    ll m0 = b[0];
    ll m1 = b[1];

    rep(i, n){
        if(a[i] == b[0]) cout << b[1] << endl;
        else cout << b[0] << endl;
    }
}

Measured memory_bytes: 4736
from collections import Counter

h,w,n = map(int,input().split())

black_count = {}

for _ in range(n):
    a,b = map(int,input().split())
    for dx in (-1,0,1):
        for dy in (-1,0,1):
            y = a+dy
            x = b+dx
            if 2<=y<=h-1 and 2<=x<=w-1:
                black_count[(y,x)] = black_count.get((y,x),0) + 1

ans = Counter(black_count.values())
ans[0] = (h-2) * (w-2) - sum(ans.values())
for i in range(10):
    print(ans.get(i,0))

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

#define pb		push_back
#define eb		emplace_back
#define mk		make_pair
#define fi		first
#define se		second
#define cc(x)	cout << #x << " = " << x << endl
#define ok		cout << "ok" << endl
#define endl	'\n'

typedef long long ll;
typedef pair<int,int> ii;
const int INF = 0x3f3f3f3f;
const double PI = acos(-1.0);
 
const ll N = 1e5 + 10;
ll dp[N], p[N], v[N];
ll n, w;

int main() {
    	ios_base::sync_with_stdio(false);

	memset(dp, -INF, sizeof dp);    
	cin >>n >>w;

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

	dp[0] = 0;
	for(int i = 0; i < n; i++){
		for(int j = N-1; j-p[i] >= 0; j--){
			dp[j] = max(dp[j], dp[j-p[i]] + v[i]);
		}
	}

	ll ans = 0;
	for(int i = 0; i <= w; i++) ans = max(ans, dp[i]);

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


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define REP(i,a,b) for (int i = a; i <b; i++)
typedef long long ll;
#define int ll
typedef vector<int> vi;
typedef vector<long long> vl;
typedef pair<int,int> pi;
#define trace(x) cout<<#x<<"="<<x<<"\n";
#define sz(x) (int)(x.size())
#define mod 1000000007
#define endl "\n"
template < typename F, typename S >
ostream& operator << ( ostream& os, const pair< F, S > & p ) {
    return os << "(" << p.first << ", " << p.second << ")";
}

template < typename T >
ostream &operator << ( ostream & os, const vector< T > &v ) {
    os << "{";
    typename vector< T > :: const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "}";
}

template < typename T >
ostream &operator << ( ostream & os, const set< T > &v ) {
    os << "[";
    typename set< T > :: const_iterator it;
    for ( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << *it;
    }
    return os << "]";
}

template < typename F, typename S >
ostream &operator << ( ostream & os, const map< F, S > &v ) {
    os << "[";
    typename map< F , S >::const_iterator it;
    for( it = v.begin(); it != v.end(); it++ ) {
        if( it != v.begin() ) os << ", ";
        os << it -> first << " = " << it -> second ;
    }
    return os << "]";
}

#define deb(x) cerr << #x << " = " << x << endl;



int32_t main(){
    ios::sync_with_stdio(false);
    int r;
    cin>>r;
    cout<<(2*3.14*r)<<"\n";

    return 0;
}

Measured memory_bytes: 3800
#include<bits/stdc++.h>
using namespace std;
#define ll long long
const int x = 123;
bool chk(string s)
{
	int l = s.size(), i;
	unsigned long long sd = 101, p = 1, d = 0, h = 0;
	for (i = l - 1; i >= 0; i--)
		{
			d = d + s[i] * p;
			p = p * sd;
			h = h * sd + s[i];
		}
	return (d == h);
}
int main()
{
	ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
	string s;
	cin >> s;
	int sz = s.size();
	ll l1 = sz / 2;
	ll l2 = (sz + 3) / 2;
	if (chk(s) && chk(s.substr(0, l1)) && chk(s.substr(l2 - 1, l1)))
		cout << "Yes" << endl;
	else cout << "No" << endl;
	//main();
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#define REP(i, n) for(int i = 0; i < (n); i++)
#define ALL(v) (v).begin(), (v).end()
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef pair<int, int> P;
const int INF = 1001001001;
const int mINF = -1001001001;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};


int main() {
int n;
cin >> n;
vi p(n),q(n);
REP(i,n) cin >> p[i];
REP(i,n) cin >> q[i];
vi a(n);
REP(i,n) a[i]=i+1;
map<vi,int> pa;
int j=1;
do {
  pa[a]=j;
  j++;
} while (next_permutation(a.begin(),a.end()));
cout << abs(pa[p]-pa[q]) << endl;
return 0;
}


Measured memory_bytes: 5248
#D
n,W = list(map(int,input().split()))
w = [0]*n
v = [0]*n
for i in range(n):
    w[i],v[i] = list(map(int,input().split()))
    
dp = [[0 for i in range(W+1)] for j in range(n)]
for i in range(n): #品物iまで
    for j in range(W+1):
        if j == 0:
            dp[i][j] = 0
            continue
        if j-w[i] >= 0:
            dp[i][j] = max(dp[i-1][j],dp[i-1][j-w[i]] + v[i])
        else:
            dp[i][j] = dp[i-1][j]
print(max([dp[i][W]for i in range(n)]))

Measured memory_bytes: 171656
x, y = map(int, input().split())
p = list(map(int, input().split()))
if x not in p:
  print(x)
else:
  d = 1
  while True:
    if x - d not in p:
      print(x - d)
      break
    if x + d not in p:
      print(x + d)
      break
    d += 1

Measured memory_bytes: 9184
#include<cstdio>
#include<vector>
#include<algorithm>
using namespace std;
using ll = long long;
using ull = unsigned long long;
const static int MOD = 1000000007;

int main(){
    unsigned N, K, C;
    scanf("%u %u %u\n", &N, &K, &C);
    bool can_work[N];
    vector<unsigned> candidate;
    for (unsigned i = 0; i < N; i++){
        char tmp;
        scanf("%c", &tmp);
        can_work[i] = tmp == 'o';
        if(can_work[i]) candidate.push_back(i);
    }
    scanf("\n");
    size_t _size = candidate.size(), j;
    unsigned after[_size+1], right_after[_size];
    after[_size] = 0;
    for (int i = _size - 1; i >= 0; i--){
        j = distance(candidate.begin(), upper_bound(candidate.begin(), candidate.end(), candidate[i] + C));
        right_after[i] = j;
        after[i] = 1 + after[j];
    }
    unsigned now = 0, n_selected = 0;
    unsigned selected[K];
    while(now != _size && n_selected < K){
        selected[n_selected] = now;
        now = right_after[now];
        n_selected++;
    }
    if(now != _size){
        printf("\n");
        return 0;
    }
    vector<unsigned> answer;
    for (size_t i = 0; i < K; i++){
        if(i + after[selected[i]+1] < K) answer.push_back(candidate[selected[i]] + 1);
    }
    for(auto p : answer) printf("%u\n", p);    
	return 0;
}

Measured memory_bytes: 7496
#include<iostream>
#include<vector>
#include<algorithm>
#include<tuple>
#include<utility>

using namespace std;

typedef long long int64;

int main(void){
    int64 N;
    cin>>N;
    int64 cnt=0;
    vector<int64> p(N);
    for(int64 i=0;i<N;i++){
        cin>>p[i];
        if(p[i]!=i+1){
            cnt++;
        }
    }

    if(cnt==0||cnt==2){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cstdio>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <numeric>
#include <cmath>

using namespace std;

typedef long long int ll;

#define all(x) x.begin(),x.end()

const ll mod = 1e9+7;
const ll INF = 1e9;
const ll MAXN = 1e9;

int main()
{
	ll a[3];
	for(int i = 0; i < 3; i++){
		cin >> a[i];
	}
	ll ans = min(min(a[0]*a[1],a[1]*a[2]),a[2]*a[0]);
	for(int i = 0; i < 3; i++){
		if(a[i]%2==0) ans = 0;
	}
	cout << ans << endl;

	return 0;
}

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

int main(){
    int N;
    int M = -1;
    scanf("%d", &N);
    vector<int> A(N);
    for(int i = 0; i < N; i++){
        scanf("%d", &A[i]);
        if(M < A[i])M = A[i];
    }
    
    vector<vector<bool>> B(M + 1, vector<bool>(N + 1, false));
    
    for(int i = 0; i < N; i++){
        for(int j = 0; j < A[i]; j++){
            B[j][i] = true;
        }
    }
    
    int ans = 0;
    
    for(int i = 0; i <= M; i++){
        bool K = false;
        for(int j = 0; j <= N; j++){
            if(B[i][j]){
                K = true;
            }else{
                if(K){
                    ans++;
                    K = false;
                }
            }
        }
    }
    
    cout << ans << endl;
}

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

using namespace std;

int main() {
	int n, q;
	vector<int> a, m;
	cin >> n;
	int tmp;
	for (int i = 0;i < n;i++) {
		cin >> tmp;
		a.push_back(tmp);
	}
	cin >> q;
	for (int i = 0;i < q;i++) {
		cin >> tmp;
		m.push_back(tmp);
	}
	vector<int> sum;
	for (int i = 0;i < 1 << a.size();i++) {
		int s = 0;
		for (int j = 0;j < a.size();j++) {
			if (i & 1 << j) {
				s += a[j];
			}
		}
		sum.push_back(s);
	}
	sort(sum.begin(), sum.end());
	for (int i = 0;i < m.size();i++) {
		if (binary_search(sum.begin(), sum.end(), m[i])) {
			cout << "yes\n";
		}
		else {
			cout << "no\n";
		}
	}
}


Measured memory_bytes: 6892
X, Y, A, B, C = list(map(int, input().split()))
A = sorted(list(map(int, input().split())), reverse=True)
B = sorted(list(map(int, input().split())), reverse=True)
C = sorted(list(map(int, input().split())), reverse=True)

A_s = A[0:X]
B_s = B[0:Y]

All = A_s
All.extend(B_s)
All.extend(C)
All.sort(reverse=True)

print(sum(All[0:X+Y]))


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

int main() {
	int n; cin >> n;
	vector<int> p(n);
	int ra[n + 1];
	for (int i = 0; i < n; i++) {
		cin >> p[i];
		ra[p[i]] = i;
	}
	ll ans = 0;
	set<int> S;
	S.insert(-1); S.insert(n);
	for (ll d = n; d >= 1; d--) {
		int i = ra[d];
		auto it = S.lower_bound(i);
		int r = *it;
		it--;
		int l = *it;
		if (r == n && l == -1) {
			S.insert(i);
			continue;
		}
		if (l == -1) {
			it++; it++;
			int rr = *it;
			ans += d * (rr - r) * (i + 1);
		}
		else if (r == n) {
			it--;
			int ll = *it;
			ans += d * ((l - ll)) * (n - i);
		}
		else {
			it--;
			int ll = *it;
			it++; it++; it++;
			int rr = *it;
			ans += (l - ll) * (r - i) * d;
			ans += (rr - r) * (i - l) * d;
		}
		S.insert(i);
	}
	cout << ans << endl;
}

Measured memory_bytes: 5760
#include <bits/stdc++.h>
using namespace std;
int main() {
	string S;
	cin>>S;
	sort(S.begin(),S.end());
	if(S[0]==S[1] && S[2]==S[3] && S[0]!=S[2]) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
}

Measured memory_bytes: 256
function main(arg) {
    let s = arg.split("")

    let ans=0, max=0
    for(let i=0;i <3; i++) {
        if(s[i]==="R") {
            ans++
        } else {
            ans=0
        }
        max=Math.max(max,ans)
    }
    console.log(max)
}

main(require("fs").readFileSync("/dev/stdin", "utf8"));


Measured memory_bytes: 29676
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#define ll long long
using namespace std;
int main()
{
  ios_base::sync_with_stdio(0);
  int a,b;
  cin >> a >> b;
  if(a+b>=10)
    cout << "error" << endl;
  else
    cout << a+b << endl;
  return 0;
}


Measured memory_bytes: 256
A,B,C = map(str,input().split(" "))

AB = max(int(A+B),int(B+A))
AC = max(int(A+C),int(C+A))
BC = max(int(B+C),int(C+B))
A,B,C = map(int,[A,B,C])
print(max([A+BC,B+AC,C+AB]))

Measured memory_bytes: 38384
# -*- coding: utf-8 -*-
import fractions
gcd_map = [[0 for i in range(401)] for i in range(401)]


def mem_gcd(p, q):
    if gcd_map[p][q] == 0:
        gcd_map[p][q] = fractions.gcd(p, q)
    return gcd_map[p][q]


k = int(input())
res = 0
for a in range(1, k+1):
    for b in range(a, k+1):
        tmp_gcd = mem_gcd(a, b)
        for c in range(b, k+1):
            tk = mem_gcd(tmp_gcd, c)
            if a == b:
                if b == c:
                    res += tk
                else:
                    res += tk * 3
            else:
                if b == c:
                    res += tk*3
                else:
                    res += tk*6

print(res)

Measured memory_bytes: 11940
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

readl= lambda: list(map(int, sys.stdin.readline().split()))
readt= lambda: tuple(map(int, sys.stdin.readline().split()))
read = lambda: sys.stdin.readline().rstrip()
readi = lambda: int(read())
readmi = lambda: map(int, sys.stdin.readline().split())
readms = lambda: map(str, sys.stdin.readline().split())

def cmb(n, r):
    if n - r < r: r = n - r
    if r == 0: return 1
    if r == 1: return n

    numerator = [n - r + k + 1 for k in range(r)]
    denominator = [k + 1 for k in range(r)]

    for p in range(2,r+1):
        pivot = denominator[p - 1]
        if pivot > 1:
            offset = (n - r) % p
            for k in range(p-1,r,p):
                numerator[k - offset] /= pivot
                denominator[k] /= pivot

    result = 1
    for k in range(r):
        if numerator[k] > 1:
            result *= int(numerator[k])
        result %= 10 ** 9 + 7
    return result

x, y = readmi()
if (x + y) % 3 != 0:
    print(0)
else:
    n = (x + y) // 3
    x -= n
    y -= n
    if x < 0 or y < 0:
        print(0)
    else:
        a = cmb(x + y, x)
        print(a)

Measured memory_bytes: 47792
#include <stdio.h>
int main(void){
    int n,a[100],max=0,min=1000 ;
    scanf ("%d",&n) ;
    for (int i=0; i<n; i++) {
        scanf ("%d",&a[i]) ;
        if (max<a[i]) {
            max=a[i] ;
        }
        if (min>a[i]) {
            min=a[i] ;
        }
    }
    printf ("%d\n",max-min) ;
    return 0 ;
}

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

int table[10][10];
int town;
int INF = 9999;

void fw(){
    for(int k = 0; k <= town; k++){
        for(int i = 0; i <= town; i++){
            for(int j = 0; j <= town; j++){
                table[i][j] = min(table[i][j], table[i][k] + table[k][j]);
            }
        }
    }
}

void solve(){
    int ret, mintable = 1<<21;
    for(int i = 0; i <= town; i++){
        int candidate = 0;
        for(int j = 0; j <= town; j++){
            candidate += table[i][j];
        }
        if(candidate < mintable){
            mintable = candidate;
            ret = i;
        }
    }

    cout << ret << " " << mintable << endl;
}

int main(){
    while(1){
        int n;
        cin >> n;

        if(n == 0)  break;

        town = 0;
        memset(table, INF, sizeof(table));
        for(int i = 0; i < 10; i++) table[i][i] = 0;

        int a, b, c;
        while(n-- > 0){
            cin >> a >> b >> c;
            table[a][b] = table[b][a] = c;
            town = max(town, max(a,b));
        }

        fw();
        solve();
    }
    return 0;
}


Measured memory_bytes: 2980
#include <iostream>
#include <algorithm>
#include <vector>

using namespace std;

struct Time {
	int hour;
	int minute;
	int second;
};

int main(){
	for(int i = 0; i < 3; i++){
		Time Atime, Ltime, time;
		cin >> Atime.hour >> Atime.minute >> Atime.second;
		cin >> Ltime.hour >> Ltime.minute >> Ltime.second;
		
		time.hour = Ltime.hour - Atime.hour;
		time.minute = Ltime.minute - Atime.minute;
		time.second = Ltime.second - Atime.second;
		
		if(time.second < 0){
			time.minute--;
			time.second += 60;
		}
		if(time.minute < 0){
			time.hour--;
			time.minute += 60;
		}
		cout << time.hour << " " << time.minute << " " << time.second << endl;
	}

	return 0;
}


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

int main(){
    int n;
    cin>>n;
    string s;
    cin>>s;
    int a=0; int b=0;
    rep(i,n)if(s[i]=='R')++a;
    int ans=max(a,b);
    rep(i,n){
        if(s[i]=='R')--a;
        else ++b;
        int now=max(a,b);
        ans=min(ans,now);
    }
    cout<<ans<<endl;
    return 0;
    
}

Measured memory_bytes: 3768
n, k = map(int, input().split())
D = {a: 0 for a in range(1, n+1)}
for i in range(k):
    d = int(input())
    for a in map(int, input().split()):
        D[a] += 1
ans = 0
for k, v in D.items():
    if v == 0:
        ans += 1
print(ans)

Measured memory_bytes: 8984
import sys
import heapq
input = sys.stdin.readline


n = int(input())
Xs = []
Ys = []
for i in range(n):
    x, y = map(int, input().split())
    Xs.append((x-1, i))
    Ys.append((y-1, i))

Xs.sort()
Ys.sort()

edges = [[] for _ in range(n)]
for i in range(n-1):
    x, node = Xs[i]
    nx, new_node = Xs[i+1]
    edges[node].append((nx-x, new_node))
    edges[new_node].append((nx-x, node))

for i in range(n-1):
    y, node = Ys[i]
    ny, new_node = Ys[i+1]
    edges[node].append((ny-y, new_node))
    edges[new_node].append((ny-y, node))

seen = [False] * n
dist = [float('INF')] * n
todo = [(0, 0)]

while todo:
    d, node = heapq.heappop(todo)
    if seen[node]:
        continue
    seen[node] = True
    dist[node] = d

    for edge in edges[node]:
        nd, to = edge
        if dist[to] <= nd:
            continue
        heapq.heappush(todo, (nd, to))

print(sum(dist))

Measured memory_bytes: 89796
def main():
    import sys
    from collections import defaultdict
    from heapq import heappop, heappush
    input = sys.stdin.readline

    N, Q = map(int, input().split())
    used = defaultdict(int)
    tank = []
    
    p = []
    p_append = p.append
    for i in range(N):
        s, t, x = map(int, input().split())
        p_append((s - x, x))
        p_append((t - x, -x))
    p.sort()

    cnt = 0
    for i in range(Q):
        d = int(input())
        while cnt <= len(p) - 1 and p[cnt][0] <= d:
            w = p[cnt][1]
            if w >= 0:
                used[w] += 1
                heappush(tank, w)
            else:
                used[-w] -= 1
            cnt += 1
        while True:
            if len(tank) == 0:
                print (-1)
                break
            kouho = tank[0]
            if used[kouho] > 0:
                print (kouho)
                break
            else:
                heappop(tank)

if __name__ == '__main__':
    main()

Measured memory_bytes: 79120
#include<iostream>
#include<string>
using namespace std;
int main(){
	int n;
	int tarop=0,hanap=0;
	string taroc,hanac;
	cin >> n;
	for(int i=0;i<n;i++){
		cin >> taroc >> hanac;
		if(taroc.size()<hanac.size())
			for(;taroc.size()<hanac.size();)
				taroc+="a";
		if(taroc.size()>hanac.size())
			for(;taroc.size()>hanac.size();)
				hanac+="a";
		
		for(int j=0;j<taroc.size();j++){
			if(taroc==hanac){	tarop++; hanap++; break;}
			if(taroc.at(j)==hanac.at(j))continue;
			if(taroc.at(j)<hanac.at(j)){hanap+=3; break;}
			if(taroc.at(j)>hanac.at(j)){tarop+=3; break;}
		}
	}
	cout << tarop << " " << hanap << endl;
	return 0;
}

Measured memory_bytes: 1212
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

int n;
map<string,int> s, ct;

string f[4];

bool vis[4][4]={};
void dfs(int d, int y, int x, string now){
    if(s.count(now)) ++ct[now];
    if(d==8) return;

    for(int dy=-1; dy<=1; ++dy)for(int dx=-1; dx<=1; ++dx){
        int ny = y+dy , nx = x+dx;
        if(0<=ny && ny<4 && 0<=nx && nx<4 && !vis[ny][nx]){
            vis[ny][nx] = true;
            dfs(d+1,ny,nx,now+f[ny][nx]);
            vis[ny][nx] = false;
        }
    }
}

const int N = 10001;

vector<int> v[9];
int dp[N]={};

int main(){
    cin >>n;
    rep(i,n){
        string w;
        int score;
        cin >>w >>score;
        s[w] = score;
    }

    rep(i,4) cin >>f[i];

    rep(i,4)rep(j,4){
        vis[i][j] = true;
        dfs(1,i,j,string(1,f[i][j]));
        vis[i][j] = false;
    }

    for(const auto &p:ct){
        int sz = p.fi.size();
        rep(i,p.se) v[sz].pb(s[p.fi]);
    }

    int T;
    cin >>T;

    for(int i=1; i<=8; ++i){
        vector<int> x = v[i];
        sort(all(x),greater<int>());

        int X = x.size();
        if(X>10000/i) x.resize(10000/i);
        X = x.size();

        rep(j,X){
            for(int k=T-i; k>=0; --k){
                dp[k+i] = max(dp[k+i], dp[k]+x[j]);
            }
        }
    }

    int ans = 0;
    rep(i,T+1) ans = max(ans,dp[i]);
    cout << ans << endl;
    return 0;
}



Measured memory_bytes: 5256
#include <iostream>
#include <algorithm>
#include <vector>
#include <deque>
#include <queue>
#include <string>
#include <tuple>
#include <functional>
#include <numeric>
#include <cmath>
#include <iomanip>
#include <map>
#include <random>
//#include "toollib.h"
//#include "puzzle.h"
#define INT_MAX 2147483647
#define Loop(i, n) for(int i = 0; i < (int)n; i++)
#pragma warning (disable:4018)
#pragma warning (disable:4244)

using namespace std;
typedef long long int lint;


//***** Main Program *****

int main() {
	int n;
	cin >> n;
	vector<int> R(n);
	Loop(i, n) cin >> R[i];
	map<int, int> mp;
	Loop(i, n) mp[R[i]]++;
	int ret = R[1] - R[0];
	auto itr = --mp.end();
	Loop(i, n - 1) {
		mp[R[i]]--;
		while (itr->second == 0) itr--;
		int x = itr->first - R[i];
		if (x > ret) ret = x;
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 12780
import java.util.*;
import java.lang.*;
import java.io.*;


public class Main{
	public static void main (String[] args) throws java.lang.Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String[] s = br.readLine().split("\\s");
		int N = Integer.parseInt(s[0]);
		int K = Integer.parseInt(s[1]);
		s = br.readLine().split("\\s");
		long[] arr = new long[N];
		for(int i=0;i<N;++i) arr[i] = Long.parseLong(s[i]);
		System.out.println(solve(arr,N,K));
	}
	
	private static long solve(long[] arr,int N,int K){
		long[] dp = new long[N];
		Arrays.fill(dp,-1);
		dp[N-1] = 0;
	    
	    for(int i=N-2;i>=0;--i){
	    	for(int j=i+1;j<N && j <= i+K;++j){
	    		long val = dp[j] + Math.abs(arr[i] - arr[j]);
	    		if(dp[i] == -1 || dp[i] > val){
	    			dp[i] = val;
	    		}
	    	}
	    }
		
		return dp[0];
	}
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

const int N = 100005;

intt n;

int main() {

	FAST;

	cin >> n;
	intt ans = n / 11 * 2;
	if (n % 11) ans ++;
	if ((n % 11) > 6) ans ++;
	cout << ans << '\n';
	return 0;
}

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

string to_string(string s) { return '"' + s + '"'; }
string to_string(const char* s) { return to_string((string) s); }
string to_string(bool b) { return (b ? "true" : "false"); }
template <typename A, typename B>
string to_string(pair<A, B> p) { return "(" + to_string(p.first) + ", " + to_string(p.second) + ")"; } 
template <typename A>
string to_string(A v) {
    bool first = true; 
    string res = "{";
    for (const auto &x : v) {
        if (!first) res += ", ";
        first = false;
        res += to_string(x);
    }
    res += "}"; 
    return res;
}
void dbg_out() { cerr << endl; }
template <typename Head, typename... Tail>
void dbg_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    dbg_out(T...);
}
#ifdef LOCAL
    #define dbg(...) cerr << "[" << #__VA_ARGS__ << "]:", dbg_out(__VA_ARGS__)
#else
    #define dbg(...) 42
#endif

#define int long long
#define pb push_back
#define eb emplace_back
#define all(x) (x).begin(),(x).end()
#define ff first
#define ss second
#define MP make_pair
#define sz(v) ((int)(v).size())  
#define fr(i, j, k) for(int i = j; i < k; i++)
#define nl "\n"
typedef pair<int, int> pii;
typedef vector <int> vi;

pii dir[8] = { {-1, 0}, {1, 0}, {0, -1}, {0, 1}, {1, 1}, {-1, -1} , {-1, 1}, {1, -1} };

const int inf = (1LL << 60), mod = 1e9+7, nn = 1005;

void solve(){
    int h, n;
    cin >> h >> n;
    int aa[n+1], bb[n+1];

    // vector < pair < double, pii > > v;
    // fr(i, 0, n){
    //     int a, b;
    //     cin >> a >> b;
    //     double val = 1.0 * a/b;
    //     v.push_back({val, {a, b}});
    //     aa[i] = a;
    //     bb[i] = b;
    // }
    // sort(all(v));
    // reverse(all(v));
    // int ans = 0;

    // fr(i, 0, n){
    //     if(h <= 0) break;
    //     int a = v[i].ss.ff, b =  v[i].ss.ss;
    //     int f = h/a;
    //     h -= f * a;
    //     ans += f * b;
    // }

    // if(h > 0){
    //     int mn = inf;
    //     fr(i, 0, n){
    //         if(aa[i] >= h){
    //             mn = min(mn, bb[i]);
    //         }
    //     }
    //     ans += mn;
    // }
    // cout << ans;
    fr(i, 1, n+1) cin >> aa[i] >> bb[i];

    int dp[h+1];
    fr(i, 0, h+1) dp[i] = inf;
    dp[0] = 0;

    for(int i = 1; i <= n; i++){
        for(int j = 1; j <= h; j++){
            dp[j] = min(dp[j], dp[max(0LL, j - aa[i])] + bb[i]);
            // dbg(i, j, dp[j], max(0LL, j-aa[i]), bb[i], dp[max(0LL, j - aa[i])]);
        }
    } 
    cout << dp[h];
}

int32_t main(){
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    int T = 1;
    // cin >> T;
    for(int tc = 1; tc <= T; tc++){
        // cout << "Case #" << tc << ": ";
        solve();
    }
    return 0;
}

Measured memory_bytes: 384
import kotlin.math.*
import java.util.*

const val MOD = 1_000_000_007L

fun readI() = readLine()!!.toInt()
fun readL() = readLine()!!.toLong()
fun readD() = readLine()!!.toDouble()
fun readIs() = readLine()!!.split(' ').map(String::toInt)
fun readLs() = readLine()!!.split(' ').map(String::toLong)
fun readDs() = readLine()!!.split(' ').map(String::toDouble)

fun main() {
  val (d, t, s) = readIs()
  println(if (t * s < d) "No" else "Yes")
}


Measured memory_bytes: 36308
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<string>
#include<cmath>
#include<cassert>
#include<cstdint>
#include<map>
using namespace std;

typedef int64_t i64;typedef int32_t i32;
typedef int16_t i16;typedef int8_t i8;
typedef uint64_t ui64;typedef uint32_t ui32;
typedef uint16_t ui16;typedef uint8_t ui8;

typedef i64 int__;
#define rep(i,j) for(int__ i=0;i<j;i++)
#define repeat(i,j,k) for(int__ i=(j);i<(k);i++)
#define all(v) begin(v),end(v)

const i32 INF=1<<30;//10E10

int P,Q,A,N;
double PpQ;
int dfs(i64 sum_u,i64 sum_d,int i,int a,int n){
  //printf("u:%lld d:%lld i:%d a:%d n:%d\n",sum_u,sum_d,i,a,n);
  if(P*sum_d==Q*sum_u)return 1;
  if(n<=0)return 0;
  int ret=0;
  while(i*a<=A){
    int u=sum_u*i+sum_d;
    int d=sum_d*i;
    double s=(double)u/d;
    if(s<=PpQ and n*(1.0/i)+s>=PpQ)
      ret+=dfs(u,d,i,i*a,n-1);
    i++;
  }
  return ret;
}


int main()
{
  while(true){
    cin>>P>>Q>>A>>N;
    if(Q==0)break;
    PpQ=(double)P/Q;
    cout<<dfs(0,1,1,1,N)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1160
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, n) for(ll i = 0, i##_len = (n); i < i##_len; i++)
#define reps(i, s, n) for(ll i = (s), i##_len = (n); i < i##_len; i++)
#define rrep(i, n) for(ll i = (n) - 1; i >= 0; i--)
#define rreps(i, e, n) for(ll i = (n) - 1; i >= (e); i--)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) ((ll)(x).size())
#define len(x) ((ll)(x).length())
#define endl "\n"

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    // ifstream in("input.txt");
    // cin.rdbuf(in.rdbuf());
    ll h, w;
    cin >> h >> w;
    vector<string> a(h);
    rep(i, h) cin >> a[i];
    rep(i, w + 2) printf("#");
    printf("\n");
    rep(i, h) printf("#%s#\n", a[i].c_str());
    rep(i, w + 2) printf("#");
    printf("\n");
    return 0;
}


Measured memory_bytes: 256
from sys import stdin


if __name__ == "__main__":
    _in = [_.rstrip() for _ in stdin.readlines()]
    N = int(_in[0])  # type:int
    A = int(_in[1])  # type:int
    # vvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvvv
    TF = 'Yes' if N%500<=A else 'No'
    # ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    print(TF)


Measured memory_bytes: 38384
#include <bits/stdc++.h>
#include <cstdlib>  // abs() for integer 絶対値求めやつ
#include <cmath>    // abs() for float, and fabs()
#include <algorithm>
#include <vector>
#include <string>
#define rep(i,n) for(int i = 0; i< (n);i++)
#define SORT(a) sort((a).begin(),(a).end());
#define che(a,string) cout<<string<<":"<<(a)<<endl;
#define ch(a,string) cout<<string<<":"<<(a)<<" ";
using namespace std;
typedef pair<int,int> p;
using  ll = long long;
#define INF 2000000000
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;
}
	int main(){
		int n,k;cin>>n>>k;
	/*	vector<int> K(k);
		rep(i,k){
			K[i]=i+1;
		}*/
		//KはK段先まで飛べますよ～～
	vector<int> h(n);
	rep(i,n){
		cin>>h[i];
	}
	//i(>=1)番目の高さをh[i-1]に格納
	vector<long long> dp(100010,INF);
	dp[0]=0;
	dp[1]=0;
	for(int i = 2 ; i <= n ; i ++){//dpの中身の作成
		for( int K = k;K>0;K--){
			if(K<i){
				int a = abs(h[i-1] - h[i - K-1]);
			//	che(a,'a');
			chmin(dp[i], dp[i-K] +a );
				//chmin(dp[i],dp[i-k]+abs(h[i]-h[i-k]));
			}
		}
	}
	cout<<dp[n]<<endl;
	}



Measured memory_bytes: 1408
//小数点以下　cout << fixed << setprecision(10) << num << endl;
//桁数はlog10(mid)でやれ　log(mid)/log(10)はWA
//long*long<0で判定するな
//開区間と閉区間
//アルファベットが何番目かは x=s[i]-'a'
//bfsはmain()内で　rep(i,h)rep(j,w)rep(i,4)でバグ
//切り上げ：(a+(b-1))/b
//32bit以上は 1ull<<j
// map 初期値0 for(auto itr=mp.begin();itr!=mp.end();++itr) itr->fi itr->se で全探索
// for(auto u:mp) u.fi u.se も可能
//n個のgcd,lcmは一つずつみて更新していく
//大きな数を扱うときは素因数分解した形で持っておく
// (l/a[i]) = l*powmod(a[i],MOD-2)%MOD;
//auto itr=lower_bound(ALL(a),key) a[itr-a.begin()]
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <queue>
#include <stack>
#include <tuple>
#include <cmath>
#include <iomanip>
#include <map>
#include <stdio.h>
#include <cstring> //memset(dp,0,sizeof(dp))
#include <functional> //operator[]
#define ll long long
#define rep(i,n) for(int i=0;i<(n);i++)
#define rrep(i,n) for(int i=n-1;i>=0;i--)
#define fi first
#define se second
#define pb push_back
#define ALL(a) (a).begin(),(a).end()
using namespace std;
template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}
typedef pair<int,int> P;
typedef pair<ll,ll> Pll;

struct edge{
    int from;
    int to;
    ll cost;
};

signed main(){
    int n,m;
    cin >> n >> m;
    vector<edge> v;
    ll d[n];
    rep(i,n) d[i] = 1001001001001001;
    d[0]=0;
    rep(i,m){
        edge e;
        cin >> e.from >> e.to >> e.cost;
        e.from--; e.to--;
        e.cost*=-1;
        v.pb(e);
    }
    //for(auto e:v) cout << e.from <<" "<<e.to<<" "<<e.cost<<endl;
    bool ng=0;
    rep(i,n){
        rep(j,v.size()){
            edge e = v[j];
            if(d[e.to] > d[e.from]+e.cost){
                d[e.to] = d[e.from] + e.cost;
                if(i==n-1){
                    ng=1;
                    break;
                }
            }
        }
    }
    if(ng){
        ll pre=d[n-1];
        rep(i,n){
            rep(j,v.size()){
                edge e = v[j];
                if(d[e.to] > d[e.from]+e.cost){
                    d[e.to] = d[e.from] + e.cost;
                    if(i==n-1){
                        ng=1;
                        break;
                    }
                }
            }
        }
        if(pre!=d[n-1]){
            cout << "inf" << endl;
            return 0;
        }
    }
    cout << -1*d[n-1] << endl;
}


Measured memory_bytes: 256
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,pprint,fractions
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

x,k = inpl()
print('Yes' if x*500 >= k else 'No')

Measured memory_bytes: 65516
def check(N,target,A,K):
  cnt = 0
  for i in range(N):
    cnt += -(-A[i]//target)-1
  if cnt>K:
    return False
  return True

def solve():
  ans = 0
  N, K = map(int, input().split())
  A = list(map(int, input().split()))
  low = 1
  high = 10**9+1
  mid = (low+high)//2
  while high>low+1:
    if check(N,mid,A,K):
      high = mid
    else:
      low = mid
    mid = (low+high)//2
  if check(N,low,A,K):
    ans = low
  else:
    ans = high
  return ans
print(solve())

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

int main() {
    vector<vector<int>> A(3,vector<int>(3));
    for (int i=0; i<3; i++) {
        cin >> A.at(i).at(0) >> A.at(i).at(1) >> A.at(i).at(2); 
    }
    int N;
    cin >> N;
    vector<int> b(N);
    for (int i=0; i<N; i++) {
        cin >> b[i];
    }


    string ans = "No";
    for (int k=0; k<N; k++) {
        for (int i=0; i<3; i++) {
            for (int j=0; j<3; j++) {
                if (b[k]==A.at(i).at(j)) {
                    A.at(i).at(j) = 0;
                }
            }
        }
        if (A.at(0).at(0)==0 and A.at(0).at(1)==0 and A.at(0).at(2)==0) {
            ans = "Yes";
            break;
        }
        else if (A.at(1).at(0)==0 and A.at(1).at(1)==0 and A.at(1).at(2)==0) {
            ans = "Yes";
            break;
        }
        else if (A.at(2).at(0)==0 and A.at(2).at(1)==0 and A.at(2).at(2)==0) {
            ans = "Yes";
            break;
        }
        else if (A.at(0).at(0)==0 and A.at(1).at(0)==0 and A.at(2).at(0)==0) {
            ans = "Yes";
            break;
        }
        else if (A.at(0).at(1)==0 and A.at(1).at(1)==0 and A.at(2).at(1)==0) {
            ans = "Yes";
            break;
        }
        else if (A.at(0).at(2)==0 and A.at(1).at(2)==0 and A.at(2).at(2)==0) {
            ans = "Yes";
            break;
        }
        else if (A.at(0).at(0)==0 and A.at(1).at(1)==0 and A.at(2).at(2)==0) {
            ans = "Yes";
            break;
        }
        else if (A.at(0).at(2)==0 and A.at(1).at(1)==0 and A.at(2).at(0)==0) {
            ans = "Yes";
            break;
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3524
#include <bits/stdc++.h>
#define mset(a,b) memset(a,b,sizeof a)
#define mcpy(a,b) memcpy(a,b,sizeof b)
#define lb(x) ((x)&(-(x)))
#define xx first
#define yy second
#define pb push_back
#define mp make_pair
#define pii pair<int,int> 
#define dalao 1000000007
#define inf 0x3f3f3f3f
#define N 15
using namespace std;
typedef long long ll;
struct edge{int a,b;double v;bool operator <(const edge& x)const{return v<x.v;};}e[N*N];
int n,a[N],x[N],y[N],fa[N],cnt;
double A,B,dis[N][N],val[1<<N|1],f[1<<N|1];
inline int find(int x){while(fa[x]^x)x=fa[x]=fa[fa[x]];return x;}
inline double min(double a,double b){return a<b?a:b;}
int main(){
	scanf("%d",&n);
	for(int i=0;i<n;i++)scanf("%d%d%d",&x[i],&y[i],&a[i]);
	for(int i=0;i<n;i++)for(int j=0;j<n;j++)dis[i][j]=sqrt(1ll*(x[i]-x[j])*(x[i]-x[j])+1ll*(y[i]-y[j])*(y[i]-y[j]));
	for(int i=0;i<(1<<n);i++){
		cnt=A=B=0;
		for(int j=0;j<n;j++){
			fa[j]=j;
			if(i>>j&1)A+=a[j];
		}
		for(int j=0;j<n;j++)if(i>>j&1)for(int k=j+1;k<n;k++)if(i>>k&1)
			e[++cnt]=(edge){j,k,dis[j][k]};
		sort(e+1,e+1+cnt);
		for(int j=1;j<=cnt;j++){
			e[j].a=find(e[j].a),e[j].b=find(e[j].b);
			if(e[j].a^e[j].b)fa[e[j].a]=e[j].b,B+=e[j].v;
		}
		val[i]=max(.0,(A-B)/__builtin_popcount(i));
	}
	for(int i=1;i<(1<<n);i++){
		f[i]=val[i];
		for(int j=(i-1)&i;j;j=(j-1)&i)
			f[i]<min(f[j],val[i-j])?f[i]=min(f[j],val[i-j]):0;
	}
	printf("%.12lf",f[(1<<n)-1]);
	return 0;
}

Measured memory_bytes: 768
FAST_IO = 1
if FAST_IO:
    import io, sys, atexit
    rr = iter(sys.stdin.read().splitlines()).next
    sys.stdout = _OUTPUT_BUFFER = io.BytesIO()
    @atexit.register
    def write():
        sys.__stdout__.write(_OUTPUT_BUFFER.getvalue())
else:
    rr = raw_input
rri = lambda: int(rr())
rrm = lambda: map(int, rr().split())

N = rri()
arr = rrm()



def solve(N, arr):
    ans= arr[0]
    if 0 in arr:
        return 0
    for i in range(1, N):
        if ans > 10**18:
            return -1
        else:
            ans *= arr[i]
    if ans >10**18:
        return -1
    return ans

print(solve(N, arr))


Measured memory_bytes: 84088
split = input().split()
a = int(split[0])
b = int(split[1])
c = int(split[2])
nums = []

check = a if a < b else b

for i in range(1, check + 1, 1):
    if a % i == 0 and b % i == 0:
        nums.append(i)
print(nums[-c])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define debug(x) cerr<<#x<<": "<<x<<endl
#define sz(x) (int)(x).size()
#define trav(a,x) for(auto &a:x)
#define all(x) x.begin(), x.end()
using ll = long long;
const ll MOD=998244353;
vector<int> labels(vector<vector<int>> g) {
    int n = sz(g);
    vector<int> label(n);
    for(int i=n-1;i>=0;--i) {
        vector<int> others;
        for(int j:g[i]) if(j>i) others.push_back(label[j]);
        sort(all(others));
        int k=0;
        for(int x:others) {
            if(x==k) ++k;
            else if(x>k) break;
        }
        label[i]=k;
    }
    return label;
}
vector<vector<int>> getgraph(int n) {
    int m;
    cin>>m;
    vector<vector<int>> g(n);
    rep(i,0,m) {
        int a,b;
        cin>>a>>b;
        --a;--b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    return g;
}
int main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int n;
    cin>>n;
    ll B = 1;
    rep(i,0,18) B=(B*10)%MOD;
    vector<ll> power(n,B);
    rep(i,1,n) power[i]=(B*power[i-1])%MOD;
    auto g1 = getgraph(n);
    auto g2 = getgraph(n);
    auto g3 = getgraph(n);
    auto l1 = labels(g1), l2 = labels(g2), l3=labels(g3);
    vector<ll> w1(2*n), w2(2*n), w3(2*n);
    rep(i,0,n) {
        w1[l1[i]]=(w1[l1[i]]+power[i])%MOD;
        w2[l2[i]]=(w2[l2[i]]+power[i])%MOD;
        w3[l3[i]]=(w3[l3[i]]+power[i])%MOD;
    }
    // rep(i,0,n) {
    //     cerr<<w1[i]<<" "<<w2[i]<<" "<<w3[i]<<"\n";
    // }
    int mxl1=0,mxl2=0;
    rep(i,0,n) {
        if(w1[i]!=0) mxl1=i;
        if(w2[i]!=0) mxl2=i;
    }
    ll ans=0;
    rep(i,0,mxl1+1) rep(j,0,mxl2+1) {
        ll x=(w1[i]*w2[j])%MOD;
        ans=(ans+x*w3[i^j])%MOD;
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 24280
#include <stdio.h>
 
int main(void){
	
	char a[2],b[2];
	int x,y;
	
	scanf("%s%s",a,b);
	
	if(a[0]=='A'){x=10;}
	if(a[0]=='B'){x=11;}
	if(a[0]=='C'){x=12;}
	if(a[0]=='D'){x=13;}
	if(a[0]=='E'){x=14;}
	if(a[0]=='F'){x=15;}
	
	if(b[0]=='A'){y=10;}
	if(b[0]=='B'){y=11;}
	if(b[0]=='C'){y=12;}
	if(b[0]=='D'){y=13;}
	if(b[0]=='E'){y=14;}
	if(b[0]=='F'){y=15;}
	
	if(x<y){
	printf("<\n");
	} else if(x>y){
	printf(">\n");
	} else {
	printf("=\n");
	}
	return 0;
}

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

#define count_bits(n) (0x0000ffff&((0x00ff00ff&((0x0f0f0f0f&((0x33333333&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))+((0xcccccccc&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))>>2)))+((0xf0f0f0f0&((0x33333333&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))+((0xcccccccc&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))>>2)))>>4)))+((0xff00ff00&((0x0f0f0f0f&((0x33333333&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))+((0xcccccccc&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))>>2)))+((0xf0f0f0f0&((0x33333333&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))+((0xcccccccc&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))>>2)))>>4)))>>8)))+((0xffff0000&((0x00ff00ff&((0x0f0f0f0f&((0x33333333&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))+((0xcccccccc&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))>>2)))+((0xf0f0f0f0&((0x33333333&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))+((0xcccccccc&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))>>2)))>>4)))+((0xff00ff00&((0x0f0f0f0f&((0x33333333&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))+((0xcccccccc&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))>>2)))+((0xf0f0f0f0&((0x33333333&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))+((0xcccccccc&((0x55555555&(n))+((0xaaaaaaaa&(n))>>1)))>>2)))>>4)))>>8)))>>16)

int main(){
    int n, m;
    cin >> n >> m;
    int s[m];
    int p[m];

    memset(s, 0, sizeof(int)*m);
    for(int i=0; i<m; i++){
        int k;
        cin >> k;
        for(int j=0; j<k; j++){
            int si;
            cin >> si;
            s[i] |= (1<<(si-1));
        }
    }

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

    int res_cnt=0;
    for(int i=0; i<(1<<n); i++){
        int on_cnt=0;
        for(int j=0; j<m; j++){
            if((count_bits(i&s[j]) & 1) == p[j]){
                on_cnt ++;
            }
        }
        if(on_cnt == m){
            res_cnt++;
        }
    }
     
    cout << res_cnt << endl;

    return 0;
}

Measured memory_bytes: 256
/* C/C++ program to remove invalid parenthesis */
#include <bits/stdc++.h> 
using namespace std; 
#define ll long long int
//#define inf 1e9+1

ll dp[3001][3001][2];

ll fun(int i, int j,int arr[], int turn)
{
    if(i>j)
    return 0;
    if(dp[i][j][turn]!=-1)
    return dp[i][j][turn];
    if(turn==1)
    return dp[i][j][turn]=max(arr[i]+fun(i+1,j,arr,0),arr[j]+fun(i,j-1,arr,0));
    else
    return dp[i][j][turn]=min(fun(i+1,j,arr,1),fun(i,j-1,arr,1));
}
int main() 
{ 
   int n;
   cin>>n;
   int arr[n];
  // ll dp[n][n];
   ll sum=0;
   for(int i=0;i<n;i++){
    cin>>arr[i];
    sum+=arr[i];
   }
   
     memset(dp,-1,sizeof(dp));
    ll scoreA=fun(0,n-1,arr,1);
   // cout<<scoreA<<"  "<<sum<<" ";
    ll scoreB=sum-scoreA;
    ll ans=scoreA-scoreB;
    cout<<ans;
	return 0; 
} 


Measured memory_bytes: 141184
#include<iostream>
#include<algorithm>
using namespace std;
int n,a[100005],b[100005],r;
int main()
{
	cin>>n;
	for(int i=0;i<100005;i++)
	    b[i]=0;
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		r=a[i];
		if(r!=0)
		    b[r-1]++;
		b[r]++;
		b[r+1]++;
	}
	sort(b,b+100005);
	reverse(b,b+100005);
	cout<<b[0];
	return 0;
}

Measured memory_bytes: 1024