akhauriyash/Code-Regression huggingface dataset:
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>

using lint = long long;

int main() {
    int n;
    std::string s;
    std::cin >> n >> s;

    std::vector<lint> dsum(n + 1, 0), msum(n + 1, 0), dmsum(n + 1, 0);
    std::vector<int> cpos;
    for (int i = 1; i <= n; ++i) {
        char c = s[i - 1];
        dsum[i] = dsum[i - 1];
        msum[i] = msum[i - 1];
        dmsum[i] = dmsum[i - 1];

        if (c == 'D') {
            ++dsum[i];
        } else if (c == 'M') {
            ++msum[i];
            dmsum[i] += dsum[i];
        } else if (c == 'C') {
            cpos.push_back(i);
        }
    }

    int q;
    std::cin >> q;
    for (int p = 0; p < q; ++p) {
        int k;
        std::cin >> k;
        lint ans = 0;
        for (auto i : cpos) {
            int l = std::max(0, i - k);
            ans += (dmsum[i] - dmsum[l]) -
                   (msum[i] - msum[l]) * dsum[l];
        }
        std::cout << ans << std::endl;
    }
    return 0;
}


Measured memory_bytes: 30972
solve :: Int -> Int -> [Int] -> [Int] -> [Int]
solve 0 _ _ _ = []
solve c n as bs = a + b : solve (c - 1) n as bs
  where a = sum $ take c as
        b = sum $ drop (c - 1) bs

main :: IO ()
main = do
  n <- readLn
  as <- map read . words <$> getLine
  bs <- map read . words <$> getLine
  print . maximum $ solve n n as bs

Measured memory_bytes: 1020
keynum = int(input())
for i in range(1,keynum+1):
    if i%3 ==0 or i%10 ==3 :
        print(" "+str(i),end ="")
    else:        
        j = i
        while True:
            if j%10 == 3 :
                print(" "+str(i),end ="")
                break
            else:
                j = j//10
                if j == 0:
                    break

print()


Measured memory_bytes: 5868
#include <iostream>
#include <cmath>
#include <set>
using namespace std;

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

    int count = 0;
    for (int i = 1; i <= N; i += 2) {
        int divCount = 0;
        int d;
        for (d = 1; pow(d, 2) < i; d++) {
            if (i % d == 0) {
                divCount += 2;
            }
        }

        if (pow(d, 2) == i) {
            divCount++;
        }
        
        if (divCount == 8) {
            count++;
        }
    }

    cout << count << endl;
    
}

Measured memory_bytes: 888
n=int(raw_input())
N=map(int,raw_input().split())
d={}
for i in N:
    d[i]=0
for i in N:
    d[i]+=1
res=res2=res3=0
for i in N:
    if d[i]>=2:
        res=max(res,i)
for i in N:
    if d[i]>=2 and i!=res:
        res2=max(res2,i)
for i in N:
    if d[i]>=4:
        res3=max(res3,i)
print max(res*res2,res3*res3)

Measured memory_bytes: 16088
#include <stdio.h>          // printf(), scanf()
#include <stdlib.h>         // qsort()
#include <math.h>           // fabs()
#include <stdbool.h>

#define MAX_N 1000

typedef struct rbmi_tbl
{
	int p;
	double rbmi;
} rbmi_t;

int
cmp_func(const void *l_, const void *r_)
{
	const rbmi_t *l = (const rbmi_t*) l_;
	const rbmi_t *r = (const rbmi_t*) r_;

	if (l->rbmi < r->rbmi)
		return -1;

	if (l->rbmi > r->rbmi)
		return 1;

	if (l->p < r->p)
		return -1;

	if (l->p > r->p)
		return 1;

	return 0;
}

int
main(int argc, char **argv)
{
	int n;
	rbmi_t rbmi[MAX_N];
	int h, w;

	while (true)
	{
		scanf("%d", &n);
		if (n == 0)
			break;

		for (int i = 0; i < n; ++i)
		{
			scanf("%d%d%d", &rbmi[i].p, &h, &w);
			double m = h / 100.0;
			rbmi[i].rbmi = fabs(w / (m * m) - 22.0);
		}

		qsort(rbmi, n, sizeof(rbmi_t), cmp_func);
		printf("%d\n", rbmi[0].p);
	}

	return 0;
}


Measured memory_bytes: 1832
N = int(input())
A = list(map(int, input().split()))


T = [None] * N

c = 0

from functools import reduce

def check():
    def f(a, b):
        return a * b

    global c
    r = reduce(f, T)
    # print(T, r)
    if r % 2 == 0:
        c += 1


def dfs(pos):
    if pos == N:
        check()
        return

    T[pos] = A[pos] - 1
    dfs(pos+1)

    T[pos] = A[pos]
    dfs(pos+1)

    T[pos] = A[pos] + 1
    dfs(pos+1)

dfs(0)

print(c)

Measured memory_bytes: 3572
import sys

input = sys.stdin.buffer.readline
in_n = lambda: int(input())
in_nn = lambda: map(int, input().split())
in_s = lambda: input().rstrip().decode('utf-8')
in_map = lambda: [s == ord('.') for s in input() if s != ord('\n')]

MOD = 10**9 + 7
INF = 8 * 10**18


def main():

    x = in_n()

    dp = [False] * 1100
    dp[1] = True

    for i in range(2, 110):
        for j in range(2, 20):
            now = i**j
            if now <= 1000:
                dp[now] = True
            else:
                break

    for i in range(x, 0, -1):
        if dp[i]:
            print(i)
            break


if __name__ == '__main__':
    main()


Measured memory_bytes: 9180
#include <iostream>
#include <vector>
#include <unordered_map>
#include <deque>
#include <list>
#include <set>
#include <random>
#include <deque>

using namespace std;
using ll = long long;
const int BIG = 100000007;


int main() {
    ll x;
    cin >> x;
    cout << (1999 - x) / 200 + 1 << endl;
}




Measured memory_bytes: 3192
/*input

*/
#include <bits/stdc++.h>
#define up(i,a,b) for(int (i) = (a);(i)<=(b);++(i))
#define down(i,b,a) for(int (i) = (b);i>=(a);--i)
#define debug(x) cerr << (x) << '\n';
#define bits(x,i) ((x >> i) & 1)
#define mid ((l+r)/2)
#define pr pair<int,int>
using namespace std;
const int N = 105;
pr p[N];
int n;
bool angle(pr a, pr b){
	return atan2(a.first, a.second) < atan2(b.first, b.second);
}
int main(){
	ios_base::sync_with_stdio(0); cin.tie(0);
	cin >> n;
	for(int i=0;i<n;++i) cin >> p[i].first >> p[i].second;
	sort(p, p+n, angle);
	long long ans = 0;
	for(int i=0;i<n;++i){
		long long curX = 0, curY = 0;
		for(int j=0;j<n;++j){
			int pi = (i + j) % n;
			curX += p[pi].first;
			curY += p[pi].second;
			ans = max(ans, curX * curX + curY * curY);
		}
	}
	// cout << ans << '\n';
	cout << setprecision(15) << sqrt(ans);
}


Measured memory_bytes: 4168
n = int(input())
d = list(map(int,input().split()))

ans = 1
if d[0] == 0 and d.count(0) == 1:
    l = [0 for i in range(10**5+10)]
    for i in range(n):
        l[d[i]] += 1
    
    count = l[0] + l[1]
    for i in range(2,10**5+10):
        if l[i] == 0:
            break
        else:
            ans = ans * l[i-1]**l[i]
   #         print(l[i-1]**l[i],ans)
            count += l[i]
    if count != n:
        ans = 0
    print(ans%998244353)
    
else:
    print(0)

Measured memory_bytes: 56280
#[allow(unused_imports)]
use std::cmp::*;
#[allow(unused_imports)]
use std::collections::*;
use std::io::{Write, BufWriter};
// https://qiita.com/tanakh/items/0ba42c7ca36cd29d0ac8
macro_rules! input {
    ($($r:tt)*) => {
        let stdin = std::io::stdin();
        let mut bytes = std::io::Read::bytes(std::io::BufReader::new(stdin.lock()));
        let mut next = move || -> String{
            bytes
                .by_ref()
                .map(|r|r.unwrap() as char)
                .skip_while(|c|c.is_whitespace())
                .take_while(|c|!c.is_whitespace())
                .collect()
        };
        input_inner!{next, $($r)*}
    };
}

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

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

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

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

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

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

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

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

#[allow(unused)]
macro_rules! debug {
    ($($format:tt)*) => (write!(std::io::stderr(), $($format)*).unwrap());
}
#[allow(unused)]
macro_rules! debugln {
    ($($format:tt)*) => (writeln!(std::io::stderr(), $($format)*).unwrap());
}

fn solve() {
    let out = std::io::stdout();
    let mut out = BufWriter::new(out.lock());
    macro_rules! puts {
        ($($format:tt)*) => (let _ = write!(out,$($format)*););
    }
    input! {
        n: usize,
        ab: [(i64, i64); n],
    }
    let mut a: Vec<i64> = ab.iter().map(|&(a, _)| a).collect();
    let mut b: Vec<i64> = ab.iter().map(|&(_, b)| b).collect();
    a.sort(); b.sort();
    if n % 2 == 0 {
        puts!("{}\n", b [n / 2 - 1] + b[n / 2] - a[n / 2 - 1] - a[n / 2] + 1);
    } else {
        puts!("{}\n", b[n / 2] - a[n / 2] + 1);
    }
}

fn main() {
    // In order to avoid potential stack overflow, spawn a new thread.
    let stack_size = 104_857_600; // 100 MB
    let thd = std::thread::Builder::new().stack_size(stack_size);
    thd.spawn(|| solve()).unwrap().join().unwrap();
}


Measured memory_bytes: 7952
#include<bits/stdc++.h>
using namespace std;
typedef long long ll;
typedef double db;
#define pb push_back
#define IOS ios::sync_with_stdio(false); cin.tie(0); cout.tie(0)



int main()
{
	ios::sync_with_stdio(false);
	int a;
	cin>>a;
	cout<<a+a*a+a*a*a;
	return 0;
}




Measured memory_bytes: 3652
import java.util.*;

public class Main {
    public static void main(String[] args) {
        Scanner sc = new Scanner(System.in);
        String s = sc.next();
        String t = sc.next();
        int ans = 0;
        for (int i = 0; i < 3; i++) {
            if (s.charAt(i) == t.charAt(i))
                ans++;
        }
        System.out.println(ans);
    }
}

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

int main() {
  int m, k;
  cin >> m >> k;
  if (k >= (1 << m) || (m == 1 && k == 1)) {
    cout << -1 << endl;
    return 0;
  }
  if (m == 1) {
    puts("0 0 1 1");
    return 0;
  }
  for (int i = 0; i < (1 << m); i++) {
    if (i == k) continue;
    cout << i << " ";
  }
  cout << k << " ";
  for (int i = (1 << m) - 1; i >= 0; i--) {
    if (i == k) continue;
    cout << i << " ";
  }
  cout << k << endl;
}


Measured memory_bytes: 1792
def f(p, q):
    if q < p:
        return q
    else:
        return f(p, q//p) + q%p

n = int(input())
s = int(input())
flag = 0
if n < s:
    print(-1)
    flag = 1
if flag == 0 and n == s:
    print(n+1)
    flag = 1
if flag == 0:
    for i in range(2, int(n**0.5)+2):
        if f(i, n) == s:
            print(i)
            flag = 1
            break
if flag == 0:
    for i in range(int(n**0.5), 0, -1):
        if (n-s)%i == 0:
            if f((n-s)//i+1, n) == s:
                print((n-s)//i+1)
                flag = 1
                break

if flag == 0:
    print(-1)

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


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

  int x;
  x = N*100/108;
  
  int M;
  M = x*108/100;
  
  int L;
  L = (x+1)*108/100;
  
  if(M==N){ 
  cout << x << endl;
  }
  else if(L==N){
    cout << x+1 << endl;
  }
  else {
    cout << ":(" << endl;
  }
      
  return 0;
}



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

int main(){

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


    if(n <= k){
        cout << "unsafe" << endl;
    }else{
        cout << "safe" << endl;
    }
    
    
    return 0;
}


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

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

#[allow(dead_code)]
struct Main {}

#[allow(dead_code)]
impl Main {}

fn main() {
    let a = read::<i64>();
    let b = read::<i64>();
    let _c = read::<i64>();
    let k = read::<i64>();
    let mut cnt = k;
    let mut res = 0;
    cnt -= a;
    if cnt <= 0 {
        res = k;
        println!("{}", res);
        return;
    }
    res += a;
    cnt -= b;
    if cnt <= 0 {
        println!("{}", res);
        return;
    }
    res -= cnt;
    println!("{}", res);
}


Measured memory_bytes: 2116
A, B, M = map(int, input().split())
a = list(map(int, input().split()))
b = list(map(int, input().split()))
m = []
for i in range(M):
  x = list(map(int, input().split()))
  m.append(x)
a_min = min(a)
b_min = min(b)
s_min = a_min + b_min
for i in range(M):
  if a[m[i][0]-1] + b[m[i][1]-1] - m[i][2] < s_min:
    s_min = a[m[i][0]-1] + b[m[i][1]-1] - m[i][2]
print(s_min)

Measured memory_bytes: 38500
#include<bits/stdc++.h>
#define mins(a,b) a=min(a,b)
#define maxs(a,b) a=max(a,b)
using namespace std;

const long long INF=9000000000000000;
int main(){
  long long n,a=0,b=0,x=1;
  cin>>n;
  long long num[n];
  long long ok[100010]={};
  for(int i=0;i<n;i++){
    cin>>num[i];
  }
  sort(num,num+n);
  for(int i=0;i<n;i++){
    if(num[x]==num[x-1]){
      ok[x]=num[x];
      x++;
    }
    x++;
    if(x>=100010)
      break;
  }
  sort(ok,ok+n);
  reverse(ok,ok+n);
  cout<<ok[0]*ok[1]<<endl;
}

Measured memory_bytes: 1792
#include <iostream>
#include <cstdio>
using namespace std;
int main(void) {
  int n;
  int rn[100000];
  unsigned long long ave=0;

  cin >> n;
  for(int i = 0 ; i < n ; i++) {
    cin >> rn[i];
    ave += rn[i];
  }
  ave /= n;
  cout << ave << endl;
  return 0;
}

Measured memory_bytes: 0
#include<cstdio>
#include<vector>
#include<algorithm>
#include<map>

using namespace std;

using ll=long long;
using vi=vector<int>;
using vvi=vector<vi>;
using pii=pair<int,int>;
using vll=vector<ll>;
using vvll=vector<vll>;
using vpii=vector<pii>;

//るので、 998244353 で割った余り
using ll=long long;

class mod_ll
{
public:
	ll m_v;
	ll m_m; // prime value ex. 1000000009
	mod_ll(ll m=998244353, ll v=0) : m_v(v), m_m(m)
	{
	}
	mod_ll operator = (ll rhs)
	{
		m_v=rhs%m_m;
		return *this;
	}
	mod_ll operator = (mod_ll rhs)
	{
		m_v=rhs.m_v;
		m_m=rhs.m_m;
		return *this;
	}
	mod_ll operator += (ll rhs)
	{
		m_v=(m_v+rhs)%m_m;
		return *this;
	}
	mod_ll operator += (mod_ll rhs)
	{
		if(m_m!=rhs.m_m) throw;
		m_v=(m_v+rhs.m_v)%m_m;
		return *this;
	}
	mod_ll operator + (mod_ll rhs)
	{
		auto ret=*this;
		return ret+=rhs;
	}
	mod_ll operator *= (ll rhs)
	{
		m_v=(m_v*rhs)%m_m;
		return *this;
	}
	mod_ll operator *= (mod_ll rhs)
	{
		if(m_m!=rhs.m_m) throw;
		m_v=(m_v*rhs.m_v)%m_m;
		return *this;
	}
	mod_ll operator * (mod_ll rhs)
	{
		mod_ll ret=*this;
		return ret*=rhs;
	}
	mod_ll operator ^ (ll rhs)
	{
		mod_ll t=*this;
		mod_ll ret(m_m, 1LL);

		for(;rhs>0;rhs>>=1)
		{
			if(rhs&1) ret*=t;
			t*=t;
		}
		return ret;
	}
	mod_ll operator /= (mod_ll rhs)
	{
		if(m_m!=rhs.m_m) throw;
		return *this*=(rhs^(m_m-2));
	}
	mod_ll operator /= (ll rhs)
	{
		mod_ll t(m_m, rhs);
		return *this/=t;
	}
	mod_ll operator / (mod_ll rhs)
	{
		mod_ll ret=*this;
		return ret/=rhs;
	}
};

mod_ll mod_nPr(int n, int r, ll m)
{
	mod_ll ret(m, 1);

	for(int i=0;i<r;i++)
	{
		ret*=(n-i);
	}
	return ret;
}


mod_ll mod_fact(int x)
{
	static vector<mod_ll> memo(1, mod_ll(998244353, 1));

	if(x>=memo.size())
	{
		if(memo.size()==1)
		{
			memo.reserve(200010);
		}
		mod_ll ret=memo.back();
		for(int i=memo.size();i<=x;i++)
		{
			ret*=i;
			memo.push_back(ret);
		}
	}
	return memo[x];
}


mod_ll mod_nCr(int n, int r)
{
	mod_ll bunsi=mod_fact(n);
	mod_ll bunbo=mod_fact(n-r)*mod_fact(r);
	return bunsi/bunbo;
}


int main(void)
{
	int n, m, k;

	while(scanf("%d%d%d", &n, &m, &k)==3)
	{
		mod_ll u;
		mod_ll ans;

		u=m;
		ans=0;
		for(int t=1;t<=n;t++)
		{
			if(t>=n-k)
			{
				ans+=u*mod_nCr(n-1, n-t);
			}
			u*=m-1;
		}
		printf("%lld\n", ans.m_v);
	}
	return 0;
}


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

using namespace std;

typedef long long ll;
typedef unsigned long long ull;
typedef vector<int> vi;
typedef vector<ll> vl;
typedef pair<int, int> pii;
typedef pair<ll, ll> pll;

#define REP(i, n) for(int i=0; i<(n); ++i)
#define FOR(i, a, b) for(int i=(a); i<(b); ++i)
#define FORR(i, a, b) for(int i=(b)-1; i>=(a); --i)

#define DEBUG(x) cout<<#x<<": "<<(x)<<'\n'
#define DEBUG_VEC(v) cout<<#v<<":";REP(i, v.size())cout<<' '<<v[i];cout<<'\n'
#define ALL(a) (a).begin(), (a).end()

template<typename T> inline void CHMAX(T& a, const T b) {if(a<b) a=b;}
template<typename T> inline void CHMIN(T& a, const T b) {if(a>b) a=b;}

constexpr ll MOD=1000000007ll;
// constexpr ll MOD=998244353ll;
#define FIX(a) ((a)%MOD+MOD)%MOD

const double EPS=1e-11;
#define EQ0(x) (abs((x))<EPS)
#define EQ(a, b) (abs((a)-(b))<EPS)

pll sum[252521];

int main(){
  ios::sync_with_stdio(false);
  cin.tie(0);
  // cout<<setprecision(10)<<fixed;
  int n;
  ll k, a[252521];
  cin>>n>>k;
  sum[0]=pll(0, 0);
  REP(i, n){
    cin>>a[i];
    sum[i+1]=pll((sum[i].first+a[i])%k, i+1);
  }
  REP(i, n){
    sum[i+1].first-=(i+1)%k;
    while(sum[i+1].first<0){
      sum[i+1].first+=k;
    }
  }
  sort(sum, sum+n+1);
  // FOR(i, 0, n+1){
  //   cout<<sum[i].first<<" \n"[i==n];
  // }
  ll ans=0;
  int r=0;
  REP(i, n){
		ll cnt=0;
    while(r<n+1 && sum[i].first==sum[r].first && sum[r].second-sum[i].second<k){
      ++r;
    }
		if(r!=i){
      ans+=r-i-1;
      // cout<<i<<' '<<r<<'\n';
      // DEBUG(ans);
    }
	}
  cout<<ans<<'\n';
  return 0;
}


Measured memory_bytes: 4992
#include "bits/stdc++.h"
#define ALL(x) x.begin(), x.end()
#define iostreamBooster() do{ cin.tie(nullptr); ios_base::sync_with_stdio(false); }while(0)
#define rep(i, s, n) for(i64 i=(s); i < (n); ++i)
using namespace std;
using i64 = long long;
using pii = pair<int, int>;
template<class A, class B>inline bool chmax(A &a, const B &b){return b>a ? a=b,1 : 0;}
template<class A, class B>inline bool chmin(A &a, const B &b){return b<a ? a=b,1 : 0;}
constexpr int INF  = 0x3f3f3f3f;
constexpr i64 LINF = 0x3f3f3f3f3f3f3f3fLL;
constexpr int MOD  = int(1e9) + 7;

int N;
int a[105];
int dp[105][10005];

int slv(int k, int sum)
{
  if (k >= N) {
    return (sum % 10) ? sum : 0;
  }

  if (~dp[k][sum]) return dp[k][sum];

  return dp[k][sum] =
    max(slv(k+1, sum), slv(k+1, sum + a[k]));
}

signed main()
{
  cin >> N;
  rep(i, 0, N) cin >> a[i];

  memset(dp, -1, sizeof(dp));

  cout << slv(0, 0) << endl;

  return 0;
}



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


int main() {

    ll n , i,m ;

    cin >> n >> m ;
    ll ans = 0 ;
    for(i=1;i<n;i++)
        ans+=i ;
    for(i=1;i<m;i++)
        ans+=i ;

    cout << ans << endl ;


}


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

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

  int n; cin >> n;
  vector<int> arr(n);

  for (int i = 0; i < n; ++i) cin >> arr[i];

  bool visited[n];
  memset(visited, false, sizeof(visited));

  int buttons_pressed = 0;
  queue<int> q({1});
  while (!q.empty() && !visited[q.front() - 1]) {
    int current_button = q.front(); q.pop();
    int next_button = arr[current_button - 1];
    buttons_pressed++;

    if (next_button == 2) {
      cout << buttons_pressed << "\n";
      return 0;
    }

    visited[current_button - 1] = true;
    q.push(next_button);
  }
  cout << -1 << "\n";
}


Measured memory_bytes: 3764
#include <bits/stdc++.h> 
#define ll long long
#define ull unsigned long long
#define endl '\n'
#define pb push_back
#define mp make_pair
#define sp(x) fixed<<setprecision(x)
#define fast_io ios_base::sync_with_stdio(false);cin.tie(NULL);cout.tie(NULL);
using namespace std;

const ll mod = 1e9 + 7;
//const int scope = 100005;
char k[100005];

void add_store(int &a, int b)
{
    (a += b) %= mod;
    
}

int main()
{
    fast_io;
    
    int D;
    cin>>k>>D;
    int length = strlen(k);
    
    vector< vector<int>> dp (D, vector<int> (2));
    dp[0][0] = 1;
    
    for(int pos=0;pos<length;pos++)
    {
        vector< vector<int>> dp1(D, vector<int>(2));
        for(int sum=0;sum<D;sum++)
        {
            for( bool small : {false,true})
            {
                for(int dig=0;dig<=9;dig++)
                {
                    
                    if(dig > pos[k]-'0' && small == false)
                    break;
                    
                    add_store( dp1[(sum+dig)%D][small || dig < pos[k]-'0'], dp[sum][small]);
                }
            }
        }
        dp = dp1;
    }
    
    int ans = dp[0][true] + dp[0][false];
    int res = (ans%mod)-1;
    
    //res =0 ? cout<<res : cout<<0;
 // res == -1 ? cout<<mod-1 : cout<<res;
 cout<<( mod + ans - 1)%mod;
    cout<<endl;
    return 0;
}


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

int main(){
    int n,m,k;
    cin>>n>>m>>k;
    for(int i=0;i<=n;i++){
        for(int j=0;j<=m;j++){
            if(i*(m-j)+j*(n-i)==k){
                cout<<"Yes"<<endl;
                return 0;
            }
        }
    }
    cout<<"No"<<endl;
}

Measured memory_bytes: 3632
#include <bits/stdc++.h>
using namespace std;
int main()
{
    unsigned long long int a, b, n;
    cin >> a >> b >> n;

    if(b > n) cout << a * n / b << endl;
    else {
        unsigned long long int num1 = a * n / b - a * (unsigned long long int)(n / b);
        unsigned long long int num2 = (a * (b - 1)) / b;
        if(num1 > num2) cout << num1 << endl;
        else cout << num2 << endl;
    }

    return 0;
}

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

using namespace std;
#define inf             0x3f3f3f3f
#define INF             2e18
#define eps             1e-9

#define FastRead        ios_base::sync_with_stdio(0);cin.tie(0)
#define fRead           freopen("input.txt","r",stdin)
#define fWrite          freopen("output.txt","w",stdout)

#define LL              long long
#define ull            unsigned long long
#define PI              acos(-1.0)
#define pb              push_back
#define mk              make_pair
#define pii             pair<int,int>
#define pLL             pair<LL,LL>
#define ff              first
#define ss              second
#define all(a)          a.begin(),a.end()
#define SQR(a)          ((a)*(a))
#define min3(a,b,c)     min(a,min(b,c))
#define max3(a,b,c)     max(a,max(b,c))
#define min4(a,b,c,d)   min(min(a,b),min(c,d))
#define max4(a,b,c,d)   max(max(a,b),max(c,d))
#define max5(a,b,c,d,e) max(max3(a,b,c),max(d,e))
#define min5(a,b,c,d,e) min(min3(a,b,c),min(d,e))
#define vi              vector <int>
#define vL              vector <LL>
#define LB(a,x)         (lower_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which does not compare less than val.
#define UB(a,x)         (upper_bound(all(a),x)-a.begin()) //  first element in the range [first,last) which compares greater than val.
#define prec(n)         fixed << setprecision(n)

#define MEM(a,x)        memset(a,x,sizeof(a))
#define SORT(v)         sort(v.begin(),v.end())
#define REV(v)          reverse(v.begin(),v.end())
#define Unique(a)       sort(all(a)),a.erase(unique(all(a)),a.end())

#define FOR(i,a,b)      for(int i=a;i<=b;i++)
#define ROF(i,a,b)      for(int i=a;i>=b;i--)
#define REP(i,b)        for(int i=0;i<b;i++)
#define IT(it,x)	    for(it=x.begin();it!=x.end();it++)
int mp[300];
int main()
{
    int cnt=0;
    for(int i='A';i<='Z';i++)
        mp[i]=cnt++;
    int n;
    cin>>n;
    string s;
    cin>>s;
    for(int i=0;i<s.size();i++)
    {
        int x=mp[s[i]];
        x+=n;
        x=x%26;
        s[i]=char(x+'A');
    }
    cout<<s;
}


Measured memory_bytes: 3644
#include <algorithm>
#include <bitset>
#include <cmath>
#include <cstring>
#include <iostream>
#include <map>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

const int MOD = 1e9 + 7;
const int iINF = 1000000000;
const long long int llINF = 1000000000000000000;

using namespace std;
using ll = long long int;
using edge = struct {
  int to;
  int cost;
};
#define REP(i, n) for (ll i = 0; i < (n); i++)
#define FOR(i, a, b) for (ll i = (a); i < (b); i++)
#define AUTO(i, m) for (auto i = (m).begin(); i != (m).end(); ++i)
#define ALL(a) (a).begin(), (a).end()
#define MAX(vec) *std::max_element(vec.begin(), vec.end());
#define MIN(vec) *std::min_element(vec.begin(), vec.end());
#define MAXI(vec)                                                              \
  std::distance(vec.begin(), *std::max_element(vec.begin(), vec.end()));
#define MINI(vec)                                                              \
  std::distance(vec.begin(), *std::min_element(vec.begin(), vec.end()));
#define BIT(n, num) std::bitset<(n)>((num)).to_string()
#define MATMUL(a, b, c)                                                        \
  REP(i, a.size())                                                             \
  REP(j, b[0].size()) REP(k, a[0].size()) c[i][j] += a[i][k] * b[k][j];
#define CLA2(a) REP(i, a.size()) REP(j, a[0].size()) a[i][j] = 0;
#define REV(T) greater<T>()

ll pow_(ll a, ll n) {
  ll x = 1;
  while (n > 0) {
    if (n & 1)
      x = (x * a) % MOD;
    a = (a * a) % MOD;
    n >>= 1;
  }
  return x;
}

vector<ll> divisor(ll n) {
  vector<ll> ret;
  for (ll i = 1; i * i <= n; i++) {
    if (n % i == 0) {
      ret.push_back(i);
      if (i * i != n)
        ret.push_back(n / i);
    }
  }
  sort(begin(ret), end(ret));
  return (ret);
}

map<ll, int> prime_factor(ll n) {
  map<ll, int> ret;
  for (ll i = 2; i * i <= n; i++) {
    while (n % i == 0) {
      ret[i]++;
      n /= i;
    }
  }
  if (n != 1)
    ret[n] = 1;
  return ret;
}

ll factorial(int n) {
  ll ans = 1;
  for (int i = 2; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll P(int n, int m) {
  ll ans = 1;
  for (int i = m + 1; i <= n; i++) {
    ans *= i;
    ans %= MOD;
  }
  return ans;
}
ll power(int n, int m) {
  if (m == 0) {
    return 1;
  } else if (m % 2 == 0) {
    ll tmp = power(n, m / 2);
    return (tmp * tmp) % MOD;
  } else {
    return (n * power(n, m - 1)) % MOD;
  }
}
ll C(int n, int m) {
  return (P(n, n - m) * power(factorial(m), MOD - 2)) % MOD;
}
int dx[4] = {1, 0, -1, 0};
int dy[4] = {0, 1, 0, -1};

int main() {
  ll N;
  vector<ll> A;
  cin >> N;
  if (N == 25)
    cout << "Christmas" << endl;
  else if (N == 24)
    cout << "Christmas Eve" << endl;
  else if (N == 23)
    cout << "Christmas Eve Eve" << endl;
  else if (N == 22)
    cout << "Christmas Eve Eve Eve" << endl;
  return 0;
}


Measured memory_bytes: 256
#include <iostream>
#include <algorithm>
#include <vector>
#include <string>
#include <sstream>
#include <set>
#include <map>
#include <iostream>
#include <utility>
#include <cctype>
#include <queue>
#include <stack>
#include <cstdio>
#include <cstdlib>
#include <cmath>
#include <unordered_set>
#include <unordered_map>
#include <limits.h>
#include <cstring>
#include <tuple>
#include <cassert>
#include <numeric>
#include <iomanip>
using namespace std;
// type alias
typedef long long LL;
typedef pair< int , int > II;
typedef tuple< int, int, int > III;
typedef vector<int> VI;
typedef vector<string> VS;
typedef vector<vector<int>> VVI;
typedef unordered_map<int,int> MAPII;
typedef unordered_set<int> SETI;
template<class T> using VV=vector<vector<T>>;
// minmax
template<class T> inline T SMIN(T& a, const T b) { return a=(a>b)?b:a; }
template<class T> inline T SMAX(T& a, const T b) { return a=(a<b)?b:a; }
// repetition
#define FORE(i,a,b) for(int i=(a);i<=(b);++i)
#define REPE(i,n)  for(int i=0;i<=(n);++i)
#define FOR(i,a,b) for(int i=(a);i<(b);++i)
#define REP(i,n)  for(int i=0;i<(n);++i)
#define FORR(x,arr) for(auto& x:arr)
#define SZ(a) int((a).size())
// collection
#define ALL(c) (c).begin(),(c).end()
// DP
#define MINUS(dp) memset(dp, -1, sizeof(dp))
#define ZERO(dp) memset(dp, 0, sizeof(dp))

// stdout
#define println(args...) fprintf(stdout, ##args),putchar('\n');

// debug cerr
#define TRACE true
#define dump(x) if(TRACE) { cerr << #x << " = " << (x) << endl; }
#define dump2(x,y) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << endl; }
#define dump3(x,y,z) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << endl; }
#define dump4(x,y,z,a) if(TRACE) { cerr << #x << " = " << (x) << ", " << #y << " = " << (y) << ", " << #z << " = " << (z) << ", " << #a << " = " << (a) << endl; }
#define dumpf(args...) if(TRACE) { fprintf(stderr, ##args); putchar('\n'); }
#define dumpAR(ar) if(TRACE) { FORR(x,(ar)) { cerr << x << ','; } cerr << endl; }
template<class Iter> void dumpc(Iter begin, Iter end) { if (TRACE) { for(; begin!=end; ++begin) { cerr<<*begin<<','; } cerr<<endl; } }

// $ cp-batch StringTransformation | diff StringTransformation.out -
// $ g++ -std=c++14 -Wall -O2 -D_GLIBCXX_DEBUG -fsanitize=address StringTransformation.cpp && ./a.out

/*
 
 1/17/2019
 
 9:14-
 
 */

//const int MAX_N=1e6+1;
string S,T;
int N;

int mx[26][26];

bool f(string S, string T) {
  ZERO(mx);
  int N=SZ(S);
  REP(i,N) mx[S[i]-'a'][T[i]-'a']=1;
  bool ok=true;
  REP(i,26) {
    int cnt=accumulate(mx[i],mx[i]+26,0);
//    dump2(i,cnt);
    ok&=cnt<=1;
  }
  return ok;
}

void solve() {
  cout<<(f(S,T)&&f(T,S)?"Yes":"No")<<endl;
}

int main() {
  ios_base::sync_with_stdio(false);
  cin.tie(0);
  cout<<setprecision(12)<<fixed;
  
  cin>>S>>T;
  solve();
  
  return 0;
}


Measured memory_bytes: 1556
N=int(input())
testimony=[[-1]*N for i in range(N)]
count=0
for i in range(N):
    A=int(input())
    for j in range(A):
        x,y=map(int,input().split())
        testimony[i][x-1]=y
for i in range(1<<N):
    honest=[0]*N
    for j in range(N):
        if (i>>j)&1:
            honest[j]=1
    flag=True
    for j in range(N):
        if honest[j]:
            for k in range(N):
                if testimony[j][k]==-1:
                    continue
                if testimony[j][k]!=honest[k]:
                    flag=False
    if flag:
        count=max(count,honest.count(1))
print(count)

Measured memory_bytes: 9136
#include <stdio.h>
int main(void)
{
int N;
  int flag=0;
  scanf("%d",&N);
  for(int i=1;i<=9;i++)
    {
      if(N%i==0 && 1<=N/i && N/i<=9) 
        {
          flag=1;
        }
      	}
      if(flag==1)
      {
      printf("Yes");
      }
    else printf("No");
    
}

Measured memory_bytes: 128
#include <algorithm>
#include <vector>
#include <set>
#include <map>
#include <unordered_map>
#include <unordered_set>
#include <string>
#include <cmath>
#include <iostream>
#include <stack>
#include <queue>
#include <climits>
#include <iomanip>

#define all(x) x.begin(), x.end()
#define MOD 998244353

const long double PI = 3.141592653589793236L;

typedef long long int ll;
typedef long double ld;

using namespace std;

void solve()
{
	// Your code goes here.
	vector<int>a(5);
	for (int i=1; i<=5; i++)
    {
        cin>>a[i];

    }
    for (int i=1; i<=5; i++)
    {
        if (a[i]==0)
        {
            cout<<i<<endl;
            return;
        }
    }


}
int main()
{
    ios_base::sync_with_stdio(false);
    cin.tie(NULL);

    int T = 1;
    //cin >> T; // If only one test case then you can comment this line out.

    while (T--)
    {
        solve();
    }

    return 0;
}


Measured memory_bytes: 3648
s=input()
k=int(input())
m=0
j=0
if len(set(list(s)))==1:print((len(s)*k)//2);exit()
for i in range(len(s)):
  if len(s)<=j+1:
    a=m*k
    if s[0]==s[-1]==s[1]==s[len(s)//3]:print(a+k-1)
    else:print(a)
    break;
  if s[j]==s[j+1]:
    m+=1
    j+=1
  j+=1


Measured memory_bytes: 3064
#include <bits/stdc++.h>
#define REP(i, a, b) for (int i = a; i <= b; ++i)
#define PER(i, a, b) for (int i = a; i >= b; --i)
#define RVC(i, S) for (int i = 0; i < S.size(); ++i)
#define mp make_pair
#define pb push_back
#define debug(...) fprintf(stderr, __VA_ARGS__)
using namespace std;

typedef long long LL;
typedef vector<int> VI;
typedef pair<int, int> pii;

inline int read(){
	int x = 0, ch = getchar(), f = 1;
	while (!isdigit(ch)){if (ch == '-') f = -1; ch = getchar();}
	while (isdigit(ch)) x = x * 10 + ch - '0', ch = getchar();
	return x * f;
}

int n, du[100005], rt, fl = 1;
LL a[100005];
VI E[100005];

void dfs(int x, int f){
	LL sum = 0, mx = 0;
	int cnt = 0;
	RVC(i, E[x]) if (E[x][i] != f){
		int y = E[x][i];
		dfs(y, x); cnt += 1;
		sum += a[y];
		if (a[y] > mx) mx = a[y];
	}
	if (cnt == 0) return;
	if (sum < a[x] || mx > a[x]){
		printf("NO\n"); exit(0);
	}
	a[x] -= sum - a[x];
	if (a[x] < 0){
		printf("NO\n"); exit(0);
	}
}

int main(){
	n = read();
	REP(i, 1, n) a[i] = read();
	REP(i, 2, n){
		int a = read(), b = read();
		E[a].pb(b); E[b].pb(a);
		++du[a]; ++du[b];
	}
	if (n == 2){
		if (a[1] == a[2]) printf("YES\n");
		else printf("NO\n");
		return 0;
	}
	REP(i, 1, n) if (du[i] > 1){
		rt = i; dfs(i, 0); break;
	}
	if (!a[rt]) printf("YES\n");
	else printf("NO\n");
	return 0;
}

Measured memory_bytes: 14848
N, M = [int(x) for x in input().split()]
H = [int(x) for x in input().split()]
A = [0]*M
B = [0]*M
for m in range(M):
    A[m],B[m] = [int(x) for x in input().split()]
result = [True]*N
#print(result)
for m in range(M):
    #print(H[A[m]-1],H[B[m]-1])
    if H[A[m]-1]==H[B[m]-1]:
        result[A[m]-1] = False
        result[B[m]-1] = False
    elif H[A[m]-1] < H[B[m]-1]:
        result[A[m]-1] = False
    else:
        result[B[m]-1] = False
count = 0
#print(result)
for r in result:
    if r:
        count+=1
print(count)

Measured memory_bytes: 21856
#include <iostream>
#include <iomanip>

using namespace std;

int main(){
  int a,b;
  cin >> a >> b;
  cout << a / b << " ";
  cout << a % b << " ";
  cout << fixed;
  cout << setprecision(5) << double(a)/double(b) << endl;
  return 0;
}

Measured memory_bytes: 3264
#include "bits/stdc++.h"
using namespace std;
using ll = long long;
using pii = pair<int, int>;
using pll = pair<ll, ll>;
using vi = vector<int>;
using vl = vector<ll>;
using vvi = vector<vi>;
using vvl = vector<vl>;
const ll INF = 1LL << 60;
const ll MOD = 1000000007;
template <class T>
bool chmax(T &a, const T &b) {
    return (a < b) ? (a = b, 1) : 0;
}
template <class T>
bool chmin(T &a, const T &b) {
    return (b < a) ? (a = b, 1) : 0;
}
template <class C>
void print(const C &c, std::ostream &os = std::cout) {
    std::copy(std::begin(c), std::end(c), std::ostream_iterator<typename C::value_type>(os, " "));
    os << std::endl;
}

int main() {
    int n;
    cin >> n;
    vl a(n);
    for (int i = 0; i < n; ++i) {
        cin >> a[i];
    }
    bool ok = false;
    for (int i = 0; i < n; ++i) {
        if (a[i] % 2 == 1) {
            ok = true;
        }
    }
    if (ok)
        cout << "first" << "\n";
    else
        cout << "second" << "\n";
    return 0;
}

Measured memory_bytes: 1152
import java.util.Scanner;
class Main {
    public static void main(String[] args) {
        Scanner stdIn = new Scanner(System.in);
        int n = stdIn.nextInt();
        int d = stdIn.nextInt();
        int x[][] = new int[n][d];

        for(int i = 0;i < n;i++) {
            for(int j = 0;j < d;j++) {
                x[i][j] = stdIn.nextInt();
            }
        }

        int count = 0;
        for(int i = 0;i < n;i++) {
            for(int j = i + 1;j < n;j++) {
                 double r = 0;
                 for(int k = 0;k < d;k++) {
                     r += (x[i][k] - x[j][k]) * (x[i][k] - x[j][k]);
                 }
                 r = Math.sqrt(r);
                 if(r == (int)r) {
                     count++;
                 }
            }
        }

        System.out.println(count);
        
        
    }
}



Measured memory_bytes: 21844
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
#define rep(i,a) for(int i=0;i<(a);i++)
const ll MOD=1000000007;
//const ll MOD=998244353;

int main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  
  int N,R; cin>>N>>R;
  cout<<R+100*max(0,10-N)<<endl;
  return 0;
}

Measured memory_bytes: 256
package main

import (
	"fmt"
)

func main() {
	var N int
	fmt.Scan(&N)

	X := make([]int, N)
	for i := 0; i < N; i++ {
		fmt.Scan(&X[i])
	}

	s := make(map[int]struct{})
	for i := 0; i < N; i++ {
		s[X[i]] = struct{}{}
	}

	if len(s) == N {
		fmt.Println("YES")
	} else {
		fmt.Println("NO")
	}

}


Measured memory_bytes: 9856
#include <cstdio>
#include <vector>
#include <set>
#include <algorithm>

using namespace std;

int a[50];
int b[50];
int dp[51][51];

void dfs(int x, int y) {
    int i;
    
    if (dp[x][y] != 1e9) return;
    if (x == y) {
        dp[x][y] = 0;
        return;
    }
    
    for (i = 1; i <= x; i++) {
        dfs(x % i, y);
        dp[x][y] = min(dp[x][y], max(dp[x % i][y], i));
    }
}

int main() {
    int n, i, j, k;
    long long ans = 0;
    vector <set<int>> v;
    set <int>::iterator it;
    
    scanf("%d", &n);
    
    for (i = 0; i < n; i++) scanf("%d", &a[i]);
    for (i = 0; i < n; i++) scanf("%d", &b[i]);
    
    for (i = 0; i <= 50; i++) {
        for (j = 0; j <= 50; j++) {
            dp[i][j] = 1e9;
        }
    }
    
    for (i = 0; i <= 50; i++) {
        for (j = 0; j <= i; j++) {
            dfs(i, j);
        }
    }
    
    for (i = 0; i < n; i++) {
        if (dp[a[i]][b[i]] == 1e9) {
            puts("-1");
            return 0;
        }
    }
    
    for (i = 0; i < n; i++) {
        set <int> s;
        s.insert(a[i]);
        v.push_back(s);
    }
    
    for (i = 50; i >= 1; i--) {
        for (j = 0; j < n; j++) {
            for (it = v[j].begin(); it != v[j].end(); it++) {
                if (dp[*it][b[j]] < i) break;
            }
            
            if (it == v[j].end()) break;
        }
        
        if (j < n) {
            ans += (1LL << i);
            
            for (j = 0; j < n; j++) {
                for (it = v[j].begin(); it != v[j].end(); it++) {
                    v[j].insert(*it % i);
                }
            }
        }
    }
    
    printf("%lld\n", ans);
    
    return 0;
}


Measured memory_bytes: 256
#include<iostream>
#include<iomanip>
#include<algorithm>
#include<vector>
#include<string>
#include<set>
using namespace std;
int main(){
	int x,a,b;
	cin >> x >> a >> b;
	if(abs(x-a) > abs(x-b)) cout << "B" << endl;
	else cout << "A" << endl;
}

Measured memory_bytes: 256
import heapq

V,E = map(int, input().split())

es = [[] for _ in range(V)]
q = []
for _ in range(E):
    s,t,w = map(int, input().split())
    heapq.heappush(q, (w,s,t))

class UnionFind:
    def __init__(self, N):
        self.parent = [i for i in range(N)]
        self.rank = [0] * N # 最初はそれぞれのノードが誰ともUnionをつくってないから木の深さが０
        self.count = 0 # unite回数
    
    # 根を返す
    def root(self, a):
        if self.parent[a] == a:
            return a
        else:
            # 親を見に行く
            self.parent[a] = self.root(self.parent[a])
            return self.parent[a]
    
    # 同じUnionに属するかどうか
    def is_same(self, a, b):
        return self.root(a) == self.root(b)
    
    # 同じUnionにする
    def unite(self, a, b):
        ra = self.root(a)
        rb = self.root(b)
        if ra == rb:
            return 
        if self.rank[ra] < self.rank[rb]:
            self.parent[ra] = rb
        else:
            self.parent[rb] = ra
            if self.rank[ra] == self.rank[rb]:
                self.rank[ra] += 1
        self.count += 1

uf = UnionFind(V)
total = 0
while q:
    w,s,t = heapq.heappop(q)
    if not uf.is_same(s,t):
        uf.unite(s,t)
        total += w

print(total)


Measured memory_bytes: 23852
#include <algorithm>
#include <cmath>
#include <deque>
#include <iomanip>
#include <iostream>
#include <map>
#include <queue>
#include <set>
#include <stack>
#include <tuple>
#include <vector>
using namespace std;
typedef long long ll;
ll const INF = 1LL << 60;

int main() {
  ll H, W;
  cin >> H >> W;
  string s;
  for (int i = 0; i < H; i++) {
    cin >> s;
    cout << s << endl;
    cout << s << endl;
  }
  return 0;
}

Measured memory_bytes: 3608
using System;
using System.Linq;

namespace test
{
  class Program
  {
   	static void Main(string[] args)
   	{
     	string[] s = Console.ReadLine().Split(' ');
     	int[] pqr= new int[]{int.Parse(s[0]), int.Parse(s[1]),int.Parse(s[2])};
    
     	Console.WriteLine(pqr.OrderBy(x => x).Sum() - pqr.Max());    
   	}
  }
}


Measured memory_bytes: 13396
#!/usr/bin/env python3
x = int(input())
for b in range(-(10 ** 4), 10 ** 4):
    ok = 0
    ng = 10 ** 6
    while ng - ok > 1:
        m = (ok + ng) // 2
        if m ** 5 - b ** 5 <= x:
            ok = m
        else:
            ng = m
    a = ok
    if a ** 5 - b ** 5 == x:
        print(a, b)
        exit()


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

#define rep(i,a,n)     for(int i=a;i<n;i++)
#define rep3(n)        for(int i=0;i<n;i++)
#define ll             long long
#define int            long long
#define pb             push_back
#define all(v)         v.begin(),v.end()
#define endl           "\n"
#define eb             emplace_back
#define x              first
#define y              second
#define gcd(a,b)       __gcd(a,b)
#define mem1(a)        memset(a,-1,sizeof(a))
#define mem0(a)        memset(a,0,sizeof(a))
#define pres(a,x)      a.find(x)!=a.end()
#define sz(a)          (int)a.size()
#define pii            pair<int,int>
#define hell           1000000007
#define elasped_time   1.0 * clock() / CLOCKS_PER_SEC
using namespace std;


template<typename T1,typename T2>istream& operator>>(istream& in,pair<T1,T2> &a){in>>a.x>>a.y;return in;}
template<typename T1,typename T2>ostream& operator<<(ostream& out,pair<T1,T2> a){out<<a.x<<" "<<a.y;return out;}
template<typename T,typename T1>T maxs(T &a,T1 b){if(b>a)a=b;return a;}
template<typename T,typename T1>T mins(T &a,T1 b){if(b<a)a=b;return a;}

const int maxn=2000005;
int p[maxn];
int sz[maxn];
int cnt;
void clear(int n=maxn){
    rep(i,0,maxn)p[i]=i,sz[i]=1;
}
int root(int x){
   while(x!=p[x]){
       p[x]=p[p[x]];
       x=p[x];
   }
   return x;  
}
void merge(int x,int y){
    int p1=root(x);
    int p2=root(y);
    if(p1==p2)return;
    cnt--;
    if(sz[p1]>=sz[p2]){
        p[p2]=p1;
        sz[p1]+=sz[p2];
    }
    else{
        p[p1]=p2;
        sz[p2]+=sz[p1];
    }
}

int solve(){
 	int n,m;cin>>n>>m;
 	clear();
 	cnt=n;
 	rep3(m){
 		int a,b;cin>>a>>b;
 		merge(a,b);
 	}
 	cout<<cnt-1<<endl;
 return 0;
}
signed main(){
    ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
    //freopen("input.txt", "r", stdin);
    //freopen("output.txt", "w", stdout);
    #ifdef SIEVE
    sieve();
    #endif
    #ifdef NCR
    init();
    #endif
    int t=1;//cin>>t;
    while(t--){
        solve();
    }
    return 0;
}
 

Measured memory_bytes: 34892
#include <bits/stdc++.h>
#define REP(i,n) for (int i = 0; i <(n); ++i)
#define REP2(i,x,n) for (int i = x; i <(n); ++i)
#define ALL(v) v.begin(), v.end()
#define RALL(v) v.rbegin(), v.rend()
using namespace std;
using ll = long long;
using P = pair<int,int>;
static const double PI = acos(-1);



int main(){
  int n;
  cin >> n;
  int ans = 0;

  REP(i,1000){
    n -= 1000;
    if(n <= 0) break;

  }

  ans = abs (n);

  cout << ans << endl;


  return 0;

}


Measured memory_bytes: 3616
#include <stdio.h>

int main() {
	int n, ctr = 0;
	scanf("%d", &n);
	char s[n+1];
	scanf("%s", s);
	
	for (int i = 0, j = n/2; i < n/2; i++, j++){
		if (s[i] == s[j]) {
			ctr++;
		}
	}
	if (n % 2 != 0 || ctr != n/2) {
		printf("No\n");
	}
	else if (ctr == n/2) {
		printf("Yes\n");
	}
	
	return 0;
}

Measured memory_bytes: 1636
#include <algorithm>
#include <iostream>
#include <string>
#include <vector>

#define rep(inc, bgn, end) for (int inc = bgn; inc < end; ++inc)
#define repe(inc, bgn, end) for (int inc = bgn; inc <= end; ++inc)

using ll = long long;
using namespace std;

int main() {
    int n, m;
    cin >> n >> m;
    cout << n * m << endl;
    return 0;
}


Measured memory_bytes: 3636
#include <bits/stdc++.h>
using namespace std;
#define rep(i,n) for (int i=0; i<(int)(n); ++i)
#define all(a) (a).begin(), (a).end()
#define rall(a) (a).rbegin(), (a).rend()
using ll = long long;
using vi = vector<int>;
using vl = vector<ll>;
using Graph = vector<vi>;  // vi <=> vl
using vb = vector<bool>;
using boolGraph = vector<vb>;
using P = pair<int, int>;  // int <=> ll
const int MOD = 1e9+7;
const double EPS = 1e-9;

int main() {
  int N, K; cin >> N >> K;
  vi arr;
  rep(i,N) {
    int x; cin >> x;
    if (x < K) arr.push_back(x);
  }

  sort(rall(arr));

  boolGraph dp(arr.size()+1, vb(K, false));
  rep(i,dp.size()) dp[i][0] = true;
  rep(i,arr.size()) {
    rep(j,K-arr[i]) {
      dp[i+1][j+arr[i]] = dp[i][j] || dp[i][j+arr[i]];
    }
  }

  reverse(all(arr));

  boolGraph dp2(arr.size()+1, vb(K, false));
  rep(i,dp2.size()) dp2[i][0] = true;
  rep(i,arr.size()) {
    rep(j,K-arr[i]) {
      dp2[i+1][j+arr[i]] = dp2[i][j] || dp2[i][j+arr[i]];
    }
  }

  int ans = arr.size();

  rep(i,arr.size()) {
    vi tmp(K+1);
    rep(j,K) tmp[j+1] = tmp[j] + (dp2[i][j] ? 1 : 0);

    int h = arr.size()-1 - i;

    rep(j,K) {
      if (!dp[h][j]) continue;

      if (j < K-arr[i] && tmp[K-j] == tmp[K-arr[i]-j]) continue;
      
      --ans;
      break;
    }
  }

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


Measured memory_bytes: 6912
import java.util.Scanner;

public class Main {
  public static void main(String[] args) {
    Scanner scanner = new Scanner(System.in);

    int N = scanner.nextInt();
    int M = scanner.nextInt();
    boolean[] toN = new boolean[N];
    boolean[] from1 = new boolean[N];
    for (int i = 0; i < M; i++) {
      int a = scanner.nextInt() - 1;
      int b = scanner.nextInt() - 1;
      if (a == 0) {
        from1[b] = true;
      }
      if (b == 0) {
        from1[a] = true;
      }
      if (a == N - 1) {
        toN[b] = true;
      }
      if (b == N - 1) {
        toN[a] = true;
      }
    }

    for (int i = 0; i < N; i++) {
      if (from1[i] && toN[i]) {
        System.out.println("POSSIBLE");
        return;
      }
    }
    System.out.println("IMPOSSIBLE");
  }
}


Measured memory_bytes: 98868
#include<map>
int64_t k,t=1,n,s,p;int S(int64_t x){s=0;while(x)s+=x%10,x/=10;return s;}int main(){scanf("%d",&k);while(printf("%ld\n",n+=t),--k)t+=t*9*(S(p=n+t+t)*(n+t)>S(n+t)*p);}

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

const int maxn = 1e5 + 10;
int a[maxn];
int dp[maxn];

int main() {
	int n, m;
	cin >> n >> m;
	for (int i = 1; i <= m; i++)
		cin >> a[i];
	sort(a+1, a+m+1);
	for (int i = 1; i <= m-1; i++)
		dp[i] = a[i+1] - a[i];
	sort(dp+1, dp+m);
	for (int i = 1; i <= m-n; i++) 
		dp[m] += dp[i];
	printf("%d\n", dp[m]);
	return 0;
}

Measured memory_bytes: 1024
// https://atcoder.jp/contests/dp/tasks/dp_e

#include <algorithm>
#include <cmath>
#include <iomanip>
#include <iostream>
#include <map>
#include <numeric>
#include <set>
#include <string>
#include <tuple>
#include <vector>
using namespace std;

typedef long long ll;
typedef pair<int, int> PII;
typedef pair<ll, ll> PLL;
#define INF (1e9)
#define MOD (1e9 + 7)
#define LINF (1e18)
#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) for (int i = 0; i < (n); ++i)
#define REPR(i, n) for (int i = n; i >= 0; i--)
#define FOREACH(x, a) for (auto &(x) : (a))
#define ALL(obj) (obj).begin(), (obj).end()
#define ALLR(obj) (obj).rbegin(), (obj).rend()
// int gcd(long a, long b) { return b ? gcd(b, a % b) : a; }
// int lcm(long a, long b) { return a * b / gcd(a, b); }

int main() {
    ios::sync_with_stdio(false);
    cin.tie(0);
    int n, w, i1, i2;
    cin >> n >> w;
    // dp[i] : 価値iの重さを最小化する
    vector<ll> dp(1000001, LINF);
    dp[0] = 0;
    int s = 0;
    REP(i, n) {
        cin >> i1 >> i2;
        for (ll j = s; j >= 0; j--) {
            if (i1 + dp[j] <= w) {
                dp[j + i2] = min(dp[j + i2], dp[j] + i1);
            }
        }
        s += i2;
    }
    for (int i = s; i >= 1; i--) {
        if (dp[i] <= w) {
            cout << i << endl;
            break;
        }
    }

    return 0;
}


Measured memory_bytes: 8064
n = int(input())
lst = []
for i in range(n):
    a = int(input())
    b = []
    for j in range(a):
        x, y = map(int,input().split())
        x -= 1
        b.append([x, y])
    lst.append(b)
ans = 0

for i in range(2**n):
    honest = []
    contradiction_f = False

    for j in range(n):
        if i>>j & 1:
            honest.append(j)

    for j in honest:
        judge = lst[j]
        for k in judge:
            if k[1] == 1:
                if not k[0] in honest:
                    contradiction_f = True
                    break
            else:
                if k[0] in honest:
                    contradiction_f = True
                    break

    if not contradiction_f:
        ans = max(ans, len(honest))

print(ans)

Measured memory_bytes: 9224