akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
const int INF = 0x3f3f3f3f;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}

int a[100];
int e[100];
int r[100];
int dp[101][101];

int main() {
  int d,n;
  while (cin>>d>>n, d||n) {
    REP(i,n) {
      cin >> a[i] >> e[i] >> r[i];
    }
    memset(dp,0x3f,sizeof(dp));
    dp[0][0] = 0;
    REP(i,d) {
      REP(j,101) {
        REP(k,n) {
          if (j >= r[k]) {
            chmin(dp[min(d,i+a[k])][min(100,j+e[k])], dp[i][j] + 1);
          }
        }
      }
    }
    int ans = INF;
    REP(j,101)
      chmin(ans, dp[d][j]);
    if (ans == INF) puts("NA");
    else cout << ans << endl;
  }
}

Measured memory_bytes: 1212
import sys
sys.setrecursionlimit(100000000)


def main():
    solve()


def solve():
    for data in get_dataset():
        print search(data)


def search(data):
    count = 0
    H = len(data)
    W = len(data[0])
    for i in xrange(H):
        for j in xrange(W):
            if data[i][j] == '.':
                continue
            _search(i, j, H, W, data[i][j], data)
            count += 1
    return count


def _search(i, j, H, W, cell, data):
    data[i][j] = '.'
    for a in xrange(i-1, i+2):
        if not -1 < a < H:
            continue
        for b in xrange(j-1, j+2):
            if not -1 < b < W:
                continue

            if a != i and b != j:
                continue

            if data[a][b] == '.':
                continue

            if cell == data[a][b]:
                _search(a, b, H, W, cell, data)
    return


def get_dataset():
    dataset = []
    while True:
        line = raw_input().rstrip().split()
        H = int(line[0])
        if H == 0:
            break

        data = []
        for i in xrange(H):
            data.append(list(raw_input().rstrip()))
        dataset.append(data)
    return dataset


if __name__ == '__main__':
    main()

Measured memory_bytes: 15780
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;

using namespace std;
int main() {
	string s;
	cin >> s;
	int cnt = 0;
	rep(i, s.size()) {
		if (s[i] == 'o') cnt++;
	}

	if (cnt + 15 - s.size() >= 8) cout << "YES" << endl;
	else cout << "NO" << endl;
	return 0;
}


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

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

    sort(a, a + n, greater<int>());

    int sum = 0;
    for (int i = 0; i < k; i++) {
        sum += a[i];
    }
    cout << sum << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long 
int main()
{
  int n,cnt = 1;
  int p[200005];
  int mi[200005];
 
  cin >> n;

  for(int i=0; i<200005; i++) mi[i] = 1000000;
 
  for(int i=0; i<n; i++) cin >> p[i];

  mi[0] = p[0];

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

    if(mi[i-1] > p[i]) cnt++;
    mi[i] = min(mi[i-1] , p[i]);
  }

  cout << cnt << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <iostream>

using namespace std;

int main(){
  string s;
  cin >> s;
  int max = 0;
  int cnt = 0;
  for (int i = 0; i < 3; i++)
    if (s[i]=='R') {
		cnt++;
      	if (cnt>max) max = cnt;
    }
  	else cnt = 0;
  cout << max << endl;
 return 0; 
}

Measured memory_bytes: 3624
#include <iostream>
using namespace std;
#include <vector>
#include <stdio.h>
#include <algorithm>
#define _USE_MATH_DEFINES
#include <math.h>
#include <string>
#include <cstdlib>

int main() {
	string a;
	char temp;
	for(int i = 0; i < 2; i++) {
		cin >> a;
		if(i == 1) {
			temp = a[0];
		}
	}
	cout << "A" << temp << "C";
	return 0;
}

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

int main() {
    int n;cin>>n;
    ll a,b;cin>>a>>b;
    ll x[n];rep(i,n)cin>>x[i];
    ll ans = 0;
    rep(i,n-1)ans+=min((x[i+1]-x[i])*a,b);
    cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 4428
#include <iostream>
#include <cstdio>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <iomanip>
#include <stdlib.h>
#include <string.h>
#include <cstring>
#include <cmath>
#include <map>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <stdio.h>
#include <tuple>
#include <bitset>
#include <cfloat>
#include <fstream>
#include <limits.h>
#include <list>
#include <math.h>
#include <random>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <numeric>
#include <utility>
#include <sstream>

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 namespace std;
#define ll long long
#define rep(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i,a,b) for(ll i=(a);i<(b);i++)
#define FORR(i,a,b)for(ll i=(a);i<=(b);i++)
#define repR(i,n) for(ll i=n;i>=0;i--)
#define P pair<ll, ll>
#define sz(x) (ll)x.size()
#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define VE vector<ll>
#define COUT(x) cout<<(x)<<endl
#define MA map<ll,ll>
#define SE set<ll>
#define PQ priority_queue<ll>
#define PQR priority_queue<ll,VE,greater<ll>>
#define COUT(x) cout<<(x)<<endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl

ll gcd(ll a, ll b) {
	if (a < b)swap(a, b);
	if (b == 0) return a;
	return gcd(b, a % b);
}
ll lcm(ll a, ll b) {
	ll g = gcd(a, b);
	return a / g * b;
}
bool prime(ll n) {
	for (ll i = 2; i <= sqrt(n); i++) {
		if (n%i == 0)return false;
	}
	return n != 1;
}


const long long MOD = 1000000007;
const long long INF = 1e9;
const long long LINF = 1LL << 50;
#define int long long

signed main() {
	ios_base::sync_with_stdio(0);
	cin.tie(0);
	int n; cin >> n;
	VE a(n); rep(i, n)cin >> a[i];
	sort(ALLR(a));
	map<int, int>mp;
	rep(i, n) {
		mp[a[i]]++;
	}
	int ans = 0, ans2 = 0;
	rep(i, n) {
		if (mp[a[i]] >= 2) {
			ans = a[i]; mp[a[i]] -= 2;
			break;
		}
	}
	rep(i, n) {
		if (mp[a[i]] >= 2) {
			ans2 = a[i]; break;
		}
	}
	cout << ans * ans2 << endl;
	return 0;
}


Measured memory_bytes: 7296
h,w = map(int,input().split())
n = int(input())
a = list(map(int,input().split()))
color = 1
c = [[''for _ in range(w)]for _ in range(h)]
for i in range(h):
  for j in range(w):
    if a[color-1] == 0:
      color += 1
    c[i][j] = str(color)
    a[color-1] -= 1
for i in range(0,h,2):
  c[i] = c[i][::-1]
for i in range(h):
  print(' '.join(c[i]))

Measured memory_bytes: 3700
n, y = gets.chomp.split.map(&:to_i)

flg = 0
(0..n).each do |i|
  (0..n).each do |j|
    if (9000 * i + 4000 * j == y - 1000 * n) && 0 <= (n - i - j)
      puts "#{i} #{j} #{n - i - j}"
      flg = 1
      break
    end
  end
  break if flg == 1
end

puts '-1 -1 -1' if flg == 0

Measured memory_bytes: 1788
#include<bits/stdc++.h>
using namespace std;
#define rep(i,x,y) for(int i=x;i<y;i++)
#define range(a) (a).begin(),(a).end()
#define print(A,x,n) rep(i,0,n){cout<<(i ? " ":"")<<A[i]x;}cout<<endl;
#define pprint(A,y,m,n) rep(j,0,m){print(A[j],y,n);}
const long mod=1e9+7;
const int size=2e5;
const int inf=1e9;
int main(){
	int N,M;cin>>N>>M;
	int a; int sum = 0;
	rep(i,0,M){ cin>>a; sum += a; }
	if(sum <= N) cout<<N - sum<<endl;
	else cout<<-1<<endl;
}

Measured memory_bytes: 3600
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

int main() {
    ios::sync_with_stdio(false);
    int n, x[102] = {}, y[102] = {}, h[102] = {};
    cin >> n;
    for (int i = 0; i < n; i++) cin >> x[i] >> y[i] >> h[i];
    for (int i = 0; i < n; i++) if (h[i]) swap(x[0], x[i]), swap(y[0], y[i]), swap(h[0], h[i]);
    for (int i = 0; i <= 100; i++) {
        for (int j = 0; j <= 100; j++) {
            int a = abs(i - x[0]) + abs(j - y[0]) + h[0];
            bool w = 0;
            for (int k = 1; k < n; k++) {
                if (max(0, a - abs(i - x[k]) - abs(j - y[k])) != h[k]) w = 1;
            }
            if (w == 0) {
                cout << i << ' ' << j << ' ' << a << '\n';
                return 0;
            }
        }
    }
}


Measured memory_bytes: 3196
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int X,sum;
  cin >> X;
  sum=0;
  int Y=X;
  for (int i=10*10*10*10*10*10*10*10;i>0;i/=10){
    sum += Y/i;
    Y -= Y/i*i;
  }
  if (X % sum==0) {
    cout << "Yes" << endl;
  }
  else
    cout << "No" << endl;
}

Measured memory_bytes: 256
import math

b = [int(e) for e in input().split()]
"""
n=input()
n=int(n)
a=input()
a=int(a)
b=input()
b=int(b)
"""
list = []
for i in range(b[0]+1):
    x=i
    check = 0
    #print(x)
    while(True):
        check=check+x%10
        x=math.floor(x/10)
        #print(x)
        if(x==0):
            break
    if(check>=b[1] and check<=b[2]):
        list.append(i)

print(sum(list))
#print(list)

Measured memory_bytes: 3316
#include <iostream>
#include <iomanip>
typedef long long ll;
using namespace std;
const  ll INF = 1e9;
const  ll MOD = 1e9 + 7;
#define repi(i,n,init) for(ll i=init;i<(n);i++)

int main()
{
    ll a,b;
    cin >> a >> b;
    cout << a * b << endl;
    return 0;
}

Measured memory_bytes: 3624
<?php
  list($n) = explode(" ", trim(fgets(STDIN)));
  
  $ans = 1;
  $max = 0;
  for ($i=0; $i<=$n; $i++) {
    $div2=0;
    $x = $i;
    while($x % 2 == 0 && $x > 1){
      $div2++;
//      echo $x." ";
      $x = $x / 2;
    }
    if($max < $div2){
      $ans = $i;
      $max = $div2;
    }
  }

  echo $ans;


Measured memory_bytes: 16280
#include <iostream>

int main()
{
	int H, W;
	
	while (1) {
		std::cin >> H >> W;
		if (H == 0 && W == 0) {
			break;
		}
		for (int i=0;i < H;i++) {
	for(int n=0;n<W;n++){
		std::cout << "#";
				}
	std::cout << std::endl;
			}
		std::cout <<std::endl;
	}
    return 0;
}

Measured memory_bytes: 3080
#[allow(unused_macros)]
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! input_inner {
    ($next:expr) => {};
    ($next:expr, ) => {};

    ($next:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($next, $t);
        input_inner!{$next $($r)*}
    };
}

#[allow(unused_macros)]
macro_rules! read_value {
    ($next:expr, ( $($t:tt),* )) => {
        ( $(read_value!($next, $t)),* )
    };

    ($next:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()
    };

    ($next:expr, chars) => {
        read_value!($next, String).chars().collect::<Vec<char>>()
    };

    ($next:expr, usize1) => {
        read_value!($next, usize) - 1
    };

    ($next:expr, $t:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        #[cfg(debug_assertions)]
        writeln!(&mut std::io::stderr(), concat!("[DEBUG] ", $(stringify!($a), "={:?} "),*), $($a),*);
    }
}

#[allow(unused_imports)]
use std::cmp::{min, max};

#[allow(unused_imports)]
use std::io::Write;

fn main() {
    input!{
      s: chars,
    }
    let n = s.len();

    let mut t: usize = 1 << 32;
    let mut ok = true;
    for i in 1..n {
        if s[i] != s[i-1] {
            ok = false;
            t = min(t, max(i, n-i));
        }
    }
    if ok {
        println!("{}", s.len());
    } else {
        println!("{}", t);
    }
}


Measured memory_bytes: 4352
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
const ll MOD=1000000007;
const ll INF=1000000000000LL;
const int MAX=100001;
const double EPS=1e-10;
int main(){
    int r,c,n;
    cin>>r>>c>>n;
    stack<int> st;
    vector<pair<int,P>> v1,v2,v3,v4;
    bool f=true;
    for(int i=0;i<n;i++){
        int x[2],y[2];
        cin>>x[0]>>y[0]>>x[1]>>y[1];
        if(((x[0]==0)||(y[0]==0)||(x[0]==r)||(y[0]==c))&&((x[1]==0)||(y[1]==0)||(x[1]==r)||(y[1]==c)));
        else continue;
        for(int j=0;j<2;j++){
            pair<int,P> p;
            if(y[j]==0){
                p=make_pair(x[j],P(i,y[j]));
                v1.push_back(p);
            }else if(x[j]==r){
                p=make_pair(y[j],P(i,x[j]));
                v2.push_back(p);
            }else if(y[j]==c){
                p=make_pair(x[j],P(i,y[j]));
                v3.push_back(p);
            }else if(x[j]==0){
                p=make_pair(y[j],P(i,x[j]));
                v4.push_back(p);
            }
        }
    }
    bool ff[100010]={false};
    sort(v1.begin(),v1.end());sort(v2.begin(),v2.end());sort(v3.begin(),v3.end(),greater<pair<int,P>>());sort(v4.begin(),v4.end(),greater<pair<int,P>>());
    for(const auto& e:v1){
        int idx=e.second.first;
        if(ff[idx]){
            if(st.top()==idx){
                st.pop();
            }else{
                f=false;
                break;
            }
        }else{
            st.push(idx);
            ff[idx]=true;
        }
    }
    for(const auto& e:v2){
        int idx=e.second.first;
        if(ff[idx]){
            if(st.top()==idx){
                st.pop();
            }else{
                f=false;
                break;
            }
        }else{
            st.push(idx);
            ff[idx]=true;
        }
    }
    for(const auto& e:v3){
        int idx=e.second.first;
        if(ff[idx]){
            if(st.top()==idx){
                st.pop();
            }else{
                f=false;
                break;
            }
        }else{
            st.push(idx);
            ff[idx]=true;
        }
    }
    for(const auto& e:v4){
        int idx=e.second.first;
        if(ff[idx]){
            if(st.top()==idx){
                st.pop();
            }else{
                f=false;
                break;
            }
        }else{
            st.push(idx);
            ff[idx]=true;
        }
    }
    if(f){
        cout<<"YES"<<endl;
    }else{
        cout<<"NO"<<endl;
    }
}


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

int main(void)
{
	int a, b, c, d,ans1,ans2,ans3;
	scanf("%d%d%d%d", &a, &b, &c, &d);
	ans1 = abs(b - a);
	ans2 = abs(c - b);
	ans3 = abs(c - a);
	if (ans1 <= d && ans2 <= d)
		printf("Yes");
	else if (ans3 <= d)
		printf("Yes");
	else
		printf("No");
	return 0;
}

Measured memory_bytes: 128
package main

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

var (
	BufferSize = 1000
)

func readLine(sc *bufio.Scanner) string {
	sc.Scan()
	return sc.Text()
}

func scanStr(sc *bufio.Scanner) string {
	if !sc.Scan() {
		panic(nil)
	}
	return sc.Text()
}

func scanInt(sc *bufio.Scanner) int {
	if !sc.Scan() {
		panic(nil)
	}
	i, err := strconv.Atoi(sc.Text())
	if err != nil {
		panic(err)
	}
	return i
}

func main() {
	sc := bufio.NewScanner(os.Stdin)
	buf := make([]byte, BufferSize)
	sc.Buffer(buf, BufferSize)
	sc.Split(bufio.ScanWords)

	n := scanInt(sc)
	s := scanStr(sc)

	ans := "Yes"

	if n%2 != 0 {
		ans = "No"
	} else {
		for i := 0; i < n/2; i++ {
			if s[i] != s[i+n/2] {
				ans = "No"
			}
		}
	}
	fmt.Println(ans)
}


Measured memory_bytes: 640
# -*- coding: utf-8 -*-
import numpy
import sys
from functools import lru_cache
sys.setrecursionlimit(10**6)

h,n=map(int, input().split())  #複数数値入力　「A B」みたいなスペース空いた入力のとき
AB = [tuple(map(int, input().split())) for _ in range(n)]
#効率順にソート
AB.sort(key=lambda ab: (ab[1] / ab[0], ab[0]))

@lru_cache(maxsize=None)
def dp(h):
    if h <= 0:
        return 0
    else:
        best = float('inf')
        for a, b in AB:
            mp = b + dp(h -a)
            if mp < best:
                best = mp
            else:
                break
        return best

print(dp(h))


Measured memory_bytes: 38740
#include <cstdio>
#include <algorithm>
#include <vector>
using namespace std;

int main() {
  int N, M; scanf("%d%d", &N, &M);
  static int wf[20][20];
  for(int i = 0; i < N; i++)
    for(int j = 0; j < N; j++)
      wf[i][j] = 1000000000;
  for(int i = 0; i < M; i++) {
    int a,b,c,d; scanf("%d,%d,%d,%d", &a, &b, &c, &d); a--; b--;
    wf[a][b] = c;
    wf[b][a] = d;
  }
  int s,t,m1,m2; scanf("%d,%d,%d,%d", &s, &t, &m1, &m2); s--; t--;
  for(int k = 0; k < N; k++)
    for(int i = 0; i < N; i++)
      for(int j = 0; j < N; j++)
        wf[i][j] = min(wf[i][j], wf[i][k]+wf[k][j]);
  printf("%d\n", m1-m2-wf[s][t]-wf[t][s]);
  return 0;
}

Measured memory_bytes: 1028
import java.util.Scanner;
 
public class Main {
    public static void main(String[] args) {
    	Scanner sc = new Scanner(System.in);
      int r = sc.nextInt();
    	int g = sc.nextInt();
        int b = sc.nextInt();
    	if ((10*g+b)%4==0) {
    		System.out.println("YES");
    	} else {
    		System.out.println("NO");
    	}
 
    }
}

Measured memory_bytes: 20692
#include "bits/stdc++.h"
using namespace std;

int main() {
    int a,b,res;

    cin >> a >> b;
    if(a >= 13){
        res = b;
    }
    else if (a >= 6 && a <= 12 ){
        res = b/2;
    }
    else if(a < 6){
        res =0;
    }
    

    cout<< res <<endl;
    return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<iostream>
#define LL long long
using namespace std;
const LL mod=1e9+7;
LL f[1010][1010],n,a,b,c,d,C[1010][1010],inv[1010][1010],fac[1010],finv[1010];
void pre()
{
	inv[0][1]=inv[1][1]=1;fac[0]=fac[1]=1;
	for(LL i=2;i<=1000;i++) inv[i][1]=(mod-mod/i)*inv[mod%i][1]%mod,fac[i]=fac[i-1]*i%mod;
	for(LL i=2;i<=1000;i++) inv[i][1]=inv[i-1][1]*inv[i][1]%mod;
	for(LL i=1;i<=1000;i++)
		for(LL j=2;j<=1000;j++) inv[i][j]=inv[i][1]*inv[i][j-1]%mod;
	for(LL i=1;i<=1000;i++)
		for(LL j=1;j<=i;j++) C[i][j]=fac[i]*inv[i-j][1]%mod;
}
LL get(LL x,LL y,LL i) {return C[x][i*y]*inv[y][i]%mod*inv[i][1]%mod;}
LL dfs(LL x,LL y)
{
	if(f[x][y]!=-1) return f[x][y];
	if(x==0) return 1;
	if(y<a) return 0;
	f[x][y]=0;
	for(LL i=c;i<=d;i++)
	{
		LL num=i*y;
		if(num<=x) (f[x][y]+=dfs(x-num,y-1)*get(x,y,i)%mod)%=mod;
		else break;
	}
	(f[x][y]+=dfs(x,y-1))%=mod;
	return f[x][y];
}
int main()
{
	pre();
	scanf("%lld %lld %lld %lld %lld",&n,&a,&b,&c,&d);
	memset(f,-1,sizeof(f));
	printf("%lld",dfs(n,b));
}

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

int M, N, D[255];
vector < int > G[255];
bool visited[255];
bool vim[255];

void visit(int v)
{
    if ( !visited[v] ) {
        visited[v] = true;
        for ( auto &x : G[v] ) {
            visit(x);
        }
    }
}


bool dfs(int v)
{
    bool ret = false;
    if ( !vim[v] ) {
        vim[v] = true;
        if ( v == N + 1 ) return ( true );
        for ( auto &x : G[v] ) {
            ret |= dfs(x);
        }
    }
    return (ret);
}

int main()
{

    while ( cin >> M, M ) {
        cin >> N;
        fill_n(visited, 255, false);
        for ( int i = 0; i < 255; i++ ) {
            while ( !G[i].empty() ) {
                G[i].pop_back();
            }
        }

        for ( int i = 1; i <= N; i++ ) {
            cin >> D[i];
        }
        D[0] = 0, D[N + 1] = 0;

        for ( int i = 0; i <= N + 1; i++ ) {
            for ( int j = 1; j <= M; j++ ) {
                if ( i + j >= N + 1 ) {
                    G[i].push_back(N + 1);
                } else {
                    G[i].push_back(max(0, i + j + D[i + j]));
                }
            }
        }

        visit(0);

        bool possible = true;
        for ( int i = 0; i <= N + 1; i++ ) {
            if ( visited[i] ) {
                fill_n(vim, 255, false);
                possible &= dfs(i);
            }
        }

        if ( possible ) {
            cout << "OK" << endl;
        } else {
            cout << "NG" << endl;
        }
    }

    return ( 0 );
}



Measured memory_bytes: 3160
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
const long long int sMod = 998244353;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define fi first
#define se second
#define all(x) (x).begin(),(x).end()
#define rp(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

void solve(){
    ll n;
    ll l;
    cin >> n >> l;
    if(l>=0) print((l+l+n-1)*n/2-l);
    else if(l+n-1>=0) print((l+l+n-1)*n/2);
    else print((l+l+n-1)*n/2-(l+n-1));
    return;
}
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    std::cout<<std::fixed<<std::setprecision(30);
    solve();
    return 0;
}

Measured memory_bytes: 3612
#リストの準備
list=[]
for i in range(5):
  list.append(int(input()))
#料理出てくる時間の1の位を切り上げたリストの作成
import math
list2=[]
for i in range(5):
  list2.append(int(math.ceil(list[i]*0.1)*10))

#4つ目までは、list2の要素を単純に足せばいい。
#最後の1つは、切り上げ前後の差が最も大きいものをlistから選ぶようにする。
#つまり、5つ目まで単純に足し、最後に↑の差を引く。

#最大の差を算出：
def d(j):
  return list2[j]-list[j]
max=max(d(0),d(1),d(2),d(3),d(4))

#list2の総和-最大の差
print(sum(list2)-max)

Measured memory_bytes: 3064
#include <stdio.h>
#include <string.h>

int main(void)
{
    int k,a,b;
    int flag=0;

    scanf("%d",&k);
    // printf("k=%d\n",k);
    scanf("%d %d",&a,&b);
    // printf("a=%d b=%d\n",a,b);
    // printf("flag=%d\n",flag);

    for (int i=1;i<=1000;i++){
        if (k*i>=a && k*i<=b){
            // printf("i=%d %d\n",i,k*i);
            flag=1;
            break;
        }
    }

    if (flag==1)
        printf("OK");
    else
        printf("NG");
    
    return 0;
    

}

Measured memory_bytes: 1700
using System;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using static System.Math;

namespace Traveling
{
    class Program
    {
        public static void Main(string[] args)
        {
            using (var sc = new SetConsole())
            {
                int n = GetString().ToInt();
                var ts = new List<int[]>
                {
                    new int[] { 0, 0, 0 }
                };
                for (int i = 1; i <= n; i++)
                {
                    ts.Add(GetArray<int>());
                }
                for (int i = 1; i <= n; i++)
                {
                    if (Abs(ts[i][0] - ts[i - 1][0]) < Abs(ts[i][1] - ts[i - 1][1]) + Abs(ts[i][2] - ts[i - 1][2]))
                    {
                        CWrite("No");
                        return;
                    }
                    if (ts[i][0] % 2 != (ts[i][1] + ts[i][2]) % 2)
                    {
                        CWrite("No");
                        return;
                    }
                }
                CWrite("Yes");
            }
        }

        static void CWrite<T>(T str) => Console.WriteLine(str);
        static string GetString() => Console.ReadLine();
        static T[] GetArray<T>()
        {
            var t = typeof(T);
            var str = Console.ReadLine();
            if (t == typeof(string))
            {
                return (T[])(object)str.Split();
            }
            if (t == typeof(int))
            {
                return (T[])(object)str.ToNumArray<T>();
            }
            if (t == typeof(long))
            {
                return (T[])(object)str.ToNumArray<T>();
            }
            if (t == typeof(double))
            {
                return (T[])(object)str.ToNumArray<T>();
            }
            throw new NotSupportedException($"{t} is not supported.");
        }
    }



    class SetConsole : IDisposable
    {
        readonly StreamWriter sw = new StreamWriter(Console.OpenStandardOutput());
        public SetConsole()
        {
            sw.AutoFlush = false;
            Console.SetOut(sw);
        }
        public void Dispose()
        {
            Console.Out.Flush();
            sw.AutoFlush = true;
            Console.SetOut(sw);
        }
    }

    static class ExtentionsLibrary
    {
        public static T[] ToNumArray<T>(this string str)
        {
            var t = typeof(T);
            if (t == typeof(int))
            {
                return (T[])(object)str.Split().Select(int.Parse).ToArray();
            }
            if (t == typeof(long))
            {
                return (T[])(object)str.Split().Select(long.Parse).ToArray();
            }
            if (t == typeof(double))
            {
                return (T[])(object)str.Split().Select(double.Parse).ToArray();
            }
            throw new NotSupportedException();
        }
        public static int ToInt(this string str) => int.Parse(str);
    }
}


Measured memory_bytes: 25532
using System;
using System.Linq;

namespace atcoderA
{
    class Program
    {
        static void Main(string[] args)
        {
            var input = Console.ReadLine().Split(' ');
            int x = int.Parse(input[0]);
            int y = int.Parse(input[1]);
            Console.WriteLine(getN(x) == getN(y) ? "Yes" : "No");
        }

        public static int getN(int a)
        {
            int[] array = new int[] { 4, 6, 9, 11 };
            int group = 0;
            if (a == 2)
            {
                group = 1;
            }
            else if (array.Contains(a))
            {
                group = 2;
            }
            else
            {
                group = 3;
            }
            return group;
        }
    }
}

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

int main(){
	long long n;
	cin >> n;
	long long sum = 0;
	for(long long i=0; i <= n; i++){
		if(i%5==0 || i%3 == 0){
			continue;
		}else{
			sum += i;
		}
	}
	cout << sum << endl;
	return 0;
}


Measured memory_bytes: 3592
// #pragma GCC target("avx")  // CPU 処理並列化
// #pragma GCC optimize("O3")  // CPU 処理並列化
// #pragma GCC optimize("unroll-loops")  // 条件処理の呼び出しを減らす
// #define BEGIN_STACK_EXTEND(size) void * stack_extend_memory_ = malloc(size);void * stack_extend_origin_memory_;char * stack_extend_dummy_memory_ = (char*)alloca((1+(int)(((long long)stack_extend_memory_)&127))*16);*stack_extend_dummy_memory_ = 0;asm volatile("mov %%rsp, %%rbx\nmov %%rax, %%rsp":"=b"(stack_extend_origin_memory_):"a"((char*)stack_extend_memory_+(size)-1024));
// #define END_STACK_EXTEND asm volatile("mov %%rax, %%rsp"::"a"(stack_extend_origin_memory_));free(stack_extend_memory_);

#include<stdio.h>
#include<math.h>
#include<algorithm>
#include<queue>
#include<deque>
#include<stack>
#include<string>
#include<string.h>
#include<vector>
#include<set>
#include<map>
#include<bitset>
#include<stdlib.h>
#include<cassert>
#include<time.h>
#include<bitset>
#include<numeric>
#include<unordered_set>
#include<unordered_map>
#include<complex>
using namespace std;
const long long mod=1000000007;
const long long inf=mod*mod;
const long long d2=(mod+1)/2;
const double EPS=1e-9;
const double INF=1e+10;
const double PI=acos(-1.0);
const int C_SIZE = 3100000;
const int UF_SIZE = 3100000;
namespace{
	long long fact[C_SIZE];
	long long finv[C_SIZE];
	long long inv[C_SIZE];
	inline long long Comb(int a,int b){
	 	if(a<b||b<0)return 0;
	 	return fact[a]*finv[b]%mod*finv[a-b]%mod;
	}
	void init_C(int n){
		fact[0]=finv[0]=inv[1]=1;
		for(int i=2;i<n;i++){
			inv[i]=(mod-(mod/i)*inv[mod%i]%mod)%mod;
		}
		for(int i=1;i<n;i++){
			fact[i]=fact[i-1]*i%mod;
			finv[i]=finv[i-1]*inv[i]%mod;
		}
	}
	long long pw(long long a,long long b){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%mod;
			a=a*a%mod;
			b/=2;
		}
		return ret;
	}
	long long pw_mod(long long a,long long b,long long M){
		if(a<0LL)return 0;
		if(b<0LL)return 0;
		long long ret=1;
		while(b){
			if(b%2)ret=ret*a%M;
			a=a*a%M;
			b/=2;
		}
		return ret;
	}
	int pw_mod_int(int a,int b,int M){
		if(a<0)return 0;
		if(b<0)return 0;
		int ret=1;
		while(b){
			if(b%2)ret=(long long)ret*a%M;
			a=(long long)a*a%M;
			b/=2;
		}
		return ret;
	}
	int ABS(int a){return max(a,-a);}
	long long ABS(long long a){return max(a,-a);}
	double ABS(double a){return max(a,-a);}
	int sig(double r) { return (r < -EPS) ? -1 : (r > +EPS) ? +1 : 0; }
	int UF[UF_SIZE];
	void init_UF(int n){
		for(int i=0;i<n;i++)UF[i]=-1;
	}
	int FIND(int a){
		if(UF[a]<0)return a;
		return UF[a]=FIND(UF[a]);
	}
	void UNION(int a,int b){
		a=FIND(a);b=FIND(b);if(a==b)return;
		// if(UF[a]>UF[b])swap(a,b);
		UF[a]+=UF[b];UF[b]=a;
	}
}
// ここから編集しろ

int main(){
	int a,b,c,d;
	scanf("%d%d%d%d",&a,&b,&c,&d);
	while(1){
		c-=b;
		if(c<=0){
			printf("Yes\n");
			break;
		}
		a-=d;
		if(a<=0){
			printf("No\n");
			break;
		}
	}
}

Measured memory_bytes: 1620
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0;i<(n);i++)
#define FOR(i,s,e) for (int i=s;i<(e);i++)
#define All(v) (v).begin(),(v).end()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
using namespace std;
typedef long long llint;
typedef pair<int, int> P;
const int MOD = (int)1e9 + 7;
const int INF = 999999999;

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

    int N;
    cin >> N;
    REP(i,25){
        REP(j,20){
            if(N == 4*(i)+7*(j)){
                cout << "Yes\n";
                return 0;
            }
        }
    }
    cout << "No\n";
    return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10 ** 7)

import numpy as np

# 使った建物の番号集合ごとに、右端の高さと総コストを持つ：一意

N,K = map(int,input().split())
A = [int(x) for x in input().split()]

L = 1<<N
right = np.zeros(L,dtype=np.int64)
total = np.zeros(L,dtype=np.int64)

for i,a in enumerate(A):
    bit = 1<<i
    right[bit:2*bit] = np.maximum(right[:bit]+1,a)
    np.maximum(right[:bit],a,out=right[:bit])
    total[bit:2*bit] = (right[bit:2*bit] - a) + total[:bit]

popcount = np.zeros(L,dtype=np.int32)
rng = np.arange(L)
for _ in range(15):
    popcount += rng&1
    rng >>= 1

answer = total[popcount >= K].min()
print(answer)



Measured memory_bytes: 21572
# import numpy as np
N=int(input())
L=list(map(int, input().split()))
L.sort()
ans=0
for i in range(N-2):
    k=i+2
    for j in range(i+1,N-1):
        l=L[i]+L[j]
        while(L[k]<l):
#           print(i,j,k)
            k+=1
            if k==N:
                break
        k-=1
        ans+=k-j
print(ans)    

Measured memory_bytes: 3188
//hi
#include<bits/stdc++.h>
using namespace std;
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define inf 10000000000000000LL
typedef long long int LL;
LL s[2004];
LL mr[2004][2004];
int main(void){
    int n;
    LL x;
    scanf("%d%lld",&n,&x);
    int i,j;
    for(i=0;i<n;i++) scanf("%lld",&s[i]);
    for(i=0;i<n;i++)
		for(j=0;j<n;j++)
			mr[i][j]=inf;
    for(i=0;i<n;i++){
		mr[i][0]=s[i];
		for(j=1;j<n;j++){
			mr[i][j]=mr[i][j-1];
			mr[i][j]=min(mr[i][j],s[(i-j+n)%n]);
		}
	}
    LL tot=inf;
    int mx;
    for(mx=0;mx<n;mx++){
		LL sum=0;
		for(i=0;i<n;i++) sum+=mr[i][mx];
		sum+=x*mx;
		tot=min(tot,sum);
	}
	printf("%lld\n",tot);
    return 0;
}


Measured memory_bytes: 31616
N = int(input())
A = list(map(int, input().split()))
cnt = 0
for i in range(N-1):
  if A[i] > A[i+1]:
    cnt += A[i] - A[i+1]
    A[i+1] += A[i] - A[i+1]
    
print(cnt)
    

Measured memory_bytes: 94180
#include <iostream>
#include <vector>
#include <utility>
#include <map>
#include <unordered_map>
#include <queue>
#include <numeric>
#include <algorithm>

using namespace std;

using int64 = long long;
using P = pair<int,int>;
using TP = tuple<int,int,int>;

struct edge {
    long u,v,cost;
    edge(long _u, long _v, long _cost): u(_u), v(_v), cost(_cost){}
};

class unionfind {
    vector<int64> _size;
    vector<int64> _root;
public:
    unionfind(int n) {
        _size = vector<int64> (n+1, 1);
        _root = vector<int64> (n+1);
        iota(_root.begin(), _root.end(), 0);
    }
    int64 root(int x) {
        while(x != _root[x]) x = _root[x];
        return x;
    }
    bool merge(int x, int y) {
        if (is_same(x,y)) return false;
        x = root(x); y = root(y);
        if (_size[x] > _size[y]) swap(x,y);
        _size[y] += _size[x];
        _root[x] = y;
        return true;
    }
    int64 is_same(int x, int y) {
        return root(x) == root(y);
    }
    int64 size(int x) {
        return _size[root(x)];
    }
};

int64 kruskal(const int& n,vector<edge>& edges) {

    auto cmp = [](edge x, edge y) {return x.cost < y.cost;};
    sort(edges.begin(), edges.end(), cmp);
    unionfind uni(n);
    int res = 0;
    for (auto e : edges) {
        if (uni.is_same(e.u , e.v)) continue;
        uni.merge(e.u, e.v);
        res += e.cost;
    }

    return res;
}

int main() {
    int n;
    cin >> n;
    vector<TP> p;
    for (int i=1; i<=n; i++) {
        int x,y;
        cin >> x >> y;
        p.emplace_back(x, y, i);
    }


    sort(p.begin(), p.end());

    vector<edge> edges;
    for (int i=0; i<n-1; i++) {
        int x1,y1,u;
        tie(x1, y1, u) = p[i];
        int x2,y2,v;
        tie(x2, y2, v) = p[i+1];
        edges.emplace_back(u,v, abs(x1 - x2));
    }

    auto cmp = [](TP x, TP y) {return get<1>(x) < get<1>(y);};
    sort(p.begin(), p.end(), cmp);

    for (int i=0; i<n-1; i++) {
        int x1,y1,u;
        tie(x1, y1, u) = p[i];
        int x2,y2,v;
        tie(x2, y2, v) = p[i+1];
        edges.emplace_back(u, v, abs(y1 - y2));

    }


    int ans = kruskal(n, edges);

    cout << ans << endl;

}

Measured memory_bytes: 9456
import fractions
a,b,c,d=map(int,input().split())
def lcm(x, y):
    return (x * y) // fractions.gcd(x, y)
e=lcm(c,d)
cc=b//c-(a-1)//c
dd=b//d-(a-1)//d
ee=b//e-(a-1)//e
print(b-a-cc-dd+ee+1)

Measured memory_bytes: 77528
import java.util.*;

public class Main {

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

	public void execute() {
		Scanner sc = new Scanner(System.in);
		final int N = sc.nextInt();

		int[] ameUe = new int[N];
		int[] ameShita = new int[N];
		for (int i = 0; i < N; i++) {
			int a1i = sc.nextInt();
			if (i > 0) {
				ameUe[i] = ameUe[i - 1] + a1i;
			} else {
				ameUe[i] = a1i;
			}
		}

		for (int i = 0; i < N; i++) {
			int a2i = sc.nextInt();
			if (i > 0) {
				ameShita[i] = ameShita[i - 1] + a2i;
			} else {
				ameShita[i] = a2i;
			}
		}

		int maxAme = 0;
		for (int i = 0; i < N; i++) {
			int ame;
			if (i == 0) {
				ame = ameUe[0] + ameShita[N - 1];
			} else {
				ame = ameUe[i] + ameShita[N - 1] - ameShita[i - 1];
			}
			maxAme = Math.max(maxAme, ame);
		}

		System.out.println(maxAme);
		sc.close();
	}

}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005

int main() {
    int x, y;
    cin >> x >> y;

    int ans = 0;

    if(abs(x) < abs(y)){
        if(0 <= x){
            ans = abs(y) - abs(x);
            if(y < 0)ans++;
        }else{
            ans = 1;
            ans += abs(y) - abs(x);
            if(y < 0)ans++;
        }
    }else if(abs(x) > abs(y)){
        if(x >= 0){
            ans = 1;
            ans += abs(x) - abs(y);
            if(y > 0)ans++;
        }else{
            ans += abs(x) - abs(y);
            if(y > 0)ans++;
        }
    }else{
        ans = 1;
    }


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


Measured memory_bytes: 256
n = int(input())
A = list(map(int, input().split()))
from itertools import accumulate
B = [0]+A
B = list(accumulate(B))

d = {}
ans = 0
for i in range(n+1):
  if B[i] not in d:
    d[B[i]] = 1
  else:
    ans += d[B[i]]
    d[B[i]] += 1
    
print(ans)

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

int main(int argc, char const *argv[]) {
    int H,W;
    std::cin >> H >> W;
    char a[H][W];
    for (size_t i = 0; i < H; i++) {
        for (size_t j = 0; j < W; j++) {
            std::cin >> a[i][j];
        }
    }
    std::string upper_frame(W+2,'#');
    std::cout << upper_frame << '\n';
    for (size_t i = 0; i < H; i++) {
        std::cout << "#";
        for (size_t j = 0; j < W; j++) {
            std::cout << a[i][j];
        }
        std::cout << "#" << '\n';
    }
    std::cout << upper_frame << '\n';

    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
 
typedef long long ll;
typedef pair<int, int> P;
 
#define mod 1000000007
#define inf 1000000000
#define all(x) (x).begin(), (x).end()
#define pb push_back
#define popcount(x) __builtin_popcountll(x)
 
const long double PI = acos(-1);
 
ll gcd(ll a,ll b){return b ? gcd(b,a%b) : a;}
ll lcm(ll a,ll b){return a / gcd(a,b) * b;}
 
int main(){
  ll a = 0, b = 0;
  for(ll i = 0; i < 3; i++){
    char c = 0;
    cin >> c;
    if(c == 'A') a++;
    else b++;
  }
  if(a == 3 || b == 3) cout << "No" << endl;
  else cout << "Yes" << endl;
}

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

int main() {
  string s;
  cin >> s;
  vector<bool> app(26);
  rep(i, 26) app[i] = false;
  rep(i, s.size()) app[s[i] - 'a'] = true;
  string ans = "";
  rep(i, 26) if(!app[i]) {
    ans = i + 'a';
    cout << ans << endl;
    return 0;
  }
  
  cout << "None" << endl;
  return 0;
}

Measured memory_bytes: 3752
#include <bits/stdc++.h>
using namespace std;
using ll=long long;
#define rep(i,n) for(int i=0;i<n;i++)
int main() {
  int n;
  cin>>n;
  vector<vector<int>>l(n);
  rep(i,n){
    int a;
    cin>>a;
    rep(j,a){
      int x,y;
      cin>>x>>y;
      l[i].push_back(x);
      l[i].push_back(y);
    }
  }
  int ans=0;
  for(int tmp=0;tmp<(1<<15);tmp++){
    bitset<15>t(tmp);
    int tans=0;
    bool check=true;
    for(int i=0;i<n;i++){
      if(t.test(i)){
        tans++;
        for(int j=0;j<l[i].size();j+=2){
          if(l[i][j+1]==1 && (!t.test(l[i][j]-1))) check=false;
          if(l[i][j+1]==0 && (t.test(l[i][j]-1))) check=false;
        }
      }
    }
    if(check) ans=max(ans,tans);
  }
  cout<<ans<<endl;
}

Measured memory_bytes: 3532
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define rep2(i,x,n) for(int i=x; i<(n); i++)
#define ALL(c) (c).begin(), (c).end()
#define pb push_back
#define eb emplace_back
using namespace std;
const long long INF = 1LL<<60; // 仮想的な無限大の値;
using ll = long long;
using P  = pair<int, int>;
#define vi vector<int>
#define vll vector<ll>
#define vs vector<string>
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; }

int main()
{
    int s, t;
    cin >> s >> t;
    if(s <= t)
    {
        cout << "unsafe\n";
    }
    else
    {
        cout << "safe\n";
    }
    
    return 0;
}

Measured memory_bytes: 3596
def gcd(a, b):
    (x, lastx) = (0, 1)
    (y, lasty) = (1, 0)
    while b != 0:
        q = a // b
        (a, b) = (b, a % b)
        (x, lastx) = (lastx - q * x, x)
        (y, lasty) = (lasty - q * y, y)
    return a

N=int(input())
a=list(map(int,input().split()))

l=[0]*N
l[0]=a[0]
for i in range(1,N):
    l[i]=gcd(l[i-1],a[i])

r=[0]*N
r[N-1]=a[N-1]
for i in range(N-2,-1,-1):
    r[i]=gcd(r[i+1],a[i])

ans=max(r[1],l[N-2])
for i in range(1,N-1):
    tmp=gcd(l[i-1],r[i+1])
    ans=max(tmp,ans)

print(ans)

Measured memory_bytes: 14052
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<cstring>
#include<cstdlib>
#include<utility>
#include<map>
#include<vector>
#include<stack>
#include<queue>
#define loop(i,a,b) for(int i=a;i<b;i++)
#define rep(i,a) loop(i,0,a)
#define pi acos(-1)
#define pb push_back
#define all(v) v.begin(),v.end()
using namespace std;
typedef pair<int,int> p;
typedef long long ll;

int main(){
	ll x,y;
	cin>>x>>y;
	ll cnt=0;
	while(x<=y){
		cnt++;
		x*=2;
	}
	cout<<cnt<<endl;
	return 0;
}

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

int main()
{
    ll x; cin >> x;
    
    ll ans = 0;

    ans += x / 500 * 1000;

    ll mod500 = x % 500;

    ans += mod500 / 5 * 5;

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

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    int a, b, c;
    cin >> a >> b >> c;
    if (c >= a && c <= b) {
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }
    return 0;
}


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

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

using namespace std;

int main(){
	int n,h,w; scanf("%d%d%d",&n,&h,&w);
	printf("%d\n",(n-h+1)*(n-w+1));
	return 0;
}


Measured memory_bytes: 3744
#include <bits/stdc++.h>
using namespace std;
using ll = long long int;
using str = string;
using P = pair<int, int>;
using Pll = pair<ll, ll>;
const double PI = 3.141592653589793238;
const ll mod = 1000000007;
#define rep(i, n) for (int i = 0; i < (int)n; i++)
#define REP(i, m, n) for (int i = m; i < (int)n; i++)
#define all(a) (a).begin(), (a).end()
#define allg(a) (a).begin(), (a).end(), greator<>()
#define d20 std::setprecision(20)
#define veci vector<int>
#define vecll vector<long long int>
#define vecd vector<double>
template <typename T>
T lcm(T a, T b)
{
	return a / __gcd(a, b) * b;
}
void comb(vector<vector<long long int>> &v)
{
	for (int i = 0; i < v.size(); i++)
	{
		v[i][0] = 1;
		v[i][i] = 1;
	}
	for (int k = 1; k < v.size(); k++)
	{
		for (int j = 1; j < k; j++)
		{
			v[k][j] = (v[k - 1][j - 1] + v[k - 1][j]);
		}
	}
}
bool is_not_out_of_range(size_t now, size_t max_num)
{
	return !(now < 0 || max_num <= now);
}

int main()
{
	int n;
	cin >> n;
	vector<pair<pair<str, int>, int>> v(n);

	rep(i, n)
	{
		str s;
		int p;
		cin >> s >> p;
		v[i] = make_pair(make_pair(s, -p), i + 1);
	}
	sort(all(v));
	rep(i, n)
	{
		cout << v[i].second << endl;
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define endl "\n"
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

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

const long long INF = 1e18;
//const ll mod = 1000000007;
ll N;
vector<ll> V, W;
ll K = 10;
vector<l_l> mid[1 << 18];

vector<l_l> f(vector<l_l> a) {
    vector<l_l> tmp;
    int n = a.size();
    for(int i = 0; i < (1 << n); i++) {
        l_l now;
        for(int j = 0; j < n; j++) {
            if(!(i & (1 << j))) continue;
            now.first += a[j].second;
            now.second += a[j].first;
        }
        tmp.push_back(now);
    }
    sort(tmp.begin(), tmp.end(), [](l_l a, l_l b) {
        if(a.first != b.first) return a.first < b.first;
        return a.second > b.second;
    });
    vector<l_l> ret;
    for(auto a : tmp) {
        if(ret.size() and ret.back().second >= a.second) continue;
        ret.push_back(a);
    }
    return ret;
}

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> N;
    V.resize(N + 1);
    W.resize(N + 1);
    for(int i = 1; i <= N; i++) {
        cin >> V[i] >> W[i];
    }
    for(int i = 1; i <= N; i++) {
        if(i >= (1 << (K - 1)) and i < (1 << (K))) {
            //cerr << "---" << i << "---" << endl;
            vector<l_l> v;
            ll copy = i;
            while(copy != 0) {
                v.push_back({V[copy], W[copy]});
                copy /= 2;
            }
            mid[i] = f(v);
            for(auto tmp : mid[i]) {
                //cerr << tmp.first << " " << tmp.second << endl;
            }
        }
    }
    int Q;
    cin >> Q;
    while(Q--) {
        ll x, L;
        cin >> x >> L;
        if(x < (1 << K)) {
            ll copy = x;
            vector<l_l> v;
            while(copy != 0) {
                v.push_back({V[copy], W[copy]});
                copy /= 2;
            }
            vector<l_l> w = f(v);
            ll ans = 0;
            for(auto tmp : w) {
                if(tmp.first <= L) chmax(ans, tmp.second);
            }
            cout << ans << endl;
        } else {
            ll copy = x;
            vector<l_l> v;
            while(copy >= (1 << K)) {
                v.push_back({V[copy], W[copy]});
                copy /= 2;
            }
            auto w = f(v);
            auto q = mid[copy];
            ll ans = 0;
            for(auto tmp : w) {
                l_l s = {L - tmp.first + 1, -INF};
                auto itr = lower_bound(q.begin(), q.end(), s);
                if(itr == q.begin()) continue;
                itr--;
                chmax(ans, tmp.second + (*itr).second);
            }
            cout << ans << endl;
        }
    }
    return 0;
}


Measured memory_bytes: 21820
#include <bits/stdc++.h>
using namespace std;
int main() {
  int n, m;
  cin >> n >> m;

  int tmp;
  int A[n][m] = {0};
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < m; j++) {
      cin >> tmp;
      A[i][j] = tmp;
    }
  }
  int b[m] = {0};
  for (int j = 0; j < m; j++) {
    cin >> tmp;
    b[j] = tmp;
  }
  for (int i = 0; i < n; i++) {
    int answer = 0;
    for (int j = 0; j < m; j++) {
      answer += A[i][j] * b[j];
    }
    cout << answer << endl;
  }
  return 0;
}



Measured memory_bytes: 3100
#include<bits/stdc++.h>
using namespace std;
#define fast {ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);}
typedef long long int ll;
typedef string S;
#define M 1e18
#define AS 250005
#define sp cout<<' '
#define nw cout<<endl
#define rt return
#define __ template<typename T, typename... Types>
void in() {rt;} __ void in(T &a, Types&... b){cin>>(a); in(b...);}
void o() {rt;}  __ void o(T a, Types... b){cout<<(a);sp; o(b...);}
#define fr(i,a,n) for(ll i=a;i<=n;i++)
#define frm(i,a,n) for(ll i=n;i>=a;i--)
#define P pair<ll,ll>
#define vc vector<ll>
#define pb push_back
#define MP map<ll,ll>
bool sortin(const pair<ll,ll> &e,const pair<ll,ll> &f){return (e.first<f.first);}
bool POT(ll x){return x && (!(x&(x-1)));}
ll i,j,k,l,m,n,p,q,r,a,b,c,d,x,y,z,ts,mn=1e18,mod=1e9+7;
ll ar[AS],br[AS],xr[AS],tem[AS];
int main()
{
    fast;
    in(a,b,c,d);
    m=-M;
    m=max(m,a*c);
    m=max(m,a*d);
    m=max(m,b*c);
    m=max(m,b*d);
    if(a<=0 and b>=0)m=max(m,0LL);
    if(c<=0 and d>=0)m=max(m,0LL);
    o(m);
}



Measured memory_bytes: 3648
n = int(input())
h = list(map(int,input().split()))

dp = [0 for _ in range(100010)]
dp[1] = abs(h[0]-h[1])

for i in range(2,len(h)):
        dp[i] = min(abs(h[i]-h[i-2])+dp[i-2],abs(h[i]-h[i-1])+dp[i-1])
print(dp[n-1])


Measured memory_bytes: 13976