akhauriyash/Code-Regression huggingface dataset:
n = gets.to_i
as = gets.strip.split.map(&:to_i)

sum = as.sum

ans = as.map.with_index(0) { |a, i|
  sub_sum = sum - as[i]
  as[i] * sub_sum
}.sum / 2

puts(ans % (10 ** 9 + 7))


Measured memory_bytes: 48104
import sys
import math
from fractions import gcd
# import queue
# from collections import Counter
# from itertools import accumulate
# from functools import reduce

def lcm(a, b):
    return a * b // gcd(a, b)

def combination_count(n, r):
    return math.factorial(n) // (math.factorial(n - r) * math.factorial(r))

def permutations_count(n, r):
    return math.factorial(n) // math.factorial(n - r)

big_prime = 1000000007

"""
# 標準入力取得
## 文字列
 =  sys.stdin.readline().rstrip()
 =  list(sys.stdin.readline().rstrip())

## 数値
 =  int(sys.stdin.readline())
 =  map(int, sys.stdin.readline().split())
 =  list(map(int, sys.stdin.readline().split()))
 =  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]
"""

N = int(sys.stdin.readline())
list_travel=  [list(map(int,list(sys.stdin.readline().split()))) for i in range(N)]

x_now = 0
y_now = 0
time_now = 0

ans = 'Yes'

for i in range(N):
    time_next = list_travel[i][0]
    x_next = list_travel[i][1]
    y_next = list_travel[i][2]
    #time_next, x_next, y_next = i for i in range(list_num[i])
    dis_delta = abs(x_next - x_now) + abs(y_next - y_now)
    time_delta = time_next - time_now
    if(dis_delta <= time_delta
    and (dis_delta - time_delta)%2 == 0):
        x_now = x_next
        y_now = y_next
        time_now = time_next
    else:
        ans = 'No'

print(ans)

Measured memory_bytes: 29380
s = input()

c_idx = len(s)
f_idx = -1
for i in range(len(s)):
    if s[i] == 'C':
        c_idx = min(c_idx, i)
    if s[i] == 'F':
        f_idx = max(f_idx, i)
print('Yes' if c_idx < f_idx else 'No')


Measured memory_bytes: 9108
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
long double pi = 2 * acos(0.0);
const ll mod = 1e9 + 7;

void solve() {
    ll sum = 0;
    char x;
    while(x = getchar()) {
        if(x == '\n') break;
        sum += x - '0';
        sum %= 9;
    }
    if(sum) cout << "No\n";
    else cout << "Yes\n";
}   

int main() {
    ios_base :: sync_with_stdio(false); 
    cin.tie(nullptr);   
    ll t = 1;
    //cin >> t;
    while(t--) {
        solve();
    }
    return 0;
}

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

int main() {
	int n; cin >> n;
	vector<vector<int>> f(n, vector<int>(10, 0));
	rep(i, 0, n) {
		rep(j, 0, 10) {
			cin >> f[i][j];
		}
	}
	vector<vector<ll>> p(n, vector<ll>(11, 0));
	rep(i, 0, n) {
		rep(j, 0, 11) {
			cin >> p[i][j];
		}
	}

	ll ans = -1e7 * 100;
	int num = pow(2, 10);
	rep(i, 1, num) {
		ll P = 0;
		bitset<10> open(i);
		rep(j, 0, n) {
			int c = 0;
			rep(k, 0, 10) {
				if (open[k] && f[j][k]) c++;
			}
			P += p[j][c];
		}
		ans = max(ans, P);
	}

	cout << ans << endl;

	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cstring>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
#include<map> 
#define INF 0x3f3f3f3f
#define int long long 
using namespace std;
typedef long long LL;
typedef unsigned long long ULL;
const int maxn=2e5+6;
const int mod=1e9+7;
const double pi=acos(-1.0);
int n,k;
int a[maxn];
int vis[maxn];
int read(){        
    int s = 0, f = 1;        
    char ch = getchar();        
    while(!isdigit(ch)) {        
        if(ch == '-') f = -1;        
        ch = getchar();        
    }        
    while(isdigit(ch)) {        
        s = s * 10 + ch - '0';        
        ch = getchar();        
    }        
    return s * f;        
}        
void write(int x){        
    if(x < 0) {        
        putchar('-');        
        x = -x;        
    }        
    if(x > 9)        
        write(x/10);        
    putchar(x % 10 + '0');        
    return;        
}   
vector<int >adj[maxn];
int be,ed;
void dfs(int u){
	adj[0].push_back(u);
	for(int i=0;i<adj[u].size();i++){
		int v=adj[u][i];
		if(vis[v]){
			be=v;
			ed=u;
			return ;
		}  
		vis[v]=1;
		dfs(v);
	}
}
signed main(){
	cin>>n>>k;
	k++;
	for(int i=1;i<=n;i++){
		int x;
		cin>>x;
		adj[i].push_back(x);
	}
	vis[1]=1;
	dfs(1);
	int cnt=INF;
	adj[1].clear();
	//cout<<be<<" "<<ed<<endl;
	for(int i=0;i<adj[0].size();i++){
		if(adj[0][i]==be)
			cnt=i;
		if(i>=cnt) adj[1].push_back(adj[0][i]);
	}
	if(k<=cnt){
		cout<<adj[0][k-1]<<endl;
	}
	else{
		k-=cnt;
		cout<<adj[1][(k-1)%adj[1].size()]<<endl;
	}
	return 0;
}

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

int main()
{
  int n;
  cin >> n;
  vector<long double> v(n);
  for(int i = 0;i<n;i++)
    cin >> v[i];
  vector<vector<long double> > dp(n+1,vector<long double>(n+1));
  dp[0][0] = 1;
  for(int i = 1;i<=n;i++)
  {
    for(int j = 0;j<=i;j++)
    {
        if(j == 0)
            dp[i][j] = dp[i-1][j] * (1 - v[i-1]);
        else
            dp[i][j] = dp[i-1][j-1] * v[i-1] + dp[i-1][j] * (1 - v[i-1]) ;
    }
  }
  
  long double ans = 0;
  
  for(int i = (n+1)/2;i<= n;i++)
    ans += dp[n][i];
    
  cout << setprecision(10) << ans << endl;
  
  return 0; 
}

Measured memory_bytes: 144264
#include <stdio.h>

int main(void)
{
  int N,result=0;
  scanf("%d",&N);
  char ch[N];
  if (N%2==1) result = 1;
  else
  {
    scanf("%s",ch);

    for (int c = 0; c < (N/2); c++)
    {
      if (ch[c]!=ch[c+N/2])
      {
        result=1;
        break;
      }
    }
  }
  if (result==1)	//間違い
  {
    printf("No");
  }
  else
  {
    printf("Yes");
  }
  return 0;
}


Measured memory_bytes: 128
from sys import stdin

s = stdin.readline().rstrip()

ans = 0
cnt = 0
i = 0
while i < len(s): 
    if s[i] == 'A':
        cnt += 1
    elif i < len(s)-1 and s[i] == 'B' and s[i+1] == 'C':
        ans += cnt
        i += 1
    else:
        cnt =0
    i += 1

print(ans)


Measured memory_bytes: 40304
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <stack>
#include <functional>

#ifdef LOCAL
    #define eprintf(...) fprintf(stderr, __VA_ARGS__)
#else
    #define eprintf(...) 42
#endif

#define rep_(i, a_, b_, a, b, ...) for (int i = (a), i##_len = (b); i < i##_len; ++i)
#define rep(i, ...) rep_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define reprev_(i, a_, b_, a, b, ...) for (int i = (b-1), i##_min = (a); i >= i##_min; --i)
#define reprev(i, ...) reprev_(i, __VA_ARGS__, __VA_ARGS__, 0, __VA_ARGS__)
#define all(x) (x).begin(), (x).end()
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return 1; } return 0; }
template <class T> bool chmin(T &a, const T &b) { if (b < a) { a = b; return 1; } return 0; }
template <class T> T gcd(T a, T b) { return b ? gcd(b, a % b) : a; }
using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair <int,int> P;
typedef long double ld;

struct UnionFind {
    vector< int > data;
    UnionFind(int sz) {
        data.assign(sz, -1);
    }
    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if(x == y) return (false);
        if(data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }
    int find(int k) {
        if(data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }
    int size(int k) {
        return (-data[find(k)]);
    }
};

vector<vector<P> > graph;
vector<bool> used;
vector<ll> pl;
vector<vector<bool> > used_edge;

bool rec (int k) {
    bool ret = true;
    used[k] = true;
    rep (i, graph[k].size()) {
        if (!used_edge[k][i]) {
            int a, b; tie(a, b) = graph[k][i];
            if (used[a] && b + pl[k] != pl[a]) {
                eprintf("%d %d %d %d %d\n", b, k, pl[k], a, pl[a]);
                return false;
            }
            pl[a] = b + pl[k];
            used_edge[k][i] = true;
            if (!used[a]) {
                ret &= rec(a);
                if (!ret) return false;
            }
        }
    }
    return true;
}
int main (void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n, m; cin >> n >> m;
    graph.resize(n);
    rep (_, m) {
        int l, r, d; cin >> l >> r >> d; l--; r--;
        graph[l].emplace_back(r, d);
        graph[r].emplace_back(l, -d);
    }
    used.resize(n);
    pl.resize(n);
    used_edge.resize(n);
    rep (i, n) used_edge[i].resize(graph[i].size());
    bool ans = true;
    rep (i, n) {
        if (!used[i]) ans &= rec(i);
    }
    rep (i, n) eprintf("%d ", pl[i]); eprintf("\n");
    cout << (ans ? "Yes\n" : "No\n");
    return 0;
}

Measured memory_bytes: 21120
holiday = $stdin.gets.to_i
japanesePage = $stdin.gets.to_i
mathPage = $stdin.gets.to_i
japanesePagePerDay = $stdin.gets.to_i
mathPagePerDay = $stdin.gets.to_i

puts holiday - [(japanesePage.to_f / japanesePagePerDay.to_f).ceil, (mathPage.to_f / mathPagePerDay.to_f).ceil].max

Measured memory_bytes: 6088
#include<iostream>

using namespace std;

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

int n;
ll a[100000];

int main(){
	cin >> n;
	REP(i, n){
		cin >> a[i];
	}

	int maxinc = 1;
	int corinc = 1;
	for(int i=1; i<n; i++){
		if(a[i-1] < a[i]){
			corinc +=1;
			maxinc = max(corinc, maxinc);
		} else if (a[i-1]==a[i]) {
			continue;
		} else {
			corinc = 1;
		}
	}

	
	int maxdec = 1;
	int cordec = 1;
	for(int i=1; i<n; i++){
		if(a[i-1] > a[i]){
			cordec +=1;
			maxdec = max(cordec, maxdec);
		} else if (a[i-1]==a[i]) {
			continue;
		} else {
			cordec = 1;
		}
	}

	cout << max(maxdec, maxinc) << endl;
}

Measured memory_bytes: 3820
#include <bits/stdc++.h>
using namespace std;
int main (){
	string s;
	cin>>s;
	bool ans = false;
	for(int i=0;i<s.length()-1;i++){
		if(s[i] == 'A' && s[i+1] == 'C') ans = true;
	}
	if(ans) cout<<"Yes"<<endl;
	else cout<<"No"<<endl;
	return 0;
}

Measured memory_bytes: 256
s=input()
t="keyence"

if t in s:
  if s.find(t)==0 or s.find(t)==len(s)-7:
    print("YES")
  else:
    print("NO")
else:
  for i in range(1,7):
    a,b=t[:i],t[i:]
    if a in s and b in s:
      if s.find(a)==0 and s.rfind(b)==len(s)-len(b):
        print("YES")
        break
  else:
    print("NO")

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



// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    int N;cin >> N;
    vector<int> v;
    for(int i = 0;i < N;i++){
        int b;cin >> b;
        if(b % 2 == 0 && !(b % 3 == 0 || b % 5 == 0)){
            cout<<"DENIED"<<endl;
            return 0;
        }
    }
    cout<<"APPROVED"<<endl;
}


Measured memory_bytes: 256
import heapq
X,Y,Z,K=map(int,input().split())
A=list(map(int,input().split()))
B=list(map(int,input().split()))
C=list(map(int,input().split()))
A.sort(reverse=True)
B.sort(reverse=True)
C.sort(reverse=True)
Q=[[-A[0]-B[0]-C[0],0,0,0]]
heapq.heapify(Q)
ans=[]
ijk={(0,0,0)}
while len(ans)<K:
  abc,i,j,k=heapq.heappop(Q)
  if i+1<X and  not (i+1,j,k) in ijk:
    ijk.add((i+1,j,k))
    heapq.heappush(Q,[-A[i+1]-B[j]-C[k],i+1,j,k])
  if j+1<Y and  not (i,j+1,k) in ijk:
    ijk.add((i,j+1,k))
    heapq.heappush(Q,[-A[i]-B[j+1]-C[k],i,j+1,k])
  if k+1<Z and  not (i,j,k+1) in ijk:
    ijk.add((i,j,k+1))
    heapq.heappush(Q,[-A[i]-B[j]-C[k+1],i,j,k+1])
  ans.append(-abc)
for i in ans:
  print(i)

Measured memory_bytes: 5232
enc={' '=>'101','\''=>'000000',','=>'000011','-'=>'10010001','.'=>'010001','?'=>'000001',
'A'=>'100101','B'=>'10011010','C'=>'0101','D'=>'0001','E'=>'110','F'=>'01001','G'=>'10011011',
'H'=>'010000','I'=>'0111','J'=>'10011000','K'=>'0110','L'=>'00100','M'=>'10011001','N'=>'10011110',
'O'=>'00101','P'=>'111','Q'=>'10011111','R'=>'1000','S'=>'00110','T'=>'00111','U'=>'10011100',
'V'=>'10011101','W'=>'000010','X'=>'10010010','Y'=>'10010011','Z'=>'10010000'}

dec={'00000'=>'A','00001'=>'B','00010'=>'C','00011'=>'D','00100'=>'E','00101'=>'F','00110'=>'G',
'00111'=>'H','01000'=>'I','01001'=>'J','01010'=>'K','01011'=>'L','01100'=>'M','01101'=>'N',
'01110'=>'O','01111'=>'P','10000'=>'Q','10001'=>'R','10010'=>'S','10011'=>'T','10100'=>'U',
'10101'=>'V','10110'=>'W','10111'=>'X','11000'=>'Y','11001'=>'Z','11010'=>' ','11011'=>'.',
'11100'=>',','11101'=>'-','11110'=>'\'','11111'=>'?'}

while gets
  input=$_.chomp
  le,ld="",""
  input.each_char do |c|
    le+=enc[c]
  end
  while !le.empty?
    ld+=dec[format("%05s",le.slice!(0,5).reverse).reverse.gsub(" ","0")]
  end
  puts ld
end

Measured memory_bytes: 9244
#include <bits/stdc++.h>
using namespace std;
#define P 1000000007
long long ans,sum,f[1000005],g[1000005];int n;
int main()
{
    scanf("%d",&n);f[1]=1;
    for(int i=1;i<=n;i++) (f[i]+=i>=3?g[i-3]:0)%=P,(f[i]+=f[i-1])%=P,(g[i]=g[i-1]+f[i])%=P;
    for(int i=1;i<n;i++) (ans+=1ll*f[i]*(n-1)%P*(n-1)%P)%P;
    for(int i=1;i<n-1;i++) (ans+=1ll*f[i]*(i+1)%P)%P;
    (ans+=1ll*f[n]*n%P)%=P;(ans+=1ll*f[n-1]*(n-1)%P)%=P;printf("%d\n",ans);
}

Measured memory_bytes: 15872
#include <iostream>
#include<cmath>

using namespace std;

int N, W, w[100+5], v[100+5], buffv = 0, vsum = 0;
long long DP[100+5][100000+5]; //DP[N][V]

void solve(){
    //配列の初期化
    for(int i = 0; i <= N; i++){
        for(int j = 0; j <= vsum; j++ ){
            if(j == 0) DP[i][j] = 0;//v=0はW=0で得る
            else DP[i][j] = 1000000000+5;
        }
    }

    for(int i = 1; i <= N; i++){
        for(int j = 1; j <= vsum; j++ ){
            if(j - v[i] >= 0 && DP[i-1][j-v[i]] + w[i] <= W){
                DP[i][j] = min(DP[i-1][j], DP[i-1][j-v[i]] + w[i]);//書き込み
                buffv = max(buffv, j);
            }
            else DP[i][j] = DP[i-1][j];
        }
    }

    //テーブルの表示
    // cout << "Ltable:" << endl;
    // for(int row=0; row <= N; ++row){
    // for(int col = 0; col <= vsum; ++col){
    //     cout << DP[row][col] << " ";
    // }
    // cout << endl;
    // }

    cout << buffv << endl;
}

int main(){
    cin >> N >> W;
    for(int i = 1; i <= N; i++){
        cin >> w[i] >> v[i];
        vsum += v[i];
    } 

    solve();
} 

Measured memory_bytes: 80128
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define int long long
typedef long long ll;
#define fi first
#define se second
#define pii pair<int,int>
#define endl '\n'
#define fr(i, a, b) for(int i = a; i <= b; i++)
#define sz(s) (int)s.size()
#define y1 fdfbvfds
typedef long double f80;
#define all(x) x.begin(), x.end()
typedef long double f80;
 
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
ll rand(ll l,ll r){
    uniform_int_distribution<ll> uid(l, r);
    return uid(rng);
}
 
const int mod = 998244353;
int pwr(int a,int b) {
    int ans = 1;
    while(b) {
        if(b & 1) {
            ans = (ans * 1LL * a) % mod;
        }
        a = (a * 1LL * a) % mod;
        b >>= 1;
    }
    return ans;
}

const int N = 2e5 + 5;
const int NN = 1e6 + 5;
ll cnt[NN], cnt2[NN];
int mu[NN];
bool pr[NN];

int inv[NN];
int a[N];
 
signed main()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    fr(i, 1, NN - 1) {
        inv[i] = pwr(i, mod - 2);
    }
    int n;
    cin >> n;
    fr(i, 1, n) {
        cin >> a[i];
        cnt[a[i]] += a[i];
        if(cnt[a[i]] >= mod) cnt[a[i]] -= mod;
        cnt2[a[i]] += (a[i] * a[i]) % mod;
        if(cnt2[a[i]] >= mod) cnt2[a[i]] -= mod;
    }
    fr(i, 1, NN - 1) {
        for(int j = 2 * i; j < NN; j += i) {
            cnt[i] += cnt[j];
            cnt2[i] += cnt2[j];
            if(cnt[i] >= mod) cnt[i] -= mod;
            if(cnt2[i] >= mod) cnt2[i] -= mod;
        }
        cnt[i] = (cnt[i] * 1LL * cnt[i] - cnt2[i] + mod) % mod;
        cnt[i] = (cnt[i] * inv[2]) % mod;
    }
    fill(mu + 1, mu + NN, 1);
    fr(i, 2, NN - 1) {
        if(!pr[i]) {
            for(int j = i; j < NN; j += i) {
                mu[j] *= -1;
                pr[j] = 1;
            }
            if(i * 1LL * i < NN) {
                for(int j = i * i; j < NN; j += i * i) {
                    mu[j] = 0;
                }
            }
        }
    }
    int ans = 0;
    fr(d, 1, NN - 1) {
        if(!mu[d]) continue;
        for(int g = 1; g * d < NN; g++) {
            int cur = mu[d];
            if(cur == -1) cur += mod;
            cur = (cur * 1LL * inv[g]) % mod;
            cur = (cur * 1LL * cnt[g * d]) % mod;
            ans += cur;
            if(ans >= mod) ans -= mod;
        }
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 34048
#include <iostream>
#include <utility>
#include <vector>
#include <algorithm>
using namespace std;

typedef pair<int,int> PII;

int main(void){
  int n, ans, now;
  vector<PII> v;
  
  cin >> n;
  for (int i=0; i<n; i++){
    int s,t;
    cin >> s >> t;
    v.push_back(make_pair(t,s));
  }
  sort(v.begin(), v.end());
  ans = 0;
  now = -1;
  for (int i=0; i<n; i++){
    if (v[i].second > now){
      ans++;
      now = v[i].first;
    }
  }
  cout << ans << endl;
  return 0;
}



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

int main()
{
	int N, W;
	scanf("%d%d", &N, &W);
	std::vector<long long> value_max(W + 1, -1);
	value_max[0] = 0;
	for (int i{}; i < N; i++)
	{
		int w;
		long long v;
		scanf("%d%lld", &w, &v);
		for (int j{W - w}; j >= 0; j--)
		{
			if (value_max[j] < 0) continue;
			value_max[j + w] = std::max(value_max[j + w], value_max[j] + v);
		}
	}
	long long max{};
	for (int i{}; i <= W; i++)
		max = std::max(max, value_max[i]);
	printf("%lld\n", max);

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
using namespace std;
int main(void){
    int n; cin >> n;
    for(int i=1;i<10;i++){
        for(int j=1;j<10;j++){
            if(n==i*j){
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define REP(i,n) for (int i=0; i<(n); ++i)
#define REPR(i,n,m) for (int i=(n); i>=(m); --i)
using namespace std;
using LL = long long;
using LD = long double;
using PLL = pair<long long, long long>;
using PLD = pair<long double, long double>;
using VLL = vector<long long>;
using VLD = vector<long double>;
using VPLL = vector<PLL>;
using VPLD = vector<PLD>;

const int INF = numeric_limits<int>::max();
const unsigned long long int ULLINF = numeric_limits<unsigned long long int>::max();

int main(){
    
    int dx[4] = {1, 0, -1, 0};
    int dy[4] = {0, 1, 0, -1};

	int h, w;
    cin >> h >> w;
    vector<string> v(h);
    for (int i=0; i<h; i++) cin >> v[i];

    // 多点スタート
    vector<vector<int>> dist(h, vector<int>(w, -1));
    using pint = pair<int, int>;
    queue<pint> que;
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            if (v[i][j]=='#') {
                dist[i][j] = 0;
                que.push(pint(i,j));
            }
        }
    }

    // bfs
    while (!que.empty()) {
        auto cur = que.front();
        que.pop();
        for (int dir=0; dir<4; dir++) {
            int nx = cur.first + dx[dir];
            int ny = cur.second + dy[dir];
            if (nx < 0 || nx >=h || ny < 0 || ny >= w) continue;
            if (dist[nx][ny] == -1) {
                dist[nx][ny] = dist[cur.first][cur.second] + 1;
                que.push(pint(nx,ny));
            }
        }
    }

    int res = 0;
    for (int i=0; i<h; i++) {
        for (int j=0; j<w; j++) {
            res = max(res, dist[i][j]);
        }
    }

    cout << res << endl;


	return 0;
}


Measured memory_bytes: 17016
#!/usr/bin/env python
"""<https://github.com/cheran-senthil/PyRival>"""
from __future__ import division, print_function

import collections
import os
import sys
from io import BytesIO, IOBase

if sys.version_info[0] < 3:
    from __builtin__ import xrange as range
    from future_builtins import ascii, filter, hex, map, oct, zip
else:
    _str = str
    str = lambda x=b"": x if type(x) is bytes else _str(x).encode()


def main():
    N, Q = map(int, input().split())
    updates = []
    for i in range(N):
        S, T, X = map(int, input().split())
        updates.append((S - X, 1, X))
        updates.append((T - X, -1, X))

    active = []
    to_delete = collections.defaultdict(int)
    import heapq
    updates.sort(reverse=True)
    for _ in range(Q):
        x = int(input())
        while updates and updates[-1][0] <= x:
            coord, tp, val = updates.pop()

            if tp == -1:
                to_delete[val] += 1
            else:
                heapq.heappush(active, val)

            while active and to_delete[active[0]] > 0:
                to_delete[active[0]] -= 1
                heapq.heappop(active)
        print(active[0] if active else -1)


# region fastio

BUFSIZE = 8192


class FastIO(IOBase):
    newlines = 0

    def __init__(self, file):
        self._buffer = BytesIO()
        self._fd = file.fileno()
        self._writable = "x" in file.mode or "r" not in file.mode
        self.write = self._buffer.write if self._writable else None

    def read(self):
        if self._buffer.tell():
            return self._buffer.read()
        return os.read(self._fd, os.fstat(self._fd).st_size)

    def readline(self):
        while self.newlines == 0:
            b = os.read(self._fd, max(os.fstat(self._fd).st_size, BUFSIZE))
            self.newlines = b.count(b"\n") + (not b)
            ptr = self._buffer.tell()
            self._buffer.seek(0, 2), self._buffer.write(b), self._buffer.seek(ptr)
        self.newlines -= 1
        return self._buffer.readline()

    def flush(self):
        if self._writable:
            os.write(self._fd, self._buffer.getvalue())
            self._buffer.truncate(0), self._buffer.seek(0)


def print(*args, **kwargs):
    """Prints the values to a stream, or to sys.stdout by default."""
    sep, file = kwargs.pop("sep", b" "), kwargs.pop("file", sys.stdout)
    at_start = True
    for x in args:
        if not at_start:
            file.write(sep)
        file.write(str(x))
        at_start = False
    file.write(kwargs.pop("end", b"\n"))
    if kwargs.pop("flush", False):
        file.flush()


sys.stdin, sys.stdout = FastIO(sys.stdin), FastIO(sys.stdout)
input = lambda: sys.stdin.readline().rstrip(b"\r\n")

# endregion

if __name__ == "__main__":
    main()


Measured memory_bytes: 132944
#include<algorithm>
#include<iostream>
#include<vector>
#include<string>
#include<queue>
#include<stack>
#include<cmath>
#include<list>
#include<set>
#include<map>

using namespace std;
long long MOD = 1000000007LL;
const double PI = 3.14159265358979323846;
#undef INT_MIN
#undef INT_MAX
#define INT_MIN -2147483648
#define INT_MAX 2147483647
#define endl "\n"

template<class T>
map<T, int> prime_factorization(T n) {
	map<T, int> ret;

	for (long long i = 2; i * i <= n; ++i) {
		while (n % i == 0) {
			ret[i]++;
			n /= i;
		}
	}

	if (n != 1)ret[n] = 1;
	return ret;
}


int main() {
	int N;
	cin >> N;

	map<long long, long long> vec;
	for (int i = 0; i < N; ++i) {
		long long a;
		cin >> a;

		vec[a] = 1;
	}
	

	map<long long, int> mp;

	for (auto x : vec) {
		if (N == 1 || 5e17 < x.first) {
			cout << x.first << endl;
			return 0;
		}
		map<long long, int> mp2;
		
		mp2 = prime_factorization(x.first);
		for (auto y : mp2) {
			mp[y.first] = max(mp[y.first], y.second);
		}
	}

	long long ans = 1;
	for (auto x : mp) {
		long long y = x.second;
		long long yP = 1;
		for (int i = 0; i < x.second; ++i) yP *= x.first;
		ans = ans * yP;
	}

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


Measured memory_bytes: 3608
import sys
input = sys.stdin.readline


def main():
    n = int(input().strip())
    A = [int(i) for i in input().strip().split()]
    diff = [0] * n # 0-indexed table
    prev = 0
    _sum = 0
    for idx, a in enumerate(A):
        _sum += abs(prev - a)
        prev = a
        if idx == 0:
            diff[idx] = abs(0 - A[1]) - (abs(a-0) + abs(a - A[1]))
        elif idx < n - 1:
            diff[idx] = abs(A[idx - 1] - A[idx + 1]) - (abs(a - A[idx - 1]) + abs(a - A[idx + 1]))
        elif idx == n - 1:
            diff[idx] = abs(A[idx - 1] - 0) - (abs(a - A[idx - 1]) + abs(a - 0))
    _sum += abs(a)
    
    for i in range(n):
        print(_sum + diff[i])

if __name__ == "__main__":
    main()

Measured memory_bytes: 84824
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define il inline
#define outy printf("Yes\n")
#define outn printf("No\n")
#define outf printf("First\n")
#define outs printf("Second\n")
#define FOR(a,b,c) for(int a=b;a<=c;a++)
#define FORD(a,b,c) for(int a=b;a>=c;a--)
#define FORL(a,b) for(int a=head[b];a;a=nxt[a])
#define in(a)  a=read()
#define in2(a,b)  a=read(),b=read()
#define in3(a,b,c)  a=read(),b=read(),c=read()
#define in4(a,b,c,d)  a=read(),b=read(),c=read(),d=read()
#define inl(a)  a=readl()
#define inl2(a,b)  a=readl(),b=readl()
#define inl3(a,b,c)  a=readl(),b=readl(),c=readl()
#define inl4(a,b,c,d)  a=readl(),b=readl(),c=readl(),d=readl()
#define out(a) printf("%d\n",a)
#define out2(a,b) printf("%d %d\n",a,b)
#define out3(a,b,c) printf("%d %d %d\n",a,b,c)
#define out4(a,b,c,d) printf("%d %d %d %d\n",a,b,c,d)
#define outl(a) printf("%lld\n",a)
#define outl2(a,b) printf("%lld %lld\n",a,b)
#define outl3(a,b,c) printf("%lld %lld %lld\n",a,b,c)
#define outl4(a,b,c,d) printf("%lld %lld %lld %lld\n",a,b,c,d)
#define clr(x,y) memset(x,y,sizeof(x))
inline int read(){
    char c;int s=0,t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
inline ll readl(){
    char c;ll s=0;int t=1;
    while(!isdigit(c=getchar()))if(c=='-')t=-1;
    do{s=s*10+c-'0';}while(isdigit(c=getchar()));
    return s*t;
}
/*------------------------------------------------------------*/
#define mod 1000000007
#define maxn 100010
/*------------------------------------------------------------*/
int n,m;
int main(){
	int x,y,z;
	in3(x,y,z);
	FOR(i,0,maxn){
//		if(i>1){
			if(y*i+z*(i+1)>x){
				out(i-1);
				return 0;
			}
//		}
	}
			
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <cstring>
#include <fstream>
#include <cmath>
#include <iomanip>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <map>
#include <deque>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <list>
#include <unordered_map>
#include <bitset>
#include <sstream>

typedef  long long ll;
#define mop 1000000007
using namespace std;

multiset <ll> table;

int main() {
   
    ll n,m;
    cin >> n >> m;
    for (ll i=0;i<n;i++){
        ll tmp;
        cin >> tmp;
        table.insert(tmp);
    }
    for (ll i=0;i<m;i++){
        auto itr = table.end();
        itr--;
        ll newv = *itr / 2;
        table.erase(itr);
        table.insert(newv);
    }
    ll ans = 0;
    for (auto itr = table.begin(); itr != table.end();itr++){
        ans += *itr;
    }
    cout << ans << endl;
}

Measured memory_bytes: 4992
#define _CRT_SECURE_NO_WARNINGS
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<functional>
#include<iomanip>
#include<iostream>
#include<list>
#include<map>
#include<queue>
#include<set>
#include<stack>
#include<string>
#include<utility>
#include<vector>

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

using namespace std;

int main() {
	int N, a, cnt[3] = { 0 };
	cin >> N;
	REP(i, N) {
		cin >> a;
		if (a % 4 == 0) {
			cnt[0]++;
		}
		else if (a % 2 == 1) {
			cnt[1]++;
		}
		else {
			cnt[2]++;
		}
	}

	if (cnt[1] <= cnt[0]) {
		cout << "Yes" << endl;
	}
	else if (cnt[1] == cnt[0] + 1 && cnt[2] == 0) {
		cout << "Yes" << endl;
	}
	else {
		cout << "No" << endl;
	}


	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <cmath>
#include <vector>
#include <string>
#include <map>
#include <queue>
#include <set>
#include <stack>
using ll = long long;
using uint = unsigned int;
using graph = std::vector<std::vector<ll>>;
using wGraph = std::vector<std::vector<std::pair<ll,ll>>>;
#define rep(i,n) for (int i=0; i < int(n); i++)

using namespace std;
ll MOD7 = 1000000007;
ll MOD9 = 1000000009;
vector<ll> InputVec(ll N){
    vector<ll> A(N);
    for (int i = 0; i < N; ++i) {
        cin >> A[i];
    }
    return A;
}
void OutputVec(vector<ll> A){
    for (int i = 0; i < A.size(); ++i) {
        cout << A[i] << ",";
    }
    cout << endl;
}
vector<vector<ll>> InputVec2d(ll H,ll W){
    vector<vector<ll>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<ll>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        for (int xi = 0; xi < W; ++xi) {
            cin >> A[yi][xi];
        }
    }
    return A;
}
vector<vector<char>> InputVec2dStr(ll H,ll W){
    vector<vector<char>> A(H);
    for (int yi = 0; yi < H; ++yi) {
        A[yi] = vector<char>(W);
    }
    for (int yi = 0; yi < H; ++yi) {
        string S;
        cin >> S;
        for (int xi = 0; xi < W; ++xi) {
            A[yi][xi] = S[xi];
        }
    }
    return A;
}
void OutputVec2d(vector<vector<ll>> A){
    for (int yi = 0; yi < A.size(); ++yi) {
        for (int xi = 0; xi < A[yi].size(); ++xi) {
            cout << A[yi][xi] << ",";
        }
        cout << endl;
    }
}
graph InputGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
        G[b].push_back(a);
    }
    return G;
}
graph InputDGraph(ll N,ll M){
    graph G(N);
    for (int i = 0; i < M; ++i) {
        ll a,b;
        cin >> a >> b;
        a--;b--;
        G[a].push_back(b);
    }
    return G;
}
void OutputGraph(graph G){
    for (int i = 0; i < G.size(); ++i) {
        cout << i << ":";
        for (int j = 0; j < G[i].size(); ++j) {
            cout << G[i][j]<< ",";
        }
        cout << endl;
    }
}
void OutputAnswerBool(bool b,bool isUpperCase = false){
    if(b){
        if(isUpperCase){
            cout << "YES" << endl;
        }else{
            cout << "Yes" << endl;
        }
    }else{
        if(isUpperCase){
            cout << "NO" << endl;
        }else{
            cout << "No" << endl;
        }
    }
}

int main() {
    ll a,b;
    cin >> a >> b;
    if(a <= 0 && 0 <= b){
        cout << "Zero" << endl;
    }else if(0 < a){
        cout << "Positive" << endl;
    }else if(b < 0){
        if(abs(b - a) % 2 == 0){
            cout << "Negative" << endl;
        }else{
            cout << "Positive" << endl;
        }
    }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
constexpr long long MOD = 1000000007;
long long modpow(long long x,long long n,long long mod){
    long long res = 1;
    while(n > 0) {
        if(n & 1) (res *= x) %= mod;
        (x *= x) %= mod;
        n>>=1;
    }
    return res;
}

long long modinv(long long x, long long mod){
    return modpow(x, mod - 2, mod); }
int main(){
ll m,n;
cin >> m >> n;
cout << modpow(m, n, MOD) << endl;
}


Measured memory_bytes: 3120
#include <algorithm>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;
#define rep(i, n) for (int i = 0; i < (n); i++)

using namespace std;
using ll = long long int;
using P = pair<int, int>;
using edge = struct {
  int to;
  int cost;
};

int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
vector<ll> po(5);
int main() {
  int N = 0;
  cin >> N;
  rep(i, N) {
    string a;
    cin >> a;
    if (a[0] == 'M')
      po[0]++;
    else if (a[0] == 'A')
      po[1]++;
    else if (a[0] == 'R')
      po[2]++;
    else if (a[0] == 'C')
      po[3]++;
    else if (a[0] == 'H')
      po[4]++;
  }
  int count = 0;
  rep(i, 5) {
    if (po[i] != 0) {
      count++;
    }
  }
  ll ans = 0;
  rep(i, 5) {
    rep(j, 5) {
      rep(p, 5) {
        if (i != j && j != p && i != p) {
          ans += po[i] * po[j] * po[p];
        }
      }
    }
  }
  cout << ans / 6 << endl;

  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var x, a, b float64
	fmt.Scan(&x, &a, &b)

	result := "A"
	if math.Abs(x-b) < math.Abs(x-a) {
		result = "B"
	}
	fmt.Println(result)
}


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

const int T = 26;

int main()
{
    int D;
    cin >> D;
    vector<long> c(T);
    rep(i, T) cin >> c[i];
    vector<vector<long>> s(D);
    rep(i, D) {
        s[i] = vector<long>(T);
        rep(j, T) cin >> s[i][j];
    }
    vector<long> Inputs(D);
    rep(i, D) { int a; cin >> a; Inputs[i] = a - 1; }

    long ans = 0;
    vector<long> cc(T);
    rep(i, T) cc[i] = -1;
    rep(i, D) {
        ans += s[i][Inputs[i]];
        cc[Inputs[i]] = i;
        rep(j, T) {
            ans -= c[j] * (i - cc[j]);
        }
        cout << ans << endl;
    }


    return 0;
}

Measured memory_bytes: 3616
#include <bits/stdc++.h>
using namespace std;
///////////////////////////////////////////
const long long int INF = INT64_MAX;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;
using Vi = vector<long long int>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(int i=0;i<N;i++)
auto max(auto x,auto y){if(x>y){return x;}else{return y;}}
auto min(auto x,auto y){if(x>y){return y;}else{return x;}}
template<class T>bool chmax(T &former, const T &b) { if (former<=b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<=former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
typedef vector<vector<ll> > matrix;
///////////////////////////////////////////////////////////////////////////////////

struct union_find{
    vector<int> par;
    int par_siz;
    union_find(int n) : par(n){
        par_siz = n;
        for(ll i=0;i<n;i++)par[i]=-1; //init
    }
    int root(int x){
        if(par[x]<0)return x;
        else return par[x] = root(par[x]);
    }
    
    void unite(int p1,int p2){
        int pa1 = root(p1),pa2 = root(p2);
        if(pa1==pa2)return;
        if(par[pa1]>par[pa2]){ // |pa1| < |pa2|
            par[pa2] += par[pa1];
            par[pa1] = pa2;
        }else{ // |pa1| > |pa2|
            par[pa1] += par[pa2];
            par[pa2] = pa1;
        }
        par_siz--;
    }
    int size(int x){ return (-1)*par[root(x)]; }
    int par_size(){return par_siz;}
    bool same(int p1,int p2){ return root(p1) == root(p2); }
};

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,m;cin>>n>>m;
    union_find uf(n);
    int x,y,z;
    rep(i,m){
        cin>>x>>y>>z;
        uf.unite(x-1,y-1);
    }
    cout<<(uf.par_size())<<endl;
    return 0;
}

Measured memory_bytes: 640
from collections import defaultdict

N = int(input())
A = [int(i) for i in input().split()]

mod = 10 ** 9 + 7

def prime_factor(x) :
  ret = dict()
  if x % 2 == 0 :
    ret[2] = 0
    while x % 2 == 0 :
      x //= 2
      ret[2] += 1
          
  i = 3
  while i * i <= x :
    if x % i == 0 :
      ret[i] = 0
      
      while x % i == 0 :
        x //= i
        ret[i] += 1
    i += 2
      
  if x != 1 :
    ret[x] = 1
  
  return ret

pr = defaultdict(int)
for i in range(N) :
  for k, v in prime_factor(A[i]).items() :
    pr[k] = max(pr[k], v)
    
a = 1
for k, v in pr.items() :
  a *= pow(k, v, mod)
  a %= mod

ret = 0
for i in range(N) :
  ret += a * pow(A[i], mod - 2, mod)
  ret %= mod
print(ret)

Measured memory_bytes: 48988
import java.util.Scanner;

public class Main{
    static int dp[][];
    private static int memo(String a, String b, int i, int j){
        if(dp[i][j]!=-1){
            return dp[i][j];
        }
        if(j==b.length()){
            dp[i][j] = 0;
            return 0;
        }
        if(i == a.length()){
            dp[i][j] = 2000;
            return 2000;
        }
        if(a.charAt(i)==b.charAt(j)){
            dp[i][j] = Math.min(memo(a, b, i+1, 0), memo(a, b, i+1, j+1));
        }else{
            dp[i][j] = Math.min(memo(a, b, i+1, 0), 1 + memo(a, b, i+1, j+1));
        }
        return dp[i][j];
    }
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String a = sc.nextLine();
        String b = sc.nextLine();
        dp = new int[a.length()+1][b.length()+1];
        for(int i=0;i<=a.length();i++)
            for(int j=0;j<=b.length();j++)
                dp[i][j] = -1;
        System.out.println(memo(a, b, 0, 0));
        sc.close();
    }
}

Measured memory_bytes: 42472
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <cmath>

using namespace std;

int main()
{
	string S;
	cin >> S;

	bool flag = true;

	if (S[0] != 'A')
	{
		flag = false;
	}

	int cnt = 0;
	for (int i = 2; i < S.size() - 1; i++)
	{
		if (S[i] == 'C')
		{
			cnt++;
		}
	}
	if (cnt != 1)
	{
		flag = false;
	}

	for (int i = 1; i < S.size(); i++)
	{
		if (S[i] != 'C' && !('a' <= S[i] && S[i] <= 'z'))
		{
			flag = false;
			break;
		}
	}

	if (flag)
	{
		cout << "AC" << endl;
	}
	else
	{
		cout << "WA" << endl;
	}

	return 0;
}


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

int main()
{
    char w[101],count[26] = {0};
    scanf("%s",w);

    int len = strlen(w);
    int i;
    for (i = 0; i < len; i++)
    {
        count[w[i] - 'a']++;
    }
    
    for (i = 0; i < 26; i++)
    {
        if(count[i] % 2 == 1)break;
    }
    printf("%s",i != 26 ? "No" : "Yes");
}

Measured memory_bytes: 128
/*
** 树的先序遍历，中序遍历，后序遍历
*/

# include <cstdio>
# define MAX 30
# define NIL -1

struct Node {
    int parent, left, right;
} tree[MAX];

int n;

void createTree() {
    scanf("%d", &n);
    for (int i = 0; i < n; i++) {
        tree[i].parent = NIL;
    }

    int u, l, r;
    for (int i = 0; i < n; i++) {
        scanf("%d%d%d", &u, &l, &r);
        tree[u].left = l;
        tree[u].right = r;
        if (l != NIL) {
            tree[tree[u].left].parent = u;
        }
        if (r != NIL) {
            tree[tree[u].right].parent = u;
        }
    }
}

void Preorder(int u) {
    if (u == NIL)
        return;
    printf(" %d", u);
    Preorder(tree[u].left);
    Preorder(tree[u].right);
}

void Inorder(int u) {
    if (u == NIL)
        return;
    Inorder(tree[u].left);
    printf(" %d", u);
    Inorder(tree[u].right);
}

void Postorder(int u) {
    if (u == NIL)
        return;
    Postorder(tree[u].left);
    Postorder(tree[u].right);
    printf(" %d", u);
}

int getRoot() {
    for (int i = 0; i < n; i++) {
        if (tree[i].parent == NIL)
            return i;
    }
}

void printTree() {
    int root = getRoot();

    printf("Preorder\n");
    Preorder(root);
    printf("\n");

    printf("Inorder\n");
    Inorder(root);
    printf("\n");

    printf("Postorder\n");
    Postorder(root);
    printf("\n");
}

int main() {
    // freopen("infile", "r", stdin);
    // freopen("outfile", "w", stdout);

    createTree();
    printTree();

    return 0;
}


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

int main(){
 int x,n;  
  cin>>x>>n;
vector<int> data(n);
  for(int i=0;i<n;i++){
     cin >> data.at(i);
  }
  int b=x;
  int c=b;
  bool a=false;
  
 
    a=true;
     for(int i=0;i<n;i++){
       
        if(data.at(i)==b){
      a=false;
    }
}
      if(a==true){
      cout<<c<<endl;  
    }
  
    if(a==false){
      for(int j=0;j<100;j++){

  a=true;

    c=b-j;
      for(int i=0;i<n;i++){
    if(data.at(i)==c){
      a=false;
    }
      }
    
    
    
    if(a==true){
      cout<<c<<endl;
      break;
    }
        a=true;
        c=b+j;
          for(int i=0;i<n;i++){
    if(data.at(i)==c){
      a=false;
    }
    }
    
    
    
    if(a==true){
      cout<<c<<endl;
      break;
    }
          if(a==true){
            break;
          }
      }

  }
}

Measured memory_bytes: 3632
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner reader = new Scanner(System.in);
		int A = reader.nextInt();
		int B = reader.nextInt();
		int C = reader.nextInt();
		int ans = A + C;
		int AB = A + B;
		int BC = B + C;
		ans = Math.min(ans, AB);
		ans = Math.min(ans, BC);


		System.out.println(ans);
		reader.close();

	}
}





Measured memory_bytes: 21844
import sys

lines = sys.stdin.readlines()

cnt = 1
threshold = int(lines[0].strip())
if threshold == 0:
  print(0)
  sys.exit()

sentinel = 9999
for i in range(sentinel):
  new_cnt = cnt * 2
  if new_cnt > threshold:
    print(cnt)
    break
  else:
    cnt = new_cnt

Measured memory_bytes: 3060
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
import java.io.InputStreamReader;
import java.util.Arrays;
import java.util.HashMap;
import java.util.Map;
import java.util.Map.Entry;
import java.util.Scanner;
import java.util.StringTokenizer;


public class Main {
	
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		
		final int N = sc.nextInt();
		final long a = sc.nextInt();
		final long d = sc.nextInt();
		
		final int M = sc.nextInt();
		int[] xs = new int[M];
		int[] ys = new int[M];
		int[] zs = new int[M];
		
		for(int i = 0; i < M; i++){
			xs[i] = sc.nextInt();
			ys[i] = sc.nextInt() - 1;
			zs[i] = sc.nextInt() - 1;
		}
		
		final int K = sc.nextInt() - 1;
		int[] query_K = new int[M + 1];
		query_K[M] = K;
		
		for(int i = M - 1; i >= 0; i--){
			if(xs[i] == 0 && ys[i] <= query_K[i + 1] && query_K[i + 1] <= zs[i]){
				query_K[i] = (zs[i] - query_K[i + 1]) + ys[i];
			}else{
				query_K[i] = query_K[i + 1];
			}
		}
		
		long answer = a + d * query_K[0];
		for(int i = 0; i < M; i++){
			if(xs[i] == 0){ continue; }
			else if(xs[i] == 1 && ys[i] <= query_K[i] && query_K[i] <= zs[i]){
				answer += 1;
			}else if(xs[i] == 2 && ys[i] <= query_K[i] && query_K[i] <= zs[i]){
				answer /= 2;
			}
		}
		
		System.out.println(answer);
	}	
	
	public static class Scanner {
		private BufferedReader br;
		private StringTokenizer tok;
		
		public Scanner(InputStream is){
			br = new BufferedReader(new InputStreamReader(is));
		}
		
		private void getLine(){
			try{
				while(!hasNext()){
					tok = new StringTokenizer(br.readLine());
				}
			} catch (IOException e){
				
			}
		}
		
		private boolean hasNext(){
			return tok != null && tok.hasMoreTokens();
		}
		
		public String next(){
			getLine(); return tok.nextToken();
		}
		
		public int nextInt(){
			return Integer.parseInt(next());
		}
	}
}

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

using namespace std;

#define IoFast ios_base::sync_with_stdio(0);cin.tie(0);
#define ll long long int
#define float long double
#define foor(i, a, b) for ( int (i) = (a); (i)<(b); (i)++ )
#define foor2(i, a, b) for( int (i) = (a); (i)>(b); (i)-- )
#define foorl(i, a, b) for ( ll (i) = (a); (i)<(b); (i)++ )
#define foorl2(i, a, b) for( ll (i) = (a); (i)>(b); (i)-- )
#define mp make_pair
#define f1 first
#define f2 second
#define pb push_back
#define pii pair<int,int>
#define vpii vector <pii>
#define vi vector<int>
#define sz(a) (int) a.size( )
#define fillArr(n, a) foor(i, 0, n) cin >> a[i];
#define print(a) cout << #a << endl;
#define umax(a,b) a = max ( a, b )
#define umin(a,b) a = min ( a, b )
#define all(k) k.begin ( ), k.end( )
#define rall(k) k.rbegin ( ), k.rend( )
#define clean(k) memset( k, 0, sizeof(k) )
#define endl '\n'


int main(){
	IoFast;
	int n;
	string s2,s1;
	cin >> n ;
	cin >> s1 >> s2;
	int jk = INT_MIN;
	int ans = sz(s1) + sz(s2);
	foor(i,0,n){
		if (s1[i] == s2[0]){ 
			int kj = 0;
			foor (j,0,n){
				if (j + i < n && s1[j+i] == s2[j])
				 kj++;
				else
					break;
			}
			umax(jk,kj);
		}
			
	}
	umax(jk,0);
	cout << ans - jk << endl;
}



Measured memory_bytes: 256
n = int(input())
a_n = list(map(int, input().split()))
result1 = max(a_n)
min_delta = max(a_n)
result2 = max(a_n)
for num in a_n:
    if num == result1:
        pass
    elif abs(num-result1/2)<=min_delta:
        min_delta = abs(num-result1/2)
        result2 = num
print('{} {}'.format(result1, result2))

Measured memory_bytes: 14428
import numpy as np
N,W = map(int,input().split())
s=np.full(N*1000+1,W+1)
s[0]=0
for i in range(N):
  w,v =  map(int,input().split())
  s[v:]=np.minimum(s[v:],s[:-v]+w)
print(np.max(np.where(s<=W)))

Measured memory_bytes: 14920
// È¥°É£¡Æ¤¿¨Çð! °ÑAC´ø»ØÀ´£¡
//      ¤Ø¡¡¡¡¡¡¡¡¡¡£¯|
// ¡¡¡¡/£Ü7¡¡¡¡¡¡ ¡Ï£ß/
// ¡¡ /¡¡©¦¡¡¡¡ £¯¡¡£¯								AC		AC		AC		AC
//    ©¦¡¡Z £ß,£¼¡¡£¯¡¡¡¡ /`©c						AC		AC		AC		AC
//    ©¦¡¡¡¡¡¡¡¡¡¡©c¡¡¡¡ /¡¡¡¡¡µ					AC		AC		AC		AC
// ¡¡Y¡¡¡¡¡¡¡¡¡¡`¡¡ /¡¡¡¡/  /						AC		AC		AC		AC
// ¡¡Øé¡ñ¡¡.¡¡¡ñ¡¡¡¡¡´¡¡/¡¡/						AC		AC		AC		AC
// ¡¡()¡¡ ¤Ø¡¡¡¡¡¡¡¡|¡¡£Ü¡´							AC		AC		AC		AC
// ¡¡¡¡>- ._¡¡ ¥£¡¡ ©¦ £¯£¯							AC		AC		AC		AC
// ¡¡ / ¤Ø¡¡¡¡ /¡¡/£¼| £Ü£Ü							AC		AC		AC		AC
// ¡¡ ©c_/¡¡¡¡(_£¯¡¡ ©¦£¯£¯							AC		AC		AC		AC
// ¡¡¡¡ 7¡¡¡¡¡¡¡¡¡¡¡¡¡¡|£¯							AC		AC		AC		AC
// ¡¡¡¡ £¾¨Dr£þ£þ`-¨D£ß/							AC		AC		AC		AC
//**************************************Accepted*****************************************//

#include<bits/stdc++.h>

#define all(x) x.begin(),x.end()
#define pb push_back
#define mp make_pair
#define Unique(x) x.erase(unique(all(x)),x.end());

#define CIN_FILE "input.txt"
#define COUT_FILE "output.txt"

#define Pig (OO)

using namespace std;

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

const int Days[]={-1,31,28,31,30,31,30,31,31,30,31,30,31};

inline int read()
{
	#define gc getchar
	int ans=0;
	bool f=1;
	char ch=gc();
	
	while(!isdigit(ch))f^=ch=='-',ch=gc();
	
	while(isdigit(ch))ans=((ans<<2)+ans<<1)+(ch^48),ch=gc();
	
	return f?ans:-ans;
	
	#undef gc
}

typedef long long ll;

int n,m;
vector<int> v[610];
double DP[610];

#define c 1.00000000000000000000000000000000000000000000000000
#define z 0.00000000000000000000000000000000000000000000000000

int main(int argc, char const *argv[])
{
	ios::sync_with_stdio(false);
	
	cin>>n>>m;
	
	for(int i=0;i<m;i++)
	{
		int x,y;
		cin>>x>>y;
		
		v[--x].pb(--y);
	}
	
	double E=1000000007;
	
	for(int i=0;i<n-1;i++)
	{
		memset(DP,z,sizeof(DP));
		
		for(int j=n-2;j>=0;j--)
		{
			if(v[j].size()==1){DP[j]=DP[v[j][0]]+c;}
			else
			{
				double sum=z,maxv=z;
				
				for(int k=0;k<v[j].size();k++)sum+=DP[v[j][k]]*c,maxv=max(maxv,DP[v[j][k]]*c);
				
				DP[j]=c+(sum-maxv*(i==j))/(double)(v[j].size()-(i==j))*c;
			}
		}
		
		E=min(E,DP[0]*c);
	}
	
	cout<<fixed<<setprecision(50)<<E;
	
	//printf("Time used = %.12f",(double)(clock())/CLOCKS_PER_SEC);
	return 0;
}

/*  GOD BLESS  */


Measured memory_bytes: 1408
#include <iostream>
#include <vector>
#include <string>
#include <algorithm>
#include <queue>
#include <utility>
#include <climits>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;
typedef unsigned int ui;

typedef vector<ull> vull;
typedef vector<ll> vll;
typedef vector<ui> vui;
typedef vector<long> vl;
typedef vector<int> vi;

typedef pair<ull, ull> pull;
typedef pair<ll, ll> pll;
typedef pair<ui, ui> pui;
typedef pair<long, long> pl;
typedef pair<int, int> pi;

string S, T;

bool check(int index) {
    for (int i = 1; i < T.size(); ++i) if (S[i + index] != T[i] && S[i + index] != '?') return false;
    return true;
}

int main() {
    cin >> S >> T;

    int index = -1;
    for (int i = S.size() - T.size(); i >= 0; --i) {
        if ((S[i] == T[0] || S[i] == '?') && check(i)) {
            index = i;
            break;
        }
    }    

    if (index == -1) {
        cout << "UNRESTORABLE" << endl;
        return 0;

    } else {
        for (int i = 0; i < S.size(); ++i) {
            if (index <= i && i < index + T.size()) cout << T[i - index];
            else                                    cout << (S[i] == '?' ? 'a' : S[i]);
        }
        cout << endl;
    }

    return 0;
}


Measured memory_bytes: 256
from sys import stdin
n=int(stdin.readline().strip())
data=[stdin.readline().rstrip().split() for _ in range(3)]
data=[[int(i) for i in l]for l in data]

candy_sum = []
for i in range(n):
    candy_sum.append(sum(data[0][:i+1])+sum(data[1][i:]))
print(max(candy_sum))

Measured memory_bytes: 3064