akhauriyash/Code-Regression huggingface dataset:
#float型を許すな
#numpyはpythonで
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**7)
from collections import Counter, deque
from collections import defaultdict
from itertools import combinations, permutations, accumulate, groupby, product
from bisect import bisect_left,bisect_right
from heapq import heapify, heappop, heappush
from math import floor, ceil,pi,factorial
from operator import itemgetter
def I(): return int(input())
def MI(): return map(int, input().split())
def LI(): return list(map(int, input().split()))
def LI2(): return [int(input()) for i in range(n)]
def MXI(): return [[LI()]for i in range(n)]
def SI(): return input().rstrip()
def printns(x): print('\n'.join(x))
def printni(x): print('\n'.join(list(map(str,x))))
inf = 10**17
mod = 10**9 + 7

n=I()
ans=0
lis=[I() for i in range(n)]
ind =[0 for i in range(n)]
for i in range(n):
    if lis[i]==0:
        ind[i]=-1
    ans+=lis[i]//2
    lis[i]=lis[i]%2
points=[]
for i in range(n):
    if lis[i]==1:
        points.append(i)
#print(points)
#for i in range(len(points)-1):
z=0
while z<len(points)-1:
    x=points[z]
    y=points[z+1]
    count=0
    #print(y)
    #print(x)
    for j in range(x,y+1):
        if ind[j]==0:
            count+=1
    if count==y-x+1:
        z+=1
        ans+=1
    z+=1
print(ans)
    






        
        
    
    
        
    
    


Measured memory_bytes: 87768
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <algorithm>

using namespace std;
typedef long long ll;

ll calc(string s) {
  ll ans = 0;
  string t="";
  for (ll i=0;i<s.size();i++){
    if(s[i]=='+'){
      if(t.size()>0){
        stringstream ss(t);
        ll lt;
        ss>>lt;
        ans += lt;
        t="";
      }
    }else{
      t+=s[i];
    }
  }
  if(t.size()>0){
    stringstream ss(t);
    ll lt;
    ss>>lt;
    ans += lt;
  }
  // cout<<s<<':'<<ans<<endl;
  return ans;
}

ll solve(string s, ll a) {
  ll ans = 0;

  if (a == s.size() - 1) {
    return calc(s);
  }

  ans += solve(s, a + 1);
  string s2 = string(s);
  s2.insert(a + 1, "+");
  ans += solve(s2, a + 2);

  return ans;
}

int main(int argc, char *argv[]) {
  string s;cin>>s;
  ll t = solve(s, 0);
  cout<<t<<endl;
  return 0;
}


Measured memory_bytes: 256
using System;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Collections.Generic;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading;
using static System.Math;
using Debug = System.Diagnostics.Debug;

static class P
{
    static void Main()
    {
        var n = int.Parse(Console.ReadLine());
        var time = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var velocity = Console.ReadLine().Split().Select(int.Parse).ToArray();

        int[] minSpeed = Enumerable.Repeat(int.MaxValue, n + 1).ToArray();
        minSpeed[0] = 0;
        minSpeed[n] = 0;

        for (int i = 1; i < velocity.Length; i++)
            minSpeed[i] = Min(velocity[i - 1], velocity[i]);

        for (int i = 1; i < minSpeed.Length; i++)
        {
            minSpeed[i] = Min(minSpeed[i - 1] + time[i - 1], minSpeed[i]);
        }
        for (int i = minSpeed.Length - 2; i >= 0; i--)
        {
            minSpeed[i] = Min(minSpeed[i + 1] + time[i], minSpeed[i]);
        }
        double res = 0;
        for (int i = 0; i < n; i++)
        {
            var speedLimit = velocity[i];
            var sectionTime = time[i];
            var startSpeed = minSpeed[i];
            var endSpeed = minSpeed[i + 1];

            var topSpeed = Min(speedLimit, startSpeed + (double)((endSpeed + sectionTime) - startSpeed) / 2);
            var topStartTime =  topSpeed - startSpeed;
            var topEndTime = sectionTime - (topSpeed - endSpeed);

            res += (startSpeed + topSpeed) * topStartTime / 2;
            res += topSpeed * (topEndTime - topStartTime);
            res += (endSpeed + topSpeed) * (sectionTime - topEndTime) / 2;
        }
        Console.WriteLine(res);
    }
}


Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
#define sd(x) scanf("%d", &x)
#define sz(v) (int) v.size()
#define pr(v) For(i, 0, sz(v)) {cout<<v[i]<<" ";} cout<<endl;
#define slld(x) scanf("%lld", &x)
#define all(x) x.begin(), x.end()
#define For(i, st, en) for(ll i=st; i<en; i++)
#define tr(x) for(auto it=x.begin(); it!=x.end(); it++)
#define fast std::ios::sync_with_stdio(false);cin.tie(NULL);
#define pb push_back
#define ll long long
#define int long long
#define mp make_pair
#define F first
#define S second
typedef pair<int, int> pii;
#define MOD 1000000007
#define INF 1000000000000000007
#define MAXN 100005

// it's swapnil07 ;)

int dp[1005][1005];
int arr[1004][1004];

signed main(){
    fast    
    #ifdef SWAPNIL07
        freopen("/home/swapnil/Desktop/c++/input.txt","r",stdin);
        freopen("/home/swapnil/Desktop/c++/output.txt","w",stdout);
    #endif
    memset(dp, 0, sizeof(dp));
    memset(arr, 0, sizeof(arr));
    int h, w; cin>>h>>w;
    For(i, 1, h+1){
        For(j, 1, w+1){
            char c; cin>>c;
            if(c=='.') arr[i][j]=1;
            else arr[i][j]=0;
        }
    }
    For(i, 1, h+1){
        For(j, 1, w+1){
            dp[i][j] = dp[i-1][j]+dp[i][j-1];
            if(i==1 && j==1){
                dp[i][j]+=1;
            }
            dp[i][j]*=arr[i][j];
            dp[i][j]%=MOD;
        }
    }
    cout<<dp[h][w];
    return 0;
}

Measured memory_bytes: 16000
#include <iostream>
#include <string>
#include <cmath>
#include<algorithm>
#include<stack>
#include<queue>
#include<map>
#include<set>
#include<iomanip>
#define _USE_MATH_DEFINES
#include <math.h>
#include <functional>
using namespace std;

#define rep(i,x) for(ll i=0;i<x;i++)
#define repn(i,x) for(ll i=1;i<=x;i++)

typedef long long ll;
const ll INF = 1e17;
const ll MOD = 1000000007;
const ll MAX = 1000001;

ll max(ll a, ll b) {
	if (a > b) { return a; }
	return b;
}

ll min(ll a, ll b) {
	if (a > b) { return b; }
	return a;
}

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

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

struct edge {
	ll ind;
	ll fr;
	ll to;
	ll d;
};


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




int main() {

	ll H, W, N;
	cin >> H >> W >> N;

	vector < vector<ll>> ans(H, vector<ll>(W));

	ll s = 0;

	repn(i, N) {
		ll a;
		cin >> a;

		repn(j, a) {
			ll h = s / W;
			ll w;
			if (h % 2 == 0) { w = s % W; }
			else { w = W - 1 - s % W; }
			ans[h][w] = i;
			s++;
		}
	}

	rep(h, H) {
		rep(w, W) {
			cout << ans[h][w]<<" ";
		}
		cout << endl;
	}

	system("PAUSE");

}





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

ll H[6][60];//x1,y1,z1,x2,y2,z2
vector<ll>V[3];

int main() {
	int n, k;
	ll ans = 0;
	scanf("%d%d", &n, &k);
	rep(i, n) {
		rep(j, 6) {
			scanf("%lld", &H[j][i]);
			V[j % 3].push_back(H[j][i]);
		}
	}
	rep(i, 3)
		sort(V[i].begin(), V[i].end());
	rep(i, V[0].size()-1) {
		rep(j, V[1].size()-1) {
			rep(t, V[2].size()-1) {
				ll cnt = 0;
				rep(k, n) {
					if (
						V[0][i] >= H[0][k] && H[3][k] >= V[0][i + 1] &&
						V[1][j] >= H[1][k] && H[4][k] >= V[1][j + 1] &&
						V[2][t] >= H[2][k] && H[5][k] >= V[2][t + 1]
						)
						cnt++;
				}
				if (cnt >= k) 
					ans += (V[0][i + 1] - V[0][i])*(V[1][j + 1] - V[1][j])*(V[2][t + 1] - V[2][t]);
			}
		}
	}
	printf("%lld\n", ans);
	return 0;
}

Measured memory_bytes: 3272
#include<bits/stdc++.h>
using namespace std;
int main(){
    int A,B,C,max=0;
    cin>>A>>B>>C;
    int a=A*10+B+C;
    int b=B*10+A+C;
    int c=C*10+A+B;
    max=a;
    if(max<b)max=b;
    if(max<c)max=c;
    cout<<max<<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

public class Main {

    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int[] a = new int[n];
        for (int i = 0; i < n; i++) {
            a[i] = sc.nextInt();
        }
        sc.close();

        double bunbo = 0;
        for (int i = 0; i < n; i++) {
            bunbo += 1.0 / a[i];
        }
        double ans = 1 / bunbo;
        System.out.println(ans);
    }

}


Measured memory_bytes: 23892
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> pp;
typedef pair<ll,ll> pll;
void read(int& x){ scanf("%d",&x); }
void read(ll& x){ scanf("%lld",&x); }
template<typename T,typename... Args>
void read(T& a,Args&... b){ read(a); read(b...); }
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define x first
#define y second

int n, m;
vector<int> edge[100010];
bool has[100010];

int main()
{
	read(n, m);
	for(;m--;){
        int a, b; read(a, b);
        edge[a].pb(b);
        edge[b].pb(a);
	}
	deque<int> ans;
	ans.pb(1);
	has[1]=1;
	
	while(true){
        int x=ans.back();
        for(int y:edge[x]) if(!has[y]){
            has[y]=1;
            ans.pb(y);
            break;
        }
        if(ans.back() == x) break;
	}
	
	while(true){
        int x=ans.front();
        for(int y:edge[x]) if(!has[y]){
            has[y]=1;
            ans.push_front(y);
            break;
        }
        if(ans.front() == x) break;
	}
	
	printf("%d\n", int(ans.size()));
	for(int x:ans) printf("%d ", x);
    return 0;
}


Measured memory_bytes: 6784
#include<stdio.h>

int b[15][15];

void reset(){
    int i,j;
    for(i=0;i<15;i++){
        for(j=0;j<15;j++){
            b[i][j]=0;
        }
    }
}

void magic_square(int x,int y,int n,int c){
    if(c==n*n)return;
    if(b[x][y]==0){
        b[x][y]=++c;
        if(++x==n)x=0;
        if(++y==n)y=0;
        magic_square(x,y,n,c);
    }else{
        if(++x==n)x=0;
        if(--y==-1)y=n-1;
        magic_square(x,y,n,c);
    }
}

int main(){
    int n,i,j;
    while(scanf("%d",&n),n){
        reset();
        magic_square(n/2+1,n/2,n,0);
        for(i=0;i<n;i++){
            for(j=0;j<n ;j++){
                printf("%4d",b[i][j]);
            }
            puts("");
        }
    }
    return 0;
}

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

// templates -------------------------------------

#define ULL unsigned long long
#define LL long long
#define LLD long long double
#define REP(i, n) for(LL i = 0; i < n; i++)
#define INV_REP(i, n) for(LL i = n; 0 <= i; i--)

LL combination(LL n, LL m)
{
  LL nume = 1;
  REP(i, m) nume *= (n-i);
  LL demo = 1;
  for(int i = 1; i <= m; i++) demo *= i;
  return nume / demo;
}

template<class T>
class UnionFind
{
private:
  vector<T> par;
  vector<T> rank;
  vector<T> size;

public:
  UnionFind(T N) :
    par(N, T()), rank(N, T()), size(N, T())
  {
    REP(i, N)
    {
      par[i] = i;
      rank[i] = 0;
      size[i] = 1;
    }
  }

  inline T root(T x)
  {
    return par[x] == x ? x : par[x] = root(par[x]);
  }

  inline bool same(T x, T y)
  {
    return root(x) == root(y);
  }

  inline T getSize(T x)
  {
    return size[root(x)];
  }

  void unite(T x, T y)
  {
    T r1 = root(x);
    T r2 = root(y);
    if(r1 == r2) return;

    if(rank[r1] < rank[r2]) swap(r1, r2);
    if(rank[r1] == rank[r2]) rank[r1]++;
    par[r2] = r1;
    size[r1] += size[r2];
  }
};

// --------------------------------------

int a, b;

void input()
{
  cin >>a >> b;
}

void solve()
{
  if(13 <= a)
  {
    cout << b;
  }
  else if(6 <= a)
  {
    cout << b/2;
  }
  else cout << 0;
}

int main()
{
  input();
  solve();
  return 0;
}

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

int main() {
    int A, B, C, K;
    cin >> A >> B >> C >> K;
    int ans = A + B + C - max({A, B, C});
    int tmp = max({A,B,C});
    for (int i = 0; i < K; i++){
        tmp *= 2;
    }
    cout << ans + tmp << endl;
}


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

#define REP(i, n) for (ll (i) = 0 ; (i) < (ll)(n) ; ++(i))
#define REPN(i, m, n) for (ll (i) = m ; (i) < (ll)(n) ; ++(i))
#define REP_REV(i, n) for (ll (i) = (ll)(n) - 1 ; (i) >= 0 ; --(i))
#define REPN_REV(i, m, n) for (ll (i) = (ll)(n) - 1 ; (i) >= m ; --(i))

#define INF 2e9
#define INF_LL 1LL<<60
#define ll long long

#define MAX_V 105

typedef pair<int, int> P; 
bool kimari[3];
int suuji[3];

int main(){
    int a, b, m;
    cin >> a >> b >> m;
    vector<int> reizo(a), re(a);
    vector<int> renji(b), ren(b);

    REP(i, a) {
        cin >> reizo[i];
        re[i] = reizo[i];
    }
    REP(i, b) {
        cin >> renji[i];
        ren[i] = renji[i];
    }

    sort(re.begin(), re.end());
    sort(ren.begin(), ren.end());

    int ans = re[0] + ren[0];

    REP(i, m) {
        int x, y, c;
        cin >> x >> y >> c;
        x--, y--;
        ans = min(reizo[x] + renji[y] - c, ans);
    }

    cout << ans << endl;


    return 0;
}


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

int main() {
	int N;
	cin >> N;
	string str = to_string(N);
	char f = str[0];
	bool shift = false;
	for (int i = 0; i < str.length(); i++) {
		if (f < str[i]) {
			if (f == '9') {
				shift == true;
			}
			else {
				f++;
			}
			break;
		}
	}

	if (shift) {
		for (int i = 0; i < str.length() + 1; i++) {
			cout << 1;
		}
	}
	else {
		for (int i = 0; i < str.length(); i++) {
			cout << f;
		}
	}

	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
 
int main(){

	int N;
	double R=0;
	cin >> N;
	vector<double> V(N);
	for (int i=0; i<N; i++){
		cin >> V.at(i);
	}
	
	sort(V.begin(),V.end());
	
	R =V.at(0);
	
	for (int i=1; i<N; i++){
		R = (R+V.at(i))/2;
	}

	 cout << R << endl;
}	

Measured memory_bytes: 256
n=int(input())
a=[int(i) for i in input().split()]
nC2=[0 for i in range(n+1)]
for i in range(2,n+1):
    nC2[i]=i*(i-1)//2
cnt=[0 for i in range(n)]
for i in a:
    cnt[i-1]+=1
res=0
for i in cnt:
    res+=nC2[i]
for i in a:
    print(res-nC2[cnt[i-1]]+nC2[cnt[i-1]-1])

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

using ll = long long int;

const int MAX = (int)(1e5 + 5);
const ll INF = (ll)(1e10 + 5);

int al[5];

int main(void) {
  // Here your code !
  scanf("%d %d %d", &(al[0]), &(al[1]), &(al[2]));

  sort(al, al + 3);

  printf("%d\n", al[0] + al[1]);

  return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<cstdio>
#include<cstring>
#include<cmath>
using namespace std;
int main(){
	int h,n,a,ans=0; 
	cin>>h>>n;
	for(int i=1;i<=n;i++){
		cin>>a;
	    ans=ans+a;
	}
	if(ans>=h){
	cout<<"Yes";}else{
	cout<<"No";}
}

Measured memory_bytes: 3648
def dfs(i, f, sum):
  if i == 3:
    if sum == 7:
      print(f + '=7')
      exit()
      
  else:
    dfs(i+1, f + '-' + n[i+1], sum-int(n[i+1]))
    dfs(i+1, f + '+' + n[i+1], sum+int(n[i+1]))
    
n = input()
dfs(0, n[0], int(n[0]))


Measured memory_bytes: 9084
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstring>
#include <cmath>
#include <limits>
#include <stack>
#include <queue>
#include <map>

using namespace std;

using ll = long long;
using ui = unsigned int;
const ll MOD = 1000000007;
const ll INF = 9223372036854775807;


//A
int main() {
	ll A;
	scanf("%lld", &A);
	ll B;
	scanf("%lld", &B);

	ll result = 0;

	result = max(0LL, A - B * 2);

	printf("%lld\n", result);

	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <iomanip>
#include <vector>
#include <queue>
#include <set>
#include <map>

using namespace std;
typedef long long ll;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    cout << setprecision(10) << fixed;
    int d, s, t; cin >> d >> s >> t;
    if(d > s*t){
        cout << "No" << endl;
    }else{
        cout << "Yes" << endl;
    }
}

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

#define INF 10000000000
using namespace std;
typedef long long ll;
typedef pair<int,int> P;

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

	ll n,m; cin >> n >> m;
	ll d[1003];
	ll c[1003];

	d[0] = c[0] = 0;

	for (int i = 0;i < n;i++){
		cin >> d[i];
	}
	for (int i = 0;i < m;i++){
		cin >> c[i];
	}

	ll dp[1003][1003]; //日数, 場所
	for (int i = 0;i <= m;i++){
		for (int j = 0;j <= n;j++){
			dp[i][j] = INF;
		}
	}

	dp[0][0] = 0;

	for (int i = 0;i <= m;i++){
		for (int j = 0;j <= n;j++){
			if(dp[i][j] == INF) continue;
			dp[i+1][j] = min(dp[i+1][j],dp[i][j]);
			if(i < m && j < n){
				ll cost = d[j] * c[i];
				dp[i+1][j+1] = min(dp[i+1][j+1],dp[i][j]+cost);
			}
		}
	}

	cout << dp[m][n] << endl;

	return 0;

}



Measured memory_bytes: 11020
#include<iostream>
#include<cstdio>
#include<algorithm>
#include<vector>
using namespace std;
int n, a[10000], T[10000];
int main() {
	cin >> n; for (int i = 0; i < n; i++)cin >> a[i];
	sort(a, a + n);
	long double maxn = 0;
	for (int i = 0; i < n; i++) {
		for (int j = i + 1; j < n; j++) {
			T[i] = 1; T[j] = 1;
			vector<int>vec;
			for (int k = n - 1; k >= 0; k--) {
				if (T[k] == 0)vec.push_back(a[k]);
				if (vec.size() == 2)break;
			}
			maxn = max(maxn, 1.0l*(vec[0] + vec[1]) / (a[j] - a[i]));
			T[i] = 0; T[j] = 0;
		}
	}
	printf("%.15Lf\n", maxn);
	return 0;
}

Measured memory_bytes: 3236
#include<bits/stdc++.h>
using namespace std;
#define inf 2123333333

struct node { int t,v,op,next; }a[2000010];

int sum1[100010],sum2[100010];
int head[200010],level[200010],cur[200010],P[100010],Q[100010],from1[100010],from2[100010],n,t1,t2,vs,vt,tot;
bool vis[200010];

inline int rd()
{
	int x=0;char ch=getchar();
	for (;ch<'0'||ch>'9';ch=getchar());
	for (;ch>='0'&&ch<='9';ch=getchar()) x=x*10+ch-'0';
	return x;
}

inline void add(int x,int y,int z)
{
	a[++tot].t=y;a[tot].v=z;a[tot].op=tot+1;a[tot].next=head[x];head[x]=tot;
	a[++tot].t=x;a[tot].v=0;a[tot].op=tot-1;a[tot].next=head[y];head[y]=tot;
}

queue<int> q;

inline bool bfs()
{
	while (!q.empty()) q.pop();
	for (int i=vs;i<=vt;i++) level[i]=0;
	q.push(vs);level[vs]=1;cur[vs]=head[vs];
	while (!q.empty())
	{
		int x=q.front();q.pop();
		for (int i=head[x];i;i=a[i].next) if (a[i].v)
		{
			int t=a[i].t;
			if (level[t]) continue;
			level[t]=level[x]+1;cur[t]=head[t];
			if (t==vt) return true;
			q.push(t);
		}
	}
	return false;
}

inline int dfs(int x,int y)
{
	if (x==vt||!y) return y;
	int res=0;
	for (int &i=cur[x];i;i=a[i].next) if (a[i].v)
	{
		int t=a[i].t;
		if (level[t]!=level[x]+1) continue;
		int hh=dfs(t,min(y,a[i].v));
		if (!hh) continue;
		res+=hh;y-=hh;
		a[i].v-=hh;a[a[i].op].v+=hh;
		if (!y) break;
	}
	return res;
}

int main()
{
	n=rd();tot=0;
	for (int i=1;i<=n;i++) P[i]=rd()+1;
	for (int i=1;i<=n;i++) Q[i]=rd()+1;
	for (int i=1;i<=n;i++) if (!vis[i])
	{
		if (P[i]==i) continue;
		t1++;
		for (int j=i;!vis[j];j=P[j])
		{
			vis[j]=true;from1[j]=t1;
			if (Q[j]==j) sum1[t1]++;
		}
	}
	memset(vis,false,sizeof(vis));
	for (int i=1;i<=n;i++) if (!vis[i])
	{
		if (Q[i]==i) continue;
		t2++;
		for (int j=i;!vis[j];j=Q[j])
		{
			vis[j]=true;from2[j]=t2;
			if (P[j]==j) sum2[t2]++;
		}
	}
	vs=0;vt=t1+t2+1;
	for (int i=1;i<=t1;i++) if (sum1[i]) add(vs,i,sum1[i]);
	for (int i=1;i<=t2;i++) if (sum2[i]) add(t1+i,vt,sum2[i]);
	for (int i=1;i<=n;i++) if (P[i]!=i&&Q[i]!=i) add(t1+from2[i],from1[i],1);
	for (int i=1;i<=n;i++) if (P[i]!=i&&Q[i]!=i&&P[i]==Q[i]) add(from1[i],t1+from2[i],1);
	int ans=n;
	for (int i=1;i<=n;i++) if (P[i]==i&&Q[i]==i) ans--;
	while (bfs()) ans-=dfs(vs,inf);
	printf("%d\n",ans);
	return 0;
}

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

int main(){
	int H, W, M; 
	scanf("%d %d %d", &H, &W, &M);
	vector<int> tate(H, 0), yoko(W, 0);
	map<P, int> MAP;
	for(int i = 0; i < M; i++){
		int x, y; scanf("%d %d", &x, &y);
		--x; --y;
		MAP[P(x, y)]++;
		tate[x]++;
		yoko[y]++;
	} 

	auto tate1 = tate, yoko1 = yoko;
    sort(tate.begin(), tate.end(), greater<int>());
	sort(yoko.begin(), yoko.end(), greater<int>());
	int ans = tate[0] + yoko[0];
	int cnt = count(tate.begin(), tate.end(), tate[0]) * count(yoko.begin(), yoko.end(), yoko[0]);
	int cnt1 = 0;

	for(auto key : MAP){
		int x = key.first.first, y = key.first.second;
		if(tate1[x] + yoko1[y] == ans) cnt1++;
	}
	if(cnt == cnt1) ans--;
	printf("%d\n", ans);
}

Measured memory_bytes: 26784
#if __has_include("../library/Basic/Debug.hpp")

#include "../library/Basic/Debug.hpp"

#else

/* ----- Header Files ----- */
// IO
#include <cstdio>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm
#include <algorithm>
#include <cmath>
#include <numeric>

// container
#include <vector>
#include <array>
#include <string>
#include <tuple>
#include <complex>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>

// others
#include <random>
#include <limits>
#include <functional>
#include <ctime>
#include <cassert>
#include <cstdint>

/* ----- Type Alias ----- */
using lint = long long int;
using Real = long double;
template <class T>
using MaxHeap = std::priority_queue<T>;
template <class T>
using MinHeap = std::priority_queue<T, std::vector<T>, std::greater<T>>;

template <class T>
T ndvec(T v) { return v; }

template <class T, class... Ts>
auto ndvec(size_t l, Ts... ts) {
    return std::vector<decltype(ndvec<T>(ts...))>(l, ndvec<T>(ts...));
}

template <class Cost = int>
struct Edge {
    int src, dst;
    Cost cost;
    Edge(int src = -1, int dst = -1, Cost cost = 1)
        : src(src), dst(dst), cost(cost){};

    bool operator<(const Edge<Cost>& e) const { return this->cost < e.cost; }
    bool operator>(const Edge<Cost>& e) const { return this->cost > e.cost; }
};

template <class Cost = int>
using Edges = std::vector<Edge<Cost>>;
template <class Cost = int>
using Graph = std::vector<std::vector<Edge<Cost>>>;

#endif

/* ----- Misc ----- */
void fastio() {
    std::ios::sync_with_stdio(false);
    std::cin.tie(nullptr);
}

struct Fout {
    int precision;
    explicit Fout(int precision) : precision(precision) {}
};

std::ostream& operator<<(std::ostream& os, const Fout& fio) {
    os << std::fixed << std::setprecision(fio.precision);
    return os;
}

/* ----- Constants ----- */
// constexpr Int INF = std::numeric_limits<Int>::max() / 3;
// constexpr Int MOD = 1000000007;
const Real PI = acos(-1);
// constexpr Real EPS = 1e-10;
// std::mt19937 mt(int(std::time(nullptr)));

int main() {
    Real a, b, x;
    std::cin >> a >> b >> x;
    Real ans = std::atan(2 * (a * a * b - x) / (a * a * a));

    if (ans > std::atan(b / a)) {
        ans = PI / 2 - std::atan(2 * x / (a * b * b));
    }
    std::cout << Fout(20)
              << ans / PI * 180
              << std::endl;
    return 0;
}


Measured memory_bytes: 256
#include <iostream>

using namespace std;

int main() {
  int H, W;
  cin >> H >> W;
  while (H != 0 && W != 0) {
    for (int i = 0; i < H; i++) {
      for (int j = 0; j < W; j++) {
        if (i == 0 || i == H - 1) {
          cout << "#";
        } else if (j == 0 || j == W - 1) {
          cout << "#";
        } else {
          cout << ".";
        }
      }
      cout << endl;
    }
    cin >> H >> W;
    cout << endl;
  }
  return 0;
}


Measured memory_bytes: 3056
#include<bits/stdc++.h>
using namespace std;
#define int long long
#define vi vector<int>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define pi 3.141592653589793238
#define eb emplace_back
#define rep(i,a,b) for (int i = a; i <= b; i++)
#define zip(i,a,b) for(int i=a;i<b;i++)
#define rzip(i,a,b) for(int i=a;i>=b;i--)
#define ll unsigned int
#define test int t;cin>>t; while(t--)
#define um unordered_map
#define en '\n'
#define us unordered_set
typedef pair<int, int>     pii;
typedef pair<char, int>    pci;
typedef pair<char, char>   pcc;
typedef vector<pii>       vii;
typedef long double ld;
#define all(v) v.begin(), v.end()
#define sz(x) (int)x.size()
#define INF (1e18+5)
#define inf (1e9+5)
#define mod 1000000007


void __print(int x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}
// You should only debug a pair of simple data types. For example,
// the debug won't work if one of pair's elements is collection type
// (std::vector, std::map, std::set...).
template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i : x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifndef ONLINE_JUDGE
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif


// bool check_prime(int n)  return whether a number is prime or not O(sqrt(N));
// int BE(int x,int n,int m)  return x^n%m; O(logN);
// void sieve()  from number 1-1000001 saare prime store kar lega  in bool is_prime[1000001] array
// vector<int> z_array(string s)  return vector which is Z-array of string s;
// vector<int> lps(string s)      return vector which is lps array of string s;
// int power(int x,int n) return x^n; O(logN);
// using_ordered_set (template for using ordered set , replace first 2 lines of this page with this code..);


int32_t main()
{
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(0);
#ifndef ONLINE_JUDGE
	if (fopen("input.txt", "r"))
	{
		freopen ("input.txt" , "r" , stdin);
		freopen ("output.txt" , "w" , stdout);
	}
#endif
	//_______________________________-code starts-_______________________________________________

	int x, k, d;
	cin >> x >> k >> d;
	if (abs(x) / d >= k)
	{
		cout << abs(abs(x) - k * d) << en;
	}
	else
	{
		int x1 = abs(x);
		k -= x1 / d;
		int pos = x1 % d;
		if (k % 2 == 0)
			cout << pos << en;
		else
			cout << abs(d - pos) << en;
	}
	return 0;
}




Measured memory_bytes: 3652
#include<iostream>
#include<sstream>
#include<algorithm>
#include<climits>
#include<cmath>
#include<cstdio>
#include<cstdlib>
#include<ctime>
#include<cfloat>
#include<functional>
#include<map>
#include<string>
#include<cstring>
#include<vector>
#include<queue>
#include<stack>
#include<deque>
#include<set>
#include<bitset>
#include<list>
#include<numeric>
#include<complex>

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int, int> i_i;
typedef pair<long long, int> ll_i;
typedef pair<double, int> d_i;
typedef pair<long long, long long> ll_ll;
typedef pair<double, double> d_d;
typedef vector<int> Vint;

#define PI 3.141592653589793238462643383279
#define mod 1000000007LL
#define rep(i, n) for(i = 0;i < n;++i)
#define rep1(i, n) for(i = 1;i < n;++i)
#define rep2d(i, j, n) for(i = 0;i < n;++i)for(j = i + 1;j < n;++j)
#define per(i, n) for(i = n - 1;i > -1;--i)
#define int(x) int x; scanf("%d",&x)
#define int2(x, y) int x, y; scanf("%d%d",&x, &y)
#define int3(x, y, z) int x, y, z; scanf("%d%d%d",&x, &y, &z)
#define int4(v, x, y, z) int v, x, y, z; scanf("%d%d%d%d", &v, &x, &y, &z)
#define int5(v, w, x, y, z) int v, w, x, y, z; scanf("%d%d%d%d%d", &v, &w, &x, &y, &z)
#define scn(n, a) rep(i, n)cin >> a[i]
#define sc2n(n, a, b) rep(i, n)cin >> a[i] >> b[i]
#define pri(x) cout << x << "\n"
#define pri2(x, y) cout << x << " " << y << "\n"
#define pri3(x, y, z) cout << x << " " << y << " " << z << "\n"
#define pb push_back
#define mp make_pair
#define all(a) (a).begin(),(a).end()
#define endl "\n"
#define kabe puts("---------------------------")
#define kara puts("")
#define debug(x) cout << " --- " << x << "\n"
#define debug2(x, y) cout << " --- " << x << " " << y << "\n"
#define debug3(x, y, z) cout << " --- " << x << " " << y << " " << z << "\n"
#define X first
#define Y second
#define eps 0.0001
#define prid(x) printf("%.15lf\n", x)

string s;
bool judge(string t){
  int i, j, k;
  rep1(i, t.size()){
    rep(j, t.size()){
      int sp = j;
      rep(k, s.size()){
        if(sp >= t.size())break;
        if(s[k] == t[sp])sp += i;
        else break;
      }
      if(k == s.size())return true;
    }
  }
  return false;
}

signed main(void){
  int i, j, k;
  for(int testcase = 0;testcase < 1234567;testcase++){
    int(n);
    cin >> s;
    int res = 0;
    for(;n--;){
      string t; cin >> t;
      if(judge(t))res++;
    }
    pri(res);

/*/

//*/ break;
  }
  return 0;
}

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

#define rep(i, a, n)  for(ll i=a; i<n; i++)
#define per(i, a, n)  for(ll i=n-1; i>=a; i--)
#define fill0(n)  setfill('0') << right << setw(n)
#define all(x)  (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define LONGMAX 1e18
#define INTMAX 1000000000
using namespace std;
typedef long long ll;
typedef pair<int,int> p;

int n;
int a[200];
int colors[9];

int main(){
  cin >> n;
  rep(i,0,n){
    cin >>a[i];
    if(a[i]>=3200)colors[8]++;
    else colors[a[i]/400]++;
  }
  int min = 0;
  rep(i,0,8){
    if(colors[i]!=0)min++;
  }
  int max;
  max = min + colors[8];
  if(colors[8]==n){
    min=1;max = n;
  }
  cout << min << ' ' << max << endl;

}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int N=100010;
int i,j,k,n,m,x,y,t;
int a[N],b[N];
int main(){
	scanf("%d%d",&n,&m);
	a[1]=1;for (i=1;i<=n;i++)b[i]=1;
	while (m--){
		scanf("%d%d",&x,&y);
		b[x]--;b[y]++;
		if (a[x])a[y]=1;
		if (!b[x])a[x]=0;
	}
	int ans=0;for (i=1;i<=n;i++)ans+=a[i];
	printf("%d\n",ans);
	return 0;
}

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

int main() {
  
  int n,m;
  cin >>n >>m;
  
  vector<int> start(m);
  vector<int> goal(m);
  
  for(int i;i<m;i++){
    cin >> start.at(i) >> goal.at(i);
  }
  
  for(int i = 1; i <= n; i++){
    int counter = 0;
    for(int j = 0; j<m; j++){
      if(start.at(j) == i || goal.at(j) == i){
        counter++;
      }
    }
    cout << counter << endl;
  }
  
}

Measured memory_bytes: 256
#include "bits/stdc++.h"
#define rep(i,n) for(int i = 0; i < (n); ++i)
using namespace std;
typedef long long int ll;
typedef pair<int, int> P;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n;
    cin >> n;
    set<string> se;
    rep(i,n){
        string s;
        cin >> s;
        se.insert(s);
    }
    cout << se.size() << endl;
	return 0;
}

Measured memory_bytes: 19288
#include<bits/stdc++.h>
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define rep2(i, m, n) for(int i = (int)(m); i < (int)(n); i++)
#define rep_inv(i, n, m) for(int i = (int)(n); i > (int)(m); i--)
using namespace std;
using ll = long long;
using vl = vector<ll>;
using vc = vector<char>;
using vvl = vector<vl>;
using vvc = vector<vc>;
using pll = pair<ll, ll>;
using vpll = vector<pll>;

bool even(string s){
  if(s.size() % 2 == 1){
    return false;
  }

  ll n = s.size() / 2;

  rep(i, n){
    if(s[i] != s[i + n]){
      return false;
    }
  }

  return true;
}

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

  S = S.substr(0, S.size() - 2);

  while(true){
    if(even(S)){
      cout << S.size() << endl;
      return 0;
    }

    S = S.substr(0, S.size() - 2);
  }
  
  return 0;
}


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

int main() {
  int a, b, c;
  cin >> a >> b >> c;

  if ((a == b && a != c) || (a == c && a != b) || (b == c && a != b)) cout << "Yes" << endl;
  else cout << "No" << endl;
  return 0;
}

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

using ll = long long;
using ii = pair<int, int>;

const int maxn = 1e3 + 3;
const int mod = 1e9 + 7;

inline int mul() { return 1; }
template <typename T, typename... V>
inline T mul(T a, V... v) {
#if !defined(_WIN32) || defined(_WIN64)
	return (int) ((long long) a * mul(v...) % mod);
#endif
	unsigned long long x = (long long) a * mul(v...);
	unsigned xh = (unsigned) (x >> 32), xl = (unsigned) x, d, m;
	asm(
		"divl %4; \n\t"
		: "=a" (d), "=d" (m)
		: "d" (xh), "a" (xl), "r" (mod)
	);
	return m;
}

int n, k;
int a[maxn];
int C[maxn][maxn];
int dp[21][maxn];

int main(int argc, char const *argv[])
{
#ifdef LOCAL
	freopen("in", "r", stdin);
#endif
	for(int i = 0; i < maxn; i++) {
		C[i][i] = C[i][0] = 1;
	}
	for(int i = 1; i < maxn; i++) {
		for(int j = 1; j < i; j++) {
			C[i][j] = C[i-1][j] + C[i-1][j-1];
			if(C[i][j] >= mod) C[i][j] -= mod;
		}
	}
	cin >> n >> k;
	for(int i = 1; i <= k; i++) {
		cin >> a[i];
	}
	dp[0][0] = 1;
	for(int i = 1; i <= k; i++) {
		dp[i][0] = mul(dp[i-1][0], C[n][a[i]]);
		for(int j = 1; j <= n; j++) {
			for(int tek = 0; tek <= j and tek <= a[i]; tek++) {
				dp[i][j] += mul(dp[i-1][j-tek], C[j][tek], C[n-tek][a[i]-tek]);
				if(dp[i][j] >= mod) dp[i][j] -= mod;
			}
		}
	}
	cout << dp[k][n] << endl;
	return 0;
}

Measured memory_bytes: 4224
#include<iostream>
#include<cstdio>
#define MAX 10000
#define MMIINN -2000000200
using namespace std;
typedef long long ll;

class Heap{
public:
  int index;
  ll HeapArray[MAX+1];

  Heap(){
    index=0;
    for(int i=0;i<=MAX;i++)HeapArray[i]=MMIINN;
  }

  void insert(ll v){
    index++;
    HeapArray[index]=v;
  }

  ll getValue(int i){
    return HeapArray[i];
  }

  ll getParent(int i){
    return HeapArray[i/2];
  }

  ll getLeft(int i){
    return HeapArray[2*i];
  }

  ll getRight(int i){
    return HeapArray[2*i+1];
  }



};


int main(){
  int n;
  ll val;
  Heap H;
  cin >> n;
  for(int i=0;i<n;i++){
    cin >> val;
    H.insert(val);
  }

  for(int i=1;i<=n;i++){
    printf("node %d: key = %lld, ",i,H.getValue(i));
    if(i != 1)printf("parent key = %lld, ",H.getParent(i));
    if(H.getLeft(i) != MMIINN)printf("left key = %lld, ",H.getLeft(i));
    if(H.getRight(i) != MMIINN)printf("right key = %lld, ",H.getRight(i));
    printf("\n");
  }



  return 0;
}


Measured memory_bytes: 3296
//abc146_e.cpp
//Sun Dec  8 17:44:54 2019

#include <iostream>
#include <string>
#include <queue>
#include <map>
#include <unordered_map>
#include <vector>
#include <algorithm>
#include <math.h>
#include <set>
#define INTINF 2147483647
#define LLINF 9223372036854775807
using namespace std;
using ll=long long;
typedef pair<int,int> P;

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

	ll sum[n+1];
	sum[0] = 0;
	ll ans = 0;
	unordered_map<ll, ll> mp;
	mp[0]++;
	for (int i=1;i<=n;i++){
		ll temp;
		cin >> temp;
		temp = (temp-1+k)%k;
		sum[i] = (sum[i-1]+temp)%k;
		ans += mp[sum[i]];
//		cout << i << " " << ans << endl;
		mp[sum[i]]++;
		if (i-k+1>=0){
			mp[sum[i-k+1]]--;
		}
	}

	if (k==1){
		cout << 0 << endl;
		return 0;
	}

	cout << ans << endl;
//	printf("%.4f\n",ans);
}

Measured memory_bytes: 10056
#coding utf-8
N,K=map(int,input().split())
ans=[0 for i in range(K+1)]
M=N-K
p=10**9+7
  
def comb(n,k,p):
  """power_funcを用いて(nCk) mod p を求める"""
  from math import factorial
  if n<0 or k<0 or n<k: return 0
  if n==0 or k==0: return 1
  a=factorial(n) %p
  b=factorial(k) %p
  c=factorial(n-k) %p
  return (a*power_func(b,p-2,p)*power_func(c,p-2,p))%p
def power_func(a,b,p):
  """a^b mod p を求める"""
  if b==0: return 1
  if b%2==0:
    d=power_func(a,b//2,p)
    return d*d %p
  if b%2==1:
    return (a*power_func(a,b-1,p ))%p


  
for i in range(1,K+1):
  ans[i]=(comb(M+1,i,p)*comb(K-1,i-1,p))%p

for i in range(1,K+1):
  print(ans[i])

Measured memory_bytes: 3444
//#include<bits/stdc++.h>
#include<cstdio>
#include<cstdlib>
#include<iostream>
#include<algorithm>
#include<vector>
#include<stack>
#include<queue>
#include<set>
#include<string>
#include<cmath>
#include<cassert>
#include<map>
  using namespace std;

typedef long long ll;
typedef ll int__;
#define rep(i,j) for(int__ (i)=0;(i)<(j);(i)++)
#define repeat(i,j,k) for(int__ i=(j);i<(k);(i)++)
#define all(v) begin(v),end(v)


int main()
{

  while(true){
    int n,m;
    cin>>n>>m;
    if(n==0 and m==0)break;
    vector<int > s(n),t(m);
    int s_s=0,t_s=0;
    rep(i,n){
      cin>>s[i];
      s_s+=s[i];
    }
    rep(i,m){
     cin>>t[i];
     t_s+=t[i];
    }

    int ans_s,ans_t;
    bool flg=false;
    rep(i,n){
      rep(j,m){
        if(s_s-s[i]+t[j] == t_s-t[j]+s[i]){
          if(!flg){
            ans_s=s[i];ans_t=t[j];
            flg=true;
          }
          else{
            if(ans_s+ans_t>s[i]+t[j]){
              ans_s=s[i];ans_t=t[j];
            }
          }
        }
      }
      
    }
    if(flg)cout<<ans_s<<" "<<ans_t<<endl;
    else cout<<-1<<endl;
  }
  
  return 0;
}

Measured memory_bytes: 1196
import java.io.BufferedReader;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Random;
import java.util.StringTokenizer;
 
public class Main {
	
	public static void main(String[] args) {
		FastReader scan = new FastReader();
		PrintWriter out = new PrintWriter(System.out);
		Task solver = new Task();
		int t = 1;
		while(t-->0) solver.solve(1, scan, out);
		out.close();
	}
	
	static class Task {
		public void solve(int testNumber, FastReader scan, PrintWriter out) {
			int n = scan.nextInt();
			int[] b = new int[n-1];
			for(int i = 0; i < n-1; i++) b[i] = scan.nextInt();
			int[] res = new int[n];
			for(int i = 0; i < n-1; i++) {
				res[i+1] = res[i] = b[i];
				if(i > 0) res[i] = Math.min(b[i], b[i-1]);
			}
			long t = 0;
			for(int i : res) t += i;
			out.println(t);
		}
		
	}
	
	static void shuffle(int[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			int temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	
	static void shuffle(long[] a) {
		Random get = new Random();
		for(int i = 0; i < a.length; i++) {
			int r = get.nextInt(a.length);
			long temp = a[i];
			a[i] = a[r];
			a[r] = temp;
		}
	}
	
 
	static class FastReader {
		BufferedReader br;
		StringTokenizer st;
 
		public FastReader() {
			br = new BufferedReader(new InputStreamReader(System.in));
		}
		public FastReader(String s) throws FileNotFoundException {
			br = new BufferedReader(new FileReader(new File(s)));
		}
 
		String next() {
			while (st == null || !st.hasMoreElements()) {
				try {
					st = new StringTokenizer(br.readLine());
				} catch (IOException e) {
					e.printStackTrace();
				}
			}
			return st.nextToken();
		}
 
		int nextInt() {
			return Integer.parseInt(next());
		}
 
		long nextLong() {
			return Long.parseLong(next());
		}
 
		double nextDouble() {
			return Double.parseDouble(next());
		}
 
		String nextLine() {
			String str = "";
			try {
				str = br.readLine();
			} catch (IOException e) {
				e.printStackTrace();
			}
			return str;
		}
	}
 
}

Measured memory_bytes: 23380
#include <iostream>

using namespace std;

long kouyakusuu(long x, long y) {
  if (x % y == 0) return y;
  else return kouyakusuu(y, x % y);
}

int main(void) {
  long N, X;
  cin >> N >> X;

  long x;
  long ans;
  long dist;

  cin >> x;
  ans = abs(x - X);

  for (long i = 1; i < N; i++) {
    cin >> x;
    dist = abs(x - X);
    ans = kouyakusuu(ans, dist);
  }

  cout << ans << endl;
}


Measured memory_bytes: 764
#include<bits/stdc++.h>
#define all(v) (v).begin(),(v).end()
#define pb push_back
#define ppb pop_back
#define mp make_pair
#define ri(x) scanf("%d",&(x))
#define ri2(x,y) scanf("%d %d",&(x),&(y))
#define ri3(x,y,z) scanf("%d %d %d",&(x),&(y),&(z))
#define rll(x) scanf("%lld",&(x))
#define rll2(x,y) scanf("%lld %lld",&(x),&(y))
#define rll3(x,y,z) scanf("%lld %lld %lld",&(x),&(y),&(z))
#define gc(x) ((x) = getchar())
using namespace::std;

const long double PI = acos(-1);
const long long MOD = 1000000000 +7;

typedef long long ll;
typedef pair<ll,ll> pll;
typedef pair<ll,pll> tll;
typedef pair<int,int> ii;
typedef pair<int,ii> iii;
typedef vector<int> vi;
typedef vector<ii> vii;
typedef vector<iii> viii;
typedef vector<ll> vll;
typedef vector<pll> vpll;
typedef vector<tll> vtll;
typedef vector<string> vs;
typedef set<int> si;
typedef set<ii> sii;
typedef set<iii> siii;

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

ll add(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a+b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll mul(ll a, ll b, ll m = MOD){
	if(a >= m) a %= m;
	if(b >= m) b %= m;
	if(a < 0) a += m;
	if(b < 0) b += m;
	ll res = a*b;
	if(res >= m or res <= -m) res %= m;
	if(res < 0) res += m;
	return res;
}

ll pow_mod(ll a, ll b, ll m = MOD){
	ll res = 1LL;
	a = a%m;
	while(b){
		if(b&1) res = mul(res,a,m);
		b >>= 1;
		a = mul(a,a,m);
	}
	return res;
}

ll fastexp(ll a, ll b){
	ll res = 1LL;
	while(b){
		if(b&1) res = res*a;
		b >>= 1;
		a *= a;
	}
	return res;
}

int gcdExtendido(int a, int b, int *x, int *y){
	if(a == 0){
		*x = 0;
		*y = 1;
		return b;
	}
	int x1, y1;
	int gcd = gcdExtendido(b%a,a,&x1,&y1);
	
	*x = y1-(b/a)*x1;
	*y = x1;
	return gcd;
}

int modInverso(int a, int m){
	int x, y;
	int g = gcdExtendido(a,m,&x,&y);
	if(g!=1) return -1;
	else return (x%m + m)%m;
}

/****************************************
*************P*L*A*N*T*I*L*L*A************
*****************************************/

string s;

int main(){
	cin >> s;
	if(s[2] == s[3] and s[4] == s[5]) puts("Yes");
	else puts("No");
	return 0;
}


Measured memory_bytes: 764
/* #                          */

#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <string>
#include <deque>
#include <map>
#include <iomanip>
#include <functional>
#include <cassert>
#include <cstdio>
#include <cmath>
#include <cstdint>
#include <cstring>
//#pragma warning(disable:4996)

using namespace std;


/** Type Define **/
typedef long long int           ll;
typedef pair<int, int>          pii;
typedef pair<ll, ll>            pll;
typedef vector<string>          vs;
typedef vector<bool>            vb;
typedef vector<int>             vi;
typedef vector<long long>		vl;
typedef vector<vi>              vvi;
typedef vector<vl>				vvl;
typedef vector<char>            vch;
#define		it(x)  x.begin() 
#define		all(x)  x.begin(), x.end()
#define		pb(x)   push_back(x)
constexpr int           inf = 0x3f3f3f3f;
constexpr long long 	INF = 9123456789123456789;
constexpr long long     MOD = 1000000007LL;
/*************************************************/
void sol() {
    int L; cin >> L;
    double x = double(L) / 3.0;
    double ans = x * x * x;
    cout << ans << endl;
}

int main() {
    ios_base::sync_with_stdio(false);
    cout << fixed << setprecision(12);
    cin.tie(nullptr);
    int T(1);
    while (T--)
        sol();


    return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
	public static void main(String[] args){
		Scanner sc=new Scanner(System.in);
		HashMap<Integer,Integer> mp=new HashMap<Integer,Integer>();
		int n=sc.nextInt();
		int a[]=new int[n];
		for(int i=0;i<n;i++){
			a[i]=sc.nextInt();
			if(mp.get(a[i])==null)mp.put(a[i],1);
			else mp.put(a[i],mp.get(a[i]).intValue()+1);
		}
		int ans=0;
		for(int i:mp.keySet()){
			int t=mp.get(i);
			if(t>i)ans+=t-i;
			else if(t<i)ans+=t;
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 63012
import java.util.*;

class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int now = 0;
        int ans = 0;
        for (int i = 0; i < N; i++) {
            int h = sc.nextInt();
            if (now < h) {
                ans += h - now;
            }
            now = h;
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23252
#include <iostream>
#include <cstdio>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    double x1, x2, y1, y2, x3, y3, x, y, xx, yy;
    while(scanf("%lf,%lf,%lf,%lf,%lf,%lf",&x1,&y1,&x2,&y2,&x3,&y3)!=EOF){
        if(abs(y2-y1) < 0.0000000001){
            x = x3;
            y = 2*y2-y3;
        }
        else if(abs(x2-x1) < 0.0000000001){
            x = 2*x2-x3;
            y = y3;
        }
        else{
        xx = (x2-x1)/(y2-y1);
        yy = (y2-y1)/(x2-x1);
        x = ((-xx+yy)*x3-2*y3-2*x1*yy+2*y1)/(-xx-yy);
        y = -xx*(x-x3)+y3;
        }
        cout << fixed;
        cout << setprecision(5)<< x <<" "<< y << endl;
    }

    return 0;
}


Measured memory_bytes: 3280
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>

using namespace std;

#define mod 1000000007

int main()
{
	int n, x;
	cin >> n >> x;
	int a[100001];
	for(int i = 0; i < n; i++){
		cin >> a[i];
	}
	long long int ans = max(0, a[0] - x);
	a[0] -= max(0, a[0] - x);
	for(int i = 1; i < n; i++){
		int tmp = a[i - 1] + a[i] - x;
		a[i] -= max(0, tmp);
		ans += max(0, tmp);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
import java.io.BufferedInputStream;
import java.io.IOException;
import java.io.InputStream;
import java.util.Arrays;

public class Main {

	public static void main(String[] args) throws Exception {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt() - 1;
		int m = sc.nextInt() - 1;

		System.out.println(n * m);
	}

	private static boolean isDebug = System.getProperty("sun.desktop") != null;

	private static void debug(Object... o) {
		if (isDebug) {
			System.err.println(Arrays.deepToString(o));
		}
	}

	public static class Scanner {
		private BufferedInputStream inputStream;
		private StringBuilder buffer = new StringBuilder();

		public Scanner(InputStream in) {
			inputStream = new BufferedInputStream(in);
		}

		public int nextInt() throws IOException {
			int num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(int[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
			}
		}

		public void fill(int[] a, int[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextInt();
				b[i] = nextInt();
			}
		}

		public long nextLong() throws IOException {
			long num = 0;
			int sign = 1;

			int read = skip();
			if (read == '-') {
				sign = -1;
				read = inputStream.read();
			}

			do {
				num = num * 10 + sign * (read - 0x30);
			} while ((read = inputStream.read()) > 0x20);

			return num;
		}

		public void fill(long[] a) throws IOException {
			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
			}
		}

		public void fill(long[] a, long[] b) throws IOException {
			if (a.length != b.length) {
				throw new IllegalArgumentException();
			}

			for (int i = 0; i < a.length; i++) {
				a[i] = nextLong();
				b[i] = nextLong();
			}
		}

		public long[] nextLong(int n) throws IOException {
			long[] array = new long[n];
			for (int i = 0; i < n; i++) {
				array[i] = nextLong();
			}

			return array;
		}

		public String next() throws IOException {
			int read = skip();
			do {
				buffer.append((char) read);
			} while ((read = inputStream.read()) > 0x20);

			String text = buffer.toString();
			buffer.delete(0, buffer.length());

			return text;
		}

		private int skip() throws IOException {
			int read;
			while ((read = inputStream.read()) <= 0x20)
				;

			return read;
		}
	}
}

Measured memory_bytes: 23380