akhauriyash/Code-Regression huggingface dataset:
X = int(input())
import math

def is_prime(n):
    if n == 1: return False

    for k in range(2, int(math.sqrt(n)) + 1):
        if n % k == 0:
            return False

    return True

while True:
  if is_prime(X) == False:
    X += 1
  else:
    break

print(X)

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

using namespace std;

typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const ll MOD = (ll)1e9 + 7;

int main()
{
  vector<string> v(2);
  cin >> v[0] >> v[1];
  int N = v[0].size() + v[1].size();
  string ans;
  for (int i = 0; i < N; ++i) {
    ans.push_back(v[i & 1][i / 2]);
  }
  printf("%s\n", ans.c_str());
  return 0;
}


Measured memory_bytes: 256
uses
  SysUtils,
  Classes;
 
 function isLower(const value : string): boolean;
	const
		UPP = 'ABCDEFGHIJKLMNOPQRSTUVWXYZ';
	var
		upper : string;
		i : Integer;
	begin
	Result := True;
	upper := UPP;
	if Length(Value) <> 1 then
		Exit(False);
	for i := 1 to Length(upper) do
		if value = upper[i] then
			Exit(False);
	end;
 
 function judgeFunc(const Value : string) : string;
	const
		BAD = 'WA';
		OK = 'AC';
	var
		i : Integer;
		flag : Boolean;
	begin
	Result := OK;
	flag := False;
	i := 1;
	if not (Value[i] = 'A') then
		Exit(BAD);
	Inc(i);
	if  not isLower(Value[i]) then
		Exit(BAD);
	i := Length(Value);
	if not isLower(Value[i]) then
		Exit(BAD);
	for i := 3 to Length(Value) - 1 do
		begin
			if Value[i] = 'C' then
				begin
				if flag then
					Exit(BAD)
				else
					flag := True;
				end
			else if not isLower(Value[i]) then
				Exit(BAD);
		end;
	if not flag then
		Result := BAD;
	end;
 
procedure MainProc;
	var
		aText : string;
		pushText : string;
	begin
	ReadLn(aText);
	pushText := judgeFunc(aText);
	writeLn(pushText);
	end;
	
begin
MainProc;
end.


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main()
{
    int n;
    cin >> n;
    string s[n];
    for(int i = 0;i < n;i++)
    {
        cin >> s[i];
        sort(s[i].begin(),s[i].end());
    }
    sort(s,s + n);
    long long int sum = 0;
    for(int i = 0;i < n;i++)
    {
        long long int count = 0;
        for(int j = i + 1;j < n;j++)
        {
            if(s[i] == s[j])
            {
                count++;
                i++;
            }
            else
            {
                break;
            }            
        }
        if(count != 0)
        {
            sum = sum + count * (count + 1) / 2;
        }
    }
    cout << sum;
 
    return 0;
}

Measured memory_bytes: 7296
#include <bits/stdc++.h>
#ifdef _DEBUG
#include "debug.hpp"
#else
#define debug(...)
#endif
#define REP(i, m, n) for(int (i) = (m); (i) < (n); ++i)
#define rep(i, n) REP(i, 0, n)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int INF = 1e9 + 7;
const ll LINF = 1LL << 60;
template<class T, class U> inline bool chmax(T &a, const U &b) { if(a < b) { a = b; return true; } return false; }
template<class T, class U> inline bool chmin(T &a, const U &b) { if(a > b) { a = b; return true; } return false; }

int q;

int main() {
  cin.tie(0); ios::sync_with_stdio(false);
  cin >> q;
  rep(qi,q) {
    string x, y;
    cin >> x >> y;
    int n = x.size(), m = y.size();
    vector<vector<int>> dp(n+10, vector<int>(m+10, 0));
    rep(i,n) rep(j,m) {
      if(x[i] == y[j]) chmax(dp[i+1][j+1], dp[i][j]+1);
      else {
        chmax(dp[i+1][j+1], max(dp[i+1][j], dp[i][j+1]));
      }
    }
    cout << dp[n][m] << '\n';
  }
  return 0;
}


Measured memory_bytes: 6884
#include<bits/stdc++.h>
using namespace std;
#define maxn 200050
#define fi first
#define se second
#define PII pair<int,int>
PII ans[maxn];int k;
PII cal(int x,int y){
	if(x>y){
		PII w=cal(y,x);
		return {w.se,w.fi};
	}
	if(x<0){
		PII w=cal(-x,y);
		return {-w.fi,w.se};
	}
	if(x+y>=2*k)return {x,y-k};
	if(x+y==k)return {0,0};
	int t=k-(x+y)/2;//k为奇数且(x+y)为奇数时需要三步，不好理解，第一步使abs(x)+abs(y)=k+1,然后就正常了 
	return {-t,y-k+x+t};
}
int main(){
	int x,y,si=0;scanf("%d%d%d",&k,&x,&y);
	if(!(k&1)&&(x+y)&1)return puts("-1"),0;
	ans[si]={x,y};
	for(;ans[si].fi|ans[si].se;si++)ans[si+1]=cal(ans[si].fi,ans[si].se);
	printf("%d\n",si);
	while(si--)printf("%d %d\n",ans[si].fi,ans[si].se);
	return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  long long N;
  long long min,max,sum;
  //vector<vector<int>> A(n, vector<int>(m, 0));
  double a,b,C;

  while(1){
  	cin >> N;
    if(N == 0)break;
    
    a = 0;
    b = 0;
    C = 0;
    vector<double> A(N, 0.0);
    for(int i=0; i<N; i++){
    	cin >> A.at(i);
        a += A.at(i);
    }
    a /= N;
    
    for(int i=0; i<N; i++){
    	A.at(i) -= a;
        b += pow(A.at(i), 2.0);
    }
    b /= N;
    
    C =  sqrt(b);
    
    cout << std::fixed << std::setprecision(6) << C << endl;
  }
}


Measured memory_bytes: 3296
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double lb;
typedef vector<int,vector<int>> vec;
typedef pair<int,int> P;
#define REP(i,j,n) for (int i=j;i<(n);i++)
#define RREP(i,n,j) for (int i = n; j<i;i--)
#define print(out) cout<< out  << "\n";
#define all(vec) vec.begin(),vec.end()
#define mod 1000000007
const int INF = 1e9;

ll calcNumOfCombination(ll n, ll r){
    ll num = 1;
    for(ll i = 1; i <= r; i++){
        num = num * (n - i + 1) / i;
    }
    return num;
}

int main(){
  ll N,a;cin>>N;
  map<ll,ll>mp,mp1,mp2;
  vector<ll> vec(N);
   REP(i,0,N){
    cin>>a;
    mp[a]++;
    vec[i]=a;
  }

  for (const auto& m : mp){
      mp1[m.first]=(m.second>=2?calcNumOfCombination(m.second,2):0);
      mp2[m.first]=(m.second-1>=2?calcNumOfCombination(m.second-1,2):0);
  }
  ll sm=0;
    for (const auto& m : mp1){
      sm+=mp1[m.first];
    }

  REP(i,0,N){
    ll ans=sm+mp2[vec[i]]-mp1[vec[i]];
    print(ans)
  }
}


Measured memory_bytes: 26880
import java.io.*;
public class Main {
    public static void main(String[] args) {
        BufferedReader reader=new BufferedReader(new InputStreamReader(System.in));
        try{
            String line=reader.readLine();
            int x=Integer.parseInt(line);
            System.out.println(x*x*x);
        }
        catch(IOException e){
            System.out.println(e);
        }
    }
}


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

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

  int A, B;
  cin >> A >> B;

  if (A <= 8 && B <= 8) {
    cout << "Yay!\n";
  } else {
    cout << ":(\n";
  }

  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i,n) for(ll i=0;i<(n);++i)
#define sayyes cout<<"Yes"<<endl;
#define sayno cout<<"No"<<endl;
using namespace std;
typedef long long ll;
const double PI=acos(-1);
typedef pair<int,int>P;
const int mod =1e9+7;

int main()
{
    ll s;
    cin>>s;
    string ans;
    while(s>0)
    {
        int z=s%26;
        if(z==0)
        {
            ans+='z';
        }
        else
        {
            ans+=('a'+(z-1));
        }
        s--;
        s/=26;

    }
    reverse(ans.begin(),ans.end());
    cout<<ans;
    
}


Measured memory_bytes: 3584
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<queue>
#include<string>
#include<set>
#include<utility>
#include<vector>

using namespace std;
typedef long long ll;
#define rep(i, n) for(int i=0; i<n; i++)
#define per(i, n) for(int i=n-1; i>=0; i--)
#define reps(i, n) for(int i=1; i<n; i++)
#define pers(i, n)  for(int i=n-1; i>=1; i--)

const int INF = 1001001001;

ll ncr(ll n, ll r){
  if(n-r<r) r=n-r;
  if(r==0)  return 1;
  if(r==1)  return n;
  if(n==0)  return 0;

  ll ret = 1;
  for(int i=0; i<r; i++){
    ret *= (n-i);
    ret /= (i+1);
  }
  return ret;
}



void solve(){
  ll N;  cin >> N;
  vector<ll> vec(N);
  rep(i, N) cin >> vec[i];
  sort(vec.rbegin(), vec.rend());
  ll n = vec[0];
  ll r = 0, p=0;
  reps(i, N){
    ll cr = min(n-vec[i], vec[i]);
    if(r<=cr){
      r = cr;
      p = i;
    }
  }
  cout << n << " " << vec[p] << endl;
}

int main(){
  solve();
  return 0;
}


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

#include <iostream>
//#include <algorithm>
// #include <iomanip>
#define ll long long
#define map unordered_map
#define set unordered_set

using namespace std;

const ll MOD = 1000000007;
const ll INF = (1LL << 62);

int main() {
  // std::cout << std::fixed << std::setprecision(10);

  ll N, K;
  scanf("%lld %lld", &N, &K);

  vector<ll> list(N);
  for (ll i = 0; i < N; i++) {
    ll v;
    scanf("%lld", &v);
    list[i] = v;
  }

  ll ans = 0;

  ll cnt = min(N, K);
  for (ll move = 0; move <= cnt; move++) {
    // cout << "# move:" << move << endl;

    for (ll left = 0; left <= move; left++) {
      priority_queue<int, vector<int>, greater<int>> queue;
      ll right = move - left;

      // cout << "## left:" << left;
      // cout << ", right:" << right << endl;

      for (ll k = 0; k < left; k++) {
        ll val = list[k];
        queue.push(val);
      }
      for (ll k = 0; k < right; k++) {
        ll val = list[list.size() - 1 - k];
        queue.push(val);
      }

      /////

      ll throw_minus = K - move;
      // cout << "throw_minus:" << throw_minus << endl;
      for (ll m = 0; m < throw_minus; m++) {
        if (queue.size() == 0) {
          break;
        }
        ll val = queue.top();
        if (val < 0) {
          queue.pop();
        }
      }

      ll sum = 0;
      for (;;) {
        if (queue.size() == 0) {
          break;
        }
        ll v = queue.top();
        // cout << v << endl;
        sum += v;
        queue.pop();
      }
      // cout << "sum:" << sum << endl;
      // cout << "" << endl;

      ans = max(ans, sum);
    }  // move
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
#include <iostream>
#include <sstream>
#include <string>
#include <cassert>
#include <cmath>
#include <climits>
#include <cstdio>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <stack>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>

using namespace std;
typedef unsigned int uint;
typedef long long ll;
typedef unsigned long long ull;

#define REP(i,n) for(int i = 0; i < (int)(n); ++i)
#define FOR(i,a,b) for(int i = (a); i < (int)(b); ++i)
#define ALL(c) (c).begin(), (c).end()
#define SIZE(v) ((int)v.size())

#define pb push_back
#define mp make_pair
#define mt make_tuple

const int INF = 1e9;

int main(void)
{
    cin.sync_with_stdio(false);
    int N, M;
    cin >> N >> M;
    vector<pair<int,int>> edges(M);
    REP(m, M) {
        int a, b;
        cin >> a >> b;
        --a; --b;
        edges[m] = mp(a, b);
    }
    
    int ans = 0;
    REP(m, M) {
        vector<vector<int>> d(N, vector<int>(N, INF));
        REP(i, N) d[i][i] = 0;

        REP(m2, M) {
            if (m == m2) continue;
            int a, b;
            tie(a, b) = edges[m2];
            d[a][b] = d[b][a] = 1;
        }

        // Warshall Floyd
        REP(k, N){
            REP(i, N){
                REP(j, N){
                    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }

        bool bridge = false;
        REP(i, N){
            REP(j, N){
                if (d[i][j] == INF) {
                    bridge = true;
                }
            }
        }

        ans += bridge;
    }

    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 888
s = input()
t = input()
c = []
for i in range(len(s)-len(t)+1):
    flag = True
    for j in range(len(t)):
        if s[i+j] != "?" and s[i+j] != t[j]:
            flag = False
            break
    if flag:
        c.append((s[:i] + t + s[i+len(t):]).replace("?", "a"))
c.sort()
if len(c) == 0:
    print("UNRESTORABLE")
else:
    print(c[0])

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i,ini,n) for(int i=ini;i<n;i++)
#define _rep(i,ini,n) for(int i=ini;i>=n;i--)
#define ToEnd(a) a.begin(),a.end()
uint64_t MOD=1000000007;

int main(){
    int A,B,C,X,Y; cin>>A>>B>>C>>X>>Y;

    int ans=0;
    if(A+B<=2*C){
        ans+=A*X+B*Y;
    }else{
        int minPz,minPz_p,maxPz,maxPz_p;
        if(X>=Y){minPz=Y;minPz_p=B;maxPz=X;maxPz_p=A;}
        else{minPz=X;minPz_p=A;maxPz=Y;maxPz_p=B;}

        if(2*C<=maxPz_p) ans+=2*maxPz*C;
        else ans+=2*minPz*C+(maxPz-minPz)*maxPz_p;
    }

    cout<<ans<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
const int INF = 1e9;
const int MOD = 1e9+7;
const long long LINF = 1e18;
#define dump(x)  cout << 'x' << ' = ' << (x) << ` `;
#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;i>=0;i--)
#define FOREACH(x,a) for(auto& (x) : (a) )
typedef long long ll;
using namespace std;
typedef pair<ll, ll> P;

template<typename T>
void print(const vector<T> &x) {
    int n = x.size();
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x) {
    int n = x.size();
    rep(i,n) {
        rep(j,x[i].size()) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

template<typename T>
void print(const vector<T> &x, int n) {
    rep(i,n) {
        cout << x[i];
        if (i!=n-1) cout<<" ";
        else cout << endl;
    }
}

template<typename T>
void print(const vector<vector<T>> &x, int n, int m) {
    rep(i,n) {
        rep(j,m) {
            cout << x[i][j] << " ";
        }
        cout << endl;
    }
}

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

void input_init() {
    cin.tie(0); ios::sync_with_stdio(false);
}

int main(int argc, char const *argv[]) {
    ll h,w; cin>>h>>w;
    ll x = h*w;
    if (h==1 || w==1) {
        cout << 1 << '\n';
        return 0;
    }
    if (x%2) {
        cout << (x/2)+1ll << '\n';
    }
    else {
        cout << x/2 << '\n';
    }
    return 0;
}

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

#define rep(i, a, b) for(int i = a; i < (b); ++i)
#define trav(a, x) for(auto& a : x)
#define all(x) x.begin(), x.end()
#define sz(x) (int)(x).size()

typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vl;

const ll big = 1000000007;
const ll mod = 998244353;

ll n,m,q;
ll T;

string s;
vector<string> ANS;
set<string> S;

string alfa = "abcdefghijklmnopqrstuvwxyz";

int main() {

    ios_base::sync_with_stdio(0);
    cin.tie(0);
    //freopen("input.txt","r",stdin);
    //freopen("autput.txt","w",stdout);
    ll a,b,c,e;

    cin >> s;
    n = s.length();
    cin >> m;

   for(int c1 = 0; c1 < n; c1++){
        string s2 = "";
        for(int c2 = c1; c2 < min(c1+7ll,n); c2++){
            s2 += s[c2];
            if(S.find(s2) == S.end()){
                S.insert(s2);
                ANS.push_back(s2);
            }
        }
   }

    sort(all(ANS));

    cout << ANS[m-1] << "\n";

    return 0;
}


Measured memory_bytes: 2812
H,W =  map(int,input().split())

board = [list(map(int,input().split())) for x in range(H)]
moves = []
for i in range(H):
    for j in range(W):
        if board[i][j] % 2 == 1:
            if i < H - 1 and (board[i+1][j] % 2 == 1 or j == W - 1):
                moves.append([i+1,j+1,i+2,j+1])
                board[i+1][j] += 1
            elif j < W - 1:
                moves.append([i+1,j+1,i+1,j+2])
                board[i][j+1] += 1

print(len(moves))
for i in range(len(moves)):
    print(" ".join(map(str,moves[i])))


Measured memory_bytes: 29668
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <stack>
#include <queue>
#include <cmath>
#include <tuple>
#include <cstdio>
#include <bitset>
#include <sstream>
#include <iterator>
#include <numeric>
#include <map>
#include <cstring>

using namespace std;

#define DEBUG_ //!!提出時にコメントアウト!!
#ifdef DEBUG_
	#define dump(x)  cerr << #x << " = " << (x) << endl;
#else
	#define dump(x)  ; //何もしない文
#endif

#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define SZ(x) ((int)(x).size()) //unsignedのサイズをint型に変換
#define pb push_back

typedef long long LL; 
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<LL, LL> PLL;

template <typename T>
std::string printVector(const std::vector<T> &data)
{
    std::stringstream ss;
    std::ostream_iterator<T> out_it(ss, ", ");
    ss << "[";
    std::copy(data.begin(), data.end() - 1, out_it);
    ss << data.back() << "]";
    return ss.str();
}

const int MOD = 1e9+7;
const LL LINF = 1001002003004005006ll;
const int INF = 1001001001;

int main(int argc, char const *argv[])
{
    cin.tie(0);
    ios::sync_with_stdio(false);	
    LL N; cin >> N;
    LL obj;
    vector<LL> yakusu;
    for(LL i = 1; i * i <= N; i++)
    {
        if(N % i == 0) 
        {
            yakusu.pb(i);
            obj = N / i;
        }


    }
    int ans = 0;
    while(1)
    {
        if(obj / 10 > 0)
        {
            obj /= 10;
            ans++;
        }
        else
        {
            ans++;
            break;
        }
    }

    cout << ans << endl;

}


Measured memory_bytes: 256
#pragma comment(linker, "/STACK:1000000000")
#define _CRT_SECURE_NO_WARNINGS
#define _SCL_SECURE_NO_WARNINGS
#define _USE_MATH_DEFINES
#include <cstdio>
#include <vector>
#include <algorithm>
#include <string>
#include <cstring>
#include <queue>
#include <deque>
#include <map>
#include <unordered_map>
#include <set>
#include <unordered_set>
#include <bitset>
#include <memory>
#include <cassert>
#include <cstdlib>
#include <cmath>
#include <ctime> 
#include <stack>
#include <iostream>
#include <fstream>

#define mp make_pair
#define pb push_back

using ll = long long;
using ld = long double;

using namespace std;

const int MAXN = 200001;

set <int> e[MAXN];

int q[MAXN], qe = 0;

void eredge(int x, int y) {
	e[x].erase(y);
	if (e[x].empty()) {
		cout << "First" << endl;
		exit(0);
	}
	if (e[x].size() == 1) q[qe++] = x;
}

int main() {
	//freopen("input.txt", "r", stdin); freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0); cout.setf(ios::fixed); cout.precision(20);
	int n;
	cin >> n;
	for (int i = 1; i < n; i++) {
		int a, b;
		cin >> a >> b;
		e[a].insert(b);
		e[b].insert(a);
	}	
	for (int i = 1; i <= n; i++) {
		if (e[i].size() == 1) q[qe++] = i;
	}
	for (int qb = 0; qb < qe; qb++) {
		int v = q[qb];
		int v2 = *e[v].begin();
		for (int u : e[v2]) {
			if (u != v)
				eredge(u, v2);
		}
	}
	cout << "Second" << endl;
	return 0;
}

Measured memory_bytes: 19328
import sys
sys.setrecursionlimit(1000000)
input = sys.stdin.readline
from bisect import *
from collections import *
from heapq import *
INF = 500000
mod = 10**9+7

cs = atoz = [chr(i) for i in range(97,97+10)]

N = int(input())

def Str(i, m, S):
    if i == N:
        print(S)
        return
    for c in cs[:m]:
        Str(i+1, m, S+c)
    Str(i+1, m+1, S+cs[m])

Str(0, 0, '')


Measured memory_bytes: 4764
#include <cstdio>           // printf(), scanf()
#include <string>
#include <queue>
#include <map>
#include <algorithm>        // swap()

using namespace std;
static const int N = 3;
static const int N2 = 9;

struct puzzle
{
	int f[N2];
	int space;
	string path;
	bool operator < (const puzzle &p) const
	{
		for (int i = 0; i < N2; ++i)
		{
			if (f[i] != p.f[i])
				return f[i] > p.f[i];
		}

		return false;
	}
};

bool
is_target(puzzle p)
{
	for (int i = 0; i < N2; ++i)
	{
		if (p.f[i] != i + 1)
			return false;
	}

	return true;
}

static const int dx[4] = {-1, 0, 1, 0};
static const int dy[4] = {0, -1, 0, 1};
static const char dir[4] = {'u', 'l', 'd', 'r'};

string
bfs(puzzle s)
{
	queue<puzzle> Q;
	map<puzzle, bool> V;
	puzzle u, v;
	s.path = "";
	Q.push(s);
	V[s] = true;

	while (!Q.empty())
	{
		u = Q.front(); Q.pop();
		if (is_target(u))
			return u.path;

		int sx = u.space / N;
		int sy = u.space % N;
		for (int r = 0; r < 4; ++r)
		{
			int tx = sx + dx[r];
			int ty = sy + dy[r];
			if (tx < 0 || ty < 0 || tx >= N || ty >= N)
				continue;

			v = u;
			swap(v.f[u.space], v.f[tx * N + ty]);
			v.space = tx * N + ty;
			if (!V[v])
			{
				V[v] = true;
				v.path += dir[r];
				Q.push(v);
			}
		}
	}

	return "unsolvable";
}

int
main(int argc, char** argv)
{
	puzzle in;

	for (int i = 0; i < N2; ++i)
	{
		scanf("%d", &in.f[i]);
		if (in.f[i] == 0)
		{
			in.f[i] = N2;
			in.space = i;
		}
	}

	string ans = bfs(in);
	printf("%lu\n", ans.size());
	return 0;
}

Measured memory_bytes: 28540
#pragma region Macros
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define REPR(i, n) for(int i=(n); i>=0; --i)
#define FOR(i, n, m) for(int i=(m), i##_len=(n); i<i##_len; ++i)
#define EACH(i, v) for(const auto& i : v)
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
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; }
template<class Value>using vec = vector< Value >;
using ll = long long;
using P = pair< long long, long long >;
#define fi first
#define se second
#define el endl
#pragma endregion
void Main();

int main(){
    std::cin.tie(nullptr);
    std::cout << std::fixed << std::setprecision(15);
    Main();
    return 0;
}

void Main(){
    string S;
    cin >> S;
    vec<ll> memo(S.length()+1, -1);
    ll cnt = -1;
    REP(i, S.length()){
        if(S[i] == '<'){
            if(cnt < 0){
                cnt = 0;
            }
            memo[i] = cnt;
        }else{
            memo[i] = cnt;
            cnt = -2;
        }
        cnt++;
    }
    memo[S.length()] = cnt;
    cnt = -1;
    REPR(i, S.length()-1){
        if(S[i] == '>'){
            if(cnt < 0){
                cnt = 0;
            }
            memo[i+1] = max(cnt, memo[i+1]);
        }else{
            memo[i+1] = max(cnt, memo[i+1]);
            cnt = -2;
        }
        cnt++;
    }
    memo[0] = max(cnt, memo[0]);
    ll ans = 0;
    REP(i, S.length()+1){
        //cout << memo[i] << " ";
        ans += memo[i];
    }
    //cout << el;
    cout << ans << el;
}



Measured memory_bytes: 7676
#include <cstdio>
#include <algorithm>

using namespace std;

const int MAXN=1e5+10,INF=1e9+4;

int dp[MAXN],N,ans=0;

int main(){
    scanf("%d",&N);
    fill(dp+1,dp+N+1,INF);
    for(int i=1;i<=N;i++){
        int temp;
        scanf("%d",&temp);
        auto l=lower_bound(dp+1,dp+1+i,temp);
        *l=temp;
        ans=max(ans,(int)(l-dp));
    }

    printf("%d\n",ans);

    return 0;
}


Measured memory_bytes: 3124
#include <stdio.h>

int selectionsort(int A[],int N)
{
	int i,j,t,minj;
	int count = 0;
	
	for(i = 0; i < N - 1; i++)
	{
		minj = i;
		for(j = i; j < N; j++)
		{
			if(A[j] < A[minj])
			{
				minj = j;
			}
		}
		
		t = A[minj];
		A[minj] = A[i];
		A[i] = t;
		
		if(i != minj)
		{
			count++;
		}
	}
	return count;
}

int main(void)
{
	int A[100],N,count;
	int i;
	
	scanf("%d",&N);
	
	for(i = 0; i < N; i++)
	{
		scanf("%d",A + i);
	}
	
	count = selectionsort(A,N);
	
	for(i = 0; i < N; i++)
	{
		if(i > 0)
		{
			printf(" ");
		}
		
		printf("%d",A[i]);
	}
	printf("\n");
	
	printf("%d\n",count);
	
	return 0;
}
	

Measured memory_bytes: 604
# -*- coding: utf-8 -*-


if __name__ == '__main__':

    N, W = map(int, input().split())
    I = [None] + [list(map(int, input().split())) for _ in range(N)]
    C = [[0 for _ in range(W + 1)] for _ in range(N + 1)]

    for i in range(1, N + 1):
        for w in range(1, W + 1):
            if I[i][1] <= w:
                C[i][w] = max(C[i - 1][w - I[i][1]] + I[i][0], C[i - 1][w])
            else:
                C[i][w] = C[i - 1][w]

    print(C[N][W])



Measured memory_bytes: 42476
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {

       Scanner ab = new Scanner(System.in);

		int a= ab.nextInt();
		int b= ab.nextInt();
        
        if((a<=9)&&(b<=9)){
        System.out.println(a*b);
        }else{
            System.out.println(-1);
        }

    }
}

Measured memory_bytes: 21844
#1:初期化
N = int(input())
h = list(map(int, input().split()))
inf = float("inf")
dp = [inf]*(N)

#2:初期値
dp[0] = 0

#3:dp実行部
for i in range(1,N):
    dp[i] = min(dp[i], dp[i-1] + abs(h[i] - h[i-1]))
    if(i>1): #2つ目の足場には二個前の足場がないので．
        dp[i] = min(dp[i], dp[i-2] + abs(h[i] - h[i-2]))

#4:出力
print(dp[N-1])

Measured memory_bytes: 13928
n = int(input())
l = [[0 for i in range(13)] for j in range(4)]
pattern = ['S', 'H', 'C', 'D']
for _ in range(n):
    m, num = input().split()
    l[pattern.index(m)][int(num)-1] = 1

for i in range(4):
    for j in range(13):
        if not l[i][j]:
            print(pattern[i], j+1)
        



Measured memory_bytes: 5604
n = int(input())
li = []
for i in range(n):
    li.append(int(input()))
list.sort(li,reverse = True)
total = 0
for i in range(n):
    if i == 0:
        total += 1
        continue
    else:
        if li[i] == li[i-1]:
            continue
        else:
            total += 1
print(total)

Measured memory_bytes: 3060
import java.util.Scanner;

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

        String aStr = String.valueOf(a);
        String bStr = String.valueOf(b);

        String aA = "";
        String bB = "";

        for (int i = 0; i < a; i++) {
            aA += bStr;
        }

        for (int i = 0; i < b; i++) {
            bB += aStr;
        }

        if (aA.compareTo(bB) < 0) {
            System.out.println(aA);
        } else {
            System.out.println(bB);
        }

    }
}


Measured memory_bytes: 21588
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
typedef long long ll;

int main()
{

    int a,b,c,k,ans=0,l=0;
    scanf("%d %d %d %d",&a,&b,&c,&k);

    while(l<k&&a>0)
    {
        ans=ans+1;
        a=a-1;
        l=l+1;
    }

    while(l<k&&b>0)
    {
        b=b-1;
        l=l+1;
    }

    while(l<k)
    {
        ans=ans-1;
        l=l+1;
    }


        printf("%d\n",ans);

    return 0;
}

Measured memory_bytes: 1720
#include<bits/stdc++.h>
namespace my_std{
	using namespace std;
	#define Rint register int
	#define FOR(i,a,b) for(register int i=(a);i<=(b);++i)
	#define ROF(i,a,b) for(register int i=(a);i>=(b);--i)
	#define GO(x) for(register int i=p[x].head,v;i;i=e[i].link)
	#define FILE(s) freopen(s".in","r",stdin),freopen(s".out","w",stdout)
	#define PII pair<int,int>
	#define MP make_pair
	typedef long long LL;
	typedef double DB;
	inline LL read(){
		LL ans=0,f=1;char c=getchar();
		while(c>'9'||c<'0'){ f^=(c=='-'); c=getchar(); }
		for(;c<='9'&&c>='0';c=getchar()) ans=ans*10+c-'0'; return f?ans:-ans;
	}
	const int mod = 1e9+7;
	inline void inc(int &x,const int &y){ x+=y; if(x>=mod) x-=mod; }
	inline int ksm(int x,LL y){ int res=1; for(;y;y>>=1,x=1ll*x*x%mod) if(y&1) res=1ll*res*x%mod; return res;}
}
using namespace my_std;

LL n,m , ans,pre;

int main(){
	n = read();
//	printf("%lld\n",n);
	for(LL l = 1,r = 1;l <= n;l = r + 1){
		r = n/(n/l);
		pre = n/l;
		if(n % pre == 0 && (n/pre)-1 <= r && (n/pre)-1 >= l) ans += (n / pre) - 1;
	}
	printf("%lld",ans);
	return 0;
}


Measured memory_bytes: 256
MOD = 10**9 + 7
N = 10**6 + 10

fact = [1]*(N+1)
rfact = [1]*(N+1)
r = 1
for i in range(1, N+1):
  fact[i] = r = r * i % MOD
rfact[N] = r = pow(fact[N], MOD-2, MOD)
for i in range(N, 0, -1):
  rfact[i-1] = r = r * i % MOD

# nPk (mod MOD) を求める
def perm(n, k):
  return fact[n] * rfact[n-k] % MOD

# nCk (mod MOD) を求める
def comb(n, k):
  return fact[n] * rfact[k] * rfact[n-k] % MOD

n,m,k = map(int,input().split())

p = comb(n*m-2, k-2)

ans = 0
for i in range(1,n):
    ans += i * (n-i) * m * m * p
    ans %= MOD

for i in range(1,m):
    ans += i * (m-i) * n * n * p
    ans %= MOD

print(ans)

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

int main() {
  int n, a, b; cin >> n >> a >> b;
  int c = 0;
  for(int i = 1; i <= n; i++){
    int p, q, r, s, t, u;
    p = i /10000;
    q = (i / 1000) % 10;
    r = (i / 100 ) % 10;
    s = (i / 10  ) % 10;
    t = i % 10;
    u = p + q + r + s + t;
    if(u >= a && u <= b)c += i;
  }
  cout << c << endl;
}

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

int main(){
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    int N;
    cin >> N;
    bool flg = false;

    for(int i = 1; i < 10; ++i){

        for(int j = 1; j < 10; ++j){

            if(i * j == N) flg = true;
        }
    }
    if(flg) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int N;
long long K;
vector<long long> A, F, S;
long long cost(long long x) {
    long long sum = 0;
    for (int i = 0; i < N; ++i) {
        sum += max(0LL, (S[i]-x+F[i]-1)/F[i]);
    }
    return sum;
}
long long lower_bound(long long first, long long last, long long func(long long)) {
    long long len = last-first;
    while (len != 0) {
        long long half = len / 2;
        long long mid = first+half;
        if ((*func)(mid) > K) {
            len -= half + 1;
            first = ++mid;
        } else {
            len = half;
        }
    }
    return first;
}

int main() {
    cin.tie(nullptr);
    ios::sync_with_stdio(false);
    cin >> N >> K;
    A = vector<long long>(N);
    for (auto & a : A) cin >> a;
    F = vector<long long>(N);
    for (auto & f : F) cin >> f;
    sort(A.rbegin(), A.rend());
    sort(F.begin(), F.end());
    S = vector<long long>(N);
    for (int i = 0; i < N; ++i) {
        S[i] = A[i]*F[i];
    }
    long long ans = lower_bound(0LL, 1e12, cost);
    printf("%lld\n", ans);
    return 0;
}


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

int main(void)
{
    std::vector<int> w;
    int N, min;

    std::cin >> N;

    for (int i = 0; i < N; i++)
    {
        int tmp;
        std::cin >> tmp;
        w.push_back(tmp);
    }

    int tmp1 = w[0], tmp2 = 0;
    for (int i = 1; i < N - 1; i++)
    {
        tmp2 += w[i];
    }
    min = std::abs(tmp1 - tmp2);
    for (int i = 1; i < N - 1; i++)
    {
        int tmp1 = 0, tmp2 = 0;
        for (int j = 0; j <= i; j++)
        {
            tmp1 += w[j];
        }
        for (int j = i + 1; j < N; j++)
        {
            tmp2 += w[j];
        }
        if (min > std::abs(tmp1 - tmp2))
        {
            min = std::abs(tmp1 - tmp2);
        }
    }

    std::cout << min << std::endl;

    return 0;
}

Measured memory_bytes: 256
n = int(input())
a = list(map(int, input().split()))
b = [bin(i)[2:] for i in a]
c = [0] * n
for i,v in enumerate(b):
  for j in v[::-1]:
    if j == '0':
      c[i] += 1
    else:
      break
print(min(c))

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

using namespace std;
int main (){
    int n;
    int count=0;
    string s;
    cin >> n >> s;
    for (int i = 0; i < n-2; i++){
        if(s[i] =='A' && s[i+1] =='B' && s[i+2] =='C') count++;
    }
    cout << count << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <fstream>
#include <stdio.h>
#include <math.h>
#include <time.h>
#include <string>
#include <tuple>
#include <vector>
#include <map>
#include <unordered_map>
#include <list>
#include <set>
#include <stack>
#include <queue>
#include <cstdlib>
#include <algorithm>
#include <random>
#include <cassert>
using namespace std;
#define LL long long
#define MP(a, b) make_pair(a, b)
#define MMP(a, b, c) make_pair(make_pair(a, b), c)
#define MAX 1000000000
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483647
#define INT_MAX 2147483647
#define LL_MIN (LL)-9223372036854775807
#define LL_MAX (LL)9223372036854775807
#define PI 3.14159265359

int main(){
    iostream::sync_with_stdio(false);
    
    string S,T;
    cin >> S >> T;
    sort(S.begin(), S.end());
    sort(T.begin(), T.end());
    reverse(T.begin(), T.end());
    if(S < T) cout << "Yes" << endl;
    else cout << "No" << endl;
    
    return 0;
}


/*

int main(){
    iostream::sync_with_stdio(false);
    
    
    
    return 0;
}
*/

/*

int main(){
    iostream::sync_with_stdio(false);
    
    
    
    return 0;
}
*/

Measured memory_bytes: 888
#include <algorithm>
#include <climits>
#include <iostream>
#include <vector>
 
int calc(int n, const std::vector<int>& array) {
    int size = 1 << n;
    std::vector<int> table(size, INT_MAX);
    table[0] = 0;
    for (int status = 0; status < size - 1; status++) {
        for (int i = 0; i < n; i++) {
            if (status & (1 << i)) {
                continue;
            }
            int target = status | (1 << i);
 
            int min = array[i * (n + 1)];
            for (int j = 0; j < n; j++) {
                if (status & (1 << j)) {
                    int index = i * (n + 1) + j + 1;
                    min = std::min(min, array[index]);
                }
            }
 
            table[target] = std::min(table[target], table[status] + min);
        }
    }
    return table[size - 1];
}
 
int main() {
    while (true) {
        int n;
        std::cin >> n;
        if (n == 0) {
            break;
        }
        std::vector<int> array(n * (n + 1));
        for (int i = 0; i < n * (n + 1); i++) {
            std::cin >> array[i];
        }
        std::cout << calc(n, array) << std::endl;
    }
    return 0;
}

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

using namespace std;
typedef long long int ll;
typedef pair<ll, ll > pi;  
typedef pair<pair<ll, ll >, ll > pii;  
vector<ll > vec;
vector<vector<ll > > vec2;
ll MOD = 1000000007;
ll INF = 1145141919454519;

ll gcd(ll a, ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a, ll b){return a*b/gcd(a,b);}
//もっと簡単にかけるらしい
int main() {

    ll N; cin >> N;
    
    //初期値
    ll T = 1;
    ll A = 1;
    
    //TとAが与えられると投票数はTx, Axになるはず
    //ここで最小のxを求める
    //条件としては注目する得票数は前の得票数以上であること
    ll x = 1;
    ll t, a; 
    for(ll i = 0; i < N; i++){
        cin >> t >> a;
        if(T == t && A == a) continue;
        //切り上げ処理ceilは誤差を生むことがあるので自分で実装する
        //x = max(ceil(T * x / t), ceil(A * x / a));
        ll x1 = T * x / t;
        ll x2 = A * x / a;
        if(T * x % t != 0){
            x1++;
        }
        if(A * x % a != 0){
            x2++;
        }

        x = max(x1, x2);
        
        T = t;
        A = a;
    }
    ll ans = T * x + A * x;
    cout << ans << endl;
}


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

int n;
long long int a, b;

struct plate {
    int a;
    int b;
} p[200000];

bool cmp(const plate &pa, const plate &pb) {
    return pa.a+pa.b > pb.a+pb.b;
}

int main() {
    cin >> n;
    for(int i=0; i<n; i++) {
        cin >> p[i].a >> p[i].b;
    }
    sort(p, p+n, cmp);
    for(int i=0; i<n; i++) {
        if(i%2==0)  a += p[i].a;
        else        b += p[i].b;
    }
    cout << a-b << endl;
    return 0;
}

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

#define CK(N, A, B) (A <= N && N < B)
#define REP(i, a, b) for (int i = a; i < b; i++)
#define RREP(i, a, b) for (int i = (b - 1); a <= i; i--)
#define F first
#define S second
#define ll long long

const int INF = 1e9;
const long long LLINF = 1e18;

using namespace std;

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

/*==================================================*/
/*variable*/
ll N;
ll A[200010];

int d[25];
/*==================================================*/
/*function*/
bool ok(ll num){
    bool ret = true;
    REP(i,0,20){
        if(d[i] > 0 && ((1<<i)&num)){
            ret = false;
        }
    }
    return ret;
}

/*==================================================*/

int main() {
    cin>>N;
    REP(i,0,N) cin >> A[i];

    ll ans = 0LL;

    int l=0, r=0;
    while(l < N) {
        while(r < N && ok(A[r])){
            REP(i,0,20){
                if((1<<i)&A[r]) d[i]++;
            }
            r++;
        }

        ans += r - l;

        REP(i,0,20){
            if((1<<i)&A[l])d[i]--;
        }
        l++;
    }

    cout<<ans<<endl;

    return 0;
}




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

using namespace std;

typedef long long ll;

const ll MOD = 1e9+7;
const ll INF = 1e18+7;

signed main(){
    ll n;
    cin >> n;
    vector<ll> a(n), b(n), diff(n);
    for(ll i = 0; i < n; ++i){
        cin >> a[i] >> b[i];
    }
    vector<pair<ll,ll>> p;
    for(ll i = 0; i < n; ++i){
        p.emplace_back(a[i] + b[i], i);
        b[i] *= -1;
    }
    sort(p.begin(), p.end(), greater<pair<ll,ll>>());

    ll ans = 0;
    for(ll i = 0; i < n; ++i)
        ans += (i & 1 ? b[p[i].second] : a[p[i].second]);

    cout << ans << endl;

}


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

using namespace std;
#define inf 1000000000
#define unvisited -1
#define visited 1
#define eps 1e-9
#define mp make_pair
#define pb push_back
#define pi acos(-1.0)
#define uint64 unsigned long long
#define FastSlowInput ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define debug if(true)
typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> ii;
typedef vector<ii> vii;

const int maxn = 1e5 + 5;

int main(){
	int x,y,a,b,c,i,j;
	scanf("%d %d %d %d %d",&x,&y,&a,&b,&c);
	int ar1[maxn], ar2[maxn], ar3[maxn];
	for(i=0;i<a;i++){
		scanf("%d",&ar1[i]);
	}
	for(i=0;i<b;i++){
		scanf("%d",&ar2[i]);
	}
	for(i=0;i<c;i++){
		scanf("%d",&ar3[i]);
	}
	sort(ar1, ar1+a);
	sort(ar2, ar2+b);
	priority_queue<int, vi, greater<int> > pq1, pq2;
	int idx = a-1;
	for(i=0;i<x;i++){
		pq1.push(ar1[idx]);
		// printf("push: %d\n",ar1[idx]);
		idx--;
	}
	idx = b-1;
	for(i=0;i<y;i++){
		pq2.push(ar2[idx]);
		// printf("push: %d\n",ar2[idx]);
		idx--;
	}
	for(i=0;i<c;i++){
		int bil = ar3[i];
		int minim1 = pq1.top(), minim2 = pq2.top();
		int minim = min(minim1, minim2);
		if(minim >= bil){continue;}
		if(minim == minim1){
			pq1.pop();
			pq1.push(bil);
			// printf("pq1 push %d\n",bil);
		}else{
			pq2.pop();
			pq2.push(bil);
			// printf("pq2 push %d\n",bil);
		}
	}
	ll sum = 0;
	while(!pq1.empty()){
		sum += pq1.top(); pq1.pop();
	}
	while(!pq2.empty()){
		sum += pq2.top(); pq2.pop();
	}
	printf("%lld\n",sum);
	return 0;
};

Measured memory_bytes: 2552
# coding: utf-8
# Your code here!
N=int(input())
l=list(map(int,input().split()))
pre=[]
ans=[]

while l:
    if pre==l:
        print(-1)
        exit()
    pre.clear()
    pre+=l
    for i in range(len(l))[::-1]:
        if l[i]==i+1:
            ans.append(l.pop(i))
            break

for item in ans[::-1]:
    print(item)

Measured memory_bytes: 3064
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
using namespace std;

const int MOD = 1000000007;

int row(int n) {
  if (n == 1) {
    return 2;
  } else if (n == 2) {
    return 3;
  } else {
    return row(n-1) + row(n-2);
  }
}

int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);
  // freopen("input.txt", "r", stdin);

  vector<int> bar(8, 0); // 1-based
  for (int i = 1; i <= 7; ++i) {
    bar[i] = row(i);
  }

  int h, w, k; cin >> h >> w >> k;

  vector<int> left(w+2, 0), center(w+2, 0), right(w+2, 0); // 1-based
  int temp[4];
  for (int i= 1; i <= w; ++i) {
    temp[0] = bar[max(w-2-i, 0)];
    temp[1] = bar[max(w-1-i, 0)];
    temp[2] = bar[max(i-2, 0)];
    temp[3] = bar[max(i-3, 0)];
    left[i] = max(max(max(temp[1], temp[3]), temp[1] * temp[3]), 1);
    center[i] = max(max(max(temp[2], temp[1]), temp[2] * temp[1]), 1);
    right[i] = max(max(max(temp[2], temp[0]), temp[2] * temp[0]), 1);
  }
  left[1] = 0;
  right[w] = 0;

  vector<vector<long long> > dp(h+1, vector<long long>(w+2, 0)); // 1-based
  dp[0][1] = 1;
  for (int i = 1; i < h+1; ++i) {
    for (int j = 1; j <= w; ++j) {
      dp[i][j] = (right[j-1] * dp[i-1][j-1]) % MOD + (center[j] * dp[i-1][j]) % MOD + (left[j+1] * dp[i-1][j+1]) % MOD;
      dp[i][j] %= MOD;
    }
  }
  cout << dp[h][k] << "\n";
  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
long long arr[100020][3], dp[100020][3];
long long fun(long long x, long long i)
{
    if (x <= 0)
        return 0;
    if (i > 2)
        return 0;
    if (dp[x][i] != -1)
        return dp[x][i];
    return dp[x][i] = arr[x][i] + max(fun(x - 1, (i + 1) % 3), fun(x - 1, (i + 2) % 3));
}
int main()
{
    long long n, x, y;
    cin >> n;
    for (x = 1; x <= n; x++)
        cin >> arr[x][0] >> arr[x][1] >> arr[x][2];
    memset(dp, -1, sizeof(dp));
    long long ans = max(fun(n, 0), max(fun(n, 1), fun(n, 2)));
    cout << ans << endl;
}

Measured memory_bytes: 11136
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;

#define REP(i, n) for (int i = 0; i < (n); i++)
#define REP1(i, n) for (int i = 1; i < (n); i++)
#define CIN(A) int A; cin >> A;
#define CIN2(A, B) int A, B; cin >> A >> B;
#define CIN3(A, B, C) int A, B, C; cin >> A >> B >> C;
#define CINVEC(A, N) vector<int> A; REP(i, N) { int a; cin >> a; A.emplace_back(a); }
#define ANS(ans) cout << (ans) << endl
#define rsort(p, q) sort(p, q, greater<int>());

#define DEBUGV(V) REP(i, V.size()) cout << V.at(i) << " "; cout << endl 

int
main()
{
  string S; cin >> S;

  vector<int> N;
  for (int i = S.size() - 3; 0 <= i; i--) {
    N.emplace_back(abs(atoi(&S.at(i))-753));
    S.at(i + 2) = 0;
  }

  sort(N.begin(), N.end());
  ANS(N.at(0));

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ll long long
#define pii pair<int, int>

using namespace std;

int main() {
    //freopen("output.txt", "w", stdout);
    double r; cin >> r;
    const double pi = 2*acos(0);
    cout << fixed << setprecision(8);
    cout << 2*pi*r << endl;
}

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

using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef pair<ll, ll> Pll;
typedef vector<int> Vi;
typedef tuple<int, int, int> T;
#define FOR(i,s,x) for(int i=s;i<(int)(x);i++)
#define REP(i,x) FOR(i,0,x)
#define ALL(c) c.begin(), c.end()
#define MP make_pair
#define DUMP( x ) cerr << #x << " = " << ( x ) << endl
#define fst first
#define snd second

const int dr[8] = {-1, -1, 1, 1, 0, 0, 1, -1};
const int dc[8] = {-1, 1, -1, 1, -1, 1, 0, 0};
  
int board[8][8];

int count_lock(int r, int c, int k) {
  int cnt = 0;
  
  REP(i, 8) {
    int nr = r+dr[i], nc = c+dc[i];
    while (0 <= nr && nr < 8 && 0 <= nc && nc < 8 && board[nr][nc] == (k^1))
      nr += dr[i], nc += dc[i];
    if (0 <= nr && nr < 8 && 0 <= nc && nc < 8 && board[nr][nc] == k) {
      nr -= dr[i], nc -= dc[i];
      while (0 <= nr && nr < 8 && 0 <= nc && nc < 8 && board[nr][nc] == (k^1)) {
	cnt++;
	nr -= dr[i], nc -= dc[i];
      }
    }
  }
  return cnt;
}
  
void put_lock(int r, int c, int k){
  board[r][c] = k;
  REP(i, 8) {
    int nr = r+dr[i], nc = c+dc[i];
    while (0 <= nr && nr < 8 && 0 <= nc && nc < 8 && board[nr][nc] == (k^1))
      nr += dr[i], nc += dc[i];
    if (0 <= nr && nr < 8 && 0 <= nc && nc < 8 && board[nr][nc] == k) {
      nr -= dr[i], nc -= dc[i];
      while (0 <= nr && nr < 8 && 0 <= nc && nc < 8 && board[nr][nc] == (k^1)) {
	board[nr][nc] = k;
	nr -= dr[i], nc -= dc[i];
      }
    }
  }
}

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

  REP(i, 8) {
    string row;
    cin >> row;
    REP(j, 8) {
      switch(row[j]) {
      case '.':
	board[i][j] = -1;
	break;
      default:
	board[i][j] = row[j] == 'o' ? 0 : 1;
	break;
      }
    }
  }

  bool flag = true;
  while (flag) {
    flag = false;
    REP(k, 2) {
      int f = 0;
      P f_p;
      REP(r, 8) REP(c, 8) {
	if (board[r][c] == -1) {
	  int cnt = count_lock(r, c, k);
	  if ((k == 0 && cnt > f) || (k == 1 && cnt > 0 && cnt >= f)) {
	    f = cnt;
	    f_p = make_pair(r, c);
	  }
	}
      }
      if (f > 0) {
	put_lock(f_p.first, f_p.second, k);
	flag = true;
      }
    }
    
  }
  REP(r, 8) {
    REP(c, 8) {
      switch(board[r][c]) {
      case -1:
	cout << '.';
	break;	
      default:
	cout << (board[r][c] == 0 ? 'o' : 'x');
	break;
      }
    }
    cout << endl;
  }
  return 0;
}

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

using namespace std;

#define REP(i, n)   for(int i = 0; i < (n); i++)
#define REPS(i, n)  for(int i = 1; i <= (n); i++)
#define RREP(i, n)  for(int i = (n)-1; i >= 0; i--)
#define RREPS(i, n) for(int i = (n); i > 0; i--)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
#define UNIQUE(v) v.erase(unique(v.begin(), v.end()), v.end())
#define mp make_pair
#define mt make_tuple
#define pb push_back

using ll  = long long;
using pi  = pair<int, int>;
using pl  = pair<ll, ll>;
using vi  = vector<int>;
using vl  = vector<ll>;
using vs  = vector<string>;
using vb  = vector<bool>;
using vvi = vector<vi>;
using vvl = vector<vl>;

const int MOD = 1e9 + 7;
const int INF = 1e9 + 7;
const ll  INFL = 1e18;
const double PI = 3.141592653589793;
const double EPS = 1e-9;

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

ll f(ll a, ll b)
{
    ll da = 0, db = 0;
    while(a > 0) da++, a /= 10;
    while(b > 0) db++, b /= 10;
    return max(da, db);
}

signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(20);

    ll N; cin >> N;
    ll ans = INFL;
    for(ll i = 1; i * i <= N; i++) if(N % i == 0) chmin(ans, f(i, N / i));
    cout << ans << endl;
}

Measured memory_bytes: 3616
import random

D=int(input())
c=list(map(int,input().split()))
s=[list(map(int,input().split())) for i in range(D)]

plus=0
minus=0
data=[[1 for i in range(D)] for j in range(26)]
ans=[0]*D
for i in range(D):
    t=random.randint(1,26)
    ans[i]=t
    plus+=s[i][t-1]
    if i!=0:
        for j in range(26):
            data[j][i]=data[j][i-1]+1
    data[t-1][i]=0
    minus+=sum(c[j]*data[j][i] for j in range(26))

eval=plus-minus
count=1200000
check=[]
while count:
    d=random.randint(2,D)
    q=random.randint(1,26)
    if ans[d-1]==q:
        continue
    if c[ans[d-1]-1]*data[ans[d-1]-1][d-2]>c[q-1]*data[q-1][d-2] or s[d-1][q-1]>s[d-1][ans[d-1]-1]:
        testplus=plus+s[d-1][q-1]-s[d-1][ans[d-1]-1]
        testminus=minus
        pre=ans[d-1]
        #print("pre",pre)

        day=0
        for j in range(d-1,D):
            if data[q-1][j]!=0:
                if j==d-1:
                    testminus+=day*c[q-1]-data[q-1][d-1]*c[q-1]
                else:
                    testminus+=(day+1-data[q-1][j])*c[q-1]
                    day+=1
            else:
                break

        day=0
        for j in range(d-1,D):
            if j==d-1:
                if j==0:
                    day=1
                    testminus+=c[pre-1]*day
                else:
                    day=1+data[pre-1][j-1]
                    testminus+=c[pre-1]*day
            elif data[pre-1][j]!=0:
                testminus+=(day+1-data[pre-1][j])*c[pre-1]
                day+=1
            else:
                break

        if testplus-testminus>eval:
            eval=testplus-testminus
            plus=testplus
            minus=testminus
            ans[d-1]=q
            for j in range(d-1,D):
                if data[q-1][j]!=0:
                    if j==d-1:
                        data[q-1][d-1]=0
                    else:
                        data[q-1][j]=data[q-1][j-1]+1
                else:
                    break

            for j in range(d-1,D):
                if j==d-1:
                    if j==0:
                        data[pre-1][j]=1
                    else:
                        data[pre-1][j]=1+data[pre-1][j-1]
                elif data[pre-1][j]!=0:
                    data[pre-1][j]=data[pre-1][j-1]+1
                else:
                    break

    else:
        continue

    count-=1
check.sort(reverse=True)
if check:
    if check[0][0]>eval:
        #print(check[0][0])
        for i in range(1,D+1):
            print(check[0][i])
    else:
        #print(eval)
        for i in range(D):
            print(ans[i])
else:
    #print(eval)
    for i in range(D):
        print(ans[i])


Measured memory_bytes: 95884