akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
int main(void){
  int n,m;
  scanf("%d %d",&n,&m);
  const int nmMAX=50;
  int a[nmMAX],b[nmMAX];
  for(int i=0;i<m;++i){
    scanf("%d %d",&a[i],&b[i]);
  }
  int road[nmMAX];
  for (int i=0;i<n;++i){
    road[i]=0;
  }
  for(int i=0;i<m;++i){
    road[a[i]-1]+=1;
    road[b[i]-1]+=1;
  }
  for(int i=0;i<n;++i){
    printf("%d\n",road[i]);
  }
  return 0;
}

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

typedef long long int ll;

int a[1000010];

int main() {
	ll n, k; cin >> k >> n;
	for(int i = 0; i < n; i++) cin >> a[i];
	int mx = a[0]+k-a[n-1];

	ll sum = 0;
	for (int i = 1; i < n; i++)
		mx = max(mx, a[i]-a[i-1]);

	cout << k-mx << endl;

	return 0;
}


Measured memory_bytes: 1024
#include <stdio.h>

int main(){
  int i, j, count = 0, A[100], minj, N, temp;
  
  //input
  scanf("%d",&N);

  for(i = 0; i < N; i++){
    scanf("%d",&A[i]);
  }
  
  //sort
  for(i = 0; i < N; i++){
    minj = i;
    
    for(j = i; j < N; j++){
      if(A[j] < A[minj]) minj = j;
    }
    
    temp = A[i];
    A[i] = A[minj];
    A[minj] = temp;
    if(i != minj) count++;
  }

  //output
  for(i = 0; i < N-1; i++){
    printf("%d ",A[i]);
  }

  printf("%d\n%d\n",A[i],count);

  return 0;
}




Measured memory_bytes: 2108
n = int(input())
alpha = ["a", "b", "c", "d", "e", "f", "g", "h", "i", "j"]
def doukei(n):
  if n == 1:
    return [["a", "a"]]
  k = doukei(n-1)
  ans = []
  for i in range(len(k)):
    key = k[i][1]
    ans.append([k[i][0]+"a", key])
    for j in range(1, 10):
      if key == alpha[j-1]:
        ans.append([k[i][0]+alpha[j], alpha[j]])
        break
      else:
        ans.append([k[i][0]+alpha[j], k[i][1]])
  return ans
answer = doukei(n)
for i in range(len(answer)):
  print(answer[i][0])

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

using namespace std;

int main() {
    ios_base::sync_with_stdio(0); cin.tie(nullptr); cout.tie(nullptr);
    map <string, int> M;
    int n;
    cin >> n;
    for (int i = 0; i < n; i++) {
        string s, t;
        cin >> s >> t;
        if (s == "insert") M[t] = 1;
        else cout << (M[t] ? "yes" : "no") << '\n';
    }
    return 0;
}



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

int main()
{
    int N; cin>>N;
    string s; cin>>s;
    const int K=10;
    vector<vector<int>> pos(K);
    for(int i=0;i<N;i++) pos[s[i]-'0'].push_back(i);
    for(int i=0;i<K;i++) pos[i].push_back(N);

    int ans=0;
    for(int i=0;i<K;i++) for(int j=0;j<K;j++) for(int k=0;k<K;k++){
        int idx=pos[i][0];
        if(idx<N) idx=*upper_bound(pos[j].begin(),pos[j].end(),idx);
        if(idx<N) idx=*upper_bound(pos[k].begin(),pos[k].end(),idx);
        if(idx<N) ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
import Control.Applicative
import Control.Monad
import Control.Monad.ST
import Data.Functor
import Data.Function
import Data.Monoid
import Data.Maybe
import Data.List
import qualified Data.Foldable as Foldable
import qualified Data.Set as Set
import Data.List.Split
import Data.Bits
import Data.Char
import Data.Ix
import Data.Ratio
import Data.Ord
import Data.Tuple
import Data.Array
--import Data.Array.Unboxed
import Data.Array.IO
import Data.Array.ST
import Data.IORef
import Data.STRef
-- import System.IO.Unsafe
 
readInt = read :: String -> Int
readDouble = read :: String -> Double
getInt = readLn :: IO Int
getInts = map readInt . words <$> getLine
getDouble = readLn :: IO Double
sjoin :: (Show a) => [a] -> String
sjoin = unwords . map show
cond :: a -> a -> Bool -> a
cond t f c = if c then t else f
apply2 :: (a -> a -> b) -> [a] -> b
apply2 f [x,y] = f x y
apply3 :: (a -> a -> a -> b) -> [a] -> b
apply3 f [x,y,z] = f x y z
apply4 :: (a -> a -> a -> a -> b) -> [a] -> b
apply4 f [x,y,z,w] = f x y z w
fnBin :: (b -> c -> d) -> (a -> b) -> (a -> c) -> a -> d
fnBin op f g x = op (f x) $ g x
fnTuple :: (a -> b, a -> c) -> a -> (b, c)
fnTuple (f,g) a = (f a, g a)
replace :: (Eq a) => a -> a -> [a] -> [a]
replace x y = map (\z -> if z==x then y else z)
modifyArray :: (Ix i, MArray a e m) => a i e -> i -> (e -> e) -> m ()
modifyArray arr ix f = readArray arr ix >>= writeArray arr ix . f
-- end of templete

toSec h m s = h * 3600 + m * 60 + s
toHMS s = [div s 3600, div (mod s 3600) 60, mod s 60]

main = do
    replicateM_ 3 $ do
        [h,m,s,hh,mm,ss] <- getInts
        putStrLn $ sjoin $ toHMS $ toSec hh mm ss - toSec h m s

Measured memory_bytes: 3788
import java.util.Scanner;

public class Main {

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

			int cnt = sc.nextInt();
			
			if(cnt <0 || cnt > 10000) {
				System.exit(0);
			}
			
			int[] ary = new int[cnt];
			int input;
			int i=0;
			while(i<cnt) {
				input = sc.nextInt();
				if(input >= -1000000 && input <= 1000000) {
					ary[i] = input;
					i++;
				}
			}
				
			
			long sum =0;
			int min = ary[0];
			int max = ary[0];
			for(int tmp:ary) {
				if(tmp < min) {
					min = tmp;
				}
				if(tmp > max) {
					max = tmp;
				}
				sum += tmp;
			}
			System.out.println(String.format("%d %d %d", min,max,sum));
		}
	}
}

Measured memory_bytes: 41828
#include <bits/stdc++.h>
using namespace std;
int main(){
  long long N;
  long long ans=0;
  cin >> N;
  for(int i=1;i<=N;i++){
      if(i%15 == 0 || i%3 == 0 || i%5 == 0){
      }
      else{
        ans += i;
      }
  }
  cout << ans;
return 0;
}

Measured memory_bytes: 3636
#include<stdio.h>
int main(){
  long long i,n,s=0,d[200010],b[200010]={};
  scanf("%lld",&n);
  for(i=0;i<n;i++){
    scanf("%lld",&d[i]);
    b[d[i]]++;
  }
  for(i=0;i<200010;i++)s+=b[i]*(b[i]-1)/2;
  //printf("%lld\n",s);
  for(i=0;i<n;i++)printf("%lld\n",s-b[d[i]]+1);
  return 0;
}


Measured memory_bytes: 5632
#!/usr/bin/env python
import sys
sys.setrecursionlimit(10**9)
from collections import deque,defaultdict
import heapq
from itertools import combinations
import bisect

n=int(input())
l=[]
p=[]
q=[]
for i in range(n):
    a,b=map(int,input().split())
    l.append([2*a,2*b])
    p.append(2*a)
    q.append(2*b)
p.sort()
q.sort()
if n%2==0:
    al=(p[n//2]+p[n//2-1])//2
    ar=(q[n//2]+q[n//2-1])//2
else:
    al=p[n//2]//2
    ar=q[n//2]//2
print(ar-al+1)



Measured memory_bytes: 56048
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <string>
#include <cmath>
#include <cstdio>
#include <iomanip>
#include <fstream>
#include <cassert>
#include <cstring>
#include <unordered_set>
#include <unordered_map>
#include <numeric>
#include <ctime>
#include <bitset>
#include <complex>

using namespace std;

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

	int n;
	cin >> n;
	vector<pair<string, int>> a(n);
	for (auto &t : a) {
		cin >> t.first >> t.second;
		t.second *= -1;
	}
	vector<int> ind(n);
	iota(ind.begin(), ind.end(), 0);
	sort(ind.begin(), ind.end(), [&](int i, int j) {
		return a[i] < a[j];
	});
	for (auto t : ind) {
		cout << t + 1 << '\n';
	} 
}


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

const int MAX_N = 1000005;

class Edge {
public:
  int nxt, to;
} e[MAX_N << 1];

int head[MAX_N], sg[MAX_N], cnt, N;
void addedge(int u, int v) {
  e[++cnt] = (Edge){head[u], v}, head[u] = cnt;
  e[++cnt] = (Edge){head[v], u}, head[v] = cnt;
}

void dfs(int u, int v) {
  for (int i = head[u]; i; i = e[i].nxt)
    if (e[i].to != v) {
      dfs(e[i].to, u);
      sg[u] ^= sg[e[i].to] + 1;
    }
}

int main() {
  scanf("%d", &N);
  for (int i = 1, u, v; i < N; ++i) {
    scanf("%d%d", &u, &v);
    addedge(u, v);
  }
  
  dfs(1, 0);

  if (sg[1] == 0) puts("Bob");
  else puts("Alice");
  return 0;
}


Measured memory_bytes: 13440
#include <bits/stdc++.h>
namespace f{
	const int MAXN = 5e5 + 19, MAXM = 1e6 + 19;
	struct Edge{
		int to, next, c, dist;
	}edge[MAXM << 1];
	int cnt = -1, head[MAXN];
	inline void add(int from, int to, int c, int dist){
		edge[++cnt].to = to;
		edge[cnt].c = c;
		edge[cnt].dist = dist;
		edge[cnt].next = head[from];
		head[from] = cnt;
	}
	int n, m, s, t;
	int pre[MAXN], dist[MAXN], flow[MAXN];
	int ans1, ans2;
	int spfa(void){
		std::queue<int>q; q.push(s);
		std::memset(dist, 0x3f, sizeof dist); dist[s] = 0;
		std::memset(flow, 0x3f, sizeof flow);
		while(!q.empty()){
			int node = q.front(); q.pop();
			for(int i = head[node]; i != -1; i = edge[i].next)
				if(edge[i].c && dist[edge[i].to] > dist[node] + edge[i].dist){
					dist[edge[i].to] = dist[node] + edge[i].dist;
					flow[edge[i].to] = std::min(flow[node], edge[i].c);
					pre[edge[i].to] = i;
					q.push(edge[i].to);
				}
		}
		if(dist[t] == 0x3f3f3f3f)
			return 0;
		return flow[t];
	}
	void edmonds_karp(int& flow, int& fee){
		int stream;
		while(stream = spfa()){
			flow += stream, fee += stream * dist[t];
			for(int i = t; i != s; i = edge[pre[i] ^ 1].to)
				edge[pre[i]].c -= stream, edge[pre[i] ^ 1].c += stream;
		}
	}
}
const int MAXN = 59;
int n, m, ans;
char s[MAXN][MAXN];
int len[MAXN][MAXN][MAXN][MAXN];
int o[MAXN][MAXN];
int main(){
	std::scanf("%d%d", &n, &m);
	for(int i = 1; i <= n; ++i) std::scanf("%s", s[i] + 1);
	std::memset(len, -0x3f, sizeof len);
	for(int i = n; i >= 1; --i)
		for(int j = m; j >= 1; --j)
			if(s[i][j] == 'o' || s[i][j] == '.'){
				len[i][j][i][j] = 0;
				if(s[i + 1][j] == 'o' || s[i + 1][j] == '.')
					for(int p = n; p > i; --p)
						for(int q = m; q >= j; --q)
							len[i][j][p][q] = std::max(len[i][j][p][q], len[i + 1][j][p][q] + 1);
				if(s[i][j + 1] == 'o' || s[i][j + 1] == '.')
					for(int p = n; p >= i; --p)
						for(int q = m; q > j; --q)
							len[i][j][p][q] = std::max(len[i][j][p][q], len[i][j + 1][p][q] + 1);
			}
	std::memset(f::head, -1, sizeof f::head);
	int ind = 0; f::s = ++ind, f::t = ++ind;
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			o[i][j] = ++ind, f::add(o[i][j], f::t, 1, 0), f::add(f::t, o[i][j], 0, 0);
	for(int i = 1; i <= n; ++i)
		for(int j = 1; j <= m; ++j)
			if(s[i][j] == 'o'){
				int v = ++ind;
				f::add(f::s, v, 1, 0), f::add(v, f::s, 0, 0);
				for(int p = i; p <= n; ++p)
					for(int q = j; q <= m; ++q)
						if(len[i][j][p][q] >= 0){
							f::add(v, o[p][q], 1, -len[i][j][p][q]), f::add(o[p][q], v, 0, len[i][j][p][q]);
						//	std::printf("%d %d %d %d %d\n", i, j, p, q, len[i][j][p][q]);
						}
			}
	f::n = ind;
	int ans, tmp;
	f::edmonds_karp(tmp, ans);
	std::printf("%d\n", -ans + 1);
	return 0;
}

Measured memory_bytes: 59244
#include<iostream>
#include<string>
#include<map>
using namespace std;
string s,t;
map<char,char>ma,mb;
int main(){
	cin>>s>>t;
	for(int i=0;i<s.size();i++){
		if(ma.count(s[i])==0&&mb.count(t[i])==0){
			ma[s[i]]=t[i];
			mb[t[i]]=s[i];
		}
		else if(ma[s[i]]==t[i]){
			continue;
		}
		else{
			cout<<"No";
			return 0;
		}
	}
	cout<<"Yes";
	return 0;
} 

Measured memory_bytes: 776
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <string>
#include <cstring>
#include <cctype>
#include <cstdlib>
#include <cmath>
#include <vector>
#include <set>
#include <map>
using namespace std;

#define REP(i, s, e) for (int i = (s); i < (e); i++)
#define REPI(i, s, e) for (int i = (s); i <= (e); i++)
#define rep(i, n) REP(i, 0, n)
#define repi(i, n) REPI(i, 0, n)
#define ALL(v) (v).begin(), (v).end()

#define dump(x) (cout << #x << " = " << x << endl)
#define dump2(x, y) (cout << "(" << #x << ", " << #y << ") = (" << x << ", " << y << ")" << endl)

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

int main(void)
{
	string str;
	string left = "qwertasdfgzxcvb";
	for (;;) {
		cin >> str;
		if (str[0] == '#') break;
		vector<bool> vs;
		rep(i, str.size()) {
			if (left.find(str[i]) != string::npos)
				vs.push_back(true);
			else
				vs.push_back(false);
		}
		int cnt = 0;
		REP(i, 1, vs.size())
			if (vs[i-1] != vs[i])
				cnt++;
		cout << cnt << endl;
	}
	return 0;
}

Measured memory_bytes: 1192
import java.util.Arrays;
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();
		int[] h = new int[n];
		for(int i  = 0; i < n; i++) {
			h[i] = sc.nextInt();
		}
		Arrays.sort(h);
		int ans = Integer.MAX_VALUE;
		for(int i = 0; i < n-k+1; i++) {
			int temp = h[k-1+i]-h[i];
			ans = Math.min(temp, ans);
		}
		System.out.println(ans);
	}
}

Measured memory_bytes: 50732
use std::io::*;
use std::str::FromStr;

#[allow(unused_macros)]
macro_rules! scan {
  ($e:expr; $t:ty) => {
    $e.get::<$t>()
  };
  ($e:expr; $($t:ty), *) => {
    ($($e.get::<$t>(),)*)
  }
}

struct Scanner<R: BufRead> {
  reader: R,
  iter: std::vec::IntoIter<String>
}

#[allow(dead_code)]
impl<R: BufRead> Scanner<R> {
  fn new(reader: R) -> Scanner<R> {
    Scanner { reader, iter: vec![String::new()].into_iter() }
  }
  fn new_line(&mut self) {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    self.iter = line.trim().split_whitespace().map(|s| s.to_string()).collect::<Vec<String>>().into_iter();
  }
  fn get<T: FromStr>(&mut self) -> T {
    self.iter.next().unwrap().parse().ok().unwrap()
  }
  fn get_line(&mut self) -> String {
    let mut line = String::new();
    self.reader.read_line(&mut line).ok();
    line.trim().to_string()
  }
}

fn main() {
  let cin = stdin();
  let cin = cin.lock();
  let mut sc = Scanner::new(cin);
  sc.new_line();
  let (x1, y1, x2, y2) = scan!(sc; f64, f64, f64, f64);
  println!("{}", ((x1 - x2).abs().powf(2.0) + (y1 - y2).abs().powf(2.0)).sqrt());
}



Measured memory_bytes: 5052
import java.util.*;

public class Main {
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        int N = sc.nextInt();
        int x = sc.nextInt();
        int[] a = new int[N];
        int count = 0;
        
        for(int i = 0; i < N; i++){
            a[i] = sc.nextInt();
        }
        
        Arrays.sort(a);
        //System.out.println();
        for(int i = 0; i < N; i++){
            //System.out.println(a[i]);
            x -= a[i];
            count++;
            if(x < 0){
                count--;
                break; 
            }
        }
        if(x > 0){
        System.out.println(count-1);
        }else{
            System.out.println(count);
        }
    }
}


Measured memory_bytes: 22996
A = list(map(int, list(input())))

for i in range(1 << 3):
    x = A[0]
    ans = str(A[0])
    for j in range(3):
        if i & 1 << j > 0:
            x += A[j + 1]
            ans += '+' + str(A[j + 1])
        else:
            x -= A[j + 1]
            ans += '-' + str(A[j + 1])
    if x == 7:
        print(ans + "=7")
        break
            


Measured memory_bytes: 9108
#include <cstdio>
#include <cstdint>
#include <vector>
#include <algorithm>
#include <utility>
#include <string>

int main() {
  size_t n;
  scanf("%zu", &n);

  std::vector<std::pair<std::string, int>> st(n);
  for (auto& p: st) {
    char buf[128];
    scanf("%s %d", buf, &p.second);
    p.first = buf;
  }

  char buf[128];
  scanf("%s", buf);
  std::string x = buf;

  int res = 0;
  bool ok = false;
  for (auto const& p: st) {
    if (ok) res += p.second;
    if (p.first == x) ok = true;
  }

  printf("%d\n", res);
}


Measured memory_bytes: 764
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <deque>
#include <queue>
#include <array>
#include <set>
#include <map>
#include <cmath>
#include <complex>
#include <algorithm>
#include <numeric>
#include <utility>
#include <tuple>
#include <bitset>
#include <cstdint>
#include <cassert>
#include <random>
#include <iterator>

using namespace std;
using i64 = int64_t;
using i32 = int32_t;

int main() {
    int n, m;
    cin >> n >> m;
    vector<int> s(n);
    for (int i = 0; i < m; ++i) {
        int k;
        cin >> k;
        while (k--) {
            int a;
            cin >> a;
            s[a - 1] |= 1 << i;
        }
    }
    int p = 0;
    for (int i = 0; i < m; ++i) {
        int q;
        cin >> q;
        p |= q << i;
    }
    int ans = 0;
    for (int t = 0; t < (1 << n); ++t) {
        int ssum = 0;
        for (int i = 0; i < n; ++i) {
            if (t & (1 << i)) ssum ^= s[i];
        }
        ans += ssum == p;
    }
    cout << ans << endl;
    return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
	"math"
)

func main() {
	var a, b float64
	var h, m float64
	fmt.Scan(&a, &b, &h, &m)
	mc := m * 6.0
	hc := (360/12)*h + mc/12
	if mc == hc {
		fmt.Println(math.Abs(b - a))
		return
	}
	ang := math.Abs(mc - hc)
	if ang > 180 {
		ang = 360 - ang
	}
	// 予言定理
	//c2 := math.Sqrt()
	c2 := math.Pow(a, 2) + math.Pow(b, 2) - 2*a*b*math.Cos(math.Pi*ang/180)
	r := math.Sqrt(c2)
	fmt.Println(r)
}


Measured memory_bytes: 1820
// https://atcoder.jp/contests/abc137/tasks/abc137_b
//
#![allow(unused_imports)]
use std::io::*;
use std::fmt::*;
use std::str::*;
use std::cmp::*;
use std::collections::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let 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")
    };
}

#[allow(unused_macros)]
macro_rules! dvec {
    ($t:expr ; $len:expr) => {
        vec![$t; $len]
    };

    ($t:expr ; $len:expr, $($rest:expr),*) => {
        vec![dvec!($t; $($rest),*); $len]
    };
}

#[allow(unused_macros)]
macro_rules! debug {
    ($($a:expr),*) => {
        println!(concat!($(stringify!($a), " = {:?}, "),*), $($a),*);
    }
}

fn main() {
    input! {
        k: i32, x: i32
    };
    println!("{}", (x-k+1..x+k).into_iter().map(|i| i.to_string()).collect::<Vec<_>>().join(" "));
}


Measured memory_bytes: 4352
#include <iostream>
using namespace std;
#include <algorithm>
int main() {
	int X, A, B;
	cin >> X >> A >> B;
	
	int lim = A - B;
	if(lim >= 0) cout << "delicious";
	else if(abs(lim) <= X) cout << "safe";
	else cout << "dangerous";
	
	
	cout << endl;
	
	return 0;
}

Measured memory_bytes: 256
#include <stdio.h>
#include <utility>
#include <algorithm>
using namespace std;
typedef long long ll;

int main(void) {
  ll i, n, now = 0;
  scanf("%lld", &n);
  pair<ll, ll> a[n];
  for(i = 0; i < n; ++i) scanf("%lld%lld", &a[i].second, &a[i].first);
  sort(a, a + n);
  for(i = 0; i < n; ++i) {
    now += a[i].second;
    if(a[i].first < now) {
      printf("No");
      return 0;
    }
  }
  printf("Yes");
  return 0;
}

Measured memory_bytes: 3456
#include <stdio.h>

#define MAX 100000

int partition(int, int);

int A[MAX], n;

int main()
{
  int i, q;
  
  scanf("%d", &n);

  for( i = 0 ; i < n ; i++ )
    scanf("%d", &A[i]);

  q = partition(0, n-1);

  for( i = 0 ; i < n ; i++ ){
    if( i > 0 ) printf(" ");
    if( i == q ) printf("[");
    printf("%d", A[i]);
    if( i == q ) printf("]");
  }

  printf("\n");

  return 0;
}

int partition(int p, int r)
{
  int i, j, x, tmp;
  
  x = A[r];
  i = p-1;

  for( j = p ; j < r ; j++ ){
    if( A[j] <= x){
      i++;
      tmp = A[i];
      A[i] = A[j];
      A[j] = tmp;
    }
  }

  tmp = A[i+1];
  A[i+1] = A[r];
  A[r] = tmp;

  return i+1;
}

Measured memory_bytes: 992
import std.stdio, std.string, std.conv;
import std.range, std.algorithm, std.array, std.typecons, std.container;
import std.math, std.numeric, core.bitop;

enum inf3 = 1_001_001_001;
enum inf6 = 1_001_001_001_001_001_001L;
enum mod = 1_000_000_007L;

alias Pair = Tuple!(int, "i", int, "j");

void main() {
    int n;
    scan(n);
    auto a = readArr!(int)();
    solve(n, a);
}

void solve(int n, int[] a) {
    long ans;
    long s;

    for (int l, r; l < n; l++) {
        while (r < n && (s ^ a[r]) == (s + a[r])) {
            s += a[r];
            r++;
        }
        ans += r - l;
        s -= a[l];
    }

    writeln(ans);
}





















int[][] readGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new int[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v;
        scan(u, v);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= v;
        if (isUndirected) {
            adj[v] ~= u;
        }
    }

    return adj;
}

alias Edge = Tuple!(int, "to", int, "cost");

Edge[][] readWeightedGraph(int n, int m, bool isUndirected = true, bool is1indexed = true) {
    auto adj = new Edge[][](n, 0);

    foreach (i; 0 .. m) {
        int u, v, c;
        scan(u, v, c);
        if (is1indexed) {
            u--, v--;
        }
        adj[u] ~= Edge(v, c);
        if (isUndirected) {
            adj[v] ~= Edge(u, c);
        }
    }

    return adj;
}

void yes(bool b) {
    writeln(b ? "Yes" : "No");
}

void YES(bool b) {
    writeln(b ? "YES" : "NO");
}

T[] readArr(T)() {
    return readln.split.to!(T[]);
}

T[] readArrByLines(T)(int n) {
    return iota(n).map!(i => readln.chomp.to!T).array;
}

void scan(T...)(ref T args) {
    import std.stdio : readln;
    import std.algorithm : splitter;
    import std.conv : to;
    import std.range.primitives;

    auto line = readln().splitter();
    foreach (ref arg; args) {
        arg = line.front.to!(typeof(arg));
        line.popFront();
    }
    assert(line.empty);
}

void fillAll(R, T)(ref R arr, T value) {
    static if (is(typeof(arr[] = value))) {
        arr[] = value;
    }
    else {
        foreach (ref e; arr) {
            fillAll(e, value);
        }
    }
}

bool chmin(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x > arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}

bool chmax(T, U...)(ref T x, U args) {
    bool isChanged;

    foreach (arg; args) {
        if (x < arg) {
            x = arg;
            isChanged = true;
        }
    }

    return isChanged;
}


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

using ll = long long;
using ull = unsigned long long;
#define repi(n) for (long long i = 0; i < (n); ++i)
#define repj(n) for (long long j = 0; j < (n); ++j)
#define repk(n) for (long long k = 0; k < (n); ++k)
#define rep(i, a, b) for (auto i = (a); i < (b); ++i)
#define itr(itr) for (auto&& v : (itr))
#define updatemax(t, v) (t = std::max(t, (v)))
#define updatemin(t, v) (t = std::min(t, (v)))

#include <boost/operators.hpp>

class modint : private boost::operators<modint>, private boost::equivalent<modint> {
  modint(const long long x, const bool y)
      : x(x) {}

 public:
  static long long M;
  long long x;
  modint(const long long x = 0)
      : x((x % M + M) % M) {}
  modint operator-() const { return modint(x ? M - x : 0, true); }
  modint& operator+=(const modint& b) { return ((x += b.x) >= M ? x -= M : 0), *this; }
  modint& operator++() { return (++x >= M ? x -= M : 0), *this; }
  modint& operator-=(const modint& b) { return ((x -= b.x) < 0 ? x += M : 0), *this; }
  modint& operator--() { return (--x < 0 ? x += M : 0), *this; }
  modint& operator*=(const modint& b) { return x = x * b.x % M, *this; }
  modint& operator/=(const modint& b) { return *this *= b.pow(-1); }
  modint pow(long long b) const {
    long long r = 1, a = x;
    b = (b % (M - 1) + (M - 1)) % (M - 1);
    while (b) {
      if (b & 1) r = r * a % M;
      b = b >> 1;
      a = a * a % M;
    }
    return modint(r, true);
  }
  friend bool operator<(const modint& a, const modint& b) { return a.x < b.x; }
  friend std::istream& operator>>(std::istream& s, modint& a) { return s >> a.x, a = a.x, s; }
  friend std::ostream& operator<<(std::ostream& s, const modint& a) { return s << a.x; }
};
long long modint::M = 998244353;

int main() {
  ll n, m, k;
  cin >> n >> m >> k;
  modint re(0), pa(1), pb(m);
  rep(i, 0, n) {
    if (i >= n - 1 - k) re += pa * pb;
    pa *= n - 1 - i;
    pa /= i + 1;
    pb *= m - 1;
  }
  cout << re << endl;
}


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

using namespace std;

int main(int argc, const char *argv[]) {
  int x;
  cin >> x;

  if (x < 1200) {
    cout << "ABC" << '\n';
  } else {
    cout << "ARC" << '\n';
  }

  return 0;
}

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

using Int = __int128_t;
Int abs128(Int val){return val<0?-val:val;}

ostream &operator<<(ostream &os,Int val){
  if(ostream::sentry(os)){
    __uint128_t tmp=abs128(val);
    char buf[64];
    char *d=end(buf);
    do{
      --d;
      *d=char(tmp%10+'0');
      tmp/=10;
    }while(tmp);
    if(val<0) *--d='-';
    Int len=end(buf)-d;
    if(os.rdbuf()->sputn(d,len)!=len){
      os.setstate(ios_base::badbit);
    }
  }
  return os;
}

istream &operator>>(istream &is,Int &val){
  string s;
  is>>s;
  val=0;
  for(Int i=0;i<(Int)s.size();i++)
    if(isdigit(s[i])) val=val*10+s[i]-'0';
  if(s[0]=='-') val*=-1;
  return is;
}



template<typename T1,typename T2> inline void chmin(T1 &a,T2 b){if(a>b) a=b;}
template<typename T1,typename T2> inline void chmax(T1 &a,T2 b){if(a<b) a=b;}

//INSERT ABOVE HERE
signed main(){
  Int n,a;
  cin>>n>>a;
  
  Int ans=n;
  for(Int i=1;i<100;i++){
    auto calc2=[&](Int x){      
      assert(x/i>=2);
      vector<Int> v(i,x/i);
      for(Int j=0;j<x%i;j++) v[j]++;
      Int s=1;
      for(Int j=0;j<i;j++){
	if(s<(n+v[j]-1)/v[j]) s*=v[j];
	else s=n;
	if(s>=n) break;
      }
      return (n+s-1)/s;
    };
    
    auto calc=[&](Int x){
      if(x<0) return ans;
      return i*a+x+calc2(x);
    };
    
    auto best=[&](Int x){
      if(x<0) return x;
      Int l=0,r=x-2*i+1;
      Int v=calc2(x);
      while(l+1<r){
	Int m=(l+r)>>1;
	if(v==calc2(x-m)) l=m;
	else r=m;
      }
      return x-l;
    };
    
    auto next=[&](Int x)->Int{
      if(x<0) return x;
      Int l=0,r=1e18;
      Int v=calc2(x);
      if(v==calc2(x+r)) return -1;
      while(l+1<r){
	Int m=(l+r)>>1;
	if(v==calc2(x+m)) l=m;
	else r=m;
      }
      return best(x+r);
    };
    
    Int l=i*2,r=1e18;    
    l=best(l);
    r=best(r);
    while((l+1<r)&&(calc2(r)+1<calc2(l))){
      chmin(ans,calc(l));
      chmin(ans,calc(r));
      Int m=best((l+r)>>1);
      Int t=next(m);
      chmin(ans,calc(m));
      chmin(ans,calc(t));
      if(calc2(t)+(t-m)==calc2(m))
	for(Int j=m+1;calc2(j)<calc2(j-1);j++) chmin(ans,calc(j));
      if(calc2(t)+(t-m)<calc2(m)) l=m;
      else r=m;
    }
    chmin(ans,calc(l));
    chmin(ans,calc(r));
  }

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


Measured memory_bytes: 256
#include <stdio.h>

int main(void) {
    int a,b;
    scanf("%d",&a);scanf("%d",&b);
    int max = a + b;
    if(max <= a-b ) { max = a-b;}
    if(max <= a*b ) { max = a*b;}
    printf("%d\n",max);
    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);

    //input
    int d = sc.nextInt();
    int[] c = new int[26]; //array of decrease
    for(int i = 0; i < c.length; i++){
      c[i] = sc.nextInt();
    }
    int[][] s = new int[d][26]; //two dimensional array of increase
    for(int row = 0; row < s.length; row++){ //day
      for(int col = 0; col < s[row].length; col++){ //contest number
        s[row][col] = sc.nextInt();
      }
    }
    /*
    int[] t = new int[d]; //array of contest numbers of the day
    for(int i = 0; i < t.length; i++){
      t[i] = sc.nextInt();
    }
    */

    //output
    for(int i = 0; i < d; i++){
      System.out.println((int)(Math.random()*26+1));
    }

    /*
    int value = 0;
    for(int i = 0; i < t.length; i++){
      int contestNum = t[i]-1;
      int day = i+1;
      value += s[day-1][contestNum]; //increase
      for(int j = 0; j < c.length; j++){
        if( !(j == contestNum) ){
          int daySinceLast = day;
          for(int m = 0; m < i; m++){
            if( j == t[m]-1 ){
              daySinceLast = day-m-1;
            }
          }
          value -= c[j]*(daySinceLast); //decrease (amount of decrease * days since last one)
        }
      }
      System.out.println(value);
    }
    */

  }
}


Measured memory_bytes: 38120
#include <cstdio>
#include <iostream>
#include <cstring>
using namespace std;
int main()
{
	string s;
	cin >> s;
	if(s=="Sunny")
	cout << "Cloudy";
	if(s=="Cloudy")
	cout << "Rainy";
	if(s=="Rainy")
	cout << "Sunny";
	
	return 0;
}

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

int main() {
  string S, T;
  cin >> S >> T;
  int Ssize = S.size();
  int Tsize = T.size();
  bool result;
  
  if(Tsize != Ssize + 1) {
    result = false;
  }
  
  for(int i = 0; i < Ssize; i++) {
    if(T.at(i) != S.at(i)) {
      result = false;
      break;
    }
    result = true;
  }
  
  if(result) {
    cout << "Yes" << endl;
  } else {
    cout << "No" << endl;
  }
}

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

int main() {
  int H, W;
  cin >> H >> W;
  string C[100];
  for (int i = 0; i < H; i++) {
    cin >> C[i];
    cout << C[i] << endl << C[i] << endl;
  }
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
const int INF=0x3f3f3f3f;

int n,ans=-INF;
int a[12],sum[120],f[120][12],p[120][12];

int solve()
{
	bool flag=0; int ret=0;
	for (int i=1;i<=10;i++)
		if (a[i]) {flag=1; break;}
	if (!flag) return -INF;
	
	memset(sum,0,sizeof(sum));
	for (int i=1;i<=n;i++)
		for (int j=1;j<=10;j++)
			if (a[j] && f[i][j]) sum[i]++;
	for (int i=1;i<=n;i++) ret+=p[i][sum[i]];
	return ret;
}

void dfs(int x)
{
	if (x==11)
	{
		ans=max(ans,solve());
		return;
	}
	a[x]=1; dfs(x+1);
	a[x]=0; dfs(x+1);
}

int main()
{
	scanf("%d",&n);
	for (int i=1;i<=n;i++)
		for (int j=1;j<=10;j++)
			scanf("%d",&f[i][j]);
	for (int i=1;i<=n;i++)
		for (int j=0;j<=10;j++)
			scanf("%d",&p[i][j]);
	
	dfs(1);
	printf("%d\n",ans);
	return 0;
}

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

using namespace std;

typedef long long int ll;

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

  int n;
  string s;
  cin >> n >> s;
  map < pair < string, string >, int > mp;

  for (int i = 0; i < (1 << n); i++) {
    string r, b;
    for (int j = 0; j < n; j++) {
      if ((i >> j) & 1) r += s[j];
      else b += s[j];
    }
    mp[{r, b}]++;
  }

  ll ans = 0;
  for (int i = 0; i < (1 << n); i++) {
    string r, b;
    for (int j = n; j < 2 * n; j++) {
      if ((i >> (j - n)) & 1) b += s[j];
      else r += s[j];
    }
    reverse (r.begin(), r.end());
    reverse (b.begin(), b.end());

    ans += mp[{r, b}];
  }

  cout << ans << '\n';
}


Measured memory_bytes: 60832
//! ----------------------------------------------
//! Framework <https://github.com/vain0x/procon>
//!
//! See the bottom of file for solution.
//! ----------------------------------------------

#![allow(unused_imports)]
#![allow(non_snake_case)]

use std::cell::RefCell;
use std::cmp::{max, min, Ordering};
use std::collections::*;
use std::fmt::{Debug, Display, Formatter, Write as FmtWrite};
use std::io::{stderr, stdin, BufRead, Write};
use std::mem::{replace, swap};
use std::ops::*;
use std::rc::Rc;

/// Print values to standard error if debug mode.
#[allow(unused_macros)]
macro_rules! debug {
    ($($e:expr),*) => {
        #[cfg(debug_assertions)]
        $({
            let (e, mut err) = (stringify!($e), stderr());
            writeln!(err, "\x1B[33m{}\x1B[0m = {:?}", e, $e).unwrap()
        })*
    };
}

/// Read from standard input and parse each word.
/// - `read!(T, U, ..)` parses a line as a tuple of words.
/// - `read![[T]]` parses a line as an array of words.
/// - `read![..; N]` parses `N` lines, using `read!(..)` repeatedly.
#[allow(unused_macros)]
macro_rules! read {
    ([$t:ty] ; $n:expr) =>
        ((0..$n).map(|_| read!([$t])).collect::<Vec<_>>());
    ($($t:ty),+ ; $n:expr) =>
        ((0..$n).map(|_| read!($($t),+)).collect::<Vec<_>>());
    ([$t:ty]) =>
        (rl().split_whitespace().map(|w| w.parse().unwrap()).collect::<Vec<$t>>());
    ($($t:ty),*) => {{
        let buf = rl();
        let mut w = buf.split_whitespace();
        ($(w.next().unwrap().parse::<$t>().unwrap()),*)
    }};
}

/// Read a line from standard input.
#[allow(dead_code)]
fn rl() -> String {
    let mut buf = String::new();
    stdin().read_line(&mut buf).unwrap();

    #[allow(deprecated)]
    buf.trim_right().to_owned()
}

// -----------------------------------------------
// Solution
// -----------------------------------------------

const P: i64 = 1_000_000_007;

pub fn factorize(mut x: i64) -> BTreeMap<i64, i64> {
    let mut ms = BTreeMap::new();
    let r = (x as f64).sqrt() as i64 + 1;

    for p in 2..r as i64 {
        let mut m = 0;

        while x >= p && x % p == 0 {
            x /= p;
            m += 1;
        }

        if m > 0 {
            ms.insert(p, m);
        }
    }

    // `x` can have a prime factor larger than √x at most one.
    if x > 1 {
        ms.insert(x, 1);
    }

    ms
}

fn main() {
    let N = read!(i64);

    let mut f = BTreeMap::new();

    for n in 1..N + 1 {
        for (p, m) in factorize(n) {
            *f.entry(p).or_insert(0) += m;
        }
    }

    let mut x = 1_i64;
    for (_, m) in f {
        x *= m + 1;
        x %= P;
    }

    println!("{}", x)
}


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

using namespace std;
#define _overload3(_1,_2,_3,name,...) name
#define _rep(i,n) repi(i,0,n)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define rep(...) _overload3(__VA_ARGS__,repi,_rep,)(__VA_ARGS__)

typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1LL<<60;

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

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

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

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

  string s;
  cin >> s;

  if(s.length() < 4){
    cout << "No" << endl;
    return 0;
  }

  if(s.substr(0, 4) == "YAKI"){
    cout << "Yes" << endl;
  }else{
    cout << "No" << endl;
  }

  return 0;
}


Measured memory_bytes: 256
#include <iostream>
using namespace std;
#include<cstring>
#include<cmath>
#include<cstdio>
#include<string>
#include<string.h>
#include<stdio.h>
#include <vector>
#include <map>
#include <set>
#include<algorithm>
#include<iterator>
#include<bits/stdc++.h>
typedef long long int lli;
typedef long long ll;
int i, j, k;
int BinarySearch(int a[], int l, int h, int x);

int main()
{
    int m,n;
    cin>>n>>m;
    if(n==m)
    {
        cout<<"Yes"<<endl;
        
    }
    else
    {
        cout<<"No"<<endl;
    }
    
    
    
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
using namespace std;
int main(){
	char a[3];
	for(int i=0;i<3;i++){
		cin>>a[i];
		if(a[i]=='9')a[i]='1';
		else if(a[i]=='1')a[i]='9';
	}
	for(int i=0;i<3;i++){
		cout<<a[i];
	}
	return 0;
} 

Measured memory_bytes: 256
import java.io.*;

class Main {
	public static void main(String[] args) throws Exception {
		BufferedReader br = new BufferedReader(new InputStreamReader(System.in));
        String[] nm=br.readLine().split(" ");
        int n=Integer.parseInt(nm[0]);
        int m=Integer.parseInt(nm[1]);
        int[][] a=new int[n][m];
        int[] b=new int[m];
        for(int i=0;i<n;i++){
        	String[] aa=br.readLine().split(" ");
            for(int j=0;j<m;j++) a[i][j]=Integer.parseInt(aa[j]);
        }
        for(int i=0;i<m;i++){
        	b[i]=Integer.parseInt(br.readLine());
        }
        StringBuilder sb=new StringBuilder();
        for(int i=0;i<n;i++){
        	int c=0;
        	for(int j=0;j<m;j++) c+=a[i][j]*b[j];
        	sb.append(c+"\n");
        }
        System.out.print(sb);
	}
}

Measured memory_bytes: 22616
#include <iostream>
#include <cmath>
#include <vector>
#include <iomanip>
#include <algorithm>
using namespace std;

int GCD(int x, int y)
{
	int small = min(x, y);
	int big = max(x, y);
	
	int a = big % small;
	if(a == 0){
		return small;
	}
	return GCD(small, a);
}
int main(void)
{	
	int x, y;
	cin >> x >> y;
	
	int g = GCD(x, y);
	
	cout << g << endl;
	
	return 0;
}

Measured memory_bytes: 3072
#include <cstdio>
#include <cstdlib>
#include <iostream>
#include <algorithm>
#include <cstring>
#include <vector>
#include <map>
 
#define rep(i,n) for(int i = 0;i < (n);i++)
#define all(x) (x).begin(),(x).end()

using namespace std;

typedef long long int ll;
typedef vector<int> vi;
typedef vector<vi> vvi;
typedef vector<ll> vl;
typedef vector<pair<int, int> > vpi;
typedef vector<pair<ll, ll> > vpl;

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



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

int solve(int s, int N, vector<int> C, vector<int> S, vector<int> F){
  if (s == N){
    return 0;
  }
  int t=0;
  for (int i=s; i<N-1; i++){
    // 今の時刻に、発車時刻と所要時間を足す（発車時刻は今の時刻から最も近いやつ）
    // S[i] + k * F[i] のうちtより大きい最小の値
    if (t < S[i]){
      t += S[i] - t + C[i];
    } else{
      t += ((t-1) / F[i] + 1) * F[i] - t + C[i];
    }
  }
  return t;
}

int main(){
    int N;
    cin >> N;
    vector<int> C(N-1);
    vector<int> S(N-1);
    vector<int> F(N-1);
    for (int i=0; i<N-1; i++){
      cin >> C[i] >> S[i] >> F[i];
    }
	
    for (int i=0; i<N; i++){
      cout << solve(i, N, C, S, F) << endl;
    }
    return 0;
}

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

typedef long long ll;

int main() {
	ll X, K, D;
	cin >> X >> K >> D;
	X = abs(X);
	ll moves = min(K, X / D);
	K -= moves;
	X -= moves * D;
	cout << ((K % 2 == 0) ? X : (D - X)) << '\n';	
}

Measured memory_bytes: 3576
#include <stdio.h>
#include <stdlib.h>
int compara(void const *a, void const *b){
	char *x = (char *)a, *y = (char *)b;
	int i = 0;
	while(x[i] != '\0' && y[i] != '\0'){
		if(x[i] < y[i]) return -1;
		if(x[i] > y[i]) return 1;
		i++;
	}
	if(x[i] < y[i]) return -1;
	if(x[i] > y[i]) return 1;
	return 0;
}

int main(){
	char stringe[100][111];
	int n, l;
	scanf("%d%d", &n, &l);
	for(int i = 0; i < n; ++i) scanf(" %s", stringe[i]);
	qsort(stringe, n, sizeof(stringe[0]), compara);
	for(int i = 0; i < n; ++i){
		int z = 0;
		while(stringe[i][z] != '\0') printf("%c", stringe[i][z++]);
	}
	printf("\n");
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define ll long long
typedef pair<ll,ll> P;
#define M 1000000007
int main(){
  int n;
  cin>>n;vector<int> a(n),b(n),c(n);
  for(int i=0;i<n;i++){
    cin>>a[i];
  }for(int i=0;i<n;i++){
    cin>>b[i];
  }for(int i=0;i<n-1;i++){
    cin>>c[i];
  }
int d=0;
  for(int i=0;i<n;i++){
    d+=b[i];if(i<n-1){
    if(a[i]+1==a[i+1]){
      d+=c[a[i]-1];
    }}
  }
  cout<<d;
}

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

int main(){
  int N;
  cin >> N;
  vector<int> K(N);
  vector<string> S(N);
  vector<int> P(N);
  for(int i=0;i<N;i++){
    K.at(i) = i+1;
    cin >> S.at(i) >> P.at(i);
  }
  bool don = false;//ひっくり返すかどうか決める
  int moji=0;
  for(int i=0;i<N-1;i++){
    for(int j=0;j<N-i-1;j++){
      //jとj+1を比較する
      don = false;
      moji = min(S.at(j).size(),S.at(j+1).size());
      if(S.at(j)==S.at(j+1)){
        if(P.at(j)<P.at(j+1)){
          don = true;
        }
      }else{
        //for(int k=0;k<moji;k++){
        // if(S.at(j).at(k)>S.at(j+1).at(k)){
        //    don = true;
        //    break;
        //  }
        //}
        if(S.at(j)>S.at(j+1)){
          don=true;
        }
      }
      if(don){
        swap(S.at(j),S.at(j+1));
        swap(P.at(j),P.at(j+1));
        swap(K.at(j),K.at(j+1));
      }
    }
  }
  for(int i=0;i<N;i++){
    cout << K.at(i) << endl;
  }
}

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

string s,p;
bool flag=true;

int main()
{
	cin>>s;
	p="YAKI";
	if(s.length()<4){
		puts("No");
		return 0;
	}
	for(int i=0;i<p.length();i++){
		if(s[i]!=p[i])flag=false;
	}
	if(flag==true)puts("Yes");
	else puts("No");
	return 0;
}

Measured memory_bytes: 256
#include <algorithm>
#include <bitset>
#include <cassert>
#include <cctype>
#include <climits>
#include <cmath>
#include <complex>
#include <cstdio>
#include <cstring>
#include <deque>
#include <functional>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <random>
#include <set>
#include <stack>
#include <string>
#include <tuple>
#include <unordered_map>
#include <vector>
#define rep(i, n) for (int i = 0; i < (int)(n); ++i)
#define show(x) cout << #x << " = " << (x) << endl;
using namespace std;
using ll = long long;
using pii = pair<int,int>;
double dp[3005][3005];
int main(){
    int n;
    cin >> n;
    vector<double>p(n);
    rep(i,n)cin >> p[i];
    dp[0][0] = 1;
    rep(i,n){
        for(int j = 0; j <= i+1; j++){
            if(j)dp[i+1][j] = dp[i][j] * (1-p[i]) + dp[i][j-1] * p[i];
            else dp[i+1][j] = dp[i][j] * (1-p[i]);
        }
    }
    double ans = 0;
    rep(i,n/2+1){
        ans += dp[n][n-i];
    }
    printf("%.10lf\n",ans);
}

Measured memory_bytes: 68992
#include <iostream>
#include <string>
 
using namespace std;
 
int main(){
  	int n,k,q,i;
  	cin >> n >> k >> q;
	int winner; //正解者
	int point[n];
	for (i=0; i<n; i++){
        point[i] = 0;
	}
	
  	for (i=0; i<q; i++){
    	cin >> winner;
    	point[winner-1]++;
    }

    
	for (i=0; i<n; i++){
		if (k-q+point[i] > 0) {
        	cout << "Yes" << endl;
        } else {
    		cout << "No" << endl;
        }
	}
		
	return 0;
}

Measured memory_bytes: 1024
N,M=map(int,input().split())
H=list(map(int,input().split()))
l=[1]*N
for i in range(M):
    A,B=map(lambda x:int(x)-1,input().split())
    if H[A]>=H[B]:
        l[B]=0
    if H[A]<=H[B]:
        l[A]=0
print(sum(l))

Measured memory_bytes: 20024
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using P = pair<ll,ll>;
#define rep(i,n) for(int (i)=0;(i)<(n);(i)++)
#define rep2(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
const ll INF = 1LL<<60;
const ll MOD = 1e9+7;

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    ll n;cin>>n;
    string s;cin>>s;
    ll ans = 1;
    for(int i=1; i<n; i++){
        if(s[i]!=s[i-1])ans++;
    }
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 512
def a(q)
puts"? "+q.join(" ")
STDOUT.flush
gets
end
N=gets.to_i
s="! "
I=(0..2*N).to_a
f=a I[1,N]
l,r=1,N+1
9.times{
m=(l+r)/2
f==a(I[m,N])?l=m:r=m
}
z=I-[0]
x=I[r,N-1]
y=z-I[l,N+1]
z.map{|i|
s+=a([i]+(x.index(i)?y:x))[0]
}
puts s

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

int main(){
  
  long long n;
  cin >> n;
  vector<long long> a(n);
  for(int i=0; i<n; i++){
    cin >> a[i];
  }
  long long ans=0;
  long long cnt;
  for(int i=1; i<n; i++){
    if(a[i]<=a[i-1]){
      cnt++;
    }
    else{
      cnt=0;
    }
    ans=max(ans,cnt);
  }
  
  cout << ans << endl;
}
    



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

#ifdef NON_SUBMIT
#define TEST(n) (n)
#define tout cerr
#else
#define TEST(n) ((void)0)
#define tout cin
#endif

using namespace std;

int main()
{
	ios::sync_with_stdio(false);
	cin.tie(NULL); cout.tie(NULL);
	TEST(freopen("input.txt","r",stdin));
	TEST(freopen("output.txt","w",stdout));
	TEST(freopen("debug.txt","w",stderr));
	string s;
	cin>>s;
	cout<<(s[2]==s[3] && s[4]==s[5] ? "Yes\n":"No\n");
	return 0;
}

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

int main() {

	int n; cin >> n;
	vector<int> d(n);
	for (int i = 0; i < n; i++) {
		cin >> d[i];
	}
	sort(d.begin(), d.end());
	ll left = d[n / 2 - 1];
	ll right = d[n / 2];
	cout << max(0LL, right - left) << endl;
	return 0;
}

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

int main() {
	int n,m,i,j,k,ans=0;
	cin >> n;
	vector<int> a(n),b(n),c(n);
	for(i=0; i<n; i++){
		cin >> a[i];
	}
	for(i=0; i<n; i++){
		cin >> b[i];
	}
	for(i=0; i<n-1; i++){
		cin >> c[i];
	}
	j=a[0]-1;
	ans+=b[j];
	for(i=1; i<n; i++){
		k=a[i]-1;
		ans+=b[k];
		if(k==j+1){
			ans+=c[j];
		}
		j=k;
	}
	cout << ans;
	return 0;
}

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

int main(){
int n, ans = 0;
cin >> n;
vector<int> a(n);
for(auto &i:a) cin >> i;
sort(a.begin(), a.end());
reverse(a.begin(), a.end());
for(int i=0; i<n; ++i){
ans += (1-i%2*2)*a[i];
}
cout << ans << endl;
}


Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Text.RegularExpressions;
using static System.Console;
using static System.Math;
using static MyIO;
using static MyUtil;

public class C
{
	public static void Main() => (new Solver()).Solve();
}

public class Solver
{
	public void Solve()
	{
		long N = GetLong();
		long K = GetLong();
		var x = N % K;
		WriteLine(Min(x, Abs(x - K)));
	}
}

public static class MyIO
{
	private static string[] args = null;
	private static int num = -1;
	private static int used = -1;

	private static string getArg()
	{
		if(used == num)
		{
			args = Console.ReadLine().Split(' ');
			num = args.Length;
			used = 0;
		}
		return args[used++];
	}

	public static int GetInt() => int.Parse(getArg());
	public static long GetLong() => long.Parse(getArg());
	public static double GetDouble() => double.Parse(getArg());
	public static decimal GetDecimal() => decimal.Parse(getArg());
	public static string GetString() => getArg();
	public static char GetChar() => getArg()[0];
	public static int[] GetInts(long N) => Enumerable.Range(0, (int)N).Select(_ => GetInt()).ToArray();
	public static long[] GetLongs(long N) => Enumerable.Range(0, (int)N).Select(_ => GetLong()).ToArray();
	public static double[] GetDoubles(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDouble()).ToArray();
	public static decimal[] GetDecimals(long N) => Enumerable.Range(0, (int)N).Select(_ => GetDecimal()).ToArray();
	public static string[] GetStrings(long N) => Enumerable.Range(0, (int)N).Select(_ => GetString()).ToArray();
}

public static class MyUtil
{
	public static void chmax<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) < 0)
			x = y;
	}

	public static void chmin<T>(ref T x, T y) where T : IComparable<T>
	{
		if(x.CompareTo(y) > 0)
			x = y;
	}

	public static void swap<T>(ref T x, ref T y)
	{
		T tmp = x;
		x = y;
		y = tmp;
	}
}

Measured memory_bytes: 13140
#include<stdio.h>
#include<stdlib.h>
#include<string.h>
#include<math.h>
#include<iostream>
#include<queue>
#include<algorithm>
#include<map>
#include<set>
using namespace std;
#define ll long long
#define re register
#define file(a) freopen(a".in",,"r",stdin);freopen(a".out","w",stdout)
inline int gi(){
	int f=1,sum=0;char ch=getchar();
	while(ch>'9' || ch<'0'){if(ch=='-')f=-1;ch=getchar();}
	while(ch>='0' && ch<='9'){sum=sum*10+ch-'0';ch=getchar();}
	return f*sum;
}
const int N=10010;
int n,k,d[N],flag[N],Max,now[N];
int main(){
	n=gi();k=gi();
	for(int i=1;i<=k;i++)d[i]=gi();
	for(int i=1;i<=k;i++)flag[d[i]]=1;
	for(int i=n;i<=100000;i++){
		int tmp=i,Flag=1;
		while(tmp){if(flag[tmp%10]){Flag=0;break;}tmp/=10;}
		if(Flag)return printf("%d\n",i),0;
	}
	return 0;
}


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

using namespace std;

int main(){
  int n;
  cin >> n;
  vector<double> a(n);
  for(int i=0;i<n;i++){
    cin >> a[i];
  }
  double sum =0;
  for(int i=0;i<n;i++){
    double reverse = 1/a[i];
    sum += reverse;
  }
  double ans = 1/sum;
  cout << fixed << setprecision(10);
  cout << ans << endl;
}

Measured memory_bytes: 256
# -*- coding: utf-8 -*-
INF=10**10

def main():
   X=int(input())
   n=0
   while(True):
      S=n*(n+1)//2
      if S>=X:
          print(n)
          return 0
      n+=1
        
      
if __name__=="__main__":
    main()
    

Measured memory_bytes: 2940