akhauriyash/Code-Regression huggingface dataset:
#![allow(unused_imports)]
#![allow(non_snake_case)]
#![allow(non_upper_case_globals)]
#![allow(unused_mut)]
#![allow(dead_code)]
#![allow(unused_variables)]

use std::collections::HashSet;
use std::collections::HashMap;
use std::collections::BTreeSet;
use std::collections::VecDeque;
use std::cmp::{max, min};
use std::mem::swap;
use std::io::prelude::*; // input()

fn input<T>() -> T
    where T: std::str::FromStr {
    let stdin = std::io::stdin();
    let token: String = stdin
        .lock()
        .bytes()
        .map(|c| c.unwrap() as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().unwrap()
}

const INF: usize = 1_000_000_000;
const NMAX: usize = 200;
static mut d: &'static mut [[usize; NMAX+1]; NMAX+1] = &mut [[INF; NMAX + 1]; NMAX + 1];
static mut r: &'static mut [usize] = &mut [0; 9];
static mut res: usize = 0;
static mut N: usize = 0;
static mut M: usize = 0;
static mut R: usize = 0;
static mut A: usize = 0;
static mut B: usize = 0;
static mut C: usize = 0;
static mut used: &'static mut [bool] = &mut [false; 9];

fn main() {
    unsafe {
        N = input::<usize>();
        M = input::<usize>();
        R = input::<usize>();
        for i in 1..R+1 {
            r[i] = input::<usize>();
        }
        for i in 1..N+1 {
            d[i][i] = 0;
        }
        let mut ab = Vec::new();
        for i in 0..M {
            A = input::<usize>();
            B = input::<usize>();
            C = input::<usize>();
            d[A][B] = min(d[A][B], C);
            d[B][A] = min(d[B][A], C);
            ab.push((A, B, C));
        }
        for k in 1..N+1 {
            for i in 1..N+1 {
                for j in 1..N+1 {
		    d[i][j] = min(d[i][j], d[i][k] + d[k][j]);
                }
            }
        }
        res = INF;
        dfs(1, None, 0);
        println!("{}", res);
    }
}

fn dfs(c: usize, las: Option<usize>, dist: usize) {
    unsafe {
        if c == R+1 {
            if res>dist {
                res = dist;
                return;
            }
        }
        for i in 1..R +1 {
            if !used[i] {
                used[i] = true;
                if las == None {
                    dfs(c+1, Some(i), 0);
                }
                else {
                    dfs(c+1, Some(i), dist+d[r[las.unwrap()]][r[i]]);
                }
                used[i] = false;
            }
        }
    }
}


Measured memory_bytes: 4732
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <functional>
#include <queue>
#include <string>
#include <map>
using namespace std;

long long X, Y, A, B, C, minx = (1LL << 60);
int main() {
	cin >> A >> B >> C >> X >> Y;
	for (int i = 0; i <= max(X, Y); i++) {
		long long Z1 = X - i, Z2 = Y - i, Z3 = 2 * i; Z1 = max(Z1, 0LL); Z2 = max(Z2, 0LL);
		minx = min(minx, A * Z1 + B * Z2 + C * Z3);
	}
	cout << minx << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int Nmax = 1e4 + 5;
const int mod = 1e9 + 7;

int dp[Nmax][100][2];
int n,m;

string s;

void add(int &a, int b)
{
    a += b;
    if (a >= mod) a -= mod;
}

int solve(int i, int cur, bool smlr)
{
    int &res = dp[i][cur][smlr];
    if (i > n) return !cur;
    if (res != -1) return res;
    res = 0;
    int lim = s[i] - '0';
    if (smlr) lim = 9;
    for (int d = 0; d <= lim; d++)
    {
        int nxt = (cur + d) % m;
        add(res, solve(i + 1, nxt, smlr | (d < s[i] - '0')));
    }
    return res;
}

signed main()
{
    //freopen("file.inp","r",stdin);
    cin >> s >> m;
    n = s.size();
    s = ' ' + s;
    memset(dp, -1, sizeof(dp));
    cout << (solve(1, 0, 0) - 1 + mod) % mod;
    return 0;
}


Measured memory_bytes: 20232
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int r,g,b;
  cin >> r >> g>> b;
  
  int rgb;
  rgb=100*r+10*g+b;
  
  
  if(rgb%4==0){
    cout << "YES" <<endl;
  }else{
    cout << "NO" <<endl;
  }
  
}

Measured memory_bytes: 256
s,k=input().split();k,o,c,z,L,O=int(k),s.count("1")+1,0,0,[],998244353;M,r=min(o,k+1),range
for i in s:
 if i=="0":L+=[c];c=0
 else:c+=1
d=[[0]*M for _ in r(o)];d[0][0]=1
for i in L:
 D=[[0]*M for _ in r(o)]
 for j in r(o):
  for l in r(max(z+i-j,0),o-j):
   m=max(l-i,0)
   for p in r(min(j+1,M-m)):D[j+l][p+m]=(D[j+l][p+m]+d[j][p])%O
 z+=i;d=D
print(sum([sum(i)for i in d])%O)

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

long long power(long long a, long long b, long long m) {
    a %= m;
    long long res = 1;
    while (b > 0) {
        if (b & 1)
            res = res * a % m;
        a = a * a % m;
        b >>= 1;
    }
    return res;
    }
   
    
   int binomial(int n, int k)  
{  
    // Base Cases  
    if (k == 0 || k == n)  
        return 1;  
  
    // Recur  
    return binomial(n - 1, k - 1) + binomial(n - 1, k);  
}   

bool Sieve(ll int n) 
{ 
    
    bool prime[n+100000]; 
    memset(prime, true, sizeof(prime)); 
  
    for (int p=2; p*p<=n; p++) 
    { 
        if (prime[p] == true) 
        { 
            for (int i=p*p; i<=n; i += p) 
                prime[i] = false; 
        } 
    } 
    return prime[n];
}
  
    
vector<long long> factor;  
vector<long long>prime(long long n) {
 for (long long d = 2; d * d <= n; d++) {
     while (n % d == 0) {
         factor.push_back(d);
            n /=d;
        }
    }
 if (n > 1)
    factor.push_back(n);
    return factor;
}




//It reurns Fn,Fn+1
pair<int, int> fib (int n) {
    if (n == 0)
        return {0, 1};

    auto p = fib(n >> 1);
    int c = p.first * (2 * p.second - p.first);
    int d = p.first * p.first + p.second * p.second;
    if (n & 1)
        return {d, c + d};
    else
        return {c, d};
}


  
int main() {
    ll int h1,m1,h2,m2,k;
     cin>>h1>>m1>>h2>>m2>>k;
    ll int l=(h2-h1)*60;
    ll int p=l+(m2-m1)-k;
     cout<<p<<endl;
}



Measured memory_bytes: 3600
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <class T> using treap = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
    {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
    {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
    {0, 0},  // 自身
};
template <class T> inline bool chmax(T& a, const T& b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T& a, const T& b) { if (a > b) { a = b; return true; } return false; }
template <class T, class S> vector<T> make_vec(size_t n, S x) { return vector<T>(n, x); }
template <class T, class... Ts> auto make_vec(size_t n, Ts... ts) { return vector<decltype(make_vec<T>(ts...))>(n, make_vec<T>(ts...)); }

// debug
template <class T> ostream& operator<<(ostream& s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream& s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream& s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T> ostream& operator<<(ostream& s, set<T> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T> ostream& operator<<(ostream& s, multiset<T> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
template <class T, class S> ostream& operator<<(ostream& s, unordered_map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
    #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
    #define dump(...)
    #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(nullptr); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
    int n, k; cin >> n >> k;
    int ans = 0;
    REP (i, n) {
        int x; cin >> x;
        ans += x >= k;
    }
    cout << ans << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
char p[201000];
int n,a,b,c,d,S[201000],w[201000];
int main() {
	int i;
	cin>>n>>a>>b>>c>>d;
	scanf("%s",p+1);
	for(int i=1;i<=n;i++) {
		if(p[i]=='#') w[i]=1;
		S[i]=S[i-1]+w[i];
	}
	for(int i=1;i<n;i++) {
		if(w[i] && w[i+1]) {
			if(a<=i && i+1<=c) {
				cout<<"No"<<endl;
				return 0;
			}
			if(b<=i && i+1<=d) {
				cout<<"No"<<endl;
				return 0;
			}
		}
	}
	if(c<=d) {
		cout<<"Yes"<<endl;
		return 0;
	}
	for(int i=b;i<=d;i++) {
		if(!w[i-1] && !w[i] && !w[i+1]) {
			cout<<"Yes"<<endl;
			return 0;
		}
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 1920
#include <stdio.h>

int main()
{
    int x, y, r = 1;

    scanf("%d %d", &x, &y);

    while (r != 0)
    {
        r = x % y;
        x = y;
        y = r;
    }

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

    return 0;
}


Measured memory_bytes: 2104
#include <bits/stdc++.h>
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define ALL(v) v.begin(), v.end()
using namespace std;
typedef long long ll;
int main()
{
  int ab,bc,ca;
  cin >> ab >> bc >> ca;
  cout << ab*bc/2 << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); ++i)
#define rep2(i,n) for(int i=1; i<=(n); ++i)
using namespace std;
using ll = long long;
using P = pair<int,int>;
#define all(x) (x).begin(),(x).end()
#define Sort(x) sort((x).begin(),(x).end())
#define Sort2(x) sort((x).begin(),(x).end(), greater<int>())

int digit_sum(int n) {
    int res = 0;
    while(n > 0) {
        res += n%10;
        //↑合計 ↓桁数
        //res++;
        n /= 10;
    }
    return res;
}

int main()
{
    int x; cin >> x;
    int fx = digit_sum(x);
    if (x % fx == 0) cout << "Yes" << endl;
    else cout << "No" << endl;

}

/*
Ctrl+@
g++ a.cpp
./a.out
*/

Measured memory_bytes: 256
import bisect

def main():
    N = int(input())
    base_list=input().split()
    int_list=[]
    i = 0
    [int_list.append(int(i)) for i in base_list]
    int_list=sorted(int_list)
    anslist=[]
    ans=0
    for index,value in enumerate(int_list):
        for index2,value2 in enumerate(int_list[index+1:]):
            ans+=bisect.bisect_left(int_list,value+value2)-(index+1+index2+1)
    print(ans)

if __name__ == "__main__":
    main()

Measured memory_bytes: 3188
from collections import deque, Counter
from itertools import chain, combinations
import json
# import numpy as np
import bisect
import sys
import math
import bisect

sys.setrecursionlimit(10 ** 8)
# mem = {}

M = 10 ** 9 + 7


def f(rs, gs, bs):
    res = 0
    lgs = len(gs)
    lbs = len(bs)
    for i in rs:
        j = bisect.bisect_left(gs, i)
        k = bisect.bisect_left(bs, i)
        res += (lgs - j) * (lbs - k)

        for jj in range(j, lgs):
            d = (gs[jj] - i)
            index = bisect.bisect_left(bs, i + 2 * d)
            if index != lbs:
                if bs[index] == i + 2 * d:
                    res -= 1

        for kk in range(k, lbs):
            d = (bs[kk] - i)
            index = bisect.bisect_left(gs, i + 2 * d)
            if index != lgs:
                if gs[index] == i + 2 * d:
                    res -= 1


        # for j in reversed(gs):
        #     if not (i < j):
        #         break
        #     for k in reversed(bs):
        #         if not (i < k):
        #             break
        #         if j < k:
        #             if (j - i) != k - j:
        #                 res += 1
        #         else:
        #             if (k - i) != j - k:
        #                 res += 1

    return res


def main():
    N = int(input())
    S = input()

    rs = []
    gs = []
    bs = []

    for i, c in enumerate(S):
        if c == 'R':
            rs.append(i)
        elif c == 'G':
            gs.append(i)
        else:
            bs.append(i)
    print(f(rs, gs, bs) + f(gs, rs, bs) + f(bs, rs, gs))


if __name__ == "__main__":
    main()


Measured memory_bytes: 70872
"use strict";

var input = require("fs").readFileSync("/dev/stdin", "utf8");
var cin = input.split(/ |\n/),
    cid = 0;

function next() {
    return +cin[cid++];
} // number一個取得
function nextstr() {
    return cin[cid++];
} // 文字列一個取得
function nextbig() {
    return BigInt(cin[cid++]);
} // BigInteger一個取得
// 長さnの配列として取得。aは文字列フラグ
function nexts(n, a) {
    return a ? cin.slice(cid, cid += n) : cin.slice(cid, cid += n).map(a => +a);
}
// 長さnのBigInt配列として取得。
function nextsbig(n) {
    return cin.slice(cid, cid += n).map(a => BigInt(a));
}
// w個ずつを組にして長さhの配列。aは文字列フラグ。
function nextm(h, w, a) {
    var r = [],
        i = 0;
    if (a)
        for (; i < h; i++) r.push(cin.slice(cid, cid += w));
    else
        for (; i < h; i++) r.push(cin.slice(cid, cid += w).map(a => +a));
    return r;
}
// 多次元配列。v,a1,a2,a3 なら、3次元。[[値vで長さa3の配列]をa2個並べた配列]をa1個並べた配列。
function xArray(v) {
    var a = arguments,
        l = a.length,
        r = "Array(a[" + --l + "]).fill().map(x=>{return " + v + ";})";
    while (--l) r = "Array(a[" + l + "]).fill().map(x=>" + r + ")";
    return eval(r);
}


console.log(main().toString());

function main() {
    let k = next();
    let s = next();
    let ans = 0;
    let x, y, z
    for (x = 0; x <= k; x++)
        for (y = 0; y <= k; y++)
            if (x + y <= s && x + y + k >= s) {
                //console.log(x, y, s - x - y, k)
                ans ++
            }
    return ans;
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define mp(a,b) make_pair(a,b)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout<<#x"="<<x<<endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> P;
typedef pair<P, int> PPI;
typedef pair<ll, ll> PL;
typedef pair<P, ll> PPL;

#define INF INT_MAX/3

#define MAX_N 1000

#define M 1000000007

ll mem[55][2];

int n;
string a,b,c;

ll dfs(int digit,int carry){
	if(digit==-1)return (carry==1?0:1);
	if(mem[digit][carry]!=-1)return mem[digit][carry];
	ll res=0;

	rep(an,10){
		if(a[digit]!='?'&&a[digit]-'0'!=an)continue;
		if(digit==0&&an==0)continue;
		rep(bn,10){
			if(b[digit]!='?'&&b[digit]-'0'!=bn)continue;
			if(digit==0&&bn==0)continue;
			rep(cn,10){
				if(c[digit]!='?'&&c[digit]-'0'!=cn)continue;
				if(digit==0&&cn==0)continue;
				if((an+bn+carry)%10==cn)res=(res+dfs(digit-1,(an+bn+carry)/10))%M;
			}
		}
	}
	return mem[digit][carry]=res;
}

int main(){
	cin.sync_with_stdio(false);
	while(1){
		cin>>a;
		if(a[0]=='0')break;
		cin>>b>>c;
		n=a.length();
		memset(mem,-1,sizeof(mem));
		cout<<dfs(n-1,0)<<endl;
	}
	return 0;
}

Measured memory_bytes: 3112
import java.util.Scanner;

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

		char[] c = S.toCharArray();
		for (int i = 0; i < S.length(); i++) {
			if (c[i] == 'A' || c[i] == 'C' || c[i] == 'G' || c[i] == 'T') {
				a++;
			} else {
				b = 1;
				if (max < a) {
					max = a;
				}
				a = 0;
			}
			if (max < a) {
				max = a;
			}
		}
		if (b == 0) {
			System.out.println(S.length());
		} else {
			System.out.println(max);
		}
	}
}


Measured memory_bytes: 21844
from collections import Counter
N, *S=map(str, open(0).read().split())
N = int(N)
S = Counter(S)

print("AC x {}".format(S["AC"]))
print("WA x {}".format(S["WA"]))
print("TLE x {}".format(S["TLE"]))
print("RE x {}".format(S["RE"]))

Measured memory_bytes: 17300
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef pair<int, int> pi;
#define debug(x) cerr << #x << ": " << x << endl;
#define debug2(x, y) debug(x) debug(y);
#define repn(i, a, b) for(int i = (int)(a); i < (int)(b); i++)
#define rep(i, a) for(int i = 0; i < (int)(a); i++)
#define all(v) v.begin(), v.end() 
#define mp make_pair
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define fi first
#define se second
#define sq(x) ((x) * (x))

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

int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	//freopen("input.in", "r", stdin);
	//freopen("output.out", "w", stdout);
	string s;
	cin >> s;
	int cnt = 0;
	rep(i, s.size()) cnt += (s[i] == 'A');
	if(cnt == 3 || !cnt) cout << "No" << endl;
	else cout << "Yes" << endl;
	return 0;
}
/*
Things to look out for:
	- Integer overflows
	- Array bounds
	- Special cases
Be careful!
*/


Measured memory_bytes: 256
#include <algorithm>
#include <array>
#include <bitset>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <stack>
#include <unordered_map>
#include <unordered_set>
#include <queue>

using namespace std;

struct Initializer {
  Initializer() {
    cin.tie(0);
    ios::sync_with_stdio(0);
    cout << fixed << setprecision(15);
  }
} initializer;

template<typename T> istream& operator>>(istream &s, vector<T> &v) {
  for (T &t : v) s >> t;
  return s;
}

template<typename T> ostream& operator<<(ostream &s, const vector<T> &v) {
  for (const T &t : v) s << t << endl;
  return s;
}

int main() {
  int n, m, x, s = 0, t = 0;
  cin >> n >> m >> x;
  for (int i = 0; i < m; ++i) {
    int a;
    cin >> a;
    if (a < x) ++s;
    else ++t;
  }
  cout << min(s, t) << endl;
}



Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main (){
	bool bandera=false;
	int k, a, b;
	cin >> k;
	cin >> a >> b;
	for (int i=a; i<=b; i++){
		if (i%k == 0){
			bandera = true;
			break;
		}
	}
	if (bandera == true) cout << "OK";
	else cout << "NG";
	return 0;	
}


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

using namespace std;

const int MAXN = 1000 * 1000 + 10;

int arr[MAXN];

int main()
{
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //cout << fixed << setprecision(10);

    int n;
    cin>>n;
    long long ans=0;
    long long pos;
    cin >> pos;
    for(int i=1;i<n;i++){
        long long a;
        cin>>a;
        if(pos > a) ans += pos - a;
        pos = max(a,pos);
    }
    cout<< ans <<endl;
    return 0;
}



Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int mod=1e9+7;
const int nmax=1000010;
ll fac[nmax],finv[nmax],inv[nmax];
 
void COMinit(){
  fac[0]=fac[1]=1;
  finv[0]=finv[1]=1;
  inv[1]=1;
  for(int i=2;i<nmax;i++){
    fac[i]=fac[i-1]*i%mod;
    inv[i]=mod-inv[mod%i]*(mod/i)%mod;
    finv[i]=finv[i-1]*inv[i]%mod;
  }
}
ll pow_mod(ll n,ll k,ll m){
  ll res=1;
  for(;k>0;k>>=1){
    if(k&1){
      res=(res*n)%m;
    }
    n=(n*n)%m;  
  }
  return res;
}
int main(){
  int n;cin >> n;
  COMinit();
  vector<int> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  vector<int> p(1000005);
  for(int i=0;i<n;i++){
    int num=a[i];
    for(int j=2;j*j<=num;j++){
      int cnt=0;
      while(num%j==0){
        num/=j;
        cnt++;
      }
      p[j]=max(p[j],cnt);
    }
    if(num!=1){
      p[num]=max(p[num],1);
    }
  }
  ll lcm=1,ans=0;
  for(int i=2;i<=1000000;i++){
    if(p[i]){
      lcm=lcm*pow_mod(i,p[i],mod)%mod;
    }
  }
  for(int i=0;i<n;i++){
    ans+=lcm*inv[a[i]]%mod;
    ans%=mod;
  }
  cout << ans << endl;
}

Measured memory_bytes: 27648
#include <stdio.h>

int A[1000000];

int  main(){
  int i,n,key,temp,big=0,sml=0;

  scanf("%d",&n);
  for(i=0;i<n;i++)
    scanf("%d",&A[i]);

  key = A[n-1];
 
  for(i=0;i<n-1;i++){
    if(i == 0 && key >= A[i]){
      sml++;
      big++;
    }
    else if(key >= A[i]){
      temp = A[i];
      A[i] = A[sml];
      A[sml] = temp;
      sml++;
      big++;
    }
    else
      big++;
  }
  
  temp = key;
  A[n-1] = A[sml];
  A[sml] = temp;

  printf("%d",A[0]);
  for(i=1;i<n;i++){
    if(i == sml)
      printf(" [%d]",A[i]);
    else printf(" %d",A[i]);
  }
  printf("\n");

  return 0;
}



Measured memory_bytes: 2128
c = {
  'AC': 0,
  'WA': 0,
  'TLE': 0,
  'RE': 0
}

N = int(input())
for i in range(N):
  c[input().strip()] += 1

for t in ['AC', 'WA', 'TLE', 'RE']:
  print(f"{t} x {c[t]}")

Measured memory_bytes: 9188
a = [1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51]
N = int(input())
print(a[N-1])

Measured memory_bytes: 3060
#!/usr/bin/env python3
import sys

YES = "Yes"  # type: str
NO = "No"  # type: str


def solve(K: int, X: int):
    if 500*K >= X:
        print(YES)
    else:
        print(NO)
    return


# Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
def main():
    def iterate_tokens():
        for line in sys.stdin:
            for word in line.split():
                yield word
    tokens = iterate_tokens()
    K = int(next(tokens))  # type: int
    X = int(next(tokens))  # type: int
    solve(K, X)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
using namespace std;
const char* solve() {
    int N, M, K;
    cin >> N >> M >> K;
    for (int k = 0; k <= N; k++) {
        int t1 = K - k * M, t2 = N - 2 * k;
        if (0 <= t1 && t1 <= M * t2 && t1 % t2 == 0) return "Yes";
    }
    return "No";
}
int main() {
    cout << solve() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef int ll;
typedef long double ld;
const ll N = 100005;
char en = '\n';
ll inf = 1e17;
ll mod = 1e9 + 7;
ll power(ll x, ll n, ll mod) {
  ll res = 1;
  x %= mod;
  while (n) {
    if (n & 1)
      res = (res * x) % mod;
    x = (x * x) % mod;
    n >>= 1;
  }
  return res;
}

ll n, q;
ll nxt[N][30];
char arr[N];
ll dp[255][255][255];

string a, b, c;

ll recur(ll posa, ll posb, ll posc) {

  if (posa == 0 && posb == 0 && posc == 0)
    return 0;
  ll &ans = dp[posa][posb][posc];
  if (ans != -1)
    return ans;

  ans = n + 1;
  if (posa) {
    ll len = recur(posa - 1, posb, posc);
    //  cout << posa << " " << len << endl;
    ans = min(ans, nxt[len + 1][a[posa] - 'a']);
  }
  if (posb) {
    ll len = recur(posa, posb - 1, posc);
    ans = min(ans, nxt[len + 1][b[posb] - 'a']);
  }
  if (posc) {
    ll len = recur(posa, posb, posc - 1);
    ans = min(ans, nxt[len + 1][c[posc] - 'a']);
  }

  return ans;
}

int32_t main() {
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);

  ll n, m;
  cin >> n >> m;

  ll sum1 = 0;
  ll sum2 = 0;
  for (ll i = 1; i <= n; i++) {
    ll x;
    cin >> x;

    x = (x % mod + mod) % mod;
    sum2 += x;
    sum2 = (sum2 % mod + mod) % mod;

    sum1 += i * x % mod - sum2;
    sum1 = (sum1 % mod + mod) % mod;
  }

  ll stx = sum1;

  sum1 = 0;
  sum2 = 0;
  for (ll i = 1; i <= m; i++) {
    ll x;
    cin >> x;
    x = (x % mod + mod) % mod;
    sum2 += x;

    sum2 = (sum2 % mod + mod) % mod;

    sum1 += i * x % mod - sum2;
    sum1 = (sum1 % mod + mod) % mod;
  }

  cout << stx * sum1 % mod << en;

  return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <map>
#include <deque>
using namespace std;

#define REP(i,n) for(int i = 0; i < n; i++)
#define ALL(v) v.begin(),v.end()
typedef long long ll;
typedef pair<int,int> pi;
typedef pair<ll,ll> pll;
typedef pair<string,string> pss;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<pi> vpi;
typedef vector<ll> vll;
typedef vector<vll> vvll;

double EPS = 1e-9;
int INFi = 1000000005;
long long INFll = 1000000000000000005ll;
double PI = acos(-1);
int dirx[8] = {-1,0,0,1,-1,-1,1,1};
int diry[8] = {0,1,-1,0,-1,1,-1,1};
ll MOD = 1000000007;

// #define MAX_N 100000
// ll n, a, b;
// ll h[MAX_N];

int main(){
  int n;
  cin >> n;
  ll a[3*n];
  REP(i,3*n)cin >> a[i];

  priority_queue<ll, vll, greater<ll>> pqf;

  ll sum = 0;

  REP(i,n){
    sum += a[i];
    pqf.push(a[i]);
  }
  ll f[n+1];
  f[0] = sum;
  REP(i,n){
    sum += a[n+i];
    pqf.push(a[n+i]);
    sum -= pqf.top();
    pqf.pop();
    f[i+1] = sum;
  }

  //back

  priority_queue<ll> pqb;

  sum = 0;

  REP(i,n){
    sum += a[3*n-1-i];
    pqb.push(a[3*n-1-i]);
  }
  ll b[n+1];
  b[n] = sum;
  REP(i,n){
    sum += a[2*n-1-i];
    pqb.push(a[2*n-1-i]);
    sum -= pqb.top();
    pqb.pop();
    b[n-1-i] = sum;
  }

  ll ma = -INFll;
  REP(i,n+1){
    ma = max((f[i] - b[i]), ma);
    // cout << "i " << i << " f " << f[i] << " b " << b[i] << endl;
  }

  cout << ma << endl;



  return 0;
}


Measured memory_bytes: 5876
#include<stdio.h>
#include<stdlib.h>
int main(void){
    int N;
    long *num_mon;
    long *num_beat;

    scanf("%d",&N);
    num_mon=(long *)malloc(sizeof(long)*(N+1));
    num_beat=(long *)malloc(sizeof(long)*N);
    int i;
    for(i=0;i<N+1;i++){
        scanf("%ld",&num_mon[i]);
    }
    long count=0;
    for(i=0;i<N;i++){
        scanf("%ld",&num_beat[i]);
        if(num_beat[i]<=num_mon[i]){
            num_mon[i]-=num_beat[i];
            count+=num_beat[i];
        }
        else if(num_beat[i]>num_mon[i]){
            count+=num_mon[i];
            num_beat[i]-=num_mon[i];
            num_mon[i]=0;
            if(num_beat[i]<=num_mon[i+1]){
                num_mon[i+1]-=num_beat[i];
                count+=num_beat[i];
            }
            else if(num_beat[i]>num_mon[i+1]){
                count+=num_mon[i+1];
                num_mon[i+1]=0;
            }
        }
    }
    printf("%ld",count);
    return 0;
}

Measured memory_bytes: 1792
#include <stdio.h>
int main(){
  int a[4][3][10],i,j,k,n,b,f,v,r;
  for(i=0; i<4; i++){
    for(j=0; j<3; j++){
      for(k=0; k<10; k++){
        a[i][j][k]=0;
      }
    }
  }
  scanf("%d\n",&n);
  for(i=0; i<n; i++){
    scanf("%d %d %d %d\n",&b,&f,&r,&v);
    a[b-1][f-1][r-1]+=v;
  }
  for(i=0; i<4;	i++){
    for(j=0; j<3; j++){
      for(k=0; k<10; k++){
        printf(" %d",a[i][j][k]);
        if(k==9)printf("\n");
	if(k==9&&j==2&&i<3)printf("####################\n");
      }
    }
  }
  return 0;
}

Measured memory_bytes: 616
#include <iostream>
#include <vector>
#define rep(i, n) for (int i = 0, i##_len = (n); i < i##_len; ++i)
using namespace std;

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

struct Class
{
    Class() = default;
    Class(int _MP, const vector<int> &_i)
        : MP(_MP), indexes(_i)
    {
    }
    int MP;
    vector<int> indexes;
};

bool operator== (const Class& value, const Class& other)
{
    for (int i = 0; i < value.indexes.size(); ++i)
    {
        for (int k = 0; k < other.indexes.size(); ++k)
        {
            if (value.indexes[i] == other.indexes[k])
            {
                return true;
            }
        }
    }
    return false;
}

int main()
{
    int N, A, B, C;
    cin >> N >> A >> B >> C;
    vector<int> L(N);
    rep (i, N) { cin >> L[i]; }

    int num[3] = { A, B, C };

    vector<Class> rem[3];
    for (int i = 0; i < 3; ++i)
    {
        int t = num[i];

        for (int bit = 0; bit < (1 << N); ++bit)
        {
            int MP = 0;
            vector<int> use;
            int sum = 0;
            for (int k = 0; k < N; ++k)
            {
                if (bit & (1 << k))
                {
                    sum += L[k];
                    MP += 10;
                    use.push_back(k);
                }
                
            }
            if (use.empty())
            {
                continue;
            }
            MP += abs(sum - t) - 10;

            rem[i].push_back(Class(MP, use));
        }
    }

    long long min = 10e9 + 7;
    for (int i = 0; i < rem[0].size(); ++i)
    {
        for (int k = 0; k < rem[1].size(); ++k)
        {
            for (int m = 0; m < rem[2].size(); ++m)
            {
                if (rem[0][i] == rem[1][k])
                {
                    continue;
                }
                if (rem[1][k] == rem[2][m])
                {
                    continue;
                }
                if (rem[2][m] == rem[0][i])
                {
                    continue;
                }
                chmin(min, (long long) rem[0][i].MP + rem[1][k].MP + rem[2][m].MP);
            }
        }
    }

    cout << min << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(n);i++)
#define N 100010
#define INF 10000000000
typedef long long ll;
#define ALL(v) (v).begin(),(v).end()
#define SZ(x) int(x.size())
#define IN(a) cin>>(a)
#define OUT(a) cout<<(a)<<endl
typedef pair<int,int> P;
const int MAX = 1000000;
const int MOD = 1000000007;
int main(){
    int w,h,x,y;
    cin>>w>>h>>x>>y;
    int t=0;
    if(w==2*x&&h==2*y)t=1;
    double ans=(double)w*h/2;
    printf("%.10lf\n",ans);
    OUT(t);
	return 0;
}

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

#define debug(x) cout <<"DEBUG"<<" "<< #x << ":" << x << '\n'

// n回繰り返し
#define rep(i,n) for(int i = 0; i < ((int)(n)); i++)   // 0-indexed昇順
#define rep1(i,n) for(int i = 1; i <= ((int)(n)); i++) // 1-indexed昇順
#define rrep(i,n) for(int i = ((int)(n)-1); i >= 0; i--)  // 0-indexed降順
#define rrep1(i,n) for(int i = ((int)(n)); i >= 1; i--)   // 1-indexed降順
#define all(x) (x).begin(),(x).end()

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vi> vii;  // 2次元配列
typedef vector<ll> vll;
typedef vector<double> vd;
typedef pair<int, int> PII;

template<typename T>
using vec = vector<T>;
template<class T>
using maxheap = std::priority_queue<T>;
template<class T>
using minheap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

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

const ld Pi = std::acos(-1.0L);
const ll infll = (1LL<<62)-1;
const int inf = (1<<30)-1;
const int mod = 1000000007;
// const int mod = 998244353;


/*FUNCs=================================================*/


/*MAIN==================================================*/
signed main(){
    int _StartTime_ = clock();
    cin.tie(nullptr);
    ios::sync_with_stdio(false);   //cin cout 高速化
    // cout << fixed << setprecision(15);

    ll n; cin >> n;
    ll ans = (1+n-1)*(n-1)/2;
    cout << ans << '\n';

    // printf("ExecutionTime: %d /ms\n",1000*(int)((clock()-_StartTime_)/CLOCKS_PER_SEC));
}

Measured memory_bytes: 256
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <math.h>

using namespace std;

#define PI 3.14159265358979323846264338327950

int main() {
	long double A, B, H, M;

	cin >> A >> B >> H >> M;

	long double h, m,kaku;
	m = (long double)M / 60 * 2 * PI;
	h = ((long double)H / 12 + (long double)M / 720) * 2 * PI;
	kaku = fabs(m - h);

	long double ans;

	ans = A * A + B * B - 2 * A * B * cos(kaku);
	ans = sqrt(ans);
	cout << fixed << setprecision(20) << ans << endl;

	return 0;
}

Measured memory_bytes: 4152
n = int(input())
v_li = list(map(int,input().split()))
v_li.sort()
ans = 0
j = 2
for i,v in enumerate(v_li):
    if i<2:
        ans += v/2**(n-1)
    else:
        ans += v/2**(n-j)
        j += 1
print(ans)

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
int n;
int ans;
int a[200005];
int main() {
	cin >> n;
	for(int i=1; i<=n; i++) {
		cin >> a[i];
		if(a[i]==ans+1) ans++;
	}
	if(ans==0) cout<<-1<<endl; else
	cout<<n-ans<<endl; 
}


Measured memory_bytes: 1024
import sys

sys.setrecursionlimit(10 ** 6)
INF = float("inf")
MOD = 10 ** 9 + 7


def input():
    return sys.stdin.readline().strip()


def main():
    N, M = map(int, input().split())
    X = list(map(int, input().split()))
    X.sort()

    dist = []
    for i in range(1, M):
        dist.append(X[i] - X[i - 1])

    dist.sort(reverse=True)

    if N >= M:
        print(0)
    else:
        # N - 1個の開いた区間が出てくる
        ans = sum(dist[N - 1 :])
        print(ans)


if __name__ == "__main__":
    main()


Measured memory_bytes: 13960
#include<bits/stdc++.h>
#define MAXN 200005

using namespace std;

vector <int> v[MAXN];
bool vis [MAXN] = {false};
long long memo[MAXN]={0} ;


void dfs (int u){
	
  if ( vis[u]== false ){
		vis[u]= true;
		for ( int i=0; i<v[u].size();i++ ){
			int t = v[u][i];
			if (vis[t] == false){
				memo[t] += memo[u];
				dfs( t );	
			}
		}
	}
}


int main (){
	
	//freopen("t.txt","r",stdin);
	int n,q,a,b,p,x; 
	cin>>n>>q;
	
	for (int i=1;i<=n-1;i++){
		int a,b; cin>>a>>b;
		v[a].push_back (b);
		v[b].push_back (a);
	}
	
	for (int i=1;i<=q;i++){
		cin>>p>>x; memo[p]+=x;
	}
	
	dfs(1);
	for (int i=1;i<=n;i++){
		cout<< memo[i]<<" ";
	}
	
	return 0;
}

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

int n,cnt,head[100001],st,ed,res;
struct gg
{
	int x,y;
}red[101],blue[101];
struct node
{
	int x,y,c,next,other;
}e[2000001];
void add(int x,int y,int c)
{
//	cout<<x<<" "<<y<<endl;
	int k1,k2;
	cnt++;
	k1=cnt;
	e[cnt].x=x;
	e[cnt].y=y;
	e[cnt].c=c;
	e[cnt].next=head[x];
	head[x]=cnt;
	cnt++;
	k2=cnt;
	e[cnt].x=y;
	e[cnt].y=x;
	e[cnt].c=0;
	e[cnt].next=head[y];
	head[y]=cnt;
	e[k1].other=k2;
	e[k2].other=k1;
}
int q[100001],h,t,dep[100001];
int bfs()
{
	memset(dep,0,sizeof(dep));
	dep[st]=1;
	q[1]=st;
	h=1;
	t=2;
	while(h!=t)
	{
		int x=q[h];
		for(int i=head[x];i;i=e[i].next)
		{
			int y=e[i].y;
			if(e[i].c>0&&dep[y]==0)
			{
				dep[y]=dep[x]+1;
				q[t++]=y;
			}
		}
		h++;
	}
	if(dep[ed]>0)
	return 1;
	else
	return 0;
}
int findflow(int x,int f)
{
	if(x==ed)
	return f;
	int s=0,t;
	for(int i=head[x];i;i=e[i].next)
	{
		int y=e[i].y;
		if(e[i].c>0&&dep[y]==(dep[x]+1)&&s<f)
		{
			s+=(t=findflow(y,min(e[i].c,f-s)));
			e[i].c-=t;
			e[e[i].other].c+=t;
		}
	}
	if(s==0)
	dep[x]=0;
	return s;
}
//201³¬¼¶Ô´ 202³¬¼¶»ã 
int main()
{
	st=201;
	ed=202;
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&red[i].x,&red[i].y);
	}
	for(int i=1;i<=n;i++)
	{
		scanf("%d%d",&blue[i].x,&blue[i].y);
	}
	for(int i=1;i<=n;i++)
	{
		add(201,i,1);
	}
	for(int i=1;i<=n;i++)
	{
		add(i+100,202,1);
	}
	for(int i=1;i<=n;i++)
	{
		for(int j=1;j<=n;j++)
		{
			if(red[i].x<blue[j].x&&red[i].y<blue[j].y)
			{
				add(i,j+100,1);
			}
		}
	}
	while(bfs())
	{
		res+=findflow(st,2e9);
	}
	printf("%d\n",res);
	return 0;
}

Measured memory_bytes: 768
#include<iostream>
#include<bits/stdc++.h>
#define ll long long
using namespace std;
int main()
{
    ll n;
    cin>>n;
    ll arr[n][3];
    for(ll i=0;i<n;i++)
        for(ll j=0;j<3;j++)
           cin>>arr[i][j];
    ll dp[n][3];
    dp[0][0]=arr[0][0];
    dp[0][1]=arr[0][1];
    dp[0][2]=arr[0][2];
    for( ll i=1;i<n;i++)
    {
       for(ll j=0;j<3;j++)
       {
            dp[i][j]=arr[i][j]+max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3]);
       }
    }
    cout<<max(max(dp[n-1][0],dp[n-1][1]),dp[n-1][2]);
}


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

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

    if(a-k>0){
        cout << a-k << " " << b << endl;
    }else if(a+b-k>0){
        cout << 0 << " " << a+b-k << endl;
    }else{
        cout << 0 << " " << 0 << endl;
    }
}


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

int main()
{
    int a;
    string s;

    cin>>a>>s;

    if(a>=2800&&a<5000)
    {
        if(a<3200)
        {
            cout<<"red"<<endl;
        }

        else
        {
            cout<<s<<endl;
        }
    }
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	int w, h, count, cb, cw;
	int[][] map;
	boolean black, white;
	
	public void func(){
		for(int i=0;i<h;i++){
			for(int j=0;j<w;j++){
				if(map[i][j]==0){
					count = 0;
					black = true;
					white = true;
					loop(i, j);
					if(black==false && white==true){
						cb += count;
					}else if(black==true && white==false){
						cw += count;
					}
				}
			}
		}
		System.out.println(cb + " " + cw);
	}
	
	public void loop(int y, int x){
		if(map[y][x]==8){
			black = false;
		}else if(map[y][x]==9){
			white = false;
		}else if(map[y][x]==0){
			map[y][x] = 1;
			count++;
			if(y!=0) loop(y-1,x);
			if(x!=0) loop(y,x-1);
			if(y!=h-1) loop(y+1,x);
			if(x!=w-1) loop(y,x+1);
		}
	}
	
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		
		while(true){
			Main A = new Main();
			A.w = sc.nextInt();
			A.h = sc.nextInt();
			if(A.w==0 && A.h==0)break;
			A.map = new int[A.h][A.w];
			String s = "";
			for(int i=0;i<A.h;i++){
				s = sc.next();
				for(int j=0;j<A.w;j++){
					if(s.codePointAt(j)==66) A.map[i][j]=8;
					else if(s.codePointAt(j)==87) A.map[i][j]=9;
				}
			}
			A.func();
			
		}
	}	
}

Measured memory_bytes: 30264
//
// Created by Myabu on 2020/01/26.
//

#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <map>
#include <utility>
#include <math.h>
#include <stack>
#include <queue>
#include <cstdio>
#include <numeric>
#include <iomanip>

using namespace std;


int main(void){
    string S;

    cin>>S;

    bool yymm = false;
    bool mmyy = false;
    if(stoi(S.substr(0,2)) <= 12 && stoi(S.substr(0,2)) > 0){
        mmyy = true;
    }

    if(stoi(S.substr(2,2)) <= 12 && stoi(S.substr(2,2)) > 0) {
        yymm = true;
    }


    if(mmyy && yymm){
        cout<<"AMBIGUOUS"<<endl;
    }else if(mmyy){
        cout<<"MMYY"<<endl;
    }else if(yymm){
        cout<<"YYMM"<<endl;
    }else{
        cout<<"NA"<<endl;
    }



        return 0;
}

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

using namespace std;

typedef long long ll;

int N;
ll C, x[100000], v[100000];
ll best[100000 + 10];

const ll INF = 1145141919810893;

int main() {
	cin >> N >> C;
	for (int i = 0; i < N; i++)cin >> x[i] >> v[i], best[i] = INF;

	ll ans = 0;
	{
		//反時計回りを事前計算して、時計回り方向の区間の終端を全探索
		ll eiyou = 0;
		best[N] = 0;//反時計回り方向で何も食べに行かない
		for (int i = N - 1; i >= 0; i--) {
			eiyou += v[i];
			ll cost = eiyou - C + x[i];
			best[i] = max(best[i + 1], cost);
		}

		eiyou = 0;
		for (int i = 0; i < N; i++) {
			ll tmp = 0;
			eiyou += v[i];
			tmp = eiyou - x[i];
			ans = max(ans, tmp);

			tmp -= x[i];
			tmp += best[i + 1];
			ans = max(ans, tmp);
		}
	}
	
	{

		//時計回りを事前計算して、反時計回り方向の区間の終端を全探索
		ll eiyou = 0;
		best[0] = 0;
		for (int i = 1; i <= N; i++) {
			eiyou += v[i - 1];
			ll cost = eiyou - x[i - 1];
			best[i] = max(best[i - 1], cost);
		}

		eiyou = 0;
		for (int i = N - 1; i >= 0; i--) {
			ll tmp = 0;
			eiyou += v[i];
			tmp = eiyou - (C - x[i]);
			ans = max(ans, tmp);

			tmp -= (C - x[i]);
			tmp += best[i];
			ans = max(ans, tmp);
		}
	}
	
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 2560
#include<stdio.h>

int main()
{
    long long int i, a, b, c, d,ans;
    long long int e,f,j,z;
    scanf("%lld%lld%lld%lld", &a, &b, &c, &d);

    z=a*c;
    e=a*d;
    f=b*c;
    j=b*d;
    //i = z;
   if(z>e&&z>f&&z>j)ans=z;
   else if(e>z&&e>f&&e>j)ans=e;
   else if(f>e&&f>z&&f>j)ans=f;
   else
    ans=j;
   printf("%lld",ans);

   return 0;
}

Measured memory_bytes: 1728
#include<iostream>
#include<vector>
#include<algorithm>
#include<functional>
#include<queue>
#include<stack>
#include<set>
#include<map>
#include<unordered_map>
#include<climits>
#include<cstdlib>
#include<cmath>
#include<string>
#include<iomanip>
#include<bitset>

using namespace std;

#define ll long long int

ll const MOD = 1000000007;
ll const INF = (long long int)1 << 61;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    ll n;
    cin >> n;
    ll a,b;
    cin >> a >> b;
    vector<ll> p(n);
    for(int i = 0; i < n; i++){
        cin >> p[i];
    }    
    vector<ll> c(3,0);

    for(int i = 0; i < n; i++){
        if(p[i] <= a){
            c[0]++;
        }else if(p[i] <= b){
            c[1]++;
        }else{
            c[2]++;
        }
    }

    cout << min(c[0],min(c[1],c[2])) << endl;
    return 0;
}

Measured memory_bytes: 256
import math
X,Y=map(int,input().split())
mod=pow(10,9)+7
if (X+Y)%3!=0:
    print(0)
else:
    m=(X*2-Y)//3
    n=X-2*m
    if n<0 or m<0:
        print(0)
    else:
        def comb(a,b):
            x=1
            for i in range(a-b+1,a+1):
                x*=i
                x%=mod
            y=1
            for j in range(1,b+1):
                y*=j
                y%=mod
            return x*pow(y,mod-2,mod)%mod
        print(comb(n+m,n))
        

Measured memory_bytes: 39408
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define repr(i, a, b) for(int i = a; i < b; i++)
#define  all(x) (x).begin(),(x).end()     // 昇順ソート
#define  rall(v) (v).rbegin(), (v).rend() // 降順ソート
#define  FastIO ios_base::sync_with_stdio(0),cin.tie(0),cout.tie(0)
typedef long long ll;
typedef long long int lli;
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; }

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

int main(){
    FastIO;
    ll n, k;
    cin >> n >> k;
    vector<ll> a(n);
    rep(i, n){
        ll ai;
        cin >> ai;
        ai--;
        a[i] = ai;
    } 
    ll startP = 0;
    ll cnt = 0;
    map<int, int> m;
    m[0] = 0;
    while(true){
        startP = a[startP];
        cnt++;
        if (cnt == k){
            cout << startP+1 << endl;
            return 0;
        }
        if(m.count(startP)){
            break;
        }else{
            m[startP] = cnt;
        }
    }
    ll loopCnt = (k-m[startP]) % (cnt - m[startP]);
    ll ans = startP;
    while(loopCnt > 0){
        ans = a[ans];
        loopCnt--;
    }
    cout << ans+1 << endl;

}

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

#define ll long long int
#define MAXN 500005

ll A[MAXN];

int main() {
    string S;
    cin >> S;
    int N = S.length() + 1;
    
    for (int i = 0; i < N; ++i) {
        A[i] = 0;
    }
    
    for (int i = 1; i < N; ++i) {
        if (S[i - 1] == '<')
            A[i] = max(A[i], A[i - 1] + 1);
    }
    
    for (int i = N - 2; i >= 0; --i) {
        if (S[i] == '>')
            A[i] = max(A[i], A[i + 1] + 1);
    }
    
    ll ans = 0;
    for (int i = 0; i < N; ++i) {
        ans += A[i];
    }
    
    cout << ans << '\n';
    
    return(0);
}


Measured memory_bytes: 4740
#include <bits/stdc++.h>
#include <math.h>
#include <cmath>

using namespace std;
using ll =long long;
using vi = vector<int>; 
using vvi = vector<vi>; 
using vl = vector<ll>; 
using vvl = vector<vl>; 
using vs = vector<string>;
using vvs = vector<vs>; 
using vc = vector<char>;
using vvc = vector<vc>; 
using vb = vector<bool>;
using vvb = vector<vb>; 

#define rep(i,n) ;for( int i =0; i < n ; i ++)
#define all(a) a.begin(),a.end()
#define pb(a) push_back(a)
#define pd(a) printf("%.10f\n",a)
#define mem(a) memset(a,0,sizeof(a))
#define f(i,a,b) for(int i=a;i<b;i++)
#define pri(a)  printf("%.14lf\n",a);
#define MOD 1000000007
bool is_int_lround(double x){
  return std::lround(x)==x;
}
ll keta(ll x){
  ll n=0;
  while(x>0){
    x /=10 ;
    n ++;
  }
  return n;
}

ll conbi(int n,int m){
  
  cin>>n>>m;
  vector<ll> a(100);
  a[0] =1;
  for(int i=0;i<14;i++){
    a[i+1]=a[i]*(i+1);
  }
  return a[n] /(a[m] *a[n-m]);
}

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;//繰り返し二乗法
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}
ll kaijo(ll x){
  ll z=1;
  if(x==0){
    return 1;
  }
  while(x>0){
    z *=x;
    z %=MOD;
    x--;
  }
  return z;
}
ll yakusu_num(ll n){
  vl yakusu(n+1,1);
  for(ll i=2;i*i<=n;i++){ 
    while(n%i==0){
      n /=i;
      yakusu[i]++;
    }
  }
  if(n!=1)yakusu[n]++;
  ll num=1;
  for(ll i=0;i<=n;i++){
    num*=yakusu[i];
  }
  return num;
}

int H,W;
vs s(50);
vi dv ={-1,0,1,0};vi du={0,-1,0,1};
int cnt=1;
int dfs(int u,int v){
  s[u][v]='.';
  
  rep(i,4){
   
      int nu =u +du[i],nv=v+dv[i];
      if(nu<0||nu>=H||nv<0||nv>=W)continue;
      if(s[nu][nv]=='.')continue;
      cnt ++;
      dfs(nu,nv);
    
  }
  return cnt;

}
int keta_wa(int x){
  int tot=0;
  while(x>0){
    tot +=x%10;
    x/=10;
  }
  return tot;
}

//vc alp ={'a','b','c','d','e','f','g','h','i','j','k','l','m','n','o','p','q','r','s','t','u','v','w','x','y','z'};
//cout<<""<<endl;
int main(){
  string s;cin>>s;
  cout<<s[0]<<s.size()-2<<s[s.size()-1]<<endl;
  
  
}







Measured memory_bytes: 256
//Space: O(1) Time: O(n)
#include<bits/stdc++.h>
#define MOD 1000000007
#define ll long long int
using namespace std;
int main(){
int n,a,b,c,d,p,temp;
cin>>n;
cin>>c>>d;
a=0; b=abs(c-d);
for(int i=2; i<n; i++){
    cin>>p; 
    temp=b;    
    b=min(b+abs(p-d),a+abs(p-c)); 
    a=temp;
    c=d; d=p;
}
cout<<b;
return 0;
}


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

int main(){
  int n,a[100010],b[100010],c[100010],cost=0;
  cin>>n;
  a[0]=0;
  a[n+1]=0;

  for(int i=1;i<=n;++i){
        cin>>a[i];
        cost+=abs(a[i-1]-a[i]);
  }

  for(int i=1;i<=n;++i){
    b[i]=abs(a[i]-a[i-1])+abs(a[i+1]-a[i]);
    c[i]=abs(a[i+1]-a[i-1]);
  }

  cost+=abs(a[n]);

  for(int i=1;i<=n;++i){
    cout << cost-b[i]+c[i] << endl;
  }

  return 0;
}


Measured memory_bytes: 2432
#include <iostream>
#include <stack>
#include <string>
#include <cstdlib>
using namespace std;

stack<int> s;

int calc(string str){
    int x = s.top();
    s.pop();
    int y = s.top();
    s.pop();
    
    switch(str[0]){
        case '+':
            return x+y;
        case '-':
            return y-x;
        case '*':
            return x*y;
    }
    return y/x;
}

void judge(){
    string str;
    
    while(cin >> str){
        if(str=="+"||str=="-"||str=="*"||str=="/"){
            s.push(calc(str));
        }
        else{
            s.push(atoi(str.c_str()));
        }
    }
    cout << s.top() << endl;
}


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

Measured memory_bytes: 1204
#include<cstdio>
#include<algorithm>
#define fo(i,a,b) for(i=a;i<=b;i++)
using namespace std;
const int maxn=100000+10;
int h[maxn],go[maxn*2],nxt[maxn*2],bit[maxn],f[maxn];
int i,j,k,l,t,n,m,tot,top,ans;
void add(int x,int y){
    go[++tot]=y;
    nxt[tot]=h[x];
    h[x]=tot;
}
void dfs(int x,int y){
    bit[x]=f[x]=0;
    int t=h[x],l=0;
    while (t){
        if (go[t]!=y){
            dfs(go[t],x);
            l=max(l,(bit[x]&bit[go[t]]));
            bit[x]|=bit[go[t]];
        }
        t=nxt[t];
    }
    if (!bit[x]) bit[x]=1;
    else{
        while ((1<<f[x])<=l||(1<<f[x])&bit[x]) f[x]++;
        bit[x]=(bit[x]>>f[x]<<f[x])|(1<<f[x]);
    }
    ans=max(ans,f[x]);
}
int main(){
    scanf("%d",&n);
    fo(i,1,n-1){
        scanf("%d%d",&j,&k);
        add(j,k);add(k,j);
    }
    dfs(1,0);
    printf("%d\n",ans);
}

Measured memory_bytes: 6272