akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
#define int long long
#define out(x) cerr << #x << " = " << x << "\n"
using namespace std;
// by piano
template<typename tp> inline void read(tp &x) {
	x = 0;
	char c = getchar();
	bool f = 0;
	for(; c < '0' || c > '9'; f |= (c == '-'), c = getchar());
	for(; c >= '0' && c <= '9'; x = (x << 3) + (x << 1) + c - '0', c = getchar());
	if(f) x = -x;
}
// define f[i][j] as the move of di...N = j

const int MaxN = 3400, N = 110;
const int mo = 1e9 + 7;
int f[N][MaxN + 10], n, k, c;
inline void U(int &x, int y, int i, int j) {
	for(x += y; x >= mo; x -= mo);
}

inline void Solve() {
	f[n][1] = (k >= n);
	f[n][0] = 1 + k - f[n][1];
	int Max = 1;
	for(int i = n - 1; i >= 1; i --) {
		for(int st = 0; st <= k; st ++) {
			for(int j = 0; j <= Max; j ++)  {
				if(st <= i)
					U(f[i][j + (st + j) / i], f[i + 1][j], i, (j + (st + j) / i));
				else U(f[i][j], f[i + 1][j], i, j);
			}
			
//	for(int i = 0; i <= 3; i ++) cout << f[1][i] << ' ';
//	putchar('\n');
		}
		for(int j = MaxN; ~j; j --) if(f[i][j]) {
			Max = j; break;
		}
	}
}

inline int pow_mod(int a, int k, int mo) {
	int ans = 1;
	for(; k; k >>= 1, a = (a * a) % mo) if(k & 1) ans = (ans * a) % mo;
	return ans;
}
 
main() {
	read(n), read(k);
	Solve();
//	puts("233");
//	for(int i = 0; i <= 3; i ++) cout << f[1][i] << ' ';
	for(int i = 0; i <= MaxN; i ++) U(c, i * f[1][i], 1, i);
//	cout << c << "\n";
    int a = pow_mod(k + 1, n - 1, mo);
    int sum = (k * (k + 1) / 2) % mo;
    (a *= sum) %= mo;
    (a *= n) %= mo;
//    cout << a << ' ' << sum << "\n";
    cout << (a - c + mo) % mo << "\n";
    
}

Measured memory_bytes: 768
a,b,c=map(int,input().split())

if a==b:
    if b==c:
        print(1)
    else :
        print(2)
elif b==c:
    if c==a:
        print(1)
    else :
        print(2)
elif c==a:
    if a==b:
        print(1)
    else :
        print(2)
else :
    print(3)

Measured memory_bytes: 3064
open Str

let read_list f =
  split (regexp " +") (read_line ()) |> List.map f

let print_array a = Array.to_list a |> List.map string_of_int |> String.concat " " |> print_endline

let bubble_sort a n =
  let rec oloop i c fin =
    if fin then c
    else let rec iloop j c' fin' =
           if j = i then oloop (i+1) c' fin'
           else if a.(j) < a.(j-1) then begin
               let v = a.(j) in
               a.(j) <- a.(j-1);
               a.(j-1) <- v;
               iloop (j-1) (c'+1) false
             end
           else iloop (j-1) c' fin' in
         iloop (n-1) c true
  in
  oloop 0 0 false
                        
let () =
  let n = read_int () in
  let ar = Array.of_list (read_list int_of_string) in
  let c = bubble_sort ar n in
  print_array ar; string_of_int c |> print_endline

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

int nlist[100010];

int main(){
  int N,L;
  cin>>N>>L;
  for(int i=0;i<N;i++){
    cin>>nlist[i];
  }
  int index = -1;
  for(int i=0;i<N-1;i++){
    int t = nlist[i+1] + nlist[i];
    if(t >= L){
      index = i;
      break;
    }
  }
  if(index == -1){
    cout<<"Impossible"<<endl;
  }else{
    cout<<"Possible"<<endl;
    for(int i=0;i<index;i++){
      cout<<i+1<<endl;
    }
    for(int i = N-1;i>=index+1;i--){
      cout<<i<<endl;
    }
  }
  return 0;
}


Measured memory_bytes: 1152
#include <iostream>
#include <stdio.h>
#include <string>
#include <cstdlib>
#include <cmath>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <queue>
#include <stack>
#include <climits>
#include <bitset>
#include <list>
#include <map>
#include <set>

using namespace std;

typedef unsigned long long ull;
typedef long long ll;

int main(){
	int n, k;
	cin >> n >> k;
	if(k==1) cout << 0 << endl;
	else cout << n-k << endl;
	return 0;
}

Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
#define cinf(n,x) for(int i=0;i<(n);i++)cin>>x[i];
#define ft first
#define sc second
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define all(v) (v).begin(),(v).end()
#define LB(a,x) lb(all(a),x)-a.begin()
#define UB(a,x) ub(all(a),x)-a.begin()
#define mod 1000000007
#define FS fixed<<setprecision(15)
using namespace std;
typedef long long ll;
const double pi=3.141592653589793;
template<class T> using V=vector<T>;
using Graph = vector<vector<int>>;
using P=pair<ll,ll>;
typedef unsigned long long ull;
typedef long double ldouble;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }

const ll INF=1e18;
//tokiomarine
int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    ll n,k;
    cin>>n>>k;
    V<ll> a(n);
    
    rep(i,n){
        cin>>a[i];
    }
    ll m=0;
    while(m<k){
        bool ok=1;
        V<ll> cnt(n+2,0);
        rep(i,n){
            cnt[min(n+1,a[i]+i+1+1)]--;
            cnt[max(0LL,i+1-a[i])]++;
        }
        for(ll i=1;i<=n;i++){
            cnt[i]+=cnt[i-1];
            a[i-1]=cnt[i];
            if(cnt[i]!=n) ok=0;
        }
        
        if(ok) break;
        m++;
    }
    rep(i,n) cout<<a[i]<<' ';
    cout<<endl;
}
//ペナルティ出しても焦らない　ACできると信じろ！！！
//どうしてもわからないときはサンプルで実験　何か見えてくるかも
//頭で考えてダメなら紙におこせ！！
/*
V,P(大文字)使用不可
乗算などの際にオーバーフローに注意せよ！
(適切にmodをとれ　にぶたんで途中で切り上げろ)
制約をよく読め！
{
    ・全探索できるなら全探索しろ
    ・異常な制約ならそこに注目
}
stringの計算量(扱い)注意
コーナー注意！(特に数値が小さいものについては要検証)
N行出力のときは'¥n'
グリッド上では行先が範囲内におさまるかif文で確認(RE注意)
if文ではちゃんと比較演算子==を使え('='でもエラー出ない)
配列(vector)の大きさが0か1以上かで場合分けせよ(RE注意)
(vector<int> a(m)でm==0というものはできない)
modはなるべく最後に取れ！
doubleを扱うときには(abs)ではなく'fabs'!!!
*/

Measured memory_bytes: 6312
// https://atcoder.jp/contests/abc174/tasks/abc174_c

#include "algorithm"
#include "bitset"
#include "cmath"
#include "functional"
#include "iomanip"
#include "iostream"
#include "map"
#include "numeric"
#include "queue"
#include "set"
#include "string"
#include "vector"
#define rep(i, to) for (ll i = 0; i < (to); ++i)
#define rep1(i, to) for (ll i = 1; i <= (to); ++i)
#define repf(i, from, to) for (ll i = from; i < (to); ++i)
#define repr(i, from) for (ll i = from - 1; i >= 0; --i)
#define all(vec) vec.begin(), vec.end()
#define unless(cond) if (!(cond))
#define fi first
#define se second
using namespace std;
typedef long long ll;
typedef long double ld;
template <typename T>
using V = vector<T>;
using VL = V<ll>;
using VVL = V<VL>;
template <typename T, typename U>
using P = pair<T, U>;
using PL = P<ll, ll>;
using VPL = V<PL>;

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

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

template <typename T>
inline ll len(V<T> arr) {
  return arr.size();
}

struct exit_exception : public std::exception {
  const char* what() const throw() { return "Exited"; }
};

template <typename T>
void drop(T res) {
  cout << res << endl;
  throw exit_exception();
}

const ll INF = 1e18;

void solve();

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

  try {
    solve();
  } catch (exit_exception& e) {
  }

  return 0;
}
#endif

void solve() {
  ll K;
  cin >> K;

  if (K == 1) drop(1);
  if (K == 7) drop(1);

  ll cur = 7 % K;
  ll res = 1;

  rep(i, 5e6) {
    res++;
    cur = 10 * cur + 7;
    if (cur % K == 0) drop(res);
    cur %= K;
  }

  drop(-1);
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define len(v) ll(v.size())
#define fi first
#define se second

template <class T>
void cout_vec(const vector<T> &vec){
  for(auto itr:vec) cout<<itr<<' ';
  cout<<'\n';
}

typedef pair<ll,ll> P;
const ll mod=1e9+7;

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll n,c,k;
    cin>>n>>c>>k;
    vector<ll> t(n);
    rep(i,n) cin>>t[i];
    sort(begin(t),end(t));
    ll ans=0;
    ll now=0;
    while(now<n){
      //cout<<now<<endl;
      ans++;
      ll ind=lower_bound(begin(t),end(t),t[now]+k)-begin(t);
      if(t[ind]>t[now]+k) ind--;
      if(ind-now>=c){
        now=now+c;
      }else{
        now=ind+1;
      }
    }
    cout<<ans<<endl;
}

Measured memory_bytes: 1024
#pragma GCC optimize ("Ofast")
#include<bits/stdc++.h>
#define pb push_back
#define __V vector
#define all(x) x.begin(), x.end()
#define oit ostream_iterator
#define mod 1000000007ll
using namespace std;
void doin() {
	cin.tie();
	cout.tie();
	ios::sync_with_stdio(0);
#ifndef ONLINE_JUDGE
//	freopen("input.txt", "r", stdin);
//	freopen("output.txt", "w", stdout);
#endif
}
template<typename X, typename Y>
istream& operator>>(istream& in, pair<X, Y> &a) {
	in >> a.first >> a.second;
	return in;
}
template<typename T>
void getv(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv(vector<T>& v, int n, Ns ... ns) {
	v.resize(n);
	for (auto& i : v)
		getv(i, ns...);
}
template<typename T>
void getv1(T& i) {
	cin >> i;
}
template<typename T, typename ... Ns>
void getv1(vector<T>& v, int n, Ns ... ns) {
	v.resize(n + 1);
	for (int i = 1; i <= n; i++)
		getv(v[i], ns...);
}
#ifdef _WIN32
#define getchar_unlocked() _getchar_nolock()
#define _CRT_DISABLE_PERFCRIT_LOCKS
#endif
inline void getch(char &x) {
	while (x = getchar_unlocked(), x < 33) {
		;
	}
}
inline void getstr(string &str) {
	str.clear();
	char cur;
	while (cur = getchar_unlocked(), cur < 33) {
		;
	}
	while (cur > 32) {
		str += cur;
		cur = getchar_unlocked();
	}
}
template<typename T> inline bool sc(T &num) {
	bool neg = 0;
	int c;
	num = 0;
	while (c = getchar_unlocked(), c < 33) {
		if (c == EOF)
			return false;
	}
	if (c == '-') {
		neg = 1;
		c = getchar_unlocked();
	}
	for (; c > 47; c = getchar_unlocked())
		num = num * 10 + c - 48;
	if (neg)
		num *= -1;
	return true;
}
typedef unsigned long long ull;
typedef long long ll;
typedef float ld;
typedef ll _I;
typedef pair<_I, _I> pi;
typedef pair<ld, ld> pd;
typedef map<_I, _I> mii;
typedef __V <_I> vi;
typedef __V <char> vc;
typedef __V <ld> vd;
typedef __V <vd> vvd;
typedef __V <pi> vpi;
typedef __V <__V<_I>> vvi;
typedef __V <__V<char>> vvc;
typedef __V <__V<pi>> vvpi;
using AntonTsypko = void;
using arsijo = AntonTsypko;
using god = arsijo;
uniform_real_distribution<double> double_dist(0, 1);
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());

int main() {
	doin();
	ll n, pm, c;
	vi v;
	cin >> n;
	getv1(v, n);
	for (auto& i : v)
		i &= 1;
	vi a(n + 1, 0), r;
	for (int i = n; i; i--) {
		int t = 0;
		for (int j = i; j <= n; j += i)
			t ^= a[j];
		if (t != v[i]) {
			a[i] = 1;
			r.pb(i);
		}
	}
	cout << r.size() << "\n";
	for (auto i : r)
		cout << i << " ";
	return 0;
}


Measured memory_bytes: 5108
#include <bits/stdc++.h>
#include <cstdlib> 
using namespace std;
 
int main() {
  int n;
  cin >> n;
  string str[100100];
  long long m,a,r,c,h;
  unsigned long long num;
  m =0;
  a =0;
  r =0;
  c =0;
  h =0;
  
   for (int i = 0; i < n; ++i) cin >> str[i];
  
   for (int i = 0; i < n; ++i){
     if(str[i].at(0) == 'M'){
         m = m + 1;
       }
     else if(str[i].at(0) == 'A'){
         a = a + 1;
       }
     else if(str[i].at(0) == 'R'){
         r = r + 1;
       }
     else if(str[i].at(0) == 'C'){
         c = c + 1;
       }
     else if(str[i].at(0) == 'H'){
         h = h + 1;
       }
   }
  
   num = m*a*r; 
   num = num + m*a*c; 
   num = num + m*a*h; 
   num = num + m*r*c; 
   num = num + m*r*h; 
   num = num + m*c*h; 
   num = num + a*r*c; 
   num = num + a*r*h; 
   num = num + a*c*h; 
   num = num + r*c*h;
  
  cout << num << endl;
}

Measured memory_bytes: 6144
# 冒泡排序
def bubbleSort(arr):
    for i in range(1, len(arr)):
        for j in range(0, len(arr)-i):
            if arr[j] > arr[j+1]:
                arr[j], arr[j + 1] = arr[j + 1], arr[j]
    return arr

def main():
    arr = [int(x) for x in input().split()]
    sort_arr = [str(x) for x in bubbleSort(arr)]
    str_arr = ' '.join(sort_arr)
    print(str_arr)

if __name__ == "__main__":
    main()


Measured memory_bytes: 5604
// Copyright lzt
#include<stdio.h>
#include<cstring>
#include<cstdlib>
#include<algorithm>
#include<vector>
#include<map>
#include<set>
#include<cmath>
#include<iostream>
#include<queue>
#include<string>
#include<ctime>
using namespace std;
typedef long long ll;
typedef std::pair<int, int> pii;
typedef long double ld;
typedef unsigned long long ull;
typedef std::pair<long long, long long> pll;
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define rep(i, j, k)  for (register int i = (int)(j); i <= (int)(k); i++)
#define rrep(i, j, k) for (register int i = (int)(j); i >= (int)(k); i--)
#define Debug(...) fprintf(stderr, __VA_ARGS__)

inline ll read() {
  ll x = 0, f = 1;
  char ch = getchar();
  while (ch < '0' || ch > '9') {
    if (ch == '-') f = -1;
    ch = getchar();
  }
  while (ch <= '9' && ch >= '0') {
    x = 10 * x + ch - '0';
    ch = getchar();
  }
  return x * f;
}

const int maxn = 100100;
int n, k;
int a[maxn], f[maxn];

void work() {
  n = read(), k = read();
  rep(i, 1, n) a[i] = read();
  rep(i, 2, n) {
    f[i] = 2e9;
    rrep(j, i - 1, i - k) {
      if (j < 1) break;
      f[i] = min(f[i], f[j] + abs(a[i] - a[j]));
    }
  }
  printf("%d\n", f[n]);
}

int main() {
  #ifdef LZT
    freopen("in", "r", stdin);
  #endif

  work();

  #ifdef LZT
    Debug("My Time: %.3lfms\n", (double)clock() / CLOCKS_PER_SEC);
  #endif
}


Measured memory_bytes: 1152
#!usr/bin/env python3
from collections import defaultdict
from collections import deque
from heapq import heappush, heappop
import sys
import math
import bisect
import random
def LI(): return list(map(int, sys.stdin.readline().split()))
def I(): return int(sys.stdin.readline())
def LS():return list(map(list, sys.stdin.readline().split()))
def S(): return list(sys.stdin.readline())[:-1]
def IR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = I()
    return l
def LIR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = LI()
    return l
def SR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = S()
    return l
def LSR(n):
    l = [None for i in range(n)]
    for i in range(n):l[i] = SR()
    return l
mod = 1000000007

#A
"""
n = S()
if n == n[::-1]:
    print("Yes")
else:
    print("No")
"""
#B
a,b,c,d = LI()
print(max(0,min(b,d)-max(c,a)))
#C
"""
def gcd(a,b):
    if a == 0:
        return b
    return gcd(b%a,a)
n = I()
a = IR(n)
l = a[0]
for i in range(1,n):
    g = gcd(l,a[i])
    l *= a[i]//g
print(l)
"""

#D
"""
n = I()
v = [[] for i in range(n)]
for i in range(n-1):
    a,b,c = LI()
    a -= 1
    b -= 1
    v[a].append([b,c])
    v[b].append([a,c])
Q,k = LI()
d = [-1 for i in range(n)]
d[k-1] = 0
q = deque()
q.append(k-1)
while q:
    x = q.pop()
    for y,c in v[x]:
        if d[y] == -1:
            d[y] = d[x]+c
            q.append(y)
for i in range(Q):
    x,y = LI()
    x -= 1
    y -= 1
    print(d[x]+d[y])
"""


#E

#F

#G

#H

#I

#J

#K

#L

#M

#N

#O

#P

#Q

#R

#S

#T


Measured memory_bytes: 39792
#include<bits/stdc++.h>
using namespace std;
int main(){
int n,a,b;
cin >> n >> a >> b;
int ans = 0;
for(int i = 1; i <= n; i++){
    int c = 0; int con = i;
    for(int j = 0; j < 5; j++){
        c += con % 10;
        con /= 10;
    }
        if(a <= c && c <= b)
        ans += i;
    
}
cout << ans << endl;
}

Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG//TLEの原因になるので注意！！！！！！！！！！！
#include<cmath>
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
vector<int> arr;
stack<int> st;
queue<int> qu;
queue<pair<int,int> > qu2;

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define rep2(i,n) for(int i=1; i<=(int)(n); i++)
#define mins(x,y) x=min(x,y)
#define maxs(x,y) x=max(x,y)
typedef set<int> set_t;
typedef set<string> set_g;
typedef complex<double> xy_t;
static const int NIL = -1;
static const int INF = 1000000007;
#define mp make_pair
#define sz(x) int(x.xise())
#define mod 1000000007
#define reps(i,s,n) for(int i = s; i < n; i++)
#define Rreps(i,n,e) for(int i = n - 1; i >= e; --i)
#define Rrep(i,n) Rreps(i,n,0)
deque<int> deq;
#define fi first
#define se second
//#define int long long
 
//cerrはコメントアウトしなくても通る//ただしTLEを引き起こすことがある

ll N,M,H,W,K,Q;
string S;
//const ll MOD = 998244353;
const ll MOD = (1e+9) + 7;
//const ll INF = 1LL << 60;
//typedef pair<ll,ll> P;
typedef pair<int, int> P;
bool chmx(int &a, int b) {
	if (b > a) {
		a = b;
		return true;
	}
	return false;
}

bool chmn(int &a, int b) {
	if (b < a) {
		a = b;
		return true;
	}
	return false;
}


int main(){
    int n;
    ll d,a;
    cin >> n >> d>> a;
    d=d*2;
    vector<pair<int,int>> X;
    rep(i,n){
        int x,h;
        cin >> x>>h;
        X.push_back(mp(x,h));
    }
    sort(X.begin(),X.end());
    ll ans=0;
    ll tot=0;//ダメージ量
    queue<pair<ll,ll>> q;
    rep(i,n){
        ll x,h;
        x=X[i].fi;
        h=X[i].se;
        while(q.size()&&q.front().fi<x){
            tot-=q.front().se;
            q.pop();
        }
        h-=tot;
        if(h>0){
            ll num = (h+a-1)/a;
            ans+=num;
            ll damage = num*a;
            tot+=damage;
            q.emplace(x+d,damage);
        }
    }
    cout<<ans<<endl;
    return 0;
}



Measured memory_bytes: 3444
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }

int n, m;
struct pydata {
    int no; long long y;
};
bool cmp(const pydata &aa, const pydata &bb) {
    return aa.y < bb.y;
}
struct andata {
    int no; int year;
};

int main() {
    cin >> n >> m;
    vector< vector<pydata> > ken(n, vector<pydata>());

    for(int i = 0; i < m; ++i) {
        int pp; long long yy;
        cin >> pp >> yy;
        pp--;
        pydata indata; indata.no = i; indata.y = yy;
        ken.at(pp).push_back(indata);
    }

    for(int i = 0; i < n; ++i) {
        sort(ken.at(i).begin(), ken.at(i).end(), cmp);
    }

    vector<andata> ansdata(m);
    for(int i = 0; i < n; ++i) {
        for(int j = 0; j < ken.at(i).size(); ++j) {
            pydata outdata = ken.at(i).at(j);
            int chno = outdata.no;
            andata ina;
            ina.no = j+1;
            ina.year = i+1;
            ansdata.at(chno) = ina;
        }
    }

    for(int i = 0; i < m; ++i) {
        cout << setw(6) << setfill('0') << ansdata.at(i).year;
        cout << setw(6) << setfill('0') << ansdata.at(i).no << endl;
    }
}

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

using int64 = long long;

int main() {
  int n, m;
  cin >> n >> m;

  vector<int64> dp(1 << n, 1LL << 60);
  dp[0] = 0;
  for (int i = 0; i < m; ++i) {
    int a, b;
    cin >> a >> b;
    int bit = 0;
    for (int j = 0; j < b; ++j) {
      int c;
      cin >> c;
      bit |= 1 << (c - 1);
    }
    dp[bit] = min<int64>(dp[bit], a);
  }

  for (int k = 0; k < 3; ++k) {
    for (int i = 0; i < 1 << n; ++i) {
      if (dp[i] > 1LL << 50)
        continue;
      for (int j = i + 1; j < 1 << n; ++j) {
        if (dp[j] > 1LL << 50)
          continue;
        int ij = i | j;
        dp[ij] = min(dp[ij], dp[i] + dp[j]);
      }
    }
  }

  int64 r = dp[(1 << n) - 1];
  if (r > 1LL << 50) r = -1;
  cout << r << "\n";

  return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,n) for(int i=0;i<(int)(n);++i)
#define REPR(i,n) for (int i=(int)(n)-1;i>=0;--i)
#define FOR(i,c) for(__typeof((c).begin())i=(c).begin();i!=(c).end();++i)
#define ALL(c) (c).begin(), (c).end()
#define valid(y,x,h,w) (0<=y&&y<h&&0<=x&&x<w)
#define tpl(...) make_tuple(__VA_ARGS__)
const int INF = 0x3f3f3f3f;
const double EPS = 1e-8;
const double PI = acos(-1);
const int dy[] = {-1,0,1,0};
const int dx[] = {0,1,0,-1};
typedef long long ll;
typedef pair<int,int> pii;
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
template<typename Ch,typename Tr,typename C,typename=decltype(begin(C()))>basic_ostream<Ch,Tr>& operator<<(basic_ostream<Ch,Tr>&os,
const C& c){os<<'[';for(auto i=begin(c);i!=end(c);++i)os<<(i==begin(c)?"":" ")<<*i;return os<<']';}
template<class S,class T>ostream&operator<<(ostream &o,const pair<S,T>&t){return o<<'('<<t.first<<','<<t.second<<')';}
template<int N,class Tp>void output(ostream&,const Tp&){}
template<int N,class Tp,class,class ...Ts>void output(ostream &o,const Tp&t){if(N)o<<',';o<<get<N>(t);output<N+1,Tp,Ts...>(o,t);}
template<class ...Ts>ostream&operator<<(ostream&o,const tuple<Ts...>&t){o<<'(';output<0,tuple<Ts...>,Ts...>(o,t);return o<<')';}
template<class T>void output(T t,char z=10){if(t<0)t=-t,putchar(45);int c[20];
int k=0;while(t)c[k++]=t%10,t/=10;for(k||(c[k++]=0);k;)putchar(c[--k]^48);putchar(z);}
template<class T>void outputs(T t){output(t);}
template<class S,class ...T>void outputs(S a,T...t){output(a,32);outputs(t...);}
template<class T>void output(T *a,int n){REP(i,n)cout<<a[i]<<(i!=n-1?',':'\n');}
template<class T>void output(T *a,int n,int m){REP(i,n)output(a[i],m);}
template<class T>bool input(T &t){int n=1,c;for(t=0;!isdigit(c=getchar())&&~c&&c-45;);
if(!~c)return 0;for(c-45&&(n=0,t=c^48);isdigit(c=getchar());)t=10*t+c-48;t=n?-t:t;return 1;}
template<class S,class ...T>bool input(S&a,T&...t){input(a);return input(t...);}
template<class T>bool inputs(T *a, int n) { REP(i,n) if(!input(a[i])) return 0; return 1;}

int h[100005];
ll dp[1000005];

int main() {
  int n;
  while(cin>>n) {
    inputs(h,n);
    memset(dp,0x3f,sizeof(dp));
    dp[0] = 0;
    REP(i,n) {
      chmin(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
      chmin(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
    }
    cout << dp[n-1] << endl;
  }
}


Measured memory_bytes: 8448
#define  _CRT_SECURE_NO_WARNINGS
#include <stdio.h>
#include <algorithm>
#include <utility>
#include <functional>
#include <cstring>
#include <queue>
#include <stack>
#include <math.h>
#include <iterator>
#include <vector>
#include <string>
#include <set>
#include <math.h>
#include <iostream>
#include <random>
#include<map>
#include <iomanip>
#include <time.h>
#include <stdlib.h>
#include <list>
#include <typeinfo>
#include <list>
#include <set>
#include <cassert>
#include<fstream>
#include <unordered_map>
#include <cstdlib>
#include <complex>
#include <cctype>
#include <bitset>
using namespace std;
typedef string::const_iterator State;
#define Ma_PI 3.141592653589793
#define eps 1e-5
#define LONG_INF 2000000000000000000LL
#define GOLD 1.61803398874989484820458
#define MAX_MOD 1000000007LL
#define GYAKU 500000004LL
#define MOD 998244353LL
#define seg_size 262144
#define REP(a,b) for(long long a = 0;a < b;++a)
int main() {
	long long n;
	cin >> n;
	long long ans = n;
	for (long long i = 1; i <= sqrt(n); ++i) {
		if (n % i == 0) {
			ans = min(ans, n / i + i - 2);
		}
	}
	cout << ans << endl;
}

Measured memory_bytes: 888
import sys

stdin = sys.stdin
 
ri = lambda: int(rs())
rl = lambda: list(map(int, stdin.readline().split()))
rs = lambda: stdin.readline().rstrip()  # ignore trailing spaces

N, M = rl()
AB = [rl() for _ in range(N)]
CD = [rl() for _ in range(M)]
for i in range(N):
    x, y = AB[i]
    length = 10 ** 9
    answer = -1
    for j in range(M):
        l = abs(x-CD[j][0]) + abs(y-CD[j][1])
        if l < length:
            answer = j
            length = l
    print(answer+1)

#22


Measured memory_bytes: 3064
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,l;
  cin>>n>>l;
  string s[100];
  for (int i=0;i<n;i++) cin>>s[i];
  sort(s,s+n);
  for(int i=0;i<n;i++) cout<<s[i];
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
  int a,b,c,t;
  cin>>a>>b>>c;
  if(a>b){
    t=a,a=b,b=t;
    t=0;
  }
if(b>c){
t=b,b=c,c=t;
    t=0;
  }
if(a>b){
t=a,a=b,b=t;
  }
  cout<<a<<" "<<b<<" "<<c<<"\n";
  return 0;
}

Measured memory_bytes: 1168
n,m,x = map(int,input().split())
price = 10**100
l = []

for i in range(n):
    p = list(map(int,input().split()))
    l.append(p)

for j in range(2**n):
    s = [0 for _ in range(m+1)]
    s[0] += x
    for k in range(n):
        if ((j>>k)&1):
            for o in range(m+1):
                so = s[o]
                lo = l[k][o]
                s[o] = so + lo
    if all( q >= x for q in s):
        z = s[0] - x
        if price > z:
            price = z

if price == 10**100:
    price = -1
print(price)

Measured memory_bytes: 9148
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); i++)
#define all(x) (x).begin(),(x).end()
#define dup(x,y) (((x)+(y)-1)/(y))
#define sz(x) (int)(x).size()
#define MOD 1000000007
using namespace std;
typedef long long ll;

int main(){
    int a, b, c;
    cin >> a >> b >> c;
    cout << (a+b+c)-max(a,max(b,c)) << endl;

}

Measured memory_bytes: 256
n, m = map(int, input().split())
A = [0]*m
C = [0]*m
for i in range(m):
    a, b = map(int, input().split())
    A[i] = a
    c = list(map(int, input().split()))
    c = [x-1 for x in c]
    C[i] = c


dp = [10**18]*(2**n)
dp[0] = 0
C_bit = [0]*m
for i in range(m):
    C_bit[i] = 0
    for j in C[i]:
        C_bit[i] += 2**j

for i in range(2**n):
    for j in range(m):
        ni = i | C_bit[j]
        dp[ni] = min(dp[ni], dp[i]+A[j])

if dp[-1] == 10**18:
    print(-1)
else:
    print(dp[-1])

Measured memory_bytes: 45288
#include <algorithm>
#include <bitset>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <cctype>
#include <assert.h>
#include <stdlib.h>
#include <stdio.h>
#include <cassert>
#include <cfloat>
#include <climits>
#include <cmath>
#include <complex>
#include <ctime>
#include <deque>
#include <fstream>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <limits>
#include <map>
#include <memory>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <unordered_set>
#include <utility>
#include <vector>
#define int long long
using namespace std;
signed main() {


    int n, k;
    cin >> n >> k;
    vector<int> a(n);
    for (int i = 0; i < n; i++) {
        cin >> a[i];
    }

    for (int j = 0; j < n - k; j++) {
        if (a[j] < a[j + k]) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
}

Measured memory_bytes: 4844
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using static System.Console;
using static System.Math;

namespace AtTest.ABC_145
{
    class A
    {
        static void Main(string[] args)
        {
            var sw = new System.IO.StreamWriter(OpenStandardOutput()) { AutoFlush = false };
            SetOut(sw);

            Method(args);

            Out.Flush();
        }

        static void Method(string[] args)
        {
            int r = ReadInt();
            WriteLine(r * r);
        }

        private static string Read() { return ReadLine(); }
        private static char[] ReadChars() { return Array.ConvertAll(Read().Split(), a => a[0]); }
        private static int ReadInt() { return int.Parse(Read()); }
        private static long ReadLong() { return long.Parse(Read()); }
        private static double ReadDouble() { return double.Parse(Read()); }
        private static int[] ReadInts() { return Array.ConvertAll(Read().Split(), int.Parse); }
        private static long[] ReadLongs() { return Array.ConvertAll(Read().Split(), long.Parse); }
        private static double[] ReadDoubles() { return Array.ConvertAll(Read().Split(), double.Parse); }
    }
}


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

template<class T> void vin(vector<T>& v, int n) {
    v.resize(n);
    for (int i = 0; i < n; ++i) {
        cin >> v[i];
    }
}

map<ll, ll> prime_factor(ll n) {
    map<ll, ll> res;
    for (ll i=2; i*i<=n; ++i) {
        while (n%i == 0) {
            ++res[i];
            n /= i;
        }
    }
    if (n != 1) res[n]++;
    return res;
}

ll mod = 1e9+7;

struct ModComb {
    vector<long long> fact, rfact;
    long long max, mod;
    ModComb(long long ma, long long mod) :fact(ma, 0), rfact(ma, 0), max(ma), mod(mod) {
        fact[0] = 1;
        for (long long i=1; i<max; ++i) {
            fact[i] = fact[i-1]*i;
            fact[i] %= mod;
        }
        rfact[max-1] = mod_inverse(fact[max-1], mod);
        for (long long i=max-2; i>=0; --i) {
            rfact[i] = rfact[i+1]*(i+1);
            rfact[i] %= mod;
        }
    }
    long long mod_pow(long long x, long long n, long long mod) {
        long long a = 1LL;
        while (n) {
            if (n%2) a = ((a%mod)*(x%mod))%mod;
            x = ((x%mod)*(x%mod))%mod;
            n /= 2LL;
        }
        return a;
    }

    long long mod_inverse(long long a, long long m) {
        return mod_pow(a, m-2, m);
    }

    long long operator()(long long n, long long r) {
        if (n < r) return 0;
        return (((fact[n] * rfact[r]) % mod) * rfact[n - r]) % mod;
    }
};

int main() {
    ll n, m;
    cin >> n >> m;
    ModComb mb(210000LL, mod);

    auto v = prime_factor(m);
    ll res = 1;
    for (auto& t : v) {
        ll num = t.second;
        ll tmp = mb(n-1+num, num);
        res = (res * tmp) % mod;
    }
    cout << res << endl;
}


Measured memory_bytes: 3584
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <queue>
#include <cstring>
#include <vector>
#include <map>
#include <algorithm>
#include <cctype>
#include <cmath>
#include <bitset>
#include <set>
using namespace std;

#define REP(i,n) for(int i=0;i<(int)(n);i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)
#define FOR(i,k,n) for(int i=(k);i<(int)(n);i++)
#define all(i,n) (i),(i+n)

int dx4[4]={1,0,-1,0};
int dy4[4]={0,-1,0,1};
int dx8[8]={1,0,-1,1,-1,1,0,-1};
int dy8[8]={1,1,1,0,0,-1,-1,-1};

typedef pair<int, int> P;
typedef pair<string, int> SP;
typedef long long ll;

const int INF = 1e9;
const ll LLINF = 1e18;
const int MAX_V = 1e6+1;
const ll mod = 1000000007;

// --------------------------------------
ll a, b, c, d;
ll gcd(ll a, ll b) {
  if(b == 0) return a;
  return gcd(b, a % b);
}

ll lcm(ll a, ll b) {
  if(a < b) swap(a, b);
  return a * b / gcd(a, b);
}
int main() {
  cin.tie(0);
  ios::sync_with_stdio(false);

  cin >> a >> b >> c >> d;
  ll cc = (b / c - (a - 1) / c);
  ll dc = (b / d - (a - 1) / d);

  ll lc = lcm(c, d);
  ll lcc = (b / lc - (a - 1) / lc);

  cout << (b - (a - 1)) - (cc + dc - lcc) << endl;
}


Measured memory_bytes: 256
N = int(input())
H = list(map(int, input().split()))

cnt = 0
max_cnt = -1
for i in range(1, N):
    if H[i-1] >= H[i]:
        cnt += 1
    else:
        if cnt >= max_cnt:
            max_cnt = cnt
        cnt = 0
if cnt >= max_cnt:
    max_cnt = cnt
print(max_cnt) 

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

typedef pair<int,int> P;
typedef vector<P> vec;
typedef vector<vec> mat;

const int INF = 1 << 28;

mat v;

int long_path(int now, int pre, int d) {
    if (v[now].size() == 1) return 0;
    int ret = 0;
    for (int i = 0; i < v[now].size(); i++) {
        if (v[now][i].second == pre) continue;
        ret = max(ret, long_path(v[now][i].second, now, v[now][i].first));
    }

    return ret + d;
}

int main() {
    int n;
    while(cin >> n, n) {
        v.resize(0);
        v.resize(n);
        vector <int> A(n), B(n);
        for (int i = 1; i < n; i++) cin >> A[i], A[i]--;
        for (int i = 1; i < n; i++) cin >> B[i];
        for (int i = 1; i < n; i++) {
            v[i].push_back(P(B[i], A[i]));
            v[A[i]].push_back(P(B[i], i));
        }

        int sum = 0;
        int sum_of_lev = 0;
        for (int i = 0; i < n; i++) {
            for (int j = 0; j < v[i].size(); j++) {
                if (v[i].size() > 1 && v[v[i][j].second].size() > 1) {
                    sum += v[i][j].first * 3;
                } else {
                    sum_of_lev += v[i][j].first;
                }
            }
        }

        sum /= 2;
        sum_of_lev /= 2;

        int path = 0;
        for (int i = 0; i < n; i++) {
            path = max(path, long_path(i, -1, 0));
        }

        cout << sum - path + sum_of_lev << endl;
    }

    return 0;
}

Measured memory_bytes: 3204
#include <bits/stdc++.h>
using namespace std;
int main() {
    const int MOD= 1000000007;
    int n,m;
    vector <bool> issafe;
    cin >> n >>m;
    issafe.assign(n+1, true);
    for(int i=0;i<m;++i) {
        int a;
        cin >> a;
        issafe[a]=false;
    }
    vector <int> dp(n+1,0);
    dp[0]=1;
    if(issafe[1]) dp[1]=1;
    for(int i=2;i<=n;++i) {
        if(issafe[i-1]) dp[i]+=dp[i-1];
        if(issafe[i-2]) dp[i]+=dp[i-2];
        dp[i] %= MOD;
    }
    cout << dp[n] << endl;
}



Measured memory_bytes: 640
#include <iostream>
#include <cstdlib>
#include <cstdio>
#include <cstring>
#include <algorithm>

#include <queue>

using namespace std;


typedef long long LL;;


typedef pair <int, int> pr;


const int N = 2e5 + 10;


int a[N], b[N];
int n;

priority_queue <pr> q;

int main()
{
	scanf("%d", &n);
	
	for (int i = 1; i <= n; i++) scanf("%d", &a[i]);
	for (int i = 1; i <= n; i++) scanf("%d", &b[i]);
	
	for (int i = 1; i <= n; i++) q.push(make_pair(b[i], i));
	
	LL Ans = 0;
	
	while (!q.empty())
	{
		pr now = q.top(); q.pop();
		int val = now.first, id = now.second;
		if (val == a[id]) continue;
		if (val < a[id]) return 0 & puts("-1");
		int w = val - a[id]; 
		int num = b[id < n ? id + 1 : 1] + b[id > 1 ? id - 1 : n];
		if (num > w) return 0 & puts("-1");
		Ans += w / num;
		b[id] -= (w / num) * num;
		q.push(make_pair(b[id], id));
	}
	
	printf("%lld\n", Ans);
	
	return 0;
}

Measured memory_bytes: 3956
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <unordered_map>
#include <map>
#include <set>
#include <unordered_set>
#include <algorithm>
#include <cctype>
#define rep(x,y,z) for(long long x=y;x<z;++x)
#define dwn(x,y,z) for(long long x=y;x>z;--x)
using namespace std;

typedef long long ll;

ll ans[3][100000];

int main() {
    ll n;
    cin >> n;
    vector<ll> a(n), b(n), c(n);
    for (ll i = 0; i < n; i++) {
        cin >> a[i] >> b[i] >> c[i];
    }
    ans[0][0] = a[0];
    ans[1][0] = b[0];
    ans[2][0] = c[0];
    for (ll j = 1; j < n; j++) {
        ans[0][j] = a[j] + max(ans[1][j - 1], ans[2][j - 1]);
        ans[1][j] = b[j] + max(ans[0][j - 1], ans[2][j - 1]);
        ans[2][j] = c[j] + max(ans[1][j - 1], ans[0][j - 1]);
    }
    cout << max(max(ans[0][n - 1], ans[1][n - 1]), ans[2][n - 1]) << endl;
    return 0;
}


Measured memory_bytes: 4992
#include <cstdio>
#include <cstring>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iostream>
#include <queue>
#include <bits/stdc++.h>
#include <iomanip>
#include <string>
#include <map>
using namespace std;
typedef long long LL;
const int N = 4005;
const int K=31;  
const int M=10921000; 
const int INF = 0x3f3f3f3f; 
const LL MOD = 1e9+7;
int n,m;
int a,b;
LL dp[N][N];
LL dp2[N][N];
int main ()
{
    // for(int i=0;i<=4000;i++)
    //     dp[i][0]=1;
    // for(int i=1;i<=4000;i++)
    //     for(int j=1;j<=i;j++)
    //         dp[i][j]=(dp[i-1][j-1]+dp[i-1][j])%MOD;
    for (int i=0;i<N;i++)
        for (int j=0;j<=i;j++)
        {
            if (j==0 || i==j)
                dp[i][j] = 1;
            else
                dp[i][j] = (dp[i-1][j-1]+dp[i-1][j])%MOD;
        }

    // for (int i = 0; i < N; i ++) dp2[i][0] = dp2[i][i] = 1;
    // for (int i = 1; i < N; i ++) {
    //         for (int j = 1; j < i; j ++) {
    //                 dp2[i][j] = (dp2[i - 1][j] + dp2[i - 1][j - 1]) % MOD;
    //         }
    // }
    while (~scanf("%d%d",&a,&b))
    {
        // LL ans=a+1;
        // for(int i=1;i<=b-1;i++)
        //     for(int j=0;j<=min(i-1,n-i);j++){
        //         int res=1;
        //         res=1ll*res*dp[m-1][i]%MOD*dp[i-1][j]%MOD*dp[n-i-j+2][2]%MOD;
        //         ans=(ans+res)%MOD;
        // }
        LL ans = a+1;
        for (int i=1;i<=min(a,b-1);i++)
            for (int j=0;i+j<=a && j<i;j++)
            {
                LL tmp = (dp[b-1][i] * dp[i-1][j])%MOD * dp[a-i-j+2][2]%MOD;
                ans = (ans + tmp)%MOD;
            }
        // for(int i=1;i<=min(a,b-1);i++)
        // {
        //     for(int j=0;j<i&&j+i<=a;j++)
        //     {
        //         LL lin=dp[b-1][i]*dp[i-1][j]%MOD*dp[a-i-j+2][2]%MOD;
        //         cout<<i<<" "<<j<<" "<<lin<<" "<<dp[b-1][i]<<" "<<dp[i-1][j]<<" "<<dp[a-i-j+2][2]<<endl;
        //         ans=(ans+lin)%MOD;
        //     }
        // }
        // cout<<ans<<endl;
        // ans = a+1;
        // for(int i=1;i<=min(a,b-1);i++)
        // {
        //     for(int j=0;j<i&&j+i<=a;j++)
        //     {
        //         LL lin=dp2[b-1][i]*dp2[i-1][j]%MOD*dp2[a-i-j+2][2]%MOD;
        //         cout<<i<<" "<<j<<" "<<lin<<" "<<dp2[b-1][i]<<" "<<dp2[i-1][j]<<" "<<dp2[a-i-j+2][2]<<endl;
        //         ans=(ans+lin)%MOD;
        //     }
        // }
        printf("%lld\n", ans);
    }
    return 0;
}
 
/*
 
6 5
1 2
2 3
3 4
4 5
5 6
 
*/

Measured memory_bytes: 126080
#include<stdio.h>
#define N 50400
int prime[N];
int main(){
	int i,j,n;
	int c;
	for(i=0;i<N;i++)prime[i]=1;
	prime[0] = prime[1] = 0;
	for(i=4;i<N;i+=2)prime[i]=0;
	for(i=3;i<N;i+=2){
		if(prime[i] == 0 )continue;
		for(j=i+i;j<N;j+=i)prime[j]=0;
	}

	for(;scanf("%d",&n)&&n;){
		c=0;
		for(i=2;i<=n/2;i++){
			if(prime[i]&&prime[n-i])c++;
		}
		printf("%d\n",c);
	}
	return 0;
}

Measured memory_bytes: 604
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int n = Integer.parseInt(sc.next());
        Integer[] ary_1 = new Integer[n];
        Integer[] ary_2 = new Integer[n];
        Integer[] ary_3 = new Integer[n-1];

        for(int i = 0; i < n; ++i) {
            int tmp = sc.nextInt();
            ary_1[i] = tmp;
        }
        for(int i = 0; i < n; ++i) {
            int tmp = sc.nextInt();
            ary_2[i] = tmp;
        }
        for(int i = 0; i < n-1; ++i) {
            int tmp = sc.nextInt();
            ary_3[i] = tmp;
        }

        int sum = 0;
        for(int i = 0; i < n; ++i) {
            sum += ary_2[i];
        }

        //System.out.println(sum);

        for(int i = 0; i < n-1; ++i) {
            if(ary_1[i] + 1 == ary_1[i + 1]) {
                sum += ary_3[ary_1[i]-1];
            }
        }

        System.out.println(sum);
    }
}

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

long long n;
long long a[200005];

int main(){
	cin >> n;
	for(long long i = 0; i < n; i++){
		cin >> a[i];
	}
	vector<long long> ans;
	if(n%2 == 0){
		for(long long i = n - 1; i >= 0; i-=2){
			ans.push_back(a[i]);
		}
		for(long long i = 0; i < n; i+=2){
			ans.push_back(a[i]);
		}
	}else{
		for(long long i = n - 1; i >= 0; i-=2){
			ans.push_back(a[i]);
		}
		for(long long i = 1; i < n; i+=2){
			ans.push_back(a[i]);
		}
	}

	for(long long i = 0; i < ans.size(); i++){
		cout << ans[i];
		if(i != ans.size() - 1){
			cout << " ";
		}
	}
	cout << endl;
}



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

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

	int sum = 0;
	vector<int>s(n); for (auto&& x : s) { cin >> x; sum += x; }
	if (sum % 10 != 0) {
		cout << sum << endl; return 0;
	}

	sort(s.begin(), s.end());
	for (int i = 0; i < n; i++) {
		sum -= s[i] % 10 == 0 ? 0 : s[i];
		if (sum % 10 != 0) {
			cout << sum << endl; return 0;
		}
	}
	if (sum % 10 == 0)sum = 0;
	cout << sum << endl;

	return 0;
}

Measured memory_bytes: 256
import core.bitop, std.algorithm, std.ascii, std.bigint, std.conv, std.math,
    std.functional, std.numeric, std.range, std.stdio, std.string, std.random,
    std.typecons, std.container, std.format;

// dfmt off
T lread(T = long)(){return readln.chomp.to!T();}
T[] aryread(T = long)(){return readln.split.to!(T[])();}
void scan(TList...)(ref TList Args){auto line = readln.split();
foreach (i, T; TList){T val = line[i].to!(T);Args[i] = val;}}
alias sread = () => readln.chomp();enum MOD = 10 ^^ 9 + 7;
alias PQueue = BinaryHeap!(Array!long, "a<b");
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread();
    long odd_count;
    foreach (a; A)
        odd_count += a & 1;
    writeln(odd_count & 1 ? "NO" : "YES");
}


Measured memory_bytes: 4348
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<queue>
#include<cstring>
#define pb push_back
#define X first
#define Y second

using namespace std;
typedef pair<int,int> pii;
typedef pair<int,pii> pipii;
typedef long long ll;
map<pii,int > dfa;
map<int,ll> memo;
vector<int> nfa[100][100];
queue<int > que;
int N,low[10],high[10],nfafin;
set<int> used,dfafin;

void makeNFA(){
  int i,j,k;
  for(i=0;i<N;i++){
    if(low[i]/10==high[i]/10){
      if(low[i]<10){
	for(j=low[i]%10;j<=high[i]%10;j++)
	  nfa[i*4][j].pb(i*4+4);
      }else{
	nfa[i*4][low[i]/10].pb(i*4+1);
	for(j=low[i]%10;j<=high[i]%10;j++)
	  nfa[i*4+1][j].pb(i*4+4);
      }
    }else{
      if(low[i]<10){
	for(j=low[i]%10;j<10;j++)
	  nfa[i*4][j].pb(i*4+4);
      }else{
	nfa[i*4][low[i]/10].pb(i*4+1);
	for(j=low[i]%10;j<10;j++)
	  nfa[i*4+1][j].pb(i*4+4);
      }

      for(j=low[i]/10+1;j<high[i]/10;j++){
	nfa[i*4][j].pb(i*4+2);
      }
      if(high[i]/10-low[i]/10>1)for(k=0;k<10;k++)
	nfa[i*4+2][k].pb(i*4+4);
      
      nfa[i*4][high[i]/10].pb(i*4+3);
      for(k=0;k<=high[i]%10;k++)
	nfa[i*4+3][k].pb(i*4+4);
    }
  }
  nfafin=4*N;
  return;
}

void makeDFA(){
  int i,j,k;
  que.push(1);
  while(!que.empty()){
    int cur=que.front();que.pop();
    int to=0;
    for(int in=0;in<10;in++){
      to=0;
      for(i=0;i<30;i++){
	if(cur&(1<<i)){
	  for(j=0;j<nfa[i][in].size();j++)
	    to|=(1<<nfa[i][in][j]);
	}
      }
      if(to==0)continue;
      if(used.count(to)==0){
	used.insert(to);
	que.push(to);
      }
      dfa[pii(cur,to)]++;
    }
  }
  return;
}

ll dfs(int pos){
  if(pos == (1<<nfafin))
    return 1;
  if(memo.count(pos))
    return memo[pos];
  ll re=0;
  map<pii,int>::iterator it;
  it=dfa.lower_bound(pii(pos,0));
  for(;it!=dfa.end();++it){
    if(it->X.X!=pos)break;
    re+=(it->Y)*dfs(it->X.Y);
  }
  return memo[pos]=re+!!(pos&(1<<nfafin));
}

int main(){
  int i,j,k;
  while(1){
    cin>>N;
    if(N==0)break;

    dfa.clear();memo.clear();
    for(i=0;i<100;i++)for(j=0;j<100;j++)nfa[i][j].clear();
    while(!que.empty())que.pop();
    used.clear(),dfafin.clear();

    for(i=0;i<N;++i)
      cin>>low[i]>>high[i];
    // cout<<N<<endl;
    makeNFA();
    /*    for(i=0;i<100;i++)for(j=0;j<100;j++){
	if(nfa[i][j].size()){
	  cout<<i<<","<<j<<":";
	  for(k=0;k<nfa[i][j].size();k++)
	    cout<<nfa[i][j][k]<<",";
	  cout<<endl;
	}
	}*/
    makeDFA();/*
    for(map<pii,int>::iterator it=dfa.begin();it!=dfa.end();++it)
    cout<<it->X.X<<","<<it->X.Y<<","<<it->Y<<endl;*/
    cout<<dfs(1)<<endl;
  }
  return 0;
}

Measured memory_bytes: 1500
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <cmath>
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int mod = 1000000007;

vector<int> g[100005];
int d[100005];

void dfs(int x, int p) {
    d[x] = d[p] + 1;
    for (int i : g[x]) if (i != p) dfs(i, x);
}

int main() {
    ios::sync_with_stdio(false);
    int n, u, v, c = 0;
    vector<int> a, b, e, z, y;
    cin >> n;
    for (int i = 1; i < n; i++) cin >> u >> v, g[u].push_back(v), g[v].push_back(u);
    u = v = 0;
    dfs(1, 1);
    for (int i = 1; i <= n; i++) if (d[i] > d[u]) u = i;
    for (int i = 1; i <= n; i++) d[i] = 0;
    dfs(u, u);
    for (int i = 1; i <= n; i++) if (d[i] > d[v]) v = i;
    a.push_back(v);
    while (v != u) {
        for (int i : g[v]) if (d[i] + 1 == d[v]) {
            v = i;
            a.push_back(v);
            break;
        }
    }
    for (int i : a) {
        if (i == a[0] || i == a.back()) b.push_back((int)g[i].size());
        else b.push_back((int)g[i].size() - 1);
        c += b.back();
    }
    e = b;
    reverse(e.begin(), e.end());
    if (c != n) {
        cout << -1;
    } else {
        z.resize(n);
        y.resize(n);
        c = 0;
        for (int i : b) {
            z[c + i - 1] = c + 1;
            for (int j = c + 1; j < c + i; j++) z[j - 1] = j + 1;
            c += i;
        }
        c = 0;
        for (int i : e) {
            y[c + i - 1] = c + 1;
            for (int j = c + 1; j < c + i; j++) y[j - 1] = j + 1;
            c += i;
        }
        if (z > y) swap(z, y);
        for (int i : z) cout << i << ' ';
    }
}


Measured memory_bytes: 15628
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
const int N=2e5+10;
const int M=1e6+10;
int gi() {
    int x=0,o=1;char ch=getchar();
    while((ch<'0'||ch>'9')&&ch!='-') ch=getchar();
    if(ch=='-') o=-1,ch=getchar();
    while(ch>='0'&&ch<='9') x=x*10+ch-'0',ch=getchar();
    return x*o;
}
struct edge { int to,nxt; } e[M];
int tot=1,h[N],cur[N];
void adde(int u,int v) {
    e[++tot]=(edge){v,h[u]};h[u]=tot;
    e[++tot]=(edge){u,h[v]};h[v]=tot;
}
int n,rt1,rt2,a[N],b[N],ans[N];
vector<int> E[N];
bool odd[N],vis[M];
void dfs(int u) {
    odd[u]=1;
    for(int v:E[u]) dfs(v),odd[u]^=1;
}
void dfs2(int u) {
    for(int &i=cur[u];i;i=e[i].nxt) {
        if(vis[i]) continue;
        vis[i]=vis[i^1]=1;
        int v=e[i].to;
        if(u&&u<=n&&v==u+n) ans[u]=-1;
        else if(v&&u>n&&v==u-n) ans[v]=1;
        dfs2(v);
    }
}
int main() {
    cin>>n;
    for(int i=1;i<=n;i++) {
        a[i]=gi();
        if(a[i]==-1) rt1=i;
        else E[a[i]].pb(i),adde(a[i],i);
    }
    for(int i=1;i<=n;i++) {
        b[i]=gi();
        if(b[i]==-1) rt2=i+n;
        else E[b[i]+n].pb(i+n),adde(b[i]+n,i+n);
    }
    dfs(rt1);dfs(rt2);
    for(int i=1;i<=n;i++) if(odd[i]!=odd[i+n]) return puts("IMPOSSIBLE"),0;
    puts("POSSIBLE");
    for(int i=1;i<=n;i++) if(odd[i]) adde(i,i+n);
    adde(0,rt1);adde(0,rt2);
    for(int i=0;i<=n+n;i++) cur[i]=h[i];
    dfs2(0);
    for(int i=1;i<=n;i++) printf("%d ",ans[i]);
    return 0;
}
//orzgzy
//鸡贼明年进队超稳


Measured memory_bytes: 26744
n, c = map(int, input().split())
sushi = [list(map(int, input().split())) for _ in range(n)]
clock = [[0, 0] for _ in range(n)]
anticlock = [[0, 0] for _ in range(n)]

max_clock = max(sushi[0][1] - sushi[0][0], 0)
clock[0] = [sushi[0][1] - sushi[0][0], max_clock]
for i in range(1, n):
	clock[i][0] = clock[i-1][0] + sushi[i][1] - (sushi[i][0] - sushi[i-1][0])
	max_clock = max(max_clock, clock[i][0])
	clock[i][1] = max_clock

max_anti = max(sushi[-1][1] - (c - sushi[-1][0]), 0)
anticlock[0] = [sushi[-1][1] - (c - sushi[-1][0]), max_anti]
for i in range(1, n):
	anticlock[i][0] = anticlock[i-1][0] + sushi[-(i+1)][1] - (sushi[-i][0] - sushi[-(i+1)][0])
	max_anti = max(max_anti, anticlock[i][0])
	anticlock[i][1] = max_anti

ans_clock = 0
ans_anti = 0

for i in range(n - 1):
	if clock[i][0] - sushi[i][0] + anticlock[n - 2 - i][1] > ans_clock:
		ans_clock = clock[i][0] - sushi[i][0] + anticlock[n - 2 - i][1]
	if anticlock[i][0] - (c - sushi[-(i+1)][0]) + clock[n - 2 - i][1] > ans_anti:
		ans_anti = anticlock[i][0] - (c - sushi[-(i+1)][0]) + clock[n - 2 - i][1]

print(max(ans_clock, ans_anti, clock[-1][1], anticlock[-1][1]))

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

#define rep(i,s,n) for(ll i = (s); i < (n); i++)
#define rep0(i,n) rep(i,0,n)
#define rep1(i,n) rep(i,1,n+1)
#define repR(i,s,n) for(ll i = (n-1); i >= (s); i--)
#define repR0(i,n) repR(i,0,n)
#define repR1(i,n) repR(i,1,n+1)

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;
#define fcout cout << fixed << setprecision(18)

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

int a[100];
int cells[100][100]; // r * c

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

  priority_queue<ll> q;
  rep0(i, N) {
    ll a;
    cin >> a;
    q.push(a);
  }

  rep0(i, M) {
    ll a = q.top();
    q.pop();
    q.push(a / 2);
  }

  ll ans = 0;
  rep0(i, N) {
    ll a = q.top();
    ans += a;
    q.pop();
  }

  cout << ans << BR;
  return 0;
}

Measured memory_bytes: 1400