akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
using ll = long long;
using P = pair<int, int>;
/*
struct Edge
{
    int to;
    int weight;
    Edge(int t, int w) : to(t), weight(w) {}
};
using Graph = vector<vector<Edge>>;
*/
using Graph = vector<vector<int>>;

const long long INF = 1LL << 60;
const int INT_INF = 1000000000;

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

const int mod = 1000000007;
struct mint
{
    ll x; // typedef long long ll;
    mint(ll x = 0) : x((x % mod + mod) % mod) {}
    mint operator-() const { return mint(-x); }
    mint &operator+=(const mint a)
    {
        if ((x += a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator-=(const mint a)
    {
        if ((x += mod - a.x) >= mod)
            x -= mod;
        return *this;
    }
    mint &operator*=(const mint a)
    {
        (x *= a.x) %= mod;
        return *this;
    }
    mint operator+(const mint a) const { return mint(*this) += a; }
    mint operator-(const mint a) const { return mint(*this) -= a; }
    mint operator*(const mint a) const { return mint(*this) *= a; }
    mint pow(ll t) const
    {
        if (!t)
            return 1;
        mint a = pow(t >> 1);
        a *= a;
        if (t & 1)
            a *= *this;
        return a;
    }

    // for prime mod
    mint inv() const { return pow(mod - 2); }
    mint &operator/=(const mint a) { return *this *= a.inv(); }
    mint operator/(const mint a) const { return mint(*this) /= a; }
};
istream &operator>>(istream &is, const mint &a) { return is >> a.x; }
ostream &operator<<(ostream &os, const mint &a) { return os << a.x; }

struct combination
{
    vector<mint> fact, ifact;
    combination(int n) : fact(n + 1), ifact(n + 1)
    {
        assert(n < mod);
        fact[0] = 1;
        for (int i = 1; i <= n; ++i)
            fact[i] = fact[i - 1] * i;
        ifact[n] = fact[n].inv();
        for (int i = n; i >= 1; --i)
            ifact[i - 1] = ifact[i] * i;
    }
    mint operator()(int n, int k)
    {
        if (k < 0 || k > n)
            return 0;
        return fact[n] * ifact[k] * ifact[n - k];
    }
    mint p(int n, int k)
    {
        return fact[n] * ifact[n - k];
    }
} c(1000005);

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int N;
    cin >> N;
    if (N == 1)
    {
        cout << 0 << endl;
        return 0;
    }
    mint base1 = 10, base2 = 9, base3 = 8;
    mint ans = base1.pow(N) - base2.pow(N) - base2.pow(N) + base3.pow(N);
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 18600
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
#include <vector>
#include <utility>
#include <cstring>
#include <iomanip>
#include <numeric>
#include <cmath>
#include <cassert>
using namespace std;
using ll = long long;
const int INF = 1<<30;
const int MOD = 1e9 + 7;
signed main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n; cin >> n;
    string s; cin >> s;
    int R = 0, B = 0;
    for(int i = 0; i < s.size(); i++)
    {
        if(s[i] == 'R') R++;
        else B++;
    }
    cout << (R > B ? "Yes" : "No") << endl;
    return 0;
}



Measured memory_bytes: 256
#累積和　AGC023
from collections import Counter
from math import factorial
def nC2(n):
    if n >= 2:
        return factorial(n) // (factorial(n-2)*factorial(2))
    else:
        return 0
N = int(input())
A = list(map(int,input().split()))
B = [0]
ans = 0
for i in range(N):
    B.append(A[i] + B[i])
C =Counter(B)

for v in C.values():
    ans += nC2(v)
print(ans)

Measured memory_bytes: 113096
N = int(input())
cord_list = [[0, 0, 0]]
flag = 0
    
for j in range(N):
    cord_list.append(list(map(int, input().split())))
    a = cord_list[j+1][0] - cord_list[j][0]
    b = abs(cord_list[j+1][1] - cord_list[j][1])
    c = abs(cord_list[j+1][2] - cord_list[j][2])
    if ((a - (b+c))%2 ==0) & ((b+c) <= a):
        pass
    else:
        print("No")
        flag += 1
        break
        
if flag == 0:
    print("Yes")

Measured memory_bytes: 27300
#include<stdio.h>
#include<string.h>
int main()
{
int i;
int n[100];
int a,b;
scanf("%d",&a);
for(i=0;i<a;i++)
{
scanf("%d",&b);
n[i]=b;
}
for(i=a-1;i>=0;i--)
{
printf("%d",n[i]);
if(i!=0)
{
printf(" ");
}
}
printf("\n");
return 0;
}

Measured memory_bytes: 2696
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For(i, 0, n)
#define rrep(i, n) rFor(i, n, 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1000000007;
constexpr lint INF = mod * mod;
constexpr int MAX = 100010;

typedef struct UnionFindTree{
    vector<int> par;

    UnionFindTree(int n){
        par.resize(n, -1);
    }

    bool is_root(int x){
        return par[x]<0;
    }

    int find(int x){
        if(is_root(x)) return x;
        return par[x] = find(par[x]);
    }

    int size(int x){
        return -par[find(x)];
    }

    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        if(x == y) return false;
        if(size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        return true;
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
}UF;

int n, c;
int dx[6] = {-1, -1, 0, 1, 1, 0};
int dy[6] = {-1, 0, 1, 1, 0, -1};

void solve(){
    int s[n][n];
    rep(i, n)rep(j, i + 1) scanf("%d", &s[i][j]);
    int ans = -mod;
    rep(x, n)rep(y, x + 1)if(s[x][y] == 0){
        s[x][y] = c;

        UF uf(n * n);
        rep(tx, n)rep(ty, tx + 1){
            rep(i, 6){
                int nx = tx + dx[i], ny = ty + dy[i];
                if(0 <= nx && nx < n && 0 <= ny && ny <= nx && s[nx][ny] == s[tx][ty]){
                    uf.unite(tx * n + ty, nx * n + ny);
                }
            }
        }
        bool surrounded[n * n];
        rep(i, n * n) surrounded[i] = true;
        rep(tx, n)rep(ty, tx + 1){
            rep(i, 6){
                int nx = tx + dx[i], ny = ty + dy[i];
                if(0 <= nx && nx < n && 0 <= ny && ny <= nx && s[nx][ny] == 0){
                    surrounded[uf.find(tx * n + ty)] = false;
                }
            }
        }

        int tmp = 0;
        rep(tx, n)rep(ty, tx + 1)if(s[tx][ty] != 0 && uf.is_root(tx * n + ty) && surrounded[tx * n + ty]){
            if(s[tx][ty] == c) tmp -= uf.size(tx * n + ty);
            else tmp += uf.size(tx * n + ty);
        }
        chmax(ans, tmp);

        s[x][y] = 0;
    }
    printf("%d\n", ans);
}

int main(){
    while(scanf("%d%d", &n, &c) && n){
        solve();
    }
}


Measured memory_bytes: 3160
#include <iostream>
#include <vector>
#include <algorithm>

using namespace std;

int main(){

	int n;
	int alice=0, bob=0;
	cin >> n;

	vector<int> card(n);

	for(int i=0;i<n;i++){
		int t;
		cin >> t;
		card.push_back(t);
	}

	vector<int>::iterator itr;

	for(int i=0;i<n;i++){
		if(i%2==0){
			itr = max_element(card.begin(), card.end());
			alice += *itr;
			card.erase(itr);
		}

		if(i%2==1){
			itr = max_element(card.begin(), card.end());
			bob += *itr;
			card.erase(itr);
		}
	}

	cout << alice-bob << endl;

	return 0;
}


Measured memory_bytes: 256
n,m=map(int,input().split())
ac=[0]*n
pena=[0]*n
for i in range(m):
  p,s=input().split()
  p=int(p)
  if ac[p-1]==0:
    if s=="AC":
      ac[p-1]=1
      LAC=i
    if s=="WA":
      pena[p-1]+=1
if m==0:
  print("0 0")
else:
  pen=0
  for (x,y) in zip(ac,pena):
    pen+=x*y
  print("{} {}".format(ac.count(1),pen))


Measured memory_bytes: 4596
import os
import sys
from atexit import register
from io import BytesIO
sys.stdin = BytesIO(os.read(0, os.fstat(0).st_size))
sys.stdout = BytesIO()
register(lambda: os.write(1, sys.stdout.getvalue()))
input = lambda: sys.stdin.readline().rstrip('\r\n')
raw_input = lambda: sys.stdin.readline().rstrip('\r\n')


n = int(input())
seq = [int(x) for x in input().split()]
ans = 0
d = {}
for val in seq:
    try:
        d[val] += 1
    except:
        d[val] = 1
mm  = max(seq)
lst = [True for _ in range(mm+1)]
for val in seq:
    f = 2
    while val*f <= mm:
        lst[val*f] = False
        f += 1
ans = 0
for val in seq:
    if lst[val] and d[val] == 1:
        ans += 1
print(ans)

Measured memory_bytes: 128696
#include <bits/stdc++.h>
#define mod 1000000007
#define ull unsigned ll
#define ll long long int
#define ld long double
#define pb push_back
#define mp make_pair
#define mt make_tuple
#define ff first
#define ss second
#define pi acos(-1)
#define nui 100
#define INF 100000000000
#pragma GCC optimize("Ofast")
#pragma GCC target("avx,avx2,fma")
#pragma GCC optimization ("unroll-loops")
#define F(i,a,n) for(ll i=a;i<n;i++)
#define B(i,a,n) for(ll i=n-1;i>=a;i--)
#define tc int t;cin>>t;while(t--)
#define tcf int t;cin>>t;for(int w=1;w<=t;w++)



using namespace std;

void dex(int a)
{
    if (a == 1)
    {
        cout << "1\n";
    }
    else if (a == -1)
    {
        cout << "-1\n";
    }
    else if (a == 0)
    {
        cout << "0\n";
    }
    else if (a == 2)
    {
        cout << "YES\n";
    }
    else if (a == 3)
    {
        cout << "NO\n";
    }

}

ll binpow(ll a, ll b)
{
    ll res = 1;
    while (b > 0)
    {
        if (b & 1)
        {
            res = (res * a) % mod;
        }
        a = (a * a) % mod;
        b >>= 1;
    }
    return res;
}

vector<ll>adj[200005];
vector<ll>visited(200005, 0);
ll k = 0;
void dfs(ll node)
{
    k++;
    visited[node] = 1;
    for (auto i : adj[node])
    {
        if (!visited[i])
        {
            dfs(i);

        }
    }
}

int main()
{

#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif

    ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

    ll n, m;
    cin >> n >> m;
    ll a, b;
    ll cc = 0;
    while (m--)
    {
        cin >> a >> b;
        adj[a].pb(b);
        adj[b].pb(a);
    }
    ll ans = 0;
    F(i, 1, n + 1)
    {
        k = 0;
        if (!visited[i])
        {
            dfs(i), cc++;
        }
        ans = max(ans, k);
    }
    cout << ans << "\n";

    return 0;

}


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

void solve()
{
	int n;
	cin >> n;
	while(n--)
	{
		int a, b, c;
		cin >> a >> b >> c;
		int aa = a * a;
		int bb = b * b;
		int cc = c * c;
		if(aa + bb == cc || aa + cc == bb || bb + cc == aa)
		{
			cout << "YES" << endl;
		}
		else
		{
			cout << "NO" << endl;
		}
	}
}

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

Measured memory_bytes: 1152
#include <bits/stdc++.h>
#define FOR(i, a, b) for(int i = a; i < b; i++)
#define REP(i, n) FOR(i, 0, n)
#define INF 999999999
typedef long long ll;
using namespace std;
int main() {
    int A, B, C, X;
    cin >> A >> B >> C >> X;
    int ans = 0;
    REP(i, A+1) {
        REP(j, B+1) {
            REP(k, C+1) {
                if(i*500 + j*100 + k*50 == X) ans++;
            }
        }
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
n, m = map(int, input().split())
s = list(map(int, input().split()))
t = list(map(int, input().split()))
dp = [[0] * (m+2) for _ in range(n+2)]
mod = 1000000007

for i in range(n+1):
    dp[i][0] = 1
for i in range(m+1):
    dp[0][i] = 1

for i in range(1, n+1):
    for j in range(1, m+1):
        dp[i][j] = (dp[i-1][j] + dp[i][j-1] - dp[i-1][j-1]) % mod
        if s[i-1] == t[j-1]:
            dp[i][j] += dp[i-1][j-1]
            dp[i][j] %= mod
print(dp[n][m])


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

int main(){
	int x,y;
	int cell[101][101];
	memset(cell,0,sizeof(cell));
	cin >> y >> x;
	int sum = 0;
	for(int i=0;i<y;i++){
		for(int j=0;j<x;j++){
			cin >> cell[i][j];
			cell[i][x] += cell[i][j];
			cell[y][j] += cell[i][j];
			sum += cell[i][j];
		}
	}
	cell[y][x] = sum;
	for(int i=0;i<=y;i++){
		for(int j=0;j<=x;j++){
			cout << cell[i][j];
			if(j != x) cout << " ";
		}
		cout << endl;
	}
	
	return 0;
}


Measured memory_bytes: 3104
#include <bits/stdc++.h>
#define pb push_back
#define all(a) a.begin(), a.end()
#define sz(a) (int)a.size()
#define x first
#define y second
#define debug(...) cout<<"["<<#__VA_ARGS__<<": "<<__VA_ARGS__<<"]\n"
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<int, int>pii;
const int maxn = 3e3 + 100;
const int mod = 1e9 + 7;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());
int dp[maxn][maxn];
pii from[maxn][maxn];
string s, t;
int main()
{
    ios_base::sync_with_stdio(false), cin.tie(0);
    cin >> s >> t;
    int n = sz(s), m = sz(t);
    for(int i = 1; i <= n; i++)
    {
        for(int j = 1; j <= m; j++)
        {
            if(s[i - 1] == t[j - 1])
            {
                if(dp[i][j] < dp[i - 1][j - 1] + 1)
                {
                    dp[i][j] = dp[i - 1][j - 1] + 1;
                    from[i][j] = {i - 1, j - 1};
                }
            }
            if(dp[i][j] <= dp[i - 1][j])
            {
                dp[i][j] = dp[i - 1][j];
                from[i][j] = {i - 1, j};
            }
            if(dp[i][j] <= dp[i][j - 1])
            {
                dp[i][j] = dp[i][j - 1];
                from[i][j] = {i, j - 1};
            }
        }
    }
    string ans;
    int ci = n, cj = m;
    while(from[ci][cj] != pii(ci, cj))
    {
        int cx = from[ci][cj].x, cy = from[ci][cj].y;
        if(cx == ci - 1 && cy == cj - 1) ans += s[cx];
        ci = cx, cj = cy;
    }
    reverse(all(ans));
    cout << ans << "\n";
    return 0;
}


Measured memory_bytes: 111744
<?php
// 標準入力取得
  $hanter = fgets(STDIN);
  $hanter = str_replace(PHP_EOL, '', $hanter);

  list($hanterZ, $hanterV) = preg_split('/\s+/', $hanter);

  // $nums = preg_split('/\s+/', $line);
  $runner = fgets(STDIN);
  $runner = str_replace(PHP_EOL, '', $runner);

  list($runnerZ, $runnerV) = preg_split('/\s+/', $runner);


  $distance = abs($hanterZ - $runnerZ); // 鬼と逃げる人の距離
  $V = $hanterV - $runnerV; // 1秒に縮まる距離

  // 追いかける時間
  $chaceTime = fgets(STDIN);

    // 最初に同じ位置におらず、差が縮まらない場合には捕まえられない
  if ($V <= 0 && $distance > 0) {
    echo "NO";
    exit();
  }

  $tijimaruKyori = (int)$chaceTime * (int)$V;

  if ($tijimaruKyori >= $distance) {
    echo "YES";
    exit();
  }

  echo "NO";


Measured memory_bytes: 16420
import java.math.BigDecimal;
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        // TODO 自動生成されたメソッド・スタブ

        Scanner sc = new Scanner(System.in);
        BigDecimal one = new BigDecimal(1);

        BigDecimal r1 = new BigDecimal(sc.nextInt());
        BigDecimal r2 = new BigDecimal(sc.nextInt());

        r1 = one.divide(r1,12,BigDecimal.ROUND_UP );
        r2 = one.divide(r2,12,BigDecimal.ROUND_UP );
        BigDecimal r3 = r1.add(r2);
        r3 = one.divide(r3,12,BigDecimal.ROUND_UP);
        System.out.println(r3);

    }

}


Measured memory_bytes: 10320
//============================================================================
// Name        : ChessTest.cpp
// Author      :
// Version     :
// Copyright   : Your copyright notice
// Description : Hello World in C++, Ansi-style
//============================================================================

#include <iostream>
using namespace std;

int main() {
	int H,W,i,j;
	cin>>H>>W;
	while(H!=0){
		for(i=0;i<H;i++){
			for(j=0;j<W;j++){
				if((i%2==0&&j%2==0)||(i%2==1&&j%2==1))cout<<"#";
				else cout<<".";
			}
			cout<<endl;
		}
		cout<<endl;
		cin>>H>>W;
	}
	}



Measured memory_bytes: 3076
#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 <cstdio> // printf
#include <map> // map
#include <queue> // queue, priority_queue
#include <set> // set
#include <stack> // stack
#include <deque> // deque
#include <unordered_map> // unordered_map
#include <unordered_set> // unordered_set
#include <bitset> // bitset
#include <cctype> // isupper, islower, isdigit, toupper, tolower
#include <iomanip> // setprecision
#include <complex> // complex
#include <math.h> 
#include <climits> 
#include <assert.h>
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;
using ll = long long;
using P = pair<int,int>;
constexpr ll INF = 1e18;
constexpr int inf = 1e9;
constexpr ll mod = 1000000007;
constexpr ll mod2 = 998244353;
const double PI = 3.1415926535897932384626433832795028841971;
const int dx[8] = {1, 0, -1, 0,1,1,-1,-1};
const int dy[8] = {0, 1, 0, -1,1,-1,1,-1};
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(){
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    int d;
    cin >> d;
    vector<int> c(26);
    for(int i=0; i<26; i++) cin >> c[i];
    vector<vector<int>> G(d,vector<int> (26));
    for(int i=0; i<d; i++){
        for(int j=0; j<26; j++){
            cin >> G[i][j];
        }
    }
    vector<int> t(d);
    for(int i=0; i<d; i++){
        cin >> t[i];
        t[i]--;
    }
    vector<int> now(26,0);
    vector<int> last(26,0);
    for(int i=0; i<d; i++){
        last[t[i]] = i+1;
        now[t[i]] += G[i][t[i]];
        for(int j=0; j<26; j++){
            now[t[i]] -= c[j] * (i+1 - last[j]);
        }
        int sum = 0;
        for(int j=0; j<26; j++){
            sum += now[j];
        }
        cout << sum << "\n";        
    }
    return 0;
}

Measured memory_bytes: 3660
#include <bits/stdc++.h>
using namespace std;
const int N = 100010;
int n,m,k,a[N],mp[110][110];
int main() {
	cin >> n >> m >> k;
	for (int i = 1;i <= k;i++) scanf("%d",a+i);
	int x = 1, y = 1, id = 1, d = 1;
	for (int i = 1; i <= n*m; i++) {
		mp[x][y] = id;
		a[id]--;
		if (a[id] == 0) id++;
		y += d;
		if (y > m||y <= 0) {
			d *= -1;
			y += d;
			x += 1;
		} 
	}
	for (int i = 1; i <= n;i++) {
		for (int j = 1;j <= m-1;j++) printf("%d ",mp[i][j]);
		printf("%d\n",mp[i][m]);
	}
	return 0;
}

Measured memory_bytes: 384
#include <iostream>
#include <vector>
#include <algorithm>
#include <string>
#include <set>
#include <map>
using namespace std;
using ll = long long;



int main() {
	int n;
	cin >> n;
	vector<int> h(n);
	for (int i = 0; i < n; i++) cin >> h[i];
	int m=0,ans=1;
	m = h[0];
	for (int i = 1; i < n; i++) {
		if (m <= h[i]) ans++;
		m = max(m, h[i]);
	}
	cout << ans << endl;


	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main() {
  int a, b;
  cin >> a >> b;
  cout << (a+b+1)/2 << endl;
  return 0;
}

Measured memory_bytes: 256
/// Be Kind :)
#include <bits/stdc++.h>
using namespace std;
 
#pragma GCC optimize("O2,no-stack-protector,unroll-loops,fast-math")
#pragma GCC target("sse,sse2,sse3,ssse3,sse4,popcnt,abm,mmx,avx,tune=native")
//#pragma GCC optimize("Os")

/*				We pop out at your party, I'm with the gang
				And it's gon' be a robbery, so tuck ya chain
				I'm a killer girl, I'm sorry, but I cannot change
				We ain't aiming for your body, shots hit you brain
				We come from poverty, man, we ain't have a thing
				It's a lot of animosity, but they won't say my name
				Them killers rock with me, lil' nigga, don't get banged
				'Cause they'll do that job for me while I hop on a plane	*/

/*				I take you to the candy shop								*/

/*				Baby, let me put your panties to the side
				I'ma make you feel alright
				'Cause I'ma give you what you need, yeah					*/

/*				Ooooh ooh, it's me, myself and I
				Solo ride until I die, 'cause I got me for life				*/

/*				So I ball So hard, muh'fuckas wanna find me					*/

/*				Bitch, where you when I was walkin'?
				Now I run the game, got the whole world talkin'				*/
 
/*				Niggas been counting me out
				I'm counting my bullets, I'm loading my clips
				I'm writing down names, I'm making a list					*/

/*				Fuck your friendship, I meant it							*/

/*				The Chanel or Balenciaga, Louis and Vuitton
				She know I got Fendi, Prada when I hit Milan				*/

/*				I ran away, I don't think I'm coming back home				*/
 
#define F first
#define S second
#define pb push_back
#define SZ(x) (ll)(x.size())
#define all(x) x.begin(),x.end()
 
typedef int ll;
typedef long double ld;
typedef pair<ll,ll> pll;
 
//mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
const ll maxn=2e3+10, maxm=1e5+10, lg=21, mod=1e9+7, inf=1e18;

bitset<maxn*maxn> bit;

int main(){
	ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0);
	
	ll n,sum=0; cin>>n;
	bit[0]=1;
	while(n--){
		ll x; cin>>x; sum+=x;
		bit|=(bit<<x);
	}
	for(int i=(sum+1)/2;;i++)if(bit[i]) return cout<<i,0;
	
	return 0;
}



 


Measured memory_bytes: 1792
#include <bits/stdc++.h>
using namespace std;
#define int long long   // <-----!!!!!!!!!!!!!!!!!!!

#define rep(i,n) for (int i=0;i<(n);i++)
#define rep2(i,a,b) for (int i=(a);i<(b);i++)
#define rrep(i,n) for (int i=(n)-1;i>=0;i--)
#define rrep2(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define all(a) (a).begin(),(a).end()

typedef long long ll;
typedef pair<int, int> P;
typedef tuple<int, int, int> TUPLE;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;

string d = "ixcm";

int conv(string s) {
    s = "#" + s;
    int ret = 0;
    rep(k, 4) {
        rep(i, s.size()) {
            if (s[i] == d[k]) {
                ret += (isdigit(s[i - 1]) ? s[i - 1] - '0' : 1) * pow(10, k);
            }
        }
    }
    return ret;
}

string inv(int a) {
    string s = "";
    rep(k, 4) {
        if (a % 10 >= 1) {
            s += d[k];
        }
        if (a % 10 >= 2) {
            s += (a % 10) + '0';
        }
        a /= 10;
    }
    reverse(all(s));
    return s;
}

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

    int n;
    cin >> n;
    while (n--) {
        string s, t;
        cin >> s >> t;
        cout << inv(conv(s) + conv(t)) << endl;
    }
}

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

using namespace std;

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

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

int num[125252];

int main(){
	ios::sync_with_stdio(false);
	cin.tie(0);
	// cout<<setprecision(10)<<fixed;
	int n, k, q, a[125252];
	cin>>n>>k>>q;
	REP(i, q){
		cin>>a[i];
		--a[i];
		++num[a[i]];
	}
	REP(i, n){
		cout<<(num[i]+k>q ? "Yes" : "No")<<'\n';
	}
	return 0;
}


Measured memory_bytes: 1408
// Template
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <functional>
#include <numeric>
#include <list>
#include <set>
#include <map>
#include <algorithm>
#include <cmath>

using namespace std;
typedef long long ll;

#define REP(i, n) for(int i = 0;i < n;i++)
#define INF 1 << 30
int dx[4] = {0, 1, 0, -1};
int dy[4] = {1, 0, -1, 0};

int main(){
    std::ios_base::sync_with_stdio(false);

    ll n; cin >> n;
    std::vector<ll> a(n);
    std::vector<ll> b(n);
    std::vector<ll> diff(n);

    REP(i,n) cin >> a[i];
    REP(i,n) cin >> b[i];

    ll sum = 0LL;

    REP(i,n){
        diff[i] = a[i]-b[i];
        sum+=diff[i];
    }

    if(sum<0LL){
        cout << -1 << endl;
        return 0;
    }

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

    ll ans = 0LL;

    ll left=0LL;
    ll right=n-1LL;
    bool ok=false;

    ll nokori = 0;

    while(!ok){

        if(diff[left]>=0) break;
        if(left > right) break;

        if(nokori < 0 || nokori+diff[left] < 0){
            nokori += diff[right];
            right--;
        } else {
            nokori += diff[left];
            left++;
        }

        //cout << nokori << " " << left << " " << right << endl;
    }


    cout << left+n-right-1 << endl;


    return 0;
}


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

typedef long long ll;
const int MOD = 1e9 + 7;
typedef vector<ll> vll;
typedef vector<int> vi;
const int maxn = 100 + 10;
vll levelCnt(51);
vll pattyCnt(51);

void eat(ll& ans, ll level, ll& layer) {
    if (layer <= 0) return;
    if (layer >= levelCnt[level]) {
        ans += pattyCnt[level];
        layer -= levelCnt[level];
        return;
    }
    if (level == 0) {
        ans += 1;
        layer -= 1;
    } else {
        layer -= 1;
        eat(ans, level - 1, layer);
        if (layer <= 0) return;
        ans += 1;
        layer -= 1;
        eat(ans, level - 1, layer);
        if (layer <= 0) return;
        layer -= 1;
    }
}

int main() {
    ll n, x;
    cin >> n >> x;
    ll ans = 0;
    levelCnt[0] = 1;
    pattyCnt[0] = 1;
    for (int i = 1; i <= 50; ++i) {
        levelCnt[i] = 3 + (levelCnt[i - 1] << 1);
        pattyCnt[i] = 1 + (pattyCnt[i - 1] << 1);
    }
    eat(ans, n, x);
    cout << ans << endl;
    // for (int i = 0; i <= 50; ++i) {
    //     printf("level: %i levelCnt: %lld pattyCnt: %lld\n", i, levelCnt[i], pattyCnt[i]);
    // }
    return 0;
}


Measured memory_bytes: 256
MOD = 10**9 + 7
N,M = map(int,input().split())
S = [0] + [int(x) for x in input().split()]
T = [0] + [int(x) for x in input().split()]

# 最後に(n,m)でとる
dp = [[0] * (M+1) for _ in range(N+1)]
# 2次元累積和、(n,m) inclusive. 
dp_cum = [[0] * (M+1) for _ in range(N+1)]

# empty
dp[0][0] = 1
dp_cum[0][0] = 1
for n in range(N+1):
  dp_cum[n][0] = 1
for m in range(M+1):
  dp_cum[0][m] = 1
  
for n in range(1,N+1):
  for m in range(1,M+1):
    if S[n] != T[m]:
      dp[n][m] = 0
    else:
      # (n-1, m-1)までで作れてるやつから飛んでくる
      dp[n][m] = dp_cum[n-1][m-1]
    dp_cum[n][m] = dp_cum[n-1][m] + dp_cum[n][m-1] - dp_cum[n-1][m-1] + dp[n][m]
    dp_cum[n][m] %= MOD

#print(dp)
#print(dp_cum)
answer = dp_cum[N][M]
print(answer)

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

int main() {
    ll N,M,V,P; cin>>N>>M>>V>>P;
    vector<ll> A(N),sum(N+1,0);
    rep(i,N) cin>>A[i];
    sort(A.begin(),A.end(),greater<ll>());
    rep(i,N) sum[i+1]=sum[i]+A[i];
    ll ans=P;
    reps(i,P,N){
        ll summ=sum[i+1]-sum[P-1]-A[i]*(i-P+2);
        if(A[P-1]>A[i]+M or summ>(N-V)*M) break;
        ++ans;
    }
    cout<< ans <<"\n";
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
#include<ios>
using namespace std;
int main(){
     ios::sync_with_stdio(false);
     const int INF = INT32_MAX;
     int N, K, h[100001], dp[100001];
     cin >> N >> K;
     for(int i = 0; i < N; ++i){
         cin >> h[i];
         dp[i] = INF;
     }
     dp[0] = 0;
     for(int i = 1; i < N; ++i) {
         for(int j = i-1; j >= 0 && j+K >= i ;--j) {
             if(dp[i] > dp[j] + abs(h[i]-h[j])) {
                 dp[i] = dp[j] + abs(h[i]-h[j]);
             }
         }
     }
     cout << dp[N-1] << "\n";
}

Measured memory_bytes: 1024
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
#include <cstring>
#include <sstream>
#include <cassert>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
typedef pair<int,int> PI;
#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()
#define mp(a,b) make_pair(a,b)
#define pb(a) push_back(a)
int dx[]={0,1,0,-1},dy[]={1,0,-1,0};

main(){
  string str;
  while(getline(cin,str)){
    if(str=="0")break;

    int plen,cnum,width,cspace;
    {
      stringstream ss(str);
      ss>>plen;
    }

    {
      getline(cin,str);
      stringstream ss(str);
      ss>>cnum;
    }

    {
      getline(cin,str);
      stringstream ss(str);
      ss>>width;
    }

    {
      getline(cin,str);
      stringstream ss(str);
      ss>>cspace;
    }

    vector<string> out;

    while(getline(cin,str)){
      if(str=="?")break;

      int pos=0;
      string pu;
      while(pos<str.size()){
	if(pu.size()==width){
	  out.pb(pu);
	  pu="";
	}
	pu+=str[pos];
	++pos;
      }
      out.pb(pu);
    }
    
    while(out.size()%(cnum*plen))out.pb("");

    rep(i,out.size()){
      while(out[i].size()<width)out[i]+='.';
    }

    rep(i,out.size()/cnum/plen){
      rep(j,plen){
	rep(k,cnum){
	  if(k)rep(l,cspace)cout<<".";
	  cout<<out[i*cnum*plen+k*plen+j];
	}
	cout<<endl;
      }
      cout<<"#"<<endl;
    }
    cout<<"?"<<endl;
  }
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
using namespace std;
typedef pair<int,int> P;
typedef long long ll;
typedef long double ld;
const int inf=1e9+7;
const ll longinf=1LL<<60;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define F first
#define S second

const int mx=100010;
const ll mod=1e9+7;

int main() {
  int n; cin >> n;
  vector<int> a(n,0);
  ll snk=0,ari=0;
  rep(i,n){ cin >> a[i]; ari+=a[i];}

  ll ans=longinf;
  rep(i,n-1){
    snk += a[i];
    ari -= a[i];
    ans = min(ans,abs(ari-snk));
  }
  
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 1024
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#define rep(i,n) for(int i=0;i<(int)n;i++)
#define reps(i,n) for(int i=1;i<=(int)n;i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define mp make_pair
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define MOD 1000000007
#define itn int
#define enld endl
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
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 A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

vector<pair<long long, long long>> prime_factorize(long long N) {
    vector<pair<long long, long long>> res;
    for (long long a = 2; a * a <= N; ++a) {
        if (N % a != 0) continue;
        long long ex = 0;
        while (N % a == 0) {
            ++ex;
            N /= a;
        }
        res.push_back({a, ex});
    }
    if (N != 1) res.push_back({N, 1});
    return res;
}

int main(){
    int A,B,M; cin >> A >> B >> M;
    int a[100100],b[100100];
    rep(i,A) cin >> a[i];
    rep(i,B) cin >> b[i];
    int ans = 1001001001;
    rep(i,M){
        int x,y,c; cin >> x >> y >> c;
        x--; y--;
        chmin(ans, a[x]+b[y]-c);
    }
    sort(a,a+A);
    sort(b,b+B);
    chmin(ans,a[0]+b[0]);
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 4372
n,k=map(int,input().split())
P,X,Y=[],[],[]
for _ in range(n):
    x,y=map(int,input().split())
    P.append((x,y))
    X.append(x)
    Y.append(y)
ans=10**19
X.sort()
Y.sort()
for d in range(n-1):
    for u in range(d,n):
        for l in range(n-1):
            for r in range(n):
                D,U,L,R=X[d],X[u],Y[l],Y[r]
                cnt=0
                for i in P:
                    if D<=i[0]<=U and L<=i[1]<=R:
                        cnt+=1
                if cnt>=k:
                    ans=min(ans,(U-D)*(R-L))
print(ans)

Measured memory_bytes: 48220
#include<bits/stdc++.h>
using namespace std;
#define Sheryang main
const int maxn=1e6+7;
typedef long long ll;
const int mod=1e9+7;
///#define getchar()(p1 == p2 && (p2 = (p1 = buf) + fread(buf, 1, 1 << 21, stdin), p1 == p2) ? EOF : *p1++)
char buf[(1 << 21) + 1], *p1 = buf, *p2 = buf;
#define IO cin.tie(0),ios::sync_with_stdio(false);
#define pi acos(-1)
#define PII pair<ll,ll>
ll read(){ll c = getchar(),Nig = 1,x = 0;while(!isdigit(c) && c!='-')c = getchar();if(c == '-')Nig = -1,c = getchar();while(isdigit(c))x = ((x<<1) + (x<<3)) + (c^'0'),c = getchar();return Nig*x;}
#define read read()
/** keep hungry and keep calm! **/

int a,b,c;
int Sheryang(){

    scanf("%d/%d/%d",&a,&b,&c);
    if(b<4)
        printf("Heisei\n");
    else if(b==4 && c<=30)
        printf("Heisei\n");
    else
        printf("TBD\n");

    return 0;
}


Measured memory_bytes: 256
s=list(map(int,list(input())))
#print(s)
#modで考える
# 2019100を
# 2019100%2019 と100%1019
#同じmodの組み合わせ

#右から見ていく

mod=[0]*2019

tmp=0
ten=1

#hoge=""

for ii in range(len(s)):
    i=len(s)-ii-1
    if ii==0:
        ten=1
    else:
        ten=(ten*10)%2019

    tmp=((tmp+s[i]*ten)%2019)
    #hoge=str(s[i])+hoge
    #print(tmp,int(hoge)%2019,hoge)
    mod[tmp]+=1

ans=0
for i in range(2019):
    ans+=((mod[i]*(mod[i]-1))//2)

ans+=mod[0]

print(ans)



Measured memory_bytes: 94788
/*
        Author: Prokash
                CSE48, JU

*/

#include<bits/stdc++.h>
using namespace std;

typedef long long ll;
#define FAST ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
int main()
{
    FAST;
    ll t,a,b;
    cin>>t;
    ll sum=0;
    while(t--)
    {
        cin>>a>>b;
        if(a!=b)
        {
            sum+=abs(b-a)+1;
        }
        else
        {
            sum+=1;
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 256
import collections
N=int(input())
S=['a']*N
for i in range(0,N):
    S[i]=input()
J=collections.Counter(S)
print('AC',J['AC'],sep=' x ')
print('WA',J['WA'],sep=' x ')
print('TLE',J['TLE'],sep=' x ')
print('RE',J['RE'],sep=' x ')

Measured memory_bytes: 16484
import sys
sys.setrecursionlimit(20000000)

n = int(input())
G = [[] for _ in range(n)]
for i in range(n - 1):
    u, v, w = map(int, input().split())
    G[u - 1].append([v - 1, w])
    G[v - 1].append([u - 1, w])

def dfs(node, dist):
    for nxt_node, edge_size in G[node]:
        if ans[nxt_node] == -1:
            ans[nxt_node] = ((dist + edge_size) % 2)
            dfs(nxt_node, dist + edge_size)

ans = [-1] * n
dfs(0, 0)
print(*ans, sep='\n')


Measured memory_bytes: 191932
using System;
using System.Text;
using System.Linq;
 
class AtCoder
{
    static void Main(){
		string s = Console.ReadLine();
      	string t = Console.ReadLine();
      	int sum=0;
      	for(int i=0;i<s.Length;i++){
          if(s[i]==t[i]){
            sum+=1;
          }
        }
      Console.WriteLine(sum);
    }
}

Measured memory_bytes: 13140
#include<bits/stdc++.h>
using namespace std;
#define int long long
signed main(){
	int s;
	scanf("%lld",&s);
	int X1=1000000000,X2=1,Y2=(s-1)/X1+1,Y1=X1*Y2-s;
	printf("0 0 %lld %lld %lld %lld",X1,Y1,X2,Y2);
} 

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

using namespace std;

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define fi first
#define se second

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

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
typedef pair<int, pii> P;

const ll INF = 1ll<<30;
const ll MOD = 1000000007;
const double EPS  = 1e-10;

int N, K;
int a[112345];
ll b[112345], c[112345];
ll sum[112345];

int main() {
	cin >> N >> K;
	REP(i, N) scanf("%d", a + i);
	
	REP(i, N) { // 1-indexed
		b[i + 1] = b[i];
		if (a[i] >= 0) b[i + 1] += a[i];
	}
	
	for (int i = N - 1; i >= 0; i--) { // 0-indexed
		c[i] = c[i + 1];
		if (a[i] >= 0) c[i] += a[i];
	}
	
	REP(i, N) sum[i + 1] = sum[i] + a[i];
	
	ll ans = 0;
	REP(i, N) {
		if (i + K > N) break;
		ll now = sum[i + K] - sum[i];
		if (now < 0) now = 0;
		now += b[i] + c[i + K];
		chmax(ans, now);
	}
	cout << ans << endl;
	
	return 0;
}


Measured memory_bytes: 2944
import java.util.*;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int S = sc.nextInt();
        int[] memo = new int[1000000];
        calc(S, 1, memo);
    }

    public static void calc(int s, int index, int[] memo) {
        
          if (s == 4 || s==2 || s==1) {
                System.out.println(index+3);
                return;
            }
       
		int result = 0;
        if (s % 2 == 0){
            result = s/2;
        }        
        else {
            result = s*3 + 1;
        }
        calc(result, index+1, memo);
    }
}

Measured memory_bytes: 27220
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<(n);i++)
#define all(x) begin(x), end(x)
#define chmax(x,y) x = max(x,y)
using namespace std;
typedef long long ll;
typedef pair <int,int> P;

int main(){
  int a,b;
  cin>>a>>b;

  cout<<100<<' '<<100<<endl;

  string s1(100,'#'),s2(100,'.');
  a--; b--;
  rep(i,50){
    if(i%2==1) cout<<s1;
    else{
      rep(j,50){
	if(a){
	  cout<<".#";
	  a--;
	}
	else{
	  cout<<"##";
	}
      }
    }
    cout<<endl;
  }
  rep(i,50){
    if(i%2==0) cout<<s2;
    else{
      rep(j,50){
	if(b){
	  cout<<"#.";
	  b--;
	}
	else{
	  cout<<"..";
	}
      }
    }
    cout<<endl;
  }
  return 0;
}


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

using namespace std;

const int N=2005,MOD=1e9+7;

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

typedef long long ll;

int l[N][N],r[N][N],u[N][N],d[N][N];

int v,p,n,tc,q,k,c,m,b[N],cnt,curr,a[N],ans,calc[N];

bool sum[N],bad[N];

char s[N][N];


int main(){	
 

	//freopen("test.txt","r",stdin);
 	cin>>n>>m;
 
 	for(int i=0;i<n;i++)cin>>s[i];
 
 	for(int i=0;i<n;i++){
 		int lefft=0;
 		for(int j=0;j<m;j++){
 			if(s[i][j]=='#')lefft=0;
 			else l[i][j]=lefft++;
 		}
 	}
 
 	for(int j=0;j<m;j++){
 		int up=0;
 		for(int i=0;i<n;i++){
 			if(s[i][j]=='#')up=0;
 			else u[i][j]=up++;
 		}
 	}
 
 
 
 	for(int j=0;j<m;j++){
 		int dowwn=0;
 		for(int i=n-1;i>=0;i--){
 			if(s[i][j]=='#')dowwn=0;
 			else d[i][j]=dowwn++;
 		}
 	}
 
 
 
 	for(int i=n-1;i>=0;i--){
 		int rt=0;
 		for(int j=m-1;j>=0;j--){
 			if(s[i][j]=='#')rt=0;
 			else r[i][j]=rt++;
 		}
 	}
 	int ans = 0;
 	for(int i=0;i<n;i++){
 		for(int j=0;j<m;j++){
 			if(s[i][j]!='#'){
 				ans = max(ans,u[i][j]+d[i][j]+l[i][j]+r[i][j]+1);
 			}
 		}
 	}
 	cout<<ans<<"\n";
}

Measured memory_bytes: 66944
N=int(input())
A=list(map(int,input().split()))
A=[0]+A
import math

L=[0 for i in range(N+2)]
R=[0 for i in range(N+2)]
for i in range(0,N+1):
  L[i+1]=math.gcd(L[i],A[i])
for i in range(N,-1,-1):
  R[i]=math.gcd(R[i+1],A[i])

M=[0 for i in range(N+1)]
for i in range(1,N+1):
  M[i]=math.gcd(L[i],R[i+1])
print(max(M))

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

int main(){
  int n,s=0; cin >>n;
  vector<int>a(n); vector<int>b(n-1);
  for(int i=0; i<n; i++){cin >>a[i];}
  for(int i=0; i<n; i++){int m; cin >>m; s+=m;}
  for(int i=0; i<n-1; i++){cin >>b[i];}
  for(int i=0; i<n-1; i++)
  {if(a[i+1]==a[i]+1){s+=b[a[i]-1];}}
  cout <<s;
return 0;
}

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

using namespace std;

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

    int H, W;
    cin >> H >> W;

    int cost[10][10];
    for (int i = 0; i < 10; ++i) {
        for (int j = 0; j < 10; ++j) {
            cin >> cost[i][j];
        }
    }

    for (int k = 0; k < 10; ++k) {
        for (int i = 0; i < 10; ++i) {
            for (int j = 0; j < 10; ++j) {
                cost[i][j] = min(cost[i][j], cost[i][k] + cost[k][j]);
            }
        }
    }

    int A[H][W];
    int ans = 0;
    for (int i = 0; i < H; ++i) {
        for (int j = 0; j < W; ++j) {
            cin >> A[i][j];
            if (A[i][j] != -1) {
                ans += cost[A[i][j]][1];
            }
        }
    }

    cout << ans << endl;
}

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

string solver(int N)
{
    int p = 0;
    if(N<0)
    {
        p = 1;
        N *= -1;
    }
    int i=0;
    for(; N >= (1LL<<i); i++)
    {
        if((1<<i & N) && i%2 != p)
        {
            N += (1LL << (i+1));
        }
    }

    bool is_start = false;
    string ans = "";
    for(; i>=0; i--)
    {
        if(N & 1<<i)
        {
            ans += "1";
            is_start = true;
        }
        else if(is_start) ans += "0";
    }
    if(!is_start) ans += "0";

    return ans;
}

int calc(int n)
{
    int res = 1;
    for(int i=0; i<n; i++)
    {
        res *= -2;
    }
    return res;
}

ll test(string s)
{
    ll ans = 0;
    for(int i=s.size()-1; i>=0; i--)
    {
        if(s[i] == '1')
        {
            ans += calc(s.size() - 1 - i);
        }
    }
    return ans;
}

int main()
{
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll N;
    cin >> N;
    // std::mt19937 mt{ std::random_device{}() };
    // uniform_int_distribution<ll> dist(-100, 100);
    // while(true)
    // {
    //     N = dist(mt);
    //     cout << "input : " << N << '\n';
    //     string ans = solver(N);
    //     ll num = test(ans);
    //     if(N==num) cout << "OK\n";
    //     else
    //     {
    //         cout << "ans = " << ans << '\n';
    //         cout << "num = " << num << '\n';
    //         break;
    //     }
    // }
    cout << solver(N) << endl;

    return 0;
}


Measured memory_bytes: 3648
#include "bits/stdc++.h"
#define int long long
#define endl '\n'
using namespace std;
 
typedef long long ll;
#define db(x) cerr << #x << ": " << x << '\n';
#define read(a) int a; cin >> a;
#define readb(a, b) int a, b; cin >> a >> b;
#define readc(a, b, c) int a, b, c; cin >> a >> b >> c;
#define readarr(a, n) int a[(n) + 1] = {}; FOR(i, 1, (n)) {cin >> a[i];}
#define readmat(a, n, m) int a[n + 1][m + 1] = {}; FOR(i, 1, n) {FOR(j, 1, m) cin >> a[i][j];}

#define print(a) cout << a << endl;
#define printarr(a, n) FOR (i, 1, n) cout << a[i] << " "; cout << endl;
#define printv(v) for (int i: v) cout << i << " "; cout << endl;
#define printmat(a, n, m) FOR (i, 1, n) {FOR (j, 1, m) cout << a[i][j] << " "; cout << endl;} cout << endl;
#define all(v) v.begin(), v.end()
#define sz(v) (int)(v.size())
#define rz(v, n) v.resize((n) + 1);
#define pb push_back
#define fi first
#define se second
#define vi vector <int>
#define pi pair <int, int>
#define vpi vector <pi>
#define vvi vector <vi>
#define FOR(i, a, b) for (int i = (a); i <= (b); i++)
#define FORD(i, a, b) for (int i = (a); i >= (b); i--)
const ll inf = 1e18;
const ll mod = 1e9 + 7;
const ll N = 2e5 + 1;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int power (int a, int b = mod - 2)
{
    int res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % mod;
        a = a * a % mod;
        b >>= 1;
    }
    return res;
}

signed main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	
	readb(n, k);
	int dp[k + 1] = {};
	
	dp[k] = 1;
	int ans = k;
	FORD (i, k - 1, 1)
	{
	    int x = k/i;
	    dp[i] = power(x, n);
	    for (int j = i*2; j <= k; j += i) dp[i] = (dp[i] - dp[j]) % mod;
	    ans = (ans + i*dp[i]) % mod;
	}
	
	cout << (ans + mod) % mod;
}















Measured memory_bytes: 4392
#include<cstdio>
#include<cmath>
#include<climits>
#include<algorithm>
#include<sstream>
#include<iostream>
#include<string>
#include<queue>
#include<stack>
#include<set>
#include<list>
#include<map>
#include<vector>

using namespace std;


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

#define IMIN INT_MIN;
#define IMAX INT_MAX;

int maxelem(vector<int> src) {
	int dst = IMIN;
	rep(i, src.size()) {
		dst = (dst > src[i]) ? dst : src[i];
	}
	return dst;
}

int minelem(vector<int> src) {
	int dst = IMAX;
	rep(i, src.size()) {
		dst = (dst < src[i]) ? dst : src[i];
	}
	return dst;
}

int secondelem(vector<int> src) {
	int dst = IMIN;
	int dst2 = IMIN;
	rep(i, src.size()) {
		if (dst < src[i]) {
			dst2 = dst;
			dst = src[i];
		}
		else if (dst2 < src[i]) {
			dst2 = src[i];
		}
	}
	return dst2;
}

vector<int> count(vector<int> a) {
	int ma = maxelem(a);
	vector<int> count(ma+1, 0);
	rep(i, a.size()) {
		count[a[i]]++;
	}
	return count;
}

int find(vector<int> a, int b) {
	rep(i, a.size()) {
		if (a[i] == b) return i;
	}
	return -1;
}

int main(){
	int N, K;
	cin >> N >> K;
	int h[N];
	rep(i, N) cin >> h[i];

	vector<int> dp(N+K, 0);
	vector<int> dist;
	dp[0] = 0;
	rep(i, N-1) {
		rep(j, K) {
			if (i<j) break;
			dist.push_back(dp[i-j] + abs(h[i+1] - h[i-j]));
		}
		dp[i+1] = minelem(dist);
		dist.clear();
	}

	cout << dp[N-1] << endl;

	return 0;
}




Measured memory_bytes: 1024
#include<stdio.h>
int main(){
  int n,a[200001],i,cnt=1,ans=0;
  scanf("%d",&n);
  for(i=0; i<n; i++){
    scanf("%d",&a[i]);
  }
  for(i=0; i<n; i++){
      if(a[i]==cnt){
        cnt++;
      }
      else{
        ans++;
      }
  }
  if(ans==n){
    ans=-1;
  }
  printf("%d\n",ans);
  return 0;
}

Measured memory_bytes: 896
#include <cstddef>
#include <iostream>
#include <iomanip>
#include <string>
#include <sstream>
#include <vector>
#include <array>
#include <list>
#include <unordered_map>
#include <algorithm>
#include <numeric>
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <bitset>
#include <valarray>
#include <utility>
#include <tuple>
#include <cmath>
#include <memory>
#include <random>
#include <fstream>
#include <locale>
#include <regex>
#include <complex>

using ll = long long;
using ull = unsigned long long;
using ld = long double;

//vector
template <class T>
using vec = std::vector<T>;

template <class T>
using vvec = vec<vec<T>>;

constexpr std::size_t operator""_sz(ull n) { return std::size_t(n); }

constexpr ll lim = 1000000000000000ll;

int main()
{
	using namespace std;
	using std::cin;

	int h, n;
	cin >> h >> n;

	vec<int> A(n);

	for (auto& a : A)
		cin >> a;

	if (accumulate(A.cbegin(), A.cend(), 0) >= h)
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}

Measured memory_bytes: 640
#include <stdio.h>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; ++i)
using namespace std;
 
int main(void) {
  int n, ans = 0, inf = 10000;
  scanf("%d", &n);
  int dis[n];
  rep(i, n) dis[i] = inf;
  dis[0] = 0;
  vector< int > vec[n];
  rep(i, n) {
    int u, k;
    scanf("%d%d", &u, &k);
    u--;
    rep(j, k) {
      int v;
      scanf("%d", &v);
      v--;
      vec[u].push_back(v);
    }
  }
  rep(i, n - 1) {
    rep(j, n) {
      vector< int >::iterator it;
      for(it = vec[j].begin(); it != vec[j].end(); ++it) {
        if(dis[*it] > dis[j] + 1) dis[*it] = dis[j] + 1;
      }
    }
    /*rep(j, n) printf("%d ", dis[j]);
    printf("\n");*/
  }
  rep(i, n) {
    if(dis[i] != inf) printf("%d %d\n", i + 1, dis[i]);
    else printf("%d -1\n", i + 1);
  }
  return 0;
}


Measured memory_bytes: 2720