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

#define BR "\n"
#define SP " "
#define SHOW(x) for(int i = 0; i < x.size(); i++) { cout << x[i] << SP; } cout << BR;
#define SHOW2(x) for(int j = 0; j < x.size(); j++) { SHOW(x[j]); } cout << BR;

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

  vector<double> A(N);
  double s = 0;
  for (int i = 0; i < N; i++) {
    cin >> A[i];
    s = s + (1 / A[i]);
  }
  cout << fixed << (1 / s) << "\n";

  return 0;
}

Measured memory_bytes: 256
a = list(map(int, input().split()))
a.sort()
ans = 0
if (a[0]%2==0 and a[1]%2!=0) or (a[0]%2!=0 and a[1]%2==0):
  a[1] += 1
  a[2] += 1
  ans += 1
a.sort()
print(ans+(a[1]-a[0])//2+a[2]-a[1])

Measured memory_bytes: 3060
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> pl;
#define all(a) (a).begin(),(a).end()
#define overload4(_1, _2, _3, _4, name, ...) name
#define rep1(n) for(ll i = 0;i < (n);i++)
#define rep2(i,n) for(ll i = 0;i < (n);i++)
#define rep3(i,a,b) for(ll i = (a);i < (b);i++)
#define rep4(i,a,b,c) for(ll i = (a);i < (b);i += (c))
#define rep(...) overload4(__VA_ARGS__, rep4, rep3, rep2, rep1)(__VA_ARGS__)
#define rrep1(n) for(ll i = (n)-1;i >= 0;i--)
#define rrep2(i,n) for(ll i = (n)-1;i >= 0;i--)
#define rrep3(i,a,b) for(ll i = (a)-1;i >= (b);i--)
#define rrep4(i,a,b,c) for(ll i = (a)-1;i >= (b);i -= (c))
#define rrep(...) overload4(__VA_ARGS__, rrep4, rrep3, rrep2, rrep1)(__VA_ARGS__)
#define SHOW(x) cout << #x << ": " << x << endl;
template<class T> ll sumArr(const T& a){ return accumulate(all(a), 0LL);}
template<class T> auto minArr(const T& a){ return *min_element(all(a));}
template<class T> auto maxArr(const T& a){ return *max_element(all(a));}
template<class T> void DEBUG_PRINT(T tmp){cout<<tmp<<endl;}
template<class T1,class... T2> void DEBUG_PRINT(T1 tmp,T2... tmp2){cout<<tmp<<" ";DEBUG_PRINT(tmp2...);}
ll gcd(ll a, ll b){ while(b){ ll c = b; b = a % b; a = c; } return a; }
const ll INF=1e18,MOD = 1e9+7;
const int iINF = 1e9;



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

    ll a,b,n,ans = 0,min;
    cin>>a>>b>>n;
    if(b > n)min = n;
    else min = b-1;
    cout<<floor(a*min/b)<<endl;
    return 0;
}


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

//{ START
using namespace std;
#define int int64_t
#define rep(i, a, n) for (int i = (a); i < (n); ++i)
#define reps(i, a, n) for (int i = (a); i > (n); --i)
#define arep(i, x) for (auto &&i : (x))
#define irep(i, x) for (auto i = (x).begin(); i != (x).end(); ++i)
//降順はgreater<T>()
#define all(x) (x).begin(), (x).end()
#define rv(s) reverse((s).begin(), (s).end())
// gcd lcmはそのままok
#define gcd(a, b) __gcd(a, b)
#define bits(n) (1 << (n))
#define pcnt(x) __builtin_popcountll(x)
//配列内等要素削除
#define unique(x) (x).erase(unique((x).begin(), (x).end()), (x).end())
#define Fixed(n) fixed << setprecision(n)
//総和
#define sowa(n) ((n) * ((n) + 1)) / 2
#define pb(x, a) (x).push_back(a)
#define fb(x, a) (x).push_front(a)
#define eb(x, a) (x).emplace_back(a)
#define F first
#define S second
#define cauto const auto &
using P = pair<int, int>;
using Graph = vector<vector<P>>;
template <class T>  //昇順
using min_heap = priority_queue<T, vector<T>, greater<T>>;
template <class T>  //降順
using max_heap = priority_queue<T>;
template <class A, class B>
using umap = unordered_map<A, B>;
template <class A>
using uset = unordered_set<A>;
template <typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val) {  //多次元初期化
  std::fill((T *)array, (T *)(array + N), val);
}
template <class T>
bool chmax(T &a, const T &b) {  //最大値更新 返り値はbool
  if (a < b) {
    a = b;
    return 1;
  }
  return 0;
}
template <class T>
bool chmin(T &a, const T &b) {  //最小値更新 返り値はbool
  if (b < a) {
    a = b;
    return 1;
  }
  return 0;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};
constexpr int INF = 0x3f3f3f3f;
constexpr int LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int mod1 = 1e9 + 7;
constexpr int mod2 = 998244353;
//} END

signed main() {
  cin.tie(nullptr);
  ios_base::sync_with_stdio(false);

  int k;
  string s;
  cin >> k >> s;

  if (k < s.size()) {
    rep(i, 0, k) cout << s[i];
    cout << "...\n";
  } else {
    cout << s << '\n';
  }

  return 0;
}

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

int cnt_digit(long a){
	int digit=0;
	while(a/=10){
		digit++;
	}
	digit++;
	return digit;
}
int main(){
	long n;
	int digit;
	cin >> n;
	digit = cnt_digit(n);
	for(long i=2;i*i<=n;i++){
		if(n%i!=0)continue;
		int a = n/i;
		int b = max(cnt_digit(i),cnt_digit(a));
		digit = min(digit,b);
	}
	cout << digit;
	return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int parts[100000];
int res[100000][400];
int state[100000];
int main(){
  int a,b,c,many,n;
  while(cin >> a >> b >> c, a){
    many = a+b+c;
    for(int i=0;i<many;i++){
      parts[i]=2;
    }
    cin >> n;
    //int A[n],B[n],C[n];
    
    for(int i=0;i<n;i++){ //表入力
      cin >> res[i][0] >> res[i][1] >> res[i][2] >> state[i];
      
      res[i][0]--;
      res[i][1]--;
      res[i][2]--;
      if(state[i]){
	parts[res[i][0]]=1;
	parts[res[i][1]]=1;
	parts[res[i][2]]=1;
      }
      
    }
    
    for(int i=0;i<n;i++){ //故障品探し(一回全部のデータを取り込んでからやるらしい)
      if(!state[i]){
	if(parts[res[i][0]]==1 && parts[res[i][1]]==1) parts[res[i][2]]=0;
	if(parts[res[i][1]]==1 && parts[res[i][2]]==1) parts[res[i][0]]=0;
	if(parts[res[i][0]]==1 && parts[res[i][2]]==1) parts[res[i][1]]=0;
      }
    }
    
    for(int i=0;i<many;i++){
      cout << parts[i] << endl;
    }
  }
}

Measured memory_bytes: 2740
package main

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

var sc = bufio.NewScanner(os.Stdin)

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

func lowerBound(a []int, x int) int {
        n := len(a)
        ok := n
        ng := -1
        for ok-ng > 1 {
                mid := (ok + ng) / 2
                if a[mid] >= x {
                        ok = mid
                } else {
                        ng = mid
                }
        }
        return ok
}

func main() {
        sc.Buffer(make([]byte, 0), 1000006)
        sc.Split(bufio.ScanWords)

        var s, t string

        s = readLine()
        t = readLine()

        idxs := make([][]int, 256)

        for i := 0; i < len(s); i++ {
                idxs[s[i]] = append(idxs[s[i]], i)
        }

        n := int64(len(s))
        cur := int64(0)
        ng := false

        for i := 0; i < len(t); i++ {
                is := idxs[t[i]]
                if is == nil || len(is) == 0 {
                        ng = true
                        break
                }
                base := (cur / n) * n

                nidx := lowerBound(is, int(cur%n))
                if nidx == len(is) {
                        cur = base + int64(is[0]) + n + 1
                } else {
                        cur = base + int64(is[nidx]) + 1
                }
        }
        if ng {
                fmt.Println(-1)
        } else {
                fmt.Println(cur)
        }
}


Measured memory_bytes: 5760
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        for(int i = 0; i < m; i++) n -= Integer.parseInt(sc.next());
        System.out.println(n < 0 ? -1 : n);
    }
}


Measured memory_bytes: 41644
w, a, b = map(int, input().split())
a_list = [a, a+w]
b_list = [b, b+w]
if a_list[0]>b_list[1]:
    print(a_list[0]-b_list[1])
elif a_list[1]<b_list[0]:
    print(b_list[0]-a_list[1])
else:
    print(0)

Measured memory_bytes: 3060
#include <bits/stdc++.h>
using namespace std;
#define mod 998244353
#define MOD 1000000007
#define inf 0x3f3f3f3f
#define linf 0x3f3f3f3f3f3f3f3fll
typedef long long ll;
typedef pair<int,int> pii;
typedef unsigned long long ull;
int n,a,b;
int p[5050];
int rev[5050];
ll dp[5050][5050];
int main()
{
	scanf("%d%d%d",&n,&a,&b);
	for(int i=0;i<n;i++)
	{
		scanf("%d",&p[i]);
		p[i]--;
		rev[p[i]]=i;
	}
	memset(dp,0x3f,sizeof(dp));
	dp[0][0]=0;
	if(rev[0]!=0)dp[0][n]=b;
	for(int i=1;i<n;i++)
	{
		dp[i][i]=min(dp[i][i],dp[i-1][n]);
		dp[i][n]=min(dp[i][n],dp[i-1][n]+b);
	//	cout<<i<<endl;
		for(int lst=0;lst<i;lst++)
		{
			if(rev[lst]<rev[i])
			{
				dp[i][i]=min(dp[i][i],dp[i-1][lst]);
				dp[i][lst]=min(dp[i][lst],dp[i-1][lst]+b);
			}
			else
			{
				dp[i][lst]=min(dp[i][lst],dp[i-1][lst]+a);
			}
		}
	}
	ll ans=linf;
	for(int i=0;i<=n;i++)
		ans=min(ans,dp[n-1][i]);
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 199552
inputs = lambda: map(int, raw_input().split())
n_, q = inputs()
n = 1
while n<=n_: n *= 2
data = [(0, -n)] * (2*n+1)
for t in xrange(q):
    a, v = inputs()
    i = a + (n-1)
    data[i] = (data[i][0]+v, -a)
    while i:
        i = (i - 1) / 2
        data[i] = max(data[2*i+1], data[2*i+2])
    p, q = data[0]
    print -q, p

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

int main() {
    string s;
    cin >> s;
    int n = s.size();
    for (int i = 0; i < n - 1; ++i){
        if (s[i] == s[i + 1]){
            cout << i + 1 << " " << i + 2 << endl;
            return 0;
        }else if (i < n - 2 and s[i + 2] == s[i]){
            cout << i + 1 << " " << i + 3 << endl;
            return 0;
        }
    }
    cout << "-1 -1" << endl;
    return 0;
}

Measured memory_bytes: 512
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <math.h>
#include <functional>
#include <iomanip>
#include <bitset>
#include <numeric>
#include <queue>
#include <map>
#include <cstdint>
using namespace std;
#define rep(i, n) for (ll i = 0; i < n; i++)
const long long mod = 1000000007;
typedef long long int ll;
typedef pair<ll, ll> P;
const vector<int> di = { -1, 0, 1, 0 };
const vector<int> dj = { 0, 1, 0, -1 };

ll F(ll a, ll b) {
	int digit = 0;
	if (a > b) {
		while (a != 0) {
			a = a / 10;
			digit++;
		}
	}
	else {
		while (b != 0) {
			b = b / 10;
			digit++;
		}
	}
	
	return digit;
}

int main() {

	ll n;
	cin >> n;
	ll num = mod;
	for (ll i = 1; i < sqrt(n) + 1; i++) {
		if (n % i == 0) {
			num = min(num, F(i, n / i));
		}
	}
	cout << num << endl;
	

	return 0;
}

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


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

  vector<vector<long long>> F(N+1,vector<long long>(11)),P(N+1,vector<long long>(11));

  for(int i = 1;i <= N;i++) {
    for(int j = 1;j <= 10;j++) {
      cin >> F.at(i).at(j);
    }
  }

  for(int i = 1;i <= N;i++) {
    for(int j = 0;j <= 10;j++) {
      cin >> P.at(i).at(j);
    }
  }

  long long ans = -(1LL << 60);
  for(int bit = 1;bit < (1<<10);bit++) {
    
    vector<int> same(N+1),open(11);
    long long sum = 0;
    
    for(int i = 0;i < 10;i++) {
      if(bit & (1<<i)) open.at(i+1)++;
    }

    for(int i = 1;i <= N;i++) {
      for(int j = 1;j <= 10;j++) {
        if(open.at(j) && F.at(i).at(j)) same.at(i)++;
      }
    }

    for(int i = 1;i <= N;i++) {
      sum += P.at(i).at(same.at(i));
    } 

    ans = max(ans,sum);

  }

  cout << ans << endl;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define IOS ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);
#define rep(i,n) for(ll i=0;i<n;i++)
#define rep1(i,n) for(ll i=1;i<=n;i++)
#define rev(i,n) for(ll i=n-1;i>=0;i--)
#define rev1(i,n) for(ll i=n;i>0;i--)
#define pb push_back
#define vi vector<int>
#define vvi vector<vector<int>>
#define vpii vector<pair<int,int> >
#define vb vector<bool>
#define pii pair<int,int>
#define F first
#define S second
#define INF 1e9+7
typedef long long int ll;

const int N=2e3+7;
int sd[N][N];
vi visited(N);
vi parent(N);
vi level(N);
int ans[N];

void dfs(auto G,int c,int p,int d){
    if(visited[c]) return;
    visited[c]=1;
    for(auto x:G[c]) if(!visited[x]) sd[x][p]=min(sd[x][p],d+1);
    for(auto x:G[c]) if(!visited[x]) dfs(G,x,p,d+1);
}

void bfs(auto G, int p){
    queue<int> q;
    q.push(p);
    visited[p]=1;
    while(!q.empty()){
        int tmp=q.front();
        q.pop();
        for(auto x:G[tmp]) if(!visited[x]) {
            parent[x]=tmp; 
            level[x]=level[tmp]+1; 
            q.push(x);
            visited[x]=1;
            sd[p][x]=min(sd[p][x],level[x]);
        }
        //for(auto x:G[tmp]) if(!visited[x]) 
    }
}

void solve(){
    int n,x,y;
    cin>>n>>x>>y;
    rep1(i,n) rep1(j,n) sd[i][j]=2e3+7;
    vi G[n+1];
    rep1(i,n-1) { G[i].pb(i+1); G[i+1].pb(i);}
    G[x].pb(y); G[y].pb(x);
    rep1(i,n) {
        fill(visited.begin(), visited.begin()+n+1, 0);
        fill(parent.begin(), parent.begin()+n+1, 0);
        fill(level.begin(), level.begin()+n+1, 0);
        bfs(G,i);
    }
    rep1(i,n) rep1(j,n) if(j>i) ans[sd[i][j]]++;
    rep1(i,n-1) cout<<ans[i]<<"\n";
    
    //rep1(i,n) { rep1(j,n) cout<<sd[i][j]<<" "; cout<<"\n";}
}
signed main() {
    // your code goes here
    IOS
    ll t=1;
    //cin>>t;
    rep1(i,t){
        solve(); 
    }
}

Measured memory_bytes: 16128
#include<bits/stdc++.h>
using namespace std;
#define int long long
int N,h[100000+10]={},dp[100000+10]={},ans=0;

signed main(){
  cin >> N;
  for(int i=0;i<N;i++){
    cin >> h[i];
  }
  dp[0]=0;
  dp[1]=dp[0]+abs(h[1]-h[0]);
  for(int i=2;i<N;i++){
    dp[i]=min(dp[i-2]+abs(h[i]-h[i-2]),dp[i-1]+abs(h[i]-h[i-1]));
  }
  cout << dp[N-1] << endl;

  return 0;
}


Measured memory_bytes: 1792
#include <stdio.h>
typedef long long ll;

int main(void) {
  ll i, j, n, q, m = 100001, a, b, c, cnt[m], ans = 0;
  scanf("%lld", &n);
  for(i = 0; i < m; ++i) cnt[i] = 0;
  for(i = 0; i < n; ++i) scanf("%lld", &a), cnt[a]++;
  for(i = 0; i < m; ++i) ans += cnt[i] * i;
  scanf("%lld", &q);
  for(i = 0; i < q; ++i) {
    scanf("%lld%lld", &b, &c);
    ans += (c - b) * cnt[b];
    cnt[c] += cnt[b];
    cnt[b] = 0;
    printf("%lld\n", ans);
  }
  return 0;
}

Measured memory_bytes: 2508
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <map>

using namespace std;

const int MX = 150500;

int main()
{
    //freopen("in.txt","r", stdin);
    ios_base::sync_with_stdio(false);
    string s;
    cin >> s;
    int ans = 0;
    for(int i = 1; i < s.size(); i++)
        if(s[i] != s[i - 1]) ans++;
    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 640
#include<iostream>
#include<algorithm>
#include<cstring>
#include<cstdio>
#include<cmath>
using namespace std;

const int N=100000+10;

int _r;char _c;

int read()
{
	while(!isdigit(_c=getchar()));
	_r=_c-48;
	while(isdigit(_c=getchar()))
		_r=_r*10-48+_c;
	return _r;
}

int n,d[N],rt,dp[N];
int fir[N],nxt[N<<1],to[N<<1],tote;

void dfs(int u,int fa=rt)
{
	int i,v,fl(1);
	for(i=fir[u];i;i=nxt[i])if((v=to[i])!=fa)
	{
		dfs(v,u);
		if(!dp[v])
		{
			if(fl)
				fl=0;
			else
				++dp[u];
		}
		else
			dp[u]+=dp[v];
	}
}

int main()
{
	n=read();
	int i,u,v;
	for(i=1;i<n;++i)
	{
		u=read()+1;v=read()+1;
		to[++tote]=v;nxt[tote]=fir[u];fir[u]=tote;
		to[++tote]=u;nxt[tote]=fir[v];fir[v]=tote;
		++d[u];++d[v];
	}
	for(i=1;i<=n&&!rt;++i)if(d[i]>2)
		rt=i;
	if(!rt)
		printf("1");
	else
	{
		dfs(rt);
		//for(i=1;i<=n;++i)
		//{
		//	cout<<i<<":"<<dp[i]<<endl;
		//}
		printf("%d",dp[rt]);
	}
	return 0;
}


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

using namespace std;

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

const int N = 1010;

int n, k, res;

int main()
{
    cin >> n >> k;

    res = k;
    for(int i = 0; i < n - 1; i++) res *= k - 1;

    cout << res << endl;
    return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
typedef tuple<ll, ll, ll> T;

int N, A;

int main(void){
    
    scanf("%d %d", &N, &A);
    printf("%d\n", N * N - A);
    
    return 0;
}


Measured memory_bytes: 256
N = int(input())
x = 0
y = 0
t = 0
for i in range(N):
    t_i,x_i,y_i=map(int,input().split())
    x = x_i - x
    y = y_i - y
    t = t_i - t
    if t >= x + y and ( t - (x + y) )%2 == 0:
        if i == N -1:
            print("Yes")
    
    else:
        print("No")
        break
    

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

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

    string S;
    cin >> S;
    char prev_s = S[0];

    for (int i = 1; i < S.size(); ++i) {
        if (S[i] == prev_s) {
            cout << "Bad" << '\n';
            return 0;
        }
        prev_s = S[i];
    }
    cout << "Good" << '\n';

    return 0;
}


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

int main(void)
{
	char m[21];
	int f1, s;
	scanf("%s",m);
	s = strlen(m);
	for(f1 = s - 1; f1 >= 0; f1--)
	{
		printf("%c",m[f1]);
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 0
import sys
INF = 1 << 60
MOD = 10**9 + 7 # 998244353
sys.setrecursionlimit(2147483647)
input = lambda:sys.stdin.readline().rstrip()

# https://qiita.com/Kiri8128/items/eca965fe86ea5f4cbb98
def isPrimeMR(n):
    d = n - 1
    d = d // (d & -d)
    L = [2]
    for a in L:
        t = d
        y = pow(a, t, n)
        if y == 1: continue
        while y != n - 1:
            y = (y * y) % n
            if y == 1 or t == n - 1: return 0
            t <<= 1
    return 1
def findFactorRho(n):
    m = 1 << n.bit_length() // 8
    for c in range(1, 99):
        f = lambda x: (x * x + c) % n
        y, r, q, g = 2, 1, 1, 1
        while g == 1:
            x = y
            for i in range(r):
                y = f(y)
            k = 0
            while k < r and g == 1:
                ys = y
                for i in range(min(m, r - k)):
                    y = f(y)
                    q = q * abs(x - y) % n
                g = gcd(q, n)
                k += m
            r <<= 1
        if g == n:
            g = 1
            while g == 1:
                ys = f(ys)
                g = gcd(abs(x - ys), n)
        if g < n:
            if isPrimeMR(g): return g
            elif isPrimeMR(n // g): return n // g
            return findFactorRho(g)
def primeFactor(n):
    i = 2
    ret = {}
    rhoFlg = 0
    while i*i <= n:
        k = 0
        while n % i == 0:
            n //= i
            k += 1
        if k: ret[i] = k
        i += 1 + i % 2
        if i == 101 and n >= 2 ** 20:
            while n > 1:
                if isPrimeMR(n):
                    ret[n], n = 1, 1
                else:
                    rhoFlg = 1
                    j = findFactorRho(n)
                    k = 0
                    while n % j == 0:
                        n //= j
                        k += 1
                    ret[j] = k

    if n > 1: ret[n] = 1
    if rhoFlg: ret = {x: ret[x] for x in sorted(ret)}
    return ret

from math import gcd
from functools import reduce
def resolve():
    n = int(input())
    A = list(map(int, input().split()))

    if reduce(gcd, A) != 1:
        print("not coprime")
        return

    used = set()
    for a in A:
        for p in primeFactor(a):
            if p in used:
                print("setwise coprime")
                return
            used.add(p)

    print("pairwise coprime")
resolve()

Measured memory_bytes: 191040
object Main extends App {
  val sc = new java.util.Scanner(System.in)
  val n, m, r = sc.nextInt()
  val rs = List.fill(r)(sc.nextInt()-1)
  val e = List.fill(m)((sc.nextInt()-1, sc.nextInt()-1, sc.nextInt()))

  def shortestPath(n: Int, edges: Seq[(Int, Int, Int)]): Array[Array[Int]] = {
    val ans = Array.tabulate(n,n)((i,j) => if (i == j) 0 else -1)
    for ((u, v, l) <- edges) {
      ans(u)(v) = l
      ans(v)(u) = l
    }

    for {
      k <- 0 until n
      i <- 0 until n
      j <- 0 until n
      if ans(i)(k) != -1 && ans(k)(j) != -1 &&
        (ans(i)(j) == -1 || ans(i)(k) + ans(k)(j) < ans(i)(j))
    } {
      ans(i)(j) = ans(i)(k) + ans(k)(j)
    }
    ans
  }

  val sp = shortestPath(n, e)
  val ans = rs.permutations.map(_.sliding(2).map{case List(x1, x2) => sp(x1)(x2)}.sum).min
  println(ans)
}


Measured memory_bytes: 67848
package main

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

func main() {

	sc := bufio.NewScanner(os.Stdin)
	sc.Scan()
	in := sc.Text()

	vars := strings.Split(in, " ")
	W, _ := strconv.Atoi(vars[0])
	H, _ := strconv.Atoi(vars[1])
	x, _ := strconv.Atoi(vars[2])
	y, _ := strconv.Atoi(vars[3])
	r, _ := strconv.Atoi(vars[4])

	ct := y + r
	cb := y - r
	cl := x - r
	cr := x + r

	if ct > H {
		fmt.Println("No")
	} else if cb < 0 {
		fmt.Println("No")
	} else if cl < 0 {
		fmt.Println("No")
	} else if cr > W {
		fmt.Println("No")
	} else {
		fmt.Println("Yes")
	}
}



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

int main() {
  int n;cin>>n;
  cout<<180*(n-2)<<endl;
}

Measured memory_bytes: 3624
n = int(input())
cnt = [False]*n

for i in range(n):
    x,y = map(int, input().split())
    cnt[i] = x == y

ans = 'No'

for i in range(n-2):
    if cnt[i] and cnt[i+1] and cnt[i+2]:
        ans = 'Yes'

print(ans)

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

int main(){
	ll x;
	cin >> x;
	vector<int> v;
	for (int i = 1; i*i <= 1000 ; ++i) {
		for (int j = 2; j <= 10 ; ++j) {
			if(pow(i,j) <= 1000){
				v.push_back(pow(i,j));
			}
		}
	}
	int ans = 0;
	rep(i,v.size()){
		if(v[i] <= x){
			ans = max(ans, v[i]);
		}
	}
	cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main() {
  int N;
  string S;
  bool Hina = false;
  cin >> N;
  
  for(int i=0;i<N;i++){
    cin >> S;
    if(S == "Y"){
      Hina = true;
      break;
    }
  }
  if(Hina){
    cout << "Four" << endl;
  }else{
    cout << "Three" << endl;
  }
}


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

int main() {
	int a, b, c, d, e, f;
	std::cin >> a >> b >> c >> d >> e >> f;
	a *= 100;
	b *= 100;

	std::vector<int> water, suger;
	for (int i = 0; a * i <= f; ++i)
		for (int j = 0; a * i + b * j <= f; ++j)
			water.push_back(a * i + b * j);

	for (int i = 0; c * i <= f; ++i)
		for (int j = 0; c * i + d * j <= f; ++j)
			suger.push_back(c * i + d * j);

	int ansTotal = 0, ansSuger = 0;
	double maxDens = -1.0;
	for (auto&& w : water) {
		for (auto&& s : suger) {
			if (w + s <= f && s <= w / 100 * e) {
				const double dens = 1.0 * s / (w + s);
				if (dens > maxDens) {
					maxDens = dens;
					ansTotal = w + s;
					ansSuger = s;
				}
			}
		}
	}

	std::cout << ansTotal << " " << ansSuger << std::endl;
}

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

#define REP(i, n, m) for(int i = n; i < m; i++)
#define REPR(i, n, m) for(int i = n; i >= m; i--)
#define LREP(i, n, m) for(ll i = n; i < m; i++)
#define LREPR(i, n, m) for(ll i = n; i >= m; i--)


const int INF = 1e9 + 1;
const int MOD = 1e9 + 7;

typedef long long ll;


//---functions---//
int gcd(int a, int b){
    if(a < b) swap(a, b);
    return b?gcd(b, a%b):a;
}

int s2i(string num){stringstream ss; ss << num << flush; int n; ss >> n; return n;}
string i2s(int n){stringstream ss; ss << n << flush; return ss.str();}
//---------------//

int H, W;
bool s[52][52];

bool isNeibor(int h, int j){
    if(s[h-1][j] || s[h+1][j] || s[h][j-1] || s[h][j+1]) return true;
    else return false;
}
int main(){
    cin.tie(0);
    cout.tie(0);
    ios::sync_with_stdio(false);

    cin >> H >> W;
    char tmp;
    REP(i, 0, H + 2){
        REP(j, 0, W + 1) s[i][j] = false;
    }
    REP(i, 1, H + 1){
        REP(j, 1, W + 1){
            cin >> tmp;
            if(tmp == '#') s[i][j] = true;
        }
    }

    bool flag = true;
    REP(i, 1, H + 1){
        if(!flag) break;
        REP(j, 1, W + 1){
            if(s[i][j] && !isNeibor(i, j)){
                flag = false; 
                break;
            } 
        }
    }
    if(flag) cout << "Yes" << endl;
    else cout << "No" << endl;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
#define REP(i,n) for(int i=0;i<n;i++)
#define LOOP(i,x,n) for(int i=x;i<n;i++)
#define ALL(v) (v).begin(),(v).end()
#define PB push_back
#define MP make_pair
#define FR first
#define SC second
#define int long long
using namespace std;
const int MOD=1000000007;
const int INF=9000000009;

signed main(){
  int n,a,b;
  cin>>n>>a>>b;
  int sum=0;
  LOOP(i,1,n+1){
    int tmp=0;
    int t=i;
    while(t>0){
      tmp+=t%10;
      t/=10;
    }
    if(a<=tmp&&tmp<=b)sum+=i;
  }
  cout<<sum<<endl;
  return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
const int mod = 1000000007;
#define rep(i, n) for(int i = 0; i < (n); i++)

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

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






int gcd(int a,int b)
{
 
  int r, tmp;
 
  
 
  /* 自然数 a > b を確認・入替 */
  if(a<b){
    tmp = a;
    a = b;
    b = tmp;
  }
 
  /* ユークリッドの互除法 */
  r = a % b;
  while(r!=0){
    a = b;
    b = r;
    r = a % b;
  }
 
 
 
  return b;
}







int fac(int n){
  int m=1;
  while(n>=1) m*=n,n--;
  return m;
}

int vec_sum(vector<int> v){
  int n=0;
  for(int i=0;i<v.size();i++) n+=v[i];
  return n;
}
///////////////////////////
int main() {
  int n,cnt=0;
  int flag=0;
  cin>>n;
  vector<int> v;
  v.push_back(n);
  while(true){
    if(n==1){
      flag++;
    }
    if(n%2==0){
      n/=2;
      v.push_back(n);
    }else{
      n*=3;
      n++;
      v.push_back(n);
    }
    if(flag>=2){
      break;
    }
  }
  
  
  
  
  
  for(int i=0;i<v.size()-1;i++){
    for(int j=i+1;j<v.size();j++){
      if(v[i]==v[j]){
        cout<<max(i,j)+1<<endl;
        return 0;
      }
    }
  }
  
  
  
}
///////////////////////////

Measured memory_bytes: 256
str_menu,int_menu,fir_digi,ans=[str(input()) for i in range(5)],[],[],0
for i in range (5):
    fir_digi.append(int(str_menu[i][-1]))
    int_menu.append(int(str_menu[i]))
while min(fir_digi)==0:
    fir_digi[fir_digi.index(0)]=10

for i in range (5):
    if i!=fir_digi.index(min(fir_digi)):
        if fir_digi[i]!=10:
            int_menu[i]=int(int_menu[i]/10)*10+10
    ans=ans+int_menu[i]
print(ans)

Measured memory_bytes: 3064
#include<stdio.h>
int main (void)
{
	int a,b,c,x;
	scanf("%d%d%d%d",&a,&b,&c,&x);
	int pricea = 500;
	int priceb = 100;
	int pricec = 50;
	int y =0;
	for(int i = 0;i <= a;i++){
		for(int j=0;j<=b;j++){
			for(int k=0;k<=c;k++){
				if(pricea*i + priceb*j + pricec*k == x) y++;
			}
		}
	}
	printf("%d",y);
	return 0;
}


Measured memory_bytes: 128
#include <iostream>
int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    int x,a,b;
    std::cin >> x;
    std::cin >> a;
    std::cin>> b;
    int c;
    c = x-a;
    c = c - (c/b)*b;
    std::cout <<c;
    return 0;
}

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

using namespace std;

#define M 1000000007
#define pb push_back
#define f first
#define s second
#define rep(i, st, ed) for(int i=st; i<ed; i++)
#define repn(i, st, ed) for(int i=st; i<=ed; i++)
#define repb(i, ed, st) for(int i=ed; i>=st; i--)

typedef long long ll;
typedef unsigned long long int llt;
typedef long double ld;

const long double PI  =3.141592653589793238463;
const int N = 5e5 + 10;

vector<int> g[N];
bool viss[N];
int vis[N];

// Normal DFS
void dfs(int curr, int par)
{
  for(auto x: g[curr])
    if(x != par)
      dfs(x, curr);
}

// DFS with visiting status
void dfs1(int curr, int par)
{
  viss[curr] = 1;
  for(auto x: g[curr])
    if(!viss[x])
      dfs1(x, curr);
}

// DFS with strongly connected component
void dfs2(int curr, int par, int num)
{
  vis[curr] = num;
  for(auto x: g[curr])
    if(vis[x] == 0)
      dfs2(x, curr, num);
}

// XOR from 0 to n
ll fxor(ll n)
{
  if(n < 0) return 0;
  if(n % 4 == 3) return 0;
  else if(n % 4 == 0) return n;
  else if(n % 4 == 1) return n^(n-1);
  else if(n%4 == 2) return n^(n-1)^(n-2);
}

// Power in logn with mod 1000000007
llt ppow(llt x, llt y)
{
  llt res = 1;
  while(y > 0){
    if(y&1)
      res = (res * x)%M;
    y = y >> 1;
    x = (x * x)%M;
  }
  return res;
}

// Factorial with dp
llt factdp[N];
llt fact(llt x)
{
  if(x == 0) return 1;
  if(x == 1) return 1;
  if(factdp[x] != -1) return factdp[x];
  return factdp[x] = (x*fact(x-1))%M;
}

// String return to base b
string ansConv ="";
void convert10tob(llt N, int b)
{
     if (N == 0)
        return;
     int x = N % b;
     N /= b;
     if (x < 0)
        N += 1;
     convert10tob(N, b);
     ansConv += to_string(x);
     return;
}

// Convert string to num wiht base b
llt convertstrtob(string a, int b)
{
  llt aa = 0;
  llt mul = 1;
  for(int i=a.length()-1; i>=0; i--)
  {
    int curr = a[i] - '0';
    aa += (curr * mul);
    mul *= b;
  }
  return aa;
}

// Union Find algo with array
// Find()
int findpar(int curr, int arr[])
{
  while(arr[curr] != curr) curr = arr[curr];
  return curr;
}
// Union()
void Union(int b, int spa, int arr[])
{
  while(arr[b] != b)
  {
    int c = arr[b];
    arr[b] = spa;
    b = c;
  }
  arr[b] = spa;
}

// Main Code

int main()
{
  int a, b, c, d;
  cin>>a>>b>>c>>d;
  ll ar = a*b;
  ll aa = c*d;
  cout<<max(aa, ar)<<endl;
  return 0;
}


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

using namespace std;

int main(){
int N; cin >> N;
  vector<long long > H(N);
  for(int i = 0; i < N; i++){ cin >> H[i];}
  
  long long max_res = H[0];
  bool flag = true;
 for(int i = 0; i < N ; i++){
   if( H[i] <= max_res - 2){ flag = false; break;}
   
   max_res = max( max_res , H[i]);}
  
  if( flag ) { cout << "Yes" << endl;}
  else{ cout << "No" <<endl;}
  return 0;}
   

Measured memory_bytes: 1152
let m = 1020001

let split str delim =
  let open String in
  let rec doit s acc =
    match
      try Some (rindex s delim) with _ -> None
    with
    | None -> s :: acc
    | Some i -> doit (sub s 0 i) (sub s (i + 1) (length s - i - 1) :: acc) in
  doit str []

let to_x = Array.make 128 0

let to_key s =
  let n = String.length s in
  let rec doit i p acc =
    if i = n then acc
    else doit (i + 1) (5*p) (acc + p*(to_x.(Char.code s.[i]))) in
  doit 0 1 0

let to_h1 k = k mod m
let to_h2 k = 1 + (k mod (m - 1))

let insert s t =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then ()
    else if t.(h) = "\000" then t.(h) <- s
    else doit (i + 1) in
  doit 0

let find s t =
  let k = to_key s in
  let h1 = to_h1 k in
  let h2 = to_h2 k in
  let rec doit i =
    let h = (h1 + h2*i) mod m in
    if t.(h) = s then true
    else if t.(h) = "\000" then false
    else doit (i + 1) in
  doit 0

let () =
  to_x.(Char.code 'A') <- 1;
  to_x.(Char.code 'C') <- 2;
  to_x.(Char.code 'G') <- 3;
  to_x.(Char.code 'T') <- 4;
  let n = read_int () in
  let t = Array.make m "\000" in
  let rec doit i =
    if i < n then begin
      begin match split (read_line ()) ' ' with
      | ["insert"; s] -> insert s t
      | ["find"; s] -> print_endline (if find s t then "yes" else "no")
      | _ -> ()
      end;
      doit (i + 1)
    end in
  doit 0

Measured memory_bytes: 20528
import java.util.Scanner;
 
class Main {
  public static void main (String[] args) {
    Scanner scanner = new Scanner(System.in);
 
int x = scanner.nextInt();
int y = scanner.nextInt();
 
if(x == 2 ) {
x = 0;
} else if(x == 4 || x == 6 || x == 9 || x == 11) {
x = 1;
} else {
x = 2;
}
 
if(y == 2 ) {
y = 0;
} else if(y == 4 || y == 6 || y == 9 || y == 11) {
y = 1;
} else {
y = 2;
}
 
if(x ==y) {
System.out.println("Yes");
} else {
System.out.println("No");
}
}
}

Measured memory_bytes: 23124
#include<bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
vector<vector<P> > G;
signed main(){
  int n,e,r;
  cin>>n>>e>>r;
  int INF=1LL<<55LL;
  G.resize(n);
  for(int i=0;i<e;i++){
    int s,t,d;
    cin>>s>>t>>d;
    G[s].push_back(P(t,d));
  }
  int d[n];
  for(int i=0;i<n;i++) d[i]=INF;

  priority_queue<P,vector<P>,greater<P> > q;
  d[r]=0;
  q.push(P(0,r));

  while(!q.empty()){
    P p=q.top();q.pop();
    int u=p.second,c=p.first;
    //cout<<u<<" "<<c<<endl;
    if(d[u]<c) continue;
    for(P e:G[u]){
      int v=e.first,w=e.second;
      if(d[v]>d[u]+w){
	d[v]=d[u]+w;
	q.push(P(d[v],v));
	//cout<<v<<":"<<d[v]<<endl;
      }
    }
  }
  
  for(int i=0;i<n;i++){
    if(d[i]==INF) cout<<"INF"<<endl;
    else cout<<d[i]<<endl;
  }

  return 0;
}

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

int main()
{
    long long  n,sum=0;
    cin>>n;
    for(long long i=1;i<=n;i++)
    {
        if(i%3!=0 and i%5!=0) sum+=i;
    }
    cout<<sum<<endl;

    return 0;
}


Measured memory_bytes: 3636
#ifndef BZ
#pragma GCC optimize "-O3"
#endif
#include <bits/stdc++.h>
#define FASTIO ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);
#define rep(i, l, r) for (ll i = (l); i < (r); ++i)
typedef long long ll;
typedef long double ld;
typedef unsigned long long ull;
#define pii pair<int, int>
#define pll pair<ll, ll>
#define pli pair<ll, int> 
#define pdd pair<ld, ld> 
//#define mp make_pair
#define pb push_back
#define reset(x,v) memset(x,v,sizeof(x))
#define mod 1000000007
using namespace std;
bool comp(pll a, pll b){
    return a.second > b.second;
}
int main(){
   FASTIO
   int n, k;
   cin >> n >> k;
   pll p[n];
   rep(i, 0, n)
   cin >> p[i].first >> p[i].second;
   sort(p, p + n, comp);
   if(n == k){
       ll ts = 0;
       set<ll> st;
       rep(i, 0, n){
       ts += p[i].second;
       st.insert(p[i].first);
       }
       cout << ts + (st.size() * (ll)st.size());
       return 0;
   }
   unordered_map<ll, ll> mp;
   int l = 0;
   rep(i, 0, n){
       if(mp.count(p[i].first) == 0)
       mp[p[i].first] = l++;
   }
   vector<int> v[l];
   rep(i, 0, n){
       v[mp[p[i].first]].pb(p[i].second);
   }
   
   priority_queue<ll> pq;
   priority_queue<ll, vector<ll>, greater<ll> > pq2;
   ll s = 0, ms = 0;
   int i = 0, kk = min(k, l);
   ll x = kk;
   
   while(kk > 0){
       if(v[i].size() > 0){
       s += v[i][0];
       pq2.push(v[i][0]);
       kk--;
       }
       i++;
   }
   kk = n - min(k, l);
   int j = 0;
   if(k >= l){
   j = 1;
   i = 0;
   }
    while(kk > 0){
       if(v[i].size() > j){
       pq.push(v[i][j]);
       kk--;
       }
       if((i + 1) % l == 0){
           i = 0;
           j++;
       }
       else
       i++;
   }
   //s += x;
   ms = max(ms, s);
   int rem = k - min(k, l);
   while(rem > 0){
       s += pq.top();
       pq2.push(pq.top());
       pq.pop();
       rem--;
   }
   while(x > 0 && (pq.top() + (x-1)*(x-1)) > (pq2.top() + x*x)){
       s -= pq2.top();
       s += pq.top();
       ll t1 = pq.top(), t2 = pq2.top();
       pq.pop();
       pq2.pop();
       pq.push(t2);
       pq2.push(t1);
       x--;
   }
   cout << s + x * x;
}




Measured memory_bytes: 12708
#include<stdio.h>

int main(){
	int x[4],y[4],h,b,i,j;
	while(scanf("%d",&x[0])!=EOF){
		for(i=1;i<4;i++)scanf("%d",&x[i]);
		for(i=0;i<4;i++)scanf("%d",&y[i]);
		h=b=0;
		for(i=0;i<4;i++){
			if(x[i]==y[i]){
			h++;
			y[i]=10;			
			}
		}
		for(i=0;i<4;i++)for(j=0;j<4;j++)if(x[i]==y[j])b++;
		printf("%d %d\n",h,b);
	}

	return 0;
}

Measured memory_bytes: 596
#include<iostream>
#include<cstdio>
#include<cstring>
#include<string>
#include<algorithm>
#include<bitset>
#include<vector>
#include<deque>
#include<list>
#include<queue>
#include<map>
#include<set>
#include<stack>
#include<cmath>
#include<iomanip>
#include <functional>
using namespace std;
typedef long long ll;
const int mod = 1000000007;
const int INF = 1 << 28;
const double EPS = 1e-10;
//cout << fixed << std::setprecision(9)
//memset(a, 0, sizeof(a));
//--------------------------

int h, w;
char grid[1001][1001];
int dp[1001][1001];

int main()
{
	cin >> h >> w;
	for (int i = 1;i <= h;i++)
		for (int j = 1;j <= w;j++)
			cin >> grid[i][j];

	dp[1][1] = 1;

	for(int i=1;i<=h;i++)
		for (int j = 1;j <= w;j++) {
			if (i == 1 && j == 1) continue;

			if (grid[i][j] == '#') {
				dp[i][j] = 0;
			}
			else {
				dp[i][j] = (dp[i - 1][j] + dp[i][j - 1]) % mod;
			}
		}

	cout << dp[h][w] << endl;

	return 0;
}


Measured memory_bytes: 5120
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
using namespace std;
int main()
{
    long long n;
    cin >> n;
    int mid = sqrt(n);
    for (int i = 0; i < mid;i++){
        if(n%(mid-i)==0){
            n = (mid - i) + n / (mid - i) - 2;
            break;
        }        
    }
    cout << n << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int a[105]={0};
int main(){
  int n, k, d, t, cnt=0;
  scanf("%d%d", &n, &k);
  while(k--){
    scanf("%d",&d);
    for(int i=0; i<d; i++){
        scanf("%d", &t);
        a[t]++;
    }
  }
  for(int i=1; i<=n;i++){
    if(a[i]==0) cnt++;
  }
  printf("%d", cnt);
  return 0;
}


Measured memory_bytes: 3756
#include "bits/stdc++.h"
using namespace std;
typedef long long ll;
#define int ll
typedef pair<int,int> pii;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define all(a) (a).begin(),(a).end()
#define pb emplace_back
#define INF (1LL<<60)

//verified AOJ GRL_1
#define MAX_V 100020
template <typename T>
struct edge{int to;T cost;};

template <typename T>
void dijkstra(int s, vector<T> &d, vector<edge<T>> G[MAX_V]){
    priority_queue< pii,vector<pii>,greater<pii> > que;
    rep( i,d.size() )d[i]=INF;
    d[s] = 0;
    que.push( pii(0,s) );
    
    while( que.size() ){
        pii p=que.top();
        que.pop();
        
        int v=p.second;
        if(d[v]<p.first)continue;
        
        rep(i,G[v].size()){
            edge<T> e=G[v][i];
            if(d[e.to]>d[v]+e.cost){
                d[e.to]=d[v]+e.cost;
                que.push(pii(d[e.to],e.to));
            }
        }
    }
}



signed main(){
    int n,m,r,q;
    cin>>n>>m>>r>>q;
    vector<edge<int>> G[MAX_V];

    rep(i,m){
        int s,t,c;
        cin>>s>>t>>c;
        G[t].pb(edge<int>{s,c});
    }
    for(int i=1;i<=n;i++){
        G[n+1+i%r].pb(edge<int>{i,0});
    }
    
    static vector<vector<int>> d(r,vector<int>(n+r+1));
    for(int i=0;i<r;i++){
        dijkstra<int>(n+i+1,d[i],G);
    }
    
    int ans = 0;
    rep(i,q){
        int x,y,z;
        cin>>x>>y>>z;
        int mini = INF;
        rep(j,r){
            mini = min(mini,d[j][x]+d[j][y]);
        }
        if(z-mini>0)ans += z-mini;
    }
    cout<<ans<<endl;
}







Measured memory_bytes: 19192
#include <iostream>
#include <map>
using namespace std;
map<int,int> A,T;
int N,M;
int main()
{
    cin.sync_with_stdio(false);cin.tie(0);
    cout.sync_with_stdio(false);cout.tie(0);
    cin>>N;
    for(int i=1;i<=N;i++)
    {
        int a;
        cin>>a;
        A[a]++;
    }
    cin>>M;
    for(int i=1;i<=M;i++)
    {
        int a;
        cin>>a;
        T[a]++;
        if(T[a]>A[a])
        {
            cout<<"NO";return 0;
        }
    }
    cout<<"YES";
    return 0;
}


Measured memory_bytes: 19072
data = input().split(" ")
x0 = int(data[0])
k  = int(data[1])
d  = int(data[2])

const = x0 - k*d
if const >= 0:
  print(const)
else:
  ii = int(abs(const)/(2*d))
  if ii >= k:
    print( abs(const+2*d*(k)) )
  else:
    x_1 = abs(const+2*d*(ii-1))
    x_2 = abs(const+2*d*(ii))
    x_3 = abs(const+2*d*(ii+1))
    x = [x_1,x_2,x_3]
    x.sort()
    print(x[0])

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

int main() {
  int d,t,s;
  cin >> d >> t >> s;
  if (d<=s*t) {
    cout << "Yes"<<endl;
    return 0;
  }
  cout << "No" << endl;
  return 0;
}


Measured memory_bytes: 3592
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[] h = new int[n];
      int count = 0;
      int max = 0;
      for(int i = 0;i < n;i++) h[i]=sc.nextInt();
      for(int i = 1;i < n;i++){
      	if(h[i-1] >= h[i])count++;
        else{
          max = Math.max(count,max);
          count = 0;
        }
      }
      max = Math.max(count,max);
      System.out.println(max);
    }
}

Measured memory_bytes: 50840
#include "bits/stdc++.h"
#include <stdint.h>
 
#pragma optimize("O3")
 
using namespace std;
 
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> pii;
typedef vector<int> vi;
typedef long double ld;
 
#define sync                    \
ios_base::sync_with_stdio(0); \
cin.tie(0);                   \
cout.tie(0)
#define ALL(V) V.begin(), V.end()
#define SZ(V) (int)V.size()
#define pb push_back
#define mp make_pair
#define fopen freopen("input.txt", "r", stdin); freopen("output.txt","w", stdout)
#define FOR(i, a, b) for(ll i = (a); i < (b); ++i)
#define FORR(i, b, a) for(ll i = (b) - 1; i >= (a); --i)
#define REP(i, N) FOR(i, 0, N)
#define REPR(i, N) RFOR(i, N, 0)
#define FILL(A,value) memset(A,value,sizeof(A))
#define ff first
#define ss second
#define pii pair<int,int>
#define pll pair<ll, ll>
#define MP make_pair
const ll MOD = 1e9+7;
const ll INF = 1e9 + 7;
const int base = 2e5+1;
const int MAX =1e5+2;
const double EPS = 1e-9;
const double PI = acos(-1.);
const int MAXN = 32000+5;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
 
ull k;
map<int, int> start_index;
int t[800000 + 47];
void build(vector<pair<int, int>> a, int v, int l, int r){
    if(l == r){
        t[v] = a[l].second;
    }else{
        int mid = (l+r)/2;
        build(a, v*2, l, mid);
        build(a, v*2 + 1, mid + 1, r);
        t[v] = max(t[v*2], t[v*2 + 1]);
    }
}
int get_max(int v, int tl, int tr, int l, int r){
        if(l > r){
            return -1;
        }
        if(l == tl && r == tr){
            return t[v];
        }
        int mid = (tl + tr)/2;
        return max(get_max(v*2, tl, mid, l, min(r, mid)), get_max(v*2+1, mid+1, tr, max(l, mid + 1 ), tr));
}

int main()
{   
    int a, b;
    cin >> a >> b;
    if((a+b)%2 != 0){
        cout<<"IMPOSSIBLE";
    }else{
        cout<<(a+b)/2;  
    }
 
}

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

int main() {
  int cnt = 0, len;
  string s;
  cin >> s;
  len = s.size();
  for (int i = 0; i < len - 1; i++) {
    if (i == -1) i = 0;
    if ((s[i] == '0' && s[i + 1] == '1') || (s[i] == '1' && s[i + 1] == '0')) {
      cnt += 2;
      s.erase(i, 2);
      len = s.size();
      i -= 2;
    }
  }
  cout << cnt << endl;
}

Measured memory_bytes: 3768
// AOJ ALDS1_13_A 8 Queens Problem
// 2018.5.4 bal4u

#include <stdio.h>

char q[8];
char a[8], b[8], u[16], v[16];  // 衝突検出用 a:縦上下、b:横左右、u,v: 斜め方向

void found()
{
	int r, c;

	for (r = 0; r < 8; r++) {
		for (c = 0; c < 8; c++) {
			if (q[r] == c) putchar('Q');
			else           putchar('.');
		}
		putchar('\n');
	}
}

int check(int r)
{
	int c;

	if (r == 8) { found(); return 1; }
	if (b[r]) {	if (check(r+1)) return 1; }
	for (c = 0; c < 8; c++) {
		if (b[r] || a[c] || u[r+c] || v[r-c+7]) continue;
		a[c] = u[r+c] = v[r-c+7] = 1;
		q[r] = c;
		if (check(r+1)) return 1;
		a[c] = u[r+c] = v[r-c+7] = 0;
	}
	return 0;
}

int main()
{
	int k, r, c;

	scanf("%d", &k);
	while (k--) {
		scanf("%d%d", &r, &c);
		q[r] = c;
		a[c] = b[r] = u[r+c] = v[r-c+7] = 1;
	}
	check(0);
	return 0;
}



Measured memory_bytes: 2056
def is_ok(gen, res):
    if res == "Vacant":
        exit()
    return gen == res


def meguru_bisect_kai(ng, ok, gen):
    while True:
        mid = (ng + ok) // 2
        print(mid, flush=True)
        res = input()

        if is_ok(gen, res):
            if (mid - ng) % 2:
                ok = mid
            else:
                ng = mid
        else:
            if (mid - ng) % 2:
                ng = mid
                gen = res
            else:
                ok = mid


n = int(input())

print(0, flush=True)
res = input()
if res == "Vacant":
    exit()

ng = 0
ok = n
gen = res

meguru_bisect_kai(ng, ok, gen)

Measured memory_bytes: 9192
n = int(input())
h = list(map(int, input().split()))
ans = 0
last_ans = 0
for i in range(n-1):
    if h[i] >= h[i + 1]:
        ans += 1
    else:
        ans = 0
    if ans >= last_ans:
        last_ans=ans
print(last_ans)


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

int main(){
  int N,X,T;
  cin >> N >> X >> T;
  
  if(N % X == 0){
    cout << N/X * T << endl;
  }

  else{
    cout << (N/X + 1) * T << endl;
  }
  
}

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

using namespace std;
#define pb push_back
#define mp make_pair
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int i=0;i<(n);i++)
typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> pii;
constexpr int dx[] = {1, 0, -1, 0, 1, 1, -1, -1};
constexpr int dy[] = {0, -1, 0, 1, 1, -1, -1, 1};

template <typename T> ostream &operator<<(ostream &os, const vector<T> &vec){os << "["; for (const auto &v : vec) {os << v << ","; } os << "]"; return os; }
template <typename T, typename U> ostream &operator<<(ostream &os, const pair<T, U> &p) {os << "(" << p.first << ", " << p.second << ")"; return os;}

void solve() {
    int N, M;
    cin >> N >> M;
    map<int,int> cnt;
    for (int i = 0; i < M; i++) {
        int a, b;
        cin >> a >> b;
        cnt[a]++;
        cnt[b]++;
    }
    for(auto e : cnt) {
        if (e.second % 2 != 0) {
            cout << "NO" << endl;
            return;
        }
    }
    cout << "YES" << endl;

}

int main() {
    std::cin.tie(0);
    std::ios::sync_with_stdio(false);
    cout.setf(ios::fixed);
    cout.precision(16);
    solve();
    return 0;
}

Measured memory_bytes: 4352
import math
import itertools

K = int(input())
a = list(range(1, K + 1))
it = itertools.product(a, repeat=2)

c = 0
for i, j in it:
    g = math.gcd(i, j)
    for j in a:
        c += math.gcd(g, j)

print(c)


Measured memory_bytes: 9180
#include<stdio.h>

typedef struct{
  char kind;
  int value;
}array;

int main(){
  int i,j,minj,a,b,N,flag_S=1,flag_B=1;
  array C[36],B[36],S[36],temp;
  scanf("%d",&N);
  for(i=0;i < N;i++){
    scanf(" %c",&C[i].kind);
    scanf("%d",&C[i].value);

    B[i] = S[i] = C[i];
  }
  
  //Bubble
  for(i=0;i < N;i++){
    for(j=N-1;j > i;j--){
      if(B[j].value < B[j-1].value){
	temp = B[j];
	B[j] = B[j-1];
	B[j-1] = temp;
      }
    }
  }
  //Select
  for(i=0;i < N;i++){
    minj = i;
    for(j=i;j < N;j++){
      if(S[j].value < S[minj].value){
	minj = j;
      }
    }

    temp = S[i];
    S[i] = S[minj];
    S[minj] =temp;
  }
  //judge of B
  for(i=0;i < N;i++){
    for(j=i+1;j < N;j++){
      for(a=0;a < N;a++){
	for(b=a+1;b < N;b++){
          if(C[i].value == C[j].value){
	    if(C[i].value == B[b].value && C[i].kind == B[b].kind){
	      if (C[j].value == B[a].value && C[j].kind == B[a].kind){
		flag_B = 0;
	      }
	    }
	  }
	}
      }
    }
  }
  //judge of S
  for(i=0;i < N;i++){
    for(j=i+1;j < N;j++){
      for(a=0;a < N;a++){
	for(b=a+1;b < N;b++){
           if(C[i].value == C[j].value){
	    if(C[i].value == S[b].value && C[i].kind == S[b].kind){
	      if (C[j].value == S[a].value && C[j].kind == S[a].kind){
		flag_S = 0;
	      }
	    }
	  }
	}
      }
    }
  }
  
  for(i=0;i<N;i++){
    if(i != 0) printf(" ");
    printf("%c%d",B[i].kind,B[i].value);
  }
  if(flag_B==1) printf("\nStable\n");
  else printf("\nNot stable\n");
  
  for(i=0;i < N;i++){
    if(i != 0) printf(" ");
    printf("%c%d",S[i].kind,S[i].value);
  }
  if(flag_S==1) printf("\nStable\n");
  else printf("\nNot stable\n");
  
  return 0;
}



Measured memory_bytes: 2140
#include <iostream>
#define llint long long

using namespace std;

llint n;
llint a[10005], b[10005];

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

  cin >> n;
  for(int i = 1; i <= n; i++) cin >> a[i];
  for(int i = 1; i <= n; i++) cin >> b[i];

  llint sum = 0;
  for(int i = 1; i <= n; i++) sum += b[i], sum -= a[i];
  if(sum < 0){
    cout << "No" << endl;
    return 0;
  }

  llint need1 = 0, need2;
  for(int i = 1; i <= n; i++){
    if(a[i] > b[i]) need1 += a[i]-b[i];
    else need2 += (b[i]-a[i]+1)/2;
  }
  if(sum >= max(need1, need2)) cout << "Yes" << endl;
  else cout << "No" << endl;

  return 0;
}


Measured memory_bytes: 384