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

using namespace std;

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

    vector<int> vt(n, 0);
    for (int i = 0; i < m; ++i) {
        int a, b;
        cin >> a >> b;
        vt[a - 1]++;
        vt[b - 1]++;
    }

    for (auto &x:vt) {
        cout << x << endl;
    }
    return 0;
}


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

namespace ABC043_A_Children_and_Candies
{
	internal class Program
	{
		public static void Main(string[] args)
		{
			int n = int.Parse(Console.ReadLine());

			int candyCount = 0;

			for (int i = 0; i < n; i++)
			{
				candyCount += i + 1;
			}
			
			Console.WriteLine(candyCount);
		}
	}
}

Measured memory_bytes: 13268
#include <stdio.h>

int main() {
    
    int n, r;
    scanf("%d", &n);
    scanf("%d", &r);
    
    int j= r+(100*(10-n));
    
    
    if(n<10)
    {
        printf("%d", j);
    }
    else
    {
        printf("%d", r);
    }
    
    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
  
using namespace std;
  
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;
#define REP(i,n) for(ll i=0;i<n;++i)
#define REPR(i,n) for(ll i=1;i<n;++i)
#define FOR(i,a,b) for(ll i=a;i<b;++i)
  
#define DEBUG(x) cout<<#x<<": "<<x<<endl
#define DEBUG_VEC(v) cout<<#v<<":";REP(i,v.size())cout<<" "<<v[i];cout<<endl
#define ALL(a) (a).begin(),(a).end()
  
#define MOD (ll)(1e9+7)
#define ADD(a,b) a=((a)+(b))%MOD
#define FIX(a) ((a)%MOD+MOD)%MOD

#define INF 1000000000

typedef long double Real;
#define EPS 1e-13
#define EQ(x) (-EPS<x && x<EPS)
typedef complex<Real> P;
Real dot(P a,P b){return real(conj(a)*b);}
Real cross(P a,P b){return imag(conj(a)*b);}

// numcnt,sum
ll dp[10][2521];

int main(){
  dp[0][0] = 1;
  REP(x,101){
    REPR(_n,10){
      int n = 10-_n;
      REP(s,1001){
        dp[n][s+x] += dp[n-1][s];
      }
    }
  }
  while(true){
    int a,b;
    cin>>a>>b;
    if(!a&&!b)break;
    cout<<dp[a][b]<<endl;
  }
  return 0;
}

Measured memory_bytes: 1272
#include <stdio.h>

#define MAX 100
#define INFI 5000000

int main(){
  int n;
  int p[MAX+1];
  int m[MAX+1][MAX+1];
  int i=0;
  int j=0;
  int k=0;
  int l=0;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d%d",&p[i-1],&p[i]);
  }

  for(i=1;i<=n;i++) m[i][i]=0;
  
  for(j=2;j<=n;j++){
    for(i=1;i<=n-j+1;i++){
      k=i+j-1;
      m[i][k]=INFI;
      for(l=i;l<=k-1;l++){
	if(m[i][k]<m[i][l]+m[l+1][k]+p[i-1]*p[l]*p[k])
	  m[i][k]=m[i][k];
	else
	  m[i][k]=m[i][l]+m[l+1][k]+p[i-1]*p[l]*p[k];
      }
    }
  }
  
  printf("%d\n",m[1][n]);

  return 0;
}



Measured memory_bytes: 2112
#include <bits/stdc++.h>
#define rep(i, a, b) for(int i = a; i < b; i++)
#define Rep(i, a, b) for(int i = a; i <= b; i++)
#define _GLIBCXX_DEBUG
#define Vl vector<ll>
#define Vs vector<string>
#define Vp vector<pair<ll, ll>>
#define ll long long
#define ALL(v) (v).begin(),(v).end()
using namespace std;  
const double pi = acos(-1.0);
const ll MOD = 1e9 + 7;
const ll INF = 1LL << 60;



int main() { 
  ll n, a, b, c, d; cin >> n >> a >> b >> c >> d;
  string s; cin >> s;

  rep(i, a, max(c, d)){
    if(s[i] == '#' && s[i+1] == '#'){
      puts("No");
      return 0;
    }
  }
  if(c < d){
    puts("Yes");
    return 0;
  }
  Rep(i, b-1, d-1){
    if(i-1 >= 0 && i+1 < n)
    if(s[i-1] == '.' && s[i] == '.' && s[i+1] == '.'){
      puts("Yes");
      return 0;
    }
  }
  puts("No");

  return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin >> n;
    vector<string> v;
    map<string,int> mp;
    set<string> s;
    for(int i = 0 ; i < n; i++){
        string st;
        cin >> st ;
        mp[st]++;
        v.push_back(st);
    }

    int ma = 0;
    for(int i = 0; i < n; i++){
        ma = max(ma,mp[v[i]]);
    }
    for(int i = 0; i < n;i++){
        if(mp[v[i]] == ma){
            s.insert(v[i]);
        }
    }

    for(auto nx : s){
        cout << nx << endl;
    }




}
// APPROVED
// DENIED


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

int main(){
    int L;
    string S;
    cin >> L >> S;
    S = "." + S + ".";
    int ans = 0;
    for(int i=1; i<=L; i++){
        if(S[i] != '.') continue;
        bool ng = true;
        for(int d : {-1, 1}) for(int j=i+d; ; j+=d){
            if(S[j] == 'B'){
                break;
            }else if(S[j] == '.'){
                ng = false;
                break;
            }
        }
        if(ng) continue;
        int gain = 0;
        for(int d : {-1, 1}){
            int g = 0;
            for(int j=i+d; ; j+=d){            
                if(S[j] == 'B'){
                    g++;
                }else if(S[j] == '.'){
                    break;
                }else{
                    gain += g;
                    break;
                }
            }
        }
        ans = max(ans, gain);
    }
    cout << ans << endl;
    return 0;
}



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

int main () {
  string s;
  cin >> s;
  
  if (s.size() == 2) {
    cout << s << endl;
  }
  else {
    for (int i = 0; i < 3; i++) {
      cout << s[2-i];
    }
    cout << endl;
  }
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cmath>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

using namespace std;
using ll = long long;
const int IINF = 1e9;
const ll INF = 1e18;
const int MOD = 1e9 + 7;

#define dump(x) cout << #x << " = " << (x) << endl;
#define YES(n) cout << ((n) ? "YES" : "NO") << endl

template <typename T>
void dumpvec(vector<T> vec) {
  for (T cnt : vec) {
    cout << cnt << ", ";
  }
  cout << endl;
}

void chmin(ll &a, ll b) {
  if (a > b) {
    a = b;
  }
}
void chmax(ll &a, ll b) {
  if (a < b) {
    a = b;
  }
}

vector<string> split(string s, string delimiter) {
  int first = 0;
  int last = s.find_first_of(delimiter);
  vector<string> result;

  while (first < s.size()) {
    string sub = s.substr(first, last - first);
    result.push_back(sub);
    first = last + 1;
    last = s.find_first_of(delimiter, first);

    if (last == string::npos) {
      last = s.size();
    }
  }

  return result;
}

string join(vector<string> strings, string delimiter) {
  string result = "";
  for (int i = 0; i < strings.size(); i++) {
    if (result != "") result += delimiter;
    result += strings[i];
  }
  return result;
}

// FROM HERE
ll modCombination(vector<ll> &frac, vector<ll> &revfrac, int n, int p) {
  if (n < p) {
    throw new invalid_argument("p shuold be lteq n");
  }
  return ((frac[n] * revfrac[p] % MOD) * revfrac[n - p] % MOD) % MOD;
}

// base**exp
ll modExpo(int base, int exp) {
  if (exp == 0) {
    return 1;
  }

  if (exp % 2 == 0) {
    ll tmp = modExpo(base, exp / 2) % MOD;
    return (tmp * tmp % MOD);
  } else {
    ll tmp = modExpo(base, (exp - 1) / 2) % MOD;
    return (((tmp * tmp) % MOD) * base) % MOD;
  }
}

// n!
vector<ll> modFracTable(int size) {
  vector<ll> frac = vector<ll>(size, 0);
  for (int i = 0; i < size; i++) {
    if (i == 0) {
      frac[i] = 1;
    } else {
      frac[i] = ((i % MOD) * frac[i - 1]) % MOD;
    }
  }
  return frac;
}

// (n!)**-1
vector<ll> modRevFracTable(int size) {
  vector<ll> frac = modFracTable(size);
  vector<ll> revfrac = vector<ll>(size, 0);
  for (int i = 0; i < size; i++) {
    revfrac[i] = modExpo(frac[i], MOD - 2);
  }
  return revfrac;
}

// FROM HERE

int main() {
  int H, W, A, B;
  cin >> H >> W >> A >> B;

  vector<ll> frac = modFracTable(200010);
  vector<ll> revfrac = modRevFracTable(200010);

  ll ans = 0;
  for (int i = B + 1; i <= W; i++) {
    ll toPoint1 = modCombination(frac, revfrac, (i - 1 + H - A - 1), i - 1);

    // 2. point1->point2
    ll toPoint2 = 1;

    // 3. point2(i+1, H-A+1)->G(W, H)
    ll toGoal =
        modCombination(frac, revfrac, (W - i + H - (H - A + 1)), (W - i));

    ans += ((toPoint1 * toPoint2 * toGoal) % MOD);
    ans %= MOD;
  }

  cout << ans << endl;
}

Measured memory_bytes: 4992
#ifndef ___Geometry_Library
#define ___Geometry_Library

// ------ Includes ------ //
#include <cmath>
#include <complex>
#include <utility>
#include <algorithm>

// ------ Defines ------ //
typedef long double GType;
typedef std::complex<GType> Point;
typedef std::pair<Point, Point> Segment;

// ------ Constants ------ //
const GType EPS = 1.0e-10L;

// ------ Functions Level 1 ------ //
GType dot(const Point& p1, const Point& p2) {
	return (std::conj(p1) * p2).real();
}
GType cross(const Point& p1, const Point& p2) {
	return (std::conj(p1) * p2).imag();
}
int ccw(const Point& p1, const Point& p2, const Point& p3) {
	Point v1 = p2 - p1, v2 = p3 - p1;
	if (cross(v1, v2) > EPS) return +1;
	if (cross(v1, v2) < -EPS) return -1;
	if (dot(v1, v2) < -EPS) return +2;
	if (std::norm(v1) < std::norm(v2)) return -2;
	return 0;
}

// ------ Functions Level 2 ------ //
bool intersect(const Segment& s1, const Point& p1, bool segflag) {
	if (!segflag) return std::abs(cross(s1.second - p1, s1.first - p1)) < EPS;
	return (std::abs(s1.first - p1) + std::abs(s1.second - p1) - std::abs(s1.second - s1.first)) < EPS;
}
bool intersect(const Segment& s1, const Segment& s2, bool segflag) {
	if (!segflag) return cross(s1.second - s1.first, s2.first - s1.first) * cross(s1.second - s1.first, s2.second - s1.first) < EPS;
	return (ccw(s1.first, s1.second, s2.first) * ccw(s1.first, s1.second, s2.second)) <= 0 && (ccw(s2.first, s2.second, s1.first) * ccw(s2.first, s2.second, s1.second)) <= 0;
}
Point projection(const Segment& s1, const Point& p1) {
	GType mul = dot(p1 - s1.first, s1.first - s1.second) / norm(s1.first - s1.second);
	return s1.first + (s1.first - s1.second) * mul;
}
Point reflection(const Segment& s1, const Point& p1) {
	return p1 + (projection(s1, p1) - p1) * (GType)(2);
}
GType distance(const Point& p1, const Point& p2) {
	return std::abs(p2 - p1);
}
GType distance(const Segment& s1, const Point& p1, bool segflag) {
	if (!segflag) return std::abs(p1 - projection(s1, p1));
	const Point p2 = projection(s1, p1);
	if (intersect(s1, p2, true)) return std::abs(p2 - p1);
	return std::min(std::abs(s1.first - p1), std::abs(s1.second - p1));
}
GType distance(const Segment& s1, const Segment& s2, bool segflag) {
	if (intersect(s1, s2, segflag)) return 0;
	if (!segflag) return std::min(distance(s1, s2.first, false), distance(s1, s2.second, false));
	return std::min({ distance(s1, s2.first, true), distance(s1, s2.second, true), distance(s2, s1.first, true), distance(s2, s1.second, true) });
}

#endif

#include <iomanip>
#include <iostream>
using namespace std;
int q, xa, ya, xb, yb; Segment s1, s2;
int main() {
	cin >> q;
	while (q--) {
		cin >> xa >> ya >> xb >> yb; s1 = make_pair(Point(xa, ya), Point(xb, yb));
		cin >> xa >> ya >> xb >> yb; s2 = make_pair(Point(xa, ya), Point(xb, yb));
		cout << fixed << setprecision(15) << distance(s1, s2, true) << endl;
	}
	return 0;
}

Measured memory_bytes: 3368
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#define ll long long
#define endl '\n'
using namespace std;
using namespace __gnu_pbds;
template<typename T>
using ordered_set =
tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
ll memo[3001][3001],arr[3001];
int a;
ll solve(int s,int e){
    if(s>e)
        return 0;
    ll &cur=memo[s][e];
    if(cur!=-1)
        return cur;
    if(s==e)
        return arr[s];
    cur=max(arr[s]-solve(s+1,e),arr[e]-solve(s,e-1));
    return cur;
}
int main() {
    ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    memset(memo,-1,sizeof(memo));
    cin>>a;
    for(int i=0;i<a;i++)
        cin>>arr[i];
    cout<<solve(0,a-1);
}

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


int main(){


    int n, i, t;

    vector<int> d;


    cin >> n;


    for( i = 0 ; i < n ; i = i + 1 ){

         cin >> t;

         d.push_back(t);

         }


    sort( d.begin(), d.end() );


    cout << d.at( n / 2 ) - d.at( n / 2 - 1 ) << endl;

    
    return 0;


    }


Measured memory_bytes: 892
#include<iostream>
#include<vector>
#include<algorithm>
#include<map>
#define f first
#define s second
using namespace std;
 
int main()
{
  int N,x,y,w;
  map<pair<int,int>,int> M;
  vector<pair<int,int> > V; 
  cin>>N;
  for(int i=0;i<N;i++){
    cin>>x>>y>>w;
    M[make_pair(x,y)]=w;
    V.push_back(make_pair(x,y));
  }
  int ans=0,sum;
  for(int i=0;i<N;i++){
    sum=M[make_pair(V[i].f,V[i].s)];
    sum+=M[make_pair(V[i].f,V[i].s+1)];
    sum+=M[make_pair(V[i].f+1,V[i].s)];
    sum+=M[make_pair(V[i].f+1,V[i].s+1)];
    ans=max(ans,sum);
    sum=M[make_pair(V[i].f,V[i].s)];
    sum+=M[make_pair(V[i].f,V[i].s-1)];
    sum+=M[make_pair(V[i].f+1,V[i].s)];
    sum+=M[make_pair(V[i].f+1,V[i].s-1)];
    ans=max(ans,sum);
  }
  cout<<ans<<" / 1"<<endl;
 
  return 0;
}


Measured memory_bytes: 41100
///
// File:  b.cpp
// Author: ymiyamoto
//
// Created on Wed Oct  4 20:37:57 2017
//

#include <cstdint>
#include <iostream>
#include <string>
#include <vector>

using namespace std;
static vector<char> stack;

int32_t main()
{
  string str;
  cin >> str;

  for (uint32_t i = 0; i < str.size(); i++) {
    if (str[i] == 'B') {
      if (!stack.empty()) {
        stack.pop_back();
      }
    } else {
      stack.push_back(str[i]);
    }
  }

  for (uint32_t i = 0; i < stack.size(); i++) {
    cout << stack[i];
  }
  cout << endl;

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <climits>
#include <utility>
using namespace std;
int main()
{
	int n,k;
	cin >> n >> k;
	vector<int> h(n),c(n);
	for(int i=0;i<n;i++)
	{		
		cin >> h[i];
	}
	c[0]=0;
	c[1]=abs(h[1]-h[0]);
	for(int i=2;i<n;i++)
	{
		c[i]=INT_MAX;
	}
	for(int i=2;i<n;i++)
	{
		if(i<k)
		{
			for(int j=0;j<=i-1;j++)
			{
				c[i]=min(abs(c[j]+abs(h[i]-h[j])),c[i]);
			}
		}
		else
		{
			for(int j=i-k;j<=i-1;j++)
			{
				c[i]=min(abs(c[j]+abs(h[i]-h[j])),c[i]);
			}
		}
	}
	cout << c[n-1];
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
int main()
{
	string s;
	cin>>s;
	for(int i=0;i<s.size();i++)
	{
		if(s[i]!='?')
		{
			cout<<s[i];
		}
		else
		{
			cout<<"D";
		}
	}
	return 0;
}

Measured memory_bytes: 3688
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <algorithm>
#include <set>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <string>
#include <bitset>
#include <ctime>
#include <random>
#include <unordered_set>
#include <unordered_map>
#include <functional>
#pragma comment(linker, "/STACK:256000000")
using namespace std;

#define in(s) freopen(s, "r", stdin)
#define out(s) freopen(s, "w", stdout)
#define forn(i, n) for (int i = 0; i < n; i++)
#define endl '\n'
#define mp make_pair

typedef long long ll;
typedef long double ld;

const int inf = (int)1e+9 + 7;
const int MAXN = 25;

char arr[MAXN][MAXN];

pair<int, int> to[4] = { { -1, 0 }, { 1, 0 }, { 0, -1 }, { 0, 1 } };

vector < vector<int> > g;

int main()
{
	//in("input.txt");
	//out("output.txt");
	srand(1373737);
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);

	int n, m;
	cin >> n >> m;

	forn(i, n) {
		forn(j, m)
			cin >> arr[i][j];
	}

	g.resize(n * m);
	forn(i, n) {
		forn(j, m) {
			if (arr[i][j] == '#')
				continue;
			int cur = i * m + j;
			forn(t, 4) {
				int tox = i + to[t].first, toy = j + to[t].second;
				if (tox >= 0 && tox < n && toy >= 0 && toy < m && arr[tox][toy] == '.')
					g[cur].push_back(tox * m + toy);
			}
		}
	}

	int ans = -1;
	forn(i, n * m) {
		vector <int> d(n * m, inf);
		d[i] = 0;
		queue <int> q;
		q.push(i);

		while (!q.empty()) {
			int v = q.front();
			q.pop();
			forn(j, (int)g[v].size()) {
				int to = g[v][j];
				if (d[to] > d[v] + 1) {
					d[to] = d[v] + 1;
					q.push(to);
				}
			}
		}

		forn(j, n * m) {
			if (d[j] != inf)
				ans = max(ans, d[j]);
		}
	}
	cout << ans;

	return 0;
}

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

int main() {
  
  int H,W;
  cin >> H >> W;
  vector<string> S(H);
  for(int i = 0;i < H;i++) {
    cin >> S.at(i);
  }

  vector<vector<int>> l(H,vector<int>(W,0)),c(H,vector<int>(W,0));

  for(int i = 0;i < H;i++) {
    int num = 0;
    for(int j = 0;j < W;j++) {
      if(S.at(i).at(j) == '.') {
        num++;
        c.at(i).at(j) = num;
      }else num = 0;
    }

    int maxi = 0;
    for(int j = W-1;j >= 0;j--) {
      if(S.at(i).at(j) == '.') maxi = max(maxi,c.at(i).at(j));
      else maxi = 0;
      c.at(i).at(j) = maxi;
    }
  }

  for(int i = 0;i < W;i++) {
    int num = 0;
    for(int j = 0;j < H;j++) {
      if(S.at(j).at(i) == '.') {
        num++;
        l.at(j).at(i) = num;
      }else num = 0;
    }

    int maxi = 0;
    for(int j = H-1;j >= 0;j--) {
      if(S.at(j).at(i) == '.') maxi = max(maxi,l.at(j).at(i));
      else maxi = 0;
      l.at(j).at(i) = maxi;
    }
  }

  int ans = 0;
  for(int i = 0;i < H;i++) {
    for(int j = 0;j < W;j++) {
      ans = max(ans,l.at(i).at(j)+c.at(i).at(j)-1);
    }
  }

  cout << ans << endl;

}






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

int main() {
  int N, A;
  cin >> N;
  cin >> A;

  if (N < A) {
    cout << "Yes" << endl;
  }
  else if (N >= A && (N % 500) <= A){
    cout << "Yes" << endl;
  }
  else{
    cout << "No" << endl;
  }
}

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

int n, dx[4] = {1, -1, 0, 0}, dy[4] = {0, 0, 1, -1};
vector<vector<int>> d;
vector<vector<bool>> s;
void dfs(int x, int y) {
    rep(dir, 4) {
        int u = x + dx[dir], v = y + dy[dir];
        if (u != clamp(u, 0, n - 1) || v != clamp(v, 0, n - 1)) continue;
        if (d[v][u] > d[y][x] + s[v][u]) {
            d[v][u] = d[y][x] + s[v][u];
            dfs(u, v);
        }
    }
}

int main() {
    int res = 0;
    cin >> n;
    d = vector<vector<int>>(n, vector<int>(n));
    s = vector<vector<bool>>(n, vector<bool>(n, true));
    rep(i, n) rep(j, n) d[i][j] = min({i + 1, n - i, j + 1, n - j});
    rep(i, n * n) {
        int p, x, y;
        cin >> p, --p;
        --d[y = p / n][x = p % n];
        s[y][x] = false;
        dfs(x, y);
        res += d[y][x];
    }
    cout << res;
}

Measured memory_bytes: 23752
#include <stdio.h>
#include <string>
#include <cstring>
#include <stdlib.h>
#include <math.h>
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <queue>
#include <list>
#include <iterator>
#include <assert.h>
#pragma warning(disable:4996) 

typedef long long ll;
#define MIN(a, b) ((a)>(b)? (b): (a))
#define MAX(a, b) ((a)<(b)? (b): (a))
#define LINF 9223300000000000000
#define INF 2140000000
const long long MOD = 1000000007;
using namespace std;


void mtxprd( int p, int q, int r, const ll* A, const ll* B, ll* C )
{
    int i, j, k;
    for(i=0; i<p; i++) {
        for(k=0; k<r; k++) {
            C[i*r+k] = 0;
            for(j=0; j<q; j++) {
                C[i*r+k] = (C[i*r+k] + A[i*q+j] * B[j*r+k]);  //%MOD;
            }
        }
    } 
    return;
}

int main(int argc, char* argv[])
{
    int n, m, l;
    scanf("%d%d%d", &n, &m, &l);

    vector<ll> a(n*m);
    int i,j;
    for(i=0; i<n; i++) {
        for(j=0; j<m; j++) {
            scanf("%lld", &a[i*m+j]);
        }
    }

    vector<ll> b(m*l);
    for(i=0; i<m; i++) {
        for(j=0; j<l; j++) {
            scanf("%lld", &b[i*l+j]);
        }
    }

    vector<ll> c(n*l);
    mtxprd( n, m, l, &a[0], &b[0], &c[0] );

    for(i=0; i<n; i++) {
        for(j=0; j<l; j++) {
            printf("%lld", c[i*l+j]);
            if(j<l-1) printf(" ");
        }
        printf("\n");
    }

    return 0;
}



Measured memory_bytes: 2856
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int>>;
#define ll long long
#define _GLIBCXX_DEBUG
const ll MOD = 1000000007;
const int MAX = 510000;

int main() {
  ll N;
  string S;
  cin >> N >> S;
  ll numR = count(S.begin(), S.end(), 'R');
  ll numG = count(S.begin(), S.end(), 'G');
  ll numB = count(S.begin(), S.end(), 'B');
  ll res = numR*numG*numB;
  for (ll i=0; i<N; i++) {
    for (ll j=i+1; j<N; j++) {
      if (j<2*j-i&&2*j-i<N) {
        ll k = 2*j-i;
        if (S[i]!=S[j]&&S[i]!=S[k]&&S[j]!=S[k]) res--;
      }
    }
  }
  cout << max(res, 0LL) << endl;
}


Measured memory_bytes: 3592
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>

using namespace std;
typedef long long ll;

int main(){
  ll N;
  cin >> N;
  ll A[N];
  for(int i=0;i<N;i++){
    cin >> A[i];
    A[i] = -A[i];
  }
  sort(A,A+N);
  ll ans=0;
  for(int i=2;i<N+1;i++){
    ll m = floor(i/2) + 1;
    //cout << m << endl;
    ans -= A[i-m];
  }
  cout << ans << endl;
}


Measured memory_bytes: 4756
#include<bits/stdc++.h>
#pragma optimize "O3"
#define endl '\n'
const int MAXN=1500000;
using namespace std;

vector<int> G[MAXN], G2[MAXN];
int sq[MAXN], used[MAXN], used2[MAXN], col[MAXN], col2[MAXN], n, d1, d2;
int make(int i, int j) {return i*2*n+j;}
void dfs(int u, bool c)
{
	col[u]=c, used[u]=1;
	for(int i=0; i<G[u].size(); i++)
		if(used[G[u][i]]==0) dfs(G[u][i], c^1);
}
void dfs2(int u, bool c)
{
	col2[u]=c, used2[u]=1;
	for(int i=0; i<G2[u].size(); i++)
		if(used2[G2[u][i]]==0) dfs2(G2[u][i], c^1);
}
bool check(int c1, int c2)
{
	int cnt=0;
	for(int i=0; i<2*n; i++)
		for(int j=0; j<2*n; j++) if(col[make(i, j)]==c1&&col2[make(i, j)]==c2) cnt++;
	if(cnt>=n*n)
	{
		cnt=0;
		for(int i=0; i<2*n; i++)
			for(int j=0; j<2*n; j++)
				if(cnt<n*n&&col[make(i, j)]==c1&&col2[make(i, j)]==c2) {cout<<i<<" "<<j<<endl; cnt++;}
		return true;
	}
	return false;
}

void mainp()
{
	for(int i=0; i<MAXN; i++) sq[i]=-1;
	for(int i=0; i*i<MAXN; i++) sq[i*i]=i;
    cin>>n>>d1>>d2;
    for(int i=0; i<2*n; i++)
		for(int j=0; j<2*n; j++)
			for(int ii=0; ii<2*n; ii++)
			{
				long long rez=d1-(ii-i)*1ll*(ii-i);
				if(rez>=0&&rez<4ll*n*n&&sq[rez]!=-1&&!(rez==0&&ii==i))
				{
					int jj=sq[rez];
					if(j-jj>=0)
					{
						G[make(i, j)].push_back(make(ii, j-jj));
						G[make(ii, j-jj)].push_back(make(i, j));
					}
					if(j+jj<2*n)
					{
						G[make(i, j)].push_back(make(ii, jj+j));
						G[make(ii, jj+j)].push_back(make(i, j));
					}
				} 
				
				rez=d2-(ii-i)*1ll*(ii-i);
				if(rez>=0&&rez<4ll*n*n&&sq[rez]!=-1&&!(rez==0&&ii==i))
				{
					int jj=sq[rez];
					if(j-jj>=0)
					{
						G2[make(i, j)].push_back(make(ii, j-jj));
						G2[make(ii, j-jj)].push_back(make(i, j));
					}
					if(j+jj<2*n)
					{
						G2[make(i, j)].push_back(make(ii, jj+j));
						G2[make(ii, jj+j)].push_back(make(i, j));
					}
				} 
			}
	for(int i=0; i<2*n; i++)
		for(int j=0; j<2*n; j++) if(used[make(i, j)]==0)  dfs(make(i, j), 0);
	for(int i=0; i<2*n; i++)
		for(int j=0; j<2*n; j++) if(used2[make(i, j)]==0)  dfs2(make(i, j), 0);
		
	/*for(int i=0; i<2*n; i++)
		for(int j=0; j<2*n; j++) if(col[make(i, j)]==0) cout<<i<<" "<<j<<endl;*/
	if(check(0, 0)) return;
	if(check(0, 1)) return;
	if(check(1, 0)) return;
	check(1, 1);
}

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


Measured memory_bytes: 249856
import os
import sys

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

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

A, B, C = list(map(int, sys.stdin.readline().split()))
ans = max(0, C - (A - B))

print(ans)


Measured memory_bytes: 3316
num_inputs = int(input())
array = input().split(' ')
count = 0

for i in range(num_inputs):
    minj = i
    for j in range(i, num_inputs):
        if int(array[j]) < int(array[minj]):
            minj = j
    
    if minj != i:
        buf = array[i]
        array[i] = array[minj]
        array[minj] = buf
        count += 1

print(' '.join(map(str, array)))
print(str(count))


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

main(){
  int N;
  cin >> N;
  int p[N];
  for(int ii=0;ii<N;ii++){
    cin >> p[ii];
  }
  int max=0;
  for(int ii=0;ii<N;ii++){
    if(max<p[ii])max=p[ii];
  }
  int ans=0;
  for(int ii=0;ii<N;ii++){
    ans+=p[ii];
  }
  ans-=max/2;
  cout << ans << endl;
}


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

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

  int cnt=0;
  for(int i=1;i<=n;i++){
    if(i%2!=0 && a[i]%2!=0)
      cnt++;
   } 
  
  cout<<cnt<<endl;
  return 0;
}



Measured memory_bytes: 3516
#include <bits/stdc++.h>
#define all(X) (X).begin(),(X).end()
#define rall(X) (X).rbegin(),(X).rend()
#define pub push_back
#define puf push_front
#define pob pop_back
#define pof pop_front
#define ff first
#define ss second
#define P 1000000007
#define CASET int ___T; scanf("%d", &___T); for(int cs=1;cs<=___T;cs++)
 
using namespace std;
using ll = long long;
typedef pair<int, int> ii;
typedef vector<ii> vii; 
typedef vector<int> vi;
 
//recollect
//simplify
//divide into cases (i.e. i = 1, 2, N, a prime number, etc...)
  
string maxstr(string a, string b) {
	if(a.size() > b.size()) return a;
	else if(b.size() > a.size()) return b;
	if(a > b) return a;
	else return b;
}
  
int cost[] = {2, 5, 5, 4, 5, 6, 3, 7, 6};  
  
void solve() {
	int n, m;
	cin >> n >> m;
	
	vi a(m);
	for(int i = 0; i < m; i++) cin >> a[i], a[i]--;
	
	vector<string> dp(n + 1, ".");
	dp[0] = "";
	for(int i = 0; i < n; i++) {
		if(dp[i] == ".") continue;
		for(int j = 0; j < m; j++) {
			if(i + cost[a[j]] <= n) dp[i + cost[a[j]]] = maxstr(dp[i] + (char)(a[j] + '0' + 1), dp[i + cost[a[j]]]);
		}
	} 
	
	cout << dp[n] << endl;
}
 
int main(){
#define MULTITEST 0
#if MULTITEST   
 
    CASET {
        solve();
    }
    
#else
 
    solve();
    
#endif
 
    return 0;
}

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


std::vector<int> insertion_Sort(std::vector<int>, int);
std::vector<int> shell_Sort(std::vector<int>);
int cnt = 0;
std::vector<int> G;

int main(int argc, char const *argv[]){
	int N;
	std::cin >> N;
	std::vector<int> A(N);
	for (int i = 0; i < N; ++i){
		std::cin >> A[i];
	}

	std::vector<int> v = shell_Sort(A);
	std::cout << G.size() << std::endl;

	for (int i = G.size()-1; i >=0; --i){
		std::cout << G[i] << " ";
		if(i<G.size()-1) std::cout << " ";		
	}
	std::cout << std::endl;
	std::cout << cnt << std::endl;

	for (int i = 0; i < v.size(); ++i){
		std::cout << v[i] << std::endl;
	}

	return 0;
}

std::vector<int> insertion_Sort(std::vector<int> A, int G){
	for (int i = G; i < A.size(); ++i){
		int buff = A[i];
		int j = i - G;
		while( j>=0 && A[j]>buff ){
			A[j+G] = A[j];
			j -= G;
			cnt++;
		}
		A[j+G] = buff;
	}
	return A;
}

std::vector<int> shell_Sort(std::vector<int> A){
	int h = 1;
	while(A.size()>=h){
		G.push_back(h);
		h = 3 * h + 1;
	}

	for (int i=G.size()-1; i >= 0; --i){
		A = insertion_Sort(A, G[i]);
	}
	return A;
}



Measured memory_bytes: 18488
# include <bits/stdc++.h>
using namespace std;
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; }

using Edge = pair<int,int>; // (隣接頂点, 辺番号)
using Graph = vector<vector<Edge>>;
int N;
Graph G;

int main() {
    cin >> N;
    G.assign(N, vector<Edge>());
    for (int i = 0; i < N-1; ++i) {
        int a, b; cin >> a >> b; --a, --b;
        G[a].emplace_back(b, i); 
        G[b].emplace_back(a, i);
    }
    int max_color = 0;
    for (int i = 0; i < N; ++i) chmax(max_color, (int)G[i].size());
    vector<int> res(N-1, -1);

    vector<int> dist(N, -1);
    queue<pair<int,int>> que; // (頂点, 前回の色)
    que.push({0, -1});
    dist[0] = 0;
    while (!que.empty()) {
        auto p = que.front(); que.pop();
        int v = p.first, c = p.second;
        int color = 1;
        if (color == c) ++color;
        for (auto e : G[v]) {
            if (dist[e.first] == -1) {
                dist[e.first] = dist[v] + 1;
                que.push({e.first, color});
                res[e.second] = color;
                ++color;
                if (color == c) ++color;
            }
        }
    }
    cout << max_color << endl;
    for (auto v : res) cout << v << endl;
}

Measured memory_bytes: 7424
number =int(input())
powers =input().rstrip().split()
#print(number)
#print(powers)
values=[]
for i in range(number):
  values.append(int(powers[i]))
ordered = sorted(values)
#print(ordered)
answer=0
for i in range(number):
  answer=answer+((1/2)**(number-i))*int(ordered[i])
#print(answer)
trueanswer=answer+int(ordered[0])*(1/2)**number
print(trueanswer)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
 
#define forn(i,n) for(int i=0;i<(int)(n);i++)
#define si(c) ((int)(c).size())
#define forsn(i,s,n) for(int i = (int)(s); i<((int)n); i++)
#define dforsn(i,s,n) for(int i = (int)(n)-1; i>=((int)s); i--)
#define all(c) (c).begin(), (c).end()
#define D(a) cerr << #a << "=" << a << endl;
#define pb push_back
#define eb emplace_back
#define mp make_pair
 
typedef long long int ll;
typedef vector<int> vi;
typedef pair<int,int> pii;
 
const int INF = 1e9;
const int N = 2e5 + 10;
const int L = 22;

int n,v,x[N],fwd[L][N], bak[L][N];
int pref[1<<L], suf[1<<L];

int main() {
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n >> v;
    x[0] = -INF-N; x[n+1] = INF+N;
    for (int i = 1; i <= n; i++) cin >> x[i];

    int l = 0;
    while (true) {
        fwd[l][n+1] = n+1;
        for (int i = n; i >= 1; i--) 
            fwd[l][i] = x[i+1]-x[i] <= v ? fwd[l][i+1] : i+1;

        bak[l][0] = 0;
        for (int i = 1; i <= n; i++)
            bak[l][i] = x[i]-x[i-1] <= v ? bak[l][i-1] : i-1;

        l++;
        if (v == 0) break;
        v /= 2;
    }

    vector<pii> seg;
    for (int i = 1; i <= n; i = fwd[0][i]) {
        int j = fwd[0][i];
        seg.eb(i,j);
    }

    if (si(seg) >= l+2) {
        forn(i,n) cout << "Impossible\n";
        return 0;
    }

    //forn(lev, l) { forsn(i,1,n+1) cerr << fwd[lev][i] << ' '; cerr << endl; }
    //forn(lev, l) { forsn(i,1,n+1) cerr << bak[lev][i] << ' '; cerr << endl; }

    for (int mask = 0; mask < (1<<l); mask++) {
        pref[mask] = 1;
        suf[mask] = n;
        forn(i,l) if ((mask>>i)&1) {
            pref[mask] = max(
                pref[mask], 
                fwd[i][pref[mask - (1<<i)]]
            );
            
            suf[mask] = min(
                suf[mask],
                bak[i][suf[mask - (1<<i)]]
            );
        }
    }

    //forn(mask, (1<<l)) {
    //    cerr << mask << ' ' << pref[mask] << ' ' << suf[mask] << endl;
    //}

    auto ALL = (1<<l)-2;
    for (auto lr : seg) {
        int l,r; tie(l,r) = lr;
        bool can_do = false;
        for (int mask = 0; mask <= ALL; mask += 2) {
            int other = ALL - mask;
            if (l <= pref[mask] && suf[other] < r) {
                can_do = true;
                break;
            }
        }
        forn(_,r-l) cout << (can_do ? "Possible\n" : "Impossible\n");
    }

    return 0;
}


Measured memory_bytes: 45824
#include <bits/stdc++.h>
using namespace std;
int main(){
	int n,k,c;
	string s;
	cin>>n>>k>>c>>s;
	vector<int> early;
	vector<int> late;
	int tmp=-1e9;
	for (int i=0;i<n;i++){
		if (i>tmp+c&&s[i]=='o'&&early.size()<k){
			tmp=i;
			early.push_back(i);
		}
	}
	tmp=1e9;
	for (int i=n-1;i>=0;i--){
		if (i<tmp-c&&s[i]=='o'&&late.size()<k){
			tmp=i;
			late.push_back(i);
		}
	}
	reverse(late.begin(),late.end());
	for (int i=0;i<k;i++)
		if (late[i]==early[i])
			cout<<late[i]+1<<endl;
	return 0;
}

Measured memory_bytes: 3448
import math
N, D = map(int, input().split())

x_list = []
for i in range(N):
    x = list(map(int,input().split()))
    x_list.append(x)
count = 0
for i in range(1, N + 1):
    for j in range(1, N + 1):
        if i >= j:
            continue
        distance2 = 0
        for num in range(D):
            distance2 += (x_list[i - 1][num] - x_list[j - 1][num]) ** 2
        if math.sqrt(distance2).is_integer():
            count += 1
            
print(count)

Measured memory_bytes: 3064
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace TestApp
{
    class Program
    {
        static void Main(string[] args)
        {
            var num =0;
            int a = int.Parse(Console.ReadLine());
            int b = int.Parse(Console.ReadLine());
            int c = int.Parse(Console.ReadLine());
            int d = int.Parse(Console.ReadLine());
            if (a >= b)
                num += b;
            else
                num += a;
            if (c >= d)
            {
                num += d;
            }
            else
                num += c;
            Console.WriteLine(num);

        }
    }
}


Measured memory_bytes: 13140
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		StringBuilder sb = new StringBuilder();
		int a = sc.nextInt();
		int b = sc.nextInt();
		if ((a - b) % 2 == 0) {
			System.out.println(a - (a - b) / 2);
		} else {
			System.out.println("IMPOSSIBLE");
		}
	}
}

Measured memory_bytes: 23380
import java.util.*;
class Main{
 public static void main(String[] args){
  new Main().solve();
}
public void solve(){
Scanner sc = new Scanner(System.in);
int A = sc.nextInt();
int B = sc.nextInt();
if(A+B > 23) System.out.println(A+B-24);
else System.out.println(A+B);
}
 
}


Measured memory_bytes: 21716
#include <iostream>
#include <algorithm>
#include <queue>
#include <vector>
using namespace std;
typedef long long ll;
typedef struct pair<int,int> P;
typedef struct pair<int,P> P2;

vector<ll> v[28];
vector<ll> v2;

int dp[100001]={};
const ll INF=1000000000000000001;
int main() {

	int a,b;
	cin>>a>>b;
	if((a<0)&&(b<0)){
		if((b-a+1)%2==0){
			cout<<"Positive"<<endl;
		}else{
			cout<<"Negative"<<endl;
		}
	}else if((a<0)&&(b>=0)){
		cout<<"Zero"<<endl;
	}else if(a==0){
		cout<<"Zero"<<endl;
	}else {
		cout<<"Positive"<<endl;
	}
	return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
bool able[1005][1005];
int data[100007][3];
int s[100007];
    
int main(){
    int n;
    int i,j,k;
    cin>>n;
    for(i=0;i<n;i++){
        cin>>data[i][0]>>data[i][1];
        data[i+1][2]=data[i][1]+data[i][2];
        able[i][i]=true;
    }
    for(k=1;k<n;k++){
        for(i=0;i<n;i++){
            if((j=i+k)>=n)break;
            if(able[i+1][j] && data[i][0]>=(data[j+1][2]-data[i+1][2]))able[i][j]=true;
            if(able[i][j-1] && data[j][0]>=(data[j][2]-data[i][2]))able[i][j]=true;
        }
    }
    s[0]=0;
    for(i=1;i<=n;i++){
        s[i]=n+1;
        for(j=0;j<i;j++){
            if(able[j][i-1] && s[j]+1<s[i])s[i]=s[j]+1;
        }
    }
    cout<<s[n]<<endl;
    return 0;
    
}

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

class MainClass
{
    static void Main()
    {
        int N = int.Parse(Console.ReadLine());
        if (N == 1)
        {
            Console.WriteLine("Hello World");
        }
        else
        {
            int A = int.Parse(Console.ReadLine());
            int B = int.Parse(Console.ReadLine());
            Console.WriteLine(A+B);
        }
    }
}

Measured memory_bytes: 27424
#include <bits/stdc++.h>
using namespace std;
#define mp       make_pair
#define pb       push_back
#define all(x)   (x).begin(),(x).end()
#define YES() printf("YES\n")
#define NO() printf("NO\n")
#define Yes() printf("Yes\n")
#define No() printf("No\n")
#define in(x,y,h,w) x >= 0 && x < h && y >= 0 && y < w

#define int long long
//typedef    long long          ll;
typedef    vector<bool>       vb;
typedef    vector<int>        vi;
typedef    vector<vb>         vvb;
typedef    vector<vi>         vvi;
typedef    pair<int,int>      P;

template <typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template <typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
 
const int INF=1e+18;
const double EPS=1e-9;
const int MOD=1000000007;

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

signed main(){
	double ans = 0;
	int n;
	cin >> n;
	for(int i = 0;i < n;i++){
		double a;
		string s;
		cin >> a >> s;
		if(s == "JPY") ans += a;
		else ans += a * 380000.0;
	}
	printf("%.9f\n",ans);
}

Measured memory_bytes: 764
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i,a,b) for(ll i=a;i<b;i++)
#define rrep(i,a,b) for(ll i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()

int main(void){
    ll h, w, d;
    cin >> h >> w >> d;

    ll a[h][w];
    ll cost[h * w];
    pair<ll, ll> b[h * w];
    rep(i, 0, h){
        rep(j, 0, w){
            cin >> a[i][j];
            a[i][j]--;
            b[a[i][j]].first = i;
            b[a[i][j]].second = j;
        }
    }

    ll q;
    cin >> q;
    ll l[q], r[q];
    rep(i, 0, q){
        cin >> l[i] >> r[i];
        l[i]--;
        r[i]--;
    }

    rep(i, 0, d){
        for(int j = i; j < h * w; j += d){
            if(j == i){
                cost[j] = 0;
            }else{
                cost[j] = cost[j - d] + abs(b[j].first - b[j - d].first) + abs(b[j].second - b[j - d].second);
            }
        }
    }

    rep(i, 0, q){
        cout << cost[r[i]] - cost[l[i]] << endl;
    }

    return 0;
}


Measured memory_bytes: 5504
#include <bits/stdc++.h>
#define pb push_back
#define mp make_pair
#define INF 120000000

using namespace std;

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

int main() {
    int n;
    cin >> n;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (int i = 0; i < n; i++) {
        int v = a[i];
        int j;
        for (j = i - 1; a[j] > v; j--) {
            a[j + 1] = a[j];
        }
        a[j + 1] = v;

        for (int j = 0; j < n; j++) {
            cout << a[j];
            if (j != n - 1) cout << " ";
        }
        cout << endl;
    }

    return 0;
}

Measured memory_bytes: 3092
import java.util.Arrays;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int k = sc.nextInt();
        int[] arr = new int[N];
        for(int i = 0; i < N; i++) {
            arr[i] = sc.nextInt();
        }
        Arrays.sort(arr);
        int res = 0;

        for(int i = 0; i < k; i++) {
            res += arr[i];
        }
        System.out.println(res);
    }
}


Measured memory_bytes: 38912
import java.util.Scanner;

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();

		for(int i = A;i<=B;i++) {
			if(i%K==0) {
				System.out.println("OK");
				return;
			}
		}
		System.out.println("NG");
	}
}


Measured memory_bytes: 35856
#include <iostream>

using namespace std;
struct node {
    node() : id {-1}, left {-1}, right {-1}, parent {-1}, sibling {-1}, depth {0}, height {0}, degree {0} {};
    node(int i, int l, int r) : id {i}, left {l}, right {r},
                                parent {-1}, sibling {-1}, depth {0},
                                height {0}, degree {0}
    {
        if(left >= 0){
            ++degree;
        }
        if(right >= 0){
            ++degree;
        }
    };
    int id;
    int left;
    int right;
    int parent;
    int sibling;
    int depth;
    int height;
    int degree;
};

int const_tree(node* ts, int r){
    int left = ts[r].left;
    int right = ts[r].right;
    int height = 0;
    if(left >= 0){
        ts[left].parent = r;
        ts[left].depth = ts[r].depth + 1;
        ts[left].sibling = ts[r].right;
        int h = const_tree(ts, left);
        if(height < h){
            height = h;
        }
    }
    if(right >= 0){
        ts[right].parent = r;
        ts[right].depth = ts[r].depth + 1;
        ts[right].sibling = ts[r].left;
        int h = const_tree(ts, right);
        if(height < h){
            height = h;
        }
    }
    return ts[r].height = (left < 0 && right < 0) ? 0 : height+1;
}

void print_tree(node* ts, int n){
    for(int i = 0; i < n; ++i){
        cout << "node " << i << ": ";
        cout << "parent = " << ts[i].parent << ", ";
        cout << "sibling = " << ts[i].sibling << ", ";
        cout << "degree = " << ts[i].degree << ", ";
        cout << "depth = " << ts[i].depth << ", ";
        cout << "height = " << ts[i].height << ", ";
        if(ts[i].parent < 0){
            cout << "root" << endl;
        } else if(ts[i].left < 0 && ts[i].right < 0){
            cout << "leaf" << endl;
        } else {
            cout << "internal node" << endl;
        }
    }
}

int main(){
    int n;
    cin >> n;
    node ts[n];
    auto fs = new bool[n];
    for(int i = 0; i < n; ++i){
        int a, b, c;
        cin >> a >> b >> c;
        node n = node(a, b, c);
        ts[a] = n;
        if(b >= 0){
            fs[b] = true;
        }
        if(c >= 0){
            fs[c] = true;
        }
    }
    int root = -1;
    for(int i = 0; i < n; ++i){
        if(!fs[i]){
            root = i;
            break;
        }
    }
    const_tree(ts, root);
    print_tree(ts, n);
}

Measured memory_bytes: 1192
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define call(var) cout<<#var<<"="<<var<<endl;
#define dup(x,y) (((x)+(y)-1)/(y))
using ll=long long;
using vi = vector<int>;
using vl = vector<ll>;
using vb = vector<bool>;
using Graph = vector<vi>;
using P = pair<int,int>;
const int MOD=(int)1e9+7;
const int INF=(int)1e9;
const ll LINF=(ll)1e18;
const int INTMAX = 2147483647;
template<class t,class u> void chmax(t&a,u b){if(a<b)a=b;}
template<class t,class u> void chmin(t&a,u b){if(b<a)a=b;}

int main(){
    int n,m;cin >> n >> m;
    int x = 1900;
    int y = 100;
    ll ans = (int)pow(2,m) * ((m * 1900) + (n-m) * 100);
    cout << ans << endl;
}

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

int main() {
    int N, K;
    cin >> N >> K;
    int L[60];
    int sum = 0;
    for(int i = 0; i < N; i++) {
        cin >> L[i];
    }
    sort(L, L + N, greater<int>());
    for(int i = 0; i < K; i++) {
        sum += L[i];
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <functional>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <vector>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef vector<int> vi;
typedef vector<ll> vl;
#define rep(var, n) for (int var = 0; var < (n); ++var)
#define ALL(c) (c).begin(), (c).end()

int main() {
  int n, m;
  cin >> n >> m;
  if (n >= m) {
    cout << 0 << endl;
    return 0;
  }
  vi x(m);
  rep(i, m) cin >> x[i];
  sort(ALL(x));
  vi l(m - 1);
  for (int i = 1; i < m; i++) {
    l[i - 1] = x[i] - x[i - 1];
  }
  sort(ALL(l), greater<int>());
  int all = x[x.size() - 1] - x[0];
  int nomove = 0;
  for (int i = 0; i < n - 1; i++) {
    nomove += l[i];
  }
  cout << all - nomove << endl;
  return 0;
}


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

const int SIZE = 110000;
vector<int> prime;
bool isprime[SIZE + 1] = {0};

void make_prime(){
    isprime[0] = true;
    isprime[1] = true;
    for(int i = 2; i <= SIZE; i++){
        if(isprime[i]) continue;
        for(int j = i * 2; j <= SIZE; j += i) isprime[j] = true;
        prime.push_back(i);
    }
}

int main(){
    make_prime();
    int n;
    while(cin >>n){
        if(n == 0) break;
        int sum = 0;
        for(int i = 0; i < n; i++){
            sum += prime[i];
        }
        cout <<sum <<endl;
    }
    return 0;
}

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

int main() {
  int N,K;
  cin >> N >> K;
  int a = 1;
  
  for (int i = 0;i < N;i++) {
    if (a >= K) {
      a += K;
    }
    
    else {
      a *= 2;
    }
  }
  
  cout << a << endl;

}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long
int main(){
  int A,B,C,X,Y;LL ans=1ll*1e18;
  scanf("%d%d%d%d%d",&A,&B,&C,&X,&Y);
  for(int i=0;i<=max(X,Y);i++)
    ans=min(ans,(LL)i*C*2+(LL)A*max(0,X-i)+(LL)B*max(0,Y-i));
  printf("%lld",ans);
  return 0;
}


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

using namespace std;

typedef long long ll;

int main () {
	ll n, m;
	ll i, j;
	ll ret = 0;
	string s, t;
	
	cin >> s >> t;
	
	for ( i = 0; i < s.size(); i++ ) {
		if ( s[i] != t[i] ) {
			ret++;
		}
	}
	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3916
local mfl, mce = math.floor, math.ceil
local n = io.read("*n", "*l")
local t = {}
local s = io.read()
local cnt1 = 0
for i = 1, n do
  t[i] = s:byte(i) == 49
  if t[i] then cnt1 = cnt1 + 1 end
end
local plusmap, minusmap = {}, {}
for i = 1, n do
  plusmap[i], minusmap[i] = 0, 0
end
do
  local dv = cnt1 + 1
  local mul = 1
  for i = n, 1, -1 do
    plusmap[i] = mul
    mul = (mul * 2) % dv
  end
end
if 2 < cnt1 then
  local dv = cnt1 - 1
  local mul = 1
  for i = n, 1, -1 do
    minusmap[i] = mul
    mul = (mul * 2) % dv
  end
end
local plus = 0
do
  local dv = cnt1 + 1
  for i = 1, n do
    if t[i] then
      plus = (plus + plusmap[i]) % dv
    end
  end
end
local minus = 0
if 1 < cnt1 then
  local dv = cnt1 - 1
  for i = 1, n do
    if t[i] then
      minus = (minus + minusmap[i]) % dv
    end
  end
end

local function firstdevide(p, dv)
  if t[p] then
    local currem = minus
    currem = (currem + dv - minusmap[p]) % dv
    return currem
  else
    local currem = plus
    currem = (currem + plusmap[p]) % dv
    return currem
  end
end

local function getpopcnt(x)
  local c = 0
  while 0 < x do
    if x % 2 == 1 then c = c + 1 end
    x = mfl(x / 2)
  end
  return c
end

for iq = 1, n do
  local dv = t[iq] and cnt1 - 1 or cnt1 + 1
  if dv == 0 then
    print(0)
  else
    local rem = firstdevide(iq, dv)
    local cnt = 1
    while 0 < rem do
      dv = getpopcnt(rem)
      rem = rem % dv
      cnt = cnt + 1
    end
    print(cnt)
  end
end


Measured memory_bytes: 9376
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(long long i=0;i<x;i++)
#define repn(i,x) for(long long i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
vector<pair<string,P> >vec;

void solve(long long n, long long s){
	ll res = -1, cnt = 1;
	if (n == s) res = n+1;
	for (ll b = 2; b*b <= n; b++) {
		ll p = n, r = 0, now = 0;
		while (p != 0) {
			r = p%b;
			p /= b;
			now += r;
		}
		if (now == s) {
			if (res == -1 ) res = b; else res = min(res,b);
		}
		cnt++;
	}
	for (ll p = 1; p*p <= n; p++) {
		ll b = (n-s+p)/p;
		// // if ((n-s+p)%p == 0) cout << p << " " << b << endl;
		// if ((n-s+p)%p == 0 && b > 0 && n%b+p == s && res == -1) res = b;
		// if (p == 2) cout << b << endl;

		// if (b == 0) continue;
		// while (q != 0) {
		// 	r = q%b;
		// 	q /= b;
		// 	now += r;
		// 	// if (p == 2) cout << r << " " << q << " " << now << endl;
		// }

		if ((n-s+p)%p == 0 && b > cnt && n%b+n/b == s) {
			if (res == -1 ) res = b; else res = min(res,b);
		}
	}
	cout << res << endl;
}

int main(){	
	long long s;
	long long n;
	scanf("%lld",&n);
	scanf("%lld",&s);
	solve(n, s);
	return 0;
}



Measured memory_bytes: 256