akhauriyash/Code-Regression huggingface dataset:
n = int(input())
x = [0]*n
y = [0]*n
for i in range(n):
    x[i], y[i] = map(int, input().split())

from itertools import permutations
ways = list(permutations(range(n)))

from math import sqrt

def d(x1, y1, x2, y2):
    return sqrt((x1-x2)**2 + (y1 - y2)**2)

c=0

for way in ways:
    for i in range(len(way) - 1):
        c += d(x[way[i]], y[way[i]], x[way[i+1]], y[way[i+1]])

ans = c / len(ways)
print(ans)

Measured memory_bytes: 46064
import Control.Arrow
import Data.List
import qualified Data.ByteString.Char8 as B
import Control.Monad 
import qualified Data.Vector as V
import qualified Data.Vector.Mutable as VM
import Control.Monad.ST

main :: IO ()
main = breads >>= main'
    where
        main' [n, c] = replicateM c breads >>= main'' c n . build
        main'' c n ds = replicateM n breads >>= print . solve c n ds . build . map (map pred)

type V2 a = V.Vector (V.Vector a)

at :: V2 a -> (Int, Int) -> a
at vs (x, y) = vs V.! x V.! y
    
build :: [[Int]] -> V2 Int
build = V.fromList . map V.fromList

solve :: Int -> Int -> V2 Int -> V2 Int -> Int
solve c n ds cs = minimum [calc x y z | x <- [0..(c - 1)], y <- [0..(c - 1)], z <- [0..(c - 1)], x /= y, y /= z, z /= x]
    where
        [cs0, cs1, cs2] = map count [0..2]

        calc x y z = sum [diff x cs0, diff y cs1, diff z cs2]
        diff v xs = foldl' (\acc x -> acc + xs V.! x * ds `at` (x, v)) 0 [0..(c - 1)]
        count :: Int -> V.Vector Int 
        count m = runST $ newVec >>= loop >>= V.unsafeFreeze
            where
                newVec :: ST s (VM.STVector s Int) 
                newVec = VM.replicate c 0
                loop vs = vs <$ mapM_ mf [(i, j) | i <- [0..(n - 1)], j <- [0..(n - 1)], (i + j + 2) `mod` 3 == m]
                    where
                        mf idx = VM.unsafeModify vs succ $ cs `at` idx

breads :: IO [Int]
breads = unfoldr (\s -> second (maybe B.empty snd . B.uncons) <$> B.readInt s) <$> B.getLine

Measured memory_bytes: 27004
#include <iostream>
#include <vector>
#include <string>

std::vector<int64_t> calc_seq(std::vector<int64_t> & xs) {
    auto seq = std::vector<int64_t>{};
    auto count = 1;
    for (size_t i = 0; i < xs.size() - 1; i++) {
        if (xs[i] == xs[i+1]) {
            count++;
        } else {
            seq.push_back(count);
            count = 1;
        }
    }
    seq.push_back(count);
    return seq;
}

std::vector<int64_t> form_seq(std::vector<int64_t> & xs) {
    auto seq = calc_seq(xs);
    if (xs[0] == 0) {
        seq.insert(begin(seq), 0);
    }
    if (seq.size() % 2 == 0) {
        seq.push_back(0);
    }
    return seq;
}

int64_t sum(std::vector<int64_t> & xs, int64_t i0, int64_t i1) {
    auto val = 0LL;
    for (auto i = i0; i <= i1; i++) {
        val += xs[i];
    }
    return val;
}

void calc(int64_t n, int64_t k, std::vector<int64_t> & xs) {
    auto seq = form_seq(xs);
    auto m = seq.size();
    auto i = 1LL;
    if (i + 2*k > m) {
        std::cout << n;
        return;
    }
    auto val = sum(seq, i-1, i-1 + 2*k);
    auto biggest = val;
    i += 2;
    while (i + 2*k <= m) {
        val += seq[i-1+2*k-1] + seq[i-1+2*k] - seq[i-1-2] - seq[i-1-1];
        if (biggest < val) {
            biggest = val;
        }
        i += 2;
    }
    std::cout << biggest;
}

int main() {
    std::string s1, s2;
    std::cin >> s1 >> s2;
    auto n = stoi(s1);
    auto k = stoi(s2);

    std::string s3;
    std::cin >> s3;
    std::vector<int64_t> xs(n);
    for (size_t i = 0; i < n; i++) {
        xs[i] = stoi(s3.substr(i, 1));
    }
    calc(n, k, xs);
}

Measured memory_bytes: 2296
#include <iostream>

using namespace std;

int main(int argc, char **argv)
{
	unsigned int n, tmp, sum;
	
	while(1){
		cin >> n;
		if(n == 0){
			break;
		} else if(n == 1){
			cout << "deficient number" << endl;
			continue;
		}
		sum = 1;
		tmp = n;
		for(int i = 2; (i < tmp && sum < n); i++){
			if(n % i == 0){
				tmp = n/i;
				sum += ((i != tmp)? (i+tmp): i);
			}
		}
		
		if(sum == n){
			cout << "perfect number" << endl;
		}	else if(sum > n){
			cout << "abundant number" << endl;
		} else {
			cout << "deficient number" << endl;
		}
	}
	
	return 0;
}

Measured memory_bytes: 852
#include <bits/stdc++.h>
using namespace std;
int main()
{
	char a[12];
	cin>>a;
	long long l=strlen(a),k=0;
	for(int i=0;i<1<<(l-1);i++)
	{
		long long s=0,m=0;
		s=0;
		m=0;
		for(int j=0;j<l;j++)
		{
			m*=10LL;
			m+=a[j]-'0';
			if(j<l-1 && (i>>j&1))
			{
				s+=m;
				m=0;
			}
		}
		s+=m;
		k+=s;
	}
	cout<<k<<'\n';
	return 0;
}


Measured memory_bytes: 256
import std.stdio, std.string, std.conv;
import std.array, std.algorithm, std.range;

void main()
{
    immutable n = readln().chomp().to!int();
    auto a = iota(n).map!(_=>readln().split().map!(to!int).array()).array();
    int idx(int i, int j){ return i*(n+1)+j; }
    auto s = new int[(n+1)^^2];
    foreach(i;0..n)
        foreach(j;0..n)
            s[idx(i+1,j+1)] = s[idx(i+1,j)]+s[idx(i,j+1)]-s[idx(i,j)]+a[i][j];
    int m=int.min;
    foreach(i1;0..n) foreach(i2;i1+1..n+1)
        foreach(j1;0..n) foreach(j2;j1+1..n+1)
            m=max(m,s[idx(i2,j2)]-s[idx(i2,j1)]-s[idx(i1,j2)]+s[idx(i1,j1)]);
    writeln(m);
}

Measured memory_bytes: 1616
import sys
sys.setrecursionlimit(10**7)
input = sys.stdin.readlines

import math

def main():

    lines = input()
    a, b, c, d = list(map(int, lines[0].split()))

    def gcd(a, b):

        r = a % b

        if r == 0:
            return int(b)
        
        return gcd(b, r)

    g = gcd(c, d)
    gcm = int(c * d // g)

    c_in = int(b // c - (a-1)//c)
    d_in = int(b // d - (a-1)//d)
    cd_in = int(b // gcm - (a-1)//gcm)

    ans = int((b-a+1) - (c_in + d_in - cd_in))
    print(ans)

main()




Measured memory_bytes: 9212
#include <iostream>
#include <cstdio>
#include <vector>
#include <cstring>
#include <string>
#include <set>
#include <map>
#include <queue>
#include <cmath>
#include <algorithm>
#include <iomanip>
#include <sstream>
#include <stack>
#include <bitset>
#include <cstdlib>
#include <ctime>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
int g[550][550];
void dfs(int l,int r,int val)
{
    if(l==r) return;
    int mid=(l+r)/2;
    for(int i=l;i<=mid;i++)
    {
        for(int j=mid+1;j<=r;j++)
        {
            g[i][j]=val;
        }
    }
    dfs(l,mid,val+1);dfs(mid+1,r,val+1);
}
int main()
{
	int n;
	scanf("%d",&n);
	dfs(1,n,1);
    for(int i=1;i<=n-1;i++)
    {
        for(int j=i+1;j<=n;j++)
        {
            printf("%d",g[i][j]);
            if(j==n) printf("\n");
            else printf(" ");
        }
    }
	return 0;
}


Measured memory_bytes: 1536
from collections import Counter,defaultdict,deque
from heapq import heappop,heappush,heapify
import sys,bisect,math,itertools,fractions,pprint
sys.setrecursionlimit(10**8)
mod = 10**9+7
mod2 = 998244353
INF = float('inf')
def inp(): return int(sys.stdin.readline())
def inpl(): return list(map(int, sys.stdin.readline().split()))
def inpln(n): return list(int(sys.stdin.readline()) for i in range(n))

n = inp()
if n%2:
    print(0)
    quit()
res = 0
for i in range(1,100):
    res += n//((5**i)*2)
print(res)

Measured memory_bytes: 63980
n,k = map(int,input().split())
# 1 ~ n で、kで割った余りがどれだけあるか
from collections import defaultdict
dic = defaultdict(int)
for i in range(1,n+1): # 0含んだらダメじゃん
    dic[i%k] += 1
res = 0
for a in range(k):
    # 余りで考える
    b = (k-a)%k
    c = (k-a)%k
    if ((b+c)%k != 0):
        continue
    res += dic[a]*dic[b]*dic[c]
print(res)


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

using namespace std;

int main(void) {
  string s;
  cin >> s;
  int a[26];
  for(int i = 0; i < 26; i++) {
    a[i] = 0;
  }

  for(int i = 0; i < s.length(); i++) {
    a[s[i] - 'a']++;
    if(a[s[i] - 'a'] > 1) {
      cout << "no" << endl;
      return 0;
    }
  }

  cout << "yes" << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <math.h>
#include <algorithm>
#include <set>
#include <iomanip>
#include <stdio.h>
#include <sstream>
#include <string>
using namespace std;
int main(void){
  int x, a, b;
  cin>>x>>a>>b;
  if(abs(x-a)<abs(x-b)){
    cout<<"A"<<endl;
  }else{
    cout<<"B"<<endl;
  }
}

Measured memory_bytes: 256
//Created Time:2019年12月23日 星期一 15时39分53秒
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cstring>
#define N 2005
#define mod 1000000007

using namespace std;

int n, k;
int f[N][N], fac[N * N], ifac[N * N], inv[N * N];

int C(int ,int);

int main(){
	cin >> n >> k; fac[0] = ifac[0] = inv[1] = 1;
	if (k == 1) { puts("1"); return 0;}
	for (int i = 2; i <= n * k; ++i) inv[i] = mod - 1ll * mod / i * inv[mod % i] % mod;
	for (int i = 1; i <= n * k; ++i) fac[i] = 1ll * fac[i - 1] * i % mod, ifac[i] = 1ll * ifac[i - 1] * inv[i] % mod;
	f[0][0] = 1; //f[i][j] 放了i个白色球和j种颜色球的方案
	for (int i = 1; i <= n; ++i)
		for (int j = 0; j <= i; ++j) {
			f[i][j] = f[i - 1][j];
			if(j) (f[i][j] += 1ll * C(n - i + (n - j + 1) * (k - 1) - 1, k - 2) * f[i][j - 1] % mod * (n - j + 1) % mod) %= mod;
		}
	cout << f[n][n] << endl;
	return 0;
}

int C(int x, int y){
	return 1ll * fac[x] * ifac[y] % mod * ifac[x - y] % mod;
}


Measured memory_bytes: 62976
import java.util.*;
public class Main {
    public static void main(final String[] args){
        final Scanner sc = new Scanner(System.in);
        
        final int diceN = sc.nextInt();
        final int doN = sc.nextInt();
        double dicePoint[] = new double[diceN];
        double sum = 0, max = 0;
        int cnt = 0;
        for (int i = 0; i < diceN; i++) {
            dicePoint[i] = cal(sc.nextInt());
            sum += dicePoint[i];
            cnt++;
            if(cnt > doN)
                sum -= dicePoint[i - doN];
            if(sum > max)
                   max = sum;
        }
        System.out.println(max);
    }

    static double cal(int value) {
        double res = 0;
        for (int i = 1; i <= value; i++) {
            res += i;
        }
        return res / (double)(value);
    }
}

Measured memory_bytes: 64532
#include<bits/stdc++.h>
typedef long long ll;
#define REP(i,a,b) for(int i=a;i<b;i++)
#define IN(n) int n; cin>>n;
#define ARR(arr,i,n) int arr[n]; REP(i,0,n){cin>>arr[i];}
#define MOD 1000000007

using namespace std;

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

    // code comes here
    int n;
    cin>>n;
    int h[n];
    for(int i=0;i<n;i++){
        cin>>h[i];
    }
    if(n==1){
        cout<<"Yes"<<endl;
    }
    else{
        int i;
    for( i=n-2;i>=0;i--){
        if(h[i]-h[i+1]>0){
            if(h[i]-h[i+1]==1){
                h[i]=h[i]-1;
            }
            else{
                cout<<"No"<<endl;
                break;
            }
        }
    }
    if(i<0){
        cout<<"Yes"<<endl;
    }
    }



    return 0;
}





Measured memory_bytes: 640
#include <bits/stdc++.h>
using namespace std;
typedef long long int ll;
typedef pair<ll,ll> P;
ll gcd(ll x,ll y){
  if(x>y)swap(x,y);
  ll r=y%x;
  while(r){
    y=x;
    x=r;
    r=y%x;
  }
  return x;
}
vector<ll> a;
int main() {
  ll n,k,x;
  cin>>n>>k;
  a.push_back(k);
  for(int i=0;i<n;i++){
    cin>>x;
    a.push_back(x);
  }
  sort(a.begin(),a.end());
  ll d=a[1]-a[0];
  for(int i=2;i<=n;i++){
    d=gcd(d,a[i]-a[i-1]);
  }
  cout<<d<<endl;
	return 0;
}

Measured memory_bytes: 1400
#include<map>
#include<set>
#include<cmath>
#include<queue>
#include<cstdio>
#include<vector>
#include<string>
#include<cstring>
#include<iostream>
#include<algorithm>
using namespace std;
#define ll long long
#define inf 1000000000
#define MOD 1000000007
inline int read(){int x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return x*f;}
inline ll readl(){ll x=0,f=1;char c=getchar();while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}while(c>='0'&&c<='9'){x=x*10+c-'0';c=getchar();}return x*f;}
template<class T>inline void print(T x){if(x/10!=0)print(x/10);putchar(x%10+'0');}
template<class T>inline void writeln(T x){if(x<0)putchar('-');x=abs(x);print(x);putchar('\n');}
template<class T>inline void write(T x){if(x<0)putchar('-');x=abs(x);print(x);}
inline ll power(ll a,ll b){ll ans=1;while(b){if(b&1){ans=ans*a%MOD;--b;}b>>=1;a=a*a%MOD;}return ans%MOD;}
/*================Header Template==============*/
int main(){
	#ifdef zincsabian
		freopen("in.txt","r",stdin);
		freopen("out.txt","w",stdout);
	#endif
	ios::sync_with_stdio(false);
	int n=read(),d=read(),x=read();
	for(int i=1;i<=n;i++){
		int y=read();x+=d/y+1;
		if(d%y==0) x--;
	}cout<<x<<"\n";
}


Measured memory_bytes: 256
#include <iostream>
#include <math.h>

using namespace std;

int main() {
	string s;
	int ord;
	cin >> s;
	long long ll;
	while(s.length() > 1) {
		ll = 0;
		for(int i = 0; i < s.length(); i++) {
			ord = s[i] - '0';
			ll += ord;
		}
		s = to_string(ll);
    }
    if(s == "9" || s == "0") {
    	cout << "Yes";
    }
    else{
    	cout << "No";
    }
}

Measured memory_bytes: 3280
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		Scanner stdIn = new Scanner(System.in);
		
		long n = stdIn.nextLong();
		
		long a = stdIn.nextLong();
		
		long b = stdIn.nextLong();
		
		long c = a+b;
		
		long d = n/c; 
		
		long ans = 0;
		
		ans += d*a;
		
		if(n-(c*d) <= a) {
			ans += n-(c*d);
		}else {
			ans += a;
		}
		
		System.out.println(ans);
	}

}


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

using vi = vector<int>;
using vvi = vector<vector<int>>;
using vvvi = vector<vector<vector<int>>>;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
using vvvll = vector<vector<vector<ll>>>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vvvd = vector<vector<vector<double>>>;
using vb = vector<bool>;
using vvb = vector<vector<bool>>;
using vs = vector<string>;
using pint = pair<int, int>;
using Graph = vvi;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()

int main() {
    int n;
    cin >> n;
    vi x(n);
    rep(i, n) cin >> x[i];

    int mi = 114514, mx = -114514;
    rep(i, n) {
        mx = max(mx, x[i]);
        mi = min(mi, x[i]);
    }

    int ans = 1e9;
    for(int i = mi; i <= mx; i++) {
        int tmp = 0;
        rep(j, n) {
            tmp += (x[j] - i) * (x[j] - i);
        }
        ans = min(ans, tmp);
    }

    cout << ans << endl;

    return 0;
}


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

class TSort{
public:
  int V;
  vector<set<int> > in,out;
  vector<int> sorted;
  TSort(){V = 0;}
  TSort(int V){
    in.resize(V);
    out.resize(V);
    this->V = V;
  }
  
  void add_edge(int from,int to){
    assert(from < V && to < V);
    assert(out[from].count(to) == 0);
    assert(in[to].count(from) == 0);
    out[from].insert(to);
    in[to].insert(from);
  }

  void sort(){
    sorted.clear();
    queue<int> Q;
    for(int i=0;i<V;i++)if(in[i].empty()) Q.push(i);

    while(!Q.empty()){
      int v = Q.front();Q.pop();
      sorted.push_back(v);
      for(int nx:out[v]){
        if(in[nx].size() == 1) Q.push(nx);
        in[nx].erase(v);
      }     
    }

    for(int i=0;i<V;i++) if(!in[i].empty()) sorted.clear(); // exist loop
  }
};


int main(){
  int n,m;
  cin>>n>>m;
  TSort A(n);
  
  for(int i=0,a,b;i<m;i++)cin>>a>>b,A.add_edge(a,b);

  A.sort();
  
  for(int i=0;i<n;i++)cout<<A.sorted[i]<<endl;
  return 0;
}

Measured memory_bytes: 8284
#include<iostream>
#include<algorithm>
#include<numeric>
#include<vector>
#include<set>
#include <math.h>
#include <string>
#define cinf(n,x,y) for(int i=0;i<(n);i++) cin >> x[i]>>y[i];
typedef long long int ll;
using namespace std;

int main(){
	string s; cin >>s;
	bool a=0; bool b=0;
	for(int i=0;i<s.size();i++){
		if(s[i]=='C')a=true;
		if(a&&s[i]=='F')b=true;
	}
	cout << (b?"Yes":"No") << endl;
}

Measured memory_bytes: 256
/**
 *    author:  tourist
 *    created: 28.04.2018 15:08:54       
**/
#include <bits/stdc++.h>

using namespace std;

string to_string(string s) {
  return '"' + s + '"';
}

string to_string(const char* s) {
  return to_string((string) s);
}

string to_string(bool b) {
  return (b ? "true" : "false");
}

template <typename A, typename B>
string to_string(pair<A, B> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}

template <typename A>
string to_string(A v) {
  bool first = true;
  string res = "{";
  for (const auto &x : v) {
    if (!first) {
      res += ", ";
    }
    first = false;
    res += to_string(x);
  }
  res += "}";
  return res;
}

void debug_out() { cerr << endl; }

template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
  cerr << " " << to_string(H);
  debug_out(T...);
}

#ifdef LOCAL
#define debug(...) cerr << "[" << #__VA_ARGS__ << "]:", debug_out(__VA_ARGS__)
#else
#define debug(...) 42
#endif

const int md = (int) 1e9 + 7;

inline void add(int &a, int b) {
  a += b;
  if (a >= md) a -= md;
}

inline void sub(int &a, int b) {
  a -= b;
  if (a < 0) a += md;
}

inline int mul(int a, int b) {
#if !defined(_WIN32) || defined(_WIN64)
  return (int) ((long long) a * b % md);
#endif
  unsigned long long x = (long long) a * b;
  unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
  asm(
    "divl %4; \n\t"
    : "=a" (d), "=d" (m)
    : "d" (xh), "a" (xl), "r" (md)
  );
  return m;
}

inline int power(int a, long long b) {
  int res = 1;
  while (b > 0) {
    if (b & 1) {
      res = mul(res, a);
    }
    a = mul(a, a);
    b >>= 1;
  }
  return res;
}

inline int inv(int a) {
  a %= md;
  if (a < 0) a += md;
  int b = md, u = 0, v = 1;
  while (a) {
    int t = b / a;
    b -= t * a; swap(a, b);
    u -= t * v; swap(u, v);
  }
  assert(b == 1);
  if (u < 0) u += md;
  return u;
}

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  vector<int> fact(n + 1), inv_fact(n + 1);
  fact[0] = inv_fact[0] = 1;
  for (int i = 1; i <= n; i++) {
    fact[i] = mul(fact[i - 1], i);
    inv_fact[i] = inv(fact[i]);
  }
  int ans = 0;
  for (int k = (n + 1) / 2; k <= n - 1; k++) {
    int cur = mul(fact[k - 1], mul(inv_fact[n - 1 - k], inv_fact[k - 1 - (n - 1 - k)]));
    cur = mul(cur, mul(fact[k], fact[n - 1 - k]));
    add(ans, cur);
  }
  int actual = mul(fact[n - 1], n);
  sub(actual, ans);
  cout << actual << '\n';
  return 0;
}


Measured memory_bytes: 8064
#!/usr/bin/env python3

# input = stdin.readline

def solve(s,t):
  s_len = len(s)
  t_len = len(t)
  k = 0
  l = []
  while k + t_len <= s_len:
    flag = True
    for i in range(t_len):
      if s[k+i] == t[i] or s[k+i] == "?":
        pass
      else:
        flag = False
    cand = "".join((s[:k],t,s[k+t_len:])).replace("?","a")
    if flag:
      l.append(cand)
    k += 1
  if len(l) == 0:
    return "UNRESTORABLE"
  else:
    return list(sorted(l))[0]


def main():
  s = input()
  t = input()
  print(solve(s,t))
  return

if __name__ == '__main__':
  main()


Measured memory_bytes: 9032
#include <iostream>
using namespace std;
int ans = 0;
void solve(int x) {
  if (x == 0) return;
  if (x == 2) ans += 1;
  else {
    ans += x - 1;
    solve(x - 1);
  }
}
int main() {
  int N, M;
  cin >> N >> M;
  solve(N); solve(M);
  cout << ans << endl;
}

Measured memory_bytes: 256
#include<cstdio>
#include<functional>
#include<algorithm>
using namespace std;
void func(int);
int n,k[101],v[101][100],d[101],f[101],cnt;
int flg[101];
int main(void)
{
	int i,u,j;
	scanf("%d",&n);
	for(i=1;i<=n;i++)	{
		scanf("%d %d",&u,&k[i]);
		for(j=0;j<k[i];j++)	scanf("%d",&v[i][j]);
	}
	for(i=1;i<=n;i++)	flg[i]=0;
	cnt=0;
	for(i=1;i<=n;i++)	{
		if(flg[i]==0)		func(i);
	}
	for(i=1;i<=n;i++)	printf("%d %d %d\n",i,d[i],f[i]);
	return 0;
}
void func(int nn)
{
	int i;
	cnt++;	
	d[nn]=cnt;
	flg[nn]=1;
	for(i=0;i<k[nn];i++)	{
		if(flg[v[nn][i]]==0)	{
			func(v[nn][i]);
		}
	}
	cnt++;
	f[nn]=cnt;
}


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

#define REP(i,j) for(int i=0;i<j;i++)
#define REPR(i,j) for(int i=j;i>=0;i--)
#define FOR(i,j,k) for(int i=j;i<k;i++)

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

    long long X, Y, i;
    cin >> X >> Y;
    i = 0;
    while(X <= Y){
        X *= 2;
        i++;
    }
    cout << i << endl;
    return 0;
}

Measured memory_bytes: 256
Program Main

    Implicit None
    Integer              :: k,H,A

    H = 0 ; A = 0 ; k = 1
    Read(*,*) H,A

    Loop:Do
            H = H - A
            If ( H <= 0 ) Exit Loop
            k = k + 1
         Enddo Loop

    Write(*,"(I0)") k

  End Program


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

int main(void){
    int A, B, C, X;
    cin >> A;
    cin >> B;
    cin >> C;
    cin >> X;
    int count = 0;

    for(int i = 0; i <= A; i++)
        for(int j = 0; j <= B; j++)
            for(int k = 0; k <= C; k++)
                if(500*i + 100*j + 50*k == X)
                    count++;

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<algorithm>
using namespace std;
int main() {
	int n, q, key;
	int sum = 0;
	int A[100000 + 10];
	scanf("%d", &n);
	for (int i = 0; i < n; i++)
		scanf("%d", &A[i]);
	scanf("%d", &q);
	for (int i = 0; i < q; i++) {
		scanf("%d", &key);
		if (binary_search(A, A + n, key))
			sum++;
		/*
		if (*lower_bound(A, A+n,key) == key)
			sum++;
		*/
	}
	printf("%d\n", sum);
}

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

#define ll long long
#define INF_LL 1LL << 60
#define INF 99999999
#define MOD (ll)1000000007
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define REP(i, a, n) for(int i = a; i < (int)(n); i++)
#define all(x) (x).begin(),(x).end()

void put_double(double obj){printf("%.12f\n",obj);};

template < typename T > std::string to_string( const T& n )
{
    std::ostringstream stm ;
    stm << n ;
    return stm.str() ;
}

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


int main()
{
    int N;
    cin >> N;
    vector<int> v(N);
    rep(i,N) cin >> v[i];

    sort(all(v));

    double tmp = (v[0] + v[1])/2.0;

    REP(i,2,N)
    {
        tmp = (tmp+v[i])/2.0;
    }
    put_double(tmp);
}


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

#define REP(i,n) for(ll i=0;i<ll(n);++i)
#define RREP(i,n) for(ll i=ll(n)-1;i>=0;--i)
#define FOR(i,m,n) for(ll i=m;i<ll(n);++i)
#define RFOR(i,m,n) for(ll i=ll(n)-1;i>=ll(m);--i)
#define ALL(v) (v).begin(),(v).end()
#define UNIQUE(v) v.erase(unique(ALL(v)),v.end());
#define INF 1000000001ll
#define MOD 1000000007ll
#define EPS 1e-9

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


using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;



int main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	ll n, p;
	cin >> n >> p;
	if (n == 1) {
		cout << p << endl;
		return 0;
	}
	ll ans = 1;
	for (ll i = 2; i*i <= p; ++i) {
		int cnt = 0;
		while (p%i == 0) {
			p /= i;
			cnt++;
		}
		ll k = 1;
		REP(j, cnt / n)k *= i;
		ans *= k;
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<vector>
#include<string>
#include<algorithm>
#include<math.h>

using namespace std;

typedef long long ll;
typedef pair<long long, long long> pll;

int main(){
	int N, K, X, Y;
	cin >> N >> K >> X >> Y;
	if (N <= K){
		cout << N*X << endl;
	}
	else{
		int out = K*X + (N - K)*Y;
		cout << out << endl;
	}
}

Measured memory_bytes: 256
#include<stdio.h>
#define N 100

int main(){
  int min,i,j,num[N],tmp,count=0,n;
  
  scanf("%d",&n);
  
  for(i=0;i<n;i++)scanf("%d",&num[i]);
  
  for(i=0;i<n;i++){
    min=i;
    for(j=i;j<n;j++){
      if(num[min]>num[j])min=j;
   }
    if(i!=min){
      tmp=num[i];
      num[i]=num[min];
      num[min]=tmp;
      count++;
    }
  }
  
  for(i=0;i<n-1;i++)printf("%d ",num[i]);
  printf("%d\n%d\n",num[i],count);
  
  return 0;
}

Measured memory_bytes: 600
// disco2020B.cpp :
#include <iostream>
#include<vector>
#include<algorithm>

using namespace std;
int main()
{
	int N;
	cin >> N;
	vector<long long>A(N);
	long long sum = 0;
	for (int i = 0; i < N; i++)
	{
		cin >> A.at(i);
		sum += A.at(i);
	}

	vector<long long>dp_L(N + 1);
	vector<long long>dp_R(N + 1);
	long long MIN = 9223372036854775807;
	dp_L.at(0) = 0;
	dp_R.at(0) = sum;
	for (int i = 0; i < N; i++)
	{
		dp_L.at(i + 1) = dp_L.at(i) + A.at(i);
		dp_R.at(i + 1) = sum - dp_L.at(i + 1);
		MIN = min(MIN, abs(dp_L.at(i + 1) - dp_R.at(i + 1)));
	}
	cout << MIN << endl;
}


Measured memory_bytes: 4992
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define ll long long
#define all(x) (x).begin(),(x).end()
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }

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

    int ans = 0;
    for (int i=0; i<N; i++){
        int l, r;
        cin >> l >> r;
        ans += r-l+1;
    }
    cout << ans << endl;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace easy_Atcoder
{
    class Program
    {
        static void Main(string[] args)
        {
            char[] n = Console.ReadLine().ToCharArray();
            for(int i=0;i<n.Length;i++){
                if(n[i]=='1'){
                    n[i] = '9';
                }else if(n[i]=='9'){
                    n[i] = '1';
                }
            }
            Console.WriteLine(string.Join("",n));
        }   
            // float[] ABN = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // long[] NK = Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // long N = NK[0];
            // long K = NK[1];
            // long K = long.Parse(Console.ReadLine());
            // int[] abc = Array.ConvertAll(Console.ReadLine().Split(),int.Parse);
            // string S = Console.ReadLine();
            // int x = int.Parse(Console.ReadLine());
            // int b = int.Parse(Console.ReadLine());
            // int N = int.Parse(Console.ReadLine());
            // float N = float.Parse(Console.ReadLine());
            // string c = Console.ReadLine();
            // string B = Console.ReadLine();
            // string[] s = Console.ReadLine().Split();
            // var s = (new string[] { Console.ReadLine(), Console.ReadLine(), Console.ReadLine() }).Select(float.Parse);
            // float[] a = Array.ConvertAll(Console.ReadLine().Split(),float.Parse);
            // var X = Console.ReadLine();
            // int[,] abcd = new int[NMQ[2],4];
            // int[] A = new int[NMQ[0]];
            // int[] A_num = new int[NMQ[0]];
            // long[] s=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            // var hs=new Dictionary<long,long>();
            // for(int i=0;i<s[0];i++){
            //     long[] q=Array.ConvertAll(Console.ReadLine().Split(),long.Parse);
            //     if(hs.ContainsKey(q[0])){hs[q[0]]+=q[1];}
            //     else{hs.Add(q[0],q[1]);}
            // }
        
        // //最小公倍数
        // static long Lcm(long a, long b)
        // {
        //     return a/Gcd(a,b)*b;
        // }

        // //最大公約数
        // static long Gcd(long m, long n)
        // {
        //     if(n==0)return m;
        //     return Gcd(n,m%n);
        // }
    }
}


Measured memory_bytes: 11732
#include <bits/stdc++.h>
#define PB push_back
#define MP make_pair
#define REP(i,n) for (int i=0;i<(n);i++)
#define ALL(a) (a).begin(),(a).end()
#define INF 1000000001
#define MOD 100000
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> P;
const ull B=100000007;
int main(){
      int n,m;
      int s[100000];
      int a[100000];
      int cnt[100001];
      while(cin>>n>>m){
            memset(cnt,0,sizeof(cnt));
            REP(i,n-1)cin>>s[i];
            ll ans=0,now=0,next=0;
            REP(i,m){
                  cin>>a[i];
                  next=now+a[i];
                  cnt[min(now,next)]++;
                  cnt[max(now,next)]--;
                  now=next;
            }
            REP(i,n)cnt[i+1]+=cnt[i];
            REP(i,n)ans+=(cnt[i]*s[i])%MOD;
            cout<<ans%MOD<<endl;
      }
}

Measured memory_bytes: 2336
S=input()
N=len(S)-1
total=0
for i in range(2**N):
    list=['+']*N
    for j in range(N):
        if ((i>>j)&1):
            list[N-j-1]=''
    formula=''
    for num,operator in zip(S,list+['']):
        formula+=(num+operator)
    total+=eval(formula)
print(total)


Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
int main(){
  while(1){
    int n;
    cin >> n;
    if(n==0){
      return 0;
    }
    int i,j,a[110];
    for(i=0;i<n+1;i++){
      cin >> a[i];
    }
    for(i=0;i<n+1;i++){
      int tr=2000000000,res=0;
      for(j=1;j<n+1;j++){
        if(i==j){
          continue;
        }
        if(i==j-1){
          if(i-1>=0){
            int dif=a[j]-a[i-1];
            if(tr!=dif && tr!=2000000000){
              res=1;
              break;
            }
            else{
              tr=dif;
            }
          }
        }
        else{
          int dif=a[j]-a[j-1];
          if(tr!=dif && tr!=2000000000){
            res=1;
            break;
          }
          else{
            tr=dif;
          }
        }
      }
      if(res==0){
        cout << a[i] << endl;
        break;
      }
    }
  }
}


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

int main(){
    vector<int> v;

    REP(i,3){
        int k;
        cin >> k ;
        v.push_back(k);
    }

    sort(v.begin(),v.end());

    if(v[0] == 5){
        if(v[1]==5){
            if(v[2] == 7){
                cout << "YES"<< endl;
                return 0;
            }
        }
    }

    cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define Tp template<typename Ty>
#define Ts template<typename Ty,typename... Ar>
#define Reg register
#define RI Reg int
#define Con const
#define CI Con int&
#define I inline
#define W while
#define N 200000
using namespace std;
int n,a[N+5];struct Data {int l,r,v;I Data(CI x=0,CI y=0,CI t=0):l(x),r(y),v(t){}}S[N+5];
I bool Check(CI x)
{
	RI i,T=0;for(i=1;i<=n;++i)
	{
		if(a[i]>a[i-1]) {S[++T]=Data(a[i-1]+1,a[i],0);continue;}
		W(a[i]<S[T].l) --T;S[T].r=a[i];
		W(T&&S[T].v==x-1) --T;if(!T) return 0;
		S[++T]=Data(S[T].r,S[T].r,S[T].v+1),--S[T-1].r<S[T-1].l&&(S[T-1]=S[T],--T),
		S[T].r^a[i]&&(S[++T]=Data(S[T].r+1,a[i],0),0);
	}return 1;
}
int main()
{
	RI i;for(scanf("%d",&n),i=1;i<=n;++i) scanf("%d",a+i);
	RI l=1,r=n,mid;W(l<r) Check(mid=l+r-1>>1)?r=mid:l=mid+1;return printf("%d\n",r),0;
}

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


int main(){
    /* A
    int n;
    cin >> n;
    bool check = false;
    for(int i=0;i<3;i++){
        if(n%10 == 7)check = true;
        n/=10;
    }
    cout << ((check)? "Yes": "No") << endl;*/

    int64_t n;
    cin >> n;
    int64_t ans = 0;
    for(int i=1;i<=n;i++){
        if(i%3!=0&&i%5!=0)ans+=i;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3612
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include <strings.h>

#ifdef TEST
struct test {
    int ans;
} td[] = {
    {},
};
#endif

void
solver(char *s, int q, int *t, int *f, char *c)
{
    int i;
    int top = 0;
    char pre[200001];
    char post[200001];
    int pre_p = 0, post_p = 0;

    bzero(pre, sizeof(pre));
    bzero(post, sizeof(post));

    for(i = 0; i < q; i++) {
        if(t[i] == 1) {
            top = 1 - top;
        }
        if(t[i] == 2) {
            if(f[i] == 1) {
                if(top == 0) {
                    pre[pre_p++] = c[i];
                } else {
                    post[post_p++] = c[i];
                }
            } else {
                if(top == 1) {
                    pre[pre_p++] = c[i];
                } else {
                    post[post_p++] = c[i];
                }
            }
        }
    }
    if(top == 0) {
        for(i = pre_p - 1; i >= 0; i--)
            printf("%c", pre[i]);
        printf("%s%s", s, post);
    } else {
        for(i = post_p - 1; i >= 0; i--)
            printf("%c", post[i]);

        for(i = strlen(s) - 1; i >= 0; i--)
            printf("%c", s[i]);

        printf("%s", pre);
    }
    printf("\n");
}

int
main(int argc, char *argv[])
{
    char S[100001];
    char tmp[100];
    int Q;
    int T[200000];
    int F[200000];
    char C[200000];
    int i;

#ifdef TEST
    int tt;
    for(tt = 0; tt < sizeof(td) / sizeof(struct test); tt++) {
        solver();
        printf("%d\n", td[tt].ans);
    }
#endif
    scanf("%s", S);
    scanf("%d", &Q);
    for(i = 0; i < Q; i++) {
        scanf("%d", T + i);
        if(T[i] == 2) {
            scanf("%d %c", F + i, C + i);
        }
    }

    solver(S, Q, T, F, C);
    return 0;
}

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

int main() {
  int N,K,Q;
  cin>>N>>K>>Q;
  vector<int>A(Q);
  for(int i=0;i<Q;i++){
    cin>>A.at(i);
  }
  vector<int>ans(N);
  for(int i=0;i<N;i++){
    ans.at(i)=K-Q;
  }
  for(int i=0;i<Q;i++){
    ans.at(A.at(i)-1)++;
  }
  for(int i=0;i<N;i++){
    if(ans.at(i)>0){
      cout<<"Yes"<<endl;
    }
    else{
      cout<<"No"<<endl;
    }
  }
}


Measured memory_bytes: 1408
N = int(input())
A = list(map(int, input().split()))
S = [0]*(N+1)
S[0] = 0
diff = float("INF")
idx = -1
m = sum(A)/2
for i in range(N):
  S[i+1] = S[i] + A[i]
  if abs(m - S[i+1]) < diff:
    diff = abs(m - S[i+1])
    idx = i+1
lsum = S[idx]
rsum = S[N]-S[idx]
print(abs(lsum-rsum))

Measured memory_bytes: 26220
#include<bits/stdc++.h>
using namespace std;
const int maxn=100100;
int a[maxn];
bitset<4000010> bit;
int main(){
//	freopen("A.in","r",stdin);
	int n;
	scanf("%d",&n);
	bit.reset();
	bit.set(0);
	int sum=0;
	for(int i=1;i<=n;i++){
		scanf("%d",&a[i]);
		bit=bit|(bit<<a[i]);
		sum=sum+a[i];
	}
	sum=(sum+1)/2;
	for(int i=sum;;i++){
		if(bit.test(i)){
			printf("%d\n",i);
			return 0;
		}
	}
	return 0;
}


Measured memory_bytes: 2304
#include <bits/stdc++.h>
#include <unordered_map>
typedef long long ll;
#define rep(i,m,n) for(ll i = (m); i < (n); i++)
#define rrep(i,m,n) for(ll i = (m); i >= (n); i--)
#define print(x) cout << (x) << endl;
#define print2(x,y) cout << (x) << " " << (y) << endl;
#define printa(x,n) for(ll i = 0; i < n; i++){ cout << (x[i]) << " \n"[i == n-1];}
#define printp(x,n) for(ll i = 0; i < n; i++){ cout << "(" << x[i].first << ", " << x[i].second << ") "; } cout << endl;
#define INF (1e18)
using namespace std;
const ll MOD = 1e9 + 7;
typedef pair<ll, ll> lpair;
ll calc(ll a, ll b){
    if(a > b) swap(a,b);
    if(a == 0) return 0;
    if(b % a == 0) return 2 * a * (b / a) - a;
    return 2 * a * (b / a) + calc(b%a, a);
}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N,X;
    cin >> N >> X;
    ll ans = N + calc(N-X, X);
    print(ans);

}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;

/**
 * The Number of Area
 */
public class Main {

	public static void main(String[] args) throws IOException {

		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String line = "";

		while ((line = br.readLine()) != null && !line.isEmpty()) {
			int n = Integer.parseInt(line);
			System.out.println(n * (n + 1) / 2 + 1);
		}
	}
}

Measured memory_bytes: 16852
import scala.collection.mutable.ListBuffer

object Main extends App {

  private val buf = new Array[Byte](1024)
  private val input = ListBuffer.empty[String]

  def isChar(c: Int) = 32 <= c && c <= 126
  
  def reads() = {
    var sb = new StringBuilder
    var insize = System.in.read(buf)
    var i = 0
    while(i < insize){
      val c = buf(i)
      if(isChar(c)) {
        sb.append(c.toChar.toString)
        if(i + 1 == insize) {
          input += sb.toString()
          sb.clear()
        }
      } else { // break
        input += sb.toString()
        sb.clear()
      }
      i += 1
    }
  }
  
  reads()
  
  val buff = input.toVector
  val n = buff(0).toInt
  val a = buff(1).split(' ').map(_.toInt)
  val q = buff(2).toInt
  val m = buff(3).split(' ').map(_.toInt)

  def solve(i: Int, m: Int): Boolean = if(m == 0) true
  else if(i >= n) false
  else solve(i+1, m) || solve(i+1, m - a(i))

  val result = m.map(p => if(solve(0, p)) "yes" else "no")

  print(result.mkString(f"%n") + f"%n")

}




Measured memory_bytes: 44252
#include<bits/stdc++.h>
using namespace std;
#define int long long int
signed main()
{
    int a,b,m,mn=INT_MAX,sum=0;
    cin>>a>>b>>m;
    int arr[a],brr[b];
    for(int i=0;i<a;i++)
    cin>>arr[i];
    
    
    for(int i=0;i<b;i++)
        cin>>brr[i];
   
    while(m--)
    {
        int x,y,c;
        cin>>x>>y>>c;
        int sum=arr[x-1]+brr[y-1]-c;
        if(sum<mn)
        mn=sum;
    }
    sort(arr,arr+a);
     sort(brr,brr+b);
     int s=arr[0]+brr[0];
    if(s<mn)
    cout<<s<<endl;
    else
    cout<<mn<<endl;
    return 0;
}

Measured memory_bytes: 1792
#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(){
    int n,m;
    cin >> n >> m;
    vector <string> a(n),b(m);
    rep(i,n){
        cin >> a[i];
    }
    rep(i,m){
        cin >> b[i];
    }

int ans=0;
rep(l,n-m+1){
    rep(i,n-m+1){
        rep(j,m){
            if(b[j]!=a[j+l].substr(i,m)){
                break;
            }
            if(j==(m-1)){
            ans=1;
            }
        }
    }
}

    if(ans==1){
        cout << "Yes" << endl;
    }
    else{
        cout << "No" << endl;
    }

    

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main() {
  int N;
  cin >> N;
  vector<long long int> A(N);
  vector<long long int> B;
  long long ans = 0;
  for(int i = 0; i < N; i++) {
    cin >> A.at(i);
    long long int a = A.at(i);
    B.push_back(a);
    if(i > 0) {
      if(B.at(i - 1) > B.at(i)) {
        ans += B.at(i - 1) - B.at(i);
        B.at(i) = B.at(i - 1);
      }
    }
  }
  cout << ans << endl;
}

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

X = 10 ** 9 + 7
ans = 0

if N - M < 2:
    if N == M:
        ans = 2
    elif abs(N - M) == 1:
        ans = 1

    for i in range(N):
        ans *= N - i
        ans %= X
    for i in range(M):
        ans *= M - i
        ans %= X

print(ans)


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

int n;
int a[100000];

int main() {
    cin >> n;
    for (int i = 0; i < n; ++i) cin >> a[i];

    bool flag = false;
    for (int j = 0; j < n; ++j) {
        if (a[j] - a[j - 1] < 0) {
            flag = true;
            break;
        } else if (j == 0) {
        } else if (a[j] - a[j - 1] > 0) {
            a[j]--;
        }
    }

    if (flag) {
        cout << "No" << endl;
    } else {
        cout << "Yes" << endl;
    }
}


Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
typedef long long ll;
using namespace std;
const ll inf = 1LL << 50;

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

    const int NMAX = 1000;
    const int MMAX = 2000;
    int a[MMAX], b[MMAX];
    ll c[MMAX];

    for (int i = 0; i < M; i++) {
        cin >> a[i] >> b[i] >> c[i];
        c[i] = -c[i];
    }

    ll dist[NMAX];
    fill(dist, dist+NMAX, inf);

    dist[0] = 0;

    for (int loop = 0; loop < N - 1; loop++) {
        for (int i = 0; i < M; i++) {
            if (dist[a[i] - 1] == inf) continue;
            if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
                dist[b[i] - 1] = dist[a[i] - 1] + c[i];
            }
        }
    }

    ll ans = dist[N - 1];

    bool negative[NMAX];
    fill(negative, negative+NMAX, false);

    for (int loop = 0; loop < N; loop++) {
        for (int i = 0; i < M; i++) {
            if (dist[a[i] - 1] == inf) continue;

            if (dist[b[i] - 1] > dist[a[i] - 1] + c[i]) {
                dist[b[i] - 1] = dist[a[i] - 1] + c[i];
                negative[b[i] - 1] = true;
            }

            if (negative[a[i] - 1] == true) {
                negative[b[i] - 1] = true;
            }
        }
    }

    if (negative[N-1]) cout << "inf" << endl;
    else cout << -ans << endl;

    return 0;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void)
{
	int i, j;
	
	for (i = 0; i < 9; i++){
		for (j = 0; j < 9; j++){
			printf("%dx%d=%d\n", i+1, j+1, (i+1)*(j+1));
		}
	}
	
	
	return (0);
}

Measured memory_bytes: 520
//Only for codeforces
#include<bits/stdc++.h>
using namespace std;
//#define ll long long int
#define ld long double
#define int long long
#define pb push_back 
#define mod 1000000007
#define mod2 998244353
#define Z(c) (int)(c).size()
#define F first
#define S second
#define nl "\n"
//#define mp make_pair
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define clber cin.ignore(numeric_limits<streamsize>::max(),'\n')
#define rep(i,iv,n) for(int (i)=(iv);(i)<(n);(i)++)
#define D1(x) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<nl
#define D2(x,y) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<nl
#define D3(x,y,z) cerr <<"At line "<<__LINE__<<" "<<#x<<"="<<x<<" "<<#y<<"="<<y<<" "<<#z<<"="<<z<<nl
#define pi 3.1415926536
#define BS binary_search
#define LB lower_bound
#define UB upper_bound
#define tr(it,ct) for(auto &(it) : (ct))
typedef vector< int > vi;
typedef vector< vi > vvi;
typedef pair< int,int > pii;
typedef vector< pii > vp;

int power(int a,int n,int lelo)
{
        if(n==0)
                return 1;
        if(n==1)
                return a;
        if(n==2)
                return (a*a)%lelo;
        if(n%2)
                return (a*power(a,n-1,lelo))%lelo;
        else
                return power(power(a,n/2,lelo),2,lelo)%lelo;
}


void swap(int &a,int &b)
{ int tm=a; a=b; b=tm; }

 const int N=1e+5;
 

void solve()
{ 
  int n; cin>>n; vi v(n+1); rep(i,1,n+1) cin>>v[i];
  int dp[n+1]; rep(i,0,n+1) dp[i]=1e10;
  dp[0]=0; dp[1]=0; dp[2]=abs(v[1]-v[2]);
   
   rep(i,3,n+1)
   dp[i]=min(dp[i-2]+abs(v[i-2]-v[i]),dp[i-1]+abs(v[i-1]-v[i]));

   cout<<dp[n];  

}


signed main()
{
  ios_base::sync_with_stdio(0);
  cin.tie(0); cout.tie(0); 
    
  
  int t=1;
   
//  cin>>t;
rep(i,1,t+1)
  { // cout<<"Case #"<<i<<": ";
   solve();
   
   if(i<t)
   cout<<"\n";
  }
 
 
 return 0; 
}

Measured memory_bytes: 1792
n = int(input())
answer = 0

for i in range(1, n + 1):       # range内を出力(i)していく
    if i % 3 != 0 and i % 5 != 0:
        answer += i             # iを足していったものがanswer
print(answer)                   # 実際に見えるように出力


Measured memory_bytes: 9148
#include <bits/stdc++.h>
using namespace std;
#include <iostream>
#include <vector>
#include <cstdlib>
#include <cmath>
#include <math.h>
#include <sstream>
#include <numeric>
#include <cctype>
#include <bitset>
#include <cassert>
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep1(i, n) for (int i = 1; i <= (int)(n); i++)
#define rep2(i, s, n) for (int i = (s); i < (int)(n); i++)
#define SIZE 100005
#define INF 1000000000000000LL
using pint = pair<int,int>;
using vec = vector<int>;
using ll=long long;
using vll = vector<ll>;
using vvll = vector<vector<ll>>;
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return true; } return false; }
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return true; } return false; }


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

    int n; cin>>n;
    vec d(n+1);
    rep1(i,n){
        for(int j=i; j<=n; j+=i){
            d[j]++;
        }
    }

    ll sum=0;
    for(ll i=1; i<=n; i++) sum += i*d[i]; 
    cout<<sum<<endl;
    }

Measured memory_bytes: 42260
n=int(input())
n*=2
A=list(input())
mod=10**9+7
if A[0]=="W" or A[-1]=="W": print(0);exit()

A=[i=="B" for i in A]
LR=[""]*n
LR[0]="L"
for i  in range(n-1):
    LR[i+1]=LR[i] if A[i]!=A[i+1] else ["L","R"][LR[i]=="L"]
from collections import Counter
#print(LR)
C=Counter(LR)
if C["L"]!=C["R"]:print(0);exit()
if LR[-1]=="L": print(0);exit()

r=0
ans=1
n//=2
for s in range(2*n-1,-1,-1):
    if LR[s]=="R":
        r+=1
    else:
        ans*=r
        ans%=mod
        r-=1
for i in range(1,n+1):
    ans*=i
    ans%=mod
print(ans)

Measured memory_bytes: 12248
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0;i<n;i++)
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }
typedef long long ll;
using namespace std;
int main(void){
    int n;cin>>n;
    int x=n%10;
    if(x==2||x==4||x==5||x==7||x==9)cout<<"hon"<<endl;
    else if(x==0||x==1||x==6||x==8)cout<<"pon"<<endl;
    else cout<<"bon"<<endl;
}


Measured memory_bytes: 3632
/**
 * code generated by JHelper
 * More info: https://github.com/AlexeyDmitriev/JHelper
 * @author NikuKyabe
 */

#include <iostream>
#include <fstream>

#include "bits/stdc++.h"
using namespace std;
#define MOD 1000000007
//#define MOD 998244353
const double EPS = 1e-9;
#define INF (1LL<<60)
#define D double
#define fs first
#define sc second
#define int long long
#define FOR(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define RFOR(i,a,b) for(int i = (int)(b-1);i>=(int)(a);--i)
#define REP(i,n)  FOR(i,0,(n))
#define RREP(i,n) RFOR(i,0,(n))
#define ITR(itr,mp) for(auto itr = (mp).begin(); itr != (mp).end(); ++itr)
#define RITR(itr,mp) for(auto itr = (mp).rbegin(); itr != (mp).rend(); ++itr)
#define range(i,a,b) ((a)<=(i) && (i)<(b))
#define debug(x)  cout << #x << " = " << (x) << endl;
#define SP << " " <<
#define outdicimal out << fixed << setprecision(10)//TODO 小数点以下の桁数の変更
typedef pair<int,int> P;
typedef vector<int> vec;
typedef vector<vector<int>> mat;


class BExactlyNPoints {
public:
	void solve(std::istream& in, std::ostream& out) {
    int n;
    in >> n;
    int sum = 0;
    int cnt = 0;
    vec a;
    while(n > sum){
      cnt++;
      sum += cnt;
    }
    FOR(i, 1, cnt + 1) {
      if(sum - n != i){
        out << i << endl;
      }
    }
	}
};


signed main() {
  ios::sync_with_stdio(false);
  cout.tie(0);
  cout << fixed;
	BExactlyNPoints solver;
	std::istream& in(std::cin);
	std::ostream& out(std::cout);
	solver.solve(in, out);
	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
template <class T> int size(const T &x) { return x.size(); }
#define rep(i,a,b) for (decltype(a) i=(a); i<(b); ++i)
#define iter(it,c) for (decltype((c).begin()) it = (c).begin(); it != (c).end(); ++it)
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef long long ll;
typedef unsigned long long ull;
const int INF = ~(1<<31);

const double EPS = 1e-9;
const double pi = acos(-1);
typedef unsigned long long ull;
typedef vector<vi> vvi;
typedef vector<vii> vvii;
template <class T> T smod(T a, T b) {
  return (a % b + b) % b; }

ll gcd(ll a, ll b) { return b == 0 ? a : gcd(b, a % b); }


int main()
{
    ll n, m;
    string s, t;
    cin >> n >> m;
    cin >> s;
    cin >> t;
    ll g = gcd(n, m);
    ll l = n*m/g;
    map<ll, char> r;
    rep(i,0,n)
    {
        r[i*l/n] = s[i];
    }
    bool fail = false;
    rep(j,0,m)
    {
        auto it = r.find(j*l/m);
        if(it != r.end() && it->second != t[j]) fail = true;
    }
    if(fail) cout << -1 << endl;
    else cout << l << endl;

    return 0;
}


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

int main() {
    int N;
    cin>>N;
    long A[N], B[N];
    for(int i=0;i<N;++i){
        cin>>A[i]>>B[i];
    }
    long sum = 0;
    long ans = 0;
    for(int i=N-1;i>=0;--i){
        A[i] += ans;
        if(A[i] % B[i]==0) continue;
        ans += B[i] - (A[i] % B[i]);
    }
    cout<<ans<<endl;
}


Measured memory_bytes: 1920