akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef int ll;
typedef long long int li;
ll x,res;
inline ll read()
{
    register ll num=0,neg=1;
    register char ch=getchar();
    while(!isdigit(ch)&&ch!='-')
    {
        ch=getchar();
    }
    if(ch=='-')
    {
        neg=-1;
        ch=getchar();
    }
    while(isdigit(ch))
    {
        num=(num<<3)+(num<<1)+(ch-'0');
        ch=getchar();
    }
    return num*neg;
} 
int main()
{
	x=read(),res=(x/500)*1000,x%=500;
	res+=(x/5)*5,printf("%d\n",res);
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, a, n) for(int i = a; i < n; i++)
#define repr(i, a, b) for(int i = a; i >= b; i--)
#define int long long
#define all(a) a.begin(), a.end()
#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
using namespace std;
typedef pair<int, int> P;
const int mod = 1000000007;
const int INF = 1e15;

signed main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin >> n;
    vector<int> t(n + 1), x(n + 1), y(n + 1);
    t[0] = x[0] = y[0] = 0;
    rep(i, 1, n + 1) cin >> t[i] >> x[i] >> y[i];
    bool f = true;
    rep(i, 1, n + 1){
        int diff = abs(x[i] - x[i - 1]) + abs(y[i] - y[i - 1]);
        int tm = t[i] - t[i - 1];
        if(diff <= tm && diff % 2 == tm % 2) ;
        else f = false;
    }
    if(f) cout << "Yes" << endl;
    else cout << "No" << endl;
}

Measured memory_bytes: 2560
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<iostream>
#include<string>
#include<vector>
#include<stack>
#include<bitset>
#include<cstdlib>
#include<cmath>
#include<set>
#include<list>
#include<deque>
#include<map>
#include<queue>
#include<sstream>
using namespace std;
typedef long long LL;
const int INF = 0x3f3f3f3f;
LL n;


int main()
{
	cin >> n;
	LL base = 0;
	LL a = 1;
	while(a <= n){
		base += a;
		a *= 2;
	}
	cout << base << endl;
	return 0;
}


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

namespace AtCoder
{
    class Program
    {
        static void Main(string[] args)
        {
            MainStream();
        }
        static void MainStream()
        {
            Scan sc = new Scan();
            write wr = new write();

            int[] nk = sc.intarr;
            int n = nk[0];
            int k = nk[1];

            int[] h = sc.intarr;

            int count = 0;

            for(int i=0; i<n; i++)
            {
                if(h[i] >= k)
                {
                    count++;
                }
            }
            wr.wri(count);
        }


    }

    class Scan
    {
        public string str => Console.ReadLine();

        public string[] strarr => str.Split(' ');

        public long[] longarr => strarr.Select(long.Parse).ToArray();
        public int[] intarr => strarr.Select(int.Parse).ToArray();
        public char[] chararr => str.ToArray();


    }



    class write
    {
        public void wri<Type>(Type x)
        {
            Console.WriteLine(x);
        }
    }

    class Method
    {
        static public int max(params int[] nums)
        {

            int maxx = nums[0];
            for (int i = 1; i < nums.Length; i++)
            {
                maxx = Math.Max(maxx, nums[i]);
            }
            return maxx;
        }
    }
}


Measured memory_bytes: 18784
n, c, k = gets.split.map(&:to_i)
ts = n.times.map { gets.to_i }.sort!.reverse!

ans = 1
base = ts.first
passengers = 1

1.upto(n - 1) do |i|
  if ts[i] + k < base || (ts[i] + k <= base + k && passengers == c)
    ans += 1
    passengers = 0
    base = ts[i]
  end

  passengers += 1
end

puts ans


Measured memory_bytes: 4016
// Zende bad Shoma nasime faghat !
#include <bits/stdc++.h>

#define pb push_back
#define F first
#define S second
#define all(x) x.begin(), x.end()
#define debug(x) cerr << #x << " : " << x << '\n'

using namespace std;

typedef long long ll;
typedef long double ld;
typedef string str;
typedef pair<ll, ll> pll;

const ll Mod = 1000000007LL;
const int N = 1e6 + 10;
const ll Inf = 2242545357980376863LL;
const ll Log = 26;

int la = 0;

int nx[N][Log];
int cnt[N];

str s[N];
ll n;
int C[30];

int main(){
	ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
	memset(nx, -1, sizeof nx);

	cin >> n;
	for(int i = 0; i < n; i++){
		cin >> s[i];
	}
	sort(s,s + n, [&](str &A, str &B){
		return A.size() < B.size();
	});
	str t;
	ll ans = 0;
	for(int i = 0; i < n; i++){
		memset(C, 0, sizeof C);

		t = s[i];
		reverse(all(t));
		for(auto &c : t) C[c - 'a'] ++;
		int nw = 0;
		int ch;
		for(auto &c : t){
			ch = c - 'a';
			if(nx[nw][ch] == -1)
				nx[nw][ch] = ++ la;
			for(int j = 0; j < Log; j++){
				if(nx[nw][j] != -1 && C[j] > 0){
					ans += cnt[nx[nw][j]];
					//cerr << cnt[nx[nw][j]] << '\n';
				}
			}
			nw = nx[nw][ch];
			C[ch] --;
		}
		cnt[nw] ++;
	}
	cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 141368
import time

start = time.time()

n = int(input())
s = list(map(int, input().split()))

s.sort()
s.reverse()

flag = True
for i in range(n):
    a = s[0:2 ** i]
    b = s[2 ** i:2 ** (i + 1)]
    for j in range(len(a)):
        if b[j] >= a[j]:
            flag = False
            break
if flag:
    print('Yes')
    exit()

s.reverse()

a = []
a.append(s[-1])
s.pop(-1)
for i in range(n):
    for j in range(len(a)):
        for k in range(len(s)):
            if a[j]>s[-1-k]:
                a.append(s[-1-k])
                s.pop(-1-k)
                break
        if time.time() - start > 1.8:
            print('Yes')
            exit()
    if len(a)!=2**(i+1):
        print('No')
        exit()

print('Yes')


Measured memory_bytes: 113608
import Data.Maybe
import Data.List

main :: IO ()
main = do
  input <- getContents
  putStrLn $ trim (solve (trim input))

--処理
solve :: String -> String
solve s = show $ (a + b) `mod` 24 where [a, b] = fmap read (words s) :: [Int]

trimHead :: String -> String
trimHead = dropWhile (\s -> isJust (elemIndex s [' ', '\t', '\n', '\r']))

trim :: String -> String
trim = reverse . trimHead . reverse . trimHead

Measured memory_bytes: 508
{-# LANGUAGE BangPatterns #-}
import           Control.Exception           (assert)
import           Control.Monad
import           Control.Monad.Primitive
import qualified Control.Monad.ST            as ST
import qualified Data.Array.IO               as IO
import qualified Data.Array.ST               as ST
import qualified Data.Array.Unboxed          as A
import           Data.Bits
import qualified Data.ByteString.Char8       as BS
import           Data.Char
import           Data.Foldable
import           Data.List
import qualified Data.Map.Strict             as Map
import           Data.Maybe
import qualified Data.Sequence               as Seq
import qualified Data.Set                    as Set
import qualified Data.Vector                 as VB
import qualified Data.Vector.Mutable         as VBM
import qualified Data.Vector.Unboxed         as V
import qualified Data.Vector.Unboxed.Mutable as VM
import           Debug.Trace

readInt = fst . fromJust . BS.readInt
readIntList = map readInt . BS.words
getInt = readInt <$> BS.getLine
getIntList = readIntList <$> BS.getLine
getIntVec n = V.unfoldrN n (BS.readInt . BS.dropWhile isSpace) <$> BS.getLine

readInteger = fst . fromJust . BS.readInteger
readIntegerList = map readInteger . BS.words
getInteger = readInteger <$> BS.getLine
getIntegerList = readIntegerList <$> BS.getLine

inf :: Int
inf = 10^18

main = do
  [n, k] <- getIntList
  as <- getIntVec n

  let calcNCut i x res
        | i == n = res
        | otherwise = let a = as V.! i
                          m = (a+x-1) `div` x - 1
                      in calcNCut (i+1) x (res+m)

      isOk x = calcNCut 0 x 0 <= k

      solve ng ok | abs (ok - ng) <= 1  = ok
                  | otherwise = let m = (ok + ng) `div` 2
                                    (ok', ng') = if isOk m then (m, ng) else (ok, m)
                              in solve ng' ok'

  print $ solve 0 inf

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

#define int long long

#define rep(i,n) for(int i=0;i<(n);i++)
#define pb push_back
#define all(v) (v).begin(),(v).end()
#define fi first
#define se second
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;

template<typename A,typename B>inline void chmin(A &a,B b){if(a>b)a=b;}
template<typename A,typename B>inline void chmax(A &a,B b){if(a<b)a=b;}

int N,M;
vint G[1111];
vint anc;
bool used[1111];
bool isanc[1111];

vint uku;


bool latte(vint &vs){
	vint lis(N);
	rep(i,vs.size())lis[vs[i]]=true;
	rep(i,vs.size()){
		for(auto u:G[vs[i]]){
			if(u==vs[(i+1)%vs.size()])continue;
			if(!lis[u])continue;
			int k=find(all(vs),u)-vs.begin();
			if(k<i){
				vint x;
				for(int j=k;j<=i;j++)x.pb(vs[j]);
				vs=x;
				return true;
			}
			else{
				vint x;
				for(int j=0;j<=i;j++)x.pb(vs[j]);
				for(int j=k;j<vs.size();j++)x.pb(vs[j]);
				vs=x;
				return true;
			}
		}
	}
	return false;
}

void dfs(int v){
	used[v]=true;
	isanc[v]=true;
	anc.pb(v);
	for(auto u:G[v]){
		if(!used[u]){
			dfs(u);
		}
		if(!isanc[u])continue;
		if(uku.size())continue;
		int k=find(all(anc),u)-anc.begin();
		for(int j=k;j<anc.size();j++)uku.pb(anc[j]);
	}
	isanc[v]=false;
	anc.pop_back();
}

signed main(){
	cin>>N>>M;
	rep(i,M){
		int a,b;
		cin>>a>>b;
		a--;b--;
		G[a].pb(b);
	}

	rep(i,N){
		if(!used[i]){
			dfs(i);
		}
	}

	if(uku.size()==0){
		cout<<"-1"<<endl;
		return 0;
	}

	while(latte(uku));
	cout<<uku.size()<<endl;
	rep(i,uku.size())cout<<uku[i]+1<<endl;
	return 0;
}

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

#if MYDEBUG
#include "lib/cp_debug.hpp"
#else
#define DBG(...) ;
#endif
#if __cplusplus <= 201402L
template <typename T>
T gcd(T a, T b) { return ((a % b == 0) ? b : gcd(b, a % b)); }
template <typename T>
T lcm(T a, T b) { return a / gcd(a, b) * b; }
#endif
using LL = long long;
constexpr LL LINF = 334ll << 53;
constexpr int INF = 15 << 26;
constexpr LL MOD = 1E9 + 7;

namespace Problem {
using namespace std;

class Solver {
 public:
  LL n;
  vector<vector<LL>> price;
  Solver(LL n) : n(n), price(2, vector<LL>(3)){};

  void solve() {
    for (int i = 0; i < 2; ++i) {
      for (int j = 0; j < 3; ++j) {
        cin >> price[i][j];
      }
    }
    for (int i = 0; i < 2; ++i) {
      int cnt = 0;
      for (int j = 0; j < 3; ++j) {
        if (price[i][j] < price[(i + 1) % 2][j]) cnt++;
      }
      if (cnt == 0) {
        continue;
      } else if (cnt == 1) {
        int k;
        for (int j = 0; j < 3; ++j) {
          if (price[i][j] < price[(i + 1) % 2][j]) k = j;
        }
        LL amount = n / price[i][k];
        n = n - amount * price[i][k] + amount * price[(i + 1) % 2][k];
      } else if (cnt == 2) {
        vector<int> k;
        for (int j = 0; j < 3; ++j) {
          if (price[i][j] < price[(i + 1) % 2][j]) k.push_back(j);
        }
        LL ma = n;
        for (LL h = 0; h <= n / price[i][k[0]]; ++h) {
          LL amount = (n - h * price[i][k[0]]) / price[i][k[1]];
          LL tmp = n + h * (price[(i + 1) % 2][k[0]] - price[i][k[0]]) + amount * (price[(i + 1) % 2][k[1]] - price[i][k[1]]);
          ma = max(ma, tmp);
        }
        n = ma;
      } else {
        LL ma = n;
        for (LL g = 0; g <= n / price[i][0]; ++g) {
          for (LL h = 0; h <= (n - g * price[i][0]) / price[i][1]; ++h) {
            LL amount = (n - g * price[i][0] - h * price[i][1]) / price[i][2];
            LL tmp = n + g * (price[(i + 1) % 2][0] - price[i][0]) + h * (price[(i + 1) % 2][1] - price[i][1]) + amount * (price[(i + 1) % 2][2] - price[i][2]);
            ma = max(ma, tmp);
          }
        }
        n = ma;
      }
    }
    cout << n << endl;
  }
};

}  // namespace Problem

int main() {
  std::cin.tie(0);
  std::ios_base::sync_with_stdio(false);
  // std::cout << std::fixed << std::setprecision(12);
  long long n = 0;
  std::cin >> n;

  Problem::Solver sol(n);
  sol.solve();
  return 0;
}


Measured memory_bytes: 256
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

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

func main() {
	sc.Split(bufio.ScanWords)

	var s string
	fmt.Scan(&s)

	slice := strings.Split(s, "")
	m := map[string]int{}

	for _, ss := range slice {
		m[ss]++
	}

	if len(m) == 2 {
		for _, v := range m {
			if v != 2 {
				fmt.Println("No")
				return
			}
		}
		fmt.Println("Yes")
		return
	}

	fmt.Println("No")

}


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

int strong(int x) {
	if (x==1) return 100;
	return x;
}

int main() {
	cin.tie(0); cout.tie(0); ios_base::sync_with_stdio(0);
	int a,b; cin>>a>>b;
	int x=strong(a),y=strong(b);
	if (x==y) cout<<"Draw";
	else if (x>y) cout<<"Alice";
	else cout<<"Bob";
	return 0;
}


Measured memory_bytes: 256
#include<cstdio>
#include<algorithm>
#include<stack>
#include<queue>
#include<string>
using namespace std;

int main(void){
        int i;
        int n,m;
        int a[10001];
        

        scanf("%d%d",&n,&m);
        for(i=0;i<m;i++){
                scanf("%d", &a[i]);
        }
        for(i=0;i<m;i++){
                n -= a[i];
        }
        if (n >= 0){
                printf("%d\n",n);
        } else {
                printf("-1\n");
        }

        return 0;
}



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

int main(){
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  int a,b;
  cin>>a>>b;
  int f=0;
  for(int i=a;i<=b;i++){
    int c[5];
    int j=0;
    int d=i;
    while(d){
       c[j]=d%10;
       d=d/10;
       j++;
    }
    int x=1;
    for(int l=0;l<j;l++){
      if(c[l]==c[j-l-1]){
          x=1;
      }else{
          x=0;
          l=5;
      }
    }
    if(x){
      f++;
    }
  }
cout<<f;
}


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

constexpr int inf = 0x3f3f3f3f;
constexpr ll linf = 0x3f3f3f3f3f3f3f3fLL;

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

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

    ll ans = 0;
    ll cur = a[0];
    for (int i = 1; i < n; i++) {
        if (a[i] < cur) {
            ans += cur - a[i];
        } else {
            cur = a[i];
        }
    }
    cout << ans << endl;
    return 0;
}


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

#define int ll
#define X first
#define Y second
#define mp make_pair
#define pb push_back
#define all(a) (a).begin(), (a).end()
#define sz(a) (int)(a).size()
typedef long long ll;
typedef long double ld;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;
mt19937 rng(chrono::high_resolution_clock::now().time_since_epoch().count());

const int INF = 1e9 + 7;

signed main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n, k;
  cin >> n >> k;
  vector<int> a(n);
  for (int i = 0; i < n; ++i) {
    cin >> a[i];
  }
  int l = 0, r = INF;
  while (r - l > 1) {
    int m = (l + r) / 2;
    int need = 0;
    for (int i = 0; i < n; ++i) {
      need += (a[i] - 1) / m;
    }
    if (need <= k) {
      r = m;
    } else {
      l = m;
    }
  }
  cout << r;
  return 0;
}


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

typedef long long ll;
const int INF = 1e9;
const ll MOD = 1e9 + 7;
const ll MOD2 = 998244353;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define MP make_pair
#define F first
#define S second
#define PB push_back
#define dump(x)  cout << #x << " = " << (x) << endl;	// debug
#define SZ(x) ((ll)(x).size())
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define pvd(v) cout << setprecision(16) << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, left, right)  (a).begin()+(left),(a).begin()+(right)	// left to (right-1)

int main() {
	int n;
	cin >> n;
	vector<int>h(n);
	FOR(i, 0, n - 1) {
		cin >> h[i];
	}
	int res = 0;
	while (1) {
		int i = 0;
		while (h[i] == 0) {
			if (i == n - 1) {
				pv(res);
				return 0;
			}
			else {
				i++;
			}
		}
		for (int j = i; j<=n-1 && h[j] != 0; j++) {
			h[j]--;
		}
		res++;
	}
	pv(res)
	return 0;
}

Measured memory_bytes: 3604
#include <iostream>
#include <cmath>

const int LIMIT = 1000000;

void eratosthenes(int n, bool *primes);

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

    bool primes[LIMIT];
    primes[0] = primes[1] = false;
    for (int i = 2; i < LIMIT; ++i)
        primes[i] = true;
    eratosthenes(LIMIT, primes);

    int num_of_primes[LIMIT] = {};
    for (int i = 1; i < LIMIT; ++i) {
        num_of_primes[i] = num_of_primes[i-1];
        if (primes[i])
            ++num_of_primes[i];
    }

    int n;
    while (std::cin >> n) {
        std::cout << num_of_primes[n] << std::endl;
    }
}

void eratosthenes(int n, bool *primes)
{
    double root_n = std::sqrt((double) n);
    for (int i = 2; i <= root_n; ++i)
        if (primes[i])
            for (int j = i*i; j <= n; j += i)
                primes[j] = false;
}




Measured memory_bytes: 7964
//#include <bits/stdc++.h>
#include <iostream>
#include <string>
#include <vector>
#include <set>
#include <algorithm>

#define fastio ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define endl "\n"

using namespace std;
using ll = long long;

const ll MOD = 1000000007LL; // = 10^9 + 7
const double PI = 3.14159265358979;

void solve()
{
  string s;
  int k;
  cin >> s >> k;
  set<char> ana;
  for(const char& c : s) ana.insert(c);

  vector<string> subset;
  for(const char c : ana)
  {
    for(int i = 0; i < s.length(); ++i)
    {
      if (s[i] == c)
      {
        for(int j = 1; i + j <= min((int)s.length(), i + k); ++j)
        {
          subset.emplace_back(s.substr(i, j));
        }
      }
    }
    if (subset.size() >= k)
    {
      sort(subset.begin(), subset.end());
      subset.erase( unique(subset.begin(), subset.end()), subset.end() );

      // for(const auto& v : subset) cout << v << endl;
      // cout << "-----\n";

      if (subset.size() >= k)
      {
        cout << subset[k - 1];
        return;
      }
    }
  }



}

int main()
{
  fastio;
  solve();

  return 0;
}

Measured memory_bytes: 4228
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF          1e9
#define INFLL        1e18
#define EPS          1e-9
#define MOD          1000000007
#define REP(i,n)     for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)    for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)    for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)   for(ll i=(n);i>0;--i)
#define REPC(i,obj)  for(auto i:obj)
#define ALL(obj)     (obj).begin(),(obj).end()
#define SETP(n)      cout<<fixed<<setprecision(n)
#define VV(T,h,w)    move(vector<vector<T>>(h,move(vector<T>(w))))
#define VVI(T,h,w,i) move(vector<vector<T>>(h,move(vector<T>(w,i))))
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

int main()
{
	ll n = in();
	ll ans = 0, cnt = 1, now = in();
	REP(i, n - 1) {
		ll foo = in();
		if (now == foo) {
			++cnt;
		} else {
			ans += cnt / 2;
			cnt = 1;
		}
		now = foo;
	}
	ans += cnt / 2;
	cout << ans << endl;
}

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

int n;
int ans = 0;

int main(){
	scanf("%d",&n);
	for(int i=1;i<=n;i++){
		int x;
		scanf("%d",&x);
		ans = __gcd(ans,x);
	}
	int ret = 0;
	while(ans > 0 && ans%2 == 0){
		ret++;
		ans/=2;
	}
	printf("%d\n",ret);
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
int main(void){
  int n,t[100],m,p[100],x[100],i;
  scanf("%d",&n);
  int total=0;
  for(i=0;i<n;i++){
    scanf("%d",&t[i]);
    total+=t[i];
  }
  int ttotal=total;
  scanf("%d",&m);
  for(i=0;i<m;i++){
    scanf("%d %d",&p[i],&x[i]);
  }
  for(i=0;i<m;i++){
    total=ttotal;
    total=total-t[p[i]-1]+x[i];
    printf("%d\n",total);
  }
  return 0;
}

Measured memory_bytes: 128
# include <bits/stdc++.h>
# define rep(i, n) for(ll i = 0; i < (n); ++i)
# define reps(i, n) for(ll i=1, i##_len=(n); i<=i##_len; ++i)
# define rrep(i, n) for(ll i=((int)(n)-1); i>=0; --i)
# define rreps(i, n) for(ll i=((int)(n)); i>0; --i)
# define ll long long
# define ALL(x) (x).begin(), (x).end()
# define SZ(x) ((int)(x).size())
# define pb push_back
# define optimize_cin() cin.tie(0); ios::sync_with_stdio(false)
# define P pair<int, int>
# define mp make_pair
using namespace std;
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; }

ll lmax(ll a, ll b){
  if(a>= b) return a; else return b;
}

ll lmin(ll a, ll b){
  if(a>= b) return b; else return a;
}

int main() {
  int n; cin >> n;
  vector<ll> a(n+1), b(n);
  rep(i, n+1) cin >> a[i];
  rep(i, n) cin >> b[i];

  ll ans = 0;
  rep(i, n){
    ans += lmin(a[i], b[i]);
    if(b[i] > a[i]){
      b[i] -= a[i];
      ans += lmin(a[i+1], b[i]);
      a[i+1] = lmax(a[i+1] - b[i], 0);
    }
  }

  cout << ans << endl;
}


Measured memory_bytes: 4820
#include <bits/stdc++.h>
#define debug(x) cerr << #x << ": " << x << '\n';
using namespace std;
using ll = long long;
using Point = pair<int, int>;
const int INF = (int)1e9;

int N, M;
Point p[100000];

bool comp(Point a, Point b){
    if(a.second < b.second)return true;
    else return false;
}

int main(void){
    cin >> N >> M;
    for(int i = 0; i < M; i++){
        int a, b; cin >> a >> b;
        p[i] = Point(a-1, b-1);
    }

    sort(p, p+M, comp);
    int bridge_east = -1;
    int res = 0;
    for(int i = 0; i < M; i++){
        if(p[i].first > bridge_east){
            res++;
            bridge_east = p[i].second-1;
        }
    }
    

    /*
    for(int i = 0; i < M; i++) p[i].second *= -1;
    sort(p, p+M);
    for(int i = 0; i < M; i++) p[i].second *= -1;

    int pos_a = INF;
    int pos_bridge = INF;
    int res = 0;
    for(int i = M-1; i >= 0; i--){
        if(pos_a == p[i].first) continue;

        pos_a = p[i].first;
        if(p[i].second = pos_bridge){
            pos_bridge = p[i].first;
            res++;
        }
    }
    */

    cout << res << '\n';

    return 0;
}

Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define all(v) (v).begin(), (v).end()
#define fastIO ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);


signed main(){
    fastIO
    int n; cin >> n;
    set<int> s;
    for(int i =0, temp; i<n; i++){
        cin >> temp;
        s.insert(temp);
    }
    cout << (s.size() == n ? "YES" : "NO");
}

Measured memory_bytes: 9600
import std.conv, std.functional, std.range, std.stdio, std.string;
import std.algorithm, std.array, std.bigint, std.bitmanip, std.complex, std.container, std.math, std.mathspecial, std.numeric, std.regex, std.typecons;
import core.bitop;

class EOFException : Throwable { this() { super("EOF"); } }
string[] tokens;
string readToken() { for (; tokens.empty; ) { if (stdin.eof) { throw new EOFException; } tokens = readln.split; } auto token = tokens.front; tokens.popFront; return token; }
int readInt() { return readToken.to!int; }
long readLong() { return readToken.to!long; }
real readReal() { return readToken.to!real; }

bool chmin(T)(ref T t, in T f) { if (t > f) { t = f; return true; } else { return false; } }
bool chmax(T)(ref T t, in T f) { if (t < f) { t = f; return true; } else { return false; } }

int binarySearch(alias pred, T)(in T[] as) { int lo = -1, hi = cast(int)(as.length); for (; lo + 1 < hi; ) { const mid = (lo + hi) >> 1; (unaryFun!pred(as[mid]) ? hi : lo) = mid; } return hi; }
int lowerBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a >= val)); }
int upperBound(T)(in T[] as, T val) { return as.binarySearch!(a => (a > val)); }

struct ModInt(int M_) {
  alias M = M_;
  int x;
  this(ModInt a) { x = a.x; }
  this(long a) { x = cast(int)(a % M); if (x < 0) x += M; }
  ref ModInt opAssign(long a) { return (this = ModInt(a)); }
  ref ModInt opOpAssign(string op)(ModInt a) {
    static if (op == "+") { x += a.x; if (x >= M) x -= M; }
    else static if (op == "-") { x -= a.x; if (x < 0) x += M; }
    else static if (op == "*") { x = cast(int)((cast(long)(x) * a.x) % M); }
    else static if (op == "/") { this *= a.inv(); }
    else static assert(false);
    return this;
  }
  ref ModInt opOpAssign(string op)(long a) {
    static if (op == "^^") {
      ModInt t2 = this, te = ModInt(1);
      for (long e = a; e; e >>= 1) {
        if (e & 1) te *= t2;
        t2 *= t2;
      }
      x = cast(int)(te.x);
      return this;
    } else return mixin("this " ~ op ~ "= ModInt(a)");
  }
  ModInt inv() const {
    int a = x, b = M, y = 1, z = 0, t;
    for (; ; ) {
      t = a / b; a -= t * b;
      if (a == 0) {
        assert(b == 1 || b == -1);
        return ModInt(b * z);
      }
      y -= t * z;
      t = b / a; b -= t * a;
      if (b == 0) {
        assert(a == 1 || a == -1);
        return ModInt(a * y);
      }
      z -= t * y;
    }
  }
  ModInt opUnary(string op)() const if (op == "-") { return ModInt(-x); }
  ModInt opBinary(string op, T)(T a) const { return mixin("ModInt(this) " ~ op ~ "= a"); }
  ModInt opBinaryRight(string op)(long a) const { return mixin("ModInt(a) " ~ op ~ "= this"); }
  string toString() const { return x.to!string; }
}

enum MO = 1000000007;
alias Mint = ModInt!MO;


void main() {
  try {
    for (; ; ) {
      const N = readInt();
      auto A = new int[N];
      foreach (i; 0 .. N) {
        A[i] = readInt();
      }
      
      auto cnt = new int[N + 1];
      cnt[0] = 3;
      Mint ans = 1;
      foreach (i; 0 .. N) {
        ans *= cnt[A[i]];
        --cnt[A[i]];
        ++cnt[A[i] + 1];
      }
      writeln(ans);
    }
  } catch (EOFException e) {
  }
}


Measured memory_bytes: 4404
#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 ALL(v) (v).begin(),(v).end()
#define fi first
#define se second
template<typename A, typename B> inline bool chmax(A &a, B b) { if (a<b) { a=b; return 1; } return 0; }
template<typename A, typename B> inline bool chmin(A &a, B b) { if (a>b) { a=b; return 1; } return 0; }
using ll = long long;
using pii = pair<int, int>;
constexpr ll INF = 1ll<<30;
constexpr ll longINF = 1ll<<60;
constexpr ll MOD = 1000000007;
constexpr bool debug = 0;
//---------------------------------//

vector<ll> findDivisor(ll n) {
	vector<ll> divisor;
	
	ll i = 1;
	for (; i * i <= n; i++) if (n % i == 0) divisor.push_back(i);
	i--;
	if (i * i == n) i--;
	for (; i >= 1; i--) if (n % i == 0) divisor.push_back(n / i);
	
	return divisor;
}

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

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

ll A, B;

int main() {
	cin >> A >> B;
	
	vector<ll> v = findDivisor(gcd(A, B));
	ll lc = 1;
	int ans = 0;
	
	for (ll cur : v) {
		if (gcd(cur, lc) == 1) {
			ans++;
			lc = lcm(cur, lc);
		}
	}
	
	cout << ans << endl;
	return 0;
}


Measured memory_bytes: 384
#include <algorithm>
#include <iostream>
#include <queue>
#include <vector>
using namespace std;
template <class T>
inline bool chmax(T &a, T b) {
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}

typedef long long ll;

/*
void dfs(vector<string> &grid, ll h, ll w, ll mh, ll mw, ll &count) {
  cout << h << " " << w << " visited" << endl;
  grid[h][w] = '#';
  count++;

  // down
  if ((h + 1) < mh && grid[h + 1][w] == '.') {
    dfs(grid, h + 1, w, mh, mw, count);
  }
  // up
  if ((h - 1) >= 0 && grid[h - 1][w] == '.') {
    dfs(grid, h - 1, w, mh, mw, count);
  }
  // right
  if ((w + 1) < mw && grid[h][w + 1] == '.') {
    dfs(grid, h, w + 1, mh, mw, count);
  }

  // left
  if ((w - 1) >= 0 && grid[h][w - 1] == '.') {
    dfs(grid, h, w - 1, mh, mw, count);
  }
}
*/

struct point{
  ll h;
  ll w;
  ll level;
};

int main() {
  ll H, W;
  cin >> H >> W;
  vector<string> grid(H);
  for (ll i = 0; i < H; i++) {
    cin >> grid[i];
  }

  ll ans = 0;
  queue<point> q;
  for (ll i = 0; i < H; i++) {
    for (ll j = 0; j < W; j++) {
      if (grid[i][j] == '.') {
        point p = {i, j, 0};
        q.push(p);

        // wfs
        vector<vector<bool>> visited(H, vector<bool>(W, false));
        ll level = 0;
        visited[i][j] = true;
        while (!q.empty()) {
          point pair = q.front();
          q.pop();
          ll h = pair.h;
          ll w = pair.w;
          ll l = pair.level;

          // cout << h << " " << w << " visited" << endl;
          level = l;

          // down
          if ((h + 1) < H && grid[h + 1][w] == '.' && visited[h + 1][w] == false) {
            // q.push(make_pair(h + 1, w));
            point t = {h + 1, w, l + 1};
            q.push(t);
            visited[h+1][w] = true;
          }
          // up
          if ((h - 1) >= 0 && grid[h - 1][w] == '.' && visited[h - 1][w] == false) {
            //q.push(make_pair(h - 1, w));
            point t = {h - 1, w, l + 1};
            q.push(t);
            visited[h-1][w] = true;
          }
          // right
          if ((w + 1) < W && grid[h][w + 1] == '.' && visited[h][w + 1] == false) {
            //q.push(make_pair(h, w + 1));
            point t = {h, w + 1, l + 1};
            q.push(t);
            visited[h][w + 1] = true;
          }

          // left
          if ((w - 1) >= 0 && grid[h][w - 1] == '.' && visited[h][w - 1] == false) {
            //q.push(make_pair(h, w - 1));
            point t = {h, w - 1, l + 1};
            q.push(t);
            visited[h][w-1] = true;
          }
        }

        // cout << "level: " << level << endl;

        ans = max(ans, level);
      }
    }
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
#define LOCAL
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); ++i)
#define rrep(i, n) for(int i=(n-1); i>=0; --i)
#define rep2(i, s, n) for(int i=s; i<(n); ++i)
#define ALL(v) (v).begin(), (v).end()
#define memr(dp, val) memset(dp, val, sizeof(dp))
using namespace std;
typedef long long ll;
static const int INTINF = (INT_MAX >> 1); // 10^9 + 10^7
static const ll LLINF = (LLONG_MAX >> 1);
static const int MAX = 100001;
static const ll MOD = 1000000007;
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; }
template<class T> inline bool int_ceil(T a, T b) { T res = a / b; if(a % b != 0) res++; return res; }
template<typename T>
using min_priority_queue = priority_queue<T, vector<T>, greater<T> >;
string to_string(string s) { return '"' + s + '"'; }
string to_string(bool b) { return b ? "true" : "false"; }
template <size_t N> string to_string(bitset<N> bs) {
  string res;
  for (size_t i = 0; i < N; ++i) res += '0' + bs[i];
  return res;
}
string to_string(vector<bool> v) {
  string res = "{";
  for (bool e : v) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p);
template <class C> string to_string(C c) {
  string res = "{";
  for (auto e : c) res += to_string(e) + ", ";
  return res += "}";
}
template <class T, class U> string to_string(pair<T, U> p) {
  return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
void debug() { cerr << '\n'; }
template <class Head, class... Tail> void debug(Head head, Tail... tail) {
  cerr << '\t' << to_string(head), debug(tail...);
}
#ifdef LOCAL
#define print(...) cerr << "[" << #__VA_ARGS__ << "]:", debug(__VA_ARGS__)
#else
#define print(...)
#endif

ll calc(ll x, ll y, ll z){
	return x * x + y * y + z * z + z * x + x * y + z * y;
}

ll dp[MAX];

int main(int argc, const char * argv[]) {
	std::cout << std::fixed << std::setprecision(15);

	memr(dp, 0);

	rep2(i, 1, 101){
		rep2(j, 1, 101){
			rep2(k, 1, 101){
				dp[calc(i, j, k)]++;
			}
		}
	}

	int n; cin >> n;

	rep(i, n){
		cout << dp[i + 1] << endl;
	}


	return 0;
}


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

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define forn(i, n) for (int i = 0; i < (int)(n); ++i)
#define for1(i, n) for (int i = 1; i <= (int)(n); ++i)
#define ford(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 rep(i, l, r) for (int i = (l); i <= (r); i++)
#define per(i, r, l) for (int i = (r); i >= (l); i--)
#define ms(x, y) memset(x, y, sizeof(x))
 
using namespace std;
 
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn = (int)1e5 + 1000;
int n, u, v, a[maxn], b[maxn], vis[maxn];
vvi g(maxn);
 
void dfs1(int now, int step) {
	for (auto it : g[now]) {
		if (a[it] == -1) {
			a[it] = step + 1;
			dfs1(it, step + 1);
		}
	}
}
void dfs2(int now, int step) {
	for (auto it : g[now]) {
		if (b[it] == -1) {
			b[it] = step + 1;
			dfs2(it, step + 1);
		}
	}
}

int main() {
	ios::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.precision(10);
    cout << fixed;
#ifdef LOCAL_DEFINE
    freopen("in", "r", stdin);
#endif
	
	ms(a, -1); ms(b, -1);
	cin >> n >> u >> v;
	forn(i, n - 1) {
		int e1, e2;
		cin >> e1 >> e2;
		g[e1].pb(e2);
		g[e2].pb(e1);
	}
	a[u] = 0;
	dfs1(u, 0);
	b[v] = 0;
	dfs2(v, 0);
	int ans = -1;
//	for1(i, n) cerr << a[i] << " " << b[i] << endl;
	for1(i, n) {
		if (a[i] <= b[i]) {
			ans = max(ans, b[i]);
		}
	}
	cout << (ans - 1) << '\n';
		
#ifdef LOCAL_DEFINE
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
#endif
	return 0;
}


Measured memory_bytes: 9088
def main():
    n=int(input())
    d=list(map(int,input().split(' ')))
    ans = 0
    for n,i in enumerate(d):
        for m,j in enumerate(d):
            if n != m:
                ans += i*j
    print(ans//2)

if __name__ == '__main__':
    main()


Measured memory_bytes: 2940
#include <bits/stdc++.h>
using namespace std;
signed main(){
  int white[105][105];
  int h,w,n,x,y,a,ans=0;
 
  cin>>w>>h>>n;

  for(int i=0;i<h;i++){
    for(int j=0;j<w;j++){
      white[i][j]=1;
    }
  }

  for(int i=0;i<n;i++){
    cin>>x>>y>>a;
    if(a == 1){
      for(int j=0;j<h;j++){
	for(int k=0;k<x;k++){
	  white[j][k]=0;
	}
      }
    }
    
    if(a == 2){
      for(int j=0;j<h;j++){
	for(int k=x;k<w;k++){
	  white[j][k]=0;
	}
      }
    }
    
    if(a == 3){
      for(int j=0;j<y;j++){
	for(int k=0;k<w;k++){
	  white[j][k]=0;
	}
      }
    }
    
    if(a == 4){
      for(int j=y;j<h;j++){
	for(int k=0;k<w;k++){
	  white[j][k]=0;
	}
      }
    }
  }
  
  for(int i=0;i<w;i++){
    for(int j=0;j<h;j++){
      ans+=white[j][i];
    }
  }
  
  cout<<ans<<endl;

  return(0);
}


Measured memory_bytes: 256
using System;
using System.Linq;//リストの使用
using System.Collections.Generic;
class Program
{
static int n = int.Parse(Console.ReadLine());//int.Parseは文字列を整数に変換。
static long[] nums = Array.ConvertAll(Console.ReadLine().Split(' '),long.Parse);
static List<long> numsThree = new List<long>();
static List<long> numsThreeR = new List<long>();
static long[] sum = new long[n+1];
static long[] sumR = new long[n+1];
static long answer = 0;
static long check = 0;

	static void Main()
	{
      
    for(int i=0; i<n; i++)
    {
    sum[0] += nums[i];
    numsThree.Add(nums[i]);
    
    sumR[n] += nums[3*n-1-i];
    numsThreeR.Add(nums[3*n-1-i]);
    }
    
    

    numsThree.Sort();//昇順にソート
    numsThreeR.Sort();//降順にソート
    numsThreeR.Reverse();

      
    for(int i=0; i<n; i++)
    {
      numsThree = PushHeap(numsThree,nums[n+i]);
      sum[i+1] = sum[i] + nums[n+i];
      numsThree = PopHeap(numsThree);
      sum[i+1] -= check;

      numsThreeR = PushHeapR(numsThreeR,nums[2*n-1-i]);
      sumR[n-1-i] = sumR[n-i] + nums[2*n-1-i];
      numsThreeR = PopHeapR(numsThreeR);
      sumR[n-1-i] -= check;
    }
    
    answer = sum[0] - sumR[0];
    //Console.WriteLine(sum[0] +" "+ sumR[0]);//デバッグ
    for(int i=1; i<=n; i++)
    {
      long ans = sum[i] - sumR[i];
      //Console.WriteLine(sum[i] +" "+ sumR[i]);//デバッグ
      if(ans > answer) answer = ans;
    }
    
	Console.WriteLine(answer);
	}

  static List<long> PushHeap(List<long> nums, long addNum)//現在のヒープnumsにaddNumを追加
{
  int n = nums.Count;
  nums.Add(addNum);

  while (n > 0)
  {
    int i = (n-1)/2;
    if (nums[n] < nums[i])//親のほうが大きいなら入れ替え。
    {
      long tmp = nums[n];
      nums[n] = nums[i];
      nums[i] = tmp;
    }
    n = i;
  }
  return nums;
}

static List<long> PopHeap(List<long> nums)//ヒープnumsからポップ
{
  int n = nums.Count - 1;
  check = nums[0];
  nums[0] = nums[n];//最大値である根を削除して配列の最後を持ってくる
  nums.RemoveAt(n);

  for (int i = 0, j; (j = 2*i+1) < n; )
  {
    if ((j != n-1) && (nums[j] > nums[j+1]))// ２つの子のうち、値の小さい方を選ぶ
      j++;
    if (nums[i] > nums[j])//子が親より小さいなら入れ替え
    {
      long tmp = nums[j];
      nums[j] = nums[i];
      nums[i] = tmp;
    }
    i = j;
  }
  return nums;
}

static List<long> PushHeapR(List<long> nums, long addNum)//現在のヒープnumsにaddNumを追加
{
  int n = nums.Count;
  nums.Add(addNum);

  while (n > 0)
  {
    int i = (n-1)/2;
    if (nums[n] > nums[i])//親のほうが小さいなら入れ替え。
    {
      long tmp = nums[n];
      nums[n] = nums[i];
      nums[i] = tmp;
    }
    n = i;
  }
  return nums;
}

static List<long> PopHeapR(List<long> nums)//ヒープnumsからポップ
{
  int n = nums.Count - 1;
  check = nums[0];
  nums[0] = nums[n];//最大値である根を削除して配列の最後を持ってくる
  nums.RemoveAt(n);

  for (int i = 0, j; (j = 2*i+1) < n; )
  {
    if ((j != n-1) && (nums[j] < nums[j+1]))// ２つの子のうち、値の大きい方を選ぶ
      j++;
    if (nums[i] < nums[j])//子が親より大きいなら入れ替え
    {
      long tmp = nums[j];
      nums[j] = nums[i];
      nums[i] = tmp;
    }
    i = j;
  }
  return nums;
}




  
}


Measured memory_bytes: 42544
import math

N, M = map(int, input().split())

if M % N == 0:
    print(M//N)
    exit()

ans = 1
for i in range(1, math.ceil(M ** 0.5)):
    if M % i == 0:
        if i*N <= M:
            ans = max(ans, i)
        if (M//i)*N <= M:
           ans = max(ans, M//i) 


print(ans)


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

using namespace std;

int main(){
 int n;
  cin >> n;
  int res=0;
 vector<int> l(n),r(n);
  for(int i=0;i<n;i++){ cin >> l[i] >> r[i];
   res+=(r[i]-l[i]+1);
  }
  cout << res << endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cmath>
#include <map>
typedef long long ll;
#define rep(i,a,b) for(int i=a;i<b;++i)
#define rrep(i,a,b) for(int i=a;i>=b;--i)
using namespace std;

int main() 
{
	int a;
	cin >> a;
	vector<double>data(a);
	double bunbo = 0;
	for (int i = 0; i < a; i++)
	{
		cin >> data[i];
	}
	sort(data.begin(), data.end());
	for (int i = 0; i < a - 1; i++)
	{
		double a = (data[i] + data[i+1])/2;
		data[i] = 0;
		data[i + 1] = a;
		sort(data.begin(), data.end());
	}
	cout << data[a-1]<< endl;
	
}

Measured memory_bytes: 256
b = list(map(int, input().split()))
tmp1 = list(map(int, input().split()))
tmp2 = list(map(int, input().split()))
b.extend(tmp1)
b.extend(tmp2)
answer = [False]*9
N = int(input())
for i in range(N):
    num = int(input())
    if num in b:
        answer[b.index(num)] = True
if (answer[0] and answer[1] and answer[2]) or (answer[3] and answer[4] and answer[5]) or (answer[6] and answer[7] and answer[8]) or (answer[1-1] and answer[4-1] and answer[7-1]) or (answer[2-1] and answer[5-1] and answer[8-1]) or (answer[3-1] and answer[6-1] and answer[9-1]) or (answer[1-1] and answer[5-1] and answer[9-1]) or (answer[3-1] and answer[5-1] and [7-1]):
    print("Yes")
else:
    print("No")


Measured memory_bytes: 3064
#include<stdio.h>

int main(void) {
int N;
scanf("%d", &N);

long long int arr[N+1];
arr[0] = 2;
arr[1] = 1;

for (int i = 2; i < N+1; i++) {
arr[i] = arr[i-1] + arr[i-2];
}
if (N== 0)printf("%lld", arr[0]);
else if (N==1)printf("%lld", arr[1]);
else printf("%lld", arr[N]);

return 0;

}

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

int main()
{

    double n, m, a, b, c;

    while( cin >> n )
    {
        if( n == 0 )
            break;

        cin >> m;

        double max = 0, j = 0;
        for( int i = 0; i < n; i++ )
        {
            cin >> a >> b >> c;
            if( c == 1 && max < 1 + m * b / 100 )
            {
                max = 1 + m * b / 100;
                j = a;
            }
            if( c == 2 && max < pow( ( 1 + b / 100 ), m ) )
            {
                max = pow( ( 1 + b / 100 ), m );
                j = a;
            }
        }
        cout << j << endl;
    }

    return 0;
}



Measured memory_bytes: 3500
#include<bits/stdc++.h>
using namespace std;
const int N=3100;
#define ll long long
ll a[N];
ll dp[N][N][3];


ll solve(int l,int r,int flag){
	if(l>r)
		return 0LL;
	ll &ans=dp[l][r][flag];
	if(ans!=-1LL)
		return ans;
	if(flag){
		ans=max(a[l]+solve(l+1,r,!flag),a[r]+solve(l,r-1,!flag));
	}else{
		ans=min(-a[l]+solve(l+1,r,!flag),-a[r]+solve(l,r-1,!flag));
	}
	return ans;
}

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

	memset(dp,-1LL,sizeof(dp));
	int n;
	cin>>n;
	for (int i = 0; i < n; ++i)
	{
		cin>>a[i];
	}
	cout<<solve(0,n-1,1)<<"\n";
}

Measured memory_bytes: 225792
n, m = map(int, input().split())
hen = []
for _ in range(m):
    hen.append(list(map(int, input().split())))

def dfs(vis, graph, x, n):
    vis[x] = True
    for i in range(n):
        if graph[x][i] == False:
            continue
        if vis[i] == True:
            continue
        dfs(vis, graph, i, n)
    return vis


ans = 0
for i in range(m):
    graph = [[False for _ in range(n)] for _ in range(n)]
    rng = [a for a in range(m)]
    del rng[i]
    for y in rng:
        graph[hen[y][0]-1][hen[y][1]-1] = True
        graph[hen[y][1]-1][hen[y][0]-1] = True
    vis = [False for _ in range(n)]
    vis = dfs(vis, graph, 0, n)
    connected = True
    for k in range(n):
        if vis[k] == False:
            connected = False
    if connected == False:
        ans += 1

print(ans)

Measured memory_bytes: 3192
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <vector>
#include <cstring>
#include <queue>
#include <set>
#include <map>
#include <functional>
#include <cmath>
#include <string>
#define SIZE 25
#define BT (1<<21)
#define MOD 1000000007

using namespace std;
typedef long long int ll;
typedef pair <int,int> P;

ll dp[BT];
ll nxt[BT];
int id[SIZE][SIZE];
int n,m,K;

void solve()
{
	for(int S=0;S<1<<n;S++) nxt[S]=dp[S];
	for(int i=0;i<n;i++)
	{
		for(int S=0;S<1<<n;S++)
		{
			if(!(S>>i&1))
			{
				int to=i+1;
				while(to<n&&!(S>>to&1)) to++;
				if(to<n)
				{
					nxt[S+(1<<i)-(1<<to)]+=nxt[S];
				}
				else
				{
					nxt[S+(1<<i)]+=nxt[S];
				}
			}
		}
		for(int S=0;S<1<<n;S++) nxt[S]%=MOD;
	}
}
int main()
{
	scanf("%d %d %d",&n,&m,&K);n--;
	memset(id,-1,sizeof(id));
	for(int i=0;i<K;i++)
	{
		int a,b,c;
		scanf("%d %d %d",&a,&b,&c);a--,b--;
		id[a][b]=c;
	}
	memset(dp,0,sizeof(dp));
	dp[0]=1;
	for(int i=0;i<m;i++)
	{
		solve();
		for(int S=0;S<1<<n;S++)
		{
			bool up=true;
			for(int j=0;j<n;j++)
			{
				if(id[i][j]==0&&(S>>j&1)) up=false;
				else if(id[i][j]==1&&!(S>>j&1)) up=false;
			}
			if(!up) dp[S]=0;
			else dp[S]=nxt[S];
		}
	}
	ll ret=0;
	for(int S=0;S<1<<n;S++)
	{
		ret+=dp[S];
		if(ret>=MOD) ret-=MOD;
	}
	printf("%lld\n",ret);
	return 0;
}


Measured memory_bytes: 22784
a, b, c, x, y = map(int, input().split())
s = 0
if a+b > 2*c:
    if x >= y:
        s = 2*y*c + (x-y)*min([a, 2*c])
    else:
        s = 2*x*c + (y-x)*min([b, 2*c])
else:
    if x >= y:
        s = y*(a+b) + (x-y)*min([a, 2*c])
    else:
        s = x*(a+b) + (y-x)*min([b, 2*c])

print(s)


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

using namespace std;

static const int INF = 1e9 + 7;

template<typename T>
using Vec = vector<T>;

template<typename T, typename T2>
using P = pair<T, T2>;

template<typename... Args>
using Tup = tuple<Args...>;

template<typename T>
using qp = priority_queue<T, Vec<T>, greater<T> >;

template<typename T>
using pq = priority_queue<T>;

using llong = long long;
using ullong = unsigned long long;
using uint = unsigned int;

template<typename T>
T gcd(T x, T y)
{
	return y ? gcd(y, x % y) : x;
}

void hawawa()
{
	int w, a, b;
	cin >> w >> a >> b;
	if ((a <= b && b <= a + w) || (b <= a && a <= b + w) ) {
		cout << 0 << "\n";
	}
	else {
		cout << min(abs(a - b + w), abs(b - a + w)) << "\n";
	}
}

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


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

using namespace std;

#define ll long long
#define rep(i, n) for(int i=0; i < (n); ++i)
#define repr(i, n) for(int i=n; i>= 0; --i)
#define FOR(i, m, n) for(int i=m; i<(n); ++i)



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

    cin >> A >> B >> C;

    if(A[A.length()-1] == B[0] && B[B.length()-1] == C[0])
        cout << "YES" << endl;
    else
        cout << "NO" << endl;
    return 0;
}

Measured memory_bytes: 256
#include <limits.h>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

#include <algorithm>
#include <cassert>
#include <cfloat>
#include <complex>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <regex>
#include <set>
#include <stack>
#include <string>
#include <unordered_map>
#include <vector>

using namespace std;

#define chmax(x, y) x = max(x, y)
#define chmin(x, y) x = min(x, y)
#define rep(i, n) for (ll i = 0; i < (n); ++i)
#define repLRE(i, l, r) for (ll i = (l); i <= (r); ++i)
#define rrepLRE(i, l, r) for (ll i = (l); i >= (r); --i)
#define Sort(v) sort(v.begin(), v.end())
#define rSort(v) sort(v.rbegin(), v.rend())
#define Reverse(v) reverse(v.begin(), v.end())
#define Lower_bound(v, x) \
  distance(v.begin(), lower_bound(v.begin(), v.end(), x))
#define Upper_bound(v, x) \
  distance(v.begin(), upper_bound(v.begin(), v.end(), x))

using ll = long long;
using ull = unsigned long long;
using P = pair<ll, ll>;
using T = tuple<ll, ll, ll>;
using vll = vector<ll>;
using vP = vector<P>;
using vT = vector<T>;
using vvll = vector<vector<ll>>;
using vvP = vector<vector<P>>;
using dqll = deque<ll>;

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

/* Macros reg. ends here */

const ll INF = 1LL << 50;
static const long long mod = 1000000007;

ll dfs(ll n, string s) {
  if (s.size() == 10) {
    bool cond = stoll(s) <= n && (s.find('7') != string::npos) && (s.find('5') != string::npos) && (s.find('3') != string::npos);
    if (cond)
      return 1;
    else
      return 0;
  }
  ll ret = 0;
  if(s == "" || s.back() == '0') ret += dfs(n, s + '0');;
  ret += dfs(n, s + '7');
  ret += dfs(n, s + '5');
  ret += dfs(n, s + '3');
  return ret;
}

int main() {
  // ios_base::sync_with_stdio(0), cin.tie(0), cout.tie(0);
  cout << fixed << setprecision(15);

  ll n;
  cin >> n;

  ll tsuyoshi = dfs(n, "");
  cout << tsuyoshi << endl;

  return 0;
}


Measured memory_bytes: 3588
#include<iostream>
#include<algorithm>
using namespace std;
int N_MAX = 16;
typedef pair<int,int> P;
int main()
{
  int n,m,t,x,y,i,j,k,res=0;
  int a[N_MAX],h[N_MAX];
  P xy[N_MAX][N_MAX];
  cin >> n;
  for(i=1;i<=n;i++){
    cin >> a[i];
    for(j=0;j<a[i];j++)
      cin >> xy[i][j].first >> xy[i][j].second;
  }
  m=1<<n;
  for(k=0;k<m;k++){
    t=k;
    for(i=1;i<=n;i++){
      h[i]=t%2;
      t>>=1;
    }
    t=1;
    for(i=1;i<=n;i++){
      if(h[i]==0) continue;
      for(j=0;j<a[i];j++){
        x=xy[i][j].first;
        y=xy[i][j].second;
        if(y==0&&h[x]==1||y==1&&h[x]==0){
          t=0;
          break;
        }
      }
      if(t==0) break;
    }
    if(t==0) continue;
    t=0;
    for(i=1;i<=n;i++)
      t+=h[i];
    res=max(res,t);
  }
  cout << res << endl;
  return 0;
}

Measured memory_bytes: 256