akhauriyash/Code-Regression huggingface dataset:
H, W = map(int, input().split())
a = [None]*H
b = [[1 for j in range(W)] for i in range(H)]
delete = 1
for i in range(0, H):
  a[i] = input()
for i in range(0, H):
  for j in range(0, W):
    if a[i][j] != ".":
      delete = 0
      break
  if delete == 1:
    for j in range(0, W):
      b[i][j] = 0
  else:
    delete = 1
for j in range(0, W):
  for i in range(0, H):
    if a[i][j] != ".":
      delete = 0
      break
  if delete == 1:
    for i in range(0, H):
      b[i][j] = 0
  else:
    delete = 1
new_line = 0
for i in range(0, H):
  for j in range(0, W):
    if b[i][j] == 1:
      print(a[i][j], end = '')
      new_line = 1
  if new_line == 1:
    print(" ")
    new_line = 0
      


Measured memory_bytes: 4596
#include <iostream>
#include <string>
#include <vector>
#include <string>
#include <algorithm>

using namespace std;

int main()
{
	int a, b;
	cin >> a >> b;
	
	int ans = a * b;

	if (ans % 2 == 0) {
		cout << "Even" << endl;
	}
	else {
		cout << "Odd" << endl;
	}
}

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

// n個の重複しない整数(min ~ max)の和としてsを表す組み合わせの数
int ci(int n, int s, int min, int max) {
  // 特殊なパターンを処理
  if (s < min || n < 1) return 0;
  if (n == 1) return (s > max)? 0: 1;
  
  // 最も小さい数で場合分けし再帰処理
  int r = 0;
  for (int i=min; i<s && i<=max; i++) r += ci(n - 1, s - i, i + 1, max);
  return r;
}

int main() {
  while (true) {
    int n, s;
    cin >> n >> s;
    if (!n && !s) break;
    cout << ci(n, s, 0, 9) << endl;
  }
  return 0;
}


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

int main()
{
    string str, str2;
    cin >> str >> str2;
    if (str == str2.substr(0, str.size()))
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    return 0;
}

Measured memory_bytes: 3624
#include<stdio.h>
#define max(m,n) ((m)>(n)?(m):(n))
#define min(m,n) ((m)>(n)?(n):(m))
int main()
{
	int a,b,c,d,e,f;
	while(scanf("%d%d%d%d",&a,&b,&c,&d)!=EOF)
	{
		if(a<b&&c<d)
		{
			e=max(a,c);
			f=min(b,d);
			if(f-e>0)
			printf("%d\n",f-e);
			else printf("0\n");
		}
		else printf("0\n");
	}
	return 0;
}

Measured memory_bytes: 128
#include <stdio.h>

int SumOf2_UpTo18(int sum);
int SumOf2_UpTo9(int sum);

int main(void)
{
    int sum;
    int cnt;
    while (scanf("%d", &sum) != EOF) {
        cnt = SumOf2_UpTo18(sum);
        printf("%d\n", cnt);
    }

    return 0;
}

int SumOf2_UpTo18(int sum)
{
    int k, l;
    int cnt = 0;
    int cnt_k, cnt_l;
    for (k = 0; k <= 18; k++) {
        if ((l = sum - k) >= 0 && l <= 18) {
            cnt_k = SumOf2_UpTo9(k);
            cnt_l = SumOf2_UpTo9(l);
            cnt += cnt_k * cnt_l;
        }
    }

    return cnt;
}

int SumOf2_UpTo9(int sum)
{
    int a, b;
    int cnt = 0;
    for (a = 0; a <= 9; a++) {
        if ((b = sum - a) >= 0 && b <= 9) {
            cnt++;
        }
    }

    return cnt;
}

Measured memory_bytes: 596
#include <iostream>
#include <functional>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <queue>
#include <map>
#include <iomanip>
#include <complex>
#include <random>
#include <bitset>
// #include <prettyprint.hpp>
using namespace std;
#define repi(i,n) for(int i=0;i<n;++i)
#define rep(i,n) for(ll i=0;i<n;++i)
#define repinvi(i,n) for(int i=n-1;i>=0;--i)
#define sll(n) scanf("%lld", &n);
#define sii(n) scanf("%d", &n);
#define slf(n) scanf("%lf", &n);
#define pll pair<ll,ll>
#define pii pair<int,int>
#define psi pair<si,si>
typedef long long ll;
typedef double lf;
typedef short int si;


void Main(){
    ll X, Y;
    sll(X);
    sll(Y);

    bool is_ok = false;
    for(ll i=0;i<=X;i++){
        ll j = X - i;
        is_ok = is_ok || (i*2 + j*4 == Y);
    }

    if(is_ok){
        cout << "Yes" <<endl;
    }else{
        cout << "No" <<endl;

    }

    


}

int main(){
    Main();
}

Measured memory_bytes: 3168
using System;
using System.Linq;
using CompLib.Util;

public class Program
{

    public void Solve()
    {
        var sc = new Scanner();
        int n = sc.NextInt();
        int k = sc.NextInt();
        int[] a = new int[n];
        long[] b = new long[n];
        for (int i = 0; i < n; i++)
        {
            a[i] = sc.NextInt();
            b[i] = sc.NextLong();
        }

        // k
        long ans = 0;
        for (int i = 0; i < n; i++)
        {
            if ((k & a[i]) == a[i]) ans += b[i];
        }

        // i桁目を0にして以下全部1

        for (int t = 0; t < 30; t++)
        {
            if ((k & (1 << t)) == 0) continue;
            int tmp = k - (1 << t);
            tmp |= (1 << t) - 1;

            long sum = 0;
            for (int i = 0; i < n; i++)
            {
                if ((tmp & a[i]) == a[i]) sum += b[i];
            }


            ans = Math.Max(ans, sum);
        }

        Console.WriteLine(ans);
    }

    public static void Main(string[] args) => new Program().Solve();
}

namespace CompLib.Util
{
    using System;
    using System.Linq;

    class Scanner
    {
        private string[] _line;
        private int _index;
        private const char Separator = ' ';

        public Scanner()
        {
            _line = new string[0];
            _index = 0;
        }

        public string Next()
        {
            if (_index >= _line.Length)
            {
                string s;
                do
                {
                    s = Console.ReadLine();
                } while (s.Length == 0);

                _line = s.Split(Separator);
                _index = 0;
            }

            return _line[_index++];
        }

        public string ReadLine()
        {
            _index = _line.Length;
            return Console.ReadLine();
        }

        public int NextInt() => int.Parse(Next());
        public long NextLong() => long.Parse(Next());
        public double NextDouble() => double.Parse(Next());
        public decimal NextDecimal() => decimal.Parse(Next());
        public char NextChar() => Next()[0];
        public char[] NextCharArray() => Next().ToCharArray();

        public string[] Array()
        {
            string s = Console.ReadLine();
            _line = s.Length == 0 ? new string[0] : s.Split(Separator);
            _index = _line.Length;
            return _line;
        }

        public int[] IntArray() => Array().Select(int.Parse).ToArray();
        public long[] LongArray() => Array().Select(long.Parse).ToArray();
        public double[] DoubleArray() => Array().Select(double.Parse).ToArray();
        public decimal[] DecimalArray() => Array().Select(decimal.Parse).ToArray();
    }
}


Measured memory_bytes: 46860
#include <iostream>

using namespace std;
int main()
{
   int a, b, c, d;
   for(d=1; d<=3000; d++)
   
   {
     cin >> a >> b;
     if(a==0 && b==0)
       break;
       
     if(a > b)
     {
       c = a;
       a = b;
       b = c;
     }
     cout << a << " " << b << endl;
   }
}


Measured memory_bytes: 3080
N, C = gets.split.map(&:to_i)
progs = []
N.times do
  r = gets.split.map(&:to_i)
  progs << [r[0]*2, r[1]*2, r[2]]
end

progs.sort!

recorders = []

progs.each do |s, t, c|
  best_index = nil
  best_diff = 1e100
  recorders.each_with_index do |r, i|
    rt, rc = *r
    if c != rc
      rt += 1
    end
    if rt <= s
      diff = s - rt
      if best_diff > diff
        best_diff = diff
        best_index = i
      end
    end
  end

  if !best_index
    best_index = recorders.size
    recorders << [0, 0]
  end

  recorders[best_index] = [t, c]
end

p recorders.size


Measured memory_bytes: 10616
#include<bits/stdc++.h>
//#pragma GCC optimize("Ofast","no-stack-protector","unroll-loops")
//#pragma GCC target("sse,sse2,sse3,ssse3,sse4,sse4.2,popcnt,abm,mmx,avx")
//#include<bits/extc++.h>
//using namespace __gnu_pbds;
using namespace std;
#define F(i,L,R) for (int i = L; i < R; i++)
#define FE(i,L,R) for (int i = L; i <= R; i++)
#define getI(a) scanf("%d", &a)
#define getII(a,b) scanf("%d%d", &a, &b)
#define getIII(a,b,c) scanf("%d%d%d", &a, &b, &c)
#define VgetI(n) int (n); scanf("%d",&(n))
#define VgetII(n,m) int (n),(m); scanf("%d %d",&(n),&(m))
#define VgetIII(n,m,k) int (n),(m),(k); scanf("%d %d %d",&(n),&(m),&(k))
#define debug(x) cout<<(#x)<<"="<<x<<"\n";
#define pb push_back
#define pii pair<int,int>
#define mp make_pair
#define f first
#define s second
#define ll long long
#define INF 2000000000
int ans[100005];
int main(){
        int n;
        while(~getI(n)){
                FE(i,1,n){
                        VgetI(x);
                        ans[x]=i;
                }
                FE(i,1,n) printf("%d ",ans[i]);
                puts("");
        }
}

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

int main() {
  int N, A, x;
  cin >> N >> A;
  x = N % 500;
  if (x <= A) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
  return 0;
}


Measured memory_bytes: 256
//模範解答？
#include <iostream>
using namespace std;

//flagを用いたバブルソート
int bubbleSort(int a[], int n)
{
    int sw = 0;
    bool flag = 1;
    for(int i = 0; flag; i++){
      flag = 0;
      for(int j = n-1; j >= i+1; j--){
        if(a[j] < a[j-1]){
          //隣接要素を交換する
          swap(a[j], a[j-1]);
          flag = 1;
          sw++;
        }
      }
    }
    return sw;
}

int main()
{
    int a[100], n, sw;
    cin >> n;

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

    sw = bubbleSort(a, n);

    for(int i = 0; i<n; i++){
      if(i) cout << " ";
      cout << a[i];
    }
    cout << endl;
    cout << sw << endl;

    return 0;
}


Measured memory_bytes: 3136
N,M=map(int,input().split())
X=[[int(i) for i in input().split()] for i in range(N)]
X.sort()
t=M
ans=0
for a,b in X:
    if t>b:
        ans+=a*b
        t-=b
    else:
        ans+=a*t
        break
print(ans)

Measured memory_bytes: 21604
#include<bits/stdc++.h>
#define fast ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define ll long long
using namespace std;
void solve()
{
    string s,t;
    int cnt=0;
    cin>>s>>t;
    for(int i=0;i<s.length();++i)
    {
        if(s[i]!=t[i]){
            cnt++;
        }
    }
    cout<<cnt<<endl;
}

int main()
{
    fast;
    int t;
    solve();
}



Measured memory_bytes: 3828
#include <iostream>
#include <algorithm>
#include <vector>
#include <math.h>
using namespace std;
int main() {
    //freopen("input.txt", "r", stdin);
    int n, k;
    cin >> n >> k;
    int a[1000];
    for (int i = 0; i < n; i++)
        cin >> a[i];
    sort(a, a + n);
    int sum = 0;
    for (int i = 0; i < k; i++) {
        sum += a[i];
    }
    cout << sum;
    return 0;
}

Measured memory_bytes: 3640
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <queue>
#include <algorithm>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <string>
#include <cstring>
#include <complex>
#include <ctime>
#include <cstdlib>

using namespace std;

inline int to_int(string s) {int v; istringstream sin(s); sin >> v; return v;}
template<class T> inline string to_str(T x) {ostringstream sout; sout << x; return sout.str();}

typedef long long ll;

int main()
{
	string sent;
	vector<string> word;
	int st = 0, ed, cnt = 0;

	getline(cin , sent);

	while(1)
	{
		if(cnt > sent.size())
		{
			break;
		}
		if( (sent[cnt] == ',' || sent[cnt] == ' ' || sent[cnt] == '.') && st != -1)
		{
			if((cnt-st) >= 3 && (cnt-st) <= 6)
			{
				word.push_back(sent.substr(st, cnt-st));
			}
			st = -1;
		}
		else if( (sent[cnt] != ',' && sent[cnt] != ' ' && sent[cnt] != '.') ) 
		{
			if(st == -1)
			{
				st = cnt;
			}
		}
		cnt++;
	}

	for(int i = 0; i < word.size(); i++)
	{
		printf("%s%c", word[i].c_str(), (i == word.size()-1)?'\n':' ');
	}

}

Measured memory_bytes: 1196
#include<iostream>
#include<utility>
#include<string>
#include<vector>
#include<map>

using namespace std;
#define cerr cerr << "[DBG] "
#define DBG(x) cerr << #x << ": " << x << endl
// http://genkisugimoto.com/jp/blog/procon/2015/04/15/print-debug-technique-in-cpp.html
template<typename T1, typename T2> ostream& operator<<(ostream& s, const pair<T1, T2>& p) {return s << "(" << p.first << ", " << p.second << ")";}

template<typename T> ostream& operator<<(ostream& s, const vector<T>& v) { for (int i = 0; i < v.size(); ++i) { s << v[i]; if (i < v.size() - 1) s << "\t"; } return s; }

typedef long long ll;

main(){
	ll h, w, n;
	cin >> h >> w >> n;
	vector<pair<int,int>> v;
	for(int i=0;i<n;i++){
		int a,b;
		cin >> a >> b;
		v.push_back(make_pair(a-1,b-1));
	}
	map<pair<ll,ll>, ll> m;
	for(int i=0;i<n;i++){
		for(int dy=-1;dy<=1;dy++){
			for(int dx=-1;dx<=1;dx++){
				ll fx = v[i].second + dx;
				ll fy = v[i].first + dy;
				if(fx <= 0 || fx >= w-1 ||
						fy <= 0 || fy >= h-1) continue;
				auto p = make_pair(fx,fy);
				if(m.find(p)!=m.end()){
					m[p]++;
				}
				else{
					m[p]=1;
				}
			}
		}
	}
	vector<ll> result(10,0);
	ll sum = 0;
	for(auto itr=m.begin(); itr!=m.end();itr++){
		result[itr->second] += 1;
		sum++;
	}
	result[0] = (h-2)*(w-2)-sum;

	for(int i=0; i<10; i++){
		cout << result[i] << endl;
	}
}


Measured memory_bytes: 57332
#include <iostream>

using namespace std;

int main(){

  int N,A,B;
  int out = 0;
  
  cin >> N >> A >> B;

  for(int i = 1; i <= N; i++){
    int num = i;
    int sum = 0; 
    while(num){
      sum += num % 10;
      num = num / 10;
    }
    if((A <= sum) && (sum <= B)){
      out += i;
    }
  }

  cout << out << "\n";
  
  return 0;
}


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

using namespace std;

#define all(x) x.begin(), x.end()
typedef long long ll;
typedef vector<int> vi;
typedef vector<vi> vvi;

const int mod = 1e9;
const int maxn = 55;
int a[maxn], n, k;

int g(int l, int r){
    if(l + r > k || l + r > n || l + r == 0)
        return -mod;
    vi v;
    for(int i = 0; i < l; i++) v.push_back(a[i]);
    for(int i = 0; i < r; i++) v.push_back(a[n - i - 1]);
    int sum = accumulate(v.begin(), v.end(), 0);
    sort(v.begin(), v.end());
    for(int i = 0; i < k - l - r && i < v.size(); i++){
        if(v[i] >= 0)
            break;
        sum -= v[i];
    }
    return sum;
}

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

    cin >> n >> k;
    for(int i = 0; i < n; i++)
        cin >> a[i];
    int res = 0;
    for(int i = 0; i < n + 1; i++)
        for(int j = 0; j < n + 1; j++)
            res = max(res, g(i, j));
    cout << res;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <numeric>
#define rep(i,n) for (int i = 0; i < n; ++i)
#define rep1(i,n) for (int i = 1; i <= n; ++i)
template<typename T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
template<typename T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int,int> P;
const long long MOD = 1e9+7;
template<typename T> inline void add(T& a, T b) { a += b; if (a >= MOD) a -= MOD; }

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

  ll N,K; cin >> N >> K;
  if(N == K) {
    cout << 0 << endl;
    return 0;
  }

  if(N > K) {
    N %= K;
  }

  if(K - N < N) {
    cout << K - N << endl;
  } else {
    cout << N << endl;
  }
}

// 4 6
// 2 6

// 3 6
// 3 6

// 2 6
// 4 6

// 4 7
// 3

// 15 7
// 8
// 1


Measured memory_bytes: 256
/*************************************
 * problem:      AT2165 Median Pyramid Hard. 
 * user ID:      63720.
 * user name:    Jomoo.
 * time:         2019-08-13.
 * language:     C++.
 * upload place: Luogu.
*************************************/ 

#include <bits/stdc++.h>
using namespace std;

typedef signed char          int8;
typedef unsigned char       uint8;
typedef short                int16;
typedef unsigned short      uint16;
typedef int                  int32;
typedef unsigned            uint32;
typedef long long            int64;
typedef unsigned long long  uint64;

template <typename Int>
inline Int read()       
{
    Int flag = 1;
    char c = getchar();
    while ((!isdigit(c)) && c != '-') c = getchar();
    if (c == '-') flag = -1, c = getchar();
    Int init = c & 15;
    while (isdigit(c = getchar())) init = (init << 3) + (init << 1) + (c & 15);
	return init * flag;
}

template <typename Int>
inline void write(Int x)
{
    if (x < 0) putchar('-'), x = ~x + 1;
    if (x > 9) write(x / 10);
    putchar((x % 10) | 48);
}  

template <typename Int>
inline void write(Int x, char nextch)
{
    write(x);
    putchar(nextch);
}

int n, a[200000 + 7];

int turn(int Id1, int Id2, int MidNum) 
{
    return (a[Id1] >= MidNum) + (a[Id2] >= MidNum);
}

bool check(int lim)
{
    for (int i = 0; i < n - 1; i++) {
        if (turn(n - i, n - i - 1, lim) == 2 || turn(n + i, n + i + 1, lim) == 2) return true;
        if (turn(n - i, n - i - 1, lim) == 0 || turn(n + i, n + i + 1, lim) == 0) return false;
    }
    return a[1] >= lim;
}

int main()
{
    n = read<int>();
    for (int i = 1; i <= 2 * n - 1; i++) 
        a[i] = read<int>();
    int l = 1, r = 2 * n - 1, mid, ans = -1;
    while (l <= r) {
        mid = (l + r) >> 1;
        if (check(mid)) l = mid + 1, ans = mid;
        else r = mid - 1;
    }
    write(ans);
    return 0;
}

Measured memory_bytes: 1024
#coding:utf-8
import sys
sys.setrecursionlimit(10**6)
write = sys.stdout.write
dbg = lambda *something : print(*something) if DEBUG else 0
DEBUG = False
def main(given = sys.stdin.readline):
    input = lambda : given().rstrip()
    LMIIS = lambda : list(map(int,input().split()))
    II = lambda : int(input())
    XLMIIS = lambda x : [LMIIS() for _ in range(x)]


    N, K, Q = LMIIS()
    scores = [0] * N
    for _ in range(Q):
        a = II() - 1
        scores[a] += 1
    sumscore = sum(scores)

    for s in scores:
        print('Yes') if K + s  - sumscore > 0 else print('No')
    
    



if __name__ == '__main__':
    main()

Measured memory_bytes: 47580
#include<iostream>
#include<string>
#include<cstdio>

using namespace std;

int main() {
	int n, c1 = 0, c2 = 0;
	string s1, s2;
	cin >> n;
	for (int i = 0; i < n; i++) {
	    cin >> s1 >> s2;
	    if (s1 > s2) c1 += 3;
	    else if (s2 > s1) c2 += 3;
	    else {
	        c1++;
	        c2++;
	    }
	}
	cout << c1 << " " << c2 << endl;
	return 0;
}


Measured memory_bytes: 3144
#include <bits/stdc++.h>
using namespace std;
/*{{{*/  //template
#define rep(i,n) for(int i=0;i<(int)(n);i++)
constexpr int INF = numeric_limits<int>::max()/2;
constexpr long long LINF = numeric_limits<long long>::max()/3;
#define mp make_pair
#define pb push_back
#define eb emplace_back
#define fi first
#define se second
#define all(v) (v).begin(),(v).end()
#define sz(x) (int)(x).size()
#define debug(x) cerr<<#x<<":"<<x<<endl
#define debug2(x,y) cerr<<#x<<","<<#y":"<<x<<","<<y<<endl
//struct fin{ fin(){ cin.tie(0); ios::sync_with_stdio(false); } } fin_;
struct Double{ double d; explicit Double(double x) : d(x){} };
ostream& operator<<(ostream& os,const Double x){ os << fixed << setprecision(20) << x.d; return os; }
template<typename T> ostream& operator<<(ostream& os,const vector<T>& vec){ os << "["; for(const auto& v : vec){ os << v << ","; } os << "]"; return os; }
template<typename T,typename U> ostream& operator<<(ostream& os,const pair<T,U>& p){ os << "(" << p.first << ","<< p.second <<")"; return os; }
template<typename T> ostream& operator<<(ostream& os,const set<T>& st){ os<<"{"; for(T v:st) os<<v<<","; os <<"}"; return os; }
template<typename T,typename U> inline void chmax(T &x,U y){ if(y>x) x = y; }
template<typename T,typename U> inline void chmin(T &x,U y){ if(y<x) x = y; }
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
typedef vector<int> vi;
typedef vector<vi> vvi;
ll gcd(ll a,ll b){ if(b==0) return a; else return gcd(b,a%b); }
//constexpr double eps = 1e-14; 
constexpr double eps = 1e-10; 
constexpr ll mod = 1e9+7;
const int dx[]={1,0,-1,0} ,dy[] = {0,1,0,-1};
/*}}}*/

struct P{
    int len,i,j;
    char c;
    P(){ len = 0; i = j = -1; c = 0;}
};

P dp[3003][3003];

int main(){
    string s,t; cin >> s >> t;

    dp[0][0] = P();
    for(int i=0;i<s.size();i++){
        for(int j=0;j<t.size();j++){
            if(s[i] == t[j]){
                dp[i+1][j+1] = dp[i][j];
                dp[i+1][j+1].len++;
                dp[i+1][j+1].c = s[i];
                dp[i+1][j+1].i = i;
                dp[i+1][j+1].j = j;
            }else{
                if(dp[i+1][j].len >= dp[i][j+1].len){
                    dp[i+1][j+1] = dp[i+1][j];
                    dp[i+1][j+1].i = i+1;
                    dp[i+1][j+1].j = j;
                }else{
                    dp[i+1][j+1] = dp[i][j+1];
                    dp[i+1][j+1].i = i;
                    dp[i+1][j+1].j = j+1;
                }
                dp[i+1][j+1].c = 0;
            }
        }
    }


    int i=s.size();
    int j=t.size();
    string ans = "";
    while(1){
        int ii = i , jj = j;
        if(dp[i][j].c == 0){
            i = dp[ii][jj].i;
            j = dp[ii][jj].j;
        }else{
            ans.push_back(dp[i][j].c);
            i = dp[ii][jj].i;
            j = dp[ii][jj].j;
        }
        if(i==-1 or j==-1) break;
    }
    reverse(all(ans));
    cout << ans << endl;
}


Measured memory_bytes: 141184
#シェルソート
def insertionSort(A, n, g):
    global cnt
    for i in range(g, n):
        #その間隔で比較できる最も左から始める.vが基準値
        v = A[i]
        j = i - g 
        while j >= 0 and A[j] > v:
            A[j+g] = A[j]
            j -= g
            cnt += 1
        A[j+g] = v

n = int(input())
A = [int(input()) for i in range(n)]

cnt = 0
G = [1]
for i in range(100):
    if n < 1 + 3*G[-1]:
        break
    G.append(1+3*G[-1])
m = len(G)
G.reverse()

for i in range(m):
    insertionSort(A, n, G[i])

print(m)
print(*G)
print(cnt)
print(*A, sep='\n')


Measured memory_bytes: 53284
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <deque>
#include <fstream>
#include <functional>
#include <iostream>
#include <limits>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>
using namespace std;
using ll = long long;
#define fst first
#define snd second

/* clang-format off */
template <class T, size_t D> struct _vec { using type = vector<typename _vec<T, D - 1>::type>; };
template <class T> struct _vec<T, 0> { using type = T; };
template <class T, size_t D> using vec = typename _vec<T, D>::type;
template <class T> vector<T> make_v(size_t size, const T& init) { return vector<T>(size, init); }
template <class... Ts> auto make_v(size_t size, Ts... rest) { return vector<decltype(make_v(rest...))>(size, make_v(rest...)); }
template <class T> inline void chmin(T &a, const T& b) { if (b < a) a = b; }
template <class T> inline void chmax(T &a, const T& b) { if (b > a) a = b; }
/* clang-format on */

template <class T>
vector<T> sumup(const vector<T>& a) {
  int N = a.size();
  vector<T> res(N + 1);
  for (int i = 0; i < N; i++) res[i + 1] = res[i] + a[i];
  return res;
}

template <class T>
ll invs(vector<T>& A) {
  ll res = 0;
  int N = A.size();
  if (N > 1) {
    vector<T> X(A.begin(), A.begin() + N / 2);
    vector<T> Y(A.begin() + N / 2, A.end());
    res += invs(X);
    res += invs(Y);
    int ai = 0, xi = 0, yi = 0;
    while (yi < Y.size()) {
      while (xi < X.size() && X[xi] <= Y[yi]) A[ai++] = X[xi++];
      A[ai++] = Y[yi++];
      res += X.size() - xi;
    }
    while (xi < X.size()) A[ai++] = X[xi++];
  }
  return res;
}

int main() {
#ifdef DEBUG
  ifstream ifs("in.txt");
  cin.rdbuf(ifs.rdbuf());
#endif
  int N;
  ll K;
  while (cin >> N >> K) {
    vector<ll> A(N);
    for (ll& x : A) {
      cin >> x;
      x -= K;
    }
    auto S = sumup(A);
    ll res = 1ll * N * (N + 1) / 2 - invs(S);
    cout << res << endl;
  }
  return 0;
}


Measured memory_bytes: 6528
#include <iostream>
using namespace std;
int main(){
	int a,b,num1,num2,num3,max=-100000;
	cin >> a >> b;
	num1 = a+b;
	num2 = a-b;
	num3 = a*b;
	if (num1>max)max = num1;
	if (num2>max)max = num2;
	if (num3>max)max = num3;
	cout << max << endl;
	return 0;
	}


Measured memory_bytes: 256
/*
	submission # - User: herp_sy
	https://atcoder.jp/contests/
*/

#include <bits/stdc++.h>
using namespace std;

// utility of stdin,stdout
#define _CRT_SECURE_NO_WARNINGS
#define OUT cout << 
#define BR << endl
#define RET return 0
#define TLong long long
#define TBMod 1000000007

int main(int argc, char const *argv[]){
	int a,b;
	cin >> a >> b;
	OUT(max({a + b, a * b, a - b})) BR;
}


Measured memory_bytes: 256
import java.util.*;
import java.io.*;
public class Main {
    static InputStreamReader r;
    public static void main(String[] args) throws Exception {
        r = new InputStreamReader(System.in);
        int N = nextInt();
        int M = nextInt();

        long LCM = 1;
        int cnt1 = 0;
        for (int i = 0; i < N; i++) {
            int Ai = nextInt();
            LCM = Ai > LCM ? LCM/GCD(Ai, LCM)*Ai : LCM/GCD(LCM, Ai)*Ai;
            if (i == 0) {
                while (Ai%2 == 0) {
                    Ai = Ai/2;
                    cnt1++;
                }
            } else {
                int cnt2 = 0;
                while (Ai%2 == 0) {
                    Ai = Ai/2;
                    cnt2++;
                }
                if (cnt1 != cnt2) {
                    LCM = Long.MAX_VALUE;
                    break;
                }
            }
        }

        long ans = (M/(LCM/2)+1)/2;
        System.out.println(ans);
    }

    public static long GCD(long l, long s) {
        return s == 0 ? l : GCD(s, l%s);
    }

    public static String nextString() throws Exception {
        String res = "";
        while (true) {
            int c = r.read();
            if (c == 32 || c == 10 || c == -1) {
                break;
            }
            res += (char)c;
        }
        return res;
    }

    public static int nextInt() throws Exception {
        return Integer.parseInt(nextString());
    }

    public static long nextLong() throws Exception {
        return Long.parseLong(nextString());
    }
}


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

int main(){

  int n,m;
  cin>>n>>m;
  int a[n],b[n],c[m],d[m];
  for(int i=0;n>i;i++){  
    cin>>a[i]>>b[i];}
  for(int i=0;m>i;i++){
    cin>>c[i]>>d[i];}
  for(int i=0;n>i;i++){
    int k=1e9,o;
    for(int j=0;m>j;j++){
      int l=abs<int>(a[i]-c[j])+abs<int>(b[i]-d[j]);
      if(k>l){
	k=l;
	   o=j;}
    }
    cout<<o+1<<endl;
  } 
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		StringBuilder ans = new StringBuilder();
		while(in.hasNext()) {
			String x = in.next();
			if(x.contains("apple"))
				ans.append(x.replace("apple","peach")).append(" ");
			else if(x.contains("peach"))
				ans.append(x.replace("peach","apple")).append(" ");
			else
				ans.append(x).append(" ");
		}
		System.out.println(ans.toString().trim());
	}
}

Measured memory_bytes: 12000
using System;

public class Watch {
  static int Main(string[] args)
  {
    int inputData = int.Parse(Console.ReadLine());
    int hours = inputData / 3600;
    int minutes = (inputData - hours * 3600) / 60;
    int seconds = inputData - (hours * 3600) - (minutes * 60);
    Console.WriteLine("{0}:{1}:{2}", hours, minutes, seconds);
    return 0;
  }
}


Measured memory_bytes: 9256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

ll a[3002];
ll gcd(ll l ,ll r){
	if(r==0){
		return l;
	}
	return gcd(r,l%r);
}
int main() {
	ll n;
	cin>>n;
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	ll LMC=a[0];
	for(int i=1;i<n;i++){
		ll GCD=gcd(max(LMC,a[i]),min(LMC,a[i]));
		LMC=LMC/GCD*a[i];
	}
	LMC--;
	ll ans=0;
	for(int i=0;i<n;i++){
		ans+=LMC%a[i];
	}
	ans=0;
	for(int i=0;i<n;i++){
		ans+=a[i];
	}
	cout <<ans-n;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
N = int(input())
F = [list(map(int, input().split())) for _ in range(N)]
P = [list(map(int, input().split())) for _ in range(N)]

max_first, max_second = 0, 0

max_v = -float("inf")
for p in range(1, 1 << 10):
	v = 0
	for n in range(N):
		c = 0
		for m in range(10):
			c += (p & 1 << m != 0) & (F[n][m])
		v += P[n][c]
	max_v = max(max_v, v)

print(max_v)


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

using namespace std;

#define fi first
#define se second
#define pb push_back
#define sz(x) ((int)(x).size())
#define whole(x) (x).begin(), (x).end()

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

const int N = 1000005;
const int LG = 20;
const ll mod = (int)1e9 + 7;
const int INF = (int)1e9 + 7;
const ll linf = 1e16;
const ld pi = acos(-1);
const int base = 10;
const ld EPS = 1e-9;

int x, y;
ll f[N], finv[N], inv[N];

void mod_inverse ()
{
    f[0] = f[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < N; ++i)
    {
        f[i] = (f[i - 1] * i) % mod;
        inv[i] = mod - inv[mod % i] * (mod / i) % mod;
        finv[i] = (finv[i - 1] * inv[i]) % mod;
    }
}

ll GetMod (ll m, ll k)
{
    if (m < k) return 0;
    if (m < 0 || k < 0) return 0;
    return f[m] * ((finv[k] * finv[m - k]) % mod) % mod;
}

int main ()
{
    scanf ("%d %d", &x, &y);

    if ((x + y) % 3 != 0) return !printf ("0\n");
    int kol = (x + y) / 3;
    if (x - kol < 0 || 2 * 1ll * kol - x < 0) return !printf ("0\n");
    mod_inverse();

    printf ("%lld\n", GetMod(kol, x - kol));
    return 0;
}


Measured memory_bytes: 23808
import java.util.Scanner;
class Main
{

	public static void main(String[] args) {
		Scanner sc=new Scanner(System.in);
		String s1=sc.next();
		int len=s1.length();
		if(s1.charAt(len-1)=='s')
		{
			s1=s1.concat("es");
		}
		else
		{
			s1=s1.concat("s");
		}
		System.out.println(s1);
	}

}


Measured memory_bytes: 27016
import java.util.*;
public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    int count = 0;
    int[] ary = new int[n];
    for(int c = 0;c<n;c++){
      ary[c] = sc.nextInt();
    }
    for(int c = 1;c<n-1;c++){
      if(ary[c]>ary[c-1]&&ary[c+1]>ary[c]){
        count++;
      }else if(ary[c+1]<ary[c]&&ary[c]<ary[c-1]){
        count++;
      }
    }
    System.out.println(count);
  } 
}

Measured memory_bytes: 23636
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

int main()
{
	int n, m;
	cin >> n >> m;
	vector<int> ai(m, 0);
	rep(i, m)
	{
		cin >> ai.at(i);
		n -= ai.at(i);
		if (n < 0)
		{
			n = -1;
			break;
		}
	}

	cout << n << endl;
	return 0;
}

Measured memory_bytes: 3584
import math
import sys

x = int(input())
# aは正の数とする
# bが負の場合
max_a = math.floor(x ** (1/5))
for i in range(max_a,-1,-1):
    b5 = x - (i ** 5)
    b = round(b5 ** (1/5), 5)
    if b.is_integer():
        print(i,int(-1 * b))
        sys.exit()
# bが正の場合
for i in range(120):
    for j in range(i + 1, 120):
        if j**5 - i**5 == x:
            print(j, i)
            sys.exit()

Measured memory_bytes: 9388
#include <stdio.h>

int main(void)
{
	char s[10];
	int cut = 0;
	
	scanf("%s",s);
	if(s[0]=='1')	 cut++;
	if(s[1]=='1')    cut++;
	if(s[2]=='1')    cut++;
	printf("%d\n",cut);

	return 0;
}

Measured memory_bytes: 128
N = int(input())
A = list(map(int, input().split()))

cnt = len([a for a in A if a < 0])
if cnt % 2 == 0:
    print(sum([abs(a) for a in A]))
else:
    ans = sum([abs(a) for a in A])
    M = float('inf')
    for a in A:
        if abs(a) < M:
            M = abs(a)
    print(ans - 2 * M)


Measured memory_bytes: 20088
#include <iostream>
using namespace std;
int n,m,f[61][61];
bool map[61][61];
char x;
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)
	for(int j=1;j<=m;j++)
	{
		cin>>x;
		if(x=='#') map[i][j]=1;
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=m;j++)
		{
			if(!map[i][j])
			cout<<map[i-1][j-1]+map[i-1][j]+map[i-1][j+1]+map[i][j-1]+map[i][j+1]+map[i+1][j-1]+map[i+1][j]+map[i+1][j+1];
			else
			cout<<'#';
		}
		cout<<endl;
	}
	return 0;
}

Measured memory_bytes: 256
import java.io.*;
class Main{
	public static void main(String args[])throws Exception{
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		
		String str = br.readLine();
		String array[] = str.split(" ");
		
		int x = Integer.parseInt(array[0]);
		int y = Integer.parseInt(array[1]);
		int z = Integer.parseInt(array[2]);
		
		if( x < y && y < z){
			System.out.println("Yes");
			}else{
			System.out.println("No");
			}
			}
			}

Measured memory_bytes: 24208
fun main(args: Array<String>) {
    fun ncr2(n: Long): Long {
        return ((n * n) - n) / 2L
    }
    val n = readLine()?.toInt() ?: return
    val aList = readLine()?.split(" ")?.map(String::toInt) ?: return

    val map = hashMapOf<Int, Long>()
    aList.forEach { a ->
        map[a] = map[a]?.let { it + 1L } ?: 1L
    }
    var sum = 0L
    map.values.forEach {
        sum += ncr2(it)
    }

    for (i in aList.indices) {
        val decrementValue = aList[i]
        val size = map[decrementValue] ?: 0L
        if (size > 1L) {
            println(sum - (ncr2(size) - ncr2(size - 1)))
        } else {
            println(sum)
        }
    }
}


Measured memory_bytes: 102908
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef vector<ll> vll;
#define all(x) (x).begin(), (x).end()
#define endl '\n'
#define fsp(x) cout << fixed << setprecision(x)
const ll inf = LLONG_MAX;
const long double pi = M_PI;
void Yes() {cout << "Yes" << endl;}
void No() {cout << "No" << endl;}
void YES() {cout << "YES" << endl;}
void NO() {cout << "NO" << endl;}

int main() {
  string s;
  cin >> s;
  ll n = s.size();

  ll move_to = n - 1, ans = 0;
  for (ll i = 0; i < n; i++) {
    if (s[n - 1 - i] == 'B') {
      ans += move_to - (n - 1 - i);
      move_to--;
    }
  }
  cout << ans << endl;
}

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

using namespace std;

//----------------------- Print Function ----------------------//

inline void print() {
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest) {
    cout << first << ' ';
    print(rest...);
}

//------------------------- Libraries -------------------------//

//--------------------------- Solve ---------------------------//

void solve() {
    int N; cin >> N;
    map<int, int> mp;
    for (int i = 0; i < N; i++) {
        int a; cin >> a;
        mp[a]++;
    }

    int ans = 0;
    for (auto e : mp) {
        if (e.first <= e.second) ans += e.second - e.first;
        else ans += e.second;
    }

    cout << ans << '\n';
}

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

    solve();

    return 0;
}

Measured memory_bytes: 8064
#include <bits/stdc++.h>
using namespace std;
int main(){
	char data[4]={'m','c','x','i'};
	int n,num[4]={1000,100,10,1};
	cin>>n;
	while(n--){
		int sum=0;
		string s,ans="";
		for(int times=0;times<2;times++){
			cin>>s;
			for(int i=0;i<s.size();i++){
				for(int j=0;j<4;j++){
					if(s[i]==data[j]){
						if(i>0&&s[i-1]-'0'<10){
							sum+=num[j]*(s[i-1]-'0');
						}else{
							sum+=num[j];
						}
					}
				}
			}
		}
		int digit=1000;
		for(int i=0;i<4;i++){
			if(sum/digit>1){
				ans+=(char)((sum/digit)+'0');
				ans+=data[i];
				sum%=digit;
			}else if(sum/digit==1){
				ans+=data[i];
				sum%=digit;
			}
			digit/=10;
		}
		cout<<ans<<endl;
	}
}

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

int K;
string t;

int dfs(string s, int d, int k) {
    if (s == t) return d;

    int diff = t[k] - s[k];
    if (diff == 0) {
        return dfs(s, d, k+1);
    }
    int ret = 1111;
    for (int i = k; i < K; i++) {
        s[i] = (char)((10 + diff + s[i] - '0')%10 + '0');
        ret = min(ret, dfs(s, d+1, k+1));
    }

    return ret;
}

int main() {
    while (cin >> K, K) {
        string s;
        cin >> s >> t;
        cout << dfs(s, 0, 0) << endl;
    }

    return 0;
}

Measured memory_bytes: 3152
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
using namespace std;
int main()
{
    int a,b,c,k;
    cin>>a>>b>>c>>k;
    int x=max((a,b),c);
    int t=x;
    for(int i=0;i<k;i++)
    {
        t*=2;
    }
    cout<<a+b+c-x+t;   
    //system("pause");
    return 0;
}
    

Measured memory_bytes: 256
import java.util.Scanner;

class Main{
	public static void main(String[] ars) {
		Scanner sc=new Scanner(System.in);
		int Hour=sc.nextInt();
		int wa=sc.nextInt();
		int a=sc.nextInt();

		if(Hour*wa>a) {
			System.out.println(a);
		}

		else if(Hour*wa<=a) {
			System.out.println(Hour*wa);
		}
	}
}

Measured memory_bytes: 21716
A = int(input())
B = int(input())
C = int(input())
X = int(input())
cnt = 0
for a in range(A+1):
    for b in range(B+1):
        for c in range(C+1):
            if (a*500+b*100+c*50) == X:
                cnt += 1
print(cnt)

Measured memory_bytes: 67656
// 問題の URL を書いておく
// 

#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <iostream>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <vector>

using namespace std;

//#define ENABLE_PRINT

#if defined(ENABLE_PRINT)

#define Print(v) \
do {\
    cout << #v << ": " << v << endl; \
}while(0)

#define PrintVec(v) \
do {\
    for(int __i = 0; __i < v.size(); ++__i) \
    { \
        cout << #v << "[" << __i << "]: " << v[__i] << endl; \
    }\
}while(0)

#else

#define Print(v) ((void)0)
#define PrintVec(v) ((void)0)

#endif

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

int main(int, const char**)
{
    int n;
    cin >> n;
    vector<int> a(n);
    int64_t totalA = 0;
    rep(i, n)
    {
        cin >> a[i];
        totalA += a[i];
    }
    int64_t totalB = 0;
    int64_t bFitCount = 0;
    int64_t aFitCount = 0;
    rep(i, n)
    {
        int64_t b;
        cin >> b;
        totalB += b;
        if(a[i] - b > 0)
        {
            bFitCount += a[i] - b;
        }
        else
        {
            aFitCount += (b - a[i] + 1) / 2;
        }
    }
    auto tryNum = totalB - totalA;
    if(tryNum >= 0 && bFitCount <= tryNum && aFitCount <= tryNum)
    {
        cout << "Yes" << endl;
    }
    else
    {
        cout << "No" << endl;
    }

    return 0;
}


Measured memory_bytes: 3672
import sys, re, os
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, radians
from itertools import permutations, combinations, product, accumulate
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from heapq import heapify, heappop, heappush
from fractions import gcd
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def S_MAP(): return map(str, input().split())
def LIST(): return list(map(int, input().split()))
def S_LIST(): return list(map(str, input().split()))
 
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10 ** 9 + 7

def lcm(a, b):
    y = a*b / gcd(a, b)
    return int(y)


A, B, C, D = MAP()
# print(gcd(C, D))
def f(N):
    a = N // C
    b = N // D
    c = N // lcm(C, D)
    # print(a, b, c)
    return N - (a + b - c)
print(f(B)-f(A-1))
# print(f(B))
# print(f(A-1))

Measured memory_bytes: 5192
import java.util.*;
import java.util.Map.Entry;
 
class Main {
	 static int mod =  (int) (Math.pow(10,9)+7);
//	 static int mod = 998244353;
   public static void main(String[] args) {
	   
       Scanner sc = new Scanner(System.in);
       int  N = sc.nextInt();
       

       int[] c = new int[N];
       int[] s = new int[N];
       int[] f = new int[N];
       for (int i=0 ; i<N-1; i++) {
           c[i] = sc.nextInt();
           s[i] = sc.nextInt();
           f[i] = sc.nextInt();
       }
       
       int sum=0;
       int[] ans=new int[N];
       for(int i=0;i<N-1;i++) {
    	   sum=0;
           for(int j=i;j<N-1;j++) {
        	   int tmp=0;
        	   if(sum%f[j]!=0) {
        		   tmp=f[j]-sum%f[j];
        	   }
        	   sum=Math.max(sum+(tmp), s[j]);
        	   sum=sum+c[j];        	   
           }
           ans[i]=sum;
       }
       
       for(int i=0;i<N;i++) {
    	   System.out.println(ans[i]);
       }
   }
}

Measured memory_bytes: 26592
from _collections import deque
n,m=map(int,input().split())
edg=[[] for i in range(n+1)]
for i in range(m):
    a,b=map(int,input().split())
    edg[a].append(b)
    edg[b].append(a)
dep=[-1]*(n+1)
dep[1]=0
data=deque([1])
while len(data)>0:
    p=data.popleft()
    for i in edg[p]:
        if dep[i]==-1:
            dep[i]=dep[p]+1
            data.append(i)
print("POSSIBLE" if dep[n]==2 else "IMPOSSIBLE")



Measured memory_bytes: 111816
import java.util.Scanner;

public class Main {
	/**
	 * TODO : ただの再帰ではなく、バランスを取らなければならない
	 *　これは手戻りが発生する 
	 * 
	 * @author Taichiro
	 *
	 */
	public static class Node{
		Node left, right;
		long l_dist, r_dist;
		long weight;
		
		public Node(long l_dist, long r_dist) {
			super();
			this.l_dist = l_dist;
			this.r_dist = r_dist;
			this.weight = 0;
		}
		
		public long solve(){
			if(this.weight != 0){
				return this.weight;
			}
			
			if(this.left == null && this.right == null){
				final long moment  = lcm(this.l_dist, this.r_dist);
				final long left_w  = moment / l_dist;
				final long right_w = moment / r_dist;
				
				return this.weight = (left_w + right_w);
			}else{
				final long left_ch_w  = left  != null ? left.solve()  : 1;
				final long right_ch_w = right != null ? right.solve() : 1;
				
				final long moment = lcm(left_ch_w * l_dist, right_ch_w * r_dist);
				
				final long left_w  = moment / l_dist;
				final long right_w = moment / r_dist;
				
				return this.weight = (left_w + right_w);
			}
		}
		
		public String toString(){
			return "[" + this.weight + " : " + (this.left == null ? "" : this.left.toString()) + ", " + (this.right == null ? "" : this.right.toString()) + "]";
		}
	}
	
	public static long gcd(long x, long y){
		if(x == 0){
			return y;
		}else{
			return gcd(y % x, x);
		}
	}
	
	public static long lcm(long x, long y){
		return  x * y / gcd(x, y);
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while (true) {
			final int n = sc.nextInt();
			
			if(n == 0){
				break;
			}
			
			int[][] data = new int[n][4];
			Node[] nodes = new Node[n];
			for(int i = 0; i < n; i++){
				for(int j = 0; j < 4; j++){
					data[i][j] = sc.nextInt();
				}
			}
			
			for(int i = n - 1; i >= 0; i--){
				//System.out.println(i);
				nodes[i] = new Node(data[i][0], data[i][1]);
			}
			for(int i = n - 1; i >= 0; i--){
				if(data[i][2] != 0){
					nodes[i].left  = nodes[data[i][2] - 1];
				}
				if(data[i][3] != 0){
					nodes[i].right = nodes[data[i][3] - 1];
				}
			}
			
			long max = 0;
			for(int i = 0; i < n; i++){
				max = Math.max(max, nodes[i].solve());
			}
			
			System.out.println(max);
		}
	}

}

Measured memory_bytes: 24084
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>

using namespace std;

#define INF 1 << 29
#define LL long long int

struct PAIR{
    int a;
    int b;

    bool operator < (const PAIR &right) const{
        return a == right.a? b < right.b : a < right.a;
    }
};

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

    unsigned long long int h,w,n;
    cin >> h >> w >> n;
    set<PAIR> st;
    vector<PAIR> vec;
    set<PAIR> close;

    for(int i = 0; i < n; i++){
        int a,b;
        cin >> a >> b;
        vec.push_back(PAIR{a,b});
        st.insert(vec[i]);
        close.insert(vec[i]);
    }

    unsigned long long int result[10];
    for(int i = 0;i < 10; i++){
        result[i] = 0;
    }

    int disa[] = {-1,0,1,-1,0,1,-1,0,1};
    int disb[] = {-1,-1,-1,0,0,0,1,1,1};
    bool countable = true;

    for(int i = 0; i < n; i++){
        PAIR tmp = vec[i];
        int count = 0;

        for(int j = 0; j < 9; j++){
            if(tmp.a + disa[j] < 1 || tmp.a + disa[j] > h || tmp.b + disb[j] < 1 || tmp.b + disb[j] > w){
                countable = false;
                break;
            }
            auto it = st.find(PAIR{tmp.a + disa[j],tmp.b + disb[j]});
            if(it != st.end()){
                count++;
            }
        }

        if(countable){
            result[count]++;
        }
        countable = true;
        
        for(int j = 0; j < 9; j++){
            count = 0;
            if(tmp.a + disa[j] < 1 || tmp.a + disa[j] > h || tmp.b + disb[j] < 1 || tmp.b + disb[j] > w){
                continue;
            }
            PAIR x = PAIR{tmp.a + disa[j],tmp.b + disb[j]};
            auto itc = close.find(x);
            if(itc != close.end()){
                continue;
            }
            close.insert(x);
            for(int k = 0; k < 9; k++){
                if(x.a + disa[k] < 1 || x.a + disa[k] > h || x.b + disb[k] < 1 || x.b + disb[k] > w){
                    countable = false;
                    break;
                }
                auto it2 = st.find(PAIR{x.a + disa[k],x.b + disb[k]});
                if(it2 != st.end()){
                    count++;
                }
            }
            if(countable){ 
                result[count]++;
            }
            countable = true;
        }
        


    }

    unsigned long long int tmp = (h-2)*(w-2);

    for(int i = 1; i < 10; i++){
        tmp -= result[i];
    }
    result[0] = tmp;

    for(int i = 0; i < 10; i++){
        cout << result[i] << endl;
    }

    return 0;
}

Measured memory_bytes: 47988
#include<iostream>

using namespace std;

const double tax8 = 0.08;
const double tax10 = 0.1;

int main(){
    int a,b;
    cin >> a >> b;
    for(int price=1;price <= 1009;price++){
        if(a == (int)(tax8*price) && b == (int)(tax10*price)){
            cout << price << endl;
            return 0;
        } 
    }
    cout << -1 << endl;
    return 0;
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

vector<vector<pair<ll,ll>>>a(100010);
ll ch[100010];
void dep(ll now,ll nowc,ll p){
	if(a[now].size()==1&&a[now][0].first==p){
		return ;
	}
	for(ll i=0;i<a[now].size();i++){
		ll nex=a[now][i].first;
		ll nexc=nowc;
		if(ch[nex]!=-1){
			continue;
		}
		ll wei=a[now][i].second;
	//	cout << wei<<endl;
	//	if(wei==3||wei==1){
	//		cout << now<<" "<<nex << " "<<nowc<<endl;
	//	}
		if(wei%2==0){
			ch[nex]=nexc;
			dep(nex,nexc,now);
		}
		else{
			nexc=abs(nexc-1);
			ch[nex]=nexc;
			dep(nex,nexc,now);
		}
	}
}
int main() {
	ll n;
	cin>>n;
	for(ll i=0;i<n;i++){
		ch[i]=-1;
	}
	for(ll i=0;i<n-1;i++){
		ll l,r,w;
		cin>>l>>r>>w;
		l--;r--;
		a[l].push_back(make_pair(r,w));
		a[r].push_back(make_pair(l,w));
	}
	ch[0]=0;
	dep(0,ch[0],-1);
	for(ll i=0;i<n;i++){
		cout <<ch[i]<<endl;
	}
	// your code goes here
	return 0;
}

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

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt(), count=0;
		int[] length = new int[n];
		for(int i=0;i<n;i++) length[i]=sc.nextInt();
		Arrays.sort(length);
		for(int i=0;i<n-2;i++) {
			for(int j=i+1;j<n-1;j++) {
				int left=0,right=n, tar=length[i]+length[j];
				while(left+1<right) {
					int mid = (left+right)/2;
					if(length[mid]<tar) left = mid;
					else right=mid;
				}
				count+=left-j;
			}
		}
		System.out.println(count);
	}
}

Measured memory_bytes: 32004