akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

struct Node{
  int p, l, r;
};

Node t[100005];
int D[100005];//node depth

int rec(int u, int p){
  //write depth
  D[u] = p;

  if(t[u].r != -1){
    rec(t[u].r, p);
  }
  if(t[u].l != -1){
    rec(t[u].l, p + 1);
  }
}

void print(int a){
  //node, parent, depth
  cout << "node " << a << ": ";
  cout << "parent = " << t[a].p << ", ";
  cout << "depth = " << D[a] << ", ";
  
  //root or leaf or internal node
  if(t[a].p == -1){
    cout << "root, ";
  }else if(t[a].l == -1){
    cout << "leaf, ";
  }else{
    cout << "internal node, ";
  }

  //children list
  cout << "[";
  int c;
  for(int i = 0, c = t[a].l; c != -1; i++, c = t[c].r){
    if(i){
      cout << ", ";
    }
    cout << c;
  }
  cout << "]" << endl;
}

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

  //init
  for(int i = 0; i < n; i++){
    t[i].p = -1;
    t[i].l = -1;
    t[i].r = -1;
  }

  //path
  int id, k, c, l, r;
  for(int i = 0; i < n; i++){
    cin >> id >> k;
    for(int j = 0; j < k; j++){
      cin >> c;
      if(j == 0)t[id].l = c;//leftest children
      else t[l].r = c;//right node
      l = c;
      t[c].p = id;//parent
    }
  }

  //search root
  for(int i = 0; i < n; i++){
    if(t[i].p == -1)r = i;
  }

  rec(r, 0);

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

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

int lenght(char* str){
  int i=0;
 while(str[i]){
     i++;
 }
 return i;
}

int main(){
 char str[100];
  cin>>str;
 int N =lenght(str);
 for (int i = 0; i < N; i++)
 {
   cout << "x";
 }
 cout << endl;
 
}

Measured memory_bytes: 256
#include<stdio.h>
#include<string.h>
int main(void){
	char str[4];
	int ans=0;
	
	scanf("%s",str);
    
    if(strstr(str,"RRR")!=NULL) printf("3");
	else if(strstr(str,"RR")!=NULL)  printf("2");
	else if(strstr(str,"R")!=NULL)   printf("1");
	else printf("0");

	return 0;
}

Measured memory_bytes: 1664
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N; 
int ans = 0;

int dfs(int n, bool is3, bool is5, bool is7){
  if(n > N) return 0;

  int ret = 0;
  if(is3 && is5 && is7) ret++;

  ret += dfs(n*10+3, true, is5, is7);
  ret += dfs(n*10+5, is3, true, is7);
  ret += dfs(n*10+7, is3, is5, true);

  return ret;
}

signed main() {
  cin >> N;

  cout << dfs(0, false, false, false) << "\n";

  return 0;
}

Measured memory_bytes: 256
N = int(input())
s = list(map(int,input().split()))
a = s[0]

if not 0 in s:
    if len(s) > 1:
        for i in range(1,N):
            a = a * s[i]
            
            if a > 10**18:
                a = -1
                break
else:
    a=0
print(a)


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

char getGrade(int m, int f, int r){
int sum=m+f;
char grade;
if(m==-1||f==-1) grade='F';
else if(80<=sum) grade='A';
else if(65<=sum && sum<80) grade='B';
else if(50<=sum && sum<65) grade='C';
else if(30<=sum && sum<50){
if(50<=r) grade='C';
else grade='D';
}
else if(sum<30) grade='F';
return grade;
}

int main(){
int m,f,r;
while(1){
cin >>m >>f >>r;
if(m==-1 && f==-1 && r==-1) break;
cout <<getGrade(m,f,r) <<endl;
}

return 0;
}

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

int main(){
  int n;
  cin >> n;
  int a[n];
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  int ans=0;
  for(int i=0;i<n;i++){
    ans+=a[i];
  }
  ans-=n;
  cout << ans << endl;
}

Measured memory_bytes: 256
S = input()
S = S + 'R'
Lflag = 0
Rcount = 0
Lcount = 0
ans = ""
for letter in S:
    if Lflag == 1 and letter == 'R':
        a = (Rcount + 1) // 2 + Lcount // 2
        b = (Lcount + 1) // 2 + Rcount // 2
        ans += "0 " * (Rcount-1) + str(a) + " " + str(b) + " " + "0 " * (Lcount-1)
        Lflag = 0
        Rcount = 1
        Lcount = 0

    elif letter == 'R':
        Rcount += 1
    else:
        Lflag = 1
        Lcount += 1
print(ans)

Measured memory_bytes: 3828
#include <bits/stdc++.h>
using namespace std;
typedef vector<long long> vi;
typedef vector<vi> vvi;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;
typedef long long int ll;
typedef unsigned long long int ull;
typedef pair<int, int> pii;

inline bool valid(int x, int n) {
    return 0 <= x && x < n;
}

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

template <typename T>
inline T pop(queue<T>& q) {
    T front = q.front();
    q.pop();
    return front;
}

template <typename T>
inline T gcd(T a, T b) {
    for (; b; a %= b, swap(a, b));
    return a; 
}

template <typename T>
tuple<T, T, T> xgcd(T a, T b) {
    if (b == 0) return {1, 0, a};
    T x, y, g;
    tie(x, y, g) = xgcd(b, a%b);
    return {y, x-(a/b)*y, g};
}

const int M = 500005;
int arr[M] = {};
int tree[M*4] = {};

void update(int tgt, int idx, int left, int right) {
    if (left == right) {
        tree[idx] = (1 << arr[tgt]);
        return;
    }
    int mid = (left + right) / 2;
    if (tgt <= mid) update(tgt, idx*2, left, mid);
    else update(tgt, idx*2+1, mid+1, right);
    tree[idx] = (tree[idx*2] | tree[idx*2+1]);
}

int getX(int beg, int end, int idx, int left, int right) {
    if (beg > right || end < left) return 0;
    if (beg <= left && right <= end) return tree[idx];
    int mid = (left + right) / 2;
    return (getX(beg, end, idx*2, left, mid) | getX(beg, end, idx*2+1, mid+1, right));
}

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

    int N; cin >> N;
    string S; cin >> S;
    int Q; cin >> Q;

    for (int i = 0; i < N; i++) {
        arr[i+1] = S[i] - 'a';
        update(i+1, 1, 1, N);
    }

    while (Q--) {
        int q; cin >> q;
        if (q == 1) {
            int i;
            char c;
            cin >> i >> c;
            arr[i] = c - 'a';
            update(i, 1, 1, N);
        }
        else {
            int i, j; cin >> i >> j;
            int X = getX(i, j, 1, 1, N);
            int rst = 0;
            for (int k = 0; k < 26; k++) {
                if (X & (1 << k)) rst++;
            }

            cout << rst << "\n";
        }
    }
}

Measured memory_bytes: 10652
#include <iostream>
#include <fstream>
#include <string>
#include <algorithm>
#include <cstdlib>
#include <vector>
#include <stack>
#include <queue>
#include <complex>
#include <set>
#include <list>
#include <iomanip>
#include <map>
#include <limits.h>
#include <memory.h>


using namespace std;
static const double EPS = 1e-10;
typedef long long ll;
typedef unsigned long long ull;
#define FOR(i,n) for(int i=0;i<(int)n;++i)
#define FORNUM(p, x) for (int num = p; num < (int)(x); ++num)
#define FORI(p, x) for (int i = p; i < (int)(x); ++i)
#define FORJ(p, x) for (int j = p; j < (int)(x); ++j)
#define FORK(p, x) for (int k = p; k < (int)(x); ++k)
#define FORL(p, x) for (int l = p; l < (int)(x); ++l)

typedef vector<double> vec;
typedef vector<vec> mat;

int cnt[30];


int main() {
	string s;
	cin>>s;
	FORI(0,s.length()){

		cnt[s[i]-'a']++;
	}
	FORI(0,s.length()){

		cnt[i] %=2;
	}
	int ans=0;
	FORI(0,26){

		ans+=cnt[i];
	}	

	cout<< (ans==0?"Yes":"No")<<endl;
	return 0;
}




Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
#define FOR(i,x,n) for(int i=x; i<(n); i++)
#define ALL(n) begin(n),end(n)
#define MOD (1000000007)
#define INF (1e9)
#define INFL (1e18)

typedef long long ll;
typedef unsigned int ui;
typedef unsigned long long ull;
template<class T>using arr=vector<vector<T>>;
template<class T>int popcount(T &a){int c=0; rep(i, 8*(int)sizeof(a)){if((a>>i)&1) c++;} return c;}
template<class T>void pr(T x){cout << x << endl;}
template<class T>void prvec(vector<T>& a){rep(i, a.size()-1){cout << a[i] << " ";} pr(a[a.size()-1]);}
template<class T>void prarr(arr<T>& a){rep(i, a.size()) if(a[i].empty()) pr(""); else prvec(a[i]);}
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 (b<a) { a=b; return 1; } return 0; }

int f(int n){
    int rec = 0;
    while(n!=0){
        // pr(n);
        rec++;
        int k = popcount(n);
        n = n%k;
    }
    return rec;
}

int main()
{
    int n; string x;
    cin >> n >> x;

    int one=0;
    rep(i, n) if(x[i]=='1') one++;

    // if(one==0) {pr(0); return 0;}

    vector<int> add(n), sub(n);
    add[n-1] = 1;
    sub[n-1] = 1;
    for(int i=n-2; i>=0; i--){
        add[i] = (add[i+1]*2)%(one+1);
        if(one!=1) sub[i] = (sub[i+1]*2)%(one-1);
    }

    int a=0, b=0;
    rep(i, n){
        if(x[i]=='1'){
            a += add[i];
            a %= (one+1);
            if(one!=1){
                b += sub[i];
                b %= (one-1);
            }
        }
    }

    rep(i, n){
        int c;
        if(x[i]=='1'){
            if(one==1){
                pr(0);
                continue;
            }
            c = (b - sub[i] + one - 1)%(one-1);
            pr(f(c)+1);
        }else{
            if(one==0){
                pr(1);
                continue;
            }
            c = (a + add[i])%(one+1);
            pr(f(c)+1);
        }
    }
    return 0;}

Measured memory_bytes: 5240
from collections import Counter

def prime_decomposition(n: int) -> list:
    """素因数分解"""
    i = 2
    table = []
    while i * i <= n:
        while n % i == 0:
            n //= i
            table.append(i)
        i += 1
    if n > 1:
        table.append(n)
    return table

MOD = 10 ** 9 + 7
N = int(input())
factors = []
for i in range(1, N+1):
    factors += prime_decomposition(i)
counter = Counter(factors)
ans = 1
for k, v in counter.items():
    if k == 1: continue
    ans *= (v+1)
    ans %= MOD
print(ans)

Measured memory_bytes: 9324
from collections import deque
N,M=map(int,input().split())
graph=[[] for i in range(N)]
for i in range(M):
    A,B=map(int,input().split())
    graph[A-1].append(B-1)
    graph[B-1].append(A-1)
queue=deque([0])
distance=[0]*N
while queue:
    value=queue.popleft()
    for i in graph[value]:
        if distance[i]<1:
            distance[i]=value+1
            queue.append(i)
if 0 in distance:
    print("No")
else:
    print("Yes")
    for i in range(1,N):
        print(distance[i])

Measured memory_bytes: 36868
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
typedef long long ll;
typedef pair<int, int> P;

int main(){
    int l, r, i, j, res = 2019*2019;
    cin >> l >> r;
    for(i=l; i<min(l+2019, r); i++){
        for(j=i+1; j<=min(l+2019, r); j++){
            res = min(res, ((i%2019) * (j%2019))%2019);
        }
    }
    cout << res << "\n";
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<stdio.h>
//#include <bits/stdc++.h>
#include<vector>
#include<float.h>
#include<iomanip>
#include<algorithm>
#include<string>
#include<cstring>
#include<math.h>
#include<cmath>
#include<sstream>
#include<set>
#include<map>
#include<queue>
#include <cassert>
#include <cmath>
#include<cstdint>

#define INF 1e9
#define rep(i,n)for(int i=0;(i)<(int)(n);i++)
#define REP(i,a,b)for(int i=(int)(a);(i)<=(int)(b);i++)
#define VEC(type, c, n) std::vector<type> c(n);for(auto& i:c)std::cin>>i;
#define vec(type,n) vector<type>(n)
#define vvec(m,n) vector<vector<int>> (int(m),vector<int>(n))
#define ALL(a)  (a).begin(),(a).end()
#define chmax(a, b) a = max(a, b)
#define chmin(a, b) a = min(a, b)


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

ll dp[200005][2];
int main(){
    string t;
    cin >> t;

    rep(i, t.size()){
        if(t[i] == '?')t[i] = 'D';
    }
    cout << t << endl;
}

Measured memory_bytes: 3488
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int n,s=0;
	ios::sync_with_stdio(false); 
	cin>>n;
	for(int i=1;i<n;i++)
	{
		for(int j=1;j*j<=n-i;j++)
		{
			if((n-i)%j==0)
			{
				s++;
				if((n-i)/j!=j)s++;
			}
		}
	}
	cout<<s;
}

Measured memory_bytes: 3652
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <queue>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>
#include <fstream>
#include <stdio.h>
#include <complex>
#include <cstdint>
#include <tuple>
#include <regex>

#define M_PI       3.14159265358979323846

using namespace std;

//conversion
//------------------------------------------
inline int toInt(string s) { int v; istringstream sin(s); sin >> v; return v; }
template<class T> inline string toString(T x) { ostringstream sout; sout << x; return sout.str(); }

//typedef
//------------------------------------------
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<int, PII> TIII;
typedef long long LL;
typedef unsigned long long ULL;
typedef vector<LL> VLL;
typedef vector<VLL> VVLL;

//container util

//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
//------------------------------------------
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define MOD 1000000007

int a[2000];
int aa[2000];
int b[2000];

int main() {
	int n, k, q, ret = 1e9 + 5;
	scanf("%d%d%d", &n, &k, &q);
	REP(i, n)scanf("%d", &a[i]);
	REP(i, n) {
		int s = 0;
		int idx = 0;
		memcpy(aa, a, sizeof(a));
		do {
			int e = n;
			FOR(j, s, n) {
				if (a[j] < a[i]) {
					e = j;
					break;
				}
			}
			if (e > s) {
				sort(&aa[s], &aa[e]);
				REP(i, e - s - k + 1) {
					b[idx++] = aa[s + i];
				}
			}
			s = e + 1;
		} while (s < n);
		if (idx < q)continue;
		sort(b, b + idx);
		ret = min(ret, b[q - 1] - b[0]);		
	}
	printf("%d\n", ret);
	return 0;
}

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

using PP = pair<long, long>;
int n;
long a[18];
int cat[19];
vector<PP> rec(int l, int r) {
  if (l + 1 == r) return { PP(0, 0) };
  if (l + 2 == r) return { PP(a[l + 1], a[l + 1]) };
  vector<PP> ret;
  ret.reserve(cat[r - l - 1]);
  for (int m = l + 1; m < r; ++m) {
    auto v = rec(l, m);
    auto w = rec(m, r);
    for (auto&& p : v) {
      for (auto&& q : w) {
        long vm = a[m] + p.second + q.first;
        ret.emplace_back(p.first + vm, q.second + vm);
      }
    }
  }
  return ret;
}

int main() {
  cin >> n;
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  
  cat[0] = 1;
  cat[1] = 1;
  for (int i = 2; i < n; ++i) {
    for (int k = 0; k < i; ++k) {
      cat[i] += cat[k] * cat[i - k - 1];
    }
  }
  
  auto res = rec(0, n - 1);
  long mn = 1e18;
  for (auto&& p : res) {
    mn = min(mn, p.first + p.second);
  }
  cout << mn + a[0] + a[n - 1] << endl;
}

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

using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int INF = INT_MAX;
const ll LINF = LLONG_MAX;
const ll MOD = 1e9+7;

template <class T>ostream &operator<<(ostream &o,const vector<T>&v)
{o<<"[";for(int i=0;i<(int)v.size();i++)o<<(i>0?", ":"")<<v[i];o<<"]";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const pair<T, U>&p)
{o<<"{"<<p.first<<", "<<p.second<<"}";return o;}
template <class T, class U>ostream &operator<<(ostream &o, const map<T, U>&obj)
{o<<"{";for(auto itr=obj.begin();itr!=obj.end();++itr)o<<(itr!=obj.begin()?", ":"")<<*itr;o<<"}";return o;}

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int n,a;
  cin >> n;
  multiset<int> ms;
  cin >> a;
  ms.insert(a);

  for(int i=1; i<n; i++){
    cin >> a;
    if ( a <= *ms.begin()){
      ms.insert(a);
    }else{
      auto it = ms.lower_bound(a);
      it--;
      int t = *it;
      ms.insert(a);
      ms.erase(ms.find(t));
    }
  }
  cout << ms.size() << endl;

  return 0;
}


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

int main(){
    char a, b;
    cin >> a >> b;

    if((a == 'H' && b == 'H') || (a == 'D' && b =='D')){
        cout << 'H' << endl;
    }
     if((a == 'D' && b == 'H') || (a == 'H' && b == 'D')){
        cout << 'D' << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
        #include <stdlib.h>

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


        void emp(int *x,int *y)
        {
            int p,q;
            for(p = 0;p < 4; p++)
              {
                for(q = 0; q < 4; q++)
              {
                    if(!pz[p][q])
                  {
                        *x = q;
                        *y = p;
                        return;
                  }
              }
            }
        }

        void SWAP(int *m,int *n)
        {

            int tmp1;
            tmp1 = *m;
            *m = *n;
            *n = tmp1;

        }


        int cal()
        {
            int i,n,sum=0;

            for(i = 0; i < 16; i++)
              {
                n = pz[i/4][i%4];
                if(n)
              {
                    n--;
                    sum += abs(i/4 - n/4) + abs(i%4 - n%4);
              }
            }

            return sum;

        }


        int dfs(int x,int y,int p,int dep,int lim)
        {
            int i,h,fx,fy,res;

            h = cal();

            if(h==0) return dep;

            if(dep+h>lim) return -1;

            for(i=0; i<4; i++)
              {
                fx = x+dx[i];
                fy = y+dy[i];

                if((~p && i == (p+2) % 4) || (!(0 <= fx && fx < 4 && 0 <= fy && fy < 4))) continue;

                SWAP(&pz[y][x],&pz[fy][fx]);

                res = dfs(fx,fy,i,dep+1,lim);

                if(~res) return res;

                SWAP(&pz[y][x],&pz[fy][fx]);

              }

            return -1;

        }


        int main() {

          int i,j,k,x,y,A;

            for(i = 0; i < 4; i++)
              {
                for(j = 0; j < 4; j++)
                scanf("%d",&pz[i][j]);
              }

            emp(&x,&y);

            for(k = 0; k < 100; k++) {

                for(i = 0; i < 4; i++) {

                    for(j = 0; j < 4; j++) tmp[i][j] = pz[i][j];

                }

                A = dfs(x,y,-1,0,k);

                if(A!=-1) {
                    printf("%d\n",A);
                    break;
                }

                for(i = 0 ; i < 4; i++) {
                    for(j = 0 ; j < 4; j++) pz[i][j] = tmp[i][j];
                }
                A = -1;
                if(k == 99) printf("%d\n",A);
            }
            return 0;
        }



Measured memory_bytes: 2096
#include<iostream>
using namespace std;
#define ll long long int
ll arr[1000001];
ll dp[1000001];

int solve(int n)
{
    dp[1]=0;
    dp[2]=abs(arr[2]-arr[1]);

    for(ll i=3;i<=n;i++)
    {
        ll opt1= dp[i-1]+abs(arr[i]-arr[i-1]);
        ll opt2= dp[i-2]+abs(arr[i]-arr[i-2]);
        dp[i]=min(opt1,opt2);
    }
    return dp[n];

}
int main()
{
    ll n;  cin>>n;
    
    for(int i=1;i<=n;i++)  cin>>arr[i];

    cout<<solve(n)<<endl;
}


Measured memory_bytes: 4720
#include <bits/stdc++.h> 
#define F(i,a,b) for(int i=a;i<=(b);++i)
#define dF(i,a,b) for(int i=a;i>=(b);--i)
#define inf 0x3f3f3f3f
#define infll 0x3f3f3f3f3f3f3f3f
#define pb push_back
#define maxnkp make_pair
#define fi first
#define se second
#define eps 1e-10
using namespace std;
typedef long long ll;
const int mods = 998244353;
const int maxn = 2e5+10;
const int N = 1e6+10;
const int E = 1e6+10;  
ll n,m,k;
string s;
string t;
int main(){
	cin>>s;
	n = s.size();
	dF(i,n-1,0){
		t+=s[i];
	}
	bool flg = 1;
	F(i,0,n-1){
		if(t[i]!=s[i]){
			flg = 0;
			break;
		}
	}
	F(i,0,(n-1)/2-1){
		if(s[i]!=s[i+(n+3)/2 -1]){
			flg = 0;
			break;
		}
	}
	if(flg){
		printf("Yes\n"); 
	}
	else printf("No\n");
}

Measured memory_bytes: 256
n, a, b = map(int, input().split())
x = 0
for i in range(n + 1):
    t = int(i / 10000) + int(i % 10000 / 1000) + int(i % 1000 / 100) + int(i % 100 / 10) + int(i % 10)
    if a <= t <= b:
        x += i

print(x)


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

using namespace std;

long long dp[51][51][2501];

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

  int n, a;
  cin >> n >> a;

  vector<int> v(n);
  for (int i = 0; i < n; ++i) cin >> v[i];

  dp[0][0][0] = 1;
  for (int i = 1; i <= n; ++i) {
    for (int j = 0; j <= i; ++j) {
      for (int k = 0; k <= 2500; ++k) {
        if (k < v[i - 1] || j == 0) {
          dp[i][j][k] = dp[i - 1][j][k];
        } else {
          dp[i][j][k] = dp[i - 1][j][k] + dp[i - 1][j - 1][k - v[i - 1]];
        }
      }
    }
  }

  long long res = 0;
  for (int i = 1; i <= n; ++i) {
    res += dp[n][i][i * a];
  }

  cout << res << "\n";
}
	



Measured memory_bytes: 29736
using System;
using System.Linq;
using System.Collections.Generic;

class P
{
    static void Main()
    {
        string s = Console.ReadLine();
        string res = "";
        for (int i = 0; i < s.Length; i++)
        {
            if (i == 4) res += " ";
            res += s[i];
        }
        Console.WriteLine(res);
    }
}

Measured memory_bytes: 11092
/**
*    author:  boutarou
*    created: 28.06.2020 20:54:48
**/

#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i = 0; i < int(n); i++)
#define fcout cout << fixed << setprecision(15)
using lint = long long;
using P = pair<int, int>;

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

const double PI = 3.1415926535897932;

int d;
int c[26];
int s[365][26];

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> d;
    /*cin >> d;
    rep(i, 26) cin >> c[i];
    rep(i, d) {
        rep(j, 26) cin >> s[i][j];
    }*/
    rep(i, d) cout << 1 << endl;
    
    return 0;
}

Measured memory_bytes: 3656
import statistics
N = int(input())
A = [0] * N
B = [0] * N
for i in range(N):
    A[i], B[i] = map(int, input().split())
A.sort()
B.sort()
if N%2==1:
  print(statistics.median(B)-statistics.median(A)+1)
else:
  print(int(statistics.median(B)*2-statistics.median(A)*2+1))

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

#define ld long double
#define ll long long
#define ALL(a)  (a).begin(),(a).end()
#define ALLR(a)  (a).rbegin(),(a).rend()
#define spa << " " <<
#define MP make_pair
ll MOD = 1e9+7;
//ll MOD = 998244353;
ll INF = 1e18;
void chmin(ll &a,ll b){if(a>b)a=b;}
void chmax(ll &a,ll b){if(a<b)a=b;}
void pmod(ll &a,ll b){a=(a+b)%MOD;};
void qmod(ll &a,ll b){a=(a*b)%MOD;};
void ans1(bool x){if(x) cout<<"Yes"<<endl;else cout<<"No"<<endl;}
void ans2(bool x){if(x) cout<<"YES"<<endl;else cout<<"NO"<<endl;}
void ans3(bool x){if(x) cout<<"Yay!"<<endl;else cout<<":("<<endl;}
void ans(bool x, ll y, ll z){if(x)cout<<y<<endl;else cout<<z<<endl;}   


int main(){
  ll i,j,o;
  ll result=0,buf=0,buf1=0,buf2=0,buf3=0,buf4=0;
  bool judge = true;
  ll n,k;cin>>n>>k;
  result=1;
  for(i=0;i<n;i++){
    if(result<k)result*=2;
    else result+=k;
  }
  cout<<result<<endl;


  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
ll ans = 0;
char a[25][25];
ll n,m;
ll dx[4][2]={{-1,0},{0,1},{1,0},{0,-1}};
void solve(ll p,ll q)
{
	queue<pair<ll,ll> > q1;
	q1.push({p,q});
	bool visited[25][25];
	memset(visited,false,sizeof(visited));
	visited[p][q]=true;
	ll Ans = 0;
	//cout<<p<<" "<<q<<"\n";
	while(!q1.empty())
	{
		ll sz = q1.size();
		while(sz--)
		{
			pair<ll,ll> t = q1.front();
			q1.pop();
			p = t.first;
			q = t.second;
			//cout<<p<<" "<<q<<"\n";
			for(ll i=0;i<4;i++)
			{
				ll newp = p+dx[i][0];
				ll newq = q+dx[i][1];
				if (newq>=0 and newq<m and newp>=0 and newp<n and visited[newp][newq]==false and a[newp][newq]=='.')
				{
					q1.push({newp,newq});
					visited[newp][newq]=true;
				}
			}
		}
		//cout<<"\n";
		Ans++;
	}
	//cout<<Ans<<"\n";
	ans = max(ans,Ans-1);
}
int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	cin>>n>>m;
	
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<m;j++)
			cin>>a[i][j];
	}
	for(ll i=0;i<n;i++)
	{
		for(ll j=0;j<m;j++)
		{
			if (a[i][j]=='.')
				solve(i,j);
		}
	}
	cout<<ans;
}

Measured memory_bytes: 256
function Main(s) {
  s = s.trim();
  var a = 0, b = 0, c = 0;
  var ans = "YES";
  for(var i = 0; i < s.length; i++){
    if(s[i] === "a")a++;
    else if(s[i] === "b")b++;
    else c++;
  }
  if(Math.max(a, b, c) - Math.min(a, b, c) > 1)ans = "NO";
  console.log(ans);
}
Main(require("fs").readFileSync("/dev/stdin","utf8"));

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

ll C[2010][2010];
ll mod = 1e9+7;
void init(){
    C[0][0] = 1;
    C[1][0] = 1;
    C[1][1] = 1;
    for(int i=2; i<2010; ++i){
        C[i][0] = 1;
        for(int j=1; j<2010; ++j){
            C[i][j] = (C[i-1][j] + C[i-1][j-1])%mod;
        }
    }
}
int main() {
    init();
    int n, k;
    cin >> n >> k;
    int b = k;
    int r = n-k;
    for(int i=1; i<=k; ++i){
        ll prob = (C[r+1][i]*C[b-1][i-1])%mod;
        cout << prob << endl;
    }
}

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

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

void solve(void)
{
    ll n, m, l;
    cin >> n >> m >> l;
    const ll INF = 1e9 + 1;
    vector<vector<ll>> g(n, vector<ll>(n, INF));
    rep(i, n) g[i][i] = 0;
    rep(i, m)
    {
        ll a, b, c;
        cin >> a >> b >> c;
        --a, --b;
        g[a][b] = c;
        g[b][a] = c;
    }

    ll q;
    cin >> q;
    vector<ll> s(q), t(q);
    rep(i, q) cin >> s[i] >> t[i], --s[i], --t[i];

    rep(k, n) rep(i, n) rep(j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);

    rep(i, n) rep(j, n)
    {
        if (i == j)
            g[i][j] = 0;
        else if (g[i][j] <= l)
            g[i][j] = 1;
        else
            g[i][j] = INF;
    }
    rep(k, n) rep(i, n) rep(j, n) g[i][j] = min(g[i][j], g[i][k] + g[k][j]);

    rep(i, q)
    {
        if (g[s[i]][t[i]] == INF)
            cout << -1 << endl;
        else
            cout << g[s[i]][t[i]] - 1 << endl;
    }
}
int main(void) { solve(); }


Measured memory_bytes: 5372
#include<iostream>
#include<vector>
#include<map>
#include<algorithm>
#include<math.h>
#include<string>
#include <iomanip>
#include<deque>

typedef long long ll;
typedef unsigned long long ull;
typedef int itn;
const ll LINF = 1e18;
const int INF = 1e8;

using namespace std;


//マクロ定義
#define vvint(vec,n,m,l) vector<vector<int>> vec(n, vector<int>(m,l));	// lで初期化
#define vvll(vec,n,m,l) vector<vector<ll>> vec(n,vector<ll>(m,l));
#define vint vector<int>
#define pint pair<int,int>
#define rep(i,a) for(int i=0;i<(a);i++)
#define all(x) (x).begin(),(x).end()
#define debug system("pause")				//デバッグ用


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

	itn n, a, b;
	cin >> n >> a >> b;
	cout << min(a * n, b)<<endl;

}

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


int main(){
  int n,i;
  cin >> n;
  vector<int> a(n);
  int ans=0;
  for(i=0;i<n;++i){
    cin >> a[i];
    if(a[i]%2!=0){
      ans++;
    }
  }
  if(ans%2!=0){
    cout << "NO" << endl;
  }else{
    cout << "YES" << endl;
  }
  return 0;
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
int main() {
	int n,sum=0,sub=0,sa;
	int w[100];
	void sort(int n, int* w);
	std::cin >> n;
	for (int i = 0; i < n; ++i) {
		std::cin >> w[i];
	}
	for (int i = 0; i < n; ++i) {
		sum += w[i];
	}
	sa = sum;
	for (int i = 0; i < n; ++i) {
		sub += w[i];
		if (sa > std::abs(sum - 2*sub))sa = sum - 2 * sub;
	}
	std::cout << std::abs(sa) << std::endl;
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int h = scan.nextInt();
		int w = scan.nextInt();
		scan.nextLine();
		int[][] arr = new int[h][w];
		for(int i = 0; i < h; i++) {
			String[] line = scan.nextLine().split(" ");
			for(int j = 0; j < w; j++) {
				arr[i][j] = Integer.parseInt(line[j]);
			}
		}
		int[][] ansArr = new int[h][w];
		int ans = 0;
		for(int i = 0; i < h; i++) ansArr[i][0] = (arr[i][0]==0)?1:0;
		for(int i = 0; i < w; i++) ansArr[0][i] = (arr[0][i]==0)?1:0;
		for(int i = 1; i < h; i++) {
			for(int j = 1; j < w; j++) {
				ansArr[i][j] = (arr[i][j]==0)?Math.min(Math.min(ansArr[i-1][j],ansArr[i][j-1]),ansArr[i-1][j-1])+1:0;
			}
		}
		for(int[] _arr : ansArr) for(int num : _arr) ans = Math.max(ans,num);
		System.out.println(ans*ans);
	}
}



Measured memory_bytes: 113996
#include<stdio.h>
#define N 100
#define INFTY 10000000 
int min(int ,int);
int main(){
  int n,i,j,l,k,m[N+1][N+1],p[N+1];

  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d",&p[i-1]);
    scanf("%d",&p[i]);
      }

  for(i=1;i<=n;i++) m[i][i]=0;
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j] = INFTY;
      for(k=i;k<=j-1;k++){
	m[i][j] = min(m[i][j],m[i][k]+m[k+1][j]+p[i-1]*p[k]*p[j]);
      }
	
    }

  }
  printf("%d\n",m[1][n]);
  
  return 0;
}

int min(int x,int y){
  int min;
  if(x<y) min = x;
  else min = y;
  return  min;
}



Measured memory_bytes: 2108
#include <bits/stdc++.h>
#include <boost/multiprecision/cpp_int.hpp>
using namespace std;
typedef long long ll;
namespace mp = boost::multiprecision;
using Mint = mp::cpp_int;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repi(i,a,b) for(int i = int(a); i < int(b); i++)
#define all(v) v.begin(), v.end()
#define uni(v) v.erase(unique(all(v)), v.end())
#define sort_g(v) sort(all(v), greater<int>())
#define dump(x) cerr << #x << ' ' << '=' << ' ' << x << endl

int main() {
    int N;
    cin >> N;
    vector<int> A(N);
    rep(i, N) cin >> A.at(i);

    sort_g(A);

    cout << A.at(0) - A.at(A.size() - 1) << endl;
}


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

int main() {
  int N;
  cin >> N;
  vector<int> A(N + 1);
  int64_t buy;
  for (int i = 1; i <= N; i++) {
    cin >> A.at(i);
  }
  int64_t money = 1000;
  int64_t kabu = 0;
  for (int i = 1; i < N; i++) {
    if (A.at(i + 1) > A.at(i)) {
      buy = money / A.at(i);
      kabu += buy;
      money -= A.at(i) * buy;
    }
    else {
      money += kabu * A.at(i);
      kabu = 0;
    }
  }
  money += kabu * A.at(N);
  cout << money << endl;
  return 0;
}

Measured memory_bytes: 3560
import collections
l = collections.Counter()
n = int(input())
for i in range(n):
    k = input()
    l[k] += 1
n = int(input())
for i in range(n):
    k = input()
    l[k] -= 1
l = l.most_common()
print(l[0][1] if l[0][1] >= 0 else 0)


Measured memory_bytes: 39856
n = gets.to_i

h = {
  'AC' => 0,
  'WA' => 0,
  'TLE' => 0,
  'RE' => 0,
}

n.times do
  s = gets.strip
  h[s] += 1
end

puts "AC x #{h['AC']}"
puts "WA x #{h['WA']}"
puts "TLE x #{h['TLE']}"
puts "RE x #{h['RE']}"


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

N,K = map(int,input().split())
E = [[] for _ in range(N)]
MOD = 10**9+7

for _ in range(N-1):
	u,v = map(int,input().split())
	u -= 1
	v -= 1
	E[u].append(v)
	E[v].append(u)

if N == 1:
	print(K)
	sys.exit()

color = [-1 for _ in range(N)]

stack = []
color[u] = 1
ans = K
for i,v in enumerate(E[u]):
	stack.append(v)
	ans *= (K-i-1)
	ans %= MOD

while stack:
	u = stack.pop()
	color[u] = 1
	length = 0
	for v in E[u]:
		if color[v] == -1:
			stack.append(v)
			length += 1
	tmp = 1
	for i in range(K-1-length,K-1):
		tmp *= i
		tmp %= MOD
	ans *= tmp
	ans %= MOD

print(ans%MOD)


Measured memory_bytes: 23660
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
int main()
{
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  cout.tie(NULL);
  ll n, m;
  cin >> n >> m;
  ll a[n];
  double tot = 0;
  for (int i = 0; i < n; ++i)
  {
    cin >> a[i];
    tot += a[i];
  }
  double min = tot / (4 * m);
  sort(a, a + n);
  bool flag = false;
  ll cnt = 0;
  for (ll i = n - 1; i >= 0; i--)
  {
    if (a[i] >= min)
      cnt++;
    if (cnt == m)
    {
      flag = true;
      break;
    }
  }
  if (flag)
    cout << "Yes";
  else
    cout << "No";
}


Measured memory_bytes: 384
A, B, C, K = map(int, input().split())

ans = 0
import sys
while K > 0:
    if A and A >= K:
        ans += K
        break
    elif A and A < K:
        ans += A
        K -= A
        A = 0
    elif B and B >= K:
        break
    elif B and B < K:
        K -= B
        B = 0
    elif C and C >= K:
        ans -= K
        break
    elif C and C < K:
        ans -= C
        break
print(ans)

Measured memory_bytes: 9204
#include <algorithm>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <utility>
#include <vector>
#define MOD 1000000007
using namespace std;

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

int main() {
    int A, B;
    cin >> A >> B;
    cout << (A * B % 2 == 0 ? "No" : "Yes") << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(a,n) for (ll a = 0; a < (n); ++a)
using namespace std;
typedef long long ll;
typedef pair<ll,ll> P;
typedef pair<P,ll> PP;
typedef vector<vector<ll> > Graph;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
const ll INF = 1e18;


int main(){
    ll n;
    cin >> n;
    vector<ll>a(n);
    rep(i,n)cin>>a[i];
    ll kane = 1000;
    rep(i,n-1){
        if(a[i]>a[i+1]){
            a[i]=0;
        }
        else{
            break;
        }
    }
    for(int i=n-1;i>=1;i--){
        if(a[i-1]>a[i]){
            a[i]=0;
        }
        else{
            break;
        }
    }
    vector<ll>nx;
    rep(i,n){
        if(a[i]!=0){
            nx.push_back(a[i]);
        }
    }
    int l = nx.size();
    if(l==0){
        cout << 1000 << endl;
        return 0;
    }
    ll kabusuu = 1000/nx[0];
    kane -= nx[0]*kabusuu;
    bool sage=false;
    for(int i=1;i<l-1;i++){
        if(nx[i]==nx[i+1])continue;
        if(sage){
            if(nx[i]<nx[i+1]){
                kabusuu += kane/nx[i];
                kane -= kabusuu*nx[i];
                sage = false;
            }
        }
        else{
            if(nx[i]>nx[i+1]){
                kane += kabusuu*nx[i];
                kabusuu=0;
                sage = true;
            }
        }
    }
    kane += kabusuu*nx[l-1];
    cout << kane << endl;

    return 0;
}


Measured memory_bytes: 3628
#include<bits/stdc++.h>
#define all(vec) vec.begin(),vec.end()
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000010;
const ll LINF=4000000000000000010;
int dx[5]={0,1,0,-1,0};
int dy[5]={1,0,-1,0,0};
vector<int> v;
int main(){
    int n,m,p;cin>>n>>m>>p;
    for(int i=0;i<m;i++){
        int d;cin>>d;if(p>d)d+=n;
        v.push_back(d);
    }
    sort(all(v));
    int ans=min(v[m-1]-p,n-(v[0]-p));
    for(int i=0;i<m;i++){
        int s1=(n-(v[i]-p))*2+v[(i+m-1)%m]-p;
        int s2=(v[(i+m-1)%m]-p)*2+n-(v[i]-p);
        ans=min(ans,min(s1,s2));
    }
    cout<<ans*100<<endl;
}



Measured memory_bytes: 3176
import java.io.IOException;
import java.io.InputStream;
import java.util.NoSuchElementException;
  
public class Main {
    private static FastScanner sc = new FastScanner();
     
    public static void main(String[] args) {
        int N = sc.nextInt();
        int W = sc.nextInt();
        int[] v = new int[N];
        int[] w = new int[N];
        for(int i=0; i<N; i++) {
            v[i] = sc.nextInt();
            w[i] = sc.nextInt();
        }
         
        int[] dp = new int[W+1];
        for(int i=0; i<N; i++) {
            for(int j=W; j>=0; j--) {
                if(j-w[i] >= 0 && dp[j-w[i]] + v[i] > dp[j]) {
                    dp[j] = dp[j-w[i]] + v[i];
                }
            }
        }
         
        int max = 0;
        for(int j=0; j<=W; j++) {
            if(dp[j] > max) {
                max = dp[j];
            }
        }
        System.out.println(max);
    }
     
    static class FastScanner {
        private final InputStream in = System.in;
        private final byte[] buffer = new byte[1024];
        private int ptr = 0;
        private int buflen = 0;
        private boolean hasNextByte() {
            if(ptr < buflen) {
                return true;
            } else {
                ptr = 0;
                try {
                    buflen = in.read(buffer);
                } catch(IOException e) {
                    e.printStackTrace();
                }
                if(buflen <= 0) {
                    return false;
                }
            }
            return true;
        }
        private int readByte() { if (hasNextByte()) return buffer[ptr++]; else return -1;}
        private static boolean isPrintableChar(int c) { return 33 <= c && c <= 126;}
        private void skipUnprintable() { while(hasNextByte() && !isPrintableChar(buffer[ptr])) ptr++;}
        public boolean hasNext() { skipUnprintable(); return hasNextByte();}
        public String next() {
            if (!hasNext()) throw new NoSuchElementException();
            StringBuilder sb = new StringBuilder();
            int b = readByte();
            while(isPrintableChar(b)) {
                sb.appendCodePoint(b);
                b = readByte();
            }
            return sb.toString();
        }
        public long nextLong() {
            return Long.parseLong(next());
        }
        public int nextInt(){
            return Integer.parseInt(next());
        }
        public double nextDouble(){
            return Double.parseDouble(next());
        }
    }
}

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

int main() {
  int N;
  cin >> N;
  bool f = false; // 奇数のものがあり，先手必勝か
  int a;
  rep(i, N) {
    cin >> a;
    if (a % 2 == 1) {
      f = true;
      break;
    }
  }
  if(f) cout << "first" << endl;
  else cout << "second" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(long long i=0; i<n; i++)
#define Rep(i,n) for(long long i=1; i<n; i++)
#define ll long long
#include <math.h>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <numeric>
#include <queue>
#include <set>
#include <vector>


using namespace std;
#define PI acos(-1)
using P =pair<int,int>;

int main(){
    int n;
    cin>>n;
    vector<int> p(n),q(n);
    rep(i,n) cin>>p[i];
    rep(i,n) cin>>q[i];
    vector<int> a(n);
    rep(i,n)a[i]=i+1;
    
    map<vector<int>,int> mp;
    do{
        mp[a] =mp.size();
    } while (next_permutation(a.begin(),a.end()));
    cout<<abs(mp[p]-mp[q])<<endl;
    }


Measured memory_bytes: 8656
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include<cmath>
#include<limits>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define pint_INF 2000000000
#define ll_INF 	9223372036854775807
#define MOD 1000000007
#define vi vector<int>
#define vvi vector<vector<int>>
#define vvll vector<vector<long long>>
#define vvc vector<vector<char>>
#define vll vector<long long>
#define pii pair<int,int>
#define vpii vector<pair<int,int>>
#define sysp system("PAUSE")
#define pno cout << "no" << endl
#define pyes cout << "yes" << endl
#define pYes cout << "Yes" << endl
#define pNo cout << "No" << endl
using namespace std;

vi generate(vi& vec) {
    vector<int> res;
    for (int i = 0; i < vec.size(); i++) {
        for (int j = 0; j < vec[i]; j++) {
            res.push_back(i + 1);
        }
    }
    return res;
}

int main() {
    int H, W, N; cin >> H >> W >> N;
    vi vec(N); rep(i, N) cin >> vec[i];
    vi gen = generate(vec);

    int dir = 1;
    int cnt = 0;
    vector<vi> ans(H, vi(W));
    for (int i = 0; i < H; i++) {
        if (dir < 0) {
            int j = W - 1;
            for (; j >= 0; j--) {
                ans[i][j] = gen[cnt];
                cnt++;
            }
            dir = -dir;
        }
        else {
            int j = 0;
            for (; j < W; j++) {
                ans[i][j] = gen[cnt];
                cnt++;
            }
            dir = -dir;
        }
    }

    for (auto v : ans) {
        for (auto e : v) {
            cout << e << " ";
        }
        cout << endl;
    }
    cout << endl;
}

Measured memory_bytes: 3712
#include<stdio.h>
#include<stdlib.h>
int Desc(const void* a,const void* b){return *(const int*)a>*(const int*)b?-1:1;}
int IN(void)
{
  int x=0,f=0,c=getchar();while(c<48||c>57){f^=c==45,c=getchar();}
  while(c>47&&c<58){x=x*10+c-48,c=getchar();}return f?-x:x;
}
int main(void)
{
  int N=IN(),K=IN(),P[1000]={0},i=0,sum=0;
  while(i<N){P[i++]=IN();}
  qsort(P,(size_t)N,sizeof(int),Desc);
  while(i>N-K){sum+=P[--i];}
  return printf("%d\n",sum),0;
}

Measured memory_bytes: 1608
import bisect
import heapq
import itertools
import math
import operator
import os
import re
import string
import sys
from collections import Counter, deque, defaultdict
from copy import deepcopy
from decimal import Decimal
from fractions import gcd
from functools import lru_cache, reduce
from operator import itemgetter, mul, add, xor

import numpy as np

if os.getenv("LOCAL"):
    sys.stdin = open("_in.txt", "r")

sys.setrecursionlimit(2147483647)
INF = float("inf")
IINF = 10 ** 18
MOD = 10 ** 9 + 7

X = int(sys.stdin.readline())
ans = 0
x = 1
s = 0
while s < X:
    s += x
    x += 1
print(x - 1)


Measured memory_bytes: 13664
n,a,b = map(int,input().split())
x_ls = list(map(int, input().split()))

cost = 0
for i in range(1,n):
    diff = x_ls[i] - x_ls[i-1]
    if diff * a < b:
        cost += diff * a
    else:
        cost += b
print(cost)

Measured memory_bytes: 14252
#include <bits/stdc++.h>
using namespace std;
int main() {
  int a[9],n,b; for(int i=0;i<9;i++) cin>>a[i];
  cin>>n;
  for(int i=0;i<n;i++){
    cin>>b;
    for(int& i:a) if(i==b) i=0;
  }
  cout<<(!(a[0]+a[1]+a[2])||!(a[3]+a[4]+a[5])||!(a[6]+a[7]+a[8])||!(a[0]+a[3]+a[6])||!(a[1]+a[4]+a[7])||!(a[2]+a[5]+a[8])||!(a[0]+a[4]+a[8])||!(a[2]+a[4]+a[6])?"Yes":"No");
}

Measured memory_bytes: 3644
#include <stdio.h>

int main(){
	int num, i;
	char number[1001] = {};
	while(1){
		scanf("%s", number);
		if(number[0] == '0')break;
		num = 0;
		for(i = 0; number[i] != '\0'; i++){
			num += number[i] - '0';
		}
		printf("%d\n", num);
	}
	return 0;
}

Measured memory_bytes: 536
#include<bits/stdc++.h>
using namespace std;
#define MOD 1000000007
#define BIG 1000000010
#define EPS 1e-9
#define fst first
#define scd second

#define debug(x) cout<<x<<endl;
#define repi(i,x,n) for(int i=x;i<n;i++)
#define rep(i,n) repi(i,0,n)
#define repn(i,n) for(int i=n;i>=0;i--)
#define int long long


signed main(){
  int n,k;
  cin>>n>>k;
  if(k==1) cout<<0<<endl;
  else cout<<max((int)0,n-k)<<endl;

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i, n) for (int i = 0; i < n; i++)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define ll long long int

struct edge
{
  int to, cost;
};
typedef std::vector<std::vector<edge>> graph;
const ll MOD = 1000000007;
using namespace std;

int main()
{
  int n, m;
  int a[50][50] = {};
  int b[50][50] = {};
  cin >> n >> m;
  REP(i, n)
  {
    string s;
    cin >> s;
    REP(j, s.length())
    {
      if (s[j] == '.')
      {
        a[i][j] = 0;
      }
      else
      {
        a[i][j] = 1;
      }
    }
  }

  REP(i, m)
  {
    string s;
    cin >> s;
    REP(j, s.length())
    {
      if (s[j] == '.')
      {
        b[i][j] = 0;
      }
      else
      {
        b[i][j] = 1;
      }
    }
  }

  REP(i, n - m + 1)
  {
    REP(j, n - m + 1)
    {
      bool flag = true;
      REP(k, m)
      {
        REP(l, m)
        {
          if (b[k][l] != a[i + k][j + l])
          {
            flag = false;
          }
        }
      }
      if (flag)
      {
        cout << "Yes" << endl;
        return 0;
      }
    }
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int x, y, z, qaq, ans;
int main()
{
    cin >> x >> y >> z;
qaq = z;
    while(qaq + y + z <= x){
        qaq += y + z; 
        ans ++;
    }
    cout << ans <<endl;
    return 0;
}

Measured memory_bytes: 256
N,M=map(int,input().split())
s=set([])
g=set([])
for i in range(M):
    a,b=map(int,input().split())
    if a==1:s.add(b)
    if b==N:g.add(a)
print(["IMPOSSIBLE","POSSIBLE"][len(s&g)>0])

Measured memory_bytes: 19024
def main():
    s=input()
    
    ans=0
    before=""
    dump=0
    for now in s:
      #print(before,now,dump)
      if now!=before:
        if dump==1:
          before=before+now
          ans+=1
          dump=0
          
        else:
          ans+=1
          before=now
      else:
        if dump==1:
          before=before*2
          dump=0
          ans+=1
        else:
          dump=1
    print(ans)
    
if __name__ == "__main__":
    main()

Measured memory_bytes: 3500
n = int(input())
s = input()
d = dict()
for x in 'RGB':
    d[x] = s.count(x)
ans = 0
for j in range(n-1):
    for i in range(j):
        if s[i] != s[j]:
            for t in 'RGB':
                if s[i] != t != s[j]:
                    break
            ans += d[t] - ((2*j - i) < n and t == s[2*j - i])
    d[s[j]] -= 1
print(ans)

Measured memory_bytes: 68512