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

using namespace std;

#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, a, b) for(ll i = (a); i > (b); --i)
#define REP(i, n) for(ll i = 0; i < (n); ++i)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOREACH(x, a) for(auto &(x) : (a))
#define VECCIN(x)                                                              \
    for(auto &youso_ : (x)) cin >> youso_
#define mp make_pair
#define bitcnt __builtin_popcount
#define SZ(x) ((ll)(x).size())
#define All(a) (a).begin(), (a).end()
template <typename T = long long> inline T IN() {
    T x;
    cin >> x;
    return (x);
}
inline void CIN() {}
template <class Head, class... Tail>
inline void CIN(Head &&head, Tail &&... tail) {
    cin >> head;
    CIN(move(tail)...);
}
#define CINT(...)                                                              \
    int __VA_ARGS__;                                                           \
    CIN(__VA_ARGS__)
#define LCIN(...)                                                              \
    ll __VA_ARGS__;                                                            \
    CIN(__VA_ARGS__)
#define SCIN(...)                                                              \
    string __VA_ARGS__;                                                        \
    CIN(__VA_ARGS__)
#define Yes(a) cout << (a ? "Yes" : "No") << "\n"
#define YES(a) cout << (a ? "YES" : "NO") << "\n"

typedef long long ll;
typedef unsigned long long ul;
typedef vector<int> V;
typedef vector<ll> VL;
typedef pair<ll, ll> PL;
typedef priority_queue<ll> PQ;
typedef priority_queue<ll, V, greater<ll>> PQG;

const int INF = 1e9;
const int MOD = 1e9 + 7;
// const int MOD = 998244353;
const ll LINF = 1e18;

ll N, K;

ll pow(ll x, ll n) {
    ll res = 1;
    while(n > 0) {
        if(n & 1) res = res * x;
        x *= x;
        n >>= 1;
    }
    return res;
}

int main() {
    cin >> N >> K;
    if(K % 2) {
        cout << setprecision(18) << pow(N / K, 3) << "\n";
    } else {
        ll div2 = N / K;
        if(N % K >= K / 2) div2++;
        ll ans = pow(div2, 3) + pow(N / K, 3);
        cout << setprecision(18) << ans << "\n";
    }
}


Measured memory_bytes: 384
# -*- coding: utf-8 -*-
"""
https://beta.atcoder.jp/contests/abc082/tasks/arc087_b

"""
import sys
from sys import stdin
input = stdin.readline


def check_x(forwards):
    n = sum(forwards[::2])      #  x軸方向への最大移動量
    dpx = [False] * (n * 2 + 1) #  真ん中を0として、±両方向のdp領域を確保
    dpx[forwards[0] + n] = True #  最初は0からプラス方向に移動

    for f in forwards[2::2]:
        if f == 0:
            continue
        n_move = dpx[f:] + [False]*f
        p_move = [False]*f + dpx[:-f]
        t = [a or b for a, b in zip(n_move, p_move)]
        dpx = t
    return dpx, n


def check_y(forwards):
    n = sum(forwards[1::2])
    dpy = [False] * (n * 2 + 1)
    dpy[n] = True

    for f in forwards[1::2]:
        if f == 0:
            continue
        n_move = dpy[f:] + [False]*f
        p_move = [False]*f + dpy[:-f]
        t = [a or b for a, b in zip(n_move, p_move)]
        dpy = t
    return dpy, n


def solve(s, gx, gy):
    forwards = [len(x) for x in s.split('T')] #  進む歩数情報の数字に変換
    dpx, zx = check_x(forwards)
    dpy, zy = check_y(forwards)

    if zx < abs(gx):
        return 'No'
    if zy < abs(gy):
        return 'No'
    if dpx[gx + zx] is True and dpy[gy + zy] is True:
        return 'Yes'
    else:
        return 'No'


def main(args):
    s = input().strip()
    gx, gy = map(int, input().split())
    # s = 'F'
    # gx, gy = -1, 0
    ans = solve(s, gx, gy)
    print(ans)


if __name__ == '__main__':
    main(sys.argv[1:])
    


Measured memory_bytes: 3700
#include<stdio.h>
	int main(){
		int d,e,f,g,a,C[26]={0};
		char b;
		register c;
		while(scanf("%c", &b) != EOF ){
		
		if(isupper(b))
		b=tolower(b);
		a=b-'a';
        C[a]+=1;
	}
	for(c=0;c<26;c++){
		b=c+'a';
		printf("%c : %d\n",b,C[c]);
	}
	return 0;
	}

Measured memory_bytes: 548
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
using P = pair<int, int>;
using vec = vector<int>;
using mat = vector<vector<int>>;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define endl "\n"

constexpr int MOD = 1000000007;
const int INF = 1 << 30;

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

    int mx = max({a, b, c});
    mx *= 3;
    int d = mx - (a+b+c);
    int res = INF;
    if (d % 2 == 0) {
        res = min(res, d/2);
    }
    else {
        mx = max({a, b, c});
        mx++;
        mx *= 3;
        d = mx - (a+b+c);
        res = min(res, d/2);
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
	int n,i,j;
	cin>>n;
	double a[n];

	for(i=0;i<n;i++) cin>>a[i];
	double headsup[n+1]={0};
	headsup[0]=1;
	double sum=0;
	for(i=0;i<n;i++)
	{
		for(j=n;j>=0;j--)
		{
			if(j==0)
			{
				headsup[j]=headsup[j]*(1-a[i]);
				continue;
			}
			headsup[j]=headsup[j-1]*a[i]+headsup[j]*(1-a[i]);
		}
	}
	for(i=n/2+1;i<=n;i++)
	{
		sum+=headsup[i];
	}
	printf("%0.10lf\n", sum);
	return 0;

}


Measured memory_bytes: 384
def move(block, i, j, num, n, m)
  block[i][j] = 0
  results = []
  did = false
  [[0,-1],[1,0],[0,1],[-1,0]].each do |x,y|
    next if i+y < 0 || j+x < 0 || i+y >= n || j+x >= m
    if block[i+y][j+x] == 1
      did = true
      results << move(block, i+y, j+x, num+1, n, m)
    end
  end

  block[i][j] = 1
  if did 
    return results.max || 0
  else 
    return num
  end
end

loop do
  m = gets.chomp.to_i
  n = gets.chomp.to_i
  break if m == 0
  block = []
  n.times do
    block << gets.chomp.split(" ").map(&:to_i)
  end
  
  max = 0
  (0...n).each do |i|
    (0...m).each do |j|
      if block[i][j] == 1
        count = [move(block, i, j, 1, n, m), max]
        max = count.max
      end
    end
  end
  puts max
end



Measured memory_bytes: 6988
/*Made by Shivam Solanki*/
#include<bits/stdc++.h>
using namespace std;
#define DEBUG(x) cout << '>' << #x << ':' << x << endl;
#define ll long long int
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vll> vvl;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<pii> vp;
typedef vector<pll> vpll;
typedef map<int,int> mii;
typedef map<ll,ll> mll;
typedef set<int> sii;
typedef set<ll> sll;
typedef unordered_map<int,int> umii;
typedef unordered_map<ll,ll> umll;
#define rep(i,k,n) for (int i = k; i < n; ++i) 
#define repr(i,k,n) for (int i = n; i>=k; --i)
#define REP(i,k,n) for (int i = k; i <= n; ++i) 
#define REPR(i,k,n) for (int i = k; i >= n; --i)
#define repll(i,k,n) for (ll i = k; i < n; ++i) 
#define pb push_back
#define mp make_pair
#define __gcd gcd
#define F first
#define S second
#define fastio ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
const ll INF = 1e18+5;
const int MOD = 1e9+7;
 
void solve(){
    ll n;
    cin>>n;
    vector<pair<ll,ll>> a;
    for(ll i=1;i*i<=n;i++){
        if(n%i==0){
            a.pb({i,n/i});
        }
    }
    ll ctr=INF;
    rep(i,0,a.size()){
        ctr=min(ctr,a[i].F+a[i].S-2);
    }
    cout<<ctr;
}
 
int main(){
    // #ifndef ONLINE_JUDGE  
        // freopen("input.txt", "r", stdin); 
        // freopen("output.txt", "w", stdout); 
    // #endif 
    // fastio;
    int t=1;
    // cin>>t;
    while(t--)
        solve();
    return 0;
}

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

using namespace std;
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VL;
typedef vector<VL> VVL;
typedef pair<int, int> PII;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()
#define IN(a, b, x) (a <= x && x < b)
#define MP make_pair
#define PB push_back
#define MOD 1000000007
#define INF (1LL << 30)
#define LLINF (1LL << 60)
#define PI 3.14159265359
#define EPS 1e-12
//#define int ll

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

struct S {
  int x, p, v;
  double t;
  bool operator<(S s) const { return t > s.t; }
};

int main() {
  while (true) {
    int n, m;
    cin >> n >> m;
    if (!n && !m)
      break;
    int s, g;
    cin >> s >> g;
    int d[31][31];
    int l[31][31] = {};
    for (int i = 0; i < m; i++) {
      int x, y, di, c;
      cin >> x >> y >> di >> c;
      d[x][y] = d[y][x] = di;
      l[x][y] = l[y][x] = c;
    }
    bool p[31][31][31] = {};
    priority_queue<S> que;
    que.push({s, 0, 0, 0});
    while (!que.empty()) {
      S cs = que.top();
      if (cs.x == g && cs.v == 1)
        break;
      que.pop();
      if (p[cs.x][cs.p][cs.v]++)
        continue;
      for (int i = 0; i <= n; i++) {
        if (cs.p == i)
          continue;
        for (int j = -1; j <= 1; j++) {
          int nv = cs.v + j;
          if (nv <= 0 || l[cs.x][i] < nv)
            continue;
          que.push({i, cs.x, nv, cs.t + d[cs.x][i] * 1. / nv});
        }
      }
    }
    if (que.empty()) {
      cout << "unreachable" << endl;
    } else {
      cout << fixed << que.top().t << endl;
    }
  }
}

Measured memory_bytes: 21732
class abc_154:
    
    def __init__(self):
        pass
    
    def A(self):
        pass
    def B(self):
        pass
    def C(self):
        N=int(input())
        A=list(map(int,input().split()))
        B=list(set(A))
        
        ans= "YES" if len(A)==len(B) else "NO"
        print(ans)
                
    def D(self):
        pass
    def E(self):
        pass
    def F(self):
        pass
    
    
if __name__=='__main__':
    obj=abc_154()
    obj.C()

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

int main()
{
    /*collecting balls
    int n,k;
    cin>>n>>k;
    vector <int> x(n);
    for(int i=0;i<n;i++)
    {
        cin>>x[i];
    }
    int dist = 0;
    for(int i=0;i<n;i++)
    {
        int dist_part= min(x[i],abs(k-x[i]));
        dist+=dist_part*2;
    }
    cout<<dist<<endl;
    */
    int n;
    cin>>n;
    vector <int> a(n);
    rep(i,n)
    {
        cin>>a[i];
    }
    sort(a.rbegin(),a.rend());
    int alice=0;
    int bob = 0;
    for(int i=0;i<n;i++)
    {
        if(i%2==0)
        {
            alice += a[i];
        }
        else
        {
            bob += a[i];
        }
    }
    cout<<alice-bob<<endl;
    return 0;
}

Measured memory_bytes: 256
import sys

def solve():
    file_input = sys.stdin
    N, K = map(int, file_input.readline().split())
    
    G = [[] for i in range(10)]
    for line in file_input:
        c, g = map(int, line.split())
        G[g - 1].append(c)
    
    for genre in G:
        genre.sort(reverse=True)
        for p, i in zip(genre, range(1, len(genre))):
            genre[i] += p + 2 * i # Recording cumulative price
    
    C = [0] * (K + 1)
    for genre in G:
        pre_C = C.copy()
        for n, p in enumerate(genre, start=1):
            for i, vals in enumerate(zip(pre_C[n:], C)):
                v1, v2 = vals
                v1 += p
                if v1 > v2:
                    C[i] = v1
    print(C[0])

solve()


Measured memory_bytes: 5652
#include <iostream>
#include <cstdio>
#include <cstdlib>
using namespace std;

class Stack{
private:
  int size;
  int array[200];
public:
  Stack(){
    size = 0;
  }
  bool isEmpty();
  void push(int num);
  int pop();
};

bool Stack::isEmpty(){
  if(size == 0) return true;
  else return false;
}

void Stack::push(int num){
  array[size++] = num;
}

int Stack::pop(){
  return array[--size];
}

int main(void){ 
  Stack st;
  char s[100];
  while(scanf("%s", s) != EOF){
    if(s[0] == '+'){
      int a = st.pop();
      int b = st.pop();
      st.push(a + b);
    }else if(s[0] == '-'){
      int a = st.pop();
      int b = st.pop();
      st.push(b - a);
    }else if(s[0] == '*'){
      int a = st.pop();
      int b = st.pop();
      st.push(a * b);
    }else{
      st.push(atoi(s));
    }
  }
  cout << st.pop() << endl;
  return 0;
}



Measured memory_bytes: 3156
#include <bits/stdc++.h>
#define int long long
#define double long double
using namespace std;
#define SIZE 1000010
#define INF 1e18
vector<int> get_primes() {
  bool used[SIZE];
  for (int i = 0; i < SIZE; i++) used[i]=0;
  vector<int> primes;
  for (int i = 2; i*i < SIZE; i++) {
    if (!used[i]) {
      used[i] = 1;
      primes.push_back(i);
      for (int j = i*2; j*j < SIZE; j+=i) {
        used[j] = 1;
      }
    }
  }
  return primes;
}

vector<int> get_divisor(int N) {
  vector<int> divisor;
  vector<int> primes = get_primes();
  while (N != 1) {
    for (int i = 0; i < primes.size(); i++) {
      if (N % primes[i] == 0 && N != primes[i]) {
        divisor.push_back(primes[i]);
        N /= primes[i];
        break;
      }
    }
  }
  return divisor;
}

signed main() {
  int N; cin >> N;
  int ans = N-1;
  for (int i = 2; i*i <= N; i++) {
    if (N % i == 0) {
      ans = min(ans, i+ (N/i) -2);
    }
  }
  cout << ans << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << endl;
#define CFYN(n) cout << ( (n) ? "YES":"NO") << endl;
#define out(n) cout << (n) << endl;
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;

int main(void)
{
    IOS
    string s; cin >> s;
    int x, y;
    cin >> x >> y;

    vector<int> vx,vy;
    int tcount = 0;
    int fcount = 0;
    REP(i,s.size()+1) {
        if (i == s.size() || s[i] == 'T') {
            if (tcount % 2 == 0) vx.push_back(fcount);
            else vy.push_back(fcount);
            tcount++;
            fcount = 0;
        } else {
            fcount++;
        }
    }

    vector<set<int>> dpx(vx.size()+1),dpy(vy.size()+1);
    dpx[0].insert(0);
    dpy[0].insert(0);
    
    REP(i,vx.size()) {
        //set<int> tmp;
        //swap(dpx,tmp);
        // for(auto m:tmp) {
        //     dpx.insert(m+vx[i]);
        //     if (i != 0) dpx.insert(m-vx[i]);
        // }
        for(auto m:dpx[i]) {
            dpx[i+1].insert(m+vx[i]);
            if (i != 0) dpx[i+1].insert(m-vx[i]);
        }
    }

    REP(i,vy.size()) {
        //set<int> tmp;
        //swap(dpy,tmp);
        // for(auto m:tmp) {
        //     dpy.insert(m+vy[i]);
        //     dpy.insert(m-vy[i]);
        // }
        for(auto m:dpy[i]) {
            dpy[i+1].insert(m+vy[i]);
            dpy[i+1].insert(m-vy[i]);
        }
    }
    
    //ATYN(dpx.find(x) != dpx.end() && dpy.find(y) != dpy.end())
    ATYN(dpx[vx.size()].find(x) != dpx[vx.size()].end() &&
         dpy[vy.size()].find(y) != dpy[vy.size()].end())

    return 0;
}

Measured memory_bytes: 232320
#include <stdio.h>
#include <string.h>

int main(){

  int i, len;
  char s[100010], ans[100010];

  scanf("%s", s);

  len=strlen(s);
  for(i=0;i<len;i+=2){
    ans[i/2]=s[i];
  }

  puts(ans);
  return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
struct point{int x;int y;};
int i,j,k,count1=0,count2=0;

int main(){
    int a[3][3];
    for(i=0;i<3;i++){
        for(j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    int hanbetu=0,a1,a2,a3,b1,b2,b3;
    for(i=0;i<=100;i++){
        a1=i;
        b1=a[0][0]-a1;
        b2=a[0][1]-a1;
        b3=a[0][2]-a1;
        for(j=0;j<=100;j++){
            a2=j;
            if(b1==a[1][0]-a2&&b2==a[1][1]-a2&&b3==a[1][2]-a2){
                for(k=0;k<=100;k++){
                    a3=k;
                    if(b1==a[2][0]-a3&&b2==a[2][1]-a3&&b3==a[2][2]-a3){
                        cout<<"Yes"<<endl;
                        return 0;
                    }
                }
            }
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
#define rep(i,n)for(int i=0;i<(int)(n);i++)
#define PI 3.141592653589793
//vector < vector<int>>a(0, vector<int>(0));二次元配列宣言


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

	vector<int>h(n);
	int i;
	int cnt = 0;
	for (i = 0; i < n; i++)
	{
		cin >> h.at(i);
		if (h.at(i) >= k)
			cnt++;
	}
	cout << cnt << endl;
	
}

Measured memory_bytes: 3788
# -*- coding: utf-8 -*-

def solve(S):
    count = 0
    mark = S[0]
    for i in range(1, len(S)):
        if(S[i] == mark):
            continue
        else:
            mark = S[i]
            count += 1
    print(count)
    
if __name__ == '__main__':
    S = list(input())
    
    solve(S)

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

#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define vi vector<int>

#define ll long long
#define vl vector<ll>
#define vll vector<vl>
#define P pair<ll, int>

const int INF = 1e9;
const long double pi=3.14159265358979323846;

#define E pair<int, ll>

int main() {
	vector<E> edge[100010];
	int n, m;
	cin >> n >> m;
	int l[100010], r[100010];
	ll c[100010];
	rep(i, m)
	{
		cin >> l[i] >> r[i] >> c[i];
		l[i]--;
		r[i]--;
		edge[l[i]].push_back(E(r[i], c[i]));
	}
	rep(i, n-1) edge[i+1].push_back(E(i, 0));

	/*rep(i, n)
	{
		rep(j, edge[i].size())
		{
			cout << '(' << edge[i][j].first+1 << ',' << ' ' << edge[i][j].second << ' ';
		}
		cout << endl;
	}*/

	ll d[100010];
	d[0]=0;
	rep(i, n-1) d[i+1]=100000000000000000;
	priority_queue<P, vector<P>, greater<P>> q;
	rep(i, n) q.push(P(d[i], i));

	while(!q.empty())
	{
		P x=q.top();
		q.pop();
		int from=x.second;
		rep(i, edge[from].size())
		{
			int to=edge[from][i].first;
			ll w=edge[from][i].second;
			if(d[to]>d[from]+w)
			{
				d[to]=d[from]+w;
				q.push(P(d[to], to));
			}
		}
	}
	//rep(i, n) cout << d[i] << ' ';
	if(d[n-1]==100000000000000000) cout << "-1" << endl;
	else cout << d[n-1] << endl;
	return 0;
}

Measured memory_bytes: 15476
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cassert>
#include <algorithm>
#include <functional>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <vector>
#define repi(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i,a) repi(i,0,a)
#define repdi(i,a,b) for(ll i=(a)-1;i>=(b);--i)
#define repd(i,a) repdi(i,a,0)
#define itr(it,a) for( auto it = (a).begin(); it != (a).end(); ++it )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
#define endl '\n'
#define debug(x) std::cerr << #x << " = " << (x) << endl;

using ll = long long;
using P = std::pair<ll, ll>;

constexpr ll INF = 1ll<<60;

template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

template<class S, class T>
std::ostream& operator<< ( std::ostream& out, const std::pair<S,T>& a )
{ std::cout << '(' << a.first << ", " << a.second << ')'; return out; }

template<class T>
std::ostream &operator<< ( std::ostream& out, const std::vector<T>& a )
{ std::cout << '['; rep( i, a.size() ){ std::cout << a[i]; if( i != a.size()-1 ) std::cout << ", "; } std::cout << ']'; return out; }

ll N;
ll x[110], y[110], h[110];

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

  rep( i, N )
    std::cin >> x[i] >> y[i] >> h[i];

  rep( i, 101 ) rep( j, 101 ) {
    ll prv = INF;
    bool enter = false;

    rep( k, N ) {
      ll height = llabs(i-x[k])+llabs(j-y[k])+h[k];

      if( prv != INF && ((h[k] && enter && prv != height) || (!h[k] && enter && prv > height)) )
        goto end;
      
      if( !h[k] && !enter )
        chmin( prv, height );
      if( !h[k] && enter ) {
        if( prv > height )
          goto end;
      }
      if( h[k] ) {
        if( prv != INF && prv < height )
          goto end;

        prv = height;
        enter = true;
      }
    }

    std::cout << i << ' ' << j << ' ' << prv << endl;

end:;
  }

  return 0;
}

Measured memory_bytes: 3568
#include <iostream>
#include <list>

using namespace std;

bool dpx[8000][16001];
bool dpy[8000][16001];
int f[8000];

int main(int argc, char *argv[]) {
	string s;
	int x, y;
	cin >> s >> x >> y;

	int idx = 0;
	for (char &c : s) {
		if (c == 'F') f[idx]++;
		else idx++;
	}
	idx++;

	dpx[1][8000 + f[0]] = true;

	for (int i = 1; 2 * i < idx; i++) {
		for (int j = 0; j < 16001; j++) {
			if (dpx[i][j]) {
				dpx[i + 1][j + f[2 * i]] = true;
				dpx[i + 1][j - f[2 * i]] = true;
			}
		}
	}

	dpy[0][8000] = true;
	for (int i = 0; 2 * i < idx; i++) {
		for (int j = 0; j < 16001; j++) {
			if (dpy[i][j]) {
				dpy[i + 1][j + f[2 * i + 1]] = true;
				dpy[i + 1][j - f[2 * i + 1]] = true;
			}
		}
	}

	if (dpx[(idx + 2 - 1) / 2][x + 8000] && dpy[idx / 2][y + 8000])
		cout << "Yes" << endl;
	else
		cout << "No" << endl;
	return 0;
}

Measured memory_bytes: 125696
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

namespace Practice
{
    class Program
    {
        static void Main(string[] args)
        {
            Solve();
        }
        private const long MOD = 1000000007;
        static void Solve()
        {
            var o = ReadAndParseIntArr();
            int n = o[0];
            int l = o[1];
            var s = new string[n];
            for(int i=0;i<n;++i)
            {
                s[i] = Console.ReadLine();
            }

            var list = new List<string>(s);
            list.Sort();
            var sb = new StringBuilder();
            foreach( var si in list)
            {
                sb.Append(si);
            }
            string ans = sb.ToString();
            Console.WriteLine(ans);
        }
        
        #region よく使う便利関数
        private static bool isPrime(long x)
        {
            if (x == 2) { return true; }
            if (x < 2 || x % 2 == 0) { return false; }
            long i = 3;
            while (i * i <= x)
            {
                if (x % i == 0) { return false; }
                i = i + 2;
            }
            return true;
        }
        private static long lcm(long x, long y)
        {
            return x / gcd(x, y) * y;
        }
        private static long gcd(long x, long y)
        {
            return y > 0 ? gcd(y, x % y) : x;
        }
        private static long pow(long x, long n)
        {
            if (n == 0) { return 1; }
            long res = pow(x * x % MOD, n / 2);
            if (n % 2 == 1)
            {
                res = res * x % MOD;
            }
            return res;
        }
        private static int ReadAndParseInt()
        {
            return int.Parse(Console.ReadLine());
        }
        private static int[] ReadAndParseIntArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), int.Parse);
        }
        private static long ReadAndParseLong()
        {
            return long.Parse(Console.ReadLine());
        }
        private static long[] ReadAndParseLongArr()
        {
            return Array.ConvertAll(Console.ReadLine().Split(' '), long.Parse);
        }
        #endregion
    }
}

Measured memory_bytes: 13408
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>
#include<vector>
#include<functional>
#include<algorithm>
#include<stdlib.h>
#include<string>
#include<string.h>
#define _USE_MATH_DEFINES
#include<math.h>
#include<deque>
#include<set>
#include<map>
#include<queue>
#include<list>
#include<iostream>
#include <bitset>
using namespace std;
typedef long long ll;
#define rep(i,a,b) for(auto i=a;i<b;i++)
#define all(_x) _x.begin(), _x.end()
#define r_sort(_x) sort(_x.begin(), _x.end(), std::greater<int>())
#define vec_cnt(_a, _n) (upper_bound(all(_a), _n) - lower_bound(all(_a), _n))
#define vec_unique(_a) _a.erase(std::unique(all(_a)), _a.end());
#define vvec vector<vector<ll>>
ll gcd(ll a, ll b) { return a % b == 0 ? b : gcd(b, a % b); }
ll lcm(ll a, ll b) { return (a / gcd(a, b)) * b; }
#define INF 1 << 30
const int mod = 1000000007;
ll power(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x *= x; p /= 2; } else { a *= x; p--; } }return a; }
ll mpower(ll x, ll p) { ll a = 1; while (p > 0) { if (p % 2 == 0) { x = x * x % mod; p /= 2; } else { a = a * x % mod; p--; } }return a; }
ll c(ll n, ll k) { ll a = 1; rep(i, 1, k) { a *= n - i + 1; a /= i; }return a; }
ll mc(ll n, ll m) { ll k = 1, l = 1; rep(i, n - m + 1, n + 1) k = k * i % mod; rep(i, 1, m + 1) l = l * i % mod; l = mpower(l, mod - 2); return k * l % mod; }

#define COMB_MAX (int)1e6 + 10
ll f[COMB_MAX], rf[COMB_MAX];
ll inv(ll x) {
	ll res = 1;
	ll k = mod - 2;
	ll y = x;
	while (k) {
		if (k & 1) res = (res * y) % mod;
		y = (y * y) % mod;
		k /= 2;
	}
	return res;
}
void init() {
	f[0] = 1;
	rep(i, 1, COMB_MAX) f[i] = (f[i - 1] * i) % mod;
	rep(i, 0, COMB_MAX) rf[i] = inv(f[i]);
}
//---------------------------------------------------------------------------------------------------
ll C(int n, int k) {
	if (k<0 || k>n || n < 0)return 0;
	ll a = f[n]; // = n!
	ll b = rf[n - k]; // = (n-k)!
	ll c = rf[k]; // = k!

	ll bc = (b * c) % mod;

	return (a * bc) % mod;
}
int main(void) {
	int n, k;
	ll ans = 0;
	cin >> n >> k;
	if (k >= n - 1) {
		ans = mc(2 * n - 1, n);
	}
	else {
		init();
		rep(i, 0, k + 1) {
			ans += C(n, i) * C(n - 1, i) % mod;
			ans %= mod;
		}
	}
	printf("%lld\n", ans);
	return 0;
}


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

int main() {
	char a;
	string b;
	rep(i, 8) {
		cin >> a;
	}
	cin >> b;
	cout << "2018/01/" << b << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
//#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1010000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)}; 

signed main() {
  int a,b;cin>>a>>b;
  if(b%a==0)cout << a+b << endl;
  else cout << b-a << endl;
}


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

#define REP(i,x,y) for(int i=(x);i<(y);i++)
#define RREP(i,x,y) for(int i=(y)-1;i>=(x);i--)
#define all(x) (x).begin(),(x).end()
// #define int long long

using namespace std;

// conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

#ifdef LOCAL
#define eprintf(...) fprintf(stderr, __VA_ARGS__)
#define dump(x)  cerr << #x << " = " << (x) << endl
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl
#else
#define eprintf(...) 42
#define dump(x) 42
#define debug(x) 42
#endif

typedef long long ll;

const ll MOD = 1e9 + 7;

void solve(int N, int K, vector<int>& A) {
    vector<vector<bool>> dp(2, vector<bool>(K)); // dp[0: Taro, 1: Jiro][k] =  true: Taro wins
    dp[0][0] = false;
    dp[1][0] = true;
    REP(k,1,K+1) {
        // Taro
        for (const auto a : A) {
            if (k-a >= 0 && dp[1][k-a]) {
                dp[0][k] = true;
                break;
            }
            dp[0][k] = false;
        }
        // Jiro
        for (const auto a : A) {
            if (k-a >= 0 && !dp[0][k-a]) {
                dp[1][k] = false;
                break;
            }
            dp[1][k] = true;
        }
    }

	string answer = dp[0][K] ? "First" : "Second";
	stringstream ss;
	ss << answer;
	cout << ss.str() << '\n';

    return;
}

signed main() {
    int N, K;
    cin >> N >> K;
    
    vector<int> A(N);
    REP(i,0,N) cin >> A[i];
    
    solve(N, K, A);
    
    return 0;
}



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

int main(){
    int a,b,c,d;
    cin >> a >> b >> c >> d;
    int ans = 0;
    for (int i = 0; i <= 100; i ++){
        if (a <= i && i <= b && c <= i && i <= d ){
            ans ++;
        }
    }
    if(ans != 0)    ans --;
    cout << ans << endl;
}	

Measured memory_bytes: 256
N = int(input())
plus = []
for _ in range(N):
    plus.append(input())
M = int(input())
minus = []
for _ in range(M):
    minus.append(input())
def counter(array):
    from collections import Counter
    return list(Counter(array).most_common())
plus = counter(plus)
minus = counter(minus)
ans = 0
for x in plus:
    for y in minus:
        if x[0] == y[0]:
            ans = max(ans,x[1] - y[1])
            break
    else:
        ans = max(ans,x[1])
print(ans)


Measured memory_bytes: 3316
#include <bits/stdc++.h>
#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
#define int long long
typedef long long ll;
const int MOD = 1000000007;
const int INF = 1100000000;
const double EPS = 1e-10;
using namespace std;
const pair<int,int> fd[] = {make_pair(1,0),make_pair(-1,0),make_pair(0,1),make_pair(0,-1)};
const int max_n = 1 << 20;

int d[310][310];int t[310][310];int qs[1000000], qt[1000000];
signed main() {
	int n,m,l;cin>>n>>m>>l;
  rep(i,n)rep(j,n)d[i][j] = INF;
  rep(i,n)d[i][i] = 0;
  rep(i,m){
    int a,b,c;cin>>a>>b>>c;a--;b--;d[a][b] = d[b][a] = c;
  }
  int q;cin>>q;
  rep(i,q){
    cin>>qs[i]>>qt[i];qs[i]--;qt[i]--;
  }
  rep(k,n){
    rep(i,n){
      rep(j,n)d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
    }
  }
  rep(i,n)rep(j,n)t[i][j] = INF;
  rep(i,n)t[i][i] = 0;
  rep(i,n){
    rep(j,n){
      if(d[i][j] <= l)t[i][j] = 1;
    }
  }
  rep(k,n){
    rep(i,n){
      rep(j,n)t[i][j] = min(t[i][j], t[i][k] + t[k][j]);
    }
  }
  rep(i,q)cout << (t[qs[i]][qt[i]] == INF ? -1 : t[qs[i]][qt[i]]-1) << endl;

}



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

using namespace std;

using ll = long long;

ll MAX_N = 1e5;
vector<vector<ll> > graph(MAX_N);
vector<bool> visited(MAX_N);

// ALDS1_11_B
vector<ll> d(MAX_N);
vector<ll> f(MAX_N);
ll t = 0;

// O(E)
void dfs(ll u){
    visited[u] = true;
    // visit v
    d[u] = ++t;
    for(ll v: graph[u]){
        if(!visited[v]){
            dfs(v);
        }
    }
    f[u] = ++t;
}

// ALDS1_11_B: verified
int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    ll n; cin >> n;
    for(ll i=0;i<n;i++){
        ll u, k; cin >> u >> k;
        vector<ll> vs;
        for(ll j=0;j<k;j++){
            ll v; cin >> v;
            vs.push_back(v);
        }
        sort(vs.begin(), vs.end());
        for(ll j=0;j<k;j++){
            ll v = vs[j];
            graph[u - 1].push_back(v - 1);
        }
    }
    for(int i=0;i<n;i++){
        if(!visited[i]) dfs(i);
    }
    for(int i=0;i<n;i++) cout << i + 1 << " " << d[i] << " " << f[i] << endl;
}



Measured memory_bytes: 6636
import Data.List(sort,group)
import Control.Monad(forM_)

main = do
  ns <- fmap (fmap (read :: String -> Int) . words) . lines <$> getContents
  let n = head $ head ns
  let ls = group $ sort $ concat $ tail ns
  let res = reverse $ solve n ls
  forM_ res putStrLn

solve :: Int -> [[Int]] -> [String]
solve 0 ls = []
solve n ls =  makeAns n ls : solve (subtract 1 n) ls

makeAns :: Int -> [[Int]] -> String
makeAns n ls
  | elem n $ concat ls = show $ length $ head $ filter (\ns -> head ns == n) ls
  | otherwise = "0"

Measured memory_bytes: 1020
n = int(input())
val = [int(x) for x in input().split()]

ans = 1
for i in range(n):
    ans *= val[i]
    if(ans > 1e18):
        ans = -1
        break

if(ans == -1):
    for i in range(n):
        if(val[i] == 0):
            ans = 0
            break
print(ans) 


Measured memory_bytes: 21676
#define _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <numeric>
#include <set>
#include <unordered_set>
#include <map>
#include <unordered_map>
#include <string>
#include <iterator>
#include <cmath>
#include <deque>
#include <stack>
#include <functional>
#include <queue>
using namespace std;



signed main()
{
    {
        if (fopen("input.txt", "r")) {
            freopen("input.txt", "r", stdin);
            freopen("output.txt", "w", stdout);
        }
        ios_base::sync_with_stdio(false);
        cin.tie(NULL);
        cout.tie(NULL);
    }

    int n, k;
    cin >> n >> k;
    int ans = 0;
    while (n > 0) {
        n /= k;
        ++ans;
    }
    cout << ans;
	return 0;
}

Measured memory_bytes: 256
INF=10**50

def Bellman_Ford(s,N,Edge):
    dist=[INF]*N
    dist[s]=0
    for i in range(N-1):
        for f,t,c in Edge:
            if dist[f]!=INF and dist[t]>dist[f]+c:
                dist[t]=min(dist[t],dist[f]+c)
    F=[False]*N
    for j in range(N):
        for f,t,c in Edge:
            if(dist[t]>dist[f]+c):
                dist[t]=dist[f]+c
                F[t]=True
    if F[N-1]:
        return 'inf'
    else:
        return -dist[N-1]
    
N,M=map(int,input().split())
Edge=[]
for i in range(M):
    a,b,c=map(int,input().split())
    a,b,c=a-1,b-1,-c
    Edge.append([a,b,c])
print(Bellman_Ford(0,N,Edge))

Measured memory_bytes: 47064
#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=998244353;

long long modpow(long long a, long long n) {
    long long res = 1LL;
    while (n > 0) {
        if (n & 1LL) res = res * a % mod;
        a = a * a % mod;
        n >>= 1LL;
    }
    return res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll d[n];
    ll a[n];
    for(int i=0;i<n;i++){
        a[i]=0LL;
    }
    for(ll i=0LL;i<n;i++){
        cin>>d[i];
        a[d[i]]++;
    }
    ll ans=1LL;
  if(d[0]!=0){cout<< 0<<endl;
        return 0;}
    if(a[0]!=1LL){
        cout<< 0<<endl;
        return 0;
    }
    bool maki=true;
    for(ll i=0LL;i<n;i++){
        if(a[i]==0LL){
            maki=false;
        }
        else{
            if(maki){
                if(i){
                    ans*=modpow(a[i-1],a[i]);
                    ans%=mod;
                }
            }
            else{
              cout<< 0<<endl;
              return 0;  
            }
            
        }
    }
    cout << ((ans%mod)+mod)%mod<<endl;
    return 0;
}


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

typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> ii;
typedef tuple<ll, ll, ll> iii;
typedef vector<ll> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
#define REP(i,n) for (ll i = 0; i < n; ++i)
#define REPR(i,n) for (ll i = n-1; i >= 0; --i)
#define FOR(i,m,n) for (ll i = m; i < n; ++i)
#define FORR(i,m,n) for (ll i = n-1; i >= m; --i)
#define FORE(x,xs) for (const auto& x : xs)
#define ALL(v) v.begin(), v.end()

const int MAX = 5010;

int K, Q;
ll D[MAX];

ll solve(ll N, ll X, ll M) {
    ll all = N - 1;
    ll a_n = X % M;
    ll sm = 0;
    REP (i, K) {
        ll n = (N-1) / K;
        if (i < (N-1) % K) n++;
        a_n += (D[i] % M) * n;
        if (D[i] % M == 0) sm += n;
    }
    all -= sm + a_n / M;
    return all;
}

int main() {
    cin >> K >> Q;
    REP (i, K) cin >> D[i];
    REP (i, Q) {
        int n, x, m;
        cin >> n >> x >> m;
        cout << solve(n, x, m) << endl;
    };
}

Measured memory_bytes: 384
#include <iostream>
#include <algorithm>
#include <set>
#include <cstdio>

#define MAXNT 110

#define lengthof(x) (sizeof(x) / sizeof(*(x)))

using namespace std;

int main(int argc, char const *argv[])
{
	int n,t,l,b;
	double dp[MAXNT][MAXNT];

	while(1){
		cin>>n>>t>>l>>b;
		if(n+t+l+b==0) break;

		fill((double *)dp,(double *)(dp+lengthof(dp)),0);

		int temp;
		set<int> sl;
		set<int> sb;
		for(int i1=0;i1<l;i1++){
			cin>>temp;
			sl.insert(temp);
		}

		for(int i1=0;i1<b;i1++){
			cin>>temp;
			sb.insert(temp);
		}

		dp[0][0]=1.0;
		for(int i1=0;i1<t;i1++){
			for(int i2=0;i2<n;i2++){
				if(dp[i1][i2]>0) {
					for(int i3=1;i3<7;i3++){
						temp=i2+i3;
						if(temp>n) temp=2*n-i2-i3;

						if(!sl.empty() && sl.find(temp)!=sl.end()) {
							dp[i1+2][temp]+=(dp[i1][i2]*1.0/6);
						}
						else if(!sb.empty() && sb.find(temp)!=sb.end()) {
							dp[i1+1][0]+=(dp[i1][i2]*1.0/6);
						}
						else dp[i1+1][temp]+=(dp[i1][i2]*1.0/6);
					}
				}
			}
		}

		double sum=0.0;
		for(int i1=1;i1<=t;i1++){
			sum+=dp[i1][n];
		}

		printf("%0.6f\n",sum);
	}
	return 0;
}

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

int main(void){

  int N, K;
  cin >> N >> K;
  vector<int> l(N);
  for (int i=0; i<N; i++) cin >> l[i];

  int sum = 0;
  sort( (l).begin(), (l).end() );
  for (int i=0; i<K; i++){
    sum  += l[N-i-1];
  }

  cout << sum << "\n";
}


Measured memory_bytes: 3592
fun main() {
    val (n, k) = readLine()!!.split(" ").map { it.toInt() }
    val list = readLine()!!.split(" ").map { it.toInt() }.sorted()
    var sum = 0
    for ((index, p) in list.withIndex()) {
        if (index in 0 until k) {
            sum += p
        }
    }
    println(sum)
}

Measured memory_bytes: 40696
import collections
def nCr(n, r):
    """
    Calculate the number of combination (nCr = nPr/r!).
    The parameters need to meet the condition of n >= r >= 0.
    It returns 1 if r == 0, which means there is one pattern
    to choice 0 items out of the number of n.
    """
 
    # 10C7 = 10C3
    r = min(r, n-r)
 
    # Calculate the numerator.
    numerator = 1
    for i in range(n, n-r, -1):
        numerator *= i
 
    # Calculate the denominator. Should use math.factorial?
    denominator = 1
    for i in range(r, 1, -1):
        denominator *= i
 
    return numerator // denominator
 
N = int(input())
Sum = 0
lists = []
for i in range(N):
    s = str(input())
    s_list = list(s)
    s_list.sort()
    m = "".join(s_list)
    lists.append(m)
c = collections.Counter(lists)
set_lists = list(set(lists))
for i in range(len(set_lists)):
    cnt = c[str(set_lists[i])]
    if cnt == 1:
        pass
    else:
        Sum += nCr(cnt,2)
print(Sum)

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

using namespace std;
using ll = long long;
const ll INF = 1e18;

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

    vector<int> broken(M);
    for(int i=0; i<M; i++)cin >> broken.at(i);

    vector<ll> dp(N+1,0);
    dp.at(0) = 1;
    for(int i=1; i<=N; i++){
        if(binary_search(broken.begin(), broken.end(), i)){
            dp.at(i) = 0;
        }else{
            dp.at(i) += dp.at(i-1);
            if(i>1)dp.at(i) += dp.at(i-2);
        }

        dp.at(i) %= 1000000007;
    }

    // for(int i=0; i<=N; i++){
    //     cout << i << ": " << dp.at(i) << endl;
    // }

    cout << dp.at(N) << endl;
}

Measured memory_bytes: 4540
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <random>
#include <cmath>
#include <set>

#define ll unsigned long long
#define p(a, b) pair<a,b>

using namespace std;

//ifstream cin("Input.txt");
//ofstream cout("Output.txt");

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    if (n == 1) {
        cout << "Hello World";
    } else {
        int a, b;
        cin >> a >> b;
        cout << a + b;
    }
    return 0;
}

Measured memory_bytes: 256
def next(n):
    s = [int(i) for i in str(n)]
    l = len(s)
    if l == 1:
        return n + 1
    ans = s
    for i in range(l - 1):
        if s[-i - 1] <= s[-i - 2] and s[-i - 1] != 9:
            ans = s[:-i - 1]
            ans.append(s[-i - 1] + 1)
            for j in range(i):
                if ans[-1] == 0:
                    ans.append(0)
                else:
                    ans.append(ans[-1] - 1)
            return int(''.join([str(i) for i in ans]))
    if s[0] == 9:
        return n + 1
    ans = [s[0] + 1]
    for j in range(l - 1):
        if ans[-1] == 0:
            ans.append(0)
        else:
            ans.append(ans[-1] - 1)
    return int(''.join([str(i) for i in ans]))


K = int(input())
ans = 1
for i in range(K - 1):
    ans = next(ans)
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h>
// Copy Korte ascho tai nah //
#define CASE(t)                 printf("Case %d: ",t)
#define gcd(a,b)                __gcd(a,b)
#define lcm(a,b)                ((a)*(b))/gcd(a,b)
#define PI                      2*acos(0.0)
#define ll                      long long int
//MD.JAHIR RAYHAN  , 11th batch CSE ,ID : 11908028 , Comilla University (2018-2019) :
//Email : rayhanlabib7@gmail.com, Phone : 01637809651.
using namespace std;
int main()
{
string s;
int i;
cin>>s;
for(i=0;i<s.size();i++)
{
    if(s[0]=='R')
    {
        cout<<"Sunny"<<endl;
        return 0;
    }
    else if(s[0]=='C')
    {
        cout<<"Rainy";
        return 0;
    }
    else if(s[0]=='S')
    {
        cout<<"Cloudy"<<endl;
        return 0;
    }
}

return 0;
}




Measured memory_bytes: 256
#include<stdio.h>
using namespace std;
#define LL long long
LL a[100005];
int main()
{
    int k;
    scanf("%d",&k);
    for(int i=0;i<k;i++) scanf("%lld",&a[i]);
    LL mx=2,mn=2;
    for(int i=k-1;i>=0;i--){
        if(mn%a[i]!=0) mn=(mn/a[i]+1)*a[i];
        mx=(mx/a[i]+1)*a[i]-1;
    }
    if(mx<=mn) printf("-1\n");
    else printf("%lld %lld\n",mn,mx);
    return 0;
}


Measured memory_bytes: 896
#include <iostream>
#include <string>

using namespace std;

int main() {

  string str;
  string temp;
  int JOIcount,IOIcount;

  string::size_type index;


  while(getline(cin,str)) {

    index=0;
    JOIcount=0;
   
    temp=str;

    while(1) {

      index=temp.find("JOI");

      if(index==string::npos) break;

      temp=temp.substr(index+1,temp.length());

      JOIcount++;

    }

    index=0;
    IOIcount=0;

    temp=str;

    while(1) {

      index=temp.find("IOI");

      if(index==string::npos) break;

      temp=temp.substr(index+1,temp.length());

      IOIcount++;

    }

    cout << JOIcount << "\n" << IOIcount << endl;
    
  }

  return 0;

}

Measured memory_bytes: 0
#include <iostream>
#include <string>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <algorithm>
#include <queue>
#include <stack>
#include <functional>
#include <bitset>
#include <assert.h>
#include <unordered_map>
#include <fstream>
#include <ctime>
#include <complex>
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef vector<char> vc;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<double> vd;
typedef pair<ll,ll> P;
typedef pair<int,int> pii;
typedef vector<P> vpl;
typedef tuple<ll,ll,ll> tapu;
#define rep(i,n) for(int i=0; i<(n); i++)
#define REP(i,a,b) for(int i=(a); i<(b); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
const int inf = 1<<30;
const ll linf = 1LL<<62;
const int MAX = 510000;
ll dy[8] = {1,-1,0,0,1,-1,1,-1};
ll dx[8] = {0,0,1,-1,1,-1,-1,1};
const double pi = acos(-1);
const double eps = 1e-7;
template<typename T1,typename T2> inline bool chmin(T1 &a,T2 b){
	if(a>b){
		a = b; return true;
	}
	else return false;
}
template<typename T1,typename T2> inline bool chmax(T1 &a,T2 b){
	if(a<b){
		a = b; return true;
	}
	else return false;
}
template<typename T> inline void print(T &a){
    rep(i,a.size()) cout << a[i] << " ";
    cout << "\n";
}
template<typename T1,typename T2> inline void print2(T1 a, T2 b){cout << a << " " << b << "\n";}
template<typename T1,typename T2,typename T3> inline void print3(T1 a, T2 b, T3 c){
	cout << a << " " << b << " " << c << "\n";
}
ll pcount(ll x) {return __builtin_popcountll(x);}
const int mod = 1e9 + 7;
//const int mod = 998244353;

int main(){
	while(1){
		int n,m,L,k,a,h;
		cin >> n >> m >> L >> k >> a >> h;
		if(n+m+L+k+a+h == 0) break;
		vb reitou(n,false);
		rep(i,L){
			int tmp; cin >> tmp;
			reitou[tmp] = true;
		}
		vector<vector<pii>> G(n);
		rep(i,k){
			int x,y,t; cin >> x >> y >> t;
			G[x].emplace_back(y,t);
			G[y].emplace_back(x,t);
		}
		priority_queue<tapu,vector<tapu>,greater<tapu>> pq;
		pq.emplace(0,0,a);
		vvl d(n,vl(m+1,inf));
		d[a][0] = 0;
		while(!pq.empty()){
			ll cost, use, u;
			tie(cost, use, u) = pq.top(); pq.pop();
			if(d[u][use] < cost) continue;
			for(auto v : G[u]){
				int nxt = v.second + use;
				if(v.second + use <= m){
					rep(i,nxt+1){
						if(i && !reitou[v.first]) break;
						if(chmin(d[v.first][nxt-i], cost + v.second + i)){
							pq.emplace(d[v.first][nxt-i], nxt-i, v.first);
						}
					}
				}
			}
		}
		int ans = inf;
		rep(i,m+1) chmin(ans, d[h][i]);
		if(ans == inf) puts("Help!");
		else cout << ans << "\n";
	}
}


Measured memory_bytes: 3824
n = int(input())
A = list(map(int, input().split()))
B = list(map(int, input().split()))
diff = [0] * n

ans = 0
com = 0

for i in range(n):
    diff[i] = A[i] - B[i]
    if A[i] - B[i] < 0:
        ans += 1
        com += A[i] - B[i]

if com == 0:
    print(0)
    exit()

diff.sort()
d = -1
while d >= -1 * n and diff[d] > 0:
    ans += 1
    com += diff[d]
    d -= 1
    if com >= 0:
        print(ans)
        break
else:
    print(-1)

Measured memory_bytes: 18792
using System;
using System.Collections.Generic;
using System.Linq;
using static Input;
using NX = System.Int64;


public class Prog
{
    public static void Solve()
    {
        int A = NextInt();
        int B = NextInt();
        Console.WriteLine(6 - A - B);
    }
    public static long RepPow(long x, long p, long m = 1000000007)
    {
        if (p == 0) return 1;
        if (p == 1) return x % m;
        long b = RepPow(x, p / 2, m) % m;
        if (p % 2 == 0) { return (b * b) % m; }
        else { return (x * ((b * b) % m)) % m; }
    }
    public static void Main()
    {
        var sw = new System.IO.StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
        Console.SetOut(sw);
        Solve();
        Console.Out.Flush();
        return;
    }
}
public class Input
{
    public const long MOD = 1000000007;
    public const int INF = 1000000007;
    private static Queue<string> q = new Queue<string>();
    private static void Confirm() { if (q.Count == 0) foreach (var s in Console.ReadLine().Split(' ')) q.Enqueue(s); }
    public static int NextInt() { Confirm(); return int.Parse(q.Dequeue()); }
    public static long NextLong() { Confirm(); return long.Parse(q.Dequeue()); }
    public static string NextString() { Confirm(); return q.Dequeue(); }
    public static double NextDouble() { Confirm(); return double.Parse(q.Dequeue()); }
    public static int[] LineInt() { return Console.ReadLine().Split(' ').Select(int.Parse).ToArray(); }
    public static long[] LineLong() { return Console.ReadLine().Split(' ').Select(long.Parse).ToArray(); }
    public static string[] LineString() { return Console.ReadLine().Split(' ').ToArray(); }
    public static double[] LineDouble() { return Console.ReadLine().Split(' ').Select(double.Parse).ToArray(); }
    public long Abs(long a, long b) => Math.Abs(a - b);
}


Measured memory_bytes: 13268
#include<bits/stdc++.h>
typedef long long int ll;
using namespace std;
#define MAXN 200005
#define X first
#define Y second
#define MOD 998244353
#define inf 1e18
#define pb push_back
#define fastio ios_base::sync_with_stdio(false);cout.tie(0);cin.tie(0);
ll n,i,j,t;

int main()
{
    fastio;
    string s;
    cin>>s;
    n=s.length();
    ll a=n/2;
    ll cnt=0;
    a--;
    for(i=0;i<=a;i++){
        if(s[i]!=s[n-i-1]) cnt++;
    }
    cout<<cnt<<endl;
}


Measured memory_bytes: 256
object Main {
  def main(args: Array[String]): Unit = {
    solve
  }

  def solve(): Unit = {
    val sc = new java.util.Scanner(System.in)
    val n, k = sc.nextInt()
    val nums = Array.fill[Int](n + 1)(0)
    for (i <- 0 until n) {
      nums(sc.nextInt() - 1) += 1
    }

    // filterを減らしてみた
    println(nums.sorted.dropRight(k).sum)
//    println(nums.filter(_ != 0).sorted.dropRight(k).sum)
  }
}


Measured memory_bytes: 70772
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n;
	int i, j;
	long ans = 0;

	cin >> n;
	long *a = new long[n + 2];
	long *ab = new long[n + 2];
	long *ab2 = new long[n + 2];

	for (i = 1; i <= n; i++) {
		cin >> a[i];
		ab2[i] = i - a[i];
		ab[i] = i + a[i];
	}

	sort(&ab[1], &ab[n + 1]);
	sort(&ab2[1], &ab2[n + 1]);

	j = 1;
	long cnt, cnt2;
	for (i = 1; i <= n;i++) {
		cnt = 1;
		for (i=i+1; i <= n; i++) {
			if (ab[i] == ab[i - 1]) {
				cnt++;
			}
			else {
				i--;
				break;
			}

		}
		if (i > n)i--;

		cnt2 = 0;
//		cout << "i = " << i << endl;
		for (; ab[i] >= ab2[j]&&j<=n; j++) {
//			cout << ab[i] << " / " << ab2[j] << endl;
			if (ab[i] == ab2[j]) {
//				cout << i << " / " << j << endl;
				cnt2++;
			}
		}
		ans += cnt * cnt2;
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 8332