akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define LOCAL
using std::to_string;
auto to_string(std::string s) -> std::string {
  return '"' + s + '"';
}
auto to_string(char c) -> std::string {
  return "'" + std::string{c} + "'";
}
auto to_string(const char* s) -> std::string {
  return to_string((std::string) s);
}
auto to_string(bool b) -> std::string {
  return (b ? "true" : "false");
}
template <typename T, typename U>
auto to_string(std::pair<T, U> p) -> std::string {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
template <size_t N>
auto to_string(std::bitset<N> bs) -> std::string {
  std::string res{};
  for (size_t i = 0; i < N; i++)
    res.insert(res.begin(), bs.test(i) ? '1' : '0');
  return res;
}
template <typename T>
auto to_string(T v) -> std::string {
  bool flg = false;
  std::string res = "{";
  for (auto const&x : v) {
    if (flg) res += ", ";
    else flg = true;
    res += to_string(x);
  }
  res += "}";
  return res;
}
void debug_out() { std::cerr << std::endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  std::cerr << " " << to_string(H);
  debug_out(T...);
}
#ifdef LOCAL
#define debug(...) std::cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

int main() {
  std::cin.tie(0); std::cin.sync_with_stdio(false);
  int n, k; std::cin >> n >> k;
  std::vector<int> a(n);
  for (auto& x : a) std::cin >> x;
  int sum = std::accumulate(a.begin(), a.end(), 0);
  auto divisors = [&] {
    auto ret = std::vector<int> {};
    for (int i = 1; i * i <= sum; i++) {
      if (sum % i == 0) {
        ret.push_back(i);
        if (i * i != sum) ret.push_back(sum / i);
      }
    }
    std::sort(ret.begin(), ret.end());
    return ret;
  }();
  auto check = [&] (int d) {
    std::vector<int> rem(2 * n);
    std::transform(a.begin(), a.end(), rem.begin(), [d](auto x){return x % d;});
    std::transform(rem.begin(), rem.begin() + n, rem.begin() + n, [d](auto x){return x - d;});
    std::sort(rem.begin(), rem.end());
    long long now = std::accumulate(rem.begin(), rem.begin() + n, 0LL);
    for (int l = 0; l <= n; l++) {
      int r = l + n;
      long long abs = std::accumulate(rem.begin() + n, rem.begin() + r, 0LL);
      if (now == 0 && abs <= (long long)k) return true;
      if (l == n) break;
      now -= rem.at(l);
      now += rem.at(r);
    }
    return false;
  };
  int ans = 1;
  for (auto d : divisors) {
    if (check(d)) ans = std::max(ans, d);
  }
  std::cout << ans << std::endl;
  return 0;
}

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

using namespace std;

#define SZ(x) (int)(x.size())

using ll = long long;
using ld = long double;
using P = pair<int, int>;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
const double eps = 1e-10;
const int MOD = 1000000007;
const int INF = 1000000000;
const ll LINF = 1ll<<50;

template<typename T>
void printv(const vector<T>& s) {
  for(int i=0;i<(int)(s.size());++i) {
    cout << s[i];
    if(i == (int)(s.size())-1) cout << endl;
    else cout << " ";
  }
}

int f(int a) {
  return (a * a + 4) / 8;
}

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

  int n; cin >> n;
  vi a(n);
  for(int i=0;i<n;++i) {
    cin >> a[i];
  }
  sort(a.begin(), a.end());
  cout << a[n-1] - a[0] << endl;
}


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

namespace ConsoleApp1
{
    class Program
    {
        static void Main(string[] args)
        {
            var inputs = Console.ReadLine().Split(' ').Select(v => long.Parse(v)).ToArray();
            var A = inputs[0];
            var B = inputs[1];
            var C = inputs[2];
            var X = inputs[3];
            var Y = inputs[4];

            var ans = long.MaxValue;
            for (int i = 0; i <= 200000; i += 2)
            {
                var res = i * C;
                var x = Math.Max(0, X - i / 2);
                var y = Math.Max(0, Y - i / 2);
                res += x * A;
                res += y * B;
                ans = Math.Min(ans, res);
            }
            Console.WriteLine(ans);
        }
    }
}


Measured memory_bytes: 13268
import java.util.*;

public class Main{
      public static void main(String[] args) {
            Scanner sc = new Scanner(System.in);
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();
            int d = sc.nextInt();
            if(Math.abs(c-a) <= d || Math.abs(b-a) <= d && Math.abs(c-b) <=d){
              System.out.println("Yes");
            } else {
              System.out.println("No");
            }
          }
}


Measured memory_bytes: 21844
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e18;

int d[1010 * 1010];
bool f[1010 * 1010];
bool g[1010 * 1010];

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, m;
    cin >> n >> m;
    vector<int> a(n), b(m);
    rep(i, 0, n) cin >> a[i];
    rep(i, 0, m) cin >> b[i];
    set<int> st;
    bool h = true;
    rep(i, 0, n){
        if(st.count(a[i])){
            h = false;
        }
        st.insert(a[i]);
    }
    st.clear();
    rep(i, 0, m){
        if(st.count(b[i])){
            h = false;
        }
        st.insert(b[i]);
    }
    if(!h){
        cout << 0 << endl;
        return 0;
    }
    rep(i, 0, n){
        rep(j, 0, m){
            int tmp = min(a[i], b[j]);
            if(a[i] == b[j]){
                g[a[i]] = true;
            }
            f[tmp] = true;
            d[tmp]++;
        }
    }
    int ans = 1, now = 0;
    for(int i = n * m; i >= 1; i--){
        now += d[i];
        if(g[i]){
            // cout << 1 << endl;
        }else if(f[i]){
            // cout << d[i] << endl;
            (ans *= d[i]) %= mod;
        }else{
            // cout << now << endl;
            (ans *= now) %= mod;
        }
        now--;
    }
    cout << ans << endl;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#define ll long long
using namespace std;
const int N=100010;
int n;
ll a[N],ans[N];
int main(){
//	freopen("1.in","r",stdin);
    cin>>n;
    for(int i=1;i<=n;++i){
        scanf("%lld",a+i);
        a[i]*=2;
	}
	ll sum=0;
	for(int i=1;i<=n;++i){
	    sum=a[i]-sum;
	}
	ans[1]=sum/2;
	for(int i=2;i<=n;++i){
	    ans[i]=a[i-1]-ans[i-1];
	}
	for(int i=1;i<=n;++i){
	    printf("%lld ",ans[i]);
	}
	puts("");
	return 0;
}

Measured memory_bytes: 2816
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9;
static const ll INF = 1LL << 50;
using namespace std;

int main() {
	string s;
	cin >> s;
	string sub1 = s.substr(0,2), sub2=s.substr(2,2),ans;
	if (sub1 <= "12" && sub1 != "00") {
		if (sub2 <= "12" && sub2 != "00")ans = "AMBIGUOUS";
		else ans = "MMYY";
	}
	else {
		if (sub2 <= "12" && sub2 != "00")ans = "YYMM";
		else ans = "NA";
	}cout << ans << endl; return 0;
}

Measured memory_bytes: 256
N=int(input())
s=input()
e=0
w=0
for i in s:
    if(i=='W'):
        w+=1
    elif(i=='E'):
        e+=1
ans=[0,0]
dp=[-1 for _ in range(N)]

for i in range(N):
    tmp=ans[1]
    if(s[i]=='W'):
        ans[1]+=1
    else:
        ans[0]+=1
    dp[i]=tmp+(e-ans[0])

print(min(dp))

Measured memory_bytes: 15520
#include <stdio.h>

int min(int a, int b){
  return 0 <= (b-a) ? a : b;
}

int nl(int a){
  return 0 <= a ? a : 0;
}

int main(){
  int a,b,c,x,
      i,j,res=0;
  
  scanf("%d%d%d%d", &a, &b, &c, &x);
  
  x /= 50;
  
  for(i=min(x/10, a); 0<=i; i--){
    res += nl(min((x-10*i)/2, b) - nl((x-10*i - c + 1) / 2) + 1);
/*    for(j=0; j<=min((x-10*i)/2,b); j++){
      if((x - 10*i - c + 1) / 2 <= j){
        res++;
      }
    }
*/  }
  
  printf("%d", res);
  
  return 0;
}

Measured memory_bytes: 128
#include<iostream>
#include<vector>
#include<set>
#include<algorithm>

using ll = long long;
#define rep(i,n) for(int i=0; i<(n); i++)
using namespace std;

int main(){

    rep(i,5){
        int a;
        cin >> a;
        if(a==0)
            cout << i+1 << endl;
    }

     return 0;
}

Measured memory_bytes: 3632
n,y = gets.chomp.split(" ").map(&:to_i)
y /= 1000
for i in 0..8
  x = y-4*i-n
  if x >= 0 && x%9 == 0 && n-i-x/9 >= 0
    puts "#{x/9} #{i} #{n-i-x/9}"
    exit
  end
end
puts "-1 -1 -1"

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

#define ll long long
#define ull unsigned long long

using namespace std;

int main() {
	int N, M, X, Y;
	cin >> N >> M >> X >> Y;
	vector <int> x(N, 0);
	for (int ii = 0; ii < N; ++ii){
		cin >> x[ii];
	}
	vector <int> y(M, 0);
	for (int ii = 0; ii < M; ++ii){
		cin >> y[ii];
	}

	x.push_back(X);
	y.push_back(Y);

	sort(x.begin(), x.end());
	sort(y.begin(), y.end());

	int xmax = x[N];
	int ymin = y[0];

	if (xmax < ymin){ 
		cout << "No War" << "\n";
	} else {
		cout << "War" << "\n";		
	}


	

	return 0;
}


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


int main() {
    string s;
    cin >> s;
    int lst = s.length()-1;
    if (s[lst] != 's') {
        cout << s+"s" << endl;
    } else {
        cout << s+"es" << endl;
    }
    return 0;
}

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

using namespace std;

typedef long long ll;

const int maxn=1e5+10;

struct point{
    int x,y;
    point(){}
    point(int x,int y):x(x),y(y){}
} ;

struct segment{
    point a,b;
    int c;                  //用于排序，bottom>(left||right)>top
    segment(point a,point b,int c):a(a),b(b),c(c){}
    bool operator <(const segment & p){
        if(a.y!=p.a.y) return a.y<p.a.y;
        return c!=p.c?c<p.c:a.x<p.a.x;
    }
};

vector<segment> v;

int x[maxn*2];

int tree[maxn<<2];

void up(int p){
    tree[p]=tree[p<<1]+tree[p<<1|1];
}

void modify(int p,int l,int r,int x,int v){
    if(l==r){
        tree[p]+=v;
        return ;
    }
    int mid=l+r>>1;
    if(x<=mid){
        modify(p<<1,l,mid,x,v);
    }else{
        modify(p<<1|1,mid+1,r,x,v);
    }
    up(p);
}

int query(int p,int l,int r,int x,int y){
    if(x<=l&&r<=y){
        return tree[p];
    }
    int mid=l+r>>1;
    int res=0;
    if(x<=mid){
        res+=query(p<<1,l,mid,x,y);
    }
    if(y>mid){
        res+=query(p<<1|1,mid+1,r,x,y);
    }
    return res;
}

int main(){
    int n;
    scanf("%d",&n);
    int len=1;
    for(int i=0;i<n;i++){
        point a,b;
        scanf("%d%d%d%d",&a.x,&a.y,&b.x,&b.y);
        if(a.x!=b.x){
            if(a.x>b.x) swap(a,b);
            x[len++]=a.x;
            x[len++]=b.x;
            v.push_back(segment(a,b,2));
        }else{
            if(a.y>b.y) swap(a,b);
            x[len++]=a.x;
            v.push_back(segment(a,a,1));
            v.push_back(segment(b,b,3));
        }
    }
    len--;
//    printf("%d\n",len);
    sort(x+1,x+len+1);
    len=unique(x+1,x+len+1)-(x+1);
//    for(int i=1;i<=len;i++){
//        printf("%d ",x[i]);
//    }
    sort(v.begin(),v.end());
    int vsize=v.size();
//    for(int i=0;i<vsize;i++){
//        printf("%d %d %d\n",v[i].a.x,v[i].a.y,v[i].c);
//    }
    int ans=0;
    for(int i=0;i<vsize;i++){
        if(v[i].a.x==v[i].b.x){
            int id=lower_bound(x+1,x+len+1,v[i].a.x)-x;
//            printf("--%d %d\n",v[i].a.x,id);
            int c=v[i].c==3?-1:1;
            modify(1,1,len,id,c);
//            printf("123123123\n");
        }else{
            int id1=lower_bound(x+1,x+len+1,v[i].a.x)-x;
            int id2=lower_bound(x+1,x+len+1,v[i].b.x)-x;
//            printf("%d %d\n",v[i].a.x,id1);
//            printf("%d %d\n",v[i].b.x,id2);
            ans+=query(1,1,len,id1,id2);
        }
    }
    printf("%d\n",ans);
    return 0;
}



Measured memory_bytes: 8484
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const static ll INF = 1e9;
const static ll MOD = 1e9+7;


int main(){
    int N; cin >> N;
    vector<pair<ll, ll>> V(N);
    for(int i = 0; i < N; i++){
        ll x, y; cin >> x >> y;
        V[i] = make_pair(x, y); 
    } 
    sort(V.begin(), V.end());
    map<pair<ll, ll>, int> M;
    for(int i = 0; i < N-1; i++){
        for(int j = i+1; j < N; j++){
            M[make_pair(V[j].first - V[i].first, V[j].second - V[i].second)]++;
        }
    }
    ll Max = 0;
    for(auto m : M) Max = max(Max, (ll)m.second);
    cout << N - Max << endl;

}

Measured memory_bytes: 384
import math
import itertools
def comb(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))
N, X, Y =map(int,input().split())

L = [i for i in range(1,N+1)]
c_list = list(itertools.combinations(L,2))

Answer = {}
for i in range(1,N):
    inti = str(i)
    Answer[inti] = 0
def des(a,b):
    if b <= X or a >=  Y:
        return (b-a)
    else:
        return min(b-a, abs(Y-b)+abs(X-a)+1)
for cl in c_list:
    a = cl[0]
    b = cl[1]
    inti = des(a,b)
    inti = str(inti)
    Answer[inti] += 1
for n, m in Answer.items():
    print(m)


Measured memory_bytes: 151872
#include<bits/stdc++.h>
using namespace std;
long long n,m,k,a[300010],b[300010],x[300010],y[300010],ans,c,d,f,aa,bb;
int main(){
	cin>>n>>m>>k;
	for (int i=0;i<k;i++){
		cin>>x[i]>>y[i];
		a[x[i]]++;
		b[y[i]]++;
	}
	for (int i=1;i<=n;i++) c=max(c,a[i]);
	for (int i=1;i<=n;i++) if (a[i]==c) aa++;
	for (int i=1;i<=m;i++) d=max(d,b[i]);
	for (int i=1;i<=m;i++) if (b[i]==d) bb++;
	for (int i=0;i<k;i++) if (a[x[i]]==c&&b[y[i]]==d) f++;
	if (f<aa*bb)
		cout<<c+d<<endl;
	else
		cout<<c+d-1<<endl;
	return 0;
}

Measured memory_bytes: 13012
#include<cstdio>
#include<iostream>
#include<cstring>
using namespace std;
const int N=4e5+10;
int w[N],ne[N],la[N],t;
int a[N],dfn[N],ed[N],n,fa[N],mrk[N],pre[N];
void link(int x,int y){
	w[++t]=y;
	ne[t]=la[x];
	la[x]=t;
}
void dfs(int x,int s,int ms){
	if (s==ms)ms=x;
	if (x>pre[s])s=ms;
	if (x>max(s,pre[s]))s=ms=x;
	ed[x]=dfn[x]=++t;
	for (int y=la[x];y;y=ne[y]){
		int z=w[y];
		if (z==fa[x])continue;
		pre[z]=max(pre[x],x);
		fa[z]=x;
		dfs(z,s,ms);
		ed[x]=ed[z];
	}
	mrk[x]=s;
}
int main(){
	cin>>n;
	for (int i=1;i<n;i++){
		int x,y;
		scanf("%d%d",&x,&y);
		link(x,y);
		link(y,x);
	}t=0;
	dfs(1,0,0);
	for (int i=1;i<=n;i++)a[dfn[mrk[i]]]++,a[ed[mrk[i]]+1]--;
	for (int i=1;i<=n;i++)a[i]+=a[i-1];
//	for (int i=1;i<=n;i++){
//		if (dfn[mrk[i]]<=dfn[77]&&dfn[77]<=ed[mrk[i]]){
//			cout<<i<<endl;
//		}
//	}
	for (int i=2;i<=n;i++)printf("%d ",a[dfn[i]]-1);
}

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

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

using namespace std;

int main(){
  string s[3];
  cin>>s[0];
  cin>>s[1];
  cin>>s[2];

  int c=s[0].at(0)-'a';
  s[0].erase(0,1);
  while(true){
    if(s[c].empty())break;
    int t=s[c].at(0)-'a';
    s[c].erase(0,1);
    c=t;
  }

  cout<<(char)(c+'A');
  return 0;
}

Measured memory_bytes: 256
// Mo's algorithm
// 例題：数列の区間内の要素の種類数を求める  ABC174 F

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

struct Mo {
    vector<int> left, right, index; // offline query
    int window; // bucket width
    int nl, nr, ptr; // [nl,nr)

    vector<int> a; // input
    vector<int> res; // output
    // add,delで書き換えていく
    vector<int> count;
    int sum;
    
    
    Mo(int n, vector<int> aa) : window((int)sqrt(n)), nl(0), nr(0), ptr(0), count(n,0), sum(0) { a = aa; }
    
    /* query [l,r) 0-indexed */
    void push(int l, int r) { left.push_back(l), right.push_back(r); }
    
    /* query sort */
    void build() {
        index.resize(left.size());
        res.resize(left.size());
        iota(index.begin(), index.end(), 0);
        sort(index.begin(), index.end(), [&](int a, int b){
            if (left[a] / window != left[b] / window) return left[a] < left[b];
            if((left[a] / window) % 2) return right[a] > right[b];
            return right[a] < right[b];
        });
    }

    /* 問題ごとに書き換える */
    void add(int id){ if(count[a[id]]++ == 0) sum++; return; };
    void del(int id){ if(--count[a[id]] == 0) sum--; return; }
    
    /* 区間を次のquery用に伸縮させる */
    void next() {
        int i = index[ptr++];
        while (left[i] < nl ) add(--nl);
        while (nr < right[i]) add(nr++);
        while (nl < left[i] ) del(nl++);
        while (right[i] < nr) del(--nr);
        res[i] = sum;
    } // 返り値はquery-index
};

int n, q, l, r;

int main() {
    cin >> n >> q;
    vector<int> a(n);
    rep(i,n){ cin >> a[i]; a[i]--; }
    Mo mo(n,a);
    rep(i,q){ cin >> l >> r; mo.push(--l, r); }

    mo.build();
    rep(i,q) mo.next();
    rep(i,q) cout << mo.res[i] << "\n";
    return 0;
}

Measured memory_bytes: 18492
# 小さい方からk番目がx
# x以下がk個以上となる最小のx
# 負の数のところでバグってそう
from bisect import bisect_left, bisect_right

import sys

input = sys.stdin.buffer.readline

n, k = map(int, input().split())
A = list(map(int, input().split()))
A.sort()
minusA = bisect_left(A, 0)
mA = A[:minusA]

zeroA = bisect_right(A, 0) - bisect_left(A, 0)
plusA = n - minusA - zeroA
pA = A[-plusA:]
minus = minusA * plusA
plus = plusA * (plusA - 1) // 2 + minusA * (minusA - 1) // 2
zero = zeroA * (zeroA - 1) // 2 + (n - zeroA) * zeroA


# x以下の数を数える
def calc(x):
    mmA = mA[::-1]
    res = 0
    if x > 0:
        lim = plusA - 1
        for i in range(plusA):
            while lim >= 0:
                if pA[i] * pA[lim] > x:
                    lim -= 1
                else:
                    break
            res += lim + 1
            if lim >= i:
                res -= 1
        lim = minusA - 1
        mmA = mA[::-1]
        for i in range(minusA):
            while lim >= 0:
                if mmA[i] * mmA[lim] > x:
                    lim -= 1
                else:
                    break
            res += lim + 1
            if lim >= i:
                res -= 1
        res //= 2
        res += minus + zero
    elif x == 0:
        res += minus + zero
    else:
        # 正の数、左絶対値小さい
        # 負の数、左絶対値大きい
        lim = minusA - 1
        for i in range(plusA):
            while lim >= 0:
                if pA[i] * mmA[lim] <= x:
                    lim -= 1
                else:
                    break
            res += minusA - (lim + 1)
    return res


ng = -(10 ** 20)
ok = 10 ** 20
while ok - ng > 1:
    mid = (ok + ng) // 2
    if calc(mid) >= k:
        ok = mid
    else:
        ng = mid

print(ok)


Measured memory_bytes: 163832
#include<cstdio>
long long s[2][100002];
long long const infty=1e15;
inline long long max(long long a,long long b){
    return (a<b)?b:a;
}
inline long long min(long long a,long long b){
    return (a<b)?a:b;
}
inline long long min(long long a,long long b,long long c){
    return min(a,min(b,c));
}
inline long long min(long long a,long long b,long long c,long long d){
    return min(min(a,b),min(c,d));
}
int main(){
    int a[2],q;
    scanf("%d%d%d",&a[0],&a[1],&q);
    for(int i=0;i<2;i++){
        s[i][0]=-infty;
        for(int j=1;j<=a[i];j++)scanf("%lld",&s[i][j]);
        s[i][a[i]+1]=infty;
    }
    for(int qi=0;qi<q;qi++){
        long long x;
        scanf("%lld",&x);
        int l[2],r[2];
        long long dl[2],dr[2];
        for(int i=0;i<2;i++){
            l[i]=0;
            r[i]=a[i]+1;
            while(r[i]-l[i]>1){
                int m=(r[i]+l[i])/2;
                if(s[i][m]<x)l[i]=m;
                else r[i]=m;
            }
            dl[i]=x-s[i][l[i]];
            dr[i]=s[i][r[i]]-x;
        }
        //左に直進: 左側の遠いほうまでの距離
        //右に直進: 右側の遠いほうまでの距離
        //方向転換: 左右の近いほうまでの距離の和+xまで戻る距離
        printf("%lld\n",min(max(dl[0],dl[1]),max(dr[0],dr[1]),min(dl[0],dr[0])+min(dl[1],dr[1])+min(dl[0],dl[1],dr[0],dr[1])));
    }
    return 0;
}

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

namespace ConsoleApplication5
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] tmp = Console.ReadLine().Split(' ');

            long X = long.Parse(tmp[0]);
            long A = long.Parse(tmp[1]) * -1;
            long B = long.Parse(tmp[2]);

            string ret = "";
            if (A + B <= 0) ret = "delicious";
            else if (A + B > X) ret = "dangerous";
            else ret = "safe";

            Console.WriteLine(ret);
            Console.Read();
        }

    }
}


Measured memory_bytes: 11092
#include <bits/stdc++.h>
#define int long long
#define vi vector <int>
#define si set <int>
#define mii map <int,int>
#define pii pair <int,int>
#define endl "\n"
#define FOR(P,Q) for(int P=0;P<(Q);P++)
#define FORR(P,Q) for(int P=1;P<=(Q);P++)
#define rep(P,R,Q) for(int P=(R);P<=(Q);P++)
#define repb(P,R,Q) for(int P=(R);P>=(Q);P--)
#define pb push_back
#define eb emplace_back
#define bug(P) cerr<<P<<" "
#define NL cerr<<endl
#define D1(arr,a) rep(P,1,a) bug(arr[P]) 
#define F first
#define S second
typedef long long ll;
typedef long double ld;
using namespace std;


    
int32_t main()
{
    ios_base::sync_with_stdio(0);
    cout.tie(0);
    cin.tie(0);
    #ifndef ONLINE_JUDGE
    freopen("error.txt","w",stderr);
    #endif
    int tces=1;
    // cin>>tces;
    while(tces--){
        int n;
        cin>>n;
        vi v(n+5);
        FORR(i,n){
            cin>>v[i];
        }
        int ans=0;
        sort(v.begin()+1, v.begin()+n+1);
        FORR(i,n){
            rep(j,i+1,n){
                rep(k,j+1,n){
                    if(v[i]-v[j] and v[j]-v[k] and v[i]+v[j]>v[k])
                        ans++;
                }
            }
        }
        cout<<ans;
    }
    
return 0;
}

Measured memory_bytes: 3652
/*Bismillahir Rahmanir Rahim*///{
#include <bits/stdc++.h>
#include <ext/numeric>
using namespace std; using __gnu_cxx::power;
using ll = long long; using ull = unsigned long long; using ld = long double;
const ll llinf = (1ll<<61)-1; const double eps = 1e-6, ldeps = 1e-9;
struct Dbg { static constexpr auto &os = cout;   // replace by cerr in interactive.
template<class C> static auto o(C *x)->decltype(os << *x, 0);
template<class C> static char o(...);
template<class C> typename enable_if<sizeof o<C>(0)!=1,Dbg&>::type operator<<(const C &x) {os<<x; return *this;}
template<class C> Dbg &dump(C b, C e) {
    for (struct{C i;int j;} i={(*this<<"\n[",b),0}; i.i!=e and i.j<26; i.i++, i.j++) *this<<", "+2*(i.i==b)<<*i.i;
    return *this << ']';
}
template<class C> typename enable_if<sizeof o<C>(0)==1, Dbg&>::type operator<<(const C &x) {
    return dump(begin(x), end(x));
}
template<class C, size_t X> typename enable_if<!is_same<C, const char>::value, Dbg&>::type operator<<(C (&x)[X]) {
    return dump(begin(x), end(x));
}
template<class B, class C> Dbg &operator<<(const pair<B, C> &x) {return *this<<'{'<<x.first<<", "<<x.second<<'}';}
Dbg &operator<<(ostream&(*x)(std::ostream&)) { os << x; return *this; }
} dbg;
void err(istringstream *iss) { delete iss; }
template<class C, class... Args> void err(istringstream *iss, const C &val, const Args &... args) {
    string name; *iss >> name; if (name.back()==',') name.pop_back();
    dbg << name << " = " << val << "; ", err(iss, args...);
}
#define bug(args...) dbg << __LINE__ << ": ", err(new istringstream(#args), args), dbg << endl
#define cbug(a, args...) if (a) bug(args);
#define ASSERT(a, o, b, args...) if (!((a)o(b))) bug(a, b, ##args), assert((a)o(b));
#define sl(a) int(strlen(a))
#define sz(a) int(a.size())
int T, Q, cn;//}
const int inf = 1000000007, mxn = 200005;

int n, a[mxn];

signed main() { cin.tie(0)->sync_with_stdio(0); cin.exceptions(cin.failbit); cout.precision(11), cout.setf(ios::fixed);
    cin >> n;
    for (int i = 1; i <= n; i++) {
        cin >> a[i];
    }
    sort(a+1, a+1+n, greater<int>());
    ll ans = a[1];
    int cur = 1;
    for (int i = 3; i <= n; i++) {
        cur += (i&1);
        ans += a[cur];
    }
    cout << ans << '\n';
}

Measured memory_bytes: 4408
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define f(i,a,n) for(ll i=a;i<n;i++)
#define w(_t) ll _t;cin>>_t;while(_t--)
ll md=1000000007;

ll poww(ll a,ll n){
    if(n==0) return 1;
    if(n%2==0) return poww((a*a)%md,n/2);
    else return (a*poww((a*a)%md,n/2))%md;
}


int main() {
    ios::sync_with_stdio(false);cin.tie(0);
    ll n;cin>>n;
    ll a=poww(10,n);
    ll b=(2*poww(9,n))%md;
    ll c=poww(8,n);
    a-=b;
    a+=c;
    a+=md;
    a%=md;
    cout<<a;
    return 0;
}

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

int main () {
  int n,m,sum =0;
  cin >> n >> m;
  vector<int>vec(n);
  for (int i = 0; i < n; i++) {
    cin >> vec.at(i);
  }
  sort(vec.begin(),vec.end());
  reverse(vec.begin(),vec.end());
  
  for (int i = 0; i < n; i++) {
    sum += vec.at(i);
  }
  
  if (vec.at(m-1) < (double)sum/m/4 ) {
    cout << "No" << endl;
  }
  else cout << "Yes" << endl;
}



Measured memory_bytes: 256
#AGC001 A 23:11 - 
'''
問題
2本の串にいくつかの具材を刺して串焼きをN個つくりたい
串は2N本ありi番目の串の長さはLi
2本の串のうち短いほうの長さをxとすると串焼きには最大で具材をx個刺せる
うまく串を組み合わせたとき具材は全部で最大何個刺せるか?

ただしNは1以上100以下
Liは1以上100以下

考察
串の長さの差が小さいほどよいのでLiをソートして奇数番目に小さい値の総和をとる
'''

N = int(input())
L = sorted(list(map(int,input().split(' '))))
ans = 0
for i in range(N):
	ans += L[2*i]
print(str(ans))

Measured memory_bytes: 2940
using System;
using System.Collections;
using System.Collections.Generic;

namespace ConsoleApplication6
{
    class Program
    {
        static void Main(string[] args)
        {
            var read = Console.ReadLine();
            int N = int.Parse(read);
            int maxhidari = 0;
            int maxmigi = 0;
            for (int i = 0; i < N; i++)
            {
                var split = Console.ReadLine().Split(' ');
                int hidari = int.Parse(split[0]);
                int migi = int.Parse(split[1]);
                if (maxhidari < hidari)
                {
                    maxhidari = hidari;
                    maxmigi = migi;
                }
            }
            Console.WriteLine(maxhidari + maxmigi);
        }
    }
}


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

int main(){
    string S;
    cin >> S;
    int count = 0;

    for(int i = 0; i < S.size(); i++){
        if(S.at(i) == 'A'){
            for(int j = S.size()-1; j > i; j--){
                if(S.at(j) == 'Z'){
                    cout << j - i + 1 << endl;
                    return 0;
                }
            } 
        }
    }
}

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

int main() {
	int N,height;
	cin >> N;
	height = 1;
	vector<int> v(N);
	//cin.ignore();
	for (int i = 0; i < N; i++) {
		cin >> v.at(i);
	}
	sort(v.begin(), v.end());
	for (int i = 0; i < N; i++) {
		if (i + 1 < N) {
			if (v.at(i) < v.at(i + 1)) {
				height++;
			}
		}
	}
	cout << height << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
typedef long long int ll;
typedef long double ld;
using namespace std;
const long long int INF = 1e18;
const long long int MOD = 1e9+7;

typedef pair<ll, ll> pairs;
typedef vector<pairs> p;

struct edge{
    ll to, cost;
};


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

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

ll keta(ll N){
    int tmp{};
    while( N > 0 ){
        tmp += ( N % 10 );
        N /= 10;
    }
    N = tmp;
    return N;
}

// 素数
vector<bool> IsPrime;
void sieve(size_t max){
    if(max+1 > IsPrime.size()){
        IsPrime.resize(max+1,true);
    } 
    IsPrime[0] = false;
    IsPrime[1] = false;

    for(size_t i=2; i*i<=max; ++i){
        if(IsPrime[i]){
            for(size_t j=2; i*j<=max; ++j){
                IsPrime[i*j] = false;
            }
        }
    }
}

// べき乗の余り
ll modpow(ll a, ll n, ll mod){
    ll res = 1;
    while(n){
        if(n & 1){
            (res *= a) %= mod;
        }else{
            (a *= a) %= mod;
        }
        n >>= 1;
    }
    return res;
}

// 回文
bool kai(string S){
    bool flag = true;
    for(ll i=0;i<S.size()/2;++i){
        if(S[i] != S[S.size()-i-1]){
            flag = false;
            break;
        }
    }
    return flag;
}
// ---------------------------------------------

int main(){
    string s;
    cin>>s;
    ll Q;
    cin>>Q;
    bool flag = true;
    vector<char> x;
    vector<char> y;
    for(ll i=0;i<Q;++i){
        ll a;
        cin>>a;

        if(a == 1){
            if(flag){
                flag = false;
            }else{
                flag = true;
            }
        }else if(a == 2){
            ll f;
            char c;
            cin>>f>>c;
            if(f == 1){
                if(flag){
                    x.push_back(c);
                }else{
                    y.push_back(c);
                }
            }else if(f == 2){
                if(flag){
                    y.push_back(c);
                }else{
                    x.push_back(c);
                }
            }
        }
    }

    if(flag){
        for(ll i=x.size()-1;i>=0;--i){
            cout<<x[i];
        }
        cout<<s;
        for(ll i=0;i<y.size();++i){
            cout<<y[i];
        }
        cout<<endl;
    }else{
        for(ll i=y.size()-1;i>=0;--i){
            cout<<y[i];
        }
        reverse(s.begin(), s.end());
        cout<<s;
        for(ll i=0;i<x.size();++i){
            cout<<x[i];
        }
        cout<<endl;
    }

    return 0;
}

Measured memory_bytes: 3800
use std::io::*;
use std::str::FromStr;

fn parse_line<T: FromStr>() -> T {
    let mut s = String::new();
    stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn parse_quadraple<T: FromStr, U: FromStr, V: FromStr, W: FromStr>() -> (T, U, V, W) {
    let line = parse_line::<String>();
    let mut iter = line.split_whitespace();
    (
        iter.next().unwrap().parse().ok().unwrap(),
        iter.next().unwrap().parse().ok().unwrap(),
        iter.next().unwrap().parse().ok().unwrap(),
        iter.next().unwrap().parse().ok().unwrap(),
    )
}

fn println<T: ToString>(s: T) {
    println!("{}", s.to_string());
}

// ------------------------------------------------------------------------

fn gcd(x: u64, y: u64) -> u64 {
    let mut x = x;
    let mut y = y;
    while y != 0 {
        let t = y;
        y = x % y;
        x = t;
    }
    x
}

// ------------------------------------------------------------------------

fn count_dividable(min_n: u64, max_n: u64, divisor: u64) -> u64 {
    if min_n == max_n {
        return if min_n % divisor == 0 { 1 } else { 0 };
    }

    let first_valid = if min_n % divisor == 0 { min_n } else { min_n + divisor - min_n % divisor };

    if first_valid <= max_n {
        1 + (max_n - first_valid) / divisor
    } else {
        0
    }
}

fn main() {
    let (a, b, c, d) = parse_quadraple::<u64, u64, u64, u64>();

    if c == d {
        println(b + 1 - a - count_dividable(a, b, c));
        return;
    }

    let lcm = c * d / gcd(c, d);

    println(
        b + 1 - a - (count_dividable(a, b, c) + count_dividable(a, b, d) - count_dividable(a, b, lcm))
    );
}


Measured memory_bytes: 4352
N,M,X,Y=map(int,input().split())
x=list(map(int,input().split()))
y=list(map(int,input().split()))
A=max(x)
B=min(y)
if A>=B:
    print("War")
else:
    if X<=A and B<=Y:
        print("No War")
    else:
        print("War")


Measured memory_bytes: 3060
fun main(args: Array<String>) {
    val (A, B) = listOfLong()
    var ans = ""
    println(lcm(A, B))
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong(delta: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + delta }
fun gcd(a: Long, b: Long): Long = if (a % b == 0L) b else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b

Measured memory_bytes: 36156
#include <bits/stdc++.h>
using namespace std;
#define pii pair<int,int>
#define ff first
#define ss second
#define sfi(a) scanf("%d",&a)
#define sfi2(a,b) scanf("%d %d",&a,&b)
#define sfi3(a,b,c) scanf("%d %d %d",&a,&b,&c)
#define sfll(a) scanf("%lld",&a)
#define all(a) a.begin(),a.end()
#define keepu(a) a.erase(unique(all(a)),a.end())
#define inf 1e7
#define m_p make_pair
#define min3(a,b,c) min(a,min(b,c))
#define pb push_back
#define mem(x,val) memset(x,val,sizeof(x))
#define read freopen("output.txt","r",stdin)
#define write freopen("input.txt","w",stdout)
#define FAST  ios_base::sync_with_stdio(0);cout.tie(0)
#define sqr(x) ((x)*(x))

typedef long long ll;
const ll mod = 1e9+7;
const int sz = 500;


int main(){

    ll sum = 0;

    int n;
    cin >> n;


    for(int i=1;i<=n;i++){
        for(int j=1;j<=n;j++){
            for(int k=1;k<=n;k++){
                sum += __gcd(i,__gcd(j,k));
            }
        }
    }

    cout << sum << endl;

    return 0;
}


Measured memory_bytes: 3632
//ΔARC086C
#include<iostream>
#include<cstdio>
#include<fstream>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cmath>
#include<cstring>
#include<cstdlib>
using namespace std;
typedef long long LL;
const int N = 2e5+25;
const int mod = 1e9+7;
struct node{
	LL s0;
	LL s1;
	LL s2;
	node(int x){
		s0=1;
		s1=x;
		s2=0;
	}
	void upd(){
		s0+=s2;
		s2=0;
		if(s0>=mod)
			s0-=mod;
	}
	void merge(node& x){
		s2=s2*(x.s0+x.s1+x.s2)+s1*(x.s1+x.s2)+s0*x.s2;
		s2%=mod;
		s1=s1*x.s0+s0*x.s1;
		s1%=mod;
		s0=s0*x.s0%mod;
	}
}node0(0),node1(1);
struct vec{
	int sz;
	vector<node> vn;
	vec(){
		sz=0;
		vn.clear();
	}
	void upd(){
		int i;
		for(i=sz-1;i>=0;i=i-1){
			if(!vn[i].s2)
				return;
			vn[i].upd();
		}
	}
	void pb(node x){
		sz++;
		vn.push_back(x);
	}
	void merge(vec* x){
		int i,j;
		for(i=sz-1,j=x->sz-1;j>=0;i=i-1,j=j-1)
			vn[i].merge(x->vn[j]);
	}
};
vec* cur=new vec;
int pw[N];
int p[N],d[N],s[N],t[N];
int v[N],pr[N],la[N];
vec* merge(vec* x,vec* y){
	if(x->sz<y->sz)
		return merge(y,x);
	x->merge(y);
	return x;
}
vec* dfs(int u){
	vec* res =new vec;
	int i;
	for(i=la[u];i;i=pr[i])
		res=merge(res,dfs(v[i]));
	res->upd();
	res->pb(node1);
	return res;
}
int main()
{
	int n,i,j,x,y;
	LL ans;
	pw[0]=1;
	for(i=1;i<N-5;i=i+1)
		pw[i]=pw[i-1]*2%mod;
	scanf("%d",&n);
	s[0]=1;
	for(i=1;i<=n;i=i+1){
		scanf("%d",p+i);
		d[i]=d[p[i]]+1;
		s[d[i]]++;
		v[i]=i;
		pr[i]=la[p[i]];
		la[p[i]]=i;
	}
	for(i=n;i>=0;i=i-1){
		t[i]++;
		t[p[i]]+=t[i];
	}
	cur=dfs(0);
	reverse(cur->vn.begin(),cur->vn.end());
	ans=0;
	for(i=0;i<cur->sz;i=i+1)
		ans+=cur->vn[i].s1*pw[n+1-s[i]]%mod;
	cout<<ans%mod<<endl;
	return 0;
}
/*
31
0 1 0 2 4 0 4 1 6 4 3 9 7 3 7 2 15 6 12 10 12 16 5 3 20 1 25 20 23 24 23

*/

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

vector<long long> memo;

long long ans(int n) {
    if (n == 0) {
        return 2;
    }
    if (n == 1) {
        return 1;
    }
    if (memo[n] != -1) {
        return memo[n];
    }
    return memo[n] = ans(n - 1) + ans(n - 2);
}

int main()
{
    int N;
    cin >> N;
    memo.resize(N + 1);
    for (int i = 0; i <= N; i++) {
        memo[i] = -1;
    }
    cout << ans(N) << endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <deque>
#include <algorithm>


using namespace std;

int main()
{
	int n, c=0, ans=0, p;
	scanf("%d", &n);
	for(int i=1; i<=n; i++){
		scanf("%d", &p);
		if(p!=i){
			ans=ans+(c+1)/2;
			c=0;
		}else{
			c++;
		}
	}
	ans=ans+(c+1)/2;
	printf("%d\n", ans);

	return 0;
}

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

int main()
{
	int N, K;
	cin >> N >> K;
	int a[50];
	for (int i = 0; i < N; i++) {
		cin >> a[i];
	}
	sort(a, a + N, greater<int>());
	int sum = 0;
	for (int i = 0; i < K; i++) {
		sum += a[i];
	}
	cout << sum << endl;
}

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

int main(void) {
  int N, M;
  cin >> N >> M;
  vector<int> L(M), R(M);
  for (int i = 0; i < M; i++) {
    cin >> L[i] >> R[i];
  }
  int l_max = *max_element(L.begin(), L.end());
  int r_min = *min_element(R.begin(), R.end());
  cout << max(0, r_min - l_max + 1) << endl;
  return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
#define IOS ios::sync_with_stdio(false); cin.tie(0);
#define FOR(i,s,n) for(int i = s; i < (n); i++)
#define REP(i,n) FOR(i,0,n)
#define ALL(n) (n).begin(), (n).end()
#define RALL(n) (n).rbegin(), (n).rend()
#define ATYN(n) cout << ( (n) ? "Yes":"No") << '\n';
#define CFYN(n) cout << ( (n) ? "YES":"NO") << '\n';
#define OUT(n) cout << (n) << '\n';
using ll = long long;
using ull = unsigned long long;
using pii = pair<int,int>;
using pll = pair<ll,ll>;

int main(void)
{
    IOS
    const int P = 100;
    int n; cin >> n;
    vector<ll> x(n);
    REP(i,n) cin >> x[i];

    ll ans = 1LL << 60;
    REP(i,P+1) {
        ll tmp = 0;
        REP(j,n) {
            tmp += (x[j]-i) * (x[j]-i);
        }
        ans = min(ans,tmp);
    }

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <cmath>
typedef long long ll;

using namespace std;

int a[200000];
int c[200000];
int main()
{
	int n,k;
	int ans=0;
	
	cin>>n>>k;
	for(int i=0;i<200000;i++)
	{
		c[i]=0;
	}
	for(int i=0;i<n;i++)
	{
		cin>>a[i];
		c[a[i]]++;
	}
	sort(c,c+200000);
	reverse(c,c+200000);
	for(int i=k;i<200000;i++)
	{
		ans+=c[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 1792
#include <iostream>
#include <utility>
#include <vector>
#include <queue>
#include <stack>
#include <array>
#include <algorithm>
#include <numeric>
#include <limits>
#include <string>
#include <regex>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
using ll = long long;

int main()
{
    int N;
    cin >> N;
    int A[N];
    for (int i = 0; i < N; i++) cin >> A[i];
    sort(A, A + N);
    for (int i = 1; i < N; i++) {
        if (A[i-1] == A[i]) {
            cout << "NO" << endl;
            return 0;
        }
    }
    cout << "YES" << endl;
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define fi first
#define se second
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = 1; i <= (n); ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
#define srep(i,s,t) for (int i = s; i < t; ++i)
#define rng(a) a.begin(),a.end()
#define pb push_back
#define sz(x) (int)(x).size()
#define v(T) vector<T>
#define vv(T) v(v(T))
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<P> vp;
const double eps = 1e-10;
const ll LINF = 1001002003004005006ll;
const int INF = 1001001001;
#define dame { puts("-1"); return 0;}
#define yn {puts("YES");}else{puts("NO");}

int main(){
    int n;
    cin >> n;
    bool ans=false;

    for(int i=1;i<=9;i++){
        for(int j=i;j<=9;j++){
            if(i*j == n){
                ans = true;
            }
        }
    }

    if(ans) cout << "Yes" << endl;
    else cout << "No" << endl;
    return 0;

}

Measured memory_bytes: 256
t = {}
for i = 1, 5 do
  t[i] = io.read("*n")
end
table.sort(t, function(a, b)
  if a % 10 == b % 10 then return false
  else
    va = a % 10
    vb = b % 10
    if va == 0 then va = 10 end
    if vb == 0 then vb = 10 end
    return va < vb
  end
end
)
ret = t[1]
for i = 2, 5 do
  ret = ret + 10 * math.ceil(t[i] / 10)
end
print(ret)


Measured memory_bytes: 2792
n,m,p=map(int,input().split())
l=[list(map(int,input().split())) for i in range(m)]
distance=[float('inf')]*n
distance[0]=0
for i in range(n-1):
  for j in range(m):
    if distance[l[j][1]-1]>distance[l[j][0]-1]-l[j][2]+p:
      distance[l[j][1]-1]=distance[l[j][0]-1]-l[j][2]+p
x=distance[n-1]
for i in range(n):
  for j in range(m):
    if distance[l[j][1]-1]>distance[l[j][0]-1]-l[j][2]+p:
      distance[l[j][1]-1]=-float('inf')
if distance[n-1]!=x:
  print(-1)
elif x>0:
  print(0)
else:
  print(max(-distance[n-1],0))

Measured memory_bytes: 48216
#include <bits/stdc++.h>
using namespace std;
using vi = vector<int>;
using vii = vector<vi>;
using vs = vector<string>;
using in6 = int64_t;
using ind = double;
using pii = pair<int,int>;
using psi = pair<string,int>;
using vpi = vector<pii>;
using vps = vector<psi>;
#define rep(i, n) for (in6 i = 0; i < (in6)(n); i++)
#define repa(i,a,n) for(in6 i = a; i < (in6)(n); i++)
#define repdown(i,n) for(in6 i = n; i > 0; i--)
#define kyun ios::sync_with_stdio(false)
#define hinata cout << "\n"
#define all(c) (c).begin(), (c).end()
#define pb push_back
#define inf 2147483647
#define dset(n) cout << fixed << setprecision(n)

void yes() {
  cout << "Yes";
}

void no() {
  cout << "No";
}

int main() {
  kyun;
  in6 x,y;
  cin >> x >> y;
  in6 floor = 2*x;
  in6 ceiling = 4*x;
  bool ans = 1;
  if(y < floor || y > ceiling) ans = 0;
  else if(y & 2 != 0) ans = 0;
  if(ans) yes();
  else no();
  hinata;
}

Measured memory_bytes: 3612
from collections import deque

import numpy as np

n, p = map(int, input().split())
d = deque(input())

ans = 0
if p == 2 or p == 5:
  for i in range(n):
    k = int(d.popleft())
    if k % p == 0:
      ans += i + 1
else:
  sub = [0 for i in range(n)]
  wk = 0
  for i in range(n):
    k = int(d.pop())
    wk = (wk + k * pow(10, i, p)) % p
    sub[i] = wk
  ans = 0
  dic = {}
  for i in range(n):
    if sub[i] == 0:
      ans += 1
    if sub[i] in dic.keys():
      ans += dic[sub[i]]
      dic[sub[i]] = dic[sub[i]] + 1
    else:
      dic[sub[i]] = 1

print(ans)

Measured memory_bytes: 21496
N = int(input())
A = list(map(int, input().split(" ")))
B = list(map(int, input().split(" ")))

c = A[:]
# print(c)
point = 0
for i in range(N):
    p = min(c[i], B[i])
    c[i] -= p
    point += p
    p = min(c[i+1], B[i]-p)
    c[i+1] -= p
    point += p

print(point)

Measured memory_bytes: 18476
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        #[allow(unused_mut)]
        let mut s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

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

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

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

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

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

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

fn main() {
    input! {
        n: u32,
        a: u32,
        b: u32,
    };
    let s: u32 = (0..=n)
        .filter(|&c| {
            let s = sum_digit(c);
            s >= a && s <= b
        })
        .sum();
    println!("{}", s);
}

fn sum_digit(n: u32) -> u32 {
    n.to_string()
        .chars()
        .map(|c| c.to_digit(10).unwrap())
        .sum::<u32>()
}


Measured memory_bytes: 2128
import kotlin.math.*
import java.util.*

fun gcd(a: Int, b: Int): Int {
  var x = a
  var y = b
  if (y < x) {
    x = b
    y = a
  }
  for (i in x downTo 1) {
    if (x % i == 0 && y % i == 0) return i
  }
  throw RuntimeException()
}

fun main(args: Array<String>) {
  val k = readLine()!!.toInt()
  var ans = 0
  for (x in 1..k) {
    for (y in 1..k) {
      val s = gcd(x, y)
      for (z in 1..k) {
        ans += gcd(s, z)
      }
    }
  }
  println(ans)
}


Measured memory_bytes: 35948
N=int(input())
D=list(map(int,input().split()))
if D[0] >0:
  print(0)
  exit()
X=[0]*N
for d in D[1:]:
  X[d-1]+=1
ans=1
i=1
while X[i]!=0:
  ans*=X[i-1]**X[i]
  i+=1
while i<N:
  if X[i]!=0:
    ans=0
    break
  i+=1
print(ans%998244353)

Measured memory_bytes: 14020
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
const int dx[] = {-1, 0, 1, 0};
const int dy[] = { 0,-1, 0, 1};

struct NODE{
	int x,y;
	int count;
	char sw;
};
bool operator<(const NODE &a,const NODE &b){
	return a.count > b.count;
}

int w,h;
bool isWrong(const NODE &n){
	if(n.x > w+1 || n.y > h+1)return true;
	if(n.x <  0  || n.y <  0 )return true;
	return false;
}
bool isEdge(const NODE &n){
	if(n.x == 0 || n.x == w+1)return true;
	if(n.y == 0 || n.y == h+1)return true;
	return false;
}

int main(){
	while(cin >> w >> h, w){
		char map[102][102];
		rep(i,102)rep(j,102)map[i][j] = '.';
		NODE t; t.count = 0, t.sw = '.';
		
		for(int i=1;i<=h;i++){
			for(int j=1;j<=w;j++){
				cin >> map[i][j];
				if(map[i][j] == '&')t.y = i, t.x = j , map[i][j] = '.';
			}
		}
		
		int memo[102][102];
		rep(i,102)rep(j,102)memo[i][j] = (1<<21);
		
		priority_queue<NODE> Q;
		Q.push(t);
		while(Q.size()){
			NODE q = Q.top(); Q.pop();
			if(memo[q.y][q.x] <= q.count)continue;
			
			if(isEdge(q)){
				cout << q.count << endl;
				break;
			}
			memo[q.y][q.x] = q.count;
			rep(i,4){
				NODE nt;
				nt.x = q.x+dx[i], nt.y = q.y+dy[i], nt.count = q.count;
				if(isWrong(nt))continue;
				if( q.sw == '#' && map[nt.y][nt.x] == '.')nt.count++;
				nt.sw = map[nt.y][nt.x];
				
				Q.push(nt);		
			}
		}
	}
}

Measured memory_bytes: 0