akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <queue>
#include <map>

using namespace std;

class S{
public:
  int g, d, s, e;
  S(){}
  S(int g, int d, int s, int e) : g(g), d(d), s(s), e(e) {}
};

class State{
public:
  int y, x, used, t, sum;
  State(){}
  State(int y, int x, int used, int t, int sum) : y(y), x(x), used(used), t(t), sum(sum) {}
};

int w, h, n;
char mapData[20][20];
map<int, int> conv;
S data[10];
int sy, sx;
int dy[] = {-1, 0, 1, 0};
int dx[] = {0, 1, 0, -1};

int bfs(){
  bool vis[20][20][1<<10];
  fill(vis[0][0], vis[20][0], false);
  State u, v;
  u = State(sy, sx, 0, 0, 0);
  queue<State> q;
  q.push(u);
  vis[u.y][u.x][u.used] = true;
  int res = 0;
  while(!q.empty()){
    u = q.front(); q.pop();
    for(int i=0;i<4;i++){
      int ny = u.y + dy[i];
      int nx = u.x + dx[i];
      if(ny<0 || ny>=h) continue;
      if(nx<0 || nx>=w) continue;
      if(mapData[ny][nx] != '.'){
        int num = conv[mapData[ny][nx] - '0'];
        if(u.t < data[num].e && !((1 << num) & u.used)){
          if(u.t >= data[num].s){
            v.y = u.y;
            v.x = u.x;
            v.used = u.used | (1<<num);
            v.t = u.t;
            v.sum = u.sum + data[num].d;
            res = max(res, v.sum);
            if(!vis[v.y][v.x][v.used]){
              vis[v.y][v.x][v.used] = true;
              q.push(v);
            }
          }else q.push(State(u.y, u.x, u.used, data[num].s, u.sum));
        }
      }else{
        if(!vis[ny][nx][u.used]){
          vis[ny][nx][u.used] = true;
          q.push(State(ny, nx, u.used, u.t+1, u.sum));
        }
      }
    }
  }
  return res;
}

main(){
  while(cin >> w >> h && (w|h)){
    conv.clear();
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
        cin >> mapData[i][j];
        if(mapData[i][j] == 'P'){
          mapData[i][j] = '.';
          sy = i;
          sx = j;
        }
      }
    }
    cin >> n;
    for(int i=0;i<n;i++){
      int a, b, c, d;
      cin >> a >> b >> c >> d;
      data[i] = S(a, b, c, d);
      conv[a] = i;
    }
    cout << bfs() << endl;
  }
}

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

int main() {
    int p; cin >> p;
    int d = p % 10;
    int c = (p % 100 - d) / 10;
    int b = (p % 1000 - c) / 100;
    int a = (p % 10000 - b) / 1000;
    //cout << a << b << c << d << endl;

    int s[] = {1, -1};
    vector<int> res(3);
    for (int i=0; i<2; ++i) {
        for (int j=0; j<2; ++j) {
            for (int k=0; k<2; ++k) {
                int ans = a + b * s[i] + c * s[j] + d * s[k];
                if (ans == 7) {
                    res[0] = b * s[i];
                    res[1] = c * s[j];
                    res[2] = d * s[k];
                }
            }
        }
    }

    cout << a;
    for (int i=0; i<3; ++i) {
        if (res[i] >= 0) cout << '+' << res[i];
        else cout << res[i];
    }
    cout << "=7" << endl;
}

Measured memory_bytes: 256
# include "cstdio"

using namespace std;

int main(){
	int maxx=0,minn=0x7f7f7f7f,n,now;
	scanf("%d",&n);
	for(register int i=1;i<=n;i++){
		scanf("%d",&now);
		minn=minn<now?minn:now;
		maxx=maxx>now?maxx:now;
	}
	printf("%d",maxx-minn);
	return 0;
}

Measured memory_bytes: 128
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
int main()
{
	char c[99],d[80];
	double s[80],t;
	int n,p,q;
	while(gets(c))
	{
		if(c[0] == 0)
			break;
		for(n=0,p=-1,q=0;c[n];n++)
		{
			switch(c[n])
			{
			case '+':
				t=s[p-1]+s[p];
				s[--p]=t;
				break;
			case '*':
				t=s[p-1]*s[p];
				s[--p]=t;
				break;
			case '/':
				t=s[p-1]/s[p];
				s[--p]=t;
				break;
			case ' ':
				if(q!=0)
				{
					s[++p]=atof(d);
					memset(d,NULL,80);
					q=0;
				}
				break;
			case '-':
				if(c[n+1]==' '||c[n+1]=='\0')
				{
					t=s[p-1]-s[p];
					s[--p]=t;
					break;
				}
			default:
				d[q++]=c[n];
			}
		}
		if(q!=0)
			s[0]=atof(d);
		printf("%f\n",s[0]);
	}
	return 0;
}

Measured memory_bytes: 572
#include <bits/stdc++.h>
#define FR first
#define SE second

using namespace std;

typedef pair<int,int> pr;

vector <pr> ans;

int main() {
  int n;
  scanf("%d",&n);
  int m=((n&1)?n:n+1);
  for(int i=1;i<=n;i++)
    for(int j=i+1;j<=n;j++)
      if (i+j!=m) ans.push_back(pr(i,j));
  printf("%d\n",ans.size());
  for(int i=0;i<ans.size();i++) printf("%d %d\n",ans[i].FR,ans[i].SE);
  return 0;
}


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

int main() {
    string S;
    cin >> S;
    int sum = 700;
    for(int i = 0; i < 3; i++) {
        if(S.at(i) == 'o') {
            sum += 100;
        }
    }
    cout << sum << endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		long M = sc.nextLong();
		int A[] = new int[N];
		for(int i=0;i<N;i++)A[i]=sc.nextInt();
 		sc.close();
 		
 		rsort(A);
 		
 		//２数の和がKを越えるものだけ使うことにする。
 		int R = 2*100000 + 100;
 		int L = 0;
 		while(L+1<R) {		
 			int C = (L+R)/2;//このcが実現できるか調べるK
 			long subsum = 0;
 			for(int i=0;i<N;i++) {
 				int base = A[i];
 				int r = N;
 				int l = i-1;
 				while(l+1<r) {
 					int c = (l + r)/2;
 					if(base + A[c]>=C)l=c;
 					else r = c;
 				}
 				if(l-i<0)continue;
 				subsum += 1 + 2*(l-i);
 			}
 			if(subsum>=M) L = C;
 			else R = C;
 		}
 		//Lが最大のK
 		
 		long memosum = 0;
 		int min = Integer.MAX_VALUE;
 		int memo[] = new int[N];
 		for(int i=0;i<N;i++) {
				int base = A[i];
				int r = N;
				int l = i-1;
				while(l+1<r) {
					int c = (l + r)/2;
					if(base + A[c]>=L)l=c;
					else r = c;
				}
				memo[i]=l-i; 
				
				if(l-i>=0) {
					memosum += 2*(l-i)+1;
					min = Math.min(min,base+A[l]);
				}
				
			}
 		
 		
 		
 		long sum[] = new long[N+1];
 		for(int i=0;i<N;i++)sum[i+1]=sum[i]+ A[i];
 		
 		long ans = 0;
 		for(int i=0;i<N;i++) {
 			if(memo[i]<0)break;
			int last = i+memo[i];
			long tmp = ((long)last-i+1)*2*A[i]+2*(sum[last+1]-sum[i+1]);
			ans += tmp;
 		}
 		long mul = Math.max(0,memosum-M);
 		ans -= mul*min;
 		System.out.println(ans);
	}
	
	static void rsort(int[] x) {
		Arrays.sort(x);
		int len = x.length;
		for(int i=0;i<len/2;i++) {
			int tmp = x[i];
			x[i]=x[len-1-i];
			x[len-1-i]=tmp;
		}
	}
}


Measured memory_bytes: 51516
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll, ll> l_l;
typedef pair<int , int> i_i;
typedef vector<ll> vel;
typedef vector<int> vei;
typedef vector<char> vec;
typedef vector<bool> veb;
typedef vector<string> ves;
typedef vector<vector<ll>> ve_vel;
typedef vector<vector<int>> ve_vei;
typedef vector<vector<char>> ve_vec;
typedef vector<vector<bool>> ve_veb;
typedef vector<vector<string>> ve_ves;
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define rep1(i,n) for(int i=1;i<(int)(n);i++)
#define rep2(i,n) for(int i=2;i<(int)(n);i++)
#define repk(i,k,n) for(int i=k;i<(int)(n);i++)
#define fs first
#define sc second
#define pub push_back
#define pob pop_back
#define all(a) a.begin(),a.end()
#define rall(a) a.rbegin(),a.rend()
#define maxel(a) *max_element(all(a))
#define minel(a) *min_element(all(a))
#define acc accumulate
#define EPS (1e-7)
//#define INF (1e9)
#define PI (acos(-1))
#define mod (1000000007)
typedef long long int64;
const int64 INF = 1LL << 58;
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; }

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
    
    int time; cin >> time;
    int h = time / 3600;
    time -= h * 3600;
    int m = time / 60;
    int s = time % 60;
    cout << h << ":" << m << ":" << s << endl;
}


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

bool hantei(string T) {
	if (T.size() < 6) { return false; }
	int a = 0, b = 0, c = 0;
	for (int i = 0; i < T.size(); i++) {
		if (isdigit(T[i])) { a++; }
		if (islower(T[i])) { b++; }
		if (isupper(T[i])) { c++; }
	}
	if (a == 0) { return false; }
	if (b == 0) { return false; }
	if (c == 0) { return false; }
	return true;
}

string S;

int main() {
	cin >> S;
	if (hantei(S) == true) { cout << "VALID" << endl; }
	else { cout << "INVALID" << endl; }
	return 0;
}

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

int main() {
  int n, p;
  string s;
  cin >> n;
  vector<tuple<string, int, int>> v(n);
  for (int i = 0; i < n; i++) {
    cin >> s >> p;
    v.at(i) = make_tuple(s, 100 - p, i);
  }
  
  sort(v.begin(), v.end());
  for (int i = 0; i < n; i++)
    cout << get<2>(v.at(i)) + 1 << endl;
  
}



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

typedef long long ll;
typedef unsigned long long ull;
typedef unsigned __int128 HASH;
typedef pair<int,int> pii;
typedef pair<ll, ll> pll;
typedef pair<ull, ull> pullull;
typedef pair<ll,int> plli;
typedef pair<double, int> pdbi;
typedef pair<int,pii> pipii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;
typedef vector<vvi> vvvi;
typedef vector<pii> vpii;
typedef vector<vector<int>> mat;

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n);i>0;i--)
#define rrep2(i,a,b) for (int i=(a);i>b;i--)
#define pb push_back
#define fi first
#define se second
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()

const ll hmod1 = 999999937;
const ll hmod2 = 1000000000 + 9;
const ll INF = 1<<30;
const ll mod = 10000 + 7;
const int dx4[4] = {1, 0, -1, 0};
const int dy4[4] = {0, 1, 0, -1};
const int dx8[8] = {1, 1, 1, 0, 0, -1, -1, -1};
const int dy8[8] = {0, 1, -1, 1, -1, 0, 1, -1};
const double pi = 3.141592653589793;

#define int long long
#define addm(X, Y) (X) = ((X) + ((Y) % mod) + mod) % mod

int n, m, k;

signed main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m >> k;
    rep2(i, 0, n + 1)rep2(j, 0, m + 1) {
        if (i * (m - j) + j * (n - i) == k) {
            cout << "Yes" << endl;
            return 0;
        }
    }
    cout << "No" << endl;
}


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

#define ff first
#define ss second

const int MAXN = 50005;
const double INF = 100000000000;
int n;

int t[MAXN];
int sum(int idx)
{
    int res = 0;
    while (idx)
    {
        res += t[idx];
        idx -= (idx & -idx);
    }
    return res;
}

void upd(int idx, int val)
{
    int old_val = sum(idx) - sum(idx-1);
    while (idx <= n)
    {
        t[idx] += (val - old_val);
        idx += (idx & -idx);
    }
}


struct line
{
    double A, B, C;
} L[MAXN];

pair <double, int> cross[MAXN];

bool compX(line A, line B)
{
    return -(A.B/A.A) > -(B.B/B.A);
}

bool compY(line A, line B)
{
    return -(A.A/A.B) > -(B.A/B.B);
}

int main()
{
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> L[i].A >> L[i].B >> L[i].C;

    int HALF = (n*(n-1)/2 + 1) / 2;

    sort(L, L + n, compX);
    double l = -INF;
    double r = INF;
    for (int q = 0; q < 100; q++)
    {
        double m = (l + r) / 2;
        for (int i = 0; i < n; i++)
        {
            cross[i].ff = (L[i].C - L[i].B*m) / L[i].A;
            cross[i].ss = i+1;
        }
        sort(cross, cross + n);
        for (int i = 0; i < n; i++)
            upd(i+1, 1);

        int res = 0;
        for (int i = 0; i < n; i++)
        {
            res += sum(cross[i].ss - 1);
            upd(cross[i].ss, 0);
        }

        if (res >= HALF)
            r = m;
        else l = m;
    }
    double ansY = r;
    sort(L, L + n, compY);
    l = -INF;
    r = INF;
    for (int q = 0; q < 100; q++)
    {
        double m = (l + r) / 2;
        for (int i = 0; i < n; i++)
        {
            cross[i].ff = (L[i].C - L[i].A*m) / L[i].B;
            cross[i].ss = i+1;
        }
        sort(cross, cross + n);

        for (int i = 0; i < n; i++)
            upd(i+1, 1);

        int res = 0;
        for (int i = 0; i < n; i++)
        {
            res += sum(cross[i].ss - 1);
            upd(cross[i].ss, 0);
        }

        if (res >= HALF)
            r = m;
        else l = m;
    }
    double ansX = r;

    cout << setprecision(13) << fixed << ansX << " " << ansY;
    return 0;
}


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


int main() {
    int n,k;
    cin >> n >> k;
    bool have[n];
    rep(i,n) have[i] = false;
    
    rep(i,k) {
        int d;
        cin >> d;
        rep(j,d) {
            int x;
            cin >> x;
            have[x-1] = true;
        }
    }

    int ans = 0;
    rep(i,n) {
        if(have[i]==false) ans++;
    }

    cout << ans << endl;


    return 0;
}



Measured memory_bytes: 3632
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; ++i)
#define FOR(i, a, b) for (int i = a; i < b; ++i)
#define ALL(vec) vec.begin(), vec.end()
#define rALL(vec) vec.rbegin(), vec.rend()
using namespace std;
using ll = long long;
// ------------------------------

int main() {
    int L, R, d;
    cin >> L >> R >> d;
    int ans = 0;
    FOR(i, L, R + 1){
        if (i % d == 0) ans += 1;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3524
#include <bits/stdc++.h>
const int MAX = 1e5 + 10;
const int MOD = 1e9 + 7;
const double EPS = 1e-9;
typedef long long ll;
using namespace std;
#define mul(a, b) (((i64)(a) * (b) ) % MOD)
#define sum(a, b) (((a) + (b) ) % MOD)

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

	#define endl '\n'

	#ifdef LOCAL_DEBUG
		freopen("data.in", "r", stdin );
	#endif
	int n; cin >> n;
	vector<string> ar(n);
	for(int i = 0; i <n; i++)
		cin >> ar[i];
	int ans = 0;
	for(int ba = -(n - 1); ba <= n - 1; ba++){
		bool ok = true;;
		for(int i = 0; i <n ;i++)
			for(int j = 0;j < n; j++){
				if(ar[i][j] != ar[(j + ba + n) % n][(i - ba + n) % n]){
					ok = false;
					j = i = n;
				}
			}
		if(ok){
			if(ba < 0){
				ans += n + ba;
			}
			else{
				ans += n - ba;
			}
		}

	}
	cout << ans << endl;


}


Measured memory_bytes: 384
N=int(input())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
for i in range(1,N): A[i]+=A[i-1]
for i in range(N-2,-1,-1): B[i]+=B[i+1]
ans=max(A[i]+B[i] for i in range(N))
print(ans)


Measured memory_bytes: 9040
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cmath>
#include <cstdlib>
#include <cstring>
#include <deque>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <sstream>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <vector>

#define len(X) ((int)(X).size())

#ifdef __LOCAL
#define DBG(X) cout << #X << "=" << (X) << '\n';
#define SAY(X) cout << (X) << '\n';
#else
#define DBG(X)
#define SAY(X)
#endif

using namespace std;

using ll = long long int;
using ull = unsigned long long int;
using ld = long double;
using pii = pair<int, int>;
using pll = pair<ll, ll>;

const int INT_INF = (int)(2e9);
const ll  LL_INF = (ll)(2e18);

const int NIL = -1;
static mt19937 _g(time(nullptr));

std::string pad(int num)
{
    char buffer[4];
    std::snprintf(buffer, sizeof(buffer), "%03d", num);
    return buffer;
}

inline ll randint(ll a, ll b) { ll w = (_g() << 31LL) ^ _g(); return a + w % (b - a + 1); }
inline void fast_io() { ios_base::sync_with_stdio(false); cin.tie(nullptr); cout.tie(nullptr); };
template<typename T> inline T sign(T x) { return T(x > 0) - T(x < 0); }
template<typename T, typename S> inline ostream& operator<<(ostream& os, const pair<T, S> p) { cout << "[" << p.first << ";" << p.second << "]"; return os; }
template<typename T> inline ostream& operator<<(ostream& os, const vector<T>& v) { for (auto el : v) cout << el << " "; return os; }
template<typename T> inline T fetch() { T ret; cin >> ret; return ret; }
template<typename T> inline vector<T> fetch_vec(int sz) { vector<T> ret(sz); for (auto& elem : ret) cin >> elem; return ret; }

#ifdef _MSC_VER
#  include <intrin.h>
#  define __builtin_popcount __popcnt
#endif

ll solve()
{
    int N;

    std::cin >> N;

    vector<int> v = fetch_vec<int>(N);
    unordered_map<int, int> vplus;

    ll counter = 0;

    for (int i = 0; i < N; ++i) {
        counter += vplus[i - v[i]];
        vplus[v[i] + i]++;
    }

    return counter;
}

int main()
{
    std::cout << solve() << std::endl;
//    solve();

    return 0;
}

Measured memory_bytes: 19412
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char X[1001];
char Y[1001];
int LCS(int r,int s);

int main(){
  int q, i, out;
  int l1,l2;

  scanf("%d", &q);

  for(i = 0;i < q;i++){
    scanf("%s", X);
    scanf("%s", Y);
    l1 = strlen(X);
    l2 = strlen(Y);
    out = LCS(l1, l2);
    printf("%d\n", out);
  }
  return 0;
}

int LCS(int r, int s){
  int i, j;
  int t[1001][1001];

  for(i = 0;i <= r;i++){
    t[i][0] = 0;
  }
  for(i = 0;i <= s;i++){
    t[0][j] = 0;
  }

  for(i = 1;i <= r;i++){
    for(j = 1;j <= s;j++){
      if(X[i-1] == Y[j-1]){
        t[i][j] = t[i-1][j-1]+1;
      }else if(t[i-1][j-1] >= t[i][j-1]){
        t[i][j] = t[i-1][j];
      }else{
        t[i][j] = t[i][j-1];
      }
    }
  }

  if(i == 0 || j == 0){
    return 0;
  }else if(i > 0 && j > 0 && r == s){
    return t[i-1][j-1];
  }else if(i > 0 && j > 0 && r != s){
    return t[r][s];
  }
  return 0;
}

Measured memory_bytes: 4512
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

int main(void) {

int ar[100][100];
char *ptr;
int z,i,j,count;
char str[100]={'\0'};
char *ln;

fgets(str, 100, stdin); // 入力："123456\n"
ln = strchr(str, '\n'); /* 改行文字を検索 */
if (ln != NULL) { /* 改行が読み取られていたかどうか */
   *ln = '\0';    /* 改行文字を終端文字に置き換える */
}
else {            /* 入力ストリーム上に文字が残ってる場合 */
   while (1) {    /* 改行文字が読み取られるまで空読みする */
       z = getchar();
      if (z == '\n' || z == EOF) break;
   }
}

	count=0;
    
    ptr = strtok(str, " ");
    i = atoi(ptr);
    
    ar[0][count]=i;
    count=count+1;
    
    
    // 2回目以降
    while(ptr != NULL) {
        // strtok関数により変更されたNULLのポインタが先頭
        ptr = strtok(NULL, " ");
        
        // ptrがNULLの場合エラーが発生するので対処
        if(ptr != NULL) {
		    i = atoi(ptr);
		      ar[0][count]=i;
    		count=count+1;
        }
    }

//printf("%d\n",ar[0][0]);
//printf("%d\n",ar[0][1]);

fgets(str, 100, stdin); // 入力："123456\n"
ln = strchr(str, '\n'); /* 改行文字を検索 */
if (ln != NULL) { /* 改行が読み取られていたかどうか */
   *ln = '\0';    /* 改行文字を終端文字に置き換える */
}
else {            /* 入力ストリーム上に文字が残ってる場合 */
   while (1) {    /* 改行文字が読み取られるまで空読みする */
       z = getchar();
      if (z == '\n' || z == EOF) break;
   }
}

	count=0;
    
    ptr = strtok(str, " ");
    i = atoi(ptr);
    
    ar[1][count]=i;
    count=count+1;
    
    
    // 2回目以降
    while(ptr != NULL) {
        // strtok関数により変更されたNULLのポインタが先頭
        ptr = strtok(NULL, " ");
        
        // ptrがNULLの場合エラーが発生するので対処
        if(ptr != NULL) {
		    i = atoi(ptr);
		      ar[1][count]=i;
    		count=count+1;
        }
    }

//printf("%d\n",ar[1][0]);
//printf("%d\n",ar[1][1]);

int a,b,c,d;

a=ar[0][0];
b=ar[0][1];
c=ar[1][0];
d=ar[1][1];

printf("%d\n",a*b-a*d-b*c+c*d);


    return 0;
}


Measured memory_bytes: 128
#[allow(unused_imports)]
use std::collections::VecDeque;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        #[allow(unused_variables)]
        #[allow(unused_mut)]
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        n: chars
    }
    let a = if n[2] == n[3] && n[4] == n[5] {"Yes"} else {"No"};
    println!("{}", a);
}


Measured memory_bytes: 4352
#ifdef MY_LOCAL
#define MY_NAMESPACE(ns) namespace ns {
#define MY_NAMESPACE_    }
#define MY_DEBUG(s)      s
#else
#define MY_NAMESPACE(ns) 
#define MY_NAMESPACE_    
#define MY_DEBUG(s)      
#endif

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <random>
#include <set>
#include <string>
#include <tuple>
#include <unordered_map>
#include <utility>
#include <vector>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define EPS (1e-7)


MY_NAMESPACE(testbed)
const ll inf = 1e9;
#define sz      15
int arr[sz][sz];


int main()
{
	int n, m, x;
	cin >> n >> m >> x;

	vector<int> cost(n);
	for (int i = 1; i <= n; i++)
	{
		cin >> cost[i - 1];
		for (int j = 1; j <= m; j++)
		{
			cin >> arr[i][j];
		}
	}

	int ans = inf;
	for (int mask = 0; mask < (1 << n); mask++)
	{
		int c = 0;
		vector<int> level(m + 1);
		for (int i = 1; i <= n; i++)
		{
			if (mask & (1 << (i - 1)))
			{
				c += cost[i - 1];
				for (int j = 1; j <= m; j++)
				{
					level[j] += arr[i][j];
				}
			}
		}
		bool ok = true;
		for (int i = 1; i <= m; i++)
		{
			if (level[i] < x)
				ok = false;
		}
		if (ok)
			ans = min(ans, c);
	}
	if (ans == inf)
		cout << -1 << "\n";
	else
		cout << ans << "\n";
	return 0;
}
MY_NAMESPACE_

Measured memory_bytes: 3620
N=int(input())
edge=[list(map(int,input().split())) for i in range(N-1)]
C=list(map(int, input().split()))
from heapq import heapify,heappop
for i in range(N):
    C[i]=-C[i]
heapify(C)
c=[[] for i in range(N)]
for i,j in edge:
    c[i-1].append(j-1)
    c[j-1].append(i-1)
d=[-1]*N
d[0]=-heappop(C)
v=[0]*N
v[0]=1
SUM=d[0]
import sys
sys.setrecursionlimit(10**5)
def dfs(p,v,d):
    global SUM
    for n in c[p]:
        if v[n]==0:
            d[n]=-heappop(C)
            SUM+=d[n]
            v[n]=1
            dfs(n,v,d)
dfs(0,v,d)
print(SUM-d[0])
for i in range(N-1):
    print(d[i],end=' ')
print(d[N-1])

Measured memory_bytes: 16136
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <sstream>
#include <string>
#include <vector>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <utility>
using namespace std;

#define rep(i,n) for((i)=0; (i)<(int)(n); ++(i))
#define foreach(c,itr) for(__typeof((c).begin()) itr=(c).begin();itr!=(c).end();itr++)

int n, m, a[1002];

int main() {
  int i;
  while (cin >> n >> m, n|m) {
    rep (i,n) cin >> a[i];
    
    int cur_time = 0, cur = -1, cur_lv = 1002;
    bool multi = false;
    rep (i,n) {
      if (i == 0) {
        cur_time = m - (m % a[i]);
        cur = 0;
        cur_lv = a[i];
        continue;
      }
      int tmp_time = m - (m % a[i]);
      if (a[i] > m) tmp_time = 0;
      if (tmp_time > cur_time) continue;
      else if (tmp_time == cur_time) {
        if (cur_lv == a[i]) {
          multi = true;
          continue;
        }
        if (cur_lv < a[i]) continue;
        if (cur_lv > a[i]) {
          cur_lv = a[i];
          cur = i;
          continue;
        }
        multi = true; continue;
      }
      else if (tmp_time < cur_time) {
        multi = false;
        cur_time = tmp_time;
        cur = i;
        cur_lv = a[i];
      }
    }
    cout << ((multi) ? n : cur+1) << endl;
  }
  return 0;
}

Measured memory_bytes: 0
fun main() = Thread(null, ::aising2020c, "(^o^)", 128 * 1024 * 1024).apply { start() }.join()

@OptIn(ExperimentalStdlibApi::class)
fun aising2020c() {
    val n = readLine()!!.toInt()

    val count = LongArray(n + 1)

    for (x in 1..n) {
        for (y in 1..n) {
            for (z in 1..n) {
                val value = x * x + y * y + z * z + x * y + y * z + z * x
                if (value <= n) count[value]++ else break
            }
        }
    }

    val answer = count.drop(1).joinToString(System.lineSeparator())

    println(answer)
}


Measured memory_bytes: 41216
#include<bits/stdc++.h>
#define chal ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;
string rotation(string s,int k)
{
    string x;
    for(int i=k-1;i<s.size();i++)
    {
        x+=s[i];
    }
    if(k%2==0 || s.size()%2==1){
    for(int i=k-2;i>=0;i--)
    {
        x+=s[i];
    }
    }
    else
    {
    for(int i=0;i<k-1;i++)
    {
        x+=s[i];
    }
    }
    return x;
}
int main()
{
    int a;
    cin>>a;
    cout<<pow(a,3)+pow(a,2)+a;
    return 0;
}


Measured memory_bytes: 4260
#include <bits/stdc++.h>
#define rep(i,n) for (ll i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
const ll INF=1e18;
// Binary Indexed Tree (Fenwick Tree)
// https://youtu.be/lyHk98daDJo?t=7960
template<typename T>
struct BIT {
  int n;
  vector<T> d;
  BIT(int n=0):n(n),d(n+1) {}
    //末尾の要素(i&-i)をたす→一つ上の階層なので、要素の更新の時に使える
  void add(int i, T x=1) {
    for (i++; i <= n; i += i&-i) {
      d[i] += x;
    }
  }
     //末尾の要素(i&-i)を引く→一つ上の一つ左の階層なので、要素の総和をとる時に使える
  T sum(int i) {
    T x = 0;
    for (i++; i; i -= i&-i) {
      x += d[i];
    }
    return x;
  }
    T sum(int l, int r) {
        return sum(r-1) - sum(l-1);
    }
};




int main() {
  ll n,q;
  cin>>n>>q;
  BIT <ll> B(n);
  vector<ll> a(n);
  rep(i,n){
    cin>>a[i];
    B.add(i,a[i]);
  }
  rep(i,q){
    ll t1,t2,t3;
    cin>>t1>>t2>>t3;
    if(t1==0){
      B.add(t2,t3);
    }
    else{

      ll ans=B.sum(t2,t3);
      cout<<ans<<endl;
    }

  }

}


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

int main(void){
  int N, i, j;
  scanf("%d", &N);
  int L[N], max_num=0, sum=0;
  for (i=0; i<N; i++){
    scanf("%d", &L[i]);
  }
  for (i=0; i<N; i++){
    if (L[i] > max_num){
      max_num = L[i];
      j = i;
    }
  }
  for (i=0; i<N; i++){
    if (i == j){
      continue;
    }
    sum += L[i];
  }
  printf("%s\n", sum > max_num ? "Yes":"No");
}

Measured memory_bytes: 128
use std::io::stdin;
use std::vec::Vec;

mod utils {
    use std::io::BufRead;
    use std::str::{self, FromStr};

    pub struct StdinReader<R: BufRead> {
        reader: R,
        buf: Vec<u8>,
    }

    impl<R: BufRead> StdinReader<R> {
        pub fn new(reader: R) -> StdinReader<R> {
            StdinReader {
                reader: reader,
                buf: Vec::new(),
            }
        }

        #[allow(unused)]
        #[inline]
        pub fn reads<T: FromStr>(&mut self) -> T {
            self.read_until(b' ')
        }

        #[allow(unused)]
        #[inline]
        pub fn readl<T: FromStr>(&mut self) -> T {
            self.read_until(b'\n')
        }

        #[allow(unused)]
        #[inline]
        pub fn read_vec<T: FromStr>(&mut self) -> Vec<T> {
            return self.read_until::<String>(b'\n').trim().split_whitespace().map(|c| c.parse().ok().unwrap()).collect();
        }

        #[inline]
        pub fn read_until<T: FromStr>(&mut self, delim: u8) -> T {
            loop {
                self.buf.clear();
                let len = self.reader
                    .read_until(delim, &mut self.buf)
                    .expect("failed reading bytes");
                match len {
                    0 => panic!("early eof"),
                    1 if self.buf[0] == delim => (),
                    _ => {
                        if self.buf[len - 1] == delim {
                            self.buf.truncate(len - 1);
                        }
                        break;
                    }
                }
            }

            let elem = unsafe { str::from_utf8_unchecked(&self.buf) };
            elem.parse().unwrap_or_else(|_| panic!(format!("failed parsing: {}", elem)))
         }
    }
}


fn main(){
    let stdin = stdin();
    let mut r = utils::StdinReader::new(stdin.lock());
    let n:i32 = r.reads();
    let m:i32 = r.readl();
    if(n == m){
        println!("Yes");
    }else{
        println!("No")
    }
}


Measured memory_bytes: 4352
N,K = map(int,input().split())
if K == 0:
    print(N*N)
    exit()

ans = 0
for b in range(1,N+1):
    cycle,rem = divmod(N,b)
    ans += cycle * max(0, b-K)
    ans += max(0, rem+1 - K)
print(ans)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#include <math.h>
#define _GLIBCXX_DEBUG
#define _LIBCPP_DEBUG 0

using namespace std;
#define ll long long
#define rep(i,n) for (int i = 0; i < n; i++)
#define rrep(i,n) for (int i = n-1; i >= 0; i--)
#define MOD (1000000007)
#define vi vector<int>
#define vl vector<ll>
#define vvi vector<vi>
#define vvl vector<vl>
#define pii pair<int, int>
#define pb push_back

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

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

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

const ll INF = 1LL << 60;

const int dh[4] = {1,0,-1,0};
const int dw[4] = {0,1,0,-1};

int k;
vvi G;
vi color;
map<pii, int> edge;

void dfs(int v, int p = -1, int col = 0){
  if(p != -1){
    int e = edge[mp(v,p)];
    color[e] = col + 1;
  }

  for(auto nv : G[v]) {
    if(nv == p) continue;
    col = (col + 1)%k;
    dfs(nv, v, col);
  }
}


int main(){
  int n; cin >> n;
  G.resize(n);
  vi deg(n);
  rep(i,n-1) {
    int a,b; cin >> a >> b;
    a--; b--;
    G[a].pb(b); G[b].pb(a);
    deg[a]++; deg[b]++;
    edge[mp(a,b)] = edge[mp(b,a)] = i;
  }

  k = 0;
  rep(v,n) chmax(k,deg[v]);

  color.resize(n-1);
  dfs(0);

  cout << k << endl;
  rep(i,n-1) cout << color[i] << endl;;
}


Measured memory_bytes: 19328
fun main() {
    val n = readInt()
    val bosses = readInts()
    val counts = mutableMapOf<Int, Int>()
    bosses.forEach { boss -> counts[boss] = counts[boss]?.plus(1) ?: 1 }

    for (i in 1..n) { println(counts[i] ?: 0) }
}

// Input Reader
private fun readLn() = readLine()!!

private fun readStrings() = readLn().trim().split(" ")
private fun readInt() = readLn().toInt()
private fun readInts() = readStrings().map { it.toInt() }


Measured memory_bytes: 85076
#include<bits/stdc++.h>
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<stack>
#include<algorithm>
#include<iostream>
#include<set>
#pragma comment(linker, "/STACK:102400000,102400000")
#define IOS ios::sync_with_stdio(false);cin.tie(0)
//#define ll long long
#define ll unsigned long long
#define inf 0x3f3f3f3f
#define mod 1000000007
#define eps 1e-6
#define pi acos(-1)
#define mea (memset(a,0,sizeof(a)))
#define myit set<ll>::iterator
#define mysets multiset<ll>
#define myits multiset<ll>::iterator
#define v30 (1<<30)-1
#define all(x) (x).begin(),(x).end()
#define maxs *s.rbegin()
#define fi first
#define se second
#define lowbit(x) (x&(-x))
#define mp make_pair
#define pb push_back
#define ins insert
#define ee exp(1.0)
#define fixed cout.setf(ios::fixed)
#define fixeds(x) setprecision(x)
using namespace std;
inline ll read(){
   ll s=0,w=1;
   char ch=getchar();
   while(ch<'0'||ch>'9'){if(ch=='-')w=-1;ch=getchar();}
   while(ch>='0'&&ch<='9') s=s*10+ch-'0',ch=getchar();
   return s*w;
}
void put1(){ puts("YES") ;}
void put2(){ puts("NO") ;}
void put3(){ puts("-1"); }
ll gcd(ll a,ll b){ return b==0?a:gcd(b,a%b);}
using namespace std;

const int manx=3e5+5;

int main()
{
    ll n=read(),x=read();
    ll ans=0;
    while(n){
        n/=x;
        ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<stdio.h>
void maxHeapfy(int *,int);
void buildMaxHeap(int*);
int parent(int);
int left(int);
int right(int);
int H;

int main(){
  int  i,j,A[500000];
  scanf("%d",&H);
  for(i=1;i<H+1;i++){
    scanf("%d",&A[i]);
  }

  buildMaxHeap(A);

  for(j=1;j<H+1;j++){
    printf(" %d",A[j]);
  }
  printf("\n");
  return 0;
}




int parent(int i){
  return i/2;
}


int left(int i){
  return 2*i;
}


int right(int i){
  return 2*i+1;
}


void maxHeapify(int *A,int i){
  int l,r,largest,a;
  l=left(i);
  r=right(i);
  
  if(l<=H&&A[l]>A[i]){
    largest=l;
  }else{
    largest=i;
  }

  if(r<=H&&A[r]>A[largest]){
    largest=r;
  }

  if(largest!=i){
    a=A[i];
    A[i]=A[largest];
    A[largest]=a;
    maxHeapify(A,largest);
  }
}

void buildMaxHeap(int *A){
  int i;
  for(i=H/2;i>=1;i--){
    maxHeapify(A,i);
  }
}



Measured memory_bytes: 3636
#include<iostream>
#include<vector>
#include<algorithm>
#include<climits>
using namespace std;
int c;
void marge(vector<int>& A, int l, int m, int r)
{
  int i,j,k,n1=m-l,n2=r-m;
  vector<int> L(n1+1),R(n2+1);
  
  for(i=0; i<n1; i++) L[i]=A[l+i];
  for(i=0; i<n2; i++) R[i]=A[m+i];
  L[n1]=INT_MAX; R[n2]=INT_MAX;
  i=0; j=0;
  for(k=l; k<r; k++){
    c++;
    if(L[i]<=R[j]){ A[k]=L[i]; i++; }
    else{ A[k]=R[j]; j++; }
  }
}
void margeSort(vector<int>& A, int l, int r)
{
  if(l+1<r){
    int m=(l+r)/2;
    margeSort(A, l, m);
    margeSort(A, m, r);
    marge(A, l, m, r);
  }
}
int main()
{
  c=0;
  int i,j,n;
  vector<int> S;
  cin>>n; S.resize(n);
  for(i=0; i<n; i++) cin>>S[i];
  margeSort(S,0,n);
  for(i=0; i<n-1; i++) cout<<S[i]<<' '; cout<<S[n-1]<<endl;
  cout<<c<<endl;
  return 0;
}


Measured memory_bytes: 6836
#include<iostream>
#include<cmath>
#define int long long
using namespace std;
signed main() {
	int n, m; cin >> n >> m;
	int p = 1;
	for (int i = 1; i <= sqrt(m); i++) {
		if (m%i == 0) {
			if (n*(m / i) <= m) {
				cout << m / i << endl;
				return 0;
			}
			else if (n*i <= m)p = i;
		}
	}
	cout << p << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
using namespace std;
using ll = long long;
int main(){
  ll n;
  cin>>n;
  string ans;
  while(n){
    n--;
    ans+='a'+n%26;
    n/=26;
  }
  reverse(ans.begin(),ans.end());
  cout<<ans<<endl;
}

Measured memory_bytes: 3576
n,k=map(int,input().split())
p=list(map(int,input().split()))
c=list(map(int,input().split()))
for i in range(n):
    p[i]-=1
ans=max(c)
for i in range(n):
    f=i
    r=0
    l=[]
    while True:
        f=p[f]
        l.append(c[f])
        r+=c[f]
        if f==i:
            break
    t=0
    for j in range(len(l)):
        t+=l[j]
        if j+1>k:
            break
        ret=t
        if r>0:
            e=(k-j-1)//len(l)
            ret+=r*e
        ans=max(ans,ret)
print(ans)


Measured memory_bytes: 81128
#include <stdio.h>
#include <math.h>

int main(){
	double n, d, x, y;
	int cont = 0;
	scanf("%lf %lf", &n, &d);

    double dist;

	int xq, yq, soma;

	for(int i = 0; i < n; i++){
		scanf("%lf %lf", &x, &y);
		dist = sqrt(pow(x,2)+pow(y,2));

		if(dist <= d)
			cont += 1;
	}

	printf("%d\n", cont);

	return 0;


}


Measured memory_bytes: 2124
#include <stdio.h>
int main(void)
{
  int A, B, K;
  scanf("%d %d", &A, &B);
  if(A >= B)
    K = B + (A - B) / 2;
  else
    K = A + (B - A) / 2;
  
  if(A % 2 == B % 2)
    printf("%d", K);
  else
    printf("IMPOSSIBLE");

  return 0;
}


Measured memory_bytes: 128
#include<iostream>
#include<stdio.h>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include <queue>
#include <utility>
#include <map>
#include <set>
using namespace std;

int main() {
    int N, K, X, Y;
    cin >> N >> K >> X >> Y;

    int ans;
    if (N <= K)ans = N*X;
    else ans = K*X + (N - K)*Y;
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 256
n=int(input())
a=list(map(int,input().split()))
col=[False]*8
ans=0
for i in a:
    if 1<=i<=399:
        col[0]=True
    elif i<=799:
        col[1]=True
    elif i<=1199:
        col[2]=True
    elif i<=1599:
        col[3]=True
    elif i<=1999:
        col[4]=True
    elif i<=2399:
        col[5]=True
    elif i<=2799:
        col[6]=True
    elif i<=3199:
        col[7]=True
    else:
        ans+=1
ans1=0
for i in col:
    if i:
        ans1+=1
print(max(ans1,1),ans1+ans)

Measured memory_bytes: 3064
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")

// Use g++ compiler for this include to work.
#include <bits/stdc++.h>

using namespace std;

// Constants 
#define INF 1e18
#define EPsecond 1e-9
#define MOD 1000000007
 
// // for using in pairs
#define f first
#define S second
 
// Macros
#define all(x) begin(x), end(x)
 
// aliases
using ll = long long;
using ull = unsigned long long;
using ui = unsigned int;
using ld = long double;

// Temporary macro.
#define int long long

// Operator overloads.
/**
 * The type of element in the vector should have overload for << operator with ostream. 
 */
template<typename T>
ostream& operator<<(ostream &stream, vector<T> v)
{
	for (const auto &it : v)
		stream << it << " ";
	return stream;
}

/**
 * Both types in the pair should have overload for << operator with ostream. 
 */
template<typename T1, typename T2>
ostream& operator<<(ostream &ostream, pair<T1, T2> p)
{
	ostream << p.first << " " << p.second;
	return ostream;
}

// Utility functions.
void swap(int a, int b)
{
	int t = a;
	a = b;
	b = t;
}

///////////////////////////////////////////////////////////////////////

void dfs(set<int> adj[], int x, int CC[], int count)
{
	CC[x] = count;
	for (auto &it : adj[x])
	{
		if (!CC[it])
			dfs(adj, it, CC, count);
	}
}

void solve(int tc)
{
	int n, m;
	cin >> n >> m;

	set<int> adj[n + 1];
	for (int i = 0; i < m; i++)
	{
		int u, v;
		cin >> u >> v;
		adj[u].insert(v);
		adj[v].insert(u);
	}

	int CC[n + 1] = {0};
	int count = 1;

	for (int i = 1; i <= n; i++)
	{
		if (!CC[i])
		{
			dfs(adj, i, CC, count);
			count++;
		}
	}

	map<int, int> f;
	for (int i = 1; i <= n; i++)
		f[CC[i]]++;

	int ans = 0;
	for (auto &it : f)
		ans = max(ans, it.S);

	cout << ans;
}	

int32_t main()
{	
	#ifndef ONLINE_JUDGE
		freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif

	ios_base::sync_with_stdio(false);
	cin.tie(0);

	int t = 1;
	// cin >> t;		
	for (int i = 1; i <= t; i++)
	{
		solve(i);
	}

	return 0;
}


Measured memory_bytes: 42680
#include <cstdio>
#include <utility>
#include <cctype>
#include <vector>
#include <climits>
#include <algorithm>
using namespace std;

#ifdef __linux
#define _U(s) s##_unlocked
#else
#define _U(s) _##s##_nolock
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
#define gcu _U(getchar)
#define pcu _U(putchar)
#define _DEF(r, n, ...) inline r n(__VA_ARGS__) noexcept
#define _T template <typename T>
#define _HT template <typename H,typename... T>
#define _OP(t) inline operator t()
struct _in {
#ifdef _GLIBCXX_STRING
	_OP(string){string s;char c;while(isspace(c = gcu()));do{s+=c;}while(c=gcu(),c!=' '&&c!='\n'&&c!=EOF);return s;}
#define _S
#endif
	_OP(char){char c=gcu();gcu();return c;}
	_OP(double){double d; scanf("%lf",&d); gcu();return d;}
	_T _OP(T){T n{},m{1},c;while(isspace(c = gcu()));if(c=='-')m=-1,c=gcu();do{n=10*n+(c-'0'),c=gcu();}while(c>='0'&&c<='9');return m*n;}
} in;
#define _SCAN(...) _DEF(bool,scan,__VA_ARGS__)
#ifdef _S
_SCAN(string &o) {int c{gcu()};if(c==EOF)return false;else{ungetc(c,stdin);string t=move(in);o=t;return true;}}
#endif
_T _SCAN(T &o) {int c{gcu()};return c==EOF?false:(ungetc(c,stdin),o=in,true);}
_HT _SCAN(H &h,T&&... t){return scan(h)&&scan(t...);}
#define _OUT(...) _DEF(void,out,__VA_ARGS__)
#define _OUTL(...) _DEF(void,outl,__VA_ARGS__)
_OUT(bool b){pcu('0'+b);}
_OUT(const char *s){while(*s)pcu(*s++);}
_OUT(char c){pcu(c);}
#ifdef _S
_OUT(string &s){for(char c:s)pcu(c);}
#endif
_T _OUT(T n){static char b[20];char *p=b;T m=n<0?pcu('-'),-1:1;
	if(!n)*p++='0';else while(n)*p++=(char)(n%10*m+'0'),n/=10;while(p!=b)pcu(*--p);}
_OUTL(){out('\n');}
#ifdef _GLIBCXX_VECTOR
	_T _OUT(vector<T> &v){for(T &x:v)out(&x == &v[0]?"":" "),out(x);}
#endif
_HT _OUT(H &&h, T... t){out(h);out(t...);}
template <typename... T> _OUTL(T... t){out(t...);outl();}
struct range{
	int e,b=0,s=1;range(int _b,int _e,int _s):e(_e),b(_b),s(_s){} range(int _b,int _e): e(_e), b(_b){} range(int _e):e(_e){}
	struct it{int v,s; it(int _v,int _s):v(_v),s(_s){} operator int()const{return v;} operator int&(){return v;}int operator*()const{return v;}
		it& operator++(){v+=s;return *this;} }; it begin(){return {b,s};} it end(){return {e,s};}};
#define times(i,n) for(int i=n;i;i--)

template <typename T>
using V = vector<T>;

int main() {
	for (int N, M; N = in, M = in;) {
		V<int> C(M);
		for (int &i: C)
			i = in;
		V<V<int>> D(N + 1, V<int>(256, INT_MAX)), T (M, V<int>(256));
		for (int i: range(M))
			for (int j: range(256))
				T[i][j] = min(max(C[i] + j, 0), 255);
		D[0][128] = 0;
		for(int i: range(N)) {
			int x {in};
			for (int j : range(256))
				if (D[i][j] != INT_MAX)
					for (int k: range(M)) {
						int n = T[k][j];
						D[i + 1][n] = min(D[i + 1][n], D[i][j] + (x - n) * (x - n));
					}
		}
		outl(*min_element(begin(D[N]), end(D[N])));
	}
}


Measured memory_bytes: 23196
a = ['a', 'b', 'c', 'd', 'e', 'f', 'g', 'h', 'i', 'j', 'k', 'l', 'm', 'n', 'o', 'p', 'q', 'r', 's', 't', 'u', 'v', 'w', 'x', 'y', 'z']
C = input()
if (C != 'z') and (C in a):
	i = a.index(C)
	print (a[i+1])

Measured memory_bytes: 3064
#include <iostream>
#include <string>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>
#include<math.h>
#include<stack>
#include<set>
#include<map>
#define INF 1000000007
#define rep(i,n,m) for(int i=n;i<m;i++)

using namespace std;


int main()
{
	int a, b, c;
	cin >> a >> b >> c;
	bool ans = 0;
	if (a == b || b == c || c == a)ans = true;
	if (a == b && b == c && c == a)ans = false;
	if (ans)cout << "Yes" << endl;
	else cout << "No" << endl;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(i, n) for (int i = (int)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (int i = (int)(a); i <= (int)(b); ++i)
#define deb(x) cout<<#x<<" "<<endl;
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long ll;
typedef vector<ll> vll;
typedef vector<vll> vvll;
typedef pair<ll, ll> pll;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }
//-------------------------------------------------------------------------------





int main(){
	ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
	
	int n;
	cin>>n;
	vi dp(3); //the total cost such that we did ith activity on last considered day
	for(int d=0;d<n;++d){
		vi new_dp(3,0);
		vi c(3);
		for(int i=0;i<3;++i){
			cin>>c[i];
		}
		for(int i=0;i<3;++i){//iterate on previous
			for(int j=0;j<3;++j){ // iterate on current
				if(i!=j){
					new_dp[j]=max(new_dp[j],dp[i]+c[j]);
				}

			}
		}
		dp	=new_dp;

	}
	cout<<max(dp[0],max(dp[1],dp[2]));
		

}
 


Measured memory_bytes: 256
// g++ -std=c++11 a.cpp
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<map>
#include<set>
#include<unordered_map>
#include<utility>
#include<cmath>
#include<random>
#include<cstring>
#include<queue>
#include<stack>
#include<bitset>
#include<cstdio>
#include<sstream>
#include<iomanip>
#include<assert.h>
#include<typeinfo>
#define loop(i,a,b) for(long long i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define FOR(i,a) for(auto i:a)
#define pb push_back
#define all(in) in.begin(),in.end()
#define shosu(x) fixed<<setprecision(x)
#define show1d(v) {rep(_,v.size())cout<<" "<<v[_];cout<<endl;}
#define show2d(v) {rep(__,v.size())show1d(v[__]);}
using namespace std;
//kaewasuretyuui
typedef long long ll;
#define int ll
typedef int Def;
typedef pair<Def,Def> pii;
typedef vector<Def> vi;
typedef vector<vi> vvi;
typedef vector<pii> vp;
typedef vector<vp> vvp;
typedef vector<string> vs;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef pair<Def,pii> pip;
typedef vector<pip>vip;
#define mt make_tuple
typedef tuple<int,int,int,int> tp;
typedef vector<tp> vt;
template<typename A,typename B>bool cmin(A &a,const B &b){return a>b?(a=b,true):false;}
template<typename A,typename B>bool cmax(A &a,const B &b){return a<b?(a=b,true):false;}
const double PI=acos(-1);
const double EPS=1e-9;
Def inf = sizeof(Def) == sizeof(long long) ? 2e18 : 1e9+10;
#define yes cout<<"Yes\n"
#define no cout<<"No\n"
 
signed main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	int n,m,k;
	cin>>n>>m>>k;
	vvi out(n,vi(m));
	vs in(n);
	rep(i,n)cin>>in[i];
	
	vi h(n,1);
	int t=1,w;
	rep(i,n){
		w=1;
		rep(j,m){
			if(in[i][j]=='#'){
				h[i]=0;
				if(!w)t++;
				w=0;
				if(t>k)t=k;
			}
			out[i][j]=t;
		}
		if(!h[i])t++;
	}
	w=1;
	rep(i,n){
		if(h[i]&&!w)out[i]=out[i-1],h[i]=0;
		if(!h[i])w=0;
	}
	w=1;
	for(int i=n-1;i>=0;i--){
		if(h[i]&&!w)out[i]=out[i+1];
		if(!h[i])w=0;
	}
	
	
	show2d(out);
	
}












Measured memory_bytes: 1664
import java.util.*;
public class Main {
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int k = sc.nextInt();
  
		int a = sc.nextInt();
		int b = sc.nextInt();
      int c = 0;
      boolean hit = false;
      for(int i = a;i<=b;i++){
         if(i%k==0){
            hit = true;
         }
      }
      if(hit){
         System.out.println("OK");
      }else{
         System.out.println("NG");
      }
   }
}

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

int main() {
  int A, B;
  cin >> A >> B ;
  
  int sum = 0;
  
  for (int i = A; i <= B; i++) {
    int a, b, c, d, e;
    a = i / 10000;
    b = i / 1000 - a * 10;
    c = i / 100 - a * 100 - b * 10;
    d = i / 10 - a * 1000 - b * 100 - c * 10;
    e = i - a * 10000 - b * 1000 - c * 100 - d * 10;
    if (a == e && b == d) sum++;
  }
  cout << sum << endl;
}


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

using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,int> pli;
typedef pair<ll,ll> pll;
const ll INF = 2e18;
const int inf = 1e9+10;
const int maxN = 5e5 + 10;
const int maxD = 15;
const int maxH = 100; 
const int MOD = 1e9+7;



int main()
{
	int n;
	cin>>n;
	unordered_map<string,int> mp;
	while(n--)
	{
		string s;
		cin>>s;
		mp[s]++;
	}
	vector<string> v = {"AC","WA","TLE","RE"};
	for(int i=0;i<4;i++)
	{
		cout<<v[i];
		printf(" x %d\n",(int)mp[v[i]]);
	}
	return 0;
}

Measured memory_bytes: 3736
#include<iostream>
#include<queue>
#include<string>
#define rep(i,n) for(int i=0;i<n;i++)
#define ck(a,b) (0<=(a)&&(a)<b)
using namespace std;
int dx[]={-1,1,0,0},dy[]={0,0,-1,1};
struct S{
	int lx,ly,rx,ry;
	S(int a,int b,int c,int d):lx(a),ly(b),rx(c),ry(d){}
};
bool V[50][50][50][50];
int main(){
	int w,h;
	while(cin>>w>>h,w){
		int lx,ly,rx,ry;
		string cavel[h],caver[h];
		rep(i,h)cin>>cavel[i]>>caver[i];
		rep(i,h)rep(j,w){
			if(cavel[i][j]=='L')ly=i,lx=j,cavel[i][j]='.';
			if(caver[i][j]=='R')ry=i,rx=j,caver[i][j]='.';
		}
		queue<S> F; rep(i,h)rep(j,w)rep(k,h)rep(l,w)V[i][j][k][l]=0;
		F.push(S(lx,ly,rx,ry)); V[ly][lx][ry][rx]=1;
		int goal=0;
		while(!F.empty()&&!goal){
			S s=F.front(); F.pop();
			rep(d,4){
				int clx=s.lx,cly=s.ly,crx=s.rx,cry=s.ry,nlx=clx+dx[d],nly=cly+dy[d],nrx=crx-dx[d],nry=cry+dy[d];
				if(!ck(nlx,w)||!ck(nly,h)||cavel[nly][nlx]=='#')nlx=clx,nly=cly;
				if(!ck(nrx,w)||!ck(nry,h)||caver[nry][nrx]=='#')nrx=crx,nry=cry;
				if(nlx==clx&&nly==cly&&nrx==crx&&nry==cry||(cavel[nly][nlx]=='%'^caver[nry][nrx]=='%'))continue;
				if(cavel[nly][nlx]=='%'&&caver[nry][nrx]=='%'){
					goal=1; goto END;
				}
				if(!V[nly][nlx][nry][nrx]){
					F.push(S(nlx,nly,nrx,nry));
					V[nly][nlx][nry][nrx]=1;
				}
			}
		}
		END:cout<<(goal?"Yes":"No")<<endl;
	}
	return 0;
}

Measured memory_bytes: 7920