akhauriyash/Code-Regression huggingface dataset:
import java.util.*;
import java.util.stream.Collectors;



public class Main {
    public static int[] ints;
    public static void main(String[] args) {
        Scanner scanner=new Scanner(System.in);
        String[] strings=scanner.next().split("");
        ints=new int[strings.length];
        for(int i=0;i<ints.length;i++){
            ints[i]=Integer.parseInt(strings[i]);
        }
        char[] chars=new char[ints.length-1];
        func(3,chars,7);

    }
    public static void func(int index,char[] chars,int val){
        //System.out.println("call func!");
        //System.out.println(String.format("\tindex=%d,chars=[%c,%c,%c],val=%d",index,chars[0],chars[1],chars[2],val));
        if(index==0){
            if(val==ints[0]){
                for(int i=0;i<ints.length-1;i++){
                    System.out.print(String.format("%d%c",ints[i],chars[i]));
                }
                System.out.println(String.format("%d=7",ints[ints.length-1]));
                System.exit(0);
            }else{
                return;
            }
        }
        char[] chars1=Arrays.copyOf(chars,chars.length);
        char[] chars2=Arrays.copyOf(chars,chars.length);
        chars1[index-1]='+';
        chars2[index-1]='-';
        func(index-1,chars1,val-ints[index]);
        func(index-1,chars2,val+ints[index]);


    }
}

Measured memory_bytes: 21972
#include<bits/stdc++.h>
using namespace std;
int n,q,f[200005],g[200005];
struct edge{
	int u,v,w;
}e[400005];
bool cmp(edge x,edge y)
{
	return x.w<y.w;
}
int find(int x)
{
	if(f[x]==x)
	return x;
	return f[x]=find(f[x]);
}
int main()
{
	int x,y,z;
	cin>>n>>q;
	memset(g,0x7f,sizeof(g));
	for(int i=1;i<=q;i++)
	{
		cin>>x>>y>>z;
		x++;
		y++;
		e[i].u=x;
		e[i].v=y;
		e[i].w=z;
		g[x]=min(g[x],z+1);
		g[y]=min(g[y],z+2);
	} 
	for(int i=1;i<=n;i++)
	{
		g[i%n+1]=min(g[i]+2,g[i%n+1]);
	}
	for(int i=1;i<=n;i++)
	{
		g[i%n+1]=min(g[i]+2,g[i%n+1]);
	}
	for(int i=1;i<=n;i++)
	{
		e[i+q].u=i;
		e[i+q].v=i%n+1;
		e[i+q].w=g[i];
	}
	for(int i=1;i<=n;i++)
	f[i]=i;
	sort(e+1,e+1+n+q,cmp);
	long long sum=0,cnt=0;
	for(int i=1;i<=n+q;i++)
	{
		x=find(e[i].u);
		y=find(e[i].v);
		if(x!=y)
		{
			f[x]=y;
			cnt++;
			sum+=e[i].w;
		}
		if(cnt==n-1)
		break;
	}
	cout<<sum;
	return 0;
}

Measured memory_bytes: 8832
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace ABC0603
{
	class Program
	{
		static void Main(string[] args)
		{
			var param = Console.ReadLine();

			var param2 = param.Distinct();
			var param3 = param.ToList();

			if(param2.Count() == param3.Count())
			{
				Console.WriteLine("yes");
			}
			else
			{
				Console.WriteLine("no");
			}
		}
	}
}


Measured memory_bytes: 13268
N = gets.to_i

class Fixnum
  def bijective_s(base=nil, offset=nil)
    offset ||= 'a'.ord #65
    base ||= 26
    value = self
    result = []
    while value > 0
      value -= 1
      result << (value%base+offset).chr
      value /= base
    end
    result.reverse.join
  end
end

puts N.bijective_s 



Measured memory_bytes: 14352
import java.util.LinkedHashMap;
import java.util.Scanner;

public class Main {
	private Scanner sc;
	
	public static void main(String[] args) {
		new Main();
	}
	
	public Main() {
		sc = new Scanner(System.in);
		
		int lines = Integer.parseInt(sc.nextLine());
		while (lines != 0) {
			LinkedHashMap<String, Integer> nico = new LinkedHashMap<String, Integer>();
			
			for (int i = 0; i < lines; i++) {
				String line = sc.nextLine();
				String[] data = line.split(" ");
				
				int sales = Integer.parseInt(data[1]) * Integer.parseInt(data[2]);
				if (nico.containsKey(data[0]) == true) {
					nico.put(data[0], nico.get(data[0]) + sales);
				} else {
					nico.put(data[0], sales);
				}
			}
			
			boolean na = true;
			for (String key : nico.keySet()) {
				if (nico.get(key) >= 1000000) {
					System.out.println(key);
					na = false;
				}
			}
			if (na == true) System.out.println("NA");
			
			lines = Integer.parseInt(sc.nextLine());
		}
	}
}

Measured memory_bytes: 32364
function Main(input) {
  const inputs = input.split(" ");
        a = parseInt(inputs[0], 10);
        b = parseInt(inputs[1], 10);

  console.log(Math.ceil((a+b)/2));

}

function debug(){
	var input = document.getElementById("input").value;
	Main(input);
}

Main(require("fs").readFileSync("/dev/stdin", "utf8"));


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

using namespace std;

int main(void){
  
  string s, t;
  cin >> s >> t;
  
  int ans = 0;
  for(int i = 0;i < s.length() - t.length() + 1; i++){
    int count = 0;
    for(int j = 0;t[j] != '\0'; j++){
      if(s[i+j] == t[j]) count++;
    }
    ans = max(ans, count);
  }
    
  cout << t.length() - ans << endl;
  
}

Measured memory_bytes: 3628
#include<iostream>
#include<string>
#include<algorithm>
#include<iomanip>
using namespace std;
#define pi 3.141592653589793283462
int main(){
    int a,b,c;
    int p=0;
    cin>>a>>b>>c;
    for(int i=a;i<=b;i++){
        if(c%i==0)
           ++p;
        }
    cout<<p<<endl;
    return 0;
}

Measured memory_bytes: 1160
N = int(input())
a = input().split()
i=0
n = 0
sam = abs(int(a[0]))+abs(int(a[N-1]))
for i in range(N-1):
    sam += abs(int(a[i+1]) - int(a[i]))
for n in range(N):
    if n == 0:
        print(sam - abs(int(a[0])) - abs(int(a[1])-int(a[0])) +abs(int(a[1])))
    elif n == N-1:
        print(sam - abs(int(a[N-1])) - abs(int(a[N-2])-int(a[N-1])) +abs(int(a[N-2])))
    else:
        print(sam - abs(int(a[n])-int(a[n-1])) - abs(int(a[n+1])-int(a[n])) +abs(int(a[n+1])-int(a[n-1])))

Measured memory_bytes: 12064
def lower_bound(ary, n)
    return ary.size if ary[-1]<n    # case by case
    u = ary.size-1
    l = 0
    while u>l
      s = (u+l)/2
      ary[s] < n ? l = s+1 : u = s
    end
    l
end

n = gets.to_i
a = gets.split.map(&:to_i)

a.sort!

max = a.pop
mmax = max/2.0

if a[-1]<=mmax
  printf("%d %d\n", max, a[-1])
  exit
end

idx = lower_bound(a, mmax)

if (a[idx]-mmax).abs < (a[idx-1]-mmax).abs
  printf("%d %d\n", max, a[idx])
else
  printf("%d %d\n", max, a[idx-1])
end


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

int main(){
  string s,t;
  cin >> s >> t;
  
  int array_size = 'z' - 'a' + 1;
  int before[array_size];
  int after[array_size];
  for (int i = 0; i < array_size; i++){
    before[i] = -1;
    after[i]= -1;
  }

  int offset = 'a';
  bool flag = true;
  for (int j = 0; j < s.size(); j++){
    if (before[s[j] - offset] < 0){
      before[s[j] - offset] = t[j] - offset;
    }else{
      if (before[s[j] - offset] != t[j] - offset){
        flag = false;
        break;
      }
    }
    if (after[t[j] - offset] < 0){
      after[t[j] - offset] = s[j] - offset;
    }else{
      if (after[t[j] - offset] != s[j] - offset){
        flag = false;
        break;
      }
    }
  }
  
  if(flag){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }
  
  return 0;
}

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

int main() {
    int N; cin >> N;
    int ans = 0;
    for (int i = 1; i <= N; i++) {
        for (int j = 1; j <= N / i; j++) {
            int t = N - i * j;
            if (t > 0) ans++;
        }
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 3628
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)


def main():
    x = int(input())
    for i in range(-1000, 1000):
        for j in range(-1000, 1000):
            if x == (i**5-j**5):
                print(str(i)+' '+str(j))
                return


main()


Measured memory_bytes: 64580
import java.util.Scanner;
class Main
{
    public static void main(String args[])
    {
Scanner scan=new Scanner(System.in);

	while(scan.hasNext())
	    {
	
	long a,b,a1,b1;
	a=scan.nextInt();
	b=scan.nextInt();
	a1=a;
	b1=b;
	if(b>a)
	    {
		long tmp=b;
		b=a;
		a=tmp;
	    }
	while(a%b!=0)
	    {
		long tmp=b;
		b=a%b;
		a=tmp;
	    }
	System.out.println(b+" "+((a1*b1)/b));
	    }
    }
}

Measured memory_bytes: 17216
#include<iostream>
#include<algorithm>
#include<map>
using namespace std;

int main(){
  map<int, bool> memo;

  int N;
  cin >> N;
  int d = 0;

  for(int i=0; i<N; i++){
    int p[3];
    cin >> p[0] >> p[1] >> p[2];

    sort(p, p+3);

    int k = ((p[0]-1)*1000+(p[1]-1))*1000+(p[2]-1);

    if(memo.find(k)!=memo.end()){
      d++;
    }else{
      memo[k] = true;
    }
  }
   cout << d << endl;

 return 0;
}



Measured memory_bytes: 3208
#include<bits/stdc++.h>
using namespace std;
using ll = long long;
int main(){
    ll c,ans,i,length;
    string N;
    cin >> N;
    length = N.size();
    ans = 0;
    c = 0;
    for(i=0;i<length;i++){
        if(N[i] == 'W')
            ans += c;
        else
            c++;
    }
    
    cout << ans << "\n";
    return 0;
}

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

int main(){
  vector<int> v(5),v2(5),v3(5);
  rep(i,5){
    cin >> v.at(i);
    if(v.at(i)%10){
      v2.at(i) = (v.at(i)/10+1)*10;
    }else{
      v2.at(i) = v.at(i);
    }
  }
  rep(i,5){
    v3.at(i) = v2.at(i) - v.at(i);
  }
  sort(v3.begin(),v3.end());
  int sum = 0;
  rep(i,5){
    sum += v2.at(i);
  }
  cout << sum - v3.at(4) << endl;
}


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


void solve(long long A, long long B){
    ll res = 0;
    if(A>B) {
        res += A; A--;
    }else{
        res += B; B--;
    }
    res += max(A,B);
    cout << res << endl;
}

int main(){
    long long A;
    scanf("%lld",&A);
    long long B;
    scanf("%lld",&B);
    solve(A, B);
    return 0;
}


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

using namespace std;

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

    int64_t ans = 0;
    for(int i=0; i<N; i++) {
        int64_t m = min(A[i], B[i]);
        ans += m;
        B[i] -= m;
        m = min(A[i+1], B[i]);
        A[i+1] -= m;
        ans += m;
    }

    cout << ans << endl;
    return 0;
}


Measured memory_bytes: 1792
#include<set>
#include<map>
#include<cmath>
#include<ctime>
#include<queue>
#include<stack>
#include<cstdio>
#include<string>
#include<vector>
#include<cstdlib>
#include<cstring>
#include<iomanip>
#include<iostream>
#include<algorithm>
#define fi first
#define se second
#define pb push_back
#define lowbit(x) x&(-x)
#define PII  pair<int, int> 
#define all(x) x.begin(), x.end()
#define FAST ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)
typedef long long ll;
const int inf = 0x3f3f3f3f;
const ll mod = 12345678910;
const int maxn = (int)1e5 + 5;
using namespace std;

int main()
{
	int n; cin >> n;
	int ans = 0;
	for(int i = 1; i <= n; i++){
		ans += i;
	}
	cout << ans << endl;
	return 0;
}

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

int main() {
        int n, k;
        scanf("%d%d", &n, &k);
        vector<int> p(2 * n, -1);
        rep(i, k) {
                int a, b;
                scanf("%d%d", &a, &b);
                a --, b --;
                p[a] = b;
                p[b] = a;
        }
        vector<vector<long long>> tozan(2 * n, vector<long long> (2 * n));
        rep(i, 2 * n) {
                rep(j, 2 * n) {
                        for (int l = i; l <= j; l ++) {
                                tozan[i][j] += (p[l] == -1);
                        }
                }
        }
        const long long mod = 1e9 + 7;
        vector<vector<long long>> gezan(2 * n, vector<long long> (2 * n));
        rep(i, 2 * n) {
                rep(j, 2 * n) {
                        if (tozan[i][j] % 2 == 0) {
                                gezan[i][j] = 1;
                                for (long long l = tozan[i][j] - 1; l > 0; l -= 2) {
                                        (gezan[i][j] *= l) %= mod;
                                }
                        }
                }
        }
        vector<vector<long long>> dp(2 * n, vector<long long> (2 * n));
        vector<long long> hoge;
        long long ans = 0;
        for (int d = 1; d < 2 * n; d ++) {
                rep(l, 2 * n) {
                        int r = l + d;
                        if (r >= 2 * n) break;
                        bool ng = false;
                        for (int m = l; m <= r; m ++) {
                                if (p[m] != -1 && (p[m] < l || r < p[m])) {
                                        ng = true;
                                        break;
                                }
                        }
                        if (tozan[l][r] % 2 == 1) ng = true;
                        if (ng) {
                                continue;
                        }
                        dp[l][r] = gezan[l][r];
                        for (int m = l + 1; m < r; m ++) {
                                (dp[l][r] -= dp[l][m] * gezan[m + 1][r] % mod) %= mod;
                                (dp[l][r] += mod) %= mod;
                        }
                        long long rem = (l > 0 ? tozan[0][l - 1] : 0) + (r < 2 * n - 1 ? tozan[r + 1][2 * n - 1] : 0);
                        long long unko = 1;
                        for (long long m = rem - 1; m > 0; m -= 2) (unko *= m) %= mod;
                        (ans += dp[l][r] * unko % mod) %= mod;
                }
        }
        printf("%lld\n", ans);
        return 0;
}


Measured memory_bytes: 8704
require 'matrix'

gets.to_i.times do
  x1, y1, x2, y2, x3, y3 = gets.split.map(&:to_f)
  px, py = (Matrix[[2*(x1-x2), 2*(y1-y2)], [2*(x1-x3), 2*(y1-y3)]].inv *
    Matrix[[x1**2+y1**2-x2**2-y2**2], [x1**2+y1**2-x3**2-y3**2]]).to_a.flatten
  r = Math.sqrt((x1-px)**2+(y1-py)**2)
  printf "%.3f %.3f %.3f\n", px, py, r
end

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

int main(){
    string s;
    cin >> s;
    if(s=="ABC"){
        cout << "ARC" << endl;
    }else{
        cout << "ABC" << endl;
    }
}

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

using namespace std;

int main() {
	char x, y;
	cin >> x >> y;
	if (x < y) {
		cout << '<' << endl;
	}
	else if(x > y) {
		cout << '>' << endl;
	}
	else {
		cout << '=' << endl;
	}
	return 0;
}

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

// a quote from http://www.igaris.com/math/c.pdf

#define MOD (1000000000+7)

long long C[1001][1001];

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

	long long ans = 0;
	if( n <= k ) {
		// Pascal's triangle for combination
		C[0][0] = 1;
		for( int i = 1; i < 1001; i++ ) {
			for( int j = 0; j <= i; j++ ) {
				if( j == 0 || j == i ) {
					C[i][j] = C[i - 1][0];
				}
				else {
					C[i][j] = ( C[i - 1][j - 1] + C[i - 1][j] ) % MOD;
				}
			}
		}
		ans = C[k][n];
	}

	cout << ans << endl;

	return 0;
}



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

main(void){
  vector<vector<int>> c(3,vector<int>(3));
  for(int i=0;i<3;i++){
    for(int j=0;j<3;j++){
      cin >> c.at(i).at(j);
    }
  }
  int x[3],y[3];
  for(int i=0;i<=100;i++){
    x[0]=i;
    for(int j=0;j<3;j++) y[j]=c[0][j]-x[0];
    for(int j=0;j<3;j++) x[j]=c[j][0]-y[0];
    for(int j=0;j<3;j++){
      for(int k=0;k<3;k++){
        if(x[j]+y[k]!=c[j][k]){
          cout << "No" << endl;
          return 0;
        }
      }
    }
  }
  cout << "Yes" <<endl;
}

Measured memory_bytes: 3628
#include <iostream>
#include <vector>
#include <algorithm>
#define llint long long

using namespace std;

struct UnionFind{
	int size;
	vector<int> parent;
	
	UnionFind(){}
	UnionFind(int size){
		this->size = size;
		parent.resize(size+1);
		init();
	}
	void init(){
		for(int i = 0; i <= size; i++) parent[i] = i;
	}
	int root(int i){
		if(parent[i] == i) return i;
		return parent[i] = root(parent[i]);
	}
	bool same(int i, int j){
		return root(i) == root(j);
	}
	void unite(int i, int j){
		int root_i = root(i), root_j = root(j);
		if(root_i == root_j) return;
		parent[root_i] = root_j;
	}
};

int n, q;
int p[100005];
vector<int> G[100005];
char c[100005]; int v[100005];
bool mark[100005];
UnionFind uf(100005);

void dfs(int v)
{
	for(int i = 0; i < G[v].size(); i++){
		if(!mark[G[v][i]]) uf.unite(G[v][i], v);
		dfs(G[v][i]);
	}
}

int main(void)
{
	while(1){
		cin >> n >> q;
		if(n == 0 && q == 0) break;
		
		for(int i = 1; i <= n; i++) G[i].clear();
		for(int i = 2; i <= n; i++){
			cin >> p[i];
			G[p[i]].push_back(i);
		}
		for(int i = 0; i < q; i++){
			cin >> c[i] >> v[i];
		}
		
		for(int i = 1; i <= n; i++) mark[i] = false;
		mark[1] = true;
		
		for(int i = 0; i < q; i++){
			if(c[i] == 'M'){
				if(mark[v[i]]) c[i] = 'X';
				else mark[v[i]] = true;
			}
		} 
		uf.init();
		dfs(1);
		
		reverse(c, c+q);
		reverse(v, v+q);
		
		llint ans = 0;
		for(int i = 0; i < q; i++){
			if(c[i] == 'Q') ans += uf.root(v[i]);
			else if(c[i] == 'M' && v[i] != 1) uf.unite(v[i], p[v[i]]);
		}
		cout << ans << endl;
	}
	
	return 0;
}


Measured memory_bytes: 22848
program go_to_jail
  implicit none
  integer :: n, d1, d2, a(3) = 0, i
  read(*,*) n
  do i = 1, 2
    read(*,*) d1, d2
    a(i) = d1 - d2
  end do
  do i = 3, n
    read(*,*) d1, d2
    a(3) = d1 - d2
    if (all(a == 0)) then
      write(*,'(a)') 'Yes'
      stop
    end if
    a(1) = a(2)
    a(2) = a(3)
  end do
  write(*,'(a)') 'No'
end program go_to_jail

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

int main()
{
        	long long n;
	       cin>>n;
	       long long ans=0;
	       for(long long i=1;i<=n;i++)
           {
	           long long no=n/i;
	           long long lst=no*i;
	           long long res=no*(i+lst);
	           res/=2;
               ans+=res;
	       }
      cout<<ans;

 
  
  return 0;
}


Measured memory_bytes: 3620
import sys
read = sys.stdin.buffer.read
readline = sys.stdin.buffer.readline
readlines = sys.stdin.buffer.readlines

from fractions import gcd
from functools import reduce

N,*A = map(int,read().split())

MOD = 10 ** 9 + 7

lcm = reduce(lambda x,y: y//gcd(x,y)*x, A)
lcm %= MOD

coef = sum(pow(x, MOD-2, MOD) for x in A)
answer = lcm * coef % MOD

print(answer)

Measured memory_bytes: 5880
#include<bits/stdc++.h>
#define ford(i,a,b) for(int i=(a);i>=b;i--)
#define rep1(i,a,b) for(int i=(a);(i)<=(b);(i)++)
#define rep(i,a,b) for(int i=(a);(i)<(b);(i)++)
#define ll long long
#define N 100005
#define pql priority_queue<ll>
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define rev(a,n) reverse(a,a+n)
using namespace std;
int n,x,ans,a[N];
int main() {
	cin>>n>>x;
	rep(i,0,n) cin>>a[i];
	rep(i,0,n) ans=__gcd(ans,abs(x-a[i]));
	cout<<ans; 
	return 0;
}

Measured memory_bytes: 3872
// AOJ 1010: Dominoes Arrangement
// 2017.12.15 bal4u@uu

#include <stdio.h>
#include <stdlib.h>
#include <string.h>

char f['7'], g['7'];

int main()
{
	int n, i, k, ans;
	char buf[60], *p;

	while (fgets(buf, 6, stdin) != NULL) {
		n = atoi(buf);
		memset(f, 0, sizeof(f));
		memset(g, 0, sizeof(g));

		fgets(p=buf, 60, stdin);
		for (i = 0; i < n; i++) {
			if (*p == *(p+1)) g[*p] = 1;
			else f[*p]++, f[*(p+1)]++;
			p+=3;
		}

		ans = 0;
		if (n == 1) { ans = 1; goto done; }
		for (i = '0'; i <= '6'; i++) if (g[i] && !f[i]) goto done;
		k = 0; for (i = '0'; i <= '6'; i++) if (f[i] & 1) k++;
		ans = !k || k == 2;
done:	puts(ans ? "Yes" : "No");
	}
	return 0;
}

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

int main(){
    int N,M;
    cin >>N>>M;
    vector<int> broken(N+1);
    rep(i,M){
        int a;
        cin>>a;
        broken[a]=1;
    }
    vector<int> dp(N+2);
    const int mod = 1000000007;
    dp[N]=1;
    for(int i=N-1;i>=0;i--){
        if(broken[i]){
            dp[i]=0;
            continue;
        }
        dp[i]=(dp[i+1]+dp[i+2])%mod;
    }
	cout << dp[0];
    return 0;
}

Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
 
template<class T> bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T> bool chmin(T &a, const T &b) { if (a>b) { a=b; return 1; } return 0; }
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

int main(){
    int h,w;
    cin>>h>>w;
    int x=0;
    rep(i,h){
        string s;
        cin>>s;
        rep(j,w){
            if(s[j]=='#')x++;
        }
    }
    if(x==(h+w-1))cout<<"Possible"<<endl;
    else cout<<"Impossible"<<endl;
}

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

using namespace std;
typedef long long ll;
#define int ll

#define REP(i,n) for(int i=0;i<n;++i)
#define SORT(name) sort(name.begin(), name.end())
#define ZERO(p) memset(p, 0, sizeof(p))
#define MINUS(p) memset(p, -1, sizeof(p))
#if 1
#  define DBG(fmt, ...) printf(fmt, ##__VA_ARGS__)
#else
#  define DBG(fmt, ...)
#endif

const ll LLINF = (1LL<<60);
const int INF = (1LL<<30);
const double DINF = std::numeric_limits<double>::infinity();
const int MOD = 1000000007;
#define MAX_N 100010
#define MAX_K MAX_N

int N;
int K;
int fact[MAX_N];

ll get_need(ll n) {
    int cnt = 0;
    while(n < K) {
        n *= 2;
        cnt++;
    }
    return cnt;
}

signed main()
{
    cin >> N >> K;

    // fact の作成
    fact[0] = 1;
    fact[1] = 2;
    for(int i = 2; i < MAX_N; ++i) { fact[i] = fact[i-1] * 2; }

    double ans = 0;
    REP(i, N) {
        int num = i + 1;    // 出た目
        // 得点が K 以上になるのに必要な数
        int need = get_need(num);
        double val = 1.0 / static_cast<double>(N * fact[need]);
        ans += val;
        //DBG("val: %.11f ans: %.11f\n", val, ans);
    }
    printf("%.11f\n", ans);
    return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
using namespace std;
/* typedef */
typedef long long ll;
typedef pair<int, int> pii;
/* constant */
const int INF = 1 << 30;
const ll LINF = 1LL << 50;
const int NIL = -1;
const int MAX = 10000;
const int mod = 1000000007;
const double pi = 3.141592653589;
/* global variables */
/* function */
/* main */
int main(){
    int a, b;
    cin >> a >> b;
    for (int i = 0; i <= 1000; i++) {
        int c = i * 0.08;
        int d = i * 0.1;
        if (a == c && b ==  d) {
            cout << i << '\n';
            return 0;
        }
    }
    cout << -1 << '\n';
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (n); i++)
#define rep2(i, x, n) for (int i = x; i < (n); i++)
#define all(n) begin(n), end(n)
struct cww
{
    cww()
    {
        ios::sync_with_stdio(false);
        cin.tie(0);
    }
} star;
const long long INF = numeric_limits<long long>::max();
typedef long long ll;
typedef vector<int> vint;
typedef vector<char> vchar;
typedef vector<vector<int>> vvint;
typedef vector<ll> vll;
typedef vector<vector<ll>> vvll;
typedef unsigned long long ull;
template <class T>
bool chmax(T &a, const T &b)
{
    if (a < b)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <class T>
bool chmin(T &a, const T &b)
{
    if (b < a)
    {
        a = b;
        return 1;
    }
    return 0;
}
template <typename T>
vector<T> make_v(size_t a) { return vector<T>(a); }

template <typename T, typename... Ts>
auto make_v(size_t a, Ts... ts)
{
    return vector<decltype(make_v<T>(ts...))>(a, make_v<T>(ts...));
}
template <typename T, typename V>
typename enable_if<is_class<T>::value == 0>::type
fill_v(T &t, const V &v) { t = v; }

template <typename T, typename V>
typename enable_if<is_class<T>::value != 0>::type
fill_v(T &t, const V &v)
{
    for (auto &e : t)
        fill_v(e, v);
}
using P = pair<int, int>;
int dx[] = {0, -1, 0, 1};
int dy[] = {1, 0, -1, 0};
int main()
{
    int H, W;
    cin >> H >> W;
    auto A = make_v<char>(H, W);
    queue<pair<P, int>> q;
    rep(i, H)
    {
        rep(j, W)
        {
            cin >> A[i][j];
            if (A[i][j] == '#')
            {
                q.push({{i, j}, 0});
            }
        }
    }
    int ans = 0;
    while (!q.empty())
    {
        auto now = q.front();
        auto pos = now.first;
        int num = now.second;
        q.pop();
        rep(i, 4)
        {
            int ny = pos.first + dy[i], nx = pos.second + dx[i];
            if (ny < H and ny >= 0 and nx < W and nx >= 0 and A[ny][nx] != '#')
            {
                q.push({{ny, nx}, num + 1});
                A[ny][nx] = '#';
            }
        }
        chmax(ans, num);
    }
    cout << ans;
    return 0;
}

Measured memory_bytes: 13328
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using ld = long double;
template <class T>
using vc = vector<T>;
template <class T>
using vvc = vector<vector<T>>;
using vl = vector<ll>;

const ll MOD = 1e9 + 7;
const ll INF = 1e14;
const ld EPS = 1e-11;

#define eb emplace_back
#define all(x) (x).begin(), (x).end()
#define rep(i, n) for (int i = 0; i < (n); i++)
#define repr(i, n) for (int i = (n)-1; i >= 0; i--)
#define repe(i, l, r) for (int i = (l); i < (r); i++)
#define reper(i, l, r) for (int i = (r)-1; i >= (l); i--)

void init() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout << fixed << setprecision(15);
}
//--------------------------------------------------------------------------------//
struct UnionFind {
    vector<int> par;
    vector<int> count;
    vector<int> rank;

    UnionFind(int N) {
        count.assign(N, 1);
        rank.assign(N, 0);
        par.assign(N, 0);
        rep(i, N) par[i] = i;
    }

    int find(int x) {
        if (par[x] == x)
            return x;
        else {
            par[x] = find(par[x]);
            return par[x];
        }
    }

    void unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return;
        if (rank[x] < rank[y])
            swap(x, y);
        else if (rank[x] == rank[y])
            rank[y]++;
        par[y] = x;
        count[x] += count[y];
        return;
    }

    int size(int x) {
        return count[find(x)];
    }

    bool issame(int x, int y) {
        return find(x) == find(y);
    }
};
using UF = struct UnionFind;
int main() {
    init();
    ll N, M;
    cin >> N >> M;
    vl P(N);
    rep(i, N) {
        cin >> P[i];
        P[i]--;
    }
    UF uf(N);
    rep(i, M) {
        ll a, b;
        cin >> a >> b;
        a--, b--;
        uf.unite(a, b);
    }
    ll ans = 0;
    rep(i, N) {
        if (uf.issame(i, P[i])) ans++;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 2176
/**
       **********    ************
	  Author : Avi J Patel
	  University : DAIICT
       **********    ************
**/
#include<bits/stdc++.h>
using namespace std;
#define ll long long
#define ull unsigned long long
#define ld long double
#define pb push_back
#define pf push_front
#define mp make_pair 
#define mt make_tuple
#define ff first
#define ss second
#define si size()
#define MOD 1000000007
#define Mod 998244353
#define N 200001
#define large 10000000000000001
#define For(i,m,n) for(long long i=m;i<n;i++)
#define st(x) sort(x.begin(),x.end())
#define re(x,i) reverse(x.begin()+i,x.end())
#define FAST ios_base::sync_with_stdio(false),cin.tie(0),cout.tie(0);srand(time(NULL));
bool sortbysec(const pair<int,int> &a, 
              const pair<int,int> &b) 
{ 
    if(a.second < b.second) return true; 
    else if(a.ss==b.ss) return a.ff<b.ff;
	else return false;
}
bool sortbyboth(const pair<int,int> &a, const pair<int,int> &b)
{
	if(a.first<b.first) return true;
	else if(a.first==b.first) return a.second<b.second;
	else return false;
} 
ull powr(ull x1, ull n1) {
    if(x1==0)
    {
        return 0;
    }
    ull result=1;
    while(n1>0)
    {
        if(n1&1)
        {
            result=(result*x1);
        }
        n1=n1>>1;
        x1=(x1*x1);
    }
    return result;
} 
ll power(ll x, ll y, ll p) 
{ 
    ll res = 1;      // Initialize result 
  
    x = x % p;  // Update x if it is more than or 
                // equal to p 
  
    while (y > 0) 
    { 
        // If y is odd, multiply x with result 
        if (y & 1) 
            res = (res*x) % p; 
  
        // y must be even now 
        y = y>>1; // y = y/2 
        x = (x*x) % p; 
    } 
    return res; 
} 
  
ll modInverse(ll n, ll p) 
{ 
    return power(n, p-2, p); 
} 
ll ncr(ll n, ll r, ll p) 
{ 
   if (r==0) 
      return 1; 
    ll fac[n+1]; 
    fac[0] = 1; 
    for (ll i=1 ; i<=n; i++) 
        fac[i] = fac[i-1]*i%p; 
  
    return (fac[n]* modInverse(fac[r], p) % p * 
            modInverse(fac[n-r], p) % p) % p; 
} 

int main()
{
	FAST
	int t=1;
//	cin>>t;
	while(t--)
	{
		int n,x,y;
		cin>>n>>x>>y;
		int a[n+1][n+1];
		int b[n]={0};
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				a[i][j]=abs(i-j);
			}
		}
		a[x][y]=1;
		a[y][x]=1;
		for(int i=1;i<=n;i++)
		{
			for(int j=1;j<=n;j++)
			{
				a[i][j]=min(a[i][j],a[i][x]+1+a[y][j]);
				a[i][j]=min(a[i][j],a[i][y]+1+a[x][j]);
				b[a[i][j]]++;
			}
		}
		for(int i=1;i<n;i++)
		{
			cout<<b[i]/2<<endl;
		}
	}
	return 0;
}

















Measured memory_bytes: 15872
#include <iostream>
#include <vector>
#include <queue>
#include <algorithm>
#include <cmath>
#include <bitset>
#include <iomanip>
#include <stack>
#include <list>
#include <map>
#include <unordered_map>
#include <chrono>
#include <numeric>
using namespace std;
using ll = long long;
const ll INF = (ll)1e18+1;
const ll DIV = 1000000007;
//#define TEST

ll all_divs(ll n){
    vector<ll> ret;
    for(ll i = 1 ; i*i <= n ; ++i){
        if(n%i == 0){
            ret.push_back(i);
            if(i*i != n){
                ret.push_back(n/i);
            }
        }
    }
    return ret.size();
}

int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
#ifdef TEST
    chrono::system_clock::time_point start, end;
    start = chrono::system_clock::now();
#endif
    ll N;
    cin >> N;
    vector<ll> divN(10000001);
    ll total = 0;
    for(size_t i=1;i<=N; i++)
    {
        for(size_t j=i;j<=N; j+=i)
        {
            //if(j % i == 0) 
            total += j;
        }
    }
    cout << total << endl;
#ifdef TEST
    end = chrono::system_clock::now();
    cerr << static_cast<double>(chrono::duration_cast<chrono::microseconds>(end - start).count() / 1000.0) << "[ms]" << endl;
#endif
    return 0;
}

Measured memory_bytes: 81336
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <algorithm>
#include <cmath>
#include <sstream>
#include <iomanip>
#include <set>
using namespace std;
typedef long long int ll;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define yes cout << "yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
#define no cout << "no" << endl

const int INF = 1001001001;
const int mod = 1000000007;
#define PI 3.14159265359;

void P(int x) {cout << x << endl;}
void P(long x) {cout << x << endl;}
void P(double x) {cout << x << endl;}
void P(ll x) {cout << x << endl;}
void P(string x) {cout << x << endl;}
void P(char x) {cout << x << endl;}

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

int main() {
  int n;
  cin >> n;
  vector<int> v(n);
  rep (i, n - 1) {
    cin >> v[i];
  }
  int a[n];
  a[0] = v[0];
  a[n - 1] = v[n - 2];
  for (int i = 1; i < n - 1; i++) {
    a[i] = min(v[i - 1], v[i]);
  }
  int ans = 0;
  rep (i, n) {
    ans += a[i];
  }

  P(ans);

  return 0;
}





Measured memory_bytes: 256
#include <iostream>
#include <cassert>
#include <climits>
#include <bitset>
#include <stack>
#include <queue>
#include <iomanip>
#include <limits>
#include <string>
#include <cmath>
#include <set>
#include <map>
#include <math.h>
#include <algorithm>
#include <vector>
#include <string.h>
#include <tuple>

using namespace std;

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

long long int INF = 1e18;
long long int mod = 1000000007;
double Pi = 3.1415926535897932384626;
/*
vector<ll> G[500005];
vector<P> tree[500010];

//big priority queue
priority_queue <ll> pql;
priority_queue <P> pqp;

//small priority queue
priority_queue <ll,vector<ll>,greater<ll> > pqls;
priority_queue <P,vector<P>,greater<P> > pqps;
*/
//top pop

int dx[8]={1,0,-1,0,1,1,-1,-1};
int dy[8]={0,1,0,-1,1,-1,-1,1};
char dir[] = "RULD";
//↓,→,↑,←

#define p(x) cout<<x<<endl;
#define el cout<<endl;
#define pe(x) cout<<x<<" ";
#define ps(x) cout<<fixed<<setprecision(25)<<x<<endl;
#define pu(x) cout<<x;
#define re(i,n) for(i=0;i<n;i++);
#define pb push_back
#define lb lower_bound
#define ub upper_bound
#define deba(x) cout<< #x << " = " << x <<endl

ll rui(ll number1,ll number2){
    if(number2 == 0){
        return 1;
    }else{
        ll number3 = rui(number1,number2 / 2);
        number3 *= number3;
        number3 %= mod;
        if(number2%2==1){
            number3 *= number1;
            number3 %= mod;
        }
        return number3;
    }
}
ll gcd(ll number1,ll number2){
    if(number1 > number2){
        swap(number1 , number2);
    }
    if(number1 == 0 || number1 == number2){
        return number2;
    }else{
        return gcd(number2 % number1 , number1);
    }
}


ll i,j,k,ii,jj,n,m;
ll a,b,c,d,e,g,h,r,l,w,num,ans;
ll x[500005],y[500005],z[500005];
ll dp[3005][3005];
ll sum[3005];
bool dame;
char s[4000];

int main(){    
    cin >> n >> k;
	for(i=0;i<n;i++){
		cin >> x[i];
		y[i] = INF;
	}
	y[0] = 0;
	for(i=1;i<n;i++){
		for(j=1;j<=k;j++){
			if(i - j < 0)continue;
			y[i] = min(y[i],y[i-j] + abs(x[i] - x[i-j]));
		}
	}
	p(y[n-1]);
    return 0;
}

Measured memory_bytes: 4352
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
const ll MOD = 1000000007;
ll ans = 0, N, K;
int main() {
    cin >> N >> K;
    for(ll i = K; i <= N+1; i++){
        ans += (N-(i-1))*i + 1;
        ans %= MOD;
    }
    printf("%lld\n", ans);

    return 0;
}

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

#define REP(i, x, n) for (int i = x; i < (int)(n); i++)
#define rep(i, n) REP (i, 0, n)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define sz(x) (int)(x.size())
#define popcount(x) __builtin_popcount(x)
#define popcountll(x) __builtin_popcountll(x)
#define uniq(x) x.erase(unique(x.begin(), x.end()), x.end())
#define F first
#define S second
#define mp make_pair
#define eb emplace_back

using namespace std;

typedef long long ll;

const int INF = 1 << 29;

int main() {
    int n, k;
    cin >> n >> k;
    vector<int> d(k);
    rep (i, k) cin >> d[i];

    REP (i, n, INF) {
        string s = to_string(i);
        bool flg = true;
        rep (j, sz(s)) rep (l, sz(d)) {
            if (s[j] - '0' == d[l]) {
                flg = false;
            }
        }
        if (flg) {
            cout << i << endl;
            return 0;
        }
    }
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long int ll;
int main(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);cout.tie(0);
    ll n,i,temp;
    cin>>n;
    vector<pair<ll,ll> >arr;
    for(i=1;i<=n;i++){
        cin>>temp;
        arr.push_back(make_pair(temp,i));
    }
    sort(arr.begin(),arr.end());
    n=arr.size();
    for(i=0;i<n;i++)
        cout<<arr[i].second<<" ";
    cout<<endl;
    return 0;
}


Measured memory_bytes: 2544
#include <iostream>
#include <vector>
#include <algorithm>
#include <cmath>
#include <iomanip>
using namespace std;
int main(void){
    int n;
    cin>>n;
    vector<double>x(n);
    for(int i=0;i<n;i++){
        cin>>x[i];
    }
    for(int i=0;i<n;i++){
        double y;
        cin>>y;
        x[i]=abs(x[i]-y);
    }
    double s1=0,s2=0,s3=0,sinf=0;
    for(int i=0;i<n;i++){
        s1+=x[i];
        s2+=x[i]*x[i];
        s3+=x[i]*x[i]*x[i];
        sinf=max(sinf,x[i]);
    }
    s2=sqrt(s2);
    s3=cbrt(s3);
    cout<<fixed<<setprecision(10);
    cout<<s1<<endl<<s2<<endl<<s3<<endl<<sinf<<endl;
    
}



Measured memory_bytes: 3436
#include <iostream>
#include <vector>
#include <algorithm>
#include <stack>
#include <string>
#include <map>
#include <functional>
#include <cmath>
#include <cstdio>
using namespace std;

#define PI 4*atan(1);

int main(){
  int n, aa[1000] = {0};
  cin >> n;
  int a, b, c, d;
  map<int ,int> point, rank;
  for(int i = 0; i < n; i++){
    point[i] = 0;
  }
  for(int i = 0; i < n * (n - 1) / 2; i++){
    cin >> a >> b >> c >> d;
    if(c > d){
      point[a] += 3;
    }else if(c < d){
      point[b] += 3;
    }else{
      point[a]++;
      point[b]++;
    }
  }
  vector<int> v;
  for(int i = 1; i <= n; i++){
    int tmp;
    tmp = point[i];
    v.push_back(tmp);
  }
  sort(v.begin(), v.end(), greater<int>());
  for(int i = 0; i < n; i++){
    for(int j = 1; j <= n; j++){
      if(v[i] == point[j]){
        rank[j] = i + 1;
        point[j] = -1;
      }
    }
  }
  for(int i = 0; i < n; i++){
    cout << rank[i + 1] << endl;
  }
}

Measured memory_bytes: 1224
#include <cstdio>
#include <cstring>
#include <algorithm>

using namespace std;

#define MAX_N 3001


/* -----------------------------------------------------------------------------
	型とクラス定義
----------------------------------------------------------------------------- */

/* -----------------------------------------------------------------------------
	大域データ
----------------------------------------------------------------------------- */
int N;			// 料理の種類数 (2≦N≦3000)
int T;			// 制限時間     (1≦T≦3000)
int a[MAX_N];	// 時間 (1≦a[i]≦3000)
int b[MAX_N];	// おいしさ (1≦b[i]≦3000)

int sat[MAX_N];	// 時刻tまで注文したときの満足度

int main () {

	// 初期化
	memset(sat, 0, sizeof(sat));
	// N，Tの読込み
	scanf("%d %d", &N, &T);
	// a_i, b_iの読込み
	for(int i = 0; i < N; i++)	
		scanf("%d %d", a + i, b + i);
	for(int i = 0; i < N; i++) {
		for(int j = N - 1; j > i; j--) {
			if(a[j-1] > a[j]) {
				std::swap(a[j-1], a[j]);
 				std::swap(b[j-1], b[j]);
			}
		}
	}

	// 満足度更新
	for(int i = 0; i < N; i++) {
		for(int t = T - 1; t >= 0; t--) {
			if(t + a[i] >= T) {
				if(sat[T] < sat[t] + b[i])
					sat[T] = sat[t] + b[i];
			} else {
				if(sat[t + a[i]] < sat[t] + b[i])
					sat[t + a[i]] = sat[t] + b[i];
			}
		}
	}

	// 結果
	printf("%d\n", sat[T]);

	return 0;
}


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

int n,m,a[N]; char s[N];
int main(){
	scanf("%d%d%s",&n,&m,s+1);
	int i;
	for (i=1; i<=n; i++) a[i]=(s[i]=='A');
	int l=1,r=n,tg=0; i=0;
	while (m--){
		if (a[l]^tg) a[l]^=1; else{
			l++; r++;
			a[r]=tg; tg^=1;
		}
		if (l>(n<<1) && !(m&1)) break;
	}
	for (i=l; i<=r; i++)
		printf("%c",(a[i]^tg)?'A':'B');
	puts("");
	return 0;
}


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

#define FOR(i,b,e) for(ll i=(b); i <= (e); ++i)
#define FORD(i,b,e) for(ll i=(b); i >= (e); --i)
#define SIZE(c) (int) (c).size()
#define FORE(i,c) FOR(i,0,SIZE(c)-1)
#define FORDE(i,c) FORD(i,SIZE(c)-1,0)

#define pb push_back
#define mp make_pair
#define st first
#define nd second


using namespace std;

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

typedef vector <int> VI;
typedef vector <bool> VB;
typedef vector <pii> VP;
typedef vector <ll> VL;
typedef vector <pll> VPL;

typedef vector <VI> VVI;
typedef vector <VL> VVL;
typedef vector <VB> VVB;
typedef vector <VP> VVP;

const int MOD = 1000000007;
const int INF = 1000000001;
const ll LINF = 1000000000000000001LL;


/*************************************************************************/

int main() {
    ios_base::sync_with_stdio(0);
    
    int n;
    cin >> n;
    
    VI a(n), b(n), c(n);
    
    FOR(i,0,n-1) cin >> a[i];
    FOR(i,0,n-1) cin >> b[i];
    FOR(i,0,n-1) cin >> c[i];
    
    sort(a.begin(), a.end());
    sort(b.begin(), b.end());
    sort(c.begin(), c.end());

    ll ans = 0;
    
    FOR(i,0,n-1) {
        ll inA = lower_bound(a.begin(), a.end(), b[i]) - a.begin();
        ll inB = c.end() - upper_bound(c.begin(), c.end(), b[i]);
    
        ans += inA * inB;
    }
    
    cout << ans;

    return 0;
}

/*************************************************************************/


Measured memory_bytes: 1408
#include<bits/stdc++.h>
using namespace std;
int main(){
  string s;
  cin >> s;
  int i;
  int ans = s.length();
  bool tmp = true;
  for(i=1;i<s.length();i++){
    if(s[i]==s[i-1]){
      ans--;
      i+=2;
    }
  }
  cout<<ans<<endl;
}


Measured memory_bytes: 640
#include <stdio.h>
#include <math.h>
#define rep(i, n) for(int i = 0; i < n; ++i)

typedef double llb;

llb abs(llb a) {
  return a > 0 ? a : -a;
}

int main(void) {
  int i, n, j;
  scanf("%d", &n);
  llb x[n], y[n], d[n], max;
  rep(i, n) scanf("%lf", &x[i]);
  rep(i, n) scanf("%lf", &y[i]);
  rep(i, n) d[i] = abs(x[i] - y[i]);
  /*rep(i, n) printf("%f ", d[i]);
  printf("\n");*/
  rep(i, n) if(max < d[i]) max = d[i];
  llb ans = 0;
  for(i = 1; i <= 3; ++i) {
    ans = 0;
    rep(j, n) ans += pow(d[j], (double)i);
    ans = pow(ans, 1.0 / (double)i);
    printf("%f\n", ans);
  }
  printf("%f\n", max);
  return 0;
}


Measured memory_bytes: 2940
#include<stdio.h>
int main(void) {
	int n, a, b;
	scanf("%d", &n);
	scanf("%d", &a);
	scanf("%d", &b);

	while (1) {
		if (a + 1 != b) {
			a++;
			if (b - 1 != a) {
				b--;
			}
			else if (b + 1 <= n) {
				b++;
			}
			else {
				printf("Alice\n");
				break;
			}
		}
		else if (a - 1 >= 2) {
			a--;
			if (b - 1 != a) {
				b--;
			}
			else if (b + 1 <= n) {
				b++;
			}
			else {
				printf("Alice\n");
				break;
			}
		}
		else {
			printf("Borys\n");
			break;
		}
	}
	return 0;
}

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

const ll INF = 1LL << 60;

ll N;
vector<ll> h;
int main() {
    cin >> N;
    h.resize(N + 1);
    rep(i, N) cin >> h[i + 1];

    ll ans = 0;
    h[0] = 0;
    for (int i = 1; i <= N; i++) {
        if (h[i - 1] < h[i]) {
            ans += (h[i] - h[i - 1]);
        }
    }

    cout << ans << endl;
}

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

#define ll long long
#define N 200010
int n, a[N];
ll f[N][5];

int main()
{
	while (scanf("%d", &n) != EOF)
	{
		for (int i = 1; i <= n; ++i) scanf("%d", a + i);
		memset(f, 0x3f, sizeof f);
		for (int i = 0; i < 5; ++i) f[0][i] = 0;
		// 0 左边零碎
		// 1 左边偶数
		// 2 奇数
		// 3 右边偶数
		// 4 右边零碎
		for (int i = 1; i <= n; ++i)
		{
			ll Min = (ll)1e18, cost;
			cost = a[i];
			Min = min(Min, f[i - 1][0]);
			f[i][0] = Min + cost;
			
			cost = a[i] == 0 ? 2 : (a[i] % 2);
			Min = min(Min, f[i - 1][1]);
			f[i][1] = Min + cost;

			cost = a[i] == 0 ? 1 : (a[i] % 2 == 0);
			Min = min(Min, f[i - 1][2]);
			f[i][2] = Min + cost;
			
			cost = a[i] == 0 ? 2 : (a[i] % 2);
			Min = min(Min, f[i - 1][3]);
			f[i][3] = Min + cost;

			cost = a[i];
			Min = min(Min, f[i - 1][4]);
			f[i][4] = Min + cost;
		}
		ll res = (ll)1e18;
		for (int i = 0; i < 5; ++i)
			res = min(res, f[n][i]);
		printf("%lld\n", res);
	}
	return 0;
}


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

const int PRIME_SIZE = 1000000;

int main()
{
	bool prime[ PRIME_SIZE ] = { 0 };
	prime[ 0 ] = prime[ 1 ] = true;
	for( int i = 2; i < PRIME_SIZE; ++i ){
		if( prime[ i ] ) continue;
		for( int j = i + i; j < PRIME_SIZE; j += i ){
			prime[ j ] = true;
		}
	}

	int n;
	while( cin >> n && n ){
		int pay = -n;
		int* hit = new int[ PRIME_SIZE + 1 ]();
		for( int i = 0; i < n; ++i ){
			int p, m;
			cin >> p >> m;
			int low = max( 0, p - m );
			int high = min( PRIME_SIZE - 1, p + m );
			++hit[ low ];
			--hit[ high + 1 ];
		}
		int count = 0;
		for( int i = 0; i < PRIME_SIZE; ++i ){
			count += hit[ i ];
			if( !prime[ i ] ){
				pay += count;
			}
		}

		cout << ( pay < 0 ? 0 : pay ) << endl;

		delete[] hit;
	}
	return 0;
}

Measured memory_bytes: 6084
n,m = gets.chomp.split.map(&:to_i)
ps = m.times.map{gets.chomp.split}
p_array = Array.new(n+1,0)
ac_array = Array.new(n+1,false)
ps.each do |p,s|
  p = p.to_i
  if s == "AC"
    ac_array[p] = true
  elsif s == "WA" && ac_array[p] == false
    p_array[p] += 1
  end
end
ac_cnt = 0
p_cnt = 0
ac_array.each_with_index do |f,i|
  if f == true
    ac_cnt += 1
    p_cnt += p_array[i]
  end
end
puts [ac_cnt,p_cnt].join(" ")

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

//typedef
//------------------------------------------
typedef long long LL;
typedef vector<LL> VL;
typedef vector<VL> VVL;
typedef vector<string> VS;
typedef pair<LL, LL> PLL;

//container util
//------------------------------------------
#define ALL(a)  (a).begin(),(a).end()
#define RALL(a) (a).rbegin(), (a).rend()
#define PB push_back
#define MP make_pair
#define SZ(a) int((a).size())
#define EACH(i,c) for(typeof((c).begin()) i=(c).begin(); i!=(c).end(); ++i)
#define EXIST(s,e) ((s).find(e)!=(s).end())
#define SORT(c) sort((c).begin(),(c).end())

//constant
//--------------------------------------------
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int MOD = 1000000007;

//debug
#define dump(x)  cerr << #x << " = " << (x) << endl;
#define debug(x) cerr << #x << " = " << (x) << " (L" << __LINE__ << ")" << " " << __FILE__ << endl;

//main code

int main(int argc, char const* argv[])
{
	vector<char> a(9);
	for (int i = 0; i < 9; i++) {
		cin >> a[i];
	}
	cout << a[0] << a[4] << a[8] << endl;
	return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#include <fstream>
#include <algorithm>
#include <string>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <vector>
#include <limits.h>
#include <math.h>
#include <functional>
#include <bitset>
#include <iomanip>
#include <cassert>
#include <float.h>
#include <random>

#define repeat(i,n) for (int i = 0; (i) < (n); ++ (i))
#define debug(x) cerr << #x << ": " << x << '\n'
#define debugArray(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge] << '\n'
#define debugArrayP(x,n) for(long long hoge = 0; (hoge) < (n); ++ (hoge)) cerr << #x << "[" << hoge << "]: " << x[hoge].first<< " " << x[hoge].second << '\n'

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef pair<int,int> Pii;
typedef vector<int> vint;
typedef vector<ll> vll;
const ll INF = LLONG_MAX/2;
const ll MOD = 1e9+7;


template<typename T>
class ConvexHullTrick {
private:
    vector<pair<T, T>> lines;
    int head;
    bool check(pair<T, T> l1, pair<T, T> l2, pair<T, T> l3) {
        return (l3.second - l2.second) * (l2.first - l1.first) >= (l2.second - l1.second) * (l3.first - l2.first);
    }

    T f(int i, T x) {
        return lines[i].first * x + lines[i].second;
    }


public:
    ConvexHullTrick():head(0){}

    bool empty(){
        return lines.size()-head==0;
    }

    void insert(T a, T b) {
        pair<T, T> line(a, b);
        if(lines.size()-head>=1&&a==lines.back().first&&b>lines.back().second)return;
        while (lines.size()-head >= 2 && check(*(lines.end() - 2), lines.back(), line))
            lines.pop_back();
        lines.emplace_back(line);
    }

    T getmin(T x) {
        while (lines.size() - head >= 2 && (f(head, x)>=f(head + 1, x)))
            ++head;
        return f(head, x);
    }
};

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  int N;ll C;cin>>N>>C;
  ConvexHullTrick<ll> CHT;
  ll dp=0;
  repeat(i,N){
    ll h;cin>>h;
    if(!CHT.empty())dp = CHT.getmin(h)+h*h+C;
    CHT.insert(-2*h,h*h+dp);
  }
  cout<<dp<<endl;
  return 0;
}


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

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

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

Measured memory_bytes: 256
package main

import (
    "fmt"
)

func main() {
    var n int
    fmt.Scan(&n)
    hs := make([]int, n)
    for i := 0; i < n; i++ {
        var h int
        fmt.Scan(&h)
        hs[i] = h
    }

    dp := make([]int, n)
    dp[0] = 0
    dp[1] = abs(hs[1] - hs[0])
    for i := 2; i < n; i++ {
        dp[i] = min(
            abs(hs[i]-hs[i-2])+dp[i-2],
            abs(hs[i]-hs[i-1])+dp[i-1],
        )
    }

    fmt.Println(dp[n-1])
}

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

func abs(n int) int {
    if n < 0 {
        return -n
    }
    return n
}


Measured memory_bytes: 5504