akhauriyash/Code-Regression huggingface dataset:
use std::io;
use std::str::FromStr;

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

fn input_vec() -> Vec<i64> {
    let mut line: String = String::new();
    io::stdin().read_line(&mut line);
    line.split_whitespace().map(|s| s.parse().unwrap()).collect()
}

// 累積和
struct Cummulation {
    sums: Vec<i64>
}

impl Cummulation {
    fn new(target: &Vec<i64>) -> Cummulation {
        let mut cumulation_vec: Vec<i64> = Vec::new();
        cumulation_vec.push(0);
        let mut pre = 0;
        for i in target {
            let n = i + pre;
            cumulation_vec.push(n);
            pre = n;
        }
        Cummulation {sums: cumulation_vec}
    }

    fn get(&self, left: usize, right: usize) -> i64 {
        self.sums[right + 1] - self.sums[left]
    }
}

fn binary_search(left_boundary: usize, right_boundary: usize, cummulation: &Cummulation) -> i64 {
    let mut left = left_boundary as i64 - 1;
    let mut right = right_boundary as i64 + 1;
    let mut mid: i64;
    loop {
        if (right - left).abs() <= 1 {
            if left < 0 {
                return right;
            }
            if right >= right_boundary as i64 + 1 {
                return left;
            }
            if (cummulation.get(left_boundary, left as usize) - cummulation.get(left as usize + 1, right_boundary)).abs() 
            < (cummulation.get(left_boundary, right as usize) - cummulation.get(right as usize + 1, right_boundary)).abs() {
                return left;
            } else {
                return right;
            }
        }

        mid = (left + right) / 2;
        if cummulation.get(left_boundary, mid as usize) < cummulation.get(mid as usize + 1, right_boundary) {
            left = mid;
        } else {
            right = mid;
        }   
    }

}

fn main() {
    let n: usize = input();
    let a_vec = input_vec();
    let mut sum_vec: Vec<i64> = Vec::new();
    sum_vec.push(0);
    for i in 0..n {
        sum_vec.push(a_vec[i] + sum_vec[i]);
    }
    let cummulation = Cummulation::new(&a_vec);
    let mut ans = std::i64::MAX;
    for half in 1..(n-2) {
        let mut candidates: Vec<i64> = Vec::new();
        let quater = binary_search(0, half, &cummulation);
        candidates.push(cummulation.get(0, quater as usize));
        candidates.push(cummulation.get(quater as usize + 1, half));

        let quater_third = binary_search(half + 1, n - 1, &cummulation);
        candidates.push(cummulation.get(half + 1, quater_third as usize));
        candidates.push(cummulation.get(quater_third as usize + 1, n - 1));
        candidates.sort();
        if candidates[3] - candidates[0] < ans {
            ans = candidates[3] - candidates[0];
        }
    }
    println!("{}", ans);
}


Measured memory_bytes: 7868
import java.util.*;
import java.io.*;
public class Main {
    static long arr[],dp[][],pre_sum[];
    public static void main(String args[]) {
        Scanner input=new Scanner(System.in);
        int n=input.nextInt();
        arr=new long[n];
        pre_sum=new long[n];
        for(int i=0;i<n;i++) {
            arr[i]=input.nextLong();
            if(i==0) {
                pre_sum[i]=arr[i];
            }
            else {
                pre_sum[i]=pre_sum[i-1]+arr[i];
            }
        }
        dp=new long[n][n];
        for(int i=0;i<n;i++) {
            for(int j=0;j<n;j++) {
                dp[i][j]=-1;
            }
        }
        System.out.println(solve(0,n-1));
    }
    public static long solve(int l,int r) {
        if(l==r) {
            return 0;
        }
        if(dp[l][r]!=-1) {
            return dp[l][r];
        }
        long cost=Long.MAX_VALUE;
        for(int i=l;i<r;i++) {
            long cst=solve(l,i)+solve(i+1,r)+(prefix_sum(l,i)+prefix_sum(i+1,r));
            cost=Math.min(cost,cst);
        }
        dp[l][r]=cost;
        return dp[l][r];
    }
    public static long prefix_sum(int l,int r) {
        if(l==0) {
            return pre_sum[r];
        }
        else {
            return pre_sum[r]-pre_sum[l-1];
        }
    }
}


Measured memory_bytes: 25384
N, C = map(int, input().split())
stc = [list(map(int, input().split())) for _ in range(N)]

max_t = 0
for s, t, c in stc:
  max_t = max(max_t, t)

T = [[0 for _ in range(max_t + 2)] for _ in range(C + 1)] 
for i in range(N):
  s, t, c = stc[i]
  T[c][s] = t - s + 1
#print("T:", T[1:])

for c in range(1, C + 1):
  for i in range((max_t + 2) - 1):
    if T[c][i]:
      if T[c][i + 1] == 0:
        T[c][i + 1] = T[c][i] - 1
      T[c][i] = 1      
#print("T:", T[1:])

answer = []
for i in range(max_t + 2):
  cnt = 0
  for c in range(1, C + 1):
    if T[c][i]:
      cnt += 1
  answer.append(cnt)
#print("answer:", answer)
print(max(answer))

Measured memory_bytes: 129924
n = int(input())

t_l = input().split()
l = []
for i in t_l:
    l.append(int(i))

h = [-1 for i in l]

h[0] = 0
h[1] = abs(l[0] - l[1])

i = 2
while i < len(l):
    h[i] = min(h[i-1] + abs(l[i-1] - l[i]), 
    h[i-2] + abs(l[i-2] -l[i]))
    i+=1

print(h[len(l)-1])





Measured memory_bytes: 17888
#include <bits/stdc++.h>
using namespace std;
typedef long long lint;
typedef long double llf;
typedef pair<lint, lint> pi;
const int MAXN = 100005;

int n, a[100005];

int main(){
	lint ans = 0;
	cin >> n;
	int cnt = 1;
	for(int i=1; i<=n; i++){
		int x;
		cin >> x;
		ans += (x - 1) / cnt;
		if(x == cnt || cnt == 1) cnt++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
require 'set'; require 'prime'; require 'pp'
INF=Float::INFINITY; MOD=10**9+7
h,w,m = gets.chomp.split.map(&:to_i)
set = Set.new
rows = Array.new(h, 0)
cols = Array.new(w, 0)
m.times do
  y,x = gets.chomp.split.map{|e| e.to_i - 1}
  rows[y] += 1
  cols[x] += 1
  set.add [y, x]
end

rowmax = rows.max
colmax = cols.max

rows = rows.zip((0...h).to_a)
cols = cols.zip((0...w).to_a)

rows0 = rows.select{|row| row[0] == rowmax}
cols0 = cols.select{|col| col[0] == colmax}

rows0.each do |row_v, row_i|
  cols0.each do |col_v, col_i|
    unless set.include? [row_i, col_i]
      puts row_v + col_v
      exit
    end
  end
end
puts rows0[0][0] + cols0[0][0] - 1


Measured memory_bytes: 90780
#include <iostream>
#include<algorithm>
#include <vector>
#include<string>
#include<cmath>
#include<cstdio>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define max(x,y) (((x)>(y)) ? x:y)
#define min(x,y) (((x)<(y)) ? x:y)
#define FOR(a) for(int i=0;i<a;i++)
#define ender {return 0;}
#define tosasuretu(a) (a*(a+1)/2)
inline ll kaizyo(ll);
ll gcd(ll, ll);
ll combination(ll, ll);
int main() {
	int n, m, c;
	cin >> n >> m >> c;
	int ain;
	int total;
	int number = 0;
	int b[100];
	FOR(m) {
		cin >> b[i];
	}
	FOR(n) {
		total = 0;
		for (int j = 0; j < m; j++) {
			cin >> ain;
			total += (ain * b[j]);
		}
		total += c;
		if (total > 0)number++;
	}
	cout << number;
	return 0;
}


inline ll kaizyo(ll x) {
	long ans = 1;
	for (int z = 0; z < x; z++) {
		ans *= (x - z);
	}
	return ans;
}
ll gcd(ll a, ll b) {
	if (b == 0)return a;
	return gcd(b, a%b);
}

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

int main() {
	int N,ans=0;
	cin>>N;
	vector<int>A(N);
	vector<int>B(N);
	vector<int>C(N-1);
	for(int i=0;i<N;++i)cin>>A[i];
	for(int i=0;i<N;++i)cin>>B[i];
	for(int i=0;i<N-1;++i)cin>>C[i];
	for(int i=0;i<N;++i){
		ans+=B[A[i]-1];
		if(i!=0&&A[i]-A[i-1]==1){
			ans+=C[A[i-1]-1];
		}
	}
	cout<<ans;
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <utility>
#include <algorithm>
#include <map>
#include <set>
#include <vector>
#include <cmath>
#include <cstdlib>
#include <queue>
#include <stack>
#include <iomanip>
#include <fstream>
#include <thread>

using namespace std;

#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, m, n) for(ll i = m;i < n;i++)
#define FORR(i, m, n) for(int i = m;i >= n;i--)
#define REPO(i, n) for(ll i = 1;i <= n;i++)
#define ll long long
#define INF (ll)1 << 60
#define MINF (-1 * INF)
#define ALL(n) n.begin(),n.end()
#define MOD (ll)1000000007
#define P pair<ll, ll>

ll h, w, k, ans[310][310], now = 1;
string s[310];
int main() {
	cin >> h >> w >> k;
	REP(i, h)cin >> s[i];
	REP(j, w) {
		REP(i, h) {
			if (s[i][j] == '#') {
				ans[i][j] = now;
				ll pos = i;
				while (1) {
					pos--;
					if (pos < 0)break;
					if (ans[pos][j] != 0)break;
					if (s[pos][j] == '#')break;
					ans[pos][j] = now;
				}
				pos = i;
				while (1) {
					pos++;
					if (pos >= h)break;
					if (ans[pos][j] != 0)break;
					if (s[pos][j] == '#')break;
					ans[pos][j] = now;
				}
				now++;
			}
		}
	}
	REP(i, h) {
		FOR(j, 1, w) {
			if (ans[i][j] == 0)ans[i][j] = ans[i][j - 1];
		}
	}
	REP(i, h) {
		FORR(j, w - 2, 0) {
			if (ans[i][j] == 0)ans[i][j] = ans[i][j + 1];
		}
	}
	REP(i, h) {
		REP(j, w) {
			if (j != 0)cout << " ";
			cout << ans[i][j];
		}
		cout << endl;
	}
}

Measured memory_bytes: 1664
#include <bits/stdc++.h>
#include <ext/pb_ds/assoc_container.hpp>
#include <ext/pb_ds/tree_policy.hpp>
#define vi vector<int>
#define vvi vector<vector<int>>
#define pb push_back
#define pii pair<ll,ll>
#define tii tuple<ll,ll,ll>
#define all(v) (v).begin(),(v).end()
#define ll long long
#define deb(x) cout << #x << "=" << x << endl;
#define ull unsigned long long
#define fastio ios_base::sync_with_stdio(false);cin.tie(nullptr);
#define ld long double
#define mod 1000000007
#define PI 3.141592653589793238
#define phi 1.638
#define eps 1e-9
#define endl "\n"
using namespace std;
using namespace __gnu_pbds;
typedef tree<int, null_type, less<int>, rb_tree_tag, tree_order_statistics_node_update> ordered_set;   


int main() {
    fastio
    ll n;
    cin>>n;
    vector<ll> vec(n);
    for(auto& it : vec) cin>>it;

    ll ans = 0;
    for(int i = 1; i<n; ++i) {
        if(vec[i] < vec[i-1]) {
            ans += vec[i-1] - vec[i];
            vec[i] = vec[i-1];
        }
    }
    cout<<ans<<endl;
}

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

using namespace std;

int main(){
  int banti[2000];
  int N,num,saisyo=20000,saigo=0;
  cin >> N;
  
  for(int i = 1 ; i < 2001 ; i++){
    banti[i] = 0;
  }
  
  for(int i = 0;i < N ; i++){
    cin >> num;
    banti[num] = 1;
    if(saisyo > num){
      saisyo = num;
    }
    if(saigo < num){
    saigo = num;
    }
  }

  //cout << "saisyo is " << saisyo << endl;
  //cout << "saigo is " << saigo << endl;

  cout << (saigo - (saisyo-1)) / 2   << endl;

}



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

template <typename T,typename E>
struct SegmentTree{
  using F = function<T(T,T)>;
  using G = function<T(T,E)>;
  using H = function<E(E,E)>;
  using P = function<E(E,size_t)>;
  Int n;
  F f;
  G g;
  H h;
  T ti;
  E ei;
  P p;
  vector<T> dat;
  vector<E> laz;
  SegmentTree(Int n_,F f,G g,H h,T ti,E ei,
	      P p=[](E a,size_t b){b++;return a;}):
    f(f),g(g),h(h),ti(ti),ei(ei),p(p){
    init(n_);
  }
  void init(Int n_){
    n=1;
    while(n<n_) n*=2;
    dat.assign(2*n-1,ti);
    laz.assign(2*n-1,ei);
  }
  void build(Int n_, vector<T> v){
    for(Int i=0;i<n_;i++) dat[i+n-1]=v[i];
    for(Int i=n-2;i>=0;i--)
      dat[i]=f(dat[i*2+1],dat[i*2+2]);
  }
  inline void eval(Int len,Int k){
    if(laz[k]==ei) return;
    if(k*2+1<n*2-1){
      laz[k*2+1]=h(laz[k*2+1],laz[k]);
      laz[k*2+2]=h(laz[k*2+2],laz[k]);
    }
    dat[k]=g(dat[k],p(laz[k],len));
    laz[k]=ei;
  }
  T update(Int a,Int b,E x,Int k,Int l,Int r){
    eval(r-l,k);
    if(r<=a||b<=l) return dat[k];
    if(a<=l&&r<=b){
      laz[k]=h(laz[k],x);
      return g(dat[k],p(laz[k],r-l));
    }
    return dat[k]=f(update(a,b,x,k*2+1,l,(l+r)/2),
		    update(a,b,x,k*2+2,(l+r)/2,r));
  }
  T update(Int a,Int b,E x){
    return update(a,b,x,0,0,n);
  }
  T query(Int a,Int b,Int k,Int l,Int r){
    eval(r-l,k);
    if(r<=a||b<=l) return ti;
    if(a<=l&&r<=b) return dat[k];
    T vl=query(a,b,k*2+1,l,(l+r)/2);
    T vr=query(a,b,k*2+2,(l+r)/2,r);
    return f(vl,vr);
  }
  T query(Int a,Int b){
    return query(a,b,0,0,n);
  }
  void update(Int k,T x){
    query(k,k+1);//evaluate
    k+=n-1;
    dat[k]=x;
    while(k){
      k=(k-1)/2;
      dat[k]=f(dat[k*2+1],dat[k*2+2]);
    }
  }
};

//INSERT ABOVE HERE
signed main(){
  Int n,q;
  cin>>n>>q;
  
  Int INF = 1e9;
  SegmentTree<Int, Int>::F f=[&](Int a,Int b){return a+b;};
  SegmentTree<Int, Int>::G g=[&](Int a,Int b){return b==INF?a:b;};
  SegmentTree<Int, Int>::H h=[&](Int a,Int b){return b==INF?a:b;};
  SegmentTree<Int, Int>::P p=[&](Int a,size_t b){return a==INF?a:a*b;};

  SegmentTree<Int, Int> seg(n,f,g,h,0,INF,p);
  seg.build(n,vector<Int>(n,0));

  for(Int i=0;i<q;i++){
    Int c,s,t,x;
    cin>>c>>s>>t;
    t++;
    if(c){
      cout<<seg.query(s,t)<<endl;
    }else{
      cin>>x;
      seg.update(s,t,x);
    }
  }
  
  return 0;
}



Measured memory_bytes: 7604
#include<bits/stdc++.h>
#define MB template <class T>
#define Fur(i,x,y) for(int i=x;i<=y;i++)
#define fcin ios::sync_with_stdio(false)
MB T MAX(T x,T y){return x>y?x:y;}
using namespace std;
#define N 400000
char ch[N];
int n,k,a[N],d=1,ans=0,t;
int main(){
    fcin;
    cin>>n>>k>>ch;
    for(int i=0;i<n;){
        while(ch[i]==49)a[d]++,i++;d++;
        while(ch[i]==48)a[d]++,i++;d++;
    }
    Fur(i,1,d)a[i+1]+=a[i];
    t=k*2+1;
    Fur(i,1,d)ans=MAX(ans,a[i]-a[MAX(i-t,0)]),i++;
    cout<<ans<<endl;
}

Measured memory_bytes: 768
// lcmとか__builtin_popcountとかはg++ -std=c++17 default.cppみたいなかんじで
// -fsanitize=undefinedでオーバーフロー検出
#include <bits/stdc++.h>
#define mod 1000000007
#define INF LLONG_MAX
#define ll long long
#define ln cout<<endl
#define Yes cout<<"Yes"<<endl
#define NO cout<<"NO"<<endl
#define YES cout<<"YES"<<endl
#define No cout<<"No"<<endl
#define REP(i,m,n) for(ll i=(ll)(m);i<(ll)(n);i++)
#define rep(i,n) REP(i,0,n)
#define all(x) (x).begin(),(x).end()
#define rall(x) (x).rbegin(),(x).rend()
using namespace std;
ll dx[4]={1,0,-1,0};
ll dy[4]={0,1,0,-1};

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

    ll a,b,c,d,m,n,maxi=0,f=0,mini=INF,sum=0;
    string str;
    cin>>str;
    ll bs=0;
    n=str.length();
    rep(i,n){
        if(str[i]=='B') {
            sum+=n-i-1-bs;
            bs++;
        }
    }
    cout<<sum<<endl;
    return 0;
}

Measured memory_bytes: 3740
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <utility>
#include <vector>
using ll = long long;
#define rep(i, n) for (int i = 0; i < n; i++)
#define repk(i, k, n) for (int i = k; i < n; i++)
#define MOD 1000000007
#define INF 1e9
#define PIE 3.14159265358979323

template <class T>
inline bool chmin(T &a, T b) {
    if (a > b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
inline bool chmax(T &a, T b) {
    if (a < b) {
        a = b;
        return true;
    }
    return false;
}
template <class T>
T GCD(T a, T b) {
    if (b == 0)
        return a;
    else
        return GCD(b, a % b);
}
template <class T>
inline T LCM(T a, T b) {
    return (a * b) / GCD(a, b);
}

using namespace std;
//#inculude <bits/stdc++.h>
#define int long long

signed main() {
    int n;
    cin >> n;
    vector<string> a(n);
    set<string> s;
    rep(i, n) {
        cin >> a[i];
        s.insert(a[i]);
    }
    rep(i, n - 1) {
        if (a[i].back() != a[i + 1].front()) {
            cout << "No" << endl;
            return 0;
        }
    }
    if (s.size() != a.size()) {
        cout << "No" << endl;
        return 0;
    }
    cout << "Yes" << endl;
    return 0;
}

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

using namespace std;

int main() {
  vector<int> A(3);
  for (int i = 0; i < 3; i++) {
    cin >> A[i];
  }

  sort(A.begin(), A.end());
  printf("%d\n", A[2] - A[0]);

  return 0;
}


Measured memory_bytes: 256
fun main(args: Array<String>) {
  val xs = readLine()!!.split(" ").map(String::toInt)
  var minCount = xs.sum()!!
  for (k in xs.min()!!..xs.max()!!) {
    val count = xs.map {
      val delta = k - it
      if (delta >= 0) {
        if (delta % 2 == 0) delta / 2
        else delta / 2 + 2
      } else {
        -delta
      }
    }
        .sum()!!
    minCount = Math.min(minCount, count)
  }
  println(minCount)
}

Measured memory_bytes: 35948
#include <iostream>
#include <cstdio>
#include <cstdlib>
#include <algorithm>
#include <cmath>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <ctime>
#include <cassert>
#include <complex>
#include <string>
#include <cstring>
#include <chrono>
#include <random>
#include <queue>
#include <bitset>
#include <deque>

using namespace std;

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

	int m;
	cin >> m;

	cout << 48 - m << endl;
}

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

const long long MOD = 2019;

void solve(long long L, long long R){
    ll res = 2019;
    for (ll i = L; i < L + 2019 && i <= R; i++) {
        for (ll j = i + 1; j < i + 1 + 2019 && j <= R; j++) {
            res = min(res, i * j % 2019);
        }
    }
    cout << res << endl;
}

int main(){
    long long L;
    scanf("%lld",&L);
    long long R;
    scanf("%lld",&R);
    solve(L, R);
    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
#define LL long long int
#define MAXN 200000

int N, K, prefixSum[MAXN + 3], ptr;
map<int, int> counter;
LL answer;

int mod(int a, int b) {
    if (a >= 0)
        return a%b;
    else {
        int absa = abs(a);
        return (absa/b + (absa%b == 0 ? 0 : 1))*b + a;
    }
}

int main() {
    cin >> N >> K;

    prefixSum[0] = 0;
    for (int i = 1; i <= N; i++) {
        int A;
        cin >> A;

        prefixSum[i] = (prefixSum[i - 1] + A)%K;
    }

    int ptr = 0;
    counter[0] = 1;
    answer = 0;

    for (int i = 1; i <= N; i++) {
        while (i - ptr + 1 > K) {
            counter[mod(prefixSum[ptr] - ptr, K)] -= 1;
            ptr += 1;
        }

        int target = mod(prefixSum[i] - i, K);
        if (counter.find(target) == counter.end()) {
            counter[target] = 1;
        } else {
            answer += counter[target];
            counter[target] += 1;
        }
    }

    cout << answer << endl;
}


Measured memory_bytes: 10368
#include <iostream>
#include <cstdio>
#include <algorithm>
#include <cmath>
#include <string.h>
#include <string>
#include <vector>
#define maxn 10000000
#define pi acos(-1)
using namespace std;
bool visit[maxn+1000000];
int prime[maxn]; ///prime的大小大概估计一下再开数组。大概是（x/lnx）
void getprime(int n)///素数打表；
{
	memset(visit, false, sizeof(visit));
	int num = 0;
	for (int i = 2; i <=n; ++i)
	{
		if ( !visit[i] )  prime[++num] = i;
		for (int j = 1; j <= num && i * prime[j] <= n ;  j++)
		{
			visit[ i  *  prime[j] ]  =  true;
			if (i % prime[j] == 0) break; //此处是重点，避免了很多的重复判断，比如i=9,现在素数是2,3,5,7,进入二重循环，visit[2*9]=1;visit[3*9]=1；这个时候9%3==0，要跳出。因为5*9可以用3*15来代替，如果这个时候计算了，i=15的时候又会被重复计算一次，所以这里大量避免了重复运算。
		}
	}
}
double aabs(double x)
{
	if(x<0)return -x;
	return x;
}
int gcd(int a,int b)
{
	if(a%b==0)return b;
	return gcd(b,a%b);
}
int main(){
	int n,tmp,count = 0,limit;
	scanf("%d",&n);
	for(int i = 0; i < n; i++)
	{
		scanf("%d",&tmp);
		limit = sqrt(tmp);
		for(int j = 2; j <= limit; j++){
			if(tmp%j==0){
				count++;
				break;
			}
		}
	}
	printf("%d\n",n-count);
	return 0;
}



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

using namespace std;
using ll = long long;
// #define int ll
using PII = pair<ll, ll>;

#define FOR(i, a, n) for (ll i = (ll)a; i < (ll)n; ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(x) x.begin(), x.end()

template<typename T> T &chmin(T &a, const T &b) { return a = min(a, b); }
template<typename T> T &chmax(T &a, const T &b) { return a = max(a, b); }
template<typename T> bool IN(T a, T b, T x) { return a<=x&&x<b; }
template<typename T> T ceil(T a, T b) { return a/b + !!(a%b); }

template<typename T> vector<T> make_v(size_t a) { return vector<T>(a); }
template<typename T,typename... Ts>
auto make_v(size_t a,Ts... ts) {
  return vector<decltype(make_v<T>(ts...))>(a,make_v<T>(ts...));
}
template<typename T,typename V> typename enable_if<is_class<T>::value==0>::type
fill_v(T &t, const V &v) { t=v; }
template<typename T,typename V> typename enable_if<is_class<T>::value!=0>::type
fill_v(T &t, const V &v ) { for(auto &e:t) fill_v(e,v); }

template<class S,class T>
ostream &operator <<(ostream& out,const pair<S,T>& a){
  out<<'('<<a.first<<','<<a.second<<')'; return out;
}
template<typename T>
istream& operator >> (istream& is, vector<T>& vec){
  for(T& x: vec) {is >> x;} return is;
}
template<class T>
ostream &operator <<(ostream& out,const vector<T>& a){
  out<<'['; for(T i: a) {out<<i<<',';} out<<']'; return out;
}

int dx[] = {0, 1, 0, -1}, dy[] = {1, 0, -1, 0}; // DRUL
const int INF = 1<<30;
const ll LLINF = 1LL<<60;
const ll MOD = 1000000007;

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

  ll n;
  cin >> n;
  string a, b, c;
  cin >> a >> b >> c;

  ll ret = 0;
  REP(i, n) {
    if(a[i] == b[i] && b[i] == c[i]) {

    } else if(a[i] == b[i] || b[i] == c[i] || c[i] == a[i]) {
      ret++;
    } else {
      ret += 2;
    }
  }
  cout << ret << endl;

  return 0;
}

Measured memory_bytes: 256
#ifndef LOCAL
#pragma GCC optimize("O2")
#endif
#include <iostream>
#include <vector>
#include<algorithm>
using namespace std;

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

    char previous_char;
    int point = 0;
    for(int i=0; i<N; i++){
        if(previous_char != s[i]){
            point += 1;
        }     
        previous_char = s[i];
    }

    cout << point << endl;

}

Measured memory_bytes: 512
#include <iostream>
#include <vector>

using namespace std;

int main()
{
	const int B_MAX = 100000;
	vector<long long> v(B_MAX + 1, 0);

	int N;
	long long K;
	cin >> N >> K;
	--K;

	for (int i = 0; i < N; ++i) {
		int a, b;
		cin >> a >> b;
		v[a] += b;
	}

	long long j = 0;
	for (int k = 0; k < v.size(); ++k) {
		if (j <= K && K < j + v[k]) {
			cout << k << endl;
			break;
		}
		j += v[k];
	}
}


Measured memory_bytes: 1152
#include<bits/stdc++.h>
#define st first
#define nd second
#define pb push_back
#define pf push_front
#define ppb pop_back
#define ppf pop_front
#define umax(x,y) x=max(x,y)
#define umin(x,y) x=min(x,y)
#define ll long long 
#define ii pair<int,int>
#define iii pair<ii,int>
#define iiii pair<ii,ii>
#define sz(x) ((int) x.size())
#define orta ((bas+son)/2)
#define all(x) x.begin(),x.end()
#define pw(x) (1<<(x))
#define inf 1000000000
#define MOD 1000000007 
#define N 200005
#define M 1000003
#define MAX 2000000
#define LOG 20
#define KOK 300
#define EPS 0.0000001
using namespace std;

int ans;
int psum[500005];
vector<int> pos[1<<20];

int mul(int x,int y) {
	
	return (ll)x*y%MOD;

}

int add(int x,int y) {

	x+=y;

	if(x>=MOD) x-=MOD;
	if(x<0) x+=MOD;

	return x;

}

void solve(int val,int n) {

	if(val) {

		pos[val].pb(n+1);

		int zero=(sz(pos[val])>1),non=0;

		if(!zero) return ;

		for(int i=0;i<sz(pos[val])-1;i++) {

			non=add(non,zero);

			int inside=psum[pos[val][i+1]-1]-psum[pos[val][i]];

			zero=add(zero,mul(inside,non));

		}

		pos[val].ppb();

		if(pos[val].back()==n) ans=add(ans,zero);
		else ans=add(ans,non);

	}
	else {

		int res=1;

		for(int i=0;i<sz(pos[val])-1;i++) res=add(res,res);

		ans=add(ans,res);

	}

}
	
int main() {

	int n;

	scanf("%d",&n);

	vector<int> pre(n+1,0);

	for(int i=1;i<=n;i++) {

		int x;

		scanf("%d",&x);

		pre[i]=pre[i-1]^x;

		psum[i]=psum[i-1]+(pre[i]==0);

		pos[pre[i]].pb(i);

	}

	if(pre[n]==0) {

		for(int i=0;i<(1<<20);i++) solve(i,n);

	}
	else {

		solve(pre[n],n);

	}

	printf("%d",ans);

} 

Measured memory_bytes: 64252
#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;
  cin >> n;
  vector<ll> h(n);
  rep(i,n) cin >> h.at(i);

  const ll INF = LLONG_MAX;

  ll dp[100010];

  rep(i,100010) dp[i] = INF;

  dp[0] = 0;
  dp[1] = abs(h.at(1) - h.at(0));

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

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

  return 0;
}

Measured memory_bytes: 1792
#include <cmath>
#include<iostream>
#include<algorithm>
#include<map>
#include<vector>
using namespace std;
typedef long long ll;
typedef pair<ll, ll> P;
ll inf = 1000000007;
int main() {
	int a, b;
	cin >> a >> b;
	cout << a * b << endl;
	return 0;
}



Measured memory_bytes: 3596
#include <bits/stdc++.h>
    
#define int long long
    
#define REP(i,n) for(int i=0;i<n;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 pb(x) push_back(x) 
#define SORT(x) sort((x).begin(),(x).end())
#define INF 99999999999
    
using namespace std;
    
int dy[4]={1, -1, 0, 0};
int dx[4]={0, 0, 1, -1};

int32_t main(){
    int n;
    cin >> n;
    vector<pair<int, int> > r(n), b(n);
    REP(i, n){
        int c, d;
        cin >> c >> d;
        r[i] = make_pair(c, d);
    }
    REP(i, n){
        int c, d;
        cin >> c >> d;
        b[i] = make_pair(c, d);
    }

    SORT(r); SORT(b);

    int cnt=0;
    set<int> s;
    REP(i, n){
        int m=-1, u;
        REP(j, n){
            if(r[j].first>b[i].first) break;
            if(b[i].second<=r[j].second) continue;
            if(m<r[j].second && s.find(j)==s.end()){
                m = r[j].second;
                u = j;
            }
        }
        if(m!=-1){
            cnt++;
            s.insert(u);
        }
    }

    cout << cnt << endl;
}

Measured memory_bytes: 256
#include <stdio.h>

int main(void){
  int x, y;

  while(1){
    scanf("%d%d", &x, &y);
    if(x == 0 && y == 0)  break;
    if(x < y){
      printf("%d %d\n", x, y);
    }else{
      printf("%d %d\n", y, x);
    }
  }
  return 0;
}

Measured memory_bytes: 600
N = int(input())
d = list(map(int,input().split()))
d = sorted(d)
chuou1 = d[N//2-1]
chuou2 = d[(N//2)]
if(chuou2 - chuou1 < 0):
  print("0")
else:
  print(str(chuou2 - chuou1))

Measured memory_bytes: 20684
import java.util.Scanner;

public class Main {

	public static void main(String[] args) {
		Scanner sc = new Scanner(System.in);
		String s = sc.nextLine();
		int n = Integer.parseInt(s);
		int fx = 0;
		for (String tmp : s.split("")) {
			fx += Integer.parseInt(tmp);
		}

		if (n % fx == 0) {
			System.out.println("Yes");
		} else {
			System.out.println("No");
		}

		sc.close();
	}
}

Measured memory_bytes: 21716
#include<iostream>
#include<cstdio>
#include<cmath>
#include<algorithm>
#include<string>
#include<vector>
#include<map>
#include<stack>
#include<queue>

using namespace std;

const int INF=1<<29;

int main(){
	vector<int> dp(1000001,INF);
	vector<int> odp(1000001,INF);
	dp[0]=0;
	odp[0]=0;
	
	int num=0;
	for(int i=1;num<1000001;i++){
		num=i*(i+1)*(i+2)/6;
		for(int j=num;j<1000001;j++){
			dp[j]=min(dp[j],dp[j-num]+1);
			if(num%2==1)
			odp[j]=min(odp[j],odp[j-num]+1);
		}
	}
	int n;
	while(1){
		scanf("%d",&n);
		if(n==0) break;
		printf("%d %d\n",dp[n],odp[n]);
	}
}


Measured memory_bytes: 10572
N,P=map(int,input().split())
if N==1:
    print(P)
    exit()
elif P==1:
    print(1)
    exit()

PO=P
K=[0]*(int(P**0.5)+1)

for i in range(2,int(P**0.5)):
    while P%i==0:
        K[i]+=1
        P=P//i
    K[i]=K[i]//N
    if P==1:
        break

ans=1
for i in range(2,int(PO**0.5)):
    if K[i]!=0:
        ans*=i**K[i]

print(ans)


Measured memory_bytes: 10868
#include<bits/stdc++.h>
#define _GLIBCXX_DEBUG
//repマクロ定義
#define rep(i,n) for (int i = 0; i < (int)(n); i++)
//allマクロ定義
#define all(v) v.begin(),v.end()
using namespace std;

int main(){
  int n,m,s=0;
  cin >> n >> m;
  int ans[m+1]={0};
  for(int i=0;i<n;i++){
    int k;
    cin >> k;
    for(int j=0;j<k;j++){
      int a;
      cin >> a;
      ans[a]+=1;
    }
  }

  for(int i=1;i<=m;i++){
    if(ans[i]==n) s++;
  }

  cout << s;
}

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

int main(){
	int H, W, K, i, j, k;
	scanf("%d%d%d", &H, &W, &K);
	vector<string> S(H);
	for(i = 0; i < H; i++){
		cin >> S[i];
	}
	int ans = H + W;
	for(int s = 0; s < (1 << (H - 1)); s++){
		vector<vector<int>> sec(1, vector<int>(1, 0));
		for(i = 1; i < H; i++){
			if((s | (1 << (i - 1))) == s){
				sec.push_back(vector<int>(1, i));
			}
			else{
				sec[sec.size() - 1].push_back(i);
			}
		}
		vector<vector<int>> l_count(sec.size(), vector<int>(W, 0));
		for(i = 0; i < sec.size(); i++){
			for(j = 0; j < sec[i].size(); j++){
				for(k = 0; k < W; k++){
					l_count[i][k] += S[sec[i][j]][k] - '0';
				}
			}
		}
		int f = 0;
		for(i = 0; i < sec.size(); i++){
			for(j = 0; j < W; j++){
				if(l_count[i][j] > K){
					f = 1;
				}
			}
		}
		if(f == 1){
			continue;
		}
		int res = sec.size() - 1;
		vector<int> now(sec.size(), 0);
		int last = 0;
		for(j = 0; j < W; j++){
			for(i = 0; i < sec.size(); i++){
				now[i] += l_count[i][j];
				if(now[i] > K){
					f = 1;
				}
			}
			if(f == 1){
				res++;
				for(i = 0; i < sec.size(); i++){
					now[i] = l_count[i][j];
				}
				f = 0;
			}
		}
		ans = min(ans, res);
	}
	printf("%d\n", ans);
	return 0;
}

Measured memory_bytes: 256
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
class Program
{
    static void Main(string[] args)
    {
            // 入力
            string[] sS = Console.ReadLine().Trim().Split(' ');
            int iH = int.Parse(sS[0]);
            int iW = int.Parse(sS[1]);
            List<List<string>> lstC = new List<List<string>>();
            for (int i = 0; i < iH; i++)
            {
                string s2 = Console.ReadLine().Trim();
                List<string> lstO = new List<string>();
                for (int j = 0; j < s2.Length; j++)
                {
                    lstO.Add(s2.Substring(j, 1));
                }
                lstC.Add(lstO);
            }

            System.Diagnostics.Stopwatch sw = new System.Diagnostics.Stopwatch();
            sw.Start();

            // 解析
            string sOut = "Yes";
            for (int i = 0; i < lstC.Count; i++)
            {
                for (int j = 0; j < lstC[i].Count; j++)
                {
                    int iCk = 0;
                    if (i - 0 >= 0 && j - 0 >= 0 && lstC[i - 0][j - 0] == "#")
                    {
                        if (i - 1 >= 0 && j - 0 >= 0) { if (lstC[i - 1][j - 0] == ".") { iCk += 1; } } else { iCk += 1; }   // ↑ 上
                        if (i - 0 >= 0 && j - 1 >= 0) { if (lstC[i - 0][j - 1] == ".") { iCk += 1; } } else { iCk += 1; }   // ← 左
                        if (i - 0 >= 0 && j + 1 < iW) { if (lstC[i - 0][j + 1] == ".") { iCk += 1; } } else { iCk += 1; }   // → 右
                        if (i + 1 < iH && j - 0 >= 0) { if (lstC[i + 1][j - 0] == ".") { iCk += 1; } } else { iCk += 1; }   // ↓ 下
                        if (iCk == 4) { sOut = "No"; break; }
                    }
                }
                if (sOut == "No") { break; }
            }

            // 出力
            Console.WriteLine("{0}", sOut.ToString().Trim());

            sw.Stop();
#if DEBUG
            Console.WriteLine();
            Console.WriteLine("{0}", sw.Elapsed.ToString());
            Console.WriteLine("続行するには何かキーを押してください．．．");
            Console.ReadKey();
#endif
    }

}


Measured memory_bytes: 11348
k,a,b = gets.chomp.split(' ').map(&:to_i)
if b - a <= 2 || a >= k
  puts k + 1
else
  if (k - a) % 2 == 0
    puts (((k - a)/2) - 1)*(b - a) + b + 1
  else
    puts (((k - a + 1)/2) - 1)*(b - a) + b 
  end
end


Measured memory_bytes: 14268
#include<bits/stdc++.h>
#define IOFAST ios::sync_with_stdio(false);cin.tie(0);cout.tie(0);
using namespace std;
#define ll long long
#define fo(i,n) for(int i=0;i<n;i++)
 
#define pb push_back  
 
 
int main(){
    int n;
    cin>>n;
    set<string>s;
    for(int i=0;i<n;i++){
        string x;
        cin>>x;
        s.insert(x);
    }
    cout<<s.size()<<endl;

}

Measured memory_bytes: 19264
#include <iostream>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <algorithm>
#include <iomanip>
#include <cassert>
using namespace std;

#define GET_ARG(a,b,c,F,...) F
#define REP3(i,s,e) for (i = s; i <= e; i++)
#define REP2(i,n) REP3 (i,0,(int)(n)-1)
#define REP(...) GET_ARG (__VA_ARGS__,REP3,REP2) (__VA_ARGS__)
#define RREP3(i,s,e) for (i = s; i >= e; i--)
#define RREP2(i,n) RREP3 (i,(int)(n)-1,0)
#define RREP(...) GET_ARG (__VA_ARGS__,RREP3,RREP2) (__VA_ARGS__)
#define DEBUG(x) cerr << #x ": " << x << endl

const int INF = 1e8;

int dp[301][301];
string s[300];
int cost[301][301];

int main(void) {
    int i, j, k, l, h, w;
    cin >> h >> w;
    REP (i,h) cin >> s[i];
    int ans = 0;
    REP (k,0,w-2) {
        REP (i,0,h) REP (j,0,h) {
            dp[i][j] = INF;
            cost[i][j] = 0;
        }
        dp[0][0] = 0;
        REP (i,0,h) REP (j,0,h) {
            if (i == 0) {
                REP (l,h-j) if (s[l+j][k] == s[l][k+1]) cost[i][j]++;
            }
            else if (j == 0) {
                REP (l,h-i) if (s[l][k] == s[l+i][k+1]) cost[i][j]++;
            }
            else if (i == h || j == h) {
                cost[i][j] = 0;
            }
            else {
                cost[i][j] = cost[i-1][j-1] - (s[h-i][k] == s[h-j][k+1]);
            }
            if (i < h) dp[i+1][j] = min(dp[i+1][j],dp[i][j] + cost[i][j]);
            if (j < h) dp[i][j+1] = min(dp[i][j+1],dp[i][j] + cost[i][j]);
        }
        ans += dp[h][h];
    }
    cout << ans << endl;
    return 0;
}


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

int main() {
  
  int A, B;
  cin >> A >> B;
  
  if (A<=8 && B<=8) {
    cout << "Yay!" << endl;
  }
  else{
    cout << ":(" << endl;
  }

return 0;
}

Measured memory_bytes: 3612
#include<bits/stdc++.h>
using namespace std;
const int N=3e5+1;
long long n,m,x,y,z,f[N],l=1,r=1,w,A[N],B[N],C[N],t;
int main()
{
    scanf("%lld %lld",&n,&m);
    t=n%m;
    x=m-t;
    printf("%lld\n",min(x,t));
}



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

typedef long long   ll;
typedef long double ld;
using namespace std;

int main() {
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);
    int n,m;
    cin >> n >> m;
    vector<bool> trf(n,false);
    vector<bool> trl(n,false);
    for(int i = 0; i < m; i++) {
        int ta,tb;
        cin >> ta >> tb;
        if(ta==1) trf[tb-1]=true;
        if(tb==n) trl[ta-1]=true;
    }
    bool jud=false;
    for(int i = 1; i < n-1; i++) {
        if(trf[i]*trl[i]) jud=true;
    }


    if(jud) cout << "POSSIBLE" << "\n";
    else    cout << "IMPOSSIBLE" << "\n";
    return 0;
}

Measured memory_bytes: 256
N, K = list(map(int,input().split()))
S = input()
 
n = 1
c = []
if S[0]=='0':
  c.append(0)
for i in range(1,N):
    if S[i]!=S[i-1]:
        c.append(n)
        n=1
    else:
        n+=1
c.append(n)
if S[-1]=='0':
  c.append(0)

# print(c)

t = sum(c[:2*K+1])
m = t
# print(t)
for i in range(2*K+1, len(c), 2):
  t += c[i] + c[i+1] - c[i-(2*K+1)] - c[i+1-(2*K+1)]
  # print(t)
  m = max(m,t)

print(m)

Measured memory_bytes: 4596
#! env python
# -*- coding: utf-8 -*-

import os
import sys

# ac_py.main
# Date: 2020/06/12
# Filename: main 
# Author: acto_mini

d = ["dreamer", "dream", "erase", "eraser"]


def find(s):
    while True:
        for term in d:
            if s.endswith(term):
                s = s[:-1 * len(term)]
                break
        else:
            print("NO")
            break
        if len(s) == 0:
            print("YES")
            break
    return


def main():
    find(input())
    return


if __name__ == '__main__':
    main()


Measured memory_bytes: 3316
from itertools import accumulate
import numpy as np

n, k = map(int, input().split())
A = list(map(int, input().split()))
C = [0] + list(accumulate(A))
D = []
for i in range(n):
  for j in range(i+1, n+1):
    D.append(C[j] - C[i])
    
D = np.array(D)
def enough(x):
  return np.count_nonzero(x&D == x) >= k

x = 0
for i in range(39, -1, -1):
  temp = x + 2**i
  if enough(temp):
    x = temp
    
print(x)

Measured memory_bytes: 36184
import sys
input = sys.stdin.readline
sys.setrecursionlimit(10**6)

N,Q = [int(i) for i in input().split()] #N個の頂点、Q回の操作
aaabbb = [[int(i) for i in input().split()] for j in range(N-1)] #木の辺
pppxxx = [[int(i) for i in input().split()] for j in range(Q)] #操作

tree = [[] for i in range(N+1)]

for a,b in aaabbb:
    tree[a].append(b)
    tree[b].append(a)

#print(tree)

counter = [0 for i in range(N+1)]

for p,x in pppxxx:
    counter[p] += x

#print(counter)

def dfs(pos,parent,add):
    counter[pos] += add
    for next_pos in tree[pos]:
        if not next_pos == parent:
            dfs(next_pos,pos,counter[pos])

dfs(1,0,0)

#print(counter)

print(" ".join([str(i) for i in counter[1:]]))


Measured memory_bytes: 285888
#include<bits/stdc++.h>
using namespace std;
#define Mod(n) n % 1000000007
const int dx[8] = {1, 0, -1, 0, -1, 1, -1, 1};
const int dy[8] = {0, 1, 0, -1, 1, -1, -1, 1};
int main()
{    
    int N,T;
    cin >> N >> T;
    int c = -1,t;
    int ans = 1 << 20;
    for(int i = 0;i < N;i++)
    {
        cin >> c >> t;
        if(t > T)
            continue;
        ans = min(ans,c);
    }
    if(ans == 1 << 20)
        cout << "TLE\n";
    else
        cout << ans << '\n';  
}



Measured memory_bytes: 256
#define _CRT_SECURE_NO_WARNINGS
#include"bits/stdc++.h"
#ifdef _DEBUG
#define DBG(n) n
#else
#define DBG(n)
#endif
#define INF         1e9
#define INFLL       1e18
#define EPS         1e-9
#define REP(i,n)    for(ll i=0,i##_len=(n);i<i##_len;++i)
#define REP1(i,n)   for(ll i=1,i##_len=(n);i<=i##_len;++i)
#define REPR(i,n)   for(ll i=(n)-1;i>=0;--i)
#define REPR1(i,n)  for(ll i=(n);i>0;--i)
#define REPC(i,obj) for(auto i:obj)
#define ALL(obj)    (obj).begin(),(obj).end()
#define SETP(n)     cout << fixed << setprecision(n)
using namespace std;
using ll = long long;
template<typename T = ll>inline T in() { T ret; cin >> ret; return ret; }

signed main() {
	int n = in(), m = in();
	vector<int>imos(n + 1);
	REP(i, m) {
		int c = in(), d = in();
		++imos[c];
		--imos[d];
	}
	REP(i, n)imos[i + 1] += imos[i];
	int len = 0;
	REP(i, n + 1)if (imos[i] != 0)++len;
	cout << n + len * 2 + 1 << endl;
}


Measured memory_bytes: 3100
use std::io::*;
use std::str::FromStr;

//https://qiita.com/tubo28/items/e6076e9040da57368845
fn read<T: FromStr>() -> T {
    let stdin = stdin();
    let stdin = stdin.lock();
    let token: String = stdin
        .bytes()
        .map(|c| c.expect("failed to read char") as char)
        .skip_while(|c| c.is_whitespace())
        .take_while(|c| !c.is_whitespace())
        .collect();
    token.parse().ok().expect("failed to parse token")
}

fn main() {
    let n: usize = read();
    let a: Vec<i64> = (0..n).map(|_| read()).collect();
    let b: Vec<i64> = (0..n).map(|_| read()).collect();

    //println!("{:?}",a);
    //println!("{:?}",b);

    let mut biggerA : i64 = 0;
    let mut biggerB : i64 = 0;
    for i in 0..n {
        if a[i] > b[i] {
            biggerA += a[i] - b[i];
        } else if a[i] < b[i] {
            biggerB += (b[i] - a[i]) / 2;
        }
    }

    if biggerB >= biggerA {
        println!("Yes");
    } else {
        println!("No");
    }
}


Measured memory_bytes: 2284
n = int(input())
a = list(map(int, input().split()))
a.sort()
flag = [True] * (a[-1] + 1)
memo = -1
for i in a:
    if memo == i:
        flag[i] = False
        continue
    memo = i
    tmp = 2 * i
    while tmp <= a[-1]:
        flag[tmp] = False
        tmp += i
ans = 0
for i in a:
    if flag[i]: ans += 1
print(ans)


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

int main(){
    int N,x;
    cin>>N>>x;
    
    vector<int> a(N);
    for(int i=0;i<N;i++) cin>>a[i];
    
    sort(a.begin(),a.end());
    
    int count=0;
    for(int i=0;i<N;i++){
        if(x-a[i]>=0){
            x-=a[i];
            count++;
        }else if(x-a[i]<0)break;
    }
    
    if(count>0){
        if(x==0)cout<<count<<endl;
        else if(count!=N)cout<<count<<endl;
        else cout<<count-1<<endl;
    }else{
        cout<<count<<endl;
    }
}

Measured memory_bytes: 256
S = str(input())

if S[0] == S[1]:
	if S[0] != S[2] and S[2] == S[3] :
		print('Yes')
	else:
		print('No')
else:
	if (S[0] == S[2] and S[1] == S[3]) or (S[0] == S[3] and S[1] == S[2]):
		print('Yes')
	else:
		print('No')

Measured memory_bytes: 3060
#include<bits/stdc++.h>
#define debug1 cout<<"?"<<endl;
#define debug2 cout<<"?"<<i<<endl;
#define PII pair<int,int>
typedef long long ll;
const int maxn=2e5+9;
const double pi=acos(-1);
const int mod=1e9+7;
const int INF=1e9;
const double ep=1e-7;
using namespace std;
int main()
{
	int n,k,i,j,r,s,p;
	int ans=0;
	char t[maxn],ss[maxn];
	scanf("%d%d%d%d%d%s",&n,&k,&r,&s,&p,t+1);
	for(i=1;i<=n;i++)
	{
		if(i<=k)
		{
			if(t[i]=='p')ss[i]='s',ans+=s;
			if(t[i]=='s')ss[i]='r',ans+=r;
			if(t[i]=='r')ss[i]='p',ans+=p;
		}
		else
		{
			if(t[i]=='r')
			{
				if(ss[i-k]!='p')ss[i]='p',ans+=p;
				else 
				{
					if(t[i+k]=='r')ss[i]='r';
					if(t[i+k]=='s')ss[i]='s';
					if(t[i+k]=='p')ss[i]='r';
				}
			}
			if(t[i]=='p')
			{
				if(ss[i-k]!='s')ss[i]='s',ans+=s;
				else 
				{
					if(t[i+k]=='r')ss[i]='r';
					if(t[i+k]=='s')ss[i]='p';
					if(t[i+k]=='p')ss[i]='p';
				}
			}
			if(t[i]=='s')
			{
				if(ss[i-k]!='r')ss[i]='r',ans+=r;
				else 
				{
					if(t[i+k]=='r')ss[i]='s';
					if(t[i+k]=='s')ss[i]='s';
					if(t[i+k]=='p')ss[i]='p';
				}
			}
		}
	}
	printf("%d\n",ans);
}

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

int main()
{
int A;
int B;
int C;

	ios::sync_with_stdio( false );
	cin.tie( 0 );

	cin >> A;
	cin >> B;
	cin >> C;

	if( A < C && C < B )
		cout << "Yes" << endl;
	else if( A > C && C > B )
		cout << "Yes" << endl;
	else
		cout << "No" << endl;

	return 0;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
#define int long long
using namespace std;
const int MOD = 1000000007; 

signed main() {
  int N, K;
  cin >> N >> K;
  
  vector<int> A(N);
  for( int i = 0; i < N; i++ ){
    cin >> A.at(i);
  }
  
  int ichi = 0; //Aの中の転倒数
  for( int i = 0; i < N; i++ ){
    for( int j = i+1; j < N; j++ ){
      if( A.at(i) > A.at(j) ) ichi++;
    }
  }
  
  
  int aida = 0; //AとAの間の転倒数
  for( int i = 0; i < N; i++ ){
    for( int j = 0; j < N; j++ ){
      if( A.at(i) > A.at(j) ) aida++;
    }
  }
  
  int ans = ( (ichi*K % MOD) + (aida*((K*(K-1))/2 % MOD)) )% MOD;
  cout << ans << endl;
      
  
}




Measured memory_bytes: 256
#include <cstdio>
#include <algorithm>
using namespace std;
int N, M, a, b, c, s, bit, d[19][19], dp[32777];
int main() {
	scanf("%d%d", &N, &M);
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			d[i][j] = (i == j ? 0 : 1 << 29);
		}
	}
	for (int i = 0; i < M; i++) {
		scanf("%d%d%d", &a, &b, &c);
		bit ^= (1 << a) ^ (1 << b);
		d[a][b] = min(d[a][b], c);
		d[b][a] = min(d[b][a], c);
		s += c;
	}
	for (int i = 0; i < N; i++) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < N; k++) {
				d[j][k] = min(d[j][k], d[j][i] + d[i][k]);
			}
		}
	}
	fill(dp, dp + (1 << N), 1 << 30); dp[bit] = s;
	for (int i = bit - 1; i >= 0; i--) {
		for (int j = 0; j < N; j++) {
			for (int k = 0; k < j; k++) {
				if (!((i >> j) & 1) && !((i >> k) & 1)) {
					dp[i] = min(dp[i], dp[i + (1 << j) + (1 << k)] + d[j][k]);
				}
			}
		}
	}
	printf("%d\n", dp[0]);
	return 0;
}


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

int main() {
  int A, B, C;
  cin >> A >> B >> C;
  
  if (A >= C) {
    cout << "delicious" << endl;
  } else if (A + B >= C) {
    cout << "safe" << endl;
  } else {
    cout << "dangerous" << endl;
  }
}

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

    int main (){
        int a,b;
        cin >> a >> b;
        int ten=b;
        int cnt=1;
        while(ten/10>0){
            ten=ten/10;
            cnt++;
        }
        int ans = a;
    rep(i,cnt){
        ans*=10;
    }
    ans+=b;
    int cnt2=ans/2;
    rep(i,cnt2){
        if(i*i==ans){
            cout << "Yes" << endl;
            break;
        }
        if(i+1==cnt2){
            cout << "No" << endl;
            break;
        }

    }

    return 0;
    }

Measured memory_bytes: 3596
N = int(input())
lst = [int(input()) for _ in range(N)]

cnt = 0
idx = 0

while True :
    x = lst[idx]
    cnt += 1
    if x == 2:
        print(cnt)
        exit()
    idx = x - 1
    if cnt > N:
        print(-1)
        exit()

Measured memory_bytes: 7084
#include<iostream>
#include<string>
#include<cstring>
using namespace std;
int main()
{	
	char test1[10007];
	while(cin>>test1){
		int num1=0,num2=0,num3=0;
		num1=strlen(test1);
		for(int i=0;i<num1-2;i++){
			if(test1[i]=='J'&&test1[i+1]=='O'&&test1[i+2]=='I'){
				num2=num2+1;
			}
			if(test1[i]=='I'&&test1[i+1]=='O'&&test1[i+2]=='I'){
				num3=num3+1;
			}
		}
		cout<<num2;
		cout<<"\n";
		cout<<num3;
		cout<<"\n";
		num2=0;
		num3=0;
	}
	return 0;
}

Measured memory_bytes: 1148
#include <bits/stdc++.h>
using namespace std;
int main(){
	while(1){
	int h,w,i,j;
	cin>>h>>w;
	if(h==0&&w==0) return 0;
	for(i=0;i<h;i++){
		if(i%2==0){
			for(j=0;j<w;j++){
				cout<<"#";
				j++;
				if(j==w) break;
				cout<<".";
			}
			cout<<"\n";
		}
		else{
			for(j=0;j<w;j++){
				cout<<".";
				j++;
				if(j==w) break;
				cout<<"#";
			}
			cout<<"\n";
		}
	}
	cout<<"\n";
	}
	return 0;
}

Measured memory_bytes: 3060
#include <bits/stdc++.h>
#define REP(i, n) for (ll i = 0; i < (ll)(n); i++)
#define REPD(i, n) for (ll i = n - 1; i >= 0; i--)
#define FOR(i, a, b) for (ll i = a; i <= (ll)(b); i++)
#define FORD(i, a, b) for (ll i = a; i >= (ll)(b); i--)
#define ALL(x) (x).begin(), (x).end()
#define SIZE(x) ((ll)(x).size())
#define MAX(x) *max_element(ALL(x))
#define MIN(x) *min_element(ALL(x))
#define PI 3.14159265358979323846264338327950L
using namespace std;
typedef long long ll;
typedef long double ld;

const ll INF = 1LL << 60;

int main()
{
  ll x, y;
  cin >> x >> y;

  FOR(i, 0, x)
  {
    ll j = x - i;
    if (2 * i + 4 * j == y)
    {
      cout << "Yes" << endl;
      return 0;
    }
  }

  cout << "No" << endl;
  return 0;
}

Measured memory_bytes: 3628
#include "bits/stdc++.h"
 
typedef long long ll;
#define int ll
#define fi first
#define se second
#define SORT(a) sort(a.begin(),a.end())
#define rep(i,n) for(int i = 0;i < (n) ; i++) 
#define REP(i,n) for(int i = 0;i < (n) ; i++) 
#define MP(a,b) make_pair(a,b)
#define pb(a) push_back(a)
#define INF LLONG_MAX/2
#define all(x) (x).begin(),(x).end()
#define debug(x) cerr<<#x<<": "<<x<<endl
#define debug_vec(v) cerr<<#v<<":";rep(i,v.size())cerr<<" "<<v[i];cerr<<endl
using namespace std;
int MOD = 998244353;
int n;

signed main(){
    cin >> n;
    int ans = 0;
    //vector<int> ret;
    for(int i = 1;i*i <= n;i++){
        if(n%i == 0){
            int a = n/i;
            int m = i-1;
            if(i != 1 && n/m == n%m)ans += m;
            
            if(i*i!=n){
                int m = n/i-1;
                int a = n/(m+1);
                if(n/m == n%m)ans += m;
            }
        }
    }
    cout << ans << endl;
    
    
    return 0; 
}

// g++ -std=c++14 code1.cpp
// rm -r -f test;oj dl https://cf17-final-open.contest.atcoder.jp/tasks/cf17_final_a
// rm -r -f test;oj dl http://diverta2019.contest.atcoder.jp/tasks/diverta2019_a

Measured memory_bytes: 256
N = int(input())
A = [int(x) for x in input().split()]
B = [int(x) for x in input().split()]
C = [int(x) for x in input().split()]

A = sorted(A)
B = sorted(B)
C = sorted(C)

BB = [0] * N

cidx = 0
for i in range(N):
    while cidx < N and C[cidx] <= B[i]:
        cidx += 1
    BB[i] = N - cidx

BBB = [0] * N
for i in range(N - 1, -1, -1):
    if (i == N - 1):
        BBB[i] = BB[i]
    else:
        BBB[i] = BB[i] + BBB[i+1]

sum = 0
bidx = 0
for i in range(N):
    while bidx < N and B[bidx] <= A[i]:
        bidx += 1
    if bidx != N:
        sum += BBB[bidx]

print(sum)


Measured memory_bytes: 27400