akhauriyash/Code-Regression huggingface dataset:
#include<bits/stdc++.h>
using namespace std;
typedef int64_t ll;
typedef long double ld;
const ll MOD=1000000007;
#define rep(i,n) for(ll i=0;i<(ll)(n);i++)
#define change(a,b) do{ll c=a; a=b; b=c;}while(0)
long long gcd(long long a,long long b){
    ll gcdmax=max(a,b);
    ll gcdmin=min(a,b);
    while(true){
        if(gcdmax%gcdmin==0)break;
        else gcdmax%=gcdmin;
        change(gcdmin,gcdmax);
    }
    return gcdmin;
}
ll powerup(ll N,ll P,ll M){
    if(P==0)return 1;
    else if(P%2==0){
        ll t=powerup(N,P/2,M);
        return t*t%M;
    }
    else return N*powerup(N,P-1,M)%M;
}
int main()
{
  ld N;
  cin>>N;
  cout<<setprecision(14)<<N*N*N/27<<endl;
}

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

#define rep(i, n) for (int i = 0; i < (n); i++)
using namespace std;
typedef long long ll;
const int INF = 1e9;

int main() {
  ll a, b, c, k;
  cin >> a >> b >> c >> k;
  ll ua, ub, uc;
  ua = min(k, a);
  k -= ua;
  ub = min(b, k);
  k -= ub;
  uc = min(k, c);
  ll ans = ua - uc;

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


Measured memory_bytes: 3632
#include <vector>
#include <iostream>
#include <utility>
#include <algorithm>
#include <string>
#include <deque>
#include <queue>
#include <tuple>
#include <queue>
#include <functional>
#include <cmath>
#include <iomanip>
#include <map>
#include <set>
#include <numeric>
#include <unordered_map>
#include <unordered_set>
#include <complex>
#include <iterator>
#include <array>
#include <memory>
#include <stack>
#define vi vector<int>
#define vvi vector<vector<int> >
#define ll long long int
#define vl vector<ll>
#define vvl vector<vector<ll>>
#define vb vector<bool>
#define vc vector<char>
#define vs vector<string>
#define ld long double
#define INF 1e9
#define EPS 0.0000000001
#define rep(i,n) for(int i=0;i<n;i++)
#define loop(i,s,n) for(int i=s;i<n;i++)
#define all(in) in.begin(), in.end()
template<class T, class S> void cmin(T &a, const S &b) { if (a > b)a = b; }
template<class T, class S> void cmax(T &a, const S &b) { if (a < b)a = b; }
#define MAX 9999999
using namespace std;
typedef pair<int, int> pii;
typedef pair<double,double>pdd;
typedef pair<ll,ll>pll;
int main(){
    int n;cin>>n;
    int ans=0;
    rep(_,n){
        int a,b,c,d; cin>>a>>b>>c>>d;
        int temp=0;
        if(c>=5&&d>=2)temp=0.8*(a*c+b*d);
        else {
            temp=(a*c+b*d);
            int t=c,u=d;
            if(t<5)t=5;
            if(u<2)u=2;
            cmin(temp,0.8*(a*t+b*u));
        }
        cout<<temp<<endl;
    }
}

Measured memory_bytes: 3100
#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>
#include <numeric>
#include <cmath>

#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;


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

    vector<ll> l(n);
    rep(i,n) cin >> l[i];

    int cnt = 0;
    for(int i = 0; i < n-2; i++) {
        for (int j = i + 1; j < n - 1; j++) {
            for (int k = j + 1; k < n; k++) {
                if (l[i] + l[j] > l[k] && l[j] + l[k] > l[i] &&
                    l[i] + l[k] > l[j] && l[i] != l[j] && l[j] != l[k]
                    && l[i] != l[k]) {
                    cnt++;
                }
            }
        }
    }
    cout << cnt << endl;
}

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

typedef unsigned long long int ll; 
#define MOD 1000000007
#define rep(i,n) fp(i,0,n)  
#define fp(i,a,b) for(ll i=(a);i<(b);++i)
#define fn(i,a,b) for(ll i=(a);i>(b);i--)
#define MS0(X) memset((X), 0, sizeof((X)))
#define MS1(X) memset((X), -1, sizeof((X)))
#define ff first
#define ss second
typedef pair<ll, ll> pll; 
typedef vector<pll> vpll;
typedef vector<ll> vll;
#define rs(t) string t;cin>>t
#define ri(t) int t;cin>>t
#define rll(t) long long int t;cin>>t
#define mk make_pair
#define pb push_back
#define po pop_back




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

  int n;
  cin >> n;
  vector <long long> v(n);
  rep(i,n){
  	cin >> v[i];
  }
  
  int ans = 0;
  for(int i=n-1;i>=0;i--){
  	int mv = 0;
  	int j=i-1;
  	while(j>=0 && v[j]>=v[i]){
  		j--;
  		i--;
  		mv++;
  	}
  	ans = max(mv,ans);

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

Measured memory_bytes: 1024
from collections import Counter

H, W, N, *AB = map(int, open(0).read().split())

move = [
    (-1, -1), (-1, 0), (-1, 1),
    (0, -1),  (0, 0),  (0, 1),
    (1, -1),  (1, 0),  (1, 1),
]

C = Counter()
for a, b in zip(*[iter(AB)] * 2):
    for i, j in move:
        if 2 <= a - i <= H - 1 and 2 <= b - j <= W - 1:
            C[(a - i, b - j)] += 1

D = Counter(v for _, v in C.items())

print((H - 2) * (W - 2) - sum(D.values()))
for i in range(1, 10):
    print(D[i])


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

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

    string s;
    cin >> s;

    if(s[2] == s[3] and s[4] == s[5]){
        cout << "Yes" << endl;
    }else{
        cout << "No" << endl;
    }

    return 0;
}

Measured memory_bytes: 256
#include <iostream>
#include <cstdio>
#define N 100005
using namespace std;

typedef long long ll;
ll n, x, c, a[N];
int main()
{
	ll i;
	cin >> n >> x;
	for (i = 0; i < n; i++) scanf("%lld", &a[i]);
	if (a[0] > x) c = a[0] - x, a[0] = x;
	for (i = 1; i < n; i++) {
		c += max(0LL, a[i] - x + a[i - 1]);
		a[i] = min(a[i], x - a[i - 1]);
	}
    cout << c << endl;
    return 0;
}

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

using namespace std;
typedef long long ll;

const int N = 1007, M = 1e9 + 7;

char mat[N][N];


int memo[N][N];
int n, m;

int solve(int i, int j) {
    if(i == n-1 and j == m-1) return 1;
    if(i >= n or j >= m) return 0;

    if(mat[i][j] == '#') return 0;
    
    int & st = memo[i][j];
    if(st == -1) {
        st = solve(i+1, j) + solve(i, j+1);
        st %= M;
    }
    return st;
}

int main() {
    memset(memo, -1, sizeof memo);
    cin >> n >> m;

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

    cout << solve(0, 0) << endl;
}

Measured memory_bytes: 5248
// tested on node version 0.10.36
var fs = require("fs");

function shark_week(n) {
    var loan = 100;
    for(var i = 0; i < n; i++) {
        loan = Math.ceil(loan * 1.05);
    }
    return loan * 1000;
}

var input = fs.readFileSync('/dev/stdin').toString().trim();
console.log(shark_week(parseInt(input)));

Measured memory_bytes: 15336
<?php

fscanf(STDIN, "%d %d %d %d", $a, $b, $c, $k);

if($k - $a > 0){
	$number = 1*$a;
  	$k -= $a;
}else{
 	echo 1 * $k;
    return;
}
if ($b > 0){
	$number += 0;
    $k -= $b;
  if($k < 0){
  	echo $number;
    return;
  }
}
$number += -1*$k;
echo $number;

Measured memory_bytes: 16024
import re  # 正規表現, findall('正規表現', 文字列), search('正規表現', 文字列)
import sys # プログラム終了：sys.exit()
# sys.setrecursionlimit(10**6) # 再帰呼び出しの上限を上げる

def i_input(): return int(input())
def s_input(): return map(int,input().split())
def l_input(): return list(map(int, input().split()))
# 文字列のまま受け取りたいときはinput()

def main():
    N = i_input()
    T, X, Y = [], [], []
    for _ in range(N):
        t, x, y = s_input()
        T.append(t)
        X.append(x)
        Y.append(y)

    pre_t, pre_x, pre_y = 0, 0, 0
    for i in range(N):
        now_t, now_x, now_y = T[i], X[i], Y[i]
        time = now_t - pre_t
        x_diff = abs(now_x - pre_x)
        y_diff = abs(now_y - pre_y)

        if time >= x_diff + y_diff and\
            (time - x_diff - y_diff) % 2 == 0:
            pre_t, pre_x, pre_y = now_t, now_x, now_y
        else:
            print('No')
            sys.exit()
    
    print('Yes')

if __name__ == "__main__":
    main()

Measured memory_bytes: 65496
#![allow(unused_imports)]
#![allow(unused_macros)]
#![allow(non_snake_case)]
#![allow(dead_code)]
#![allow(unused_variables)]
#![allow(unused_mut)]
#![allow(unused_assignments)]
use proconio::input;
use proconio::marker::Usize1;
use std::collections::*;
use std::cmp::*;
use std::f64::consts::*;

const MOD: u64 = 1000000007;
const INF: usize = std::usize::MAX / 4;

fn main() {
    input! {
        S: String,
    }

    let A: Vec<u32> = S.chars().filter_map(|s| s.to_digit(10)).collect();

    let M: u32 = 2019;
    let mut cnt: Vec<u32> = vec![0; M as usize];
    let mut ans: u32 = 0;
    let mut cum: u32 = 0;
    let mut pwd: u32 = 1;

    cnt[0] = 1;
    for &a in A.iter().rev() {
        cum = (cum + pwd * a) % M;
        ans += cnt[cum as usize];
        cnt[cum as usize] += 1;
        pwd = pwd * 10 % M;
    }

    println!("{}", ans);
}


Measured memory_bytes: 3304
#include<bits/stdc++.h>
#pragma GCC optimize("Ofast")
using namespace std;
#define all(x) (x).begin(),(x).end()
typedef long long ll;
#define rep(i,n) for(ll i=0, i##_len=(n); i<i##_len; ++i)
#define REP(i,num,n) for(ll i=num, i##_len=(n); i<i##_len; ++i)
template<class T>bool chmax(T &a, const T &b) { if (a<b) { a=b; return 1; } return 0; }
template<class T>bool chmin(T &a, const T &b) { if (b<a) { a=b; return 1; } return 0; }
#define print(x) cout << (x) << endl;
#define sz(x) int(x.size())
 
ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
const ll LLINF = 1LL<<60;
const int INF = 1<<29;
const int MOD = 1000000007;
 
void add(long long &a, long long b) {
  a += b;
  if (a >= MOD) a -= MOD;
}
 
const int dx[8] = {1, 0, -1, 0, 1, -1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, 1, -1, -1};

ll dp[100100];

int main(void){
    cin.tie(0);
    ios::sync_with_stdio(false);
    cout<<fixed<<setprecision(10);
    ll N;
    cin >> N;
    vector<ll> h(N);
    rep(i,N) cin >> h[i];
    REP(i,1,100100) dp[i] = LLINF;
    dp[0] = 0;
    rep(i,N-1){
      chmin(dp[i+1], dp[i] + abs(h[i+1] - h[i]));
      chmin(dp[i+2], dp[i] + abs(h[i+2] - h[i]));
    }
    print(dp[N-1]);
}


Measured memory_bytes: 1792
import java.util.*;
import java.util.stream.IntStream;
import java.util.concurrent.TimeUnit;
import java.util.concurrent.CountDownLatch;

public class Main{
    
    static final int SLEEP_TIME = 17;
    
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        
        int n = Integer.parseInt(sc.next());
        int[] d = new int[n];
        for(int i=0; i<n; i++){
            d[i] = Integer.parseInt(sc.next());
        }
        
        final CountDownLatch latch = new CountDownLatch(d.length+1);
        final Count c = new Count();
        
        for(final int num : d){
            new Thread(new Runnable(){
                public void run(){
                    try{
                        TimeUnit.MILLISECONDS.sleep(num*SLEEP_TIME);
                        synchronized(c){
                            c.flagUp();
                        }
                    }catch(InterruptedException e){
                        //e.printStackTrace();
                    }finally{
                        latch.countDown();
                    }
                }
            }).start();
        }
        
        new Thread(new Runnable(){
            public void run(){
                try{
                    for(int i=0; i<103; i++){
                        c.countUp();
                        TimeUnit.MILLISECONDS.sleep(SLEEP_TIME);
                    }
                }catch(InterruptedException e){
                    //e.printStackTrace();
                }finally{
                    latch.countDown();
                }
            }
        }).start();
        
        
        try{
            latch.await();
        }catch(InterruptedException e){
            e.printStackTrace();
        }
        
        System.out.println(c.getResult());
    }
}

class Count{
    int cnt;
    boolean flag;
    
    public Count(){
        cnt = 0;
        flag = false;
    }
    
    public void flagUp(){
        flag = true;
    }
    
    public void countUp(){
        if(flag){
            cnt++;
            flag = false;
        }
    }
    
    public int getResult(){
        return cnt;
    }
}


Measured memory_bytes: 39108
#include<stdio.h>

int l,r,h;

void buildmaxHeap(int T[]){
  for(int i=h/2;i>=1;i--)maxHeapify(T,i);
}

void maxHeapify(int T[],int i){
  int tem,lar;
  l=i*2;
  r=i*2+1;

  if(l<=h && T[l]>T[i])lar = l;
  else lar = i;
if(r<=h && T[r]>T[lar])lar = r;
  if(lar != i){
    tem=T[lar];
    T[lar]=T[i];
    T[i]=tem;
    maxHeapify(T,lar);
  }
}

  int main(){
    int i,k;
    scanf("%d",&h);
    int T[h+1];
    for(i=1;i<h+1;i++){
      scanf("%d",&k);
      T[i]=k;
    }

    buildmaxHeap(T);

    for(i=1;i<h+1;i++)printf(" %d",T[i]);
    printf("\n");
      return 0;
    }



Measured memory_bytes: 3656
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <string>
using namespace std;

int main(){
	string s1,s2;
	cin >> s1 >> s2;
	
	//d[i][j]:=文字列s1の1文字目~i文字目までの部分文字列と文字列s2の1文字目~j文字目までの部分文字列の編集距離
	//(indexが0の部分は空の文字列を表す)
	int d[1001][1001]={0};
	
	//どちらかの長さが0なら、その時は挿入か削除を続けるのが最適
	for(int i=0; i<=s1.size(); ++i) d[i][0]=i;
	for(int i=0; i<=s2.size(); ++i) d[0][i]=i;
	
	for(int i=1; i<=s1.size(); ++i){
		for(int j=1; j<=s2.size(); ++j){
			int tmp = d[i-1][j-1];
			if(s1[i-1]!=s2[j-1]) tmp++;
			
			d[i][j] = min(tmp, min(d[i-1][j]+1,d[i][j-1]+1));
		}
	}
	
	printf("%d\n", d[s1.size()][s2.size()]);
}


Measured memory_bytes: 7256
#include<iostream>
#include<vector>
#include<algorithm>
using namespace std;
int d[50][50], p[50][50], M, n, m;
vector<int>dp[50][50]; int g[50][50];
bool Dainari(vector<int>a, vector<int>b) {
	if (a.size() < b.size())return true;
	if (b.size() > a.size())return false;
	for (int i = 0; i < a.size(); i++) {
		if (a[i] < b[i])return true;
		if (a[i] > b[i])return false;
	}
	return false;
}
int main() {
	cin >> n >> m; int S = 0;
	for (int j = 0; j < n; j++) {
		 for (int i = 0; i < m; i++) { cin >> d[i][j]; M = min(M, d[i][j]); }
	}
	for (int i = 0; i < m; i++) {
		M = 1 << 30; for (int j = 0; j < n; j++) { M = min(d[i][j], M); }
		for (int j = 0; j < n; j++) { if (d[i][j] == M)p[i][j] = 1; }S += M;
	}
	for (int i = 0; i < 50; i++) { for (int j = 0; j < 50; j++)g[i][j] = 1 << 30; }
	for (int i = 0; i < n; i++) { if (p[0][i] == 1) { dp[0][i].push_back(i); g[0][i] = 0; } }
	for (int i = 1; i < m; i++) {
		for (int j = 0; j < n; j++) {
			if (p[i][j] == 0)continue;
			for (int k = 0; k < n; k++) {
				if (p[i - 1][k] == 0)continue;
				vector<int>D = dp[i - 1][k]; D.push_back(j); int L = 1; if (j == k)L = 0;
				if (g[i - 1][k] + L < g[i][j]) { g[i][j] = g[i - 1][k] + L; dp[i][j] = D; }
				else if (g[i - 1][k] + L == g[i][j] && Dainari(D, dp[i][j])) dp[i][j] = D;
			}
		}
	}
	vector<pair<int, vector<int> > >X;
	for (int i = 0; i < n; i++) { X.push_back(make_pair(g[m - 1][i], dp[m - 1][i])); }
	sort(X.begin(), X.end()); vector<int>Y = X[0].second; cout << S << ' ' << X[0].first << endl;
	for (int i = 0; i < m; i++) cout << Y[i] + 1 << endl;
	return 0;
}

Measured memory_bytes: 1612
import java.util.Scanner;

//Square
public class Main {

	public static int[] a;

	public static void dfs(int k, int rest, int left){
		if(rest < 0)return;
		if(rest == 0){
			for(int i=0;i<k-1;i++){
				System.out.print(a[i] + " ");
			}
			System.out.println(a[k-1]);
			return;
		}
		for(int i=left;i>=1;i--){
			a[k] = i;
			dfs(k+1, rest-i, i);
		}
	}

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		while(true){
			int n = sc.nextInt();
			if(n==0)break;
			a = new int[30];
			dfs(0, n, n);
		}
	}
}

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

const int MOD = 1e9+7;
const int MAX_N = 21;
int N;
int a[MAX_N][MAX_N];
ll dp[MAX_N][1<<MAX_N];

ll dfs(int x, int f)
{
	if(x == N){
		if(f == ((1<<N)-1)) return 1;
		else return 0;
	}
	ll& res = dp[x][f];
	if(res != -1) return res;
	res = 0;
	for(int i=0;i<N;++i)if(a[x][i]&&!(f>>i&1)){
		(res += dfs(x+1,f|(1<<i)))%=MOD;
	}
	return res;
}

void solve()
{
	memset(dp, -1, sizeof(dp));
	ll ans = dfs(0, 0);
	cout << ans << '\n';
} 

int main()
{
	cin >> N;
	for(int i=0;i<N;++i)for(int j=0;j<N;++j){
		cin >> a[i][j];
	}
	solve();
	return 0;
}

Measured memory_bytes: 344320
#include <bits/stdc++.h>
typedef long long ll;
#define INF 1000000000
using namespace std;
int main(void){
    int n;
    string s;
    cin>>n>>s;
    bool zen[26]={false};
    int ans=0;
    for(int i=1;i<n;i++){
        int tmp=0;
        zen[s[i-1]-'a']=true;
        bool al[26]={false};
        for(int j=i;j<n;j++){
            if(zen[s[j]-'a']==true&al[s[j]-'a']==false){
                tmp++;
                al[s[j]-'a']=true;
            }
        }
        if(tmp>ans){
            ans=tmp;
        }
    }
    cout<<ans<<endl;

}

Measured memory_bytes: 256
<?php

class Scanner
{
    private $arr = [];
    private $count = 0;
    private $pointer = 0;

    /**
     * @return mixed
     */
    public function next() {
        if ($this->pointer >= $this->count) {
            $str = trim(fgets(STDIN));
            $this->arr = explode(' ', $str);
            $this->count = count($this->arr);
            $this->pointer = 0;
        }
        $result = $this->arr[$this->pointer];
        $this->pointer++;
        return $result;
    }

    /**
     * @return bool
     */
    public function hasNext() {
        return $this->pointer < $this->count;
    }

    /**
     * @return int
     */
    public function nextInt() {
        return (int)$this->next();
    }

    /**
     * @return float
     */
    public function nextDouble() {
        return (double)$this->next();
    }
}

/**
 * 優先度付きキュー(低い方が優先度高)
 * Class DijkstraPriorityQueue
 */
class DijkstraPriorityQueue extends SplPriorityQueue
{
    public function compare($priority1, $priority2) {
        if ($priority1 === $priority2) {
            return 0;
        }
        return $priority1 < $priority2 ? 1 : -1;
    }     
}



// 初期化
$sc = new Scanner();
$n = $sc->nextInt();
$nodeCostList = array();
$edgeList = array();
$fixedList = array();
foreach (range(0,$n-1) as $lineNum) {
    $u = $sc->nextInt();
    $nodeCostList[$u] = INF;
    
    $k = $sc->nextInt();

    foreach (range(0, $k-1) as $setNum) {
        $v = $sc->nextInt();
        $c = $sc->nextInt();
        $edgeList[$u][$v] = $c;
    }
}


$nodeCostList[0] = 0;

$result = array();

$result[0] = 0;
$pQueue = new DijkstraPriorityQueue();
$pQueue->insert(0,0);


while (!$pQueue->isEmpty()) {
    // 全ノード確定したら抜ける
    if (count($result) >= $n) {
        break;
    }
    
    $targetNode = $pQueue->extract();
    // 距離確定させる
    $result[$targetNode] = $nodeCostList[$targetNode];
    
    // 対象ノードと繋がっているノードごと
    foreach ($edgeList[$targetNode] as $adjNode => $cost) {
        // 確定済みは見ない
        if (isset($result[$adjNode])) {
            continue;
        }
        
        // 今のコストより短ければ更新
        if ($nodeCostList[$targetNode] + $cost < $nodeCostList[$adjNode]) {
            $nodeCostList[$adjNode] = $nodeCostList[$targetNode] + $cost;
            $pQueue->insert($adjNode, $nodeCostList[$adjNode]);
        }
    }
}

ksort($result);
foreach ($result as $node=>$resultCost) {
    echo $node . ' ' . $resultCost . "\n";
}





Measured memory_bytes: 83820
#include<bits/stdc++.h>
using namespace std;
int calc(int a,int k){
	//cout<<a<<" "<<k<<endl;
	if(a < k) return 0;
	if(a % k == 0) return a / k;
	int tmp = a / k + 1,t2 = a / k * k;
	int t3 = a % tmp,t4 = t2 % tmp;
	int t5 = t4 - t3;
	if(t5 < 0) t5 += tmp;
	return calc(t2 - t5,k);
}
int main(){
	int ans = 0,n,i,a,k;
	scanf("%d",&n);
	for(i = 1;i <= n;++i){
		scanf("%d%d",&a,&k);
		ans ^= calc(a,k);
		//cout<<calc(a,k)<<endl;
	}
	if(ans) puts("Takahashi");
	else puts("Aoki");
	return 0;
}

Measured memory_bytes: 256
#include <queue>
#include <stdio.h>
#include <vector>

using namespace std;

#define NMAX 100
#define INF -1
#define NIL -1

int n;
int d[NMAX + 1]; // distance, 1-origin
vector<int> adj[NMAX + 1];
queue<int> Q;

int next_unvisited_adj(int u) {
    vector<int>::iterator it;
    for (it = adj[u].begin(); it != adj[u].end(); it++) {
        if (d[*it] == INF)
            return *it;
    }
    return NIL;
}

void bfs(int x) {
    d[x] = 0;
    Q.push(x);
    int u, v;
    while (!Q.empty()) {
        u = Q.front();
        Q.pop();
        while ((v = next_unvisited_adj(u)) != NIL) {
            d[v] = d[u] + 1;
            Q.push(v);
        }
    }
}

int main() {
    scanf("%d", &n);
    int u, k, v;
    for (int i = 1; i <= n; i++) {
        d[i] = INF;
        scanf("%d %d", &u, &k);
        for (int j = 0; j < k; j++) {
            scanf("%d", &v);
            adj[u].push_back(v);
        }
    }
    bfs(1);
    for (int i = 1; i <= n; i++)
        printf("%d %d\n", i, d[i]);
    return 0;
}


Measured memory_bytes: 2800
import java.util.Scanner;

public class Main {
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		int n = sc.nextInt();
		int x = sc.nextInt();
		int point = 0;
		int res = 1;
		for(int i = 0; i < n; i++) {
			point += Integer.parseInt(sc.next());
			if(x < point) break;
			res++;
		}
		System.out.println(res);
	}
}

Measured memory_bytes: 24020
// Many Easy Problems
// * frank_c1
// * 2017 / 09 / 29
 
#include <bits/stdc++.h>
using namespace std;
typedef long long LL;

LL pow_mod(LL b, LL p, LL k) {
	LL ret = 1;
	for (; p; p >>= 1) {
		if (p & 1) ret = ret * b % k;
		b = b * b % k;
	} return ret;
}

const int maxn = (int)(1e6) + 5;
const int mo = 924844033;
const int gi = 5;
int cnt[maxn], siz[maxn];
LL f[maxn], g[maxn], fac[maxn], ivf[maxn];
vector<int> nxt[maxn];
int n;

inline LL C(int n, int m) {
	if (m < 0 || n - m < 0) return 0;
	return (fac[n] * ivf[m] % mo) * ivf[n - m] % mo;
}

void dfs(int x, int f) {
	siz[x] = 1;
	for (int i = 0; i < (int)nxt[x].size(); ++i) if (nxt[x][i] != f) {
		dfs(nxt[x][i], x); siz[x] += siz[nxt[x][i]];
	} if (f) {
		++cnt[siz[x]]; ++cnt[n - siz[x]];
	}
}

void NTT(LL a[], int n, int d = 1) {
	for (int i = (n >> 1), j = 1; j < n; ++j) {
		if (i < j) swap(a[i], a[j]);
		int k; for (k = (n >> 1); i & k; i ^= k, k >>= 1);
		i ^= k;
	}
	for (int m = 2; m <= n; m <<= 1) {
		LL w = pow_mod(gi, (d * ((mo - 1) / m) + mo - 1) % (mo - 1), mo);
		for (int i = 0; i < n; i += m) {
			LL s = 1;
			for (int j = i; j < i + (m >> 1); ++j) {
				LL u = a[j], v = a[j + (m >> 1)] * s % mo;
				a[j] = (u + v) % mo; a[j + (m >> 1)] = (u - v + mo) % mo;
				s = s * w % mo;
			}
		}
	} 
	if (d == -1) {
		LL xinv = pow_mod(n, mo - 2, mo);
		for (int i = 0; i < n; ++i) a[i] = a[i] * xinv % mo;
	}
}

int main() {
	scanf("%d", &n);
	fac[0] = ivf[0] = 1;
	for (int i = 1; i <= n; ++i) fac[i] = fac[i - 1] * i % mo;
	ivf[n] = pow_mod(fac[n], mo - 2, mo);
	for (int i = n - 1; i >= 1; --i) ivf[i] = ivf[i + 1] * (i + 1) % mo;
	for (int i = 1; i < n; ++i) {
		int u, v; scanf("%d%d", &u, &v);
		nxt[u].push_back(v); nxt[v].push_back(u);
	} dfs(1, 0);
	int len = 0;
	while ((1 << len) <= (n << 1)) ++len;
	for (int i = 0; i < n; ++i) f[i] = ivf[i];
	for (int i = 1; i <= n; ++i) g[n - i + 1] = fac[i] * cnt[i] % mo;
	NTT(f, 1 << len); NTT(g, 1 << len);
	for (int i = 0; i < (1 << len); ++i) f[i] = f[i] * g[i] % mo;
	NTT(f, 1 << len, -1);
	for (int i = 1; i <= n; ++i) printf("%lld\n", (n * C(n, i) + f[n - i + 1] * (mo - ivf[i])) % mo);
 	return 0;
}

Measured memory_bytes: 70784
import java.util.*;
public class  Main{
public static void main(String[] args) {
        int x;
        Scanner in = new Scanner(System.in);
        x=in.nextInt();
        if(x>=30)
        {
            System.out.println("Yes");
        }
        else{
            System.out.println("No");
        }

    }
}

Measured memory_bytes: 35820
N = int(input())
ds = set()
m = 1
while m*m <= N:
    if N%m==0:
        ds.add(m)
        ds.add(N//m)
    m += 1

ans = 999
for d in ds:
    e = N//d
    t = max(len(str(d)) ,len(str(e)))
    ans = min(ans, t)
print(ans)

Measured memory_bytes: 9096
#include <bits/stdc++.h>
using namespace std;
#define int long long
#define REP(i, n) for (long long i = 0, max_i = (n); i < max_i; i++)
#define REPI(i, a, b) for (long long i = (a), max_i = (b); i < max_i; i++)
#define ALL(obj) begin(obj), end(obj)
#define RALL(obj) rbegin(obj), rend(obj)
#define fi first
#define se second
using ii = pair<int, int>;
vector<ii> dirs = {
  {1, 0}, {0, 1}, {-1, 0}, {0, -1},  // 4方向
  {1, 1}, {-1, 1}, {-1, -1}, {1, -1},  // 斜め
  {0, 0},  // 自身
};
template <class T> inline bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template <class T> inline bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

// debug
template <class T> ostream& operator<<(ostream &s, vector<T>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : " "); return s; }
template <class T> ostream& operator<<(ostream &s, vector<vector<T>>& d) { REP (i, d.size()) s << d[i] << (i == d.size() - 1 ? "" : "\n"); return s; }
template <class T, class S> ostream& operator<<(ostream &s, pair<T, S>& p) { s << "{" << p.first << ", " << p.second << "}"; return s; }
template <class T, class S> ostream& operator<<(ostream& s, map<T, S> m) { for (auto it = m.begin(); it != m.end(); it++) { s << *it << (next(it) == m.end() ? "" : "\n"); } return s; }
#ifdef _MY_DEBUG
  #define dump(...) cerr << "/* " << #__VA_ARGS__ << " :[" << __LINE__ << ":" << __FUNCTION__ << "]" << endl, dump_func(__VA_ARGS__), cerr << "*/\n\n";
#else
  #define dump(...)
  #define endl "\n"
#endif
void dump_func() { cerr << endl; }
template <class Head, class... Tail> void dump_func(Head&& h, Tail&&... t) { cerr << h << (sizeof...(Tail) == 0 ? "" : ", "), dump_func(forward<Tail>(t)...); }

struct Fast { Fast() { cin.tie(0); ios::sync_with_stdio(false); } } fast;
mt19937 rnd(chrono::steady_clock::now().time_since_epoch().count());
constexpr int MOD = 1000000007;
// *************** TEMPLATE END *************** 

signed main() {
  int n, Q; cin >> n >> Q;
  string s; cin >> s;
  vector<char> t(Q), d(Q); REP (i, Q) cin >> t[i] >> d[i];
  auto get = [&]() {
    int l = -1;
    for (int i = Q - 1; i >= 0; i--) {
      if (d[i] == 'L') {
        if (l + 1 < n && s[l + 1] == t[i]) l++;
      } else {
        if (l >= 0 && s[l] == t[i]) l--;
      }
    }
    return l;
  };
  int l = get();
  reverse(ALL(s));
  REP (i, Q) d[i] = d[i] == 'L' ? 'R' : 'L';
  int r = get();
  dump(l, r);
  cout << max(0LL, n - l - r - 2) << endl;
}


Measured memory_bytes: 976
fun main(args: Array<String>) {
    val N=readLine()!!.toInt()
    val s =Array(N){ readLine()!! }
    var ab=0
    var a=0
    var b=0
    var ba=0
    s.forEach {
        it.forEachIndexed { i,c1->if(i<it.length-1&&c1=='A'&&it[i+1]=='B')ab+=1 }
        if(it[0]=='B'){
            if(it[it.length-1]=='A')ba+=1
            else b+=1
        }else if(it[it.length-1]=='A')a+=1
    }
    var abab=Math.min(ba,Math.min(a,b))
    ba-=abab
    a-=abab
    b-=abab
    var tba=0
    if(ba>0){
        if(abab>0)tba=ba
        else {
            tba=ba-1
            if(Math.max(a,b)>0)tba+=1
        }
    }else{
        tba=Math.min(a,b)
    }
    print(ab+abab*2+tba)
}

Measured memory_bytes: 34436
var obj = init();
Main();
function nextInt(){return myconv(next(),1);}
function nextStrArray(){return myconv(next(),2);}//半角スペース分割
function nextIntArray(){return myconv(next(),4);}//半角スペース + 数値化
function nextCharArray(){return myconv(next(),6);}//1文字分割
function next(){return obj.next();}
function hasNext(){return obj.hasNext();}
function myin(){return require("fs").readFileSync("/dev/stdin", "utf8").trim().split("\n");}
function init(){
  var inputFile = myin();
  var returnObj = {
    "list" : inputFile, "index" : 0, "max" : inputFile.length,
    "hasNext" : function(){return (this.index < this.max);},
    "next" : function(){if(!this.hasNext()){throw "ArrayIndexOutOfBoundsException これ以上ないよ";}else{var returnInput = this.list[this.index];this.index++;return returnInput;}}
  };
  return returnObj;
}
function myout(t){console.log(t);}//標準出力
function myerr(t){console.error(t);}//標準エラー出力
//[no]要素の扱い。数値型
//不明値、異常時:引数そのまま返す　1:数値へ変換
//2:半角SPで分割 4:半角SPで分割し、数値配列へ
//6:1文字で分割  7:1文字で分割し、数値配列へ
//8:半角SPで結合 9:改行で結合 0:文字なしで結合
function myconv(i,no){try{switch(no){case 1:return parseInt(i);case 2:return i.split(" ");case 4:return i.split(" ").map((a)=>Number(a));case 6:return i.split("");case 7:return i.split("").map((a)=>Number(a));case 8:return i.join(" ");case 9:return i.join("\n");case 0:return i.join("");default:return i;}}catch(e){return i;}}
function Main(){
  var N = nextInt();
	var list = new Array(N);
	for(var i = 0; i < N; i++){
		list[i] = nextIntArray();
	}
	var minus = 0;
	var output = 0;
	for(var i = 0; i < N; i++){
		for(var j = 0; j < N; j++){
			output += list[i][j];
		}
	}
	myerr(output);	
	output /= 2;
	var used = new Set();
	for(var k = 0; k < N; k++){
		for(var i = 0; i < N; i++){
			for(var j = 0; j < N; j++){
				if(list[i][j] > (list[i][k] + list[k][j])){
					myout(-1);
					return;
				}else if(list[i][j] == (list[i][k] + list[k][j]) && i != k && j != k){
					var num = Math.min(i,j).toString() + ":" + Math.max(i,j).toString();
 					if(!used.has(num)){
						minus += list[i][j];
						used.add(num);
						//myerr((i + 1) + "," + (j + 1) + "," + (k + 1));
					}
					
				}
			}
		}
	}
	myerr(minus);
	//minus /= 2;
	myout(output - minus);
}


Measured memory_bytes: 32344
//om namah shivaay
//faith over fear
 
#include<bits/stdc++.h>
using namespace std;
 
#define mp make_pair
#define mt make_tuple
#define fi first
#define se second
#define pb push_back
#define ll long long 
#define all(x) (x).begin(), (x).end()
#define rall(x) (x).rbegin(), (x).rend()
#define rep(i,n) for(i=0;i<n;i++)
#define forn(i, n) for (ll i = 0; i < (ll)(n); ++i)
#define for1(i, n) for (ll i = 1; i <= (ll)(n); ++i)
#define ford(i, n) for (ll i = (ll)(n) - 1; i >= 0; --i)
#define fore(i, a, b) for (ll i = (ll)(a); i <= (ll)(b); ++i)
#define fora(it,x) for(auto it:x)
#define PI 3.14159265
#define sync ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
#define endl "\n"
 
typedef pair<ll, ll> pii;
typedef vector<ll> vi;
typedef vector<pii> vpi;
typedef vector<vi> vvi;
typedef long long i64;
typedef vector<i64> vi64;
typedef vector<vi64> vvi64;
typedef pair<i64, i64> pi64;
typedef long double ld;
 
template<class T> bool uin(T &a, T b) { return a > b ? (a = b, true) : false; }
template<class T> bool uax(T &a, T b) { return a < b ? (a = b, true) : false; }

int main(){
    ll x;
    cin>>x;
    if(x<600) cout<<"8";
    else if(x<800) cout<<"7";
    else if(x<1000)cout<<"6";
    else if(x<1200) cout<<"5";
    else if(x<1400)cout<<"4";
    else if(x<1600)cout<<"3";
    else if(x<1800) cout<<"2";
    else if(x<2000)cout<<"1";
}

Measured memory_bytes: 3604
#include <algorithm>
#include <cstdio>
#include <iostream>
#include <map>
#include <math.h>
#include <queue>
#include <set>
#include <stack>
#include <vector>
using namespace std;
typedef long long int ll;
typedef long double ld;
#define rep(i,n) for(int i = 0; i < (n); ++i)
#define Sort(Array) sort(Array.begin(), Array.end())
#define Reverse(a) reverse(a.begin(), a.end())
#define out(ans) cout << ans << endl;
const int MOD = 1000000007;
const int INF = 2147483647;

//------------↓------------- M -------------- E ---------------- M --------------- O ---------------↓--------------//
// コンパイル 
// g++ -std=c++1z
//
// -------型変換--------
// int を string に変換
// string s = to_string(n);
// string を int に変換
// int n = stoi(s);
//
// -------二分探索---------
// k以上の値が最初に現れる時のイテレータ
// lower_bound(data.begin(), data.end(), k)
// kより大きい値が最初の現れる時のイテレータ O(logN)
// upper_bound(data.begin(), data.end(), k)
// kがdataに存在するかをtrue or falseで返す O(logN)
// binary_search(data.begin(), data.end(), k)
// 
//
//
//
//
//
// 
//------------↑------------- M -------------- E ---------------- M --------------- O ---------------↑--------------//







int main(void) {

    int a, b, c, d;
    cin >> a >> b >> c >> d;
    int turn = 0;
    while(1) {
        if (turn % 2 == 0) {
            c -= b;
            if (c <= 0) {
                cout << "Yes" << endl;
                break;
            }
            else {
                a -= d;
                if (a <= 0) {
                    cout << "No" << endl;
                    break;
                }
            }
        }
        ++turn;
    }


    return 0;
}











Measured memory_bytes: 3588
#まともに挙動追うと相当大変だがちゃんとやる。
#特にループ、forのインデント
N=int(input())
L=input().split( )
A=[int(L[i]) for i in range(N)]
c=0
for i in range(N):
    minj=i
    j=i
    while j<N:
        if A[j]<A[minj]:
            minj=j
        j+=1
    temp=A[i]
    A[i]=A[minj]
    A[minj]=temp
    #print(A)
    #print(A[minj])
    if i!=minj:
        c+=1
for j in range(N):
    if j<N-1:
        print(A[j],end=" ")
    else:
        print(A[j])
print(c)



Measured memory_bytes: 5612
#include "bits/stdc++.h"
#define in std::cin
#define out std::cout
#define rep(i,N) for(LL i=0;i<N;++i)
typedef long long int LL;

LL N;
std::vector<LL>A(N), B(N);

int main()
{
	in >> N;
	A.resize(N); B.resize(N);
	rep(i, N) in >> A[i] >> B[i];

	std::vector<std::pair<std::pair<LL, LL>, LL>>v1, v2;
	rep(i, N)
	{
		v1.push_back(std::make_pair(std::make_pair(A[i] + B[i], A[i]), i));
		v2.push_back(std::make_pair(std::make_pair(B[i] + A[i], B[i]), i));
	}
	std::sort(v1.rbegin(), v1.rend());
	std::sort(v2.rbegin(), v2.rend());

	std::map<LL, bool>flag;
	rep(i, N) flag[i] = true;

	LL ans = 0, s1 = 0, s2 = 0;
	rep(i, N)
	{
		if (i % 2 == 0)
		{
			for (int j = s1; j < N; ++j)
			{
				if (flag[v1[j].second])
				{
					ans += A[v1[j].second];
					flag[v1[j].second] = false;
					s1 = j + 1;
					break;
				}
			}
		}
		else
		{
			for (int j = s2; j < N; ++j)
			{
				if (flag[v2[j].second])
				{
					ans -= B[v2[j].second];
					flag[v2[j].second] = false;
					s2 = j + 1;
					break;
				}
			}
		}
	}

	out << ans << std::endl;
}


Measured memory_bytes: 13476
fun main(args: Array<String>) {
    val inputList1 = readLine()!!.split(' ').map { it.toInt() }
    val votes = readLine()!!.split(' ').map { it.toInt() }
    val popularCountM = inputList1[1]
    val sumOfVotes = votes.sum()
    val validVotes = votes.filter { it >= sumOfVotes * 1.0 / (4*popularCountM) }
    if (validVotes.size >= popularCountM)
        println("Yes")
    else
        println("No")
}

Measured memory_bytes: 38380
n=int(input())
a=[int(input()) for i in range(n)]
b=list(set(a))
if len(b)==1:
  for i in range(n):
    print(b[0])
elif a.count(b[-1])>=2:
  for i in a:
    print(b[-1])
else:
  for i in a:
    if i==b[-1]:
      print(b[-2])
    else:
      print(b[-1])


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

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    string s;
    cin >> s;
    int a[4];
    for (int i = 0; i < 4; i++) {
        a[i] = s[i] - '0';
    }
    for (int i = 0; i < 8; i++) {
        int s = a[0];
        for (int j = 1; j <= 3; j++) {
            s += (2 * ((i / (int) pow(2, j - 1)) % 2) - 1) * a[j];
        }
        if (s == 7) {
            cout << a[0];
            for (int k = 1; k <= 3; k++) {
                if ((i / (int) pow(2, k - 1)) % 2) {
                    cout << '+';
                } else {
                    cout << '-';
                }
                cout << a[k];
            }
            cout << "=7\n";
            break;
        }
    }
    return 0;
}

Measured memory_bytes: 512
short t[9];
double*p,s[99],v;
main(){
	for(p=s+2;~scanf("%[^ \n]",t);){
		v=*--p;
		if(*t==43)
			p[-1]+=v;
		else if(*t==45)
			p[-1]-=v;
		else if(*t==42)
			p[-1]*=v;
		else if(*t==47)
			p[-1]/=v;
		else
			sscanf(t,"%lf",&v),*++p=v,p++;
		if(getchar()==10)
			printf("%f\n",*--p);
	}
}

Measured memory_bytes: 0
#include <bits/stdc++.h>
#define rep(i,n)  for(int i=0;i<n;i++)
#define per(i,n)  for(int i=n-1;i>=0;i--)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define PB push_back
#define MP make_pair
#define F first
#define S second
#define sz(x) ((int)(x).size())
#define all(x) (x).begin(),(x).end()
#define INF 2000000000
#define fast_io() ios_base::sync_with_stdio(false); cin.tie(NULL)

using namespace std;
typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef set<int> si;
typedef vector<ii> vii;

int main() {
    fast_io();
    bool flag = true;
    string s; cin >> s;
    int N = s.size();
    int len = N - 1;
    rep(i, N){
        if (s[i] != s[len - i]) flag = false;
    }
    len = (( N - 1 ) / 2 ) - 1;
    
    rep(i, ( N - 1 ) / 2 ){
        if (s[i] != s[ len - i]) flag = false;
    }
    len = N - 1;
    for (int i = ((N + 3) / 2) - 1; i < N; i++){
        if (s[i] != s[len - i]) flag = false;
    }
    
    cout << (flag ? "Yes" : "No");
    
    return 0;
}


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

class Main{
    public static void main(String [] args){
        Scanner sc = new Scanner(System.in);
        while(true){
            int n = sc.nextInt();
            int k = sc.nextInt();
            if (n==0) break;
            int[] amountInFridge = new int[k];
            int[][] amountNeed = new int[n][k];
            boolean isEnough = true;

            for(int i =0; i<k; i++){
                amountInFridge[i] = sc.nextInt();
            }

            for (int i=0; i<n; i++){
                for(int j=0; j<k; j++){
                    amountNeed[i][j] = sc.nextInt();
                }
            }


            OUT: for (int j =0 ; j<k; j++){
                int sum = amountNeed[0][j];
                for (int i=1; i<n; i++){
                    sum+= amountNeed[i][j];
                    if (sum > amountInFridge[j]) {
                        isEnough = false;
                        break OUT;
                    }

                }
            }

            if(isEnough) System.out.println("Yes");
            else System.out.println("No");



        }
    }
}


Measured memory_bytes: 102420
from collections import Counter
N, C = map(int, input().split())
R = [[0]*C]*C
for i in range(C):
    *R[i], = map(int, input().split())
A = [0]*N
L0, L1, L2 = [], [], []
for i in range(N):
    *A, = map(int, input().split())
    for j in range(N):
        if (i+j+2)%3 == 0:
            L0 += [A[j]]
        elif (i+j+2)%3 == 1:
            L1 += [A[j]]
        else:
            L2 += [A[j]]
CL0 = Counter(L0)
CL1 = Counter(L1)
CL2 = Counter(L2)
K = 10**9
for i in range(1,C+1):
    for j in range(1,C+1):
        for k in range(1,C+1):
            if i == j or j == k or k == i:
                pass
            else:
                Y = 0
                for n in range(1,C+1):
                    Y += R[n-1][i-1]*CL0[n]
                for l in range(1,C+1):
                    Y += R[l-1][j-1]*CL1[l]
                for m in range(1,C+1):
                    Y += R[m-1][k-1]*CL2[m]
                K = min(K,Y)
    
print(K)

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

int main ( ) 
{
	int n , x , y;
	cin >> n ; 
	int arr [n] , temp [n]; 
	for (int i =0 ; i<n ;i++)
	{
		cin >> arr[i] ; 
		temp[i] = arr[i] ;
	}
	int m ; 
	cin >> m ; 
	int arr1 [m] , sum[m]={0} ; 
	for (int j=0; j<m;j++)
	{
		cin >> x >>y ; 
		temp [x-1] = y ; 
		for (int i =0 ; i<n ;i++)
		 {
			sum[j]+= temp[i] ;

		}
		temp [x-1] = arr[x-1] ;
		
	}
		for (int j=0; j<m;j++)
{ cout << sum[j] << endl ; 
}
	
	
		return 0 ; 
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
//#include <boost/multiprecision/cpp_int.hpp>
//namespace mp = boost::multiprecision;

using namespace std;

const double PI = 3.14159265358979323846;
typedef long long ll;
const double EPS = 1e-9;
#define rep(i, n) for (int i = 0; i < (n); ++i)
//#define rep(i, n) for (ll i = 0; i < (n); ++i)
typedef pair<ll, ll> P;
const ll INF = 10e17;
#define cmin(x, y) x = min(x, y)
#define cmax(x, y) x = max(x, y)
#define ret() return 0;

double equal(double a, double b) {
    return fabs(a - b) < DBL_EPSILON;
}

std::istream &operator>>(std::istream &in, set<int> &o) {
    int a;
    in >> a;
    o.insert(a);
    return in;
}

std::istream &operator>>(std::istream &in, queue<int> &o) {
    ll a;
    in >> a;
    o.push(a);
    return in;
}

bool contain(set<int> &s, int a) { return s.find(a) != s.end(); }

//ofstream outfile("log.txt");
//outfile << setw(6) << setfill('0') << prefecture << setw(6) << setfill('0') << rank << endl;
// std::cout << std::bitset<8>(9);
//const ll mod = 1e10;

typedef priority_queue<ll, vector<ll>, greater<ll> > PQ_ASK;

vector<vector<int>> calcNext(string &s) {
    int n = s.size();
    vector<vector<int>> res(n + 2, vector<int>(26, n + 1));

    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) res[i][j] = res[i + 1][j];
        res[i][s[i] - 'a'] = i;
    }

    return res;
}

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

string solve(string s) {
    int n = s.size();
    auto next = calcNext(s);
    vector<int> dp(n + 1, 1 << 29);
    vector<char> recon(n + 1, 'a');
    dp[n] = 1;
    for (int i = n - 1; i >= 0; i--) {
        for (int j = 0; j < 26; j++) {
            if (next[i][j] == n + 1) {
                if (dp[i] > 1) {
                    dp[i] = 1;
                    recon[i] = 'a' + j;
                }
            } else if (chmin(dp[i], dp[next[i][j] + 1] + 1)) {
                recon[i] = 'a' + j;
            }
        }
    }


    string res = "";
    int index = 0;
    while (index <= n) {
        res += recon[index];
        index = next[index][recon[index] - 'a'] + 1;
    }
    return res;
}

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

    cout << solve(s) << endl;
}


Measured memory_bytes: 28164
//ループverです。移動後はvisitedが増えるので, visited昇順にループを回せば良いです。
#include <iostream>
#include <algorithm>
using namespace std;

int INF = 1000000007;
int n, m;
bool canMove[15][15] = {false};
int ecost[15][15];
int dp[1 << 15][15];	//dp[visited][pos] = これまでの最小コスト（visitedの下位i(>=0)ビット目が1⇔頂点iを訪問済み, pos…現在地.）

int main() {
	int i, j, k;
	
	cin >> n >> m;
	for (i = 0; i < m; i++) {
		int s, t, d;
		cin >> s >> t >> d;
		ecost[s][t] = d;
		canMove[s][t] = true;
	}
	
	for (i = 0; i < (1 << n); i++) for (j = 0; j < n; j++) dp[i][j] = INF;
	dp[1][0] = 0;
	for (i = 1; i < (1 << n) - 1; i++) {
		for (j = 0; j < n; j++) {
			if (dp[i][j] >= INF) continue;	//この行は無くてもよい
			for (k = 0; k < n; k++) {
				if (!canMove[j][k]) continue;
				if ((i >> k) & 1) continue;
				dp[i + (1 << k)][k] = min(dp[i + (1 << k)][k], dp[i][j] + ecost[j][k]);
			}
		}
	}
	
	int ans = INF;
	for (j = 0; j < n; j++) {
		if (dp[(1 << n) - 1][j] < INF && canMove[j][0]) {
			ans = min(ans, dp[(1 << n) - 1][j] + ecost[j][0]);
		}
	}
	if (ans >= INF) cout << -1 << endl;
	else cout << ans << endl;
	return 0;
}


Measured memory_bytes: 5008
#include "bits/stdc++.h"
#include <iostream>
#include <string.h>
#include <stdio.h>
#include <map>
#include <vector>
#include <math.h>
#include <algorithm>
#include <queue>
#include <set>
#include <tuple>
using namespace std;

#define FOR(i,init,a) for(int i=init; i<a; i++)
#define rep(i,a) FOR(i,0,a)
#define rrep(i,a) for(int i=a; i>=0; i--)
#define rep1(i,a) for(int i=1; i<=a; i++)
#define cout1(a) cout << a << endl;
#define cout2(a,b) cout << a << " " << b << endl;
#define cout3(a,b,c) cout << a << " " << b << " " << c << endl;
#define cout4(a,b,c,d) cout << a << " " << b << " " << c << " " << d << endl;
#define mem(a,n) memset( a, n, sizeof(a))
#define all(a) a.begin(),a.end()
#define chmin(a,b) a=min(a,b);
#define chmax(a,b) a=max(a,b);

typedef long long ll;
typedef long double ld;
typedef pair<int,int> pii;
typedef vector<int> V;
typedef vector<V> VV;
typedef vector<VV> VVV;
const int INF = 1e9;
const int MOD = 1e9+7;
const ll LLINF = 1e18;
static const double pi = 3.141592653589793;

int main() {
    cin.tie(0);
    ios::sync_with_stdio(false);
    
    string s;
    cin>>s;
    
    map<char,int> dic;
    rep(i,s.size()){
        dic[s[i]]++;
    }
    
    bool f=true;
    if(dic['N']>0){
        if(dic['S']==0) f=false;
    }
    if(dic['S']>0){
        if(dic['N']==0) f=false;
    }
    if(dic['E']>0){
        if(dic['W']==0) f=false;
    }
    if(dic['W']>0){
        if(dic['E']==0) f=false;
    }
    
    cout1((f?"Yes":"No"))
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
int main(){

int n, m;
cin>>n>>m;

int MAX, MIN;
MAX = 0;
MIN = 100000;

int l[m],r[m];


for(int i=0;i<m;i++){
	cin>>l[i]>>r[i];
	if(MAX < l[i])
	MAX = l[i];
	if(MIN > r[i])
	MIN = r[i];
}

if(MIN - MAX < 0)
cout<< 0 <<endl;

else
cout<< MIN - MAX + 1 <<endl;



}


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

int main() {
	int N;

	cin >> N;

	vector<double> A(N);
	set<double> A_set;

	for (int i = 0; i < N; i++) {
		cin >> A.at(i);
		A_set.insert(A.at(i));
	}

	if (A.size() == A_set.size()) {
		cout << "YES" << endl;
	}
	else {
		cout << "NO" << endl;
	}
	return 0;
}

Measured memory_bytes: 11136
import java.util.Scanner;

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

        while (sc.hasNext()){
            int a = sc.nextInt();
            int b = sc.nextInt();
            int c = sc.nextInt();

            if (a*c <= b)
                System.out.println(c);
            else{
                System.out.println(b/a);
            }
        }
    }
}


Measured memory_bytes: 22996
#include <bits/stdc++.h>
using namespace std;
int main() {
    #ifdef DEBUG
    std::ifstream in("/home/share/inputf.in");
    std::cin.rdbuf(in.rdbuf());
    #endif
    int64_t N, K, ans = 0;
    cin >> N >> K;
    int64_t tmp = 0;
    if(K % 2 == 0) {
        if (((2 * N) / K) % 2 == 0) {
            tmp = N / K;
            ans += tmp * tmp * tmp;
            ans *= 2;
        } else {
            tmp = N / K + 1;
            ans += tmp * tmp * tmp;
            tmp = N / K;
            ans += tmp * tmp * tmp;
        }
    } else {
        tmp = N / K;
        ans += tmp * tmp * tmp;
    }
    cout << ans << endl;
    return 0;
}

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

int main(){
	int a, b, c, d, e;
	cin >> a >> b >> c >> d >> e;
	if(c-e >= 0 && d-e >= 0 && c+e <= a && d+e <= b)
		cout << "Yes\n";
	else
		cout << "No\n";
}


Measured memory_bytes: 3076
#include <iostream>
#include <bits/stdc++.h>
using namespace std;
#define li long
#define ll long long
#define ull unsigned long long
#define ff first
#define ss second
#define pii pair<int,int>
#define pli pair<li,li>
#define pll pair<ll,ll>
#define pb push_back
#define fori(i,k,n) for(int i = k;i<n; i++)
#define rfori(i,k,n) for(int i = k; i>=n; i--)
#define tc int t;cin>>t;while(t--)
#define all(v) v.begin(),v.end()
const ll mod = 1000000007;
void fastio(){
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    cout.tie(NULL);
} 
void swap(int &x,int &y){
	x = x^y;
	y = x^y;
	x = x^y;
}
class dsu{
    public:
    unordered_map<int,int> p,sz;
    unordered_map<int,pair<int,int>> gp;
    void make_set(int x,bool gender){
        p[x] = x;
        sz[x]+=1;
        if(gender == 1)gp[x].ff++;
        else gp[x].ss++;
    }
    int find(int x){
        if(x == p[x])return x;
        return p[x] = find(p[x]);
    }
    void merge(int a,int b,bool ga,bool gb){
        a = find(a);
        b = find(b);
        if(a == b)return;
        if(sz[a]<sz[b])swap(a,b),swap(ga,gb);
        p[b] = a;
        sz[a]+=sz[b];
        if(gb)gp[a].ff++;
        else gp[a].ss++;
        sz.erase(b);
    }
};
ll power(ll x,ll y,ll p){
    ll res = 1;
    x%=p;
    while(y>0){
        if(y&1)res = (res%p*x%p)%p;
        y>>=1;
        x = (x%p*x%p)%p;
    }
    return res;
}
ll power(ll x,ll y){
    ll res = 1;
    while(y>0){
        if(y&1)res = (res*x);
        y>>=1;
        x = (x*x);
    }
    return res;
}
int main(){
    fastio();
	vector<int> term = {1, 1, 1, 2, 1, 2, 1, 5, 2, 2, 1, 5, 1, 2, 1, 14, 1, 5, 1, 5, 2, 2, 1, 15, 2, 2, 5, 4, 1, 4, 1, 51};
	int k;
	cin>>k;
	cout<<term[k-1];
}

Measured memory_bytes: 256