akhauriyash/Code-Regression huggingface dataset:
macro_rules! get {
    ($t:ty) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.trim().parse::<$t>().unwrap()
        }
    };
    ($($t:ty),*) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            let mut iter = line.split_whitespace();
            (
                $(iter.next().unwrap().parse::<$t>().unwrap(),)*
            )
        }
    };
    ($t:ty; $n:expr) => {
        (0..$n).map(|_|
                    get!($t)
        ).collect::<Vec<_>>()
    };
    ($($t:ty),*; $n:expr) => {
        (0..$n).map(|_|
                    get!($($t),*)
        ).collect::<Vec<_>>()
    };
    ($t:ty |) => {
        {
            let mut line: String = String::new();
            std::io::stdin().read_line(&mut line).unwrap();
            line.split_whitespace()
                .map(|t| t.parse::<$t>().unwrap())
                .collect::<Vec<_>>()
        }
    };
    ($t:ty | $n:expr) => {
        (0..$n).map(|_| get!($t |)).collect::<Vec<_>>()
    };
}

fn get_sum(map: &Vec<Vec<char>>) -> Option<usize> {
    let mut visited: Vec<Vec<bool>> = map.iter().map(|row| row.iter().map(|c| false).collect()).collect();
    let mut q = std::collections::VecDeque::new();
    q.push_back((0, 0, 1));
    while q.len() > 0 {
        let (x, y, sum) = q.pop_front().expect("A");
        if y == map.len()-1 && x == map[0].len()-1 {
            return Some(sum);
        }
        if y > 0 {
            if map[y-1][x] == '.' && !visited[y-1][x] {
                visited[y-1][x] = true;
                q.push_back((x, y-1, sum + 1));
            }
        }
        if y < map.len() - 1 {
            if map[y+1][x] == '.' && !visited[y+1][x] {
                visited[y+1][x] = true;
                q.push_back((x, y+1, sum + 1));
            }
        }
        if x > 0 {
            if map[y][x-1] == '.' && !visited[y][x-1] {
                visited[y][x-1] = true;
                q.push_back((x-1, y, sum + 1));
            }
        }
        if x < map[0].len() - 1 {
            if map[y][x+1] == '.' && !visited[y][x+1] {
                visited[y][x+1] = true;
                q.push_back((x+1, y, sum + 1));
            }
        }
    }
    return None;
}

fn main() {
    let (H, W) = get!(usize, usize);
    let map = get!(String; H)
        .iter()
        .map(|s| s.chars().collect::<Vec<_>>())
        .collect::<Vec<_>>();
    let sum = get_sum(&map);
    let white = map.iter().flat_map(|row| row.iter()).fold(0, |sum, &c| sum + if c == '.' {
        1
    } else {
        0
    });
    if let Some(sum) = sum {
        if white > 0 {
            println!("{}", white - sum);
        } else {
            println!("-1");
        }
    } else {
        println!("-1");
    }
}


Measured memory_bytes: 4352
// Frog 2 https://atcoder.jp/contests/dp/tasks/dp_b
#include <bits/stdc++.h>
using namespace std;

const int INF = 1e9 + 5;

int n, k;
vector<int> h;
vector<int> memo;
vector<bool> computed;

// rec(x) is best score to get to position x
int rec(int pos) {
	if(pos == 0) {
		return 0;
	}
	if(computed[pos]) {
		return memo[pos];
	}
	int best = INF;
	for(int jump = 1; jump <= k && pos - jump >= 0; ++jump) {
		best = min(best, rec(pos - jump) + abs(h[pos] - h[pos-jump]));
	}
	computed[pos] = true;
	return memo[pos] = best;
}

int solve1() {
	return rec(n-1);
}

int solve2() { // pull dp
	vector<int> dp(n);
	for(int i = 1; i < n; i++) {
		dp[i] = INF; // and now compute dp[i]
		for(int jump = 1; jump <= k && i - jump >= 0; ++jump) {
			dp[i] = min(dp[i], dp[i-jump] + abs(h[i]-h[i-jump]));
		}
	}
	return dp[n-1];
}

int solve3() { // push dp
	vector<int> dp(n, INF);
	dp[0] = 0;
	for(int i = 0; i <= n - 2; ++i) {
		for(int jump = 1; jump <= k && i + jump < n; ++jump) {
			dp[i+jump] = min(dp[i+jump], dp[i] + abs(h[i]-h[i+jump]));
		}
	}
	return dp[n-1];
}

int main() {
	cin >> n >> k;
	h.resize(n);
	memo.resize(n, 0);
	computed.resize(n, false);
	for(int& x : h) {
		cin >> x;
	}
	cout << solve3();
}


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

const int maxn = 10e5 + 5;

int n,x,a[maxn],ans,maxx;

int gcd(int a,int b)
{
	if(!b) return a;
	return gcd(b,a%b);
}

int main()
{
	scanf("%d%d",&n,&x);
	for(int i=1;i<=n;i++)
		scanf("%d",&a[i]);
	int ans=0;
	for(int i=1;i<=n;i++) ans=gcd(ans,abs(x-a[i]));
	printf("%d",ans);
	return 0;
}

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

A = []
for _ in range(N):
    A.append(int(input()))

if sum(A) % 10 != 0:
    print(sum(A))
else:
    A.sort()
    ans = 0
    for i in range(N):
        if (sum(A) - A[i]) % 10 != 0:
            ans = sum(A) - A[i]
            break

    print(ans)

Measured memory_bytes: 38384
A = [list(map(int, input().split())) for _ in range(3)]
N = int(input())
B = [int(input()) for _ in range(N)]
card = [[False] * 3 for _ in range(3)]
for i in range(3):
    for j in range(3):
        card[i][j] = A[i][j] in B
for triple in (
    ((0, 0), (0, 1), (0, 2)),
    ((1, 0), (1, 1), (1, 2)),
    ((2, 0), (2, 1), (2, 2)),
    ((0, 0), (1, 0), (2, 0)),
    ((0, 1), (1, 1), (2, 1)),
    ((0, 2), (1, 2), (2, 2)),
    ((0, 0), (1, 1), (2, 2)),
    ((0, 2), (1, 1), (2, 0)),
):
    ok = True
    for i, j in triple:
        if not card[i][j]:
            ok = False
    if ok:
        print("Yes")
        break
else:
    print("No")


Measured memory_bytes: 3064
parseInt(x)=parse(Int, x)
parseMap(x::Array{SubString{String},1})=map(parseInt, x)

function main()
	n = readline() |> parseInt
	b = readline() |> split |> parseMap
	a = copy(b)
	d = Dict{Int,Int}()
	f = 0
	for i in 1:n
		x = 2
		df = 0
		while a[i]>1 && x*x<=a[i]
			if a[i]%x == 0
				if haskey(d,x)&&df==0
					f = 1
				else
					d[x] = 1
				end
				a[i] = x*x==a[i] ? 1 : div(a[i],x)
				df = 1
			else
				x += 1
				df = 0
			end
		end
		if a[i] > 1
			if haskey(d,a[i])
				f = 1
			else
				d[a[i]] = 1
			end
		end
	end
	if f == 0
		println("pairwise coprime")
	else
		k = b[1]
		for i in 2:n
			k = gcd(k,b[i])
		end
		println(k==1 ? "setwise coprime" : "not coprime")
	end
end

main()

Measured memory_bytes: 255396
import java.util.Scanner;
public class Main{
  public static void main(String... args){
    Scanner sc = new Scanner(System.in);
    int N = sc.nextInt();
    
    if(N%2 == 0){
      System.out.println(N/2 - 1);
    }else{
      System.out.println(N/2);
    }
  }
}

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

int main() {
    ios_base::sync_with_stdio(0);
    cin.tie(0);
    cout.tie(0);
    int n;
    cin >> n;
    map<string, int> mp;
    for(int i = 0; i < n; i++) {
        string s;
        cin >> s;
        mp[s]++;
    }
    cout << mp.size() << endl;
    return 0;
}


Measured memory_bytes: 19204
#include <iostream>

inline void fastin(int &num) {
    bool neg = false;
    int c;
    num = 0;
    c = getchar_unlocked();
    if (c == '-') {
        neg = true;
        c = getchar_unlocked();
    }
    for (; (c > 47 && c < 58); c = getchar_unlocked()) num = num * 10 + c - 48;
    if (neg) num *= -1;
}

inline void fastout(int n) {
    int N = n, rev, count = 0;
    rev = N;
    if (N == 0) { putchar_unlocked('0'); putchar_unlocked('\n'); return ;}
    while ((rev % 10) == 0) { ++count; rev /= 10;}
    rev = 0;
    while (N != 0) { rev = (rev<<3) + (rev<<1) + N % 10; N /= 10;}
    while (rev != 0) { putchar_unlocked(rev % 10 + '0'); rev /= 10;}
    while (count--) putchar_unlocked('0');
}

int main(){    
    int n, m, Q; fastin(n); fastin(m); fastin(Q);
    int square[n + 5][n + 5] = {};
    for (int i = 0; i < m; ++i){
      int l, r;
      fastin(l); fastin(r); ++square[l][r];
    }

    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= n; ++j){
            square[i][j] += square[i][j - 1];
        }
    }

    for (int i = 1; i <= n; ++i){
        for (int j = 1; j <= n; ++j){
            square[i][j] += square[i - 1][j];
        }
    }

    for (int i = 0; i < Q; ++i){
        int p, q; fastin(p); fastin(q);
        fastout(square[q][q] + square[p - 1][p - 1] - square[p - 1][q] - square[q][p - 1]); putchar_unlocked('\n');
    }
    
    return 0;
}

Measured memory_bytes: 1920
import bisect
import math
MAX = 10**5

res = [3]
def prime(x):
    for i in range(2,int(math.sqrt(x))+1):
        if x%i == 0:
            return False
    return True
for i in range(3,MAX,2):
    if prime(i) and prime(i*2-1):
        res.append(i*2-1)

q = int(input())

for i in range(q):
    l,r = map(int,input().split())
    print(bisect.bisect_right(res,r)-bisect.bisect_left(res,l))



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

typedef long long ll;
typedef double dd;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int,int> pii;

const int mx=1e6+11;
const double PI = acos(-1);
#define MOD 1000000007


#define nl '\n'
#define pb push_back
#define F first
#define S second
#define I insert
#define mp make_pair

#define sz(x) x.size()
#define sa(v) sort(v.begin(),v.end())
#define sd(v) sort(v.begin(),v.end(),greater<>())
#define rev(s) reverse(s.begin(),s.end())
#define tt int t; cin>>t; while(t--)
#define lo(i,a,b) for(ll i=a;i<b;i++)
#define be(a) (a).begin(),(a).end()
#define rbe(a) (a).rbegin(),(a).rend()

#define sqr(a) ((a) * (a))
#define gcd(a,b) __gcd(a,b)
#define lcm(a,b) (a*(b/gcd(a,b)))
#define mem(a,b) memset(a,b,sizeof(a))

#define yes cout<<"YES"<<nl;
#define no cout<<"NO"<<nl;

#define su ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
#define file freopen("input.txt","r",stdin);freopen("output.txt","w",stdout);
#define frac cout.unsetf(ios::floatfield); cout.precision(10); cout.setf(ios::fixed,ios::floatfield);

#include <ext/pb_ds/assoc_container.hpp>
using namespace __gnu_pbds;
typedef tree< long long, null_type, less_equal<long long>, rb_tree_tag, tree_order_statistics_node_update > ordered_set;
void erase ( ordered_set &s, long long val )
{
    auto it = s.upper_bound(val);

    if ( it == s.begin() && val == *s.begin() )
        s.erase ( s.upper_bound(val) );
    else
        s.erase ( s.upper_bound(val) );
}

#define dbg(args...) do {cerr << #args << " : "; faltu(args); } while(0)
void faltu ()
{
    cerr << endl;
}
template < typename T, typename ... hello>void faltu( T arg, const hello &... rest)
{
    cerr << arg << ' ';
    faltu(rest...);
}


int main()
{
    su;
    int l,r,d;
    cin>>l>>r>>d;
    if(l%d==0)
      cout<<r/d-l/d+1;
    else
      cout<<r/d-l/d;
    cout<<nl;
    return 0;
}


Measured memory_bytes: 3652
#include "bits/stdc++.h"
using namespace std;
#ifdef _DEBUG
#include "dump.hpp"
#else
#define dump(...)
#endif

//#define int long long
#define rep(i,a,b) for(int i=(a);i<(b);i++)
#define rrep(i,a,b) for(int i=(b)-1;i>=(a);i--)
#define all(c) begin(c),end(c)
const int INF = sizeof(int) == sizeof(long long) ? 0x3f3f3f3f3f3f3f3fLL : 0x3f3f3f3f;
const int MOD = (int)(1e9) + 7;
const double PI = acos(-1);
const double EPS = 1e-9;
template<class T> bool chmax(T &a, const T &b) { if (a < b) { a = b; return true; } return false; }
template<class T> bool chmin(T &a, const T &b) { if (a > b) { a = b; return true; } return false; }

signed main() {
	cin.tie(0);
	ios::sync_with_stdio(false);
	int N; cin >> N;
	vector<int> s(N); rep(i, 0, N) { cin >> s[i]; }
	vector<int>dp(100 * 100 + 1, 0);
	dp[0] = 1;
	int ans(0);
	rep(i, 0, N)rrep(j, s[i], dp.size())
		chmax(dp[j], dp[j - s[i]]);
	rrep(i, 0, dp.size()) {
		if (dp[i] == 1 && i % 10 != 0) {
			chmax(ans, i);
		}
	}
	cout << ans << endl;
	return 0;
}

Measured memory_bytes: 256
import std.stdio;
import std.string;
import std.conv;
import std.algorithm;
import std.array;

void main() {
  long n, m;
  readf("%d %d\n", &n, &m);

  auto xs = new long[](m);
  foreach (_; 0..n) {
    auto ys = readln.strip.split(" ").map!(to!int).array;
    foreach (y; ys[1..$]) {
      xs[y-1]++;
    }
  }

  writeln(xs.count(n));


}


Measured memory_bytes: 256
#include <iostream>
#include <queue>
#include <vector>
#include <iostream>
#include <vector>
#include <cassert>
#include <algorithm>
#include <functional>
#include <cmath>
#include <queue>
#include <set>
#include <stack>
#include <deque>
#include <map>
using ll=long long;
using namespace std;
//const int INF = 7+(1e+9);
ll GCD(ll x, ll y)
{
    if (y == 0)
    {
        return x;
    }
    else
    {
        return GCD(y, x % y);
    }
}
ll LCM(ll x, ll y)
{
    return x / GCD(x, y) * y;
}
struct UnionFind {
    vector<int> par; // par[i]:iの親の番号　(例) par[3] = 2 : 3の親が2
    UnionFind(int N) : par(N) { //最初は全てが根であるとして初期化
        for(int i = 0; i < N; i++) par[i] = i;
    }

    int root(int x) { // データxが属する木の根を再帰で得る：root(x) = {xの木の根}
        if (par[x] == x) return x;
        return par[x] = root(par[x]);
    }

    void unite(int x, int y) { // xとyの木を併合
        int rx = root(x); //xの根をrx
        int ry = root(y); //yの根をry
        if (rx == ry) return; //xとyの根が同じ(=同じ木にある)時はそのまま
        par[rx] = ry; //xとyの根が同じでない(=同じ木にない)時：xの根rxをyの根ryにつける
    }

    bool same(int x, int y) { // 2つのデータx, yが属する木が同じならtrueを返す
        int rx = root(x);
        int ry = root(y);
        return rx == ry;
    }
};
vector<vector<char>> vec(12,vector<char>(12));

int dx[]={0,-1,0,1};
int dy[]={1,0,-1,0};
int dfs(int y,int x){
    vec[y][x]='5';
    for(int i=0;i<4;i++){
        if(x+dx[i]<12&&x+dx[i]>=0&&y+dy[i]<12&&y+dy[i]>=0&&vec[dy[i]+y][dx[i]+x]=='1'){
            dfs(y+dy[i],x+dx[i]);
        }
    }
    return 0;
}

int main(){
    ll k;cin>>k;
    int c=0;
    ll n=1;
    while(1){
        c++;
        n*=3;
      //  cout<<n<<nd
        if(n>=k){
            break;
        }
    }
    cout<<c<<endl;
}


Measured memory_bytes: 3108
import math


def main():
    nvertices, nedges, s = map(int, input().split())
    E = []
    for i in range(nedges):
        u, v, w = map(int, input().split())
        E.append((u, v, w))

    INF = float('inf')
    d = [INF] * nvertices
    d[s] = 0
    for i in range(nvertices - 1):
        for u, v, w in E:
            if d[u] + w < d[v]:
                d[v] = d[u] + w

    for i in range(nvertices - 1):
        for u, v, w in E:
            if d[v] > d[u] + w:
                print("NEGATIVE CYCLE")
                return

    for val in d:
        if math.isinf(val):
            print("INF")
        else:
            print(val)


main()

Measured memory_bytes: 8164
#include <iostream>
#include <vector>
#include <string>
#include <map>
#include <list>
#include <set>
#include <stack>
#include <deque>
#include <queue>
#include <cmath>
#include <algorithm>
#include <utility>
#include <functional>
#include <fstream>
#define debug(x) cout << #x << " = " << x << endl
#define FOR(i,a,b) for(int i = (a); i < (b); i++)
#define rep(i,n) for(int i = 0; i < (n); i++)
#define repr(i,n) for(int i = (n); i > -1; i--)
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const int MOD = 1000000007;
const double EPS = 1e-9;


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

  ll n;
  cin>>n;
  ll t[n], a[n];
  rep(i,n) cin>>t[i]>>a[i];
  if(n == 1) {
    cout << t[0] + a[0] << endl;
    return 0;
  }
  FOR(i, 1, n) {
    if(t[i] < t[i-1] || a[i] < a[i-1]) {
      ll nt = (t[i-1] - 1) / t[i];
      ll na = (a[i-1] - 1) / a[i];
      ll k = max(nt, na);
      t[i] = t[i] * k + t[i];
      a[i] = a[i] * k + a[i];
    }
  }
  cout << t[n-1] + a[n-1] << endl;

  return 0;
}


Measured memory_bytes: 256
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.Scanner;

public class Main {
    public static void main(String[] args) {
        Main main = new Main();
        main.solve();
    }
    public void solve() {
        Scanner scan = new Scanner(new BufferedReader(new InputStreamReader(System.in)));
        int N = scan.nextInt();
        int H = scan.nextInt();
        int W = scan.nextInt();
        int high = N - H + 1;
        int col = N - W + 1;
        System.out.println(high*col);
    }
}


Measured memory_bytes: 21844
def gen_factorization(N):
    tables=[-1]*(N+1)
    for i in range(2,N+1):
        if tables[i]!=-1:continue
        tmp=i
        while tmp<=N:
            tables[tmp]=i
            tmp+=i
    def fuctorization(n):
        if n==1:return {1:1}
        elif n<0:n=abs(n)
        if n>N:return "error"
        ans={}
        while n!=1:
            tmp=tables[n]
            #debug print
            #print(tmp,n)
            ans.setdefault(tmp,0)
            ans[tmp]+=1
            n//=tmp
        return ans
    return fuctorization

N=int(input())
f=gen_factorization(10**6+10)
A=list(map(int,input().split()))
primes={}
for i in A:
  d=f(i)
  for j in d:
    primes.setdefault(j,0)
    primes[j]+=1
primes[1]=1
ansMax=max(primes.values())

if ansMax==1:
  print('pairwise coprime')
elif ansMax==N:
  print('not coprime')
else:
  print('setwise coprime')

Measured memory_bytes: 213408
use std::vec::Vec;

fn read<T: std::str::FromStr>() -> T {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    s.trim().parse().ok().unwrap()
}

fn read_vec<T: std::str::FromStr>() -> Vec<T> {
    read::<String>().split_whitespace().map(|e| e.parse().ok().unwrap()).collect()
}

fn read_touple<T: std::str::FromStr + Copy>() -> (T, T) {
  let v: Vec<T> = read_vec();
  assert_eq!(v.len(), 2);
  (v[0], v[1])
}

fn main() {
  let (n, p) = read_touple();
  let s: Vec<usize> = read::<String>()
                        .chars()
                        .rev()
                        .map(|c| c as usize - '0' as usize)
                        .collect();

  let mut ans = 0;
  if p == 2 || p == 5 {

    for i in 0..n {
      if s[i] % p == 0 {
        ans += (n - i);
      }
    }
    println!("{}", ans);
    return
  } 

  let mut sum = vec![0; n+1];
  let mut c = 1;
  for i in 0..n {
    sum[i+1] =  sum[i] + c * s[i];
    sum[i+1] %= p;
    c *= 10;
    c %= p;
  }

  let mut count = vec![0; p];

  for i in 0..n+1 {
    let e = sum[i];
    count[e] += 1;
  } 

  for &c in &count {
    //println!("{} {}", c, (c * (c-1)) / 2);
    ans += ((c-1) * c) / 2;
  }

  //println!("{:?}", sum);
  //println!("{:?}", count);
  println!("{}", ans);
}


Measured memory_bytes: 8444
// nlather (Nishant Raj Lather)
// Chrollo_Lucifer

#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;
template <typename T>
using ordered_set = tree<T, null_type, less<T>, rb_tree_tag, tree_order_statistics_node_update>;

#define MOD 1e9+7
#define boost ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define rep(i, x, n) for(ll i = x; i < n; i++)
#define rrep(i, x, n) for(ll i = x; i >= n; i--)
#define all(v) v.begin(),v.end()
#define endl '\n'
#define ff first
#define ss second
#define pb push_back
#define eb emplace_back
#define e emplace
#define mp make_pair
double PI=3.14159265358979323846;
typedef long long int ll;
typedef long double ld;
typedef pair< ll, ll > pii;
typedef vector< ll > vi;
typedef vector< vi > vvi;

ll dp[105][300005];
ll w[105];
ll v[105];
ll n, www;

ll solve(ll i = 0, ll ww = 0) {
  	if(dp[i][ww]) return dp[i][ww];
	if(ww > www) return LONG_MIN;
	if(i >= n or ww == www) return 0;
	return dp[i][ww] = max(solve(i + 1, ww), v[i] + solve(i + 1, ww + w[i]));
}

int main()
{
	boost
	cin >> n >> www;
	rep(i, 0, n) cin >> w[i] >> v[i];
	cout << solve();
}

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

#define ll long long int
#define pi 3.141592653589793238
#define FAST ios_base::sync_with_stdio(0); cin.tie(0); cout.tie(0)
#define mod 1000000007
ll dx[4]={0,0,1,-1};
ll dy[4]={-1,1,0,0};


void solve()
{
    string s,t;
    cin>>s>>t;
    int n=s.size();
    int m=t.size();
    int ans=m;
    for(int i=0;i<=n-m;i++)
    {
        int cnt=0;
        for(int j=0;j<m;j++)
        {
            // cout<<s[i+j]<<t[j]<<" ";
            if(s[i+j]!=t[j])
                cnt++;
        }
        // cout<<cnt<<endl;
        ans=min(ans,cnt);
    }
    cout<<ans;
    return;
}

int main()
{
	FAST;
    ll q;
    q=1;
    // cin>>q;
    while(q--)
        solve();
	return 0;
}

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

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<double> vd;
typedef vector<ll> vl;
typedef vector<vi> vvi;
typedef vector<vl> vvl;
typedef pair<int,int> pii;
typedef pair<double, double> pdd;
typedef pair<ll, ll> pll;
typedef vector<pii> vii;
typedef vector<pll> vll;
typedef vector<pdd> vdd;

#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define mem(a,b) memset(a, b, sizeof(a) )
#define all(x) (x).begin(),(x).end()
#define INF 1000000000000
#define MOD 1000000007
#define PB push_back
#define MP make_pair
#define F first
#define S second

inline void normal(ll &a) { a %= MOD; (a < 0) && (a += MOD); }
inline ll modMul(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a*b)%MOD; }
inline ll modAdd(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); return (a+b)%MOD; }
inline ll modSub(ll a, ll b) { a %= MOD, b %= MOD; normal(a), normal(b); a -= b; normal(a); return a; }
inline ll modPow(ll b, ll p) { ll r = 1; while(p) { if(p&1) r = modMul(r, b); b = modMul(b, b); p >>= 1; } return r; }
inline ll modInverse(ll a) { return modPow(a, MOD-2); }
inline ll modDiv(ll a, ll b) { return modMul(a, modInverse(b)); }

ll gcd(ll a,ll b){return b?gcd(b,a%b):a;}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

int ctoi(char c) {
	if (c >= '0' && c <= '9') {
		return c - '0';
	}
	return 0;
}

int main(){
    ll n;cin>>n;
    vl a(n),c(n),d;
    map<ll,ll>b;
    ll sum=0;
    rep(i,n){
        cin>>a[i];
        c[i]=a[i];
        b[a[i]]++;
    }
    sort(all(c));
    c.erase(unique(all(c)),c.end());
    rep(i,c.size()){
        sum+=b[c[i]]*(b[c[i]]-1)/2;
    }
    rep(i,a.size()){
        cout<<sum-b[a[i]]*(b[a[i]]-1)/2+(b[a[i]]-1)*(b[a[i]]-2)/2<<endl;
    }
}

Measured memory_bytes: 14336
#include <iostream>
using namespace std;
typedef long long ll;

const ll m = 1e9+7;
ll sm[400005];
void sm_bulid() {
	sm[0]=1;for(ll i=1;i<400005;i++) sm[i]=sm[i-1]*i%m;
}
ll mod_pow(ll x, ll a) {
	ll an = 1;
	while(a > 0) {
		if (a&1) an = an * x % m;
		x = x * x % m; a >>= 1;
	}
	return an;
}
ll ncr(ll n, ll r) {
  return sm[n] * mod_pow(sm[n-r], m-2) % m * mod_pow(sm[r], m-2) % m;
}

int main(){
	sm_bulid();
	ll n,k; cin>>n>>k;
  ll p=min(k,n-1); // ci=0である個数がpとなる

  ll an=0;

  for(int i=0;i<=p;i++) {
    an+=ncr(n,i)*ncr(n-i+i-1, n-i-1)%m;
  }
  cout<<an%m<<endl;
}

Measured memory_bytes: 3328
#pragma GCC optimize("Ofast")
#include<bits/stdc++.h>
using namespace std;
using ll=long long;
using datas=pair<ll,ll>;
using ddatas=pair<double,double>;
using tdata=pair<ll,datas>;
using vec=vector<ll>;
using mat=vector<vec>;
using pvec=vector<datas>;
using pmat=vector<pvec>;
#define For(i,a,b) for(i=a;i<(ll)b;i++)
#define bFor(i,a,b) for(i=a;i>=(ll)b;i--)
#define rep(i,N) For(i,0,N)
#define rep1(i,N) For(i,1,N)
#define brep(i,N) bFor(i,N-1,0)
#define all(v) (v).begin(),(v).end()
#define allr(v) (v).rbegin(),(v).rend()
#define vsort(v) sort(all(v))
#define vrsort(v) sort(allr(v))
#define endl "\n"
#define pb push_back
#define output(v) do{bool f=0;for(auto outi:v){cout<<(f?" ":"")<<outi;f=1;}cout<<endl;}while(0)
const ll mod=1000000007;
const ll inf=1LL<<60;
const double PI = acos(-1);
const double eps = 1e-9;
template<class T> inline bool chmax(T& a,T b){bool x=a<b;if(x)a=b;return x;} 
template<class T> inline bool chmin(T& a,T b){bool x=a>b;if(x)a=b;return x;} 

void startupcpp(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(15);
}

double distance(ddatas& x,ddatas& y){
  double a=x.first-y.first,b=x.second-y.second;
  return sqrt(a*a+b*b);
}

ll modinv(ll a) {
  ll b=mod,u=1,v=0,t;
  while(b){
    t=a/b;
    a-=t*b; swap(a,b);
    u-=t*v; swap(u,v);
  }
  return (u+mod)%mod;
}

ll moddevide(ll a,ll b){return (a*modinv(b))%mod;}

vec modncrlistp,modncrlistm;

ll modncr(ll n,ll r){
  ll i,size=modncrlistp.size();
  if(size<=n){
    modncrlistp.resize(n+1);
    modncrlistm.resize(n+1);
    if(!size){
      modncrlistp[0]=modncrlistm[0]=1;
      size++;
    }
    For(i,size,n+1){
      modncrlistp[i]=modncrlistp[i-1]*i%mod;
      modncrlistm[i]=modinv(modncrlistp[i]);
    }
  }
  return modncrlistp[n]*modncrlistm[r]%mod*modncrlistm[n-r]%mod;
}

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

ll gcd(ll a,ll b){if(!b)return a;return (a%b==0)?b:gcd(b,a%b);}
ll lcm(ll a,ll b){return a/gcd(a,b)*b;}

ll countdigits(ll n){
  ll ans=0;
  while(n){n/=10;ans++;}
  return ans;
}

ll sumdigits(ll n){
  ll ans=0;
  while(n){ans+=n%10;n/=10;}
  return ans;
}
void judgement(int a){
  if(a){
    cout<<"Yes"<<endl;
  }else{
    cout<<"No"<<endl;
  }
  if(a){
    cout<<"YES"<<endl;
  }else{
    cout<<"NO"<<endl;
  }
}

int main(){
  ll i,j,N,H,W,ans;
  cin>>N>>H>>W;
  if((W-H)%2==0){
    ans=(W-H)/2;
  }else{
    ans=0;
    if(H-1<N-W){
      ans+=H;
      W-=ans;
      ans+=(W-1)/2;
    }else{
      ans+=N-W+1;
      H+=ans;
      ans+=(N-H)/2;
    }
  }
  cout<<ans<<endl;
  return 0;
}

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

typedef long long ll;
typedef pair<int,int> P;
typedef vector<int> vi;
typedef vector<ll> vl;
const ll MOD = round(1e9+7);

int main() {
    int N, K; cin >> N >> K;
    vi p(N); rep(i,N) cin >> p[i];
    sort(p.begin(), p.end());
    int ans = 0;
    rep(i,K){
        ans += p[i];
    }
   

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


Measured memory_bytes: 3624
n=int(input())
x=list(map(int,input().split()))
ans=0
a=min(x)
x.remove(min(x))
b=min(x)
x.remove(min(x))
ans+=(a+b)/2
while len(x)>0:
    c=min(x)
    ans=(ans+c)/2
    x.remove(min(x))
print(ans)

Measured memory_bytes: 3064
import java.util.*;

public class Main{
    public static void main(String[] args){
        Scanner sc = new Scanner(System.in);
        long H = sc.nextLong();
        long W = sc.nextLong();
        if(H%3 == 0 || W%3 == 0){
            System.out.println(0);
            return;
        }
        long ans = Math.min(H, W);
        for(long h = 1;h < H;h++){
            long l = 1;
            long h1 = Math.max(h, H-h);
            long h2 = Math.min(h, H-h);
            long d = H*(W-(long)1)-h1;
            l += d/(H+h1);
            ans = Math.min(ans, H*(W-l)-h2*l);
            l++;
            long a = Math.min(h2*l, H*(W-l));
            ans = Math.min(ans, h1*l-a);
            long c = Math.max(Math.abs((H-h)*W-h*(W/2)), Math.abs((H-h)*W-h*((W+(long)1)/2)));
            c = Math.max(c, h*((W+(long)1)/2)-h*(W/2));
            ans = Math.min(ans, c);
        }
        System.out.println(ans);
    }
}

Measured memory_bytes: 23124
Dis = [i*i for i in range(101)]
N = int(input())
X = [int(i) for i in input().split()]

ans = []
for i in range(1,101):
    k = 0
    for j in X:
        k += Dis[abs(i-j)]
    ans.append(k)
print(min(ans))

Measured memory_bytes: 3060
#include <stdio.h>
#include <math.h>

int main(){
    int X;
    scanf("%d", &X);
    if (X == 1) printf("1");
    else{
        int max = 1;
        for (int i = 2; i*i <= X; ++i){
            for (int j = 2; pow(i, j) <= X; ++j){
                max = pow(i, j)>max ? pow(i, j):max;
            }
        }

        printf("%d", max);
    }

    return 0;
}

Measured memory_bytes: 128
'use strict';
const main = input => {
  const n = parseInt(input[0]);
  let check = 0
  for(let i=1; i<=9; i++) {
    if (n%i == 0 && n/i <= 9) {
      check = 1;
      break;
    }
  }
  console.log(check==1?'Yes':'No');
  
}
main(require("fs").readFileSync("/dev/stdin", "utf8").split('\n'));

Measured memory_bytes: 7372
using System;
using System.Collections.Generic;

namespace ABC157d
{
    class Program
    {
        static void Main(string[] args)
        {
            string[] s = Console.ReadLine().Split(' ');
            int N = int.Parse(s[0]);
            int M = int.Parse(s[1]);
            int K = int.Parse(s[2]);

            List<int> friend = new List<int>();
            var blockCount = new List<int>();
            for (int i = 0; i < N; i++)
            {
                friend.Add(0);
                blockCount.Add(0);
            }

            UnionFind tree = new UnionFind(N);

            for(int i = 0; i < M; i++)
            {
                s = Console.ReadLine().Split(' ');
                int a = int.Parse(s[0])-1;
                int b = int.Parse(s[1])-1;

                tree.Unite(a, b);
                friend[a] += 1;
                friend[b] += 1;
            }

            for (int i = 0; i < K; i++)
            {
                s = Console.ReadLine().Split(' ');
                int a = int.Parse(s[0]) - 1;
                int b = int.Parse(s[1]) - 1;

                if (tree.Same(a, b))
                {
                    blockCount[a] += 1;
                    blockCount[b] += 1;
                }
            }

            for (int i = 0; i < N; i++)
            {
                int sz = tree.Size(i);

                Console.Write((sz - 1 - friend[i] - blockCount[i]) + " ");
            }
         }

    }
    public class UnionFind
    {
        private List<int> par;
        private List<int> siz;

        public UnionFind(int N)
        {
            par = new List<int>();
            siz = new List<int>();
            for (int i = 0; i < N; i++)
            {
                par.Add(i);
                siz.Add(1);
            }
        }

        public int Root(int x)
        {
            if (par[x] == x) { return x; }

            return par[x] = Root(par[x]);
        }

        public void Unite(int x, int y)
        {
            int rx = Root(x);
            int ry = Root(y);

            if (rx == ry) { return; }

            par[rx] = ry;
            siz[ry] += siz[rx];
        }
        public bool Same(int x, int y)
        {
            int rx = Root(x);
            int ry = Root(y);

            return rx == ry;
        }
        public int Size(int x)
        {
            return siz[Root(x)];
        }
    }
}


Measured memory_bytes: 21028
#include <iostream>
#include <vector>
#include <iomanip>
#include <stack>
#include <array>
#include <deque>
#include <forward_list>
#include <list>
#include <map>
#include <queue>
#include <set>
#include <algorithm>
#include <iterator>
#include <string>
#include <cstring>
//#include <fstream>
#include <complex>
#define _USE_MATH_DEFINES
#include <cmath>
#include <math.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define REP(i,n) for(int i=0;i<(n);i++)
#define RREP(i,n) for(int i=n;i>0;i--)
#define arep(a,i,n) for(int i=(a);i<(n);i++)
#define SORT(v) sort((v).begin(),(v).end())
const ll INF = (1LL << 50);
typedef pair<int, int> P;

int main() {

	int h, w, n;
	cin >> h >> w >> n;

	int a = max(h, w);
	int c = min(h, w);
	int b = (int)ceil((double)n / a);
	//cout << b << endl;

	if (b > c) {
		int d = n - a * b;
		int e = d / c;
		cout << c << endl;
	}
	else {
		cout << b << endl;
	}

	return 0;

}

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


min = 0
out = []
list = input().split(" ")
for i in list:
  if min == 0:
    min = int(i)
    out.append(i)
  else:
    if int(i) <= min:
     
      min = int(i)
      out.append(i)
print(len(out))
  

Measured memory_bytes: 18056
using System;
using System.Collections.Generic;

public class Pg
{
    static void Main()
    {
        var _class = new string[]
{ "light fly", "fly", "bantam", "feather", "light"
, "light welter", "welter", "light middle", "middle"
, "light heavy", "heavy" };
        var value = new List<double> { 48, 51, 54, 57, 60, 64, 69, 75, 81, 91, 150 };
        string line;
        while ((line = Console.ReadLine()) != null)
        {
            var weight = double.Parse(line);
            bool flag = false;
            value.ForEach(delegate (double x)
            {
                if (weight <= x&&!flag)
                {
                    Console.WriteLine(_class[value.IndexOf(x)]);
                    flag = true;
                }
            });
        }
    }
}



Measured memory_bytes: 13828
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<iostream>
#include<algorithm>
#include<cstdio>
#include<queue>
#include<cstring>
#include<string>
#include<cmath>
#include<map>
#define mem0(a) memset(a,0,sizeof(a))
#define meminf(a) memset(a,0x3f,sizeof(a))
using namespace std;
typedef unsigned long long ull;
typedef long long ll;
typedef long double ld;
typedef double db;
const int maxn=1e6;
int a,b,c;
int x,y;
int ans;
int main()
{
   cin>>a>>b>>c;
   cin>>x>>y;
   if(a+b<=2*c)
     ans=a*x+b*y;
   else
   {
    if(x>y)
    {
        int num=x-y;
        ans+=y*2*c;
        if(a<=2*c)
        ans+=num*a;
       else
        ans+=num*2*c;
    }
    else
    {
        int num=y-x;
        ans+=x*2*c;
        if(b<=2*c)
        ans+=num*b;
       else
        ans+=num*2*c;
    }
   }
   cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 256
/* ---------- STL Libraries ---------- */
// IO library
#include <cstdio>
#include <fstream>
#include <iomanip>
#include <ios>
#include <iostream>

// algorithm library
#include <algorithm>
#include <cmath>
#include <numeric>
#include <random>

// container library
#include <array>
#include <bitset>
#include <deque>
#include <map>
#include <unordered_map>
#include <queue>
#include <set>
#include <string>
#include <tuple>
#include <vector>

/* ---------- Namespace ---------- */
using namespace std;

/* ---------- Type ---------- */
using ll = long long;
#define int ll
#define P pair<ll, ll>

/* ---------- Constants  */
const double PI = 3.141592653589793238462643383279;
const ll MOD = 1e9 + 7;
const int INF = 1LL << 55;

/* v-v-v-v-v-v-v-v-v Main Part v-v-v-v-v-v-v-v-v */
signed main() {
    int N, X;
    cin >> N >> X;
    int A[N];
    for (int i = 0; i < N; i++) cin >> A[i];

    int ret = 0;
    for (int i = 0; i < N - 1; i++) {
        if (A[i] + A[i+1] <= X) continue;
        int diff = A[i] + A[i+1] - X;
        if (diff > A[i+1]) {
            A[i] -= diff - A[i+1];
            A[i+1] = 0;
        } else {
            A[i+1] -= diff;
        }

        ret += diff;
    }

    cout << ret << endl;

    return 0;
}

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

using namespace std;

#define intt long long
#define FAST ios_base::sync_with_stdio(0); cin.tie(0);

#define PI 3.1415926535897932384626

int main() {

	FAST;

	int a, b, h, m;
	cin >> a >> b >> h >> m;
	double angle = abs(1.0 * (11 * m - 60 * h) / 2);
	// cout << angle << '\n';
	if (angle > 180) {
		angle = 360 - angle;
	}
	// cout << angle << '\n';
	double cc = a * a + b * b - 2 * a * b * cos(angle * PI / 180);
	// cout << setprecision(9) << fixed << cos(angle) << '\n';
	// cout << cc << '\n';
	cout << setprecision(9) << fixed << sqrt(cc) << '\n';
	return 0;
}

Measured memory_bytes: 4132
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cstdlib>
#include <queue>
using namespace std;
#define N 2050
priority_queue<int>q;
int n,a[N],G[N][N],gg[N][N],vis[N],du[N];
int gcd(int x,int y) {return y?gcd(y,x%y):x;}
void dfs(int x) {
	vis[x]=1;
	int i;
	for(i=1;i<=n;i++) if(!vis[i]&&gg[x][i]>1) {
		dfs(i); G[x][i]=1; du[i]++;
	}
}
int main() {
	scanf("%d",&n);
	int i,j;
	for(i=1;i<=n;i++) scanf("%d",&a[i]);
	sort(a+1,a+n+1);
	for(i=1;i<=n;i++) {
		for(j=1;j<=n;j++) {
			gg[i][j]=gcd(a[i],a[j]);
		}
	}
	for(i=1;i<=n;i++) if(!vis[i]) dfs(i);
	for(i=1;i<=n;i++) if(!du[i]) q.push(i);
	while(!q.empty()) {
		int x=q.top(); q.pop();
		printf("%d ",a[x]);
		for(i=1;i<=n;i++) if(G[x][i]) {
			du[i]--;
			if(!du[i]) q.push(i);
		}
	}
}


Measured memory_bytes: 33152
#ABC116-B
s = int(input())

a = [0] * 1000000

a[0] = s
i = 0
while True:
    if a[i] % 2 == 0:
        i += 1
        a[i] = a[i-1] // 2
    else:
        i += 1
        a[i] = 3 * a[i-1] + 1
        

    if a[i] in set(a[:i-1]):
        print(i+1)
        break
        

Measured memory_bytes: 10868
#include<iostream>
#include<vector>
#include<string>
#include<algorithm>
#include<cmath>
#include<climits>
#include<cmath>
#include<fstream>
#include<numeric>

int main(){
	int A,B;

	std::cin >> A >> B;

	if(A==B) std::cout << A+B << std::endl;
	else std::cout << std::max(A,B)+std::max(A,B)-1 << std::endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
using namespace std;
constexpr int MOD = 1000000007;
constexpr int INF = numeric_limits<int>::max() / 2;
typedef pair<int,int> P;
using Graph = vector<vector<int>>;
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; }
const double PI = acos(-1.0);
// cout << fixed << setprecision(14);
 
 
signed main(){
	cin.tie(nullptr);
	ios::sync_with_stdio(false);

    int N;
    cin >> N;
    P p[N];
    int A[N];
    int B[N];
    rep(i,N) cin >> p[i].first >> p[i].second;
    rep(i,N){
        A[i] = p[i].first;
        B[i] = p[i].second;
    }
    sort(A, A+N);
    sort(B, B+N);
    if(N % 2 == 1){
        cout << B[N/2] - A[N/2] +1 << endl;
    }
    else{
        int cnt1 = A[N/2-1] + A[N/2];
        int cnt2 = B[N/2-1]  + B[N/2];
        cout << cnt2-cnt1+1 << endl; 
    }
}

Measured memory_bytes: 9908
#include <stdio.h>
#include <stdlib.h>
int main()
{   int a,b,i,n,cnt=0,ans=0;
    scanf("%d",&a);
    for(i=1;i<=a;i++){
        for(n=1;n<=i;n++){
            if(i%n==0){
                cnt+=1;
            }
        }if(cnt==8){
            ans+=1;
            cnt=0;
            i+=1;
        }else{cnt=0;i+=1;}
    }
    printf("%d",ans);

    return 0;
}


Measured memory_bytes: 128
#include <bits/stdc++.h>
#define CYES cout << "Yes" \
                  << "\n";
#define CNO cout << "No" \
                 << "\n";
#define CFS           \
    cin.tie(nullptr); \
    ios::sync_with_stdio(false);
#define CST(x) cout << fixed << setprecision(x);
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
template <class T>
using MaxHeap = priority_queue<T>;
template <class T>
using MinHeap = priority_queue<T, vector<T>, greater<T>>;
const int IINF = 1 << 30;
const ll LINF = 1LL << 60;
const int MOD = (int)1e9 + 7;
const string MM = " ";

int main()
{
    double l;
    cin >> l;
    cout << setprecision(12) << pow(l / 3, 3) << "\n";
}

Measured memory_bytes: 256
#Union-Find木の構築
import sys
def 解():
    iN,iK,iL = [int(_) for _ in input().split()]
    aD = [[int(_) for _ in sLine.split()] for sLine in sys.stdin.readlines()]

    def buildTree(a):
        #aT = [0]*(iN+1)
        aT = list(range(iN+1))
        for p,q in a:
            rp = getRoot(aT,p)
            rq = getRoot(aT,q)
            thisRoot = max(rp,rq,q) #みんな小さい方に合わせてるのでデカい方に合>わせてみる
            aT[p] = thisRoot
            aT[q] = thisRoot
            aT[rp] = thisRoot #これで Union してるつもり
            aT[rq] = thisRoot
        return aT
    def getRoot(a,i): #find
        #if a[i] == i or a[i] == 0:
        #   if a[i] == 0 : a[i] = i
        if a[i] == i :
            return i
    #   elif i < a[i] :
        else :
            a[i] = getRoot(a,a[i])
            return a[i]
    #   else:
    #       print("! ",i,a[i])

    aT道 = buildTree(aD[0:iK])
    aT鉄道 = buildTree(aD[iK:])
    aRet = []
    dRet = {}
    for i in range(1,iN+1):
        # いやはやこんなもんもキーになるのか。
        Comb = (getRoot(aT道,i), getRoot(aT鉄道,i))
        aRet.append(Comb)
        if Comb in dRet:
            dRet[Comb] += 1
        else:
            dRet[Comb] = 1
    print(" ".join([str(dRet[_]) for _ in aRet]))

解()


Measured memory_bytes: 95400
#https://atcoder.jp/contests/abc121/tasks/abc121_b

import numpy as np

n,m,c=map(int,input().split())
blist=np.array(list(map(int,input().split())))
alist=np.array([list(map(int,input().split())) for i in range(n)])

count=0

for i in range(n):
	if np.sum(alist[i]*blist)+c > 0:
		count += 1

print(count)	


Measured memory_bytes: 12492
#include<iostream>
#include<vector>
#include<math.h>
using namespace std;
int main(){
    int N, K, min = 0, t=0;
    bool answer = true;
    cin >> N >> K;
    vector<char> D(K);
    for(int i = 0; i < K; i++){
        cin >> D[i];
    }
    for(int i = N; i < 10*N; i++){
        answer = true;
        for(int j = 0; j < to_string(i).size(); j++){
            for(int l = 0; l < K;l++){
                if(to_string(i).at(j) == D[l]){answer = false;}
            }
        }
        if(answer == true){
                min = i;
                break;
        }
    }
    cout << min << endl;
}

Measured memory_bytes: 256
#include<iostream>
#include<string>
#include<algorithm>
#include<cmath>
#include<vector>
#include<map>
#include<set>
#include<stack>
#include<queue>
using namespace std;
#define rep(i,n) for(int i=0;i<n;i++)
#define int long long
#define END system("PAUSE");return 0
int n, a[252525], cnt = 1, ans = 1;
signed main() {
	cin >> n;
	rep(i, n) {
		int x;
		cin >> x;
		a[x - 1] = i;
	}
	for (int i = 1; i < n; i++) {
		cin >> a[i];
		if (a[i] > a[i - 1])cnt++;
		else {
			ans = max(ans, cnt);
			cnt = 1;
		}
	}
	cout << n - max(ans, cnt) << endl;
	END;
}


Measured memory_bytes: 2040
#include <iostream>
#include <algorithm>
#include <vector>
#include <queue>
#include <set>
#include <bitset>
#include <cmath>
#include <string>
#define FI first
#define SE second
#define PF push_front
#define PB push_back
#define PPF pop_front
#define PPB pop_back
#define MA make_pair
#define ll long long
#define PA pair<int,int>
#define VE vector<int>
#define VP vector<PA>
#define FOR(i,a,b) for(int i=a;i<b;i++)
#define ROF(i,a,b) for(int i=b-1;i>=a;i--)
#define YES(i) cout<<(i?"YES":"NO")<<endl
#define Yes(i) cout<<(i?"Yes":"No")<<endl
using namespace std;
const int INF=1e9+7;
const int mod=1e9+7;
struct poi{
	int X;int Y;int Z;
  bool operator<(const poi&R)const{
		return X==R.X ? Y==R.Y ? Z<R.Z : Y<R.Y : X<R.X;
	}
};
//
//ACACACACACACACACACACACAC//
//WAWAWAWAWAWAWAWAWAWAWAWA//
//CECECECECECECECECECECECE//
//RERERERERERERERERERERERE//
//TLETLETLETLETLETLETLETLE//
//
int main(){
	string S;
	cin>>S;
	int cnt=0;
	FOR(i,0,(int)S.size()-1){
		if(S[i]!=S[i+1]){
			cnt++;
		}
	}
	cout<<cnt<<endl;
  return 0;
}


Measured memory_bytes: 512
#include <stdio.h>

int gcd(int, int);
int maximum(int[], int);

int main(){
    int n, i, max;
    int a[100000], l[100000], r[100000], m[100000];

    scanf("%d", &n);

    l[0] = 0;
    r[n] = 0;

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

    for(i=0; i<n; i++)
        l[i+1] = gcd(l[i], a[i]);

    for(i=n-1; i>=0; i--){
        r[i] = gcd(r[i+1], a[i]);
    }

    for(i=0; i<n; i++)
        m[i] = gcd(l[i], r[i+1]);
    

    max = maximum(m, n);

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

    return 0;
}

int gcd(int a, int b){
    int r, work;

    if((a == 0 && b != 0) || (a != 0 && b == 0)){
        if(a == 0)
            return b;
        else
            return a;
    }

    if(a < b){
        work = a;
        a = b;
        b = work;
    }

    r = a % b;

    while(r != 0){
        a = b;
        b = r;
        r = a % b;
    }

    return b;
}

int maximum(int x[], int n){
    int i, max;

    max = x[1];

    for(i=0; i<n; i++){
        if(max < x[i])
            max = x[i];
    }
    
    return max;
}

Measured memory_bytes: 1664
s = input()
K = int(input())

len_s = len(s)
str_list = []
for i in range(len_s):
    j_lim = min(len_s-i+1, 6)
    for j in range(1, j_lim):
#        print(s[i:i+j])
        if(not(s[i:i+j] in str_list)):
            str_list.append(s[i:i+j])
        
#print(str_list)
s_str_list = sorted(str_list)
#print(s_str_list)
print(s_str_list[K-1])

Measured memory_bytes: 4072
#include <iostream>

using namespace std;

long foo[50] = {0};

void count(long num, long pos) {
  if (num == 0) return;
  if (num % 2 == 1) foo[pos]++;
  count(num / 2, pos + 1);
}

long shift(long K, long keta) {
  if (keta == 0) return K;
  return shift(K * 2, keta-1);
}

long unshift(long K, long keta) {
  if (keta == 0) return K;
  if (K == 0) return K;
  return unshift(K / 2, keta-1);
}

long fulluse(long N, long limit) {
  long ans = 0;
  for (long i = 0; i <= limit; i++) {
    long tmp = foo[i];
    if (N - foo[i] > tmp) tmp = N - foo[i];
    ans += shift(tmp, i);
  }
  return ans;
}

long maxfx(long K, long N, long limit) {
  if (limit < 0) return 0;
  if (unshift(K, limit) % 2 == 0) {
    return shift(foo[limit], limit) + maxfx(K, N, limit - 1);
  }
  long tmp1 = shift(N - foo[limit], limit) + maxfx(K, N, limit - 1);
  long tmp2 = shift(foo[limit], limit) + fulluse(N, limit - 1);
  if (tmp1 > tmp2) return tmp1;
  return tmp2;
}

int main(void) {
  long N, K;
  cin >> N >> K;

  for (long i = 0; i < N; i++) {
    long tmp;
    cin >> tmp;
    count(tmp, 0);
  }

  cout << maxfx(K, N, 49) << endl;

  return 0;
}


Measured memory_bytes: 256
while True:
    m = int(input())
    if not m:
        break
    n = int(input())
    ds = [0] + [int(input()) for _ in range(n)] + [0]

    g = [[] for _ in range(n+2)]
    rg = [[] for _ in range(n+2)]
    for i in range(n+2):
        for j in range(min(n+1,i+1),min(n+1,i+m)+1):
            j = max(0,min(n+1,j+ds[j]))
            g[i].append(j)
            rg[j].append(i)
    
    def go(g,bs,i):
        bs[i] = True
        for j in g[i]:
            if not bs[j]:
                go(g,bs,j)
    
    bs = [False]*(n+2)
    rbs = [False]*(n+2)
    go(g,bs,0)
    go(rg,rbs,n+1)

    if any((b and (not rb)) for b,rb in zip(bs,rbs)):
        print('NG')
    else:
        print('OK')

Measured memory_bytes: 7752
//inlclude前用define 
#define _USE_MATH_DEFINES

//include
#include<iostream>
#include<string>
#include<algorithm>
#include<vector>
#include<cmath>
#include<type_traits>
#include<numeric>
#include<assert.h>
//#include<deque>
#include<iomanip>
#include<set>
#include<tuple>
#include<map>

using namespace std;

//typedef
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<char> VC;
typedef pair<int, int> P1;
typedef long long int ll;

//define
#define INF 1e18
#define NUM 1000000007
#define all(x) begin(x), end(x)
#define rep(i,n) for(int i=0;i<(int)(n);i++)
#define repi(i,a,b) for(int i=int(a);i<int(b);++i)
#define REP(i,a,b) for(int i=int(a);i<int(b);++i)
#define chmin(a,b) a=min((a),(b))
#define chmax(a,b) a=max((a),(b))

int main() {
	int h, w;
	cin >> h >> w;
	int x[] = { -1, 0, 1, 0 };
	int y[] = { 0,-1,0,1 };
	bool flag = true;
	VS s(h+1);
	rep(i, w) s[0][i] = '.';
	REP(i,1,h+1) {
		cin >> s[i];
		s[i] += '.';
	}

	rep(i, h) {
		rep(j, w) {
			int cnt = 0;
			if (s[i][j] == '#') {
				rep(k, 4) {
					if (s[i + x[k]][j + y[k]]=='#') {
						cnt++;
					}
				}
				if (cnt == 0) flag = false;
			}
		}
	}
	
	if (flag) cout << "Yes" << endl;
	else cout << "No" << endl;

}






Measured memory_bytes: 256