akhauriyash/Code-Regression huggingface dataset:
#include<iostream>
using namespace std;

int main(){
  int D;
  cin >> D;
  D = (D+3)%7;
  switch(D){
    case(0): cout << "mon" << endl; break;
    case(1): cout << "tue" << endl;break;
    case(2): cout << "wed" << endl;break;
    case(3): cout << "thu" << endl;break;
    case(4): cout << "fri" << endl;break;
    case(5): cout << "sat" << endl;break;
    case(6): cout << "sun" << endl;break;
  }
  return 0;
}


Measured memory_bytes: 3112
#include<bits/stdc++.h>
using namespace std;
typedef int sign;
typedef long long ll;
#define For(i,a,b) for(register sign i=(sign)(a);i<=(sign)(b);++i)
#define Fordown(i,a,b) for(register sign i=(sign)(a);i>=(sign)(b);--i)
const int N=1e3+5;
template<typename T>bool cmax(T &a,T b){return (a<b)?a=b,1:0;}
template<typename T>bool cmin(T &a,T b){return (a>b)?a=b,1:0;}
template<typename T>T read()
{
	T ans=0,f=1;
	char ch=getchar();
	while(!isdigit(ch)&&ch!='-')ch=getchar();
	if(ch=='-')f=-1,ch=getchar();
	while(isdigit(ch))ans=(ans<<3)+(ans<<1)+(ch-'0'),ch=getchar();
	return ans*f;
}
template<typename T>void write(T x,char y)
{
	if(x==0)
	{
		putchar('0'),putchar(y);
		return;
	}
	if(x<0)
	{
		putchar('-');
		x=-x;
	}
	static char wr[20];
	int top=0;
	for(;x;x/=10)wr[++top]=x%10+'0';
	while(top)putchar(wr[top--]);
	putchar(y);
}
void file()
{
#ifndef ONLINE_JUDGE
	freopen("in","r",stdin);
	freopen("out","w",stdout);
#endif
}
int n;
void input()
{
	n=read<int>();
}
vector<int>E[N];
#define pb push_back
void work()
{
	int m=0;
	for(int i=1;i*(i-1)<=n*2;i++)if(i*(i-1)==n*2)m=i;
	if(!m){puts("No");return;}
	int now=1;
	puts("Yes");
	write(m,'\n');
	For(i,1,m)For(j,i+1,m)E[i].pb(now),E[j].pb(now),now++;
	For(i,1,m)
	{
		write(E[i].size(),' ');
		for(int v:E[i])write(v,' ');
		puts("");
	}
}
int main()
{
	//file();
	input();
	work();
	return 0;
}


Measured memory_bytes: 2304
//https://atcoder.jp/contests/abc139/submissions/7282608

#include <bits/stdc++.h>
#pragma GCC optimize("O3")
#define REP(i,n) for(int i=0;i<n;i++)
#define REPP(i,n) for(int i=1;i<=n;i++)
const double PI = acos(-1);
const double EPS = 1e-15;
long long INF=(long long)1E17;
#define i_7 (long long)(1E9+7)
long mod(long a){
    long long c=a%i_7;
    if(c>=0)return c;
    return c+i_7;
}
using namespace std;
bool prime_(int n){
    if(n==1){
        return false;
    }else if(n==2){
        return true;
    }else{
        for(int i=2;i<=sqrt(n);i++){
            if(n%i==0){
                return false;
            }
        }
        return true;
    }
}

long long gcd_(long long a, long long b){
    if(a<b){
        swap(a,b);
    }
    if(a%b==0){
        return b;
    }else{
        return gcd_(b,a%b);
    }
}

long long lcm_(long long x, long long y){
    return (x/gcd_(x,y))*y;
}

class UnionFind {
public:
    //各頂点の親の番号を格納する。その頂点自身が親だった場合は-(その集合のサイズ)を入れる。
    vector<int> Parent;

    //クラスを作るときは、Parentの値を全て-1にする。
    //以下のようにすると全てバラバラの頂点として解釈できる。
    UnionFind(int N) {
        Parent = vector<int>(N, -1);
    }

    //Aがどのグループに属しているか調べる
    int root(int A) {
        if (Parent[A] < 0) return A;
        return Parent[A] = root(Parent[A]);
    }

    //自分のいるグループの頂点数を調べる
    int size(int A) {
        return -Parent[root(A)];//先祖をrootで取っておきたい。
    }

    //AとBをくっ付ける
    bool connect(int A, int B) {
        //AとBを直接つなぐのではなく、root(A)にroot(B)をくっつける
        A = root(A);
        B = root(B);
        if (A == B) {
            //すでにくっついてるからくっ付けない
            return false;
        }

        //大きい方(A)に小さいほう(B)をくっ付けたい
        //大小が逆だったらAとBをひっくり返す。
        if (size(A) < size(B)) swap(A, B);

        //Aのサイズを更新する
        Parent[A] += Parent[B];
        //Bの親をAに変更する
        Parent[B] = A;

        return true;
    }
};


int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n;
    cin>>n;
    int a[n][n-1];
    REP(i,n){
        REP(j,n-1){
            cin>>a[i][j];
            a[i][j]--;
        }
    }
    int now[n]={};
    //bool used[n][n-1] = {};
    register int day = 0;
    register bool flag;
    register bool upgrade_;
    register int op;
    while(true){
        upgrade_ = false;
        flag = true;
        int visited[n] = {};
        REP(i,n){
            if(now[i]==n-1)continue;
            flag = false;
            if(visited[i])continue;
            op = a[i][now[i]];
            if(visited[op])continue;
            if(now[op]==n-1)continue;
            if(a[op][now[op]]==i){
                //used[i][now[i]] = true;
                now[i]++;
                visited[i] = true;
                //used[op][now[op]] = true;
                now[op]++;
                visited[op] = true;
                upgrade_ = true;
            }
        }
        if(flag)break;
        if(!upgrade_){
            day = -1;
            break;
        }else{
            day++;
        }
    }
    cout<<day<<endl;
    return 0;
}


Measured memory_bytes: 4224
package main

import (
	"bufio"
	"fmt"
	"os"
	"strconv"
)

var sc = bufio.NewScanner(os.Stdin)

func Scanner() string {
	sc.Scan()
	return sc.Text()
}

func intScanner() int {
	n, _ := strconv.Atoi(Scanner())
	return n
}

func floatScanner() float64 {
	n, _ := strconv.ParseFloat(Scanner(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func stringSliceScanner(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scanner()
	}
	return a
}
func intSliceScanner(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = intScanner()
	}
	return a
}

var mod int

func main() {
	mod = 1000000007
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	s := Scanner()
	for i := 0; i < len(s); i++ {
		if string(s[i]) == "P" {
			fmt.Print("P")
		} else {
			fmt.Print("D")
		}
	}
	fmt.Println("")
}


Measured memory_bytes: 2488
import fractions
a,b = map(int,input().split())
b = fractions.gcd(a,b)
c = 0
a = 0
for i in range(2,1000001):
    while b%i == 0:
        b //= i
        a = 1
    if a:
        c+=1
    a = 0
    if b == 1:
        break
if b != 1:
    c += 1
print(c+1)


Measured memory_bytes: 5048
import java.awt.*;
import java.awt.geom.*;
import java.io.*;
 
import java.util.*;
class Main {
 
    static char[] xx = new char[] {'S','H','C','D'};
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        while(true) {
            int m = sc.nextInt();
            int f = sc.nextInt();
            int r = sc.nextInt();
            if(m == -1 && f == -1 && r == -1) break;
             
            if(m == -1 || f == -1) {
                System.out.println("F");
                continue;
            }
            if(m + f >= 80) {
                System.out.println("A");
                continue;
            }
            else if(m + f >= 65) {
                System.out.println("B");
            }
            else if(m + f >= 50) {
                System.out.println("C");
            }
            else if(m +f < 30) {
                System.out.println("F");
            }
            else {
                System.out.println((r >= 50)?"C":"D");
            }
             
        }
 
    }
}


Measured memory_bytes: 26524
#include <iostream>

//?????§??¬?´???°????±???????????????°??????(m >= n)
int calcGcd(int m, int n);
//????°???¬?????°????±????????????????????????°??????
inline int calcLcm(int m, int n, int gcd);

int main(){
	int gcd, lcm, a, b;
	
	while(std::cin >> a >> b){
		if(a > b) gcd = calcGcd(a, b);
		else gcd = calcGcd(b, a);
		lcm = calcLcm(a, b, gcd);
		
		std::cout << gcd << " " << lcm << std::endl;
	}
	
	return 0;
}

int calcGcd(int m, int n){
	return n == 0 ? m : calcGcd(n, m%n);
}

inline int calcLcm(int m, int n, int gcd){
	return m / gcd * n;
}

Measured memory_bytes: 1156
// 171

#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <numeric>
#include <queue>
#include <iomanip>
#include <climits>
#include <string>

using namespace std;

int main(){
    long long int k, tmp=0, b_buf=0, buf=0, n, m, ans=0, j;
    cin >> n >> m >> k;
    vector<long long  int> a(n), b_sum(m);
    for(int i=0; i<n; i++){
        cin >> a.at(i);
    }
    for(long long int i=0; i<m; i++){
        cin >> buf;
        b_buf += buf;
        b_sum.at(i) = b_buf;
    }

    j=m;
    for(long long int i=0; i<=n; i++){
        if(tmp > k) break;
        for(; j>0; j--){
            // cout << a_sum.at(i) << " " << b_sum.at(j) << endl;
            if(tmp + b_sum.at(j-1) <= k){
                break;
            }
        }
        ans = max(ans, i+j);
        if(i == n) break;
        tmp += a.at(i);
    }
    cout << ans << endl;
    return 0;
}


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

int main(void){
  int n;
  cin >> n;
  long power = 1;
  long number = pow(10,9);
  number = number+7;
  for(int i = 1;i <= n;i++){
    power = power*i;
    power = power%number;
  }
  cout << power << '\n';
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use itertools::Itertools;
#[allow(unused_imports)]
use itertools_num::ItertoolsNum;
#[allow(unused_imports)]
use std::cmp;
#[allow(unused_imports)]
use std::iter;
#[allow(unused_imports)]
use superslice::*;

fn run() {
    let (r, w) = (std::io::stdin(), std::io::stdout());
    let mut sc = IO::new(r.lock(), w.lock());

    let n: i64 = sc.read();

    let ans = n >= 30;
    if ans {
        println!("Yes");
    } else {
        println!("No");
    }
}

fn main() {
    std::thread::Builder::new()
        .name("run".into())
        .stack_size(256 * 1024 * 1024)
        .spawn(run)
        .unwrap()
        .join()
        .unwrap();
}

pub struct IO<R, W: std::io::Write>(R, std::io::BufWriter<W>);

impl<R: std::io::Read, W: std::io::Write> IO<R, W> {
    pub fn new(r: R, w: W) -> IO<R, W> {
        IO(r, std::io::BufWriter::new(w))
    }
    pub fn write<S: std::ops::Deref<Target = str>>(&mut self, s: S) {
        use std::io::Write;
        self.1.write(s.as_bytes()).unwrap();
    }
    pub fn read<T: std::str::FromStr>(&mut self) -> T {
        use std::io::Read;
        let buf = self
            .0
            .by_ref()
            .bytes()
            .map(|b| b.unwrap())
            .skip_while(|&b| b == b' ' || b == b'\n' || b == b'\r' || b == b'\t')
            .take_while(|&b| b != b' ' && b != b'\n' && b != b'\r' && b != b'\t')
            .collect::<Vec<_>>();
        unsafe { std::str::from_utf8_unchecked(&buf) }
            .parse()
            .ok()
            .expect("Parse error.")
    }
    pub fn read_vec<T: std::str::FromStr>(&mut self, n: usize) -> Vec<T> {
        (0..n).map(|_| self.read()).collect()
    }
    pub fn read_pairs<T: std::str::FromStr>(&mut self, n: usize) -> Vec<(T, T)> {
        (0..n).map(|_| (self.read(), self.read())).collect()
    }
    pub fn read_pairs_1_indexed(&mut self, n: usize) -> Vec<(usize, usize)> {
        (0..n)
            .map(|_| (self.read::<usize>() - 1, self.read::<usize>() - 1))
            .collect()
    }
    pub fn read_chars(&mut self) -> Vec<char> {
        self.read::<String>().chars().collect()
    }
    pub fn read_char_grid(&mut self, n: usize) -> Vec<Vec<char>> {
        (0..n).map(|_| self.read_chars()).collect()
    }
    pub fn read_matrix<T: std::str::FromStr>(&mut self, n: usize, m: usize) -> Vec<Vec<T>> {
        (0..n)
            .map(|_| (0..m).map(|_| self.read()).collect())
            .collect()
    }
}


Measured memory_bytes: 2220
N = int(input())
list = list(map(int,input().split()))
josu = 0

#脳筋
#for i in range(len(list)):
#    josu += 1/list[i]

#ans = 1/josu


#ちょい工夫？
all_jousu = 1
for i in range(len(list)):
    all_jousu *= list[i]

josu = 0
for i in range(len(list)):
    josu += all_jousu/list[i]

ans = all_jousu/josu



print(ans)

Measured memory_bytes: 3060
#include<stdio.h>

int main(void){
  int k , n;
  scanf("%d %d",&k ,&n);

  int a[2*n];
  for(int i = 0;i < n;i ++){
    scanf("%d",&a[i]);
    a[n+i] = a[i] + k;
  }
  int min = k;
  for(int i = 0;i < n;i ++){
    if((a[n+i-1] - a[i]) <  min){
      min = a[n+i-1] - a[i];
    }
  }

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

  return 0;
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
using namespace std;
long long po[35];
int sign[35];
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(NULL);
	cout.tie(NULL);
	long long sum=1;
	po[0]=1;
	for(int i=1;i<35;i++){
		po[i]=po[i-1]*2;
		sum+=po[i];
	}
	int n;
	cin>>n;
	vector<pair<long long, long long>>v;
	for(int i=0;i<n;i++){
		long long x, y;
		cin>>x>>y;
		v.push_back({x, y});
		if(i>0 && (v[i-1].first+v[i-1].second+x+y)%2!=0){
			//cout<<"YEET\n";
			cout<<-1;
			return 0;
		}
	}
	string s="";
	if((v[0].first+v[0].second)%2==0){
		s="R";
		for(int i=0;i<n;i++){
			v[i].first--;
		}
		cout<<36<<"\n";
		cout<<1<<" ";
		for(int i=0;i<35;i++) cout<<po[i]<<" ";
			cout<<"\n";
	}
	else{
		cout<<35<<"\n";
		for(int i=0;i<35;i++) cout<<po[i]<<" ";
			cout<<"\n";
	}
	for(int i=0;i<n;i++){
		string t=s;
		long long x=v[i].first, y=v[i].second;
		long long minus=(sum-x-y)/2;
		//cout<<x<<" "<<y<<endl;
		for(int i=0;i<35;i++){
			if((1ll<<i)&minus){
				sign[i]=-1;
			}
			else sign[i]=1;
		}
		for(int i=0;i<35;i++){
			if(x%(1ll<<(i+1))!=0){
				if(sign[i]==-1) t.push_back('L');
				else t.push_back('R');
				x-=sign[i]*(1ll<<i);
			}
			else{
				if(sign[i]==1) t.push_back('U');
				else t.push_back('D');
			}
		}
		cout<<t<<"\n";
	}
}

Measured memory_bytes: 384
a, va = map(int, input().split())
b, wb = map(int, input().split())
t = int(input())

kyori = abs(b-a)
hayasa = wb-va

if hayasa >= 0:
  print('NO')
elif kyori / abs(hayasa) <= t:
  print('YES')
else:
  print('NO')


Measured memory_bytes: 9176
#include<bits/stdc++.h>
using namespace std;
const int dx[]={-1,0,0,1},dy[]={0,-1,1,0};
int n,m,w[1101][1101];
char s[1101][1101];
int main()
{
	cin>>n>>m;
	for(int i=1;i<=n;i++)cin>>(s[i]+1);
	queue<pair<int,int>> q;
	memset(w,0x3f,sizeof w);
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)
			if(s[i][j]=='#')w[i][j]=0,q.push({i,j});
	while(!q.empty())
	{
		int x=q.front().first,y=q.front().second;q.pop();
		for(int d=0;d<4;d++)
		{
			int nx=x+dx[d],ny=y+dy[d];
			if(nx>0&&ny>0&&nx<=n&&ny<=m&&w[nx][ny]>w[x][y]+1)w[nx][ny]=w[x][y]+1,q.push({nx,ny});
		}
	}
	int ans=0;
	for(int i=1;i<=n;i++)
		for(int j=1;j<=m;j++)ans=max(ans,w[i][j]);
	cout<<ans<<'\n';
}


Measured memory_bytes: 14224
## coding: UTF-8

S = input()

#S_r = S[::-1]
#print(S_r)

N = len(S)

def hantei(s):
    #回文かどうかの判定
    if(s == s[::-1]):
        return 'OK'
    else:
        return 'NG'

#print(hantei(S))

answer = 'Yes'

#Sは回文である
if(hantei(S) == 'NG'):
    answer = 'No'

#前半は回文である
p = int((N-1) / 2)
#print(p)
#print(S[:p])
if(hantei(S[:p]) == 'NG'):
    answer = 'No'

#後半は回文である
q = int((N+3) / 2)
#print(S[q-1:])
if(hantei(S[q-1:]) == 'NG'):
    answer = 'No'

print(answer)

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

int main() {
  string s;
  cin >> s;
  int t = atoi(s.substr(0,2).c_str()), u = atoi(s.substr(2,2).c_str());
  
  if (u <=12 && t <= 12 && t !=0 && u !=0)
    cout <<"AMBIGUOUS"<<endl;
  else if (0 < t &&t <= 12 && u >= 0)
    cout <<"MMYY"<<endl;
  else if (0 < u && u <= 12 && t >=0)
    cout <<"YYMM"<<endl;
  else
    cout <<"NA"<<endl;
}

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

int main() {
	int N,M;
	cin >> N >> M;
	vector<P> t(M);
	set<int> s;

	rep(i,M)
		cin >> t.at(i).first >> t.at(i).second;
	sort(t.begin(), t.end());

	rep(i,M) {
		if(t.at(i).first == 1)
			s.insert(t.at(i).second);
		if(t.at(i).second==N && s.count(t.at(i).first)) {
			cout << "POSSIBLE" << endl;
			return 0;
		}
	}

	cout << "IMPOSSIBLE" << endl;
}

Measured memory_bytes: 6528
#include<bits/stdc++.h>
using namespace std;
int main()
{
	int k;
	cin>>k;
	int sum=0;
	for(int i=1;i<=k;i++)
	{
		for(int j=1;j<=k;j++)
		{
			for(int t=1;t<=k;t++)
			{
				sum+=__gcd(i,__gcd(j,t));
			}
		}
	}
	cout<<sum<<endl;
	return 0;
}

Measured memory_bytes: 3636
d = {
    1: 2,
    2: 5,
    3: 5,
    4: 4,
    5: 5,
    6: 6,
    7: 3,
    8: 7,
    9: 6,
}
N, M = map(int, input().split())
A = list(map(int, input().split()))
A.sort(reverse=True)

inf = 10**9
dp = [-inf]*(N+1)
dp[0] = 0


for a in A:
    for j in range(d[a], N + 1):
        dp[j] = max(dp[j], dp[j - d[a]] + 1)

ans = ""
remain = dp[N]
match = N
while match > 0:
    for a in A:
        if match - d[a] < 0:
            continue
        if dp[match - d[a]] == remain - 1:
            ans += str(a)
            match -= d[a]
            remain -= 1
            break

print(ans)


Measured memory_bytes: 3316
mod = 10 ** 9 + 7
n = int(input())


def nCr(a, b):
    p = q = 1
    for i in range(a - b + 1, a + 1):
        p *= i
        p %= mod
    for i in range(2, b + 1):
        q *= i
        q %= mod
    return p * pow(q, mod - 2, mod) % mod

ans = 0
l, m = divmod(n, 3)
ans += nCr(l + m - 1, m)

for i in range(l - 1, 0, -1):
    y = n - 3 * i
    ans += nCr(i + y - 1, y)
    ans %= mod
print(ans)


Measured memory_bytes: 67812
n=int(input())
sum=0
a=1
b=n-1
ans=100000000
while(a<=b):
	ans1=0
	i=a
	j=b
	while(i//10!=0):
		ans1+=i%10
		i=i//10
	ans1+=i%10
	while(j//10!=0):
		ans1+=j%10
		j=j//10
	ans1+=j%10
	a+=1
	b-=1
	if(ans1<ans):
		ans=ans1
print(ans)

Measured memory_bytes: 3064
import sys
import itertools
sys.setrecursionlimit(1000000000)
from heapq import heapify,heappop,heappush,heappushpop

import collections

a,b = map(int,input().split())
ans = a - 1
for i in range(b+1):
    if a == i:
        ans +=1
print(ans)

Measured memory_bytes: 3316
#include<bits/stdc++.h>
using namespace std;
typedef long long int lld;
typedef pair<int,string> P;
#define INF (1<<20)

int main(){
  int n;
  int num[1111];
  while(cin >> n, n){
    for(int i=0;i<n;i++){
      cin >> num[i];
    }
    int tar; cin >> tar;
    int cnt = 0;
    int left = 0;
    int right = n-1;
    while(left <= right){
      int mid = (left+right)/2;
      cnt++;
      if(num[mid] == tar) break;
      else if(num[mid] > tar) right = mid - 1;
      else left = mid + 1;
    }
    cout << cnt << endl;
  }
}

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

namespace abc141_c
{
    class Program
    {
        static void Main(string[] args)
        {
          
            var NKQ = Console.ReadLine().Split(' ').Select(x => int.Parse(x)).ToList();
            var N = NKQ[0];
            var K = NKQ[1];
            var Q = NKQ[2];

            int[] p = new int[N];

            for(int i = 0; i < Q; i++)
                p[int.Parse(Console.ReadLine()) - 1] += 1;

            for (int i = 0; i < N; i++)
                Console.WriteLine(K - Q + p[i]  > 0 ? "Yes" : "No");

        }

    }
}


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

using namespace std;

using ll = long long;


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

    ll x, y, z, k;
    cin >> x >> y >> z >> k;

    vector<ll> a(x), b(y), c(z);
    for (int i = 0; i < x; ++i) cin >> a[i];
    for (int i = 0; i < y; ++i) cin >> b[i];
    for (int i = 0; i < z; ++i) cin >> c[i];

    vector<ll> ab;
    ab.reserve(x * y);
    for (int i = 0; i < x; ++i)
        for (int j = 0; j < y; ++j)
            ab.push_back(a[i] + b[j]);

    sort(ab.begin(), ab.end(), greater<ll>());
    sort(c.begin(), c.end(), greater<ll>());

    vector<ll> abc;
    abc.reserve(min(k, x * y));
    for (int i = 0; i < min(k, x * y); ++i) {
        for (int j = 0; j < min(k, z); ++j) {
            abc.push_back(ab[i] + c[j]);
        }
    }

    sort(abc.begin(), abc.end(), greater<ll>());
    for (int i = 0; i < k; ++i)
        cout << abc[i] << '\n';

    return 0;
}


Measured memory_bytes: 34216
#include <iostream>
#include <map>
#include <vector>
#include <algorithm>
#include <set>
#include <stdio.h>
#include <math.h>
#include <queue>
using namespace std;
typedef long long int lli;
const long long int MaxN=300005;
const lli mod=1e9+7;
#define fst first
#define snd second
#define mp make_pair
const float pi=3.1415926535897932384626433832795028;
	lli mcd(lli a,lli b){
		if(a==0)return b;
		return mcd(b%a,a);
	}
	lli arr[MaxN];
	void solve(){
		lli N,i,j,res=0,ind;
		cin>>N;	
		N=N*3;
		ind=N-1;
		for(i=0;i<N;i++){
			cin>>arr[i];
		}
		sort(arr,arr+N);
		for(i=0;i<N/3;i++){
			res+=arr[ind-1];
			ind-=2;
		}
		cout<<res;
	}
int main(){
	//cin.tie(0),ios_base::sync_with_stdio(0);
	lli i,t;
	t=1;
	for(i=1;i<=t;i++){
		solve();
	}
}


Measured memory_bytes: 2560
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
int n;db a[200005];
int main(){
    ios::sync_with_stdio(false);
    cin>>n;
    db sum = 0;
    for(int i=1;i<=n;i++)cin>>a[i],sum+=1.0/a[i];
    sum=1/sum;
    printf("%.11f\n",sum);
}

Measured memory_bytes: 256
#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
#include<vector>
using namespace std;
typedef long long ll;
const int N=300000;
struct node
{
	ll d1,d2;
}p1[5*N],p2[5*N];
int n,i,j,k,ch[N][2],w[N][2],l1,l2;
ll lt,rt,mid;
vector<node> vct1[N],vct2[N];
bool cmp(node a,node b)
{
	return a.d1<b.d1;
}
bool cmq(node a,node b)
{
	return a.d2<b.d2;
}
void dfs(int x)
{
	int i,j;
	vct1[x].clear(),vct2[x].clear();
	if(!ch[x][0]&&!ch[x][1])
	{
		vct1[x].push_back((node){0,0}),vct2[x].push_back((node){0,0});
		return;
	}
	dfs(ch[x][0]);
	dfs(ch[x][1]);
	if(vct1[ch[x][0]].size()>vct1[ch[x][1]].size())
	{
		swap(ch[x][0],ch[x][1]);
		swap(w[x][0],w[x][1]);
	}
	l1=l2=0;
	ll g=1ll<<60;
	for(i=vct2[ch[x][0]].size()-1,j=0;i>=0;--i)
	{
		while(j<vct1[ch[x][1]].size()&&vct2[ch[x][0]][i].d2+vct1[ch[x][1]][j].d1+w[x][0]+w[x][1]<=mid)
		{
			g=min(g,vct1[ch[x][1]][j].d2);
			++j;
		}
		if(g<(1ll<<60))
		{
			while(l1&&vct2[ch[x][0]][i].d1+w[x][0]<=p1[l1].d1)
				--l1;
			p1[++l1]=(node){vct2[ch[x][0]][i].d1+w[x][0],g+w[x][1]};
		}
	}
	g=1ll<<60;
	for(i=vct1[ch[x][0]].size()-1,j=0;i>=0;--i)
	{
		while(j<vct2[ch[x][1]].size()&&vct1[ch[x][0]][i].d1+vct2[ch[x][1]][j].d2+w[x][0]+w[x][1]<=mid)
		{
			g=min(g,vct2[ch[x][1]][j].d1);
			++j;
		}
		if(g<(1ll<<60))
		{
			while(l2&&vct1[ch[x][0]][i].d2+w[x][0]<=p2[l2].d2)
				--l2;
			p2[++l2]=(node){g+w[x][1],vct1[ch[x][0]][i].d2+w[x][0]};
		}
	}
	for(i=1,j=l2;i<=l1&&j>=1;)
		if(p1[i].d1<p2[j].d1)
			vct1[x].push_back(p1[i++]);
		else
			vct1[x].push_back(p2[j--]);
	while(i<=l1)
		vct1[x].push_back(p1[i++]);
	while(j>=1)
		vct1[x].push_back(p2[j--]);
	for(i=l1,j=1;i>=1&&j<=l2;)
		if(p1[i].d2<p2[j].d2)
			vct2[x].push_back(p1[i--]);
		else
			vct2[x].push_back(p2[j++]);
	while(i>=1)
		vct2[x].push_back(p1[i--]);
	while(j<=l2)
		vct2[x].push_back(p2[j++]);
}
int main()
{
	scanf("%d",&n);
	for(i=2;i<=n;++i)
	{
		scanf("%d%d",&j,&k);
		if(!ch[j][0])
		{
			ch[j][0]=i;
			w[j][0]=k;
		}
		else
		{
			ch[j][1]=i;
			w[j][1]=k;
		}
	}
	lt=0,rt=n*131072ll;
	while(lt<rt)
	{
		mid=lt+rt>>1;
		dfs(1);
		if(vct1[1].empty())
			lt=mid+1;
		else
			rt=mid;
	}
	printf("%lld",lt);
	return 0;
}


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

int main() {
  string S;
  int N;
  cin >> S;
  N = S.size();
  
  int ans = 0;
  
  for(int i = 0; i < N / 2; i++) {
    if (S[i] != S[N-1-i]) ans++;
  }
  
  cout << ans << endl;
}


Measured memory_bytes: 256
import java.util.Scanner;

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

    int N = scanner.nextInt();
    int K = scanner.nextInt();
    int n = 0;
    while (N > 0) {
      n++;
      N /= K;
    }
    System.out.println(n);
  }
}


Measured memory_bytes: 23760
#include <bits/stdc++.h>
using namespace std;
#define N 1000009
#define INF 1000000009
#define MOD 1000000007
typedef long long int ll;
#define sd(x) scanf("%d",&x)
#define sd2(x,y) scanf("%d%d",&x,&y)
#define sd3(x,y,z) scanf("%lld%lld%lld",&x,&y,&z)
#define pf(x) printf("%d",x);
#define pf2(x,y) printf("%d %d\n",x,y);
#define pf3(x,y,z) printf("%d %d %d\n",x,y,z);
#define fi first
#define se second
#define pb(x) push_back(x)
#define mp(x,y) make_pair(x,y)
#define _ ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
#define tr(x) cout<<x<< endl;
#define tr2(x,y) cout<<x<<" "<<y<<" " << endl;
#define tr3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;
#define tr4(x,y,z,a) cout<<x<<" "<<y<<" "<<z<<  " " << a << " " << endl;
int a[N],b[N];
int main(){
    int i,j,n,m,t,k,x,y;
    sd(n);
    for(i=0;i<n; i++){
        sd(a[i]);
    }
    fill(b,b+N,INF);
    b[0]=0,b[1]=abs(a[1]-a[0]);
    for(i=2; i<n; i++){
        b[i] = min(b[i],b[i-1]+abs(a[i]-a[i-1]));
        b[i] = min(b[i],b[i-2]+abs(a[i]-a[i-2]));
        // tr2(i,b[i]);
    }
    tr(b[n-1]);
}

Measured memory_bytes: 6400
#include <bits/stdc++.h>
using namespace std;
int dp[110003];
int main() {
    ios::sync_with_stdio(false);
    if (fopen("input.in", "r")) {
        freopen("input.in", "r", stdin);
        freopen("output.out", "w", stdout);
    }
    int n, k;
    int h[110003];
    cin >> n >> k;
    for (int i = 0; i < n; i++) cin >> h[i];
    for (int i = 1; i < n; i++) dp[i] = 1e9;
    for (int i = 0; i <= n - 1; i++) {
        for (int j = 1; j <= k; j++) {
            dp[i + j] = min(dp[i + j], dp[i] + abs(h[i + j] - h[i]));
        }
    }
    cout << dp[n - 1] << endl;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define ff first
#define ss second
#define pb push_back
#define mp make_pair
using namespace std;
typedef long long   ll;
typedef unsigned long long   ull;
typedef long double ld;
typedef pair<ll, ll>    pll;
typedef pair<ull, ull>    pull;
typedef pair<int, int>  pii;
typedef pair<ld, ld>  pld;
ll n;
pll a[100009];
ll ans;
vector<pair<ll, pll>> v;
set<pll> sl;
set<pll> sr;
ll alll = 0;
ll allr = 1e18;
ll sfunc(pair<ll, pll> a, pair<ll, pll> b){
    return a.ss.ff < b.ss.ff;
}
int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(nullptr);
    
    //freopen("in.txt", "r", stdin);
    //freopen("out.txt", "w", stdout);
    
    cin >> n;
    ll mini = 1e18;
    ll id = 0;
    for(ll i = 0; i < n; ++i){
        cin >> a[i].ff >> a[i].ss;
        alll = max(alll, a[i].ff);
        allr = min(allr, a[i].ss);
        if(a[i].ss < mini){
            mini = a[i].ss;
            id = i;
        }
    }
    ll minr = a[id].ss;
    ll maxl = a[id].ff;
    for(ll i = 0; i < n; ++i){
        if(i == id)
            continue;
        v.pb({i, a[i]});
        sl.insert({-a[i].ff, i});
        sr.insert({a[i].ss, i});
    }
    sort(v.begin(), v.end(), sfunc);
    for(auto u : v){
        ll l2 = -(*sl.begin()).ff;
        ll r2 = (*sr.begin()).ff;
        ans = max(ans, max((ll)0, minr-maxl+1) + max((ll)0, r2-l2+1));
        sl.erase({-u.ss.ff, u.ff});
        sr.erase({u.ss.ss, u.ff});
        minr = min(minr, u.ss.ss);
        maxl = max(maxl, u.ss.ff);
    }
    for(ll i = 0; i < n; ++i){
        ans = max(ans, a[i].ss-a[i].ff+1+max((ll)0, allr-alll+1));
    }
    cout << ans << "\n";
}

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

const int INF = 1000000005;
int main(void){
  int n,k; cin >> n >> k;
  vector<int> p(n);
  rep(i,n) cin >> p[i];

  sort(p.begin(),p.end());
  int ans = 0;

  rep(i,k) ans += p[i];
  cout << ans << endl;
  
  return 0;
}


Measured memory_bytes: 3616
h,w = map(int,input().split())
arr=[]
arr.append(['.']*(w+2))
for _ in range(h):
    arr.append(list('.'+input()+'.'))
arr.append(['.']*(w+2))
ans=[]
for i in range(h):
    ans.append([])
    for j in range(w):
        tmpans=0
        if arr[i+1][j+1]=='#':
            tmpans='#'
        else:
            for hh in range(3):
                for ww in range(3):
                    if not(hh==1 and ww==1) and arr[i+hh][j+ww]=='#':
                        tmpans+=1
            tmpans=str(tmpans)
        ans[i].append(tmpans)
for line in ans:
    print(''.join(line))


Measured memory_bytes: 3188
N = int(input())
xyh = [list(map(int, input().split())) for _ in range(N)]
xyh.sort(key = lambda x: -x[2])
H = 0
for i in range(101):
  for j in range(101):
    for l in xyh:
      h = abs(i - l[0]) + abs(j - l[1])
      if l[2] != 0:
        if H == 0:
          H = l[2] + h
        else:
          if l[2] + h != H:
            H = 0
            break
      else:
        if H != 0:
          if H - h > 0:
            H = 0
            break
            
    if H != 0:
      print(i, j, H)
      exit(0)

Measured memory_bytes: 40816
from collections import deque

H,W = list(map(int, input().split()))
S = [input() for _ in range(H)]
dist = [[0] * W for i in range(H)]
dist[0][0] = 1

whites = 0
for s in S:
    for w in s:
        if w == ".":
            whites += 1

# Pythonの再帰はおっっそい. 再帰が今回のケースだと使いにくい(探索打ち切り)
def BFS(cur):
    #global dist
    x_path = [-1,0,1,0]
    y_path = [0,-1,0,1]

    q = deque()
    q.append(cur)
    while True:
        if len(q) == 0:
            break
        cur = q.popleft()
        if cur == (H,W):
            break

        for x,y in zip(x_path, y_path):
            nex = (cur[0] + x, cur[1] + y)
            if nex[0] < 1 or nex[0] > H or nex[1] < 1 or nex[1] > W:
                continue
            if S[nex[0]-1][nex[1]-1] == "#":
                continue
            if dist[nex[0]-1][nex[1]-1] > 0:
                continue

            dist[nex[0]-1][nex[1]-1] = dist[cur[0]-1][cur[1]-1] + 1 
            q.append(nex)


BFS((1,1))
if dist[H-1][W-1] == 0:
    print(-1)
else:
    print(whites - dist[H-1][W-1])


Measured memory_bytes: 3316
#include<bits/stdc++.h>
 using namespace std;
 #define rep(i, c) for(int i = 0; i < (int)c; i++)
 const int inf = 1000000000; // 10^9

 int main() {

 int n;
 int ans = 0;
 cin >> n;
 vector<int> a(n);
 for (int i = 0; i < n; i++)
 {
     cin >> a[i];
 }

 int currMIN = 1e9;
 //lyginam reiksmes
 for (int i = 0; i < n; i++)
 {
     currMIN = min(currMIN, a[i]);//einam per elementus, zinodami iki ju maziausias reiskmes, jeigu a[i] elementas turi didesne reiksme negu currMin, reiskiasi p[i] > p[j]
     if(currMIN == a[i]) ans++;

 }
 cout << ans;

}


Measured memory_bytes: 1024
import java.util.*;
public class Main {
	Scanner in = new Scanner(System.in);
	public static void main(String[] args) {
		new Main();
	}

	public Main(){
		new AOJ1142().doIt();
	}
	
	class AOJ1142{
		String text;
		void solve(){
			HashSet<String> set = new HashSet<String>();
			int n = text.length();
			for(int i=0;i<n;i++){
				StringBuilder t = new StringBuilder(text.substring(0,i));
				StringBuilder t2 = new StringBuilder(text.substring(i,text.length()));
				String a = t.toString() , b = t2.toString(), c = t.reverse().toString(), d = t2.reverse().toString(); 
//				System.out.println(a+" "+b);
//				System.out.println(c+" "+d);
//				HashSet<String> set2 = new HashSet<String>();
//				set2.add(a+b);set2.add(a+d);set2.add(c+b);set2.add(c+d);
//				set2.add(b+a);set2.add(d+a);set2.add(b+c);set2.add(d+c);
//				System.out.println(set2);
				set.add(a+b);set.add(a+d);set.add(c+b);set.add(c+d);
				set.add(b+a);set.add(d+a);set.add(b+c);set.add(d+c);
			}
//			System.out.println(set);
			System.out.println(set.size());
		}
		
		void doIt(){
			int a = in.nextInt();
			for(int i=0;i<a;i++){
				text = in.next();
				solve();
			}
		}
	}
	
}

Measured memory_bytes: 54624
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <cstdint>
#include <cstdio>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <unordered_map>
#include <unordered_set>
#include <bitset>
#include <cctype>
#define ll long long int
#define pb push_back
#define rep(i,n) for(int i=0;i<(n);i++)
#define REP(i,n) for(int i=1;i<=(n);i++)
using namespace std;

int mx8[] = {0,0,1,-1,-1,1,-1,1};
int my8[] = {-1,1,0,0,-1,-1,1,1};
int mx4[] = {1,-1,0,0};
int my4[] = {0,0,-1,1};
const int MOD = 1000000007;

const int D = 60;
const int max_n = 200005;



int main() {
    vector<vector<int>> g(4);
    rep(i,3){
        int a, b; cin >> a >> b;
        a--; b--;
        g[a].pb(b);
        g[b].pb(a);
    }
    int one = 0, two = 0;
    rep(i,4){
        if(g[i].size() == 1) one++;
        else if(g[i].size() == 2) two++;
    }
    if(one == 2 && two == 2) cout << "YES" << endl;
    else cout << "NO" << endl;
}




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

#define ed cout << "\n";
#define speed                         \
    ios_base::sync_with_stdio(false); \
    cin.tie(NULL);                    \
    cout.tie(NULL);
#define ll long long
#define ffor(i, a, b) for (ll i = (ll)(a); i < (ll)(b); ++i)
#define rep(i, n) ffor(i, 0, n)
#define All(obj) (obj).begin(), (obj).end()
#define INF ((ll)1e9 + 7)
#define c(a) cout << a << "\n";
using namespace std;
const int N = 100005;
ll comb(ll a, ll b);
int main()
{
    speed;
    cout << fixed << setprecision(10);
    /*start*/
    int n;
    ll T;
    cin >> n >> T;
    vector<ll> t(n);
    ll ans = 0;
    rep(i, n)
    {
        cin >> t[i];
    }
    ffor(i, 1, n)
    {

        if (t[i] - t[i - 1] > T)
        {
            ans += T;
        }
        else
        {
            ans += t[i] - t[i - 1];
        }
    }
    ans += T;
    c(ans);
    return 0;
}


Measured memory_bytes: 1792
import sys
input = lambda : sys.stdin.readline().rstrip()
sys.setrecursionlimit(max(1000, 10**9))
write = lambda x: sys.stdout.write(x+"\n")


x = input()
s = []
for c in x:
    if c=="T" and s and s[-1]=="S":
        s.pop()
    else:
        s.append(c)
ans = len(s)
print(ans)

Measured memory_bytes: 85888
import java.util.*;


public class Main {
	public static void main(String[] args) {
		Main main = new Main();
		main.run();
	}

	long MOD = 1000000007;
	public void run() {
		Scanner sc = new Scanner(System.in);
		int n=sc.nextInt();

		//文字数 1つ前の文字, 2つ前の文字, 3つ前の文字 -> 条件を満たす文字列の数
		//A=0 C=1 G=2 T=3
		long dp[][][][] = new long[101][4][4][4];

		dp[0][3][3][3] = 1;

		for(int len=0; len<n; len++) {
			for(int c1=0; c1<4; c1++) {
				for(int c2=0; c2<4; c2++) {
					for(int c3=0; c3<4; c3++) {
						if(dp[len][c1][c2][c3]==0) continue;
						for(int nextc=0; nextc<4; nextc++) {
							if(nextc==1 && c1==2 && c2==0) continue;
							if(nextc==1 && c1==0 && c2==2) continue;
							if(nextc==2 && c1==1 && c2==0) continue;
							if(nextc==1 && c2==2 && c3==0) continue;
							if(nextc==1 && c1==2 && c3==0) continue;
							dp[len+1][nextc][c1][c2] += dp[len][c1][c2][c3];
							dp[len+1][nextc][c1][c2] %= MOD;
						}
					}
				}
			}
		}

		long ans = 0;
		for(int c1=0; c1<4; c1++) {
			for(int c2=0; c2<4; c2++) {
				for(int c3=0; c3<4; c3++) {
					ans += dp[n][c1][c2][c3];
					ans %= MOD;
				}
			}
		}
		System.out.println(ans);
		sc.close();
	}



}


Measured memory_bytes: 21460
//package abc117_B;

import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		
		Scanner sc = new Scanner(System.in);
		
		int n = sc.nextInt();
		
		int sum = 0;
		int max = 0;
		
		for (int i = 0; i < n; i++) {
			int l = sc.nextInt();
			sum += l;
			max = Math.max(max, l);
		}
		
		System.out.println((max < sum - max) ? "Yes" : "No");
	}

}

Measured memory_bytes: 21716
#include <bits/stdc++.h>
#include <ext/rope>
#define VALHALLA cin.tie(0);ios_base::sync_with_stdio(false);cout<<fixed<<setprecision(13);
#define endl "\n"
#define pb push_back
#define all(v) v.begin(),v.end()
#define debug(x) std::cerr << #x << ": " << (x) << '\n';
#define sz(x) (int)x.size()
#define fast(map_name) map_name.reserve(1024);map_name.max_load_factor(0.25);
using namespace std;
using namespace __gnu_cxx;
typedef long long int ll;
typedef pair<int,int> ii;
typedef complex<double> point;
const double epsilon=1e-9;
mt19937 rng(chrono::steady_clock::now().time_since_epoch().count());
const int mod=1e9+7;
/* VARIABLE DECLARATION START */
/*  FUCNTION TEMPLATE STARTS  HERE */

double dot(point a,point b){ return (conj(a)*b).real() ; }
double cross(point a,point b){ return (conj(a)*b).imag() ; }
double dist(point a, point b){ return abs(a-b); }
struct neal {
static uint64_t splitmix64(uint64_t x)
 {
    x += 0x9e3779b97f4a7c15;
    x = (x ^ (x >> 30)) * 0xbf58476d1ce4e5b9;
    x = (x ^ (x >> 27)) * 0x94d049bb133111eb;
    return x ^ (x >> 31);
}
size_t operator()(uint64_t x) const
 {
    static const uint64_t FIXED_RANDOM = chrono::steady_clock::now().time_since_epoch().count();
    return splitmix64(x + FIXED_RANDOM);
}
};
struct HASH{
  size_t operator()(const pair<int,int>&x)const{
    return (size_t) x.first * 37U + (size_t) x.second;
  }
};
bool isprime(ll n) {
    if (n == 2 || n == 3) return true;
    if (n < 2 || n % 2 == 0 || n % 3 == 0) return false;
    for (ll i = 6; (i - 1) * (i - 1) <= n; i += 6) {
        if (n % (i - 1) == 0 || n % (i + 1) == 0) {
            return false;
        }
    }
    return true;
}
inline ll exp(ll a, ll b, ll mod) {
    ll n = 1;
    ll p = a;
    while (b > 0) {
        if (b % 2 == 1) {
            n *= p;
            n %= mod;
        }
        p *= p;
        p %= mod;
        b /= 2;
    }
    return n;
}

inline bool comp(double a,double b)
{
  return (fabs(a-b)<epsilon);
}
ll gcd(ll u, ll v) {
  ll r;
  while (0 != v) {
    r = u % v; u = v; v = r;
  }
  return u;
}


/*  FUCNTION TEMPLATE ENDS HERE */
int main()
{
   VALHALLA
   string s1,s2,s3;
   cin>>s1>>s2>>s3;
   map<char,string> m;
   reverse(all(s1));
   reverse(all(s2));
   reverse(all(s3));
   m['a']=s1;m['b']=s2;m['c']=s3;
   char curr='a';
   while(sz(m[curr])!=0)
   {
     string s=m[curr];
     char res=s.back();
     s.pop_back();
     m[curr]=s;
     curr=res;
   }
   cout<<char(curr-32)<<endl;

}


Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int n;
	int a[10];
	cin>>n;
	int sum=0;
	for(int i=0;i<n;i++){
		cin>>a[i];
		sum+=a[i];
	}
	sort(a,a+n);
	cout<<sum-a[n-1]/2<<endl;
}


Measured memory_bytes: 256
import collections
import sys
import numpy as np
sys.setrecursionlimit(1000000000)

n = int(input())
li = []
ans = 0
for i in range(n+1):
    if i%15 == 0:
        continue
    elif i%3 == 0:
        continue
    elif i%5 == 0:
        continue
    else:
        ans += i
print(ans)

Measured memory_bytes: 26960
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <utility>
#include <tuple>
#include <queue>
#include <deque>
#include <map>
#include <set>
#include <cmath>
#include <iomanip>
#include <cassert>
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define ALL(x) (x).begin(), (x).end()
#define SZ(x) (int)(x).size()
using namespace std;
using ll = long long;
constexpr ll INF = 3000000000000000000;

int main() {
    int n, m, v, p;
    cin >> n >> m >> v >> p;
    vector<int> a(n);
    REP(i, n) cin >> a[i];
    
    sort(ALL(a));
    int left = -1, right = n;
    while (right - left > 1) {
        int mid = (right + left) / 2;
        int cnt = 0;
        ll nokori = (ll)(v - 1) * m;
        vector<int> vec;
        REP(i, n) {
            if (i == mid) continue;
            if (a[i] <= a[mid]) {
                nokori -= m;
            } else if (a[mid] + m < a[i]) {
                ++cnt;
                nokori -= m;
            } else {
                vec.push_back(a[i]);
            }
        }
        if (cnt >= p) {
            left = mid;
            continue;
        }
        reverse(ALL(vec));
        REP(i, SZ(vec)) {
            if (i < p - cnt - 1) nokori -= m;
            else nokori -= (a[mid] + m - vec[i]);
        }
        if (nokori > 0) left = mid;
        else right = mid;
    }
    
    cout << n - right << "\n";
    return 0;
}


Measured memory_bytes: 4460
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for( int i = 0 ; i < n ; i++ )
typedef long long ll ;
int main() {
  ll A , B ,C ;
  cin >> A >> B >> C ;
  if(A + B > C ){
    cout << "No" << endl;
    return 0 ;
  }
  //ll ans = C*C - 2*(A + B)*C + A * A + B * B - 2 * A * B ;
  //cout << ans << endl;
  if(C*C - 2*(A + B)*C + A * A + B * B - 2 * A * B > 0 )cout << "Yes" << endl;
  else cout << "No" << endl; 
}

Measured memory_bytes: 256
import java.util.*;

class Main{
	public static void main(String[] args){
		Scanner sc = new Scanner(System.in);
		int a, b, tmp, a2, b2;
		while(sc.hasNext()){
			a2 = a = sc.nextInt();
			b2 = b = sc.nextInt();
			
			a %= b;
			while(a != 0){
				tmp = a;
				a = b;
				b = tmp;
				a %= b;
			}
			System.out.println(b + " " + a2 / b * b2);
		}
	}
}

Measured memory_bytes: 12000
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
int main(){
  int *data;
  int maxv,minv,j,n;

  scanf("%d",&n);
  data=(int *)malloc(sizeof(int)*n);
  for(j=0;j<n;j++){
    scanf("%d",&data[j]);
  }
  maxv=-1*pow(10,9);
  minv=data[0];

  for(j=1;j<n;j++){
    if(maxv<data[j]-minv){
      maxv=data[j]-minv;
    }
    if(minv>data[j]){
      minv=data[j];
    }
  }

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

  return 0;
}



Measured memory_bytes: 2512
#include <bits/stdc++.h>
#define rep(i, n) for(int i=0; i<(n); i++)
#define all(x) (x).begin(), (x).end()
#define bit(x) (1L << (x))
using ll = long long;
using namespace std;

template<typename T>
vector<T> make_v(size_t a,T b){return vector<T>(a,b);}
 
template<typename... Ts>
auto make_v(size_t a,Ts... ts){
        return vector<decltype(make_v(ts...))>(a,make_v(ts...));
}

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

        vector<int> a(n);
        rep (i, n) cin >> a[i];

        // dp[i][j][k] := i番目について、jは選んだ、kは今までに飛ばした数
        auto dp = make_v(n + 10, 2, 3, numeric_limits<ll>::min() / 2);
        dp[0][0][0] = 0;

        rep (i, n) {
                rep (j, 2) rep (k, 3) {
                        dp[i + 1][0][k] = max(dp[i + 1][0][k], dp[i][1][k]);
                        dp[i + 1][1][k] = max(dp[i + 1][1][k], dp[i][0][k] + a[i]);
                }

                rep (k, 2) {
                        dp[i + 1][0][k + 1] = max(dp[i + 1][0][k + 1], dp[i][0][k]);
                }
        }

        if (n % 2 == 0) {
                cout << max(dp[n][0][0], dp[n][1][1]) << endl;
        } else {
                cout << max(dp[n][0][1], dp[n][1][2]) << endl;
        }

        return 0;
}


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

int main() {
	
	int a[100],n;
	cin>>n;
	
	for(int i=0; i<n; i++){
		cin>>a[i];
	}
	
	int sw = 0;

	for(int i=0; i<n ; i++){
		int minj = i;
		for(int j=i; j<n; j++){
			if(a[minj]>a[j]){
				minj = j;
			}
		}
		if(i != minj){
			swap(a[i],a[minj]);
			sw++;
		}
	}
	
	for(int i=0; i<n ; i++){
		if(i) cout<<" ";
		cout<<a[i];
	}
	cout<<endl;
	cout<<sw<<endl;
	
	return 0;
}

Measured memory_bytes: 1160
#if 0
date +%Y.%m.%d

题解先咕着。
#endif
#include <cstdio>
#include <algorithm>
#include <vector>
#define debug(...) fprintf(stderr, __VA_ARGS__)

typedef long long ll;

struct {
	inline operator int () { int x; return scanf("%d", &x), x; }
	inline operator ll () { ll x; return scanf("%lld", &x), x; }
	template<class T> inline void operator () (T &x) { x = *this; }
	template<class T, class ...A> inline void operator () (T &x, A &...a)
	{ x = *this; this -> operator ()(a...); }
} read;

const int maxn = 300005;
int al[maxn], ar[maxn];
std::vector<int> tor[maxn];

struct Tree {
	int lti, rti;
	int val;
};
#define self pool[now]
#define lt pool[self.lti]
#define rt pool[self.rti]
Tree pool[maxn * 20];
int pp;

void lain(int &now, int L, int R, int p) {
	pool[++ pp] = self;
	now = pp;
	/* debug("%d %d %d %d\n", now, L, R, p); */
	++ self.val;
	if(L == R) return;
	int M = (L + R) >> 1;
	if(p <= M) lain(self.lti, L, M, p);
	else lain(self.rti, M + 1, R, p);
}

int query(int now, int L, int R, int l, int r) {
	if(!now or r < L or l > R) return 0;
	if(l <= L and R <= r) return self.val;
	int M = (L + R) >> 1;
	return query(self.lti, L, M, l, r) + query(self.rti, M + 1, R, l, r);
}

int T[maxn];

int main() {
	int n = read, m = read;

	for(int i = 1; i <= n; i ++) {
		read(al[i], ar[i]);
		tor[al[i]].push_back(ar[i]);
	}

	for(int l = 0; l <= m; l ++) {
		if(l) T[l] = T[l - 1];
		for(int r : tor[l])
			lain(T[l], 0, m, r);
	}

	for(int d = 1; d <= m; d ++) {
		int ans = 0;
		for(int t = 0; t <= m / d; t ++) {
			int l = t * d + 1, r = t * d + d;
			/* for(int i = 1; i <= n; i ++) */
			/* 	if(l <= al[i] and al[i] <= r and ar[i] >= r) */
			/* 		++ ans; */
			ans += query(T[r], 0, m, r, m) - query(T[l - 1], 0, m, r, m);
		}
		printf("%d\n", ans);
	}
}


Measured memory_bytes: 77568
#include <stdio.h>
#include <stdlib.h>
#include <stdbool.h>
#include <math.h>
#include <string.h>

int main(void){
    int i,j,k;
    int N,answer = 0,temp = 10;
    
    scanf("%d",&N);
   
    if(N < 10){
        printf("%d\n",N);
    }else if(N < 100){
        printf("%d\n",9);
    }else if(N < 1000){
        printf("%d\n",9 + N - 99);
    }else if(N < 10000){
        printf("%d\n",9 + 999 - 99);
    }else if(N < 100000){
        printf("%d\n",9 + 999 - 99 + N - 9999);
    }else{
        printf("%d\n",9 + 999 - 99 + 99999 - 9999);
    }
    
    return 0;
}



Measured memory_bytes: 128
# Python3 (3.4.3)
import sys
input = sys.stdin.readline

# -------------------------------------------------------------
# function
# -------------------------------------------------------------


# -------------------------------------------------------------
# main
# -------------------------------------------------------------
N = int(input())
H = list(map(int,input().split())) + [10**9+1]

ans = 0
cnt = 0
for i in range(N):
    if H[i] >= H[i+1]:
        cnt += 1
    else:
        ans = max(ans,cnt)
        cnt = 0

print(ans)

Measured memory_bytes: 14168
#include <bits/stdc++.h>
#define rep(i, n) for(long long int i = 0; i < n; i++)
#define _rep(i, m, n) for(long long int i = m; i < n; i++)
#define print(n) std::cout << n << std::endl
#define _print(n) std::cout << n
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
const int N = 1000000;
const ll mod = 1000000007;
using Graph = vector<vector<int>>;
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

ll gcd(ll A, ll B){
    if(B == 0)return A;
    return gcd(B, A % B);
}
ll lcm(ll A, ll B){
    return A * B / gcd(A, B);
}

/*------------------------------------------------------------------*/


int main(){
    int h, w; cin >> h >> w;
    string s[h][w];
    rep(i, h)rep(j, w)cin >> s[i][j];
    rep(i, h){
        char c = 'A';
        rep(j, w){
            if(s[i][j] == "snuke"){
                cout << c << i + 1 << endl;
            }
            c++;
        }
    }    
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
#define fin ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define ii pair<int,int>
#define F first
#define S second
#define pb push_back
#define pf push_front
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
#define fore(i,a,b) for(int i = a;i < b; i+= 1)
#define forr(i,a) for(int i = a; i >= 0; i--)
#define fori(i,m) for(auto i = m.begin(); i != m.end(); i++) 
#define w(t) while(t--)
#define sz(s) int(s.size())
#define cls(a,car) memset(a,car,sizeof (a))
#define what_is(x) cerr << #x << " is " << x << endl;
using namespace std;
typedef long long ll;
typedef vector<int> vi;
typedef vector<ii> vii;
const int N = 1 * 1e5 + 5;
const ll mod = 1e9 + 7;
const int INF = INT_MAX;
const ll INFCAD  = ll(INT_MAX) * 2 + 1;
const double E = 1e-9;
// fflush(stdout)
// cout << flush
// a + b = a ^ b + 2 * (a & b)
int main(){
    //freopen("in","r",stdin);
    //freopen("out","w",stdout);
    fin;
    string  s;
    cin >> s;
    int n = 0;
    fore(i, 0, sz(s))
        if(s[i] == '+')
            n++;
        else n--;
        cout << n << '\n';
    cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    return 0;
}   

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

int main(){
    int n, k;
    cin >> n >> k;
    int h[n]; rep(i,n) cin >> h[i];

    int count = 0;
    rep(i,n){
        if(h[i] >= k){
            count++;
        }
    }
    cout << count << endl;
    return 0;
}

Measured memory_bytes: 640
#include <iostream>


using namespace std;


//1 * 4 or 2 * 2 网上思路
int main() {
	int n;
	scanf("%d", &n);
	int four = 0;
	int two = 0;
	int one = 0;
	int temp;
	while (n--) {
		scanf("%d", &temp);
		if(temp % 4 == 0) {
			four++;
		} else if(temp % 2 == 0) {
			two++;
		} else {
			one++;
		}
	}

	if(one > four + 1 || (one == four + 1 && two > 0)) {
		printf("No");
	} else {
		printf("Yes");
	}


	return 0;
}

Measured memory_bytes: 384