akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < n; i++)
#define REPR(i, n) for(int i = n - 1; i >= 0; i--)
#define FOR(i, m, n) for(int i = m; i <= n; i++)
#define FORR(i, m, n) for(int i = m; i >= n; i--)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define VSORTR(v) sort(v.rbegin(), v.rend());
#define ALL(v) (v).begin(),(v).end()
 
using ll = long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using P = pair<ll, ll>;

// U, D, L, R
const vll dx = {0, 0, -1, 1};
const vll dy = {-1, 1, 0, 0};

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

    ll h, w;
    cin >> h >> w;
    vector<string> s(h);
    REP(i, h) {
        cin >> s[i];
    }
    ll res = -1, inf = 1e10;
    REP(i, h) {
        REP(j, w) {
            if(s[i][j] == '#') continue;
            queue<P> que;
            vvll dist(h, vll(w, inf));
            dist[i][j] = 0;
            que.push({i, j});
            while (!que.empty()) {
                ll cy = que.front().first, cx = que.front().second;
                que.pop();
                REP(k, 4) {
                    ll ny = cy + dy[k], nx = cx + dx[k];
                    if (ny < 0 || ny >= h || nx < 0 || nx >= w) continue;
                    if (s[ny][nx] == '#') continue;
                    if (dist[ny][nx] != inf) continue;
                    que.push({ny, nx});
                    dist[ny][nx] = min(dist[ny][nx], dist[cy][cx] + 1);
                    res = max(res, dist[ny][nx]);
                }
            }
        }
    }
    cout << res << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
struct cww{cww(){ios::sync_with_stdio(false);cin.tie(0);}}star;
#define P(x) cout << (x) << "\n"
#define p(x) cout << (x)
#define all(c) (c).begin(), (c).end()
#define rall(c) (c).rbegin(), (c).rend()
#define vv(type, c, m, n, i) vector<vector<type>> c(m, vector<type>(n, i));
#define rep(i,a,n) for(int i=(a), i##_len=(n); i<i##_len; ++i)
#define rrep(i,a,n) for(int i=(a), i##_len=(n); i>i##_len; --i)
#define len(x) ((int)(x).size())
#define mp make_pair
#define eb emplace_back
#define fi first
#define se second
#define chmax(a,b) if(a<b)a=b;
#define chmin(a,b) if(b<a)a=b;
typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<long long> vll;
typedef vector<string> vs;
typedef vector<bool> vb;
constexpr int MAX = 1400;
vv(int, dp, MAX, MAX, 0);
vv(int, G, MAX, MAX, 0);
int getLargestSquare(int H, int W) {
	int maxWidth = 0;
	rep(i, 0, H) {
		rep(j, 0, W) {
			dp[i][j] = (G[i][j] + 1) % 2;
			maxWidth |= dp[i][j];
		}
	}
	rep(i, 1, H) {
		rep(j, 1, W) {
			if(!G[i][j]) {
				dp[i][j] = min({dp[i - 1][j - 1], dp[i - 1][j], dp[i][j - 1]}) + 1;
				chmax(maxWidth, dp[i][j]);
			}
		}
	}
	return maxWidth * maxWidth;
}
int main() {
	int H, W; cin >> H >> W;
	rep(i, 0, H) rep(j, 0, W) cin >> G[i][j];
	P(getLargestSquare(H, W));
	return 0;
}

Measured memory_bytes: 18396
#include <bits/stdc++.h>
using namespace std;
using lint = long long;
template<class T = int> using V = vector<T>;
template<class T = int> using VV = V< V<T> >;

int main() {
  cin.tie(nullptr); ios::sync_with_stdio(false);
  int n; cin >> n;
  V<> a(n); for (auto&& e : a) cin >> e;
  sort(begin(a), end(a));
  lint res = 0;
  for (int j = 0; j < n; ++j) for (int i = 0; i < j; ++i) {
    int l = a[j] - a[i] + 1, u = a[i] + a[j];
    int c = lower_bound(begin(a), end(a), u) - lower_bound(begin(a), end(a), l);
    c -= l <= a[i] and a[i] < u;
    c -= l <= a[j] and a[j] < u;
    res += c;
  }
  cout << res / 3 << '\n';
}

Measured memory_bytes: 256
#![allow(unused_imports)]
 
use proconio::{input, fastout};
use proconio::marker::*;
use std::collections::HashMap;
 
#[fastout]
fn main() {
  input! {
    s: String,
    t: String,
  }
  let mut s: Vec<char> = s.chars().collect();
  let mut t: Vec<char> = t.chars().collect();
  let mut amap: HashMap<char, char> = HashMap::new();
  let mut bmap: HashMap<char, char> = HashMap::new();
  for i in 0..s.len() {
    let sc = s[i];
    let tc = t[i]; 
    if let Some(v) = amap.get(&sc) {
      if v != &tc {
        println!("No");
        return
      }
    }
    if let Some(v) = bmap.get(&tc) {
      if v != &sc {
        println!("No");
        return
      }
    }
    amap.insert(sc, tc);
    bmap.insert(tc, sc);
  }
  println!("Yes");
}

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

using namespace std;
#define ll long long int
#define mp make_pair
#define pb push_back
#define fi first
#define si second
#define fastIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define F(a,n) for(int i=0;i<n;i++){cin>>a[i];}
#define F1(a,n) for(int i=1;i<=n;i++){cin>>a[i];}
#define P(a,n) for(int i=0;i<n;i++){cout<<a[i]<<' ';}cout<<endl;
#define P1(a,n) for(int i=1;i<=n;i++){cout<<a[i]<<' ';}cout<<endl;
#define NF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cin>>a[i][j];}}
#define NF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cin>>a[i][j];}}
#define PNF(a,n,m) for(int i=0;i<n;i++){for(int j=0;j<m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
#define PNF1(a,n,m) for(int i=1;i<=n;i++){for(int j=1;j<=m;j++){cout<<a[i][j]<<' ';}cout<<endl;}cout<<endl;
const int nax = 1e4+5;
const int mod = 1e9+7;
int comp[21][21];
int n;
ll dp[21][(1<<21)];

ll func(ll pos, ll women){
	//base case
	if(pos == n){
		return women == 0;
	}
	//recursive case
	if(dp[pos][women]!=-1){ return dp[pos][women];}
	ll ans=0;
	for(int i=0; i<n; i++){
		if(comp[pos][i] && (women&(1<<i))){
			ans += func(pos+1, (women&(~(1<<i))));
			ans %= mod;
		}
	}
	return dp[pos][women] = ans;
}

int main(){
	fastIO
	cin>>n;
	NF(comp, n , n);
	memset(dp, -1, sizeof(dp));
	cout<<func(0, ((1<<n)-1));
	
}

Measured memory_bytes: 344320
#include <bits/stdc++.h>
#include <math.h>
#include <vector>
#include <queue>
#include <iomanip>
#include <string>
using namespace std;
using Graph = vector<vector<int>>;
#define rep(i,n) for(int i=0;i<n;i++)
#define rep_1 (i,j,n) for(int i=j;i<n;i++)
typedef long long ll;
typedef long l;
const ll l_INF = 101010101000;
const int INF = 1010101010;
const int dx[4] = {-1,0,1,0};
const int dy[4] = {0,-1,0,1};
using vi = vector<int>;
using vvi = vector<vi>;
using pii = pair<int,int>;

int main(){
  int n;
  cin >> n;
  vector<int> p(n);
  rep(i,n) cin >> p[i];
  vector<int> min(n);
  int min_0=INF;
  rep(i,n){
    if(min_0>p[i]) min_0=p[i];
    min[i] = min_0;
  }
  int count = 0;
  rep(i,n){
    if(i==0) count++;
    else if(min[i-1]>p[i]) count++;
  }
  cout << count;
}

Measured memory_bytes: 1792
#include<cstdio>
#include<algorithm>
int main(void){
  int n, a, b, c, d[128], dollar, cal, m;

  scanf("%d %d %d %d", &n, &a, &b, &c);
  for(int i = 0;i < n; i++) scanf("%d", d + i);
  dollar = a; cal = c; m = cal / dollar;
  std::sort(d, d + n);
  std::reverse(d, d + n);
  for(int i = 0;i < n; i++){
    dollar += b; cal += d[i];
    m = std::max(m, cal / dollar);
  }
  printf("%d\n", m);
}


Measured memory_bytes: 1040
#pragma GCC optimize("O3")
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <bits/stdc++.h>

#define DEBUG
#ifdef DEBUG
    #define IFD(...) __VA_ARGS__
    #define IFN(...)
    #define L cout<<__LINE__<<"\n";
    #define PRINT(...) __VA_ARGS__ cout<<__LINE__<" : "<<#__VA_ARGS__<<"\n"
    #define PRT(x) cout<<__LINE__<<" : "<<#x<<" = "<<x<<"\n"
#else // DEBUG
    #define IFD(...)
    #define IFN(...) __VA_ARGS__
    #define L
    #define PRINT(...) __VA_ARGS__
    #define PRT(x)
#endif // DEBUG

#define it iterator
#define rit reverse_iterator
#define mp make_pair
#define mems(a,b) memset(a,b,sizeof(a))
#define mem0(a) mems(a,0)
#define mem1(a) mems(a,1)
#define mem255(a) mems(a,255)
#define halt exit(0)
#define all(c) (c).begin() , (c).end()
#define sz(c) ((long long)((c).size()))
#define phb push_back
#define ppb pop_back
#define phf push_front
#define ppf pop_front
#define fort0(i,a,b) for(ll i=a,i##_TO=b;i<i##_TO;i++)
#define for0(i,n) fort0(i,0,n)
#define fort1(i,a,b) for(ll i=a,i##_TO=b;i<=i##_TO;i++)
#define for1(i,n) fort1(i,1,n)
#define ford(i,a,b) for(ll i=a,i##_TO=b;i>=i##_TO;i--)

using namespace __gnu_pbds;
using namespace std;

#define int ll

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef pair<ll,ll> pll;

template
<
    class key,
    class val=null_type,
    class comp=less<key>
>
using ord_set=tree
<
    key,
    val,
    comp,
    rb_tree_tag,
    tree_order_statistics_node_update
>;

signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
    int n,k;
    cin>>n>>k;
//    int m=-1;
//    for(int i=1;i<=n;i++)
//    {
//        int t;
//        cin>>t;
//        if(t==1)
//            m=i;
//    }
    cout<<(n-1+k-2)/(k-1);
}


Measured memory_bytes: 256
#include<stdio.h>

int main(void){
  char s[10];
  int i;
  scanf("%s",s);
  for(i=0;i<3;i++){
    if(s[i]==s[i+1]){
      printf("Bad\n");
      return 0;
    }
  }
  printf("Good\n");
  return 0;
}

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

int main()
{
    int n;
    scanf("%d", &n);
    int d[101];
    for(int i = 0; i < n; i++)
        scanf("%d", &d[i]);

   long sum = 0;

   for(int i = 0 ; i < n - 1; i++){
      for(int j = i + 1 ; j < n ; j++){
        sum = sum + (d[i] * d[j]);
      }
   }
   printf("%ld\n", sum);
   return 0;
}


Measured memory_bytes: 3824
#include <bits/stdc++.h>
#define rep(i,a,b) for(int i=int(a);i<int(b);++i)
#define SIZE 200005
#define INF 1000000005LL
#define MOD 1000000007
using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

int main(){
    ll n;
    cin >> n;
    map<ll,ll> data;
    ll Max = -1;
    int check = 1;
    rep(i,0,n){
        ll a;
        cin >> a;
        if(i==0&&a!=0){
            check = 0;
        }
        Max = max(Max,a);
        data[a]++;
    }
    if(check==0){
        cout<<0<<endl;
    }else if(data[0]!=1){
        cout<<0<<endl;
    }else{
        ll ans = 1;
        rep(i,1,Max){
            ll kake = 1;
            rep(j,0,data[i+1]){
                kake*=data[i];
                kake %= 998244353;
            }
            //ll kake = pow(data[i],data[i+1]);
            //kake %= 998244353;
            ans *= kake;
            ans %= 998244353;
        }
        cout<<ans<<endl;
    }
    
    

    return 0;
}


Measured memory_bytes: 9684
#include<iostream>
#include<cstdio>
#include<vector>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<math.h>
#include<numeric>
#include<iomanip>

using namespace std;

typedef vector<int> vi;
typedef pair<int, int> pii;
typedef long long ll;
typedef vector<long long> vll;
typedef pair<long long, long long> pll;

const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main(){
	int x, y;
	cin >> x >> y;
	if (x == 1 || x == 3 || x == 5 || x == 7 || x == 8 || x == 10 || x == 12){
		if (y == 1 || y == 3 || y == 5 || y == 7 || y == 8 || y == 10 || y == 12){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	if (x == 4 || x == 6 || x == 9 || x == 11){
		if (y == 4 || y == 6 || y == 9 || y == 11){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	if (x == 2){
		if (y == 2){
			cout << "Yes" << endl;
		}
		else{
			cout << "No" << endl;
		}
	}
	return 0;
}


Measured memory_bytes: 256
#![allow(unused_parens)]
#![allow(unused_imports)]
#![allow(non_upper_case_globals)]
#![allow(non_snake_case)]
#![allow(unused_mut)]
#![allow(unused_variables)]
#![allow(dead_code)]

use itertools::Itertools;
use proconio::input;
use proconio::marker::{Chars, Usize1};

#[allow(unused_macros)]
#[cfg(debug_assertions)]
macro_rules! mydbg {
    //($arg:expr) => (dbg!($arg))
    //($arg:expr) => (println!("{:?}",$arg));
      ($($a:expr),*) => {
          eprintln!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
      }
}
#[cfg(not(debug_assertions))]
macro_rules! mydbg {
    ($($arg:expr),*) => {};
}

macro_rules! echo {
    ($($a:expr),*) => {
          $(println!("{}",$a))*
      }
}

use std::cmp::*;
use std::collections::*;
use std::ops::{Add, Div, Mul, Sub};

#[allow(dead_code)]
static INF_I64: i64 = 92233720368547758;
#[allow(dead_code)]
static INF_I32: i32 = 21474836;
#[allow(dead_code)]
static INF_USIZE: usize = 18446744073709551;
#[allow(dead_code)]
static M_O_D: usize = 1000000007;
#[allow(dead_code)]
static PAI: f64 = 3.1415926535897932;

trait IteratorExt: Iterator {
    fn toVec(self) -> Vec<Self::Item>;
}

impl<T: Iterator> IteratorExt for T {
    fn toVec(self) -> Vec<Self::Item> {
        self.collect()
    }
}

trait CharExt {
    fn toNum(&self) -> usize;
    fn toAlphabetIndex(&self) -> usize;
    fn toNumIndex(&self) -> usize;
}
impl CharExt for char {
    fn toNum(&self) -> usize {
        return *self as usize;
    }
    fn toAlphabetIndex(&self) -> usize {
        return self.toNum() - 'a' as usize;
    }
    fn toNumIndex(&self) -> usize {
        return self.toNum() - '0' as usize;
    }
}

trait VectorExt {
    fn joinToString(&self, s: &str) -> String;
}
impl<T: ToString> VectorExt for Vec<T> {
    fn joinToString(&self, s: &str) -> String {
        return self
            .iter()
            .map(|x| x.to_string())
            .collect::<Vec<_>>()
            .join(s);
    }
}

trait StringExt {
    fn get_reverse(&self) -> String;
}
impl StringExt for String {
    fn get_reverse(&self) -> String {
        self.chars().rev().collect::<String>()
    }
}

trait UsizeExt {
    fn pow(&self, n: usize) -> usize;
}
impl UsizeExt for usize {
    fn pow(&self, n: usize) -> usize {
        return ((*self as u64).pow(n as u32)) as usize;
    }
}

fn main() {
    input! {
       x:i64,
       N:usize,
       a:[i64;N],
    }

    mydbg!(a);
    let mut a2 = vec![];
    for i in 0..250 {
        a2.push(i * -1);
    }
    for i in 1..250 {
        if a.iter().position(|&x| x == i).is_none() {
            a2.push(i);
        }
    }
    mydbg!(a2);
    a2.reverse();

    let mut ans = INF_I64;
    let mut b = INF_I64;
    for &item in &a2 {
        if b >= (item - x).abs() {
            ans = item;
            b = (item - x).abs();
        }
    }
    mydbg!(b, ans);

    echo!(ans);
}


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

typedef long long int ll;
#define loop(i,s,e) for(ll i=s;i<e;i++)
#define test ll x;cin>>x;while(x--)
#define pb push_back
#define vec vector<ll>
#define sortvec(x) sort(x.begin(),x.end())
#define sz(x) x.size()

int main () {
	ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    ll n;
    cin>>n;
    ll a[n];
    ll x=0;
    loop(i,0,n)
    {
    	cin>>a[i];
    	x=x^a[i];
    }
    loop(i,0,n)
    {
    	ll y=x^a[i];
    	cout<<y<<" ";
    }

    cout<<"\n";
}

Measured memory_bytes: 5140
#include <iostream>
#include <vector>

using namespace std;

typedef long long ll;

int main(){
    ll n; string s;
    cin >> n >> s;
    vector<int> sum(n,0);
    if(s[0] == 'W') sum[0] = 1;
    for(int i = 1; i < n; i++){
        sum[i] = sum[i-1];
        if(s[i] == 'W'){
            sum[i]++;
        }
    }

    ll ans = n;
    for(int i = 0; i < n; i++){
        ll buf = (i == 0) ? 0 : sum[i-1];
        buf += (n-1-i-(sum[n-1] - sum[i]));
        ans = min(ans, buf);
    }
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1916
#include<bits/stdc++.h>
using namespace std;
#define MN 100000
#define MOD 1000000007
int a[MN+5],r[MN+5];
inline int inv(int x)
{
	int y=MOD-2,r=1;
	for(;y;y>>=1,x=1LL*x*x%MOD)if(y&1)r=1LL*r*x%MOD;
	return r; 
}
int main()
{
	int n,i,ans=0;
	scanf("%d",&n);
	for(i=1;i<=n;++i)scanf("%d",&a[i]);
	for(i=1;i<=n;++i)r[i]=(r[i-1]+inv(i))%MOD;
	for(i=1;i<=n;++i)ans=(ans+1LL*a[i]*(r[i]+r[n-i+1]-1))%MOD;
	for(i=1;i<=n;++i)ans=1LL*ans*i%MOD;
	printf("%d",ans); 
}

Measured memory_bytes: 1024
#include<iostream>
#include<string>
#include<algorithm>
using namespace std;
#define rep(i, a, b) for (int i = a; i < b; ++i)

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

for(int i=0;s[i];){
    cout<<s[i];
    i+=n;
}
cout<<endl;
return 0;
}

Measured memory_bytes: 256
#include <cstdio>

int main()
{
	int r,c;
	scanf("%d %d", &r, &c);

	int array[101][101] = {0};

	for (int i = 0; i < r; i++) {
		for (int j = 0; j < c; j++) {
			scanf("%d", &array[i][j]);
			array[i][c] += array[i][j];
			array[r][j] += array[i][j];
			array[r][c] += array[i][j];
		}
	}

	/* test */ 
	for (int i = 0; i <= r; i++) {
		for (int j = 0; j <= c; j++) {
			printf("%d", array[i][j]);
			if(j != c) printf(" ");
		}
		printf("\n");
	}
	
	return 0;
}


Measured memory_bytes: 2696
#include<iostream>
#include<algorithm>
#include<vector>

using namespace std;

typedef pair<int,int> P;
typedef pair<int,P> PP;
const int MAX = 20001;
bool infected[MAX];
int N,M;

void init(){
  fill(infected,infected+MAX,false);
  infected[1] = true;
}

int main(){
  
  while(cin >> N >> M && N+M){
    init();
    vector<PP> V;
    for(int i = 0; i < M; i++){
      PP pp;
      cin >> pp.first >> pp.second.first >> pp.second.second;
      V.push_back(pp);
    }
    sort(V.begin(),V.end());

    for(int i = 0; i < V.size(); i++){
      infected[V[i].second.second] = (infected[V[i].second.second]
				      ||infected[V[i].second.first]);
    }

    int ans = 0;
    for(int i = 1; i <= N; i++)
      if(infected[i]) ans++;
    cout << ans << endl;
  }
  return 0;
}

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

#define int             long long int
#define ld              long double
#define ff              first
#define ss              second
#define mp              make_pair
#define pb              push_back
#define endl            "\n"

#define si              set <int>
#define vi              vector <int>
#define pii             pair <int, int>
#define vpii            vector <pii>
#define mii             map <int, int>
#define que_max         priority_queue <int>
#define que_min         priority_queue <int, vi, greater<int>>

#define loop(i,s,e)     for(int i=s;i<e;i++)
#define rloop(i,e,s)    for(int i=e;i>=s;i--)
#define mset(a,f)       memset(a,f,sizeof(a))


#define M               1000000007
#define sz(x)           ((int) x.size())
#define all(p)          p.begin(), p.end()

#define bug(...)        __f (#__VA_ARGS__, __VA_ARGS__)
#define print(a)        for (auto x : a) cout << x << " "; cout << endl
#define Print(a,x,y)    for (int i=x; i<y; i++) cout<< a[i]<< " "; cout << endl

inline int power(int a, int b)
{
	int x = 1;
	while (b)
	{
		if (b & 1) x *= a;
		a *= a;
		b >>= 1;
	}
	return x;
}

template <typename Arg1>
void __f (const char* name, Arg1&& arg1) { cout << name << " : " << arg1 << endl; }
template <typename Arg1, typename... Args>
void __f (const char* names, Arg1&& arg1, Args&&... args)
{
	const char* comma = strchr (names + 1, ',');
	cout.write (names, comma - names) << " : " << arg1 << " | "; __f (comma + 1, args...);
}

const int N = 2e5 + 7;


void solve()
{
	int k; cin >> k;
	if (k < 9)cout << k;
	else
	{
		queue<string>q;
		loop(i, 1, 10) q.push(to_string(i));
		int cnt = 9;
		while (true)
		{
			string no = q.front();
			//bug(no);
			q.pop();
			char last = no.back();
			for (char ch = '0'; ch <= '9'; ch++)
			{
				if (abs(last - ch) <= 1)
				{
					//bug(last, ch);
					string temp = no;
					temp = temp + ch;
					//bug(no);
					cnt++;
					q.push(temp);
					if (cnt == k)
					{
						cout << temp ;
						return;
					}

				}
			}
		}
	}
	return;
}
int32_t main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);



	cout << setprecision(9) << fixed;

	int t = 1;
	//cin >> t;
	while (t--)
	{
		solve();
	}


	return 0;
}


Measured memory_bytes: 4864
using System;
using System.Collections;
using System.Collections.Generic;
using System.Linq;
using System.IO;
using System.Text;
using System.Globalization;
using System.Diagnostics;



class Myon
{
    public Myon() { }
    public static int Main()
    {
        new Myon().calc();
        return 0;
    }


    Scanner cin;

    void calc()
    {
        cin = new Scanner();
        int N = cin.nextInt();
        int now = 10;
        while(now < N) { now *= 10; }
        if(now == N)
        {
            Console.WriteLine(10);
            return;
        }
        int ans = 0;
        while(N > 0)
        {
            ans += N % 10;
            N /= 10;
        }

        Console.WriteLine(ans);
    }
}






class Scanner
{
    string[] s;
    int i;

    char[] cs = new char[] { ' ' };

    public Scanner()
    {
        s = new string[0];
        i = 0;
    }

    public string next()
    {
        if (i < s.Length) return s[i++];
        string st = Console.ReadLine();
        while (st == "") st = Console.ReadLine();
        s = st.Split(cs, StringSplitOptions.RemoveEmptyEntries);
        if (s.Length == 0) return next();
        i = 0;
        return s[i++];
    }

    public int nextInt()
    {
        return int.Parse(next());
    }
    public int[] ArrayInt(int N, int add = 0)
    {
        int[] Array = new int[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextInt() + add;
        }
        return Array;
    }

    public long nextLong()
    {
        return long.Parse(next());
    }

    public long[] ArrayLong(int N, long add = 0)
    {
        long[] Array = new long[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextLong() + add;
        }
        return Array;
    }

    public double nextDouble()
    {
        return double.Parse(next());
    }


    public double[] ArrayDouble(int N, double add = 0)
    {
        double[] Array = new double[N];
        for (int i = 0; i < N; i++)
        {
            Array[i] = nextDouble() + add;
        }
        return Array;
    }
}


Measured memory_bytes: 11092
#include<bits/stdc++.h> 
using namespace std;
using ll=long long;
typedef pair<int,int> P;
typedef tuple<ll,int,int> T;
#define fi first
#define se second
#define all(v) (v).begin(),v.end()
const ll mod=1000000007;
const ll mod2=998244353;
const ll inf=100000000000000000;
ll gcd(ll a,ll b) {return b ? gcd(b,a%b):a;}
ll lcm(ll c,ll d){return c/gcd(c,d)*d;}
vector<int> dy={-1,0,1,0},dx={0,-1,0,1};
int main(){
  ios_base::sync_with_stdio(false);
  cin.tie(NULL);
  ll n,z,w; 
  cin>>n>>z>>w;
  vector<ll> a(n);
  for(int i=0;i<n;i++)cin>>a[i];
  if(n==1)cout<<abs(a[0]-w)<<endl;
  else cout<<max(abs(w-a[n-1]),abs(a[n-2]-a[n-1]))<<endl;
}

Measured memory_bytes: 256
N = int(input())
As = [int(s) for s in input().split()]

As.sort()
As.reverse()

ans = As[0]

idx = (N-2) // 2
ans += sum(As[1:1+idx]) * 2
if (N-2)%2 == 1:
    ans += As[1+idx]

print(ans)


Measured memory_bytes: 31564
#include<iostream>
#include<cstring>
#include<cstdio>

using namespace std;

const int L = 30;

int a[L], n;

int f[L];

int main()
{
	scanf("%d", &n);
	for (int s = 0; s < n; s++) scanf("%d", &a[s]);
	int ans = 1, m = a[0];
	for (int s = 1; s < n; s++)
		if (a[s] >= m)
		{
			m = a[s];
			ans++;
		}
	printf("%d", ans);
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using ll = long long;
using namespace std;
const long long INF = 1LL << 60;
ll mod = 1e9 + 7;

int main()
{
    int n;
    cin >> n;
    vector<ll> a(n);
    rep(i, n) cin >> a[i];
    ll min = INF;
    for (ll i = -100; i <= 100; i++)
    {
        ll sum = 0;
        rep(j, n)
        {
            sum += (a[j] - i) * (a[j] - i);
        }
        if (sum < min)
            min = sum;
    }
    cout << min << endl;
    return 0;
}


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

int main() {
  int n, m;
  cin >> n >> m;
  vector<int> t(n, 0);
  for(int i=0; i<m; i++) {
    int a, b;
    cin >> a >> b;
    t.at(a-1)++;
    t.at(b-1)++;
  }
  for(int x : t) {
    cout << x << endl;
  }
}

Measured memory_bytes: 384
// Etavioxy
#include<cstdio>
#include<cctype>
#include<cstring>
#include<algorithm>
#include<functional>
#include<cmath>
#define il inline
#define ll long long
#define rep(i,s,t) for(register int i=(s);i<=(t);i++)
#define rev_rep(i,s,t) for(register int i=(s);i>=(t);i--)
#define each(i,u) for(int i=head[u];i;i=bow[i].nxt)
#define file(s) freopen(s".in" ,"r",stdin),freopen(s".out","w",stdout)
#define pt(x) putchar(x)
using namespace std;
il int ci(){
	register char ch;int f=1;
	while(!isdigit(ch=getchar()))f=ch=='-'?-1:1;
	register int x=ch^'0';
	while(isdigit(ch=getchar()))x=(x*10)+(ch^'0');
	return f*x;
}


enum{N=100023};
int a[N],b[N];
ll n,m,v,p;

bool chk(int w){
//	printf("chk %d :\n",w);
	int tot = 0;
	ll x= a[w]+m;
	rep(i,p,n) if( i!=w ) b[++tot]= a[i];
	ll sum= 0;
	rep(i,1,tot){
		if( b[i]>x ) return 0;
		sum+= min(m,x-b[i]);
	}
//	printf("%lld >= %lld\n",sum,m*(v-p));
	return sum >= m*(v-p);
}

int main(){
	n=ci(), m=ci(), v=ci(), p=ci();
	rep(i,1,n) a[i]=ci();
	sort(a+1,a+n+1,greater<int>());
	int l, r=n;
	rep(i,p,n) if( a[i+1]<a[p] ){
		l=i; break;
	}
	while( l<r ){
//		printf("[%d %d]\n",l,r);
		int w= (l+r+1)/2;
		if( chk(w) ) l=w;
		else r=w-1;
	}
	printf("%d\n",l);
	return 0;
}
/*
4 2 3 2
2 3 3 6
*/


Measured memory_bytes: 896
#!/usr/bin/env python
S = input()
a = int(S[:2])
b = int(S[2:])
if a > 0 and a <= 12:
    if b > 0 and b <= 12:
        print('AMBIGUOUS')
    else:
        print('MMYY')
else:
    if b > 0 and b <= 12:
        print('YYMM')
    else:
        print('NA')

Measured memory_bytes: 3060
n = int(input())
build = [[[0] * 10 for i in range(3)] for j in range(4)]

for i in range(n):
    b, f, r, v = map(int, input().split())
    build[b - 1][f - 1][r - 1] = build[b - 1][f - 1][r - 1] + v

for i in range(4):
    for j in range(3):
        print(' ', end='')
        print(' '.join(map(str, (build[i][j]))))
    if i != 3: print('#' * 20)


Measured memory_bytes: 5608
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int N = sc.nextInt();
		String name = null;
		if(N <= 999){
			name = "ABC";
		}else{
			name = "ABD";
		}
		System.out.println(name);
	}
}


Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
#define rep(i,N) for(ll (i)=0;(i)<(N);(i)++)
const int mod = 1000000007;

ll dp[55][2];
int main(){
  ll n, k;
  cin >> n >> k;
  vector<ll> a(n);
  rep(i, n) {
    cin >> a[i];
  }
  vector<ll> cnt(50);

  for(int i = 0; i < n; ++i) {
    for(int j = 0; j < 50; ++j) {
      cnt[j] += (a[i]>>j)&1;
    }
  }
  rep(i, 55) {
    rep(j, 2) dp[i][j] = -1;
  }
  dp[50][0] = 0;
  
  for (int i = 49; i >= 0; --i) {
    ll t = 1LL << i;

    ll score0 = cnt[i] * t;
    ll score1 = (n - cnt[i]) * t;

    if(dp[i + 1][1] != -1) {
      dp[i][1] = max(dp[i][1], dp[i + 1][1] + max(score0, score1));
    }
    if(dp[i + 1][0] != -1) {
      if(k & t) {
        dp[i][1] = max(dp[i][1], dp[i + 1][0] + score0);
        dp[i][0] = max(dp[i][0], dp[i + 1][0] + score1);
      } else {
        dp[i][0] = max(dp[i][0], dp[i + 1][0] + score0);
      }
    }
  }
  cout << max(dp[0][0], dp[0][1]) << endl;
  
}

Measured memory_bytes: 1024
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		// TODO Auto-generated method stub
		Scanner sc = new Scanner(System.in);

		int a = sc.nextInt();
		int b = sc.nextInt();
		int c = sc.nextInt();
		int d = sc.nextInt();

		System.out.println(Math.min(a, b) + Math.min(c, d));
	}

}


Measured memory_bytes: 22740
#include<bits/stdc++.h>
#define ll long long
#define ull unsigned long long
#define IO ios::sync_with_stdio(false), cin.tie(0)
#define endl '\n'
#define main() int main()
#define ff1(i,n) for(int i=1;i<=n;++i)
#define ff0(i,n) for(int i=0;i<n;++i)
#define pi acos(-1.0)
#define ms(a, x) memset(a, x, sizeof(a))
#define lowbit(x) ((x)&(-(x)))
#define pb push_back
#define binarycount __builtin_popcount(x)
#define tr t[root]
#define lson t[root << 1]
#define rson t[root << 1 | 1]
#define fir first
#define sec second
#define debug(x) cout<<x<<'\n'
#define sa(a) scanf("%d", &a)
#define sab(a, b) scanf("%d%d", &a, &b)
#define pa(a) printf("%d",a)
#define pab(a,b) printf("%d%d",a,b)
#define pii pair<string,int>
using namespace std;
#define maxn 1005
const int inf = 0x3f3f3f3f;
const int mod = 1e9+7;
const double eps = 1e-8;
ll gcd(ll a, ll b) {return b==0?a:gcd(b, a%b);}
ll lcm(ll a, ll b) {return a/gcd(a, b)*b;}
int max(int x,int y){if(x>y) return x;return y;}
ll powmod(ll a,ll b){
    ull ans = 1, pow = a%mod;
    while(b) { if(b&1) ans = (ans*pow)%mod; pow = (pow*pow)%mod; b >>= 1; }
    return ans%mod;
}

int n,m;
char mp[maxn][maxn];
int dp[maxn][maxn];
main()
{
	IO;
	cin>>n>>m;
	ms(dp,0);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
		 cin>>mp[i][j];
		 
	for(int i=1;i<=n;i++){
		if(mp[i][1]=='#')break;
		dp[i][1]=1;
	}	 
	for(int i=1;i<=m;i++){
		if(mp[1][i]=='#')break;
		dp[1][i]=1;
	}
	for(int i=2;i<=n;i++)
	{
		for(int j=2;j<=m;j++)
		{
			if(mp[i][j]=='#')continue;
			if(mp[i-1][j]!='#'){
				dp[i][j]=(dp[i][j]+dp[i-1][j])%mod;
			}
			if(mp[i][j-1]!='#'){
				dp[i][j]=(dp[i][j]+dp[i][j-1])%mod;
			}
		}
	}

	cout<<dp[n][m]%mod<<endl;
	
}


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

int main() {
  string	S;
  int	i, l, ll;
  // char b;
  //  int N, K, KK, x, s=0;
  cin >> S;
  for ( i=l=ll=0; i<S.size(); i++) {
    if ( (S.at(i) == 'A') 
        || (S.at(i) == 'G')
        || (S.at(i) == 'C' )
        || (S.at(i) == 'T' ) ) {
      l++;
    } else {
      if ( l>ll ) ll=l;
      l=0;
    }
  }
  if (l>ll) cout << l;
  else cout << ll;
  cout << endl;
}


Measured memory_bytes: 256
N = int(input())
T = [int(i) for i in input().split()]
V = [int(i) for i in input().split()]

T_p = [0,0]
temp = 0
for tt in T:
    temp += tt
    T_p.append(temp)
T_p.append(temp)

Tmax = temp

def vv(i,tt):
    a = T_p[i]
    b = T_p[i + 1]
    if i == 0 or i == N + 1:
        vmax = 0
    else:
        vmax = V[i - 1]
    
    if tt >= b:
        res = tt - b + vmax
    elif tt <= a:
        res = a - tt + vmax
    else:
        res = vmax

    return res

mints = [min([vv(i, tt/2) for i in range(N + 2)]) for tt in range(2 * Tmax + 1)]

res = 0
for i in range(len(mints) -1 ):
    res += (mints[i] + mints[i + 1])/4

print(res)



Measured memory_bytes: 46172
#include <bits/stdc++.h>
#define F first
#define S second
#define pii pair<int, int>
#define pb push_back

using namespace std;

typedef long long ll;
typedef long double ld;

 const int N = 1e5 + 10;

int n, A, B, h[N];

ll ceil(ll x, ll y){
	if(x <= 0)return 0;
	return (x + y - 1)/y;
}

bool check(int t){
	ll need = 0;
	for(int i=0; i<n; i++){
		ll xi =  ceil(h[i] - 1LL * t * B, A - B);
		need += xi;
	}
	return need <= t;
}

int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n >> A >> B;
	for(int i=0; i<n; i++)
		cin >> h[i];

	int lo = 0, hi = 1e9 + 10;
	while(hi - lo > 1){
		int mid = (lo + hi)/2;
		if(check(mid))hi = mid;
		else lo = mid;
	}
	cout << hi << endl;
	
}


Measured memory_bytes: 640
#include<iostream>

int main() 
{
    std::string S, T;
    std::cin >> S;
    std::cin >> T;

    //ここからコードを書く
    std::string s_cnt, t_cnt;
    std::string s_alt, t_alt; //S,Tを置換したもの。これを比較して結果を出す
    int s_count = 0;
    int t_count = 0;
    
    for (int i = 0; i < S.size(); ++i) {
        int buffer = 0;
        for (buffer; buffer < s_count; ++buffer) {
            if (s_cnt[buffer] == S[i]) { break;}
        }  //もし以前に同じ文字がなかったらbuffer == s_countになるはず
        if (buffer == s_count) {
            s_cnt += S[i]; ++s_count;
        }

        s_alt += std::to_string(buffer);
    }


    for (int i = 0; i < T.size(); ++i) {
        int buffer = 0;
        for (buffer; buffer < t_count; ++buffer) {
            if (t_cnt[buffer] == T[i]) { break;}
        }  //もし以前に同じ文字がなかったらbuffer == t_countになるはず
        if (buffer == t_count) {
            t_cnt += T[i]; ++t_count;
        }

        t_alt += std::to_string(buffer);
    }

    //デバッグ用
    //std::cout << s_cnt << '\n';
    //std::cout << t_cnt << '\n';
    //std::cout << s_alt << '\n';
    //std::cout << t_alt << '\n';

    if(s_alt == t_alt) {
        std::cout << "Yes" << '\n';
    } else {
        std::cout << "No" << '\n';
    }

    return 0;

}

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

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

int dp[100];

//最大公約数
int gcd(int x, int y){
  if(x % y == 0) return y;
  return gcd(y, x % y);
}
//最小公倍数
int lcm(int x, int y){
  return x * y / gcd(x, y);
}
//フィボナッチ数列
//配列dpを-1で初期化する
int fib(int n){
  if(n == 0 || n == 1) return dp[n] = 1;
  if(dp[n] != -1) return dp[n];
  return dp[n] = fib(n - 1) + fib(n - 2);
}
//階乗計算(factorial)
int fact(int n){
  if(n = 1) return 1;
  return n * fact(n - 1);
}
//累乗計算(Exponentiation)
//x**y
ll expo(int x, int y){
  ll ans = 1;
  rep(i, y){
    ans *= x;
  }
  return ans;
}
//桁数
int keta(ll x){
  if(x == 0) return 1;
  int res = 0;
  while(x){
    x /= 10;
    res++;
  }
  return res;
}


int main(){
  int S;
  cin >> S;
  int h = S / 3600;
  int m = S / 60 - h * 60;
  int s = S % 60;
  printf("%d:%d:%d\n", h, m, s);
}





Measured memory_bytes: 3196
#include <bits/stdc++.h>
#define int long long
using namespace std;
using P = pair<double, int>;
const int INF = 1LL<<60;
const int MOD = (int)1e9 + 7;


signed main() {
    ios::sync_with_stdio(false);
    cin.tie(nullptr);
    map<string, int> s;
    s["SUN"] = 0;
    s["MON"] = 1;
    s["TUE"] = 2;
    s["WED"] = 3;
    s["THU"] = 4;
    s["FRI"] = 5;
    s["SAT"] = 6;
    string t;
    cin >> t;
    cout << 7 - s[t] << "\n";
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <algorithm>
#include <set>
#include <iomanip>
#include <cmath>

#define vi vector<int>
#define tests int t; cin>>t; while(t--)
#define ll long long
#define vll vector<long long>

using namespace std;

char nums[10] = { '0','1','2','3','4','5','6','7','8','9' };
char alphsl[26] = { 'A','B','C','D','E','F','G','H','I','J','K','L','M','N','O','P','Q','R','S','T','U','V','W','X','Y','Z' };

using namespace std;

void solve() {

	int n;
	cin >> n;
	vi v(n);
	for (auto& x : v) cin >> x;
	ll cnt = 0;
	for (int i = 0; i < n-2; i++) {
		for (int j = i + 1; j < n - 1; j++) {
			for (int k = j + 1; k < n; k++) {
				if (v[i] != v[j] && v[i] != v[k] && v[j] != v[k] && (v[i] + v[j] > v[k]) && (v[j] + v[k] > v[i]) && (v[i] + v[k] > v[j])) cnt++;
			}
		}
	}

	cout << cnt << endl;
}

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



Measured memory_bytes: 3596
N = int(input())
x = 0
u = 0
Y = 0
for i in range(N):
    str = input().split(' ')

    x = float(str[0])
    u = str[1]
    if u == 'JPY':
        Y += x
    else:
        Y += x * 380000.0
print(Y)

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

#define rep(i, n) REP(i, 0, n)
#define repr(i, n) for (int i = (n); i >= 0; i--)
#define ALL(v) v.begin(), v.end()
#define MSG(a) cout << #a << " " << a << endl;
#define REP(i, x, n) for (int i = x; i < n; i++)
#define OP(m) cout << m << endl
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

int main()
{
    ll n, m;
    cin >> n >> m;
    ll sum = 0;
    rep(i, m)
    {
        ll a;
        cin >> a;
        sum += a;
    }
    if (n - sum < 0)
    {
        OP(-1);
    }
    else
    {
        OP(n - sum);
    }
    return 0;
}

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

using namespace std;
using ll = long long;
#define int ll
using VI = vector<int>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template <typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }

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

string s[105];
VI rec[40010];
signed main(void)
{
  cin.tie(0);
  ios::sync_with_stdio(false);

  while(true) {
    int h, w, l;
    cin >> h >> w >> l;
    if(!h && !w && !l) return 0;
    REP(i, h) cin >> s[i];

    // スタート地点
    int x=-1, y=-1, dir=-1;
    REP(i, h) REP(j, w) {
      if(s[i][j]=='N') {
        y=i, x=j, dir=0;
      } else if(s[i][j]=='E') {
        y=i, x=j, dir=1;
      } else if(s[i][j]=='S') {
        y=i, x=j, dir=2;
      } else if(s[i][j]=='W') {
        y=i, x=j, dir=3;
      }
    }
    assert(x!=-1&&y!=-1&&dir!=-1);

    // シミュレーション
    int cnt = 0, r = 0, loop = 0;
    map<VI, int> mp;
    while(true) {
      while(true) {
        int nx = x+dx[dir], ny = y+dy[dir];
        if(IN(0LL, w, nx) && IN(0LL, h, ny) && s[ny][nx]!='#') break;
        dir=(dir+1)%4;
      }
      if(mp.find({x,y,dir}) != mp.end()) {
        r = mp[{x,y,dir}];
        loop = cnt - r;
        break;
      }
      mp[{x,y,dir}] = cnt;
      rec[cnt++] = {x,y,dir};
      x += dx[dir], y += dy[dir];
    }

    // 答えを求める
    char c[] = {'N', 'E', 'S', 'W'};
    if(l-r+1 <= 0) {
      // rec[l] が答え
      cout << rec[l][1]+1 << " " << rec[l][0]+1 << " " << c[rec[l-1][2]] << endl;
    } else {
      int tmp = (l-r)%loop;
      // rec[r+tmp] が答え
      cout << rec[r+tmp][1]+1 << " " << rec[r+tmp][0]+1 << " " << c[rec[r+(tmp-1+loop)%loop][2]] << endl;
    }
  }

  return 0;
}



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

#define REP(i, n) for(int i = 0; i < n; ++i)
#define REPR(i, n) for(int i = n; i >= 0; --i)
#define FOR(i, m, n) for(int i = m; i < n; ++i)
#define FORR(i, m, n) for(int i = m; i >= n; --i)
#define SORT(v, n) sort(v, v+n);
#define VSORT(v) sort(v.begin(), v.end());
#define llong long long
#define pb(a) push_back(a)

#define INF 999999999

using namespace std;

typedef pair<int, int> P;
typedef pair<llong, llong> LP;
typedef pair<int, P> PP;
typedef pair<llong, LP> LPP;

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

int main(){
    cin.tie(0); //cinとcoutの同期切り
    ios::sync_with_stdio(false); //iostreamとstdioの同期切り

    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if(abs(c - a) <= d || (abs(b - a) <= d && abs(c - b) <= d)) cout << "Yes" << endl;
    else cout << "No" << endl;

    return 0;
}

/*****************************************************************************/
/*****   1秒間で処理できるfor文ループの回数                                 *****/
/*****   → 10^8 = 100,000,000 回程度                                      *****/
/*****                                                                   *****/
/*****   sort(a, a+N, greater<int>()); // a[0:N) を大きい順にソート        *****/
/*****                                                                   *****/
/*****                                                                   *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3"                *****/
/*****   std::cout << std::fixed;                                        *****/
/*****   std::cout << std::setprecision(2) << 3.0; // "3.00"             *****/
/*****                                                                   *****/
/*****************************************************************************/

Measured memory_bytes: 256
import os
import sys
import math
import heapq
from decimal import *
from io import BytesIO, IOBase
from collections import defaultdict, deque

def r():
    return int(input())
def rm():
    return map(int,input().split())
def rl():
    return list(map(int,input().split()))

mod=1000000007
n = r()
a = rl()
b = [a[-1]]
for i in range(n-2,-1,-1):
    b.append(b[-1]+a[i])
b = b[::-1]
ans = 0
for i in range(n-1):
    ans= (ans+(a[i]*b[i+1])%mod)%mod
print(ans)

Measured memory_bytes: 111556
#include <iostream>
#include <vector>
#include <array>
#include <deque>
#include <stack>
#include <queue>
#include <list>
#include <map>
#include <set>
#include <algorithm>
#include <numeric>
#include <utility>
#include <cmath>

using namespace std;
using ll=long long int;

int dp[10001][2];
const int cost[] = {0, 2, 5, 5, 4, 5, 6, 3, 7, 6};

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

    vector<int> u(m);
    for (auto &a: u) cin >> a;
    sort(u.begin(), u.end());

    for (auto &&a: u) {
        dp[cost[a]][0] = 1;
        dp[cost[a]][1] = a;
    }

    for (int i = 2; i <= n; ++i) {
        for (auto &&a: u) {
            if (i < cost[a]) continue;
            if (dp[i-cost[a]][1] == 0) continue;
            if (dp[i][0] <= dp[i-cost[a]][0]+1) {
                dp[i][0] = dp[i-cost[a]][0]+1;
                dp[i][1] = a;
            }
        }
    }

    int i = n;
    while (i > 0) {
        cout << dp[i][1];
        i -= cost[dp[i][1]];
    }
    cout << endl;

    return 0;
}


Measured memory_bytes: 384
#include <bits/stdc++.h>
#define endl "\n"
#define ll long long int
#define pii pair<int,int>
#define pll pair<long long, long long>
#define inf 1000000000000000001;
#define all(c) c.begin(),c.end()
#define mp(x,y) make_pair(x,y)
#define mem(a,val) memset(a,val,sizeof(a))
#define eb emplace_back
#define f first
#define s second
#define MAXN 10000057
#define mod 998244353
#define fr(i, s, e, st) for(ll (i) = (s); (i) < (e); (i) += (st))
#define fre(i, s, e, st) for(ll (i) = (s); (i) <= (e); (i) += (st))
#define fastio ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);cout<<fixed;cout<<setprecision(10);

using namespace std;

bool isPalindrome(string str, ll l, ll h) 
{ 
  
    // Keep comparing characters while they are same 
    while (h > l) 
    { 
        if (str[l++] != str[h--]) 
        { 
            return false; 
        } 
    } 
    return true;
} 

int main()
{
    fastio;
    ll T = 1;
    //cin >> T;
    while (T--)
    {
        string s;
        cin>>s;
        ll n = s.length();
        if(isPalindrome(s, 0, n-1) && isPalindrome(s, 0, (n-1)/2 - 1) && isPalindrome(s, (n+3)/2 - 1, n-1))
            cout<<"Yes"<<endl;
        else
            cout<<"No"<<endl;
    }
    return 0;
}

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

using ll = long long;
using pii = pair<ll, ll>;
using vi = vector<ll>;
using vvi = vector<vi>;

template <class T>
using max_heap = priority_queue<T>;
template <class T>
using min_heap = priority_queue<T, vector<T>, greater<T>>;

template <class T, class U>
void chmax(T &a, U b) {
    if (a < b) a = b;
}
template <class T, class U>
void chmin(T &a, U b) {
    if (b < a) a = b;
}

#define rep(i, j) for (int i = 0; i < j; i++)
#define all(obj) (obj).begin(), (obj).end()
#define rall(obj) (obj).rbegin(), (obj).rend()
#define debug(x) cerr << #x << ": " << x << endl;
#define int ll

const ll mod = 1e9 + 7;
const ll inf = (1LL << 50);

void solve(long long N) {

    cout << (N + 1) / 2 << endl;
}
signed main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    long long N;
    scanf("%lld", &N);
    solve(N);
    return 0;
}


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

#define F first
#define S second
#define MP make_pair
#define PB push_back

using namespace std;

typedef long long ll;
typedef long double ld;
typedef pair < int, int > pii;
typedef pair < ll, ll > pll;
typedef vector < ll > vl;

const int MAXN = 405;
const int INF = 0x3f3f3f3f;
const int MOD = 1e9 + 7;
const int LOG = 18;
const double EPS = 1e-9;
const double PI = 3.1415926535;

ll dp[MAXN][MAXN];
ll slime[MAXN];
ll prefix[MAXN];

void preprocess(int N) {
    memset(dp, INF, sizeof(dp));
    for(int i = 0; i < N; i++)
        dp[i][i] = 0;

    prefix[0] = 0;
    for(int i = 1; i <= N; i++)
        prefix[i] = prefix[i - 1] + slime[i - 1];
}

int main() {
    int N;

    cin >> N;
    for(int i = 0; i < N; i++)
        cin >> slime[i];

    preprocess(N);
    for(int len = 2; len <= N; len++) {
        for(int l = 0; l <= N - len; l++) {
            int r = l + len - 1;
            for(int k = l; k <= r - 1; k++)
                dp[l][r] = min(dp[l][r], dp[l][k] + dp[k + 1][r]);
            dp[l][r] += prefix[r + 1] - prefix[l];
        }
    }

    cout << dp[0][N - 1] << endl;

    return 0;
}



Measured memory_bytes: 1536
import sys

read = sys.stdin.read
readline = sys.stdin.readline
readlines = sys.stdin.readlines
sys.setrecursionlimit(10 ** 9)
INF = 1 << 60
MOD = 1000000007


def main():
    N = int(readline())

    amt = [1]
    a = 6
    while a <= N:
        amt.append(a)
        a *= 6
    a = 9
    while a <= N:
        amt.append(a)
        a *= 9

    dp = [INF] * (N + 1)
    dp[0] = 0
    for i in range(1, N + 1):
        for a in amt:
            if i >= a and dp[i] > dp[i - a]:
                dp[i] = dp[i - a] + 1

    print(dp[N])

    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 9448
// dfmt off
T lread(T=long)(){return readln.chomp.to!T;}T[] lreads(T=long)(long n){return iota(n).map!((_)=>lread!T).array;}
T[] aryread(T=long)(){return readln.split.to!(T[]);}void arywrite(T)(T a){a.map!text.join(' ').writeln;}
void scan(L...)(ref L A){auto l=readln.split;foreach(i,T;L){A[i]=l[i].to!T;}}alias sread=()=>readln.chomp();
void dprint(L...)(lazy L A){debug{auto l=new string[](L.length);static foreach(i,a;A)l[i]=a.text;arywrite(l);}}
static immutable MOD=10^^9+7;alias PQueue(T,alias l="b<a")=BinaryHeap!(Array!T,l);import std, core.bitop;
// dfmt on

void main()
{
    long N = lread();
    auto A = aryread();
    long s = A.sum();
    long t;
    long ans = long.max;
    foreach (i; 0 .. N - 1)
    {
        t += A[i];
        ans = ans.min(abs((s - t) - t));
    }
    writeln(ans);
}


Measured memory_bytes: 12516
n = int(input())
c = {
    'S': [0]*13,
    'H': [0]*13,
    'C': [0]*13,
    'D': [0]*13
}
for i in range(n):
    chara, number = input().split()
    c[chara][int(number) - 1] = 1

for i in ["S", "H", "C", "D"]:
    for j in range(13):
        if c[i][j] == 0:
            print("{0} {1}".format(i, j+1))



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

using namespace std;
using ll = long long;
using vec = vector<ll>;
using mat = vector<vec>;
using pll = pair<ll,ll>;

#define INF (1LL << 60)
#define MOD 1000000007
#define PI 3.14159265358979323846

#define REP(i,m,n) for(ll (i)=(m),(i_len)=(n);(i)<(i_len);++(i))
#define FORR(i,v) for(auto (i):v)
#define ALL(x) (x).begin(), (x).end()
#define PR(x) cout << (x) << endl
#define PS(x) cout << (x) << " "
#define SZ(x) ((ll)(x).size())
#define MAX(a,b) (((a)>(b))?(a):(b))
#define MIN(a,b) (((a)<(b))?(a):(b))
#define REV(x) reverse(ALL((x)))
#define ASC(x) sort(ALL((x)))
#define DESC(x) ASC((x)); REV((x))
#define pb push_back
#define eb emplace_back

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

    ll p = 1;
    REP(i,1,N+1) p = (p * i) % MOD;
    PR(p);

    return 0;
}

/*



*/

Measured memory_bytes: 3544
var R = mutableListOf<String>()
fun main(args: Array<String>) {
    val (N, M) = listOfLong()
    val A = listOfLong().map { it / 2 }
    var s = A[0]
    for (n in 1 until N.toInt()) {
        s = lcm(s, A[n])
    }
    if (A.any { (s / it) % 2 == 0L }) {
        println(0)
        return
    }
    var ans = 0L
    var S = s
    while (S <= M) {
        ans += 1
        S += s * 2
    }
    println(ans)
}
fun next() = readLine()!!
fun listOfString() = next().split(" ")
fun listOfLong(delta: Long = 0L) = listOfString().map { java.lang.Long.parseLong(it) + delta }
fun gcd(a: Long, b: Long): Long = if (a % b == 0L) b else gcd(b, a % b)
fun lcm(a: Long, b: Long): Long = a / gcd(a, b) * b

Measured memory_bytes: 58024
#include<iostream>
#include<cstring>
#include<cstdio>
using namespace std;

#define REP(i,a,b) for(i=a; i<b; ++i)
#define rep(i,n) REP(i,0,n)

double dp[102][102][2];
char board[102];

int main() {
  int n,t,b,l,i,j,x;
  while(cin>>n>>t>>l>>b, n|t|l|b) {
    memset(board, 0, sizeof(board));
    rep(i,102) rep(j,102) dp[i][j][0] = dp[i][j][1] = 0.0;
    dp[0][0][0] = 1.0;

    rep(i,l) {
      cin>>x;
      board[x] = 'L';
    }
    rep(i,b) {
      cin>>x;
      board[x] = 'B';
    }

    REP(i,0,t+1) {
      rep(j,n) {
	if(dp[i][j][0] > 0.0) {
	  for(int k=1; k<=6; ++k) {
	    int next = j+k;
	    if(next > n) {
	      //cout<<next<<" "<<n<<" ";
	      next = n - (next - n);
	      //cout<<next<<endl;
	    }
	    if(board[next] == 'B') {
	      dp[i+1][0][0] += dp[i][j][0]/6.0;
	    }else if(board[next] == 'L') {
	      dp[i+1][next][1] += dp[i][j][0]/6.0;
	    }else{
	      dp[i+1][next][0] += dp[i][j][0]/6.0;
	    }
	  }
	}
	if(dp[i][j][1] > 0.0) dp[i+1][j][0] += dp[i][j][1];
      }
    }
    //rep(i,n+1) cout<<dp[t][i]<<" ";
    //cout<<endl;
    double ans = 0.0;
    rep(i,t+1) ans += dp[i][n][0];
    printf("%.6f\n", ans);
  }
}

Measured memory_bytes: 0