akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pb push_back
#define f first
#define s second
#define go ios::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mem(arr,v) memset(arr,v,sizeof(arr))
/*bool sortbysec(const pair<int,int> &a,
              const pair<int,int> &b)
{
    return (a.second < b.second);
} */
int main()
{
     ll t,arr[100005],v,cnt=0;
     map<ll,ll>mp;
     cin>>t;
     for(int i=1;i<=t;i++)
     {
         cin>>v;
         arr[i]=v;
     }
     v=1;
     mp[1]++;
     while(true)
     {
         v=arr[v];
         mp[v]++;
         cnt++;
         if(v==2)
            {
                cout<<cnt;
                return 0;
            }
         else if(mp[v]>1)
         {
             cout<<"-1";
             return 0;
         }
     }

}


Measured memory_bytes: 7296
#include <bits/stdc++.h>
#define rep(i, a, b) for (int i = a; i <= b; i++)
#define per(i, a, b) for (int i = a; i >= b; i--)
using namespace std;

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

template <typename _T>
inline void read(_T &f) {
	f = 0; _T fu = 1; char c = getchar();
	while (c < '0' || c > '9') { if (c == '-') { fu = -1; } c = getchar(); }
	while (c >= '0' && c <= '9') { f = (f << 3) + (f << 1) + (c & 15); c = getchar(); }
	f *= fu;
}

template <typename T>
void print(T x) {
	if (x < 0) putchar('-'), x = -x;
	if (x < 10) putchar(x + 48);
	else print(x / 10), putchar(x % 10 + 48);
}

template <typename T>
void print(T x, char t) {
	print(x); putchar(t);
}

const int N = 105;

vector <int> a[N][N];
int match[N], vis[N], adj[N][N], b[N][N], c[N][N];
int n, m;

int dfs1(int u) {
	for (int i = 1; i <= n; i++) {
		if (adj[u][i] && !vis[i]) {
			vis[i] = 1;
			if (!match[i] || dfs1(match[i])) {
				match[i] = u;
				return 1;
			}
		}
	}
	return 0;
}

int main() {
	read(n); read(m);
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			int x; read(x);
			a[i][(x - 1) / m + 1].push_back(x);
		}
	}
	for (int j = 1; j <= m; j++) {
		memset(match, 0, sizeof(match));
		for (int i = 1; i <= n; i++) {
			for (int j = 1; j <= n; j++) {
				if (a[i][j].size()) adj[i][j] = 1;
				else adj[i][j] = 0;
			}
		}
		for (int i = 1; i <= n; i++) {
			memset(vis, 0, sizeof(vis));
			dfs1(i);
		}
		for (int i = 1; i <= n; i++) {
			int id = match[i];
			b[id][j] = a[id][i].back();
			a[id][i].pop_back();
		}
	}
	for (int j = 1; j <= m; j++) {
		for (int i = 1; i <= n; i++) c[i][j] = b[i][j];
		for (int i = 1; i <= n; i++) {
			for (int k = n; k > i; k--) {
				if (c[k][j] < c[k - 1][j]) {
					swap(c[k][j], c[k - 1][j]);
				}
			}
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			print(b[i][j], j == m ? '\n' : ' ');
		}
	}
	for (int i = 1; i <= n; i++) {
		for (int j = 1; j <= m; j++) {
			print(c[i][j], j == m ? '\n' : ' ');
		}
	}
	return 0;
}

Measured memory_bytes: 4304
#line 1 "main.cpp"

/**
 * @title Template
 */

#include <iostream>
#include <algorithm>
#include <utility>
#include <numeric>
#include <vector>
#include <array>
#include <cassert>

#line 2 "/Users/kodamankod/Desktop/Programming/Library/other/chmin_chmax.cpp"

template <class T, class U>
constexpr bool chmin(T &lhs, const U &rhs) {
  if (lhs > rhs) { lhs = rhs; return true; }
  return false;
}

template <class T, class U>
constexpr bool chmax(T &lhs, const U &rhs) {
  if (lhs < rhs) { lhs = rhs; return true; }
  return false;
}

/**
 * @title Chmin/Chmax
 */
#line 2 "/Users/kodamankod/Desktop/Programming/Library/other/range.cpp"

#line 4 "/Users/kodamankod/Desktop/Programming/Library/other/range.cpp"

class range {
public:
  class iterator {
  private:
    int64_t M_position;

  public:
    constexpr iterator(int64_t position) noexcept: M_position(position) { }
    constexpr void operator ++ () noexcept { ++M_position; }
    constexpr bool operator != (iterator other) const noexcept { return M_position != other.M_position; }
    constexpr int64_t operator * () const noexcept { return M_position; }

  };

  class reverse_iterator {
  private:
    int64_t M_position;
  
  public:
    constexpr reverse_iterator(int64_t position) noexcept: M_position(position) { }
    constexpr void operator ++ () noexcept { --M_position; }
    constexpr bool operator != (reverse_iterator other) const noexcept { return M_position != other.M_position; }
    constexpr int64_t operator * () const noexcept { return M_position; }

  };
  
private:
  const iterator M_first, M_last;

public:
  constexpr range(int64_t first, int64_t last) noexcept: M_first(first), M_last(std::max(first, last)) { }
  constexpr iterator begin() const noexcept { return M_first; }
  constexpr iterator end() const noexcept { return M_last; }
  constexpr reverse_iterator rbegin() const noexcept { return reverse_iterator(*M_last - 1); } 
  constexpr reverse_iterator rend() const noexcept { return reverse_iterator(*M_first - 1); } 

};

/**
 * @title Range
 */
#line 2 "/Users/kodamankod/Desktop/Programming/Library/other/rev.cpp"

#include <type_traits>
#include <iterator>
#line 6 "/Users/kodamankod/Desktop/Programming/Library/other/rev.cpp"

template <class T>
class rev_impl {
public:
  using iterator = decltype(std::rbegin(std::declval<T>()));

private:
  const iterator M_begin;
  const iterator M_end;

public:
  constexpr rev_impl(T &&cont) noexcept: M_begin(std::rbegin(cont)), M_end(std::rend(cont)) { }
  constexpr iterator begin() const noexcept { return M_begin; }
  constexpr iterator end() const noexcept { return M_end; }

};

template <class T>
constexpr decltype(auto) rev(T &&cont) {
  return rev_impl<T>(std::forward<T>(cont));
}

/**
 * @title Reverser
 */
#line 17 "main.cpp"

using i32 = int32_t;
using i64 = int64_t;
using u32 = uint32_t;
using u64 = uint64_t;

constexpr i32 inf32 = (i32(1) << 30) - 1;
constexpr i64 inf64 = (i64(1) << 62) - 1;

int main() {
  i32 d, t, s;
  std::cin >> d >> t >> s;
  std::cout << (s * t >= d ? "Yes" : "No") << '\n';
  return 0;
}


Measured memory_bytes: 3592
import           Control.Monad
import           Data.Array.ST
import           Data.Array.Unboxed    (UArray)
import qualified Data.Array.Unboxed    as U
import qualified Data.ByteString.Char8 as BS
import           Data.Char
import           Data.List

getAsInt :: IO [Int]
getAsInt =  unfoldr (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

getAsIntLine :: Int -> IO [[Int]]
getAsIntLine n = replicateM n getAsInt

-- n: number of lines
-- m: number of values per a line
getAsIntArray2D :: Int -> Int -> IO (UArray (Int,Int) Int)
getAsIntArray2D n m = U.listArray ((1,1),(n,m)) . concat <$> getAsIntLine n

main :: IO ()
main = do
  [n,w] <- getAsInt
  wvs <- getAsIntArray2D n 2
  let vMax = sum (map (\x -> wvs U.! (x,2)) [1..n])
      wMax = sum (map (\x -> wvs U.! (x,1)) [1..n])
      solve = solve1
      result = solve wMax n vMax wvs
  print $ head $ filter (\x -> w >= result U.! (n,x)) [vMax,vMax-1..0]
  -- sequence_ [print $ filter (\x -> w >= result U.! (i,x)) [vMax,vMax-1..0] | i <- [1..n]]

solve1 :: Int -> Int -> Int -> UArray (Int,Int) Int -> UArray (Int,Int) Int
solve1 wMax n' vMax wvs = runSTUArray $ do
  dp <- newArray ((0,0),(n',vMax)) wMax
  writeArray dp (0,0) 0
  forM_ [(n_,v_) | n_ <- [1..n'], v_ <- [0..vMax]] $ \(n,v) -> do
    let wtmp = wvs U.! (n,1)
        vtmp = wvs U.! (n,2)
    if v - vtmp < 0
      then readArray dp (n-1,v) >>= writeArray dp (n,v)
      else do
        a <- readArray dp (n-1,v)
        b <- readArray dp (n-1,v-vtmp)
        writeArray dp (n,v) $ min a (b+wtmp)
  return dp


Measured memory_bytes: 85372
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
const int INF = 1e9;
const ll LINF = 1e18;
template<class S,class T> ostream& operator << (ostream& out,const pair<S,T>& o){ out << "(" << o.first << "," << o.second << ")"; return out; }
template<class T> ostream& operator << (ostream& out,const vector<T> V){ for(int i = 0; i < V.size(); i++){ out << V[i]; if(i!=V.size()-1) out << " ";} return out; }
template<class T> ostream& operator << (ostream& out,const vector<vector<T> > Mat){ for(int i = 0; i < Mat.size(); i++) { if(i != 0) out << endl; out << Mat[i];} return out; }
template<class S,class T> ostream& operator << (ostream& out,const map<S,T> mp){ out << "{ "; for(auto it = mp.begin(); it != mp.end(); it++){ out << it->first << ":" << it->second; if(mp.size()-1 != distance(mp.begin(),it)) out << ", "; } out << " }"; return out; }

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */
string solveA(){
    ll R; cin >> R;
    return R < 1200 ? "ABC": R < 2800?"ARC":"AGC";
}
string solveB(){
    string S; cin >> S;
    vector<int> flag(S.length());
    if(*S.begin() != 'A') return "WA";
    bool a = false;
    for(int i = 2; i < S.length()-1;i++){
        if(S[i] == 'C'){
            if(a) return "WA";
            a = true;
            flag[i] = true;
        }
    }
    flag[0] = true;
    if(!a) return "WA";
    
    for(int i = 0; i < S.length();i++){
        if(flag[i])continue;
        if(islower(S[i])) continue;
        return "WA";
    }
    return "AC";
    
}
int main(void) {
    cin.tie(0); ios_base::sync_with_stdio(false);
    //cout << solveA() << endl;
    cout << solveB() << endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <map>
#include <set>
#include <queue>
#include <vector>
#include <string>
#include <algorithm>
#include <utility>
#include <functional>

using namespace std;

#define int long long
#define rep(i,n) for(int i=0;i<(int)n;++i)
#define rep1(i,n) for(int i=1;i<=(int)n;++i)
#define all(a) begin(a),end(a)

using vi=vector<int>;

int H,W,K;
string S[11];

signed main()
{
	cin >> H >> W >> K;

	rep(i, H) cin >> S[i];

	int ans = H*W+5;

	rep(mask, 1ll << (H-1)) {
		int k = 0;

		vector<int> g(H);

		int t = 0;
		rep(i, H) {
			g[i] = t;
			if (mask >> i & 1) {
				k++;
				t++;
			}
		}
		
		vector<int> counter(t+1);

		bool ok = true;

		rep(i, W) {
			vector<int> counter2(t+1);
			bool flag = false;

			rep(j, H) {
				if (S[j][i] == '1') {
					counter2[g[j]]++;
				}
			}

			rep(j, t+1) {
				if (counter2[j] > K) {
					ok = false;
				}

				if (counter[j] + counter2[j] > K) {
					flag = true;
				}
			}

			if (flag) {
				k++;
				counter = counter2;
			} else {
				rep(j, t+1) counter[j] += counter2[j];
			}
		}

		if (ok) ans = min(ans, k);
	}

	cout << ans << endl;
}


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

int main(){

  int n, k, x, sum=0;

  cin>>n>>k;
  for(int i=0;i<n;i++){
    cin>>x;
    sum+=2*min(x, abs(x-k));
  }

  cout<<sum<<endl;

  return 0;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int,input().split()))
cnt = 0
for i in range(N):
    flg = 1
    height = H[i]
    for j in range(i):
        if H[j] > height:
            flg = 0
            break
    if flg == 1:
        cnt += 1
print(str(cnt))

Measured memory_bytes: 3060
n = int(input())
bl = list(map(int, input().split()))
al = []

al.append(bl[0])
al.append(bl[len(bl)-1])
for i in range(len(bl)-1):
    if bl[i] <= bl[i+1]:
        al.append(bl[i])
    else:
        al.append(bl[i+1])
print(sum(al))

Measured memory_bytes: 3064
#include<iostream>
#include<algorithm>
using namespace std;
int n, a[500000], maxn, sum;
int main() {
	while (true) {
		cin >> n; maxn = -1000000000;
		if (n == 0) { break; }
		for (int i = 0; i < n; i++) {
			cin >> a[i];
		}
		for (int i = 0; i < n; i++) {
			sum = 0;
			for (int j = i; j < n; j++) {
				sum += a[j];
				maxn = max(sum, maxn);
			}
		}
		cout << maxn << endl;
	}
}

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

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

		int n=sc.nextInt();
		if(n==2) {
			System.out.println(2);
		}else {
			if(n%2==0) {
				n++;
			}
			int f=0;
			do {
					f=0;
					for(int i=3;i<n/3;i+=2) {
						if(n%i==0) {
							f=1;
							n+=2;
							break;

						}
					}

			}while(f==1);
			System.out.println(n);
		}




	}

}


Measured memory_bytes: 21716
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using Graph = vector<vector<int>>;
#define int ll
#define double long double
#define YES cout<<"YES"<<'\n'
#define NO cout<<"NO"<<'\n'
#define Yes cout<<"Yes"<<'\n'
#define No cout<<"No"<<'\n'
#define yes cout<<"yes"<<'\n'
#define no cout<<"no"<<'\n'
void YN(bool flg) {cout<<(flg?"YES":"NO")<<'\n';}
void Yn(bool flg) {cout<<(flg?"Yes":"No")<<'\n';}
void yn(bool flg) {cout<<(flg?"yes":"no")<<'\n';}
#define SORT(a) sort(a.begin(),a.end())
#define REVERSE(a) reverse(a.begin(),a.end())
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define out(n) cout << n << '\n'
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<VI> VVI;
const int MOD = 1000000007;
const long long INF = 10e10;
const double PI = acos(-1.0);
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; }
template<class T>auto MAX(const T& a) { return *max_element(a.begin(),a.end()); }
template<class T>auto MIN(const T& a) { return *min_element(a.begin(),a.end()); }
template<class T, class U>U SUM(const T& a, const U& v) { return accumulate(a.begin(),a.end(), v); }
template<class T, class U>U COUNT(const T& a, const U& v) { return count(a.begin(),a.end(), v); }
template<class T, class U>int LOWER(const T& a, const U& v) { return lower_bound(a.begin(),a.end(), v) - a.begin(); }
template<class T, class U>int UPPER(const T& a, const U& v) { return upper_bound(a.begin(),a.end(), v) - a.begin(); }
int GCD(int a, int b) { return b ? GCD(b, a%b) : a; }
int LCM(int a, int b) { int g = GCD(a, b); return a / g * b; }
int POW(int a, int n) { int r = 1; while (n > 0) { if (n & 1)r *= a; a *= a; n >>= 1; }return r; }
int isPrime(int n){if(n<2){return 0;}for(int i=2; i*i<=n; i++){if(n%i==0){return 0;}}return 1;}
/*素因数分解*/map< int, int >prime_factor(int n){map< int, int > ret;for(int i = 2; i * i <= n; i++) {while(n % i == 0) {ret[i]++;n /= i;}}if(n != 1) ret[n] = 1;return ret;}
/*約数列挙*/vector<int> divisor(int n){vector<int> v; for(int i=1; i*i<=n; i++){if(n%i==0){v.push_back(i);if(i!=n/i){v.push_back(n/i);}}}sort(v.begin(),v.end()); return v;}
//----------------ライブラリとか----------------

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

    int n,k; cin >> n >> k;
    int ans = 1;
    while(n--) ans = min(ans*2,ans+k);
    out(ans);

    return 0;
}

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

using namespace std;

const int Max_N=1e5+10;
const int maxCost = 1e9 + 10;
int n , k;
int a[Max_N];
int dp[Max_N];

int main(){
    cin >> n >> k;
    for(int i = 1 ; i <= n ; i++){
        cin >>a[i];
        dp[i] = maxCost;
    }
    dp[1]=0;
    for(int i = 2; i <= n ; i++)
        for (int j = i-1 ; j >= max(1,i - k); j--)
            dp[i] = min(dp[i] , dp[j] + abs(a[i] - a[j]));
    cout << dp[n] << endl;
    
    return 0;
}

Measured memory_bytes: 1024
print=console.log;
ls=require("fs").readFileSync("/dev/stdin","utf-8").split("\n");ls.length--
Object.prototype.trace = function(label){ print(this); return this }
Number.prototype.trace = function(label){ print(this+""); return this }
String.prototype.int = function(c){ return this.split(c||" ").map(int)}
Array.prototype.max = function(){ return Math.max.apply(null, this) }
Array.prototype.min = function(){ return Math.min.apply(null, this) }
Array.prototype.copy = function(){ return this.map(id) }
Array.prototype.rotate = function(n){
  return this.slice(n, this.length).concat(this.slice(0, n)); }
Array.prototype.permutation = function () {
  if (this.length == 0) return [];
  if (this.length == 1) return [this];
  var ret = [], ar = this;
  for (var i=0; i<ar.length; ++i)
    ret = ret.concat(ar.slice(0, i)
             .concat(ar.slice(i+1, ar.length))
             .permutation()
             .map(function(p){ return p.concat(ar[i]) }));
  return ret;
}
Array.prototype.flatten = function() {
  for (var i=0, ret=[]; i<this.length; ++i) ret = ret.concat(this[i]);
  return ret;
}
function iota(n, b, s) {
  b=b||0; s=s||1; for (var ret=[]; n--; b+=s) ret.push(b); return ret;
}
function int(s){return +s}
function add(a,b){return a+b}
function sub(a,b){return a-b}
function bus(a,b){return b-a}
function id(x){return x}

function solve (T, P, ls) {
  var tms = [];
  for (var i=0; i<T; ++i) {
    tms[i] = [];
    for (var j=0; j<P; ++j) tms[i][j] = 0; // wrong count
    tms[i].solved_count = 0;
    tms[i].penalty = 0;
  }
  for (var i=0; i<ls.length; ++i) {
    var b = ls[i].split(" ");
    var tid = b[0] - 1, pid = b[1] - 1, time = +b[2];

    if (b[3] == "WRONG") {
      tms[tid][pid]++;
    } else {
      tms[tid].solved_count++;
      tms[tid].penalty += tms[tid][pid] * 1200 + time;
    }
  }
  tms.map(function(t,i){
            return {id:i+1, solved_count:t.solved_count,
                    penalty:t.penalty}})
     .sort(function(a,b){
        if (b.solved_count != a.solved_count)
          return b.solved_count - a.solved_count;
        else if (b.penalty != a.penalty) return a.penalty - b.penalty;
        else return a.id - b.id;
     })
     .forEach(function(t) {
       print(t.id, t.solved_count, t.penalty);
     });
}

(function main() {
  for (var k = 0;;) {
    var a = ls[k].int(),
        T = a[0],
        P = a[1],
        n = a[2];
    if (T == 0 && P == 0 && n == 0) break;
    solve(T, P, ls.slice(k+1, k+n+1));
    k += n+1;
  }
})();

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

const int INF = 1 << 30;

int a[100100];
int dp[100100];

int main() {
    int n, k, i, j;
    cin >> n >> k;
    for (i = 0; i < n; i++) cin >> a[i];
    dp[0] = 0;
    for (i = 1; i < n; i++) dp[i] = INF;
    for (i = 0; i < n-1; i++) {
        for (j = 1; j <= k; j++) {
            dp[i+j] = min(dp[i+j], dp[i] + abs(a[i] - a[i+j]));
        }
    }
    cout << dp[n-1] << endl;
    return 0;
}

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

int r, c;
int a[101][101];

int main(){
  cin >> r >> c;
  for(int i = 0; i < r; i++){
    for(int j = 0; j < c; j++){
      cin >> a[i][j];
      a[i][c] += a[i][j];
      a[r][j] += a[i][j];
      a[r][c] += a[i][j];
    }
  }

  for(int i = 0; i <= r; i++){
    for(int j = 0; j <= c; j++){
      cout << a[i][j];
      if(j != c) cout << " ";
    }
    cout << endl;
  }
}

Measured memory_bytes: 3116
// doot diddly donger cuckerino Hahahahahah

#include<bits/stdc++.h>

using namespace std;

typedef long long int LL;
typedef unsigned int UINT;
typedef unsigned long long ULL;
typedef pair<int, int> PII;
typedef pair<string, int> PSI;
typedef pair<LL, LL> PLL;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<bool> VB;
typedef vector<PII> VPII;
typedef vector<PLL> VPLL;
typedef vector<LL> VLL;
typedef tuple<int,int,int> TPL;
typedef priority_queue<int> pqueue;
typedef priority_queue<int,VI,greater<int>> pdqueue;

const int dx[] = {-1, 0, 1, 0, -1, -1, 1, 1};
const int dy[] = {0, 1, 0, -1, -1, 1, -1, 1};
const int dxhorse[] = {-2, -2, -1, -1, 1, 1, 2, 2};
const int dyhorse[] = {1, -1, 2, -2, 2, -2, 1, -1};

#define MP make_pair
#define MT make_tuple
#define PB push_back
#define EB emplace_back
#define endl "\n"
#define UNIQUE(X) (X).erase(unique(all(X)),(X).end())
#define F first
#define S second
#define SZ(x)           (x).size()
#define MAX(a, b)      ((a)>(b)?(a):(b))
#define MIN(a, b)      ((a)<(b)?(a):(b))
#define ALL(a)         std::begin(a), std::end(a)
#define Fill(n, x)      memset(n,x,sizeof n);
#define IN_REP         int _t; cin >> _t ; while(_t--)
#define IOS            ios::sync_with_stdio(false);cin.tie(NULL)
#define FOR(i, a, b)    for(int i=(a);i<(b);i++)
#define REP(i, n)       FOR(i,0,n)
#define FORR(i, n)      for(int i=(n);i>=0;i--)
#define EPS (double) 1e-9
#define MOD (1000*1000*1000 + 7)
#define INF 1011111111
#define LLINF 1000111000111000111LL
#define MAXN 5000007

template<typename T>
inline T Pow(T base, T exp) {
    LL result = 1;
    while (exp) {
        if (exp & 1)result *= base;
        exp >>= 1;
        base *= base;
    }
    return result;
}

template<typename T>
inline T Mulmod(T a, T b, T c) {
    LL x = 0, y = a % c;
    while (b > 0) {
        if (b & 1) x = (x + y) % c;
        y = (y << 1) % c;
        b >>= 1;
    }
    return x;
}

template<typename T>
inline T Pow(T base, T exp, T mod) {
    LL x = 1, y = base;
    while (exp > 0) {
        if (exp & 1) x = Mulmod(x, y, mod);
        y = Mulmod(y, y, mod);
        exp >>= 1;
    }
    return x;
}
LL n,m;
string s,t;
int main() {
    IOS;
    cin >> n >> m;
    cin >> s >> t;
    int g = __gcd(n,m);
    n/=g;
    m/=g;
    for(int i = 0;i < g ;i ++){
        if(s[i*n] != t[i*m]){
            cout << -1 << endl;
            return 0;
        }
    }
    cout << n*m*g << endl;
    return 0;
}


Measured memory_bytes: 640
N, M = map(int, input().split())
A = list(map(lambda x: -1*x, list(map(int, input().split()))))

import heapq
heapq.heapify(A)
while M:
    a = heapq.heappop(A)
    heapq.heappush(A, -1 * (-1 * a // 2))
    M -= 1

print(sum(map(lambda x: -1*x, A)))

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

import sys

sys.setrecursionlimit(10 ** 9)
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
INF=float('inf')

# ベクトルの内積
def dot(a, b):
    x1,y1=a
    x2,y2=b
    return x1*x2+y1*y2

# ベクトルの外積
def cross(a, b):
    x1,y1=a
    x2,y2=b
    return x1*y2-y1*x2

Q=INT()
for _ in range(Q):
    x1,y1,x2,y2,x3,y3,x4,y4=MAP()
    # 2直線のベクトルを出しておく
    # (今回は方向だけ分かればよくて向きはどっちでもいいので、x1-x2かx2-x1かはどっちでもいい。
    # ただしxとyでどっちにするかは揃える。)
    v1=(x1-x2, y1-y2)
    v2=(x3-x4, y3-y4)
    # 直交判定(内積が0)
    if dot(v1, v2)==0:
        print(1)
    # 平行判定(外積が0)
    elif cross(v1, v2)==0:
        print(2)
    else:
        print(0)



Measured memory_bytes: 5728
#pragma GCC optimize("O3")
#include <bits/stdc++.h>
#define ll long long
#define rep2(i,a,b) for(ll i=a;i<=b;++i)
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep3(i,a,b) for(ll i=a;i>=b;i--)
#define pii pair<int,int>
#define pll pair<ll,ll>
#define pq priority_queue
#define pb push_back
#define eb emplace_back
#define vec vector<int>
#define vecll vector<ll>
#define vecpii vector<pii>
#define vec2(a,b) vector<vec>(a,vec(b))
#define vec2ll(a,b) vector<vecll>(a,vecll(b))
#define vec3(a,b,c) vector<vector<vec>>(a,vec2(b,c))
#define vec3ll(a,b,c) vector<vector<vecll>>(a,vec2ll(b,c))
#define fi first
#define se second
#define endl "\n"
#define all(c) begin(c),end(c)
#define ios ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
#define lb(c,x) distance(c.begin(),lower_bound(all(c),x))
#define ub(c,x) distance(c.begin(),upper_bound(all(c),x))
#define MM " "
// #define INF 100000000
using namespace std;
int in() {int x;cin>>x;return x;}
ll lin() {ll x;cin>>x;return x;}
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;}
template<class T> inline void print(pair<T,T> p){cout<<"("<<p.first<<","<<p.second<<") ";}
template<class T> inline void print(vector<pair<T,T>> v){for(auto e:v)print(e); cout<<endl;}
template<class T> inline void print(T v){for(auto e:v)cout<<e<<" ";cout<<endl;}



string p[2]={"Yes\n","No\n"};
string pp[2]={"yes\n","no\n"};

int n,m,k;
vec a,b;
void get(){
    rep(i,n)a.pb(in());
}

int main(){
    ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);cout<<fixed<<setprecision(15);
    
    double l=in();
    cout<<l*l*l/27.0<<endl;
    
}



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

#define pb push_back
#define mp make_pair
typedef long long ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef complex<double> point;
#define xx real()
#define yy imag()

#define REP(i, a, b) for(int i = (a); i < (int)(b); i++)
#define REPN(i, a, b) for(int i = (a); i <= (int)(b); i++)
#define FA(it, x) for(__typeof((x).begin()) it = (x).begin(); it != (x).end(); it++)
#define SZ(x) (int)(x).size()
#define BE(x) (x).begin(), (x).end()
#define SORT(x) sort(BE(x))
#define _1 first
#define _2 second

#define x1 gray_cat_x1
#define y1 gray_cat_y1

template<class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }

#define file "I1"

const double EPS = 1e-9;
const double PI = acos(-1.);
const int INF = 1e9;
const ll MOD = 1e9 + 7;

const int MAXN = 4e5 + 5;

pii pp[MAXN];

pii vv[MAXN];

set<int> mins, maxs;

void solve(){
	int n;
	scanf("%d", &n);
	REP(i, 0, n) {
		scanf("%d%d", &pp[i]._1, &pp[i]._2);
		if (pp[i]._1 > pp[i]._2) {
			swap(pp[i]._1, pp[i]._2);
		}
	}
	int mn1 = pp[0]._1, mx1 = pp[0]._1;
	int mn2 = pp[0]._2, mx2 = pp[0]._2;
	REP(i, 1, n) {
		mn1 = min(mn1, pp[i]._1);
		mx1 = max(mx1, pp[i]._1);
		mn2 = min(mn2, pp[i]._2);
		mx2 = max(mx2, pp[i]._2);
	}
	ll ans = 1ll * (mx1 - mn1) * (mx2 - mn2);
	
	REP(i, 0, n) {
		vv[2 * i] = mp(pp[i]._1, i);
		vv[2 * i + 1] = mp(pp[i]._2, i);
	}
	sort(vv, vv + 2 * n);
	if (vv[0]._2 == vv[2 * n - 1]._2) {
		printf("%lld\n", ans);
		return;
	}
	
	//printf("%lld\n", ans);
	
	int l, r;
	for(r = 2 * n - 1; r >= 0; r--) {
		if (maxs.find(vv[r]._2) != maxs.end()) {
			break;
		}
		maxs.insert(vv[r]._2);
	}
	for(l = 0; l < 2 * n; l++) {
		if (maxs.find(vv[l]._2) != maxs.end() || mins.find(vv[l]._2) != mins.end()) {
			break;
		}
		mins.insert(vv[l]._2);
	}
	mn1 = vv[0]._1, mx1 = vv[2 * n - 1]._1;
	for(; ; ) {
		mn2 = vv[l]._1;
		mx2 = vv[r]._1;
		ans = min(ans, 1ll * (mx1 - mn1) * (mx2 - mn2));
		
		//printf("%d %d\n", mn2, mx2);
		
		if (mins.find(vv[l]._2) != mins.end() || vv[l]._2 == vv[2 * n - 1]._2) {
			break;
		}
		if (maxs.find(vv[l]._2) != maxs.end()) {
			for(; r < 2 * n && vv[r]._2 != vv[l]._2; r++) {
				maxs.erase(vv[r]._2);
			}
			maxs.erase(vv[l]._2);
		}
		mins.insert(vv[l]._2);
		l++;
	}
	
	printf("%lld\n", ans);
}   

int main(){

    //freopen(file".in", "r", stdin); freopen(file".out", "w", stdout);
    int t = 1;
    //cin >> t;
    while(t--){
        solve();    
    }
}


Measured memory_bytes: 15744
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
using namespace std;
signed main(){
    int n; cin >> n;
    int cnt = 0;
    rep(i,n){
        int a; cin >> a;
        bool isprime = true;
        if(a == 1){
            isprime = false;
            continue;
        }
        rep2(i, 2, sqrt(a)+1){
            if (a % i == 0){
                isprime = false;
                break;
            }
        }
        if (isprime) cnt++;
    }
    cout << cnt << endl;
    return 0;
}


Measured memory_bytes: 3120
#include <bits/stdc++.h>
using namespace std;
typedef long long  ll;
int main(){
    string s;
    vector<string> v = {"ABC","ARC"};
    cin>>s;
    for(int i=0; i<2; i++){
        if(v[i] ==s) cout<<v.at((i+1)%2)<<endl;
    }
}

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

using lint = long long;

#define reps(i, a, n) for (lint i = (a); i < (lint)(n); ++i)
#define rep(i, n) reps(i, 0, n)
#define each(i, n) for (auto &&i : n)

inline bool inside(int y, int x, int h, int w) { return 0 <= y && y < h && 0 <= x && x < w; }
const int dy[] = {0, 1, 0, -1}, dx[] = {1, 0, -1, 0};
struct PRE { PRE() { ios::sync_with_stdio(0); cin.tie(0); cout << fixed << setprecision(10);} } _PRE;
// }}}

bool N, W, S, E;

signed main() {
  string s;
  cin >> s;

  each(c, s) {
    if (c == 'N') N = true;
    if (c == 'W') W = true;
    if (c == 'S') S = true;
    if (c == 'E') E = true;
  }

  if (N && !S || S && !N || W && !E || E && !W) {
    cout << "No" << endl;
  } else {
    cout << "Yes" << endl;
  }
}


Measured memory_bytes: 384
a, b = [int(w) for w in input().split()]
s = input()

cond = True

if not s[:a].isnumeric():
    cond = False

if not s[a] == "-":
    cond = False

if not s[a+1:].isnumeric():
    cond = False

print("Yes" if cond else "No")


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

int main(){
    int A,B,K;
    cin>>K>>A>>B;
    for(int i=A;i<=B;i++){
        if(i%K==0){
            cout <<"OK"<<endl;
            return 0;
        }
    }
    cout<<"NG"<<endl;
    return 0;
}


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

using namespace std;

typedef long long LL;
typedef pair<int , int> P2;
typedef pair<pair<int , int> , int> P3;
typedef pair<pair<int , int> , pair<int , int> > P4;
#define PB(a) push_back(a)
#define MP(a , b) make_pair((a) , (b))
#define M3P(a , b , c) make_pair(make_pair((a) , (b)) , (c))
#define M4P(a , b , c , d) make_pair(make_pair((a) , (b)) , make_pair((c) , (d)))
#define repp(i,a,b) for(int i = (int)(a) ; i < (int)(b) ; ++i)
#define repm(i,a,b) for(int i = (int)(a) ; i > (int)(b) ; --i)

int H,W,N;
int ans[111][111];
int p;

int main(){
	scanf("%d%d%d" , &H , &W , &N);
	repp(i,1,N+1){
		int a;
		scanf("%d" , &a);
		while(a > 0){
			ans[p/W][(p/W)%2==1?W-1-(p%W):(p%W)] = i;
			++p;
			--a;
		}
	}
	repp(i,0,H){
		repp(j,0,W){
			printf("%d%c" , ans[i][j] , j+1==W ? '\n' : ' ');
		}
	}
	return 0;
}


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

#define int long long

const int MOD = 1e9 + 7;
string K;
int D;

int dp[10010][2][110] = {0};

signed main() {
  cin >> K >> D;
  int n = K.size();

  dp[0][0][0] = 1;
  for (int digit = 0; digit < n; digit++) {
    for (int smaller : {0, 1}) {
      int lim = smaller == 1 ? 9 : K[digit] - '0';
      for (int num = 0; num <= lim; num++) {
        for (int modD = 0; modD < D; modD++) {
          dp[digit+1][smaller || num < lim][(modD + num) % D] += dp[digit][smaller][modD] % MOD;
        }
      }
    }
  }

  // この部分
  int ans = 0;
  for (int smaller : {0, 1}) {
    ans = ((ans % MOD) + (dp[n][smaller][0] % MOD)) % MOD;
  }
  ans = ((ans % MOD) + ((-1 + MOD) % MOD)) % MOD;
  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 17408
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for (int i = 0; i < (int)(n); i++)
typedef long long ll;
typedef pair<int, int> P;
int main() {
  int H, W;
  cin >> H >> W;
  vector<string> S(H);
  REP(i, H) cin >> S[i];
  ll ans = 0;
  REP(i, H) REP(j, W) REP(k, H) REP(l, W) {
    P start = P(i, j), goal = P(k, l);
    if (S[start.first][start.second] == '#' ||
        S[goal.first][goal.second] == '#')
      continue;
    vector<vector<int>> dis(H, (vector<int>(W, -1)));
    dis[start.first][start.second] = 0;
    queue<P> que{};
    que.push(start);
    while (!que.empty()) {
      P p = que.front();
      que.pop();
      int y = p.first, x = p.second;
      if (p.first == goal.first && p.second == goal.second) break;
      if (x > 0 && W > 1) {
        int nx = x - 1, ny = y;
        if (S[ny][nx] == '.' && dis[ny][nx] == -1) {
          dis[ny][nx] = dis[y][x] + 1;
          que.push(P(ny, nx));
        }
      }
      if (x < W - 1) {
        int nx = x + 1, ny = y;
        if (S[ny][nx] == '.' && dis[ny][nx] == -1) {
          dis[ny][nx] = dis[y][x] + 1;
          que.push(P(ny, nx));
        }
      }
      if (y > 0 && H > 1) {
        int nx = x, ny = y - 1;
        if (S[ny][nx] == '.' && dis[ny][nx] == -1) {
          dis[ny][nx] = dis[y][x] + 1;
          que.push(P(ny, nx));
        }
      }
      if (y < H - 1) {
        int nx = x, ny = y + 1;
        if (S[ny][nx] == '.' && dis[ny][nx] == -1) {
          dis[ny][nx] = dis[y][x] + 1;
          que.push(P(ny, nx));
        }
      }
    }
    if (dis[goal.first][goal.second] == -1) continue;
    ans = max((ll)dis[goal.first][goal.second], ans);
  }
  cout << ans << endl;
}

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

int ri() {
	int n;
	scanf("%d", &n);
	return n;
}

struct SegTree {
	std::unordered_map<int64_t, int> data;
	int64_t n;
	SegTree (int64_t n_) {
		for (n = 1; n < n_; n <<= 1);
	}
	void add(int64_t i, int val) {
		for (i += n; i; i >>= 1) data[i] += val;
	}
	int get(int64_t l, int64_t r) {
		int sum = 0;
		for (l += n, r += n; l < r; l >>= 1, r >>= 1) {
			if (r & 1) sum += data[--r];
			if (l & 1) sum += data[l++];
		}
		return sum;
	}
};

int main() {
	int n = ri(), k = ri();
	int a[n];
	for (auto &i : a) i = ri() - k;
	int64_t sum[n + 1];
	sum[0] = 0;
	for (int i = 0; i < n; i++) sum[i + 1] = sum[i] + a[i];
	for (auto &i : sum) i += 100000000000000000;
	SegTree tree(1000000000000000000);
	int64_t res = 0;
	for (int i = 1; i <= n; i++) {
		tree.add(sum[i - 1], 1);
		res += tree.get(0, sum[i] + 1);
	}
	std::cout << res << std::endl;
	return 0;
}





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

#define repd(i,a,b) for (int i=(a);i<(b);i++)
#define rep(i,n) repd(i,0,n)
typedef long long ll;

using namespace std;


int inputValue(){
    int a;
    cin >> a;
    return a;
};

void inputArray(int * p, int a){
    rep(i, a){
        cin >> p[i];
    }
};

void inputVector(vector<int> * p, int a){
    rep(i, a){
        int input;
        cin >> input;
        p -> push_back(input);
    }
}

template <typename T>
void output(T a, int precision) {
    if(precision > 0){
        cout << setprecision(precision)  << a << "\n";
    }
    else{
        cout << a << "\n";
    }
}

int main(int argc, const char * argv[]) {
    
    // source code
  string s,t;
  cin >> s >> t;
  int count = 0;
  rep(i,3)
  {
    if(s[i] == t[i])
    {
      count++;
    }
  }
  
  cout << count << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int w(vector<int> v, int begin, int end){
    int i, c = 0;
    if(end > v.size()) end = v.size();
    for(i = begin; i < end; i++){
        c += v[i];
    }
    return c;
}

int main(){
    int n, k, i, b;
    vector<int> v;
    string s;
    cin >> n >> k;
    cin >> s;
    int c = 1;
    char l = s[0];
    for(i = 1; i < n; i++){
        if(s[i] != l){
            v.push_back(c);
            c = 1;
        }
        else{
            c++;
        }
        l = s[i];
    }
    v.push_back(c);

    int m = w(v, 0, k * 2);
    if(s[0] == '0'){
        for(i = 1; i + k * 2 <= v.size(); i+=2){
            if(m < w(v, i, i + k * 2 + 1)){
                m = w(v, i, i + k * 2 + 1);
            }
        }
    }
    else{
        for(i = 0; i + k * 2 <= v.size(); i+=2){
            if(m < w(v, i, i + k * 2 + 1)){
                m = w(v, i, i + k * 2 + 1);
            }
        }
    }
    cout << m << endl;
}

Measured memory_bytes: 1276
import sys
S = list(input())
lis = [0] * (len(S)+1)
 
if len(S) == 1:
    print(1)
    sys.exit()
 
 
#最初は < を処理する
for i in range(len(S)):
    if S[i] == "<":
        lis[i+1] = lis[i] + 1
 
 
 
 
for j in range(len(S)-1,-1,-1):
    if S[j] == ">":
        lis[j] = max(lis[j],lis[j+1] + 1)
 
 
 
print(sum(lis))

Measured memory_bytes: 27184
#include<bits/stdc++.h>
#define int long long int
#define ld long double
#define getFaster ios_base::sync_with_stdio(false),cin.tie(NULL),cout.tie(NULL)
#define rep(i,init,n) for(int i=init;i<n;i++)
#define rev(i,n,init) for(int i=n;i>=init;i--)
#define MAXN 200005
#define MOD2 998244353
#define MOD1 1e9+7
#define f first
#define s second
#define endl '\n'
#define pii pair<int,int>
#define piii pair<pii,int>
#define precise(i) cout<<fixed<<setprecision(i)
using namespace std;
const long double PI = atan(1.0)*4;
const int64_t INF=INT64_MAX;
const int32_t LOG=21;
const int MOD=MOD2;


int32_t main()
{ 
      getFaster;
      int tests=1;
      //cin>>tests;
      rep(ii,0,tests)
      {
            string s;
            cin>>s;
            rep(i,0,s.length())
            {
                 if(s[i]=='7')
                 {
                   cout<<"Yes"<<endl;
                   return 0;
                 } 
            }
            cout<<"No"<<endl;  
      }

      return 0;                         
}

/*
 TIPS(FOR ME):
 1.) Check for corner cases (like 0 is exception case)
 2.) Check for global memory sizes,memory refreshments and its complexity 
 3.) Check for sorting criteria (if used 1-based indexing)
 4.) Check for numbers overflow (while multiplying and doing MOD)
 5.) Check for typecasting issues like int to float( while dividing numbers)
*/


Measured memory_bytes: 3652
// cand <genesis?>
#include <bits/stdc++.h>
#define ll long long
#define ld long double
using namespace std;
const ll base = 7;
const ll N = 5e5 + 9;
const ll inf = 1000100009;
typedef pair<ll,ll> LL;

string s,t,p;

int main(){
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("test.INP", "r", stdin);
    cin>>s>>t;
    ll n = t.size();
    p = t.substr(0,n - 1);
    if (s == p) cout<<"Yes\n";
    else cout<<"No\n";
}


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

int main(){
    int N,K;
    cin >> N >> K;
    vector<double> vec(N);
    rep(i,N){
        cin >> vec[i];
        vec[i] = (vec[i] + 1) * 0.5;
    }
    double ans = 0;
    double sub_ans = 0;
    rep(i,K){
        sub_ans += vec[i];
    }
    ans = sub_ans;
    rep(i,N - K){
        sub_ans += vec[K + i];
        sub_ans -= vec[i];
        ans = max(ans,sub_ans);
    }
    cout << fixed << setprecision(15) << ans << endl;
}



Measured memory_bytes: 4712
#include<stdio.h>
typedef struct go{
	char c;
	int n;
}GO;
GO a[100005];
int main(){
	int n,f,x,i,j,ans;
	FILE *fp;
	//fp=fopen("test.txt","r");
	fp=stdin;
	while(1){
		fscanf(fp,"%d",&n);
		if(n==0)break;
		fscanf(fp,"%d",&x);
		a[0].c=x;
		a[0].n=1;
		f=1;
		for(i=2;i<=n;i++){
			fscanf(fp,"%d",&x);
			if(i%2==1){
				if(a[f-1].c==x){
					a[f-1].n++;
				}else{
					a[f].c=x;
					a[f].n=1;
					f++;
				}
			}else{
				if(a[f-1].c==x){
					a[f-1].n++;
				}else{
					if(f>=2){
						a[f-2].n+=a[f-1].n+1;
						f--;
					}else{
						a[f-1].c=(a[f-1].c+1)%2;
						a[f-1].n++;
					}
				}
			}
			//printf("%d:",i);for(j=0;j<f;j++)printf("(%d:%d,%d)",j,a[j].c,a[j].n);
			//printf("\n");
		}
		ans=0;
		for(i=0;i<f;i++){
			if(a[i].c==0)ans+=a[i].n;
		}
		printf("%d\n",ans);
	}
	return 0;
}

Measured memory_bytes: 0
#include <stdio.h>

int a[50];

int fib(int);

int main()
{
  int i, n, ans;

  for(i = 0; i < 50; i++)
    {
      a[i] = -1;
    }

  scanf("%d",&n);

  ans = fib(n);

  printf("%d\n",ans);
  
  return 0;
}

int fib(int n)
{
  if(n == 0 || n == 1)return a[n] = 1;
  else if(a[n] != -1)return a[n];
  else return a[n] = fib(n-1) + fib(n-2);
}



Measured memory_bytes: 2112
#include <iostream>
#include <cmath>
#include <string>

typedef long long lint;

using namespace std;

// dpテンプレ
template<class T> inline bool chmin(T& a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template<class T> inline bool chmax(T& a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}

//入力
int n;
lint h[100000][3] = {};
//dpテーブル
lint dp[100000][3] = {};

int main(){
  int n,i,j,k;
  lint ans;
  cin >> n;
  for(i = 0; i < n; i++){
    for(j = 0; j < 3; j++){
      cin >> h[i][j];
    }
  }
  //初期値
  for(i = 0; i < 3; i++){
    dp[0][i] = h[0][i];
  }
  //ループ
  for(i = 1; i < n; i++){
    for(j = 0; j < 3; j++){
      for(k = 0; k < 3; k++){
        if(j == k) continue;
        chmax(dp[i][j], dp[i - 1][k] + h[i][j]);
      }
    }
  }
  ans = 0;
  for(i = 0; i < 3; i++){
    chmax(ans, dp[n - 1][i]);
  }
  cout << ans;
}


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

//repetition
#define FOR(i,a,b) for(ll i=(a);i<(b);++i)
#define rep(i, n) for(ll i = 0; i < (ll)(n); i++)

//container util
#define all(x) (x).begin(),(x).end()

//typedef
typedef long long ll;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef vector<ll> VLL;
typedef vector<VLL> VVLL;
typedef vector<string> VS;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;

//const value
//const ll MOD = 1e9 + 7;
//const int dx[] = {0,1,0,-1};//{0,0,1,1,1,-1,-1,-1};
//const int dy[] = {1,0,-1,0};//{1,-1,0,1,-1,0,1,-1};

//conversion
inline int toInt(string s) {int v; istringstream sin(s);sin>>v;return v;}
inline ll toLL(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();}
ll n, a, b;
bool enough(ll t, vector<ll> & h){
  ll plus = a-b;
  ll cnt = 0;
  rep(i,n){

    if( (h[i] - t * b)> 0){
      cnt += max(0LL, (h[i] - (t*b) + (plus-1) ) / plus);
    }
  }
  //cout << t << ':' << cnt << endl;
  if(cnt <= t) return true;
  else return false;
}
int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cin >> n >> a >> b;
    VLL h(n);

    rep(i,n) cin >> h[i];
    sort(all(h),greater<ll>());

    ll left = 0;
    ll right = 1e9;
    while(right - left > 1){
      ll mid = (left + right) / 2;
      if(enough(mid, h)) right = mid;
      else left = mid;
      //cout << left << ',' << right << endl;
    }
    cout << right << endl;
    return 0;
}


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

int main()
{
    cin.sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
//    freopen("input.txt","r",stdin);freopen("output.txt","w",stdout); 
    
ll n; 

cin>>n;
ll ans=0; 
if(n&1)
  ans=0; 
else 
{
ll count=0;
n=n/2;
for (ll i = 5;( n / i) >= 1; i *= 5) 
        ans += (n / i); 

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

}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<stdio.h>
#include<stdlib.h>
using namespace std;
int main(){
	int a,b;
	cin>>a>>b;
	int c;
	if(a<0&&b<0){
		c=abs(b-a);
		if(c%2==0)cout<<"Negative"<<endl;
		else cout<<"Positive"<<endl;}
	else if(a>0&&b>0)cout<<"Positive"<<endl;
	else cout<<"Zero"<<endl;
}


Measured memory_bytes: 256
import collections
import math

def combinations_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))


s=list(input())
s=s+[0]
mod=0
ans=[]
count=0
n=len(s)
p=2019

for i in range(n):
    mod+=(pow(10,i,p)*int(s[n-i-1]))%p
    mod%=p
    ans.append(mod)

ans = collections.Counter(ans)
ans=ans.most_common()
for i in range(len(ans)):
    if ans[i][1]>=2:
        count+=combinations_count(ans[i][1],2)

print(count)

Measured memory_bytes: 97924
# Rooted Trees

import sys
sys.setrecursionlimit(2**20)  # 再帰回数上限の向上 かなり多くしないとREになる

class Node:
    def __init__(self, parent, left, right):
        self.parent = parent
        self.left = left
        self.right = right

def get_depth(T: dict, u: int):
    d = 0
    while T[u].parent is not None:
        u = T[u].parent
        d += 1
    return d

D = {}  # 深さを保存しておく用のdict

def get_all_depth(T: dict, u: int, p: int):
    '''  
    一度にすべてのノードの深さを取得する関数(再帰的に処理を行う)。
    一気に全体の深さを求めるならばこちらの方がオーダーが小さい。
    pは現在扱う深さ
    '''
    D[u] = p
    if T[u].right is not None:
        # 右の兄弟ノード(深さは同じ)から入れていく
        get_all_depth(T, T[u].right, p)
    if T[u].left is not None:
        # 兄弟を入れ終わったら次は下のふさへ
        get_all_depth(T, T[u].left, p+1)

def ret_children(T, u):
    children = []
    c = T[u].left
    while c is not None:
        children.append(c)
        c = T[c].right
    return children

def print_for_a_node(T: dict, node: int, D: dict):
    node_type = 'internal node' if T[node].left is not None else 'leaf'
    if T[node].parent is None:
        parent = -1
        node_type = 'root'
    else:
        parent = T[node].parent
    children = ret_children(T, node)

    print(
        f'node {node}: parent = {parent}, depth = {D[node]}, {node_type}, {children}')

N = int(input())
T = {k: Node(None, None, None) for k in range(N)}
for _ in range(N):
    lst = list(map(int, input().split()))
    if lst[1] == 0:  # もし子ノードがなければ次へ
        continue
    T[lst[0]].left = lst[2]
    T[lst[2]].parent = lst[0]
    prev_sibling = lst[2]  # 前のノード番号を覚えておく用
    for sib in lst[3:]:
        T[prev_sibling].right = sib
        T[sib].parent = lst[0]  # 子から親を与えている
        prev_sibling = sib

for node in range(N):
    if T[node].parent is None:
        get_all_depth(T, node, 0)  # rootを入れなければいけないことに注意
        # Dに深さが入った
        break

for node in range(N):
    print_for_a_node(T, node, D)


Measured memory_bytes: 141960
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define FRE freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define all(v) (v).begin(),(v).end()
#define endl "\n"
#define int long long
#define rep(i,a,b) for(int i=a;i<b;i++)
#define per(i,a,b) for(int i=a;i>b;i--)
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>
#define SET(A,VAL) memset(A, VAL, sizeof(A))
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl
const int MAX = 1e6+8;
const int sz = 1e5+5;
void f_io(){
    IOS;
}
int32_t main(){
    f_io();
    int t = 1;
    //cin>>t;
    while(t--){
        string str; cin>>str;
        std::vector<string> v(3);
        int i = 0;
        string temp = "";
        for(auto k : str){
            if(k == ','){
                v[i++] = temp;
                temp = "";
                continue;
            }
            temp += k;
        }
        v[i] = temp;
        for(auto k : v) cout<<k<<" ";

    }
}

Measured memory_bytes: 256
groups = [[1, 3, 5, 7, 8, 10, 12], [4, 6, 9, 11], [2]]
gg = lambda t: [i for i in range(0, 3) if t in groups[i]][0]
x, y = map(int, input().split())
print('Yes' if gg(x) == gg(y) else 'No')

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n); for(int i = 0;i < (n);i++)
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef tuple<int,int,int> state;
long double pi = acos(-1);
const int INF = 1001001001;


// 最小公倍数を求める
int euqlid (int a, int b){
  int temp;
  temp = a % b;
  if(temp == 0)return b;
  return euqlid(b,temp);
}
ll conbination(ll a,ll b){
  ll u = 1;
  ll d = 1;
  while(b != 0){
    u *= a;
    d *= b;
    a--;
    b--;
  }
  return u / d;
}
int strtoint(char s){
  return (int(s-'0'));
}
char changeS(char alpha){
  if(0x41 <= alpha and alpha <= 0x5A)return (alpha + 0x20);
  else if(0x61 <= alpha and alpha <= 0x7A)return (alpha - 0x20);
  return alpha;
}
int fact(int n){
  if(n == 1)return 1;
  return n * fact(n-1);
  }
int ceil(int a,int b){
  // a/bの切り上げを考える
  return (a+b-1)/b;
}


int main(){ 
  int n,m;
  cin >> n >> m;
  int a[n], b[n], c[m], d[m];
  rep(i,n)cin >> a[i] >> b[i];
  rep(i,m)cin >> c[i] >> d[i];

  rep(i,n){
    int len = 1e9;
    int cp = -1;
    rep(j,m){
      int dist = abs(a[i] - c[j]) + abs(b[i] - d[j]);
      if(len > dist){
        len = dist;
        cp = j + 1;
      }
    }
    cout << cp << endl;
  }
}

Measured memory_bytes: 3644