akhauriyash/Code-Regression huggingface dataset:
{-# LANGUAGE TypeApplications #-}
{-# LANGUAGE LambdaCase, DeriveFunctor #-}

import           Control.Applicative
import           Control.Arrow
import           Control.Monad
import           Data.Bits
import           Data.Char
import           Data.List
import           Data.Maybe
import           Data.Ord
import           Control.Monad.Fix
import qualified Data.Set                      as S



twice f x = f x x

both :: Arrow a => a b c -> a (b, b) (c, c)
both = twice (***)

readsLn :: Read a => IO [a]
readsLn = mapM readIO . words =<< getLine


main = do
  n <- readLn @Int
  a <- map (\[a, b] -> a == b) <$> replicateM n (readsLn @Int)
  putStrLn $ if f a then "Yes" else "No"
 where
  f [_, _] = False
  f (a : b : c : xs) | a && b && c = True
                     | otherwise   = f (b : c : xs)


Measured memory_bytes: 4788
#include <bits/stdc++.h>
using namespace std;
int c[10000][2]={},N,W;
int main()
{
    cin>>N>>W;
    pair<int,int> I[N];
    for(int u=0;u!=N;++u)
        cin>>I[u].first>>I[u].second;
    for(int u=0;u!=N;++u)
    {
        for(int q=0;q<=W;++q)
        {
            if(q-I[u].second<0)
                continue;
            if(c[q-I[u].second][0]+I[u].first>c[q][0])
                c[q][1]=c[q-I[u].second][0]+I[u].first;
            else
                c[q][1]=c[q][0];
        }
        for(int q=0;q<=W;++q)
            c[q][0]=c[q][1];
//        cout<<"L0:";
//        for(int q=0;q<=W;++q)
//            cout<<c[q][0]<<' ';
//        cout<<"\nL1:";
//        for(int q=0;q<=W;++q)
//            cout<<c[q][1]<<' ';
//        cout<<'\n';
    }
    cout<<c[W][0]<<'\n';
    return 0;
}

Measured memory_bytes: 3160
def mapt(fn, *args):
    return tuple(map(fn, *args))
    
n, m = mapt(int, input().split(" "))
nums = [mapt(int, input().split(" ")) for i in range(n)]
b = [int(input()) for i in range(m)]

for row in nums:
    print(sum(i*j for i, j in zip(b,row)))


Measured memory_bytes: 6004
#include <bits/stdc++.h>
#define int long long
using namespace std;

signed main() {
string S;
cin >> S;

int N = (int)S.size();
int ans = 0;

for( int i = 1;  i < N-ans; i++ ){
if( S.at(i) != S.at(i-1) ){
ans += 2;
S.erase(i-1, 2);
if( i >= 2 ) i -= 2;
else i--;
}
}

cout << ans << endl;
    
}



Measured memory_bytes: 512
#include <iostream>
using namespace std;
typedef long long ll;

int h[100005]={0};
int main(){
  int n;
  cin>>n;
  for(int i=1;i<=n;i++){
    int a;
    cin>>a;
    h[a]++;
  }
  if(n%2==0){
    ll ans=1;
    for(int i=1;i<=n/2;i++){
      if(h[2*i-1]!=2){
        cout<<0<<endl;
        return 0;
      }
      ans*=2;
      ans%=1000000007;
    }
    cout<<ans<<endl;
  }
  else{
    ll ans=1;
    if(h[0]!=1){
      cout<<0<<endl;
      return 0;
    }
    for(int i=1;i<=n/2;i++){
      if(h[2*i]!=2){
        cout<<0<<endl;
        return 0;
      }
      ans*=2;
      ans%=1000000007;
    }
    cout<<ans<<endl;
  }
return 0;
}

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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)

// START for segment tree
#define params int p, int L, int R
#define housekeep int mid = (L + R) >> 1, left = p << 1, right = left | 1
// END

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

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

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

//#ifdef LOCAL_MACHINE
//#endif

const int MAXN = 1e5 + 5;

struct myds {
    multiset<ll> myset;
    ll lazy = 0;

    inline void inc(int x) {
        lazy += x;
    }

    void add(ll x) {
        myset.insert(x - lazy);
    }

    void rem(ll x) {
        myset.erase(myset.find(x - lazy));
    }

    ll get_max() {
        return *prev(myset.end()) + lazy;
    }

    ll get_min() {
        return *myset.begin() + lazy;
    }
} one, two;
int l[MAXN], r[MAXN], len[MAXN];

int main() {
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    int n;
    scanf("%d", &n);
    for (int i = 1; i <= n; i++) {
        scanf("%d %d", &l[i], &r[i]);
        len[i] = r[i] - l[i];
    }
    ll ans = 0;
    one.add(r[1]);
    two.add(r[1]);
    //puts("OK");
    for (int i = 2; i <= n; i++) {
        one.inc(-len[i - 1]);
        two.inc(len[i]);
        ll opt_l = one.get_max();
        ll opt_r = two.get_min();
        //printf("for i = %d opt_l = %lld and opt_r = %lld\n", i, opt_l, opt_r);
        if (opt_l <= ( ll )r[i] && ( ll )r[i] <= opt_r) {
            one.add(r[i]);
            two.add(r[i]);
        } else if (( ll )r[i] < opt_l) {
            one.add(r[i]);
            one.add(r[i]);
            one.rem(opt_l);
            two.add(opt_l);
            ans += abs(opt_l - r[i]);
        } else {
            two.add(r[i]);
            two.add(r[i]);
            two.rem(opt_r);
            one.add(opt_r);
            ans += abs(opt_r - r[i]);
        }
    }
    printf("%lld\n", ans);
    return 0;
}



Measured memory_bytes: 10880
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <cmath>
using namespace std;
const int N=200010;
int v[N];
inline int gi() {
    int x=0,o=1;
    char ch=getchar();
    while(ch!='-'&&(ch<'0'||ch>'9')) ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
int main() {
    int n;
    long long ans=0;
    cin>>n;
    for(int i=1;i<=n;i++) v[i]=gi()-i;
    sort(v+1,v+1+n);
    for(int i=1,j=v[(n+1)/2];i<=n;i++) ans+=abs(v[i]-j);
    cout<<ans;
    return 0;
}

Measured memory_bytes: 1024
#include<cstdio>
	int main()
{
	int a[3];
	int z,c;
	z=0,c=0;
	for(int i=0;i<3;i++){
		scanf("%d",&a[i]);
	}
	for(int k=0;k<3;k++){
	if(a[k]==5){	
		z++;
	}
	if(a[k]==7){
		c++;
	}}
	if(z==2||c==1){
	printf("YES\n");
	}
	else
	{
	printf("NO\n");
	}
	}	

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

int main() {
  while(true){
    int r,n;
    cin >> r >> n;
    if(r==0 && n==0) break;
    int bill[40]={0};
    rep(i,n){
      int xl,xr,h;
      cin >> xl >> xr >> h;
      repi(j,xl,xr){
	bill[20+j]=max(bill[20+j],h);
      }
    }
    double min_distance=100000000000000000000.0;
    repi(i,-1*r,r){
      double circle_part = max(sqrt(r*r-i*i),sqrt(r*r-(i+1)*(i+1)));
      min_distance=min(min_distance,bill[20+i]+r-circle_part);
    }
    cout << min_distance << endl;
  }
}

Measured memory_bytes: 3204
// ----- In the name of ALLAH, the Most Gracious, the Most Merciful -----

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

#define sim template <class c
#define ris return *this
#define dor > debug &operator<<
#define eni(x)                                                                 \
  sim > typename enable_if<sizeof dud<c>(0) x 1, debug &>::type operator<<(    \
            c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c *x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
  ~debug() { cerr << endl; }
  eni(!=) cerr << boolalpha << i;
  ris;
} eni(==) ris << range(begin(i), end(i));
}
sim, class b dor(pair<b, c> d) {
  ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
  *this << "[";
  for (auto it = d.b; it != d.e; ++it)
    *this << ", " + 2 * (it == d.b) << *it;
  ris << "]";
}
#else
  sim dor(const c &) { ris; }
#endif
}
;
#define deb(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define memo(dp, val) memset(dp, val, sizeof(dp))
#define NINJA                                                                  \
  ios_base::sync_with_stdio(0);                                                \
  cin.tie(0);                                                                  \
  cout.tie(0)
#define all(a) a.begin(), a.end()
#define fo(i, n) for (int i = 0; i < n; i++)
#define Fo(i, k, n) for (int i = k; i < n; i++)
#define for1(i, n) for (int i = 1; i <= n; i++)
#define dloop(i, n) for (int i = n - 1; i >= 0; i--)
#define iii tuple<int, int, int>
#define vi vector<int>
#define ii pair<int, int>
#define vii vector<ii>
#define int long long
#define ld long double
#define pb push_back
#define endl "\n"
#define setbits __builtin_popcountll
#define mp map<int, int>
#define F first
#define S second
#define sz(v) (int)v.size()
#define mod 1000000007
#define inf (int)1e18

const int mxn = 1e6 + 10;
int spf[mxn];
int n;

int find_divisor(int x) {
  map<int, int> m;
  while (x != 1) {
    m[spf[x]]++;
    x /= spf[x];
  }
  int cnt = 1;
  for (auto i : m)
    cnt = (cnt * (i.second + 1));
  return cnt;
}

int32_t main() {
  NINJA;

  cin >> n;

  for (int i = 1; i < mxn; i++)
    spf[i] = i;

  for (int i = 4; i < mxn; i += 2) {
    spf[i] = 2;
  }

  for (int i = 3; i * i <= mxn; i++) {
    if (spf[i] == i) {
      for (int j = i * i; j < mxn; j += i) {
        if (spf[j] == j) {
          spf[j] = i;
        }
      }
    }
  }

  int cnt = 0;

  for (int i = 1; i <= n - 1; i++) {
    int a = find_divisor(i);
    cnt += a;
  }

  cout << cnt << endl;

  return 0;
}

Measured memory_bytes: 11420
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define rep2(i, s, n) for (ll i = (s); i < (ll)(n); i++)
#define all(v) v.begin(), v.end()
#define sz(v) v.size()
#define INF 100000000000000 //10^14 100兆
// aよりもbが大きいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmax(T &a, const T& b) {
  if (a < b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}
// aよりもbが小さいならばaをbで更新する
// (更新されたならばtrueを返す)
template <typename T>
bool chmin(T &a, const T& b) {
  if (a > b) {
    a = b;  // aをbで更新
    return true;
  }
  return false;
}

int main(){
  ll K, A, B;
  cin >> K >> A >> B;
  ll d = A;
  while(d <= B){
    if(d % K == 0){
      cout << "OK" << endl;
      return 0;
    }
    d++;
  }
  cout << "NG" << endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

struct Node;
using Trie = Node*;
struct Node {
  array<Trie, 26> ch;
  bool be;
  int sz;
};
void insert(Trie& t, const string& s, int i = 0) {
  if (!t) t = new Node();
  ++t->sz;
  if (!s[i]) {
    t->be = true;
    return;
  }
  insert(t->ch[s[i] - 'a'], s, i + 1);
}
int size(Trie t) { return t ? t->sz : 0; }

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<string> s(n);
  Trie t = new Node();
  for (auto&& e : s) {
    cin >> e;
    insert(t, e);
  }
  int Q; cin >> Q;
  struct Query { int id; string p; };
  VV<Query> q(n);
  for (int i = 0; i < Q; ++i) {
    int k; cin >> k, --k;
    string p; cin >> p;
    q[k].emplace_back(Query{i, p});
  }
  V<> res(Q);
  for (int i = 0; i < n; ++i) {
    VV<> a(26, V<>(26));
    auto v = t;
    int x = 0;
    for (char c : s[i]) {
      for (char d = 'a'; d <= 'z'; ++d) {
        a[c - 'a'][d - 'a'] += size(v->ch[d - 'a']);
      }
      x += v->be;
      v = v->ch[c - 'a'];
    }
    for (const auto& e : q[i]) {
      res[e.id] = x;
      for (int j = 0; j < 26; ++j) for (int k = 0; k < j; ++k) {
        res[e.id] += a[e.p[j] - 'a'][e.p[k] - 'a'];
      }
    }
  }
  for (int e : res) cout << e + 1 << '\n';
}

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

typedef long long ll;

int n, res;
int a[101];
int x3, x5, x15, x25, x75;
void init() {
    for (int i = 2; i <= n; ++i) {
        int n = i;
        while (n != 1) {
            for (int j = 2; j <= n; ++j) {
                while (n % j == 0) {
                    a[j]++;
                    n = n / j;
                }
            }
        }
    }
    for (int i = 2; i <= n; ++i) {
        if (a[i] >= 2) ++x3;
        if (a[i] >= 4) ++x5;
        if (a[i] >= 14) ++x15;
        if (a[i] >= 24) ++x25;
        if (a[i] >= 74) ++x75;
    }
}

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cin >> n;
    init();
    // cout <<  x3 << ' ' << x5 << endl;

    res += x5 * (x5 - 1) / 2 * (x3 - 2);
    res += x15 * (x5 - 1);
    res += x75;
    res += x25 * (x3 - 1);
    cout << res << endl;

    return 0;
}



Measured memory_bytes: 3632
n,k,*a=map(int,open(0).read().split())
l,*b=[[]for _ in range(200002)]
for i,v in enumerate(a):
  b[v]+=i,
  l+=len(b[v]),
s=a[0]
i=c=0
while i<n:
  j=l[i]%len(b[s])
  c+=j<1
  i=b[s][j]+1
  s=a[i%n]
k%=c+1
i=c=0
r=[]
while i<n:
  j=l[i]%len(b[s])
  if c>k-2and j<1:
    r+=s,
    i+=1
  else:i=b[s][j]+1
  c+=j<1
  s=a[i%n]
print(*r)

Measured memory_bytes: 48640
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
using namespace std;

#define rep(i,a) for(int i=0; i<a; i++)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define loop3(i,j,k,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)
#define loop4(i,j,k,l,a) for(int i=0; i<a; i++)for(int j=0; j<a; j++)if(i!=j)for(int k=0; k<a; k++)if(i!=k&&j!=k)for(int l=0; l<a; l++)if(i!=l&&j!=l&&k!=l)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define scnd1(a) scanf("%d", &a)
#define scnd2(a,b) scanf("%d%d", &a,&b)
#define scnd3(a,b,c) scanf("%d%d%d", &a,&b,&c)
#define scnd4(a,b,c,d) scanf("%d%d%d%d", &a,&b,&c,&d)
#define cin1(a) cin >> a;
#define cin2(a,b) cin >> a >> b;
#define cin3(a,b,c) cin >> a >> b >> c;
#define cin4(a,b,c,d) cin >> a >> b >> c >> d;
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define prtd1(a) printf("%d\n", a)
#define prtd2(a,b) printf("%d %d\n", a,b)
#define prtd3(a,b,c) printf("%d %d %d\n", a,b,c)
#define prtd4(a,b,c,d) printf("%d %d %d %d\n", a,b,c,d)
#define mem(a,n) memset( a, n, sizeof(a))

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;

long long power(long long x, long long c) {
    if(c==0) return 1;
    if(c==1) return x;
    if (c%2==1) return (power( (x*x)%MOD, c/2)*x)%MOD;
    else return power( (x*x)%MOD, c/2)%MOD;
}

ll comb(ll n, ll m, ll fc[], ll ifc[]){
    return (fc[n] * ifc[m] %MOD) * ifc[n-m] %MOD;
}

int main() {
    ll H, W, A, B;
    cin>>H>>W>>A>>B;
    
    ll fact[H+W]; fact[0]=1;
    rep1(i,H+W-1) fact[i]= fact[i-1]*i%MOD;
    
    ll invFact[H+W]; invFact[H+W-1] = power(fact[H+W-1],MOD-2);
    rrep(i,H+W-2) invFact[i] = invFact[i+1] * (i+1) %MOD;
    
    ll sum=0;
    for(int i=B+1; i<=W; i++){
        sum = ( sum + comb(H-A-1+i-1, i-1, fact, invFact) * comb(A-1+W-i, W-i, fact, invFact) )%MOD;
    }
    
    cout1(sum);
}

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

int main() {
  int a,b;
  cin >> a >> b;
  vector<int> T(1010);
  T.at(0)=1;
  for(int i=0;i<999;i++) T.at(i+1)=T.at(i)+i+2;
  int ans=0;
  for(int i=0;i<1000;i++){
    if(T.at(i)-a == T.at(i+1)-b){
      ans=T.at(i)-a;
      break;
    }
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
class UnionFind():
    def __init__(self, n):
        self.n = n
        self.parents = [-1] * n
    def find(self, x):
        if self.parents[x] < 0:
            return x
        else:
            self.parents[x] = self.find(self.parents[x])
            return self.parents[x]
    def union(self, x, y):
        x = self.find(x)
        y = self.find(y)
        if x == y:
            return 0
        if self.parents[x] > self.parents[y]:
            x, y = y, x
        self.parents[x] += self.parents[y]
        self.parents[y] = x

N,M,*f = map(int, open(0).read().split())
p = f[:N]
xy = [f[N+2*i:N+2*i+2] for i in range(M)]
uf = UnionFind(N+1)
for x, y in xy:
    uf.union(x,y)
ans = 0
for i in range(1,N+1):
    if p[i-1] == i:
        ans += 1
    else:
        if uf.find(p[i-1]) == uf.find(i):
            ans += 1
        elif uf.find(i) < 0:
            if uf.find(p[i-1]) == i:
                ans += 1
        elif uf.find(p[i-1]) < 0:
            if uf.find(i) == p(i-1):
                ans += 1
print(ans)

Measured memory_bytes: 35316
N = int(input())
S = input()

sum = 0
for i in range(1,len(S)):
    if S[i] == 'E':
        sum += 1
min = sum

for i in range(1,len(S)):
    if S[i] == 'E':
        sum -= 1
    if S[i-1] == 'W':
        sum += 1
    if min > sum:
        min = sum
print(min)

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

bool dfs(int i, int nowcolor, vector<vector<int>> &way, vector<int> &color) {
  color.at(i) = nowcolor;
  for(int j = 0; j < way.at(i).size(); j++) {
    if(color.at(way.at(i).at(j)) == nowcolor) {
      return false;
    }
    else if(color.at(way.at(i).at(j)) == -1) {
      color.at(way.at(i).at(j)) = 1 - nowcolor;
      if(!dfs(way.at(i).at(j), 1 - nowcolor, way, color)) {
        return false;
      }
    }
  }
  return true;
}
            
int main() {
  int64_t N, M;
  cin >> N >> M;
  vector<vector<int>> way(N);
  for(int64_t i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    way.at(a - 1).push_back(b - 1);
    way.at(b - 1).push_back(a - 1);
  }
  vector<int> color(N, -1);
  if(!dfs(0, 0, way, color)) {
    cout << N * (N - 1) / 2 - M << endl;
  }
  else {
    int count = 0;
    for(int i = 0; i < N; i++) {
      if(color.at(i) == 1) {
        count++;
      }
    }
    cout << count * (N - count) - M << endl;
  }
}

Measured memory_bytes: 6784
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <numeric>
#include <stack>
#include <queue>
#include <map>
#include <set>
#include <utility>
#include <sstream>
#include <complex>
#include <fstream>
#include <bitset>
#include <time.h>
#include <tuple>
#include <iomanip>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;
typedef vector<ll> V;
typedef complex<double> Point;

#define PI acos(-1.0)
#define EPS 1e-10
const ll INF = 1e12;
const ll MOD = 1e9 + 7;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,N) for(int i=0;i<(N);i++)
#define ALL(s) (s).begin(),(s).end()
#define EQ(a,b) (abs((a)-(b))<EPS)
#define EQV(a,b) ( EQ((a).real(), (b).real()) && EQ((a).imag(), (b).imag()) )
#define fi first
#define se second
#define N_SIZE (1LL << 20)
#define NIL -1

ll sq(ll num) { return num*num; }
ll mod_pow(ll x, ll n) {
	if (n == 0)return 1;
	if (n == 1)return x%MOD;
	ll res = sq(mod_pow(x, n / 2));
	res %= MOD;
	if (n % 2 == 1) {
		res *= x;
		res %= MOD;
	}
	return res;
}
ll mod_add(ll a, ll b) { return (a + b) % MOD; }
ll mod_sub(ll a, ll b) { return (a - b + MOD) % MOD; }
ll mod_mul(ll a, ll b) { return a*b % MOD; }

ll n, m, l, k, a, h;
vector<ll> ls;
ll dp[110][110];

struct edge{
	ll to;
	ll cost;
};
vector<edge> G[110];
ll d[100010];

void dijkstra() {
	fill(d, d + 100010, INF);
	d[a] = 0;

	typedef pair<P, ll> Pi;
	priority_queue<Pi, vector<Pi>, greater<Pi>> que;
	que.push({ P(0, a), m });

	while (!que.empty()) {
		Pi p = que.top();
		que.pop();
		ll v = p.first.second;
		ll nm = p.second;
		if (d[v] < p.first.first || v == h)continue;
		for (int i = 0; i < G[v].size(); i++) {
			edge e = G[v][i];
			if (e.cost > m)continue;
			if (nm >= e.cost) {
				if (d[e.to] > d[v] + e.cost) {
					d[e.to] = d[v] + e.cost;
					que.push({ P(d[e.to], e.to), nm - e.cost });
				}
			}
			else {
				if (d[e.to] > d[v] + e.cost + (e.cost - nm)) {
					d[e.to] = d[v] + e.cost + (e.cost - nm);
					que.push({ P(d[e.to], e.to), 0 });
				}
			}
		}
	}
}

int main() {
	while (cin >> n >> m >> l >> k >> a >> h&&n + m + l + k + a + h) {
		ls.clear();
		rep(i, l) {
			ll x;
			cin >> x;
			ls.push_back(x);
		}
		ls.push_back(a);
		ls.push_back(h);
		rep(i, n) {
			G[i].clear();
			rep(j, n) {
				if (i == j)dp[i][j] = 0;
				else dp[i][j] = INF;
			}
		}
		rep(i, k) {
			ll x, y, c;
			cin >> x >> y >> c;
			dp[x][y] = c;
			dp[y][x] = c;
		}
		rep(kk, n) {
			rep(i, n) {
				rep(j, n)dp[i][j] = min(dp[i][j], dp[i][kk] + dp[kk][j]);
			}
		}
		rep(i, ls.size()) {
			FOR(j, i + 1, ls.size()) {
				ll u = ls[i], v = ls[j];
				G[u].push_back({ v,dp[u][v] });
				G[v].push_back({ u,dp[v][u] });
				//cout << u << " " << v << " " << dp[u][v] << endl;
			}
		}
		dijkstra();
		//rep(i, n) {
		//	cout << "!" << i << " " << d[i] << endl;
		//}
		if (d[h] == INF)cout << "Help!" << endl;
		else cout << d[h] << endl;
	}
}


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

int main()
{
  long long N,K;
  cin>>N>>K;
  vector<long long> H(N);
  for(long long int i=0; i<N; i++)
    cin>>H[i];
  if(K>=N)
    cout<<0;
  else
  {
    sort(H.begin(), H.end());
    long long sum =0;
    for(long long i=0; i<N-K; i++)
      sum+=H[i];
    cout<<sum;
  }
  return 0;
}

Measured memory_bytes: 1792
#include<iostream>

int a, b, c;
int n;

int main()
{
	while( std::cin >> a >> b >> c, a | b | c )
	{
		std::cin >> n;

		int mi = std::min( a, std::min( b, c ) );
		int ma = std::max( a, std::max( b, c ) );
		int snd = a + b + c - mi - ma;

		while( n-- )
		{
			int r;
			std::cin >> r;

			if( mi * mi + snd * snd < 4 * r * r )
				std::cout << "OK" << std::endl;
			else
				std::cout << "NA" << std::endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1156
#include<cstdio>
#include<cstdlib>
#include<cstring>
struct Node{
    int key;
    Node *next,*prev;
};
Node *nil;
Node* listSearch(int key){
    Node *cur = nil->next;
    while(cur!=nil && cur->key != key){
        cur = cur->next;
    }
    return cur;
}
void init(){
    nil=(Node *)malloc(sizeof(Node));
    nil->next=nil;
    nil->prev=nil;
}
void printList(){
    Node *cur = nil->next;
    int isf=0;
    while(1){
        if(cur==nil)break;
        if(isf++>0)printf(" ");
        printf("%d",cur->key);
        cur=cur->next;
    }
    printf("\n");
}
void deleteNode(Node *t){
    if(t==nil)return;
    t->prev->next=t->next;
    t->next->prev=t->prev;
    free(t);
}
void deleteFirst(){
    deleteNode(nil->next);
}
void deleteLast(){
    deleteNode(nil->prev);
}
void deleteKey(int key){
    deleteNode(listSearch(key));
}
void insert(int key){
    Node *x=(Node *)malloc(sizeof(Node));
    x->key=key;
    x->next=nil->next;
    nil->next->prev=x;
    nil->next=x;
    x->prev=nil;
}
int main(){
    int key,n,i;
    int size=0;
    char com[20];
    int np=0,nd=0;
    scanf("%d",&n);
    init();
    for(i=0;i<n;i++){
        scanf("%s%d",com,&key);
        if(com[0]=='i'){insert(key);np++;size++;}
        else if(com[0]=='d'){
            if(strlen(com)>6){
                if(com[6]=='F')deleteFirst();
                    if(com[6]=='L')deleteLast();
                }else{
                    deleteKey(key);nd++;
                }
                size--;
                }
        }
        printList();
        return 0;
    }


Measured memory_bytes: 33928
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    string S;
    cin >> S;
    int L = S.size();

    int upper = 1 << (L - 1);
    ll ans = 0;
    for (int b = 0; b < upper; b++) {
        vector<int> split;
        split.push_back(0);
        for (int i = 0; i < L; i++) { if (b >> i & 1) split.push_back(i+1); }
        split.push_back(L);
        for (int i = 0; i < split.size() - 1; i++) {
            ans += stoll(S.substr(split[i], split[i+1] - split[i]));
        }
    }
    cout << ans << '\n';
}


Measured memory_bytes: 256
def iread():
    return int(input())


def sread():
    return input()


def aread_int():
    tmp = input().split()
    ret = [int(i) for i in tmp]
    return ret


def aread_str():
    return input().split()

if __name__ == '__main__':
    n, m = map(int, input().split())
    
    x = aread_int()
    x = sorted(x)
    x_dist = [0] * (m - 1)
    for i in range(m - 1) :
        x_dist[i] += abs(x[i] - x[i + 1])
    
    if n > m :
        print(0)
        exit()
    
    x_dist = sorted(x_dist)
    idx = len(x_dist) - 1
    cost = sum(x_dist)
    for i in range(n - 1) :
        cost -= x_dist[idx]
        x_dist[idx] = 0
        idx -= 1

    print(cost)

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

const long long MAX = 1000000;
const long long MOD = 1000000000 + 7;

long long fac[MAX], finv[MAX], inv[MAX];

void COMinit() {
  fac[0] = fac[1] = 1;
  finv[0] = finv[1] = 1;
  inv[1] = 1;
  for (long long i = 2; i < MAX; i++) {
    fac[i] = fac[i - 1] * i % MOD;
    inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
    finv[i] = finv[i - 1] * inv[i] % MOD;
  }
}

long long COM(long long n, long long k) {
  if (n < 0 || k < 0 || k > n) return 0;
  return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main () {
  
  long long X, Y;
  cin >> X >> Y;
  
  COMinit();
  
  if ((X + Y) % 3 != 0 || Y > 2*X || X > 2*Y) {
    cout << 0 << endl;
  }
  
  else {
    
    long long n = (X + Y) / 3;
    long long k = (n - Y + X) / 2;
    
    cout << COM(n, k) << endl;
    
  }
  
}


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

#define ll long long
#define pb push_back
#define pii pair<int,int>
#define pll pair<ll,ll>
#define ff first
#define ss second

using namespace std;

const double pi = acos(-1);
const int N = 2e3 + 6, mod = 998244353, M = 1e7 + 7;
const ll MAX = 5e18;

int n, c[N], a[N], r;
ll ans;

bool can(int x, int y, int z){
    return x + y > z && x + z > y && y + z > x;
}

int main()
{
    cin >> n;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    for(int i = 0; i < n; i++){
        r = i + 2;
        for(int j = i + 1; j < n; j++){
            while(r < n && can(a[i], a[j], a[r]))
                r++;
            if(r <= n)
                ans += r - j - 1;
        }
    }
    cout << ans;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <queue>
#include <vector>
#include <set>
#define maxn 1100
#define oo 1000000000
#define clearAll(a) memset(a,0,sizeof(a))
#define sq(a) ((a)*(a))

using namespace std;

typedef long long ll;

vector<int> g[maxn];
ll d[115][115];
int a[maxn];
ll t[maxn];

int p[maxn],vis[maxn],n,m,l;

int find(int u)
{
    int i;
    int sz = g[u].size();

    for(i=0;i<sz;i++)
    {
    	int v = g[u][i];

        if(vis[v]==0)
        {
            vis[v]=1;
            if(p[v]==0||find(p[v])==1)
            {
                p[v]=u;
                return 1;
            }
        }
    }
    return 0;
}

void build()
{
	for (int i=1;i<=l;i++)
		scanf("%d%lld",&a[i],&t[i]);
	int x,y;
	for (int i=1;i<=l;i++)
		for (int j=1;j<=l;j++)
		if (i!=j)
		{
			x = a[i]+1; y = a[j]+1;
			if (d[x][y]+t[i]<=t[j])
				g[i].push_back(j);
		}
}

int main()
{
    //freopen("C:\\Users\\py\\Desktop\\input.txt","r",stdin);
    //freopen("C:\\Users\\py\\Desktop\\output.txt","w",stdout);

    while (scanf("%d%d%d",&n,&m,&l)&&(n||m||l))
    {

    	for (int i=1;i<=l;i++)
    		g[i].clear();

    	int x,y,w;

    	for (int i=1;i<=n;i++)
    		for (int j=1;j<=n;j++)
    			d[i][j]=oo;
    	for (int i=1;i<=n;i++)
    		d[i][i]=0;

    	for (int i=1;i<=m;i++)
    	{
    		scanf("%d%d%d",&x,&y,&w);
    		x++; y++;
    		d[x][y]=d[y][x]=w;
    	}

    	for (int k=1;k<=n;k++)
    		for(int i=1;i<=n;i++)
    			for (int j=1;j<=n;j++)
    				d[i][j]=min(d[i][j],d[i][k]+d[k][j]);
    	build();

        clearAll(p);
    	int ans = 0;
    	for (int i=1;i<=l;i++)
    	{
    	    clearAll(vis);
    		if (find(i)==1)
    			ans++;
    	}

    	printf("%d\n",l-ans);
    }

    return 0;
}

Measured memory_bytes: 5640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <algorithm>
using namespace std;

#include <assert.h>

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

int main() {
    int n;
    cin >> n;
    int ma = 0, ans;
    REP(i,n){
        int a, b;
        cin >> a >> b;
        if (a > ma){
            ma = a;
            ans = a + b;
        }
    }
    cout << ans << endl;

    return 0;
}





Measured memory_bytes: 256
N, M = map(int, input().split())
K = [list(map(int, input().split())) for _ in range(M)]
P = list(map(int, input().split()))

num = 2**N
ans = 0
for i in range(num):
    bit = bin(i)[2:].zfill(N)
    on, off = [], []
    ret = 0
    for j, b in enumerate(bit):
        j += 1
        if b == '1':
            on.append(j)
        else:
            off.append(j)
    for k in range(M):
        on = set(on)
        onon = set(K[k][1:])
        if len(on & onon) % 2 == P[k]:
            ret += 1
    if ret == M:
        ans += 1

print(ans)


Measured memory_bytes: 3064
#include <cstdio>
#include <iostream>
#include <cstring>
#include <string>
#include <cmath>
#include <algorithm>
#include <cstdlib>
#include <utility>
#include <map>
#include <stack>
#include <set>
#include <vector>
#include <queue>
#include <deque>
#define x first
#define y second
#define mp make_pair
#define pb push_back
#define LL long long
#define Pair pair<int,int>
#define LOWBIT(x) x & (-x)
using namespace std;

const int MOD=1e9+7;
const LL INF=1e16+1000;
const int magic=348;

LL k;
int n;
LL a[148];
LL b[148];
LL least,most;
LL cnt,cur;

int main ()
{
	int i,j;
	cin>>k;
	LL coef;
	for (n=2;n<=50;n++)
	{
		//if ((k-(n-1))%(n+1)==0) least=(k-(n-1))%(n+1); else least=(k-(n-1))%(n+1)+1;
		//if ((INF+k)%(n+1)==0) most=(INF+k)%(n+1); else most=(INF+k)%(n+1);
		//if (least*n>k || most*n<k) continue;
		//for (i=1;i<=n;i++) a[i]=least;
		for (i=1;i<=n;i++) a[i]=0;
		LL left=k;
		LL ss=left/n;
		for (i=1;i<=n;i++) a[i]+=ss;
		left=left-(left/n*n); 	
		for (i=1;i<=left;i++) a[i]++;
		bool f=true;
		for (i=1;i<=n;i++)
		{
			coef=a[i]*n+a[i]-k;
			if ((n-1)+coef<0)
			{
				f=false;
				break;
			}
			if (coef>INF)
			{
				f=false;
				break;
			}
		}
		if (!f) continue;
		cout<<n<<endl;
		for (i=1;i<=n;i++)
		{
			coef=a[i]*n+a[i]-k;
			LL num=n-1;
			while (num+coef>INF) num--;
			cout<<num+coef<<' ';
		}
		cout<<endl;
		//for (i=1;i<=n;i++) cout<<a[i]<<' ';
		//cout<<endl;
		break;
	}
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<algorithm>
#include<string>
 
using namespace std;
 
int expression();
int term();
int factor();
int number();
 
int now;
string s;
 
int expression(){
    int res=term();
        while(true){
        if(s[now]=='+')now++,res+=term();
        else if(s[now]=='-')now++,res-=term();
        else break;
    }
    return res;
}
 
int term(){
    int res=factor();
    while(true){
        if(s[now]=='*')now++,res*=factor();
        else if(s[now]=='/')now++,res/=factor();
        else break;
    }
    return res;
}
 
int factor(){
    int res=0;
    if(s[now]=='('){
        now++;
        res=expression();
        now++;
    }
    else return number();
     
    return res;
}
 
int number(){
    int res=0;
    while('0'<=s[now] && s[now]<='9'){
        res*=10;
        res+=s[now++]-'0';
    }
    return res;
}
 
 
int main(void){
    int n;
    cin >> n;
     
    while(n--){
        cin >> s;
        now=0;
        cout << expression() << endl;
    }
     
    return 0;
}

Measured memory_bytes: 3084
K, T = map(int, input().split())
numbers = [int(x) for x in input().split()]

table = [False] * (K + 1)

table[0] = True

for n in numbers:
  for i in range(K, 0, -1):
    if i - n >= 0:
      table[i] = table[i] or table[i - n]
    
m = 0

for i, t in enumerate(table):
  if not t:
    continue
  m = i if abs(i - K / 2) < abs(m - K / 2) else m

if abs(2 * m - K) <= 1:
  print(0)
else:
  print(abs(2 * m - K) - 1)

Measured memory_bytes: 39280
#include <iostream>
#include <algorithm>
#include <bitset>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <cstring>
#include <utility>
#include <vector>
#include <complex>
#include <valarray>
#include <fstream>
#include <cassert>
#include <cmath>
#include <functional>
#include <iomanip>
#include <numeric>
#include <climits>
#include <random>

#define _overload(a, b, c, d, ...) d
#define _rep1(X, A, Y) for (int (X) = (A);(X) <= (Y);++(X))
#define _rep2(X, Y) for (int (X) = 0;(X) < (Y);++(X))
#define rep(...) _overload(__VA_ARGS__, _rep1, _rep2)(__VA_ARGS__)
#define rrep(X,Y) for (int (X) = Y-1;(X) >= 0;--(X))
#define all(X) (X).begin(),(X).end()
#define len(X) ((int)(X).size())
#define mod(n, m) (((n)%(m)+(m))%m)
#define fi first
#define sc second
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
const int INFINT = 1 << 30;                          // 1.07x10^ 9
const ll INFLL = 1LL << 60;                          // 1.15x10^18
const double EPS = 1e-10;
const int MOD = 1000000007;
const int dx[4] = {1, 0, -1, 0}, dy[4] = {0, 1, 0, -1};

int N, K;

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

  cin >> N >> K;
  cout << N-K+1 << endl;

}


Measured memory_bytes: 888
import java.util.*;

class Main {
    static int a;
    static int b;

    public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      a = sc.nextInt();    
      b = sc.nextInt();    
      System.out.println(a * b + " " + 2*(a + b));
    }
}


Measured memory_bytes: 26144
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <map> 
using namespace std;
typedef long long ll;
#define rep(i,n) for (int i=0;i < (int)(n);i++)

 
int main(){
  int n,x;
  cin >> n >> x;
  vector<int> v(n);
  int mn = 1e9;
  rep(i,n){
    cin >> v[i];
    x-= v[i];
    mn = min(mn,v[i]);
  }
  cout << n+(x/mn) << endl;

  
  
  return 0; 
}



Measured memory_bytes: 256
def main():
    input1 = input()
    input2 = input()
    k , n = map(int , input1.split())
    al = list(map(int , input2.split()))
    arg = [[k,n],al]
    ans = process(arg)
    print(ans)
    
def process(arg):
    ans = 0
    ensyu = arg[0][0]
    kensu = arg[0][1]
    aida = list()
    for x in range(arg[0][1]):
        mae = arg[1][x-1]
        b = arg[1][x]
        if x == 0:
            # 1件目は演習
            w = b + ensyu - arg[1][kensu-1]
        else:
            w = b - mae
        aida.append(w)

    m = max(aida)
    flg = False
    for y in aida:
        if flg == True or y != m :
            ans = ans + y
        else:
            flg = True
    return ans

def getInput(input):

    return 

if __name__ == '__main__':
    main()


Measured memory_bytes: 27220
#include <bits/stdc++.h>
#define ll long long int
#define ld long double
#define yorn(f) cout<<((f)?"Yes":"No")<<endl;
#define YORN(f) cout<<((f)?"YES":"NO")<<endl;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i, n) for (int i = 1; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define put(x) cout << x << endl;
#define println(x) cout << x << endl;
using namespace std;
int main()
{
    int n;
    cin >> n;
    vector<ll> h(n);
    rep(i, n) cin >> h[i];

    ll ma = 0;
    rep(i, n) {
        if (ma - h[i] >= 2) {
            put("No");
            return 0;
        }
        ma = max(ma, h[i]);
    }
    
    put("Yes");

    return 0;
}

Measured memory_bytes: 4008
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,n) for(int i=0;i<n;i++)
#define Rep(i,n) for(int i=1;i<=n;i++)
const ll MOD = 1000000007;
struct edge{
    int to,weight;
    edge(int to,int weight):to(to),weight(weight){}
};
using Graph = vector<vector<int>>;
using GraphEdge = vector<vector<int>>;
long long modinv(long long a, long long m=MOD) {long long b = m, u = 1, v = 0;while (b) {    long long t = a / b;    a -= t * b; swap(a, b);    u -= t * v; swap(u, v);}u %= m; if (u < 0) u += m;return u;}
//MODの割り算の際にa/＝b;をa *= modinv(b,MOD);とする。
int gcd(int a, int b){if (a%b == 0){return(b);}else{return(gcd(b, a%b));}}
int lcm(int a, int b){return a * b / gcd(a, b);}

int main(){
    int a,b;cin >>a >> b;
    cout << a+(b/2) << endl;
    return 0;
}

Measured memory_bytes: 3624
using System;
using System.Linq;

namespace D
{
    class Program
    {
        static void Main(string[] args)
        {
            int[] IN = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();
            long n = IN[0];
            long m = IN[1];
            for(long i = m / n; i >= 1; i--)
            {
                if (m % i == 0) { Console.WriteLine(i);break; }
            }
        }
    }
}

Measured memory_bytes: 28236
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<stack>
#include<cstdlib> 
using namespace std;
int main(){
	int n,a[100005],b[100005],ans=0;
	cin>>n;
	for(int i=1;i<=n;i++){
		cin>>a[i]>>b[i];
		ans+=b[i]-a[i]+1;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
#include<math.h>
#include<algorithm>
using namespace std;

int nx[4][2]= {{-1,0},{0,-1},{0,1},{1,0}}; //上 左 右 下  置换顺序

//各个数字应在位置对照表
int goal[16][2]= {{3,3},{0,0},{0,1},{0,2},//0 1 2 3
    {0,3},{1,0},{1,1},{1,2},//4 5 6 7
    {1,3},{2,0},{2,1},{2,2},//8 9 10 11
    {2,3},{3,0},{3,1},{3,2}
};//12 13 14 15

int map[4][4],map2[16],limit;
//mit全部的曼哈顿距离之和
int flag,length;

int hv(int a[][4])//估价函数,曼哈顿距离,小于等于实际总步数
{
    int cost=0;
    for(int i=0; i<4; i++)
    {
        for(int j=0; j<4; j++)
        {
            int w=map[i][j];
            if( w != 0 )
                cost+=abs(i-goal[w][0])+abs(j-goal[w][1]);
        }
    }
    return cost;
}

void dfs(int x,int y,int len,int pre_move)//sx,sy是空格的位置
{
    if(flag) return;
    int dv=hv(map);
    if(len==limit)
    {
        if(dv==0)  //成功 退出
        {
            flag=1;
            length=len;
            return;
        }
        else return;  //超过预设长度 回退
    }
    else if(len<limit)
    {
        if(dv==0)  //短于预设长度 成功 退出
        {
            flag=1;
            length=len;
            return;
        }
    }
    for(int i=0; i<4; i++)
    {
        if(i+pre_move==3&&len>0) continue;//不和上一次移动方向相反,对第二步以后而言
        int tx=x+nx[i][0];
        int ty=y+nx[i][1];
        if(tx>=0&&tx<4&&ty>=0&&ty<4)
        {
            swap(map[x][y],map[tx][ty]);
            int p=hv(map);
            if(p+len<=limit&&flag==0)
            {
                dfs(tx,ty,len+1,i);
                if(flag) return;
            }
            swap(map[x][y],map[tx][ty]);
        }
    }
}

int main()
{
    int t=1;
    while(t--)
    {
        int x1,y1;
        for(int i=0; i<16; i++) //map一维map2二维
        {
            scanf("%d",&map2[i]);
            if(map2[i]==0)
            {
                x1=i/4;
                y1=i%4;
                map[x1][y1]=0;
            }
            else
            {
                map[i/4][i%4]=map2[i];
            }
        }

        limit=hv(map);
//        printf("limit===%d\n",limit);
        flag=0;
        length=0;
        while(flag==0&&length<=45)//要求45步之内到达
        {
            dfs(x1,y1,0,0);
            if(flag==0) limit++; //得到的是最小步数
        }
        if(flag) printf("%d\n",length);
    }
    return 0;
}


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

int main(){
    int h,w;
    cin >> h >> w;
    char s[h][w];
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            cin >> s[i][j];
        }
    }
    int ans;
    for(int i=0;i<h;i++){
        for(int j=0;j<w;j++){
            ans=0;
            if(s[i][j]=='.'){
                for(int k=-1;k<=1;k++){
                    for(int l=-1;l<=1;l++){
                        if(i+k>=0&&i+k<h&&j+l>=0&&j+l<w){
                            if(s[i+k][j+l]=='#') ans++;
                        }
                    }
                }
                cout << ans;
            }else{
                cout << '#';
            }
        }
        cout << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <cstring>
#include <algorithm>
using namespace std;

int main(){
  int L, A, B, C, D;
  int a, b;
  
  cin >> L >> A >> B >> C >> D;
  a = A / C;
  if(A % C != 0) a++;
  b = B / D;
  if(B % D != 0) b++;
  
  int ans = L - max(a, b);
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 1164
#include<stdio.h>
int main(void)
{
    int a,b,max;
    scanf("%d %d",&a,&b);
    max=a+b;
    if(max<a-b){
        max=a-b;
    }
    if(max<a*b){
        max=a*b;
    }
    printf("%d\n",max);
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define pb push_back
#define N 300009
#define inf 1e18
int mod=1e9+7;
int maxN=1e9;

#define PI 3.141596535

int32_t main(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n;cin>>n;
    int k;cin>>k;
    int s=0;
    for(int i=0;i<k;i++){
        int x;cin>>x;
        s+=x;
    }
    int left=n-s;
    left=max(-1LL,left);
    cout<<left<<"\n";
    return 0;
}

Measured memory_bytes: 3656
// ABC142 B

#include <bits/stdc++.h>
#define RI register int
typedef long long LL;


using namespace std;

int main() {

  int n; cin >> n;
  int m; cin >> m;
  int ans = 0;
  for (RI i = 1, x; i <= n; ++i)
    cin >> x, ans += (x >= m);
  cout << ans;

  return 0;
}

// created by Daniel yuan


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

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

  int ans = 0;
  for( int i = 0; i < n; i++ ) {
    if( i < k ) {
      ans += x;
    }
    else {
      ans += y;
    }
  }

  cout << ans << endl;

  return 0;
}



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

int main(){
  int i, j, k;
  int w, h;
  char s[30][30] = {}, c;

  cin>>w>>h>>c;

  for(i = 1; i <= w; i++){

    if(i != 1 && i != w)s[1][i] = '-';
    else s[1][i] = '+';
    if(i != 1 && i != w)s[h][i] = '-';
    else s[h][i] = '+';
  }

  for(i = 1; i <= h; i++){

    if(i != 1 && i != h)s[i][1] = '|';
    else s[i][1] = '+';
    if(i != 1 && i != h)s[i][w] = '|';
    else s[i][w] = '+';
  }

  for(i = 1; i <= h; i++ ){
    for(j = 1; j <= w; j++){
      if(s[i][j] != '+' && s[i][j] != '-' && s[i][j] != '|') s[i][j] = '.';
    }
  }

  s[(h + 1)/2][(w + 1)/2] = c;

    for(i = 1; i <= h; i++){
      for(j = 1; j <= w; j++){
	cout<<s[i][j];
      }cout<<endl;
    }
  
  return 0;
}



Measured memory_bytes: 3092
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Text;
 
 
 
class Myon
{
    public Myon() { }
    public static int Main()
    {
        cin = new Scanner();
        new Myon().calc();
        return 0;
    }
 
    static Scanner cin;
 
  // ここに回答
    void calc()
    {
        string s = cin.next();
        int N = 13;
        int mod = 1000000007;

        long[] dp = new long[N];
        dp[0] = 1;

        for (int i = 0; i < s.Length; i++)
        {
            long[] nextDp = new long[N];
            char c = s[i];
            if (c == '?')
            {
                // ?が0～9まで値を取るためループ
                for (int j = 0; j < 10; j++)
                {
                    // 13のあまりは0～12まで取るためループ
                    for (int k = 0; k < N; k++)
                    {
                        // 合同式の性質から、ある値に1桁jを足すと、(1桁前の余りk*10)+jが新しいあまりになる
                        nextDp[((k * 10) + j) % N] += dp[k];
                        nextDp[((k * 10) + j) % N] %= mod;
                    }
                }
            }
            else
            {
                // charからintへの変換
                int j = (int)(s[i] - '0');
                // 13のあまりは0～12まで取るためループ
                for (int k = 0; k < N; k++)
                {
                    // 合同式の性質から、ある値に1桁jを足すと、(1桁前の余りk*10)+jが新しいあまりになる
                    nextDp[((k * 10) + j) % N] += dp[k];
                    nextDp[((k * 10) + j) % N] %= mod;
                }

            }
            dp = nextDp;
        }

        Console.WriteLine(dp[5]);
    }
}
 
 
 
class Scanner
{
    string[] s;
    int i;
 
    char[] cs = new char[] { ' ' };
 
    public Scanner()
    {
        s = new string[0];
        i = 0;
    }
 
    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }
 
    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }
 
    public long nextLong()
    {
        return long.Parse(next());
    }
 
    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }
 
    public double nextDouble()
    {
        return double.Parse(next());
    }
 
 
    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}

Measured memory_bytes: 16072
let rec check str maxN bufN =
  let len = (String.length str) in
  if len = 0 then maxN
  else
    let headS = str.[0] in
    let newStr = String.sub str 1 (len - 1) in
    if headS = 'A' || headS = 'T' || headS = 'C' || headS = 'G' then
      let newBufN = bufN + 1 in
      if maxN <= newBufN then
        check newStr newBufN newBufN
      else
        check newStr maxN newBufN
    else check newStr maxN 0
let () = Scanf.scanf "%s\n"
    (fun str -> check str 0 0)
         |> print_int

Measured memory_bytes: 384
#include<iostream>
#include<cmath>
using namespace std;
typedef long long li;
#define rep(i,n) for(int i=0;i<(n);i++)
#define df 0
template<class T> void print(const T& t){ cout << t << "\n"; }
template<class T, class... Ts> void print(const T& t, const Ts&... ts) { cout << t; if (sizeof...(ts)) cout << " "; print(ts...); }

int main(){
  int a,b,h,m; cin >>a >>b >>h >>m;
  double xa,ya,xb,yb;
  xb=cos(m*M_PI/30)*b;
  yb=sin(m*M_PI/30)*b;
  if(df)print(xb,yb);
  m+=h*60;
  xa=cos(m*M_PI/30/12)*a;
  ya=sin(m*M_PI/30/12)*a;
  double x=xa-xb,y=ya-yb;
  if(df)print(xa,ya);
  
  printf("%10.15lf\n",sqrt(x*x+y*y));
}


Measured memory_bytes: 4028