akhauriyash/Code-Regression huggingface dataset:
#include <stdio.h>

int main() {
  int width, point_a, point_b;
  scanf("%d %d %d", &width, &point_a, &point_b);
  if(point_a > point_b) {
    int temp = point_a;
    point_a = point_b;
    point_b = temp;
  }
  if(point_a + width >= point_b) {
    printf("0\n");
  } else {
    printf("%d\n", point_b - width - point_a);
  }
  return 0;
}


Measured memory_bytes: 128
D = int(input())
c = list(map(int, input().split()))
s = [list(map(int, input().split())) for _ in range(D)]
last = [-1]*26
ans = 0
for d in range(D):
    t = int(input())-1
    last[t] = d
    for i in range(26):
        ans -= (d-last[i])*c[i]
    ans += s[d][t]
    print(ans)

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

int main(){
  int n;
  cin >> n;
  vector<int> l(n);
  for(int i=0; i<n; ++i) cin >> l[i];
  sort(l.begin(),l.end());
  int ans = 0;
  for(int i=0; i<n; ++i) for(int j=i+1; j<n; ++j){
    auto it = lower_bound(l.begin(),l.end(),l[i]+l[j]);
    ans += (it - l.begin()) -j -1;
  }
  cout << ans << endl;
}

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

#define ll long long 
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define all(x) (x).begin(),(x).end()
#define f(i, a, b) for (int i=a; i<(signed)(b); ++i)
#define pc __builtin_popcount // counts number of 1's in bin(num)
#define pb push_back
#define mp make_pair

// debug templates 
#define debug(x)       cerr<< #x <<" : "<< x << endl;
#define debuga(A,N)    cerr<< #A <<" : [";for(int i = 0; i<N;i++) cerr<<A[i]<<" "; cerr<<"]\n";
#define debuga2(A,N,M) cerr<< #A << " : \n"; for(int i=0;i<N;i++){cerr<<"[";for(int j=0;j<M;++j) cerr<<A[i][j]<<" ";cerr<<"]\n";}
#define debugp(p)      cerr<< #p <<" : "<<"("<<(p).first<<","<<(p).second<<")\n";
#define debugv(v)      cerr<< #v <<" : "<<"[";for(int i = 0; i< (v).size(); i++) cerr<<v[i]<<" "; cerr<<"]\n";
#define debugv2(v)     cerr<< #v << " : \n"; for(int i=0;i<v.size();i++){cerr<<"[";for(int j=0;j<(v[0].size());++j) cerr<<v[i][j]<<" ";cerr<<"]\n";}
#define debugs(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin(); itr!=m.end();itr++) cerr<<*itr<<" "; cerr<<"]\n";
#define debugm(m)      cerr<< #m <<" : [ "; for(auto itr = m.begin();itr!=m.end(); itr++) cerr<<"("<<itr->first<<","<<itr->second<<") ";cerr<<"]\n";

void solve(){
	ll x; cin >> x;
	ll cur = 100;
	ll ans = 0;
	while(cur < x){
		++ans;
		cur += cur*0.01;
	} 
	cout << ans;
}

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
	
	solve();
}








Measured memory_bytes: 3652
#include <iostream>

int main()
{
	int x, y;
	while (std::cin >> x >> y, x || y)
	{
		if (x <= y)
		{
			std::cout << x << " " << y << '\n';
		}
		else
		{
			std::cout << y << " " << x << '\n';
		}
	}
	return 0;
}

Measured memory_bytes: 2980
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;

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

    vector<int> ajiAry(N);
    for (int i = 0; i < N; ++i) {
        ajiAry[i] = L + i;
    }

    // 0 に最も近い値を調べる
    int min = ajiAry[0];
    for (int i = 0; i < N; ++i) {
        int aji = ajiAry[i];

        if (abs(aji) < abs(min)) {
            min = aji;
        }
    }

    int sum = accumulate(ajiAry.begin(), ajiAry.end(), 0);
    cout << sum - min << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;
const ll mod=1000000007;
#define doublecout(a) cout<<fixed<<setprecision(10)<<a<<endl;

ll dis[100000];
vector<vector<pair<ll,ll> > > g(100000);
void dijkstra(ll start){
	for(int i=0;i<100000;i++)dis[i]=1e18;
	dis[start]=0;
    multiset<pair<ll,ll> > ms;
    ms.insert(make_pair(0,start));
    pair<ll,ll> p,niko;
    ll maki;
    while(!ms.empty()){
        p=*(ms.begin());
        ms.erase(ms.begin());
        if(dis[p.second]<p.first)continue;
        maki=g[p.second].size();
        for(int i=0;i<maki;i++){
            niko=g[p.second][i];
            if(dis[niko.first]>dis[p.second]+niko.second){
                dis[niko.first]=dis[p.second]+niko.second;
                ms.insert(make_pair(dis[niko.first],niko.first));
            }
        }
    }
    return;
}

int main() {
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);
    int n,m,s,a,b,c;
    cin>>n>>m>>s;
    for(int i=0;i<m;i++){
    	cin>>a>>b>>c;
    	g[a].pb(make_pair(b,c));
    }
    dijkstra(s);
    for(int i=0;i<n;i++){
    	if(dis[i]==1e18)cout << "INF"<<endl;
    	else cout <<dis[i]<<endl;
    }
    return 0;
}



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

int main(){
	while(1){
		int a, b, c; cin >> a >> b >> c;
		if(a == 0 && b == 0 && c == 0) return 0;
		int n; cin >> n;
		set<int> st;
		vector<int> x(n), y(n), z(n), jud(n);
		rep(i,n){
			int s, t, u, v; cin >> s >> t >> u >> v;
			x[i] = s; y[i] = t; z[i] = u; jud[i] = v;
			if(v == 1){
				st.insert(s);
				st.insert(t);
				st.insert(u);
			}
		}

		set<int> stx;
		rep(i,n){
			if(jud[i] == 0){
				int cnt = 0;
				if(st.count(x[i])) cnt++;
				if(st.count(y[i])) cnt++;
				if(st.count(z[i])) cnt++;
				if(cnt == 2){
					if(!st.count(x[i])) stx.insert(x[i]);
					if(!st.count(y[i])) stx.insert(y[i]);
					if(!st.count(z[i])) stx.insert(z[i]);
				}
			}
		}

		rep(i,a+b+c){
			if(st.count(i+1)) cout << 1 << endl;
			else if(stx.count(i+1)) cout << 0 << endl;
			else cout << 2 << endl;
		}
	
	}
}


Measured memory_bytes: 3024
'use strict'

const main = input => {
	const args = input.split('\n').map(arg => arg.split(' '))
	const N = parseInt(args[0][0], 10)
	const K = parseInt(args[0][1], 10)
	const h = args[1].map(arg => parseInt(arg, 10))
	let cnt = 0

	for (let i = 0; i < N; i++) {
		if (h[i] >= K) cnt++
	}

	console.log(cnt)
}

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

Measured memory_bytes: 16576
#include <bits/stdc++.h>
#include <bits/extc++.h>
using namespace __gnu_pbds;
using namespace std;
#define testing 1
#define FOR(ii, ss, ee) for(ll ii = (ss); ii <= (ll)(ee); ++ii)
#define DEC(ii, ss, ee) for(ll ii = (ss); ii >= (ll)(ee); --ii)
#define IAMSPEED ios_base::sync_with_stdio(false); cin.tie(0);
#define db(x) cerr << #x << "=" << x << endl
#define db2(x, y) cerr << #x << "=" << x << " , " << #y << "=" << y << endl
#define db3(a,b,c) cerr<<#a<<"="<<a<<","<<#b<<"="<<b<<","<<#c<<"="<<c<<endl
#define dbv(v) cerr << #v << ":"; for (auto it : v) cerr << it << ' '; cerr << endl
#define dbvp(v) cerr << #v << ":"; for (auto it : v) cerr << "{"  << it.f << ',' << it.s << "} "; cerr << endl
#define dba(a,ss,ee) cerr << #a << ":"; FOR(i,ss,ee) cerr << a[i] << ' '; cerr << endl
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long 
#define pb push_back
#define inf (int)1e9+500
#define oo (ll)1e18+500
#define all(x) (x).begin(), (x).end()
#define f first
#define s second
#define reach cerr << "LINE: " << __LINE__ << "\n";
typedef pair <int, int> pi;
typedef pair <ll,ll> pl;
typedef pair <pi, int> pii;
typedef tuple<int,int,int> ti3;
string cts(char x) {string t(1,x); return t;}
ll rand(ll a, ll b) { return a + rng() % (b-a+1); }
const int MOD = 1e9 + 7;
template <typename T> void chmax(T& a, T b) {
	a = max(a, b);
}
template <typename T> void chmin(T& a, T b) {
	a = min(a, b);
}
#define MAXN
#if !testing
#define cerr if(0)cout
#endif

int32_t main() {
	IAMSPEED
	string str; cin >> str;
	if(str=="hi"||str=="hihi"||str=="hihihi"||str=="hihihihi"||str=="hihihihihi")cout<<"Yes";
	else cout << "No";
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
using namespace std;
int main(){
  int n, m;
  cin >> n;
  if(n % 2 == 1){
    m = (n + 1) / 2;
    cout << m << "\n";
    return 0;
  }
  m = n / 2;
  cout << m << "\n";
}

Measured memory_bytes: 3488
#include <algorithm>
#include <cctype>
#include <cstring>
#include <cstdio>
using namespace std;
typedef long long int64;
inline int read(int f = 1, int x = 0, char ch = ' ')
{
    while(!isdigit(ch = getchar())) if(ch == '-') f = -1;
    while(isdigit(ch)) x = x*10+ch-'0', ch = getchar();
    return f*x;
} 
const int N = 2e5+5;
const int64 INF = 0x3f3f3f3f3f3f3f3f;
int n, t, e, px[N];
int64 f[N], w = INF;
int main()
{
    n = read(), e = read(), t = read();
    for(int i = 1; i <= n; ++i) px[i] = read();
    for(int i = 1, j = 0; i <= n; ++i)
    {
        while(2*(px[i]-px[j+1]) >= t) w = min(f[j]-2*px[j+1], w), ++j;
        f[i] = min(w+2*px[i], f[j]+t);
    }
    printf("%lld\n", f[n]+e);
    return 0;
}

Measured memory_bytes: 1280
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(...) out(__VA_ARGS__);cout<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void out(){} template<class T,class... U> void out(T t,U ...u){cout<<t<<" ";out(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(int, N, M);
  VEC(ll, A, N);
  vector<pll> p(M);
  rep(i, 0, M) {
    in(p[i].second, p[i].first);
  }
  sort(all(p), greater<>());
  sort(all(A));
  int ii = 0;
  rep(i, 0, M) {
    while (A[ii] < p[i].first && p[i].second && ii < N) {
      A[ii] = p[i].first;
      p[i].second--;
      ii++;
    }
  }
  print(accumulate(all(A), 0ll));
}


Measured memory_bytes: 2560
{-# LANGUAGE ScopedTypeVariables #-}
import Control.Applicative
import Control.Monad
import Control.Monad.State
import Control.DeepSeq
import Data.Array
import Data.Bits
import Data.Char
import Data.Functor.Identity
import Data.List
import Data.Ord
import Data.Maybe
import Data.Tree
import Data.Tuple
import qualified System.IO
import qualified Data.Map as M
import qualified Data.Set as S
import qualified Data.Sequence as Q
import qualified Data.ByteString.Char8 as B

main = do
  n <- getInt
  ls <- getInts
  let ms = sort ls
      ans = sum [ms !! (2*i) | i <- [0..n-1]]
  print ans

 
type Z = Int
type Q = Rational
type R = Double
type S = String

fint :: (Integral a, Num b) => a -> b
fint = fromIntegral

getInt = fst . fromJust . B.readInt <$> B.getLine
getIntPair = (\[a,b]->(a,b)) <$> getInts
getInts = map (fst . fromJust . B.readInt) . B.words <$> B.getLine
getStr = B.unpack <$> B.getLine

yesNo :: Bool -> String
yesNo True = "YES"
yesNo False = "NO"


-----  Union-find
type UnionFindT v m a = StateT (M.Map v (UnionFindVal v)) m a
newtype UnionFindVal v = UnionFindVal v

runUnionFindT :: (Monad m) => UnionFindT v m a -> m a
runUnionFindT = flip evalStateT $ M.empty

runUnionFind = runIdentity . runUnionFindT

ufFresh :: (Monad m, Ord v) => v -> UnionFindT v m ()
ufFresh v = modify $ M.insert v (UnionFindVal v)

ufClass :: (Monad m, Ord v) => v -> UnionFindT v m v
ufClass v = do
  (UnionFindVal pv) <- gets (M.! v)
  if v == pv
    then return v
    else do
      c <- ufClass pv
      modify $ M.insert v (UnionFindVal c)
      return c

ufUnify v w = do
  cv <- ufClass v
  cw <- ufClass w
  modify $ M.insert cw (UnionFindVal cv)
  return $ cv /= cw


Measured memory_bytes: 636
n = int(input())
a = list(map(int,input().split()))
b = set(a)
x = {str(i):0 for i in b}
for i in a:
    x[str(i)] += 1
ans = 0
for i,j in x.items():
    if j < int(i):
        ans += j
    else:
        ans += j - int(i)
print(ans)

Measured memory_bytes: 28660
package main

import "fmt"

var m = map[string]int{
	"SSS": 0,
	"SSR": 1,
	"SRS": 1,
	"RSS": 1,
	"SRR": 2,
	"RSR": 1,
	"RRS": 2,
	"RRR": 3,
}

func main() {
	var s string
	fmt.Scan(&s)
	fmt.Println(m[s])
}

Measured memory_bytes: 1836
n, k = map(int, input().split())

import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

for i in range(1, k+1):
#     print(n-k+1, i)
    if n-k+1 >= i:
        print((combinations_count(n-k+1, i)*combinations_count(k-1, i-1))%(1000000007))
    else:
        print(0)

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

int main() {
    ll n, k, ans1 = 0, ans2 = 0;
    cin >> n >> k;

    REP(i, 1, n+1) {
        if (i % k == 0) ans2++;
        else if (2 * i % k == 0) ans1++;
    }
    ans1 = pow(ans1, 3);
    ans2 = pow(ans2, 3);
    cout << ans1 + ans2 << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#pragma GCC optimize("O3")

#define fi first
#define se second
#define ep emplace
#define eb emplace_back
#define mp make_pair
#define pi pair<int,int>
#define vi vector<int>
#define vpi vector<pair<int,int>>
#define vll vector<ll>
#define vpll vector<pair<ll,ll>>
#define endl '\n'

#define si(v) int((v).size())
#define all(v) (v).begin(), (v).end()
#define rep(i, n) for (ll i = 0; i < (ll)(n); ++i) 
#define rep2(i, n, m) for (ll i = n; i <= (ll)(m); ++i)
#define rep3(i, n, m) for (ll i = n; i >= (ll)(m); --i)

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

constexpr ll MOD = 1000000007, MAX = 100001;

struct UnionFind {
  vi parent, siz;

  UnionFind(int n) : parent(n), siz(n) {
    rep(i, n) {
      parent[i] = i;
      siz[i] = 1;
    }
  }

  int root(int x)
  {
    if (parent[x] == x) return x;
    return parent[x] = root(parent[x]);
  }

  bool unite(int x, int y)
  {
    x = root(x);
    y = root(y);

    if (x == y) return false;

    if (siz[x] < siz[y]) swap(x, y);
    parent[y] = x;
    siz[x] += siz[y];

    return true;
  }

  bool same(int x, int y)
  {
    return root(x) == root(y);
  }

  int size(int x)
  {
    return siz[x];
  }
};


signed main()
{
  cout << fixed << setprecision(20);
  ios::sync_with_stdio(false);
  cin.tie(0);

  int n, m; cin >> n >> m;
  UnionFind uf(n + m);

  rep(i, n) {
    int k; cin >> k;
    
    rep(j, k) {
      int l; cin >> l;
      uf.unite(i, l+n-1);
    }
  }

  int r = uf.root(0);
  rep(i, n) {
    if (r != uf.root(i)) {
      cout << "NO" << endl;
      return (0);
    }
  }
  
  cout << "YES" << endl;

  return (0);
}


Measured memory_bytes: 6208
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define pint pair<int, int>
#define plint pair<ll, ll>
#define ALL(x) (x).begin(), (x).end()
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i,n) for (int i = 0; i < (n); ++i)
const int INF = 100100100;
const int MOD = (int)1e9 + 7;
const double EPS = 1e-9;
int main(){
    int n;
    cin >> n;
    vector<int > a(n);
    REP(i,n) cin >> a[i];
    bool is_ok = true;
    REP(i,n){
        // even?        
        if(a[i]%2==0){
            if(a[i]%3==0 || a[i]%5==0){
                is_ok = true;
            }else{
                is_ok = false;
            }
        }
        if(is_ok==false){
            cout << "DENIED" << endl;
            return 0;
        }
    }
    cout << "APPROVED" << endl;
    return 0;
}

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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int row, col, k;
  char grid[10][10];
  cin >> row >> col >> k;
  for(int i = 0; i < row; ++i) {
    for(int j = 0; j < col; ++j) {
      cin >> grid[i][j];
    }
  }  
  int ans = 0;
  for(int maskr = 0; maskr < (1 << row); maskr++) {
    for(int maskc = 0; maskc < (1 << col); maskc++) {
      set<int> ret, cet;
      for(int bit = 0; bit < row; ++bit) {
        if(maskr & (1 << bit)) {
          ret.insert(bit);
        }
      }
      for(int bit = 0; bit < col; ++bit) {
        if(maskc & (1 << bit)) {
          cet.insert(bit);
        }
      }
      int foo = 0;
      for(int i = 0; i < row; ++i) {
        for(int j = 0; j < col; ++j) {
          if(ret.find(i)==ret.end() && cet.find(j)==cet.end() && grid[i][j]=='#') {
            ++foo;
          }
        }
      }
      if(foo == k) {
        ans++;
      }
    }
  }
  cout << ans << '\n';
  return 0;
}


Measured memory_bytes: 3628
#include<iostream>
#include<cmath>
#include<stdio.h>
using namespace std;

struct rec{
	double x,y;
};

int main(){
	
	int n;
	struct rec dot[21]={0};
	double ans=0,a,b,c,z;
	
	for(int i=0;i<20;i++){
		if(scanf("%lf,%lf",&dot[i].x,&dot[i].y)==EOF){
			n=i;
			break;
		}
	}
	
	for(int i=0;i<n-2;i++){
		a=sqrt(pow(dot[0].x-dot[i+1].x,2)+pow(dot[0].y-dot[i+1].y,2));
		b=sqrt(pow(dot[i+1].x-dot[i+2].x,2)+pow(dot[i+1].y-dot[i+2].y,2));
		c=sqrt(pow(dot[i+2].x-dot[0].x,2)+pow(dot[i+2].y-dot[0].y,2));
		
		z=(a+b+c)/2;
		
		ans=ans+sqrt(z*(z-a)*(z-b)*(z-c));
	}
	
	printf("%.6lf\n",ans);
	
	return 0;
}

Measured memory_bytes: 1240
package main
import f "fmt"
func main(){
    var (
        a int
        b int
        )
    f.Scan(&a, &b)
    if a == b {
        f.Println("a == b")
    }else if a < b {
        f.Println("a < b")
    }else{
        f.Println("a > b")
    }
}



Measured memory_bytes: 1128
n, k=map(int, input().split())
a=[0]+list(map(int, input().split()))

t=[1]

for i in range(2*n):
    nxt=a[t[-1]]
    t.append(nxt)

if k<n+1:
    print(t[k])
    exit()

loop_end=n
loop_start=n-1

while t[loop_start]!=t[loop_end]:
    loop_start-=1

cycle=loop_end-loop_start
k%=cycle

while k<n+1:
    k+=cycle

print(t[k])

Measured memory_bytes: 114504
from collections import deque

def shortestpath(y0, x0):
    step_cnt = [[-1] * (w+2) for _ in range(h+2)]
    step_cnt[y0][x0] = 0
    q.append((y0, x0))
    while q:
        y, x = q.popleft()
        for i in range(4):
            y_next = y + dy[i]
            x_next = x + dx[i]
            if 1 <= y_next < h+1 and 1 <= x_next < w+1\
            and maze[y_next][x_next] == '.'\
            and step_cnt[y_next][x_next] == -1:
                q.append((y_next, x_next))
                step_cnt[y_next][x_next] = step_cnt[y][x] + 1

    return step_cnt[y][x]

h, w = map(int, input().split())
maze = [['#'] * (w+2)]
maze += [['#']+[x for x in input()]+['#'] for _ in range(h)]
maze += [['#'] * (w+2)]
dy = [-1, 0, 1, 0]
dx = [0, -1, 0, 1]
q = deque()

max_steps = -1
for y0 in range(1, h+1):
    for x0 in range(1, w+1):
        if maze[y0][x0] != '#':
            max_steps = max(max_steps, shortestpath(y0, x0))

print(max_steps)

Measured memory_bytes: 3444
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 99999999999999999
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;


#define NUM 1005

struct Info{
	double v_x,v_y;
};

int N;
Info info[NUM];
double X,Y;
double g;

double calc_height(double v_y,double t){

	return v_y*t-g*t*t/2.0;
}

void func(){

	for(int i = 0; i < N; i++){
		scanf("%lf %lf",&info[i].v_x,&info[i].v_y);
	}
	scanf("%lf %lf",&X,&Y);

	double minimum = (double)BIG_NUM;

	for(int i = 0; i < N; i++){
		minimum = min(minimum,calc_height(info[i].v_y,X/info[i].v_x));
	}

	if(minimum > Y+EPS){
		printf("No\n");
		return;
	}

	double left = -BIG_NUM,right = BIG_NUM,mid = (left+right)/2;
	double tmp_x,tmp_y,tmp_t;

	for(int i = 0; i < 100; i++){

		tmp_x = 0;
		tmp_y = 0;

		for(int k = 0; k < N; k++){
			tmp_t = (info[k].v_y-mid*info[k].v_x)/g;
			if(tmp_t < 0)continue;

			tmp_x += info[k].v_x*tmp_t;
			tmp_y += calc_height(info[k].v_y,tmp_t);
		}

		if(tmp_x+EPS < X){

			right = mid-EPS;

		}else{

			left = mid+EPS;

		}
		mid = (left+right)/2.0;
	}

	if(tmp_y >= Y){

		printf("Yes\n");

	}else{

		printf("No\n");
	}
}

int main(){

	g = 9.8;

	while(true){
		scanf("%d",&N);
		if(N == 0)break;

		func();
	}

	return 0;
}



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

bitset<10000001> pr;
vector<int> primes;
int count=0;
void sieve()
{
    //cout<<pr[0];
    for(int i=2;i*i<10000001;i++)
    {
        if(pr[i])continue;
        for(int j=i*2;j<1000001;j+=i)
        {
            pr[j]=i;
        }
    }
    for(int i=2;i<=1000001;i++)
    {
        if(!pr[i])primes.push_back(i);
    }
}
vector<int> tl;
void primeFctorization(int n)
{
    set<int> th;
    vector<int> ans;
    int N=n;
    n=abs(n);
    for(int i=0;i<primes.size()&&primes[i]*primes[i]<=n;i++)
    {
        while(n%primes[i]==0)
        {
            th.insert(primes[i]);
            n/=primes[i];
            ans.push_back(primes[i]);
            //cout<<primes[i]<< " ";
        }
    }
    if(n>1){
        th.insert(n);
        //cout<<n;;
        ans.push_back(n);
    }
    if(th.size()>=3)
    {
        tl.push_back(N);
        ::count++;
        //cout<<N<<endl;
    }
}
int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    int b,n;
    cin>>b>>n;
    int c=b+n;
    b=max(b,n);
    b=b*2-1;

    cout<<max(b,c);
}


Measured memory_bytes: 256
N = gets.to_i
hash = Hash.new(0)
1.upto(100) do |x|
    1.upto(100) do |y|
        1.upto(100) do |z|
            hash[x**2 + y**2 + z**2 + x*y + y*z + z*x] += 1
        end
    end
end
1.upto(N) do |n|
    puts hash[n]
end

Measured memory_bytes: 16668
S = list(input())
if S[0] != 'A':
    print('WA')
    exit()
if len([s for s in S[2:-1] if s == 'C']) != 1:
    print('WA')
    exit()
SL = [s for s in S if s not in ['A', 'C']]
if not all([sl.islower() for sl in SL]) or len(SL) + 2 != len(S):
    print('WA')
    exit()
print('AC')

Measured memory_bytes: 3064
#include <math.h>

#include <algorithm>
#include <cstring>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <string>
#include <vector>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
using ll = long long;
using P = pair<int, int>;

int main() {
  int d, t, s;
  cin >> d >> t >> s;

  cout << (d - t * s <= 0 ? "Yes" : "No");

  return 0;
}


Measured memory_bytes: 3632
#include<bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
#define ALLG(v) v.begin(), v.end() ,greater<int>()
typedef long long ll;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
ll GCD(ll x, ll y) { return y ? GCD(y, x % y) : x; }
ll LCM(ll x, ll y) { return x * y / GCD(x, y); }
ll GetDigit(ll num) {
	ll digit = 0;
	while (num != 0) {
		num /= 10;
		digit++;
	}
	return digit;
}

using namespace std;
int main() {

	int x = 0;
	cin >> x;

	int z = x / 100;
	if (z * 100 <= x &&  x <= z * 105) {
		cout << 1 << endl;
	}
	else {
		cout << 0 << endl;

	}
}

Measured memory_bytes: 256
from bisect import bisect_right, bisect_left
from itertools import groupby, permutations, combinations
from fractions import gcd
import numpy as np
from sys import stdin, stderr


def lcm(x, y):
    return (x * y) // gcd(x, y)


def main():
    H, N = [int(x) for x in input().split()]
    A = [int(x) for x in input().split()]
    A.sort()
    for i in range(N):
        H -= A[N - i - 1]
    ret = "Yes" if H <= 0 else "No"
    return ret


if __name__ == "__main__":
    print(main())

Measured memory_bytes: 23564
#include<bits/stdc++.h>
#define ll long long
#define N 510
#define INF 1000000000000000000ll
using namespace std;
ll ans=INF,dp[N][N],a[N][N],n,g[N][N],f[N][N];
ll co1(int l,int r,int x){return f[x][r]-f[x][l-1];}
ll co2(int x,int l,int r){return g[x][r]-g[x][l-1];}
int main(){
	cin>>n;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)if (i!=j)cin>>a[i][j];
	for (int i=0;i<=n;i++)
		for (int j=i;j<=n+1;j++)dp[i][j]=INF;
	for (int i=1;i<=n;i++)
		for (int j=1;j<=n;j++)
			g[i][j]=g[i][j-1]+a[i][j],f[i][j]=f[i][j-1]+a[j][i];
	dp[0][0]=0;
	for (int i=1;i<=n;i++)
		for (int j=1;j<i;j++)dp[0][0]+=a[i][j];
	for (int i=0;i<n;i++){
		for (int j=i;j<=n;j++){
			ll su=0;
			for (int k=j+1;k<=n+1;k++){
				su=su+co1(j,k-2,k-1)-co2(k-1,i,k-2);
				dp[j][k]=min(dp[j][k],dp[i][j]+su);
				if (k==n+1)ans=min(ans,dp[j][k]);
			}
		}
	}
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 8320
#include<bits/stdc++.h>
#define FOR0(i,n) for(int i=0;i<n;i++)
#define FOR1(i,n) for(ll i=1;i<=n;i++)
#define FORl(i,l,n) for(ll i=l;i<n;i++)
using namespace std;
#define pi pair<int, int>
#define pb push_back
#define ll long long
#define ld long double	
#define ff first
#define ss second
#define mp make_pair
#define mst0(x) memset(x,0,sizeof(x));
#define vi vector<ll>
#define sync ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl '\n'
#define sp <<" "<<
#define intmax 1e18
ll power(ll num, ll g, ll mod) {
	if (g == 0)return 1;
	if (g % 2 == 1)return (num * power((num * num) % mod, g / 2, mod)) % mod;
	return power( (num * num) % mod, g / 2, mod);
}

int main(){
	ll n;
	cin >> n;
	ll a[n];
	FOR0(i, n) cin >> a[i];
	vi tmp;
	for (int i = 0; i < n; i+=2){
		tmp.pb(a[i]^a[i + 1]);
	}
	ll xor_all = 0;
	for (auto x : tmp){
		xor_all ^= x;
	}
	FOR0(i, n){
		a[i] ^= xor_all;
	}
	FOR0(i, n) cout << a[i] << " ";


}	

Measured memory_bytes: 5844
#include <algorithm>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>

int main(int argc, char const* argv[]) {
    std::string a, b, c;
    std::cin >> a >> b >> c;
    std::cout << a.at(0) << b.at(0) << c.at(0) << '\n';
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>

int main(){
int H,W,i,j;
while(1){
scanf("%d %d",&H,&W);
if(H==0&&W==0) break;
for(i=0;i<H;i++){
   for(j=0;j<W;j++){
      printf("#");
   }
   printf("\n");
}
printf("\n");
}
return 0;
}

Measured memory_bytes: 572
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <numeric>
#include <list>
#include <assert.h>
#include <math.h>
#include <valarray>
#include <stdio.h>
#include <algorithm>
#include <set>
#include <complex>
#include <list>

using namespace std;
typedef long long int LL;
typedef pair<long long int, long long int> pii;
typedef pair<double, double> pdd;

#define SORT(c) sort((c).begin(),(c).end())
#define BACKSORT(c) sort((c).begin(),(c).end(),std::greater<LL>())
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)





int main()
{
	int N;
	cin >> N;
	
	int sum = 0;
	vector<int> a;
	int i = 0;
	while (true)
	{
		i++;
		sum += i;
		a.push_back(i);
		if (sum >= N) {
			if (sum > N) {
				a[sum - N - 1] = -1;
			}
			break;
		}
	}
	REP(j, a.size()) {
		if (a[j] != -1) {
			cout << a[j] << endl;
		}
	}
}

Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

func main() {
	scanInit()

	n := nextInt()
	d := nextInt()
	x := nextInt()
	al := make([]int, n)

	for i := 0; i < n; i++ {
		al[i] = nextInt()
	}

	choco := x

	for i := 1; i <= d; i++ {
		if i == 1 {
			choco += n
			continue
		}
		for j := 0; j < n; j++ {
			// 該当日だったら食べる (al[j]*N+1==i)
			if (i-1)%al[j] == 0 {
				choco++
			}
		}
	}

	fmt.Println(choco)

}

// ---- readfunc
func scanInit() {
	const cap = 64 * 1024
	var buf = make([]byte, cap)
	sc.Buffer(buf, cap)
	sc.Split(bufio.ScanWords)
	return
}
func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}
func nextStr() string {
	sc.Scan()
	return sc.Text()
}


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

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

	int n,t;
	vector <int> v,v2;

	cin >> n;

	for(int i=0;i<n;i++)
	{
		cin >> t;
		v.push_back(t);
		v2.push_back(t);
	}

	sort(v2.rbegin(),v2.rend());

	for(int i=0;i<n;i++)
	{
		if(v2[0]==v[i])
		{
			cout << v2[1] << '\n';
		}
		else{
			cout << v2[0] << '\n';
		}
	}
	
	return 0;
}



Measured memory_bytes: 3436
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
using pll = pair<ll, ll>;
#define rep(i, n) for(ll i = 0; i < n; i++)
#define rrep(i, m, n) for(ll i = m; i > n; i--)
#define Rep(i, m, n) for(ll i = m; i < n; i++)
#define all(vec) vec.begin(), vec.end()
#define lmax(x, y) max<ll>(x, y)
#define lmin(x, y) min<ll>(x, y)
#define tmax(x, y, z) lmax((x), lmax((y), (z)))
#define tmin(x, y, z) lmin((x), lmin((y), (z)))
#define MINUS(a) memset(a, 0xff, sizeof(a))
#define ZERO(a) memset(a, 0, sizeof(a))
const ll INF = 1LL << 60;
const ll MM = 1000000000; const ll MOD = MM + 7; const ll MMM=9223372036854775807;//2^63 -1
#define ADD(a,b) a = (a + ll(b)) % MOD
#define MUL(a,b) a = (a * ll(b)) % MOD
ll GCD(ll x, ll y){ if(y == 0) return x; else return GCD(y, x % y);}
ll LCM(ll x, ll y){ return x / GCD(x, y) * y;}
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;}
template<typename A, size_t N, typename T> void FILL(A (&array)[N], const T &val){ fill( (T*)array, (T*)(array+N), val );}
// struct edge{ ll from, to, cost; };
// struct edge{ ll to, cost; };
// using Graph = vector<vector<ll>>;  // 重み無し
// using Graph = vector<edge>;  // 辺
// using Graph = vector<vector<edge>>;  // 重み付き
ll dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};
ll ddx[8] = {1, 1, 0, -1, -1, -1, 0, 1}, ddy[8] = {0, 1, 1, 1, 0, -1, -1, -1};
//cout << fixed << setprecision(10);
// priority_queue<ll, vector<ll>, greater<ll>> pq;


int main(){
    string s, t;
    cin >> s >> t;
    ll ans = INF;
    rep(i, s.size()-t.size()+1){
        ll cnt = 0;
        rep(j, t.size()){
            if(t[j] != s[i+j]) cnt++;
        }
        chmin(ans, cnt);
    }
    cout << ans << endl;
}


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

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

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

  vector<vector<char>> grid(h, vector<char>(w));
  rep(i,h)rep(j,w) cin >> grid.at(i).at(j);

  vector<vector<int>> dp(h, vector<int>(w,300));
  if(grid.at(0).at(0)=='.') dp.at(0).at(0) = 0;
  else  dp.at(0).at(0) = 1;

  rep(i,h){
    rep(j,w){
      if(j+1<w){
        if(grid.at(i).at(j+1)==grid.at(i).at(j)) dp.at(i).at(j+1) = min(dp.at(i).at(j), dp.at(i).at(j+1));
        else dp.at(i).at(j+1) = min(dp.at(i).at(j)+1, dp.at(i).at(j+1));
      }

      if(i+1<h){
        if(grid.at(i+1).at(j)==grid.at(i).at(j)) dp.at(i+1).at(j) = min(dp.at(i).at(j), dp.at(i+1).at(j));
        else dp.at(i+1).at(j) = min(dp.at(i).at(j)+1, dp.at(i+1).at(j));
      }
    }
  }
  // rep(i,h){
  //   rep(j,w){
  //     cout << dp.at(i).at(j);
  //   }cout << endl;
  // }
  int c = dp.at(h-1).at(w-1);
  cout << (c+1)/2;
}

Measured memory_bytes: 3680
#include <bits/stdc++.h>
#define DAU  ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define PLEC return 0;
using namespace std;
int n;
int64_t k, res, v[200002];
int main() {
    DAU
    cin >> k >> n >> v[0];
	for (int i = 1; i < n; ++i) {
		cin >> v[i];
		res = max(res, v[i] - v[i-1]);
	}
	res = max(res, k - v[n-1] + v[0]);
	cout << k - res;
    PLEC
}


Measured memory_bytes: 1792
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <stdio.h>
#include <string>

using namespace std;

void solve(string S) {
  int yyyy = stoi(S.substr(0, 4));
  int mm = stoi(S.substr(5, 2));
  int dd = stoi(S.substr(8, 2));
  if (yyyy < 2019) {
    cout << "Heisei" << endl;
  } else if (mm < 5) {
    cout << "Heisei" << endl;
  } else {
    cout << "TBD" << endl;
  }
}

int main() {
  string S;
  cin >> S;
  solve(S);
  return 0;
}

Measured memory_bytes: 888
#include<iostream>

using namespace std;

int main()
{
	int n,h,w;
	cin >> n>> h>>w;
	int c=0;
	for(int i=1;i<=n;i++)
	{
		int a,b;
		cin >> a >> b;
		if(a>=h and b>=w)
			c++;
	}
	cout << c << endl;
}

Measured memory_bytes: 256
def f(c):
    for a1 in range(101):
        for a2 in range(101):
            for a3 in range(101):
                b1 = c[0][0] - a1
                b2 = c[0][1] - a1
                b3 = c[0][2] - a1
                if b1 == c[1][0] - a2 and b1 == c[2][0] - a3 and \
                   b2 == c[1][1] - a2 and b2 == c[2][1] - a3 and \
                   b3 == c[1][2] - a2 and b3 == c[2][2] - a3:
                    return True
    return False
                
c = [map(int, raw_input().split()) for _ in range(3)]
if f(c): print 'Yes'
else: print 'No'


Measured memory_bytes: 2692
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		int N, M, ans=0;
		int Food[][];
		Scanner scan = new Scanner(System.in);
		
		N = scan.nextInt();
		M = scan.nextInt();
		Food = new int[N+1][M];
		
		for(int i=0; i<M;i++) {
			Food[N][i] = 1;
		}
		
		int A, K;
		for(int i=0; i<N; i++) {
			K = scan.nextInt();
			for(int j=0; j<K; j++) {
				A = scan.nextInt();
				Food[i][A-1] = 1;
			}
		}
		for(int i=0; i<M; i++) {
			for(int j=0; j<N; j++) {
				Food[N][i] *= Food[j][i];
			}
		}
		for(int i=0; i<M; i++) {
			ans += Food[N][i];
		}
		System.out.print(ans);
	}

}


Measured memory_bytes: 23764
#include <iostream>
#include <algorithm>
#include <string.h>
#include <stdlib.h>
#include <math.h>

using namespace std;

int main() {
	long a, b, c;
	cin >> a >> b >> c;
	if (a % 2 == 0 || b % 2 == 0 || c % 2 == 0) {
		cout << 0 << endl;
	}
	else {
		long ab = a * b;
		long bc = b * c;
		long ca = c * a;
		cout << min(min(ab, bc), ca) << endl;
	}
	return 0;
}

Measured memory_bytes: 256
require 'pp'

# 空白区切の入力値を数値の配列で返却する
def gets_i_list()
  gets.chomp.split(" ").map(&:to_i)
end

ABC = gets_i_list.sort

appeared = []
count = 0
c_abc = ABC
while true
  if appeared.include?(c_abc)
    puts -1
    exit
  end
  c_abc.each do |e|
    if e.odd?
      puts count
      exit
    end
  end
  count += 1
  appeared.push(c_abc)
  c_abc = [
    c_abc[0]/2 + c_abc[1]/2,
    c_abc[1]/2 + c_abc[2]/2,
    c_abc[0]/2 + c_abc[2]/2,
  ].sort
end


Measured memory_bytes: 4092
#include<iostream>
#include<cstdio>
#include<cstdlib>
#include<cmath>
using namespace std;
int n,m;
char w[150][150];
bool f[150][150];
char c;
int main()
{
    cin>>n>>m;
    for (int i=0; i<n; ++i)
        for (int j=0; j<m; ++j)
        {
            scanf("%c",&c);
            while (c=='\n') scanf("%c",&c);
            w[i][j]=c;
        }
    for (int i=0; i<n; ++i)
    {
        bool ff=0;
        for (int j=0; j<m; ++j)
            if (w[i][j]=='#')
                ff=1;
        if (ff==0)
        for (int j=0; j<m; ++j)
            f[i][j]=1;
    }
    for (int j=0; j<m; ++j)
    {
        bool ff=0;
        for (int i=0; i<n; ++i)
            if (w[i][j]=='#')
                ff=1;
        if (ff==0)
            for (int i=0; i<n; ++i)
                f[i][j]=1;
    }
    for (int i=0; i<n; ++i)
    {
        bool ff=0;
        for (int j=0; j<m; ++j)
            if (f[i][j]==0)
            {
                ff=1;
                cout<<w[i][j];
            }
        if (ff)
        cout<<endl;

    }


    
    return 0;
}


Measured memory_bytes: 256
A = int(input())
B = int(input())
C = int(input())
X = int(input())
print([0 <= X - 500*a - 100*b and (X - 500*a - 100*b) %
       50 == 0 and (X - 500*a - 100*b) // 50 <= C for a in range(A+1) for b in range(B+1)].count(True))


Measured memory_bytes: 3060
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
#include<cmath>
#include<math.h>
using namespace std;

long long min(long long a,long long b){
  if(a>b)return b;
  else return a;
}

int main(){
  long long l,r;
  std::cin >> l>>r;
  long long ans=r*r;
  if(r-l>=2019)std::cout << 0 << '\n';
  else{
    for (long long i = l; i < r; i++) {
      for (long long j = i+1; j <= r; j++) {
        ans=min(ans,(i*j)%2019);
      }
      if(ans==0)break;
    }
    std::cout << ans << '\n';
  }


  return 0;
}


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <string>
#include <unordered_map>
#include <math.h>
#include <algorithm>
#include <deque>
#include <climits>
using namespace std;
#define rep(i,l,r) for(int i=l;i<r;i++)
#define repb(i,r,l) for(int i=r;i>l;i--)
#define ll long long
#define ull unsigned long long
#define ve vector
#define umap unordered_map
#define iter iterator


void solve() {
    int w,a,b;
    cin>>w>>a>>b;
    int x, y;
    if(a >= b && a <= b+w) cout<< 0;
    else if(b >= a && b <= a+w) cout<< 0;
    else cout<< min(abs(b-(w+a)),abs(a-(w+b))) <<endl;
}

int main() {
    solve();
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <iostream>
#include <iomanip>
#include <cstring>
#include <string>
#include <vector>
#include <queue>
#include <cmath>
#include <stack>
#include <set>
#include <map>
typedef long long ll;
using namespace std;

int main(){
  int N;
  ll C;
  cin >> N >> C;
  ll x[N], v[N];
  for(int i = 0; i < N; i++) cin >> x[i] >> v[i];

  //移動を考慮しない累積和
  ll sl[N + 1];
  ll sr[N + 1];
  sl[0] = 0;
  for(int i = 0; i < N; i++) sl[i + 1] = sl[i] + v[N - 1 - i];
  sr[0] = 0;
  for(int i = 0; i < N; i++) sr[i + 1] = sr[i] + v[i];

  //左右にiだけ進むとき食べられる最大の栄養価(移動考慮)
  ll gl[N + 1];
  ll gr[N + 1];
  gr[0] = 0;
  for(int i = 1; i <= N; i++) gr[i] = max(gr[i - 1], sr[i] - x[i - 1]);
  gl[0] = 0;
  for(int i = 1; i <= N; i++) gl[i] = max(gl[i - 1], sl[i] - (C - x[N - i]));

  ll ans = gr[N];
  for(int b = 1; b <= N; b++){
    ll tmp = sl[b] - 2 * (C - x[N - b]) + gr[N - b];
    //cout << "b = " << b << " " << "tmp = " << tmp << endl;
    ans = max(ans, tmp);
  }

  ans = max(ans, gl[N]);
  for(int a = 1; a <= N; a++){
    ll tmp = sr[a] - 2 * x[a - 1] + gl[N - a];
    //cout << "a = " << a << " " << "tmp = " << tmp << endl;
    ans = max(ans, tmp);
  }

  //degug
  /*cout << "s" << endl;
  for(int i = 0; i <= N; i++) cout << sl[i] << " ";
  cout << endl;
  for(int i = 0; i <= N; i++) cout << sr[i] << " ";
  cout << endl;
  cout << "g" << endl;
  for(int i = 0; i <= N; i++) cout << gl[i] << " ";
  cout << endl;
  for(int i = 0; i <= N; i++) cout << gr[i] << " ";
  cout << endl;
  */

  cout << ans << endl;
  return 0;

}

Measured memory_bytes: 4992
using System;
using System.Collections.Generic;
using System.Linq;
using static Constans;

public static class Constans
{
    public const long Mod = (long)1e9 + 7;
}

public struct ModInt
{
    public long Num;

    public ModInt(long num)
    {
        Num = num;
    }

    // x^n
    public static long Power(long x, long n)
    {
        long pow = 1;
        while (n > 0)
        {
            if (n % 2 == 0)
            {
                x *= x;
                x %= Mod;
                n /= 2;
            }
            else
            {
                pow *= x;
                pow %= Mod;
                n--;
            }
        }

        return pow;
    }

    public static ModInt GetInv(long f)
    {
        // フェルマーの小定理 a^(-1) = a^(mod-2)
        return new ModInt(Power(f, Mod - 2));
    }

    public ModInt GetInv()
    {
        return GetInv(Num);
    }

    public override string ToString()
    {
        return Num.ToString();
    }

    public static ModInt operator +(ModInt l, ModInt r)
    {
        l.Num += r.Num;
        if (l.Num >= Mod)
        {
            l.Num -= Mod;
        }
        return l;
    }

    public static ModInt operator -(ModInt l, ModInt r)
    {
        l.Num -= r.Num;
        if (l.Num < 0)
        {
            l.Num += Mod;
        }
        return l;
    }

    public static ModInt operator *(ModInt l, ModInt r)
    {
        return new ModInt(l.Num * r.Num % Mod);
    }

    public static implicit operator ModInt(long n)
    {
        n %= Mod;
        if (n < 0)
        {
            n += Mod;
        }
        return new ModInt(n);
    }
}

public class Solution
{
    public static void Main()
    {
        var vals = Console.ReadLine().Split(' ').Select(long.Parse).ToArray();
        var N = vals[0];
        var K = vals[1];
        var A = Console.ReadLine().Split(' ').Select(int.Parse).ToArray();

        ModInt count = 0;
        for (int i = 0; i < N; i++)
        {
            var all = 0;
            var right = 0;
            var a = A[i];
            for (int j = 0; j < i; j++)
            {
                if (a > A[j])
                {
                    all++;
                }
            }
            for (int j = i + 1; j < N; j++)
            {
                if (a > A[j])
                {
                    all++;
                    right++;
                }
            }

            count += right * K;
            count += (ModInt)(K * (K - 1) / 2) * all;
        }

        Console.WriteLine(count);
    }
}

Measured memory_bytes: 13432
/*
    Created by Tejas Chaudhari
    link:
*/

#include <bits/stdc++.h>

using namespace std;

typedef long long int ll;
typedef double lf;
typedef bool bl;
typedef vector<ll> vl;
typedef vector<lf> vd;
typedef vector<bl> vb;
typedef string st;
typedef pair<ll,ll> pll;
typedef vector<pll> vpll;

#define INF (LONG_LONG_MAX / 4)
#define SORT(x) sort(x.begin(), x.end())
#define Mod % 1000000007

void re_curse() {
    ll n;
    cin>>n;
    vl arr(n);
    for (int i = 0; i < n; ++i) {
        cin>>arr[i];
    }
    SORT(arr);
    ll c = 1;
    ll ans = arr[n-1];
    int i = n-2;
    while (c < n-1) {
        ++c;
        ans += arr[i];
        if (c < n-1) {
            ++c;
            ans += arr[i];
            --i;
        }
    }
    cout<<ans<<endl;
}

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int t = 1;
    // cin>>t;
    for (int i = 1; i <= t; ++i) {
        re_curse();
    }
    return 0;
}


Measured memory_bytes: 4772
#include<bits/stdc++.h>
#include<stdio.h>
using namespace std;
#define ll  long long
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pii pair<int,int>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

#define ordered_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>

ll dp[401][401];
ll ma=1e15;
ll mod(ll a){
if(a>=0)
    return a;
else return -a;
}


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

int n;
cin>>n;
ll a[n];
for(int i=0;i<n;i++)
    cin>>a[i];
ll l[n+1];
l[0]=0;
for(int i=0;i<n;i++)
    l[i+1]=l[i]+a[i];

 for(int i=1;i<=n-1;i++)
        dp[i][i+1]=l[i+1]-l[i-1];
 for(int i=3;i<=n;i++){
    for(int j=1;j<=n+1-i;j++){
        ll p=j,q=i+j-1;
        dp[p][q]=ma;
        ll x=l[q]-l[p-1];
        for(int k=p;k<q;k++){
            dp[p][q]=min(dp[p][q],x+dp[p][k]+dp[k+1][q]);
        }
    }
 }


cout<<dp[1][n]<<endl;

}


Measured memory_bytes: 1536
///   ***   ---   |||		 In the name of ALLAH		|||   ---   ***   ///



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


typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef double dl;

#define endl '\n'
#define PB push_back
#define F first
#define S second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define sz(x) (int)x.size()

const double PI = acos(-1);
const double eps = 1e-9;
const int inf = 2000000000;
const ll infLL = 9000000000000000000;
#define MOD 1000000007

#define mem(a,b) memset(a, b, sizeof(a) )
#define sqr(a) ((a) * (a))

#define optimize() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define fraction() cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);
#define file() freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
//
//debug
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<<"{";for(auto 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<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<",";os<<*it;}return os<<"]";}
template<typename T>ostream&operator<<(ostream&os,const multiset<T>&v) {os<<"[";for(auto 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<<"[";for(auto it=v.begin();it!=v.end();++it){if(it!=v.begin())os<<", ";os<<it->first<<" = "<<it->second;}return os<<"]";}
#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu(){cerr << endl;}
template<typename T>void faltu(T a[],int n){for(int i=0;i<n;++i)cerr<<a[i]<<' ';cerr<<endl;}
template<typename T,typename...hello>void faltu(T arg,const hello&...rest){cerr<<arg<<' ';faltu(rest...);}
//#else
//#define dbg(args...)
 
ll gcd ( ll a, ll b ) { return __gcd ( a, b ); }
ll lcm ( ll a, ll b ) { return a * ( b / gcd ( a, b ) ); }


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

int main()
{
	optimize();

    string s;
    cin >> s;

    int cnt = 0, ans = 0;
    for ( int i = 0; i < 3; i++ ) {
        if ( s[i] == 'R' ) cnt++;
        else {
            ans = max ( ans,cnt );
            cnt = 0;
        }
    }

    ans = max ( ans, cnt );
    cout << ans << endl;


	return 0;
}


















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

int main() {
	int n,m,sum=0,i,count=0;
	cin>>n>>m;
	int arr[n];
	for(i=0;i<n;i++){
		cin>>arr[i];
		sum+=arr[i];
	}
	if(sum%(4*m)==0){
		sum/=(4*m);
	}else{
		sum=sum/(4*m)+1;
	}
	for(i=0;i<n;i++){
		if(arr[i]>=sum){
			count++;
		}
	}
	if(count>=m){
		cout<<"Yes";
	}else{
		cout<<"No";
	}
	
	return 0;
}

Measured memory_bytes: 256
/*
ID: iCoder0020
PROG: Knapsack 1
LANG: C++                  
*/

#include <bits/stdc++.h>

using namespace std;

#define int long long

#define w(n) info[n].first
#define v(n) info[n].second

int32_t main()
{
	int N,W;
	cin>>N>>W;
	int a,b;
	vector<int>base(W+1, 0);
	vector<vector<int>>dp(N+1, base);
	pair<int, int> info[N];
	for(int n = 1; n<=N; n++)
		cin>>w(n)>>v(n);

	for(int i = 1; i<=N; i++)
	{
		for(int j = 0; j<=W; j++)
		{
			if(w(i) <= j)
			{
				dp[i][j] = max(dp[i-1][j-w(i)] + v(i), dp[i-1][j]);
			}
			else
			{
				dp[i][j] = dp[i-1][j];
			}
		}
	}
	cout<<dp[N][W]<<endl;
	return 0;	
}

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

using namespace std;

typedef long long ll;

int main(){
ll N,Q; cin >> N >> Q;
  vector<pair<ll,pair<ll,ll> >> event_sort;
  for(ll i = 0 ; i < N; i++){
    ll s,t,x; cin >> s >> t >> x;
    event_sort.push_back(make_pair(s-x,make_pair(-1,x)));
    event_sort.push_back(make_pair(t-x,make_pair(0,x)));}
  
    for(ll j = 0; j < Q; j++){
      ll d; cin >> d;
      event_sort.push_back(make_pair(d,make_pair(1,j)));}
    
    sort(event_sort.begin(),event_sort.end());
    
    multiset<ll> mp;
    
    vector<ll> answer(Q,0);
    
    for(ll i = 0; i < (2*N + Q); i++){
      ll p,q,r;
      p = event_sort[i].first;
      q = event_sort[i].second.first;
      r = event_sort[i].second.second;
      if( q == -1){ 
        mp.insert(r);}
      else if( q == 0){
        mp.erase(mp.lower_bound(r));}
      else{
        if( mp.empty()){ answer[r] = -1;}
        else{
        answer[r] = *(mp.begin());}} }
    
    for(ll i = 0; i < Q; i++){
      cout << answer[i] <<endl; }
    return 0;}
        
      


Measured memory_bytes: 26600
from collections import deque
def F(m):
	q=deque([m])
	d=[-1]*n
	while q:
		cur=q.popleft()
		for nxt in G[cur]:
			if d[nxt]<0:
				q.append(nxt)
				d[nxt]=d[cur]+1
	return d
def solve():
	global n,G
	n,*L=map(int,open(0).read().split())
	G=[[]for _ in range(n)]
	for a,b in zip(*[iter(L)]*2):
		G[a-1]+=[b-1]
		G[b-1]+=[a-1]
	print("FSennunkeec"[sum(i>j or-1 for i,j in zip(F(0),F(n-1)))>=0::2])
if __name__=="__main__":solve()

Measured memory_bytes: 37236