akhauriyash/Code-Regression huggingface dataset:
import sys
import numpy as np
import random
from decimal import Decimal
import itertools
import re
import bisect
from collections import deque, Counter
from functools import lru_cache

sys.setrecursionlimit(10**9)
INF = 10**13
def LI(): return list(map(int, sys.stdin.buffer.readline().split()))
def I(): return int(sys.stdin.buffer.readline())
def LS(): return sys.stdin.buffer.readline().rstrip().decode('utf-8').split()
def S(): return sys.stdin.buffer.readline().rstrip().decode('utf-8')
def IR(n): return [I() for i in range(n)]
def LIR(n): return [LI() for i in range(n)]
def SR(n): return [S() for i in range(n)]
def LSR(n): return [LS() for i in range(n)]
def SRL(n): return [list(S()) for i in range(n)]
def MSRL(n): return [[int(j) for j in list(S())] for i in range(n)]
def SERIES(n): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ')
def GRID(h,w): return np.fromstring(sys.stdin.buffer.read(), dtype=np.int32, sep=' ').reshape(h,-1)[:,:w]
def GRIDfromString(h,w): return np.frombuffer(sys.stdin.buffer.read(), 'S1').reshape(h,-1)[:,:w]
MOD = 1000000007

def main():
	n, a, b = LI()
	pos, *x_list = LI()
	cost = 0
	for x in x_list:
		if abs(x-pos)*a < b:
			cost += abs(x-pos) * a
		else:
			cost += b
		pos = x
	print(cost)


if __name__ == '__main__':
    main()

Measured memory_bytes: 36448
mozi = input()
if mozi == 'RRR':
    print(3)
elif mozi == 'RRS':
    print(2)
elif mozi == 'SRR':
    print(2)
elif mozi == 'SRS':
    print(1)
elif mozi == 'SSR':
    print(1)
elif mozi == 'RSS':
    print(1)
elif mozi == 'RSR':
    print(1)
else:
    print(0)

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

#define rep(i, m, n) for(int(i) = (int)(m); i < (int)(n); ++i)
#define rep2(i, m, n) for(int(i) = (int)(n)-1; i >= (int)(m); --i)
#define REP(i, n) rep(i, 0, n)
#define REP2(i, n) rep2(i, 0, n)
#define all(hoge) (hoge).begin(), (hoge).end()
#define en '\n'
using ll = long long;
using ull = unsigned long long;
using ld = long double;
template <class T>
using vec = vector<T>;
template <class T>
using vvec = vector<vec<T>>;
typedef pair<ll, ll> P;
constexpr long long INF = 1LL << 60;
constexpr int INF_INT = 1 << 25;
constexpr long long MOD = (ll)1e9 + 7;
//constexpr long long MOD = 998244353LL;
using ld = long double;
static const ld pi = 3.141592653589793L;
typedef vector<ll> Array;
typedef vector<Array> Matrix;

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

struct Edge {
    ll to, rev;
    long double cap;
    Edge(ll _to, long double _cap, ll _rev) {
        to = _to;
        cap = _cap;
        rev = _rev;
    }
};
using Edges = vector<Edge>;
using Graph = vector<Edges>;

void add_edge(Graph &G, ll from, ll to, long double cap, bool revFlag,
              long double revCap) {
    G[from].push_back(Edge(to, cap, (ll)G[to].size()));
    if(revFlag)
        G[to].push_back(Edge(from, revCap, (ll)G[from].size() - 1));
}

ll dp[50];

ll f(ll x) {
    if(x < 2)
        return 1;
    if(dp[x])
        return dp[x];
    return dp[x] = f(x - 1) + f(x - 2);
}

void solve() {
    ll n;
    cin >> n;
    cout << f(n) << en;
}

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

    solve();

    /*
    ll t;
    cin >> t;
    REP(i, t) { solve();}
    */

    return 0;
}



Measured memory_bytes: 3212
#include <stdio.h>

long long int AA[100005];
int main(){
    long long int i,N,Q,sum,t,t1,t2;
    sum = 0;
    scanf("%lld",&N);
    for(i=0;i<N;i++){
        scanf("%lld",&t);
        AA[t]++;
        sum += t;
    }
    scanf("%lld",&Q);
    for(i=0;i<Q;i++){
        scanf("%lld %lld",&t1,&t2);
        sum = sum + AA[t1]*(t2-t1);
        AA[t2] += AA[t1];
        AA[t1] = 0;
        printf("%lld\n",sum);
    }
}


Measured memory_bytes: 2516
#include<iostream>
using namespace std;
int main()
{
    int N;
    cin >> N;
    bool ans = false;
    for(int i = 1; i <= N; i++){
        if(N % i != 0)  continue;
        if((i >= 1 && i <= 9) && (N/i >= 1 && N/i <= 9)) 
            ans = true;
    }
    if(ans) cout << "Yes" << endl;
    else    cout << "No" << endl;
}


Measured memory_bytes: 256
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

func configure(scanner *bufio.Scanner) {
	scanner.Split(bufio.ScanWords)
	scanner.Buffer(make([]byte, 1000005), 1000005)
}
func getNextString(scanner *bufio.Scanner) string {
	scanned := scanner.Scan()
	if !scanned {
		panic("scan failed")
	}
	return scanner.Text()
}
func getNextInt(scanner *bufio.Scanner) int {
	i, _ := strconv.Atoi(getNextString(scanner))
	return i
}
func getNextInt64(scanner *bufio.Scanner) int64 {
	i, _ := strconv.ParseInt(getNextString(scanner), 10, 64)
	return i
}
func getNextFloat64(scanner *bufio.Scanner) float64 {
	i, _ := strconv.ParseFloat(getNextString(scanner), 64)
	return i
}
func main() {
	fp := os.Stdin
	wfp := os.Stdout
	extra := 0
	if os.Getenv("I") == "IronMan" {
		fp, _ = os.Open(os.Getenv("END_GAME"))
		extra = 100
	}
	scanner := bufio.NewScanner(fp)
	configure(scanner)
	writer := bufio.NewWriter(wfp)
	defer func() {
		r := recover()
		if r != nil {
			fmt.Fprintln(writer, r)
		}
		writer.Flush()
	}()
	solve(scanner, writer)
	for i := 0; i < extra; i++ {
		fmt.Fprintln(writer, "-----------------------------------")
		solve(scanner, writer)
	}
}
func solve(scanner *bufio.Scanner, writer *bufio.Writer) {
	n := getNextInt(scanner)
	aa := make([]int, n)
	bb := make([]int, n)
	ll := map[int]int{}
	rr := map[int]int{}
	for i := 0; i < n; i++ {
		aa[i] = getNextInt(scanner)
	}
	for i := 0; i < n; i++ {
		bb[i] = getNextInt(scanner)
	}
	for i := 0; i < n; i++ {
		ll[aa[i]] = i
	}
	for i := n - 1; i >= 0; i-- {
		rr[bb[i]] = i
	}

	dif := 0
	for l, i := range ll {
		if _, exists := rr[l]; exists && dif < i-rr[l] {
			dif = i - rr[l]
		}
	}
	cc := make([]int, n)
	for i := 0; i < n; i++ {
		cc[(i+dif+1)%n] = bb[i]
	}
	for i := 0; i < n; i++ {
		if aa[i] == cc[i] {
			fmt.Fprintln(writer, "No")
			return
		}
	}
	fmt.Fprintln(writer, "Yes")
	sep := ""
	for i := 0; i < n; i++ {
		fmt.Fprintf(writer, "%s%d", sep, cc[i])
		sep = " "
	}
	fmt.Fprintln(writer, "")
}


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

const ll LINF = 1e18;
const int INF = 1e9;
const ll MOD = 1000000007;


int main(){

    string s;
    cin >> s;
    if(((s[0] == s[1]) && (s[1] == s[2])) ||
        ((s[1] == s[2]) && (s[2] == s[3]))){
            cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    return 0;
}

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

int main() {
  int a,b,c,k;
  cin>>a>>b>>c>>k;
  int count=0;
  if(a>=k)cout<<k<<endl;
 else if(a+b>=k)cout<<a<<endl;
  else if(a+b<k)cout<<2*a+b-k<<endl;
}


Measured memory_bytes: 3612
#include <bits/stdc++.h>
using namespace std;
 
int main(){
    int a,b;
    cin >> a >> b;
 
    if (a >= 13){
      cout << b;
    }else if (a >= 6){
      cout << (b/2);
    }else{
      cout << 0;
    }
 
    return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.lang.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        if (s.contains("a") && s.contains("b") && s.contains("c")) {
            System.out.println("Yes");
        } else {
            System.out.println("No");
        }
    }
}



Measured memory_bytes: 21844
/*Function Template*/
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> pint;
const int MAX = 510000;
const int MOD = 1000000007;
#define rep(i, n) for(ll i = 0; i < (n); i++)
#define Rep(i, n) for(ll i = 1; i < (n); i++)
#define ALL(a)  (a).begin(),(a).end()
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
ll fac[MAX], finv[MAX], inv[MAX];


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;
}
// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (ll i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }

}
ll Len(ll n) {
  ll s=0;
  while(n!=0) s++, n/=10;
  return s;
}


ll Sint(ll n) {
  ll m=0,s=0,a=n;
  while(a!=0) s++, a/=10;
  for(ll i=s-1;i>=0;i--) m+=n/((ll)pow(10,i))-(n/((ll)pow(10,i+1)))*10;
  return m;
}


ll Svec(vector<ll> v){
  ll n=0;
  for(ll i=0;i<v.size();i++) n+=v[i];
  return n;
}


ll GCD(ll a,ll b) {
  return b ? GCD(b,a%b) : a;
}


ll LCM(ll a,ll b){
  return a/GCD(a,b)*b;
}


ll Factorial(ll n){
  ll m=1;
  while(n>=1) m*=n,n--;
  return m;
}

void runlength(string s,vector<pair<char,ll>> &p){
  ll x=1;
  if(s.size()==1){
    p.push_back(pair<char,ll>(s[0],1));
  }
  for(ll i=0;i<s.size()-1;i++){
    if(s[i]==s[i+1]){
      x++;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[i],x));
      }
    }else{
      p.push_back(pair<char,ll>(s[i],x));
      x=1;
      if(i==s.size()-2){
        p.push_back(pair<char,ll>(s[s.size()-1],x));
      }
    }
  }
}




ll COM(ll n,ll k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

const int MAX_N=250000;
vector<bool> sieve_of_eratosthenes(){
  vector<bool> isPrime(MAX_N+1,true);
  for(int i=2;i<=MAX_N;i++){
    if(isPrime[i]){
      for(int j=2*i;j<=MAX_N;j+=i){
        isPrime[j]=false;
      }
    }
  }
  return isPrime;
}

vector<pint> prime_factorize(ll n){
  vector<pint> ans;
  for(ll p=2;p<=sqrt(n);p++){
    if(n%p!=0) continue;
    ll cnt=0;
    while(n%p==0){
      n/=p;
      cnt++;
    }
    ans.push_back(make_pair(p,cnt));
  }
  if(n!=1) ans.push_back(make_pair(n,1));
  return ans;
}

/*↓↓↓↓↓↓↓↓↓↓↓↓↓↓↓*/
int main() {
  IOS;
  while(1){
    ll n;
    cin>>n;
    if(n==0) return 0;
    vector<bool> isPrime=sieve_of_eratosthenes();
    ll ans=0;
    for(ll i=n+1;i<=2*n;i++) if(isPrime[i]) ans++;
    cout<<ans<<endl;
  }
}


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

using namespace std;

#define int long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define INF ((long long)1e18)
#define MOD ((int)1e9+7)
#define endl "\n"

#define yn(f) ((f)?"Yes":"No")
#define YN(f) ((f)?"YES":"NO")

#define MAX

signed main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout<<fixed<<setprecision(13);
	
	int N, K;
	long double p = 0.5;
	long double ans = 0;
	cin>>N>>K;
	
	for(int i = N, con = 1, t = 2; i >= 1; i--){
		if(i >= K){
			ans += 1.0/N;
			continue;
		}
		while(i*t < K){
				t *= 2;
				p /= 2.0;
		}
		// cout<<i<<" "<<p<<" "<<t<<endl;
		ans += p/N;
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<queue>
#include<algorithm>
#include<cmath>
#include<cstdio>
#include<cstring>
#include<cstdlib>
#include<complex>
#define INF 2147483647
#define llINF 9223372036854775807
#define pb push_back
#define mp make_pair 
#define F first
#define S second
#define ll long long

using namespace std;
ll mi=INF;
typedef struct E{
  int to,cost;
}edge;
const int MAX_V=300;
const int Inf=1e9;
vector<vector<edge> >E(MAX_V);
int d[MAX_V][MAX_V];
int n,m,r;
void dijkstra(int s,int alala){
  priority_queue<pair<int,int>,vector<pair<int,int> >,greater<pair<int,int> > >que;
  d[alala][s] = 0;
  que.push(pair<int,int>(0,s));
  while(!que.empty()){
    pair<int,int> p=que.top();que.pop();
    int v = p.second;
    if(d[alala][v]<p.first)continue;
    for(int j=0;j<E[v].size();j++){
      edge t = E[v][j];
      if(d[alala][t.to]>d[alala][v]+t.cost){
	d[alala][t.to]=d[alala][v]+t.cost;
	que.push(pair<int,int>(d[alala][t.to],t.to));
      }
    }
  }
}
int main(){
  cin>>n>>m>>r;
  for(int i=0;i<MAX_V;i++)
    for(int j=0;j<MAX_V;j++)
      d[i][j]=Inf;
  int R[8]={};
  for(int i=0;i<r;i++){
    cin>>R[i];
  }
  for(int i=0;i<m;i++){
    int a,b,c;cin>>a>>b>>c;
    edge e;e.to=b;e.cost=c;
    E[a].pb(e);e.to=a;
    E[b].pb(e);
  }
  for(int i=0;i<r;i++)
    dijkstra(R[i],R[i]);
  for(int i=0;i<r;i++){
    int bi=1<<i;
    for(int ii=0;ii<r;ii++){
      if(bi&(1<<ii))continue;
      int bi2=bi+(1<<ii);
      ll s=d[R[i]][R[ii]];
      for(int iii=0;iii<r;iii++){
	if(r==2){mi=min(mi,s);break;}
	if(bi2&(1<<iii))continue;
	int bi3=bi2+(1<<iii);
	ll s2=s+d[R[ii]][R[iii]];
	for(int i4=0;i4<r;i4++){
	  if(r==3){mi=min(mi,s2);break;}
	  if(bi3&(1<<i4))continue;
	  int bi4=bi3+(1<<i4);
	  ll s3=s2+d[R[iii]][R[i4]];
	  for(int i5=0;i5<r;i5++){
	    if(r==4){mi=min(mi,s3);break;}
	    if(bi4&(1<<i5))continue;
	    int bi5=bi4+(1<<i5);
	    ll s4=s3+d[R[i4]][R[i5]];
	    for(int i6=0;i6<r;i6++){
	      if(r==5){mi=min(mi,s4);break;}
	      if(bi5&(1<<i6))continue;
	      int bi6=bi5+(1<<i6);
	      ll s5=s4+d[R[i5]][R[i6]];
	      for(int i7=0;i7<r;i7++){
		if(r==6){mi=min(mi,s5);break;}
		if(bi6&(1<<i7))continue;
		int bi7=bi6+(1<<i7);
		ll s6=s5+d[R[i6]][R[i7]];
		for(int i8=0;i8<r;i8++){
		  if(r==7){mi=min(mi,s6);break;}
		  if(bi7&(1<<i8))continue;
		  ll s7=s6+d[R[i7]][R[i8]];
		  if(r==8){mi=min(mi,s7);break;};
		}
	      }
	    }
	  }
	}
      }
    }
  }
  cout<<mi<<endl;
  return 0;
}



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

int main() {
    int64_t a, b, c;
    cin >> a >> b >> c;

    if (c-a-b > 0 && 2*a*b + 2*b*c + 2*c*a < a*a + b*b + c*c) {
        cout << "Yes" << endl;
    }
    else {
        cout << "No" << endl;
    }
}


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

/* メモリ食い過ぎ注意 */
#define int long long

typedef long long ll;

int euclid(int a, int b)
{
    if (a < b)
        euclid(b, a);
    if (b == 0)
        return a;
    int r;
    while ((r = a % b))
    {
        a = b;
        b = r;
    }
    return b;
}

/* define const */
const ll INF = (1ll << 60);
const ll MOD = (ll)1e9 + 7;
/* end defineing */

signed main()
{
    int n;
    int a[3 * 100000];
    cin >> n;
    for (int i = 0; i < 3 * n; i++)
        cin >> a[i];
    sort(a, a + 3 * n, greater<int>());
    /*
    for (int i = 0; i < 3 * n; i++)
        cout << a[i] << " ";
    cout << endl;
*/
    int sum = 0;
    for (int i = 0; i < 2 * n; i += 2)
    {
        sum += a[i + 1];
    }
    cout << sum << endl;
}


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

using namespace std;

int n,m;
int i,j,k;
string str;
int h,w;

int main(){
    cin >> w >> h >> n;
    vector<pair<int,int> > b(n);
    vector<vector<int> > f(w);
    for(i = 0;i < n;i++){
        int x,y;
        cin >> x >> y;
        x--;y--;
        b[i] = make_pair(x,y);
    }
    sort(b.begin(),b.end());
    for(i = 0;i < n;i++){
        f[b[i].first].push_back(b[i].second);
    }
    int s = 1;
    int a = w;
    for(i = 1;i < w;i++){
        if(f[i].size() > 0){
            if(f[i][0] < s){
                a = i;
                break;
            }
            if(f[i][0] == s) s--;
        }
        s++;
    }
    cout << a << endl;
}


Measured memory_bytes: 12800
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
#include <cctype>
#define len length()
#define sz size()
#define rng(i, a, b) for(int i = a; i < b; i++)
#define rep(i, n) rng(i, 0, n)
#define srt(v) sort(v.begin(), v.end())
#define rev(s) reverse(s.begin(), s.end())
#define vi(a, n) vector<int> a(n)
#define vs(a, n) vector<string> a(n)
#define vc(a, n) vector<char> a(n)
#define psb(a) push_back(a)
#define ppb pop_back()
#define erc(S, i) S.erase(S.begin() + i)
#define ers(S, i, j) S.erase(S.begin() + i, S.begin() + j)
#define sp(n) cout << setprecision(n) << fixed
#define fst(s) s.at(0)
#define lst(s) s.at(s.len - 1)
typedef long long ll;
using namespace std;
int mod = 1000000007;

int main(){
    int N;
    cin >> N;
    vector<pair<ll, ll> > p(N);
    rep(i,N) cin >> p[i].second >> p[i].first;
    sort(p.begin(), p.end());
    ll sum = 0;
    string ans = "Yes";
    rep(i,N){
        sum += p[i].second;
        //cout << i << ":" << sum << "," << p[i].first << endl;
        if(sum > p[i].first){
            ans = "No";
            break;
        }
    }
    cout << ans << endl;
    return 0;
}

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

using namespace std;

typedef unsigned int ui;

int main(){
  int n,P,in;

  while(cin >> n ,n){
    vector<int> J;
    ui sum = 0;

    for(int i = 0 ; i < n ; i++){
      cin >> P;
      sum += P;
    }

    for(int i = 0 ; i < n-1 ; i++){
      cin >> in;
      sum += in;
      J.push_back(in);
    }

    ui ans = 0;
    sort(J.begin(),J.end());

    for(int i = 0,j = 1 ; i < n-1 ; i++,j++){
      ans = max(ans,sum*j);
      sum -= J[i];
    }

    cout << max(ans,sum*n) << endl;
  }

  return 0;
}

Measured memory_bytes: 1596
package main

import (
	"bufio"
	"fmt"
	"math"
	"os"
	"strconv"
)

const (
	initialBufSize = 10000
	maxBufSize     = 1000000
	mod            = 1e9 + 7
	maxN           = 110
	maxV           = 100100
)

var (
	sc *bufio.Scanner = func() *bufio.Scanner {
		sc := bufio.NewScanner(os.Stdin)
		buf := make([]byte, initialBufSize)
		sc.Buffer(buf, maxBufSize)
		sc.Split(bufio.ScanWords)
		return sc
	}()
)

func main() {
	N := getInt()
	W := getInt()
	ws := make([]int, N)
	vs := make([]int, N)
	for i := 0; i < N; i++ {
		ws[i] = getInt()
		vs[i] = getInt()
	}

	dp := make([][]int, maxN)
	for i := 0; i < maxN; i++ {
		dp[i] = make([]int, maxV)
		for j := 0; j < maxV; j++ {
			dp[i][j] = mod
		}
	}

	dp[0][0] = 0

	for i := 0; i < N; i++ {
		for j := 0; j < maxV; j++ {
			if j < vs[i] {
				dp[i+1][j] = dp[i][j]
				continue
			}

			dp[i+1][j] = min(dp[i][j], dp[i][j-vs[i]]+ws[i])
		}
	}

	result := 0
	for i := 0; i < maxV; i++ {
		if dp[N][i] <= W {
			result = i
		}
	}

	fmt.Println(result)
}

type Graph struct {
	n     int
	edges [][]int
}

func NewGraph(n int) *Graph {
	g := &Graph{
		n:     n,
		edges: make([][]int, n),
	}
	return g
}

func (g *Graph) AddEdge(u, v int) {
	g.edges[v] = append(g.edges[v], u)
	g.edges[u] = append(g.edges[u], v)
}

func dfs(c int, edges [][]int, visited map[int]struct{}) {
	visited[c] = struct{}{}

	for _, v := range edges[c] {
		_, flag := visited[v]
		if flag {
			continue
		}
		dfs(v, edges, visited)
	}
}

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getString() string {
	sc.Scan()
	return sc.Text()
}

func abs(a int) int {
	return int(math.Abs(float64(a)))
}

func pow(p, q int) int {
	return int(math.Pow(float64(p), float64(q)))
}

func powMod(n, p int) int {
	if p == 0 {
		return 1
	} else if p%2 == 0 {
		t := powMod(n, p/2)
		return calcMod(t * t)
	} else {
		return n * powMod(n, p-1)
	}
}

func min(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton min() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Min(float64(res), float64(nums[i])))
	}
	return res
}

func max(nums ...int) int {
	if len(nums) == 0 {
		panic("funciton max() requires at least one argument.")
	}
	res := nums[0]
	for i := 0; i < len(nums); i++ {
		res = int(math.Max(float64(res), float64(nums[i])))
	}
	return res
}

func strSearch(a []string, b string) bool {
	for i := 0; i < len(a); i++ {
		if a[i] == b {
			return true
		}
	}
	return false
}

func printIntArray(array []int) {
	strArray := fmt.Sprint(array)
	fmt.Println(strArray[1 : len(strArray)-1])
}

func calcMod(x int) int {
	return x % mod
}


Measured memory_bytes: 91948
#include <cstdio>

main() {
    int age;
    scanf("%d", &age);
    if (age == 1) {
        printf("Hello World\n");
    } else {
        int a, b;
        scanf("%d", &a);
        scanf("%d", &b);
        printf("%d\n", a + b);
    }
}

Measured memory_bytes: 128
n,m=map(int,input().split())
node=[[]for _ in range(n)]
for _ in range(m):
	a,b=map(int,input().split())
	node[a-1].append(b-1)
	node[b-1].append(a-1)
from collections import deque
sign=[-1]*n
sign[0]=0
queue=deque([0])
while queue:
	r=queue.popleft()
	for x in node[r]:
		if sign[x]==-1:
			sign[x]=r+1
			queue.append(x)
if -1 in sign:
	print("No")
else:
	print("Yes")
	for i in range(n-1):
		print(sign[i+1])

Measured memory_bytes: 36732
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
template <class T> using vec = vector<T>;
template <class T> using vvec = vector<vec<T>>;
template<class T> bool chmin(T& a,T b){if(a>b) {a = b; return true;} return false;}
template<class T> bool chmax(T& a,T b){if(a<b) {a = b; return true;} return false;}
#define all(x) (x).begin(),(x).end()
#define debug(x)  cerr << #x << " = " << (x) << endl;

int main(){
    int N,K;
    cin >> N >> K;
    vec<int> X(N);
    for(auto& x:X) cin >> x;
    int M = 18;
    vvec<ll> left(M,vec<ll>(N,-1)),left_val = left;
    vvec<ll> right(M,vec<ll>(N,N)),right_val = right;
    for(int i=0;i<N;i++){
        int id = lower_bound(all(X),X[i]+K)-X.begin();
        right[0][i] = id;
        right_val[0][i] = id;
        id = upper_bound(all(X),X[i]-K)-X.begin();
        id--;
        left[0][i] = id;
        left_val[0][i] = id;
    }
    for(int k=0;k+1<M;k++) for(int i=0;i<N;i++){
        int ne = right[k][i];
        if(ne!=N){
            right[k+1][i] = right[k][ne];
            right_val[k+1][i] = right_val[k][i]+right_val[k][ne];
        }
        ne = left[k][i];
        if(ne!=-1){
            left[k+1][i] = left[k][ne];
            left_val[k+1][i] = left_val[k][i]+left_val[k][ne];
        }
    }

    auto solve = [&](int l,int r){
        ll a = l;
        int now = l;
        int cnt = 1;
        for(int k=M-1;k>=0;k--){
            if(right[k][now]<=r){
                cnt += 1<<k;
                a += right_val[k][now];
                now = right[k][now];
            }
        }
        ll b = r;
        now = r;
        for(int k=M-1;k>=0;k--){
            if(left[k][now]>=l){
                b += left_val[k][now];
                now = left[k][now];
            }
        }
        cout << b-a+cnt << "\n";
    };

    int Q;
    cin >> Q;
    while(Q--){
        int l,r;
        cin >> l >> r;
        solve(l-1,r-1);
    }
}

Measured memory_bytes: 118144
#include<bits/stdc++.h>
#define int long long
using namespace std;
signed main(){
  int N;
  cin>>N;
  vector<vector<int>> A(N);
  vector<vector<int>> C(N,vector<int>(N,1000000000000000000));
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++){
      char c;
      cin>>c;
      if(i<j)continue;
      if(i==j){
        C[i][j]=0;
        continue;
      }
      if(c=='1'){
        C[i][j]=1;C[j][i]=1;
        A[i].push_back(j);
        A[j].push_back(i);
      }
    }
  vector<int> B(N,-1);
  B[0]=0;
  queue<int> Q;
  Q.push(0);
  while(!Q.empty()){
    int I=Q.front();
    Q.pop();
    for(int i:A[I]){
      if(B[i]==-1){
        B[i]=B[I]^1;
        Q.push(i);
      }else if(B[i]==B[I]){
        puts("-1");
        return 0;
      }
    }
  }
  for(int k=0;k<N;k++)
    for(int i=0;i<N;i++)
      for(int j=0;j<N;j++)C[i][j]=min(C[i][j],C[i][k]+C[k][j]);
  int mx=0;
  for(int i=0;i<N;i++)
    for(int j=0;j<N;j++)mx=max(mx,C[i][j]);
  cout<<mx+1<<endl;
}

Measured memory_bytes: 4220
#include<iostream>
#include<iomanip>
#include<map>
#include<set>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<queue>
#include<stack>
 
using namespace std;
 
#define P(p) cout<<(p)<<endl
#define rep(i,m,n) for(int i = (m); i < (int)(n); i++)
#define rrep(i,m,n) for(int i=(int)(m); i>=(int)(n); i--)
#define vsort(v) sort(v.begin(), v.end());
#define rvsort(v) sort(v.begin(), v.end(),greater<int>());
#define YES cout<<"YES"<< endl
#define NO cout<<"NO"<<endl
#define Yes cout<<"Yes"<<endl
#define No cout<<"No"<<endl  
#define yes cout<<"yes"<<endl
#define no cout<<"no"<<endl
#define ret return
#define C(i) cin>>i
#define C2(i,j) cin>>i>>j
#define C3(i,j,k) cin>>i>>j>>k
#define C4(i,j,k,m) cin>>i>>j>>k>>m
////////////////////////////////////////////////////////////

int main(){
  long n;
  cin >> n;
  map<string,int> d= {};
  for(long i = 0 ; i < n ; i++ ){
    string s;
    cin >> s;
    d[s]++;
  }
  long m;
  cin >> m;

  for(int i = 0 ; i < m ; i++ ){
    string m;
    cin >> m;
    if(d[m] == 0){
      NO;
      ret 0;
    }else{
      d[m]--;
    }

  }
  YES;
  ret 0;
}

Measured memory_bytes: 24960
#include <bits/stdc++.h>
using namespace std;
const long long INF = 1e18;
const int MAXN = 1e5  + 10;
long long dp[MAXN];
long long h[MAXN];
int main() {
  int n, k;
	cin >> n >> k;
  	for (int i = 1; i <= n; i++) {
    	cin >> h[i];
      dp[i] = INF;
    }
  	dp[1] = 0;
  for (int i = 1; i <= n; i++) {
  	for (int j = 1; j <= k && i + j <= n; j++) {
    	dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
    }
  }
                        
  cout << dp[n];
  return 0;
}

Measured memory_bytes: 1792
#include<bits/stdc++.h>
#define fi first
#define se second
#define pb push_back
#define SZ(x) ((int)x.size())
#define L(i,u) for (register int i=head[u]; i; i=nxt[i])
#define rep(i,a,b) for (register int i=(a); i<=(b); i++)
#define per(i,a,b) for (register int i=(a); i>=(b); i--)
using namespace std;
typedef long long ll;
typedef unsigned int ui;
typedef pair<int,int> Pii;
typedef vector<int> Vi;
template<class T> inline void read(T &x){
	x=0; char c=getchar(); int f=1;
	while (!isdigit(c)) {if (c=='-') f=-1; c=getchar();}
	while (isdigit(c)) {x=x*10+c-'0'; c=getchar();} x*=f;
}
template<class T> inline void umin(T &x, T y){x=x<y?x:y;}
template<class T> inline void umax(T &x, T y){x=x>y?x:y;}
inline ui R() {
	static ui seed=416;
	return seed^=seed>>5,seed^=seed<<17,seed^=seed>>13;
}
const int N = 1<<17|3;
int n,a,b,s[N];
void solve(int n, int l, int r, int a, int b, int ok){
	if(l+1==r){
		s[l]=a;s[r]=b;return;
	}
	int mid=(l+r)>>1,bit;
	rep(i,0,17)if((ok>>i&1)&&(a>>i&1)!=(b>>i&1)){bit=i;break;}
	int q=0;rep(i,0,17)if(i!=bit&&(ok>>i&1)){q=i;break;}
	solve(n-1,l,mid,a,a^(1<<q),ok&(~(1<<bit)));
	solve(n-1,mid+1,r,a^(1<<q)^(1<<bit),b,ok&(~(1<<bit)));
}
int getcnt(int x){
	int r=0;while(x)r++,x-=x&-x;return r;
}
int main() {
	read(n);read(a);read(b);
	if((getcnt(a)-getcnt(b))%2==0){puts("NO");return 0;}
	solve(n,1,1<<n,a,b,(1<<n)-1);
	puts("YES");
	rep(i,1,1<<n)printf("%d ",s[i]);
	return 0;
}


Measured memory_bytes: 1536
import java.io.*;
import java.util.*;
import java.util.function.IntPredicate;

public class Main {
	int W;
	int H;
	int[] P;
	int[] Q;
	public void solve() {
		W = nextInt();
		H = nextInt();
		P = new int[W];
		Q = new int[H];
		long ans = 0;
		for(int i = 0; i < W; i++){
			P[i] = nextInt();
			ans += P[i];
		}
		for(int i = 0; i < H; i++){
			Q[i] = nextInt();
			ans += Q[i];
		}
		Arrays.sort(Q);
		long[] sum = new long[H + 1];
		for(int i = 0; i < H; i++){
			sum[i + 1] = sum[i] + Q[i];
		}
		
		for(int i = 0; i < W; i++){
			final int val = P[i];
			int idx = lowerBound(0, H, v -> (v >= H || Q[v] >= val));
			ans += sum[idx] + (long)P[i] * (H - idx);
		}
		out.println(ans);
	}

	public int lowerBound(int begin, int end, IntPredicate check){
		int l = begin - 1;
		int r = end;
		while(r - l > 1){
			int m = (r + l) / 2;
			if(check.test(m)){
				r = m;
			}else{
				l = m;
			}
		}
		return r;
	}
	private static PrintWriter out;

	public static void main(String[] args) {
		out = new PrintWriter(System.out);
		new Main().solve();
		out.flush();
	}

	public static int nextInt() {
		int num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(; i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10 + (c - '0');
		}
		return minus ? -num : num;
	}

	public static long nextLong() {
		long num = 0;
		String str = next();
		boolean minus = false;
		int i = 0;
		if(str.charAt(0) == '-'){
			minus = true;
			i++;
		}
		int len = str.length();
		for(; i < len; i++){
			char c = str.charAt(i);
			if(!('0' <= c && c <= '9')) throw new RuntimeException();
			num = num * 10l + (c - '0');
		}
		return minus ? -num : num;
	}

	public static String next() {
		int c;
		while(!isAlNum(c = read())){}
		StringBuilder build = new StringBuilder();
		build.append((char)c);
		while(isAlNum(c = read())){
			build.append((char)c);
		}
		return build.toString();
	}

	private static byte[] inputBuffer = new byte[1024];
	private static int bufferLength = 0;
	private static int bufferIndex = 0;

	private static int read() {
		if(bufferLength < 0) throw new RuntimeException();
		if(bufferIndex >= bufferLength){
			try{
				bufferLength = System.in.read(inputBuffer);
				bufferIndex = 0;
			}catch(IOException e){
				throw new RuntimeException(e);
			}
			if(bufferLength <= 0) return(bufferLength = -1);
		}
		return inputBuffer[bufferIndex++];
	}

	private static boolean isAlNum(int c) {
		return '!' <= c && c <= '~';
	}
}


Measured memory_bytes: 31836
#include <stdio.h>

int main(void){
  long long int n,i=2;

  scanf("%lld", &n);
  printf("%lld:", n);
  while(i*i<=n){
    if(n%i==0){
      n/=i;
      printf(" %lld", i);
    }
    else i++;
  }
  if(n!=1) printf(" %lld", n);
  printf("\n");

  return 0;
}


Measured memory_bytes: 600
<?php

fscanf(STDIN, '%s %s %s', $a, $b, $c);

if (substr($a, strlen($a) -1, 1) === substr($b, 0, 1) && substr($b, strlen($b) -1, 1) === substr($c, 0, 1)) {
    echo 'YES';
} else {
    echo 'NO';
}

echo PHP_EOL;


Measured memory_bytes: 15956
// C++ 14
#include <bits/stdc++.h>
using namespace std;
template <typename T>  ostream& operator<<(ostream& os, const vector<T>& v)  {  os << "[";  for (int i = 0; i < v.size(); ++i) {  os << v[i];  if (i != v.size() - 1)  os << ", ";  }  os << "]";  return os;  }
template <typename T> void print(T v, string s = "\n") { cout << v << s; }
template <typename T> void in(T& v) { cin >> v; }
#define ll long long
#define loop(__x, __start, __end) for(int __x = __start; __x < __end; __x++)

int main() {
  int k;in(k);
  queue<ll> Q;
  loop(i,1,10) Q.push(i);
  ll ans = 0;
  while (k) {
    ans = Q.front(); Q.pop();
    k--;
    int d = ans%10;
    for (int i=d-1; i<=d+1; i++) {
      if (i<0 or i>=10) continue;
      Q.push(ans * 10 + i);
    }
  }
  print(ans);
  return 0;
}


Measured memory_bytes: 5080
//-----------------------------B-I-Y------------------------------------------------
#include<bits/stdc++.h>
using namespace std;
 
#define ll long long
#define ld long double
#define endl '\n'
#define fast ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
const ll M = 1000000007;

void solve(){
	ll n , m , i, j,val;
	cin >> n;
	ll a[n+1];
	memset(a,0,sizeof(a));
	for( i = 2 ; i <= n ; i++ ){
		cin >> val;
		a[val]++;
	}
	for( i = 1 ; i <= n ; i++ )
		cout << a[i] << '\n';
	// cout << endl;	

}

signed main(){
    fast;
    ll t=1;
    // cin >> t;
    while( t-- )
        solve();
    return 0;
}
//-----------------------------B-I-Y------------------------------------------------

Measured memory_bytes: 5176
#include <bits/stdc++.h>
#define pb push_back 
#define x first 
#define y second 
#define mod 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pll;

double n, a, b, c;

int main(){
    ios_base::sync_with_stdio(0); cin.tie(0);
    cin >> n;
    for (ll i = 1; i <= 3500; i++)
		for (ll j = 1; j <= 3500; j++){
			ll st = 1, dr = 3500;
			while (st <= dr){
				ll mid = (st + dr) / 2;
				double ch = (4.0*i*j*mid) / (i*j + j*mid + i*mid);
				if (ch > n) dr = mid - 1;
				else if (ch < n) st = mid + 1;
				else return cout << i << " " << j << " " << mid, 0;
			}
		}
} 


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

#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()
typedef long long int ll;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<ll> vll;
typedef vector<vi> vvi;

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


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

int main() {

    ios::sync_with_stdio(false);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;

    ll a, b;
    cin >> a >> b;

    cout << a * b / gcd(a, b) << endl;

    return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;
import java.math.BigDecimal;

public class Main {
	public static void main(String[] args) {
      	Scanner scan = new Scanner(System.in);
      	BigDecimal pi = new BigDecimal("3.14");
		BigDecimal in = new BigDecimal(scan.nextLine());
    	System.out.println(pi.multiply(in).multiply(new BigDecimal("2")));
    }
}

Measured memory_bytes: 35852
//AUTHOR: RAVAN_2070
//PUNE INSTITUTE OF COMPUTER TECHNOLOGY
/*
        PEOPLE'S LIVES DON'T END WHEN THEY DIE.
        IT ENDS WHEN THEY LOSE FAITH
                                     -ITACHI UCHIHA
        EXPLAINATION BELOW->
        
*/
#include<bits/stdc++.h>
using namespace std;
typedef unsigned long long int ull;
typedef long long int ll;
typedef long double ld;
typedef vector<ll> vi;
typedef vector<pair<ll,ll>> vii;
typedef pair<ll,ll> pii;
typedef map<ll,ll> mii;
#define MOD7 1000000007
#define MOD9 1000000009
#define pi 3.1415926535
#define Test_cases ll TC;cin>>TC;while(TC--)
#define fastio ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define pb push_back
#define mp make_pair
#define F first
#define S second
#define all(x) x.begin(),x.end()
#define rall(x) x.rbegin(), x.rend()
#define sp(x) fixed<<setprecision(x)
#define sz(x) (ll)(x.size())
#define fo(i,a,b) for(i=a;i<b;i++)
#define foe(i,a,b) for(i=a;i<=b;i++)
void solve()
{
   ll n,b,cnt=0;cin>>n>>b;
   while(n)
   {
       cnt++;
       n/=b;
   }
   cout<<cnt<<"\n";
}
int main()
{
   fastio
   solve();
  return 0;
}


Measured memory_bytes: 256
#pragma GCC optimize ("O3")
#pragma GCC target ("sse4")

#include <bits/stdc++.h>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/rope>

using namespace std;
using namespace __gnu_pbds;
using namespace __gnu_cxx;
 
typedef long long ll;
typedef long double ld;
typedef complex<ld> cd;

typedef pair<int, int> pi;
typedef pair<ll,ll> pl;
typedef pair<ld,ld> pd;

typedef vector<int> vi;
typedef vector<ld> vd;
typedef vector<ll> vl;
typedef vector<pi> vpi;
typedef vector<pl> vpl;
typedef vector<cd> vcd;

template <class T> using Tree = tree<T, null_type, less<T>, rb_tree_tag,tree_order_statistics_node_update>;

#define FOR(i, a, b) for (int i=a; i<(b); i++)
#define F0R(i, a) for (int i=0; i<(a); i++)
#define FORd(i,a,b) for (int i = (b)-1; i >= a; i--)
#define F0Rd(i,a) for (int i = (a)-1; i >= 0; i--)

#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define f first
#define s second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end()

const int MOD = 1000000007;
const ll INF = 1e18;
const int MX = 100001;

void setIn(string s) { freopen(s.c_str(),"r",stdin); }
void setOut(string s) { freopen(s.c_str(),"w",stdout); }

void io(string s = "") {
    ios_base::sync_with_stdio(0); cin.tie(0);
    if (sz(s)) {
    	setIn(s+".in");
    	setOut(s+".out");
    }
}

int n, ok[MX];

void addEdge(int a, int b) {
    if (a == 0 || b == 0) return;
    cout << a << " " << b << "\n";
}

int main() {
    io();
    string s; cin >> s; n = sz(s);
    FOR(i,1,n+1) ok[i] = s[i-1]-'0';
    if (!ok[1]) {
        cout << "-1";
        exit(0);
    }
    FOR(i,1,n+1) if ((ok[i]+ok[n-i]) % 2 != 0) {
        cout << "-1";
        exit(0);
    }
    ok[n] = 1;
    int lst = 0;
    FOR(i,1,n+1) {
        if (ok[i]) {
            addEdge(i,lst);
            FOR(j,lst+1,i) addEdge(j,i);
            lst = i;
        } 
    }
}

/* 
* (Actually read this pls)
    * Rlly bad errors: int overflow, array bounds
    * Less bad errors: special cases (n=1?), set tle
    * Common sense: do smth instead of nothing
*/

Measured memory_bytes: 2000
#include <bits/stdc++.h>
#define hell 1000000007
#define fast ios::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define pb push_back
#define ll long long int
#define pi 3.1415926536
using namespace std;

void solve()
{ll n,m,x,y,z,d,p=0,b=0,q,l=INT_MAX,k,mini=0,prev;
 string s,t;
 cin>>s>>t;
 n=s.length();
 m=t.length();
 //cout<<" "<<" ";
 
 //cout<<t[i]<<" ";
 //cout<<endl;
 vector<vector<ll> > v(n+1,vector<ll>(m+1,0));
 for(ll i=1;i<=n;i++)
 {   //cout<<s[i-1]<<" ";
 	for(ll j=1;j<=m;j++)
 	{	v[i][j]=max(v[i-1][j],v[i][j-1]);
 		if(s[i-1]==t[j-1])
 		v[i][j]=v[i-1][j-1]+1;
 	//cout<<v[i][j]<<" ";	
	 }
	 
  }
  ll i=n;
  ll j=m;
  string s1="";
  while(i>0&&j>0)
  {
  	 if(v[i][j]==v[i-1][j])
  	 {i=i-1;
	   }
	  else if(v[i][j]==v[i][j-1])
	  j=j-1;
	  else
	  {
	  	 s1+=s[i-1];
	  	 i--;
	  	 j--;
	  } 
  }
  reverse(s1.begin(),s1.end());
  cout<<s1;
   
}

int main()
{

ll t=1;

while(t--)
{solve();
 //cout<<ma<<endl;
}
return 0;}

Measured memory_bytes: 70784
#include<bits/stdc++.h>
using namespace std;
int main(){
    char s[10];//字符串
    cin>>s;
    int a,b,c,d;
    a=s[0]-'0';//分离
    b=s[1]-'0';
    c=s[2]-'0';
    d=s[3]-'0';
    for(int i=43;i<=45;i+=2){//本来准备用‘+’，‘-’的，后来想了想还是没用
        for(int j=43;j<=45;j+=2){
            for(int k=43;k<=45;k+=2){
                int ans=a;
                if(i==43){//厚颜无耻的判断
                    ans+=b;
                }
                else{
                    ans-=b;
                }
                if(j==43){
                    ans+=c;
                }
                else{
                    ans-=c;
                }
                if(k==43){
                    ans+=d;
                }
                else{
                    ans-=d;
                }
                if(ans==7){
                    cout<<a<<char(i)<<b<<char(j)<<c<<char(k)<<d<<"=7"<<endl;//只要输出一种
                    return 0;
                }
            }
        }
    }
    return 0;
}//////

Measured memory_bytes: 256
while (a,b,c=gets.split.map(&:to_i))!=[-1,-1,-1]
	if 2.step(16).none?{|base|begin Integer(a.to_s(base))==b rescue nil end} then p -1;next end
	(a+1).step(c){|i|
		b=2.step(16).map{|base|z=i.to_s(base).to_i;b<=z ? z : 1e9}.min
	}
	p b
end

Measured memory_bytes: 2576
def main():
    N = int(input())
    A = list(map(int, input().split()))

    mod = 10**9 + 7

    tmp = [0] * N

    s = 0
    for i in range(N):
        tmp[- i - 1] = s
        s += A[-i - 1]

    # print(tmp)

    ans = 0
    for i in range(N):
        ans += A[i] * tmp[i]

    print(ans % mod)


if __name__ == '__main__':
    main()


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

#define REP(i,n) for (int i=0;i<(n);i++)
#define PII pair<int,int>
#define LL long long

int main(){
  LL n,inp;
  LL sum = 0;
  LL min = 100;

  cin>>n;
  REP(i,n){
    cin>>inp;
    sum+=inp;
    if(inp < min && inp%10!=0){
      min = inp;
    }
  }

  if(sum%10 == 0){
    sum-=min;
  }
  if(min==100){
    sum=0;
  }
  cout<<sum<<endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.PrintWriter
import java.util.*

fun main(args: Array<String>) {
    abc138d()
}

fun abc138d() {
    val pw = PrintWriter(System.out)

    val (n, q) = readLine()!!.split(' ').map { it.toInt() }

    val paths = Array(n) { ArrayDeque<Int>() }
    val values = IntArray(n) { 0 }

    repeat(n - 1) {
        val line = readLine()!!.split(' ').map { it.toInt() }
        paths[line[0] - 1].add(line[1] - 1)
        paths[line[1] - 1].add(line[0] - 1)
    }

    repeat(q) {
        val line = readLine()!!.split(' ').map { it.toInt() }
        values[line[0] - 1] += line[1]
    }

    val visited = BooleanArray(n) { false }

    fun dfs(i: Int) {
        visited[i] = true

        repeat(paths[i].size) {
            val index = paths[i].poll()
            if (!visited[index]) {
                values[index] += values[i]
                dfs(index)
            }
        }
    }

    dfs(0)

    pw.print(values[0])
    values.drop(1).forEach {
        pw.print(" $it")
    }

    pw.println()
    pw.flush()
}


Measured memory_bytes: 148276
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<stdio.h>
#include<queue>
#include <climits>
#include <map>
#include <set>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
const int mod = 1e9 + 7;
const long long INF = 1LL << 60;
 
int main() 
{
    int n,d; cin >> n >> d;
    int p[n][d];
    int cnt = 0;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < d; j++){
            cin >> p[i][j];
        }
    }
    for(int i = 0; i < n-1;i++){
        int d2 = 0;
        for(int j = i+1; j < n; j++){
            d2 = 0;
            for(int k = 0; k < d; k++){
                d2 += ((p[j][k] - p[i][k]) * (p[j][k] - p[i][k]));
            }
            for(int k = 1; k <10000; k++){
                if(d2 == k * k) cnt++;
            }
        }
    }
    cout << cnt;
}

Measured memory_bytes: 256
#include <stdio.h>

#define N_MAX 100
#define M_MAX 100

int calcTime(int n, int *t)
{
  int i;
  int ans;

  ans = 0;
  for (i = 0; i < n; i++)ans += t[i];
  return(ans);
}

void calcAllPattern(void)
{
  int i;
  int n, m;
  int t[N_MAX], tt[N_MAX];
  int p, x;

  scanf("%d", &n);
  for (i = 0; i < n; i++) {
    scanf("%d", &t[i]);
    tt[i] = t[i];
  }

  scanf("%d", &m);
  for (i = 0; i < m; i++) {
    scanf("%d %d", &p, &x);
    p--;
    tt[p] = x;
    printf("%d\n", calcTime(n, tt));
    tt[p] = t[p];
  }
}

int main(void)
{
  calcAllPattern();
  return(0);
}

Measured memory_bytes: 128
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <string>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <map>
#include <set>
#include <climits>
#include <random>
#include <iomanip>

using namespace std;
using P = pair<long, long>;

typedef long long int ll;

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))

#define fillInt(xs, x)        \
  for (int i = 0; i < (x); i++) \
    scanf("%d", &xs[i]);
#define fillLong(xs, x)       \
  for (int i = 0; i < (x); i++) \
    scanf("%ld", &xs[i]);
#define fillString(xs, x)       \
  for (int i = 0; i < (x); i++) \
    cin >> xs[i];
#define sortv(xs) sort(xs.begin(), xs.end())
#define sortvinv(xs) sort(xs.begin(), xs.end(), std::greater<long>())
#define lbv(xs, x) lower_bound(xs.begin(), xs.end(), x) - xs.begin()
#define ubv(xs, x) upper_bound(xs.begin(), xs.end(), x) - xs.begin()
#define bs(xs, x) binary_search(xs.begin(), xs.end(), x)
#define index_of(as, x) \
  distance(as.begin(), lower_bound(as.begin(), as.end(), x))

#define rep(i,n) for(int i=0; i<(int)(n); i++)
#define concat(xs, ys) (xs).insert((xs).end(), (ys).begin(), (ys).end())

const int mod = 1000000007;

struct edge {
  int to;
  long cost;
};

const int MAX_V = 100005;
vector<edge> G[MAX_V];
long d[MAX_V];
int n, m;
vector<long> dn;

bool bellmanFord(int s) { 
  fill(d, d+n, -INF*INF);
  d[s] = 0;
  for (int i = 0; i < n; i++) {
    dn.push_back(d[n-1]);
    for (int v = 0; v < n; v++) {
      for (int k = 0; k < G[v].size(); k++) {
        edge e = G[v][k];
        if (d[v] != -INF*INF && d[e.to] < d[v] + e.cost) {
          d[e.to] = d[v] + e.cost;
          if (i == n - 1) {
            if (dn[dn.size()-1] > dn[dn.size()-2]) {
              return true;
            } else {
              return false;
            }
          }
        }
      }
    }
  }
  return false;
}

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

  cin >> n >> m;

  rep(i, m) {
    int a, b;
    long c;
    cin >> a >> b >> c;
    a--;
    b--;
    G[a].push_back({b, c});
  }

  bool isInf = bellmanFord(0);

  if (isInf) {
    cout << "inf" << endl;
  } else {
    cout << d[n-1] << endl;
  }
}

Measured memory_bytes: 2688
#include<bits/stdc++.h>
#define f(i,t,n) for(int i=(t);i<=(n);++i)
using namespace std;
int n,a[100005];
namespace Ri_Nai
{
	void pre()
	{
		scanf("%d",&n); 
		f(i,1,n)
			scanf("%d",a+i);
		sort(a+1,a+n+1,greater<int>());
	}
	void Main()
	{
		pre();
		f(i,1,n)
		{
			if(i+1>a[i+1])
			{
				int ans=0;
				for(int j=i+1;a[j]==i;++j)ans^=1;
				ans|=(a[i]-i)&1;
				if(ans)puts("First");
				else puts("Second");
				return ;
			}
		}
	}
}
int main()
{
	Ri_Nai::Main();
}


Measured memory_bytes: 640
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        long x = sc.nextLong();
        long y = sc.nextLong();
        long ans = 0;
        if (x < 0 & y > 0 || x > 0 && y < 0) {
            ans++;
        } else {
            if (x > y) {
                ans++;
                if (y > 0 || x < 0 ) {
                    ans++;
                }
            }
        }
        ans += Math.abs(Math.abs(x) - Math.abs(y));
        System.out.println(ans);
    }

}


Measured memory_bytes: 21972
#include <bits/stdc++.h>
#include <algorithm>
#include <iostream>
using namespace std;
 
int main() {
  int n;
  int sum,pl,pu;
  long ansl,ansu,ans;
  sum = 0;
  pl = 0;
  pu = 0;
  ans = 0;
  ansl = 0;
  ansu = 0;
  cin >> n;
  vector<int> x(n);

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

  pl = sum / n;
  pu = pl + 1; 

  for(int i = 0; i < n; i++) ansl += (x[i] - pl) * (x[i] - pl);
  for(int i = 0; i < n; i++) ansu += (x[i] - pu) * (x[i] - pu);

  ans = min(ansl,ansu);

  cout << ans << endl;
}

Measured memory_bytes: 3636
#include<iostream>

using namespace std;
struct st{
	st(){};
	st(int f1,int f2,int n1,int n2){
	fx=f1;
	fy=f2;
	nx=n1;
	ny=n2;
}
int fx;int fy;
int nx;int ny;
};

st dp[150][150];
int main(){
	
	for(int i=0;i<150;i++){
		dp[0][i]=st(0,1,0,0);
		dp[i][0]=st(1,0,0,0);
	}
	
	for(int i=1;i<150;i++){
		for(int j=1;j<150;j++){
			dp[i][j].fx=(dp[i-1][j].fx+dp[i-1][j].nx)%100000;
			dp[i][j].fy=(dp[i][j-1].fy+dp[i][j-1].ny)%100000;
			dp[i][j].nx=dp[i-1][j].fy;
			dp[i][j].ny=dp[i][j-1].fx;
		}
	}
	int w,h;
	while(cin>>w>>h && w &&h){
		w--;
		h--;
		int ans=dp[w][h].fx+dp[w][h].fy+dp[w][h].nx+dp[w][h].ny;
		cout<<ans%100000<<endl;
	}
}

Measured memory_bytes: 1512
#include <stdio.h>

int main()
{

 int x, y = 1;
 while(1)
 {
     scanf("%d", &x);
     if(x == 0)
     {
         break;
     }
     printf("Case %d: %d\n", y, x);
     y++;
 }
 return 0;
}

Measured memory_bytes: 600