akhauriyash/Code-Regression huggingface dataset:
#include<stdio.h>
#include <iomanip>
#include <iostream>
#include<string>
#include<vector>
#include<map>
#include<queue>
#include<algorithm>
#include <random>
#include <chrono>

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

using namespace std;
int main() {
	int ans = 0, a, b,tmp=1;
	cin >> a >> b;


	 while (tmp < b){
		tmp--;
		tmp +=a;
		ans++;
	}
	cout << ans;
}

Measured memory_bytes: 760
#include "bits/stdc++.h"
#define YESNO OUT(three(solve(),"YES","NO"))
#define YesNo OUT(three(solve(),"Yes","No"))
#define WL(A,B) OUT(three(solve(),A,B))
#define ECHO OUT(solve())
#define three(A,B,C) ((A)?(B):(C))
#define FOR(i,a,b)  for(LL i=(a);i< (LL)(b);i++)
#define EFOR(i,a,b) for(LL i=(a);i<=(LL)(b);i++)
#define RFOR(i,a,b) for(LL i=(b);i>=(LL)(a);i--)
#define REP(i,b) FOR(i,zero,b)
#define rep REP
#define EREP(i,b) EFOR(i,zero,b)
#define RREP(i,b) RFOR(i,b,zero)
#define ALL(c) c.begin(),c.end()
#define UNIQUE(c) sort(ALL(c));c.erase(unique(ALL(c)),c.end())
#define MAX(c) (*max_element(ALL(c)))
#define MIN(c) (*min_element(ALL(c)))
#define MP make_pair
#define FI first
#define SE second
#define SI(x) (LL(x.size()))
#define PB push_back
#define DEBUG(a) OUT(a)
#define DEBUG2(a,b) OUT2(a,b)
#define cat cout << __LINE__ << endl
#define OUT(a) cout << (a) << endl
#define OUT2(a,b) cout << (a) <<" "<<(b) << endl
#define zero 0LL
#define all ALL
#define pb emplace_back
#define eb pb
#define int long long
using namespace std;
template<typename T> inline void maximize(T &a, T b) { a = max(a, b); }
template<typename T> inline void minimize(T &a, T b) { a = min(a, b); }
template<typename T> inline bool middle(T a, T b, T c) { return b <= a && a <= c; }
template<class T> inline bool MX(T &l, const T &r) { return l < r ? l = r, 1 : 0; }
template<class T> inline bool MN(T &l, const T &r) { return l > r ? l = r, 1 : 0; }
template<class T> inline bool chmax(int a, int b, T c, T d) { return c > d ? a : b; }
template<class T> inline bool chmin(int a, int b, T c, T d) { return c > d ? a : b; }
typedef int LL;
typedef double ld;
typedef int ut;
typedef vector<ut> VI;
typedef vector<VI> VII;
typedef pair<ut, ut> pr;
typedef pair<ut, pr> ppr;
typedef vector<pr> Vpr;
typedef vector<ppr> Vppr;
typedef tuple<int, int, int, int> tapu;
typedef vector<tapu> Vtapu;
typedef priority_queue<ut, VI, greater<LL> > PQ;
inline void outputVI(VI x) { REP(i, SI(x)) { cout << three(i, " ", "") << x[i]; }OUT(""); }
const int SIZE1 = 1e6 + 1000;
const int SIZE2 = 2010;
const int SIZE3 = 430;
const int SIZE = SIZE1;
const int MAPSIZE = 40;
const LL p = 7 + 1e9;
const LL INF = 1LL << 30;
const long double EPS = 1e-7;
const LL inf = 1000000000;
typedef pair<ld, ut> pld;
ut N, M, K, L, Q,  H, W, R;
VI edges[SIZE];
LL vals[SIZE], answer = zero;
LL maps[SIZE2][SIZE2];
LL A[SIZE],B[SIZE],C[SIZE],D[SIZE],E[SIZE];
LL solve() {
	REP(i, 3) {
		LL a, b;
		cin >> a >> b;
		A[a]++;
		A[b]++;
	}
	LL ans = 0;
	EFOR(i, 1, 4) if (A[i] % 2)ans++;
	return ans<=2;
}




//!!!!!!!!!!!!!!!!!!!実装を詰める!!!!!!!!!!!!!!!!!!!!!!!!!
signed main() {

	ios_base::sync_with_stdio(false);
	cout << fixed << setprecision(0);
//	solve();
	YESNO;
	//cin >> N;
	return 0;

}

Measured memory_bytes: 26496
#include <stdio.h>

int main(){
    int n;

    scanf("%d", &n);

    int m;
    m = n%10;
    if(m == 2 || m == 4 || m == 5 || m == 7 || m == 9){
        printf("hon");
    }else if(m == 0 || m == 1 || m == 6 || m == 8){
        printf("pon");
    }else{
        printf("bon");
    }
    }

Measured memory_bytes: 1732
s=input()
if s[0]!='A':
  print('WA')
  exit()
if not (s[2:-1].count('C')==1):
  print('WA')
  exit()
s=s.replace('A','')
s=s.replace('C','')
if not s.islower():
  print('WA')
  exit()
print('AC')

Measured memory_bytes: 3188
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStreamReader;
import java.util.Arrays;

import static java.lang.System.in;

public class Main {
    public static void main(String[] args) throws IOException {
        BufferedReader reader = new BufferedReader(new InputStreamReader(in));
        String[] inputs = reader.readLine().split(" ");
        int A = Integer.parseInt(inputs[0]);
        int B = Integer.parseInt(inputs[1]);
        int C = Integer.parseInt(inputs[2]);
        String answer = "NO";

        for (int i = 1; i < B; i++) {
            if( (A*i)%B == C) {
                answer="YES";
                break;
            }
        }
        System.out.println(answer);

    }
}


Measured memory_bytes: 21332
n,m = gets.split.map &:to_i
as = gets.split.map &:to_i
as_h = as.map{ |x| x / 2}

r_lcm = as_h.inject(:lcm)

if as_h.count{ |x| (r_lcm / x) % 2 == 0} > 0 then
	puts 0
else
	puts m / r_lcm - m / (r_lcm * 2)
end

Measured memory_bytes: 13444
#include <bits/stdc++.h>
using namespace std;
using ll = long long;
using pii = pair<int, int>;

int N;

int main() {
  cin.tie(0);
  ios_base::sync_with_stdio(false);
  cout << fixed << setprecision(10);
  
  cin >> N;
  vector<int> p;
  for (int i = 11; p.size() < N; i += 5) {
    int no = 0;
    for (int j = 2; j * j <= i; j++) {
      if (i % j == 0) no = 1;
    }
    if (!no) p.emplace_back(i);
  }  
  for (int i = 0; i < N; i++) {
    cout << p[i] << " \n"[i + 1 == N];
  }

  return 0;
}

Measured memory_bytes: 256
#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, r;
	cin >> n >> r;
	cout << r + 100 * max(0, 10 - n) << endl;
}


Measured memory_bytes: 256
#include<iostream>
#include<algorithm>
#include<queue>
#include<vector>
#include<map>
#include<cmath>
#include<queue>
using namespace std;
typedef pair< double , int > P;
typedef pair< int , P > Pii;
#define reps(i,b,n) for(int i = b ; i < n ; ++i )
#define rep(i,n) reps(i,0,n)
#define INF 10000000
#define fr first
#define sc second
#define EPS (1e-10)
double getdis(int x1,int y1,int x2,int y2){return sqrt((x2-x1)*(x2-x1)+(y2-y1)*(y2-y1));}

int n,s,g;
double d[5001],dis;
int prev[5001];
struct edge{
  int to;
  double cost;
  edge(){}
  edge(int to,double cost):to(to),cost(cost){};
};
vector< vector< edge > > info;
vector<int> dijkstra(){
  vector<int> ans;
  fill_n(d,5001,INF),fill_n(prev,5001,-1);
  priority_queue<P,vector<P>,greater<P> > que;
  que.push(P(0.0,s));
  d[s] = 0.0;
  while(!que.empty()){
    P p = que.top();
    que.pop();
    double dis = p.fr;
    int now = p.sc;
    if(dis > d[now]) continue;
    if(now == g){
      ans.push_back(g);
      int furuwara = g, hayashiya;
      while(furuwara != s){
        furuwara = prev[furuwara];
        ans.push_back(furuwara);
      }
      break;
    }
    rep(i,info[now].size()){
      edge e = info[now][i];
      if(d[now] + e.cost < d[e.to]){
        d[e.to] = d[now] + e.cost;
        que.push(P(d[e.to],e.to));
        prev[e.to] = now;
      }
    }
  }
  return ans;
}
int main(){
  while(cin >> n , n){
    int id[n],x[n],y[n],m;
    rep(i,n) cin >> id[i] >> x[i] >> y[i];
    info.resize(n + 1);
    rep(i,n) rep(j,n){
      if((dis = getdis(x[i],y[i],x[j],y[j])) <= 50.0){
        info[id[i]].push_back(edge(id[j],dis));
      }
    }
    cin >> m;
    while(m--){
      cin >> s >> g;
      vector<int> ans = dijkstra();
      if(ans.empty()) cout << "NA";
      else rep(i,ans.size()) cout << ( i ? " " : "" ) << ans[ans.size()-1-i];
      cout << endl;
    }
    info.clear();
  }
}

Measured memory_bytes: 1292
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
#define TEST int t;cin>>t;for(int T=1;T<=t;T++)
#define F first
#define S second
int main(){
  
  string s1,s2;
  cin>>s1>>s2;
  int l=s1.size();
  int a=0,b=0;
  for(int i=0;i<l;i++){
    if(s1[i]!=s2[i])
      a++;
  }
  cout<<a<<endl;
}


Measured memory_bytes: 3908
#include <bits/stdc++.h>
 
using namespace std;
 
typedef unsigned long long ull;
typedef long long ll;

int main() {
    ios::sync_with_stdio(0);
    cin.tie(0);
    
    int n, k;
    cin >> n >> k;

    bool hasSnack[n];
    fill(hasSnack, hasSnack + n, false);
    
    for (int i = 0; i < k; i++) {
    	int d;
    	cin >> d;
    	for (int j = 0; j < d; j++) {
    		int snuke;
    		cin >> snuke;
    		snuke--;
    		hasSnack[snuke] = true;
    	}
    }

    int ret = 0;
    for (int i = 0; i < n; i++) {
    	if (!hasSnack[i]) ret++;
    }

    cout << ret << endl;

    return 0; 
} 


Measured memory_bytes: 3620
s = list(input())
total = []
n = len(s)

def search(i,s):
	if i == n-1:
		li = []
		s = "".join(s)
		li = list(map(int,s.split("+")))
		total.append(sum(li))
		return

	else:
		search(i+1,s)

		_s = s[:-(n-i)+1] + ["+"] + s[-(n-i)+1:]
		search(i+1,_s)

search(0,s)
print(sum(total))

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

lint gcd(lint x, lint y) {
  if(x == 0) { return y; }
  else { return gcd(y%x,x); }
}

lint lcm(lint x, lint y) { return x/gcd(x,y)*y; }

lint C(lint n, lint k) {
  if(n == k) { return 1; }
  else if(n < k) { return 0; }
  else if(k == 0) { return 1; }
  else if(k == 1) { return n; }
  else return C(n-1,k-1) + C(n-1,k);
}

lint P(lint n, lint k) {
  if(k == 1) { return n; }
  return (n*(P(n-1,k-1)%1000000007)%1000000007);
}


int main() {
  lint n,m; cin >> n >> m;
  priority_queue<lint> pq;

  for(lint i=0;i<n;i++) {
    lint a; cin >> a;
    pq.push(a);
  } // init priority queue

  for(lint i=0;i<m;i++) {
    lint a=pq.top();
    pq.pop();
    pq.push(a/2);
  }

  lint ans=0;
  for(lint i=0;i<n;i++) {
    ans += pq.top();
    pq.pop();
  }

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


Measured memory_bytes: 4328
m,d = gets.chomp.split(" ").map(&:to_i)

cnt = 0

for i in 4..m do
    for j in 2..[i-1,9].min do 
        if i % j == 0
            d10 = i/j
            if (d10 * 10 + j) <= d 
                cnt += 1
            end
        end
    end
end

p cnt

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


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>


int main() {
	ll n, k;
	cin >> n >> k;
	ll ans = 0;
	REP(i, n) {
		ll a;
		cin >> a;
		if (a >= k)ans++;
	}
	cout << ans << endl;
}


Measured memory_bytes: 256
# -*- coding: utf-8 -*-

# AtCoder Beginner Contest
# Problem B

if __name__ == '__main__':
    width, a, b = list(map(int, input().split()))

    if (a + width) < b:
        print(min(b - (a + width), b - a))
    elif a <= b <= (a + width):
        print(0)
    else:
        print(min(a - b, a - (b + width)))


Measured memory_bytes: 3060
#include <iostream>
#include <string>
#include <cstring>
#include <cstdio>
#include <cstdlib>
#include <vector>
#include <algorithm>
#include <map>
#include <sstream>
#include <queue>
#include <deque>
#include <set>
#include <stack>
#include <functional>
#include <utility>
#include <stdio.h>
#define ll long long
#define MP make_pair
#define PII pair<int, int>
#define PLL pair<ll, ll>
#define F first
#define S second
#define SHN 1e9
#define lSHN 1e18
using namespace std;
int n;
int d[100010];
vector<int> v;
void build()
{
	int t=1;
	while (t<=n)
	{
		v.push_back(t);
		t*=6;
	}
	t=9;
	while (t<=n)
	{
		v.push_back(t);
		t*=9;
	}
} 
int main()
{
	cin >>n;
	build();
	fill(d+1,d+n+1,1e9);
	for (int i=0;i<n;i++)
	{
		for (int j=0;j<v.size();j++)
		{
			int t=v[j]+i;
			if (t>n) continue;
			d[t]=min(d[t],d[i]+1);
		}
	} 
	cout <<d[n];
	return 0;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
using namespace std;
int a[10];
int main(){
	cin>>a[1]>>a[2]>>a[3];
	sort(a+1,a+4);
	if (a[1]==a[2]){
		if (a[1]!=a[3])cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
		return 0;
	}
	if (a[2]==a[3]){
		if (a[1]!=a[2])cout<<"Yes"<<endl;
		else cout<<"No"<<endl;
		return 0;
	}
	cout<<"No"<<endl;
	return 0;
}


Measured memory_bytes: 256
use std::str::FromStr;

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

fn get_vec<T : FromStr>() -> Vec<T> {
    let mut s = String::new();
    std::io::stdin().read_line(&mut s).ok();
    return s.trim().split_whitespace().map(|e| e.parse().ok().unwrap()).collect();
}

fn main() {
    let a : i32 = get_one();
    let b : i32 = get_one();
    let h : i32 = get_one();
    println!("{}", (a+b) * h / 2);
}


Measured memory_bytes: 4352
/*
[ ( ^ _ ^ ) ]
*/

// problem: atc/dp_t

// package atc.t;

import java.io.*;
import java.util.*;


public class Main {
    int INF = (int)1e9;
    long MOD = 1000000007;

    void solve(InputReader in, PrintWriter out) throws IOException {
        int n = in.nextInt();
        char[] s = (" "+in.next().trim()).toCharArray();
        char lt = '<';

        long[][] dp = new long[n][n];
        dp[0][0] = 1;
        
        for(int i=1; i<n; i++) {
            for(int j=0; j<=i; j++) {
                if(s[i]==lt) {
                    dp[i][j] = dp[i-1][i-1] - (j>0?dp[i-1][j-1]:0);
                    dp[i][j] = (dp[i][j]%MOD + MOD)%MOD;
                } else {
                    if(j>0) dp[i][j] = dp[i-1][j-1];
                }
                if(j>0) dp[i][j] = (dp[i][j] + dp[i][j-1])%MOD;
            }
            // show("", dp[i]);
        }
        out.println(dp[n-1][n-1]);
    }
    

    public static void main(String[] args) throws IOException {
        if(args.length>0 && args[0].equalsIgnoreCase("d")) {
            DEBUG_FLAG = true;
        }
        InputReader in = new InputReader();
        PrintWriter out = new PrintWriter(System.out);
        int t = 1;//in.nextInt();
        long start = System.nanoTime();
        while(t-- >0) {
            new Main().solve(in, out);
        }
        long end = System.nanoTime();
        debug("\nTime: " + (end-start)/1e6 + " \n\n");
        out.close();
    }
    
    static boolean DEBUG_FLAG = false;
    static void debug(String s) {
        if(DEBUG_FLAG) System.out.print(s);
    }
    
    public static void show(Object... o) {
        System.out.println(Arrays.deepToString(o));
    }
    
    static class InputReader {
        static BufferedReader br;
        static StringTokenizer st;
    
        public InputReader() {
            br = new BufferedReader(new InputStreamReader(System.in));
        }
        
        String next() {
            while (st == null || !st.hasMoreTokens()) {
                try {
                    st = new StringTokenizer(br.readLine());
                } catch (IOException e) {
                    e.printStackTrace();
                }
            }
            return st.nextToken();
        }
        
        int nextInt() {
            return Integer.parseInt(next());
        }
        
        long nextLong() {
            return Long.parseLong(next());
        }
        
        double nextDouble() {
            return Double.parseDouble(next());
        }
    }
}

Measured memory_bytes: 128084
import java.util.*;
import java.io.*;

public class Main {
 
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        int a = sc.nextInt();   
        int b = sc.nextInt();   
        String sa = "";
        String sb = "";
        for (int i = 0; i < b; i++) {
            sa += a; 
        }
        for (int i = 0; i < a; i++) {
            sb += b; 
        }
        String[] s = {sa, sb};
        Arrays.sort(s);
        System.out.println(s[0]);
    }
}

Measured memory_bytes: 23764
#![allow(non_snake_case)]
#![allow(unused_variables)]
#![allow(dead_code)]

fn main() {
    let (N, A, B): (usize, usize, usize) = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        let mut iter = line.split_whitespace();
        (
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap(),
            iter.next().unwrap().parse().unwrap()
        )
    };
    let S: Vec<char> = {
        let mut line: String = String::new();
        std::io::stdin().read_line(&mut line).unwrap();
        line.trim().chars().collect()
    };

    let mut c = 0;
    let mut d = 0;
    for &s in &S {
        if s == 'a' && c < A + B {
            c += 1;
            println!("Yes");
        } else if s == 'b' && c < A + B && d < B {
            c += 1;
            d += 1;
            println!("Yes")
        } else {
            println!("No")
        }
    }
}


Measured memory_bytes: 4732
#include <iostream>
#include <cstdio>
#include <cstring>
#include <vector>
#include <queue>
#include <array>
#include <set>
#include <unordered_set>
#include <unordered_map>
#include <cmath>
#include <algorithm>
#include <numeric>
#include <cassert>
#include <utility>
#include <functional>

using namespace std;
using lli = long long int;
using ll = long long;

struct Shop {
    lli price;
    lli amount;

    bool operator<(const Shop &another) const {
         return price < another.price;
    };
} ;


int main() {

    lli N, M;
    cin >> N >> M;

    vector<Shop> shops(N);
    for (int i = 0; i < N; ++i) {
        lli price;
        cin >> price;

        lli amount;
        cin >> amount;

        Shop shop;
        shop.price = price;
        shop.amount = amount;
        shops[i] = shop;
    }

    sort(shops.begin(), shops.end());

    int i = 0;
    lli answer = 0;
    do {
        Shop shop = shops[i];
        lli price = shop.price;
        lli amount = shop.amount;

        bool flag = false;
        for (int j = 0; j < amount; ++j) {
            answer += price;
            --M;

            if (M == 0) {
                break;
            }
        }
        ++i;

    } while (M > 0);

    cout << answer << endl;

    return 0;
}


Measured memory_bytes: 1792
#include <bits/stdc++.h>
#define ll long long int
#define inf 3e18+1
#define all(v) (v).begin(),(v).end() 
#define N 200005
#define F first 
#define S second 
using namespace std;
ll mod=1e9+7;
// ll parent[N];  
// ll size[N]; 
// ll find(ll i){
//     if(parent[i]!=i) {
//         parent[i]=find(parent[i]);
//     }
//     return parent[i];
// }
// void Union(ll x,ll y){
//     ll a=find(x);
//     ll b=find(y);
//     if(a==b) return;
//     parent[a]=parent[b];
// }
int main()
{
    // added the two lines below 
    ios_base::sync_with_stdio (false); 
    cin.tie(NULL);
    cout.tie(0);    
    ll test=1;//cin>>test;
    while(test--){
          int n,W;
  cin>>n>>W;
  std::vector<int> weight(n) ;
  vector<int> value(n);
  for(int i=0;i<n;i++){
      cin>>weight[i]>>value[i];
  }
  int max_val = 0;
  for(int i =0;i<n;i++){
      max_val+=value[i];
  }
  vector<vector<long long int> > op(n+1,vector<long long int>(max_val+1,INT_MAX));
  for(int i =0;i<op.size();i++){
      op[i][0] = 0;
  }
  for(int i =1;i<n+1;i++){
      for(int j = 1;j<max_val+1;j++){
          op[i][j] = op[i-1][j];
          if(value[i-1]<=j){
              op[i][j] = min(op[i][j],op[i-1][j-value[i-1]] + weight[i-1]);
          }
      }
  }
  int res =0;
  for(int j = 0;j<max_val+1;j++){
      if(op[n][j]<=W){
          res = j;
      }
  }
  std::cout << res << std::endl;

        
    }
    return 0;
    
}




Measured memory_bytes: 83048
n = int(input())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
c = list(map(int, input().split()))
ans = 0
for i in range(n-1):
    if a[i]+1 == a[i+1]:
        ans += b[a[i]-1]
        ans += c[a[i]-1]
    else:
        ans += b[a[i]-1]
    if i == n-2:
        ans += b[a[i+1]-1]
print(ans)

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

using namespace std;

#define REP(i,n) for(int (i)=0;(i)<(int)(n);(i)++)
#define REPO(i,n) for(int (i)=1; (i)<=(int)(n); (i)++)
#define SZ(v) ((int)(v).size())
#define ALL(v) (v).begin(),(v).end()
#define one first
#define two second
typedef long long ll;
typedef pair<int, int> pi;
const int INF = 0x3f2f1f0f;
const ll LINF = 1ll * INF * INF;

const int MAX_N = 5e3 + 10;

int N, K, Nr[MAX_N];
bool L[MAX_N][MAX_N], R[MAX_N][MAX_N];
int FastR[2][MAX_N][MAX_N], All[MAX_N];
int main() {
	cin >> N >> K;
	REPO(i, N) scanf("%d", &Nr[i]);
	L[0][0] = true;
	for(int i=1; i<=N; i++) {
		for(int k=0; k<=K; k++) L[i][k] = L[i-1][k];
		for(int k=0; k+Nr[i]<=K; k++)
			if(L[i-1][k]) L[i][k+Nr[i]] = true;
	}
	R[N+1][0] = true;
	for(int i=N; i>=1; i--) {
		for(int k=0; k<=K; k++) R[i][k] = R[i+1][k];
		for(int k=0; k+Nr[i]<=K; k++)
			if(R[i+1][k]) R[i][k+Nr[i]] = true;
	}

	for(int i=1; i<=N+1; i++) {
		FastR[0][i][0] = R[i][0];
		FastR[1][i][K] = R[i][K];
		for(int k=1; k<=K; k++) FastR[0][i][k] = FastR[0][i][k-1] + R[i][k];
		for(int k=K-1; k>=0; k--) FastR[1][i][k] = FastR[1][i][k+1] + R[i][k];
		for(int k=0; k<=K; k++) All[i] += R[i][k];
	}

	int ans = 0;
	for(int i=1; i<=N; i++) {
		bool find = false;
		for(int k=0; k<K; k++) if(L[i-1][k]) {
			//K-Nr[i]-k to K-k-1
			int l = K-Nr[i]-k-1, r = K-k;
			int ll = 0, rr = FastR[1][i+1][r];
			if(l >= 0) ll = FastR[0][i+1][l];
			int cnt = All[i+1] - ll - rr;
			if(cnt >= 1) {find = true; break;}
		}
		if(!find) ans++;
	}
	printf("%d\n", ans);
	return 0;
}

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

typedef long long ll;
typedef pair<int, int> ii;
typedef vector<int> vi;
typedef vector<ii> vii;

const int MAXN = 1e5+2;
int dp[MAXN], n, m;
vi G[MAXN];

int dfs(int x){
    if(dp[x] != -1) return dp[x];
    dp[x] = 0;
    for(auto k : G[x]){
        dp[x] = max(dp[x], 1 + dfs(k));
    }
    return dp[x];
}

int main(){

	#ifdef MaxWell
    	freopen(".in", "r", stdin);
        cout << "<<<------------ MaxWell defined ---------------->>>\n";
    #endif

    ios_base::sync_with_stdio(0);
    cin.tie(0); cout.tie(0);

    cin >> n >> m;
    int a, b;
    for(int i=0; i<m; i++){
        cin >> a >> b;
        G[a].push_back(b);
    }

    fill(dp, dp + n + 1, -1);

    int ans = 0;
    for(int i=1; i<=n; i++)
        ans = max(ans, dfs(i));

    cout << ans << '\n';

    return 0;
}

Measured memory_bytes: 7424
#include<iostream>
#include<cstring>
#include<queue>
using namespace std;

int main(){
    int h, w, k;
    cin >> h >> w >> k;
    char mat[h][w];
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cin >> mat[i][j];
        }
    }
    int num = 1;
    vector<bool> itigo(h, 0);
    int ans[h][w];
    memset(ans, 0, sizeof(ans));
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            if(mat[i][j] == '.')    continue;
            itigo[i] = true;
            ans[i][j] = num;
            int cj = j-1;
            while(cj >= 0 && mat[i][cj] == '.' && ans[i][cj] == 0)   ans[i][cj--] = num;
            cj = j+1;
            while(cj < w  && mat[i][cj] == '.' && ans[i][cj] == 0)   ans[i][cj++] = num;
            num++;
        }
    }
    queue<int> q;
    for(int i = 0; i < h; i++)  if(itigo[i])    q.push(i);
    while(!q.empty()){
        int i = q.front();  q.pop();
        if(i-1 >= 0 && !itigo[i-1]){
            itigo[i-1] = true;
            for(int j = 0; j < w; j++)  ans[i-1][j] = ans[i][j];
            q.push(i-1);
        }
        if(i+1 < h && !itigo[i+1]){
            itigo[i+1] = true;
            for(int j = 0; j < w; j++)  ans[i+1][j] = ans[i][j];
            q.push(i+1);
        }
    }
    for(int i = 0; i < h; i++){
        for(int j = 0; j < w; j++){
            cout << ans[i][j] << " \n"[j==w-1];
        }
    }
    return 0;
}

Measured memory_bytes: 1152
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
  int edge[3],n;
  cin >>n;
  while(n--){
    cin >>edge[0]>>edge[1]>>edge[2];
    sort(edge,edge+3);
    if(edge[2]*edge[2] == edge[1]*edge[1]+edge[0]*edge[0]){cout <<"YES"<<endl;}
    else{cout <<"NO"<<endl;}
  }
  return 0;
}

Measured memory_bytes: 0
#include<iostream>
#include<string>
#include<vector>
#include<utility>
#include<algorithm>
#include<map>
#include<cstdlib>
#include<cmath>
#include<numeric>
#include<iomanip>
using namespace std;
using ll =long long;
const int MOD = 1000000007;


int main() {
	ll N;
	vector<ll>A,B;
	cin >> N;
	ll cnt=0;
	ll c;
	for (int i = 0; i < N; i++) {
		cin >> c;
		A.push_back(i+1-c);
		B.push_back(c + i+1);
	}
	ll idx_lower, idx_upper;
	sort(A.begin(), A.end());
	sort(B.begin(), B.end());
	for (int i = 0; i <N; i++) {
		if (binary_search(B.begin(), B.end(), A[i])) {
			idx_upper = distance(B.begin(), upper_bound(B.begin(), B.end(), A[i]));
			idx_lower = distance(B.begin(), lower_bound(B.begin(), B.end(), A[i]));
			cnt +=idx_upper-idx_lower;
		}
	}
	cout << cnt;
}

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

#define rep(i,s,n) for (int i = (int)s; i < (int)n; i++)
#define ll long long
#define ld long double
#define pb push_back
#define eb emplace_back
#define All(x) x.begin(), x.end()
#define Range(x, i, j) x.begin() + i, x.begin() + j
#define lbidx(x, y) lower_bound(x.begin(), x.end(), y) - x.begin()
#define ubidx(x, y) upper_bound(x.begin(), x.end(), y) - x.begin()
#define llbidx(x, y, z) lower_bound(x.begin(), x.end(), z) - lower_bound(x.begin(), x.end(), y) // 二要素間の距離
#define deg2rad(deg) ((((double)deg)/((double)360)*2*M_PI))
#define rad2deg(rad) ((((double)rad)/(double)2/M_PI)*(double)360)
#define Find(set, element) set.find(element) != set.end()
#define Decimal(x) printf("%.10f\n", x) // 小数点を10桁まで表示
// debug用
#define PrintVec(x) for (auto elementPrintVec: x) { cout << elementPrintVec << " "; } cout << endl;
#define debug(x) cerr << #x << ": " << (x) << "\n";

typedef pair<int, int> PI;
typedef pair<ll, ll> PLL;
typedef vector<int> vi;
typedef vector<vector<int>> vvi;
typedef vector<vector<vector<int>>> vvvi;
typedef vector<ll> vl;
typedef vector<vector<ll>> vvl;
typedef vector<vector<vector<int>>> vvvl;
typedef vector<PI> vpi;
typedef vector<vector<PI>> vvpi;
typedef vector<vector<vector<PI>>> vvvpi;
typedef vector<PLL> vpl;
typedef vector<vector<PLL>> vvpl;
typedef vector<vector<vector<PLL>>> vvvpl;

int POWINT(int x, int n) {
  int ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

ll POWLL(ll x, int n) {
  ll ret = 1;
  rep(i, 0, n) ret *= x;
  return ret;
};

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

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

  vector<int> A(3);
  rep(i, 0, 3) {
    cin >> A[i];
  }

  sort(All(A));
  int ans = 1e9+7;
  do {
    ans = min(ans, abs(A[0] - A[1]) + abs(A[1] - A[2]));
  } while (next_permutation(All(A)));

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


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

X = list(map(int, input().split()))

dp = {}

for i in range(N):
    for j in range(min(X), max(X)+1):
        if j in dp:
            dp[j] += (X[i] - j)*(X[i] - j)
        else:
            dp[j] = (X[i] - j)*(X[i] - j)

print(min(dp.values()))



Measured memory_bytes: 39024
#include <bits/stdc++.h>
#define rep(i, a, n) for (int i = (int)(a); i <= (int)(n); ++i)
#define rrep(i, a, n) for (int i = (int)(a); i >= (int)(n); --i)
#define debug(x) cerr << #x << " = " << x << "\n"
#define debugv(x) \
  rep(f, 0, (x.size() - 1)) cerr << x[f] << (f == (x.size() - 1) ? "\n" : " ")
#define debug2(x, y)                       \
  cerr << "(" << #x << "," << #y << ") = " \
       << "(" << x << "," << y << ")\n"
#define all(x) x.begin(), x.end()
#define each(a, x) for (auto& a : (x))
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define int long long
#define yn(x) puts((x ? "Yes" : "No"))
using namespace std;
using pii = pair<int, int>;
using vi = vector<int>;
const int MX = 1e5 + 5, INF = 5LL << 57, MOD = 1e9 + 7;

int N, M;
int K;
string S;
vi va, vb;

void input() {
  ;
  cin >> N >> K;

  ;
}
void solve() {
  ;
  // x <- diff(x,K)
  // min : 0

  // Kikaninaru
  N = N % K;

  cout << min(N, ((K - N) % K)) << endl;

  ;
}
signed main() {
  cout << setprecision(12);
  input();
  solve();
  return 0;
}

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

using namespace std;

const ll MOD = 1000000007;

int main()
{
    int n,m;cin>>n>>m;
    vector<vector<bool> > a(n,vector<bool>(m));
    for(int i = 0 ;i < n ;i ++)
    {
        string s;cin>>s;
        for(int j = 0 ; j < m ; j++)
        {
            if(s[j] == '#')
                a[i][j] = 1;
        }
    }
    vector<vector<ll> > d(n,vector<ll> (m));
    d[0][0] = 1;
    for(int i = 0 ;i < n ; i++)
    {
        for(int j = 0 ;j  < m ; j++)
        {
            if(a[i][j])
                continue;
            if(i > 0)
            {
                d[i][j] += d[i - 1][j];
                d[i][j] %= MOD;
            }
            if(j > 0)
            {    
                d[i][j] += d[i][j - 1];
                d[i][j] %= MOD;
            }

        }
    }
    cout<<d[n - 1][m - 1]<<endl;

}

Measured memory_bytes: 8320
#include<stdio.h>
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<math.h>
using namespace std;
const int inf=1<<30;
int main(){
  int a,b,c,x,y;//a:A b:B c:AB
  cin>>a>>b>>c>>x>>y;
  int tmp;
  int ans=inf;
  //i ABを買う
  int A,B;
  for(int i=0;i<=2*max(x,y);i++){
    A=2*x-i;B=2*y-i;
    A=(A+1)/2;B=(B+1)/2;
    A=max(0,A);B=max(0,B);
    tmp=i*c+A*a+B*b;
    //printf("A:%d;B:%d;AB:%d;tmp:%d;\n",A,B,i,tmp);
    ans=min(ans,tmp);
  }
  cout<<ans<<endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <cmath>
#include <vector>
#define pb push_back
#define For(i,x,y) for(register int i=(x); i<=(y); i++)
using namespace std;
int n,m,q,ans;
int a[100],b[100],c[100],d[100];
vector<int>v;
void dfs(int idx)
{
    if(idx>n)
    {
        int now=0;
        For(i,1,q)if(v[b[i]]-v[a[i]]==c[i])now+=d[i];
        ans=max(ans,now);
        return ;
    }
    //cout<<v[idx-1];
    //cout<<idx-1<<endl;
    For(i,v[idx-1],m)
    {
        v.pb(i);
        dfs(idx+1);
        v.pop_back();
    }
}
int main()
{
    ios::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    cin>>n>>m>>q;
    v.pb(1);
    for(int i=1; i<=q; i++)cin>>a[i]>>b[i]>>c[i]>>d[i];
   // cout<<"ok"<<endl;
    dfs(1);
    cout<<ans<<endl;
    return 0;
}


Measured memory_bytes: 3608
#include <bits/stdc++.h>
using namespace std;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define rep_range(i, s, e) for (int i = (s); i < (int)(e); i++)
#define rep_rev(i, s, e) for (int i = (s)-1; i >= (int)(e); i--)
#define sort_vec(v) sort((v).begin(),(v).end())
typedef int64_t lint;
// lint mod = 998244353;
template< typename T1, typename T2 >
inline bool chmax(T1 &a, T2 b) { return a < b && (a = b, true); }
template< typename T1, typename T2 >
inline bool chmin(T1 &a, T2 b) { return a > b && (a = b, true); }

string app() {
  string s;
  cin>>s;

  return (s=="ABC")?"ARC":"ABC";
}

int main(){cout<<app()<<endl;return 0;}


Measured memory_bytes: 3588
count = [0] * 101
while(True):
    try:
        s = input()
        count[s] += 1
    except Exception:
        break   
maxCount = 0
for i in range(len(count)):
    if(maxCount < count[i]):
        maxCount = count[i]
for i in range(len(count)):
    if(maxCount == count[i]):
        print(i)

Measured memory_bytes: 4204
#include<iostream>
#include <algorithm>
#include <vector>
#include <string>
using namespace std;
typedef long long ll;
typedef pair<int, int> P;
int main(){

  int N, M;
  cin >> N >> M;
  int Lmax = 0;
  int Rmin = N;
  for(int i=0;i<M;i++){
    int L, R;
    cin >> L >> R;
    Lmax = max(Lmax, L);
    Rmin = min(Rmin, R);
  }

  int ans;
  if(Lmax<=Rmin){
    ans = Rmin - Lmax +1;
  }else{
    ans = 0;
  }
  cout << ans <<endl;
  
  return 0;
}

Measured memory_bytes: 256
from sys import stdin,stdout
def INPUT():return list(int(i) for i in stdin.readline().split())
import math
def inp():return stdin.readline()
def out(x):return stdout.write(x)
import math as M
MOD=10**9+7
import random
#####################################
k=int(input())
A=[1]*(10**6+1)
A[0]=7%k
for i in range(1,10**6+1):
    A[i]=(A[i-1]*10)%k
ind=1
sum=A[0]
while(sum!=0 and ind<=10**6):
    if (A[ind]+sum)%k==0:
        ans=ind
        break
    sum=(sum+A[ind])%k
    ind+=1
if k==1 or k==7:
    print(1)
elif ind==10**6+1:
    print(-1)
else:
    print(ans+1)


Measured memory_bytes: 84764
#include <stdio.h>
#include <iostream>
#include <iomanip>
#include <algorithm>
#include <sstream>
#include <complex>
#include <vector>
#include <list>
#include <queue>
#include <deque>
#include <stack>
#include <set>
#include <map>
#include <cstdio>
#include <string>
#include <cstdlib>
#include <cstring>
#include <bits/stdc++.h>

using namespace std;
typedef long long ll;
const long double EPS = 1e-9;
const ll mod = 1e9 + 7;
const ll INF = 1e9;

#define rep(i, n) for(ll i = 0; i < n ; i++ )
#define For(i, a, b) for(ll i = (a); i < (b) ; i++ )
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()

const ll MAX_N = 100;

ll height(ll x, ll y, ll Cx, ll Cy, ll H){
    return max(ll(0), H - abs(x - Cx) - abs(y - Cy));
}

int main(void){
    ll N;
    ll Hl, Hr;
    Hl = 0;
    Hr = 1e9 + 300;
    ll Cx, Cy, H;
    ll xs[MAX_N], ys[MAX_N], hs[MAX_N];

    cin >> N;

    rep(i, N) cin >> xs[i] >> ys[i] >> hs[i];

    H = 1e9 + 300;
    bool found = false;
    rep(cx, 101){
        rep(cy, 101){
            ll h_diff = 0;
            ll cnt = 0;
            rep(i, N){
                ll hd = height(xs[i], ys[i], cx, cy, H) - hs[i];
                if (h_diff == 0 && hs[i] != 0) {h_diff = hd; Cx = xs[i]; Cy = ys[i];}
                else if (hs[i] != 0 && hd != h_diff) {found = false; break;}
                if (h_diff == hd && hs[i] != 0) cnt ++;
                if (i == N - 1 && cnt > 1) found = true;
            }
            if (found) {Cx = cx; Cy = cy; break;}
        }
        if (found) break;
    }

    while(Hr >= Hl){
        H = Hl + (Hr - Hl) / 2;
        ll err = 0;

        rep(i, N){
            ll h_diff = hs[i] - height(xs[i], ys[i], Cx, Cy, H);
            err += abs(h_diff);
            if (h_diff > 0) {Hl = H + 1; break;}
            else if (h_diff < 0) {Hr = H - 1; break;}
        }

        if (err == 0) break; 
    }

    cout << Cx << " " << Cy << " " << H << endl;

    return 0;
}


Measured memory_bytes: 256
s = list(input()) #sys.stdin.readlineは最後が改行

def mergecount(A):
    cnt = 0
    n = len(A)
    if n>1:
        A1 = A[:n>>1]
        A2 = A[n>>1:]
        cnt += mergecount(A1)
        cnt += mergecount(A2)
        i1=0
        i2=0
        for i in range(n):
            if i2 == len(A2):
                A[i] = A1[i1]
                i1 += 1
            elif i1 == len(A1):
                A[i] = A2[i2]
                i2 += 1
            elif A1[i1] <= A2[i2]:
                A[i] = A1[i1]
                i1 += 1
            else:
                A[i] = A2[i2]
                i2 += 1
                cnt += n//2 - i1
    return cnt

ans=0
ss = []
i=0
finish_calc = 0
while i<len(s):
    if s[i]=='A':
        ss.append(1)
        i+=1
        finish_calc=0
    elif i+1<len(s):
        if s[i]=='B' and s[i+1]=='C':
            ss.append(0)
            finish_calc=0
            i+=2
            continue
        if finish_calc==0:
            ans += mergecount(ss)
            ss=[]
            i+=1
            finish_calc=1
        else:
            i+=1
    elif finish_calc==0:
        ans += mergecount(ss)
        ss=[]
        i+=1
        finish_calc=1
    else:
        i+=1

if finish_calc==0:
    ans += mergecount(ss)

print(ans)



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

int main()
{
  long long A, B, C, K;
  cin >> A >> B >> C >> K;
  long long ans = 0;
  if (A >= K)
  {
    ans += K;
  }
  else
  {
    ans += A;
    K -= A;
    if (B < K)
    {
      K -= B;
      ans -= K;
    }
  }
  cout << ans << endl;
}



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

void print(vector<int>l)
{
    for(int o = 0; o < l.size(); o++)
    {
        cout << l[o] << " ";
    }
    cout << endl;
}
int main()
{
    int N, K;
    cin >> K >> N;
    vector<int>houses(N);

    for(int i = 0; i < N; i++) cin >> houses[i];

    vector<int>diff(N);
    for(int i = 0; i < N - 1; i++)
    {
        diff[i] = houses[i+1] - houses[i];
    }
    diff[N-1] = K - houses[N-1] + houses[0];

    long long max = LONG_LONG_MIN;
    long long total = 0;
    for(int i = 0; i < diff.size(); i++)
    {
        if(diff[i] > max) max = diff[i];
        total += diff[i];    
    }


    printf("%lld\n", total - max);

    return 0;
}

Measured memory_bytes: 1792
import sys
from collections import defaultdict

readline = sys.stdin.readline
readall = sys.stdin.read
ns = lambda: readline().rstrip()
ni = lambda: int(readline().rstrip())
nm = lambda: map(int, readline().split())
nl = lambda: list(map(int, readline().split()))
prl = lambda x: print(*x ,sep='\n')

n = ni()
a = nl()
q = ni()
list_ = defaultdict(lambda: 0)
for i in a:
    list_[i] += 1
res = sum(a)
for i in range(q):
    b,c = nm()
    res = res + (c*(list_[b])-b*list_[b])
    x = list_[b]
    list_[b] = 0
    list_[c] += x

    print(res)

Measured memory_bytes: 24108
def read():
  return list(map(int,input().split()))

def calc(bs,ls,first):
  if sum(ls[0::2])!=bs.count(first) or sum(ls[1::2])!=bs.count(1-first):
    return float("inf")
  res=0
  i,j=0,0
  for k in range(0,len(ls),2):
    if k>0: i+=ls[k-1]
    for _ in range(ls[k]):
      j=bs.index(first,j)
      res+=abs(j-i)
      i+=1
      j+=1
  return res

while 1:
  try:
    n,m=read()
    bs=read()
    ls=read()
  except: break
  print(min(calc(bs,ls,i) for i in range(2)))

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

inline void ioThings() {
  ios::sync_with_stdio(0);
  cin.tie(0);
#ifdef LOCAL
  freopen("io\\in.txt", "r", stdin);
  freopen("io\\out.txt", "w", stdout);
#define debug(x) cerr << #x << ": <" << (x) << ">\n"
#else
#define debug(x)
#endif
}

#define dotc()  int tcs; if (cin >> tcs) for (int tc = 0; tc < tcs; tc++)
#define sz(x)   (int)x.size()
#define eb      emplace_back
#define pb      push_back
#define all(x)  x.begin(), x.end()
#define rall(x) x.rbegin(), x.rend()
#define fi      first
#define se      second
#define mod     1000000007

using ll = long long;
using vi = vector<int>;

int main() {
  ioThings();

  int n, a, b; cin >> n >> a >> b;

  ll e = 1, ebase = 2;
  for (int i = n; i > 0; i /= 2) {
    if (i & 1) {
      e = e * ebase % mod;
    }
    ebase = ebase * ebase % mod;
  }

  ll cur = 1, ca;
  for (int i = 1; i <= b; i++) {
    cur = cur * (n - i + 1) % mod;

    ll mi = 1, mbase = i;
    for (int j = mod - 2; j > 0; j /= 2) {
      if (j & 1) {
        mi = mi * mbase % mod;
      }
      mbase = mbase * mbase % mod;
    }
    cur = cur * mi % mod;
    if (i == a)
      ca = cur;
  }

  cout << ((e - ca - cur - 1) % mod + mod) % mod;

  return 0;
}


Measured memory_bytes: 256
from collections import Counter
n = int(input())
a = list(map(int, input().split()))
c = Counter(a)
p = [True] * (10 ** 6 + 1)
s = list(set(a))
for x in s:
    t = x * 2
    while t <= 10 ** 6:
        p[t] = False
        t += x
ans = 0
for x in a:
    if c[x] == 1 and p[x] == True:
        ans += 1
print(ans)

Measured memory_bytes: 52736
#include <iostream>
#include <vector>
#include <set>
#include <map>
#include <unordered_set>
#include <unordered_map>
#include <queue>
#include <bitset>
#include <random>
#include <chrono>
#include <complex>
#include <algorithm>
#include <utility>
#include <functional>
#include <cmath>
#include <cstring>
#include <cassert>
#include <cstdio>
#include <cstdlib>
#include <ctime>
#include <iomanip> 

using namespace std;

#define mp make_pair
#define pb push_back
#define forn(i, n) for(int i = 0; i < (int)(n); ++i)
#define for1(i, n) for(int i = 1; i < (int)(n); ++i)
#define nfor(i, n) for(int i = int(n) - 1; i >= 0; --i)
#define fore(i, l, r) for(int i = int(l); i < int(r); ++i)
#define correct(x, y, n, m) (0 <= x && x < n && 0 <= y && y < m)
#define all(x) (x).begin(), (x).end()
#define fst first
#define snd second
#define endl "\n"

typedef long long ll;
typedef pair<int, int> pii;
typedef pair<ll, int> pli;
typedef pair<ll, ll> pll;
typedef long double ld;
typedef tuple<int,int,int> iii;

template<typename T> inline T abs(T a){ return ((a < 0) ? -a : a); }
template<typename T> inline T sqr(T a){ return a * a; }
template<class T> T gcd(T a, T b) { return a ? gcd (b % a, a) : b; }
template<class T> T lcm(T a, T b) { return a / gcd (a, b) * b; }
template<class T> T sign(T a) { return a > 0 ? 1 : (a < 0 ? -1 : 0); }

string to_string(string s) {
    return '"' + s + '"';
}
    
string to_string(const char* s) {
    return to_string((string) s);
}
    
string to_string(bool b) {
    return (b ? "true" : "false");
}
    
template <typename A, typename B>
string to_string(pair<A, B> p) {
    return "(" + to_string(p.first) + ", " + to_string(p.second) + ")";
}
    
template <typename A>
string to_string(A v) {
    bool first = true;
    string res = "{";
    for (const auto &x : v) {
        if (!first) {
            res += ", ";
        }
        first = false;
        res += to_string(x);
    }
    res += "}";
    return res;
}

void debug_out() { cerr << endl; }
template <typename Head, typename... Tail>
void debug_out(Head H, Tail... T) {
    cerr << " " << to_string(H);
    debug_out(T...);
}

void fastIO() {
    cin.sync_with_stdio(false);
    cin.tie(0);
}

template<typename T>
vector<T> make_unique(vector<T> v) {
    sort(all(v));
    return v.resize(unique(all(v)) - v.begin());
}

int nxt() {
    int x;
    cin >> x;
    return x;
}

const int dx[4] = {0, 0, 1, -1};
const int dy[4] = {1, -1, 0, 0};
const int dxKn[8] = {-2, -1, 1, 2,  2,  1, -1, -2};
const int dyKn[8] = { 1,  2, 2, 1, -1, -2, -2, -1};
const int dxK[8] = {0, 0, 1, -1, 1, 1, -1, -1};
const int dyK[8] = {1, -1, 0, 0, 1, -1, 1, -1};

const int MOD = int(1e9) + 7;
const int INF = int(1e9) + 100;
const ll INF64 = 2e18;
const ld PI = ld(3.1415926535897932384626433832795);
const ld e = ld(2.7182818284590452353602874713527);
const ld EPS = 1e-9;

//#############################
const int MAXN = 1000005;

int main() {
    fastIO(); 
    long double a, b;
    cin >> a >> b;

    cout << setprecision(0) << fixed;
    cout << trunc(a * b) << endl;
    return 0;
}

Measured memory_bytes: 3788
#include "bits/stdc++.h"
using namespace std;
// #define int               long long
#define nl                "\n"
#define pb                push_back
#define mp                make_pair
#define ppb               pop_back
#define pf                push_front
#define ppf               pop_front
#define all(x)            (x).begin(),(x).end()
#define uniq(v)           (v).erase(unique(all(v)),(v).end())
#define sz(x)             (int)((x).size())
#define f                 first
#define s                 second
#define pii               pair<int,int>
#define rep(i,a,b)        for(int i=a;i<b;i++)
#define mem1(a)           memset(a,-1,sizeof(a))
#define mem0(a)           memset(a,0,sizeof(a))
#define ppc               __builtin_popcount
#define ppcll             __builtin_popcountll
#define fast_io           ios_base::sync_with_stdio(false);cin.tie(NULL);
 
const long long INF=1e18;
const int32_t M=1e9+7;
const int32_t MM=998244353;

int a[301];
double dp[302][302][302];
//w-3,x-2,y-1, n-w-x-y for 0s
//dp[0][0][0]=1;



void solve(){
	int n;
	cin>>n;
	int cnt[4]={0};
	rep(i,0,n){cin>>a[i];cnt[a[i]]++;}
	//cout<<cnt[1];

	dp[0][0][0]=0;



	rep(three,0,n+1){
	 rep(two,0,n+1){
       rep(one,0,n+1){
          int zero=n-(three+two+one);
          if(zero==n or one+two+three>n)continue;

           double val=1;
            if(three>0)val+=(1.0* three / n)*dp[three-1][two+1][one];
            if(two>0)val+=(1.0* two / n)*dp[three][two-1][one+1];
            if(one>0)val+=(1.0* one / n)*dp[three][two][one-1];
            dp[three][two][one]=val/(1-1.0* zero /n);
        }
      }
    }    


cout<<setprecision(9)<<fixed;
  cout<<dp[cnt[3]][cnt[2]][cnt[1]];


       }	


signed main(){
	fast_io
   
	#ifdef SIEVE
		sieve();
	#endif
	#ifdef NCR
		init();
	#endif
	int t=1;
	//cin>>t;
	while(t--) solve();
	return 0;
}


Measured memory_bytes: 111392
import copy
import math

N = int(input())
xy = []
for _ in range(N):
    xy.append(tuple(map(int, input().split())))

def dfs(parent, p, q):
    seen[parent] = True
    for child in range(N):
        # print(child)
        if seen[child] == False:
            x, y = xy[child]
            if x + p == xy[parent][0] and y + q == xy[parent][1] or \
                    x - p == xy[parent][0] and y - q == xy[parent][1]:
                dfs(child, p, q)


m = N
for i in range(N - 1):
    for j in range(i + 1, N):
        p = xy[i][0] - xy[j][0]
        q = xy[i][1] - xy[j][1]
        cnt = 0
        seen = [False] * N
        for start in range(N):
            if seen[start] == False:
                dfs(start, p, q)
                cnt += 1
                # print(tosee)
        m = min(cnt, m)
        # print(p, q, group)
print(m)

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

int main() {
  int N,M;
  cin>>N>>M;
  int a=0;
  int sum=0;//得票数
  
  vector<int> data(N);
  for (int i = 0; i < N; i++) {
    cin >> data.at(i);
    sum += data.at(i);
  } 
  for (int i = 0; i < N; i++) {
    if(data.at(i)*4*M>=sum){
      a++;
    }
  } 
  
  if(a>=M){
  cout<<"Yes"<<endl;
  }
  else{
  cout<<"No"<<endl;
  }
  
}


Measured memory_bytes: 256
import java.util.*;
public class Main{
	public static void main(String[] args){
    	Scanner sc = new Scanner(System.in);
      int n = sc.nextInt();
      int[][] a = new int[100001][2];
      int[][] b = new int[100001][2];
      for(int i = 0;i < n/2;i++){
      	int x = sc.nextInt();
        int y = sc.nextInt();
        a[x][0]=x;
        b[y][0]=y;
        a[x][1]++;
        b[y][1]++;
      }
      Arrays.sort(a,Comparator.comparing((int[] x)->x[1]).reversed());
      Arrays.sort(b,Comparator.comparing((int[] x)->x[1]).reversed());
      if(a[0][0]!=b[0][0])System.out.println(n-a[0][1]-b[0][1]);
      else System.out.println(Math.min(n-a[1][1]-b[0][1],n-a[0][1]-b[1][1]));
    }
}

Measured memory_bytes: 66608
parseInt(x) = parse(Int, x)
parseMap(x::Array{SubString{String},1}) = map(parseInt, x)
function isPrime(x)
	if x <= 1
		false
	elseif x == 2
		true
	elseif x%2 == 0
		false
	else
		i = 3
		f = 0
		while i <= floor(sqrt(x))
			if x%i == 0
				f = 1
				break
			else
				i += 2
			end
		end
		f==0?true:false
	end
end


function main()
	prime = Bool[isPrime(i) for i in 1:100000]
	a = zeros(Int,100000)
	for i in 2:100000
		if i%2==1&&prime[i]&&prime[div(i+1,2)]
			a[i] = a[i-1]+1
		else
			a[i] = a[i-1]
		end
	end
	q = readline() |> parseInt
	for i in 1:q
		l,r = readline() |> split |> parseMap
		if l==1
			println(a[r])
		else
			println(a[r]-a[l-1])
		end
	end
end

main()

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

char chess(int h,int w){
    if((h+w)%2==0){
        return'#';
    }
    return'.';
}

int main(void){
    int H,W;
    while(true){
     cin >> H >> W;
     if(H==0 && W==0){
         break;
     }
     for(int i=0; i<H; i++){
        for(int j=0; j<W; j++){
        cout << chess(i,j);
        }
       cout << endl;
     }
     cout << endl;
    }
}


Measured memory_bytes: 3072
def distance(s, t):
    return len([1 for (a, b) in zip(s, t) if a != b])

S = input()
T = input()
ans = float('inf')
for i in range(len(S) - len(T) + 1):
    ans = min(ans, distance(T, S[i:i+len(T)]))
print(ans)


Measured memory_bytes: 67500
#include<bits/stdc++.h>
using namespace std;
int main(){
    int n,l=1000000;
    cin>>n;
    int a[n];
    for(int i=0;i<n;i++) cin>>a[i];
    for(int i=0;i<n;i++){
        int k=0,m=0;
        for(int j=0;j<i;j++){
            k+=a[j];
        }
        for(int j=i;j<n;j++){
            m+=a[j];
        }
        if(l>abs(k-m)) l=abs(k-m);
    }
    cout<<l;
}


Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
#define REP(i,a) for(int i = 0; i < (a); i++)
#define ALL(a) (a).begin(),(a).end()
typedef long long ll;
typedef pair<int, int> P;
const int INF = 1e9;
const int MOD = 1e9 + 7;

signed main(){
    string s;
    cin >> s;
    if(s[0] == 'S'){
        cout << "Cloudy" << endl;
    }else if(s[0] == 'C'){
        cout << "Rainy" << endl;
    }else{
        cout << "Sunny" << endl;
    }
}

Measured memory_bytes: 256