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

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

  vector<int> height(1000);
  vector<int> height_sa(1000);
  for (int i = 1; i <= 999; i++) {
    height[i]      = i * (i + 1) / 2;
    int tmp        = height[i] - height[i - 1];
    height_sa[tmp] = height[i];
  }

  int sa = height_sa[b - a];
  cout << sa - b << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {
	var word string
	fmt.Scan(&word)
	palindromeHugger(word)
}

func palindromeHugger(word string) int {
	word = strings.TrimSpace(word)
	reversedWord := wordReverser(word)
	wordSlice := []rune(word)
	incidence := 0

	for i, letter := range wordSlice {
		if letter != reversedWord[i] {
			incidence++
		}
	}

	fmt.Println(incidence / 2)
	return incidence / 2
}

func wordReverser(word string) []rune {
	var reversed strings.Builder
	letters := []rune(word)
	last := len(letters) - 1

	for i := 0; i < len(letters); i++ {
		reversed.WriteRune(letters[last-i])
	}

	return []rune(reversed.String())
}


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

using namespace std;

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

    vector<int> A{1};
    char a, b;
    cin >> a;

    for (int i = 1; i < N; i++) {
        cin >> b;
        if (a == b) {
            A.push_back(1);
        } else {
            A[A.size() - 1]++;
        }
        a = b;
    }

    int ans = 0;

    if (A.size() < 4) {
        for (int i = 0; i < A.size(); i++) {
            ans += A[i];
        }
    } else {
        for (int i = 1; i < A.size() - 1; i++) {
            ans = max(ans, A[i - 1] + A[i] + A[i + 1]);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a),i##formax=(b);i<i##formax;i++)
#define FORR(i,a,b) for(int i=(a),i##formax=(b);i>=i##formax;i--)
#define pb push_back
#define mp make_pair
#define fi first
#define se second
#define pcnt __builtin_popcount
#define sz(x) (int)(x).size()
#define maxs(x,y) x=max(x,y)
#define mins(x,y) x=min(x,y)
#define show(x) cout<<#x<<" = "<<x<<endl;
#define all(a) (a.begin()),(a.end())
#define each(it,c) for(__typeof((c).begin()) it=(c).begin();it!=(c).end();it++)
#define perm(c) sort(all(c));for(bool c##p=1;c##p;c##p=next_permutation(all(c)))
#define bitComb(a,n,k) for(int a##x,a##y,a=(1<<k)-1;a<(1<<n);a##x=a&-a,a##y=a+a##x,a=(((a&~a##y)/a##x)>>1)|a##y)
#define uniq(v) sort(all(v));v.erase(unique(all(v)), v.end())
#define bit(n) (1LL<<(n))
#define randInt(l,r) (uniform_int_distribution<ll>(l,r)(rnd))
#define randDouble(l,r) (uniform_real_distribution<double>(l,r)(rnd))
#define dout(d) printf("%.12f\n",d)

typedef long long ll;
typedef __int128_t lll;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;
template<class T>using V=vector<T>;
template<class T>using VV=V<V<T>>;
template<class T,class Y>ostream& operator<<(ostream& o,const pair<T,Y>& p){return o<<"("<<p.fi<<", "<<p.se<<")";}
template<typename A,size_t N,typename T>void Fill(A (&array)[N],const T&v){fill((T*)array,(T*)(array+N),v);}
lll gcd(lll a,lll b,lll &x,lll &y){if(!b){x=1;y=0;return a;}lll d=gcd(b,a%b,y,x);y-=a/b*x;return d;}
ll gcd(ll a,ll b){lll x=0,y=0;return gcd(a,b,x,y);}
ll modInv(ll a,ll m){lll x,y;gcd(a,m,x,y);return (x%m+m)%m;}
ll modPow(lll a,lll n,ll m){if(!a)return a;lll p=1;for(;n>0;n>>=1,a=a*a%m)if(n&1)p=p*a%m;return(ll)p;}
bool isPrime(ll n){if(n<2||n%2==0)return n==2;lll t=n-1,d=t/(t&-t);for(lll a:{2,325,9375,28178,450775,9780504,1795265022})if(a%n){for(t=d,a=modPow(a,t,n);t!=n-1&&a!=1&&a!=n-1;a=a*a%n,t=t*2%n);if(a!=n-1&&t%2==0)return 0;}return 1;}
const int IINF = 1e9+6;
const ll LINF = 1e18;
const int MOD = 1e9+7;
const double PI = acos(-1);
const double EPS = 1e-10;
static random_device rd;
static mt19937 rnd(rd());

const int N = 1e5;
int n, w[N];
main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cin >> n;
  int s = 0, ans = IINF, _s = 0;
  FOR(i, 0, n){
    cin >> w[i];
    s += w[i];
  }
  FOR(i, 0, n){
    _s += w[i];
    mins(ans, abs(s-_s*2));
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
// Problem : C - Guess The Number
// Contest : AtCoder Beginner Contest 157
// URL : https://atcoder.jp/contests/abc157/tasks/abc157_c
// Memory Limit : 1024 MB
// Time Limit : 2000 ms
// Powered by CP Editor (https://github.com/cpeditor/cp-editor)

#include<bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb emplace_back
#define int long long
#define vi vector<int>
#define pii pair<int,int>
#define m_p(x,y) make_pair(x,y)
#define vp vector<pair<int,int>>
#define setbits(x) __builtin_popcountll(x)
#define f first
#define se second
#define iniz(n) memset(n,0,sizeof(n))
#define inin(n) memset(n,-1,sizeof(n))
using namespace std;
using namespace __gnu_pbds;
template<typename T1,typename T2>istream &operator>>(istream &is, vector<pair<T1,T2>> &v) { for (pair<T1,T2> &t : v) is >> t.f>>t.se; return is; }
template<typename T>istream &operator>>(istream &is, vector<T> &v) { for (T &t : v) is >> t; return is; }
template<typename T>ostream &operator<<(ostream &os, const vector<T> &v) { for (const T &t : v) {os << t <<" ";} os << '\n'; return os; }
double pi=acos(-1.0);
int md=1000000007;
int abst(int a)
{return a<0?-a:a;}
typedef tree<
int,
null_type,
less<int>,
rb_tree_tag,
tree_order_statistics_node_update>
ordered_set;
// find_by_order(k)  returns iterator to kth element starting from 0;
// order_of_key(k) returns count of elements strictly smaller than k;
struct HASH{
  size_t operator()(const pii &x)const{
    return (size_t) x.first * 37U + (size_t) x.second;}};

struct custom_hash {
    static uint64_t splitmix64(uint64_t x) {
        x += 0x9e3779b97f4a7c15;
        x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
        x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
        return x ^ (x >> 31);
    }

    size_t operator()(uint64_t x) const {
        static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
        return splitmix64(x + FIXED_RANDOM);
    }
};

int Pow(int n,int x){int ans=1;
 while(x>0)
 {if(x&1)ans=(ans*n)%md;n=(n*n)%md;x=x>>1;}
 return ans;}

 vi fact,inv;
void inverse(int n)
{inv.resize(n+1);inv[0]=1;
for(int i=1;i<=n;i++)inv[i]=Pow(fact[i],md-2);}
void factorial(int n)
{fact.resize(n+1);fact[0]=1;
for(int i=1;i<=n;i++)fact[i]=(fact[i-1]*i)%md;}

int max(int a,int b){return a>b?a:b;}
int min(int a,int b){return a<b?a:b;}

void solve()
{
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
int n,m;cin>>n>>m;
vp v;int mt=m;
while(m--)
{
	int s,c;cin>>s>>c;
	v.pb(m_p(s,c));}
	
	for(int i=0;i<=999;i++)
	{
		string s=to_string(i);
		if(s.size()!=n)
		continue;
		int kt=0;
		for(int j=0;j<mt;j++)
		{
			int x=s[v[j].f-1]-'0';
			if(x!=v[j].se)
			{
				kt=1;break;
			}
		}
		if(kt==0)
		{
			cout<<s;
			return;
		}
	}
	cout<<-1;
}

int32_t main(){
ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
int t=1;
//cin>>t;
while(t--)
{
    solve();
}
}


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

using namespace std;

int main()
{
    int n;
    int card[105];

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

    sort(card, card + n, greater<int>() );

    int alice = 0;
    int bob   = 0;

    for (int i = 0; i < n; i++) {
        if ( i % 2 == 0 ) {
            alice += card[i];
        } else {
            bob += card[i];
        }
    }


    cout << alice - bob << endl;

    return 0;
}


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

int main() {
        ll int k;
         cin>>k;
         string s;
         cin>>s;
         int l=s.length();
         if(l<=k)
         {
             cout<<s<<endl;
         }
         else
         {
             for(int i=0;i<k;i++)
             {
                 cout<<s[i];
             }
             cout<<"...";
         }
}

Measured memory_bytes: 3624
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<string>

struct point{
	double x;
	double y;
};

using namespace std;

int ch(point p1, point p2, point p3){
	double dx1=p2.x-p1.x, dy1=p2.y-p1.y;
	double dx2=p3.x-p1.x, dy2=p3.y-p1.y;
	if(dx1*dy2>dx2*dy1)
	return 0;
	else
	return 1;
}

int main(){
	point a,b,c,d;
	while(scanf("%lf,%lf,%lf,%lf,%lf,%lf,%lf,%lf",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y)!=EOF){
		//scanf("%d,%d,%d,%d,%d,%d,%d,%d",&a.x,&a.y,&b.x,&b.y,&c.x,&c.y,&d.x,&d.y);
		if(ch(a,c,b)!=ch(a,c,d) && ch(b,d,a)!=ch(b,d,c))
		printf("YES\n");
		else
		printf("NO\n");
	}
}

Measured memory_bytes: 3212
package main

import "fmt"

func main() {
	var (
		w, h, x, y int
	)
	fmt.Scan(&w, &h, &x, &y)
	var s = float64(w) * float64(h) / 2.0
	var f = 0
	if w == x+x && h == y+y {
		f = 1
	}
	fmt.Printf("%.10f %d\n", s, f)
}

Measured memory_bytes: 1832
#include<iostream>
int main(void){
    int h;
    int t[3] = {0, 0, 0};
    for(int i = 0; i < 10; i++){
        std::cin >> h;
        for(int i = 0; i < 3; i++){
            if(t[i] <= h){
                switch(i){
                    case 0:
                        t[i+2] = t[i+1];
                        t[i+1] = t[i];
                        t[i] = h;
                        break;
                    case 1:
                        t[i+1] = t[i];
                        t[i] = h;
                        break;
                    case 2:
                        t[i] = h;
                }
                break;
            }
        }
    }
    for(int i = 0; i < 3; i++){
        std::cout << t[i] << std::endl;
    }
    return 0;
}



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

#define SIZE_OF_ARRAY(array) sizeof(array)/sizeof(array[0])

int main() {
    long long X;
    cin >> X;
    long long ansA, ansB;
    bool b = true;
    for(long long A = -200; A <= 200; A++){
        for(long long B = -200; B <= 200; B++){
            if(A*A*A*A*A - B*B*B*B*B == X){
                ansA = A;
                ansB = B;
                b = false;
                break;
            }
        }
        if(b){

        } else {
            break;
        }
    }
    cout << ansA << " " << ansB << endl;
}

Measured memory_bytes: 3624
#include "iostream"
#include "climits"
#include "list"
#include "queue"
#include "stack"
#include "set"
#include "functional"
#include "algorithm"
#include "string"
#include "map"
#include "iomanip"
#include "random"

using namespace std;

const long long int MOD = 1000000007;
const long double EPS = 0.00000001;
const long double PI = 3.1415926535897932384626433;

long long int N, M, K, L, R, H, W;

int main() {
	ios::sync_with_stdio(false);
	cin.tie(0);
	
	string s;
	cin >> s;
	for (int i = 0; i < s.size(); i++) {
		if (i % 2 == 0) {
			cout << s[i];
		}
	}
	cout << endl;
	return 0;
}

Measured memory_bytes: 592
def main():
    n, k = map(int, input().split())
    stones = tuple(map(int, input().split()))
    inf = 10**9
    dp = [inf]*n
    dp[0] = 0
    for i in range(n):
        for t in range(1, k+1):
            step = i+t
            if step < n:
                v = dp[i]+abs(stones[i]-stones[step])
                if v < dp[step]:
                    dp[step] = v
    print(dp[-1])


if __name__ == '__main__':    
    main()


Measured memory_bytes: 20692
a = int(raw_input())
b = int(raw_input())
c = int(raw_input())
x = int(raw_input())

result = 0
for i in range(a + 1):
  for j in range(b + 1):
    for k in range(c + 1):
      if i * 500 + j * 100 + k * 50 == x:
        result += 1

print result


Measured memory_bytes: 2568
a,b = map( int, input().split() )
 
def f_xor( num ):
    if num % 4 == 0:
        return num
    elif num % 4 == 1:
        return 1
    elif num % 4 == 2:
        return num ^ 1
    elif num % 4 == 3:
        return 0

print(f_xor(a-1) ^ f_xor(b))

Measured memory_bytes: 38256
# @oj: atcoder
# @id: hitwanyang
# @email: 296866643@qq.com
# @date: 2020-08-16 22:37
# @url:https://atcoder.jp/contests/abc175/tasks/abc175_c

import sys,os
from io import BytesIO, IOBase
import collections,itertools,bisect,heapq,math,string
from decimal import *
# region fastio

BUFSIZE = 8192

BUFSIZE = 8192

class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._fd = file.fileno()
        self.buffer = BytesIO()
        self.writable = "x" in file.mode or "r" not in file.mode
        self.write = self.buffer.write if self.writable else None

    def read(self):
        while True:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            if not b:
                break
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines = 0
        return self.buffer.read()

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self.buffer.tell()
            self.buffer.seek(0, 2), self.buffer.write(b), self.buffer.seek(ptr)
        self.newlines -= 1
        return self.buffer.readline()

    def flush(self):
        if self.writable:
            os.write(self._fd, self.buffer.getvalue())
            self.buffer.truncate(0), self.buffer.seek(0)


class IOWrapper(IOBase):
    def __init__(self, file):
        self.buffer = FastIO(file)
        self.flush = self.buffer.flush
        self.writable = self.buffer.writable
        self.write = lambda s: self.buffer.write(s.encode("ascii"))
        self.read = lambda: self.buffer.read().decode("ascii")
        self.readline = lambda: self.buffer.readline().decode("ascii")


sys.stdin, sys.stdout = IOWrapper(sys.stdin), IOWrapper(sys.stdout)
input = lambda: sys.stdin.readline().rstrip("\r\n")
# ------------------------------
def main():
    x,k,d=map(int,input().split())
    x=abs(x)
    n=x//d
    if k<=n:
        print (abs(x-k*d))
    else:
        l,r=abs(x-(n+1)*d),abs(x-n*d)
        if k%2==n%2:
            print (r)
        else:
            print (l)

if __name__ == "__main__":
    main()

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

int main()
{
	int n;
	cin >> n;
	string temp;
	int k[4]={0,0,0,0};
	for (int i=0; i<n; i++){
		cin>>temp;
		if (temp.compare("AC")==0) k[0]++;
		if (temp.compare("WA")==0) k[1]++;
		if (temp.compare("TLE")==0) k[2]++;
		if (temp.compare("RE")==0) k[3]++;
	}
	cout<<"AC x "<<k[0]<<endl;
	cout<<"WA x "<<k[1]<<endl;
	cout<<"TLE x "<<k[2]<<endl;
	cout<<"RE x "<<k[3]<<endl;
	return 0;
}

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

namespace ConsoleApp2
{
    class Program
    {
        static void Main(string[] args)
        {
            var N = GetLongNum();
            var list = new List<string>();
            for (int i = 0; i < N; i++)
            {
                list.Add(GetString());
            }

            var AC = list.Count(x => x == "AC");
            var WA = list.Count(x => x == "WA");
            var TLE = list.Count(x => x == "TLE");
            var RE = list.Count(x => x == "RE");

            Console.WriteLine("AC x " + AC);
            Console.WriteLine("WA x " + WA);
            Console.WriteLine("TLE x "+ +TLE);
            Console.WriteLine("RE x " + RE);
        }

        private static long[] GetLongNumArray()
        {
            var input = Console.ReadLine().Split(' ');
            return input.Select(x => long.Parse(x)).ToArray();
        }

        private static long GetLongNum()
        {
            return long.Parse(Console.ReadLine());
        }

        private static string[] GetStringArray()
        {
            return Console.ReadLine().Split(' ');
        }

        private static string GetString()
        {
            return Console.ReadLine();
        }
    }
}


Measured memory_bytes: 33224
#include <iostream>
#include <array>

int main(){
int r, d;
std::array<int, 11> x;
std::cin >> r >> d >> x.at(0);
for(int t = 0; t < 10 ; t++){
x.at(t+1) = r * x.at(t) - d;
std::cout<<x.at(t+1)<<std::endl;
}


}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	long n, a, b, x=0;
  
    scanf("%ld%ld%ld", &n, &a, &b);

    x += n/(a+b)*a;
    x += (n%(a+b)<=a) ? n%(a+b) : a;
  
    printf("%ld\n", x);
    
    return 0;
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
LL a[200005];
int main()
{
    int n;
    while(~scanf("%d", &n))
    {
        LL x;
        for(int i = 1; i <= n; i++)
        {
            scanf("%lld", &x);
            a[i] = x - i;
        }
        sort(a + 1, a + 1 + n);
        LL b = a[(n+1)/2];
        LL ans = 0;
        for(int i = 1; i <= n; i++)
            ans += abs(a[i] - b);
        printf("%lld\n", ans);
    }
    return 0;
}


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

using namespace std;

typedef uint64_t u64;
typedef int64_t s64;
typedef uint32_t u32;
typedef int32_t s32;
typedef vector<s32> vs32;
typedef vector<u32> vu32;
typedef vector<s64> vs64;
typedef vector<u64> vu64;

const double PI=3.14159265358979323846;

#define MAX(x, y) ((x) < (y) ? (y) : (x))
#define MIN(x, y) ((x) > (y) ? (y) : (x))

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

#define CEIL(x, y) (((x) + (y) - 1) / (y))
#define MOD 1000000007ULL

#define IN(l, r, x) ((l) <= (x) && (x) < (r))


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

    int n;
    cin >> n;

    vs64 ans;
    ans.push_back(2);
    ans.push_back(3);
    ans.push_back(25);

    int num = 3;
    s64 a = 4;
    for (; num + 15 <= n && a + 32 <= 30000;)
    {
        rep (i, 15)
        {
            if (a % 30 != 0 && a <= 30000)
            {
                ans.push_back(a);
                ++num;
            }
            a += 2;
        }
    }

    a = 9;
    for (; num + 10 <= n && a + 9 * 9 <= 30000; num += 10)
    {
        rep (i, 10)
        {
            ans.push_back(a);
            a += 6;
        }
    }

    a = 35;
    for (; num + 2 <= n && a + 20 <= 30000; num += 2)
    {
        rep (i, 2)
        {
            ans.push_back(a);
            a += 20;
        }
        a += 20;
    }
    
    a = 30;
    for (; num < n; ++num)
    {
        ans.push_back(a);
        a += 30;
    }

    rep (i, ans.size())
    {
        if (i > 0) cout << " ";
        cout << ans[i];
    }
    cout << "\n";
    return 0;
}



Measured memory_bytes: 640
#include <algorithm>
#include <bitset>
//#include <boost/multiprecision/cpp_int.hpp>
#include <climits>
#include <cmath>
#include <cstring>
#include <functional>
#include <algorithm>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <sstream>
#include <stdio.h>
#include <string>
#include <tuple>
#include <vector>
//namespace mp = boost::multiprecision;
using namespace std;
using ull = unsigned long long;
using ld = long double;
// using ll = boost::multiprecision::cpp_int;
using ll = long long;
#define FOR(i,N) for(ll i = 0; i < N; ++i)

#define ALL(v) (v).begin(), (v).end()
#define RALL(v) (v).rbegin(), (v).rend()
// using int = ll;
ll gcd(ll m, ll n) {
    if(n == 0)
        return abs(m);
    return (gcd(n, m % n));
}
void putYN(bool b) {
    if(b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
}
void swap(ll &a, ll &b) {
    ll tmp = a;
    a = b;
    b = tmp;
}
ll combi(ll n, ll k) {
    ll r = 1, rr = 1;
    for(ll i = 0; i < k; ++i) {
        r *= (n - i);
        rr *= (i + 1);
        // r %= 1000000007;
        // rr %= 1000000007;
    }
    r /= rr;
    // r %= 1000000007;
    return r;
}

int main() {

    ll N;
    cin>>N;
    vector<ll> h(N);
    FOR(i,N) { cin >> h[i]; }
    vector<ll> a(N,-1);
    function<ll(ll,ll)> f = [&](ll i,ll pre) -> ll {
        if(i==N-1)
            return abs(h[i]-h[pre]);
        if(i>N-1)
            return -1;
        if(a[i]!=-1){
            return a[i] + abs(h[i] - h[pre]);
        }
        ll ret,ret2;
        ret = f(i + 1, i);
        ret2 = f(i + 2, i);
        if(ret==-1&&ret2==-1)
            return -1;
        if(ret>ret2&&ret2!=-1)
            ret = ret2;
        a[i] = ret;
        return ret + abs(h[i] - h[pre]);
    };
    cout << f(0, 0)<<endl;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
#define f first
#define s second
using namespace std;
typedef pair<int,int> P;
int mp[35][35],smp[35][35],n,SUM,W,H;
P mem[35][35][35][35];
int used[35][35][35][35];

int cal(int x1,int y1,int x2,int y2){
  return smp[y2][x2]-(smp[y1-1][x2]+smp[y2][x1-1])+smp[y1-1][x1-1];
}

P dfs(int x,int y,int w,int h){
  if(used[x][y][w][h]++) return mem[x][y][w][h];

  P res=P(1,n-(SUM-cal(x,y,w,h)));
  for(int i=x;i!=w;i++){
    int m=max(SUM-cal(x,y,i,h),SUM-cal(i+1,y,w,h));
    if(m<=n){
      P a=dfs(x,y,i,h);
      P b=dfs(i+1,y,w,h);
      res=max(res,P((a.f+b.f),min(a.s,b.s)));
    }
  }

  for(int i=y;i!=h;i++){
    int m=max(SUM-cal(x,y,w,i),SUM-cal(x,i+1,w,h));
    if(m<=n){
      P a=dfs(x,y,w,i);
      P b=dfs(x,i+1,w,h);
      res=max(res,P((a.f+b.f),min(a.s,b.s)));
    }
  }
  return mem[x][y][w][h]=res;
}

int main(){
  while(1){
  cin>>H>>W>>n;
  if(!H&&!W&&!n)break;

  memset(used,0,sizeof(used));
  memset(mem,0,sizeof(mem));

  for(int i=1;i<=H;i++)
    for(int j=1;j<=W;j++)cin>>mp[i][j],smp[i][j]=mp[i][j];

  for(int i=1;i<=H;i++)for(int j=1;j<=W;j++) smp[i][j+1]+=smp[i][j];
  for(int i=1;i<=H;i++)for(int j=1;j<=W;j++) smp[i+1][j]+=smp[i][j];
  SUM=smp[H][W];
  P ans=dfs(1,1,W,H);
  cout <<ans.f<<" "<<ans.s<<endl;
  }
  return 0;
}

Measured memory_bytes: 18776
#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 MAXN = (int)1e5 + 5;
const ll mod = (ll)1e+9 + 7ll;

ll fact[MAXN];

inline ll bin_pow(ll a, ll n) {
	ll u = a, res = 1ll;
	while (n) {
		if (n % 2ll == 1ll)
			res = (res * u) % mod;
		u = (u * u) % mod;
		n /= 2ll;
	}
	return res;
}

inline ll div_mod(ll a, ll b) {
	return a * bin_pow(b, mod - 2ll) % mod;
}

inline ll C(int n, int k) {
	if (n < k)
		return 0ll;
	return div_mod(fact[n], fact[n - k] * fact[k] % mod);
}

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

	fact[0] = 1ll;
	for (int i = 1; i < MAXN; i++)
		fact[i] = (fact[i - 1] * (ll)i) % mod;

	int n, k;
	cin >> n >> k;

	vector <ll> arr(n);
	forn(i, n)
		cin >> arr[i];
	sort(arr.begin(), arr.end());

	ll ans = 0ll;
	forn(i, n - 1) {
		int left = i + 1, right = n - i - 1;
		ll all = C(left + right, k);
		ll bad = (C(left, k) + C(right, k)) % mod;
		ll good = (all + mod - bad) % mod;
		ans = (ans + (arr[i + 1] - arr[i]) * good % mod) % mod;
	}
	cout << ans;

	return 0;
}

Measured memory_bytes: 1792
import bisect
import sys
input = sys.stdin.buffer.readline

def main():
    N = int(input())
    A = list(map(int,input().split()))
    A.sort()

    def canuse(x):
        index = bisect.bisect_left(A,x)
        return index
        
    ans = 0
    for i in range(N):
        for j in range(N-i-1):
            s = A[i]+A[i+j+1]
            ans += canuse(s)-(i+j+2)
            
    print(ans)
        
if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
package main

import "fmt"

func main() {
	var a, b int
	fmt.Scan(&a)
	fmt.Scan(&b)

	if a%3 == 0 || b%3 == 0 || (a+b)%3 == 0 {
		fmt.Println("Possible")
	} else {
		fmt.Println("Impossible")
	}
}


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
#include <queue>
#include <utility>
#include <vector>

#define MAX_N (100000)
#define MAX_Q (100000)

using namespace std;

void dijkstra(const vector<vector<pair<int, int>>> &adj_lists,
              vector<long> &distances, int s) {
  priority_queue<pair<long, int>, vector<pair<long, int>>,
                 greater<pair<long, int>>>
      que;
  que.push(pair<long, int>(0, s));
  while (!que.empty()) {
    const pair<long, int> p = que.top();
    const long d = p.first;
    const int v = p.second;
    que.pop();
    if (distances[v] < 0) {
      distances[v] = d;
      for (int k = 0; k < adj_lists[v].size(); k++) {
        const int u = adj_lists[v][k].first, w = adj_lists[v][k].second;
        if (distances[u] < 0) {
          que.push(pair<long, int>(d + w, u));
        }
      }
    }
  }
}

int main(int argc, char *argv[]) {
  // read inputs
  int N, Q, K, as[MAX_N], bs[MAX_N], cs[MAX_N], xs[MAX_Q], ys[MAX_Q];
  scanf("%d", &N);
  for (int i = 0; i < N - 1; i++) {
    scanf("%d %d %d", &as[i], &bs[i], &cs[i]);
    as[i]--;  // NOTE : modified input
    bs[i]--;  // NOTE : modified input
  }
  scanf("%d %d", &Q, &K);
  K--;  // NOTE : modified input
  for (int k = 0; k < Q; k++) {
    scanf("%d %d", &xs[k], &ys[k]);
    xs[k]--;  // NOTE : modified input
    ys[k]--;  // NOTE : modified input
  }

  // create graph (tree)
  vector<vector<pair<int, int>>> adj_lists;
  for (int i = 0; i < N; i++) {
    adj_lists.push_back(vector<pair<int, int>>());
  }
  for (int i = 0; i < N - 1; i++) {
    const int a = as[i], b = bs[i], c = cs[i];
    adj_lists[a].push_back(pair<int, int>(b, c));
    adj_lists[b].push_back(pair<int, int>(a, c));
  }

  // calculate shortest paths from K
  vector<long> distances(N, -1);
  dijkstra(adj_lists, distances, K);

  // respond to the queries
  for (int k = 0; k < Q; k++) {
    printf("%ld\n", distances[xs[k]] + distances[ys[k]]);
  }

  return 0;
}


Measured memory_bytes: 13424
import sys
stdin = sys.stdin

def li(): return [int(x) for x in stdin.readline().split()]
def li_(): return [int(x)-1 for x in stdin.readline().split()]
def lf(): return [float(x) for x in stdin.readline().split()]
def ls(): return stdin.readline().split()
def ns(): return stdin.readline().rstrip()
def lc(): return list(ns())
def ni(): return int(ns())
def nf(): return float(ns())

h,w = li()
n = ni()
a = li()

grid = [[0]*w for _ in range(h)]

color = 1
res = a[color-1]

for hi in range(h):
    for wj in range(w):
        if res == 0:
            color += 1
            res = a[color-1]
        
        grid[hi][wj] = color
        res -= 1

            
for hi in range(h):
    if hi%2 == 0:
        print(*grid[hi])
    else:
        grid[hi] = grid[hi][::-1]
        print(*grid[hi])

Measured memory_bytes: 3916
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> Pii;
typedef pair<ll,ll> Pll;
#define rep(i,n) for (ll i=0;i<(n);++i)
#define rep2(i,a,b) for (ll i=(a);i<(b);++i)
#define debug(x) cout << #x << '=' << x << endl
#define all(v) (v).begin(),(v).end()
const ll MOD=1e9+7;
//const ll MOD=998244353;
const ll INF=1e9;
const ll IINF=1e18;
const double EPS=1e-8;
const double pi=acos(-1);

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

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,r;
    while(cin >> n >> r,n,r){
        vector<int> cs(n),cs0(n);
        iota(cs.begin(),cs.end(),1);
        reverse(cs.begin(),cs.end());
        rep(i,r){
            int p,c; cin >> p >> c;
            rep(i,n) cs0[i]=cs[i];
            rep(j,p-1) cs[j+c]=cs0[j];
            rep(j,c) cs[j]=cs0[j+p-1];
        }
        cout << cs[0] << endl;
    }
}


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

int main() {
    int K;
    std::cin >> K;

    int a[] = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51}; 

    std::printf("%d\n", a[K-1]);

    return 0;
}


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

using namespace std;

#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define pf push_front
#define iter(v, i) for (__typeof__((v).begin()) i = (v).begin(); i != (v).end(); i++)
#define fast_io_without_cstdio ios_base::sync_with_stdio(false), cin.tie(NULL)
#define all(v) (v).begin(), (v).end()
#define rep(i, s, e) for (int i = s; i < e; i++)

// START for segment tree
#define params int p, int L, int R
#define housekeep int mid = (L + R) >> 1, left = p << 1, right = left | 1
// END

#ifdef __linux__
#define gc getchar_unlocked
#define pc putchar_unlocked
#else
#define gc getchar
#define pc putchar
#endif

#if __cplusplus <= 199711L
template<class BidirIt>
BidirIt prev(BidirIt it, typename iterator_traits<BidirIt>::difference_type n = 1) {
    advance(it, -n);
    return it;
}

template<class ForwardIt>
ForwardIt next(ForwardIt it, typename iterator_traits<ForwardIt>::difference_type n = 1) {
    advance(it, n);
    return it;
}
#endif

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long double ldouble;

const double EPS = 1e-9;
const double PI = 3.141592653589793238462;

template<typename T>
inline T sq(T a) { return a * a; }

//#ifdef LOCAL_MACHINE
//#endif

const int MAXN = 2e5 + 5;

pair<ii, bool> pts[MAXN];
set<int> red;

int main() {
    //freopen("", "r", stdin);
    //freopen("", "w", stdout);
    int n;
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        scanf("%d %d", &pts[i].fi.fi, &pts[i].fi.se);
        pts[i].se = false;
    }
    for (int i = n; i < 2 * n; i++) {
        scanf("%d %d", &pts[i].fi.fi, &pts[i].fi.se);
        pts[i].se = true;
    }
    sort(pts, pts + 2 * n);
    red.insert((int)1e9);
    int ans = 0;
    for (auto cur : pts) {
        if (cur.se) {
            bool found = false;
            auto it = red.begin();
            while (*it < cur.fi.se) {
                found = true;
                it++;
            }
            it--;
            if (found) {
                ans++;
                red.erase(it);
            }
        } else {
            red.insert(cur.fi.se);
        }
    }
    printf("%d\n", ans);
    return 0;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
#define INF 1145141919810893364
//#define INF 810114514
#define PI 3.141592653589
typedef long long ll;
typedef pair<ll,ll> PP;
#define int ll
#define setdouble setprecision
#define REP(i,n) for(int i=0;i<(n);++i)
#define OREP(i,n) for(int i=1;i<=(n);++i)
#define RREP(i,n) for(int i=(n)-1;i>=0;--i)
#define GOODBYE do { cout << "0" << endl; return 0; } while (false)
#define MM <<" "<<
#define Endl endl
#define debug false
#define debug2 false

signed main(void){
    int X;
    cin >> X;
    for(int A=-200;A<=200;A++){
        for(int B=-200;B<=200;B++){
            if(A*A*A*A*A-B*B*B*B*B==X){
                cout << A << " " << B << endl;
                return 0;
            }
        }
    }
    return 0;
}




Measured memory_bytes: 3620
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll N;
  cin >> N;
  vector<string> x(N), u(N);
  long double ans = 0;
  for (int i = 0; i < N; i++) {
    cin >> x[i] >> u[i];
    if (u[i] == "BTC") {
      ans += 380000 * stod(x[i]);
    } else {
      ans += stoll(x[i]);
    }
  }
  cout << fixed << setprecision(10) << ans << endl;
  return 0;
}

Measured memory_bytes: 3772
#include<bits/stdc++.h>
#define F first
#define S second
#define node pair<pair<ll,ll>,ll>
using namespace std;
typedef long long ll;
ll read(){
	ll a=0,b=getchar(),c=1;
	while(!isdigit(b))c=b=='-'?-1:1,b=getchar();
	while(isdigit(b))a=a*10+b-'0',b=getchar();
	return a*c;
}
node a[1005];
ll n,dp[20005];
bool cmp(node x,node y){
	return x.F.F+x.F.S>y.F.F+y.F.S;
}
int main(){
	n=read();
	for(int i=1;i<=n;i++)
		a[i].F.F=read(),a[i].F.S=read(),a[i].S=read();
	sort(a+1,a+n+1,cmp);
	for(int i=1;i<=n;i++)
		for(int j=a[i].F.F;j<=a[i].F.F+a[i].F.S;j++)
			dp[j-a[i].F.F]=max(dp[j-a[i].F.F],dp[j]+a[i].S);
	printf("%lld",dp[0]);
	return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;


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

	int N, K;
	cin >> N >> K;
	bool ok[N]{};
	rep(i,K){
		int d;
		cin >> d;
		rep(j,d){
			int a;
			cin >> a;
			--a;
			ok[a] = true;
		}
	}
	int ans = 0;
	rep(i,N){
		if(!ok[i]) ++ans;
	}
	cout << ans << endl;
}

Measured memory_bytes: 3628
Q, H, S, D = map(int, input().split())
N = int(input())
if N%2 == 0:
  print((N//2)*min(8*Q,4*H,2*S,D))
else:
  m = min(4*Q,2*H,S)
  if 2*m <= D:
    print(m*N)
  else:
    print(int(D*(N//2)+m))

Measured memory_bytes: 3060
n = int(input())
lis = [list(map(int, input().split())) for i in range(n)]
lis.sort(key = lambda x: x[0])
ans = lis[0][0]
s = lis[0][0]
for i in range(1,n):
    ans += lis[i][0]-s
    s = lis[i][0]
ans += lis[-1][1]

print(ans)

Measured memory_bytes: 29448
open Batteries
open BatPrintf

let scan fmt f =
  BatScanf.sscanf (read_line ()) fmt f

let scan_list cnv =
  read_line ()
  |> BatString.split_on_char ' '
  |> List.map cnv

let rec zip xs ys =
  match xs, ys with
  | [], _ -> []
  | _, [] -> []
  | x::xs, y::ys ->
    (x, y) :: zip xs ys

let (k, x) = scan "%d %d" BatTuple.Tuple2.make

let () =
  printf "%s\n"
    (if x <= k * 500 then
       "Yes"
     else
       "No")


Measured memory_bytes: 1536
Q = int(input())
memo = [0]*(10**5+1)

def is_prime(N):
    prime = [True for _ in range(N)]
    prime[1] = False
    for i in range(2, N):
        if not prime[i]:
            continue
        j = i+i
        while j<N:
            prime[j] = False
            j += i
    return prime

prime = is_prime(10**5+1)

for i in range(1, 10**5+1):
    if prime[i] and prime[(i+1)//2]:
        memo[i] = memo[i-1] + 1
    else:
        memo[i] = memo[i-1]

for _ in range(Q):
    l, r = map(int, input().split())
    print(memo[r+1]-memo[l-1])

Measured memory_bytes: 5160
package main

import "fmt"

func main() {
	var D int
	fmt.Scan(&D)
	cs := make([]int, 26)
	for i := 0; i < 26; i++ {
		fmt.Scan(&cs[i])
	}

	ss := make([][26]int, D)
	for d := 0; d < D; d++ {
		for i := 0; i < 26; i++ {
			fmt.Scan(&ss[d][i])
		}
	}

	ts := make([]int, D)
	for i := 0; i < D; i++ {
		fmt.Scan(&ts[i])
	}

	last := [26]int{}
	sat := 0
	for d := 0; d < D; d++ {
		j := ts[d] - 1
		last[j] = d + 1
		for i := 0; i < 26; i++ {
			sat -= (d + 1 - last[i]) * cs[i]
		}
		sat += ss[d][j]
		fmt.Println(sat)
	}
}


Measured memory_bytes: 2472
n=int(input())
if n>=64:
    print(64)
elif 64>n and n>=32:
    print(32)
elif 32>n and n>=16:
    print(16)
elif 16>n and n>=8:
    print(8)
elif 8>n and n>=4:
    print(4)
elif 4>n and n>=2:
    print(2)
else:
    print(1)

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

int n, a[100010], cnt1[100010], cnt2[100010];

int main()
{
    scanf("%d", &n);
    for (int i = 1; i <= n; i++)
    {
        scanf("%d", &a[i]);
        if (i & 1) cnt1[a[i]]++;
        else cnt2[a[i]]++;
    }
    int mxa1 = 0, mxa1i = 0, mxa2 = 0, mxa2i = 0, mxb1 = 0, mxb1i = 0, mxb2 = 0, mxb2i = 0;
    for (int i = 1; i <= 100000; i++)
    {
        if (cnt1[i] >= mxa1)
        {
            mxa2 = mxa1;
            mxa2i = mxa1i;
            mxa1 = cnt1[i];
            mxa1i = i;
        }
        else if (cnt1[i] >= mxa2)
        {
            mxa2 = cnt1[i];
            mxa2i = i;
        }
        if (cnt2[i] >= mxb1)
        {
            mxb2 = mxb1;
            mxb2i = mxb1i;
            mxb1 = cnt2[i];
            mxb1i = i;
        }
        else if (cnt2[i] >= mxb2)
        {
            mxb2 = cnt2[i];
            mxb2i = i;
        }
    }
    if (mxa1i == mxb1i) printf("%d\n", min(n - mxa2 - mxb1, n - mxa1 - mxb2));
    else printf("%d\n", n - mxa1 - mxb1);
}

Measured memory_bytes: 1408
#include <iostream>
#include <string>

int main() {
  std::string s_a, s_b, s_c;
  std::cin >> s_a >> s_b >> s_c;
  std::string card = s_a.substr(0, 1);
  s_a.erase(0, 1);
  bool win_a = false, win_b = false, win_c = false;
  while (true) {
    if (card == "a") {
      if (s_a.empty()) {
        win_a = true;
        break;
      }
      card = s_a.substr(0, 1);
      s_a.erase(0, 1);
    }
    if (card == "b") {
      if (s_b.empty()) {
        win_b = true;
        break;
      }
      card = s_b.substr(0, 1);
      s_b.erase(0, 1);
    }
    if (card == "c") {
      if (s_c.empty()) {
        win_c = true;
        break;
      }
      card = s_c.substr(0, 1);
      s_c.erase(0, 1);
    }
  }
  if (win_a) {
    std::cout << "A" << "\n";
  } else if (win_b) {
    std::cout << "B" << "\n";
  } else if (win_c) {
    std::cout << "C" << "\n";
  }
}

Measured memory_bytes: 3052
using System;

public class Hello
{
	public static void Main()
	{
		string[] line = Console.ReadLine().Trim().Split(' ');
		var r = int.Parse(line[0]);
		var d = int.Parse(line[1]);
		var x = int.Parse(line[2]);
		for (int i = 0; i < 10; i++)
		{
			var nx = r * x - d;
			Console.WriteLine(nx);
			x = nx;
		}
	}
}

Measured memory_bytes: 13140
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
#define pi 3.141592653589793283462
int main(){
	int Aa,Ab,Ac,Ad;
	int ba,bb,bc,bd;
	int p,q;
	cin>> Aa>>Ab>>Ac>>Ad;
	cin>> ba>>bb>>bc>>bd;
	p=Aa+Ab+Ac+Ad;
    q=ba+bb+bc+bd;
	if(p<q)
		cout<<q<<endl;
	else if(p>q)
		cout<<p<<endl;
	else
		cout<<p<<endl;
	return 0;
}

Measured memory_bytes: 1160
#include <stdio.h>
int main(){
    int k,i[100],c=0;
    while(1){
        scanf("%d",&k);
        if(k==0&&c!=0){
            printf("%d\n",i[c-1]);
            c--;
        }else if(k!=0&&k<=10){
            i[c]=k;
            c++;
        }else break;
    }
    return 0;
}

Measured memory_bytes: 1772
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<double, int> P;
typedef tuple<ll, ll, ll> T;

int n;
double t, a;
vector<double> H(1001, 0);

int main(void){
    
    scanf("%d %lf %lf", &n, &t, &a);
    for(int i = 0; i < n; ++i) scanf("%lf", &H[i]);
    
    vector<P> v;
    for(int i = 0; i < n; ++i) H[i] = t - H[i] * 0.006, v.push_back(make_pair(abs(a - H[i]), i));
    sort(v.begin(), v.end());
    
    printf("%d\n", v[0].second + 1);
    
    return 0;
}


Measured memory_bytes: 256
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		// Scanner scan = new Scanner(new File("c:\\0520-input.txt"));

		while (scan.hasNext()) {
			int n = scan.nextInt();
			if (n == 0)
				break;

			Mobile mobile = new Mobile(n);
			for (int i = 0; i < n; i++)
				mobile.add(i + 1, scan.nextInt(), scan.nextInt(), scan.nextInt(), scan.nextInt());
			// mobile.print();
			System.out.println(mobile.getWeight(mobile.getTop()));
		}

		scan.close();
		System.exit(0);
	}

}

class Mobile {
	class Bar {
		public Bar(int _p, int _q, int _r, int _b) {
			p = _p;
			q = _q;
			r = _r;
			b = _b;
		}

		int p, q;
		int r, b;
	}

	Bar[] bar;

	public Mobile(int n) {
		bar = new Bar[n + 1];
	}

	public long getWeight(int me) {
		if (me == 0)
			return 1;
		long m = this.lcm(bar[me].p * this.getWeight(bar[me].r), bar[me].q * this.getWeight(bar[me].b));
		return (m / bar[me].p + m / bar[me].q);
	}

	public int getTop() {
		return (this.top(1));
	}

	private int top(int c) {
		int p = getParent(c);
		if (p == -1)
			return (c);
		else
			return (this.top(p));
	}

	private int getParent(int c) {
		for (int i = 1; i < bar.length; i++)
			if (bar[i].r == c || bar[i].b == c)
				return i;
		return (-1);
	}

	public void print() {
		for (int i = 1; i < bar.length; i++)
			System.out.println(i + ":" + bar[i].p + " " + bar[i].q + " " + bar[i].r + " " + bar[i].b);

	}

	public void add(int i, int p, int q, int r, int b) {
		int g = (int) this.gcd(p, q);
		bar[i] = new Bar((p / g), (q / g), r, b);
	}

	private long gcd(long a, long b) {
		while (true) {
			if (a > b) {
				long tmp = a;
				a = b;
				b = tmp;
			}

			long r = b % a;
			if (r == 0)
				return (a);
			else if (r == 1)
				return 1;
			else
				b = r;
		}
	}

	private long lcm(long a, long b) {
		return (a * b / gcd(a, b));
	}
}

Measured memory_bytes: 32304
#include <cstdio>
#include <stdint.h>
#include <algorithm>

int hs[200005];
int as[200005];
int64_t beauty[200005];
int N;

void setmax(int64_t& x,int64_t y){
  x=std::max(x,y);
}

void update(int i,int64_t v){
  for(;i<=N;i+=(i&-i)){
    setmax(beauty[i],v);
  }
}

int64_t query(int i){
  int64_t ac=0;
  for(;i>0;i-=(i&-i)){
    setmax(ac,beauty[i]);
  }
  return ac;
}

int main(){
  scanf("%d",&N);
  for(int i=1;i<=N;i++){
    scanf("%d",&hs[i]);
  }
  for(int i=1;i<=N;i++){
    scanf("%d",&as[i]);
  }
  for(int i=1;i<=N;i++){
    update(hs[i],query(hs[i])+as[i]);
  }
  printf("%ld\n",query(N));
  return 0;
}


Measured memory_bytes: 3328
#include <iostream>
#include <iomanip>
// std::cout << std::setprecision(2) << 3.141; // "3.1"
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
#include <map>

using namespace std;

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> plglg;
typedef pair<double, ll> pdlg;
typedef tuple<int, int, int> tiii;
typedef tuple<ll, ll, ll> tlglglg;
typedef tuple<double, double, double> tddd;

static const int giga = pow(10,9);
// double pi = 3.141592653589793238463;

int main(void){
  int n;
  cin >> n;
  vector<int> h(n);
  int ans = 0;
  
  for(int i = 0; i < n; i++){
    int temp;
    cin >> temp;
    h[i] = temp;
    int flag = 1;
    for(int j = 0; j < i; j++){
      if(h[i] < h[j]){
	flag = 0;
	break;
	
      } else {
	
      }
      
    }
    if(flag == 1){
      ans++;
    }
  }


  cout << ans << endl;

  return 0;
}

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

using namespace std;

class Node
{
  public:
    Node() {MyID = ParentID = -1; Depth = 0; }

    int MyID;
    int ParentID;
    int Depth;
    vector<int> ChildrenID;

    void Print()
    {
      //node 0: parent = 1, depth = 1, leaf, []
      cout << "node " << MyID << ": "
	<< "parent = " << ParentID << ", " 
	<< "depth = " << Depth << ", "
	<< (ParentID == -1 ? "root, " : ChildrenID.size() > 0 ? "internal node, " : "leaf, ");

      cout << "[";
      for(int i = 0; i < ChildrenID.size(); ++i)
	cout << ChildrenID[i] << (ChildrenID.size() - 1 == i ? "" : ", ");
      cout << "]" << endl;


    }
};

Node *Nodes;

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

  Nodes = new Node[N];

  for(int i = 0; i < N; ++i)
    Nodes[i].MyID = i;

  for(int i = 0; i < N; ++i)
  {
    int NodeID; cin >> NodeID;
    int K; cin >> K;

    for(int k = 0; k < K; ++k)
    {
      int k_id; cin >> k_id;
      Nodes[NodeID].ChildrenID.push_back(k_id);
      Nodes[k_id].ParentID = NodeID;
    }
  }

  for(int i = 0; i < N; ++i)
  {
    int p = i;
    while (Nodes[p].ParentID != -1)
    {
      Nodes[i].Depth++;
      p = Nodes[p].ParentID;
    }
  }


  for(int i = 0; i < N; ++i)
    Nodes[i].Print();

  delete [] Nodes;

  return 0;
}



Measured memory_bytes: 7616
package main

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

// Watch
func main() {
	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	num, _ := strconv.Atoi(sc.Text())
	h := num / 3600
	m := (num % 3600) / 60
	s := (num % 3600) % 60
	fmt.Printf("%v:%v:%v\n", h, m, s)
}



Measured memory_bytes: 1092
#include <algorithm>
#include <climits>
#include <iostream>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <vector>

#define int long long int
constexpr int INF = std::numeric_limits<int>::max();
constexpr int NINF = std::numeric_limits<int>::min();
using namespace std;

void solve() {
  int N, M;
  cin >> N >> M;

  vector<int> x(N);
  vector<int> y(N);
  vector<int> z(N);

  for (int i = 0; i < N; i++) {
    cin >> x[i] >> y[i] >> z[i];
  }

  int ans = 0;
  for (int a : {-1, 1}) {
    for (int b : {-1, 1}) {
      for (int c : {-1, 1}) {

        vector<pair<int, int>> v;
        for (int i = 0; i < N; i++) {
          int n = a * x[i] + b * y[i] + c * z[i];
          v.emplace_back(n, i);
        }

        sort(v.begin(), v.end(), std::greater<pair<int, int>>());
        int p = 0, q = 0, r = 0;
        for (int i = 0; i < M; i++) {
          int n = v[i].second;
          p += x[n];
          q += y[n];
          r += z[n];
        }
        ans = max(ans, abs(p) + abs(q) + abs(r));
      }
    }
  }
  cout << ans << endl;
}

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


Measured memory_bytes: 384
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
#include <cstring>
using namespace std;
const int MXN = 100010;

int n;
int a[MXN];
int pa[2] = {}, tot = 0;
int main()
{
    cin >> n;
    for (int i = 0; i < n; ++i) scanf("%d", a + i);
    sort(a, a + n, greater<int>());
    for (int i = 1; i < n; ++i)
    {
        if (a[i] == a[i - 1])
        {
            pa[tot++] = a[i]; if (tot == 2) break;
            ++i;
        }
    }
    if (tot == 2)
    {
        cout << (long long)pa[0] * pa[1] << endl;
    }
    else
    {
        cout << 0 <<endl;
    }
    return 0;
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
int main () {
  int N;
  cin >> N;
  vector<tuple<int, int, int>> pyra(N);
  for (int i = 0; i < N; i ++) {
    int x, y, h;
    cin >> x >> y >> h;
    pyra[i] = make_tuple(h, x, y);
  }
  sort(pyra.begin(), pyra.end());
  reverse(pyra.begin(), pyra.end());
  for (int x = 0; x <= 100; x ++) {
    for (int y = 0; y <= 100; y ++) {
      int cx, cy, ch;
      tie(ch, cx, cy) = pyra[0];
      int H;
      if (ch == 0) H = 1;
      else {
        int dex = max(x - cx, cx - x);
        int dey = max(y - cy, cy - y);
        H = ch + dex + dey;
      }
      bool ok = true;
      for (int i = 0; i < N; i ++) {
        tie(ch, cx, cy) = pyra[i];
        int dx = max(x - cx, cx - x);
        int dy = max(y - cy, cy - y);
        int dh = max(H - dx - dy, 0);
        if (dh != ch) ok = false;
      }
      if (ok) {
        cout << x << ' ' << y << ' ' << H << endl;
        return 0;
      }
    }
  }
}

Measured memory_bytes: 3644
#include <stdio.h>
int main(){
    while (1) {
        int h,w,f=0;
        scanf("%d %d",&h,&w);
        if(h==0&&w==0) return 0;
        char c[h][w];
        int i,x=0,y=0;
        for (i=0; i<h; i++) scanf("%s",c[i]);
        while (1) {
            switch (c[y][x]) {
                case '>':
                    c[y][x]='X';
                    x++;
                    break;
                    
                case '<':
                    c[y][x]='X';
                    x--;
                    break;
                    
                case '^':
                    c[y][x]='X';
                    y--;
                    break;
                    
                case 'v':
                    c[y][x]='X';
                    y++;
                    break;
                    
                case '.':
                    f=1;
                    printf("%d %d\n",x,y);
                    break;
                    
                case 'X':
                    f=1;
                    printf("LOOP\n");
                    break;
            }
            if(f) break;
        }
    }
}

Measured memory_bytes: 1052