akhauriyash/Code-Regression huggingface dataset:
<?php 
// ABC168 - B
    fscanf(STDIN, "%d", $K);
    fscanf(STDIN, "%s", $S);

    if(strlen($S) <= $K){
        echo $S;
    } else if (strlen($S) > $K){
        $kiritori = substr($S, 0, $K);
        echo $kiritori . '...';
    }

Measured memory_bytes: 16100
#include "bits/stdc++.h"
using namespace std;
///////////////////////////////////////////
const long long int INF = 1LL<<60;
const long long int Mod = 1000000007;
using ll = long long int; using ci = const int;
using vi = vector<int>;  using Vi = vector<long long int>;
using P = pair<int, int>;  using PLL = pair<ll, ll>;
using matrix = vector<vector<ll>>;
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define all(x) (x).begin(),(x).end()
#define rep(i,N) for(ll i = 0; i < (ll)N; i++)
#define repi(i,a,b) for(ll i = ll(a); i < ll(b); ++i)
template<class T>bool chmax(T &former, const T &b) { if (former<b) { former=b; return true; } return false; }
template<class T>bool chmin(T &former, const T &b) { if (b<former) { former=b; return true; } return false; }
template<class T>T sqar(T x){ return x*x; }//sqrt(x)は平方根;
#define Sort(v) std::sort(v.begin(), v.end(), std::greater<decltype(v[0])>()) //降順でVをソート
#define p_queue(v) priority_queue<v, vector<v>, greater<v> >
template<class T> inline void princ(T x){cout<<x<<" ";}; 
template<class T> inline void print(T x){cout<<x<<"\n";};
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
///////////////////////////////////////////////////////////////////////////////////

ll k;
string s;

int main(){
	cin.tie(0);ios::sync_with_stdio(false);
	std::cout<<std::fixed<<std::setprecision(30);
	cin>>k>>s;
	if(k>=s.size()){
		print(s);
	}else{
		string tp = s.substr(0,k);
		tp += "...";
		print(tp);
	}
	return 0;
}

Measured memory_bytes: 3652
#include <stdio.h>

int main()
{
	int W, H;
	int x, y, r;

	scanf("%d %d %d %d %d", &W, &H, &x, &y, &r);
	W -= r, H -= r;
	if (r <= x && x <= W && r <= y && y <= H) printf("Yes\n");
	else printf("No\n");
	return 0;
}



Measured memory_bytes: 2104
#include<iostream>
#include<string>
#include<algorithm>
#include<bits/stdc++.h>
 
using namespace std;
 
 int main(void){
     string A,B;
     long long sizeA,sizeB;
     cin >> A >> B;
     sizeA=A.size(); sizeB=B.size();
     if(sizeA>sizeB){
         cout << "GREATER" << endl;
         return 0;
     }else if(sizeA<sizeB){
         cout << "LESS" << endl;
         return 0;
     }else{
         for(int i=0; i<sizeA; i++){
             if(A[i]>B[i]){
                 cout << "GREATER" << endl;
                 return 0;
             }else if(A[i]<B[i]){
                 cout << "LESS" << endl;
                 return 0;
             }
         }
     }
     cout << "EQUAL" << endl;
 }

Measured memory_bytes: 256
x,y = [int(x) for x in input().split()]

if x >= 0 and y >= 0 and x <= y:
    print(y-x)
elif x >= 0 and y >= 0 and y < x:
    if y != 0:
        print(x-y+2)
    else:
        print(x-y+1)
elif x < 0 and y < 0 and y < x:
    print(x-y+2)
elif x < 0 and y < 0 and x < y:
    print(y-x)
elif x >= 0 and y < 0:
    print(abs(abs(y)-x)+1)
elif x < 0 and y >= 0:
    print(min(abs(abs(x)-y)+1, y-x))

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
int main() {
	int n, count = 0;
	cin >> n;
	vector<int> a(n + 1);
	a[0] = 0;
	for(int i = 1; i <= n; i++) cin >> a[i];

	for(int i = 1; i <= n; i++) {
		if(i == a[a[i]]) {
			count++;
		}
	}
	cout << count / 2 << endl;

	return 0;
}

Measured memory_bytes: 640
#include<stdio.h>
int main(){
	int i,j;
	double a[5];
	for(i=0;i<3;i++)
		scanf("%lf",&a[i]);
	for(i=1;i<3;i++){
		for(j=0;j<3-i;j++){		
		if(a[j]>a[j+1])
		{int t=a[j];a[j]=a[j+1]; a[j+1]=t;
		}
		}
	}
	double z=a[2]-a[0];	
	printf("%.0lf",z);
}

Measured memory_bytes: 128
//package cf;
import java.io.*;
import java.util.*;
public class Main {
    static int p=1000000007;
    public static void main(String[] args) throws Exception{
        BufferedWriter out = new BufferedWriter(new OutputStreamWriter(new FileOutputStream(java.io.FileDescriptor.out), "ASCII"), 512);
        FastReader sc=new FastReader();
        int n = sc.nextInt();
        int W = sc.nextInt();
        int w[]=new int[n];
        int v[]=new int[n];
        for(int i=0;i<n;i++)
        {
            w[i]=sc.nextInt();
            v[i]=sc.nextInt();
        }

        StringBuilder sb=new StringBuilder();
        long dp[][]=new long[n+1][W+1];
        for(int i=1;i<=n;i++)
        {
            for(int j=1;j<=W;j++)
            {
                if(j-w[i-1]>=0)
                {
                    dp[i][j]=Math.max(dp[i-1][j],v[i-1]+dp[i-1][j-w[i-1]]);
                 //   System.out.println(i+"  "+j+" "+dp[i][j]);
                }
                else
                {
                    dp[i][j]=Math.max(dp[i][j],dp[i-1][j]);
                }
            }
        }
        sb.append(dp[n][W]);
        out.write(sb.toString());
        out.flush();
    }


static class pair
{
    long a,d;
    StringBuilder sb;

    public pair(long a, long d, StringBuilder sb) {
        this.a = a;
        this.d = d;
        this.sb = sb;
    }
}



    ///////////////////////////////////////////////////////////////////////////////////
//////////////////////////////////////////////////////////////////////////////////////////////
    static class FastReader {

        BufferedReader br;
        StringTokenizer st;

        public FastReader() {
            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: 138644
#include <bits/stdc++.h>
using namespace std;

typedef long long ll;
const ll MOD = 1e9 + 7;

int a[3] = {3, 5, 7};
int solve(string &S, const string &N, bool b[3]) {
    if (S.size() > N.size()) return 0;
    if (S.size() == N.size() && S > N) return 0;
    int ret = 0;
    if (b[0] && b[1] && b[2]) ret++;
    for (int i = 0; i < 3; i++) {
        S.push_back(a[i] + '0');
        bool tmp = b[i];
        b[i] = 1;
        ret += solve(S, N, b);
        b[i] = tmp;
        S.pop_back();
    }
    return ret;
}
int main() {
    string S = "";
    string N;
    cin >> N;
    bool b[3] = {};
    cout << solve(S, N, b) << endl;
}

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

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

#define BE(x) x.begin(), x.end()

const llong inf = llong(1e18)+7;
const llong mod = 1e9+7;

llong GCD(llong a, llong b){
	a = abs(a), b = abs(b);
	if(a < b) swap(a, b);
	if(b == 0) return a;
	while(b){
		a %= b;
		swap(a,b);
	}

	return a;
}

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

int main(){
	llong N, K;
	vector<llong> A;
	llong gcd;

	cin >> N >> K;
	A.resize(N);
	for(int i = 0; i < N; i++){
		cin >> A[i];
		if(i == 0)
			gcd = A[i];
		else
			gcd = GCD(gcd, A[i]);
	}
	cerr << endl;

	bool check = false;
	for(int i = 0; i < N; i++){
		if(A[i] == K)
			check = true;
		if(A[i] > K && (A[i] - K)%gcd == 0)
			check = true;
	}

	if(check)
		cout << "POSSIBLE" << endl;
	else
		cout << "IMPOSSIBLE" << endl;

	return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define INF 1LL<<62
#define inf 1000000007

int main() {
	ll n;
	cin>>n;
	ll ans=0;
	ans+=n/500*1000;
	ans+=n%500/5*5;
	cout <<ans;
	// your code goes here
	return 0;
}


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

#define rep(i, n) for(int i = 0; i<(n); i++)
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
using ll = long long;

template<typename T>
struct BIT {
    int n;
    vector<T> d;

    BIT(int n = 0) : n(n), d(n + 1) {}

    void add(int i, T x = 1) {
        for (i++; i <= n; i += i & -i) {
            d[i] += x;
        }
    }

    T sum(int i) {
        T x = 0;
        for (i++; i; i -= i & -i) {
            x += d[i];
        }
        return x;
    }
};

int main() {
    int N, Q;
    string S;
    cin >> N >> S >> Q;
    vector<BIT<int>> bits(26, BIT<int>(N + 1));

    rep(i, N) bits[S[i] - 'a'].add(i + 1, 1);

    rep(_, Q) {
        int type;
        cin >> type;
        if (type == 1) {
            int i;
            char c;
            cin >> i >> c;
            i--;
            bits[S[i] - 'a'].add(i + 1, -1);
            S[i] = c;
            bits[S[i] - 'a'].add(i + 1, 1);
        } else {
            int l, r;
            cin >> l >> r;
            l--;
            int ans = 0;
            rep(i, 26) {
                if (bits[i].sum(r) - bits[i].sum(l) > 0) ans++;
            }
            cout << ans << endl;
        }
    }
}


Measured memory_bytes: 53636
// written by @kakira9618
// problem: 

#include <iostream>
#include <vector>
#include <string>
#include <algorithm>

#define mp       make_pair
#define all(x)   (x).begin(),(x).end()
using namespace std;
  
typedef    pair<int, int>      pii;

pii dfs(string &s, int now) {
    if (s[now] == '[') {
        vector<int> chiku;
        while(s[now] == '[') {
            pii ret = dfs(s, now + 1);
            now = ret.first;
            chiku.push_back(ret.second);
        }
        sort(all(chiku));
        int sum = 0;
        for(unsigned i = 0; i < chiku.size() / 2 + 1; i++) {
            sum += chiku[i];
        }
        return mp(now + 1, sum);
    } else if (s[now] != ']') {
        int num = 0;
        while(isdigit(s[now])) {
            num *= 10;
            num += s[now] - '0';
            now++;
        }
        return mp(now + 1, num / 2 + 1);
    }
    return mp(s.size(), -1);
}

void solve(string &s) {
    pii ret = dfs(s, 0);
    cout << ret.second << endl;
}

int main() {
    int T;
    cin >> T;
    for(int t = 0; t < T; t++) {
        string s;
        cin >> s;
        solve(s);
    }
    return 0;
}

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

#define REP(i,a) for(long i=0;i<(a);++i)

typedef std::vector<int>  VI;

int N;
VI imos(100002, 0);
int main() {
    std::cin >> N;

    REP(i, N) {
        int a, b;
        std::cin >> a >> b;
        ++imos[a];
        --imos[b+1];
    }

    int x = 0, ans = 0;
    for(int i=0; i<=N+1; ++i) {
        x += imos[i];
        if(x + 1 >= i) {
            ans = i - 1;
        }
    }
    std::cout << ans << std::endl;
    return 0;
}


Measured memory_bytes: 3100
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#include <ext/pb_ds/detail/standard_policies.hpp>
using namespace __gnu_pbds;
using namespace std;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag,
    tree_order_statistics_node_update>;
 
typedef long long int ll;
const ll N = 1e6 +9;
const ll p = 31;
const ll m = 1e9 + 7;
const ll inf= 1e14;
const ll mod = 1e9+7;
#define w first
#define v second
#define pb push_back
#define mp make_pair

const int MAX_N = 105, MAX_K = 1e5 + 5, MOD = 1e9 + 7;

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

     ll q = 1;
     // cin>>q;
     while(q--){
          ll h,n;cin>>h>>n;
          ll a[n],ans = 0;
          for(int i = 0;i<n;i++){
               cin>>a[i];
               ans+=a[i];
          }
          if(ans<h){
               cout<<"No"<<'\n';
          }
          else{
               cout<<"Yes"<<'\n';
          }
     }
}         

Measured memory_bytes: 1024
N, Y = list(map(int, input().split()))
for i in range(N,-1,-1):
    y2 = Y - 10000 * i
    if y2 >= 0:
        for j in range(N-i,-1,-1):
            y3 = y2 - 5000 * j
            k = N - i - j
            if k >= 0 and y3 - 1000 * k == 0:
                print(i, j, k)
                break
        else:
            continue
        break
else:
    print(-1, -1, -1) 

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

void solve(){
  long long int a , b, x,p;
  cin>>a>>b>>x;
  p=a;
  if(a!=0){
    a--;
  }
  long long int ans = (b/x) - (a/x) ;
  if(p==0){
    ans++;
  }
  cout<<ans<<endl;
}
int main(){
    
    solve();
    
}    

Measured memory_bytes: 3564
N = int(input())
a_list = [int(input())for _ in range(N)]

count_dct = {}
for input_num in a_list:
    if input_num in count_dct.keys():
        count_dct[input_num] += 1
    else:
        count_dct[input_num] = 1
        
counter = 0
for i, j in count_dct.items():
    if j%2 == 1:
        counter +=1
    else:
        pass
    
print(counter)

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

using namespace std;

typedef pair<int, int> P;
typedef long long LL;

LL gcd(LL a, LL b) {
    if (b == 0) {
        return a;
    }
    return gcd(b, a % b);
}

LL lcm(LL a, LL b) {
    return a * (b / gcd(a, b));
}

int main() {
    int n;
    cin >> n;
    vector<LL> t(n);
    for (int i = 0; i < n; i++) {
        cin >> t[i];
    }
    LL l = t[0];
    for (int i = 1; i < n; i++) {
        l = lcm(l, t[i]);
    }

    cout << l << endl;

    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, string> P;

int main() {
  int N; cin >> N;
  vector<string> s;
  for (int i = 0; i < N; i++) {
    string str; cin >> str;
    s.push_back(str);
  }
  sort(s.begin(), s.end());
  
  
  vector<P> vec;
  int p = 0;
  int maxl = 0;
  for (int i = 0; i < N-1; i++) {
    if (s[i] != s[i+1]) {
      vec.push_back(P(i+1-p, s[i]));
      maxl = max(maxl, i+1-p);
      p = i+1;

    }
  }
  vec.push_back(P(N-p, s[N-1]));
  maxl = max(maxl, N-p);

  
  for (int i = 0; i < vec.size(); i++) {
    if (vec[i].first == maxl) {cout << vec[i].second << endl;}
  }
}
  
  
    

Measured memory_bytes: 18288
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define pii pair<ll>
#define fi first
#define se second
#define pb push_back
#define all(x) x.begin(),x.end()
#define vll vector<ll>
#define M 200011
#define MOD 1000000007
ll md=MOD;

ll dp[M][2];
vll g[M];

ll dfs(ll u,ll pa){
	ll a1=1,a2=1;
	for(auto x:g[u]){
		if(x==pa)continue;
		dfs(x,u);
		a1=a1*(dp[x][0]+dp[x][1])%md;a1%=md;
		a2=a2*(dp[x][0])%md;a2%=md;
	}
	dp[u][0]=a1;dp[u][1]=a2;
}

int main()
{

    ios_base::sync_with_stdio(false);cin.tie(0);cout.tie(0);
	ll t,i,j,m,x,y,n,z,p,k,T;string s2,s3;x=1;
	cin>>n;
	for(i=0;i<n-1;++i){
		cin>>x>>y;g[x].pb(y);g[y].pb(x);
	}dfs(1,-1);
	cout<<(dp[1][0]+dp[1][1])%md<<"\n";
















	
	return 0;
}

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

int main() {
  int N;
  cin >> N;
  vector<int> A(N-1);
  vector<int> B(N);
  for (int i=0; i<N-1; i++) {
    cin >> A.at(i);
    B.at(A.at(i)-1)+=1;
    }
  for (int i=0; i<N; i++) {
    cout << B.at(i) << endl;
  }
}

Measured memory_bytes: 4844
#define _CRT_SECURE_NO_WARNINGS
#include<stdio.h>

int n, A[50];

// 入力値の M から選んだ要素を引いていく再帰関数
int solve(int i, int m) {
	if (m == 0) return 1;
	if (i >= n) return 0;
	int res = solve(i + 1, m) || solve(i + 1, m - A[i]);
	return res;

}

int main() {
	int q, M, i;

	scanf("%d", &n);
	for (i = 0; i < n; i++) scanf("%d", &A[i]);
	scanf("%d", &q);
	for (i = 0; i < q; i++) {
		scanf("%d", &M);
		if (solve(0, M)) printf("yes\n");
		else printf("no\n");
	}
	return 0;
}


Measured memory_bytes: 2680
package main

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

var (
	readString func() string
	stdout     *bufio.Writer
)

func init() {
	readString = newReadString(os.Stdin)
	stdout = bufio.NewWriter(os.Stdout)
}

func newReadString(ior io.Reader) func() string {
	r := bufio.NewScanner(ior)
	r.Buffer(make([]byte, 1024), int(1e+11))
	r.Split(bufio.ScanWords)

	return func() string {
		if !r.Scan() {
			panic("Scan failed")
		}
		return r.Text()
	}
}

func readInt() int {
	return int(readInt64())
}

func readInt64() int64 {
	i, err := strconv.ParseInt(readString(), 0, 64)
	if err != nil {
		panic(err.Error())
	}
	return i
}

func readIntSlice(n int) []int {
	b := make([]int, n)
	for i := 0; i < n; i++ {
		b[i] = readInt()
	}
	return b
}

func readLengthAndSlice() []int {
	n := readInt()
	return readIntSlice(n)
}

func printf(f string, args ...interface{}) (int, error) {
	return fmt.Fprintf(stdout, f, args...)
}

func println(args ...interface{}) (int, error) {
	return fmt.Fprintln(stdout, args...)
}

func minInt(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func minUint(a, b uint) uint {
	if a < b {
		return a
	}
	return b
}

func minInt64(a, b int64) int64 {
	if a < b {
		return a
	}
	return b
}

func minUint64(a, b uint64) uint64 {
	if a < b {
		return a
	}
	return b
}

func maxInt(a, b int) int {
	if a < b {
		return b
	}
	return a
}

func maxUint(a, b uint) uint {
	if a < b {
		return b
	}
	return a
}
func maxInt64(a, b int64) int64 {
	if a < b {
		return b
	}
	return a
}

func maxUint64(a, b uint64) uint64 {
	if a < b {
		return b
	}
	return a
}

func absInt(a int) int {
	if a < 0 {
		return -a
	}
	return a
}

func absInt64(a int64) int64 {
	if a < 0 {
		return -a
	}
	return a
}

// readString() string
// readInt() int
// readIntSlice(n int) []int
// readLengthAndSlice() []int
func main() {
	defer stdout.Flush()

	n := readInt()
	x := readInt64()
	a := make([]int64, n)
	for i := 0; i < n; i++ {
		a[i] = readInt64()
	}

	var ans int64
	if a[0] > x {
		ans += a[0] - x
		a[0] = x
	}
	for i := 1; i < n; i++ {
		s := a[i-1] + a[i]
		if s <= x {
			continue
		}

		d := s - x
		ans += d
		a[i] -= d
	}
	println(ans)

}


Measured memory_bytes: 3072
<?php
$n = trim(fgets(STDIN));
$a = explode(" ",trim(fgets(STDIN)));
$a = array_count_values($a);
$q = pow(10,9) + 7;
$ans = 1;
 
$c = 0;
$i = $n - 1;
while($i >= 0){
if($i != 0){
if($a[$i] != 2){
++$c;
$i = 0;
}
}else{
if($a[0] != 1){
++$c;
}
}
$i -= 2;
}
 
if($c != 0){
echo 0;
}else{
$num = floor($n / 2);
while($num > 29){
$num -= 30 ;
$ans *= (pow(2,30) % $q);
$ans %= $q;
}
echo ($ans * (pow(2,$num) % $q)) % $q;
}
?>

Measured memory_bytes: 29932
#include <stdio.h>

int main() {
  int i, j, k;
  int sum = 0;
  int C[4][4];
  for (i = 1; i <= 3; i++) {
    for (j = 1; j <= 3; j++) {
      scanf("%d", &C[i][j]);
    }
  }
  if ( C[1][1]+C[2][2]+C[3][3] == C[1][1]+C[2][3]+C[3][2]
    && C[1][1]+C[2][3]+C[3][2] == C[1][2]+C[2][3]+C[3][1]
    && C[1][2]+C[2][3]+C[3][1] == C[1][2]+C[2][1]+C[3][3]
    && C[1][2]+C[2][1]+C[3][3] == C[1][3]+C[2][1]+C[3][2]
    && C[1][3]+C[2][1]+C[3][2] == C[1][3]+C[2][2]+C[3][1] ) {
      puts("Yes");
    } else {
      puts("No");
    }
  return 0;
}


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

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

signed main() {

    int N;  cin >> N;
    vector<ll> A(N);  REP(i, N) cin >> A[i];

    set<ll> st;
    for (auto& e: A) {
        auto mp = prime_factor(e);
        for (auto& f: mp) {
            st.insert(f.first);
        }
    }

    ll ans = 0;
    for (auto itr = st.begin(); itr != st.end(); ++itr) {
        // cerr << "! : " << *itr << endl;z
        ll sum = 0;
        REP(i, N) {
            if (A[i] % *itr == 0) {
                // cerr << A[i] << ' ' << *itr << endl;
                sum += A[i];
            }
        }
        // cerr << endl;
        ans = max<ll>(ans, sum);
    }

    cout << ans << endl;

}


Measured memory_bytes: 3168
#include <bits/stdc++.h>
using namespace std;
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  FOR(i,0,n)
#define dump(x) cout << (x) << endl
typedef long long ll;
typedef pair<ll, ll> pl;
typedef pair<int, int> pi;
typedef vector<int> V;

int main() {
  int a, b, c, d, e, f;
  cin >> a >> b >> c >> d >> e >> f;
  a *= 100; b *= 100;
  double ma = -1.0;
  int x, y;
  for (int i = 0; i <= f; i += a) {
    for (int j = 0; i+j <= f; j += b) {
      if (i == 0 && j == 0) continue;
      for (int k = 0; k <= ((i+j)/100)*e; k += c) {
	for (int l = 0; k+l <= ((i+j)/100)*e; l += d) {
	  if (i+j+k+l > f) break;
	  double xx = (double)(k+l)/(double)(i+j+k+l);
	  if (xx > ma) {
	    ma = xx;
	    x = i+j+k+l;
	    y = k+l;
	  }
	}
      }
    }
  }
  cout << x << " " << y << endl;
  return 0;
}


Measured memory_bytes: 256
var
s:string[20];
min,a,b,c,l,i,j,k:longint;
begin
readln(s);
min:=753;
l:=length(s);
for i:=1 to l-2 do
begin
j:=i+1; k:=i+2;
a:=ord(s[i])-48;
b:=ord(s[j])-48;
c:=ord(s[k])-48;
a:=a*100+b*10+c;
if abs(a-753)<min then min:=abs(a-753);
end;
writeln(min);
end.


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

int main(void){
	int h,n;
	cin>>h>>n;
	vector<int> a(n);
	for(int i=0;i<n;i++){
		cin>>a[i];
	}
	for(int i=0;i<n;i++){
		h-=a[i];
		if(h<=0){
			cout<<"Yes"<<'\n';
			return 0;
		}
	}
	cout<<"No"<<'\n';

	return 0;
}

Measured memory_bytes: 640
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<cstdlib>



using namespace std;

int n,k,R,S,P;
int arr[100001];
int rock = 1,scissor = 2, paper = 3;
int ans=0;
string s;

int main(){
    cin >> n >> k;
    cin >> R >> S >> P ;
    cin >> s;
    for(int i=0;i<s.size();i++){
        if(s[i] == 'r'){
            arr[i] = rock;
        }
        else if(s[i] == 's'){
            arr[i] = scissor;
        }
        else if(s[i] == 'p'){
            arr[i] = paper;
        }
    }
    
    for(int i=0;i<k;i++){
        for(int j=i;j<n;j+=k){
            if(arr[j] == rock) ans += P;
            else if(arr[j] == scissor) ans += R;
            else if(arr[j] == paper) ans += S;

            if(j+k < n){
                if(arr[j] == arr[j+k]) j += k;
            }
        }
    }

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

Measured memory_bytes: 896
#include <iostream>
#include <iomanip>
using namespace std;

int main() {
	double a, b, c, d, e, f, x, y;
	cout << fixed << setprecision(3);
	while (cin >> a >> b >> c >> d >> e >> f) {
		x = (c * e - b * f) / (a * e - b * d);
		y = (c - a * x) / b;
		x *= 1000; x = x + (x > 0 ? 0.5 : -0.5); x = (int)x;
		y *= 1000; y = y + (y > 0 ? 0.5 : -0.5); y = (int)y;
		cout << x / 1000 << " " << y / 1000 << endl;
	}
	return 0;
}


Measured memory_bytes: 3188
import bisect

def next_int():
    return int(input())

def next_ints():
    return list(map(int, input().split()))

n = next_int()
a = next_ints()
a.sort()
ans = 0
for i in range(n-2):
    for j in range(i+1, n-1):
        pos = bisect.bisect_right(a, a[i] + a[j] - 1, j+1, n)
        ans += pos - j - 1
print(ans)


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


#define int long long 


const int N = 1e5 + 7;

int h[N];


int chk(int x, int a, int b, int n) {
	int cnt = 0;
	for(int i = 1; i <= n; i++) {
		int y = h[i] - b * x;
		if(y > 0) {
			cnt += (y - 1) / a + 1;
		}
	}
	return cnt <= x;
}

int32_t main() {
	ios_base :: sync_with_stdio(0); cin.tie(0); cout.tie(0);
	int n, a, b; cin >> n >> a >> b;
	for(int i = 1; i <= n; i++) {
		cin >> h[i];
	}
	int l = 1, r = *max_element(h + 1, h + n + 1);

	while(l < r) {
		int mid = (l + r) >> 1;
		if(chk(mid, a - b, b, n)) {
			r = mid;
		} else {
			l = mid + 1;
		}
	}
	cout << r << endl;

}

Measured memory_bytes: 4400
#include <iostream>
#include <string>
#include <sstream>
#include <algorithm>

struct compstr
{
	std::string text;

	compstr(std::string&& text) : text(text) {}

	bool operator<(const compstr& other)
	{
		if (text.size() == other.text.size())
		{
			for (int n = 0; n < text.size(); ++n)
			{
				if (text.at(n) < other.text.at(n))
					return true;
				else if (text.at(n) > other.text.at(n))
					return false;
			}

			return false;
		}

		else
		{
			int smaller = std::min(text.size(), other.text.size());

			for (int n = 0; n < smaller; ++n)
			{
				if (text.at(n) < other.text.at(n))
					return true;
				else if (text.at(n) > other.text.at(n))
					return false;
			}

			return text.size() < other.text.size();
		}
	}

	bool operator==(const compstr& other)
	{
		return text == other.text;
	}
};

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

	int t = 0;
	int h = 0;

	for (int i = 0; i < n; ++i)
	{
		std::string ts;
		std::string hs;

		std::cin >> ts >> hs;

		if (ts < hs)
			h += 3;
		else if (ts == hs)
		{
			t++;
			h++;
		}
		else
			t += 3;
	}

	std::cout << t << " " << h << std::endl;

	return 0;
}


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

int main(){
    int N, P;
    cin >> N >> P;
    int even=0, odd=0;
    for (int i = 0; i < N; i++) {
        int a;
        cin >> a;
        if (a%2==0) even++;
        else odd++;
    }
    if (P == 1 && odd == 0) {
        cout << 0 << endl;
        return 0;
    }
    ll ans = 1;
    for (int i = 0; i < even; i++) ans *= 2;
    for (int i = 0; i < odd-1; i++) ans *= 2;
    cout << ans << endl;
    return 0;
}

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

#define rep(i, n) for(int i = 0; i < (n); ++i)

using namespace std;

using ll = long long;
using P = pair<int , int>;
  
int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);

  int a[4]; rep(i, 4) cin >> a[i];

  int ans = 0;

  if(a[0] <= a[3]) {
    ans += a[0];
    a[3] -= a[0];
  } else if(a[0] > a[3]) {
    ans = a[3];
    a[3] = 0;
  }
  if(a[1] <= a[3]) {
    a[3] -= a[1];
  } else {
    a[3] = 0;
  }
  if(a[2] <= a[3]) {
    ans -= a[2];
  } else {
    ans -= a[3];
  }
  cout << ans << endl;
}
    


Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <ctype.h>
#include <string.h>

int main(int argc, char *argv[]){
        int r;
        double pi = 3.1415926535897932;
        double ans;
        scanf("%d",&r);
        ans = 2 * r * pi;
        printf("%lf",ans);
        return 0;
}

Measured memory_bytes: 2140
let n, m = stdin.ReadLine().Split() |> fun x -> (int x.[0], int x.[1])
let x = stdin.ReadLine().Split() |> Array.map int |> Array.sort
[1..m - 1] |> List.map (fun y -> x.[y] - x.[y - 1]) |> List.sortDescending |> List.skip (min (n - 1) (m - 1)) |> List.sum |> printfn "%d"

Measured memory_bytes: 34384
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
	ll a,b;
	cin >> a >> b;
	if(a>b){
        cout << "a > b" << endl;
    }else if(a<b){
        cout << "a < b" << endl;
    }else{
        cout << "a == b" << endl;
	}
}


Measured memory_bytes: 3100
#include <iostream>
#include <cmath>
#include <vector>

using namespace std;

int digit(int n, int d) {
	int m = (int)(n/pow(10,d)) * pow(10,d);
	return (n - m)/pow(10,d-1);
}

int check_digit(int n) {
	for (int i = 10; i > 0; i--) {
		if (digit(n, i) > 0) {
			return i;
		}
	}
	return 1;
}

int main(void) {
	long long N;
	cin >> N;
	int res;
	for (int i = 1; i < sqrt(N)+1; ++i) {
		if (N%i == 0) {
			res = check_digit(N/i);
		}
	}
	cout << res << endl;
	return 0;
}


Measured memory_bytes: 512
module Main where

import Control.Applicative
import Control.Monad
import Data.List

main :: IO ()
main = do
    getLine
    as <- fmap read . words <$> getLine :: IO [Int]
    let summ = sum as
    let cs = scanl1 (+) (init as)
    let ds = fmap (`subtract` summ) cs
    let es = zipWith (\c d -> abs $ c - d) cs ds
    let ans = minimum es
    print ans

Measured memory_bytes: 61820
#include <iostream>

int main()
{
  int n1, n2;
  
  std::cin >> n1 >> n2;
  
  if (n1 >= 1 && n1 <= 9 && n2 >= 1 && n2 <= 9)
    std::cout << n1 * n2;
  else
    std::cout << -1;
  
  return 0;
}

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

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

  double x1, y1, x2, y2;
  cin >> x1 >> y1 >> x2 >> y2;
  cout << fixed << setprecision(9) << sqrt((x1 - x2) * (x1 - x2) + (y1 - y2) * (y1 - y2)) << endl;
} 


Measured memory_bytes: 3244
#include <iostream>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;

#include <math.h>
#include <iomanip>
#include <vector>
#include <queue>
using Graph = vector<vector<int>>;
const double PI = 3.14159265358979323846;

long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}


//overflowするときは1を返す
int is_mul_overflow(long long a, long long b) {
	float mul_log;

	if (a == 0 || b == 0) {
		return 0;
	}

	mul_log = log10f(a) + log10f(b);


	if (mul_log > 18.0) {
		return 1;
	}
	else {
		return 0;
	}
}

int main() {

	int N;
	long long A[100010];

	cin >> N;

	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}

	long long tmp = 1;
	int flag = 0; //overflow したら1に
	int flag_0 = 0; //0のためのフラグ

	for (int i = 0; i < N; i++) {
		if (A[i] == 0) {
			flag_0 = 1;
			break;
		}
	}


	for (int i = 0; i < N; i++) {
		if (is_mul_overflow(tmp, A[i]) == 0) {
			tmp = tmp*A[i];
		}
		else {
			flag = 1;
			break;
		}

	}

	if (flag == 1 || tmp > 1000000000000000000) {
		tmp = -1;
	}

	if (flag_0 == 1) {
		tmp = 0;
	}

	cout << tmp << endl;

	cin >> tmp;

	return 0;


}

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

using namespace std;

int main(){

  


  int n,at,out;
  vector<int> a;

  cin >> n ;
  for(int i =0; i< n;i++)
    {
      cin >> at;
    a.push_back(at);
    }
  int diff;
  int sum = abs(a[0]);
  for(int i=0;i<n-1;i++)
    {
      diff = abs(a[i+1] - a[i]);
      sum += diff;
    }
  sum += abs(a[n-1]);
  int diff1, diff2,diff3,d;
  vector<int> ans;
  int first = sum - (abs(a[1] - a[0]) + abs(a[0]) - abs(a[1]));
  ans.push_back(first);
  for(int i=1;i<n-1;i++)
    {
      diff1 = abs(a[i+1] - a[i]);
      diff2 = abs(a[i] - a[i-1]);
      diff3 = abs(a[i+1] - a[i-1]);
      d = abs(diff1 + diff2 - diff3);
      ans.push_back(sum -d);
    }
  int last = sum - (abs(a[n-2] - a[n-1]) + abs(a[n-1]) - abs(a[n-2]));
  ans.push_back(last);
  for(int h:ans)
    cout << h<<endl;

}


Measured memory_bytes: 2168
#include<bits/stdc++.h>
using namespace std;
inline void io()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.precision(10);
    cout << fixed;
}
int main()
{
    io();
    int n;
    cin >> n;
    vector<int>v(n);
    for (int i = 0; i < n; ++i)
    {
        cin >> v[i];
    }
    int ans = numeric_limits<int>::max();
    for (int e = -100; e <= 100; ++e)
    {
        int cost = 0;
        for (int i = 0; i < n; ++i)
        {
            cost += (v[i] - e) * (v[i] - e);
        }
        ans = min(ans, cost);
    }
    cout << ans << '\n';
    return 0;
}


Measured memory_bytes: 256
//Bismillahir Rahmanir Rahim
#include <bits/stdc++.h>
//#include <ext/pb_ds/assoc_container.hpp>
//using namespace __gnu_pbds;
using namespace std;
 
#define ff              first
#define ss              second
#define int             long long
#define endl            "\n"
#define pb              push_back
#define ppb              pop_back
#define mp              make_pair
#define pii             pair<int, int>
#define vi              vector<int>
#define all(x)          (x).begin(), (x).end()
#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 FIO             ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
mt19937                 rng(chrono::steady_clock::now().time_since_epoch().count());
 
//typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> pbds;
 
inline int ceili(int x, int y) { return (x + y - 1) / y; }
 
void solve()
{
    int d, t, s; cin >> d >> t >> s;
    double need = (double) d / s;

    if(need <= t) cout << "Yes" << endl;
    else cout << "No" << endl;
}
 
int32_t main()
{
    FIO;
 
    solve();
 
    return 0;
}

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

int main() {
	int n, a, b, c, d;
    cin >> n >> a >> b >> c >> d;
    string data;
    cin >> data;

    int max = (c > d ? c : d);

    if (regex_search(data.substr(a - 1, max - 1 - (a - 1) + 1), regex("#{2}"))){
        cout << "No" << endl;
    }else if (c == d){
        cout << "No" << endl;
    }else if (c < d){
        cout << "Yes" << endl;
    }
    else if (regex_search(data.substr(b - 2, d - (b - 2) + 1), std::regex("\\.{3}"))){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }
}

Measured memory_bytes: 772
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define all(v) v.begin(), v.end()
#define int long long
#define _GLIBCXX_DEBUG

signed main() {
  int N, M; cin >> N >> M;
  vector<int> H(N), D(N, 0);
  rep(i, N) cin >> H[i];
  rep(i, M) {
    int a, b; cin >> a >> b;
    if(H[a-1] < H[b-1]) D[a-1]--;
    else if(H[a-1] > H[b-1]) D[b-1]--;
    else {
      D[a-1]--;
      D[b-1]--;
    }
  }
  
  
  int ans = 0;
  
  rep(i, N) if(D[i] == 0) ans++;

  cout << ans << endl;
}

Measured memory_bytes: 4844
#include <iostream>
#include <algorithm>
#include <functional>
#include <string>
#include <vector>
#include <utility>
#include <cmath>
#define REP(i, n) for(int i = 0; i < n; i++)
#define SORT(x) sort(x.begin(), x.end())
#define REV(x) reverse(x.begin(), x.end())
#define RSORT(x) sort(x.begin(), x.end(), std::greater<int>())
#define swap(a, b) \
  do { typeof(a) __tmp = (a); (a) = (b); (b) = __tmp; } while (0)
#define vi vector<int>
using namespace std;

const double EPS = 1e-10;
const double PI  = acos(-1.0);

int main() {
  
  int x, a, b;
  cin >> x >> a >> b;
  cout << (x - a) % b << endl;
  
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;
#define int long long
#define ar array
#define db long double
#define pow pw
const db pi = 3.14159265358979323846;
int pw(int a,int b){
    int ans=1;
    while(b){
    if (b%2) ans*=a;
    a*=a;
    b/=2;
    }
    return(ans);
}
const int mxn=1e5+7;
int n;
int a[mxn],dp[mxn];
signed main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(0);
    cout.tie(0);
    cin>>n;
    for (int i=1;i<=n;i++) cin>>a[i];
    dp[1]=0;
    dp[2]=abs(a[2]-a[1]);
    for (int i=3;i<=n;i++)
    {
        dp[i]=min(dp[i-2]+abs(a[i]-a[i-2]),dp[i-1]+abs(a[i]-a[i-1]));
    }
    cout<<dp[n];
    return 0;
}

Measured memory_bytes: 5100
N, W = map(int, input().split())
items = [list(map(int, input().split())) for _ in range(N)]

dp = [[0]*(W+1) for _ in range(N+1)]
# dp[i][j] := i番目までの荷物を使って重さjの時の最大の価値
for i in range(N):
    for j in range(W+1):
        # i番目のitemを使わない場合
        dp[i+1][j] = max(dp[i+1][j], dp[i][j])
        # i番目のitemを使う場合
        if j + items[i][0] > W:  # 重さがWを超えるならcontinue
            continue
        # 個数制限ありのパターン
        dp[i+1][j+items[i][0]] = max(dp[i][j]+items[i][1], dp[i+1][j+items[i][0]])
print(dp[N][W])


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

using namespace std;

#define FOR(i, j, k) for(int i = j; i < k; ++i)
#define rep(i, j) FOR(i, 0, j)
#define FORr(i, j, k) for(int i = j; i >= k; --i)
#define repr(i, j) FOR(i, j, 0)
#define INF (1 << 30)

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

const int MOD = 1e9 + 7;
const int dy[]={0, 0, 1, -1};
const int dx[]={1, -1, 0, 0};

template <class T> void chmin(T& a, const T& b) { a = min(a, b); }
template <class T> void chmax(T& a, const T& b) { a = max(a, b); }

int a[100000];

int main() {
	int n;
	scanf("%d", &n);
	rep(i, n) scanf("%d", &a[i]);
	int ans = n / 2;
	int two = 0, four = 0;
	rep(i, n) {
		if(a[i] % 4 == 0) ++four;
		else if(a[i] % 2 == 0) ++two;
	}
	ans -= four;
	two /= 2;
	ans -= two;
	if(ans <= 0) printf("Yes\n");
	else printf("No\n");
	return 0;
}

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

const int MAX_N = 1e5;
const int MAX_K = 100;
int N; int K;
vector<int> cost(MAX_N + 1, -1);
vector<int> height(MAX_N + 1);

int dp(int n) {
    if (cost[n] == -1 && n != 1) {
        int min_cost = dp(n - 1) + abs(height[n] - height[n - 1]);
        for (int i = n - 1; max(1, n - K) <= i; i--) {
            min_cost = min(min_cost, dp(i) + abs(height[n] - height[i]));
        }
        cost[n] = min_cost;
    }
    return cost[n];
}

int main() {
    cin >> N >> K;
    for (int i = 0; i < N; i++) {
        cin >> height[i+1];
    }
    cost[1] = 0;
    cout << dp(N) << endl;
}

Measured memory_bytes: 7296
A, B = map(int, input().split())


def factorization(n):
    arr = [1]
    temp = n
    for i in range(2, int(-(-n**0.5//1))+1):
        if temp%i==0:
            while temp%i==0:
                temp //= i
            arr.append(i)

    if temp!=1:
        arr.append(temp)

    if arr==[]:
        arr.append(n)

    return arr


af = factorization(A)
bf = factorization(B)
ans = 0
for afi in af:
    if afi in bf:
        ans += 1
print(ans)


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

// {U}{INT,LONG,LLONG}_{MAX,MIN}
#define INF         INT_MAX/3
#define MOD         (1000000007LL)

using LL  = long long;
// }}}

struct E {
    int to, w;
};

using G = vector<vector<E>>;

template <typename T>
pair<vector<T>, vector<int>> dijkstra(G g, int s, T inf) {
    int n = g.size();
    vector<T> d(n, INF);
    vector<int> r(n, -1);
    d[s] = 0;
    using P = pair<T, int>;
    priority_queue<P, vector<P>, greater<P>> pq;
    pq.push({0, s});
    while(!pq.empty()){
        auto c = pq.top();pq.pop();
        if(d[c.second] < c.first) continue;
        for(auto e : g[c.second]){
            if(d[e.to] > d[c.second] + e.w){
                d[e.to] = d[c.second] + e.w;
                r[e.to] = c.second;
                pq.push({d[e.to], e.to});
            }
        }
    }
    return {d, r};
}

int main() {
    std::ios::sync_with_stdio(false);
    int n, m;cin >> n >> m;
    G g(n);
    for(int i=0;i<m;i++){
        int a, b, c;cin >> a >> b >> c;a--;b--;
        g[a].push_back({b, c});
        g[b].push_back({a, c});
    }
    int used[100][100];
    memset(used, 0, sizeof(used));
    for(int i=0;i<n;i++){
        auto p = dijkstra<int>(g, i, INF);
        auto d = p.first;
        auto r = p.second;
        for(int j=0;j<n;j++){
            if(i == j) continue;
            int c = j;
            while(r[c] != -1){
                used[c][r[c]] = 1;
                used[r[c]][c] = 1;
                c = r[c];
            }
        }
    }
    int ans = 0;
    for(int i=0;i<n;i++){
        for(int j=i+1;j<n;j++){
            ans += used[i][j];
        }
    }
    cout << m-ans << endl;
    return 0;
}


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

typedef long long ll;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef vector<vector<vector<ll>>> vvvll;
typedef vector<bool> vb;
typedef vector<vector<bool>> vvb;
typedef vector<vector<vector<bool>>> vvvb;
typedef pair<ll, ll> pll;
typedef vector<pll> vpll;
typedef vector<vpll> vvpll;
typedef vector<double> vd;
typedef vector<vd> vdd;

#define FOR(i,x,y) for(ll i=(ll)x; i<(ll)y; ++i)
#define REP(i,y) FOR(i, 0, y)
#define RFOR(i,x,y) for(ll i=(ll)x; i>=(ll)y; --i)
#define RREP(i,x) RFOR(i, x, 0)
#define ALL(a) a.begin(), a.end()
#define pb push_back
#define debug_print(x...) cerr << "line " << __LINE__ << " : "; debug_print_in(x);

template <typename First>
void debug_print_in(First first){
  cerr << first << endl;
  return;
}

template <typename First, typename... Rest>
void debug_print_in(First first, Rest... rest){
  cerr << first << " ";
  debug_print_in(rest...);
  return;
}

void IN(void){
  return;
}

template <typename First, typename... Rest>
void IN(First& first, Rest&... rest){
  cin >> first;
  IN(rest...);
  return;
}

template <typename First>
void OUT(First first){
  cout << first << endl;
  return;
}

template <typename First, typename... Rest>
void OUT(First first, Rest... rest){
  cout << first << " ";
  OUT(rest...);
  return;
}

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(a>b)a=b;};
int popcount(int t){return __builtin_popcount(t);} //GCC
int popcount(ll t){return __builtin_popcountll(t);} //GCC

template <typename T>
void vec_print(vector<T> VEC){
  REP(i, VEC.size()){
    cerr << VEC[i] << " ";
  }
  cerr << endl;
};

template <typename T>
void mat_print(vector<vector<T> > MAT){
  REP(i,MAT.size()){
    REP(j,MAT[i].size()){
      cerr << MAT[i][j] << " ";
    }
    cerr << endl;
  }
};

constexpr int INF = (1<<30);
constexpr ll INFLL = 1LL<<62;
constexpr long double EPS = 1e-12;
constexpr ll MOD = (ll)((1E+9)+7);

int main(){
  cin.tie(0); // cut the cin and cout (default, std::flush is performed after std::cin)
  ios::sync_with_stdio(false); // cut the iostream and stdio (DON'T endl; BUT "\n";)

  ll N;
  IN(N);
  vvll Graph(N);
  ll ans = 0;
  REP(i,N){
    ans += (i+1)*(N-i);
  }
  REP(i,N-1){
    ll u, v;
    IN(u,v);
    u--; v--;
    if(u>v) swap(u,v);
    ans -= (u+1)*(N-v);
  }

  OUT(ans);

  return 0;
}

Measured memory_bytes: 7948
#include <bits/stdc++.h>
using namespace std;
#define min(a,b) ((a)<(b)?(a):(b))
#define max(a,b) ((a)>(b)?(a):(b))
#define REP(i,n) for(int i=0;i<n;i++)
#define FOR(i,n1,n2) for(int i=n1;i<n2;i++)
#define speed_up    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
typedef pair<int,int> Pi;
typedef long long int ll;
const int INF=(ll)(1<<30)-1;
const ll INFl=(ll)9223372036854775807;
const int MAX=10000;
const ll MOD=(ll)1e9+7;
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;}
int dx[4]={1,0,-1,0},dy[4]={0,1,0,-1};

int x,y,z,k;
ll a[1010],b[1010],c[1010];
vector<ll> v;
vector<ll> vv;

int main(){
	cin>>x>>y>>z>>k;
	REP(i,x)
		cin>>a[i];
	REP(i,y)
		cin>>b[i];
	REP(i,z)
		cin>>c[i];
		
	REP(i,x)
		REP(j,y)
		v.push_back(a[i]+b[j]);
	sort(v.begin(),v.end(),greater<ll>());
	
	for(int i=0;i<k&&i<v.size();i++){
		REP(j,z){
			ll p=v[i]+c[j];
			vv.push_back(p);
		}
	}
	sort(vv.begin(),vv.end(),greater<ll>());
	REP(i,k){
		cout<<vv[i]<<endl;
	}
	return 0;
}

Measured memory_bytes: 43236
while 1
    n, m, t, p = gets.split.map(&:to_i)
    a = (1..m).map{(1..n).map {1}}
    break if n == 0
    t.times do
        d, c = gets.split.map(&:to_i)
        if d == 1
            n = [c, n - c].max
            a.map! do |row|
                left = row[0..c-1].reverse
                right = row[c..-1]
                (0..n-1).map {|i| (left[i] || 0) + (right[i] || 0)}
            end
        else
            m = [c, m - c].max
            lower = a[0..c-1].reverse
            upper = a[c..-1]
            a = (0..m-1).map {|i|
                (upper[i] || Array.new(n, 0)).zip(lower[i] || Array.new(n, 0)).map {|r| r.inject(:+)}
            }
        end
    end
    p.times do
        x, y = gets.split.map(&:to_i)
        p a[y][x]
    end
end



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

int main(){
    string s;
    cin >>s;
   if(s=="SUN"){
       cout << 7 << endl;
   }else if(s=="MON"){
       cout << 6 << endl;
   }else if(s=="TUE"){
       cout <<5<< endl;
   }else if(s=="WED"){
       cout <<4 << endl;
   }else if(s=="THU"){
       cout <<3<< endl;
   }else if(s=="FRI"){
       cout << 2<< endl;
   }else if(s=="SAT"){
    cout << 1 << endl; 
   }
}

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

using namespace std;

int h, w;
string input[50];

void solve(int i, int j) {
    int bomb = 0;
   for (int k = -1; k <= 1; k++) {
       for (int l = -1; l <= 1; l++) {
          if (i + k >= 0 && i + k < h && j + l >= 0 && j + l < w && input[i + k][j + l] == '#') {
              bomb++;
          }
       }
   } 
   input[i][j] = '0' + bomb;
}

int main() {
    cin >> h >> w;
    for (int i = 0; i < h; i++) {
        cin >> input[i];
    }
    for (int i = 0; i < h; i++) {
        for (int j = 0; j < w; j++) {
            if (input[i][j] == '.') solve(i, j);
        }
    }
    for (int i = 0; i < h; i++) {
        cout << input[i] << endl;
    }
    return 0;
}


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

using namespace std;

#define ALL(x) (x).begin(), (x).end()
#define CONCAT(x,y) (x).insert((x).end(),(y).begin(),(y).end())
#define DUMP(xs) for (auto x:xs) cout<<x<<' ';cout<<endl
#define FOR(i,a,b) for (int i=(int)(a);i<(int)(b);++i)
#define FORE(i,a,b) for (int i=(int)(a);i<=(int)(b);++i)
#define OUT(x) cout<<x<<endl
#define REP(i,n) FOR(i,0,n)
#define REPE(i,n) FOR(i,0,n)

typedef long long ll;
typedef pair<ll, ll> P;
typedef vector<int> VEC;

int gcd(int a, int b) {
  while (true) {
    if (a < b) swap(a,b);
    if (!b) break;
    a %= b;
  }
  return a;
}

int main() {
  int N,X;cin>>N>>X;
  // 全てのabs(x-X)の最大公約数
  vector<int> xs(N);
  REP(i,N) {
    int x;cin>>x;
    xs[i] = x;
  }
  int ans = abs(X-xs[0]);
  REP(i,N) {
    ans = gcd(ans,abs(X-xs[i]));
  }
  OUT(ans);

  return 0;
}

Measured memory_bytes: 640
import copy

"""
def sumPrice(N, B):
    sum = 0
    for i in range(1, N):
        sum += abs(B[i] - B[i - 1])
    sum += abs(B[N-1] - B[0])
    return sum


N = int(input())
A = []
A = [int(i) for i in input().split()]
A.insert(0, 0)
for i in range(1, N + 1):
    B = copy.deepcopy(A)
    del B[i]
    print(sumPrice(N, B))
"""
N = int(input())
A = []
A = [int(i) for i in input().split()]
A.insert(0, 0)
A.insert(N+1, 0)

defSumPrice = 0
for i in range(1, N + 2):
    defSumPrice += abs(A[i - 1] - A[i])

for i in range(1, N + 1):  # A[i] に行かない
    sumPrice = 0
    if (A[i - 1] < A[i] and A[i+1] < A[i])or(A[i - 1] > A[i] and A[i+1] > A[i]):
        if abs(A[i] - A[i - 1]) > abs(A[i] - A[i + 1]):
            sumPrice = defSumPrice - 2 * abs(A[i] - A[i + 1])
        else:
            sumPrice = defSumPrice-2*abs(A[i]-A[i-1])
    else:
        sumPrice = defSumPrice
    print(sumPrice)


Measured memory_bytes: 14560
#include "bits/stdc++.h"

#define pb push_back
#define pob pop_back
#define pf push_front
#define pof pop_front
#define eb emplace_back
#define rep(i, a, b) for (long i = (a); i <= (b); ++i)
#define per(i, a, b) for (long i = (a); i >= (b); --i)
#define mmst(v) memset(v, 0, sizeof(v))

const long kMax2 = 109;
const long kMax3 = 1009;
const long kMax4 = 10009;
const long kMax5 = 100009;
const long kMax6 = 1000009;
const long kInfI = 0x3F3F3F3F;
const float kInfF = 1e15;

const long kMAX = 1000000000;

using namespace std;
using ll = long long;

inline int readInt() {
  char c = getchar();
  while(!isdigit(c) && c != '-') c = getchar();
  int sigma = 1;
  if (c == '-') {
    sigma = -1;
    c = getchar();
  }
  int x = 0;
  while (isdigit(c)) {
    x = x * 10 + c - '0';
    c = getchar();
  }
  return x * sigma;
}

long d[kMax5][13];

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

  string s;
  int a, b, c;
  cin >> a >> b >> c;
  int ans = c - min(c, a - b);

  cout << ans << endl;

  return 0;
}


Measured memory_bytes: 256