akhauriyash/Code-Regression huggingface dataset:
import java.io.*;
import java.util.*;
import java.lang.*;

public class Main {
    public static MyScanner scan;
    public static PrintWriter out;
    public static void main(String[] args) {
        scan=new MyScanner();
        out=new PrintWriter(new BufferedOutputStream(System.out));

        int t=1;
//        int t=scan.nextInt();
        while(t-->0) {

            int n=scan.nextInt();
            long mod=1000000007,ans=0;

            long[] a=new long[n],b=new long[n];
            for(int i=0;i<n;i++) a[i]=scan.nextLong();
            b[0]=a[n-1];
            b[0]%=mod;
            for(int i=1;i<n;i++) {
                b[i]=b[i-1]+a[n-i-1];
                b[i]%=mod;
            }

            for(int i=0;i<n-1;i++) {
                ans+=(b[n-i-2]*a[i]);
                ans%=mod;
            } out.println(ans);
        }
        out.close();
    }

//    int n=scan.nextInt();
//    long[] a=new long[n];
//    long ans=0,mod=1000000007,sum=0;
//            for(int i=0;i<n;i++) {
//        a[i]=scan.nextLong();
//        sum+=a[i];
//        sum%=mod;
//    }
//
//            for(int i=0;i<n;i++) {
//        sum-=a[i];
//        ans+=(sum*a[i]);
//        ans%=mod;
//    } out.println(ans);

    //scanner
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }

        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }

        int nextInt() {
            return Integer.parseInt(next());
        }

        long nextLong() {
            return Long.parseLong(next());
        }

        double nextDouble() {
            return Double.parseDouble(next());
        }

        String nextLine() {
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
}

Measured memory_bytes: 57264
/*2019/10/19 */
/*template*/
#include<stdio.h>
#include<stdlib.h>
#include<math.h>
#include<string.h>
#define MOD 1000000007
#define MIN 999999999
#define MAX -999999999
typedef long long int ll;
typedef unsigned long long int ull;
void llswap(ll *x,ll *y){ll tmp;tmp=*x;*x=*y;*y=tmp;}
void swap(int *x,int *y){int tmp;tmp=*x;*x=*y;*y=tmp;}
int rmax(int x,int y){return x>y?x:y;}
int rmin(int x,int y){return x>y?y:x;}
ll llrmax(ll x,ll y){return x>y?x:y;}
ll llrmin(ll x,ll y){return x>y?y:x;}
int asc(const void *a,const void *b){if(*(int*)a < *(int*)b)return -1;else if(*(int*)a == *(int*)b)return 0;else return 1;}
int desc(const void *a,const void *b){if(*(int*)a < *(int*)b)return 1;else if(*(int*)a == *(int*)b)return 0;else return -1;}
int llasc(const void *a,const void *b){if(*(ll*)a < *(ll*)b)return -1;else if(*(ll*)a == *(ll*)b)return 0;else return 1;}
int lldesc(const void *a,const void *b){if(*(ll*)a < *(ll*)b)return 1;else if(*(ll*)a == *(ll*)b)return 0;else return -1;}
int gcd(int x,int y){if(y==0)return x;return gcd(y,x%y);}
 
//int asc_t(const void *a,const void *b){if(((pair_t*)a)->d < ((pair_t*)b)->d)return -1;else if(((pair_t*)a)->d == ((pair_t*)b)->d)return 0;else return 1;}
//int asc_t(const void *a,const void *b){if(((pair_t*)a)->d < ((pair_t*)b)->d)return 1;else if(((pair_t*)a)->d == ((pair_t*)b)->d)return 0;else return -1;}

int main(){
    int a,b;
    scanf("%d %d",&a,&b);
    int ans=a-2*b;
    if(ans<0){
        printf("0\n");
    }else{
        printf("%d\n",ans);
    }
    
    return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define debug(x)        cout<<#x<<" :"<<x<<endl;
#define ff              first
#define ar              array
#define ss              second
#define int             long long
#define pb              push_back
#define mp              make_pair
#define pii             pair<int,int>
#define vi              vector<int>
#define mii             map<int,int>
#define pqb             priority_queue<int>
#define pqs             priority_queue<int,vi,greater<int> >
#define setbits(x)      __builtin_popcountll(x)
#define zrobits(x)      __builtin_ctzll(x)
#define mod             1000000007
#define inf             1e18
#define ps(x,y)         fixed<<setprecision(y)<<x
#define mk(arr,n,type)  type *arr=new type[n];
#define w(x)            int x; cin>>x; while(x--)
#define f(i,n)          for(int i=0;i<n;i++)
#define MOD             1000000007
#define pi              3.14159265
#define umii            unordered_map<int,int>
#define umci            unordered_map<char,int>
#define umsi            unordered_map<string,int>

void k_007()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifndef ONLINE_JUDGE
	freopen("ip1.txt", "r", stdin);
	freopen("op1.txt", "w", stdout);
#endif
}
bool sortbysec(const pair<int, int> &a,
               const pair<int, int> &b);
int gcd(int a, int b) ;
int prime(int n);
int power(int x, int y);
int lcm(int a, int b);
int maxf(int a, int b) {if (a > b) return a; else return b;}
int diff(int a, int b) {return abs(a - b);}
int mul(int a, int b) { return (a * b) % mod; }
int32_t main()
{
	k_007();
	vi pf(1e6 + 2, 1);
	vi primes;
	pf[0] = 0;
	pf[1] = 0;
	for (int i = 2; i <= 1e6; ++i) {
		if (pf[i]) {
			primes.push_back(i);
			for (int j = i * i; j <= 1e6; j += i) pf[j] = 0;
		}
	}
	int a, b;
	cin >> a >> b;
	int val = gcd(a, b);
	int ans = 1;
	for (int i : primes)
	{
		if (val % i == 0) ans++;
		while (val % i == 0) val = val / i;
	}
	if (val != 1) ans++;

	cout << ans << endl;
}

bool sortbysec(const pair<int, int> &a, const pair<int, int> &b)
{
	return (a.second < b.second);
}
int gcd(int a, int b) {
	if (b == 0) return a;
	return gcd(b, a % b);
}
int prime(int n) {
	int flag = 1;
	for (int i = 2; i <= sqrt(n); i++) {
		if (n % i == 0) {flag = 0; break;}
	}
	return flag;
}
int power(int x, int y)
{
	if (y == 0)
		return 1;
	else if (y % 2 == 0)
		return ((power(x, y / 2) % MOD) * ( power(x, y / 2) % MOD)) % MOD;
	else
		return ((x % MOD) * (power(x, y / 2) % MOD) * (power(x, y / 2) % MOD)) % MOD;
}
int lcm(int a, int b)
{
	return (a * b) / gcd(a, b);
}

Measured memory_bytes: 12092
#include <bits/stdc++.h>
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define srep(i,s,t) for(int i = s; i < t; ++i)
#define drep(i,n) for(int i = (n)-1; i >= 0; --i)
using namespace std;
typedef long long int ll;
typedef pair<int,int> P;
#define yn {puts("Yes");}else{puts("No");}
#define MAX_N 200005
ll x[MAX_N] = {}, y[MAX_N] = {};
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    ll n, q;
    cin >> n >> q;
    ll ans = (n-2)*(n-2);
    srep(i,2,n){
        x[i] = n;
        y[i] = n;
    }
    ll xx = n;
    ll yy = n;
    rep(_,q){
        ll t, z;
        cin >> t >> z;
        if(t == 1){
            if(z < xx){
                ans -= yy - 2;
                srep(i,z,xx) x[i] = yy;
                xx = z;
            }else{
                ans -= x[z] - 2;
            }
        }else{
            if(z < yy){
                ans -= xx - 2;
                srep(i,z,yy) y[i] = xx;
                yy = z;
            }else{
                ans -= y[z] - 2;
            }
        }
    }
    cout << ans << endl;
    return 0;
}




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

int main(){
    int N;
    cin >> N;
    vector<int> L(N);
    rep(i,N){
        cin >> L[i];
    }
    int ans = 0;
    sort(L.begin(),L.end());
    for(int i=0;i<N-2;i++){
        for(int j=i+1;j<N-1;j++){
            int A,B,C;
            A = L[i];
            B = L[j];
            auto tmp = lower_bound(L.begin()+j+1,L.end(),L[i]+L[j]);
            auto tmp2 = L.end();
            ans += (N - j - 1) - (tmp2 - tmp);
        }
    }
    cout << ans << endl;
    return 0;
}

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

#define EPS 1e-6
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define llinf 0x3f3f3f3f3f3f3f3f

#define fi first
#define se second
#define pb push_back
#define ende '\n'

#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define mset(x, y) memset(&x, (y), sizeof(x))

using namespace std; 

using ll = long long;
using ii = pair<int,int>;

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

  int n; cin >> n;
  vector<int> v(n);
  for (auto &i : v) cin >> i;
  vector<int> u = v;
  sort(all(v));

  int cnt = 0;
  for (int i = 0; i < n; ++i)
    if (v[i] != u[i]) cnt++;
  if (cnt <= 2) cout << "YES" << ende;
  else cout << "NO" << ende;

  return 0;
}


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

#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;

template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

inline void fastio () {
	cin.tie(nullptr);
	ios::sync_with_stdio(false);
}

#define whats(x) cerr << #x << " = " << (x) << "\n"; 

using LL = long long;
using LD = long double;

const LL INF = LLONG_MAX;
const LL MOD = 998244353;
const LL N = 2e5+1;

int main() {
	fastio();

	LL n;
	cin >> n;

	if (n == 1) {
		cout << 0 << "\n";
	}
	else {
		LL cnt = 0;
		LL m = n;
		for (LL i = 2; i*i <= m; ++i) {
			if (m % i == 0) {
				LL cp = 0;
				while (m%i == 0) {
					m /= i;
					cp++;
				}
				LL tim = 1;
				//cout << cp << "?";
				while (cp > 0) {
					cp -= tim;
					tim++;
					if (cp >= 0) {
						cnt++;
					}
				}
			}
		}
		if (m > 1) {
			cnt++;
		}
		cout << cnt << "\n";
	}

}

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

using namespace std;

int main(){
    int N;
    int ans = 0;
    cin >> N;
    vector<int> h(N);
    for(int i=0;i<N;i++){
        cin >> h.at(i);
    }

    for(int i=0;i<N-1;i++){
        if(h.at(i)>h.at(i+1)) ans += h.at(i)-h.at(i+1);
    }
    ans += h.at(N-1);

    cout << ans << endl;
}


Measured memory_bytes: 256
#include <algorithm>
#include <cassert>
#include <climits>
#include <cmath>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <ctime>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <iterator>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <sstream>
#include <stack>
#include <string>
#include <vector>
//#include <regex>

/* g++ -g -std=c++0x */
/* g++ -g -std=c++11 */

using namespace std;

// std::ios::sync_with_stdio(false);

// freopen("input.txt", "rt", stdin);
// freopen("output.txt", "wt", stdout);

#define ALL(c)          (c).begin(), (c).end()
#define ALLR(c)         (c).rbegin(), (c).rend()
#define FOR(i,a,b)      for (int i=(a); i < (b); ++i)
#define FORR(i,a,b)     for (int i=(a); i > (b); --i)
#define FOR_ALL(i,c)    for (__typeof((c).begin()) i=(c).begin();   \
                             i != (c).end(); ++i)
#define FOR_ALLR(i,c)   for (__typeof((c).rbegin()) i=(c).rbegin(); \
                             i != (c).rend(); ++i)
#define SZ(array)       (sizeof(array)/sizeof(array[0]))
#define lc(x)           (x<<1)     /* 2*x */
#define rc(x)           (x<<1 | 1) /* 2*x+1 */
#define lowbit(x)       (x & (-x)) /* 0b10100 -> 0b100 */

typedef long long       LL;
typedef map<int,int>    MII;
typedef pair<int,int>   PII;
typedef set<int>        SI;
typedef vector<bool>    VB;
typedef vector<double>  VD;
typedef vector<int>     VI;
typedef vector<string>  VS;

/* check if a key is in container C */
template <class C>
inline bool in_(const typename C::key_type& k, const C& A)
{ return A.find(k) != A.end(); }
inline bool in_(const string& s, const string& S)
{ return S.find(s) != string::npos; }

VI F[2];

bool solve(const int d, const int dist)
{
    set<int> dp[2];
    int cur,nxt; cur = 0; nxt = 1;
    dp[cur].insert(0);
    const int n = F[d].size();
    FOR(i,0,n) {
        dp[nxt].clear();
        FOR_ALL(pos,dp[cur]) {
            dp[nxt].insert(*pos + F[d][i]);
            if (i|d)
                dp[nxt].insert(*pos - F[d][i]);
        }
        swap(cur,nxt);
    }
    FOR_ALL(pos,dp[cur]) if (*pos == dist)
        return true;
    return false;
}

int main()
{
/* #ifndef ONLINE_JUDGE */
/*     freopen("foo", "rt", stdin); */
/* #endif */
    string s; int x,y;
    while (cin >> s >> x >> y) {
        F[0].clear(); F[1].clear();
        const int n = s.size();
        int d = 0, m = 0;
        FOR(i,0,n) {
            if (s[i] == 'T') {
                F[d].push_back(m); m = 0; d ^= 1;
            }
            else
                m++;
        }
        F[d].push_back(m);
        const bool res = solve(0,x) & solve(1,y);
        const string ans = res ? "Yes" : "No";
        cout << ans << endl;
    }
    return 0;
}


Measured memory_bytes: 640
<?php
$n = trim(fgets(STDIN));
$x = explode(" ",trim(fgets(STDIN)));

$p = round(array_sum($x)/count($x),0);
$i = 0;
foreach($x as $a) {
    $i += ($a - $p) ** 2;
}
echo $i.PHP_EOL;

Measured memory_bytes: 3828
n,y=map(int,input().split())
n,y=int(n),int(y/1000)
flag=0
for iii in range(y//10+1):
  for jjj in range((y-iii*10)//5+1):
    if iii*10+jjj*5+n-iii-jjj==y:
        print(iii,jjj,n-iii-jjj)
        flag=1
        break
  if flag==1:
    break
if flag==0:
  print("-1 -1 -1")
  

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define P pair<int,int>
using ll=int64_t;
using namespace std;
#define ketasuu(n) fixed<<setprecision(n)
#define btoe(p) p.begin(),p.end()
#define etob(p) p.rbegin(),p.rend()


const ll mod=1000000007;

int main(){
    int n,k;
    cin>>n>>k;
    vector<ll> m(10000000);
    ll s=0,e=0,a=0, b=n;
    rep(i,n+2){
        s+=a; a++;
        e+=b; b--;
        m[i+1]=e-s+1;
    }
    ll ans=0;
    for(int i=k; i<n+2; ++i){
        ans+=m[i];
        ans%=mod;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 81400
#![allow(unused_imports)]
#![allow(unused_variables)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(deprecated)]

use std::cell::{Cell, Ref, RefCell, RefMut};
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;
use std::usize;

const MOD_10_9_7: u64 = 1_000_000_007;
const INF: i64 = 1_000_000_000_000;
const MIN_INF: i64 = -1_000_000_000_000;

/// FYI: https://github.com/vain0x/scan-bench
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($t:ty) =>
        (rl().parse::<$t>().unwrap());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();
    buf.trim_right().to_owned()
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}

#[allow(unused_macros)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let n = read!(usize);
    let mut h: Vec<usize> = read![[usize]];

    for i in 1..n {
        if h[i - 1] == h[i] {
            continue;
        } else if h[i - 1] + 1 <= h[i] {
            let t = h[i];
            h[i] = t - 1;
            continue;
        } else {
            println!("No");
            return;
        }
    }
    println!("Yes");
}


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

using namespace std;

typedef long long int ll;

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

  int l;
  cin >> l;
  l--;

  int n = 19;
  vector < tuple < int, int, int > > ans;
  while (l > 0) {
    tuple < int, int, int > tp (n, n + 1, 0);
    ans.push_back (tp);
    if (l % 2 == 0) {
      ans.push_back (make_tuple (1, n + 1, l));
      l--;
    }
    get < 2 > (tp) = (l + 1) / 2;
    ans.push_back (tp);
    l = (l - 1 ) / 2;
    n--;
  }

  cout << 20 - n << " " << ans.size() << '\n';
  for (auto i : ans) {
    cout << max (1, get < 0 > (i) - n) << " " << get < 1 > (i) - n << " " << get < 2 > (i) << '\n';
  }
}


Measured memory_bytes: 3596
#include <iostream>
#include <cstdio>
#include <cstring>
#include <string>
#include <vector>
#include <algorithm>

using namespace std;

int main()
{
    int x;
    cin >> x;
    if (x == 1)
    {
        cout << 0 << endl;
    }
    else
    {
        cout << 1 << endl;
    }



    return 0;
}

Measured memory_bytes: 3608
#include<ctime>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#define file(x)freopen(x".in","r",stdin);freopen(x".out","w",stdout)
#define rt register int
#define l putchar('\n')
#define ll long long
#define r read()
using namespace std;
inline ll read(){
    ll x=0;char zf=1;char ch=getchar();
    while(ch!='-'&&!isdigit(ch))ch=getchar();
    if(ch=='-')zf=-1,ch=getchar();
    while(isdigit(ch))x=x*10+ch-'0',ch=getchar();return x*zf;
}
void write(ll y){if(y<0)putchar('-'),y=-y;if(y>9)write(y/10);putchar(y%10+48);}
void writeln(const ll y){write(y);putchar('\n');}
int k,m,n,x,y,z,cnt,ans;
int ss[100010];bool pri[100010];
void init(){
	for(rt i=2;i<=100000;i++){
		if(!pri[i])ss[++cnt]=i;
		for(rt j=1;j<=cnt&&i*ss[j]<=100000;j++){
			pri[i*ss[j]]=1;
			if(i%ss[j]==0)break;
		}
	}
}
ll a[505][505];
ll lcm(ll x,ll y){
	if(!x)return y;if(!y)return x;
	return x/__gcd(x,y)*y;
}
map<ll,bool>s;
int main(){
	n=r;
	if(n==2)return printf("10 31\n61 15"),0;
	init();
	for(rt i=1;i<=n;i++)
	for(rt j=1;j<=n;j++)if(i+j&1^1){
		a[i][j]=1ll*ss[(i+j)/2]*ss[(i-j)/2+n+n/2+1];
	}
	for(rt i=1;i<=n;i++)for(rt j=1;j<=n;j++)if(i+j&1){
		a[i][j]=lcm(lcm(a[i+1][j],a[i][j+1]),lcm(a[i-1][j],a[i][j-1]))+1;
	}
	for(rt i=1;i<=n;i++)for(rt j=1;j<=n;j++)cout<<a[i][j]<<" \n"[j==n];
	return 0;
}


Measured memory_bytes: 5248
#include <bits/stdc++.h>
using namespace std;
#define FAST std::ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl '\n'
#define pb push_back
#define mod 1000000007
#define fr(i,n) for(int i=0;i<n;i++)
#define int long long int
signed main() 
{
    FAST
    //freopen("input.txt","r",stdin);
    //freopen("output.txt","w",stdout);
    int n,W;
    cin>>n>>W;
    std::vector<int> weight(n),prices(n);
    fr(i,n)
        cin>>weight[i]>>prices[i];

    int i, w; 
    int K[n+1][W+1]; 
  
   // Build table K[][] in bottom up manner 
   for (i = 0; i <= n; i++) 
   { 
       for (w = 0; w <= W; w++) 
       { 
           if (i==0 || w==0) 
               K[i][w] = 0; 
           else if (weight[i-1] <= w) 
                 K[i][w] = max(prices[i-1] + K[i-1][w-weight[i-1]],  K[i-1][w]); 
           else
                 K[i][w] = K[i-1][w]; 
       } 
   } 

   cout<<K[n][W];

    return 0;
}

Measured memory_bytes: 79232
#include <iostream>

int main()
{
	int n, m, a[100] = { 0 };
	std::cin >> n >> m;
	while (m--)
	{
		int x, y;
		std::cin >> x >> y;
		++a[x - 1];
		++a[y - 1];
	}
	for (int i = 0; i < n; i++)
		std::cout << a[i] << "\n";
		
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n;
    cin >> n;
    vector<char>s(n);
    int mn=0;
    for(int i=0;i<n;i++)cin >> s[i];
    for(int i=0;i<n-1;i++){
        if(s[i]==s[i+1]){
            mn++;
        }

    }
    cout << n-mn;
}

Measured memory_bytes: 384
import java.util.Scanner;

public class Main {

	public static void main(String... nui) {
		
		Scanner sc = new Scanner(System.in);
		
		long h = sc.nextLong();
		long w = sc.nextLong();
		
		if (h == 1 || w == 1) {
			System.out.println(1);
			return;
		}
		
		System.out.println((h * w % 2 == 0) ? h * w / 2 : h * w / 2 + 1);
		
	}

}


Measured memory_bytes: 23760
def run(H, W, K):
    # あみだくじの通る道のパターン
    dp = {(1, 0): 1}
    for w in range(2, W+1):
        dp[(w, 0)] = 0
    # ダミーで0とW+1には0を入れておく
    for h in range(0, H+1):
        dp[(0, h)] = 0
        dp[(W+1, h)] = 0
    # あみだくじの通る道のパターンを計算
    for h in range(1, H+1):
        for w in range(1, W+1):
            '''
            hの位置で他の線のパターンを計算
            w-1からwの線があるとき
            1からw-2までw-3本の線が引ける、w+1からWまでW-w-1本の線が引ける
            1本なら2パターン、2本なら3パターン、3本なら5パターン、4本なら1+4+3=8パターン
            5本なら1+5+6+1=13パターン、6本なら1+6+10+4=21、7本なら1+7+15+10+1=34パターン
            ''' 
            a = get_coef(w-3, W-w-1)
            b = get_coef(w-2, W-w-1)
            c = get_coef(w-2, W-w-2)
            dp[(w, h)] = (a*dp[(w-1, h-1)] + b*dp[(w, h-1)] + c*dp[(w+1, h-1)]) % 1000000007
    # あみだのKに行くための経路の合計
    return dp[K, H]


def get_coef(w_l, w_r):
    coef = [1, 2, 3, 5, 8, 13, 21, 34]
    if w_l < 0:
        w_l = 0
    if w_r < 0:
        w_r = 0
    return coef[w_l]*coef[w_r]


def main():
    H, W, K = map(int, input().split())
    print(run(H, W, K))


if __name__ == '__main__':
    main()


Measured memory_bytes: 3188
class HeapArray
  def initialize
    @heapArr = []
  end

  def push(n)
    i = @heapArr.size

    while i>0
      p = (i-1)/2
      break if @heapArr[p] <= n
      @heapArr[i] = @heapArr[p]
      i=p
    end

    @heapArr[i] = n
  end

  def pop
    min = @heapArr[0]
    n   = @heapArr.pop
    unless @heapArr.empty?
      i   = 0
      while (i*2+1) < @heapArr.size
        if @heapArr[i*2+2].nil?
          buf=i*2+1
        else
          buf=(@heapArr[i*2+1]<@heapArr[i*2+2])?i*2+1:i*2+2
        end
        break if @heapArr[buf] >= n
        @heapArr[i] = @heapArr[buf]
        i=buf
      end
      @heapArr[i]=n
    end
    return min
  end

  def show
    level=0
    p=0
    while p<@heapArr.size
      (2**level).times do
        if @heapArr[p].nil?
          print "x "
        else
          print "#{@heapArr[p]} "
        end
        p+=1
      end
      puts ""
      level+=1
    end
    puts ""
  end
  
  def length
    @heapArr.length
  end
end

n = gets.to_i

items = HeapArray.new

gets.split(' ').take(n).each { |item| items.push(item.to_i) }

while items.length != 1
  item_a = items.pop
  item_b = items.pop
  res = Rational(item_a + item_b, 2)

  items.push(res)
end

puts items.pop.to_f

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

int main() {
  vector<int> v = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
  int k;
  cin >> k;

  cout << v[k-1] << endl;
}

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

int main() {
  int n;
  cin >> n;
  long long ans = 0;
  vector<int>table(n);
  for (int i = 0; i < n; i++) {
    cin >> table.at(i);
  }
  sort(table.begin(),table.end());
  reverse(table.begin(),table.end());

  if (n%2==0) {
    for (int i = 0; i < n/2; i++) {
      ans += table.at(i)*2;
    }
    ans -= table.at(0);
    cout << ans << endl;
  }  
  else if (n%2==1) {
    for (int i = 0; i < (n-1)/2; i++) {
      ans += table.at(i)*2;
    }
    ans += table.at((n-1)/2);
    ans -= table.at(0);
    cout << ans << endl;
  }
}

Measured memory_bytes: 4052
N, M = map(int, input().split())
S = input()

# dp[i] := ゴールから最短何手でマスiにたどり着けるか
dp = [float('inf')] * (N + 1)
dp[-1] = 0


class RangeMinimumQuery:
    def __init__(self, n, inf=2 ** 31 - 1):
        self.n = 1 << (n - 1).bit_length()
        self.INF = inf
        self.segtree = [self.INF] * (2 * self.n)

    # i番目の値(0-indexed)をxに変更
    def update(self, i, x):
        i += self.n
        self.segtree[i] = x
        while i > 0:
            i //= 2
            self.segtree[i] = min(self.segtree[2 * i], self.segtree[2 * i + 1])

    # [l, r)のmin
    def query(self, l, r):
        L, R = l + self.n, r + self.n
        R = min(R, len(self.segtree))
        s = self.INF
        while L < R:
            if L & 1:
                s = min(s, self.segtree[L])
                L += 1

            if R & 1:
                s = min(s, self.segtree[R - 1])
                R -= 1

            L >>= 1
            R >>= 1

        return s


# セグメント木でdpテーブルを高速に埋める
RMQ = RangeMinimumQuery(N + 1)
RMQ.update(N, 0)
for i in range(N - 1, -1, -1):
    if S[i] == '1':
        continue

    # RMQ.query(l, r) := [l, r)の最小値
    dp[i] = RMQ.query(i, i + M + 1) + 1
    RMQ.update(i, dp[i])


ans = []
position = 0
while position < N:
    for move in range(1, M + 1):
        if position + move > N:
            continue

        if S[position + move] == '1':
            continue

        # 最短手数にならない
        if dp[position + move] == dp[position]:
            continue

        ans.append(move)
        position += move
        break

    else:
        print(-1)
        exit()

print(*ans)


Measured memory_bytes: 12360
from math import ceil,floor,factorial,gcd,sqrt,log2,cos,sin,tan,acos,asin,atan,degrees,radians,pi,inf
from itertools import accumulate,groupby,permutations,combinations,product,combinations_with_replacement
from collections import deque,defaultdict,Counter
from bisect import bisect_left,bisect_right
from operator import itemgetter
from heapq import heapify,heappop,heappush
from queue import Queue,LifoQueue,PriorityQueue
from copy import deepcopy
from time import time
from functools import reduce
import string
import sys
sys.setrecursionlimit(10 ** 7)
def input() : return sys.stdin.readline().strip()
def INT()   : return int(input())
def MAP()   : return map(int,input().split())
def MAP1()  : return map(lambda x:int(x)-1,input().split())
def LIST()  : return list(MAP())

def solve():
    N, M, Q = MAP()
    A = [LIST() for _ in range(Q)]

    ans = 0
    for x in combinations_with_replacement(range(1, M+1), N):
        score = 0
        for a, b, c, d in A:
            if x[b-1] - x[a-1] == c:
                score += d
        ans = max(ans, score)
    print(ans)

if __name__ == '__main__':
    solve()

Measured memory_bytes: 10224
#include<iostream>
#include<cmath>
using namespace std;
int main(){
	int x[101],y[101],h[101];
	int N,H;
	cin >> N;
	int m,k;
	for(int i=0;i<N;i++){
		cin >> x[i] >> y[i] >> h[i];
		if(h[i]!=0) m=i;
	}
	for(int i=0;i<=100;i++){
		for(int j=0;j<=100;j++){
			H=abs(x[m]-i)+abs(y[m]-j)+h[m];
			for(k=0;k<N;k++){
				int height=max(0,H-abs(x[k]-i)-abs(y[k]-j));
				if(height!=h[k]) break;
			}
			if(k==N){
				cout << i <<" "<< j <<" "<< H;
				return 0;
			}
		}
	}
	return 0;
} 

Measured memory_bytes: 256
#include <atcoder/mincostflow>
#include <iostream>

int main() {
    const long long inf = 1001001001;
    
    int n, k;
    std::cin >> n >> k;
    std::vector<std::vector<int>> a(n, std::vector<int>(n));
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) std::cin >> a[i][j];
    
    atcoder::mcf_graph<int, long long> g(2 * n + 2);
    int s = 2 * n, t = 2 * n + 1;
    g.add_edge(s, t, n * k, inf);
    for (int i = 0; i < n; ++i) {
        g.add_edge(s, i, k, 0);
        g.add_edge(i + n, t, k, 0);
    }
    for (int i = 0; i < n; ++i) for (int j = 0; j < n; ++j) g.add_edge(i, j + n, 1, inf - a[i][j]);
    
    auto ans = g.flow(s, t, n * k);
    std::cout << inf * n * k - ans.second << "\n";
    std::vector<std::vector<char>> grid(n, std::vector<char>(n, '.'));
    auto edges = g.edges();
    for (auto e : edges) {
        if (e.from == s || e.to == t || e.flow == 0) continue;
        grid[e.from][e.to - n] = 'X';
    }
    for (int i = 0; i < n; ++i) {
        for (int j = 0; j < n; ++j) std::cout << grid[i][j];
        std::cout << "\n";
    }
}


Measured memory_bytes: 3936
#include<iostream>
#include<stdlib.h>
#include<algorithm>
#include<functional>
#include<string>
#include<string.h>

using namespace std;

int main(){
	
	int n,diff,max_kazu[9],min_kazu[9];
	char cdiff[9],keta[9];
	
	cin>>n;
	
	for(int i=0;i<n;i++){
		
		//配列の初期化
		memset(max_kazu,'0',sizeof(max_kazu));
		memset(min_kazu,'0',sizeof(min_kazu));
		memset(keta,'\0',sizeof(keta));
		memset(cdiff,'\0',sizeof(cdiff));
		
		
		cin>>keta;
		
		//char型からint型への変換
		for(int j=0;j<8;j++){
			min_kazu[j]=keta[j]-'0';
			max_kazu[j]=keta[j]-'0';
		}
		
		//昇順ソート
		stable_sort(min_kazu,min_kazu+8);
		//降順ソート
		stable_sort(max_kazu,max_kazu+8,greater<int>());
		

		/*cout<<endl;
		for(int j=0;j<8;j++){
			cout<<max_kazu[j];
		}
		cout<<endl;
		
		for(int j=0;j<8;j++){
			cout<<min_kazu[j];
		}
		cout<<endl;
		cout<<"--------"<<endl;*/
		
		for(int j=7;j>=0;j--){
			
			if((max_kazu[j]-min_kazu[j])<0){
				
				diff=(10+max_kazu[j])-min_kazu[j];
				
				//繰り下がり作業
				for(int k=j-1;k>=0;k--){
					if(max_kazu[k]!=0){
						max_kazu[k]--;
						for(int m=k+1;m<j;m++){
							max_kazu[m]=9;
						}
						break;
					}
				}
			}
			else{
				diff=max_kazu[j]-min_kazu[j];
			}
			
			cdiff[j]=diff+'0';
		}
		
		cout<<atoi(cdiff)<<endl;
		//cout<<endl;
	}
}

Measured memory_bytes: 1236
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main()
{
    ll a,b,c,i,d;
    cin>>c>>a>>b;
    d=a/c;
    if(a%c==0 || b%c==0)
        cout<<"OK"<<endl;
    else if(((d+1)*c)<=b)
        cout<<"OK"<<endl;
    else
        cout<<"NG"<<endl;


}


Measured memory_bytes: 3632
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long w = sc.nextLong();
        long h = sc.nextLong();
        long x = sc.nextLong();
        long y = sc.nextLong();

        System.out.println(String.format("%f %d", w * h / 2.0, x * 2 == w && y * 2 == h ? 1 : 0));
    }
}


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

int main() {
  int l,r,d;
  cin>>l>>r>>d;

  int cnt=0;

  for(int i=l;i<=r;i++) {
    if(i%d==0) {
      cnt++;
    }
  }
  cout<<cnt<<endl;

}


Measured memory_bytes: 3596
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N,t,c;
  cin >> N;
  t=N;
while(t>0){
  c+= t%10 ;
  t /=10;
}
if(N%c==0) cout<< "Yes"<<endl;
else cout <<"No"<<endl;

}

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

using namespace std;

bool prime_check(int n, int k = 2)
{
	if (n < 2) { return false; }

	if (n < k * k) { return true; }

	if (n % k == 0) { return false; }

	return prime_check(n, k + 1);
}

int main()
{
	vector<int> P;

	while (true)
	{
		int n, Ans = 0;

		cin >> n;

		if (n == 0) { break; }

		for (int i = n + 1; i <= 2 * n; i++)
		{
			if (prime_check(i) == true)
			{
				Ans++;
			}
		}

		P.push_back(Ans);
	}

	for (int i = 0; i < P.size(); i++)
	{
		cout << P[i] << endl;
	}

	return 0;
}

Measured memory_bytes: 1216
#include <bits/stdc++.h>
typedef long long ll;
typedef long double ld;
#define endl "\n"
#define fi first
#define se second
#define For(i,a,b) for(ll i=a;i<b;i++)
#define RFor(i,b,a) for(ll i = b;i>=a;i--)
#define sz size()
#define PQ priority_queue
#define len length()
#define mll map<ll,ll>
#define mpll map<pll,ll>
#define vll vector<ll>
#define sll set<ll>
#define vpll vector<pair<ll,ll> >
#define mp(x,y)  make_pair(x,y)
#define pll pair<ll,ll>
#define pb push_back
#define pf push_front
#define ALL(v) v.begin(),v.end()
#define LAPAK ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
using namespace std;

const ll MOD = 1e9 + 7;
const ll INF = 2e18;
const ll MAX = 405;

int main() {
    
    int d,t,s;
    cin>>d>>t>>s;
    cout<<(t*s>=d?"Yes":"No");
    
    return 0;
}

Measured memory_bytes: 3632
import heapq
from collections import deque
from enum import Enum
import sys
import math
from _heapq import heappush, heappop

#------------------------------------------#

BIG_NUM = 2000000000
HUGE_NUM = 9999999999999999
MOD = 1000000007
EPS = 0.000000001

#------------------------------------------#

class Edge:
    def __init__(self,arg_to,arg_cost):
        self.to = arg_to
        self.cost = arg_cost

class Info:
    def __init__(self,arg_node_id,arg_sum_cost):
        self.node_id = arg_node_id
        self.sum_cost = arg_sum_cost

    def __lt__(self,arg):
        return self.sum_cost < arg.sum_cost


V = int(input())
min_dist = [BIG_NUM]*V
G = [[] for i in range(V)]

for loop in range(V):
    node_id,tmp_num,*table = list(map(int,input().split()))
    for i in range(0,len(table),2):
        G[node_id].append(Edge(table[i],table[i+1]))


min_dist[0] = 0
Q = []

heappush(Q, Info(0,0))

while len(Q) > 0:
    info = heappop(Q)
    if info.sum_cost > min_dist[info.node_id]:
        continue
    for edge in G[info.node_id]:
        if min_dist[edge.to] > info.sum_cost+edge.cost:
            min_dist[edge.to] = info.sum_cost+edge.cost
            heappush(Q, Info(edge.to,min_dist[edge.to]))


for i in range(V):
    print("%d %d"%(i,min_dist[i]))






Measured memory_bytes: 7404
#include<stdio.h>
#include<string.h>
int main(){
    char s[2000];
    int n, i, j;
    scanf("%[^\n]", s);
    for ( i = 0; i < strlen(s); i++ ) {
        if ( s[i] == 'a' ) {
            if ( s[i+1] == 'p' && s[i+2] == 'p' && s[i+3] == 'l' && s[i+4] == 'e') {
                s[i] = 'p';
                s[i+1] = 'e';
                s[i+2] = 'a';
                s[i+3] = 'c';
                s[i+4] = 'h';
            }
        } else if ( s[i] == 'p') {
            if( s[i+1] == 'e' && s[i+2] == 'a' && s[i+3] == 'c' && s[i+4] == 'h') {
                s[i] = 'a';
                s[i+1] = 'p';
                s[i+2] = 'p';
                s[i+3] = 'l';
                s[i+4] = 'e';
            }
        }
    }
    printf("%s\n", s);
    return 0;
}

Measured memory_bytes: 1824
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();

    if ((n % 2) == 0) {
      System.out.println(n);
    } else {
      System.out.println(2 * n);
    }

  }
}

Measured memory_bytes: 35684
N, K = [int(x) for x in input().split()]
h = [int(x) for x in input().split()]

dp = [0] * (N + 1)

dp[0] = 0
dp[1] = abs(h[0] - h[1])

for n in range(1, N):
    mi = 999999999999
    for k in range(1, K + 1):
        if n - k >= 0:
            t = dp[n - k] + abs(h[n - k] - h[n])
            mi = min(mi, t)
    dp[n] = mi

print(dp[N - 1])


Measured memory_bytes: 52576
#include <iostream>
using namespace std;
    int main(){
    int a,b,c;
    cin >> a >> b >> c;
    if(a>b && a>c){
        if(a==b+c){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    else if(b>a && b>c){
        if(b==a+c){
            cout << "Yes" << endl;
        }else{
            cout << "No" << endl;
        }
    }
    else if(c>a && c>b){
        if(c==a+b){
            cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }
    }
    else{
        cout << "No" << endl;
    }
    }

Measured memory_bytes: 256
#include<bits/stdc++.h>
typedef long long int ll;
typedef unsigned long long int ull;
#define BIG_NUM 2000000000
#define HUGE_NUM 1000000000000000000
#define MOD 1000000007
#define EPS 0.000000001
using namespace std;




int main(){

	int W,H,x,y;
	scanf("%d %d %d %d",&W,&H,&x,&y);

	printf("%.15lf %d\n",((double)W*(double)H)/2.0,2*x == W && 2*y == H);

	return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define dbg(x) cout<<#x<<":"<<x<<endl
#define int long long
#define MOD 1e9+7
typedef pair<int,int> P;
typedef pair<int,P> PP;

signed main(){
  int n;
  cin>>n;
  int cnta=0,cntb=0,ans=0,cntc=0;
  for(int i=0;i<n;i++){
    string s;
    cin>>s;
    if(s[0]=='B'&&s[s.size()-1]=='A')cntc++;
    else if(s[s.size()-1]=='A')cnta++;
    else if(s[0]=='B')cntb++;
    for(int j=1;j<s.size();j++){
	 if(s[j-1]=='A'&&s[j]=='B')ans++;
    }
  }

  int k=min({cnta,cntb,cntc});
  ans+=k*2;
  cnta-=k;
  cntb-=k;
  cntc-=k;


  if(k>0){
    ans+=cntc;
    ans+=min(cnta,cntb);
  }else{
    if(cntc>0){
	 ans+=cntc-1;
	 if(cnta>0){
	   cnta--;
	   ans++;
	 }
	 if(cntb>0){
	   cntb--;
	   ans++;
	 }
    }
    ans+=min(cnta,cntb);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 384
#include<cstdio>
#include<cmath>
#include<vector>
#include<string>
#include<queue>
#include<algorithm>

using namespace std;

bool func(const pair<pair<long long, long long>, long long> &a, pair<pair<long long, long long>, long long> &b)
{
	return a.second > b.second;
}

int main()
{
	int n, m;
	queue<int> q;
	int *indeg;
	int *parent;
	vector<int> *graph;
	int i;
	int input1, input2;
	int cur;

	scanf("%d %d", &n, &m);

	indeg = new int[n + 1];
	parent = new int[n + 1];
	graph = new vector<int>[n + 1];

	for (i = 1; i <= n; i++)
	{
		indeg[i] = 0;
		parent[i] = -1;
	}

	for (i = 0; i < n + m - 1; i++)
	{
		scanf("%d %d", &input1, &input2);

		graph[input1].push_back(input2);

		indeg[input2]++;
	}

	for (i = 1; i <= n; i++)
	{
		if (!indeg[i])
		{
			parent[i] = 0;

			q.push(i);

			break;
		}
	}

	while (!q.empty())
	{
		cur = q.front();

		q.pop();

		for (i = 0; i < graph[cur].size(); i++)
		{
			if (!(--indeg[graph[cur][i]]))
			{
				parent[graph[cur][i]] = cur;

				q.push(graph[cur][i]);
			}
		}
	}

	for (i = 1; i <= n; i++)
	{
		printf("%d\n", parent[i]);
	}

	return 0;
}

Measured memory_bytes: 7040
#include <iostream>
#include <math.h>
#include <string.h>
#include <iomanip>
using namespace std;

bool number[10];
int res[10],x[10],y[10],n;
double s=0;

double dist(int i,int j)
{
    return sqrt(pow(x[i]-x[j]*1.0,2)+pow(y[i]-y[j]*1.0,2));
}

void xuat()
{
    for (int i=1;i<n;i++)
        s+=dist(res[i],res[i+1]);
}

void backtrack(int counter)
{
    if (counter>n)
    {
        xuat();

    }
    for (int i=1;i<=n;i++)
    {
        if (number[i]==1)
        {
            number[i]=0;
            res[counter]=i;
            backtrack(counter+1);
            number[i]=1;
        }
    }
}

int factorial(int n)
{
    if (n<=1) return 1;
    else return n*factorial(n-1);
}

int main()
{
    cin >> n;
    for (int i=1;i<=n;i++)
        cin >> x[i] >> y[i];
    memset(number,1,sizeof(number));
    backtrack(1);
    s=s/factorial(n);
    cout << fixed << setprecision(10) << s;
    return 0;
}


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

using namespace std;

int main()
{
  int A, B;
  string S;

  cin >> A >> B;
  cin >> S;

  if(S.find('-') == A && count(begin(S), end(S), '-') == 1) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

#define io ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0)
#define int long long
#define endl '\n'
#define eps  1e-9
const double pi=acos(-1);
const int mod=1e9+7;
//------------------------

int32_t main()
{ 
  io;
 
  
  string s;
  int rr=0,bb=0,n;
  cin>>n;
  cin>>s;
  for(char c: s)
  {
    rr+=(c=='R');
    bb+=(c=='B');
  }

  cout<<(rr>bb?"Yes":"No");

 return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>

using namespace std;

void solve()
{
	string str;
	cin >> str;
	int n = str.size();
	for(int i = 0; i < n; ++i)
	{
		if('D' <= str[i] && str[i] <='Z')
		{
			str[i] -= 3;
		}
		else if('A' <= str[i] && str[i] <= 'C')
		{
			str[i] += -'A' + 'X';
		}
		cout << str[i];
	}
	cout << endl;
}

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

Measured memory_bytes: 0
#pragma GCC optimize ("O3")

#include <bits/stdc++.h>

using namespace std;

#ifdef LOCAL
#include <prettyprint.hpp>
#define debug(...)  cerr << "[" << #__VA_ARGS__ << "]: ", d_err(__VA_ARGS__);
#else
#define debug(...) 83;
#endif

void d_err() {
    cerr << endl;
}

template <typename H, typename... T>
void d_err(H h, T... t) {
    cerr << h << " ";
    d_err(t...);
}

#define FOR(i, m, n) for (int i = (m); i < (n); ++i)
#define REP(i, n) FOR(i, 0, n)
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define eb emplace_back
#define bcnt __builtin_popcountll

typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef pair<ll,ll> Pll;
typedef pair<int,int> Pin;

ll INF = 1e16;
int inf = 1e9;
ll MOD;

struct mint {
    ll x;
    mint(ll x=0):x((x%MOD+MOD)%MOD){}
    mint operator-() const { return mint(-x);}
    mint& operator+=(const mint a) {
        if ((x += a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator-=(const mint a) {
        if ((x += MOD-a.x) >= MOD) x -= MOD;
        return *this;
    }
    mint& operator*=(const mint a) {
        (x *= a.x) %= MOD;
        return *this;
    }
    mint operator+(const mint a) const {
        mint res(*this);
        return res+=a;
    }
    mint operator-(const mint a) const {
        mint res(*this);
        return res-=a;
    }
    mint operator*(const mint a) const {
        mint res(*this);
        return res*=a;
    }
    mint pow(ll t) const {
        if (!t) return 1;
        mint a = pow(t>>1);
        a *= a;
        if (t&1) a *= *this;
        return a;
    }
    // for prime MOD
    mint inv() const {
        return pow(MOD-2);
    }
    mint& operator/=(const mint a) {
        return (*this) *= a.inv();
    }
    mint operator/(const mint a) const {
        mint res(*this);
        return res/=a;
    }
};


int main(){
    cin.tie(0);
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(20);
    
    int N;
    cin >> N >> MOD;

    string S;
    cin >> S;

    if (MOD == 2 || MOD == 5) {
        ll ans = 0;
        REP(i, N) {
            int s = S[i] - '0';
            if (s % MOD == 0) ans += i+1;
        }

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

    reverse(S.begin(), S.end());
    vector<ll> u(MOD, 0);
    mint m = 0;
    mint d = 1;
    u[0] = 1;

    REP(i, N) {
        if (i > 0) d *= 10;
        int c = S[i] - '0';
        m += d * c;
        u[m.x] += 1;
    }

    ll ans = 0;
    REP(i, MOD) {
        ans += u[i] * (u[i] - 1) / 2;
    }
    cout << ans << endl;
    
}


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

int main(){
  int n;
  string s;
  cin >>n>>s;	
  int ans=0;
  for(int i=1;i<n;i++){
    int co = 0;  
    for(char c='a';c<='z';c++){
      bool left=false;
      bool right=false;      
      for(int j=0;j<i;j++) if(s[j]==c) left=true;
      for(int j=i;j<n;j++) if(s[j]==c) right=true;			
      if(left and right) co++;
    }    
    if(ans<co) ans = co;
  }
	cout<<ans<<endl;
}


Measured memory_bytes: 256
# AGC023A - Zero-Sum Ranges
from collections import Counter
from itertools import accumulate


def main():
    """
    e.g. accumulated A: 0 a0 a1 a2 a3 ...
    if a0 == a2 -> a2 - a0 == 0
    -> Counter(accumulate(A)) & sum up
    """
    N, *A = map(int, open(0).read().split())
    C = Counter(accumulate([0] + A)).values()
    ans = sum(i * (i - 1) // 2 for i in C if i >= 2)
    print(ans)


if __name__ == "__main__":
    main()

Measured memory_bytes: 40840
#include <cstdio>
#include <cmath>
#include <iostream>
#include <sstream>
#include <string>
#include <vector>
#include <map>
#include <queue>
#include <algorithm>

#ifdef _DEBUG
#define DMP(x) cerr << #x << ": " << x << "\n"
#else
#define DMP(x) ((void)0)
#endif

const int MOD = 1000000007, INF = 1111111111; 
using namespace std;
typedef long long lint;

int main() {

	cin.tie(0);
	ios::sync_with_stdio(false);

	int N;
	cin >> N;

	vector<int> p(N);
	for (int i = 0; i < N; i++) cin >> p[i];
	sort(p.begin(), p.end());

	int ans = -p.back() / 2;
	for (const auto &elem : p) ans += elem;

	cout << ans << "\n";

	return 0;
}

Measured memory_bytes: 256
r, c = map(int, input().split())
arr = []
for i in range(r):
    arr.append(list(map(int, input().split())))

for line in arr:
    line.append(sum(line))
    
arr.append([sum([line[i] for line in arr]) for i in range(c  + 1)])

for line in arr:
    print(*line)


Measured memory_bytes: 6236
#include <iostream>
#include <algorithm>
using namespace std;
int main(){
  int n,m,x;
  int l=0;
  int r=0;
  cin >> n >> m >>x;
  int a[m];
  for(int i=0;i<m;i++){
     cin >> a[i];
  }
  for(int i=0;i<m;i++){
    if(a[i]<x) {
      l++;
    }
    else {
     r++;
    }
  }
  int ans=min(l,r);
  cout << ans << endl;
}


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

#define rep(X,N) for(ll X = 0; X < (N); X++)
#define PI (acos(-1.0))
#define pback push_back
#define mpair make_pair
#define MODN 1000000007
#define MODN2 998244353
#define ALL(V) (V).begin(),(V).end()
#define INT_MAX_HALF (INT_MAX / 2)
#define EPS (1e-10)

using namespace std;
typedef long long ll;

int main(){

    double a,b, h, m;
    cin >> a >> b >> h >> m;

    double ad = (h / 12 * 2 * PI + m / 60 * PI / 6) * -1;
    double bd = (m / 60 * 2 * PI) * -1;

    cerr << ad / (2 * PI) << endl;
    cerr << bd / (2 * PI) << endl;

    double ax = cos(ad) * a;
    double ay = sin(ad) * a;
    double bx = cos(bd) * b;
    double by = sin(bd) * b;

    cerr << ax << endl;
    cerr << ay << endl;
    cerr << bx << endl;
    cerr << by << endl;

    cout << setprecision(13) << sqrt(pow(ax - bx, 2.0) +  pow(ay - by, 2.0)) << endl;

    return 0;
}


Measured memory_bytes: 4260
import math
n = int(input())
x = list(map(float,input().split()))
y = list(map(float,input().split()))

def suan(p):
	d = 0
	for i in range(n):
		d += (math.fabs(x[i] - y[i]))**p
	print('%.6f'%(d**(1/p)))

suan(1)
suan(2)
suan(3)
print(max(math.fabs(x[i] - y[i])for i in range(n)))


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

string s;
int x, y, f, d = 2;
vector<int> v[2];

bool sheidzleba_migeba_netavi(vector<int> v, int x) {
	int a[32004];
	for(int i = 0; i < 32004; ++i) a[i] = 0;
	a[16000] = 1;
	for(int j = 0; j < v.size(); ++j) {
		int t = v[j];
		for(int i = 0; i < 32004; ++i) {
			if(1) {
				if((i >= t && (a[i - t] & 1)) || (i + t < 32004 && (a[i + t] & 1))) {
					if(!a[i]) a[i] = 2;
					else a[i] = 3;
				}
			}
		}
		for(int i = 0; i < 32004; ++i) {
			if(a[i] >= 2) {
				a[i] = 1;
			} else {
				a[i] = 0;
			}
		}
	}
	return(bool)a[x + 16000];
}

int main() {
	ios::sync_with_stdio(0);
	cin.tie(0);
	#ifdef CR
	cin >> s >> x >> y;
	s += 'T';
	for(int i = 0; i < s.size(); ++i) {
		if(s[i] == 'F') {
			++f;
		} else {
			if(d == 2) {
				x -= f;
			} else {
				v[d].push_back(f);
			}
			f = 0;
			if(d) d = 0;
			else d = 1;
		}
	}
	#else
	while(1) {
		int n;
		x = 0;
		v[1].clear();
		cin >> n >> y;
		v[0].resize(n);
		for(int i = 0; i < n; ++i) cin >> v[0][i];
	#endif
	if(sheidzleba_migeba_netavi(v[0], y) && sheidzleba_migeba_netavi(v[1], x)) cout << "Yes" << endl;
	else cout << "No" << endl;
	#ifndef CR
	}
	#endif
	return 0;
}


Measured memory_bytes: 512
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<iomanip>
#include<cstring>
#include<map>
#include<vector>
#include<queue>
#include<stack>
#include<climits>
#include<set>
#include<utility>
#include<typeinfo>
#include<random>
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
typedef set<int> S;
#define rep(i, n) for(int i=0; i<n; i++)
const int MOD=1e9+7;

int main(){

  string n;
  cin >> n;
  int a=n.length();
  if(n[a-1]=='3'){
    cout << "bon" << endl;
  } else if(n[a-1]=='0' || n[a-1]=='1' || n[a-1]=='6' || n[a-1]=='8'){
    cout << "pon" << endl;
  } else {
    cout << "hon" << endl;
  }


  return 0;
}

Measured memory_bytes: 3596