akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i = 0; i < (n); ++i)
#define all(x) (x).begin(),(x).end()
typedef long long lint;
 
int main() {
  string s;
  int k;
  
  cin >> s;
  cin >> k;
  
  lint ans = 0;
  int ctr = 1;
  int first_ctr = 1;
  bool first = true;
  
  if(k==1){
    rep(i,s.length()-1){
      if(s[i]==s[i+1]){
        ctr++;
        if(i==s.length()-2)ans += ctr/2;
      }
      else{
        ans += ctr/2;
        ctr = 1;
      }
    }
  }
  else{		//k>2
    string ss = s+s;
    rep(i,ss.length()-1){
      if(ss[i]==ss[i+1]){
        ctr++;
        //cout << i << "*" << ans << " " << ctr << endl;
        if(first){
          first_ctr++;
          if(i==s.length()-1){	//全文字一緒
            ans = s.length()*k/2;
            break;
          }
        }
      }
      else{
        first = false;
        ans += ctr/2;
        //cout << i << " " << ans << " " << ctr << endl;
        if(i==s.length()-1){	//連結時の考慮なし
          ans = ans*k;
          break;
        }
        else if(i>s.length()-1){      //連結時の考慮あり
          ans = ans - first_ctr/2;
          ans = ans*k;
          ans = ans + (first_ctr/2);
          ans = ans - ctr/2 + (ctr-first_ctr)/2;
          break;
        }
        ctr = 1;
      }
    }
  }
  
  cout << ans << endl;
  //cout << ctr << " " << first_ctr << endl;
}



Measured memory_bytes: 256
n = int(input())
A = list(map(int,input().split()))
ans = []
dic = {}
for i in range(len(A)):
  dic[A[i]] = dic.get(A[i])+1 if dic.get(A[i])!=None else 1
for i in range(1,n+1):
  p = dic.get(i)
  print(p if p != None else 0)

Measured memory_bytes: 33588
#include<bits/stdc++.h>
#define two(a) (1<<(a))
#define LINF (1ll<<61)
#define EPS (1e-14)
#define Lshift(a,b) (a<<b)
#define Rshift(a,b) (a>>b)
#define rep(a,b) for(a=0 ; a<b ; a++)
#define xrep(a,b,c) for(a=b ; a<c ; a++)
#define INF (1<<29)
#define swap(a,b) ( (a^=b) , (b^=a) , (a^=b) )
#define GET(x) (mark[x>>5]>>(x&31)&1)
#define SET(x) (mark[x>>5]|=1<<(x&31))
#define maxL (10000000>>5)+1
#define mod 1000000007
#define vi vector<int>
#define pii pair<int, int>
#define mii map<int, int>
#define si set<int>
#define pb push_back
typedef long long ll;
using namespace std;


int main() {
    ios_base::sync_with_stdio(false); cin.tie(NULL);
    int n, k;
    cin >> n >> k;
    int cnt(0);
    while(n) {
        cnt++;
        n /= k;
    }
    cout << cnt << endl;
}


Measured memory_bytes: 256
#[allow(unused_imports)]
use std::io::*;
#[allow(unused_imports)]
use std::str::*;
#[allow(unused_imports)]
use std::mem::*;
#[allow(unused_imports)]
use std::cmp::Ordering;
#[allow(unused_imports)]
use std::collections::HashMap;

#[allow(dead_code)]
fn read<T: FromStr>() -> T {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();
    line.trim().to_string().parse().ok().unwrap()
}

#[allow(dead_code)]
fn read_cols<T: FromStr>() -> Vec<T> {
    let mut line = String::new();
    stdin().read_line(&mut line).unwrap();

    line.trim()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap())
        .collect()
}

fn count(coins: &HashMap<u32, u32>, total: u32) -> i32 {
    if total == 0 {
        return 1;
    }

    if coins.is_empty() {
        return 0;
    }

    let (next_coin, max) = coins.iter().nth(0).unwrap();

    (0..max + 1)
        .take_while(|n| n * next_coin <= total)
        .fold(0, |total_count, n| {
            let mut next_coins = coins.clone();
            next_coins.remove(next_coin);
            total_count + count(&next_coins, total - n * next_coin)
        })
}

fn main() {
    let n500 = read::<u32>();
    let n100 = read::<u32>();
    let n50 = read::<u32>();
    let price = read::<u32>();

    let mut coins = HashMap::new();
    coins.insert(500, n500);
    coins.insert(100, n100);
    coins.insert(50, n50);

    println!("{}", count(&coins, price));
}


Measured memory_bytes: 4352
// Math = ♥️

#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
using namespace __gnu_pbds;
using namespace std;

/*-------------------------------------------------------------------------------------------------------------------------*/
#define ll long long                  // Short form for long long
#define ld long double                // Short form for long double
typedef pair<ll, ll> ii;              // Pair of long long
typedef vector<ll> vi;                // Vector of long long
typedef vector<vi> vvi;               // Vector of vector of long long
typedef vector<ii> vii;               // Vector of pairs
typedef vector<vii> vvii;             // Vector of vector of pairs
#define pq priority_queue             // Max heap (To convert to min heap, use negative sign before every value)
#define ff first                      // For pairs
#define ss second                     // For pairs
#define pb push_back                  // Pushback to vector
#define mp make_pair                  // Makes pairs to be stored as pair
#define all(c) (c).begin(), (c).end() // Mainly used by me in sorting
// ordered_set adds two new functions to set - (set).find_by_order([kth element based on zero indexing]) and order_of_key()
// order_of_key returns number of elements less that parameter. If element exists, that order is its index
#define ordered_set tree<ll, null_type, less<ll>, rb_tree_tag, tree_order_statistics_node_update>
/*-------------------------------------------------------------------------------------------------------------------------*/

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

    ll r, c, n;
    cin >> r >> c >> n;

    vector<ii> seg;

    for (int i = 0; i < n; i++)
    {
        ll x1, x2, y1, y2;
        cin >> x1 >> y1 >> x2 >> y2;

        ll flag = 0;
        if (x1 == 0 || x1 == r || y1 == 0 || y1 == c)
            flag++;
        if (x2 == 0 || x2 == r || y2 == 0 || y2 == c)
            flag++;

        if (flag == 2)
        {
            if (x1 == 0)
                seg.pb({y1, i});
            else if (y1 == c)
                seg.pb({c + x1, i});
            else if (x1 == r)
                seg.pb({r + c + (c - y1), i});
            else if (y1 == 0)
                seg.pb({r + (2 * c) + (r - x1), i});

            if (x2 == 0)
                seg.pb({y2, i});
            else if (y2 == c)
                seg.pb({c + x2, i});
            else if (x2 == r)
                seg.pb({r + c + (c - y2), i});
            else if (y2 == 0)
                seg.pb({r + (2 * c) + (r - x2), i});
        }
    }

    sort(all(seg));
    stack<ll> s;
    
    for (auto it: seg)
    {
        if (!s.empty() && s.top() == it.ss)
            s.pop();
        else
            s.push(it.ss);
    }

    if (s.empty())
        cout << "YES\n";
    else
        cout << "NO\n";
}


Measured memory_bytes: 6256
#!/usr/bin/env python3
import sys
sys.setrecursionlimit(10**8)
input = sys.stdin.readline

a, b = [item for item in input().split()]
pata = a * int(b)
patb = b * int(a)

if pata < patb:
    print(pata)
else:
    print(patb)

Measured memory_bytes: 2940
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <iomanip>
#include <vector>
#include <string.h>
#include <string>
#include <map>
#include <stack>
#include <queue>
#include <deque>
#include <set>
#include <math.h>
#include <algorithm>
#include <numeric>

using namespace std;

// マクロ&定数 ============================================================
typedef unsigned int uint;
typedef long long ll;
//typedef pair<int, int> P;
typedef vector<int> vint;
typedef vector<ll> vll;
typedef vector<double> vdouble;
typedef vector<bool> vbool;

typedef vector<vector<int>> vvint;
typedef vector<vector<ll>> vvll;
typedef vector<vector<double>> vvdouble;
typedef vector<vector<bool>> vvbool;

const int INF = 1e9 + 1;
const ll LLINF = 1e17 + 1;
const int DX[9] = { 0,0,1,-1, 1, 1, -1, -1, 0 }; // 4;４近傍
const int DY[9] = { 1,-1,0,0, 1, -1, 1, -1, 0 }; // 8:８近傍 9:(0,0)を含む
const ll MOD = 1e9 + 7; //10^9 + 7
const double PI = 3.14159265358979323846264338327950288;
//========================================================================


int main() {

	//==================================
	cin.tie(nullptr);
	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(30);
	//==================================


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

	int even = 0;
	int odd = 0;

	for (int i = 0; i < N; i++) {
		odd += A[i] % 2;
	}
	even = N - odd;

	if (P == 0) {

		if (odd == 1 && even == 0) {
			cout << 0;
			return 0;
		}

		if (odd == 0) {
			cout << ll(pow(2, N));
			return 0;
		}

		int canEven = odd - 1;

		cout << ll(pow(2, even) * pow(2,  canEven)) << endl;

	}
	else {

		if (odd == 0) {
			cout << 0;
			return 0;
		}

		int canEven = odd -1 ;

		cout << ll(pow(2, even) * pow(2, canEven));
	}


}


Measured memory_bytes: 256
#include <iostream>
#define rep(i,n) for(int i=0;i<(n);i++)
using ll = long long;
using namespace std;

int main(){
	string s,t,u;
    ll a,b;
    cin >> s >> t;
    cin >> a >> b;
    cin >> u;
    if(u == s) a--;
    if(u == t) b--;
    
    cout << a << " " << b << endl;
    return 0;

}


Measured memory_bytes: 256
import java.math.BigInteger;
import java.util.Scanner;

public class Main {

	/**
	 * @param args
	 */
	public static void main(String[] args) {
		BigInteger b = new BigInteger("1");
		for(int i = 1 ; i < 100; i++){
			b = b.multiply(new BigInteger(String.valueOf(i)));
			//System.out.println(i + " " + b);
			
		}
		Scanner cin = new Scanner(System.in);
		while(true){
			int n = cin.nextInt();
			if(n==0){
				break;
			}
			int count=0;
			for(int i = 5; i < 2000000000; i*=5){
				count+= n/i;
			}
			System.out.println(count);
				
			
			
		}
	}

}

Measured memory_bytes: 12000
#!/usr/bin/env python3


def solve(n, m, xs, ops):
    ys = sorted(xs)
    bcs = sorted(ops, key=lambda op: op[1], reverse=True)
    arr_pos = 0
    for b, c in bcs:
        while arr_pos < n and b > 0:
            if ys[arr_pos] < c:
                b -= 1
                ys[arr_pos] = c
            arr_pos += 1
    return sum(ys)


def main():
    n, m = (int(z) for z in input().split())
    xs = [int(z) for z in input().split()]
    ops = [tuple(int(z) for z in input().split()) for _ in range(m)]
    res = solve(n, m, xs, ops)
    print(res)


if __name__ == "__main__":
    main()


Measured memory_bytes: 24008
#!/usr/bin/env python3

import sys
import numpy as np


# def input():
#     return sys.stdin.readline().rstrip()


def main():
    # n, k = map(int, sys.stdin.buffer.readline().split())
    n, k = map(int, input().split())

    # warps = list(map(int, sys.stdin.buffer.readline().split()))
    warps = list(map(int, input().split()))
    warps = [0] + warps
    warps = np.array(warps, dtype=int)

    dp = np.zeros((k.bit_length() + 1, n + 1), dtype=int)

    dp[0, :] = warps

    for h in range(1, len(dp)):
        dp[h] = dp[h - 1][dp[h - 1]]

    node = 1
    # for i in reversed(range(k.bit_length())):
    for i in range(k.bit_length(), -1, -1):
        if k >> i & 1:
            node = dp[i][node]

    print(node)


main()


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

#ifdef DEBUG
#include "../include/debug.hpp"
#else
#define debug(...) 42
#define rdfile(...) 42
#endif

int cl[2010][2010];
int cr[2010][2010];
int cu[2010][2010];
int cd[2010][2010];

int main(){
    ios::sync_with_stdio(false);
    cin.tie(0);
    // rdfile("_input.txt");

    int H, W;
    cin >> H >> W;

    vector<string> S(H);
    for (int i=0; i<H; ++i) {
        cin >> S[i];
    }

    for (int i=0; i<H; ++i) {
        for (int j=0; j<W; ++j) {
            if (S[i][j] == '#') {
                cl[i][j] = 0;
                cu[i][j] = 0;
            } else {
                cl[i][j] = 1 + (j == 0 ? 0 : cl[i][j-1]);
                cu[i][j] = 1 + (i == 0 ? 0 : cu[i-1][j]);
            }
        }
    }

    for (int i=H-1; i>=0; --i) {
        for (int j=W-1; j>=0; --j) {
            if (S[i][j] == '#') {
                cr[i][j] = 0;
                cd[i][j] = 0;
            } else {
                cr[i][j] = 1 + (j == W-1 ? 0 : cr[i][j+1]);
                cd[i][j] = 1 + (i == H-1 ? 0 : cd[i+1][j]);
            }
        }
    }

    int ans = 0;
    for (int i=0; i<H; ++i) {
        for (int j=0; j<W; ++j) {
            if (S[i][j] == '#') continue;
            ans = max(ans, cu[i][j]+cd[i][j]+cl[i][j]+cr[i][j]-3);
        }
    }

    cout << ans << endl;

    return 0;
}

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

int main() {
	int n, x; cin >> n >> x;
	rep(i, n * 2 - 2) cout << x - n + 1 + i << ' ';
	cout << x + n - 1 << endl;
}

Measured memory_bytes: 256
use proconio::input;
use std::collections::VecDeque;
use std::vec::Vec;

fn main() {
    input! {
        n: usize,
        m: u32,
        es: [(usize, usize); m],
    }
    let mut g = vec![vec![]; n];
    for (u, v) in es {
        g[u - 1].push(v - 1);
        g[v - 1].push(u - 1);
    }
    let mut ans = vec![None; n];
    let mut que = VecDeque::new();
    que.push_back(0);
    while let Some(v) = que.pop_front(){
        for &nxt in g[v].iter() {
            if ans[nxt].is_some() {
                continue;
            }
            ans[nxt] = Some(v);
            que.push_back(nxt);
        }
    }
    println!("Yes");
    for i in 1..n {
        println!("{}", ans[i].unwrap() + 1);
    }
}


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

using namespace std;
#define ll long long

int debug=0;

// 2<=N <= 2x10^5
int K;
int N;
vector<int> pos;
vector<int> dis;

int main()
{
    cin >> K >> N;
    for(int i=0; i<N;++i){
        int tmp;
        cin >> tmp;
        pos.push_back(tmp);
    }

    if(debug){
        for(int i=0;i<N;++i){
            cout << pos[i] << " ";
        }
    }

    for(int i=0;i<N;++i){
        int next,tmp;
        if(i==N-1){
            next=0;
            tmp = K-pos[i]+pos[next];
            dis.push_back(tmp);
        }else{
            next=i+1;
            tmp = pos[next]-pos[i];
            dis.push_back(tmp);
        }
    }    

    auto iter = max_element(dis.begin(),dis.end());
    size_t index = distance(dis.begin(),iter);

    if(debug){
        cout << "max distance=" << dis[index];
        cout << ", index=" << index << endl;
    }

    //
    int ans=0;
    if(index==0){
        for(int i=1;i<N;i++){
            ans += dis[i];
        }
    }else if(index==N-1){
        for(int i=0;i<N-1;i++){
            ans += dis[i];
        }
    }else{
        int dis1=0,dis2=0;
        for(int i=0;i<index;i++){
            dis1+= dis[i];
        }
        for(int i=index+1;i<N;i++){
            dis2+= dis[i];
        }
        ans = dis1+dis2;
    }

    cout << ans << endl;



}

Measured memory_bytes: 2548
#include <iostream>
#include <vector>
#include <list>

using namespace std;

int main() {
    int n, m, q;
    cin >> n >> m >> q;

    list<int> v;
    for (int i = 0; i < n; i++)v.push_back(i);

    vector<bool> ret(n, true);
    auto itr = v.begin();
    for (int i = 0; i < m; i++) {
        int t;
        cin >> t;
        if (t % 2 == 0) {
            for (int j = 0; j < t; j++) {
                if (itr == --v.end())itr = v.begin();
                else itr++;
            }
        } else {
            for (int j = 0; j < t; j++) {
                if (itr == v.begin())itr = --v.end();
                else itr--;
            }
        }

        ret[*itr] = false;
        if (itr == --v.end()) {
            v.pop_back();
            itr = v.begin();
        } else {
            itr = v.erase(itr);
        }
    }

    for (int i = 0; i < q; i++) {
        int wanted;
        cin >> wanted;
        cout << (ret[wanted] ? 1 : 0) << endl;
    }
    return 0;
}


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

string FMT_F = "%.10f";

static string[] s_rd;
T RD(T = long)() { while(!s_rd.length) s_rd = readln.chomp.split; string res = s_rd[0]; s_rd.popFront; return res.to!T; }
string RDR()() { return readln.chomp; }
T[] ARR(T = long)(in string str, T fix = 0) { auto r = str.split.to!(T[]); r[] += fix; return r; }
T[] RDA(T = long)(T fix = 0) { auto r = readln.chomp.split.to!(T[]); r[] += fix; return r; }
T[][] RDA2(T = long)(size_t n, T[] fix = []) { auto r = new T[][](n); foreach (i; 0..n) { r[i] = readln.chomp.split.to!(T[]); foreach (j, e; fix) r[i][j] += e; } return r; }
size_t[] MAKE_IDX(alias less = "a < b", Range)(Range range) { auto idx = new size_t[](range.length); makeIndex!(less)(range, idx); return idx;}
size_t MIN_POS(alias less = "a < b", Range)(Range range) { auto r = minPos!(less)(range); return range.length - r.length; }

bool inside(T)(T x, T b, T e) { return x >= b && x < e; }
long lcm(long x, long y) { return x * (y / gcd(x, y)); }

long mod = 10^^9 + 7;
//long mod = 998244353;
//long mod = 1_000_003;
void moda(ref long x, long y) { x = (x + y) % mod; }
void mods(ref long x, long y) { x = ((x + mod) - (y % mod)) % mod; }
void modm(ref long x, long y) { x = (x * y) % mod; }

void main()
{
	auto N = RD!int;
	auto T = RDA;
	auto A = RDA;

	long ans = 1;
	foreach (i; 1..N-1)
	{
		if (T[i] != T[i-1])
		{
			if (A[i] < T[i])
			{
				ans = 0;
				break;
			}
		}
		else if (A[i] != A[i+1])
		{
			if (T[i] < A[i])
			{
				ans = 0;
				break;
			}
		}
		else
			ans.modm(min(T[i], A[i]));
	}
	if (N >= 2)
	{
		if (T[N-1] != T[N-2] && A[N-1] < T[N-1])
			ans = 0;
		else if (A[0] != A[1] && T[0] < A[0])
			ans = 0;
	}
	else
	{
		if (T[0] != A[0])
			ans = 0;
	}

	writeln(ans);
	stdout.flush();
	debug readln();
}

Measured memory_bytes: 9544
import java.util.*;

public class Main{
    public static void main(String[]args){
        Scanner sc=new Scanner(System.in);
        
        String s=sc.next();
        String t=sc.next();
        boolean ans=false;
        for(int i=0;i<s.length();i++){
            if(s.equals(t)){
                ans=true;
            }else{
                s=s.substring(s.length()-1,s.length())+s.substring(0,s.length()-1);
            }
        }
        if(ans) System.out.println("Yes");
        else System.out.println("No");
    }
}

Measured memory_bytes: 23764
#include <bits/stdc++.h>
using namespace std;
template<class T> inline bool chmax(T& a, T b) { if (a < b) { a = b; return 1; } return 0; }
template<class T> inline bool chmin(T& a, T b) { if (a > b) { a = b; return 1; } return 0; }

#define COUT(x) cout << #x << " = " << (x) << " (L" << __LINE__ << ")" << endl
template<class T1, class T2> ostream& operator << (ostream &s, pair<T1,T2> P)
{ return s << '<' << P.first << ", " << P.second << '>'; }
template<class T> ostream& operator << (ostream &s, vector<T> P)
{ for (int i = 0; i < P.size(); ++i) { if (i > 0) { s << " "; } s << P[i]; } return s; }
template<class T> ostream& operator << (ostream &s, vector<vector<T> > P)
{ for (int i = 0; i < P.size(); ++i) { s << endl << P[i]; } return s << endl; }
template<class T> ostream& operator << (ostream &s, set<T> P)
{ for(auto it : P) { s << "<" << it << "> "; } return s << endl; }
template<class T1, class T2> ostream& operator << (ostream &s, map<T1,T2> P)
{ for(auto it : P) { s << "<" << it.first << "->" << it.second << "> "; } return s << endl; }


long long solve(long long X, long long K, long long D) {
    X = abs(X);
    long long q = X/D, r = X%D; // 地点 r に到達するまで
    if (q >= K) return X - D*K;
    long long rem = K - q; // 残り回数
    if (rem % 2 == 0) return r;
    else return D-r;
}
int main() {
    long long X, K, D;
    cin >> X >> K >> D;
    cout << solve(X, K, D) << endl;
}

Measured memory_bytes: 3584
#include<bits/stdc++.h>
#define ll long long int
#define M 1000000007
#define fast_io() ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

int main(){
#ifndef ONLINE_JUDGE
    // for getting input from input.txt
    freopen("input.txt", "r", stdin);
    // for writing output to output.txt
    freopen("output.txt", "w", stdout);
#endif

    fast_io();
    
    int n;
    cin>>n;

    ll a[n];

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

    ll b[n];
    b[0] = 0;
    b[1] = abs(a[1]-a[0]);

    for(int i=2; i<n; i++){
        b[i] = min(abs(a[i]-a[i-1])+b[i-1], abs(a[i]-a[i-2])+b[i-2]);
    }

    cout<<b[n-1]<<"\n";

    return 0;

}
  

Measured memory_bytes: 5152
#include <bits/stdc++.h>
using namespace std;
using Graph=vector<vector<int>>;
#define MOD 1000000007
using ll=long long;

int main(){
  int N;
  cin>>N;
  vector<int> A(N);
  for(int i=0;i<N;i++){
    cin>>A[i];
  }
  sort(A.begin(),A.end());

  int count=0;
  set<int> s;
  vector<bool> have(1000001,false);
  for(int i=0;i<N;i++){
    int x=A[i];
    set<int> divd;
    for(int j=1;j*j<=x;j++){
      if(x%j==0){
        divd.insert(j);
        divd.insert(x/j);
      }
    }
    bool flag=false;
    for(auto d:divd){
      if(have.at(d)){
        flag=true;
        break;
      }
    }
    if(i<N-1){
      if(A[i]==A[i+1]){
        flag=true;
      }
    }
    if(flag){
      count++;
    }
    have.at(x)=true;
  }

  cout<<N-count<<endl;
}


Measured memory_bytes: 4316
#include <bits/stdc++.h>
#define rep(i,l,n) for(int i = l; i < (n); i++)
using namespace std;
int main() {
  int n,ans;
  bool flag;
  scanf("%d",&n);
  rep(i,n,100005) {
    flag = false;
    rep(j,2,(int)sqrt(n)+2) {
      if(i == 2) break;
      if(i%j == 0) flag = true;
    }
    if(!flag) {
      ans = i;
      break;
    }
  }
  printf("%d\n",ans);
  return 0;
}

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

#define ll long long
#define vi vector<int>
#define vl vector<ll>
#define pii pair<int,int>
#define pll pair<ll,ll>
// pll pp; -> (pp.first,pp.second)
// vector<vl> pp(n,vl(2)); sort(pp.begin(),pp.end(),[](vl a,vl b){return a[0]<b[0];});

#define REP(i,n) for(ll (i)=0;(i)<(n);(i)++)
#define RREP(i,n) for(ll (i)=(n)-1;(i)>=0;(i)--)
#define FOR(i,a,b) for(ll (i)=(a);(i)<(b);(i)++)
#define FORR(i,a,b) for(ll (i)=(b)-1;(i)>=(a);(i)--)
#define DEBUG(x) cout << #x << ": " << x << endl
#define CHMAX(a,b) a=max((a),(b))
#define CHMIN(a,b) a=min((a),(b))
/*}}}*/
ll gcd(ll a,ll b){
  if(a<b) swap(a,b);
  if(a%b==0) return b;
  return gcd(b,a%b);
}
int main() {
  ll a,b;
  cin >> a >> b;
  ll g = gcd(a,b);
  ll sq = sqrt(g);
  vl cand;
  if(g!=1)cand.push_back(g);
  FOR(i,2,sq+1){
    if(g%i!=0) continue;
    cand.push_back(i);
    while(g%i==0) g /= i;
    if(g!=1)cand.push_back(g);
  }
  sort(cand.begin(),cand.end());
  //REP(i,cand.size()) cout << cand[i] << ",";
  //cout << endl;
  vector<bool> isAns(cand.size(),true);
  REP(i,cand.size()){
    if(!isAns[i]) continue;
    FOR(j,i+1,cand.size()){
      if(cand[j]%cand[i]==0) isAns[j] = false;
    }
  }
  ll ans = 1;
  REP(i,cand.size()) if(isAns[i]) ans ++;
  cout << ans << endl;
  return 0;
}


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

int main(){

    int A,B,C,D;
    cin >> A >> B >> C >> D;

    int MIN = 0;
    if(A > B) MIN += B;
    else MIN += A;

    if(C>D) MIN += D;
    else MIN += C;

    cout << MIN << endl;

    return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define inc(i, l, r) for (int i = l; i <= r; i++)

const int maxn = 1e6 + 5;

int n, a[maxn], cnt;

int main() {
    cin >> n;
    inc(i, 1, n) {
        cin >> a[i];
        if ((i & 1) && (a[i] & 1)) cnt++;
    }
    cout << cnt;
}

Measured memory_bytes: 3564
#include <bits/stdc++.h>
#include <time.h>
#include <stdlib.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define pb push_back
#define IOS ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define ll long long
#define ull unsigned long long
#define gcd(a,b) __gcd((a),(b))
#define lcm(a,b) ((a)*(b))/__gcd((a),(b))
#define clr(x) x.clear()
#define vi vector<int>
#define vll vector<long long>
#define vvi vector<vi>
#define mp make_pair
#define hell 1000000007
#define pii pair<int,int>
#define pll pair<ll,ll>
#define vpii vector<pii>
#define vpll vector<pll>
#define all(a) a.begin(),a.end()
#define ign cin.ignore();

#define o_set tree<int, null_type,less<int>, rb_tree_tag,tree_order_statistics_node_update>
#define o_setll tree<ll, null_type,less<ll>, rb_tree_tag,tree_order_statistics_node_update>
//member functions :
//1. order_of_key(k) : number of elements strictly lesser than k
//2. find_by_order(k) : k-th element in the set

using namespace std;
using namespace __gnu_pbds;

void __print(int x) {cerr << x;}
void __print(long x) {cerr << x;}
void __print(long long x) {cerr << x;}
void __print(unsigned x) {cerr << x;}
void __print(unsigned long x) {cerr << x;}
void __print(unsigned long long x) {cerr << x;}
void __print(float x) {cerr << x;}
void __print(double x) {cerr << x;}
void __print(long double x) {cerr << x;}
void __print(char x) {cerr << '\'' << x << '\'';}
void __print(const char *x) {cerr << '\"' << x << '\"';}
void __print(const string &x) {cerr << '\"' << x << '\"';}
void __print(bool x) {cerr << (x ? "true" : "false");}

template<typename T, typename V>
void __print(const pair<T, V> &x) {cerr << '{'; __print(x.first); cerr << ','; __print(x.second); cerr << '}';}
template<typename T>
void __print(const T &x) {int f = 0; cerr << '{'; for (auto &i: x) cerr << (f++ ? "," : ""), __print(i); cerr << "}";}
void _print() {cerr << "]\n";}
template <typename T, typename... V>
void _print(T t, V... v) {__print(t); if (sizeof...(v)) cerr << ", "; _print(v...);}
#ifdef MY_PROJECT
#define debug(x...) cerr << "[" << #x << "] = ["; _print(x)
#else
#define debug(x...)
#endif

int main()
{
    IOS
    int a,b,c;
    cin>>a>>b>>c;
    cout<<c<<" "<<a<<" "<<b;
    return 0;
}


Measured memory_bytes: 256
import qualified Data.ByteString.Char8 as B
import Data.Maybe (fromJust)

mods :: Int
mods = 10 ^ (9 :: Int) + 7

modFact :: Int -> Int
modFact 0 = 1
modFact n = n * modFact (n - 1) `mod` mods

main :: IO ()
main = do
    [n, m] <- map (fst . fromJust . B.readInt) . B.words <$> B.getLine
    let (x, y) = (min n m, max n m)
    print $ case y - x of
                0 -> (toInteger (modFact x) ^ (2 :: Integer) * 2) `mod` toInteger mods
                1 -> (toInteger (modFact x) ^ (2 :: Integer) * toInteger y) `mod` toInteger mods
                _ -> 0


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

using namespace std;

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  int n;
  cin >> n;
  map<int, int> mp;
  for(int i=0; i<n; i++){
    int x;
    cin >> x;
    mp[x]++;
  }
  long long ans = 0;
  for(auto x : mp){
    if(x.first == x.second) continue;
    else if(x.first > x.second) ans += x.second;
    else ans += x.second - x.first;
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 4736
#include<stdio.h>
int main()
{
    int a,n,c=0,i,d=0,b[100]={0};
    scanf("%d",&n);
     for(i=0;i<n;i++)
     {
         scanf("%d",&a);
        if(a%2==0)
        {
        b[c]=a;
        c++;
        }
     }
     for(i=0;i<c;i++)
     {
         if(b[i]%3==0||b[i]%5==0)
            d++;
     }
     if(c==d)
        printf("APPROVED");
     else
        printf("DENIED");
}


Measured memory_bytes: 128
#include <iostream>
#include <algorithm>
#include <string>
#include <vector>
#include <climits>
#include <cmath>
#include <map>
#include <queue>
#include <iomanip>
#include <set>
using namespace std;

#define rep(i,n) for(ll (i)=0;(i)<(n);(i)++ )
#define repf(i,m,n) for(ll (i)=m;(i)<n;(i)++)
#define all(v) (v).begin(), (v).end()
#define ll long long
#define vec(name,num) vector<ll> name((num),0);
#define op(i) cout<<(i)<<endl;
#define opf(i) cout<<fixed<<setprecision(10)<<(i)<<endl;
#define ip(i) cin>>(i);
#define opN cout<<"No"<<endl;
#define opY cout<<"Yes"<<endl;
#define opP cout<<"Possible"<<endl;
#define opI cout<<"Impossible"<<endl;
#define mat(name,fnum,snum); vector<vector<ll>> name((fnum),vector<ll>((snum),0));
#define matC(name,fnum,snum); vector<vector<char>> name((fnum),vector<char>((snum),0));
#define debugP int debug_point; cin>>debug_point;
#define FI first
#define SE second
const ll MOD= 1e9 + 7;

vec(vis,0);
vector<vector<pair<ll,ll>>>edge(0,vector<pair<ll,ll>>(0));
vec(col,0);
void dfs(ll now,ll Col){
    vis[now]=1;
    ll C=0;
    rep(i,edge[now].size()){
        if(vis[edge[now][i].FI]==0){
            if(C!=Col)col[edge[now][i].SE]=C;
            else col[edge[now][i].SE]=(++C);
            dfs(edge[now][i].FI,C);
            C++;
        }
    }
    return;
}

//
void solve(long long N, std::vector<long long> a, std::vector<long long> b){
    dfs(0,-1);
    ll ans=0;
    rep(i,N-1){
        ans=max(col[i],ans);
    }
    op(ans+1)
    rep(i,N-1){
        cout<<col[i]+1<<endl;
    }
}

// Generated by 1.1.6 https://github.com/kyuridenamida/atcoder-tools  (tips: You use the default template now. You can remove this line by using your custom template)
int main(){
    long long N;
    scanf("%lld",&N);
    vis.resize(N);
    edge.resize(N);
    col.resize(N-1);
    std::vector<long long> a(N-1);
    std::vector<long long> b(N-1);
    for(int i = 0 ; i < N-1 ; i++){
        scanf("%lld",&a[i]);
        scanf("%lld",&b[i]);
        a[i]--;
        b[i]--;
        edge[a[i]].push_back(make_pair(b[i],i));
        edge[b[i]].push_back(make_pair(a[i],i));
    }
    solve(N, std::move(a), std::move(b));
    return 0;
}


Measured memory_bytes: 11008
n, m = map(int, input().split())
l = []

for _ in range(m):
    s = list(map(int, input().split()))[1:]
    l.append(s)

p = list(map(int, input().split()))
ans = 0

for i in range(2 ** n):
    tmp = [0] * n
    flg = False
    for j in range(n):
        if i >> j & 1:
            tmp[j] = 1
    for i, s in enumerate(l):
        cnt = sum([tmp[e-1] for e in s])
        if cnt % 2 != p[i]:
            flg = True
            break
    if not flg:
        ans += 1

print(ans)



Measured memory_bytes: 74692
#include "bits/stdc++.h"
using namespace std;
const int MAX = 700000;
const int MOD = 1000000007;

long long  fac[MAX], finv[MAX], inv[MAX];

// テーブルを作る前処理
void COMinit() {
	fac[0] = fac[1] = 1;
	finv[0] = finv[1] = 1;
	inv[1] = 1;
	for (int i = 2; i < MAX; i++) {
		fac[i] = fac[i - 1] * i % MOD;
		inv[i] = MOD - inv[MOD % i] * (MOD / i) % MOD;
		finv[i] = finv[i - 1] * inv[i] % MOD;
	}
}

// 二項係数計算
long long COM(int n, int k) {
	if (n < k) return 0;
	if (n < 0 || k < 0) return 0;
	return fac[n] * (finv[k] * finv[n - k] % MOD) % MOD;
}
/*第二引数で第一引数を割ったときの切り上げの計算*/
long long int maxtime(long long int x, long long int y) {
	return(x + y - 1) / y;

}
/*最大公約数*/
long long int lcm(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;

	if (number2 > number1) {
		m = number2;
		n = number1;
	}
	long long int s = -1;
	while (s != 0) {
		s = m % n;
		m = n;
		n = s;
	}
	return m;
}
/*最大公倍数*/
long long int gcd(long long int number1, long long int number2) {
	long long int m = number1;
	long long int n = number2;
	return m / lcm(m, n) * n;
}
/*逆元計算*/
long long int  modinv(long long a, long long m) {
	long long int b = m, u = 1, v = 0;
	while (b) {
		long long int t = a / b;
		a -= t * b; swap(a, b);
		u -= t * v; swap(u, v);
	}
	u %= m;
	if (u < 0) u += m;
	return u;
}
// index が条件を満たすかどうか
vector<long long int >meguru;
bool isOK(int index, int key) {
	if (meguru[index] <= key) return true;
	else return false;
}
// 汎用的な二分探索のテンプレ
int binary_search(int key) {
	int left = -1; //「index = 0」が条件を満たすこともあるので、初期値は -1
	int right = (int)meguru.size(); // 「index = a.size()-1」が条件を満たさないこともあるので、初期値は a.size()
	/* どんな二分探索でもここの書き方を変えずにできる！ */
	while (right - left > 1) {
		int mid = left + (right - left) / 2;

		if (isOK(mid, key)) left = mid;
		else right = mid;
	}
	/* left は条件を満たす最大の値、right は条件を満たさない最小の値になっている */
	return left;
}
long long modpow(long long a, long long n, long long mod) {
	long long res = 1;
	while (n > 0) {
		if (n & 1) res = res * a % mod;
		a = a * a % mod;
		n >>= 1;
	}
	return res;
}
int main() {
	int n;
	cin >> n;
	vector<long long int >v;
	for (int i = 0; i < n; i++) {
		long long int a;
		cin >> a;
		v.push_back(a);
	}
	sort(v.begin(), v.end(), greater<long long int>());
	long long int sum = 0;
	for (int i = 1; i < n; i++) {
		int tmp = i / 2;
		sum = sum + v[tmp];
	}
	cout << sum << endl;
}

Measured memory_bytes: 5288
#include <bits/stdc++.h>
using namespace std;
#define int long long
typedef pair<int,int> P;
int INF = 1e9+7;
int mod = 1e9+7;
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0 , -1};
signed main(){
    int N;
    cin >> N;
    vector<int>a(N);
    map<int,int>Mp;
    for(int i = 0; i < N; i++) {
        cin >> a[i];
        Mp[a[i]]++;
    }
    if(Mp.size() == 1) {
        if(Mp[0] == N) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else if(Mp.size() == 2) {
        // 550550550
        if(N%3 == 0 && Mp[0] == N/3) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else if(Mp.size() == 3) {
        int ok = 0;
        for(P p:Mp) {
            ok^=p.first;
            if(p.second != N/3) {
                cout << "No" << endl;
                return 0;
            }
        }
        if(ok == 0) {
            cout << "Yes" << endl;
        }
        else {
            cout << "No" << endl;
        }
    }
    else {
        cout << "No" << endl;
    }
}


Measured memory_bytes: 8600
#include <stdio.h>
#include <math.h>
#include <iostream>
#include <algorithm>
#include <stdlib.h>
#include <string>
#include <string.h>
using namespace std;
typedef long long ll;
const int maxn = 2e5+5;
const double eps = 1e-8;

int num[maxn];

int main()
{
      int N;
      scanf("%d",&N);
      int temp;
	for(int i=1;i<=N;i++)
	{
		scanf("%d",&temp);
		num[temp] = i;
	}
	int ans = 1<<30;
	int cnt = 1;
      for(int i=2;i<=N;i++)
	{
		if (num[i] > num[i-1] ) cnt++;
		else
		{
			ans = min( ans , N - cnt);
			cnt = 1;
		}
	}
	if (ans == 1<<30) printf("0");
	else printf("%d",ans);
	return 0;
}


Measured memory_bytes: 1024
#include <bits/stdc++.h>
#define INF 1e9
using namespace std;

int func(int n){
    int res=0;
    while(n>0){
        res+=(n%10);
        n/=10;
    }
    return res;
}

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

    int n;
    cin>>n;
    int sum=func(n);
    if(n%sum==0)cout<<"Yes"<<endl;
    else cout<<"No"<<endl;

}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <math.h>
#include <vector>
#include <algorithm>
#include <iomanip>
#include <set>
#include <queue>
#include <map>
using namespace std;

#define mod 1000000007
#define ten5 100005
#define ten6 1000005
#define PI 3.1415926

typedef long long LL;


//int numAC[ten5];
//int numWA[ten5];

int main(void)
{
    long long int sum=0,range=0,ceiling;
    double ans=0.0,half;
    long long int m,n,o,i,j,k=0,money;
    long long int a1,a2=0,a3=0,ar,as,at1;
    char c;
    //vector <int> v;
    //float f,g,h;
    //int c,d,big=0;
    string s,s1;
    cin>>n>>m;
    if(m==n) cout<<"Yes";
    else
        cout<<"No";
    return 0;
}





Measured memory_bytes: 256
#include<stdio.h>
int main() {
    int i,n,m,sum=0,r;
    scanf("%d%d",&n,&m);
    int a[m];
    for ( i = 0; i < m; i++)
    {
        scanf("%d",&a[i]);
        sum=sum+a[i];
    }
    r=n-sum;
    if(r>=0)
    {
        printf("%d\n",r);
    }
    else
    {
          printf("%d\n",-1);
    }
    

    

    return 0;
}

Measured memory_bytes: 1744
n=int(input())
A=list(map(int,input().split()))
B=[0]*n

def countingSort(A,B,k):
  C=[0]*(k+1)

  for j in range(n):
    C[A[j]]+=1
  
  for i in range(1,k+1):
    C[i]=C[i]+C[i-1]

  for j in reversed(range(0,n)):
    #print(A[j])
    #print(C[A[j]])
    #print(B[C[A[j]]])
    #print('---')
    B[C[A[j]]-1]=A[j]
    C[A[j]]-=1

countingSort(A,B,max(A))
print(*B)



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

int main() {
  char x;
  cin >> x;
  
  if ((x-32)>=33 && (x-32)<=58)
    cout << 'A' << endl;
  else
    cout << 'a' << endl;
}

Measured memory_bytes: 3588
package main

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

func out(x ...interface{}) {
	fmt.Println(x...)
}

var sc = bufio.NewScanner(os.Stdin)

func getInt() int {
	sc.Scan()
	i, e := strconv.Atoi(sc.Text())
	if e != nil {
		panic(e)
	}
	return i
}

func getInts(N int) []int {
	ret := make([]int, N)
	for i := 0; i < N; i++ {
		ret[i] = getInt()
	}
	return ret
}

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

// min, max, asub, absなど基本関数
func max(a, b int) int {
	if a > b {
		return a
	}
	return b
}

func min(a, b int) int {
	if a < b {
		return a
	}
	return b
}

func asub(a, b int) int {
	if a > b {
		return a - b
	}
	return b - a
}

func abs(a int) int {
	if a >= 0 {
		return a
	}
	return -a
}

func lowerBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] >= x
	})
	return idx
}

func upperBound(a []int, x int) int {
	idx := sort.Search(len(a), func(i int) bool {
		return a[i] > x
	})
	return idx
}

func main() {
	sc.Split(bufio.ScanWords)
	N, M, K := getInt(), getInt(), getInt()
	a := getInts(N)
	b := getInts(M)
	sum := 0
	for i := 0; i < M; i++ {
		sum += b[i]
	}
	pos := M
	ans := 0
	for i := 0; i <= N; i++ {
		for pos > 0 && sum > K {
			pos--
			sum -= b[pos]
		}
		if sum > K {
			break
		}
		ans = max(ans, i+pos)
		if i != N {
			sum += a[i]
		}
	}
	out(ans)
}


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

using namespace std;

const int N = 100'009;

int a[N];
int b[N];

int main() {
  int na, nb, m;
  scanf("%d%d%d", &na, &nb, &m);
  int mna = 1'000'000'000;
  for (int i = 0; i < na; ++i) {
    scanf("%d", a + i);
    mna = min(mna, a[i]);
  }
  int mnb = 1'000'000'000;
  for (int i = 0; i < nb; ++i) {
    scanf("%d", b + i);
    mnb = min(mnb, b[i]);
  }
  int ans = mna + mnb;
  for (int i = 0; i < m; ++i) {
    int x, y, z;
    scanf("%d%d%d", &x, &y, &z);
    --x;
    --y;
    ans = min(ans, a[x] + b[y] - z);
  }
  printf("%d\n", ans);
}


Measured memory_bytes: 1024
// AOJ 2193: The Door into Summer
// 2018.1.7 bal4u@uu

#include <stdio.h>
#include <string.h>

#define MAX 100003
/* UNION-FIND library */
int p[MAX], rank[MAX];

//void make_set(int x) { p[x] = x, rank[x] = 0; }
void link(int x, int y) {
	if (rank[x] > rank[y]) p[y] = x;
	else { p[x] = y; if (rank[x] == rank[y]) rank[y] = rank[y] + 1;	}
}
int find_set(int x) { if (x != p[x]) p[x] = find_set(p[x]);	return p[x]; }
void union_set(int x, int y) { link(find_set(x), find_set(y)); }

#define QMAX 15000
typedef struct { int t, s; } QUE;
QUE que[QMAX]; int qsize;

#define PARENT(i) ((i)>>1)
#define LEFT(i)   ((i)<<1)
#define RIGHT(i)  (((i)<<1)+1)

void min_heapify(int i)
{
	int l, r, min;
	QUE qt;

	l = LEFT(i), r = RIGHT(i);
	if (l < qsize && que[l].t < que[i].t) min = l; else min = i;
	if (r < qsize && que[r].t < que[min].t) min = r;
	if (min != i) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		min_heapify(min);
	}
}

void deq()
{
//	if (qsize == 0) return 0;
//	*n = que[0].node, *t = que[0].t, *c = que[0].c;
	que[0] = que[--qsize];
	min_heapify(0);
//	return 1;
}

void enq(int s, int t)
{
	int i, min;
	QUE qt;

	i = qsize++;
	que[i].s = s, que[i].t = t;
	while (i > 0 && que[min = PARENT(i)].t > que[i].t) {
		qt = que[i], que[i] = que[min], que[min] = qt;
		i = min;
	}
}

#define INF 0x10101010
int n;
int to[MAX][20]; char hi[MAX];
int goal[MAX], gsz;
int lpos[MAX], lsz;
int gdist[MAX], ndist[MAX], ldist[MAX];

//#define getchar_unlocked()  getchar()
int in()
{
	int n = 0;
	int c = getchar_unlocked();
	do n = (n<<3)+(n<<1) + (c & 0xf), c = getchar_unlocked();
	while (c >= '0');
	return n;
}

void dijkstra(int *dist, int *start, int sz)
{
	int i, s, d, e;

	memset(dist, INF, n << 2);
	qsize = 0;
	for (i = 0; i < sz; i++) dist[start[i]] = 0, enq(start[i], 0);
	while (qsize) {
		s = que[0].s, d = que[0].t, deq();
		for (i = 0; i < hi[s]; i++) {
			e = to[s][i];
			if (d+1 < dist[e]) dist[e] = d+1, enq(e, d+1);
		}
	}
}

int main()
{
	int cno, m, npos, i, a, b, c, ans;

	cno = in();
	while (cno--) {
		n = in()+1, m = in();

		memset(hi, 0, n);
		memset(rank, 0, n<<2);			// union set, <<2 = 4 = sizeof(int)
		for (i = 0; i < n; i++) p[i] = i;
		gsz = lsz = 0;

		npos = in(), a = in();	// initial position
		goal[gsz++] = 0;
		lpos[lsz++] = a;

		for (i = 0; i < m; i++) {
			a = in(), b = in(), c = getchar_unlocked(), getchar_unlocked();
			if (c == 'N') to[a][hi[a]++] = b, to[b][hi[b]++] = a;
			else union_set(a, b);
		}

		a = find_set(0), b = find_set(lpos[0]);
		if (find_set(0) == b) { puts("0"); continue; }
		for (i = 0; i < n; i++) {
			if ((c = find_set(i)) == a) goal[gsz++] = i;
			if ( c                == b) lpos[lsz++] = i;
		}

		dijkstra(gdist, goal, gsz);
		dijkstra(ldist, lpos, lsz);
		lpos[0] = npos;
		dijkstra(ndist, lpos, 1);

		ans = INF;
		for (i = 1; i < n; i++) {
			a = gdist[i]+ndist[i]+ldist[i];
			if (a < ans) ans = a;
		}
		printf("%d\n", ans);
	}
	return 0;
}



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

typedef long long ll;

const ll mod = 1e9 + 7;
ll dp[2005];

int main(){
    ll n; cin>>n;
    dp[0] = 1;
    for(int i = 3; i <= n; i++){
        for(int j = i - 3; j >= 0; j--){
            dp[i] = (dp[i] + dp[j]) % mod;
        }
    }
    cout<<dp[n]<<endl;
}


Measured memory_bytes: 3612
function Main(input) {
  line = input.split(' ');
  for (var i = 0; i < line.length; i++) {
    line[i] = parseInt(line[i]);
  }
  if (line[0] < line[1] && line[1] < line[2]) {
    console.log('Yes');
  } else {
    console.log('No');
  }
}
/*
function debug() {
  var input = document.getElementById('id1').value;
  Main(input);
}
*/

Main(require("fs").readFileSync("/dev/stdin", "utf8"));



Measured memory_bytes: 15096
#include <stdio.h>
#include <math.h>
#include <string.h>
#include <stdlib.h>
#include <time.h>

////////////////*My library*////////////////////////
#define rep_to(a,i,n) for(i=a;i<n;i++)
#define rep(i,n) for(i=0;i<n;i++)
#define rep_r(i,n) for(i=n-1;i>=0;i--)
#define debug_i(x) printf("x:%d\n",x)
#define debug_f(x) printf("x:%f\n",x)
#define debug_s(str) printf("str:%s\n",str)
#define debug_c(c) printf("c:%c\n",c)
#define s_i1(x) scanf("%d",&x)
#define s_i2(x,y) scanf("%d %d",&x,&y)
#define s_i3(x,y,z) scanf("%d %d %d",&x,&y,&z)
////////////////////////////////////////////////////
////////////////////////
/*prime()*/
/*primecount()*/
/*sort()*/
///////////////////////
int main()
{
	int i,j;
	int n,num[100000]={},key;

	while(1)
	{
		s_i1(n);
		if(n==0)break;
		rep(i,n)s_i1(num[i]);
		s_i1(key);

	/////????????¢?´¢//////////////////

		int min=0;
		int max=n-1;
		int mid=(min+max)/2;
		int count=0;
		while(min<=max)
		{
			count++;
			mid=(min+max)/2;
			if(key==num[mid])break;
			else if(key>num[mid])min=mid+1;
			else if(key<num[mid])max=mid-1;
		}
	///////////////////////////////
	printf("%d\n",count);
	}
return 0;
}

Measured memory_bytes: 1424
#include<bits/stdc++.h>
using namespace std;
const long long mod=1000000000+7;
int a[2000],n,k,a2[2000],a3[2000];
int main(){
	cin>>n>>k;
	for(int i=0;i<n;i++)
	cin>>a[i];
	for(int i=0;i<n;i++){
		for(int j=i+1;j<n;j++)
		if(a[i]>a[j])
		a2[i]++;
		for(int j=i-1;j>=0;j--)
		if(a[i]>a[j])
		a3[i]++;
	}
	long long ans=0;
	for(int i=0;i<n;i++){
		long long ans1=a2[i];
		ans1*=(k+1);
		ans1%=mod;
		ans1*=k/2;
		ans1%=mod; 
		if(k%2){
			long long dd=a2[i];
			dd*=(k/2+1);
			ans1+=dd;
		}
		ans1%=mod;
		ans+=ans1;
		ans%=mod;
		ans1=a3[i];
		ans1*=k;
		ans1%=mod;
		ans1*=(k-1)/2;
		ans1%=mod; 
		if(k%2==0){
			long long dd=a3[i];
			dd*=((k-1)/2+1);
			ans1+=dd;
		}
		ans1%=mod;
		ans+=ans1;
		ans%=mod;
	}
	cout<<ans;
	return 0;
} 

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <stack>
#include <cmath>
#include <iomanip>
#include <algorithm>
using namespace std;
using ll = long long;

void print_ans(bool flag){
    if(flag){
        cout << "Yes" << endl;
    } else {
        cout << "No" << endl;
    }   
}

int main(){
    ll n, q;
    ll k;
    cin >> n >> k >> q;
    ll ans[n];
    ll a;
    for(int i = 0; i < n; i++){
        ans[i] = k - q;
    }
    for(int i = 0; i < q; i++){
        cin >> a;
        ans[a-1]++;
    }
    for(int i = 0; i < n; i++){
        print_ans(ans[i] > 0);
    }
    return 0;
}


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

int main()
{
    ll n, m;
    cin >> n >> m;
    n = min(n, m / 2);
    m = m - n * 2;
    cout << n + m / 4 << endl;
    return 0;
}


Measured memory_bytes: 256
def main():
    a, b, c, k = input_list()

    if a == k:
        print(a)
        exit()

    if a > k:
        print(k)
        exit()

    ans = a
    nokori = k - a
    if nokori <= b:
        print(ans)
    else:
        nokori -= b
        ans += nokori * -1
        print(ans)

def input_list():
    return list(map(int, input().split()))


if __name__ == '__main__':
    main()


Measured memory_bytes: 61696
N = int(input())

dp = [None for _ in range(N+1)]
dp[0] = 0

for i in range(1, N+1):
    dp[i] = 100001
    p = 1
    while p <= i:
        dp[i] = min(dp[i], dp[i-p]+1)
        p *= 6
    p = 1
    while p <= i:
        dp[i] =min(dp[i], dp[i-p]+1)
        p *= 9
    
print(dp[N])


Measured memory_bytes: 3864
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <climits>
#include <cfloat>
#include <map>
#include <utility>
#include <set>
#include <iostream>
#include <memory>
#include <string>
#include <vector>
#include <algorithm>
#include <functional>
#include <sstream>
#include <complex>
#include <stack>
#include <queue>
using namespace std;
static const double EPS = 1e-5;
typedef long long ll;
#define FOR(i,n) for(i=0;i<n;i++)
#define rep(i,n) for(int i=0;i<n;i++)

int main(){
	int a,b;
	for(;scanf("%d %d",&a,&b)!=EOF;){
		int i=0,k=1;
		for(;a+b>=k;i++,k*=10);
		cout<<i<<endl;
	}
	return 0;
}

Measured memory_bytes: 0
#include <iostream>
#include <algorithm>

using namespace std;

int main(){
    long A, B, Q;
    long s[100000];
    long t[100000];
    cin >> A >> B >> Q;
    for(int i = 0; i < A; i++){
        cin >> s[i];
    }
    for(int i = 0; i < B; i++){
        cin >> t[i];
    }
    sort(s, s+A);
    sort(t, t+B);
    for(int i = 0; i < Q; i++){
        long x;
        cin >> x;
        long *sl = lower_bound(s, s+A, x);
        long *tl = lower_bound(t, t+B, x);
        //cout << x << ' ' << *sl << ' ' << *tl << endl;
        if(s[0] >= x){
            if(t[0] >= x){
                cout << max(s[0]-x, t[0]-x) << endl;
            }else if(t[B-1] < x){
                cout << s[0]-t[B-1]+min(s[0]-x, x-t[B-1]) << endl;
            }else{
                cout << min(s[0]-*(tl-1)+min(s[0]-x, x-*(tl-1)), max(s[0]-x, *tl-x)) << endl;
            }
        }else if(s[A-1] <= x){
            if(t[0] >= x){
                cout << t[0]-s[A-1]+min(t[0]-x, x-s[A-1]) << endl;
            }else if(t[B-1] <= x){
                cout << max(x-s[A-1], x-t[B-1]) << endl;
            }else{
                cout << min(*tl-s[A-1]+min(*tl-x, x-s[A-1]), max(x-s[A-1], x-*(tl-1))) << endl;
            }
        }else if(t[0] >= x){
            cout << min(t[0]-*(sl-1)+min(t[0]-x, x-*(sl-1)), max(*sl-x, t[0]-x)) << endl;
        }else if(t[B-1] <= x){
            cout << min(*(sl)-t[B-1]+min(*(sl)-x, x-t[B-1]), max(x-t[B-1], x-*(sl-1))) << endl;
        }else if(*sl-x < x-*(sl-1)){
            if(*tl-x < x-*(tl-1)){
                cout << max(*tl-x, *sl-x) << endl;
            }else{
                cout << min((x-*(tl-1))+(*sl-x)+min((x-*(tl-1)), (*sl-x)), min(max(x-*(tl-1), x-*(sl-1)), max(*tl-x, *sl-x))) << endl;
            }
        }else{
            if(*tl-x >= x-*(tl-1)){
                cout << max(x-*(tl-1), x-*(sl-1)) << endl;
            }else{
                //cout << min((x-*(tl-1))+(*sl-x)+min((x-*(tl-1)), (*sl-x)), min(max(x-*(tl-1), x-*(sl-1)), max(*tl-x, *sl-x))) << endl;
                cout << min((*tl-x)+(x-*(sl-1))+min((*tl-x), (x-*(sl-1))), min(max(x-*(tl-1), x-*(sl-1)), max(*tl-x, *sl-x))) << endl;
            }
        }
    }
}

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

int main(){
    int n, m;
    cin >> n >> m;
    vector<int> ans(n);
    for (int i = 0; i < 2 * m; i++) {
        int ab;
        cin >> ab;
        ans[ab - 1]++;
    }
    for (int i = 0; i < n; i++)
    cout << ans[i] << endl;
}

Measured memory_bytes: 256