akhauriyash/Code-Regression huggingface dataset:
using System;
using System.Linq;
using System.Collections;
using System.Collections.Generic;

namespace Main
{
    class Program
    {
        static void Main(string[] args)
        {
            //ここから
            //int n=Readint();
            //string[] str = Console.ReadLine().Split(' ');

            string s = Console.ReadLine();
            string t = Console.ReadLine();
            int count = 0;
            
            for(int i = 0; i < s.Length; i++)
            {
                if (s[i] != t[i]) count++;
            }

            Cout(count);
            //ここまで
        }

        static void Cout(string s)
        {
            Console.WriteLine(s);
            return;
        }

        static void Cout(int n)
        {
            Console.WriteLine(n);
            return;
        }

        static void Cout(long n)
        {
            Console.WriteLine(n);
            return;
        }

        static int Readint()
        {
            return int.Parse(Console.ReadLine());
        }

        static int[] ReadArray(int n)
        {
            string[] str = Console.ReadLine().Split(' ');
            int[] a = new int[n];
            for (int i=0; i < n; i++){ a[i] = int.Parse(str[i]); }
            return a;
        }
        static long[] ReadArray(long n)
        {
            string[] str = Console.ReadLine().Split(' ');
           long[] a = new long[n];
            for (long i = 0; i < n; i++) { a[i] = long.Parse(str[i]); }
            return a;
        }

        static long Readlong()
        {
            return long.Parse(Console.ReadLine());
        }

        static int Min(int a, int b)
        {
            if (a < b) return a;
            return b;
        }

        static int Max(int a, int b)
        {
            if (a > b) return a;
            return b;
        }


    }

}


Measured memory_bytes: 27432
#include<stdio.h>
#include <string.h>
#include<iostream>
using namespace std;

int main()
{
    int X, Y;
    int flag = 0;
    int legs;

    cin >> X >> Y;


    for (int i = 0; i <= X; i++)
    {
        if (Y == i * 4 + (X - i) * 2) {
            flag = 1;
            break;
        }

    }

    if(flag==1)
        printf("Yes");
    else
        printf("No");

    return 0;
}

Measured memory_bytes: 3760
#include <iostream>

using namespace std;

int main(){
  long long S;
  long long X1 = 0, Y1 = 0, X2 = 1000000000, Y2 = 1, X3, Y3;
  cin >> S;

  Y3 = S / X2;
  if (S%X2 != 0) Y3++;
  X3 = X2 * Y3 - S;

  printf("%llu %llu %llu %llu %llu %llu\n",X1,Y1,X2,Y2,X3,Y3);
}


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

int main(){
  int n, m;
  cin >> n >> m;
  vector<int> vec(n);
  int alln=0;
  for(int i=0; i<n; ++i){
    cin >> vec.at(i);
    alln += vec.at(i);
  }
  --alln;
  alln /= 4*m;
  int ans=0;
  for(int i=0; i<n; ++i){
    if(vec.at(i) <= alln) continue;
    else ++ans;
  }
  if(ans >= m) cout << "Yes" << endl;
  else cout << "No" << endl;
}

Measured memory_bytes: 256
s = input()
sgn = 1
Q = int(input())
L = '' #sgn=-1
R = '' #sgn=1
for _ in range(Q):
  i = input()
  if i[0] == '1':
    sgn*=-1
  else:
    if i[2] == '1':
      if sgn == 1:
        L += i[4]
      else:
        R += i[4]
    else:
      if sgn == 1:
        R += i[4]
      else:
        L += i[4]

if sgn == -1:
  s = s[::-1]
  R = R[::-1]
  print(R + s +L)
  
else:
  L = L[::-1]
  print(L + s + R)

Measured memory_bytes: 9936
N = int(input())
A = list(map(int,input().split()))
m = 1000
k = 0

for i in range(N-1) :
    bk = m//A[i]
    bm = m - A[i] * bk
    am = bm + bk*A[i+1]
    ak = 0
    if m <= am :
        m = am
        k = ak
    else :
        pass

print(m)
        

    

Measured memory_bytes: 9176
#include<iostream>
#include<vector>
#include<string>
#include<deque>
#include<unordered_map>
#include<unordered_set>
#include<queue>
#include<algorithm>
#include<cmath>
#include<numeric>
using namespace std;

typedef long long LL;
const int MOD = 1e9+7;


int gcd(int a,int b){
	while(b){
		int temp = a%b;
		a = b;
		b = temp;
	}
	return a;
}

void solve(){
	int n;
	cin>>n;
	// vector<int> a(n);
	// for(int i=0;i<n;i++){
	// 	cin>>a[i];
	// }
	LL res = 0;
	for(int i=0;i<n;i++){
		for(int j=0;j<n;j++){
			for(int k=0;k<n;k++){
				res += gcd(i+1,gcd(j+1,k+1));
			}
		}
	}
	cout<<res<<endl;
}


int main(){
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	cout.tie(nullptr);
	int T = 1;
	// cin>>T;
	while(T--){
		solve();
	}
	return 0;
}


Measured memory_bytes: 3652
#include<bits/stdc++.h>
#define ll long long int
using namespace std;
vector<bool> vis;
int dfs(vector<vector<int>> &G, int idx){
    if(vis[idx]) return 0;
    vis[idx] = 1;
    int ans = 0;
    for(auto x: G[idx]){
        if(vis[x]==0){
            ans += dfs(G,x);
        }
    }
    return 1 + ans;
}

int main(){
    int n, m; cin>>n>>m;
    vector<vector<int>> G(n+1);
    vis.resize(n+1);
    for(int i = 0 ; i < m; i++){
        int u,v; cin>>u>>v;
        G[u].push_back(v);
        G[v].push_back(u);
    }
    int maxx = 0;
    for(int i = 1 ; i <= n; i++){
        maxx = max(maxx, dfs(G, i));
    }
    cout<<maxx<<endl;
    return 0;
}

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

int main(){
    int n;
    cin >> n;
    int a[n];
    for(int i=0;i<n;i++){
        cin >> a[i];
    }
    int sum=0;
    for(int i=0;i<n;i++){
        for(int j=0;j<i;j++){
            for(int k=0;k<j;k++){
                if(a[i]!=a[j] && a[j]!=a[k] && a[k]!=a[i] && a[i]+a[j] > a[k] && a[j]+a[k] > a[i] && a[k]+a[i] > a[j]){
                    sum++;
                }
            }
        }
    }
    cout << sum << endl;
    return 0;
}

Measured memory_bytes: 3636
#include <iostream>
#include <string>
#include <algorithm>
using namespace std;
int main(){

    int n,l=0,r,count=0;
    cin>>n;

    int s[n+100];
    for(int i=0; i< n; i++){
        cin>>s[i];
    }
    
    int q;
    cin>>q;

    int t[q+100];
    for(int i=0; i<q; i++){
        cin>>t[i];
    }
    r = n;
    for(int i= 0;i<q;i++){
        r = n;
        l = 0;
        while(l < r){
            int mid=(r+l)/2;
            if(t[i]==s[mid]){
                count+=1;
                break;
            }else if(s[mid] < t[i]){
                l = mid + 1;
            }else{
                r = mid;
            }
        }
    }
cout<<count<<endl;
return 0;
}


Measured memory_bytes: 3664
#include<iostream>
#include<vector>
#include<string>
#include<unordered_map>
#include<map>
#include<queue>
#include<math.h>
using namespace std;


int main(){
  int k,s;
  cin >> k >> s;
  int count=0;
  for (int x = 0; x <=k; x++) {
    for (int y = 0; y <=k; y++) {
      if((s-x-y)<=k&&(s-x-y)>=0)count++;
    }
  }
  cout << count<<endl;
}


Measured memory_bytes: 256
#include <cstdio>
#include <vector>
#include <string>
using namespace std;
int flag[8] = { 0 }; 
int T, cnt = 0;
void getr(int num, int len) {
	if (len == 0) {
		if (num <= T) {
			if (flag[3] > 0 && flag[5] > 0 && flag[7] > 0) cnt++;
		}
		return ;
	}
	flag[3]++;
	getr(num * 10 + 3, len - 1);
	flag[3]--;
	flag[5]++;
	getr(num * 10 + 5, len - 1);
	flag[5]--;
	flag[7]++;
	getr(num * 10 + 7, len - 1);
	flag[7]--;
}
int main() {
	scanf("%d", &T);
	int len = 0;
	int t = T;
	while (t != 0) {
		len++;
		t /= 10;
	}
	int sum = 0;
	for (int i = 3;i <= len;i++) {
		cnt = 0;
		getr(0, i);
		sum += cnt;
	}
	printf("%d", sum);
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
typedef long long ll;
using namespace std;
string s[100005];
int a[10];
int main()
{
	int n;cin>>n;
	for (int i = 0; i < n; i++)
	{
		cin>>s[i];
	}
	for (int i = 0; i < n; i++)
	{
		if(s[i][0]=='A') a[0]++;
		else if(s[i][0]=='W') a[1]++;
		else if(s[i][0]=='T') a[2]++;
		else a[3]++;
	}
	cout<<"AC x "<<a[0]<<endl;
	cout<<"WA x "<<a[1]<<endl;
	cout<<"TLE x "<<a[2]<<endl;
	cout<<"RE x "<<a[3]<<endl;
	return 0;
}

Measured memory_bytes: 6756
#include <bits/stdc++.h>
using namespace std;
int main(){
	long long n,h,i;
	cin>>n>>h;
	long long a[n],b[n];
	for(i=0;i<n;i++) cin>>a[i]>>b[i];
	sort(b,b+n);
	sort(a,a+n);
	for(i=n-1;i>=0&&h>0;i--) h-=max(a[n-1],b[i]);
	if(h<1){
		cout<<n-i-1;
		return 0;
	}
	if(h%a[n-1]){
		cout<<n+h/a[n-1]+1;
		return 0;
	}
	cout<<n+h/a[n-1];
	
	return 0;
}


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

using namespace std;

int main()
{
    int n;
    cin>>n;
    long long x;
    vector<long long> v;
    for(int i = 0;i<n;i++)
    {
        cin>>x;
        v.push_back(x);
    }
    vector<long long> small,large;
    for(int j = 0;j<v.size()-1;j++)
    {
        small.push_back(j + v[j]);
        large.push_back(j+1 - v[j+1]);
    }
    map<pair<long long,long long>,int> mp;
    map<long long,int> mp2,mp3;
    for(int h = 0;h<large.size();h++)
    {
        mp2[large[h]]++;
        mp[{h,large[h]}] += mp2[large[h]];
    }
    for(int h = 0;h<large.size();h++)
    {
        mp3[large[h]]++;
    }
    long long total = 0;
    for(int k = 0;k<small.size();k++)
    {
        total += mp3[small[k]] - mp[{k,small[k]}];
        if(small[k] == 0)
        {
            total--;
        }
    }


    cout<<total;


    return 0;
}

Measured memory_bytes: 67556
#include<iostream>
using namespace std; // 575

const int MAX = 200001;
const int MOD = 1000000007; // 今回使う余り
int main() {
	int N, C;
	cin >> N;
	static int dp[MAX], color[MAX];
	for (int i = 0;i < MAX;++ i) color[i] = -1;
	dp[0] = 1;
	for (int i = 0;i < N;++ i) {
		cin >> C;
		dp[i + 1] = dp[i];
		if (color[C] >= 0 && color[C] < i) dp[i + 1] = (dp[i + 1] + dp[color[C]]) % MOD;
		color[C] = i + 1;
	}
	cout << dp[N];
	return 0;
}
/*
31536000のコメント解説欄
ここテンプレで用意してるから、A問題とかだとこの先空欄の危険あり
また、コンテスト後に https://31536000.hatenablog.com/ で解説していると思うので、良かったら読んでねー

*/

Measured memory_bytes: 1792
import numpy as np

N = int(input())
X = np.array([list(map(int, input().split())) for i in range(N)])

all_diffs = np.expand_dims(X, axis=1) - np.expand_dims(X, axis=0)
distance_matrix = np.sqrt(np.sum(all_diffs**2, axis=-1))
distance = np.sum(distance_matrix) / N

print(distance)


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

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

    int ansn = 0, ansm = 0;

    if(n >= 2){
        ansn = (n*(n-1))/2;
    }

    if(m >= 2){
        ansm = (m*(m-1))/2;
    }

    cout << ansn + ansm << endl;
    return 0;
}

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

using namespace std;

int main() {
  int h, w, a, b;
  cin >> h >> w >> a >> b;
  for (int i = 0; i < h; ++i) {
    for (int j = 0; j < w; ++j) {
      if (j < a && i < b) {
	cout << 0;
      } else if (j >= a && i >= b) {
	cout << 0;
      } else {
	cout << 1;
      }
    }
    puts("");
  }
  return 0;
}




Measured memory_bytes: 1280
from collections import deque
n,m=map(int,input().split())
l=[[0] for _ in range(n+1)]
vi=[0 for _ in range(n+1)]

for i in range (m):
  a,b=map(int,input().split())
  l[a].append(b)
  l[b].append(a)
st=deque([1])
f=set([1])


while st:
  x=st.popleft()
  for k in l[x]:
    if k not in f:
      st.append(k)
      f.add(k)
      vi[k]=x   
  
print("Yes")
for m in vi[2:]:
  print(m)
  
  

Measured memory_bytes: 42000
#include <iostream>
#include <algorithm>
#include <cmath>
#include <cassert>
#include <cstdio>
#include <cstdlib>

using namespace std;

using ll = long long;
#define MIN(a, b) (((a) < (b)) ? (a) : (b))
#define MAX(a, b) (((a) < (b)) ? (b) : (a))

int const nmax = 100000;

int query(int pos){
  cout << pos << '\n';
  cout << flush;
  string s;
  cin >> s;
  if(s == "Vacant")
    exit(0);
  else if(s == "Female")
    return 1;
  else
    return 2;
  return 0;
}

int v[1 + nmax];

void extract(int from, int to){
  if(from + 2 == to)
    v[from + 1] = query(from + 1);
  else {
    int mid = (from + to) / 2;
    if((mid - from) % 2 == 1)
      mid--;
    v[mid] = query(mid);
    if(v[from] != v[mid])
      extract(from, mid);
    else
      extract(mid, to);
  }
}

int main()
{
  int n;
  cin >> n;
  v[0] = query(0);
  v[n - 1] = query(n - 1);
  extract(0, n - 1);
  return 0;
}


Measured memory_bytes: 852
#include <cstdio>
#include <ext/pb_ds/priority_queue.hpp>
#define FOR(i, l, r) for(int i = l; i <= r; ++i)

using namespace std;
using namespace __gnu_pbds;

const int N = 200010;
const int inf = 1e9;

typedef pair <int, int> pii;
typedef __gnu_pbds::priority_queue <pii,  greater<pii >, pairing_heap_tag > heap;
heap::point_iterator id[N];

struct edge{int to, next, v;} e[N];
int head[N], dis[N];
int k, cnt;

void ins(int x, int y, int z)
{
    e[++cnt].to = y; e[cnt].next = head[x]; e[cnt].v = z; head[x] = cnt;
}

void dijkstra()
{
    heap q;
    FOR(i, 0, k - 1) dis[i] = inf;
    id[1] = q.push(make_pair(0, 1)); dis[1] = 0;
    while (!q.empty())
    {
        int x = q.top().second; q.pop();
        for(int i = head[x]; i; i = e[i].next)
        {
            int y = e[i].to;
            if (dis[x] + e[i].v < dis[y])
            {
                dis[y] = dis[x] + e[i].v;
                if (id[y] != 0)
                    q.modify(id[y], make_pair(dis[y], y));
                else id[y] = q.push(make_pair(dis[y], y));
            }
        }
    }
}

int main()
{
    scanf("%d", &k);
    FOR(i, 0, k - 1) ins(i, (i + 1) % k, 1);
    FOR(i, 0, k - 1) ins(i, i * 10 % k, 0);
    dijkstra();
    printf("%d\n", dis[0] + 1);
    return 0;
}


Measured memory_bytes: 7168
import java.util.Scanner;

class Main{
    public static void main(String[] args){
        Scanner scan = new Scanner(System.in);
        int a = scan.nextInt();
        int b = scan.nextInt();
        int c = scan.nextInt();

        if(a < b && b < c){
            System.out.println("Yes");
        }else{
            System.out.println("No");
        }
    }
}

Measured memory_bytes: 26228
#include<bits/stdc++.h>
#define ll long long
#define pb push_back
#define mp make_pair
using namespace std;

void solve()
{
    string s;
    cin >> s;
    cout << s;
    if(s[s.size()-1]=='s')
    cout << "es" << endl;
    else
    {
        cout << "s" << endl;
    }
    
}

int main()
{
    int t=1;
    //cin >> t;
    while(t--)
    solve();

    return 0;
}


Measured memory_bytes: 3628
#include "bits/stdc++.h"
using namespace std;
 
using ll = long long;
 
const ll inf = 1e18;
const int N = 2 * 1e5 + 1;

ll res , k , n;
ll w[105] , v[105] , dp[105][N];

void solve(){
    cin >> n >> k;
    for(int i = 1; i <= n; i++) {
        cin >> w[i] >> v[i];
        res += v[i];
    }
    for(int i = 1; i <= res; i++) dp[0][i] = inf; 

    for(int i = 1; i <= n; i++) {
        for(int j = 0; j <= res; j++) {
            if(v[i] > j) dp[i][j] = dp[i - 1][j];
            else dp[i][j] = min(w[i] + dp[i - 1][j - v[i]] , dp[i - 1][j]);
        }
    }
    ll ans = 0;
    for(int i = 0; i <= res; i++) {
        if(dp[n][i] <= k) 
            ans = i;
    }
    cout << ans;
}
 
int main(int argc, char const *argv[]){
    ios_base::sync_with_stdio(0);cin.tie(NULL);cout.tie(NULL);
    ll t = 1;
    //cin >> t;
    while(t--){
        solve();
    }
}


Measured memory_bytes: 82816
n = int(input())
h = [int(i) for i in input().split(" ")]

dp = [0] * n
dp[1] = abs(h[1] - h[0])

for i in range(2, n, 1):
  cost1 = abs(h[i-2] - h[i])
  cost2 = abs(h[i-1] - h[i])
  dp[i] = min(dp[i-2] + cost1, dp[i-1] + cost2)

print(dp[n-1])

Measured memory_bytes: 13928
n=int(input())
a=[0]+[int(i) for i in input().split()]+[0]
total=0
for i in range(n+1):
  total+=abs(a[i+1]-a[i])
for i in range(n):
  print(total-(abs(a[i+1]-a[i])+abs(a[i+2]-a[i+1])-abs(a[i+2]-a[i]))) 

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

int main() {
  string s;
  cin >> s;
  int n = s.size(),l = 0,r = n-1,ans = 0;
  while(l < r){
    if(s[l] == s[r]){
      l++;
      r--;
    }
    else if(s[l] == 'x'){
      l++;
      ans++;
    }
    else if(s[r] == 'x'){
      r--;
      ans++;
    }
    else{
      cout << -1 << endl;
      return 0;
    }
  }
  cout << ans << endl;
}

Measured memory_bytes: 512
import java.util.*;

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

    String s[] = sc.next().split("");

    int a = 0;
    int b = 0;
    for (int i = 0; i < s.length; i++) {
      if (i % 2 == 0) {
        if (!(s[i].equals("R")) && !(s[i].equals("U")) && !(s[i].equals("D"))) a = 1;
      } else {
        if (!(s[i].equals("L")) && !(s[i].equals("U")) && !(s[i].equals("D"))) b = 1;
      }
    }

    if (a == 1 || b == 1) {
      System.out.println("No");
    } else {
      System.out.println("Yes");
    }

  }
}


Measured memory_bytes: 25172
#include<iostream>
#include<cstring>
#include<stdio.h>

using namespace std;
int main(){
    int n,score1=0,score2=0;
    char str1[101],str2[101];
    scanf("%d",&n);
    for(int i=0;i<n;i++){
        scanf("%s %s",str1,str2);
        int len1=strlen(str1);
        int len2=strlen(str2);
        int len=len1>=len2?len1:len2;
        for(int j=0;j<len;j++){
            if(str1[j]>str2[j]){
                score1=score1+3;
                break;
            }else if(str1[j]<str2[j]){
                score2=score2+3;
                break;
            }else{
                if((j==(len1-1))&&(j==(len2-1))){
                    score1++;
                    score2++;
                    break;
                }
            }
        }
    }
    cout<<score1<<" "<<score2<<endl;
}


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

int main(){
    string s;
    cin >> s;
    int num;
    int mi = 10000;
    for (int i = 0;i < s.size()-2;i++){
        num = (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10 + (s.at(i+2)-'0')*1;
        mi = min(mi,abs(num - 753)); 
    }
    cout << mi << endl;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define mp make_pair
#define pb push_back
#define rep(i, a, b) for(int i=(a); i<(b); i++)
#define sz(a) (int)a.size()
#define de(a) cout<<#a<<" = "<<a<<endl
#define dd(a) cout<<#a<<" = "<<a<<" "
typedef long long ll;
typedef double db;
typedef pair<int, int> pii;
typedef vector<int> vi;
//----
const int N=30;
char s[N];
int n;
ll ans;
void dfs(int cur){
	if(cur==n){
		ll now=0;
		rep(i, 0, n){
			if(s[i]==0)continue;
			if(s[i]=='+')
				ans+=now, now=0;
			else
				now=now*10+s[i]-'0';
		}
		ans+=now;
		return ;
	}
	dfs(cur+1);
	if(s[cur]==0){
		s[cur]='+';
		dfs(cur+1);
		s[cur]=0;
	}
}
int main(){
	scanf("%s", s);
	n=strlen(s);
	if(n==1)printf("%s", s);
	else{
		for(int i=n-1, j=2*n-2; ~i; j-=2, i--)
			s[j]=s[i];
		for(int i=1; i<2*n; i+=2)
			s[i]=0;
		n=2*n-1;
		dfs(0);
		printf("%lld\n", ans);
	}
	return 0;
}


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

using namespace std;

#define INF 1e9
#define MAXN 100005
#define MAXM 100005
#define MOD 1000000007
#define ll long long
#define vi vector<int>
#define vll vector<long long>
#define rep(i,n) for(int i=0, i##_len=(n); i<i##_len; ++i)
#define pii pair<int, int>

ll ans;
int A,B, diff;

void solve(){
    diff = B - A;
    cout << diff*(diff+1)/2 - B << endl;
}

int main(){
    cin >> A >> B;

    solve();
}


Measured memory_bytes: 256
import heapq as hq
def main():
    n,k=map(int,input().split(' '))
    a_b=[[i for i in list(map(int,input().split(' ')))] for i in range(n)]
    hq.heapify(a_b)
    cnt = 0
    while cnt < k:
        ans,c = hq.heappop(a_b)
        cnt += c
    print(ans)
if __name__ == '__main__':
    main()

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

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<string> &o) {
    string a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

typedef pair<ll, ll> P;


struct Town {
    ll x, y;
    int town_id;
};

std::istream &operator>>(std::istream &in, Town &o) {
    cin >> o.x >> o.y;
    return in;
}

template<typename T>
struct edge {
    int src, to;
    T cost;

    edge(int src, int to, T cost) : src(src), to(to), cost(cost) {}

    edge &operator=(const int &x) {
        to = x;
        return *this;
    }

    operator int() const { return to; }
};

template<typename T>
using Edges = vector<edge<T> >;
template<typename T>
using WeightedGraph = vector<Edges<T> >;
using UnWeightedGraph = vector<vector<int> >;
template<typename T>
using Matrix = vector<vector<T> >;

struct UnionFind {
    vector<int> data;

    UnionFind(int sz) {
        data.assign(sz, -1);
    }

    bool unite(int x, int y) {
        x = find(x), y = find(y);
        if (x == y) return (false);
        if (data[x] > data[y]) swap(x, y);
        data[x] += data[y];
        data[y] = x;
        return (true);
    }

    int find(int k) {
        if (data[k] < 0) return (k);
        return (data[k] = find(data[k]));
    }

    int size(int k) {
        return (-data[find(k)]);
    }
};

template<typename T>
T kruskal(Edges<T> &edges, int V) {
    sort(begin(edges), end(edges), [](const edge<T> &a, const edge<T> &b) {
        return (a.cost < b.cost);
    });
    UnionFind tree(V);
    T ret = 0;
    for (auto &e : edges) {
        if (tree.unite(e.src, e.to)) ret += e.cost;
    }
    return (ret);
}

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

    vector<Town> towns(n);
    rep(i, n) cin >> towns[i], towns[i].town_id = i;

    Edges<ll> edges;

    sort(towns.begin(), towns.end(), [](Town e1, Town e2) { return e1.x < e2.x; });
    rep(i, n - 1) {
        Town t1 = towns[i];
        Town t2 = towns[i + 1];

        ll cost = t2.x - t1.x;
        edges.push_back(edge<ll>(t1.town_id, t2.town_id, cost));
        edges.push_back(edge<ll>(t2.town_id, t1.town_id, cost));
    }

    sort(towns.begin(), towns.end(), [](Town e1, Town e2) { return e1.y < e2.y; });
    rep(i, n - 1) {
        Town t1 = towns[i];
        Town t2 = towns[i + 1];

        ll cost = t2.y - t1.y;
        edges.push_back(edge<ll>(t1.town_id, t2.town_id, cost));
        edges.push_back(edge<ll>(t2.town_id, t1.town_id, cost));
    }
    ll now = kruskal<ll>(edges, n);

    cout << now << endl;
}


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

int div(int A, int B, int mod_p) {
  stack<int> q_stack;
  int a = B, b = mod_p, r;
  while (b) {
    q_stack.push(a / b);
    r = a % b; a = b; b = r;
  }
  long u = 1, v = 0;
  while (!q_stack.empty()) {
    int q = q_stack.top(); q_stack.pop();
    long u1 = v, v1 = u-q*v; u = u1 % mod_p; v = v1 % mod_p;
  }
  return (long)A * (u + mod_p) % mod_p;
}

int main() {
  int DIV = 1e+9 + 7;
  int N, K;
  cin >> N >> K;
  long factorial = 1, fac[N+1];
  for (int i = 0; i <= N; i++) {
    fac[i] = factorial;
    factorial *= i + 1; factorial %= DIV;
  }
  int res = 0, max_m = min(N-1, K);
  for (int m = 0; m <= max_m; m++) {
    long a = div(fac[N-1], (long)fac[m] * fac[N-1-m] % DIV, DIV);
    a *= div(fac[N], (long)fac[m] * fac[N-m] % DIV, DIV);
    a %= DIV;
    res = (res + a) % DIV;
  }
  cout << res << endl;
}

Measured memory_bytes: 1792
//的場梨沙★担当
//結城晴★副担当
//日野茜★副担当
#include <vector>
#include <list>
#include <map>
#include <climits>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <deque>
#include <stack>
#include <bitset>
#include <algorithm>
#include <functional>
#include <numeric>
#include <utility>
#include <sstream>
#include <iostream>
#include <cmath>
#include <cstdlib>
#include <cctype>
#include <string.h>
#include <string>
#include <cstring>
#include <ctime>
#include <queue>
#include <random>
#include <cctype>
#include <complex>
#include <regex>
#include <unordered_map>
#include <string>
#include <algorithm>
#include <cctype>
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <iomanip>
#include <iostream>
#include <stdio.h>
#include <string.h>
#include <vector>
#include <stdio.h>


using namespace std;

int main(void) {
    int A,B;
    cin>>A>>B;
    int C=0;
    for(int i=1;i<=3;i++){
        if((A*B*i)%2!=0){
           C++;
        }
    }

    if(C==0){
        cout<<"No"<<endl;
    }
    else{
        cout<<"Yes"<<endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
int n;
long long a[404], b[404], d[404][404];
int main() {
    cin >> n;
    for (int i = 1; i <= n; i++) cin >> a[i];
    for (int i = 1; i <= n; i++) b[i] = b[i - 1] + a[i];
    for (int i = 1; i < n; i++) for (int j = 1; j + i <= n; j++) {
        d[j][j + i] = 1e18;
        for (int k = j; k < j + i; k++)
            d[j][j + i] = min(d[j][j + i],
                              d[j][k] + d[k + 1][j + i]);
        d[j][j + i] += b[j + i] - b[j - 1];
    }
    cout << d[1][n] << '\n';
}


Measured memory_bytes: 1536
#include <iostream>
#include <vector>
#include <cmath>
#include <algorithm>
#define INT_MAX	2147483647

using namespace std;

int main()
{
    int n, k;
    cin >> n >> k;
    vector<int> h(n);
    for(int i = 0; i < n; i++)
    {
        cin >> h[i];
    }
    vector<int> dp(n, INT_MAX);
    dp[0] = 0;
    for(int i = 1; i < n; i++)
    {
        for(int j = 1; j <= k && i - j > -1; j++)
        {
            dp[i] = min(dp[i - j] + abs(h[i] - h[i - j]), dp[i]);
        }
    }
    cout << dp[n - 1];

    return 0;
}


Measured memory_bytes: 1024
def main():
    N = [0] * 3
    U = [0] * 2
    U[0], U[1], N[0], N[1], N[2] = map(int, input().split())
    V = [None] * 3
    V[0] = sorted(list(map(int, input().split())), reverse=True)
    V[1] = sorted(list(map(int, input().split())), reverse=True)
    V[2] = sorted(list(map(int, input().split())), reverse=True)
    idx = [0] * 3
    total = 0
    while sum(idx) < sum(U):
        mx = (0, -1)
        for i in range(3):
            if idx[i] < N[i] and (i >= 2 or idx[i] < U[i]):
                mx = max(mx, (V[i][idx[i]], i))
        idx[mx[1]] += 1
        total += mx[0]
    print(total)


if __name__ == "__main__":
    main()


Measured memory_bytes: 106980
import sys
 
 
f = [0, 1] * 500000
 
i = 3
while i <= 1000:
    if f[i] == 1:
        j = i * i
        while j <= 1000000:
            f[j] = 0
            j += i + i
    i += 2
 
f.pop(0)
f.pop(1)
 
for n in sys.stdin:
    i = int(n)
    if i < 2:
        print(0)
    else:
        print(sum(f[:i - 1]))

Measured memory_bytes: 24208
#include <iostream>
#include <fstream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <string>
#include <set>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <bitset>
#include <algorithm>
#include <complex>
#include <array>
#include <iomanip>
using namespace std;

#define REP(i,n) for(int i=0; i<n; ++i)
#define FOR(i,a,b) for(int i=a; i<=b; ++i)
#define FORR(i,a,b) for (int i=a; i>=b; --i)
#define ALL(c) (c).begin(), (c).end()

typedef long long ll;
typedef vector<int> VI;
typedef vector<ll> VL;
typedef vector<long double> VD;
typedef vector<VI> VVI;
typedef vector<VL> VVL;
typedef vector<VD> VVD;
typedef pair<int,int> P;
typedef pair<ll,ll> PL;

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

int in() { int x; scanf("%d", &x); return x; }
ll lin() { ll x; scanf("%lld", &x); return x; }
#define INF 1LL<<60

int main() {
    double a, b, x;
    cin >> a >> b >> x;
    x /= a;
    double ans;
    if(x <= a * b / 2.0) {
        cerr << "little " << 2 * x / b << endl;
        ans = atan2(b, 2 * x / b);
    } else {
        cerr << "a lot" << endl;
        // cerr << 2* (a * b - x) / a << endl;
        ans = atan2(2* (a * b - x) / a, a);
    }
    printf("%.8f\n", 180 * ans / M_PI);
    return 0;
}

Measured memory_bytes: 4140
#include<iostream>
using namespace std;
int main()
{
  int n;
  cin >> n;
  if(n==25)
    cout << "Christmas" << endl;
  else if(n==24)
    cout << "Christmas Eve" << endl;
  else if(n==23)
    cout << "Christmas Eve Eve" << endl;
  else
    cout << "Christmas Eve Eve Eve" << endl;
  return 0;
}

Measured memory_bytes: 256
N,K = map(int, input().split())
p = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = -1* 10**9

for si in range(N):
  s = list()
  total = 0
  l = 0
  x = si
  while(1):
    x = p[x] - 1
    s.append(c[x])
    total += c[x]
    l += 1
    if x == si:
      break
  t = 0
  for j in range(l):
    t += s[j]
    now = t
    if j >= K:
      break
    if total > 0:
      e = (K-j-1)//l
      now += total * e
    ans = max(ans, now)

print(ans)

Measured memory_bytes: 80984
#include<cstdio>
#include<algorithm>
#include<set>
#include<vector>
using namespace std;
int n, K, Mod;
int D[88][88][200], T[88][88][200];
void Do(int cur) {
	int i, j, k;
	for (i = 0; i < 80; i++)for (j = 0; j < 80; j++)for (k = 0; k < 160; k++)T[i][j][k] = 0;
	for (i = 0; i < 80; i++) {
		for (j = 0; j < 80; j++) {
			for (k = 0; k < 160; k++) {
				if (!D[i][j][k])continue;
				if (!(cur & 1)) {
					if (k != 157 && cur % 2 != k % 2) {
						T[0][j][k] = (T[0][j][k] + D[i][j][k]) % Mod;
					}
					else T[0][j][157] = (T[0][j][157] + D[i][j][k]) % Mod;

					int nk = k;
					int ni = min(i + 1, K + 1);
					if (j >= ni) {
						int needed = ((K + 2) - (ni + ni + 1)) / 2;
						if (j >= needed + ni) {
							nk = min(nk, needed * 2 + cur + 1);
						}
					}
					if (nk <= cur) {
						int z = -1;
						continue;
					}
					T[ni][j][nk] = (T[ni][j][nk] + D[i][j][k]) % Mod;
				}
				else {

					if (k != 157 && cur % 2 != k % 2) {
						T[i][0][k] = (T[i][0][k] + D[i][j][k]) % Mod;
					}
					else T[i][0][157] = (T[i][0][157] + D[i][j][k]) % Mod;

					int nk = k;
					int nj = min(j + 1, K + 1);
					if (i >= nj) {
						int needed = ((K + 2) - (nj + nj + 1)) / 2;
						if (i >= needed + nj) {
							nk = min(nk, needed * 2 + cur + 1);
						}
					}
					if (nk <= cur) {
						int z = -1;
						continue;
					}
					T[i][nj][nk] = (T[i][nj][nk] + D[i][j][k]) % Mod;
				}
			}
		}
	}
	for (i = 0; i < 80; i++)for (j = 0; j < 80; j++)for (k = 0; k < 160; k++)D[i][j][k] = T[i][j][k];
}
int DP[160][90][90];
int main() {
	int i, j, k;
	scanf("%d%d%d", &n, &K, &Mod);
	if (K % 2 == 1) {
		D[0][0][157] = 1;
		for (i = 1; i <= n; i++) {
			Do(i);
		}
		int res = 0;
		for (i = 0; i < 80; i++)for (j = 0; j < 80; j++)for (k = 0; k < 160; k++)res = (res + D[i][j][k]) % Mod;
		printf("%d\n", res);
		return 0;
	}
	DP[0][0][0] = 1;
	for (i = 1; i <= n; i++) {
		for (j = 0; j <= n / 2; j++) {
			for (k = 0; k <= n / 2; k++) {
				if (!DP[i - 1][j][k])continue;
				if (i % 2) {
					DP[i][0][k] = (DP[i][0][k] + DP[i - 1][j][k]) % Mod;
					if (j + 1 <= K/2)DP[i][j + 1][k] = (DP[i][j + 1][k] + DP[i - 1][j][k]) % Mod;
				}
				else {
					DP[i][j][0] = (DP[i][j][0] + DP[i - 1][j][k]) % Mod;
					if (k + 1 <= K/2)DP[i][j][k + 1] = (DP[i][j][k + 1] + DP[i - 1][j][k]) % Mod;
				}
			}
		}
	}
	int res = 0;
	for (i = 0; i <= n / 2 + 1; i++)for (j = 0; j <= n / 2 + 1; j++)res = (res + DP[n][i][j]) % Mod;
	printf("%d\n", res);
}


Measured memory_bytes: 12800
fn add1(v: &mut Vec<String>, n: usize) {
    if n == 1 {
        return;
    }

    let v2 = v.clone();
    v.clear();

    for s in v2 {
        let sv = s.chars().map(|c| c as u8 - 97).collect::<Vec<_>>();
        let min = sv.iter().max().unwrap();
        //println!("{:?} {}", sv, min);
        for i in 0..min + 2 {
            let mut sv2 = sv.clone();
            sv2.push(i);
            let a = sv2.iter().map(|&i| (i + 97) as char).collect::<String>();
            v.push(a);
        }
    }

    add1(v, n - 1);
}

fn main() {
    let n = read::<usize>();
    let mut v = vec!["a".to_string()];

    add1(&mut v, n);
    v.sort();
    for s in v {
        println!("{}", s);
    }
}

#[allow(dead_code)]
fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}
#[allow(dead_code)]
fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>()
        .split_whitespace()
        .map(|e| e.parse().ok().unwrap())
        .collect()
}
#[allow(dead_code)]
fn read_vec2<T: std::str::FromStr>(n: u32) -> Vec<Vec<T>> {
    (0..n).map(|_| read_vec()).collect()
}
#[allow(dead_code)]
fn yn(result: bool) {
    if result {
        println!("Yes");
    } else {
        println!("No");
    }
}


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

int gcm(int a, int b){
    if(a<b) return gcm(b, a);
    else if(a%b==0) return b;
    else return gcm(b, a%b);
}
int main() {
	int N, X; cin >> N >> X;
	int loc[100010];
	for(int i=0; i<N; ++i) cin >> loc[i];
	for(int i=0; i<N; ++i) loc[i]=abs(X-loc[i]);
	bool f=true;
	sort(loc, loc + N, greater<int>());
	int G=loc[0];
	for(int i=1; i<N; ++i){
	    if(loc[i]==0) break;
	    else G=gcm(G, loc[i]);
	}
	cout << G << endl;
	return 0;
}


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

int main() {
  long long N, M;
  cin >> N;
  M = N;
  int digit = 0;
  while(N > 0) {
    digit += N % 10;
    N = N / 10;
  }
  if(M%digit == 0) {
    cout << "Yes" << endl;
  }
  else {
    cout << "No" << endl;
  }
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define ll long long
#define fi first
#define se second
#define pb push_back
#define rep(i, s, n) for (int i = s; i < n; i++)
#define rrep(i, s, n) for (int i = (n)-1; i >= (s); i--)
#define all(a) a.begin(),a.end()
typedef pair<int,int>pint;
typedef vector<int>vint;
typedef vector<pint>vpint;
const long long MOD = 1000000007, INF = 1e17;
 
#define endl '\n'
#define IOS() ios_base::sync_with_stdio(0);cin.tie(0)
 
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;}
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;}



signed main()
{
	//IOS();
	vector<int>ans;
	while(1){
		string s;
		cin >> s;
		if(s == "#")break;
		int y,m,d;
		cin>>y>>m>>d;
		if(y>31||(y==31&&m>4)){
			printf("? %lld %lld %lld\n",y-30,m,d);
		}else{
			printf("HEISEI %lld %lld %lld\n",y,m,d);
		}
	}
}



Measured memory_bytes: 3276
#include <bits/stdc++.h>
#define int long long
#define ALL(v) (v).begin(),(v).end()
#define Vi vector<int>
#define pb push_back
#define rep(i,a,b) for(int i=a;i<b;i++)
#define repr(i,a,b) for(int i=a;i>b;i--)
#define leng(n) (int)(log10(n)+1)
#define INF 9000000000000000000
#define MOD 1000000007
using namespace std;

int gcd(int a,int b){return b?gcd(b,a%b):a;}  //  最大公約数gcd
int lcm(int a,int b){return a/gcd(a,b)*b;}  //  最小公倍数lcm

signed main() {
  int n;
  int ans = 1;
  cin >> n;
  rep(i,0,n){
    ans *= i+1;
    ans %= MOD;
  }
  cout << ans << endl;
}


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

/* snippet: useful macros and functions */
#define ARC(i, a, b) for(Int i = (a); i < (b); ++i)
#define RC(i, n) ARC(i, 0, n)
#define ARCH(i, a, b) for(Int i = (a) - 1; i >= (b); --i)
#define RCH(i, n) ARCH(i, n, 0)
template<class T> T ant(const T &a, const T &b){ return a > b ? a : b; }
template<class T> T ont(const T &a, const T &b){ return a < b ? a : b; }
template<class T> T rng(const T &a, const T &b){ return a < b ? b - a : a - b; }
template<class T> void th(T &a, const T &b, T (*f)(const T &, const T &)){ a = f(a, b); }
#define anth(a, b) th(a, b, ant)
#define onth(a, b) th(a, b, ont)

/* snippet: modint library */
template<class T, int MOD>
class Modint{
	T val;
public:
	Modint(T val = 0) : val(val) {}
	operator T(){ return val; }
	Modint &operator+=(const Modint &a){ val += a.val; if(val >= MOD) val -= MOD; return *this; }
	Modint &operator-=(const Modint &a){ val -= a.val; if(val < 0) val += MOD; return *this; }
	Modint &operator*=(const Modint &a){ val = val * a.val % MOD; return *this; }
	void inverse(){T x[2]={MOD,val},a[2]={0,1};int i;for(i=0;x[!i];i^=1){a[i]-=x[i]/x[!i]*a[!i];x[i]=x[i]%x[!i];}if(!i)a[i]+= MOD;val=a[i];}
	Modint &operator/=(Modint a){ a.inverse(); return *this *= a; }
	friend Modint modpow(Modint a, int n){ Modint ret(1); while(n){ if(n & 1) ret *= a; a *= a; n >>= 1; } return ret; }
	friend Modint operator+(Modint a, const Modint &b){ return a += b; }
	friend Modint operator-(Modint a, const Modint &b){ return a -= b; }
	friend Modint operator*(Modint a, const Modint &b){ return a *= b; }
	friend Modint operator/(Modint a, const Modint &b){ return a /= b; }
	friend std::ostream &operator<<(std::ostream &os, const Modint &a){ return os << a.val; }
};

/* snippet: using declarations */
using Int = unsigned long long;
using namespace std;
using Mint = Modint<long long, 1000000007>;

int main(){
	Int n, k;
	cin >> n >> k;
	Int ans = n % k;
	onth(ans, k - ans);
	cout << ans << endl;
}


Measured memory_bytes: 256
//Subhash Suman
//Date: 14/02/19 ; Day: Thursday ; Time: 07::11::03 
//Description : 

#include<bits/stdc++.h>
#define ll long long int
#define MAX INT_MAX
#define MIN INT_MIN
#define vi vector<int>
#define pii pair<int,int>
#define mii map<int,int>

using namespace std;
const int N = 3005;
ll arr[N];
ll dp[N][N];

int main(){
ios_base::sync_with_stdio(false);
cin.tie(NULL);
    int n;
    cin>>n;
    for(int i = 0; i < n; i++){
        cin>>arr[i];
    }
    for(int i = 0; i < n; i++){
        dp[i][i] = arr[i];
    }
    for(int i = 1; i < n; i++){
        for(int j = 0; j < n-i; j++){
            dp[j][j+i] = max(arr[j]-dp[j+1][j+i],arr[j+i]-dp[j][j+i-1]);
        }
    }
    cout<<dp[0][n-1]<<'\n';
    return 0;
}

Measured memory_bytes: 70016
// D - Line++
#include <bits/stdc++.h>
using namespace std;
#define rp(i,s,e) for(int i=(s);i<(e);++i)
int cnt[2000];

int main(){
	int N,X,Y; cin>>N>>X>>Y; X--,Y--;
	rp(i, 0, N) rp(j, i+1, N)
		cnt[min(j-i, abs(X-i) + abs(Y-j) + 1) - 1]++;
	rp(i, 0, N-1) cout<< cnt[i] <<endl;
}

Measured memory_bytes: 256
import java.util.Scanner;

//Roll-A-Big-Ball
public class Main{

final double EPS = 1e-8;
	
	double dot(double[] a, double[] b){
		return a[0]*b[0]+a[1]*b[1];
	}
	double cross(double[] a, double[] b){
		return a[0]*b[1]-a[1]*b[0];
	}
	double norm(double[] a){
		return Math.hypot(a[0], a[1]);
	}
	double norm(double[] a, double[] b){
		return Math.hypot(a[0]-b[0], a[1]-b[1]);
	}
	double[] sub(double[] a, double[] b){
		return new double[]{a[0]-b[0], a[1]-b[1]};
	}
	double ex(double[] a, double[] b, double[] c){
		double[] s1 = sub(b, a), s2 = sub(c, a);
		return cross(s1, s2);
	}
	double area(double[] a, double[] b, double[] c){
		double res = cross(a, b)+cross(b, c)+cross(c, a);
		return Math.abs(res)/2;
	}
	boolean crossing(double[] a, double[] b, double[] s, double[] t){
		if(Math.abs(cross(sub(b, a), sub(t, s)))<EPS){
			return Math.min(dist(a, b, s), Math.min(dist(a, b, t), Math.min(dist(s, t, a), dist(s, t, b))))<EPS;
		}
		if(ex(a, b, s)*ex(a, b, t)>0)return false;
		if(ex(b, a, s)*ex(b, a, t)>0)return false;
		if(ex(s, t, a)*ex(s, t, b)>0)return false;
		return ex(t, s, a)*ex(t, s, b)<0;
	}
	//Segment a-b Point p
	double dist(double[] a, double[] b, double[] p){
		if(dot(sub(b, a), sub(p, a))<EPS)return norm(a, p);
		if(dot(sub(a, b), sub(p, b))<EPS)return norm(b, p);
		return Math.abs(cross(sub(b, a), sub(p, a)))/norm(a, b);
	}
	//Segment a-b Segment s-t
	double dist(double[] a, double[] b, double[] s, double[] t){
		if(crossing(a, b, s, t))return 0;
		return Math.min(dist(a, b, s), Math.min(dist(a, b, t), Math.min(dist(s, t, a), dist(s, t, b))));
	}
	
	double[] S, T;
	double[][][] p;
	
	boolean in(int k){
		double area = norm(p[k][0], p[k][1])*norm(p[k][1], p[k][2]);
		double s = 0;
		for(int i=0;i<4;i++)s+=area(p[k][i], p[k][(i+1)%4], S);
		return Math.abs(area-s)<EPS;
	}
	
	void run(){
		Scanner sc = new Scanner(System.in);
		for(;;){
			int n = sc.nextInt();
			if(n==0)break;
			S = new double[]{sc.nextDouble(), sc.nextDouble()}; T = new double[]{sc.nextDouble(), sc.nextDouble()};
			p = new double[n][4][2];
			double[] h = new double[n];
			for(int i=0;i<n;i++){
				double x1 = sc.nextDouble(), y1 = sc.nextDouble(), x2 = sc.nextDouble(), y2 = sc.nextDouble();
				h[i] = sc.nextDouble();
				p[i][0] = new double[]{x1, y1};
				p[i][1] = new double[]{x2, y1};
				p[i][2] = new double[]{x2, y2};
				p[i][3] = new double[]{x1, y2};
//				for(int j=0;j<4;j++){
//					System.out.println(crossing(S, T, p[i][j], p[i][(j+1)%4]));
//					System.out.println(dist(S, T, p[i][j], p[i][(j+1)%4]));
//				}
			}
			double R = 1000;
			for(int i=0;i<n;i++){
				if(in(i)){
					R = 0; break;
				}
				double d = 1<<29;
				for(int j=0;j<4;j++)d = Math.min(d, dist(S, T, p[i][j], p[i][(j+1)%4]));
				if(h[i]<d)R = Math.min(R, (h[i]*h[i]+d*d)/2/h[i]);
				else R = Math.min(R, d);
			}
			System.out.printf("%.6f\n", R);
		}
	}
	
	public static void main(String[] args) {
		new Main().run();
	}
}

Measured memory_bytes: 13000
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod = 1e9;
static const ll INF = 1LL << 50;
using namespace std;

int gcd(int a,int b) {
	while (b != 0) {
		int t = a % b; a = b; b = t;
	}
	return a;
}

int main() {
	int n,ans;
	cin >> n;
	vector<int>a(n);
	repp(i, 0, n) cin >> a[i];
	sort(a.begin(), a.end());
	ans = a[0];
	repp(i, 1, n) {
		ans=gcd(ans, a[i]);
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 640
#include<bits/stdc++.h>
#define pb push_back
using namespace std;
float pi=3.141592653; 
int main(){
   int k;string s;
   cin>>k>>s;
   if(s.size()<=k)
        cout<<s;
    else {
        for(int i=0;i<k;i++) 
            cout<<s[i];   
        cout<<"...";
    }
    
   
    return 0;
}

Measured memory_bytes: 3624
import java.util.Arrays;
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner in = new Scanner(System.in);
		int h = in.nextInt();
		int w = in.nextInt();
		String[] a = new String[h];
		for (int i = 0; i < h; i++) {
			a[i] = in.next();
		}

		boolean[] row = new boolean[h];
		Arrays.fill(row, false);
		boolean[] col = new boolean[w];
		Arrays.fill(col, false);
		for (int i = 0; i < h; i++) {
			for (int j = 0; j < w; j++) {
				if (a[i].charAt(j) == '#') {
					row[i] = true;
					col[j] = true;
				}
			}
		}

		for (int i = 0; i < h; i++) {
			if (row[i]) {
				for (int j = 0; j < w; j++) {
					if (col[j]) {
						System.out.print(a[i].charAt(j));
					}
				}
				System.out.println();
			}
		}
	}
}

Measured memory_bytes: 24912
#include <iostream>

using namespace std;

int main()
{
   int i,n,m,s[105],j=0;
   double c;
   cin>>n>>m;
   for(i=0;i<n;i++)
   {
       cin>>s[i];
       c+=s[i];
   }
   c=c/(4*m);
   for(i=0;i<n;i++)
   {
       if(s[i]>=c)
        j++;
   }
   if(j>=m)
    cout<<"Yes"<<endl;
   else
    cout<<"No"<<endl;
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define ALL(x) (x).begin(),(x).end()
#define uniq(x) (x).erase(unique(ALL(x)),(x).end())
#define SORT(x) sort(ALL(x))
#define REV(x) reverse(ALL(x))
#define foreach(it,x) for(__typeof((x).begin()) it=(x).begin();it!=(x).end();it++)
#define debug(x) cerr<<#x<<"="<<(x)<<endl
#define gett() cerr<<"Time:"<<clock()<<"ms."<<endl
int n,m;
string grid[2200];
int a[2200][2200],b[2200][2200];
int main(){
	//freopen("input.txt","r",stdin);
	//freopen("output.txt","w",stdout);
	ios::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	cin>>n>>m;
	for(int i=0;i<n;i++)
		cin>>grid[i];
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)if(grid[i][j]!='#'){
			int p=j;
			while(p<m&&grid[i][p]=='.') p++;
			for(int k=j;k<p;k++) a[i][k]=p-j;
			j=p-1;
		}
	}
	for(int i=0;i<m;i++){
		for(int j=0;j<n;j++)if(grid[j][i]!='#'){
			int p=j;
			while(p<n&&grid[p][i]=='.') p++;
			for(int k=j;k<p;k++) b[k][i]=p-j;
			j=p-1;
		}
	}
	int res=0;
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++)
			res=max(res,b[i][j]+a[i][j]-1);
	}
	cout<<res<<endl;
	return 0;
}


Measured memory_bytes: 41472
package main

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

const mod = 998244353
const facNum = 300001

func main() {
	sc := newScanner(os.Stdin)
	K, A, B := sc.i(), sc.i(), sc.i()
	for i := A; i <= B; i++ {
		if i%K == 0 {
			fmt.Println("OK")
			return
		}
	}
	fmt.Println("NG")

	//if K > A {
	//	fmt.Println("NG")
	//	return
	//}
	//m := A % K
	//if m == 0 {
	//	fmt.Println("OK")
	//	return
	//}
	//da := A / K
	//db := B / K
	//if db > da {
	//	fmt.Println("OK")
	//} else {
	//	fmt.Println("NG")
	//}

}

// fmt.Println("Yes")
// fmt.Println("No")

// I/O
type scanner struct {
	sc *bufio.Scanner
}

func newScanner(input io.Reader) *scanner {
	sc := bufio.NewScanner(input)
	sc.Split(bufio.ScanWords)
	sc.Buffer(make([]byte, 1024), int(1e+9))
	return &scanner{sc}
}

func (s *scanner) s() string {
	s.sc.Scan()
	return s.sc.Text()
}

func (s *scanner) i() int {
	i, e := strconv.Atoi(s.s())
	if e != nil {
		panic(e)
	}
	return i
}

func (s *scanner) f() float64 {
	f, e := strconv.ParseFloat(s.s(), 64)
	if e != nil {
		panic(e)
	}
	return f
}

func (s *scanner) bs() []byte {
	return []byte(s.s())
}

func (s *scanner) is(n int) []int {
	res := make([]int, n)
	for i := 0; i < n; i++ {
		res[i] = s.i()
	}
	return res
}

func (s *scanner) fs(n int) []float64 {
	res := make([]float64, n)
	for i := 0; i < n; i++ {
		res[i] = s.f()
	}
	return res
}

//const factorial = new
func Pow(a, n int) int {
	ans := 1
	for n > 0 {
		if (n & 1) == 1 {
			ans = ans * a % mod
		}
		a = a * a % mod
		n = n >> 1
	}
	return ans
}

func Gcd(a, b int) int {
	if a < b {
		return Gcd(b, a)
	}
	for b != 0 {
		a, b = b, a%b
	}
	return a
}

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

func combination(n, k int, fac, ifac []int) int {
	if n < k || n < 0 {
		return 0
	}
	if k == 0 {
		return 1
	}
	//while n != 0
	ans := ifac[k] * ifac[n-k] % mod
	return ans * fac[n] % mod
}

// 階乗: factorial
// コンビネーションを計算する際に前もって計算しておく
// fac[k] => k! (mod M)
// ifac[k] => k!^(M-2) (mod M)
// n: ex. 2 * 10^5 => 200001
// fac, ifac := factorial()
func factorial() (fac []int, ifac []int) {
	fac = make([]int, facNum)
	fac[0] = 1
	ifac = make([]int, facNum)
	ifac[0] = 1
	for i := 1; i < facNum; i++ {
		fac[i] = fac[i-1] * i % mod
		ifac[i] = ifac[i-1] * Pow(i, mod-2) % mod
	}
	return
}


Measured memory_bytes: 1760