akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const long double EPS=1e-9;
const long double PI=acos(-1.0);
int ABS(int a){return max(a,-a);}
long long ABS(long long a){return max(a,-a);}
long double ABS(long double a){return max(a,-a);}
int main(){
	int a,b;scanf("%d%d",&a,&b);
	int ret=1;
	int cur=0;
	for(int i=0;i<a;i++){
		int t;scanf("%d",&t);cur+=t;
		if(cur<=b)ret++;
	}
	printf("%d\n",ret);
}


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

int main() {

  while( true ) {

    long long int a, b, c;
    cin >> a >> b >> c;
    if ( a == 0 ) break;

    vector< long long int > ans;
    for ( long long int i = 0; i < a + b + c; i++ ) {
      ans.push_back( 2 );
    }

    long long int n;
    cin >> n;

    vector< long long int > v_a, v_b, v_c;

    for ( long long int i = 0; i < n; i++ ) {

      long long int in_a, in_b, in_c, r;
      cin >> in_a >> in_b >> in_c >> r;

      if ( r == 1 ) {
	ans[ in_a - 1 ] = 1;
	ans[ in_b - 1 ] = 1;
	ans[ in_c - 1 ] = 1;
      }else {
	v_a.push_back( in_a );
	v_b.push_back( in_b );
	v_c.push_back( in_c );
      }

    }

    for ( long long int i = 0; i < v_a.size(); i++ ) {
      if ( ans[ v_a[i] - 1 ] == 1 && ans[ v_b[i] - 1 ] == 1 ) ans[ v_c[i] - 1 ] = 0;
      if ( ans[ v_a[i] - 1 ] == 1 && ans[ v_c[i] - 1 ] == 1 ) ans[ v_b[i] - 1 ] = 0;
      if ( ans[ v_b[i] - 1 ] == 1 && ans[ v_c[i] - 1 ] == 1 ) ans[ v_a[i] - 1 ] = 0;
    }

    for ( long long int i = 0; i < a + b + c; i++ ) {
      cout << ans[i] << endl;
    }

  }

  return 0;

}

Measured memory_bytes: 1256
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <algorithm>
#include <chrono>
#include <iomanip>
#include <iostream>
#include <map>
#include <set>
#include <string>
#include <vector>

using namespace std;

int main() {
    double W, H, x, y;
    cin >> W >> H >> x >> y;
    cout << setprecision(10) << (W * H) / 2.0 << " ";
    if (x == W / 2 && y == H / 2) {
        cout << '1' << endl;
    } else {
        cout << '0' << endl;
    }
    return 0;
}


Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include <iostream>
#include <cstdio>
#include <cstring>
#include <ctime>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <utility>
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef pair<int,int> pii;
#define all(c) (c).begin(), (c).end()
#define loop(i,a,b) for(ll i=a; i<ll(b); i++)
#define rep(i,b) loop(i,0,b)
#define each(e,c) for(auto&e:c)
#define pb push_back
#define eb emplace_back
#define mp make_pair
#define mt make_tuple
#define lb lower_bound
#define ub upper_bound
#ifdef DEBUG
#define dump(...) (cerr<<#__VA_ARGS__<<" = "<<(DUMP(),__VA_ARGS__).str()<<" ["<<__LINE__<<"]"<<endl)
struct DUMP:ostringstream{template<class T>DUMP &operator,(const T&t){if(this->tellp())*this<<", ";*this<<t;return *this;}};
#else
#define dump(...)
#endif

int d[111][111];
int main(){
    int n; cin >> n;
    rep(i,n) rep(j,n) cin >> d[i][j];
    ll ans = 0;
    rep(i,n) rep(j,i) ans += min(d[i][j], d[j][i]);
    cout << ans << endl;
}

Measured memory_bytes: 1200
#include <stdio.h>

int main(){
  int x,y,z,temp;

  scanf("%d%d",&x,&y);

  if(x<y){
    temp = x;
    x = y;
    y = temp;
  }

  z = x%y;
  
  while(z!=0){
    x = y;
    y = z;
    z = x%y;
  }

  printf("%d\n",y);
  
  return 0;
}



Measured memory_bytes: 2128
#pragma region Template
#include <bits/stdc++.h>
using namespace std;

#define rep(i, n) for (int (i) = 0; (i) < (n); (i)++)
#define rng(i, a, b) for (int (i) = (a); (i) < (b); (i)++)
#define rbf(i, v) for (auto& (i) : (v))
#define All(x) (x).begin(),(x).end()
#define COL(x) cout << x << endl
#define CO(x) cout << x
//#define int long long

using LL = long long;
using UL = unsigned long;
using ULL = unsigned long long;
using PII = pair<int, int>;
using VI = vector<int>;
using VVI = vector<VI>;
using VLL = vector<LL>;
using VS = vector<string>;
using VP = vector<PII>;

const double PI = 3.141592653589793;
const int MOD = 1000000007;
const LL INF64 = INT64_MAX >> 1;
const int INF = INT_MAX >> 1;

inline int sqr(int x) { return (x * x); }
inline void printd(double x) { printf("%.10lf\n", x); }
inline void upsort(VI& x) { sort((x).begin(), (x).end()); }
inline void downsort(VI& x) { sort((x).begin(), (x).end(), greater<int>()); }
inline int absdiff(int a, int b) { return (a - b) * (static_cast<int>(a > b)*2 - 1); }
int gcd(int a, int b) { // 最大公約数
	if (a < b) return gcd(b, a);
	int r;
	while ((r = a % b)) {
		a = b;
		b = r;
	}
	return b;
}
inline int lcm(int a, int b) { return a * b / gcd(a, b); } // 最小公倍数
#pragma endregion

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

	int n1 = N % 10;

	if (n1 == 3) {
		cout << "bon\n";
	}
	else if (n1 == 0 || n1 == 1 || n1 == 6 || n1 == 8) {
		cout << "pon\n";
	}
	else {
		cout << "hon\n";
	}

	return 0;
}

Measured memory_bytes: 3632
#include<stdio.h>
#define MAX 100000

int A[MAX], n;

int partition(int p, int r){
    int x,i,j,t;
    x = A[r];
    i = p-1;
    for(j=p; j<r; j++){
        if(A[j] <= x){
            i++;
            t = A[i]; A[i] = A[j]; A[j] = t;
        }
    }
    t = A[i+1]; A[i+1] = A[r]; A[r] = t;
    return i + 1;
}

int main(){
    int i,q;
    scanf("%d",&n);
    for(i=0;i<n;i++) scanf("%d",&A[i]);

    q = partition(0,n-1);

    for(i=0;i<n;i++){
        if(i) printf(" ");
        if(i==q) printf("[");
        printf("%d",A[i]);
        if(i==q) printf("]");
    }
    printf("\n");
    return 0;
}


Measured memory_bytes: 2976
#define DEB
#include<bits/stdc++.h>
#define REP(i,m) for(int i=0;i<(m);++i)
#define REPN(i,m,in) for(int i=(in);i<(m);++i)
#define ALL(t) (t).begin(),(t).end()
#define CLR(a) memset((a),0,sizeof(a))
#define pb push_back
#define mp make_pair
#define fr first
#define sc second

using namespace std;


#ifdef DEB
#define dump(x)  cerr << #x << " = " << (x) << endl
#define prl cerr<<"called:"<< __LINE__<<endl
#define dumpR(x) cerr<<"\x1b[31m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpY(x) cerr<<"\x1b[33m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
#define dumpG(x) cerr<<"\x1b[32m"<<#x<<" = " <<(x)<<"\x1b[39m"<<endl
template<class T> void debug(T a,T b){ for(;a!=b;++a) cerr<<*a<<' ';cerr<<endl;}
#else
#define dump(x) ;
#define dumpR(x) ;
#define dumpY(x) ;
#define dumpG(x) ;
#define prl ;
template<class T> void debug(T a,T b){ ;}
#endif

template<class T> void chmin(T& a,const T& b) { if(a>b) a=b; }
template<class T> void chmax(T& a,const T& b) { if(a<b) a=b; }

typedef long long int lint;
typedef pair<int,int> pi;

namespace std{
  template<class S,class T>
  ostream &operator <<(ostream& out,const pair<S,T>& a){
    out<<'('<<a.fr<<','<<a.sc<<')';
    return out;
  }
}

//const int INF=5e8;


struct uf{
  static const int MAXN=200005;
  int par[MAXN];
  int size[MAXN];
  void init(){
    memset(par,-1,sizeof(par));
    REP(i,MAXN) size[i]=1;
  }
  int root(int a){
    if(par[a]==-1) return a;
    return par[a]=root(par[a]);
  }
  void unite(int a,int b){
    a=root(a);b=root(b);
    if(a==b) return;
    if(size[a]<size[b]) swap(a,b);

    par[b]=a;
    size[a]+=size[b];
  }
  bool same(int a,int b){
    return root(a)==root(b);
  }
};

uf u;

int n,m,K;
int col[100005];
pair<int,pi> es[100005];
int main(){
  cin>>n>>m>>K;

  int K2=K;
  REP(i,n){
    scanf("%d",&col[i]);
    --col[i];
    if(col[i]==-1) col[i]=K2++;
  }
  REP(i,m){
    int a,b,w;scanf("%d%d%d",&a,&b,&w);
    --a;--b;
    int ca=col[a],cb=col[b];
    es[i]={w,{ca,cb}};
  }
  sort(es,es+m);
  u.init();
  int comp=K2;
  int uni=0;

  lint tot=0;
  lint res=-1;
  REP(i,m) {
    if(!u.same(es[i].sc.fr,es[i].sc.sc)){
      u.unite(es[i].sc.fr,es[i].sc.sc);
      --comp;
      ++uni;
      tot+=es[i].fr;
      if(uni==K-1){
        res=tot;
        break;
      }
    }
  }
  cout<<res<<endl;
  return 0;
}





Measured memory_bytes: 3328
#include <bits/stdc++.h>
#define il inline
#define int long long
const int N=1e5+5;

int n,m,D,sz[N],U[N],V[N];
struct node{int id,p;}d[N];

il bool operator < (node a,node b){return a.p<b.p;}

signed main()
{
	scanf("%lld",&n); int i,f,dis;
	for (i=1; i<=n; i++) scanf("%lld",&d[i].p),d[i].id=i,sz[i]=1;
	std::sort(d+1,d+n+1);
	
	for (i=n; i>1; i--)
	{
		f=std::lower_bound(d+1,d+n+1,(node){0,dis=d[i].p-n+sz[i]+sz[i]})-d;
		if (dis!=d[f].p) return puts("-1"),0;
		U[++m]=d[i].id,V[m]=d[f].id,sz[f]+=sz[i],D+=sz[i];
	}
	if (D!=d[1].p) return puts("-1"),0;
	for (i=1; i<n; i++) printf("%lld %lld\n",U[i],V[i]);
	
	return 0;
}

Measured memory_bytes: 7732
#include <bits/stdc++.h>
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
using Graph = vector<vector<int>>;

// 二部グラフ判定
vector<int> color;
bool dfs(const Graph &G, int v, int cur = 0) {
  color[v] = cur;

  for (auto next_v : G[v]) {
    // 隣接頂点の色がすでに確定していた場合
    if (color[next_v] != -1) {
      if (color[next_v] == cur) return false; // 同色が隣接したらNG
      continue;
    }

    // 隣接頂点の色を変えて、再帰的に探索
    // (一度でも false が帰ってきたら false で終了)
    if (!dfs(G, next_v, 1 - cur)) return false;
  }
  return true;
}

int main() {
  // 頂点数と辺数
  ll N, M; cin >> N >> M;

  // グラフ入力受取
  Graph G(N);
  for (ll i = 0; i < M; i++) {
    int a, b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }

  // 探索
  color.assign(N, -1);
  bool is_bipartite = dfs(G, 0);

  if (is_bipartite) {
    ll B = 0, W = 0;
    for (ll i = 0; i < N; i++) {
      color[i] == 0 ? B++ : W++;
    }
    cout << B * W - M << endl;
  } else {
    cout << N * (N - 1) / 2 - M << endl;
  }
}


Measured memory_bytes: 6656
#include <bits/stdc++.h>
//----***やべーやつら***----
using namespace std;
#define int long long

//----***型定義***----
using ll = long long;
using pll = pair<ll, ll>;
using pdd = pair<double, double>;
typedef long double lb;
typedef vector<int,vector<int>> vvec;
typedef long double ld;

//----***Like a Pythonista***----
#define REP(i,j,n) for (ll i=j;i<(n);i++)
#define RREP(i,n,j) for (ll i = n; j<i;i--)
#define each(i,...) for (auto&& i:__VA_ARGS__)
#define ALL(vec) (vec).begin(),(vec).end()
#define sum(...) accumulate(all(__VA_ARGS__),0LL)
#define dsum(...) accumulate(all(__VA_ARGS__),0.0L)
#define vec(type,name,...) vector<type> name(__VA_ARGS__)
template<class T> inline auto max(const T& a){ return *max_element(all(a)); }
template<class T> inline auto min(const T& a){ return *min_element(all(a)); }
inline ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
inline ll lcm(ll a, ll b){ if(!a || !b) return 0; return a * b / gcd(a, b); }

//----***定数***----
const int MOD=1000000007;
#define INF 1e9;
#define EPS 1e-9;

//----***入出力***----
#define print(out) cout<< out  << "\n";
#define debug(var)  do{std::cerr << #var << " ↓ "<<"\n";view(var);}while(0)
template<typename T> void view(T e){std::cout << e << std::endl;}
template<typename T> void view(const std::vector<T>& v){for(const auto& e : v){ std::cout << e << " "; } std::cout << std::endl;}
template<typename T> void view(const std::vector<std::vector<T> >& vv){ for(const auto& v : vv){ view(v); } }
#define HERE  cout<<"Here"<<endl;

//----***初期時読み込み***----
struct initial{initial(){cin.tie(0); ios::sync_with_stdio(0); cout<<fixed<<setprecision(20);};}initial_;

signed main(){
  int N,ans=0;cin>>N;
  vector<int> L(N);
  REP(i,0,N){
    cin>>L[i];
  }
  sort(ALL(L));
  RREP(i,N-1,1)RREP(j,i-1,0){
    int left=L[i]-L[j];
    auto iter2 = upper_bound(ALL(L), left);
    left=min(j,max(0LL,(int)distance(L.begin(),iter2)));
    //debug(left);
    //print(i<<" "<<j)
    //debug(j-left);
    ans+=j-left;
  }
  print(ans)

}


Measured memory_bytes: 256
//Author: Fuadul Hasan(fuadul202@gmail.com)
//BSMRSTU,Gopalganj
#include<bits/stdc++.h>
using namespace std;

#define ll long long
const int mod = 1e9 + 7;
const int Inf = (int)2e9 + 5;
const ll  Lnf = (ll)2e18 + 5;
const int N   = 4e5 + 5;
int solve() 
{
	
	int n,m;
	scanf("%d%d", &n,&m);
	int a[n+1];
	int sum = 0;
	for(int i=0;i<n;i++){
		scanf("%d", &a[i]);
		sum += a[i];
	}
	int cnt = 0;
	for(int i=0;i<n;i++){
		if(m*4*a[i]>=sum)cnt++;
	}

	if(cnt>=m){
		printf("Yes\n");
	}else printf("No\n");


	return 0;
}
int main(){
	int test = 1;
	//scanf("%d", &test);
	while (test--)solve();return 0;
}

Measured memory_bytes: 256
#include <stdio.h> 
int main(void)
{
int in, s, m, h;
scanf("%d", &in);
h = in / 3600;
in %= 3600;
m = in / 60;
in %= 60;
s = in;
printf("%d:%d:%d\n",h ,m, s);
return 0;
}

Measured memory_bytes: 2672
#include <iostream>
#include <vector>
#include <map>

int main()
{
  int N;
  std::cin >> N;
  std::map<std::string, std::map<int, int, std::greater<int>>> city_point_restrant;

  for(int i=0; i<N; i++) {
    std::string s;
    int p;
    std::cin >> s >> p;
    city_point_restrant[s].insert(std::make_pair(p, i+1));
  }

  for(auto &cpr: city_point_restrant) {
    for(auto &pr: cpr.second) {
      std::cout << pr.second << std::endl;
    }
  }
  return 0;
}


Measured memory_bytes: 3588
#include<stdio.h>
int main()
{
    double  s=0,x1,x2,y1,y2,a,b,c,d,ar[1000];
    scanf("%lf",&a);
    int i,j;
    for(i=1;i<=2*a;i++)
    {
        scanf("%lf",&ar[i]);
    }
    for(i=1;i<=2*a;i+=2)
    {
        x1=ar[i];
        y1=ar[i+1];
        for(j=1;j<=2*a;j+=2)
        {
            x2=ar[j];
            y2=ar[j+1];
            b=sqrt((x1-x2)*(x1-x2)+(y1-y2)*(y1-y2));
            s=s+b;
        }
    }
    double A=a*1.0;
    double S=s*1.0;
    printf("%lf\n",S/A*1.0);
    return 0;
}


Measured memory_bytes: 128
#include <iostream>
#include <vector>

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

    std::vector<int> a(n);
    for(int i = 0; i < n; ++i){
        std::cin >> a.at(i);
    }

    std::sort(a.begin(), a.end());
    a.erase(std::unique(a.begin(), a.end()), a.end());

    long ans = 0;
    for(int i = 0; i < a.size() - 1; ++i){
            ans += a.at(i + 1) - a.at(i);
    }

    std::cout << ans << std::endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ull = unsigned long long;
 
#define REP(i,n) for(long long i = 0; i < (n); i++)
#define FOR(i, m, n) for(long long i = (m);i < (n); ++i)
#define ALL(obj) (obj).begin(),(obj).end()
#define SPEED cin.tie(0);ios::sync_with_stdio(false);
 
template<class T> using V = vector<T>;
template<class T, class U> using P = pair<T, U>;
template<class T> using PQ = priority_queue<T>;
template<class T> using PQR = priority_queue<T,vector<T>,greater<T>>;
 
constexpr long long MOD = (long long)1e9 + 7;
constexpr long long MOD2 = 998244353;
constexpr long long HIGHINF = (long long)1e18;
constexpr long long LOWINF = (long long)1e15;
constexpr long double PI = 3.1415926535897932384626433;
 
template <class T> vector<T> multivector(size_t N,T init){return vector<T>(N,init);}
template <class... T> auto multivector(size_t N,T... t){return vector<decltype(multivector(t...))>(N,multivector(t...));}
template <class T> void corner(bool flg, T hoge) {if (flg) {cout << hoge << endl; exit(0);}}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj) {o << "{"; for (auto &x : obj) o << " {" << x.first << " : " << x.second << "}" << ","; o << " }"; return o;}
template <class T>ostream &operator<<(ostream &o, const set<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const multiset<T>&obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr) o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
template <class T>ostream &operator<<(ostream &o, const vector<T>&obj) {o << "{"; for (int i = 0; i < (int)obj.size(); ++i)o << (i > 0 ? ", " : "") << obj[i]; o << "}"; return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&obj) {o << "{" << obj.first << ", " << obj.second << "}"; return o;}
template <template <class tmp>  class T, class U> ostream &operator<<(ostream &o, const T<U> &obj) {o << "{"; for (auto itr = obj.begin(); itr != obj.end(); ++itr)o << (itr != obj.begin() ? ", " : "") << *itr; o << "}"; return o;}
void print(void) {cout << endl;}
template <class Head> void print(Head&& head) {cout << head;print();}
template <class Head, class... Tail> void print(Head&& head, Tail&&... tail) {cout << head << " ";print(forward<Tail>(tail)...);}
template <class T> void chmax(T& a, const T b){a=max(a,b);}
template <class T> void chmin(T& a, const T b){a=min(a,b);}
void YN(bool flg) {cout << (flg ? "YES" : "NO") << endl;}
void Yn(bool flg) {cout << (flg ? "Yes" : "No") << endl;}
void yn(bool flg) {cout << (flg ? "yes" : "no") << endl;}


int main() {
	int A,B; cin >> A >> B;
	vector<int> c(4,1);
	c[A] = c[B] = 0;
	for(int i = 1; i <= 3; ++i) if(c[i]) cout << i << endl;
	


	return 0;
	
}


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

bool including(const std::pair<int, int> &a, const std::pair<int, int> &b) {
  return (a.first <= b.first) && (b.second <= a.second);
//  return (b.second <= a.second);
}
bool intersecting(const std::pair<int, int> &a, const std::pair<int, int> &b) {
  //  return (a.first <= b.first) && (b.first < a.second);
  return (b.first < a.second);
}

int getMinBridgeNum(const int n,
                    const std::vector<std::pair<int, int>> &demands) {
  auto sorted_demands = demands;
  std::sort(sorted_demands.begin(), sorted_demands.end(),
            [](const std::pair<int, int> &l, const std::pair<int, int> &r) {
              if (l.first != r.first) {
                return l.first < r.first;
              } else {
                return l.second > r.second;
              }
            });
  int total = 1;
  std::pair<int, int> current = sorted_demands[0];
  for (int i = 0; i < sorted_demands.size() - 1; ++i) {
    if (including(current, sorted_demands[i + 1])) {
      current = sorted_demands[i + 1];
    } else if (including(sorted_demands[i + 1], current)) {
      // do nothing
    } else if (intersecting(current, sorted_demands[i + 1])) {
      current = {sorted_demands[i + 1].first, current.second};
    } else {
      total += 1;
      current = sorted_demands[i + 1];
    }
  }
  return total;
}

int main() {
  int n;
  int m;
  std::cin >> n >> m;
  std::vector<std::pair<int, int>> demands(m);
  for (int i = 0; i < m; ++i) {
    std::cin >> demands[i].first >> demands[i].second;
  }
  std::cout << getMinBridgeNum(n, demands) << std::endl;
  return 0;
}


Measured memory_bytes: 1792
import java.util.Collections;
import java.util.HashMap;
import java.util.Scanner;

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

    void solve(Scanner sc) {
        int n = sc.nextInt();
        String[] ss = new String[n];
        HashMap<String, Integer> sMap = new HashMap<>();
        for (int i = 0; i < n; i++) {
            String key = sc.next();
            sMap.put(key, sMap.getOrDefault(key, 0) + 1);
        }
        int m = sc.nextInt();
        for (int i = 0; i < m; i++) {
            String key = sc.next();
            sMap.put(key, sMap.getOrDefault(key, 0) - 1);
        }
        int max = Collections.max(sMap.values());
        System.out.println(Math.max(max, 0));
    }
}

Measured memory_bytes: 23252
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
double a[1000001],b[1000001];
int main()
{
     double sum,n,x;
     while(scanf("%lf%lf",&n,&x)==2)
     {
          for(int i=1;i<=n;i++)
               scanf("%lf",&a[i]),b[i]=a[i];
          if(a[1]+a[2]>x)
          {
               sum=a[1]+a[2]-x;
               if(x-a[1]>0)
               a[2]=x-a[1];
               else a[2]=0;
          }
          else sum=0;
          for(int i=3;i<=n;i++)
          {
               if(a[i]>(x-a[i-1]))
               a[i]=x-a[i-1];
              //printf("%d\n",a[i]);
               if(b[i]>a[i])
               {
                    sum=sum+b[i]-a[i];
               }
          }
          printf("%.0lf\n",sum);
     }
    return 0;
}



Measured memory_bytes: 1792
#define	_USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <functional>
#include <vector>
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cfloat>
#include <map>
#include <queue>
#include <stack>
#include <list>
#include <string>
#include <set>
#include <complex>
#include <utility>
#define  rep(i,n) for(int i=0;i<(n);i++)
#define  REP(i,n) for(int i=1;i<(n);i++)
#define  rrep(i,n) for(int i=(n)-1;i>=0;i--)
#define  VI	vector<int>
#define	 VS vector<string>
#define  all(a) (a).begin(),(a).end()
#define  debug(x) cout<<#x<<": "<<x<<endl
using namespace std;
typedef pair<int,int> P;
int main(){
	
	int n;
	while(cin>>n,n!=0){
		vector<int> s(n,0);
		vector<int> p(n,0);
		int count=0;
		rep(i,n)
			cin>>s[i];
		
		bool f=false;
		while(!f){
			f=true;
			map<int,int> m;
			
			rep(i,n){
				if(m.count(s[i])==0){
					m[s[i]]=1;
				}
				else
					m[s[i]]++;
			}
			rep(i,n)
				p[i]=m[s[i]];
			
			rep(i,n){
				if(p[i]!=s[i])
					f=false;
				
			}
			if(!f){
				rep(i,n)
					s[i]=p[i];
			count++;}
		}
		cout<<count<<endl;
		cout<<s[0];
		REP(i,n)
			cout<<" "<<s[i];
		cout<<endl;
		
	}
	
}

Measured memory_bytes: 1196
import bisect

def main():
    N = int(input())
    S = input()
    R, G, B = [], [], []
    for i, s in enumerate(S):
        if s == 'R':
            R.append(i)
        elif s == 'G':
            G.append(i)
        else:
            B.append(i)

    global ans
    ans = 0
    count(R, G, B)
    count(R, B, G)
    count(G, R, B)
    count(G, B, R)
    count(B, R, G)
    count(B, G, R)
    print(ans)


def count(I, J, K):
    global ans
    for j in J:
        i_list = I[:bisect.bisect_left(I, j)]
        k_list = set(K[bisect.bisect_right(K, j):])
        remove = len([i for i in i_list if (2 * j - i) in k_list])
        ans += len(i_list) * len(k_list) - remove


if __name__ == '__main__':
    main()


Measured memory_bytes: 93928
n = int(input())
a = list(map(int, input().split()))

MAX = 1000000000000000000
ans = 1

for i in range(n) :
    if (a[i] == 0) :
        print(0)
        exit()

for i in range(n) :
    ans *= a[i]
    if (ans > MAX) :
        print(-1)
        exit()

if (ans > MAX) :
    print(-1)
else :
    print(ans)


Measured memory_bytes: 21716
#include<iostream>
#include<string>
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<vector>
#include<cmath>
#include<utility>
#include<set>
#include<complex>
#include<map>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    ll a,b; cin>>a>>b;
    b=b/2;
    if(a>=b)cout<<b<<endl;
    else {b-=a; ll hoge=b/2;
        if(!hoge)cout<<a<<endl;
        else cout<<a+hoge<<endl;
    }
    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define _overload3(_1, _2, _3, name, ...) name
#define _rep(i, n) repi(i, 0, n)
#define repi(i, a, b) for(int i = int(a); i < int(b); ++i)
#define rep(...) _overload3(__VA_ARGS__, repi, _rep, )(__VA_ARGS__)
#define all(a) (a).begin(), (a).end()
using namespace std;
using ll = long long;
using P = pair<int, int>;
#define SZ(x) ((int)(x).size())
#define bit(n) (1LL << (n))
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end());

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

  double n,m;
  cin >> n >> m;

  vector<int> a(n);
  double sum = 0;
  rep(i,n) {
    int aa;
    cin >> aa;
    sum += aa;
    a[i] = aa;
  }

  sum = sum / 4 / m;
  
  int ans = 0;
  rep(i,n) {
    if (a[i] >= sum) {
      ans++;
    }
  }

  cout << ((ans >= m) ? "Yes" : "No") << endl;

  return 0;
}


Measured memory_bytes: 3708
#include <bits/stdc++.h>
using namespace std;
#define int long long
const int MOD = 1000000007;

signed main() {
 int n,a,b;
 cin>>n>>a>>b;
 pair<int,int> dp[n][n+1];
 int v[n];
for(int i=0;i<n;i++)cin>>v[i];
dp[0][0]=make_pair(0,1);
dp[0][1]=make_pair(v[0],1);
for(int i=1;i<n;i++){
  dp[i][0]=make_pair(0,1);
  for(int j=1;j<=i;j++){
    if(dp[i-1][j-1].first+v[i]>dp[i-1][j].first)dp[i][j]=make_pair(dp[i-1][j-1].first+v[i],dp[i-1][j-1].second);
    else{
      if(dp[i-1][j-1].first+v[i]<dp[i-1][j].first)dp[i][j]=dp[i-1][j];
      else dp[i][j]=make_pair(dp[i-1][j-1].first+v[i],dp[i-1][j-1].second+dp[i-1][j].second);
    }
  }
  dp[i][i+1]=make_pair(dp[i-1][i].first+v[i],1);
}
int ans2=a;
pair<int,int> ans1=dp[n-1][a];
for(int i=a+1;i<=b;i++){
  if(i*ans1.first<ans2*dp[n-1][i].first){
    ans1=dp[n-1][i];
    ans2=i;
  }else{
    if(i*ans1.first==ans2*dp[n-1][i].first)ans1.second+=dp[n-1][i].second;
  }
}
//cerr<<ans1.first<<' '<<ans2<<' '<<ans1.second<<endl;
cout<< std::setprecision(23) <<double(ans1.first)/double(ans2)<<endl<<ans1.second;
return 0;
}


Measured memory_bytes: 256
//B
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		String xs = sc.next();
      	long x = Long.parseLong(xs);
		long count = 100;
		int max = 10000000;
		
		for (int i = 0; i < max; i++) {
			count = (long)((double)count * 1.01);
			if (count >= x) {
				System.out.println(i + 1);
				break;
			}
		}
	}
}

Measured memory_bytes: 35712
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
const lint mod = 1000000007;
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl((lint)(n))
#define fcout cout << fixed << setprecision(15)
#define highest(x) (63 - __builtin_clzl(x))
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
lint power(lint base, lint exponent, lint module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ lint root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position mv[4] = {{0, -1}, {1, 0}, {0, 1}, {-1, 0}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); } string to_string(string x){ return x; }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++) ans += to_string(*i) + " "; if(!ans.empty()) ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr first, itr last){ for(auto i = first; i != last; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
struct combination{ vector<lint> fact, inv; combination(int sz) : fact(sz + 1), inv(sz + 1){ fact[0] = 1; for(int i = 1; i <= sz; i++){ fact[i] = fact[i - 1] * i % mod; } inv[sz] = power(fact[sz], mod - 2, mod); for(int i = sz - 1; i >= 0; i--){ inv[i] = inv[i + 1] * (i + 1) % mod; } } lint C(int p, int q) const{ if(q < 0 || p < q) return 0; return (fact[p] * inv[q] % mod * inv[p - q] % mod); } };
template<class itr> bool next_sequence(itr first, itr last, int max_bound){ itr now = last; while(now != first){ now--; (*now)++; if((*now) == max_bound){ (*now) = 0; }else{ return true; } } return false; }
template<class itr, class itr2> bool next_sequence2(itr first, itr last, itr2 first2, itr2 last2){ itr now = last; itr2 now2 = last2; while(now != first){ now--, now2--; (*now)++; if((*now) == (*now2)){ (*now) = 0; }else{ return true; } } return false; }

int main(){
    int N;
    cin >> N;
    cout << N * N << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define fi first
#define se second
#define sz(a)  int((a).size())
#define pb  push_back
#define eb  emplace_back
#define FOR(var,from,to) for(int var=(from);var<=(to);++var)
#define rep(var,n)  for(int var=0;var<(n);++var)
#define rep1(var,n)  for(int var=1;var<=(n);++var)
#define repC2(vari,varj,n)  for(int vari=0;vari<(n)-1;++vari)for(int varj=vari+1;varj<(n);++varj)
#define repC3(vari,varj,vark,n)  for(int vari=0;vari<(n)-2;++vari)for(int varj=vari+1;varj<(n)-1;++varj)for(int vark=varj+1;vark<(n);++vark)
#define ALL(c)  (c).begin(),(c).end()
#define RALL(c)  (c).rbegin(),(c).rend()
#define tr(i,c)  for(auto i=(c).begin(); i!=(c).end(); ++i)
#define mset(arr,val)  memset(arr,val,sizeof(arr))
#define mid(x,y) ((x)+((y)-(x))/2)
#define IN(x,a,b) ((a)<=(x)&&(x)<=(b))
using namespace std;
template<typename T> void Out(T x) { cout << x << endl; }
template<typename T1, typename T2> void Ans(bool f, T1 y, T2 n) { if(f) Out(y); else Out(n); }


int main() {
    ll L,R;
    int ans=2019;
    cin>>L>>R;
    if(R-L>=2019){
        Out(0);
        return 0;
    }

    if(L%2019>R%2019){
        Out(0);
        return 0;
    }
    FOR(i,L%2019,R%2019-1){
        FOR(j,i+1,R%2019)
        if(((i%2019)*(j%2019))%2019<ans)
            ans=((i%2019)*((j)%2019))%2019;
    }
    Out(ans);
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int N=30;
string s;
bool vis[30];
int main()
{
    cin>>s;
    if(s.size()<26)
    {
        for(int i=0;i<s.size();i++)
            vis[s[i]-'a']=true;
        cout<<s;
        for(int i=0;i<26;i++)
            if(!vis[i])
        {cout<<(char)(i+'a');return 0;}
    }
    else
    {
        for(int i=0;i<s.size();i++)
            vis[s[i]-'a']=true;
        for(int i=s.size()-1;i>=0;i--)
        {
            for(int j=s[i]-'a'+1;j<26;j++)
                if(!vis[j])
            {
                for(int k=0;k<i;k++)
                    cout<<s[k];
                cout<<(char)(j+'a');
                return 0;
            }
            vis[s[i]-'a']=false;
        }
        cout<<-1<<endl;
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{
  int a,b,c;
  cin>>a>>b>>c;
  int A[a];
  int B[b];
  int min=0,temp=INT_MAX;
	for(int i=0;i<a;i++)
    {
      cin>>A[i];
      if(temp>A[i])
        temp=A[i];
    }
  min=temp; temp=INT_MAX;
   for(int i=0;i<b;i++)
   {
     cin>>B[i];
     if(temp>B[i])
		temp=B[i];
   }
  min+=temp;
  	for(int i=0;i<c;i++)
    {
      cin>>a>>b>>temp;
      temp=A[a-1]+B[b-1]-temp;
      if(temp<min)
        min=temp;
    }
  cout<<min<<endl;
}

Measured memory_bytes: 1024
package main

import (
	"bufio"
	"container/heap"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func nextInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func nextLine() string {
	sc.Scan()
	return sc.Text()
}

type PriorityQueue []int

func (pq PriorityQueue) Len() int            { return len(pq) }
func (pq PriorityQueue) Less(i, j int) bool  { return pq[i] > pq[j] }
func (pq PriorityQueue) Swap(i, j int)       { pq[i], pq[j] = pq[j], pq[i] }
func (pq *PriorityQueue) Push(x interface{}) { *pq = append(*pq, x.(int)) }
func (pq *PriorityQueue) Pop() interface{} {
	old := *pq
	n := len(old)
	x := old[n-1]
	*pq = old[0 : n-1]
	return x
}

func main() {
	sc.Split(bufio.ScanWords)

	N, M := nextInt(), nextInt()
	ts := make(map[int][]int)

	for i := 0; i < N; i++ {
		a, b := nextInt(), nextInt()
		ts[a] = append(ts[a], b)
	}

	pq := make(PriorityQueue, 0, N)
	heap.Init(&pq)
	ans := 0
	for i := 1; i <= M; i++ {
		if _, ok := ts[i]; ok {
			for _, v := range ts[i] {
				heap.Push(&pq, v)
			}
		}
		if len(pq) > 0 {
			ans += heap.Pop(&pq).(int)
		}
	}
	fmt.Println(ans)
}


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

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

    if(b<10){
        c = 10*a + b;
    }else if(b<100){
        c = 100*a + b;
    }else{
        c = 1000*a + b;
    }

    d = sqrt(c);
    if( ((int)d)*((int)d) == c) cout << "Yes";
    else cout << "No";

    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<string>
using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef long long ll;
typedef long double ld;

#define rep(i,x) for(int i = 0 ; i < x ; i ++)
#define rep1(i,x) for(int i = 1 ; i <= x ; i ++)
#define rrep(i,x) for(int i = x-1 ; i >= 0 ; i --)
#define rrep1(i,x) for(int i = x ; i > 0 ; i --)
#define fr first
#define sc second
#define pb push_back

const int INF = 1000000000;

int main(){
	while(1){
		int d,n;
		int a[102],e[102],r[102];
		scanf("%d%d",&d,&n);
		if(d == 0 && n == 0)break;
		rep(i,n){
			scanf("%d%d%d",&a[i],&e[i],&r[i]);
		}
		int c[102][102];
		rep(i,102)rep(j,102){
			c[i][j] = INF;
		}
		c[0][0] = 0;
		rep(i,d)rep(j,101){
			if(c[i][j] == INF)continue;
			rep(k,n){
				if(j < r[k])continue;
				c[min(d,i+a[k])][min(100,j+e[k])] = min ( c[min(d,i+a[k])][min(100,j+e[k])] , c[i][j]+1 );
			}
		}
		int ret = INF;
		rep(j,101)ret = min ( ret , c[d][j] );
		if(ret == INF)puts("NA");
		else printf("%d\n",ret);
	}
}

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

using namespace std;

#define forn(i,n) for ( int i=0 ; i < n ; i++ )
#define all(a) (a).begin(), (a).end()
#define lb lower_bound
#define ub upper_bound
#define vi vector<int >
#define pii pair<int, int>
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define SQ(a) (a)*(a)
#define ll long long
#define lli long long int
#define ull unsigned long long
#define endl '\n'
#define Pi(a) printf("%d\n",a);
#define debug2(a,b) printf("%d\t%d\n",a,b);
#define debug1(a) printf("%d\n",a);
#define Si(a) scanf("%d",&a);
#define mod 1000000007
#define w(n) while(n--)



int main()
{
	ios::sync_with_stdio(0);
	cin.tie(0);
	string s;
	cin >> s;
	int w;
	cin >> w;
	
	int i=0;
	while(i<s.length()){
		cout << s[i];
		i+=w;
	}
	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()

using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
using P = pair<int,int>;

vector<int>bitSearch(int bit,int n){
    vector<int>S;
    rep(i,n)if(bit&(1<<i))S.push_back(i);
    return S;
}


int d[3] = {-1,0,1};
int main(){
    string s;cin>>s;
    int n = s.size();
    int a,z;
    rep(i,n){
        if(s[i]=='A'){
            a = i;
            break;
        }
    }
    reverse(ALL(s));
    rep(i,n){
        if(s[i]=='Z'){
            z = n-i;
            break;
        }
    }
    cout<<z-a;
}



Measured memory_bytes: 640
// AtCoder Beginner Contest 155 C.cpp

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int n, count = 0, co = 0;
	cin >> n;
	vector<string>a(n);
	vector<string>answer;
	for (auto& i : a)
		cin >> i;
	sort(a.begin(), a.end());

	string temp = a[0];
	vector<string>b(n);
	vector<int>c(n, 0);

	for (auto i : a) {
		if (i != temp) {
			b[count] = temp;
			count++;
			temp = i;
		}
		c[count]++;
	}
	b[count] = temp;
	for (int i = 0; i <= count; i++) {
		if (co < c[i])
			co = c[i];
	}

	/*cout << "co = " << co << endl;
	for (int i = 1; i <= count; i++) {
		cout << "b[" << i << "] = " << b[i] << endl;
		cout << "c[" << i << "] = " << c[i] << endl;
	}*/

	for (int i = 0; i <= count; i++) {
		if (co == c[i])
			answer.push_back(b[i]);
	}
	sort(answer.begin(), answer.end());
	for (auto i : answer) {
		cout << i << endl;
	}
}

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

#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define ppi pair<int, int>
#define endl "\n"
#define nl cout << "\n"
#define deb(x) cout << #x << " " << x << endl;

const int N = 1010;
const int mod = 1e9 + 7;
int H, W;
char grid[N][N];

// dp[i][j] = #Ways to reach from (i, j) to (H, W)
int dp[N][N];

int Top_Down(int x = 1, int y = 1) {
    // Base Case
    if(x == H && y == W) return (dp[x][y] = 1);
    // Choice
    if(dp[x][y] != -1) return dp[x][y];
    int ways = 0;
    if(x <= H && grid[x+1][y] == '.') ways += Top_Down(x+1, y)%(mod);
    if(y <= W && grid[x][y+1] == '.') ways += Top_Down(x, y+1)%(mod);
    return (dp[x][y]=ways%(mod));
}

int32_t main() {
    IOS;
    memset(dp, -1, sizeof(dp));
    cin >> H >> W;
    for(int i = 1; i <= H; ++i) 
        for(int j = 1; j <= W; ++j) {
            cin >> grid[i][j];
        }
    //
    cout << Top_Down()%(mod) << endl;
    // for(int i = 1; i <= H; ++i){
    //     for(int j = 1; j <= W; ++j) cout << dp[i][j] << " ";
    //     cout << endl;
    // }
}

Measured memory_bytes: 9344
import java.util.*;	 
	public class Main {
	    Scanner sc = new Scanner(System.in);
	    void work(){
	        for(;;){
	            int n = sc.nextInt();
	            int r = sc.nextInt();	             
	            if((n|r) ==0) {
	                break;
	            }	             
	            int[] input = new int[n];
	            for(int i = 0; i < n ; i++){
	                input[i] = n - i;
	            }	             
	            for(int i = 0; i < r ; i++){
	                int p = sc.nextInt()-1;
	                int c = sc.nextInt();                 
	                int[] deck = input.clone();	                 
	                for(int j = 0 ; j < c ; j++){
	                    deck[j] = input[j+p];
	                }
	                for(int j = 0; j < p ; j ++){
	                    deck[j+c] = input[j];
	                }
	                input = deck;
	            }
	            System.out.println(input[0]);
	        }
	         
	    }
	    public static void main(String[] args){
	    	Main Misson_work = new Main();
	        Misson_work.work();
	    }
	}



Measured memory_bytes: 37224
#!/usr/bin/env python
# -*- coding: utf-8 -*-
from __future__ import (division, absolute_import, print_function,
                        unicode_literals)
from sys import stdin

li = []
for line in stdin:
    compress = False
    num = 1
    for c in line:
        if c == '@':
            compress = True
        elif compress:
            compress = False
            num = int(c)
        else:
            li.append(c * num)
            num = 1
print(''.join(li), end='')

Measured memory_bytes: 4252
#include <bits/stdc++.h>
#define rep(i, n) for(ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
const double PI=acos(-1);

template<typename T>
istream& operator>> (istream& is, vector<T> &vec){
    for(T& x: vec) is >> x;
    return is;
}

using graph = vector<vector<ll>>;
vector<ll> x(200000, 0), ans(200000, 0);
vector<bool> seen;
void dfs(const graph &g, int v, int sum = 0){
    seen[v] = true;
    ans[v] = sum + x[v];

    for(auto next : g[v]){
        if(seen[next]) continue;
        dfs(g, next, ans[v]);
    }
}

int main(){
    ll n, q; cin >> n >> q;
    graph g(n+1);
    
    rep(i, n-1){
        ll a, b; cin >> a >> b;
        g[a].push_back(b);
        g[b].push_back(a);
    }
    rep(i, q){
        ll p, xi; cin >> p >> xi;
        x[p] += xi;
    }

    seen.assign(n+1, false);
    dfs(g, 1);

    rep(i, n+1){
        if(i == 0) continue;
        if(i > 1) cout << " ";
        cout << ans[i];
    }
    cout << endl;

    return 0;
}

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

int main()
{
    int A, B, C;
    cin >> A >> B >> C;

    if (A + B >= C){
        cout << "Yes" << endl;
        return (0);
    }
    else {
        cout << "No" << endl;
        return (0);
    }
}


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

ll countDigits(ll n) {
	ll count=0;
	while (n>0) {
		n/=10;
		count++;
	}
	return count;
}

ll F(ll a, ll b) {
	ll digits1 = countDigits(a);
	ll digits2 = countDigits(b);
	return max(digits1, digits2);
}

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

	ll min = countDigits(n);
	for (ll i=1ll; i*i<=n; i++) {
		if (n%i) continue;
		ll digits = F(i,n/i);
		if (digits < min)
			min = digits;
	}
	cout << min << endl;
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main()
{

    char str[100],str1[101], temp;
    int i=0, j;
    cin>>str>>str1;
    i=0;
    j=strlen(str)-1;
    while(i<j)
    {
        temp=str[i];
        str[i]=str[j];
        str[j]=temp;
        i++;
        j--;
    }
    if(strcmp(str, str1)==0)
    {
        cout<<"YES"<<endl;
    }
    else
    {
        cout<<"NO"<<endl;
    }
   return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i, N) for (int i = 0; i < (int)N; ++i)
#define all(a) (a).begin(), (a).end()
template <int MOD>
class ModInt {
  long long x;

 public:
  ModInt(long long v = 0) : x(v % MOD) {
    if (x < 0) v += MOD;
  }

  ModInt& operator+=(const ModInt& r) {
    x += r.x;
    if (x >= MOD) x -= MOD;
    return *this;
  }

  ModInt& operator-=(const ModInt& r) {
    x -= r.x;
    if (x < 0) x += MOD;
    return *this;
  }
  ModInt& operator*=(const ModInt& r) {
    x = x * r.x % MOD;
    return *this;
  }
  ModInt& operator/=(const ModInt& r) {
    *this *= r.inverse();
    return *this;
  }

  ModInt operator-() const { return ModInt(-x); }

  ModInt operator+(const ModInt& r) const { return ModInt(*this) += r; }
  ModInt operator-(const ModInt& r) const { return ModInt(*this) -= r; }
  ModInt operator*(const ModInt& r) const { return ModInt(*this) *= r; }
  ModInt operator/(const ModInt& r) const { return ModInt(*this) /= r; }
  bool operator==(const ModInt& r) const { return x == r.x; }
  bool operator!=(const ModInt& r) const { return x != r.x; }

  ModInt inverse() const {
    long long a = x, b = MOD, u = 1, v = 0, t;
    while (b > 0) {
      t = a / b;
      swap(a -= t * b, b);
      swap(u -= t * v, v);
    }
    return ModInt(u);
  }

  ModInt<MOD> pow(long long n) const {
    ModInt ret(1), mul(x);
    while (n > 0) {
      if (n & 1) ret *= mul;
      mul *= mul;
      n >>= 1;
    }
    return ret;
  }

  friend ostream& operator<<(ostream& os, const ModInt& x) { return os << x.x; }

  friend istream& operator>>(istream& is, ModInt& x) { return is >> x.x; }

  int getMod() { return MOD; }
};

const int MOD = 998244353;
using mint = ModInt<MOD>;

int N;
string X;
int main() {
  cin >> N >> X;

  X += X;
  rep(i, N) X[i + N] = X[i] == '0' ? '1' : '0';

  vector<int> periods;
  for (int r = 1; r <= sqrt(N); ++r) {
    if (N % r != 0) continue;
    int k = N / r;

    if (k % 2 != 0) periods.push_back(r);
    if (k != r && r % 2 != 0) periods.push_back(k);
  }
  sort(all(periods));

  mint two(2);
  vector<mint> c(periods.size(), 0);
  rep(i, periods.size()) {
    int t = periods[i];
    string Y = X.substr(0, t);
    string T = Y + Y;
    rep(j, t) T[j + t] = T[j] == '0' ? '1' : '0';
    string S = T;
    while (S.size() < X.size()) S += T;

    rep(d, t) {
      if (Y[t - 1 - d] == '1') c[i] += two.pow(d);
    }
    if (S <= X) c[i] += 1;

    rep(j, i) if (periods[i] % periods[j] == 0) c[i] -= c[j];
  }

  mint ans = 0;
  rep(i, periods.size()) ans += c[i] * (2 * periods[i]);
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 1800
import sys
input = sys.stdin.readline

L, R = map(int, input().split())
if R - L > 2018:
    print(0)
else:
    tmp = []
    for i in range(L, R+1):
        tmp.append(i%2019)
    m = 2019
    for i in range(R-L+1):
        for j in range(i+1, R-L+1):
            m = min(m, (tmp[i]*tmp[j])%2019)
    print(m)


Measured memory_bytes: 3060
#include <string.h>

int main(void){
  int i,j;
  int n,x[11][11];

  while(1){
    scanf("%d",&n);
    if(!n) break;

    memset(x,0,sizeof(x));
    for(i=0;i<n;i++){
      for(j=0;j<=n;j++){
        if(j==n){
          x[n][n] += x[i][j];
        }
        else{
          scanf("%d",&x[i][j]);
          x[i][n] += x[i][j];
          x[n][j] += x[i][j];
        }
      }
    }
    for(i=0;i<=n;i++){
      for(j=0;j<=n;j++){
        printf("%5d",x[i][j]);
      }
      putchar('\n');
    }
  }

  return 0;
}

Measured memory_bytes: 0
#define F first
#define S second
#define EPS 1E-10
using namespace std;
#define pb push_back
#define mp make_pair
#define inf 0x3f3f3f3f
#include <bits/stdc++.h>
#define int64 long long int
#define infl 0x3f3f3f3f3f3f3f3fll
#define uint64 unsigned long long int




const int N = 200010;
int n, a[N];
int64 sum, ssum, ans = infl;

int main ()
{
	scanf ("%d", &n);
	for (int i = 1; i <= n; i++) {
		scanf ("%d", a + i);
		sum += a[i];
	}
	for (int i = 1; i < n; i++) {
		ssum += a[i];
		int64 xy = sum - ssum;
		int64 abb = abs (xy - ssum);
		if (abb < ans) ans = abb;
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 1024
from collections import deque
import heapq
N,M = map(int,input().split())
adj = [ [] for _ in range(N+1) ]
for _ in range(M):
  a,b = map(int,input().split())
  adj[a].append(b)
  adj[b].append(a)

def dijkstra(N):
  signs = [None] * (N+1)
  signs[0] = -1
  steps = [float('inf')] * (N+1)
  visited = [False] * (N+1)

  # step,from,cur_node
  q = [(0, -1, 1)]
  while q:
    step,p,cur_node = heapq.heappop(q)
    steps[cur_node] = step
    signs[cur_node] = p
    visited[cur_node] = True

    for nei in adj[cur_node]:
      if visited[nei]: continue
      if step+1 < steps[nei]:
        steps[nei] = step+1
        heapq.heappush(q, (step+1, cur_node, nei))
  return signs

signs = dijkstra(N)[2:]
if float('inf') in signs:
  print("No")
else:
  print("Yes")
  for s in signs:
    print(s)


Measured memory_bytes: 106948
import java.util.*;

public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		
		int h = scan.nextInt();
		int n = scan.nextInt();
		int a = 0;
		
		for(int i=0;i<n;i++) {
			a += scan.nextInt();
		}
		if(h <= a) {
			System.out.println("Yes");
		}else {
			System.out.println("No");
		}
	}
}




Measured memory_bytes: 46204
#include <bits/stdc++.h>
using namespace std;
typedef signed long long ll;

#undef _P
#define _P(...) (void)printf(__VA_ARGS__)
#define FOR(x,to) for(x=0;x<(to);x++)
#define FORR(x,arr) for(auto& x:arr)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define ALL(a) (a.begin()),(a.end())
#define ZERO(a) memset(a,0,sizeof(a))
#define MINUS(a) memset(a,0xff,sizeof(a))
//-------------------------------------------------------

int N,A[202020];
int L[202020],R[202020];
void solve() {
	int i,j,k,l,r,x,y; string s;
	
	cin>>N;
	for(i=1;i<=N;i++) {
		cin>>A[i];
		L[i]=max(L[i-1],A[i]);
	}
	for(i=N;i>=1;i--) R[i]=max(R[i+1],A[i]);
	
	for(i=1;i<=N;i++) cout<<max(L[i-1],R[i+1])<<endl;
	
}


int main(int argc,char** argv){
	string s;int i;
	if(argc==1) ios::sync_with_stdio(false), cin.tie(0);
	FOR(i,argc-1) s+=argv[i+1],s+='\n'; FOR(i,s.size()) ungetc(s[s.size()-1-i],stdin);
	cout.tie(0); solve(); return 0;
}


Measured memory_bytes: 3968