akhauriyash/Code-Regression huggingface dataset:
#include <bits/stdc++.h>
using namespace std;

#define int long long

struct Combination
{
  int mod;
  vector<int> mfact;
  vector<int> rfact;

  /*
    constructor : O(sz+log(mod))    
   */
  Combination(int sz, int mod) : mfact(sz+1), rfact(sz+1), mod(mod) {
    mfact[0] = 1;
    for ( int i = 1; i < (int)mfact.size(); i++ ) {
      mfact[i] = mfact[i-1]*i % mod;
    }
    rfact[sz] = inv(mfact[sz]);
    for ( int i = sz-1; i >= 0; i-- ) {
      rfact[i] = rfact[i+1]*(i+1) % mod;
    }
  }

  int fact(int k) const {
    return (mfact[k]);
  }

  int pow(int x, int n) const {
    int ret = 1;
    while ( n > 0 ) {
      if ( n & 1 ) (ret *= x) %= mod;
      (x *= x) %= mod;
      n >>= 1;
    }
    return (ret);
  }

  int inv(int x) const {
    return (pow(x, mod - 2));
  }

  /*
    permutation
   */
  int P(int n, int r) const {
    if ( r < 0 || n < r ) return (0);
    return (mfact[n]*rfact[n-r] % mod);
  }

  /*
    combination
   */
  int C(int n, int r) const {
    if ( r < 0 || n < r ) return (0);    
    return (mfact[n]*rfact[r]%mod * rfact[n-r] % mod);    
  }  

  /*
    combination with repetition
   */
  int H(int n, int r) const {
    if ( n < 0 || r < 0 ) return 0;
    if ( n == 0 && r == 0 ) return 1;
    return C(n+r-1, n);    
  }

  /*
    stirling number
   */
  int S(int n, int r) const {
    int ret = 0;
    for ( int i = 1; i <= r; i++ ) {
      int add = C(r, i)*pow(i, n)%mod;      
      if ( (r-i)&1 ) ret += mod-add;
      else ret += add;
      ret %= mod;      
    }
    (ret *= rfact[r]) %= mod;
    return ret;
  }

  /*
    bell number
   */
  int B(int n, int r) const {
    int ret = 0;
    for ( int i = 1; i <= r; i++ ) {
      (ret += S(n, i)) %= mod;      
    }
    return ret;
  }
};

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

  int n, k;
  cin >> n >> k;

  int MOD = 1e9+7;  
  Combination c(2000, MOD);

  cout << c.B(n, k) << endl;  
  
  return 0;
}



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

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

    int mn[N + 1];
    mn[0] = 100000000;
    for(int i = 0; i < N; i++){
        mn[i + 1] = min(mn[i], a[i]);
    }

    int ans = 0;
    for(int i = 0; i < N; i++){
        if(mn[i] >= a[i]) ans++;
    }

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


Measured memory_bytes: 1920
#include<iostream>
#include<algorithm>
#include<vector>
#include<queue>
#define lol(i,n) for(int i=0;i<n;i++)
#define mod 1000000007
typedef long long ll;
using namespace std;
int n,k;
int cnt[200010];
int main(){
	cin>>n>>k;
	lol(i,n)cnt[i]=0;
	lol(i,n){
		int a;cin>>a;
		cnt[a-1]++;
	}
	sort(cnt,cnt+n);
	int ans=0;
	lol(i,n-k)ans+=cnt[i];
	cout<<ans<<endl;
	return 0;
}


Measured memory_bytes: 1024
#include <iostream>
#include <vector>
#include <algorithm>
using namespace std;
struct data{
	int t;
	int s;
	int d;
};

bool operation(const data &l,const data&r){
	return l.t < r.t;
}
int main(){
	bool b[20001];
	int N,M;
	vector<data> v;
	data da;
	int res;
	while(1){
		cin >> N >> M;
		if(N == 0)break;
		v.clear();
		for(int i = 1;i <= N;i++){
			b[i] = false;
		}
		for(int i = 0;i < M;i++){
			cin >> da.t >> da.s >> da.d;
			v.push_back(da);
		}
		sort(v.begin(),v.end(),operation);
		b[1] = true;
		res = 1;
		for(int i = 0;i < v.size();i++){
			if(b[v[i].s] && !b[v[i].d]){
				b[v[i].d] = true;
				res++;
				//cout << v[i].s << " : " << v[i].d <<endl;
			}
		}
		cout << res <<endl;
	}


	return 0;
}

Measured memory_bytes: 1716
#include <iostream>
#include <vector>
#include <utility>
#include <algorithm>
using namespace std;

int main()
{
    int N, M;
    cin >> N >> M;

    vector<pair<int, pair<int, int>>> i_p_y;
    for (int i = 0; i < M; i++)
    {
        int p, y;
        cin >> p >> y;
        i_p_y.push_back(make_pair(i, make_pair(p, y)));
    }
    std::sort(i_p_y.begin(), i_p_y.end(), [](auto &left, auto &right) {
        return left.second < right.second;
    });

    // for (int i = 0; i < i_p_y.size(); i++)
    // {
    //     cout << i_p_y[i].first << ", " << i_p_y[i].second.first << ", " << i_p_y[i].second.second << endl;
    // }

    vector<pair<int, string>> ans;
    int now_p = 1;
    int num = 1;
    for (int i = 0; i < i_p_y.size(); i++)
    {
        if (now_p < i_p_y[i].second.first)
        {
            i--;
            num = 1;
            now_p++;
            continue;
        }

        string sp = to_string(now_p);
        string sy = to_string(num);
        while (sp.size() < 6)
        {
            sp = "0" + sp;
        }
        while (sy.size() < 6)
        {
            sy = "0" + sy;
        }
        string s = sp + sy;

        ans.push_back(make_pair(i_p_y[i].first, s));
        num++;
    }
    sort(ans.begin(), ans.end());

    for (int i = 0; i < ans.size(); i++)
    {
        cout << ans[i].second << endl;
    }

    return 0;
}

Measured memory_bytes: 9372
#include <bits/stdc++.h>
using namespace std;
#define modulo 1000000007
#define mod(mod_x) ((((long long)mod_x+modulo))%modulo)
#define Inf 10000000000000000

int main(){
	
	int N;
	cin>>N;
	
	vector<string> S(N);
	for(int i=0;i<N;i++)cin>>S[i];
	
	set<int> se;
	
	for(int i=0;i<N;i++){
		for(int j=0;j<N;j++){
			if(S[i][j]=='#')se.insert(j);
		}
	}
	
	if(se.size()==0){
		cout<<-1<<endl;
		return 0;
	}
	
	int ans = 100000;
	
	for(int i=0;i<N;i++){
		int temp = 0;
		if(!se.count(i))temp++;
		for(int j=0;j<N;j++){
			if(S[i][j]=='.')temp++;
		}
		ans = min(ans,temp);
	}
	
	ans += N;
	for(int i=0;i<N;i++){
		bool f = true;
		for(int j=0;j<N;j++){
			if(S[j][i]=='.')f=false;
		}
		if(f)ans--;
	}
	
	cout<<ans<<endl;
	
	return 0;
}

Measured memory_bytes: 512
#include<stdio.h>
#define N 44

int F[N];

int fibonacci(int n){
  if(n == 1|| n == 0){
    return F[n] = 1;
  }
  if(F[n]) return F[n];
  return F[n] = fibonacci(n - 2) + fibonacci(n - 1);
}

int main(){
  int n;
  scanf("%d",&n);
  printf("%d\n",fibonacci(n));
  return 0;
}




Measured memory_bytes: 2108
use std::collections::*;
use std::cmp::*;

macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
    ($($r:tt)*) => {
        let s = {
            use std::io::Read;
            let mut s = String::new();
            std::io::stdin().read_to_string(&mut s).unwrap();
            s
        };
        let mut iter = s.split_whitespace();
        input_inner!{iter, $($r)*}
    };
}

macro_rules! input_inner {
    ($iter:expr) => {};
    ($iter:expr, ) => {};

    ($iter:expr, $var:ident : $t:tt $($r:tt)*) => {
        let $var = read_value!($iter, $t);
        input_inner!{$iter $($r)*}
    };
}

macro_rules! read_value {
    ($iter:expr, ( $($t:tt),* )) => {
        ( $(read_value!($iter, $t)),* )
    };

    ($iter:expr, [ $t:tt ; $len:expr ]) => {
        (0..$len).map(|_| read_value!($iter, $t)).collect::<Vec<_>>()
    };

    ($iter:expr, chars) => {
        read_value!($iter, String).chars().collect::<Vec<char>>()
    };

    ($iter:expr, usize1) => {
        read_value!($iter, usize) - 1
    };

    ($iter:expr, $t:ty) => {
        $iter.next().unwrap().parse::<$t>().expect("Parse error")
    };
}

fn main() {
    input!{
        x: i32,
        y: i32,
        z: i32,
    }

    println!("{} {} {}", z, x, y);
}


Measured memory_bytes: 4352
import java.io.File;
import java.io.FileNotFoundException;
import java.util.ArrayList;
import java.util.Collections;
import java.util.Comparator;
import java.util.List;
import java.util.Scanner;

public class Main {

	public static void main(String[] args) throws FileNotFoundException {

		Scanner scan = new Scanner(System.in);
		//Scanner scan = new Scanner(new File("c:\\0529-input.txt"));

		while (scan.hasNext()) {
			int n = scan.nextInt();
			int m = scan.nextInt();
			if (n == 0)
				break;
			Darts d = new Darts(n, m);
			for (int i = 0; i < n; i++)
				d.add(scan.nextInt());
			System.out.println(d.max());
		}
		scan.close();
		System.exit(0);
	}
}

class Darts {
	List<Integer> score = new ArrayList<Integer>();
	int M;

	public Darts(int n, int m) {
		M = m;
		score.add(0);
	}

	public int max() {
		score.sort(null);
		Integer[] sc = score.toArray(new Integer[score.size()]);
		score.clear();

		for (int i = 0; i < sc.length; i++)
			for (int j = i; j < sc.length; j++)
				if (sc[i] + sc[j] > M)
					break;
				else
					score.add(sc[i] + sc[j]);

		score.sort(null);
		sc = null;
		sc = score.toArray(new Integer[score.size()]);
		// System.out.println("--" + sc.length);
		int max = 0;
		for (int i = 0; i < sc.length; i++)
			for (int dj = (sc.length - i) / 2, j = i + dj; dj > 0 && j < sc.length;)
				if (sc[i] + sc[j] > M) {
					dj /= 2;
					j -= dj;
				} else {
					if (max < sc[i] + sc[j])
						max = sc[i] + sc[j];
					dj /= 2;
					if (dj == 0)
						dj = 1;
					j += dj;
				}

		return max;
	}

	public void add(int s) {
		if (s <= M)
			score.add(s);
	}
}

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

#define ll long long
#define fornum(A,B,C) for(A=B;A<C;++A)
#define pii pair<int,int>
#define pll pair<ll,ll>

using namespace std;

/////////////////////////////////////////////////////

ll H,W,K;
char S[1010][1010];
ll mk[1 << 11][20],mk2[20];

ll dp[1 << 11];
ll i, j, k;
int main(){
    scanf("%lld%lld%lld", &H, &W, &K);
    fornum(i,0,H){
        scanf("%s", S[i]);
    }
    fornum(i,0,1<<H){
        ll c = __builtin_popcountll(i);
        dp[i] = c;
    }
    fornum(i,0,W){
        fornum(j,0,1<<H){
            ll ii = 0;
            fornum(k,0,H){
                mk2[ii] += (S[k][i] == '1'?1:0);
                if(j&(1<<k)){
                    ++ii;
                }
            }
            fornum(k,0,H){
                if(mk[j][k]+mk2[k]>K){
                    break;
                }
            }
            if(k<H){
                ++dp[j];
                fornum(k,0,H){
                    mk[j][k] = 0;
                }
            }
            //ll a = 0;
            fornum(k,0,H){
                if(mk2[k]>K){
                    dp[j] = 1e9;
                }
                mk[j][k] += mk2[k];
                //a = max(mk[j][k], a);
                mk2[k] = 0;
            }
            //printf("%lld,", dp[j]);
        }
        //printf("\n");
    }
    ll ans = 1e9;
    fornum(i,0,1<<H){
        ans = min(ans, dp[i]);
    }

    
    printf("%lld\n", ans);

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
using namespace std;
#define REP(i, n) for(int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; --i)
#define FOR(i, n, m) for (int i = m; i < n; i++)
#define INF 1e9
#define ALL(v) v.begin(), v.end()

typedef long long ll;
/**
 * C問以降は ll を使う.
 * double型にするのを忘れない.
 * nC2の求め方 (1/2)*n*(n-1)
 * vector<型> 変数名(要素数, 初期値)
 */
int main()
{
    string s;
    cin >> s;
    s.replace(s.length()-8, 8, "");
    cout << s << endl;
    return 0;
}

Measured memory_bytes: 256
N, W = (int(x) for x in input().split())
dp = [0] * (W+1) # Maximum value of items we can carry at weight
for _ in range(N):
  w, v = (int(x) for x in input().split())
  for cur in range(W, w-1, -1):
    dp[cur] = max(dp[cur-w]+v, dp[cur])

print(dp[W])

Measured memory_bytes: 67556
package main

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

func exec(stdin *Stdin, stdout *Stdout) {
	n := stdin.ReadInt()
	m := stdin.ReadInt()
	a := []int{}
	for i := 0; i < n; i++ {
		a = append(a, stdin.ReadInt())
	}

	c := 0
	for a[0]%2 == 0 {
		a[0] /= 2
		c++
	}

	for i := 1; i < n; i++ {
		d := 0
		for a[i]%2 == 0 {
			a[i] /= 2
			d++
		}

		if c != d {
			stdout.Println(0)
			return
		}
	}

	for i := 0; i < c-1; i++ {
		m /= 2
	}

	lcm := 1
	for i := 0; i < n; i++ {
		lcm = Lcm(lcm, a[i])
	}

	if lcm <= m {
		stdout.Println(((m / lcm) + 1) / 2)
	} else {
		stdout.Println(0)
	}
}

func main() {
	stdout := NewStdout()
	defer stdout.Flush()
	exec(NewStdin(bufio.ScanWords), stdout)
}

type Stdin struct {
	stdin *bufio.Scanner
}

func NewStdin(split bufio.SplitFunc) *Stdin {
	s := Stdin{bufio.NewScanner(os.Stdin)}
	s.stdin.Split(split)
	s.stdin.Buffer(make([]byte, bufio.MaxScanTokenSize), int(math.MaxInt32))
	return &s
}

func (s *Stdin) Read() string {
	s.stdin.Scan()
	return s.stdin.Text()
}

func (s *Stdin) ReadInt() int {
	n, _ := strconv.Atoi(s.Read())
	return n
}

func (s *Stdin) ReadFloat64() float64 {
	n, _ := strconv.ParseFloat(s.Read(), 64)
	return n
}

type Stdout struct {
	stdout *bufio.Writer
}

func NewStdout() *Stdout {
	return &Stdout{bufio.NewWriter(os.Stdout)}
}

func (s *Stdout) Flush() {
	s.stdout.Flush()
}

func (s *Stdout) Println(a ...interface{}) {
	fmt.Fprintln(s.stdout, a...)
}

func Gcd(x, y int) int {
	if x < y {
		x, y = y, x
	}

	for y > 0 {
		x, y = y, x%y
	}

	return x
}

func Lcm(x, y int) int {
	return x * y / Gcd(x, y)
}


Measured memory_bytes: 5632
#include <iostream>
#include <cstdio>
#include <cmath>
#include <vector>
#include <queue>

#include <map>
#include <set>
#include <string>
#include <algorithm>
#include <functional>
using namespace std;
#define FOR(i,a,b) for (int i=(a);i<(b);i++)
#define RFOR(i,a,b) for (int i=(b)-1;i>=(a);i--)
#define REP(i,n) for (int i=0;i<(n);i++)
#define RREP(i,n) for (int i=(n)-1;i>=0;i--)
#define INF 1<<29
#define ALEN(ARR) (sizeof(ARR) / sizeof((ARR)[0]))
#define MP make_pair
#define mp make_pair
#define pb push_back
#define PB push_back
#define _DEBUG(x) cout<<#x<<": "<<x<<endl
#define _DDEBUG(x,y) cout<<#x<<": "<<x<<", "<<#y<<": "<<y<<endl
#define ll long long
#define ull unsigned long long
#define MOD 1000000007

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

    int n, m, k, l;
    cin >> n >> m >> k >> l;
#if DEBUG
    cout << "** RESULT **" << endl; // debug
#endif
    cout << (n * k - (n - m > 0 ? n - m : 0) * (k - l)) << endl;

    return 0;
}


Measured memory_bytes: 256
#include<iostream>



using namespace std;

int main()
{
	int N, K, A[99999], times = 0;
	cin >> N >> K;
	for (int i = 0; i < N; i++) {
		cin >> A[i];
	}
	times++;
	N -= K;

	while (N > 0) {
		times++;
		N -= (K- 1);
	}

	cout << times;
	return 0;

}

Measured memory_bytes: 640
#include <bits/stdc++.h>
#define FI(__n) for(int i = 0; i < __n; ++i)
#define FJ(__n) for(int j = 0; j < __n; ++j)
#define INT_MAX 2147483647
#define INT_MIN -2147483648
#define l first
#define r second
#define mp make_pair
#define pb push_back
using namespace std;
typedef long long ll;
typedef pair<int, int> pii;
const int MOD=1000000007;
int solve()
{
    int n;
    cin>>n;
    int maxC=1;
    int maxCounter=0;
    for(int i=n;i>0;i--)
    {
        int counter=0;
        int t=i;

        while(t%2==0)
        {

            t/=2;
            counter++;
        }
        if(maxCounter<counter) {maxC=i;maxCounter=counter;}
    }
    cout<<maxC;
    return 0;
}
int main()
{
    ofstream coutf;
    coutf.open("output.txt");
    ifstream cinf;
    cinf.open("input.txt");
    solve();
    cinf.close();
    coutf.close();
    return 0;
}


Measured memory_bytes: 256
a,b,c,d = map(int,input().split())
from fractions import gcd
def lcm(x,y):
  return (x*y) // gcd(x,y)
if c == 1 or d == 1:
  print(0)
else:
  print(b-a+1 - b//c + (a-1)//c - b//d + (a-1)//d + b//lcm(c,d) - (a-1)//lcm(c,d))

Measured memory_bytes: 5104
#pragma GCC optimize ("O3")
#pragma GCC target ("avx")
//#include<bits/stdc++.h>
#include<cstdio>
#include<algorithm>
using namespace std;
typedef long long ll;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define rep1(i, n) for(int i = 1; i <= (n); i++)
#define co(x) cout << (x) << "\n"
#define cosp(x) cout << (x) << " "
#define ce(x) cerr << (x) << "\n"
#define cesp(x) cerr << (x) << " "
#define pb push_back
#define mp make_pair
#define chmin(x, y) x = min(x, y)
#define chmax(x, y) x = max(x, y)
#define Would
#define you
#define please

int dp[1001][1001];
const int mod = 1e9 + 7;
char A[1001][1001];
int main() {
	//cin.tie(0);
	//ios::sync_with_stdio(false);


	int H, W;
	scanf("%d", &H);
	scanf("%d", &W);
	rep(i, H) scanf("%s", A[i]);

	dp[0][0] = 1;
	rep1(h, H - 1) dp[h][0] = (A[h][0] == '.' ? dp[h - 1][0] : 0);
	rep1(w, W - 1) dp[0][w] = (A[0][w] == '.' ? dp[0][w - 1] : 0);
	rep1(h, H - 1) {
		rep1(w, W - 1) {
			if (A[h][w] == '.') {
				dp[h][w] = (dp[h - 1][w] + dp[h][w - 1]) % mod;
			}
		}
	}
	printf("%d", dp[H - 1][W - 1]);

	Would you please return 0;
}

Measured memory_bytes: 4992
def solve():
    N = int(input())
    S1 = input()
    S2 = input()
    MOD = 1000000007
    
    pattern = []
    i = 0
    while i < N:
        if S1[i] == S2[i]:
            pattern.append(0)
            i += 1
        else:
            pattern.append(1)
            i += 2
    
    ans = 3 if pattern[0] == 0 else 6
    for i in range(1, len(pattern)):
        if pattern[i] == 0:
            if pattern[i - 1] == 0:
                ans = ans * 2 % MOD
        else:
            if pattern[i - 1] == 0:
                ans = ans * 2 % MOD
            else:
                ans = ans * 3 % MOD
    print(ans)


if __name__ == '__main__':
    solve()


Measured memory_bytes: 3064
#include<iostream>
#include<string>
#include<cstdio>
#include<vector>
#include<cmath>
#include<algorithm>
#include<functional>
#include<iomanip>
#include<queue>
#include<ciso646>
#include<random>
#include<map>
#include<set>
#include<bitset>
#include<stack>
#include<unordered_map>
#include<utility>
#include<cassert>
using namespace std;

typedef long long ll;

typedef unsigned long long ul;
typedef unsigned int ui;
const ll mod = 998244353;
const ll INF = mod * mod;
typedef pair<int, int> P;
#define stop char nyaa;cin>>nyaa;
#define rep(i,n) for(int i=0;i<n;i++)
#define per(i,n) for(int i=n-1;i>=0;i--)
#define Rep(i,sta,n) for(int i=sta;i<n;i++)
#define rep1(i,n) for(int i=1;i<=n;i++)
#define per1(i,n) for(int i=n;i>=1;i--)
#define Rep1(i,sta,n) for(int i=sta;i<=n;i++)
typedef pair<ll, ll> LP;
typedef vector<LP> vec;
typedef vector<string> svec;
typedef long double ld;
typedef pair<ld, ld> LDP;
const ld eps = 1e-8;

ll dp[200][1 << 10],cop[200][1<<10];

void solve() {
	int n, k; ll m; cin >> n >> k >> m;
	int s = (1 << 10);
	rep1(i, k) {
		dp[i][0] = 1;
	}
	rep(i, n - 1) {
		rep(j, 200) {
			rep(x, (1 << 10))cop[j][x] = 0;
		}
		rep(j, 200) {
			rep(x, (1 << 10)) {
				if (dp[j][x] == 0)continue;
				int len = j - i;
				if (len > n)continue;
				if (len < i + 1)continue;
				else if (len == i + 1) {
					bool f = false; int las;
					rep(l, 10) {
						if ((x&(1 << l)) == 0) {
							las = j - 1 - l;
							f = true; break;
						}
					}
					if (!f)continue;
					if (j + 1 - las > k)continue;
					Rep1(l, 2, k) {
						if (j + l >= 2 * n)continue;
						int nx = x << l; nx += (1 << (l - 1));
						nx %= s;
						cop[j + l][nx] += dp[j][x];
						if (cop[j + l][nx] >= m)cop[j + l][nx] -= m;
					}
				}
				else {
					int dif = len - (i + 1);
					int tmp = 0; bool f = false;
					int past;
					int las;
					rep(l, 10) {
						if ((x&(1 << l))==0) {
							if (tmp == 0) {
								las = j - 1 - l;
							}
							tmp++;
							if (tmp == dif) {
								past = j - 1 - l;
								f = true; break;
							}
						}
					}
					if (!f) {
						continue;
					}
					rep1(l, k) {
						int nj = j + l;
						if (nj >= 2 * n)continue;
						if (nj - past > k)continue;
						if (l > 1) {
							if (j + 1 - las > k)continue;
						}
						int nx = x << l; nx += (1 << (l-1));
						nx %= s;
						cop[nj][nx] += dp[j][x];
						if (cop[nj][nx] >= m)cop[nj][nx] -= m;
					}
				}
			}
		}
		//cout << i << endl;
		rep(j, 200) {
			rep(x, (1 << 10)) {
				dp[j][x] = cop[j][x];
				//if (dp[j][x]) {
				//	//cout << j << " " << x << " " << dp[j][x] << endl;
				//}
			}
		}
	}
	int ans = 0;
	rep(x, (1 << 10)) {
		ans += dp[2 * n - 1][x];
		if (ans >= m)ans -= m;
	}
	cout << ans << endl;
	/*rep(j, 200) {
		int len = j - n;
		rep(x, (1 << 10)) {
			ans += dp[j][x];
			if (ans >= m)ans -= m;
		}
	}
	cout << ans << endl;*/
}

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

	//cout << fixed << setprecision(10);
	//init();
	solve();
	//stop
	return 0;
}



Measured memory_bytes: 6436
//Link : https://atcoder.jp/contests/dwacon6th-prelims/tasks/dwacon6th_prelims_d

#include <bits/stdc++.h>
using namespace std;
#define ll long long
#define N 100005
int a[N];
int indeg[N];
void solve() {
  int n;scanf("%d ", &n);
  for(int i=1;i<=n;++i) {
    scanf("%d ", &a[i]);
    indeg[a[i]]++;
  }
  set<pair<int,int> >s;
  set<int> remNode;
  for(int i=n;i;--i) {
    s.insert(make_pair(indeg[i],i));
    remNode.insert(i);
  }
  if(n==2) {
    printf("-1\n");
    return;
  }
  int ban = -1;
  while(true) {
    if(n<=3) {
      vector<int> v;
      for(int node : remNode) {
        v.push_back(node);
      }
      vector<int> ret;
      do {
        if(v[0]==ban) {
          continue;
        }
        bool isGood = true;
        for(int i=0;i<v.size()-1;++i) {
          if(a[v[i]]==v[i+1]) {
            isGood = false;
            break;
          }
        }
        if(isGood) {
          if(ret.size()==0) {
            ret = v;
          } else {
            ret = min(ret,v);
          }
        }
      } while(next_permutation(v.begin(),v.end()));
      for(int i=0;i<ret.size();++i) {
        printf("%d ", ret[i]);
      }
      putchar('\n');
      break;
    } else {
      pair<int,int> tmp = *prev(s.end());
      int chNode = -1;
      if(tmp.first==n-1) {
        chNode = tmp.second;
      } else {
        for(int node : remNode) {
          if(node!=ban) {
            chNode = node;
            break;
          }
        }
      }
      printf("%d ", chNode);
      ban = a[chNode];
      s.erase(make_pair(indeg[chNode],chNode));
      remNode.erase(chNode);
      if(remNode.count(a[chNode])) {
        s.erase(make_pair(indeg[a[chNode]],a[chNode]));
        --indeg[a[chNode]];
        s.insert(make_pair(indeg[a[chNode]],a[chNode]));
      }
      --n;
    }
  }
}

int main() {
    //freopen("input.txt","r",stdin);
    solve();
    return 0;
}


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

struct unionfind{
	vector<int> data;
	vector<int> size;
	unionfind(int n){
		for(int i=0;i<n;i++){
			data.push_back(i);
			size.push_back(1);
		}
	}
	
	int find(int x){
		if(data[x]==x)return x;
		return data[x]=find(data[x]);
	}
	
	bool unite(int x,int y){
		x=find(x);y=find(y);
		if(x==y)return false;
		data[x]=y;
		size[y]+=size[x];
		return true;
	}
	
	bool check(int x,int y){
		return (find(x)==find(y));
	}
	
	int get_size(int x){
		int X = find(x);
		return size[X];
	}
};



int main(){
	
	int N,M;
	cin>>N>>M;
	unionfind uf(N);
	vector<pair<int,int>> A(M);
	for(int i=0;i<M;i++){
		int a,b;
		cin>>a>>b;
		A[i].first=a-1;
		A[i].second=b-1;
	}
	reverse(A.begin(),A.end());
	vector<long long> ans(M);
	ans[0]=(long long)N*(N-1)/2;
	for(int i=0;i<M-1;i++){
		int a = uf.get_size(A[i].first);
		int b = uf.get_size(A[i].second);
		bool f = uf.unite(A[i].first,A[i].second);
		if(f){
			ans[i+1]=ans[i]-a*b;
		}
		else{
			ans[i+1]=ans[i];
		}
	}
	reverse(ans.begin(),ans.end());
	for(int i=0;i<M;i++){
		cout<<ans[i]<<endl;
	}
	
	
	return 0;
}

Measured memory_bytes: 3828
#!/usr/bin/env python3
import sys
import math
import decimal
import itertools
from itertools import product
from functools import reduce
def input():
    return sys.stdin.readline()[:-1]
def gcd(*numbers):
    return reduce(math.gcd, numbers)
def lcm_base(x, y):
    return (x * y) // math.gcd(x, y)
def lcm(*numbers):
    return reduce(lcm_base, numbers, 1)
def sort_zip(a:list, b:list):
    z = zip(a, b)
    z = sorted(z)
    a, b = zip(*z)
    a = list(a)
    b = list(b)
    return a, b
def ceil(x):
    return math.ceil(x)
def floor(x):
    return math.floor(x)

def main():
    N, K = map(int, input().split())
    A = list(map(int, input().split()))

    ans = ceil((N - 1) / (K - 1))
    print(ans)


if __name__ == '__main__':
    main()


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

int main() {
    ll n, k;
    cin >> n >> k;
    if (k % 2 == 0)
    {
        ll a = n / k;
        ll b = (n + k / 2) / k;
        cout << a * a * a + b * b * b << endl;
    }
    else
    {
        ll a = n / k;
        cout << a * a * a << endl;
    }
}


Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <vector>
#include <algorithm>
#include <cstdint>

using namespace std;
static const int INF = 1000000000;
static int dp[10000][50];

vector<uint64_t> matmul(
	const vector<uint64_t> &a, const vector<uint64_t> &b)
{
	const int n = a.size();
	vector<uint64_t> b_t(n);
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			b_t[j] |= ((b[i] >> j) & 1) << i;
		}
	}
	vector<uint64_t> c(n);
	for(int i = 0; i < n; ++i){
		for(int j = 0; j < n; ++j){
			c[i] |= (a[i] & b_t[j]) ? (1ull << j) : 0ull;
		}
	}
	return c;
}

vector<uint64_t> matpow(const vector<uint64_t> &a, int p){
	const int n = a.size();
	vector<uint64_t> result(n);
	for(int i = 0; i < n; ++i){ result[i] = (1ull << i); }
	for(int i = 0; i < p; ++i){ result = matmul(result, a); }
	return result;
}

int main(){
	ios_base::sync_with_stdio(false);
	int n, m, a, b, c;
	cin >> n >> m >> a >> b >> c;
	vector<uint64_t> mat(n);
	for(int i = 0; i < m; ++i){
		int u, v;
		cin >> u >> v;
		--u; --v;
		mat[u] |= (1ull << v);
	}
	const auto a_mat = matpow(mat, a);
	const auto b_mat = matpow(mat, b);
	const auto c_mat = matpow(mat, c);
	for(int i = 0; i < 10000; ++i){
		for(int j = 0; j < n; ++j){ dp[i][j] = INF; }
		dp[i][n - 1] = 0;
	}
	for(int i = 9000; i >= 0; --i){
		for(int j = 0; j < n - 1; ++j){
			int as = INF, bs = INF, cs = INF;
			for(int k = 0; k < n; ++k){
				if(a_mat[j] & (1ull << k)){ as = min(as, dp[i + a][k]); }
				if(b_mat[j] & (1ull << k)){ bs = min(bs, dp[i + b][k]); }
				if(c_mat[j] & (1ull << k)){ cs = min(cs, dp[i + c][k]); }
			}
			dp[i][j] = max({ as, bs, cs }) + 1;
		}
	}
	const int answer = dp[0][0];
	if(answer >= INF){
		cout << "IMPOSSIBLE" << endl;
	}else{
		cout << answer << endl;
	}
	return 0;
}

Measured memory_bytes: 5184
use std::io::Read;

fn main() {
    let mut buf = String::new();
    std::io::stdin().read_to_string(&mut buf).unwrap();
    let mut iter = buf.split_whitespace();
    let n: usize = iter.next().unwrap().parse().unwrap();
    let d: Vec<i32> = (0..n)
        .map(|_| iter.next().unwrap().parse().unwrap())
        .collect();
    let s: i32 = d.iter().sum();
    let mut ans = s * s;
    for i in 0..n {
        ans -= d[i] * d[i];
    }
    println!("{}", ans / 2);
}


Measured memory_bytes: 4352
#include<iostream>
#include<cstdio>
#include<queue>
#include<cstring>
#include<algorithm>
#include<vector>
#include<map>
#include<sstream>
typedef long long LL;
using namespace std;
 
LL a[3010];
int main()
{
    int n;
    scanf("%d",&n);
    int s=0;
    for(int i=1;i<=n;i++)
        scanf("%lld",&a[i]),s+=a[i]-1;
 
    printf("%d\n",s);
    return 0;
}

Measured memory_bytes: 256
use proconio::input;

fn main() {
    input! {
        n: usize,
        w: [String; n],
    };
    let mut ok = true;
    let mut set = std::collections::BTreeSet::new();
    set.insert(&w[0]);
    let mut p = &w[0];
    for w_i in w.iter().skip(1) {
        if !set.insert(w_i) || p.chars().last() != w_i.chars().nth(0) {
            ok = false;
            break;
        }
        p = w_i;
    }
    let ans = ok;
    println!("{}", if ans { "Yes" } else { "No" });
}


Measured memory_bytes: 2176
#include <iostream>
#include <algorithm>
using namespace std;
#define MAX 20000

int main(void){
  int array[MAX],n,sum,ans;

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

    sort(array,array+n);    

    sum = 0;
    ans = 0;
    for(int i = 0 ; i < n ; i++){
      sum += array[i];
      ans += sum; 
    }
    cout << ans << endl;
  }

  return 0;
}

Measured memory_bytes: 1180
#pragma GCC optimize("Ofast,fast-math,unroll-loops")
 
#include <bits/stdc++.h>
 
#define int ll
//#define double long double
#define endl '\n'
#define all(C) (C).begin(), (C).end()
#define rall(C) (C).rbegin(), (C).rend()
#define mp make_pair 
#define pb emplace_back
#define dbg(x) cerr << #x << " : " << x << endl
//#define PI 3.141592653589
 
using namespace std;
        
using ll = long long;
using ull = unsigned long long;
using ld = long double;
using pii = pair <int, int>;
using pld = pair <ld, ld>;

/*
const ll MAX_MEM = 4e8;
char MEM[MAX_MEM];
ll MEM_POS = 0;
void* operator new(size_t x)
{
    auto ret = MEM + MEM_POS;
    MEM_POS += x;
    assert(MEM_POS < MAX_MEM);
    return ret;
}
void operator delete(void*)
{}
*/
        
template <class T>
istream& operator>> (istream &in, vector <T> &a)
{
    for (auto &i : a)
        in >> i;
    return in;
}
        
template <class T> 
ostream& operator<< (ostream &out, vector <T> a)
{
    for (auto &i : a)
        out << i << ' ';
    return out;
}
        
template <class T, class U>
istream& operator>> (istream &in, pair <T, U> &p)
{
    in >> p.first >> p.second;
    return in;
}
        
template <class T, class U>
ostream& operator<< (ostream &out, pair <T, U> p)
{
    out << p.first << " " << p.second << " ";
    return out;
}
        
inline void Start()
{
    ios_base::sync_with_stdio(0);
    cin.tie(0), cout.tie(0);
    //freopen("lol.in", "r", stdin);
    //freopen("lol.out", "w", stdout);
}

signed main()
{
    Start();
    stack <char> q;
    string s;
    cin >> s;
    for (auto &c : s)
    {
        if (c == 'S')
            q.emplace(c);
        else
        {
            if (!q.empty() && q.top() == 'S')
                q.pop();
            else
                q.emplace(c);
        }
    }
    cout << q.size();
    return 0;
}



Measured memory_bytes: 720
#define _GLIBCXX_DEBUG
#include <bits/stdc++.h>
#include <atcoder/all>
using namespace atcoder;
using namespace std;
#define REP(i,n) for(int i=0;i<n;i++)
#define RREP(i,n) for(int i=n-1;i>=0;i--)

int main(){
    int N,Q;
    cin>>N>>Q;
    dsu d(N);
    REP(i,Q){
        int t,u,v;
        cin>>t>>u>>v;
        if(!t){
            d.merge(u,v);
        }else{
            if(d.same(u,v)){
                cout<<1<<endl;
            }else{
                cout<<0<<endl;
            }
        }
    }
    }

Measured memory_bytes: 4036
#include<cstdio>
#include<iostream>
#include<cmath>
#include<cstring>
#include<algorithm>
#define ll long long
using namespace std;
int main()
{
    int a, b;
    string ans;
    cin>>a>>b;
    if(a == 1){
        if(b == 1){
            ans = "Draw";
        }
        else ans = "Alice";
    }
    else if(b == 1){
        if(a == 1){
            ans = "Draw";
        }
        else ans = "Bob";
    }
    else if(a > b)ans = "Alice";
    else if(a < b)ans = "Bob";
    else ans = "Draw";
    cout<<ans;


    return 0;
}


Measured memory_bytes: 256
#include<bits/stdc++.h>
using namespace std;
int main(){
long long int n;
  string str;
  cin>>n;
  cin>>str;
  if(str.length()<=n){
  cout<<str;
  }else if(str.length()>n){
  for(long long int i=0;i<n;i++){
  cout<<str[i];
  }cout<<"...";
  }
  
}

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

using namespace std;
template<class T1, class T2> inline void chkmin(T1 &x, const T2 &y) {if (x > y) x = y;}
template<class T1, class T2> inline void chkmax(T1 &x, const T2 &y) {if (x < y) x = y;}
#define all(c) (c).begin(), (c).end()
#define sz(c) (int)(c).size()
#define mp make_pair
#define pb push_back
#define read(FILENAME) freopen((string(FILENAME) + ".in").c_str(), "r", stdin)
#define write(FILENAME) freopen((string(FILENAME) + ".out").c_str(), "w", stdout);
const int Mod = 1000000007;
const int MAXN = 200228;

int sum(const int &a, const int &b) {
	return (a + b >= Mod ? a + b - Mod: a + b);
}


int mul(const int &a, const int &b) {
	return (1LL * a * b) % Mod;
}


int powm(int a, int b) {
	int res = 1;
	while (b) {
		if (b & 1) {
			res = mul(res, a);
		}
		b >>= 1;
		a = mul(a, a);
	}
	return res;
}


int n, a, b, c;
int fact[MAXN], rfact[MAXN];

int main() {
	ios_base::sync_with_stdio(false);
	cin.tie(0);
	cout.tie(0);
	//read("input");
	cin >> n >> a >> b >> c;
	fact[0] = 1;
	for (int i = 1; i < MAXN; i++) {
		fact[i] = mul(fact[i - 1], i);
	}
	for (int i = 0; i < MAXN; i++) {
		rfact[i] = powm(fact[i], Mod - 2);
	}
	int p = mul(a, powm(a + b, Mod - 2));
	int q = mul(b, powm(a + b, Mod - 2));
 	int ans = 0;
 	for (int m = n; m < 2 * n; m++) {
 		int cnk = mul(fact[m - 1], rfact[n - 1]);
 		cnk = mul(cnk, rfact[m - n]);
 		int A = mul(powm(p, n), powm(q, m - n));
 		int B = mul(powm(p, m - n), powm(q, n));
 		int C = mul(sum(A, B), m);
 		ans = sum(ans, mul(cnk, C));
 	}
 	ans = mul(ans, mul(100, powm(sum(a, b), Mod - 2)));
    cout << ans << '\n';
	return 0;
}


Measured memory_bytes: 1792
#include <cstdio>
#include <cstring>
#include <iostream>
using namespace std;
const int mod = 1000000007;
const int N = 100005;
char s[N];
int main(){
	cin>>s;
	int len  = strlen(s);
	int ans = 0;
	for (int i = 1;i < len; ++i){
		if (s[i] != s[i-1]) ans++;
	}
	printf("%d\n",ans);
	return 0;
}

Measured memory_bytes: 384
#include<bits/stdc++.h>
using namespace std;
int main(){
	int r,g,b,n;cin>>r>>g>>b>>n;
  long long num_ways=0;
  for(int i=0 ; i*r<=n;i++)
    for(int j=0;j*g<=n;j++){
    	if(n<(i*r+j*g))continue;
      else{
      	if((n-i*r-j*g)%b==0)num_ways++;
      }
    }
  cout<<num_ways;
}

Measured memory_bytes: 256
//  cout << char(i+48) << endl;//なぜかaは47と得る時がある。+48で出力もaにできる。
//  cout << char(97) << endl;//アスキーコードでaを出力
// sort(b.begin(), b.end());//bという配列を小さい方からソート
// reverse(b.begin(), b.end());//bという配列をリターン
// 10桁でdouble出力するパターン１ 
// printf("%.10f\n", ma);
// 10桁でdouble出力するパターン２
//cout << fixed << setprecision(10);
//  cout << ma << endl;

/*01 02 03 12 13 23　と６回見ていくパターン 
for(int i=0;i<n-1;i++){
  for(int j=i+1;j<n;j++){
    }
  }
*///vector<vector<int>> data(3, vector<int>(4));//int型の2次元配列(3×4要素の)の宣言
//int64_t a;
//10のi乗pow(10, i);
/*string s; stringでの文字列を数字型に変える方法
  cin >> s;
  rep(i,s.size()-2) {
  int a= (s.at(i)-'0')*100 + (s.at(i+1)-'0')*10+ s.at(i+2) -'0';
    */
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef unsigned long long ull;
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
int main() {
  ull a,b,x;
  cin >> a >> b >> x;
  if(a%x !=0 && b%x!=0){
   cout <<  (b / x + 1) - (a / x + 1) << endl;
  }
  else if(a%x !=0 && b%x==0){
   cout <<  (b / x + 1) - (a / x + 1) << endl;
  }
  else{
   cout << (b / x + 1 ) - (a / x + 1 ) + 1 << endl;
  }
}

Measured memory_bytes: 256
if __name__ == '__main__':
    N,C=list(map(int,input().split()))
    D=[list(map(int,input().split())) for i in range(C)]
    c=[list(map(int,input().split())) for i in range(N)]

    mode={0:{i:0 for i in range(C)},1:{i:0 for i in range(C)},2:{i:0 for i in range(C)}}

    for i in range(N):
        for j in range(N):
            mode[(i+j+2)%3][c[i][j]-1]+=1

    ans=1e10

    for i in range(C):
        for j in range(C):
            if i!=j:
                for k in range(C):
                    if i!=k and j!=k:
                        temp=0
                        for l in range(C):
                            temp+=D[l][i]*mode[0][l]
                            temp+=D[l][j]*mode[1][l]
                            temp+=D[l][k]*mode[2][l]
                        ans=min(ans,temp)

    print(ans)


Measured memory_bytes: 44892
import java.util.*;

public class Main{
    public static void main(String[] args){
	Scanner sc = new Scanner(System.in);
	int a = sc.nextInt();
    int b = sc.nextInt();
    int c = sc.nextInt();
    int d = sc.nextInt();
      boolean takahashi = true;
      while(a > 0 && c > 0){
        if(takahashi)
          c -= b;
        else
          a -= d;
        takahashi = !takahashi;    
      }
      if(takahashi)
        System.out.println("No");
      else
        System.out.println("Yes");
	}
}

Measured memory_bytes: 35608
#include<stdio.h>
#include<limits.h>
int m[110][110],p[100],N;
void ChainOrder();
int min(int ,int);
int main()
{
  
  int n,i;
  scanf("%d",&n);
  for(i=1;i<=n;i++){
    scanf("%d %d",&p[i],&p[i+1]);
  }
  N=i;
  ChainOrder();

 return 0;
}

void ChainOrder(){
  int l,n,i,k,j,q;
  n=N;
  for(i=1;i<=n;i++){
    m[i][i]=0;
  }
  for(l=2;l<=n;l++){
    for(i=1;i<=n-l+1;i++){
      j=i+l-1;
      m[i][j]=INT_MAX;
      for(k=i;k<=j-1;k++){
	q=m[i][k]+m[k+1][j] +p[i-1]*p[k]*p[j];
	m[i][j]=min(m[i][j],q);
      }
    }
  }
    printf("%d\n",m[i][j]);
}
int min(int m,int q){
  if(m<q)return m;
  else return q;
}

Measured memory_bytes: 640
#include <iostream>
#include <algorithm>
#include <vector>
#include <map>
#include <set>
#include <queue>
#include <iomanip>
using namespace std;
using i64 = int64_t;
#define rep(i, j, n) for(int i = (j); i < (n); ++i)
#define rrep(i, j, n) for(int i = (n) - 1; (j) <= i; --i)
constexpr i64 MOD = 1000000007;
constexpr i64 INF = 1LL << 60;

int main() {
	i64 n; cin >> n;

	vector<i64> cnt(n + 10);

	rep(i, 1, n + 1) {
			for (i64 j = i; j <= n; j += i) {
				cnt[j]++;
			}
	}

	i64 ans = 0;
	rep(i, 1, n + 1) {
		ans += i * cnt[i];
	}
	cout << ans;
	return 0;
}

Measured memory_bytes: 81396
#include <iostream>
#include <vector>
#include <algorithm>
#include <climits>

#define inf 1e9

int N;
int ma, mb;
int dp[41][401][401];
int a[41];
int b[41];
int c[41];

int mymin(int x, int y){
  if (x < y) return x;
  else return y;
}

int main(){
  std::cin >> N >> ma >> mb;
  std::fill(dp[0][0], dp[41][0], inf);

  int maxa = 0;
  int maxb = 0;
  for(int i = 1; i <= N; i++){
    std::cin >> a[i] >> b[i] >> c[i];
    if(a[i] > maxa) maxa = a[i];
    if(b[i] > maxb) maxb = b[i];
  }

  dp[0][0][0] = 0;
  for(int i = 1; i <= N; i++){
    for(int j = 0; j <= maxa*N; j++){
      for(int k = 0; k <= maxb*N; k++){
        if(j >= a[i] && k >= b[i]){
          dp[i][j][k] = mymin(dp[i-1][j][k], dp[i-1][j-a[i]][k-b[i]] + c[i]);
        }
        else{
          dp[i][j][k] = dp[i-1][j][k];
        }
      }
    }
  }

  int result = inf;
  for(int i = 1; i <= maxa*N/ma && i <= maxb*N/mb; i++){
    if(result > dp[N][i*ma][i*mb]){
      result = dp[N][i*ma][i*mb];
    }
  }

  if(result == inf) std::cout << -1 << std::endl;
  else std::cout << result << std::endl;


  return 0;
}


Measured memory_bytes: 25984
#include <iostream>
#include <algorithm>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <string.h>
#include <vector>
#include <queue>
#include <cmath>
#include <bitset>
#include <complex>
#include <functional>
#include <numeric>
#include <iomanip>

// output
#define SPBR(w, n) std::cout<<(w + 1 == n ? '\n' : ' ');
#define YES cout << "YES" << endl
#define Yes cout << "Yes" << endl
#define NO cout << "NO" << endl
#define No cout << "No" << endl
// utility
#define ALL(i) (i).begin(), (i).end()
#define FOR(i, a, n) for(int i=(a);i<(n);++i)
#define RFOR(i, a, n) for(int i=(n)-1;i>=(a);--i)
#define REP(i, n) for(int i=0;i<int(n);++i)
#define RREP(i, n) for(int i=int(n)-1;i>=0;--i)
#define IN(a, x, b) (a<=x && x<b)
#define OUT(a, x, b) (x<a || b<=x)
template<class T> inline T chmax(T & a, const T b) { return a = (a < b) ? b : a; }
template<class T> inline T chmin(T& a, const T b) { return a = (a > b) ? b : a; }

// type/const
#define int ll
using ll = long long;
using ull = unsigned long long;
using ld = long double;
const int MOD = 1000000007;
/* const int MOD = 998244353; */
const int INF = 1e18;
const double PI = acos(-1);

using namespace std;
struct INIT { INIT(){
  cin.tie(0); ios::sync_with_stdio(false);
  cout << fixed << setprecision(10);
}}INIT;

int N; 
vector<double> x(50), y(50);

double dist(int i, int j){
  return hypot(x[j]-x[i], y[j]-y[i]);
}

double mid;
bool f(double xx, double yy){
  REP(i, N){
    if(hypot(xx-x[i], yy-y[i]) > mid+1e-10) return false;
  }
  return true;
}

bool check(){
  bool flag = true;
  REP(i, N){
    FOR(j, i+1, N){
      if(dist(i, j) > mid*2+1e-10) continue;
      double d = sqrt(mid*mid-dist(i, j)*(dist(i, j))/4);
      double mx = (x[i]+x[j])/2;
      double my = (y[i]+y[j])/2;
      double px = (y[i]-y[j])/dist(i, j)*d;
      double py = -(x[i]-x[j])/dist(i, j)*d;
      if(f(mx+px, my+py)) return true;
      if(f(mx-px, my-py)) return true;
      flag = false;
    }
  }
  return false;
}

signed main() {
  cin >> N;

  REP(i, N) cin >> x[i] >> y[i];

  double ok = 4000;
  double ng = 0;
  REP(i, 50){
    mid = (ok+ng)/2;
    if(check()) ok = mid;
    else ng = mid;
  }

  cout << ok << "\n";

  return 0;
}

Measured memory_bytes: 384
import java.util.Scanner;


public class Main {
	
       public static void main(String[] args) {
    	  Scanner input=new Scanner( System.in);
    	  
    	  String string=input.next();
    	  int ans=0;
    	  for(int i=0;i<string.length()-1;i++)
    	  {
    		  if(string.charAt(i)!=string.charAt(i+1))
    		  {
    			  ans++;
    		  }
    	  }
    	  System.out.println(ans);
          
	}
}


Measured memory_bytes: 25812
let h, w, d, ps, ts = Array.(Scanf.scanf "%d %d %d" @@ fun h w d -> h, w, d, make (h * w) (0, 0), make (h * w) 0)
let lrs = Scanf.(for i = 0 to h - 1 do for j = 0 to w - 1 do ps.(scanf " %d" pred) <- i, j done done; scanf " %d" @@ fun q -> Array.init q @@ fun _ -> scanf " %d %d" @@ fun a b -> a - 1, b - 1)
let f a b = let (i, j), (k, l) = ps.(a), ps.(b) in abs (i - k) + abs (j - l)
let _ = for i = d to h * w - 1 do ts.(i) <- ts.(i - d) + f (i - d) i done; Array.iter (fun (l, r) -> Printf.printf "%d\n" @@ ts.(r) - ts.(l)) lrs

Measured memory_bytes: 10880
#include<iostream>
#include<cstdio>
#include<cstring>
#include<algorithm>
#include<cmath>
#include<queue>
#define maxn 100010
using namespace std;
int read()
{
    int x=0,f=1;
    char ch=getchar();
    while(ch-'0'<0||ch-'0'>9){if(ch=='-') f=-1;ch=getchar();}
    while(ch-'0'>=0&&ch-'0'<=9){x=x*10+ch-'0';ch=getchar();}
    return x*f;
}
int n,K,ans;
int head[maxn],nxt[maxn],to[maxn],tot;
void add(int u,int v)
{
    tot++;
    nxt[tot]=head[u];
    head[u]=tot;
    to[tot]=v;
}
int dep[maxn];
void dfs(int x,int las)
{
    for(int i=head[x];i;i=nxt[i])
    {
        dfs(to[i],x);
        dep[x]=max(dep[x],dep[to[i]]);
    }
    dep[x]++;
    if(dep[x]==K&&las!=1)  ans++,dep[x]=0;
}
int main()
{
    n=read();K=read();
    for(int i=1;i<=n;i++)
    {
        int x=read();
        if(i==1)  ans+=(x!=1);
        else{
            add(x,i);
        }
    }
    for(int i=head[1];i;i=nxt[i])  dfs(to[i],1);
    cout<<ans<<endl;
    return 0;
}

Measured memory_bytes: 6528
#!/usr/bin/env python
# -*- coding: utf-8 -*-


def solve(inp):
    (N, A, B) = map(int, inp.readline().strip().split(' '))

    a = int(N / (A + B)) * A
    r = N % (A + B)
    if r <= A:
        a += r
    else:
        a += A

    return str(a)


def main():
    import sys
    result = solve(sys.stdin)
    if result is not None and result != '':
        print(result)


if __name__ == '__main__':
    main()


Measured memory_bytes: 3060
#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++)
typedef long long ll;

int main() {
    string A, B;
    cin >> A >> B;
    bool flag = true;
    if (A.length() > B.length()){
        cout << "GREATER" << endl;
    }
    else if (A.length() < B.length()){
        cout << "LESS" << endl;
    }
    else{
        for (int i = 0; i < A.length(); i++){
            if(A[i] > B[i]){
                cout << "GREATER" << endl;
                flag = false;
                break;
            }
            else if (A[i] < B[i]){
                cout << "LESS" << endl;
                flag = false;
                break;
            }
        }
        if (flag){
            cout << "EQUAL" << endl;
        }
    }
}


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

inline int read()
{
	int x=0,f=1; char ch=getchar();
	while(ch<'0'||ch>'9'){if(ch=='-')f=-1; ch=getchar();}
	while(ch>='0'&&ch<='9'){x=x*10+ch-'0'; ch=getchar();}
	return x*f;
}
inline int qpow(int bas,int pw)
{
	int ret=1; for(;pw;pw>>=1,bas=1ll*bas*bas%mod)
	if(pw&1) ret=1ll*ret*bas%mod; return ret;
}
inline void Add(int &x,int y)
{
	x+=y; if(x>=mod) x-=mod;
	if(x<0) x+=mod;
}
int n,a,b,c,d,fac[2010],inv[2010],F[2010],G[2010],Ans;
int main()
{
	n=read(); a=read(); b=read(); c=read(); d=read();
	fac[0]=1; for(int i=1;i<=1000;i++) fac[i]=1ll*fac[i-1]*i%mod;
	for(int i=0;i<=1000;i++) inv[i]=qpow(fac[i],mod-2);
	F[0]=1; for(int i=a;i<=b;i++)
	{
		memset(G,0,sizeof G);
		for(int j=c;j<=d;j++) if(j*i<=n)
		{
			for(int k=n;k>=j*i;k--)
				Add(G[k],1ll*F[k-j*i]*qpow(inv[i],j)%mod*inv[j]%mod);
		}
		for(int j=1;j<=n;j++) Add(F[j],G[j]);
	}
	cout << 1ll*fac[n]*F[n]%mod << endl;
	return 0;
}

Measured memory_bytes: 256
n = int(input())
l = list(map(int,input().split()))
ans = 1
t = 1
if n == 1:
  if l[0] == 0:
    print(1)
  else:
    print(0)
 
elif n == 2:
  if l[0] ==0 and l[1] == 1:
    print(1)
  else:
    print(0)
 
else:
  if l[0] != 0:
    print(0)
  else:
    a = [0]*n
    for i in range(n):
      a[l[i]] += 1
 
    if a[0] != 1:
      print(0)
    else:
      for i in range(n-1):
        if a[i]==0 and a[i+1]!=0:
          t = 0
          
        elif a[i]!=0 and a[i+1]!=0:
          ans = ans * (a[i]**a[i+1])
      if t == 1:
        print(ans%998244353)
      else:
        print(0)

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

W = [int(x) for x in input().split()]
TOTAL=sum(W)
TARGET=TOTAL/2
X=0

for i in range(N-1):
    X+=W[i]
    if X >= TARGET:
        ans=min(abs(TOTAL-2*X),abs(TOTAL-2*(X-W[i])))
        break
    
print(ans)

Measured memory_bytes: 3064
#include<bits/stdc++.h> 
#include <ext/pb_ds/assoc_container.hpp> 
#include <ext/pb_ds/tree_policy.hpp> 
using namespace std;
using namespace __gnu_pbds;  
#define ordered_set tree<ll, null_type , less<ll> , rb_tree_tag , tree_order_statistics_node_update> 
#define ll long long
#define ull unsigned long long
#define pb push_back
#define inf 1e18
#define mk make_pair
#define ld long double
#define mod 1000000007
#define fi first
#define se second
#define fastIO ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0)
#define test ll t; cin>>t; while(t--)
#define setbits __builtin_popcount
#define endl '\n'
#define LOCAL
#define sim template < class c
#define ris return * this
#define dor > debug & operator <<
#define eni(x) sim > typename \
enable_if<sizeof dud<c>(0) x 1, debug&>::type operator<<(c i) {
sim > struct rge { c b, e; };
sim > rge<c> range(c i, c j) { return rge<c>{i, j}; }
sim > auto dud(c* x) -> decltype(cerr << *x, 0);
sim > char dud(...);
struct debug {
#ifdef LOCAL
~debug() { cerr << endl; }
eni(!=) cerr << boolalpha << i; ris; }
eni(==) ris << range(begin(i), end(i));}
sim, class b dor(pair < b, c > d) {
    ris << "(" << d.first << ", " << d.second << ")";
}
sim dor(rge<c> d) {
    *this << "[";
    for (auto it = d.b; it != d.e; ++it)
        *this << ", " + 2 * (it == d.b) << *it;
    ris << "]";
}
#else
sim dor(const c&) { ris; }
#endif
};
#define imie(...) " [" << #__VA_ARGS__ ": " << (__VA_ARGS__) << "] "
int main()
{
    fastIO;
    ll n,k;
    cin>>n>>k;
    ll x,y,val,val1;
    if(n%k==0)
    {
        cout<<0<<endl;
    }
    else
    {
        x=n/k;
        y=n-(x*k);
        x=(n+k-1)/k;
        val=x*k-n;
        val1=min(val,y);
        cout<<val1<<endl;
    }
}

Measured memory_bytes: 256