akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
 
using namespace std;
 
const int N = 1e5 + 6;
 
vector< int > adj[N];
int a[N];
long long dfs(int v = 0, int par = -1) {
  long long sum = (adj[v].size() <= 1) ? a[v] : 0;
  long long ma = 0;
  for (int u : adj[v]) if (u != par) {
    long long cur = dfs(u, v);
    if (cur < 0)
      return -1;
    if (ma < cur)
      ma = cur;
    sum += cur;
  }
  long long up = 2 * a[v] - sum;
  if (up < (ma - (sum - ma)) || up > sum)
    return -1;
  return up;
}
 
 
int main() {
  int n;
  scanf("%d", &n);
  for (int i = 0; i < n; i++)
    scanf("%d", a+i);
  for (int i = 1; i < n; i++) {
    int u, v;
    scanf("%d %d", &u, &v);
    u--; v--;
    adj[u].push_back(v);
    adj[v].push_back(u);
  }
  puts(dfs() == 0 ? "YES" : "NO");
  return 0;
}

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

#define REP(i,n) for(int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> pint;
template <class T> inline void chmax(T &a, const T b) { a = max(a, b); }
template <class T> inline void chmin(T &a, const T b) { a = min(a, b); }
template <class T> void pp(T v, int n) { REP(i,n) cout<<v[i]<< ' '; cout << endl; }

void inline TorF(bool tf, const string &trueMessage, const string &falseMessage) {
  cout << (tf ? trueMessage : falseMessage) << endl;
}
void inline YESNO(bool tf) { TorF(tf, "YES", "NO"); }
void inline YesNo(bool tf) { TorF(tf, "Yes", "No"); }

int main() {
  int N, M; cin>>N>>M;
  vector< vector <int> > s(M);
  vector<int> p(M);

  REP(i,M) {
    int	k ; cin>>k;
    REP(j,k) {
      int sw; cin>>sw; sw--;
      s[i].push_back(sw);
    }
  }
  REP(i,M) cin>>p[i];
  int ans = 0;
  vector<int> onoff(N);
  REP(mask, (1<<N)){
    REP(i,N) onoff[i] =	(mask>>i) & 1;
    bool ok = true;
    REP(i,M) {
      int sum = 0;
      REP(j,s[i].size()) {
        sum += onoff[s[i][j]];
      }
      //      cout << i << "," << sum << "," << p[i] << endl;                                
      if(sum % 2 != p[i]) {
	ok = false; break;
      } 
    }
    if(ok) {
      ans++;
    }
    //    cout << mask << " " << ans << endl;                                                

  }

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


Measured memory_bytes: 888
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <iomanip>
using namespace std;
typedef long long unsigned int ll;
template<typename T> using min_priority_queue = priority_queue<T, vector<T>, greater<T>>;

#define EPS (1e-7)
#define INF (1e15)
#define PI (acos(-1))
#define MOD 1000000007

#define REP(i,n) for(int i=0;i<n;i++)
#define REPS(i,f,n) for(int i=(f);i<(n);i++)
#define EACH(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)

#define dump(x)  cout << #x << " = " << (x) << endl;
#define debug(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

typedef pair<int, int> P;
typedef pair<ll, ll> LP;
typedef pair<int, P> PP;
typedef pair<ll, LP> LPP;

int dy4[]={0, 0, 1, -1};
int dx4[]={1, -1, 0, 0};
int dx8[]={0, 0, 1, -1, 1, 1, -1, -1};
int dy8[]={1, -1, 0, 0, 1, -1, -1, 1};

// https://atcoder.jp/contests/abc093/tasks/abc093_b

int main() {
    int A, B, K;
    cin >> A >> B >> K;
    set<int> st;

    for (int i = A; i < A+K; i++) {
        if (i <= B) st.insert(i);
    }
    for (int i = B; i > B-K; i--) {
        if (i >= A) st.insert(i);
    }

    for (int t : st) {
        cout << t << "\n";
    }


    return 0;
}


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

using namespace std;
using int64 = long long;

constexpr int DEBUG = 0;

constexpr int64 P = 1000000007;

struct FiniteField {
 private:
  int64 x;
  static inline int64 Normalize(int64 x) {
    if (0 <= x && x < P) return x; x %= P; if (x < 0) x += P; return x;
  }
 public:
  FiniteField(int64 x) : x(Normalize(x)) {}
  FiniteField() : x(0) {}
  int64 Value() const { return x; }
  inline FiniteField operator+(FiniteField o) const {
    FiniteField r(*this); r += o; return r;
  }
  inline FiniteField operator-(FiniteField o) const {
    FiniteField r(*this); r -= o; return r;
  }
  inline FiniteField operator* (FiniteField o) const {
    FiniteField r(*this); r *= o; return r;
  }
  inline FiniteField operator/ (FiniteField o) const {
    FiniteField r(*this); r /= o; return r;
  }
  inline void operator+= (FiniteField o) { x = (x + o.x) % P; }
  inline void operator-= (FiniteField o) { x = (x + P - o.x) % P; }
  inline void operator*= (FiniteField o) { x = (x * o.x) % P; }
  void operator/=(FiniteField o) {
    int64 p = P - 2; while (p) { if (p % 2) { *this *= o; } o *= o; p /= 2; }
  }
};

ostream& operator<<(ostream& s, const FiniteField& v) { s << v.Value(); return s; }

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

  int n, m;
  cin >> n >> m;
  vector<int64> xs(n);
  vector<int64> ys(m);
  for (int i = 0; i < n; i++) {
    cin >> xs[i];
  }
  for (int i = 0; i < m; i++) {
    cin >> ys[i];
  }

  auto sum_fn = [](vector<int64>& zs) -> FiniteField {
    vector<int64> ds(zs.size() - 1);
    for (int i = 0; i < zs.size() - 1; i++) {
      ds[i] = zs[i + 1] - zs[i];
    }

    FiniteField r = 0;
    for (int i = 0; i < ds.size(); i++) {
      r += FiniteField(ds[i]) * (i + 1) * (ds.size() - i);
    }
    return r;
  };

  auto s1 = sum_fn(xs);
  auto s2 = sum_fn(ys);
  cout << s1 * s2 << endl;
}

Measured memory_bytes: 2672
n,m,q=map(int,input().split())
abcd=[list(map(int,input().split()))for _ in range(q)]
ans=0
import itertools
for i in itertools.combinations_with_replacement(list(range(m)),n):
  anss=0
  for a,b,c,d in abcd:
    if i[b-1]-i[a-1]==c:anss+=d
  ans=max(ans,anss)
print(ans)


Measured memory_bytes: 9108
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>
#define maxn 300005
#define ll long long
using namespace std;
int a[maxn];
int b[maxn];
int c[maxn]; 
int n, k, q;
int main()
{
	scanf("%d%d%d", &n, &k, &q);
	for(int i = 1; i <= n; i++)
		scanf("%d", &a[i]);
	int ans = 1000000000;
	for(int i = 1; i <= n; i++)
	{	// y >= a[i] mns
		int ncnt = 0;
		for(int j = 1; j <= n; )
		{
			if(a[j] < a[i]) 
			{
				j++;
				continue;
			}
			int npl = j;
			while(npl <= n && a[npl] >= a[i])
				npl++;
			int tms = npl - j - k + 1;
			for(int l = j; l < npl; l++)
				b[l] = a[l];
			sort(b + j, b + npl);
			for(int l = j; l < j + tms; l++)
				c[ncnt++] = b[l];
			j = npl + 1;
		}
		if(ncnt < q) continue;
		sort(c, c + ncnt);
		ans = min(ans, c[q - 1] - a[i]);
	}
	printf("%d\n", ans);
	return 0;
 } 

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var n, count, ans int
	fmt.Scan(&n)
	var s string

	fmt.Scan(&s)

	for _, value := range s {
		if value == rune('I') {
			count++
			if count > ans {
				ans++
			}
		} else if value == rune('D') {
			count--
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 512
#include<iostream>
#include<iomanip>
#include<string>
#include<vector>
#include<algorithm>
#include<utility>
#include<tuple>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<numeric>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>

using namespace std;

using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

#define BIL ((ll)1e9)
#define MOD ((ll)1e9+7)
#define INF (1LL<<60)           //1LL<<63でオーバーフロー
#define inf (1<<29)             //1<<29でオーバーフロー

int main(int argc,char* argv[]){
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(20);

    string a,b,c;
    cin >> a >> b >> c;

    bool ans=false;
    if(a.at(a.size()-1)==b[0] && b.at(b.size()-1)==c[0])ans=true;

    if(ans) cout << "YES" << endl;
    else cout << "NO" << endl;

    return 0;
}


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

using namespace std;

int main() {
    vector<int> a(5);
    
    for (int i = 0; i < 5; i++) {
        cin >> a[i];
    }
    
    int sum = 0;
    int maxi = 0;
    
    for (int i = 0; i < 5; i++) {
        sum += (a[i] + 9) / 10 * 10;
        
        if (a[i] % 10 != 0) {
            maxi = max(maxi, 10 - a[i] % 10);
        }
    }
    
    cout << sum - maxi << endl;
}

Measured memory_bytes: 888
#include <stdio.h>

int main()
{
    int i, j, t=0, n=3, ara[3];
    scanf("%d %d %d", &ara[0], &ara[1], &ara[2]);
    for(i=0; i<n-1; i++){
        for(j=i+1; j<n; j++){
            if(ara[i]>ara[j]){
                int x = ara[j];
                ara[j] = ara[i];
                ara[i] = x;
            }
        }
    }
    for(i=1; i<n; i++){
        t += abs(ara[i]-ara[i-1]);
    }
    printf("%d", t);
    return 0;
}


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

#define be(v) (v).begin(),(v).end()
#define pb(q) push_back(q)
typedef long long ll;
using namespace std;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n;
    cin>>n;
    ll x[n],y[n],ansx,ansy;
    for(int i=0;i<n;i++){
        cin>>x[i]>>y[i];
    }
    ansx=x[0];
    ansy=y[0];
    for(int i=1;i<n;i++){
        while(ansx%x[i]!=0||ansy%y[i]!=0||ansx/x[i]!=ansy/y[i]){
            if(ansx%x[i]!=0){
                ansx+=(x[i]-ansx%x[i]);
            }
            if(ansy%y[i]!=0){
                ansy+=(y[i]-ansy%y[i]);
            }
            if(ansx/x[i]!=ansy/y[i]){
                ll maki=ansx/x[i]-ansy/y[i];
                if(maki>0){
                    ansy+=maki*y[i];
                }
                else{
                    ansx-=maki*x[i];
                }
            }
        }
    }
    cout << ansx+ansy<<endl;
    return 0;
}



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

#define ll long long
#define F first
#define S second
#define ii pair < int , int >
#define ever (;;)

const int N = 100100;

int n,m,out[N],dp[N],ans;
vector <int> adj[N];
queue <int> q;

int main()
{
    scanf("%d%d",&n,&m);
    for(int i=1;i<=m;i++)
    {
        int a,b;
        scanf("%d%d",&a,&b);
        adj[b].push_back(a);
        out[a]++;
    }

    for(int i=1;i<=n;i++)
        if( !out[i] )
            q.push(i);

    while( !q.empty() )
    {
        int u = q.front();

        q.pop();

        for(auto &x:adj[u])
        {
            dp[x] = max( dp[x] , dp[u] + 1 );
            ans = max( ans , dp[x] );
            out[x]--;
            if( !out[x] )
                q.push(x);
        }
    }

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


Measured memory_bytes: 9884
// {{{
#include <algorithm>
#include <array>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <tuple>
#include <utility>
#include <vector>
// }}}

using namespace std;

using ll = long long;
using ull = unsigned long long;
using ld = long double;

static constexpr int mod = (int)1e9 + 7;
static constexpr int inf = 100100100;
static constexpr ll linf = 1e18;
static constexpr double eps = 1e-9;
static constexpr double pi = 3.14159265359;

#define rep(i, n) for (ll i = 0; i < n; ++i)
#define rrep(i, n) for (ll i = n; i >= 0; --i)
#define all(c) begin(c), end(c)
#define rall(c) rbegin(c), rend(c)
#define pb push_back
#define ist insert
#define fst first
#define snd second


int main() {
    // cin.tie(0);
    // ios_base::sync_with_stdio(false);
    ll N, A, B;
    cin >> N >> A >> B;
    cout << min(N * A, B) << endl;
}


Measured memory_bytes: 888
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
	char a[101];
	int sta,end;
	cin>>a;
	int i=0;
	while(i<sizeof(a)){
		if(a[i]=='C'){
			int j=sizeof(a);
			while(j>=i){
				if(a[j]=='F'){
					cout<<"Yes"<<endl;
					return 0;
				}
				if(j==i){
					cout<<"No"<<endl;
					return 0;
				}
				j--;
			}
		}i++;
	}cout<<"No"<<endl;
}

Measured memory_bytes: 256
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define mfill(x,y) memset(x,y,sizeof(x))
#define all(v) v.begin(), v.end()
#define in(x,y,h,w) if(0<=x&&x<h&&0<=y&&y<w)
#define y0 y12345
#define y1 y54321

#ifdef LOCAL
#define debug(...) fprintf(stderr,__VA_ARGS__)
#else
#define debug(...) 42
#endif

using ul = unsigned long;
using ll = long long;
using P = pair<int, int>;
using vint = vector<int>;using vvint = vector<vector<int>>;
using vll = vector<ll>;using vvll = vector<vector<ll>>;
template<class T>bool chmax(T &a, const T &b){if(a<b){a=b;return 1;}return 0;}
template<class T>bool chmin(T &a, const T &b){if(a>b){a=b;return 1;}return 0;}
template <class T>void initvv(vector<vector<T> > &v, int a, int b, const T &t = T()){
	v.assign(a, vector<T>(b, t));
}
template <class T>T gcd(T &a, T &b){if(a<b){swap(a,b);} T r = a%b; while(r!=0){a=b;b=r;r=a%b;} return b;}

vint dx = {-1, 0, 1, 0}, dy = {0, -1, 0, 1};
vint dx8 = {-1, -1, -1, 0, 1, 1, 1, 0}, dy8 = {-1, 0, 1, 1, 1, 0, -1, -1};

int main() {
	cin.tie(0);
   	ios::sync_with_stdio(false);
	debug("debug test\n");
   	ll h, n;
	ll sum = 0;cin>>h>>n;
	rep(i, n){
		ll s;cin>>s;
		sum += s;
	}
	if(h - sum <= 0){
		cout << "Yes" << endl;
	}else{
		cout << "No" << endl;

	}
	return 0;
}


Measured memory_bytes: 256
/*jai_ganeshdeva*/

#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define pu push  //  adds the value to the last of the queue 
#define lld long long int
#define ins insert /// used in set to insert the values 
#define adv advance  /// used to increment the iterator
#define mp make_pair
#define fi first
#define se second
#define all(c) c.begin(),c.end()
#define PI 3.1415926
#define INF (lld)1e18
#define vl  vector<long long int >
#define vpll vector< pair<lld ,lld> >
#define vvl vector<vector<lld> > 
#define pll pair <lld,lld>
#define modA(cccc,bbbb ,p) (((cccc+bbbb)%p+p)%p)
#define modS(cccc,bbbb ,p) (((cccc-bbbb)%p+p)%p)
#define modM(cccc,bbbb ,p) ((((cccc%p)*(bbbb%p))%p+p)%p)

long long int modp(lld a,lld p,lld n)
{
    lld d[100];
    lld i,j,k,l;
    if(n==0) return 1;
    for(i=0;n>=1;i++)
    {
        d[i]=n%2;
        n/=2;
    }
    l=i;
    long long int e=1;
    if(d[0]==1) e*=(a%p);
    for(i=1;i<l;i++)
    {
        a*=a;
        a=a%p;
        if(d[i]==1) 
        {
            e*=a;
            e=e%p;
        }
    }
    return e%p;
}
lld modInverse(lld n, lld p) 
{ 
    return modp(n, p, p-2); 
}

/*lld fac[100001]; 

void getfac(lld p)
{
    fac[0] = 1; 
    for (lld i=1 ; i<=100000; i++) 
        fac[i] = fac[i-1]*i%p; 
}    

long long int nCrmodp(lld n, lld r,lld p) 
{ 
   // Base case 
   if (r==0) 
      return 1; 
     
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
}*/


lld gcd(lld a,lld b)
{
    if(a>b) return gcd(b,a);
    if(b%a==0) return a;
    else return gcd(b%a,a);
}

lld p1=1e9 + 7,p2=998244353;
lld l,r,mid,ans;
lld n,i,j,k,g,m;
lld x,y,n1,n2,h,z,c;
lld aa=1;



void solve()
{
    cin>>n;
    x=1;
    for(i=0;i<n;i++)
    {
        cin>>l;
        if(l==x) x+=1;
    }


    if(x==1) cout<<-1;
    else cout<<n-x+1;

    
}


int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    lld t=1;
    
    //cin>>t;
    //cout<<t;
   //  getfac(p2);
    //check the value by which modulo is to be taken
    lld ans=0;
    for(int i=0;i<t;i++)
    {
   //     cout<<"Case #"<<i+1<<": ";
                  solve();
        cout<<"\n";
    }
    return 0;
}


Measured memory_bytes: 3628
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author tatsumack
 */

#include <iostream>
#include <fstream>

#include <bits/stdc++.h>

#define int long long
#define REP(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
#define FOR(i, a, b) for (int i = (a), i##_len = (b); i <= i##_len; ++i)
#define REV(i, a, b) for (int i = (a); i >= (b); --i)
#define CLR(a, b) memset((a), (b), sizeof(a))
#define DUMP(x) cout << #x << " = " << (x) << endl;
#define INF 1001001001001001001ll
#define fcout cout << fixed << setprecision(12)

using namespace std;

typedef pair<int, int> P;

class DDiceInLine {
public:
    void solve(std::istream& cin, std::ostream& cout) {
        int N, K;
        cin >> N >> K;
        vector<int> p(N);
        REP(i, N) cin >> p[i];

        vector<int> sum(1001);
        FOR(i, 1, 1000) sum[i] = i + sum[i - 1];

        int r = 0;
        double cur = 0;
        while (r < K - 1) {
            cur += (double) sum[p[r]] / (double) p[r];
            r++;
        }

        double res = 0;
        REP(l, N - K + 1) {
            if (r >= N) break;
            cur += (double) sum[p[r]] / (double) p[r];
            res = max(res, cur);
            cur -= (double) sum[p[l]] / (double) p[l];
            r++;
        }
        fcout << res << endl;
    }
};


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    std::istream& in(std::cin);
    std::ostream& out(std::cout);

    DDiceInLine solver;
    solver.solve(in, out);
    return 0;
}


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

int main () {
  string s;
  cin >> s;

  int a=s[5]-'0',b=s[6]-'0';
  if (a==0 && b<=4)
    cout << "Heisei" << endl;
  else cout << "TBD" << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
//#include <string>
#include <algorithm>
//#include <math.h>
//#include <queue>
//#include <stack>
//#include <iomanip>

// sometimes used
//#include <set>
//#include <map>
//#include <numeric>
//#include <list>
//#include <deque>
//#include <unordered_map>

typedef long long LL;
//typedef long double LD;
using namespace std;
 
//#define MOD 1000000007
//#define MAX 200100
//#define NIL -1

int main() {
    int n;
    LL h;
    vector<LL> a;
    vector<LL> b;
    LL tmp_a;
    LL tmp_b;
    cin >> n >> h;
    for(int i=0; i<n; i++){
        cin >> tmp_a >> tmp_b;
        a.push_back(tmp_a);
        b.push_back(tmp_b);
    }
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    auto itr=lower_bound(b.begin(), b.end(), a[n-1]+1);
    int idx=distance(b.begin(), itr);
    int k_throw=n-1;
    LL ans=0;
    while(h>0){
        if(k_throw>=idx){
            h-=b[k_throw];
            k_throw--;
            ans++;
        }else{
            if(h%a[n-1]==0){
                ans+=h/a[n-1];
            }else{
                ans+=h/a[n-1]+1;
            }
            h=0;
        }
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 2036
import java.util.Scanner;

public class Main
{
	public static void main(String arg[])
	{
		Scanner sc = new Scanner(System.in);
		while(sc.hasNext())
		{
			int n= sc.nextInt();
			if(n==0)
				return;
			int a[]=new int[n];
			int inde=0;
			int maxinde=0;
			int sum=0;
			int max=0;
			while(n-->0)
			{
					inde=sc.nextInt();
					sum = sc.nextInt()+sc.nextInt();
				if(sum>max)
				{
					max=sum;
					maxinde=inde;
				}
			}
			System.out.println(maxinde+" "+max);
		}
	}
}

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

int n, m, k, ans, b[33], t;

int main(){
  scanf("%lld%d", &n, &m);
  for(int i = 0; i < n; i++){
    scanf("%d", &k);
    for(int i = 0; i < k; i++){
      scanf("%d", &t); b[--t]++;
    }
  }
  for(int i = 0; i < m; i++){
    if(b[i] == n) ans++;
  }
  printf("%d\n", ans);
}

Measured memory_bytes: 256
a_p, b_p, ab_p ,x,y = gets.to_s.split.map{|t|t.to_i}

ans = Float::INFINITY

0.upto([x,y].max) do |ab_n|
  
  cost = ab_p * ab_n * 2
  
  need_a = x - ab_n
  need_b = y - ab_n
  
  need_a = 0 if need_a < 0
  need_b = 0 if need_b < 0
  
  cost += a_p * need_a
  cost += b_p * need_b
  
  ans = cost if ans > cost
end

puts ans

Measured memory_bytes: 1788
from collections import deque
N, K = map(int, input().split())
p = list(map(int, input().split()))
max_ans = 0
tmp_ans = 0
queue = deque([])
for i in range(N):
    e = (p[i] + 1) / 2 
    tmp_ans += e
    queue.append(e)
    if len(queue) > K:
        tmp_ans = tmp_ans - queue.popleft()
    max_ans = max(max_ans, tmp_ans)
print(max_ans)

Measured memory_bytes: 25572
#include<stdio.h>
int main(){
  char s[8001];
  int i,j,k,t=1,x,y,a[2][16001]={},c[16001];
  scanf("%s%d%d",s,&x,&y);
  for(i=0;s[i]=='F';i++);
  a[0][8000+i]=a[1][8000]=1;
  for(;s[i];i++)if(s[i]=='T'){
    for(j=i+1;s[j]=='F';j++);j--;
    for(k=0;k<16001;k++){c[k]=a[t][k];a[t][k]=0;}
    for(k=0;k<16001;k++){
      if(c[k])a[t][k-i+j]=a[t][k+i-j]=1;
    }
    t^=1;
  }
  printf(a[0][x+8000]&&a[1][y+8000]?"Yes":"No");
}


Measured memory_bytes: 1932
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
#define FOR(i,a,n) for(ll i=(ll)a;i<(ll)n;i++)
#define RFOR(i,a,n) for(ll i=(ll)n-1;i >= (ll)a;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,0,n)
#define ALL(v) v.begin(), v.end()
#define bra(first,second) '(' << first << ',' << second << ')'
ll MOD = 1000000007;
//ll INF = 21474836470000000;
ll INF = 1001001001001001001;
long double EPS = 1e-11;
long double PI = 3.141592653589793238;
template<typename T>
void remove(std::vector<T>& vector, unsigned int index){
    vector.erase(vector.begin() + index);
}

using Graph = vector<vector<ll>>;

int main(){
    ll N;
    cin >> N;
    cout << (N+1) / 2 << endl;
}


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

using namespace std;

int n;
int k;
int x;
int y;
string s;
int main()
{
    cin >> n >> k >> s;
    for(int i = 1; i < n; i ++){
        x += (s[i - 1] == s[i]);
        y += (s[i - 1] != s[i]);
    }
    cout << x + min(y, k * 2) << "\n";
}


Measured memory_bytes: 512
#include<bits/stdc++.h>
#define FOR(i,a,b)for(int i=(a),_b=(b);i<=_b;i++)
#define FORN(i,b,a)for(int i=(b);_a=(a);i>=_a;i--)
#define REP(i,n)for(int i=0,_n=n;i<n;i++)
#define ll long long
#define pii pair<int,int>
#define re return
#define vi vector<int>
#define pb push_back
#define si set<int>
#define in insert
#define fl float
#define db double
#define ld long double
#define X first
#define Y first
#define st string
#define ull unsigned long long
#define size(s) s.size()
using namespace std;
inline void read(int &x)
{
	short negative=1;
    x=0;
    char c=getchar();
    while(c<'0' || c>'9')
    {
		if(c=='-')
			negative=-1;
		c=getchar();
	}
    while(c>='0' && c<='9')
        x=(x<<3)+(x<<1)+(c^48),c=getchar();
    x*=negative;
}
/*inline void write(long long x) {
  static long long sta[35];
  long long top = 0;
  do {
    sta[top++] = x % 10, x /= 10;
  } while (x);
  while (top) putchar(sta[--top] + 48);
  puts("");
}
bool prime(int n)
{
	if(n==0||n==1)
	  return false;
	for(int i=2;i*i<=n;i++)
	  if(n%i==0)
	    return false;
	return true;
}
const ll power(int n,int k)
{
	ll t=1;
	rep(i,k)
	  t*=n;
	return t;
}
const string turn2(int n)
{
	string s="";
	while(n!=0)
	{
		s+=(char)(n%2+'0');
		n/=2;
	}
	reverse(s.begin(),s.end());
	return s;
}
const string turn16(int n)
{
	string s="";
	while(n!=0)
	{
		if(n%16>9)
		  s+=(char)('A'+n%16-10);
		else
		  s+=(char)('0'+n%16);
		n/=16;
	}
	reverse(s.begin(),s.end());
	return s;
}*/
int main()
{
	int n;
	string s;
	cin>>n>>s;
	int cnt=0;
	for(int i=0;i<n;i++)
	{
		if(s.substr(i,3)=="ABC"){
			cnt++;
			i+=2;}
	}
	cout<<cnt<<endl;
	return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args) throws Exception {
		Scanner s = new Scanner(System.in);
		int A = s.nextInt(), B = s.nextInt(), K = s.nextInt(), k = 0, i = A;
		while (B > 0){
			int C = Math.min(A, B);
			B = Math.max(A, B) % C;
			A = C;
		}
		for (i = A;; i--){
			if (A % i == 0){
				k++;
			}
			if (k == K){
				System.out.println(i);
				break;
			}
		}
		
	}
}


Measured memory_bytes: 23764
#include<cstdio>
#include<queue>
#include<cstring>
using namespace std;

#define REP(i,a,b) for(i=a; i<b; ++i)
#define rep(i,n) REP(i,0,n)

int graph[500][500],dist[500];

int main() {
  int n,m,i,j,k,a,b;
  for(;;) {
    scanf("%d", &n);
    scanf("%d", &m); if(!n) break;
    memset(graph, 0, sizeof(graph));
    memset(dist, 0, sizeof(dist));
    rep(i,m) {
      scanf("%d %d", &a, &b);
      graph[a-1][b-1] = graph[b-1][a-1] = 1;
    }

    queue<int> Q;
    int ans = 0;
    dist[0] = 1;
    Q.push(0);
    while(!Q.empty()) {
      int now = Q.front(); Q.pop();
      ans++;
      if(dist[now] >= 3) continue;
      rep(i,n) {
	if(dist[i] != 0 || graph[now][i] == 0) continue;
	dist[i] = dist[now]+1;
	Q.push(i);
      }
    }

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

Measured memory_bytes: 0
import java.io.*;
import java.util.*;
public class Main{
    public static void main(String[] args) throws IOException{
        Reader r = new Reader();
        int N, K;
        {int[] a = r.ii(); N = a[0]; K = a[1];}
        int[] V = r.ii();
        int R = Math.min(N, K);
        int max = 0;
        for(int a = 0; a <= R; a++){
            for(int b = 0; b <= R-a; b++){
                int[] v = new int[a+b];
                for(int i = 0; i < a; i++)
                    v[i] = V[i];
                for(int i = N-b; i < N; i++)
                    v[a+i-(N-b)] = V[i];
                Arrays.sort(v);
                int lmt = Math.min(K-a-b,v.length);
                for(int i = 0; i < lmt && v[i] < 0; i++)
                    v[i] = 0;
                int sum = 0;
                for(int t : v)
                    sum += t;
                if(max < sum)
                    max = sum;
            }
        }
        println(max);
    }

    static void print(Object o){
        System.out.print(o.toString());
    }

    static void println(Object o){
        System.out.println(o.toString());
    }

    static int Int(String s){
        return Integer.parseInt(s);
    }

    static long Long(String s){
        return Long.parseLong(s);
    }
    static class Reader extends BufferedReader{
        Reader(){
            super(new InputStreamReader(System.in));
        }

        String s() throws IOException{
            return readLine();
        }

        String[] ss() throws IOException{
            return s().split(" ");
        }

        int i() throws IOException{
            return Int(s());
        }

        int[] ii() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            int[] ii = new int[size];
            for(int j = 0; j < size; j++) ii[j] = Int(ss[j]);
            return ii;
        }

        long l() throws IOException{
            return Long(s());
        }

        long[] ll() throws IOException{
            String[] ss = ss();
            int size = ss.length;
            long[] ll = new long[size];
            for(int j = 0; j < size; j++) ll[j] = Long(ss[j]);            
            return ll;
        }
    }
}


Measured memory_bytes: 23636
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
using namespace std;
typedef long long ll;

ll K;
const ll amax = pow(10ll, 16) + 1000;

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

    cin >> K;

    for(int N = 2; N <= 50; ++N){
        if(K % N == 0){
            ll ans = K / N + N - 1;
            if(ans <= amax){
                cout << N << endl;
                for(int i = 0; i < N; ++i){
                    if(i != 0) cout << " ";
                    cout << ans;
                }
                cout << endl;
                break;
            }
        }
        else {
            int x = K % N;
            ll ans1 = -x + N + (K - x) / N - 1;
            ll ans2 = -x + 2 * N + (K - x) / N;
            if(ans2 <= amax){
                cout << N << endl;
                for(int i = 0; i < N - x; ++i){
                    if(i != 0) cout << " ";
                    cout << ans1;
                }
                for(int i = N - x; i < N; ++i){
                    cout << " " << ans2;
                }
                cout << endl;
                break;
            }
        }
    }

    return 0;
}

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

class Program
{
    static void Main()
    {
        string input;
        while ((input = Console.ReadLine()) != null)
        {
            var t = input.Split().Select(int.Parse).Aggregate((a, b) => a + b).ToString();
            Console.WriteLine(t.Length);
        }
    }
}

Measured memory_bytes: 9588
class Program
    {
        static void Main(string[] args)
        {
            int N = int.Parse(System.Console.ReadLine());
            double sum = 0;
            for (int i = 0; i < N; i++)
            {
                string[] temp = System.Console.ReadLine().Split(' ');
                double num = double.Parse(temp[0]);
                string type = temp[1];
                if (type.Equals("BTC")) { num = num * 380000; }
                sum += num;
            }
            System.Console.WriteLine(sum);
        }
    }

Measured memory_bytes: 11092
50.times{
    m,f,r = gets.split.map(&:to_i)
    if m == -1 && f == -1 && r == -1
        break
    end
sum = m + f
    if m == -1 || f == -1
        puts "F"
    elsif sum >= 80
        puts "A"
    elsif 65 <= sum && sum < 80
        puts "B"
    elsif 50 <= sum && sum < 65
        puts "C"
    elsif 30 <= sum && sum < 50 && r < 50
        puts "D"
    elsif 30 <= sum && sum < 50 && r >= 50
        puts "C"
    elsif sum < 30 
        puts "F"
    end
}



Measured memory_bytes: 6880
#include <bits/stdc++.h>
#define INF 1e18
#define int long long
#define Rep(i, a, n) for (int i = (a); i < (n); i++)
#define rep(i, n) Rep(i, 0, n)
#define all(a) (a).begin(), (a).end()
using namespace std;
typedef pair<int, int> P;
typedef pair<int, P> PP;
const int mod = 1000000007;
//const int mod = 998244353;

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

    string s;
    cin >> s;
    int n = s.size(), ans = 0;
    rep(i, n / 2)
    {
        if (s[i] != s[n - i - 1])
            ans++;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include "bits/stdc++.h"
using namespace std;
const int MOD = 1e9 + 7;
typedef long long lint;
const int INF = 1e7;
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define repi(i, k, n) for (int i = (k); i < (int)(n); ++i)
typedef pair<int, int> P;
typedef vector<lint> vi;
typedef vector<vi> vvi;
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define N 305
vvi d(N, vi(N, INT_MAX));
void warshall_floyd(int n)
{
    for (int i = 0; i < n; i++)
    {
        for (int j = 0; j < n; j++)
        {
            for (int k = 0; k < n; k++)
            {
                d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
            }
        }
    }
}
int main()
{
    int n, m, r;
    cin >> n >> m >> r;
    rep(i, n)
    {
        d[i][i] = 0;
    }
    vi v;
    rep(i, r)
    {
        int rr;
        cin >> rr;
        rr--;
        v.push_back(rr);
    }
    rep(i, m)
    {
        int a, b, c;
        cin >> a >> b >> c;
        a--;
        b--;
        d[a][b] = c;
        d[b][a] = c;
    }
    warshall_floyd(n);
    lint ans = INT_MAX;
    sort(all(v));
    do
    {
        lint cc = 0;
        rep(i, r - 1)
        {
            cc += d[v[i]][v[i + 1]];
        }
        if (cc < ans)
        {
            ans = cc;
        }
    } while (next_permutation(v.begin(), v.end()));
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 1024
n,x,m = map(int,input().split())
exist = [0] * (m+1)
ans = 0
imamade = []
cnt = 0
for i in range(1,n+1):
    if exist[x] == 1:
        break
    else:
        ans += x
        exist[x] = 1
        imamade.append(x)
        x *= x
        x %= m
        cnt += 1
    if i == n:
        print(ans)
        exit()
num = imamade.index(x)
print(sum(imamade[:num]) + sum(imamade[num:]) * ((n-num) // (cnt-num)) + sum(imamade[num:num+((n-num) % (cnt-num))]))


Measured memory_bytes: 69384
import java.util.*;class Main{public static void main(String[]z){Scanner s=new Scanner(System.in);for(int n,a,b,x,y;(n=s.nextInt())>0;System.out.println(a+" "+b))for(a=b=0;n-->0;y=s.nextInt(),a+=x<y?0:x>y?x+y:x,b+=x>y?0:x<y?x+y:x)x=s.nextInt();}}

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

#define endl '\n'
#define int ll
typedef long long ll;

const int MAX_N = 1e5 + 87;
int h[MAX_N] = {};

int dp[MAX_N] = {};

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

    int N;
    cin >> N;
    for (int i = 1; i <= N; i++)
        cin >> h[i];
    
    dp[1] = 0;
    dp[2] = abs(h[2] - h[1]);
    for (int i = 3; i <= N; i++) {
        int temp1 = abs(h[i] - h[i - 1]) + dp[i - 1];
        int temp2 = abs(h[i] - h[i - 2]) + dp[i - 2];
        dp[i] = min(temp1, temp2);
    }

    cout << dp[N];

    return 0;
}

Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
const int N = 2e5+1e3;
int h[N],dp[N];
int main(){
    int n; cin >> n;
    for(int i = 1; i <= n; i++)cin >> h[i];
    dp[0] = -1e9;
    for(int i = 2; i <= n; i++){
        if(i > 2)dp[i] = min(abs(h[i-1]-h[i]) + dp[i-1],abs(h[i-2]-h[i]) + dp[i-2]);
        else dp[i] = abs(h[i-1]-h[i]) + dp[i-1];
    }
    cout << dp[n];
}


Measured memory_bytes: 4356
import fractions
import bisect

N,M = map(int,input().split())
S=input()
T=input()

A=(N//fractions.gcd(N,M))*M

NL=[0]*N
ML=[0]*M

for i in range(N):
    NL[i]=i*(A//N)


for i in range(M):
    ML[i]=i*(A//M)


ANDL = sorted(list(set(NL) & set(ML)))

for i in ANDL:
    St=bisect.bisect_left(NL,i)
    Tt=bisect.bisect_left(ML,i)
    if(S[St]!=T[Tt]):
        print("-1")
        exit()
print(A)


Measured memory_bytes: 20700
import itertools
H,W = map(int,input().split())
C = [list(map(int,input().split())) for i in range(10)]
bit = [0]*10
for i in range(H):
    s = input().split()
    for j in range(W):
        if int(s[j]) == -1: continue
        bit[int(s[j])] += 1

# dist[i][j]: iからjへのコスト,  n:頂点数
def warshall_floyd(dist,n):
    for k in range(n):
        for i in range(n):
            for j in range(n):
                if dist[i][j] > dist[i][k]+dist[k][j]:
                    dist[i][j] = dist[i][k]+dist[k][j]

warshall_floyd(C,10)
ans = 0
for i in range(10):
    ans += C[i][1]*bit[i]
print(ans)

Measured memory_bytes: 3064
use std::io;
use std::io::Read;
use std::iter;

fn merge_sort(xs: &mut [usize], left: usize, right: usize) -> usize {
    if left + 1 < right {
        let mid = (left + right) / 2;
        let ncompleft = merge_sort(xs, left, mid);
        let ncompright = merge_sort(xs, mid, right);
        let ncompthis = merge(xs, left, mid, right);
        ncompleft + ncompright + ncompthis
    } else {
        0
    }
}

fn merge(xs: &mut [usize], left: usize, mid: usize, right: usize) -> usize {
    let l: Vec<usize> = xs[left..mid]
        .iter()
        .cloned()
        .chain(iter::once(std::usize::MAX))
        .collect();
    let r: Vec<usize> = xs[mid..right]
        .iter()
        .cloned()
        .chain(iter::once(std::usize::MAX))
        .collect();
    let mut i = 0;
    let mut j = 0;
    let mut ncomp = 0;

    for k in left..right {
        if l[i] <= r[j] {
            xs[k] = l[i].clone();
            i += 1;
        } else {
            xs[k] = r[j].clone();
            j += 1;
        }
        ncomp += 1;
    }

    ncomp
}

fn main() {
    let mut stdin = io::stdin();
    let mut buf = String::new();

    stdin.read_to_string(&mut buf);

    let mut iter = buf.split_whitespace();
    let n = iter.next().unwrap().parse().unwrap();
    let mut s: Vec<usize> = iter.map(|s| s.parse().unwrap()).collect();
    let cnt = merge_sort(&mut s, 0, n);
    println!(
        "{}",
        s.iter()
            .map(|s| s.to_string())
            .collect::<Vec<_>>()
            .join(" ")
    );
    println!("{}", cnt);
}



Measured memory_bytes: 39696
// AOJ 1575: Product Sale Lines
// 2017.9.29 bal4u@uu

#include <stdio.h>

int main()
{
	int w, h, n, p, x, y, ans;

	scanf("%d%d%d", &w, &h, &n);
	ans = x = y = 0;
	while (n--) {
		scanf("%d", &p);
		if (!p) x++; else y++;
		if (x < w-1) {
			if (y == x) ans++;
		} else if (x == w-1) ;
		else if (x < w+h-2) {
			if (y+2 == x) ans++;
		} else if (x == w+h-2) ;
		else {
			if (y+4 == x) ans++;
		}
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 1848
import sys

n = int(input())
s = input()

if n % 2 == 0:
    n_2 = n // 2
    for i in range(n_2):
        if s[i] == s[i+n_2]:
            continue
        else:
            print('No')
            sys.exit()
            
    print('Yes')
else:
    print('No')


Measured memory_bytes: 2940
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <map>
#include <list>
#include <set>
using namespace  std;

#define int long long int

constexpr int INF = std::numeric_limits<int>::max();

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

    int len = 0;
    int mx = 0;
    while (N--) {
        int l; cin >> l;
        len += l;
        mx = max(mx, l);
    }

    if (len - mx > mx) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
int main()
{
     long int n;
     cin>>n;
  
     long int arr[n-1];
  
    for(int i=1;i<=n-1;i++)
    cin>>arr[i];
  
  
     long int ans=0;
     arr[0]=arr[n]=100000; 
   for(int i=1;i<=n;i++)
   {
     ans+=min(arr[i-1],arr[i]);
   }
    cout<<ans<<endl;
}  

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
h, n = [int(x) for x in input().strip().split()]
a = [0] * n
b = [0] * n
for i in range(n):
    a[i], b[i] = [int(x) for x in input().strip().split()]

dp = [float('inf')] * (h + 1)
dp[0] = 0
for i in range(1, h+1):
    for aa, bb in zip(a, b):
        dp[i] = min(dp[i], dp[max(0, i-aa)]+bb)
print(dp[h])

Measured memory_bytes: 42348
#include <iostream>
#include <string.h>
#include <algorithm>
using namespace std;
int A[100005],B[100005];
int  main(){
    ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    int a,b,c;
    cin>>a>>b>>c;
    int n=0,m=0; int e,f;
    for(int i=1;i<=a;i++){
        cin>>A[i];
        if(n==0){
            e=A[i]; n++;
        }
        else e=min(e,A[i]);
    }
    for(int i=1;i<=b;i++) {
        cin>>B[i];
        if(m==0){
            f=B[i]; m++;
        }
        else f=min(f,B[i]);
    }
    int k=e+f;
    for(int i=0;i<c;i++){
        int z,x,v; cin>>z>>x>>v;
        k=min(k,A[z]+B[x]-v);
    }
    cout<<k<<endl;
}


Measured memory_bytes: 1024
import itertools
n, m, q = map(int, input().split())
abcd = [list(map(int, input().split())) for _ in range(q)]
l = list(itertools.combinations_with_replacement(range(1, m+1), n))
ans = 0
for i in l:
    w = 0
    for j in abcd:
        if i[j[1]-1] - i[j[0]-1] == j[2]:
            w += j[3]
    ans = max(ans, w)
print(ans)

Measured memory_bytes: 21612
#include <iostream>
#include <algorithm>
using namespace std;
int main(void){
    int h,w;
    cin>>h>>w;
    if(h%3==0){
        cout<<0<<endl;
        return 0;
    }
    if(w%3==0){
        cout<<0<<endl;
        return 0;
    }
    int ans=min(h,w);
        if(w%2==0)ans=min(ans,w/2);
        else ans=min(ans,max(w/2+h/3,(h/3)*2)+1);
        
        if(h%2==0)ans=min(ans,h/2);
        else ans=min(ans,max(h/2+w/3,(w/3)*2)+1);
    
    cout<<ans<<endl;
    
    return 0;
    
}

Measured memory_bytes: 256
#include <stdio.h> 
int main(void)
{
int x[10000],i,j;
i=0;
scanf("%d",&x[i]);
while(x[i]!=0){
	i++;
	scanf("%d",&x[i]);
}
j=i-1;
for(i=0;i<=j;i++){
	printf("Case %d: %d\n",i+1,x[i]);
}
return 0;
}


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

typedef long long ll;
typedef unsigned long long ull;
typedef pair<ll, ll> P;

#define fi first
#define se second
#define repl(i,a,b) for(ll i=(ll)(a);i<(ll)(b);i++)
#define rep(i,n) repl(i,0,n)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define mmax(x,y) (x>y?x:y)
#define mmin(x,y) (x<y?x:y)
#define maxch(x,y) x=mmax(x,y)
#define minch(x,y) x=mmin(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt __builtin_popcount

string s;
ll k;
ll n;
ll dp[2001][2001];
ll cnt[2001][2001];

ll dfs(ll l,ll r){
  if(l>r){
    cnt[l][r]=1;
    return 0;
  }
  if(dp[l][r]!=-1)return dp[l][r];
  ll res;
  if(s[l]==s[r]){
    res=dfs(l+1,r-1)+(l==r?1:2);
    cnt[l][r]=cnt[l+1][r-1];
  }else{
    ll resl=dfs(l+1,r)+2;
    ll resr=dfs(l,r-1)+2;
    if(resl==resr){
      res=resl;
      cnt[l][r]=cnt[l+1][r]+cnt[l][r-1];
    }else if(resl<resr){
      res=resl;
      cnt[l][r]=cnt[l+1][r];
    }else{
      res=resr;
      cnt[l][r]=cnt[l][r-1];
    }
  }
  if(cnt[l][r]>1e18)cnt[l][r]=1e18+1;
  return dp[l][r]=res;
}

string dfs2(ll l,ll r,ll crtk){
  if(l>r)return "";
  if(l==r)return s.substr(l,1);
  string res;
  if(s[l]==s[r]){
    res+=s[l];
    res+=dfs2(l+1,r-1,crtk);
    res+=s[r];
  }else{
    if(dp[l+1][r]==dp[l][r-1]){
      if(s[l]<s[r]){
        if(crtk<=cnt[l+1][r]){
          res+=s[l];
          res+=dfs2(l+1,r,crtk);
          res+=s[l];
        }else{
          crtk-=cnt[l+1][r];
          res+=s[r];
          res+=dfs2(l,r-1,crtk);
          res+=s[r];
        }
      }else{
        if(crtk<=cnt[l][r-1]){
          res+=s[r];
          res+=dfs2(l,r-1,crtk);
          res+=s[r];
        }else{
          crtk-=cnt[l][r-1];
          res+=s[l];
          res+=dfs2(l+1,r,crtk);
          res+=s[l];
        }
      }
    }else if(dp[l+1][r]<dp[l][r-1]){
      res+=s[l];
      res+=dfs2(l+1,r,crtk);
      res+=s[l];
    }else{
      res+=s[r];
      res+=dfs2(l,r-1,crtk);
      res+=s[r];
    }
  }
  return res;
}

int main(){
  cin>>s>>k;
  n=s.size();
  memset(dp,-1,sizeof(dp));
  dfs(0,n-1);
  if(cnt[0][n-1]<k){
    cout<<"NONE"<<endl;
    return 0;
  }
  string res=dfs2(0,n-1,k);
  cout<<res<<endl;
  return 0;
}



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

for i_1 in range(n):
    if a[i_1]==1:
        break

#print(i_1)
#print(a[:i_1],a[i_1+1:])
if len(a[:i_1])==0:
    ans = len(a[i_1+1:])//(k-1)
    if len(a[i_1+1:])%(k-1)==0:
        print(ans)
    else:
        print(ans+1)
elif len(a[i_1+1:])==0:
    ans = len(a[:i_1])//(k-1)
    if len(a[:i_1])%(k-1)==0:
        print(ans)
    else:
        print(ans+1)
else:
    ans = len(a[:i_1])//(k-1) + 1
    tmp = ans * (k-1)
    ans += len(a[tmp+1:])//(k-1)
    if len(a[tmp+1:])%(k-1)==0:
        print(ans)
    else:
        print(ans+1)


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

int main(){
    int N;
    cin >> N;
    int counter = 0;
    rep (i, N){
        int l, r;
        cin >> l >> r;
        counter += r - l + 1;
    }
    cout << counter << endl;
}

Measured memory_bytes: 256
#include<stdio.h>
int main(void)
{
  int n;
  int a[10000];
  long long int min=9999999999;
  long long int sum;
  
  scanf("%d",&n);
  for(int i=0;i<n;i++){
    scanf("%d",&a[i]);
  }
  for(int i=-100;i<=100;i++){
    sum=0;
    for(int j=0;j<n;j++){
      sum+=(a[j]-i)*(a[j]-i);
    }
    if(min>sum)min=sum;
  }
  printf("%lld\n",min);
}

Measured memory_bytes: 128
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String S = sc.nextLine();
        String T = sc.nextLine();
        sc.close();

        boolean isOK = true;
        for (int i = 0; i < S.length(); i++) {
            char sVal = S.charAt(i);
            char tVal = T.charAt(i);
            if (sVal != tVal) {
                isOK = false;
                break;
            }
        }

        if (isOK) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }

}


Measured memory_bytes: 35548
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>

int main()
{
	int a[101][101], b[101], c[101];
	int i, j;
	int n, m;

	scanf("%d%d", &n, &m);
	for (i = 0; i < n; i++) {
		for (j = 0; j < m; j++) scanf("%d", &a[i][j]);
	}
	for (j = 0; j < m; j++) scanf("%d", &b[j]);

	for (i = 0; i < n; i++) {
		c[i] = 0;
		for (j = 0; j < m; j++) c[i] += a[i][j] * b[j];
	}

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



Measured memory_bytes: 2144
/*
#include "stdafx.h"
#include<iostream>
#include<vector>
#include<algorithm>
#include<queue>
#include<stack>
#include<cmath>
#include<complex>
*/

#include<bits/stdc++.h>

#define X real()
#define Y imag()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ff first
#define ss second
#define FastF freopen("in.txt","r",stdin); freopen("out.txt","w",stdout)
#define Fast cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0)
using ll = long long;
using namespace std;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vi::iterator vii;
typedef vector<ll> vl;
typedef vl::iterator vli;
typedef long double C;
typedef complex<C> P;
const int INF = 1e9 + 5;
const ll INFF = 1e18 + 5;
const int M = 1e9 + 7;
const double pi = acos(-1);

int main()
{
	//FastF;
	Fast;
	int n; cin >> n;
	vi h(n + 2);
	for (int i = 0; i < n; ++i) {
		cin >> h[i];
	}
	vi dp(n + 2,INF);
	dp[0] = 0;
	for (int i = 0; i < n; ++i) {
		for (int j : {i + 1, i + 2}) {
			dp[j] = min(dp[j], dp[i] + abs(h[i] - h[j]));
		}
	}
	cout << dp[n - 1] << '\n';
	return 0;
}

Measured memory_bytes: 1024
package main

import (
	"fmt"
	"sort"
)

func main() {
	var N int
	fmt.Scan(&N)
	
	mochis := make([]int,N)
	
	//mochis格納
	for i, _ := range mochis {
		fmt.Scan(&mochis[i])
	}
	
	//降順に並び替え
	sort.Sort(sort.Reverse(sort.IntSlice(mochis)))
	
	//重複の排除
	step := mochis[0]
	cnt := 1
	
	for _, v := range mochis {
		if step == v {
			continue
		} else {
			step = v
			cnt++
		}
	}
	fmt.Println(cnt)
}

Measured memory_bytes: 512
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define rrng(a) a.rbegin(),a.rend()
#define maxs(x,y) (x = max(x,y))
#define mins(x,y) (x = min(x,y))
#define limit(x,l,r) max(l,min(x,r))
#define lims(x,l,r) (x = max(l,min(x,r)))
#define isin(x,l,r) ((l) <= (x) && (x) < (r))
#define pb push_back
#define eb emplace_back
#define sz(x) (int)(x).size()
#define pcnt __builtin_popcountll
#define uni(x) x.erase(unique(rng(x)),x.end())
#define show(x) cout<<#x<<" = "<<x<<endl;
#define print(x)cout<<x<<endl;
#define PQ(T) priority_queue<T,v(T),greater<T> >
#define bn(x) ((1<<x)-1)
#define dup(x,y) (((x)+(y)-1)/(y))
#define newline puts("")
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef unsigned uint;
typedef unsigned long long ull;
typedef pair<int,int> P;
typedef tuple<int,int,int> T;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
typedef vector<T> vt;
const int mod = 1000000007;
struct mint {
  ll x;  // typedef long long ll;
  mint(ll x = 0) : x((x % mod + mod) % mod) {}
  mint operator-() const { return mint(-x); }
  mint& operator+=(const mint a) {
    if ((x += a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator-=(const mint a) {
    if ((x += mod - a.x) >= mod) x -= mod;
    return *this;
  }
  mint& operator*=(const mint a) {
    (x *= a.x) %= mod;
    return *this;
  }
  mint operator+(const mint a) const {
    mint res(*this);
    return res += a;
  }
  mint operator-(const mint a) const {
    mint res(*this);
    return res -= a;
  }
  mint operator*(const mint a) const {
    mint res(*this);
    return res *= a;
  }
  mint pow(ll t) const {
    if (!t) return 1;
    mint a = pow(t >> 1);
    a *= a;
    if (t & 1) a *= *this;
    return a;
  }

  // for prime mod
  mint inv() const { return pow(mod - 2); }
  mint& operator/=(const mint a) { return (*this) *= a.inv(); }
  mint operator/(const mint a) const {
    mint res(*this);
    return res /= a;
  }
};

mint dp[110][110000];
mint dp_sum[110][110000];

int main() {
  int n,k;
  cin >> n >> k;
  vl a(n);
  rep(i,n)cin >> a[i];
  rep(j,k+1)dp_sum[0][j] = 1;
  rep(i,n){
    rep(j,k+1){
      if(j-a[i]-1 >= 0)dp[i+1][j] = dp_sum[i][j] - dp_sum[i][j-a[i]-1];
      else dp[i+1][j] = dp_sum[i][j];
      if(j>=0)dp_sum[i+1][j] = dp[i+1][j]+dp_sum[i+1][j-1];
      else  dp_sum[i+1][j] = dp[i+1][j];
    }
  }
  cout<<dp[n][k].x<<endl;
  return 0;
}

Measured memory_bytes: 189312