akhauriyash/Code-Regression huggingface dataset:
/**
 *      purpose : 
 *      author  : kyomukyomupurin
 *      created : 
**/

// input/output
#include <iostream>
#include <fstream>
#include <sstream>
// container class
#include <array>
#include <deque>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <unordered_set>
#include <vector>
// math, algorithm
#include <algorithm>
#include <cmath>
#include <complex>
#include <numeric>
// etc
#include <bitset>
#include <cassert>
#include <cctype>
#include <cstring>
#include <chrono>
#include <iomanip>
#include <random>
#include <utility>
// using-directive
using namespace std;
// alias template
using int64 = int64_t;
using vi = vector<int>;
using vl = vector<int64_t>;
using pii = pair<int, int>;
using pll = pair<int64_t, int64_t>;
// text macro replacement
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define all(v) (v).begin(), (v).end()
#define rall(v) (v).rbegin(), (v).rend()
#define print(x) cout << (x) << '\n'
#define debug(x) cerr << #x << ": " << (x) << '\n'
// variadic template
template<typename T> inline void chmin(T &a, T b) {if (a > b) a = b; return;}
template<typename T> inline void chmax(T &a, T b) {if (a < b) a = b; return;}
// constant
const int INF = (1<<30) - 1;
const int64_t INF64 = (1LL<<62) - 1;
const int64 MOD = 1000000007;

int n; int64 k;
vector<vector<int>> graph(101010);

int64 ans;

void dfs(int v, int p) {
  int64 can = k - 1;
  if (p != -1) --can;
  for (auto next : graph[v]) {
    if (next == p) continue;
    (ans *= can) %= MOD;
    --can;
    dfs(next, v);
  }
}

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

  cin >> n >> k;
  rep(i, n - 1) {
    int x, y; cin >> x >> y;
    --x; --y;
    graph[x].push_back(y);
    graph[y].push_back(x);
  }
  ans = k;
  dfs(0, -1);

  cout << ans << '\n';

  return 0;
}


Measured memory_bytes: 10496
#include<iostream>
#include<stdio.h>
#include<vector>
#include<algorithm>
#include<set>
#include<string>
#include<map>
#include<string.h>
#include<complex>
#include<math.h>
#include<queue>
#include <functional>
#include<time.h>
#include <stack>
#include<iomanip>
using namespace std;
#define rep(i,a,n) for(int i=(a);i<(n);i++)
#define ll long long
#define llint long long int
#define reverse(v)  reverse(v.begin(), v.end());
#define Yes(ans) if(ans)cout<<"Yes"<<endl; else cout<<"No"<<endl;
#define YES(ans) if(ans)cout<<"YES"<<endl; else cout<<"NO"<<endl;
#define hei(a) vector<a>
#define whei(a) vector<vector<a>>
#define UF  UnionFind 
#define Pint pair<llint,llint>
#define keta(a)  fixed << setprecision(a)
constexpr auto INF = 1000000000000000;
constexpr auto mod = 1000000007;
//辞書順はnext_permutation( begin( v ), end( v ) );やで！
// lower_boundは二分探索
struct edge { int to, cost; };
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}

// mod. m での a の逆元 a^{-1} を計算するよ！
long long modinv(long long a, long long m) {
	long long b = m, u = 1, v = 0;
	while (b) {
		long long t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}


//aCbをmod.mで割った余りを求める
ll int c(ll int a, ll int b, ll int m) {
	ll int ans = 1;
	for (ll int i = 0; i < b; i++) {
		ans *= a - i;
		ans %= m;
	}
	for (ll int i = 1; i <= b; i++) {
		ans *= modinv(i, m);
		ans %= m;
	}
	return ans;
}

//sは初めの点、vは頂点size、dは最短距離を求める(初期化はINF),Gは有向グラフ
void dijkdtra(int s, int v, vector<int>& d, whei(edge)& G) {
	priority_queue<Pint, vector<Pint>, greater<Pint>> que;//firstが距離、secondが頂点
	d[s] = 0;//スタートの距離はもちろんzero
	que.push(Pint(0, s));
	while (!que.empty()) {
		Pint p = que.top();
		que.pop();
		int V = p.second;
		if (d[V] < p.first)continue;
		for (int i = 0; i < G[V].size(); i++) {
			edge e = G[V][i];
			if (d[e.to] > d[V] + e.cost) {
				d[e.to] = d[V] + e.cost;
				que.push(Pint(d[e.to], e.to));
			}
		}
	}
}

llint binary_search(vector<int>&s,llint a) {
	llint l = -1;
	llint r = (int)s.size();
	while (r - l > 1) {
		llint mid = l + (r - l) / 2;

		if (s[mid]>=a) r = mid;
		else l = mid;
	}
	return r;
}
int k(ll n) {
	int x=0;
	while (n) {
		x+=n % 10;
		n /= 10;
	}
	return x;
}
ll max(ll x, ll y) {
	if (x < y)return y;
	return x;
}


int F(int n) {
	int x = 0;
	while (n) {
		x += n % 10;
		n /= 10;
	}
	return x;
}


int main() {
	ll n, a, b;
	cin >> n >> a >> b;
	ll x = n / (a + b);
	ll y = n % (a + b);
	x *= a;
	x += min(a, y);
	cout << x << endl;
	return 0;
}



Measured memory_bytes: 256
import java.util.*;
import java.io.*;
import static java.lang.Math.*;

public class Main {
    public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		
		// 入力
		int n = sc.nextInt();
		
		// 計算
		int result = 0;
		if(n == 0) result = 1;
		
		// 出力
		System.out.println(result);
	}
	
	public static class Scanner {
		private BufferedReader br; private StringTokenizer tok;
		public Scanner(InputStream is) throws IOException { br = new BufferedReader(new InputStreamReader(is));}
		private void getLine() throws IOException { while(!hasNext()) tok = new StringTokenizer(br.readLine());}
		private boolean hasNext() { return tok != null && tok.hasMoreTokens();}
		public String next() throws IOException { getLine(); return tok.nextToken();}
		public int nextInt() throws IOException { return Integer.parseInt(next());}
		public long nextLong() throws IOException { return Long.parseLong(next());}
		public double nextDouble() throws IOException { return Double.parseDouble(next());}
	}

}


Measured memory_bytes: 25340
#include <iostream>
#include <vector>
#include <string>
#define rep(i, n) for(int i = 0; i < n; i++)
bool Calc(std::string expr);
void DeleteReverse(std::string& expr);

int main()
{
	std::vector<std::string> results;
	while (1) {
		std::string expr;
		std::cin >> expr;
		if (expr == "#") break;
		//?????????????????£?¶??????????????????????
		while (1) {
			bool isDelete = false;
			rep(i, expr.size() - 1) {
				if (expr[i] == '-' && expr[i + 1] == '-') {
					expr.erase(i, 2);
					isDelete = true;
					break;
				}
			}
			if (!isDelete) break;
		}
		//->??? >?????????

		rep(i, expr.size() - 1) {
			if (expr[i] == '-' && expr[i + 1] == '>') {
				expr.erase(i, 1);
			}
		}
		int tfFlugs = -1;
		bool isCorrect = true;
		while (1) {
			tfFlugs++;
			std::string replaced = expr;
			bool includeFalse = false;
			//????????????
			rep(i, 11) {//0a 1b 2c...
				if (tfFlugs & 1 << i) {
					for (auto& x : replaced) {
						if (x == 'a' + i) {
							x = 'T';
						}
					}
				}
				else {
					includeFalse = true;
					for (auto& x : replaced) {
						if (x == 'a' + i) {
							x = 'F';
						}
					}
				}
			}
			//?????????????????????
			DeleteReverse(replaced);
			isCorrect = Calc(replaced);
			if (!isCorrect) break;
			if (!includeFalse) break;
		}
		results.push_back(isCorrect ? "YES" : "NO");
	}

	for (auto& x : results) {
		std::cout << x << std::endl;
	}

	return 0;
}

bool Calc(std::string expr)
{
	//????????¨???????????????
	std::string e[2];
	e[0] = expr.substr(0, expr.find_first_of('='));
	e[1] = expr.substr(expr.find_first_of('=') + 1);
	while (1) {
		rep(i, 2) {
			if (e[i].size() >= 5) { //?¨????????????¨???????????£?????????
				rep(j, e[i].size() - 4) {
					// ( TF +*> TF ) ?????????????§????
					if (e[i][j] == '(' && (e[i][j + 1] == 'T' || e[i][j + 1] == 'F') &&
						(e[i][j + 2] == '+' || e[i][j + 2] == '*' || e[i][j + 2] == '>') &&
						(e[i][j + 3] == 'T' || e[i][j + 3] == 'F') && e[i][j + 4] == ')') {
						char result;
						switch (e[i][j + 2])
						{
						case '+':
							if (e[i][j + 1] == 'F' && e[i][j + 3] == 'F') {
								result = 'F';
							}
							else result = 'T';
							break;
						case '*':
							if (e[i][j + 1] == 'T' && e[i][j + 3] == 'T') {
								result = 'T';
							}
							else result = 'F';
							break;
						case '>':
							if (e[i][j + 1] == 'T' && e[i][j + 3] == 'F') {
								result = 'F';
							}
							else result = 'T';
							break;
						}
						//????????????
						e[i].erase(j, 4); // ) ????????????
						e[i][j] = result; // ) ???TF??????????????????
						DeleteReverse(e[i]);
						break;
					}
				}
			}
			//?¨??????????
			if (e[0].size() == 1 && e[1].size() == 1) {
				if (e[0].front() == e[1].front()) {
					return true;
				}
				else return false;
			}
		}
	}
	return false;
}

void DeleteReverse(std::string & expr)
{
	rep(i, expr.size() - 1) {
		if (expr[i] == '-' && expr[i + 1] == 'F') {
			expr.erase(i, 1);
			expr[i] = 'T';
		}
		else if (expr[i] == '-' && expr[i + 1] == 'T') {
			expr.erase(i, 1);
			expr[i] = 'F';
		}
	}
}

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

using str = string;
using ss = stringstream;

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

    int n;
    cin>>n;

    map<str, int> m;

    bool ans=true;

    str bw="";

    for(int i=0;i<n;i++)
    {
        str w;
        cin>>w;
        if(bw!="")
        {
            if(bw[bw.size()-1]!=w[0])
            {
                ans=false;
                break;
            }
        }
        bw=w;
        if(m[w]>0)
        {
            ans=false;
            break;
        }
        m[w]++;
    }

    puts(ans?"Yes":"No");

    return 0;
}


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

using namespace std;


#ifdef zxc

#include <sys/resource.h>
#include "debug.h"
#include "profile.h"

#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#define profile(X) LOG_DURATION(X)
#else
#define debug(...) 42
#define profile(...) 42
#endif

using ll = int64_t;
using ld = double;
const ld EPS = 1e-9;
const int MOD = 1e9 + 7;
const ld PI = 3.141592653589793;
const int maxn = 600001;
using cd = complex<double>;

void fast_io() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

signed main() {
#ifdef zxc
    struct rlimit rl;
    const rlim_t kStackSize = 512L * 1024L * 1024L;
    assert(!getrlimit(RLIMIT_STACK, &rl));
    rl.rlim_cur = kStackSize;
    assert(!setrlimit(RLIMIT_STACK, &rl));
    freopen("../input.txt", "r", stdin);
//    freopen("../kolya_output.txt", "w", stdout);
#else
    //    mt19937 mt(std::chrono::high_resolution_clock::now().time_since_epoch().count());
    //            freopen("", "r", stdin);
    //        freopen("hack.out", "w", stdout);
#endif
    profile("all");
    auto solve = [](int _) {
        int r, c;
        cin >> r >> c;
        int n;
        cin >> n;
        vector<array<pair<int, int>, 2>> segs(n);
        for (int i = 0; i < n; ++i) {
            for (int j = 0; j < 2; ++j) {
                cin >> segs[i][j].first >> segs[i][j].second;
            }
        }


        auto is_feasible = [&](pair<int, int> p) {
            return (p.first == 0 || p.first == r) || (p.second == 0 || p.second == c);
        };
        ld cent_x = r * 0.5;
        ld cent_y = c * 0.5;
        vector<pair<ld, ld>> feasible_segs;
        for (int i = 0; i < n; ++i) {
            if (!is_feasible(segs[i][0]) || !is_feasible(segs[i][1])) {
                continue;
            }
            array<ld, 2> ang;
            for (int e = 0; e < 2; ++e) {
                ang[e] = atan2(segs[i][e].second - cent_y, segs[i][e].first - cent_x);
            }
            if (ang[0] > ang[1]) {
                swap(ang[0], ang[1]);
            }
            feasible_segs.emplace_back(ang[0], ang[1]);
        }
        vector<pair<ld, int>> ev;
        for (int i = 0; i < feasible_segs.size(); ++i) {
            ev.push_back({feasible_segs[i].first, i + 1});
            ev.push_back({feasible_segs[i].second, -(i + 1)});
        }
        stack<int> st;
        sort(ev.begin(), ev.end());
        bool ok = true;
        for (auto e:ev) {
            if (e.second > 0) {
                st.push(e.second);
            } else {
                if (-e.second != st.top()) {
                    ok = false;
                    break;
                }
                st.pop();
            }
        }
        if (ok) {
            cout << "YES";
        } else {
            cout << "NO";
        }
    };


    fast_io();

    cout.precision(9);
    cout <<
         fixed;
    for (int i = 1; i <= 1; ++i)
        solve(1);


}


Measured memory_bytes: 11012
#include <algorithm>
#include <cassert>
#include <cmath>
#include <cstdio>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#include <cfloat>

using std::cerr;
using std::cin;
using std::cout;
using std::endl;

using namespace std;
typedef long long int64;

int main(){
  cout << std::fixed << std::setprecision(16);
  cin.tie(nullptr);
  std::ios::sync_with_stdio(false);

  int n;
  cin>>n;
  int64 result=0;
  for(int i=0;i<n;i++){
    int a;
    cin>>a;
    while(a%2==0){
      result++;
      a/=2;
    }
  }
  cout<<result<<endl;



  return 0;
}

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

int main(){
	int n, a, min, max, i;
	long long s;
 
	cin>>n>>a;
	
	s = a;
	min = a;
	max = a;
	
	for (i = 1; i < n; i++) {
 		cin>>a;
		if (a > max) max = a;
		if (a < min) min = a;
		s += a;
	}
	
	cout<<min<<" "<<max<<" "<<s<<endl;

	return 0;
}


Measured memory_bytes: 3120
#include <cstdio>
#include <iostream>
using namespace std;
const int maxn=2e5+50;
int n,k,c;
int suf[maxn<<1];
char S[maxn];
int main()
{
    scanf("%d%d%d",&n,&k,&c);
    scanf("%s",S+1);
    for(int i=n;i>=1;--i)
    {
        if(S[i]=='x') suf[i]=suf[i+1];
        else suf[i]=1+suf[i+c+1];
    }
    int cnt=0;
    for(int i=1,las=-c;i<=n;++i) if(i-las>c)
    {
        if(S[i]=='x') continue;
        if(cnt+suf[i+1]<k) printf("%d\n",i);
        ++cnt;
        las=i;
    }
    return 0;
}

Measured memory_bytes: 2432
#include <bits/stdc++.h>
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define REPr(i,n) for(int i=(n)-1;i>=0; --i)
#define FORq(i, m, n) for(int i = (m);i <= (n);++i)
#define FORqr(i, m , n) for(int i = (n);i >=(m);--i)
#define SCD(n) scanf("%d",&n)
#define SCD2(m,n) scanf("%d%d",&m,&n)
#define SCD3(m,n,k) scanf("%d%d%d",&m,&n,&k)
#define SCLLD(n) scanf("%lld",&n)
#define SCLLD2(m,n) scanf("%lld%lld",&m,&n)
#define SCLLD3(m,n,k) scanf("%lld%lld%lld",&m,&n,&k)
#define PB push_back
#define MP make_pair
#define ARSCD(A,N) REP(i,N){SCD(A[i]);}
#define ARSCD1(A,N) FORq(i,1,N){SCD(A[i]);}
#define VSCD(v,N) REP(i,N){int x; SCD(x); v.PB(x);}
#define VSCLLD(v,N) REP(i,N){long long x; SCLLD(x); v.PB(x);}
#define PRINTD(n) printf("%d\n",n)
#define PRINTLLD(n) printf("%lld\n",n)
#define DEBUG printf("%s\n","debug")
#define fst first
#define snd second
#define SIN(x,S) (S.count(x) != 0)
using namespace std;
typedef pair<int,int> PII;
typedef vector<int> VI;
typedef vector < VI > VVI;
typedef vector<long long> VL;
typedef long long ll;
typedef long long integer;
////////////////////////////////////////////////////////////////////
int main(){
    int N; SCD(N);
    int even = 0;
    REP(i,N){
        int k;
        cin >> k;
        if (k % 2 == 0) even++;
    }

    if (even == N) printf("second\n");
    else printf("first\n");
}

Measured memory_bytes: 256
import sys
from collections import Counter
input = sys.stdin.readline


N = int(input())
alist = list(map(int, input().split()))
Q = int(input())


sumA = sum(alist)
adict = Counter(alist)

for _ in range(Q):
    b, c = map(int, input().split())

    if b not in adict:
        print(sumA)
        continue

    bnum = adict.pop(b)
    if c in adict:
        adict[c] += bnum
    else:
        adict[c] = bnum

    sumA -= bnum * (b - c)
    print(sumA)


Measured memory_bytes: 21120
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		String s =scan.next();
		String t =scan.next();
		scan.close();
		int cnt=0;
		for(int i=0;i<s.length();i++) {
			if(s.charAt(i)==t.charAt(i))cnt++;
		}
		System.out.println(cnt);
	}
}

Measured memory_bytes: 21972
#include <iostream>
#include <fstream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <functional>
#include <map>
#include <queue>

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

using namespace std;
using ll = long long;
using P = pair<int, int>;
using TP = tuple<ll, ll, ll>;
ll MOD = 1e9+7;
ll INF = 1LL<<40;

vector<int> e(100,0);
map<ll, bool> mp;
ll N;

int count(int a){
    a--;
    int ret = 0;
    REP(i, N){
        if(e[i] >= a){
            ret++;
        }
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    cin >> N;
    for(ll i = N; i > 0; i--){
        ll tmp = i;
        for(ll j = 2; j <= i; j++){
            if(tmp % j == 0){
                tmp /= j;
                e[j]++;
                j--;
            }
        }
    }
    
    ll ans = count(75)
            + count(25) * (count(3) - 1)
            + count(15) * (count(5) - 1)
            + count(5) * (count(5) - 1) * (count(3) - 2) / 2;
    
    cout << ans << endl;
    return 0;
}


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

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


signed main(){
  cin.tie(0);	
  ios::sync_with_stdio(false);
  int n;
  cin>>n;
  cout<<(n-1)/2<<endl;

  return 0;
}


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

int main() {
  int A, B;
  cin >> A >> B;
  int ans = 0;
  for (int a = 1; a < 10; a++){
    for (int b = 0; b < 10; b++) {
      for (int c = 0; c < 10; c++) {
        int x = 10001 * a + 1010 * b + 100 * c;
        if (x >= A && x <=B){
          ans++;
        }
      }
    }
  }
  cout << ans << endl;
  return 0;
}

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

int main(){
  int x, y;
  cin >> x >> y;
  
  int u[13] = {0, 1, 2, 1, 3, 1, 3, 1, 1, 3, 1, 3, 1};
  
  if(u[x] == u[y]) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define REP(i, n) rep(i, 0, n)
#define repb(i, a, b) for(int i = a; i >= b; i--)
#define all(a) a.begin(), a.end()
#define int long long
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e12;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, k;
    cin >> n >> k;
    vector<int> x(n);
    int ans = 0;
    rep(i, 0, n){
        cin >> x[i];
        ans += min(abs(k - x[i]), x[i]);
    }
    cout << 2 * ans << endl;
}

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

using namespace std;

int main(void) {
    int N;
    cin >> N;
    vector<int> A(N);
    int minus = 0;
    for(int i=0; i<N; i++) {
        cin >> A.at(i);
        if(A.at(i) < 0) {
            minus += 1;
            A.at(i) *= -1;
        }
    }
    long long int ans = accumulate(A.begin(), A.end(), 0LL);
    if(minus % 2 == 0) {
        cout << ans << endl;
    } else {
        int minimum = *min_element(A.begin(), A.end());
        cout << ans - 2 * minimum << endl;
    }

    return 0;
}


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

int main() {
    int n, m, k;
    cin >> n >> m >> k;
    for(int i = 0; i <= n; ++i){
        for(int j = 0; j <= m; ++j){
            int t = i*(m-j) + j*(n-i);
            if(k==t) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}

Measured memory_bytes: 3628
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Scanner;
public class Main {


    public static void main(String[] args) {


        Scanner scan = new Scanner(System.in);
int N=scan.nextInt();
        int K=scan.nextInt();
int p[]=new int [N];
for (int i=0;i<N;i++){p[i]=scan.nextInt();}
Arrays.sort(p);
int j=0;
for(int i=0;i<K;i++){j=j+p[i];}
System.out.println(j);

    }
    }




Measured memory_bytes: 30268
import java.util.*;
import java.io.*;

public class Main {
	public void solve() throws IOException {
		int n = nextInt();
		int[][] mat = new int[n][n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				mat[i][j] = nextInt();
			}
		}
		int[][][] sum = new int[n][n][n];
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				sum[i][j][j] = mat[i][j];
				for(int k = j+1; k < n; k++){
					sum[i][j][k] = sum[i][j][k-1] + mat[i][k];
				}
			}
		}
		long ans = Integer.MIN_VALUE;
		for(int i = 0; i < n; i++){
			for(int j = 0; j < n; j++){
				for(int k = j; k < n; k++){
					long tmp = 0;
					for(int l = i; l < n; l++){
						tmp += sum[l][j][k];
						ans = Math.max(ans, tmp);		
					}
				}
			}
		}
		writer.println(ans);
	}

	public static void main(String[] args) throws IOException {
		new Main().run();
	}

	BufferedReader reader;
	StringTokenizer tokenizer;
	PrintWriter writer;

	public void run() throws IOException {
		try {
			reader = new BufferedReader(new InputStreamReader(System.in));
			tokenizer = null;
			writer = new PrintWriter(System.out);
			solve();
			reader.close();
			writer.close();
		} catch (Exception e) {
			e.printStackTrace();
		}
	}

	public String nextToken() throws IOException {
		while (tokenizer == null || !tokenizer.hasMoreTokens()) {
			tokenizer = new StringTokenizer(reader.readLine());
		}
		return tokenizer.nextToken();
	}

	public int nextInt() throws IOException {
		return Integer.parseInt(nextToken());
	}
}

Measured memory_bytes: 28460
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <algorithm>
#include <utility>
using namespace std;
//#define local
int main()
{
#ifdef local
    freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
#endif
    char s[110];
    int flag=1,cnt[30]= {0};
    cin>>s;
    for(int i=0; s[i]; i++)
        cnt[s[i]-'a']++;
    for(int i=0; i<26; i++)
        if(cnt[i]%2)
        {
            flag=0;
            break;
        }
    if(flag) cout<<"Yes";
    else cout<<"No";
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


#define rep(i,n) for(int i=0; i<n; i++)
#define rept(i,a,b) for(int i=a; i<b; i++)
#define ll long long
#define MOD 1000000007

#define IMIN INT_MIN;
#define IMAX INT_MAX;


int main(){
    int X;
    cin>>X;
    if(X/100*5>=X%100)cout<<"1"<<endl;
    else cout<<"0"<<endl;

	return 0;
}



Measured memory_bytes: 256
n = int(input())
a_list = list()

for i in range(n):
    a_list.append(int(input()))

a_list.sort()

d = 0
step = 0

for j in range(n):
    if a_list[j] > d:
        step += 1
        d = a_list[j]

print(step)

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

using namespace std;

int ans[200000];

int main() {
    int n;
    cin >> n;
    /*for (int i=0; i<n; i++) {
        ans[i] = 0;
    }
    for (int i=0; i<n; i++)
        cout << ans[i] << " ";
    cout << "\n";*/
    for (int i=0; i<n-1; i++) {
        int x;
        cin >> x;
        ans[x-1]++;
    }

    for (int i=0; i<n; i++)
        cout << ans[i] << "\n";
    return 0;
}


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

int gcd(int a,int b){
  if(a%b!=0) gcd(b,a%b);
  else return b;
}



int main(){
  int a,b,ans;
  cin>>a>>b;
 ans=gcd(a,b);
 cout<<ans<<endl;
  return 0;
}

Measured memory_bytes: 1164
using System;

namespace _174.c
{
    internal class Program
    {
        private static void Main(string[] args)
        {
            var k = int.Parse(Console.ReadLine());
            long a = 7;
            var ans = -1;

            for (var i = 0; i < k; i++)
            {
                if (a % k == 0)
                {
                    ans = i + 1;
                    break;
                }
                a = (a % k) * (10 % k) + (7 % k);
            }

            Console.WriteLine(ans.ToString());
        }
    }
}

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

void fnOutput(const vector<int> &argviSort, int argiSortCnt)
{
  for (int i = 0; i < argviSort.size(); i++)
  {
    if (i) cout << " ";
    cout << argviSort[i];
  }
  cout << endl;
  cout << argiSortCnt << endl;
}

void fnSelectionSort(vector<int> &argviSort, int &argiSortCnt)
{
  for (int ixSorting = 0; ixSorting < argviSort.size() - 1; ixSorting++)
  {
    int ixMinimum = ixSorting;
    bool bSorting = false;

    for (int j = ixSorting + 1; j < argviSort.size(); j++)
    {
      if (argviSort[j] < argviSort[ixMinimum])
      {
        ixMinimum = j;
        bSorting = true;
      }
    }
    if (bSorting == true)
    {
      swap(argviSort[ixSorting], argviSort[ixMinimum]);
      argiSortCnt++;
    }
  }
}

int main()
{
  int iSortCnt = 0;
  vector<int> viSort;
  int iMaxSize;
  
  cin >> iMaxSize;
  for (int i = 0; i < iMaxSize; i++)
  {
    int iNum;
    cin >> iNum;
    viSort.push_back(iNum);
  }

  fnSelectionSort(viSort, iSortCnt);
  fnOutput(viSort, iSortCnt);

  return 0;
}

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

using namespace std;

struct f
{
    int bh,t;
} M[100005];

bool cmp(f a,f b)
{
    return a.t<b.t;
}

int main()
{
    int n;
    while(cin>>n)
    {
        int i;
        for(i=1; i<=n; i++)
        {
            cin>>M[i].t;
            M[i].bh=i;
        }
        sort(M+1,M+n+1,cmp);
        for(i=1;i<=n;i++)
            cout<<M[i].bh<<' ';
        cout<<endl;
    }
    return 0;
}


Measured memory_bytes: 1536
n=int(input())
t,a=map(int,input().split())
h=list(map(int,input().split()))
diff=float('inf')
ans=0
for i in range(n):
    tmp=abs(a-(t-h[i]*0.006))
    if tmp<diff:
        diff=tmp
        ans=i+1
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
int main(){
    int n;
    cin >> n;
    deque<int> ans;
    rep(i,n){
        int a;
        cin >> a;
        if(i%2 == n%2){
            ans.push_back(a);
        }
        else{
            ans.push_front(a);
        }
    }
    rep(i,n){
        cout << ans[i] <<" ";
    }
    cout << endl;
}

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

int main() {
    int N;
    cin >> N;
    ll A, B;
    cin >> A >> B;
    if (A > B) swap(A, B);
    vector<ll> S(N);
    for (int i = 0; i < N; i++) cin >> S[i];
    for (int i = 2; i < N; i++) {
        if (S[i]-S[i-2] < A) {
            cout << 0 << endl;
            return 0;
        }
    }
    S.insert(S.begin(), -2e18);
    
    vector<ll> dp(N+2, 0);
    dp[0] = 0;
    dp[1] = 1;
    vector<ll> sum(N+2, 0);
    sum[0] = 0;
    sum[1] = 1;
    int pt = 0;
    
    ll mod = 1e9+7;
    for (int i = 1; i <= N; i++) {
        int lim = distance(S.begin(), lower_bound(S.begin(), S.end(), S[i]-B));
        if (S[lim] > S[i]-B) lim--;
        if (pt <= lim) {
            if (pt >= 0) dp[i+1] = (sum[lim+1]-sum[pt]+mod)%mod;
            else dp[i+1] = sum[lim+1];
        }
        //cout << lim  << " " << dp[i+1] << endl;
        sum[i+1] = (sum[i]+dp[i+1])%mod;
        if (S[i] - S[i-1] < A) {
            pt = i-1;
        }
    }
    cout << (sum[N+1] - sum[pt] + mod) % mod << endl;
    return 0;
}


Measured memory_bytes: 5508
import sys
import math
N, M = map(int, input().split())
INF = 10 ** 9 + 7

if abs(N - M) >= 2:
    print(0)
    sys.exit()

tmpN = math.factorial(N)
tmpM = math.factorial(M)
ans = tmpN * tmpM
if N == M:
    ans *= 2
print(ans % INF)

Measured memory_bytes: 55152
from sys import stdin
def stdinput():
    return stdin.readline().strip()

def main():
    a, b = map(int, stdinput().split())

    a, b = min(a, b), max(a, b)
    while b % a != 0:
        a, b = b % a, a
    
    print(a)

if __name__ == '__main__':
    main()


Measured memory_bytes: 5604
#include <iostream>

using namespace std;
int main() {
	for (int i = 1; i < 10002; ++i) {
		int n, m;
		cin >> n >> m;
		if (n == 0 && m == 0)
			break;
		if (m < n)
			cout << m  << " " << n << endl;
		else
			cout << n  << " " << m << endl;
	}
	return 0;
}


Measured memory_bytes: 2988
#include<bits/stdc++.h>
#define ll long long 
#define hell 1000000007
#define F first
#define re 15000000
#define S second
#define pb push_back
#define all(a)  (a).begin(),(a).end()
#define rep(i,a,b) for(ll int i = a;i<b;i++)
#define pi 3.1415926536
#define Mod 998244353
//char a[2000][2000];
using namespace std;
bool check(ll m,ll k,ll n,ll a ,ll b){
  ll rem = n-m;
  if( k > rem*b + a*m)
      return 1;
  else
    return 0;

}
int getMod(string s,int k){
  ll sum = 0;
  for(int i = 0;i<s.size();i++){
    sum = sum*10+(s[i]-'0');
    sum = sum%k;
  }
  return sum%k;

}
int main()
{   
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);            
    //std::setprecision(20);    
    int tests=1;
      //freopen("input.txt", "r", stdin);   
     // cin>>tests;
  while(tests--)
    {
      ll l,r;
      cin>>l>>r;
      for(int i = l;i<=r;i++){
        if((i)%2019 == 0){
            cout<<0;
            exit(0);
          }
      }
      
      vector<int> v(r-l+1);
      for(int i = l;i<=r;i++){
        v[i-l] =  i%2019;
      }
      int ans = INT_MAX;
      for(int i = 0;i<v.size();i++){
        for(int j = i+1;j<v.size();j++){
          ans = min(ans,v[i]*v[j]%2019);
        }
      }
      cout<<ans;
      
    }
    
}

Measured memory_bytes: 256
#define _USE_MATH_DEFINES
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
#include <iomanip>	
#include <deque>
#include <set>
#include <climits>
#include <memory>
#include <numeric>
#include <utility>


#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
#define fore(i,a) for(auto &i:a)
#define INF INT_MAX/2;
#define PI 3.14159265358979323846264338327950L;
const int INF2 = 1001001001;
typedef long long ll;
using namespace std;
using vi = vector<int>;
using vll = vector<ll>;
ll mod = 1e9 + 7;
//ll llmax = 10000000000000000000ll;
const ll LINF = 1e18 + 100;
using namespace std;
using Graph = vector<vector<int>>;



int cnt_digit(ll N)
{
	int digit = 0;

	while (N > 0)
	{
		N /= 10;
		digit++;
	}
	return digit;
}


 // 最大公約数計算
 
ll gcd(ll a, ll b)
{
	if (b == 0) {
		return a;
	}
	else {
		return gcd(b, a % b);
	}
}
// 最小公倍数の計算

ll lcm(ll a, ll b)
{
	ll g = gcd(a, b);

	return a / g * b;
}

struct union_find
{
	vector<int> par, r;
	union_find(int n)
	{
		par.resize(n);
		r.resize(n);
		init(n);
	}


	void init(int n)
	{
		for (int i = 0; i < n; i++) par[i] = i;
		for (int i = 0; i < n; i++) r[i] = 0;
	}

	int find(int x)
	{
		if (par[x] == x)return x;
		else return find(par[x]);
	}

	void unite(int x, int y)
	{
		x = find(x);
		y = find(y);

		if (r[x] < r[y])
		{
			par[x] = y;
		}
		else
		{
			par[y] = x;
			if (r[x] == r[y])
			{
				r[x]++;
			}
		}
	}
};

const int MAX_N = 110000;

int memo[MAX_N];

int rec(int n) {
	if (n == 0)return 0;
	if (memo[n] != -1)return memo[n];

	int res = n;

	for (int pow6 = 1; pow6 <= n; pow6 *= 6)res = min(res, rec(n - pow6) + 1);

	for (int pow9 = 1; pow9 <= n; pow9 *= 9)res = min(res, rec(n - pow9) + 1);

	return memo[n] = res;
}

int calc(int x) {
	int ret = 0;
	while (x % 2 == 0) {
		x /= 2;
		ret++;
	}

	return ret;
}

int a[12][12];
int D;
ll G;
vector<ll> P, C;

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

	int n,x;
	cin >> n >> x;

	
	
	cout << n*x << endl;
}
	

Measured memory_bytes: 3652
#include <bits/stdc++.h>
#define rep(i, n) for (int i=0; i<(int)(n); i++)
#define all(v) v.begin(), v.end()
#define allR(v) v.rbegin(), v.rend()
#define PRINT(v) for (auto x : (v)) cout <<x <<" " ; cout <<endl;
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
typedef pair<int,int> Pi;
const ll MOD = 1000000007;
const ll INF = 10000000000000000;
const int inf = 1001001001;
vector<int> x4 = {0, 1, 0, -1}, x8 = {0, 1, 1, 1, 0, -1, -1, -1};
vector<int> y4 = {1, 0, -1, 0}, y8 = {1, 1, 0, -1, -1, -1, 0, 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;}
template<class T> inline T powerM(T a,T b){if (b==0) return 1;
T tmp = powerM(a,b/2); if (b%2==0) return tmp*tmp%MOD; else return tmp*tmp%MOD*a%MOD; }
template<class T> inline T power(T a,T b,T m=numeric_limits<T>::max()){ if (b==0) return 1;
  T tmp = power(a,b/2,m); if (b%2==0) return tmp*tmp%m; else return tmp*tmp%m*a%m; }
template<class T> inline T gcd(T a, T b){if (b==0) return a; return gcd(b, a%b);}
template<class T> inline T lcm(T a, T b){return a / gcd(a,b) * b;}
// ax+by=gcd(a,b)を解く
template<class T> inline T extgcd(T a,T b,T &x,T &y){if (b==0){x=1; y=0; return a;} T d=extgcd(b,a%b,y,x); y -= a/b*x; return d;}
void hey(){ cout <<"hey" <<endl; }

template<class T> struct edge { int to; T cost;};


// Dijkstra法-------------------------------------------------
// 単一始点最短路問題に。負の辺がなければおｋ。O(MlogN)
// 何回か問題を解いたのでライブラリとしては大丈夫なはず
// N を入力しないとバグるので注意

int N,M,L;

vector<vector<edge<int>>> G;
vector<vector<Pi>> dist;
const int INFC = 1001001001;

void dijkstra(int s){
  priority_queue<pair<Pi, int>, vector<pair<Pi, int>>, greater<pair<Pi, int>> > que;
  // 燃料補給の最小回数、燃料最小消費量、頂点番号
  dist[s][s] = {0, 0};
  que.push({Pi(0, 0), s});
  while (!que.empty()){
    Pi score = que.top().first;
    int v = que.top().second;
    que.pop();
    if (score > dist[s][v]) continue;
    for (auto ne : G[v]){
      int nv = ne.to;
      Pi nscore = score;
      if (nscore.second + ne.cost > L){
        nscore.first++;
        nscore.second = ne.cost;
      }else{
        nscore.second += ne.cost;
      }
      if (nscore > dist[s][nv]) continue;
      dist[s][nv] = nscore;
      que.push({nscore, nv});
    }
  }
}

void solve(){
  cin >>N >>M >>L;
  G.assign(N, vector<edge<int>>());
  rep(i, M){
    int a,b,c; cin >>a >>b >>c; a--; b--;
    if (c > L) continue;
    // そもそも燃料タンク容量いっぱいで移動できない道はポイ
    G[a].push_back({b, c});
    G[b].push_back({a, c});
  }
  dist.assign(N, vector<Pi>(N, {INFC, INFC}));
  rep(i, N) dijkstra(i);
  
  int Q; cin >>Q;
  vector<int> ans(Q);
  rep(i, Q){
    int s,t; cin >>s >>t; s--; t--;
    int res = dist[s][t].first;
    if (res == INFC) res = -1;
    ans[i] = res;
  }
  rep(i, Q) cout <<ans[i] <<endl;
}

int main() {
  solve();
}

Measured memory_bytes: 5792
#include<stdio.h>

int main()
{
    long q, h, s, d, n,ans = 0;
    scanf("%ld%ld%ld%ld%ld", &q, &h, &s, &d, &n);
    if (q * 2 < h)
        h = q * 2;
    if (h * 2 < s)
        s = h * 2;
    if (s * 2 < d)
        d = s * 2;
    if (n % 2 == 1)
    {
        ans += s;
        n--;
    }
    ans += d * (n / 2);
    printf("%ld", ans);
    return 0;
}

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

#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define input_txt() freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
#define ll long long int
#define vi vector<int>
#define vll vector<ll>
#define pb push_back
#define si set<int>
#define msi map<string, int>
#define test ll t; cin>>t; while(t--)
#define input(a,n) for(int i=0;i<n;i++) cin>>a[i];
#define sqr(a) (a)*(a)
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
const double PI = acos(-1);
const int inf=2000000000;
const ll infLL=9000000000000000000;


void case_i()
{
    int x,y;cin>>x>>y;
    if((x==4 || x==6 || x==9 || x==11) && (y==4 || y==6 || y==9 || y==11) && x!=y)
        cout<<"Yes"<<endl;
    else if(x==2 || y==2)
        cout<<"No"<<endl;
    else if((x==1 || x==3 || x==5 || x==7 || x==8 || x==10 || x==12) && (y==1 || y==3 || y==5 || y==7 || y==8 || y==10 || y==12) && x!=y)
        cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

int main()
{
    IOS;
    //    input_txt();
    //test
    case_i();
    /**/
    return 0;
}



//End up here once more;






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

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

    int ab = a + b;
    int bc = b + c;

    if ( ( a + b + c ) != 17 )
    {
        cout << "NO" << endl;
    }
    else
    {
        if ( ( ab == 12 && bc == 12 ) | ( ab == 10 && bc == 12 ) |
             ( ab == 12 && bc == 10 ) )
        {
            cout << "YES" << endl;
        }
        else
        {
            cout << "NO" << endl;
        }
    }

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
using namespace std;

ll N,K;
int main(){
     cin >> N >> K;
     if (N >= 2*K-1) cout << "YES" << endl;
     else cout << "NO" << endl;

     return 0;
}


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

using namespace std;

int main()
{
    string s;

    getline(cin, s);

    for(int i = 0; i < s.size();)
    {
        string temp = s.substr(i, 5);
        if(temp == "apple")
        {
            temp = "peach";
            for(int j = 0; j < 5; ++j) {
                s[i + j] = temp[j];
            }
            i += 5;
        }
        else if(temp == "peach")
        {
            temp = "apple";
            for(int j = 0; j < 5; ++j) {
                s[i + j] = temp[j];
            }
            i += 5;
        }
        else
        {
            ++i;
        }
    }

    cout << s << endl;

}

Measured memory_bytes: 1180
//今日の成果*AOJ0027*AOJ0028


#include<iostream>
#include<string>
#include<vector>
#include<cstdio>
#include<sstream>
#include<algorithm>
#include<cmath>
#include<map>
using namespace std;
int stoi(string x){stringstream ss;ss<<x;int tmp;ss>>tmp;return tmp;}
string itos(int x){stringstream ss;ss<<x;return ss.str();}
int main(){
	
	int h,ans=0;
	while(true){
	cin>>h;
	if(h==0)break;
	ans=0;
	int ta[200][5]={{0},{0}};
	for(int i=0;i<h;i++)for(int j=0;j<5;j++)cin>>ta[i][j];
	//盤面の存在しないところは0
	while(true){

	bool f=1;
	for(int i=0;i<h;i++){
	int cnt=0,fi=-1;
		for(int j=0;j<3;j++){
			if(ta[i][j]==ta[i][j+1]&&ta[i][j]==ta[i][j+2]&&ta[i][j]!=0){
			cnt++;
			if(fi==-1)fi=j;
			}
		}//endfor
		if(cnt!=0)ans+=ta[i][fi]*(2+cnt),f=0;
		if(cnt!=0)for(int j=0;j<2+cnt;j++)ta[i][fi+j]=0;
	}//endfor
	if(f)break;
	//落とす処理
	for(int i=h-2;i>=0;i--){
		for(int j=0;j<5;j++){
			int ti=i;
			while(true){
			if(ti==h-1||ta[ti+1][j]!=0)break;
			ta[ti+1][j]=ta[ti][j];
			ta[ti][j]=0;
			ti++;
			}//endwhile
		}//endfor
	}//endfor
	//for(int i=0;i<h;i++)printf("%d%d%d%d%d\n",ta[i][0],ta[i][1],ta[i][2],ta[i][3],ta[i][4]);
	//printf("\n");
	}//endwhile
	cout<<ans<<endl;
	}//endwhile
	return 0;
}

Measured memory_bytes: 1172
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> pii;
typedef long long ll;

#define pb push_back
#define fastIO ios_base::sync_with_stdio(false); cin.tie(nullptr);
#define endl '\n'
#define deb(x) cout << #x << " "<< x << endl;
#define fo(i, n) for(int i=0; i<n; i++)
#define Fo(i, k, n) for(int i=k; i<n; i++)

struct greaterr
{
    template<class T>
    bool operator()(T const &a, T const &b) const { return a > b; }
};

vector<bool> sieve(1000007,true);

void help(){
     sieve[0] = false;
     sieve[1] = false;

     for(int i=2;i*i<=1000000;++i){
        if(sieve[i]){
            for(int j=i*i;j<=1000000;j+=i)
                sieve[j] = false;

        }
     }


}

int main() {
   fastIO

   int n;
   cin>>n;

   if(n<=9)
    cout<<n;

   else if(n>9&&n<=99)
      cout<<"9";

   else if(n>=100&&n<=999)
    cout<<(9+n-100+1);

   else if(n>999&&n<9999)
     cout<<(9+999-100+1);

   else if(n>=10000&&n<=99999)
           cout<<(9+999-100+1+n-10000+1);
    else
    cout<<(9+999-100+1+99999-10000+1);






   return 0 ;
      }


Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <stack>
#include <algorithm>

using namespace std;



int trace_parent(int cur_index, int backtrack, int parentLookup[101]) {
  if (backtrack == 1) return parentLookup[cur_index];
  return trace_parent(parentLookup[cur_index], backtrack-1, parentLookup);
}


int main() {
  int N; //no. of explorations
  cin >> N;

  for (int i = 0; i < N; i++) {
    stack<int> path;
    vector<int> output[101];
    int parentLookup[101] = {-1}; //index is a child of entry on current path
    int freeChild[101] = {-1}; // how many unclosed children

    int max_state = 1;
    parentLookup[1] = 1;
    
    int entry;
    cin >> entry;

    while (entry != 0) {
      if (entry > 0) {
	int new_state = max_state;
	if (new_state == 1) {
	  freeChild[new_state] = entry;
	} else {
	  freeChild[new_state] = entry - 1;
	}

	
	//add to output
	if (new_state != 1) {
	  int parent = path.top();
	  parentLookup[new_state] = parent;
	  output[new_state].push_back(parent);
	  output[parent].push_back(new_state);
	}
	
	path.push(new_state);
	max_state++;
      } else if (entry < 0) {
	int backlink_id = trace_parent(path.top(), -entry, parentLookup);
	//cout << "parent of " << path.top() << "is: " << backlink_id << endl;
	output[path.top()].push_back(backlink_id);
	output[backlink_id].push_back(path.top());
	freeChild[path.top()] -= 1;
	freeChild[backlink_id] -= 1;
      }
      
      while (freeChild[path.top()] == 0) {
	if (path.top() == 1) break;
	path.pop();
	freeChild[path.top()] -= 1;	
      }
      cin >> entry; 
    }
    
    
    for (int i = 1; i < max_state; i++) {
      cout << i;
      sort(output[i].begin(), output[i].end());
      for (vector<int>::const_iterator j = output[i].begin(); j != output[i].end(); ++j) {
	cout << " " <<  *j;
      }
      cout << endl;
    }
  }
}
	

Measured memory_bytes: 1240
#include<iostream>
#include<vector>
#include<cassert>

const int mod = 998244353;
struct mint {
	long long x;
	mint(long long x = 0) : x((x%mod + mod)%mod) {} 

	mint operator - () const { return mint(-x); } 

	mint& operator += (const mint& a){
		if((x += a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator -= (const mint& a){
		if ((x += mod-a.x) >= mod) x -= mod;
		return *this;
	}
	mint& operator *= (const mint& a) {
		(x *= a.x) %= mod;
		return *this;
	}

	mint operator + (const mint& a) const { return mint(*this) += a;}
	mint operator - (const mint& a) const { return mint(*this) -= a;}
	mint operator * (const mint& a) const { return mint(*this) *= a;}

	//べき乗
	mint pow(long long t) const{
		if(!t) return 1;
		mint a = pow(t >> 1); 
		a *= a;
		if(t&1) a *= *this;
		return a;
	}

	//逆元を求める
	mint inv() const {
		return pow(mod - 2);
	}
	//割り算
	mint& operator /= (const mint a) { return (*this) *= a.inv(); }
	mint operator / (const mint a) const { return mint(*this) /= a; }
};
//入出力
std::istream& operator >> (std::istream& is, const mint& a) { return is >> a.x; }
std::ostream& operator << (std::ostream& os, const mint& a) { return os << a.x; }

struct combination {
	std::vector<mint> fact, ifact;

	combination(int n) : fact(n+1), ifact(n+1) {
		assert(n < mod);
		fact[0] = 1;
		for(int i=1; i<=n; i++){
			fact[i] = fact[i-1] * i;
		}
		ifact[n] = fact[n].inv();
		for(int i=n; i>=1; i--){
			ifact[i-1] = ifact[i] * i;
		}
	}
	mint operator () (int n, int k){
		if(k < 0 || k > n) return 0;
		return fact[n]*ifact[k]*ifact[n-k];
	}
}c(200005);


int main(){
	int n, m, k;
	std::cin >> n >> m >> k;

	mint ans = 0, col = m;
	for(int x=n-1; x>=0; x--){
		mint now = col;
		now *= c(n-1, x);
		if(x <= k){
			ans += now;
		}
		col *= m-1;
	}

	std::cout << ans << std::endl;
	return 0;

}

Measured memory_bytes: 6232
import java.util.*;

public class Main {
public static void main(String[] args) {
		
		Scanner keyboard = new Scanner(System.in); 
		
		int N  = keyboard.nextInt();
		int ans[] = new int[1000000];
		
		for(int x = 1; x<120; x++) {
			for(int y = 1; y<120; y++) {
				for(int z = 1; z<120; z++) {
					ans[(x+y+z)*(x+y+z)-x*(y+z)-y*z]++;
				}
			} 
		}
		
		for(int j =1; j<N+1; j++) {
			System.out.println(ans[j]);
		}
		keyboard.close();	
	}
}


Measured memory_bytes: 42628
#include<iostream>
#include<string>
#include<iomanip>
#include<cmath>
#include<vector>
#include<algorithm>
#include<utility>
#include<queue>


using namespace std;

#define int long long
#define endl "\n"

constexpr long long INF = (long long)1e18;
constexpr long long MOD = 1'000'000'007; 

struct fast_io {
	fast_io(){
		std::cin.tie(nullptr);
		std::ios::sync_with_stdio(false);
	};
} fio;


int H, W, K;
vector<string> c;

int dijkstra(int sy, int sx, int gy, int gx){
	priority_queue<pair<int,pair<int,int>>,vector<pair<int,pair<int,int>>>,greater<pair<int,pair<int,int>>>> q;
	
	vector<vector<int>> d(H, vector<int>(W, INF));
	
	d[sy][sx] = 0;
	q.push({0,{sy, sx}});
	
	while(!q.empty()){
		pair<int,pair<int,int>> p = q.top();q.pop();
		int x = p.second.second;
		int y = p.second.first;
		int cost = p.first;
		
		
		if(d[y][x] < cost) continue;
		
		if(y == gy && gx == x) return cost;
		
		{
			for(int i = x + 1; i < W; i++){
				if(c[y][i] == '@') break;
				if(d[y][i] <= d[y][x]) break;
				int ncost = (i - x - 1)/K + 1;
				
				if(ncost >= 2) break;
				
				if(ncost + cost < d[y][i]) {
					d[y][i] = ncost + cost;
					q.push({d[y][i], {y, i}});
				}
			}
			
			for(int i = x - 1; i >= 0; i--){
				if(c[y][i] == '@') break;
				if(d[y][i] <= d[y][x]) break;
				
				int ncost = (x - i - 1)/K + 1;
				
				if(ncost >= 2) break;
				if(ncost + cost < d[y][i]) {
					d[y][i] = ncost + cost;
					q.push({d[y][i], {y, i}});
				}
			}
		}
		
		{
			for(int i = y + 1; i < H; i++){
				if(c[i][x] == '@') break;
				if(d[i][x] <= d[y][x]) break;
				
				int ncost = (i - y - 1)/K + 1;
				if(ncost >= 2) break;
				if(ncost + cost < d[i][x]) {
					d[i][x] = ncost + cost;
					q.push({d[i][x], {i, x}});
				}
			}
			
			for(int i = y - 1; i >= 0; i--){
				if(c[i][x] == '@') break;
				if(d[i][x] <= d[y][x]) break;
				
				int ncost = (y - i - 1)/K + 1;
				if(ncost >= 2) break;
				if(ncost + cost < d[i][x]) {
					d[i][x] = ncost + cost;
					q.push({d[i][x], {i, x}});
				}
			}
		}
	}
	
	return -1;
}


signed main(){
	cout<<fixed<<setprecision(10);
	
	int x1, y1, x2, y2;
	
	cin>>H>>W>>K;
	
	
	cin>>x1>>y1>>x2>>y2;
	
	x1--;
	y1--;
	x2--;
	y2--;
	
	c.resize(H);
	
	for(int i = 0; i < H; i++){
		cin>>c[i];
	}
	cout<<dijkstra(x1, y1, x2, y2)<<endl;
	
	return 0;
}

Measured memory_bytes: 19792
# n, m, l = map(int, input().split())

# list_n = list(map(int, input().split()))

# n = input()
# list = [input() for i in range(N)

# list = [[i for i in range(N)] for _ in range(M)]

import sys
input = sys.stdin.readline


def cal(Sn, opt):
    ans = Sn[0]
    for i in range(3):
        if opt[i] == '+':
            ans += Sn[i+1]
        else:
            ans -= Sn[i+1]
    return ans


S = list(input().rstrip('\n'))
Sn = [int(i) for i in S]
op = ['+', '-']
opL = [(i, j, k) for i in op for j in op for k in op]

for opt in opL:
    if cal(Sn, opt) == 7:
        break

ans = ''
for i in range(3):
    ans += S[i] + opt[i]
ans += S[3] + '=7'
print(ans)


Measured memory_bytes: 9144
i=gets.split
w=i[0].to_i
h=i[1].to_i
x=i[2].to_i
y=i[3].to_i
r=i[4].to_i

if(x-r>=0 && y-r>=0 && w-x-r>=0 && h-y-r>=0)
   puts("Yes")
else puts("No")
end

Measured memory_bytes: 6100
import java.util.*;
import java.io.*;

class Main {

	void solve () {

		int a = in.nextInt(), b = in.nextInt();
		int[] ar = {a+b, a-b, a*b};
		Arrays.sort(ar);
		out.println(ar[2]);
		
	}

	public static PrintWriter out = new PrintWriter(System.out);
	public static Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main().solve();
		out.flush();
	}

}

Measured memory_bytes: 23764