akhauriyash/Code-Regression huggingface dataset:
#![allow(dead_code)]

const MOD: i64 = 1_000_000_007;

fn main(){
    let arg: Vec<usize> = input_vec();
    let n = arg[0] as i64;
    let m = arg[1] as i64;
    
    let math = Math::new(m);
    let mut ans = 0;
    
    for i in 0..=n {
        let i = i as i64;
        let t1 = math.comb(n, i) * math.perm(m, i) %MOD;
        let t2 = modpow(math.perm(m-i, n-i), 2);
        let t3 = modpow(-1, i);
        let t = t1*t2%MOD * t3;
        ans += t;
        ans = (ans%MOD+MOD)%MOD;
    }
    println!("{}", ans);
}

struct Math {
    fact:Vec<i64>,
    factinv:Vec<i64>,
}

impl Math {
    fn new(n: i64) -> Math {
        let n = n as usize + 1;
        let mut fact = vec![1i64; n];
        let mut factinv = vec![1i64; n];
        
        for i in 2..n {
            fact[i] = fact[i-1] * i as i64 %MOD;
        }
        factinv[n-1] = modinv(fact[n-1]);
        for i in (2..n).rev() {
            factinv[i-1] = factinv[i] * i as i64 %MOD;
        }
        Math {fact, factinv}
    }

    fn perm(&self, n: i64, r: i64) -> i64 {
        let n = n as usize;
        let r = r as usize;
        self.fact[n] * self.factinv[n-r] %MOD
    }

    fn comb(&self, n: i64, r: i64) -> i64 {
        self.perm(n, r) * self.factinv[r as usize] %MOD
    }
}


/*
 * modpow
 */
fn modpow(mut r: i64, mut n: i64) -> i64{
    let mut res = 1;
    while n>0 {
        if n%2 == 1 {res = res*r%MOD;}
        r = r*r%MOD;
        n = n/2;
    }
    res
}

fn modinv(n: i64) -> i64{
    modpow(n, MOD-2)
}


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


fn input_vec<T: std::str::FromStr>() -> Vec<T> {
    input::<String>()
        .split_whitespace()
        .map(|s| s.parse().ok().unwrap()).collect()
}


Measured memory_bytes: 9884
#include<stdio.h>

int main(void){
	int n, k, a[100],i,j;
	scanf("%d %d",&n,&k);
	for(i=0;i<100;i++) {
		a[i]=0;
	}
	for(i=0;i<k;i++) {
		int d;
		scanf("%d",&d);
		for(j=0;j<d;j++) {
			int t;
			scanf("%d",&t);
			if(a[t-1] == 0) {
				a[t-1]=1;
			}
		}
	}
	int sum=0;
	for(i=0;i<n;i++) {
		if(a[i] == 0) {
			sum ++;
		}
	}
	printf("%d",sum);
}


Measured memory_bytes: 1708
#include <stdio.h>
#include <stdint.h>
#include <string.h>
#include <set>
#include <map>

int64_t A, B, C, K;

int d[6];
int digits;

int main(){
  int c;
  while((c = getchar()) != EOF){
    if(c < '0' || '9' < c) break;
    d[digits++] = c - '0';
  }
  int i;
  for(i = digits - 1; i >= 0; i--) {
    if(d[i]) break;
  }
  if(i == 0 && d[i] == 1){
    d[i] = 10;
  }
  int count = 0;
  for(int i = 0; i < digits; i++){
    count += d[i];
  }
  printf("%d\n", count);
  return 0;
}

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

#define rep(i, n) for(int i = 0; i < n;i++)

int main()
{
    int A, B, C, D;
    cin >> A >> B >> C >> D;
    int sum_t = (C + B - 1) / B;
    int sum_a = (A + D - 1) / D;
    cout << (sum_t <= sum_a ? "Yes" : "No") << endl;
}



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

int main()
{
	string tmp;
	cin >> tmp;
	if(tmp.size()&1)
	{
		if(tmp[0]==tmp[tmp.size()-1])
			cout << "Second" << endl;
		else
			cout << "First" << endl;
	}
	else
	{
		if(tmp[0]==tmp[tmp.size()-1])
			cout << "First" << endl;
		else
			cout << "Second" << endl;
	}
	return 0;
}


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

public class Main {
	
	public static class Mono implements Comparable<Mono>{
		String name;
		double kouritu;
		
		
		public Mono(String name, double kouritu) {
			super();
			this.name = name;
			this.kouritu = kouritu;
		}

		@Override
		public int compareTo(Mono arg0) {
			if(this.kouritu > arg0.kouritu){
				return -1;
			}else if(this.kouritu < arg0.kouritu){
				return 1;
			}else{
				return this.name.compareTo(arg0.name);
			}
		}
	}
	
	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);

		while(true){
			final int N = sc.nextInt();
			
			if(N == 0){
				break;
			}
			
			Mono[] monos = new Mono[N];
			
			for(int i = 0; i < N; i++){
				String name = sc.next();
				int price = sc.nextInt();
				int atl = sc.nextInt() + sc.nextInt() + sc.nextInt();
				int mi = sc.nextInt() + sc.nextInt();
				int kazu = sc.nextInt();
				int sold = sc.nextInt();
				int times = sc.nextInt();
				
				int time = atl + times * mi;
				
				int rieki = kazu * times * sold - price;
				
				monos[i] = new Mono(name, rieki/(double)(time));
			}
			
			Arrays.sort(monos);
			
			for(Mono m : monos){
				System.out.println(m.name);
			}
			
			System.out.println("#");
		}
		
	}

}

Measured memory_bytes: 12000
#include "bits/stdc++.h"
using namespace std;

// コンテスト中のみ
#define int long long

#define ll long long
#define rep(i,n) for(int i = 0; i < (n); i++)
#define P pair<ll,ll>
int MOD = 1000000007;
const ll INF = 1LL << 60;


signed main() {
	ios::sync_with_stdio(false);
	cin.tie(nullptr);
	ll a; cin >> a;
	cout << a + a * a + a * a*a << endl;
	return 0;
}

Measured memory_bytes: 3612
#include <iostream>
#include <algorithm>
#include <cstdio>
#include <cmath>
#include <string>
#include <cctype>
#include <stack>
#include <queue>
#include <vector>
#include <cstdlib>
#include <list>
#define _USE_MATH_DEFINES
#include <math.h>

using namespace std;

int main() {

	int n, p[101], m[101][101];

	cin >> n;
	for (int i = 1; i <= n; i++) {
		cin >> p[i - 1] >> p[i];
		m[i][i] = 0;
	}

	for (int i = 2; i <= n; i++) {
		for (int j = 1; j <= n - i + 1; j++) {
			int k = i + j - 1;
			m[j][k] = (1 << 21);
			for (int l = j; l <= k - 1; l++) {
				m[j][k] = min(m[j][k], m[j][l] + m[l + 1][k] + p[j - 1] * p[l] * p[k]);
			}
		}
	}
	cout << m[1][n] << endl;
	return 0;
}

Measured memory_bytes: 3128
#include <bits/stdc++.h>
#define SZ(c)       int(c.size())
#define FOR(i,a,b)  for (int i=a; i<(b); ++i)
#define DOWN(i,a,b) for (int i=(a)-1; i>=(b); --i)
using namespace std;
using i64 = long long;

const int MAXN=16016;
const int SHIFT=8000;

string s;
int x,y;
vector<int> xs;
vector<int> ys;
bool can[2][MAXN];

bool check(int v,vector<int> a) {
  // cerr<<v<<endl;
  // for (int t:a) cerr<<t<<" ";
  // cerr<<endl;
  auto &curr=can[0];
  auto &next=can[1];
  memset(curr,0,sizeof(curr));
  curr[a[0]+SHIFT]=true;
  FOR(j,1,SZ(a)) {
    int t=a[j];
    memset(next,0,sizeof(next));
    FOR(i,-SHIFT,SHIFT+1) {
      if (curr[i+SHIFT]) {
        next[i+t+SHIFT]=true;
        next[i-t+SHIFT]=true;
      }
    }
    swap(curr,next);
  }
  return curr[v+SHIFT];
}

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(0);
  cout<<fixed<<setprecision(10);

  cin>>s>>x>>y;

  bool f=true;
  int cur=0;
  ys.push_back(0);
  for (char c:s) {
    if (c=='F') cur+=1;
    if (c=='T') {
      if (cur==0 && f && xs.empty()) {
        xs.push_back(0);
      }
      if (cur>0) {
        if (f) xs.push_back(cur); else ys.push_back(cur);
      }
      f=!f;
      cur=0;
    }
  }
  if (cur>0) {
    if (f) xs.push_back(cur); else ys.push_back(cur);
  }
  if (xs.empty()) xs.push_back(0);

  if (check(x,xs) && check(y,ys)) cout<<"Yes"; else cout<<"No";
  cout<<endl;

  return 0;
}


Measured memory_bytes: 384
import math

a, b, c = list(map(float, input().split()))

h = b * math.sin(math.radians(c))

S = (1/2) * a * h

x = b * math.cos(math.radians(c))

side = ((a-x)**2 + h**2) ** (1/2)

L = a + b + side

print(S)
print(L)
print(h)


Measured memory_bytes: 5696
#include<stdio.h>
#define N 10000
#define Q 500

int linearSearch();

int S[N],n,key;

int main(){
  int T[Q],q,i,c=0;

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

  scanf("%d",&q);
  for(i=0;i<q;i++){
    scanf("%d",&T[i]);
  }

  for(i=0;i<q;i++){
    key=T[i];
    if(linearSearch()) c++;
  }

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

  return 0;
  
}

int linearSearch(){
  int i=0;

  S[n]=key;

  while(S[i]!=key) i++;

  if(i==n) return 0;

  return 1;
}

Measured memory_bytes: 640
N,M = map(int,input().split())
x = set()
y = set()

for m in range(M):
    a,b = map(int,input().split())
    if a==1:
      x.add(b)
    if b==N:
      y.add(a)

if x&y:
  print("POSSIBLE")
else:
  print("IMPOSSIBLE")

Measured memory_bytes: 19024
#include <stdio.h>
#include <queue>
using namespace std;

char S[2001001], T[500500];
int pi[500500], f[500500], d[500500], l[500500];

int main()
{
  scanf ("%s %s",S,T);
  
  int n = 0; while (S[n]) n++;
  int N = n; while (N < 2001001) S[N] = S[N-n], N++;
  int m = 0; while (T[m]) m++;
  
  int k = -1; pi[0] = -1;
  for (int i=1;i<m;i++){
	while (k >= 0 && T[i] != T[k+1]) k = pi[k];
    if (T[i] == T[k+1]) k++;
    pi[i] = k;
  }
  
  k = -1;
  for (int i=0;i<N;i++){
	while (k >= 0 && S[i] != T[k+1]) k = pi[k];
    if (S[i] == T[k+1]) k++;
    if (k == m-1){
		f[i%n] = 1;
      k = pi[k];
    }
  }
  
  for (int i=0;i<n;i++) if (f[i]){
	d[(i+m)%n]++;
  }
  
  queue<int> Q;
  for (int i=0;i<n;i++) if (f[i] && !d[i]){
	Q.push(i); l[i]=  1;
  }
  
  int ans = 0;
  while (!Q.empty()){
	int x = Q.front(); Q.pop();
    int y = (x + m) % n; f[x] = 0;
    if (ans < l[x])
      ans = l[x];
    if (f[y]){
		Q.push(y); l[y] = l[x] + 1;
    }
  }
  
  for (int i=0;i<n;i++) if (f[i]) ans = -1;
  printf ("%d\n",ans);

return 0;
}

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

#define REP(i, n) for (int i = 0; i < n; i++)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOR(i, m, n) for (int i = m; i < n; i++)
#define FORR(i, m, n) for (int i = m; i >= n; i--)
#define ALL(x) (x).begin(), (x).end()

using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
const ll INF = 1e15;
const ll MOD = 1e9 + 7;

int main() {
  ll n;
  cin >> n;
  vector<ll> t(n), a(n);
  REP(i, n) cin >> t[i];
  REP(i, n) cin >> a[i];

  vector<bool> tr(n, true), ar(n, true);

  tr[0] = ar[n - 1] = false;
  FOR(i, 1, n) {
    if (t[i - 1] != t[i]) {
      tr[i] = false;
    }
  }

  FORR(i, n - 2, 0) {
    if (a[i + 1] != a[i]) {
      ar[i] = false;
    }
  }

  ll ans = 1;
  REP(i, n) {
    if (tr[i] && ar[i]) {
      ans *= min(t[i], a[i]);
      ans %= MOD;
    } else if (!tr[i] && ar[i]) {
      if (t[i] > a[i]) {
        cout << 0 << endl;
        return 0;
      }
    } else if (tr[i] && !ar[i]) {
      if (a[i] > t[i]) {
        cout << 0 << endl;
        return 0;
      }
    } else {
      if (t[i] != a[i]) {
        cout << 0 << endl;
        return 0;
      }
    }
  }

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

Measured memory_bytes: 1792
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
const int N=5e3+5,M=2e4+5,inf=0x3f3f3f3f,mod=1e9+7;
#define mst(a,b) memset(a,b,sizeof a)
#define lx x<<1
#define rx x<<1|1
#define reg register
#define PII pair<int,int>
#define fi first
#define se second
#define pb push_back
#define il inline
int a[N],dp[N],n,k;
ll s;
int main(){
	scanf("%d%d",&n,&k);
	for(int i=1;i<=n;s+=a[i++]){
		scanf("%d",&a[i]);
		if(a[i]>k) a[i]=k;
	}sort(a+1,a+n+1);
	dp[0]=1;
	for(int i=n;~i;s-=a[i--]){
		bool ok=1;
		for(int j=k-1;j>=max(k-s,0LL);j--)
			if(dp[j]){
				ok=0;break;
			}
		if(ok){
			printf("%d\n",i);break;
		}
		for(int j=k;j>=a[i];j--) dp[j]|=dp[j-a[i]];
	}
	return 0;
}

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

#define CPP_STR(x) CPP_STR_I(x)
#define CPP_CAT(x,y) CPP_CAT_I(x,y)
#define CPP_STR_I(args...) #args
#define CPP_CAT_I(x,y) x ## y

using i8  = int8_t;
using u8  = uint8_t;
using i16 = int16_t;
using u16 = uint16_t;
using i32 = int32_t;
using u32 = uint32_t;
using i64 = int64_t;
using u64 = uint64_t;

using f32 = float;
using f64 = double;

#define FOR(i, start, end) for(i64 i = (start), CPP_CAT(i,xxxx_end)=(end); i < CPP_CAT(i,xxxx_end); ++i)
#define REP(i, n) FOR(i, 0, n)
#define REPS(i, n) for(i64 i = 1; i <= n; ++i)
#define RREP(i, n) for(i64 i = n - 1; i >= 0 ; --i)
#define RREPS(i, n) for(i64 i = n; i >= 1; --i)

#define ALL(f,c,...) (([&](decltype((c)) cccc) { return (f)(std::begin(cccc), std::end(cccc), ## __VA_ARGS__); })(c))

#define UNIQUE(v) v.erase( unique(v.begin(), v.end()), v.end() );

#define pb push_back
#define mp make_pair

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

template<typename C>
i64 SIZE(const C& c) { return static_cast<i64>(c.size()); }

template<typename T, size_t N>
i64 SIZE(const T (&)[N]) { return static_cast<i64>(N); }


struct ProconInit {
    static constexpr int IOS_PREC = 15;
    static constexpr bool AUTOFLUSH = false;

    ProconInit() {
        cin.tie(nullptr);
        ios::sync_with_stdio(false);
        cout << fixed << setprecision(IOS_PREC);
        if(AUTOFLUSH)
            cout << unitbuf;
    }
} PROCON_INIT;


int main() {
    string S; cin >> S;
    vector<bool> dp(S.length() + 10, false);
    vector<string> T = {"dream", "dreamer", "erase", "eraser"};

    dp[0] = true;
    REP(i, S.length()) {
        if (!dp[i]) continue;
        REP(j, SIZE(T)) {
            if (i + T[j].length() > S.length()) continue;
            string ss = S.substr(i, T[j].length());
            if (ss == T[j]) dp[i + T[j].length()] = true;
        }
    }
    if (dp[S.length()]) {
        cout << "YES" << endl;
    } else {
        cout << "NO" << endl;
    }

    return 0;
}

Measured memory_bytes: 512
indexes = {}

while line = gets
  word, page = line.chomp.split
  indexes[word] ||= []
  indexes[word] << page.to_i
end

indexes = indexes.sort do |(k1, v1), (k2, v2)|
  k1 <=> k2
end

indexes.each do |k, v|
  puts k
  puts v.sort { |a, b| a <=> b }.join(' ')
end

Measured memory_bytes: 8600
#include<bits/stdc++.h>
using namespace std;
#define ll long long int
#define vi vector<int>
#define vii vector<vector<int>>
#define vpi vector<pair<int,int>>
#define w(t) int t;cin>>t;while(t--)
#define pi pair<int,int>
#define mii map<int,int>
#define pb push_back
#define ff first
#define ss second
#define FOR(i,t,n) for(int i=t;i<n;i++)
#define SCI(x)  scanf("%d",&x)
#define SCL(x) scanf("%lld",&x)
#define debug(x) cout<<x<<endl
#define debug2(x,y) cout<<x<<" "<<y<<endl;
#define debug3(x,y,z) cout<<x<<" "<<y<<" "<<z<<endl;

int main()
{
	int n;
	cin >> n;
	int a[n];
	FOR(i, 0, n) {
		cin >> a[i];
	}

	int dp[n];
	dp[0] = 0;
	dp[1] = abs(a[0] - a[1]);

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

	cout << dp[n - 1] << endl;
}


Measured memory_bytes: 4280
n = int(input())
l0 = 2
l1 = 1
if n == 0:
    print(l0)
elif n == 1:
    print(l1)
else:
    for i in range(2,n+1):
        li = l0 + l1
        l0 = l1
        l1 = li
    print(li)

  
  
  

Measured memory_bytes: 2940
#! /usr/bin/env ruby

input = STDIN.read.split("\n").map{|l| l.split(" ")}
lens = input[0].map{|i| i.to_i}
chars = input[1]

N = lens[0]
M = lens[1]

S = input[1][0]
T = input[2][0]

L = N.lcm(M)
lib = {}

for i in 0..(S.length - 1)
  pos = 1
  if i > 0
    pos = L / N * i + 1
  end

  lib[pos] = S[i]
end

ok = true

for i in 0..(T.length - 1)
  pos = 1
  if i > 0
    pos = L / M * i + 1
  end

  if lib.has_key?(pos) && lib[pos] != T[i] then
    ok = false
    break;
  else
    lib[pos] = T[i]
  end
end

if ok then
  puts L
else
  puts "-1"
end


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

ll x;

int main(){
    cin >> x;
    
    for(int k = x; k <= x + 1e5; k++){
        bool ok = 1;
        
        for(int i = 2; i * i <= k; i++){
            if(k % i == 0){
                ok = 0; break;
            }
        }
        
        if(ok){
            cout << k << '\n';
            break;
        }
    }
}


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

int main()
{
  int N, M;
  cin >> N >> M;
  vector<vector<long long int>> data(N, vector<long long int>(3));
  for (int i = 0; i < N; i++)
  {
    for (int j = 0; j < 3; j++)
    {
      cin >> data.at(i).at(j);
    }
  }
  long long ans = -1;
  //求めるのは絶対値の合計ではなく合計の絶対値
  //どの要素を正，負どちらの方向に最大化させるかで8通り
  for (int bit = 0; bit < (1 << 3); bit++)
  {
    vector<long long int> svec(N);
    for (int j = 0; j < N; j++)
    {
      long long int S = 0;
      for (int k = 0; k < 3; k++)
      {
        if (1 & (bit >> k))
        { //bitにk番目のフラグが立っているか
          svec.at(j) += data.at(j).at(k);
        }
        else
        {
          svec.at(j) -= data.at(j).at(k);
        }
      }
    }
    sort(svec.begin(), svec.end(), greater<long long int>());
    long long int sum = 0;
    for (int j = 0; j < M; j++)
    {
      sum += svec.at(j);
    }
    ans = max(ans, sum);
  }
  cout << ans << endl;
  return 0;
}


Measured memory_bytes: 256
import java.util.Scanner;

public class Main {
	public static void main (String args[]) {
		Scanner scan = new Scanner(System.in);
		int k = scan.nextInt();
		int x = scan.nextInt();     	
		String ans = "No";
		
		if(x <= 500 * k) {
			ans = "Yes";
		}
		System.out.println(ans);
	}
}

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

int main() {
  int N;
  cin>>N;
  long double J=0,B=0;
  for(int i=0;i<N;i++){
    long double X;
    string S;
    cin>>X>>S;
    if(S=="JPY"){
      J+=X;
    }
    else{
      B+=X;
    }
  }
  B*=380000.0;
  B+=J;
  cout<<fixed<<setprecision(15);
  cout<<B<<endl;
}

Measured memory_bytes: 3664
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
typedef  long long ll;
struct UnionFind {
    vector<int> par;
    
    UnionFind(int n) : par(n, -1) { }
    void init(int n) { par.assign(n, -1); }
    
    int root(int x) {
        if (par[x] < 0) return x;
        else return par[x] = root(par[x]);
    }
    
    bool issame(int x, int y) {
        return root(x) == root(y);
    }
    
    bool merge(int x, int y) {
        x = root(x); y = root(y);
        if (x == y) return false;
        if (par[x] > par[y]) swap(x, y); // merge technique
        par[x] += par[y];
        par[y] = x;
        return true;
    }
    
    int size(int x) {
        return -par[root(x)];
    }
};
int main(){
    ll N,M;
    int A[100010];
    int B[100010];
    cin>>N>>M;
    for(int i=0;i<M;i++){
        cin>>A[i]>>B[i];
        --A[i];
        --B[i];
    }
   UnionFind uf(N);
    long long cur = N * (N-1) / 2;
    vector<long long> res;
    for (int i = 0; i < M; ++i) {
        res.push_back(cur);
            
        int a = A[M-1-i], b = B[M-1-i];
        if (uf.issame(a, b)) continue;
        
        long long sa = uf.size(a), sb = uf.size(b);
        cur -= sa * sb;
        uf.merge(a, b);
    }
        
    reverse(res.begin(), res.end());
    for (int i = 0; i < res.size(); ++i) cout << res[i] <<endl;
}

Measured memory_bytes: 3444
n,m = map(int,input().split())

a = []
b = []

for i in range(n):
    a.append(list(map(int,input().split()))) #(listが大事)
for i in range(m):
    b.append(int(input()))
#print(a)
#print(b)

sum = 0

for i in range(n):
    for j in range(m):
        sum += a[i][j]*b[j]
    print(sum)
    sum = 0


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

using namespace std;

int main() {

    int N, K;
    cin >> N >> K;

    int d[101], A[101][101];

    for(int i = 1; i <= K; i++) {
        cin >> d[i];
        for(int j = 1; j <= d[i]; j++) {
            cin >> A[i][j];
        }
    }

    set<int> members;

    for(int i = 1; i <= K; i++) {
        for(int j = 1; j <= d[i]; j++) {
            members.insert(A[i][j]);
        }
    }

    int have = members.size();

    cout << N - have << endl;


    return 0;
}

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

int main()
{ 
  int n, m, p;
  vector<int> ans;
  while(cin>>n>>m>>p, n||m||p)
  {
    m--;
    vector<int> x;
    for(int i=0;i<n;++i)
    {
      int t; cin>>t;
      x.push_back(t);
    }
    int sum=accumulate(x.begin(), x.end(), 0);
    int tmp;
    if(x[m]==0) tmp=0;
    else 
    {
      double t=1.0*sum/x[m];
      tmp=t*(100-p);
    }
    ans.push_back(tmp);
  }
  for(auto e: ans) cout<<e<<"\n";

  return 0;
}



Measured memory_bytes: 3132
using System;
using System.Collections.Generic;
using System.Linq;

// https://atcoder.jp/contests/abc124/tasks/abc124_d
namespace DHandstand
{
    class Program
    {
        static void Main(string[] args)
        {
            // 入力の取得
            var inputs = Console.ReadLine().Split().Select(int.Parse).ToArray();
            var n = inputs[0];
            var k = inputs[1];

            var states = Console.ReadLine().ToCharArray().Select(x => x == '1').ToArray();

            // 逆立ちしている人を1度直立させる操作も考えうるが、010->101->111 も 010->110->111 も手数が同じであるため
            // 逆立ちしている人を直立させることは除外して、連続する直立の人を反転することだけを考えることとする
            // また、すべての人が逆立ちしたらそこで操作を終了する

            // 連続する直立/逆立ちの人数をまとめる
            var stateSummary = new List<Tuple<bool, int>>();
            var currentState = states[0];
            var stateCount = 0;
            foreach (var state in states)
            {
                if (currentState != state)
                {
                    stateSummary.Add(Tuple.Create(currentState, stateCount));
                    currentState = state;
                    stateCount = 0;
                }
                stateCount++;
            }
            stateSummary.Add(Tuple.Create(currentState, stateCount));

            var maxHandstands = 0;
            var uprightGroups = stateSummary.Count(t => !t.Item1);
            if (uprightGroups <= k)
            {
                // 直立している人のグループが操作回数以下であれば、全員逆立ちにできる
                maxHandstands = n;
            }
            else
            {
                // 直立している人のグループが操作回数より多いのであれば、連続する k 個の直立グループを反転させて最大をとる
                var left = stateSummary[0].Item1 ? 1 : 0;
                var right = left + 2 * (k - 1);
                var sum = 0;
                for (var i = left - 1; i <= right + 1; i++)
                {
                    if (i < 0) continue;
                    sum += stateSummary[i].Item2;
                }

                maxHandstands = sum;

                for (var i = 0; i < uprightGroups - k; i++)
                {
                    if (0 <= left - 1) sum -= stateSummary[left - 1].Item2;
                    sum -= stateSummary[left].Item2;
                    left += 2;
                    right += 2;
                    sum += stateSummary[right].Item2;
                    if (right + 1 < stateSummary.Count) sum += stateSummary[right + 1].Item2;

                    if (maxHandstands < sum) maxHandstands = sum;
                }
            }

            // 解答の出力
            Console.WriteLine(maxHandstands);
        }
    }
}


Measured memory_bytes: 18016
#include<iostream>
using namespace std;
int main()
{
	int A[5][4][11],n; 
	for(int i=1;i<=4;i++)
		for(int j=1;j<=3;j++)
			for(int k=1;k<=10;k++)A[i][j][k]=0;

	cin>>n;
	for(int i=0;i<n;i++){
		int b,f,r,v;
		cin>>b>>f>>r>>v;
		A[b][f][r]+=v;
	}

	for(int f=1;f<=4;f++){
		if(f>1)cout<<"####################\n";
		for(int b=1;b<=3;b++){
			for(int r=1;r<=10;r++){
				cout<<" "<<A[f][b][r];
			}
			cout<<endl;
		}
	}

	return 0;
}

Measured memory_bytes: 1168
n, m = [int(i) for i in input().split()]
data = []  # P, Y and Order
for i in range(m):
    arr = [int(k) for k in input().split()]
    data.append(arr + [i])

data.sort()
id = []  # P, x and Order
now_p = rank = 0
for p, _, o in data:
    if now_p != p:
        now_p = p
        rank = 1
    id.append([p, rank, o])
    rank += 1

id.sort(key=lambda x: x[2])
for p, x, _ in id:
    print('{:06}{:06}'.format(p, x))


Measured memory_bytes: 37884
from collections import deque
N, M = map(int, input().split())
G = [[] for _ in range(N+1)]

for i in range(M):
    x, y = map(int, input().split())
    G[x].append(y)
    G[y].append(x)

USED = [-1] * (N+1)
USED[0] = 0
USED[1] = 0

Q = deque()
Q.append(1)

while Q:
    x = Q.pop()
    for t in G[x]:
        if USED[t] == -1:
            Q.appendleft(t)
            USED[t] = x

if -1 in USED:
    print("No")
else:
    print("Yes")
    print(*USED[2:])


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

using namespace std;

int main()
{
	int t1;
	t1=1;
	while(t1--)
	{
	
	string s,t;
	int n,m,i,j,k;
	
	cin>>s>>t;
	
	
	n=s.length();
	m=t.length();
	k=n+1;
	for(i=0;i<=n-m;i++)
	{
	 string g=s.substr(i,m);
	 
	 
	 int f=0;
	 for(j=0;j<m;j++)
	 {
	 	if(g[j]!=t[j])
	 	f++;
	 	
	 }
		
		k=min(f,k);
		
	}
	
	cout<<k<<endl;
	
	}



}


Measured memory_bytes: 3632
package main

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

var sc = bufio.NewScanner(os.Stdin)

func Scan() string {
	sc.Scan()
	return sc.Text()
}
func iScan() int {
	n, _ := strconv.Atoi(Scan())
	return n
}
func fScan() float64 {
	n, _ := strconv.ParseFloat(Scan(), 64)
	return n
}
func stringToInt(s string) int {
	n, _ := strconv.Atoi(s)
	return n
}
func SScan(n int) []string {
	a := make([]string, n)
	for i := 0; i < n; i++ {
		a[i] = Scan()
	}
	return a
}
func iSScan(n int) []int {
	a := make([]int, n)
	for i := 0; i < n; i++ {
		a[i] = iScan()
	}
	return a
}
func abs(x int) int {
	if x < 0 {
		x = -x
	}
	return x
}
func larger(a, b int) int {
	if a < b {
		return b
	} else {
		return a
	}
}
func smaller(a, b int) int {
	if a > b {
		return b
	} else {
		return a
	}
}
func max(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x < a[i] {
			x = a[i]
		}
	}
	return x
}
func min(a []int) int {
	x := a[0]
	for i := 0; i < len(a); i++ {
		if x > a[i] {
			x = a[i]
		}
	}
	return x
}
func sum(a []int) int {
	x := 0
	for _, v := range a {
		x += v
	}
	return x
}
func fSum(a []float64) float64 {
	x := 0.
	for _, v := range a {
		x += v
	}
	return x
}

var mod int = 1000000007

func main() {
	buf := make([]byte, 0)
	sc.Buffer(buf, mod)
	sc.Split(bufio.ScanWords)
	n := iScan()
	m := iScan()
	uf := newUnionFind(n)
	for i := 0; i < m; i++ {
		uf.unite(iScan()-1, iScan()-1)
	}
	ans := 1
	for i := 0; i < n; i++ {
		ans = larger(ans, uf.size(i))
	}
	fmt.Println(ans)
}

type UnionFind struct {
	par []int
}

func newUnionFind(N int) *UnionFind {
	u := new(UnionFind)
	u.par = make([]int, N)
	for i := range u.par {
		u.par[i] = -1
	}
	return u
}
func (u UnionFind) root(x int) int {
	if u.par[x] < 0 {
		return x
	}
	u.par[x] = u.root(u.par[x])
	return u.par[x]
}
func (u UnionFind) unite(x, y int) {
	xr := u.root(x)
	yr := u.root(y)
	if xr == yr {
		return
	}
	u.par[yr] += u.par[xr]
	u.par[xr] = yr
}
func (u UnionFind) same(x, y int) bool {
	if u.root(x) == u.root(y) {
		return true
	}
	return false
}
func (u UnionFind) size(x int) int {
	return -u.par[u.root(x)]
}


Measured memory_bytes: 33056
import java.util.Scanner;

public class Main{
    public static void main(String args[]){
	Scanner sc = new Scanner(System.in);
	int N = sc.nextInt();
	int A[] = new int[N];
	int B[] = new int[N];
	int C[] = new int[N];
	int ans = 0;

	for(int i = 0; i < N; i++){
	    A[i] = sc.nextInt();
	}
	for(int i = 0; i < N; i++){
	    B[i] = sc.nextInt();
	}
	for(int i = 0; i < N - 1; i++){
	    C[i] = sc.nextInt();
	}

	int num = 0;	
	for(int i = 0; i < N; i++){
	    num = (A[i] - 1);
	    ans = ans + B[num];
	    if((i + 1) != N && A[i + 1] - A[i] == 1){
		ans = ans + C[num];
	    }
	}

	System.out.println(ans);
    }
}


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

int main()
{
	int n, m;
	cin >> n >> m;
	
	int map[]{ -1, -1, -1 };
	bool is_error = false;
	rep (i, m) {
		int x, y;
		cin >> x >> y;
		--x;

		if (map[x] != -1 && map[x] != y) is_error = true;
		if (n > 1 && x == 0 && y == 0) is_error = true;

		map[x] = y;
	}

	if (is_error) {
		cout << -1 << endl;
		return 0;
	}

	rep(i, n) {
		if (map[i] == -1) {
			if (i == 0) {
				if (n == 1)
					map[i] = 0;
				else
					map[i] = 1;
			}
			else map[i] = 0;
		}
	}

	int ans = 0;
	rep(i, n) {
		ans += pow(10, n - i - 1) * map[i];
	}

	cout << ans << endl;
}


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

using namespace std;

int N, M, t[4018], lev[4018], d[4018], ap[4018], x[4018], y[4018], z[4018], extras[4018], p2[4018];
long long X, mst0;
const int mod = 1e9 + 7;
vector < pair < int, int > > v[4018];

int add (int x, int y) {int ans = x + y; if (ans >= mod) ans -= mod; return ans;}
int subtract (int x, int y) {if (x >= y) return x - y; return x - y + mod;}
int mul (int x, int y) {return 1LL * x * y % mod;}
void adto (int &x, int y) {x += y; if (x >= mod) x -= mod;}

pair < int, pair < int, int > > e[4018];
void read ()
{
    scanf ("%d %d\n%lld\n", &N, &M, &X), p2[0] = 1;
    for (int i=1; i<=M; i++)
        scanf ("%d %d %d", &e[i].second.first, &e[i].second.second, &e[i].first), p2[i] = add (p2[i - 1], p2[i - 1]);
    sort (e + 1, e + M + 1);
    for (int i=1; i<=M; i++)
        x[i] = e[i].second.first, y[i] = e[i].second.second, z[i] = e[i].first;
}

int tata (int x)
{
    if (t[x] == x) return x;
    return t[x] = tata (t[x]);
}

void addEdge (int x, int y, int z)
{
    v[x].push_back ({y, z});
    v[y].push_back ({x, z});
}

void buildMst0 ()
{
    for (int i=1; i<=N; i++)
        t[i] = i;
    for (int i=1; i<=M; i++)
    {
        int a = x[i], b = y[i];
        if (tata (a) != tata (b))
            mst0 += z[i], t[tata (a)] = tata (b), addEdge (a, b, z[i]), ap[i] = 1;
    }
}

void dfs (int nod)
{
    for (auto it : v[nod])
        if (it.first != t[nod])
            lev[it.first] = lev[nod] + 1, t[it.first] = nod, d[it.first] = it.second, dfs (it.first);
}

int maxOnPath (int x, int y)
{
    int ans = 0;
    while (x != y)
    {
        if (lev[x] > lev[y]) ans = max (ans, d[x]), x = t[x];
        else ans = max (ans, d[y]), y = t[y];
    }
    return ans;
}

void computeAnswer ()
{
    int nr = 0, ans = 0;
    for (int i=1; i<=M; i++)
        if (ap[i] == 0)
            extras[++nr] = z[i] - maxOnPath (x[i], y[i]);
    sort (extras + 1, extras + nr + 1);
    if (X == mst0 && N > 1)
        ans = subtract (p2[N - 1], 2);
    ans = mul (ans, p2[M - N + 1]);
    for (int i=1; i<=nr; i++)
        if (mst0 + extras[i] == X)
            adto (ans, p2[nr - i + 1]);
    printf ("%d\n", ans);
}

int main ()
{
//freopen ("input", "r", stdin);
//freopen ("output", "w", stdout);

read ();
buildMst0 ();
for (int i=1; i<=N; i++)
    t[i] = 0;
dfs (1);
computeAnswer ();
return 0;
}


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

using namespace std;
using ll = long long int;
constexpr ll M = 1e9 + 7;
inline ll sum_1(const ll n) { return ((n * (n + 1)) / 2) % M; }
inline ll sum_2(const ll n) { return ((n * (n + 1) * (2 * n + 1)) / 6) % M; }
inline ll sum_3(const ll n) { return (((n * (n + 1)) / 2) % M * ((n * (n + 1)) / 2) % M) % M; }
inline ll sum_1(const ll i, const ll j) { return (sum_1(j) - sum_1(i - 1) + M) % M; }
inline ll sum_2(const ll i, const ll j) { return (sum_2(j) - sum_2(i - 1) + M) % M; }
inline ll sum_3(const ll i, const ll j) { return (sum_3(j) - sum_3(i - 1) + M) % M; }

void solve() {
    int x, y, z;
    cin >> x >> y >> z;
    swap(x, y);
    swap(x, z);
    cout << x << " " << y << " " << z << endl;
}

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

    solve();

    return 0;
}

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

int main() {
  ios::sync_with_stdio(false);
  cin.tie(0);
  cout << setprecision(20) << fixed;
  long double D, T, S;
  cin >> D >> T >> S;
  if(D / S <= T){
    cout << "Yes" <<endl;
  } else cout << "No" <<endl;
}



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

#define vi vector<int>
#define vii vector<int, int>
#define ll long long
#define pb push_back
#define IOS ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);

#ifdef LOCAL
#define trace(...) __f(#__VA_ARGS__, __VA_ARGS__)
template <typename Arg1>
void __f(const char* name, Arg1&& arg1){
  cerr << name << ": " << arg1 << endl;
}
template <typename Arg1, typename... Args>
void __f(const char* names, Arg1&& arg1, Args&&... args){
  const char* comma = strchr(names + 1, ',');
  cerr.write(names, comma - names) << ": " << arg1 << " |";
  __f(comma + 1, args...);
}
#else
#define trace(...) 42
#endif

int main(){
    IOS;
    string s;
    cin >> s;
    string ans(s.size(), 'x');
    cout << ans << endl;

    #ifdef LOCAL
        cerr << "Time elapsed: " << 1.0 * clock() / CLOCKS_PER_SEC << " s.\n";
    #endif

    return 0;
}




Measured memory_bytes: 256
#include<bits/stdc++.h>
#define N 100005
using namespace std;
char s[N];
int n,delta=0,ans=0;
bool col[N];
int main(){
	scanf("%s",s+1),n=strlen(s+1);
	for(int i=1;i<=n;++i)col[i]=(s[i]=='p');
	for(int i=1;i<=n;++i){
		if(delta<=0)++delta,ans-=col[i];
		else --delta,ans+=(!col[i]);
	}
	cout<<ans;
	return 0;
}

Measured memory_bytes: 384
import sys

def resolve():
    N = int(input())
    cnt = 0
    for i in range(1, N+1, 2):
        if is_8_factors(i):
            cnt += 1
    print(cnt)

def is_8_factors(n):
    nfactors = 2
    upper = n
    div = 3
    while True:
        if upper <= div:
            break
        if n % div == 0:
            nfactors += 2
            upper = n // div
        div += 2

    return True if nfactors == 8 else False

if '__main__' == __name__:
    resolve()

Measured memory_bytes: 38512
A = []
B = []
s = True
while(s):
    try:
        a,b = map(int, input().split())
    except:
        break
    A.append(a)
    B.append(b)

for i in range(len(A)):
    sum = A[i] + B[i]
    digits = 1
    while(sum//10 != 0):
        digits += 1
        sum //= 10
    print(str(digits))



Measured memory_bytes: 5604
#include<stdio.h>

int main(void){
	int w[300], h[300];
	int i_count = 0;
	while (1){
		scanf("%d %d", &h[i_count], &w[i_count]);
		if (h[i_count] == 0 && w[i_count] == 0)
			break;

		i_count++;
	}

	int i, j,n=i_count;
	for (i_count = 0; i_count < n; i_count++){
		for (i = 0; i < h[i_count]; i++){
			for (j = 0; j < w[i_count]; j++){
				if ((i == 0 || i == h[i_count]-1) || (j == 0 || j == w[i_count]-1))
					printf("%c", '#');
				else
					printf("%c", '.');
			}
			putchar('\n');
		}
		putchar('\n');
	}


	return 0;
}


Measured memory_bytes: 2052
#include <bits/stdc++.h>
using namespace std;
#pragma GCC optimize("Ofast")
#pragma GCC target("avx")
#define all(x) (x).begin(),(x).end()
#define rep(i,n) for(int (i)=0;i<(n);i++)
#define rrep(i,n) for(int (i)=1;i<=(n);i++)
#define REP(i,m,n) for(int (i)=(m);(i)<(n);(i)++)
#define MOD 1000000007
#define INF 1e18
#define int long long
#define endl "\n"
#define yorn(f) puts((f)?"Yes":"No")
#define YORN(f) puts((f)?"YES":"NO")
typedef long long ll;
typedef pair<int, int> P;
int gcd(int a,int b){return b?gcd(b,a%b):a;};
int lcm(int a,int b){return a/gcd(a,b)*b;};
int mod(int a,int b){return (a+b-1)/b;};
template<typename A, size_t N, typename T>
void Fill(A(&array)[N],const T &val){std::fill((T*)array,(T*)(array+N),val);}
template<class T>inline bool chmax(T& a,T b){if(a<b){a=b;return true;}return false;};
template<class T>inline bool chmin(T& a,T b){if(a>b){a=b;return true;}return false;};

std::vector<int> sieve(int n) {
  std::vector<int> res(n);
  std::iota(res.begin(), res.end(), 0);
  for (int i = 2; i*i < n; ++i) {
    if (res[i] < i) continue;
    for (int j = i*i; j < n; j += i)
      if (res[j] == j) res[j] = i;
  }
  return res;
}

std::vector<int> factor(int n, const std::vector<int>& min_factor) {
  // min_factor は sieve() で得られたものとする
  std::vector<int> res;
  //res.push_back(1);
  while (n > 1) {
    res.push_back(min_factor[n]);
    n /= min_factor[n];
    // 割った後の値についても素因数を知っているので順次求まる
  }
  return res;
}

signed main() {
	cin.tie(0);
	cout.tie(0);
	ios::sync_with_stdio(false);
	//cout << fixed << setprecision(15);
	
	int n;
	cin >> n;
	int ans = 1;
	vector<int> si = sieve(n+1);
	for(int i = 2; i <= n; i++) {
		vector<int> cur = factor(i, si);

		int now = 1, t = 1;
		//rep(i, cur.size()) cout << cur[i] << " ";
		//cout << endl;
		REP(i, 1, cur.size()) {
			if(cur[i] == cur[i-1]) t++;
			else {
				now *= (t + 1);
				t = 1;
			}
		}
		now *= t + 1;
		ans += now * i;
		//cout << i << ": " << now << endl;
	}
	cout << ans << endl;
	return 0;
}

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

typedef long long ll;
const int INF = 1e9;
const int MOD = 1e9 + 7;
const ll LINF = 1e18;
#define y0 y3487465
#define y1 y8687969
#define j0 j1347829
#define j1 j234892
#define next asdnext
#define prev asdprev
#define dump(x)  cout << #x << " = " << (x) << endl;	//debug
#define SZ(x) ((int)(x).size())
#define REP(i, n) for(ll i = 0; i < (n); i++)
#define REPR(i, n) for (ll i = (n); i >= 0; i--)
#define FOR(i, a, b) for (ll i = (a); i <= (b); i++)
#define RFOR(i, a, b) for (ll i = (a); i >= (b); i--)
#define ps(s) cout << #s << endl;
#define pv(v) cout << (v) << endl;
#define ALL(a)  (a).begin(),(a).end()
#define RANGE(a, l, r)  (a).begin()+(l),(a).begin()+(r)


int main() {
	int n;
	cin >> n;
	vector<string> sv(n);
	FOR(i, 0, n - 1) {
		cin >> sv[i];
		sort(ALL(sv[i]));
	}
	sort(ALL(sv));

	ll cnt = 1;
	ll i = 0;
	ll res = 0;
	while (1) {
		while (sv[i] == sv[i + 1]) {
			cnt++;
			i++;
			if (i == n - 1) {
				if (cnt >= 2) {
					res += cnt*(cnt - 1) / 2;
				}
				pv(res);
				return(0);
			}
		}
		if (cnt >= 2) {
			res += cnt*(cnt - 1) / 2;
		}
		cnt = 1;
		i++;
		if (i == n - 1) {
			if (cnt >= 2) {
				res += cnt*(cnt - 1) / 2;
			}
			pv(res);
			return(0);
		}
	}

	return(0);
}

Measured memory_bytes: 7296
import java.util.*;
import java.io.*;
 
public class Main {
    static int ans = 0;
    public static void main(String[] args) throws Exception {
        FastScanner sc = new FastScanner(System.in);
        int n = sc.nextInt();
        ArrayList<Dish> li = new ArrayList<>();
        for(int i = 0; i < n; i++){
            li.add(new Dish(sc.nextLong(),sc.nextLong()));
        }
        Collections.sort(li);
        long ans = 0;
        for(int i = 0; i < n; i++){
            if(i % 2 == 0){
                ans += li.get(i).t;
            }else{
                ans -= li.get(i).a;
            }
        }
        System.out.println(ans);
    }
}

class Dish implements Comparable<Dish>{
    long t,a,total;
    public Dish(long t, long a){
        this.t = t;
        this.a = a;
        this.total = t+a;
    }
    public int compareTo(Dish d){
        if(this.total > d.total){
            return -1;
        }else if(this.total < d.total){
            return 1;
        }else{
            return 0;
        }
    }
    
}
class FastScanner {
    private BufferedReader reader = null;
    private StringTokenizer tokenizer = null;
    public FastScanner(InputStream in) {
        reader = new BufferedReader(new InputStreamReader(in));
        tokenizer = null;
    }
    
    public void close() throws Exception{
        this.reader.close();
        return;
    }

    public String next() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                tokenizer = new StringTokenizer(reader.readLine());
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken();
    }

    public String nextLine() {
        if (tokenizer == null || !tokenizer.hasMoreTokens()) {
            try {
                return reader.readLine();
            } catch (IOException e) {
                throw new RuntimeException(e);
            }
        }
        return tokenizer.nextToken("\n");
    }

    public long nextLong() {
        return Long.parseLong(next());
    }

    public int nextInt() {
        return Integer.parseInt(next());
    }

    public double nextDouble() {
         return Double.parseDouble(next());
    }

    public int[] nextIntArray(int n) {
        int[] a = new int[n];
        for (int i = 0; i < n; i++)
            a[i] = nextInt();
        return a;
    }

    public long[] nextLongArray(int n) {
        long[] a = new long[n];
        for (int i = 0; i < n; i++)
            a[i] = nextLong();
        return a;
    } 
}


Measured memory_bytes: 47928
// https://atcoder.jp/contests/abc058/tasks/abc058_a

#include <iostream>
using namespace std;

int main()
{
  /* Magic word */
  cin.tie(0);
  ios::sync_with_stdio(false);
  /* ---------- */

  int a, b, c;
  string r;

  cin >> a >> b >> c;

  r = b - a == c - b ? "YES" : "NO";

  cout << r << "\n";

  return 0;
}


Measured memory_bytes: 256
//#define _GLIBCXX_DEBUG
#include "bits/stdc++.h"

using namespace std;

//------------------------------- Type Names -------------------------------//

using i64 = int_fast64_t;

using seika = string;
//{akari : 1D, yukari : 2D, maki : 3D} vector
template <class kizuna>
using akari = vector<kizuna>;
template <class yuzuki>
using yukari = akari<akari<yuzuki>>;
template <class tsurumaki>
using maki = akari<yukari<tsurumaki>>;
//{akane : ascending order, aoi : decending order} priority queue
template <class kotonoha>
using akane = priority_queue<kotonoha, akari<kotonoha>, greater<kotonoha>>;
template <class kotonoha>
using aoi = priority_queue<kotonoha>;

//------------------------------- Libraries ---------------------------------//

//------------------------------- Dubug Functions ---------------------------//
inline void print()
{
    cout << endl;
}
template <typename First, typename... Rest>
void print(const First &first, const Rest &... rest)
{
    cout << first << ' ';
    print(rest...);
}
//------------------------------- Solver ------------------------------------//

void solve()
{
    int h, w;
    cin >> h >> w;
    yukari<int> g(h, akari<int>(w));
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            cin >> g[i][j];
        }
    }
    for (int i = 0; i < h; i++)
    {
        for (int j = 0; j < w; j++)
        {
            int b;
            cin >> b;
            g[i][j] = abs(g[i][j] - b);
        }
    }
    const int m = 6400;
    akari<bitset<12801>> dp(w);
    dp[0].set(m);
    for (int i = 0; i < h; i++)
    {
        akari<bitset<12801>> nx(w);
        for (int j = 0; j < w; j++)
        {
            int k = g[i][j];
            nx[j] |= dp[j] << k;
            nx[j] |= dp[j] >> k;
            if (j)
            {
                nx[j] |= nx[j - 1] << k;
                nx[j] |= nx[j - 1] >> k;
            }
        }
        swap(dp, nx);
    }
    //print(dp.back());
    int ans = 1e9;
    for (int i = 0; i <= 12800; i++)
    {
        if (dp.back().test(i))
        {
            ans = min(ans, abs(i - m));
        }
    }
    cout << ans << endl;
}

int main()
{
    solve();
    return 0;
}


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

int main() {
	int n, c;
	int sum = 0;
	cin >> n >> c;
	n++;
	int p[105] = { 0 };
	for (int i = 0; i < c; i++) {
		cin >> p[i];
		sum += p[i];
	}
	if(sum%n==0) cout << sum / n << endl;
	else cout << sum / n + 1 << endl;
	return 0;
}


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

int main() {
    pair< int, pair< int, int > > a, b;
    cin >> a.first >> a.second.first >> a.second.second;
    cin >> b.first >> b.second.first >> b.second.second;

    if (a > b) swap(a, b);

    if (a.second < b.second) cout << b.first-a.first+1 << endl;
    else cout << b.first-a.first << endl;

    return 0;
}


Measured memory_bytes: 3112
#include <cstdio>
#include <iostream>
#include <cmath>
#include <cstring>
#include <sstream>
#include <algorithm>
#include <cstdlib>
#include <map>
#include <queue>
#include <utility>
#include <vector>
#include <set>
#include <memory.h>
#include <iomanip>
#include <bitset>
#include <list>
#include <stack>
#include <deque>
#include <numeric>

using namespace std;

#define mod 1000000007

int main()
{
	int a, b;
	cin >> a >> b;
	if((a * b) % 2 == 0) cout << "Even" << endl;
	else cout << "Odd" << endl;
}

Measured memory_bytes: 256
//http://judge.u-aizu.ac.jp/onlinejudge/description.jsp?id=0351

#include<bits/stdc++.h>
const int N = 1505;
const int inf = 1e9;
using namespace std;

typedef pair <int, int> ii;
vector <ii> adj[N];
int n, m, d[N][N], ans, visit[N], f[N], ck[N];

void dijkstra(int S){
    for (int i = 1; i <= n; i++) d[S][i] = inf; d[S][S] = 0;
    priority_queue <ii, vector <ii>, greater<ii> > mq; mq.push(ii(d[S][S], S));
    while (mq.size()){
        ii z = mq.top(); mq.pop();
        int u = z.second, val = z.first;
        if (val != d[S][u]) continue;
        ans = max(ans, val);
        for (int i = 0; i < adj[u].size(); i++){
            int v = adj[u][i].first, cost = adj[u][i].second;
            if (d[S][v] > d[S][u] + cost){
                d[S][v] = d[S][u] + cost;
                mq.push(ii(d[S][v], v));
            }
        }
    }
}

void dfs(int u, int root){
    if (visit[u]) return;
    visit[u] = true;
    f[u] = d[root][u];
    for (int i = 0; i < adj[u].size(); i++){
        int v = adj[u][i].first, cost = adj[u][i].second;
        if (d[root][v] == d[root][u] + cost){
            dfs(v, root); f[u] = max(f[u], f[v]);
        }
    }
    if (f[u] == ans) ck[u] = 1;
}

int main(){
    ios_base::sync_with_stdio(false); cin.tie(0); cout.tie(0);
    cin >> n >> m;
    for (int i = 1; i <= m; i++){
        int u, v, d; cin >> u >> v >> d;
        adj[u].push_back(ii(v, d));
        adj[v].push_back(ii(u, d));
    }
    for (int i = 1; i <= n; i++) dijkstra(i);
    for (int i = 1; i <= n; i++){
        for (int j = 1; j <= n; j++) visit[j] = 0;
        dfs(i, i);
    }
    int cnt = 0; for (int i = 1; i <= n; i++) if (!ck[i]) cnt++;
    cout << cnt << "\n";
    for (int i = 1; i <= n; i++) if (!ck[i]) cout << i << "\n";
}



Measured memory_bytes: 12228
N, K = map(int, input().split())
V = list(map(int, input().split()))
ans = 0
for pick in range(min(K+1, N+1)):
    for right in range(pick+1):
        left = pick - right
        pick_list = V[:right] + V[N-left:]

        pick_list.sort()
        tmp_ans = sum(pick_list)
        rem = min(K - pick, len(pick_list))
        for i in range(rem):
            if pick_list[i] < 0:
                tmp_ans -= pick_list[i]
            else:
                break
        ans = max(tmp_ans, ans)
print(ans)

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

typedef long long ll;
const int maxn = 100010;
int n, K, a[maxn], b[maxn], L[maxn], R[maxn], t[maxn << 3];
ll sum[maxn], f[maxn];

#define mid (l + r >> 1)
#define ls (k << 1)
#define rs (k << 1 | 1)
void pushdown(int k) {
    t[ls] = t[rs] = t[k], t[k] = 0;
}

void modify(int k, int l, int r, int ql, int qr, int v) {
    if (ql > qr) return;
    if (l >= ql && r <= qr) { t[k] = v; return; }
    if (t[k]) pushdown(k);
    if (mid >= ql) modify(ls, l, mid, ql, qr, v);
    if (mid < qr) modify(rs, mid + 1, r, ql, qr, v);
}

int query(int k, int l, int r, int p) {
    if (l == r) return t[k];
    if (t[k]) pushdown(k);
    if (mid >= p) return query(ls, l, mid, p);
    else return query(rs, mid + 1, r, p);
}

int main() {
    scanf("%d %d", &n, &K);
    for (int i = 1; i <= n; i++) {
        scanf("%d %d", &a[i], &b[i]);
        sum[i] = sum[i - 1] + a[i];
        if (b[i] == 1 && 2 * a[i] > K) printf("-1\n"), exit(0);
    }
    vector<int> V;
    for (int i = 1; i <= n; i++) {
        if (b[i] == 1) {
            L[i] = (-2 * sum[i - 1] % K + K) % K;
            R[i] = (-2 * sum[i] % K + K) % K;
        } else {
            L[i] = 0, R[i] = K - 1;
        }
        V.push_back(L[i]), V.push_back(R[i]);
    }
    sort(V.begin(), V.end());
    V.resize(unique(V.begin(), V.end()) - V.begin());
    for (int i = 1; i <= n; i++) {
        L[i] = lower_bound(V.begin(), V.end(), L[i]) - V.begin();
        R[i] = lower_bound(V.begin(), V.end(), R[i]) - V.begin();
    }
    auto get = [&](int x) {
        int y = query(1, 0, V.size() - 1, x);
        return !y ? 0 : f[y] + (V[L[y]] - V[x] + K) % K;
    };
    for (int i = n; i; i--) {
        f[i] = get(L[i]);
        if (R[i] < L[i]) {
            modify(1, 0, V.size() - 1, R[i] + 1, L[i] - 1, i);
        } else {
            modify(1, 0, V.size() - 1, 0, L[i] - 1, i);
            modify(1, 0, V.size() - 1, R[i] + 1, V.size() - 1, i);
        }
    }
    ll ans = LLONG_MAX;
    for (int i = 0; i < V.size(); i++) {
        ans = min(ans, get(i));
    }
    printf("%lld\n", ans + (sum[n] << 1));
    return 0;
}

Measured memory_bytes: 8476