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


public class Main{
    public static void main(String[] args) {
        MyScanner sc = new MyScanner();
        out = new PrintWriter(new BufferedOutputStream(System.out));

        // Start writing your solution here. -------------------------------------
        //int t = sc.nextInt();
        int t = 1;
        while(t -- > 0)
        {
            int n = sc.nextInt();
            int k = sc.nextInt();
            long h[] = new long[n + 1];
            long dp[] = new long[n + 1];
            for(int i = 1; i <= n; i++) h[i] = sc.nextLong();
            Arrays.fill(dp, 20000000000l);
            dp[1] = 0;
            for(int i = 2; i <= n; i++)
                for(int j = 1; j <= k && j <= i; j++)
                    dp[i] = Math.min(dp[i], dp[i - j] + Math.abs(h[i] - h[i - j]));
            out.println(dp[n]);
        }
        //for(int i = 1; i <= n; i++) System.out.println(Arrays.toString(dp[i]));
        out.close();

        /*
        int n      = sc.nextInt();        // read input as integer
        long k     = sc.nextLong();       // read input as long
        double d   = sc.nextDouble();     // read input as double
        String str = sc.next();           // read input as String
        String s   = sc.nextLine();       // read whole line as String

        int result = 3*n;
        out.println(result);                    // print via PrintWriter
        */
        // Stop writing your solution here. -------------------------------------
        out.close();
    }
    //-----------PrintWriter for faster output---------------------------------
    public static PrintWriter out;
    //-----------MyScanner class for faster input----------
    public static class MyScanner {
        BufferedReader br;
        StringTokenizer st;

        public MyScanner() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        String next() {
            while (st == null || !st.hasMoreElements()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        int nextInt() {
            return Integer.parseInt(next());
        }
        long nextLong() {
            return Long.parseLong(next());
        }
        double nextDouble() {
            return Double.parseDouble(next());
        }
        String nextLine(){
            String str = "";
            try {
                str = br.readLine();
            } catch (IOException e) {
                e.printStackTrace();
            }
            return str;
        }
    }
    //--------------------------------------------------------
}

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

#define fi first
#define se second
#define repl(i,a,b) for(int i=(int)(a);i<(int)(b);i++)
#define repr(i,a,b) for(int i=(int)(a-1);i>=b;i--)
#define rep(i,n) repl(i,0,n)
#define each(itr,v) for(auto itr:v)
#define pb(s) push_back(s)
#define all(x) (x).begin(),(x).end()
#define dbg(x) cout << #x" = " << x << endl
#define maxch(x,y) x=max(x,y)
#define minch(x,y) x=min(x,y)
#define uni(x) x.erase(unique(all(x)),x.end())
#define exist(x,y) (find(all(x),y)!=x.end())
#define bcnt(x) bitset<32>(x).count()

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

#define INF INT_MAX/3

int main(){
    cin.sync_with_stdio(false);
    int x, a, b;
    cin >> x >> a >> b;

    if (b - a <= 0) cout << "delicious" << endl;
    else if (b - a <= x) cout << "safe" << endl;
    else cout << "dangerous" << endl;
    return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n,k;cin>>n>>k;
	int r,s,p;cin>>r>>s>>p;
	string t;cin>>t;
	vector<string> arr(k);
	for(int i=0;i<n;++i){
		arr[i%k].push_back(t[i]);
	}
	// r : Rock
	// s : Scissors
	// p : Paper

	int res = 0;
	for(int i=0;i<k;++i){
		int rr,ss,pp;
		rr=0;ss=0;pp=0;
		for(int j=0;j<arr[i].length();++j){
			char curr = arr[i][j];
			if(curr=='r'){
                int local = max(max(rr,ss),pp);
				pp = max(pp,max(rr,ss)+p);
                rr = local;
                ss = local;
			}
			if(curr=='s'){
               int local = max(max(rr,ss),pp);
				rr = max(rr,max(pp,ss)+r);
                pp = local;
                ss = local;
			}
			if(curr=='p'){
                int local = max(max(rr,ss),pp);
				ss = max(ss,max(pp,rr)+s);
                pp = local;
                rr = local;
			}
		}
		res += max(max(rr,ss),pp);
	}
	cout<<res<<endl;
	return 0;
}

Measured memory_bytes: 5120
#include <iostream>
#include <vector>

const int n = 200002;

int main(){
   int N, C;
   std::cin >> N >> C;
   int s[N], t[N], c[N];
   for(int i=0; i<N; ++i){
      std::cin >> s[i] >> t[i] >> c[i];
   }

   std::vector<int> sum(n,0);
   for(int i=1; i<=C; ++i){
      std::vector<int> x(n,0);
      for(int j=0; j<N; ++j){
	 if(c[j]==i){
	    x[s[j]*2-1]++;	    
	    x[t[j]*2]--;	    
	 }
      }
      for(int j=1; j<n; ++j)
	 x[j] += x[j-1];
      for(int j=0; j<n; ++j){
	 if(x[j]>0) sum[j]++;
      }
   }
   int ans = 0;
   for(int i=0; i<n; ++i)
      ans = std::max(sum[i], ans);

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


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

#define REP(i,x) for(int i{ 0 }; i < (int)(x); i++)

#define PB push_back
#define ALL(x) (x).begin(),(x).end()

using namespace std;

typedef pair<int, int> pii;


int main()
{
	int n;
	vector<pii> s;

	cin >> n;
	REP(i, n)
	{
		int a; cin >> a;
		s.PB(pii(a, i + 1));
	}

	sort(ALL(s));

	REP(i, n)
		cout << s[i].second << " ";
	cout << endl;

}


Measured memory_bytes: 1780
#include "bits/stdc++.h"
using namespace std;

int main() {
	long long int x;
	cin >> x;

	long long int ans = 0;
	
	ans = x / 11 * 2;
	if (x % 11 == 0);
	else if (x % 11 > 6) ans += 2;
	else ans += 1;

	cout << ans << endl;
}

Measured memory_bytes: 3620
#include <iostream>
#include <cstring>
#include <sstream>
#include <algorithm>

using namespace std;

const int I = 21;

int str2int(string str) {
  stringstream ss;
  int ans;

  ss<<str;
  ss>>ans;

  return ans;
}

string int2str(int num) {
  stringstream ss;

  ss<<num;

  return ss.str();
}

int checker(int ai[], int j) {
  int flag = -1;

  for(int i=0; i<j && flag==-1; i++) {
    if(ai[i] == ai[j]) {
      flag = i;
    }
  }

  return flag;
}

int main() {

  string tmp;
  int  l;

  cin>>tmp>>l;

  while(tmp!="0" || l!=0) {
    string as;
    int ai[I] = {0};
    as = tmp;
    while(as.length() < l) {
      as += "0";
    }

    ai[0] = str2int(as);

    int flag = -1;
    int j=1;
    while(flag == -1) {
      string big=as, small=as;
      sort(big.begin(), big.end(), greater<int>());
      sort(small.begin(), small.end());

      ai[j] = str2int(big)-str2int(small);
      as = int2str(ai[j]);
      while(as.length() < l) {
	as += "0";
      }
      
      /*
      for(int i=0; i<=j; i++) {
	cout<<"ai["<<i<<"] = "<<ai[i]<<endl;
      }
      cout<<endl;
      */
      
      flag = checker(ai, j);

      //cout<<"ai["<<j<<"] = "<<ai[j]<<endl;
      //cout<<as<<endl;

      j++;
    }

    cout<<flag<<" "<<ai[flag]<<" "<<j-flag-1<<endl; // ループの最後で j が増えているために-1が必要

    cin>>tmp>>l;
  }
  
}

Measured memory_bytes: 1252
import java.util.*;
import java.util.Scanner;

class Dice{
    private int one_;
    private int two_;
    private int three_;
    private int four_;
    private int five_;
    private int six_;
    
    Dice(int one, int two, int three, int four, int five, int six){
        one_ = one;
        two_ = two;
        three_ = three;
        four_ = four;
        five_ = five;
        six_ = six;
    }
    
    int swapFaces(String ways){
        char[] way = new char[ways.length()];
        
        for(int i = 0; i < ways.length(); i++){
            way[i] = ways.charAt(i);
            
            int tmp;
            switch(way[i]){
                case 'E':
                    tmp = one_;
                    one_ = four_;
                    four_ = six_;
                    six_ = three_;
                    three_ = tmp;
                    break;
                case 'N':
                    tmp = one_;
                    one_ = two_;
                    two_ = six_;
                    six_ = five_;
                    five_ = tmp;
                    break;
                case 'S':
                    tmp = one_;
                    one_ = five_;
                    five_ = six_;
                    six_ = two_;
                    two_ = tmp;
                    break;
                case 'W':
                    tmp = one_;
                    one_ = three_;
                    three_ = six_;
                    six_ = four_;
                    four_ = tmp;
                    break;
            }
        }
        return one_;
    }
    
}
public class Main {
    public static void main(String[] args) throws Exception {
        Scanner sc = new Scanner(System.in);
        Dice d = new Dice(sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt(), sc.nextInt());
        // d.one = sc.nextInt();
        // d.two = sc.nextInt();
        // d.three = sc.nextInt();
        // d.four = sc.nextInt();
        // d.five = sc.nextInt();
        // d.six = sc.nextInt();
        
        String way = sc.next();
        System.out.println(d.swapFaces(way));
    }
}



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

#define INF 1.1e9
#define LINF 1.1e18
#define FOR(i,a,b) for (int i=(a);i<(b);++i)
#define REP(i,n) FOR(i,0,n)
#define ALL(v) (v).begin(),(v).end()
#define pb push_back
#define pf push_front
#define fi first
#define se second
#define BIT(x,n) bitset<n>(x)
#define PI 3.14159265358979323846

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

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

int n;
ll a[100000],l;

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

	cin>>n>>l;
	REP(i,n) cin>>a[i];

	bool over_l=false;
	int idx=-1;
	REP(i,n) {
		if(a[i]>=l) {
			over_l=true;
			if(i==0) idx=i+1;
			else idx=i;
			break;
		}
	}
	if(!over_l) {
		REP(i,n-1) {
			if(a[i]+a[i+1]>=l) {
				over_l=true;
				idx=i;
				break;
			}
		}
	}
	if(!over_l) {
		cout<<"Impossible"<<endl;
		return 0;
	}
	cout<<"Possible"<<endl;
	REP(i,idx) cout<<i+1<<endl;
	for(int i=n-2;i>=idx;i--) cout<<i+1<<endl;

	return 0;
}


Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int,int> P;
typedef pair<int,P> P1;
typedef pair<P,P> P2;
#define pu push
#define pb push_back
#define mp make_pair
#define eps 1e-7
#define INF 1000000000
#define mod 1000000007
#define fi first
#define sc second
#define rep(i,x) for(int i=0;i<x;i++)
#define repn(i,x) for(int i=1;i<=x;i++)
#define SORT(x) sort(x.begin(),x.end())
#define ERASE(x) x.erase(unique(x.begin(),x.end()),x.end())
#define POSL(x,v) (lower_bound(x.begin(),x.end(),v)-x.begin())
#define POSU(x,v) (upper_bound(x.begin(),x.end(),v)-x.begin())
int main(){
	string s; cin>>s; int a=0;
	rep(i,s.size()) if(s[i]=='x') a++;
	if(a>=8) puts("NO"); else puts("YES");}

Measured memory_bytes: 256
#![allow(unused_mut, non_snake_case, unused_imports, dead_code)]

use std::iter;
use std::cmp::{max, min, Ordering};
use std::mem::swap;
use std::collections::{HashMap, BTreeMap, HashSet, BTreeSet, BinaryHeap, VecDeque};
use std::iter::FromIterator;

//　高速 EOF要
//macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();input_inner!{iter, $($r)*}};($($r:tt)*) => {let mut s = {use std::io::Read;let mut s = String::new();std::io::stdin().read_to_string(&mut s).unwrap();s};let mut iter = s.split_whitespace();input_inner!{iter, $($r)*}};}
//macro_rules! input_inner {($iter:expr) => {};($iter:expr, ) => {};($iter:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($iter, $t);input_inner!{$iter $($r)*}};}
//macro_rules! read_value {($iter:expr, ( $($t:tt),* )) => {( $(read_value!($iter, $t)),* )};($iter:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()};($iter:expr, chars) => {read_value!($iter, String).chars().collect::<Vec<char>>()};($iter:expr, usize1) => {read_value!($iter, usize) - 1};($iter:expr, $t:ty) => {$iter.next().unwrap().parse::<$t>().expect("Parse error")};}
// 低速 EOF不要
macro_rules! input {(source = $s:expr, $($r:tt)*) => {let mut iter = $s.split_whitespace();let mut next = || { iter.next().unwrap() };input_inner!{next, $($r)*}};($($r:tt)*) => {let stdin = std::io::stdin();let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));let mut next = move || -> String{bytes.by_ref().map(|r|r.unwrap() as char).skip_while(|c|c.is_whitespace()).take_while(|c|!c.is_whitespace()).collect()};input_inner!{next, $($r)*}};}
macro_rules! input_inner {($next:expr) => {};($next:expr, ) => {};($next:expr, $var:ident : $t:tt $($r:tt)*) => {let $var = read_value!($next, $t);input_inner!{$next $($r)*}};}
macro_rules! read_value {($next:expr, ( $($t:tt),* )) => {( $(read_value!($next, $t)),* )};($next:expr, [ $t:tt ; $len:expr ]) => {(0..$len).map(|_| read_value!($next, $t)).collect::<Vec<_>>()};($next:expr, chars) => {read_value!($next, String).chars().collect::<Vec<char>>()};($next:expr, usize1) => {read_value!($next, usize) - 1};($next:expr, $t:ty) => {$next().parse::<$t>().expect("Parse error")};}

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

/*
 <url:>
 問題文============================================================
 =================================================================
 解説=============================================================
 ================================================================
 */

fn main() {
    input!{N:i64,L:[i64;N]}
    let N:i64= N;
    let mut L:Vec<i64> = L;
    let Sum = L.iter().sum::<i64>();
    let max = *L.iter().max().unwrap();
    println!("{}",if Sum - max > max {"Yes"} else {"No"});
}

Measured memory_bytes: 4476
h, w = map(int, input().split())

s = [['.']*(w+2)]+ [list('.'+ input() + '.') for i in range(h)] + [['.']*(w+2)]
a = [[0]*w for i in range(h)]


for i in range(1, h+1):
  for j in range(1,w+1):
    if s[i][j] == '#':
      a[i-1][j-1] = '#'
    else:
      b = [s[i-1][j-1],s[i-1][j], s[i-1][j+1], s[i][j-1], s[i][j+1], s[i+1][j-1], s[i+1][j], s[i+1][j+1]]
      c = b.count('#')
           
      a[i-1][j-1] = c

for i in range(h):
  a[i] = [str(x) for x in a[i]]
  print(''.join(a[i]))

Measured memory_bytes: 9220
from itertools import permutations
N = int(input())
P = list(map(int,input().split()))
Q = list(map(int,input().split()))
A = sorted(P)
cnt = 0
for x in permutations(A,N):
    x = list(x)
    if x==P:
        a = cnt
    if x==Q:
        b = cnt
    cnt += 1
print(abs(a-b))

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

int main()
{
	int n, z, w;
	cin >> n >> z >> w;
	vector<int> a(n);
	rep(i, n) cin >> a[i];

	if(n==1){
		cout << abs(a[0]-w) << endl;
		return 0;
	}
	cout << max(abs(a[n-1]-w), abs(a[n-2]-a[n-1]) ) << endl;
	
}



Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
class Program
{
    public static bool f = false, t = true;
    static void Main(string[] args)
    {
        string a = Console.ReadLine();
        for(int i = 0; i < a.Length - 1; i++)
        {
            if (a[i] == 'A' && a[i + 1] == 'C') { Console.WriteLine("Yes");return; }
        }
        Console.WriteLine("No");
    }
    public static long gcd(long a, long b)
    {
        while (true)
        {
            if (a == 0) { return b; }
            if (b == 0) { return a; }
            if (a > b) { a -= b; }
            else { b -= a; }
        }
    }
    public static long lcm(long a, long b) { return a / gcd(a, b) * b; }
    public static bool IsPrime(long n)
    {
        if (n < 2) return false;
        if (n == 2) return true;
        for (long i = 2; i < n; i++) { if (n % i == 0) return false; }
        return true;
    }
}
public static class Read
{
    public static void outl(string n = "") { Console.WriteLine(n); return; }
    public static long Long() { return long.Parse(Console.ReadLine()); }
    public static long[] longs() { return Console.ReadLine().Split().Select(long.Parse).ToArray(); }
    public static int Int() { return int.Parse(Console.ReadLine()); }
    public static int[] ints() { return Console.ReadLine().Split().Select(int.Parse).ToArray(); }
    public static string Str() { return Console.ReadLine(); }
    public static string[] Strs() { return Console.ReadLine().Split(); }
}

Measured memory_bytes: 13140
import numpy as np
w, h = map(int, input().split())
ps = [int(input()) for _ in range(w)]
qs = np.sort([int(input()) for _ in range(h)])
sqs = np.cumsum(qs)
bound = np.searchsorted(qs, ps)

s = sum(qs) + sum(ps)

for p, b in zip(ps, bound):
    if b > 0:
        s += sqs[b-1] + p*(h-b)
    else:
        s += p*h

print(s)

Measured memory_bytes: 23540
#include <bits/stdc++.h>
typedef long long ll;
#define pb push_back
#define mii map <int, int>
#define mll map <ll, ll>
#define pii pair <int, int>
#define pll pair <ll, ll>
#define vi vector <int>
#define vd vector <double>
#define vll vector <ll>
#define fi first
#define se second
#define si set <int>
#define sll set <ll>
#define spii set <pii>
#define vs vector <string>
#define vpii vector <pair <int,int> >
#define vpll vector <pair <long long,long long> >
#define vvi vector <vector <int> >
#define vvpii vector <vector <pii > >
#define forn(i, n) for (int i = 0; i < (n); i++)
#define rep(i, n) for (int i = 0; i < (n); i++)
#define for1(i, n) for (int i = 1; i < (n); i++)
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(),(x).rend()


using namespace std;
const ll INFLL = 1e18;
const int MAXN = 1e6+100;
const ll INF = 1e9;
const ll mod1=1e9+7;
const ll mod2=2e9+11;

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    #ifdef LOCAL
    freopen("a.in","r",stdin);
    #endif
    ll a,b,c;
    cin>>a>>b>>c;
    map <ll,ll> m;
    m[a]++;
    m[b]++;
    m[c]++;
    if (m.size()==2)
        cout<<"Yes";
    else
        cout<<"No";




}

Measured memory_bytes: 256
s = gets.strip

words = ['dream', 'dreamer', 'erase', 'eraser']

until s.empty? do
    reduced = false
    words.map do |w|
        if s[-w.size, w.size] == w
            s = s[0..-w.size - 1]
            reduced = true
            break
        end
    end

    unless reduced
        puts 'NO'
        exit 0
    end
end

puts 'YES'

Measured memory_bytes: 56152
#include<stdio.h>
#include<string.h>
int main(void)
{
	char s[4];
	
	scanf("%s",s);
	
	if(strchr(s,'a')!=NULL && strchr(s,'b')!=NULL && strchr(s,'c')!=NULL) printf("Yes");
	else printf("No");
	
	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);
        int n = sc.nextInt();
        int k = sc.nextInt();
        long[] a = new long[n];
        for(int i=0; i<n; i++){
            a[i] = sc.nextLong();
        }

        long ans1 = 0;
        long ans2 = 0;

        long max = -1000000000000000L;
        long max2 = -1000000000000000L;
        long min = 1000000000000000L;
        int posmax = 0;
        int posmin = 0;
        long l1 = 0;
        long s1 = 0;
        for(int j=0; j<k; j++){
            if(a[j] > 0) l1 += a[j];
            if(a[j] < 0)  s1 += a[j];
        }
        if(s1 > max){
            max = s1;
            posmax = 0;
        }
        if( l1 < min){
            min = l1;
            posmin = 0;
        }
        for(int i=1; i<n+1-k; i++){
            long l = l1;
            if(a[i-1] > 0) l -= a[i-1];
            if(a[i-1+k] > 0) l += a[i-1+k];
            long s = s1;
            if(a[i-1]< 0) s -= a[i-1];
            if(a[i-1+k] < 0) s += a[i-1+k];
            if(s > max){
                max = s;
                posmax = i;
            }
            if( l < min){
                min = l;
                posmin = i;
            }
            l1 = l;
            s1 = s;
        }

        for(int i=0; i<n; i++){
            if((i < posmin || i > posmin + k-1) && a[i] > 0){
                ans1 += a[i];
            }
        }

        ans2 += max;
        for(int i=0; i<n; i++){
            if(a[i] > 0){
                ans2 += a[i];
            }
        }

        System.out.println(Long.max(ans1, ans2));
    }
}

Measured memory_bytes: 60912
#include <bits/stdc++.h>
#define rep(i,n) for(int i=0; i<(n); i++)
#define reps(i,s,n) for(int i=(s); i<(n); i++)
#define all(v) v.begin(),v.end()
#define outve(v) for(auto i : v) cout << i << " ";cout << endl
#define outmat(v) for(auto i : v){for(auto j : i) cout << j << " ";cout << endl;}
#define in(n,v) for(int i=0; i<(n); i++){cin >> v[i];}
#define out(n) cout << (n) << endl
#define fi first
#define se second
#define pb push_back
#define si(v) int(v.size())
#define len(v) int(v.length())
#define lob(v,n) lower_bound(all(v),n)
#define lobi(v,n) lower_bound(all(v),n) - v.begin()
#define upb(v,n) upper_bound(all(v),n)
#define upbi(v,n) upper_bound(all(v),n) - v.begin()
#define mod 1000000007
#define infi 1900000000
#define infl 1100000000000000000
#define cyes cout << "Yes" << endl
#define cno cout << "No" << endl
#define csp << " " <<
#define outset(n) cout << fixed << setprecision(n);
using namespace std;
using ll = long long;
using ld = long double;
using vi = vector<int>;
using vvi = vector<vector<int>>;
using vs = vector<string>;
using vc = vector<char>;
using vd = vector<double>;
using vvd = vector<vector<double>>;
using vl = vector<ll>;
using vvl = vector<vector<ll>>;
using pii = pair<int,int>;
using pll = pair<ll,ll>;
using vvp = vector<vector<pair<int,int>>>;
template<typename T> using ve = vector<T>;
template<typename T> using pq2 = priority_queue<T>;
template<typename T> using pq1 = priority_queue<T,vector<T>,greater<T>>;
template<typename T> bool chmax(T &a, T b) {if(a < b) {a = b;return 1;}return 0;}
template<typename T> bool chmin(T &a, T b) {if(a > b) {a = b;return 1;}return 0;}




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

    double a,b,x;
    cin >> a >> b >> x;

    outset(10);
    double dd = a*a*b/2;
    
    if(dd == x){
        cout << atan(b/a)*180/M_PI << endl;
    }else if(dd < x){
        
        double c = 2/a*(b-x/a/a);

        c = atan(c);
        
        cout << c*180/M_PI << endl;
    }else{
        double c = 2*x/a/b;
        cout << atan(b/c)*180/M_PI << endl;
        
    }
    
    
    
    

    return 0;
}


Measured memory_bytes: 4068
#include <bits/stdc++.h>
#define For(i, a, b) for(int (i)=(int)(a); (i)<(int)(b); ++(i))
#define rFor(i, a, b) for(int (i)=(int)(a)-1; (i)>=(int)(b); --(i))
#define rep(i, n) For((i), 0, (n))
#define rrep(i, n) rFor((i), (n), 0)
#define fi first
#define se second
using namespace std;
typedef long long lint;
typedef unsigned long long ulint;
typedef pair<int, int> pii;
typedef pair<lint, lint> pll;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return true;} return false;}
template<class T> bool chmin(T &a, const T &b){if(a>b){a=b; return true;} return false;}
template<class T> T div_floor(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>=0 ? a/b : (a+1)/b-1;
}
template<class T> T div_ceil(T a, T b){
    if(b < 0) a *= -1, b *= -1;
    return a>0 ? (a-1)/b+1 : a/b;
}

constexpr lint mod = 1e9+7;
constexpr lint INF = mod * mod;
constexpr int MAX = 200010;

typedef struct UnionFindTree{
    vector<int> par, edge;
    vector<array<int, 2>> cnt;

    UnionFindTree(int n){
        par.resize(n, -1);
        cnt.resize(n);
        edge.resize(n, 0);
        rep(i, n){
            if(i < n/2) cnt[i][0] = 1, cnt[i][1] = 0;
            else cnt[i][0] = 0, cnt[i][1] = 1;
        }
    }

    bool is_root(int x){
        return par[x]<0;
    }

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

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

    bool unite(int x, int y){
        x = find(x);
        y = find(y);
        ++edge[x];
        if(x == y) return false;
        if(size(x) < size(y)) swap(x, y);
        par[x] += par[y];
        par[y] = x;
        rep(i, 2) cnt[x][i] += cnt[y][i];
        edge[x] += edge[y];
        return true;
    }

    bool same(int x, int y){
        return find(x) == find(y);
    }
}UF;

int main(){
    int n;
    scanf("%d", &n);
    UF uf(MAX);
    rep(i, n){
        int x, y;
        scanf("%d%d", &x, &y);
        uf.unite(x, y+MAX/2);
    }
    lint ans = 0;
    rep(i, MAX)if(uf.is_root(i)){
        ans += (lint)uf.cnt[i][0] * uf.cnt[i][1] - uf.edge[i];
    }
    printf("%lld\n", ans);
}

Measured memory_bytes: 3328
#include<stdio.h>
int a[400000];
int visit[400000];
int cur,num,i,record,n;
long long k,t,cycle;
int main(){
	scanf("%d %lld",&n,&k);
	for (i=1;i<=n;i++){
		scanf("%d",&a[i]);
	}
	for (i=1;i<=n;i++) visit[i]=0;
	cur=1;num=0;
	while (1==1){
		num++;
		cur=a[cur];
		if (visit[cur]!=0)
		{record=cur;
		 break;
		}else{
			visit[cur]=num;
		}
	}
	cycle=num-visit[record];
	if (k<=visit[record]){
		cur=1;
		for (i=1;i<=k;i++)
		  cur=a[cur];
		printf("%d",cur);
	}else{
		t=(k-(visit[record]-1))%cycle;
		if (t==0) t=cycle;
		cur=1;
		for (i=1;i<=visit[record]-1+t;i++)
		  cur=a[cur];
		printf("%d",cur);
	}
} 

Measured memory_bytes: 3300
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using p = pair<int, int>;
#define INF 1000000000
#define rep(i, n) for (ll i = 0; i < (ll)(n); i++)
#define repX(i, n ,x) for (int i = x; i < (int)(n); i++)
#define repM(i, n) for (int i = n; i > 0; i--)

int main() {
    ll A,B,K;
    cin >> A >> B >> K;
    if(A>0){
        if(K>=A){
            K -= A;
            A = 0;
        }else{
            A -= K;
            K = 0;
        }
    }
    if(B>0){
        if(K>=B){
            K -= B;
            B = 0;
        }else{
            B -= K;
            K = 0;
        }
    }
    cout << A << " " << B << endl;

    return 0;
}

Measured memory_bytes: 256
# -*- coding:utf-8 -*-
N=int(input())
a=list(map(int,input().split()))
ans=0
i=0
i2=0
while i<N:
    if i2==a[i]-1:
        i=i+1
        i2=i2+1
    else:
        i=i+1
        ans=ans+1
if ans==N:
    print(-1)
else:
    print(ans) 

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

//1以上N以下の整数のうち先頭がa,末尾がbのものをカウントして二次元配列に格納
void count(vector<vector<int>> &V, int N)
{
    for (int i = 1; i <= N; i++)
    {
        int a = i % 10, b = i;

        while (b > 9)
        {
            b /= 10;
        }

        V.at(a).at(b)++;
        //cout << a << " " << b << " " << V.at(a).at(b) << endl;
    }
}

int main()
{
    int N, ans = 0;
    cin >> N;

    vector<vector<int>> V(10, vector<int>(10, 0));

    count(V, N);

    for (int i = 1; i <= 9; i++)
    {
        for (int j = 1; j <= 9; j++)
        {
            ans += V.at(i).at(j) * V.at(j).at(i);
        }
    }

    cout << ans << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<set>
#include<map>
#include<utility>
#include<algorithm>
#include<cmath>
#include<climits>
using namespace std;

#define MOD 1000000007;

int main(){
	int n, k;
	cin >> n >> k;
	int num=k;
	for(int i=1; i<n; i++)
		num *= k-1;
	cout << num << endl;
	return 0;
}

Measured memory_bytes: 256
#include <iostream>
#define N 25
#define M 25
using namespace std;

int main()
{
    int n, m, c, a[N][M], b[M];
    int count = 0;

    cin >> n >> m >> c;

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

    for (int i = 0; i < n; i++)
    {
        int value = 0;
        for (int j = 0; j < m; j++)
        {
            cin >> a[i][j];
            value += a[i][j] * b[j];
        }
        if (value + c > 0)
        {
            count++;
        }
    }

    cout << count << endl;
    return 0;
}

Measured memory_bytes: 256
n=str(input())
x=0
if n[0]=='1':
	x=x+900
elif n[0]=='9':
	x=x+100

if n[1]=='1':
	x=x+90
elif n[1]=='9':
	x=x+10

if n[2]=='1':
	x=x+9
elif n[2]=='9':
	x=x+1
print(x)

Measured memory_bytes: 3064
#include <iostream>
#include <stdio.h>

#include <vector>
#include <cctype>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>

using namespace std;

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

	int number = n % 500;

	if (number > a) {
		cout << "No" << endl;

	}
	else {
		cout << "Yes" << endl;
	}

	return 0;
}


Measured memory_bytes: 3572
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int num;
	scanf("%d",&num);
	switch((num-200)/200)
	{
		case 1:printf("8");break;
		case 2:printf("7");break;
		case 3:printf("6");break;
		case 4:printf("5");break;
		case 5:printf("4");break;
		case 6:printf("3");break;
		case 7:printf("2");break;
		case 8:printf("1");break;
	}
}

Measured memory_bytes: 3760
#include<bits/stdc++.h>
using namespace std;
const long long llINF = 9223372036854775807;
const int INF = 2147483647;
const int maxn = 2e3 + 7;
const int maxm = 1e5 + 7;
const int mod = 998244353;

int n;
pair<int,int> a[maxn];
long long dp[maxn][maxn]; //1: 往左，2：往右
long long ans;

void debug()
{
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			cout<<dp[i][j]<<" ";
		}
		cout<<endl;
	}
}

int main(int argc, char const *argv[])
{
	scanf("%d",&n);
	for(int i=1;i<=n;i++)
	{
		scanf("%d",&a[i].first);
		a[i].second=i;
	}
	sort(a+1,a+1+n);
	reverse(a+1,a+1+n);
	
	for(int i=0;i<=n;i++)
	{
		for(int j=0;j<=n;j++)
		{
			int num=i+j+1;
			if(num>n)
				break;
			dp[i+1][j]=max(dp[i+1][j],dp[i][j]+1ll*a[num].first*abs(a[num].second-(i+1)));
			dp[i][j+1]=max(dp[i][j+1],dp[i][j]+1ll*a[num].first*abs(a[num].second-(n-j)));
		}
	}
	
	for(int i=0;i<=n;i++)
		ans=max(ans,dp[i][n-i]);
	printf("%lld\n",ans);
	//debug();
  	return 0;
}


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

using namespace std;

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

    vector< int > A(N);
    for (int i = 0; i < N; i++) {
        cin >> A[i];
    }

    while (true) {
        auto min_itr = min_element(A.begin(), A.end());
        bool flag = true;
        for (auto itr = A.end() - 1; itr >= A.begin(); itr--) {
            if (itr != min_itr && *itr != 0) {
                if (*itr % *min_itr == 0) {
                    A.erase(itr);
                } else {
                    *itr = *itr % *min_itr;
                }
                flag = false;
            }
        }

        if (flag) {
            cout << *min_itr << endl;
            break;
        }
    }
}

Measured memory_bytes: 640
def modpow(a,n,mod):
    res = 1
    while(n>0):
        if n&1:
            res = res*a%mod
        a = a*a%mod
        n >>= 1
    return res



n = int(input())

mod = 1000000000 + 7

if n == 1:
    print(0)
else:
    print((modpow(10,n,mod)+modpow(8,n,mod)-2*modpow(9,n,mod))%mod)

Measured memory_bytes: 61748
import sys

def main():
    N, K = map(int, raw_input().split(' '))
    A = map(int, raw_input().split(' '))

    position_1 = A.index(1)
    if position_1 <= K or N-K <= position_1:
        if (N-K) % (K-1) > 0:
            print 1 + (N-K)/(K-1) + 1
            return
        else:
            print 1 + (N-K)/(K-1)
            return

    minimum = sys.maxint
    for i in range(K):
        total = 1
        smaller_A = A[:position_1-K+1]
        bigger_A = A[position_1+i:]

        if len(smaller_A) % (K-1) == 0:
            total += len(smaller_A) / (K-1)
        else:
            total += (len(smaller_A) / (K-1)) + 1
        
        if len(bigger_A) % (K-1) == 0:
            total += len(bigger_A) / (K-1)
        else:
            total += (len(bigger_A) / (K-1)) + 1

        if total < minimum:
            minimum = total

    print total

main()


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

public class Katana
{
    public long a { get; set; }
    public long b { get; set; }
}

public class Hello
{
    public static void Main()
    {
        var katanas = new List<Katana>();
        string[] line = Console.ReadLine().Trim().Split(' ');
        var n = int.Parse(line[0]);
        var h = long.Parse(line[1]);
        for (int i = 0; i < n; i++)
        {
            string[] line2 = Console.ReadLine().Trim().Split(' ');
            var a = long.Parse(line2[0]);
            var b = long.Parse(line2[1]);
            katanas.Add(new Katana { a = a, b = b });
        }
        var amax = katanas.Max(x => x.a);
        var count = 1;
        foreach (var x in katanas.Where(y => y.b > amax).OrderByDescending(y =>y.b))
        {
            h -= x.b;
            if (h <= 0) { Console.WriteLine(count); goto end; }
            count++;
        }
        Console.WriteLine(count - 1 + (h + amax - 1) / amax);
        end:;
    }
}


Measured memory_bytes: 25288
#include <bits/stdc++.h>
#define mp make_pair
#define pb push_back
using namespace std;
using ll = long long int;
template<typename T>
ostream& operator+(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out<<x<<" ";
    }
    out<<"\n";
    return out;
}
template<typename T>
ostream& operator*(ostream& out, const vector<T> &vec){
    for(const auto &x : vec){
        out+x;
    }
    return out;
}
template<typename T>
istream& operator>>(istream& in, vector<T> &vec){
    for(auto &x : vec){
        in>>x;
    }
    return in;
}
void solve(){
    int n,m;
    cin>>n>>m;
    vector<vector<int>> adj(n);
    for(int i=0;i<m;i++){
        int u,v;
        cin>>u>>v;
        --u;--v;
        adj[u].pb(v);
        adj[v].pb(u);
    }
    int ans = -1;
    vector<bool> vis(n);
    function<void(int)> dfs = [&](int u){
        vis[u] = 1;
        for(const auto &v : adj[u]) if(!vis[v]) dfs(v);
    };
    for(int i=0;i<n;i++){
        if(!vis[i]) dfs(i), ++ans;
    }
    cout<<ans<<"\n";
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    solve();
}

Measured memory_bytes: 10064
/***********************************************
 *                   _ooOoo_                   *
 *                  o8888888o                  *
 *                  88" . "88                  *
 *                  (| -_- |)                  *
 *                  O\  =  /O                  *
 *               ____/`---'\____               *
 *             .'  \\|     |//  `.             *
 *            /  \\|||  :  |||//  \            *
 *           /  _||||| -:- |||||-  \           *
 *           |   | \\\  -   * |    |           *
 *           | \_|  ''\---/''  |   |           *
 *           \  .-\__  `-`  ___/-. /           *
 *         ___`. .'  /--.--\  `. . __          *
 *      ."" '<  `.___\_<|>_/___.'  >'"".       *
 *     | | :  `- \`.;`\ _ /`;.`/ - ` : | |     *
 *     \  \ `-.   \_ __\ /__ _/   .-` /  /     *
 *======`-.____`-.___\_____/___.-`____.-'======*
 *                   `=---='                   *
 *^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^

             佛祖保佑       永无BUG

   本程序已经经过开光处理，绝无可能再产生bug
 **********************************************/
#include<algorithm>
#include <iostream>
#include  <cstdlib>
#include  <cstring>
#include   <string>
#include   <vector>
#include   <cstdio>
#include    <queue>
#include    <stack>
#include    <ctime>
#include    <cmath>
#include      <map>
#include      <set>
#define ll long long
#define inf 0x3f3f3f3f
#define pii pair<int,int>
#define INF 0x3f3f3f3f3f3f3f3f
#define mkp(a,b) make_pair(a,b)
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define db1(x) cout<<#x<<"="<<(x)<<endl
#define db2(x,y) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<endl
#define db3(x,y,z) cout<<#x<<"="<<(x)<<", "<<#y<<"="<<(y)<<", "<<#z<<"="<<(z)<<endl
#define getchar()(p1==p2&&(p2=(p1=buf)+fread(buf,1,1<<22,stdin),p1==p2)?EOF:*p1++)
using namespace std;
char buf[(1<<22)],*p1=buf,*p2=buf;
inline ll read(){
    char c=getchar();ll x=0,f=1;
    while(c<'0'||c>'9'){if(c=='-')f=-1;c=getchar();}
    while(c>='0'&&c<='9')x=x*10+c-'0',c=getchar();
    return x*f;
}
const int maxn=4005;
int main(){
    #ifdef DanDan
    freopen("in.txt","r",stdin);
    //freopen("in.txt","w",stdout);
    clock_t start=clock();
    #endif //DanDan
    int n;cin>>n;
    printf("%.10f\n",1.0*((n+1)/2)/n);

    #ifdef DanDan
    clockid_t end=clock();
    double endtime=(double)(end-start)/CLOCKS_PER_SEC;
    printf("\n\n\n\n\n");
    cout<<"Total time:"<<endtime<<"s"<<endl;        //s为单位
    cout<<"Total time:"<<endtime*1000<<"ms"<<endl;    //ms为单位
    #endif //DanDan
    return 0;
}


// ━━━━━━神兽出没━━━━━━
//      ┏┓       ┏┓
//     ┏┛┻━━━━━━━┛┻┓
//     ┃           ┃
//     ┃     ━     ┃
//     ????━????   ┃
//     ┃           ┃
//     ┃    ┻      ┃
//     ┃           ┃
//     ┗━┓       ┏━┛
//       ┃       ┃
//       ┃       ┃
//       ┃       ┗━━━┓
//       ┃           ┣┓
//       ┃           ┏┛
//       ┗┓┓┏━━━━━┳┓┏┛
//        ┃┫┫     ┃┫┫
//        ┗┻┛     ┗┻┛
//
// ━━━━━━感觉萌萌哒━━━━━━



Measured memory_bytes: 256
import math
 
def calc(x, y):
    s = math.fabs((x[1]-x[0])*(y[2]-y[0]) - (x[2]-x[0])*(y[1]-y[0]))/2
    a = ((x[2]-x[1])**2 + (y[2]-y[1])**2)**0.5
    b = ((x[0]-x[2])**2 + (y[0]-y[2])**2)**0.5
    c = ((x[1]-x[0])**2 + (y[1]-y[0])**2)**0.5
    r = a*b*c/(4*s)
 
    a = [2*(x[1]-x[0]), 2*(x[2]-x[0])]
    b = [2*(y[1]-y[0]), 2*(y[2]-y[0])]
    c = [x[0]**2 - x[1]**2 + y[0]**2 -y[1]**2, x[0]**2 - x[2]**2 + y[0]**2 -y[2]**2]
    x = (b[0]*c[1]-b[1]*c[0])/(a[0]*b[1]-a[1]*b[0])
    y = (c[0]*a[1]-c[1]*a[0])/(a[0]*b[1]-a[1]*b[0])
 
    return [x,y,r]
 
for i in range(int(input())):
    list = [float(l) for l in raw_input().split()]
    x,y = [list[0::2],list[1::2]]
 
    ans = calc(x,y)
 
    print "%.3f %.3f %.3f" % (ans[0],ans[1],ans[2])

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

#define rep(i,n) for(int i=0;i<n;i++)
#define REP(i,s,n) for(int i=(s);i<=(n);i++)
#define repr(i,n) for(int i=n-1;i>=0;i--)
#define REPR(i,s,n) for(int i=(s);i>=(n);i--)
#define all(a) (a).begin(),(a).end()
#define rall(a) (a).rbegin(),(a).rend()
#define Eunique(v) v.erase(unique(all(v)),v.end())
#define Eback(s) s.erase(s.end()-1,s.end())
#define rev(v) reverse(all(v))
#define minvec(v) *min_element(all(v))
#define maxvec(v) *max_element(all(v))
#define sumvec(v) accumulate(all(v),0LL)
#define mapmin(v) v.rbegin()->first
#define mapmax(v) v.begin()->first
#define pb push_back
#define pf push_front
#define m_p make_pair
#define DOUBLE fixed << setprecision(15)
#define OK cerr<<"OK\n"
#define OK1 cerr<<"OK1\n"
#define OK2 cerr<<"OK2\n"
#define SIZE(s) (int)s.size()
//#define INF ((1LL<<62)-(1LL<<31))
#define INF pow(10,18)
#define zero(x,n) setw(x) << setfill('0') << n

typedef long long ll;

typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<long long> vll;
typedef vector<vll> vvll;
typedef vector<double> vd;
typedef vector<vd> vvd;
typedef vector<char> vc;
typedef vector<vc> vvc;
typedef vector<bool> vb;
typedef vector<vb> vvb;
typedef vector<string> vs;

typedef pair<ll,ll> pll;
typedef pair<int,int> pii;
typedef vector<pair<int,int>> vpii;
typedef vector<pair<ll,ll>> vpll;

const double pi = acos(-1.0);
const int mod=1000000007;
const int mod2=998244353;

template<class A, class B>
ostream& operator<<(ostream& ost, const pair<A, B>&p) {
	ost << "{" << p.first << ", " << p.second << "} ";
	return ost;
}

template<class T>
ostream& operator<<(ostream& ost, const vector<T>&v) {
	ost << "{";
	for (int i = 0; i<(int)v.size(); i++) {
		if (i)ost << " ";
		ost << v[i];
	}
	ost << "} \n";
	return ost;
}

template<class A, class B>
ostream& operator<<(ostream& ost, const map<A, B>&v) {
	ost << "{";
	for (auto p:v) {
		ost << "{" << p.first << ", " << p.second << "} ";
	}
	ost << "} ";
	return ost;
}

template<class T>
inline bool chmax(T& a, T b){if(a<b){a=b;return true;} return false;}

template<class T>
inline bool chmin(T& a, T b){if(a>b){a=b;return true;} return false;}

void YES(bool b) {cout << ((b)?"YES\n":"NO\n");}
void Yes(bool b) {cout << ((b)?"Yes\n":"No\n");}
void yes(bool b) {cout << ((b)?"yes\n":"no\n");}
void Yay(bool b) {cout << ((b)?"Yay!\n":":(\n");}

ll powmod(ll a,ll b){ll c=1; while(b>0){ if(b&1){ c=a*c%mod; } a=a*a%mod; b>>=1; } return c;}
ll gcd(ll x, ll y) {return __gcd(x,y);}
ll lcm(ll x, ll y) {return x/__gcd(x,y)*y;}

int main()
{
	ll a,b,q;
	cin >> a >> b >> q;
	vll s(a+2),t(b+2),x(q);
	s[0]=t[0]=-INF;
	s[a+1]=t[b+1]=INF;
	rep(i,a) cin >> s[i+1];
	rep(i,b) cin >> t[i+1];
	rep(i,q) cin >> x[i];
	rep(i,q){
		ll ans=INF;
		vll ss(2),tt(2);
		ss[0]=s[lower_bound(all(s),x[i])-s.begin()-1];
		ss[1]=s[lower_bound(all(s),x[i])-s.begin()];
		tt[0]=t[lower_bound(all(t),x[i])-t.begin()-1];
		tt[1]=t[lower_bound(all(t),x[i])-t.begin()];
		for(auto&& e:ss){
			for(auto&& f:tt) chmin(ans,abs(x[i]-e)+abs(e-f));
		}
		for(auto&& e:tt){
			for(auto&& f:ss) chmin(ans,abs(x[i]-e)+abs(e-f));
		}
		cout << ans << endl;
	}
	return 0;
}


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

int main(void){
    string s;
    cin >> s;
    ll n = s.length();
    vector<ll>children(n);
    int cnt = 0;
    for(int i=0;i<n-1;i++){
        if(s[i]=='R'){
            cnt++;
            if(s[i+1]=='L'){
                cnt--;
                children[i]+=cnt/2 + 1;
                children[i+1] += (cnt+1)/2; 
                cnt = 0;
            }
        }
    }
    cnt = 0;
    for(int i=n-1;0<i;i--){
        if(s[i]=='L'){
            cnt++;
            if(s[i-1]=='R'){
                cnt--;
                children[i]+=cnt/2 + 1;
                children[i-1] += (cnt+1)/2; 
                cnt = 0;
            }
        }
    }

    for(int i=0;i<n;i++){
        cout << children[i];
        if(i!=n-1){
            cout << ' ';
        }
    }
    cout << endl;
    
    return 0;
}

Measured memory_bytes: 1408
#include<iostream>
#include<cstdio>
#include<cstring>
using namespace std;
char s[555555];
int n,all,dp[555555],nxt[555555];
int main()
{
	scanf("%d",&n);
	scanf("%s",s);
	for (int i=n-1;i>=0;i--)
	{
		if (s[i]=='1') all++;
		nxt[i]=n;
		if (s[i]=='0') nxt[i]=i;
		else if (i<n-1) nxt[i]=nxt[i+1];
	}
	for (int i=0;i<n;i++) dp[i]=1e9;
	for (int i=0;i<n;i++)
	{
		if (!i)
		{
			if (s[i]=='0') dp[i]=0;
			else dp[i]=1;
		}
		else
		{
			if (s[i]=='0') dp[i]=min(dp[i-1],dp[i]);
			else dp[i]=min(dp[i-1]+1,dp[i]);
		}
		if (s[i]=='1')
		{
			if (nxt[i]==i+1)
			{
				for (int j=i+2;j<n;j++)
				{
					if (s[j]=='0') break;
					dp[j]=min(dp[j],dp[i-1]+1);
				}
			}
			if (nxt[i]+1<n && s[nxt[i]+1]=='1')
			{
				dp[nxt[i]+1]=min(dp[nxt[i]+1],dp[i-1]+1);
			}
		}
	}
	printf("%d\n",all-dp[n-1]);
	return 0;
}

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

typedef long double ld;
typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef pair<int,int> pi;

#define all(x) x.begin(),x.end();

const int INF=INT_MAX;
const ld PI=3.1415926535897932384626433;
const ld E=2.71828183;
const int MOD=1e9+7;

vi bfs(vector<vi>adj,int src){
    //adjacency list, not-weighted, possibly directed ,src is 1-indexed, adj[0].size()=0!!!
    //for n vertices, adj.size()=n+1. (constructed via push_back() ).

    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return dst;
}
vi bfsParents(vector<vi>adj,int src){
    vi parents=vi(adj.size(),INF);
    parents[src]=-1;
    queue<int>q;
    q.push(src);
    vi dst(adj.size(),INF);
    dst[src]=0;
    while(!q.empty()){
        int c=q.front();
        q.pop();
        for(int nbr:adj[c]){
            if(dst[nbr]==INF){
                parents[nbr]=c;
                dst[nbr]=dst[c]+1;
                q.push(nbr);
            }
        }
    }
    return parents;
}
vi shortestPath(vector<vi>adj,int src,int dst){
    vi bfsParetns=bfsParents(adj,src);
    vi ans;
    while(src!=dst){
        if(bfsParetns[src]==INF)
            return {};
        ans.push_back(src);
        src=bfsParetns[src];
    }
    return ans;
}
int powMod(int base,int exp,int mod){
    //(base^exp) %mod
    int ans=1;
    for(int i=0; i<exp; i++)
        ans=((ans%mod)*(base%mod))%mod;
    return ans;
}
vi divisorsOf(int n){
    //vector of divisors of n (inc. 1 , excl.n)
    vi ans;
    for(int i=1; i*i<=n; i++){
        if(n%i==0)
            ans.push_back(i);
        if(i*i!=n && i!=1)
            ans.push_back(n/i);
    }
    return ans;
}
int gcd(int a,int b){
    if(a%b==0)
        return b;
    else
        return gcd(b,a%b);
}

ld log (ld a,ld b){return log(b)/log(a);}
void solve();

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int t;
  //  cin >> t;
   // while(t--)
        solve();
    return 0;
}

void solve(){
    vi v={1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
    int k;
    cin >> k;
    cout << v[k-1] << "\n";

}





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

bool compere(pair<pair<int,string>,int> a, pair<pair<int,string>,int> b){
	if(a.first.second != b.first.second){
		return a.first.second < b.first.second;
	}else
	{
		return a.second > b.second;
	}
}

int main()
{
	int N;

	cin >> N;

	vector<pair<pair<int,string>,int>> rest(N);

	for(int i=0; i<N; ++i){
		string S;
		int P;
		cin >> S >> P;
		rest[i] = make_pair(make_pair(i,S),P);
	}

	sort(rest.begin(),rest.end(), compere);
	for(auto&& x: rest){
		cout << x.first.first + 1<< '\n';
	}

	return 0;
}

Measured memory_bytes: 256
import java.util.*;
import java.util.concurrent.ThreadLocalRandom;

public class Main {
    static HashSet<Long> dic = new HashSet<>();
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int n = sc.nextInt();
        dfs(0,n);
        System.out.println(dic.size());
    }
    static void dfs(long n, long upper){
        if(n>upper) return;
        String N = Long.toString(n);
        if(N.contains("3")&&N.contains("5")&&N.contains("7")) dic.add(n);
        dfs(n*10+3,upper);
        dfs(n*10+5,upper);
        dfs(n*10+7,upper);
    }
}

Measured memory_bytes: 28628
#include <iostream>
#include <vector>
#include <algorithm>
#include <functional>
using namespace std;

int main()
{
	int n;
	cin >> n;
	auto p = vector <pair<int, int>>(n);
	for(auto i = 0; i < n; ++i){
		auto& a = p[i].second;
		auto& b = p[i].first;
		cin >> a >> b;
	}
	sort(p.begin(), p.end(), greater<pair<int,int>>());
	int t = 1000000001;
	for(auto q : p){
		auto& a = q.second;
		auto& b = q.first;
		if(b < t) t = b;
		t -= a;
	}
	cout << (t < 0 ? "No" : "Yes") << endl;
	return 0;
}

Measured memory_bytes: 1792
import bisect, copy, heapq, math, sys
from collections import *
from functools import lru_cache
from itertools import accumulate, combinations, permutations, product
def input():
    return sys.stdin.readline()[:-1]
def ruiseki(lst):
    return [0]+list(accumulate(lst))
def celi(a,b):
    return -(-a//b)
sys.setrecursionlimit(5000000)
mod=pow(10,9)+7
al=[chr(ord('a') + i) for i in range(26)]
direction=[[1,0],[0,1],[-1,0],[0,-1]]

h,w,n=map(int,input().split())
ab=[list(map(int,input().split())) for i in range(n)]

itta={}
dic={}
for a,b in ab:
    dic[(a,b)]=1
def seek(t,y):
    if (not (t,y) in itta) and 2<=t<h and 2<=y<w:
        itta[(t,y)]=1
        cnt=0
        for i in range(3):
            for j in range(3):
                cnt+=(t-1+i,y-1+j) in dic
        return cnt
    else:
        return 0

lst=[0]*10
for i in range(n):
    a,b=ab[i]
    for i in range(3):
        for j in range(3):
            cnt=seek(a-1+i,b-1+j)
            if cnt:
                lst[cnt]+=1

# print(lst)
# sumlst=sum(lst)
lst[0]=(h-2)*(w-2)-sum(lst)
for i in range(10):
    print(lst[i])

Measured memory_bytes: 238996