akhauriyash/Code-Regression huggingface dataset:
//
//AtCoder Beginner Contest 166
//D - I hate Factorization
//

#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>

using namespace std;

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

using ll = long long;

const double PI = 3.14159265358979323846;
const int MOD = 1000000007;

ll gcd(ll x, ll y) { return (x % y)? gcd(y, x % y): y; }
ll lcm(ll x, ll y) { return x / gcd(x, y) * y; }

int main()
{
    ll x;

    cin >> x;

    for(int a = -1000; a<1000; a++){
        for(int b = -1000; b<1000; b++){
            if (pow(a, 5) == x + pow(b,5)) {

                cout << a << " " << b << endl;
            
                return 0;
            }
        }
    }

    
    return 0;
}


Measured memory_bytes: 4068
#include <iostream>

using namespace std;

int main(int argc, char const *argv[]) {
  int n, ans=0;
  cin >> n;
  for (int i = 1; i <= n; i+=2) {
    int cnt = 0;
    for (int j = 1; j <= i; j++) {
      if (i%j==0) cnt++;
    }
    if (cnt == 8 and i%2==1) ans++;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<iostream>
#include<cstring>
#define white 0
#define gray 1
#define black 2
using namespace std;
const int MAXN = 100+10 ;

int a[MAXN][MAXN],flag[MAXN],d[MAXN],f[MAXN],cnt;
int n,u,v,t;

void fun(int x)
{
    flag[x] = gray;
    d[x] = ++cnt;
    for(int i = 1; i <= n; ++i)
    {
        if(a[x][i] && flag[i]==white)
            fun(i);
    }
    flag[x] = black;
    f[x] = ++cnt;
    return;
}

void dfs()
{
    memset(flag,0,sizeof flag);
    for(int i = 1; i <= n; ++i)
    {
        if(flag[i] == white)
            fun(i);
    }
    for(int i = 1; i <= n; ++i)
        cout<<i<<' '<<d[i]<<' '<<f[i]<<'\n';
}
int main(void)
{

    cin>>n;
    for(int i = 1; i <= n; ++i)
    {
        cin>>u>>t;
        for(int j = 1; j <= t; ++j)
        {
            cin>>v;
            a[u][v] = 1;
        }
    }
    dfs();
}



Measured memory_bytes: 3120
// C++ 14
#include <iostream>
#include <string>
#include <vector>
#include <list>
#include <algorithm>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <unordered_map>
#include <math.h>
#include <sstream>
#include <unistd.h>

#define ll long long
#define Int int
#define loop(x, start, end) for(Int x = start; x < end; x++)
#define loopdown(x, start, end) for(int x = start; x > end; x--)
#define rep(n) for(int __x = 0; __x < n; __x++)
#define span(a,x,y) a.begin()+x,a.begin()+y
#define span_all(a) a.begin(),a.end()
#define len(x) (x.size())
#define last(x) (x.at(x.size()-1))

using namespace std;

#define EPS 0.0000000001
#define MOD 1000000007

class Vector2 {
public:
  double x, y;
  
  Vector2(double x = 0, double y = 0): x(x), y(y) {}
  
  Vector2 operator + (Vector2 v) { return Vector2(x + v.x, y + v.y); }
  Vector2 operator - (Vector2 v) { return Vector2(x - v.x, y - v.y); }
  Vector2 operator * (double k) { return Vector2(x * k, y * k); }
  Vector2 operator / (double k) { return Vector2(x / k, y / k); }
  
  double length() { return sqrt(norm()); }
  double norm() { return x * x + y * y; }
  double dot (Vector2 v) { return x * v.x + y * v.y; }
  double cross (Vector2 v) { return x * v.y - y * v.x; }
  
  bool operator < (const Vector2 &v) const {
    return x != v.x ? x < v.x : y < v.y;
  }
  
  bool operator == (const Vector2 &v) const {
    return fabs(x - v.x) < EPS && fabs(y - v.y) < EPS;
  }
};

ostream & operator << (ostream & out, Vector2 const & v) { 
  out<< "Vector2(" << v.x << ", " << v.y << ')';
  return out;
}

istream & operator >> (istream & in, Vector2 & v) { 
  double x, y;
  in >> x;
  in >> y;
  v.x = x;
  v.y = y;
  return in;
}

#define MAX_N 8
#define MAX_M (8*7*0.5)

Int N, M;
vector<vector<Int> > G(MAX_N, vector<Int>(MAX_N, 0));

void input() {
  cin >> N >> M;
  Int u, v;
  loop(m,0,M) {
    cin >> u >> v;
    u--,v--;
    G.at(u).at(v) = 1;
    G.at(v).at(u) = 1;
  }
}

Int bit() {
  vector<Int> path;
  loop(n,0,N) path.push_back(n);
  Int numPaths = 0;
  do {
    bool ok = true;
    loop(i,1,path.size()) {
      if (!G.at(path.at(i-1)).at(path.at(i))) {
        ok = false;
        break;
      }
    }
    if (ok) numPaths++;
  } while (next_permutation(path.begin()+1, path.end()));
  return numPaths;
}

void solve() {
  cout << endl;
  cout << bit() << endl;
}

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


Measured memory_bytes: 256
def main():
    N = int(input())
    d = {}
    for i in range(0,10):
        for j in range(0,10):
            d[i*10+j] = 0
    
    for i in range(N+1):
        s = str(i)
        d[int(s[0])*10+int(s[-1])] += 1
    
    ans = 0
    for i in range(1,10):
        for j in range(1,10):
            ans += d[i*10+j] *d[j*10+i]

    print(ans)

if __name__ == '__main__':
    main()

Measured memory_bytes: 67828
#include<bits/stdc++.h>
using namespace std;
int i,j,n,m,c,d,a,b,e;
int s[210000];
int main(){
  for(cin>>n;i<n;i++)cin>>s[i];
  sort(s,s+i);
  for(j=0;j<n-1;j++)if(s[j]==s[j+1])return cout<<"NO",0;
  cout<<"YES",0;
}

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

typedef vector<int> vi;
typedef vector<bool> vb;
typedef pair<int,int> pii;
typedef vector<pair<int,int> > vpii;
typedef vector<vector<bool> > vvb;
typedef vector<vector<int> > vvi;
typedef map<int, bool> mib;

typedef long long ll;
typedef vector<long long> vl;
typedef pair<long long,long long> pll;
typedef vector<pair<long long,long long> > vpll;

typedef vector<string> vs;

typedef long double ld;

#define _GLIBCXX_DEBUG

#define REP(i,n) for (int i = 0; i < (n); ++i)
#define REPD(i,n) for (int i = (n-1); i >= 0; --i)
#define FORE(i, s, n) for (int i = (s); i <= (int)(n); i++)
#define FORED(i, s, n) for (int i = (s); i >= (int)(n); i--)
#define debug(x) cerr << #x << ": " << x << '\n'
#define debug2(x, y) cerr << #x << ": " << x << ", " << #y << ": " << y << '\n'
#define debug3(x, y, z) cerr << #x << ": " << x << ", " << #y << ": " << y << ", " << #z << ": " << z << '\n'
#define debugs(s) cerr << s << "\n"
#define hyphen() cerr << "--\n"

#define ALL(vec) (vec).begin(), (vec).end()
#define REVALL(vec) (vec).rbegin(), (vec).rend()

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

#define fst first
#define snd second
#define pb push_back
#define mk(x,y) make_pair((x),(y))

// http://ehafib.hatenablog.com/entry/2015/12/23/164137
int qp(int a,ll b){int ans=1;do{if(b&1)ans=1ll*ans*a;a=1ll*a*a;}while(b>>=1);return ans;}
int qpm(int a,ll b,int mo){int ans=1;do{if(b&1)ans=1ll*ans*a%mo;a=1ll*a*a%mo;}while(b>>=1);return ans;}
// gcd : O(logN)
int gcd(int a,int b){return b?gcd(b,a%b):a;}
int lcm(int a, int b) { return a / gcd(a, b) * b; }

#define sz(v) int(v.size())

// x1, x2ライブラリとの被りを避ける
#define x1 x192837465
#define x2 x123456789
#define y1 y192837465
#define y2 y123456789

// typo
#define itn int
#define reutrn return
#define reutnr return
#define srting string

#define make(type, x) type x; cin>>x;
#define make2(type, x, y) type x, y; cin>>x>>y;
#define make3(type, x, y, z) type x, y, z; cin>>x>>y>>z;
#define make4(type, x, y, z, t) type x, y, z, t; cin>>x>>y>>z>>t;

int ctoi(const char c){
    if('0' <= c && c <= '9') return (c-'0');
    return -1;
}

#define uniq(v) (v).erase(unique(ALL((v))), (v).end());

// area of (0, 0)(a, b)(c, d)
double area(double a, double b, double c, double d){
    return abs(a * d - b * c) / 2.0;
}

const int PREC = 10;
#define coutf(val) cout << fixed << setprecision(PREC) << (val) << endl;

const int MOD = (int)1e9 + 7;
const int INF = numeric_limits<int>::max();

signed main() {
    make(string, S);

    string ans = "";

    for (auto c : S) {
        debug(c);
        if (c == '0' || c == '1'){
            ans += c;
        } else {
            if (sz(ans) > 0) {
                ans.pop_back();
            }
        }
        debug(ans);
    }
    cout << ans << endl;
}


Measured memory_bytes: 3624
#include<stdio.h>

int main(){
  int m,n,l,i,x,f,y;

  for(;;){
    scanf("%d",&l);
    if(l==0)
      break;
    x=0;
    f=1;

    for(i=0;i<12;i++){
      scanf("%d%d",&m,&n);
      x += m-n;
      if(f){
	if(x>=l){
	  y=i+1;
	  f=0;
	}
      }
    }
    if(f)
      printf("NA\n");
    else
      printf("%d\n",y);
  }
  return 0;
}

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

const int MAXT = -10e10;
int n, t, a, sol, temp;
//vector <int> v;
int last = -MAXT;

int main () {

    cin >> n >> t;
    sol = 0;
    for (int i = 0; i < n; i++) {
        scanf("%d", &temp);
        sol += t;
        sol -= max(0, last + t - temp);
        last = temp;
        //cout << sol << endl;
    }
    cout << sol;



    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define f first
#define s second
#define pb push_back
#define pi acos(-1)

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    
    int n, m;
    ll sum = 0, ans = 0;
    cin >> m >> n;
    int arr[n+5];
    for(int i = 0; i < n; i++)
    {
        cin >> arr[i];
        sum += arr[i];
    }
    if(sum > m)
        ans = -1;
    else
        ans = m-sum;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3688
#include <iostream>
#include <cstdio>
#include <vector>
#include <algorithm>
#include <complex>
#include <cstring>
#include <cstdlib>
#include <string>
#include <cmath>
#include <queue>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)n;++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 1<<30;

int main() {
  int w;
  while(cin>>w,w!=-1) {
    int res = 1150;
    REP(i,w+1) {
      if (i>10 && i<=20) res += 125;
      else if (i>20 && i<=30) res += 140;
      else if (i>30) res += 160;
    }
    cout << 4280 - res << endl;
  }
}

Measured memory_bytes: 0
#include<iostream>
using namespace std;
int main()
{
	long a,b,x,ans;cin>>a>>b>>x;
	if(a==0)cout<<b/x+1<<endl;
	else if(a%x==0)cout<<b/x-a/x+1<<endl;
	else cout<<b/x-a/x<<endl;
	return 0;
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES

#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <vector>
#include <queue>
#include <map>
#include <list>
#include <stack>

using namespace std;

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

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

int N;
vector<int> E[210000];
bool flag[210000] = {};
long long int grundy[210000], grundy_[210000];

long long int func(int pos, int pre, int start){
	if(grundy[pos] != -1){
		return grundy[pos];
	}
	if(pos == start && pre != -1){
		return INF;
	}
	vector<long long int> ret;
	for(int i = 0; i < E[pos].size(); i++){
		long long int S = func(E[pos][i], pos, start);
		ret.push_back(S);
	}
	for(int i = 0; i < ret.size(); i++){
		if(ret[i] == INF){
			for(int j = 0; j < i; j++){
				flag[ret[j]] = false;
			}
			grundy[pos] = INF;
			return INF;
		}else{
			flag[ret[i]] = true;
		}
	}
	int val;
	for(int i = 0; i <= N; i++){
		if(!flag[i]){
			grundy[pos] = i;
			val = i;
			break;
		}
	}
	for(int i = 0; i < ret.size(); i++){
		flag[ret[i]] = false;
	}
	return val;
}

long long int func2(int pos){
	if(grundy_[pos] != -1 && grundy_[pos] != INF){
		return grundy_[pos];
	}
	vector<long long int> ret;
	for(int i = 0; i < E[pos].size(); i++){
		long long int S = func2(E[pos][i]);
		ret.push_back(S);
	}
	for(int i = 0; i < ret.size(); i++){
		flag[ret[i]] = true;
	}
	int val;
	for(int i = 0; i <= N; i++){
		if(!flag[i]){
			grundy_[pos] = i;
			val = i;
			break;
		}
	}
	for(int i = 0; i < ret.size(); i++){
		flag[ret[i]] = false;
	}
	return val;
}

int main(){
	
	cin >> N;
	
	for(int i = 1; i <= N; i++){
		int p;
		cin >> p;
		E[p].push_back(i);
	}
	
	for(int i = 0; i <= N; i++){
		grundy[i] = -1;
	}
	
	long long int pos, nex;
	for(int i = 0; i <= N; i++){
		if(grundy[i] == -1){
			long long int ret = func(i, -1, i);
			if(ret == INF){
				pos = i;
				break;
			}
		}
	}
	
	
	bool ff[210000] = {};
	for(int i = 0; i < E[pos].size(); i++){
		if(grundy[E[pos][i]] == INF){
			nex = E[pos][i];
		}else{
			ff[grundy[E[pos][i]]] = true;
		}
	}
	int cnt = 0, pre;
	for(int i = 0; i <= N; i++){
		if(!ff[i]){
			for(int j = 0; j <= N; j++){
				grundy_[j] = grundy[j];
			}
			grundy_[pos] = i;
			func2(nex);
			if(cnt == 0){
				pre = grundy_[pos];
				if(grundy_[pos] != grundy_[nex]){
					cout << "POSSIBLE" << endl;
					return 0;
				}
			}else{
				if(grundy_[nex] == pre){
					cout << "POSSIBLE" << endl;
				}else{
					cout << "IMPOSSIBLE" << endl;
				}
				return 0;
			}
			cnt += 1;
		}
	}
	return 0;
}


Measured memory_bytes: 35200
#pragma GCC optimize("Ofast",3,"inline")
#include<bits/stdc++.h>
using namespace std;
#define fir first
#define sec second
#define m_p make_pair
#define y1 ygftgfgcdtfgxffgx
#define y2 yfdsesgvtyghftfvv
#define x1 xvyr6cf6fgcfgf676
#define x2 xcr6rfc5r66y6r6fr
#define up_bound upper_bound
#define low_bound lower_bound
#define next_per next_permutation
#define pb push_back
#define i_to_s to_string
typedef priority_queue<int> p_queue;
typedef priority_queue<int, vector<int>, greater<int> > min_p_queue;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
int mon[20]={31,28,31,30,31,30,31,31,30,31,30,31};
ll gcd(ll x,ll y){return ((y==0)?x:gcd(y,x%y));}	
int N;
ll K, A[200010], F[200010];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
//	freopen(".in","r",stdin);
//	freopen(".out","w",stdout);
	cin >> N >> K;
	for (int i = 0; i < N; ++i)
		cin >> A[i];
	for (int i = 0; i < N; ++i)
		cin >> F[i];
	sort(A, A + N);
	sort(F, F + N);
	reverse(F, F + N);
	ll l = 0, r = A[N - 1] * F[0], ans;
	while (l <= r){
		ll m = l + r >> 1;
		ll cnt = 0;
		for (int i = 0; i < N; ++i){
			if (A[i] * F[i] > m){
				cnt += A[i] - (m / F[i]);
			}
		}
		if (cnt > K) l = m + 1;
		else { ans = m; r = m - 1; }
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 3328
def read_acm; gets.split.map(&:to_i).inject(:+); end


a = []

while a[0] = read_acm and a[0] != 0
  4.times { |i| a[i+1] = read_acm }
  idx = a.index a.max
  puts %w[A B C D E][idx] + " " + a[idx].to_s
  a.clear
end

Measured memory_bytes: 2740
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;

ll a, b, c, d;
vector<ll> ope(3, 0);

void dfs(ll x, ll num)
{
        ope[num] = x;
        if (num == 2) {
                ll ans = a;
                string S(9, '0'); S[0] = a + '0';
                if (ope[0] == 0) { ans += b; S[1] = '+'; }
                else if (ope[0] == 1) { ans -= b; S[1] = '-'; }
                S[2] = b + '0';
                if (ope[1] == 0) { ans += c; S[3] = '+'; }
                else if (ope[1] == 1) { ans -= c; S[3] = '-'; }
                S[4] = c + '0';
                if (ope[2] == 0) { ans += d; S[5] = '+'; }
                else if (ope[2] == 1) { ans -= d; S[5] = '-'; }
                S[6] = d + '0';
                S[7] = '=';
                S[8] = '7';
#if 1
                if (ans == 7) {
                        cout << S << endl;
                        exit(0);
                }
#endif
                return;
        }

        for (int i = 0; i < 2; ++i) {
                dfs(i, num+1);
        }

}

int main()
{
        string s;
        cin >> s;
        a = s[0] - '0';
        b = s[1] - '0';
        c = s[2] - '0';
        d = s[3] - '0';

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

                dfs(i, 0);

        }



}


Measured memory_bytes: 256
// Problem : A - Frog 1
// Contest : AtCoder - Educational DP Contest
// URL : https://atcoder.jp/contests/dp/tasks/dp_a
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cpeditor)

#include<bits/stdc++.h>
using namespace std;
#define int         long long
#define ull 		unsigned long long
#define ll 			long long
#define MM			1000000007
#define N			100005
#define pb 			push_back
#define p_q 		priority_queue
#define pii         pair<ll,ll>
#define vi          vector<ll>
#define vii         vector<pii>
#define mi          map<ll,ll>
#define mii         map<pii,ll>
#define all(a)      (a).begin(),(a).end()
#define sz(x)       (ll)x.size()
#define endl        '\n'
#define Endl        '\n'
#define gcd(a,b)    __gcd((a),(b))
#define lcm(a,b)    ((a)*(b)) / gcd((a),(b))
#define ios	    	ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define mp 			make_pair
#define lb 			lower_bound
#define ub			upper_bound
#define F           first
#define S           second
#define rep(i, begin, end) for(int i=begin;i<end;i++)
#define repr(i,begin,end) for(int i=end-1;i>=begin;i--)
#define ini(a,n,b)	for(ll int i=0;i<n;i++) a[i]=0;
#define cset(a)		__builtin_popcountll(a)
#define hell 		(ull)1e9
#define re 			resize
 
 
 
signed main(void)
{ios
	int TESTS=1;
	//cin>>TESTS;
	while(TESTS--)
	{
		int n;
		cin>>n;
		int a[n];
		rep(i,0,n) cin>>a[i];
		int dp[n][2];
	    rep(i,0,n) rep(j,0,2) dp[i][j]=INT_MAX;
	    dp[0][1]=0;
	    dp[0][0]=0;
	    dp[1][0]=abs(a[0]-a[1]);
	    rep(i,2,n)
	    {
	        dp[i][0]=min(dp[i-1][0],dp[i-1][1])+abs(a[i]-a[i-1]);
	        dp[i][1]=min(dp[i-2][0],dp[i-2][1])+abs(a[i]-a[i-2]);
	    }
	    cout<<min(dp[n-1][0],dp[n-1][1]);
	}
}

Measured memory_bytes: 5896
#include <stdio.h>
long long smaller(long long a,long long b,long long c){
    return a<b?(c<a?c:a):(c<b?c:b);
}
long long bigger(long long a,long long b,long long c){
    return a>b?(c>a?c:a):(c>b?c:b);
}
int main(void){
    long long n,m,i,tmp,tmp2,min=10000000,a,b,c;
    scanf("%lld %lld",&n,&m);
    for(i=1;i<n;i++){
        a=i*m;
        if(m%2==0){
            b=m/2*(n-i);
            c=b;
        }else{
            b=m/2*(n-i);
            c=(m/2+1)*(n-i);
        }
        tmp=smaller(a,b,c);
        tmp2=bigger(a,b,c);
        //printf("a=%d b=%d c=%d tmp=%d tmp2=%d\n",a,b,c,tmp,tmp2);
        if(tmp2-tmp<min){
            min=tmp2-tmp;
        }
    }
    for(i=1;i<n;i++){
        a=i*m;
        if((n-i)%2==0){
            b=(n-i)/2*m;
            c=b;
        }else{
            b=(n-i)/2*m;
            c=(n-i+1)/2*m;
        }
        tmp=smaller(a,b,c);
        tmp2=bigger(a,b,c);
        //printf("a=%d b=%d c=%d tmp=%d tmp2=%d\n",a,b,c,tmp,tmp2);
        if(tmp2-tmp<min){
            min=tmp2-tmp;
        }
    }
    for(i=1;i<m;i++){
        a=i*n;
        if(n%2==0){
            b=n/2*(m-i);
            c=b;
        }else{
            b=n/2*(m-i);
            c=(n/2+1)*(m-i);
        }
        tmp=smaller(a,b,c);
        tmp2=bigger(a,b,c);
        //printf("a=%d b=%d c=%d tmp=%d tmp2=%d\n",a,b,c,tmp,tmp2);
        if(tmp2-tmp<min){
            min=tmp2-tmp;
        }
    }
    for(i=1;i<m;i++){
        a=i*n;
        if((m-i)%2==0){
            b=(m-i)/2*n;
            c=b;
        }else{
            b=(m-i)/2*n;
            c=(m-i+1)/2*n;
        }
        tmp=smaller(a,b,c);
        tmp2=bigger(a,b,c);
        //printf("a=%d b=%d c=%d tmp=%d tmp2=%d\n",a,b,c,tmp,tmp2);
        if(tmp2-tmp<min){
            min=tmp2-tmp;
        }
    }
    printf("%lld\n",min);
    return 0;
}


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

int main()
{
    int k, s; cin >> k >> s;
    int ans = 0;

    for (int i = 0; i <= k; i++) {
        for (int j = 0; j <= k; j++) {
            if (s >= i + j && s - (i + j) <= k) ans++;
        }
    }

    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
<?php
list($n,$k)=explode(" ",trim(fgets(STDIN)));
$a=explode(" ",trim(fgets(STDIN)));
$ans=0;
$i=0;
while($i<$k){
  $e=($a[$i]+1)/2;
  $ans+=$e;
  $a[$i]=$e;
  ++$i;
}
$sum=$ans;
$j=0;
while($i<$n){
  $e=($a[$i]+1)/2;
  $sum+=$e-$a[$j];
  if($ans<$sum){
    $ans=$sum;
  }
  $a[$i]=$e;
  ++$i;
  ++$j;
}
echo $ans;

Measured memory_bytes: 18932
#include<bits/stdc++.h>
using namespace std;
#define     pb              push_back
#define     PB              pop_back
#define     nn              "\n"
#define     O_O             ios_base::sync_with_stdio(false); cin.tie(NULL)
#define     all(p)          p.begin(),p.end()
#define     zz(v)           v.size()
#define     ss              ' '
#define     S(a)            scanf("%lld",&a)
#define     SS(a,b)         scanf("%lld %lld",&a,&b)
#define     SSS(a,b,c)      scanf("%lld %lld %lld",&a,&b,&c)
#define     gcd(a,b)        __gcd(a,b)
#define     lcm(a,b)        (a*b)/gcd(a,b)
#define     pi              acos(-1.0)
typedef     long long       ll;
typedef     vector<ll>      vll;
 
 
int main()
{
    ll a,p;
    S(a);
    for(ll i=a;; i++)
    {
        p=0;
        for(ll j=2; j<i; j++)
        {
            if(i%j==0)
            {
                p=1;
                break;
            }
 
        }
 
        if(p==0)
        {
            cout<<i<<nn;
            break;
        }
    }
 
 
    return 0;
}

Measured memory_bytes: 256
import sys
import  math
from heapq import *
import fractions
from collections import defaultdict
stdin = sys.stdin
     
ns = lambda: stdin.readline().rstrip()
ni = lambda: int(stdin.readline().rstrip())
nm = lambda: map(int, stdin.readline().split())
nl = lambda: list(map(int, stdin.readline().split()))

N=int(input())
n_l=[[0]*10 for i in range(10)]#col matu row sentou
for i in range(1,N+1):
    if(1<=i and i<10):
        n_l[i][i]+=1
    elif(10<i and i<10**2):
        n_l[i%10][i//10]+=1
    elif(10**2<i and i<10**3):
        n_l[i%10][i//100]+=1
    elif(10**3<i and i<10**4):
        n_l[i%10][i//1000]+=1
    elif(10**4<i and i<10**5):
        n_l[i%10][i//10000]+=1
    elif(10**5<i):
        n_l[i%10][i//100000]+=1
    

ans=0
for i in range(1,10):
    for k in range(1,10):
        if(i!=k):
            ans+=(n_l[i][k])*((n_l[k][i]))

for i in range(1,10):
    ans+=(n_l[i][i])*((n_l[i][i]))
print(ans)


Measured memory_bytes: 65008
#include<bits/stdc++.h>
#define range(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,b) for(int i = 0; i < (b); i++)
#define all(a) (a).begin(), (a).end()
#define show(x)  cerr << #x << " = " << (x) << endl;
#define int long long
using namespace std;

template <typename X, typename T>
auto vectors(X x, T a) {
	return vector<T>(x, a);
}

template <typename X, typename Y, typename Z, typename... Zs>
auto vectors(X x, Y y, Z z, Zs... zs) {
	auto cont = vectors(y, z, zs...);
	return vector<decltype(cont)>(x, cont);
}

template<typename T>
ostream& operator << (ostream& os, vector<T>& v){
	rep(i,v.size()){ os << v[i] << (i == v.size() - 1 ? "" : " "); } return os;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& v){
	for(T& x: v){ is >> x; } return is;
}

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

	vector<int> v(n);
	cin >> v;

	int ans = 0;
	rep(op, min(n + 1, k + 1)){
		rep(left, op + 1){
			set<int> minus;
			int sum = 0;
			int right = op - left;
			//cout << left << ' ' << right << endl;
			rep(i,left){
				if(v[i] >= 0) sum += v[i];
				else minus.emplace(v[i]);
			}
			//show(sum)
			for(int i = n - 1; i > n - 1 - right; i--){
				if(v[i] >= 0) sum += v[i];
				else minus.emplace(v[i]);
			}
			//show(sum)

			int enq = k - op;
			for(auto i : minus){
				if(enq > 0){
					enq--;
					continue;
				}
				sum += i;
			}
			ans = max(ans, sum);
		}
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
//FIRST THINK THEN CODE.

#include <bits/stdc++.h>
 
 
using namespace std;
 
typedef long long ll;
 
#define MOD 998244353
#define rep(i,a,b) for(ll i=a;i<b;++i)
#define rrep(i,a,b) for(ll i=a;i>b;--i)
#define vi vector<int>
#define vl vector<ll>
#define ld long double
#define vvi vector<vector<int>>
#define vvl vector<vector<long long>>
#define pii pair<int,int>
#define pll pair<long,long>
#define vpii vector<pii>
#define vpll vector<pll>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define PI 3.1415926535897932384626433832795
#define fix(f,n) fixed<<setprecision(n)<<f
#define all(x) x.begin(),x.end()
#define endl "\n"
#define IOS ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
 
ll newmod(ll a,ll b)
 {
  return ((a%b)+b)%b;
}
 
 
ll powM(ll a,ll b,ll m )
{ 
  a%=m;
  ll ans=1LL;
  while(b)
  {
    if(b&1)ans=ans*a%m;
    a=a*a%m;
    b>>=1;
  }
 
return ans;
}
 
ll poww(ll a,ll b)
{ 
  
  ll ans=1;
  while(b)
  {
    if(b&1)ans=ans*a;
    a=a*a;
    b>>=1;
  }
 
return ans;
}

const ll N=5e5+5;

ll sp[N];

void sieve(){
  for(int i=2;i<N;i++)sp[i]=i;

    for(int i=2;i*i<N;i++){
      if(sp[i]==i){
      for(int j=i*i;j<N;j+=i){
        sp[j]=i;
      }
    }
}

}

ll fac[N],inv[N];

ll p=1e9+7;

void fill(){
  fac[0]=inv[0]=1;

  for(int i=1;i<N;i++){
    fac[i]=fac[i-1]*i%p;
    inv[i]=powM(fac[i],p-2,p);
  }
}

ll c(ll a,ll b,ll p){
if(a<b)return 0;

  return (fac[a]*inv[a-b]%p)*(inv[b])%p;
}


ll lcm(ll a,ll b)
{
  return (a*b)/(__gcd(a,b));
}

int main()
{ 

  IOS;

ll n,l;

cin>>n>>l;

ll val=2e6;

for(int i=1;i<=n;i++){
  ll flav=(l-1+i);
  if(abs(flav)<abs(val)){
    val=flav;
  }
}

//cout<<val<<endl;

ll ans=n*l-n+n*(n+1)/2;
//cout<<ans<<endl;
ans-=val;

cout<<ans<<endl;


return 0;
 
}



Measured memory_bytes: 3616
#include<iostream>
#include<iomanip>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<algorithm>
#include<set>
#include<map>
#include<queue>
#include<stack>
#include<vector>
#include<cctype>
#define szxb 100010
#define F(a,b) for(register int (a)(1);(a)^((b)+(1));(a)++)
using namespace std;
int n,m,a[szxb];
bool b[szxb]={0,1};
signed main()
{
	scanf("%d%d",&n,&m);int x,y,ans(0);
	F(i,n){a[i]=1;}F(i,m){scanf("%d%d",&x,&y),a[x]--,a[y]++;if(!(b[x]-1)){b[y]=1;}if(!a[x]){b[x]=0;}}F(i,n){ans+=b[i];}
	printf("%d",ans);
	return putchar(10),0;
}

Measured memory_bytes: 768
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<x<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;

int n, m, R;
vint r;
vvint cost;
int ans = INF;
void dfs(int num, int c, int prev, vbool visit) {
    if (num == R) {
        ans = min(ans, c);
        return;
    }
    visit[prev] = true;
    rep(i, R) {
        if (!visit[i]) {
            dfs(num+1, c+cost[r[prev]][r[i]], i, visit);
        }
    }
}

void solve() {
    vbool visit(R, false);
    rep(i, R) {
        dfs(1, 0, i, visit);
    }
}

int main() {
    cin >> n >> m >> R;
    r.resize(R);
    rep(i, R) {
        cin >> r[i];
        --r[i];
    }

    cost.resize(n, vint(n, INF));
    rep(i, m) {
        int a, b, c;
        cin >> a >> b >> c;
        --a;
        --b;
        cost[a][b] = c;
        cost[b][a] = c;
    }

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

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

Measured memory_bytes: 384
# -*- coding: utf-8 -*-
import bisect
import heapq
import math
import random
import sys
from collections import Counter, defaultdict, deque
from decimal import ROUND_CEILING, ROUND_HALF_UP, Decimal
from functools import lru_cache, reduce
from itertools import combinations, combinations_with_replacement, product, permutations
from operator import add, mul, sub

sys.setrecursionlimit(100000)
input = sys.stdin.readline
INF = 2**62-1

def read_int():
    return int(input())


def read_int_n():
    return list(map(int, input().split()))


def read_float():
    return float(input())


def read_float_n():
    return list(map(float, input().split()))


def read_str():
    return input().strip()


def read_str_n():
    return list(map(str, input().split()))


def error_print(*args):
    print(*args, file=sys.stderr)


def mt(f):
    import time

    def wrap(*args, **kwargs):
        s = time.time()
        ret = f(*args, **kwargs)
        e = time.time()

        error_print(e - s, 'sec')
        return ret

    return wrap


@mt
def slv(S):
    return 'x' * len(S)


def main():
    S = read_str()
    print(slv(S))


if __name__ == '__main__':
    main()


Measured memory_bytes: 7740
/**
 * author: stein
 * created: 2020.08.15 13:25:03
**/
#include <bits/stdc++.h>
using namespace std;

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

  int n, cnt = 0, ans = 0;
  cin >> n;
  vector<long long> f (n);
  vector<long long> tmp (3);
  for (auto &it : f) cin >> it;

  for (int i = 0; i < n; i++) {
    for (int j = i+1; j < n; j++) {
      for (int k = j+1; k < n; k++) {
        if (f[i] != f[j] && f[j] != f[k] && f[k] != f[i]) {
          tmp[0] = f[i], tmp[1] = f[j], tmp[2] = f[k];
          sort(tmp.begin(), tmp.end());
          ans += (tmp[0] + tmp[1] > tmp[2]);
        }
      }
    }
  }
  cout << ans << endl;

  return 0;
}

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0;i < n;i++)
#define REPR(i, n) for(int i = n;i >= 0;i--)
#define FOR(i, m, n) for(int i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)
#define INF 999999999
using namespace std;
typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main()
{
string s;
cin>>s;
int a=0,b=0,c=0;
for(int i=0; i<3; i++)
{
    if(s[i]=='a') ++a;
    if(s[i]=='b') ++b;
    if(s[i]=='c') ++c;
}
if(a==1&&b==1&&c==1) cout<<"Yes"<<endl;
else cout<<"No"<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;

int main()
{
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int n; cin >> n;
  vector<ll> a(n+1);
  REP(i,n+1) cin >> a[i];

  vector<ll> sum(n+2, 0);
  REPR(i,n) sum[i] = sum[i+1] + a[i];

  if(n==0){
    if(a[0]==1){
      cout << 1 << endl;
    }else{
      cout << -1 << endl;
    }
    return 0;
  }
  if(a[0]!=0){
    cout << -1 << endl;
    return 0;
  }

  ll ans = 1;
  ll cur = 1;
  FOR(i,1,n+1){
    cur *= 2;
    cur = min(cur, sum[i]);
    ans += cur;
    cur -= a[i];
    if(cur<0){
      cout << -1 << endl;
      return 0;
    } 
  }
  cout << ans << endl;
  return 0;
}


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

#define DUMP(x) cerr << #x << "=" << x << endl
#define DUMP2(x, y) cerr<<"("<<#x<<", "<<#y<<") = ("<<x<<", "<<y<<")"<< endl
#define BINARY(x) static_cast<bitset<16> >(x)

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

#define in_range(x, y, w, h) (0<=(int)(x) && (int)(x)<(int)(w) && 0<=(int)(y) && (int)(y)<(int)(h))
#define ALL(a) (a).begin(),(a).end()

typedef long long ll;
const int INF = 1e9;
typedef pair<int, int> PII;
int dx[4]={0, -1, 1, 0}, dy[4]={-1, 0, 0, 1};

int N;
string S;

bool check(int n, bool seep, bool a, bool b)
{
    if ((S[n] == 'o' && seep) || (S[n] == 'x' && !seep)) return (a == b);
    return (a != b);
}

bool check_all(vector<bool> anim)
{
    bool ok = true;
    ok &= check(0, anim[0], anim[N-1], anim[1]);
    for (int i=1; i<N-1; i++) {
        ok &= check(i, anim[i], anim[i-1], anim[i+1]);
    }
    ok &= check(N-1, anim[N-1], anim[N-2], anim[0]);
    return ok;
}

vector<bool> sim(bool zero, bool one)
{
    vector<bool> res(N);
    res[0] = zero;
    res[1] = one;
    for (int i=1; i<N-1; i++) {
        if ((S[i] == 'o' && res[i]) || (S[i] == 'x' && !res[i])) {
            res[i+1] = res[i-1];
        } else {
            res[i+1] = !res[i-1];
        }
    }
    return res;
}

int main()
{
    ios::sync_with_stdio(false);

    cin >> N >> S;

    rep(a, 2) rep(b, 2) {
        vector<bool> tmp = sim(a, b);
        if (check_all(tmp)) {
            for (auto i : tmp) cout << "WS"[i];
            cout << endl;
            return 0;
        }
    }

    cout << -1 << endl;
}



Measured memory_bytes: 592
#include<bits/stdc++.h>
using namespace std;
int main()
{
    string s;
    cin>>s;
    int c=0;
    for(int i=0; i<s.size(); i++)
    {
        if((s[i]=='A' && s[i+1]=='B') || (s[i+1]=='A' && s[i+2]=='B'))
        {
            c=1;
            break;
        }
    }
    for(int i=0; i<s.size(); i++)
    {
        if((s[i]=='B' && s[i+1]=='A') || (s[i+1]=='B' && s[i+2]=='A'))
        {
            c=2;
            break;
        }
    }
    if(c==1 ||c==2)
    {
        cout<<"Yes"<<endl;
    }
    else
    {
        cout<<"No"<<endl;
    }
    return 0;
}


Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <math.h>
#include <cmath>
#include <numeric>
#include <iostream>
#include <sstream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <queue>
#include <stack>
#include <deque>
#include <list>
#include <unordered_map>
#include <tuple>
#include <complex>


#define FOR(i, a, b)		for(int i = (int)(a); i < (int)(b); ++i)
#define FORE(i, a, b)		for(int i = (int)(a); i <= (int)(b); ++i)
#define REP(i, n)			FOR(i, 0, n)
#define REPE(i, n)			FORE(i, 0, n)
#define ALL(x)				(x).begin(),(x).end()
#define DEBUG_DC(x)			cout << #x << ": " << x << endl
#define VEC_TYPE			int
#define INF					1e5+1

using namespace std;
typedef long long ll;
typedef vector<VEC_TYPE> vdef;
typedef vector<vdef> vvdef;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmaxE(T& a, T b) { if (a <= b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<class T> inline bool chminE(T& a, T b) { if (a >= b) { a = b; return 1; } return 0; }
template<typename T> inline T mygcd(T a, T b) { return b ? mygcd(b, a%b) : a; }
template<typename T> inline T mylcm(T a, T b) { return a * b / mygcd(a, b); }


int main()
{
	ll a, b, c, d;
	cin >> a >> b >> c >> d;
	ll ans = (ll)0;

	ll lcmcd = mylcm(c, d);
	ll cNUM = b / c - a / c;
	if (a%c == 0) ++cNUM;
	ll dNUM = b / d - a / d;
	if (a%d == 0) ++dNUM;
	ll lcmNUM = b / lcmcd - a / lcmcd;
	if (a%lcmcd == 0) ++lcmNUM;
	
	ll sum = b - a + (ll)1;
	ans=sum - cNUM - dNUM + lcmNUM;
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
/*  CREATED BY
    Stream_Cipher
    13-sep-2020
*/
#include<bits/stdc++.h>
using namespace std;
#define int long long int
#define double long double
#define debug1(a) cout<<#a<<"="<<(a)<<"\n"
#define debug2(a,b) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<"\n"
#define debug3(a,b,c) cout<<#a<<"="<<(a)<<","<<#b<<"="<<(b)<<","<<#c<<"="<<(c)<<"\n"
#define fix_precision(n) cout<<fixed<<setprecision(n)
#define all(a) a.begin(),a.end()
const double pi=acos(-1.0);
int inf=0x3f3f3f3f3f3f3f3f;
const int mod=1e9+7;
const int mx=5*1000000;//5*64M bit ->5*8M byte ->40MB size for long long int (64 bit)
int32_t main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    #ifndef ONLINE_JUDGE
        freopen("input.txt","r",stdin);
        freopen("output.txt","w",stdout);
    #endif
        int n;
        cin>>n;
        cout<<(n^1)<<endl;
}

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

#define fi first
#define se second
#define mk(a,b) make_pair(a,b)

typedef long long ll;
typedef pair<ll, ll> pll;
typedef pair<ll, pll> plpll;
typedef pair<pll, pll> llll;

int N, M;
vector<pll> G[4010];
vector<pll> T[4010];
vector<pll> cost;
vector<plpll> E;
bool is_tree[400010];
int par[4010];
ll sum;
int current_root;
ll max_cost[4010][4010];

void init(int N)
{
    for(int i = 0; i < N; i++)par[i] = i;
    return;
}

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

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

    if(x == y)return;

    par[x] = y;
    return;
}

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

void DFS(int v, int p = -1, ll d = 0)
{
    max_cost[current_root][v] = d;
    for(int i = 0; i < T[v].size(); i++)
    {
        int next = T[v][i].fi, id = T[v][i].se;
        ll cost = E[id].fi;
        if(p == next || !is_tree[id])continue;
        DFS(next, v, max(d, cost));
    }
    return;
}

int main()
{
    cin >> N >> M;
    for(int i = 0; i < M; i++)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        cost.push_back(mk(c, i));
        E.push_back(mk(c, mk(a, b)));
        G[a].push_back(mk(b, i));
        G[b].push_back(mk(a, i));
    }

    init(N);
    sort(cost.begin(), cost.end());
    for(int i = 0; i < M; i++)
    {
        int now = cost[i].se;
        int a = E[now].se.fi, b = E[now].se.se;
        if(!same(a, b))
        {
            sum += cost[i].fi;
            T[a].push_back(mk(b, now));
            T[b].push_back(mk(a, now));
            is_tree[now] = true;
            unite(a, b);
        }
    }

    for(int i = 1; i <= N; i++)
    {
        current_root = i;
        DFS(i);
    }

    int Q;
    cin >> Q;
    for(int i = 0; i < Q; i++)
    {
        int a, b;
        cin >> a >> b;
        cout << sum - max_cost[a][b] << endl;
    }
}


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

using namespace std;

int main(void) {
    int N, M;
    cin >> N >> M;
    if(N == 1 && M == 0) {
        cout << 0 << endl;
        return 0;
    }
    string ans(N, '_');

    while(M--) {
        int s, c;
        cin >> s >> c;
        --s;
        if(ans[s] == '_') {
            ans[s] = '0' + c;
        } else if(ans[s] != '0' + c) {
            cout << -1 << endl;
            return 0;
        }
    }

    if(ans.front() == '_') {
        ans.front() = '1';
    }
    for(int i=1; i<ans.size(); i++) {
        if(ans[i] == '_') {
            ans[i] = '0';
        }
    }

    if(ans.size() > 1 && ans[0] == '0') {
        cout << -1 << endl;
    } else {
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 256
import java.lang.StringBuilder

fun main(arr:Array<String>) {
    val (sx,sy,tx,ty) = readLine()!!.split(" ").map { it.toInt() }
    val ans = StringBuilder()
    for(i in (sx until tx)) {
        ans.append("R")
    }
    for(i in (sy until ty)) {
        ans.append("U")
    }
    for(i in (sx until tx).reversed()) {
        ans.append("L")
    }
    for(i in (sy until ty).reversed()) {
        ans.append("D")
    }
    ans.append("D")
    for(i in (sx .. tx)) {
        ans.append("R")
    }
    for(i in (sy .. ty)) {
        ans.append("U")
    }
    ans.append("L")
    ans.append("U")
    for(i in (sx .. tx).reversed()) {
        ans.append("L")
    }
    for(i in (sy .. ty).reversed()) {
        ans.append("D")
    }
    ans.append("R")
    println(ans.toString())

}

Measured memory_bytes: 36160
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(ll i=0;i<n;i++)
const ll INF=1e15;
const ll MOD=1e9+7;

const int MAX = 1100000;
ll fac[MAX], finv[MAX], inv[MAX];
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}
ll COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
int main(){
    ll N,K;cin>>N>>K;
    COMinit();
    rep(i,K){
        ll ans=COM(N-K+1,i+1)*COM(K-1,i)%MOD;
        cout<<ans<<endl;
    }
    return 0;
}

Measured memory_bytes: 25984
import java.util.Scanner;

public class Main{
  public static void main(String[]args){
    Scanner kbd=new Scanner(System.in);
    int n=kbd.nextInt();//the number of people
    int k=kbd.nextInt();//regular height(cm)
    int h[]=new int[n];
    int count=0;
    for(int i=0;i<n;i++){
      h[i]=kbd.nextInt();
      if(h[i]>=k){
        count++;
      }
    }
    System.out.println(count);
  }
}


Measured memory_bytes: 48664
#include <cstdio>
#include <algorithm>
int R, C, N, L, G;
std::pair < int, int > p[200001];
int F(int x, int y)
{
	if (x == 0)
		return y + 1;
	else if (y == C)
		return x + C + 1;
	else if (x == R)
		return R + C + C + 1 - y;
	else if (y == 0)
		return R + R + C + C + 1 - x;
	else
		return -1;
}
int main()
{
	scanf("%d%d%d", &R, &C, &N);
	L = R + C << 1;
	for (int i = 1, x1, y1, x2, y2; i <= N; i++)
	{
		scanf("%d%d%d%d", &x1, &y1, &x2, &y2);
		int p1 = F(x1, y1), p2 = F(x2, y2);
		if (~p1 && ~p2)
		{
			if (p1 > p2)
				std::swap(p1, p2);
			p[++G] = { p1, i };
			p[++G] = { p2, -i };
		}
	}
	std::sort(p + 1, p + G + 1);
	static int q[200001], D;
	for (int i = 1; i <= G; i++)
		if (p[i].second > 0)
			q[++D] = p[i].second;
		else
		{
			if (!D || -p[i].second != q[D])
			{
				puts("NO");
				return 0;
			}
			D--;
		}
	puts("YES");
	return 0;
}


Measured memory_bytes: 1920
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.List;
import java.util.Scanner;

public class Main { 
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String line = sc.nextLine();
		char tmp = 'A';
		String result = "Good";
		for(int i = 0;i<line.length();i++) {
			char compChar = line.charAt(i);
			if(tmp == compChar) {
				result = "Bad";
				break;
			}
			tmp = compChar;
		}
		System.out.println(result);
	}
}
	
	

Measured memory_bytes: 23252
#include <stdio.h> /* printf, scanf */
#include <stdbool.h>    /* bool */

static void Read(int* a, int* b);
static int CompareAToB(int a, int b);
static void Write(int target);
static bool RangeCheck(int a, int b);

int main()
{
    int a = 0, b = 0;
    int result = 0;

    Read(&a, &b);

    if (!RangeCheck(a, b)) {
        return -1;
    }

    result = CompareAToB(a, b);

    Write(result);

    return 0;
}

void Read(int* a, int* b)
{
    scanf("%d %d", a, b);
}

int CompareAToB(int a, int b)
{
    int ret = 0;

    if (a < b) {
        ret = 1;
    }

    if (a > b) {
        ret = -1;
    }

    return ret;
}

void Write(int target)
{
    switch (target) {
    case -1:
        printf("a > b\n");
        break;
    case 1:
        printf("a < b\n");
        break;
    default:
        printf("a == b\n");
    }
}

bool RangeCheck(int a, int b)
{
    return (-1000 <= a && 1000 >= a) && (-1000 <= b && 1000 >= b) ? true : false;
}



Measured memory_bytes: 2052
unittest
{
//	assert( [ "4 4" ].parse.expand.solve == "Yes\n1\n6\n3\n7\n4\n5\n2" );
	assert( [ "2 1" ].parse.expand.solve == "No" );
}



import std.conv;
import std.range;
import std.stdio;
import std.typecons;

void main()
{
	stdin.byLineCopy.parse.expand.solve.writeln;
}

auto parse( Range )( Range input )
if( isInputRange!Range && is( ElementType!Range == string ) )
{
	auto nx = input.front.split.to!( long[] );
	return tuple( nx[ 0 ], nx[ 1 ] );
}

auto solve( long n, long x )
{
	auto m = n * 2 - 1;
	
	// 端の値は中央値になれないのでダメ
	if( x <= 1 || m <= x ) return "No";
	
	// 真ん中は最上段の値と同じにする
	auto anss = new long[ m ];
	anss[ n - 1 ] = x;
	
	// 右は内側から大きい値で埋める
	foreach( ref ans; anss[ n .. $ ] )
	{
		ans = m;
		m--;
		if( m == x ) m--;
	}
	
	// 右は外側から大きい値で埋める
	foreach( ref ans; anss[ 0 .. n - 1 ] )
	{
		ans = m;
		m--;
		if( m == x ) m--;
	}
	
	return "Yes\n" ~ anss.to!( string[] ).join( "\n" );
}


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

using namespace std;

int main()
{
	int s,k,c=0;
	scanf("%d%d",&k,&s);
	for(int x=0;0<=x&&x<=k;x++)
    {
        for (int y=0;0<=y&&y<=k;y++)
        {
            int z=s-(x+y);
            if(z>=0&&z<=k)
            {
                c++;
            }
        }
    }
    printf("%d",c);
}



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

int main(){
   string s;
   int q,k,u;
   char c;
   cin>>s>>q;
   int flag=0;
   while(q--){
    cin>>u;
    if(u==1){
        flag++;
    }
    else{
        cin>>k>>c;
        if(flag%2==0){
            if(k==1) s.insert(s.begin(),c);
            else s.insert(s.end(),c);
        }
        else{
            if(k==1) s.insert(s.end(),c);
            else s.insert(s.begin(),c);
        }
     }
   }
   if(flag%2==1) reverse(s.begin(),s.end());
   cout<<s;
   return 0;
}



Measured memory_bytes: 900
N = int(input())
a = N

for n in range(N+1):
  c = 0
  t = n
  while t>0:
    c+=t%6
    t//=6
  t = N-n
  while t>0:
    c+=t%9
    t//=9
  a = min(a,c)
  
print(a)

Measured memory_bytes: 9080
#include <iostream>
#include<iomanip>
#include <algorithm>
#include <vector>
#include <string>
#include <utility>
#include <queue>
#define INF 1e9+7
#define rep(i,m,n) for(int i=m;i<n;i++)
#define mrep(i,m,n) for(int i=m;i>n;i--)
#define NO cout<<"NO"<<endl;
#define YES cout << "YES"<<endl;
#define No cout << "No"<<endl;
#define Yes cout << "Yes"<<endl;
using namespace std;
typedef long long int ll;
typedef unsigned long long int ull;


//(int)'a'は97 (int)'A'は65 (int)'1'は49
//おまじない

ull ans = 0;

void cal(string s,int p=1) {
	if (p == s.size() - 1) {
		int b = 0;
		for (int i = 1; i < s.size(); i += 2) {
			if (s[i] == '+') {
				ll n = 0;
				for (int j = b; j < i; j += 2) {
					n = n * 10 + (int)s[j] - 48;
				}
				ans += n;
				b = i + 1;
			}
		}

		return;
	}
	else {
		s[p] = '+';
		cal(s, p + 2);
		s[p] = '#';
		cal(s, p + 2);
	}

	return;
}

int main() {

	string o, s;
	cin >> o;

	rep(i, 0, o.size()) {
		s.push_back(o[i]);
		s.push_back('#');
	}

	s[s.size() - 1] = '+';

	cal(s);
	
	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <functional>
#include <vector>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <string>
#include <numeric>
#include <cmath>

#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
typedef long long ll;
using P = pair<ll, ll>;

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;}

const ll MOD = 1000000007;
const int INF = 1<<30;
//const ll INF = (ll)1e18 + 1;

int main(){
  int N; cin >> N;
  vector<int> h(N); rep(i, N) cin >> h[i];

  int left, right;
  int ans = 0;
  int sum = accumulate(h.begin(), h.end(), 0);

  while (sum != 0){
    int m = INF;
    bool flag = false;
    rep(i, N){
      if (h[i] != 0 && !flag) {left = i; flag = true;}
      if (h[i] == 0 && flag) {right = i - 1; break;}
      if (h[i] != 0 && i == N - 1) {right = N - 1; break;}
    }
    for (int j = left; j <= right; ++j) m = min(m, h[j]);
    for (int j = left; j <= right; ++j) h[j] -= m;
    ans += m;
    sum = 0;
    rep(i, N) sum += h[i];
    /*
    rep(i, N) cout << h[i] << " ";
    cout << endl;*/
  }

  cout << ans << endl;
}


Measured memory_bytes: 256
N = int(input())
H = [int(h) for h in input().split()]
f = 0
for n in range(N-1, 0, -1):
    if H[n] < H[n-1]:
        H[n-1] -= 1
        if H[n] < H[n-1]:
            print("No")
            break

else:
    print("Yes")

Measured memory_bytes: 63984