akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;

#define int long long
typedef vector<int>vint;
typedef pair<int,int>pint;
typedef vector<pint>vpint;
#define rep(i,n) for(int i=0;i<(n);i++)
#define reps(i,f,n) for(int i=(f);i<(n);i++)
#define all(v) (v).begin(),(v).end()
#define each(it,v) for(__typeof((v).begin()) it=(v).begin();it!=(v).end();it++)
#define pb push_back
#define fi first
#define se second
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,R;
int D[30];

vpint G[30];
const int INF=1001001001;
int dist[30][30][2][2001];

typedef tuple<int,int,int,int,int>t5;

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

    fill_n(***dist,30*30*2*2001,INF);
    dist[0][0][0][0]=0;
    priority_queue<t5,vector<t5>,greater<t5>>que;
    que.push(make_tuple(0,0,0,0,0));

    while(que.size()){
        int t,v,p,f,c;
        tie(t,v,p,f,c)=que.top();
        que.pop();
        if(dist[v][p][f][c]<t)continue;
        if(t+15<=R&&dist[v][v][1][c+D[v]]>t+15){
            dist[v][v][1][c+D[v]]=t+15;
            que.push(make_tuple(t+15,v,v,1,c+D[v]));
        }

        for(auto &e:G[v]){
            int np;
            if(f)np=v;
            else np=e.fi;
            if(e.fi!=p||e.se*2>=15){
                if(t+e.se>R||dist[e.fi][np][1][c+D[e.fi]]<=t+e.se)continue;
                dist[e.fi][np][1][c+D[e.fi]]=t+e.se;
                que.push(make_tuple(t+e.se,e.fi,np,1,c+D[e.fi]));
            }
            else{
                if(t+e.se>R)continue;
                if(dist[e.fi][np][0][c]>t+e.se){
                    dist[e.fi][np][0][c]=t+e.se;
                    que.push(make_tuple(t+e.se,e.fi,np,0,c));
                }
                int nt=t+e.se+(15-e.se*2);
                if(nt>R)continue;
                if(dist[e.fi][e.fi][1][c+D[e.fi]]>nt){
                    dist[e.fi][e.fi][1][c+D[e.fi]]=nt;
                    que.push(make_tuple(nt,e.fi,e.fi,1,c+D[e.fi]));
                }
            }
        }
    }

    int ans=0;
    rep(i,N)rep(j,2001)rep(k,2)if(dist[N-1][i][k][j]<=R)chmax(ans,j);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 33604
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

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

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

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

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func main() {
	sc.Split(bufio.ScanWords)
	N := getInt()
	a := make([]int, N)
	for i := 0; i < N; i++ {
		a[i] = getInt()
	}

	l := make([]int, N)
	r := make([]int, N)
	for i := 0; i < N; i++ {
		if i-a[i] > 0 {
			l[i-a[i]]++
		}
		if i+a[i] < N {
			r[i+a[i]]++
		}
	}

	ans := 0
	for i := 0; i < N; i++ {
		ans += r[i] * l[i]
	}

	// out(r)
	// out(l)
	out(ans)
	// ans := 0
	// for i := 0; i < N; i++ {
	// 	for j := i + a[i]; j < N; j++ {
	// 		if a[i]+a[j] == j-i {
	// 			ans++
	// 		}
	// 	}
	// }
	// out(ans)
}


Measured memory_bytes: 8024
#include<cstdio>
using namespace std;

int main(){
  int box[1010]={},x,a;
  box[0]=0;
  box[1]=1;
  for(int i=2;i<35;i++){
    a=i*i;
    while(a<=1000){
      box[a]=a;
      a*=i;
    }
  }
  for(int i=2;i<=1000;i++){
    if(box[i]<box[i-1])
       box[i]=box[i-1];
  }
  scanf("%d",&x);
  printf("%d\n",box[x]);
}


Measured memory_bytes: 128
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<cmath>
#include<cstring>

using namespace std;
string st;
int main()
{
	cin>>st;
	for(int i=0;i<st.size();i+=2)
	cout<<st[i];
	cout<<"\n";
	
	return 0;
}

Measured memory_bytes: 512
n = int(input())

count = 0
if int(n / 100) == 1:
    count += 1
    n = n % 100
else:
    pass

if int(n / 10) == 1:
    count += 1
    n = n % 10
else:
    pass

if n == 1:
    count += 1
else:
    pass

print(count)


Measured memory_bytes: 2940
n = int(input())
a = list(map(int, input().split()))

pre = a[0]
ok = True
for i in range(n):
    if pre > a[i]:
        ok = False
        break
    if a[i] > pre:
        a[i] -= 1

    pre = a[i]

print('Yes' if ok else 'No')


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

ll ans;
string s[22];
int main() {
	ll h,w;
	cin>>h>>w;
	ll dx[4]={0,0,1,-1};
	ll dy[4]={1,-1,0,0};
	for(ll i=0;i<h;i++){
		string t;
		cin>>t;
		s[i]=t;
	}
	for(ll i=0;i<h;i++){
		for(ll j=0;j<w;j++){
			if(s[i][j]=='#'){
				continue;
			}
			for(ll n=0;n<h;n++){
				for(ll m=0;m<w;m++){
					if(s[n][m]=='#'){
						continue;
					}
					if(i==n&&j==m){
						continue;
					}
					ll ch[22][22];
					for(ll k=0;k<h;k++){
						for(ll l=0;l<w;l++){
							ch[k][l]=-1;
						}
					}
					ch[i][j]=0;
					queue<ll>H,W;
					H.push(i);
					W.push(j);
					while(H.size()!=0){
						ll nowh=H.front();H.pop();
						ll noww=W.front();W.pop();
						for(ll k=0;k<4;k++){
							ll nexh=nowh+dx[k];
							ll nexw=noww+dy[k];
							if(nexh<0||nexh>=h||nexw<0||nexw>=w){
								continue;
							}
							if(ch[nexh][nexw]!=-1){
								continue;
							}
							if(s[nexh][nexw]=='#'){
								continue;
							}
							ch[nexh][nexw]=1+ch[nowh][noww];
							H.push(nexh);
							W.push(nexw);
							if(nexh==n&&nexw==m){
								ans=max(ans,ch[nexh][nexw]);
							}
						}
					}
				}
			}

		}
	}
	cout <<ans;
	// your code goes here
	return 0;
}

Measured memory_bytes: 256
#!/usr/bin/env python
# -*- coding: utf-8 -*-
#
# FileName: 	B
# CreatedDate:  2020-06-28 21:02:34 +0900
# LastModified: 2020-06-28 22:01:44 +0900
#


import os
import sys
# import numpy as np
# import pandas as pd


def main():
    d = int(input())
    c = list(map(int, input().split()))
    s = []   # 満足度
    box = [-1]*26  # 各コンテストの実施日
    for i in range(d):
        s.append(list(map(int, input().split())))

    total_satisfy = 0
    for i in range(d):
        t = int(input())
        total_satisfy += s[i][t-1]
        box[t-1] = i
        for j in range(26):
            if box[j] == -1:
                total_satisfy -= c[j]*(i+1)
            else:
                total_satisfy -= c[j]*(i-box[j])
#        print(box)

        print(total_satisfy)






if __name__ == "__main__":
    main()


Measured memory_bytes: 9388
a, b, x = map(int, input().split())
lim = a ** 2 * b / 2
import math
theta = 0
if x >= lim:
    theta = math.atan(2 * (2 * lim - x)/a ** 3)
else:
    theta = math.atan(a * b ** 2/(2 * x))
print(math.degrees(theta))


Measured memory_bytes: 2940
import Control.Applicative
import Control.Monad

main :: IO ()
main = solve <$> replicateM 9 f >>= putStrLn
  where
    f = map g <$> getLine
    g '0' = False
    g '1' = True

solve :: [[Bool]] -> String
solve mp = f (0, 0) [R]
  where
    f (i, j) (R:rs)
      | i > 0 && mp !! (i-1) !! (j+1) = f (i-1, j+1) (U:R:rs)
      | j < 3 && mp !! i !! (j+1) = f (i, j+1) (R:R:rs)
      | i < 8 && mp !! (i+1) !! (j+1) = f (i+1, j+1) (D:R:rs)
      | otherwise = f (i, j) (L:R:rs)
    f (i, j) (D:rs)
      | j < 4 && mp !! (i+1) !! j = f (i+1, j) (R:D:rs)
      | i < 7 && mp !! (i+2) !! j = f (i+2, j) (D:D:rs)
      | j > 0 = f (i+1, j-1) (L:D:rs)
      | otherwise = f (i, j) (U:D:rs)
    f (0, 0) (L:rs) = concatMap show . reverse $ L:rs
    f (i, j) (L:rs)
      | i < 8 && mp !! (i+1) !! j = f (i+1, j) (D:L:rs)
      | j > 0 && mp !! i !! (j-1) = f (i, j-1) (L:L:rs)
      | i > 0 && mp !! (i-1) !! j = f (i-1, j) (U:L:rs)
      | otherwise = f (i, j) (R:L:rs)
    f (1, 0) (U:rs) = concatMap show . reverse $ U:rs
    f (i, j) (U:rs)
      | j > 0 && mp !! (i-1) !! (j-1) = f (i-1, j-1) (L:U:rs)
      | i > 1 && mp !! (i-2) !! j = f (i-2, j) (U:U:rs)
      | j < 4 && mp !! (i-1) !! j = f (i-1, j) (R:U:rs)
      | otherwise = f (i, j) (D:U:rs)

data Dir = R | D | L | U deriving (Show, Eq)



Measured memory_bytes: 3508
#include <bits/stdc++.h>
#include <fstream>
#include <vector>
#include <bitset>
#include <unordered_map>
#include <algorithm>
#include <queue>
#include <math.h>
#include <iomanip>

using namespace std;

/********** TEMPLATE STARTS HERE ***********/

#define IOS ios::sync_with_stdio(false), cin.tie(0);
#define all(v) v.begin(), v.end()
#define F first
#define S second
#define pb push_back
#define PI 3.1415926535897932384626433832795
#define gcd __gcd 

typedef unsigned long long ll;
typedef pair <int, int> pii;
typedef pair <ll, ll> pll;
typedef vector <int> vi;
typedef vector <long long> vl;
typedef vector <pll> vll;
typedef vector <pii> vii;

const int INF = 0x3f3f3f3f;
const ll LINF = 0x3f3f3f3f3f3f3f3f;

template <typename T, typename U> inline void amin(T &x, U y) { if(y < x) x = y; }
template <typename T, typename U> inline void amax(T &x, U y) { if(x < y) x = y; }

/*********** TEMPLATE ENDS HERE *************/

const int DIM = 5;

int v[DIM][DIM];

main()
{
	for(int i = 1; i <= 3; i++)
		for(int j = 1; j <= 3; j++)
			cin >> v[i][j];
	
	int d1 = v[2][1] - v[1][1];
	
	if(v[2][2] - v[1][2] != d1 || v[2][3] - v[1][3] != d1)
	{
		cout << "No";
		return 0;
	}
	
	d1 = v[3][1] - v[1][1];
	
	if(v[3][2] - v[1][2] != d1 || v[3][3] - v[1][3] != d1)
	{
		cout << "No";
		return 0;
	}
	
	cout << "Yes";
}

Measured memory_bytes: 256
import java.util.*

fun main(args: Array<String>) {
  val sc = Scanner(System.`in`)
  val n = sc.nextInt()
  val m = sc.nextInt()
  val k = sc.nextLong()
  val a = (1..n).map { sc.nextLong() }
  val b = (1..m).map { sc.nextLong() }


  val sumA = Array(n+1) { 0L }
  val sumB = Array(m+1) { 0L }


  for (i in 0 until n) {
    sumA[i+1] = sumA[i] + a[i]
  }
  for (i in 0 until m) {
    sumB[i+1] = sumB[i] + b[i]
  }

  var maxM = 0
  for (i in 0..m) {
    if (sumB[i] > k) {
      break
    }
    maxM = i
  }

  var ans = 0
  for (i in 0..n) {
    if (sumA[i] > k) {
      break
    }
    while (sumB[maxM] > k - sumA[i]) {
      maxM--
    }
    ans = Math.max(ans, i + maxM)
  }

  println(ans)
}


Measured memory_bytes: 81432
#include <bits/stdc++.h>
typedef long long int lld;
typedef unsigned long long int llu;
#define INF (lld)(9223372036854775807)
#define IINF (int)(2147483647)

using namespace std;
int main(void) {
  lld n;
  cin >> n;
  cout << ((n + 1) / 2) << "\n";
}

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

#ifndef DEBUG
#define endl '\n'
#define debug(...)
#else
#define debug(...) __VA_ARGS__
#endif
#define debugf(...) debug(printf(__VA_ARGS__);)

using ll = long long;
const int N = 128;

ll P(ll x) {
    return x * x * x * x * x;
}

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


    ll x; cin >> x;

    for (ll a = -N; a <= N; a++) {
        for (ll b = -N; b <= N; b++) {
            if (P(a) - P(b) == x) {
                cout << a << ' ' << b << endl;
                return 0;
            }
        }
    }

    assert(false);

    return 0;
%>

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

public class Main{
	public static void main(String[] args) throws IOException {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
		String str;
		int n;

		boolean prime[] = new boolean[110001];
		prime[0]=true;

		for(int i=2; i<prime.length; i++){
			if(!prime[i]){
				for(int j=i*2; j<prime.length; j=j+i){
					prime[j]=true;
				}
			}
		}

		while(!(str=br.readLine()).equals("0")){
			n = Integer.parseInt(str);
			solve(prime, n);
		}

	}

	static void solve(boolean p[], int n){
		int sum=0;
		int j=0;

		for(int i=2; i<p.length; i++){
			if(!p[i]){
				j++;
				sum += i;
				if(j==n)break;
			}
		}
		System.out.println(sum);
	}

}

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

long long N, Q;
vector<long long> tree[200005];
set<long long>visit;
long long ans[200005];

void dfs(long long node, long long point) {
	point += ans[node];
	ans[node] = point;
	visit.insert(node);

	for(long long i = 0; i < tree[node].size(); i++){
		long long next = tree[node][i];
		if(visit.find(next) == visit.end()){
			dfs(next, point);
		}
	}
}

int main(){
	cin >> N >> Q;
	for(long long i = 0; i < N - 1; i++){
		long long a,b;
		cin >> a >> b;a--;b--;
		tree[a].push_back(b);
		tree[b].push_back(a);
	}

	for(long long i = 0; i < Q; i++){
		long long p,x;
		cin >> p >> x;p--;
		ans[p] += x;
	}
	dfs(0, 0);

	for(long long i = 0; i < N; i++){
		cout << ans[i];
		if(i != N-1){
			cout << " ";
		}else{
			cout << endl;
		}
	}
}


Measured memory_bytes: 33664
#include <iostream>
#include <sstream>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <cctype>
#include <cstring>
#include <iomanip>
#include <bitset>
#include <algorithm>
#include <vector>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <list>
#include <map>

using namespace std;

const int N = 16;

int n;
int mat[N][N];
long long dp[1 << N];

int main() {
  cin >> n;
  for (int i = 0; i < n; i++) {
    for (int j = 0; j < n; j++) {
      cin >> mat[i][j];
    }
  }
  for (int mask = 1; mask < (1 << n); mask++) {
    long long here = 0;
    for (int i = 0; i < n; i++) {
      if (!(mask & (1 << i))) continue;
      for (int j = i + 1; j < n; j++) {
        if (!(mask & (1 << j))) continue;
        here += mat[i][j];
      }
    }
    dp[mask] = here;
  }
  for (int mask = 1; mask < (1 << n); mask++) {
    for (int ss = mask; ss > 0; ss = (ss - 1) & mask) {
      dp[mask] = max(dp[mask], dp[ss] + dp[mask ^ ss]);
    }
  }
  cout << dp[(1 << n) - 1] << endl;
  return 0;
}


Measured memory_bytes: 768
import fractions
a, b, c, d=map(int,input().split())

x=b-a+1
A=a-1
bclcm=(d*c)//fractions.gcd(c,d)
y=(b//c)+(b//d)-(b//(bclcm))
z=(A//c)+(A//d)-(A//(bclcm))

ans=x-y+z

print(int(ans))


Measured memory_bytes: 5052
//
// Created by 13783 on 2020/4/1.
//
#include<iostream>
using namespace std;
const int N=1E5+2;
int a[N][3];
int dp[N][3];
int n;
void solve(){
    dp[1][0]=a[1][0];
    dp[1][1]=a[1][1];
    dp[1][2]=a[1][2];
    for(int i=1;i<=n;i++){
        for(int j=0;j<3;j++){
            dp[i][j]=max(dp[i-1][(j+1)%3],dp[i-1][(j+2)%3])+a[i][j];
        }
    }
    cout<<max(dp[n][0],max(dp[n][1],dp[n][2]));
}
int main(){
    cin>>n;
    for(int i=1;i<=n;i++){
        for(int j=0;j<3;j++){
            cin>>a[i][j];
        }
    }
    solve();
    return 0;
}

Measured memory_bytes: 2560
a = input()
t, a = map(int, input().split())
basho = list(map(int, input().split()))
dstlist = [t - 0.006 * b for b in basho]
minsa = abs(t - 0.006 * basho[0])
count = 0
for i, d in enumerate(dstlist):
    if minsa > abs(a-d):
        minsa = abs(a-d)
        count = i
print(count+1)

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

const int nIMPOS = -1;
struct StDir
{
  int m_nDir;
  int m_nDone;

  StDir(int nDir) : m_nDir(nDir), m_nDone(0)
  { }
};

void fnInput(vector<vector<StDir>>& rvvoAdjcy, vector<int>& rvnDst)
{
  int nxSiz;
  cin >> nxSiz;

  StDir oDir(0);
  rvvoAdjcy.resize(nxSiz + 1, vector<StDir>(nxSiz + 1, oDir));
  for (int i = 0; i < nxSiz; ++i)
  {
    int nx, nySiz;
    cin >> nx >> nySiz;
    for (int j = 0; j < nySiz; ++j)
    {
      int ny;
      cin >> ny;
      rvvoAdjcy[nx][ny].m_nDir = 1;
    }
  }
  rvnDst.resize(nxSiz + 1, nIMPOS);
}

void fnBreadthFirstSearch(vector<vector<StDir>>& rvvoAdjcy, 
                          queue<int>& rqnBFSrch, vector<int>& rvnDst)
{
  while (rqnBFSrch.size())
  {
    int nx = rqnBFSrch.front(); rqnBFSrch.pop();
    if (rvnDst[nx] == nIMPOS)  continue;

    for (int ny = 1; ny < rvvoAdjcy[nx].size(); ++ny)
      if (rvvoAdjcy[nx][ny].m_nDir == 1   &&
          rvvoAdjcy[nx][ny].m_nDone == 0)
      {
        rvvoAdjcy[nx][ny].m_nDone = 1;
        int nDst = rvnDst[nx] + 1;
        if (rvnDst[ny] == nIMPOS)
          rvnDst[ny] = nDst;
        else
          rvnDst[ny] = min(rvnDst[ny], nDst);

        rqnBFSrch.push(ny);
      }
  }
}

void fnResult(const vector<int>& cnrvnDst)
{
  for (int i = 1; i < cnrvnDst.size(); ++i)
    cout << i <<  " " << cnrvnDst[i] << endl;
}

int main()
{
  cin.tie(0);
  ios::sync_with_stdio(false);
  vector<vector<StDir>> vvoAdjcy;
  queue<int>  qnBFSrch;
  vector<int> vnDst;

  fnInput(vvoAdjcy, vnDst);

  vnDst[1] = 0;
  qnBFSrch.push(1);
  fnBreadthFirstSearch(vvoAdjcy, qnBFSrch, vnDst);
  fnResult(vnDst);

  return 0;
}

Measured memory_bytes: 3200
#include <iostream>
#include <math.h>
using namespace std;
int main()
{
	int n;
	cin >> n;
	int t[n][3], inc[n][3], excl[n][3];
	
	for(int i=0;i<n;++i)
	{
		cin >> t[i][0] >> t[i][1] >> t[i][2];
	}
	
	for(int i=0;i<n;++i)
	{
		if (!i)
		{
			inc[i][0] = t[i][0];
			inc[i][1] = t[i][1];
			inc[i][2] = t[i][2];
			
			excl[i][0] = max(t[i][1], t[i][2]);
			excl[i][1] = max(t[i][0], t[i][2]);
			excl[i][2] = max(t[i][0], t[i][1]);
		}
		else
		{
			inc[i][0] = t[i][0] + excl[i-1][0];
			inc[i][1] = t[i][1] + excl[i-1][1];
			inc[i][2] = t[i][2] + excl[i-1][2];
			
			excl[i][0] = max(inc[i][1], inc[i][2]);
			excl[i][1] = max(inc[i][0], inc[i][2]);
			excl[i][2] = max(inc[i][0], inc[i][1]);
		}
	}
	
	cout<<max(inc[n-1][0], max(inc[n-1][1], inc[n-1][2]))<<endl;
	return 0;
}

Measured memory_bytes: 3712
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);

        int r =sc.nextInt();
        int D = sc.nextInt();
        int x = sc.nextInt();
        
        int nextX = x;

        for(int i = 0; i < 10; i++){
            nextX = r * nextX - D;
            System.out.println(nextX);
        }
    }
}

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

const int64_t MOD = 1000000007;
typedef int64_t ll;
typedef uint64_t ull;

#define INF LLONG_MAX

#define FOR(i, start, end) for(uint64_t i=start; i<end; i++)
#define REP(i, n) FOR(i, 0, n)

// 最大公約数gcd
// 最小公倍数lcm=m*n/gcd
uint64_t gcd(uint64_t m, uint64_t n) {
  uint64_t temp;
  while (m % n != 0){
    temp = n;
    n = m % n;
    m = temp;
  }
  return n;
}

uint64_t lcm(uint64_t m, uint64_t n) {
  return (m*n)/gcd(m,n);
}

// vector<vector<uint64_t> > v(n+1, vector<uint64_t>(n+1, 0))
// v[n][k]に組み合わせ数が入る。
void comb(vector<vector <uint64_t> > &v){
  for(uint64_t i = 0;i <v.size(); i++){
    v[i][0]=1;
    v[i][i]=1;
  }
  for(uint64_t k = 1;k <v.size();k++){
    for(uint64_t j = 1;j<k;j++){
      v[k][j]=(v[k-1][j-1]+v[k-1][j]);
    }
  }
}

// 掛け算オーバーフロー判定
bool is_product_overflow(uint64_t a, uint64_t b) {

	uint64_t prod = a * b;
	
	return (prod / b != a);
}

//素因数分解
void primeFactorization(uint64_t a, list<uint64_t> &factors){ //素因数分解を出力するプログラム
  long i,sq;
  if(a%2==0){ //偶数の場合
    factors.push_back(2);
    primeFactorization(a/2,factors); //2で割った値で再帰
    return;
  }
  sq = sqrt(a);
  for(i=3;i<=sq;i+=2){ //3以上√a以下の奇数の場合
	if(a%i==0){
	  factors.push_back(i);
      primeFactorization(a/i,factors); //割れた値で再帰
      return;
	}
  }
  //偶数でも3以上√a以下の奇数の場合でも割り切れない場合
  if(a!=1){ //aが1でないなら、a自身は素数
    factors.push_back(a);
  }
}

// フェルマーの小定理
// mod. m での a の逆元 a^{-1} を計算する
// (a/b)%m = a*movinv(b,m)%m  
int64_t modinv(int64_t a, int64_t m) {
    int64_t b = m, u = 1, v = 0;
    while (b) {
        int64_t t = a / b;
        a -= t * b; swap(a, b);
        u -= t * v; swap(u, v);
    }
    u %= m;
    if (u < 0) u += m;
    return u;
}

// 円周率
// M_PI

// #include <iomanip> // setprecisionを使用するのに必要
// cout << std::fixed << std::setprecision(15) << y << endl;

// 昇順
// priority_queue<int, vector<int>, greater<int> > queue;

signed main() {
  
  vector<int> v(3);
  cin >> v[0] >> v[1] >> v[2];
  
  sort(v.begin(),v.end());
  
  int diff1 = v[2]-v[1];
  int diff2 = v[1]-v[0];
  
  if(diff2%2==1){
    diff1++;
  }
  cout << diff1 + (diff2+1)/2 << endl;
  return 0;
}



Measured memory_bytes: 3612
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
#include<queue>
#include<map>
#include<set>
#include<cstdio>
#include<cstdlib>
#include<cstring>
#include<cmath>
using namespace std;

int n, m;
vector<int> node[10];  

int slv(int now, int f);

int main(){
  ios_base::sync_with_stdio(false);

  cin >> n >> m;
  for(int i=0;i<m;i++){
    int a, b;
    cin >> a >> b;
    node[a].push_back(b);
    node[b].push_back(a);
  }

  cout << slv(1, 2) << endl;

  return 0;
}

int slv(int now, int f){

  if(f == (((1 << n) - 1) << 1)){
    return 1;
  }

  int t = 0;
  for(int i=0;i<node[now].size();i++){

    int next = node[now][i];

    if((f & (1 << next)) != 0){
      continue;
    }

    t += slv(next, (f | (1 << next)));
  } 

  return t;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for(int i=0; i<(n); i++)
using ll = long long;
using P = pair<int,int>;
vector<int> ki[220000],ans;
void dfs(int now,int last = -1){
    for(int next:ki[now]){
        if(next == last)continue;
        ans[next] += ans[now];
        dfs(next,now);
    }
}
int main()
{
    int n,q;
    cin >> n >> q;
    ans.resize(n);
    rep(i,n-1){
        int a,b;
        cin >> a >> b;
        --a;--b;
        ki[a].push_back(b);
        ki[b].push_back(a);
    }
    rep(i,q){
        int p,x;
        cin >> p >> x;
        --p;
        ans[p]+=x;

    }
    dfs(0);
    rep(i,n)cout << ans[i] << endl;
    return 0;
}


Measured memory_bytes: 23936
#include <bits/stdc++.h>
using namespace std;
int p[7] = {2, 3, 5, 7, 11, 13, 17};
int q[7] = {9, 6, 4, 3, 3, 3, 3};
int r[7];
int n, z, pc = 7;
int a[320];
int b[320];
int w[320];
void dfs(int x) {
	if (x == pc) {
		memset(w, 0, sizeof w);
		for (int i = 0; i < n; i++) {
			bool flag = false;
			int u = a[i];
			int v = b[i];
			for (int j = 0; j < pc; j++) {
				for (int k = 0; k < r[j]; k++) {
					if (u % p[j] == 0) {
						u /= p[j];
					} else {
						break;
					}
				}
				if (u % p[j] == 0) {
					flag = true;
					break;
				}
			}
			if (flag) {
				continue;
			}
			w[u] += v;
		}
		int t = w[1];
		for (int i = 2; i <= 300; i++) {
			if (w[i] > 0) {
				t += w[i];
			}
		}
		z = max(z, t);
	} else {
		for (r[x] = 0; r[x] < q[x]; r[x]++) {
			dfs(x + 1);
		}
	}
}
int main() {
	scanf("%d", &n);
	for (int i = 0; i < n; i++) {
		scanf("%d%d", &a[i], &b[i]);
	}
	dfs(0);
	printf("%d\n", z);
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;

int main(){
  int d,e;
  while(cin >> d >> e,d){
    double min = 10000;
    for(int i=0; i<=d; ++i){
      double tmp = i*i + (d-i)*(d-i);
      tmp = fabs(sqrt(tmp)-e);
      if(min > tmp){
	min = tmp;
      }
    }
    cout << min << endl;
  }
  return 0;
}
      


Measured memory_bytes: 3172
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> l_l;
typedef pair<int, int> i_i;
template<class T>
inline bool chmax(T &a, T b) {
    if(a < b) {
        a = b;
        return true;
    }
    return false;
}

template<class T>
inline bool chmin(T &a, T b) {
    if(a > b) {
        a = b;
        return true;
    }
    return false;
}

#define EPS (1e-7)
#define INF (1e9)
#define PI (acos(-1))
//const ll mod = 1000000007;
string A[55], B[55];

int main() {
    //cout.precision(10);
    cin.tie(0);
    ios::sync_with_stdio(false);
    int M, N;
    cin >> N >> M;
    for(int i = 0; i < N; i++) cin >> A[i];
    for(int i = 0; i < M; i++) cin >> B[i];
    for(int h = 0; h < N; h++) {
        if(h + M - 1 >= N) continue;
        for(int w = 0; w < N; w++) {
            if(w + M - 1 >= N) continue;
            bool ok = true;
            for(int i = 0; i < M; i++) {
                for(int j = 0; j < M; j++) {
                    if(B[i][j] != A[i+h][j+w]) ok = false;
                }
            }
            if(ok) {
                cout << "Yes" << endl;
                return 0;
            }
        }
    }
    cout << "No" << endl;
    return 0;
}


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

using namespace std;
#ifdef _DEBUG
#define _GLIBCXX_DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

#define int long long
#define ll long long
#define DBG 1
#define rep(i, a, b) for (int i = (a); i < (b); i++)
#define rrep(i, a, b) for (int i = (b)-1; i >= (a); i--)
#define loop(n) rep(loop, (0), (n))
#define all(c) begin(c), end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
#define fi first
#define se second
#define pb push_back
#define eb emplace_back
using pii = pair<int, int>;
// template<class T> ostream &operator<<(ostream &os,T &t){dump(t);return os;}
template <typename T, typename S>istream &operator>>(istream &is, pair<T, S> &p) { is >> p.first >> p.second; return is; }
template <typename T, typename S>ostream &operator<<(ostream &os, pair<T, S> &p) { os << p.first << " " << p.second; return os; }

template <typename T> void printvv(const vector<vector<T>> &v) {
	cerr << endl;
	rep(i, 0, v.size()) rep(j, 0, v[i].size()) {
		if (typeid(v[i][j]).name() == typeid(INF).name() and v[i][j] == INF) {
			cerr << "INF";
		}
		else
			cerr << v[i][j];
		cerr << (j == v[i].size() - 1 ? '\n' : ' ');
	}
	cerr << endl;
}

#ifndef _DEBUG
#define printvv(...)
#endif
void YES(bool f) { cout << (f ? "YES" : "NO") << endl; }
void Yes(bool f) { cout << (f ? "Yes" : "No") << endl; }
template <class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; }return false; }
template <class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; }return false; }
int gcd(int x, int y) { return (y == 0 ? x : gcd(y, x%y)); }
int gcd(vector<int>&v) {
	int ret = v[0];
	for (int i = 1; i < v.size(); i++) {
		ret = gcd(ret, v[i]);
	}
	return ret;
}

signed main(signed argc, char *argv[]) {
	cin.tie(0);
	ios::sync_with_stdio(false);
	cout << fixed << setprecision(12);

	int N; cin >> N;
	vector<int>A(N); rep(i, 0, N) { cin >> A[i]; }
	vector<int>B(A);

	rep(i, 1, N) {
		A[i] = gcd(A[i], A[i - 1]);
	}
	rrep(i, 1, N) {
		B[i - 1] = gcd(B[i - 1], B[i]);
	}

	int ans = B[1];
	rep(i, 0, N-2) {
		chmax(ans, gcd(A[i], B[i + 2]));
	}
	chmax(ans, A[N - 2]);
	cout << ans << endl;

	return 0;
}


Measured memory_bytes: 1792
use proconio::{input, fastout};

#[fastout]
fn main() {
    input! {
        k: usize,
        s: usize,
    }

    let mut count = 0;

    for x in 0..=k {
        for y in 0..=k {
            let xy = x + y;
            if s >= xy && s - xy <= k {
                count += 1;
            }
        }
    }

    println!("{}", count);
}

Measured memory_bytes: 2148
import java.util.Scanner

fun main(args: Array<String>) {
    val sc = Scanner(System.`in`)

    val N = sc.nextInt()
    val M = sc.nextInt()
    val S = sc.next()

    val A = IntArray(N+1) { -1 }
    A[N] = 0
    var sel = N
    var nxt = N
    for (i in N-1 downTo 0) {
	if (sel - i > M) {
	    if (sel == nxt) {
		println("-1")
		return
	    }
	    sel = nxt
	}
	if (S[i] == '0') {
	    A[i] = sel - i
	    nxt = i
	}
    }

    val ans = mutableListOf<Int>()
    var i = 0
    while (i < N) {
	ans.add(A[i])
	i += A[i]
    }
    println(ans.joinToString(" "))
}


Measured memory_bytes: 34904
import sys
import numpy as np
read = sys.stdin.read

N, *A = map(int, read().split())
a = np.array(A, np.int64)
mod = 10 ** 9 + 7
answer = 0
for i in range(60):
    bit = np.count_nonzero(a & 1)
    answer += 2 ** i * bit * (N - bit)
    answer %= mod
    a >>= 1

print(answer)

Measured memory_bytes: 49820
#include<bits/stdc++.h>
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rrep(i,a,b) for(int i=a;i>=b;i--)
#define fore(i,a) for(auto &i:a)
#define all(x) (x).begin(),(x).end()
//#pragma GCC optimize ("-O3")
using namespace std; void _main(); int main() { cin.tie(0); ios::sync_with_stdio(false); _main(); }
typedef long long ll; const int inf = INT_MAX / 2; const ll infl = 1LL << 60;
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; }
//---------------------------------------------------------------------------------------------------
/*---------------------------------------------------------------------------------------------------
　　　　　　　　　　　 ∧＿∧
　　　　　 ∧＿∧ 　（´<_｀ ）　 Welcome to My Coding Space!
　　　　 （ ´_ゝ`）　/　 ⌒i     @hamayanhamayan
　　　　／　　　＼　 　  |　|
　　　 /　　 /￣￣￣￣/　　|
　 ＿_(__ﾆつ/　    ＿/ .| .|＿＿＿＿
　 　　　＼/＿＿＿＿/　（u　⊃
---------------------------------------------------------------------------------------------------*/














int N, A, B;
//---------------------------------------------------------------------------------------------------
void _main() {
	cin >> N >> A >> B;
	int ans = min(N * A, B);
	cout << ans << endl;
}












Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <functional>
#include <cstring>
#include <utility>
#include <cstdio>
using namespace std;

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

struct edge {
  double dist;
  int limit;
};

struct state {
  double cost;
  int pre, cur, v;
  state(double d, int a, int b, int c):cost(d),pre(a),cur(b),v(c){}
  bool operator<(const state& a) const {
    return cost > a.cost;
  }
};

const int INF = 100000000, MAX_N = 31, MAX_V = 31;
int n, m;
edge e[1000];
int graph[MAX_N][MAX_N];
bool used[MAX_N][MAX_N][MAX_V];

void solve() {
  memset(graph, -1, sizeof graph);
  memset(used, false, sizeof used);
  
  int s, g; cin>>s>>g;
  rep(i,m) {
    int x, y;
    cin>>x>>y>>e[i].dist>>e[i].limit;
    graph[x][y] = i;
    graph[y][x] = i;
  }
  
  double d[MAX_N][MAX_N][MAX_V];
  rep(i,MAX_N) rep(j,MAX_N) rep(k,MAX_V) d[i][j][k] = INF;
  priority_queue<state> que;
  REP(i,1,n+1) if (graph[s][i] != -1) {
    int en = graph[s][i];
    if (e[en].limit < 1) continue;
    d[s][i][1] = e[en].dist;
    que.push(state(d[s][i][1],s,i,1));
  }
  
  while (!que.empty()) {
    state si = que.top(); que.pop();
    double cost = si.cost;
    int pre = si.pre, cur = si.cur, v = si.v;
    
    if (used[pre][cur][v]) continue;
    used[pre][cur][v] = true;
    
    if (cur == g && v == 1) {
      printf("%.4lf\n", cost); return;
    }
        
    REP(i,1,n+1) if (graph[cur][i] != -1) {
      if (i == pre || i == cur) continue;
      int en = graph[cur][i];
      REP(j,-1,2) {
        if (v+j < 1 || v+j > e[en].limit) continue;
        double ne = cost + e[en].dist / (v+j);
        if (d[cur][i][v+j] > ne) {
          d[cur][i][v+j] = ne;
          que.push(state(ne, cur, i, v+j));
        }
      }
    }
  }
  cout<<"unreachable"<<endl;
}

int main (int argc, char const* argv[]) {
  while (cin>>n>>m, n||m) {
    solve();
  }
  return 0;
}

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

int main() {
  int a, b;
  cin >> a >> b;
  string s, t;
  for(int i=0; i<b; i++) s += to_string(a);
  for(int i=0; i<a; i++) t += to_string(b);
  if (s >= t) cout << t << endl;
  else cout << s << endl; 
}

Measured memory_bytes: 3644
#include <iostream>
#include <stdio.h>
#include <cmath>
#include <algorithm>
#include <climits>
#include <vector>
#include <iomanip>
#include <string>
#include <queue>
#include <numeric>
#include <functional>
#include <array>
#include <map>
#include <set>

#define INF 1000000007 //1000000000000000003
#define MOD 1000000007
#define MAX 2000005

#define ll long long

//printf("%.10f", );
//cout << fixed << setprecision(10) << heikin << endl;
//vector<vector<int>> data(3, vector<int>(4, -1));
//left + 1 < top

using namespace std;
using P = pair<int, int>;
using Pc = pair<double, int>;
using T = tuple<int, int, int>;
using edge = struct { int to; long long dist; };
const double PI = 3.141592653589793;
long long fact[MAX], inv[MAX];
int dx[] = { -1,0,1,0 };
int dy[] = { 0,-1,0,1 };

//////////////////////////////////

vector<vector<int>> bingo(3, vector<int>(3));
vector<vector<int>> tree(100005);
int color[100005];
map<P, int>colorMap;
int m = 0;

struct BridgeInfo {
	int town1;
	int town2;
	int year;
	BridgeInfo(int t1, int t2, int y) {
		town1 = t1;
		town2 = t2;
		year = y;
	}
};

struct People {
	int index;
	int town;
	int year;
	People(int i, int t, int y) {
		index = i;
		town = t;
		year = y;
	}
};

bool compare_by_second(pair<int, int> a, pair<int, int> b) {
	if (a.second != b.second) {
		return a.second < b.second;
	}
	else {
		return a.first < b.first;
	}
}

struct UnionFind {
	vector<int>uf;

	UnionFind(int size) :uf(size, -1) {};

	int root(int target) {
		if (uf[target] < 0)return target;
		else return uf[target] = root(uf[target]);
	}

	void merge(int a, int b) {
		a = root(a);
		b = root(b);
		if (a == b)return;
		if (uf[b] < uf[a])swap(a, b);
		uf[a] += uf[b];
		uf[b] = a;
	}
};

ll CalcPow(ll num, ll power) {
	if (power == 0)return 1;
	if (power % 2 == 0) {
		ll half = CalcPow(num, power / 2);
		return (half * half) % MOD;
	}
	else return (num * CalcPow(num, power - 1)) % MOD;
}

ll combination(ll all, ll select) {
	if (all < select) return 0;
	if (all < 0 || select < 0) return 0;
	return fact[all] * (inv[select] * inv[all - select] % MOD) % MOD;
}

void initCombination(int max) {
	fact[0] = fact[1] = 1;
	for (int i = 2; i <= max; ++i) {
		fact[i] = fact[i - 1] * i % MOD;
	}

	inv[max] = CalcPow(fact[max], MOD - 2);
	for (int i = max - 1; 0 <= i; --i) {
		inv[i] = (inv[i + 1] * (i + 1)) % MOD;
	}
}

ll getGcd(ll a, ll b) {
	if (a < b) {
		ll temp = b;
		b = a;
		a = temp;
	}

	ll r;
	while ((r = a % b) != 0) {
		a = b;
		b = r;
	}
	return b;
}

int main() {

	ll N, M; cin >> N >> M;
	ll A = 0;
	for (int i = 0; i < M;++i) {
		ll a; cin >> a;
		A += a;
	}
	ll ans = N - A;
	ans = ans < 0 ? -1 : ans;
	cout << ans << endl;
}



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

#define FOR(idx, begin, end) for(int idx = (int)(begin); idx < (int)(end); ++idx)
#define DMP(x) cerr << #x << ": " << x << "\n"

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


int main() {

	cin.tie(0);
	
	lint N, A, B, ans = 0;
	cin >> N >> A >> B;

	vector<lint> X(N);
	FOR(i, 0, N) cin >> X[i];

	FOR(i, 0, N - 1) {
		if ((X[i + 1] - X[i]) * A < B) ans += (X[i + 1] - X[i]) * A;
		else ans += B;
	}

	cout << ans;

	return 0;
}

Measured memory_bytes: 1024
#include <iostream>
#include <string>
#include <algorithm>
#include <vector>
#include <cctype>
#include <locale>
#include <cmath>
#include <iomanip>
#include <numeric>

using namespace std;
using ll = long long;

ll choose(ll n){
    return n*(n-1)/2;
}

int main() {
    int N;
    cin >> N;
    vector<int> data(N);
    vector<int> counter(N);
    for(int i = 0; i < N; i++){
        cin >> data[i];
    }
    for(int i = 0; i < N; i++){
        data[i]--;
    }
    for(int i = 0; i < N; i++){
        counter[data[i]]++;
    }
    long long sum = 0;
    for(int i = 0; i < N; i++){
        sum += choose(counter[i]);
    }
    for(int i = 0; i < N; i++){
        // long long ans = sum - (counter[x] - 1);
        ll ans = sum;
        ans -= choose(counter[data[i]]);
        ans += choose(counter[data[i]]-1);
        cout << ans << endl;
    }
    return 0;
}

Measured memory_bytes: 4096
#include <bits/stdc++.h>
using namespace std;
#define ll long long
const int N  =1e5+10;
const int mod =1e9+7;
const int MAX =1e9;
#define db double
int main() {
    int a;
    string s,t;
    cin>>s>>t;
    int cnt=0;
    for (int i = 0; i <s.size() ; ++i) {
        if(s[i]!=t[i])cnt++;
    }
    cout<<cnt;
    return 0;
}



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

const int Nmax=200010;

int main() {
	int H,W;
	cin >> H >> W;
	int c[10][10],dist[10][10]={};
	for(int i=0;i < 10;i++)
		for(int j=0;j < 10;j++){
			cin >> c[i][j];
			dist[i][j] = c[i][j];
		}
			
	for(int i=9;i >= 0;i--)
		for(int j=9;j >= 0;j--)
			for(int k=9;k >= 0;k--)
					dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
	for(int i=0;i < 10;i++)
		for(int j=0;j < 10;j++)
			for(int k=0;k < 10;k++)
					dist[i][j] = min(dist[i][j], dist[i][k]+dist[k][j]);
	ll ans=0;
  	int A;
	for(int i=0;i < H;i++){
		for(int j=0;j < W;j++){
			cin >> A;
			if(A != -1)
			ans += dist[A][1];
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>

using namespace __gnu_pbds;
using namespace std;


#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define PSET(x,y) fixed<<setprecision(y)<<x
#define pb push_back
#define pii pair<int,int>
#define pf push_front
#define mp make_pair
#define vi vector<int>
#define vip vector<pair<int,int> >
#define ff first
#define ss second
#define int long long
#define mod 1000000007
#define BIG 998244353
#define s(t) scanf("%lld",&t)
#define p(t) printf("%lld\n",t)
#define mii map<int,int>
#define MSET(table,i) memset(table, i, sizeof(table))
#define endl '\n'
#define tc int t;cin>>t;while(t--)
#define pi  3.1415926358
#define bits(x) __builtin_popcountll(x)
#define minimum(a,n) min_element(a,a+n)-a
#define maximum(a,n) max_element(a,a+n)-a
#define pqbig priority_queue<int>
#define pqsmall priority_queue<pii,vector<pii>,greater<pii> >
#define all(v) v.begin(),v.end()
#define sitr set<int>:: iterator
#define spitr set<pii>:: iterator
#define mitr map<int,int>:: iterator

int toint(const string &s) {stringstream ss; ss << s; int x; ss >> x; return x;}
string tostring ( int number ) {stringstream ss; ss << number; return ss.str();}


typedef tree<pii, null_type, less<pii>, rb_tree_tag,
        tree_order_statistics_node_update>
        new_data_set;


#define trace1(x)                cerr<<#x<<": "<<x<<endl
#define trace2(x, y)             cerr<<#x<<": "<<x<<" | "<<#y<<": "<<y<<endl
#define trace3(x, y, z)          cerr<<#x<<":" <<x<<" | "<<#y<<": "<<y<<" | "<<#z<<": "<<z<<endl
#define trace4(a, b, c, d)       cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<endl
#define trace5(a, b, c, d, e)    cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<endl
#define trace6(a, b, c, d, e, f) cerr<<#a<<": "<<a<<" | "<<#b<<": "<<b<<" | "<<#c<<": "<<c<<" | "<<#d<<": "<<d<<" | "<<#e<< ": "<<e<<" | "<<#f<<": "<<f<<endl


int32_t main()
{
	fast;
	int n;cin>>n;
	int *arr=new int[n];
	int ans=0;
	for(int i=0;i<n;i++)
		cin>>arr[i];

	for(int i=1;i<n;i++)
	{
		ans+=max(arr[i-1]-arr[i],0ll);
		arr[i]=max(arr[i-1],arr[i]);
	}
	cout<<ans<<endl;
}


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

int main()
{
    string S;
    cin >> S;

    vector<int> x;
    for (int i = 0; i < S.size(); i++)
    {
        switch (S[i])
        {
        case 'A':
            x.push_back(0);
            break;
        case 'B':
            if (i + 1 < S.size() && S[i + 1] == 'C')
            {
                x.push_back(1);
                i++;
            }
            else
            {
                x.push_back(2);
            }
            break;
        default:
            x.push_back(2);
            break;
        }
    }

    long long ans = 0;
    int prev = -1;
    int current = -1;
    long long a_count = 0;
    long long bc_count = 0;

    for (int i = 0; i < x.size(); i++)
    {
        if (x[i] == 0)
        {
            a_count++;
        }
        else
        {
            if (x[i] == 1)
            {
                ans += a_count;
            }
            else
            {
                a_count = 0;
            }
        }
        if (current != x[i])
        {
            prev = current;
            current = x[i];
        }
    }
    cout << ans << endl;
}


Measured memory_bytes: 1532
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define pi 3.141592653589793238
#define fast ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define MOD 1000000007
int main()
{
	fast;
	ll a,b;
	cin>>a>>b;
	ll ans=0;
	if(a>b)
		ans=a,a--;
	else
		ans=b,b--;
	if(a>b)
		ans+=a;
	else
		ans+=b;
	cout<<ans;
	return 0;
}


Measured memory_bytes: 3616
#include <stdio.h>

int main(int argc, const char * argv[]) {
    int y,x,z,tmp;
    for(x=1;;x++){
        scanf("%d %d",&y,&z);
        if(y==0&&z==0){
            break;
        }
        if(y>z){
            tmp=y;
            y=z;
            z=tmp;
        }
        printf("%d %d\n",y,z);
    }
    return 0;
}


Measured memory_bytes: 2032
#include "bits/stdc++.h"
using namespace std;
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i)); }
sim, class b dor(pair < b, c > d) {
ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
*this << "[";
for (auto it = d.b; it != d.e; ++it)
*this << ", " + 2 * (it == d.b) << *it;
ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
#define cool ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define int  long long int
#define pb push_back
#define fe first
#define lb lower_bound 
#define ub upper_bound
#define pii pair<pair<int,int>,pair<int,int> >
#define se second
#define endl "\n"
#define pi pair<int, int>
#define mi          map<int,int>
#define mii         map<pi,int>
#define vi vector<int> 
#define vvi vector<vi>
#define bs   binary_search
#define rep(i,a,b) for(int i=a;i<b;i++)
#define rep1(i,a,b) for(int i=a;i<=b;i++)	
#define all(c) (c).begin(),(c).end()
#define sz(x)       (int)x.size() 
#define PI 3.14159265358979323846

 const int N=1e7+5;

 int mod= 1e9+7;
 int dx[4]={0,0,+1,-1};
 int dy[4]={+1,-1,0,0};  
 
 
int po(int a, int b) {
	a %= mod;
	int res = 1;
	while (b > 0) {
		if (b & 1)
			res = (res * a) % mod;
		a =(a*a) % mod;
		b >>= 1;
	}
	 return res;	
   }



void solve() {
   int n,q,sum=0;
   cin>>n;
    mi mp;
    rep(i,0,n) {
		  int x;
		  cin>>x;
		  mp[x]++;
		  sum+=x;
		}
	cin>>q;
	
	rep(i,0,q) {
		 int l,r;
		 cin>>l>>r;
		 if( mp.find(l)==mp.end()) {
			   cout<<sum<<endl;
			   continue;
			 } 
		else {
			  sum-=l*mp[l];			  
			  sum+=mp[l]*r;
			  
			  mp[r]+=mp[l];
			  mp.erase(l);
			  cout<<sum<<endl;
			}
			
			//~ for(auto to:mp)
			  //~ cout<<to.fe<<" "<<to.se<<endl;
			  //~ cout<<endl;	 
	 }	
    
       					   
 }

    
int32_t main() {
	cool;
	int t=1;	

	//cin>>t;
	while(t--)
	  solve();


return 0;	   
}


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

const int N = 2e5 + 100;
const int A = 26;

char str[N];
int go[N][A], n, pos[A];
int cnt[A];

int f[N], g[N];

int main() {
#ifdef lol
	freopen("d.in", "r", stdin);
	freopen("d.out", "w", stdout);
#endif

	scanf("%s", str + 1);
	n = strlen(str + 1);
	//for (int i = 1; i <= n; ++i)
	//	++cnt[str[i] - 'a'];
	//for (int i = 0; i < A; ++i)
	//	if (!cnt[i]) {
	//		putchar('a' + i);
	//		puts("");
	//		return 0;
	//	}
	for (int i = 0; i < A; ++i)
		pos[i] = n + 1;
	memset(f, 0x3f, sizeof f);
	f[n + 1] = 0;
	for (int i = n; 0 < i; --i) {
		memcpy(go[i], pos, sizeof pos);
		for (int j = 0; j < A; ++j)
			f[i] = min(f[i], f[go[i][j]] + 1);
		pos[str[i] - 'a'] = i;
	}
	memcpy(go[0], pos, sizeof pos);
	for (int i = 0; i < A; ++i)
		f[0] = min(f[0], f[go[0][i]] + 1);

	int p = 0;
	do {
		for (int i = 0; i < A; ++i)
			if (f[go[p][i]] == f[p] - 1) {
				putchar('a' + i);
				p = go[p][i];
				break;
			}
	} while (p != n + 1);
	puts("");

	return 0;
}

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

class UnionFind {
  public:
    //親の番号を格納する．親だった場合は-(その集合のサイズ)
    vector<int> Parent;
    //作るときはParentの値をすべて-1にする
    //こうするとすべてバラバラになる．
    UnionFind(int N) {
      Parent = vector<int>(N,-1);
    }

    //親がどのグループに属しているか
    int root(int A){
      if(Parent[A] < 0) return A;
      //親の紐づけを変更
      return Parent[A] = root(Parent[A]);
    }

    int size(int A){
      return -Parent[root(A)];//親を取ってきたい
    }

    //AとBをくっつける
    bool connect(int A, int B){
      //AとBを直接つなぐのではなく，root(A)とroot(B)をくっつける
      A = root(A);
      B = root(B);
      if( A == B ){
        //すでにくっついているからくっつけない
        return false;
      }
      //大きいほう(A)に小さいほう(B)をくっつけたい
      //大小逆ならひっくり返す
      if( size(A) < size(B) ) swap(A,B);

      //Aのサイズを更新
      Parent[A] += Parent[B];
      //Bの親をAにする
      Parent[B] = A;
      return true;
    }
};

int main(void){
  int N,M;
  cin >> N >> M;
  vector<int> A(M), B(M);
  for(int i = 0; i<M; i++){
    cin >> A[i] >> B[i];
    A[i]--;
    B[i]--;
  }

  vector<long long> ans(M);
  ans[M-1] = (long long)N*(N-1)/2;

  UnionFind Uni(N);

  for(int i = M-1; i >= 1; i--){

    ans[i-1] = ans[i];

    //繋がってなかったのがつながった時
    if(Uni.root(A[i]) != Uni.root(B[i])){
      ans[i-1] -= (long long)Uni.size(A[i]) * Uni.size(B[i]);
      Uni.connect(A[i],B[i]);
    }
  }

  for(int i = 0; i<M; i++){
    cout << ans[i] << endl;
  }

  return 0;
}

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

using Pair = pair<int, int>;

int N;
vector<Pair> ps;
map<Pair, int> mp;

int main() {
  scanf("%d", &N);
  for (int i=0; i<N; i++) {
    int x, y, w;
    scanf("%d%d%d", &x, &y, &w);
    mp[Pair(x,y)] = w;
    ps.emplace_back(Pair(x, y));
  }

  int ans = 0;
  for (Pair p : ps) {
    int x = p.first;
    int y = p.second;
    int t = mp[Pair(x, y)] + mp[Pair(x, y-1)] + mp[Pair(x-1, y)] + mp[Pair(x-1, y-1)];
    int t2 = mp[Pair(x, y)] + mp[Pair(x, y-1)] + mp[Pair(x+1, y)] + mp[Pair(x+1, y-1)];
    ans = max(ans, t);
    ans = max(ans, t2);
  }
  printf("%d / 1\n", ans);
}

Measured memory_bytes: 41088
#include<bits/stdc++.h>
using namespace std;
#define ll long long
int main()
{
    ll a,b,c;
    cin>>a>>b>>c;
    if(c>=b)
        cout<<(floor(a*(b-1)/b))<<endl;
    else
        cout<<floor(a*(c)/b)<<endl;
    return 0;
}


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

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

typedef long long ll;

#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=a;i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=a;i>=(ll)(b);i--)
//定数
#define INF 1000000000 //10^9:極めて大きい値,∞
//略記
#define PB push_back //vectorヘの挿入
#define MP make_pair //pairのコンストラクタ
#define F first //pairの一つ目の要素
#define S second　//pairの二つ目の要素

int n;
vector<ll> a;
ll memo[3000][3000];
int flag[3000][3000]={};

ll dp(int ifir, int ibak){ // X-Y
    if(flag[ifir][ibak]) return memo[ifir][ibak];
    flag[ifir][ibak]=1;
    ll ret;
    if(ifir==ibak) {
        if((n+ifir+ibak)%2==1) ret=a[ifir];
        else ret=-a[ifir];
    }
    else{
        if((n+ifir+ibak)%2==1){
            ret=max(a[ifir]+dp(ifir+1,ibak),a[ibak]+dp(ifir,ibak-1));
        }
        else{
            ret=min(-a[ifir]+dp(ifir+1,ibak),-a[ibak]+dp(ifir,ibak-1));
        }
    }
    memo[ifir][ibak]=ret;
    return ret;
}

int main(){
    cin>>n;
    a.resize(n);
    rep(i,n) cin>>a[i];
    cout<<dp(0,n-1)<<endl;
    return 0;
}

Measured memory_bytes: 105088
#include<iostream>
#include<cmath>
using namespace std;
int main()
{
  int x,y,z,m;
  double e;
  while(cin>>e,e){
    m=1000000;
    for(z=0;z*z*z<=e;z++){
      y=(int)pow(e-z*z*z,1.0/2.0);
      x=e-y*y-z*z*z;
      if(m>x+y+z)m=x+y+z;
      //      cout<<x<<" "<<y<<" "<<z<<" "<<m<<endl;
    }
    cout<<m<<endl;
  }
}

Measured memory_bytes: 0
import math
A,B,H,M = map(int, input().split())
s1 = H*30+float(M/60)*30
s2 = M*6
sita = min(max(s1,s2)-min(s1,s2),(360-max(s1,s2))+min(s1,s2))
co = math.cos(math.radians(sita))
res = (B**2)+(A**2)+(-2*B*A*co)
print(math.sqrt(res))

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

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

  int sum = 0;
  vector<int> cost(N);
  
  for (int i=0; i<N; i++) {
    cost.at(i) = V.at(i) - C.at(i);
    
    if (cost.at(i) < 0) {
      cost.at(i) = 0;
    }
    sum =sum + cost[i];
  }
  cout << sum << endl;
}           

Measured memory_bytes: 256