akhauriyash/Code-Regression huggingface dataset:
#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn main() {
    let (n, k) = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        let mut ws = s.split_whitespace();
        let a: usize = ws.next().unwrap().parse().unwrap();
        let b: usize = ws.next().unwrap().parse().unwrap();
        (a, b)
    };

    let mut h: Vec<usize> = {
        let mut s = String::new();
        std::io::stdin().read_line(&mut s).unwrap();
        let s = s.trim_right().to_owned();
        s.split_whitespace().map(|x| x.parse().unwrap()).collect()
    };
    let mut dp: Vec<usize> = vec![std::usize::MAX; n + k];

    for _ in 0..k {
        h.push(0);
    }

    dp[0] = 0;

    for i in 0..n {
        for j in 1..k+1 {
            dp[i + j] = std::cmp::min(dp[i + j], dp[i] + abs_sub(h[i], h[i + j]));
        }
    }

    // println!("{:?}", dp);
    println!("{}", dp[n - 1]);
}

fn abs_sub(a: usize, b: usize) -> usize {
    if a > b {
        a - b
    } else {
        b - a
    }
}


Measured memory_bytes: 8444
n = int(input())
a = list(map(int,input().split()))
t = max(a)
p = [0]*(t+1)
for x in a:
  p[x] += 1
if t%2:
  if any(p[:t//2+1]) or p[t//2+1] != 2 or min(p[t//2+1:]) < 2:
    print('Impossible')
  else:
    print('Possible')
else:
  if any(p[:t//2]) or p[t//2] != 1 or min(p[t//2+1:]) < 2:
    print('Impossible')
  else:
    print('Possible')

Measured memory_bytes: 3064
/* Author : Aaryan Srivastava ^__^ */ 
#include <bits/stdc++.h>
#include <random>
#include <chrono>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp> 
#define pb push_back
#define popb pop_back
#define mt make_tuple 
#define eb emplace_back
#define mp make_pair
#define ff first
#define ss second 
#define ull unsigned long long  
#define pii pair<int, int>
#define piii pair<int,pii>
#define beg begin
#define rep(i,n) for(int (i) = 0 ; i < (n) ; i++)
#define repA(i,x,y) for(int i = (x) ; i <= (y) ; i++)
#define repD(i,x,y) for(int i = (x) ; i >= (y) ; i--)
#define all(c) (c).begin(),(c).end()
#define fill(a,val) memset(a,val,sizeof(a))
#define Randomize mt19937 rng(chrono::steady_clock::now().time_since_epoch().count())
#define int ll
using ll = long long;
const int N = 3*1e5 +5 ;
const int mod = 1e9 + 7 ;
const int inf = 1e18 ;
const int SZ = 101 ;
const double eps = 1e-9 ;
using namespace __gnu_pbds;
using namespace std;
using ordered_set =  tree<int,null_type,less<int>,rb_tree_tag,tree_order_statistics_node_update> ;

#ifdef AaryanS
#define mycout cout
#define mycerr cerr 
#endif

#ifndef AaryanS
#define mycout if(false) cout
#define mycerr if(false) cerr
#endif

vector<int> cache(N,inf) , a; 
int k;
int dp(int cur){
	if(cur == 0) 
		return 0 ;
	if(cur < 0)
		return inf ;
	int& ans = cache[cur] ;
	if(ans != inf) return ans ;
	for(int i = 1 ; i <= k ; ++i)
		if(cur - i >= 0)
			ans = min(ans, dp(cur - i) + abs(a[cur] - a[cur - i])) ;
	return ans ;
}
void solve()
{
	int n ;
	cin >> n >> k ;
	a.resize(n);
	for(auto &it : a) cin >> it; 
	cout << dp(n-1) ;
}   

     
int32_t main(int32_t argc, char *argv[])
{
    double t1 = clock() ;
    ios::sync_with_stdio(0);    
    cin.tie(0); cout.tie(0);
    int TC = 1, t = 0;
    //cin >> TC ;
    while(t++ < TC)
    {
        //cout << "Case #" << t << ": " ;
        solve();
        //cout << endl ;
    }
    mycerr << "Time : " << 1000 *(clock() - t1)/CLOCKS_PER_SEC << " ms\n" ;
    return 0;
}

Measured memory_bytes: 8064
import java.util.PriorityQueue

fun main(args: Array<String>) {
  val N = readInputLine().toInt()
  val queue = PriorityQueue<Pair<Long, Int>>(N) { x, y -> x.first.compareTo(y.first) }
  
  readInputLine().split(" ").map {
    queue.add(Pair(it.toLong(), 1))
  }
  
  while (queue.size != 1) {
    val (size1, color1) = queue.poll()!!
    val (size2, color2) = queue.poll()!!
    
    if (size1 * 2L < size2) {
      queue.add(Pair(size1 + size2, color2))
    } else {
      queue.add(Pair(size1 + size2, color1 + color2))
    }
  }
  
  println(queue.poll()!!.second)
}

fun readInputLine(): String {
  return readLine()!!
}


Measured memory_bytes: 76416
#include<iostream>
#include<string>
#include<cstdio>
#include<cmath>
#include<cstring>
#include<algorithm>
#include<vector>
#include<functional>
#include<iomanip>
#include<queue>
#include<cassert>
#include<tuple>
#include<set>
#include<map>
#include<list>
#include<bitset>

#define PB push_back
#define ALL(a)  (a).begin(),(a).end()
#define DWN(a)  (a).begin(),(a).end(), greater<int>()
#define rep(i, m) for (int i = 0; i < m; i++)
#define REP(i, n, m) for (int i = n; i < m; i++)

#define mod 1000000007

using namespace std;

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

const int dx[4] = { 1, 0, -1, 0 };
const int dy[4] = { 0, 1, 0, -1 };
const int INF = (int)1e9;

int main()
{
	int n;
	cin >> n;
	vector<int> a(n);
	rep(i, n) cin >> a[i];
	ll res = 0LL;
	int right = 0;
	int sum = 0;
	for (int left = 0; left < n; left++) { //左端
		while (right < n && (sum ^ a[right]) == (sum + a[right])) { //lからrまでのa[i]を加算する
			sum += a[right];
			right++;
		}
		res += right - left; //区間の個数
		if (right == left) right++; //同じときは右端をずらす。
		else {
			sum -= a[left]; //左端をずらす分だけ減らす
		}
	}
	cout << res << endl;
	return 0;
}

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

int main(void){
  int n;
  int diff = 0;
  int cmp;
  cin >> n;
  for (int i = 1; i <= n; i++){
   int a;
   cin >> a;
   if(i != a){
     diff++;   
   }
  }
  
  if(diff <= 2){
   cout << "YES" << endl;
  }
  else{
   cout << "NO" << endl;
  }

  return 0;
  
}

Measured memory_bytes: 256
import Data.List (foldl')

main :: IO ()
main = print . solve . map read . tail . lines =<< getContents

solve :: [Int] -> Int
solve = fst . foldl' (\(a, b) c -> let d = min b c; (e, f) = (c - d) `divMod` 2 in (a + d + e, f)) (0, 0)


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

using namespace std;

#define int long long
const double PI = 3.14159265358979323846;
typedef vector<int> vint;
typedef pair<int, int> pint;
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};
// cout << fixed << setprecision(20);

// FenwickTree (0 - indexed)
template<class T>
class FenwickTree {
    int n;
    std::vector<T> data;
public:
    FenwickTree(int n) : n(n), data(n + 1) {}

    // [0, i)の区間和を取得する
    T sum(int i) {
        T s = 0;
        for (; i > 0; i -= i & -i)s += data[i];
        return s;
    }

    // [l, r)の区間和を取得する
    T sum(int l, int r) { return sum(r) - sum(l); }

    // 要素iにxを加算する
    void add(int i, T x) { for (i++; i <= n; i += i & -i)data[i] += x; }
};

// 階乗、階乗逆元テーブル


int N;
int x[220000], y[220000];
pint point[220000];
int tw[220000];
int mod = 998244353;

signed main() {
    cin >> N;
    for (int i = 0; i < N; i++) {
        cin >> x[i] >> y[i];
        point[i] = pint(x[i], y[i]);
    }
    sort(point, point + N);
    for (int i = 0; i < N; i++)point[i].first = i;
    for (int i = 0; i < N; i++)swap(point[i].first, point[i].second);
    sort(point, point + N);
    FenwickTree<int> l(N), r(N);
    for (int i = 0; i < N; i++)r.add(i, 1);
    int ans = 0;
    tw[0] = 1;
    for (int i = 1; i <= N; i++)tw[i] = tw[i - 1] * 2 % mod;
    for (int i = 0; i < N; i++) {
        r.add(point[i].second, -1);
        int A = l.sum(point[i].second);
        int B = l.sum(point[i].second, N);
        int C = r.sum(point[i].second);
        int D = r.sum(point[i].second, N);
        (ans += tw[N] - 1 + mod) %= mod;
        (ans -= tw[A + B] - mod) %= mod;
        (ans -= tw[A + C] - mod) %= mod;
        (ans -= tw[B + D] - mod) %= mod;
        (ans -= tw[C + D] - mod) %= mod;
        (ans += tw[A]) %= mod;
        (ans += tw[B]) %= mod;
        (ans += tw[C]) %= mod;
        (ans += tw[D]) %= mod;
        l.add(point[i].second, 1);
    }
    cout << ans << endl;

}

Measured memory_bytes: 11648
#include<iostream>
#include<string>
#include<algorithm>
#include<math.h>
#include<queue>
#include<vector>
#include<map>
#include<iomanip>
#include<tuple>
#include<bitset>


using namespace std;
#define rep(i,n) for(int i=0;i<(n);i++)
#define printfloat(x) cout << fixed << setprecision(7) << (x) << endl;
#define printbit(x) cout << bitset<15>(x) << endl;
using ll = long long int;



long double pi = 3.14159265359;



priority_queue<int> q;
int n,m;
int t;

int main(){
    cin >> n >> m;
    rep(i,n) {
        cin >> t;
        q.push(t);
    }
    rep(i,m){
        int x = q.top();q.pop();
        x = x/2;
        // cout << x << endl;
        q.push(x);
    }
    ll ans=0;
    rep(i,n){
        ans += q.top();q.pop();
    }
    cout << ans << endl;

return 0;
}

Measured memory_bytes: 3828
r, c = [int(arg) for arg in input().split()]
table = [[int(arg) for arg in input().split()] for _ in range(r)]
new_row = [0] * (c+1)
for row in table:
    row.append(sum(row))
    for j, v in enumerate(row):
        new_row[j] += v
table.append(new_row)
for row in table:
    print(' '.join([str(i) for i in row]))


Measured memory_bytes: 5684
import fractions as math

n,x = map(int,input().split())
s = list(map(int,input().split()))

a = []
for i in s:
    a.append(abs(i-x))

tmp = a[0]
for i in range(1,len(a)):
    tmp = math.gcd(tmp,a[i])

print(tmp)

Measured memory_bytes: 16240
#define _USE_MATH_DEFINES
#include <cstdio>
#include <iostream>
#include <sstream>
#include <fstream>
#include <iomanip>
#include <algorithm>
#include <cmath>
#include <complex>
#include <string>
#include <vector>
#include <array>
#include <list>
#include <queue>
#include <stack>
#include <set>
#include <map>
#include <bitset>
#include <numeric>
#include <limits>
#include <climits>
#include <cfloat>
#include <functional>
#include <iterator>
#include <memory>
#include <regex>
using namespace std;

int main()
{
    int l, r, d;
    cin >> l >> r >> d;

    int ans = r / d - (l - 1) / d;
    cout << ans << endl;

    return 0;
}


Measured memory_bytes: 3632
n,k=map(int,input().split())
a=[i for i in input()]
c=[0]*n
for i in range(1,n):
    if a[i]=="C" and a[i-1]=="A":
        c[i]=c[i-1]+1
    else:
        c[i]=c[i-1]
for w in range(k):
    l,r=map(int,input().split())
    print(c[r-1]-c[l-1])

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

namespace PaizaSkillCheck
{
    public class Program
    {
        public static int[] A = new int[1000000];

        public static void Main(string[] args)
        {
            //string[] line = Console.ReadLine().Split(' ');
            int s = int.Parse(Console.ReadLine());
            A[1] = s;

            Dictionary<int, bool> dic = new Dictionary<int, bool>();
            dic.Add(s, true);
            for (int i = 2; i < A.Length; i++)
            {
                int v = f(A[i - 1]);
                A[i] = v;

                if (dic.ContainsKey(v))
                {
                    Console.WriteLine(i);
                    return;
                }
                dic.Add(v, true);
            }
        }

        public static int f(int n)
        {
            bool isEven = n % 2 == 0;

            return isEven ? (n / 2) : (3 * n + 1);
        }
    }
}


Measured memory_bytes: 13268
#include <iostream>
#include <algorithm>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <utility>
#include <string.h>
#include <map>
#include <stack>
#include <iomanip>
#include <chrono>
#include <random>
#include <math.h>
#include <time.h>
#include <assert.h>
#define rnd mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
#define ll long long
#define pb push_back 
#define mp make_pair
#define ff first
#define ss second
#define FIO ios_base::sync_with_stdio(false); cin.tie(NULL);
#define all(x) x.begin(),x.end() 
#define PII pair <ll,ll>
#define N 100005
#define MOD 1000000007
#define INF 1000000000000000000
using namespace std;

int main()
{
	int n, dp[N], h[N];
	cin >> n;
	for (int i = 1; i <= n; ++i)
	{
		cin >> h[i];
	}
	dp[1] = 0;
	dp[2] = abs(h[2] - h[1]);
	for (int i = 3; i <= n; ++i)
	{
		dp[i] = min(dp[i - 1] + abs(h[i] - h[i - 1]), dp[i - 2] + abs(h[i] - h[i - 2]));
	}
	cout << dp[n];
}


Measured memory_bytes: 1024
x,y=map(int,input().split())
if (x+y)%3:print(0)
else:
    sab=(x+y)//3
    a=y-sab
    b=sab-a
    if a<0 or b<0:print(0);exit()
    mod=10**9+7
    fact=[1]*(sab+1)
    inv=[1]*(sab+1)
    for i in range(2,sab+1):
        fact[i]=i*fact[i-1]%mod
    inv[-1]=pow(fact[-1],mod-2,mod)
    for i in range(sab,1,-1):
        inv[i-1]=inv[i]*i%mod
    def comb(x,y):return fact[x]*inv[y]%mod*inv[x-y]%mod if x>=y>=0 else 0
    print(comb(sab,a))

Measured memory_bytes: 55796
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;

public class MainClass
{
	public const long Giri = 1000000007;
	public const long DpInf = 99999999999999;
	public static void Main(string[] args)
	{
		var s = Console.ReadLine();
		var t = Console.ReadLine();
		var u = Console.ReadLine();
		Console.WriteLine("{0}{1}{2}", s[0], t[1], u[2]);
	}
	
	static long GCD(long a, long b)
	{
		var v = new[] { a, b };
		while (v[1] != 0) { v = new[] { v[1], v[0] % v[1] }; }
		return v[0];
	}
	public static string[] Input() { return Console.ReadLine().Split(); }
}

public static class Smarter
{
	public static int ToInt(this string str) { return int.Parse(str); }
	public static long ToLong(this string str) { return long.Parse(str); }
	public static int[] ToInt(this string[] str, int offset = 0)
	{
		var r = new int[str.Length];
		for(int i = 0; i < str.Length; i++) r[i] = str[i].ToInt() + offset;
		return r;
	}
}


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

using namespace std;

#define ll long long
#define pi pair<int, int>
#define pb push_back
#define fr first
#define sc second
#define endl '\n'

const int mxn = 1e6 + 5;
const ll MOD = 1e9 + 7;
int arr[mxn];
int n, m, k;
string s, t;

ll pow(ll A,ll B,ll R=1)
{while(B){if(B&1)R=R*A%MOD;A=A*A%MOD;B>>=1;}return R;}


void read(){
    cin >> n;
//    for(int i = 0, u, v; i < n; i++){
//        cin >> arr[i];
//    }
}

void solve(){
    double p = 3.14159265359;
    double res = p * (double) n * (double) 2;
    cout.precision(10);
    cout << res << endl;
}


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


Measured memory_bytes: 3836
l, r = map(int, input().split())

d = r - l + 1

if d >= 2019:
    print(0)
else:
    ans = 2018

    n = l % 2019
    for i in range(n, n + d):
        for j in range(i + 1, n + d):
            r = (i * j) % 2019
            if r < ans:
                ans = r

    print(ans)


Measured memory_bytes: 40684
X = int(input())
if X == 0:
    print(0,0)
    exit()
for i in range(0,10000):
    for j in range(0,10000):
        if i!=j and (X % abs(i-j) == 0 or X % abs(i+j) == 0):
            if i**5 - j**5 ==X:
                print(i,j)
                exit()
            if i**5 + j**5 ==X:
                print(i,-j)
                exit()
            if -i**5 + j**5 ==X:
                print(-i,-j)
                exit()
            if - i**5 - j**5 ==X:
                print(-i,j)
                exit()

Measured memory_bytes: 67800
import java.util.Scanner;

public class Main {

  public static void main(String[] args) {

    Scanner sc = new Scanner(System.in);
    boolean[] b = new boolean[1001];
    b[1] = true;
    for (int i = 2; i <= 32; i++) {
      int tmp = i * i;
      while (tmp <= 1000) {
        b[tmp] = true;
        tmp *= i;
      }
    }

    int x = sc.nextInt();
    int i = x;
    while (true) {
      if (b[i]) {
        System.out.println(i);
        return;
      }
      i--;
    }

  }
}

Measured memory_bytes: 35744
import java.util.Scanner;
public class Main {
	public static void main(String[] args) {
		Scanner scan = new Scanner(System.in);
		int N = scan.nextInt();
		String S = scan.next();
		scan.close();
		String ans = "";
		for(int i = 0;i<S.length();i++) {
			String s = S.substring(i,i+1);
			int sn=0;
			if(s.equals("A"))sn=0;
			if(s.equals("B"))sn=1;
			if(s.equals("C"))sn=2;
			if(s.equals("D"))sn=3;
			if(s.equals("E"))sn=4;
			if(s.equals("F"))sn=5;
			if(s.equals("G"))sn=6;
			if(s.equals("H"))sn=7;
			if(s.equals("I"))sn=8;
			if(s.equals("J"))sn=9;
			if(s.equals("K"))sn=10;
			if(s.equals("L"))sn=11;
			if(s.equals("M"))sn=12;
			if(s.equals("N"))sn=13;
			if(s.equals("O"))sn=14;
			if(s.equals("P"))sn=15;
			if(s.equals("Q"))sn=16;
			if(s.equals("R"))sn=17;
			if(s.equals("S"))sn=18;
			if(s.equals("T"))sn=19;
			if(s.equals("U"))sn=20;
			if(s.equals("V"))sn=21;
			if(s.equals("W"))sn=22;
			if(s.equals("X"))sn=23;
			if(s.equals("Y"))sn=24;
			if(s.equals("Z"))sn=25;
			sn+=N;
			if(sn%26==0)ans+="A";
			if(sn%26==1)ans+="B";
			if(sn%26==2)ans+="C";
			if(sn%26==3)ans+="D";
			if(sn%26==4)ans+="E";
			if(sn%26==5)ans+="F";
			if(sn%26==6)ans+="G";
			if(sn%26==7)ans+="H";
			if(sn%26==8)ans+="I";
			if(sn%26==9)ans+="J";
			if(sn%26==10)ans+="K";
			if(sn%26==11)ans+="L";
			if(sn%26==12)ans+="M";
			if(sn%26==13)ans+="N";
			if(sn%26==14)ans+="O";
			if(sn%26==15)ans+="P";
			if(sn%26==16)ans+="Q";
			if(sn%26==17)ans+="R";
			if(sn%26==18)ans+="S";
			if(sn%26==19)ans+="T";
			if(sn%26==20)ans+="U";
			if(sn%26==21)ans+="V";
			if(sn%26==22)ans+="W";
			if(sn%26==23)ans+="X";
			if(sn%26==24)ans+="Y";
			if(sn%26==25)ans+="Z";
		}
		System.out.println(ans);
	}
}


Measured memory_bytes: 147408
#include <stdio.h>
#include <string.h>
char str[200];
int len;
int count(int num)
{
	int i;
	int j;
	char stat[27];
	int index=0;
	int x=1;
	int flag=0;
	int ret=0;
	for(i=0;i<=num-1;i++)
	{
		flag=0;
		for(x=1;x<=index;x++)
		{
			if(stat[x]==str[i])
			{
				flag=1;
				break;
			}
		}
		
		if(flag==1)
		{
			;
		}else {
			
			stat[++index]=str[i];
			flag=0;
			for(j=num;j<=len-1;j++)
			{
				if(str[i]==str[j])
				{
					flag=1;
				}
			}
			if(flag==1)
			{
				ret++;
			}else {
				;
			}
		}
	}
	return ret;
}
int main()
{
	
	int max;
	int i;
	int temp;
	scanf("%d",&len);
	scanf("%s",&str);

	max=0;
	for(i=1;i<=len-1;i++)
	{
		temp=count(i);
	//	printf("%d<<<<<\n",temp);
		if(max<temp)
		{
	//		printf("%d   %d\n",i,temp);
			max=temp;
		}
	}
	printf("%d\n",max);
}


Measured memory_bytes: 128
//{{{
#include<algorithm>
#include<cmath>
#include<fstream>
#include<iomanip>
#include<iostream>
#include<map>
#include<numeric>
#include<queue>
#include<random>
#include<set>
#include<sstream>
#include<sys/time.h>
#include<unordered_map>
#include<unordered_set>
#include<vector>
using ll = long long;
enum : int { M = (int)1e9 + 7 };
enum : ll { MLL = (ll)1e18L + 9 };
using namespace std;
#ifdef LOCAL
#include"rprint2.hpp"
#else
#define FUNC(name) template <ostream& out = cout, class... T> void name(T&&...){ }
FUNC(prints) FUNC(printw) FUNC(printwe) FUNC(printb) FUNC(printbe) FUNC(printd) FUNC(printde) FUNC(printdu);
#endif
template <class S, class T>
istream& operator >> (istream& in, pair<S, T>& p){ return in >> p.first >> p.second; }
template <class T>
istream& operator >> (istream& in, vector<T>& v){ for(auto& e : v){ in >> e; } return in; }
//}}}

int main(){
    cin.tie(0);
    ios::sync_with_stdio(false);
    int t, x;
    cin >> t >> x;
    cout << fixed << setprecision(20) << 1.0 * t / x << '\n';
}


Measured memory_bytes: 256
import collections
import heapq

N, K = map(int, input().split())
A = list(map(int, input().split()))

c = collections.Counter(A)
value_list = list(c.values())
heapq.heapify(value_list)
# print(value_list)

ans = 0
for i in range(len(value_list) - K):
    ans += heapq.heappop(value_list)

print(ans)

Measured memory_bytes: 98768
#include<bits/stdc++.h>
#define ll long long int
using namespace std;

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

ll power(ll x, ll y)
{
    ll res = 1;

    while (y > 0) {

        if (y & 1)
            res = res * x;


        y = y >> 1;
        x = x * x;
    }
    return res;
}

int main()
{
    int a;
    cin>>a;
    string s;
    cin>>s;
    if(a>=3200) cout<<s<<'\n';
    else cout<<"red"<<'\n';
    return 0;
}


Measured memory_bytes: 256
import sys
from sys import stdin
input = stdin.readline

class UnionFind():
  def __init__(self, n):
    self.n = n
    self.d = [-1] * n
  
  def find(self, x):
    if (self.d[x] < 0):
      return x
    else:
      self.d[x] = self.find(self.d[x])
      return self.d[x]
  
  def unite(self, x, y):
    x = self.find(x)
    y = self.find(y)
    if (x == y): return
    if (self.d[x] > self.d[y]):
      x, y = y, x
    self.d[x] += self.d[y]
    self.d[y] = x
  def same(self, x, y): return self.find(x) == self.find(y)
  def size(self, x): return -self.d[self.find(x)]

n, m = map(int, input().split())
uf = UnionFind(n)
for i in range(m):
  a, b = map(int, input().split())
  a -= 1
  b -= 1
  uf.unite(a,b)
ans = 0
for i in range(n):
  ans = max(ans, uf.size(i))
print(ans)

Measured memory_bytes: 14556
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define OUT(x) cout << (x) << endl;
#define REP(i, n) for (int i=0; i<n; ++i)

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

int main(){
    int H, W;
    cin >> H >> W;
    string S[100];
    REP(i, H) cin >> S[i];

    // S[H][W]    
    REP(i, H){
        REP(j, W){
            if(S[i][j] == '#') continue;

            // 8近傍をとる
            int count = 0;
            for(int n=0; n<8; n++){
                const int ni = i + dy[n];
                const int nj = j + dx[n];

                if(nj<0 or W<=nj) continue;
                if(ni<0 or H<=ni) continue;
                if(S[ni][nj] == '#') count++;
            }
            S[i][j] = char(count + '0');
        }
    }
    REP(i, H) cout<<S[i]<<endl;
}


Measured memory_bytes: 256
n = int(input())
s = input()
 
S = len(s)
mod = 10 ** 9 + 7
 
tmp_ans = pow(26, n, mod)
div = pow(26, -1, mod)
 
ans = tmp_ans
 
for i in range(1, n+1):
    tmp_ans = (tmp_ans * 25 * div) % mod
    tmp_ans = ((tmp_ans * (S-1+i)) * pow(i, -1, mod)) % mod
    ans = (ans + tmp_ans) % mod
 
ans %= mod
 
print(ans)

Measured memory_bytes: 10908
#include<bits/stdc++.h>
#include<ext/pb_ds/assoc_container.hpp>
#include<ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;
using ll = long long;
using ld = long double;
using vvll = vector<ll, vector<ll> >;
using vll = vector<ll> ;
#define ordered_set tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update>
#define fastio(); ios_base::sync_with_stdio(false); cin.tie(NULL); cout.tie(NULL);


int main() {
    fastio();

    int N;
    cin >> N;
    string s;
    cin >> s;
    int ANS = 0;
    for(int i = 0;i < N;i ++) {
        if(i == 0 || s[i] != s[i - 1]) {
            ANS ++;
        }
    }
    cout << ANS << "\n";
}

Measured memory_bytes: 512
#define _USE_MATH_DEFINES
#include <iostream>
#include <iomanip>
#include <cstdio>
#include <cmath>
#include <algorithm>
#include <string>

using namespace std;

int main()
{
    string s;
    getline(cin, s);
    for (int i = 0; i < s.size();i++){
        if (64 < s[i] && s[i] <= 64 + 26)
            s[i] += 32;
        else if (96 < s[i] && s[i] <= 96 + 26)
            s[i] -= 32;
    }
    cout << s << endl;
}


Measured memory_bytes: 3144
import java.util.Scanner;

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

        int count = 0;
        Long x, y;

        for(int i = 0; i < num; i++){
            x = sc.nextLong(); y = sc.nextLong();
            if( Math.sqrt(x*x+y*y) <= dis ){
                count++;
            }
        }

        System.out.println(count);
        sc.close();
    }
}

Measured memory_bytes: 59356
import java.util.ArrayList;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		List<int[]> hws = new ArrayList<>();
		while(true) {
			int H = sc.nextInt();
			int W = sc.nextInt();
			
			if(H == 0) break;
			
			int[] hw = new int[]{H, W};
			hws.add(hw);
			
		}
		sc.close();
		
		for(int[] hw : hws) {
			
			for(int hh = 0; hh < hw[0]; hh++) {
				for(int ww = 0; ww < hw[1]; ww++) {
					
					if( (hh+ww) % 2 == 0 ) {
						System.out.print("#");
					} else {
						System.out.print(".");
					}
					
				}
				System.out.println();
			}
			System.out.println();
		}
	}
}

Measured memory_bytes: 35224
n=int(input())
s=str(input())

ans=0#(
count1=0
for i in range(n):
    if s[i]=='(':
        count1+=1
    else:
        if count1==0:
            ans+=1
        else:
            count1-=1

for i in range(ans):
    print('(',end="")
print(s,end="")
for i in range(count1):
    print(')',end="")


Measured memory_bytes: 3060
#include <iostream>

using namespace std;

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

  for (int i=0; i<n; i++) {
    int x;
    cin >> x;
    sum+=min(x*2, (k-x)*2);
  }

  printf("%d\n", sum);
  return 0;
}

Measured memory_bytes: 256
#include <cstdio>
#include <cstring>
#include <stack>
#include <vector>
#define MAXN 110
#define MAXS 5100
using namespace std;

int n,m;
int a[MAXN][MAXN],s[MAXN][MAXN],ex,ey;
int px[MAXN][MAXN],py[MAXN][MAXN],numpx,numpy;
int f[MAXS][MAXS];

int getS(int x1,int x2,int y1,int y2){
	return s[x2][y2]-s[x1-1][y2]-s[x2][y1-1]+s[x1-1][y1-1];
}

int trans(int x1,int x2,int y1,int y2,int x3,int x4,int y3,int y4){
	int tx1=x2-n+ex,tx2=x1+ex-1;
	int ty1=y2-m+ey,ty2=y1+ey-1;
	if(tx1>x3) x3=tx1;
	if(tx2<x4) x4=tx2;
	if(ty1>y3) y3=ty1;
	if(ty2<y4) y4=ty2;
	if(x3<=x4 && y3<=y4) return getS(x3,x4,y3,y4);
	else return 0;
}

int gao(int x1,int x2,int y1,int y2){
	if(x1==x2 && y1==y2) return a[x1][y1];
	int res=0;
	if(x1<x2){
		res=max(res,f[px[x1][x2-1]][py[y1][y2]]+trans(x1,x2-1,y1,y2,x2,x2,y1,y2));
		res=max(res,f[px[x1+1][x2]][py[y1][y2]]+trans(x1+1,x2,y1,y2,x1,x1,y1,y2));
	}
	if(y1<y2){
		res=max(res,f[px[x1][x2]][py[y1][y2-1]]+trans(x1,x2,y1,y2-1,x1,x2,y2,y2));
		res=max(res,f[px[x1][x2]][py[y1+1][y2]]+trans(x1,x2,y1+1,y2,x1,x2,y1,y1));
	}
	return res;
}

int main(){
#ifdef DEBUG
	freopen("E.in","r",stdin);
#endif
	scanf("%d%d",&n,&m);
	for(int i=1;i<=n;i++){
		static char str[MAXN];
		scanf("%s",str+1);
		for(int j=1;j<=m;j++)
			if(str[j]=='o'){
				a[i][j]=1;
			}else if(str[j]=='E'){
				ex=i;
				ey=j;
			}
	}
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++) 
			s[i][j]=a[i][j]+s[i-1][j]+s[i][j-1]-s[i-1][j-1];
	for(int i=1;i<=n;i++)
		for(int j=i;j<=n;j++)
			px[i][j]=++numpx;
	for(int i=1;i<=m;i++)
		for(int j=i;j<=m;j++)
			py[i][j]=++numpy;
	for(int w=1;w<=n;w++)
		for(int h=1;h<=m;h++)
			for(int i=1;i+w-1<=n;i++)
				for(int j=1;j+h-1<=m;j++)
					f[px[i][i+w-1]][py[j][j+h-1]]=gao(i,i+w-1,j,j+h-1);
	printf("%d\n",f[px[1][n]][py[1][m]]);
	return 0;
}


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

int main(){
  int N;
  long long sum = 0;
  cin >> N;
  int a[N];
  for (int i=0; i < N; ++i){
    cin >> a[i];
    a[i] -= i+1;
  }
  sort(a, a+N);
  for (int i=0; i < N/2; ++i)
    sum += a[N/2] - a[i];
  for (int i=N/2; i < N; ++i)
    sum += a[i] - a[N/2];
  cout << sum << endl;
}


Measured memory_bytes: 1024
#include<bits/stdc++.h>
using namespace std;
#define all(v) (v).begin(),(v).end()
#define rall(v) (v).rbegin(),(v).rend()
#define pb push_back
#define eb emplace_back
#define fs first
#define sc second
using lint = long long;
using pii = pair<int,int>;
using vi = vector<int>;
using vvi = vector<vi>;
using vii = vector<pii>;

int n, a[200000];

lint solve(){
  lint ret = 0;
  int mx = a[0];
  for(int i=1;i<n;++i){
    ret += max(mx-a[i], 0);
    mx = max(mx, a[i]);
  }
  return ret;
}

int main(){
  scanf("%d",&n);
  for(int i=0;i<n;++i)
    scanf("%d",a+i);

  lint ans = solve();
  printf("%lld",ans);
}


Measured memory_bytes: 4592
x,n=map(int,input().split())
if n!=0:
    p=list(map(int,input().split()))
    k=[i for i in range(0,102)]
    kset=set(k)
    pset=set(p)
    ansbook=kset-pset
    ansbook=list(ansbook)
    ansbook=ansbook[::-1]
    ans1=100000
    ans=0
    for i in ansbook:
        if abs(i-x)<=ans1:
            ans1=abs(i-x)
            ans=i
    print(ans)
else:
    print(x)

Measured memory_bytes: 9212
#include<stdio.h>
#include<math.h>
#include<stdlib.h>

int main()
{
	int n,i;
	int *data;

	
	while(scanf("%d",&n)!=EOF)
	{
		double avt=0,dev2=0,deviation=0;
		if(n==0)break;
		
		data=(int *)malloc(sizeof(int)*n);
		
		for(i=0;i<n;i++)
		{
			scanf("%d",&data[i]);
			avt+=data[i];
		}
		
		avt/=n;
		
		for(i=0;i<n;i++)
		{
			dev2+=pow(data[i]-avt,2);
		}
		
		dev2/=n;
		
		printf("%lf\n",sqrt(dev2));
		free(data);
	}

	return 0;
}

Measured memory_bytes: 636
#include <cstdio>
#include <cmath>
#include <cstring>
#include <ctime>
#include <iostream>
#include <algorithm>
#include <set>
#include <vector>
#include <sstream>
#include <typeinfo>
#include <fstream>
#include <climits>
#include <functional>
#include <queue>
#include <tuple>

#define REP(i,n) for(int i = 0;i < n;i++)

using namespace std;
typedef long long ll;
const int INF = INT_MAX / 4;

const int max_n = 1e3;

// union-find
void init(int n, int par[]) {
  REP(i, n) {
    par[i] = i;
  }
}

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

void unite(int x, int y, int par[]) {
  x = find(x, par);
  y = find(y, par);
  par[x] = y;
}

bool same(int x, int y, int par[]) {
  return find(x, par) == find(y, par);
}


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

  int N;
  cin >> N;
  // point, town_id
  priority_queue<pair<int, int>> X, Y;
  // cost, town1, town2
  priority_queue<tuple<int, int, int>, vector<tuple<int, int, int>>, greater<tuple<int, int, int>>> q;

  int x, y;
  REP(i, N) {
    cin >> x >> y;
    X.push(make_pair(x, i));
    Y.push(make_pair(y, i));
  }

  // sort x cost
  pair<int, int> x1, x2;
  x1 = X.top();
  X.pop();
  while( ! X.empty() ) {
    x2 = X.top();
    X.pop();
    q.push(make_tuple(abs(x1.first - x2.first), x1.second, x2.second));
    x1 = x2;
  }
  // sort y
  pair<int, int> y1, y2;
  y1 = Y.top();
  Y.pop();
  while( ! Y.empty() ) {
    y2 = Y.top();
    Y.pop();
    q.push(make_tuple(abs(y1.first - y2.first), y1.second, y2.second));
    y1 = y2;
  }

  ll cost = 0;
  int uftree[N];
  init(N, uftree);
  tuple<int, int, int> t;
  int c, t1, t2;
  while (!q.empty()) {
    t = q.top();
    q.pop();
    c = get<0>(t); t1 = get<1>(t); t2 = get<2>(t);
    // cerr << c << " " << t1 << " " << t2 << "\n";
    if (!same(t1, t2, uftree)) {
      unite(t1, t2, uftree);
      cost += c;
    }
  }

  cout << cost << "\n";
  return 0;
}


Measured memory_bytes: 7016
n = int(input())
a = tuple(i for i in input().split())

els = {}

for num in a:
    if num in els.keys():
        els[num] += 1
    else:
        els[num] = 1

total = 0

for k, v in els.items():
    total += v if int(k) > v else (v - int(k)) if int(k) < v else 0

print(total)


Measured memory_bytes: 20984
import java.util.*;

public class Main {
    static Scanner scanner = new Scanner(System.in);

    public static void main(String[]$) {
        int a = scanner.nextInt();
        int b = scanner.nextInt();
        int c = scanner.nextInt();
        int k = scanner.nextInt();
        int max = Math.max(Math.max(a, b), c);
        System.out.println(a + b + c - max + (max << k));
    }
}

Measured memory_bytes: 21588
#include <bits/stdc++.h>
using namespace std;
int main() {
    int N,M,X; cin>>N>>M>>X;
    int maec=0,atoc=0;
    for(int i=0;i<M;i++){
        int tmp=0;
        cin>>tmp;
        if(tmp<X){
            maec++;
        }
        else{
            atoc++;
        }
    }
    int minimum=min(maec,atoc);
    cout<<minimum;
    return 0;
}

Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main() {
	int a[100] = { 0 }, b[100] = { 0 };
	int x;
	int n, m;
	int j = 0;
	int length;
	while (true) {
		cin >> x;
		if (x == 0){
			length = j;
			break;
		}
		for (int i = 0; i < x; i++) {
			cin >> n >> m;
			if (n > m) {
				a[j] += n + m;
			}
			else  if (n < m) {
				b[j] += n + m;
			}
			else {
				a[j] += n;
				b[j] += m;
			}
		}
		j++;
	}
	for (int i = 0; i < length; i++){
		cout << a[i] << " " << b[i] << endl;
	}
	char c;
	cin >> c;
}

Measured memory_bytes: 3088
import sys

sys.setrecursionlimit(10 ** 6)
input = sys.stdin.readline

def main():
    n = int(input())
    aa = [0] + list(map(int, input().split())) + [0]
    d = 0
    for a0, a1 in zip(aa, aa[1:]):
        d += abs(a0 - a1)
    for i in range(1, 1 + n):
        print(d - abs(aa[i - 1] - aa[i]) - abs(aa[i + 1] - aa[i]) + abs(aa[i - 1] - aa[i + 1]))

main()


Measured memory_bytes: 14048
#include<bits/stdc++.h>
using namespace std;
#define INF 1e15
#define MOD 1000000007
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
typedef long long ll;
typedef pair<int, int> P;
#define END system("PAUSE");return 0
int a, b, c;
signed main() {
	cin >> a >> b >> c;
	if (a % 2 & b % 2 && c % 2) {
		int d[3] = { a,b,c };
		sort(d, d + 3);
		cout << d[0] * d[1] << endl;
	}
	else puts("0");
	END;
}


Measured memory_bytes: 504
# coding: UTF-8
def pprint(numlist):
  print(" ".join(map(str,numlist)))
N = int(input())
A = list(map(int, input().split()))
pprint(A)
for i in range(1,N):
  j = i
  v = A[i]
  while A[j] < A[j-1] and j >= 1:
    A[j] = A[j-1]
    A[j-1] = v
    j -= 1
  pprint(A)
  



Measured memory_bytes: 5608
use proconio::{fastout, input};

#[fastout]
fn main() {
    input! {
        x: i128,
    }

    let mut y: i128 = 100;
    let mut t: i128 = 0;
    while y < x {
        t += 1;
        y = y + y / 100;
    }
    println!("{}", t);
}


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

#define FOR(i,a,b) for(int i=(a);i<(b);i++)
#define rep(i,n) FOR(i,0,n)
#define RFOR(i,a,b) for(int i=(a)-1;i>=(b);i--)
#define rrep(i,n) RFOR(i,n,0)

using namespace std;

typedef long long ll;
typedef unsigned long long ull;

ll k;
ll a[100003];

ll g(ll x){
	rep(i,k) x = x - x % a[i];
	return x;
}

ll bin_search1(ll lb, ll ub){
	while(ub - lb > 1){
		ll mid = (lb + ub) / 2;
		if(g(mid) >= 2) ub = mid; 
		else lb = mid;
	}
	return ub;
}

ll bin_search2(ll lb, ll ub){
	while(ub - lb > 1){
		ll mid = (lb + ub) / 2;
		if(g(mid) > 2) ub = mid;
		else lb = mid;
	}
	return ub;
}

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

	cin >> k;
	rep(i,k) cin >> a[i];

	ll l = bin_search1(-1,1e15);
	ll r = bin_search2(-1,1e15)-1;

	if(r < l) cout << -1 << endl;
	else cout << l << " " << r << endl;
}

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

int main(void) {
  int i, j=0, N, a[100], d=0, x=0, y=0, z;
  cin >> N;
  for(i = 0; i < N; i++){
  		scanf("%d", &a[i]);
  		}

  for(i = 0; i < N; i++){
  		for(int c = 0; c<N-1; c++){
  			if(a[c] < a[c+1]){
  				d = a[c];
  				a[c] = a[c+1];
  				a[c+1] = d;
  			}
  		}
  }
  //printf("%d\n%d\n", a[0], a[1]);

  for(i = 0; i < N; i++){
  	if(i % 2 == 0){
  		x += a[i];
  	}
  	else if(i % 2 != 0){
  		y += a[i];
  	}
  }

  z = x - y;
  printf("%d", z);


  return 0;
}

Measured memory_bytes: 256
mod = 10 ** 9 + 7
H, W, K = map(int, input().split())
K -= 1
dp = [0] * W
dp[0] = 1
ndp = [0] * W
for r in range(H):
    for i in range(1 << (W - 1)):
        if '11' in bin(i): continue
        perm = [i for i in range(W)]
        for j in range(W - 1):
            if (i >> j) & 1:
                perm[j], perm[j + 1] = perm[j + 1], perm[j]
        for j in range(W):
            next_line = perm[j]
            ndp[next_line] += dp[j]
            ndp[next_line] %= mod
    dp = ndp.copy()
    ndp = [0] * W
print(dp[K])


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

void print_vector(vector<ll> v)
{
  vector<ll>::iterator itr;
  for (itr = v.begin(); itr != v.end(); itr++)
  {
    cout << *itr << " ";
  }
  cout << endl;
}

int main()
{
  ll n;
  cin >> n;
  vector<ll> v(n);
  rep(n)
  {
    cin >> v[i];
  }
  ll cnt = 0;
  ll right = 0, left = 0, min;
  string dm;
  while(1)
  {
    for (left = 0; left < n; left++)
    {
      if(v[left]!=0){
        break;
      }
    }
    if(left==n) break;
    for (right = left ; right < n; right++)
    {
      if(v[right]!=0)
      {
        v[right]--;
      } else {
        break;
      }
    }
    cnt++;
  }
  cout << cnt << endl;
  return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
#define ff first
#define ss second
#define len(x) (int)(x.size())
#define all(x) x.begin(), x.end()
using namespace std;
using ll = long long;
using ii = pair<int, int>;

int main(){
	ios::sync_with_stdio(0);
	ll x = 100;
	ll value;
	cin >> value;
	int d = 0;
	while(x<value){
		++d;
		x += x/100LL;
	}
	cout << d << endl;
}


Measured memory_bytes: 3648
n = int(input())
a, b, c = 1, 1, 1
for i in range(n):
  a, b, c = a * 10, b * 9, c * 8
  a, b, c = a % (10**9+7), b % (10**9+7), c % (10**9+7)
print(0 if n==1 else (a - b*2 + c) % (10**9+7))

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

using namespace std;

int main() {
  int N;
  
  cin >> N;
  
  vector<int>A, B, C;
  
  for (int i = 0; i < N; i++) {
    int inA;
    
    cin >> inA;
    
    A.push_back(inA);
  }
  
  for (int i = 0; i < N; i++) {
    int inB;
    
    cin >> inB;
    
    B.push_back(inB);
  }
  
  for (int i = 0; i < N - 1; i++) {
    int inC;
    
    cin >> inC;
    
    C.push_back(inC);
  }
  
  int aft = 0, bef = -2147483648, sum = 0;
  for (int i = 0; i < N; i++) {
    aft = A[i] - 1;
    
    if (bef + 1 == aft) {
      sum += C[bef];
    }
    
    sum += B[aft];
    bef = aft;
  }
  
  cout << sum << endl;
  
  return 0;
}

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

#define int long long
#define fast_io(); ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
#define loop(i,a,b) for(int i=a;i<b;i++)
#define all(x) x.begin(),x.end()
#define us unordered_set
#define um unordered_map
#define ms multiset
#define mm multimap
#define pb push_back
#define pf push_front
#define ins insert
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define _max max_element
#define _min min_element
#define tc(T) int T; cin>>T; while(T--)
#define q(q) int q; cin>>q; while(q--)
#define pi 3.1415926535897932384626433832
const int pinf=((int)9e18);
const int ninf=((int)-9e18);
const int mod=1000000007;

using namespace std;

int32_t main()
{
    fast_io();

    //FILE *fptr1=freopen("in.txt","r",stdin);
    //FILE *fptr2=freopen("out.txt","w",stdout);

    int n;
    cin>>n;

    vector <int> adj[n+1];

    loop(i,2,n+1)
    {
        int x;
        cin>>x;
        adj[x].push_back(i);
    }

    loop(i,1,n+1)
    {
        cout<<adj[i].size()<< "\n";
    }


    return 0;
}


Measured memory_bytes: 14520
#include <iostream>
#include <cstring>
#include <queue>
using namespace std;
#define MAX_H 50
#define MAX_W 50
const int INF = 10000000;
typedef pair<int, int> P;
int sp();
void init();

char maze[MAX_H][MAX_W+1];
int d[MAX_H][MAX_W];
int dx[]={1, 0, -1, 0};
int dy[]={0, 1, 0, -1};
int h, w;
int w_cnt=0;

int main(){
  init();
  int n=sp();
  if (n!=-1) {
    printf("%d\n", w_cnt-(n+1));
  }else{
    printf("-1\n");
  }
  // test();
  return 0;
}

void init(){
  cin >> h >> w;
  for (int y = 0; y < h; y++) {
    for (int x = 0; x < w; x++) {
      cin >> maze[y][x];
      if(maze[y][x]=='.') w_cnt++;
      d[y][x]=INF;
    }
  }
}

int sp(){
  queue<P> que;
  que.push(P(0, 0));
  d[0][0]=0;
  while(que.size()){
    P p = que.front(); que.pop();
    if(p.first==w-1&&p.second==h-1){
      return d[p.second][p.first];
    }else{
      for (int i = 0; i < 4; i++) {
        int nx = p.first  + dx[i];
        int ny = p.second + dy[i];
        if (0 <= nx && nx < w && 0 <= ny && ny < h && maze[ny][nx] != '#' && d[ny][nx] == INF) {
          que.push(P(nx, ny));
          d[ny][nx]=d[p.second][p.first]+1;
        }
      }
    }
  }
  return -1;
}


Measured memory_bytes: 256
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <cmath>
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <stack>
#include <list>
#include <queue>
#include <deque>
#include <algorithm>
#include <numeric>
#include <utility>
#include <complex>
#include <functional>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> p;
const int INF = (1 << 28);
const int dx[4] = {0, 1, 0, -1}, dy[4] = {-1, 0, 1, 0};
const int Dx[8] = {0, 1, 1, 1, 0, -1, -1, -1}, Dy[8] = {-1, -1, 0, 1, 1, 1, 0, -1};
#define yes cout << "Yes" << endl
#define YES cout << "YES" << endl
#define no cout << "No" << endl
#define NO cout << "NO" << endl
#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define INF 2e9
#define ALL(v) v.begin(), v.end()
int n, m;
vector<int> a;
int change[9];
string dp[11000];
const string MINUSINF = "-";
void chmax(string &a, string b) //参照を渡して書き換える
{
    if (a == MINUSINF)
        a = b;
    else if (a.size() < b.size()) //sizeが大きいなら桁数が大きい
        a = b;
    else if (a.size() == b.size()) //辞書順が大きい
    {
        if (a < b)
            a = b;
    }
}
int main()
{
    cin.tie(0);
    ios::sync_with_stdio(false);
    cin >> n >> m;
    for (int i = 0; i < m; i++)
    {
        int temp;
        cin >> temp;
        a.push_back(temp);
    }
    int match[9] = {2, 5, 5, 4, 5, 6, 3, 7, 6};
    for (int i = 0; i < 11000; ++i)
        dp[i] = MINUSINF;
    dp[0] = "";
    for (int i = 0; i <= n; ++i) //全通り試す
    {
        if (dp[i] == MINUSINF)
            continue;
        for (int j = 0; j < a.size(); j++)
            chmax(dp[i + match[a[j] - 1]], dp[i] + (char)('0' + a[j]));
    }
    cout << dp[n] << endl;
}

Measured memory_bytes: 43776
//#include <iostream>
//#include <algorithm>
//#include <functional>
//#include <vector>
//#include <string>
//#include <map>
//#include <sstream>
//#include <cmath>
//#include <cstdio>
//#include <iomanip>
//#include <stdexcept>
//#include <utility>

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define ld long double
#define rep(i,h) for(int i = 0; i < h; ++i)
#define rep1(i,h) for(int i = 0; i <= h; ++i)
#define rep2(i,n,h) for(int i = n; i < h; ++i)
#define rep3(l,n,h) for(int l = n; l <= h; ++l)
typedef pair<int,int> int_pair;


int main() {
    int n;
    cin >> n;
    vector<string> data(n);
    rep(i,n) cin >> data.at(i);
    rep(i,n) {
        rep2(j,i+1,n) {
            if(data.at(i) == data.at(j)) {
                cout << "No" << endl;
                return 0;
            }
        }
    }
    rep(i,n-1) {
        int k = data.at(i).length();
        if(data.at(i)[k-1] != data.at(i+1)[0]) {
            cout << "No" << endl;
            return 0;
        }
    }
    cout << "Yes" << endl;
     return 0;
    }


Measured memory_bytes: 256
def triangle?(a, b, c)
    return false if a + b <= c
    true
end

sankaku = 0
eikaku = 0
chokaku = 0
donkaku = 0

loop do
    line = gets
    break  if line == "\n"

    a, b, c = line.split.map(&:to_i).sort
    break if !triangle?(a, b, c)

    sankaku += 1
    if a**2 + b**2 > c **2
        eikaku += 1
    elsif a**2 + b**2 == c **2
        chokaku += 1
    else
        donkaku += 1
    end
end

puts "#{sankaku} #{chokaku} #{eikaku} #{donkaku}"



Measured memory_bytes: 6876
#include <stdio.h>

int main(void) {
  int y = 700, i;
  char s[4];

  scanf("%s", s);

  for (i = 0; i < 3; i++) {
    if (s[i] == 'o') {
      y += 100;
    }
  }

  printf("%d\n", y);

  return 0;
}


Measured memory_bytes: 128
import java.util.Scanner;
public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            if(n == 0){
                break;
            }
            double[] s = new double[n];
            double total = 0;
            for(int i = 0; i < n;i++){
                s[i] = sc.nextDouble();
                total += s[i];
            }
            double m = total/n;
            double a = 0;
            for(int i = 0; i < n; i++){
                a += Math.pow(s[i]-m,2);
            }
            a /= n;
            System.out.printf("%.5f",Math.sqrt(a));
            System.out.println("");
        }
    }
}


Measured memory_bytes: 39212
mod = 10**9 + 7
n = int(input())
s = input()
dic = {}
for si in s:
  if si not in dic:
    dic[si] = 0
  dic[si] += 1
ans = 1
for k, v in dic.items():
  ans = ans * ((v+1) % mod) % mod
print((ans-1)%mod)

Measured memory_bytes: 67620
#include<cstdio>
int main(){
	char a,b;
	scanf("%c %c",&a,&b);
	if(a=='H' && b=='H') printf("H");
	if(a=='H' && b=='D') printf("D");
	if(a=='D' && b=='H') printf("D");
	if(a=='D' && b=='D') printf("H");
	return 0;
}


Measured memory_bytes: 128
#include <stdio.h>

int main(){
  int A, B;
  scanf ("%d %d", &A , &B );
  int a, b, c;
  int answer = 0;
  for (a = 1; a <= 9; a++){
   for (b = 0; b <= 9; b++){
    for (c = 0; c <= 9; c++){
     int x = 10001 * a + 1010 * b + 100 * c;
     if (x >= A && x <= B){
       answer++;
     }
    }
   }
  }
  printf ("%d\n",answer);
}








Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define RI register int
int read() {
	int q=0;char ch=' ';
	while(ch<'0'||ch>'9') ch=getchar();
	while(ch>='0'&&ch<='9') q=q*10+ch-'0',ch=getchar();
	return q;
}
const int N=100005;
int n,K,ans,tot,h[N],ne[N],to[N],dep[N],dis[N];
void add(int x,int y) {to[++tot]=y,ne[tot]=h[x],h[x]=tot;}
void dfs(int x,int las) {
	dis[x]=dep[x];
	for(RI i=h[x];i;i=ne[i]) {
		dep[to[i]]=dep[x]+1,dfs(to[i],x);
		dis[x]=max(dis[x],dis[to[i]]);
	}
	if(las!=1&&x!=1&&dis[x]-dep[x]==K-1) ++ans,dis[x]=0;
}
int main()
{
	int x;
	n=read(),K=read();
	for(RI i=1;i<=n;++i) {
		x=read();
		if(i==1&&x!=1) x=1,++ans;
		if(i!=1) add(x,i);
	}
	dfs(1,0),printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 6912
#include <iostream>
#include <string>
#include <vector>
#include <utility>
#include <map>
#include <tuple>

using namespace std;

int main(int, char**) {
    int n;
    vector<int> v;
    cin >> n;
    for (int i(0); i<n; ++i){
        int t;
        cin >> t;
        v.push_back(t-1);
    }
    int cnt(0);

    for (int i(0); i<n; ++i){
        int t = v[i];
        if (v[t] == i) ++cnt;
    }
    cout << cnt/2 << endl;
    return 0;
}



Measured memory_bytes: 892
a = int(input())
b = int(input())
c = int(input())
x = int(input())
# print(a, b, c, x)

ans = 0
for i_a in range(a+1):
    for i_b in range(b+1):
        for i_c in range(c+1):
            sum = 500 * i_a + 100 * i_b + 50 * i_c
            if sum == x:
                ans += 1

print(ans)


Measured memory_bytes: 3060
#include<stdio.h>
#include<string.h>
int main()
{
	int n,i;
	int dp[10000];
	while (scanf("%d",&n) != EOF) {
		memset(dp,0,sizeof(dp));
		dp[0]=1;
		for (i=1;i<=n;i++) {
			dp[i]=dp[i-1]+i;
		}
		printf("%d\n",dp[n]);
	}
	return 0;
}

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

int main()
{
    int n,m;
    cin>>n>>m;
    vector<int> from(50);
    vector<int> to(50);

    for(int i=0;i<m;i++){
        cin>>from.at(i)>>to.at(i);
    }
    for(int i=1;i<=n;i++){
        int count = 0;
        for(int j=0;j<m;j++){
            if(from.at(j) == i){
                count++;
            }
            if(to.at(j) == i){
                count++;
            }
        }
        cout<<count<<endl;
    }
}

Measured memory_bytes: 256