akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define mp(a,b) make_pair((a),(b))
#define pb(a) push_back((a))
#define all(x) (x).begin(),(x).end()
#define uniq(x) sort(all(x)),(x).erase(unique(all(x)),end(x))
#define fi first
#define se second
#define dbg(...) _dbg(#__VA_ARGS__, __VA_ARGS__)
void _dbg(string){cout<<endl;}
template<class H,class... T> void _dbg(string s,H h,T... t){int l=s.find(',');cout<<s.substr(0,l)<<" = "<<h<<", ";_dbg(s.substr(l+1),t...);}
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}
 
#define INF 1120000000
 
int main(){
  int x,y,z;
  cin>>x>>y>>z;
  int n = x+y+z;
  vector<long> a(n), b(n), c(n);
  rep(i,n) scanf("%ld %ld %ld", &a[i], &b[i], &c[i]);
 
  vector<int> vi(n);
  rep(i,n) vi[i] = i;
  sort(all(vi),[&](int l, int r){
    return a[l]-b[l] < a[r]-b[r];
  });
  // a[l]+b[r] < a[r]+b[l]
 
  vector<long> vl(n, 0), vr(n, 0);
 
  {
    priority_queue<long> pq;
    // 左からL個の中からy個のb，残りはc
    long tmp = 0;
    rep(i,y){
      int id = vi[i];
      pq.push(c[id] - b[id]);
      tmp += b[id];
    }
    vl[y-1] = tmp;
    repl(i,y,n){
      int id = vi[i];
      tmp += b[id];
      long t = pq.top(); pq.pop();
      long u = c[id]-b[id];
      pq.push(min(t, u));
      tmp += max(t, u);
      vl[i] = tmp;
    }
  }
 
  {
    priority_queue<long> pq;
    // 右からR個の中からx個のa，残りはc
    long tmp = 0;
    for(int i=n-1; i>=n-x; i--){
      int id = vi[i];
      pq.push(c[id] - a[id]);
      tmp += a[id];
    }
    vr[n-x] = tmp;
    for(int i=n-x-1; i>=0; i--){
      int id = vi[i];
      tmp += a[id];
      long t = pq.top(); pq.pop();
      long u = c[id]-a[id];
      pq.push(min(t, u));
      tmp += max(t, u);
      vr[i] = tmp;
    }
  }
 
  long ans = 0;
  for(int i=y-1; i+x<n; i++){
    ans = max(ans, vl[i] + vr[i+1]);
  }
 
  cout << ans << endl;
 
  return 0;
}

Measured memory_bytes: 5752
n, m, x = gets.split(" ").map(&:to_i)
books = Array.new(n){ gets.split(" ").map(&:to_i) }

check = []
for i in 1..2 ** n
  bit = i
  price = 0
  understanding = Array.new(m){ 0 }
  books.each_with_index do |book, j|
    # p "#{i} #{book} #{bit[j]}"
    if bit[j] == 1
      price += book[0]
      (1..m).each{|j| understanding[j-1] += book[j]}
    end
  end
#   p "#{price} #{understanding}"
  if understanding.all?{|r| r >= x}
    check << price
  end
end

if check.empty? 
  puts -1 
else
  puts check.min
end


Measured memory_bytes: 14344
#include<stdio.h>
int main(void){
	int H,W,i,j;
	while(1){
		scanf("%d %d",&W,&H);
		if(W==0&&H==0){
			break;
		}
		for(i=0;i<H;i++){
			printf("#");
		}
		printf("\n");
		for(i=0;i<W-2;i++){
			printf("#");
			for(j=0;j<H-2;j++){
				printf(".");
			}
				printf("#\n");
		}
		for(i=0;i<H;i++){
			printf("#");
		}
		printf("\n");
		printf("\n");
		}
	return 0;
}

Measured memory_bytes: 588
#include <bits/stdc++.h>
using namespace std;
static const long long MOD = 1000000000+7;

int main() {
  int n;
  cin >> n;
  vector<int> p(n),q(n),init(n);
  for (int i=0; i<n; i++) {
    cin >> p.at(i);
  }
  for (int i=0; i<n; i++) {
    cin >> q.at(i);
  }

  for (int i=0; i<n; i++) {
    init.at(i) = i+1;
  }


  auto check = [&](auto a, auto b){
    for (int i=0; i<n; i++) {
      if (a.at(i) != b.at(i)) return true;
    }
    return false;
  };

  int ans,cp=0,cq=0;
  while (check(init, p)) {
    cp++;
    next_permutation(init.begin(),init.end());
  }

  for (int i=0; i<n; i++) {
    init.at(i) = i+1;
  }

  while (check(init,q)) {
    cq++;
    next_permutation(init.begin(), init.end());
  }

  ans = abs(cp-cq);


  // cout << cp << " " << cq << endl;
  cout << ans << endl;
}


Measured memory_bytes: 256
n = int(input())
hl = list(map(int,input().split()))

dp = [[] for _ in range(n)]
dp[0] = 0
dp[1] = abs(hl[1] - hl[0])

for i in range(2,n):
    dp[i] = min(dp[i-1] + abs(hl[i]-hl[i-1]), dp[i-2] + abs(hl[i]-hl[i-2]))
    
print(dp[-1])

Measured memory_bytes: 20620
#include<bits/stdc++.h>
using namespace std;
bool Palindrome(string s) {
	string a=s;
	string b;
	for(int i=0;i<s.size();i++) {
		if(s[i]!=s[s.size()-i-1]) return false;
	}
	return true;
}
int main() {
	string a,b,c;
	cin>>a;
	int n;
	n=((a.size()-1)/2);
	b=a.substr(0,n);
	c=a.substr(n+1,n);
	if(Palindrome(a) && Palindrome(b) && Palindrome(c)) cout<<"Yes"<<endl;
	else cout<<"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++)

int tile[140][140];
using vpii = vector<pair<int,int>>;
int dx[] = {1,-1,0,0,-1,1};
int dy[] = {1,-1,1,-1,0,0};


int main()
{
  int t,n;
  while(cin >> t >> n,t+n){
    REP(i,140){
      REP(j,140){
        tile[i][j] = 0;
      }
    }
    vpii pii;
    REP(i,n){
      int c,k;
      cin >> c >> k;
      pii.push_back({k,c});
    }
    int sx,sy;
    cin >> sx >> sy;
    tile[70][70] = 1;
    for(auto x : pii){
      tile[x.first-sy+70][x.second-sx+70] = 2;
    }
    REP(_t,t){
      REP(i,140){
        REP(j,140){
          if(tile[i][j] == 1){
           REP(k,6){
            auto ny = max(0,min(139,i + dy[k]));
            auto nx = max(0,min(139,j+dx[k]));
            if(tile[ny][nx]==0){
              tile[ny][nx] = -1;
            }
           }
          }
        }
      }
      REP(i,140){
        REP(j,140){
          if(tile[i][j]==-1){
            tile[i][j] = 1;
          }
        }
      }
    }
    int ans = 0;
    REP(i,140){
      REP(j,140){
        if(tile[i][j]==1){
          ans++;
        }
      }
    }
    cout << ans<< endl;
  }

}

Measured memory_bytes: 3184
#include <vector>
#include <set>
#include <cmath>
#include <iostream>
#include <algorithm>

typedef char                SINT8;
typedef unsigned char       UINT8;
typedef short               SINT16;
typedef unsigned short      UINT16;
typedef int                 SINT32;
typedef unsigned int        UINT32;
typedef long long           SINT64;
typedef unsigned long long  UINT64;
typedef double              DOUBLE;

#define MAX(a,b) ((a)>(b)?(a):(b))
#define MIN(a,b) ((a)<(b)?(a):(b))
#define ABS(a) ((a)>(0)?(a):-(a))
#define REP(i,n) for(int (i)=0;(i)<(n);(i)++)

using namespace std;

int main() {

	SINT32 N = 0;
	cin >> N;

	set<SINT32> DATA;
	
	for (SINT32 i = 0; i < N; i++) {
		SINT32 buf;
		cin >> buf;
		DATA.insert(buf);
	}


	cout << DATA.size() << endl;
	return 0;
}

//	sort(DATA.begin(),DATA.end());
//	sort(DATA.begin(),DATA.end(),std::greater<SINT32>());
//	__gcd(ANS,DATA[i]);

//	// DATA.emplace_back(BUF);	//後ろに追加

//  DATA.erase(std::unique(DATA.begin(), DATA.end()), DATA.end());

//	DATA.insert(DATA.begin() + X, 0);	//X番目の要素に0を挿入


//	vector<vector<SINT32>> DP(N,vector<SINT32>(3));　//2次元配列

/*
	SINT32 M = 3;
	vector<pair<SINT32,SINT32>> DATA2(M);
	for (SINT32 i = 0; i < M; i++) {
		cin >> DATA2[i].first;
		cin >> DATA2[i].second;
	}
	sort(DATA2.begin(),DATA2.end());
	cout << DATA2[0].first << endl;
	cout << DATA2[0].second << endl;
*/

// 	vector<pair<int,pair<int,int>>> DATA(M);
//	cin >> DATA[i].first;
//	cin >> DATA[i].second.first;
//	cin >> DATA[i].second.second;


//		APOSI = lower_bound(ADATA.begin(),ADATA.end(),QDATA[i]) - ADATA.begin();
//		BPOSI = lower_bound(BDATA.begin(),BDATA.end(),QDATA[i]) - BDATA.begin();


/* 文字列回転
	string N;
	cin >> N;
	N = N[N.length()-1] + N.substr(0,N.length()-1);
*/

Measured memory_bytes: 256
package main

import (
  "fmt"
)

func max(a, b int) int {
  if a > b {
    return a
  }
  return b
}

func main() {
  var n int
  fmt.Scan(&n)
  
  S := 0
  M := 0
  for i := 0; i < n; i ++ {
    var p int
    fmt.Scan(&p)
    S += p
    M = max(M, p)
  }
  var ans = S - M/2
  fmt.Println(ans)
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define rep(i,a,...) for(int i = (a)*(strlen(#__VA_ARGS__)!=0);i<(int)(strlen(#__VA_ARGS__)?__VA_ARGS__:(a));++i)
#define per(i,a,...) for(int i = (strlen(#__VA_ARGS__)?__VA_ARGS__:(a))-1;i>=(int)(strlen(#__VA_ARGS__)?(a):0);--i)
#define foreach(i, n) for(auto &i:(n))
#define pii pair<int, int>
#define pll pair<long long, long long>
#define all(x) (x).begin(), (x).end()
#define bit(x) (1ll << (x))
#define method(name,res,...) function<res (__VA_ARGS__) > name = [&](__VA_ARGS__) -> res
using ll = long long;
//const ll MOD = (ll)1e9+7;
const ll MOD = 998244353;
const int INF = (ll)1e9+7;
const ll INFLL = (ll)1e18;
using namespace std;
template<class t>
using vvector = vector<vector<t>>;
template<class t>
using vvvector = vector<vector<vector<t>>>;
template<class t>
using priority_queuer = priority_queue<t, vector<t>, greater<t>>;
template<class t, class u> bool chmax(t &a, u b){if(a<b){a=b;return true;}return false;}
template<class t, class u> bool chmin(t &a, u b){if(a>b){a=b;return true;}return false;}
#ifdef DEBUG
#define debug(x) cout<<"LINE "<<__LINE__<<": "<<#x<<" = "<<x<<endl;
#else
#define debug(x) (void)0
#endif

namespace templates{
  ll modpow(ll x, ll b){
    ll res = 1;
    while(b){
      if(b&1)res = res * x % MOD;
      x = x * x % MOD;
      b>>=1;
    }
    return res;
  }

  ll modinv(ll x){
    return modpow(x, MOD-2);
  }

  bool was_output = false;
  template<class t>
  void output(t a){
    if(was_output)cout << " ";
    cout << a;
    was_output = true;
  }
  void outendl(){
    was_output = false;
    cout << endl;
  }
  ll in(){
    ll res;
    scanf("%lld", &res);
    return res;
  }

  template<class t>
  istream& operator>>(istream&is, vector<t>&x){
    for(auto &i:x)is >> i;
    return is;
  }

  template<class t, class u>
  istream& operator>>(istream&is, pair<t, u>&x){
    is >> x.first >> x.second;
    return is;
  }

  template<class t>
  void in(t&x){
    cin >> x;
  }

  template<class t>
  t in(){
    t res; cin >> res; return res;
  }

  template<class t>
  void out(t x){
    cout << x;
  }

  template<class t>
  vector<t> sorted(vector<t> line,function<bool(t,t)> comp=[](t a,t b){return a<b;}){
    sort(line.begin(),line.end(),comp);
    return line;
  }

  template<class t>
  vector<t> reversed(vector<t> line){
    reverse(line.begin(),line.end());
    return line;
  }
}

using namespace templates;

ll func(ll n,ll m){
  vector<pll> line(n);
  foreach(i,line)i=in<pll>();
  sort(all(line),[](pll x,pll y){return x.second>y.second;});
  ll res = 0;
  foreach(i,line){
    ll use = min(m,i.first);
    res += (i.first-use) * i.second;
    m -= use;
  }
  return res;
}

int main(){
  int n;
  int m;
  while(cin>>n>>m&&n){
    cout << func(n,m) << endl;
  }
  return 0;
}



Measured memory_bytes: 3172
'use strict'

const main = (input) => {
    input = input.split('\n')
    const words = input.slice(1, parseInt(input[0]) + 1)

    if(words.length !== [...new Set(words)].length){
        console.log('No')
        return
    }
    
    let last = ''
    let say = 'Yes'
    words.forEach((v, i) => {
        if(i === 0){
            last = v.split('').pop()
            return
        }
        let char = v.split('')
        let first = char[0]
        if(first !== last) {
            say = 'No'
            return 
        }
        last = char.pop()
    })
    console.log(say)
}

main(require('fs').readFileSync('/dev/stdin', 'utf-8'))

Measured memory_bytes: 21956
package main

import (
	"fmt"
	"bufio"
	"os"
	"strconv"
	//"strings"
)

var stdin = initStdin()
 
func initStdin() *bufio.Scanner {
	bufsize := 1 * 1024 * 1024
	var stdin = bufio.NewScanner(os.Stdin)
	stdin.Buffer(make([]byte, bufsize), bufsize)
	stdin.Split(bufio.ScanWords)
	return stdin
}

func scanInt() int {
	stdin.Scan()
	i, _ := strconv.Atoi(stdin.Text())
	return i
}

func scanStr() string {
	stdin.Scan()
	return stdin.Text()
}

type ia []int

func (ia ia)Len() int {
	return len(ia)
}
func (ia ia)Swap(i, j int) {
	ia[i], ia[j] = ia[j], ia[i]
}
func (ia ia)Less(i, j int) bool {
	return ia[i] < ia[j]
}

func main() {
	n := scanInt()
	p := make([]int, n)
	ans := 0
	for i := 0; i < n; i++ {
		p[i] = scanInt()
	}
	for i := 0; i < n-2; i++ {
		if (p[i] < p[i+1] && p[i+1] < p[i+2]) || (p[i] > p[i+1] && p[i+1] > p[i+2]) {
			ans++
		}
	}
	fmt.Println(ans)
}

Measured memory_bytes: 640
/*you will be given an array of coins and an amount of total money.you have to say that if it is possible to make it using the coins of array no more than one time.*/
 #include<bits/stdc++.h>
 using namespace std;
 #define ll long long 
 #define maxsz 1000
 #define pb push_back
 ll n;
 ll parent[500005];
 ll power[500005];
 vector<ll>frnd[500005];
 vector<ll>blk[500005];
 ll power2[500005];
 void initialize(){
   for(ll i=1;i<=n;i++){
     parent[i]=i;
   }
 }
 ll find_parent(ll a){
   while(a!=parent[a])
    a=parent[a];
    return a;
 }
 void make_union(ll a,ll b){
   ll parent1=find_parent(a);
   ll parent2=find_parent(b);
   if(power[parent1]>=power[parent2]){
     parent[parent2]=parent1;
     power[parent1]++;
   }
   else{
     parent[parent1]=parent2;
     power[parent2]++;
   }
 }
 int main(){
   ll m,i,j,k,l,u,v;
   scanf("%lld%lld%lld",&n,&m,&k);
   initialize();
   for(i=1;i<=m;i++){
     scanf("%lld%lld",&u,&v);
     frnd[u].pb(v);
     frnd[v].pb(u);
     make_union(u,v);
   }
   for(i=1;i<=k;i++){
     scanf("%lld%lld",&u,&v);
     blk[u].pb(v);
     blk[v].pb(u);
   }
   for(i=1;i<=n;i++){
     ll parentx=find_parent(i);
     ///cout<<parentx<<" ";
     parent[i]=parentx;
     power2[parentx]++;
   }
   for(i=1;i<=n;i++){
     ll cnt=0;
     ll sz=frnd[i].size();
     cnt=sz;
     sz=blk[i].size();
      for(j=0;j<sz;j++){
       if(parent[blk[i][j]]==parent[i])
         cnt++;
     }
     printf("%lld ",power2[parent[i]]-cnt-1);
   }
 }

Measured memory_bytes: 37120
#include <bits/stdc++.h>
#define all(a) (a).begin(), (a).end()
#define REP(i, n) for(int (i)=0; (i)<(n); (i)++)
#define RREP(i, n) for(int (i)=(n)-1, (i)>=0; (i)--)
#define ios() cin.tie(0), ios::sync_with_stdio(false)
typedef long long ll;
typedef unsigned long long ull;
ll const MOD = 1e9+7;
ll const INF = 1e18;
using namespace std;

int main(){
    int n, m;
    cin >> n >> m;
    vector<vector<char>> a(n, vector<char>(n)), b(m, vector<char>(m));
    for(auto& i : a){
        for(auto& j : i){
            cin >> j;
        }
    }
    for(auto& i : b){
        for(auto& j : i){
            cin >> j;
        }
    }
    for(int i=0; i+m-1<n; i++){
        for(int j=0; j+m-1<n; j++){
            bool flag = true;
            REP(ii, m){
                REP(jj, m){
                    flag &= (b[ii][jj] == a[i+ii][j+jj]);
                }
            }
            if(flag){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 256
n = input()
_list = input().split(" ")
_list = [int(x) for x in _list]
even = [x for x in _list if x % 2==0]
answer = []
for x in even:
    if x % 3 == 0 or x % 5 == 0:
        answer.append(True)
if len(even) ==len(answer):
    print("APPROVED")
else:
    print("DENIED")


Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define INF 9223372036854775807LL
#define inf 1000000007
#define lol long long
#define abs(x,y) (max(x,y)-min(x,y))
#define mp make_pair
#define fi first
#define se second
using namespace std;
lol a,b,c;
int x[100001],y[100001];
signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  lol d=0,e=0,f=0;
  string s;
  cin >>a;
  b=a/100;
  c=b*5;
  if(a%100==0||a%100-c<=0) cout <<1<<'\n';
  else cout <<0<<'\n';
  return 0;
}


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

int main()
{
  string s1,s2,u;
  int a,b;
  map<string,int>m;
  cin>>s1>>s2;
  cin>>a>>b>>u;
  m[s1]=a,m[s2]=b;
  m[u]--;
  cout<<m[s1]<<" "<<m[s2];
    return 0;
}


Measured memory_bytes: 256
//package gfg;

import java.io.BufferedReader;
import java.io.InputStreamReader;

public class Main {

	public static void main(String[] args) throws Exception {
		BufferedReader br=new BufferedReader(new InputStreamReader(System.in));
		
			String[] s=br.readLine().split(" ");
			int l=Integer.parseInt(s[0].trim());
			int r=Integer.parseInt(s[1].trim());
			int d=Integer.parseInt(s[2].trim());
			int res=0;
			for(int i=l;i<=r;i++) {
				if(i%d==0) {
					res++;
				}
			}
			
			System.out.println(res);
			
	}

}


Measured memory_bytes: 32724
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<math.h>
#include<stdlib.h>
#include<string>
#include<iostream>
#include<set>
#include<map>
#include<deque>
using namespace std;
typedef long long ll;
typedef pair<ll, ll>pii;
typedef pair<pii, ll>pi3;
ll mod = 1000000007;
char a[50][50], b[50][50];
int main()
{
	string s;
	cin >> s;
	printf("%c%d%c\n", s[0], s.size() - 2, s[s.size() - 1]);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for (int i=0; i<(n); ++i)
#define per(i,n) for (int i=n-1; i>=0; --i)
#define all(a) a.begin(), a.end()
#define rall(a) a.rbegin(), a.rend()
using namespace std;
using ll = long long;
using P  = pair<int,int>;
using vi = vector<int>;
using vv = vector<vi>;
const int mod = 1000000007;
//const int mod = 998244353;

ll dp[2001][2001];

int main(){
    int n;
    cin >> n;
    vector<P> a(n);
    rep(i,n){
        cin>>a[i].first;
        a[i].second = i;
    }
    sort(rall(a));
    //rep(i,n)cout<<a[i].first<<endl;
    
    for(int i=1; i<=n; i++){
        for(int x=0; x<=i; x++){
            
            int y = i-x;
            ll  c = a[i-1].first;
            ll  p = a[i-1].second;
            if(x)dp[x][y] = max(dp[x][y], dp[x-1][y] + c*(p-(x-1)));
            if(y)dp[x][y] = max(dp[x][y], dp[x][y-1] + c*((n-y)-p));
        }
    }
    ll ans = 0;
    rep(i,n+1){
        ans = max(ans, dp[i][n-i]);
    }
    
    cout << ans << endl;
    
    return 0;
}

Measured memory_bytes: 26156
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < int(n); i++)
using namespace std;
using ll = long long;
const int INF = (1<<30)-1;
const long long LINF = (1LL<<62)-1;
const int dx[] = {-1, 0, 1, 0};
const int dy[] = {0, 1, 0, -1};
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int x;
  cin >> x;
  vector<pair<ll, ll>> v;
  for (ll i = 1; pow(i, 5) < 1e17; i++) {
    ll num = pow(i, 5);
    v.push_back({num, i});
  }
  for (ll a = 0; ; a++) {
    ll a5 = pow(a, 5);
    if (a5 <= x) {
      auto it = lower_bound(v.begin(), v.end(), make_pair(x-a5, 0LL));
      if (it->first == x-a5) {
        ll b = -(it->second);
        cout << a << ' ' << b << endl;
        return 0;
      }
    } else {
      auto it = lower_bound(v.begin(), v.end(), make_pair(a5-x, 0LL));
      if (it->first == a5-x) {
        ll b = it->second;
        cout << a << ' ' << b << endl;
        return 0;
      }
    }
  }
  return 0;
}

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

int n;

int main(){
//	cin.tie(0);
//	ios::sync_with_stdio(false);
	cin >> n;
	for(int i=2; i<=10010; ++i){
		if(i*(i-1)/2 == n){
			cout << "Yes\n";
			cout << i << "\n";
			vector<int> v[i];
			int t = 1;
			for(int j=1; j<=i; ++j){
				for(int k=j+1; k<=i; ++k){
					v[j-1].push_back(t);
					v[k-1].push_back(t);
					++t;
				}
			}
			for(int j=0; j<i; ++j){
				cout << v[j].size() << " ";
				for(int k=0; k<v[j].size(); ++k)
					cout << v[j][k] << (k+1 == v[j].size() ? "\n" : " ");
			}
			return 0;
		}
	}
	cout << "No\n";
}

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

int main(){
	int a;
	int b;
	cin >> a >> b;
	int y;
	int x = max(a, b);
	
	if (x == a){
		y = max(a-1, b);
	}else{
		y = max(a, b-1);
	}

	cout << x + y << endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cctype>

using namespace std;

string maxs(string a, string b){
    if(a.size()>b.size()) return a;
    if(a.size()<b.size()) return b;
    for(int i=0;i<a.size();i++){
        if(a[i] > b[i]) return a;
        if(a[i] < b[i]) return b;
    }
    return a;
}

int main(void){
  int w,h;
  string grid[71],dp[71][71];

  while(cin >> w >> h,w|h){
    for(int i=0;i<71;i++)
      for(int j=0;j<71;j++)dp[i][j].clear();

    for(int i=0;i<h;i++)cin >> grid[i];

    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	if(!isupper(grid[i][j])){
	  dp[i][j]=grid[i][j];
	  string a="",b="";
	  if(i>0 && !dp[i-1][j].empty())a=dp[i-1][j]+grid[i][j];
	  if(j>0 && !dp[i][j-1].empty())b=dp[i][j-1]+grid[i][j];
	  
	  while(a[0]=='0') a.erase(a.begin());
	  while(b[0]=='0') b.erase(b.begin());

	  dp[i][j]=maxs(dp[i][j],maxs(a,b));
	}
      }
    }

    string s="";
    for(int i=0;i<h;i++){
      for(int j=0;j<w;j++){
	s=maxs(s,dp[i][j]);
      }
    }
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 1376
#include <cstdio>
#include <vector>
using namespace std;
using ll = long long int;
const ll MOD = 1000000007;

ll mod_pow(ll x, ll n) {
    if(n == 0) return 1;
    ll res = mod_pow((x * x) % MOD, n / 2);
    if(n & 1) res = (res * x) % MOD;
    return res;
}

// 階乗 mod p
vector<ll> fact;
void fact_mod(int n) {
    fact.resize(n+1);
    fact[0] = 1;
    for(int i=0; i<n; i++) {
        fact[i+1] = (fact[i] * (i+1)) % MOD;
    }
}

// 階乗の逆元 mod p
vector<ll> finv;
void fact_inv(int n) {
    finv.resize(n+1);
    finv[n] = mod_pow(fact[n], MOD-2);
    for(int i=n-1; i>=0; i--) {
        finv[i] = (finv[i+1] * (i+1)) % MOD;
    }
}

// fact, finv を使って組み合わせを出す
// 基本的にはこれを使ったほうがいい
ll combination_array(int n, int r) {
    if(n < 0 || r < 0 || n < r) return 0;
    ll x = fact[n];
    ll y = (finv[r] * finv[n-r]) % MOD;

    return (x * y) % MOD;
}

ll combination_duplicate(int x, int y) {
    return combination_array(x+y-1, y);
}

const int M = 6000010;
int main() {
    fact_mod(M);
    fact_inv(M);

    while(1) {
        ll A, B, C, X, Y; scanf("%lld%lld%lld%lld%lld", &A, &B, &C, &X, &Y);
        if(A + B + C + X + Y == 0) break;

        ll ans = 0;
        // diff を決め打ち
        for(int D = 0; D <= X+Y; D++) {
            int free_pt = (X+Y-D) / 2, S = A+B+C;
            if( (X+Y-D) % 2 == 1 ) continue;
            if(free_pt > X || free_pt > Y) continue;

            // 差分以外の点数を適当に配置
            ll add = combination_duplicate(S, free_pt);

            // 引き分けの位置
            (add *= combination_array(S, C)) %= MOD;

            // 勝ちの位置
            (add *= combination_array(A+B, A)) %= MOD;

            // P, Q の計算 (それぞれ A 以上・B 以上でなければならない)
            int P = X - free_pt, Q = Y - free_pt;

            if(P < A || Q < B) continue;
            if(A == 0 && P > 0) continue;
            if(B == 0 && Q > 0) continue;
            P -= A, Q -= B;
            if(A > 0) (add *= combination_duplicate(A, P)) %= MOD;
            if(B > 0) (add *= combination_duplicate(B, Q)) %= MOD;

            (ans += add) %= MOD;
            // printf("D = %d, add = %lld\n", D, add);
        }
        printf("%lld\n", ans);
    }
    return 0;
}


Measured memory_bytes: 95900
#include <iostream>
#include <vector>
#include <algorithm>
#define MOD 1000000007
using ll = long long;
using namespace std;

int main() {
	int N, M, Q;
	cin >> N >> M >> Q;
	vector<vector<int>> x(N, vector<int>(N,0)), dp(N, vector<int>(N, 0));
	for (int i = 0; i < M; i++)
	{
		int L, R;
		cin >> L >> R;
		L--; R--;
		x[L][R]++;
	}
	dp[0][0] = x[0][0];
	for (int i = 0; i < N-1; i++)
	{
		dp[0][i + 1] = dp[0][i] + x[0][i + 1];
		dp[i + 1][0] = dp[i][0] + x[i + 1][0];
	}
	for (int i = 0; i < N-1; i++)
	{
		for (int j = 0; j < N-1; j++)
		{
			dp[i + 1][j + 1] = dp[i][j + 1] + dp[i + 1][j] - dp[i][j] + x[i + 1][j + 1];
		}
	}
	for (int j = 0; j < Q; j++)
	{
		int p, q;
		cin >> p >> q;
		p--; q--;
		if (p > 0) {
			cout << dp[q][q] - dp[q][p - 1] - dp[p - 1][q] + dp[p - 1][p - 1] << endl;
		}
		else {
			cout << dp[q][q] << endl;
		}
	}
	cin >> N;
	return 0;
}

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

int heaps[2000000], h = 0;

void heapify(int a[], int i) {
  int largest, b;
  int l = i * 2;
  int r = i * 2 + 1;

  if (l <= h && a[l] > a[i])
    largest = l;
  else
    largest = i;
  if (r <= h && a[r] > a[largest])
    largest = r;

  if (largest != i) {
    b = a[i];
    a[i] = a[largest];
    a[largest] = b;
    heapify(a, largest);
  }
}

void maxheap(int a[], int i, int parent) {
  int b;
  while (i > 1 && a[i] > a[i / 2]) {
    b = a[i];
    a[i] = a[i / 2];
    a[i / 2] = b;
    i = i / 2;
  }
}

void insert(int a[], int key, int i) {
  int parent;
  a[i] = key;
  parent = i / 2;

  maxheap(a, i, parent);
}

int extract(int a[], int i) {
  int parent;
  int max = a[1];
  a[1] = a[i];
 
  return max;
}

int main(void) {
  int key;
  char order[10];

  while (1) {
    scanf("%s", order);
    if (strcmp(order, "insert") == 0) {
      scanf("%d", &key);
      h++;
      insert(heaps, key, h);
    }
    else if (strcmp(order, "extract") == 0) {
      printf("%d\n", extract(heaps, h));
      h--;
      heapify(heaps, 1);
    }
    else
      break;
  }

  return 0;
}



Measured memory_bytes: 5640
import math
line = input().split(" ")
A = int(line[0])
B = int(line[1])
C = int(line[2])

W = C//(7*A+B)
remain = C - (7*A+B)*W
#print(W, " ", remain)
D = 0
if(remain >= 7*A):
    D = 7 
else:
    D = math.ceil(remain/A)

ans = 7*W + D

print(ans)


Measured memory_bytes: 5664
#include <stdio.h>
int main(void){
 int n,i,c=0;
 scanf("%d",&n);
 int l[1000];
 int r[1000];
 for(i=0;i<n;i++){
  scanf("%d%d",&l[i],&r[i]);
  c=c+r[i]-l[i]+1;
 }
 printf("%d",c);
 return 0;
}

Measured memory_bytes: 128
import java.util.Scanner;

public class Main{
	public static int count;

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		for(int i = 0;i < n; i++){
			int num = sc.nextInt();
			solve(num);
		}

		System.out.println(count);

	}

	public static void solve(int num){
		if(num == 1){
			return;
		}
		else if(num == 2){
			count++;
			return;
		}
		else if(num % 2 == 0){
			return;
		}
		else{
			for(int i = 3;i <= Math.sqrt(num); i++){
				if(num % i == 0){
					return;
				}
			}
		}
		count++;
	}

}

Measured memory_bytes: 41052
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 ans = 0;
        for (int i = 1 ; i <= N ; i++) {
            int x = sc.nextInt();
            ans += Math.min(x, K - x) * 2;
        }
        System.out.println(ans);
    }

}

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

int main(){
  long long n;

  cin >> n;


  switch(n%10) {
    case 2:
    case 4:
    case 5:
    case 7:
    case 9:
      cout << "hon" << endl;
      break;
    case 0:
    case 1:
    case 6:
    case 8:
      cout << "pon" << endl;
      break;
    case 3:
      cout << "bon" << endl;
      break;
  }

  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
using namespace std;
using ll = long long;
using P = pair<int,int>;
//入力
int n;
//DPテーブル
ll dp[100100][3]; //dp[i][j]:
ll a[100100], b[100100], c[100100];


int main() {
  //input
  cin >> n;
  for(int i = 1; i <= n; ++i) cin >> a[i] >> b[i] >> c[i];

  //DPの初期化 もともと0で初期化されているから
  dp[0][0] = 0;
  dp[0][1] = 0;
  dp[0][2] = 0;

  //DPループ
  for(int i = 1; i <= n; ++i){

    dp[i][0] = max(dp[i-1][1], dp[i-1][2]) + a[i];
    dp[i][1] = max(dp[i-1][2], dp[i-1][0]) + b[i];
    dp[i][2] = max(dp[i-1][0], dp[i-1][1]) + c[i];
  }

  int ans = max({dp[n][0], dp[n][1], dp[n][2]});
  cout << ans << endl;
}


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

int main(){

  int a,b;
  char op;
  while(1){
    scanf("%d %c %d",&a,&op,&b);
    if(op == '+'){
      printf("%d\n",a+b);
    }
    if(op == '-'){
      printf("%d\n",a-b);
    }
    if(op == '*'){
      printf("%d\n",a*b);
    }
    if(op == '/'){
      printf("%d\n",a/b);
    }
    if(op == '?'){
      break;
    }
  }
  //  printf("%lf %lf\n",3.1415926535*r*r,2*r*3.1415926535);
  return 0;
}

Measured memory_bytes: 600
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <algorithm>
#include <string>

using namespace std;
typedef long long ll;

int main(int argc, char *argv[]) {
  int n, x;
  cin>>n>>x;
  std::vector<int> v(n);
  int left = x;
  int mn = 10000;
  for (int i = 0; i < n; i++)  {
    cin>>v[i];
    x -= v[i];
    mn = min(v[i], mn);
  }
  int ans = n + (x/mn);
  cout << ans <<endl;
  return 0;
}


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


int GCD( int X, int Y )
{
	while( true )
	{
		X %= Y;
		if( X == 0 ) return Y;

		Y %= X;
		if( Y == 0 ) return X;
	}
}



int main()
{
int i;
int N;
int A;
int X;

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

	cin >> N;
	cin >> X;

	for( i = 1; i < N; i++ )
	{
		if( X == 1 )
		{
			cout << 1 << endl;

			return 0;
		}

		cin >> A;

		X = GCD( A, X );
	}

	cout << X << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define cout16 cout << setprecision(16) 
#define rep(i,n) for(int i=0;i<n;i++ )
#define rep2(i,f,n) for(int i=f;i<n;i++ )
#define SORT(A) sort(A.begin(),A.end())
#define REV(A) reverse(A.begin(),A.end())
typedef long long int ll;
using vi = std::vector<int>;
using vvi = std::vector<std::vector<int>>;
using vll = std::vector<ll>;
using vvll = std::vector<std::vector<ll>>;
using P = std::pair<int,int>;
using vp = std::vector<P>;
using namespace std;
#define INF 1001001001
#define LL_INF 1001001001001001001
#define fi first
#define se second

int main(void) {
	int n; cin >> n;
	rep(i,n+1){
		int x = i*1.08;
		if(x==n){
			cout << i << endl;
			return 0;
		}
	}
	cout << ":(" << endl;
}


Measured memory_bytes: 256
from sys import stdin
input = stdin.readline
n = int(input())
a = []
for _ in range(n):
    a.append(list(map(int,input().split())))
b = [[0,0,0] for _ in range(n)]
b[0][0]=a[0][0]
b[0][1]=a[0][1]
b[0][2]=a[0][2]
for i in range(n-1):
    for j in range(3):
        if j==0:
            b[i+1][j] = max(a[i+1][j]+b[i][1],a[i+1][j]+b[i][2])
        if j==1:
            b[i+1][j] = max(a[i+1][j]+b[i][0],a[i+1][j]+b[i][2])
        if j==2:
            b[i+1][j] = max(a[i+1][j]+b[i][1],a[i+1][j]+b[i][0])
print(max(b[-1]))

Measured memory_bytes: 47320
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define rep(i,n)   FOR(i,0,n)
#define pb emplace_back
typedef long long ll;
typedef pair<int,int> pint;

ll s[3001];
vector<ll> v;
int main(){
    ll n,m,k,a,b,c,t;
    cin>>n>>m>>k;
    cin>>a>>b>>c>>t;
    rep(i,m){
        cin>>s[i];
        --s[i];
    }
    int r=k-m;
    ll ans=(s[m-1]*b<=t)?1:0;
    rep(i,m-1){
        ll cur=b*s[i];
        if(cur>t) break;
        ll cnt=(t-cur)/a+1;
        ans+=min(s[i+1]-s[i],cnt);
        cur+=(cnt)*c;
        if(cur>t) continue;
        rep(j,r){
            ll cnt2=(t-cur)/a+1;
            ll ss=min(s[i]+cnt+cnt2,s[i+1])-min(s[i]+cnt,s[i+1]);
            v.pb(ss);
            cur+=(cnt2)*c;cnt+=cnt2;
            if(cur>t) break;
        }
    }
    sort(v.rbegin(),v.rend());
    int cnt=0;
    for(auto it:v){
        if(cnt==k-m) break;
        ans+=it;++cnt;
    }
    cout<<ans-1<<endl;
    return 0;
}


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

int main(){
	string S;
	string tmp;
	while(getline(cin,tmp)){
		//cout<<tmp<<endl;
		if(tmp=="\0")break;
		S+=tmp;
	}
	for(int i=0;i<S.length();++i){
		if(S[i]>='A' && S[i]<='Z')S[i]+=0x20;
	}
	map<char,int>num;
	for(int i=0;i<S.length();++i){
		if(S[i]>='a' && S[i]<='z')num[S[i]]++;
	}
	for(int i=0;i<26;++i){
		cout<<(char)('a'+i)<<" : "<<num[(char)'a'+i]<<endl;
	}
}


Measured memory_bytes: 3172
#include "bits/stdc++.h"
using namespace std;
int main(){
    int n,i,a,odd=0,even=0,all=1,ex=1;
    cin >> n;
    for(i=0;i<n;i++){
        cin >> a;
        if(a%2) odd++;
        else even++;
    }
    for(i=0;i<n;i++){
        all *= 3;
        if(i<even)ex*=2;
    }
    cout << all-ex << endl;
    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <bits/stdc++.h>
#include <algorithm>
#include <map>
#include <unordered_map>
#include <deque>
#include <tuple>
#include <unordered_set>
#include <array>
#include <string>

using namespace std;
#define ll long long
#define ar array
const int mxN=1e3;
int n, m, si, sj, ei, ej;
string grid[mxN];
queue<ar<int, 2>> q;

bool dfs(int i, int j) {
	if (i<0||j<0||i>=n||j>=m||grid[i][j]=='#') return 0;
	grid[i][j]='#';
	if (i==ei&&j==ej) return 1;
	for (int a=i-2; a<=i+2; a++)
		for (int b=j-2; b<=j+2; b++) {
			if (a<0||b<0||a>=n||b>=m||grid[a][b]=='#') continue;
			q.push({a, b});
		}
	return dfs(i-1, j)||dfs(i+1, j)||dfs(i, j-1)||dfs(i, j+1);
}

int main()
{   
	cin >> n >> m >> si >> sj >> ei >> ej;
	si--, sj--, ei--, ej--;
	for (int i=0; i<n; i++) cin >> grid[i];
	q.push({si, sj});
	int d=0;
	while (!q.empty()) {
		for (int l=q.size()-1; l>=0; l--) {
			ar<int, 2> curr=q.front(); q.pop();
			int i=curr[0], j=curr[1];
			if (grid[i][j]=='#') continue;
			bool res=dfs(i, j);
			if (res) {
				cout << d;
				return 0;
			}
		}
		d++;
	}
	cout << -1;
	return 0;
}

Measured memory_bytes: 5952
A, B, C = map(int, input().split())
K = int(input())
cnt = 0
if A>=B:
    for i in range(K):
        B = 2*B
        cnt += 1
        if A<B:
            break
if B>=C:
     for j in range(K-cnt):
        C = 2*C
if A<B and B<C:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 61652
from heapq import heapify, heappush, heappop
n = int(input())
A = list(map(int, input().split()))
heapify(A)
while len(A) != 1:
    t = heappop(A)
    A = [a % t for a in A if a % t != 0]
    if A is None:
        A = [t]
        break
    heappush(A, t)
print(A[0])


Measured memory_bytes: 14180
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))


p = 2019
s = input()[::-1]
res = 0
now = 0
d = [0] * p
d[0] = 1
for i,t in enumerate(s):
    now += int(t) * pow(10,i,p)
    now %= p
    d[now] += 1
for i in range(p):
    v = d[i]
    res += v*(v-1)//2
print(res)


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

const ll maxs = 1e5+5;
const ll lmaxs = 20;
ll mod = 1e9+7;
ll oo = 1e15;

#define IOS ios_base::sync_with_stdio(false);cin.tie(nullptr);cout.tie(nullptr);
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define I insert
#define endl '\n'

void pre(){
    
}

void solve(){
    ll k;
    cin >> k;
    ll a,b;
    cin >> a >> b;
    ll f= a/k*k;
    if(f < a)
        f += k;
    if(f >= a and f <= b)
        cout << "OK";
    else cout << "NG" ; 
}

int main(){
    IOS;
    pre();
    ll T = 1;
    //cin>>T;
    while(T--){
        solve();   
    }
    return 0;
}

Measured memory_bytes: 3648
class COM:
    def __init__(self, n: int, mod: int):
        self.n = n
        self.mod = mod
        self.fact = [0] * (n + 1)
        self.factinv = [0] * (n + 1)
        self.inv = [0] * (n + 1)
        
        self.fact[0] = self.fact[1] = 1
        self.factinv[0] = self.factinv[1] = 1
        self.inv[1] = 1
        for i in range(2, n + 1):
            self.fact[i] = (self.fact[i - 1] * i) % mod
            self.inv[i] = (-self.inv[mod % i] * (mod // i)) % mod
            self.factinv[i] = (self.factinv[i - 1] * self.inv[i]) % mod
    
    def get_cmb(self, n: int, k: int):
        if (k < 0) or (n < k):
            return 0
        k = min(k, n - k)
        return self.fact[n] * self.factinv[k] % self.mod * self.factinv[n - k] % self.mod


def solve():
    n, k = map(int, input().split())
    MOD = 10 ** 9 + 7
    
    com = COM(n, MOD)
    ans = 0
    for i in range(min(n, k + 1)):
        ans += com.get_cmb(n, i) * com.get_cmb(n - 1, i)
        ans %= MOD
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 26740
fn main() {
    let input = {
        use std::io::*;
        let mut input = String::new();
        let _ = stdin().read_to_string(&mut input);
        input.remove(4);
        input.remove(6);
        input.trim().parse::<i32>().unwrap()
    };
    println!("{}", if input <= 20190430 { "Heisei" } else { "TBD" });
}

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

//すべての入力を受け取ってソートし重複していないのを取る
int main() {
    vector<string> v;  
    int n,cnt=1;
    string str;
    int f = 0;
    cin >> n;
    
    for(int i=0; i<n; i++){
        cin >> str;
        v.push_back(str);
    }
    sort(v.begin(),v.end());
    for(int i=0; i<n-1; i++){
        if(v[i] != v[i+1]){
            cnt++;
        }
    }
    cout << cnt << endl;
}

Measured memory_bytes: 11580
#include<bits/stdc++.h>
using namespace std;
//#pragma comment(linker, "/STACK:102400000,102400000")
typedef long long ll;
typedef pair<int,int> P;
#define ls(x) (x<<1)
#define rs(x) (x<<1|1)
#define lowbit(x) (x&-x)
const ll INF=0x3f3f3f3f;
const double EPS=1e-7;
const int N=2e5+10;
const ll mod=1e9+7;
inline ll read()
{  ll f=1,x=0;char ch=getchar();
   for(;ch>'9'||ch<'0';ch=getchar())if(ch=='-') f=-1;
   for(;ch<='9'&&ch>='0';ch=getchar()) x=x*10+ch-'0';
   return x*f;
}
ll n,x,a[N];
map<int,ll>dp[N];
ll solve(int now,int cnt)
{  
   if((now+1)/2<cnt)return -INF*1000000;
   if(cnt==0||now<1)return 0;
   if(dp[now].count(cnt))return dp[now][cnt]; 
   return dp[now][cnt]=max(solve(now-2,cnt-1)+a[now],solve(now-1,cnt));
}
int main()
{  cin>>n;
   for(int i=1;i<=n;i++)cin>>a[i];
   cout<<solve(n,n/2);
}

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

struct node {
    int id;
    int parent = -1;
    int sibling = -1;
    int degree = 0;
    int depth;
    int height;
    string type;
    vector<int> children;
};

void checkDepth(vector<node> &tree, int idx, int dep) {
    if (tree.at(idx).parent != -1) {
        if (tree.at(idx).degree == 0) {
            tree.at(idx).depth = dep;
            tree.at(idx).type = "leaf";
            return;
        } else {
            tree.at(idx).depth = dep;
            tree.at(idx).type = "internal node";
        }
    }
    for (auto &x : tree.at(idx).children) {
        checkDepth(tree, x, dep + 1);
    }
    return;
}

void checkHeight(vector<node> &tree, int idx, int h) {
    tree.at(idx).height = max(tree.at(idx).height, h);
    if (tree.at(idx).parent != -1) {
        checkHeight(tree, tree.at(idx).parent, h + 1);
    }
    return;
}

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

    int n;
    cin >> n;
    vector<node> tree(n);
    for (int i = 0; i < n; ++i) {
        int idx;
        cin >> idx;
        tree.at(idx).id = idx;
        int left, right;
        cin >> left >> right;
        if (left != -1) {
            tree.at(idx).children.push_back(left);
            tree.at(left).parent = idx;
            tree.at(idx).degree++;
            if (right != -1) {
                tree.at(left).sibling = right;
            }
        }
        if (right != -1) {
            tree.at(idx).children.push_back(right);
            tree.at(right).parent = idx;
            tree.at(idx).degree++;
            if (left != -1) {
                tree.at(right).sibling = left;
            }
        }
    }
    for (int i = 0; i < n; ++i) {
        if (tree.at(i).parent == -1) {
            tree.at(i).depth = 0;
            tree.at(i).type = "root";
            checkDepth(tree, i, 0);
        }
        if (tree.at(i).degree == 0) {
            checkHeight(tree, i, 0);
        }
    }
    for (int i = 0; i < n; ++i) {
        cout << "node " << tree.at(i).id;
        cout << ": parent = " << tree.at(i).parent;
        cout << ", sibling = " << tree.at(i).sibling;
        cout << ", degree = " << tree.at(i).degree;
        cout << ", depth = " << tree.at(i).depth;
        cout << ", height = " << tree.at(i).height;
        cout << ", " << tree.at(i).type << endl;
    }

    return 0;
}


Measured memory_bytes: 3172
use std::io;

fn gets() -> String {
    let mut buf = String::new();
    io::stdin().read_line(&mut buf).ok();
    buf
}

fn main() {
    let line = gets();
    let mut it = line.trim().chars();
    let a = it.next().unwrap();
    let b = it.next().unwrap();
    let c = it.next().unwrap();
    let d = it.next().unwrap();
    if (a == b && b == c) || (b == c && c == d) {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
#include<cmath>
#define pb push_back
#define ld long double
#define mp make_pair
#define vl vector<ll> 
#define vd vector<double>
#define vld vector<long double>
#define ll long long int
#define pl pair<ll, ll>
#define all(a) a.begin(), a.end()
#define forr(i, n) for(ll i=0; i<n; i++) 
#define forr1(i, n) for(ll i=1; i<=n; i++)
using namespace std;
const ld PI =3.1415926535897923846;
const ll MOD = 1e9+7;
void solve()
{
    ll n;
    cin>>n;
    ll sum=0;
    for(ll i=1; i<=n; i++)
    {
        if(i%3==0||i%5==0)
        continue;
        sum+=i;
    }
    cout<<sum;
}
int main()
{
    ll test=1;
    //cin>>test;
    while(test--)
        solve();
}

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

  int main()
  {
    int n, max1=0, max2=0;
    bool is_continue = false;
    cin >> n;
    int h[n];
    rep(i, n) cin >> h[i];
    //左より右のほうが大きかったら数をカウントしていく
	rep(i, n - 1){
      if(h[i] >= h[i + 1])
        max1 += 1;
      //途中でカウントがストップしたら、別のカウンタをカウントアップしていく
      else if(h[i] < h[i + 1])
      { 
        max2 = max(max1, max2);
        max1 = 0;
      }
     // cout << max1 << " " << max2 << endl;
    }
    cout << max(max1, max2) << endl;
    return 0;
  }


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

int main(){
	while(1){
		string s1,s2;
		cin>>s1;
		if(s1==".")return 0;
		cin>>s2;
		string s11[201],s22[201];
		for(int i=0;i<201;i++){
			s11[i]=".";s22[i]=".";
		}
		s11[0]="";s22[0]="";
		int now1=0,now2=0;
		for(int i=0;i<(int)s1.length();i++){
			if(s1[i]=='"'){
				now1++;
				s11[now1]="";
			}else s11[now1]+=s1[i];
		}
		for(int i=0;i<(int)s2.length();i++){
			if(s2[i]=='"'){
				now2++;
				s22[now2]="";
			}else s22[now2]+=s2[i];
		}
		int d=0;
		for(int i=0;i<201;i++){
			if(s11[i]!=s22[i]){
				if(i&1){
					d++;
				}else d+=2;
			}
		}
		if(d==0)cout<<"IDENTICAL";
		else if(d==1)cout<<"CLOSE";
		else cout<<"DIFFERENT";
		cout<<"\n";
	}
}

Measured memory_bytes: 3176
#pragma comment(linker, "/STACK:102400000,102400000")
#include <bits/stdc++.h>
using namespace std;
#define vi vector<int>
#define pii pair<int,int>
#define pb push_back
#define mp make_pair
#define all(x) x.begin(),x.end()
#define SZ(x) (int)(x.size())
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=b-1;i>=a;i--)
#define inf 1000000007
#define mod 1000000007
#define x first
#define y second
#define pi acos(-1.0)
#define DBG(x) cerr<<(#x)<<"="<<x<<"\n";
//#define dprintf(...) 
#define hash _hash
#define next _next
//#define dprintf(...) fprintf(outFile,__VA_ARGS__)
 
#define FOREACH(it,x) for(__typeof(x.begin()) it=x.begin();it!=x.end();it++)
#define ull unsigned long long
#define ll long long
#define N 400010
 
template <class T,class U>inline void Max(T &a,U b){if(a<b)a=b;}
template <class T,class U>inline void Min(T &a,U b){if(a>b)a=b;}
 
//FILE* outFile;
inline void add(int &a,int b){a+=b;while(a>=mod)a-=mod;}


int pow(int a,int b){
    int ans=1;
    while(b){
        if(b&1)ans=ans*(ll)a%mod;
        a=(ll)a*a%mod;b>>=1;
    }
    return ans;
}


int ch[N][26],sz,cnt[N],w[N],pre[N],c[N],a[N],sum[26][26];
char s[N],t[26];
int add(string s,int id){
	int n=s.size(),p=0;
	rep(i,0,n){
		int j=s[i]-'a';
		if(!ch[p][j]){
			ch[p][j]=++sz;pre[sz]=p;c[sz]=j;
		}
		p=ch[p][j];cnt[p]++;
	}
	w[p]++;
	return p;
}
void cal(int p){
	while(p){
		rep(i,0,26)if(i!=c[p]){
			sum[i][c[p]]+=cnt[ch[pre[p]][i]];
		}
		sum[c[p]][c[p]]+=w[p];
		p=pre[p];
	}
}
struct node{
	string t;
	int id;
};
vector<node>q[N>>2];
int ans[N>>2];
int main(){
	int i,j,k,ca=0,n=0,m,K;
	scanf("%d",&n);
	rep(i,0,n){
		scanf("%s",s);
		a[i]=add(s,i);
	}
	scanf("%d",&m);
	rep(k,0,m){
		scanf("%d%s",&i,t);i--;
		q[i].pb((node){(string)t,k});
	}
	rep(i,0,n)if(SZ(q[i])){
		memset(sum,0,sizeof(sum));
		cal(a[i]);
		FOREACH(it,q[i]){
		int tot=0;
		rep(j,0,26){
			string &t=it->t;
			rep(k,j,26)tot+=sum[t[j]-'a'][t[k]-'a'];
		}
		ans[it->id]=tot;
		}
	}
	rep(i,0,m)printf("%d\n",ans[i]);
    return 0;
}




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

#define Int long long int
#define REP(i,n) for(int i=0;i<(n);i++)
#define REAP(i,a,n) for(int i=(a);i<(n);i++)
#define YES cout<<"Yes"<<endl
#define NO cout<<"No"<<endl
#define fr first
#define sc second
#define pb push_back
#define All(v) v.begin(),v.end()

int main(){
    int n,d,x;

    cin >> n >> d >> x;
    int sum=n;
    d--;
    int a;
    REP(i,n){
        cin >> a;
        sum+=d/a;
    }
    cout << sum+x << endl;
}


Measured memory_bytes: 256
#include<stdio.h>
int main()
{
	int n,m,a[100];
	int i,c=0;
	double x=0;
	scanf("%d %d",&n,&m);
	for(i=0;i<n;i++){
		scanf("%d",&a[i]);
		x+=a[i];
	}
	x=x/(4*m);
	for(i=0;i<n;i++){
		if(x<=a[i]){
			c++;
		}
	}
	if(m<=c){
		printf("Yes\n");
	}
	else{
		printf("No\n");
	}
	return 0;
}


Measured memory_bytes: 1636
#include<stdio.h>
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#include<functional>
 
 
#define rep(i,n) for(int i=0;i<(n);i++)
 
using namespace std;
const int INF = 100000000;
const double EPS = 0.0000001;
typedef pair<int,int> P;

int n;
//           999999
bool isPrime[1000003];

void solve() {
	int ans=0;
	rep(i,n+1) if(isPrime[i]) ans++;
	cout<<ans<<endl;
}

void init() {
	rep(i,1000003) isPrime[i]=true;
	isPrime[0]=isPrime[1]=false;

	for(int i=2;i<1000003;i++) {
		if(isPrime[i]) {
			for(int j=i+i;j<1000003;j+=i) isPrime[j]=false;
		}
	}


}

int main() {
	init();
	while (cin>>n)
	{
		if(n==0) return 0;
		solve();

	}
}

Measured memory_bytes: 2136
A = [list(map(int, input().split())) for i in range(3)]
A = A[0] + A[1] + A[2]
N = int(input())
for i in range(N):
    b = int(input())
    if b in A:
        A[A.index(b)] = 0
lines = [
            [A[0], A[3], A[6]],
            [A[1], A[4], A[7]],
            [A[2], A[5], A[8]],
            [A[0], A[1], A[2]],
            [A[3], A[4], A[5]],
            [A[6], A[7], A[8]],
            [A[0], A[4], A[8]],
            [A[2], A[4], A[6]],
        ]
if [0, 0, 0] in lines:
    print('Yes')
else:
    print('No')

Measured memory_bytes: 38384
#include <bits/stdc++.h>
using namespace std;
using Graph = vector<vector<int> >;
#define rep(i, n)         for(int i = 0; i < (int)(n); i++)
#define brep(n)           for(int bit=0;bit<(1<<n);bit++)
#define erep(i,container) for (auto i : container)
#define irep(i, n)        for(int i = n-1; i >= (int)0; i--)
#define rrep(i,m,n) for(int i = m; i < (int)(n); i++)
#define reprep(i,j,h,w) rep(i,h)rep(j,w)
#define all(x) (x).begin(),(x).end()
#define aall(x,n) (x).begin(),(x).begin()+(n)
#define VEC(type,name,n) std::vector<type> name(n);rep(i,n)std::cin >> name[i];
#define pb push_back
#define pf push_front
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define itn int
#define mp make_pair
#define sum accumulate
#define keta fixed<<setprecision
#define vvector(name,typ,m,n,a)vector<vector<typ> > name(m,vector<typ> (n,a))
#define vvvector(name,t,l,m,n,a) vector<vector<vector<t> > > name(l, vector<vector<t> >(m, vector<t>(n,a)));
#define vvvvector(name,t,k,l,m,n,a) vector<vector<vector<vector<t> > > > name(k,vector<vector<vector<t> > >(l, vector<vector<t> >(m, vector<t>(n,a)) ));
typedef long long ll;
const int INF = 2000000000;
const ll INF64 = 1000000000000000ll;
const ll MOD = 1000000007LL;
//ノート　isupperで大文字の判定　islowerで小文字の判定
int main(){
   string s;
   std::cin >> s;
   rep(i,s.size())std::cout << 'x';
   std::cout  << std::endl;
}

Measured memory_bytes: 256