akhauriyash/Code-Regression huggingface dataset:
//#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<set>
#include<map>

/*
#include<boost/multiprecision/cpp_int.hpp>
#include <boost/multiprecision/cpp_dec_float.hpp>
#include <boost/rational.hpp>
namespace mp = boost::multiprecision;
using Real = mp::number<mp::cpp_dec_float<1024>>;
using Bint = mp::cpp_int;
*/

using namespace std;

#define int long long
#define REP(i,s,e) for((i)=(s);(i)<(e);(i)++)
#define RREP(i,s,e) for((i)=((s)-1);(i)>=(e);(i)--)
#define FOR(i,n) for((i)=(0);(i)<(n);(i)++)
#define RFOR(i,n) for((i)=((n)-1);(i)>=(0);(i)--)
#define MOD 1000000007
#define MAX 400000

signed main(){
    int H,W,M;
    cin>>H>>W>>M;
    int h[MAX],w[MAX];
    for(int i=0;i<M;i++){
        cin>>h[i]>>w[i];
    }

    int ans1=0;

    int cn[MAX+1]={0};
    for(int i=0;i<M;i++){
        cn[h[i]]++;
    }
    int mi=-1,mn=-1;
    for(int j=1;j<=H;j++){
        if(mn<cn[j]){
            mn=cn[j];
            mi=j;
        }
    }
    for(int i=1;i<=MAX;i++) cn[i]=0;
    ans1=mn;
    int mi2=mi;
    mi=-1,mn=-1;
    for(int i=0;i<M;i++){
        if(mi2!=h[i]) cn[w[i]]++;
    }
    mi=-1,mn=-1;
    for(int j=1;j<=W;j++){
        if(mn<cn[j]){
            mn=cn[j];
            mi=j;
        }
    }
    ans1+=mn;
    for(int i=1;i<=MAX;i++) cn[i]=0;
    int ans2=0;

    for(int i=0;i<M;i++){
        cn[w[i]]++;
    }
    mi=-1,mn=-1;
    for(int j=1;j<=W;j++){
        if(mn<cn[j]){
            mn=cn[j];
            mi=j;
        }
    }
    for(int i=1;i<=MAX;i++) cn[i]=0;
    ans2=mn;
    mi2=mi;
    mi=-1,mn=-1;
    for(int i=0;i<M;i++){
        if(mi2!=w[i]) cn[h[i]]++;
    }
    mi=-1,mn=-1;
    for(int j=1;j<=H;j++){
        if(mn<cn[j]){
            mn=cn[j];
            mi=j;
        }
    }
    ans2+=mn;

    cout<<max(ans1,ans2)<<endl;
}


Measured memory_bytes: 10972
#include<iostream>
#include<string>
using namespace std;
int main()
{
    int n;
    string s;
    cin >> n >> s;
    int position = 0;
    int maxi_l = 0;
    for(int i = 0; i < s.size(); i++){
        if(s[i] == ')'){
            position++;
        } else {
            position--;
        }
        maxi_l = max(maxi_l, position);
    }
    position = 0;
    int maxi_r = 0;
    for(int i = s.size() - 1; i >= 0; i--){
        if(s[i] == '('){
            position++;
        } else {
            position--;
        }
        maxi_r = max(maxi_r, position);
    }
    for(int i = 0; i < maxi_l; i++){
        cout << "(";
    }
    cout << s;
    for(int i = 0; i < maxi_r; i++){
        cout << ")";
    }
    cout << endl;
    return 0;
}

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

int main(){
  int x,y,legs;
  cin >> x >> y;
  legs = x * 2;
  while(legs <= x * 4){
    if (legs == y){
      cout << "Yes" << endl;
      return 0;
    }
    legs += 2;
  }
  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3580
#include <algorithm>
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(), (x).end()
#define ll long long
#define INF 1000000000000000000
typedef pair<ll, ll> pll;

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

    string s; cin >> s;
    string ns = "";
    rep(i, s.size()){
        ns += "x";
    }

    cout << ns << endl;
}

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


int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    set<char> s;
    for(int i = 0; i < 4; i++){
        char c;
        cin >> c;
        s.insert(c);
    }
    cout << (s.size() == 2 ? "Yes" :"No" ) << '\n';



    return 0;
}
















Measured memory_bytes: 256
#include <iostream>
#include<queue>
#include<stack>
#include<vector>
#include<set>
#include<map>
#include<algorithm>
#include<cstring>
#include<string>
#include<cassert>
#include<cmath>
#include<climits>
#include<iomanip>
#include<bitset>
#include<unordered_map>

using namespace std;

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define rep(i,j,n) for(ll (i)=(j);(i)<(n);(i)++)
#define FOR(i,c) for(decltype((c).begin())i=(c).begin();i!=(c).end();++i)
#define ll long long
#define ull unsigned long long
#define all(hoge) (hoge).begin(),(hoge).end()
typedef pair<ll, ll> P;
const long long INF = 1LL << 60;
const long long MOD = 1e9 + 7;
typedef vector<ll> Array;
typedef vector<Array> Matrix;


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

//グラフ関連
struct Edge {//グラフ
	ll to, cap, rev;
	Edge(ll _to, ll _cap, ll _rev) {
		to = _to; cap = _cap; rev = _rev;
	}
};
typedef vector<Edge> Edges;
typedef vector<Edges> Graph;

void add_edge(Graph& G, ll from, ll to, ll cap, bool revFlag, ll revCap) {
	G[from].push_back(Edge(to, cap, (ll)G[to].size()));
	if (revFlag)G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}



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

	ll n, m;
	cin >> n >> m;
	string s;
	cin >> s;

	Array a;
	REP(i, n + 1) {
		if (s[i] == '0') {
			a.push_back(i);
		}
	}

	ll k = n;
	Array ans;
	
	while (k != 0) {
		auto it = lower_bound(all(a), k - m);
		if (*it == k) {
			cout << -1 << endl;
			return 0;
		}
		else {
			ans.push_back(k - *it);
            //cout<<k-*it<<endl;
			k = *it;
		}
	}

	if (k != 0) {
		cout << -1 << endl;
	}
	else {
		for (int i = ans.size() - 1; i >= 0; i--) {
			cout << ans[i] << " ";
		}
	}
	return 0;
}

Measured memory_bytes: 2628
#pragma GCC target ("avx2")
#pragma GCC optimization ("O3")
#pragma GCC optimization ("unroll-loops")
#include<bits/stdc++.h>
#define fastAF ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define ll long long
#define ull unsigned ll
#define ld long double
#define pb push_back
#define pf push_front
#define dll deque<ll>
#define vll vector<ll>
#define pll pair<ll,ll>
#define mapll map<ll,ll>
#define endl "\n"
#define all(v) v.begin(),v.end()
#define deb(x) cout<<x
#define ms(a,x) memset(a,x,sizeof(a))
using namespace std;
int main()
{
	// #ifndef ONLINE_JUDGE
 //    freopen("input.txt", "r", stdin);
 //    freopen("output.txt", "w", stdout);
 //    #endif
    fastAF
    ll x,k,d; cin>>x>>k>>d;
    if(x==0)
    {
    	if(k&1) cout<<d; else cout<<0; return 0;
    }
    ll dist=abs(x);
    ll in=dist/d;
    ll rem=dist%d;
    if(in>=k)
    {
    	cout<<dist-k*d; return 0;
    }
    k-=in;
    if(k%2==0)
    {
    	cout<<rem;
    }
    else cout<<d-rem;
    return 0;
}

Measured memory_bytes: 3612
#include <bits/stdc++.h>
#define all(vec) vec.begin(), vec.end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
constexpr ll INF = (1LL << 30) - 1LL;
constexpr ll LINF = (1LL << 60) - 1LL;
constexpr ll MOD = 1e9 + 7;
template <typename T> void chmin(T &a, T b) { a = min(a, b); }
template <typename T> void chmax(T &a, T b) { a = max(a, b); }
int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m;
    cin >> n >> m;
    vector<int> a(m), c(m);
    for (int i = 0; i < m; i++) {
        cin >> a[i];
        int b;
        cin >> b;
        c[i] = 0;
        for (int j = 0; j < b; j++) {
            int t;
            cin >> t;
            --t;
            c[i] |= (1 << t);
        }
    }
    vector<vector<int>> dp(m + 1, vector<int>((1 << n), INF));
    dp[0][0] = 0;
    for (int i = 0; i < m; i++) {
        for (int j = 0; j < (1 << n); j++) {
            chmin(dp[i + 1][j], dp[i][j]);
            chmin(dp[i + 1][j | c[i]], dp[i][j] + a[i]);
        }
    }
    if (dp[m][(1 << n) - 1] == INF) {
        cout << -1 << endl;
    } else {
        cout << dp[m][(1 << n) - 1] << endl;
    }
}

Measured memory_bytes: 16384
#include <iostream>
#include <cstdint>

using Int = std::int64_t;

int main() {
	Int t1, t2, a1, a2, b1, b2;
	std::cin >> t1 >> t2 >> a1 >> a2 >> b1 >> b2;

	Int x = t1 * (b1 - a1) + t2 * (b2 - a2);
	
	Int h = t1 * (a1 - b1);

	if (x == 0) {
		std::cout << "infinity" << std::endl;
		return 0;
	}

	if ((x > 0) != (h > 0))
		std::cout << 0 << std::endl;
	else
		std::cout << 1 + h / x * 2 - (h % x == 0 ? 1 : 0) << std::endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>	
#include<map>
#include<set>
#include<utility>
#include<cmath>
#include<cstring>
#include<queue>
#include<stack>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#define loop(i,a,b) for(int i=a;i<b;i++) 
#define rep(i,a) loop(i,0,a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
using namespace std;
//kaewasuretyuui
#define int long long
typedef long long ll;
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
//#define mt make_tuple
//typedef tuple<double,int,double> tp;
//typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-7;
Def inf=sizeof(Def)==sizeof(long long)?2e18:1e9;
int dx[]={0,1,0,-1};
int dy[]={1,0,-1,0};
class DIJ{
	public:
	struct edge{
		int to,cost;
	};
	vector<vector<edge> >G;
	int n;
	vi d;//distance
	DIJ(int size){
		n=size;
		G=vector<vector<edge> >(n);
	}
	void add_edge(int a,int b,int c){
		edge e={b,c},ee={a,c};
		G[a].pb(e);
		G[b].pb(ee);
	}
	void dij(int s){
		d=vi(n,inf);
		d[s]=0;
		priority_queue<pii>q;
		q.push(pii(0,s));
		while(!q.empty()){
			pii p=q.top();
			q.pop();
			int pos=p.second,cost=-p.first;
			if(cost>d[pos])continue;
			rep(i,G[pos].size()){
				edge e=G[pos][i];
				int to=e.to;
				int nowcost=cost+e.cost;
				if(nowcost<d[to]){
					d[to]=nowcost;
					q.push(pii(-d[to],to));
				}
			}
		}
	}
};
signed main(){
	int n;
	cin>>n;
	DIJ dij(n);
	rep(i,n-1){
		int a,b,c;
		cin>>a>>b>>c;
		a--;b--;
		dij.add_edge(a,b,c);
	}
	int q,k;
	cin>>q>>k;
	dij.dij(k-1);
	while(q--){
		int a,b;
		cin>>a>>b;
		cout<<dij.d[a-1]+dij.d[b-1]<<endl;
	}
}








Measured memory_bytes: 11120
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#define rep(i, n) for(int i = 0; i < (int)(n); ++i)
using namespace std;
using lint = int64_t;

int main() {
    int X, Y, Z, K;
    cin >> X >> Y >> Z >> K;
    vector<lint> A(X), B(Y), C(Z);
    rep(i, X) cin >> A[i];
    rep(i, Y) cin >> B[i];
    rep(i, Z) cin >> C[i];
    
    vector<lint> D(X * Y);
    rep(i, X) rep(j, Y) D[i * Y + j] = A[i] + B[j];
    sort(D.rbegin(), D.rend());
    vector<int> cnt(Z, 0);
    rep(i, K) {
        lint ans = 0;
        rep(j, Z) {
            if (cnt[j] == X * Y) continue;
            ans = max(ans, D[cnt[j]] + C[j]);
        }
        cout << ans << "\n";
        rep(j, Z) {
            if (cnt[j] == X * Y) continue;
            if (D[cnt[j]] + C[j] == ans) {
                ++cnt[j];
                break;
            }
        }
    }
    return 0;
}


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

#define ll long long int
#define endl "\n"
#define mod 1000000007

int main()
{

	ios_base::sync_with_stdio(0);
	cin.tie(0);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	{
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	}
#endif
	ll t;
	//cin >> t;
	t = 1;
	while (t--) {
		ll s, w;
		cin >> s >> w;
		if (w >= s) {
			cout << "unsafe" << endl;
		} else {cout << "safe" << endl;}
	}

	return 0;

}

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

using namespace std;

#define INF 1001000100010001000
#define MOD 1000000007
#define EPS 1e-10
#define int long long
#define rep(i, N) for (int i = 0; i < N; i++)
#define Rep(i, N) for (int i = 1; i < N; i++)
#define For(i, a, b) for (int i = (a); i < (b); i++)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define i_i pair<int, int>
#define vi vector<int>
#define vvi vector<vi >
#define vb vector<bool>
#define vvb vector<vb >
#define vp vector< i_i >
#define all(a) (a).begin(), (a).end()
#define Int(x) int x; cin >> x;
#define int2(x, y) Int(x); Int(y);
#define int3(x, y, z) Int(x); int2(y, z);
#define fir first
#define sec second
#define ffir first.first
#define fsec first.second
#define sfir second.first
#define ssec second.second
#define Decimal fixed << setprecision(10)

//int dxy[5] = {0, 1, 0, -1, 0};
// // assign avl ncm dijkstra geo2 kruskal graph uf lca BIT
// matrix dinic next_combination topcoder lcm vi st gin
// cusum segtree


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

    vb funami(30001, false);
    Int(n);

    n -= 3;
    cout << 2 << " " << 3 << " " << 25;
    funami[2] = funami[3] = funami[25] = true;

    int sum = 0;
    while (n > 1) {
        sum += 30;
        for (int i = 4; i + i < sum; i++) {
            if (i % 2 && i % 3 && i % 5) continue;
            if (!funami[i] && !funami[sum - i] && i != sum - i) {
                if (i > 30000 || sum - i > 30000) funami[-10] = false;
                funami[i] = funami[sum - i] = true;
                cout << " " << i << " " << sum - i;
                n -= 2;
            }
            if (n < 2) break;
        }
    }

    sum = 0;
    while (n) {
        sum += 30;
        if (!funami[sum]) {
            cout << " " << sum;
            n--;
        }
    }

    cout << endl;

    return 0;
}





Measured memory_bytes: 384
#include<iostream>
#include<iomanip>
#include<cmath>
#include<string>
#include<vector>
#include<list>
#include<algorithm>
#include<map>
#include<set>
#include<queue>
#include<stack>
using namespace std;
typedef long long ll;
#define fi first
#define se second
#define mp make_pair
const int inf=1e9+7;
const ll mod=1e9+7;
const ll big=1e18;

int main() {
    ll N;
    cin>>N;
    ll n = N;
    vector<ll> ans;
    for(ll i=2;i*i<=N;++i){
        while(N%i==0){
            ans.push_back(i);
            N /= i;
        }
    }
    if(N>1) ans.push_back(N);
    cout<<n;
    cout<<':';
    for(int i=0;i<ans.size();++i){
        cout<<' ';
        cout<<ans[i];
    }
    cout<<endl;
}




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

using ll = long long;
using ld = long double;
using vi = vector<int>;
using vll = vector<ll>;
using P = pair<int, int>;

const int INF = 1e9;
const ll INFLL = 1e18;
const int MOD = 1e9 + 7;
const int NIL = -1;
const ld PI = acosl(-1);

#define rep(i,n) for(int i=0; i<(n); ++i)
#define all(n) n.begin(),n.end()

int main(){
    int l, r;
    cin >> l >> r;

    const int mod = 2019;
    ll ans = mod;
    for(ll i = l; i < r; i++){
        for(ll j = i+1; j <= r; j++){
            ll res = (i*j) % mod;
            ans = min(ans, res);
            if(res == 0){
                cout << ans << endl;
                return 0;
            }
        }
    }

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


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

int main () {
    int a, b;
    std::cin >> a >> b;

    int bd = b;
    int cnt = 0;
    while(bd > 0) {
        bd /= 10;
        cnt++;
    }

    int mlti = 1;
    for (int i = 0; i < cnt; i++) {
        mlti *= 10;
    }

    long long  num = a * mlti + b;

    std::string ans;
    bool f = false;
    for (int i = 1; i*i <= num; i++)
    {
        if(i == 1.0*num/i) {
            f = true;
        } 
    }

    ans = f ? "Yes" : "No";

    std::cout << ans << "\n";
}

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

using namespace std;

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

    int n;
    while (cin >> n, n)
    {
        vector<int> w(n);
        for (int i = 0; i < n; i++)
            cin >> w[i];
        vector<vector<int>> dp(n, vector<int>(n, 0));
        int ret = 0;
        for (int i = 0; i < n - 1; i++)
        {
            if (abs(w[i] - w[i + 1]) <= 1)
            {
                dp[i][i + 1] = 2;
                ret = 2;
            }
        }
        for (int i = 3; i <= n; i++)
        {
            for (int j = 0; j <= n - i; j++)
            {
                if (dp[j + 1][j + i - 2] == i - 2 && abs(w[j] - w[j + i - 1]) <= 1)
                {
                    dp[j][j + i - 1] = i;
                    ret = i;
                }
                else
                {
                    for (int k = j + 1; k <= j + i - 1; k++)
                    {
                        dp[j][j + i - 1] = max(dp[j][j + i - 1], dp[j][k - 1] + dp[k][j + i - 1]);
                    }
                    ret = max(ret, dp[j][j + i - 1]);
                }
            }
        }
        cout << ret << endl;
    }
}



Measured memory_bytes: 3276
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<queue>
#include<stack>
#include<cmath>	

using namespace std;

int main() {
	int A, B, C;
	cin >> A >> B >> C;
	cout << max(0, C - (A - B)) << endl;
	return 0;
}

Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<unordered_map>
using namespace std;
typedef long long ll;
int n;
ll ans,c[410][4],h[410],v[4],tmp[4];
unordered_map<ll,int>mp;
void upd(ll x,int d){
    for(int i=0;i<4;i++,x=((x&1023ll)<<30ll)|(x>>10ll))
        mp[x]+=d;
    return;
}
ll Hash(ll *a){
    ll ret=0;
    for(int i=0;i<4;i++)
        ret|=(a[i]<<(i*10ll));
    return ret;
}
int main(){
    scanf("%d",&n);
    for(int i=1;i<=n;i++){
        scanf("%lld%lld%lld%lld",c[i],c[i]+1,c[i]+2,c[i]+3);
        h[i]=Hash(c[i]);
        upd(h[i],1);
    }
    for(int i=1;i<=n-5;i++){
        upd(h[i],-1);
        for(int j=i+1;j<=n;j++){
            upd(h[j],-1);
            for(int k=0;k<4;k++){
                ll res=1;
                for(int l=0;l<4;l++){
                    ll tmp[]={c[i][(l+1)&3],c[i][l],c[j][(3-l+k)&3],c[j][(6-l+k)&3]};
                    v[l]=Hash(tmp);
                    if(!mp.count(v[l]))
                        goto to;
                }
                for(int l=0;l<4;l++){
                    res*=mp[v[l]];
                    upd(v[l],-1);
                }
                ans+=res;
                for(int l=0;l<4;l++)
                    upd(v[l],1);
                to: ;
            }
            upd(h[j],1);
        }
    }
    printf("%lld",ans);
    return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("O3")
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <string>
#include <cstring>
#include <deque>
#include <list>
#include <queue>
#include <stack>
#include <vector>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <complex>
#include <cmath>
#include <limits>
#include <cfloat>
#include <climits>
#include <ctime>
#include <cassert>
#include <numeric>
#include <fstream>
#include <functional>
#include <bitset>
using namespace std;

using ll = long long;
using P = pair<int, int>;
using T = tuple<int, int, int>;

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

constexpr int MOD = 1e9 + 7;
constexpr int inf = 1e9;
constexpr long long INF = 1e18;

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

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

vector<ll> divisor(ll n){
    vector<ll> v;
    for(ll i=1; i*i<=n; i++){
        if(n % i == 0){
            v.emplace_back(i);
            v.emplace_back(n / i);
        }
    }

    sort(v.begin(), v.end());
    v.erase(unique(v.begin(), v.end()), v.end());

    return v;
}

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

    int n, m; cin>>n>>m;

    auto div = divisor(m);

    int ans = 1;
    for(auto i : div){
        if(n <= m / i) chmax(ans, (int)i);
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <vector>
#define _USE_MATH_DEFINES
#include <math.h>
#include <cstring>
#include <numeric>
#include <algorithm>
#include <stdlib.h>>
#include <functional>
#include <string>
#include <array>
#include <map>
#include <queue>
#include <limits.h>
#include <set>
#include <stack>
#include <random>
#include <complex>
#include <unordered_map>
#include <nmmintrin.h>
#include <chrono>
#define rep(i,s,n) for(int i = (s); (n) > i; i++)
#define REP(i,n) rep(i,0,n)
#define RANGE(x,a,b) ((a) <= (x) && (x) <= (b))
#define DUPLE(a,b,c,d) (RANGE(a,c,d) || RANGE(b,c,d) || RANGE(c,a,b) || RANGE(d,a,b))
#define INCLU(a,b,c,d) (RANGE(a,c,d) && (b,c,d))
#define PW(x) ((x)*(x))
#define ALL(x) (x).begin(), (x).end()
#define MODU 1000000007
#define bitcheck(a,b)   ((a >> b) & 1)
#define bitset(a,b)      ( a |= (1 << b))
#define bitunset(a,b)    (a &= ~(1 << b))
#define MP(a,b) make_pair((a),(b))
#define Manh(a,b) (abs((a).first-(b).first) + abs((a).second - ((b).second))
#define pritnf printf
#define scnaf scanf
#define itn int
#ifdef _MSC_VER
#define __builtin_popcount _mm_popcnt_u32
#define __builtin_popcountll _mm_popcnt_u64
#endif
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
ll gcd(ll a, ll b) {
	if (b == 0) return a;
	return gcd(b, a%b);
}
template<typename A, size_t N, typename T>
void Fill(A(&array)[N], const T &val) {
	std::fill((T*)array, (T*)(array + N), val);
}

ll func(ll b, ll n) {
	if (n < b)
		return n;
	return func(b, n/b) + n%b;
}

signed main() {

	ll n, s;

	scanf("%lld %lld", &n, &s);

	if (s == n) {
		printf("%lld", n + 1);
		return 0;
	}
	else if(s > n){
		printf("-1");
		return 0;
	}

	int sqn = sqrt(n);
	rep(i, 2, sqn+1) {
		if (func(i, n) == s) {
			printf("%d\n", i);
			return 0;
		}
	}
	ll Min = LLONG_MAX;
	rep(i, 1, sqn+1) {
		if(!((n-s)%i))
			if (func(1LL + (n - s) / (ll)i, n) == s) {
				Min = min(Min, 1LL + (n - s) / (ll)i);
			}
	}
	printf("%lld\n", Min == LLONG_MAX ? -1 : Min);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int n,daisuu;
  cin>>n;
  vector<tuple<int,int> > a;
  for(int i=1; i<n+1; i++){
    cin>>daisuu;
    a.push_back(make_tuple(daisuu,i  ));
  }
  sort(a.begin(), a.end());
  for (tuple<int, int> t : a) {
    int x, y;
    tie(x, y) = t;
    cout << y;
    if(x==n){
      break;
    }
    cout<<" ";
  }
}

Measured memory_bytes: 1780
#include <iostream> 
#include <vector>
#include <cmath>
#include <string>
#include <sstream>
#include <algorithm>
#include <queue>
#include <stack>
#include <unordered_set>
#include <set>
#include <unordered_map>
#include <map>
#include <iomanip>
#include <cctype>
#include <climits>

using namespace std;

using ii = pair<int, int>;
using vi = vector<int>;
using vii = vector<ii>;
using vvi = vector<vi>;

using ll = long long int;

#define mp(a,b) make_pair(a,b)

const int MOD = 1000 * 1000 * 1000 + 7;

bool res() {
	int a,b,c;
	cin >> a >> b >> c;
	if (!cin) return false;

	if (a == b && a != c) {
		cout << "Yes\n";
		return true;
	}
	if (a == c && a != b) {
		cout << "Yes\n";
		return true;
	}
	if (c == b && a != c) {
		cout << "Yes\n";
		return true;
	}

	cout << "No\n";

	return true;
}

int main() {
	while (res()) {}
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int a,b,c;
    int x,y;
    cin >> a >> b >> c >> x >> y;
    
    int ans = a*x + b*y;
    for(int i=0; i<=2*max(x,y); i+=2){
        ans = min(ans, i*c+ max(0,a*(x-i/2)) + max(0,b*(y-i/2)));
    }
    cout << ans << endl;
}

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

int main(){
	char a,b;
	scanf("%c %c",&a,&b);
	if(a=='H'){
		if(b=='H')puts("H");
		else puts("D");
	}else{
		if(b=='D')puts("H");
		else puts("D");
	}
	return 0;
}

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

using namespace std;

int main(){
    int N,ans=0;
    cin >> N;
    vector<int> B(N-1);

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

    ans += B[0];
    ans += B.back();

    for(int i=0;i<N-2;i++){
        ans += min(B[i],B[i+1]);
    }

    cout << ans << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <set>
#include <sstream>
#include <vector>
using namespace std;

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

    int N; //switches
    int M; //bulbs
    cin >> N >> M;

    int p[M];

    long long connected_bulbs[M];
    for (int i = 0; i < M; i++)
    {
        int k;
        cin >> k;
        int tmp = 0;
        //cout << "k: " << k;
        for (int j = 0; j < k; j++)
        {
            int t;
            cin >> t;
            tmp |= (1 << (t - 1));
        }
        connected_bulbs[i] = tmp;
        // cout << " i:" << i << " tmp:" << tmp << endl;
    }

    for (int i = 0; i < N; i++)
    {
        int tmp;
        cin >> tmp;
        p[i] = tmp;
        //cout << "i: " << i << " p:" << p[i] << endl;
    }

    int all_ons = 0;
    for (int bit = 0; bit < (1 << N); ++bit)
    {
        long long mask = 0;
        for (int i = 0; i < N; ++i)
        {
            if (bit & (1 << i))
            {
                //s.push_back(i);
                mask = mask | (1 << i);
            }
        }
        // std::bitset<64> y(mask);
        // cout << y << endl;

        int counter = 0;
        for (int i = 0; i < M; ++i)
        {
            int related = (mask & connected_bulbs[i]);
            // if (connected_bulbs[i] == (mask & connected_bulbs[i]))
            // {
            //     cout << "connected!"
            //          << "mask: " << mask << " connected_bulbs:" << connected_bulbs[i] << endl;
            // }
            // int connected = mask & connected_bulbs[i];
            // cout << "bit:" << bit << " i:" << i << " connected:" << connected << endl;
            int ons = __builtin_popcount(related & mask);
            if (ons % 2 == p[i])
            {
                ++counter;
            }
        }
        if (M == counter)
        {
            ++all_ons;
        }
    }

    cout << all_ons << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
    #include<stdio.h>
    //#include <bits/stdc++.h>
    #include<vector>
    #include<float.h>
    #include<iomanip>
    #include<algorithm>
    #include<string>
    #include<cstring>
    #include<math.h>
    #include<cmath>
    #include<sstream>
    #include<set>
    #include<map>
    #include<queue>
    #include<cassert>
    #include<cmath>
    #include<cstdint>
     
    #define INF 1e9
    #define rep(i,n)for(int i=0;(i)<(int)(n);i++)
    #define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
    #define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
    #define vec(type,n) vector<type>(n)
    #define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
    #define ALL(a)  (a).begin(),(a).end()
    #define chmin(a, b) a = min(a, b)
    #define chmax(a, b) a = max(a, b)
     
    using namespace std;
    using ll = long long;
    using Graph = vector<vector<int>>;
    using P = pair<ll, ll>;
     
const int MOD = 1e9 + 7;


ll cmb[100][100];
int main(){
   rep(i, 100){
      rep(j, i + 1){
         if(j == 0 || j == i)cmb[i][j] = 1;
         else cmb[i][j] = cmb[i - 1][j - 1] + cmb[i - 1][j];
      }
   }
   int n, a, b;
   cin >> n >> a >> b;
   a--;b--;
   vector<ll> v(n);
   map<ll, ll> mp;
   rep(i, n){
      cin >> v[i];
      mp[v[i]]++;
   }
   sort(ALL(v), greater<ll>());
   ll sum = 0;
   long double res = 0;
   vector<int> que;
   rep(i, a)sum += v[i];
   REP(i, a, b){
      sum += v[i];
      if(res < (long double)sum / (i + 1)){
         que = vector<int>(0);
         que.push_back(i);
         res = (long double)sum / (i + 1);
      }
      else if(res == (long double)sum / (i + 1)){
         que.push_back(i);
      }
   }
   map<ll, ll> mpp;
   que.push_back(INF);
   ll ans = 0;
   rep(i, n){
      mpp[v[i]]++;
      if(i == *lower_bound(ALL(que), i)){
         ll tmp = 1;
         for(auto p : mpp){
            tmp *= cmb[mp[p.first]][p.second];
         }
         ans += tmp;
      }
   }
   cout << fixed << setprecision(10) << res << endl;
   cout << ans << endl;
   //rep(i, (int)que.size())cout << que[i] << " ";
}


Measured memory_bytes: 3852
import java.util.*;
class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		int n=sc.nextInt();
		int m=sc.nextInt();
		int c=sc.nextInt();

		
		int[] b=new int[m];
		for(int i=0;i<m;i++){
			b[i]=sc.nextInt();
		}


		int[][] a=new int[n][m];
		for(int i=0;i<n;i++){
			for(int j=0;j<m;j++){
				a[i][j]=sc.nextInt();
			}
		}

		int count=0;
		for(int i=0;i<n;i++){
			int sum=0;
			for(int j=0;j<m;j++){
				sum+=a[i][j]*b[j];
			}
			if(sum+c>0)
				count++;
		}
		System.out.println(count);
	}
	
}

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

int rate[] = {400, 800, 1200, 1600, 2000, 2400, 2800, 3200};

int main() {
    int N;
    cin >> N;
    int cnt = 0;
    set<int> se;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        for (int j = 0; j < 8; j++) {
            if (a < rate[j]) {
                se.insert(j);
                break;
            }
            if (j == 7) cnt++;
        }
    }
    int minv = se.size();
    if (N == cnt) {
        minv = 1;
        cnt--;
    }
    cout << minv << " " << minv + cnt << endl;
}

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

#define ll long long
#define fw(p) for(int w=0;w<(p);w++)
#define fx(p) for(int x=0;x<(p);x++)
#define fy(p) for(int y=0;y<(p);y++)
#define fz(p) for(int z=0;z<(p);z++)
#define fyg(p,g) for(int y=(g);y<(p);y++)
#define fzg(p,g) for(int z=(g);z<(p);z++)
#define ce(d) cout<<d<<endl;
#define vecp(p) int aa;cin>>aa;(p).push_back(aa);
#define vecpl(p) long long aa;cin>>aa;(p).push_back(aa);
#define vecps(p) string aa;cin>>aa;(p).push_back(aa);
#define vecp2(p) cin>>aa;(p).push_back(aa);
#define vecpl2(p) long long a	b;cin>>ab;(p).push_back(ab);
#define vecps2(p) string ab;cin>>ab;(p).push_back(ab);
#define sorts(c) sort((c).begin(),(c).end());
#define reverses(c) reverse((c).begin(),(c).end());
#define vec(b) vector<int> (b);
#define vecl(b) vector<long long> (b);
#define vecs(b) vector<string> (b);
#define pb(b,a) (b).push_back((a));
#define doublece(a,b) cout<<(a)<<' '<<(b)<<endl;
#define pairs(s) vector<pair<int,int>> (s);
#define pairsp(s) int aa,bb;cin>>aa>>bb;(s).push_back(make_pair(aa,bb));
#define MOD 1000000007
#define cey ce("Yes")
#define cen ce("No")
#define ceY ce("YES")
#define ceN ce("NO")

int main()
{
		ll A , V , B, W , T;
	cin >> A >> V >> B >> W >> T;

	if (A>B) {
		if (A-V*T<=B-W*T) {
			ceY;
		}
		else {
			ceN;
		}
	}
	else {
		if (A + V * T >= B + W * T) {
			ceY;
		}
		else {
			ceN;
		}
	}
    return 0;
}



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

using namespace std;

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    char nums[k];   
    for(int i=0; i<k; ++i) {
        cin >> nums[i];
    }
    bool ok;
    string s;
    while(true) {
        ok=true;
        s = to_string(n);
        for(int i=0; i<s.size() && ok; ++i) {
            for(int j=0; j<k; ++j) {
                if( s[i] == nums[j] ) {
                    ok = false; break;
                }
            }
        }
        if(ok) {
            cout << n << '\n';
            return 0;
        } else {
            n++;
        }
    }
    return 0;
}

Measured memory_bytes: 3708
<?php
    list($a, $b, $c) = explode(" ", trim(fgets(STDIN)));
    $k = trim(fgets(STDIN));
    while($b <= $a){
        $b = $b * 2;
        $k--;
    }
    while($c <= $b){
        $c = $c * 2;
        $k--;
    }
    if($k < 0){
        echo "No";
    } else {
        echo "Yes";
    }
?>

Measured memory_bytes: 16188
/**
                 MD.Faysal Hasan
                Comilla Univesity               **/

#include<bits/stdc++.h>
#include<algorithm>
#include<cmath>
#include<string>
#include<stdlib.h>
using namespace std;

#define         rep(i,n)       for ( i=0 ; i<n ; ++i )
#define         rep1(i,n)      for ( i=1 ; i<=n ; ++i )
#define         sajo(str)      sort(str.begin(),str.end())
#define         rev(str)       reverse(str.begin(),str.end())
#define         usajo(str)     sort(str.rbegin(),str.rend())
#define         input(a)       for(auto &it : a) cin>>it
#define         pi             2*acos(0.0)
#define         nel            printf("\n")
#define         longmx         92233720368547758
#define         gcd(a,b)       __gcd(a,b)
#define         lcm(a,b)       (a/gcd(a,b))*b
#define         yes            cout<<"Yes"<<"\n"
#define         no             cout<<"No"<<"\n"
#define         vcl            vector<ll>
#define         vpl            vector<pair<ll,ll>>
#define         pb             push_back
#define         mkp(x,y)       make_pair(x,y)
#define         ff             first
#define         sc             second
#define         spc            ' '
#define         nn             '\n'
#define         ikarus_101     ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef         long long int  lli;
typedef         long long      ll;

int main(){ikarus_101

    ll ans,sum,tot,cnt,mx,mn,idx,chk,tmp,mid,lft,rgt,pos;
    ll tc,n,m,a,b,c,d,g,h,l,r,x,y,i,j,k;

    cin>>a;
    double rr=a;
    cout<<fixed<<setprecision(40)<<2.0*pi*rr<<nn;
    return 0;
}


Measured memory_bytes: 3808
#include <bits/stdc++.h>  // g++ -std=c++14 -o a a.cpp

using namespace std;

typedef pair<int, int> P;
typedef long long ll;

#define rep(i, n) for(int i = 0; i < (n); i++)
#define repto(i, n) for(int i = 0; i <= (n); i++)
#define all(c) (c).begin(), (c).end()
#define uniq(c) c.erase(unique(all(c)), (c).end())
#define _1 first
#define _2 second
#define pb push_back
#define INF 1145141919
#define MOD 1000000007
#define DEBUG(x) cout << #x << ": " << x << endl;

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

__attribute__((constructor))
void initial() {
    cin.tie(0);
    ios::sync_with_stdio(false);
}

int main() {
    int times[1001] = {0};
    int a, b, N;
    cin >> a >> b >> N;
    for (int i = a; i < b; i++)
    {
        times[i] = 1;
    }

    rep(x, N) {
        cin >> a >> b;
        for (int i = a; i < b; i++)
        {
            if (!times[i]) {
                times[i] = 1;
            } else {
                cout << 1 << endl;
                return 0;
            }
        }
    }
    
    cout << 0 << endl;
}



Measured memory_bytes: 3156
#include "bits/stdc++.h"
 
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
//----------------------------------------------------------------

int MOD = 998244353;
// int MOD = 1000000007;

int dp[201][201] = {0};
int s[201][201] = {0};

//----------------------------------------------------------------
signed main(){

	int n;
	cin >> n;
	vector<string> s(n);
	rep(i,n)cin >> s[i];

	rep(i,n) rep(j,n) dp[i][j] = INF;
    //costの入力 0-indexedに直して入れる
	rep(i,n){
		rep(j,n){
			if(s[i][j] == '1')dp[i][j] = 1;
		}
	}
	rep(i,n)dp[i][i] = 0;
	rep(k,n){
        rep(i,n){
            rep(j,n){
                dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);
            }
        }
    }
	rep(i,n){
		rep(j,n){
			cerr << dp[i][j] << " ";
		}cerr << endl;
	}
	// rep(i,n){
	// 	rep(j,n){
	// 		cerr << s[i][j] << " ";
	// 	}cerr << endl;
	// }

    rep(k,n){
        rep(i,n){
            rep(j,n){
                dp[i][j] = min(dp[i][j],dp[i][k] + dp[k][j]);
            }
        }
    } 

	int mx = 0;
	int p = 0;
	rep(i,n){
		rep(j,n){
			if(mx <= dp[i][j]){
				mx = dp[i][j];
				p = i;
			}	
		}
	}

	vll d(n,0);
	rep(i,n){
		d[i] = dp[p][i];
	}
	
	// rep(i,n){
	// 	rep(j,n){
	// 		if(d[i] != d[j]  && dp[i][j] != abs(d[i]-d[j])){
	// 			cout << -1 << endl;
	// 			cerr << i <<" " << j << endl;
	// 			rep(i,n)cerr << d[i] <<" ";cerr << endl;
	// 			return 0;
	// 		}
	// 	}
	// }
	rep(i,n){
		rep(j,n){
			if(i != j && d[i] == d[j] && s[i][j] == '1'){
				cout << -1 << endl;
				cerr << i <<" " << j << endl;
				rep(i,n)cerr << d[i] <<" ";cerr << endl;
				return 0;
			}
		}
	}
	cout << mx+1 << endl;


	

	return 0;
}

//----------------------------------------------------------------

// g++ -std=c++14 code1.cpp
// sudo pip3 install --upgrade online-judge-tools
// rm -r -f test;oj dl https://code-festival-2018-quala.contest.atcoder.jp/tasks/code_festival_2018_quala_c
// rm -r -f test;oj dl https://ddcc2017-final.contest.atcoder.jp/tasks/ddcc2017_final_b
// rm -r -f test;oj dl https://agc039.contest.atcoder.jp/tasks/agc039_a

Measured memory_bytes: 640
#include <algorithm>
#include <iostream>
#include <numeric>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>

using namespace std;
using ll = long long;

constexpr static ll MOD = 1000000007ll;
constexpr static int INF = 1 << 28; // for x <= 10^9
constexpr static ll INFL = 1ll << 60; // for x <= 10^19

int main() {
    int n, m;
    cin >> n >> m;
    unordered_set<int> aSet(m);
    for (int i = 0; i < m; i++) {
        int a;
        cin >> a;
        aSet.insert(a);
    }

    vector<ll> dp(n + 1);
    dp[0] = 1;
    dp[1] = (aSet.find(1) == aSet.end()) ? 1 : 0;
    for (int i = 2; i <= n; i++) {
        if (aSet.find(i) == aSet.end()) {
            dp[i] = (dp[i - 1] + dp[i - 2]) % MOD;
        } else {
            dp[i] = 0;
        }
    }
    cout << dp[n] << endl;
}


Measured memory_bytes: 4992
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = pow(10, 9) + 7;
//const ll MOD = 998244353;
//const ll MOD = ;
ll mod(ll A, ll M) {return (A % M + M) % M;}
const ll INF = 1LL << 60;
template<class T> bool chmin(T& a, T b) {if (a > b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a, T b) {if (a < b) {a = b; return true;} return false;}
ll divCeil(ll A, ll B) {return (A + (B - 1)) / B;}
ll myctoi(char C) {return C - '0';}
char myitoc(ll N) {return '0' + N;}
#define FINALANS(A) {cout << (A) << endl; exit(0);}

int main()
{
  ll N;
  cin >> N;
  vector<ll> A(N);
  for (ll i = 0; i < N; i++)
  {
    cin >> A.at(i);
  }

  ll ans = accumulate(A.begin(), A.end(), 0LL) - N;
  cout << ans << endl;
}

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

int main() {
    long long N, D, X, Y;
    cin >> N >> D;
    long long C = 0;
    for (int i = 0; i < N; i++) {
        cin >> X >> Y;
        if (X*X + Y*Y <= D*D) C++;
    }
    cout << C << endl;
    return 0;
}


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

int A[100005];
bool B[100005];

int main(void)
{
  using namespace std;
  int N;
  cin >> N;
  for(int i = 1; i <= N; i++)
  {
    cin >> A[i];
  }

  int i = 1;
  int ans = 0;
  while(i != 2 && !B[i])
  {
    B[i] = true;
    i = A[i];
    ++ans;
  }

  if(i != 2)
  {
    cout << "-1\n";
  }
  else
  {
    cout << ans << '\n';
  }
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
#include <unordered_set>
#include <random>
using namespace std;
#define ll long long
#define fr first
#define sc second
#define pll pair<ll, ll>
#define all(v) v.begin(), v.end()

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

	int cnt[4] = { 0 };
	for (int i = 0; i < N; i++) {
		string s; cin >> s;
		if (s == "AC") cnt[0]++;
		else if (s == "WA") cnt[1]++;
		else if (s == "TLE") cnt[2]++;
		else if (s == "RE") cnt[3]++;
	}
	cout << "AC x " << cnt[0] << '\n';
	cout << "WA x " << cnt[1] << '\n';
	cout << "TLE x " << cnt[2] << '\n';
	cout << "RE x " << cnt[3] << '\n';
	return 0;
}

Measured memory_bytes: 3660
n = gets.to_i
a = gets.split(/\s/).map(&:to_i)

s = 0
count = 0
for i in 0..n-1
	s += a[i]
	if s*((-1)**i)<=0
		count += s*((-1)**(i+1)) + 1
		s = (-1)**i
	end
end

s=0
count2 = 0
for i in 0..n-1
	s += a[i]
	if s*((-1)**i)>=0
		count2 += s*((-1)**i) + 1
		s = (-1)**(i+1)
	end
end

if count<count2
	puts count
else
	puts count2
end

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

ll L, R;

int main() {
    cin >> L >> R;

    if ((R - L) >= 2019) {
        cout << 0 << endl;
        return 0;
    }

    ll N   = R - L + 1;
    ll ans = 2019;

    for(ll l=L;l<R;l++){
      for(ll r=L+1;r<=R;r++){
        if(l==r) continue;
        ans = min(ans,l*r % 2019);
      }
    }

    cout << ans << endl;
}

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

int h, w;
bool isSafe(int x, int y, vector<vector<int>> &dp) {
    return x >= 1 && y >= 1 && x <= h && y <= w && dp[x][y] != -1;
}

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

    cin >> h >> w;

    vector<vector<int>> dp(h + 1, vector<int>(w + 1));
    for (int i = 1; i <= h; i++) {
        for (int j = 1; j <= w; j++) {
            char c;
            cin >> c;
            if (c == '.') dp[i][j] = 0;
            else if (c== '#') dp[i][j] = -1;
        }
    }

    dp[h][w] = 1;
    for (int i = h; i >= 1; i--) {
        for (int j = w; j >= 1; j--) {
            if (dp[i][j] != 0) continue;
            if (isSafe(i + 1, j, dp)) {
                dp[i][j] = ((dp[i][j] % MOD) + (dp[i + 1][j] % MOD)) % MOD;
            }
            if (isSafe(i, j + 1, dp)) {
                dp[i][j] = ((dp[i][j] % MOD) + (dp[i][j + 1] % MOD)) % MOD;
            }
        }
    }

    cout << dp[1][1];
}


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

using namespace std;

#define ll long long
#define sf scanf
#define pf printf 
#define nl printf("\n")

int main()
{
	#ifndef ONLINE_JUDGE
		//freopen("in.txt","r",stdin);
		//freopen("out.txt","w",stdout);
	#endif

	int a,b,c;
	while(sf("%d %d %d",&a,&b,&c)==3){
		swap(a,b);
		swap(a,c);
		pf("%d %d %d\n",a,b,c);
	}
	return 0;
}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

template <typename T>
void print(const vector<T> &v) {
    for (auto e : v) cout << e << ' ';
    cout << endl;
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    long long H, W; cin >> H >> W;
    if (H == 1 || W == 1) cout << 1 << '\n';
    else cout << (H*W+1)/2 << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 3628
import sys
N, B = map(int,input().split())
R = N-B
T = 1000000007
def combination(n, r):
	if r == 0 or r == n:
		return 1
	elif r == 1:
		return n
	else:
		return(combination(n-1, r-1) + combination(n-1, r))
def generating_combination(n):
	T = 1000000007
	C = C = [[0 for i in range(n+1)] for j in range(n+1)]
	C[0][0] = 1
	C[1][0] = 1
	C[1][1] = 1
	for i in range(2,n+1):
		C[i][0] = 1
		C[i][i] = 1
		for j in range(1,i):
			C[i][j] = (C[i-1][j-1] + C[i-1][j])%T
	return(C)

D = generating_combination(2000)
i = 1
for i in range(1,B+1):
	print((D[B-1][i-1]*D[R+1][i])%T)
	i += 1

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

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

using namespace std;
using lint=long long;

vector<lint> divisors(lint a){
	vector<lint> res;
	for(lint i=1;i*i<=a;i++) if(a%i==0) {
		res.emplace_back(i);
		if(i*i<a) res.emplace_back(a/i);
	}
	return res;
}

int main(){
	lint n; cin>>n;

	int ans=20;
	for(lint d:divisors(n)){
		ans=min<int>(ans,max(to_string(d).length(),to_string(n/d).length()));
	}
	cout<<ans<<endl;

	return 0;
}


Measured memory_bytes: 256
import math
x1, y1, x2, y2 = [int(i) for i in input().split()]
if x1 >= x2 and y1 <= y2:
    x3 = x2 - abs(y1 - y2)
    x4 = x1 - abs(y1 - y2)
    y3 = y2 - abs(x1 - x2)
    y4 = y1 - abs(x1 - x2)
elif x1 <= x2 and y1 <= y2:
    x3 = x2 - abs(y1 - y2)
    x4 = x1 - abs(y1 - y2)
    y3 = y2 + abs(x1 - x2)
    y4 = y1 + abs(x1 - x2)
elif x1 >= x2 and y1 >= y2:
    x3 = x2 + abs(y1 - y2)
    x4 = x1 + abs(y1 - y2)
    y3 = y2 - abs(x1 - x2)
    y4 = y1 - abs(x1 - x2)
elif x1 <= x2 and y1 >= y2:
    x3 = x2 + abs(y1 - y2)
    x4 = x1 + abs(y1 - y2)
    y3 = y2 + abs(x1 - x2)
    y4 = y1 + abs(x1 - x2)
print(x3, y3, x4, y4)


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


int main() {

    int a, b, x;
    cin >> a >> b >> x;
    if (a <= x && x <= a+b) cout << "YES" << endl;
    else cout << "NO" << endl;    
    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    Main m = new Main(sc);
    m.show(m.solve());
  }

  Scanner sc;
  int H1 = 0;
  int M1 = 0;
  int H2 = 0;
  int M2 = 0;
  int K = 0;
  int answer = 0;

  // 標準入力用のコンストラクタ
  public Main(Scanner sc) {
    this.sc = sc;
    H1 = sc.nextInt();  //24時間表記
    M1 = sc.nextInt();
    H2 = sc.nextInt();
    M2 = sc.nextInt();
    K = sc.nextInt();
  }

  // 判定処理
  int solve() {
      int answer = (H2 - H1) * 60 + (M2 - M1) - K;
      return answer;
  }

  // 回答の表示
  void show(int answer) {
    System.out.println(answer); //分
  }
}

Measured memory_bytes: 35808
#include <iostream>
#include <bitset>
#define MAX 55600

using namespace std;
typedef long long ll;

int n;
bitset<MAX> prim;
void ciur(){
  prim.set(); prim[0]=prim[1]=false;
  for(int i=2;i<MAX;i++)
    if(prim[i])
      for(ll j=(ll)i*i;j<MAX;j+=i)
        prim[j]=false;
}

int main()
{
    ciur();
    cin>>n;
    for(int i=1;n;i++)
      if(prim[i]&&i%5==1)
        cout<<i<<" ",
        n--;
    return 0;
}


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

using namespace std;

typedef long long ll;
typedef pair<int, int> P;

constexpr ll MOD = 1e9 + 7;

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

    int n, a[22][22];

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

    vector<int> b[22];
    for (int i = 0; i < (1 << n); i++)
    {
        int cnt = 0;
        for (int j = 0; j < n; j++)
            cnt += (i & (1 << j)) > 0;
        b[cnt].push_back(i);
    }

    static ll dp[22][(1 << 21) + 10];
    memset(dp, 0, sizeof(dp));

    dp[0][0] = 1;

    for (int i = 1; i <= n; i++)
    {
        for (int j : b[i])
        {
            for (int k = 0; k < n; k++)
            {
                if (!(j & (1 << k)))
                    continue;
                if (!a[i][k])
                    continue;

                (dp[i][j] += dp[i - 1][j & ~(1 << k)]) %= MOD;
            }
        }
    }

    cout << dp[n][(1 << n) - 1] << endl;

    return 0;
}

Measured memory_bytes: 370108
n = int(input())
v = []
for i in range(n + 10):
    v.append([])

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

import collections
q = collections.deque([])
used = [None] * (n+10)
q.append([1,0])
while len(q) > 0:
    cur, color = q.pop()
    #print(cur,color)
    used[cur] = color
    for i in range(len(v[cur])):
        nind, w = v[cur][i]
        if used[nind] != None:
            continue
        if w % 2 == 0:
            q.append([nind, color])
        else:
            q.append([nind, 1-color])
for i in range(1, n+1):
    print(used[i])

Measured memory_bytes: 106340