akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
int n,k;
int a[1001];
int turn = 0;
int dp[100001][2];


int recur(int k, int turn){
    if(dp[k][turn] != -1) return dp[k][turn];
    if(k < a[0]) return 1 - turn;
    for(int i = 0; i < n; i++){
        if(k - a[i] >= 0 && recur(k - a[i],1-turn) == turn){
            return dp[k][turn] = turn;
        }
    }
    return dp[k][turn] = 1 - turn;
}


int main(){
    cin>>n>>k;
    memset(dp,-1,sizeof dp);
    for(int i = 0; i < n; i++){
        cin>>a[i];
    }
    sort(a,a+n);
    if(recur(k,0) == 0)cout<<"First";
    else cout<<"Second";
}

Measured memory_bytes: 5760
/*
 Author : Bisma
 @ copy from bisma template 1.0
 */
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <sstream>
#include <queue>
#include <deque>
#include <bitset>
#include <iterator>
#include <list>
#include <stack>
#include <map>
#include <set>
#include <functional>
#include <numeric>
#include <utility>
#include <limits>
#include <time.h>
#include <math.h>
#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <assert.h>
#include <iomanip>
#include <fstream>
#include <cstdio>
using namespace std;
#define rep(a,b,c) for(int a=b;a<=c;a++)
#define repn(a,b,c) for(int a=b; a>=c; a--)
#define ll long long
#define mem(a, b) memset(a, (b), sizeof(a))
#define loop(a,b,c) for(int a = b ;a<c;a++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define fi first
#define se second
using namespace std;

ll max(ll a, ll b){
    if(a>b) return a;
    return b;
}

ll min(ll a, ll b){
    if(a>b) return b;
    return a;
}

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
}



int main(){
    fast();

    ll a,b,c;
    cin>>a>>b>>c;
    if(a >= c && c>=b){
        cout<<"Yes"<<endl;
        return 0;
    }else if(a <= c && c<=b){

        cout<<"Yes"<<endl;
        return 0;
    }


    cout<<"No"<<endl;


    return 0;
    
}
 






Measured memory_bytes: 256
#include <bits/stdc++.h>
#define LL long long
#define Accel ios::sync_with_stdio(0), cin.tie(0), cout.tie(0);
#define Re(a,b) memset(a,b,sizeof a)
#define F first
#define S second
#define MP make_pair
#define PB push_back
#define ALL(X) (X).begin(), (X).end()
#define FOR(I, A, B) for (int I = (A); I <= (B); I++)
#define REP(I, N) for (int I = 0; I < (N); I++)
#define MID ((l+r)>>1)
#define lc (rt<<1)
#define rc (rt<<1|1)
#define ls lc,l,MID
#define rs rc,MID+1,r
#define st 1,1,n
#define PII pair<int,int>
#define PLL pair<LL,LL>
using namespace std;
//LL pw(LL a, LL b,LL M) { return b ? b & 1 ? a*pw(a, b - 1,M) % M : pw(a*a%M, b>>1,M) : 1; }
//void add(int x){while(x<N)BIT[x]++,x+=x&-x;}
//int sum(int x){return x?BIT[x]+sum(x-(x&-x)):0;}
const int N=1e5+1;
const LL M=1e18;
int main(){Accel
	string s;
	cin>>s;
	s[3]='8';
	cout<<s<<endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pii;
const int maxn=1e6+5;
int main() {
	int n,m,k;cin>>n>>m>>k;
	std::vector<string> buff(n+1);
	std::vector<std::vector<int>> dis(n+1,vector<int>(m+1));
	int x1,x2,y1,y2;cin>>y1>>x1>>y2>>x2;
	x1--;x2--;y1--;y2--;
	for(int i=0;i<n;i++) cin>>buff[i];
	for(int i=0;i<n;i++) 
		for(int j=0;j<m;j++) 
			if(buff[i][j]=='@') dis[i][j]=1;
    queue<pii> Q;dis[y1][x1]=1;
    Q.emplace(y1,x1);
    static int dx[]={0,0,1,-1};
    static int dy[]={1,-1,0,0};
    while(!Q.empty()) {
    	auto [y,x]=Q.front();Q.pop();
    	for(int i=0;i<4;i++) {
    		for(int j=1;j<=k;j++) {
    			auto [ny,nx]=pii{y+dy[i]*j,x+dx[i]*j};
    			if(ny<0||ny>=n||nx<0||nx>=m||(dis[ny][nx]&&dis[ny][nx]<=dis[y][x])) break;
    			if(!dis[ny][nx]||dis[y][x]+1<dis[ny][nx]) {
	    			dis[ny][nx]=dis[y][x]+1;
	    			Q.emplace(ny,nx);
    			}
    		}
    	}
    }
    // for(int i=1;i<=n;i++){for(int j=1;j<=m;j++) cout<<dis[i-1][j-1]<<' ';cout<<endl;}
    cout<<dis[y2][x2]-1<<endl;
    return 0;
}


Measured memory_bytes: 14736
from heapq import heappush, heappop


coordinate_list = []
n = int(input())
for i in range(n):
    x, y = map(int, input().split())
    coordinate_list.append((i, (x, y)))


graph = [[] for i in range(n)]


coordinate_list.sort(key = lambda x: x[1][0])
for i in range(n - 1):
    cost = coordinate_list[i + 1][1][0] - coordinate_list[i][1][0]
    graph[coordinate_list[i][0]] += [(cost, coordinate_list[i+1][0])]
    graph[coordinate_list[i + 1][0]] += [(cost, coordinate_list[i][0])]


coordinate_list.sort(key = lambda x: x[1][1])
for i in range(n - 1):
    cost = coordinate_list[i + 1][1][1] - coordinate_list[i][1][1]
    graph[coordinate_list[i][0]] += [(cost, coordinate_list[i+1][0])]
    graph[coordinate_list[i + 1][0]] += [(cost, coordinate_list[i][0])]


is_used = [0] * n
que = []
ret = 0
heappush(que, (0, 0))


for i in range(n):
    while True:
        add_cost, add_v = heappop(que)
        if not is_used[add_v]:
            break
    is_used[add_v] = 1
    ret += add_cost
    for cost, to_v in graph[add_v]:
        if not is_used[to_v]:
            heappush(que, (cost, to_v))


print(ret)

Measured memory_bytes: 122584
#include <stdio.h>
#include <math.h>

int main()
{
    int n;
    while(scanf("%d", &n) != EOF)
    {

        int a[n+1];
        for(int i = 2; i <= n; i++)
        {
            a[i] = 1;
        }
        for(int i = 2; i <= sqrt(n); i++)
        {
            if (a[i] == 1)
                for(int j = 2; i * j <= n; j++)
                {
                    a[i * j] = 0;
                }
        }
        int total = 0;
        for(int i = 2; i <= n; i++)
        {
            if (a[i] == 1)
                total++;
        }
        printf("%d", total);
        printf("\n");
    }
    return 0;
}




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

int main(){
  int D; cin >> D;
  vector<int> c(26);
  for(int i=0; i<26; i++) cin >> c[i];
  vector<vector<int>> s(D,vector<int>(26));
  for(int i=0; i<D; i++){
    for(int j=0; j<26; j++){
      cin >> s[i][j];
    }
  }
  vector<vector<int>> lastc(D+1,vector<int>(26,0));
  vector<int> t(D);
  
    srand(std::time(nullptr));
  
  for(int i=1; i<=D; i++){
    
    int cont; /*cin >> cont;
    cont--;*/ cont=rand()%26;
    t[i-1]=cont;
    
    //lastcの更新
    for(int j=0; j<26; j++){
      if(j==cont) lastc[i][j]=i;
      else lastc[i][j]=lastc[i-1][j];
    }
  }
  
  int M=10000000;//調整
  for(int i=0; i<M; i++){
    int d,q; /*cin >> d >> q; q--;
    */
    d=rand()%D+1; 
    q=rand()%26;
    int qold=t[d-1];
    
    int sat=0;
    
    sat = sat - s[d-1][qold];
    sat = sat + s[d-1][q];
    
    int lastcold = lastc[d-1][qold];
    for(int j=d; j<=D; j++){
      if(j==d){
        sat-=c[qold]*(j-lastcold);
      }
      else if(lastc[j][qold]==j){
        break;
      }
      else{
        sat-=c[qold]*(lastc[j][qold]-lastcold);
      }
    }
    
    for(int j=d; j<=D; j++){
      if(lastc[j][q]==j){
        break;
      }
      else{
        sat+=c[q]*(d-lastc[j][q]);
      }
    }
    
    if(sat>0){
      for(int j=d; j<=D; j++){
        if(j==d){
          lastc[j][qold]=lastc[j-1][qold];
        }
        else if(lastc[j][qold]==j){
          break;
        }
        else{
          lastc[j][qold]=lastc[j-1][qold];
        }
      }
      
      for(int j=d; j<=D; j++){
        if(j==d){
          lastc[j][q]=d;
        }
        else if(lastc[j][q]==j){
          break;
        }
        else{
          lastc[j][q]=lastc[j-1][q];
        }
      }
      
      t[d-1]=q;
    }
  }
  
  for(int i=0; i<D; i++){
    cout << t[i]+1 << endl;
  }
}

Measured memory_bytes: 3672
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
ll MOD = 1e9 + 7;
void add(ll &a, ll b){
  a = (a+b)%MOD;
}
int main(){
    string s;
    cin >> s;
    int n = s.size();
    vector<ll> one(n);
    one[0] = 1;
    for(int i = 1; i < n; i++){
        one[i] = one[i-1]*3%MOD;
    }
    vector<ll> two(n+1);
    two[0] = 1;
    for(int i = 1; i <= n; i++){
        two[i] = two[i-1]*2%MOD;
    }
    ll ans = 0, count = 0;
    for(int i = 0; i < n; i++){
        if(s[i] == '0') continue;
        add(ans, two[count] * one[n-1-i] % MOD);
        count++;
    }
    add(ans, two[count]);
    cout << (ans+MOD) % MOD << endl;
}

Measured memory_bytes: 2048
use std::io::Read;

struct Edge {
    from: usize,
    to: usize,
    cost: i64,
}
impl Ord for Edge {
    fn cmp(&self, other: &Self) -> std::cmp::Ordering {
        self.cost.cmp(&other.cost)
    }
}
impl PartialOrd for Edge {
    fn partial_cmp(&self, other: &Self) -> Option<std::cmp::Ordering> {
        Some(self.cost.cmp(&other.cost))
    }
}
impl Eq for Edge {}
impl PartialEq for Edge {
    fn eq(&self, other: &Self) -> bool {
        self.cost == other.cost
    }
}

struct UnionFind {
    parent: Vec<isize>,
}

impl UnionFind {
    fn new(size: usize) -> UnionFind {
        UnionFind {
            parent: vec![-1; size],
        }
    }
    fn find(&self, x: usize) -> usize {
        let mut x = x;
        while self.parent[x] >= 0 {
            x = self.parent[x] as usize;
        }
        x
    }
    fn unite(&mut self, x: usize, y: usize) {
        let px = self.find(x);
        let py = self.find(y);
        if px == py {
            return;
        }
        if self.parent[px] < self.parent[py] {
            self.parent[px] += self.parent[py];
            self.parent[py] = px as isize;
        } else {
            self.parent[py] += self.parent[px];
            self.parent[px] = py as isize;
        }
    }
    fn same(&mut self, x: usize, y: usize) -> bool {
        self.find(x) == self.find(y)
    }
}

fn kruskal(edges: &mut Vec<Edge>) -> i64 {
    let n: usize = edges.len();

    edges.sort();

    let mut uf = UnionFind::new(n);
    let mut res: i64 = 0;
    for e in edges.iter() {
        if uf.same(e.from, e.to) {
            continue;
        }
        uf.unite(e.from, e.to);
        res += e.cost;
    }
    res
}

fn main() {
    let mut s = String::new();
    std::io::stdin().read_to_string(&mut s).ok();
    let mut itr = s.trim().split_whitespace();
    let n: usize = itr.next().unwrap().parse().unwrap();
    let mut xy: Vec<(i64, i64, usize)> = vec![];
    for i in 0..n {
        let x: i64 = itr.next().unwrap().parse().unwrap();
        let y: i64 = itr.next().unwrap().parse().unwrap();
        xy.push((x, y, i));
    }

    // make the graph
    let mut edges: Vec<Edge> = Vec::new();
    xy.sort_by(|a, b| a.0.cmp(&b.0));
    for i in 1..n {
        let (from_x, from_y, from_id) = xy[i - 1];
        let (to_x, to_y, to_id) = xy[i];
        let edge = Edge {
            from: from_id,
            to: to_id,
            cost: std::cmp::min((to_x - from_x).abs(), (to_y - from_y).abs()),
        };
        edges.push(edge);
    }

    xy.sort_by(|a, b| a.1.cmp(&b.1));
    for i in 1..n {
        let (from_x, from_y, from_id) = xy[i - 1];
        let (to_x, to_y, to_id) = xy[i];
        let edge = Edge {
            from: from_id,
            to: to_id,
            cost: std::cmp::min((to_x - from_x).abs(), (to_y - from_y).abs()),
        };
        edges.push(edge);
    }
    println!("{}", kruskal(&mut edges));
}

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

int gcd(int a, int b){
    
    if(a==1 || b==1)
        return 1;
    
    if(a<b)swap(a,b);
    
    while(a%b!=0){
        a %= b;
        swap(a,b);
    }
    
    return b;
    
}

int gcd_3(int a, int b, int c){
    
    return gcd(a,gcd(b,c));
    
}

int main(){
    
    int k;
    cin >> k;
    
    long int sum= 3*k*k-3*k+1;
    
    for(int a=2; a<=k; a++){
        for(int b=2; b<=k; b++){
            for(int c=2; c<=k; c++){
                
                sum += gcd_3(a,b,c);
                
            }
        }
    }
    
    cout << sum << endl;
    
    return 0;
}


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

int N = 0;
int A[201];

int main(){
    cin >> N;
    for (int i = 0; i < N; i++){
        cin >> A[i];
        // cout << A[i] << endl;
    } 
    int count = 0;
    bool flag = 0;
    while(1){
        for (int i = 0; i < N; i++){
            if (A[i] % 2 == 1){
                flag = 1;
            }
        }
        if (flag == 1) break;
        for (int i = 0; i < N; i++){
            A[i] = A[i] / 2;
        }
        count += 1;
    }
    cout << count << endl;
    
}

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

#define ipair pair<int,int>
#define rep(i,n) for(i=0;i<n;i++)
#define repj(i,j,n) for(i=j;i<n;i++)

#define PB(a,i) (a).push_back(i)
#define ALL(a) (a).begin(),(a).end()
#define SIZE(a,n) (a).resize(n)
#define SORT(a) sort(ALL(a))
#define VSORT(a, type) sort(ALL(a),greater<type>())
#define MAPIN(a,i,j) (a).insert(make_pair(i,j))

#define OK(i) cout<<"OK "<<i<<endl
#define Yes cout<<"Yes"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define NO cout<<"NO"<<endl

using namespace std;

typedef long long int lli;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector< vi > Matrix;

int main() {
	string s,t;
    int count=0;

    cin>>s>>t;
    int i;

    rep(i,3){
        if(s[i]==t[i])count++;
    }

    cout<<count;

	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <complex>
#include <vector>

using namespace std;

typedef complex<double> P;
const double EPS = 1e-8;

double cross(P a, P b){ return imag(conj(a)*b); }

vector<P> convexCut(vector<P> g, P p, P q){
	vector<P> res;
	int n = g.size();
	for(int i=0;i<n;i++){
		P A(g[i]), B(g[(i+1)%n]);
		double p1 = cross(q-p,A-p);
		double p2 = cross(q-p,B-p);
		if(p1 > -EPS) res.push_back(A);
		if(p1*p2 < -EPS)
			res.push_back(A+cross(q-p,q-A)/cross(q-p,B-A)*(B-A));
	}
	return res;
}

double polygonArea(vector<P> g){
	double res = 0.0;
	for(int i=0;i<g.size();i++)
		res += cross(g[i],g[(i+1)%g.size()]);
	return abs(0.5*res);
}

int main(){
	int n, m; 
	while(cin >> n >> m, n){
		vector<P> island, castle;
		for(int i=0;i<n;i++){
			double Ix, Iy; cin >> Ix >> Iy;
			island.push_back(P(Ix,Iy));
		}
		for(int i=0;i<m;i++){
			double Cx, Cy; cin >> Cx >> Cy;
			castle.push_back(P(Cx,Cy));
		}
		for(int i=0;i<m;i++){
			vector<P> area = island;
			for(int j=0;j<m;j++){
				if(i==j) continue;
				P mid = (castle[i]+castle[j])/2.0;
				P dir = (castle[i]-castle[j])*P(0,1);
				P q = mid + dir;
				if(cross(q-mid,castle[i]-mid)>EPS) swap(q,mid);
				area = convexCut(area, q, mid);
			}
			printf("%.6lf\n", polygonArea(area));
		}
	}
}

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

using namespace std;

struct modular_equation {
	long long k;
	long long l;
};

modular_equation do_get_inverse(long long a, long long b) {
	if (b == 0) {
		return modular_equation{1, 0};
	}
	modular_equation eq = do_get_inverse(b, a % b);
	return modular_equation{eq.l, eq.k - (a/b)*eq.l};
}

long long get_inverse(long long num, long long mod) {
	modular_equation eq = do_get_inverse(num, mod);
	return (eq.k + mod) % mod;
}

long long get_factorial(long long num, long long mod) {
	if (num <= 1) {
		return 1;
	}
	return (get_factorial(num-1, mod) * num) % mod;
}

long long get_binom(long long upper, long long lower_left, long long lower_right, long long mod) {
	long long lower_left_recip = get_inverse(lower_left, mod);
	long long lower_right_recip = get_inverse(lower_right, mod);
	return (((upper * lower_left_recip) % mod) * lower_right_recip) % mod;
}

long long get_summand(long long left_upper, long long left_lower_left, long long left_lower_right, long long right_upper, long long right_lower_left, long long right_lower_right, long long mod) {
	return (get_binom(left_upper, left_lower_left, left_lower_right, mod) * get_binom(right_upper, right_lower_left, right_lower_right, mod)) % mod;
}

int main() {
	ios_base::sync_with_stdio(false);
	long long mod = 1000000007;
	long long h, w, a, b;
	cin >> h >> w >> a >> b;
	long long left_upper = get_factorial(b-1, mod);
	long long left_lower_left = get_factorial(b-1, mod);
	long long left_lower_right = 1;
	long long right_upper = get_factorial(w-b+h-2, mod);
	long long right_lower_left = get_factorial(w-b-1, mod);
	long long right_lower_right = get_factorial(h-1, mod);
	long long result = get_summand(left_upper, left_lower_left, left_lower_right, right_upper, right_lower_left, right_lower_right, mod);
	for (int i = 2; i <= h-a; i++) {
		left_upper = (left_upper * (i+b-2)) % mod;
		left_lower_right = (left_lower_right * (i-1)) % mod;
		right_upper = (right_upper * get_inverse(w-b+h-i, mod)) % mod;
		right_lower_right = (right_lower_right * get_inverse(h-i+1, mod)) % mod;
		result = (result + get_summand(left_upper, left_lower_left, left_lower_right, right_upper, right_lower_left, right_lower_right, mod)) % mod;
	}
	cout << result << '\n';
	return 0;
}

Measured memory_bytes: 6528
#include <bits/stdc++.h>
#include <boost/format.hpp>
using namespace std;
#define int long long
#define REP(i, n) FOR(i, 0, n)
#define REPR(i, n) for (int i = n - 1; i >= 0; i--)
#define FOR(i, s, n) for (int i = (s), i##_len = (n); i < i##_len; ++i)
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
#define DIV(a, b) ((a - 1) / b + 1)

signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, ans = 0;
    string s;
    cin >> n >> s;
    REP(i, 10) {
        auto pos1 = s.find(to_string(i));
        if (pos1 == string::npos) {
            continue;
        }
        REP(j, 10) {
            auto pos2 = s.find(to_string(j), pos1 + 1);
            if (pos2 == string::npos) {
                continue;
            }
            REP(k, 10) {
                auto pos3 = s.find(to_string(k), pos2 + 1);
                if (pos3 != string::npos) {
                    ans++;
                }
            }
        }
    }
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3780
from itertools import product

D, G = map(int, input().split())
probs = []
for _ in range(D):
    p, c = map(int, input().split())
    probs.append((p, c))
ans = 10**9
for choise in product([True, False], repeat=D):
    score = 0
    solved_probs = 0
    max_score_rem_id = 0
    for i, solve in enumerate(choise):
        if solve:
            score += probs[i][0]*(100*(i+1)) + probs[i][1]
            solved_probs += probs[i][0]
        else:
            max_score_rem_id = i
    if score < G:
        remain = G - score
        to_be_solved = (remain - 100) // (100*(max_score_rem_id+1)) + 1
        if to_be_solved < probs[max_score_rem_id][0]:
            solved_probs += to_be_solved
        else:
            continue
    ans = min(ans, solved_probs)
print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define N 100
using namespace std;
typedef complex<double> P;
typedef pair<P,P> L;
const double EPS = 1e-8;
double dot(P a, P b){ return real(conj(a)*b); }
double cross(P a, P b){ return imag(conj(a)*b); }

int ccw(P a, P b, P c){
  b -= a;
  c -= a;
  if(cross(b,c) > EPS) return 1;   // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(cross(b,c) < -EPS) return -1; // ????????????(b-a)????????´???????????????(c-a)????????¨?????????
  if(dot(b,c) < -EPS) return 2;
  if(norm(b) < norm(c)) return -2;
  return 0;
}

bool isIntersect(L s1, L s2){
  return ( ccw(s1.first,s1.second,s2.first) * ccw(s1.first,s1.second,s2.second) <= 0 &&
           ccw(s2.first,s2.second,s1.first) * ccw(s2.first,s2.second,s1.second) <= 0 );
}

double getDistanceSP(L s, P p){
  if(dot(s.second - s.first, p - s.first) < -EPS) return abs(p - s.first);
  if(dot(s.first - s.second, p - s.second) < -EPS) return abs(p - s.second);
  return abs(cross(s.second - s.first, p - s.first) / abs(s.second - s.first));  }

double getDistanceSS(L s1, L s2){
  if(isIntersect(s1,s2)) return 0.0;
  return min( min(getDistanceSP(s1, s2.first), getDistanceSP(s1, s2.second)),
              min(getDistanceSP(s2, s1.first), getDistanceSP(s2, s1.second)));
}

vector<P> get_p(P a,double d,double r){
  vector<P> res(5);
  d=(d/360)*2*M_PI;
  P p=P(0,r)*P(cos(d),sin(d));
  res[0]=p+a;
  d=2*M_PI/5;
  for(int i=1;i<=4;i++){
    p=p*P(cos(d),sin(d));
    res[i]=p+a;
  }
  return res;
}


double G[N][N],x[N],y[N],d[N],r[N];
double get_dis(int a,int b){
  vector<P> A=get_p(P(x[a],y[a]),d[a],r[a]);
  vector<P> B=get_p(P(x[b],y[b]),d[b],r[b]);
  double res=1e9;
  for(int i=0;i<5;i++)
    for(int j=0;j<5;j++)
      res=min(res,getDistanceSS(L(A[i],A[(i+2)%5]),L(B[j],B[(j+2)%5])));
  return res;
}

int main(){
  while(1){
  int n,s,g;
  cin>>n>>s>>g;
  if(!n&&!s&&!g)break;
  for(int i=0;i<n;i++)for(int j=0;j<n;j++)G[i][j]=1e9;
  for(int i=0;i<n;i++)cin>>x[i]>>y[i]>>d[i]>>r[i];
  
  for(int i=0;i<n;i++)
    for(int j=0;j<n;j++)G[i][j]=get_dis(i,j);
  
  for(int k=0;k<n;k++)
    for(int i=0;i<n;i++)
      for(int j=0;j<n;j++)
	G[i][j]=min(G[i][j],G[i][k]+G[k][j]);

  printf("%.20f\n",G[s-1][g-1]);
  }
  return 0;
}

Measured memory_bytes: 3536
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using Edge = pair<int, int>;
using Graph = vector<vector<Edge>>;
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define SORT(v) sort((v).begin(), (v).end())
#define RSORT(v) sort((v).rbegin(), (v).rend())
const ll MOD = 1000000007;
const ll nmax = 8;
const ll INF = 1e9;
bool graph[nmax][nmax];
vector<vector<ll>> dist = vector<vector<ll>>(nmax, vector<ll>(nmax, INF));
void warshall_floyd(ll n)
{
    for (size_t i = 0; i < n; i++)
    {
        for (size_t j = 0; j < n; j++)
        {
            for (size_t k = 0; k < n; k++)
            {
                dist[j][k] = min(dist[j][k], dist[j][i] + dist[i][k]);
            }
        }
    }
}

class UnionFind
{
public:
    vector<ll> Parent;

    UnionFind(ll N)
    {
        Parent = vector<ll>(N, -1);
    }
    ll find(ll A)
    {
        if (Parent[A] < 0)
            return A;
        return Parent[A] = find(Parent[A]);
    }

    ll size(ll A)
    {
        return -Parent[find(A)];
    }

    bool Union(ll A, ll B)
    {
        A = find(A);
        B = find(B);
        if (A == B)
        {
            return false;
        }
        if (size(A) < size(B))
            swap(A, B);

        Parent[A] += Parent[B];
        Parent[B] = A;

        return true;
    }
};

ll gcd(ll a, ll b)
{
    if (b == 0)
        return a;
    return gcd(b, a % b);
}

ll lcm(ll a, ll b)
{
    ll g = gcd(a, b);
    return a / g * b;
}

ll mulMod(ll a, ll b)
{
    return (((a % MOD) * (b % MOD)) % MOD);
}

ll powMod(ll a, ll p)
{
    if (p == 0)
    {
        return 1;
    }
    else if (p % 2 == 0)
    {
        ll half = powMod(a, p / 2);
        return mulMod(half, half);
    }
    else
    {
        return mulMod(powMod(a, p - 1), a);
    }
}

ll ceil(ll a, ll b)
{
    return (a + b - 1) / b;
}

void solve(long long A, long long B, long long C, long long D)
{
    ll gcdCD = lcm(C, D);
    ll divC = B / C - (A - 1) / C;
    ll divD = B / D - (A - 1) / D;
    ll divCD = B / gcdCD - (A - 1) / gcdCD;

    cout << (B - A + 1) - divC - divD + divCD << endl;
}

// Generated by 1.1.4 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main()
{
    long long A;
    scanf("%lld", &A);
    long long B;
    scanf("%lld", &B);
    long long C;
    scanf("%lld", &C);
    long long D;
    scanf("%lld", &D);
    solve(A, B, C, D);
    return 0;
}


Measured memory_bytes: 256
import java.util.*;

public class Main {

	public static void main (String[] args)  {
		Scanner sc = new Scanner(System.in);
		int h = sc.nextInt();
		int m = sc.nextInt();
		int hh = sc.nextInt();
		int mm = sc.nextInt();
		System.out.println((h - hh) * (m - mm));
	}
}


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

using namespace std;

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

  char a;
  cin >> a;
  if (a == 'a' || a == 'i' || a == 'u' || a == 'e' || a == 'o') {
    cout << "vowel\n";
  } else {
    cout << "consonant\n";
  }
}


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

const int N = 100 * 1000 + 5;
int n;

int a[2 * N];
bool b[2 * N];
bool isval(int x) {
	for (int i = 1; i < 2 * n; i++) {
		b[i] = (a[i] >= x);
	}
	for (int i = 1; i < n; i++) {
		if (b[n + i] == b[n + i - 1]) {
			return b[n + i];
		}
		if (b[n - i] == b[n - i + 1]) {
			return b[n - i];
		}
	}
	if (n % 2)
		return b[n];
	else
		return !b[n];
}
int main() {
	cin >> n;
	for (int i = 1; i < 2 * n; i++) {
		cin >> a[i];
	}
	int dw = 1, up = 2 * n;
	while (up - dw > 1) {
		int md = (dw + up) / 2;
		if (isval(md))
			dw = md;
		else
			up = md;
	}
	cout << dw << endl;
	return 0;
}


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

int Solve(int n, vector<int> a, int d = 0) {
  vector<int> contrib(n); // contrib[i] = parity of Choose(n - 1, i)
  vector<int> twomul(n); // how many times a number can be divided by 2
  for (int i = 1; i < n; i++) {
    int j = i;
    while (j > 1 && j % 2 == 0) {
      twomul[i]++;
      j /= 2;
    }
  }
  for (int i = 1; i < n; i++) {
    twomul[i] += twomul[i - 1];
  }
  for (int i = 0; i < n; i++) {
    int candiv = twomul[n - 1] - twomul[i] - twomul[n - 1 - i];
    if (candiv > 0) {
      contrib[i] = 0;
    } else {
      contrib[i] = 1;
    }
  }
  int xorall = 0;
  for (int i = 0; i < n; i++) {
    if (contrib[i]) {
      xorall ^= a[i] % 2;
    }
  }
  if (xorall == 1) {
    return 1;
  }
  if (d == 1) {
    return 0;
  }
  for (int i = 0; i < n; i++) {
    if (a[i] == 1) {
      return 0;
    }
  }
  for (int i = 0; i < n; i++) {
    a[i] /= 2;
  }
  return 2 * Solve(n, a, 1);
}

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

  int n;
  cin >> n;
  string s;
  cin >> s;

  vector<int> a;
  for (auto &i : s) {
    a.emplace_back(i - '1');
  }

  cout << Solve(n, a) << "\n";
  return 0;
}


Measured memory_bytes: 31972
//ABC96B
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<n; i++)
using namespace std;
int main(void){
    int n;
    vector<int>vec(3,0);
    rep(i, 3) cin >> vec[i];
    cin >> n;
    rep(i, n){
        sort(vec.begin(), vec.end());
        vec[2] = vec[2]*2;
    }
    cout << accumulate(vec.begin(), vec.end(), 0) << endl;
}

Measured memory_bytes: 256
#include <algorithm>
#include <fstream>
#include <iomanip>
#include <iostream>
#include <map>
#include <math.h>
#include <set>
#include <stdio.h>
#include <string>
#include <vector>

using namespace std;

struct Edge {
  int a, b;
  int cost;
};

struct Node {
  int now, time;
  int walk;
};

bool operator<(const Node &lhs, const Node &rhs) { return lhs.time < rhs.time; }

int main() {
  while (true) {
    int n, m, l, k, a, h;
    cin >> n >> m >> l >> k >> a >> h;
    if (n == 0)
      break;
    // n: 街の数, m: 再冷凍までの時間, l: 冷凍施設のある
    // k: 辺数, a: 本国の首都, h: お姫様
    vector<int> f(l);
    for (int i = 0; i < l; i++)
      cin >> f[i];
    vector<bool> fre(n);
    for (int i = 0; i < l; i++)
      fre[f[i]] = true;
    vector<Edge> e(k);
    for (int i = 0; i < k; i++)
      cin >> e[i].a >> e[i].b >> e[i].cost;
    int path[201][201] = {};
    for (int i = 0; i < 201; i++)
      for (int j = 0; j < 201; j++)
        path[i][j] = 100000000;

    for (int i = 0; i < k; i++) {
      path[e[i].a][e[i].b] = path[e[i].b][e[i].a] = e[i].cost;
    }
    multiset<Node> q;
    q.insert(Node{a, 0, 0});
    bool ch[201][101] = {false};
    bool ok = false;
    int ans = 1000000000;
    while (q.size() > 0) {
      Node now = *q.begin();
      q.erase(q.begin());
      if (ch[now.now][now.walk]) {
        continue;
      }
      ch[now.now][now.walk] = true;
      if (now.now == h) {
        ans = min(ans, now.time + max(now.time - m, 0));
        ok = true;
        break;
      }
      if (now.walk > 0 && fre[now.now]) {
        Node next{now.now, now.time, 0};
        q.insert(next);
        continue;
      }
      for (int i = 0; i < n; i++) {
        if (path[now.now][i] < 100000000) {
          if (now.walk + path[now.now][i] > m)
            continue;

          if (ch[i][now.walk])
            continue;
          q.insert(Node{i, now.time + path[now.now][i],
                        now.walk + path[now.now][i]});
        }
      }
    }
    if (!ok) {
      cout << "Help!" << endl;
    } else {
      cout << ans << endl;
    }
  }
  return 0;
}



Measured memory_bytes: 3564
#include <stdio.h>

int main()
{
    int a[3],i,j;
    for(i=0;i<3;i++) scanf("%d", &a[i]);
    for(i=2;i>0;i--) {
        for(j=0;j<i;j++) {
            if(a[j]>a[j+1]) {
                int x=a[j];
                a[j]=a[j+1];
                a[j+1]=x;
            }
        }
    }
    //for(i=0;i<3;i++) printf("%d ", a[i]);
    int ans=a[0]-a[1];
    if(ans<0) ans=0-ans;
    int x=a[1]-a[2];
    if(x<0) x=0-x;
    ans+=x;
    printf("%d\n", ans);
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <list>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <string>
#include <queue>
#include <numeric>
#include <ctype.h>
#include <limits>
#include <iomanip>

#define rep(i,n) for (int i = 0; i < n; i++)
#define all(x) (x).begin(),(x).end()
using namespace std;

typedef long long ll;

int main()
{
	int x, y;
	cin >> x >> y;
	int ans = 0;
	if (x <= 3)ans += 400000 - 100000 * x;
	if (y <= 3)ans += 400000 - 100000 * y;
	if (x == 1 && y == 1)ans += 400000;
	cout << ans;
	return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
#include <set>
#include <vector>

int dfs(
    const std::vector<std::vector<size_t>> &g, std::set<size_t> &s,
    size_t r, size_t p
) {
    if (s.size() == g.size()-1) return 1;
    if (s.count(r)) return 0;

    int res=0;
    s.insert(r);
    for (size_t c: g[r])
        if (c != p && !s.count(c))
            res += dfs(g, s, c, r);

    s.erase(r);
    return res;
}

int main() {
    size_t N;
    int M;
    scanf("%zu %d", &N, &M);

    std::vector<std::vector<size_t>> g(N);
    for (int i=0; i<M; ++i) {
        size_t a, b;
        scanf("%d %d", &a, &b);

        --a, --b;
        g[a].emplace_back(b);
        g[b].emplace_back(a);
    }

    std::set<size_t> s;
    printf("%d\n", dfs(g, s, 0, -1));
    return 0;
}


Measured memory_bytes: 256
// inputに入力データ全体が入る
function Main(input) {
    var A = input[0].split(" ")[0];
    var B = input[0].split(" ")[1];
    var M = input[0].split(" ")[2];
    var amap = [];
    var bmap = [];
    var amin = bmin = 100000000;
    input[1].split(" ").forEach((v,i)=>{
        v = v-0;
        amap[i+1] = v;
        amin = Math.min(amin, v);
    });
    input[2].split(" ").forEach((v,i)=>{
        v = v-0;
        bmap[i+1] = v;
        bmin = Math.min(bmin, v);
    });

    var ans = amin+bmin;
    input.filter((v,i)=>i>2).map(v=>{
        var a = v.split(" ")[0]-0;
        var b = v.split(" ")[1]-0;
        var c = v.split(" ")[2]-0;
        ans = Math.min(amap[a]+bmap[b]-c, ans);
    });
    console.log(ans);


}



Main(require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n"));

Measured memory_bytes: 58724
#include <iostream>
#include <cstring>
#include <cmath>
#include <vector>
#include <map>
#include <algorithm>
#include <deque>
#include <tuple>
#include <utility>
using namespace std;
typedef long long ll;
#define for1(i,n) for (ll i=0;i<(n);(i)++)
#define for2(i,m,n) for (ll (i)=(m);(i)<(n);(i)++)
#define for3(i,m,n,d) for (ll (i)=(m);(i)<(n);(i)+=(d))
#define INF (1LL << 60)

void solve()
{
  vector<ll> A(3);
  cin >> A[0] >> A[1] >> A[2];
  sort(A.begin(), A.end());
  for1(i,3) {
    if (A[i] % 2 == 0) {
      cout << 0 << endl;
      return;
    }
  }

  cout << A[0] * A[1] << endl;
}

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


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define ull unsigned long long int
#define ll long long int
#define LL_MAX 9223372036854775807
#define pb push_back
#define pf push_front
#define mp make_pair
#define popb pop_back
#define vl vector<ll>
#define bs(v, x) binary_search(v.begin(), v.end(), x)
#define popf pop_front
#define p() cout << '\n'
#define p0(x) cout << x << " "
#define p1(x) cout << x << '\n'
#define p2(x, y) cout << x << " " << y << '\n'
#define p3(x, y, z) cout << x << " " << y << " " << z << '\n'
#define printv(v)                   \
  for (ll i = 0; i < v.size(); ++i) \
    cout << v[i] << " ";            \
  cout << '\n'
#define pr1(x) cout << fixed << setprecision(15) << x << '\n'
#define mod 1000000007
#define mod1 998244353
#define fio                         \
  ios_base::sync_with_stdio(false); \
  cin.tie(NULL)
#define get(n) \
  ll n;        \
  cin >> n
#define getvec(v, n)         \
  vector<ll> v(n);           \
  for (ll i = 0; i < n; i++) \
    cin >> v[i];
#define getstr(s) \
  string s;       \
  cin >> s
#define all(x) x.begin(), x.end()
#define countBits(x) __builtin_popcount(x)
using namespace std;

void mainSolve()
{
  get(n);
  get(x);
  get(t);
  int div = n / x;
  if (n % x != 0)
    ++div;
  ll ans = (div * t);
  p1(ans);
}

int main()
{
  fio;
#ifndef ONLINE_JUDGE
  freopen("input.txt", "r", stdin);
  freopen("output.txt", "w", stdout);
#endif
  //get(t);
  ll t = 1;
  while (t--)
  {
    mainSolve();
  }
  return 0;
}


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

int main() {
    int N;
    cin >> N;
    ll dBase[N][N];
    ll d[N][N];
    bool isShortest[N][N];
    rep(i, N) {
        rep(j, N) {
            cin >> d[i][j];
            dBase[i][j] = d[i][j];
            isShortest[i][j] = true;
        }
    }
    rep(k, N) {
        rep(i, N) {
            for (int j = i + 1; j < N; j++) {
                if (i == j || i == k || j == k) {
                    continue;
                }
                ll dd = d[i][k] + d[k][j];
                if (d[i][j] >= dd) {
                    isShortest[i][j] = false;
                    d[i][j] = dd;
                }
            }
        }
    }
    ll total = 0;
    rep(i, N) {
        for (int j = i + 1; j < N; j++) {
            if (dBase[i][j] != d[i][j]) {
                cout << -1 << endl;
                return 0;
            }
            if (isShortest[i][j]) {
                total += dBase[i][j];
            }
        }
    }
    cout << total << endl;
    return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>

using namespace std;

typedef long long ll;

int main() {
    string s;
    cin >> s;
    int n = (int)s.size();

    stack<char> st;
    for (int i = 0; i < n; ++i) {
        char c = s[i];
        if (st.empty() || st.top() == 'T' || c == 'S') st.push(c);
        else if (c == 'T') st.pop();
    }

    cout << st.size() << endl;
}

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

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; }

#define rep(i,cc,n) for(int i=cc;i<n;++i)
#define lrep(i,cc,n) for(long long i=cc;i<n;++i)
#define sqrep(i,cc,n) for(long long i=cc;i*i<=n;++i)
#define rrep(i,cc,n) for(long i=cc;i>n;--i)
#define pii pair<int, int>
#define pll pair<long long, long long>
 
using ll = long long;

const vector<int> dx = {1, 0, -1, 0};
const vector<int> dy = {0, 1, 0, -1};
const ll inf = 1001001001;
const ll e9  = 1000000000;
const ll mod = 1000000007;

int main(){
  int n, ans=0;
  cin >> n;
  vector<int>a(n);
  rep(i, 0, n){
    cin >> a[i];
    a[i]--;
  }
  int j = 0, p = 0;
  rep(i, 0, n){
    if(a[i]==j)j++;
  }
  if(j==0){
    cout << -1 << endl;
    return 0;
  }else{
    cout << n-j << endl;
    return 0;
  }
}

Measured memory_bytes: 4000
#include<cstdio>
#include<cmath>

typedef long long ll;

const double eps = 1e-9;

int main(void)
{
	ll n;
	int result = 0,t;
	scanf("%lld", &n);
	t = sqrt(n) + eps;
	for (int  i = t; i >= 1; --i)
	{
		if (n % i == 0)
		{
			ll a = n / i;
			while (a)
			{
				++result;
				a /= 10;
			}
			break;
		}
	}
	printf("%d", result);
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
#define fo(i,a,b) for(int i= a ; i < b ; ++i)
#define rep(i,n) fo(i,0,n)
#define pln(n) printf("%lld",n)
#define sll(n) scanf("%lld",&n)
#define ss(n) scanf("%s",n)
#define vi vector < int >
#define pii pair < int , int >
#define pb push_back
#define mp make_pair
#define ll long long
#define ull unsigned long long
#define INF 0x3f3f3f3f
#define dbg(x) { cout<< #x << ": " << (x) << endl; }
#define dbg2(x,y) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) << endl; }
#define dbg3(x,y,z) { cout<< #x << ": " << (x) << " , " << #y << ": " << (y) <<" , "<< #z <<": "<<(z)<<endl; }
#define all(x) x.begin(),x.end()
#define sz(x) (int)x.size()
#define vll vector<long long>
#define vvll vector<vector<long long>>
#define vvvll vector<vector<vector<ll>>>
#define si set<int>
#define tr(c, it) \
for(decltype(c.begin()) it = c.begin(); it!= c.end(); it++)
#define pis pair<int,string>
#define present(c, x) (c.find(x) != c.end())
#define cpresent(c, x) (find(all(c),x) != c.end())
#define  ones(x)  __builtin_popcount(x)
using namespace std;
int exponentMod(int A, int B, int C)  
{  
    // Base cases  
    if (A == 0)  
        return 0;  
    if (B == 0)  
        return 1;  
  
    // If B is even  
    long y;  
    if (B % 2 == 0) {  
        y = exponentMod(A, B / 2, C);  
        y = (y * y) % C;  
    }  
  
    // If B is odd  
    else {  
        y = A % C;  
        y = (y * exponentMod(A, B - 1, C) % C) % C;  
    }  
  
    return (int)((y + C) % C);  
}

int main(){
    string a;
    cin >> a;
    //cout << a[0];
    int U[a.size() + 1];//remainder of the no upto index i
    U[a.size()] = 0;
    int ans = 0;
    unordered_map<int,int> m;
    for(int i = a.size() - 1; i >= 0; i--){
        U[i] = ((U[i + 1])%2019 + ((a[i] - '0')%2019 * exponentMod(10,a.size() - i - 1, 2019))%2019)%2019;
        //dbg(U[i]);
        if(m.find(U[i]) != m.end()){
            ans += m[U[i]];
            m[U[i]]++;
        }
        else{
            m[U[i]] = 1;
        }
        if(U[i] == 0)ans++;
    }
    cout << ans ;

    
}

Measured memory_bytes: 4500
#include<bits/stdc++.h>
using namespace std;
 
#define IOS ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
#define ll long long
#define rep(i,a,b)    for(ll i=a;i<b;i++)
#define repn(i,a,b)   for(ll i=a;i>=b;i--)
#define F first
#define S second
#define qi queue<ll>
#define pii pair<ll,ll>
#define vi vector<ll>
#define si set<ll>
#define vii vector<pii>
#define mi multiset<ll>
#define mii multiset<pii>
#define MI map<ll,ll>
#define pb push_back
#define mp  make_pair
#define all(v) (v).begin(), (v).end()
#define allr(v) (v).rbegin(), (v).rend()
#define mod 998244353
#define mod2 998244353

// size_t f= str.find(string s,0); find s in str from start
// if found then (f != string::npos)
// m.insert({x,y}); m[x]=y;

int fexp(int a, int b){int ans = 1;while(b){if(b&1) ans = ans*a%mod2; b/=2;a=a*a%mod2;}return ans;}
int inverse(int a, int p){return fexp(a, p-2);}

signed main(){
    IOS
	#ifndef ONLINE_JUDGE
    	freopen("input.txt", "r", stdin);
		freopen("output.txt", "w", stdout);
	#endif
	int a,b,c,d,e;
  cin>>a>>b>>c>>d>>e;
  int time = (c-a)*60+(d-b)-e;
  if(time>0) cout<<time;
  else cout<<"0";
    return 0;
}

Measured memory_bytes: 3648
#include<stdio.h>

int main(){
    int R, G, B, N;
    int i,j,k;
    int ans = 0;
    int sum, tmp;

    scanf("%d %d %d %d", &R, &G, &B, &N);

    for(i=0; i<=N; i++){
        for(j=0; j<=N; j++){
            tmp = N-(i*R + j*G);
            if((tmp>=0) && (tmp%B==0)){
                ans +=1;
            }
        }
    }
    printf("%d", ans);
    return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<queue>
#include<stack>
#include<numeric>
#include<cstring>
#include<vector>
#include<algorithm>
#include<unordered_map>
#include<unordered_set>
#include<climits>
#include<cmath>

using namespace std;
#define ll long long
#define pp pair<int,int>
#define ppl pair<ll,ll> 

int main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	
	int n;
	cin>>n;

	int arr[n][3],dp[n][3];
	for(int i=0;i<n;i++)
		cin>>arr[i][0]>>arr[i][1]>>arr[i][2];

	dp[0][0]=arr[0][0];
	dp[0][1]=arr[0][1];
	dp[0][2]=arr[0][2];

	for(int i=1;i<n;i++)
	{
		dp[i][0]=arr[i][0]+max(dp[i-1][1],dp[i-1][2]);
		dp[i][1]=arr[i][1]+max(dp[i-1][0],dp[i-1][2]);
		dp[i][2]=arr[i][2]+max(dp[i-1][0],dp[i-1][1]);
	}

	cout<<*max_element(dp[n-1],dp[n-1]+3);

	return 0;
}

Measured memory_bytes: 2560
def plass_only(a):
    for i in a:
        if i < 0:
            return 0
    return 1

def minus_only(a):
    for i in a:
        if i > 0:
            return 0
    return 1

def sarch(list, a):
    for i in range(len(list)):
        if a == list[i]:
            return i
            break

N = int(input())
a = list(map(int, input().split()))
if plass_only(a) == 1:
    for i in range(1, len(a)):
        a[i] += a[i - 1]
    print(len(a) - 1)
    for i in range(1, len(a)):
        print(i, i + 1)

elif minus_only(a) == 1:
    for i in range(len(a) - 2, -1, -1):
        a[i] += a[i + 1]
    print(len(a) - 1)
    for i in range(len(a), 1, -1):
        print(i, i - 1)

else:
    a_p = [i for i in a]
    a_m = [i for i in a]
    count_p = 0
    count_m = 0
    plass_print = []
    minus_print = []
    for i in range(len(a)):
        while a_p[i] < 0:
            a_p[i] += max(a_p)
            count_p += 1
            plass_print.append(str(sarch(a_p, max(a_p)) + 1) + " " + str(i + 1))
            if count_p > N: break
        while a_m[i] > 0:
            a_m[i] += min(a_m)
            count_m += 1
            minus_print.append(str(sarch(a_m, min(a_m)) + 1) + " " + str(i + 1))
            if count_m > N: break
    if count_p <= count_m:
        count = count_p
        a = a_p
        for i in range(1, len(a)):
            a[i] += a[i - 1]
            count += 1
        print(count)
        for i in plass_print:
            print(i)
        for i in range(1, len(a)):
            print(i, i + 1)

        
    else:
        count = count_m
        a = a_m
        for i in range(len(a) - 2, -1, -1):
            a[i] += a[i + 1]
            count += 1
        print(count)
        for i in minus_print:
            print(i)
        for i in range(len(a), 1, -1):
            print(i, i - 1)
        


Measured memory_bytes: 3192
#include <stdio.h>
#include <ctype.h>
#include <string.h>

int main(void)
{
    char s[200001];
    char t[200001];
    int S, T, result=0;
    S = scanf("%200000s", s);
    if(S==EOF) return 1;
    T = scanf("%200000s", t);
    if(T==EOF) return 1;
    if(strlen(s)!=strlen(t)) return 1;
    int i=0;
    while(s[i]!='\0'){
        if(isupper(s[i])) return 1;
        if(isupper(t[i])) return 1;
        if(!isalpha(s[i])) return 1;
        if(!isalpha(t[i])) return 1;
        if(s[i]!=t[i]){
            result++;
        }
        i++;
    }
    printf("%d\n", result);
    return 0;
}

Measured memory_bytes: 2084
#include <vector>
#include <list>
#include <map>
#include <set>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string>
#include <cstring>
#include <ctime>

//Code Short
#define REP(i,n) for(int i = 0;i < n;++i)
#define PB(s) push_back(s)
#define DSORT(n) sort(n.begin(),n.end())
#define QECHO(n) cout << n
#define QECHOS(n) cout << n << " "

//Define Math
const double EPS = 1e-10;
const double PI  = acos(-1.0);

using namespace std;
typedef long long ll;
/* prototype */


void solve(){
    //START
  int a[3];
  cin>>a[0]>>a[1]>>a[2];
  sort(a,a+3);
  int ans=(a[2]-a[1])+a[1]-a[0];
  cout<<ans<<endl;
}

int main(void){cin.tie(0);ios::sync_with_stdio(false);solve();}
int EDSum(ll number) {
  int ans = 0;
  while (1) {
    ans += number % 10;
    number /= 10;
    if (number == 0) break;
  }
  return ans;
}



Measured memory_bytes: 256
n, p = map(int, input().split())

if n==1:
    print(p)
else:
    out=1
    tm = int(pow(p, 1/n))
    for i in range(2,tm+1):
        while p%(i**n)==0:
            p = p//(i**n)
            out *= i
        if p < i**n:
            break
    print(out)


Measured memory_bytes: 3060
#include <string>
#include <iostream>
#include <cmath>
#include <algorithm>
using namespace std;
int sum(long long n) {
    int r = 0;
    while (n > 0) {
        r += n % 10;
        n /= 10;
    }
    return r;
}
int main(){
    int k;
    cin >> k;
    long long a=1;
    long long p=1;
    for(int i=1;i<=k;i++){
        cout << a<< endl;
        long long c=a+p;
        long long d=a+p*10;
        if(c* sum(d) <= d * sum(c)){
            a=c;
        }
        else {
            a=d;
            p=p*10;
        }
    }


}

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

int main()
{
  int N;
  cin >> N;
  vector<int> A(N), B(N), C(N);
  set<int> S;
  for (int i = 0; i < N; i++)
  {
    cin >> A[i];
    if (i > 0 && A[i] == A[i - 1] + 1)
    {
      S.insert(A[i - 1]);
    }
  }
  int ans = 0;
  for (int i = 0; i < N; i++)
  {
    cin >> B[i];
    ans += B[i];
  }
  for (int i = 0; i < N - 1; i++)
  {
    cin >> C[i];
    if (S.find(i + 1) != S.end())
    {
      ans += C[i];
    }
  }
  cout << ans << endl;
  return 0;
}

Measured memory_bytes: 256
import math


def main():
    n = int(input())
    ans = 0
    for i in range(1, n + 1):
        if math.log(i, 10) % 2 // 1 == 0 and i != 1000:
            ans += 1
    print(ans)


if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <iostream>
#define ll long long
#define MOD 1000000007
using namespace std;

int main(){
	ll n,k,ans = 0; cin>>n>>k;
	while(k<=n+1){
		ll minVal = k*(k-1)/2, maxVal = n*(n+1)/2 - (n-k+1)*(n-k)/2;
		ans = (ans+maxVal-minVal+1)%MOD;
		k++;
	}
	cout<<ans;
}


Measured memory_bytes: 3644
#include<algorithm>
#include<algorithm>     //sort,二分探索,など
#include<bitset>        //固定長bit集合
#include<cmath>         //pow,logなど
#include<complex>       //複素数
#include<deque>         //両端アクセスのキュー
#include<functional>    //sortのgreater
#include<iomanip>       //setprecision(浮動小数点の出力の誤差)
#include<iostream>      //入出力
#include<iterator>      //集合演算(積集合,和集合,差集合など)
#include<map>           //map(辞書)
#include<numeric>       //iota(整数列の生成),gcdとlcm(c++17)
#include<queue>         //キュー
#include<set>           //集合
#include<stack>         //スタック
#include<string>        //文字列
#include<unordered_map> //イテレータあるけど順序保持しないmap
#include<unordered_set> //イテレータあるけど順序保持しないset
#include<utility>       //pair
#include<vector>        //可変長配列

using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef long double ld;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
typedef vector<vector<int>> vvi;
typedef vector<vector<ll>> vvll;
typedef vector<vector<string>> vvs;
typedef vector<vector<bool>> vvb;
const ll MOD = 1000000007;
const ll INF = 1000000000000000000;
#define rep(i,n) for(int i=0;i<n;i++)
#define repl(i,s,e) for(int i=s;i<e;i++)
#define reple(i,s,e) for(int i=s;i<=e;i++)
#define revrep(i,n) for(int i=n-1;i>=0;i--)
#define all(x) (x).begin(),(x).end()

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

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

    vi x(5);
    rep(i, 5) cin >> x[i];

    rep(i, 5)
    {
        if (x[i] == 0)
        {
            cout << (i + 1) << endl;
            return 0;
        }
    }
    return 0;
}

Measured memory_bytes: 3608