akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define lli long long int
#define MODV 1000000007
#define INF INT_MAX // 2147483647
#define INFLL LLONG_MAX // 9223372036854775807
#define rep(i, n) for(lli i=0, i##_len=(lli)(n); i<i##_len; i++)
#define repf(i, n) for(lli i=1, i##_len=(lli)(n+1); i<i##_len; i++)
#define per(i, n) for(lli i=((lli)(n))-1; i>=0; i--)
#define perf(i, n) for(lli i=((lli)(n)); i>0; i--)
#define all(v) v.begin(), v.end()
#define endl "\n"
#define vi vector<lli>
#define vvi vector<vector<lli>>
#define Yes() cout << "Yes" << endl
#define YES() cout << "YES" << endl
#define No() cout << "No" << endl
#define NO() cout << "NO" << endl
template<class T>bool chmax(T &a, const T &b){ if(a<b){ a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b){ if(b<a){ a=b; return 1; } return 0; }
using namespace std;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << fixed << setprecision(10);
    lli n, m;
    cin >> n >> m;
    vvi ab(100001);
    rep(i, n){
        lli a, b;
        cin >> a >> b;
        ab[a].push_back(b);
    }

    priority_queue<lli> que;
    lli sum = 0;
    for(lli RemDay = 1; RemDay<=m; RemDay++){
        for(auto p: ab[RemDay]) que.push(p);
        if(!que.empty()){
            sum += que.top();
            que.pop();
        }
    }
    cout << sum << endl;
}

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

void checkA( char a[9][18] )
{
    int b[10];
    
    for( int i = 0; i < 9; i++ )
    {
        for( int j = 0; j < 10; j++ )
            b[j] = 0;
        for( int j = 1; j < 18;  j += 2 )
            b[a[i][j]-'0']++;
        for( int j = 1; j < 18;  j += 2 )
            if( b[a[i][j]-'0'] >= 2 )
                a[i][j-1] = '*';
    }
}

void checkB( char a[9][18] )
{
    int b[10];
    
    for( int i = 1; i < 18; i += 2 )
    {
        for( int j = 0; j < 10; j++ )
            b[j] = 0;
        for( int j = 0; j < 9; j++ )
            b[a[j][i]-'0']++;
        for( int j = 0; j < 9; j++ )
            if( b[a[j][i]-'0'] >= 2 )
                a[j][i-1] = '*';
    }
}

void checkC2( char a[9][18], int x, int y, int w, int z )
{
    int b[10];

    for( int j = 0; j < 10; j++ )
        b[j] = 0;

    for( int i = x; i <= w; i++ )
        for( int j = y; j <= z; j += 2 )
            b[a[i][j]-'0']++;

    for( int i = x; i <= w; i++ )
        for( int j = y; j <= z; j += 2 )
            if( b[a[i][j]-'0'] >= 2 )
                a[i][j-1] = '*';
}

void checkC1( char a[9][18] )
{
    checkC2( a, 0, 1, 2, 5 );
    checkC2( a, 0, 7, 2, 11 );
    checkC2( a, 0, 13, 2, 17 );
    checkC2( a, 3, 1, 5, 5 );
    checkC2( a, 3, 7, 5, 11 );
    checkC2( a, 3, 13, 5, 17);
    checkC2( a, 6, 1, 8, 5 );
    checkC2( a, 6, 7, 8, 11 );
    checkC2( a, 6, 13, 8, 17 );
}

int main()
{
    int n;

    cin >> n;

    for( int i = 0; i < n; i++ )
    {
        if( i != 0 )
            cout << endl;

        char a[9][18];
        for( int j = 0; j < 9; j++ )
        {
            for( int k = 0; k < 18; k++ )
            {
                if( k % 2 == 0 )
                    a[j][k] = ' ';
                else
                    cin >> a[j][k];
            }
        }

        checkA( a );
        checkB( a );
        checkC1( a );

        for( int j = 0; j < 9; j++ )
        {
            for( int k = 0; k < 18; k++ )
                cout << a[j][k];
            cout << endl;
        }

    }

    return 0;
}


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

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

    string s;
    cin >> s;
    stack<char> st;
    for (char c : s) {
        if (c == '*') {
            st.push(c);
        } else {
            if (st.empty()) {
                st.push(c);
            } else {
                if (st.top() == '(' && c == ')') {
                    st.pop();
                } else {
                    st.push(c);
                }
            }
        }
    }
    cout << (st.size() - 1) / 2 << endl;
}



Measured memory_bytes: 3208
#include <bits/stdc++.h>
using namespace std;
int a[200005],n;
int main(){
//	freopen("a.txt","r",stdin);
	cin>>n;
	for(int i=0;i<n;i++)cin>>a[i];
	int smallest=a[0];
	int res=a[1]-a[0];
	for(int i=1;i<n;i++){
		res=max(res,a[i]-smallest);
		smallest=min(smallest,a[i]);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 3888
using System;
using System.Collections.Generic;
using System.Linq;
public class Hello
{
    public static void Main()
    {
        
        var NM = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray();
        //展望台の数
        var N = NM[0];
        //道の数
        var M = NM[1];
        //高さを高さ配列に保持する
        var height = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray();
        var conn = new Dictionary<int,List<int>>();
        //pathをもたない展望台を記録するための配列
        var havePath = new bool[N];
        for(int num = 0;num < M;num++)
        {
            //pathの入力
            var path = Console.ReadLine().Split().Select(e => int.Parse(e)).ToArray();
            var A = path[0];
            var B = path[1];
            //起点となる展望台がすでに存在すれば行き先を追加
            // 存在しなければ生成する
            if(!conn.ContainsKey(A))
            {
                conn[A] = new List<int>();
                conn[A].Add(B);
            }
            else
            {
                conn[A].Add(B);
            }
            if(!conn.ContainsKey(B))
            {
                conn[B] = new List<int>();
                conn[B].Add(A);
            }
            else
            {
                conn[B].Add(A);
            }
            //行き先をもつ展望台を記録する
            havePath[A-1]=true;
            havePath[B-1]=true;
        }
        var ans = 0;
        //生成したDictionaryをすべてループする
        foreach(var c in conn)
        {
            //Keyとなる展望台の標高を保持する
            var heightNow = height[c.Key-1];
            var flg = true;
            foreach(var val in c.Value)
            {
                //標高が他の展望台以下であるなら回答になりえない
                if(heightNow <= height[val-1])
                {
                    flg =false;
                    break;
                }
            }
            if(flg)
            {
                ans++;
            }
        }
        Console.WriteLine(ans + havePath.Count(e => e == false));
    }
}


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

typedef long long ll;
const ll mod = 1e9 + 7;

struct matrix {
	int n;
	vector<vector<ll>> t;
	matrix(int size) {
		n = size;
		t.resize(size, vector<ll> (size, 0));
	}
	matrix multiply(matrix b) {
		matrix c = matrix(n);
		for (int i = 0; i < n; i++) {
			for (int j = 0; j < n; j++) {
				for (int k = 0; k < n; k++) {
					c.t[i][j] = (c.t[i][j] + t[i][k] * b.t[k][j]) % mod;
				}
			}
		}
		return c;
	}
	matrix expo(ll k) {
		matrix res = matrix(n);
		for (int i = 0; i < n; i++) {
			res.t[i][i] = 1;
		}
		while (k > 0) {
			if (k & 1) {
				res = res.multiply(*this);
			}
			*this = multiply(*this);
			k = k >> 1;
		}
		return res;
	}
};

int main() {
	ios_base::sync_with_stdio(false);
	
	int n;
	ll k;
	cin >> n >> k;
	matrix g = matrix(n);
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			cin >> g.t[i][j];
		}
	}
	g = g.expo(k);
	ll answer = 0;
	for (int i = 0; i < n; i++) {
		for (int j = 0; j < n; j++) {
			answer = (answer + g.t[i][j]) % mod;
		}
	}
	cout << answer;
	
	return 0;
}

Measured memory_bytes: 3728
#include <bits/stdc++.h>
using namespace std;
 
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define endl "\n"
#define int long long
#define double long double

const double PI = acosl(-1.0l);

double a, b, h, m;

int32_t main()
{
	IOS;
	cin >> a >> b >> h >> m;
	double angle1 = (2 * PI) / 12 * h;
	double angle2 = (2 * PI) / 60 * m;
	angle1 += (2 * PI) / (12 * 60) * m;
 	double diff = angle1 - angle2;
	if(diff < 0)
		diff += 2 * PI;
	if(diff == PI)
		cout << a + b;
	else
	{
		double ans = a * a + b * b - (2 * a * b * cos(diff));
		ans = sqrtl(ans);
		cout << fixed << setprecision(12) << ans;
	}
	return 0;
}


Measured memory_bytes: 4212
#include <algorithm>
#include <boost/optional.hpp>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstring>
#include <functional>
#include <iostream>
#include <limits>
#include <list>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <string>
#include <tuple>
#include <type_traits>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>

#define REP(i, n) for(int i = 0, i##_MACRO = (n); i < i##_MACRO; i++)
#define RANGE(i, a, b) for(int i = (a), i##_MACRO = (b); i < i##_MACRO; i++)
#define EACH(e, a) for(auto&& e : a)
#define ALL(a) std::begin(a), std::end(a)
#define RALL(a) std::rbegin(a), std::rend(a)
#define FILL(a, n) memset((a), n, sizeof(a))
#define FILLZ(a) FILL(a, 0)
#define INT(x) (static_cast<int>(x))

using namespace std;

using ll = long long;
using VI = vector<int>;
using VI2D = vector<vector<int>>;

constexpr int INF = 2e9;
constexpr double EPS = 1e-10;
constexpr double PI = acos(-1.0);

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

template <typename T>
constexpr int sign(T x) {
	return x < 0 ? -1 : x > 0 ? 1 : 0;
}

template <>
constexpr int sign(double x) {
	return x < -EPS ? -1 : x > EPS ? 1 : 0;
}

template <typename T, typename U>
constexpr void chmax(T& m, U x) {
	m = max(m, x);
}

template <typename T, typename U>
constexpr void chmin(T& m, U x) {
	m = min(m, x);
}

template <typename T>
constexpr T square(T x) {
	return x * x;
}

int main() {
	int n, k;
	string s;
	cin >> n >> k;
	cin >> s;
	s[k - 1] = s[k - 1] + ('a' - 'A');
	cout << s << endl;
	return 0;
}


Measured memory_bytes: 3600
#include<iostream>
#include<vector>
#include<string>
#define rep(i, start, end) for (int i = (int)start; i < (int)end; ++i)
#define rrep(i, start, end) for (int i = (int)start - 1; i >= end; --i)
#define iter(i, c) for (auto i = (c).begin(); i != (c).end(); ++i)
#define riter(i, c) for (auto i = (c).rbegin(); i != (c).rend(); ++i)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
using namespace std;
using ll = long long;

const ll INF = 1LL << 50;

ll dp[404][404];

ll dfs(const vector<ll>& c, int l, int r) {
    // [l,r)
    if (r - l == 1) {
        return dp[l][r] = 0;
    }
    if (dp[l][r] >= 0) {
        return dp[l][r];
    }
    ll res = INF;
    rep(i, l + 1, r) {
        ll left_cost = dfs(c, l, i);
        ll right_cost = dfs(c, i, r);
        res = min(res, left_cost + right_cost + c[r] - c[l]);
    }
    return dp[l][r] = res;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    vector<ll> A(N);
    rep(i, 0, N) cin >> A[i];
    vector<ll> cumsum(N + 1, 0);
    rep(i, 1, N + 1) {
        cumsum[i] = A[i - 1] + cumsum[i - 1];
    }
    rep(i, 0, N + 1) rep(j, 0, N + 1) {
        dp[i][j] = -1;
    }
    cout << dfs(cumsum, 0, N) << endl;
    return 0;
}

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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

ll gcd(ll a, ll b)
{
    if (a < b)
        gcd(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    ll a[200001];
    cin >> n;
    for (int i = 0; i < n; i++)
        cin >> a[i];

    deque<ll> d;
    for (int i = 0; i < n; i++)
        if (i % 2 == 0)
            d.push_back(a[i]);
        else
            d.push_front(a[i]);

    if (n % 2)
        reverse(d.begin(), d.end());

    for (auto it = d.begin(); it != d.end(); it++)
    {
        cout << *it;
        if (it + 1 != d.end())
            cout << " ";
    }
    cout << endl;
}


Measured memory_bytes: 5376
#pragma comment(linker, "/STACK:10240000")
#include <bits/stdc++.h>

using namespace std;

const int MAXN = 20;

char s[MAXN];
int a[MAXN];

long long dfs (int k, int m, int n)
{
    long long ans = 0;
    if (k >= n)
    {
        int last = 0;
        long long tmp;
        for (int i = 1; i <= n; i ++)
        {
            if (a[i] == 1)
            {
                tmp = 0;
                while (last < i)
                {
                    tmp = tmp * (long long) 10 + (long long) s[last] - '0';
                    last ++;
                }
                ans += tmp;
            }
        }
        tmp = 0;
        while (last < n)
        {
            tmp = tmp * (long long) 10 + (long long) s[last] - '0';
            last ++;
        }
        ans += tmp;
    }
    else
    {
        if (m)
        {
            a[k] = 1;
            ans += dfs (k + 1, m - 1, n);
            a[k] = 0;
        }
        a[k] = 0;
        ans += dfs (k + 1, m, n);
    }
    return ans;
}

int main ()
{
    scanf ("%s", &s);
    int len = strlen (s);
    printf ("%lld\n", dfs (1, len - 1, len));
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define loop(i,a,b) for(int i=a;i<b;i++)
#define test() int t;cin>>t;loop(test,1,t+1)
#define pb push_back
#define eb emplace_back
#define mkp make_pair
#define nl cout<<"\n"
#define sp cout<<" "
#define F first
#define S second
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vii vector<pii>
#define vll vector<pll>
#define prsp(v) loop(i,0,v.size())cout<<v[i],sp;nl;
#define prpsp(v) loop(i,0,v.size())cout<<v[i].F<<" "<<v[i].S<<" , ";nl;
#define prnl(v) loop(i,0,v.size())cout<<v[i],nl;nl;
#define prpnl(v) loop(i,0,v.size())cout<<v[i].F<<" "<<v[i].S,nl;nl;
#define MOD 1000000007
#define mod(n) (((n%MOD)+MOD)%MOD)
#define all(x) x.begin(),x.end()

template<class C> void min_self( C &a, C b ){ a = min(a,b); }
template<class C> void max_self( C &a, C b ){ a = max(a,b); }

const int MAXN = 1e5+5;
int dx[] = {1,0,-1,0};
int dy[] = {0,1,0,-1};

vector<pii>gr[MAXN];
bool vis[MAXN];

void dfs(int node, int par)
{
    vis[node]=1;
    for(int i=0;i<gr[node].size();i++)
    {
        int next = gr[node][i].F;
        if( !vis[next] )
        {
            dfs(next,node);
        }
    }
}

int main() 
{
    fastio();

    int n,m,x,y,z;
    cin>>n>>m;
    loop(i,0,m)
    {
        cin>>x>>y>>z;
        x--,y--;
        gr[x].pb({y,z%2});
        gr[y].pb({x,z%2});
    }

    int cc=0;
    loop(i,0,n)
    {
        if( !vis[i] )
        {
            cc++;
            dfs(i,-1);
        }
    }
    cout<<cc,nl;


    cerr << "\nTime elapsed: " << 1000 * clock() / CLOCKS_PER_SEC << "ms\n";
    return 0;
}

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

using namespace std;

vector<array<int, 2>> V;
unordered_multimap<int, int> E;

void dfs(int v, int prev, int t, int d) {
  V[v][t] = d;
  auto r = E.equal_range(v);
  for_each(r.first, r.second, [=](auto& i) {
    if (i.second != prev) dfs(i.second, v, t, d + 1);
  });
};

int main() {
  int N, u, v;
  cin >> N >> u >> v;
  for (int i = N - 1; i--;) {
    int a, b;
    cin >> a >> b;
    E.emplace(a - 1, b - 1);
    E.emplace(b - 1, a - 1);
  }
  V.resize(N);
  dfs(u - 1, -1, 0, 0);
  dfs(v - 1, -1, 1, 0);
  int ans = 0;
  for (auto& v : V)
    if (v[1] > v[0]) ans = max(ans, v[1]);
  cout << ans - 1 << endl;
  return 0;
}


Measured memory_bytes: 15688
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
         Scanner sc=new Scanner(System.in);
         int i;
        String line=sc.nextLine();
         String answer="";
        int length=line.length();
        for(i=0;i<length;i++){
            char ch =line.charAt(i);
            if(Character.isLowerCase(ch)==true){
                answer+=Character.toUpperCase(ch);
            }else{
                answer+=Character.toLowerCase(ch);
            }
        }
        System.out.println(answer);
    }
}



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


void solve(int N, int K, string S){
    vector<int> Nums;
    int now = 1;
    int cnt = 0;
    for(int i = 0; i < N; i++){
        if(S[i] == (char)('0' + now)) cnt++;
        else{
            Nums.push_back(cnt);
            now = 1 - now;
            cnt = 1;
        }
    }
    if(cnt != 0) Nums.push_back(cnt);

    if(Nums.size() % 2 == 0) Nums.push_back(0);

    int Add = 2 * K + 1;

    int ans = 0;

    for(int i = 0; i < Nums.size(); i += 2){
        int tmp = 0;
        int left = i;
        int right = min(i + Add, (int)Nums.size());
        for(int j = left; j < right; j++){
            tmp += Nums[j];
        }
        ans = max(tmp, ans);
    }

    cout << ans << endl;
}

int main(){
    int N, K;
    cin >> N >> K;
    string S;
    cin >> S;
    solve(N, K, S);
    return 0;
}

Measured memory_bytes: 1148
let rec manipulate maxH lst =
    match lst with
    | [] -> true
    | [x] -> maxH - x <= 1
    | x :: tail when maxH - x > 1 -> false
    | x :: tail -> manipulate (max maxH x) tail

let _ = stdin.ReadLine() |> int
stdin.ReadLine().Split(' ')
|> Array.map int
|> Array.toList
|> manipulate 0
|> fun flag -> if flag then "Yes" else "No"
|> printfn "%s"


Measured memory_bytes: 29912
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <string.h>
#include <math.h>
#include <string>
using namespace std;

int kaijou(int num){
  int i,fact=1;
  for(i=1; i<=num; ++i) {
    fact = fact * i;
  }
  return fact;
}

int main() {
	cin.tie(0);
  ios::sync_with_stdio(false);
 
	int n,k,i,j,r,a,b;
  vector<int> v;
  cin>>n;
  for(i=0;i<n;i++){
    int tmp;
    cin>>tmp;
    v.push_back(tmp);
  }
  sort(v.begin(), v.end());

  int sum, min=10000000;
  for(int p=v[0]; p <= v[n-1]; p++){
    sum=0;
    for(i=0; i<n; i++){
      sum+=pow(v[i]-p,2);
    }
    if(min>sum)min=sum;
  }
  cout<<min;

  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <deque>
#include <list>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>

using namespace std;

//typedef
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//conversion
inline LL toLong(string s) {LL v; istringstream sin(s);sin>>v;return v;}
template<class T> inline string toString(T x) {ostringstream sout;sout<<x;return sout.str();}

//math
//-------------------------------------------
template<class T> inline T sqr(T x) {return x*x;}

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) LL((a).size())
#define EACH(i,c) for(auto i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//repetition
#define FOR(i,a,b) for(LL i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define UNTIL(p) while(!(p))

//constant
const double EPS = 1e-5;
const double PI  = acos(-1.0);

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

#define PUTS(x) cout << (x) << endl;

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin>>s;
    PUTS((s[0] == s[1] || s[1] == s[2] || s[2] == s[3]) ? "Bad" : "Good");

}

Measured memory_bytes: 256
#define  _CRT_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES

#pragma comment (linker, "/STACK:526000000")

#include "bits/stdc++.h"

using namespace std;
typedef string::const_iterator State;
#define eps 1e-11L
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL

#define MOD 998244353LL
#define seg_size 262144 * 4LL
#define pb push_back
#define mp make_pair
typedef long long ll;
#define REP(a,b) for(long long (a) = 0;(a) < (b);++(a))
#define ALL(x) (x).begin(),(x).end()

void init() {
    iostream::sync_with_stdio(false);
    cout << fixed << setprecision(20);
}


//#define int ll

unsigned long xor128() {
    static unsigned long x = 123456789, y = 362436069, z = 521288629, w = 88675123;
    unsigned long t = (x ^ (x << 11));
    x = y; y = z; z = w;
    return (w = (w ^ (w >> 19)) ^ (t ^ (t >> 8)));
}
vector<int> a, b;
int dp[2][3][60][60][60][60];
int suma[60][60];
int sumb[60][60];
int dfs(int c, int d, int e, int f, int g, int h) {
    if (d == 3) return 0;
    if (dp[c][d][e][f][g][h] != -1e9) return dp[c][d][e][f][g][h];
    int now = suma[e][f] - sumb[g][h]; // set it to "pass"
    now += dfs((c + 1) % 2, d + 1, f, f, h, h);
    if (c == 0) {
        if (f != a.size()) {
            if (a[f] != -1) {
                now = max(now, dfs(1, 0, e, f + 1, g, h));
            }
            else {
                now = max(now, dfs(1, 0, e, f + 1, h, h));
            }
        }
    }
    else {
        if (h != b.size()) {
            if (b[h] != -1) {
                now = min(now, dfs(0, 0, e, f, g, h + 1));
            }
            else {
                now = min(now, dfs(0, 0, f, f, g, h + 1));
            }
        }
    }
    return dp[c][d][e][f][g][h] = now;
}
void solve() {
    int n, m;
    cin >> n >> m;
    REP(i, n) {
        int c;
        cin >> c;
        a.push_back(c);
    }
    REP(i, m) {
        int c;
        cin >> c;
        b.push_back(c);
    }
    REP(i, n) {
        int geko = 0;
        for (int q = i; q < n; ++q) {
            geko += max(0, a[q]);
            suma[i][q + 1] = geko;
        }
    }
    REP(i, m) {
        int geko = 0;
        for (int q = i; q < m; ++q) {
            geko += max(0, b[q]);
            sumb[i][q + 1] = geko;
        }
    }
    REP(i, 2) {
        REP(q, 3) {
            REP(j, 60) {
                REP(j2, 60) {
                    REP(j3, 60) {
                        REP(j4, 60) {
                            dp[i][q][j][j2][j3][j4] = -1e9;
                        }
                    }
                }
            }
        }
    }
    cout << dfs(0, 0, 0, 0, 0, 0) << endl;
}

#undef int
int main() {
    init();
    solve();
}


Measured memory_bytes: 306988
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <bitset>
#include <algorithm>
#include <cmath>
#include <numeric>
#include <utility>
#include <set>
#include <map>
#include <tuple> 
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <list>
using namespace  std;
typedef pair<long long , long long> P;
typedef long long ll;
typedef long long lint;
#define REP(i, n) for(long long (i)=0; (i)<(n); ++i)
#define FOR(i, a, b) for(long long (i)=(a); (i)<(b); ++i)
#define ALL(a) (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
const long long MOD = static_cast<long long>(1e9) + 7LL;
const long long INF = 1234567891234567890LL;
signed main(){
    int N; cin>>N;
    vector<ll> A(N);
    REP(i, N) cin>>A[i];
    vector<ll> B(N);
    REP(i, N) cin>>B[i];
    vector<ll> res(30);
    vector<ll> X(N);
    for(int k=0; k<=28; k++){
        REP(i, N) X[i] = B[i] % (1<<(k+1));
        sort(ALL(X));
        for(int i=0; i<N; i++){
            ll a = A[i] % (1<<(k+1));
            res[k] += lower_bound(ALL(X), (1<<k)*2-a) - lower_bound(ALL(X), (1<<k)-a);
            res[k] += lower_bound(ALL(X), (1<<k)*4-a) - lower_bound(ALL(X), (1<<k)*3-a);
        }
    }
    ll ans = 0;
    for(int i=0; i<=28;i++){
        if(res[i]%2){
            ans += 1<<i;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4992
//https://atcoder.jp/contests/abc142/tasks/abc142_c
#include <bits/stdc++.h>
using namespace std;
using ll=int64_t;
#define FOR(i,a,b) for(int64_t i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
int main() {
    ll N; cin>>N;
    vector<pair<ll,ll>> an(N+1); //no,id
    FOR(i,1,N+1){
        cin>>an.at(i).first;
        an.at(i).second=i;
    }
    sort(an.begin()+1,an.end());

    FOR(i,1,N+1){
        if(i!=1)cout<<" ";
        cout<<an.at(i).second;
    }
    cout<<endl;
    return 0;
}

Measured memory_bytes: 2432
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

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

func main() {
	sc.Split(bufio.ScanWords)

	a := getInt()
	b := getInt()
	c := getInt()

	ma := max(a, max(b, c))
	su := 0
	if ma == a {
		su = b + c
	} else if ma == b {
		su = a + c
	} else {
		su = a + b
	}

	if ma == su {
		out("Yes")
	} else {
		out("No")
	}

}


Measured memory_bytes: 640
# coding=utf-8

###
### for atcorder program
###

import sys
import math

# math class
class mymath:
    ### pi
    pi = 3.14159265358979323846264338

    ### Prime Number
    def pnum_eratosthenes(self, n):
        ptable = [0 for i in range(n+1)]
        plist = []

        for i in range(2, n+1):
            if ptable[i]==0:
                plist.append(i)
                for j in range(i+i, n+1, i):
                    ptable[j] = 1
        return plist

    ### GCD
    def gcd(self, a, b):
        if b == 0:
            return a
        return self.gcd(b, a%b)

    ### LCM
    def lcm(self, a, b):
        return (a*b)//self.gcd(a,b)

    ### Mat Multiplication
    def mul(self, A, B):
        ans = []
        for a in A:
            c = 0
            for j, row in enumerate(a):
                c += row*B[j]
            ans.append(c)
        return ans

mymath = mymath()

### output class
class output:
    ### list
    def list(self, l):
        l = list(l)
        #print(" ", end="")
        for i, num in enumerate(l):
            print(num, end="")
            if i != len(l)-1:
                print(" ", end="")
        print()

output = output()

### input sample
#i = input()
#N = int(input())
#A, B, C = [x for x in input().split()]
#N, K = [int(x) for x in input().split()]
#inlist = [int(w) for w in input().split()]

#R = float(input())
#A.append(list(map(int,input().split())))

#for line in sys.stdin.readlines():
#    x, y = [int(temp) for temp in line.split()]

#abc list
#abc = [chr(ord('a') + i) for i in range(26)]

### output sample
#print("{0} {1} {2:.5f}".format(A//B, A%B, A/B))
#print("{0:.6f} {1:.6f}".format(R*R*math.pi,R*2*math.pi))
#print(" {}".format(i), end="")

def get_input():
    N = []
    while True:
        try:
            N.append(input())
            #N.append(int(input()))
            #N.append(float(input()))
        except EOFError:
            break
    return N

def is_integer(n):
    try:
        float(n)
    except ValueError:
        return False
    else:
        return float(n).is_integer()

def dist(A, B):
    d = 0
    for i in range(len(A)):
        d += (A[i]-B[i])**2            
    d = d**(1/2)
    return d

N, D = [int(x) for x in input().split()]
X = []

for i in range(N):
    X.append([int(x) for x in input().split()])

count = 0

for i in range(len(X)):
    for j in range(i+1,len(X)):
        d = dist(X[i],X[j])
        if is_integer(d):
            count += 1
            #print(d)
print(count)

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

int main() {

  int N;
  cin >> N;

  string s = to_string(N);

  int sn = 0;
  for (int i = 0; i < s.size(); i++) {
    sn += s[i] - '0';
  }

  if (N % sn == 0) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }

}

Measured memory_bytes: 256
# include<iostream>
# include <cstdio>
# include <cstring>
using namespace std;
int main(void){
    char s[1000];
    scanf("%s",s);
    int len = strlen(s);
    int ans = 0;
    for (int i=0;i<len/2;i++)
    if (s[i]!=s[len-i-1]) ans++;
    printf("%d\n",ans);
    return 0;
}

Measured memory_bytes: 256
# coding: UTF-8
import sys
#sys.setrecursionlimit(n)
import heapq
import re
import bisect
import random
import math
import itertools
from collections import defaultdict, deque
from copy import deepcopy
from decimal import *

n, m = map(int, input().split())
a = [0] * (n + 2)
r = defaultdict(int)
for i in range(m):
    x,y = map(int,input().split())
    a[x - 1] += 1
    a[y] += -1

for i in range(n + 1):
    a[i + 1] += a[i]
count = 0
flg = True
for i in range(n):
    if a[i] >= m:
        count += 1
print(count)

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

int main() {
    int N;
    cin >> N;
    string str;
    cin >> str;
    int ans = 0;
    while (N--) {
        string old;
        cin >> old;

        bool flag = false;
        for (int i = 0, len = old.size(); i < len; i++) {
            for (int j = 1; i + (j - 1) * ((int)str.size() - 1) + (int)str.size() <= len; j++) {
                bool f = true;
                for (int k = 0, l = str.size(); f && k < l; k++) {
                    if (str[k] != old[i + k * j]) f = false;
                }
                if (f) flag = true;
            }
            if (flag) break;
        }
        if (flag) ans++;
    }
    cout << ans << endl;

    return 0;
}

Measured memory_bytes: 3144
#!/usr/bin/env python3
import sys
read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 7)

n = int(readline())
s = str(readline())
count = 0
for i in range(0,n - 2):
    if s[i] == 'A' and s[i + 1] == 'B' and s[i + 2] == 'C':
        count +=1
print(count)

Measured memory_bytes: 3064
#include <iostream>
#include <vector>
#include <string>
#include <climits>
#define input std::cin

using vector = std::vector<int>;
using lint = long long int;
using string = std::string;

class lazytree {
  public:
	std::vector<int> prop;
	lazytree (int n) : prop (4*n, INT_MAX) {}

	void update (int l, int r, int v, int tl, int tr, int t) {
	  if (l > r)
		return;
	  if (l == tl && r == tr)
		prop[t] = std::min (v, prop[t]);
	  else {
		int mid = (tl + tr)/2;
		update (l, std::min (r, mid), v, tl, mid, 2*t+1);
		update (std::max(l, mid+1), r, v, mid+1, tr, 2*t+2);
	  }
	}

	int query (int i, int v, int tl, int tr, int t) {
	  if (tl == tr) {
		prop[t] = std::min (v, prop[t]);
		return prop[t];
	  }
	  prop[t] = std::min (v, prop[t]);
	  int mid = (tl + tr)/2;
	  if (i <= mid)
		return query (i, prop[t], tl, mid, 2*t+1);
	  else
		return query (i, prop[t], mid+1, tr, 2*t+2);
	}
};

int main() {
  int n, q; input >> n >> q;
  lazytree mincols (n);
  mincols.update(0, n-1, n, 0, n-1, 0);
  lazytree minrows (n);
  minrows.update(0, n-1, n, 0, n-1, 0);
  lint blacks = (n-2) * (lint) (n-2);
  for (int i=0; i<q; i++) {
	int opt, x; input >> opt >> x;
	if (opt == 1) {
	  int row = minrows.query (x-1, INT_MAX, 0, n-1, 0);
	  mincols.update (0, row-1, x, 0, n-1, 0);
	  blacks -= row-2;
	} else {
	  int col = mincols.query (x-1, INT_MAX, 0, n-1, 0);
	  minrows.update (0, col-1, x, 0, n-1, 0);
	  blacks -= col-2;
	}
  }
  std::cout << blacks << std::endl;
}



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


int main() {
	int n;
	cin >> n;
	vector<long double> a(n);
	for (int i = 0; i < n; i++) {
		cin >> a[i];
	}
	sort(a.begin(), a.end());
	long double sum = (a[0] + a[1]) / 2;
	for (int i = 2; i < n; i++) {
		sum = (sum + a[i]) / 2;
	}
	cout << fixed << setprecision(10) << sum;
	return 0;
}

Measured memory_bytes: 3788
#include<bits/stdc++.h>
using namespace std;
#define inf 1000000000
#define INF 1000000000000000
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define PLL pair<ll,ll>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
#define IN(a,n) rep(i,n){ cin>>a[i]; }
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define PI 3.14159265
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
void init(){
  cin.tie(0);
  ios::sync_with_stdio(false);
}



signed main(){
  init();
  int n;
  cin>>n;
  vector<int> a(n);
  rep(i,n){
    cin>>a[i];
  }
  int ans = __gcd(a[0],a[1]);

  rep(i,n){
    ans = __gcd(ans,a[i]);
  }

  cout<<ans<<endl;
}


Measured memory_bytes: 1024
#include<iostream>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 998244353
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
  int a,b;cin>>a>>b;
  int ans=a-b+1;
  cout<<ans<<endl;


}


Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <complex>
#include <deque>
#include <iostream>
#include <istream>
#include <iterator>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>
#include <tuple>
#include <iomanip>
#include <climits>
#include <fstream>
#include <random>
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
//typedef pair<ll, ll> P;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define revrep(i, n) for(int i = (n)-1; i >= 0; i--)
#define pb push_back
#define f first
#define s second
#define chmin(x, y) x = min(x, y);
#define chmax(x, y) x = max(x, y);
#define sz(x) ((int)(x).size())

//const ll INFL = LLONG_MAX;//10^18 = 2^60
const ll INFL = 1LL<<60;
//const int INF = INT_MAX;
const int INF = 1 << 30;//10^9
const ll MOD = 1000000007;
//const ll MOD = 998244353;
double EPS = 1e-10;

vector<ll> dy = {0, 1, 0, -1, 1, 1, -1, -1, 0};
vector<ll> dx = {1, 0, -1, 0, 1, -1, 1, -1, 0};

void pres(double A){printf("%.12lf\n", A);}
void BinarySay(ll x, ll y = 60){rep(i, y) cout << (x>>(y-1-i) & 1); cout << endl;}
ll cnt_bit(ll x){return __builtin_popcountll(x);}

ll pow_long(ll x, ll k){
  ll res = 1;
  while(k > 0){
    if(k % 2) res *= x;
    x *= x; k /= 2;
  }
  return res;
}

ll pow_mod(ll x, ll k){
  x %= MOD;
  ll res = 1;
  while(k > 0){
    if(k % 2){
      res *= x; res %= MOD;
    }
    x *= x; x %= MOD;
    k /= 2;
  }
  return res;
}

ll inverse(ll x){return pow_mod(x, MOD - 2);};

ll gcd(ll a, ll b){
    if(b == 0) return a;
    return gcd(b, a % b);
}

ll lcm(ll x, ll y){
  ll res = x / gcd(x, y);
  res *= y;
  return res;
};


//コンビネーション
const int MAXcomb = 200010;
ll fac[MAXcomb], finv[MAXcomb], inv[MAXcomb];
//facはn!,finvは1/n!
//invは逆元
void COMinit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(int i = 2; i < MAXcomb; i++){
        fac[i] = fac[i-1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}
ll comb(int n, int k){
    if(n < k) return 0;
    if(n < 0 || k < 0) return 0;
    return fac[n] * finv[k] % MOD * finv[n-k] % MOD;
}

const int MAXkai = 200010;
ll kai_memo[MAXkai];
ll kai(ll N){
  if(kai_memo[N] != 0) return kai_memo[N];
  if(N <= 1) return 1;
  return kai_memo[N] = N * kai(N-1) % MOD;
}

ll disit(ll s, ll base = 10){
  ll res = 0;
  while(s){
    res++;
    s /= base;
  }
  return res;
}

//約数の列挙O(√n)
vector<ll> divisor(ll n){
    vector<ll> res(0);
    for(ll i = 1; i * i <= n; i++){
        if(n % i == 0){
            res.push_back(i);
            if(i != n/i) res.push_back(n/i);
        }
    }
    sort(res.begin(), res.end());
    return res;
}

vector<int> a = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
void solve(){
  int K;
  cin >> K;
  cout << a[K-1] << endl;
}

int main(){
  ios_base::sync_with_stdio(0);
  cin.tie(0), cout.tie(0);
  solve();
}


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

using ll = long long;

using namespace std;

//0 -> a-1
#define rep(i, a) for (int i = 0; (i) < (int)(a); (i)++)
//a -> b-1
#define reps(i, a, b) for (int i = (int)(a); (i) < (int)(b); (i)++)
//a-1 -> 0
#define rrep(i, a) for (int i = (int)a - 1; (i) >= 0; (i)--)
//a-1 -> b
#define rreps(i, a, b) for (int i = (int)(a)-1; (i) >= (int)(b); (i)--)
#define MP(a, b) make_pair((a), (b))
#define PB(a) push_back((a))
#define all(v) (v).begin(), (v).end()
//next_permutation(all(v))
#define PERM(v) next_permutation(all(v))
/*sort(all(v));
(v).erase(unique(all(v)), v.end())*/
#define UNIQUE(v) \
	sort(all(v)); \
	(v).erase(unique(all(v)), v.end())
#define CIN(type, x) \
	type x;          \
	cin >> x
#define YES(f) if ((f)) {cout << "YES" << endl;} else {cout << "NO" << endl;}
#define Yes(f) if ((f)) {cout << "Yes" << endl;} else {cout << "No" << endl;}
#define MINV(v) min_element(all(v))
#define MAXV(v) max_element(all(v))
#define MIN3(a, b, c) min(min(a, b), c)
#define MIN4(a, b, c, d) min(MIN3(a, b, c), d)
#define MIN5(a, b, c, d, e) min(MIN4(a, b, c, d), e)
#define MIN6(a, b, c, d, e, f) min(MIN5(a, b, c, d, e), f)
#define MAX3(a, b, c) max(max(a, b), c)
#define MAX4(a, b, c, d) max(MAX3(a, b, c), d)
#define MAX5(a, b, c, d, e) max(MAX4(a, b, c, d), e)
#define MAX6(a, b, c, d, e, f) max(MAX5(a, b, c, d, e), f)
//b is [a, c)
#define RANGE(a, b, c) ((a) <= (b) && (b) < (c))
//c is [a, e) && d is [b, f)
#define RANGE2D(a, b, c, d, e, f) (RANGE((a), (c), (e)) && RANGE((b), (d), (f)))
#define chmin(a, b) a = min(a, (b))
#define chmin3(a, b, c) a = MIN3(a, (b), (c))
#define chmin4(a, b, c, d) a = MIN4(a, (b), (c), (d))
#define chmin5(a, b, c, d, e) a = MIN5(a, (b), (c), (d), (e))
#define chmin6(a, b, c, d, e, f) a = MIN6(a, (b), (c), (d), (e), (f))
#define chmax(a, b) a = max(a, (b))
#define chmax3(a, b, c) a = MAX3(a, (b), (c))
#define chmax4(a, b, c, d) a = MAX4(a, (b), (c), (d))
#define chmax5(a, b, c, d, e) a = MAX5(a, (b), (c), (d), (e))
#define chmax6(a, b, c, d, e, f) a = MAX6(a, (b), (c), (d), (e), (f))
#define fcout cout << fixed << setprecision(12)
#define RS resize
#define CINV(v, N)             \
	do                         \
	{                          \
		v.RS(N);               \
		rep(i, N) cin >> v[i]; \
	} while (0);

#define RCINV(v, N)             \
	do                          \
	{                           \
		v.RS(N);                \
		rrep(i, N) cin >> v[i]; \
	} while (0);
#define MOD 1000000007

template <class T>
inline T GET()
{
	T x;
	cin >> x;
	return x;
}

void init();
void solve();

signed main()
{
	init();
	solve();
}

void init()
{
	int N;
	cin >> N;
	vector<pair<int, int>> v;
	int M;
	if (N % 2) M = N;
	else M = N + 1;
	reps(i, 1, N+1) {
		reps(j, i+1, N+1) {
			if (i + j != M) {
				v.PB(MP(i, j));
			}
		}
	}
	cout << v.size() << endl;
	for (auto p : v) {
		cout << p.first << " " << p.second << endl;
	}
}

void solve()
{
}


Measured memory_bytes: 384
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.AbstractMap;
import java.util.StringTokenizer;

public class Main {

	public static void main(String[] args) {
		FastScanner sc = new FastScanner(System.in);
		PrintWriter out = new PrintWriter(System.out);

		solve(sc,out);

		out.flush();
	}

	public static void solve(FastScanner sc, PrintWriter out) {
		long r = sc.nextLong();
		long d = sc.nextLong();
		long x = sc.nextLong();
		
		long[] dp = new long[100];
		
		dp[1] = x;
		
		for(int i = 2; i < 12; i++) {
			dp[i] = r*dp[i-1]-d;
		}
		
		for(int i = 2; i < 12; i++) {
			out.println(Math.abs(dp[i]));
		}
 	}

	public static int gcd(int a, int b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
	
	public static long gcd(long a, long b) {
		if(a < b) return gcd(b, a);
		if(b == 0) return a;
		return gcd(b, a % b);
	}
}

class Pair<K, V> extends AbstractMap.SimpleEntry<K, V> {

    public Pair(final K key, final V value) {
        super(key, value);
    }
 }

class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;

    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }

        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
     }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    }
}

Measured memory_bytes: 23124
#include <cstdio>
#include <cstring>
#include <cmath>
#include <cstdlib>
#include <iostream>

using namespace std;
int main(){
int n;
cin >> n;
int data;
data = n;
int d[10];
int m = 1;
for (int i = 0; i<10 ;i++){
	d[i] = ( n % (9*m) )/m;
	n = n - n % (9*m);
	m = m*9;
}
n = data;
int j[10];
int k[10];
int pans;
int ans = 100000;
for (j[5] = 0; j[5] <= 2; j[5]++){
	for (j[4] = 0; j[4] <= 8; j[4]++){
		for (j[3] = 0; j[3] <= 8; j[3]++){
			for (j[2] = 0; j[2] <= 8; j[2]++){
			for (j[1] = 0; j[1] <= 8; j[1]++){
					
						n = n - (j[5] * 59049 + j[4] * 6561 + j[3] * 729 + j[2] * 81 + j[1] * 9);
					if(n >= 0){
						int m = 1;
                                                int pans = 0;
						for (int i = 0; i<10 ;i++){
						k[i] = ( n % (6*m) )/m;
						n = n - n % (6*m);
						m = m*6;
						pans = pans + k[i];
						}
						
					pans = pans + j[1] + j[2] + j[3] + j[4] + j[5];
					n = data;
					if(pans <= ans){
						ans = pans;
				} else {}
}
			}
}		}
	}
}

cout << ans;
return 0;

}


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

typedef vector<int> vi;
const int maxn = 100010;
#define pb push_back

int a[maxn];

long long s[maxn];
long long f[maxn];
long long g[maxn];

int main() {
	int n, K; scanf("%d%d", &n, &K);
	for(int i = 1; i <= n; ++i) {
		scanf("%d", &a[i]);
		s[i] = s[i-1] + a[i];
		f[i] = f[i-1] + max(a[i], 0);
		if(i == K) {
			g[i] = max(s[i], 0ll);
		} else {
			g[i] = f[i-K] + max(s[i] - s[i-K], 0ll);
			g[i] = max(g[i], g[i-1] + max(a[i], 0));
		}
	}
	printf("%lld\n", g[n]);
	return 0;
}


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

int main(){
  string card,tmp;
  int h,shu;
  while(1){
    cin >> card;
    if(card == "-") break;
    cin >> h;
    for(int i=0;i<h;i++){
      cin >> shu;
      tmp = card.substr(0,shu);
      card.erase(0,shu);
      card += tmp;
    }
    cout << card << endl;
  }
}
  

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

int main() {
  int N;
  cin>>N;
  int a=0;
  std::vector<int> t(N);
  for(int i=0;i<N;i++){
    cin>>t[i];
    a+=t[i];
  }
  int M;
  cin>>M;
  int p,x;
  std::vector<int> b(M);
  for(int i=0;i<M;i++){
    cin>>p>>x;
    b[i]=a-t[p-1]+x;
  }
  for(int i=0;i<M;i++)cout<<b[i]<<endl;
}


Measured memory_bytes: 256
from itertools import product

n,a,b,c,*L = map(int,open(0).read().split())

li1 = [1,2,3,4]
ans = 10**10
for v in product(li1,repeat = n):
    num = 0
    A,B,C = [],[],[]
    for i in range(n):
        if v[i] == 1:
            A.append(L[i])
        elif v[i] == 2:
            B.append(L[i])
        elif v[i] == 3:
            C.append(L[i])

    if A and B and C:
        num +=abs(sum(A)-a) + max(0,(len(A)-1)*10) + abs(sum(B)-b) + max(0,(len(B)-1)*10)+ abs(sum(C)-c) + max(0,(len(C)-1)*10)
        ans = min(ans,num)

print(ans)

Measured memory_bytes: 75836
#include<stdio.h>
int main(void)
{
	int a,b,c,d,e,f,g,h,x,y;
	scanf("%d",&a);
	scanf("%d",&b);
	scanf("%d",&c);
	scanf("%d",&d);
	scanf("%d",&e);
	scanf("%d",&f);
	scanf("%d",&g);
	scanf("%d",&h);
	x=a+b+c+d;
	y=e+f+g+h;
	if(x>=y){
		printf("%d\n",x);
	}
	else{
		printf("%d\n",y);
	}
	
	return 0;
}



Measured memory_bytes: 2680
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <queue>
#include <stack>
#include <map>
#include <algorithm>
#include <math.h>
#include <cassert>
#define rep(i,n) for(int i = 0; i < n; ++i )
using namespace std;
using ll = long long;
using P = pair<int,int>;

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a[i], --a[i];
  int ans = 0;
  rep(i,n-1){
    if(i!=a[i])continue;
    swap(a[i],a[i+1]);
    ++ans;
  }
  if(a[n-1]==n-1) ++ans;
  cout << ans << endl;
}

Measured memory_bytes: 640
#include <iostream>
#include <fstream>
#include <cstdio>
#include <vector>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <stack>
#include <queue>
#include <algorithm>
#include <string.h>
#include <string>
#include <math.h>
#include <iomanip>
#include <cassert>
#include <random>
using namespace std;

#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
#define pb push_back
#define FOR(i, n) for(int i = 0; i < (n); i++)
typedef pair<int, int> pii;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;

const int mod = 1e9 + 7;
const int mod2 = 998244353;

void fact_init(int n);
ll exp(ll taban, ll us, ll md);
ll ebob(ll a, ll b);
ll ekok(ll a, ll b);
ll komb(ll a, ll b);

vector<ll> fact;
vector<ll> inv_fact;
void fact_init(int n){
    fact.resize(n+5);
    inv_fact.resize(n+5);
    fact[0] = inv_fact[0] = 1;
    for(int i = 1; i <= n; i++){
        fact[i] = (fact[i-1] * i) % mod;
        inv_fact[i] = exp(fact[i], mod-2, mod);
    }
}
ll exp(ll taban, ll us, ll md) {
    ll carpan = taban % md;
    if(carpan == 0) return 0;
    ll temp = us;
    ll res = 1;
    while(temp){
        if(temp % 2) res = (res*carpan) % md;
        temp /= 2;
        carpan = (carpan*carpan) % md;
    }
    return res;
}
 
ll ebob(ll a, ll b){
    if(!a)return b;
    return ebob(b%a, a);
}

ll ekok(ll a, ll b){
    return (a*b)/ebob(a, b);
}

ll komb(ll a, ll b){
    if(a < b) return 0;
    return fact[a] * (inv_fact[a-b] * inv_fact[b] % mod) % mod;
}
const int N = 3e5 + 5;

int main(){
    ios::sync_with_stdio(false); cin.tie(NULL);
	fact_init(2005);
	int s; cin>>s;
	ll res = 0;
	for(int i = 1; i <= 2000 && s - 3*i >= 0; i++){
		int tmp = s - 3*i;
		//a1 + a2... + ai = tmp
		res = (res + komb(tmp + i -1, tmp))%mod;
	}
	cout<<res<<"\n";
}

Measured memory_bytes: 3668
a = int(input())

l = [a]
b = a
c = 1
while True:
    if b % 2 == 0:
        b = int(b/2)
    else:
        b = 3 * b + 1

    c += 1

    if b in l:
        break

    l.append(b)

print(c)


Measured memory_bytes: 2940
import java.util.Scanner;

public class Main {
	public static void main(String args[]) {
		Scanner scn = new Scanner(System.in);
		int d,w,h;
		while((d = scn.nextInt())!=0) {
			w = scn.nextInt();
			h = scn.nextInt();
			int max = Math.max(d, Math.max(w,h));
			long L = d*d + w*w + h*h -max*max;
			int n = scn.nextInt();
			for(int i = 0; i < n;i++) {
				int a = scn.nextInt();
				System.out.println(L < 4*a*a?"OK":"NA");
			}
		}
		scn.close();
	}
}



Measured memory_bytes: 25848