akhauriyash/Code-Regression huggingface dataset:
from collections import Counter


class Bit:
  def __init__(self, n):
    self.size = n
    self.tree = [0] * (n + 1)
  
  def sum(self, i):
    s = 0
    while i > 0:
      s += self.tree[i]
      i -= i & -i
    return s
  
  def add(self, i, x):
    while i <= self.size:
      self.tree[i] += x
      i += i & -i

n,k = map(int, input().split())
aaa = list(map(int, input().split()))
MOD = 10**9 + 7
bit = Bit(2001)
single = 0
for a in reversed(aaa):
  single += bit.sum(a)
  bit.add(a + 1, 1)
ans = single * k % MOD
coef = k * (k - 1) // 2 % MOD
cnt = Counter(aaa)
before = 0
for a, c in sorted(cnt.items()):
  ans = (ans + c * before * coef) % MOD
  before += c
print(ans)





Measured memory_bytes: 3564
# -*- coding: utf-8 -*-
"""
Created on Sat Mar  9 23:07:39 2019

@author: Yamazaki Kenichi
"""

A,B = map(int,input().split())

def a(A):
    if A % 4 == 0:
        return A
    elif A % 4 == 2:
        return A ^ 1
    elif A % 4 == 1:
        return 1
    elif A % 4 == 3:
        return 0

ans = a(A-1)^a(B)      
      
print(ans)

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

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n, d;
  cin >> n >> d;
  int x[n][d];
  int dis = 0;
  int ans = 0;
  for(int i = 0; i < n; i++) {
    for(int j = 0; j < d; j++) {
      cin >> x[i][j];
    }
  }
  
  for(int i = 0; i < n; i++) {
    for(int j = i + 1; j < n; j++) {
      for(int k = 0; k < d; k++) {
        dis += pow(x[i][k] - x[j][k], 2);
      }
      for(int h = 1; h <= 400; h++) {
        if(dis == h * h) {
          ans++;
        }
      }
      dis = 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
import math
PI = math.pi

a, b, h, m = map(int, input().split())
x1 = a * math.cos((PI/2) - 2*PI*(60*h+m)/720)
y1 = a * math.sin((PI/2) - 2*PI*(60*h+m)/720)
x2 = b * math.cos((PI/2) -2*PI*m/60)
y2 = b * math.sin((PI/2) -2*PI*m/60)


print(((x2-x1)**2 + (y2-y1)**2)**.5)


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

int main() {
	int n;
	cin >> n;
	int a[n];
	for (int i = 0; i < n; ++i) {
		cin >> a[i];
	}
	sort (a, a + n);

	int elementsToBeRemoved = 0;
	for (int i = 0; i < n;) {
		int item = a[i];
		int count = 0;
		while (i < n && item == a[i]) {
			++i;
			++count;
		}
		if (count >= item) {
			elementsToBeRemoved += (count - item);
		} else {
			elementsToBeRemoved += count;
		}
	}
	cout << elementsToBeRemoved;
	return 0;
}

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

using namespace std;

#define all(x) x.begin(), x.end()
#define sz(x) (int) x.size()
#define pb push_back
#define endl '\n'
#define snd second
#define fst first
#define fastio cin.tie(NULL),cout.sync_with_stdio(true)

typedef long long int ll;
typedef unsigned long long int ull;
typedef vector <int> vi;
typedef pair <ll,int> ii;
typedef pair <ii,int> iii;

const int mod = 1e9 + 7;
const int N = 300005;
int st[4*N], dp[N];
int query(int id, int l, int r, int i, int j){
    if(r < i or l > j) return 0;
    if(l >= i and r <= j)
        return st[id];
    return max(query(2*id, l, (l+r)/2, i, j) ,
            query(2*id+1, (l+r)/2+1, r, i, j));
}
void update(int id, int l, int r, int i, int x){
    if(r < i or l > i)
        return ;
    if(l == i and r == i) {
        st[id] = x;
    } else {
        update(2*id, l, (l+r)/2, i, x);
        update(2*id+1, (l+r)/2+1, r, i, x);
        st[id] = max(st[2*id], st[2*id+1]);
    }
}
int main(){
	fastio;
	int n,k;
	cin >> n >> k;
	vi v(n+1);
	for(int i = 1; i <= n; i++)
		cin >> v[i];
	int ans = 0;
	for(int i = 1; i <= n; i++){
		int temp = query(1,0,300000,v[i]-k, v[i]+k) + 1;
		ans = max(ans, temp);
		cerr << v[i] <<" " << temp << endl;
		update(1,0,300000, v[i], temp);
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 9688
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
inline ll gcd(ll a, ll b) { return b ? gcd(b, a%b) : a; }
inline ll lcm(ll a, ll b) { return a / gcd(a, b)*b; }
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T>& V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> >& Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T>& mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }
template<typename T>vector<T> make_v(size_t a){return vector<T>(a);}
template<typename T,typename... Ts>auto make_v(size_t a,Ts... ts){return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type fill_v(T &t,const V &v){t=v;}
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type fill_v(T &t,const V &v){for(auto &e:t) fill_v(e,v);}
/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

template<class Type>
Type solve(Type res = Type()){
    ll A,B; cin >> A >> B;
    res = max({A+B,A-B,A*B});
    return res;
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    // solve(0);
    cout << fixed << setprecision(15) << solve<ll>() << endl;
    return 0;
}


Measured memory_bytes: 764
#if 0

#endif
#include <iostream>
#include <memory>
#include <vector>
#include <string>
#include <algorithm>
#include <assert.h>
#include <complex>
#include <queue>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
using namespace std;
using ll = long long;
ll ll_max = numeric_limits<ll>::max();
ll ll_min = numeric_limits<ll>::min();
int int_max = numeric_limits<int>::max();
int int_min = numeric_limits<int>::min();
int N, id, C, to;
vector<int> V[100];
int t = 0;
int visit[100][2] = {};
void dfs(int cur) {
    t += 1;
    visit[cur][0] = t;
    for (auto v : V[cur]) {
        if (visit[v][0] == 0) dfs(v);
    }
    t += 1;
    visit[cur][1] = t;
} 


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

    cin >> N;
    rep(n, N) {
        cin >> id >> C;
        rep(c, C) {
            cin >> to;
            V[n].push_back(to - 1);
        }
    }
    
    rep(n, N) {
        if (visit[n][0] == 0)
            dfs(n);
    }
        

    rep(n, N) cout << n + 1 << " " << visit[n][0] << " " << visit[n][1] << endl;

    return 0;
}


Measured memory_bytes: 3208
#include<iostream>
#include<cassert>
#include <algorithm>
using namespace std;
int a[201],w[201],n;
int merge_and_count(int l,int r){
  if(l+1>=r)return 0;
  if(l+2==r){
    if(a[l]<=a[l+1])return 0;
    else{
      swap(a[l],a[l+1]);
      return 1;
    }
  }
  int m= (l+r)/2;
  int cl=merge_and_count(l,m);
  int cr=merge_and_count(m,r);
  int ret=cl+cr;
  int i=l,j=m,k=l;
  while(i<m&&j<r&&k<r){
    if(a[i]<=a[j])w[k++]=a[i++];
    else{
      w[k++]=a[j++];
      ret+=m-i;
    }
  }
  while(i<m)w[k++]=a[i++];
  while(j<r)w[k++]=a[j++];
  assert(k==r);
  for(i=l;i<r;i++){
    a[i]=w[i];
  }
  //cout<<"marge"<<l<<" "<<r<<" "<<ret<<endl;
  return ret;
}
int main(){
  while(cin>>n&&n){
    for(int i=0;i<n;i++){
      cin>>a[i];
    }
    cout<<merge_and_count(0,n)<<endl;
  }
}

Measured memory_bytes: 1160
#include <iostream>
#include <vector>
#include <queue>
using namespace std;

int main()
{
    int n,m;
    cin >> n >> m;
    vector<vector<int>> vec(n,vector<int>());
    for(int i = 0; i < m; ++i)
    {
        int a,b;
        cin >> a >> b;
        --a;
        --b;
        vec[a].push_back(b);
        vec[b].push_back(a);
    }

    vector<bool> checker(n);
    queue<int> que;
    vector<int> stone(n);
    stone[0] = 0;
    que.push(0);
    checker[0] = true;
    while(!que.empty())
    {
        int t = que.front();
        que.pop();
        for(int next : vec[t])
        {
            if(checker[next])
            {
                continue;
            }
            stone[next] = t;
            que.push(next);
            checker[next] = true;
        }
    }

    cout << "Yes" << endl;
    for(int i = 1; i < n; ++i)
    {
        cout << stone[i] + 1 << endl;
    }
}

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

class State
{
private:
    int D;
    vector<int> c;
    vector<vector<int>> s;
    vector<int> t;
    int64_t score;
    vector<vector<int>> ds;

    int sum(int x)
    {
        return x * (x + 1) / 2;
    }

public:
    State(int D, vector<int> c, vector<vector<int>> s, vector<int> t) : D(D), c(c), s(s), t(t)
    {
        score = 0;
        ds = vector<vector<int>>(26);
        vector<int> last(26, -1);
        for (int d = 0; d < D; d++)
        {
            last.at(t.at(d)) = d;
            score += s.at(d).at(t.at(d));
            for (int i = 0; i < 26; i++)
            {
                if (i == t.at(d))
                    continue;
                score -= c.at(i) * (d - last.at(i));
            }
            ds.at(t.at(d)).push_back(d);
        }
    }

    int64_t getScore()
    {
        return score;
    }

    void change(int d, int td_new)
    {
        int td_old = t.at(d);

        {
            int idx = 0;
            while (idx < (int)ds.at(td_old).size() && ds.at(td_old).at(idx) != d)
                idx++;
            int d_prev = (idx - 1 < 0) ? -1 : ds.at(td_old).at(idx - 1);
            int d_next = (idx + 1 >= (int)ds.at(td_old).size()) ? D : ds.at(td_old).at(idx + 1);
            score -= s.at(d).at(td_old);
            score += sum(d - 1 - d_prev) * c.at(td_old);
            score += sum(d_next - 1 - d) * c.at(td_old);
            score -= sum(d_next - 1 - d_prev) * c.at(td_old);
            ds.at(td_old).erase(ds.at(td_old).begin() + idx);
        }
        {
            int idx = 0;
            while (idx < (int)ds.at(td_new).size() && ds.at(td_new).at(idx) < d)
                idx++;
            int d_prev = (idx - 1 < 0) ? -1 : ds.at(td_new).at(idx - 1);
            int d_next = (idx >= (int)ds.at(td_new).size()) ? D : ds.at(td_new).at(idx);
            score += s.at(d).at(td_new);
            score -= sum(d - 1 - d_prev) * c.at(td_new);
            score -= sum(d_next - 1 - d) * c.at(td_new);
            score += sum(d_next - 1 - d_prev) * c.at(td_new);
            ds.at(td_new).insert(ds.at(td_new).begin() + idx, d);
        }

        t.at(d) = td_new;
    }
};

void solve(int D, vector<int> c, vector<vector<int>> s, vector<int> t, int M, vector<int> d, vector<int> q)
{
    State state = State(D, c, s, t);
    for (int i = 0; i < M; i++)
    {
        state.change(d.at(i), q.at(i));
        cout << state.getScore() << endl;
    }
}

int main()
{
    int D;
    cin >> D;
    vector<int> c(26);
    for (int i = 0; i < 26; i++)
    {
        cin >> c.at(i);
    }
    vector<vector<int>> s(D, vector<int>(26));
    for (int i = 0; i < D; i++)
    {
        for (int j = 0; j < 26; j++)
        {
            cin >> s.at(i).at(j);
        }
    }
    vector<int> t(D);
    for (int i = 0; i < D; i++)
    {
        cin >> t.at(i);
        t.at(i)--;
    }
    int M;
    cin >> M;
    vector<int> d(M);
    vector<int> q(M);
    for (int i = 0; i < M; i++)
    {
        cin >> d.at(i);
        cin >> q.at(i);
        d.at(i)--;
        q.at(i)--;
    }
    solve(D, move(c), move(s), move(t), M, move(d), move(q));
    return 0;
}


Measured memory_bytes: 4188
#include <stdio.h>

int main(void)
{
	int a,b,c,ma,mb,mc;
	
	scanf("%d%d%d", &ma,&mb,&mc);
	a = mc;
	b = ma;
	c = mb;
	printf("%d %d %d\n",a,b,c);
	return 0;
}

Measured memory_bytes: 128
# -*- coding: utf-8 -*-
N = int(input())
A = input().split()

B = [0]
for i in range(N):
    B.append(B[i] + int(A[i]))

sum = 0
for i in range(N):
    sum += int(A[i]) * (B[N] - B[i+1])

print(sum % (10**9 + 7))


Measured memory_bytes: 34480
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const long long INF = 1LL << 60;

int main(){
    ll n;
    cin >> n;
    string ans;

    while(n) {
        int x;
        n--;
        x = n % 26;
        char c = (char('a'+ x));
        ans += c;
        n /= 26;
    }
    reverse(ans.begin(), ans.end());
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3592
import java.util.Scanner

case class Point(x: Double, y: Double) {
  def distanceTo(that: Point) = this.minus(that).norm
  def scale(c: Double) = Point(c*x, c*y)
  def add(that: Point) = that match { case Point(xx, yy) => Point(x+xx,y+yy) }
  def minus(that: Point) = add(that.scale(-1))
  def norm = math.sqrt(x*x+y*y)
  def normalized = this.scale(1.0/norm)
  def ortho = Point(y, -x)
}

object Point {
    def intersections(p1: Point, p2: Point, r: Double): Option[(Point, Point)] = {
    val m = p1.add(p2).scale(1.0/2)
    val h = p1.distanceTo(m)
    if (r > h) {
      val d = math.sqrt(r*r-h*h)
      val dv = p1.minus(p2).ortho.normalized.scale(d)
      Some((m.add(dv), m.minus(dv)))
    } else None
  }
}

case class Input(ps: List[Point]) {
  private def nearAll(from: Point, r: Double,
                      e1: Point, e2: Point): Boolean =
    ps.forall(p => p == e1 || p == e2 || from.distanceTo(p) <= r)
  private def ok(r: Double): Boolean = {
    val bs = for (List(p1, p2) <- ps.combinations(2)) yield
      Point.intersections(p1, p2, r) match {
        case None => false
        case Some((ip1, ip2)) => {
          nearAll(ip1, r, p1, p2) || nearAll(ip2, r, p1, p2)
        }
      }
    bs.exists(identity)
  }
  private def binsearch(lb: Double, ub: Double): Double = {
    if (ub - lb < math.pow(10, -7)) ub
    else {
      val m = (lb + ub) / 2
      if (ok(m)) binsearch(lb, m)
      else binsearch(m, ub)
    }
  }
  def solved: Output = {
    val ans = binsearch(0, 1500000)
    Output(ans)
  }
}

object Input {
  def fromStdin(): Input = {
    val sc = new Scanner(System.in)
    val n = sc.nextInt()
    def nextPoint() =  Point(sc.nextInt(), sc.nextInt())
    Input(List.fill(n)(nextPoint))
  }
}

case class Output(ans: Double) {
  override def toString(): String = {
    ans.toString()
  }

  def print() = println(this.toString())
}

object Main extends App {
  Input.fromStdin().solved.print()
}


Measured memory_bytes: 49592
#include <bits/stdc++.h>
using ll = long long;
using namespace std;
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <typename T> bool chmax(T &a, const T &b) {
    if(a < b) {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T> bool chmin(T &a, const T &b) {
    if(a > b) {
        a = b;
        return 1;
    }
    return 0;
}
const long long INFLL = 1LL << 60;
const long long MOD = 1e9 + 7;
int main() {
    int list[3][3];
    rep(i, 3) rep(j, 3) cin >> list[i][j];
    bool check[3][3] = {};
    int N;
    cin >> N;
    int b;
    rep(n, N) {
        cin >> b;
        rep(i, 3) rep(j, 3) if(b == list[i][j]) check[i][j] = 1;
    }
    int bingo = 0;
    rep(i, 3) {
        if(check[i][0] && check[i][1] && check[i][2]) bingo++;
        if(check[0][i] && check[1][i] && check[2][i]) bingo++;
    }
    if(check[0][0] && check[1][1] && check[2][2]) bingo++;
    if(check[2][0] && check[1][1] && check[0][2]) bingo++;
    cout << (bingo > 0 ? "Yes" : "No") << endl;
}

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

using namespace std;

int main()
{
    int a, b, c, k;
    cin >> a >> b >> c >> k;
    int sum = 0;
    if(k >= a){
        sum += a;
        k -= a;
        if(k >= b){
            k -= b;
            if(k >= c){
                sum -= c;
                cout << sum << endl;
            }
            else{
                sum -= k;
                cout << sum << endl;
            }
        }
        else{
            cout << sum << endl;
        }
    }
    else{
        sum += k;
        cout << sum << endl;
    }
    return 0;
}


Measured memory_bytes: 3588
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second

void io(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    #ifdef LOCAL
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
}
const int N = 1e6 + 50;
ll mod = 998244353;
auto seed = chrono::high_resolution_clock::now().time_since_epoch().count();
mt19937_64 mt(seed);
int fac[N],invf[N];
inline int add(int x, int y) { return x + y >= mod ? x + y - mod : x + y; }
inline int sub(int x, int y) { return x - y >= 0 ? x - y : x - y + mod; }
inline int power(int x, int y, int res = 1) {
    for (; y; y >>= 1, x = 1ll * x * x % mod) {
        if (y & 1) { res = 1ll * res * x % mod; }
    } return res;
}
void initcombi(int n) {
    for (int i = fac[0] = 1; i <= n; i++) { fac[i] = 1ll * fac[i - 1] * i % mod; }
    invf[n] = power(fac[n], mod - 2);
    for (int i = n; i; i--) { invf[i - 1] = 1ll * invf[i] * i % mod; }
}
 
inline int NCR(int n, int m) {
    if (n < m) { return 0; }
    return 1ll * fac[n] * invf[m] % mod * invf[n - m] % mod;
}
ll maxx;
int a[N];
int main() {
    io();
    int k, n;
    cin >> k >> n;

    for(int i = 0; i < n; i++) {
        cin >> a[i];
    }
    a[n] = a[0] + k;
    for(int i = 1; i <= n; i++) {
        if(a[i] - a[i - 1] > maxx)  maxx = a[i] - a[i - 1];
    }
    cout << k - maxx;
}
    

Measured memory_bytes: 3072
#include <iostream>
#include <stdio.h>
#include <complex>
using namespace std;
typedef complex<double> xy_t;
xy_t P[110];
double cross_product(xy_t a, xy_t b) { return (conj(a)*b).imag(); }
int main(int argc, const char * argv[]) {
    int N=0;
    double x, y;
    while(~scanf("%lf,%lf", &x, &y)){
        P[N++] = xy_t(x,y);
    }
    double sum = 0.0;
    for (int i=0; i+2<N; ++i){
        xy_t a=P[0], b=P[i+1], c=P[i+2];
        sum += cross_product(b-a, c-a)*0.5;
    }
    printf("%.6f\n",abs(sum));
    return 0;
}

Measured memory_bytes: 1244
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
const int INF = 1e9 + 7;

int dp[4][N];
int ac[4][N];

int main()
{
	ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
	memset(dp,0,sizeof(dp));

	int n;
	cin>>n;
	
	for(int i=1;i<=n;++i)
		for(int j=0;j<3;++j)
			cin>>ac[j][i];
	
	for(int i=1;i<=n;++i)	
	{
		for(int j=0;j<3;++j)
		{
			dp[j][i] = max(dp[(j+1)%3][i-1] , dp[(j+2)%3][i-1]) + ac[j][i];
		}
	}

	int ans = 0;
	for(int i=0;i<3;++i)
		ans = max(ans,dp[i][n]);
	cout<<ans<<"\n";
}

Measured memory_bytes: 2944
n=int(input())
x=list(map(int,input().split()))

from copy import deepcopy

y=sorted(x)

res='NO'

if x==y:
	res='YES'
else:
	for i in range(n-1):
		for j in range(i+1,n):
			z=deepcopy(x)
			a=z[i]
			b=z[j]
			z[i]=b
			z[j]=a
			if z==y:
				res='YES'
				break
		if res=='YES':
			break

print(res)

Measured memory_bytes: 3444
#define TEST_MODE true
 
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
 
#include "bits/stdc++.h"
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define rep2(i, a, b) for (int i = (a); i < (int)(b); ++i)
#define rrep(i, n) for (int i = (n)-1; i >= 0; --i)
#define rrep2(i, a, b) for (int i = (a)-1; i >= (int)b; --i)
#define range(i, a, b, c) for (int i = a;		\
                               c > 0 ? i < b : i > b;	\
                               i += c)
#define chmax(a, b) (a = (a) < (b) ? (b) : (a))
#define chmin(a, b) (a = (a) > (b) ? (b) : (a))
using ll = long long;
using ull = unsigned long long;
using ld = long double;
#define all(a) begin(a), end(a)
#define ifnot(a) if (not(a))
#define int long long
 
#if TEST_MODE == true
const bool test = true;
#define dump(x) cerr << #x << " = " << (x) << " "
#define dumpl(x) cerr << #x << " = " << (x) << " " << endl;
#else
const bool test = false;
#define dump(x) 
#define dumpl(x) 
#endif
 
int dx[] = {1, 0, -1, 0};
int dy[] = {0, 1, 0, -1};
const int INF = (int)1 << 60;
const ll INFL = (ll)1 << 60;
ll mod_n = (int)1e9 + 7;
const double eps = 1e-10;
typedef long double Real;
// return -1, 0, 1
int sgn(const Real &r) { return (r > eps) - (r < -eps); }
int sgn(const Real &a, const Real &b) { return sgn(a - b); }
 
//.....................
const int MAX = (int)2e5 + 5;
 
vector<string> split(const string &str, char sep)
{
  vector<string> v;
  stringstream ss(str);
  string buffer;
  while (getline(ss, buffer, sep))
    {
      v.push_back(buffer);
    }
  return v;
}
 
template <class InputIterator>
int sum(InputIterator begin, InputIterator end)
{
  return accumulate(begin, end, 0ll);
}
 
template<typename T>
T gcd(T a, T b)
{
  T c;
  while (a != 0) {
    c = a; a = b%a;  b = c;
  }
  return b;
}
 
void solve();
 
class Solver {
public:
  string s;

  void solve() {
    cin >> s;
    cout << "2018" + s.substr(4, s.size()) << endl;
  }
};
 
signed main()
{
  srand(time(NULL));
  cout << fixed << setprecision(20);
  auto ptr = new Solver();
  ptr->solve();
  delete ptr;
  // while (true) {    
  //     auto ptr = new Solver();
  //     ptr->solve();
  //     delete ptr;
  // }
  return 0;
}
 
// class Mycin {
// 	bool flag = true;
// public:
// 	Mycin& operator >> (int& a) {flag = scanf("%lld", &a) != EOF; return *this;}
// 	Mycin& operator >> (char& a) {flag = scanf("%c", &a) != EOF; return *this;}
// 	Mycin& operator >> (string& s) {flag = (bool)(cin >> s); return *this;}
// 	operator bool() {return flag;}
// } mycin;
 
// class Mycout {
// public:
// 	Mycout& operator << (const int& a) {printf("%lld", a); return *this;}
// 	Mycout& operator << (const char c) {printf("%c", c); return *this;}
// 	Mycout& operator << (const string& s) {printf("%s", s.c_str()); return *this;}
// } mycout;
 
// #define cin mycin
// #define cout mycout
// #define endl '\n'


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

#define EB emplace_back
#define int long long
#define F first
#define S second
#define N 500005
#define all(x) x.begin(),x.end()
#define endl '\n'
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)

using namespace std;

int32_t main(){
	IOS;
	int tt = 1; 
	//cin >> tt;
	while(tt--){
	int a; cin >> a ;
      cout<< a + a * a  + a * a * a << endl;
	
	}
	return 0;
}


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

int main() {
  int n;
  string s;
  cin >> n >> s;
  int k = s.size();
  for(int i = 0;i < k;i++) {
    if('A' <= (char)(s[i] + n) && (char)(s[i] + n) <= 'Z') 
      cout << (char)(s[i] + n);
    else cout << (char)(s[i] + n - 26);
  }
}

Measured memory_bytes: 3600
S = input()
kami = int(S[:2])
simo = int(S[2:])
if(1 <= kami and kami<=12 and 1 <= simo and simo<=12):
    print("AMBIGUOUS")
elif(1<=kami and kami<=12):
    print("MMYY")
elif(1<=simo and simo<=12):
    print("YYMM")
else:
    print("NA")


Measured memory_bytes: 2940
#include <algorithm>
#include <cassert>
#include <iostream>
#include <map>
#include <vector>

static const int IINF = 1 << 30;
static const long long LINF = 1LL << 60;
static const long long MOD = 1.0e+9 + 7;

template <typename T> std::vector<T> vectors(std::size_t n, T val) {
  return std::vector<T>(n, val);
}

template <typename T, typename... Args>
auto vectors(std::size_t n, Args... args) {
  return std::vector<decltype(vectors<T>(args...))>(n, vectors<T>(args...));
}

template <class T> inline bool chmin(T &a, const T &b) {
  return (a > b) ? a = b, true : false;
}

template <class T> inline bool chmax(T &a, const T &b) {
  return (a < b) ? a = b, true : false;
}

template <class T> inline void chadd(T &a, const T &b) {
  a += b, a %= MOD;
  // TODO minus case
}

template <class T>
std::ostream &operator<<(std::ostream &s, const std::vector<T> &v) {
  if (v.empty())
    return s;
  s << *v.begin();
  for (auto iter = v.begin() + 1; iter != v.end(); ++iter)
    if (std::is_fundamental<T>::value)
      s << " " << *iter;
    else
      s << std::endl << *iter;
  return s;
}

int main() {
  // Input
  int N;
  std::cin >> N;
  std::vector<int> h(N);
  for (int i = 0; i < N; ++i)
    std::cin >> h[i];

  int res = 0;
  for (int j = 1; j <= 100; ++j) {
  // Record duration of "online" and "offline" interchangeably
    std::vector<int> duration;
    if (h[0] >= j)
      duration.push_back(0);
    for (int left = 0; left < N;) {
      int right = left;
      while (right < N and (h[left] >= j) == (h[right] >= j))
        ++right;
      duration.push_back(right - left);
      left = right;
    }
    if (h[N - 1] >= j)
      duration.push_back(0);

    assert(duration.size() % 2 == 1);
    res += duration.size() / 2;
  }

  // Output
  std::cout << res << std::endl;

  return 0;
}


Measured memory_bytes: 384
/**
 * Created by hiramekun at 22:15 on 2020-05-20.
 */
#include <bits/stdc++.h>

using namespace std;

using ll = long long;
using vl = vector<ll>;
using vvl = vector<vl>;
using vb = vector<bool>;
using P = pair<ll, ll>;
template<typename T> using pq = priority_queue<T>;
template<typename T> using minpq = priority_queue<T, vector<T>, greater<T>>;
template<typename T, typename K> using ump = unordered_map<T, K>;
const ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
const ll mod = 1000000007;
const ll inf = ll(1e9);
const ll e5 = ll(1e5);
const ll ll_inf = ll(1e9) * ll(1e9);

#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)
#define repr(i, n) for(ll i = ll(n - 1); i >= 0; i--)
#define each(i, mp) for(auto& i:mp)
#define eb emplace_back
#define F first
#define S second
#define all(obj) (obj).begin(), (obj).end()

template<class T>
ostream &operator<<(ostream &out, const vector<T> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << ' ';
    return out;
}

template<class T>
istream &operator>>(istream &in, vector<T> &list) {
    ll n = list.size();
    rep(i, n) in >> list[i];
    return in;
}

template<class T>
ostream &operator<<(ostream &out, const vector<vector<T>> &list) {
    ll n = list.size();
    rep(i, n) out << list[i] << '\n';
    return out;
}

/* ------------- ANSWER ------------- */
/* ---------------------------------- */

void solve() {
    ll h, n;
    cin >> h >> n;

    vl a(n), b(n);
    rep(i, n) {
        cin >> a[i] >> b[i];
    }
    vl dp(2 * 1e4 + 1, ll_inf); // dp[i]: 体力をi減らすため消耗する魔力の最小値
    dp[0] = 0;
    rep(i, 2 * 1e4 + 1) {
        rep(j, n) {
            if (i < a[j]) continue;
            dp[i] = min(dp[i], dp[i - a[j]] + b[j]);
        }
    }
    ll ans = ll_inf;
    for (ll r = h; r <= 2 * 1e4; ++r) {
        ans = min(ans, dp[r]);

    }
    cout << ans << '\n';
}

int main() {
#ifdef MY_DEBUG
    while (true) {
#endif
        solve();
#ifdef MY_DEBUG
    }
#endif
    return 0;
}

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

int selectionSort(int A[], int N){

	int count = 0;
	for (int i=0; i<N; i++){
		int minj = i;
		for (int j=i; j<N; j++){
			if (A[j] < A[minj]) minj = j;
		}
		swap(A[i], A[minj]);
		if (i != minj) count++;
	}

	for (int i=0; i<N; i++){
		if (i != N-1) cout << A[i] << " ";

		else cout << A[i] << endl;
	}
	cout << count << endl;
}

int main(){
	int A[100], N;

	cin >> N;

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

	selectionSort(A, N);

	return 0;
}

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

int main()
{
	int i, j, n, m, x, flag=0;
	string s, t;
	cin >> s >> t;

	n=s.length();
	m=t.length();

	for(i=n-1; i>=m-1; i-=1)
	{
		x=i;
		flag=1;
		for(j=m-1; j>=0; j-=1)
		{
			if(s[x]=='?' || s[x]==t[j])
			{
				x-=1;
				continue;
			}
			else
			{
				flag=0;
				break;
			}
		}
		if(flag==1)
			break;
	}
	if(flag==0)
		cout << "UNRESTORABLE" << endl;
	else
	{
		x+=1;
		for(j=0; j<n; j+=1)
		{
			if(j==x)
			{
				cout << t;
				j+=m-1;
			}
			else if(s[j]=='?')
				cout << 'a';
			else
				cout << s[j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 256
from bisect import bisect_left
n, m = map(int, input().split())
city_list = [[0] for _ in range(n + 1)]
city = [[]]
for _ in range(m):
    p, y = map(int, input().split())
    city_list[p].append(y)
    city.append([p, y])
for i in range(1, n + 1):
    city_list[i].sort()
for i in range(1, m + 1):
    ID = ''
    p = city[i][0]
    order = str(bisect_left(city_list[p], city[i][1]))
    #order = str(city_list[p].index(city[i][1]))
    p = str(p)
    ID = ID + ('0' * (6 - len(p)))
    ID += p
    ID += ('0' * (6 - len(order)))
    ID += order
    print(ID)

Measured memory_bytes: 32736
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define pb(x) push_back(x)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
#define pr(x) cerr<<#x<<"="<<(x)<<endl
#define pri(x,lo) {cerr<<#x<<"={";for (int ol=0;ol<=lo;ol++)cerr<<x[ol]<<",";cerr<<"}"<<endl;}
#define inf 100000000
#define N 1000
int a[N];
int main()
{
	scanf("%d %d %d",&a[1],&a[2],&a[3]);
	int o=a[1]&1,p=a[2]&1,q=a[3]&1;
	if (o==p&&p==q)
	{
		sort(a+1,a+1+3);
		printf("%d\n",(a[3]-a[1])/2+(a[3]-a[2])/2);
		return 0;
	}
	if (p==q) swap(o,q),swap(a[1],a[3]);
	if (o==q) swap(p,q),swap(a[2],a[3]);
	a[1]++;a[2]++;
	sort(a+1,a+1+3);
	printf("%d\n",1+(a[3]-a[1])/2+(a[3]-a[2])/2);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>

// #undef DEBUG  // Uncomment this line to forcefully disable debug print.
#if DEBUG
template <typename T>
void debug(T value) {
  std::cerr << value;
}
template <typename T, typename... Ts>
void debug(T value, Ts... args) {
  std::cerr << value << ", ";
  debug(args...);
}
#define DBG(...)                              \
  do {                                        \
    cerr << #__VA_ARGS__ << ": ";             \
    debug(__VA_ARGS__);                       \
    cerr << " (L" << __LINE__ << ")" << endl; \
  } while (0)
#else
#define DBG(...)
#endif

void read_from_cin() {}
template <typename T, typename... Ts>
void read_from_cin(T& value, Ts&... args) {
  std::cin >> value;
  read_from_cin(args...);
}
#define CIN(type, ...) \
  type __VA_ARGS__;    \
  read_from_cin(__VA_ARGS__);

template <typename T>
void write_to_cout(const T& value) {
  std::cout << value << std::endl;
}
template <typename T, typename... Ts>
void write_to_cout(const T& value, const Ts&... args) {
  std::cout << value << ' ';
  write_to_cout(args...);
}
#define COUT(...) write_to_cout(__VA_ARGS__);

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

using ll = long long;
using bigint = boost::multiprecision::cpp_int;

using namespace std;

int N;
bigint A[100000];
ll kMax = 1000000000000000000;

int main() {
  cin >> N;
  REP(i, N) {
    cin >> A[i];
    if (A[i] == 0) {
      cout << 0 << endl;
      return 0;
    }
  }
  bigint ans = 1;
  REP(i, N) {
    ans *= A[i];
    if (ans > kMax) {
      cout << -1 << endl;
      return 0;
    }
  }
  COUT(ans);
}


Measured memory_bytes: 6804
#include<stdio.h>
/*int main(){
  int q,a,b,r,n,m,p[10010]={0};
  scanf("%d %d",&n,&m);
  while(m--){
    scanf("%d %d %d",&q,&a,&b);
    for(r=++a;p[r];r=p[r]);
    for(;n=p[a];a=n)p[a]=r;
    for(r=++b;p[r];r=p[r]);
    for(;n=p[b];b=n)p[b]=r;
    if(q)printf("%d\n",a-b?0:1); 
    else if(a-b)p[a]=b;
  }
  return 0;
  }//*/
int main(){
  int n,m,a,b,q,p[10010]={0};
  int d[10010]={0};
  scanf("%*d %d",&n);
  while(n--){
    scanf("%d %d %d",&q,&a,&b);
    for(a++;p[a];a=p[a]);
    for(b++;p[b];b=p[b]);
    if(q)printf("%d\n",a-b?0:1);
    else if(a-b){
      d[a]<d[b]?(p[a]=b):(p[b]=a);
      if(d[a]==d[b])d[a]++;
    }
  }
  return 0;
}

Measured memory_bytes: 688
import java.io.*;
import java.util.*;

public class Main {
	public static void main(String[] args) {
		FastScanner fs = new FastScanner();
		String s = fs.next();
		String t = fs.next();
		if (t.substring(0, t.length() - 1).equals(s)) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}
	}
}

class FastScanner {
	private final InputStream in = System.in;
	private final byte[] buffer = new byte[1024];
	private int ptr = 0;
	private int buflen = 0;

	private boolean hasNextByte() {
		if (ptr < buflen) {
			return true;
		} else {
			ptr = 0;
			try {
				buflen = in.read(buffer);
			} catch (IOException e) {
				e.printStackTrace();
			}
			if (buflen <= 0) {
				return false;
			}
		}
		return true;
	}

	private int readByte() {
		if (hasNextByte())
			return buffer[ptr++];
		else
			return -1;
	}

	private static boolean isPrintableChar(int c) {
		return 33 <= c && c <= 126;
	}

	public boolean hasNext() {
		while (hasNextByte() && !isPrintableChar(buffer[ptr]))
			ptr++;
		return hasNextByte();
	}

	public String next() {
		if (!hasNext())
			throw new NoSuchElementException();
		StringBuilder sb = new StringBuilder();
		int b = readByte();
		while (isPrintableChar(b)) {
			sb.appendCodePoint(b);
			b = readByte();
		}
		return sb.toString();
	}

	public long nextLong() {
		if (!hasNext())
			throw new NoSuchElementException();
		long n = 0;
		boolean minus = false;
		int b = readByte();
		if (b == '-') {
			minus = true;
			b = readByte();
		}
		if (b < '0' || '9' < b) {
			throw new NumberFormatException();
		}
		while (true) {
			if ('0' <= b && b <= '9') {
				n *= 10;
				n += b - '0';
			} else if (b == -1 || !isPrintableChar(b)) {
				return minus ? -n : n;
			} else {
				throw new NumberFormatException();
			}
			b = readByte();
		}
	}

	public int nextInt() {
		long nl = nextLong();
		if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE)
			throw new NumberFormatException();
		return (int) nl;
	}

	public double nextDouble() {
		return Double.parseDouble(next());
	}
}

Measured memory_bytes: 32468
W,H,N = map(int,input().split())
w = W*[1]
h = H*[1]

for n in range(N):
  x,y,a = map(int,input().split())
  if a == 1:
    w[:x] = x*[0]
  elif a == 2:
    w[x:] = (W-x)*[0]
  elif a == 3:
    h[:y] = y*[0]
  else:
    h[y:] = (H-y)*[0]

print(w.count(1)*h.count(1))

Measured memory_bytes: 9080
#include <bits/stdc++.h>
typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LINF = 1e18;

using namespace std;

#define rep(i, a, b) for (int i = a; i < b; i++)
#define rrep(i, a, b) for (int i = a; i <= b; i++)
#define all(a)  begin((a)),end((a))
#define uniq(c) (c).erase(unique(all((c))), end((c)))

int main()
{
    long long N, A, B;
    cin >> N >> A >> B;

    long long num_base = N / (A+B);
    long long fraction = N - num_base * (A+B);
    long long ans = A * num_base + min(A, fraction);
    cout << ans << endl;
}

Measured memory_bytes: 256
/*
 * Author : Andrew J
*/
#include <bits/stdc++.h>
using namespace std;
void in(int &x);
#define fi first
#define se second
#define pb push_back
using ll = long long;
typedef pair <int , int> ii;
const int N = 105;
int n,a[N];

bool ok(vector <int> &v) {
   for (int i = 0 ; i < 3 ; i++) {
      for (int j = i + 1 ; j < 3 ; j++) {
         if (v[i] == v[j]) return 0;
      }
   }
   return 1;
}

int main() {
   in(n);
   for (int i = 1 ; i <= n ; i++) {
      in(a[i]);
   }
   int sol = 0;
   for (int i = 1 ; i <= n ; i++) {
      for (int j = i + 1 ; j <= n ; j++) {
         for (int k = j + 1 ; k <= n ; k++) {
            vector <int> cur;
            cur.pb(a[i]); cur.pb(a[j]); cur.pb(a[k]);
            sort(cur.begin() , cur.end());
            if (!ok(cur)) continue;
            if (cur[0] + cur[1] > cur[2]) {
               sol++;
            }
         }
      }
   }
   printf("%d\n" , sol);
   return 0;
}

void in(int &x){
	bool neg = false;
	register int c;
	x = 0;
	c = getchar();
	if(c == '-'){
		neg = true;
		c = getchar();
	}
	for (; c > 47 && c < 58; c = getchar())
	x = (x << 1) + (x << 3) + c - 48;
	if (neg) x *= -1;
}


Measured memory_bytes: 3720
#include<iostream>
#include<algorithm>
#include<math.h>
#include<vector>

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

using namespace std;
using ll = long long;
using ull = unsigned long long;
using P = pair<int, int>;

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

    vector<int> a;
    rep(i, N) {
       int s; cin >> s;
       a.push_back(s);
    }

    sort(a.begin(), a.end());
    
    int res = 0;
    rep(i, N) {
        if (x < a[i]) break;
        x -= a[i];
        res++;
    }

    if ((res == N) && (x > 0)) res--;
    cout << res << endl;
    return 0;
}


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

#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()

typedef long long ll;

const ll MOD=1000000007ll;
const int MAX=5100000;

using namespace std;

int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    for(int i=0;i<a;i++){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    for(int i=0;i<a;i++){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

ll fact[MAX], fact_inv[MAX];

ll power(ll a, ll b){
	ll res=1;
	while(b>0){
		if(b&1) res=res*a%MOD;
		a=a*a%MOD;
		b>>=1;
	}
	return res;
}

// nCr
ll comb(ll n, ll r){
	ll t=1000000;
	fact[0]=1;
	    for(int i=0;i<t;i++){ fact[i+1]=fact[i]*(i+1)%MOD;}
	fact_inv[t]=power(fact[t], MOD-2);
	for(int i=0;i<t;i++){ fact_inv[i]=fact_inv[i+1]*(i+1)%MOD;}
	return (fact[n]*fact_inv[r])%MOD*fact_inv[n-r]%MOD;
}

int i,j,k,tmp;
ll ans = 0;

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

  int N; cin >> N;
  int D[N*2]; rep(i,N*2){cin >> D[i];}
  for(int i=0;i<N*2;i+=2){
	  if(D[i]==D[i+1] && D[i+2]==D[i+3] && D[i+4]==D[i+5]){
		  cout << "Yes" << endl; return 0;
	  }
  }
	cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3652
#include <iostream>
#include <iomanip>
#include <utility>
#include <cmath>
#include <random>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <string>
#include <algorithm>
using namespace std;

#define rep(i,n) for(int i = 0; i<n; ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
typedef long long ll;

int main(){
    string b; cin >> b;
    if(b == "A")cout << "T" << endl;
    if(b == "T")cout << "A" << endl;
    if(b == "G")cout << "C" << endl;
    if(b == "C")cout << "G" << endl; return 0;
}

Measured memory_bytes: 256
from heapq import heappush, heappop

def dijkstra(s):
    '''
    始点sから各頂点への最短距離を求める
    '''
    d = [float("inf")] * n
    d[s] = 0
    used = [False] * n
    used[s] = True
    edgelist = []

    for e in edge[s]:
        heappush(edgelist, e)

    while edgelist:
        cost, v = heappop(edgelist)
        if used[v]:
            continue
        d[v] = cost
        used[v] = True
        for e in edge[v]:
            if not used[e[1]]:
                heappush(edgelist, [e[0] + d[v], e[1]])

    return d


n = int(input())

edge = [[] for _ in range(n)]
for _ in range(n-1):
    a, b, c = map(int, input().split())
    edge[a-1].append([c, b-1])
    edge[b-1].append([c, a-1])

q, k = map(int, input().split())

dist = dijkstra(k-1)

res = [0] * q
for i in range(q):
    x, y = map(int, input().split())
    res[i] = dist[x-1] + dist[y-1]

for v in res:
    print(v)

Measured memory_bytes: 122416
#include <iostream>
#include <limits>
#include <vector>

using namespace std;

int main(int argc, char* argv[])
{
  int N; cin >> N;

  vector<int> A(N);

  bool isZero = false;
  int num_minus = 0;
  int min_abs = numeric_limits<int>::max();
  unsigned long max_total = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    if (A[i] == 0) {
      isZero = true;
    } else if (A[i] < 0) {
      num_minus++;
    }
    min_abs = min(min_abs, abs(A[i]));
    max_total += abs(A[i]);
  }

  if (!isZero && (num_minus%2 == 1)) {
    max_total -= 2*min_abs;
  }

  cout << max_total << endl;
  return 0;
}


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

using namespace std;

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

  int N;
  cin>>N;
  vector<vector<int>> table(N, vector<int>(N-1));
  for (int i = 0; i < N; i++) {
    for (int j = 0; j < N-1; j++) {
      int t; cin>>t;
      t--;
      table[i][j] = t;
    }
  }
  vector<int> is(N, 0);
  set<int> cands;
  auto check = [&](int x) {
    if (is[x] < N-1) {
      int io = table[x][is[x]];
      if (is[io] < N-1 and table[io][is[io]] == x) {
        cands.insert(x);
        cands.insert(io);
      }
    }
  };
  for (int i = 0; i < N; i++) {
    check(i);
  }
  int d = 0;
  while (not cands.empty()) {
    vector<bool> played(N, false);
    vector<int> ncands;
    for (auto i : cands) {
      if (is[i] == N-1)
        continue;
      int o = table[i][is[i]];
      if (not played[i] and not played[o]) {
        played[i] = played[o] = true;
        ++is[i];
        ++is[o];
        ncands.push_back(i);
        ncands.push_back(o);
      }
    }
    cands.clear();
    for (auto c : ncands)
      check(c);
    d++;
  }
  bool suc = true;
  for (int i = 0; i < N; i++) {
    suc &= is[i] == N-1;
  }
  cout << (suc ? d : -1) << endl;

  return 0;
}


Measured memory_bytes: 4224
import math
a,b,h,m = map(int,input().split())
hour = 30*h+0.5*m
minutes = m*6

Long = max(hour,minutes)
short = min(hour,minutes)

ans = (a**
2+b**2-2*a*b*math.cos(math.radians(Long-short)))**0.5
print(ans)

Measured memory_bytes: 9452
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <valarray>
#include <vector>
using namespace std;

using ll = long long;
using ld = long double;
const int INF = 1e9;
const double EPS = 1e9;
const ll MOD = 1e9 + 7;

int main()
{
  double a;
  scanf("%lf", &a);
  double b;
  scanf("%lf", &b);
  double x;
  scanf("%lf", &x);
  if (2 * x >= a * a * b)
    printf("%.10lf\n", 180.0 / M_PI * atan2(2.0 * (a * a * b - x), a * a * a));
  else
    printf("%.10lf\n", 180.0 / M_PI * atan2(a * b * b, 2.0 * x));

  return 0;
}


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

#define reps(v, f, l) for (int v = (f), v##_ = (l); v < v##_; ++v)
#define rep(v, n) reps(v, 0, n)
#define lep(v, n) reps(v, 1, n + 1)

using namespace std;

typedef long long int lint;

static inline int in(){ int x; scanf("%d", &x); return x; }
static inline lint inl(){ lint x; scanf("%lld", &x); return x; }
template<typename T> void show(T& a, char del='\n', char last='\n'){ rep(i, a.size() - 1) cout << a[i] << del; cout << a[a.size() - 1] << last; }

int main()
{
  rep(i, in()){
    int x, y, b, p;
    x = in();
    y = in();
    b = in();
    p = in();
    printf("%d\n", min(x * b + y * p, (int)((x * max(b, 5) + y * max(p, 2)) * 0.8)));
  }
  return 0;
}

Measured memory_bytes: 1188
import java.util.*;
import static java.lang.System.*;
import java.io.*;
import java.math.*;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner();
		PrintWriter out = new PrintWriter(System.out);
		int n = sc.nextInt();
		int m = n - 1;
		long ans = 0;
		for(int i = 1; i <= m / 2; i++) {
			ans += n;
		}
		if(m % 2 == 1)
			ans += n/2;
		out.println(ans);
		
		out.close();
	}

static class FastScanner {
    private final InputStream in = System.in;
    private final byte[] buffer = new byte[1024];
    private int ptr = 0;
    private int buflen = 0;
    private boolean hasNextByte() {
        if (ptr < buflen) {
            return true;
        }else{
            ptr = 0;
            try {
                buflen = in.read(buffer);
            } catch (IOException e) {
                e.printStackTrace();
            }
            if (buflen <= 0) {
                return false;
            }
        }
        return true;
    }
    private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
    private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
    public boolean hasNext() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++; return hasNextByte();}
    public String next() {
        if (!hasNext()) throw new NoSuchElementException();
        StringBuilder sb = new StringBuilder();
        int b = readByte();
        while(isPrintableChar(b)) {
            sb.appendCodePoint(b);
            b = readByte();
        }
        return sb.toString();
    }
    public long nextLong() {
        if (!hasNext()) throw new NoSuchElementException();
        long n = 0;
        boolean minus = false;
        int b = readByte();
        if (b == '-') {
            minus = true;
            b = readByte();
        }
        if (b < '0' || '9' < b) {
            throw new NumberFormatException();
        }
        while(true){
            if ('0' <= b && b <= '9') {
                n *= 10;
                n += b - '0';
            }else if(b == -1 || !isPrintableChar(b)){
                return minus ? -n : n;
            }else{
                throw new NumberFormatException();
            }
            b = readByte();
        }
    }
    public int nextInt() {
        long nl = nextLong();
        if (nl < Integer.MIN_VALUE || nl > Integer.MAX_VALUE) throw new NumberFormatException();
        return (int) nl;
    }
    public double nextDouble() { return Double.parseDouble(next());}
}
}


Measured memory_bytes: 21460
//g++ t.cpp -o t && t < p.txt
//d>p.txt&&t<p.txt&&t2<p.txt

#include <iostream> // プログラムの耳と口
#include <vector> // 超有能配列秘書
#include <algorithm> // みんな大好きソートと二分探索
#include <queue> // きゅーちゃん、だいすき
#include <string> // to_string
#include <functional> // 関数を変数に入れる子
#include <set> // 値の取得・挿入・削除を高速に
#include <map> // setの妹 これまた優秀
#include <random> // 乱択さん
#include <ctime>
#include <bitset>

#define DB cerr<<"D"<<endl
using namespace std; using ll=long long; using ld=long double; const int INF=1e9; const ll LINF=1e18; const double dINF = 1e18; const ld ldINF = 1e18; const double EPS = 1e-6;
template<typename T, typename U, typename O> void caut(T a, U b, O c){cout<<"("<<a<<","<<b<<","<<c<<") ";} template<typename T, typename U> void caut(T a, U b){cout<<"("<<a<<","<<b<<") ";} template<typename T> void caut(T a){cout<<"("<<a<<") ";};
using P=pair<ll,ll>;
const ll M = 1e9+7;
ll mod_pow(ll x, ll a) { ll an = 1; while(a > 0) { if (a&1) an = an * x % M; x = x * x % M; a >>= 1;} return an;}
void add(ll& x, ll y) {x+=y; x%=M;}; void mul(ll& x, ll y) {x*=y; x%=M;}; template<typename T, typename U> void chmax(T& x, U y) {if (x<y) x=y;}; template<typename T, typename U> void chmin(T& x, U y) {if (x>y) x=y;}
bool vaild(int x, int y, int hh, int ww){return 0<=x&&x<hh&&0<=y&&y<ww;}
int keta(ll a) {int res=0; while(a>0) res+=a%10, a/=10; return res;}
const int up[]={1,-1,0,0}, lf[]={0,0,1,-1};

int main() {
  int n,x,t; cin>>n>>x>>t;
  cout<<(n/x+(n%x>0))*t<<endl;
}
// ・配列の大きさok？　・priority_queueはgreater？　・debug消した？
// ・落ち着いて。提出まで4分待ってね……WJ……1/10……2/10……

// Thank you for making problems and running the contest


Measured memory_bytes: 3620