akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
typedef long long ll;

int main(){
  int s,w;
  cin >> s >> w;
  if(s > w){
    cout << "safe";
  }else{
    cout << "unsafe";
  }
}

Measured memory_bytes: 3636
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include <string.h>
#include <algorithm>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <string>
#include <vector>
#include <bits/stdc++.h>
using namespace std;
 
const double TL = 1.5 * CLOCKS_PER_SEC;
mt19937 rng((unsigned int) chrono::steady_clock::now().time_since_epoch().count());
#define clr(x, y) memset(x, y, sizeof(x))
#define forn(i, n) for (int i = 0; i < n; i++)
#define LL long long
const double pi = acos(-1.0);

int n;
LL d;

int main() {
#ifdef LOCAL
  auto start_clock = clock();
  freopen("in", "r", stdin);
#endif
  int ans = 0;
  cin >> n >> d;
  for (int i = 0; i < n; i++) {
    LL x, y;
    cin >> x >> y;
    if (x * x + y * y <= d * d) {
      ans += 1;
    }
  }
  printf("%d\n", ans);


#ifdef LOCAL
 auto end_clock = clock();
 cout << "Time:" << (end_clock - start_clock) / CLOCKS_PER_SEC << endl;
#endif
  return 0;
}

Measured memory_bytes: 3764
#include<bits/stdc++.h>
#define rep(i,N) for(int i=0;i<(N);i++)
#define FOR(i,a,b) for(int i=(a);i<(b);i++)
using namespace std;
const long long MOD = 1e9 + 7;
const long long INF = 1e12;
const int inf = 1e9;
typedef long long ll;
typedef pair<ll,int> P;
typedef set<int> S;
int main(){
    int a,b,c;
    cin>>a>>b>>c;
    cout<<min(b/a,c)<<endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
    int N, W;
    cin>>N>>W;
    int w[N];
    long long val[N];
    for(int i=0; i<N; i++)
        cin>>w[i]>>val[i];
    for(int i=0; i<N; i++){
        for(int j=i+1; j<N; j++){
            if(w[i] > w[j]){
                swap(w[i], w[j]);
                swap(val[i], val[j]);
            }
        }
    }
    long long dp[N][W+1];
    for(int i=0; i<N; i++)
        dp[i][0] = 0;
    for(int i=1; i<=W; i++){
        if(w[0] <= i)
            dp[0][i] = val[0];
        else
            dp[0][i] = 0;
    }
    
    for(int i=1; i<N; i++){
        for(int j=1; j<=W; j++){
            if(j >= w[i]){
                dp[i][j] = max(val[i] + dp[i-1][j-w[i]], dp[i-1][j]);
            }
            else
                dp[i][j] = dp[i-1][j];
        }
    }
    cout<<dp[N-1][W];
}

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

#define COUT(x) cout << #x << " = " << (x) << ", "
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
typedef long long ll;
const int MOD = 1000000007;

int N,M;
vector<int> G[50];

int dfs(int n, vector<bool> flag){
  vector<bool> tmpflag = flag;
  tmpflag[n] = true;
  flag[n] = true;
  bool f = true;
  for(int i = 0; i < N; i++){
    f = f & flag[i];
  }
  if(f) return 1;
  int res = 0;
  bool oflag = false;
  for(auto x: G[n]){
    if(tmpflag[x] == false){
      res += dfs(x, tmpflag);
      oflag = true;
    }
  }
  if(oflag == false){
    return 0;
  }else{
    return res;
  }
}

int main(){
  cin >> N >> M;
  for(int i = 0; i < M; i++){
    int a,b;
    cin >> a >> b;
    a--; b--;
    G[a].push_back(b);
    G[b].push_back(a);
  }
  vector<bool> flag(N, false);
  int ans = dfs(0, flag);
  cout << ans << endl;
}


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

main()
{
    int n;
    cin >> n;
    int a[n];
    rep(i, 0, n, 1)
            cin >>
        a[i];

    ll dp[n + 1][3];
    dp[1][0] = a[0];
    dp[1][1] = max(a[0], a[1]);
    dp[1][2] = max(a[0], max(a[1], a[2]));
    rep(i, 2, n, 1)
    {
        rep(j, 0, 3, 1)
        {
            if (j == 0)
            {
                if (i % 2 == 0)
                {
                    dp[i][j] = dp[i - 1][j];
                }
                else
                {
                    dp[i][j] = dp[i - 1][j] + a[i - 1];
                }
            }
            else if (j == 1)
            {
                if (i % 2 == 0)
                {
                    dp[i][j] = max(dp[i - 1][j], dp[i - 1][0]);
                }
                else
                {
                    dp[i][j] = max(dp[i - 1][j] + a[i], dp[i][0]);
                }
            }
            else
            {
                if (i % 2 == 0)
                {
                    dp[i][j] = max(dp[i - 1][2], max(dp[i - 1][1], dp[i - 1][0]));
                }
                else
                {
                    dp[i][j] = max(dp[i][0], max(dp[i][1], dp[i - 1][2] + a[i + 1]));
                }
            }
        }
    }
    if(n % 2 == 1)
    {
        cout << dp[n - 2][2] << endl;
    }
    else
    {
        cout << dp[n-1][1] << endl;
    }
    
    

    return 0;
}

Measured memory_bytes: 9104
#include <stdio.h>
#include <stdlib.h>

#define MAX 101

int main() {
    int n, m;
    int *table[MAX];
    int d;
    int b[MAX];

    scanf("%d %d", &n, &m);
    for (int i=0; i<n; ++i) {
        table[i] = (int*)malloc(sizeof(int) * m);
        for (int j=0; j<m; ++j) {
            scanf("%d", &d);
            table[i][j] = d;
        }
    }

    for (int i=0; i<m; ++i) {
        scanf("%d", &b[i]);
    }

    for (int i=0; i<n; ++i) {
        int sum = 0;
        for (int j=0; j<m; ++j) {
            sum += table[i][j] * b[j];
        }
        printf("%d\n", sum);
        free(table[i]);
    }

    return 0;
}



Measured memory_bytes: 2132
import java.io.*;

public class Main {
    public static void main(String[] args) {
        InputStreamReader isr = new InputStreamReader(System.in);
        BufferedReader br = new BufferedReader(isr);
        try {
            while(true) {
                String[] str = br.readLine().split(" ");
                int x = Integer.parseInt(str[0]);
                int y = Integer.parseInt(str[1]);
                if(x == 0 && y == 0) {
                    break;
                }
                System.out.println((x < y ? x : y) + " " + (x > y ? x : y));
            }
        } catch(IOException e) {
            e.printStackTrace();
        }
    }
}

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

using namespace std;

typedef long long ll;
typedef long double ld;

void ng(string& s, int nc, const int& n) {
    if (s.size() == n) {
        cout << s << "\n";
        return;
    }
    for (int i = 0; i < nc; ++i) {
        s += 'a' + i;
        ng(s, nc, n);
        s.pop_back();
    }
    s += 'a' + nc;
    ng(s, nc + 1, n);
    s.pop_back();
}

int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    cout.tie(nullptr);
    int n;
    cin >> n;
    string s = "";
    ng(s, 0, n);
    return 0;
}


Measured memory_bytes: 1536
n = int(input())
t = list(map(int, input().split()))
a = list(map(int, input().split()))
mod = 10**9+7
ans = 1
if n == 1 and t != a:
    print(0)
    exit()
for i in range(1,n-1):
    if t[i-1] == t[i] and a[i] == a[i+1]:
        ans = (ans*min(t[i],a[i]))%mod
    elif t[i-1] < t[i] and t[i] > a[i]:
        print(0)
        exit()
    elif a[i] > a[i+1] and t[i] < a[i]:
        print(0)
        exit()
print(ans)

Measured memory_bytes: 19012
#include <iostream>

using namespace std;

int calc(int types[], int D, int c[], int s[][27])
{
    int last[27];
    for (int i = 1; i <= 26; i++)
    {
        last[i] = 0;
    }
    int satisfy = 0;
    for (int d = 1; d <= D; d++)
    {
        int today = types[d];
        satisfy += s[d][today];
        last[today] = d;
        for (int i = 1; i <= 26; i++)
        {
            satisfy -= c[i] * (d - last[i]);
        }
    }
    return satisfy;
}

int main()
{
    int D;
    cin >> D;
    int c[26 + 1];
    for (int i = 1; i <= 26; i++)
    {
        cin >> c[i];
    }
    int s[D + 1][26 + 1];
    for (int d = 1; d <= D; d++)
    {
        for (int j = 1; j <= 26; j++)
        {
            cin >> s[d][j];
        }
    }
    /*int types[D+1];
    for(int d=1;d<=D;d++){
        cin >> types[d];
    }*/

    int types[D + 1];
    for (int d = 1; d <= D; d++)
    {
        int i_max = 1;
        int s_max = 0;
        for (int i = 1; i <= 26; i++)
        {
            if (s[d][i] > s_max)
            {
                s_max = s[d][i];
                i_max = i;
            }
        }
        cout << i_max << endl;
        types[d] = i_max;
    }
    //cout << calc(types, D, c, s);
    return 0;
}

Measured memory_bytes: 3664
n = gets.chomp.to_i
vs = gets.chomp.split.map(&:to_i)
cs = gets.chomp.split.map(&:to_i)

sum = 0
(0..n-1).each do |i|
    sum += (vs[i] - cs[i]) if (vs[i] - cs[i]) > 0
end

puts sum

Measured memory_bytes: 1788
ceildiv a b = div (a + b - 1) b

main = do
    [a, b, c, d] <- map read . words <$> getLine :: IO [Int]
    let t1 = ceildiv c b
    let t2 = ceildiv a d
    putStrLn $ if t1 <= t2 then "Yes" else "No"


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

using namespace std;

const int MAX = 3000;
const int MOD = 1000000007;

long long fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for (int i = 2; i < MAX; i++){
        fac[i] = fac[i - 1] * i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD / i) % MOD;
        finv[i] = finv[i - 1] * inv[i] % MOD;
    }
}

// 二項係数計算
long long COM(int n, int k){
    if (n < k) return 0;
    if (n < 0 || k < 0) return 0;
    return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}

int main(void) {
    int N, K;
    cin >> N >> K;
    COMinit();
    for(int i=1; i<=K; i++) {
        cout << (COM(N-K+1, i) * COM(K-1, i-1)) % MOD << endl;
    }
    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
  
#define ll long long
#define all(aaa) aaa.begin(), aaa.end()

const int N = 1e5 + 5;
vector<int> g[N];
int a[N], b[N];
int z = 0, ans = 0;
bool used[N];

void dfs(int node) {
    used[node] = 1;

    if (b[node] == z)
        ans++;
    b[node] = z;
    if (b[a[node]] == z)
        ans++;
    b[a[node]] = z;

    for (int to : g[node]) {
        if (!used[to]) {
            dfs(to);
        }
    }
}

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

    int n, m;
    cin >> n >> m;

    for (int i = 0; i < n; i++) {
        cin >> a[i];
        a[i]--;
    }

    for (int i = 0; i < m; i++) {
        int x, y;
        cin >> x >> y;
        x--;
        y--;
        g[x].push_back(y);
        g[y].push_back(x);
    }

    for (int i = 0; i < n; i++) {
        if (!used[i]) {
            z++;
            dfs(i);
        }
    }

    cout << ans;
    
    return 0;   
}

Measured memory_bytes: 8576
package main

import (
	"fmt"
)

func main() {
	var n int
	fmt.Scan(&n)
	list := make([]int, n)
	total := 0
	for i:=0; i<n; i++ {
		fmt.Scan(&list[i])
		total += list[i]
	}
	s1 := 0
	ans := 10000000
	for i:=0; i<n; i++ {
		s1 += list[i]
		s2 := total - s1
		if ans > abs(s1-s2) {
			ans = abs(s1-s2)
		}
	}
	fmt.Println(ans)
}

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


Measured memory_bytes: 512
#include <stdio.h>
#include <stdlib.h>
typedef struct
{  int k;
   int l;
   int r;
}Node;
void print1(Node *t,int p)
{  if(t[p].l>=0) print1(t, t[p].l);
   printf(" %d", t[p].k);
   if(t[p].r>=0) print1(t, t[p].r);
}
void print2(Node *t,int p)
{   printf(" %d", t[p].k);
    if(t[p].l>=0) print2(t, t[p].l);
    if(t[p].r>=0) print2(t, t[p].r);
}
void insert(Node *t,int count,int z)
{  int x=0,y;
   if(count<1) x=-1;
   t[count].k= z;
   t[count].l = -1;
   t[count].r= -1;
   while(x>=0)
   {  y=x; 
      if(z<t[x].k)  x=t[x].l; 
      else x=t[x].r; 
   }
   if(count<1){}
   else if(z < t[y].k) t[y].l=count;
   else   t[y].r=count;
}
int main()
{  char s[10];
   Node *t;
   int m;
   int a;
   int i;
   int count=0;
   scanf("%d", &m);
   t=(Node*)malloc(sizeof(Node)*m);
   for(i=0;i<m;i++)
   {  scanf("%s", &s);
      if(s[0]=='i')
	  {  scanf("%d", &a);
	     insert(t,count,a);
		 count++;
	  }
      if(s[0]=='p')
	  {  if(count>0) print1(t, 0);
         printf("\n");
         if(count>0) print2(t, 0);
         printf("\n");
      }
   }
   return 0;
}


Measured memory_bytes: 8552
n = int(input())
a = [int(x) for x in input().split()]
a.sort()
flag = [False] * n
res = 0

for i in range(n):
  if flag[i]:
    continue
  
  c = 0
  j = i
  
  while a[i] == a[j]:
    c += 1
    flag[j] = True
    j += 1
    if j == n:
      break
  
  if c == a[i] or c == 0:
    continue
  elif c < a[i]:
    res += c
  else:
    res += c - a[i]
    
print(res)

Measured memory_bytes: 20632
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(sc.hasNext()){
            double velocity = sc.nextDouble();
            double height = Math.pow((velocity / 2),2) / 4.9;
            System.out.println((int)(Math.ceil(height / 5) * 5 + 5) / 5);
        }
    }
}



Measured memory_bytes: 27828
import java.util.*;

public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        int m = sc.nextInt();
        if (n % 3 == 0 || m % 3 == 0 || (n + m) % 3 == 0) {
            System.out.println("Possible");
        } else {
            System.out.println("Impossible");
        }
    }
}


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

using namespace std;
typedef long long ll;
#define mp make_pair

int main() {
	//	freopen("input.txt", "r", stdin);
	//	freopen("output.txt", "w", stdout);
	ios_base::sync_with_stdio(0);
	cin.tie(nullptr);	
	ll k;
	cin >> k;
	ll n = 50;
	ll t = n - (k % n);
	ll l = k / n;
	cout << 50 << endl;
	for (int i = 0; i < t; i++) 
		cout << (n - 1) + l + 1 - n + t - 1 << " ";
	for (int i = 0; i < n - t; i++)
		cout << (n - 1) + l + 1 + t << " ";
	cout << endl;
	return 0;
}

Measured memory_bytes: 256
open System

let a, b, c, k =
    let line = Console.ReadLine().Split(" ") |> Array.map int
    line.[0], line.[1], line.[2], line.[3]

let max =
    let mutable max = 0
    if a + b >= k then max <- min k a else max <- a - (k - (a + b))
    max

max |> Console.WriteLine


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


 

int main() {
 int H ,W;
cin >> H >> W;
for(int i =0; i < H;i++){
vector<char> vec(W);

for(int j =0; j < W; j++){
cin >> vec.at(j);}
for(int j =0; j < W; j++){
cout << vec.at(j);}
cout << endl;
for(int j =0; j < W; j++){
cout << vec.at(j);}
cout << endl;
}
}

Measured memory_bytes: 256
def diff(u, v):
    res = 0
    for i in range(len(u)):
        if u[i] != v[i]:
            res += 1

    return res


s = [int(item) for item in list(input())]
print(min(diff(s, [1 if i % 2 else 0 for i in range(len(s))]),
          diff(s, [0 if i % 2 else 1 for i in range(len(s))])))


Measured memory_bytes: 4652
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<cmath>
#include<set>
#include<map>

using namespace std;

int main(void) {
	int n, m;
	cin >> n;
	vector<int>t(n);
	for (int i = 0; i < n; i++)cin >> t[i];
	cin >> m;
	vector<int>p(m), x(m);
	for (int i = 0; i < m; i++)cin >> p[i] >> x[i];
	int sum;
	for (int i = 0; i < m; i++) {
		int copy = t[p[i]-1];
		t[p[i] - 1] = x[i];
		sum = 0;
		for (int j = 0; j < n; j++) {
			sum += t[j];
		}
		t[p[i]-1] = copy;

		cout << sum << endl;
	}
	return 0;
}

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

int main() {
  int a, b, c, d, e, k;
  cin >> a >> b >> c >> d >> e >> k;
  vector<int> location = {a, b, c, d, e};
  bool possible = true;
  for (int i=0; i<5; i++) {
    for (int j=1; j<5-i; j++) {
      if (location.at(i+j)-location.at(i) > k) {
        possible = false;
        break;
      }
      if (!possible) {
        break;
      }
    }
  }
  if (possible) {
    cout << "Yay!" << endl;
  }
  else {
    cout << ":(" << endl;
  }
}

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

namespace AtCoder2 {
	class Program {
		static void Main(string[] args) {

			//出力の都度更新をやめる
			var sw = new StreamWriter(Console.OpenStandardOutput()) { AutoFlush = false };
			Console.SetOut(sw);


			Ans();

			//更新する
			Console.Out.Flush();
			
		}
		public static void Ans() {

			var inputArray = retreiveLongArray();
			var inputCount = 1;

			// 不正な入力は処理しない
			if (inputArray.Length != inputCount) {
				Console.WriteLine("invalid input");
				return;
			}
			long N = inputArray[0];

			var keta = (int)Math.Truncate(Math.Log10(N))+1;

			var ans = 0;

			//桁以外の場合
			for (int i = 1; i < keta; i++) {
				ans += (int)Math.Pow(3, i) - 3 * (int)Math.Pow(2, i) + 3;
			}

			//最大桁の場合は、大小比較が必要
			var pattern = (int)Math.Pow(3, keta);

			for (int i = 0; i < pattern; i++) {
				var p = i;
				var num = 0;
				var three = false;
				var five = false;
				var seven = false;
				for (int j = 0; j < keta; j++) {
					var a= p % 3;
					var n = 0;
					if (a==0) {
						n = 3;
						three = true;
					}
					else if (a == 1) {
						n = 5;
						five = true;
					}
					else {
						n = 7;
						seven = true;
					}
					num *= 10;
					num += n;
					p /= 3;
				}
				if (num <= N && three && five && seven) {
					ans++;
				}

			}

			//答えの出力
			Console.WriteLine(ans);

		}

		/// <summary>
		/// スペースで区切られた文字列配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static string[] retreiveStringArray() {
			var inputArray = Console.ReadLine().Split(' ');
			return inputArray;
		}

		/// <summary>
		/// スペースで区切られた整数配列の入力を受け取る
		/// </summary>
		/// <returns></returns>
		private static long[] retreiveLongArray() {
			var inputArray = Console.ReadLine().Split(' ');
			var longArray = inputArray.Select(s => long.Parse(s));
			return longArray.ToArray();
		}


		/// <summary>
		/// 2組みずつの入力データ(数値)からTuppleListを作成する
		/// </summary>
		/// <param name="N"></param>
		/// <returns></returns>
		private static List<Tuple<long, long>> createLongTuppleList(long N) {
			var inpList = new List<Tuple<long, long>>();

			for (int i = 0; i < N; i++) {
				var inp = retreiveLongArray();
				var item1 = inp[0];
				var item2 = inp[1];
				inpList.Add(new Tuple<long, long>(item1, item2));
			}
			return inpList;
		}
	}
}


Measured memory_bytes: 28436
#include<set>
#include<map>
#include<ctime>
#include<queue>
#include<cmath>
#include<cstdio>
#include<vector>
#include<climits>
#include<cstring>
#include<iostream>
#include<algorithm>
#define LL long long
using namespace std;
int read(){
    int f=1,x=0;char s=getchar();   
    while(s<'0'||s>'9'){if(s=='-')f=-1;s=getchar();}  
    while(s>='0'&&s<='9'){x=x*10+s-'0';s=getchar();}
    return x*f;
}
#define eps 1e-8
#define MAXN 1000
#define INF 0x3f3f3f3f
#define Mod int(1e9+7)
int main(){
	int n=read(),T=read(),Ans=INF;
	for(int i=1;i<=n;i++){
		int x=read(),y=read();
		if(y<=T) Ans=min(Ans,x);
	}
	if(Ans==INF) puts("TLE");
	else printf("%d\n",Ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n, m) for (int i = (int)(n); i < (int)(m); i++)
#define repr(i, n, m) for (int i = (int)(n) - 1; i >= (int)(m); i--)
using namespace std;
using ll = int64_t;
const int MOD = 1000000007; // 10^9+7
// https://atcoder.jp/contests/abc048/tasks/abc048_b
int main() {
    ll a, b, x;
    cin >> a >> b >> x;

    ll ar = a % x;
    ll br = b % x;

    ll lower;
    if (ar == 0) {
        lower = a;
    } else {
        lower = a + x - ar;
    }

    ll higher;
    if (br == 0) {
        higher = b;
    } else {
        higher = b - br;
    }

    ll ql = lower / x;
    ll qh = higher / x;

    cout << qh - ql + 1 << endl;
}


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

const long long MOD = 1000000007;
const int INF = 1<<29;
const double EPS = 1e-8;
typedef vector<int> vec;
typedef pair<int,int> P;
typedef long long ll;

const int dx[] = {1, 0, -1, 0};
const int dy[] = {0, 1, 0, -1};

struct State{
    int y, x, k, c;
    State(int y, int x, int k, int c): y(y), x(x), k(k), c(c){}
    bool operator<(const State& right ) const {
        return c > right.c;
    }
};

int main(){
    while(1){
        int W, H;
        cin >> W >> H;
        if(W == 0) break;

        int field[30][30];
        for(int i=0;i<H;i++){
            for(int j=0;j<W;j++){
                cin >> field[i][j];
            }
        }

        int cost[4];
        for(int i=0;i<4;i++){
            cin >> cost[i];
        }

        int minDist[30][30][4];
        memset(minDist, -1, sizeof(minDist));
        priority_queue<State> que;
        que.emplace(0, 0, 0, 0);
        minDist[0][0][0] = 0;

        int ans;
        while(que.size()){
            State s = que.top(); que.pop();
            if(minDist[s.y][s.x][s.k] < s.c) continue;
            if(s.y == H-1 && s.x == W-1){
                ans = s.c;
                break;
            }
            for(int d=0;d<4;d++){
                int nk = (s.k+d)%4, nc = s.c;
                int ny = s.y + dy[nk], nx = s.x + dx[nk];
                if(ny<0 || H<=ny || nx<0 || W<=nx) continue;
                if(d != field[s.y][s.x]){
                    nc += cost[d];
                }
                if(minDist[ny][nx][nk] == -1 || minDist[ny][nx][nk] > nc){
                    minDist[ny][nx][nk] = nc;
                    que.emplace(ny, nx, nk, nc);
                }
            }
        }
        cout << ans << endl;
    }

    return 0;
}

Measured memory_bytes: 3208
#include<iostream>
#include<string>
#include<cinttypes>
#include<vector>
#include<queue>



using ui64 = std::uint64_t;
using ui32 = std::uint32_t;
using si32 = std::int32_t;

template<class T>
using array = std::vector<T>;

int main() {
	constexpr const auto mod = 1000'000'000 + 7;

	ui32 h, w;
	std::cin >> h >> w;

	array<std::string> board(h);
	for (auto&e : board)
		std::cin >> e;

	array<array<ui64>> tab(h, array<ui64>(w,0) );

	auto pt = [&]() {
		for (const auto&e : tab) {
			for (const auto&ee : e) {
				std::cout << ee << " ";
			}std::cout << "\n";
		}
	};


//	tab[h - 1][w - 1] = 1;

	/*
	for (ui32 i{}; i < h - 1; ++i) {
		const auto hi = h - (i + 1);//[h-1,1]
		tab[hi - 1].back()
			= board[hi-1].back()=='#'?0:tab[hi].back();
	}

	for (ui32 i{ 1 }; i <= w - 1; ++i) {
		const auto wi = w - i;
		tab.back()[wi - 1] = board.back()[wi - 1] == '#' ? 0 : tab.back()[wi];
	}

	*/

	//pt();

	
	auto hw = [](auto h_, auto w_) {
		return std::make_pair(h_, w_);
	};
	auto modify = [](const auto &pair, auto diff) {
		auto t = pair;
		t.first += diff.first;
		t.second += diff.second;
		return t;
	};

	const auto up = hw(-1, 0);
	const auto left = hw(0, -1);
	const auto down = hw(1, 0);
	const auto right = hw(0, 1);


	tab[0][0] = 1;
	std::queue<std::pair<si32, si32>> que;
	que.emplace(0, 0);


	while (!que.empty()) {


		const auto v = std::move(que.front()); que.pop();

		if (board[v.first][v.second] == '#')
			continue;


		auto&here = tab[v.first][v.second];
		if (here != 0 && !(v.first==0 && v.second==0 ) )
			continue;

		//std::cout << "(H, W, x) = " << v.first << " " << v.second << " " << here << "\n";
		for (auto&e : { up, left }) {
			const auto prev = modify(v, e);
			
			if ( prev.first<0 || prev.second <0 )
				continue;

			if ('#'== board[prev.first][prev.second])
				continue;

			here += tab[prev.first][prev.second];
			here %= mod;
		}

		if(v.first+1 < static_cast<si32>(h) )
			que.emplace(modify(v, down));

		if(v.second+1 < static_cast<si32>(w) )
			que.emplace(modify(v, right));
		

	}

	//pt();

	std::cout << tab[h-1][w-1] << "\n";
	return 0;
}


Measured memory_bytes: 9728
#include <iostream>
#include <cstdio>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#define rep(i, n) for(int i = 0; i < n; i++)
using namespace std;
typedef long long ll;

int N, M;
string board[60];
string pattern[60];

bool match(int x, int y) {
    int i, j;
    rep(i, M) {
        rep(j, M) {
            if(board[x+i][y+j] != pattern[i][j]) {
                return false;
            }
        }
    }
    return true;
}

int main() {
    cin >> N >> M;
    int i, j;
    rep(i, N) {
        cin >> board[i];
    }
    rep(i, M) {
        cin >> pattern[i];
    }
    bool found = false;

    for(i = 0; i <= N-M; i++) {
        for(j = 0; j <= N-M; j++) {
            if(match(i, j)) {
                found = true;
            }
        }
    }

    cout << (found ? "Yes" : "No") << endl;
    return 0;
}

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

#define LL long long
using namespace std;

LL count(string s, string pat){
    LL result = 0;
    for (int i = 0; i < s.length() - 1; i += 2){
        if(s[i] != pat[0]){
            result++;
        }
        if(s[i + 1] != pat[1]){
            result++;
        }
    }
    if(s.length() % 2 == 1){
        if(s[s.length() - 1] != pat[0]){
            result++;
        }
    }
    return result;
}

int main(void){
    string s, pat1, pat2;
    LL result1, result2;

    cin >> s;

    pat1.push_back('1');
    pat1.push_back('0');
    pat2.push_back('0');
    pat2.push_back('1');

    result1 = count(s, pat1);
    result2 = count(s, pat2);

    if(result1 < result2){
        cout << result1 << endl;
    }else{
        cout << result2 << endl;
    }

    return 0;
}



Measured memory_bytes: 512
#include<stdio.h>
int main(){
int a[10000],i,N=0;
scanf("%d",&a[0]);
for(i=1;a[i-1]!=0;i++)
{
scanf("%d",&a[i]);
N++;
}
for(i=0;i<=N-1;i++)
{printf("Case %d: %d\n",i+1,a[i]);
}
return 0;
}


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

int main() {
  int N, i;
  cin >> N ;
  
  vector<int> a(N);

  for (i = 0; i < N; i++)
    cin >> a[i];
  
  sort(a.begin(), a.end());
  
  int count = 0, last = 0;
  for (i = 0; i < N; i++) {
    if (last < a[i]) {
      count++;
      last = a[i];
    }
  }
  
  cout << count << endl;
}

Measured memory_bytes: 256
N, K = map(int, input().split())
i = 0
while (2**i) < K:
    i+= 1

numerator = 0
denominator = 2**i

answer = 0
for x in range(1,N+1):
    i = 0
    while (2**i) * x < K:
        i += 1
    numerator += denominator // (2**i)
    
answer = numerator / (denominator * N)
print(answer)

Measured memory_bytes: 3064
n,k=map(int,input().split())
arr=[list(map(int,input().split())) for _ in range(n)]
arr=sorted(arr,key=lambda x:x[0])
ans=0
count=0
for i in range(n):
  if arr[i][1]<k-count:
    ans+=arr[i][0]*arr[i][1]
    count+=arr[i][1]
  else:
    ans+=arr[i][0]*(k-count)
    print(ans)
    break

Measured memory_bytes: 29792
#include<iostream>
#include<algorithm>
#include<cmath>
#include<map>
#include<stdio.h>
#include<vector>
using namespace std;
#define rep(s,i,n) for(int i=s;i<n;i++)
#define c(n) cout<<n<<endl;
#define ic(n) int n;cin>>n;
#define sc(s) string s;cin>>s;
#define mod 1000000007
#define f first
#define s second
#define int long long	
string s[114],t[114];
signed main(){
	int n,m;
	cin>>n;
	rep(0,i,n)cin>>s[i];
	cin>>m;
	rep(0,i,m)cin>>t[i];
	int sum,ans=0;
	rep(0,i,n){
		rep(0,j,n)if(s[j]==s[i])sum++;
		rep(0,j,m)if(t[j]==s[i])sum-=1;
		if(sum>ans)ans=sum;
		sum=0; 
	}
	c(ans)
}			
			

Measured memory_bytes: 256
#include <cmath>
#include <iostream>
#include <functional>
#include <string>
#include <sstream>
#include <vector>
#include <algorithm>
#include <stdio.h>
#include <iomanip>
#include <math.h>
#include <list>
#include <numeric>
using namespace std;

int main(){    
  long long A,B,M,minA=10000000,minB=10000000;
  cin >> A >> B >> M;
  long long S[A],T[B],x,y,d,dis=10000000;
  for(int i=0;i<A;i++){
    cin >> S[i];
    minA = min(minA,S[i]);
  }
  for(int i=0;i<B;i++){
    cin >> T[i];
    minB = min(minB,T[i]);
  }
  
  long long sum = minA+minB;
  
  for(int i=0;i<M;i++){
    cin >> x >> y >> d;
    dis = min(S[x-1]+T[y-1]-d,dis);
  }
  //cout << dis << endl;
  if(sum < dis){
    cout << sum << endl;
  }
  else{
  cout << dis << endl;
  }
}


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

#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define FOR(i,n,m) for(int i=(int)(n); i<=(int)(m); i++)
#define RFOR(i,n,m) for(int i=(int)(n); i>=(int)(m); i--)
#define ITR(x,c) for(__typeof(c.begin()) x=c.begin();x!=c.end();x++)
#define RITR(x,c) for(__typeof(c.rbegin()) x=c.rbegin();x!=c.rend();x++)
#define setp(n) fixed << setprecision(n)

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 ld long double
#define ll long long
#define vll vector<ll>
#define vi vector<int>
#define pll pair<ll,ll>
#define pi pair<int,int>

#define all(a) (a.begin()),(a.end())
#define rall(a) (a.rbegin()),(a.rend())
#define fi first
#define se second
#define pb push_back
#define mp make_pair
#define ins insert

using namespace std;

#define INF INT_MAX

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

int main(void)
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    int n,m; cin>>n>>m;
    vector<vector<pi> > adj(n);
    rep(i,m){
        int l,r,d; cin>>l>>r>>d; l--; r--;
        adj[l].emplace_back(r,d);
        adj[r].emplace_back(l,-d);
    }
    vi dist(n,INF);
    bool ng=false;
    rep(i,n){
        if (dist[i]==INF){
            queue<int> que;
            que.push(i);
            dist[i] = 0;
            while(!que.empty()){
                int v = que.front(); que.pop();
                for(auto e:adj[v]){
                    int u,d;
                    tie(u,d) = e;
                    if (dist[u]!=INF){
                        if (dist[u]!=dist[v]+d) ng = true;
                        continue;
                    }
                    dist[u] = dist[v]+d;
                    que.push(u);
                }
            }
        }
    }
    if (ng){
        cout<<"No\n";
    }else{
        cout<<"Yes\n";
    }
    return 0;
}


Measured memory_bytes: 9344
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
//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; }

/* attention
    long longのシフト演算には気をつけよう
    タイポした時のデバッグが死ぬほどきつくなるので変数名は最低3字くらい使った方がいいかも
*/

int main(){
    ll N; cin >> N;
    vector<ll> a(5);
    for(int i=0; i<5; i++) cin >> a[i];

    sort(a.begin(), a.end());
    ll minv = a[0];
    ll turn;
    if(a[0] == 1) turn = N;
    else turn = (N-1)/minv + 1;

    cout << turn + 4 << endl;
}

Measured memory_bytes: 256
/***********************
*  Author: xuziyuan    * 
***********************/

#include <bits/stdc++.h>

#define rt0 return 0
#define rep(i,n) for(int i=0;i<n;i++)
#define repn(i,n) for(int i=1;i<=n;i++)
#define replet(c) for(char c='a';c<='z';c++) 
#define LL long long
#define pii pair <LL,LL>
#define pb push_back
#define fi first
#define se second
#define mpr make_pair
#define sqr(a) ((a)*(a))

using namespace std;

const LL MOD=1e9+7;

LL n,x,y,now=0;
vector <pii> v;

int main()
{
	cin>>n;
	rep(i,n)
	{
		scanf("%I64d%I64d",&x,&y);
		v.pb({y,x});
	}
	sort(v.begin(),v.end());
	rep(i,v.size())
	{
		now+=v[i].se;
		if(now>v[i].fi)
		{
			puts("No");
			rt0;
		}
	}
	puts("Yes");
	rt0;
}

Measured memory_bytes: 6512
#include <stdio.h>
#include <stdlib.h>


int DFS(int,int,int , int);

int tag();
void change(int *, int *);

int xarr[4]={-1,0,1,0},yarr[4]={0,-1,0,1};
int array[3][3],sum;
int main(){
  int i,j,zerox,zeroy;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      scanf("%d",&array[i][j]);
      if(array[i][j]==0){

	zerox=j;
	zeroy=i;
      }
    }
  }

  for(sum=0;sum<32;sum++){
    if(DFS(0,10,zerox,zeroy)==1) break;
  }
  printf("%d\n",sum);  /*output*/
  return 0;
}
int  DFS(int dep, int prev, int zerox, int zeroy){
  int i,xx,yy,ta;
  ta=tag();
  if(ta==0) return 1;
  if(dep+ta>sum) return -1;

    for(i=0;i<4;i++){
      if(i-prev==-2 || i-prev==2) continue;
      xx=zerox+xarr[i];
      yy=zeroy+yarr[i];
      if(xx<0 || yy<0 || xx>=3 || yy>=3) continue;
      change(&array[zeroy][zerox],&array[yy][xx]);

      if(DFS(dep+1,i,xx,yy)==1) return 1;
      change(&array[zeroy][zerox],&array[yy][xx]);

    }
    return -1;

}



int tag(){
  int i,j,num=0;
  for(i=0;i<3;i++){
    for(j=0;j<3;j++){
      if(array[i][j]==0) continue;
      num+=abs((array[i][j]-1)/3-i)+abs((array[i][j]-1)%3-j);


    }
  }
  return num;
}

/*exchange array[zeroy][zerox] and array[yy][xx]*/
void change(int * num1, int *num2){
  int ch;
  ch=*num1;
  *num1=*num2;
  *num2=ch;
}



Measured memory_bytes: 2140
#include<stdio.h>
#include<math.h>

int main(){
  double A,B,x;
  double V,deg;
  
  scanf("%lf %lf %lf",&A,&B,&x);
  
  if(2*(B-x/(A*A))-B<0){
  deg=atan((2.0*B-(2*x/(A*A)))/A)*180/3.14159265358;
  
  printf("%.9lf",deg);
  }else{
      deg=atan(A*B*B/(2*x))*180/3.14159265358;
        printf("%.9lf",deg);
  }
  return 0;
  
}
  

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

using namespace std;

const int ms = 1e5 + 17;
const int mod = 1e9 + 7;

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

    int n;
    cin >> n;

    if(n & 1)
        cout << n * 2 << '\n';
    else
        cout << n << '\n';
}


Measured memory_bytes: 256
#include <iostream>
#include <vector>
#include <string>
#include <sstream>

std::vector<std::string> split(std::string &str, char delim) {
	std::vector<std::string> result;
	std::istringstream is(str);
	std::string buf;
	while (getline(is, buf, delim)) {
		result.push_back(buf);
	}
	return result;
}

bool inputDataSet(std::vector<int> *l) {
	std::string line;
	if (!getline(std::cin, line)) { return false; }
	const std::vector<std::string> tokens(split(line, ','));
	if (tokens.size() != 3) { return false; }
	l->clear();
	for (std::vector<std::string>::const_iterator it = tokens.begin(); it != tokens.end(); ++it) {
		std::istringstream is(*it); int x;
		is >> x;
		l->push_back(x);
	}
	return true;
}

int main() {
	int nr = 0, nl = 0;
	std::vector<int> l(3);
	while (inputDataSet(&l)) {
		if (l[0] * l[0] + l[1] * l[1] == l[2] * l[2]) { ++nr; }
		if (l[0] == l[1]) { ++nl; }
	}
	std::cout << nr << std::endl;
	std::cout << nl << std::endl;
	return 0;
}

Measured memory_bytes: 0
A, B, C = map(int, input().split())

if A == B == C and A % 2 == 0:
    print(-1)
    exit()

res = 0
while A % 2 == 0 and B % 2 == 0 and C % 2 == 0:
    A, B, C = (B + C) // 2, (A + C) // 2, (A + B) // 2
    res += 1

print(res)


Measured memory_bytes: 2940
#[allow(unused_imports)]
use std::cmp::Reverse;

#[allow(unused_imports)]
use proconio::{fastout, input, marker::Chars};

#[allow(unused_imports)]
use itertools::Itertools;

#[fastout]
pub fn main() {
    input! {
        h: usize,
        w: usize,
        a: [Chars; h],
    }

    let mut dp = vec![vec![0; w]; h];

    for i in 0..h {
        for j in 0..w {
            if a[i][j] == '#' {
                continue;
            }
            if i == 0 && j == 0 {
                dp[i][j] = 1;
            } else {
                if i != 0 && a[i - 1][j] == '.' {
                    dp[i][j] += dp[i - 1][j];
                }
                if j != 0 && a[i][j - 1] == '.' {
                    dp[i][j] += dp[i][j - 1];
                }
                dp[i][j] %= 1000000007;
            }
        }
    }
    println!("{}", dp[h - 1][w - 1]);
}


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

int N;
int A[30],B[30],C[30];
int ans=0;
int main()
{
    cin>>N;
    for(int i=1;i<=N;i++) cin>>A[i];
    for(int i=1;i<=N;i++) cin>>B[i];
    for(int i=1;i<N;i++) cin>>C[i];
    ans = B[A[1]];
    for(int i=2;i<=N;i++)
    {
        ans+=B[A[i]];
        if(A[i]==A[i-1]+1) ans+=C[A[i-1]];
    }
    cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>

int main()
{
  int k, a, b;
  std::cin >> k >> a >> b;
  
  bool isOK = false;
  for(int i = a; i <= b; ++i)
  {
    if(i % k == 0)
    {
      isOK = true;
      break;
    }
  }
  
  std::cout << (isOK? "OK" : "NG") << std::endl;
  return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
typedef long long lint;

#define PI acos(-1)
#define INF64 1LL << 60
#define INF32 1 << 29
#define all(a) (a).begin(), (a).end()
#define INV ((long long int)1000000007)

using namespace std;

void execute()
{
	int a, b, c;
	cin >> a >> b >> c;
	if (a % b == c)
	{
		cout << "YES" << endl;
		return;
	}
	int first_mod = a % b;
	for (int i = a * 2; i % b != first_mod; i += a)
	{
		if (i % b == c)
		{
			cout << "YES" << endl;
			return;
		}
	}
	cout << "NO" << endl;
	return;
}

int main()
{
	cin.tie(0);
	ios_base::sync_with_stdio(false);
	std::cout << std::fixed << std::setprecision(15);
	execute();

	int stop;
	cin >> stop;

	return 0;
}

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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int MAXN = 1e3+2, mod = 1e9 + 7;
int dp[MAXN][MAXN], H, W;
string a[MAXN];


int main(){

	#ifdef MaxWell
    	freopen(".in", "r", stdin);
        cout << "<<<------------ MaxWell defined ---------------->>>\n";
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> H >> W;
    for(int i=0; i<H; i++)
        cin >> a[i];

    dp[0][0] = 1;

    for(int i=1; i<H; i++)
        if(a[i][0] == '.') dp[i][0] += dp[i-1][0];

    for(int i=1; i<W; i++)
        if(a[0][i] == '.') dp[0][i] += dp[0][i-1];

    for(int i = 1; i<H; i++)
        for(int j = 1; j<W; j++)
            if(a[i][j] == '.') dp[i][j] = (dp[i][j] + dp[i-1][j] + dp[i][j-1]) % mod;

    cout << dp[H-1][W-1] << '\n';

    return 0;
}

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

using namespace std;
#define BUF (100005)
#define ll long long 

int n,c;


int a[32][BUF];
int cnt[BUF];

int main(void){
	cin >> n >> c;
	for(int i=1;i<=n;i++){
		int s,t,ch;
		cin >> s >> t >> ch;
		if(a[ch][s] == 0){
			a[ch][s] = 5;
		}else{
			a[ch][s]=0;
		}
		if(a[ch][t] == 0){
			a[ch][t] = -1;
		}else{
			a[ch][t]=0;
		}
	}

	for(int ch = 1;ch<=c;ch++){
		for(int i=1; i<BUF;i++){
			if(a[ch][i]==5){
				if(a[ch][i-1]==-1){
					a[ch][i]=0;
					a[ch][i-1]=0;
				}else{
					a[ch][i]=0;
					a[ch][i-1]=1;
				}
			}
		}
	}

	int tv=0;
	int ans = 0;
	for (int i = 0; i < BUF ; i++)
	{
		for (int ch = 1; ch <= c; ch++)
		{
			tv+=a[ch][i];
		}
		ans = max(ans,tv);
	}

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


Measured memory_bytes: 12032
#include <bits/stdc++.h>
using namespace std;
double mem[51][5001];
int x,y,z,v[100],used[51][5001];
struct po{int e,a;};
po E[101];

double dfs(int pos,int mo){
  if(pos==y) return mo;
  if(used[pos][mo]) return mem[pos][mo];
  used[pos][mo]=1;
  
  for(int i=0;i<x;i++) {
    int npos=min(y,pos+v[i]),nmo=mo;
    int e=E[npos].e, a=E[npos].a;
    if(e){
      if(e==1)npos=min(y,npos+a);
      if(e==2)nmo+=a;
      if(e==3)nmo=max(0,nmo-a);
    }
    mem[pos][mo] += dfs(npos,nmo)/x;
  }
  return mem[pos][mo];
}

int main(){
  while(1){
  cin>>x>>y>>z;
  if(!x&&!y&&!z)break;
  for(int i=0;i<x;i++)cin>>v[i];
  memset(E,0,sizeof(E));
  for(int i=0,a;i<z;i++)cin>>a,cin>>E[a].e>>E[a].a;
  memset(used,0,sizeof(used));
  memset(mem,0,sizeof(mem));
  cout <<(int)dfs(0,0)<<endl;
  }
  return 0;
}

Measured memory_bytes: 4156
#include <iostream>
    
using namespace std;
    
int main(){
 int H,W,i,j;
 while (1) {
  cin>>H;
  cin >>W;
  if (H==0 && W==0) break;
  for (i=0;i<H;i++) {
   for (j=0;j<W;j++) {
    if (i==0 || j==0 || i==H-1 || j==W-1) {
     cout << "#";
    } else {
     cout << ".";
    }
   }
   cout << endl;
  }
  cout << endl;
 }
 return 0;
}



Measured memory_bytes: 3112
# -*- coding: utf-8 -*-
"""
Closest Pair
http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=CGL_5_A&lang=ja
TLE
"""
import sys


from collections import deque
def closest_pair(points):
    return find_closest(sorted(points)) ** 0.5

def find_closest(points):
    n = len(points)
    if n <= 1:
        return float('inf')
    m = n // 2
    x = points[m][0]
    d = min(find_closest(points[:m]),  find_closest(points[m:]))
    points.sort(key=lambda p:p[1])
    b = deque()
    for p in points:
        if (p[0] - x)**2 < d:
            for q in b:
                dx = p[0] - q[0]
                dy = p[1] - q[1]
                if dy**2 >= d:
                    break
                if (dx**2 + dy**2) < d:
                    d = (dx**2 + dy**2)
            b.appendleft(p)
    return d


def main(args):
    n = int(input())
    points = []
    for _ in range(n):
        x, y = map(float, input().split())
        points.append((x, y))
    ans = closest_pair(sorted(points))
    print('{:.10f}'.format(ans))


if __name__ == '__main__':
    main(sys.argv[1:])


Measured memory_bytes: 21708
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pint = pair<int, int>;
using pll = pair<ll, ll>;
using Edge = pair<int, ll>;
using Graph = vector<vector<int>>;
using WeightedGraph = vector<vector<Edge>>;
const ll INF64 = 1LL << 60;
const int INF32 = 1 << 29;
const ll MOD = 1000000007;

const int CASES = 3;

long long modpow(long long a, long long n, long long mod) {
    long long res = 1;
    while (n > 0) {
        if (n & 1) res = res * a % mod;
        a = a * a % mod;
        n >>= 1;
    }
    return res;
}


void solve() {
    ll n, p; cin >> n >> p;
    string s; cin >> s;
    if(p==2){
        ll ans = 0;
        for (ll i = 0; i < n; ++i) {
            ll tmp = (ll)(s[i] - '0');
            if(tmp % 2 == 0) ans += (i+1);
        }
        cout << ans << endl;
        return;
    }
    if(p==5){
        ll ans = 0;
        for (ll i = 0; i < n; ++i) {
            ll tmp = (ll)(s[i] - '0');
            if(tmp % 5 == 0) ans += (i+1);
        }
        cout << ans << endl;
        return;
    }
    vector<ll> a(n), sum(n+1);
    for (ll i = 0; i < n; ++i) {
        ll tmp = (ll)(s[i] - '0');
        a[i] = tmp * modpow(10LL, n-1LL-i, p);
        a[i] %= p;
        sum[i+1] = sum[i] + a[i];
        sum[i+1] %= p;
    }

    ll ans = 0;
    map<ll, ll> mp;
    for(int i = 0; i <= n; ++i){
        ans += mp[sum[i]];
        ++mp[sum[i]];
    }
    cout << ans << endl;
    return;
}

int main() {
#ifdef MYLOCAL
    vector<string> filenames {"input1.txt", "input2.txt", "input3.txt", "input4.txt", "input5.txt"};
    cout << "------------\n";
    for(int i = 0; i < CASES; ++i){
        ifstream in(filenames[i]);
        cin.rdbuf(in.rdbuf());
        solve();
        cout << "------------\n";
    }
#else

    solve();

#endif
    return 0;
}


Measured memory_bytes: 4100
#include<iostream>
#include<algorithm>
#include<string>
#include<vector>
using namespace std;
typedef long long ll;

int main(void) {
	ll count = 0, k;
	string s;
	cin >> s >> k;
	for (ll i = 0;i < s.length();i++) {
		if (s[i] == '1')count++;
		else break;
	}
	if (count >= k)cout << 1 << endl;
	else cout << s[count] << endl;
	return 0;
}

Measured memory_bytes: 256
import sys
input = sys.stdin.readline
n,m,q = map(int,input().split())
abcd = [list(map(int,input().split())) for _ in range(q)]
A = [[i] for i in range(1,m+1)]
def listup(A,m):
  b = []
  for i in A:
    for j in range(i[-1],m+1):
      b.append(i+[j])
  return b
      
for i in range(n-1):
  A = listup(A,m)
ans = 0
for i in A:
  temp = 0
  for j in abcd:
    if i[j[1]-1]-i[j[0]-1] == j[2]:
      temp += j[3]
  ans = max(ans,temp)
print(ans)

Measured memory_bytes: 30492
#include <bits/stdc++.h>
using namespace std;
#define fi first
#define se second
#define countof(array) (sizeof(array) / sizeof(array[0]))
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define rrep(i,n) for(int i = (n)-1; i >= 0; --i)
#define rep2(i,n) for(int i = 1; i <= (n); ++i)
#define rrep2(i,n) for(int i = (n); i > 0; --i)
#define srep(i,s,n) for(int i = s; i < (n); ++i)
#define rsrep(i,s,n) for(int i = (n)-1; i >= s; --i)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define aall(a) (a), (a)+countof(a)//for array sorting
#define raall(a) (a), (a)+countof(a), greater<>()
#define show(x) cout<<#x<<" = "<<(x)<<endl;
#define vfind(v, a) find(all(v), a) != v.end()
#define yn(f) { if (f) puts("YES"); else puts("NO"); }
#define yns(f) { if (f) puts("Yes"); else puts("No"); }
#define show_ary(...) { cout<<#__VA_ARGS__<<" = "; for (const auto& x : (__VA_ARGS__)) { cout<<x<<" "; } cout<<endl; }
#define show_pair(...) cout<<#__VA_ARGS__<<" = "<<endl; for (const auto& x : (__VA_ARGS__)) { cout<<"  "<<x.fi<<" : "<<x.se<<endl; }
#define out_ary(...) { int n = (__VA_ARGS__).size(); rep(i, n) printf("%d%s", (__VA_ARGS__)[i], i != n-1 ? " " : "\n"); }
#define argmax(v) distance((v).begin(), max_element(all(v)))
#define argmin(v) distance((v).begin(), min_element(all(v)))
#define vmax(v) *max_element(all(v))
#define vmin(v) *min_element(all(v))
typedef long long int ll;
typedef pair<int, int> P;
typedef vector<P> vpair;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<string> vstr;
typedef vector<bool> vbool;
typedef vector<vint> vvint;
typedef vector<vll> vvll;
typedef vector<vstr> vvstr;
typedef vector<vbool> vvbool;
const ll LINF = 2000000000000000000ll;
const int INF = 1000000100;
const ll MOD = 1e9+7;


int main() {
    int n;
    cin >> n;
    vint a(n);
    rep(i, n) cin >> a[i];
    
    vint sum(n+1, 0);
    rep(i, n) sum[i+1] = sum[i] + abs(a[i]);

    ll dist = abs(a[0]);
    ll now = a[0];
    srep(i, 1, n) {
        if (a[i] == 0) {
            dist += abs(now);
            now = 0;
            continue;
        }
        if (a[i]>0 == a[i-1]>0) {
            dist += abs(a[i]-a[i-1]);
        } 
        else {
            dist += abs(a[i])+abs(a[i-1]);
        }
        now = a[i];
    }
    dist += abs(now);
    now = 0;
    a.push_back(0);
    rep(i, n) {
        if (a[i] >= now && a[i] <= a[i+1]) {
            cout << dist << endl;
        }
        else if (a[i] <= now && a[i] >= a[i+1]) {
            cout << dist << endl;
        }
        else {
            ll ans = dist;
            ans -= abs(now-a[i]);
            ans -= abs(a[i+1]-a[i]);
            ans += abs(a[i+1]-now);
            cout << ans << endl;
        }
        now = a[i];
    }

    return 0;
}

Measured memory_bytes: 2040
while True:
    m, f, r = map(int, input().split())
    if m == f == r == -1:
        break
    elif m == -1 or f == -1:
        print("F")
    elif 80 <= m + f:
        print("A")
    elif 65 <= m + f < 80:
        print("B")
    elif 50 <= m + f < 65:
        print("C")
    elif 30 <= m + f < 50:
        if 50 <= r:
            print("C")
        else:
            print("D")
    elif m + f < 30:
        print("F")
    else:
        pass



Measured memory_bytes: 5592
#include <iostream>
using namespace std;
#include <string>
#include <vector>
#include <algorithm>
#include <map>
typedef long long ll;
#include <cmath>


int main(int argc, char *argv[])
{
	int n;
	cin >>n;
	
	string s="No";

	while (n>0)
	{
		if ((n%10)==7) s="Yes";
		n/=10;
	}
	cout<<s<<endl;
	return 0;
}



Measured memory_bytes: 3620
#include <iostream>
#include <cstdlib>
#include <algorithm>
#include <limits.h>
using namespace std;

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

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

int dp[n] = {0};
for (int i=1; i<=n; i++) {
    dp[i] = INT_MAX;
    for (int j=1; j<=k; j++)
        if (i-j>=0)
            dp[i] = min(dp[i], dp[i-j] + abs(a[i]-a[i-j]));
}

cout << dp[n-1];




}




Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define FOR(i,k,n)  for(int i = (k);i < (n);++i)
#define REP(i,n)    FOR(i,0,n)
#define ALL(x)      begin(x),end(x)

using namespace std;
using vecint = vector<int>;
using ll = int64_t;

int main()
{
  int n;
  cin>>n;
  vector<string> t(n);
  REP(i,n) cin>>t[i];
  vector<string> s(n*2);
  REP(i,n) {
    s[i] = t[i] + t[i];
    s[i+n] = s[i];
  }
  vector<vector<vector<bool>>> dp(2*n, vector<vector<bool>>(2*n, vector<bool>(n+1, false)));
  REP(i,2*n)REP(j,2*n) {
    dp[i][j][1] = true;
  }
  FOR(k,1,n+1) {
    REP(i,2*n-1)REP(j,2*n-1) {
      if (dp[i][j][k] && dp[i+1][j+1][k] && s[i+k][j] == s[i][j+k]) {
        dp[i][j][k+1] = true;
      }
    }
  }
  int cnt = 0;
  REP(i,n)REP(j,n) {
    if (dp[i][j][n]) ++cnt;
  }
  cout << cnt << endl;
  return 0;
}


Measured memory_bytes: 33920