akhauriyash/Code-Regression huggingface dataset:
import sys
sys.setrecursionlimit(10**9)
N,M=map(int,input().split())

def find_negative_loop(n,w,es):
  dist=[float("inf")]*n
  #この始点はどこでもよい
  dist[1]=0
  
  for i in range(n):
    for j in range(w):
      e=es[j]
      if dist[e[1]]>dist[e[0]]+e[2]:
        dist[e[1]]=dist[e[0]]+e[2]
        if i==n-1:
          return True
  return False

def shortest_path(s,n,w,es):
  #s→iの最短距離
  #s:始点, n:頂点数, w:辺の数, es[i]:[辺の始点,辺の終点,辺のコスト]
  dist=[float("inf")]*n
  #d[i]: s→iの最短距離
  dist[s]=0

  while True:
    update=False
    for p,q,r in es:
      # e: 辺iについて [from,to,cost]
      if dist[p]!=float("inf") and dist[q]>dist[p]+r:
        dist[q]=dist[p]+r
        update=True
    if not update:
      break
      
  return dist

graph=[[] for _ in range(N+1)]
elist=[]
for _ in range(M):
  a,b,c=map(int,input().split())
  graph[a].append(b)
  elist.append((a,b,-c))
  
#remove unnecessary vertex and edge
visited=[None]*(N+1)
def check_reachable(u):
  if u==N:
    reachable[u]=True
    return True
  
  visited[u]=True
  cnt=0
  for v in graph[u]:
    if not visited[v]:
      ret=check_reachable(v)
      if ret:
        cnt+=1
        
  if cnt>0:
    reachable[u]=True
    return True
  else:
    return False

reachable=[False]*(N+1)
for i in range(1,N+1):
  if not reachable[i]:
    visited=[False]*(N+1)
    check_reachable(i)
#print(reachable)
  
elist2=[]
for a,b,nc in elist:
  if reachable[b]:
    elist2.append((a,b,nc))
  
M2=len(elist2)
res1=find_negative_loop(N+1,M2,elist2)

if res1:
  print("inf")
else:
  res2=shortest_path(1,N+1,M2,elist2)
  print(-res2[N])

Measured memory_bytes: 4340
s = input()
c1 = ['0']*len(s)
c2 = ['0']*len(s)
for i in range(len(s)):
    if i%2 == 0:
        c2[i] = '1'
    else:
        c1[i] = '1'
# print(c1)
a1 = 0
a2 = 0
for i in range(len(s)):
    if c1[i] == s[i]:
        a1 += 1
    if c2[i] == s[i]:
        a2 += 1
print(min(a1,a2))

Measured memory_bytes: 4724
/*** author: yuji9511 ***/
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<ll,ll> lpair;
const ll MOD = 1e9+7;
const ll INF = 1e18;
#define rep(i,m,n) for(ll i=(m);i<(n);i++)
#define rrep(i,m,n) for(ll i=(m);i>=(n);i--)
#define printa(x,n) for(ll i=0;i<n;i++){cout<<(x[i])<<" \n"[i==n-1];};
void print() {}
template <class H,class... T>
void print(H&& h, T&&... t){cout<<h<<" \n"[sizeof...(t)==0];print(forward<T>(t)...);}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    ll N;
    cin >> N;
    ll d[55];
    rep(i,0,N) cin >> d[i];
    ll ans = 0;
    rep(i,0,N){
        rep(j,0,N){
            if(i >= j) continue;
            ans += d[i] * d[j];
        }
    }
    print(ans);


}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define MAX LLONG_MAX
#define MIN LLONG_MIN
#define ALL(obj) (obj).begin(), (obj).end()
#define fi first
#define se second
#define NIL -1
using ll = long long;
const ll MOD = 1000000007;
#define REP(i,n) for (ll i=0; i < (n); ++i)
#define FOR(i,a,b) for (ll i=(a); i < (b); ++i)
using namespace std;

int get_gcd(int a, int b){while(1){if (a < b) swap(a, b); if (b == 0) return a; a %= b;}}
int get_lcm(int a, int b){return a * b / get_gcd(a, b);}
int dx[4]={1,0,-1,0};
int dy[4]={0,1,0,-1};

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

  array<int, 10> num = {0,2,5,5,4,5,6,3,7,6};

  int m,n;
  cin >> n >> m;
  vector<int> a(m);
  REP(i,m) cin >> a[i];
  sort(ALL(a), greater<int>());

  //dp[i] ... ちょうどi本のマッチ棒を使って作れる整数の最大桁数
  //まずはdp[i]を求める。
  vector<int> dp(n+1);
  dp[0] = 0;
  for (int i=1; i<=n; i++) {
    int max_ = MIN;
    REP(j,m) {
      // A[j]を使ったときの残りのマッチの本数
      int r = i - num[a[j]];
      if (r < 0) continue;
      max_ = max(max_, dp[r] + 1);
    }
    dp[i] = max_;
  }

  //dp[n]について、具体的な整数を決定していく。
  int ans = 0;
  int r = n; // 残りのマッチの本数
  REP(i,n) {
    // A[j]が使えるかを見る。使えたらそれに決定。
    int j = 0;
    REP(j,m) {
      if (r-num[a[j]] < 0) continue;
      if (dp[r - num[a[j]]] == dp[r] - 1) {
        cout << a[j];
        r -= num[a[j]];
        break;
      }
    }
  }
  cout << endl;

  return 0;
}


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

using namespace std;

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  int N, M;
  cin >> N >> M;
  vector<int> ball(N, 1);
  vector<bool> red(N, false);
  red[0] = true;
  for (int i = 0; i < M; i++) {
    int x, y;
    cin >> x >> y;
    x--, y--;
    ball[x]--, ball[y]++;
    if (red[x]) red[y] = true;
    if (ball[x] == 0) red[x] = false;
  }
  int cnt = 0;
  for (int i = 0; i < N; i++) {
    if (red[i] && ball[i] > 0) cnt++;
  }
  cout << cnt << '\n';
  return 0;
}


Measured memory_bytes: 640
using System;
class _0048
{
    public static void Main()
    {
        string str;
        double m;
        while ((str = Console.ReadLine()) != null)
        {
            m = double.Parse(str);
            if (m <= 48.00) Console.WriteLine("light fly");
            else if (m <= 51.00) Console.WriteLine("fly");
            else if (m <= 54.00) Console.WriteLine("bantam");
            else if (m <= 57.00) Console.WriteLine("feather");
            else if (m <= 60.00) Console.WriteLine("light");
            else if (m <= 64.00) Console.WriteLine("light welter");
            else if (m <= 69.00) Console.WriteLine("welter");
            else if (m <= 75.00) Console.WriteLine("light middle");
            else if (m <= 81.00) Console.WriteLine("middle");
            else if (m <= 91.00) Console.WriteLine("light heavy");
            else Console.WriteLine("heavy");
        }
    }
}

Measured memory_bytes: 20000
#include<iostream>
using namespace std;
#include<set>
#include<vector>
set<string> s;
void function(int initial,int final,vector<int> v)
{
	if(initial>final)
	{
		string str="";
		for(int x:v)
		{
			char y=char(x);
			str+=y;
		}
		s.insert(str);
	}
	else
	{
		int m=v[0];
		for(int j=1;j<v.size();j++)
		{
			m=max(m,v[j]);
		}
		for(int j=97;j<=m+1;j++)
		{
			v.push_back(j);
			function(initial+1,final,v);
			auto it=v.end();
			it--;
			v.erase(it);
		}
	}
}
int32_t main()
{
    int n;
    cin>>n;
    vector<int> v;
    v.push_back(97);
    function(1,n-1,v);
    for(string str:s)
        cout<<str<<endl;
}


Measured memory_bytes: 14208
import java.util.Scanner;
public class Main {

	public static void main(String[] args) {
		// TODO 自動生成されたメソッド・スタブ
		Scanner sc = new Scanner(System.in);
		int a[]= new int[5];
		
		for(int i =0;i<5; i++) {
			a[i] = sc.nextInt();
		}
		
		for(int i =0;i<5;i++) {
			if(a[i]==0) {
				System.out.println(i+1);
			}
		}
	}

}


Measured memory_bytes: 35632
// ref. https://atcoder.jp/contests/abc157/submissions/10472433
// @sunuke

import java.util.*;

public class Main {
  public static void main(String[] args) {
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    int M = sc.nextInt();
    int K = sc.nextInt();
    UnionFind friendsGroup = new UnionFind(N);
    int[] friendSize = new int[100_000 + 5];
    Map<Integer, List<Integer>> block = new HashMap<>();
    for (int i = 0; i < M; i++) {
      int a = sc.nextInt() - 1, b = sc.nextInt() - 1;
      friendSize[a]++;
      friendSize[b]++;
      friendsGroup.unite(a, b);
    }
    for (int i = 0; i < K; i++) {
      int a = sc.nextInt() - 1, b = sc.nextInt() - 1;
      block.computeIfAbsent(a, k -> new ArrayList<>()).add(b);
      block.computeIfAbsent(b, k -> new ArrayList<>()).add(a);
    }
    for (int i = 0; i < N; i++) {
      int ans = friendsGroup.size(i) - 1 - friendSize[i];
      for (int to : block.getOrDefault(i, Collections.emptyList())) {
        if (friendsGroup.find(i) == friendsGroup.find(to)) ans--;
      }
      System.out.println(ans);
    }
  }
  static class UnionFind {
    int[] parent;
    int[] size;
    int[] rank;
    UnionFind(int n) {
      parent = new int[n];
      for (int i = 0; i < n; i++) {
        parent[i] = i;
      }
      size = new int[n];
      Arrays.fill(size, 1);
      rank = new int[n];
    }
    int size(int i) {
      return size[find(i)];
    }
    void unite(int a, int b) {
      int a1 = find(a), b1 = find(b);
      if (a1 == b1) return;
      if (rank[a1] > rank[b1]) {
        parent[b1] = a1;
        size[a1] += size[b1];
      } else {
        parent[a1] = b1;
        size[b1] += size[a1];
        if (rank[a1] == rank[b1]) {
          rank[a1]++;
        }
      }
    }
    int find(int a){
      if (parent[a] == a) return a;
      return  parent[a] = find(parent[a]);
    }
  }
}


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

namespace TOPSIC
{
    partial class Program
    {
        static void Main(string[] args)
        {
          string[] A1 = Console.ReadLine().Split(' ');
            string[] A2 = Console.ReadLine().Split(' ');
            string[] A3 = Console.ReadLine().Split(' ');

            int[,] A = new int[3, 3];

            for (int i = 0; i < 3; i++)
            {
                A[0, i] = int.Parse(A1[i]);
            }
            for (int i = 0; i < 3; i++)
            {
                A[1, i] = int.Parse(A2[i]);
            }
            for (int i = 0; i < 3; i++)
            {
                A[2, i] = int.Parse(A3[i]);
            }

            string NK = Console.ReadLine();
            int N = int.Parse(NK);

            int[] b = new int[N];

            for (int i = 0; i < N; i++)
            {
                b[i] = int.Parse(Console.ReadLine());
            }




            for (int i = 0; i < N; i++)
            {
                for (int j = 0; j < 3; j++)
                {
                    for (int k = 0; k < 3; k++)
                    {
                        if (A[j, k] == b[i])
                        {
                            A[j, k] = 0;
                        }
                    }
                }
            }

            for (int j = 0; j < 3; j++)
            {
                int ans = 0;
                for (int k = 0; k < 3; k++)
                {
                    ans += A[j, k];
                }

                if (ans == 0)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }

            for (int j = 0; j < 3; j++)
            {
                int ans = 0;
                for (int k = 0; k < 3; k++)
                {
                    ans += A[k, j];
                }

                if (ans == 0)
                {
                    Console.WriteLine("Yes");
                    return;
                }
            }

            if (A[0, 0] == 0 && A[1, 1] == 0 && A[2, 2] == 0)
            {
                Console.WriteLine("Yes");
                return;
            }

            if (A[0, 2] == 0 && A[1, 1] == 0 && A[2, 0] == 0)
            {
                Console.WriteLine("Yes");
                return;
            }

            Console.WriteLine("No");
        }
    }
}


Measured memory_bytes: 13140
package main

import (
	"fmt"
)

func main() {
	var N, T, A int
	fmt.Scan(&N, &T, &A)

	best := 0
	min_diff := 1000000000
	for i := 1; i < N+1; i++ {
		var h int
		fmt.Scan(&h)

		var diff int
		diff = abs((T*1000 - h*6) - A*1000)

		if diff < min_diff {
			min_diff = diff
			best = i
		}
	}

	fmt.Println(best)
}

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


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

using namespace std;

typedef long long ll;

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

	int N, D;
	cin >> N >> D;

	vector<vector<ll>> X(N, vector<ll>(D));
	rep(i, N) rep(j, D) cin >> X[i][j];

	set<ll> squ;
	rep(i, 1000) squ.insert(i*i);

	int ans = 0;
	for(int i = 0; i < N;i++){
		for(int j = i+1; j < N; j++){
			ll t = 0;
			for(int k = 0; k < D; k++){
				t += (X[i][k] - X[j][k]) * (X[i][k] - X[j][k]);
			}

			auto itr = squ.find(t);
			if(itr != squ.end()) ans++;
		}
	}

	cout << ans << endl;
}


Measured memory_bytes: 256
#pragma GCC optimize("Ofast")
#pragma GCC optimize("unroll-loops")
#include<bits/stdc++.h>
using namespace std;
const int N=1505;
int val[N][N],b[N][N],S[N],n,u[N][N],l[N],r[N];
char A[N][N];
bool flag[N][N];
int main(){
	scanf("%d",&n);
	for (register int i=1;i<=n;++i)scanf("%s",A[i]+1);
	for (register int i=1;i<=n;++i)
		for (register int j=1;j<=n;++j)flag[i][j]=A[i][j]>='0'&&A[i][j]<='9',b[i][j]=A[i][j]-'0';
	for (register int i=0;i<=n;++i)
		for (register int j=0;j<=n;++j)u[i][j]=flag[i][j]?min(i,min(u[i-1][j],u[i][j-1])):1<<30;
	long long ans=0;
	for (register int x=1;x<=n;++x){
		for (register int j=1;j<=n;++j)S[j]=S[j-1]+(u[x][j]<=x?b[x][j]:0);
		for (register int j=n+1;j;--j){
			if (flag[x][j]){
				l[j]=j-1;
				r[j]=max(r[j+1],j);
				val[x][j]+=(S[r[j]]-S[l[j]]-b[x][j]);
			}
			else l[j]=n+1,r[j]=0;
		}
		for (register int i=x-1;i;--i){
			for (register int j=1;j<=n;++j)S[j]=S[j-1]+(u[x][j]<=i?b[x][j]:0);
			for (register int j=n+1;j;--j){
				if (flag[i][j]){
					l[j]=min(l[j+1],l[j]);
					r[j]=max(r[j+1],r[j]);
					val[i][j]+=(S[r[j]]-S[l[j]]);
				}
				else l[j]=n+1,r[j]=0;
			}
		}
	}
	for (register int i=1;i<=n;++i)
		for (register int j=1;j<=n;++j)ans+=val[i][j]*b[i][j];
	printf("%lld\n",ans);
}



Measured memory_bytes: 17408
def main():
    n = input()
    tree = MyTree(n)
    for i in range(n):
        id_k_cn = map(int,raw_input().split())
        id_node = id_k_cn.pop(0)
        k = id_k_cn.pop(0)
        tree.add(id_node,k,None,id_k_cn)
    
    tree.search_children()
    tree.set_depth(tree.nodes[tree.id_root],0)
    
    for node in tree.nodes:
        print "node {0}: parent = {1}, depth = {2}, {3}, {4}".format(node.id_self, node.id_parent, node.depth, node.node_type, node.id_children)


class MyTree():
    def __init__(self,num_nodes):
        self.nodes = [MyNode() for i in range(num_nodes)]
        self.id_root = None

    def add(self,id_node,n_children,id_parent,id_children):
        node = self.nodes[id_node]
        node.id_self = id_node
        node.n_children = n_children
        node.id_parent = id_parent
        node.id_children = id_children
    
    def search_children(self):
        for node in self.nodes:
            if node.n_children == 0:
                node.node_type = "leaf"
            else:
                node.node_type = "internal node"
            for j in node.id_children:
                self.nodes[j].id_parent = node.id_self

        for node in self.nodes:
            if node.id_parent == None:
                node.id_parent = -1
                node.node_type = "root"
                self.id_root = node.id_self
                break

    def set_depth(self,node,depth):
        node.depth = depth
        node.id_children
        for item in node.id_children:
            self.set_depth(self.nodes[item],depth+1)


class MyNode():
    def __init__(self):
        self.id_self = None
        self.id_parent = None
        self.id_children = None
        self.depth = None
        self.node_type = None
        self.n_children = 0
        


if __name__ == "__main__":
    main()

Measured memory_bytes: 143752
import sys
F = sys.stdin
S = F.readline().replace("A", "1").replace("B", "2").strip("\n")
T = F.readline().replace("A", "1").replace("B", "2").strip("\n")

sSum = [0] * (len(S)+1)
tSum = [0] * (len(T)+1)
for i in range(len(S)):
    sSum[i+1] = sSum[i] + int(S[i])
for i in range(len(T)):
    tSum[i+1] = tSum[i] + int(T[i])

Ans = ""
Q = int(F.readline().strip("\n"))
for _ in range(Q):
    a, b, c, d = map(int, F.readline().strip("\n").split(" "))
    if (sSum[b] - sSum[a-1]) % 3 == (tSum[d] - tSum[c-1]) % 3: Ans += "YES\n"
    else: Ans += "NO\n"
print(Ans)

Measured memory_bytes: 13600
#include <stdio.h>
int main(){
	int n,a,b,c,d;
	scanf("%d",&n);
	a=n/1000;
	n=n%1000;
	b=n/100;
	n=n%100;
	c=n/10;
	d=n%10;
	if(a+b+c+d==7){
		printf("%d+%d+%d+%d=7",a,b,c,d);
	}
	else if(a-b+c+d==7){
		printf("%d-%d+%d+%d=7",a,b,c,d);
	}
	else if(a+b-c+d==7){
		printf("%d+%d-%d+%d=7",a,b,c,d);
	}
	else if(a+b+c-d==7){
		printf("%d+%d+%d-%d=7",a,b,c,d);
	}
	else if(a-b-c+d==7){
		printf("%d-%d-%d+%d=7",a,b,c,d);
	}
	else if(a-b+c-d==7){
		printf("%d-%d+%d-%d=7",a,b,c,d);
	}
	else if(a+b-c-d==7){
		printf("%d+%d-%d-%d=7",a,b,c,d);
	}
	else if(a-b-c-d==7){
		printf("%d-%d-%d-%d=7",a,b,c,d);
	}
}

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

int main(){
 int a,b; cin>>a>>b;
  if(a<=b){
    for(int i=0; i<b; i++){cout<<a;}
  }
  else if(a>b){
    for(int i=0; i<a; i++){cout<<b;}
  }
}










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

using namespace std;

#define ll long long

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

	ll n, MAX; cin>>n>>MAX;
	ll dp[n + 1][MAX + 1], v[n + 1], w[n + 1];

	for(int i=1;i<=n;++i)cin>>w[i]>>v[i];

	for(int i=0;i<=n;++i)
		for(int j=0;j<=MAX;++j)dp[i][j] = 0;

	for(int i=1;i<=n;++i)
		for(int j=0;j<=MAX;++j){
			dp[i][j] = dp[i - 1][j];
			if(j - w[i] >= 0)
				dp[i][j] = max(dp[i][j], v[i] + dp[i - 1][j - w[i]]);
		}

	cout<<dp[n][MAX]<<"\n";
	return 0;
}

Measured memory_bytes: 79104
#include<bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
#define MOD 1000000007
#define MAX 1000005
#define loop(i,a,b) for(long long int i=a;i<b;i++)
#define pb(a) push_back(a)
#define mp(a,b) make_pair(a,b)
#define debug(x) cout<<#x<<" :: "<<x<<endl;
#define debug2(x,y) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<endl;
#define debug3(x,y,z) cout<<#x<<" :: "<<x<<"\t"<<#y<<" :: "<<y<<"\t"<<#z<<" :: "<<z<<endl;
typedef long long int ll;

using namespace std;
//using namespace boost::multiprecision;

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

ll n,m,sum=0;
cin>>m>>n;

ll a[n];
loop(i,0,n)
{
	cin>>a[i];
	sum += a[i];
}

if(sum>m)
cout<<"-1\n";
else
cout<<m-sum<<"\n";





return 0;
}


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

int main() {
    long long n, c;
    cin >> n >> c;
    long long x[n], v[n], dp[n + 1], result = 0;
    dp[0] = 0;
    for (long long i = 0; cin >> x[i] >> v[i]; i++) {
    }
    for (long long i = 0, sum = 0; i < n; i++) {
        sum += v[i];
        dp[i + 1] = max(dp[i], sum - x[i]);
        result = max(result, dp[i + 1]);
    }
    for (long long i = n - 1, sum = 0; i > 0; i--) {
        sum += v[i];
        result = max(result, sum - 2 * (c - x[i]) + dp[i]);
    }
    dp[n] = 0;
    for (long long i = n - 1, sum = 0; i >= 0; i--) {
        sum += v[i];
        dp[i] = max(dp[i + 1], sum - c + x[i]);
        result = max(result, dp[i]);
    }
    for (long long i = 0, sum = 0; i < n; i++) {
        sum += v[i];
        result = max(result, sum - 2 * x[i] + dp[i + 1]);
    }
    cout << result;
    return 0;
}


Measured memory_bytes: 2560
A=[[-1 for i in range(3)] for j in range(3)]

for i in range(3):
    A[i] = map(int, raw_input().split())

#print A

N = int(raw_input())
B = [-1 for i in range(N)]

for i in range(N):
    B[i] = int(raw_input())

#print B
for i in range(N):
    for j in range(3):
        for k in range(3):
            if B[i] == A[j][k]:
                A[j][k] = 0

for i in range(3):
    if (A[i][0] == 0 and A[i][1] == 0 and A[i][2] == 0 or
        A[0][i] == 0 and A[1][i] == 0 and A[2][i] == 0):
        print "Yes"
        exit(0)

if (A[0][0] == 0 and A[1][1] == 0 and A[2][2] == 0 or
    A[2][0] == 0 and A[1][1] == 0 and A[0][2] == 0):
    print "Yes"
else:
    print "No"


Measured memory_bytes: 2696
#include<iostream>
#define rep(i,cc,n) for(int i=cc;i<=n;++i)
using namespace std;

int main() {
  int N, M, C;
  cin >> N >> M >> C;
  int B[M];
  int ai, ans = 0;
  rep(i,0,M-1) cin >> B[i];
  rep(i,0,N-1) {
    int tmp = 0;
    rep(j,0,M-1) {
      cin >> ai;
      tmp += ai * B[j];
    }
    if (0 < tmp + C) ans++;
  }
  cout << ans << endl;
  return 0;
}


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

int main(){
  long long int n,m,s,l,ans=0;
  cin >> n >> m;
  if(n>m/2){
    ans = m/2;
  }else{
    ans = n+(m-n*2)/4;
  }
  cout << ans << endl;
}


Measured memory_bytes: 256
from itertools import combinations

EPS = 1e-8

N, K, *XYC = map(int, open(0).read().split())
PC = [(complex(x, y), c) for x, y, c in zip(*[iter(XYC)] * 3)]


def intersection(A, r, B, s):
    D = B - A
    d = abs(D)

    cos_t = (d * d + r * r - s * s) / (2 * d * r)
    sin_t = max(1 - cos_t * cos_t, 0.0) ** 0.5

    R = r * complex(cos_t, sin_t)
    D /= d

    return (
        A + D * R,
        A + D * R.conjugate(),
    )


def is_ok(T):
    A = [p for p, _ in PC]
    for (p1, c1), (p2, c2) in combinations(PC, 2):
        A += intersection(p1, T / c1, p2, T / c2)

    return any(K <= sum(1 for p, c in PC if c * abs(a - p) < T + EPS) for a in A)


ng, ok = 0, 1000000
for _ in range(100):
    md = (ng + ok) / 2
    if is_ok(md):
        ok = md
    else:
        ng = md

print(ok)

Measured memory_bytes: 70748
import java.util.Scanner;

public class Main {

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

		int N=sc.nextInt();
		int D=sc.nextInt();

		int[][] X=new int[N][D];

		for(int i=0;i<N;i++){
			for(int j=0;j<D;j++) X[i][j]=sc.nextInt();
		}

		int ans=0;

		for(int i=0;i<N-1;i++){

			for(int k=i+1;k<N;k++){

				double d=0.0;

				for(int j=0;j<D;j++){
					d+=Math.pow(Math.abs(X[i][j]-X[k][j]),2);
				}

				d=Math.sqrt(d);

				//System.out.println(d);

				String[] str=(String.valueOf(d)).split("");

				int len=str.length;

				if(str[len-2].equals(".") && str[len-1].equals("0")) ans++;
			}

		}

		System.out.println(ans);

		sc.close();
	}


}


Measured memory_bytes: 21972
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <string.h>
using namespace std;
template<class T> inline void YES(T condition){ if(condition) cout << "YES" << endl; else cout << "NO" << endl; }
template<class T> inline void Yes(T condition){ if(condition) cout << "Yes" << endl; else cout << "No" << endl; }
template<class T> inline void POSS(T condition){ if(condition) cout << "POSSIBLE" << endl; else cout << "IMPOSSIBLE" << endl; }
template<class T> inline void Poss(T condition){ if(condition) cout << "Possible" << endl; else cout << "Impossible" << endl; }
template<class T> inline void First(T condition){ if(condition) cout << "First" << endl; else cout << "Second" << endl; }
template<class T = string, class U = char>int character_count(T text, U character){ int ans = 0; for(U i: text){ ans += (i == character); } return ans; }
long power(long base, long exponent, long module){ if(exponent % 2){ return power(base, exponent - 1, module) * base % module; }else if(exponent){ long root_ans = power(base, exponent / 2, module); return root_ans * root_ans % module; }else{ return 1; }}
struct position{ int y, x; }; position move_pattern[4] = {{-1, 0}, {0, 1}, {1, 0}, {0, -1}}; // double euclidean(position first, position second){ return sqrt((second.x - first.x) * (second.x - first.x) + (second.y - first.y) * (second.y - first.y)); }
template<class T, class U> string to_string(pair<T, U> x){ return to_string(x.first) + "," + to_string(x.second); }
template<class itr> void array_output(itr start, itr goal){ string ans; for(auto i = start; i != goal; i++){ ans += to_string(*i) + " "; } ans.pop_back(); cout << ans << endl; }
template<class itr> void cins(itr start, itr goal){ for(auto i = start; i != goal; i++){ cin >> (*i); } }
template<class T> T gcd(T a, T b){ if(a && b){ return gcd(min(a, b), max(a, b) % min(a, b)); }else{ return a; }} template<class T> T lcm(T a, T b){ return a / gcd(a, b) * b; }
#define mod long(1e9 + 7)
#define all(x) (x).begin(), (x).end()
#define bitcount(n) __builtin_popcountl(long(n))
#define fcout cout << fixed << setprecision(10)
#define highest(x) (63 - __builtin_clzl(x))

int main(){
    int n;
    cin >> n;
    cout << 1110 - n << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;
public class Main{
public static void main(String[] args){
Scanner sc = new Scanner(System.in);
int a = sc.nextInt();
int b = sc.nextInt();
int area = a*b;
int length = 2*(a+b);
System.out.println(area+" "+length);
sc.close();    
}
}


Measured memory_bytes: 26136
#include<bits/stdc++.h>
using namespace std;
namespace $$f
{
	template<typename T> void read(T &a)
	{
		a=0;
		int f=1;
		char c=getchar();
		while(!isdigit(c))
		{
			if(c=='-')
			{
				f=-1;
			}
			c=getchar();
		}
		while(isdigit(c))
		{
			a=a*10+c-'0';
			c=getchar();
		}
		a=a*f;
	}
	template <typename T> void write(T a)
	{
		if(a<0)
		{
			a=-a;
			putchar('-');
		}
		if(a>9)
		{
			write(a/10);
		}
		putchar(a%10+'0');
	}
	template <typename T> void writeln(T a)
	{
		write(a);
		puts("");
	}
}
long long n,high,last_high,ans;
int main()
{
	$$f::read(n);
	while(n--)
	{
		$$f::read(high);
		if(high>last_high)
		{
			ans+=high-last_high;
		}
		last_high=high;
	}
	$$f::write(ans);
}


Measured memory_bytes: 256
#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++)
#define whole(f, x, ...) ([&](decltype((x)) whole) { return (f)(begin(whole), end(whole), ## __VA_ARGS__); })(x) // decltypeで型取得、引数があればva_argsのところに入れる
using namespace std;
typedef long long ll; // long longをllでかけるようにした
const int INF = 1e9;
#define int long long
#define mod 1000000007
template <typename T = long long > T in () { T x; cin >> x; return(x);}
// int a = in() のように使うlong long以外の型の時はstirng s = in<string>()のように型を指定する

signed main(void){
    int n = in(), m = in();
    int ans = 1;
    if(abs(n - m) >= 2){
        cout << 0 << endl;
        return 0;
    }
    else{
        if(n == m + 1) swap(n, m);
        REP(i, n){
            ans *= (i + 1);
            ans %= mod;
        }
    }
    ans *= ans;
    ans %= mod;
    if(n == m) ans *= 2 % mod;
    else ans *= (n + 1) % mod;
    ans %= mod;
    cout << ans << endl;
}

Measured memory_bytes: 256
package main

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

func main() {
	scanner := bufio.NewScanner(os.Stdin)
	var N, M int
	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &N)

	sset := make(map[string]int)
	for i := 0; i < N; i++ {
		var str string
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%s", &str)
		sset[str]++
	}

	scanner.Scan()
	fmt.Sscanf(scanner.Text(), "%d", &M)
	tset := make(map[string]int)
	for i := 0; i < M; i++ {
		var str string
		scanner.Scan()
		fmt.Sscanf(scanner.Text(), "%s", &str)
		tset[str]++
	}

	ans := 0
	for s, cnt := range sset {
		ans = max(ans, cnt-tset[s])
	}
	fmt.Println(ans)
}

func max(ns ...int) int {
	ret := math.MinInt64
	for _, n := range ns {
		if n > ret {
			ret = n
		}
	}
	return ret
}


Measured memory_bytes: 640
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
int main(){
    int N,W;
    cin>>N>>W;
    vector<ll> dp(W+1,0);
    for(int i=0; i<N; ++i){
        ll w,v;
        cin>>w>>v;
        vector<ll> new_dp(W+1,0);
        for(int weight=1; weight<=W; ++weight){
            if(w<=weight){
                new_dp[weight]=max(v + dp[weight-w], dp[weight]);
            }
            else{
                new_dp[weight]=dp[weight];
            }
        }
        dp=new_dp;
    }
    cout<<dp[W]<<"\n";
}

Measured memory_bytes: 1804
#include "bits/stdc++.h"

using namespace std;
using ll = long long;
using ull = unsigned long long;

typedef pair<int, int>pi;
typedef pair<ll, ll> P;
typedef pair<ll, P> PP;
typedef pair<P, P> PPP;

const ll MOD = 1e9 + 7;
const ll INF = 9e18;
const double DINF = 5e14;
const double eps = 1e-10;
const int di[4] = { 1,0,-1,0 }, dj[4] = { 0,1,0,-1 };

#define ALL(x) (x).begin(),(x).end()
#define ALLR(x) (x).rbegin(),(x).rend()
#define pb push_back
#define eb emplace_back
#define fr first
#define sc second

int n, k, p;

int main() {
	cin >> n;
	for (int i = 0;i < n;i++) {
		cin >> k >> p;
		if (k%p == 0)cout << p << endl;
		else cout << k % p << endl;
	}
	return 0;
}


Measured memory_bytes: 3096
#include <iostream>
using namespace std;
int cnt[100010];
int main(){
	int n,m; cin >>n>>m;
	int a,b;
	for(int i=0;i<m;i++){
		cin >>a>>b;
		cnt[a-1]++;
		cnt[b-1]++;
	}
	for(int i=0;i<n;i++){
		if(cnt[i]%2==1){
			cout << "NO" << endl;
			return 0;
		}
	}
	cout << "YES" << endl;
}

Measured memory_bytes: 640
using System;
using System.Linq;

namespace AtCoder
{
    class Program2
    {

        static void Main(string[] args)
        {
            //lee una linea con numeros
            var cantidades = Console.ReadLine().Split(' ').Select(x => Int64.Parse(x)).ToArray();

            //separar numeros
            Int64 N = cantidades[0];
            Int64 M = cantidades[1];

            Int64 respuesta = N;
            bool yaesta = false;

            if (M == 1)
                Console.WriteLine("0");
            else
            {
                respuesta = N % M;

                while (!yaesta)
                {
                    Int64 resta = respuesta - M;
                    Int64 absoluto = Math.Abs(resta);

                    if (absoluto > respuesta)
                        yaesta = true;
                    else
                        respuesta = absoluto;
                }
                Console.WriteLine(respuesta);
            }

        }


    }
}

Measured memory_bytes: 13396
#include <bits/stdc++.h>
using namespace std;
int main()
{
  int a,b;
  cin >> a >> b;
  if(a>=b+1) cout << a*2-1 << endl;
  else if (b>=a+1) cout << b*2-1 << endl;
  else cout << a+b << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;

namespace CSharp
{
    class Program
    {
        public static void Main()
        {
            var tmp = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToArray();

            var A = tmp[0];
            var B = tmp[1];
            var C = tmp[2];

            var ans = C - A + B;

            if(ans >= 0)
            {
                Console.WriteLine(ans);
            }
            else
            {
                Console.WriteLine(0);
            }
        }
    }
}


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

using namespace std;

int falling_asleep(int N, string& X, vector<string>& s, vector<int>& t) {
	int pos = 1 + distance(s.begin(), find(s.begin(), s.end(), X));
	return accumulate(t.begin() + pos, t.end(), 0);
}

int main() {
	int N;
	string X;
	cin >> N;
	vector<string> s(N);
	vector<int> t(N);
	for (int i = 0; i < N; i++)
		cin >> s[i] >> t[i];
	cin >> X;
	cout << falling_asleep(N, X, s, t);
	return 0;
}

Measured memory_bytes: 256
import java.util.*;

public class Main{
   public static void main(String[] args) {
      Scanner sc =new Scanner(System.in);
 for(;;){
	 int n=sc.nextInt();
	 if(n==-1)break;
    double x=1;
    double y=0;
    for(int i=2;i<=n;i++){
    	double d =Math.sqrt(x*x+y*y);
    	double dx = -y/d;
    	double dy = x/d;
    	x+=dx;
    	y+=dy;
    }
    System.out.printf("%.2f\n%.2f\n",x,y);
 }
 }
}

Measured memory_bytes: 17200
m=0
def merge(a,left,mid,right):
    n1=mid-left
    n2=right-mid
    el=a[left:mid]
    ar=a[mid:right]
    el.append(float("inf"))
    ar.append(float("inf"))
    i=0
    j=0
    for k in range(left,right):
        global m
        m+=1
        if(el[i] <= ar[j]):
            a[k] = el[i]
            i=i+1
        else:
            a[k]=ar[j]
            j=j+1

def merge_sort(a,left,right):
    if(left+1<right):
        mid=(left+right)//2
        merge_sort(a,left,mid)
        merge_sort(a,mid,right)
        merge(a,left,mid,right)
    else:
        if(a[left]>a[right-1]):
            a[left],a[right-1]=a[right],a[left]



n=int(input())
s=input()
a=list(map(int,s.split()))
merge_sort(a,0,n)
a=map(str,a)
print(" ".join(list(a)))
print(m)
    

Measured memory_bytes: 71748
#include<iostream>
using namespace std;
int main(){
 int a,b;
  cin>>a>>b;
  int c,d;
  cin>>c>>d;
  int k;
  cin>>k;
  int min=0;
  min=60-b;
  min+=d;
  min=min+(c-a-1)*60;
  cout<<min-k<<endl;
  
  
  return 0;
}

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

#define lint long long

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

    int sum = 0;
    for(int i = 0; i < S.length(); ++i){
        if(S[i] == '+'){
            sum++;
        } else {
            sum--;
        }
    }
    
    cout << sum << endl;
}

Measured memory_bytes: 256
class UnionFind:
    def __init__(self, size):
        self.data = [-1 for _ in range(size)]
    def find(self, x):
        if self.data[x] < 0:
            return x
        else:
            self.data[x] = self.find(self.data[x])
            return self.data[x]
    def union(self, x, y):
        x, y = self.find(x), self.find(y)
        if x != y:
            if self.data[y] < self.data[x]:
                x, y = y, x
            self.data[x] += self.data[y]
            self.data[y] = x
        return (x != y)
    def same(self, x, y):
        return (self.find(x) == self.find(y))
    def size(self, x):
        return -self.data[self.find(x)]

N, M = map(int, input().split())
uf = UnionFind(N + M + 1)
for i in range(1, N + 1):
    K, *L = map(int, input().split())
    for l in L:
        uf.union(i, l + N)

if all(uf.same(i, N) for i in range(1, N)):
    print("YES")
else:
    print("NO")


Measured memory_bytes: 9464
use std::str::FromStr;
use std::fmt::Debug;

fn read_as_vec<T>() -> Vec<T>
where T: FromStr, <T as FromStr>::Err : Debug{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().split_whitespace().map(|c| T::from_str(c).unwrap()).collect()
}

fn read_as_string() -> String{
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).unwrap();
    s.trim().to_string()
}

fn is_dead_left(s: &[char], spells: &[(char, char)], n: usize) -> bool{
    let mut current = n;
    for &(trout, mov) in spells{
        if trout == s[current]{
            if mov == 'L'{
                if current > 0{
                    current -= 1;
                }else{
                    return true;
                }
            }else{
                if current < s.len()-1{
                    current += 1;
                }else{
                    return false;
                }
            }
        }
    }
    return false;
}

fn is_dead_right(s: &[char], spells: &[(char, char)], n: usize) -> bool{
    let mut current = n;
    for &(trout, mov) in spells{
        if trout == s[current]{
            if mov == 'L'{
                if current > 0{
                    current -= 1;
                }else{
                    return false;
                }
            }else{
                if current < s.len()-1{
                    current += 1;
                }else{
                    return true;
                }
            }
        }
    }
    return false;
}

fn main(){
    let line: Vec<usize> = read_as_vec();
    let (n, q) = (line[0], line[1]);
    let s = read_as_string().chars().collect::<Vec<char>>();

    let mut spells: Vec<(char, char)> = vec![];

    for _ in 0..q{
        //let line: Vec<char> = read_as_vec();
        let line: Vec<char> = read_as_string().chars().filter(|c| *c != ' ').collect();
        spells.push((line[0], line[1]));
    }

    let mut lb = -1;
    let mut ub = n as i32;

    while lb+1 < ub{
        let mid = (ub+lb)/2;
        
        if is_dead_left(&s, &spells, mid as usize){
            lb = mid;
        }else{
            ub = mid;
        }
    }
    
    let left = lb;

    
    let mut lb = -1;
    let mut ub = n as i32;
    
    while lb+1 < ub{
        let mid = (ub+lb)/2;
        //println!("lb = {}, ub = {}, mid = {}", lb, ub, mid);
        if is_dead_right(&s, &spells, mid as usize){
            ub = mid;
        }else{
            lb = mid;
        }
    }
    let right = ub;
    
    println!("{}", right-left-1);
    
    
}




Measured memory_bytes: 8444
s = input()
k = int(input())

asc = [0] * len(s)
for i in range(len(s)):
    asc[i] = ord(s[i]) - ord("a")
i = 0
for i in range(len(s)):
    if 26 - asc[i] <= k and asc[i] != 0:
        x = 26 - asc[i]
        asc[i] = 0
        k -= x
if k > 0:
    asc[-1] += k % 26
for i in range(len(s)):
    asc[i] += ord("a")
    asc[i] = chr(asc[i])
print("".join(asc))

Measured memory_bytes: 10192
#include<bits/stdc++.h>
#define rep(i,N) for(ll i=0; i<N; i++)
using namespace std;
using ll = long long;
const ll MOD = 1000000007;

int main(){
    string s; ll k; cin >> s >> k;
    
    queue<ll> q;
    char tmp = s[0]; ll cnt = 1;
    rep(i, s.size()){
        if(tmp == s[i]){
            cnt++;
        }else{
            q.push(--cnt);
            cnt = 2;
        }
        tmp = s[i];
    }
  	if(cnt != 2 || s.size() == 1) q.push(--cnt);

    ll ans = 0;
  	//cout << q.front() << endl;
    if(q.size() == 1){
        cout << q.front() * k / 2 << endl;
    }else if(s[0] == s[s.size()-1]){
        ll first = q.front(); q.pop();
        while(q.size() != 1){
            ans += q.front() / 2; q.pop();  
        }
        ans *= k;
        ans += (k-1)*((first + q.front()) / 2) + (first / 2) + (q.front() / 2);
        cout << ans << endl;
    }else{
        while(!q.empty()){
            ans += q.front() / 2; q.pop();  
        }
        cout << ans * k << endl;
    }

}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef long double ld;
typedef pair<ll,ll> P;
typedef pair<int,int> Pi;
#define rep(i, n) for (ll i = 0; i < n; i++)
#define FOR(i, a, b) for (ll i = a; i < b; i++)
#define fi first
#define se second
#define endl "\n"

template<typename T> inline bool chmax(T &a, T b){if(a<b){a=b;return true;}return false;}
template<typename T> inline bool chmin(T &a, T b){if(a>b){a=b;return true;}return false;}
template<typename T> ostream& operator<<(ostream& s,const complex<T>& d) {return s<<"("<<d.real()<<", "<<d.imag()<< ")";}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const pair<T1,T2>& d) {return s<<"("<<d.first<<", "<<d.second<<")";}
template<typename T> ostream& operator<<(ostream& s, const vector<T>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i];if(i<len-1) s<<" ";
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const vector<vector<T>>& d){
	int len=d.size();
	rep(i,len){
		s<<d[i]<<endl;
	}
	return s;
}
template<typename T> ostream& operator<<(ostream& s,const set<T>& v){
	s<<"{ ";
	for(auto itr=v.begin();itr!=v.end();++itr) {
		if (itr!=v.begin()) {s<< ", ";}
		s<<(*itr);
	}
	s<<" }";
	return s;
}
template<typename T1, typename T2> ostream& operator<<(ostream& s,const map<T1,T2>& m){
	s<<"{"<<endl;
	for(auto itr=m.begin();itr!=m.end();++itr){
		s<<" "<<(*itr).first<<" : "<<(*itr).second<<endl;
	}
	s<<"}"<<endl;
	return s;
}

const ll mod=1e9+7;
const ll inf=1e17;
const int INF=1e9;
const double PI=acos(-1);
const double EPS=1e-10;

int main(){
	cin.tie(0);
	ios::sync_with_stdio(false);
	int n;
	cin>>n;
	vector<ll> a(n);
	bool flag=false;
	ll ans=0;
	rep(i,n){
		cin>>a[i];
		if(a[i]>=n) flag=true;
	}
	while(flag){
		ll s=0;
		rep(i,n){
			s+=a[i]/n;
		}
		flag=false;
		rep(i,n){
			ll now=a[i];
			a[i]-=(now/n)*n;
			a[i]+=(s-now/n);
			if(a[i]>=n) flag=true;
		}
		ans+=s;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int n = Integer.parseInt(sc.next());
		sc.close();

		if (n <= 999) {
			System.out.println("ABC");
		}
		else {
			System.out.println("ABD");
		}
	}
}

Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
#define rep(i,n) for(int (i)=0;(i)<(int)(n);++(i))
#define all(x) (x).begin(),(x).end()
#define pb push_back
#define fi first
#define se second
#define dbg(x) cout<<#x" = "<<((x))<<endl
template<class T,class U> ostream& operator<<(ostream& o, const pair<T,U> &p){o<<"("<<p.fi<<","<<p.se<<")";return o;}
template<class T> ostream& operator<<(ostream& o, const vector<T> &v){o<<"[";for(T t:v){o<<t<<",";}o<<"]";return o;}

string col="RYGB";

int main()
{
    int h,w,d;
    cin >>h >>w >>d;
    rep(i,h)
    {
        rep(j,w)
        {
            int idx = 0;
            idx |= (i+j)/d %2;
            idx |= ((500*d+i-j)/d %2)*2;
            printf("%c", col[idx]);
        }
        printf("\n");
    }
    return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

const int MAX = 100000;

struct Chasebord{ int H,W; };

void printChasebord(struct Chasebord cb){
  bool isBlack;
  for(int i=0;i<cb.H;i++){
    if(i%2==0){
      isBlack = true;
    } else {
      isBlack = false;
    }
    for(int j=0;j<cb.W;j++){
      if(isBlack){
        printf("#");
      } else {
        printf(".");
      }
      isBlack = !isBlack;
    }
    printf("\n");
  }
}

int main(){
  struct Chasebord chasebords[MAX];
  int length = 0;
  for(int i=0;i<MAX;i++){
    scanf("%d",&chasebords[i].H);
    scanf("%d",&chasebords[i].W);
    if(chasebords[i].H == 0 && chasebords[i].W == 0){
      break;
    } else {
      length++;
    }
  }

  for(int i=0;i<length;i++){
    printChasebord(chasebords[i]);
    printf("\n");
  }

  return 0;
}


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

#define REP(i, n) for(ll i = 0; i < n; i++)
#define REPR(i, n) for(ll i = n; i >= 0; i--)
#define FOR(i, m, n) for(ll i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
#define  DESC std::greater<int>() //sort 3rd arg


int main()
{
	ll n;
	cin >> n;
	vector<int> check;
	int keta = 0;
	//n--;
	while (1) {
		n--;
		int c = n % 26;
		check.push_back(c);
		n = n / 26;
		if (n <= 0) {
			break;
		}
	}

	for (int i = check.size() - 1; i >= 0; i--) {
		cout << (char)('a' + check[i]);
	}

	cout << endl;

	return 0;
}



Measured memory_bytes: 3604
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using P = pair<string,int>;
const double PI = acos(-1);

int main() {
  int n;
  cin >> n;
  vector<int> a(n);
  rep(i,n) cin >> a.at(i);
  int cnt2 = 0;
  rep(i,n)if(a.at(i)%2 == 0) cnt2++;
  int cnt4 = 0;
  rep(i,n)if(a.at(i)%4 == 0) cnt4++;
  cnt2 -= cnt4;
  bool ans  = false;
  if(cnt4 >= n/2) ans = true;
  else if(cnt2 >= n-2*cnt4) ans = true;
  cout <<(ans?"Yes":"No") << endl;
}

Measured memory_bytes: 3684
fun main(args: Array<String>) {
    val bingo = (1..3).map {
        readLine()!!.split(" ").map { it.toInt() }
    }
    val N = readLine()!!.toInt()
    val bn = (1..N).map { readLine()!!.toInt() }
    val ans = solve(bingo, N, bn)
    println(ans)
}

fun solve(bingo: List<List<Int>>, N: Int, bn: List<Int>): String {
    //0,1,2
    //3,4,5
    //6,7,8
    //0,3,6
    //1,4,7
    //2,5,8
    //0,4,8
    //2,4,6

    val realBingo = bingo.flatten()
    val bingo1 = listOf(realBingo[0], realBingo[1], realBingo[2])
    val bingo2 = listOf(realBingo[3], realBingo[4], realBingo[5])
    val bingo3 = listOf(realBingo[6], realBingo[7], realBingo[8])
    val bingo4 = listOf(realBingo[0], realBingo[3], realBingo[6])
    val bingo5 = listOf(realBingo[1], realBingo[4], realBingo[7])
    val bingo6 = listOf(realBingo[2], realBingo[5], realBingo[8])
    val bingo7 = listOf(realBingo[0], realBingo[4], realBingo[8])
    val bingo8 = listOf(realBingo[2], realBingo[4], realBingo[6])


    return if (
        bn.containsAll(bingo1) ||
        bn.containsAll(bingo2) ||
        bn.containsAll(bingo3) ||
        bn.containsAll(bingo4) ||
        bn.containsAll(bingo5) ||
        bn.containsAll(bingo6) ||
        bn.containsAll(bingo7) ||
        bn.containsAll(bingo8)
    ) {
        "Yes"
    } else {
        "No"
    }
}

/**
 * ファクション
 */
fun floor(target: Double): Double {
    return Math.floor(target)
}

fun ceil(target: Double): Double {
    return Math.ceil(target)
}


Measured memory_bytes: 38028
#include<iostream>
#include<string>
#include<vector>

using namespace std;

int main(){
  string s;
  cin >> s;
  char t='a',result='0';
  int sw=0;
  while(t!='{'){
    for(int i=0;s[i]!='\0';i++){
      if(s[i]==t){
        sw=1;
        break;
      }
    }
    if(sw==1){
      t++;
      sw=0;
    }
    else{
      result=t;
      break;
    }
  }
  if(result=='0')
    cout << "None\n";
  else
    cout << result << "\n";
  return 0;
}


Measured memory_bytes: 512
#include <algorithm>
#include <cmath>
#include <iostream>
#include <stdio.h>
#include <string>
#include <vector>

#define rep(i,n) for (int i = 0; i < (n); ++i)
using namespace std;
using ll = long long;
using P = pair<int, int>;
const double PI = 3.1415926535897932;

/* a と b の最大公約数を返す関数 */
long long GCD(long long a, long long b) {
	if (b == 0) return a;
	else return GCD(b, a % b);
}

const int MOD = 1000000007;

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

	for (ll i = k; i <= n + 1; ++i)
	{
		ll first = i * (i - 1) / 2;
		ll last = (n * 2 - i + 1) * i / 2;
		ll add = last - first + 1;
		ret = (ret + add) % MOD;
 	}

	cout << ret << endl;
	return 0;
}

Measured memory_bytes: 3612
#include<iostream>
#include<string>
#include<algorithm>

using namespace std;

int main(){
	int a,b;
	cin >> a >> b;
	if(a % 3 == 0 || b % 3 == 0 || (a + b) % 3 == 0)
		cout << "Possible" << endl;
	else
		cout << "Impossible" << endl;
	
 	return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;

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

		if(a * n > b) {
			System.out.println(b);
		}else {
			System.out.println(a * n);
		}
	}
}


Measured memory_bytes: 21844
#include<bits/stdc++.h>
#define taskname "A"
#define pb push_back
#define mp make_pair
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace std;
using namespace __gnu_pbds;

typedef long long ll;
typedef long double ld;
typedef pair<int,int> ii;
const int maxn = 1e5 + 5;
const int logn = log2(maxn) + 1;
const int mod = 1e9 + 7;
int n;
int a , b;
struct Point{
    int x , y , id;
    bool operator < (const Point & other)const &{
        return mp(x,y) < mp(other.x,other.y);
    }
    Point(){};
    Point(int x , int y , int id):x(x) , y(y) , id(id){};
}p[maxn];
vector<int> adj[maxn];
int ans[maxn];

void Solve(int dis , int delta){
    sort(p+1,p+n+1);
    int pre = 1;
    int l = 1;int r = 1;
    for(int i = 1 ; i <= n ; ++i){
        while(l <= n && p[l] < Point(p[i].x+dis,p[i].y-(dis-delta),0)){
            ++l;
        }
        while(r <= n && p[r] < Point(p[i].x+dis,p[i].y+(dis-delta)+1,0)){
            ++r;
        }
        ans[p[i].id] += r - l;
        pre = max(pre , l);
        for(int j = pre ; j < r ; ++j){
            adj[p[i].id].pb(p[j].id);
            adj[p[j].id].pb(p[i].id);
        }
        pre = r - 1;
    }
}
bool vis[maxn];

ll DFS(int u){
    vis[u] = 1;
    ll ans = ::ans[u];
    for(int c : adj[u]){
        if(vis[c] == 0)ans += DFS(c);
    }
    return ans;
}
int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    if(fopen(taskname".INP", "r")) {
        freopen(taskname".INP", "r", stdin);
        freopen(taskname".OUT", "w", stdout);
    }
    cin >> n >> a >> b;
    for(int i = 1 ; i <= n ; ++i){
        p[i].id = i;
        cin >> p[i].x >> p[i].y;
        tie(p[i].x,p[i].y) = mp(p[i].x - p[i].y , p[i].x + p[i].y);
    }
    int dis = max(abs(p[a].x-p[b].x),abs(p[a].y-p[b].y));
    Solve(dis,0);
    for(int i = 1 ; i <= n ; ++i)swap(p[i].x,p[i].y);
    Solve(dis,1);
    cout << DFS(a);
}


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

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];
    sort(h.begin(), h.end());

    int ans = INT_MAX;
    for (int i=0; i+k-1<n; i++) {
        ans = min(ans, abs(h[i] - h[i+k-1]));
    }

    cout << ans << endl;
}


Measured memory_bytes: 640
#include <iostream>
#include <cstring>
#include <cstdio>
#include <cmath>
#include <cstdlib>
#include <algorithm>

int main()
{
    int n;
    scanf("%d",&n);
    if (n%2==0) printf("%d\n",n);
    else printf("%d\n",n*2);
    return 0;
}


Measured memory_bytes: 256
from collections import defaultdict as dd

def ri():
    return int(input())

def rl():
    return map(int, input().split())

def rl2():
    return list(rl())

N, M = rl()
edges = dd(list)
for i in range(M):
    A, B = rl()
    edges[A].append(B)
    edges[B].append(A)

parents = {1:0}
ring = [1]
while ring:
    nxt = []
    for room in ring:
        for nbr in edges[room]:
            if nbr not in parents:
                parents[nbr] = room
                nxt.append(nbr)
    ring = nxt

if len(parents) < N:
    print ("No")
else:
    print ("Yes")
    for i in range(2, N + 1):
        print (parents[i])



Measured memory_bytes: 120396