akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10 ** 6)
# input = sys.stdin.readline    ####
def int1(x): return int(x) - 1
def II(): return int(input())

def MI(): return map(int, input().split())
def MI1(): return map(int1, input().split())

def LI(): return list(map(int, input().split()))
def LI1(): return list(map(int1, input().split()))
def LLI(rows_number): return [LI() for _ in range(rows_number)]

def SI(): return input().split()

def printlist(lst, k='\n'): print(k.join(list(map(str, lst))))
INF = float('inf')

from math import ceil, floor, log2
from collections import deque
from itertools import combinations as comb, combinations_with_replacement as comb_w, accumulate, product
from heapq import heapify, heappop, heappush

def is_prime(n):
    for i in range(2, int(pow(n, 0.5))+1):
        if n % i == 0:
            return False

    return True


def solve():
    X = II()

    while 1:
        if is_prime(X):
            print(X)
            return

        X += 1



if __name__ == '__main__':
    solve()


Measured memory_bytes: 3316
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val sx, sy, tx, ty = sc.nextInt()
  val dx = tx - sx
  val dy = ty - sy
  val ans = s"${"R" * dx}${"U" * dy}${"L" * dx}${"D" * (dy+1)}${"R" * (dx+1)}${"U" * (dy+1)}LU${"L" * (dx + 1)}${"D" * (dy+1)}R"
  println(ans)
}


Measured memory_bytes: 55420
/*~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=
*$* WRITER:kakitamasziru/OxOmisosiru *$*
~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=~=*/
#ifdef LOCAL_JUDGE
#define _GLIBCXX_DEBUG //FOR THE DEBUG! COMMENT OUT THIS WHEN SUBMITTING!
#endif
#include <iostream> // cout, endl, cin
#include <string> // string, to_string, stoi
#include <vector> // vector
#include <algorithm> // min, max, swap, sort, reverse, lower_bound, upper_bound
#include <utility> // pair, make_pair
#include <tuple> // tuple, make_tuple
#include <cstdint> // int64_t, int*_t
#include <iomanip>
#include <limits>//setprecision
//#include <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
//#include <unordered_set> //unordered_set
#include <stack> // stack
#include <deque> // deque
#include <math.h>//pow,,,
#include <cmath>//abs,,,
#include <bitset> // bitset
//It is so troublesome that I include bits/stdc++.h !
using namespace std;

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; }
const long long INF = 10010010010010;
const long long MOD = 1000000007;
typedef pair<int,int> P;

//Solve N^M. This, mod_pow use Iterative Square Method.
long long mod_pow(long long N, long long M) {
    if (M == 0) return 1;
    long long res = mod_pow((N * N) % MOD, M / 2);
    //最下位ビット(*N)が1の時は単独でNをかける
    if (M & 1) res = (res * N) % MOD;

    return res %= MOD;
}

long long gcd(long long a, long long b) {
    if (b == 0) return a;
    else return gcd(b, a % b);
}
long long lcm(long long a, long long b) {
    return a / gcd(a, b) * b ;
}

int main() {
    int N;cin >> N;
    string S;cin >> S;
    map<int,long long> M;
    for(int i = 0;i<N;i++){
        int idx = S.at(i)-'0';
        M[idx]++;
    }
    long long ans = 1;
    for(auto V : M){
        ans *= V.second+1;
        ans %= MOD;
    }
    ans -= 1;
    cout << ans << endl;
}


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

const int MAXN = 200000;
const long INFTY = 1e16;

int main() {
	int n;
	cin >> n;
	long a[MAXN];
	long sum = 0;
	for(int i = 0; i < n; i++) {
		cin >> a[i];
		sum += a[i];
	}
	long minVal = INFTY;
	long prefix = 0;
	for(int i = 0; i < n - 1; i++) {
		prefix += a[i];
		long next = abs(prefix - (sum - prefix));
		minVal = min(minVal, next);
	}
	cout << minVal << "\n";
}


Measured memory_bytes: 1792
h, w, k = map(int, input().split())
chocolate = ['0' + input() for _ in range(h)]

white_count = [[0] * (w+1)]
for line in chocolate:
    prev = white_count[-1]
    cumsum = []
    total = 0
    for color, count in zip(line, prev):
        if color == '1':
            total += 1
        cumsum.append(total + count)
    white_count.append(cumsum)

ans = []
for pattern in range(2**(h-1)):
    dived = []
    for y in range(h-1):
        if (pattern >> y) & 1:
            dived.append(y + 1)

    dived.append(h)
    slash_count = len(dived) - 1

    prev_x = 0
    for nx in range(1, w + 1):
        prev_y = 0
        possible = True
        for ny in dived:
            white = white_count[ny][nx] - white_count[prev_y][nx] - (white_count[ny][prev_x] - white_count[prev_y][prev_x])
            prev_y = ny
            if white <= k:
                continue
            else:
                slash_count += 1
                slash = nx - 1
                if prev_x == slash:
                    possible = False
                prev_x = slash
                break

        if not possible:
            break

    else:
        ans.append(slash_count)

print(min(ans))


Measured memory_bytes: 3316
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using vl=vector<ll>;
using vvl=vector<vl>;
using pii=pair<int,int>;
using pll=pair<ll,ll>;
const ll LINF=0x1fffffffffffffff;
const int INF=0x3fffffff;
const int MOD=1000000007;
#define VAR(type,...) type __VA_ARGS__;in(__VA_ARGS__)
#define VEC(type,name,size) vector<type> name(size);each(x, name)in(x)
#define rep(i,a,b) for(int i=(a);i<(b);++i)
#define rrep(i,a,b) for(int i=(a-1);i>=(b);--i)
#define each(x,v) for(auto &x:(v))
#define all(x) (x).begin(),(x).end()
#define print(x) cout<<(x)<<endl
void in(){} template<class T,class... U> void in(T &t,U &...u){cin>>t;in(u...);}
void solve();
int main(){cin.tie(0);ios::sync_with_stdio(0);solve();}

void solve() {
  VAR(string, s);
  print(s.find_last_of('Z') - s.find('A') + 1);
}


Measured memory_bytes: 720
from collections import deque

n = int(input())
neighbor = {}
for _ in range(n - 1):
    u, v, w = map(int, input().split())
    if u not in neighbor:
        neighbor[u] = deque()
    if v not in neighbor:
        neighbor[v] = deque()
    neighbor[u].append((v, w))
    neighbor[v].append((u, w))

color = {1: 0}
visited = set([1])
queue = deque([(1, 0)])

while len(queue) > 0:
    v, wsum = queue.pop()
    for u, w in neighbor[v]:
        if u in visited:
            continue
        visited.add(u)
        color[u] = (wsum + w) % 2
        queue.append((u, wsum + w))

for i in range(n):
    print(color[i + 1])


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

int main(){
    int n,d;
    cin >> n >> d;
    int s = n/(2*d + 1);
    if(n%(2*d+1) != 0) s+= 1;
    cout << s << endl;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
    int N, M;
    scanf("%d %d", &N, &M);
    int L[M], R[M];
    for(int i=0; i<M; i++)
        scanf(" %d %d", &L[i], &R[i]);
    int maxL=1, minR=N;
    for(int i=0; i<M; i++){
        if(maxL < L[i]) maxL = L[i];
        if(minR > R[i]) minR = R[i];
    }

    int card = maxL <= minR ? minR - maxL + 1 : 0;
    printf("%d\n", card);
}


Measured memory_bytes: 896
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<map>
#include<iomanip>
#include<queue>
#include<stack>
#include<numeric>
#include<utility>
#include<regex>

#pragma region _define

#define f(i,a,b) for(int i=a;i<b;i++)
#define f_vI(v,n) f(i,0,n)cin>>v[i]
#define f_v2I(v1,v2,n) f(i,0,n)cin>>v1[i]>>v2[i]
#define f_v3I(v1,v2,v3,n) f(i,0,n)cin>>v1[i]>>v2[i]>>v3[i]
#define f_vO(v,n) f(i,0,n)cout<<v[i]<<endl
#define all(a) a.begin(),a.end()
#define size(s) s.size()
#define endl "\n"
#define _y() cout<<"Yes"<<endl
#define _Y() cout<<"YES"<<endl
#define _n() cout<<"No"<<endl
#define _N() cout<<"NO"<<endl

#pragma endregion

#pragma region _using

using namespace std;

using LL = long long;
using st = string;
using vi = vector<LL>;
using vvi = vector<vi>;
using vvvi = vector<vvi>;
using vs = vector<st>;
using vb = vector<bool>;
using vvb = vector<vb>;
using vvvb = vector<vvb>;
using si = stack<LL>;
using pi = pair<LL, LL>;
using v_pi = vector<pi>;

#pragma endregion

#pragma region _graph

#define node 50
//bool graph[node][node]; bool visited[node] = { false };
#define link(a,b) f(i,0,n){cin>>a[i]>>b[i]; a[i]--; b[i]--; graph[a[i]][b[i]]=graph[b[i]][a[i]]=true;}

#pragma endregion

LL gcd(LL a, LL b) {
	LL r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}
LL lcm(LL a, LL b) {
	return (a / gcd(a, b) * b);
}

/*****************************************************************************/


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

	int h, w;
	cin >> h >> w;
	vs s(h);
	f(i, 0, h)cin >> s[i];
	f(i, 0, h) {
		f(j, 0, w) {
			if (s[i][j] == '#') {
				bool f = false;
				if ((0 <= i - 1 && s[i - 1][j] == '#')||(i+1<h&&s[i+1][j]=='#')||(0<=j-1&&s[i][j-1]=='#')||(j+1<w&&s[i][j+1]=='#')) {
					f = true;
				}
				else {
					_n();
					return 0;
				}
			}
		}
	}
	_y();
	return 0;
}

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

using namespace std;

#define F first
#define S second
#define PB push_back
#define MP make_pair
#define MT make_tuple

typedef long long ll;
typedef vector<int> vi;
typedef pair<int,int> pi;
typedef tuple<int,int,int> ti;

int main(){
	ios::sync_with_stdio(0);
	cin.tie(0);
	
	int t;
	// cin>>t;
	t = 1;
	while(t--){
		int n;
		cin>>n;
		int a[n],b[n],c[n];
		int dp[n][3];
		for(int i=0;i<n;i++){
			cin>>a[i]>>b[i]>>c[i];
		}
		dp[0][0]=a[0];
		dp[0][1]=b[0];
		dp[0][2]=c[0];
		for(int i=1;i<n;i++){
			for(int j=0; j<3;j++){
				int k = c[i];
				if(j==0){
					k = a[i];
				}
				else if(j==1){
					k = b[i];
				}
				dp[i][j] = max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]) + k;
			}
		}
		cout<<max({dp[n-1][0],dp[n-1][1],dp[n-1][2]})<<'\n';
	}
}

Measured memory_bytes: 2560
N=int(input())
s={}
for a in list(map(int,input().split())):
    if a not in s:
        s[a]=1
    else:
        s[a]+=1

ans=0
for a in s:
    if s[a]>=a:
        ans+=s[a]-a
    else:
        ans+=s[a]

print(ans)

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

#define REP(i,n) for(int i=0;i<(n);i++)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
typedef long long ll;
typedef pair<int,int> P;

template<typename A,typename B> inline void chmin(A &a,B b){if(a>b) a=b;}
template<typename A,typename B> inline void chmax(A &a,B b){if(a<b) a=b;}

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

int x[205],y[205];

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

    int n;
    while(cin>>n,n)
    {
        x[0]=y[0]=0;
        for(int i=1;i<n;i++)
        {
            int k,d;
            cin>>k>>d;
            x[i]=x[k]+dx[d];
            y[i]=y[k]+dy[d];
        }
        cout<<*max_element(x,x+n)-*min_element(x,x+n)+1<<" "
            <<*max_element(y,y+n)-*min_element(y,y+n)+1<<endl;
    }   
}

Measured memory_bytes: 3068
N, A = map(int, input().split())
x = list(map(int, input().split()))
maxX = max(max(x), A)
dp = [[[0 for _ in range(N * maxX + 1)] for _ in range(N + 1)] for _ in range(N + 1)]
dp[0][0][0] = 1
for i in range(N):
    for j in range(N + 1):
        for k in range(N * A + 1):
            if dp[i][j][k] == 0: continue
            dp[i + 1][j][k] += dp[i][j][k]
            dp[i + 1][j + 1][k + x[i]] += dp[i][j][k]

ans = 0
for i in range(1, N + 1):
    ans += dp[N][i][A * i]
print(ans)

Measured memory_bytes: 71420
N = int(input())
X = list(map(int, input().split()))
Xc = X.copy()
Xc.sort()

d = N // 2
dn = Xc[d]

for i in range(N):
    if X[i] < dn:
        print(Xc[d])
    else:
        print(Xc[d-1])


Measured memory_bytes: 25228
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <random>
#include <complex>
#include <random>
 
using namespace std;

#define int long long

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

    string s;
    cin >> s;
    int sumw = 0;
    int cntw = 0;
    for (int i = 0; i < (int)s.size(); i++) {
    	if (s[i] == 'W') {
    		sumw += i;
    		cntw++;
    	}
    }
    int nsum = (cntw * (cntw - 1)) / 2;
    cout << sumw - nsum << endl;
}


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

void sort(int h[]);
void swap(int *x, int *y){
    
}
void sort(int a[], int n){
    int i, j, temp;
    for(i=0;i<n-1;i++){
        for (j=n-1;j>i;j--){
            if(a[j-1] > a[j]){
                temp = a[j-1];
                a[j-1] = a[j];
                a[j] = temp;
            }
        }
    }
}


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

    sort(a, n);
    // for (i = 0; i < n; i++)
    // {
    //     cout << a[i] << " ";
    // }
    long double result;
    // add start
    result = a[0];
    for (i=1;i<n;i++){
        result = (result + a[i])/2;
    }
    cout << result << endl;

    return 0;
}

Measured memory_bytes: 256
/*------------------------------------
........Bismillahir Rahmanir Rahim....
..........created by Abdul Aziz.......
------------------------------------*/
#include <iostream>
#include <algorithm>
#include <stdio.h>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <cstring>
#include <unordered_map>
#include <queue>
#define   mod  998244353
#define   int  long long 
#define   ld   long double
#define   pb   push_back
#define   vi  vector<int> 
#define   dbg(x)  cerr << #x << " = " << x << '\n'
#define   sz(x)  (int)x.size()
#define   all(a) (a.begin(),a.end())
#define   ff   first
#define   ss   second
#define   pii  pair<int,int> 
#define   lcm(a,b) (a*b)/__gcd(a,b) 
using namespace std;

vector <int> g[200005];
int res[200005];
bool vis[200005];

void dfs(int root,int add){ 
	vis[root]=true;
	for (auto &it: g[root]){ 
		if (!vis[it]){ 
			res[it] += add; 
			dfs(it,res[it]); 
		} 
	} 
} 

signed main()
{
    int n,q; cin>>n>>q; 
    for (int i=1;i<n;i++){
    	int a,b;cin>>a>>b;
    	g[a].pb(b);
    	g[b].pb(a);
    }
    while (q--){
    	int root,add;
    	cin>>root>>add;
    	res[root] += add;
    }
    dfs(1,res[1]);
    for (int i=1;i<=n;i++) cout << res[i]<< " ";
    cout << endl;
    return 0;
}


Measured memory_bytes: 25644
#include <cstdio>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int num[300];
int cmp(int a, int b)
{
	return abs(a) < abs(b);
}
int main()
{
	int n, l;

	cin >> n >> l;
	for (int i = 0; i < n; ++i) {
		num[i] = l + i;
	}
	sort(num, num + n, cmp);
	int sum = 0;
	for (int i = 1; i < n; ++i) {
		sum += num[i];
	}
	cout << sum << endl;
	return 0;
}


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

int main() {
    int n, a, sum = 0;
    cin >> n >> a;
    while (1) {
        if (n % 500 == 0)
            break;
        n--;
        sum++;
    }
    if (sum <= a)
        cout << "Yes" << endl;
    else
        cout << "No" << endl;
    return 0;
}

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

int main(){
    int H1, A1, H2, A2;
    cin >> H1 >> A1 >> H2 >> A2;
    while(true){
        H2 -= A1;
        if(H2 <= 0){
            cout << "Yes" << endl;
            break;
        }
        H1 -= A2;
        if(H1 <= 0){
            cout << "No" << endl;
            break;
        }

    }
}

Measured memory_bytes: 3636
fn main() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let s = sc.chars();
    let ans = match s.last().unwrap().to_digit(10).unwrap() {
        3 => "bon",
        0 | 1 | 6 | 8 => "pon",
        _ => "hon",
    };
    println!("{}", ans);
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: ToString>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.to_string().as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
}

Measured memory_bytes: 2132
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ConsoleApp1 {
    class Program {
        static void Main(string[] args) {
            //string[] str = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得
            //int a = int.Parse(str[0]);  //数値で受け取りたい場合は変換する
            //int b = int.Parse(str[1]);
            //if ((a + b) % 2 == 0) {
            //    Console.WriteLine((a + b) / 2);
            //} else {
            //    Console.WriteLine("IMPOSSIBLE");
            //}


            //数列pのNi+1 - Niの差がすべて１ならOK、つまりN - 1ならOK
            //

            string str = Console.ReadLine();
            int n = int.Parse(str);
            string[] strData = Console.ReadLine().Split(' ');//2つ以上のスペース区切り入力の取得

            var num = new List<int>();
            var num1 = new List<int>();

            var countDiff = 0;
            bool isPossible;

            foreach(var obj in strData) {
                num.Add(int.Parse(obj));
                num1.Add(int.Parse(obj));
            }

            num.Sort();

            //Console.WriteLine("[{0}]", string.Join(", ", num));
            //Console.WriteLine("[{0}]", string.Join(", ", num1));

            for(var i = 0; i < n; i++) {
                if(num[i] != num1[i]) {
                    countDiff++;
                }
            }

            if(countDiff <= 2) {
                isPossible = true;
            } else {
                isPossible = false;
            }


            if (isPossible) {
                Console.WriteLine("YES");
            } else {
                Console.WriteLine("NO");
            }

            Console.ReadKey();

        }
    }
   
}


Measured memory_bytes: 11220
#include <sstream>
#include <iostream>
#include <cstdlib>
#include <string>
using namespace std;

int a[200];
int top = 0;
void push(int num)
{
	a[++top] = num;
}

int pop()
{
	top--;
	return a[top + 1];
}

int main(int argc, char const *argv[])
{
	int x, y;
	string c;
	while (cin >> c)
	{
		switch (c[0])
		{
		case '+':
			y = pop();
			x = pop();
			push(x + y);
			break;
		case '-':
			y = pop();
			x = pop();
			push(x - y);
			break;
		case '*':
			y = pop();
			x = pop();
			push(x * y);
			break;
		default:
			stringstream x(c);
			int m;
			x >> m;
			push(m);
		}
	}
	cout << pop() << endl;
	return 0;
}


Measured memory_bytes: 3156
#include <iostream>

using namespace std;

int main(){
    int v[3][3];
    for(int i=0;i<3;i++)
        for(int j=0;j<3;j++) 
            cin >> v[i][j];

    int a = v[0][0]-v[1][0];
    int b = v[0][1]-v[1][1];
    int c = v[0][2]-v[1][2];
    int d = v[1][0]-v[2][0];
    int e = v[1][1]-v[2][1];
    int f = v[1][2]-v[2][2];

    if(a==b && a==c && d==e && d ==f){
        cout<<"Yes"<<endl;
    }else{
        cout<<"No"<<endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define FAST ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
typedef long long ll;
typedef long double ld;
#define pb push_back
#define mp make_pair
#define ff first
#define ss second
#define mod 1000000007
#define inf 1000000000000000000
#define bpc(x) __builtin_popcountll(x)
#define autoit(x,it) for(auto it = x.begin(); it != x.end(); it++)
#define rep(n) for(ll i = 0; i < n; i++)
#define repi(i,n) for(ll i = 0; i < n; i++)

#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace __gnu_pbds; 

#define ordered_set tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update> 

using namespace std;

char get(ll n)
{
    if(n == 1)
        return 'P';
    return 'D';    
}

int main()
{
   FAST/**/
   
   ll n;
   cin>>n;
   
   ll arr[n+1];
   rep(n+1)
        cin>>arr[i];
   if((n == 0 && arr[0]!=1) || (arr[0] == 1 && n>0))
   {
       cout<<-1;
       return 0;
   }
   
   if(n == 0)
   {
       cout<<1;
       return 0;
   }
   
   ll curr = 1;
   ll sum = 1;
   
   ll post[n+1];
   post[n] = arr[n];
   for(ll i=n-1;i>-1;i--)
        post[i]=post[i+1]+arr[i];
        
   for(ll i=1;i<=n;i++)
   {
       ll maxi = post[i];
       ll l = curr - arr[i-1];
       ll r = 2*l;
       
       if(curr<arr[i-1])
       {
           cout<<-1;
           return 0;
       }
       if(maxi<l)
       {
           //cout<<"hehe\n";
           //cout<<-10<<" at "<<i<<"\n";
           cout<<-1;
           return 0;
       }
       
       ll ele;
       if(maxi<=r)
            ele = maxi;
       else ele = r;
       
       if(i == n && r<maxi)
       {
           //cout<<-100<<" at "<<i<<"\n";
           cout<<-1;
           return 0;
       }
       
       curr = ele;
       sum+=ele;
   }
   
   cout<<sum;
   
   
   return 0;        
}  
  
   

Measured memory_bytes: 5220
#0-indexed , 半開区間[a,b)
#calc変更で演算変更
class SegTree:

    def __init__(self,N,first):
        self.NO = 2**(N-1).bit_length()
        self.First = first
        self.data = [first] * (2*self.NO)

    def calc(self,l,r):
        return max(l,r)

    def update(self,ind,x):
        ind += self.NO - 1
        self.data[ind] = x
        while ind >= 0:
            ind = (ind - 1)//2
            self.data[ind] = self.calc(self.data[2*ind+1],self.data[2*ind+2])

    def query(self,l,r):
        L = l + self.NO
        R = r + self.NO
        s = self.First
        while L < R:
            if R & 1:
                R -= 1
                s = self.calc(s , self.data[R-1])
            if L & 1:
                s = self.calc(s , self.data[L-1])
                L += 1
            L >>= 1
            R >>= 1
        return s

    def get(self , ind):
        ind += self.NO - 1
        return self.data[ind]

from sys import stdin

N,K = map(int,stdin.readline().split())

ST = SegTree(400000,0)

for i in range(N):

    A = int(stdin.readline())

    nmax = ST.query(max(0,A-K) , min(350000,A+K+1))
    ST.update(A,nmax+1)

print (ST.query(0,350000))

Measured memory_bytes: 84140
#include <algorithm>
#include <cstdio>
#include <cstring>

using namespace std;
typedef long long LL;
int n;
int a[200000 + 10];

bool check(int a, int b) {
    return (a + b) == (a ^ b);
}

int main() {
    while (~scanf("%d", &n)) {
        for (int i = 0; i < n; i++)
            scanf("%d", a + i);

        int r = 1;
        int t = a[0];
        LL ans = 0;
        for (int i = 0; i < n; i++) {
            while (r < n && check(t, a[r])) {
                t ^= a[r];
                r++;
            }
            ans += r - i;
            //printf("%d %d\n", i, r);
            t = a[i] ^ t;
            //printf("%d\n", t);
        }
        printf("%lld\n", ans);
    }
    return 0;
}

Measured memory_bytes: 896
H, W = map(int, input().split())
N = int(input())
a = list(map(int, input().split()))
colors = []
for color in range(1, N + 1):
    for j in range(a[color - 1]):
        colors.append(str(color))
canvas = []
for i in range(H):
    if i % 2 == 0:
        canvas.append(colors[i * W: i * W + W])
    else:
        canvas.append(colors[i * W + W - 1: i * W - 1: -1])
for line in canvas:
    print(' '.join(line))

Measured memory_bytes: 3828
N=int(input(), 10)
cnt = dict()
for _ in range(N):
    s = input()
    if s in cnt:
        cnt[s] += 1
    else:
        cnt[s] = 0

max_cnt = max(cnt.values())
for word in sorted([key for key, value in cnt.items() if value == max_cnt]):
    print(word)


Measured memory_bytes: 32988
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
const int INF = 1 << 29;
const int MOD = 1000000007;

int main() {
    int n, k;
    cin >> n >> k;
    int r, s, p;
    cin >> r >> s >> p;
    string t;
    cin >> t;

    // mod kによってk個のグループに分ける
    // 各グループに対してそのグループにおいて最大何点とれるかを求める
    // ただし連続で同じ手を出すことはできない

    // 貪欲法で解く(確認済み)
    // 基本的には勝てる手を出し、1つ前に出した手のせいで勝てないときは飛ばす(手をリセット)

    long long score = 0;

    // グループ毎に
    for (int i = 0; i < k; i++) {
        // 各グループにおいて
        // 前回の手(初期値は適当なchar)
        char pre_hand = 'a';

        for (int j = i; j < n; j += k) {
            // 今回の敵の手
            char hand = t.at(j);

            // 前回の手と同じ場合は点数なし
            if (hand == pre_hand) {
                // 前回の手を初期化
                pre_hand = 'a';
                continue;
            }

            // 前回の手と異なる場合点数を加算
            if (hand == 'r') {
                score += p;
            } else if (hand == 's') {
                score += r;
            } else if (hand == 'p') {
                score += s;
            }

            // 今回の手を更新
            pre_hand = hand;
        }
    }

    cout << score << endl;
}


Measured memory_bytes: 3724
#include <vector>
#include <climits>
#include <cstdio>
using namespace std;

class SegmentTree {
    const int N; // array size
    const int M; // initial value of the tree
    const int O; // initial value of the query
    const int H; // height of the tree, the highest significant bit in N

    int (*f)(int, int); // query operation
    int (*g)(int, int); // update operation

public:
    vector<int> t; // tree
    vector<int> d; // delayed tree

    SegmentTree(int N, int M, int O, int (*f)(int, int)) :
            N(N), M(M), O(O), H(sizeof(int) * 8 - __builtin_clz(N)), f(f), g(f), t(2 * N, M), d(N) {}

    SegmentTree(int N, int M, int O, int (*f)(int, int), int (*g)(int, int)) :
            N(N), M(M), O(O), H(sizeof(int) * 8 - __builtin_clz(N)), f(f), g(g), t(2 * N, M), d(N) {}

    void apply(int p, int val) {
        t[p] = g(val, t[p]);
        if (p < N) d[p] = g(val, d[p]);
    }

    void build(int p) {
        while (p > 1) {
            p >>= 1;
            t[p] = g(d[p], f(t[p << 1], t[p << 1 | 1]));
        }
    }

    void push(int p) {
        for (int s = H; s > 0; --s) {
            int i = p >> s;
            if (d[i] != 0) {
                apply(i << 1, d[i]);
                apply(i << 1 | 1, d[i]);
                d[i] = 0;
            }
        }
    }

    void update(int l, int r, int val) { // update val at interval [l, r)
        if (val == 0) return;
        l += N, r += N;
        int l0 = l, r0 = r;
        for (; l < r; l >>= 1, r >>= 1) {
            if (l & 1) apply(l++, val);
            if (r & 1) apply(--r, val);
        }
        build(l0);
        build(r0 - 1);
    }

    int query(int l, int r) { // query on interval [l, r)
        l += N, r += N;
        push(l);
        push(r - 1);
        int res = O;
        for (; l < r; l >>= 1, r >>= 1) {
            if (l & 1) res = f(t[l++], res);
            if (r & 1) res = f(t[--r], res);
        }
        return res;
    }
};

void test() {
    int n, q;
    scanf("%d%d", &n, &q);

    SegmentTree T(n, 0, INT_MAX,
                  [](int a, int b) { return min(a, b); },
                  [](int a, int b) { return a + b; }
    );

    while (q--) {
        int type;
        scanf("%d", &type);
        if (type) {
            int s, t;
            scanf("%d%d", &s, &t);
            printf("%d\n", T.query(s, t + 1));
        } else {
            int s, t, x;
            scanf("%d%d%d", &s, &t, &x);
            T.update(s, t + 1, x);
        }
    }
}

int main() {
    test();
}



Measured memory_bytes: 3456
#include<cstdio>
#include<iostream>
#include<algorithm>
#include<string>
#include<cstring>
#include<queue>
#include<vector>
#include<functional>
#include<cmath>
#include<map>
#include<stack>
#include<set>
#include<numeric>
#include<limits>
#include<iterator>

#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define rep(i,n) for(int i=0; i<n; i++)
#define FOR(i,a,n) for(int i=a; i<n; i++)

using namespace std;
typedef long long ll;
typedef pair<int, int> pi;
typedef pair<ll, ll> pl;
typedef pair<ll, char> plc;

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

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


Measured memory_bytes: 256
// スタックサイズ: 100MB

#include <iostream>
#include <fstream>
#include <vector>
#include <map>
#include <unordered_map>
#include <string>
#include <cmath>
#include <cstdio>
#include <algorithm>
#include <functional>
#include <numeric>
#include <iomanip>
#include <queue>
#include <list>
#include <set>
using namespace std;

typedef int64_t ll;
typedef vector<ll> vll;
typedef pair<ll, ll> pll;
const ll INF = 1000000000000000000;
#define fori(i, a, b) for (ll i = (a); i < (b); ++i)
#define ford(i, a, b) for (ll i = (b - 1); (a) <= i; --i)
#define rep(i, n) fori(i, 0, n)
#define all(v) (v).begin(), (v).end()
#define fst first
#define snd second
ll pw(ll x, ll y) { ll r = 1;  rep(i, y) { r *= x; }; return r; }




int main() {

	ll N;
	cin >> N;
	ll bu = 0;
	rep(i, 9) {
		ll tmp = N;
		tmp /= pow(10, i);
		tmp %= 10;
		bu += tmp;
	}
	cout << (N % bu == 0 ? "Yes" : "No") << endl;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"strings"
)

func main() {

	var t, w string
	var n int = 0
	fmt.Scan(&w)

	for {
		fmt.Scan(&t)
		if t=="END_OF_TEXT" {
			break
		}
		t = strings.ToLower(t)
		if t==w {
			n++
		}
	}
	fmt.Println(n)
}


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

using namespace std;
using ll = long long;

//container util
#define SORT(c) sort((c).begin(),(c).end())

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


int main(void){

	
	int N, K; cin >> N >> K;
	
	int ans = 0;
	REP(i,N){
		int h; cin >> h;
		if(h >= K) ans++;
	}

	cout << ans << endl;

	return 0;

}


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

using namespace std;
using ll =long long;
typedef vector<int> VI;
typedef vector<VI> VVI;
typedef pair<int,int> PII;
#define SORT(a) sort((a).begin(),(a).end())
#define rSORT(a) reverse((a).begin(),(a).end())
#define For(i, a, b)    for(int i = (a) ; i < (b) ; ++i)
#define rep(i, n)       For(i, 0, n)
#define debug(x)  cerr << #x << " = " << (x) << endl;
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; }
using P = pair<int,int>;
//Write From this Line

int main()
{
	string s;
	cin >> s;
	if(s=="AKIHBR") cout << "YES" << endl;
	else if(s=="KIHABR") cout << "YES" << endl;
	else if(s=="AKIHABR") cout << "YES" << endl;
	else if(s=="KIHBAR") cout << "YES" << endl;
	else if(s=="AKIHBAR") cout << "YES" << endl;
	else if(s=="KIHABAR") cout << "YES" << endl;
	else if(s=="AKIHABAR") cout << "YES" << endl;
	else if(s=="KIHBRA") cout << "YES" << endl;
	else if(s=="AKIHBRA") cout << "YES" << endl;
	else if(s=="KIHABRA") cout << "YES" << endl;
	else if(s=="AKIHABRA") cout << "YES" << endl;
	else if(s=="KIHBARA") cout << "YES" << endl;
	else if(s=="AKIHBARA") cout << "YES" << endl;
	else if(s=="KIHABARA") cout << "YES" << endl;
	else if(s=="AKIHABARA") cout << "YES" << endl;
	else if(s=="KIHBR") cout << "YES" << endl;
	else cout << "NO" << endl;
}


Measured memory_bytes: 256
n = int(input())
a = {}
for i in range(n):
    s = list(input())
    s.sort()
    s = "".join(s)
    a.setdefault(s, 0)
    a[s] += 1
count = 0
for i in a.values():
    count += i * (i - 1) // 2
print(count)

Measured memory_bytes: 17932
import java.util.*;

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

    String s = sc.next();
    int len = s.length();
    String ans = "Yes";

    for(int i = 0; i < len / 2; i++){
      if(s.charAt(i) != s.charAt((len / 2) - 1 - i)){
        ans = "No";
        break;
      } else if(s.charAt((len / 2) + 1 + i) != s.charAt((len / 2) - 1 - i)){
        ans = "No";
        break;
      }
    }

    System.out.println(ans);
  }
}


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

#define IL __inline__ __attribute__((always_inline))

#define For(i, a, b) for (int i = (a), i##end = (b); i <= i##end; ++ i)
#define FOR(i, a, b) for (int i = (a), i##end = (b); i < i##end; ++ i)
#define Rep(i, a, b) for (int i = (a), i##end = (b); i >= i##end; -- i)
#define REP(i, a, b) for (int i = (a) - 1, i##end = (b); i >= i##end; -- i)

typedef long long LL;

template<class T>
IL bool chkmax(T &a, const T &b) {
  return a < b ? ((a = b), 1) : 0;
}

template<class T>
IL bool chkmin(T &a, const T &b) {
  return a > b ? ((a = b), 1) : 0;
}

template<class T>
IL T mymax(const T &a, const T &b) {
  return a > b ? a : b;
}

template<class T>
IL T mymin(const T &a, const T &b) {
  return a < b ? a : b;
}

template<class T>
IL T myabs(const T &a) {
  return a > 0 ? a : -a;
}

const int INF = 0X3F3F3F3F;
const double EPS = 1E-10, PI = acos(-1.0);

#define DEBUG(...) fprintf(stderr, __VA_ARGS__)
#define OK DEBUG("Passing [%s] in LINE %d...\n", __FUNCTION__, __LINE__)
/*------------------------------header------------------------------*/

const int MAXN = 100000 + 5;

int a[MAXN];

int main() {
  int m, n;
  scanf("%d%d", &m, &n);
  For(i, 1, n) {
    scanf("%d", &a[i]);
  }
  if (n == 1) {
    if (a[1] == 1) {
      printf("%d\n%d\n%d\n", a[1], 1, 1);
    } else {
      printf("%d\n%d\n%d %d\n", a[1], 2, a[1] - 1, 1);
    }
    exit(0);
  }
  if (n == 2) {
    if (a[1] == 1) {
      printf("%d %d\n%d\n%d\n", a[1], a[2], 1, a[1] + a[2]);
    } else {
      printf("%d %d\n%d\n%d %d\n", a[1], a[2], 2, a[1] - 1, a[2] + 1);
    }
    exit(0);
  }
  int cnt = (a[1] & 1) + (a[n] & 1);
  FOR(i, 2, n) {
    if (a[i] & 1) {
      if (!cnt) {
        std::swap(a[1], a[i]);
        ++ cnt;
      } else if (cnt == 1) {
        std::swap(a[i], a[n]);
        ++ cnt;
      } else {
        puts("Impossible");
        exit(0);
      }
    }
  }
  For(i, 1, n) {
    printf("%d ", a[i]);
  }
  puts("");
  if (a[1] == 1) {
    printf("%d\n", n - 1);
    FOR(i, 2, n) {
      printf("%d ", a[i]);
    }
    printf("%d\n", a[n] + 1);
    exit(0);
  }
  printf("%d\n", n);
  printf("%d ", a[1] - 1);
  FOR(i, 2, n) {
    printf("%d ", a[i]);
  }
  printf("%d\n", a[n] + 1);
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <math.h>
#include <stdio.h>
using namespace std;
int main(){
int n,m;
cin >> n >>m;
int x[100003];
for(int i=0;i<m;i++){
 cin >> x[i];
}
sort(x,x+m);

int y[100003];
for(int i=0;i<m-1;i++){
y[i]=x[i+1]-x[i];
}
sort(y,y+m-1);

int ans=0;
for(int i=0;i<m-n;i++){
 ans=ans+y[i];
}


cout << ans;


return 0;
  
}

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

int main() {
	int n; cin >> n;
	vector<string> v;
	string s;
	for (int i = 0; i < n; i++) {
		cin >> s; v.push_back(s);
		if (i) {
			if (s.front() != v[i - 1].back()) {
				cout << "No" << endl;
				return 0;
			}

			for (int j = 0; j < v.size() - 1; j++) {
				if (s == v[j]) {
					cout << "No" << endl;
					return 0;
				}
			}
		}
	}
	cout << "Yes" << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
#define ll long long
#define MOD 1000000007
#define nl cout<<endl
#define rt ll Q[100005]={0}
#define mp make_pair
#define test() ull t;cin>>t;while(t--)
#define pb push_back
#define ff first
#define ss second
#define all(v) v.begin(),v.end()
#define oa(a,n) for(ll i=0;i<n;i++)cout<<a[i]<<" ";nl
#define cn(a,n) for(ll i=0;i<n;i++)cin>>a[i]
#define ov(a) for(ll i=0;i<a.size();i++)cout<<a[i]<<" ";nl
#define fastio() ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
int main()
{
	fastio();
	ll N,W;
	cin>>N>>W;
	ll ar[W+1]={0};
	vector <pair<ll,ll>> v;
	ll a,b;
	for(ll i=0;i<N;i++)
	{
		cin>>a>>b;
		v.pb(mp(a,b));
	}
	sort(v.begin(),v.end());
	for(ll j=0;j<N;j++)
	{
		for(ll i=W;i>=0;i--)
		{
			if(i<v[j].ff)
				ar[i]=max(ar[i],ar[max((i-v[j].ff),0ll)]);
			else
				ar[i]=max(ar[i],v[j].ss+ar[max((i-v[j].ff),0ll)]);
		}
	}
	cout<<ar[W]<<endl;
}	


Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <unordered_map>
#include <cmath>
using namespace std;

typedef long long llong;
typedef unsigned long long ullong;
// -2.1e-9 <= int <= 2.1e9
// 0 <= unsigned int <= 4.2e9

int main()
{
    int A, B;
    cin >> A >> B;
    pair<int, int> valueA, valueB;

    valueA.first = A * 100 / 8;
    while(static_cast<int>(valueA.first * 0.08) != A) {
        ++valueA.first;
    }
    valueA.second = valueA.first;
    while(static_cast<int>(valueA.second * 0.08) == A) {
        ++valueA.second;
    }
    --valueA.second;

    //valueB[0] = static_cast<int>(ceil(B * 10.0));
    valueB.first = B * 10;
    while(static_cast<int>(valueB.first * 0.1) != B) {
        ++valueB.first;
    }
    valueB.second = valueB.first;
    while(static_cast<int>(valueB.second * 0.1) == B) {
        ++valueB.second;
    }
    --valueB.second;

    if ((valueA.first > valueB.second) || (valueB.first > valueA.second)) {
        cout << -1 << endl;
        return 0;
    }
    int ans = max(valueA.first, valueB.first);
    cout << ans << endl;
}



Measured memory_bytes: 256
//#include <cstdio>
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <map>
#include <set>
//#include <queue>
//#include <stack>
#include <cstring>
#include <cassert>

using namespace std;

#ifdef LOCAL_DEBUG
#include <local_debug.h>
#define DEBUG(...) DBG2::print(#__VA_ARGS__, __LINE__, __VA_ARGS__)
#else
#define DEBUG(...)
#endif

#define SZ(a) int((a).size())
#define REP(i,n) for(int i=0,_n=(n);i<_n;++i)
#define FOR(i,a,b) for(int i=(a),_b=(b);i<=_b;++i)

typedef long long llong;
typedef vector<int> VI;
typedef vector<VI> VVI;

llong solve(int N, VI A) {
   assert(N > 1);
   if (N == 2)
      return max(A[0], A[1]);

   sort(A.begin(), A.end(), greater<int>());

   llong res = 0;
   REP(i, N) {
      if (i == 0) continue;
   // DEBUG(i, A[i/2]);
      res += A[i/2];
   }
   return res;
}

int main(int argc, char* argv[]) {
   ios_base::sync_with_stdio(false); 
   cin.tie(nullptr);
   cout.precision(10);
   cout << fixed;

   int N;
   cin >> N;
   VI A(N);
   REP(i, N)
      cin >> A[i];

   llong res = solve(N, A);
   cout << res << endl;

   return 0;
}


Measured memory_bytes: 4776
#include<string>
#include<string.h>
#include<map>
#include<set>
#include<vector>
#include<stdio.h>
#include<math.h>
#include<iostream>
#include<algorithm>
#include<queue>
using namespace std;
int main()
{

int n;
const long long big=1000000007;
cin>>n;
long long ans=n;
for(int i=1;i<n;i++)
{ans*=i;
 if(ans>big)
 ans%=big;}
 cout<<ans;
system("pause"); 
return 0;
}


Measured memory_bytes: 504
#include <bits/stdc++.h>
using namespace std;
//NOT TO SUBMIT IN WRONG PLACE
//ABC, task c, 2020/04/12
//ms, ac
/*
*/

int main(void){
  int max;
  int ab_gcd;
  vector<int> gcd_list(201);
  gcd_list.at(0)=0;
  int gcd_list_sum;
  int ans=0;
  int temp;

  cin >>max;

  for(int a=1;a<=max;a++){
    for(int b=1;b<=max;b++){
      ab_gcd = gcd(a,b);
      gcd_list_sum=0;
      for(int i=1;i<=ab_gcd;i++){
        gcd_list.at(i)=gcd(i,ab_gcd);
        gcd_list_sum += gcd_list.at(i);
      }
      temp = (max/ab_gcd)*gcd_list_sum;
      for(int i=0;i<=(max%ab_gcd);i++){
        temp +=gcd_list.at(i);
      }
      ans += temp;
    }
  }

  cout <<ans <<endl;
  return 0;
}


Measured memory_bytes: 3644
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define FORD(i,a,b) for(int i=a;i>=b;i--)
#define REP(i,n) FOR(i,0,n)
#define pb push_back
#define en "\n"
#define LL long long
#define ITER(i,a) for( typeof(a.begin()) i=a.begin();i!=a.end();i++)
#define mod 1000000007
#define mpp make_pair
#define mes(a,b) memset((a),(b),sizeof((a))
typedef map<int,int> MI;
typedef pair<int,int> pairs;
typedef vector<int> VI;
int main() {
	// your code goes here
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int x;
    cin>>x;
    if(x>=30)
    cout<<"Yes"<<en;
    else
    cout<<"No"<<en;
    return 0;
}


Measured memory_bytes: 3592
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.Scanner;
import java.util.stream.IntStream;

public class Main {

	public static void main(String[] args) {
		try (Scanner scanner = new Scanner(System.in)) {
			int n = scanner.nextInt();
			int[][] a = new int[2][n];
			IntStream.range(0, 2).forEach(i -> IntStream.range(0, n).forEach(j -> a[i][j] = scanner.nextInt()));
			System.out.println(getResult(0, 0, a, new HashMap<>()));
		}
	}

	/**
	 * @param i   現在の縦座標
	 * @param j   現在の横座標
	 * @param a   飴の数の配列
	 * @param map 計算結果を保存するマップ
	 * @return (i,j)の地点から終点までの結果の最大値
	 */
	private static int getResult(int i, int j, final int[][] a, Map<List<Integer>, Integer> map) {
		List<Integer> key = Arrays.asList(i, j);
		Integer result = map.get(key);
		if (null == result) {
			result = a[i][j];
			if (i < a.length - 1) {
				// 下に移動できる場合
				if (j < a[0].length - 1) {
					// 右に移動できる場合、双方向の結果の最大値を計算
					result += Math.max(getResult(i + 1, j, a, map), getResult(i, j + 1, a, map));
				} else {
					// 右に移動できない場合、下方向の結果を計算
					result += getResult(i + 1, j, a, map);
				}
			} else {
				// 下に移動できない場合
				if (j < a[0].length - 1) {
					// 右に移動できる場合、右方向の結果を計算
					result += getResult(i, j + 1, a, map);
				}
			}
		}
		return result;
	}
}


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

long long modRecursive(long long a,long long b,long long c)
{
    if(b == 0) return 1;
    if(b%2 ==0) return modRecursive((a*a)%c,b/2,c);
    else return ((a%c)*(modRecursive((a*a)%c,b/2,c)))%c;
}

long long mod=1e9+7;

int main()
{
    string s; int d=0;
    cin>>s;
    for(int i=0; i<s.size(); i++)
    {
        if((i+1)%2==0)
        {
            if(s[i]=='L' || s[i]=='U' || s[i]=='D') d++;
        }
        else if((i+1)%2==1)
        {
            if(s[i]=='R' || s[i]=='U' || s[i]=='D') d++;
        }
    }
    if(d==s.size()) cout<<"Yes\n";
    else cout<<"No\n";
    return 0;
}



Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>

int top, S[100];

void push(int x){
  S[++top] = x;
}

int pop(){
  --top;
  return S[top+1];
}

int main(){
  int a, b, x;
  top = 0;
  char s[100];
  while( scanf("%s", s) != EOF ){
    if ( s[0] == '+' ){
      a = pop();
      b = pop();
      push(a + b);
    } else if ( s[0] == '-' ){
      b = pop();
      a = pop();
      push(a - b);
    } else if ( s[0] == '*' ){
      a = pop();
      b = pop();
      push(a * b);
    } else {
      x = atoi(s);
      push(x);
    }
  }

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

  return 0;
}

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,a) FOR(i,0,a)

typedef long long ll;
const ll INF=2e18;

int N;
ll T,A;

int main(){
	cin>>N;
	cin>>T>>A;
	REP(i,N-1){
		ll a,b;
		cin>>a>>b;
		ll n=(T+a-1)/a;
		ll temp1,temp2;
		temp1=temp2=INF;
		if (b*n>=A){
			temp1=n;
		}
		n=(A+b-1)/b;
		if (a*n>=T){
			temp2=n;
		}
		n=min(temp1,temp2);
		T=a*n;
		A=b*n;
	}
	cout<<T+A<<endl;
	return 0;
}


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

using namespace std;

const int max_n = 300111, mod = 998244353;

int n, cnt[10];
char s[max_n];
int ans = 1;

int mul(int x, int y) {
    return (1LL * x * y) % mod;
}

int get_c(char c) {
    if (c == 'R') {
        return 0;
    } else if (c == 'G') {
        return 1;
    }
    return 2;
}

int main() {
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    scanf("%d%s", &n, s);
    for (int i = 1; i <= n; ++i) {
        ans = mul(ans, i);
    }
    for (int i = 0; i < 3 * n; ++i) {
        int full = 7;
        int c = get_c(s[i]);
        full -= 1 << c;
        if (cnt[full]) {
            //cout << "full " << i << endl;
            ans = mul(ans, cnt[full]);
            --cnt[full];
        } else {
            bool f = 0;
            for (int j = 0; j < 3; ++j) {
                if (c != j && cnt[1 << j]) {
                    //cout << "$" << i << " " << cnt[1 << j] << endl;
                    ans = mul(ans, cnt[1 << j]);
                    --cnt[1 << j];
                    ++cnt[(1 << j) ^ (1 << c)];
                    f = 1;
                    break;
                }
            }
            if (!f) {
                //cout << "$" << i << endl;
                ++cnt[1 << c];
            }
        }
    }
    printf("%d\n", ans);
    return 0;
}


Measured memory_bytes: 512
from itertools import permutations as per
ty,he=map(int,input().split())
l=[set(map(int,input().split())) for i in range(he)]
ans=0
for g in per(range(2,ty+1)):
  co=[1]+list(g)
  for sd in zip(co,co[1:]):
    if set(sd) not in l:break
  else:ans+=1
print(ans)

Measured memory_bytes: 3064
import java.util.Scanner;

public class Main {

	static Scanner scanner;

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

	    int a=gi();
	    int b=gi();

	    int c=gi();

	    //System.out.print(s);

        if (a+b+c<=21) {
        	System.out.print("win");
        } else {
        	System.out.print("bust");
        }


	}
	// 文字列として入力を取得
	public static String gs() {
		return scanner.next();
	}

	// intとして入力を取得
	public static int gi() {
		return Integer.parseInt(scanner.next());
	}

	// longとして入力を取得
	public static long gl() {
		return Long.parseLong(scanner.next());
	}

	// doubleとして入力を取得
	public static double gd() {
		return Double.parseDouble(scanner.next());
	}
}

Measured memory_bytes: 35584
#include <stdio.h>
#include <string.h>
/*ABC132 a*/

int main(void)
{
  int count1 = 0;
  int count2 = 0;
  char str[4];
  char c = ' ';

  scanf("%s", &str);
  for (size_t i = 1; i < 4; i++) {
    if (str[i] == str[0]) {
      count1++;
    }else if(str[i] == c){
      count2++;
    }else c = str[i];
  }

  if (count1 == 1 && count2 ==1) {
    printf("Yes\n");
  }else printf("No\n");

  return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define rep(i,b) FOR(i,0,b)
#define INF mugen
#define dump(x) cerr<<#x<<"="<<x<<endl


using ll = long long;
const ll mod = LLONG_MAX;

int x,a,b;
int main(){
  cin>>x>>a>>b;
  if(abs(x-a) > abs(x-b))cout<<"B"<<endl;
  else cout<<"A"<<endl;
}


Measured memory_bytes: 256