akhauriyash/Code-Regression huggingface dataset:
// Devarshi

#include<bits/stdc++.h>
using namespace std;

#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);

typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef double ld;

template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

const int maxn=1000001;

int main(){

sync
/*a
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif
*/
int n;
cin>>n;
if(n==1){
	cout<<"Hello World";
}
else{
	int a,b;
	cin>>a>>b;
	cout<<a+b;
}

return 0;
}


Measured memory_bytes: 256
#include <cstdio>

int main()
{
    int a, b, c;
    scanf("%d %d %d", &a, &b, &c);

    int max;
    if (a > b)
    {
        if (a > c)
            max = a;
        else
            max = c;
    }
    else
    {
        max = b > c ? b : c;
    }

    printf("%d", a+b+c - max);
    return 0;
}


Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define pb push_back
#define ll long long int
#define mp make_pair
#define S second
#define F first
ll mod=1e9+7;
#define input_from_file  freopen("input.txt", "r", stdin);

int main()
{
  //------------ SEE BELOW ARTICLE---------------
 // https://codeforces.com/blog/entry/64250?#comment-484569
  // input_from_file;
  ll n,m,k,x;cin>>n;
  vector<ll> vec(n,0),sum(n,0);
  for(int i=0;i<n;i++)  {
    cin>>vec[i];
    if(i==0) sum[i]=vec[0];
    else  sum[i]=sum[i-1]+vec[i];
  }  
  vector<vector<ll>> dp(n,vector<ll>(n,1e14));
  for(int i=0;i<n;i++)   {
    dp[i][i]=0;
    if(i!=0)  dp[i-1][i]=vec[i]+vec[i-1];
  }
  for(ll gap=2;gap<n;gap++){
    for(ll i=0;i<n-gap;i++){
      for(ll j=i+1;j<=i+gap;j++){
        // if(i==0 && i+gap=2)
        dp[i][i+gap]=min(dp[i][i+gap],dp[i][j-1]+dp[j][i+gap]);
      }
      if(i==0)  dp[i][i+gap]+=sum[i+gap];
      else    dp[i][i+gap]+=sum[i+gap]-sum[i-1];
    }
  }
  // for(ll i=0;i<n;i++) {
  //     for(ll j=0;j<n;j++)  cout<<dp[i][j]<<" ";cout<<endl;}
  cout<<dp[0][n-1];
  return 0;
}


Measured memory_bytes: 1536
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
#[allow(unused_imports)]
use std::iter::*;
#[allow(unused_imports)]
use std::*;

macro_rules! test {
    ($($input:expr => $output:expr),* $(,)*) => {
#[test]
        fn solve_test() {
            $(
                {
                    let mut out = Vec::<u8>::new();
                    solve($input,&mut out);
                    let out_str =str::from_utf8(&out).unwrap();
                    assert_eq!(&out_str, &$output);
                }
            )*
        }
    };
}
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
#[allow(unused_mut)]
        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 mut $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,str) => {
        $iter.next().unwrap()
    };

    ($iter:expr, $t:tt) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

macro_rules! stdin {
    () => {{
        use std::io::Read;
        let mut s = String::new();
        std::io::stdin().read_to_string(&mut s).unwrap();
        s
    }};
}

fn main() {
    let mut out = std::io::stdout();

    solve(&stdin!(), &mut out);
}

#[allow(unused_mut)]
fn solve<W: std::io::Write>(src: &str, out: &mut W) {
    #[allow(unused_macros)]
    macro_rules! out {
        ($fmt:expr) => {{
            let _ = out.write_fmt(format_args!($fmt));
        }};
        ($fmt:expr, $($args:tt)*) => {{
            let _ = out.write_fmt(format_args!($fmt, $($args)*));
        }};
    }
    #[allow(unused_macros)]
    macro_rules! outln {
        ($fmt:expr) => {{
            out!(concat!($fmt,"
"));
        }};
        ($fmt:expr, $($args:tt)*) => {{
            out!(concat!($fmt, "
"), $($args)*);
        }};
    }

    input! {
        source = src,
        n:chars,
    }
    let mut s: usize = 0;
    for &nc in n.iter() {
        s += (nc as u8 - '0' as u8) as usize;
    }
    let a = if s % 9 == 0 { "Yes" } else { "No" };
    out!("{}", a);
}
test! {}


Measured memory_bytes: 3236
import java.util.*;
public class Main {
    public static void main(String args[]) {
     Scanner s=new Scanner(System.in);
    
    	int n=s.nextInt();
    	int w=s.nextInt();
    	int arr[][]=new int[n+1][3];
    	for(int i=1;i<=n;i++) {
    		for(int j=1;j<=2;j++) {
    		 arr[i][j]=s.nextInt(); // w v
    		                        //1   2
    		}
    	}
    	int maxval=n*1000;
    	long dp[][]=new long[n+1][maxval+1];
    	
    	for(int i=0;i<=maxval;i++) {
    		dp[1][i]=Integer.MAX_VALUE;
    	}
    	
    	dp[1][0]=0;
    	dp[1][arr[1][2]]=arr[1][1];
    	
    	for(int i=2;i<=n;i++) {
    		for(int v=0;v<=maxval;v++) {
    			dp[i][v]=dp[i-1][v];
    			if(arr[i][2]>v) {
    				continue;
    			}
    			dp[i][v]=Math.min(arr[i][1] + dp[i-1][v-arr[i][2]],dp[i][v]);
    		   
    		}
    	 }
    	long ans=0;
    	for(int i=0;i<=maxval;i++) {
    		
    			if(dp[n][i]<=w) {
    				ans=i;
    			}
    		
    	}
    	System.out.println(ans);
    	
    }
}

Measured memory_bytes: 137800
#include <iostream>

using namespace std;

string S,T;

int main(int argc,char ** argv)
{
    getline(cin,S);
    getline(cin,T);
    for (int i=S.length();i;i--)
    {
        char ch=S[S.length()-1];
        S.erase(S.length()-1,1);
        S.insert(S.begin(),ch);
        if (S==T)
        {
            cout<<"Yes\n";
            return 0;
        }
    }
    cout<<"No\n";
    return 0;
}

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

public class Main {
    public static void main(String[] args) {
        Scanner in = new Scanner(System.in);
        int n = in.nextInt();
        int[] x = new int[n];
        for (int i = 0; i < n; i++) {
            x[i] = in.nextInt();
        }
        Arrays.sort(x);
        int a = x[n-1];
        x[n-1] = -1;
        Arrays.sort(x);
        int b = -1, c = -1;
        for (int i = 0; i < n; i++) {
            if(x[i] <= a / 2) {
                b = x[i];
            } else {
                c = x[i];
                break;
            }
        }
        if(b == -1) b = x[1];
        if(c == -1) c = x[1];
        System.out.println(a + " " + (a/2 - b < c - a/2 ? b : c));
    }
}


Measured memory_bytes: 50388
import java.io.{BufferedOutputStream, BufferedReader, InputStreamReader, PrintWriter}

object Main {
  def main(args: Array[String]): Unit = {
    val in = new BufferedReader(new InputStreamReader(System.in))
    val out = new PrintWriter(new BufferedOutputStream(System.out))
    val Array(sx, sy, tx, ty) = in.readLine().split("\\s+").map(_.toInt)

    var path = ""

    for {
      _ <- sy until ty
    } {
      path += "U"
    }

    for {
      _ <- sx until tx
    } {
      path += "R"
    }

    path += "U"

    for {
      _ <- tx until (sx - 1) by -1
    } {
      path += "L"
    }

    for {
      _ <- (ty + 1) until sy by -1
    } {
      path += "D"
    }

    path += "R"

    for {
      _ <- sx until tx
    } {
      path += "R"
    }

    for {
      _ <- sy until ty
    } {
      path += "U"
    }

    path += "R"

    for {
      _ <- ty until (sy - 1) by -1
    } {
      path += "D"
    }

    for {
      _ <- (tx + 1) until sx by -1
    } {
      path += "L"
    }

    path += "U"

    out.println(path)

    out.flush()
  }
}


Measured memory_bytes: 113080
using System;
using System.Collections;
using System.Collections.Generic;
using System.Diagnostics;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using static System.Math;
using MethodImplAttribute = System.Runtime.CompilerServices.MethodImplAttribute;
using MethodImplOptions = System.Runtime.CompilerServices.MethodImplOptions;
public static class P
{
    public static void Main()
    {
        int n = int.Parse(Console.ReadLine());
        var a = Console.ReadLine().Split().Select(int.Parse).ToArray();
        var accumOdd = new long[n + 1];
        var accumEven = new long[n + 1];
        for (int i = 0; i < n; i++)
        {
            if (i % 2 == 0)
            {
                accumEven[i + 1] = accumEven[i] + a[i];
                accumOdd[i + 1] = accumOdd[i];
            }
            else
            {
                accumEven[i + 1] = accumEven[i];
                accumOdd[i + 1] = accumOdd[i] + a[i];
            }
        }
        if (n % 2 == 0)
        {
            var res = Max(accumOdd.Last(), accumEven.Last());
            var sum = 0L;
            for (int i = accumEven.Length - 3; i >= 0; i -= 2)
            {
                sum += a[i + 1];
                res = Max(res, accumEven[i] + sum);
            }
            Console.WriteLine(res);
            return;
        }
        else
        {
            //max(xoxoxox, oxoxoxx, xxoxoxo)
            var sum = accumEven.SkipLast(1).Last();
            var res = sum;
            var tailSum = 0L;
            var tailMax = 0L;
            for (int i = accumEven.Length - 4; i >= 0; i -= 2)
            {
                sum -= a[i]; sum += a[i + 1];
                tailSum += a[i + 2]; tailSum -= a[i + 1];
                tailMax = Max(tailMax, tailSum);
                res = Max(res, sum + tailMax);
            }
            Console.WriteLine(res);
            return;
        }
    }
}


Measured memory_bytes: 50028
import java.util.*;

public class Main{
  public static void main(String args[]){
    Scanner sc = new Scanner(System.in);
    int n = sc.nextInt();
    String s[] = new String [n];
    int flag = 0;
    for(int i = 0;i < n;i++){
      s[i] = sc.next();
      if(s[i].equals("Y")){
        flag = 1;
      }
    }
    if(flag == 1){
      System.out.println("Four");
    }else{
      System.out.println("Three");
    }
  }
}

Measured memory_bytes: 23508
// Created by ...Lusifer
#include<bits/stdc++.h>
using namespace std;
 
#define pb 		push_back
#define mp 		make_pair
#define prior   priority_queue
#define MOD 	1000000007
#define INF64 	(long long)1e18
#define INF 	(int)1e9
#define PI 		3.1415926535897932384626433832795 
#define ll      long long
#define ld		long double
#define ret     return
#define NUM 	1000001
const int SIZE = 2e5+4;
void fastio(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
}

void solveTest(){
	int n,d;
	cin>>n>>d;
	int a[n][d];
	for(int i=0;i<n;i++){
		for(int j=0;j<d;j++){
			cin>>a[i][j];
		}
	}
	int cnt=0;
	for(int i=0;i<n-1;i++){
		for(int j=i+1;j<n;j++){
			ll sum=0;
			for(int k=0;k<d;k++){
				sum += abs(a[i][k]-a[j][k])*abs(a[i][k]-a[j][k]);
			}
			int x = sqrt(sum);
			if(sqrt(sum)==x){
				cnt++;
			}
		}
	}
	cout<<cnt<<endl;
	
	return ;
}
 
int main(){
	fastio();

	int t=1;
	//cin>>t;
	while(t--){
		solveTest();
 
	}
	return 0;
}

Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;int N,a,b,i,V[1<<20],f[1<<20];pair<int,int>R[1<<20];main(){for(cin>>N;i<N;cin>>a>>b,R[i]={a,a+b},i++);for(sort(R,R+N),b=V[N]=1;i--;b=V[i]=(b+V[f[i]=a])%998244353)for(a=i+1;a<N&&R[a].first<R[i].second;a=f[a]);cout<<*V;}

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

#define FOR(i,a,b) for(int i=a;i<=b;++i)
#define FORD(i,a,b) for(int i=a;i>=b;--i)
#define maxn 110
#define maxweight 100010

typedef long long ll;
using namespace std;
const ll oo = 1e18;

struct dta { int w, v; };

int n, W, V;
ll F[maxn][maxweight];
dta A[maxn];

int main()
{
	ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0);
    cin >> n >> W;
    V = 0;
    FOR(i, 1, n) {
        cin >> A[i].w >> A[i].v;
        V += A[i].v;
    }
    FOR(i, 1, V) F[0][i] = oo;
    F[0][0] = 0;
    FOR(i, 1, n)
    FOR(j, 1, V) {
        F[i][j] = F[i-1][j];
        if (j-A[i].v >= 0) F[i][j] = min(F[i][j], F[i-1][j-A[i].v] + A[i].w);
    }

    int res = 0;
    FORD(i, V, 1)
        if (F[n][i] <= W) {
            res = i;
            break;
        }
    cout << res;
	return 0;
}


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

class Program
{
	static void Main(string[] args)
	{
        string[] input = Console.ReadLine().Split(' ');

        if (input[0].Last() == input[1].First() && input[1].Last() == input[2].First())
        {
            Console.WriteLine("YES");
        }
        else
        {
            Console.WriteLine("NO");
        }
	}
}

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

using namespace std;


int main () {
	string s;
	cin >> s;

	string t = "abcdefghijklmnopqrstuvwxyz";

	sort(s.begin(), s.end());
	s.erase(unique(s.begin(), s.end()), s.end());

	while (s.size() != 0) {
		if (s[0] == t[0]) {
			s.erase(0, 1);
			t.erase(0, 1);
		}
		else {
			break;
		}
	}

	if (t.size()) cout << t[0] << endl;
	else cout << "None" << endl;

	return 0;
}

Measured memory_bytes: 512
#include<bits/stdc++.h>
#include<iostream>
#include<algorithm>
using namespace std;
int main()
{
	int n, m, ans = 0;
	cin>> n>>m;
	int sw[n][m];
	vector<int> onoff(n);
	for(int i=0;i<n;i++){
		for(int j=0;j<m;j++){
			sw[i][j] = 0;
		}
	}
	for(int i=0;i<m;i++){
		int k;
		cin>>k;
		for(int j=0;j<k;j++){
			int b;
			cin>>b;
			sw[b-1][i] = 1;
		}
	}
	vector<int> p(m);
	for(int i=0;i<m;i++){
		cin>>p[i];
	}
	for(int i=0;i<(1<<n);i++){
		for(int j=0;j<n;j++){
			onoff[j] = i&(1<<j);
			onoff[j]>>=j;
		}
		int cnt = 0;
		for(int k=0;k<m;k++){
			int tmpcnt = 0;
			for(int l=0;l<n;l++){
				if(sw[l][k] == 1&&onoff[l] == 1){
					tmpcnt++;
				};
			}
			if(tmpcnt%2 == p[k]) cnt++;
		}
		if(cnt == m) ans++;
	}
	cout<<ans<<endl;
}

Measured memory_bytes: 3604
#include<iostream>
#include<algorithm>
#include<string>
#include<cmath>
#include<vector>
#include<map>
using namespace std;
int main() {
    string s;
    cin >> s;
    string t[20010];
    string T;
    int j = 0;
    reverse(s.begin(), s.end());
    int n = s.size();
    for(int i = 0; i < n; i++){
        t[j] += s[i];
        if(t[j] == "maerd" || t[j] == "esare" || t[j] == "remaerd" || t[j] == "resare"){
            T += t[j];
            j++;
        }

    }
    if(T.size() == s.size()) cout << "YES" << endl;
    else cout << "NO" << endl; 
    return 0;
}

Measured memory_bytes: 4352
import java.util.Scanner;
 
public class Main {
	public static void main(String[] args) {
      Scanner sc = new Scanner(System.in);
      String S =sc.next();
      String T =sc.next();
      int A =sc.nextInt();
      int B =sc.nextInt();
      String U =sc.next();
      
      int a = A-1;
      int b = B-1;
      
      if(S.equals(U)){
      System.out.println(a);
      System.out.println(B);  
      }
      else if(T.equals(U)){
         System.out.println(A);
      System.out.println(b);
      }
    }
}

Measured memory_bytes: 23124
#include <iostream>
#include <unordered_set>
#include <vector>

using namespace std;

template <typename T>
using vec1 = vector<T>;

template <typename T>
T cin2var()
{
    T val;
    cin >> val;
    return val;
}

template <typename T>
vec1<T> cin2vec(size_t size)
{
    vec1<T> vec1;
    for (size_t i = 0; i < size; ++i) {
        T val;
        cin >> val;
        vec1.push_back(val);
    }
    return move(vec1);
}

int main()
{
    const int          N(cin2var<int>());
    const vec1<int>    X(cin2vec<int>(N));
    const int          M(cin2var<int>());
    const vec1<int>    A(cin2vec<int>(M));
    vector<int>        player_place;
    unordered_set<int> place;
    for (int x : X) {
        player_place.push_back(x);
        place.insert(x);
    }
    for (int a : A) {
        const int now  = player_place[a - 1];
        const int next = now + 1;
        if (next > 2019) {
            continue;
        }
        if (place.count(next)) {
            continue;
        }
        player_place[a - 1] = next;
        place.erase(now);
        place.insert(next);
    }
    for (int p : player_place) {
        cout << p << endl;
    }
    return 0;
}



Measured memory_bytes: 3164
#include<stdio.h>
int main(void)
{
	int t[4][3][10] = { 0 };
	int b, f, r, v, i, j, k, n;
	scanf("%d", &n);

	for (i = 0; i < n; i++) {
		scanf("%d%d%d%d", &b, &f, &r, &v);
		t[b - 1][f - 1][r - 1] = t[b - 1][f - 1][r - 1] + v;
	}

	for (i = 0; i < 4; i++) {
		for (j = 0; j < 3; j++) {
			for (k = 0; k < 10; k++) {
				printf(" %d", t[i][j][k]);
			}
			printf("\n");
		}
		if (i != 3) {
			printf("####################\n");
		}
	}
	
	return(0);
}


Measured memory_bytes: 2068
import itertools
import copy

h,w,k = map(int,input().split())
c = [list(input()) for i in range(h)]
ans = 0
hh = []
for i in range(h+1):
    hh.append(list(itertools.combinations(range(h+1), i)))
ww = []
for i in range(w+1):
    ww.append(list(itertools.combinations(range(w+1), i)))
# print(hh)
# print(hh[0])

for _ in range(h+1):
    for hs in hh[_]:
        #init
        temp = copy.deepcopy(c)
        # print(c)

        for i in hs:
            # print(i) #i列の塗り潰し
            if i == 0:
                continue
            temp[i-1] = list('r' * w)

        for _ in range(w+1):
            for ws in ww[_]:
                #init
                temp2 = copy.deepcopy(temp)

                for j in ws:
                    # print(i) #j列の塗り潰し
                    if j == 0:
                        continue
                    for ii in range(h):
                        # print(temp[ii][j-1])
                        temp2[ii][j-1] = 'r'
                # print(temp2)
                # 判定
                cnttemp = 0
                for iii in range(h):
                    cnttemp+= temp2[iii].count('#')
                if cnttemp == k:
                    ans += 1

print(ans//4)


Measured memory_bytes: 9356
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
using namespace std;
using namespace std::chrono;
#include <iostream>
#include <algorithm>
#include <math.h> 
#include <string>
#include <iomanip>
#include <vector>
#include <chrono>
#include <cstdlib>
using namespace std;
int n;
vector<long long> x, y;
 
int solve(){
    if(n == 1) return 1;
    int res = n;
    for(int i = 0; i < n; i++){
        for(int j = 0; j < n; j++){
            if(i == j) continue;
            long long dx = x[j] - x[i];
            long long dy = y[j] - y[i];
            int sub = 0;
            for(int k = 0; k < n; k++){
                for(int l = 0; l < n; l++){
                    if(k == l) continue;
                    if(dx == x[l] - x[k] && dy == y[l] - y[k]) sub++;
                }
            }
            res = min(res, n-sub);
        }
    }
    return res;
}
int main(){
    cin >> n;
    x.resize(n);
    y.resize(n);
    for(int i = 0; i < n; i++) cin >> x[i] >> y[i];
    cout << solve() << endl;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define rep(i, n) for (int i = 0; i < n; i++)
#define rrep(i, n) for (int i = n - 1; i >= 0; i--)
using namespace std;
#define INF ((1<<30)-1)
#define LINF (1LL<<60)
#define EPS (1e-10)
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const int MOD2 = 998244353;

int p[200010];
set<int> st;
int mx[200010]; // iからi+k-1までの最大要素 (i=0, n-k)
int mn[200010]; // iからi+k-1までの最小要素 (i=0, n-k)
int cnt[200010]; // その時点での

int main(){
    int n, k;
    cin >> n >> k;
    rep(i, n) cin >> p[i];
    rep(i, k) st.insert(p[i]);
    mn[0] = *st.begin();
    mx[0] = *st.rbegin();
    for(int i = 1; i < n-k+1; i++){
        st.erase(p[i-1]);
        st.insert(p[i+k-1]);
        mn[i] = *st.begin();
        mx[i] = *st.rbegin();
    }

    int ans = n - k + 1;

    rep(i, n-1) cnt[i+1] = cnt[i] + (p[i] > p[i+1]);

    int tmp = 0;
    rep(i, n-k+1){ // i ~ i+k-1 のソート済みと i+1 ~ i+k のソート済みが等しいかを比較する 
        // cout << p[i] << " " << mn[i+1] << " " << mx[i] << " " << p[i+k] << endl;
        if (cnt[i] == cnt[i+k-1]) {
            tmp++;
            continue;
        }
        if (p[i] < mn[i+1] && mx[i] < p[i+k]) ans--;
    }

    cout << ans - max(0, tmp-1)<< endl;

    return 0;
}


Measured memory_bytes: 14468
#include <iostream>
#include <vector>
#include <algorithm>
#include <iterator>
#include <queue>
#include <stack>
#include <map>
#include <set>
#include <string>
#include <cmath>
using namespace std;
#define MOD 1000000007
#define INF 1<<30
#define LINF (ll)1<<62
#define MAX 510000
#define rep(i,n) for(ll i=0; i<(n); i++)
#define REP(i,a,b) for(ll i=(a); i<(b); i++)
#define all(x) (x).begin(),(x).end()
using namespace std;
typedef long long ll;
typedef vector<ll> vl;
typedef vector<vl> vvl;
typedef pair<ll, ll> P;
typedef vector<pair<ll, ll>> vpl;
const int mod = 1e9 + 7;

vector<ll> fac(MAX), finv(MAX), inv(MAX);

void comInit(){
    fac[0] = fac[1] = 1;
    finv[0] = finv[1] = 1;
    inv[1] = 1;
    for(ll i=2; i<MAX; i++){
        fac[i] = fac[i-1]*i % MOD;
        inv[i] = MOD - inv[MOD%i] * (MOD/i) % MOD;
        finv[i] = finv[i-1] * inv[i] % MOD;
    }
}

int main(){
    comInit();
    ll a,b; cin >> a >> b;
    if(abs(a-b)>1) puts("0");
    else{
        if(abs(a-b)==1){
            cout << (fac[a]*fac[b]) % MOD << endl;
        }else{
            cout << 2*(fac[a]*fac[b]) % MOD << endl;
        }
    }
}

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

using namespace std;

const int SIZE = 210;
const double eps = 1e-10;

typedef long long ll;

typedef ll P_type;
typedef complex<P_type> P;
const P_type P_eps = 0; //整数の時はゼロ

namespace std{
  template<class T> bool operator<(const complex<T> &a, const complex<T> &b){
    return a.real() == b.real() ? a.imag() < b.imag() : a.real() < b.real();
  }
};

P rotate(P p, double theta){
  return p * P(cos(theta), sin(theta));
}

//内積
double dot(P a, P b) {
  return (a * conj(b)).real();
}

//外積
double cross(P a, P b) {
  return (conj(a) * b).imag();
}

//反時計回り
int ccw(P a, P b, P c){
  if(cross(b-a,c-a) > 0) return 1; //COUNTER_CLOCKWISE
  if(cross(b-a,c-a) < 0) return -1; //CLOCKWISE
  if(dot(b-a,c-a) < 0) return -2; //ONLINE_BACK
  if(dot(a-b,c-b) < 0) return 2; //ONLINE_FRONT
  return 0; //ON_SEGMENT
}

/* ConvexHull(凸包) */

vector<P> ConvexHull(vector<P> s){
  vector<P> g;
  int n = (int)s.size();
  
  if(n<3) return s;
  
  sort(s.begin(),s.end());
  
  for(int i=0;i<n;i++){
    for(int m = (int)g.size();m>=2 && ccw(g[m-2],g[m-1],s[i]) <= 0; m--){
      g.pop_back();
    }
    g.push_back(s[i]);
  }
  
  int t = (int)g.size();
  
  for(int i=n-2;i>=0;i--){
    for(int m = (int)g.size();m>t && ccw(g[m-2],g[m-1],s[i]) <= 0; m--){
      g.pop_back();
    }
    g.push_back(s[i]);
  }

  g.pop_back();
  
  return g; //反時計回り
}


int main(){
  int n;
  vector<P> vec;

  scanf("%d",&n);

  for(int i=0;i<n;i++){
    int x, y;
    scanf("%d%d",&x,&y);
    vec.push_back(P(x,y));
  }

  auto res = ConvexHull(vec);

  printf("%d\n",(int)res.size());

  int start = 0;

  for(int i=1;i<(int)res.size();i++){
    if(res[i].imag() < res[start].imag() ||
       (res[i].imag() == res[start].imag() && res[i].real() < res[start].real())){
      start = i;
    }
  }
  
  for(int i=0;i<res.size();i++){
    printf("%d %d\n",(int)res[(start+i)%res.size()].real(), (int)res[(start+i)%res.size()].imag());
  }
  
  return 0;
}



Measured memory_bytes: 8352
import java.util.*;
public class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int x1 = sc.nextInt();
		int y1 = sc.nextInt();
		int x2 = sc.nextInt();
		int y2 = sc.nextInt();
		int a = x2 - x1;
		int b = y2 - y1;
		System.out.println((x2-b) + " " + (y2+a) + " " + (x1-b) + " " + (y1+a));
	}
}

Measured memory_bytes: 25172
#ifdef __GNUC__
#pragma GCC target("avx2")
#pragma GCC optimize ("O25")
#pragma GCC optimize ("tree-vectorize")
#pragma GCC optimize("unroll-loops")
#define iss std::cin
#endif
#include "bits/stdc++.h"
//#include <boost/multiprecision/cpp_int.hpp>
//#include <boost/multiprecision/cpp_dec_float.hpp>
#define rep(i, times) for(ll i = 0; i < (times); ++i)
#define p(x) (cout << x << "\n")
using ll = long long; using ld = long double; using namespace std;

#ifndef __GNUC__
string text =
R"X(
1 2
)X";
stringstream iss{text};
#endif 

bool procedures( ) {
	ll X, Y; iss >> X >> Y;
	for (ll a = 0; a <= X; ++a) {
		ll b = X - a;
		if ((Y == 2 * a + 4 * b) || (Y == 4 * a + 2 * b)) return true;
	}
	return false;
};
int main( ) {
	cin.tie(0);	ios::sync_with_stdio(0);
	cout << (procedures( ) ? "Yes" : "No") << "\n";
}


Measured memory_bytes: 3616
#include <bits/stdc++.h>
#define _GLIBCXX_DEBUG
using namespace std;
#define REP(i,m,n) for(int i=(int)(m) ; i < (int) (n) ; ++i )
#define rep(i,n) REP(i,0,n)
#define square(x) pow(x 2.0)
#define all(x) (x).begin(),(x).end()
#define F first
#define S second
#define max_queue(x) priority_queue<x>
#define min_queue(x) priority_queue<x, vector<x>, greater<x>>
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vs = vector<string>;


int main() {
  int n,max=0;
  string str;
  vs max_word;
  cin >> n;
  std::map<string, int> mp;
  rep(i,n){
    cin >> str;
    mp[str]++;
  }
  for(auto p : mp){
    if(max<p.S){
      max = p.S;
      max_word.clear();
      max_word.push_back(p.F);
    }else if(max == p.S){
      max_word.push_back(p.F);
    }
  }
  for(auto x : max_word){
    cout << x << endl;
  }
  return 0;
}


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

using namespace std;
typedef long long ll;
typedef pair<ll, ll> pair2;
typedef pair<pair<ll, ll>, int > pair3;
typedef pair<int, pair<int, pair<int, int> > > pair4;
#define MAXN 313
#define INF 1000000000000000000LL
#define MOD 1000000007LL
#define IINF 1000000000
#define mp make_pair
#define pb push_back
#define remove pop
#define all(x) x.begin(), x.end()


int n, m;

ll L;

vector<pair2> adj[MAXN];

pair2 best[MAXN][MAXN]; //first is num refills, second is fuel remaining
bool visited[MAXN][MAXN];


void solve(int start) {

	for (int i = 0; i < n; i++) {
		best[start][i] = mp(IINF * 1LL, 0LL);
	}

	best[start][start] = mp(0, -L);

	for (int asdf = 0; asdf < n; asdf++) {
		//Find closest

		pair3 closest = mp(mp(IINF * 1LL, 0LL), -1);

		for (int i = 0; i < n; i++) {
			if (visited[start][i]) continue;

			pair3 item = mp(best[start][i], i);

			if (item < closest) {
				closest = item;
			}
		}

		if (closest.first == mp(IINF * 1LL, 0LL)) {
			break;
		}

		int cur = closest.second;

		pair2 dist = closest.first;

		visited[start][cur] = true;

		for (pair2 p2 : adj[cur]) {
			int next = p2.first;
			ll distThere = p2.second;

			if (visited[start][next]) continue;

			pair2 nextDist = closest.first;

			if (distThere > -nextDist.second) {
				nextDist.first++;
				nextDist.second = -(L - distThere);
			} else {
				nextDist.second += distThere;
			}

			best[start][next] = min(best[start][next], nextDist);
		}
	}
}

int main() {
	if (fopen("FILENAME.in", "r")) {
		freopen("FILENAME.in", "r", stdin);
		freopen("FILENAME.out", "w", stdout);
	}
	ios_base::sync_with_stdio(false); 
	cin.tie(NULL);

	cin >> n >> m >> L;

	for (int i = 0; i < m; i++) {
		ll a, b; ll c;
		cin >> a >> b >> c;
		a--;b--;

		if (c > L) continue;
		adj[a].pb(mp(b, c));
		adj[b].pb(mp(a, c));
	}


	for (int i = 0; i < n; i++) {
		solve(i);
	}


	int q;
	cin >> q;

	while (q--) {
		int s, t;
		cin >> s >> t;

		s--;t--;

		if (!visited[s][t]) {
			cout << -1 << '\n';
		} else {
			cout << best[s][t].first << '\n';
		}
	}
}

//GCD GCD GCD USE GCD IN MATH


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

using namespace std;

int main() {
    int N;
    cin >> N;
    vector<int> A(N+1);
    for (int i = 1; i <= N; ++i) {
        cin >> A[i]; 
    }
    long port = 0;
    long value = 1000;
    for (int i = 1; i <= N-1; ++i) {
        if (A[i+1] - A[i] >= 0) {
            port = value / A[i];
        }
        else {
            port = 0;
        }
        value += port * (A[i+1] - A[i]);
    }
    cout << value << endl;
    return 0;
}

Measured memory_bytes: 3472
#include<cstdio>
#include<cstring>
#include<iostream>
using namespace std;
int N,ans=0;
int main(){
	scanf("%d",&N);
	for(int i=1;i<=N;i++){
		if((i>=1&&i<=9)||(i>=100&&i<=999)||
		(i>=10000&&i<=99999))ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define MOD 1000000007LL
using namespace std;
typedef long long ll;
typedef pair<ll,int> P;

int n,m;
ll a[100001];
vector<int> G[100001];
int cmp[100001];

struct quickfind{
	int par[200005];
	priority_queue<ll,vector<ll>,greater<ll> > qi[200005];
	quickfind(){
	}
	void init(int n){
		for(int i=0;i<n;i++){
			par[i]=i;
		}
	}
	int find(int x){
		if(par[x]==x)return x;
		return par[x]=find(par[x]);
	}

	void insert(int x,int y){
		qi[x].push(y);
	}

	void unite(int x,int y){
		x=find(x);
		y=find(y);
		if(x==y)return;
		if(qi[x].size()<qi[y].size()){
			par[x]=y;
			while(qi[x].size()){
				ll v=qi[x].top();
				qi[x].pop();
				qi[y].push(v);
			}
		}else{
			par[y]=x;
			while(qi[y].size()){
				ll v=qi[y].top();
				qi[y].pop();
				qi[x].push(v);
			}
		}
	}

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

quickfind qui;

void dfs(int v,int c){
	cmp[v]=c;
	qui.qi[c].push(a[v]);
	for(int i=0;i<G[v].size();i++){
		if(cmp[G[v][i]]==-1){
			dfs(G[v][i],c);
		}
	}
}

int main(void){
	scanf("%d%d",&n,&m);
	for(int i=0;i<n;i++){
		scanf("%lld",&a[i]);
	}
	for(int i=0;i<m;i++){
		int u,v;
		scanf("%d%d",&u,&v);
		G[u].push_back(v);
		G[v].push_back(u);
	}
	memset(cmp,-1,sizeof(cmp));
	int cnt=0;
	for(int i=0;i<n;i++){
		if(cmp[i]==-1)dfs(i,cnt++);
	}
	if(cnt==1){
		puts("0");
		return 0;
	}
	priority_queue<ll,vector<ll>,greater<ll> > pl;
	ll ans=0;
	int ct=0;
	for(int i=0;i<cnt;i++){
		if(qui.qi[i].size()>=2){
			ans+=qui.qi[i].top();
			qui.qi[i].pop();
			while(qui.qi[i].size()){
				pl.push(qui.qi[i].top());
				qui.qi[i].pop();
			}
		}
		else{
			ans+=qui.qi[i].top();
			ct++;
		}
	}
	for(int i=0;i<cnt-2;i++){
		if(pl.size()==0){
			printf("Impossible\n");
			return 0;
		}
		ans+=pl.top();
		pl.pop();
	}
	printf("%lld\n",ans);
	return 0;
}

Measured memory_bytes: 15480
/*GOD     IS    GREAT,
  SO    AM    I*/
#include<bits/stdc++.h>
#include<numeric>
using namespace std;
#define ll long long int
#define ford(i,a,n) for(long long int i=a;i<n;++i)
#define fore(i,a,n) for(long long int i=a;i<=n;i++)
#define foru(i,a,n) for(long long int i=a;i>=n;i--)
#define test ll t;cin>>t;while(t--)
#define op(z) cout<<z<<endl
#define ops(z) cout<<z<<" "
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define all(vec) (vec).begin(),(vec).end() 
#define debug(x) cout<<#x<<" "<<x<<endl
#define pp pair<ll,ll>
#define F first
#define S second
#define PB push_back
#define MP make_pair
#define maxe 1000000
#define MOD 1000000007
ll prime[maxe] = {0},ans=0;
// TO COUNT THE DIGIT IN A NUMBER => floor(log(n)/log10+1)
ll pwe(ll a, ll b) {
    if (b == 0)
        return 1;
    ll res = pwe(a, b / 2);
    res *= res; res %= MOD;
    if (b % 2)
        return (res * a) % MOD;
    else
        return (res );
}

void file()
{
#ifndef ONLINE_JUDGE
    freopen("input.txt", "r", stdin);
    freopen("output.txt", "w", stdout);
#endif
}
ll sumofdigits(ll n) {
    ll sum = 0;
    while (n > 0) {
        sum += n % 10;
        n /= 10;
    }
    return sum;
}
void sieve()
{
    prime[0] = 0;
    prime[1] = 0;
    prime[2] = 1;
    ll i, j, k;
    for (i = 3; i <= maxe; i += 2)
    {
        prime[i] = 1;
    }
    for (i = 3; i <= maxe; i++)
    {
        if (prime[i])
        {
            for (j = i * i; j <= maxe; j += 2 * i)prime[j] = 0;
        }
    }
}
bool cmp(pp &a, pp &b)
{
    if (a.first != b.first)
    {
        return b.first > a.first;
    }
    else
    {
        return b.second > a.second;
    }
}
void solve()
{
  string s;
  cin>>s;
  ll sum=0;
  ford(i,0,s.length())
  {
    sum+=s[i]-'0';
  }
  if(sum%9)
  {
    op("No");
  }
  else
  op("Yes");
}
int main()
{
    fastIO
    //sieve();
    //file();
    //test
    {
        solve();
    }
    return 0;
}

Measured memory_bytes: 3768
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<cmath>
#include<vector>
#include<utility>
#include<queue>
#include<deque>
#include<stack>
#include<set>
#include<map>
#include<bitset>
#include<string>
#include<functional>
#define rep(i,n,m) for(int i=(n);i<(int)(m);i++)
#define reps(i,n,m) for(int i=(n);i<=(int)(m);i++)
#define all(v) v.begin(), v.end()
#define allr(v) v.rbegin(), v.rend()
#define SZ(x) ((int)(x).size())
#define pb push_back
#define fs first
#define sc second
#define lb lower_bound
#define ub upper_bound
#define LB(a,x) lb(all(a), x) - a.begin()
#define UB(a,x) ub(all(a), x) - a.begin()
#define printfdouble(x) printf("%.20f\n",(x))
#define chartoint(c) (int)((c) - '0')
#define chartoll(c) (long long)((c) - '0')
#define MOD 1000000007
#define itn int
#define enld endl
#define ednl endl
#define icn cin
#define cotu cout
#define Endl endl
#define stirng string
using namespace std;
typedef long long ll;
const double pi = 3.141592653589793;
using Graph = vector<vector<int>>;
template<class T> bool chmax(T &a, const T &b){if(a<b){a=b; return 1;} return 0;}
template<class T> bool chmin(T &a, const T &b){if(b<a){a=b; return 1;} return 0;}
template<typename A, size_t N, typename T>
void Fill(A (&array)[N], const T &val){
    std::fill( (T*)array, (T*)(array+N), val );
}

int main(){
    cin.tie(0);ios::sync_with_stdio(false);
    int n,m; cin >> n >> m;
    bool connected[10][10];
    Fill(connected, false);
    rep(i,0,m){
        int a,b; cin >> a >> b;
        a--; b--;
        connected[a][b] = connected[b][a] = true;
    }

    vector<int> path;
    rep(i,0,n) path.pb(i);
    int ans = 0;
    do{
        bool flag = true;
        if(path[0] != 0) flag = false;
        rep(i,0,n-1){
            if(flag == false) break;
            if(connected[path[i]][path[i+1]] == false){
                flag = false;
                break;
            }
        }
        if(flag) ans++;
    }while(next_permutation(all(path)));

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


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

// マクロ
// forループ
#define REP(i,n) for(ll i=0;i<(ll)(n);i++)
#define REPD(i,n) for(ll i=n-1;i>=0;i--)
#define FOR(i,a,b) for(ll i=(a);i<=(ll)(b);i++)
#define FORD(i,a,b) for(ll i=(a);i>=(ll)(b);i--)
// xにはvectorなどのコンテナ
#define ALL(x) (x)begin(),(x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
// 出力
#define PRINT(x) cout<<(x)<<endl
#define PRINTA(x,n) REP(i,n)PRINT(x[i])
// 定数
#define INF 1000000000000 // 10^12
#define MOD 1000000007 // 10^9+7
// 略記
#define PB push_back
#define MP make_pair



int main() {
    int K; cin >> K;
    string S; cin >> S;
    if (S.size() <= K) PRINT(S);
    else {
        REP(i, K) cout << S[i];
        PRINT("...");
    }
    return 0;
}

Measured memory_bytes: 3624
#include <cstdio>
#include <algorithm>


using namespace std;

int main(){
    int N, L;
    scanf("%d %d", &N, &L);
    int a = abs(L + 1 - 1);
    int min_i = 1;
    for(int i = 1; i <= N; i++){
        if(abs(L + i - 1) < a){
            a = abs(L + i - 1);
            min_i = i;
        }
    }

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

    printf("%d\n", sum - (L + min_i - 1));

    return 0;
}

Measured memory_bytes: 128
#!/usr/bin/env python3
# -*- coding: utf-8 -*-

from math import gcd
from functools import reduce

def gcd_list(numlist):
    return reduce(gcd, numlist)

def main():
    K = int(input())

    s = 0

    for a in range(1, K+1):
        for b in range(1, K+1):
            for c in range(1, K+1):
                s += gcd_list([a, b, c])
    
    print(s)



if __name__ == '__main__':
    main()

Measured memory_bytes: 74844
#include <bits/stdc++.h>
#define maxn 10005
#define MOD 998244353
#define INF 10000000

using namespace std;

#define ll long long
#define pii pair<ll, ll>
#define piii pair<ll, pii>
#define ft first
#define sd second

void fast(){
    ios_base::sync_with_stdio(false);
    cin.tie(0);
}

ll dp[maxn];

void solve(){
    ll n, r;
    cin >> n >> r;
    if(n >= 10){
        cout << r;
    }
    else cout << r + 100 * (10-n);
}

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

/*
5
1 2
2 3
3 4
3 5
*/


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <algorithm>
#include <cmath>
#include <vector>
#include <numeric>
#include <set>
#include <cstdlib>
#include <queue>
#include <map>

using namespace std;

typedef long long llint;
typedef long double ld;
#define inf 1e18
#define mod 1000000007
//priority_queue<llint,vector<llint>,greater<llint>> que;
//priority_queue<llint> q;

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

llint x;

void solve(){
  cin >> x;
  cout << x*x*x << endl;
}

int main() {
  solve();
  return 0;
}



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

int main(){
  map< char , int > count;
  string str;
  while( cin>>str ){
    for(int i=0;i<(int)str.size();i++){
      if( isupper(str[i]) ){
        str[i]=tolower(str[i]);
      }
    }
    for(int i=0;i<(int)str.size();i++){
      count[ str[i] ]++;
    }
  }
  for(char ch='a';ch<='z';ch++){
    cout<<ch<<" : "<<count[ch]<<endl;
  }
  return 0;
}



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


int main(){
	int a, b;
	cin >> a >> b;
	if(a%2 != 0 && b%2 != 0) cout << "Odd\n";
	else cout << "Even\n";
}


Measured memory_bytes: 256
n = int(input())
ans = 0
d = {}
for i in range(1,n+1):
    t = str(i)
    key = t[0]+t[-1]
    if "0" not in key:
        d[key] = d.get(key,0) + 1

for k in d:
    k2 = k[1]+k[0]
    ans += int(d[k])*int(d.get(k2,0))

print(ans)

Measured memory_bytes: 3064
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using ll = long long;
using vi = vector<int>;
using vvi = vector<vi>;
using vl = vector<ll>;
using vvl = vector<vl>;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(nullptr);
  int INF = 1000000000;
  int h, n;
  cin >> h >> n;
  vi a(n+1), b(n+1);
  rep(i,n) cin >> a[i+1] >> b[i+1];
  vvi dp(n+1, vi(h+1, INF));
  rep(i,n+1) dp[i][0] = 0;
  for(int i=1; i<=n; i++){
    for(int j=1; j<=h; j++){
      if(j-a[i]>=0) dp[i][j] = min(dp[i-1][j], dp[i][j-a[i]] + b[i]);
      else dp[i][j] = min(dp[i-1][j], b[i]);
    }
  }
  cout << dp[n][h] << endl;
}

Measured memory_bytes: 42516
arr = Array.new
while line = $stdin.gets
  arr << line.chomp.split.map(&:to_i)
end

# arr は[[2, 3, 1], [3, 3], [3, 3, 3], [1, 2, 1]] となってる

waribiki = arr.slice(3..-1)
answers = []
waribiki.each {|innerarr| answers << arr[1][innerarr[0]-1] + arr[2][innerarr[1]-1] - innerarr[2]}
answers << arr[1].min + arr[2].min 
puts answers.min

Measured memory_bytes: 20252
import sys
import heapq
import bisect

mod = 10**9+7
dd = ((-1,0),(1,0),(0,-1),(0,1))

def I(): return(int(sys.stdin.readline()))
def LI(): return([int(x) for x in sys.stdin.readline().split()])
def S(): return(sys.stdin.readline()[:-1])
def IR(n): return([I() for _ in range(n)])

def GCD(a,b):
    while b!=0:
        a,b = b,a%b
    return a

def LCM(a,b):
    return a * b // GCD(a,b)

def main():
    N = I()
    D = LI()

    pigeon = [0] * 13

    for d in D:
        pigeon[d] += 1

    if pigeon[0] >= 1:
        return 0
    if pigeon[12] >=2:
        return 0
    for i in range(1,12):
        if pigeon[i] >= 3:
            return 0

    if N > 11:
        return 1

    Time = [[0,24] for _ in range(2**N)]

    ans = 0
    for x in range(2**N):
        for i in range(N):
            if (x>>i)%2:
                Time[x].append(D[i])
            else:
                Time[x].append(24-D[i])
        Time[x].sort()
        ans = max(ans,min([a-b for a,b in zip(Time[x][1:],Time[x][:-1])]))

    return(ans)

if __name__ == "__main__":
    print(main())


Measured memory_bytes: 42204
#include <bits/stdc++.h>
using namespace std;
#define ll  long long int
#define ld long double
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
#define MOD 1000000007
#define FAST ios_base::sync_with_stdio(false), cin.tie(0), cout.tie(0);srand(time(NULL));
const ll INF = LLONG_MAX;
vector<ll> v[100005];
ll n,m;
ll dp[100005];
ll dfs(ll node)
{
    if(dp[node]!=-1)     return dp[node];
    ll ans = 1;
    ll temp = 0;
    for(auto X:v[node])
    {
        temp = max(temp,dfs(X));
    }
    return dp[node] = (ans + temp) ;
}
int main()
{
    cin >> n >> m;
    for(ll i=0;i<m;i++)
    {
        ll x,y;
        cin>>x>>y;
        v[x].pb(y);
    }
    for(ll i=1;i<=n;i++)
    {
        ll temp = v[i].size();
        if(temp)   dp[i] = -1;
    }
    for(ll i=1;i<=n;i++)
    {
        if(dp[i]==-1)
        {
            dfs(i);
        }
    }
    cout<<*max_element(dp,dp+n+1);
}

Measured memory_bytes: 8576
#include <bits/stdc++.h>
using namespace std;
#define mem(a,b) memset(a,b,sizeof(a))
#define cin(a) scanf("%d",&a)
#define pii pair<int,int>
#define int long long
#define gcd __gcd
const int inf = 0x3f3f3f3f;
const int maxn = 201110;
const int M = 1e9+7;

vector<pii> v;

int atk[maxn];

signed main()
{
	ios::sync_with_stdio(false);
	cin.tie(0);
	int n,a,d;
	cin>>n>>d>>a;
	for(int i = 1,x,y; i <= n; i++) 
	{
		cin>>x>>y;
		v.push_back(make_pair(x,y));
	}
	sort(v.begin(),v.end());
	int ans = 0;
	for(int i = 0,j = 0; i < n; i++) 
	{	
		while(j < n && v[j].first <= v[i].first+2*d) j++;
		int res = max((v[i].second - atk[i]*a + a - 1)/a,0ll);
		ans += res;
		atk[i] += res;
		atk[j] -= res;
		atk[i+1] += atk[i];
	}
	cout<<ans<<endl;
	return 0;
}

Measured memory_bytes: 6512
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
typedef vector<vector<int>> Matrix;
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define ALL(x) (x).begin(), (x).end()
static const int INF = 2000000000;


int main(){
  int n, m, x;
  cin >> n >> m >> x;
  vector<int> c(n);
  vector<vector<int>> a(n, vector<int>(m));
  rep(i, n){
    cin >> c[i];
    rep(j, m) cin >> a[i][j];
  }

  int ans = INF;
  for (int bit = 0; bit < (1<<12); bit++){
    int cost = 0;
    vector<int> now(m, 0);
    bool ok = true;
    rep(i, n){
      if (bit & (1<<i)){
        cost += c[i];
        rep(j, m) {
          now[j] += a[i][j];
        }
      }
    }
    rep(i, m) if (now[i] < x) ok = false;
    if (ok) ans = min(ans, cost);
  }
  if (ans == INF) ans = -1;
  cout << ans << endl;
} 

Measured memory_bytes: 3640
def main():
  import sys
  b=sys.stdin.buffer
  h,w=map(int,b.readline().split())
  x=w+1
  s=[c>>3for c in b.read()]
  dp=[10001]*h*x
  dp[0]=5-s[0]
  for i in range(1,w):
    dp[i]=dp[i-1]+(s[i-1]^s[i])
  for i in range(x,h*x,x):
    dp[i]=dp[i-x]+(s[i-x]^s[i])
    for j in range(1,w):
      k=i+j
      t=dp[k-1]+(s[k-1]^s[k])
      u=dp[k-x]+(s[k-x]^s[k])
      if t>u:t=u
      dp[k]=t
  print(dp[-2]+1>>1)
main()

Measured memory_bytes: 3188
#include<bits/stdc++.h>
using namespace std;
typedef long long LL;
const int N=1001001;
char s[N];
int f[N][2]={0};
char c[N][2];
int main(){
	scanf("%s",s+1);
	int n=strlen(s+1);
	f[n+1][0]=f[n+1][1]=0;
	for(int i=n;i>=1;i--){
		for(int j=0;j<2;j++){
			int d=f[i+1][0]+1+(j==1);
			int p=f[i+1][1];
			f[i][j]=s[i]=='?'?max(p,d):s[i]=='P'?p:d;
			c[i][j]=s[i]=='?'?p>=d?'P':'D':s[i];
		}
	}
	// cerr<<f[1][0]<<endl;
	char last='D';
	for(int i=1;i<=n;i++){
		char cc=c[i][last=='P'];
		putchar(cc);
		last=cc;
	}
	printf("\n");
	return 0;
}

Measured memory_bytes: 5812
a = Array.new
5.times{
  a << gets.to_i
}
max = 0
i_p = 0
a.each_with_index do |i, index|
  n = 10 - i.to_s[-1].to_i
  if n == 10
    n = 0
  end
  if n > max
    max = n
    i_p = index
  end
end

def get_10_upper(i)
  if i % 10 == 0
    return i
  end
  return (i / 10 + 1) * 10
end

sum = 0
a.each_with_index do |i, index|
  if  index == i_p
    sum = sum + i
  else
    sum = sum + get_10_upper(i)
  end
end
puts sum


Measured memory_bytes: 1788
#include <bits/stdc++.h>
using namespace std;
#define rep(i,N) for(int i=0,i##_max=(N);i<i##_max;++i)
#define repp(i,l,r) for(int i=(l),i##_max=(r);i<i##_max;++i)
#define per(i,N) for(int i=(N)-1;i>=0;--i)
#define perr(i,l,r) for(int i=r-1,i##_min(l);i>=i##_min;--i)
#define all(arr) (arr).begin(), (arr).end()
#define SP << " " <<
#define SPF << " "
#define SPEEDUP cin.tie(0);ios::sync_with_stdio(false);
#define MAX_I INT_MAX //1e9
#define MIN_I INT_MIN //-1e9
#define MAX_UI UINT_MAX //1e9
#define MAX_LL LLONG_MAX //1e18
#define MIN_LL LLONG_MIN //-1e18
#define MAX_ULL ULLONG_MAX //1e19
  typedef long long ll;
  typedef pair<int,int> PII;
  typedef pair<char,char> PCC;
  typedef pair<ll,ll> PLL;
  typedef pair<char,int> PCI;
  typedef pair<int,char> PIC;
  typedef pair<ll,int> PLI;
  typedef pair<int,ll> PIL; 
  typedef pair<ll,char> PLC; 
  typedef pair<char,ll> PCL; 

inline void YesNo(bool b){ cout << (b?"Yes" : "No") << endl;}
inline void YESNO(bool b){ cout << (b?"YES" : "NO") << endl;}
inline void Yay(bool b){ cout << (b?"Yay!" : ":(") << endl;}

//約数列挙O(root n)
PLL div(ll n){
  for(ll i=sqrt(n); i>=1; --i){
    if(n%i == 0) return PLL(i,n/i);
  }
  return PLL(0,0);
}


int main(void){
  SPEEDUP
  cout << setprecision(15);
  ll S;cin >> S;
  // S = x1y2 - x2y1;
  // S = E9y2 - x2;
  ll E9 = 1e9;
  ll x1=E9,y1=1;
  ll x2=E9-(S%E9),y2=(S/E9)+1;
  if(S!=1e18)cout << 0 SP 0 SP x1 SP y1 SP x2 SP y2 << endl;
  else cout << 0 SP 0 SP 0 SP 1e9 SP 1e9 SP 0 << endl;
  return 0;
}


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

using namespace std;

const int maxn =2e5 + 5;

char a[maxn];

int main() {
	int n;
	ios::sync_with_stdio(0);
	cin >> n;
	for(int i = 0 ; i < n ; i++) {
		cin >> a[i];
	}
	int ans = 0 , i = 0 , j = n - 1;
	while(i < j) {
		if(a[j] == 'R' && a[i] == 'R') {
			i++;
		}
		else if(a[j] == 'R' && a[i] == 'W'){
			i++; j--;
			ans++;
		}
		else {
			j--;
		}
	}
	cout << ans << "\n";
	return 0;
}

Measured memory_bytes: 3800
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <string>
#include <sstream>
#include <vector>
#include <queue>
#include <set>
#include <map>
#include <ctime>

#define inf 0x3f3f3f3f
#define Inf 0x3FFFFFFFFFFFFFFFLL
#define rep(i, n) for (int i = 0; i < (n); ++i)
#define Rep(i, n) for (int i = 1; i <= (n); ++i)
#define clr(x, a) memset(x, (a), sizeof x)
using namespace std;
typedef long long ll;
int const N = 100100;
int p[N], q[N], r[N];
priority_queue<int> que;
int main() {
  int x, y, a, b ,c; scanf("%d%d%d%d%d", &x, &y, &a, &b, &c);
  rep(i, a) scanf("%d", &p[i]);
  rep(i, b) scanf("%d", &q[i]);
  rep(i, c) scanf("%d", &r[i]);
  sort(p, p + a);
  sort(q, q + b);
  sort(r, r + c);
  Rep(i, x) que.push(-p[a - i]);
  Rep(i, y) que.push(-q[b - i]);
  int d = c - 1;
  while (d >= 0 && r[d] > -que.top()) {
    que.pop();
    que.push(-r[d--]);
  }
  ll ans = 0;
  while (!que.empty()) {
    ans -= que.top();
    que.pop();
  }
  printf("%lld\n", ans);
  return 0;
}



Measured memory_bytes: 2552