akhauriyash/Code-Regression huggingface dataset:
S = int(input())

mod = 10 ** 9 + 7


fact = [0] * 3000
fact[0] = 1
for i in range(1, 3000):
    fact[i] = fact[i - 1] * i % mod

invfact = [0] * 3000
invfact[3000 - 1] = pow(fact[3000 - 1], mod - 2, mod)
for i in range(3000 - 1, 0, -1):
    invfact[i - 1] = invfact[i] * i % mod


def nCk(n, k):
    return fact[n] * invfact[k] * invfact[n - k] % mod


ans = 0
for n in range(1, S):
    if 3 * n > S:
        break
    ans += nCk(S - 3 * n + n - 1, n - 1)
    ans %= mod

print(ans)


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

//def
#define debug(x) cout << #x << ": " << x << endl
#define out(x) cout << x << endl
#define repeat(i, a, b) for (int i = (int)(a); i < (int)(b); i++)
#define revrepeat(i, a, b) for (int i = (int)(b)-1; i >= (int)(a); i--)
#define rep(i, n) for (int i = 0; i < (int)(n); i++)
#define revrep(i, n) for (int i = (int)(n)-1; i >= 0; i--)
#define foreach(e, v) for (auto &e : v)
#define all(x) (x).begin(), (x).end()
#define CYES cout << "Yes" << endl
#define CNO cout << "No" << endl
#define SPC(x) cout << fixed << setprecision(x)
#define ZERO(a) memset(a, 0, sizeof(a))
#define MINUS(a) memset(a, 0xff, sizeof(a))

typedef long long ll;
typedef long double ld;
typedef vector<int> vi;
typedef vector<vector<int>> vii;
typedef vector<ll> vl;
typedef vector<vector<ll>> vll;
typedef pair<int, int> P;
constexpr int MOD = 1e9 + 7;
constexpr int INF = __INT_MAX__;               // 2^31 - 1
constexpr long long INFLL = __LONG_LONG_MAX__; // 2^61 - 1
constexpr int MAX_N = 1e5 + 5;
constexpr double PI = acos(-1);

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

    ll x, y, a, b, c;
    cin >> x >> y >> a >> b >> c;
    vector<pair<char, ll>> apples;
    rep(i, a + b + c) {
        ll temp;
        cin >> temp;
        if (i < a) {
            apples.emplace_back('P', temp);
        } else if (i < a + b) {
            apples.emplace_back('Q', temp);
        } else {
            apples.emplace_back('R', temp);
        }
    }
    auto comPair = [&](pair<char, ll> one, pair<char, ll> two) {
        return one.second > two.second;
    };
    sort(all(apples), comPair);
    ll rx, ry, rz, idx, ans;
    idx = rx = ry = rz = ans = 0;
    for (; rx + ry + rz < x + y; idx++) {
        char F = apples[idx].first;
        ll val = apples[idx].second;
        if (F == 'P' and rx < x) {
            rx++;
            ans += val;
        }
        if (F == 'Q' and ry < y) {
            ry++;
            ans += val;
        }
        if (F == 'R') {
            rz++;
            ans += val;
        }
    }

    out(ans);
    return 0;
}


Measured memory_bytes: 10476
#include <bits/stdc++.h>
using namespace std;
typedef long long ll;
const int maxn = 1e3 + 5;
//head
ll x, y, z, k, a[maxn], b[maxn], c[maxn];
int main() {
//    freopen("in.txt", "r", stdin);
//    freopen("out.txt", "w", stdout);
    ios::sync_with_stdio(false);
    cin >> x >> y >> z >> k;
    for(int i = 0; i < x; ++i) {
        cin >> a[i];
    }
    for(int i = 0; i < y; ++i){
        cin >> b[i];
    }
    for(int i = 0; i < z; ++i) {
        cin >> c[i];
    }
    vector<ll> v;
    for(int i = 0; i < x; ++i) {
        for(int j = 0; j < y; ++j) {
            v.push_back(a[i] + b[j]);
//            printf("v = %lld\n", a[i]+b[j]);
        }
    }
    sort(v.begin(), v.end());
    reverse(v.begin(), v.end());
    vector<ll> ans;
    int sz = min((ll)v.size(), k);
    for(int i = 0; i < sz; ++i) {
        for(int j = 0; j < z; ++j) {
            ans.push_back(v[i] + c[j]);
        }
    }
    sort(ans.begin(), ans.end());
    reverse(ans.begin(), ans.end());
    for(int i = 0; i < k; ++i) {
        cout << ans[i] << endl;
    }
    return 0;
}


Measured memory_bytes: 43364
#include <stdio.h>

int main() {
	int n1,n2,n3,n4,w=0,x=0,y=0,z=0;
	scanf("%d %d %d %d",&n1,&n2,&n3,&n4);
	if(n1==1 ||n2==1||n3==1||n4==1 )
	w++;
	if(n1==9 ||n2==9||n3==9||n4==9 )
	x++;

if(n1==7||n2==7||n3==7||n4==7 )
	y++;
if(n1==4 ||n2==4||n3==4||n4==4 )
	z++;
if(x==1 && y==1 && z==1 && w==1)
printf("YES");
else
printf("NO");
	return 0;
}

Measured memory_bytes: 128
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,m;
  cin>>n>>m;
  vi dp(n+1,inf);
  dp[0]=0;
  while(m--){
    int c;
    cin>>c;
    rep(i,n-c+1){
      dp[i+c]=min(dp[i+c],dp[i]+1);
    }
  }

  cout<<dp[n]<<endl;


}


Measured memory_bytes: 3280
#include<iostream>
#include<string>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<cstdio>
#include<cmath>
#include<numeric>
#include<queue>
#include<stack>
#define repp(i,a,b) for(int i=(int)a;i<(int)b;++i)
#define repm(i,a,b) for(int i=(int)a;i>(int)b;--i)
using ll=long long;
static const ll mod=1e9+7;
static const ll INF=1LL<<50;
using namespace std;

int main() {
	string s;
  bool j=true;
  cin>>s;
  repp(i,0,s.size()-1)if(s[i]==s[i+1])j=false;
  if(j)cout<<"Good"<<endl;
  else cout<<"Bad"<<endl;
  return 0;
}

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

using namespace std;
using ll=long long;
using ull=unsigned long long;
using pii=pair<int,int>;

#define INF LONG_MAX
#define MOD 1000000007
#define rng(a) a.begin(),a.end()
#define rrng(a) a.end(),a.begin()
#define endl "\n"

template<int_fast64_t m=MOD>
struct Mcomb{
  using i64=int_fast64_t;
  vector<i64>f;  //$B3,>h(B
  vector<i64>finv; //$B3,>h$N5U85(B
  vector<i64>inv;  //$B5U85(B

  Mcomb(i64 max){
    f.resize(max+1,0);
    finv.resize(max+1,0);
    inv.resize(max+1,0);
    f[0]=f[1]=1;
    finv[0]=finv[1]=1;
    inv[1]=1;
    for(i64 i=2;i<=max;i++){
      f[i]=f[i-1]*i%m;
      inv[i]=m-inv[m%i]*(m/i)%m;
      finv[i]=finv[i-1]*inv[i]%m;
    }
  }

  //nCr=n!/r!(n-r)!
  i64 slove(i64 n,i64 r){
    if(n<r)return 0;
    if(n<0||r<0)return 0;
    return f[n]*(finv[r]*finv[n-r]%m)%m;
  }
};

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

  int n;
  cin>>n;
  //重複一個
  vector<int>a(n+1);
  for(int i=0;i<=n;i++)cin>>a[i];
  int num;
  map<int,int>m;
  for(auto it:a){
    if(m[it])num=it;
    m[it]++;
  }
  int l=-1,r=-1;
  for(int i=0;i<=n;i++){
    if(a[i]==num){
      if(l==-1)l=i;
      else r=i;
    }
  }
  Mcomb<>c(200000);
  for(int i=1;i<=n+1;i++){
    cout<<((c.slove(n+1,i)%MOD-c.slove(l+n-r,i-1)%MOD)%MOD+MOD)%MOD<<endl;
  }
  return 0;
}


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

int main() {
    int n;cin>>n;
    int a[n];
    ll l=0,r=0,mn=1e18;
    for (int i=0;i<n;i++) {
        cin>>a[i];
        r+=a[i];
    }
    for (int i=0;i<n-1;i++) {
        l+=a[i];
        r-=a[i];
        mn=min(mn,abs(l-r));
    }
    cout<<mn<<endl;
    return 0;
}

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

int main() {
  int N,count;
  count=1;
  cin>>N;
  vector<int>d(N);
  for(int i=0;i<N;i++){
  cin>>d.at(i);
  }
  sort(d.begin(),d.end());
  reverse(d.begin(),d.end());
  for(int i=1;i<N;i++){
    if(d.at(i)!=d.at(i-1)){
      count++; 
    }
  }
  cout<<count<<endl;
}


Measured memory_bytes: 256
macro_rules! input {
    (source = $s:expr, $($r:tt)*) => {
        let mut iter = $s.split_whitespace();
        let mut next = || { iter.next().unwrap() };
        input_inner!{next, $($r)*}
    };
    ($($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:ty) => {
        $next().parse::<$t>().expect("Parse error")
    };
}


fn main() {
    input!{
        n: i32,
        m: i32,
        a: [i32;m],
    };
    let sum: i32 = a.iter().sum();
    if sum > n {
        println!("-1");
    } else {
        println!("{}", n - sum);
    }
}


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

int main(){
    int W, H, x, y, r;
    
    cin >> W >> H >> x >> y >> r;
    if((x - r) < 0 || ( x + r ) > W){
        cout << "No" << endl;
    }
    
    // if((x - r) >= 0 && (x + r) <= W){
    //     cout << "Yes" << endl;
    // }
    
    else{
        if((y + r) > H || (y - r) < 0){
            cout << "No" << endl;
        }
        else{
            cout << "Yes" << endl;
        }
    }
    
    return 0;
}


Measured memory_bytes: 3112
#include<stdio.h>
#include<math.h>
int main(){
  int N,T,c[100],t[100];
  int temp;
  int i,j;
  scanf("%d%d", &N, &T);
  for(i=0;i<N;i++){
    scanf("%d%d", &c[i], &t[i]);
  }

  for(i=0;i<N;i++){
    for(j=N-1;j>i;j--){
      if(c[j]<c[j-1]){
	temp=t[j];
	t[j]=t[j-1];
	t[j-1]=temp;
	temp=c[j];
	c[j]=c[j-1];
	c[j-1]=temp;
      }
    }
  }
  i=0;
  while(t[i]>T){
    i++;
    if(i==N) break;
  }
  if(i==N) printf("TLE\n");
  else printf("%d\n", c[i]);
  return 0;
}


Measured memory_bytes: 128
N = int(input())
MOD = 10**9 + 7

ans1=1
ans2=1
ans3=1

for i in range(N):
  ans1 = ans1*10 % MOD
  ans2 = ans2*9 % MOD
  ans3 = ans3*8 % MOD

print((ans1-2*ans2+ans3) % MOD)


Measured memory_bytes: 63260
import math
n, d = list(map(int,input().split(" ")))
ls = []
for i in range(n):
  ls.append(list(map(int,input().split(" "))))
ans = 0
for i in range(n):
  for j in range(i+1,n):
    dist = 0
    for k in range(d):
      dist += pow(ls[i][k]-ls[j][k], 2)
    dist = pow(dist ,0.5)
    if math.ceil(dist) == math.floor(dist):
      ans += 1
print(ans)

Measured memory_bytes: 3188
// Last Change: 10/24/2019 20:11:23.
#include <algorithm>
#include <array>
#include <bitset>
#include <cmath>
#include <complex>
#include <cstdlib>
#include <functional>
#include <iomanip>
#include <iostream>
#include <list>
#include <map>
#include <memory>
#include <numeric>
#include <queue>
#include <set>
#include <stack>
#include <string>
#include <vector>

using namespace std;
using ll = long long;
vector<ll> coin = {10, 50, 100, 500};

ll getOturi(ll diff) {
  vector<ll> res(4);
  for (int i = 3; i >= 0; --i) {
    res[i] = diff / coin[i];
    diff -= res[i] * coin[i];
  }

  ll ans = 0;
  for (auto &&e : res) {
    ans += e;
  }
  return ans;
}

void solve(ll N) {
  vector<ll> ipt(4);

  for (auto &&e : ipt) {
    cin >> e;
  }

  ll oturi = numeric_limits<ll>::max();

  vector<ll> res(4, 0);
  for (int i = 0; i <= ipt[0]; ++i) {
    for (int j = 0; j <= ipt[1]; ++j) {
      for (int k = 0; k <= ipt[2]; ++k) {
        for (int l = 0; l <= ipt[3]; ++l) {
          ll val = coin[0] * i + coin[1] * j + coin[2] * k + coin[3] * l;
          if (val >= N) {
            ll diff = val - N;
            ll curOturi = getOturi(diff) - i - j - k - l;
            if (curOturi < oturi) {
              oturi = curOturi;
              res = {i, j, k, l};
            }
          }
        }
      }
    }
  }

  for (int i = 0; i < 4; ++i) {
    if (res[i] > 0) {
      cout << coin[i] << ' ' << res[i] << endl;
    }
  }
}

int main() {
  ll N;
  bool flag = false;
  while (cin >> N and N > 0) {
    if (flag) {
      cout << endl;
    }
    solve(N);
    flag = true;
  }
}



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

int main()
{
  int a[5];
  
  for (int i = 0; i < 5; i++){
    cin >> a[i];
  }
  sort(a, a + 5, greater<int>());
  
  cout << a[0];
  for (int i = 1; i < 5; i++){
    cout << " " << a[i];
  }
  cout << endl;
}

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

int main() {
    int x, y, ans = 0;
    cin >> x >> y;
    if(x == 1 && y == 1) {
        ans = 1000000;
    } else {
        if(x == 1) ans += 300000;
        if(y == 1) ans += 300000;
        if(x == 2) ans += 200000;
        if(y == 2) ans += 200000;
        if(x == 3) ans += 100000;
        if(y == 3) ans += 100000;
    }
    cout << ans << '\n';
}


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

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

    ll ten=1, ni=1, ei=1;
    ll ans = 0;
    for(int i=0; i<n; i++){
        ten = ten * 10;
        if(i!=n-1)
            ten = ten % MOD;
        ni = ni * 9;
        ni = ni % MOD;
        ei = ei * 8;
        if(i!=n-1)
            ei = ei % MOD;
        
    }
    ni = 2*ni;
    ni = ni % MOD;
    ans = ten - ni + ei;
    ans = ans % MOD;

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

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

using namespace std;

typedef long long ll;

ll N, K, L, R;
ll a[40];

decltype(auto) enumerate(int sidx, int size) {
  vector<pair<ll, ll>> ret;
  for(int i=0; i<1<<size; i++) {
    int cnt = 0; ll sum = 0;
    for(int j=0; j<size; j++)
      if(i >> j & 1) cnt++, sum += a[sidx + j];
    ret.emplace_back(cnt, sum);
  }
  return ret;
}

ll solve() {
  decltype(auto) v0 = enumerate(0, N / 2);
  decltype(auto) v1 = enumerate(N / 2, (N + 1) / 2);
  sort(v0.begin(), v0.end());
  ll ret = 0;
  for(int i=0; i<(int)v1.size(); i++)
    ret +=  upper_bound(v0.begin(), v0.end(), make_pair(K - v1[i].first, R - v1[i].second))
          - lower_bound(v0.begin(), v0.end(), make_pair(K - v1[i].first, L - v1[i].second));
  return ret;
}

int main() {
  cin >> N >> K >> L >> R;
  for(int i=0; i<N; i++) cin >> a[i];
  cout << solve() << endl;
  return 0;
}

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

using namespace std;


long long gcd2(long long x,long long y) {
    if(y == 0) return x;
    return gcd2(y,x % y);
}

long long lcm2(long long x,long long y) {
    return x / gcd2(x,y) * y;
}

int main() {
    int x;
    cin >> x;
    long long n = lcm2(x,360);
    cout << n / x << "\n";
    return 0;
}

Measured memory_bytes: 3560
#include<stdio.h>
#define N 100000

int a,A[N];
int partition(int p,int r){
  int x,i,j,y;
  x = A[r];
  i = p-1;
  for(j=p;j<r;j++){
    if(A[j]<=x){
      i = i+1;
      y = A[i];
      A[i] = A[j];
      A[j] = y;
    }
}

  y = A[i+1];
  A[i+1]=A[r];
  A[r]=y;
  return i+1;
}


int main(){
  int i,c;
  scanf("%d",&a);
  for(i=0;i<a;i++){
    scanf("%d",&A[i]);
  }
  
  c = partition(0,a-1);
  
  for(i=0;i<a-1;i++){
    if(i==c)printf("[%d] ",A[i]);
    else{
      printf("%d ",A[i]);
    }
  }
  printf("%d",A[a-1]);
  printf("\n");
  return 0;
}

Measured memory_bytes: 992
#include <bits/stdc++.h>
typedef long long ll;
using namespace std;
ll k;
ll n;
vector< ll > a;
int main()
{
        cin >> k;
        n = 50;
        if(k >= 50){
        ll V = (k/n);
        a.resize(n, V);
        for(ll i=0;i<n;i++) a[i] += i;
        ll rems = k%n;
        for(ll i=0;(i<n) && (rems); i++) {
                a[i] += n;
                for(ll j=0;j<n;j++) {
                        if(j==i) continue;
                        a[j] -= 1;
                }
                rems--;
        }
        cout << a.size() << "\n";
        for(auto &i: a) cout << i << " ";
        }else {
                a.resize(n, 0);
                for(ll i=0;i<n;i++) a[i] += i;
                ll rems = k;
                for(ll i=0;(i<n) && (rems); i++) {
                a[i] += n;
                for(ll j=0;j<n;j++) {
                        if(j==i) continue;
                        a[j] -= 1;
                }
                rems--;
        }
        cout << a.size() << "\n";
        for(auto &i: a) cout << i << " ";
        }
        return 0;
}


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

int main(){
	int n;
	cin >> n;
	vector<int> a(n);
	vector<vector<int>> x(n), y(n);
	for(int i=0;i<n;i++) {
		cin >> a[i];
		for(int j=0;j<a[i];j++) {
			int s, t;
			cin >> s >> t;
			s--;
			x[i].push_back(s);
			y[i].push_back(t);
		}
	}
	int ans = 0;

	for(int bit=0;bit<(1<<n);bit++) {
		bool flag= true;
		set<int> st, dt;
		int cnt = 0;
		for(int i=0;i<n;i++) {
			// 正直者
			if(bit & (1<<i)) {
				cnt++;
				st.insert(i);
				for(int j=0;j<a[i];j++) {
					if(y[i][j]) {
						st.insert(x[i][j]);
					} else{
						dt.insert(x[i][j]);
						if(st.count(x[i][j])) flag = false;
					}
				}
			} else {
				dt.insert(i);
				/*
				for(int j=0;j<a[i];j++) {
					if(!y[i][j]) {
						st.insert(x[i][j]);
					} else {
						if(st.count(x[i][j])) flag = false;
					}
				}
				*/
			}

		}
		if(flag and (int)st.size()+(int)dt.size() == n and cnt == (int)st.size()) ans = max(ans, (int)st.size());
	}
	cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
using namespace std;
 
int main()
{
  int X, A, B;
  cin >> X >> A >> B;
 
  int diff = B - A;
 
  if(diff <= 0)
    cout << "delicious" << endl;
  else if(X - diff >= 0)
    cout << "safe" << endl;
  else
    cout << "dangerous" << endl;
 
  return 0;
}

Measured memory_bytes: 256
#include <bits/stdc++.h>
using namespace std;
int main(){
	ios_base::sync_with_stdio(false);
	cin.tie(0);cout.tie(0);
	int n;
	cin>>n;
	int a1,b1,c1;
	cin>>a1>>b1>>c1;
	while(--n){
		int a2,b2,c2;
		cin>>a2>>b2>>c2;
		a2+=max(b1,c1);
		b2+=max(a1,c1);
		c2+=max(a1,b1);
		a1=a2;
		b1=b2;
		c1=c2;
	}
	cout<<max(a1,max(b1,c1));
}

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

int main()
{
    int h,n;
    cin >> h >> n;
    int a[n] = {};
    int b[n] = {};
    for(int i=0; i<n; i++)  cin >> a[i] >> b[i];
    vector<vector<int>> dp(n+1, vector<int>(h+1, 1e9));
    dp[0][0] = 0;
    for(int i=0; i<n; i++){
        for(int w=0; w<=h; w++){
            dp[i+1][w] = min(dp[i][w], dp[i+1][w]);
            int t = min(h, w+a[i]);
            dp[i+1][t] = min(dp[i+1][t], dp[i+1][w]+b[i]);
        }
    }
    cout << dp[n][h];
    return 0;
}


Measured memory_bytes: 39424
#include <iostream>
#include <array>
#include <vector>
#include <iomanip>
#include <string>
#include <cmath>
#include <algorithm>
#include <queue>
#include <map>
#include <set>
using namespace std;

typedef  pair<int,int> P;
typedef long long LL;

const LL INF=3000000000;
const LL MOD=1000000007;



int main(){
    int n,m;
    cin>>n>>m;
    LL a[50],b[50],c[50],d[50];
    for(int i=0;i<n;++i){
        cin>>a[i]>>b[i];
    }
    for(int i=0;i<m;++i){
        cin>>c[i]>>d[i];
    }
    
    for(int i=0;i<n;++i){
        LL ans=INF; int p=-11;
        for(int j=0;j<m;++j){
            if(abs(a[i]-c[j])+abs(b[i]-d[j])<ans){
                ans=abs(a[i]-c[j])+abs(b[i]-d[j]);
                p=j+1;
            }
        }
        cout<<p<<"\n";
    }

    cout<<endl;
}

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

int main()
{
  // max:31
  int x, ans = 1, tmp;
  
  cin >> x;
  for (int i = 2; i <= 31; i++)
  {
    tmp = i;
    while (tmp * i <= x)
      tmp *= i;
    if (tmp != i)
      ans = max(ans, tmp);
  }
  cout << ans << endl;
}

Measured memory_bytes: 256
#include <iostream>
#include <string>
#include <set>
#include <vector>
#include <algorithm>
#include <stdint.h>

using namespace std;

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

  vector<set<string>> S(5);//s_m, s_a, s_r, s_c, s_h;
  
  for (int n=0; n<N; ++n) {
    string s;
    std::cin >> s;

    switch (s.front()) {
    case 'M':
      S[0].insert(s);
      break;
    case 'A':
      S[1].insert(s);
      break;
    case 'R':
      S[2].insert(s);
      break;     
    case 'C':
      S[3].insert(s);
      break;
    case 'H':
      S[4].insert(s);
      break;
    }
  }
  
  vector<int> X = {0,1,2,3,4};

  set<set<int>> P;
  
  do {
    set<int> p;
    for (int ii=0; ii<3; ++ii)
      p.insert(X[ii]);
    P.insert(p);
  } while ( next_permutation(X.begin(), X.end()) );

  int64_t x = 0;
  for (auto p : P) {
    int64_t k = 1;
    for (auto i : p) {
      k *= S[i].size();
    }
    x += k;
  }

  cout << x << endl;
   
  return 0;
}

Measured memory_bytes: 9600
#include<bits/stdc++.h>
using namespace std;
#define inf INT_MAX
#define INF LLONG_MAX
#define ll long long
#define ull unsigned long long
#define M (int)(1e9+7)
#define P pair<int,int>
#define FOR(i,m,n) for(int i=(int)m;i<(int)n;i++)
#define RFOR(i,m,n) for(int i=(int)m;i>=(int)n;i--)
#define rep(i,n) FOR(i,0,n)
#define rrep(i,n) RFOR(i,n,0)
#define all(a) a.begin(),a.end()
const int vx[4] = {0,1,0,-1};
const int vy[4] = {1,0,-1,0};
#define F first
#define S second
#define PB push_back
#define EB emplace_back
#define int ll
#define vi vector<int>
#define IP pair<int,P>
#define PI pair<P,int>
#define PP pair<P,P>
#define Yes(f){cout<<(f?"Yes":"No")<<endl;}
#define YES(f){cout<<(f?"YES":"NO")<<endl;}
int Madd(int x,int y) {return (x+y)%M;}
int Msub(int x,int y) {return (x-y+M)%M;}
int Mmul(int x,int y) {return (x*y)%M;}


signed main(){
  cin.tie(0);
  ios::sync_with_stdio(false);
  cout<<fixed<<setprecision(20);

  int n,k;
  cin>>n>>k;
  vi a(n);
  rep(i,n){
    cin>>a[i];
  }

  int i=0,j=0;
  int s=0;
  vi cnt(1e5+1,0);
  int ans=inf;

  while(i<n){
    while(i<n&&s<k){
      if(a[i]<=k&&cnt[a[i]]==0) s++;
      cnt[a[i]]++;
      i++; 
    }
    
    if(s==k)ans=min(ans,i-j);
    while(s==k){
      cnt[a[j]]--;
      if(a[j]<=k&&cnt[a[j]]==0) s--;
      j++;
      if(s==k)ans=min(ans,i-j);
    }
  }

  cout<<(ans==inf?0:ans)<<endl;

    
}


Measured memory_bytes: 4416
#include<cstdio>
#include<algorithm>
#include<vector>
#include<queue>
#include<string>
#include<iostream>
#include<cmath>
#include<map>
#include<set>
using namespace std;
typedef vector<string>vs;
typedef vector<int>vi;
typedef vector<vi>vvi;
typedef vector<double>vd;
typedef pair<int,int>pii;
typedef long long ll;
typedef pair<ll,ll>pll;
typedef vector<ll>vl;
#define rrep(i,x,n) for(int i=(x);i<(n);++i)
#define rep(i,x) rrep(i,0,(x))
#define fi first
#define se second
#define each(i,c) for(__typeof((c).begin()) i=(c).begin();i!=(c).end();++i)
#define all(c) (c).begin(),(c).end()
#define rall(c) (c).rbegin(),(c).rend()
#define pb push_back
#define maxs(a,b) (a)=max(a,b)
#define mins(a,b) (a)=min(a,b)

int main(){
    set<string>S;
    char head='a';
    for(int i=0;i<50;i++){
        cout<<"?"<<head<<(char)(i/26+'a')<<(char)(i%26+'a')<<"a"<<endl;
        string str;
        cin>>str;
        if(S.find(str)!=S.end()||str[0]!='a'){
            cout<<"!OUT"<<endl;
            break;
        }
        head=str[str.size()-1];
        S.insert(str);
    }
    return 0;
}

Measured memory_bytes: 1256
// Hail god Yato
 
#include <bits/stdc++.h> 
using namespace std;
 
#define add(x) accumulate(x)
#define sz(x) (int)(x).size()
#define mp make_pair
#define pb push_back
#define ff first
#define ss second
#define lb lower_bound
#define ub upper_bound
#define all(x) x.begin(), x.end() 
#define rep(i, a, b) for (int i=a; i<(b); i++)
#define hs ios::sync_with_stdio(0); cin.tie(0); cout.tie(0);
typedef long long ll;
typedef pair<ll,ll> pll;
typedef vector<ll> vll;
typedef vector<pll> vpll;
const ll mod = 1000000007;
const ll INF = 1e18;
const ll MAX = 100001;
//
//
                void solve(){
                        ll n,k ;
                        cin>>n>>k;
                        ll div=n%k;
                        cout<<min(div,k-div);
                }
                int main(){ 
                        hs;
                        ll t;
                        t=1;
                        // cin>>t;
                        for (int i=1; i<=t; i++){
                                //cout<<"Case #"<<i<<": ";
                                solve();
                         }
        return 0; 
}         
 

Measured memory_bytes: 256
import sys


class SegTreeMin:
    """
    以下のクエリを処理する
    1.update:  i番目の値をxに更新する
    2.get_min: 区間[l, r)の最小値を得る
    """

    def __init__(self, n, INF):
        """
        :param n: 要素数
        :param INF: 初期値（入りうる要素より十分に大きな数）
        """
        n2 = 1 << (n - 1).bit_length()
        self.offset = n2
        self.tree = [INF] * (n2 << 1)
        self.INF = INF

    @classmethod
    def from_list(cls, lst, INF):
        """
        既存のリストから構築する

        :param lst:
        :param INF:
        :return:
        """
        n = len(lst)
        ins = cls(n, INF)
        ofs = ins.offset
        tree = ins.tree
        tree[ofs:ofs + n] = lst
        for i in range(ofs - 1, 0, -1):
            l = i << 1
            tree[i] = min(tree[l], tree[l + 1])
        return ins

    def update(self, i, x):
        """
        i番目の値をxに更新
        :param i: index(0-indexed)
        :param x: update value
        """
        i += self.offset
        self.tree[i] = x
        while i > 1:
            y = self.tree[i ^ 1]
            if y <= x:
                break
            i >>= 1
            self.tree[i] = x

    def get_min(self, a, b):
        """
        [a, b)の最小値を得る
        :param a: index(0-indexed)
        :param b: index(0-indexed)
        """
        result = self.INF

        l = a + self.offset
        r = b + self.offset
        while l < r:
            if r & 1:
                result = min(result, self.tree[r - 1])
            if l & 1:
                result = min(result, self.tree[l])
                l += 1
            l >>= 1
            r >>= 1

        return result


n, x, *aaa = map(int, sys.stdin.buffer.read().split())
INF = 10 ** 18
sgt = SegTreeMin.from_list(aaa + aaa, INF)
# k回魔法を使うと決め打つ → その回数で色iを入手するのに最適なのは、i-k～iのスライムの最小値
ans = INF
for k in range(n):
    ans = min(ans, sum(sgt.get_min(i - k, i + 1) for i in range(n, 2 * n)) + k * x)
print(ans)


Measured memory_bytes: 56412
#include <iostream>
#include <cstdio>
using namespace std;
#define rep2(x,from,to) for(int x=(from);(x)<(to);(x)++)
#define rep(x,to) rep2(x,0,to)
int main() {
	int n;
	int a[110];
	cin >> n;
	rep(i,n) {
		cin >> a[i];
	}
	rep(i,n) {
		cout << a[i];
		if(i < n - 1) cout << " ";
	}
	cout << endl;
	
	rep2(i,1,n) {
		int v = a[i];
		int j = i - 1;
		while(j >= 0 && a[j] > v) {
			a[j+1] = a[j];
			--j;
		}
		a[j+1] = v;
		rep(j,n) {
			cout << a[j];
			if(j < n - 1) cout << " ";
		}
		cout << endl;
	}
	return 0;
}

Measured memory_bytes: 1160
#include<cstdio>
#include<cstring>
#include<cmath>
#include<vector>
#include<algorithm>
#include<map>
#include<set>
#include<queue>

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

#define PI 3.1415926535897932384626433832795


struct g_t
{
	int p;
	int n;
};


int get_parent(vector<g_t>&g, int a)
{
	int p=g[a].p;
	if(p==a) return a;

	p=get_parent(g, p);
	g[a].p=p;
	return g[a].p;
}


void join(vector<g_t>&g, int a, int b)
{
	if(g[a].n<g[b].n) swap(a, b);
	int ap=get_parent(g, a);
	int bp=get_parent(g, b);
	if(ap!=bp)
	{
		g[ap].n+=g[bp].n;
		g[bp].n=0;
		g[bp].p=ap;
	}
}


int main(void)
{
	int n, m, k;
	while(scanf("%d%d%d", &n, &m, &k)==3)
	{
		vi a(m), b(m);
		vi c(k), d(k);
		for(int i=0;i<m;i++) scanf("%d%d", &a[i], &b[i]);
		for(int i=0;i<k;i++) scanf("%d%d", &c[i], &d[i]);

		vector<g_t> g(n+1);
		for(int i=1;i<=n;i++)
		{
			g[i].p=i;
			g[i].n=1;
		}

		for(int i=0;i<m;i++)
		{
			join(g, a[i], b[i]);
		}
		for(int i=1;i<=n;i++)
		{
			get_parent(g, i);
		}

		vi ans(n+1);
		for(int i=1;i<=n;i++)
		{
			ans[i]=g[get_parent(g, i)].n-1;
		}

		for(int i=0;i<m;i++)
		{
			int ap=get_parent(g, a[i]);
			int bp=get_parent(g, b[i]);
			if(ap==bp)
			{
				ans[a[i]]--;
				ans[b[i]]--;
			}
		}

		for(int i=0;i<k;i++)
		{
			int cp=get_parent(g, c[i]);
			int dp=get_parent(g, d[i]);
			if(cp==dp)
			{
				ans[c[i]]--;
				ans[d[i]]--;
			}
		}

		printf("%d", ans[1]);
		for(int i=2;i<=n;i++)
		{
			printf(" %d", ans[i]);
		}
		printf("\n");
	}
	return 0;
}


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

int fact (int n) {
	if (n == 0) return 1;
	return n * fact (n - 1);
}

int count_rank (string s, int n) {
	vector < bool > present (n + 1, true);
	auto count_smaller = [&] (int x) {
		int cnt = 0;
		for (int i = 1; i < x; i++) {
			cnt += present[i];
		}
		return cnt;
	};
	int rnk = 0;
	//cout << "s = " << s << endl;
	for (int i = 0; i < n; i++) {
		int smaller = count_smaller (s[i] - '0');
		//cout << "smaller = " << smaller << endl;
		int x = smaller * fact (n - 1 - i);
		//cout << "x = " << x << endl;
		rnk += x;
		present[s[i] - '0'] = false;
	}
	//cout << s << " => " << rnk << endl;
	return rnk;
}

int solve() {
	int n;
	string p, q;
	char c;
	cin >> n;
	for (int i = 0; i < n; i++) {
		cin >> c;
		p += c;
	}
	for (int i = 0; i < n; i++) {
		cin >> c;
		q += c;
	}
	//cout << p << endl << q << endl;
	if (p < q) {
		return count_rank (q, n) - count_rank (p, n);
	} else {
		return count_rank (p, n) - count_rank (q, n);
	}
}

int main() {
	ios::sync_with_stdio (false);
	int ans = solve();
	cout << ans << endl;
	return 0;
}



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

int main() {
	int N;
  	cin >> N;
  	vector<int> light(N + 1); //最初のボタン「 1 」を含めるので要素数を +1 する
	light.at(0) = 1; //最初のボタン「 1 」を要素 0番 に登録する
    int SUM = 0; //ボタンを何回押したかカウントするための変数
  	int NEXT = 0; //次に押すボタンの番号を表す変数
  	int flag = 0; //ボタン「 2 」が光ったかどうかを判定するための変数
  	int a;
  	for(int i = 0; i < N; i++){
   		cin >> a;
		light.at(i + 1) = a;
    }
  	for(int j = 0; j < N; j++){
      	if(light.at(NEXT) == 2){
          	flag = 1;
        	break;
        }
      	NEXT = light.at(NEXT);
      	SUM += 1;
    }
  	if(flag == 1){
    	cout << SUM << endl;
    }else{
    	cout << -1 << endl;
    }
}


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

using namespace std;

int main(){
	int N, K;
	scanf("%d%d", &N, &K);
	
	if(K > (N-1)*(N-2)/2){
		printf("-1");
		return 0;
	}
	
	int cnt = 0;
	printf("%d\n", N*(N-1)/2-K);
	for(int i = 1; i < N; i ++){
		for(int j = 1; j+i <= N; j ++){
			if(cnt < N*(N-1)/2-K){
				printf("%d %d\n", i, j+i);
			}
			cnt ++;
		}
	}
	
	return 0;
}


Measured memory_bytes: 256
import sys, re
from collections import deque, defaultdict, Counter
from math import ceil, sqrt, hypot, factorial, pi, sin, cos, tan, asin, acos, atan, radians, degrees#, log2
from itertools import accumulate, permutations, combinations, combinations_with_replacement, product, groupby
from operator import itemgetter, mul
from copy import deepcopy
from string import ascii_lowercase, ascii_uppercase, digits
from bisect import bisect, bisect_left, insort, insort_left
from fractions import gcd
from heapq import heappush, heappop
from functools import reduce
def input(): return sys.stdin.readline().strip()
def INT(): return int(input())
def MAP(): return map(int, input().split())
def LIST(): return list(map(int, input().split()))
def ZIP(n): return zip(*(MAP() for _ in range(n)))
sys.setrecursionlimit(10 ** 9)
INF = float('inf')
mod = 10**9 + 7
#from decimal import *

S = input()
N = len(S)

dp = [[0, 0] for _ in range(N+1)]
dp[1][0] = 1
 
for i in range(2, N+1):
	if S[i-1] != S[i-2]:
		dp[i][0] = dp[i-1][0] + 1
	else:
		dp[i][0] = dp[i-1][1] + 1

	dp[i][1] = dp[i-2][0] + 1
	#print(dp)

print(dp[-1][0])

Measured memory_bytes: 40852
#include <string>
#include <cstdio>
#include <iostream>
#include <vector>
#include <unordered_map>
#include <cstring>
#include <algorithm>
#include <bitset>
#include <deque>
#include <stack>
#include <queue>
using namespace std;
long long S;
int main()
{
    scanf("%lld", &S);
    if (S == 1e18)
    {
        printf("0 0 1000000000 0 0 1000000000");
        return 0;
    }
    long long x = 2;
    while (x * x <= S) x += 2;
    long long s = x * x  - S;
    long long xx = 1;
    for (int i = 1 ; (long long)i*i <= s; i ++)
        if (s % i == 0)  xx = i;
    printf("0 0 %lld %lld %lld %lld\n", xx, x, x, s / xx);
    return 0;
}

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

//#define int long long
#define ll long long
#define all(v) (v).begin(), (v).end()
#define rep(i,n) for(int i=0;i<n;++i)
#define rep1(i,n) for(int i=1;i<n;++i)
#define FOR(i, m, n) for(int i = m; i < n; i++)
#define EPS (1e-7)
#define gearup ios_base::sync_with_stdio(0);cin.tie(0);cout.tie(0);
typedef pair<ll, ll> P;
typedef vector<ll> vl;
typedef vector<vector<ll> > vvl;
typedef vector<vector<vector<ll> > > vvvl;
ll MOD = 1000000007;
const long long L_INF = 1LL << 60;
const int INF = 2147483647; // 2^31-1
const double PI = acos(-1);
//cout<<fixed<<setprecision(10);

template<class T> inline bool chmin(T& a, T b) {if (a > b) {a = b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if (a < b) {a = b;return true;}return false;}
template<class T> void debug(T v){rep(i,v.size()) cout<<v[i]<<" ";cout<<endl;}

signed main()
{   
    gearup;
    int n,m; cin >> n >> m;
    ll res = 0;
    res += n*(n-1)/2;
    res += m*(m-1)/2;
    cout << res << endl;
}

Measured memory_bytes: 256
#pragma gcc optimize("Ofast")
#include <bits/stdc++.h>
using namespace std;

#define FOR(i, a, b) for (int i = (a); i < (b); ++i)
#define REP(i, n) FOR(i, 0, n)
#define ALL(V) (V).begin(),(V).end()
#define SORT(V) sort(ALL(V)) //小さい方からソート
#define REV(V) reverse(ALL(V)) //リバース
#define RSORT(V) SORT(V);REV(V) //大きい方からソート
#define NPN(V) next_permutation(ALL(V)) //順列
#define pb(n) push_back(n)
#define endl '\n'
#define Endl '\n'
#define DUMP(x)  cout << #x << " = " << (x) << endl
#define YES(n) cout << ((n) ? "YES" : "NO"  ) << endl
#define Yes(n) cout << ((n) ? "Yes" : "No"  ) << endl
#define yes(n) cout << ((n) ? "yes" : "no"  ) << endl
#define Yay(n) cout << ((n) ? "Yay!": ":(") << endl
#define RAPID cin.tie(0);ios::sync_with_stdio(false)
#define VSUM(V) accumulate(ALL(V), 0)
#define MID(a,b,c) (a) < (b) && (b) < (c)
#define MIDe(a,b,c) (a) <= (b) && (b) <= (c)
#define IN(n) cin >> n
#define IN2(a,b) cin >> a >> b
#define IN3(a,b,c) cin >> a >> b >> c 
#define IN4(a,b,c,d) cin >> a >> b >> c >> d
#define VIN(V) for(int i = 0; i < (V).size(); i++) {cin >> (V).at(i);}
#define OUT(n) cout << n << endl
#define VOUT(V) REP(i, (V).size()) {cout << (V)[i] << endl;}
#define VOUT2(V) REP(i, (V).size()) {cout << (V)[i] << " ";} cout<<endl;
#define FIX cout << fixed << setprecision(15)

// 型マクロ定義
#define int long long
#define P pair<ll,ll>
#define Vi vector<ll>
#define VVi vector<vector<ll>>
#define Vd vector<double>
#define Vb vector<bool>
#define Vs vector<string>
#define Vc vector<char>
#define M map<ll,ll>
#define S set<ll>
#define PQ priority_queue<ll>
#define PQG priority_queue<ll,V,greater<ll>
//

template<class T> inline bool chmin(T& a, T b) {if(a>b){a=b;return true;}return false;}
template<class T> inline bool chmax(T& a, T b) {if(a<b){a=b;return true;}return false;}

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

const int MOD = 1000000007;
const int INF = 1061109567;
const double EPS = 1e-10;
const double PI  = acos(-1.0);
const int dx[4] = {1, 0, -1, 0};
const int dy[4] = {0, 1, 0, -1};

int gcd(int a,int b){return b != 0 ? gcd(b, a % b) : a;} //最大公約数
int lcm(int a, int b){return a * b / gcd(a, b);}
string toStrUp(string str){char diff = 'A'-'a';REP(i,str.size()) str[i] += diff;return str;}
string gCh(string str, int key){return str.substr(key,1);}

signed main() {
  RAPID;
  // デフォルト変数定義
  int n=0,m=0,a=0,b=0,c=0,d=0,x=0,y=0,z=0;
  string s="",t="";
  //

  // ここから
  IN3(a,b,c);
  OUT(min(a+b+1,c)+b);
}

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

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

bool is_prime(int x) {
  for (int i = 2; i * i <= x; i++) {
    if (x % i == 0) return false;
  }
  return true;
}

void solve() {
  int n;
  cin >> n;
  unordered_map<int, int> b;
  unordered_set<int> c;
  vector<bool> d(1e6 + 1, true);
  for (int i = 0; i < n; i++) {
    int t;
    cin >> t;
    ++b[t];
    c.insert(t);
  }

  for (auto &i : c) {
    int t = 2;
    while (i * t <= 1e6) {
      d[i * t] = false;
      ++t;
    }
  }

  int ans = 0;
  for (auto &i : c) {
    if (b[i] == 1 && d[i]) ++ans;
  }

  cout << ans << endl;
}

int main() {
  cin.tie(nullptr);
  ios::sync_with_stdio(false);
  std::cout << std::fixed << std::setprecision(15);

  solve();
  return 0;
}


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

#define W 5
#define DELETE 0

int main(void){
  while(true){
    int H;
    cin >> H;
    if(H == 0){ break; }

    // ?????¢???????????????
    vector<vector<int> > puyo(H, vector<int>(W));
    for(int i = 0; i < H; i++)
      for(int j = 0; j < W; j++)
        cin >> puyo[i][j];

    // ??????????¶????????????§???????????°?????????
    int flag, ans = 0;
    do{
      /*
      printf("\nans: %d\n", ans);
      for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
          printf("[%d]", puyo[i][j]);
        }
        printf("\n");
      }
      */
      
      // ?????????????????°????????£?????????
      flag = false;

      for(int i = 0; i < H; i++){
        for(int j = 0; j < W; j++){
          if(puyo[i][j] == DELETE){ continue;}
          
          // ??????[i][j]?????????????????¨??????
          // ??????????????§????????????????±???????
          int seg;
          for(seg = 1; (j + seg < W) && (puyo[i][j] == puyo[i][j + seg]); seg++);

          // ??£?¶??????????3??\????????£???????¶????
          if(seg >= 3){
            for(int k = 0; k < seg; k++){
              // ?¶??????´??????????????°????????????????????????????????????
              flag = true;
              ans += puyo[i][j + k];
              puyo[i][j + k] = DELETE;
            }
          }
        }
      }

      // DELETE ????????£????????????????????????????????????
      for(int k = 0; k < H; k++){
        for(int i = 1; i < H; i++){
          for(int j = 0; j < W; j++){
            if(puyo[i][j] == DELETE){
              int tmp = puyo[i][j];
              puyo[i][j] = puyo[i - 1][j];
              puyo[i - 1][j] = tmp;
            }
          }
        }
      }
    }while(flag);

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

Measured memory_bytes: 3092
#include<iostream>
#include<algorithm>
using namespace std;
int main(){
	int a,b,c,z,r=0;
	cin>>a>>b>>c;
	if(a>b){
		swap(a,b);}
	for(int x = a ; x <= b; x++){
	z=c%x;
	if(z==0){
	r++;
	}else if(x>=c){
		break;}}
	cout<<r<<endl;
	return 0;
}


Measured memory_bytes: 3116
#include<iostream>
#include<cstring>
#include<algorithm>
#include<vector>
#include<cmath>
#include<limits>
#include<map>
#define ll long long
#define ALL(x) (x).begin(),(x).end()
#define rep(i, n) for(int i = 0; i < (int)(n); i++)
#define int_INF 2147483647
#define ll_INF 	9223372036854775807
#define vi vector<int>
#define vii vector<vector<int>>
#define vll vector<long long>
#define pii pair<int,int>
using namespace std;
void sub1() {

	ll a, b, c;
	cin >> a >> b >> c;
	if (c - a - b > 0) {
		if ((c - a - b) * (c - a - b) - 4 * a * b > 0) {
			cout << "Yes" << endl;
		}
		else {
			cout << "No" << endl;
		}
	}
	else {
		cout << "No" << endl;
	}
	
}

int main() {
	sub1();
}


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

template<typename T>
struct imos2d {
	vector<vector<T>> board;
	const int h, w;
	imos2d(int h, int w) : 
		board(vector<vector<T>>(h + 2, vector<T>(w + 2, 0))),
		w(w + 2),
		h(h + 2)
		{}
	// 範囲外許さないマン
	bool able(int y, int x) {
		if(y <= 0 or h < y) return false;
		if(x <= 0 or w < x) return false;
		return true;
	}
	bool able(int y1, int x1, int y2, int x2) {
		if(not able(y1, x1)) return false;
		if(not able(y2, x2)) return false;
		if(make_pair(y1, x1) > make_pair(y2, x2)) return false;
		return true;
	}
	// 1点加算
	void add(int y, int x, T z) {
		assert(able(y, x));
		board[y][x] += z;
	}
	// 矩形加算
	void add(int y1, int x1, int y2, int x2, T z) {
		assert(able(y1, x1, y2, x2));
		board[y1][x1] += z;
		board[y1][x2 + 1] -= z;
		board[y2 + 1][x1] -= z;
		board[y2 + 1][x2 + 1] += z;
	}
	// 累積和
	void build() {
		for(int y = 1; y < h; ++y) {
			for(int x = 1; x < w; ++x) {
				board[y][x] += board[y][x - 1];
			}
		}
		for(int y = 1; y < h; ++y) {
			for(int x = 1; x < w; ++x) {
				board[y][x] += board[y - 1][x];
			}
		}
	}
	// 1点取得
	T get(int y, int x) {
		assert(able(y, x));
		return board[y][x];
	}
	// 矩形取得
	T get(int y1, int x1, int y2, int x2) {
		assert(able(y1, x1, y2, x2));
		return board[y2][x2] - board[y2][x1 - 1] - board[y1 - 1][x2]+board[y1 - 1][x1 - 1];
	}
	void debug() {
		for(int y = 1; y < h - 1; ++y) {
			for(int x = 1; x < w - 1; ++x) {
				cout << board[y][x] << " ";
			}
			cout << '\n';
		}
	}
};

int main() {
	int n, m, q; cin >> n >> m >> q;
	imos2d<int> imos(n, n);
	while(m--) {
		int l, r; cin >> l >> r;
		imos.add(1, r, l, n , 1);
	}
	imos.build();
	while(q--) {
		int l, r; cin >> l >> r;
		cout << imos.get(l, r) << '\n';
	}
	return 0;
}

Measured memory_bytes: 1920
import Data.Char

main :: IO ()
main = getLine >>= print . solve

solve :: String -> Int
solve s = min (calc wb) (calc bw)
  where
    ints = map digitToInt s :: [Int]
    wb = cycle [1, 0]
    bw = cycle [0, 1]
    calc = sum . map abs . zipWith (-) ints

Measured memory_bytes: 7164
#include<bits/stdc++.h>
#include<set>
using namespace std;
int main () {
  int N;
  cin >> N;
  set<int>A;
  for (int i = 0; i < N; i ++) {
    int c;
    cin >> c;
    A.insert(c);
  }
  cout << A.size() << endl;
}

Measured memory_bytes: 256
// ＡＢＣのＡ過去問を解くだけだよ

// フォント:Electroharmonix
// x:小文字(ｘ)    X:大文字(Ｘ)
// +:プラス(＋)    &:アンド(＆)

#include <bits/stdc++.h>

using namespace std;

void Main()
{
    int a, b, c, d;
    cin >> a >> b >> c >> d;

    if (abs(a - c) <= d 
        || (abs(a - b) <= d && abs(b - c) <= d))
    {
        cout << "Yes";
    }
    else
    {
        cout << "No";
    }
    
}

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

    //std::cout << std::fixed << std::setprecision(10);

    /*
	while (true)
	{
		Main();
		cout << endl;
	}
	//*/

    Main();
    cout << endl;

    return 0;
}

Measured memory_bytes: 384
#include <bits/stdc++.h>
 
#define _overload(_1,_2,_3,name,...) name
#define _rep(i,n) _range(i,0,n)
#define _range(i,a,b) for(int i=(int)(a);i<(int)(b);++i)
#define rep(...) _overload(__VA_ARGS__,_range,_rep,)(__VA_ARGS__)
 
#define _rrep(i,n) _rrange(i,n,0)
#define _rrange(i,a,b) for(int i=(int)(a)-1;i>=(int)(b);--i)
#define rrep(...) _overload(__VA_ARGS__,_rrange,_rrep,)(__VA_ARGS__)
 
#define _all(arg) begin(arg),end(arg)
#define uniq(arg) sort(_all(arg)),(arg).erase(unique(_all(arg)),end(arg))
#define bit(n) (1LL<<(n))
 
// #define DEBUG
 
#ifdef DEBUG
    #define dump(...) fprintf(stderr, __VA_ARGS__)
#else
    #define dump(...)
#endif
 
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;}
 
using namespace std;
using ll=long long;
using vi=vector<int>;
using vll=vector<ll>;
 
const double EPS = 1e-10;
const double PI = acos(-1.0);
const int inf = INT_MAX;
const ll INF = LLONG_MAX;
const ll MOD = 1000000007LL;
const int dx[4]={1,0,-1,0};
const int dy[4]={0,1,0,-1};
 
ll extgcd(ll a,ll b,ll& x,ll& y){x=1,y=0;ll g=a;if(b!=0) g=extgcd(b,a%b,y,x),y-=a/b*x;return g;}
ll ADD(const ll &a, const ll &b, const ll mod=MOD) { return (a+b)%mod;}
ll SUB(const ll &a, const ll &b, const ll mod=MOD) { return (a-b+mod)%mod;}
ll MUL(const ll &a, const ll &b, const ll mod=MOD) { return (1LL*a*b)%mod;}
ll DIV(const ll &a, const ll &b, const ll mod=MOD) {ll x,y; extgcd(b,mod,x,y);return MUL(a,(x+mod)%mod,mod);}
 
///////////////////////
const int N = 1e6; 
const int mod = MOD;
ll fact[N+1];

void set_fact() {
    fact[0] = 1;
    rep(i,N) fact[i+1] = ((((ll)i+1) % mod) * fact[i]) % mod;
}

ll mod_inv(ll a, ll m) {
    ll x, y;
    extgcd(a, m, x, y);
    return (m + x % m) % m;
}

// n! mod p 
ll mod_fact(ll n, ll p, ll &e) {
    e = 0;
    if (!n) return 1;
    ll res = mod_fact(n/p, p, e);
    e += n/p;

    if ((n/p)%2) 
        return res * (p - fact[n%p]) %p;
    else
        return res * fact[n%p] % p;
}

// nCk mod p ; O(log_p n)
ll mod_comb(ll n, ll k, ll p) {
    if (n<0 || k<0 || n<k) return 0;
    ll e1, e2, e3;
    ll a1 = mod_fact(n, p, e1), a2 = mod_fact(k, p, e2), a3 = mod_fact(n-k, p, e3);
    if (e1 > e2+e3) return 0;
    return a1 * mod_inv(a2*a3%p, p) % p;
}

// nHk mod p ;
ll mod_h_comb(ll n, ll k, ll p) {
    return mod_comb(n+k-1, k, p);
}
///////////////////////

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

    int n, m; cin >> n >> m;
    int M = m;

    set_fact();

    ll res = 1LL;
    rep(i, 2, (int)(sqrt(m))+1){
        int cnt = 0;
        while(M % i == 0){
            cnt++;
            M /= i;
        }
        if(cnt == 0) continue;

        ll cur = DIV(fact[cnt + n - 1], MUL(fact[cnt], fact[n - 1]));
        res = MUL(res, cur);
    }

    if(M > 1){
        int cnt = 1;
        ll cur = DIV(fact[cnt + n - 1], MUL(fact[cnt], fact[n - 1]));
        res = MUL(res, cur);
    }

    cout << res << endl;

    return 0;
}


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

int main(){
  int a,b=0,c=0;
  for(int i=0;i<3;i++){
    cin>>a;
    if(a==5)b++;
    if(a==7)c++;
  }
  if(b==2&&c==1)cout<<"YES"<<endl;
  else cout<<"NO"<<endl;

}


Measured memory_bytes: 256
H,W = map(int,input().split())
C = [list(input()) for i in range(H)]
for i in range(H):
  for j in range(W):
    if C[i][j]=='#':
      if (i>0 and C[i-1][j]=='.') and (i<H-1 and C[i+1][j]=='.') and (j>0 and C[i][j-1]=='.') and (j<H-1 and C[i][j+1]=='.'):
        print("No")
        exit()
print("Yes")

Measured memory_bytes: 39024
# import bisect
from collections import Counter, deque # https://note.nkmk.me/python-scipy-connected-components/
# from copy import copy, deepcopy
# from fractions import gcd
# from functools import reduce
# from itertools import accumulate, permutations, combinations, combinations_with_replacement, groupby, product
# import math
# import numpy as np  # Pythonのみ！
# from operator import xor
# import re
# from scipy.sparse.csgraph import connected_components  # Pythonのみ！
# ↑cf.  https://note.nkmk.me/python-scipy-connected-components/
# from scipy.sparse import csr_matrix
# import string
import sys
sys.setrecursionlimit(10 ** 5 + 10)
def input(): return sys.stdin.readline().strip()

def resolve():
    N=int(input())
    A=list(map(int,input().split()))
    mod=10**9+7
    if N%2==0:
        l=[2*i+1 for i in range(0,N//2)]+[2*i+1 for i in range(0,N//2)]
        if Counter(l)!=Counter(A):
            ans=0
        else:
            ans=2**(N//2)
    else:
        l=[2*i for i in range(1,N//2+1)]*2+[0]
        if Counter(l)!=Counter(A):
            ans=0
        else:
            ans=2**(N//2)
    print(ans%mod)


resolve()

Measured memory_bytes: 20696
#include<bits/stdc++.h>
using namespace std;
#define rep(i, n) for(int i = 0; i < (n); i++)
#define All(V) v.begin(), v.end()
typedef long long int ll;
typedef pair<int, int> P;
const ll MOD = 1e9+7, INF = 1e9;

int main() 
{
  int a, b; cin >> a >> b;
  cout << (a+b+1)/2 << endl;
  system("pause");
}

Measured memory_bytes: 504
S = list(input())
K = int(input())

moji = []

count = 1
for i in range(len(S)-1): 
  if(S[i] == S[i+1]):
    count += 1
  else:
    moji.append(count)
    count = 1
moji.append(count)
#print(moji)

ans = 0
if len(moji) == 1:
  ans = (moji[len(moji)-1] * K) //2
elif len(moji) != 1 and S[0] == S[len(S)-1]:
  for i in range(1, len(moji)-1):
    ans += (moji[i] // 2) * K
    
  ans += ((moji[0] + moji[len(moji)-1]) // 2) * (K-1)
  ans += moji[0] // 2
  ans += moji[len(moji)-1] // 2

else:
  for i in range(len(moji)):
    ans += (moji[i] // 2) * K
    
print(ans)



Measured memory_bytes: 3064